~albaguirre/mir/backport-fixes-to-0.11

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Kevin DuBois
  • Date: 2015-01-29 16:35:31 UTC
  • mfrom: (2215.3.26 pull-list-from-device)
  • Revision ID: tarmac-20150129163531-oklyqevk921mxuq3
android: pull the mga::LayerList instance from the mga::HwcDevice to the mga::DisplayBuffer.

Approved by Alan Griffiths, Alexandros Frantzis, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
            display_size, refresh_rate, mir_pixel_format_abgr_8888)};
70
70
    MirOrientation orientation{mir_orientation_normal};
71
71
    mga::DisplayBuffer db{
 
72
        std::unique_ptr<mga::LayerList>(
 
73
            new mga::LayerList(std::make_shared<mga::IntegerSourceCrop>(), {})),
72
74
        mock_fb_bundle,
73
75
        mock_display_device,
74
76
        native_window,
81
83
 
82
84
TEST_F(DisplayBuffer, can_post_update_with_gl_only)
83
85
{
84
 
    EXPECT_CALL(*mock_display_device, post_gl(testing::_));
 
86
    using namespace testing;
 
87
    std::unique_ptr<mga::LayerList> list(new mga::LayerList(std::make_shared<mga::IntegerSourceCrop>(), {}));
 
88
    EXPECT_CALL(*mock_display_device, commit(
 
89
        mga::DisplayName::primary, Ref(*list), _, _));
 
90
 
 
91
    mga::DisplayBuffer db{
 
92
        std::move(list),
 
93
        mock_fb_bundle,
 
94
        mock_display_device,
 
95
        native_window,
 
96
        *gl_context,
 
97
        stub_program_factory,
 
98
        orientation,
 
99
        mga::OverlayOptimization::enabled};
 
100
 
85
101
    db.gl_swap_buffers();
86
102
    db.flip();
87
103
}
93
109
        std::make_shared<mtd::StubRenderable>(),
94
110
        std::make_shared<mtd::StubRenderable>()};
95
111
 
96
 
    EXPECT_CALL(*mock_display_device, post_overlays(_, Ref(renderlist), _))
 
112
    EXPECT_CALL(*mock_display_device, compatible_renderlist(Ref(renderlist)))
97
113
        .Times(2)
98
114
        .WillOnce(Return(true))
99
115
        .WillOnce(Return(false));
102
118
    EXPECT_FALSE(db.post_renderables_if_optimizable(renderlist)); 
103
119
}
104
120
 
 
121
TEST_F(DisplayBuffer, defaults_to_normal_orientation)
 
122
{
 
123
    EXPECT_EQ(mir_orientation_normal, db.orientation());
 
124
}
 
125
 
105
126
TEST_F(DisplayBuffer, rotation_transposes_dimensions_and_reports_correctly)
106
127
{
107
128
    geom::Size const transposed{display_size.height.as_int(), display_size.width.as_int()};
108
 
    mga::DisplayBuffer inv_db(
109
 
        mock_fb_bundle,
110
 
        mock_display_device,
111
 
        native_window,
112
 
        *gl_context,
113
 
        stub_program_factory,
114
 
        mir_orientation_inverted,
115
 
        mga::OverlayOptimization::enabled);
116
 
    mga::DisplayBuffer left_db(
117
 
        mock_fb_bundle,
118
 
        mock_display_device,
119
 
        native_window,
120
 
        *gl_context,
121
 
        stub_program_factory,
122
 
        mir_orientation_left,
123
 
        mga::OverlayOptimization::enabled);
124
 
    mga::DisplayBuffer right_db(
125
 
        mock_fb_bundle,
126
 
        mock_display_device,
127
 
        native_window,
128
 
        *gl_context,
129
 
        stub_program_factory,
130
 
        mir_orientation_right,
131
 
        mga::OverlayOptimization::enabled);
132
 
 
133
129
    EXPECT_EQ(display_size, db.view_area().size);
134
130
    EXPECT_EQ(db.orientation(), mir_orientation_normal);
135
 
 
136
 
    EXPECT_EQ(display_size, inv_db.view_area().size);
137
 
    EXPECT_EQ(inv_db.orientation(), mir_orientation_inverted);
138
 
 
139
 
    EXPECT_EQ(transposed, left_db.view_area().size);
140
 
    EXPECT_EQ(left_db.orientation(), mir_orientation_left);
141
 
 
142
 
    EXPECT_EQ(transposed, right_db.view_area().size);
143
 
    EXPECT_EQ(right_db.orientation(), mir_orientation_right);
 
131
    db.configure(mir_power_mode_on, mir_orientation_inverted);
 
132
 
 
133
    EXPECT_EQ(display_size, db.view_area().size);
 
134
    EXPECT_EQ(db.orientation(), mir_orientation_inverted);
 
135
    db.configure(mir_power_mode_on, mir_orientation_left);
 
136
 
 
137
    EXPECT_EQ(transposed, db.view_area().size);
 
138
    EXPECT_EQ(db.orientation(), mir_orientation_left);
 
139
    db.configure(mir_power_mode_on, mir_orientation_right);
 
140
 
 
141
    EXPECT_EQ(transposed, db.view_area().size);
 
142
    EXPECT_EQ(db.orientation(), mir_orientation_right);
144
143
}
145
144
 
