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