Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1 | /* |
| 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 Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 19 | #include <android/native_window.h> |
| 20 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 21 | #include <gui/ISurfaceComposer.h> |
| 22 | #include <gui/Surface.h> |
| 23 | #include <gui/SurfaceComposerClient.h> |
| 24 | #include <private/gui/ComposerService.h> |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 25 | #include <private/gui/LayerState.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 26 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 27 | #include <utils/String8.h> |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 28 | #include <ui/DisplayInfo.h> |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 29 | |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 30 | #include <math.h> |
| 31 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | |
| 34 | // Fill an RGBA_8888 formatted surface with a single color. |
| 35 | static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 36 | uint8_t r, uint8_t g, uint8_t b, bool unlock=true) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 37 | ANativeWindow_Buffer outBuffer; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 38 | sp<Surface> s = sc->getSurface(); |
| 39 | ASSERT_TRUE(s != NULL); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 40 | ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, NULL)); |
| 41 | uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 42 | for (int y = 0; y < outBuffer.height; y++) { |
| 43 | for (int x = 0; x < outBuffer.width; x++) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 44 | uint8_t* pixel = img + (4 * (y*outBuffer.stride + x)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 45 | pixel[0] = r; |
| 46 | pixel[1] = g; |
| 47 | pixel[2] = b; |
| 48 | pixel[3] = 255; |
| 49 | } |
| 50 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 51 | if (unlock) { |
| 52 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 53 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | // A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check |
| 57 | // individual pixel values for testing purposes. |
| 58 | class ScreenCapture : public RefBase { |
| 59 | public: |
| 60 | static void captureScreen(sp<ScreenCapture>* sc) { |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 61 | sp<IGraphicBufferProducer> producer; |
| 62 | sp<IGraphicBufferConsumer> consumer; |
| 63 | BufferQueue::createBufferQueue(&producer, &consumer); |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 64 | sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 65 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 66 | sp<IBinder> display(sf->getBuiltInDisplay( |
| 67 | ISurfaceComposer::eDisplayIdMain)); |
Pablo Ceballos | 15311bd | 2016-06-01 18:53:40 -0700 | [diff] [blame] | 68 | SurfaceComposerClient::openGlobalTransaction(); |
| 69 | SurfaceComposerClient::closeGlobalTransaction(true); |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 70 | ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0, |
| 71 | 0, INT_MAX, false)); |
| 72 | *sc = new ScreenCapture(cpuConsumer); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) { |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 76 | 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 Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 79 | 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 Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 83 | EXPECT_EQ(String8(), err) << err.string(); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 87 | void expectFGColor(uint32_t x, uint32_t y) { |
| 88 | checkPixel(x, y, 195, 63, 63); |
| 89 | } |
| 90 | |
| 91 | void expectBGColor(uint32_t x, uint32_t y) { |
| 92 | checkPixel(x, y, 63, 63, 195); |
| 93 | } |
| 94 | |
| 95 | void expectChildColor(uint32_t x, uint32_t y) { |
| 96 | checkPixel(x, y, 200, 200, 200); |
| 97 | } |
| 98 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 99 | private: |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 100 | ScreenCapture(const sp<CpuConsumer>& cc) : |
| 101 | mCC(cc) { |
| 102 | EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuf)); |
| 103 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 104 | |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 105 | ~ScreenCapture() { |
| 106 | mCC->unlockBuffer(mBuf); |
| 107 | } |
| 108 | |
| 109 | sp<CpuConsumer> mCC; |
| 110 | CpuConsumer::LockedBuffer mBuf; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | class LayerUpdateTest : public ::testing::Test { |
| 114 | protected: |
| 115 | virtual void SetUp() { |
| 116 | mComposerClient = new SurfaceComposerClient; |
| 117 | ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); |
| 118 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 119 | sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay( |
| 120 | ISurfaceComposer::eDisplayIdMain)); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 121 | DisplayInfo info; |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 122 | SurfaceComposerClient::getDisplayInfo(display, &info); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 123 | |
| 124 | ssize_t displayWidth = info.w; |
| 125 | ssize_t displayHeight = info.h; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 126 | |
| 127 | // Background surface |
| 128 | mBGSurfaceControl = mComposerClient->createSurface( |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 129 | String8("BG Test Surface"), displayWidth, displayHeight, |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 130 | PIXEL_FORMAT_RGBA_8888, 0); |
| 131 | ASSERT_TRUE(mBGSurfaceControl != NULL); |
| 132 | ASSERT_TRUE(mBGSurfaceControl->isValid()); |
| 133 | fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195); |
| 134 | |
| 135 | // Foreground surface |
| 136 | mFGSurfaceControl = mComposerClient->createSurface( |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 137 | String8("FG Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 138 | ASSERT_TRUE(mFGSurfaceControl != NULL); |
| 139 | ASSERT_TRUE(mFGSurfaceControl->isValid()); |
| 140 | |
| 141 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 142 | |
| 143 | // Synchronization surface |
| 144 | mSyncSurfaceControl = mComposerClient->createSurface( |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 145 | String8("Sync Test Surface"), 1, 1, PIXEL_FORMAT_RGBA_8888, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 146 | ASSERT_TRUE(mSyncSurfaceControl != NULL); |
| 147 | ASSERT_TRUE(mSyncSurfaceControl->isValid()); |
| 148 | |
| 149 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 150 | |
| 151 | SurfaceComposerClient::openGlobalTransaction(); |
| 152 | |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 153 | mComposerClient->setDisplayLayerStack(display, 0); |
| 154 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 155 | ASSERT_EQ(NO_ERROR, mBGSurfaceControl->setLayer(INT32_MAX-2)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 156 | ASSERT_EQ(NO_ERROR, mBGSurfaceControl->show()); |
| 157 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 158 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT32_MAX-1)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 159 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(64, 64)); |
| 160 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show()); |
| 161 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 162 | ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setLayer(INT32_MAX-1)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 163 | ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setPosition(displayWidth-2, |
| 164 | displayHeight-2)); |
| 165 | ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->show()); |
| 166 | |
| 167 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 168 | } |
| 169 | |
| 170 | virtual void TearDown() { |
| 171 | mComposerClient->dispose(); |
| 172 | mBGSurfaceControl = 0; |
| 173 | mFGSurfaceControl = 0; |
| 174 | mSyncSurfaceControl = 0; |
| 175 | mComposerClient = 0; |
| 176 | } |
| 177 | |
| 178 | void waitForPostedBuffers() { |
| 179 | // Since the sync surface is in synchronous mode (i.e. double buffered) |
| 180 | // posting three buffers to it should ensure that at least two |
| 181 | // SurfaceFlinger::handlePageFlip calls have been made, which should |
| 182 | // guaranteed that a buffer posted to another Surface has been retired. |
| 183 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 184 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 185 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 186 | } |
| 187 | |
| 188 | sp<SurfaceComposerClient> mComposerClient; |
| 189 | sp<SurfaceControl> mBGSurfaceControl; |
| 190 | sp<SurfaceControl> mFGSurfaceControl; |
| 191 | |
| 192 | // This surface is used to ensure that the buffers posted to |
| 193 | // mFGSurfaceControl have been picked up by SurfaceFlinger. |
| 194 | sp<SurfaceControl> mSyncSurfaceControl; |
| 195 | }; |
| 196 | |
| 197 | TEST_F(LayerUpdateTest, LayerMoveWorks) { |
| 198 | sp<ScreenCapture> sc; |
| 199 | { |
| 200 | SCOPED_TRACE("before move"); |
| 201 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 202 | sc->expectBGColor(0, 12); |
| 203 | sc->expectFGColor(75, 75); |
| 204 | sc->expectBGColor(145, 145); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | SurfaceComposerClient::openGlobalTransaction(); |
| 208 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128, 128)); |
| 209 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 210 | { |
| 211 | // This should reflect the new position, but not the new color. |
| 212 | SCOPED_TRACE("after move, before redraw"); |
| 213 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 214 | sc->expectBGColor(24, 24); |
| 215 | sc->expectBGColor(75, 75); |
| 216 | sc->expectFGColor(145, 145); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63); |
| 220 | waitForPostedBuffers(); |
| 221 | { |
| 222 | // This should reflect the new position and the new color. |
| 223 | SCOPED_TRACE("after redraw"); |
| 224 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 225 | sc->expectBGColor(24, 24); |
| 226 | sc->expectBGColor(75, 75); |
| 227 | sc->checkPixel(145, 145, 63, 195, 63); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | |
| 231 | TEST_F(LayerUpdateTest, LayerResizeWorks) { |
| 232 | sp<ScreenCapture> sc; |
| 233 | { |
| 234 | SCOPED_TRACE("before resize"); |
| 235 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 236 | sc->expectBGColor(0, 12); |
| 237 | sc->expectFGColor(75, 75); |
| 238 | sc->expectBGColor(145, 145); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 241 | ALOGD("resizing"); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 242 | SurfaceComposerClient::openGlobalTransaction(); |
| 243 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setSize(128, 128)); |
| 244 | SurfaceComposerClient::closeGlobalTransaction(true); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 245 | ALOGD("resized"); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 246 | { |
| 247 | // This should not reflect the new size or color because SurfaceFlinger |
| 248 | // has not yet received a buffer of the correct size. |
| 249 | SCOPED_TRACE("after resize, before redraw"); |
| 250 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 251 | sc->expectBGColor(0, 12); |
| 252 | sc->expectFGColor(75, 75); |
| 253 | sc->expectBGColor(145, 145); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 256 | ALOGD("drawing"); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 257 | fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63); |
| 258 | waitForPostedBuffers(); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 259 | ALOGD("drawn"); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 260 | { |
| 261 | // This should reflect the new size and the new color. |
| 262 | SCOPED_TRACE("after redraw"); |
| 263 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 264 | sc->expectBGColor(24, 24); |
| 265 | sc->checkPixel(75, 75, 63, 195, 63); |
| 266 | sc->checkPixel(145, 145, 63, 195, 63); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 270 | TEST_F(LayerUpdateTest, LayerCropWorks) { |
| 271 | sp<ScreenCapture> sc; |
| 272 | { |
| 273 | SCOPED_TRACE("before crop"); |
| 274 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 275 | sc->expectBGColor(24, 24); |
| 276 | sc->expectFGColor(75, 75); |
| 277 | sc->expectBGColor(145, 145); |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | SurfaceComposerClient::openGlobalTransaction(); |
| 281 | Rect cropRect(16, 16, 32, 32); |
| 282 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setCrop(cropRect)); |
| 283 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 284 | { |
| 285 | // This should crop the foreground surface. |
| 286 | SCOPED_TRACE("after crop"); |
| 287 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 288 | sc->expectBGColor(24, 24); |
| 289 | sc->expectBGColor(75, 75); |
| 290 | sc->expectFGColor(95, 80); |
| 291 | sc->expectFGColor(80, 95); |
| 292 | sc->expectBGColor(96, 96); |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 296 | TEST_F(LayerUpdateTest, LayerFinalCropWorks) { |
| 297 | sp<ScreenCapture> sc; |
| 298 | { |
| 299 | SCOPED_TRACE("before crop"); |
| 300 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 301 | sc->expectBGColor(24, 24); |
| 302 | sc->expectFGColor(75, 75); |
| 303 | sc->expectBGColor(145, 145); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 304 | } |
| 305 | SurfaceComposerClient::openGlobalTransaction(); |
| 306 | Rect cropRect(16, 16, 32, 32); |
| 307 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFinalCrop(cropRect)); |
| 308 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 309 | { |
| 310 | // This should crop the foreground surface. |
| 311 | SCOPED_TRACE("after crop"); |
| 312 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 313 | sc->expectBGColor(24, 24); |
| 314 | sc->expectBGColor(75, 75); |
| 315 | sc->expectBGColor(95, 80); |
| 316 | sc->expectBGColor(80, 95); |
| 317 | sc->expectBGColor(96, 96); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 321 | TEST_F(LayerUpdateTest, LayerSetLayerWorks) { |
| 322 | sp<ScreenCapture> sc; |
| 323 | { |
| 324 | SCOPED_TRACE("before setLayer"); |
| 325 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 326 | sc->expectBGColor(24, 24); |
| 327 | sc->expectFGColor(75, 75); |
| 328 | sc->expectBGColor(145, 145); |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | SurfaceComposerClient::openGlobalTransaction(); |
| 332 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT_MAX - 3)); |
| 333 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 334 | { |
| 335 | // This should hide the foreground surface beneath the background. |
| 336 | SCOPED_TRACE("after setLayer"); |
| 337 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 338 | sc->expectBGColor(24, 24); |
| 339 | sc->expectBGColor(75, 75); |
| 340 | sc->expectBGColor(145, 145); |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | TEST_F(LayerUpdateTest, LayerShowHideWorks) { |
| 345 | sp<ScreenCapture> sc; |
| 346 | { |
| 347 | SCOPED_TRACE("before hide"); |
| 348 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 349 | sc->expectBGColor(24, 24); |
| 350 | sc->expectFGColor(75, 75); |
| 351 | sc->expectBGColor(145, 145); |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | SurfaceComposerClient::openGlobalTransaction(); |
| 355 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->hide()); |
| 356 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 357 | { |
| 358 | // This should hide the foreground surface. |
| 359 | SCOPED_TRACE("after hide, before show"); |
| 360 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 361 | sc->expectBGColor(24, 24); |
| 362 | sc->expectBGColor(75, 75); |
| 363 | sc->expectBGColor(145, 145); |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | SurfaceComposerClient::openGlobalTransaction(); |
| 367 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show()); |
| 368 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 369 | { |
| 370 | // This should show the foreground surface. |
| 371 | SCOPED_TRACE("after show"); |
| 372 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 373 | sc->expectBGColor(24, 24); |
| 374 | sc->expectFGColor(75, 75); |
| 375 | sc->expectBGColor(145, 145); |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
| 379 | TEST_F(LayerUpdateTest, LayerSetAlphaWorks) { |
| 380 | sp<ScreenCapture> sc; |
| 381 | { |
| 382 | SCOPED_TRACE("before setAlpha"); |
| 383 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 384 | sc->expectBGColor(24, 24); |
| 385 | sc->expectFGColor(75, 75); |
| 386 | sc->expectBGColor(145, 145); |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | SurfaceComposerClient::openGlobalTransaction(); |
| 390 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75f)); |
| 391 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 392 | { |
| 393 | // This should set foreground to be 75% opaque. |
| 394 | SCOPED_TRACE("after setAlpha"); |
| 395 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 396 | sc->expectBGColor(24, 24); |
| 397 | sc->checkPixel(75, 75, 162, 63, 96); |
| 398 | sc->expectBGColor(145, 145); |
Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 402 | TEST_F(LayerUpdateTest, LayerSetLayerStackWorks) { |
| 403 | sp<ScreenCapture> sc; |
| 404 | { |
| 405 | SCOPED_TRACE("before setLayerStack"); |
| 406 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 407 | sc->expectBGColor(24, 24); |
| 408 | sc->expectFGColor(75, 75); |
| 409 | sc->expectBGColor(145, 145); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | SurfaceComposerClient::openGlobalTransaction(); |
| 413 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayerStack(1)); |
| 414 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 415 | { |
| 416 | // This should hide the foreground surface since it goes to a different |
| 417 | // layer stack. |
| 418 | SCOPED_TRACE("after setLayerStack"); |
| 419 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 420 | sc->expectBGColor(24, 24); |
| 421 | sc->expectBGColor(75, 75); |
| 422 | sc->expectBGColor(145, 145); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | TEST_F(LayerUpdateTest, LayerSetFlagsWorks) { |
| 427 | sp<ScreenCapture> sc; |
| 428 | { |
| 429 | SCOPED_TRACE("before setFlags"); |
| 430 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 431 | sc->expectBGColor(24, 24); |
| 432 | sc->expectFGColor(75, 75); |
| 433 | sc->expectBGColor(145, 145); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | SurfaceComposerClient::openGlobalTransaction(); |
| 437 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setFlags( |
| 438 | layer_state_t::eLayerHidden, layer_state_t::eLayerHidden)); |
| 439 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 440 | { |
| 441 | // This should hide the foreground surface |
| 442 | SCOPED_TRACE("after setFlags"); |
| 443 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 444 | sc->expectBGColor(24, 24); |
| 445 | sc->expectBGColor(75, 75); |
| 446 | sc->expectBGColor(145, 145); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
| 450 | TEST_F(LayerUpdateTest, LayerSetMatrixWorks) { |
| 451 | sp<ScreenCapture> sc; |
| 452 | { |
| 453 | SCOPED_TRACE("before setMatrix"); |
| 454 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 455 | sc->expectBGColor(24, 24); |
| 456 | sc->expectFGColor(91, 96); |
| 457 | sc->expectFGColor(96, 101); |
| 458 | sc->expectBGColor(145, 145); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | SurfaceComposerClient::openGlobalTransaction(); |
| 462 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setMatrix(M_SQRT1_2, M_SQRT1_2, |
| 463 | -M_SQRT1_2, M_SQRT1_2)); |
| 464 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 465 | { |
| 466 | SCOPED_TRACE("after setMatrix"); |
| 467 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 468 | sc->expectBGColor(24, 24); |
| 469 | sc->expectFGColor(91, 96); |
| 470 | sc->expectBGColor(96, 91); |
| 471 | sc->expectBGColor(145, 145); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 472 | } |
| 473 | } |
| 474 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 475 | class GeometryLatchingTest : public LayerUpdateTest { |
| 476 | protected: |
| 477 | void EXPECT_INITIAL_STATE(const char * trace) { |
| 478 | SCOPED_TRACE(trace); |
| 479 | ScreenCapture::captureScreen(&sc); |
| 480 | // We find the leading edge of the FG surface. |
| 481 | sc->expectFGColor(127, 127); |
| 482 | sc->expectBGColor(128, 128); |
| 483 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 484 | |
| 485 | void lockAndFillFGBuffer() { |
| 486 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false); |
| 487 | } |
| 488 | |
| 489 | void unlockFGBuffer() { |
| 490 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 491 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 492 | waitForPostedBuffers(); |
| 493 | } |
| 494 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 495 | void completeFGResize() { |
| 496 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 497 | waitForPostedBuffers(); |
| 498 | } |
| 499 | void restoreInitialState() { |
| 500 | SurfaceComposerClient::openGlobalTransaction(); |
| 501 | mFGSurfaceControl->setSize(64, 64); |
| 502 | mFGSurfaceControl->setPosition(64, 64); |
| 503 | mFGSurfaceControl->setCrop(Rect(0, 0, 64, 64)); |
| 504 | mFGSurfaceControl->setFinalCrop(Rect(0, 0, -1, -1)); |
| 505 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 506 | |
| 507 | EXPECT_INITIAL_STATE("After restoring initial state"); |
| 508 | } |
| 509 | sp<ScreenCapture> sc; |
| 510 | }; |
| 511 | |
| 512 | TEST_F(GeometryLatchingTest, SurfacePositionLatching) { |
| 513 | EXPECT_INITIAL_STATE("before anything"); |
| 514 | |
| 515 | // By default position can be updated even while |
| 516 | // a resize is pending. |
| 517 | SurfaceComposerClient::openGlobalTransaction(); |
| 518 | mFGSurfaceControl->setSize(32, 32); |
| 519 | mFGSurfaceControl->setPosition(100, 100); |
| 520 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 521 | |
| 522 | { |
| 523 | SCOPED_TRACE("After moving surface"); |
| 524 | ScreenCapture::captureScreen(&sc); |
| 525 | // If we moved, the FG Surface should cover up what was previously BG |
| 526 | // however if we didn't move the FG wouldn't be large enough now. |
| 527 | sc->expectFGColor(163, 163); |
| 528 | } |
| 529 | |
| 530 | restoreInitialState(); |
| 531 | |
| 532 | // Now we repeat with setGeometryAppliesWithResize |
| 533 | // and verify the position DOESN'T latch. |
| 534 | SurfaceComposerClient::openGlobalTransaction(); |
| 535 | mFGSurfaceControl->setGeometryAppliesWithResize(); |
| 536 | mFGSurfaceControl->setSize(32, 32); |
| 537 | mFGSurfaceControl->setPosition(100, 100); |
| 538 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 539 | |
| 540 | { |
| 541 | SCOPED_TRACE("While resize is pending"); |
| 542 | ScreenCapture::captureScreen(&sc); |
| 543 | // This time we shouldn't have moved, so the BG color |
| 544 | // should still be visible. |
| 545 | sc->expectBGColor(128, 128); |
| 546 | } |
| 547 | |
| 548 | completeFGResize(); |
| 549 | |
| 550 | { |
| 551 | SCOPED_TRACE("After the resize"); |
| 552 | ScreenCapture::captureScreen(&sc); |
| 553 | // But after the resize completes, we should move |
| 554 | // and the FG should be visible here. |
| 555 | sc->expectFGColor(128, 128); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | class CropLatchingTest : public GeometryLatchingTest { |
| 560 | protected: |
| 561 | void EXPECT_CROPPED_STATE(const char* trace) { |
| 562 | SCOPED_TRACE(trace); |
| 563 | ScreenCapture::captureScreen(&sc); |
| 564 | // The edge should be moved back one pixel by our crop. |
| 565 | sc->expectFGColor(126, 126); |
| 566 | sc->expectBGColor(127, 127); |
| 567 | sc->expectBGColor(128, 128); |
| 568 | } |
chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 569 | |
| 570 | void EXPECT_RESIZE_STATE(const char* trace) { |
| 571 | SCOPED_TRACE(trace); |
| 572 | ScreenCapture::captureScreen(&sc); |
| 573 | // The FG is now resized too 128,128 at 64,64 |
| 574 | sc->expectFGColor(64, 64); |
| 575 | sc->expectFGColor(191, 191); |
| 576 | sc->expectBGColor(192, 192); |
| 577 | } |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 578 | }; |
| 579 | |
| 580 | TEST_F(CropLatchingTest, CropLatching) { |
| 581 | EXPECT_INITIAL_STATE("before anything"); |
| 582 | // Normally the crop applies immediately even while a resize is pending. |
| 583 | SurfaceComposerClient::openGlobalTransaction(); |
| 584 | mFGSurfaceControl->setSize(128, 128); |
| 585 | mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63)); |
| 586 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 587 | |
| 588 | EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)"); |
| 589 | |
| 590 | restoreInitialState(); |
| 591 | |
| 592 | SurfaceComposerClient::openGlobalTransaction(); |
| 593 | mFGSurfaceControl->setSize(128, 128); |
| 594 | mFGSurfaceControl->setGeometryAppliesWithResize(); |
| 595 | mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63)); |
| 596 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 597 | |
| 598 | EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)"); |
| 599 | |
| 600 | completeFGResize(); |
| 601 | |
| 602 | EXPECT_CROPPED_STATE("after the resize finishes"); |
| 603 | } |
| 604 | |
| 605 | TEST_F(CropLatchingTest, FinalCropLatching) { |
| 606 | EXPECT_INITIAL_STATE("before anything"); |
| 607 | // Normally the crop applies immediately even while a resize is pending. |
| 608 | SurfaceComposerClient::openGlobalTransaction(); |
| 609 | mFGSurfaceControl->setSize(128, 128); |
| 610 | mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127)); |
| 611 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 612 | |
| 613 | EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)"); |
| 614 | |
| 615 | restoreInitialState(); |
| 616 | |
| 617 | SurfaceComposerClient::openGlobalTransaction(); |
| 618 | mFGSurfaceControl->setSize(128, 128); |
| 619 | mFGSurfaceControl->setGeometryAppliesWithResize(); |
| 620 | mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127)); |
| 621 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 622 | |
| 623 | EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)"); |
| 624 | |
| 625 | completeFGResize(); |
| 626 | |
| 627 | EXPECT_CROPPED_STATE("after the resize finishes"); |
| 628 | } |
| 629 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 630 | // In this test we ensure that setGeometryAppliesWithResize actually demands |
| 631 | // a buffer of the new size, and not just any size. |
| 632 | TEST_F(CropLatchingTest, FinalCropLatchingBufferOldSize) { |
| 633 | EXPECT_INITIAL_STATE("before anything"); |
| 634 | // Normally the crop applies immediately even while a resize is pending. |
| 635 | SurfaceComposerClient::openGlobalTransaction(); |
| 636 | mFGSurfaceControl->setSize(128, 128); |
| 637 | mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127)); |
| 638 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 639 | |
| 640 | EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)"); |
| 641 | |
| 642 | restoreInitialState(); |
| 643 | |
| 644 | // In order to prepare to submit a buffer at the wrong size, we acquire it prior to |
| 645 | // initiating the resize. |
| 646 | lockAndFillFGBuffer(); |
| 647 | |
| 648 | SurfaceComposerClient::openGlobalTransaction(); |
| 649 | mFGSurfaceControl->setSize(128, 128); |
| 650 | mFGSurfaceControl->setGeometryAppliesWithResize(); |
| 651 | mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127)); |
| 652 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 653 | |
| 654 | EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)"); |
| 655 | |
| 656 | // We now submit our old buffer, at the old size, and ensure it doesn't |
| 657 | // trigger geometry latching. |
| 658 | unlockFGBuffer(); |
| 659 | |
| 660 | EXPECT_INITIAL_STATE("after unlocking FG buffer (with geometryAppliesWithResize)"); |
| 661 | |
| 662 | completeFGResize(); |
| 663 | |
| 664 | EXPECT_CROPPED_STATE("after the resize finishes"); |
| 665 | } |
| 666 | |
| 667 | TEST_F(CropLatchingTest, FinalCropLatchingRegressionForb37531386) { |
| 668 | EXPECT_INITIAL_STATE("before anything"); |
| 669 | // In this scenario, we attempt to set the final crop a second time while the resize |
| 670 | // is still pending, and ensure we are successful. Success meaning the second crop |
| 671 | // is the one which eventually latches and not the first. |
| 672 | SurfaceComposerClient::openGlobalTransaction(); |
| 673 | mFGSurfaceControl->setSize(128, 128); |
| 674 | mFGSurfaceControl->setGeometryAppliesWithResize(); |
| 675 | mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127)); |
| 676 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 677 | |
chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 678 | EXPECT_INITIAL_STATE("after setting crops with geometryAppliesWithResize"); |
| 679 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 680 | SurfaceComposerClient::openGlobalTransaction(); |
| 681 | mFGSurfaceControl->setFinalCrop(Rect(0, 0, -1, -1)); |
| 682 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 683 | |
chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 684 | EXPECT_INITIAL_STATE("after setting another crop"); |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 685 | |
| 686 | completeFGResize(); |
| 687 | |
chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 688 | EXPECT_RESIZE_STATE("after the resize finishes"); |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 691 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { |
| 692 | sp<ScreenCapture> sc; |
| 693 | { |
| 694 | SCOPED_TRACE("before anything"); |
| 695 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 696 | sc->expectBGColor(32, 32); |
| 697 | sc->expectFGColor(96, 96); |
| 698 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | // set up two deferred transactions on different frames |
| 702 | SurfaceComposerClient::openGlobalTransaction(); |
| 703 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75)); |
| 704 | mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(), |
| 705 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); |
| 706 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 707 | |
| 708 | SurfaceComposerClient::openGlobalTransaction(); |
| 709 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128,128)); |
| 710 | mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(), |
| 711 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); |
| 712 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 713 | |
| 714 | { |
| 715 | SCOPED_TRACE("before any trigger"); |
| 716 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 717 | sc->expectBGColor(32, 32); |
| 718 | sc->expectFGColor(96, 96); |
| 719 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | // should trigger the first deferred transaction, but not the second one |
| 723 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 724 | { |
| 725 | SCOPED_TRACE("after first trigger"); |
| 726 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 727 | sc->expectBGColor(32, 32); |
| 728 | sc->checkPixel(96, 96, 162, 63, 96); |
| 729 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | // should show up immediately since it's not deferred |
| 733 | SurfaceComposerClient::openGlobalTransaction(); |
| 734 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(1.0)); |
| 735 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 736 | |
| 737 | // trigger the second deferred transaction |
| 738 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 739 | { |
| 740 | SCOPED_TRACE("after second trigger"); |
| 741 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 742 | sc->expectBGColor(32, 32); |
| 743 | sc->expectBGColor(96, 96); |
| 744 | sc->expectFGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 748 | TEST_F(LayerUpdateTest, LayerSetRelativeLayerWorks) { |
| 749 | sp<ScreenCapture> sc; |
| 750 | { |
| 751 | SCOPED_TRACE("before adding relative surface"); |
| 752 | ScreenCapture::captureScreen(&sc); |
| 753 | sc->expectBGColor(24, 24); |
| 754 | sc->expectFGColor(75, 75); |
| 755 | sc->expectBGColor(145, 145); |
| 756 | } |
| 757 | |
| 758 | auto relativeSurfaceControl = mComposerClient->createSurface( |
| 759 | String8("Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0); |
| 760 | fillSurfaceRGBA8(relativeSurfaceControl, 255, 177, 177); |
| 761 | waitForPostedBuffers(); |
| 762 | |
| 763 | // Now we stack the surface above the foreground surface and make sure it is visible. |
| 764 | SurfaceComposerClient::openGlobalTransaction(); |
| 765 | relativeSurfaceControl->setPosition(64, 64); |
| 766 | relativeSurfaceControl->show(); |
| 767 | relativeSurfaceControl->setRelativeLayer(mFGSurfaceControl->getHandle(), 1); |
| 768 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 769 | |
| 770 | |
| 771 | { |
| 772 | SCOPED_TRACE("after adding relative surface"); |
| 773 | ScreenCapture::captureScreen(&sc); |
| 774 | // our relative surface should be visible now. |
| 775 | sc->checkPixel(75, 75, 255, 177, 177); |
| 776 | } |
| 777 | |
| 778 | // A call to setLayer will override a call to setRelativeLayer |
| 779 | SurfaceComposerClient::openGlobalTransaction(); |
| 780 | relativeSurfaceControl->setLayer(0); |
| 781 | SurfaceComposerClient::closeGlobalTransaction(); |
| 782 | |
| 783 | { |
| 784 | SCOPED_TRACE("after set layer"); |
| 785 | ScreenCapture::captureScreen(&sc); |
| 786 | // now the FG surface should be visible again. |
| 787 | sc->expectFGColor(75, 75); |
| 788 | } |
| 789 | } |
| 790 | |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame^] | 791 | TEST_F(LayerUpdateTest, LayerWithNoBuffersResizesImmediately) { |
| 792 | sp<ScreenCapture> sc; |
| 793 | |
| 794 | sp<SurfaceControl> childNoBuffer = |
| 795 | mComposerClient->createSurface(String8("Bufferless child"), |
| 796 | 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 797 | 0, mFGSurfaceControl.get()); |
| 798 | sp<SurfaceControl> childBuffer = mComposerClient->createSurface( |
| 799 | String8("Buffered child"), 20, 20, |
| 800 | PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get()); |
| 801 | fillSurfaceRGBA8(childBuffer, 200, 200, 200); |
| 802 | |
| 803 | SurfaceComposerClient::openGlobalTransaction(); |
| 804 | childNoBuffer->show(); |
| 805 | childBuffer->show(); |
| 806 | SurfaceComposerClient::closeGlobalTransaction(); |
| 807 | |
| 808 | |
| 809 | { |
| 810 | ScreenCapture::captureScreen(&sc); |
| 811 | sc->expectChildColor(73, 73); |
| 812 | sc->expectFGColor(74, 74); |
| 813 | } |
| 814 | |
| 815 | SurfaceComposerClient::openGlobalTransaction(); |
| 816 | childNoBuffer->setSize(20, 20); |
| 817 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 818 | |
| 819 | { |
| 820 | ScreenCapture::captureScreen(&sc); |
| 821 | sc->expectChildColor(73, 73); |
| 822 | sc->expectChildColor(74, 74); |
| 823 | } |
| 824 | } |
| 825 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 826 | class ChildLayerTest : public LayerUpdateTest { |
| 827 | protected: |
| 828 | void SetUp() override { |
| 829 | LayerUpdateTest::SetUp(); |
| 830 | mChild = mComposerClient->createSurface( |
| 831 | String8("Child surface"), |
| 832 | 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 833 | 0, mFGSurfaceControl.get()); |
| 834 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 835 | |
| 836 | { |
| 837 | SCOPED_TRACE("before anything"); |
| 838 | ScreenCapture::captureScreen(&mCapture); |
| 839 | mCapture->expectChildColor(64, 64); |
| 840 | } |
| 841 | } |
| 842 | void TearDown() override { |
| 843 | LayerUpdateTest::TearDown(); |
| 844 | mChild = 0; |
| 845 | } |
| 846 | |
| 847 | sp<SurfaceControl> mChild; |
| 848 | sp<ScreenCapture> mCapture; |
| 849 | }; |
| 850 | |
| 851 | TEST_F(ChildLayerTest, ChildLayerPositioning) { |
| 852 | SurfaceComposerClient::openGlobalTransaction(); |
| 853 | mChild->show(); |
| 854 | mChild->setPosition(10, 10); |
| 855 | mFGSurfaceControl->setPosition(64, 64); |
| 856 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 857 | |
| 858 | { |
| 859 | ScreenCapture::captureScreen(&mCapture); |
| 860 | // Top left of foreground must now be visible |
| 861 | mCapture->expectFGColor(64, 64); |
| 862 | // But 10 pixels in we should see the child surface |
| 863 | mCapture->expectChildColor(74, 74); |
| 864 | // And 10 more pixels we should be back to the foreground surface |
| 865 | mCapture->expectFGColor(84, 84); |
| 866 | } |
| 867 | |
| 868 | SurfaceComposerClient::openGlobalTransaction(); |
| 869 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(0, 0)); |
| 870 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 871 | |
| 872 | { |
| 873 | ScreenCapture::captureScreen(&mCapture); |
| 874 | // Top left of foreground should now be at 0, 0 |
| 875 | mCapture->expectFGColor(0, 0); |
| 876 | // But 10 pixels in we should see the child surface |
| 877 | mCapture->expectChildColor(10, 10); |
| 878 | // And 10 more pixels we should be back to the foreground surface |
| 879 | mCapture->expectFGColor(20, 20); |
| 880 | } |
| 881 | } |
| 882 | |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 883 | TEST_F(ChildLayerTest, ChildLayerCropping) { |
| 884 | SurfaceComposerClient::openGlobalTransaction(); |
| 885 | mChild->show(); |
| 886 | mChild->setPosition(0, 0); |
| 887 | mFGSurfaceControl->setPosition(0, 0); |
| 888 | mFGSurfaceControl->setCrop(Rect(0, 0, 5, 5)); |
| 889 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 890 | |
| 891 | { |
| 892 | ScreenCapture::captureScreen(&mCapture); |
| 893 | mCapture->expectChildColor(0, 0); |
| 894 | mCapture->expectChildColor(4, 4); |
| 895 | mCapture->expectBGColor(5, 5); |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | TEST_F(ChildLayerTest, ChildLayerFinalCropping) { |
| 900 | SurfaceComposerClient::openGlobalTransaction(); |
| 901 | mChild->show(); |
| 902 | mChild->setPosition(0, 0); |
| 903 | mFGSurfaceControl->setPosition(0, 0); |
| 904 | mFGSurfaceControl->setFinalCrop(Rect(0, 0, 5, 5)); |
| 905 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 906 | |
| 907 | { |
| 908 | ScreenCapture::captureScreen(&mCapture); |
| 909 | mCapture->expectChildColor(0, 0); |
| 910 | mCapture->expectChildColor(4, 4); |
| 911 | mCapture->expectBGColor(5, 5); |
| 912 | } |
| 913 | } |
| 914 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 915 | TEST_F(ChildLayerTest, ChildLayerConstraints) { |
| 916 | SurfaceComposerClient::openGlobalTransaction(); |
| 917 | mChild->show(); |
| 918 | mFGSurfaceControl->setPosition(0, 0); |
| 919 | mChild->setPosition(63, 63); |
| 920 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 921 | |
| 922 | { |
| 923 | ScreenCapture::captureScreen(&mCapture); |
| 924 | mCapture->expectFGColor(0, 0); |
| 925 | // Last pixel in foreground should now be the child. |
| 926 | mCapture->expectChildColor(63, 63); |
| 927 | // But the child should be constrained and the next pixel |
| 928 | // must be the background |
| 929 | mCapture->expectBGColor(64, 64); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | TEST_F(ChildLayerTest, ChildLayerScaling) { |
| 934 | SurfaceComposerClient::openGlobalTransaction(); |
| 935 | mFGSurfaceControl->setPosition(0, 0); |
| 936 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 937 | |
| 938 | // Find the boundary between the parent and child |
| 939 | { |
| 940 | ScreenCapture::captureScreen(&mCapture); |
| 941 | mCapture->expectChildColor(9, 9); |
| 942 | mCapture->expectFGColor(10, 10); |
| 943 | } |
| 944 | |
| 945 | SurfaceComposerClient::openGlobalTransaction(); |
| 946 | mFGSurfaceControl->setMatrix(2.0, 0, 0, 2.0); |
| 947 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 948 | |
| 949 | // The boundary should be twice as far from the origin now. |
| 950 | // The pixels from the last test should all be child now |
| 951 | { |
| 952 | ScreenCapture::captureScreen(&mCapture); |
| 953 | mCapture->expectChildColor(9, 9); |
| 954 | mCapture->expectChildColor(10, 10); |
| 955 | mCapture->expectChildColor(19, 19); |
| 956 | mCapture->expectFGColor(20, 20); |
| 957 | } |
| 958 | } |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 959 | |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 960 | TEST_F(ChildLayerTest, ChildLayerAlpha) { |
| 961 | fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254); |
| 962 | fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0); |
| 963 | fillSurfaceRGBA8(mChild, 0, 254, 0); |
| 964 | waitForPostedBuffers(); |
| 965 | |
| 966 | SurfaceComposerClient::openGlobalTransaction(); |
| 967 | mChild->show(); |
| 968 | mChild->setPosition(0, 0); |
| 969 | mFGSurfaceControl->setPosition(0, 0); |
| 970 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 971 | |
| 972 | { |
| 973 | ScreenCapture::captureScreen(&mCapture); |
| 974 | // Unblended child color |
| 975 | mCapture->checkPixel(0, 0, 0, 254, 0); |
| 976 | } |
| 977 | |
| 978 | SurfaceComposerClient::openGlobalTransaction(); |
| 979 | ASSERT_EQ(NO_ERROR, mChild->setAlpha(0.5)); |
| 980 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 981 | |
| 982 | { |
| 983 | ScreenCapture::captureScreen(&mCapture); |
| 984 | // Child and BG blended. |
| 985 | mCapture->checkPixel(0, 0, 127, 127, 0); |
| 986 | } |
| 987 | |
| 988 | SurfaceComposerClient::openGlobalTransaction(); |
| 989 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.5)); |
| 990 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 991 | |
| 992 | { |
| 993 | ScreenCapture::captureScreen(&mCapture); |
| 994 | // Child and BG blended. |
| 995 | mCapture->checkPixel(0, 0, 95, 64, 95); |
| 996 | } |
| 997 | } |
| 998 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 999 | TEST_F(ChildLayerTest, ReparentChildren) { |
| 1000 | SurfaceComposerClient::openGlobalTransaction(); |
| 1001 | mChild->show(); |
| 1002 | mChild->setPosition(10, 10); |
| 1003 | mFGSurfaceControl->setPosition(64, 64); |
| 1004 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 1005 | |
| 1006 | { |
| 1007 | ScreenCapture::captureScreen(&mCapture); |
| 1008 | // Top left of foreground must now be visible |
| 1009 | mCapture->expectFGColor(64, 64); |
| 1010 | // But 10 pixels in we should see the child surface |
| 1011 | mCapture->expectChildColor(74, 74); |
| 1012 | // And 10 more pixels we should be back to the foreground surface |
| 1013 | mCapture->expectFGColor(84, 84); |
| 1014 | } |
| 1015 | mFGSurfaceControl->reparentChildren(mBGSurfaceControl->getHandle()); |
| 1016 | { |
| 1017 | ScreenCapture::captureScreen(&mCapture); |
| 1018 | mCapture->expectFGColor(64, 64); |
| 1019 | // In reparenting we should have exposed the entire foreground surface. |
| 1020 | mCapture->expectFGColor(74, 74); |
| 1021 | // And the child layer should now begin at 10, 10 (since the BG |
| 1022 | // layer is at (0, 0)). |
| 1023 | mCapture->expectBGColor(9, 9); |
| 1024 | mCapture->expectChildColor(10, 10); |
| 1025 | } |
| 1026 | } |
| 1027 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 1028 | TEST_F(ChildLayerTest, DetachChildrenSameClient) { |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 1029 | SurfaceComposerClient::openGlobalTransaction(); |
| 1030 | mChild->show(); |
| 1031 | mChild->setPosition(10, 10); |
| 1032 | mFGSurfaceControl->setPosition(64, 64); |
| 1033 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 1034 | |
| 1035 | { |
| 1036 | ScreenCapture::captureScreen(&mCapture); |
| 1037 | // Top left of foreground must now be visible |
| 1038 | mCapture->expectFGColor(64, 64); |
| 1039 | // But 10 pixels in we should see the child surface |
| 1040 | mCapture->expectChildColor(74, 74); |
| 1041 | // And 10 more pixels we should be back to the foreground surface |
| 1042 | mCapture->expectFGColor(84, 84); |
| 1043 | } |
| 1044 | |
| 1045 | SurfaceComposerClient::openGlobalTransaction(); |
| 1046 | mFGSurfaceControl->detachChildren(); |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1047 | SurfaceComposerClient::closeGlobalTransaction(true); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 1048 | |
| 1049 | SurfaceComposerClient::openGlobalTransaction(); |
| 1050 | mChild->hide(); |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1051 | SurfaceComposerClient::closeGlobalTransaction(true); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 1052 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 1053 | // Since the child has the same client as the parent, it will not get |
| 1054 | // detached and will be hidden. |
| 1055 | { |
| 1056 | ScreenCapture::captureScreen(&mCapture); |
| 1057 | mCapture->expectFGColor(64, 64); |
| 1058 | mCapture->expectFGColor(74, 74); |
| 1059 | mCapture->expectFGColor(84, 84); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | TEST_F(ChildLayerTest, DetachChildrenDifferentClient) { |
| 1064 | sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient; |
| 1065 | sp<SurfaceControl> mChildNewClient = mNewComposerClient->createSurface( |
| 1066 | String8("New Child Test Surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 1067 | 0, mFGSurfaceControl.get()); |
| 1068 | |
| 1069 | ASSERT_TRUE(mChildNewClient != NULL); |
| 1070 | ASSERT_TRUE(mChildNewClient->isValid()); |
| 1071 | |
| 1072 | fillSurfaceRGBA8(mChildNewClient, 200, 200, 200); |
| 1073 | |
| 1074 | SurfaceComposerClient::openGlobalTransaction(); |
| 1075 | mChild->hide(); |
| 1076 | mChildNewClient->show(); |
| 1077 | mChildNewClient->setPosition(10, 10); |
| 1078 | mFGSurfaceControl->setPosition(64, 64); |
| 1079 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 1080 | |
| 1081 | { |
| 1082 | ScreenCapture::captureScreen(&mCapture); |
| 1083 | // Top left of foreground must now be visible |
| 1084 | mCapture->expectFGColor(64, 64); |
| 1085 | // But 10 pixels in we should see the child surface |
| 1086 | mCapture->expectChildColor(74, 74); |
| 1087 | // And 10 more pixels we should be back to the foreground surface |
| 1088 | mCapture->expectFGColor(84, 84); |
| 1089 | } |
| 1090 | |
| 1091 | SurfaceComposerClient::openGlobalTransaction(); |
| 1092 | mFGSurfaceControl->detachChildren(); |
| 1093 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 1094 | |
| 1095 | SurfaceComposerClient::openGlobalTransaction(); |
| 1096 | mChildNewClient->hide(); |
| 1097 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 1098 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 1099 | // Nothing should have changed. |
| 1100 | { |
| 1101 | ScreenCapture::captureScreen(&mCapture); |
| 1102 | mCapture->expectFGColor(64, 64); |
| 1103 | mCapture->expectChildColor(74, 74); |
| 1104 | mCapture->expectFGColor(84, 84); |
| 1105 | } |
| 1106 | } |
| 1107 | |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 1108 | TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) { |
| 1109 | SurfaceComposerClient::openGlobalTransaction(); |
| 1110 | mChild->show(); |
| 1111 | mChild->setPosition(0, 0); |
| 1112 | mFGSurfaceControl->setPosition(0, 0); |
| 1113 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 1114 | |
| 1115 | { |
| 1116 | ScreenCapture::captureScreen(&mCapture); |
| 1117 | // We've positioned the child in the top left. |
| 1118 | mCapture->expectChildColor(0, 0); |
| 1119 | // But it's only 10x10. |
| 1120 | mCapture->expectFGColor(10, 10); |
| 1121 | } |
| 1122 | |
| 1123 | SurfaceComposerClient::openGlobalTransaction(); |
| 1124 | mFGSurfaceControl->setOverrideScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 1125 | // We cause scaling by 2. |
| 1126 | mFGSurfaceControl->setSize(128, 128); |
| 1127 | SurfaceComposerClient::closeGlobalTransaction(); |
| 1128 | |
| 1129 | { |
| 1130 | ScreenCapture::captureScreen(&mCapture); |
| 1131 | // We've positioned the child in the top left. |
| 1132 | mCapture->expectChildColor(0, 0); |
| 1133 | mCapture->expectChildColor(10, 10); |
| 1134 | mCapture->expectChildColor(19, 19); |
| 1135 | // And now it should be scaled all the way to 20x20 |
| 1136 | mCapture->expectFGColor(20, 20); |
| 1137 | } |
| 1138 | } |
| 1139 | |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 1140 | // Regression test for b/37673612 |
| 1141 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) { |
| 1142 | SurfaceComposerClient::openGlobalTransaction(); |
| 1143 | mChild->show(); |
| 1144 | mChild->setPosition(0, 0); |
| 1145 | mFGSurfaceControl->setPosition(0, 0); |
| 1146 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 1147 | |
| 1148 | { |
| 1149 | ScreenCapture::captureScreen(&mCapture); |
| 1150 | // We've positioned the child in the top left. |
| 1151 | mCapture->expectChildColor(0, 0); |
| 1152 | // But it's only 10x10. |
| 1153 | mCapture->expectFGColor(10, 10); |
| 1154 | } |
| 1155 | |
| 1156 | |
| 1157 | // We set things up as in b/37673612 so that there is a mismatch between the buffer size and |
| 1158 | // the WM specified state size. |
| 1159 | mFGSurfaceControl->setSize(128, 64); |
| 1160 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 1161 | auto anw = static_cast<ANativeWindow*>(s.get()); |
| 1162 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 1163 | native_window_set_buffers_dimensions(anw, 64, 128); |
| 1164 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 1165 | waitForPostedBuffers(); |
| 1166 | |
| 1167 | { |
| 1168 | // The child should still be in the same place and not have any strange scaling as in |
| 1169 | // b/37673612. |
| 1170 | ScreenCapture::captureScreen(&mCapture); |
| 1171 | mCapture->expectChildColor(0, 0); |
| 1172 | mCapture->expectFGColor(10, 10); |
| 1173 | } |
| 1174 | } |
| 1175 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 1176 | TEST_F(ChildLayerTest, Bug36858924) { |
| 1177 | // Destroy the child layer |
| 1178 | mChild.clear(); |
| 1179 | |
| 1180 | // Now recreate it as hidden |
| 1181 | mChild = mComposerClient->createSurface(String8("Child surface"), 10, 10, |
| 1182 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eHidden, |
| 1183 | mFGSurfaceControl.get()); |
| 1184 | |
| 1185 | // Show the child layer in a deferred transaction |
| 1186 | SurfaceComposerClient::openGlobalTransaction(); |
| 1187 | mChild->deferTransactionUntil(mFGSurfaceControl->getHandle(), |
| 1188 | mFGSurfaceControl->getSurface()->getNextFrameNumber()); |
| 1189 | mChild->show(); |
| 1190 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 1191 | |
| 1192 | // Render the foreground surface a few times |
| 1193 | // |
| 1194 | // Prior to the bugfix for b/36858924, this would usually hang while trying to fill the third |
| 1195 | // frame because SurfaceFlinger would never process the deferred transaction and would therefore |
| 1196 | // never acquire/release the first buffer |
| 1197 | ALOGI("Filling 1"); |
| 1198 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 1199 | ALOGI("Filling 2"); |
| 1200 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 0, 255); |
| 1201 | ALOGI("Filling 3"); |
| 1202 | fillSurfaceRGBA8(mFGSurfaceControl, 255, 0, 0); |
| 1203 | ALOGI("Filling 4"); |
| 1204 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 1205 | } |
| 1206 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 1207 | TEST_F(ChildLayerTest, ReparentChild) { |
| 1208 | SurfaceComposerClient::openGlobalTransaction(); |
| 1209 | mChild->show(); |
| 1210 | mChild->setPosition(10, 10); |
| 1211 | mFGSurfaceControl->setPosition(64, 64); |
| 1212 | SurfaceComposerClient::closeGlobalTransaction(true); |
| 1213 | |
| 1214 | { |
| 1215 | ScreenCapture::captureScreen(&mCapture); |
| 1216 | // Top left of foreground must now be visible |
| 1217 | mCapture->expectFGColor(64, 64); |
| 1218 | // But 10 pixels in we should see the child surface |
| 1219 | mCapture->expectChildColor(74, 74); |
| 1220 | // And 10 more pixels we should be back to the foreground surface |
| 1221 | mCapture->expectFGColor(84, 84); |
| 1222 | } |
| 1223 | mFGSurfaceControl->reparentChild(mBGSurfaceControl->getHandle(), mChild->getHandle()); |
| 1224 | { |
| 1225 | ScreenCapture::captureScreen(&mCapture); |
| 1226 | mCapture->expectFGColor(64, 64); |
| 1227 | // In reparenting we should have exposed the entire foreground surface. |
| 1228 | mCapture->expectFGColor(74, 74); |
| 1229 | // And the child layer should now begin at 10, 10 (since the BG |
| 1230 | // layer is at (0, 0)). |
| 1231 | mCapture->expectBGColor(9, 9); |
| 1232 | mCapture->expectChildColor(10, 10); |
| 1233 | } |
| 1234 | } |
| 1235 | |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 1236 | TEST_F(ChildLayerTest, NestedChildren) { |
| 1237 | sp<SurfaceControl> grandchild = mComposerClient->createSurface( |
| 1238 | String8("Grandchild surface"), |
| 1239 | 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 1240 | 0, mChild.get()); |
| 1241 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 1242 | |
| 1243 | { |
| 1244 | ScreenCapture::captureScreen(&mCapture); |
| 1245 | // Expect the grandchild to begin at 64, 64 because it's a child of mChild layer |
| 1246 | // which begins at 64, 64 |
| 1247 | mCapture->checkPixel(64, 64, 50, 50, 50); |
| 1248 | } |
| 1249 | } |
| 1250 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1251 | } |