~ubuntu-branches/ubuntu/trusty/mir/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/unit-tests/graphics/android/test_hwc11_device.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Kevin Gunn, Ubuntu daily release
  • Date: 2013-11-28 10:05:20 UTC
  • mfrom: (1.1.53)
  • Revision ID: package-import@ubuntu.com-20131128100520-nm0l2ltdr2nj0q4w
Tags: 0.1.2+14.04.20131128.1-0ubuntu1
[ Kevin Gunn ]
* New upstream release 0.1.2
  - graphics: android: improve interface for mga::DisplayDevice so its
    just concerned with rendering and posting.
  - surfaces: rename "surfaces" component to "scene".
  - surfaces, shell: Migrate Session data model from shell to surfaces.
  - graphics: change fill_ipc_package() to use real pointers.
  - mir_client_library.h: Fix typo "do and locking" should be "do any
    locking".
  - API enumerations cleanup: Remove slightly misleading *_enum_max_
    values, and replace them with more accurate plural forms.
  - test_android_communication_package: Do not expect opened fd to be >0,
    we may have closed stdin making this a valid value (LP: #1247718).
  - Update docs about running Mir on the desktop to mention new package
    ubuntu-desktop-mir.
  - offscreen: Add a display that renders its output to offscreen buffers
  - graphics: android: fix regression for hwc1.0 devices introduced in r1228
    (LP: #1252433).
  - OffscreenPlatform provides the services that the offscreen display
    needs from the Platform.
  - graphics: android: consolidate the GLContexts classes in use.
  - Fix uninitialized variable causing random drm_auth_magic test
    failures. (LP: #1252144).
  - Add a fullyish functional Udev wrapper. This currently sits in
    graphics/gbm, but will be moved to the top-level when input device
    detection migrates.
  - Add resizing support to example code; demo-shell and clients.
  - eglapp: Clarify messages about pixel formats (LP: #1168304).
  - Adds support to the MirMotionEvent under pointer_coordinates called
    tool_type. This will allow clients to tell what type of tool is
    being used, from mouse/finger/etc. (LP: #1252498)
  - client,frontend: Report the real available surface pixel formats to
    clients. (LP: #1240833)
  - graphics: android: 1) change hwc1.1 to make use of sync fences during
    the compositor's gl renderloop. Note that we no longer wait for the
    render to complete, we pass this responsibility to the driver and the
    kernel. 2) support nexus 10. (LP: #1252173) (LP: #1203268)
  - shell: don't publish SurfacesContainer - it can be private to shell.
  - gbm: Don't mess up the VT mode on setup failure Only restore the
    previous VT mode during shutdown if it was VT_AUTO.
  - Fix a crash due to a failed eglMakeCurrent() call when in nested mode.
  - shell: unity-mir uses shell::FocusSetter - make the header public again
  - Add resize support to client surfaces (mir::client::MirSurface).
  - graphics: android: support 'old aka 2012' nexus 7 hwc (nvidia tegra3
    SoC) better. (LP: #1231917)
  - Add resize support to *ClientBuffer classes. Now always get dimensions
    from the latest buffer package.
  - android: support driver hooks for the Mali T604 (present in nexus 10)
  - Add width and height to the protocol Buffer messages, in preparation
    for resizable surfaces.
  - surfaces, shell, logging, tests: don't publish headers
    that can be private to surfaces. surfaces/basic_surface.h,
    surfaces/surface_controller.h and shell/surface_builder.h
  - examples: Restore GL framebuffer binding when destroying the render
    target
  - examples, surfaces, shell: remove render_surfaces dependency on
    BasicSurface
  - geometry: remove implementation of streaming operators from headers
    (LP: #1247820)
  - Eliminate the registration order focus sequence, folding it's
    functionality in to the session container.
  - Ensure the session mediator releases acquired buffer resources before
    attempting to acquire a new buffer on behalf of the client. This fixes
    performance regression (LP: #1249210).
  - Some cleanups to test_client_input.cpp.
  - Factor out a bunch of "ClientConfigCommon".
  - Small cleanup to session container test to increase encapsulation.
  - shell, surfaces: Another step in "fixing" the surfaces hierarchies -
    only publish interfaces and putting the data model into surfaces.
  - graphics: android: HWC1.1 use EGL to get further information about
    the framebuffer pixel format.
  - Fix FTBS using use_debflags=ON (building for android-armhf).
    (LP: #1248014)
  - Add a client input receiver report.
  - doc: doxygen 1.8.4 complains about an obsolete config so ran "doxygen
    u Doxyfile.in".
  - Implement resize() for the server-side Surface classes.
  - android: clean up mga::DisplayBuffer and mga::DisplayBufferFactory
  - Add resize() support to BufferStream, in preparation for resizable
    surfaces.
  - Merge metadata changes from the newly reconstructed lp:mir
  - tests: Deduplicate mg::GraphicBufferAllocator stubs.
  - examples: Remove spurious use of mir/shell/surface.h.
  - frontend: remove ClientTrackingSurface from the Surface class
    hierarchy
  - Bumping ABI on server to libmirserver11.
  - Don't mention "Renderable". That interface hasn't existed for quite
    some time now.
  - android-input: Assign more unique touch ids

[ Ubuntu daily release ]
* Automatic snapshot from revision 1167

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17
17
 */
18
18
 
 
19
#include "src/server/graphics/android/framebuffer_bundle.h"
19
20
#include "src/server/graphics/android/hwc11_device.h"
20
21
#include "src/server/graphics/android/hwc_layerlist.h"
21
 
#include "mir_test_doubles/mock_display_device.h"
22
22
#include "mir_test_doubles/mock_hwc_composer_device_1.h"
23
 
#include "mir_test_doubles/mock_hwc_layerlist.h"
 
23
#include "mir_test_doubles/mock_android_native_buffer.h"
24
24
#include "mir_test_doubles/mock_buffer.h"
25
25
#include "mir_test_doubles/mock_hwc_vsync_coordinator.h"
26
26
#include "mir_test_doubles/mock_egl.h"
 
27
#include "mir_test_doubles/mock_framebuffer_bundle.h"
 
28
#include "mir_test_doubles/stub_buffer.h"
 
29
#include <gmock/gmock.h>
27
30
#include <gtest/gtest.h>
28
31
#include <stdexcept>
29
32
 
30
33
namespace mg=mir::graphics;
31
34
namespace mga=mir::graphics::android;
32
35
namespace mtd=mir::test::doubles;
 
36
namespace geom=mir::geometry;
33
37
 
34
38
class HWC11Device : public ::testing::Test
35
39
{
36
40
protected:
37
41
    virtual void SetUp()
38
42
    {
 
43
        using namespace testing;
 
44
 
 
45
        mock_native_buffer = std::make_shared<testing::NiceMock<mtd::MockAndroidNativeBuffer>>();
 
46
        mock_buffer = std::make_shared<testing::NiceMock<mtd::MockBuffer>>();
39
47
        mock_device = std::make_shared<testing::NiceMock<mtd::MockHWCComposerDevice1>>();
40
 
        mock_display_device = std::make_shared<testing::NiceMock<mtd::MockDisplayDevice>>();
41
 
        mock_hwc_layers = std::make_shared<testing::NiceMock<mtd::MockHWCLayerList>>();
42
48
        mock_vsync = std::make_shared<testing::NiceMock<mtd::MockVsyncCoordinator>>();
43
 
        mock_egl.silence_uninteresting();
44
49
 
45
 
        empty_list.numHwLayers = 0;
46
 
        empty_list.retireFenceFd = -1;
47
 
        ON_CALL(*mock_hwc_layers, native_list())
48
 
            .WillByDefault(testing::Return(&empty_list));
 
50
        ON_CALL(*mock_buffer, native_buffer_handle())
 
51
            .WillByDefault(Return(mock_native_buffer));
49
52
    }
50
 
 
51
53
    std::shared_ptr<mtd::MockVsyncCoordinator> mock_vsync;
52
 
    std::shared_ptr<mtd::MockHWCLayerList> mock_hwc_layers;
53
54
    std::shared_ptr<mtd::MockHWCComposerDevice1> mock_device;
54
 
    std::shared_ptr<mtd::MockDisplayDevice> mock_display_device;
 
55
    std::shared_ptr<mtd::MockAndroidNativeBuffer> mock_native_buffer;
 
56
    std::shared_ptr<mtd::MockBuffer> mock_buffer;
55
57
    EGLDisplay dpy;
56
58
    EGLSurface surf;
57
 
    mtd::MockEGL mock_egl;
58
 
    hwc_display_contents_1_t empty_list;
59
 
};
60
 
 
61
 
namespace
62
 
{
63
 
struct HWCDummyLayer : public mga::HWCDefaultLayer
64
 
{
65
 
    HWCDummyLayer()
66
 
     : HWCDefaultLayer({})
67
 
    {
68
 
    }
69
 
};
70
 
}
71
 
 
72
 
TEST_F(HWC11Device, test_hwc_gles_set_empty_layerlist)
73
 
{
74
 
    using namespace testing;
75
 
 
76
 
    mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
77
 
 
78
 
    EXPECT_CALL(*mock_device, set_interface(mock_device.get(), 1, _))
79
 
        .Times(1);
80
 
    device.commit_frame(dpy, surf);
81
 
 
82
 
    EXPECT_EQ(empty_list.numHwLayers, mock_device->display0_set_content.numHwLayers);
83
 
    EXPECT_EQ(-1, mock_device->display0_set_content.retireFenceFd);
84
 
}
85
 
 
86
 
TEST_F(HWC11Device, test_hwc_gles_set_error)
87
 
{
88
 
    using namespace testing;
89
 
 
90
 
    mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
91
 
 
92
 
    EXPECT_CALL(*mock_device, set_interface(mock_device.get(), 1, _))
93
 
        .Times(1)
94
 
        .WillOnce(Return(-1));
95
 
 
96
 
    EXPECT_THROW({
97
 
        device.commit_frame(dpy, surf);
98
 
    }, std::runtime_error);
99
 
}
100
 
 
101
 
TEST_F(HWC11Device, test_hwc_gles_commit_swapbuffers_failure)
 
59
    testing::NiceMock<mtd::MockEGL> mock_egl;
 
60
};
 
61
 
 
62
TEST_F(HWC11Device, test_hwc_prepare)
 
63
{
 
64
    using namespace testing;
 
65
    EXPECT_CALL(*mock_device, prepare_interface(mock_device.get(), 1, _))
 
66
        .Times(1);
 
67
 
 
68
    mga::HWC11Device device(mock_device, mock_vsync);
 
69
    device.prepare_composition();
 
70
    EXPECT_EQ(2, mock_device->display0_prepare_content.numHwLayers);
 
71
    EXPECT_EQ(-1, mock_device->display0_prepare_content.retireFenceFd);
 
72
}
 
73
 
 
74
TEST_F(HWC11Device, test_hwc_render)
 
75
{
 
76
    EXPECT_CALL(mock_egl, eglSwapBuffers(dpy,surf))
 
77
        .Times(1);
 
78
    mga::HWC11Device device(mock_device, mock_vsync);
 
79
    device.gpu_render(dpy, surf);
 
80
}
 
81
 
 
82
TEST_F(HWC11Device, test_hwc_swapbuffers_failure)
102
83
{
103
84
    using namespace testing;
104
85
    EXPECT_CALL(mock_egl, eglSwapBuffers(dpy,surf))
105
86
        .Times(1)
106
87
        .WillOnce(Return(EGL_FALSE));
107
88
 
108
 
    mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
 
89
    mga::HWC11Device device(mock_device, mock_vsync);
109
90
 
110
91
    EXPECT_THROW({
111
 
        device.commit_frame(dpy, surf);
 
92
        device.gpu_render(dpy, surf);
112
93
    }, std::runtime_error);
113
94
}
114
95
 
115
 
TEST_F(HWC11Device, test_hwc_commit_order_with_vsync)
 
96
TEST_F(HWC11Device, test_hwc_commit)
116
97
{
117
98
    using namespace testing;
118
 
 
119
 
    mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
120
 
 
121
 
    //the order here is very important. eglSwapBuffers will alter the layerlist,
122
 
    //so it must come before assembling the data for set
 
99
    int hwc_return_fence = 94;
 
100
    mock_device->hwc_set_return_fence(hwc_return_fence);
 
101
 
 
102
    mga::HWC11Device device(mock_device, mock_vsync);
 
103
 
123
104
    InSequence seq;
124
 
    EXPECT_CALL(*mock_hwc_layers, native_list())
125
 
        .Times(1);
126
 
    EXPECT_CALL(*mock_device, prepare_interface(mock_device.get(), 1, _))
127
 
        .Times(1);
128
 
    EXPECT_CALL(mock_egl, eglSwapBuffers(dpy,surf))
129
 
        .Times(1);
130
105
    EXPECT_CALL(*mock_device, set_interface(mock_device.get(), 1, _))
131
106
        .Times(1);
132
 
 
133
 
    device.commit_frame(dpy, surf);
134
 
 
135
 
    EXPECT_EQ(empty_list.numHwLayers, mock_device->display0_prepare_content.numHwLayers);
136
 
    EXPECT_EQ(-1, mock_device->display0_prepare_content.retireFenceFd);
137
 
    EXPECT_EQ(empty_list.numHwLayers, mock_device->display0_set_content.numHwLayers);
 
107
    EXPECT_CALL(*mock_native_buffer, update_fence(hwc_return_fence))
 
108
        .Times(1);
 
109
 
 
110
    device.post(*mock_buffer);
 
111
 
 
112
    //set
 
113
    EXPECT_EQ(2, mock_device->display0_set_content.numHwLayers);
138
114
    EXPECT_EQ(-1, mock_device->display0_set_content.retireFenceFd);
139
 
}
140
 
 
141
 
TEST_F(HWC11Device, hwc_device_set_next_frontbuffer_adds_to_layerlist)
142
 
{
143
 
    std::shared_ptr<mg::Buffer> mock_buffer = std::make_shared<mtd::MockBuffer>();
144
 
    EXPECT_CALL(*this->mock_hwc_layers, set_fb_target(mock_buffer))
145
 
        .Times(1);
146
 
 
147
 
    mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
148
 
    device.set_next_frontbuffer(mock_buffer);
149
 
}
150
 
 
151
 
TEST_F(HWC11Device, test_hwc_device_display_config)
152
 
{
153
 
    using namespace testing;
154
 
 
155
 
    unsigned int hwc_configs = 0xA1;
156
 
    EXPECT_CALL(*mock_device, getDisplayConfigs_interface(mock_device.get(),HWC_DISPLAY_PRIMARY,_,Pointee(1)))
157
 
        .Times(1)
158
 
        .WillOnce(DoAll(SetArgPointee<2>(hwc_configs), Return(0)));
159
 
 
160
 
    mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
161
 
}
162
 
 
163
 
 
164
 
//apparently this can happen if the display is in the 'unplugged state'
165
 
TEST_F(HWC11Device, test_hwc_device_display_config_failure_throws)
166
 
{
167
 
    using namespace testing;
168
 
 
169
 
    EXPECT_CALL(*mock_device, getDisplayConfigs_interface(mock_device.get(),HWC_DISPLAY_PRIMARY,_,_))
 
115
    EXPECT_EQ(HWC_FRAMEBUFFER, mock_device->set_layerlist[0].compositionType);
 
116
    EXPECT_EQ(HWC_SKIP_LAYER, mock_device->set_layerlist[0].flags);
 
117
    EXPECT_EQ(HWC_FRAMEBUFFER_TARGET, mock_device->set_layerlist[1].compositionType);
 
118
    EXPECT_EQ(0, mock_device->set_layerlist[1].flags);
 
119
}
 
120
 
 
121
TEST_F(HWC11Device, test_hwc_commit_failure)
 
122
{
 
123
    using namespace testing;
 
124
 
 
125
    mga::HWC11Device device(mock_device, mock_vsync);
 
126
 
 
127
    EXPECT_CALL(*mock_device, set_interface(mock_device.get(), 1, _))
170
128
        .Times(1)
171
129
        .WillOnce(Return(-1));
172
130
 
173
131
    EXPECT_THROW({
174
 
        mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
 
132
        device.post(*mock_buffer);
175
133
    }, std::runtime_error);
176
134
}
177
 
 
178
 
namespace
179
 
{
180
 
static int const display_width = 180;
181
 
static int const display_height = 1010101;
182
 
 
183
 
static int display_attribute_handler(struct hwc_composer_device_1*, int, uint32_t,
184
 
                                     const uint32_t* attribute_list, int32_t* values)
185
 
{
186
 
    EXPECT_EQ(attribute_list[0], HWC_DISPLAY_WIDTH);
187
 
    EXPECT_EQ(attribute_list[1], HWC_DISPLAY_HEIGHT);
188
 
    EXPECT_EQ(attribute_list[2], HWC_DISPLAY_NO_ATTRIBUTE);
189
 
 
190
 
    values[0] = display_width;
191
 
    values[1] = display_height;
192
 
    return 0;
193
 
}
194
 
}
195
 
 
196
 
TEST_F(HWC11Device, test_hwc_device_display_width_height)
197
 
{
198
 
    using namespace testing;
199
 
 
200
 
    int hwc_configs = 0xA1;
201
 
    EXPECT_CALL(*mock_device, getDisplayConfigs_interface(mock_device.get(),HWC_DISPLAY_PRIMARY,_,_))
202
 
        .Times(1)
203
 
        .WillOnce(DoAll(SetArgPointee<2>(hwc_configs), Return(0)));
204
 
    EXPECT_CALL(*mock_device, getDisplayAttributes_interface(mock_device.get(), HWC_DISPLAY_PRIMARY,hwc_configs,_,_))
205
 
        .Times(1)
206
 
        .WillOnce(Invoke(display_attribute_handler));
207
 
 
208
 
    mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
209
 
 
210
 
    auto size = device.display_size();
211
 
    EXPECT_EQ(size.width.as_uint32_t(),  static_cast<unsigned int>(display_width));
212
 
    EXPECT_EQ(size.height.as_uint32_t(), static_cast<unsigned int>(display_height));
213
 
}
214
 
 
215
 
TEST_F(HWC11Device, hwc_device_reports_2_fbs_available_by_default)
216
 
{
217
 
    mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
218
 
    EXPECT_EQ(2u, device.number_of_framebuffers_available());
219
 
}
220
 
 
221
 
TEST_F(HWC11Device, hwc_device_reports_abgr_8888_by_default)
222
 
{
223
 
    mga::HWC11Device device(mock_device, mock_hwc_layers, mock_display_device, mock_vsync);
224
 
    EXPECT_EQ(mir::geometry::PixelFormat::abgr_8888, device.display_format());
225
 
}