blob: 79cd245bf58f50fe11b3b5b45927103d5c2e4b05 [file] [log] [blame]
Jamie Gennis23c2c5d2011-10-11 19:22:19 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
Michael Lentine5a16a622015-05-21 13:48:24 -070019#include <android/native_window.h>
20
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070021#include <binder/IMemory.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080022
23#include <gui/ISurfaceComposer.h>
24#include <gui/Surface.h>
25#include <gui/SurfaceComposerClient.h>
26#include <private/gui/ComposerService.h>
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -070027#include <private/gui/LayerState.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080028
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070029#include <utils/String8.h>
Mathias Agopianc666cae2012-07-25 18:56:13 -070030#include <ui/DisplayInfo.h>
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070031
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -070032#include <math.h>
33
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070034namespace android {
35
36// Fill an RGBA_8888 formatted surface with a single color.
37static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc,
38 uint8_t r, uint8_t g, uint8_t b) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -080039 ANativeWindow_Buffer outBuffer;
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070040 sp<Surface> s = sc->getSurface();
41 ASSERT_TRUE(s != NULL);
Mathias Agopiane3c697f2013-02-14 17:11:02 -080042 ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, NULL));
43 uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits);
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -070044 for (int y = 0; y < outBuffer.height; y++) {
45 for (int x = 0; x < outBuffer.width; x++) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -080046 uint8_t* pixel = img + (4 * (y*outBuffer.stride + x));
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070047 pixel[0] = r;
48 pixel[1] = g;
49 pixel[2] = b;
50 pixel[3] = 255;
51 }
52 }
53 ASSERT_EQ(NO_ERROR, s->unlockAndPost());
54}
55
56// A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check
57// individual pixel values for testing purposes.
58class ScreenCapture : public RefBase {
59public:
60 static void captureScreen(sp<ScreenCapture>* sc) {
Michael Lentine5a16a622015-05-21 13:48:24 -070061 sp<IGraphicBufferProducer> producer;
62 sp<IGraphicBufferConsumer> consumer;
63 BufferQueue::createBufferQueue(&producer, &consumer);
Michael Lentine5a16a622015-05-21 13:48:24 -070064 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070065 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Michael Lentine5a16a622015-05-21 13:48:24 -070066 sp<IBinder> display(sf->getBuiltInDisplay(
67 ISurfaceComposer::eDisplayIdMain));
Pablo Ceballos15311bd2016-06-01 18:53:40 -070068 SurfaceComposerClient::openGlobalTransaction();
69 SurfaceComposerClient::closeGlobalTransaction(true);
Michael Lentine5a16a622015-05-21 13:48:24 -070070 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0,
71 0, INT_MAX, false));
72 *sc = new ScreenCapture(cpuConsumer);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070073 }
74
75 void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) {
Michael Lentine5a16a622015-05-21 13:48:24 -070076 ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mBuf.format);
77 const uint8_t* img = static_cast<const uint8_t*>(mBuf.data);
78 const uint8_t* pixel = img + (4 * (y * mBuf.stride + x));
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070079 if (r != pixel[0] || g != pixel[1] || b != pixel[2]) {
80 String8 err(String8::format("pixel @ (%3d, %3d): "
81 "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
82 x, y, r, g, b, pixel[0], pixel[1], pixel[2]));
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -070083 EXPECT_EQ(String8(), err) << err.string();
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070084 }
85 }
86
87private:
Michael Lentine5a16a622015-05-21 13:48:24 -070088 ScreenCapture(const sp<CpuConsumer>& cc) :
89 mCC(cc) {
90 EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuf));
91 }
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070092
Michael Lentine5a16a622015-05-21 13:48:24 -070093 ~ScreenCapture() {
94 mCC->unlockBuffer(mBuf);
95 }
96
97 sp<CpuConsumer> mCC;
98 CpuConsumer::LockedBuffer mBuf;
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070099};
100
101class LayerUpdateTest : public ::testing::Test {
102protected:
103 virtual void SetUp() {
104 mComposerClient = new SurfaceComposerClient;
105 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
106
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700107 sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(
108 ISurfaceComposer::eDisplayIdMain));
Mathias Agopianc666cae2012-07-25 18:56:13 -0700109 DisplayInfo info;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700110 SurfaceComposerClient::getDisplayInfo(display, &info);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700111
112 ssize_t displayWidth = info.w;
113 ssize_t displayHeight = info.h;
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700114
115 // Background surface
116 mBGSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700117 String8("BG Test Surface"), displayWidth, displayHeight,
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700118 PIXEL_FORMAT_RGBA_8888, 0);
119 ASSERT_TRUE(mBGSurfaceControl != NULL);
120 ASSERT_TRUE(mBGSurfaceControl->isValid());
121 fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195);
122
123 // Foreground surface
124 mFGSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700125 String8("FG Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700126 ASSERT_TRUE(mFGSurfaceControl != NULL);
127 ASSERT_TRUE(mFGSurfaceControl->isValid());
128
129 fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63);
130
131 // Synchronization surface
132 mSyncSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700133 String8("Sync Test Surface"), 1, 1, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700134 ASSERT_TRUE(mSyncSurfaceControl != NULL);
135 ASSERT_TRUE(mSyncSurfaceControl->isValid());
136
137 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
138
139 SurfaceComposerClient::openGlobalTransaction();
140
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700141 mComposerClient->setDisplayLayerStack(display, 0);
142
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700143 ASSERT_EQ(NO_ERROR, mBGSurfaceControl->setLayer(INT_MAX-2));
144 ASSERT_EQ(NO_ERROR, mBGSurfaceControl->show());
145
146 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX-1));
147 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(64, 64));
148 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
149
150 ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setLayer(INT_MAX-1));
151 ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setPosition(displayWidth-2,
152 displayHeight-2));
153 ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->show());
154
155 SurfaceComposerClient::closeGlobalTransaction(true);
156 }
157
158 virtual void TearDown() {
159 mComposerClient->dispose();
160 mBGSurfaceControl = 0;
161 mFGSurfaceControl = 0;
162 mSyncSurfaceControl = 0;
163 mComposerClient = 0;
164 }
165
166 void waitForPostedBuffers() {
167 // Since the sync surface is in synchronous mode (i.e. double buffered)
168 // posting three buffers to it should ensure that at least two
169 // SurfaceFlinger::handlePageFlip calls have been made, which should
170 // guaranteed that a buffer posted to another Surface has been retired.
171 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
172 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
173 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
174 }
175
176 sp<SurfaceComposerClient> mComposerClient;
177 sp<SurfaceControl> mBGSurfaceControl;
178 sp<SurfaceControl> mFGSurfaceControl;
179
180 // This surface is used to ensure that the buffers posted to
181 // mFGSurfaceControl have been picked up by SurfaceFlinger.
182 sp<SurfaceControl> mSyncSurfaceControl;
183};
184
185TEST_F(LayerUpdateTest, LayerMoveWorks) {
186 sp<ScreenCapture> sc;
187 {
188 SCOPED_TRACE("before move");
189 ScreenCapture::captureScreen(&sc);
190 sc->checkPixel( 0, 12, 63, 63, 195);
191 sc->checkPixel( 75, 75, 195, 63, 63);
192 sc->checkPixel(145, 145, 63, 63, 195);
193 }
194
195 SurfaceComposerClient::openGlobalTransaction();
196 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128, 128));
197 SurfaceComposerClient::closeGlobalTransaction(true);
198 {
199 // This should reflect the new position, but not the new color.
200 SCOPED_TRACE("after move, before redraw");
201 ScreenCapture::captureScreen(&sc);
202 sc->checkPixel( 24, 24, 63, 63, 195);
203 sc->checkPixel( 75, 75, 63, 63, 195);
204 sc->checkPixel(145, 145, 195, 63, 63);
205 }
206
207 fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63);
208 waitForPostedBuffers();
209 {
210 // This should reflect the new position and the new color.
211 SCOPED_TRACE("after redraw");
212 ScreenCapture::captureScreen(&sc);
213 sc->checkPixel( 24, 24, 63, 63, 195);
214 sc->checkPixel( 75, 75, 63, 63, 195);
215 sc->checkPixel(145, 145, 63, 195, 63);
216 }
217}
218
219TEST_F(LayerUpdateTest, LayerResizeWorks) {
220 sp<ScreenCapture> sc;
221 {
222 SCOPED_TRACE("before resize");
223 ScreenCapture::captureScreen(&sc);
224 sc->checkPixel( 0, 12, 63, 63, 195);
225 sc->checkPixel( 75, 75, 195, 63, 63);
226 sc->checkPixel(145, 145, 63, 63, 195);
227 }
228
Steve Block9d453682011-12-20 16:23:08 +0000229 ALOGD("resizing");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700230 SurfaceComposerClient::openGlobalTransaction();
231 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setSize(128, 128));
232 SurfaceComposerClient::closeGlobalTransaction(true);
Steve Block9d453682011-12-20 16:23:08 +0000233 ALOGD("resized");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700234 {
235 // This should not reflect the new size or color because SurfaceFlinger
236 // has not yet received a buffer of the correct size.
237 SCOPED_TRACE("after resize, before redraw");
238 ScreenCapture::captureScreen(&sc);
239 sc->checkPixel( 0, 12, 63, 63, 195);
240 sc->checkPixel( 75, 75, 195, 63, 63);
241 sc->checkPixel(145, 145, 63, 63, 195);
242 }
243
Steve Block9d453682011-12-20 16:23:08 +0000244 ALOGD("drawing");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700245 fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63);
246 waitForPostedBuffers();
Steve Block9d453682011-12-20 16:23:08 +0000247 ALOGD("drawn");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700248 {
249 // This should reflect the new size and the new color.
250 SCOPED_TRACE("after redraw");
251 ScreenCapture::captureScreen(&sc);
252 sc->checkPixel( 24, 24, 63, 63, 195);
253 sc->checkPixel( 75, 75, 63, 195, 63);
254 sc->checkPixel(145, 145, 63, 195, 63);
255 }
256}
257
Haixia Shid5750962015-07-27 16:50:49 -0700258TEST_F(LayerUpdateTest, LayerCropWorks) {
259 sp<ScreenCapture> sc;
260 {
261 SCOPED_TRACE("before crop");
262 ScreenCapture::captureScreen(&sc);
263 sc->checkPixel( 24, 24, 63, 63, 195);
264 sc->checkPixel( 75, 75, 195, 63, 63);
265 sc->checkPixel(145, 145, 63, 63, 195);
266 }
267
268 SurfaceComposerClient::openGlobalTransaction();
269 Rect cropRect(16, 16, 32, 32);
270 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setCrop(cropRect));
271 SurfaceComposerClient::closeGlobalTransaction(true);
272 {
273 // This should crop the foreground surface.
274 SCOPED_TRACE("after crop");
275 ScreenCapture::captureScreen(&sc);
276 sc->checkPixel( 24, 24, 63, 63, 195);
277 sc->checkPixel( 75, 75, 63, 63, 195);
278 sc->checkPixel( 95, 80, 195, 63, 63);
279 sc->checkPixel( 80, 95, 195, 63, 63);
280 sc->checkPixel( 96, 96, 63, 63, 195);
281 }
282}
283
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000284TEST_F(LayerUpdateTest, LayerFinalCropWorks) {
285 sp<ScreenCapture> sc;
286 {
287 SCOPED_TRACE("before crop");
288 ScreenCapture::captureScreen(&sc);
289 sc->checkPixel( 24, 24, 63, 63, 195);
290 sc->checkPixel( 75, 75, 195, 63, 63);
291 sc->checkPixel(145, 145, 63, 63, 195);
292 }
293 SurfaceComposerClient::openGlobalTransaction();
294 Rect cropRect(16, 16, 32, 32);
295 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFinalCrop(cropRect));
296 SurfaceComposerClient::closeGlobalTransaction(true);
297 {
298 // This should crop the foreground surface.
299 SCOPED_TRACE("after crop");
300 ScreenCapture::captureScreen(&sc);
301 sc->checkPixel( 24, 24, 63, 63, 195);
302 sc->checkPixel( 75, 75, 63, 63, 195);
303 sc->checkPixel( 95, 80, 63, 63, 195);
304 sc->checkPixel( 80, 95, 63, 63, 195);
305 sc->checkPixel( 96, 96, 63, 63, 195);
306 }
307}
308
Haixia Shid5750962015-07-27 16:50:49 -0700309TEST_F(LayerUpdateTest, LayerSetLayerWorks) {
310 sp<ScreenCapture> sc;
311 {
312 SCOPED_TRACE("before setLayer");
313 ScreenCapture::captureScreen(&sc);
314 sc->checkPixel( 24, 24, 63, 63, 195);
315 sc->checkPixel( 75, 75, 195, 63, 63);
316 sc->checkPixel(145, 145, 63, 63, 195);
317 }
318
319 SurfaceComposerClient::openGlobalTransaction();
320 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX - 3));
321 SurfaceComposerClient::closeGlobalTransaction(true);
322 {
323 // This should hide the foreground surface beneath the background.
324 SCOPED_TRACE("after setLayer");
325 ScreenCapture::captureScreen(&sc);
326 sc->checkPixel( 24, 24, 63, 63, 195);
327 sc->checkPixel( 75, 75, 63, 63, 195);
328 sc->checkPixel(145, 145, 63, 63, 195);
329 }
330}
331
332TEST_F(LayerUpdateTest, LayerShowHideWorks) {
333 sp<ScreenCapture> sc;
334 {
335 SCOPED_TRACE("before hide");
336 ScreenCapture::captureScreen(&sc);
337 sc->checkPixel( 24, 24, 63, 63, 195);
338 sc->checkPixel( 75, 75, 195, 63, 63);
339 sc->checkPixel(145, 145, 63, 63, 195);
340 }
341
342 SurfaceComposerClient::openGlobalTransaction();
343 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->hide());
344 SurfaceComposerClient::closeGlobalTransaction(true);
345 {
346 // This should hide the foreground surface.
347 SCOPED_TRACE("after hide, before show");
348 ScreenCapture::captureScreen(&sc);
349 sc->checkPixel( 24, 24, 63, 63, 195);
350 sc->checkPixel( 75, 75, 63, 63, 195);
351 sc->checkPixel(145, 145, 63, 63, 195);
352 }
353
354 SurfaceComposerClient::openGlobalTransaction();
355 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
356 SurfaceComposerClient::closeGlobalTransaction(true);
357 {
358 // This should show the foreground surface.
359 SCOPED_TRACE("after show");
360 ScreenCapture::captureScreen(&sc);
361 sc->checkPixel( 24, 24, 63, 63, 195);
362 sc->checkPixel( 75, 75, 195, 63, 63);
363 sc->checkPixel(145, 145, 63, 63, 195);
364 }
365}
366
367TEST_F(LayerUpdateTest, LayerSetAlphaWorks) {
368 sp<ScreenCapture> sc;
369 {
370 SCOPED_TRACE("before setAlpha");
371 ScreenCapture::captureScreen(&sc);
372 sc->checkPixel( 24, 24, 63, 63, 195);
373 sc->checkPixel( 75, 75, 195, 63, 63);
374 sc->checkPixel(145, 145, 63, 63, 195);
375 }
376
377 SurfaceComposerClient::openGlobalTransaction();
378 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75f));
379 SurfaceComposerClient::closeGlobalTransaction(true);
380 {
381 // This should set foreground to be 75% opaque.
382 SCOPED_TRACE("after setAlpha");
383 ScreenCapture::captureScreen(&sc);
384 sc->checkPixel( 24, 24, 63, 63, 195);
385 sc->checkPixel( 75, 75, 162, 63, 96);
386 sc->checkPixel(145, 145, 63, 63, 195);
387 }
388}
389
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700390TEST_F(LayerUpdateTest, LayerSetLayerStackWorks) {
391 sp<ScreenCapture> sc;
392 {
393 SCOPED_TRACE("before setLayerStack");
394 ScreenCapture::captureScreen(&sc);
395 sc->checkPixel( 24, 24, 63, 63, 195);
396 sc->checkPixel( 75, 75, 195, 63, 63);
397 sc->checkPixel(145, 145, 63, 63, 195);
398 }
399
400 SurfaceComposerClient::openGlobalTransaction();
401 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayerStack(1));
402 SurfaceComposerClient::closeGlobalTransaction(true);
403 {
404 // This should hide the foreground surface since it goes to a different
405 // layer stack.
406 SCOPED_TRACE("after setLayerStack");
407 ScreenCapture::captureScreen(&sc);
408 sc->checkPixel( 24, 24, 63, 63, 195);
409 sc->checkPixel( 75, 75, 63, 63, 195);
410 sc->checkPixel(145, 145, 63, 63, 195);
411 }
412}
413
414TEST_F(LayerUpdateTest, LayerSetFlagsWorks) {
415 sp<ScreenCapture> sc;
416 {
417 SCOPED_TRACE("before setFlags");
418 ScreenCapture::captureScreen(&sc);
419 sc->checkPixel( 24, 24, 63, 63, 195);
420 sc->checkPixel( 75, 75, 195, 63, 63);
421 sc->checkPixel(145, 145, 63, 63, 195);
422 }
423
424 SurfaceComposerClient::openGlobalTransaction();
425 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFlags(
426 layer_state_t::eLayerHidden, layer_state_t::eLayerHidden));
427 SurfaceComposerClient::closeGlobalTransaction(true);
428 {
429 // This should hide the foreground surface
430 SCOPED_TRACE("after setFlags");
431 ScreenCapture::captureScreen(&sc);
432 sc->checkPixel( 24, 24, 63, 63, 195);
433 sc->checkPixel( 75, 75, 63, 63, 195);
434 sc->checkPixel(145, 145, 63, 63, 195);
435 }
436}
437
438TEST_F(LayerUpdateTest, LayerSetMatrixWorks) {
439 sp<ScreenCapture> sc;
440 {
441 SCOPED_TRACE("before setMatrix");
442 ScreenCapture::captureScreen(&sc);
443 sc->checkPixel( 24, 24, 63, 63, 195);
444 sc->checkPixel( 91, 96, 195, 63, 63);
445 sc->checkPixel( 96, 101, 195, 63, 63);
446 sc->checkPixel(145, 145, 63, 63, 195);
447 }
448
449 SurfaceComposerClient::openGlobalTransaction();
450 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setMatrix(M_SQRT1_2, M_SQRT1_2,
451 -M_SQRT1_2, M_SQRT1_2));
452 SurfaceComposerClient::closeGlobalTransaction(true);
453 {
454 SCOPED_TRACE("after setMatrix");
455 ScreenCapture::captureScreen(&sc);
456 sc->checkPixel( 24, 24, 63, 63, 195);
457 sc->checkPixel( 91, 96, 195, 63, 63);
458 sc->checkPixel( 96, 91, 63, 63, 195);
459 sc->checkPixel(145, 145, 63, 63, 195);
460 }
461}
462
Pablo Ceballos05289c22016-04-14 15:49:55 -0700463TEST_F(LayerUpdateTest, DeferredTransactionTest) {
464 sp<ScreenCapture> sc;
465 {
466 SCOPED_TRACE("before anything");
467 ScreenCapture::captureScreen(&sc);
468 sc->checkPixel( 32, 32, 63, 63, 195);
469 sc->checkPixel( 96, 96, 195, 63, 63);
470 sc->checkPixel(160, 160, 63, 63, 195);
471 }
472
473 // set up two deferred transactions on different frames
474 SurfaceComposerClient::openGlobalTransaction();
475 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75));
476 mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(),
477 mSyncSurfaceControl->getSurface()->getNextFrameNumber());
478 SurfaceComposerClient::closeGlobalTransaction(true);
479
480 SurfaceComposerClient::openGlobalTransaction();
481 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128,128));
482 mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(),
483 mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1);
484 SurfaceComposerClient::closeGlobalTransaction(true);
485
486 {
487 SCOPED_TRACE("before any trigger");
488 ScreenCapture::captureScreen(&sc);
489 sc->checkPixel( 32, 32, 63, 63, 195);
490 sc->checkPixel( 96, 96, 195, 63, 63);
491 sc->checkPixel(160, 160, 63, 63, 195);
492 }
493
494 // should trigger the first deferred transaction, but not the second one
495 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
496 {
497 SCOPED_TRACE("after first trigger");
498 ScreenCapture::captureScreen(&sc);
499 sc->checkPixel( 32, 32, 63, 63, 195);
500 sc->checkPixel( 96, 96, 162, 63, 96);
501 sc->checkPixel(160, 160, 63, 63, 195);
502 }
503
504 // should show up immediately since it's not deferred
505 SurfaceComposerClient::openGlobalTransaction();
506 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(1.0));
507 SurfaceComposerClient::closeGlobalTransaction(true);
508
509 // trigger the second deferred transaction
510 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
511 {
512 SCOPED_TRACE("after second trigger");
513 ScreenCapture::captureScreen(&sc);
514 sc->checkPixel( 32, 32, 63, 63, 195);
515 sc->checkPixel( 96, 96, 63, 63, 195);
516 sc->checkPixel(160, 160, 195, 63, 63);
517 }
518}
519
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700520}