blob: 1b17e55b30109665fe317877bd15d67f038b76f2 [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
Mathias Agopian90ac7992012-02-25 18:48:35 -080021#include <gui/ISurfaceComposer.h>
22#include <gui/Surface.h>
23#include <gui/SurfaceComposerClient.h>
24#include <private/gui/ComposerService.h>
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -070025#include <private/gui/LayerState.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080026
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070027#include <utils/String8.h>
Mathias Agopianc666cae2012-07-25 18:56:13 -070028#include <ui/DisplayInfo.h>
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070029
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -070030#include <math.h>
31
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070032namespace android {
33
34// Fill an RGBA_8888 formatted surface with a single color.
35static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc,
36 uint8_t r, uint8_t g, uint8_t b) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -080037 ANativeWindow_Buffer outBuffer;
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070038 sp<Surface> s = sc->getSurface();
39 ASSERT_TRUE(s != NULL);
Mathias Agopiane3c697f2013-02-14 17:11:02 -080040 ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, NULL));
41 uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits);
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -070042 for (int y = 0; y < outBuffer.height; y++) {
43 for (int x = 0; x < outBuffer.width; x++) {
Mathias Agopiane3c697f2013-02-14 17:11:02 -080044 uint8_t* pixel = img + (4 * (y*outBuffer.stride + x));
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070045 pixel[0] = r;
46 pixel[1] = g;
47 pixel[2] = b;
48 pixel[3] = 255;
49 }
50 }
51 ASSERT_EQ(NO_ERROR, s->unlockAndPost());
52}
53
54// A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check
55// individual pixel values for testing purposes.
56class ScreenCapture : public RefBase {
57public:
58 static void captureScreen(sp<ScreenCapture>* sc) {
Michael Lentine5a16a622015-05-21 13:48:24 -070059 sp<IGraphicBufferProducer> producer;
60 sp<IGraphicBufferConsumer> consumer;
61 BufferQueue::createBufferQueue(&producer, &consumer);
Michael Lentine5a16a622015-05-21 13:48:24 -070062 sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070063 sp<ISurfaceComposer> sf(ComposerService::getComposerService());
Michael Lentine5a16a622015-05-21 13:48:24 -070064 sp<IBinder> display(sf->getBuiltInDisplay(
65 ISurfaceComposer::eDisplayIdMain));
Pablo Ceballos15311bd2016-06-01 18:53:40 -070066 SurfaceComposerClient::openGlobalTransaction();
67 SurfaceComposerClient::closeGlobalTransaction(true);
Michael Lentine5a16a622015-05-21 13:48:24 -070068 ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0,
69 0, INT_MAX, false));
70 *sc = new ScreenCapture(cpuConsumer);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070071 }
72
73 void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) {
Michael Lentine5a16a622015-05-21 13:48:24 -070074 ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mBuf.format);
75 const uint8_t* img = static_cast<const uint8_t*>(mBuf.data);
76 const uint8_t* pixel = img + (4 * (y * mBuf.stride + x));
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070077 if (r != pixel[0] || g != pixel[1] || b != pixel[2]) {
78 String8 err(String8::format("pixel @ (%3d, %3d): "
79 "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]",
80 x, y, r, g, b, pixel[0], pixel[1], pixel[2]));
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -070081 EXPECT_EQ(String8(), err) << err.string();
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070082 }
83 }
84
Robert Carr1f0a16a2016-10-24 16:27:39 -070085 void expectFGColor(uint32_t x, uint32_t y) {
86 checkPixel(x, y, 195, 63, 63);
87 }
88
89 void expectBGColor(uint32_t x, uint32_t y) {
90 checkPixel(x, y, 63, 63, 195);
91 }
92
93 void expectChildColor(uint32_t x, uint32_t y) {
94 checkPixel(x, y, 200, 200, 200);
95 }
96
Jamie Gennis23c2c5d2011-10-11 19:22:19 -070097private:
Michael Lentine5a16a622015-05-21 13:48:24 -070098 ScreenCapture(const sp<CpuConsumer>& cc) :
99 mCC(cc) {
100 EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuf));
101 }
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700102
Michael Lentine5a16a622015-05-21 13:48:24 -0700103 ~ScreenCapture() {
104 mCC->unlockBuffer(mBuf);
105 }
106
107 sp<CpuConsumer> mCC;
108 CpuConsumer::LockedBuffer mBuf;
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700109};
110
111class LayerUpdateTest : public ::testing::Test {
112protected:
113 virtual void SetUp() {
114 mComposerClient = new SurfaceComposerClient;
115 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
116
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700117 sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(
118 ISurfaceComposer::eDisplayIdMain));
Mathias Agopianc666cae2012-07-25 18:56:13 -0700119 DisplayInfo info;
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700120 SurfaceComposerClient::getDisplayInfo(display, &info);
Mathias Agopianc666cae2012-07-25 18:56:13 -0700121
122 ssize_t displayWidth = info.w;
123 ssize_t displayHeight = info.h;
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700124
125 // Background surface
126 mBGSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700127 String8("BG Test Surface"), displayWidth, displayHeight,
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700128 PIXEL_FORMAT_RGBA_8888, 0);
129 ASSERT_TRUE(mBGSurfaceControl != NULL);
130 ASSERT_TRUE(mBGSurfaceControl->isValid());
131 fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195);
132
133 // Foreground surface
134 mFGSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700135 String8("FG Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700136 ASSERT_TRUE(mFGSurfaceControl != NULL);
137 ASSERT_TRUE(mFGSurfaceControl->isValid());
138
139 fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63);
140
141 // Synchronization surface
142 mSyncSurfaceControl = mComposerClient->createSurface(
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700143 String8("Sync Test Surface"), 1, 1, PIXEL_FORMAT_RGBA_8888, 0);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700144 ASSERT_TRUE(mSyncSurfaceControl != NULL);
145 ASSERT_TRUE(mSyncSurfaceControl->isValid());
146
147 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
148
149 SurfaceComposerClient::openGlobalTransaction();
150
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700151 mComposerClient->setDisplayLayerStack(display, 0);
152
Robert Carr1f0a16a2016-10-24 16:27:39 -0700153 ASSERT_EQ(NO_ERROR, mBGSurfaceControl->setLayer(INT32_MAX-2));
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700154 ASSERT_EQ(NO_ERROR, mBGSurfaceControl->show());
155
Robert Carr1f0a16a2016-10-24 16:27:39 -0700156 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT32_MAX-1));
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700157 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(64, 64));
158 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
159
Robert Carr1f0a16a2016-10-24 16:27:39 -0700160 ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setLayer(INT32_MAX-1));
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700161 ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setPosition(displayWidth-2,
162 displayHeight-2));
163 ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->show());
164
165 SurfaceComposerClient::closeGlobalTransaction(true);
166 }
167
168 virtual void TearDown() {
169 mComposerClient->dispose();
170 mBGSurfaceControl = 0;
171 mFGSurfaceControl = 0;
172 mSyncSurfaceControl = 0;
173 mComposerClient = 0;
174 }
175
176 void waitForPostedBuffers() {
177 // Since the sync surface is in synchronous mode (i.e. double buffered)
178 // posting three buffers to it should ensure that at least two
179 // SurfaceFlinger::handlePageFlip calls have been made, which should
180 // guaranteed that a buffer posted to another Surface has been retired.
181 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
182 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
183 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
184 }
185
186 sp<SurfaceComposerClient> mComposerClient;
187 sp<SurfaceControl> mBGSurfaceControl;
188 sp<SurfaceControl> mFGSurfaceControl;
189
190 // This surface is used to ensure that the buffers posted to
191 // mFGSurfaceControl have been picked up by SurfaceFlinger.
192 sp<SurfaceControl> mSyncSurfaceControl;
193};
194
195TEST_F(LayerUpdateTest, LayerMoveWorks) {
196 sp<ScreenCapture> sc;
197 {
198 SCOPED_TRACE("before move");
199 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800200 sc->expectBGColor(0, 12);
201 sc->expectFGColor(75, 75);
202 sc->expectBGColor(145, 145);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700203 }
204
205 SurfaceComposerClient::openGlobalTransaction();
206 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128, 128));
207 SurfaceComposerClient::closeGlobalTransaction(true);
208 {
209 // This should reflect the new position, but not the new color.
210 SCOPED_TRACE("after move, before redraw");
211 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800212 sc->expectBGColor(24, 24);
213 sc->expectBGColor(75, 75);
214 sc->expectFGColor(145, 145);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700215 }
216
217 fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63);
218 waitForPostedBuffers();
219 {
220 // This should reflect the new position and the new color.
221 SCOPED_TRACE("after redraw");
222 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800223 sc->expectBGColor(24, 24);
224 sc->expectBGColor(75, 75);
225 sc->checkPixel(145, 145, 63, 195, 63);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700226 }
227}
228
229TEST_F(LayerUpdateTest, LayerResizeWorks) {
230 sp<ScreenCapture> sc;
231 {
232 SCOPED_TRACE("before resize");
233 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800234 sc->expectBGColor(0, 12);
235 sc->expectFGColor(75, 75);
236 sc->expectBGColor(145, 145);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700237 }
238
Steve Block9d453682011-12-20 16:23:08 +0000239 ALOGD("resizing");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700240 SurfaceComposerClient::openGlobalTransaction();
241 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setSize(128, 128));
242 SurfaceComposerClient::closeGlobalTransaction(true);
Steve Block9d453682011-12-20 16:23:08 +0000243 ALOGD("resized");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700244 {
245 // This should not reflect the new size or color because SurfaceFlinger
246 // has not yet received a buffer of the correct size.
247 SCOPED_TRACE("after resize, before redraw");
248 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800249 sc->expectBGColor(0, 12);
250 sc->expectFGColor(75, 75);
251 sc->expectBGColor(145, 145);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700252 }
253
Steve Block9d453682011-12-20 16:23:08 +0000254 ALOGD("drawing");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700255 fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63);
256 waitForPostedBuffers();
Steve Block9d453682011-12-20 16:23:08 +0000257 ALOGD("drawn");
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700258 {
259 // This should reflect the new size and the new color.
260 SCOPED_TRACE("after redraw");
261 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800262 sc->expectBGColor(24, 24);
263 sc->checkPixel(75, 75, 63, 195, 63);
264 sc->checkPixel(145, 145, 63, 195, 63);
Jamie Gennis23c2c5d2011-10-11 19:22:19 -0700265 }
266}
267
Haixia Shid5750962015-07-27 16:50:49 -0700268TEST_F(LayerUpdateTest, LayerCropWorks) {
269 sp<ScreenCapture> sc;
270 {
271 SCOPED_TRACE("before crop");
272 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800273 sc->expectBGColor(24, 24);
274 sc->expectFGColor(75, 75);
275 sc->expectBGColor(145, 145);
Haixia Shid5750962015-07-27 16:50:49 -0700276 }
277
278 SurfaceComposerClient::openGlobalTransaction();
279 Rect cropRect(16, 16, 32, 32);
280 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setCrop(cropRect));
281 SurfaceComposerClient::closeGlobalTransaction(true);
282 {
283 // This should crop the foreground surface.
284 SCOPED_TRACE("after crop");
285 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800286 sc->expectBGColor(24, 24);
287 sc->expectBGColor(75, 75);
288 sc->expectFGColor(95, 80);
289 sc->expectFGColor(80, 95);
290 sc->expectBGColor(96, 96);
Haixia Shid5750962015-07-27 16:50:49 -0700291 }
292}
293
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000294TEST_F(LayerUpdateTest, LayerFinalCropWorks) {
295 sp<ScreenCapture> sc;
296 {
297 SCOPED_TRACE("before crop");
298 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800299 sc->expectBGColor(24, 24);
300 sc->expectFGColor(75, 75);
301 sc->expectBGColor(145, 145);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000302 }
303 SurfaceComposerClient::openGlobalTransaction();
304 Rect cropRect(16, 16, 32, 32);
305 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFinalCrop(cropRect));
306 SurfaceComposerClient::closeGlobalTransaction(true);
307 {
308 // This should crop the foreground surface.
309 SCOPED_TRACE("after crop");
310 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800311 sc->expectBGColor(24, 24);
312 sc->expectBGColor(75, 75);
313 sc->expectBGColor(95, 80);
314 sc->expectBGColor(80, 95);
315 sc->expectBGColor(96, 96);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000316 }
317}
318
Haixia Shid5750962015-07-27 16:50:49 -0700319TEST_F(LayerUpdateTest, LayerSetLayerWorks) {
320 sp<ScreenCapture> sc;
321 {
322 SCOPED_TRACE("before setLayer");
323 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800324 sc->expectBGColor(24, 24);
325 sc->expectFGColor(75, 75);
326 sc->expectBGColor(145, 145);
Haixia Shid5750962015-07-27 16:50:49 -0700327 }
328
329 SurfaceComposerClient::openGlobalTransaction();
330 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX - 3));
331 SurfaceComposerClient::closeGlobalTransaction(true);
332 {
333 // This should hide the foreground surface beneath the background.
334 SCOPED_TRACE("after setLayer");
335 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800336 sc->expectBGColor(24, 24);
337 sc->expectBGColor(75, 75);
338 sc->expectBGColor(145, 145);
Haixia Shid5750962015-07-27 16:50:49 -0700339 }
340}
341
342TEST_F(LayerUpdateTest, LayerShowHideWorks) {
343 sp<ScreenCapture> sc;
344 {
345 SCOPED_TRACE("before hide");
346 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800347 sc->expectBGColor(24, 24);
348 sc->expectFGColor(75, 75);
349 sc->expectBGColor(145, 145);
Haixia Shid5750962015-07-27 16:50:49 -0700350 }
351
352 SurfaceComposerClient::openGlobalTransaction();
353 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->hide());
354 SurfaceComposerClient::closeGlobalTransaction(true);
355 {
356 // This should hide the foreground surface.
357 SCOPED_TRACE("after hide, before show");
358 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800359 sc->expectBGColor(24, 24);
360 sc->expectBGColor(75, 75);
361 sc->expectBGColor(145, 145);
Haixia Shid5750962015-07-27 16:50:49 -0700362 }
363
364 SurfaceComposerClient::openGlobalTransaction();
365 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show());
366 SurfaceComposerClient::closeGlobalTransaction(true);
367 {
368 // This should show the foreground surface.
369 SCOPED_TRACE("after show");
370 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800371 sc->expectBGColor(24, 24);
372 sc->expectFGColor(75, 75);
373 sc->expectBGColor(145, 145);
Haixia Shid5750962015-07-27 16:50:49 -0700374 }
375}
376
377TEST_F(LayerUpdateTest, LayerSetAlphaWorks) {
378 sp<ScreenCapture> sc;
379 {
380 SCOPED_TRACE("before setAlpha");
381 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800382 sc->expectBGColor(24, 24);
383 sc->expectFGColor(75, 75);
384 sc->expectBGColor(145, 145);
Haixia Shid5750962015-07-27 16:50:49 -0700385 }
386
387 SurfaceComposerClient::openGlobalTransaction();
388 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75f));
389 SurfaceComposerClient::closeGlobalTransaction(true);
390 {
391 // This should set foreground to be 75% opaque.
392 SCOPED_TRACE("after setAlpha");
393 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800394 sc->expectBGColor(24, 24);
395 sc->checkPixel(75, 75, 162, 63, 96);
396 sc->expectBGColor(145, 145);
Haixia Shid5750962015-07-27 16:50:49 -0700397 }
398}
399
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700400TEST_F(LayerUpdateTest, LayerSetLayerStackWorks) {
401 sp<ScreenCapture> sc;
402 {
403 SCOPED_TRACE("before setLayerStack");
404 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800405 sc->expectBGColor(24, 24);
406 sc->expectFGColor(75, 75);
407 sc->expectBGColor(145, 145);
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700408 }
409
410 SurfaceComposerClient::openGlobalTransaction();
411 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayerStack(1));
412 SurfaceComposerClient::closeGlobalTransaction(true);
413 {
414 // This should hide the foreground surface since it goes to a different
415 // layer stack.
416 SCOPED_TRACE("after setLayerStack");
417 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800418 sc->expectBGColor(24, 24);
419 sc->expectBGColor(75, 75);
420 sc->expectBGColor(145, 145);
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700421 }
422}
423
424TEST_F(LayerUpdateTest, LayerSetFlagsWorks) {
425 sp<ScreenCapture> sc;
426 {
427 SCOPED_TRACE("before setFlags");
428 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800429 sc->expectBGColor(24, 24);
430 sc->expectFGColor(75, 75);
431 sc->expectBGColor(145, 145);
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700432 }
433
434 SurfaceComposerClient::openGlobalTransaction();
435 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFlags(
436 layer_state_t::eLayerHidden, layer_state_t::eLayerHidden));
437 SurfaceComposerClient::closeGlobalTransaction(true);
438 {
439 // This should hide the foreground surface
440 SCOPED_TRACE("after setFlags");
441 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800442 sc->expectBGColor(24, 24);
443 sc->expectBGColor(75, 75);
444 sc->expectBGColor(145, 145);
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700445 }
446}
447
448TEST_F(LayerUpdateTest, LayerSetMatrixWorks) {
449 sp<ScreenCapture> sc;
450 {
451 SCOPED_TRACE("before setMatrix");
452 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800453 sc->expectBGColor(24, 24);
454 sc->expectFGColor(91, 96);
455 sc->expectFGColor(96, 101);
456 sc->expectBGColor(145, 145);
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700457 }
458
459 SurfaceComposerClient::openGlobalTransaction();
460 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setMatrix(M_SQRT1_2, M_SQRT1_2,
461 -M_SQRT1_2, M_SQRT1_2));
462 SurfaceComposerClient::closeGlobalTransaction(true);
463 {
464 SCOPED_TRACE("after setMatrix");
465 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800466 sc->expectBGColor(24, 24);
467 sc->expectFGColor(91, 96);
468 sc->expectBGColor(96, 91);
469 sc->expectBGColor(145, 145);
Pablo Ceballos5e4fcbe2015-09-02 09:53:16 -0700470 }
471}
472
Robert Carr8d5227b2017-03-16 15:41:03 -0700473class GeometryLatchingTest : public LayerUpdateTest {
474protected:
475 void EXPECT_INITIAL_STATE(const char * trace) {
476 SCOPED_TRACE(trace);
477 ScreenCapture::captureScreen(&sc);
478 // We find the leading edge of the FG surface.
479 sc->expectFGColor(127, 127);
480 sc->expectBGColor(128, 128);
481 }
482 void completeFGResize() {
483 fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63);
484 waitForPostedBuffers();
485 }
486 void restoreInitialState() {
487 SurfaceComposerClient::openGlobalTransaction();
488 mFGSurfaceControl->setSize(64, 64);
489 mFGSurfaceControl->setPosition(64, 64);
490 mFGSurfaceControl->setCrop(Rect(0, 0, 64, 64));
491 mFGSurfaceControl->setFinalCrop(Rect(0, 0, -1, -1));
492 SurfaceComposerClient::closeGlobalTransaction(true);
493
494 EXPECT_INITIAL_STATE("After restoring initial state");
495 }
496 sp<ScreenCapture> sc;
497};
498
499TEST_F(GeometryLatchingTest, SurfacePositionLatching) {
500 EXPECT_INITIAL_STATE("before anything");
501
502 // By default position can be updated even while
503 // a resize is pending.
504 SurfaceComposerClient::openGlobalTransaction();
505 mFGSurfaceControl->setSize(32, 32);
506 mFGSurfaceControl->setPosition(100, 100);
507 SurfaceComposerClient::closeGlobalTransaction(true);
508
509 {
510 SCOPED_TRACE("After moving surface");
511 ScreenCapture::captureScreen(&sc);
512 // If we moved, the FG Surface should cover up what was previously BG
513 // however if we didn't move the FG wouldn't be large enough now.
514 sc->expectFGColor(163, 163);
515 }
516
517 restoreInitialState();
518
519 // Now we repeat with setGeometryAppliesWithResize
520 // and verify the position DOESN'T latch.
521 SurfaceComposerClient::openGlobalTransaction();
522 mFGSurfaceControl->setGeometryAppliesWithResize();
523 mFGSurfaceControl->setSize(32, 32);
524 mFGSurfaceControl->setPosition(100, 100);
525 SurfaceComposerClient::closeGlobalTransaction(true);
526
527 {
528 SCOPED_TRACE("While resize is pending");
529 ScreenCapture::captureScreen(&sc);
530 // This time we shouldn't have moved, so the BG color
531 // should still be visible.
532 sc->expectBGColor(128, 128);
533 }
534
535 completeFGResize();
536
537 {
538 SCOPED_TRACE("After the resize");
539 ScreenCapture::captureScreen(&sc);
540 // But after the resize completes, we should move
541 // and the FG should be visible here.
542 sc->expectFGColor(128, 128);
543 }
544}
545
546class CropLatchingTest : public GeometryLatchingTest {
547protected:
548 void EXPECT_CROPPED_STATE(const char* trace) {
549 SCOPED_TRACE(trace);
550 ScreenCapture::captureScreen(&sc);
551 // The edge should be moved back one pixel by our crop.
552 sc->expectFGColor(126, 126);
553 sc->expectBGColor(127, 127);
554 sc->expectBGColor(128, 128);
555 }
556};
557
558TEST_F(CropLatchingTest, CropLatching) {
559 EXPECT_INITIAL_STATE("before anything");
560 // Normally the crop applies immediately even while a resize is pending.
561 SurfaceComposerClient::openGlobalTransaction();
562 mFGSurfaceControl->setSize(128, 128);
563 mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63));
564 SurfaceComposerClient::closeGlobalTransaction(true);
565
566 EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)");
567
568 restoreInitialState();
569
570 SurfaceComposerClient::openGlobalTransaction();
571 mFGSurfaceControl->setSize(128, 128);
572 mFGSurfaceControl->setGeometryAppliesWithResize();
573 mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63));
574 SurfaceComposerClient::closeGlobalTransaction(true);
575
576 EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)");
577
578 completeFGResize();
579
580 EXPECT_CROPPED_STATE("after the resize finishes");
581}
582
583TEST_F(CropLatchingTest, FinalCropLatching) {
584 EXPECT_INITIAL_STATE("before anything");
585 // Normally the crop applies immediately even while a resize is pending.
586 SurfaceComposerClient::openGlobalTransaction();
587 mFGSurfaceControl->setSize(128, 128);
588 mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
589 SurfaceComposerClient::closeGlobalTransaction(true);
590
591 EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)");
592
593 restoreInitialState();
594
595 SurfaceComposerClient::openGlobalTransaction();
596 mFGSurfaceControl->setSize(128, 128);
597 mFGSurfaceControl->setGeometryAppliesWithResize();
598 mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127));
599 SurfaceComposerClient::closeGlobalTransaction(true);
600
601 EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)");
602
603 completeFGResize();
604
605 EXPECT_CROPPED_STATE("after the resize finishes");
606}
607
Pablo Ceballos05289c22016-04-14 15:49:55 -0700608TEST_F(LayerUpdateTest, DeferredTransactionTest) {
609 sp<ScreenCapture> sc;
610 {
611 SCOPED_TRACE("before anything");
612 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800613 sc->expectBGColor(32, 32);
614 sc->expectFGColor(96, 96);
615 sc->expectBGColor(160, 160);
Pablo Ceballos05289c22016-04-14 15:49:55 -0700616 }
617
618 // set up two deferred transactions on different frames
619 SurfaceComposerClient::openGlobalTransaction();
620 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75));
621 mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(),
622 mSyncSurfaceControl->getSurface()->getNextFrameNumber());
623 SurfaceComposerClient::closeGlobalTransaction(true);
624
625 SurfaceComposerClient::openGlobalTransaction();
626 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128,128));
627 mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(),
628 mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1);
629 SurfaceComposerClient::closeGlobalTransaction(true);
630
631 {
632 SCOPED_TRACE("before any trigger");
633 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800634 sc->expectBGColor(32, 32);
635 sc->expectFGColor(96, 96);
636 sc->expectBGColor(160, 160);
Pablo Ceballos05289c22016-04-14 15:49:55 -0700637 }
638
639 // should trigger the first deferred transaction, but not the second one
640 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
641 {
642 SCOPED_TRACE("after first trigger");
643 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800644 sc->expectBGColor(32, 32);
645 sc->checkPixel(96, 96, 162, 63, 96);
646 sc->expectBGColor(160, 160);
Pablo Ceballos05289c22016-04-14 15:49:55 -0700647 }
648
649 // should show up immediately since it's not deferred
650 SurfaceComposerClient::openGlobalTransaction();
651 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(1.0));
652 SurfaceComposerClient::closeGlobalTransaction(true);
653
654 // trigger the second deferred transaction
655 fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31);
656 {
657 SCOPED_TRACE("after second trigger");
658 ScreenCapture::captureScreen(&sc);
Robert Carr2b91c822017-02-21 19:41:24 -0800659 sc->expectBGColor(32, 32);
660 sc->expectBGColor(96, 96);
661 sc->expectFGColor(160, 160);
Pablo Ceballos05289c22016-04-14 15:49:55 -0700662 }
663}
664
Robert Carrdb66e622017-04-10 16:55:57 -0700665TEST_F(LayerUpdateTest, LayerSetRelativeLayerWorks) {
666 sp<ScreenCapture> sc;
667 {
668 SCOPED_TRACE("before adding relative surface");
669 ScreenCapture::captureScreen(&sc);
670 sc->expectBGColor(24, 24);
671 sc->expectFGColor(75, 75);
672 sc->expectBGColor(145, 145);
673 }
674
675 auto relativeSurfaceControl = mComposerClient->createSurface(
676 String8("Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0);
677 fillSurfaceRGBA8(relativeSurfaceControl, 255, 177, 177);
678 waitForPostedBuffers();
679
680 // Now we stack the surface above the foreground surface and make sure it is visible.
681 SurfaceComposerClient::openGlobalTransaction();
682 relativeSurfaceControl->setPosition(64, 64);
683 relativeSurfaceControl->show();
684 relativeSurfaceControl->setRelativeLayer(mFGSurfaceControl->getHandle(), 1);
685 SurfaceComposerClient::closeGlobalTransaction(true);
686
687
688 {
689 SCOPED_TRACE("after adding relative surface");
690 ScreenCapture::captureScreen(&sc);
691 // our relative surface should be visible now.
692 sc->checkPixel(75, 75, 255, 177, 177);
693 }
694
695 // A call to setLayer will override a call to setRelativeLayer
696 SurfaceComposerClient::openGlobalTransaction();
697 relativeSurfaceControl->setLayer(0);
698 SurfaceComposerClient::closeGlobalTransaction();
699
700 {
701 SCOPED_TRACE("after set layer");
702 ScreenCapture::captureScreen(&sc);
703 // now the FG surface should be visible again.
704 sc->expectFGColor(75, 75);
705 }
706}
707
Robert Carr1f0a16a2016-10-24 16:27:39 -0700708class ChildLayerTest : public LayerUpdateTest {
709protected:
710 void SetUp() override {
711 LayerUpdateTest::SetUp();
712 mChild = mComposerClient->createSurface(
713 String8("Child surface"),
714 10, 10, PIXEL_FORMAT_RGBA_8888,
715 0, mFGSurfaceControl.get());
716 fillSurfaceRGBA8(mChild, 200, 200, 200);
717
718 {
719 SCOPED_TRACE("before anything");
720 ScreenCapture::captureScreen(&mCapture);
721 mCapture->expectChildColor(64, 64);
722 }
723 }
724 void TearDown() override {
725 LayerUpdateTest::TearDown();
726 mChild = 0;
727 }
728
729 sp<SurfaceControl> mChild;
730 sp<ScreenCapture> mCapture;
731};
732
733TEST_F(ChildLayerTest, ChildLayerPositioning) {
734 SurfaceComposerClient::openGlobalTransaction();
735 mChild->show();
736 mChild->setPosition(10, 10);
737 mFGSurfaceControl->setPosition(64, 64);
738 SurfaceComposerClient::closeGlobalTransaction(true);
739
740 {
741 ScreenCapture::captureScreen(&mCapture);
742 // Top left of foreground must now be visible
743 mCapture->expectFGColor(64, 64);
744 // But 10 pixels in we should see the child surface
745 mCapture->expectChildColor(74, 74);
746 // And 10 more pixels we should be back to the foreground surface
747 mCapture->expectFGColor(84, 84);
748 }
749
750 SurfaceComposerClient::openGlobalTransaction();
751 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(0, 0));
752 SurfaceComposerClient::closeGlobalTransaction(true);
753
754 {
755 ScreenCapture::captureScreen(&mCapture);
756 // Top left of foreground should now be at 0, 0
757 mCapture->expectFGColor(0, 0);
758 // But 10 pixels in we should see the child surface
759 mCapture->expectChildColor(10, 10);
760 // And 10 more pixels we should be back to the foreground surface
761 mCapture->expectFGColor(20, 20);
762 }
763}
764
765TEST_F(ChildLayerTest, ChildLayerConstraints) {
766 SurfaceComposerClient::openGlobalTransaction();
767 mChild->show();
768 mFGSurfaceControl->setPosition(0, 0);
769 mChild->setPosition(63, 63);
770 SurfaceComposerClient::closeGlobalTransaction(true);
771
772 {
773 ScreenCapture::captureScreen(&mCapture);
774 mCapture->expectFGColor(0, 0);
775 // Last pixel in foreground should now be the child.
776 mCapture->expectChildColor(63, 63);
777 // But the child should be constrained and the next pixel
778 // must be the background
779 mCapture->expectBGColor(64, 64);
780 }
781}
782
783TEST_F(ChildLayerTest, ChildLayerScaling) {
784 SurfaceComposerClient::openGlobalTransaction();
785 mFGSurfaceControl->setPosition(0, 0);
786 SurfaceComposerClient::closeGlobalTransaction(true);
787
788 // Find the boundary between the parent and child
789 {
790 ScreenCapture::captureScreen(&mCapture);
791 mCapture->expectChildColor(9, 9);
792 mCapture->expectFGColor(10, 10);
793 }
794
795 SurfaceComposerClient::openGlobalTransaction();
796 mFGSurfaceControl->setMatrix(2.0, 0, 0, 2.0);
797 SurfaceComposerClient::closeGlobalTransaction(true);
798
799 // The boundary should be twice as far from the origin now.
800 // The pixels from the last test should all be child now
801 {
802 ScreenCapture::captureScreen(&mCapture);
803 mCapture->expectChildColor(9, 9);
804 mCapture->expectChildColor(10, 10);
805 mCapture->expectChildColor(19, 19);
806 mCapture->expectFGColor(20, 20);
807 }
808}
Robert Carr9524cb32017-02-13 11:32:32 -0800809
Robert Carr6452f122017-03-21 10:41:29 -0700810TEST_F(ChildLayerTest, ChildLayerAlpha) {
811 fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254);
812 fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0);
813 fillSurfaceRGBA8(mChild, 0, 254, 0);
814 waitForPostedBuffers();
815
816 SurfaceComposerClient::openGlobalTransaction();
817 mChild->show();
818 mChild->setPosition(0, 0);
819 mFGSurfaceControl->setPosition(0, 0);
820 SurfaceComposerClient::closeGlobalTransaction(true);
821
822 {
823 ScreenCapture::captureScreen(&mCapture);
824 // Unblended child color
825 mCapture->checkPixel(0, 0, 0, 254, 0);
826 }
827
828 SurfaceComposerClient::openGlobalTransaction();
829 ASSERT_EQ(NO_ERROR, mChild->setAlpha(0.5));
830 SurfaceComposerClient::closeGlobalTransaction(true);
831
832 {
833 ScreenCapture::captureScreen(&mCapture);
834 // Child and BG blended.
835 mCapture->checkPixel(0, 0, 127, 127, 0);
836 }
837
838 SurfaceComposerClient::openGlobalTransaction();
839 ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.5));
840 SurfaceComposerClient::closeGlobalTransaction(true);
841
842 {
843 ScreenCapture::captureScreen(&mCapture);
844 // Child and BG blended.
845 mCapture->checkPixel(0, 0, 95, 64, 95);
846 }
847}
848
Robert Carr9524cb32017-02-13 11:32:32 -0800849TEST_F(ChildLayerTest, ReparentChildren) {
850 SurfaceComposerClient::openGlobalTransaction();
851 mChild->show();
852 mChild->setPosition(10, 10);
853 mFGSurfaceControl->setPosition(64, 64);
854 SurfaceComposerClient::closeGlobalTransaction(true);
855
856 {
857 ScreenCapture::captureScreen(&mCapture);
858 // Top left of foreground must now be visible
859 mCapture->expectFGColor(64, 64);
860 // But 10 pixels in we should see the child surface
861 mCapture->expectChildColor(74, 74);
862 // And 10 more pixels we should be back to the foreground surface
863 mCapture->expectFGColor(84, 84);
864 }
865 mFGSurfaceControl->reparentChildren(mBGSurfaceControl->getHandle());
866 {
867 ScreenCapture::captureScreen(&mCapture);
868 mCapture->expectFGColor(64, 64);
869 // In reparenting we should have exposed the entire foreground surface.
870 mCapture->expectFGColor(74, 74);
871 // And the child layer should now begin at 10, 10 (since the BG
872 // layer is at (0, 0)).
873 mCapture->expectBGColor(9, 9);
874 mCapture->expectChildColor(10, 10);
875 }
876}
877
878TEST_F(ChildLayerTest, DetachChildren) {
879 SurfaceComposerClient::openGlobalTransaction();
880 mChild->show();
881 mChild->setPosition(10, 10);
882 mFGSurfaceControl->setPosition(64, 64);
883 SurfaceComposerClient::closeGlobalTransaction(true);
884
885 {
886 ScreenCapture::captureScreen(&mCapture);
887 // Top left of foreground must now be visible
888 mCapture->expectFGColor(64, 64);
889 // But 10 pixels in we should see the child surface
890 mCapture->expectChildColor(74, 74);
891 // And 10 more pixels we should be back to the foreground surface
892 mCapture->expectFGColor(84, 84);
893 }
894
895 SurfaceComposerClient::openGlobalTransaction();
896 mFGSurfaceControl->detachChildren();
Robert Carr8d5227b2017-03-16 15:41:03 -0700897 SurfaceComposerClient::closeGlobalTransaction(true);
Robert Carr9524cb32017-02-13 11:32:32 -0800898
899 SurfaceComposerClient::openGlobalTransaction();
900 mChild->hide();
Robert Carr8d5227b2017-03-16 15:41:03 -0700901 SurfaceComposerClient::closeGlobalTransaction(true);
Robert Carr9524cb32017-02-13 11:32:32 -0800902
903 // Nothing should have changed.
904 {
905 ScreenCapture::captureScreen(&mCapture);
906 mCapture->expectFGColor(64, 64);
907 mCapture->expectChildColor(74, 74);
908 mCapture->expectFGColor(84, 84);
909 }
910}
911
Robert Carr9b429f42017-04-17 14:56:57 -0700912TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) {
913 SurfaceComposerClient::openGlobalTransaction();
914 mChild->show();
915 mChild->setPosition(0, 0);
916 mFGSurfaceControl->setPosition(0, 0);
917 SurfaceComposerClient::closeGlobalTransaction(true);
918
919 {
920 ScreenCapture::captureScreen(&mCapture);
921 // We've positioned the child in the top left.
922 mCapture->expectChildColor(0, 0);
923 // But it's only 10x10.
924 mCapture->expectFGColor(10, 10);
925 }
926
927 SurfaceComposerClient::openGlobalTransaction();
928 mFGSurfaceControl->setOverrideScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
929 // We cause scaling by 2.
930 mFGSurfaceControl->setSize(128, 128);
931 SurfaceComposerClient::closeGlobalTransaction();
932
933 {
934 ScreenCapture::captureScreen(&mCapture);
935 // We've positioned the child in the top left.
936 mCapture->expectChildColor(0, 0);
937 mCapture->expectChildColor(10, 10);
938 mCapture->expectChildColor(19, 19);
939 // And now it should be scaled all the way to 20x20
940 mCapture->expectFGColor(20, 20);
941 }
942}
943
Robert Carr1725eee2017-04-26 18:32:15 -0700944// Regression test for b/37673612
945TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) {
946 SurfaceComposerClient::openGlobalTransaction();
947 mChild->show();
948 mChild->setPosition(0, 0);
949 mFGSurfaceControl->setPosition(0, 0);
950 SurfaceComposerClient::closeGlobalTransaction(true);
951
952 {
953 ScreenCapture::captureScreen(&mCapture);
954 // We've positioned the child in the top left.
955 mCapture->expectChildColor(0, 0);
956 // But it's only 10x10.
957 mCapture->expectFGColor(10, 10);
958 }
959
960
961 // We set things up as in b/37673612 so that there is a mismatch between the buffer size and
962 // the WM specified state size.
963 mFGSurfaceControl->setSize(128, 64);
964 sp<Surface> s = mFGSurfaceControl->getSurface();
965 auto anw = static_cast<ANativeWindow*>(s.get());
966 native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90);
967 native_window_set_buffers_dimensions(anw, 64, 128);
968 fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63);
969 waitForPostedBuffers();
970
971 {
972 // The child should still be in the same place and not have any strange scaling as in
973 // b/37673612.
974 ScreenCapture::captureScreen(&mCapture);
975 mCapture->expectChildColor(0, 0);
976 mCapture->expectFGColor(10, 10);
977 }
978}
979
Dan Stoza412903f2017-04-27 13:42:17 -0700980TEST_F(ChildLayerTest, Bug36858924) {
981 // Destroy the child layer
982 mChild.clear();
983
984 // Now recreate it as hidden
985 mChild = mComposerClient->createSurface(String8("Child surface"), 10, 10,
986 PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eHidden,
987 mFGSurfaceControl.get());
988
989 // Show the child layer in a deferred transaction
990 SurfaceComposerClient::openGlobalTransaction();
991 mChild->deferTransactionUntil(mFGSurfaceControl->getHandle(),
992 mFGSurfaceControl->getSurface()->getNextFrameNumber());
993 mChild->show();
994 SurfaceComposerClient::closeGlobalTransaction(true);
995
996 // Render the foreground surface a few times
997 //
998 // Prior to the bugfix for b/36858924, this would usually hang while trying to fill the third
999 // frame because SurfaceFlinger would never process the deferred transaction and would therefore
1000 // never acquire/release the first buffer
1001 ALOGI("Filling 1");
1002 fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0);
1003 ALOGI("Filling 2");
1004 fillSurfaceRGBA8(mFGSurfaceControl, 0, 0, 255);
1005 ALOGI("Filling 3");
1006 fillSurfaceRGBA8(mFGSurfaceControl, 255, 0, 0);
1007 ALOGI("Filling 4");
1008 fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0);
1009}
1010
Jamie Gennis23c2c5d2011-10-11 19:22:19 -07001011}