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