| 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 |  | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 473 | class GeometryLatchingTest : public LayerUpdateTest { | 
|  | 474 | protected: | 
|  | 475 | void EXPECT_INITIAL_STATE(const char * trace) { | 
|  | 476 | SCOPED_TRACE(trace); | 
|  | 477 | ScreenCapture::captureScreen(&sc); | 
|  | 478 | // We find the leading edge of the FG surface. | 
|  | 479 | sc->expectFGColor(127, 127); | 
|  | 480 | sc->expectBGColor(128, 128); | 
|  | 481 | } | 
|  | 482 | void completeFGResize() { | 
|  | 483 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 484 | waitForPostedBuffers(); | 
|  | 485 | } | 
|  | 486 | void restoreInitialState() { | 
|  | 487 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 488 | mFGSurfaceControl->setSize(64, 64); | 
|  | 489 | mFGSurfaceControl->setPosition(64, 64); | 
|  | 490 | mFGSurfaceControl->setCrop(Rect(0, 0, 64, 64)); | 
|  | 491 | mFGSurfaceControl->setFinalCrop(Rect(0, 0, -1, -1)); | 
|  | 492 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 493 |  | 
|  | 494 | EXPECT_INITIAL_STATE("After restoring initial state"); | 
|  | 495 | } | 
|  | 496 | sp<ScreenCapture> sc; | 
|  | 497 | }; | 
|  | 498 |  | 
|  | 499 | TEST_F(GeometryLatchingTest, SurfacePositionLatching) { | 
|  | 500 | EXPECT_INITIAL_STATE("before anything"); | 
|  | 501 |  | 
|  | 502 | // By default position can be updated even while | 
|  | 503 | // a resize is pending. | 
|  | 504 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 505 | mFGSurfaceControl->setSize(32, 32); | 
|  | 506 | mFGSurfaceControl->setPosition(100, 100); | 
|  | 507 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 508 |  | 
|  | 509 | { | 
|  | 510 | SCOPED_TRACE("After moving surface"); | 
|  | 511 | ScreenCapture::captureScreen(&sc); | 
|  | 512 | // If we moved, the FG Surface should cover up what was previously BG | 
|  | 513 | // however if we didn't move the FG wouldn't be large enough now. | 
|  | 514 | sc->expectFGColor(163, 163); | 
|  | 515 | } | 
|  | 516 |  | 
|  | 517 | restoreInitialState(); | 
|  | 518 |  | 
|  | 519 | // Now we repeat with setGeometryAppliesWithResize | 
|  | 520 | // and verify the position DOESN'T latch. | 
|  | 521 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 522 | mFGSurfaceControl->setGeometryAppliesWithResize(); | 
|  | 523 | mFGSurfaceControl->setSize(32, 32); | 
|  | 524 | mFGSurfaceControl->setPosition(100, 100); | 
|  | 525 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 526 |  | 
|  | 527 | { | 
|  | 528 | SCOPED_TRACE("While resize is pending"); | 
|  | 529 | ScreenCapture::captureScreen(&sc); | 
|  | 530 | // This time we shouldn't have moved, so the BG color | 
|  | 531 | // should still be visible. | 
|  | 532 | sc->expectBGColor(128, 128); | 
|  | 533 | } | 
|  | 534 |  | 
|  | 535 | completeFGResize(); | 
|  | 536 |  | 
|  | 537 | { | 
|  | 538 | SCOPED_TRACE("After the resize"); | 
|  | 539 | ScreenCapture::captureScreen(&sc); | 
|  | 540 | // But after the resize completes, we should move | 
|  | 541 | // and the FG should be visible here. | 
|  | 542 | sc->expectFGColor(128, 128); | 
|  | 543 | } | 
|  | 544 | } | 
|  | 545 |  | 
|  | 546 | class CropLatchingTest : public GeometryLatchingTest { | 
|  | 547 | protected: | 
|  | 548 | void EXPECT_CROPPED_STATE(const char* trace) { | 
|  | 549 | SCOPED_TRACE(trace); | 
|  | 550 | ScreenCapture::captureScreen(&sc); | 
|  | 551 | // The edge should be moved back one pixel by our crop. | 
|  | 552 | sc->expectFGColor(126, 126); | 
|  | 553 | sc->expectBGColor(127, 127); | 
|  | 554 | sc->expectBGColor(128, 128); | 
|  | 555 | } | 
|  | 556 | }; | 
|  | 557 |  | 
|  | 558 | TEST_F(CropLatchingTest, CropLatching) { | 
|  | 559 | EXPECT_INITIAL_STATE("before anything"); | 
|  | 560 | // Normally the crop applies immediately even while a resize is pending. | 
|  | 561 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 562 | mFGSurfaceControl->setSize(128, 128); | 
|  | 563 | mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63)); | 
|  | 564 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 565 |  | 
|  | 566 | EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)"); | 
|  | 567 |  | 
|  | 568 | restoreInitialState(); | 
|  | 569 |  | 
|  | 570 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 571 | mFGSurfaceControl->setSize(128, 128); | 
|  | 572 | mFGSurfaceControl->setGeometryAppliesWithResize(); | 
|  | 573 | mFGSurfaceControl->setCrop(Rect(0, 0, 63, 63)); | 
|  | 574 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 575 |  | 
|  | 576 | EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)"); | 
|  | 577 |  | 
|  | 578 | completeFGResize(); | 
|  | 579 |  | 
|  | 580 | EXPECT_CROPPED_STATE("after the resize finishes"); | 
|  | 581 | } | 
|  | 582 |  | 
|  | 583 | TEST_F(CropLatchingTest, FinalCropLatching) { | 
|  | 584 | EXPECT_INITIAL_STATE("before anything"); | 
|  | 585 | // Normally the crop applies immediately even while a resize is pending. | 
|  | 586 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 587 | mFGSurfaceControl->setSize(128, 128); | 
|  | 588 | mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127)); | 
|  | 589 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 590 |  | 
|  | 591 | EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)"); | 
|  | 592 |  | 
|  | 593 | restoreInitialState(); | 
|  | 594 |  | 
|  | 595 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 596 | mFGSurfaceControl->setSize(128, 128); | 
|  | 597 | mFGSurfaceControl->setGeometryAppliesWithResize(); | 
|  | 598 | mFGSurfaceControl->setFinalCrop(Rect(64, 64, 127, 127)); | 
|  | 599 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 600 |  | 
|  | 601 | EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)"); | 
|  | 602 |  | 
|  | 603 | completeFGResize(); | 
|  | 604 |  | 
|  | 605 | EXPECT_CROPPED_STATE("after the resize finishes"); | 
|  | 606 | } | 
|  | 607 |  | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 608 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { | 
|  | 609 | sp<ScreenCapture> sc; | 
|  | 610 | { | 
|  | 611 | SCOPED_TRACE("before anything"); | 
|  | 612 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 613 | sc->expectBGColor(32, 32); | 
|  | 614 | sc->expectFGColor(96, 96); | 
|  | 615 | sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 616 | } | 
|  | 617 |  | 
|  | 618 | // set up two deferred transactions on different frames | 
|  | 619 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 620 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.75)); | 
|  | 621 | mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(), | 
|  | 622 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); | 
|  | 623 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 624 |  | 
|  | 625 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 626 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(128,128)); | 
|  | 627 | mFGSurfaceControl->deferTransactionUntil(mSyncSurfaceControl->getHandle(), | 
|  | 628 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); | 
|  | 629 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 630 |  | 
|  | 631 | { | 
|  | 632 | SCOPED_TRACE("before any trigger"); | 
|  | 633 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 634 | sc->expectBGColor(32, 32); | 
|  | 635 | sc->expectFGColor(96, 96); | 
|  | 636 | sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 637 | } | 
|  | 638 |  | 
|  | 639 | // should trigger the first deferred transaction, but not the second one | 
|  | 640 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 641 | { | 
|  | 642 | SCOPED_TRACE("after first trigger"); | 
|  | 643 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 644 | sc->expectBGColor(32, 32); | 
|  | 645 | sc->checkPixel(96, 96, 162, 63, 96); | 
|  | 646 | sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 647 | } | 
|  | 648 |  | 
|  | 649 | // should show up immediately since it's not deferred | 
|  | 650 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 651 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(1.0)); | 
|  | 652 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 653 |  | 
|  | 654 | // trigger the second deferred transaction | 
|  | 655 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 656 | { | 
|  | 657 | SCOPED_TRACE("after second trigger"); | 
|  | 658 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 659 | sc->expectBGColor(32, 32); | 
|  | 660 | sc->expectBGColor(96, 96); | 
|  | 661 | sc->expectFGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 662 | } | 
|  | 663 | } | 
|  | 664 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 665 | class ChildLayerTest : public LayerUpdateTest { | 
|  | 666 | protected: | 
|  | 667 | void SetUp() override { | 
|  | 668 | LayerUpdateTest::SetUp(); | 
|  | 669 | mChild = mComposerClient->createSurface( | 
|  | 670 | String8("Child surface"), | 
|  | 671 | 10, 10, PIXEL_FORMAT_RGBA_8888, | 
|  | 672 | 0, mFGSurfaceControl.get()); | 
|  | 673 | fillSurfaceRGBA8(mChild, 200, 200, 200); | 
|  | 674 |  | 
|  | 675 | { | 
|  | 676 | SCOPED_TRACE("before anything"); | 
|  | 677 | ScreenCapture::captureScreen(&mCapture); | 
|  | 678 | mCapture->expectChildColor(64, 64); | 
|  | 679 | } | 
|  | 680 | } | 
|  | 681 | void TearDown() override { | 
|  | 682 | LayerUpdateTest::TearDown(); | 
|  | 683 | mChild = 0; | 
|  | 684 | } | 
|  | 685 |  | 
|  | 686 | sp<SurfaceControl> mChild; | 
|  | 687 | sp<ScreenCapture> mCapture; | 
|  | 688 | }; | 
|  | 689 |  | 
|  | 690 | TEST_F(ChildLayerTest, ChildLayerPositioning) { | 
|  | 691 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 692 | mChild->show(); | 
|  | 693 | mChild->setPosition(10, 10); | 
|  | 694 | mFGSurfaceControl->setPosition(64, 64); | 
|  | 695 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 696 |  | 
|  | 697 | { | 
|  | 698 | ScreenCapture::captureScreen(&mCapture); | 
|  | 699 | // Top left of foreground must now be visible | 
|  | 700 | mCapture->expectFGColor(64, 64); | 
|  | 701 | // But 10 pixels in we should see the child surface | 
|  | 702 | mCapture->expectChildColor(74, 74); | 
|  | 703 | // And 10 more pixels we should be back to the foreground surface | 
|  | 704 | mCapture->expectFGColor(84, 84); | 
|  | 705 | } | 
|  | 706 |  | 
|  | 707 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 708 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setPosition(0, 0)); | 
|  | 709 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 710 |  | 
|  | 711 | { | 
|  | 712 | ScreenCapture::captureScreen(&mCapture); | 
|  | 713 | // Top left of foreground should now be at 0, 0 | 
|  | 714 | mCapture->expectFGColor(0, 0); | 
|  | 715 | // But 10 pixels in we should see the child surface | 
|  | 716 | mCapture->expectChildColor(10, 10); | 
|  | 717 | // And 10 more pixels we should be back to the foreground surface | 
|  | 718 | mCapture->expectFGColor(20, 20); | 
|  | 719 | } | 
|  | 720 | } | 
|  | 721 |  | 
|  | 722 | TEST_F(ChildLayerTest, ChildLayerConstraints) { | 
|  | 723 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 724 | mChild->show(); | 
|  | 725 | mFGSurfaceControl->setPosition(0, 0); | 
|  | 726 | mChild->setPosition(63, 63); | 
|  | 727 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 728 |  | 
|  | 729 | { | 
|  | 730 | ScreenCapture::captureScreen(&mCapture); | 
|  | 731 | mCapture->expectFGColor(0, 0); | 
|  | 732 | // Last pixel in foreground should now be the child. | 
|  | 733 | mCapture->expectChildColor(63, 63); | 
|  | 734 | // But the child should be constrained and the next pixel | 
|  | 735 | // must be the background | 
|  | 736 | mCapture->expectBGColor(64, 64); | 
|  | 737 | } | 
|  | 738 | } | 
|  | 739 |  | 
|  | 740 | TEST_F(ChildLayerTest, ChildLayerScaling) { | 
|  | 741 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 742 | mFGSurfaceControl->setPosition(0, 0); | 
|  | 743 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 744 |  | 
|  | 745 | // Find the boundary between the parent and child | 
|  | 746 | { | 
|  | 747 | ScreenCapture::captureScreen(&mCapture); | 
|  | 748 | mCapture->expectChildColor(9, 9); | 
|  | 749 | mCapture->expectFGColor(10, 10); | 
|  | 750 | } | 
|  | 751 |  | 
|  | 752 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 753 | mFGSurfaceControl->setMatrix(2.0, 0, 0, 2.0); | 
|  | 754 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 755 |  | 
|  | 756 | // The boundary should be twice as far from the origin now. | 
|  | 757 | // The pixels from the last test should all be child now | 
|  | 758 | { | 
|  | 759 | ScreenCapture::captureScreen(&mCapture); | 
|  | 760 | mCapture->expectChildColor(9, 9); | 
|  | 761 | mCapture->expectChildColor(10, 10); | 
|  | 762 | mCapture->expectChildColor(19, 19); | 
|  | 763 | mCapture->expectFGColor(20, 20); | 
|  | 764 | } | 
|  | 765 | } | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 766 |  | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 767 | TEST_F(ChildLayerTest, ChildLayerAlpha) { | 
|  | 768 | fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254); | 
|  | 769 | fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0); | 
|  | 770 | fillSurfaceRGBA8(mChild, 0, 254, 0); | 
|  | 771 | waitForPostedBuffers(); | 
|  | 772 |  | 
|  | 773 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 774 | mChild->show(); | 
|  | 775 | mChild->setPosition(0, 0); | 
|  | 776 | mFGSurfaceControl->setPosition(0, 0); | 
|  | 777 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 778 |  | 
|  | 779 | { | 
|  | 780 | ScreenCapture::captureScreen(&mCapture); | 
|  | 781 | // Unblended child color | 
|  | 782 | mCapture->checkPixel(0, 0, 0, 254, 0); | 
|  | 783 | } | 
|  | 784 |  | 
|  | 785 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 786 | ASSERT_EQ(NO_ERROR, mChild->setAlpha(0.5)); | 
|  | 787 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 788 |  | 
|  | 789 | { | 
|  | 790 | ScreenCapture::captureScreen(&mCapture); | 
|  | 791 | // Child and BG blended. | 
|  | 792 | mCapture->checkPixel(0, 0, 127, 127, 0); | 
|  | 793 | } | 
|  | 794 |  | 
|  | 795 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 796 | ASSERT_EQ(NO_ERROR, mFGSurfaceControl->setAlpha(0.5)); | 
|  | 797 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 798 |  | 
|  | 799 | { | 
|  | 800 | ScreenCapture::captureScreen(&mCapture); | 
|  | 801 | // Child and BG blended. | 
|  | 802 | mCapture->checkPixel(0, 0, 95, 64, 95); | 
|  | 803 | } | 
|  | 804 | } | 
|  | 805 |  | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 806 | TEST_F(ChildLayerTest, ReparentChildren) { | 
|  | 807 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 808 | mChild->show(); | 
|  | 809 | mChild->setPosition(10, 10); | 
|  | 810 | mFGSurfaceControl->setPosition(64, 64); | 
|  | 811 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 812 |  | 
|  | 813 | { | 
|  | 814 | ScreenCapture::captureScreen(&mCapture); | 
|  | 815 | // Top left of foreground must now be visible | 
|  | 816 | mCapture->expectFGColor(64, 64); | 
|  | 817 | // But 10 pixels in we should see the child surface | 
|  | 818 | mCapture->expectChildColor(74, 74); | 
|  | 819 | // And 10 more pixels we should be back to the foreground surface | 
|  | 820 | mCapture->expectFGColor(84, 84); | 
|  | 821 | } | 
|  | 822 | mFGSurfaceControl->reparentChildren(mBGSurfaceControl->getHandle()); | 
|  | 823 | { | 
|  | 824 | ScreenCapture::captureScreen(&mCapture); | 
|  | 825 | mCapture->expectFGColor(64, 64); | 
|  | 826 | // In reparenting we should have exposed the entire foreground surface. | 
|  | 827 | mCapture->expectFGColor(74, 74); | 
|  | 828 | // And the child layer should now begin at 10, 10 (since the BG | 
|  | 829 | // layer is at (0, 0)). | 
|  | 830 | mCapture->expectBGColor(9, 9); | 
|  | 831 | mCapture->expectChildColor(10, 10); | 
|  | 832 | } | 
|  | 833 | } | 
|  | 834 |  | 
|  | 835 | TEST_F(ChildLayerTest, DetachChildren) { | 
|  | 836 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 837 | mChild->show(); | 
|  | 838 | mChild->setPosition(10, 10); | 
|  | 839 | mFGSurfaceControl->setPosition(64, 64); | 
|  | 840 | SurfaceComposerClient::closeGlobalTransaction(true); | 
|  | 841 |  | 
|  | 842 | { | 
|  | 843 | ScreenCapture::captureScreen(&mCapture); | 
|  | 844 | // Top left of foreground must now be visible | 
|  | 845 | mCapture->expectFGColor(64, 64); | 
|  | 846 | // But 10 pixels in we should see the child surface | 
|  | 847 | mCapture->expectChildColor(74, 74); | 
|  | 848 | // And 10 more pixels we should be back to the foreground surface | 
|  | 849 | mCapture->expectFGColor(84, 84); | 
|  | 850 | } | 
|  | 851 |  | 
|  | 852 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 853 | mFGSurfaceControl->detachChildren(); | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 854 | SurfaceComposerClient::closeGlobalTransaction(true); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 855 |  | 
|  | 856 | SurfaceComposerClient::openGlobalTransaction(); | 
|  | 857 | mChild->hide(); | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 858 | SurfaceComposerClient::closeGlobalTransaction(true); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 859 |  | 
|  | 860 | // Nothing should have changed. | 
|  | 861 | { | 
|  | 862 | ScreenCapture::captureScreen(&mCapture); | 
|  | 863 | mCapture->expectFGColor(64, 64); | 
|  | 864 | mCapture->expectChildColor(74, 74); | 
|  | 865 | mCapture->expectFGColor(84, 84); | 
|  | 866 | } | 
|  | 867 | } | 
|  | 868 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 869 | } |