| 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, | 
 | 36 |         uint8_t r, uint8_t g, uint8_t b) { | 
| 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 |     } | 
 | 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. | 
 | 56 | class ScreenCapture : public RefBase { | 
 | 57 | public: | 
 | 58 |     static void captureScreen(sp<ScreenCapture>* sc) { | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 59 |         sp<IGraphicBufferProducer> producer; | 
 | 60 |         sp<IGraphicBufferConsumer> consumer; | 
 | 61 |         BufferQueue::createBufferQueue(&producer, &consumer); | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 62 |         sp<CpuConsumer> cpuConsumer = new CpuConsumer(consumer, 1); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 63 |         sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 64 |         sp<IBinder> display(sf->getBuiltInDisplay( | 
 | 65 |                 ISurfaceComposer::eDisplayIdMain)); | 
| Pablo Ceballos | 15311bd | 2016-06-01 18:53:40 -0700 | [diff] [blame] | 66 |         SurfaceComposerClient::openGlobalTransaction(); | 
 | 67 |         SurfaceComposerClient::closeGlobalTransaction(true); | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 68 |         ASSERT_EQ(NO_ERROR, sf->captureScreen(display, producer, Rect(), 0, 0, | 
 | 69 |                 0, INT_MAX, false)); | 
 | 70 |         *sc = new ScreenCapture(cpuConsumer); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 71 |     } | 
 | 72 |  | 
 | 73 |     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] | 74 |         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 Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 77 |         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 Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 81 |             EXPECT_EQ(String8(), err) << err.string(); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 82 |         } | 
 | 83 |     } | 
 | 84 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 85 |     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 Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 97 | private: | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 98 |     ScreenCapture(const sp<CpuConsumer>& cc) : | 
 | 99 |         mCC(cc) { | 
 | 100 |         EXPECT_EQ(NO_ERROR, mCC->lockNextBuffer(&mBuf)); | 
 | 101 |     } | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 102 |  | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 103 |     ~ScreenCapture() { | 
 | 104 |         mCC->unlockBuffer(mBuf); | 
 | 105 |     } | 
 | 106 |  | 
 | 107 |     sp<CpuConsumer> mCC; | 
 | 108 |     CpuConsumer::LockedBuffer mBuf; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 109 | }; | 
 | 110 |  | 
 | 111 | class LayerUpdateTest : public ::testing::Test { | 
 | 112 | protected: | 
 | 113 |     virtual void SetUp() { | 
 | 114 |         mComposerClient = new SurfaceComposerClient; | 
 | 115 |         ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); | 
 | 116 |  | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 117 |         sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay( | 
 | 118 |                 ISurfaceComposer::eDisplayIdMain)); | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 119 |         DisplayInfo info; | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 120 |         SurfaceComposerClient::getDisplayInfo(display, &info); | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 121 |  | 
 | 122 |         ssize_t displayWidth = info.w; | 
 | 123 |         ssize_t displayHeight = info.h; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 124 |  | 
 | 125 |         // Background surface | 
 | 126 |         mBGSurfaceControl = mComposerClient->createSurface( | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 127 |                 String8("BG Test Surface"), displayWidth, displayHeight, | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 128 |                 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 Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 135 |                 String8("FG Test Surface"), 64, 64, PIXEL_FORMAT_RGBA_8888, 0); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 136 |         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 Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 143 |                 String8("Sync Test Surface"), 1, 1, PIXEL_FORMAT_RGBA_8888, 0); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 144 |         ASSERT_TRUE(mSyncSurfaceControl != NULL); | 
 | 145 |         ASSERT_TRUE(mSyncSurfaceControl->isValid()); | 
 | 146 |  | 
 | 147 |         fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
 | 148 |  | 
 | 149 |         SurfaceComposerClient::openGlobalTransaction(); | 
 | 150 |  | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 151 |         mComposerClient->setDisplayLayerStack(display, 0); | 
 | 152 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 153 |         ASSERT_EQ(NO_ERROR, mBGSurfaceControl->setLayer(INT32_MAX-2)); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 154 |         ASSERT_EQ(NO_ERROR, mBGSurfaceControl->show()); | 
 | 155 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 156 |         ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setLayer(INT32_MAX-1)); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 157 |         ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(64, 64)); | 
 | 158 |         ASSERT_EQ(NO_ERROR, mFGSurfaceControl->show()); | 
 | 159 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 160 |         ASSERT_EQ(NO_ERROR, mSyncSurfaceControl->setLayer(INT32_MAX-1)); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 161 |         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 |  | 
 | 195 | TEST_F(LayerUpdateTest, LayerMoveWorks) { | 
 | 196 |     sp<ScreenCapture> sc; | 
 | 197 |     { | 
 | 198 |         SCOPED_TRACE("before move"); | 
 | 199 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 200 |         sc->expectBGColor(0, 12); | 
 | 201 |         sc->expectFGColor(75, 75); | 
 | 202 |         sc->expectBGColor(145, 145); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 203 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 212 |         sc->expectBGColor(24, 24); | 
 | 213 |         sc->expectBGColor(75, 75); | 
 | 214 |         sc->expectFGColor(145, 145); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 215 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 223 |         sc->expectBGColor(24, 24); | 
 | 224 |         sc->expectBGColor(75, 75); | 
 | 225 |         sc->checkPixel(145, 145, 63, 195, 63); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 226 |     } | 
 | 227 | } | 
 | 228 |  | 
 | 229 | TEST_F(LayerUpdateTest, LayerResizeWorks) { | 
 | 230 |     sp<ScreenCapture> sc; | 
 | 231 |     { | 
 | 232 |         SCOPED_TRACE("before resize"); | 
 | 233 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 234 |         sc->expectBGColor(0, 12); | 
 | 235 |         sc->expectFGColor(75, 75); | 
 | 236 |         sc->expectBGColor(145, 145); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 237 |     } | 
 | 238 |  | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 239 |     ALOGD("resizing"); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 240 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 241 |     ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setSize(128, 128)); | 
 | 242 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 243 |     ALOGD("resized"); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 244 |     { | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 249 |         sc->expectBGColor(0, 12); | 
 | 250 |         sc->expectFGColor(75, 75); | 
 | 251 |         sc->expectBGColor(145, 145); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 252 |     } | 
 | 253 |  | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 254 |     ALOGD("drawing"); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 255 |     fillSurfaceRGBA8(mFGSurfaceControl, 63, 195, 63); | 
 | 256 |     waitForPostedBuffers(); | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 257 |     ALOGD("drawn"); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 258 |     { | 
 | 259 |         // This should reflect the new size and the new color. | 
 | 260 |         SCOPED_TRACE("after redraw"); | 
 | 261 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 262 |         sc->expectBGColor(24, 24); | 
 | 263 |         sc->checkPixel(75, 75, 63, 195, 63); | 
 | 264 |         sc->checkPixel(145, 145, 63, 195, 63); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 265 |     } | 
 | 266 | } | 
 | 267 |  | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 268 | TEST_F(LayerUpdateTest, LayerCropWorks) { | 
 | 269 |     sp<ScreenCapture> sc; | 
 | 270 |     { | 
 | 271 |         SCOPED_TRACE("before crop"); | 
 | 272 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 273 |         sc->expectBGColor(24, 24); | 
 | 274 |         sc->expectFGColor(75, 75); | 
 | 275 |         sc->expectBGColor(145, 145); | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 276 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 286 |         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 Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 291 |     } | 
 | 292 | } | 
 | 293 |  | 
| Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 294 | TEST_F(LayerUpdateTest, LayerFinalCropWorks) { | 
 | 295 |     sp<ScreenCapture> sc; | 
 | 296 |     { | 
 | 297 |         SCOPED_TRACE("before crop"); | 
 | 298 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 299 |         sc->expectBGColor(24, 24); | 
 | 300 |         sc->expectFGColor(75, 75); | 
 | 301 |         sc->expectBGColor(145, 145); | 
| Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 302 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 311 |         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 Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 316 |     } | 
 | 317 | } | 
 | 318 |  | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 319 | TEST_F(LayerUpdateTest, LayerSetLayerWorks) { | 
 | 320 |     sp<ScreenCapture> sc; | 
 | 321 |     { | 
 | 322 |         SCOPED_TRACE("before setLayer"); | 
 | 323 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 324 |         sc->expectBGColor(24, 24); | 
 | 325 |         sc->expectFGColor(75, 75); | 
 | 326 |         sc->expectBGColor(145, 145); | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 327 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 336 |         sc->expectBGColor(24, 24); | 
 | 337 |         sc->expectBGColor(75, 75); | 
 | 338 |         sc->expectBGColor(145, 145); | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 339 |     } | 
 | 340 | } | 
 | 341 |  | 
 | 342 | TEST_F(LayerUpdateTest, LayerShowHideWorks) { | 
 | 343 |     sp<ScreenCapture> sc; | 
 | 344 |     { | 
 | 345 |         SCOPED_TRACE("before hide"); | 
 | 346 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 347 |         sc->expectBGColor(24, 24); | 
 | 348 |         sc->expectFGColor(75, 75); | 
 | 349 |         sc->expectBGColor(145, 145); | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 350 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 359 |         sc->expectBGColor(24, 24); | 
 | 360 |         sc->expectBGColor(75, 75); | 
 | 361 |         sc->expectBGColor(145, 145); | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 362 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 371 |         sc->expectBGColor(24, 24); | 
 | 372 |         sc->expectFGColor(75, 75); | 
 | 373 |         sc->expectBGColor(145, 145); | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 374 |     } | 
 | 375 | } | 
 | 376 |  | 
 | 377 | TEST_F(LayerUpdateTest, LayerSetAlphaWorks) { | 
 | 378 |     sp<ScreenCapture> sc; | 
 | 379 |     { | 
 | 380 |         SCOPED_TRACE("before setAlpha"); | 
 | 381 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 382 |         sc->expectBGColor(24, 24); | 
 | 383 |         sc->expectFGColor(75, 75); | 
 | 384 |         sc->expectBGColor(145, 145); | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 385 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 394 |         sc->expectBGColor(24, 24); | 
 | 395 |         sc->checkPixel(75, 75, 162, 63, 96); | 
 | 396 |         sc->expectBGColor(145, 145); | 
| Haixia Shi | d575096 | 2015-07-27 16:50:49 -0700 | [diff] [blame] | 397 |     } | 
 | 398 | } | 
 | 399 |  | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 400 | TEST_F(LayerUpdateTest, LayerSetLayerStackWorks) { | 
 | 401 |     sp<ScreenCapture> sc; | 
 | 402 |     { | 
 | 403 |         SCOPED_TRACE("before setLayerStack"); | 
 | 404 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 405 |         sc->expectBGColor(24, 24); | 
 | 406 |         sc->expectFGColor(75, 75); | 
 | 407 |         sc->expectBGColor(145, 145); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 408 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 418 |         sc->expectBGColor(24, 24); | 
 | 419 |         sc->expectBGColor(75, 75); | 
 | 420 |         sc->expectBGColor(145, 145); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 421 |     } | 
 | 422 | } | 
 | 423 |  | 
 | 424 | TEST_F(LayerUpdateTest, LayerSetFlagsWorks) { | 
 | 425 |     sp<ScreenCapture> sc; | 
 | 426 |     { | 
 | 427 |         SCOPED_TRACE("before setFlags"); | 
 | 428 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 429 |         sc->expectBGColor(24, 24); | 
 | 430 |         sc->expectFGColor(75, 75); | 
 | 431 |         sc->expectBGColor(145, 145); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 432 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 442 |         sc->expectBGColor(24, 24); | 
 | 443 |         sc->expectBGColor(75, 75); | 
 | 444 |         sc->expectBGColor(145, 145); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 445 |     } | 
 | 446 | } | 
 | 447 |  | 
 | 448 | TEST_F(LayerUpdateTest, LayerSetMatrixWorks) { | 
 | 449 |     sp<ScreenCapture> sc; | 
 | 450 |     { | 
 | 451 |         SCOPED_TRACE("before setMatrix"); | 
 | 452 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 453 |         sc->expectBGColor(24, 24); | 
 | 454 |         sc->expectFGColor(91, 96); | 
 | 455 |         sc->expectFGColor(96, 101); | 
 | 456 |         sc->expectBGColor(145, 145); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 457 |     } | 
 | 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 Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 466 |         sc->expectBGColor(24, 24); | 
 | 467 |         sc->expectFGColor(91, 96); | 
 | 468 |         sc->expectBGColor(96, 91); | 
 | 469 |         sc->expectBGColor(145, 145); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 470 |     } | 
 | 471 | } | 
 | 472 |  | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 473 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { | 
 | 474 |     sp<ScreenCapture> sc; | 
 | 475 |     { | 
 | 476 |         SCOPED_TRACE("before anything"); | 
 | 477 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 478 |         sc->expectBGColor(32, 32); | 
 | 479 |         sc->expectFGColor(96, 96); | 
 | 480 |         sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 481 |     } | 
 | 482 |  | 
 | 483 |     // set up two deferred transactions on different frames | 
 | 484 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 485 |     ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75)); | 
 | 486 |     mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(), | 
 | 487 |             mSyncSurfaceControl->getSurface()->getNextFrameNumber()); | 
 | 488 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 489 |  | 
 | 490 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 491 |     ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128,128)); | 
 | 492 |     mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(), | 
 | 493 |             mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); | 
 | 494 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 495 |  | 
 | 496 |     { | 
 | 497 |         SCOPED_TRACE("before any trigger"); | 
 | 498 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 499 |         sc->expectBGColor(32, 32); | 
 | 500 |         sc->expectFGColor(96, 96); | 
 | 501 |         sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 502 |     } | 
 | 503 |  | 
 | 504 |     // should trigger the first deferred transaction, but not the second one | 
 | 505 |     fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
 | 506 |     { | 
 | 507 |         SCOPED_TRACE("after first trigger"); | 
 | 508 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 509 |         sc->expectBGColor(32, 32); | 
 | 510 |         sc->checkPixel(96, 96, 162, 63, 96); | 
 | 511 |         sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 512 |     } | 
 | 513 |  | 
 | 514 |     // should show up immediately since it's not deferred | 
 | 515 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 516 |     ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(1.0)); | 
 | 517 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 518 |  | 
 | 519 |     // trigger the second deferred transaction | 
 | 520 |     fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
 | 521 |     { | 
 | 522 |         SCOPED_TRACE("after second trigger"); | 
 | 523 |         ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 524 |         sc->expectBGColor(32, 32); | 
 | 525 |         sc->expectBGColor(96, 96); | 
 | 526 |         sc->expectFGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 527 |     } | 
 | 528 | } | 
 | 529 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 530 | class ChildLayerTest : public LayerUpdateTest { | 
 | 531 | protected: | 
 | 532 |     void SetUp() override { | 
 | 533 |         LayerUpdateTest::SetUp(); | 
 | 534 |         mChild = mComposerClient->createSurface( | 
 | 535 |                 String8("Child surface"), | 
 | 536 |                 10, 10, PIXEL_FORMAT_RGBA_8888, | 
 | 537 |                 0, mFGSurfaceControl.get()); | 
 | 538 |         fillSurfaceRGBA8(mChild, 200, 200, 200); | 
 | 539 |  | 
 | 540 |         { | 
 | 541 |             SCOPED_TRACE("before anything"); | 
 | 542 |             ScreenCapture::captureScreen(&mCapture); | 
 | 543 |             mCapture->expectChildColor(64, 64); | 
 | 544 |         } | 
 | 545 |     } | 
 | 546 |     void TearDown() override { | 
 | 547 |         LayerUpdateTest::TearDown(); | 
 | 548 |         mChild = 0; | 
 | 549 |     } | 
 | 550 |  | 
 | 551 |     sp<SurfaceControl> mChild; | 
 | 552 |     sp<ScreenCapture> mCapture; | 
 | 553 | }; | 
 | 554 |  | 
 | 555 | TEST_F(ChildLayerTest, ChildLayerPositioning) { | 
 | 556 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 557 |     mChild->show(); | 
 | 558 |     mChild->setPosition(10, 10); | 
 | 559 |     mFGSurfaceControl->setPosition(64, 64); | 
 | 560 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 561 |  | 
 | 562 |     { | 
 | 563 |         ScreenCapture::captureScreen(&mCapture); | 
 | 564 |         // Top left of foreground must now be visible | 
 | 565 |         mCapture->expectFGColor(64, 64); | 
 | 566 |         // But 10 pixels in we should see the child surface | 
 | 567 |         mCapture->expectChildColor(74, 74); | 
 | 568 |         // And 10 more pixels we should be back to the foreground surface | 
 | 569 |         mCapture->expectFGColor(84, 84); | 
 | 570 |     } | 
 | 571 |  | 
 | 572 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 573 |     ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(0, 0)); | 
 | 574 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 575 |  | 
 | 576 |     { | 
 | 577 |         ScreenCapture::captureScreen(&mCapture); | 
 | 578 |         // Top left of foreground should now be at 0, 0 | 
 | 579 |         mCapture->expectFGColor(0, 0); | 
 | 580 |         // But 10 pixels in we should see the child surface | 
 | 581 |         mCapture->expectChildColor(10, 10); | 
 | 582 |         // And 10 more pixels we should be back to the foreground surface | 
 | 583 |         mCapture->expectFGColor(20, 20); | 
 | 584 |     } | 
 | 585 | } | 
 | 586 |  | 
 | 587 | TEST_F(ChildLayerTest, ChildLayerConstraints) { | 
 | 588 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 589 |     mChild->show(); | 
 | 590 |     mFGSurfaceControl->setPosition(0, 0); | 
 | 591 |     mChild->setPosition(63, 63); | 
 | 592 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 593 |  | 
 | 594 |     { | 
 | 595 |         ScreenCapture::captureScreen(&mCapture); | 
 | 596 |         mCapture->expectFGColor(0, 0); | 
 | 597 |         // Last pixel in foreground should now be the child. | 
 | 598 |         mCapture->expectChildColor(63, 63); | 
 | 599 |         // But the child should be constrained and the next pixel | 
 | 600 |         // must be the background | 
 | 601 |         mCapture->expectBGColor(64, 64); | 
 | 602 |     } | 
 | 603 | } | 
 | 604 |  | 
 | 605 | TEST_F(ChildLayerTest, ChildLayerScaling) { | 
 | 606 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 607 |     mFGSurfaceControl->setPosition(0, 0); | 
 | 608 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 609 |  | 
 | 610 |     // Find the boundary between the parent and child | 
 | 611 |     { | 
 | 612 |         ScreenCapture::captureScreen(&mCapture); | 
 | 613 |         mCapture->expectChildColor(9, 9); | 
 | 614 |         mCapture->expectFGColor(10, 10); | 
 | 615 |     } | 
 | 616 |  | 
 | 617 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 618 |     mFGSurfaceControl->setMatrix(2.0, 0, 0, 2.0); | 
 | 619 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 620 |  | 
 | 621 |     // The boundary should be twice as far from the origin now. | 
 | 622 |     // The pixels from the last test should all be child now | 
 | 623 |     { | 
 | 624 |         ScreenCapture::captureScreen(&mCapture); | 
 | 625 |         mCapture->expectChildColor(9, 9); | 
 | 626 |         mCapture->expectChildColor(10, 10); | 
 | 627 |         mCapture->expectChildColor(19, 19); | 
 | 628 |         mCapture->expectFGColor(20, 20); | 
 | 629 |     } | 
 | 630 | } | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 631 |  | 
 | 632 | TEST_F(ChildLayerTest, ReparentChildren) { | 
 | 633 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 634 |     mChild->show(); | 
 | 635 |     mChild->setPosition(10, 10); | 
 | 636 |     mFGSurfaceControl->setPosition(64, 64); | 
 | 637 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 638 |  | 
 | 639 |     { | 
 | 640 |         ScreenCapture::captureScreen(&mCapture); | 
 | 641 |         // Top left of foreground must now be visible | 
 | 642 |         mCapture->expectFGColor(64, 64); | 
 | 643 |         // But 10 pixels in we should see the child surface | 
 | 644 |         mCapture->expectChildColor(74, 74); | 
 | 645 |         // And 10 more pixels we should be back to the foreground surface | 
 | 646 |         mCapture->expectFGColor(84, 84); | 
 | 647 |     } | 
 | 648 |     mFGSurfaceControl->reparentChildren(mBGSurfaceControl->getHandle()); | 
 | 649 |     { | 
 | 650 |         ScreenCapture::captureScreen(&mCapture); | 
 | 651 |         mCapture->expectFGColor(64, 64); | 
 | 652 |         // In reparenting we should have exposed the entire foreground surface. | 
 | 653 |         mCapture->expectFGColor(74, 74); | 
 | 654 |         // And the child layer should now begin at 10, 10 (since the BG | 
 | 655 |         // layer is at (0, 0)). | 
 | 656 |         mCapture->expectBGColor(9, 9); | 
 | 657 |         mCapture->expectChildColor(10, 10); | 
 | 658 |     } | 
 | 659 | } | 
 | 660 |  | 
 | 661 | TEST_F(ChildLayerTest, DetachChildren) { | 
 | 662 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 663 |     mChild->show(); | 
 | 664 |     mChild->setPosition(10, 10); | 
 | 665 |     mFGSurfaceControl->setPosition(64, 64); | 
 | 666 |     SurfaceComposerClient::closeGlobalTransaction(true); | 
 | 667 |  | 
 | 668 |     { | 
 | 669 |         ScreenCapture::captureScreen(&mCapture); | 
 | 670 |         // Top left of foreground must now be visible | 
 | 671 |         mCapture->expectFGColor(64, 64); | 
 | 672 |         // But 10 pixels in we should see the child surface | 
 | 673 |         mCapture->expectChildColor(74, 74); | 
 | 674 |         // And 10 more pixels we should be back to the foreground surface | 
 | 675 |         mCapture->expectFGColor(84, 84); | 
 | 676 |     } | 
 | 677 |  | 
 | 678 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 679 |     mFGSurfaceControl->detachChildren(); | 
 | 680 |     SurfaceComposerClient::closeGlobalTransaction(); | 
 | 681 |  | 
 | 682 |     SurfaceComposerClient::openGlobalTransaction(); | 
 | 683 |     mChild->hide(); | 
 | 684 |     SurfaceComposerClient::closeGlobalTransaction(); | 
 | 685 |  | 
 | 686 |     // Nothing should have changed. | 
 | 687 |     { | 
 | 688 |         ScreenCapture::captureScreen(&mCapture); | 
 | 689 |         mCapture->expectFGColor(64, 64); | 
 | 690 |         mCapture->expectChildColor(74, 74); | 
 | 691 |         mCapture->expectFGColor(84, 84); | 
 | 692 |     } | 
 | 693 | } | 
 | 694 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 695 | } |