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