146
145
TEST_F(DisplayBuffer, reports_correct_size)
153
152
 
154
153
TEST_F(DisplayBuffer, creates_egl_context_from_shared_context)
155
154
{
 
155
    testing::Mock::VerifyAndClearExpectations(&mock_egl);
 
156
 
156
157
    using namespace testing;
157
158
    EGLint const expected_attr[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
158
159
 
170
171
        .Times(AtLeast(1));
171
172
 
172
173
    mga::DisplayBuffer db{
 
174
        std::unique_ptr<mga::LayerList>(
 
175
            new mga::LayerList(std::make_shared<mga::IntegerSourceCrop>(), {})),
173
176
        mock_fb_bundle,
174
177
        mock_display_device,
175
178
        native_window,
193
196
 
194
197
    EXPECT_THROW({
195
198
        mga::DisplayBuffer db(
 
199
            std::unique_ptr<mga::LayerList>(
 
200
                new mga::LayerList(std::make_shared<mga::IntegerSourceCrop>(), {})),
196
201
            mock_fb_bundle,
197
202
            mock_display_device,
198
203
            native_window,
201
206
            orientation,
202
207
            mga::OverlayOptimization::enabled);
203
208
    }, std::runtime_error);
 
209
 
204
210
    EXPECT_THROW({
205
211
        mga::DisplayBuffer db(
 
212
            std::unique_ptr<mga::LayerList>(
 
213
                new mga::LayerList(std::make_shared<mga::IntegerSourceCrop>(), {})),
206
214
            mock_fb_bundle,
207
215
            mock_display_device,
208
216
            native_window,
215
223
 
216
224
TEST_F(DisplayBuffer, can_make_current)
217
225
{
 
226
    using namespace testing;
218
227
    EXPECT_CALL(mock_egl, eglMakeCurrent(
219
228
        dummy_display, mock_egl.fake_egl_surface, mock_egl.fake_egl_surface, dummy_context))
220
229
        .Times(2)
250
259
 
251
260
TEST_F(DisplayBuffer, reject_list_if_option_disabled)
252
261
{
 
262
    using namespace testing;
 
263
    ON_CALL(*mock_display_device, compatible_renderlist(_))
 
264
        .WillByDefault(Return(true));
 
265
 
253
266
    mg::RenderableList renderlist{std::make_shared<mtd::StubRenderable>()};
254
267
    mga::DisplayBuffer db(
 
268
        std::unique_ptr<mga::LayerList>(
 
269
            new mga::LayerList(std::make_shared<mga::IntegerSourceCrop>(), {})),
255
270
        mock_fb_bundle,
256
271
        mock_display_device,
257
272
        native_window,
262
277
 
263
278
    EXPECT_FALSE(db.post_renderables_if_optimizable(renderlist)); 
264
279
}
 
280
 
 
281
TEST_F(DisplayBuffer, rejects_commit_if_list_doesnt_need_commit)
 
282
{
 
283
    using namespace testing;
 
284
    auto buffer1 = std::make_shared<mtd::StubRenderable>();
 
285
    auto buffer2 = std::make_shared<mtd::StubRenderable>();
 
286
    auto buffer3 = std::make_shared<mtd::StubRenderable>();
 
287
 
 
288
    ON_CALL(*mock_display_device, compatible_renderlist(_))
 
289
        .WillByDefault(Return(true));
 
290
    ON_CALL(*mock_display_device, commit(_,_,_,_))
 
291
        .WillByDefault(Invoke([](
 
292
            mga::DisplayName,
 
293
            mga::LayerList& list,
 
294
            mga::SwappingGLContext const&,
 
295
            mga::RenderableListCompositor const&)
 
296
        {
 
297
            auto native_list = list.native_list();
 
298
            for (auto i = 0u; i < native_list->numHwLayers; i++)
 
299
            {
 
300
                if (native_list->hwLayers[i].compositionType == HWC_FRAMEBUFFER)
 
301
                    native_list->hwLayers[i].compositionType = HWC_OVERLAY;
 
302
            }
 
303
        }));
 
304
 
 
305
    mg::RenderableList renderlist{buffer1, buffer2};
 
306
    EXPECT_TRUE(db.post_renderables_if_optimizable(renderlist)); 
 
307
    EXPECT_FALSE(db.post_renderables_if_optimizable(renderlist)); 
 
308
 
 
309
    renderlist = mg::RenderableList{buffer2, buffer1}; //ordering changed
 
310
    EXPECT_TRUE(db.post_renderables_if_optimizable(renderlist)); 
 
311
    EXPECT_FALSE(db.post_renderables_if_optimizable(renderlist)); 
 
312
 
 
313
    renderlist = mg::RenderableList{buffer3, buffer1}; //buffer changed
 
314
    EXPECT_TRUE(db.post_renderables_if_optimizable(renderlist)); 
 
315
    EXPECT_FALSE(db.post_renderables_if_optimizable(renderlist)); 
 
316
}