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 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 17 | #include <algorithm> |
| 18 | #include <functional> |
| 19 | #include <limits> |
| 20 | #include <ostream> |
| 21 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 22 | #include <gtest/gtest.h> |
| 23 | |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 24 | #include <android/native_window.h> |
| 25 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 26 | #include <gui/ISurfaceComposer.h> |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 27 | #include <gui/LayerState.h> |
| 28 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 29 | #include <gui/Surface.h> |
| 30 | #include <gui/SurfaceComposerClient.h> |
| 31 | #include <private/gui/ComposerService.h> |
| 32 | |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 33 | #include <ui/DisplayInfo.h> |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 34 | #include <ui/Rect.h> |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 35 | #include <utils/String8.h> |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 36 | |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 37 | #include <math.h> |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 38 | #include <math/vec3.h> |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 39 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 40 | namespace android { |
| 41 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 42 | namespace { |
| 43 | |
| 44 | struct Color { |
| 45 | uint8_t r; |
| 46 | uint8_t g; |
| 47 | uint8_t b; |
| 48 | uint8_t a; |
| 49 | |
| 50 | static const Color RED; |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 51 | static const Color GREEN; |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 52 | static const Color BLUE; |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 53 | static const Color WHITE; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 54 | static const Color BLACK; |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 55 | static const Color TRANSPARENT; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | const Color Color::RED{255, 0, 0, 255}; |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 59 | const Color Color::GREEN{0, 255, 0, 255}; |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 60 | const Color Color::BLUE{0, 0, 255, 255}; |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 61 | const Color Color::WHITE{255, 255, 255, 255}; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 62 | const Color Color::BLACK{0, 0, 0, 255}; |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 63 | const Color Color::TRANSPARENT{0, 0, 0, 0}; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 64 | |
| 65 | std::ostream& operator<<(std::ostream& os, const Color& color) { |
| 66 | os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a); |
| 67 | return os; |
| 68 | } |
| 69 | |
| 70 | // Fill a region with the specified color. |
| 71 | void fillBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect, const Color& color) { |
| 72 | int32_t x = rect.left; |
| 73 | int32_t y = rect.top; |
| 74 | int32_t width = rect.right - rect.left; |
| 75 | int32_t height = rect.bottom - rect.top; |
| 76 | |
| 77 | if (x < 0) { |
| 78 | width += x; |
| 79 | x = 0; |
| 80 | } |
| 81 | if (y < 0) { |
| 82 | height += y; |
| 83 | y = 0; |
| 84 | } |
| 85 | if (x + width > buffer.width) { |
| 86 | x = std::min(x, buffer.width); |
| 87 | width = buffer.width - x; |
| 88 | } |
| 89 | if (y + height > buffer.height) { |
| 90 | y = std::min(y, buffer.height); |
| 91 | height = buffer.height - y; |
| 92 | } |
| 93 | |
| 94 | for (int32_t j = 0; j < height; j++) { |
| 95 | uint8_t* dst = static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (y + j) + x) * 4; |
| 96 | for (int32_t i = 0; i < width; i++) { |
| 97 | dst[0] = color.r; |
| 98 | dst[1] = color.g; |
| 99 | dst[2] = color.b; |
| 100 | dst[3] = color.a; |
| 101 | dst += 4; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Check if a region has the specified color. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 107 | void expectBufferColor(const sp<GraphicBuffer>& outBuffer, uint8_t* pixels, const Rect& rect, |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 108 | const Color& color, uint8_t tolerance) { |
| 109 | int32_t x = rect.left; |
| 110 | int32_t y = rect.top; |
| 111 | int32_t width = rect.right - rect.left; |
| 112 | int32_t height = rect.bottom - rect.top; |
| 113 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 114 | int32_t bufferWidth = int32_t(outBuffer->getWidth()); |
| 115 | int32_t bufferHeight = int32_t(outBuffer->getHeight()); |
| 116 | if (x + width > bufferWidth) { |
| 117 | x = std::min(x, bufferWidth); |
| 118 | width = bufferWidth - x; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 119 | } |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 120 | if (y + height > bufferHeight) { |
| 121 | y = std::min(y, bufferHeight); |
| 122 | height = bufferHeight - y; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | auto colorCompare = [tolerance](uint8_t a, uint8_t b) { |
| 126 | uint8_t tmp = a >= b ? a - b : b - a; |
| 127 | return tmp <= tolerance; |
| 128 | }; |
| 129 | for (int32_t j = 0; j < height; j++) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 130 | const uint8_t* src = pixels + (outBuffer->getStride() * (y + j) + x) * 4; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 131 | for (int32_t i = 0; i < width; i++) { |
| 132 | const uint8_t expected[4] = {color.r, color.g, color.b, color.a}; |
| 133 | EXPECT_TRUE(std::equal(src, src + 4, expected, colorCompare)) |
| 134 | << "pixel @ (" << x + i << ", " << y + j << "): " |
| 135 | << "expected (" << color << "), " |
| 136 | << "got (" << Color{src[0], src[1], src[2], src[3]} << ")"; |
| 137 | src += 4; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | } // anonymous namespace |
| 143 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 144 | using Transaction = SurfaceComposerClient::Transaction; |
| 145 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 146 | // Fill an RGBA_8888 formatted surface with a single color. |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 147 | static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b, |
| 148 | bool unlock = true) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 149 | ANativeWindow_Buffer outBuffer; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 150 | sp<Surface> s = sc->getSurface(); |
| 151 | ASSERT_TRUE(s != NULL); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 152 | ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, NULL)); |
| 153 | uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 154 | for (int y = 0; y < outBuffer.height; y++) { |
| 155 | for (int x = 0; x < outBuffer.width; x++) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 156 | uint8_t* pixel = img + (4 * (y * outBuffer.stride + x)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 157 | pixel[0] = r; |
| 158 | pixel[1] = g; |
| 159 | pixel[2] = b; |
| 160 | pixel[3] = 255; |
| 161 | } |
| 162 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 163 | if (unlock) { |
| 164 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 165 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | // A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check |
| 169 | // individual pixel values for testing purposes. |
| 170 | class ScreenCapture : public RefBase { |
| 171 | public: |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 172 | static void captureScreen(sp<ScreenCapture>* sc, int32_t minLayerZ = 0, |
| 173 | int32_t maxLayerZ = std::numeric_limits<int32_t>::max()) { |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 174 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 175 | sp<IBinder> display(sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 176 | SurfaceComposerClient::Transaction().apply(true); |
| 177 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 178 | sp<GraphicBuffer> outBuffer; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 179 | ASSERT_EQ(NO_ERROR, |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 180 | sf->captureScreen(display, &outBuffer, Rect(), 0, 0, minLayerZ, maxLayerZ, |
| 181 | false)); |
| 182 | *sc = new ScreenCapture(outBuffer); |
| 183 | } |
| 184 | |
| 185 | static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, |
| 186 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { |
| 187 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 188 | SurfaceComposerClient::Transaction().apply(true); |
| 189 | |
| 190 | sp<GraphicBuffer> outBuffer; |
| 191 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale)); |
| 192 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 195 | void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 196 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
| 197 | expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 201 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 202 | const bool leftBorder = rect.left > 0; |
| 203 | const bool topBorder = rect.top > 0; |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 204 | const bool rightBorder = rect.right < int32_t(mOutBuffer->getWidth()); |
| 205 | const bool bottomBorder = rect.bottom < int32_t(mOutBuffer->getHeight()); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 206 | |
| 207 | if (topBorder) { |
| 208 | Rect top(rect.left, rect.top - 1, rect.right, rect.top); |
| 209 | if (leftBorder) { |
| 210 | top.left -= 1; |
| 211 | } |
| 212 | if (rightBorder) { |
| 213 | top.right += 1; |
| 214 | } |
| 215 | expectColor(top, color, tolerance); |
| 216 | } |
| 217 | if (leftBorder) { |
| 218 | Rect left(rect.left - 1, rect.top, rect.left, rect.bottom); |
| 219 | expectColor(left, color, tolerance); |
| 220 | } |
| 221 | if (rightBorder) { |
| 222 | Rect right(rect.right, rect.top, rect.right + 1, rect.bottom); |
| 223 | expectColor(right, color, tolerance); |
| 224 | } |
| 225 | if (bottomBorder) { |
| 226 | Rect bottom(rect.left, rect.bottom, rect.right, rect.bottom + 1); |
| 227 | if (leftBorder) { |
| 228 | bottom.left -= 1; |
| 229 | } |
| 230 | if (rightBorder) { |
| 231 | bottom.right += 1; |
| 232 | } |
| 233 | expectColor(bottom, color, tolerance); |
| 234 | } |
| 235 | } |
| 236 | |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 237 | void expectQuadrant(const Rect& rect, const Color& topLeft, const Color& topRight, |
| 238 | const Color& bottomLeft, const Color& bottomRight, bool filtered = false, |
| 239 | uint8_t tolerance = 0) { |
| 240 | ASSERT_TRUE((rect.right - rect.left) % 2 == 0 && (rect.bottom - rect.top) % 2 == 0); |
| 241 | |
| 242 | const int32_t centerX = rect.left + (rect.right - rect.left) / 2; |
| 243 | const int32_t centerY = rect.top + (rect.bottom - rect.top) / 2; |
| 244 | // avoid checking borders due to unspecified filtering behavior |
| 245 | const int32_t offsetX = filtered ? 2 : 0; |
| 246 | const int32_t offsetY = filtered ? 2 : 0; |
| 247 | expectColor(Rect(rect.left, rect.top, centerX - offsetX, centerY - offsetY), topLeft, |
| 248 | tolerance); |
| 249 | expectColor(Rect(centerX + offsetX, rect.top, rect.right, centerY - offsetY), topRight, |
| 250 | tolerance); |
| 251 | expectColor(Rect(rect.left, centerY + offsetY, centerX - offsetX, rect.bottom), bottomLeft, |
| 252 | tolerance); |
| 253 | expectColor(Rect(centerX + offsetX, centerY + offsetY, rect.right, rect.bottom), |
| 254 | bottomRight, tolerance); |
| 255 | } |
| 256 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 257 | void checkPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 258 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
| 259 | const uint8_t* pixel = mPixels + (4 * (y * mOutBuffer->getStride() + x)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 260 | if (r != pixel[0] || g != pixel[1] || b != pixel[2]) { |
| 261 | String8 err(String8::format("pixel @ (%3d, %3d): " |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 262 | "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]", |
| 263 | x, y, r, g, b, pixel[0], pixel[1], pixel[2])); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 264 | EXPECT_EQ(String8(), err) << err.string(); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 268 | void expectFGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 195, 63, 63); } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 269 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 270 | void expectBGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 63, 63, 195); } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 271 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 272 | void expectChildColor(uint32_t x, uint32_t y) { checkPixel(x, y, 200, 200, 200); } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 273 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 274 | ScreenCapture(const sp<GraphicBuffer>& outBuffer) : mOutBuffer(outBuffer) { |
| 275 | mOutBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&mPixels)); |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 276 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 277 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 278 | ~ScreenCapture() { mOutBuffer->unlock(); } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 279 | |
| 280 | private: |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 281 | sp<GraphicBuffer> mOutBuffer; |
| 282 | uint8_t* mPixels = NULL; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 285 | class LayerTransactionTest : public ::testing::Test { |
| 286 | protected: |
| 287 | void SetUp() override { |
| 288 | mClient = new SurfaceComposerClient; |
| 289 | ASSERT_EQ(NO_ERROR, mClient->initCheck()) << "failed to create SurfaceComposerClient"; |
| 290 | |
| 291 | ASSERT_NO_FATAL_FAILURE(SetUpDisplay()); |
| 292 | } |
| 293 | |
| 294 | sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, |
| 295 | uint32_t flags = 0) { |
| 296 | auto layer = |
| 297 | mClient->createSurface(String8(name), width, height, PIXEL_FORMAT_RGBA_8888, flags); |
| 298 | EXPECT_NE(nullptr, layer.get()) << "failed to create SurfaceControl"; |
| 299 | |
| 300 | status_t error = Transaction() |
| 301 | .setLayerStack(layer, mDisplayLayerStack) |
| 302 | .setLayer(layer, mLayerZBase) |
| 303 | .apply(); |
| 304 | if (error != NO_ERROR) { |
| 305 | ADD_FAILURE() << "failed to initialize SurfaceControl"; |
| 306 | layer.clear(); |
| 307 | } |
| 308 | |
| 309 | return layer; |
| 310 | } |
| 311 | |
| 312 | ANativeWindow_Buffer getLayerBuffer(const sp<SurfaceControl>& layer) { |
| 313 | // wait for previous transactions (such as setSize) to complete |
| 314 | Transaction().apply(true); |
| 315 | |
| 316 | ANativeWindow_Buffer buffer = {}; |
| 317 | EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr)); |
| 318 | |
| 319 | return buffer; |
| 320 | } |
| 321 | |
| 322 | void postLayerBuffer(const sp<SurfaceControl>& layer) { |
| 323 | ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost()); |
| 324 | |
| 325 | // wait for the newly posted buffer to be latched |
| 326 | waitForLayerBuffers(); |
| 327 | } |
| 328 | |
| 329 | void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color) { |
| 330 | ANativeWindow_Buffer buffer; |
| 331 | ASSERT_NO_FATAL_FAILURE(buffer = getLayerBuffer(layer)); |
| 332 | fillBufferColor(buffer, Rect(0, 0, buffer.width, buffer.height), color); |
| 333 | postLayerBuffer(layer); |
| 334 | } |
| 335 | |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 336 | void fillLayerQuadrant(const sp<SurfaceControl>& layer, const Color& topLeft, |
| 337 | const Color& topRight, const Color& bottomLeft, |
| 338 | const Color& bottomRight) { |
| 339 | ANativeWindow_Buffer buffer; |
| 340 | ASSERT_NO_FATAL_FAILURE(buffer = getLayerBuffer(layer)); |
| 341 | ASSERT_TRUE(buffer.width % 2 == 0 && buffer.height % 2 == 0); |
| 342 | |
| 343 | const int32_t halfW = buffer.width / 2; |
| 344 | const int32_t halfH = buffer.height / 2; |
| 345 | fillBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); |
| 346 | fillBufferColor(buffer, Rect(halfW, 0, buffer.width, halfH), topRight); |
| 347 | fillBufferColor(buffer, Rect(0, halfH, halfW, buffer.height), bottomLeft); |
| 348 | fillBufferColor(buffer, Rect(halfW, halfH, buffer.width, buffer.height), bottomRight); |
| 349 | |
| 350 | postLayerBuffer(layer); |
| 351 | } |
| 352 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 353 | sp<ScreenCapture> screenshot() { |
| 354 | sp<ScreenCapture> screenshot; |
| 355 | ScreenCapture::captureScreen(&screenshot, mLayerZBase); |
| 356 | return screenshot; |
| 357 | } |
| 358 | |
| 359 | sp<SurfaceComposerClient> mClient; |
| 360 | |
| 361 | sp<IBinder> mDisplay; |
| 362 | uint32_t mDisplayWidth; |
| 363 | uint32_t mDisplayHeight; |
| 364 | uint32_t mDisplayLayerStack; |
| 365 | |
| 366 | // leave room for ~256 layers |
| 367 | const int32_t mLayerZBase = std::numeric_limits<int32_t>::max() - 256; |
| 368 | |
| 369 | private: |
| 370 | void SetUpDisplay() { |
| 371 | mDisplay = mClient->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain); |
| 372 | ASSERT_NE(nullptr, mDisplay.get()) << "failed to get built-in display"; |
| 373 | |
| 374 | // get display width/height |
| 375 | DisplayInfo info; |
| 376 | SurfaceComposerClient::getDisplayInfo(mDisplay, &info); |
| 377 | mDisplayWidth = info.w; |
| 378 | mDisplayHeight = info.h; |
| 379 | |
| 380 | // After a new buffer is queued, SurfaceFlinger is notified and will |
| 381 | // latch the new buffer on next vsync. Let's heuristically wait for 3 |
| 382 | // vsyncs. |
| 383 | mBufferPostDelay = int32_t(1e6 / info.fps) * 3; |
| 384 | |
| 385 | mDisplayLayerStack = 0; |
| 386 | // set layer stack (b/68888219) |
| 387 | Transaction t; |
| 388 | t.setDisplayLayerStack(mDisplay, mDisplayLayerStack); |
| 389 | t.apply(); |
| 390 | } |
| 391 | |
| 392 | void waitForLayerBuffers() { usleep(mBufferPostDelay); } |
| 393 | |
| 394 | int32_t mBufferPostDelay; |
| 395 | }; |
| 396 | |
| 397 | TEST_F(LayerTransactionTest, SetPositionBasic) { |
| 398 | sp<SurfaceControl> layer; |
| 399 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 400 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 401 | |
| 402 | { |
| 403 | SCOPED_TRACE("default position"); |
| 404 | auto shot = screenshot(); |
| 405 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 406 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 407 | } |
| 408 | |
| 409 | Transaction().setPosition(layer, 5, 10).apply(); |
| 410 | { |
| 411 | SCOPED_TRACE("new position"); |
| 412 | auto shot = screenshot(); |
| 413 | shot->expectColor(Rect(5, 10, 37, 42), Color::RED); |
| 414 | shot->expectBorder(Rect(5, 10, 37, 42), Color::BLACK); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | TEST_F(LayerTransactionTest, SetPositionRounding) { |
| 419 | sp<SurfaceControl> layer; |
| 420 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 421 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 422 | |
| 423 | // GLES requires only 4 bits of subpixel precision during rasterization |
| 424 | // XXX GLES composition does not match HWC composition due to precision |
| 425 | // loss (b/69315223) |
| 426 | const float epsilon = 1.0f / 16.0f; |
| 427 | Transaction().setPosition(layer, 0.5f - epsilon, 0.5f - epsilon).apply(); |
| 428 | { |
| 429 | SCOPED_TRACE("rounding down"); |
| 430 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 431 | } |
| 432 | |
| 433 | Transaction().setPosition(layer, 0.5f + epsilon, 0.5f + epsilon).apply(); |
| 434 | { |
| 435 | SCOPED_TRACE("rounding up"); |
| 436 | screenshot()->expectColor(Rect(1, 1, 33, 33), Color::RED); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | TEST_F(LayerTransactionTest, SetPositionOutOfBounds) { |
| 441 | sp<SurfaceControl> layer; |
| 442 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 443 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 444 | |
| 445 | Transaction().setPosition(layer, -32, -32).apply(); |
| 446 | { |
| 447 | SCOPED_TRACE("negative coordinates"); |
| 448 | screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
| 449 | } |
| 450 | |
| 451 | Transaction().setPosition(layer, mDisplayWidth, mDisplayHeight).apply(); |
| 452 | { |
| 453 | SCOPED_TRACE("positive coordinates"); |
| 454 | screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | TEST_F(LayerTransactionTest, SetPositionPartiallyOutOfBounds) { |
| 459 | sp<SurfaceControl> layer; |
| 460 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 461 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 462 | |
| 463 | // partially out of bounds |
| 464 | Transaction().setPosition(layer, -30, -30).apply(); |
| 465 | { |
| 466 | SCOPED_TRACE("negative coordinates"); |
| 467 | screenshot()->expectColor(Rect(0, 0, 2, 2), Color::RED); |
| 468 | } |
| 469 | |
| 470 | Transaction().setPosition(layer, mDisplayWidth - 2, mDisplayHeight - 2).apply(); |
| 471 | { |
| 472 | SCOPED_TRACE("positive coordinates"); |
| 473 | screenshot()->expectColor(Rect(mDisplayWidth - 2, mDisplayHeight - 2, mDisplayWidth, |
| 474 | mDisplayHeight), |
| 475 | Color::RED); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | TEST_F(LayerTransactionTest, SetPositionWithResize) { |
| 480 | sp<SurfaceControl> layer; |
| 481 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 482 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 483 | |
| 484 | // setPosition is applied immediately by default, with or without resize |
| 485 | // pending |
| 486 | Transaction().setPosition(layer, 5, 10).setSize(layer, 64, 64).apply(); |
| 487 | { |
| 488 | SCOPED_TRACE("resize pending"); |
| 489 | auto shot = screenshot(); |
| 490 | shot->expectColor(Rect(5, 10, 37, 42), Color::RED); |
| 491 | shot->expectBorder(Rect(5, 10, 37, 42), Color::BLACK); |
| 492 | } |
| 493 | |
| 494 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 495 | { |
| 496 | SCOPED_TRACE("resize applied"); |
| 497 | screenshot()->expectColor(Rect(5, 10, 69, 74), Color::RED); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | TEST_F(LayerTransactionTest, SetPositionWithNextResize) { |
| 502 | sp<SurfaceControl> layer; |
| 503 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 504 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 505 | |
| 506 | // request setPosition to be applied with the next resize |
| 507 | Transaction().setPosition(layer, 5, 10).setGeometryAppliesWithResize(layer).apply(); |
| 508 | { |
| 509 | SCOPED_TRACE("new position pending"); |
| 510 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 511 | } |
| 512 | |
| 513 | Transaction().setPosition(layer, 15, 20).apply(); |
| 514 | { |
| 515 | SCOPED_TRACE("pending new position modified"); |
| 516 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 517 | } |
| 518 | |
| 519 | Transaction().setSize(layer, 64, 64).apply(); |
| 520 | { |
| 521 | SCOPED_TRACE("resize pending"); |
| 522 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 523 | } |
| 524 | |
| 525 | // finally resize and latch the buffer |
| 526 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 527 | { |
| 528 | SCOPED_TRACE("new position applied"); |
| 529 | screenshot()->expectColor(Rect(15, 20, 79, 84), Color::RED); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | TEST_F(LayerTransactionTest, SetPositionWithNextResizeScaleToWindow) { |
| 534 | sp<SurfaceControl> layer; |
| 535 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 536 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 537 | |
| 538 | // setPosition is not immediate even with SCALE_TO_WINDOW override |
| 539 | Transaction() |
| 540 | .setPosition(layer, 5, 10) |
| 541 | .setSize(layer, 64, 64) |
| 542 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 543 | .setGeometryAppliesWithResize(layer) |
| 544 | .apply(); |
| 545 | { |
| 546 | SCOPED_TRACE("new position pending"); |
| 547 | screenshot()->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 548 | } |
| 549 | |
| 550 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 551 | { |
| 552 | SCOPED_TRACE("new position applied"); |
| 553 | screenshot()->expectColor(Rect(5, 10, 69, 74), Color::RED); |
| 554 | } |
| 555 | } |
| 556 | |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 557 | TEST_F(LayerTransactionTest, SetSizeBasic) { |
| 558 | sp<SurfaceControl> layer; |
| 559 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 560 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 561 | |
| 562 | Transaction().setSize(layer, 64, 64).apply(); |
| 563 | { |
| 564 | SCOPED_TRACE("resize pending"); |
| 565 | auto shot = screenshot(); |
| 566 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 567 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 568 | } |
| 569 | |
| 570 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 571 | { |
| 572 | SCOPED_TRACE("resize applied"); |
| 573 | auto shot = screenshot(); |
| 574 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 575 | shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | TEST_F(LayerTransactionTest, SetSizeInvalid) { |
| 580 | // cannot test robustness against invalid sizes (zero or really huge) |
| 581 | } |
| 582 | |
| 583 | TEST_F(LayerTransactionTest, SetSizeWithScaleToWindow) { |
| 584 | sp<SurfaceControl> layer; |
| 585 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 586 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 587 | |
| 588 | // setSize is immediate with SCALE_TO_WINDOW, unlike setPosition |
| 589 | Transaction() |
| 590 | .setSize(layer, 64, 64) |
| 591 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 592 | .apply(); |
| 593 | screenshot()->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 594 | } |
| 595 | |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 596 | TEST_F(LayerTransactionTest, SetZBasic) { |
| 597 | sp<SurfaceControl> layerR; |
| 598 | sp<SurfaceControl> layerG; |
| 599 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 600 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED)); |
| 601 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
| 602 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN)); |
| 603 | |
| 604 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); |
| 605 | { |
| 606 | SCOPED_TRACE("layerR"); |
| 607 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 608 | } |
| 609 | |
| 610 | Transaction().setLayer(layerG, mLayerZBase + 2).apply(); |
| 611 | { |
| 612 | SCOPED_TRACE("layerG"); |
| 613 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::GREEN); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | TEST_F(LayerTransactionTest, SetZNegative) { |
| 618 | sp<SurfaceControl> layerR; |
| 619 | sp<SurfaceControl> layerG; |
| 620 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 621 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED)); |
| 622 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
| 623 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN)); |
| 624 | |
| 625 | Transaction().setLayer(layerR, -1).setLayer(layerG, -2).apply(); |
| 626 | { |
| 627 | SCOPED_TRACE("layerR"); |
| 628 | sp<ScreenCapture> screenshot; |
| 629 | ScreenCapture::captureScreen(&screenshot, -2, -1); |
| 630 | screenshot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 631 | } |
| 632 | |
| 633 | Transaction().setLayer(layerR, -3).apply(); |
| 634 | { |
| 635 | SCOPED_TRACE("layerG"); |
| 636 | sp<ScreenCapture> screenshot; |
| 637 | ScreenCapture::captureScreen(&screenshot, -3, -1); |
| 638 | screenshot->expectColor(Rect(0, 0, 32, 32), Color::GREEN); |
| 639 | } |
| 640 | } |
| 641 | |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 642 | TEST_F(LayerTransactionTest, SetRelativeZBasic) { |
| 643 | sp<SurfaceControl> layerR; |
| 644 | sp<SurfaceControl> layerG; |
| 645 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 646 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED)); |
| 647 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
| 648 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN)); |
| 649 | |
| 650 | Transaction() |
| 651 | .setPosition(layerG, 16, 16) |
| 652 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 653 | .apply(); |
| 654 | { |
| 655 | SCOPED_TRACE("layerG above"); |
| 656 | auto shot = screenshot(); |
| 657 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 658 | shot->expectColor(Rect(16, 16, 48, 48), Color::GREEN); |
| 659 | } |
| 660 | |
| 661 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).apply(); |
| 662 | { |
| 663 | SCOPED_TRACE("layerG below"); |
| 664 | auto shot = screenshot(); |
| 665 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 666 | shot->expectColor(Rect(32, 32, 48, 48), Color::GREEN); |
| 667 | } |
| 668 | } |
| 669 | |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 670 | TEST_F(LayerTransactionTest, SetRelativeZNegative) { |
| 671 | sp<SurfaceControl> layerR; |
| 672 | sp<SurfaceControl> layerG; |
| 673 | sp<SurfaceControl> layerB; |
| 674 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 675 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED)); |
| 676 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
| 677 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN)); |
| 678 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32)); |
| 679 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE)); |
| 680 | |
| 681 | // layerR = mLayerZBase, layerG = layerR - 1, layerB = -2 |
| 682 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).setLayer(layerB, -2).apply(); |
| 683 | |
| 684 | sp<ScreenCapture> screenshot; |
| 685 | // only layerB is in this range |
| 686 | ScreenCapture::captureScreen(&screenshot, -2, -1); |
| 687 | screenshot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 688 | } |
| 689 | |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 690 | TEST_F(LayerTransactionTest, SetRelativeZGroup) { |
| 691 | sp<SurfaceControl> layerR; |
| 692 | sp<SurfaceControl> layerG; |
| 693 | sp<SurfaceControl> layerB; |
| 694 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 695 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED)); |
| 696 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
| 697 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN)); |
| 698 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32)); |
| 699 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE)); |
| 700 | |
| 701 | // layerR = 0, layerG = layerR + 3, layerB = 2 |
| 702 | Transaction() |
| 703 | .setPosition(layerG, 8, 8) |
| 704 | .setRelativeLayer(layerG, layerR->getHandle(), 3) |
| 705 | .setPosition(layerB, 16, 16) |
| 706 | .setLayer(layerB, mLayerZBase + 2) |
| 707 | .apply(); |
| 708 | { |
| 709 | SCOPED_TRACE("(layerR < layerG) < layerB"); |
| 710 | auto shot = screenshot(); |
| 711 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); |
| 712 | shot->expectColor(Rect(8, 8, 16, 16), Color::GREEN); |
| 713 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); |
| 714 | } |
| 715 | |
| 716 | // layerR = 4, layerG = layerR + 3, layerB = 2 |
| 717 | Transaction().setLayer(layerR, mLayerZBase + 4).apply(); |
| 718 | { |
| 719 | SCOPED_TRACE("layerB < (layerR < layerG)"); |
| 720 | auto shot = screenshot(); |
| 721 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); |
| 722 | shot->expectColor(Rect(8, 8, 40, 40), Color::GREEN); |
| 723 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); |
| 724 | } |
| 725 | |
| 726 | // layerR = 4, layerG = layerR - 3, layerB = 2 |
| 727 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -3).apply(); |
| 728 | { |
| 729 | SCOPED_TRACE("layerB < (layerG < layerR)"); |
| 730 | auto shot = screenshot(); |
| 731 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 732 | shot->expectColor(Rect(32, 32, 40, 40), Color::GREEN); |
| 733 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); |
| 734 | } |
| 735 | |
| 736 | // restore to absolute z |
| 737 | // layerR = 4, layerG = 0, layerB = 2 |
| 738 | Transaction().setLayer(layerG, mLayerZBase).apply(); |
| 739 | { |
| 740 | SCOPED_TRACE("layerG < layerB < layerR"); |
| 741 | auto shot = screenshot(); |
| 742 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 743 | shot->expectColor(Rect(32, 32, 48, 48), Color::BLUE); |
| 744 | } |
| 745 | |
| 746 | // layerR should not affect layerG anymore |
| 747 | // layerR = 1, layerG = 0, layerB = 2 |
| 748 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); |
| 749 | { |
| 750 | SCOPED_TRACE("layerG < layerR < layerB"); |
| 751 | auto shot = screenshot(); |
| 752 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 753 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | TEST_F(LayerTransactionTest, SetRelativeZBug64572777) { |
| 758 | sp<SurfaceControl> layerR; |
| 759 | sp<SurfaceControl> layerG; |
| 760 | |
| 761 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 762 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED)); |
| 763 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
| 764 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN)); |
| 765 | |
| 766 | Transaction() |
| 767 | .setPosition(layerG, 16, 16) |
| 768 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 769 | .apply(); |
| 770 | |
| 771 | mClient->destroySurface(layerG->getHandle()); |
| 772 | // layerG should have been removed |
| 773 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 774 | } |
| 775 | |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 776 | TEST_F(LayerTransactionTest, SetFlagsHidden) { |
| 777 | sp<SurfaceControl> layer; |
| 778 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 779 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 780 | |
| 781 | Transaction().setFlags(layer, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden).apply(); |
| 782 | { |
| 783 | SCOPED_TRACE("layer hidden"); |
| 784 | screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
| 785 | } |
| 786 | |
| 787 | Transaction().setFlags(layer, 0, layer_state_t::eLayerHidden).apply(); |
| 788 | { |
| 789 | SCOPED_TRACE("layer shown"); |
| 790 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | TEST_F(LayerTransactionTest, SetFlagsOpaque) { |
| 795 | const Color translucentRed = {100, 0, 0, 100}; |
| 796 | sp<SurfaceControl> layerR; |
| 797 | sp<SurfaceControl> layerG; |
| 798 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 799 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, translucentRed)); |
| 800 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
| 801 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN)); |
| 802 | |
| 803 | Transaction() |
| 804 | .setLayer(layerR, mLayerZBase + 1) |
| 805 | .setFlags(layerR, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque) |
| 806 | .apply(); |
| 807 | { |
| 808 | SCOPED_TRACE("layerR opaque"); |
| 809 | screenshot()->expectColor(Rect(0, 0, 32, 32), {100, 0, 0, 255}); |
| 810 | } |
| 811 | |
| 812 | Transaction().setFlags(layerR, 0, layer_state_t::eLayerOpaque).apply(); |
| 813 | { |
| 814 | SCOPED_TRACE("layerR translucent"); |
| 815 | const uint8_t g = uint8_t(255 - translucentRed.a); |
| 816 | screenshot()->expectColor(Rect(0, 0, 32, 32), {100, g, 0, 255}); |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | TEST_F(LayerTransactionTest, SetFlagsSecure) { |
| 821 | sp<SurfaceControl> layer; |
| 822 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 823 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 824 | |
| 825 | sp<ISurfaceComposer> composer = ComposerService::getComposerService(); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 826 | sp<GraphicBuffer> outBuffer; |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 827 | Transaction() |
| 828 | .setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure) |
| 829 | .apply(true); |
| 830 | ASSERT_EQ(PERMISSION_DENIED, |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 831 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, mLayerZBase, mLayerZBase, |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 832 | false)); |
| 833 | |
| 834 | Transaction().setFlags(layer, 0, layer_state_t::eLayerSecure).apply(true); |
| 835 | ASSERT_EQ(NO_ERROR, |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 836 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, mLayerZBase, mLayerZBase, |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 837 | false)); |
| 838 | } |
| 839 | |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 840 | TEST_F(LayerTransactionTest, SetTransparentRegionHintBasic) { |
| 841 | const Rect top(0, 0, 32, 16); |
| 842 | const Rect bottom(0, 16, 32, 32); |
| 843 | sp<SurfaceControl> layer; |
| 844 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 845 | |
| 846 | ANativeWindow_Buffer buffer; |
| 847 | ASSERT_NO_FATAL_FAILURE(buffer = getLayerBuffer(layer)); |
| 848 | ASSERT_NO_FATAL_FAILURE(fillBufferColor(buffer, top, Color::TRANSPARENT)); |
| 849 | ASSERT_NO_FATAL_FAILURE(fillBufferColor(buffer, bottom, Color::RED)); |
| 850 | // setTransparentRegionHint always applies to the following buffer |
| 851 | Transaction().setTransparentRegionHint(layer, Region(top)).apply(); |
| 852 | ASSERT_NO_FATAL_FAILURE(postLayerBuffer(layer)); |
| 853 | { |
| 854 | SCOPED_TRACE("top transparent"); |
| 855 | auto shot = screenshot(); |
| 856 | shot->expectColor(top, Color::BLACK); |
| 857 | shot->expectColor(bottom, Color::RED); |
| 858 | } |
| 859 | |
| 860 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); |
| 861 | { |
| 862 | SCOPED_TRACE("transparent region hint pending"); |
| 863 | auto shot = screenshot(); |
| 864 | shot->expectColor(top, Color::BLACK); |
| 865 | shot->expectColor(bottom, Color::RED); |
| 866 | } |
| 867 | |
| 868 | ASSERT_NO_FATAL_FAILURE(buffer = getLayerBuffer(layer)); |
| 869 | ASSERT_NO_FATAL_FAILURE(fillBufferColor(buffer, top, Color::RED)); |
| 870 | ASSERT_NO_FATAL_FAILURE(fillBufferColor(buffer, bottom, Color::TRANSPARENT)); |
| 871 | ASSERT_NO_FATAL_FAILURE(postLayerBuffer(layer)); |
| 872 | { |
| 873 | SCOPED_TRACE("bottom transparent"); |
| 874 | auto shot = screenshot(); |
| 875 | shot->expectColor(top, Color::RED); |
| 876 | shot->expectColor(bottom, Color::BLACK); |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | TEST_F(LayerTransactionTest, SetTransparentRegionHintOutOfBounds) { |
| 881 | sp<SurfaceControl> layerTransparent; |
| 882 | sp<SurfaceControl> layerR; |
| 883 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); |
| 884 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 885 | |
| 886 | // check that transparent region hint is bound by the layer size |
| 887 | Transaction() |
| 888 | .setTransparentRegionHint(layerTransparent, |
| 889 | Region(Rect(0, 0, mDisplayWidth, mDisplayHeight))) |
| 890 | .setPosition(layerR, 16, 16) |
| 891 | .setLayer(layerR, mLayerZBase + 1) |
| 892 | .apply(); |
| 893 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerTransparent, Color::TRANSPARENT)); |
| 894 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED)); |
| 895 | screenshot()->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 896 | } |
| 897 | |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 898 | TEST_F(LayerTransactionTest, SetAlphaBasic) { |
| 899 | sp<SurfaceControl> layer1; |
| 900 | sp<SurfaceControl> layer2; |
| 901 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer("test 1", 32, 32)); |
| 902 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer("test 2", 32, 32)); |
| 903 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer1, {64, 0, 0, 255})); |
| 904 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer2, {0, 64, 0, 255})); |
| 905 | |
| 906 | Transaction() |
| 907 | .setAlpha(layer1, 0.25f) |
| 908 | .setAlpha(layer2, 0.75f) |
| 909 | .setPosition(layer2, 16, 0) |
| 910 | .setLayer(layer2, mLayerZBase + 1) |
| 911 | .apply(); |
| 912 | { |
| 913 | auto shot = screenshot(); |
| 914 | uint8_t r = 16; // 64 * 0.25f |
| 915 | uint8_t g = 48; // 64 * 0.75f |
| 916 | shot->expectColor(Rect(0, 0, 16, 32), {r, 0, 0, 255}); |
| 917 | shot->expectColor(Rect(32, 0, 48, 32), {0, g, 0, 255}); |
| 918 | |
| 919 | r /= 4; // r * (1.0f - 0.75f) |
| 920 | shot->expectColor(Rect(16, 0, 32, 32), {r, g, 0, 255}); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | TEST_F(LayerTransactionTest, SetAlphaClamped) { |
| 925 | const Color color = {64, 0, 0, 255}; |
| 926 | sp<SurfaceControl> layer; |
| 927 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 928 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, color)); |
| 929 | |
| 930 | Transaction().setAlpha(layer, 2.0f).apply(); |
| 931 | { |
| 932 | SCOPED_TRACE("clamped to 1.0f"); |
| 933 | screenshot()->expectColor(Rect(0, 0, 32, 32), color); |
| 934 | } |
| 935 | |
| 936 | Transaction().setAlpha(layer, -1.0f).apply(); |
| 937 | { |
| 938 | SCOPED_TRACE("clamped to 0.0f"); |
| 939 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
| 940 | } |
| 941 | } |
| 942 | |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 943 | TEST_F(LayerTransactionTest, SetColorBasic) { |
| 944 | sp<SurfaceControl> bufferLayer; |
| 945 | sp<SurfaceControl> colorLayer; |
| 946 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
| 947 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED)); |
| 948 | ASSERT_NO_FATAL_FAILURE( |
| 949 | colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor)); |
| 950 | |
| 951 | Transaction().setLayer(colorLayer, mLayerZBase + 1).apply(); |
| 952 | { |
| 953 | SCOPED_TRACE("default color"); |
| 954 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
| 955 | } |
| 956 | |
| 957 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 958 | const Color expected = {15, 51, 85, 255}; |
| 959 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 960 | // channel) should be less than one |
| 961 | const uint8_t tolerance = 1; |
| 962 | Transaction().setColor(colorLayer, color).apply(); |
| 963 | { |
| 964 | SCOPED_TRACE("new color"); |
| 965 | screenshot()->expectColor(Rect(0, 0, 32, 32), expected, tolerance); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | TEST_F(LayerTransactionTest, SetColorClamped) { |
| 970 | sp<SurfaceControl> colorLayer; |
| 971 | ASSERT_NO_FATAL_FAILURE( |
| 972 | colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor)); |
| 973 | |
| 974 | Transaction().setColor(colorLayer, half3(2.0f, -1.0f, 0.0f)).apply(); |
| 975 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 976 | } |
| 977 | |
| 978 | TEST_F(LayerTransactionTest, SetColorWithAlpha) { |
| 979 | sp<SurfaceControl> bufferLayer; |
| 980 | sp<SurfaceControl> colorLayer; |
| 981 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
| 982 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED)); |
| 983 | ASSERT_NO_FATAL_FAILURE( |
| 984 | colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor)); |
| 985 | |
| 986 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 987 | const float alpha = 0.25f; |
| 988 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); |
| 989 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 990 | // channel) should be less than one |
| 991 | const uint8_t tolerance = 1; |
| 992 | Transaction() |
| 993 | .setColor(colorLayer, color) |
| 994 | .setAlpha(colorLayer, alpha) |
| 995 | .setLayer(colorLayer, mLayerZBase + 1) |
| 996 | .apply(); |
| 997 | screenshot()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, |
| 998 | tolerance); |
| 999 | } |
| 1000 | |
| 1001 | TEST_F(LayerTransactionTest, SetColorWithBuffer) { |
| 1002 | sp<SurfaceControl> bufferLayer; |
| 1003 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test", 32, 32)); |
| 1004 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED)); |
| 1005 | |
| 1006 | // color is ignored |
| 1007 | Transaction().setColor(bufferLayer, half3(0.0f, 1.0f, 0.0f)).apply(); |
| 1008 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1009 | } |
| 1010 | |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1011 | TEST_F(LayerTransactionTest, SetLayerStackBasic) { |
| 1012 | sp<SurfaceControl> layer; |
| 1013 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1014 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1015 | |
| 1016 | Transaction().setLayerStack(layer, mDisplayLayerStack + 1).apply(); |
| 1017 | { |
| 1018 | SCOPED_TRACE("non-existing layer stack"); |
| 1019 | screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
| 1020 | } |
| 1021 | |
| 1022 | Transaction().setLayerStack(layer, mDisplayLayerStack).apply(); |
| 1023 | { |
| 1024 | SCOPED_TRACE("original layer stack"); |
| 1025 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1026 | } |
| 1027 | } |
| 1028 | |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1029 | TEST_F(LayerTransactionTest, SetMatrixBasic) { |
| 1030 | sp<SurfaceControl> layer; |
| 1031 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1032 | ASSERT_NO_FATAL_FAILURE( |
| 1033 | fillLayerQuadrant(layer, Color::RED, Color::GREEN, Color::BLUE, Color::WHITE)); |
| 1034 | |
| 1035 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 0, 0).apply(); |
| 1036 | { |
| 1037 | SCOPED_TRACE("IDENTITY"); |
| 1038 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, Color::BLUE, |
| 1039 | Color::WHITE); |
| 1040 | } |
| 1041 | |
| 1042 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 32, 0).apply(); |
| 1043 | { |
| 1044 | SCOPED_TRACE("FLIP_H"); |
| 1045 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE, |
| 1046 | Color::BLUE); |
| 1047 | } |
| 1048 | |
| 1049 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).setPosition(layer, 0, 32).apply(); |
| 1050 | { |
| 1051 | SCOPED_TRACE("FLIP_V"); |
| 1052 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED, |
| 1053 | Color::GREEN); |
| 1054 | } |
| 1055 | |
| 1056 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).setPosition(layer, 32, 0).apply(); |
| 1057 | { |
| 1058 | SCOPED_TRACE("ROT_90"); |
| 1059 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE, |
| 1060 | Color::GREEN); |
| 1061 | } |
| 1062 | |
| 1063 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setPosition(layer, 0, 0).apply(); |
| 1064 | { |
| 1065 | SCOPED_TRACE("SCALE"); |
| 1066 | screenshot()->expectQuadrant(Rect(0, 0, 64, 64), Color::RED, Color::GREEN, Color::BLUE, |
| 1067 | Color::WHITE, true /* filtered */); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | TEST_F(LayerTransactionTest, SetMatrixRot45) { |
| 1072 | sp<SurfaceControl> layer; |
| 1073 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1074 | ASSERT_NO_FATAL_FAILURE( |
| 1075 | fillLayerQuadrant(layer, Color::RED, Color::GREEN, Color::BLUE, Color::WHITE)); |
| 1076 | |
| 1077 | const float rot = M_SQRT1_2; // 45 degrees |
| 1078 | const float trans = M_SQRT2 * 16.0f; |
| 1079 | Transaction().setMatrix(layer, rot, rot, -rot, rot).setPosition(layer, trans, 0).apply(); |
| 1080 | |
| 1081 | auto shot = screenshot(); |
| 1082 | // check a 8x8 region inside each color |
| 1083 | auto get8x8Rect = [](int32_t centerX, int32_t centerY) { |
| 1084 | const int32_t halfL = 4; |
| 1085 | return Rect(centerX - halfL, centerY - halfL, centerX + halfL, centerY + halfL); |
| 1086 | }; |
| 1087 | const int32_t unit = int32_t(trans / 2); |
| 1088 | shot->expectColor(get8x8Rect(2 * unit, 1 * unit), Color::RED); |
| 1089 | shot->expectColor(get8x8Rect(3 * unit, 2 * unit), Color::GREEN); |
| 1090 | shot->expectColor(get8x8Rect(1 * unit, 2 * unit), Color::BLUE); |
| 1091 | shot->expectColor(get8x8Rect(2 * unit, 3 * unit), Color::WHITE); |
| 1092 | } |
| 1093 | |
| 1094 | TEST_F(LayerTransactionTest, SetMatrixWithResize) { |
| 1095 | sp<SurfaceControl> layer; |
| 1096 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1097 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1098 | |
| 1099 | // setMatrix is applied after any pending resize, unlike setPosition |
| 1100 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setSize(layer, 64, 64).apply(); |
| 1101 | { |
| 1102 | SCOPED_TRACE("resize pending"); |
| 1103 | auto shot = screenshot(); |
| 1104 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1105 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1106 | } |
| 1107 | |
| 1108 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1109 | { |
| 1110 | SCOPED_TRACE("resize applied"); |
| 1111 | screenshot()->expectColor(Rect(0, 0, 128, 128), Color::RED); |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | TEST_F(LayerTransactionTest, SetMatrixWithScaleToWindow) { |
| 1116 | sp<SurfaceControl> layer; |
| 1117 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1118 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1119 | |
| 1120 | // setMatrix is immediate with SCALE_TO_WINDOW, unlike setPosition |
| 1121 | Transaction() |
| 1122 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
| 1123 | .setSize(layer, 64, 64) |
| 1124 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1125 | .apply(); |
| 1126 | screenshot()->expectColor(Rect(0, 0, 128, 128), Color::RED); |
| 1127 | } |
| 1128 | |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1129 | TEST_F(LayerTransactionTest, SetOverrideScalingModeBasic) { |
| 1130 | sp<SurfaceControl> layer; |
| 1131 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1132 | ASSERT_NO_FATAL_FAILURE( |
| 1133 | fillLayerQuadrant(layer, Color::RED, Color::GREEN, Color::BLUE, Color::WHITE)); |
| 1134 | |
| 1135 | // XXX SCALE_CROP is not respected; calling setSize and |
| 1136 | // setOverrideScalingMode in separate transactions does not work |
| 1137 | // (b/69315456) |
| 1138 | Transaction() |
| 1139 | .setSize(layer, 64, 16) |
| 1140 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1141 | .apply(); |
| 1142 | { |
| 1143 | SCOPED_TRACE("SCALE_TO_WINDOW"); |
| 1144 | screenshot()->expectQuadrant(Rect(0, 0, 64, 16), Color::RED, Color::GREEN, Color::BLUE, |
| 1145 | Color::WHITE, true /* filtered */); |
| 1146 | } |
| 1147 | } |
| 1148 | |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1149 | TEST_F(LayerTransactionTest, SetCropBasic) { |
| 1150 | sp<SurfaceControl> layer; |
| 1151 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1152 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1153 | const Rect crop(8, 8, 24, 24); |
| 1154 | |
| 1155 | Transaction().setCrop(layer, crop).apply(); |
| 1156 | auto shot = screenshot(); |
| 1157 | shot->expectColor(crop, Color::RED); |
| 1158 | shot->expectBorder(crop, Color::BLACK); |
| 1159 | } |
| 1160 | |
| 1161 | TEST_F(LayerTransactionTest, SetCropEmpty) { |
| 1162 | sp<SurfaceControl> layer; |
| 1163 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1164 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1165 | |
| 1166 | { |
| 1167 | SCOPED_TRACE("empty rect"); |
| 1168 | Transaction().setCrop(layer, Rect(8, 8, 8, 8)).apply(); |
| 1169 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1170 | } |
| 1171 | |
| 1172 | { |
| 1173 | SCOPED_TRACE("negative rect"); |
| 1174 | Transaction().setCrop(layer, Rect(8, 8, 0, 0)).apply(); |
| 1175 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | TEST_F(LayerTransactionTest, SetCropOutOfBounds) { |
| 1180 | sp<SurfaceControl> layer; |
| 1181 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1182 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1183 | |
| 1184 | Transaction().setCrop(layer, Rect(-128, -64, 128, 64)).apply(); |
| 1185 | auto shot = screenshot(); |
| 1186 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1187 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1188 | } |
| 1189 | |
| 1190 | TEST_F(LayerTransactionTest, SetCropWithTranslation) { |
| 1191 | sp<SurfaceControl> layer; |
| 1192 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1193 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1194 | |
| 1195 | const Point position(32, 32); |
| 1196 | const Rect crop(8, 8, 24, 24); |
| 1197 | Transaction().setPosition(layer, position.x, position.y).setCrop(layer, crop).apply(); |
| 1198 | auto shot = screenshot(); |
| 1199 | shot->expectColor(crop + position, Color::RED); |
| 1200 | shot->expectBorder(crop + position, Color::BLACK); |
| 1201 | } |
| 1202 | |
| 1203 | TEST_F(LayerTransactionTest, SetCropWithScale) { |
| 1204 | sp<SurfaceControl> layer; |
| 1205 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1206 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1207 | |
| 1208 | // crop is affected by matrix |
| 1209 | Transaction() |
| 1210 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
| 1211 | .setCrop(layer, Rect(8, 8, 24, 24)) |
| 1212 | .apply(); |
| 1213 | auto shot = screenshot(); |
| 1214 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 1215 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); |
| 1216 | } |
| 1217 | |
| 1218 | TEST_F(LayerTransactionTest, SetCropWithResize) { |
| 1219 | sp<SurfaceControl> layer; |
| 1220 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1221 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1222 | |
| 1223 | // setCrop is applied immediately by default, with or without resize pending |
| 1224 | Transaction().setCrop(layer, Rect(8, 8, 24, 24)).setSize(layer, 16, 16).apply(); |
| 1225 | { |
| 1226 | SCOPED_TRACE("resize pending"); |
| 1227 | auto shot = screenshot(); |
| 1228 | shot->expectColor(Rect(8, 8, 24, 24), Color::RED); |
| 1229 | shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK); |
| 1230 | } |
| 1231 | |
| 1232 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1233 | { |
| 1234 | SCOPED_TRACE("resize applied"); |
| 1235 | auto shot = screenshot(); |
| 1236 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 1237 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | TEST_F(LayerTransactionTest, SetCropWithNextResize) { |
| 1242 | sp<SurfaceControl> layer; |
| 1243 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1244 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1245 | |
| 1246 | // request setCrop to be applied with the next resize |
| 1247 | Transaction().setCrop(layer, Rect(8, 8, 24, 24)).setGeometryAppliesWithResize(layer).apply(); |
| 1248 | { |
| 1249 | SCOPED_TRACE("waiting for next resize"); |
| 1250 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1251 | } |
| 1252 | |
| 1253 | Transaction().setCrop(layer, Rect(4, 4, 12, 12)).apply(); |
| 1254 | { |
| 1255 | SCOPED_TRACE("pending crop modified"); |
| 1256 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1257 | } |
| 1258 | |
| 1259 | Transaction().setSize(layer, 16, 16).apply(); |
| 1260 | { |
| 1261 | SCOPED_TRACE("resize pending"); |
| 1262 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1263 | } |
| 1264 | |
| 1265 | // finally resize |
| 1266 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1267 | { |
| 1268 | SCOPED_TRACE("new crop applied"); |
| 1269 | auto shot = screenshot(); |
| 1270 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1271 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | TEST_F(LayerTransactionTest, SetCropWithNextResizeScaleToWindow) { |
| 1276 | sp<SurfaceControl> layer; |
| 1277 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1278 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1279 | |
| 1280 | // setCrop is not immediate even with SCALE_TO_WINDOW override |
| 1281 | Transaction() |
| 1282 | .setCrop(layer, Rect(4, 4, 12, 12)) |
| 1283 | .setSize(layer, 16, 16) |
| 1284 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1285 | .setGeometryAppliesWithResize(layer) |
| 1286 | .apply(); |
| 1287 | { |
| 1288 | SCOPED_TRACE("new crop pending"); |
| 1289 | auto shot = screenshot(); |
| 1290 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 1291 | shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK); |
| 1292 | } |
| 1293 | |
| 1294 | // XXX crop is never latched without other geometry change (b/69315677) |
| 1295 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); |
| 1296 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1297 | Transaction().setPosition(layer, 0, 0).apply(); |
| 1298 | { |
| 1299 | SCOPED_TRACE("new crop applied"); |
| 1300 | auto shot = screenshot(); |
| 1301 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1302 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1303 | } |
| 1304 | } |
| 1305 | |
Chia-I Wu | cdd71a5 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1306 | TEST_F(LayerTransactionTest, SetFinalCropBasic) { |
| 1307 | sp<SurfaceControl> layer; |
| 1308 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1309 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1310 | const Rect crop(8, 8, 24, 24); |
| 1311 | |
| 1312 | // same as in SetCropBasic |
| 1313 | Transaction().setFinalCrop(layer, crop).apply(); |
| 1314 | auto shot = screenshot(); |
| 1315 | shot->expectColor(crop, Color::RED); |
| 1316 | shot->expectBorder(crop, Color::BLACK); |
| 1317 | } |
| 1318 | |
| 1319 | TEST_F(LayerTransactionTest, SetFinalCropEmpty) { |
| 1320 | sp<SurfaceControl> layer; |
| 1321 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1322 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1323 | |
| 1324 | // same as in SetCropEmpty |
| 1325 | { |
| 1326 | SCOPED_TRACE("empty rect"); |
| 1327 | Transaction().setFinalCrop(layer, Rect(8, 8, 8, 8)).apply(); |
| 1328 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1329 | } |
| 1330 | |
| 1331 | { |
| 1332 | SCOPED_TRACE("negative rect"); |
| 1333 | Transaction().setFinalCrop(layer, Rect(8, 8, 0, 0)).apply(); |
| 1334 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | TEST_F(LayerTransactionTest, SetFinalCropOutOfBounds) { |
| 1339 | sp<SurfaceControl> layer; |
| 1340 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1341 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1342 | |
| 1343 | // same as in SetCropOutOfBounds |
| 1344 | Transaction().setFinalCrop(layer, Rect(-128, -64, 128, 64)).apply(); |
| 1345 | auto shot = screenshot(); |
| 1346 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1347 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1348 | } |
| 1349 | |
| 1350 | TEST_F(LayerTransactionTest, SetFinalCropWithTranslation) { |
| 1351 | sp<SurfaceControl> layer; |
| 1352 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1353 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1354 | |
| 1355 | // final crop is applied post-translation |
| 1356 | Transaction().setPosition(layer, 16, 16).setFinalCrop(layer, Rect(8, 8, 24, 24)).apply(); |
| 1357 | auto shot = screenshot(); |
| 1358 | shot->expectColor(Rect(16, 16, 24, 24), Color::RED); |
| 1359 | shot->expectBorder(Rect(16, 16, 24, 24), Color::BLACK); |
| 1360 | } |
| 1361 | |
| 1362 | TEST_F(LayerTransactionTest, SetFinalCropWithScale) { |
| 1363 | sp<SurfaceControl> layer; |
| 1364 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1365 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1366 | |
| 1367 | // final crop is not affected by matrix |
| 1368 | Transaction() |
| 1369 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
| 1370 | .setFinalCrop(layer, Rect(8, 8, 24, 24)) |
| 1371 | .apply(); |
| 1372 | auto shot = screenshot(); |
| 1373 | shot->expectColor(Rect(8, 8, 24, 24), Color::RED); |
| 1374 | shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK); |
| 1375 | } |
| 1376 | |
| 1377 | TEST_F(LayerTransactionTest, SetFinalCropWithResize) { |
| 1378 | sp<SurfaceControl> layer; |
| 1379 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1380 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1381 | |
| 1382 | // same as in SetCropWithResize |
| 1383 | Transaction().setFinalCrop(layer, Rect(8, 8, 24, 24)).setSize(layer, 16, 16).apply(); |
| 1384 | { |
| 1385 | SCOPED_TRACE("resize pending"); |
| 1386 | auto shot = screenshot(); |
| 1387 | shot->expectColor(Rect(8, 8, 24, 24), Color::RED); |
| 1388 | shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK); |
| 1389 | } |
| 1390 | |
| 1391 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1392 | { |
| 1393 | SCOPED_TRACE("resize applied"); |
| 1394 | auto shot = screenshot(); |
| 1395 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 1396 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | TEST_F(LayerTransactionTest, SetFinalCropWithNextResize) { |
| 1401 | sp<SurfaceControl> layer; |
| 1402 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1403 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1404 | |
| 1405 | // same as in SetCropWithNextResize |
| 1406 | Transaction() |
| 1407 | .setFinalCrop(layer, Rect(8, 8, 24, 24)) |
| 1408 | .setGeometryAppliesWithResize(layer) |
| 1409 | .apply(); |
| 1410 | { |
| 1411 | SCOPED_TRACE("waiting for next resize"); |
| 1412 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1413 | } |
| 1414 | |
| 1415 | Transaction().setFinalCrop(layer, Rect(4, 4, 12, 12)).apply(); |
| 1416 | { |
| 1417 | SCOPED_TRACE("pending final crop modified"); |
| 1418 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1419 | } |
| 1420 | |
| 1421 | Transaction().setSize(layer, 16, 16).apply(); |
| 1422 | { |
| 1423 | SCOPED_TRACE("resize pending"); |
| 1424 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1425 | } |
| 1426 | |
| 1427 | // finally resize |
| 1428 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1429 | { |
| 1430 | SCOPED_TRACE("new final crop applied"); |
| 1431 | auto shot = screenshot(); |
| 1432 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1433 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1434 | } |
| 1435 | } |
| 1436 | |
| 1437 | TEST_F(LayerTransactionTest, SetFinalCropWithNextResizeScaleToWindow) { |
| 1438 | sp<SurfaceControl> layer; |
| 1439 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1440 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1441 | |
| 1442 | // same as in SetCropWithNextResizeScaleToWindow |
| 1443 | Transaction() |
| 1444 | .setFinalCrop(layer, Rect(4, 4, 12, 12)) |
| 1445 | .setSize(layer, 16, 16) |
| 1446 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1447 | .setGeometryAppliesWithResize(layer) |
| 1448 | .apply(); |
| 1449 | { |
| 1450 | SCOPED_TRACE("new final crop pending"); |
| 1451 | auto shot = screenshot(); |
| 1452 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 1453 | shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK); |
| 1454 | } |
| 1455 | |
| 1456 | // XXX final crop is never latched without other geometry change (b/69315677) |
| 1457 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); |
| 1458 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED)); |
| 1459 | Transaction().setPosition(layer, 0, 0).apply(); |
| 1460 | { |
| 1461 | SCOPED_TRACE("new final crop applied"); |
| 1462 | auto shot = screenshot(); |
| 1463 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1464 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1465 | } |
| 1466 | } |
| 1467 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 1468 | class LayerUpdateTest : public LayerTransactionTest { |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1469 | protected: |
| 1470 | virtual void SetUp() { |
| 1471 | mComposerClient = new SurfaceComposerClient; |
| 1472 | ASSERT_EQ(NO_ERROR, mComposerClient->initCheck()); |
| 1473 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1474 | sp<IBinder> display( |
| 1475 | SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1476 | DisplayInfo info; |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 1477 | SurfaceComposerClient::getDisplayInfo(display, &info); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 1478 | |
| 1479 | ssize_t displayWidth = info.w; |
| 1480 | ssize_t displayHeight = info.h; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1481 | |
| 1482 | // Background surface |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1483 | mBGSurfaceControl = |
| 1484 | mComposerClient->createSurface(String8("BG Test Surface"), displayWidth, |
| 1485 | displayHeight, PIXEL_FORMAT_RGBA_8888, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1486 | ASSERT_TRUE(mBGSurfaceControl != NULL); |
| 1487 | ASSERT_TRUE(mBGSurfaceControl->isValid()); |
| 1488 | fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195); |
| 1489 | |
| 1490 | // Foreground surface |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1491 | mFGSurfaceControl = mComposerClient->createSurface(String8("FG Test Surface"), 64, 64, |
| 1492 | PIXEL_FORMAT_RGBA_8888, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1493 | ASSERT_TRUE(mFGSurfaceControl != NULL); |
| 1494 | ASSERT_TRUE(mFGSurfaceControl->isValid()); |
| 1495 | |
| 1496 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 1497 | |
| 1498 | // Synchronization surface |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1499 | mSyncSurfaceControl = mComposerClient->createSurface(String8("Sync Test Surface"), 1, 1, |
| 1500 | PIXEL_FORMAT_RGBA_8888, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1501 | ASSERT_TRUE(mSyncSurfaceControl != NULL); |
| 1502 | ASSERT_TRUE(mSyncSurfaceControl->isValid()); |
| 1503 | |
| 1504 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 1505 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1506 | asTransaction([&](Transaction& t) { |
| 1507 | t.setDisplayLayerStack(display, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1508 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1509 | t.setLayer(mBGSurfaceControl, INT32_MAX - 2).show(mBGSurfaceControl); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 1510 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1511 | t.setLayer(mFGSurfaceControl, INT32_MAX - 1) |
| 1512 | .setPosition(mFGSurfaceControl, 64, 64) |
| 1513 | .show(mFGSurfaceControl); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1514 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1515 | t.setLayer(mSyncSurfaceControl, INT32_MAX - 1) |
| 1516 | .setPosition(mSyncSurfaceControl, displayWidth - 2, displayHeight - 2) |
| 1517 | .show(mSyncSurfaceControl); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1518 | }); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | virtual void TearDown() { |
| 1522 | mComposerClient->dispose(); |
| 1523 | mBGSurfaceControl = 0; |
| 1524 | mFGSurfaceControl = 0; |
| 1525 | mSyncSurfaceControl = 0; |
| 1526 | mComposerClient = 0; |
| 1527 | } |
| 1528 | |
| 1529 | void waitForPostedBuffers() { |
| 1530 | // Since the sync surface is in synchronous mode (i.e. double buffered) |
| 1531 | // posting three buffers to it should ensure that at least two |
| 1532 | // SurfaceFlinger::handlePageFlip calls have been made, which should |
| 1533 | // guaranteed that a buffer posted to another Surface has been retired. |
| 1534 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 1535 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 1536 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 1537 | } |
| 1538 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1539 | void asTransaction(const std::function<void(Transaction&)>& exec) { |
| 1540 | Transaction t; |
| 1541 | exec(t); |
| 1542 | t.apply(true); |
| 1543 | } |
| 1544 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1545 | sp<SurfaceComposerClient> mComposerClient; |
| 1546 | sp<SurfaceControl> mBGSurfaceControl; |
| 1547 | sp<SurfaceControl> mFGSurfaceControl; |
| 1548 | |
| 1549 | // This surface is used to ensure that the buffers posted to |
| 1550 | // mFGSurfaceControl have been picked up by SurfaceFlinger. |
| 1551 | sp<SurfaceControl> mSyncSurfaceControl; |
| 1552 | }; |
| 1553 | |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 1554 | TEST_F(LayerUpdateTest, RelativesAreNotDetached) { |
| 1555 | sp<ScreenCapture> sc; |
| 1556 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1557 | sp<SurfaceControl> relative = mComposerClient->createSurface(String8("relativeTestSurface"), 10, |
| 1558 | 10, PIXEL_FORMAT_RGBA_8888, 0); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 1559 | fillSurfaceRGBA8(relative, 10, 10, 10); |
| 1560 | waitForPostedBuffers(); |
| 1561 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1562 | Transaction{} |
| 1563 | .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1) |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 1564 | .setPosition(relative, 64, 64) |
| 1565 | .apply(); |
| 1566 | |
| 1567 | { |
| 1568 | // The relative should be on top of the FG control. |
| 1569 | ScreenCapture::captureScreen(&sc); |
| 1570 | sc->checkPixel(64, 64, 10, 10, 10); |
| 1571 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1572 | Transaction{}.detachChildren(mFGSurfaceControl).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 1573 | |
| 1574 | { |
| 1575 | // Nothing should change at this point. |
| 1576 | ScreenCapture::captureScreen(&sc); |
| 1577 | sc->checkPixel(64, 64, 10, 10, 10); |
| 1578 | } |
| 1579 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1580 | Transaction{}.hide(relative).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 1581 | |
| 1582 | { |
| 1583 | // Ensure that the relative was actually hidden, rather than |
| 1584 | // being left in the detached but visible state. |
| 1585 | ScreenCapture::captureScreen(&sc); |
| 1586 | sc->expectFGColor(64, 64); |
| 1587 | } |
| 1588 | } |
| 1589 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1590 | class GeometryLatchingTest : public LayerUpdateTest { |
| 1591 | protected: |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1592 | void EXPECT_INITIAL_STATE(const char* trace) { |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1593 | SCOPED_TRACE(trace); |
| 1594 | ScreenCapture::captureScreen(&sc); |
| 1595 | // We find the leading edge of the FG surface. |
| 1596 | sc->expectFGColor(127, 127); |
| 1597 | sc->expectBGColor(128, 128); |
| 1598 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 1599 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1600 | void lockAndFillFGBuffer() { fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false); } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 1601 | |
| 1602 | void unlockFGBuffer() { |
| 1603 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 1604 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 1605 | waitForPostedBuffers(); |
| 1606 | } |
| 1607 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1608 | void completeFGResize() { |
| 1609 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 1610 | waitForPostedBuffers(); |
| 1611 | } |
| 1612 | void restoreInitialState() { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1613 | asTransaction([&](Transaction& t) { |
| 1614 | t.setSize(mFGSurfaceControl, 64, 64); |
| 1615 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 1616 | t.setCrop(mFGSurfaceControl, Rect(0, 0, 64, 64)); |
| 1617 | t.setFinalCrop(mFGSurfaceControl, Rect(0, 0, -1, -1)); |
| 1618 | }); |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1619 | |
| 1620 | EXPECT_INITIAL_STATE("After restoring initial state"); |
| 1621 | } |
| 1622 | sp<ScreenCapture> sc; |
| 1623 | }; |
| 1624 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1625 | class CropLatchingTest : public GeometryLatchingTest { |
| 1626 | protected: |
| 1627 | void EXPECT_CROPPED_STATE(const char* trace) { |
| 1628 | SCOPED_TRACE(trace); |
| 1629 | ScreenCapture::captureScreen(&sc); |
| 1630 | // The edge should be moved back one pixel by our crop. |
| 1631 | sc->expectFGColor(126, 126); |
| 1632 | sc->expectBGColor(127, 127); |
| 1633 | sc->expectBGColor(128, 128); |
| 1634 | } |
chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 1635 | |
| 1636 | void EXPECT_RESIZE_STATE(const char* trace) { |
| 1637 | SCOPED_TRACE(trace); |
| 1638 | ScreenCapture::captureScreen(&sc); |
| 1639 | // The FG is now resized too 128,128 at 64,64 |
| 1640 | sc->expectFGColor(64, 64); |
| 1641 | sc->expectFGColor(191, 191); |
| 1642 | sc->expectBGColor(192, 192); |
| 1643 | } |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 1644 | }; |
| 1645 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 1646 | // In this test we ensure that setGeometryAppliesWithResize actually demands |
| 1647 | // a buffer of the new size, and not just any size. |
| 1648 | TEST_F(CropLatchingTest, FinalCropLatchingBufferOldSize) { |
| 1649 | EXPECT_INITIAL_STATE("before anything"); |
| 1650 | // Normally the crop applies immediately even while a resize is pending. |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1651 | asTransaction([&](Transaction& t) { |
| 1652 | t.setSize(mFGSurfaceControl, 128, 128); |
| 1653 | t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127)); |
| 1654 | }); |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 1655 | |
| 1656 | EXPECT_CROPPED_STATE("after setting crop (without geometryAppliesWithResize)"); |
| 1657 | |
| 1658 | restoreInitialState(); |
| 1659 | |
| 1660 | // In order to prepare to submit a buffer at the wrong size, we acquire it prior to |
| 1661 | // initiating the resize. |
| 1662 | lockAndFillFGBuffer(); |
| 1663 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1664 | asTransaction([&](Transaction& t) { |
| 1665 | t.setSize(mFGSurfaceControl, 128, 128); |
| 1666 | t.setGeometryAppliesWithResize(mFGSurfaceControl); |
| 1667 | t.setFinalCrop(mFGSurfaceControl, Rect(64, 64, 127, 127)); |
| 1668 | }); |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 1669 | |
| 1670 | EXPECT_INITIAL_STATE("after setting crop (with geometryAppliesWithResize)"); |
| 1671 | |
| 1672 | // We now submit our old buffer, at the old size, and ensure it doesn't |
| 1673 | // trigger geometry latching. |
| 1674 | unlockFGBuffer(); |
| 1675 | |
| 1676 | EXPECT_INITIAL_STATE("after unlocking FG buffer (with geometryAppliesWithResize)"); |
| 1677 | |
| 1678 | completeFGResize(); |
| 1679 | |
| 1680 | EXPECT_CROPPED_STATE("after the resize finishes"); |
| 1681 | } |
| 1682 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1683 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { |
| 1684 | sp<ScreenCapture> sc; |
| 1685 | { |
| 1686 | SCOPED_TRACE("before anything"); |
| 1687 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 1688 | sc->expectBGColor(32, 32); |
| 1689 | sc->expectFGColor(96, 96); |
| 1690 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | // set up two deferred transactions on different frames |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1694 | asTransaction([&](Transaction& t) { |
| 1695 | t.setAlpha(mFGSurfaceControl, 0.75); |
| 1696 | t.deferTransactionUntil(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1697 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1698 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1699 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1700 | asTransaction([&](Transaction& t) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1701 | t.setPosition(mFGSurfaceControl, 128, 128); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1702 | t.deferTransactionUntil(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1703 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1704 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1705 | |
| 1706 | { |
| 1707 | SCOPED_TRACE("before any trigger"); |
| 1708 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 1709 | sc->expectBGColor(32, 32); |
| 1710 | sc->expectFGColor(96, 96); |
| 1711 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | // should trigger the first deferred transaction, but not the second one |
| 1715 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 1716 | { |
| 1717 | SCOPED_TRACE("after first trigger"); |
| 1718 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 1719 | sc->expectBGColor(32, 32); |
| 1720 | sc->checkPixel(96, 96, 162, 63, 96); |
| 1721 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
| 1724 | // should show up immediately since it's not deferred |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1725 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 1.0); }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1726 | |
| 1727 | // trigger the second deferred transaction |
| 1728 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 1729 | { |
| 1730 | SCOPED_TRACE("after second trigger"); |
| 1731 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 1732 | sc->expectBGColor(32, 32); |
| 1733 | sc->expectBGColor(96, 96); |
| 1734 | sc->expectFGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 1738 | TEST_F(LayerUpdateTest, LayerWithNoBuffersResizesImmediately) { |
| 1739 | sp<ScreenCapture> sc; |
| 1740 | |
| 1741 | sp<SurfaceControl> childNoBuffer = |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1742 | mComposerClient->createSurface(String8("Bufferless child"), 10, 10, |
| 1743 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 1744 | sp<SurfaceControl> childBuffer = |
| 1745 | mComposerClient->createSurface(String8("Buffered child"), 20, 20, |
| 1746 | PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get()); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 1747 | fillSurfaceRGBA8(childBuffer, 200, 200, 200); |
| 1748 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1749 | SurfaceComposerClient::Transaction{}.show(childNoBuffer).show(childBuffer).apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 1750 | |
| 1751 | { |
| 1752 | ScreenCapture::captureScreen(&sc); |
| 1753 | sc->expectChildColor(73, 73); |
| 1754 | sc->expectFGColor(74, 74); |
| 1755 | } |
| 1756 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1757 | SurfaceComposerClient::Transaction{}.setSize(childNoBuffer, 20, 20).apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 1758 | |
| 1759 | { |
| 1760 | ScreenCapture::captureScreen(&sc); |
| 1761 | sc->expectChildColor(73, 73); |
| 1762 | sc->expectChildColor(74, 74); |
| 1763 | } |
| 1764 | } |
| 1765 | |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 1766 | TEST_F(LayerUpdateTest, MergingTransactions) { |
| 1767 | sp<ScreenCapture> sc; |
| 1768 | { |
| 1769 | SCOPED_TRACE("before move"); |
| 1770 | ScreenCapture::captureScreen(&sc); |
| 1771 | sc->expectBGColor(0, 12); |
| 1772 | sc->expectFGColor(75, 75); |
| 1773 | sc->expectBGColor(145, 145); |
| 1774 | } |
| 1775 | |
| 1776 | Transaction t1, t2; |
| 1777 | t1.setPosition(mFGSurfaceControl, 128, 128); |
| 1778 | t2.setPosition(mFGSurfaceControl, 0, 0); |
| 1779 | // We expect that the position update from t2 now |
| 1780 | // overwrites the position update from t1. |
| 1781 | t1.merge(std::move(t2)); |
| 1782 | t1.apply(); |
| 1783 | |
| 1784 | { |
| 1785 | ScreenCapture::captureScreen(&sc); |
| 1786 | sc->expectFGColor(1, 1); |
| 1787 | } |
| 1788 | } |
| 1789 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1790 | class ChildLayerTest : public LayerUpdateTest { |
| 1791 | protected: |
| 1792 | void SetUp() override { |
| 1793 | LayerUpdateTest::SetUp(); |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1794 | mChild = mComposerClient->createSurface(String8("Child surface"), 10, 10, |
| 1795 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1796 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 1797 | |
| 1798 | { |
| 1799 | SCOPED_TRACE("before anything"); |
| 1800 | ScreenCapture::captureScreen(&mCapture); |
| 1801 | mCapture->expectChildColor(64, 64); |
| 1802 | } |
| 1803 | } |
| 1804 | void TearDown() override { |
| 1805 | LayerUpdateTest::TearDown(); |
| 1806 | mChild = 0; |
| 1807 | } |
| 1808 | |
| 1809 | sp<SurfaceControl> mChild; |
| 1810 | sp<ScreenCapture> mCapture; |
| 1811 | }; |
| 1812 | |
| 1813 | TEST_F(ChildLayerTest, ChildLayerPositioning) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1814 | asTransaction([&](Transaction& t) { |
| 1815 | t.show(mChild); |
| 1816 | t.setPosition(mChild, 10, 10); |
| 1817 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 1818 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1819 | |
| 1820 | { |
| 1821 | ScreenCapture::captureScreen(&mCapture); |
| 1822 | // Top left of foreground must now be visible |
| 1823 | mCapture->expectFGColor(64, 64); |
| 1824 | // But 10 pixels in we should see the child surface |
| 1825 | mCapture->expectChildColor(74, 74); |
| 1826 | // And 10 more pixels we should be back to the foreground surface |
| 1827 | mCapture->expectFGColor(84, 84); |
| 1828 | } |
| 1829 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1830 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1831 | |
| 1832 | { |
| 1833 | ScreenCapture::captureScreen(&mCapture); |
| 1834 | // Top left of foreground should now be at 0, 0 |
| 1835 | mCapture->expectFGColor(0, 0); |
| 1836 | // But 10 pixels in we should see the child surface |
| 1837 | mCapture->expectChildColor(10, 10); |
| 1838 | // And 10 more pixels we should be back to the foreground surface |
| 1839 | mCapture->expectFGColor(20, 20); |
| 1840 | } |
| 1841 | } |
| 1842 | |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 1843 | TEST_F(ChildLayerTest, ChildLayerCropping) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1844 | asTransaction([&](Transaction& t) { |
| 1845 | t.show(mChild); |
| 1846 | t.setPosition(mChild, 0, 0); |
| 1847 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 1848 | t.setCrop(mFGSurfaceControl, Rect(0, 0, 5, 5)); |
| 1849 | }); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 1850 | |
| 1851 | { |
| 1852 | ScreenCapture::captureScreen(&mCapture); |
| 1853 | mCapture->expectChildColor(0, 0); |
| 1854 | mCapture->expectChildColor(4, 4); |
| 1855 | mCapture->expectBGColor(5, 5); |
| 1856 | } |
| 1857 | } |
| 1858 | |
| 1859 | TEST_F(ChildLayerTest, ChildLayerFinalCropping) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1860 | asTransaction([&](Transaction& t) { |
| 1861 | t.show(mChild); |
| 1862 | t.setPosition(mChild, 0, 0); |
| 1863 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 1864 | t.setFinalCrop(mFGSurfaceControl, Rect(0, 0, 5, 5)); |
| 1865 | }); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 1866 | |
| 1867 | { |
| 1868 | ScreenCapture::captureScreen(&mCapture); |
| 1869 | mCapture->expectChildColor(0, 0); |
| 1870 | mCapture->expectChildColor(4, 4); |
| 1871 | mCapture->expectBGColor(5, 5); |
| 1872 | } |
| 1873 | } |
| 1874 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1875 | TEST_F(ChildLayerTest, ChildLayerConstraints) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1876 | asTransaction([&](Transaction& t) { |
| 1877 | t.show(mChild); |
| 1878 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 1879 | t.setPosition(mChild, 63, 63); |
| 1880 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1881 | |
| 1882 | { |
| 1883 | ScreenCapture::captureScreen(&mCapture); |
| 1884 | mCapture->expectFGColor(0, 0); |
| 1885 | // Last pixel in foreground should now be the child. |
| 1886 | mCapture->expectChildColor(63, 63); |
| 1887 | // But the child should be constrained and the next pixel |
| 1888 | // must be the background |
| 1889 | mCapture->expectBGColor(64, 64); |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | TEST_F(ChildLayerTest, ChildLayerScaling) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1894 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1895 | |
| 1896 | // Find the boundary between the parent and child |
| 1897 | { |
| 1898 | ScreenCapture::captureScreen(&mCapture); |
| 1899 | mCapture->expectChildColor(9, 9); |
| 1900 | mCapture->expectFGColor(10, 10); |
| 1901 | } |
| 1902 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1903 | asTransaction([&](Transaction& t) { t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 1904 | |
| 1905 | // The boundary should be twice as far from the origin now. |
| 1906 | // The pixels from the last test should all be child now |
| 1907 | { |
| 1908 | ScreenCapture::captureScreen(&mCapture); |
| 1909 | mCapture->expectChildColor(9, 9); |
| 1910 | mCapture->expectChildColor(10, 10); |
| 1911 | mCapture->expectChildColor(19, 19); |
| 1912 | mCapture->expectFGColor(20, 20); |
| 1913 | } |
| 1914 | } |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 1915 | |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1916 | TEST_F(ChildLayerTest, ChildLayerAlpha) { |
| 1917 | fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254); |
| 1918 | fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0); |
| 1919 | fillSurfaceRGBA8(mChild, 0, 254, 0); |
| 1920 | waitForPostedBuffers(); |
| 1921 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1922 | asTransaction([&](Transaction& t) { |
| 1923 | t.show(mChild); |
| 1924 | t.setPosition(mChild, 0, 0); |
| 1925 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 1926 | }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1927 | |
| 1928 | { |
| 1929 | ScreenCapture::captureScreen(&mCapture); |
| 1930 | // Unblended child color |
| 1931 | mCapture->checkPixel(0, 0, 0, 254, 0); |
| 1932 | } |
| 1933 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1934 | asTransaction([&](Transaction& t) { t.setAlpha(mChild, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1935 | |
| 1936 | { |
| 1937 | ScreenCapture::captureScreen(&mCapture); |
| 1938 | // Child and BG blended. |
| 1939 | mCapture->checkPixel(0, 0, 127, 127, 0); |
| 1940 | } |
| 1941 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 1942 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 1943 | |
| 1944 | { |
| 1945 | ScreenCapture::captureScreen(&mCapture); |
| 1946 | // Child and BG blended. |
| 1947 | mCapture->checkPixel(0, 0, 95, 64, 95); |
| 1948 | } |
| 1949 | } |
| 1950 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 1951 | TEST_F(ChildLayerTest, ReparentChildren) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1952 | asTransaction([&](Transaction& t) { |
| 1953 | t.show(mChild); |
| 1954 | t.setPosition(mChild, 10, 10); |
| 1955 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 1956 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 1957 | |
| 1958 | { |
| 1959 | ScreenCapture::captureScreen(&mCapture); |
| 1960 | // Top left of foreground must now be visible |
| 1961 | mCapture->expectFGColor(64, 64); |
| 1962 | // But 10 pixels in we should see the child surface |
| 1963 | mCapture->expectChildColor(74, 74); |
| 1964 | // And 10 more pixels we should be back to the foreground surface |
| 1965 | mCapture->expectFGColor(84, 84); |
| 1966 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1967 | |
| 1968 | asTransaction([&](Transaction& t) { |
| 1969 | t.reparentChildren(mFGSurfaceControl, mBGSurfaceControl->getHandle()); |
| 1970 | }); |
| 1971 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 1972 | { |
| 1973 | ScreenCapture::captureScreen(&mCapture); |
| 1974 | mCapture->expectFGColor(64, 64); |
| 1975 | // In reparenting we should have exposed the entire foreground surface. |
| 1976 | mCapture->expectFGColor(74, 74); |
| 1977 | // And the child layer should now begin at 10, 10 (since the BG |
| 1978 | // layer is at (0, 0)). |
| 1979 | mCapture->expectBGColor(9, 9); |
| 1980 | mCapture->expectChildColor(10, 10); |
| 1981 | } |
| 1982 | } |
| 1983 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 1984 | TEST_F(ChildLayerTest, DetachChildrenSameClient) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 1985 | asTransaction([&](Transaction& t) { |
| 1986 | t.show(mChild); |
| 1987 | t.setPosition(mChild, 10, 10); |
| 1988 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 1989 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 1990 | |
| 1991 | { |
| 1992 | ScreenCapture::captureScreen(&mCapture); |
| 1993 | // Top left of foreground must now be visible |
| 1994 | mCapture->expectFGColor(64, 64); |
| 1995 | // But 10 pixels in we should see the child surface |
| 1996 | mCapture->expectChildColor(74, 74); |
| 1997 | // And 10 more pixels we should be back to the foreground surface |
| 1998 | mCapture->expectFGColor(84, 84); |
| 1999 | } |
| 2000 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2001 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 2002 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2003 | asTransaction([&](Transaction& t) { t.hide(mChild); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 2004 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 2005 | // Since the child has the same client as the parent, it will not get |
| 2006 | // detached and will be hidden. |
| 2007 | { |
| 2008 | ScreenCapture::captureScreen(&mCapture); |
| 2009 | mCapture->expectFGColor(64, 64); |
| 2010 | mCapture->expectFGColor(74, 74); |
| 2011 | mCapture->expectFGColor(84, 84); |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | TEST_F(ChildLayerTest, DetachChildrenDifferentClient) { |
| 2016 | sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient; |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2017 | sp<SurfaceControl> mChildNewClient = |
| 2018 | mNewComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, |
| 2019 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 2020 | |
| 2021 | ASSERT_TRUE(mChildNewClient != NULL); |
| 2022 | ASSERT_TRUE(mChildNewClient->isValid()); |
| 2023 | |
| 2024 | fillSurfaceRGBA8(mChildNewClient, 200, 200, 200); |
| 2025 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2026 | asTransaction([&](Transaction& t) { |
| 2027 | t.hide(mChild); |
| 2028 | t.show(mChildNewClient); |
| 2029 | t.setPosition(mChildNewClient, 10, 10); |
| 2030 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 2031 | }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 2032 | |
| 2033 | { |
| 2034 | ScreenCapture::captureScreen(&mCapture); |
| 2035 | // Top left of foreground must now be visible |
| 2036 | mCapture->expectFGColor(64, 64); |
| 2037 | // But 10 pixels in we should see the child surface |
| 2038 | mCapture->expectChildColor(74, 74); |
| 2039 | // And 10 more pixels we should be back to the foreground surface |
| 2040 | mCapture->expectFGColor(84, 84); |
| 2041 | } |
| 2042 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2043 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 2044 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2045 | asTransaction([&](Transaction& t) { t.hide(mChildNewClient); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 2046 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 2047 | // Nothing should have changed. |
| 2048 | { |
| 2049 | ScreenCapture::captureScreen(&mCapture); |
| 2050 | mCapture->expectFGColor(64, 64); |
| 2051 | mCapture->expectChildColor(74, 74); |
| 2052 | mCapture->expectFGColor(84, 84); |
| 2053 | } |
| 2054 | } |
| 2055 | |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 2056 | TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2057 | asTransaction([&](Transaction& t) { |
| 2058 | t.show(mChild); |
| 2059 | t.setPosition(mChild, 0, 0); |
| 2060 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 2061 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 2062 | |
| 2063 | { |
| 2064 | ScreenCapture::captureScreen(&mCapture); |
| 2065 | // We've positioned the child in the top left. |
| 2066 | mCapture->expectChildColor(0, 0); |
| 2067 | // But it's only 10x10. |
| 2068 | mCapture->expectFGColor(10, 10); |
| 2069 | } |
| 2070 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2071 | asTransaction([&](Transaction& t) { |
| 2072 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 2073 | // We cause scaling by 2. |
| 2074 | t.setSize(mFGSurfaceControl, 128, 128); |
| 2075 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 2076 | |
| 2077 | { |
| 2078 | ScreenCapture::captureScreen(&mCapture); |
| 2079 | // We've positioned the child in the top left. |
| 2080 | mCapture->expectChildColor(0, 0); |
| 2081 | mCapture->expectChildColor(10, 10); |
| 2082 | mCapture->expectChildColor(19, 19); |
| 2083 | // And now it should be scaled all the way to 20x20 |
| 2084 | mCapture->expectFGColor(20, 20); |
| 2085 | } |
| 2086 | } |
| 2087 | |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 2088 | // Regression test for b/37673612 |
| 2089 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2090 | asTransaction([&](Transaction& t) { |
| 2091 | t.show(mChild); |
| 2092 | t.setPosition(mChild, 0, 0); |
| 2093 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 2094 | }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 2095 | |
| 2096 | { |
| 2097 | ScreenCapture::captureScreen(&mCapture); |
| 2098 | // We've positioned the child in the top left. |
| 2099 | mCapture->expectChildColor(0, 0); |
| 2100 | // But it's only 10x10. |
| 2101 | mCapture->expectFGColor(10, 10); |
| 2102 | } |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 2103 | // We set things up as in b/37673612 so that there is a mismatch between the buffer size and |
| 2104 | // the WM specified state size. |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2105 | asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 2106 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 2107 | auto anw = static_cast<ANativeWindow*>(s.get()); |
| 2108 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 2109 | native_window_set_buffers_dimensions(anw, 64, 128); |
| 2110 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 2111 | waitForPostedBuffers(); |
| 2112 | |
| 2113 | { |
| 2114 | // The child should still be in the same place and not have any strange scaling as in |
| 2115 | // b/37673612. |
| 2116 | ScreenCapture::captureScreen(&mCapture); |
| 2117 | mCapture->expectChildColor(0, 0); |
| 2118 | mCapture->expectFGColor(10, 10); |
| 2119 | } |
| 2120 | } |
| 2121 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 2122 | TEST_F(ChildLayerTest, Bug36858924) { |
| 2123 | // Destroy the child layer |
| 2124 | mChild.clear(); |
| 2125 | |
| 2126 | // Now recreate it as hidden |
| 2127 | mChild = mComposerClient->createSurface(String8("Child surface"), 10, 10, |
| 2128 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eHidden, |
| 2129 | mFGSurfaceControl.get()); |
| 2130 | |
| 2131 | // Show the child layer in a deferred transaction |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2132 | asTransaction([&](Transaction& t) { |
| 2133 | t.deferTransactionUntil(mChild, mFGSurfaceControl->getHandle(), |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2134 | mFGSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2135 | t.show(mChild); |
| 2136 | }); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 2137 | |
| 2138 | // Render the foreground surface a few times |
| 2139 | // |
| 2140 | // Prior to the bugfix for b/36858924, this would usually hang while trying to fill the third |
| 2141 | // frame because SurfaceFlinger would never process the deferred transaction and would therefore |
| 2142 | // never acquire/release the first buffer |
| 2143 | ALOGI("Filling 1"); |
| 2144 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 2145 | ALOGI("Filling 2"); |
| 2146 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 0, 255); |
| 2147 | ALOGI("Filling 3"); |
| 2148 | fillSurfaceRGBA8(mFGSurfaceControl, 255, 0, 0); |
| 2149 | ALOGI("Filling 4"); |
| 2150 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 2151 | } |
| 2152 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 2153 | TEST_F(ChildLayerTest, Reparent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2154 | asTransaction([&](Transaction& t) { |
| 2155 | t.show(mChild); |
| 2156 | t.setPosition(mChild, 10, 10); |
| 2157 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 2158 | }); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 2159 | |
| 2160 | { |
| 2161 | ScreenCapture::captureScreen(&mCapture); |
| 2162 | // Top left of foreground must now be visible |
| 2163 | mCapture->expectFGColor(64, 64); |
| 2164 | // But 10 pixels in we should see the child surface |
| 2165 | mCapture->expectChildColor(74, 74); |
| 2166 | // And 10 more pixels we should be back to the foreground surface |
| 2167 | mCapture->expectFGColor(84, 84); |
| 2168 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2169 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2170 | asTransaction([&](Transaction& t) { t.reparent(mChild, mBGSurfaceControl->getHandle()); }); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2171 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 2172 | { |
| 2173 | ScreenCapture::captureScreen(&mCapture); |
| 2174 | mCapture->expectFGColor(64, 64); |
| 2175 | // In reparenting we should have exposed the entire foreground surface. |
| 2176 | mCapture->expectFGColor(74, 74); |
| 2177 | // And the child layer should now begin at 10, 10 (since the BG |
| 2178 | // layer is at (0, 0)). |
| 2179 | mCapture->expectBGColor(9, 9); |
| 2180 | mCapture->expectChildColor(10, 10); |
| 2181 | } |
| 2182 | } |
| 2183 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 2184 | TEST_F(ChildLayerTest, ReparentToNoParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2185 | asTransaction([&](Transaction& t) { |
| 2186 | t.show(mChild); |
| 2187 | t.setPosition(mChild, 10, 10); |
| 2188 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 2189 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 2190 | |
| 2191 | { |
| 2192 | ScreenCapture::captureScreen(&mCapture); |
| 2193 | // Top left of foreground must now be visible |
| 2194 | mCapture->expectFGColor(64, 64); |
| 2195 | // But 10 pixels in we should see the child surface |
| 2196 | mCapture->expectChildColor(74, 74); |
| 2197 | // And 10 more pixels we should be back to the foreground surface |
| 2198 | mCapture->expectFGColor(84, 84); |
| 2199 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2200 | asTransaction([&](Transaction& t) { t.reparent(mChild, nullptr); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 2201 | { |
| 2202 | ScreenCapture::captureScreen(&mCapture); |
| 2203 | // Nothing should have changed. |
| 2204 | mCapture->expectFGColor(64, 64); |
| 2205 | mCapture->expectChildColor(74, 74); |
| 2206 | mCapture->expectFGColor(84, 84); |
| 2207 | } |
| 2208 | } |
| 2209 | |
| 2210 | TEST_F(ChildLayerTest, ReparentFromNoParent) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2211 | sp<SurfaceControl> newSurface = mComposerClient->createSurface(String8("New Surface"), 10, 10, |
| 2212 | PIXEL_FORMAT_RGBA_8888, 0); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 2213 | ASSERT_TRUE(newSurface != NULL); |
| 2214 | ASSERT_TRUE(newSurface->isValid()); |
| 2215 | |
| 2216 | fillSurfaceRGBA8(newSurface, 63, 195, 63); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2217 | asTransaction([&](Transaction& t) { |
| 2218 | t.hide(mChild); |
| 2219 | t.show(newSurface); |
| 2220 | t.setPosition(newSurface, 10, 10); |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2221 | t.setLayer(newSurface, INT32_MAX - 2); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2222 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 2223 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 2224 | |
| 2225 | { |
| 2226 | ScreenCapture::captureScreen(&mCapture); |
| 2227 | // Top left of foreground must now be visible |
| 2228 | mCapture->expectFGColor(64, 64); |
| 2229 | // At 10, 10 we should see the new surface |
| 2230 | mCapture->checkPixel(10, 10, 63, 195, 63); |
| 2231 | } |
| 2232 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2233 | asTransaction([&](Transaction& t) { t.reparent(newSurface, mFGSurfaceControl->getHandle()); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 2234 | |
| 2235 | { |
| 2236 | ScreenCapture::captureScreen(&mCapture); |
| 2237 | // newSurface will now be a child of mFGSurface so it will be 10, 10 offset from |
| 2238 | // mFGSurface, putting it at 74, 74. |
| 2239 | mCapture->expectFGColor(64, 64); |
| 2240 | mCapture->checkPixel(74, 74, 63, 195, 63); |
| 2241 | mCapture->expectFGColor(84, 84); |
| 2242 | } |
| 2243 | } |
| 2244 | |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 2245 | TEST_F(ChildLayerTest, NestedChildren) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2246 | sp<SurfaceControl> grandchild = |
| 2247 | mComposerClient->createSurface(String8("Grandchild surface"), 10, 10, |
| 2248 | PIXEL_FORMAT_RGBA_8888, 0, mChild.get()); |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 2249 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 2250 | |
| 2251 | { |
| 2252 | ScreenCapture::captureScreen(&mCapture); |
| 2253 | // Expect the grandchild to begin at 64, 64 because it's a child of mChild layer |
| 2254 | // which begins at 64, 64 |
| 2255 | mCapture->checkPixel(64, 64, 50, 50, 50); |
| 2256 | } |
| 2257 | } |
| 2258 | |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 2259 | TEST_F(ChildLayerTest, ChildLayerRelativeLayer) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2260 | sp<SurfaceControl> relative = mComposerClient->createSurface(String8("Relative surface"), 128, |
| 2261 | 128, PIXEL_FORMAT_RGBA_8888, 0); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 2262 | fillSurfaceRGBA8(relative, 255, 255, 255); |
| 2263 | |
| 2264 | Transaction t; |
| 2265 | t.setLayer(relative, INT32_MAX) |
| 2266 | .setRelativeLayer(mChild, relative->getHandle(), 1) |
| 2267 | .setPosition(mFGSurfaceControl, 0, 0) |
| 2268 | .apply(true); |
| 2269 | |
| 2270 | // We expect that the child should have been elevated above our |
| 2271 | // INT_MAX layer even though it's not a child of it. |
| 2272 | { |
| 2273 | ScreenCapture::captureScreen(&mCapture); |
| 2274 | mCapture->expectChildColor(0, 0); |
| 2275 | mCapture->expectChildColor(9, 9); |
| 2276 | mCapture->checkPixel(10, 10, 255, 255, 255); |
| 2277 | } |
| 2278 | } |
| 2279 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2280 | class ScreenCaptureTest : public LayerUpdateTest { |
| 2281 | protected: |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2282 | std::unique_ptr<ScreenCapture> mCapture; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2283 | }; |
| 2284 | |
| 2285 | TEST_F(ScreenCaptureTest, CaptureSingleLayer) { |
| 2286 | auto bgHandle = mBGSurfaceControl->getHandle(); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2287 | ScreenCapture::captureLayers(&mCapture, bgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2288 | mCapture->expectBGColor(0, 0); |
| 2289 | // Doesn't capture FG layer which is at 64, 64 |
| 2290 | mCapture->expectBGColor(64, 64); |
| 2291 | } |
| 2292 | |
| 2293 | TEST_F(ScreenCaptureTest, CaptureLayerWithChild) { |
| 2294 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 2295 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2296 | sp<SurfaceControl> child = |
| 2297 | mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 2298 | 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2299 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 2300 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2301 | SurfaceComposerClient::Transaction().show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2302 | |
| 2303 | // Captures mFGSurfaceControl layer and its child. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2304 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2305 | mCapture->expectFGColor(10, 10); |
| 2306 | mCapture->expectChildColor(0, 0); |
| 2307 | } |
| 2308 | |
| 2309 | TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) { |
| 2310 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 2311 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2312 | sp<SurfaceControl> child = |
| 2313 | mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 2314 | 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2315 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 2316 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2317 | sp<SurfaceControl> grandchild = |
| 2318 | mComposerClient->createSurface(String8("Grandchild surface"), 5, 5, |
| 2319 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2320 | |
| 2321 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 2322 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2323 | .show(child) |
| 2324 | .setPosition(grandchild, 5, 5) |
| 2325 | .show(grandchild) |
| 2326 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2327 | |
| 2328 | // Captures mFGSurfaceControl, its child, and the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2329 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2330 | mCapture->expectFGColor(10, 10); |
| 2331 | mCapture->expectChildColor(0, 0); |
| 2332 | mCapture->checkPixel(5, 5, 50, 50, 50); |
| 2333 | } |
| 2334 | |
| 2335 | TEST_F(ScreenCaptureTest, CaptureChildOnly) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2336 | sp<SurfaceControl> child = |
| 2337 | mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 2338 | 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2339 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 2340 | auto childHandle = child->getHandle(); |
| 2341 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2342 | SurfaceComposerClient::Transaction().setPosition(child, 5, 5).show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2343 | |
| 2344 | // Captures only the child layer, and not the parent. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2345 | ScreenCapture::captureLayers(&mCapture, childHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2346 | mCapture->expectChildColor(0, 0); |
| 2347 | mCapture->expectChildColor(9, 9); |
| 2348 | } |
| 2349 | |
| 2350 | TEST_F(ScreenCaptureTest, CaptureGrandchildOnly) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2351 | sp<SurfaceControl> child = |
| 2352 | mComposerClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 2353 | 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2354 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 2355 | auto childHandle = child->getHandle(); |
| 2356 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2357 | sp<SurfaceControl> grandchild = |
| 2358 | mComposerClient->createSurface(String8("Grandchild surface"), 5, 5, |
| 2359 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2360 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 2361 | |
| 2362 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2363 | .show(child) |
| 2364 | .setPosition(grandchild, 5, 5) |
| 2365 | .show(grandchild) |
| 2366 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2367 | |
| 2368 | auto grandchildHandle = grandchild->getHandle(); |
| 2369 | |
| 2370 | // Captures only the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2371 | ScreenCapture::captureLayers(&mCapture, grandchildHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 2372 | mCapture->checkPixel(0, 0, 50, 50, 50); |
| 2373 | mCapture->checkPixel(4, 4, 50, 50, 50); |
| 2374 | } |
| 2375 | |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2376 | TEST_F(ScreenCaptureTest, CaptureCrop) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2377 | sp<SurfaceControl> redLayer = mComposerClient->createSurface(String8("Red surface"), 60, 60, |
| 2378 | PIXEL_FORMAT_RGBA_8888, 0); |
| 2379 | sp<SurfaceControl> blueLayer = |
| 2380 | mComposerClient->createSurface(String8("Blue surface"), 30, 30, PIXEL_FORMAT_RGBA_8888, |
| 2381 | 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2382 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2383 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(redLayer, Color::RED)); |
| 2384 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(blueLayer, Color::BLUE)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2385 | |
| 2386 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2387 | .setLayer(redLayer, INT32_MAX - 1) |
| 2388 | .show(redLayer) |
| 2389 | .show(blueLayer) |
| 2390 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2391 | |
| 2392 | auto redLayerHandle = redLayer->getHandle(); |
| 2393 | |
| 2394 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2395 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 2396 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 2397 | // red area below the blue area |
| 2398 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 2399 | // red area to the right of the blue area |
| 2400 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2401 | |
| 2402 | Rect crop = Rect(0, 0, 30, 30); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2403 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, crop); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2404 | // Capturing the cropped screen, cropping out the shown red area, should leave only the blue |
| 2405 | // area visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2406 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2407 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 2408 | } |
| 2409 | |
| 2410 | TEST_F(ScreenCaptureTest, CaptureSize) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2411 | sp<SurfaceControl> redLayer = mComposerClient->createSurface(String8("Red surface"), 60, 60, |
| 2412 | PIXEL_FORMAT_RGBA_8888, 0); |
| 2413 | sp<SurfaceControl> blueLayer = |
| 2414 | mComposerClient->createSurface(String8("Blue surface"), 30, 30, PIXEL_FORMAT_RGBA_8888, |
| 2415 | 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2416 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2417 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(redLayer, Color::RED)); |
| 2418 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(blueLayer, Color::BLUE)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2419 | |
| 2420 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2421 | .setLayer(redLayer, INT32_MAX - 1) |
| 2422 | .show(redLayer) |
| 2423 | .show(blueLayer) |
| 2424 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2425 | |
| 2426 | auto redLayerHandle = redLayer->getHandle(); |
| 2427 | |
| 2428 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2429 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 2430 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 2431 | // red area below the blue area |
| 2432 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 2433 | // red area to the right of the blue area |
| 2434 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2435 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2436 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, Rect::EMPTY_RECT, 0.5); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2437 | // Capturing the downsized area (30x30) should leave both red and blue but in a smaller area. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2438 | mCapture->expectColor(Rect(0, 0, 14, 14), Color::BLUE); |
| 2439 | // red area below the blue area |
| 2440 | mCapture->expectColor(Rect(0, 15, 29, 29), Color::RED); |
| 2441 | // red area to the right of the blue area |
| 2442 | mCapture->expectColor(Rect(15, 0, 29, 29), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2443 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 2444 | } |
| 2445 | |
| 2446 | TEST_F(ScreenCaptureTest, CaptureInvalidLayer) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2447 | sp<SurfaceControl> redLayer = mComposerClient->createSurface(String8("Red surface"), 60, 60, |
| 2448 | PIXEL_FORMAT_RGBA_8888, 0); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2449 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2450 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(redLayer, Color::RED)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2451 | |
| 2452 | auto redLayerHandle = redLayer->getHandle(); |
| 2453 | mComposerClient->destroySurface(redLayerHandle); |
| 2454 | SurfaceComposerClient::Transaction().apply(true); |
| 2455 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2456 | sp<GraphicBuffer> outBuffer; |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2457 | |
| 2458 | // Layer was deleted so captureLayers should fail with NAME_NOT_FOUND |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2459 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 2460 | ASSERT_EQ(NAME_NOT_FOUND, sf->captureLayers(redLayerHandle, &outBuffer, Rect::EMPTY_RECT, 1.0)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 2461 | } |
| 2462 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame^] | 2463 | } // namespace android |