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> |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 18 | #include <chrono> |
| 19 | #include <cinttypes> |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 20 | #include <functional> |
| 21 | #include <limits> |
| 22 | #include <ostream> |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 23 | #include <thread> |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 24 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 25 | #include <gtest/gtest.h> |
| 26 | |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 27 | #include <android/native_window.h> |
| 28 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 29 | #include <gui/ISurfaceComposer.h> |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 30 | #include <gui/LayerState.h> |
| 31 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 32 | #include <gui/Surface.h> |
| 33 | #include <gui/SurfaceComposerClient.h> |
| 34 | #include <private/gui/ComposerService.h> |
| 35 | |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 36 | #include <ui/ColorSpace.h> |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 37 | #include <ui/DisplayInfo.h> |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 38 | #include <ui/Rect.h> |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 39 | #include <utils/String8.h> |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 40 | |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 41 | #include <math.h> |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 42 | #include <math/vec3.h> |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 43 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 44 | namespace android { |
| 45 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 46 | namespace { |
| 47 | |
| 48 | struct Color { |
| 49 | uint8_t r; |
| 50 | uint8_t g; |
| 51 | uint8_t b; |
| 52 | uint8_t a; |
| 53 | |
| 54 | static const Color RED; |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 55 | static const Color GREEN; |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 56 | static const Color BLUE; |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 57 | static const Color WHITE; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 58 | static const Color BLACK; |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 59 | static const Color TRANSPARENT; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | const Color Color::RED{255, 0, 0, 255}; |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 63 | const Color Color::GREEN{0, 255, 0, 255}; |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 64 | const Color Color::BLUE{0, 0, 255, 255}; |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 65 | const Color Color::WHITE{255, 255, 255, 255}; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 66 | const Color Color::BLACK{0, 0, 0, 255}; |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 67 | const Color Color::TRANSPARENT{0, 0, 0, 0}; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 68 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 69 | using android::hardware::graphics::common::V1_1::BufferUsage; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 70 | using namespace std::chrono_literals; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 71 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 72 | std::ostream& operator<<(std::ostream& os, const Color& color) { |
| 73 | os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a); |
| 74 | return os; |
| 75 | } |
| 76 | |
| 77 | // Fill a region with the specified color. |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 78 | void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect, |
| 79 | const Color& color) { |
| 80 | Rect r(0, 0, buffer.width, buffer.height); |
| 81 | if (!r.intersect(rect, &r)) { |
| 82 | return; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 85 | int32_t width = r.right - r.left; |
| 86 | int32_t height = r.bottom - r.top; |
| 87 | |
| 88 | for (int32_t row = 0; row < height; row++) { |
| 89 | uint8_t* dst = |
| 90 | static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (r.top + row) + r.left) * 4; |
| 91 | for (int32_t column = 0; column < width; column++) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 92 | dst[0] = color.r; |
| 93 | dst[1] = color.g; |
| 94 | dst[2] = color.b; |
| 95 | dst[3] = color.a; |
| 96 | dst += 4; |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 101 | // Fill a region with the specified color. |
| 102 | void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect, const Color& color) { |
| 103 | Rect r(0, 0, buffer->width, buffer->height); |
| 104 | if (!r.intersect(rect, &r)) { |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | int32_t width = r.right - r.left; |
| 109 | int32_t height = r.bottom - r.top; |
| 110 | |
| 111 | uint8_t* pixels; |
| 112 | buffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 113 | reinterpret_cast<void**>(&pixels)); |
| 114 | |
| 115 | for (int32_t row = 0; row < height; row++) { |
| 116 | uint8_t* dst = pixels + (buffer->getStride() * (r.top + row) + r.left) * 4; |
| 117 | for (int32_t column = 0; column < width; column++) { |
| 118 | dst[0] = color.r; |
| 119 | dst[1] = color.g; |
| 120 | dst[2] = color.b; |
| 121 | dst[3] = color.a; |
| 122 | dst += 4; |
| 123 | } |
| 124 | } |
| 125 | buffer->unlock(); |
| 126 | } |
| 127 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 128 | // Check if a region has the specified color. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 129 | 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] | 130 | const Color& color, uint8_t tolerance) { |
| 131 | int32_t x = rect.left; |
| 132 | int32_t y = rect.top; |
| 133 | int32_t width = rect.right - rect.left; |
| 134 | int32_t height = rect.bottom - rect.top; |
| 135 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 136 | int32_t bufferWidth = int32_t(outBuffer->getWidth()); |
| 137 | int32_t bufferHeight = int32_t(outBuffer->getHeight()); |
| 138 | if (x + width > bufferWidth) { |
| 139 | x = std::min(x, bufferWidth); |
| 140 | width = bufferWidth - x; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 141 | } |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 142 | if (y + height > bufferHeight) { |
| 143 | y = std::min(y, bufferHeight); |
| 144 | height = bufferHeight - y; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | auto colorCompare = [tolerance](uint8_t a, uint8_t b) { |
| 148 | uint8_t tmp = a >= b ? a - b : b - a; |
| 149 | return tmp <= tolerance; |
| 150 | }; |
| 151 | for (int32_t j = 0; j < height; j++) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 152 | const uint8_t* src = pixels + (outBuffer->getStride() * (y + j) + x) * 4; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 153 | for (int32_t i = 0; i < width; i++) { |
| 154 | const uint8_t expected[4] = {color.r, color.g, color.b, color.a}; |
| 155 | EXPECT_TRUE(std::equal(src, src + 4, expected, colorCompare)) |
| 156 | << "pixel @ (" << x + i << ", " << y + j << "): " |
| 157 | << "expected (" << color << "), " |
| 158 | << "got (" << Color{src[0], src[1], src[2], src[3]} << ")"; |
| 159 | src += 4; |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | } // anonymous namespace |
| 165 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 166 | using Transaction = SurfaceComposerClient::Transaction; |
| 167 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 168 | // Fill an RGBA_8888 formatted surface with a single color. |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 169 | static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b, |
| 170 | bool unlock = true) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 171 | ANativeWindow_Buffer outBuffer; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 172 | sp<Surface> s = sc->getSurface(); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 173 | ASSERT_TRUE(s != nullptr); |
| 174 | ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, nullptr)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 175 | uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 176 | for (int y = 0; y < outBuffer.height; y++) { |
| 177 | for (int x = 0; x < outBuffer.width; x++) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 178 | uint8_t* pixel = img + (4 * (y * outBuffer.stride + x)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 179 | pixel[0] = r; |
| 180 | pixel[1] = g; |
| 181 | pixel[2] = b; |
| 182 | pixel[3] = 255; |
| 183 | } |
| 184 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 185 | if (unlock) { |
| 186 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 187 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check |
| 191 | // individual pixel values for testing purposes. |
| 192 | class ScreenCapture : public RefBase { |
| 193 | public: |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 194 | static void captureScreen(std::unique_ptr<ScreenCapture>* sc) { |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 195 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 196 | sp<IBinder> display(sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 197 | SurfaceComposerClient::Transaction().apply(true); |
| 198 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 199 | sp<GraphicBuffer> outBuffer; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 200 | ASSERT_EQ(NO_ERROR, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 201 | sf->captureScreen(display, &outBuffer, Rect(), 0, 0, false)); |
| 202 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, |
| 206 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { |
| 207 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 208 | SurfaceComposerClient::Transaction().apply(true); |
| 209 | |
| 210 | sp<GraphicBuffer> outBuffer; |
| 211 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale)); |
| 212 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 215 | static void captureChildLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, |
| 216 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { |
| 217 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 218 | SurfaceComposerClient::Transaction().apply(true); |
| 219 | |
| 220 | sp<GraphicBuffer> outBuffer; |
| 221 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale, true)); |
| 222 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
| 223 | } |
| 224 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 225 | void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 226 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
| 227 | expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 231 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 232 | const bool leftBorder = rect.left > 0; |
| 233 | const bool topBorder = rect.top > 0; |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 234 | const bool rightBorder = rect.right < int32_t(mOutBuffer->getWidth()); |
| 235 | const bool bottomBorder = rect.bottom < int32_t(mOutBuffer->getHeight()); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 236 | |
| 237 | if (topBorder) { |
| 238 | Rect top(rect.left, rect.top - 1, rect.right, rect.top); |
| 239 | if (leftBorder) { |
| 240 | top.left -= 1; |
| 241 | } |
| 242 | if (rightBorder) { |
| 243 | top.right += 1; |
| 244 | } |
| 245 | expectColor(top, color, tolerance); |
| 246 | } |
| 247 | if (leftBorder) { |
| 248 | Rect left(rect.left - 1, rect.top, rect.left, rect.bottom); |
| 249 | expectColor(left, color, tolerance); |
| 250 | } |
| 251 | if (rightBorder) { |
| 252 | Rect right(rect.right, rect.top, rect.right + 1, rect.bottom); |
| 253 | expectColor(right, color, tolerance); |
| 254 | } |
| 255 | if (bottomBorder) { |
| 256 | Rect bottom(rect.left, rect.bottom, rect.right, rect.bottom + 1); |
| 257 | if (leftBorder) { |
| 258 | bottom.left -= 1; |
| 259 | } |
| 260 | if (rightBorder) { |
| 261 | bottom.right += 1; |
| 262 | } |
| 263 | expectColor(bottom, color, tolerance); |
| 264 | } |
| 265 | } |
| 266 | |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 267 | void expectQuadrant(const Rect& rect, const Color& topLeft, const Color& topRight, |
| 268 | const Color& bottomLeft, const Color& bottomRight, bool filtered = false, |
| 269 | uint8_t tolerance = 0) { |
| 270 | ASSERT_TRUE((rect.right - rect.left) % 2 == 0 && (rect.bottom - rect.top) % 2 == 0); |
| 271 | |
| 272 | const int32_t centerX = rect.left + (rect.right - rect.left) / 2; |
| 273 | const int32_t centerY = rect.top + (rect.bottom - rect.top) / 2; |
| 274 | // avoid checking borders due to unspecified filtering behavior |
| 275 | const int32_t offsetX = filtered ? 2 : 0; |
| 276 | const int32_t offsetY = filtered ? 2 : 0; |
| 277 | expectColor(Rect(rect.left, rect.top, centerX - offsetX, centerY - offsetY), topLeft, |
| 278 | tolerance); |
| 279 | expectColor(Rect(centerX + offsetX, rect.top, rect.right, centerY - offsetY), topRight, |
| 280 | tolerance); |
| 281 | expectColor(Rect(rect.left, centerY + offsetY, centerX - offsetX, rect.bottom), bottomLeft, |
| 282 | tolerance); |
| 283 | expectColor(Rect(centerX + offsetX, centerY + offsetY, rect.right, rect.bottom), |
| 284 | bottomRight, tolerance); |
| 285 | } |
| 286 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 287 | 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] | 288 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
| 289 | const uint8_t* pixel = mPixels + (4 * (y * mOutBuffer->getStride() + x)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 290 | if (r != pixel[0] || g != pixel[1] || b != pixel[2]) { |
| 291 | String8 err(String8::format("pixel @ (%3d, %3d): " |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 292 | "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]", |
| 293 | x, y, r, g, b, pixel[0], pixel[1], pixel[2])); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 294 | EXPECT_EQ(String8(), err) << err.string(); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 298 | 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] | 299 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 300 | 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] | 301 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 302 | 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] | 303 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 304 | ScreenCapture(const sp<GraphicBuffer>& outBuffer) : mOutBuffer(outBuffer) { |
| 305 | mOutBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&mPixels)); |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 306 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 307 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 308 | ~ScreenCapture() { mOutBuffer->unlock(); } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 309 | |
| 310 | private: |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 311 | sp<GraphicBuffer> mOutBuffer; |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 312 | uint8_t* mPixels = nullptr; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 313 | }; |
| 314 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 315 | class LayerTransactionTest : public ::testing::Test { |
| 316 | protected: |
| 317 | void SetUp() override { |
| 318 | mClient = new SurfaceComposerClient; |
| 319 | ASSERT_EQ(NO_ERROR, mClient->initCheck()) << "failed to create SurfaceComposerClient"; |
| 320 | |
| 321 | ASSERT_NO_FATAL_FAILURE(SetUpDisplay()); |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 322 | |
| 323 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 324 | sp<IBinder> binder = sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain); |
Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 325 | ASSERT_NO_FATAL_FAILURE(sf->getColorManagement(&mColorManagementUsed)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 326 | } |
| 327 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 328 | virtual void TearDown() { |
| 329 | mBlackBgSurface = 0; |
| 330 | mClient->dispose(); |
| 331 | mClient = 0; |
| 332 | } |
| 333 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 334 | virtual sp<SurfaceControl> createLayer(const sp<SurfaceComposerClient>& client, |
| 335 | const char* name, uint32_t width, uint32_t height, |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 336 | uint32_t flags = 0) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 337 | auto layer = |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 338 | client->createSurface(String8(name), width, height, PIXEL_FORMAT_RGBA_8888, flags); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 339 | EXPECT_NE(nullptr, layer.get()) << "failed to create SurfaceControl"; |
| 340 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 341 | Transaction t; |
| 342 | t.setLayerStack(layer, mDisplayLayerStack).setLayer(layer, mLayerZBase); |
| 343 | // If we are creating a color layer, set its crop since its size will be ignored. |
| 344 | if (flags == ISurfaceComposerClient::eFXSurfaceColor) { |
| 345 | t.setCrop_legacy(layer, Rect(0, 0, width, height)); |
| 346 | } |
| 347 | |
| 348 | status_t error = t.apply(); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 349 | if (error != NO_ERROR) { |
| 350 | ADD_FAILURE() << "failed to initialize SurfaceControl"; |
| 351 | layer.clear(); |
| 352 | } |
| 353 | |
| 354 | return layer; |
| 355 | } |
| 356 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 357 | virtual sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, |
| 358 | uint32_t flags = 0) { |
| 359 | return createLayer(mClient, name, width, height, flags); |
| 360 | } |
| 361 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 362 | ANativeWindow_Buffer getBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 363 | // wait for previous transactions (such as setSize) to complete |
| 364 | Transaction().apply(true); |
| 365 | |
| 366 | ANativeWindow_Buffer buffer = {}; |
| 367 | EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr)); |
| 368 | |
| 369 | return buffer; |
| 370 | } |
| 371 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 372 | void postBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 373 | ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost()); |
| 374 | |
| 375 | // wait for the newly posted buffer to be latched |
| 376 | waitForLayerBuffers(); |
| 377 | } |
| 378 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 379 | virtual void fillBufferQueueLayerColor(const sp<SurfaceControl>& layer, const Color& color, |
| 380 | int32_t bufferWidth, int32_t bufferHeight) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 381 | ANativeWindow_Buffer buffer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 382 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 383 | fillANativeWindowBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); |
| 384 | postBufferQueueLayerBuffer(layer); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 387 | virtual void fillBufferStateLayerColor(const sp<SurfaceControl>& layer, const Color& color, |
| 388 | int32_t bufferWidth, int32_t bufferHeight) { |
| 389 | sp<GraphicBuffer> buffer = |
| 390 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, |
| 391 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 392 | BufferUsage::COMPOSER_OVERLAY, |
| 393 | "test"); |
| 394 | fillGraphicBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); |
| 395 | Transaction().setBuffer(layer, buffer).setSize(layer, bufferWidth, bufferHeight).apply(); |
| 396 | } |
| 397 | |
| 398 | void fillLayerColor(uint32_t mLayerType, const sp<SurfaceControl>& layer, const Color& color, |
| 399 | int32_t bufferWidth, int32_t bufferHeight) { |
| 400 | switch (mLayerType) { |
| 401 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 402 | fillBufferQueueLayerColor(layer, color, bufferWidth, bufferHeight); |
| 403 | break; |
| 404 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 405 | fillBufferStateLayerColor(layer, color, bufferWidth, bufferHeight); |
| 406 | break; |
| 407 | default: |
| 408 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | void fillLayerQuadrant(uint32_t mLayerType, const sp<SurfaceControl>& layer, |
| 413 | int32_t bufferWidth, int32_t bufferHeight, const Color& topLeft, |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 414 | const Color& topRight, const Color& bottomLeft, |
| 415 | const Color& bottomRight) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 416 | switch (mLayerType) { |
| 417 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 418 | fillBufferQueueLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, |
| 419 | bottomLeft, bottomRight); |
| 420 | break; |
| 421 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 422 | fillBufferStateLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, |
| 423 | bottomLeft, bottomRight); |
| 424 | break; |
| 425 | default: |
| 426 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | virtual void fillBufferQueueLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 431 | int32_t bufferHeight, const Color& topLeft, |
| 432 | const Color& topRight, const Color& bottomLeft, |
| 433 | const Color& bottomRight) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 434 | ANativeWindow_Buffer buffer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 435 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 436 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 437 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 438 | const int32_t halfW = bufferWidth / 2; |
| 439 | const int32_t halfH = bufferHeight / 2; |
| 440 | fillANativeWindowBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); |
| 441 | fillANativeWindowBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); |
| 442 | fillANativeWindowBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); |
| 443 | fillANativeWindowBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), |
| 444 | bottomRight); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 445 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 446 | postBufferQueueLayerBuffer(layer); |
| 447 | } |
| 448 | |
| 449 | virtual void fillBufferStateLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 450 | int32_t bufferHeight, const Color& topLeft, |
| 451 | const Color& topRight, const Color& bottomLeft, |
| 452 | const Color& bottomRight) { |
| 453 | sp<GraphicBuffer> buffer = |
| 454 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, |
| 455 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 456 | BufferUsage::COMPOSER_OVERLAY, |
| 457 | "test"); |
| 458 | |
| 459 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); |
| 460 | |
| 461 | const int32_t halfW = bufferWidth / 2; |
| 462 | const int32_t halfH = bufferHeight / 2; |
| 463 | fillGraphicBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); |
| 464 | fillGraphicBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); |
| 465 | fillGraphicBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); |
| 466 | fillGraphicBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), bottomRight); |
| 467 | |
| 468 | Transaction().setBuffer(layer, buffer).setSize(layer, bufferWidth, bufferHeight).apply(); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 469 | } |
| 470 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 471 | std::unique_ptr<ScreenCapture> screenshot() { |
| 472 | std::unique_ptr<ScreenCapture> screenshot; |
| 473 | ScreenCapture::captureScreen(&screenshot); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 474 | return screenshot; |
| 475 | } |
| 476 | |
| 477 | sp<SurfaceComposerClient> mClient; |
| 478 | |
| 479 | sp<IBinder> mDisplay; |
| 480 | uint32_t mDisplayWidth; |
| 481 | uint32_t mDisplayHeight; |
| 482 | uint32_t mDisplayLayerStack; |
| 483 | |
| 484 | // leave room for ~256 layers |
| 485 | const int32_t mLayerZBase = std::numeric_limits<int32_t>::max() - 256; |
| 486 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 487 | void setPositionWithResizeHelper(uint32_t layerType); |
| 488 | void setSizeBasicHelper(uint32_t layerType); |
| 489 | void setMatrixWithResizeHelper(uint32_t layerType); |
| 490 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 491 | sp<SurfaceControl> mBlackBgSurface; |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 492 | bool mColorManagementUsed; |
| 493 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 494 | private: |
| 495 | void SetUpDisplay() { |
| 496 | mDisplay = mClient->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain); |
| 497 | ASSERT_NE(nullptr, mDisplay.get()) << "failed to get built-in display"; |
| 498 | |
| 499 | // get display width/height |
| 500 | DisplayInfo info; |
| 501 | SurfaceComposerClient::getDisplayInfo(mDisplay, &info); |
| 502 | mDisplayWidth = info.w; |
| 503 | mDisplayHeight = info.h; |
| 504 | |
| 505 | // After a new buffer is queued, SurfaceFlinger is notified and will |
| 506 | // latch the new buffer on next vsync. Let's heuristically wait for 3 |
| 507 | // vsyncs. |
| 508 | mBufferPostDelay = int32_t(1e6 / info.fps) * 3; |
| 509 | |
| 510 | mDisplayLayerStack = 0; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 511 | |
| 512 | mBlackBgSurface = mClient->createSurface(String8("BaseSurface"), mDisplayWidth, |
| 513 | mDisplayHeight, PIXEL_FORMAT_RGBA_8888, |
| 514 | ISurfaceComposerClient::eFXSurfaceColor); |
| 515 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 516 | // set layer stack (b/68888219) |
| 517 | Transaction t; |
| 518 | t.setDisplayLayerStack(mDisplay, mDisplayLayerStack); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 519 | t.setCrop_legacy(mBlackBgSurface, Rect(0, 0, mDisplayWidth, mDisplayHeight)); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 520 | t.setLayerStack(mBlackBgSurface, mDisplayLayerStack); |
| 521 | t.setColor(mBlackBgSurface, half3{0, 0, 0}); |
| 522 | t.setLayer(mBlackBgSurface, mLayerZBase); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 523 | t.apply(); |
| 524 | } |
| 525 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 526 | void waitForLayerBuffers() { |
| 527 | // Request an empty transaction to get applied synchronously to ensure the buffer is |
| 528 | // latched. |
| 529 | Transaction().apply(true); |
| 530 | usleep(mBufferPostDelay); |
| 531 | } |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 532 | |
| 533 | int32_t mBufferPostDelay; |
| 534 | }; |
| 535 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 536 | class LayerTypeTransactionTest : public LayerTransactionTest, |
| 537 | public ::testing::WithParamInterface<uint32_t> { |
| 538 | public: |
| 539 | LayerTypeTransactionTest() { mLayerType = GetParam(); } |
| 540 | |
| 541 | sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, |
| 542 | uint32_t flags = 0) override { |
| 543 | // if the flags already have a layer type specified, return an error |
| 544 | if (flags & ISurfaceComposerClient::eFXSurfaceMask) { |
| 545 | return nullptr; |
| 546 | } |
| 547 | return LayerTransactionTest::createLayer(name, width, height, flags | mLayerType); |
| 548 | } |
| 549 | |
| 550 | void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color, int32_t bufferWidth, |
| 551 | int32_t bufferHeight) { |
| 552 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerColor(mLayerType, layer, color, |
| 553 | bufferWidth, bufferHeight)); |
| 554 | } |
| 555 | |
| 556 | void fillLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 557 | int32_t bufferHeight, const Color& topLeft, const Color& topRight, |
| 558 | const Color& bottomLeft, const Color& bottomRight) { |
| 559 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerQuadrant(mLayerType, layer, |
| 560 | bufferWidth, bufferHeight, |
| 561 | topLeft, topRight, |
| 562 | bottomLeft, bottomRight)); |
| 563 | } |
| 564 | |
| 565 | protected: |
| 566 | uint32_t mLayerType; |
| 567 | }; |
| 568 | |
| 569 | INSTANTIATE_TEST_CASE_P( |
| 570 | LayerTypeTransactionTests, LayerTypeTransactionTest, |
| 571 | ::testing::Values(static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferQueue), |
| 572 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferState))); |
| 573 | |
| 574 | TEST_P(LayerTypeTransactionTest, SetPositionBasic) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 575 | sp<SurfaceControl> layer; |
| 576 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 577 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 578 | |
| 579 | { |
| 580 | SCOPED_TRACE("default position"); |
| 581 | auto shot = screenshot(); |
| 582 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 583 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 584 | } |
| 585 | |
| 586 | Transaction().setPosition(layer, 5, 10).apply(); |
| 587 | { |
| 588 | SCOPED_TRACE("new position"); |
| 589 | auto shot = screenshot(); |
| 590 | shot->expectColor(Rect(5, 10, 37, 42), Color::RED); |
| 591 | shot->expectBorder(Rect(5, 10, 37, 42), Color::BLACK); |
| 592 | } |
| 593 | } |
| 594 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 595 | TEST_P(LayerTypeTransactionTest, SetPositionRounding) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 596 | sp<SurfaceControl> layer; |
| 597 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 598 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 599 | |
| 600 | // GLES requires only 4 bits of subpixel precision during rasterization |
| 601 | // XXX GLES composition does not match HWC composition due to precision |
| 602 | // loss (b/69315223) |
| 603 | const float epsilon = 1.0f / 16.0f; |
| 604 | Transaction().setPosition(layer, 0.5f - epsilon, 0.5f - epsilon).apply(); |
| 605 | { |
| 606 | SCOPED_TRACE("rounding down"); |
| 607 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 608 | } |
| 609 | |
| 610 | Transaction().setPosition(layer, 0.5f + epsilon, 0.5f + epsilon).apply(); |
| 611 | { |
| 612 | SCOPED_TRACE("rounding up"); |
| 613 | screenshot()->expectColor(Rect(1, 1, 33, 33), Color::RED); |
| 614 | } |
| 615 | } |
| 616 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 617 | TEST_P(LayerTypeTransactionTest, SetPositionOutOfBounds) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 618 | sp<SurfaceControl> layer; |
| 619 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 620 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 621 | |
| 622 | Transaction().setPosition(layer, -32, -32).apply(); |
| 623 | { |
| 624 | SCOPED_TRACE("negative coordinates"); |
| 625 | screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
| 626 | } |
| 627 | |
| 628 | Transaction().setPosition(layer, mDisplayWidth, mDisplayHeight).apply(); |
| 629 | { |
| 630 | SCOPED_TRACE("positive coordinates"); |
| 631 | screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
| 632 | } |
| 633 | } |
| 634 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 635 | TEST_P(LayerTypeTransactionTest, SetPositionPartiallyOutOfBounds) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 636 | sp<SurfaceControl> layer; |
| 637 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 638 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 639 | |
| 640 | // partially out of bounds |
| 641 | Transaction().setPosition(layer, -30, -30).apply(); |
| 642 | { |
| 643 | SCOPED_TRACE("negative coordinates"); |
| 644 | screenshot()->expectColor(Rect(0, 0, 2, 2), Color::RED); |
| 645 | } |
| 646 | |
| 647 | Transaction().setPosition(layer, mDisplayWidth - 2, mDisplayHeight - 2).apply(); |
| 648 | { |
| 649 | SCOPED_TRACE("positive coordinates"); |
| 650 | screenshot()->expectColor(Rect(mDisplayWidth - 2, mDisplayHeight - 2, mDisplayWidth, |
| 651 | mDisplayHeight), |
| 652 | Color::RED); |
| 653 | } |
| 654 | } |
| 655 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 656 | void LayerTransactionTest::setPositionWithResizeHelper(uint32_t layerType) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 657 | sp<SurfaceControl> layer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 658 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32, layerType)); |
| 659 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 660 | |
| 661 | // setPosition is applied immediately by default, with or without resize |
| 662 | // pending |
| 663 | Transaction().setPosition(layer, 5, 10).setSize(layer, 64, 64).apply(); |
| 664 | { |
| 665 | SCOPED_TRACE("resize pending"); |
| 666 | auto shot = screenshot(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 667 | Rect rect; |
| 668 | switch (layerType) { |
| 669 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 670 | rect = {5, 10, 37, 42}; |
| 671 | break; |
| 672 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 673 | rect = {5, 10, 69, 74}; |
| 674 | break; |
| 675 | default: |
| 676 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 677 | } |
| 678 | |
| 679 | shot->expectColor(rect, Color::RED); |
| 680 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 683 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer, Color::RED, 64, 64)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 684 | { |
| 685 | SCOPED_TRACE("resize applied"); |
| 686 | screenshot()->expectColor(Rect(5, 10, 69, 74), Color::RED); |
| 687 | } |
| 688 | } |
| 689 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 690 | TEST_F(LayerTransactionTest, SetPositionWithResize_BufferQueue) { |
| 691 | ASSERT_NO_FATAL_FAILURE( |
| 692 | setPositionWithResizeHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); |
| 693 | } |
| 694 | |
| 695 | TEST_F(LayerTransactionTest, SetPositionWithResize_BufferState) { |
| 696 | ASSERT_NO_FATAL_FAILURE( |
| 697 | setPositionWithResizeHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 698 | } |
| 699 | |
| 700 | TEST_F(LayerTransactionTest, SetPositionWithNextResize_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 701 | sp<SurfaceControl> layer; |
| 702 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 703 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 704 | |
| 705 | // request setPosition to be applied with the next resize |
| 706 | Transaction().setPosition(layer, 5, 10).setGeometryAppliesWithResize(layer).apply(); |
| 707 | { |
| 708 | SCOPED_TRACE("new position pending"); |
| 709 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 710 | } |
| 711 | |
| 712 | Transaction().setPosition(layer, 15, 20).apply(); |
| 713 | { |
| 714 | SCOPED_TRACE("pending new position modified"); |
| 715 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 716 | } |
| 717 | |
| 718 | Transaction().setSize(layer, 64, 64).apply(); |
| 719 | { |
| 720 | SCOPED_TRACE("resize pending"); |
| 721 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 722 | } |
| 723 | |
| 724 | // finally resize and latch the buffer |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 725 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 726 | { |
| 727 | SCOPED_TRACE("new position applied"); |
| 728 | screenshot()->expectColor(Rect(15, 20, 79, 84), Color::RED); |
| 729 | } |
| 730 | } |
| 731 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 732 | TEST_F(LayerTransactionTest, SetPositionWithNextResizeScaleToWindow_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 733 | sp<SurfaceControl> layer; |
| 734 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 735 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 736 | |
| 737 | // setPosition is not immediate even with SCALE_TO_WINDOW override |
| 738 | Transaction() |
| 739 | .setPosition(layer, 5, 10) |
| 740 | .setSize(layer, 64, 64) |
| 741 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 742 | .setGeometryAppliesWithResize(layer) |
| 743 | .apply(); |
| 744 | { |
| 745 | SCOPED_TRACE("new position pending"); |
| 746 | screenshot()->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 747 | } |
| 748 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 749 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 750 | { |
| 751 | SCOPED_TRACE("new position applied"); |
| 752 | screenshot()->expectColor(Rect(5, 10, 69, 74), Color::RED); |
| 753 | } |
| 754 | } |
| 755 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 756 | void LayerTransactionTest::setSizeBasicHelper(uint32_t layerType) { |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 757 | sp<SurfaceControl> layer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 758 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32, layerType)); |
| 759 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer, Color::RED, 32, 32)); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 760 | |
| 761 | Transaction().setSize(layer, 64, 64).apply(); |
| 762 | { |
| 763 | SCOPED_TRACE("resize pending"); |
| 764 | auto shot = screenshot(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 765 | Rect rect; |
| 766 | switch (layerType) { |
| 767 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 768 | rect = {0, 0, 32, 32}; |
| 769 | break; |
| 770 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 771 | rect = {0, 0, 64, 64}; |
| 772 | break; |
| 773 | default: |
| 774 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 775 | } |
| 776 | shot->expectColor(rect, Color::RED); |
| 777 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 780 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer, Color::RED, 64, 64)); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 781 | { |
| 782 | SCOPED_TRACE("resize applied"); |
| 783 | auto shot = screenshot(); |
| 784 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 785 | shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK); |
| 786 | } |
| 787 | } |
| 788 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 789 | TEST_F(LayerTransactionTest, SetSizeBasic_BufferQueue) { |
| 790 | setSizeBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue); |
| 791 | } |
| 792 | |
| 793 | TEST_F(LayerTransactionTest, SetSizeBasic_BufferState) { |
| 794 | setSizeBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferState); |
| 795 | } |
| 796 | |
| 797 | TEST_P(LayerTypeTransactionTest, SetSizeInvalid) { |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 798 | // cannot test robustness against invalid sizes (zero or really huge) |
| 799 | } |
| 800 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 801 | TEST_P(LayerTypeTransactionTest, SetSizeWithScaleToWindow) { |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 802 | sp<SurfaceControl> layer; |
| 803 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 804 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 805 | |
| 806 | // setSize is immediate with SCALE_TO_WINDOW, unlike setPosition |
| 807 | Transaction() |
| 808 | .setSize(layer, 64, 64) |
| 809 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 810 | .apply(); |
| 811 | screenshot()->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 812 | } |
| 813 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 814 | TEST_P(LayerTypeTransactionTest, SetZBasic) { |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 815 | sp<SurfaceControl> layerR; |
| 816 | sp<SurfaceControl> layerG; |
| 817 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 818 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 819 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 820 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 821 | |
| 822 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); |
| 823 | { |
| 824 | SCOPED_TRACE("layerR"); |
| 825 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 826 | } |
| 827 | |
| 828 | Transaction().setLayer(layerG, mLayerZBase + 2).apply(); |
| 829 | { |
| 830 | SCOPED_TRACE("layerG"); |
| 831 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::GREEN); |
| 832 | } |
| 833 | } |
| 834 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 835 | TEST_P(LayerTypeTransactionTest, SetZNegative) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 836 | sp<SurfaceControl> parent = |
| 837 | LayerTransactionTest::createLayer("Parent", mDisplayWidth, mDisplayHeight, |
| 838 | ISurfaceComposerClient::eFXSurfaceContainer); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 839 | sp<SurfaceControl> layerR; |
| 840 | sp<SurfaceControl> layerG; |
| 841 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 842 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 843 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 844 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 845 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 846 | Transaction() |
| 847 | .reparent(layerR, parent->getHandle()) |
| 848 | .reparent(layerG, parent->getHandle()) |
| 849 | .apply(); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 850 | Transaction().setLayer(layerR, -1).setLayer(layerG, -2).apply(); |
| 851 | { |
| 852 | SCOPED_TRACE("layerR"); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 853 | auto shot = screenshot(); |
| 854 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | Transaction().setLayer(layerR, -3).apply(); |
| 858 | { |
| 859 | SCOPED_TRACE("layerG"); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 860 | auto shot = screenshot(); |
| 861 | shot->expectColor(Rect(0, 0, 32, 32), Color::GREEN); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 865 | TEST_P(LayerTypeTransactionTest, SetRelativeZBasic) { |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 866 | sp<SurfaceControl> layerR; |
| 867 | sp<SurfaceControl> layerG; |
| 868 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 869 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 870 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 871 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 872 | |
| 873 | Transaction() |
| 874 | .setPosition(layerG, 16, 16) |
| 875 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 876 | .apply(); |
| 877 | { |
| 878 | SCOPED_TRACE("layerG above"); |
| 879 | auto shot = screenshot(); |
| 880 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 881 | shot->expectColor(Rect(16, 16, 48, 48), Color::GREEN); |
| 882 | } |
| 883 | |
| 884 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).apply(); |
| 885 | { |
| 886 | SCOPED_TRACE("layerG below"); |
| 887 | auto shot = screenshot(); |
| 888 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 889 | shot->expectColor(Rect(32, 32, 48, 48), Color::GREEN); |
| 890 | } |
| 891 | } |
| 892 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 893 | TEST_P(LayerTypeTransactionTest, SetRelativeZNegative) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 894 | sp<SurfaceControl> parent = |
| 895 | LayerTransactionTest::createLayer("Parent", mDisplayWidth, mDisplayHeight, |
| 896 | ISurfaceComposerClient::eFXSurfaceContainer); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 897 | sp<SurfaceControl> layerR; |
| 898 | sp<SurfaceControl> layerG; |
| 899 | sp<SurfaceControl> layerB; |
| 900 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 901 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 902 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 903 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 904 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 905 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 906 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 907 | Transaction() |
| 908 | .reparent(layerB, parent->getHandle()) |
| 909 | .apply(); |
| 910 | |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 911 | // layerR = mLayerZBase, layerG = layerR - 1, layerB = -2 |
| 912 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).setLayer(layerB, -2).apply(); |
| 913 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 914 | std::unique_ptr<ScreenCapture> screenshot; |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 915 | // only layerB is in this range |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 916 | sp<IBinder> parentHandle = parent->getHandle(); |
| 917 | ScreenCapture::captureLayers(&screenshot, parentHandle); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 918 | screenshot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 919 | } |
| 920 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 921 | TEST_P(LayerTypeTransactionTest, SetRelativeZGroup) { |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 922 | sp<SurfaceControl> layerR; |
| 923 | sp<SurfaceControl> layerG; |
| 924 | sp<SurfaceControl> layerB; |
| 925 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 926 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 927 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 928 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 929 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 930 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 931 | |
| 932 | // layerR = 0, layerG = layerR + 3, layerB = 2 |
| 933 | Transaction() |
| 934 | .setPosition(layerG, 8, 8) |
| 935 | .setRelativeLayer(layerG, layerR->getHandle(), 3) |
| 936 | .setPosition(layerB, 16, 16) |
| 937 | .setLayer(layerB, mLayerZBase + 2) |
| 938 | .apply(); |
| 939 | { |
| 940 | SCOPED_TRACE("(layerR < layerG) < layerB"); |
| 941 | auto shot = screenshot(); |
| 942 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); |
| 943 | shot->expectColor(Rect(8, 8, 16, 16), Color::GREEN); |
| 944 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); |
| 945 | } |
| 946 | |
| 947 | // layerR = 4, layerG = layerR + 3, layerB = 2 |
| 948 | Transaction().setLayer(layerR, mLayerZBase + 4).apply(); |
| 949 | { |
| 950 | SCOPED_TRACE("layerB < (layerR < layerG)"); |
| 951 | auto shot = screenshot(); |
| 952 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); |
| 953 | shot->expectColor(Rect(8, 8, 40, 40), Color::GREEN); |
| 954 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); |
| 955 | } |
| 956 | |
| 957 | // layerR = 4, layerG = layerR - 3, layerB = 2 |
| 958 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -3).apply(); |
| 959 | { |
| 960 | SCOPED_TRACE("layerB < (layerG < layerR)"); |
| 961 | auto shot = screenshot(); |
| 962 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 963 | shot->expectColor(Rect(32, 32, 40, 40), Color::GREEN); |
| 964 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); |
| 965 | } |
| 966 | |
| 967 | // restore to absolute z |
| 968 | // layerR = 4, layerG = 0, layerB = 2 |
| 969 | Transaction().setLayer(layerG, mLayerZBase).apply(); |
| 970 | { |
| 971 | SCOPED_TRACE("layerG < layerB < layerR"); |
| 972 | auto shot = screenshot(); |
| 973 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 974 | shot->expectColor(Rect(32, 32, 48, 48), Color::BLUE); |
| 975 | } |
| 976 | |
| 977 | // layerR should not affect layerG anymore |
| 978 | // layerR = 1, layerG = 0, layerB = 2 |
| 979 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); |
| 980 | { |
| 981 | SCOPED_TRACE("layerG < layerR < layerB"); |
| 982 | auto shot = screenshot(); |
| 983 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 984 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); |
| 985 | } |
| 986 | } |
| 987 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 988 | TEST_P(LayerTypeTransactionTest, SetRelativeZBug64572777) { |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 989 | sp<SurfaceControl> layerR; |
| 990 | sp<SurfaceControl> layerG; |
| 991 | |
| 992 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 993 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 994 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 995 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 996 | |
| 997 | Transaction() |
| 998 | .setPosition(layerG, 16, 16) |
| 999 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 1000 | .apply(); |
| 1001 | |
| 1002 | mClient->destroySurface(layerG->getHandle()); |
| 1003 | // layerG should have been removed |
| 1004 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1005 | } |
| 1006 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1007 | TEST_P(LayerTypeTransactionTest, SetFlagsHidden) { |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1008 | sp<SurfaceControl> layer; |
| 1009 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1010 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1011 | |
| 1012 | Transaction().setFlags(layer, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden).apply(); |
| 1013 | { |
| 1014 | SCOPED_TRACE("layer hidden"); |
| 1015 | screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
| 1016 | } |
| 1017 | |
| 1018 | Transaction().setFlags(layer, 0, layer_state_t::eLayerHidden).apply(); |
| 1019 | { |
| 1020 | SCOPED_TRACE("layer shown"); |
| 1021 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1022 | } |
| 1023 | } |
| 1024 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1025 | TEST_P(LayerTypeTransactionTest, SetFlagsOpaque) { |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1026 | const Color translucentRed = {100, 0, 0, 100}; |
| 1027 | sp<SurfaceControl> layerR; |
| 1028 | sp<SurfaceControl> layerG; |
| 1029 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1030 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, translucentRed, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1031 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1032 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1033 | |
| 1034 | Transaction() |
| 1035 | .setLayer(layerR, mLayerZBase + 1) |
| 1036 | .setFlags(layerR, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque) |
| 1037 | .apply(); |
| 1038 | { |
| 1039 | SCOPED_TRACE("layerR opaque"); |
| 1040 | screenshot()->expectColor(Rect(0, 0, 32, 32), {100, 0, 0, 255}); |
| 1041 | } |
| 1042 | |
| 1043 | Transaction().setFlags(layerR, 0, layer_state_t::eLayerOpaque).apply(); |
| 1044 | { |
| 1045 | SCOPED_TRACE("layerR translucent"); |
| 1046 | const uint8_t g = uint8_t(255 - translucentRed.a); |
| 1047 | screenshot()->expectColor(Rect(0, 0, 32, 32), {100, g, 0, 255}); |
| 1048 | } |
| 1049 | } |
| 1050 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1051 | TEST_P(LayerTypeTransactionTest, SetFlagsSecure) { |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1052 | sp<SurfaceControl> layer; |
| 1053 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1054 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1055 | |
| 1056 | sp<ISurfaceComposer> composer = ComposerService::getComposerService(); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 1057 | sp<GraphicBuffer> outBuffer; |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1058 | Transaction() |
| 1059 | .setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure) |
| 1060 | .apply(true); |
| 1061 | ASSERT_EQ(PERMISSION_DENIED, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1062 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1063 | |
| 1064 | Transaction().setFlags(layer, 0, layer_state_t::eLayerSecure).apply(true); |
| 1065 | ASSERT_EQ(NO_ERROR, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1066 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1069 | TEST_F(LayerTransactionTest, SetTransparentRegionHintBasic_BufferQueue) { |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1070 | const Rect top(0, 0, 32, 16); |
| 1071 | const Rect bottom(0, 16, 32, 32); |
| 1072 | sp<SurfaceControl> layer; |
| 1073 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1074 | |
| 1075 | ANativeWindow_Buffer buffer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1076 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 1077 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::TRANSPARENT)); |
| 1078 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::RED)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1079 | // setTransparentRegionHint always applies to the following buffer |
| 1080 | Transaction().setTransparentRegionHint(layer, Region(top)).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1081 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1082 | { |
| 1083 | SCOPED_TRACE("top transparent"); |
| 1084 | auto shot = screenshot(); |
| 1085 | shot->expectColor(top, Color::BLACK); |
| 1086 | shot->expectColor(bottom, Color::RED); |
| 1087 | } |
| 1088 | |
| 1089 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); |
| 1090 | { |
| 1091 | SCOPED_TRACE("transparent region hint pending"); |
| 1092 | auto shot = screenshot(); |
| 1093 | shot->expectColor(top, Color::BLACK); |
| 1094 | shot->expectColor(bottom, Color::RED); |
| 1095 | } |
| 1096 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1097 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 1098 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::RED)); |
| 1099 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::TRANSPARENT)); |
| 1100 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1101 | { |
| 1102 | SCOPED_TRACE("bottom transparent"); |
| 1103 | auto shot = screenshot(); |
| 1104 | shot->expectColor(top, Color::RED); |
| 1105 | shot->expectColor(bottom, Color::BLACK); |
| 1106 | } |
| 1107 | } |
| 1108 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1109 | TEST_F(LayerTransactionTest, SetTransparentRegionHintBasic_BufferState) { |
| 1110 | const Rect top(0, 0, 32, 16); |
| 1111 | const Rect bottom(0, 16, 32, 32); |
| 1112 | sp<SurfaceControl> layer; |
| 1113 | ASSERT_NO_FATAL_FAILURE( |
| 1114 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1115 | |
| 1116 | sp<GraphicBuffer> buffer = |
| 1117 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 1118 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 1119 | BufferUsage::COMPOSER_OVERLAY, |
| 1120 | "test"); |
| 1121 | |
| 1122 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::TRANSPARENT)); |
| 1123 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::RED)); |
| 1124 | Transaction() |
| 1125 | .setTransparentRegionHint(layer, Region(top)) |
| 1126 | .setBuffer(layer, buffer) |
| 1127 | .setSize(layer, 32, 32) |
| 1128 | .apply(); |
| 1129 | { |
| 1130 | SCOPED_TRACE("top transparent"); |
| 1131 | auto shot = screenshot(); |
| 1132 | shot->expectColor(top, Color::BLACK); |
| 1133 | shot->expectColor(bottom, Color::RED); |
| 1134 | } |
| 1135 | |
| 1136 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); |
| 1137 | { |
| 1138 | SCOPED_TRACE("transparent region hint intermediate"); |
| 1139 | auto shot = screenshot(); |
| 1140 | shot->expectColor(top, Color::BLACK); |
| 1141 | shot->expectColor(bottom, Color::BLACK); |
| 1142 | } |
| 1143 | |
| 1144 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 1145 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 1146 | BufferUsage::COMPOSER_OVERLAY, |
| 1147 | "test"); |
| 1148 | |
| 1149 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::RED)); |
| 1150 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::TRANSPARENT)); |
| 1151 | Transaction().setBuffer(layer, buffer).setSize(layer, 32, 32).apply(); |
| 1152 | { |
| 1153 | SCOPED_TRACE("bottom transparent"); |
| 1154 | auto shot = screenshot(); |
| 1155 | shot->expectColor(top, Color::RED); |
| 1156 | shot->expectColor(bottom, Color::BLACK); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | TEST_P(LayerTypeTransactionTest, SetTransparentRegionHintOutOfBounds) { |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1161 | sp<SurfaceControl> layerTransparent; |
| 1162 | sp<SurfaceControl> layerR; |
| 1163 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); |
| 1164 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 1165 | |
| 1166 | // check that transparent region hint is bound by the layer size |
| 1167 | Transaction() |
| 1168 | .setTransparentRegionHint(layerTransparent, |
| 1169 | Region(Rect(0, 0, mDisplayWidth, mDisplayHeight))) |
| 1170 | .setPosition(layerR, 16, 16) |
| 1171 | .setLayer(layerR, mLayerZBase + 1) |
| 1172 | .apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1173 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerTransparent, Color::TRANSPARENT, 32, 32)); |
| 1174 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1175 | screenshot()->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 1176 | } |
| 1177 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1178 | TEST_P(LayerTypeTransactionTest, SetAlphaBasic) { |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1179 | sp<SurfaceControl> layer1; |
| 1180 | sp<SurfaceControl> layer2; |
| 1181 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer("test 1", 32, 32)); |
| 1182 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer("test 2", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1183 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer1, {64, 0, 0, 255}, 32, 32)); |
| 1184 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer2, {0, 64, 0, 255}, 32, 32)); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1185 | |
| 1186 | Transaction() |
| 1187 | .setAlpha(layer1, 0.25f) |
| 1188 | .setAlpha(layer2, 0.75f) |
| 1189 | .setPosition(layer2, 16, 0) |
| 1190 | .setLayer(layer2, mLayerZBase + 1) |
| 1191 | .apply(); |
| 1192 | { |
| 1193 | auto shot = screenshot(); |
| 1194 | uint8_t r = 16; // 64 * 0.25f |
| 1195 | uint8_t g = 48; // 64 * 0.75f |
| 1196 | shot->expectColor(Rect(0, 0, 16, 32), {r, 0, 0, 255}); |
| 1197 | shot->expectColor(Rect(32, 0, 48, 32), {0, g, 0, 255}); |
| 1198 | |
| 1199 | r /= 4; // r * (1.0f - 0.75f) |
| 1200 | shot->expectColor(Rect(16, 0, 32, 32), {r, g, 0, 255}); |
| 1201 | } |
| 1202 | } |
| 1203 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1204 | TEST_P(LayerTypeTransactionTest, SetAlphaClamped) { |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1205 | const Color color = {64, 0, 0, 255}; |
| 1206 | sp<SurfaceControl> layer; |
| 1207 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1208 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, color, 32, 32)); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1209 | |
| 1210 | Transaction().setAlpha(layer, 2.0f).apply(); |
| 1211 | { |
| 1212 | SCOPED_TRACE("clamped to 1.0f"); |
| 1213 | screenshot()->expectColor(Rect(0, 0, 32, 32), color); |
| 1214 | } |
| 1215 | |
| 1216 | Transaction().setAlpha(layer, -1.0f).apply(); |
| 1217 | { |
| 1218 | SCOPED_TRACE("clamped to 0.0f"); |
| 1219 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
| 1220 | } |
| 1221 | } |
| 1222 | |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1223 | TEST_F(LayerTransactionTest, SetColorBasic) { |
| 1224 | sp<SurfaceControl> bufferLayer; |
| 1225 | sp<SurfaceControl> colorLayer; |
| 1226 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1227 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1228 | ASSERT_NO_FATAL_FAILURE( |
| 1229 | colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor)); |
| 1230 | |
| 1231 | Transaction().setLayer(colorLayer, mLayerZBase + 1).apply(); |
| 1232 | { |
| 1233 | SCOPED_TRACE("default color"); |
| 1234 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
| 1235 | } |
| 1236 | |
| 1237 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1238 | const Color expected = {15, 51, 85, 255}; |
| 1239 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 1240 | // channel) should be less than one |
| 1241 | const uint8_t tolerance = 1; |
| 1242 | Transaction().setColor(colorLayer, color).apply(); |
| 1243 | { |
| 1244 | SCOPED_TRACE("new color"); |
| 1245 | screenshot()->expectColor(Rect(0, 0, 32, 32), expected, tolerance); |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | TEST_F(LayerTransactionTest, SetColorClamped) { |
| 1250 | sp<SurfaceControl> colorLayer; |
| 1251 | ASSERT_NO_FATAL_FAILURE( |
| 1252 | colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor)); |
| 1253 | |
| 1254 | Transaction().setColor(colorLayer, half3(2.0f, -1.0f, 0.0f)).apply(); |
| 1255 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1256 | } |
| 1257 | |
| 1258 | TEST_F(LayerTransactionTest, SetColorWithAlpha) { |
| 1259 | sp<SurfaceControl> bufferLayer; |
| 1260 | sp<SurfaceControl> colorLayer; |
| 1261 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1262 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1263 | ASSERT_NO_FATAL_FAILURE( |
| 1264 | colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor)); |
| 1265 | |
| 1266 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1267 | const float alpha = 0.25f; |
| 1268 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); |
| 1269 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 1270 | // channel) should be less than one |
| 1271 | const uint8_t tolerance = 1; |
| 1272 | Transaction() |
| 1273 | .setColor(colorLayer, color) |
| 1274 | .setAlpha(colorLayer, alpha) |
| 1275 | .setLayer(colorLayer, mLayerZBase + 1) |
| 1276 | .apply(); |
| 1277 | screenshot()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, |
| 1278 | tolerance); |
| 1279 | } |
| 1280 | |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1281 | TEST_F(LayerTransactionTest, SetColorWithParentAlpha_Bug74220420) { |
| 1282 | sp<SurfaceControl> bufferLayer; |
| 1283 | sp<SurfaceControl> parentLayer; |
| 1284 | sp<SurfaceControl> colorLayer; |
| 1285 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
| 1286 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parentWithAlpha", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1287 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1288 | ASSERT_NO_FATAL_FAILURE(colorLayer = createLayer( |
| 1289 | "childWithColor", 32, 32, ISurfaceComposerClient::eFXSurfaceColor)); |
| 1290 | |
| 1291 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1292 | const float alpha = 0.25f; |
| 1293 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); |
| 1294 | // this is handwavy, but the precision loss scaled by 255 (8-bit per |
| 1295 | // channel) should be less than one |
| 1296 | const uint8_t tolerance = 1; |
| 1297 | Transaction() |
| 1298 | .reparent(colorLayer, parentLayer->getHandle()) |
| 1299 | .setColor(colorLayer, color) |
| 1300 | .setAlpha(parentLayer, alpha) |
| 1301 | .setLayer(parentLayer, mLayerZBase + 1) |
| 1302 | .apply(); |
| 1303 | screenshot()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, |
| 1304 | tolerance); |
| 1305 | } |
| 1306 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1307 | TEST_P(LayerTypeTransactionTest, SetColorWithBuffer) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1308 | sp<SurfaceControl> bufferLayer; |
| 1309 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1310 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED, 32, 32)); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1311 | |
| 1312 | // color is ignored |
| 1313 | Transaction().setColor(bufferLayer, half3(0.0f, 1.0f, 0.0f)).apply(); |
| 1314 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1315 | } |
| 1316 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1317 | TEST_P(LayerTypeTransactionTest, SetLayerStackBasic) { |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1318 | sp<SurfaceControl> layer; |
| 1319 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1320 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1321 | |
| 1322 | Transaction().setLayerStack(layer, mDisplayLayerStack + 1).apply(); |
| 1323 | { |
| 1324 | SCOPED_TRACE("non-existing layer stack"); |
| 1325 | screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
| 1326 | } |
| 1327 | |
| 1328 | Transaction().setLayerStack(layer, mDisplayLayerStack).apply(); |
| 1329 | { |
| 1330 | SCOPED_TRACE("original layer stack"); |
| 1331 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1332 | } |
| 1333 | } |
| 1334 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1335 | TEST_P(LayerTypeTransactionTest, SetMatrixBasic) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1336 | sp<SurfaceControl> layer; |
| 1337 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1338 | ASSERT_NO_FATAL_FAILURE( |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1339 | fillLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, Color::BLUE, Color::WHITE)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1340 | |
| 1341 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 0, 0).apply(); |
| 1342 | { |
| 1343 | SCOPED_TRACE("IDENTITY"); |
| 1344 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, Color::BLUE, |
| 1345 | Color::WHITE); |
| 1346 | } |
| 1347 | |
| 1348 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 32, 0).apply(); |
| 1349 | { |
| 1350 | SCOPED_TRACE("FLIP_H"); |
| 1351 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE, |
| 1352 | Color::BLUE); |
| 1353 | } |
| 1354 | |
| 1355 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).setPosition(layer, 0, 32).apply(); |
| 1356 | { |
| 1357 | SCOPED_TRACE("FLIP_V"); |
| 1358 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED, |
| 1359 | Color::GREEN); |
| 1360 | } |
| 1361 | |
| 1362 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).setPosition(layer, 32, 0).apply(); |
| 1363 | { |
| 1364 | SCOPED_TRACE("ROT_90"); |
| 1365 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE, |
| 1366 | Color::GREEN); |
| 1367 | } |
| 1368 | |
| 1369 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setPosition(layer, 0, 0).apply(); |
| 1370 | { |
| 1371 | SCOPED_TRACE("SCALE"); |
| 1372 | screenshot()->expectQuadrant(Rect(0, 0, 64, 64), Color::RED, Color::GREEN, Color::BLUE, |
| 1373 | Color::WHITE, true /* filtered */); |
| 1374 | } |
| 1375 | } |
| 1376 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1377 | TEST_P(LayerTypeTransactionTest, SetMatrixRot45) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1378 | sp<SurfaceControl> layer; |
| 1379 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1380 | ASSERT_NO_FATAL_FAILURE( |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1381 | fillLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, Color::BLUE, Color::WHITE)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1382 | |
| 1383 | const float rot = M_SQRT1_2; // 45 degrees |
| 1384 | const float trans = M_SQRT2 * 16.0f; |
| 1385 | Transaction().setMatrix(layer, rot, rot, -rot, rot).setPosition(layer, trans, 0).apply(); |
| 1386 | |
| 1387 | auto shot = screenshot(); |
| 1388 | // check a 8x8 region inside each color |
| 1389 | auto get8x8Rect = [](int32_t centerX, int32_t centerY) { |
| 1390 | const int32_t halfL = 4; |
| 1391 | return Rect(centerX - halfL, centerY - halfL, centerX + halfL, centerY + halfL); |
| 1392 | }; |
| 1393 | const int32_t unit = int32_t(trans / 2); |
| 1394 | shot->expectColor(get8x8Rect(2 * unit, 1 * unit), Color::RED); |
| 1395 | shot->expectColor(get8x8Rect(3 * unit, 2 * unit), Color::GREEN); |
| 1396 | shot->expectColor(get8x8Rect(1 * unit, 2 * unit), Color::BLUE); |
| 1397 | shot->expectColor(get8x8Rect(2 * unit, 3 * unit), Color::WHITE); |
| 1398 | } |
| 1399 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1400 | void LayerTransactionTest::setMatrixWithResizeHelper(uint32_t layerType) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1401 | sp<SurfaceControl> layer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1402 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32, layerType)); |
| 1403 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer, Color::RED, 32, 32)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1404 | |
| 1405 | // setMatrix is applied after any pending resize, unlike setPosition |
| 1406 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setSize(layer, 64, 64).apply(); |
| 1407 | { |
| 1408 | SCOPED_TRACE("resize pending"); |
| 1409 | auto shot = screenshot(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1410 | Rect rect; |
| 1411 | switch (layerType) { |
| 1412 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 1413 | rect = {0, 0, 32, 32}; |
| 1414 | break; |
| 1415 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 1416 | rect = {0, 0, 128, 128}; |
| 1417 | break; |
| 1418 | default: |
| 1419 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 1420 | } |
| 1421 | shot->expectColor(rect, Color::RED); |
| 1422 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1425 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer, Color::RED, 64, 64)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1426 | { |
| 1427 | SCOPED_TRACE("resize applied"); |
| 1428 | screenshot()->expectColor(Rect(0, 0, 128, 128), Color::RED); |
| 1429 | } |
| 1430 | } |
| 1431 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1432 | TEST_F(LayerTransactionTest, SetMatrixWithResize_BufferQueue) { |
| 1433 | ASSERT_NO_FATAL_FAILURE( |
| 1434 | setMatrixWithResizeHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); |
| 1435 | } |
| 1436 | |
| 1437 | TEST_F(LayerTransactionTest, SetMatrixWithResize_BufferState) { |
| 1438 | ASSERT_NO_FATAL_FAILURE( |
| 1439 | setMatrixWithResizeHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1440 | } |
| 1441 | |
| 1442 | TEST_P(LayerTypeTransactionTest, SetMatrixWithScaleToWindow) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1443 | sp<SurfaceControl> layer; |
| 1444 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1445 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1446 | |
| 1447 | // setMatrix is immediate with SCALE_TO_WINDOW, unlike setPosition |
| 1448 | Transaction() |
| 1449 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
| 1450 | .setSize(layer, 64, 64) |
| 1451 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1452 | .apply(); |
| 1453 | screenshot()->expectColor(Rect(0, 0, 128, 128), Color::RED); |
| 1454 | } |
| 1455 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1456 | TEST_P(LayerTypeTransactionTest, SetOverrideScalingModeBasic) { |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1457 | sp<SurfaceControl> layer; |
| 1458 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1459 | ASSERT_NO_FATAL_FAILURE( |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1460 | fillLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, Color::BLUE, Color::WHITE)); |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1461 | |
| 1462 | // XXX SCALE_CROP is not respected; calling setSize and |
| 1463 | // setOverrideScalingMode in separate transactions does not work |
| 1464 | // (b/69315456) |
| 1465 | Transaction() |
| 1466 | .setSize(layer, 64, 16) |
| 1467 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1468 | .apply(); |
| 1469 | { |
| 1470 | SCOPED_TRACE("SCALE_TO_WINDOW"); |
| 1471 | screenshot()->expectQuadrant(Rect(0, 0, 64, 16), Color::RED, Color::GREEN, Color::BLUE, |
| 1472 | Color::WHITE, true /* filtered */); |
| 1473 | } |
| 1474 | } |
| 1475 | |
Dan Stoza | 000dd01 | 2018-08-01 13:31:52 -0700 | [diff] [blame] | 1476 | TEST_P(LayerTypeTransactionTest, RefreshRateIsInitialized) { |
| 1477 | sp<SurfaceControl> layer; |
| 1478 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1479 | |
| 1480 | sp<IBinder> handle = layer->getHandle(); |
| 1481 | ASSERT_TRUE(handle != nullptr); |
| 1482 | |
| 1483 | FrameStats frameStats; |
| 1484 | mClient->getLayerFrameStats(handle, &frameStats); |
| 1485 | |
| 1486 | ASSERT_GT(frameStats.refreshPeriodNano, static_cast<nsecs_t>(0)); |
| 1487 | } |
| 1488 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1489 | TEST_F(LayerTransactionTest, SetCropBasic_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1490 | sp<SurfaceControl> layer; |
| 1491 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1492 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1493 | const Rect crop(8, 8, 24, 24); |
| 1494 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1495 | Transaction().setCrop_legacy(layer, crop).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1496 | auto shot = screenshot(); |
| 1497 | shot->expectColor(crop, Color::RED); |
| 1498 | shot->expectBorder(crop, Color::BLACK); |
| 1499 | } |
| 1500 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1501 | TEST_F(LayerTransactionTest, SetCropBasic_BufferState) { |
| 1502 | sp<SurfaceControl> layer; |
| 1503 | ASSERT_NO_FATAL_FAILURE( |
| 1504 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1505 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1506 | const Rect crop(8, 8, 24, 24); |
| 1507 | |
| 1508 | Transaction().setCrop(layer, crop).apply(); |
| 1509 | auto shot = screenshot(); |
| 1510 | shot->expectColor(crop, Color::RED); |
| 1511 | shot->expectBorder(crop, Color::BLACK); |
| 1512 | } |
| 1513 | |
| 1514 | TEST_F(LayerTransactionTest, SetCropEmpty_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1515 | sp<SurfaceControl> layer; |
| 1516 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1517 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1518 | |
| 1519 | { |
| 1520 | SCOPED_TRACE("empty rect"); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1521 | Transaction().setCrop_legacy(layer, Rect(8, 8, 8, 8)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1522 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1523 | } |
| 1524 | |
| 1525 | { |
| 1526 | SCOPED_TRACE("negative rect"); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1527 | Transaction().setCrop_legacy(layer, Rect(8, 8, 0, 0)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1528 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1529 | } |
| 1530 | } |
| 1531 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1532 | TEST_F(LayerTransactionTest, SetCropEmpty_BufferState) { |
| 1533 | sp<SurfaceControl> layer; |
| 1534 | ASSERT_NO_FATAL_FAILURE( |
| 1535 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1536 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1537 | |
| 1538 | { |
| 1539 | SCOPED_TRACE("empty rect"); |
| 1540 | Transaction().setCrop(layer, Rect(8, 8, 8, 8)).apply(); |
| 1541 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1542 | } |
| 1543 | |
| 1544 | { |
| 1545 | SCOPED_TRACE("negative rect"); |
| 1546 | Transaction().setCrop(layer, Rect(8, 8, 0, 0)).apply(); |
| 1547 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | TEST_F(LayerTransactionTest, SetCropOutOfBounds_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1552 | sp<SurfaceControl> layer; |
| 1553 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1554 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1555 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1556 | Transaction().setCrop_legacy(layer, Rect(-128, -64, 128, 64)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1557 | auto shot = screenshot(); |
| 1558 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1559 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1560 | } |
| 1561 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1562 | TEST_F(LayerTransactionTest, SetCropOutOfBounds_BufferState) { |
| 1563 | sp<SurfaceControl> layer; |
| 1564 | ASSERT_NO_FATAL_FAILURE( |
| 1565 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1566 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1567 | |
| 1568 | Transaction().setCrop(layer, Rect(-128, -64, 128, 64)).apply(); |
| 1569 | auto shot = screenshot(); |
| 1570 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1571 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1572 | } |
| 1573 | |
| 1574 | TEST_F(LayerTransactionTest, SetCropWithTranslation_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1575 | sp<SurfaceControl> layer; |
| 1576 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1577 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1578 | |
| 1579 | const Point position(32, 32); |
| 1580 | const Rect crop(8, 8, 24, 24); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1581 | Transaction().setPosition(layer, position.x, position.y).setCrop_legacy(layer, crop).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1582 | auto shot = screenshot(); |
| 1583 | shot->expectColor(crop + position, Color::RED); |
| 1584 | shot->expectBorder(crop + position, Color::BLACK); |
| 1585 | } |
| 1586 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1587 | TEST_F(LayerTransactionTest, SetCropWithTranslation_BufferState) { |
| 1588 | sp<SurfaceControl> layer; |
| 1589 | ASSERT_NO_FATAL_FAILURE( |
| 1590 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1591 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1592 | |
| 1593 | const Point position(32, 32); |
| 1594 | const Rect crop(8, 8, 24, 24); |
| 1595 | Transaction().setPosition(layer, position.x, position.y).setCrop(layer, crop).apply(); |
| 1596 | auto shot = screenshot(); |
| 1597 | shot->expectColor(crop + position, Color::RED); |
| 1598 | shot->expectBorder(crop + position, Color::BLACK); |
| 1599 | } |
| 1600 | |
| 1601 | TEST_F(LayerTransactionTest, SetCropWithScale_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1602 | sp<SurfaceControl> layer; |
| 1603 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1604 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1605 | |
| 1606 | // crop is affected by matrix |
| 1607 | Transaction() |
| 1608 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1609 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1610 | .apply(); |
| 1611 | auto shot = screenshot(); |
| 1612 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 1613 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); |
| 1614 | } |
| 1615 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1616 | TEST_F(LayerTransactionTest, SetCropWithScale_BufferState) { |
| 1617 | sp<SurfaceControl> layer; |
| 1618 | ASSERT_NO_FATAL_FAILURE( |
| 1619 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1620 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1621 | |
| 1622 | // crop is affected by matrix |
| 1623 | Transaction() |
| 1624 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
| 1625 | .setCrop(layer, Rect(8, 8, 24, 24)) |
| 1626 | .apply(); |
| 1627 | auto shot = screenshot(); |
| 1628 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 1629 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); |
| 1630 | } |
| 1631 | |
| 1632 | TEST_F(LayerTransactionTest, SetCropWithResize_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1633 | sp<SurfaceControl> layer; |
| 1634 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1635 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1636 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1637 | // setCrop_legacy is applied immediately by default, with or without resize pending |
| 1638 | Transaction().setCrop_legacy(layer, Rect(8, 8, 24, 24)).setSize(layer, 16, 16).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1639 | { |
| 1640 | SCOPED_TRACE("resize pending"); |
| 1641 | auto shot = screenshot(); |
| 1642 | shot->expectColor(Rect(8, 8, 24, 24), Color::RED); |
| 1643 | shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK); |
| 1644 | } |
| 1645 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1646 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1647 | { |
| 1648 | SCOPED_TRACE("resize applied"); |
| 1649 | auto shot = screenshot(); |
| 1650 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 1651 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 1652 | } |
| 1653 | } |
| 1654 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1655 | TEST_F(LayerTransactionTest, SetCropWithResize_BufferState) { |
| 1656 | sp<SurfaceControl> layer; |
| 1657 | ASSERT_NO_FATAL_FAILURE( |
| 1658 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1659 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1660 | |
| 1661 | // setCrop_legacy is applied immediately by default, with or without resize pending |
| 1662 | Transaction().setCrop(layer, Rect(8, 8, 24, 24)).setSize(layer, 16, 16).apply(); |
| 1663 | { |
| 1664 | SCOPED_TRACE("new buffer pending"); |
| 1665 | auto shot = screenshot(); |
| 1666 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 1667 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 1668 | } |
| 1669 | |
| 1670 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 16, 16)); |
| 1671 | { |
| 1672 | SCOPED_TRACE("new buffer"); |
| 1673 | auto shot = screenshot(); |
| 1674 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 1675 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | TEST_F(LayerTransactionTest, SetCropWithNextResize_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1680 | sp<SurfaceControl> layer; |
| 1681 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1682 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1683 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1684 | // request setCrop_legacy to be applied with the next resize |
| 1685 | Transaction() |
| 1686 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) |
| 1687 | .setGeometryAppliesWithResize(layer) |
| 1688 | .apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1689 | { |
| 1690 | SCOPED_TRACE("waiting for next resize"); |
| 1691 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1692 | } |
| 1693 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1694 | Transaction().setCrop_legacy(layer, Rect(4, 4, 12, 12)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1695 | { |
| 1696 | SCOPED_TRACE("pending crop modified"); |
| 1697 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1698 | } |
| 1699 | |
| 1700 | Transaction().setSize(layer, 16, 16).apply(); |
| 1701 | { |
| 1702 | SCOPED_TRACE("resize pending"); |
| 1703 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1704 | } |
| 1705 | |
| 1706 | // finally resize |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1707 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1708 | { |
| 1709 | SCOPED_TRACE("new crop applied"); |
| 1710 | auto shot = screenshot(); |
| 1711 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1712 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1713 | } |
| 1714 | } |
| 1715 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1716 | TEST_F(LayerTransactionTest, SetCropWithNextResize_BufferState) { |
| 1717 | sp<SurfaceControl> layer; |
| 1718 | ASSERT_NO_FATAL_FAILURE( |
| 1719 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1720 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1721 | |
| 1722 | // request setCrop_legacy to be applied with the next resize |
| 1723 | Transaction().setCrop(layer, Rect(8, 8, 24, 24)).setGeometryAppliesWithResize(layer).apply(); |
| 1724 | { |
| 1725 | SCOPED_TRACE("set crop 1"); |
| 1726 | screenshot()->expectColor(Rect(8, 8, 24, 24), Color::RED); |
| 1727 | } |
| 1728 | |
| 1729 | Transaction().setCrop(layer, Rect(4, 4, 12, 12)).apply(); |
| 1730 | { |
| 1731 | SCOPED_TRACE("set crop 2"); |
| 1732 | screenshot()->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1733 | } |
| 1734 | |
| 1735 | Transaction().setSize(layer, 16, 16).apply(); |
| 1736 | { |
| 1737 | SCOPED_TRACE("resize"); |
| 1738 | screenshot()->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1739 | } |
| 1740 | |
| 1741 | // finally resize |
| 1742 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 16, 16)); |
| 1743 | { |
| 1744 | SCOPED_TRACE("new buffer"); |
| 1745 | auto shot = screenshot(); |
| 1746 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1747 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | TEST_F(LayerTransactionTest, SetCropWithNextResizeScaleToWindow_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1752 | sp<SurfaceControl> layer; |
| 1753 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1754 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1755 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1756 | // setCrop_legacy is not immediate even with SCALE_TO_WINDOW override |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1757 | Transaction() |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1758 | .setCrop_legacy(layer, Rect(4, 4, 12, 12)) |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1759 | .setSize(layer, 16, 16) |
| 1760 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1761 | .setGeometryAppliesWithResize(layer) |
| 1762 | .apply(); |
| 1763 | { |
| 1764 | SCOPED_TRACE("new crop pending"); |
| 1765 | auto shot = screenshot(); |
| 1766 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 1767 | shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK); |
| 1768 | } |
| 1769 | |
| 1770 | // XXX crop is never latched without other geometry change (b/69315677) |
| 1771 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1772 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1773 | Transaction().setPosition(layer, 0, 0).apply(); |
| 1774 | { |
| 1775 | SCOPED_TRACE("new crop applied"); |
| 1776 | auto shot = screenshot(); |
| 1777 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1778 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1779 | } |
| 1780 | } |
| 1781 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1782 | TEST_F(LayerTransactionTest, SetCropWithNextResizeScaleToWindow_BufferState) { |
| 1783 | sp<SurfaceControl> layer; |
| 1784 | ASSERT_NO_FATAL_FAILURE( |
| 1785 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1786 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1787 | |
| 1788 | // all properties are applied immediate so setGeometryAppliesWithResize has no effect |
| 1789 | Transaction() |
| 1790 | .setCrop(layer, Rect(4, 4, 12, 12)) |
| 1791 | .setSize(layer, 16, 16) |
| 1792 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1793 | .setGeometryAppliesWithResize(layer) |
| 1794 | .apply(); |
| 1795 | { |
| 1796 | SCOPED_TRACE("new crop pending"); |
| 1797 | auto shot = screenshot(); |
| 1798 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1799 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1800 | } |
| 1801 | |
| 1802 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); |
| 1803 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 16, 16)); |
| 1804 | Transaction().setPosition(layer, 0, 0).apply(); |
| 1805 | { |
| 1806 | SCOPED_TRACE("new crop applied"); |
| 1807 | auto shot = screenshot(); |
| 1808 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1809 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1810 | } |
| 1811 | } |
| 1812 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1813 | TEST_F(LayerTransactionTest, SetBufferBasic_BufferState) { |
| 1814 | sp<SurfaceControl> layer; |
| 1815 | ASSERT_NO_FATAL_FAILURE( |
| 1816 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1817 | |
| 1818 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1819 | |
| 1820 | auto shot = screenshot(); |
| 1821 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1822 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1823 | } |
| 1824 | |
| 1825 | TEST_F(LayerTransactionTest, SetBufferMultipleBuffers_BufferState) { |
| 1826 | sp<SurfaceControl> layer; |
| 1827 | ASSERT_NO_FATAL_FAILURE( |
| 1828 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1829 | |
| 1830 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1831 | |
| 1832 | { |
| 1833 | SCOPED_TRACE("set buffer 1"); |
| 1834 | auto shot = screenshot(); |
| 1835 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1836 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1837 | } |
| 1838 | |
| 1839 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::BLUE, 32, 32)); |
| 1840 | |
| 1841 | { |
| 1842 | SCOPED_TRACE("set buffer 2"); |
| 1843 | auto shot = screenshot(); |
| 1844 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 1845 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1846 | } |
| 1847 | |
| 1848 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1849 | |
| 1850 | { |
| 1851 | SCOPED_TRACE("set buffer 3"); |
| 1852 | auto shot = screenshot(); |
| 1853 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1854 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | TEST_F(LayerTransactionTest, SetBufferMultipleLayers_BufferState) { |
| 1859 | sp<SurfaceControl> layer1; |
| 1860 | ASSERT_NO_FATAL_FAILURE( |
| 1861 | layer1 = createLayer("test", 64, 64, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1862 | |
| 1863 | sp<SurfaceControl> layer2; |
| 1864 | ASSERT_NO_FATAL_FAILURE( |
| 1865 | layer2 = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1866 | |
| 1867 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::RED, 64, 64)); |
| 1868 | |
| 1869 | { |
| 1870 | SCOPED_TRACE("set layer 1 buffer red"); |
| 1871 | auto shot = screenshot(); |
| 1872 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 1873 | } |
| 1874 | |
| 1875 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::BLUE, 32, 32)); |
| 1876 | |
| 1877 | { |
| 1878 | SCOPED_TRACE("set layer 2 buffer blue"); |
| 1879 | auto shot = screenshot(); |
| 1880 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 1881 | shot->expectColor(Rect(0, 32, 64, 64), Color::RED); |
| 1882 | shot->expectColor(Rect(0, 32, 32, 64), Color::RED); |
| 1883 | } |
| 1884 | |
| 1885 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::GREEN, 64, 64)); |
| 1886 | { |
| 1887 | SCOPED_TRACE("set layer 1 buffer green"); |
| 1888 | auto shot = screenshot(); |
| 1889 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 1890 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); |
| 1891 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); |
| 1892 | } |
| 1893 | |
| 1894 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::WHITE, 32, 32)); |
| 1895 | |
| 1896 | { |
| 1897 | SCOPED_TRACE("set layer 2 buffer white"); |
| 1898 | auto shot = screenshot(); |
| 1899 | shot->expectColor(Rect(0, 0, 32, 32), Color::WHITE); |
| 1900 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); |
| 1901 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | TEST_F(LayerTransactionTest, SetTransformRotate90_BufferState) { |
| 1906 | sp<SurfaceControl> layer; |
| 1907 | ASSERT_NO_FATAL_FAILURE( |
| 1908 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1909 | |
| 1910 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1911 | Color::BLUE, Color::WHITE)); |
| 1912 | |
| 1913 | Transaction().setTransform(layer, NATIVE_WINDOW_TRANSFORM_ROT_90).apply(); |
| 1914 | |
| 1915 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE, |
| 1916 | Color::GREEN, true /* filtered */); |
| 1917 | } |
| 1918 | |
| 1919 | TEST_F(LayerTransactionTest, SetTransformFlipH_BufferState) { |
| 1920 | sp<SurfaceControl> layer; |
| 1921 | ASSERT_NO_FATAL_FAILURE( |
| 1922 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1923 | |
| 1924 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1925 | Color::BLUE, Color::WHITE)); |
| 1926 | |
| 1927 | Transaction().setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_H).apply(); |
| 1928 | |
| 1929 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE, |
| 1930 | Color::BLUE, true /* filtered */); |
| 1931 | } |
| 1932 | |
| 1933 | TEST_F(LayerTransactionTest, SetTransformFlipV_BufferState) { |
| 1934 | sp<SurfaceControl> layer; |
| 1935 | ASSERT_NO_FATAL_FAILURE( |
| 1936 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1937 | |
| 1938 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1939 | Color::BLUE, Color::WHITE)); |
| 1940 | |
| 1941 | Transaction().setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_V).apply(); |
| 1942 | |
| 1943 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED, |
| 1944 | Color::GREEN, true /* filtered */); |
| 1945 | } |
| 1946 | |
| 1947 | TEST_F(LayerTransactionTest, SetTransformToDisplayInverse_BufferState) { |
| 1948 | sp<SurfaceControl> layer; |
| 1949 | ASSERT_NO_FATAL_FAILURE( |
| 1950 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1951 | |
| 1952 | Transaction().setTransformToDisplayInverse(layer, false).apply(); |
| 1953 | |
| 1954 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::GREEN, 32, 32)); |
| 1955 | |
| 1956 | Transaction().setTransformToDisplayInverse(layer, true).apply(); |
| 1957 | } |
| 1958 | |
| 1959 | TEST_F(LayerTransactionTest, SetFenceBasic_BufferState) { |
| 1960 | sp<SurfaceControl> layer; |
| 1961 | ASSERT_NO_FATAL_FAILURE( |
| 1962 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1963 | |
| 1964 | sp<GraphicBuffer> buffer = |
| 1965 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 1966 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 1967 | BufferUsage::COMPOSER_OVERLAY, |
| 1968 | "test"); |
| 1969 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 1970 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 1971 | sp<Fence> fence = Fence::NO_FENCE; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1972 | |
| 1973 | Transaction() |
| 1974 | .setBuffer(layer, buffer) |
| 1975 | .setAcquireFence(layer, fence) |
| 1976 | .setSize(layer, 32, 32) |
| 1977 | .apply(); |
| 1978 | |
| 1979 | auto shot = screenshot(); |
| 1980 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1981 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1982 | } |
| 1983 | |
| 1984 | TEST_F(LayerTransactionTest, SetDataspaceBasic_BufferState) { |
| 1985 | sp<SurfaceControl> layer; |
| 1986 | ASSERT_NO_FATAL_FAILURE( |
| 1987 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1988 | |
| 1989 | sp<GraphicBuffer> buffer = |
| 1990 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 1991 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 1992 | BufferUsage::COMPOSER_OVERLAY, |
| 1993 | "test"); |
| 1994 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 1995 | |
| 1996 | Transaction() |
| 1997 | .setBuffer(layer, buffer) |
| 1998 | .setDataspace(layer, ui::Dataspace::UNKNOWN) |
| 1999 | .setSize(layer, 32, 32) |
| 2000 | .apply(); |
| 2001 | |
| 2002 | auto shot = screenshot(); |
| 2003 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2004 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2005 | } |
| 2006 | |
| 2007 | TEST_F(LayerTransactionTest, SetHdrMetadataBasic_BufferState) { |
| 2008 | sp<SurfaceControl> layer; |
| 2009 | ASSERT_NO_FATAL_FAILURE( |
| 2010 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2011 | |
| 2012 | sp<GraphicBuffer> buffer = |
| 2013 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2014 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2015 | BufferUsage::COMPOSER_OVERLAY, |
| 2016 | "test"); |
| 2017 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2018 | |
| 2019 | HdrMetadata hdrMetadata; |
| 2020 | hdrMetadata.validTypes = 0; |
| 2021 | Transaction() |
| 2022 | .setBuffer(layer, buffer) |
| 2023 | .setHdrMetadata(layer, hdrMetadata) |
| 2024 | .setSize(layer, 32, 32) |
| 2025 | .apply(); |
| 2026 | |
| 2027 | auto shot = screenshot(); |
| 2028 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2029 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2030 | } |
| 2031 | |
| 2032 | TEST_F(LayerTransactionTest, SetSurfaceDamageRegionBasic_BufferState) { |
| 2033 | sp<SurfaceControl> layer; |
| 2034 | ASSERT_NO_FATAL_FAILURE( |
| 2035 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2036 | |
| 2037 | sp<GraphicBuffer> buffer = |
| 2038 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2039 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2040 | BufferUsage::COMPOSER_OVERLAY, |
| 2041 | "test"); |
| 2042 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2043 | |
| 2044 | Region region; |
| 2045 | region.set(32, 32); |
| 2046 | Transaction() |
| 2047 | .setBuffer(layer, buffer) |
| 2048 | .setSurfaceDamageRegion(layer, region) |
| 2049 | .setSize(layer, 32, 32) |
| 2050 | .apply(); |
| 2051 | |
| 2052 | auto shot = screenshot(); |
| 2053 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2054 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2055 | } |
| 2056 | |
| 2057 | TEST_F(LayerTransactionTest, SetApiBasic_BufferState) { |
| 2058 | sp<SurfaceControl> layer; |
| 2059 | ASSERT_NO_FATAL_FAILURE( |
| 2060 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2061 | |
| 2062 | sp<GraphicBuffer> buffer = |
| 2063 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2064 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2065 | BufferUsage::COMPOSER_OVERLAY, |
| 2066 | "test"); |
| 2067 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2068 | |
| 2069 | Transaction() |
| 2070 | .setBuffer(layer, buffer) |
| 2071 | .setApi(layer, NATIVE_WINDOW_API_CPU) |
| 2072 | .setSize(layer, 32, 32) |
| 2073 | .apply(); |
| 2074 | |
| 2075 | auto shot = screenshot(); |
| 2076 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2077 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2078 | } |
| 2079 | |
| 2080 | TEST_F(LayerTransactionTest, SetSidebandStreamNull_BufferState) { |
| 2081 | sp<SurfaceControl> layer; |
| 2082 | ASSERT_NO_FATAL_FAILURE( |
| 2083 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2084 | |
| 2085 | // verify this doesn't cause a crash |
| 2086 | Transaction().setSidebandStream(layer, nullptr).apply(); |
| 2087 | } |
| 2088 | |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2089 | class ColorTransformHelper { |
| 2090 | public: |
| 2091 | static void DegammaColorSingle(half& s) { |
| 2092 | if (s <= 0.03928f) |
| 2093 | s = s / 12.92f; |
| 2094 | else |
| 2095 | s = pow((s + 0.055f) / 1.055f, 2.4f); |
| 2096 | } |
| 2097 | |
| 2098 | static void DegammaColor(half3& color) { |
| 2099 | DegammaColorSingle(color.r); |
| 2100 | DegammaColorSingle(color.g); |
| 2101 | DegammaColorSingle(color.b); |
| 2102 | } |
| 2103 | |
| 2104 | static void GammaColorSingle(half& s) { |
| 2105 | if (s <= 0.0031308f) { |
| 2106 | s = s * 12.92f; |
| 2107 | } else { |
| 2108 | s = 1.055f * pow(s, (1.0f / 2.4f)) - 0.055f; |
| 2109 | } |
| 2110 | } |
| 2111 | |
| 2112 | static void GammaColor(half3& color) { |
| 2113 | GammaColorSingle(color.r); |
| 2114 | GammaColorSingle(color.g); |
| 2115 | GammaColorSingle(color.b); |
| 2116 | } |
| 2117 | |
| 2118 | static void applyMatrix(half3& color, const mat3& mat) { |
| 2119 | half3 ret = half3(0); |
| 2120 | |
| 2121 | for (int i = 0; i < 3; i++) { |
| 2122 | for (int j = 0; j < 3; j++) { |
| 2123 | ret[i] = ret[i] + color[j] * mat[j][i]; |
| 2124 | } |
| 2125 | } |
| 2126 | color = ret; |
| 2127 | } |
| 2128 | }; |
| 2129 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2130 | TEST_F(LayerTransactionTest, SetColorTransformBasic) { |
| 2131 | sp<SurfaceControl> colorLayer; |
| 2132 | ASSERT_NO_FATAL_FAILURE( |
| 2133 | colorLayer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceColor)); |
| 2134 | |
| 2135 | Transaction().setLayer(colorLayer, mLayerZBase + 1).apply(); |
| 2136 | { |
| 2137 | SCOPED_TRACE("default color"); |
| 2138 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
| 2139 | } |
| 2140 | |
| 2141 | const half3 color(50.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f); |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2142 | half3 expected = color; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2143 | mat3 matrix; |
| 2144 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; |
| 2145 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; |
| 2146 | matrix[0][2] = 0.3; matrix[1][2] = 0.59; matrix[2][2] = 0.11; |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2147 | |
| 2148 | // degamma before applying the matrix |
| 2149 | if (mColorManagementUsed) { |
| 2150 | ColorTransformHelper::DegammaColor(expected); |
| 2151 | } |
| 2152 | |
| 2153 | ColorTransformHelper::applyMatrix(expected, matrix); |
| 2154 | |
| 2155 | if (mColorManagementUsed) { |
| 2156 | ColorTransformHelper::GammaColor(expected); |
| 2157 | } |
| 2158 | |
| 2159 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), |
| 2160 | uint8_t(expected.b * 255), 255}; |
| 2161 | |
| 2162 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 2163 | // channel) should be less than one |
| 2164 | const uint8_t tolerance = 1; |
| 2165 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2166 | Transaction().setColor(colorLayer, color) |
| 2167 | .setColorTransform(colorLayer, matrix, vec3()).apply(); |
| 2168 | { |
| 2169 | SCOPED_TRACE("new color"); |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2170 | screenshot()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2171 | } |
| 2172 | } |
| 2173 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2174 | class ExpectedResult { |
| 2175 | public: |
| 2176 | enum Transaction { |
| 2177 | NOT_PRESENTED = 0, |
| 2178 | PRESENTED, |
| 2179 | }; |
| 2180 | |
| 2181 | enum Buffer { |
| 2182 | NOT_ACQUIRED = 0, |
| 2183 | ACQUIRED, |
| 2184 | }; |
| 2185 | |
| 2186 | enum PreviousBuffer { |
| 2187 | NOT_RELEASED = 0, |
| 2188 | RELEASED, |
| 2189 | }; |
| 2190 | |
| 2191 | void reset() { |
| 2192 | mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; |
| 2193 | mExpectedSurfaceResults.clear(); |
| 2194 | } |
| 2195 | |
| 2196 | void addSurface(ExpectedResult::Transaction transactionResult, const sp<SurfaceControl>& layer, |
| 2197 | ExpectedResult::Buffer bufferResult = NOT_ACQUIRED, |
| 2198 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { |
| 2199 | mTransactionResult = transactionResult; |
| 2200 | mExpectedSurfaceResults.emplace(std::piecewise_construct, |
| 2201 | std::forward_as_tuple(layer->getHandle()), |
| 2202 | std::forward_as_tuple(bufferResult, previousBufferResult)); |
| 2203 | } |
| 2204 | |
| 2205 | void addSurfaces(ExpectedResult::Transaction transactionResult, |
| 2206 | const std::vector<sp<SurfaceControl>>& layers, |
| 2207 | ExpectedResult::Buffer bufferResult = NOT_ACQUIRED, |
| 2208 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { |
| 2209 | for (const auto& layer : layers) { |
| 2210 | addSurface(transactionResult, layer, bufferResult, previousBufferResult); |
| 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | void verifyTransactionStats(const TransactionStats& transactionStats) const { |
| 2215 | const auto& [latchTime, presentTime, surfaceStats] = transactionStats; |
| 2216 | if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) { |
| 2217 | ASSERT_GE(latchTime, 0) << "bad latch time"; |
| 2218 | ASSERT_GE(presentTime, 0) << "bad present time"; |
| 2219 | } else { |
| 2220 | ASSERT_EQ(presentTime, -1) << "transaction shouldn't have been presented"; |
| 2221 | ASSERT_EQ(latchTime, -1) << "unpresented transactions shouldn't be latched"; |
| 2222 | } |
| 2223 | |
| 2224 | ASSERT_EQ(surfaceStats.size(), mExpectedSurfaceResults.size()) |
| 2225 | << "wrong number of surfaces"; |
| 2226 | |
| 2227 | for (const auto& stats : surfaceStats) { |
| 2228 | const auto& expectedSurfaceResult = mExpectedSurfaceResults.find(stats.surfaceControl); |
| 2229 | ASSERT_NE(expectedSurfaceResult, mExpectedSurfaceResults.end()) |
| 2230 | << "unexpected surface control"; |
| 2231 | expectedSurfaceResult->second.verifySurfaceStats(stats, latchTime); |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | private: |
| 2236 | class ExpectedSurfaceResult { |
| 2237 | public: |
| 2238 | ExpectedSurfaceResult(ExpectedResult::Buffer bufferResult, |
| 2239 | ExpectedResult::PreviousBuffer previousBufferResult) |
| 2240 | : mBufferResult(bufferResult), mPreviousBufferResult(previousBufferResult) {} |
| 2241 | |
| 2242 | void verifySurfaceStats(const SurfaceStats& surfaceStats, nsecs_t latchTime) const { |
| 2243 | const auto& [surfaceControl, acquireTime, releasePreviousBuffer] = surfaceStats; |
| 2244 | |
| 2245 | ASSERT_EQ(acquireTime > 0, mBufferResult == ExpectedResult::Buffer::ACQUIRED) |
| 2246 | << "bad acquire time"; |
| 2247 | ASSERT_LE(acquireTime, latchTime) << "acquire time should be <= latch time"; |
| 2248 | ASSERT_EQ(releasePreviousBuffer, |
| 2249 | mPreviousBufferResult == ExpectedResult::PreviousBuffer::RELEASED) |
| 2250 | << "bad previous buffer released"; |
| 2251 | } |
| 2252 | |
| 2253 | private: |
| 2254 | ExpectedResult::Buffer mBufferResult; |
| 2255 | ExpectedResult::PreviousBuffer mPreviousBufferResult; |
| 2256 | }; |
| 2257 | |
| 2258 | struct IBinderHash { |
| 2259 | std::size_t operator()(const sp<IBinder>& strongPointer) const { |
| 2260 | return std::hash<IBinder*>{}(strongPointer.get()); |
| 2261 | } |
| 2262 | }; |
| 2263 | ExpectedResult::Transaction mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; |
| 2264 | std::unordered_map<sp<IBinder>, ExpectedSurfaceResult, IBinderHash> mExpectedSurfaceResults; |
| 2265 | }; |
| 2266 | |
| 2267 | class CallbackHelper { |
| 2268 | public: |
| 2269 | static void function(void* callbackContext, const TransactionStats& transactionStats) { |
| 2270 | if (!callbackContext) { |
| 2271 | ALOGE("failed to get callback context"); |
| 2272 | } |
| 2273 | CallbackHelper* helper = static_cast<CallbackHelper*>(callbackContext); |
| 2274 | std::lock_guard lock(helper->mMutex); |
| 2275 | helper->mTransactionStatsQueue.push(transactionStats); |
| 2276 | helper->mConditionVariable.notify_all(); |
| 2277 | } |
| 2278 | |
| 2279 | void getTransactionStats(TransactionStats* outStats) { |
| 2280 | std::unique_lock lock(mMutex); |
| 2281 | |
| 2282 | if (mTransactionStatsQueue.empty()) { |
| 2283 | ASSERT_NE(mConditionVariable.wait_for(lock, std::chrono::seconds(3)), |
| 2284 | std::cv_status::timeout) |
| 2285 | << "did not receive callback"; |
| 2286 | } |
| 2287 | |
| 2288 | *outStats = std::move(mTransactionStatsQueue.front()); |
| 2289 | mTransactionStatsQueue.pop(); |
| 2290 | } |
| 2291 | |
| 2292 | void verifyFinalState() { |
| 2293 | // Wait to see if there are extra callbacks |
| 2294 | std::this_thread::sleep_for(500ms); |
| 2295 | |
| 2296 | std::lock_guard lock(mMutex); |
| 2297 | EXPECT_EQ(mTransactionStatsQueue.size(), 0) << "extra callbacks received"; |
| 2298 | mTransactionStatsQueue = {}; |
| 2299 | } |
| 2300 | |
| 2301 | void* getContext() { return static_cast<void*>(this); } |
| 2302 | |
| 2303 | std::mutex mMutex; |
| 2304 | std::condition_variable mConditionVariable; |
| 2305 | std::queue<TransactionStats> mTransactionStatsQueue; |
| 2306 | }; |
| 2307 | |
| 2308 | class LayerCallbackTest : public LayerTransactionTest { |
| 2309 | protected: |
| 2310 | virtual sp<SurfaceControl> createBufferStateLayer() { |
| 2311 | return createLayer(mClient, "test", mWidth, mHeight, |
| 2312 | ISurfaceComposerClient::eFXSurfaceBufferState); |
| 2313 | } |
| 2314 | |
| 2315 | virtual void fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, |
| 2316 | const sp<SurfaceControl>& layer = nullptr) { |
| 2317 | if (layer) { |
| 2318 | sp<GraphicBuffer> buffer = |
| 2319 | new GraphicBuffer(mWidth, mHeight, PIXEL_FORMAT_RGBA_8888, 1, |
| 2320 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2321 | BufferUsage::COMPOSER_OVERLAY | |
| 2322 | BufferUsage::GPU_TEXTURE, |
| 2323 | "test"); |
| 2324 | fillGraphicBufferColor(buffer, Rect(0, 0, mWidth, mHeight), Color::RED); |
| 2325 | |
| 2326 | sp<Fence> fence = new Fence(-1); |
| 2327 | |
| 2328 | transaction.setBuffer(layer, buffer) |
| 2329 | .setAcquireFence(layer, fence) |
| 2330 | .setSize(layer, mWidth, mHeight); |
| 2331 | } |
| 2332 | |
| 2333 | transaction.addTransactionCompletedCallback(callbackHelper->function, |
| 2334 | callbackHelper->getContext()); |
| 2335 | } |
| 2336 | |
| 2337 | void waitForCallback(CallbackHelper& helper, const ExpectedResult& expectedResult, |
| 2338 | bool finalState = false) { |
| 2339 | TransactionStats transactionStats; |
| 2340 | ASSERT_NO_FATAL_FAILURE(helper.getTransactionStats(&transactionStats)); |
| 2341 | EXPECT_NO_FATAL_FAILURE(expectedResult.verifyTransactionStats(transactionStats)); |
| 2342 | |
| 2343 | if (finalState) { |
| 2344 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | void waitForCallbacks(CallbackHelper& helper, |
| 2349 | const std::vector<ExpectedResult>& expectedResults, |
| 2350 | bool finalState = false) { |
| 2351 | for (const auto& expectedResult : expectedResults) { |
| 2352 | waitForCallback(helper, expectedResult); |
| 2353 | } |
| 2354 | if (finalState) { |
| 2355 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | uint32_t mWidth = 32; |
| 2360 | uint32_t mHeight = 32; |
| 2361 | }; |
| 2362 | |
| 2363 | TEST_F(LayerCallbackTest, Basic) { |
| 2364 | sp<SurfaceControl> layer; |
| 2365 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2366 | |
| 2367 | Transaction transaction; |
| 2368 | CallbackHelper callback; |
| 2369 | fillTransaction(transaction, &callback, layer); |
| 2370 | |
| 2371 | transaction.apply(); |
| 2372 | |
| 2373 | ExpectedResult expected; |
| 2374 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2375 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2376 | } |
| 2377 | |
| 2378 | TEST_F(LayerCallbackTest, NoBuffer) { |
| 2379 | sp<SurfaceControl> layer; |
| 2380 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2381 | |
| 2382 | Transaction transaction; |
| 2383 | CallbackHelper callback; |
| 2384 | fillTransaction(transaction, &callback); |
| 2385 | |
| 2386 | transaction.setPosition(layer, mWidth, mHeight).apply(); |
| 2387 | |
| 2388 | ExpectedResult expected; |
| 2389 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer); |
| 2390 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2391 | } |
| 2392 | |
| 2393 | TEST_F(LayerCallbackTest, NoStateChange) { |
| 2394 | Transaction transaction; |
| 2395 | CallbackHelper callback; |
| 2396 | fillTransaction(transaction, &callback); |
| 2397 | |
| 2398 | transaction.apply(); |
| 2399 | |
| 2400 | ExpectedResult expected; |
| 2401 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2402 | } |
| 2403 | |
| 2404 | TEST_F(LayerCallbackTest, OffScreen) { |
| 2405 | sp<SurfaceControl> layer; |
| 2406 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2407 | |
| 2408 | Transaction transaction; |
| 2409 | CallbackHelper callback; |
| 2410 | fillTransaction(transaction, &callback, layer); |
| 2411 | |
| 2412 | transaction.setPosition(layer, -100, -100).apply(); |
| 2413 | |
| 2414 | ExpectedResult expected; |
| 2415 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2416 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2417 | } |
| 2418 | |
| 2419 | TEST_F(LayerCallbackTest, Merge) { |
| 2420 | sp<SurfaceControl> layer1, layer2; |
| 2421 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 2422 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 2423 | |
| 2424 | Transaction transaction1, transaction2; |
| 2425 | CallbackHelper callback1, callback2; |
| 2426 | fillTransaction(transaction1, &callback1, layer1); |
| 2427 | fillTransaction(transaction2, &callback2, layer2); |
| 2428 | |
| 2429 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2430 | |
| 2431 | ExpectedResult expected; |
| 2432 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2433 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2434 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2435 | } |
| 2436 | |
| 2437 | TEST_F(LayerCallbackTest, Merge_SameCallback) { |
| 2438 | sp<SurfaceControl> layer1, layer2; |
| 2439 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 2440 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 2441 | |
| 2442 | Transaction transaction1, transaction2; |
| 2443 | CallbackHelper callback; |
| 2444 | fillTransaction(transaction1, &callback, layer1); |
| 2445 | fillTransaction(transaction2, &callback, layer2); |
| 2446 | |
| 2447 | transaction2.merge(std::move(transaction1)).apply(); |
| 2448 | |
| 2449 | ExpectedResult expected; |
| 2450 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2451 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 2452 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2453 | } |
| 2454 | |
| 2455 | TEST_F(LayerCallbackTest, Merge_SameLayer) { |
| 2456 | sp<SurfaceControl> layer; |
| 2457 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2458 | |
| 2459 | Transaction transaction1, transaction2; |
| 2460 | CallbackHelper callback1, callback2; |
| 2461 | fillTransaction(transaction1, &callback1, layer); |
| 2462 | fillTransaction(transaction2, &callback2, layer); |
| 2463 | |
| 2464 | transaction2.merge(std::move(transaction1)).apply(); |
| 2465 | |
| 2466 | ExpectedResult expected; |
| 2467 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2468 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2469 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2470 | } |
| 2471 | |
| 2472 | TEST_F(LayerCallbackTest, Merge_SingleBuffer) { |
| 2473 | sp<SurfaceControl> layer1, layer2; |
| 2474 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 2475 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 2476 | |
| 2477 | Transaction transaction1, transaction2; |
| 2478 | CallbackHelper callback1, callback2; |
| 2479 | fillTransaction(transaction1, &callback1, layer1); |
| 2480 | fillTransaction(transaction2, &callback2); |
| 2481 | |
| 2482 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2483 | |
| 2484 | ExpectedResult expected; |
| 2485 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2486 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2487 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2488 | } |
| 2489 | |
| 2490 | TEST_F(LayerCallbackTest, Merge_DifferentClients) { |
| 2491 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 2492 | client2(new SurfaceComposerClient); |
| 2493 | |
| 2494 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2495 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2496 | |
| 2497 | sp<SurfaceControl> layer1, layer2; |
| 2498 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", mWidth, mHeight, |
| 2499 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2500 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", mWidth, mHeight, |
| 2501 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2502 | |
| 2503 | Transaction transaction1, transaction2; |
| 2504 | CallbackHelper callback1, callback2; |
| 2505 | fillTransaction(transaction1, &callback1, layer1); |
| 2506 | fillTransaction(transaction2, &callback2, layer2); |
| 2507 | |
| 2508 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2509 | |
| 2510 | ExpectedResult expected; |
| 2511 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2512 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2513 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2514 | } |
| 2515 | |
| 2516 | TEST_F(LayerCallbackTest, MultipleTransactions) { |
| 2517 | sp<SurfaceControl> layer; |
| 2518 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2519 | |
| 2520 | Transaction transaction; |
| 2521 | CallbackHelper callback; |
| 2522 | for (size_t i = 0; i < 10; i++) { |
| 2523 | fillTransaction(transaction, &callback, layer); |
| 2524 | |
| 2525 | transaction.apply(); |
| 2526 | |
| 2527 | ExpectedResult expected; |
| 2528 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 2529 | ExpectedResult::Buffer::NOT_ACQUIRED, |
| 2530 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 2531 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 2532 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 2533 | } |
| 2534 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 2535 | } |
| 2536 | |
| 2537 | TEST_F(LayerCallbackTest, MultipleTransactions_NoStateChange) { |
| 2538 | sp<SurfaceControl> layer; |
| 2539 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2540 | |
| 2541 | Transaction transaction; |
| 2542 | CallbackHelper callback; |
| 2543 | for (size_t i = 0; i < 10; i++) { |
| 2544 | ExpectedResult expected; |
| 2545 | |
| 2546 | if (i == 0) { |
| 2547 | fillTransaction(transaction, &callback, layer); |
| 2548 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2549 | } else { |
| 2550 | fillTransaction(transaction, &callback); |
| 2551 | } |
| 2552 | |
| 2553 | transaction.apply(); |
| 2554 | |
| 2555 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 2556 | } |
| 2557 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 2558 | } |
| 2559 | |
| 2560 | TEST_F(LayerCallbackTest, MultipleTransactions_SameStateChange) { |
| 2561 | sp<SurfaceControl> layer; |
| 2562 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2563 | |
| 2564 | Transaction transaction; |
| 2565 | CallbackHelper callback; |
| 2566 | for (size_t i = 0; i < 10; i++) { |
| 2567 | if (i == 0) { |
| 2568 | fillTransaction(transaction, &callback, layer); |
| 2569 | } else { |
| 2570 | fillTransaction(transaction, &callback); |
| 2571 | } |
| 2572 | |
| 2573 | transaction.setPosition(layer, mWidth, mHeight).apply(); |
| 2574 | |
| 2575 | ExpectedResult expected; |
| 2576 | expected.addSurface((i == 0) ? ExpectedResult::Transaction::PRESENTED |
| 2577 | : ExpectedResult::Transaction::NOT_PRESENTED, |
| 2578 | layer); |
| 2579 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, i == 0)); |
| 2580 | } |
| 2581 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 2582 | } |
| 2583 | |
| 2584 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge) { |
| 2585 | sp<SurfaceControl> layer1, layer2; |
| 2586 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 2587 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 2588 | |
| 2589 | Transaction transaction1, transaction2; |
| 2590 | CallbackHelper callback1, callback2; |
| 2591 | for (size_t i = 0; i < 10; i++) { |
| 2592 | fillTransaction(transaction1, &callback1, layer1); |
| 2593 | fillTransaction(transaction2, &callback2, layer2); |
| 2594 | |
| 2595 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2596 | |
| 2597 | ExpectedResult expected; |
| 2598 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 2599 | ExpectedResult::Buffer::NOT_ACQUIRED, |
| 2600 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 2601 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 2602 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 2603 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 2604 | } |
| 2605 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 2606 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 2607 | } |
| 2608 | |
| 2609 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients) { |
| 2610 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 2611 | client2(new SurfaceComposerClient); |
| 2612 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2613 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2614 | |
| 2615 | sp<SurfaceControl> layer1, layer2; |
| 2616 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", mWidth, mHeight, |
| 2617 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2618 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", mWidth, mHeight, |
| 2619 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2620 | |
| 2621 | Transaction transaction1, transaction2; |
| 2622 | CallbackHelper callback1, callback2; |
| 2623 | for (size_t i = 0; i < 10; i++) { |
| 2624 | fillTransaction(transaction1, &callback1, layer1); |
| 2625 | fillTransaction(transaction2, &callback2, layer2); |
| 2626 | |
| 2627 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2628 | |
| 2629 | ExpectedResult expected; |
| 2630 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 2631 | ExpectedResult::Buffer::NOT_ACQUIRED, |
| 2632 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 2633 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 2634 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 2635 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 2636 | } |
| 2637 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 2638 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 2639 | } |
| 2640 | |
| 2641 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_NoStateChange) { |
| 2642 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 2643 | client2(new SurfaceComposerClient); |
| 2644 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2645 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2646 | |
| 2647 | sp<SurfaceControl> layer1, layer2; |
| 2648 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", mWidth, mHeight, |
| 2649 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2650 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", mWidth, mHeight, |
| 2651 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2652 | |
| 2653 | Transaction transaction1, transaction2; |
| 2654 | CallbackHelper callback1, callback2; |
| 2655 | |
| 2656 | // Normal call to set up test |
| 2657 | fillTransaction(transaction1, &callback1, layer1); |
| 2658 | fillTransaction(transaction2, &callback2, layer2); |
| 2659 | |
| 2660 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2661 | |
| 2662 | ExpectedResult expected; |
| 2663 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2664 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2665 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2666 | expected.reset(); |
| 2667 | |
| 2668 | // Test |
| 2669 | fillTransaction(transaction1, &callback1); |
| 2670 | fillTransaction(transaction2, &callback2); |
| 2671 | |
| 2672 | transaction2.merge(std::move(transaction1)).apply(); |
| 2673 | |
| 2674 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2675 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2676 | } |
| 2677 | |
| 2678 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_SameStateChange) { |
| 2679 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 2680 | client2(new SurfaceComposerClient); |
| 2681 | |
| 2682 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2683 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2684 | |
| 2685 | sp<SurfaceControl> layer1, layer2; |
| 2686 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", mWidth, mHeight, |
| 2687 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2688 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", mWidth, mHeight, |
| 2689 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2690 | |
| 2691 | Transaction transaction1, transaction2; |
| 2692 | CallbackHelper callback1, callback2; |
| 2693 | |
| 2694 | // Normal call to set up test |
| 2695 | fillTransaction(transaction1, &callback1, layer1); |
| 2696 | fillTransaction(transaction2, &callback2, layer2); |
| 2697 | |
| 2698 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2699 | |
| 2700 | ExpectedResult expected; |
| 2701 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2702 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2703 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2704 | expected.reset(); |
| 2705 | |
| 2706 | // Test |
| 2707 | fillTransaction(transaction1, &callback1); |
| 2708 | fillTransaction(transaction2, &callback2); |
| 2709 | |
| 2710 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2711 | |
| 2712 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer2); |
| 2713 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2714 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2715 | } |
| 2716 | |
| 2717 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame) { |
| 2718 | sp<SurfaceControl> layer; |
| 2719 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2720 | |
| 2721 | Transaction transaction; |
| 2722 | CallbackHelper callback; |
| 2723 | std::vector<ExpectedResult> expectedResults(50); |
| 2724 | ExpectedResult::PreviousBuffer previousBufferResult = |
| 2725 | ExpectedResult::PreviousBuffer::NOT_RELEASED; |
| 2726 | for (auto& expected : expectedResults) { |
| 2727 | expected.reset(); |
| 2728 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 2729 | ExpectedResult::Buffer::NOT_ACQUIRED, previousBufferResult); |
| 2730 | previousBufferResult = ExpectedResult::PreviousBuffer::RELEASED; |
| 2731 | |
| 2732 | fillTransaction(transaction, &callback, layer); |
| 2733 | |
| 2734 | transaction.apply(); |
| 2735 | std::this_thread::sleep_for(200ms); |
| 2736 | } |
| 2737 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 2738 | } |
| 2739 | |
| 2740 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_NoStateChange) { |
| 2741 | sp<SurfaceControl> layer; |
| 2742 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2743 | |
| 2744 | Transaction transaction; |
| 2745 | CallbackHelper callback; |
| 2746 | std::vector<ExpectedResult> expectedResults(50); |
| 2747 | bool first = true; |
| 2748 | for (auto& expected : expectedResults) { |
| 2749 | expected.reset(); |
| 2750 | |
| 2751 | if (first) { |
| 2752 | fillTransaction(transaction, &callback, layer); |
| 2753 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2754 | first = false; |
| 2755 | } else { |
| 2756 | fillTransaction(transaction, &callback); |
| 2757 | } |
| 2758 | |
| 2759 | transaction.apply(); |
| 2760 | std::this_thread::sleep_for(200ms); |
| 2761 | } |
| 2762 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 2763 | } |
| 2764 | |
| 2765 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_SameStateChange) { |
| 2766 | sp<SurfaceControl> layer; |
| 2767 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2768 | |
| 2769 | // Normal call to set up test |
| 2770 | Transaction transaction; |
| 2771 | CallbackHelper callback; |
| 2772 | fillTransaction(transaction, &callback, layer); |
| 2773 | |
| 2774 | transaction.setPosition(layer, mWidth, mHeight).apply(); |
| 2775 | |
| 2776 | ExpectedResult expectedResult; |
| 2777 | expectedResult.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2778 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expectedResult, true)); |
| 2779 | |
| 2780 | // Test |
| 2781 | std::vector<ExpectedResult> expectedResults(50); |
| 2782 | for (auto& expected : expectedResults) { |
| 2783 | expected.reset(); |
| 2784 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer); |
| 2785 | |
| 2786 | fillTransaction(transaction, &callback); |
| 2787 | |
| 2788 | transaction.setPosition(layer, mWidth, mHeight).apply(); |
| 2789 | |
| 2790 | std::this_thread::sleep_for(200ms); |
| 2791 | } |
| 2792 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 2793 | } |
| 2794 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 2795 | class LayerUpdateTest : public LayerTransactionTest { |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2796 | protected: |
| 2797 | virtual void SetUp() { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2798 | LayerTransactionTest::SetUp(); |
| 2799 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2800 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2801 | sp<IBinder> display( |
| 2802 | SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 2803 | DisplayInfo info; |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 2804 | SurfaceComposerClient::getDisplayInfo(display, &info); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 2805 | |
| 2806 | ssize_t displayWidth = info.w; |
| 2807 | ssize_t displayHeight = info.h; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2808 | |
| 2809 | // Background surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2810 | mBGSurfaceControl = createLayer(String8("BG Test Surface"), displayWidth, |
| 2811 | displayHeight, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 2812 | ASSERT_TRUE(mBGSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2813 | ASSERT_TRUE(mBGSurfaceControl->isValid()); |
| 2814 | fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195); |
| 2815 | |
| 2816 | // Foreground surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2817 | mFGSurfaceControl = createLayer(String8("FG Test Surface"), 64, 64, 0); |
| 2818 | |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 2819 | ASSERT_TRUE(mFGSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2820 | ASSERT_TRUE(mFGSurfaceControl->isValid()); |
| 2821 | |
| 2822 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 2823 | |
| 2824 | // Synchronization surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2825 | mSyncSurfaceControl = createLayer(String8("Sync Test Surface"), 1, 1, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 2826 | ASSERT_TRUE(mSyncSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2827 | ASSERT_TRUE(mSyncSurfaceControl->isValid()); |
| 2828 | |
| 2829 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 2830 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2831 | asTransaction([&](Transaction& t) { |
| 2832 | t.setDisplayLayerStack(display, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2833 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2834 | t.setLayer(mBGSurfaceControl, INT32_MAX - 2).show(mBGSurfaceControl); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 2835 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2836 | t.setLayer(mFGSurfaceControl, INT32_MAX - 1) |
| 2837 | .setPosition(mFGSurfaceControl, 64, 64) |
| 2838 | .show(mFGSurfaceControl); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2839 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2840 | t.setLayer(mSyncSurfaceControl, INT32_MAX - 1) |
| 2841 | .setPosition(mSyncSurfaceControl, displayWidth - 2, displayHeight - 2) |
| 2842 | .show(mSyncSurfaceControl); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2843 | }); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | virtual void TearDown() { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2847 | LayerTransactionTest::TearDown(); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2848 | mBGSurfaceControl = 0; |
| 2849 | mFGSurfaceControl = 0; |
| 2850 | mSyncSurfaceControl = 0; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | void waitForPostedBuffers() { |
| 2854 | // Since the sync surface is in synchronous mode (i.e. double buffered) |
| 2855 | // posting three buffers to it should ensure that at least two |
| 2856 | // SurfaceFlinger::handlePageFlip calls have been made, which should |
| 2857 | // guaranteed that a buffer posted to another Surface has been retired. |
| 2858 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 2859 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 2860 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 2861 | } |
| 2862 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2863 | void asTransaction(const std::function<void(Transaction&)>& exec) { |
| 2864 | Transaction t; |
| 2865 | exec(t); |
| 2866 | t.apply(true); |
| 2867 | } |
| 2868 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2869 | sp<SurfaceControl> mBGSurfaceControl; |
| 2870 | sp<SurfaceControl> mFGSurfaceControl; |
| 2871 | |
| 2872 | // This surface is used to ensure that the buffers posted to |
| 2873 | // mFGSurfaceControl have been picked up by SurfaceFlinger. |
| 2874 | sp<SurfaceControl> mSyncSurfaceControl; |
| 2875 | }; |
| 2876 | |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2877 | TEST_F(LayerUpdateTest, RelativesAreNotDetached) { |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2878 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2879 | std::unique_ptr<ScreenCapture> sc; |
| 2880 | |
| 2881 | sp<SurfaceControl> relative = createLayer(String8("relativeTestSurface"), 10, 10, 0); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2882 | fillSurfaceRGBA8(relative, 10, 10, 10); |
| 2883 | waitForPostedBuffers(); |
| 2884 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2885 | Transaction{} |
| 2886 | .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1) |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2887 | .setPosition(relative, 64, 64) |
| 2888 | .apply(); |
| 2889 | |
| 2890 | { |
| 2891 | // The relative should be on top of the FG control. |
| 2892 | ScreenCapture::captureScreen(&sc); |
| 2893 | sc->checkPixel(64, 64, 10, 10, 10); |
| 2894 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2895 | Transaction{}.detachChildren(mFGSurfaceControl).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2896 | |
| 2897 | { |
| 2898 | // Nothing should change at this point. |
| 2899 | ScreenCapture::captureScreen(&sc); |
| 2900 | sc->checkPixel(64, 64, 10, 10, 10); |
| 2901 | } |
| 2902 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2903 | Transaction{}.hide(relative).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2904 | |
| 2905 | { |
| 2906 | // Ensure that the relative was actually hidden, rather than |
| 2907 | // being left in the detached but visible state. |
| 2908 | ScreenCapture::captureScreen(&sc); |
| 2909 | sc->expectFGColor(64, 64); |
| 2910 | } |
| 2911 | } |
| 2912 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 2913 | class GeometryLatchingTest : public LayerUpdateTest { |
| 2914 | protected: |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2915 | void EXPECT_INITIAL_STATE(const char* trace) { |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 2916 | SCOPED_TRACE(trace); |
| 2917 | ScreenCapture::captureScreen(&sc); |
| 2918 | // We find the leading edge of the FG surface. |
| 2919 | sc->expectFGColor(127, 127); |
| 2920 | sc->expectBGColor(128, 128); |
| 2921 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 2922 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2923 | void lockAndFillFGBuffer() { fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false); } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 2924 | |
| 2925 | void unlockFGBuffer() { |
| 2926 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 2927 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 2928 | waitForPostedBuffers(); |
| 2929 | } |
| 2930 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 2931 | void completeFGResize() { |
| 2932 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 2933 | waitForPostedBuffers(); |
| 2934 | } |
| 2935 | void restoreInitialState() { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2936 | asTransaction([&](Transaction& t) { |
| 2937 | t.setSize(mFGSurfaceControl, 64, 64); |
| 2938 | t.setPosition(mFGSurfaceControl, 64, 64); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2939 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 64, 64)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2940 | }); |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 2941 | |
| 2942 | EXPECT_INITIAL_STATE("After restoring initial state"); |
| 2943 | } |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2944 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 2945 | }; |
| 2946 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 2947 | class CropLatchingTest : public GeometryLatchingTest { |
| 2948 | protected: |
| 2949 | void EXPECT_CROPPED_STATE(const char* trace) { |
| 2950 | SCOPED_TRACE(trace); |
| 2951 | ScreenCapture::captureScreen(&sc); |
| 2952 | // The edge should be moved back one pixel by our crop. |
| 2953 | sc->expectFGColor(126, 126); |
| 2954 | sc->expectBGColor(127, 127); |
| 2955 | sc->expectBGColor(128, 128); |
| 2956 | } |
chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 2957 | |
| 2958 | void EXPECT_RESIZE_STATE(const char* trace) { |
| 2959 | SCOPED_TRACE(trace); |
| 2960 | ScreenCapture::captureScreen(&sc); |
| 2961 | // The FG is now resized too 128,128 at 64,64 |
| 2962 | sc->expectFGColor(64, 64); |
| 2963 | sc->expectFGColor(191, 191); |
| 2964 | sc->expectBGColor(192, 192); |
| 2965 | } |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 2966 | }; |
| 2967 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 2968 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2969 | std::unique_ptr<ScreenCapture> sc; |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 2970 | { |
| 2971 | SCOPED_TRACE("before anything"); |
| 2972 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 2973 | sc->expectBGColor(32, 32); |
| 2974 | sc->expectFGColor(96, 96); |
| 2975 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | // set up two deferred transactions on different frames |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2979 | asTransaction([&](Transaction& t) { |
| 2980 | t.setAlpha(mFGSurfaceControl, 0.75); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2981 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
| 2982 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2983 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 2984 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2985 | asTransaction([&](Transaction& t) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2986 | t.setPosition(mFGSurfaceControl, 128, 128); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2987 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
| 2988 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2989 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 2990 | |
| 2991 | { |
| 2992 | SCOPED_TRACE("before any trigger"); |
| 2993 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 2994 | sc->expectBGColor(32, 32); |
| 2995 | sc->expectFGColor(96, 96); |
| 2996 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | // should trigger the first deferred transaction, but not the second one |
| 3000 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 3001 | { |
| 3002 | SCOPED_TRACE("after first trigger"); |
| 3003 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 3004 | sc->expectBGColor(32, 32); |
| 3005 | sc->checkPixel(96, 96, 162, 63, 96); |
| 3006 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | // should show up immediately since it's not deferred |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3010 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 1.0); }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3011 | |
| 3012 | // trigger the second deferred transaction |
| 3013 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 3014 | { |
| 3015 | SCOPED_TRACE("after second trigger"); |
| 3016 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 3017 | sc->expectBGColor(32, 32); |
| 3018 | sc->expectBGColor(96, 96); |
| 3019 | sc->expectFGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3020 | } |
| 3021 | } |
| 3022 | |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3023 | TEST_F(LayerUpdateTest, LayerWithNoBuffersResizesImmediately) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3024 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3025 | |
| 3026 | sp<SurfaceControl> childNoBuffer = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3027 | mClient->createSurface(String8("Bufferless child"), 10, 10, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3028 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 3029 | sp<SurfaceControl> childBuffer = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3030 | mClient->createSurface(String8("Buffered child"), 20, 20, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3031 | PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get()); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3032 | fillSurfaceRGBA8(childBuffer, 200, 200, 200); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3033 | SurfaceComposerClient::Transaction{} |
| 3034 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 10, 10)) |
| 3035 | .show(childNoBuffer) |
| 3036 | .show(childBuffer) |
| 3037 | .apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3038 | { |
| 3039 | ScreenCapture::captureScreen(&sc); |
| 3040 | sc->expectChildColor(73, 73); |
| 3041 | sc->expectFGColor(74, 74); |
| 3042 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3043 | SurfaceComposerClient::Transaction{} |
| 3044 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 20, 20)) |
| 3045 | .apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3046 | { |
| 3047 | ScreenCapture::captureScreen(&sc); |
| 3048 | sc->expectChildColor(73, 73); |
| 3049 | sc->expectChildColor(74, 74); |
| 3050 | } |
| 3051 | } |
| 3052 | |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 3053 | TEST_F(LayerUpdateTest, MergingTransactions) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3054 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 3055 | { |
| 3056 | SCOPED_TRACE("before move"); |
| 3057 | ScreenCapture::captureScreen(&sc); |
| 3058 | sc->expectBGColor(0, 12); |
| 3059 | sc->expectFGColor(75, 75); |
| 3060 | sc->expectBGColor(145, 145); |
| 3061 | } |
| 3062 | |
| 3063 | Transaction t1, t2; |
| 3064 | t1.setPosition(mFGSurfaceControl, 128, 128); |
| 3065 | t2.setPosition(mFGSurfaceControl, 0, 0); |
| 3066 | // We expect that the position update from t2 now |
| 3067 | // overwrites the position update from t1. |
| 3068 | t1.merge(std::move(t2)); |
| 3069 | t1.apply(); |
| 3070 | |
| 3071 | { |
| 3072 | ScreenCapture::captureScreen(&sc); |
| 3073 | sc->expectFGColor(1, 1); |
| 3074 | } |
| 3075 | } |
| 3076 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3077 | class ChildLayerTest : public LayerUpdateTest { |
| 3078 | protected: |
| 3079 | void SetUp() override { |
| 3080 | LayerUpdateTest::SetUp(); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3081 | mChild = mClient->createSurface(String8("Child surface"), 10, 10, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3082 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3083 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 3084 | |
| 3085 | { |
| 3086 | SCOPED_TRACE("before anything"); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3087 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3088 | mCapture->expectChildColor(64, 64); |
| 3089 | } |
| 3090 | } |
| 3091 | void TearDown() override { |
| 3092 | LayerUpdateTest::TearDown(); |
| 3093 | mChild = 0; |
| 3094 | } |
| 3095 | |
| 3096 | sp<SurfaceControl> mChild; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3097 | std::unique_ptr<ScreenCapture> mCapture; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3098 | }; |
| 3099 | |
| 3100 | TEST_F(ChildLayerTest, ChildLayerPositioning) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3101 | asTransaction([&](Transaction& t) { |
| 3102 | t.show(mChild); |
| 3103 | t.setPosition(mChild, 10, 10); |
| 3104 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3105 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3106 | |
| 3107 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3108 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3109 | // Top left of foreground must now be visible |
| 3110 | mCapture->expectFGColor(64, 64); |
| 3111 | // But 10 pixels in we should see the child surface |
| 3112 | mCapture->expectChildColor(74, 74); |
| 3113 | // And 10 more pixels we should be back to the foreground surface |
| 3114 | mCapture->expectFGColor(84, 84); |
| 3115 | } |
| 3116 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3117 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3118 | |
| 3119 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3120 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3121 | // Top left of foreground should now be at 0, 0 |
| 3122 | mCapture->expectFGColor(0, 0); |
| 3123 | // But 10 pixels in we should see the child surface |
| 3124 | mCapture->expectChildColor(10, 10); |
| 3125 | // And 10 more pixels we should be back to the foreground surface |
| 3126 | mCapture->expectFGColor(20, 20); |
| 3127 | } |
| 3128 | } |
| 3129 | |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 3130 | TEST_F(ChildLayerTest, ChildLayerCropping) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3131 | asTransaction([&](Transaction& t) { |
| 3132 | t.show(mChild); |
| 3133 | t.setPosition(mChild, 0, 0); |
| 3134 | t.setPosition(mFGSurfaceControl, 0, 0); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3135 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 5, 5)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3136 | }); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 3137 | |
| 3138 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3139 | mCapture = screenshot(); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 3140 | mCapture->expectChildColor(0, 0); |
| 3141 | mCapture->expectChildColor(4, 4); |
| 3142 | mCapture->expectBGColor(5, 5); |
| 3143 | } |
| 3144 | } |
| 3145 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3146 | TEST_F(ChildLayerTest, ChildLayerConstraints) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3147 | asTransaction([&](Transaction& t) { |
| 3148 | t.show(mChild); |
| 3149 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 3150 | t.setPosition(mChild, 63, 63); |
| 3151 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3152 | |
| 3153 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3154 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3155 | mCapture->expectFGColor(0, 0); |
| 3156 | // Last pixel in foreground should now be the child. |
| 3157 | mCapture->expectChildColor(63, 63); |
| 3158 | // But the child should be constrained and the next pixel |
| 3159 | // must be the background |
| 3160 | mCapture->expectBGColor(64, 64); |
| 3161 | } |
| 3162 | } |
| 3163 | |
| 3164 | TEST_F(ChildLayerTest, ChildLayerScaling) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3165 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3166 | |
| 3167 | // Find the boundary between the parent and child |
| 3168 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3169 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3170 | mCapture->expectChildColor(9, 9); |
| 3171 | mCapture->expectFGColor(10, 10); |
| 3172 | } |
| 3173 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3174 | asTransaction([&](Transaction& t) { t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3175 | |
| 3176 | // The boundary should be twice as far from the origin now. |
| 3177 | // The pixels from the last test should all be child now |
| 3178 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3179 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3180 | mCapture->expectChildColor(9, 9); |
| 3181 | mCapture->expectChildColor(10, 10); |
| 3182 | mCapture->expectChildColor(19, 19); |
| 3183 | mCapture->expectFGColor(20, 20); |
| 3184 | } |
| 3185 | } |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3186 | |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3187 | TEST_F(ChildLayerTest, ChildLayerAlpha) { |
| 3188 | fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254); |
| 3189 | fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0); |
| 3190 | fillSurfaceRGBA8(mChild, 0, 254, 0); |
| 3191 | waitForPostedBuffers(); |
| 3192 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3193 | asTransaction([&](Transaction& t) { |
| 3194 | t.show(mChild); |
| 3195 | t.setPosition(mChild, 0, 0); |
| 3196 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 3197 | }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3198 | |
| 3199 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3200 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3201 | // Unblended child color |
| 3202 | mCapture->checkPixel(0, 0, 0, 254, 0); |
| 3203 | } |
| 3204 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3205 | asTransaction([&](Transaction& t) { t.setAlpha(mChild, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3206 | |
| 3207 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3208 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3209 | // Child and BG blended. |
| 3210 | mCapture->checkPixel(0, 0, 127, 127, 0); |
| 3211 | } |
| 3212 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3213 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3214 | |
| 3215 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3216 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3217 | // Child and BG blended. |
| 3218 | mCapture->checkPixel(0, 0, 95, 64, 95); |
| 3219 | } |
| 3220 | } |
| 3221 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3222 | TEST_F(ChildLayerTest, ReparentChildren) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3223 | asTransaction([&](Transaction& t) { |
| 3224 | t.show(mChild); |
| 3225 | t.setPosition(mChild, 10, 10); |
| 3226 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3227 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3228 | |
| 3229 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3230 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3231 | // Top left of foreground must now be visible |
| 3232 | mCapture->expectFGColor(64, 64); |
| 3233 | // But 10 pixels in we should see the child surface |
| 3234 | mCapture->expectChildColor(74, 74); |
| 3235 | // And 10 more pixels we should be back to the foreground surface |
| 3236 | mCapture->expectFGColor(84, 84); |
| 3237 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3238 | |
| 3239 | asTransaction([&](Transaction& t) { |
| 3240 | t.reparentChildren(mFGSurfaceControl, mBGSurfaceControl->getHandle()); |
| 3241 | }); |
| 3242 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3243 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3244 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3245 | mCapture->expectFGColor(64, 64); |
| 3246 | // In reparenting we should have exposed the entire foreground surface. |
| 3247 | mCapture->expectFGColor(74, 74); |
| 3248 | // And the child layer should now begin at 10, 10 (since the BG |
| 3249 | // layer is at (0, 0)). |
| 3250 | mCapture->expectBGColor(9, 9); |
| 3251 | mCapture->expectChildColor(10, 10); |
| 3252 | } |
| 3253 | } |
| 3254 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 3255 | TEST_F(ChildLayerTest, ChildrenSurviveParentDestruction) { |
| 3256 | sp<SurfaceControl> mGrandChild = |
| 3257 | mClient->createSurface(String8("Grand Child"), 10, 10, |
| 3258 | PIXEL_FORMAT_RGBA_8888, 0, mChild.get()); |
| 3259 | fillSurfaceRGBA8(mGrandChild, 111, 111, 111); |
| 3260 | |
| 3261 | { |
| 3262 | SCOPED_TRACE("Grandchild visible"); |
| 3263 | ScreenCapture::captureScreen(&mCapture); |
| 3264 | mCapture->checkPixel(64, 64, 111, 111, 111); |
| 3265 | } |
| 3266 | |
| 3267 | mChild->clear(); |
| 3268 | |
| 3269 | { |
| 3270 | SCOPED_TRACE("After destroying child"); |
| 3271 | ScreenCapture::captureScreen(&mCapture); |
| 3272 | mCapture->expectFGColor(64, 64); |
| 3273 | } |
| 3274 | |
| 3275 | asTransaction([&](Transaction& t) { |
| 3276 | t.reparent(mGrandChild, mFGSurfaceControl->getHandle()); |
| 3277 | }); |
| 3278 | |
| 3279 | { |
| 3280 | SCOPED_TRACE("After reparenting grandchild"); |
| 3281 | ScreenCapture::captureScreen(&mCapture); |
| 3282 | mCapture->checkPixel(64, 64, 111, 111, 111); |
| 3283 | } |
| 3284 | } |
| 3285 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3286 | TEST_F(ChildLayerTest, DetachChildrenSameClient) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3287 | asTransaction([&](Transaction& t) { |
| 3288 | t.show(mChild); |
| 3289 | t.setPosition(mChild, 10, 10); |
| 3290 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3291 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3292 | |
| 3293 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3294 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3295 | // Top left of foreground must now be visible |
| 3296 | mCapture->expectFGColor(64, 64); |
| 3297 | // But 10 pixels in we should see the child surface |
| 3298 | mCapture->expectChildColor(74, 74); |
| 3299 | // And 10 more pixels we should be back to the foreground surface |
| 3300 | mCapture->expectFGColor(84, 84); |
| 3301 | } |
| 3302 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3303 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3304 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3305 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3306 | asTransaction([&](Transaction& t) { t.hide(mChild); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3307 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3308 | // Since the child has the same client as the parent, it will not get |
| 3309 | // detached and will be hidden. |
| 3310 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3311 | mCapture = screenshot(); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3312 | mCapture->expectFGColor(64, 64); |
| 3313 | mCapture->expectFGColor(74, 74); |
| 3314 | mCapture->expectFGColor(84, 84); |
| 3315 | } |
| 3316 | } |
| 3317 | |
| 3318 | TEST_F(ChildLayerTest, DetachChildrenDifferentClient) { |
| 3319 | sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient; |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3320 | sp<SurfaceControl> mChildNewClient = |
| 3321 | mNewComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, |
| 3322 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3323 | |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 3324 | ASSERT_TRUE(mChildNewClient != nullptr); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3325 | ASSERT_TRUE(mChildNewClient->isValid()); |
| 3326 | |
| 3327 | fillSurfaceRGBA8(mChildNewClient, 200, 200, 200); |
| 3328 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3329 | asTransaction([&](Transaction& t) { |
| 3330 | t.hide(mChild); |
| 3331 | t.show(mChildNewClient); |
| 3332 | t.setPosition(mChildNewClient, 10, 10); |
| 3333 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3334 | }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3335 | |
| 3336 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3337 | mCapture = screenshot(); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3338 | // Top left of foreground must now be visible |
| 3339 | mCapture->expectFGColor(64, 64); |
| 3340 | // But 10 pixels in we should see the child surface |
| 3341 | mCapture->expectChildColor(74, 74); |
| 3342 | // And 10 more pixels we should be back to the foreground surface |
| 3343 | mCapture->expectFGColor(84, 84); |
| 3344 | } |
| 3345 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3346 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3347 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3348 | asTransaction([&](Transaction& t) { t.hide(mChildNewClient); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3349 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3350 | // Nothing should have changed. |
| 3351 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3352 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3353 | mCapture->expectFGColor(64, 64); |
| 3354 | mCapture->expectChildColor(74, 74); |
| 3355 | mCapture->expectFGColor(84, 84); |
| 3356 | } |
| 3357 | } |
| 3358 | |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3359 | TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3360 | asTransaction([&](Transaction& t) { |
| 3361 | t.show(mChild); |
| 3362 | t.setPosition(mChild, 0, 0); |
| 3363 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 3364 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3365 | |
| 3366 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3367 | mCapture = screenshot(); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3368 | // We've positioned the child in the top left. |
| 3369 | mCapture->expectChildColor(0, 0); |
| 3370 | // But it's only 10x10. |
| 3371 | mCapture->expectFGColor(10, 10); |
| 3372 | } |
| 3373 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3374 | asTransaction([&](Transaction& t) { |
| 3375 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 3376 | // We cause scaling by 2. |
| 3377 | t.setSize(mFGSurfaceControl, 128, 128); |
| 3378 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3379 | |
| 3380 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3381 | mCapture = screenshot(); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3382 | // We've positioned the child in the top left. |
| 3383 | mCapture->expectChildColor(0, 0); |
| 3384 | mCapture->expectChildColor(10, 10); |
| 3385 | mCapture->expectChildColor(19, 19); |
| 3386 | // And now it should be scaled all the way to 20x20 |
| 3387 | mCapture->expectFGColor(20, 20); |
| 3388 | } |
| 3389 | } |
| 3390 | |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3391 | // Regression test for b/37673612 |
| 3392 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3393 | asTransaction([&](Transaction& t) { |
| 3394 | t.show(mChild); |
| 3395 | t.setPosition(mChild, 0, 0); |
| 3396 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 3397 | }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3398 | |
| 3399 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3400 | mCapture = screenshot(); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3401 | // We've positioned the child in the top left. |
| 3402 | mCapture->expectChildColor(0, 0); |
| 3403 | // But it's only 10x10. |
| 3404 | mCapture->expectFGColor(10, 10); |
| 3405 | } |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3406 | // We set things up as in b/37673612 so that there is a mismatch between the buffer size and |
| 3407 | // the WM specified state size. |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3408 | asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3409 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 3410 | auto anw = static_cast<ANativeWindow*>(s.get()); |
| 3411 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 3412 | native_window_set_buffers_dimensions(anw, 64, 128); |
| 3413 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 3414 | waitForPostedBuffers(); |
| 3415 | |
| 3416 | { |
| 3417 | // The child should still be in the same place and not have any strange scaling as in |
| 3418 | // b/37673612. |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3419 | mCapture = screenshot(); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3420 | mCapture->expectChildColor(0, 0); |
| 3421 | mCapture->expectFGColor(10, 10); |
| 3422 | } |
| 3423 | } |
| 3424 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 3425 | TEST_F(ChildLayerTest, Bug36858924) { |
| 3426 | // Destroy the child layer |
| 3427 | mChild.clear(); |
| 3428 | |
| 3429 | // Now recreate it as hidden |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3430 | mChild = mClient->createSurface(String8("Child surface"), 10, 10, |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 3431 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eHidden, |
| 3432 | mFGSurfaceControl.get()); |
| 3433 | |
| 3434 | // Show the child layer in a deferred transaction |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3435 | asTransaction([&](Transaction& t) { |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3436 | t.deferTransactionUntil_legacy(mChild, mFGSurfaceControl->getHandle(), |
| 3437 | mFGSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3438 | t.show(mChild); |
| 3439 | }); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 3440 | |
| 3441 | // Render the foreground surface a few times |
| 3442 | // |
| 3443 | // Prior to the bugfix for b/36858924, this would usually hang while trying to fill the third |
| 3444 | // frame because SurfaceFlinger would never process the deferred transaction and would therefore |
| 3445 | // never acquire/release the first buffer |
| 3446 | ALOGI("Filling 1"); |
| 3447 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 3448 | ALOGI("Filling 2"); |
| 3449 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 0, 255); |
| 3450 | ALOGI("Filling 3"); |
| 3451 | fillSurfaceRGBA8(mFGSurfaceControl, 255, 0, 0); |
| 3452 | ALOGI("Filling 4"); |
| 3453 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 3454 | } |
| 3455 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3456 | TEST_F(ChildLayerTest, Reparent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3457 | asTransaction([&](Transaction& t) { |
| 3458 | t.show(mChild); |
| 3459 | t.setPosition(mChild, 10, 10); |
| 3460 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3461 | }); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 3462 | |
| 3463 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3464 | mCapture = screenshot(); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 3465 | // Top left of foreground must now be visible |
| 3466 | mCapture->expectFGColor(64, 64); |
| 3467 | // But 10 pixels in we should see the child surface |
| 3468 | mCapture->expectChildColor(74, 74); |
| 3469 | // And 10 more pixels we should be back to the foreground surface |
| 3470 | mCapture->expectFGColor(84, 84); |
| 3471 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3472 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3473 | asTransaction([&](Transaction& t) { t.reparent(mChild, mBGSurfaceControl->getHandle()); }); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3474 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 3475 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3476 | mCapture = screenshot(); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 3477 | mCapture->expectFGColor(64, 64); |
| 3478 | // In reparenting we should have exposed the entire foreground surface. |
| 3479 | mCapture->expectFGColor(74, 74); |
| 3480 | // And the child layer should now begin at 10, 10 (since the BG |
| 3481 | // layer is at (0, 0)). |
| 3482 | mCapture->expectBGColor(9, 9); |
| 3483 | mCapture->expectChildColor(10, 10); |
| 3484 | } |
| 3485 | } |
| 3486 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3487 | TEST_F(ChildLayerTest, ReparentToNoParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3488 | asTransaction([&](Transaction& t) { |
| 3489 | t.show(mChild); |
| 3490 | t.setPosition(mChild, 10, 10); |
| 3491 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3492 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3493 | |
| 3494 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3495 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3496 | // Top left of foreground must now be visible |
| 3497 | mCapture->expectFGColor(64, 64); |
| 3498 | // But 10 pixels in we should see the child surface |
| 3499 | mCapture->expectChildColor(74, 74); |
| 3500 | // And 10 more pixels we should be back to the foreground surface |
| 3501 | mCapture->expectFGColor(84, 84); |
| 3502 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3503 | asTransaction([&](Transaction& t) { t.reparent(mChild, nullptr); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3504 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3505 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3506 | // Nothing should have changed. |
| 3507 | mCapture->expectFGColor(64, 64); |
| 3508 | mCapture->expectChildColor(74, 74); |
| 3509 | mCapture->expectFGColor(84, 84); |
| 3510 | } |
| 3511 | } |
| 3512 | |
| 3513 | TEST_F(ChildLayerTest, ReparentFromNoParent) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3514 | sp<SurfaceControl> newSurface = createLayer(String8("New Surface"), 10, 10, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 3515 | ASSERT_TRUE(newSurface != nullptr); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3516 | ASSERT_TRUE(newSurface->isValid()); |
| 3517 | |
| 3518 | fillSurfaceRGBA8(newSurface, 63, 195, 63); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3519 | asTransaction([&](Transaction& t) { |
| 3520 | t.hide(mChild); |
| 3521 | t.show(newSurface); |
| 3522 | t.setPosition(newSurface, 10, 10); |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3523 | t.setLayer(newSurface, INT32_MAX - 2); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3524 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3525 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3526 | |
| 3527 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3528 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3529 | // Top left of foreground must now be visible |
| 3530 | mCapture->expectFGColor(64, 64); |
| 3531 | // At 10, 10 we should see the new surface |
| 3532 | mCapture->checkPixel(10, 10, 63, 195, 63); |
| 3533 | } |
| 3534 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3535 | asTransaction([&](Transaction& t) { t.reparent(newSurface, mFGSurfaceControl->getHandle()); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3536 | |
| 3537 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3538 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3539 | // newSurface will now be a child of mFGSurface so it will be 10, 10 offset from |
| 3540 | // mFGSurface, putting it at 74, 74. |
| 3541 | mCapture->expectFGColor(64, 64); |
| 3542 | mCapture->checkPixel(74, 74, 63, 195, 63); |
| 3543 | mCapture->expectFGColor(84, 84); |
| 3544 | } |
| 3545 | } |
| 3546 | |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 3547 | TEST_F(ChildLayerTest, NestedChildren) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3548 | sp<SurfaceControl> grandchild = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3549 | mClient->createSurface(String8("Grandchild surface"), 10, 10, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3550 | PIXEL_FORMAT_RGBA_8888, 0, mChild.get()); |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 3551 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 3552 | |
| 3553 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3554 | mCapture = screenshot(); |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 3555 | // Expect the grandchild to begin at 64, 64 because it's a child of mChild layer |
| 3556 | // which begins at 64, 64 |
| 3557 | mCapture->checkPixel(64, 64, 50, 50, 50); |
| 3558 | } |
| 3559 | } |
| 3560 | |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 3561 | TEST_F(ChildLayerTest, ChildLayerRelativeLayer) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3562 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 128, 128, 0); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 3563 | fillSurfaceRGBA8(relative, 255, 255, 255); |
| 3564 | |
| 3565 | Transaction t; |
| 3566 | t.setLayer(relative, INT32_MAX) |
| 3567 | .setRelativeLayer(mChild, relative->getHandle(), 1) |
| 3568 | .setPosition(mFGSurfaceControl, 0, 0) |
| 3569 | .apply(true); |
| 3570 | |
| 3571 | // We expect that the child should have been elevated above our |
| 3572 | // INT_MAX layer even though it's not a child of it. |
| 3573 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3574 | mCapture = screenshot(); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 3575 | mCapture->expectChildColor(0, 0); |
| 3576 | mCapture->expectChildColor(9, 9); |
| 3577 | mCapture->checkPixel(10, 10, 255, 255, 255); |
| 3578 | } |
| 3579 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3580 | class BoundlessLayerTest : public LayerUpdateTest { |
| 3581 | protected: |
| 3582 | std::unique_ptr<ScreenCapture> mCapture; |
| 3583 | }; |
| 3584 | |
| 3585 | // Verify setting a size on a buffer layer has no effect. |
| 3586 | TEST_F(BoundlessLayerTest, BufferLayerIgnoresSize) { |
| 3587 | sp<SurfaceControl> bufferLayer = |
| 3588 | mClient->createSurface(String8("BufferLayer"), 45, 45, PIXEL_FORMAT_RGBA_8888, 0, |
| 3589 | mFGSurfaceControl.get()); |
| 3590 | ASSERT_TRUE(bufferLayer != nullptr); |
| 3591 | ASSERT_TRUE(bufferLayer->isValid()); |
| 3592 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::BLACK, 30, 30)); |
| 3593 | asTransaction([&](Transaction& t) { t.show(bufferLayer); }); |
| 3594 | { |
| 3595 | mCapture = screenshot(); |
| 3596 | // Top left of background must now be visible |
| 3597 | mCapture->expectBGColor(0, 0); |
| 3598 | // Foreground Surface bounds must be color layer |
| 3599 | mCapture->expectColor(Rect(64, 64, 94, 94), Color::BLACK); |
| 3600 | // Buffer layer should not extend past buffer bounds |
| 3601 | mCapture->expectFGColor(95, 95); |
| 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | // Verify a boundless color layer will fill its parent bounds. The parent has a buffer size |
| 3606 | // which will crop the color layer. |
| 3607 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentBufferBounds) { |
| 3608 | sp<SurfaceControl> colorLayer = |
| 3609 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3610 | ISurfaceComposerClient::eFXSurfaceColor, |
| 3611 | mFGSurfaceControl.get()); |
| 3612 | ASSERT_TRUE(colorLayer != nullptr); |
| 3613 | ASSERT_TRUE(colorLayer->isValid()); |
| 3614 | asTransaction([&](Transaction& t) { |
| 3615 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3616 | t.show(colorLayer); |
| 3617 | }); |
| 3618 | { |
| 3619 | mCapture = screenshot(); |
| 3620 | // Top left of background must now be visible |
| 3621 | mCapture->expectBGColor(0, 0); |
| 3622 | // Foreground Surface bounds must be color layer |
| 3623 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 3624 | // Color layer should not extend past foreground bounds |
| 3625 | mCapture->expectBGColor(129, 129); |
| 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | // Verify a boundless color layer will fill its parent bounds. The parent has no buffer but has |
| 3630 | // a crop which will be used to crop the color layer. |
| 3631 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentCropBounds) { |
| 3632 | sp<SurfaceControl> cropLayer = |
| 3633 | mClient->createSurface(String8("CropLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3634 | 0 /* flags */, mFGSurfaceControl.get()); |
| 3635 | ASSERT_TRUE(cropLayer != nullptr); |
| 3636 | ASSERT_TRUE(cropLayer->isValid()); |
| 3637 | sp<SurfaceControl> colorLayer = |
| 3638 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3639 | ISurfaceComposerClient::eFXSurfaceColor, cropLayer.get()); |
| 3640 | ASSERT_TRUE(colorLayer != nullptr); |
| 3641 | ASSERT_TRUE(colorLayer->isValid()); |
| 3642 | asTransaction([&](Transaction& t) { |
| 3643 | t.setCrop_legacy(cropLayer, Rect(5, 5, 10, 10)); |
| 3644 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3645 | t.show(cropLayer); |
| 3646 | t.show(colorLayer); |
| 3647 | }); |
| 3648 | { |
| 3649 | mCapture = screenshot(); |
| 3650 | // Top left of background must now be visible |
| 3651 | mCapture->expectBGColor(0, 0); |
| 3652 | // Top left of foreground must now be visible |
| 3653 | mCapture->expectFGColor(64, 64); |
| 3654 | // 5 pixels from the foreground we should see the child surface |
| 3655 | mCapture->expectColor(Rect(69, 69, 74, 74), Color::BLACK); |
| 3656 | // 10 pixels from the foreground we should be back to the foreground surface |
| 3657 | mCapture->expectFGColor(74, 74); |
| 3658 | } |
| 3659 | } |
| 3660 | |
| 3661 | // Verify for boundless layer with no children, their transforms have no effect. |
| 3662 | TEST_F(BoundlessLayerTest, BoundlessColorLayerTransformHasNoEffect) { |
| 3663 | sp<SurfaceControl> colorLayer = |
| 3664 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3665 | ISurfaceComposerClient::eFXSurfaceColor, |
| 3666 | mFGSurfaceControl.get()); |
| 3667 | ASSERT_TRUE(colorLayer != nullptr); |
| 3668 | ASSERT_TRUE(colorLayer->isValid()); |
| 3669 | asTransaction([&](Transaction& t) { |
| 3670 | t.setPosition(colorLayer, 320, 320); |
| 3671 | t.setMatrix(colorLayer, 2, 0, 0, 2); |
| 3672 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3673 | t.show(colorLayer); |
| 3674 | }); |
| 3675 | { |
| 3676 | mCapture = screenshot(); |
| 3677 | // Top left of background must now be visible |
| 3678 | mCapture->expectBGColor(0, 0); |
| 3679 | // Foreground Surface bounds must be color layer |
| 3680 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 3681 | // Color layer should not extend past foreground bounds |
| 3682 | mCapture->expectBGColor(129, 129); |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | // Verify for boundless layer with children, their transforms have an effect. |
| 3687 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerCanSetTransform) { |
| 3688 | sp<SurfaceControl> boundlessLayerRightShift = |
| 3689 | mClient->createSurface(String8("BoundlessLayerRightShift"), 0, 0, |
| 3690 | PIXEL_FORMAT_RGBA_8888, 0 /* flags */, mFGSurfaceControl.get()); |
| 3691 | ASSERT_TRUE(boundlessLayerRightShift != nullptr); |
| 3692 | ASSERT_TRUE(boundlessLayerRightShift->isValid()); |
| 3693 | sp<SurfaceControl> boundlessLayerDownShift = |
| 3694 | mClient->createSurface(String8("BoundlessLayerLeftShift"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3695 | 0 /* flags */, boundlessLayerRightShift.get()); |
| 3696 | ASSERT_TRUE(boundlessLayerDownShift != nullptr); |
| 3697 | ASSERT_TRUE(boundlessLayerDownShift->isValid()); |
| 3698 | sp<SurfaceControl> colorLayer = |
| 3699 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3700 | ISurfaceComposerClient::eFXSurfaceColor, |
| 3701 | boundlessLayerDownShift.get()); |
| 3702 | ASSERT_TRUE(colorLayer != nullptr); |
| 3703 | ASSERT_TRUE(colorLayer->isValid()); |
| 3704 | asTransaction([&](Transaction& t) { |
| 3705 | t.setPosition(boundlessLayerRightShift, 32, 0); |
| 3706 | t.show(boundlessLayerRightShift); |
| 3707 | t.setPosition(boundlessLayerDownShift, 0, 32); |
| 3708 | t.show(boundlessLayerDownShift); |
| 3709 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 3710 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3711 | t.show(colorLayer); |
| 3712 | }); |
| 3713 | { |
| 3714 | mCapture = screenshot(); |
| 3715 | // Top left of background must now be visible |
| 3716 | mCapture->expectBGColor(0, 0); |
| 3717 | // Top left of foreground must now be visible |
| 3718 | mCapture->expectFGColor(64, 64); |
| 3719 | // Foreground Surface bounds must be color layer |
| 3720 | mCapture->expectColor(Rect(96, 96, 128, 128), Color::BLACK); |
| 3721 | // Color layer should not extend past foreground bounds |
| 3722 | mCapture->expectBGColor(129, 129); |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | // Verify child layers do not get clipped if they temporarily move into the negative |
| 3727 | // coordinate space as the result of an intermediate transformation. |
| 3728 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerDoNotCrop) { |
| 3729 | sp<SurfaceControl> boundlessLayer = |
| 3730 | mClient->createSurface(String8("BoundlessLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3731 | 0 /* flags */, mFGSurfaceControl.get()); |
| 3732 | ASSERT_TRUE(boundlessLayer != nullptr); |
| 3733 | ASSERT_TRUE(boundlessLayer->isValid()); |
| 3734 | sp<SurfaceControl> colorLayer = |
| 3735 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3736 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayer.get()); |
| 3737 | ASSERT_TRUE(colorLayer != nullptr); |
| 3738 | ASSERT_TRUE(colorLayer->isValid()); |
| 3739 | asTransaction([&](Transaction& t) { |
| 3740 | // shift child layer off bounds. If this layer was not boundless, we will |
| 3741 | // expect the child layer to be cropped. |
| 3742 | t.setPosition(boundlessLayer, 32, 32); |
| 3743 | t.show(boundlessLayer); |
| 3744 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 3745 | // undo shift by parent |
| 3746 | t.setPosition(colorLayer, -32, -32); |
| 3747 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3748 | t.show(colorLayer); |
| 3749 | }); |
| 3750 | { |
| 3751 | mCapture = screenshot(); |
| 3752 | // Top left of background must now be visible |
| 3753 | mCapture->expectBGColor(0, 0); |
| 3754 | // Foreground Surface bounds must be color layer |
| 3755 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 3756 | // Color layer should not extend past foreground bounds |
| 3757 | mCapture->expectBGColor(129, 129); |
| 3758 | } |
| 3759 | } |
| 3760 | |
| 3761 | // Verify for boundless root layers with children, their transforms have an effect. |
| 3762 | TEST_F(BoundlessLayerTest, RootBoundlessLayerCanSetTransform) { |
| 3763 | sp<SurfaceControl> rootBoundlessLayer = |
| 3764 | mClient->createSurface(String8("RootBoundlessLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3765 | 0 /* flags */); |
| 3766 | ASSERT_TRUE(rootBoundlessLayer != nullptr); |
| 3767 | ASSERT_TRUE(rootBoundlessLayer->isValid()); |
| 3768 | sp<SurfaceControl> colorLayer = |
| 3769 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3770 | ISurfaceComposerClient::eFXSurfaceColor, |
| 3771 | rootBoundlessLayer.get()); |
| 3772 | ASSERT_TRUE(colorLayer != nullptr); |
| 3773 | ASSERT_TRUE(colorLayer->isValid()); |
| 3774 | asTransaction([&](Transaction& t) { |
| 3775 | t.setLayer(rootBoundlessLayer, INT32_MAX - 1); |
| 3776 | t.setPosition(rootBoundlessLayer, 32, 32); |
| 3777 | t.show(rootBoundlessLayer); |
| 3778 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 3779 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3780 | t.show(colorLayer); |
| 3781 | t.hide(mFGSurfaceControl); |
| 3782 | }); |
| 3783 | { |
| 3784 | mCapture = screenshot(); |
| 3785 | // Top left of background must now be visible |
| 3786 | mCapture->expectBGColor(0, 0); |
| 3787 | // Top left of foreground must now be visible |
| 3788 | mCapture->expectBGColor(31, 31); |
| 3789 | // Foreground Surface bounds must be color layer |
| 3790 | mCapture->expectColor(Rect(32, 32, 96, 96), Color::BLACK); |
| 3791 | // Color layer should not extend past foreground bounds |
| 3792 | mCapture->expectBGColor(97, 97); |
| 3793 | } |
| 3794 | } |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 3795 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3796 | class ScreenCaptureTest : public LayerUpdateTest { |
| 3797 | protected: |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 3798 | std::unique_ptr<ScreenCapture> mCapture; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3799 | }; |
| 3800 | |
| 3801 | TEST_F(ScreenCaptureTest, CaptureSingleLayer) { |
| 3802 | auto bgHandle = mBGSurfaceControl->getHandle(); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 3803 | ScreenCapture::captureLayers(&mCapture, bgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3804 | mCapture->expectBGColor(0, 0); |
| 3805 | // Doesn't capture FG layer which is at 64, 64 |
| 3806 | mCapture->expectBGColor(64, 64); |
| 3807 | } |
| 3808 | |
| 3809 | TEST_F(ScreenCaptureTest, CaptureLayerWithChild) { |
| 3810 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3811 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3812 | sp<SurfaceControl> child = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3813 | mClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3814 | 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3815 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3816 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3817 | SurfaceComposerClient::Transaction().show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3818 | |
| 3819 | // Captures mFGSurfaceControl layer and its child. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 3820 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3821 | mCapture->expectFGColor(10, 10); |
| 3822 | mCapture->expectChildColor(0, 0); |
| 3823 | } |
| 3824 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 3825 | TEST_F(ScreenCaptureTest, CaptureLayerChildOnly) { |
| 3826 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3827 | |
| 3828 | sp<SurfaceControl> child = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3829 | mClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 3830 | 0, mFGSurfaceControl.get()); |
| 3831 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3832 | |
| 3833 | SurfaceComposerClient::Transaction().show(child).apply(true); |
| 3834 | |
| 3835 | // Captures mFGSurfaceControl's child |
| 3836 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); |
| 3837 | mCapture->checkPixel(10, 10, 0, 0, 0); |
| 3838 | mCapture->expectChildColor(0, 0); |
| 3839 | } |
| 3840 | |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 3841 | TEST_F(ScreenCaptureTest, CaptureTransparent) { |
| 3842 | sp<SurfaceControl> child = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3843 | mClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 3844 | 0, mFGSurfaceControl.get()); |
| 3845 | |
| 3846 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3847 | |
| 3848 | SurfaceComposerClient::Transaction().show(child).apply(true); |
| 3849 | |
| 3850 | auto childHandle = child->getHandle(); |
| 3851 | |
| 3852 | // Captures child |
| 3853 | ScreenCapture::captureLayers(&mCapture, childHandle, {0, 0, 10, 20}); |
| 3854 | mCapture->expectColor(Rect(0, 0, 9, 9), {200, 200, 200, 255}); |
| 3855 | // Area outside of child's bounds is transparent. |
| 3856 | mCapture->expectColor(Rect(0, 10, 9, 19), {0, 0, 0, 0}); |
| 3857 | } |
| 3858 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 3859 | TEST_F(ScreenCaptureTest, DontCaptureRelativeOutsideTree) { |
| 3860 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3861 | |
| 3862 | sp<SurfaceControl> child = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3863 | mClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 3864 | 0, mFGSurfaceControl.get()); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3865 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 10, 10, 0); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 3866 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3867 | fillSurfaceRGBA8(relative, 100, 100, 100); |
| 3868 | |
| 3869 | SurfaceComposerClient::Transaction() |
| 3870 | .show(child) |
| 3871 | // Set relative layer above fg layer so should be shown above when computing all layers. |
| 3872 | .setRelativeLayer(relative, fgHandle, 1) |
| 3873 | .show(relative) |
| 3874 | .apply(true); |
| 3875 | |
| 3876 | // Captures mFGSurfaceControl layer and its child. Relative layer shouldn't be captured. |
| 3877 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
| 3878 | mCapture->expectFGColor(10, 10); |
| 3879 | mCapture->expectChildColor(0, 0); |
| 3880 | } |
| 3881 | |
| 3882 | TEST_F(ScreenCaptureTest, CaptureRelativeInTree) { |
| 3883 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3884 | |
| 3885 | sp<SurfaceControl> child = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3886 | mClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 3887 | 0, mFGSurfaceControl.get()); |
| 3888 | sp<SurfaceControl> relative = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3889 | mClient->createSurface(String8("Relative surface"), 10, 10, |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 3890 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 3891 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3892 | fillSurfaceRGBA8(relative, 100, 100, 100); |
| 3893 | |
| 3894 | SurfaceComposerClient::Transaction() |
| 3895 | .show(child) |
| 3896 | // Set relative layer below fg layer but relative to child layer so it should be shown |
| 3897 | // above child layer. |
| 3898 | .setLayer(relative, -1) |
| 3899 | .setRelativeLayer(relative, child->getHandle(), 1) |
| 3900 | .show(relative) |
| 3901 | .apply(true); |
| 3902 | |
| 3903 | // Captures mFGSurfaceControl layer and its children. Relative layer is a child of fg so its |
| 3904 | // relative value should be taken into account, placing it above child layer. |
| 3905 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
| 3906 | mCapture->expectFGColor(10, 10); |
| 3907 | // Relative layer is showing on top of child layer |
| 3908 | mCapture->expectColor(Rect(0, 0, 9, 9), {100, 100, 100, 255}); |
| 3909 | } |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 3910 | |
| 3911 | // In the following tests we verify successful skipping of a parent layer, |
| 3912 | // so we use the same verification logic and only change how we mutate |
| 3913 | // the parent layer to verify that various properties are ignored. |
| 3914 | class ScreenCaptureChildOnlyTest : public LayerUpdateTest { |
| 3915 | public: |
| 3916 | void SetUp() override { |
| 3917 | LayerUpdateTest::SetUp(); |
| 3918 | |
| 3919 | mChild = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3920 | mClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 3921 | 0, mFGSurfaceControl.get()); |
| 3922 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 3923 | |
| 3924 | SurfaceComposerClient::Transaction().show(mChild).apply(true); |
| 3925 | } |
| 3926 | |
| 3927 | void verify() { |
| 3928 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3929 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); |
| 3930 | mCapture->checkPixel(10, 10, 0, 0, 0); |
| 3931 | mCapture->expectChildColor(0, 0); |
| 3932 | } |
| 3933 | |
| 3934 | std::unique_ptr<ScreenCapture> mCapture; |
| 3935 | sp<SurfaceControl> mChild; |
| 3936 | }; |
| 3937 | |
| 3938 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentVisibility) { |
| 3939 | |
| 3940 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); |
| 3941 | |
| 3942 | // Even though the parent is hidden we should still capture the child. |
| 3943 | verify(); |
| 3944 | } |
| 3945 | |
| 3946 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentCrop) { |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3947 | SurfaceComposerClient::Transaction() |
| 3948 | .setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 1, 1)) |
| 3949 | .apply(true); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 3950 | |
| 3951 | // Even though the parent is cropped out we should still capture the child. |
| 3952 | verify(); |
| 3953 | } |
| 3954 | |
| 3955 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresTransform) { |
| 3956 | |
| 3957 | SurfaceComposerClient::Transaction().setMatrix(mFGSurfaceControl, 2, 0, 0, 2); |
| 3958 | |
| 3959 | // We should not inherit the parent scaling. |
| 3960 | verify(); |
| 3961 | } |
| 3962 | |
Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 3963 | TEST_F(ScreenCaptureChildOnlyTest, RegressionTest76099859) { |
| 3964 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); |
| 3965 | |
| 3966 | // Even though the parent is hidden we should still capture the child. |
| 3967 | verify(); |
| 3968 | |
| 3969 | // Verify everything was properly hidden when rendering the full-screen. |
| 3970 | screenshot()->expectBGColor(0,0); |
| 3971 | } |
| 3972 | |
| 3973 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3974 | TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) { |
| 3975 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3976 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3977 | sp<SurfaceControl> child = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3978 | mClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3979 | 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3980 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3981 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3982 | sp<SurfaceControl> grandchild = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3983 | mClient->createSurface(String8("Grandchild surface"), 5, 5, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3984 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3985 | |
| 3986 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 3987 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3988 | .show(child) |
| 3989 | .setPosition(grandchild, 5, 5) |
| 3990 | .show(grandchild) |
| 3991 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3992 | |
| 3993 | // Captures mFGSurfaceControl, its child, and the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 3994 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3995 | mCapture->expectFGColor(10, 10); |
| 3996 | mCapture->expectChildColor(0, 0); |
| 3997 | mCapture->checkPixel(5, 5, 50, 50, 50); |
| 3998 | } |
| 3999 | |
| 4000 | TEST_F(ScreenCaptureTest, CaptureChildOnly) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4001 | sp<SurfaceControl> child = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4002 | mClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4003 | 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4004 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4005 | auto childHandle = child->getHandle(); |
| 4006 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4007 | SurfaceComposerClient::Transaction().setPosition(child, 5, 5).show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4008 | |
| 4009 | // Captures only the child layer, and not the parent. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4010 | ScreenCapture::captureLayers(&mCapture, childHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4011 | mCapture->expectChildColor(0, 0); |
| 4012 | mCapture->expectChildColor(9, 9); |
| 4013 | } |
| 4014 | |
| 4015 | TEST_F(ScreenCaptureTest, CaptureGrandchildOnly) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4016 | sp<SurfaceControl> child = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4017 | mClient->createSurface(String8("Child surface"), 10, 10, PIXEL_FORMAT_RGBA_8888, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4018 | 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4019 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4020 | auto childHandle = child->getHandle(); |
| 4021 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4022 | sp<SurfaceControl> grandchild = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4023 | mClient->createSurface(String8("Grandchild surface"), 5, 5, |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4024 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4025 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 4026 | |
| 4027 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4028 | .show(child) |
| 4029 | .setPosition(grandchild, 5, 5) |
| 4030 | .show(grandchild) |
| 4031 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4032 | |
| 4033 | auto grandchildHandle = grandchild->getHandle(); |
| 4034 | |
| 4035 | // Captures only the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4036 | ScreenCapture::captureLayers(&mCapture, grandchildHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4037 | mCapture->checkPixel(0, 0, 50, 50, 50); |
| 4038 | mCapture->checkPixel(4, 4, 50, 50, 50); |
| 4039 | } |
| 4040 | |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4041 | TEST_F(ScreenCaptureTest, CaptureCrop) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4042 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4043 | sp<SurfaceControl> blueLayer = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4044 | mClient->createSurface(String8("Blue surface"), 30, 30, PIXEL_FORMAT_RGBA_8888, |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4045 | 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4046 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4047 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
| 4048 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4049 | |
| 4050 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4051 | .setLayer(redLayer, INT32_MAX - 1) |
| 4052 | .show(redLayer) |
| 4053 | .show(blueLayer) |
| 4054 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4055 | |
| 4056 | auto redLayerHandle = redLayer->getHandle(); |
| 4057 | |
| 4058 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4059 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 4060 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 4061 | // red area below the blue area |
| 4062 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 4063 | // red area to the right of the blue area |
| 4064 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4065 | |
| 4066 | Rect crop = Rect(0, 0, 30, 30); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4067 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, crop); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4068 | // Capturing the cropped screen, cropping out the shown red area, should leave only the blue |
| 4069 | // area visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4070 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4071 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 4072 | } |
| 4073 | |
| 4074 | TEST_F(ScreenCaptureTest, CaptureSize) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4075 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4076 | sp<SurfaceControl> blueLayer = |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4077 | mClient->createSurface(String8("Blue surface"), 30, 30, PIXEL_FORMAT_RGBA_8888, |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4078 | 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4079 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4080 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
| 4081 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4082 | |
| 4083 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4084 | .setLayer(redLayer, INT32_MAX - 1) |
| 4085 | .show(redLayer) |
| 4086 | .show(blueLayer) |
| 4087 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4088 | |
| 4089 | auto redLayerHandle = redLayer->getHandle(); |
| 4090 | |
| 4091 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4092 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 4093 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 4094 | // red area below the blue area |
| 4095 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 4096 | // red area to the right of the blue area |
| 4097 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4098 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4099 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, Rect::EMPTY_RECT, 0.5); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4100 | // 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] | 4101 | mCapture->expectColor(Rect(0, 0, 14, 14), Color::BLUE); |
| 4102 | // red area below the blue area |
| 4103 | mCapture->expectColor(Rect(0, 15, 29, 29), Color::RED); |
| 4104 | // red area to the right of the blue area |
| 4105 | mCapture->expectColor(Rect(15, 0, 29, 29), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4106 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 4107 | } |
| 4108 | |
| 4109 | TEST_F(ScreenCaptureTest, CaptureInvalidLayer) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4110 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4111 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4112 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4113 | |
| 4114 | auto redLayerHandle = redLayer->getHandle(); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4115 | mClient->destroySurface(redLayerHandle); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4116 | SurfaceComposerClient::Transaction().apply(true); |
| 4117 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4118 | sp<GraphicBuffer> outBuffer; |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4119 | |
| 4120 | // Layer was deleted so captureLayers should fail with NAME_NOT_FOUND |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4121 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 4122 | 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] | 4123 | } |
| 4124 | |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 4125 | |
| 4126 | class DereferenceSurfaceControlTest : public LayerTransactionTest { |
| 4127 | protected: |
| 4128 | void SetUp() override { |
| 4129 | LayerTransactionTest::SetUp(); |
| 4130 | bgLayer = createLayer("BG layer", 20, 20); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4131 | fillBufferQueueLayerColor(bgLayer, Color::RED, 20, 20); |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 4132 | fgLayer = createLayer("FG layer", 20, 20); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4133 | fillBufferQueueLayerColor(fgLayer, Color::BLUE, 20, 20); |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 4134 | Transaction().setLayer(fgLayer, mLayerZBase + 1).apply(); |
| 4135 | { |
| 4136 | SCOPED_TRACE("before anything"); |
| 4137 | auto shot = screenshot(); |
| 4138 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); |
| 4139 | } |
| 4140 | } |
| 4141 | void TearDown() override { |
| 4142 | LayerTransactionTest::TearDown(); |
| 4143 | bgLayer = 0; |
| 4144 | fgLayer = 0; |
| 4145 | } |
| 4146 | |
| 4147 | sp<SurfaceControl> bgLayer; |
| 4148 | sp<SurfaceControl> fgLayer; |
| 4149 | }; |
| 4150 | |
| 4151 | TEST_F(DereferenceSurfaceControlTest, LayerNotInTransaction) { |
| 4152 | fgLayer = nullptr; |
| 4153 | { |
| 4154 | SCOPED_TRACE("after setting null"); |
| 4155 | auto shot = screenshot(); |
| 4156 | shot->expectColor(Rect(0, 0, 20, 20), Color::RED); |
| 4157 | } |
| 4158 | } |
| 4159 | |
| 4160 | TEST_F(DereferenceSurfaceControlTest, LayerInTransaction) { |
| 4161 | auto transaction = Transaction().show(fgLayer); |
| 4162 | fgLayer = nullptr; |
| 4163 | { |
| 4164 | SCOPED_TRACE("after setting null"); |
| 4165 | auto shot = screenshot(); |
| 4166 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); |
| 4167 | } |
| 4168 | } |
| 4169 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4170 | } // namespace android |