blob: 320fddba7802719d33927e581b9f88c0112f9e23 [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);
64 IGraphicBufferProducer::QueueBufferOutput bufferOutput;
65 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070066 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Michael Lentine5a16a622015-05-21 13:48:24 -070067 sp<IBinder> display(sf->getBuiltInDisplay(
68 ISurfaceComposer::eDisplayIdMain));
69 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0,
70 0, INT_MAX, false));
71 *sc = new ScreenCapture(cpuConsumer);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070072 }
73
74 void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) {
Michael Lentine5a16a622015-05-21 13:48:24 -070075 ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mBuf.format);
76 const uint8_t* img = static_cast<const uint8_t*>(mBuf.data);
77 const uint8_t* pixel = img + (4 * (y * mBuf.stride + x));
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070078 if (r != pixel[0] || g != pixel[1] || b != pixel[2]) {
79 String8 err(String8::format("pixel @ (%3d, %3d): "
80 "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
81 x, y, r, g, b, pixel[0], pixel[1], pixel[2]));
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -070082 EXPECT_EQ(String8(), err) << err.string();
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070083 }
84 }
85
86private:
Michael Lentine5a16a622015-05-21 13:48:24 -070087 ScreenCapture(const sp<CpuConsumer>& cc) :
88 mCC(cc) {
89 EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuf));
90 }
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070091
Michael Lentine5a16a622015-05-21 13:48:24 -070092 ~ScreenCapture() {
93 mCC->unlockBuffer(mBuf);
94 }
95
96 sp<CpuConsumer> mCC;
97 CpuConsumer::LockedBuffer mBuf;
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070098};
99
100class LayerUpdateTest : public ::testing::Test {
101protected:
102 virtual void SetUp() {
103 mComposerClient = new SurfaceComposerClient;
104 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
105
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700106 sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(
107 ISurfaceComposer::eDisplayIdMain));
Mathias Agopianc666cae2012-07-25 18:56:13 -0700108 DisplayInfo info;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700109 SurfaceComposerClient::getDisplayInfo(display, &info);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700110
111 ssize_t displayWidth = info.w;
112 ssize_t displayHeight = info.h;
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700113
114 // Background surface
115 mBGSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700116 String8("BG Test Surface"), displayWidth, displayHeight,
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700117 PIXEL_FORMAT_RGBA_8888, 0);
118 ASSERT_TRUE(mBGSurfaceControl != NULL);
119 ASSERT_TRUE(mBGSurfaceControl->isValid());
120 fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195);
121
122 // Foreground surface
123 mFGSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700124 String8("FG Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700125 ASSERT_TRUE(mFGSurfaceControl != NULL);
126 ASSERT_TRUE(mFGSurfaceControl->isValid());
127
128 fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63);
129
130 // Synchronization surface
131 mSyncSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700132 String8("Sync Test Surface"), 1, 1, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700133 ASSERT_TRUE(mSyncSurfaceControl != NULL);
134 ASSERT_TRUE(mSyncSurfaceControl->isValid());
135
136 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
137
138 SurfaceComposerClient::openGlobalTransaction();
139
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700140 mComposerClient->setDisplayLayerStack(display, 0);
141
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700142 ASSERT_EQ(NO_ERROR, mBGSurfaceControl->setLayer(INT_MAX-2));
143 ASSERT_EQ(NO_ERROR, mBGSurfaceControl->show());
144
145 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX-1));
146 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(64, 64));
147 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
148
149 ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setLayer(INT_MAX-1));
150 ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setPosition(displayWidth-2,
151 displayHeight-2));
152 ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->show());
153
154 SurfaceComposerClient::closeGlobalTransaction(true);
155 }
156
157 virtual void TearDown() {
158 mComposerClient->dispose();
159 mBGSurfaceControl = 0;
160 mFGSurfaceControl = 0;
161 mSyncSurfaceControl = 0;
162 mComposerClient = 0;
163 }
164
165 void waitForPostedBuffers() {
166 // Since the sync surface is in synchronous mode (i.e. double buffered)
167 // posting three buffers to it should ensure that at least two
168 // SurfaceFlinger::handlePageFlip calls have been made, which should
169 // guaranteed that a buffer posted to another Surface has been retired.
170 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
171 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
172 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
173 }
174
175 sp<SurfaceComposerClient> mComposerClient;
176 sp<SurfaceControl> mBGSurfaceControl;
177 sp<SurfaceControl> mFGSurfaceControl;
178
179 // This surface is used to ensure that the buffers posted to
180 // mFGSurfaceControl have been picked up by SurfaceFlinger.
181 sp<SurfaceControl> mSyncSurfaceControl;
182};
183
184TEST_F(LayerUpdateTest, LayerMoveWorks) {
185 sp<ScreenCapture> sc;
186 {
187 SCOPED_TRACE("before move");
188 ScreenCapture::captureScreen(&sc);
189 sc->checkPixel( 0, 12, 63, 63, 195);
190 sc->checkPixel( 75, 75, 195, 63, 63);
191 sc->checkPixel(145, 145, 63, 63, 195);
192 }
193
194 SurfaceComposerClient::openGlobalTransaction();
195 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128, 128));
196 SurfaceComposerClient::closeGlobalTransaction(true);
197 {
198 // This should reflect the new position, but not the new color.
199 SCOPED_TRACE("after move, before redraw");
200 ScreenCapture::captureScreen(&sc);
201 sc->checkPixel( 24, 24, 63, 63, 195);
202 sc->checkPixel( 75, 75, 63, 63, 195);
203 sc->checkPixel(145, 145, 195, 63, 63);
204 }
205
206 fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63);
207 waitForPostedBuffers();
208 {
209 // This should reflect the new position and the new color.
210 SCOPED_TRACE("after redraw");
211 ScreenCapture::captureScreen(&sc);
212 sc->checkPixel( 24, 24, 63, 63, 195);
213 sc->checkPixel( 75, 75, 63, 63, 195);
214 sc->checkPixel(145, 145, 63, 195, 63);
215 }
216}
217
218TEST_F(LayerUpdateTest, LayerResizeWorks) {
219 sp<ScreenCapture> sc;
220 {
221 SCOPED_TRACE("before resize");
222 ScreenCapture::captureScreen(&sc);
223 sc->checkPixel( 0, 12, 63, 63, 195);
224 sc->checkPixel( 75, 75, 195, 63, 63);
225 sc->checkPixel(145, 145, 63, 63, 195);
226 }
227
Steve Block9d453682011-12-20 16:23:08 +0000228 ALOGD("resizing");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700229 SurfaceComposerClient::openGlobalTransaction();
230 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setSize(128, 128));
231 SurfaceComposerClient::closeGlobalTransaction(true);
Steve Block9d453682011-12-20 16:23:08 +0000232 ALOGD("resized");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700233 {
234 // This should not reflect the new size or color because SurfaceFlinger
235 // has not yet received a buffer of the correct size.
236 SCOPED_TRACE("after resize, before redraw");
237 ScreenCapture::captureScreen(&sc);
238 sc->checkPixel( 0, 12, 63, 63, 195);
239 sc->checkPixel( 75, 75, 195, 63, 63);
240 sc->checkPixel(145, 145, 63, 63, 195);
241 }
242
Steve Block9d453682011-12-20 16:23:08 +0000243 ALOGD("drawing");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700244 fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63);
245 waitForPostedBuffers();
Steve Block9d453682011-12-20 16:23:08 +0000246 ALOGD("drawn");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700247 {
248 // This should reflect the new size and the new color.
249 SCOPED_TRACE("after redraw");
250 ScreenCapture::captureScreen(&sc);
251 sc->checkPixel( 24, 24, 63, 63, 195);
252 sc->checkPixel( 75, 75, 63, 195, 63);
253 sc->checkPixel(145, 145, 63, 195, 63);
254 }
255}
256
Haixia Shid5750962015-07-27 16:50:49 -0700257TEST_F(LayerUpdateTest, LayerCropWorks) {
258 sp<ScreenCapture> sc;
259 {
260 SCOPED_TRACE("before crop");
261 ScreenCapture::captureScreen(&sc);
262 sc->checkPixel( 24, 24, 63, 63, 195);
263 sc->checkPixel( 75, 75, 195, 63, 63);
264 sc->checkPixel(145, 145, 63, 63, 195);
265 }
266
267 SurfaceComposerClient::openGlobalTransaction();
268 Rect cropRect(16, 16, 32, 32);
269 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setCrop(cropRect));
270 SurfaceComposerClient::closeGlobalTransaction(true);
271 {
272 // This should crop the foreground surface.
273 SCOPED_TRACE("after crop");
274 ScreenCapture::captureScreen(&sc);
275 sc->checkPixel( 24, 24, 63, 63, 195);
276 sc->checkPixel( 75, 75, 63, 63, 195);
277 sc->checkPixel( 95, 80, 195, 63, 63);
278 sc->checkPixel( 80, 95, 195, 63, 63);
279 sc->checkPixel( 96, 96, 63, 63, 195);
280 }
281}
282
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000283TEST_F(LayerUpdateTest, LayerFinalCropWorks) {
284 sp<ScreenCapture> sc;
285 {
286 SCOPED_TRACE("before crop");
287 ScreenCapture::captureScreen(&sc);
288 sc->checkPixel( 24, 24, 63, 63, 195);
289 sc->checkPixel( 75, 75, 195, 63, 63);
290 sc->checkPixel(145, 145, 63, 63, 195);
291 }
292 SurfaceComposerClient::openGlobalTransaction();
293 Rect cropRect(16, 16, 32, 32);
294 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFinalCrop(cropRect));
295 SurfaceComposerClient::closeGlobalTransaction(true);
296 {
297 // This should crop the foreground surface.
298 SCOPED_TRACE("after crop");
299 ScreenCapture::captureScreen(&sc);
300 sc->checkPixel( 24, 24, 63, 63, 195);
301 sc->checkPixel( 75, 75, 63, 63, 195);
302 sc->checkPixel( 95, 80, 63, 63, 195);
303 sc->checkPixel( 80, 95, 63, 63, 195);
304 sc->checkPixel( 96, 96, 63, 63, 195);
305 }
306}
307
Haixia Shid5750962015-07-27 16:50:49 -0700308TEST_F(LayerUpdateTest, LayerSetLayerWorks) {
309 sp<ScreenCapture> sc;
310 {
311 SCOPED_TRACE("before setLayer");
312 ScreenCapture::captureScreen(&sc);
313 sc->checkPixel( 24, 24, 63, 63, 195);
314 sc->checkPixel( 75, 75, 195, 63, 63);
315 sc->checkPixel(145, 145, 63, 63, 195);
316 }
317
318 SurfaceComposerClient::openGlobalTransaction();
319 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX - 3));
320 SurfaceComposerClient::closeGlobalTransaction(true);
321 {
322 // This should hide the foreground surface beneath the background.
323 SCOPED_TRACE("after setLayer");
324 ScreenCapture::captureScreen(&sc);
325 sc->checkPixel( 24, 24, 63, 63, 195);
326 sc->checkPixel( 75, 75, 63, 63, 195);
327 sc->checkPixel(145, 145, 63, 63, 195);
328 }
329}
330
331TEST_F(LayerUpdateTest, LayerShowHideWorks) {
332 sp<ScreenCapture> sc;
333 {
334 SCOPED_TRACE("before hide");
335 ScreenCapture::captureScreen(&sc);
336 sc->checkPixel( 24, 24, 63, 63, 195);
337 sc->checkPixel( 75, 75, 195, 63, 63);
338 sc->checkPixel(145, 145, 63, 63, 195);
339 }
340
341 SurfaceComposerClient::openGlobalTransaction();
342 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->hide());
343 SurfaceComposerClient::closeGlobalTransaction(true);
344 {
345 // This should hide the foreground surface.
346 SCOPED_TRACE("after hide, before show");
347 ScreenCapture::captureScreen(&sc);
348 sc->checkPixel( 24, 24, 63, 63, 195);
349 sc->checkPixel( 75, 75, 63, 63, 195);
350 sc->checkPixel(145, 145, 63, 63, 195);
351 }
352
353 SurfaceComposerClient::openGlobalTransaction();
354 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
355 SurfaceComposerClient::closeGlobalTransaction(true);
356 {
357 // This should show the foreground surface.
358 SCOPED_TRACE("after show");
359 ScreenCapture::captureScreen(&sc);
360 sc->checkPixel( 24, 24, 63, 63, 195);
361 sc->checkPixel( 75, 75, 195, 63, 63);
362 sc->checkPixel(145, 145, 63, 63, 195);
363 }
364}
365
366TEST_F(LayerUpdateTest, LayerSetAlphaWorks) {
367 sp<ScreenCapture> sc;
368 {
369 SCOPED_TRACE("before setAlpha");
370 ScreenCapture::captureScreen(&sc);
371 sc->checkPixel( 24, 24, 63, 63, 195);
372 sc->checkPixel( 75, 75, 195, 63, 63);
373 sc->checkPixel(145, 145, 63, 63, 195);
374 }
375
376 SurfaceComposerClient::openGlobalTransaction();
377 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75f));
378 SurfaceComposerClient::closeGlobalTransaction(true);
379 {
380 // This should set foreground to be 75% opaque.
381 SCOPED_TRACE("after setAlpha");
382 ScreenCapture::captureScreen(&sc);
383 sc->checkPixel( 24, 24, 63, 63, 195);
384 sc->checkPixel( 75, 75, 162, 63, 96);
385 sc->checkPixel(145, 145, 63, 63, 195);
386 }
387}
388
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700389TEST_F(LayerUpdateTest, LayerSetLayerStackWorks) {
390 sp<ScreenCapture> sc;
391 {
392 SCOPED_TRACE("before setLayerStack");
393 ScreenCapture::captureScreen(&sc);
394 sc->checkPixel( 24, 24, 63, 63, 195);
395 sc->checkPixel( 75, 75, 195, 63, 63);
396 sc->checkPixel(145, 145, 63, 63, 195);
397 }
398
399 SurfaceComposerClient::openGlobalTransaction();
400 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayerStack(1));
401 SurfaceComposerClient::closeGlobalTransaction(true);
402 {
403 // This should hide the foreground surface since it goes to a different
404 // layer stack.
405 SCOPED_TRACE("after setLayerStack");
406 ScreenCapture::captureScreen(&sc);
407 sc->checkPixel( 24, 24, 63, 63, 195);
408 sc->checkPixel( 75, 75, 63, 63, 195);
409 sc->checkPixel(145, 145, 63, 63, 195);
410 }
411}
412
413TEST_F(LayerUpdateTest, LayerSetFlagsWorks) {
414 sp<ScreenCapture> sc;
415 {
416 SCOPED_TRACE("before setFlags");
417 ScreenCapture::captureScreen(&sc);
418 sc->checkPixel( 24, 24, 63, 63, 195);
419 sc->checkPixel( 75, 75, 195, 63, 63);
420 sc->checkPixel(145, 145, 63, 63, 195);
421 }
422
423 SurfaceComposerClient::openGlobalTransaction();
424 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFlags(
425 layer_state_t::eLayerHidden, layer_state_t::eLayerHidden));
426 SurfaceComposerClient::closeGlobalTransaction(true);
427 {
428 // This should hide the foreground surface
429 SCOPED_TRACE("after setFlags");
430 ScreenCapture::captureScreen(&sc);
431 sc->checkPixel( 24, 24, 63, 63, 195);
432 sc->checkPixel( 75, 75, 63, 63, 195);
433 sc->checkPixel(145, 145, 63, 63, 195);
434 }
435}
436
437TEST_F(LayerUpdateTest, LayerSetMatrixWorks) {
438 sp<ScreenCapture> sc;
439 {
440 SCOPED_TRACE("before setMatrix");
441 ScreenCapture::captureScreen(&sc);
442 sc->checkPixel( 24, 24, 63, 63, 195);
443 sc->checkPixel( 91, 96, 195, 63, 63);
444 sc->checkPixel( 96, 101, 195, 63, 63);
445 sc->checkPixel(145, 145, 63, 63, 195);
446 }
447
448 SurfaceComposerClient::openGlobalTransaction();
449 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setMatrix(M_SQRT1_2, M_SQRT1_2,
450 -M_SQRT1_2, M_SQRT1_2));
451 SurfaceComposerClient::closeGlobalTransaction(true);
452 {
453 SCOPED_TRACE("after setMatrix");
454 ScreenCapture::captureScreen(&sc);
455 sc->checkPixel( 24, 24, 63, 63, 195);
456 sc->checkPixel( 91, 96, 195, 63, 63);
457 sc->checkPixel( 96, 91, 63, 63, 195);
458 sc->checkPixel(145, 145, 63, 63, 195);
459 }
460}
461
Pablo Ceballos05289c22016-04-14 15:49:55 -0700462TEST_F(LayerUpdateTest, DeferredTransactionTest) {
463 sp<ScreenCapture> sc;
464 {
465 SCOPED_TRACE("before anything");
466 ScreenCapture::captureScreen(&sc);
467 sc->checkPixel( 32, 32, 63, 63, 195);
468 sc->checkPixel( 96, 96, 195, 63, 63);
469 sc->checkPixel(160, 160, 63, 63, 195);
470 }
471
472 // set up two deferred transactions on different frames
473 SurfaceComposerClient::openGlobalTransaction();
474 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75));
475 mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(),
476 mSyncSurfaceControl->getSurface()->getNextFrameNumber());
477 SurfaceComposerClient::closeGlobalTransaction(true);
478
479 SurfaceComposerClient::openGlobalTransaction();
480 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128,128));
481 mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(),
482 mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1);
483 SurfaceComposerClient::closeGlobalTransaction(true);
484
485 {
486 SCOPED_TRACE("before any trigger");
487 ScreenCapture::captureScreen(&sc);
488 sc->checkPixel( 32, 32, 63, 63, 195);
489 sc->checkPixel( 96, 96, 195, 63, 63);
490 sc->checkPixel(160, 160, 63, 63, 195);
491 }
492
493 // should trigger the first deferred transaction, but not the second one
494 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
495 {
496 SCOPED_TRACE("after first trigger");
497 ScreenCapture::captureScreen(&sc);
498 sc->checkPixel( 32, 32, 63, 63, 195);
499 sc->checkPixel( 96, 96, 162, 63, 96);
500 sc->checkPixel(160, 160, 63, 63, 195);
501 }
502
503 // should show up immediately since it's not deferred
504 SurfaceComposerClient::openGlobalTransaction();
505 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(1.0));
506 SurfaceComposerClient::closeGlobalTransaction(true);
507
508 // trigger the second deferred transaction
509 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
510 {
511 SCOPED_TRACE("after second trigger");
512 ScreenCapture::captureScreen(&sc);
513 sc->checkPixel( 32, 32, 63, 63, 195);
514 sc->checkPixel( 96, 96, 63, 63, 195);
515 sc->checkPixel(160, 160, 195, 63, 63);
516 }
517}
518
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700519}