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; |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame^] | 1232 | const float cornerRadius = 20.0f; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 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 | { |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame^] | 1240 | const uint8_t bottom = size - 1; |
| 1241 | const uint8_t right = size - 1; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1242 | auto shot = screenshot(); |
| 1243 | // Transparent corners |
| 1244 | shot->expectColor(Rect(0, 0, testArea, testArea), Color::BLACK); |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame^] | 1245 | shot->expectColor(Rect(size - testArea, 0, right, testArea), Color::BLACK); |
| 1246 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); |
| 1247 | shot->expectColor(Rect(size - testArea, bottom - testArea, right, bottom), Color::BLACK); |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | TEST_P(LayerTypeTransactionTest, SetCornerRadiusChildCrop) { |
| 1252 | sp<SurfaceControl> parent; |
| 1253 | sp<SurfaceControl> child; |
| 1254 | const uint8_t size = 64; |
| 1255 | const uint8_t testArea = 4; |
| 1256 | const float cornerRadius = 20.0f; |
| 1257 | ASSERT_NO_FATAL_FAILURE(parent = createLayer("parent", size, size)); |
| 1258 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(parent, Color::RED, size, size)); |
| 1259 | ASSERT_NO_FATAL_FAILURE(child = createLayer("child", size, size / 2)); |
| 1260 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(child, Color::GREEN, size, size / 2)); |
| 1261 | |
| 1262 | Transaction() |
| 1263 | .setCornerRadius(parent, cornerRadius) |
| 1264 | .reparent(child, parent->getHandle()) |
| 1265 | .setPosition(child, 0, size / 2) |
| 1266 | .apply(); |
| 1267 | { |
| 1268 | const uint8_t bottom = size - 1; |
| 1269 | const uint8_t right = size - 1; |
| 1270 | auto shot = screenshot(); |
| 1271 | // Top edge of child should not have rounded corners because it's translated in the parent |
| 1272 | shot->expectColor(Rect(0, size / 2, right, static_cast<int>(bottom - cornerRadius)), |
| 1273 | Color::GREEN); |
| 1274 | // But bottom edges should have been clipped according to parent bounds |
| 1275 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); |
| 1276 | shot->expectColor(Rect(right - testArea, bottom - testArea, right, bottom), Color::BLACK); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1280 | TEST_F(LayerTransactionTest, SetColorBasic) { |
| 1281 | sp<SurfaceControl> bufferLayer; |
| 1282 | sp<SurfaceControl> colorLayer; |
| 1283 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1284 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1285 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 1286 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 1287 | ISurfaceComposerClient::eFXSurfaceColor)); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1288 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1289 | Transaction() |
| 1290 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 1291 | .setLayer(colorLayer, mLayerZBase + 1) |
| 1292 | .apply(); |
| 1293 | |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1294 | { |
| 1295 | SCOPED_TRACE("default color"); |
| 1296 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
| 1297 | } |
| 1298 | |
| 1299 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1300 | const Color expected = {15, 51, 85, 255}; |
| 1301 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 1302 | // channel) should be less than one |
| 1303 | const uint8_t tolerance = 1; |
| 1304 | Transaction().setColor(colorLayer, color).apply(); |
| 1305 | { |
| 1306 | SCOPED_TRACE("new color"); |
| 1307 | screenshot()->expectColor(Rect(0, 0, 32, 32), expected, tolerance); |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | TEST_F(LayerTransactionTest, SetColorClamped) { |
| 1312 | sp<SurfaceControl> colorLayer; |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1313 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 1314 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 1315 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 1316 | Transaction() |
| 1317 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 1318 | .setColor(colorLayer, half3(2.0f, -1.0f, 0.0f)) |
| 1319 | .apply(); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1320 | |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1321 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1322 | } |
| 1323 | |
| 1324 | TEST_F(LayerTransactionTest, SetColorWithAlpha) { |
| 1325 | sp<SurfaceControl> bufferLayer; |
| 1326 | sp<SurfaceControl> colorLayer; |
| 1327 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1328 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1329 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 1330 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 1331 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 1332 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1333 | |
| 1334 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1335 | const float alpha = 0.25f; |
| 1336 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); |
| 1337 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 1338 | // channel) should be less than one |
| 1339 | const uint8_t tolerance = 1; |
| 1340 | Transaction() |
| 1341 | .setColor(colorLayer, color) |
| 1342 | .setAlpha(colorLayer, alpha) |
| 1343 | .setLayer(colorLayer, mLayerZBase + 1) |
| 1344 | .apply(); |
| 1345 | screenshot()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, |
| 1346 | tolerance); |
| 1347 | } |
| 1348 | |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1349 | TEST_F(LayerTransactionTest, SetColorWithParentAlpha_Bug74220420) { |
| 1350 | sp<SurfaceControl> bufferLayer; |
| 1351 | sp<SurfaceControl> parentLayer; |
| 1352 | sp<SurfaceControl> colorLayer; |
| 1353 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
| 1354 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parentWithAlpha", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1355 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1356 | ASSERT_NO_FATAL_FAILURE(colorLayer = createLayer("childWithColor", 0 /* buffer width */, |
| 1357 | 0 /* buffer height */, |
| 1358 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 1359 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1360 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1361 | const float alpha = 0.25f; |
| 1362 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); |
| 1363 | // this is handwavy, but the precision loss scaled by 255 (8-bit per |
| 1364 | // channel) should be less than one |
| 1365 | const uint8_t tolerance = 1; |
| 1366 | Transaction() |
| 1367 | .reparent(colorLayer, parentLayer->getHandle()) |
| 1368 | .setColor(colorLayer, color) |
| 1369 | .setAlpha(parentLayer, alpha) |
| 1370 | .setLayer(parentLayer, mLayerZBase + 1) |
| 1371 | .apply(); |
| 1372 | screenshot()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, |
| 1373 | tolerance); |
| 1374 | } |
| 1375 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1376 | TEST_P(LayerTypeTransactionTest, SetColorWithBuffer) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1377 | sp<SurfaceControl> bufferLayer; |
| 1378 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1379 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED, 32, 32)); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1380 | |
| 1381 | // color is ignored |
| 1382 | Transaction().setColor(bufferLayer, half3(0.0f, 1.0f, 0.0f)).apply(); |
| 1383 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1384 | } |
| 1385 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1386 | TEST_P(LayerTypeTransactionTest, SetLayerStackBasic) { |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1387 | sp<SurfaceControl> layer; |
| 1388 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1389 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1390 | |
| 1391 | Transaction().setLayerStack(layer, mDisplayLayerStack + 1).apply(); |
| 1392 | { |
| 1393 | SCOPED_TRACE("non-existing layer stack"); |
| 1394 | screenshot()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
| 1395 | } |
| 1396 | |
| 1397 | Transaction().setLayerStack(layer, mDisplayLayerStack).apply(); |
| 1398 | { |
| 1399 | SCOPED_TRACE("original layer stack"); |
| 1400 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1401 | } |
| 1402 | } |
| 1403 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1404 | TEST_P(LayerTypeTransactionTest, SetMatrixBasic) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1405 | sp<SurfaceControl> layer; |
| 1406 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1407 | ASSERT_NO_FATAL_FAILURE( |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1408 | 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] | 1409 | |
| 1410 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 0, 0).apply(); |
| 1411 | { |
| 1412 | SCOPED_TRACE("IDENTITY"); |
| 1413 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, Color::BLUE, |
| 1414 | Color::WHITE); |
| 1415 | } |
| 1416 | |
| 1417 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 32, 0).apply(); |
| 1418 | { |
| 1419 | SCOPED_TRACE("FLIP_H"); |
| 1420 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE, |
| 1421 | Color::BLUE); |
| 1422 | } |
| 1423 | |
| 1424 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).setPosition(layer, 0, 32).apply(); |
| 1425 | { |
| 1426 | SCOPED_TRACE("FLIP_V"); |
| 1427 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED, |
| 1428 | Color::GREEN); |
| 1429 | } |
| 1430 | |
| 1431 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).setPosition(layer, 32, 0).apply(); |
| 1432 | { |
| 1433 | SCOPED_TRACE("ROT_90"); |
| 1434 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE, |
| 1435 | Color::GREEN); |
| 1436 | } |
| 1437 | |
| 1438 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setPosition(layer, 0, 0).apply(); |
| 1439 | { |
| 1440 | SCOPED_TRACE("SCALE"); |
| 1441 | screenshot()->expectQuadrant(Rect(0, 0, 64, 64), Color::RED, Color::GREEN, Color::BLUE, |
| 1442 | Color::WHITE, true /* filtered */); |
| 1443 | } |
| 1444 | } |
| 1445 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1446 | TEST_P(LayerTypeTransactionTest, SetMatrixRot45) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1447 | sp<SurfaceControl> layer; |
| 1448 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1449 | ASSERT_NO_FATAL_FAILURE( |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1450 | 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] | 1451 | |
| 1452 | const float rot = M_SQRT1_2; // 45 degrees |
| 1453 | const float trans = M_SQRT2 * 16.0f; |
| 1454 | Transaction().setMatrix(layer, rot, rot, -rot, rot).setPosition(layer, trans, 0).apply(); |
| 1455 | |
| 1456 | auto shot = screenshot(); |
| 1457 | // check a 8x8 region inside each color |
| 1458 | auto get8x8Rect = [](int32_t centerX, int32_t centerY) { |
| 1459 | const int32_t halfL = 4; |
| 1460 | return Rect(centerX - halfL, centerY - halfL, centerX + halfL, centerY + halfL); |
| 1461 | }; |
| 1462 | const int32_t unit = int32_t(trans / 2); |
| 1463 | shot->expectColor(get8x8Rect(2 * unit, 1 * unit), Color::RED); |
| 1464 | shot->expectColor(get8x8Rect(3 * unit, 2 * unit), Color::GREEN); |
| 1465 | shot->expectColor(get8x8Rect(1 * unit, 2 * unit), Color::BLUE); |
| 1466 | shot->expectColor(get8x8Rect(2 * unit, 3 * unit), Color::WHITE); |
| 1467 | } |
| 1468 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1469 | void LayerTransactionTest::setMatrixWithResizeHelper(uint32_t layerType) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1470 | sp<SurfaceControl> layer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1471 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32, layerType)); |
| 1472 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer, Color::RED, 32, 32)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1473 | |
| 1474 | // setMatrix is applied after any pending resize, unlike setPosition |
| 1475 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setSize(layer, 64, 64).apply(); |
| 1476 | { |
| 1477 | SCOPED_TRACE("resize pending"); |
| 1478 | auto shot = screenshot(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1479 | Rect rect; |
| 1480 | switch (layerType) { |
| 1481 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 1482 | rect = {0, 0, 32, 32}; |
| 1483 | break; |
| 1484 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 1485 | rect = {0, 0, 128, 128}; |
| 1486 | break; |
| 1487 | default: |
| 1488 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 1489 | } |
| 1490 | shot->expectColor(rect, Color::RED); |
| 1491 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1494 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer, Color::RED, 64, 64)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1495 | { |
| 1496 | SCOPED_TRACE("resize applied"); |
| 1497 | screenshot()->expectColor(Rect(0, 0, 128, 128), Color::RED); |
| 1498 | } |
| 1499 | } |
| 1500 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1501 | TEST_F(LayerTransactionTest, SetMatrixWithResize_BufferQueue) { |
| 1502 | ASSERT_NO_FATAL_FAILURE( |
| 1503 | setMatrixWithResizeHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); |
| 1504 | } |
| 1505 | |
| 1506 | TEST_F(LayerTransactionTest, SetMatrixWithResize_BufferState) { |
| 1507 | ASSERT_NO_FATAL_FAILURE( |
| 1508 | setMatrixWithResizeHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1509 | } |
| 1510 | |
| 1511 | TEST_P(LayerTypeTransactionTest, SetMatrixWithScaleToWindow) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1512 | sp<SurfaceControl> layer; |
| 1513 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1514 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1515 | |
| 1516 | // setMatrix is immediate with SCALE_TO_WINDOW, unlike setPosition |
| 1517 | Transaction() |
| 1518 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
| 1519 | .setSize(layer, 64, 64) |
| 1520 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1521 | .apply(); |
| 1522 | screenshot()->expectColor(Rect(0, 0, 128, 128), Color::RED); |
| 1523 | } |
| 1524 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1525 | TEST_P(LayerTypeTransactionTest, SetOverrideScalingModeBasic) { |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1526 | sp<SurfaceControl> layer; |
| 1527 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1528 | ASSERT_NO_FATAL_FAILURE( |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1529 | 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] | 1530 | |
| 1531 | // XXX SCALE_CROP is not respected; calling setSize and |
| 1532 | // setOverrideScalingMode in separate transactions does not work |
| 1533 | // (b/69315456) |
| 1534 | Transaction() |
| 1535 | .setSize(layer, 64, 16) |
| 1536 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1537 | .apply(); |
| 1538 | { |
| 1539 | SCOPED_TRACE("SCALE_TO_WINDOW"); |
| 1540 | screenshot()->expectQuadrant(Rect(0, 0, 64, 16), Color::RED, Color::GREEN, Color::BLUE, |
| 1541 | Color::WHITE, true /* filtered */); |
| 1542 | } |
| 1543 | } |
| 1544 | |
Dan Stoza | 000dd01 | 2018-08-01 13:31:52 -0700 | [diff] [blame] | 1545 | TEST_P(LayerTypeTransactionTest, RefreshRateIsInitialized) { |
| 1546 | sp<SurfaceControl> layer; |
| 1547 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1548 | |
| 1549 | sp<IBinder> handle = layer->getHandle(); |
| 1550 | ASSERT_TRUE(handle != nullptr); |
| 1551 | |
| 1552 | FrameStats frameStats; |
| 1553 | mClient->getLayerFrameStats(handle, &frameStats); |
| 1554 | |
| 1555 | ASSERT_GT(frameStats.refreshPeriodNano, static_cast<nsecs_t>(0)); |
| 1556 | } |
| 1557 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1558 | TEST_F(LayerTransactionTest, SetCropBasic_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1559 | sp<SurfaceControl> layer; |
| 1560 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1561 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1562 | const Rect crop(8, 8, 24, 24); |
| 1563 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1564 | Transaction().setCrop_legacy(layer, crop).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1565 | auto shot = screenshot(); |
| 1566 | shot->expectColor(crop, Color::RED); |
| 1567 | shot->expectBorder(crop, Color::BLACK); |
| 1568 | } |
| 1569 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1570 | TEST_F(LayerTransactionTest, SetCropBasic_BufferState) { |
| 1571 | sp<SurfaceControl> layer; |
| 1572 | ASSERT_NO_FATAL_FAILURE( |
| 1573 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1574 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1575 | const Rect crop(8, 8, 24, 24); |
| 1576 | |
| 1577 | Transaction().setCrop(layer, crop).apply(); |
| 1578 | auto shot = screenshot(); |
| 1579 | shot->expectColor(crop, Color::RED); |
| 1580 | shot->expectBorder(crop, Color::BLACK); |
| 1581 | } |
| 1582 | |
| 1583 | TEST_F(LayerTransactionTest, SetCropEmpty_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1584 | sp<SurfaceControl> layer; |
| 1585 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1586 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1587 | |
| 1588 | { |
| 1589 | SCOPED_TRACE("empty rect"); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1590 | Transaction().setCrop_legacy(layer, Rect(8, 8, 8, 8)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1591 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1592 | } |
| 1593 | |
| 1594 | { |
| 1595 | SCOPED_TRACE("negative rect"); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1596 | Transaction().setCrop_legacy(layer, Rect(8, 8, 0, 0)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1597 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1598 | } |
| 1599 | } |
| 1600 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1601 | TEST_F(LayerTransactionTest, SetCropEmpty_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 | { |
| 1608 | SCOPED_TRACE("empty rect"); |
| 1609 | Transaction().setCrop(layer, Rect(8, 8, 8, 8)).apply(); |
| 1610 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1611 | } |
| 1612 | |
| 1613 | { |
| 1614 | SCOPED_TRACE("negative rect"); |
| 1615 | Transaction().setCrop(layer, Rect(8, 8, 0, 0)).apply(); |
| 1616 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | TEST_F(LayerTransactionTest, SetCropOutOfBounds_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1621 | sp<SurfaceControl> layer; |
| 1622 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1623 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1624 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1625 | Transaction().setCrop_legacy(layer, Rect(-128, -64, 128, 64)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1626 | auto shot = screenshot(); |
| 1627 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1628 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1629 | } |
| 1630 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1631 | TEST_F(LayerTransactionTest, SetCropOutOfBounds_BufferState) { |
| 1632 | sp<SurfaceControl> layer; |
| 1633 | ASSERT_NO_FATAL_FAILURE( |
| 1634 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1635 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1636 | |
| 1637 | Transaction().setCrop(layer, Rect(-128, -64, 128, 64)).apply(); |
| 1638 | auto shot = screenshot(); |
| 1639 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1640 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1641 | } |
| 1642 | |
| 1643 | TEST_F(LayerTransactionTest, SetCropWithTranslation_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1644 | sp<SurfaceControl> layer; |
| 1645 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1646 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1647 | |
| 1648 | const Point position(32, 32); |
| 1649 | const Rect crop(8, 8, 24, 24); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1650 | 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] | 1651 | auto shot = screenshot(); |
| 1652 | shot->expectColor(crop + position, Color::RED); |
| 1653 | shot->expectBorder(crop + position, Color::BLACK); |
| 1654 | } |
| 1655 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1656 | TEST_F(LayerTransactionTest, SetCropWithTranslation_BufferState) { |
| 1657 | sp<SurfaceControl> layer; |
| 1658 | ASSERT_NO_FATAL_FAILURE( |
| 1659 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1660 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1661 | |
| 1662 | const Point position(32, 32); |
| 1663 | const Rect crop(8, 8, 24, 24); |
| 1664 | Transaction().setPosition(layer, position.x, position.y).setCrop(layer, crop).apply(); |
| 1665 | auto shot = screenshot(); |
| 1666 | shot->expectColor(crop + position, Color::RED); |
| 1667 | shot->expectBorder(crop + position, Color::BLACK); |
| 1668 | } |
| 1669 | |
| 1670 | TEST_F(LayerTransactionTest, SetCropWithScale_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1671 | sp<SurfaceControl> layer; |
| 1672 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1673 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1674 | |
| 1675 | // crop is affected by matrix |
| 1676 | Transaction() |
| 1677 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1678 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1679 | .apply(); |
| 1680 | auto shot = screenshot(); |
| 1681 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 1682 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); |
| 1683 | } |
| 1684 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1685 | TEST_F(LayerTransactionTest, SetCropWithScale_BufferState) { |
| 1686 | sp<SurfaceControl> layer; |
| 1687 | ASSERT_NO_FATAL_FAILURE( |
| 1688 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1689 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1690 | |
| 1691 | // crop is affected by matrix |
| 1692 | Transaction() |
| 1693 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
| 1694 | .setCrop(layer, Rect(8, 8, 24, 24)) |
| 1695 | .apply(); |
| 1696 | auto shot = screenshot(); |
| 1697 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 1698 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); |
| 1699 | } |
| 1700 | |
| 1701 | TEST_F(LayerTransactionTest, SetCropWithResize_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1702 | sp<SurfaceControl> layer; |
| 1703 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1704 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1705 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1706 | // setCrop_legacy is applied immediately by default, with or without resize pending |
| 1707 | 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] | 1708 | { |
| 1709 | SCOPED_TRACE("resize pending"); |
| 1710 | auto shot = screenshot(); |
| 1711 | shot->expectColor(Rect(8, 8, 24, 24), Color::RED); |
| 1712 | shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK); |
| 1713 | } |
| 1714 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1715 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1716 | { |
| 1717 | SCOPED_TRACE("resize applied"); |
| 1718 | auto shot = screenshot(); |
| 1719 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 1720 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 1721 | } |
| 1722 | } |
| 1723 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1724 | TEST_F(LayerTransactionTest, SetCropWithResize_BufferState) { |
| 1725 | sp<SurfaceControl> layer; |
| 1726 | ASSERT_NO_FATAL_FAILURE( |
| 1727 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1728 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1729 | |
| 1730 | // setCrop_legacy is applied immediately by default, with or without resize pending |
| 1731 | Transaction().setCrop(layer, Rect(8, 8, 24, 24)).setSize(layer, 16, 16).apply(); |
| 1732 | { |
| 1733 | SCOPED_TRACE("new buffer pending"); |
| 1734 | auto shot = screenshot(); |
| 1735 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 1736 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 1737 | } |
| 1738 | |
| 1739 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 16, 16)); |
| 1740 | { |
| 1741 | SCOPED_TRACE("new buffer"); |
| 1742 | auto shot = screenshot(); |
| 1743 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 1744 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | TEST_F(LayerTransactionTest, SetCropWithNextResize_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1749 | sp<SurfaceControl> layer; |
| 1750 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1751 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1752 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1753 | // request setCrop_legacy to be applied with the next resize |
| 1754 | Transaction() |
| 1755 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) |
| 1756 | .setGeometryAppliesWithResize(layer) |
| 1757 | .apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1758 | { |
| 1759 | SCOPED_TRACE("waiting for next resize"); |
| 1760 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1761 | } |
| 1762 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1763 | Transaction().setCrop_legacy(layer, Rect(4, 4, 12, 12)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1764 | { |
| 1765 | SCOPED_TRACE("pending crop modified"); |
| 1766 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1767 | } |
| 1768 | |
| 1769 | Transaction().setSize(layer, 16, 16).apply(); |
| 1770 | { |
| 1771 | SCOPED_TRACE("resize pending"); |
| 1772 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1773 | } |
| 1774 | |
| 1775 | // finally resize |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1776 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1777 | { |
| 1778 | SCOPED_TRACE("new crop applied"); |
| 1779 | auto shot = screenshot(); |
| 1780 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1781 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1782 | } |
| 1783 | } |
| 1784 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1785 | TEST_F(LayerTransactionTest, SetCropWithNextResize_BufferState) { |
| 1786 | sp<SurfaceControl> layer; |
| 1787 | ASSERT_NO_FATAL_FAILURE( |
| 1788 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1789 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1790 | |
| 1791 | // request setCrop_legacy to be applied with the next resize |
| 1792 | Transaction().setCrop(layer, Rect(8, 8, 24, 24)).setGeometryAppliesWithResize(layer).apply(); |
| 1793 | { |
| 1794 | SCOPED_TRACE("set crop 1"); |
| 1795 | screenshot()->expectColor(Rect(8, 8, 24, 24), Color::RED); |
| 1796 | } |
| 1797 | |
| 1798 | Transaction().setCrop(layer, Rect(4, 4, 12, 12)).apply(); |
| 1799 | { |
| 1800 | SCOPED_TRACE("set crop 2"); |
| 1801 | screenshot()->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1802 | } |
| 1803 | |
| 1804 | Transaction().setSize(layer, 16, 16).apply(); |
| 1805 | { |
| 1806 | SCOPED_TRACE("resize"); |
| 1807 | screenshot()->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1808 | } |
| 1809 | |
| 1810 | // finally resize |
| 1811 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 16, 16)); |
| 1812 | { |
| 1813 | SCOPED_TRACE("new buffer"); |
| 1814 | auto shot = screenshot(); |
| 1815 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1816 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | TEST_F(LayerTransactionTest, SetCropWithNextResizeScaleToWindow_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1821 | sp<SurfaceControl> layer; |
| 1822 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1823 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1824 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1825 | // setCrop_legacy is not immediate even with SCALE_TO_WINDOW override |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1826 | Transaction() |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1827 | .setCrop_legacy(layer, Rect(4, 4, 12, 12)) |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1828 | .setSize(layer, 16, 16) |
| 1829 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1830 | .setGeometryAppliesWithResize(layer) |
| 1831 | .apply(); |
| 1832 | { |
| 1833 | SCOPED_TRACE("new crop pending"); |
| 1834 | auto shot = screenshot(); |
| 1835 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 1836 | shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK); |
| 1837 | } |
| 1838 | |
| 1839 | // XXX crop is never latched without other geometry change (b/69315677) |
| 1840 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1841 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1842 | Transaction().setPosition(layer, 0, 0).apply(); |
| 1843 | { |
| 1844 | SCOPED_TRACE("new crop applied"); |
| 1845 | auto shot = screenshot(); |
| 1846 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1847 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1848 | } |
| 1849 | } |
| 1850 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1851 | TEST_F(LayerTransactionTest, SetCropWithNextResizeScaleToWindow_BufferState) { |
| 1852 | sp<SurfaceControl> layer; |
| 1853 | ASSERT_NO_FATAL_FAILURE( |
| 1854 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1855 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1856 | |
| 1857 | // all properties are applied immediate so setGeometryAppliesWithResize has no effect |
| 1858 | Transaction() |
| 1859 | .setCrop(layer, Rect(4, 4, 12, 12)) |
| 1860 | .setSize(layer, 16, 16) |
| 1861 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1862 | .setGeometryAppliesWithResize(layer) |
| 1863 | .apply(); |
| 1864 | { |
| 1865 | SCOPED_TRACE("new crop pending"); |
| 1866 | auto shot = screenshot(); |
| 1867 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1868 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1869 | } |
| 1870 | |
| 1871 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); |
| 1872 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 16, 16)); |
| 1873 | Transaction().setPosition(layer, 0, 0).apply(); |
| 1874 | { |
| 1875 | SCOPED_TRACE("new crop applied"); |
| 1876 | auto shot = screenshot(); |
| 1877 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 1878 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 1879 | } |
| 1880 | } |
| 1881 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1882 | TEST_F(LayerTransactionTest, SetBufferBasic_BufferState) { |
| 1883 | sp<SurfaceControl> layer; |
| 1884 | ASSERT_NO_FATAL_FAILURE( |
| 1885 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1886 | |
| 1887 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1888 | |
| 1889 | auto shot = screenshot(); |
| 1890 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1891 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1892 | } |
| 1893 | |
| 1894 | TEST_F(LayerTransactionTest, SetBufferMultipleBuffers_BufferState) { |
| 1895 | sp<SurfaceControl> layer; |
| 1896 | ASSERT_NO_FATAL_FAILURE( |
| 1897 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1898 | |
| 1899 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1900 | |
| 1901 | { |
| 1902 | SCOPED_TRACE("set buffer 1"); |
| 1903 | auto shot = screenshot(); |
| 1904 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1905 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1906 | } |
| 1907 | |
| 1908 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::BLUE, 32, 32)); |
| 1909 | |
| 1910 | { |
| 1911 | SCOPED_TRACE("set buffer 2"); |
| 1912 | auto shot = screenshot(); |
| 1913 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 1914 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1915 | } |
| 1916 | |
| 1917 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1918 | |
| 1919 | { |
| 1920 | SCOPED_TRACE("set buffer 3"); |
| 1921 | auto shot = screenshot(); |
| 1922 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1923 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | TEST_F(LayerTransactionTest, SetBufferMultipleLayers_BufferState) { |
| 1928 | sp<SurfaceControl> layer1; |
| 1929 | ASSERT_NO_FATAL_FAILURE( |
| 1930 | layer1 = createLayer("test", 64, 64, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1931 | |
| 1932 | sp<SurfaceControl> layer2; |
| 1933 | ASSERT_NO_FATAL_FAILURE( |
| 1934 | layer2 = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1935 | |
| 1936 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::RED, 64, 64)); |
| 1937 | |
| 1938 | { |
| 1939 | SCOPED_TRACE("set layer 1 buffer red"); |
| 1940 | auto shot = screenshot(); |
| 1941 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 1942 | } |
| 1943 | |
| 1944 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::BLUE, 32, 32)); |
| 1945 | |
| 1946 | { |
| 1947 | SCOPED_TRACE("set layer 2 buffer blue"); |
| 1948 | auto shot = screenshot(); |
| 1949 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 1950 | shot->expectColor(Rect(0, 32, 64, 64), Color::RED); |
| 1951 | shot->expectColor(Rect(0, 32, 32, 64), Color::RED); |
| 1952 | } |
| 1953 | |
| 1954 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::GREEN, 64, 64)); |
| 1955 | { |
| 1956 | SCOPED_TRACE("set layer 1 buffer green"); |
| 1957 | auto shot = screenshot(); |
| 1958 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 1959 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); |
| 1960 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); |
| 1961 | } |
| 1962 | |
| 1963 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::WHITE, 32, 32)); |
| 1964 | |
| 1965 | { |
| 1966 | SCOPED_TRACE("set layer 2 buffer white"); |
| 1967 | auto shot = screenshot(); |
| 1968 | shot->expectColor(Rect(0, 0, 32, 32), Color::WHITE); |
| 1969 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); |
| 1970 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); |
| 1971 | } |
| 1972 | } |
| 1973 | |
| 1974 | TEST_F(LayerTransactionTest, SetTransformRotate90_BufferState) { |
| 1975 | sp<SurfaceControl> layer; |
| 1976 | ASSERT_NO_FATAL_FAILURE( |
| 1977 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1978 | |
| 1979 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1980 | Color::BLUE, Color::WHITE)); |
| 1981 | |
| 1982 | Transaction().setTransform(layer, NATIVE_WINDOW_TRANSFORM_ROT_90).apply(); |
| 1983 | |
| 1984 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE, |
| 1985 | Color::GREEN, true /* filtered */); |
| 1986 | } |
| 1987 | |
| 1988 | TEST_F(LayerTransactionTest, SetTransformFlipH_BufferState) { |
| 1989 | sp<SurfaceControl> layer; |
| 1990 | ASSERT_NO_FATAL_FAILURE( |
| 1991 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1992 | |
| 1993 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1994 | Color::BLUE, Color::WHITE)); |
| 1995 | |
| 1996 | Transaction().setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_H).apply(); |
| 1997 | |
| 1998 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE, |
| 1999 | Color::BLUE, true /* filtered */); |
| 2000 | } |
| 2001 | |
| 2002 | TEST_F(LayerTransactionTest, SetTransformFlipV_BufferState) { |
| 2003 | sp<SurfaceControl> layer; |
| 2004 | ASSERT_NO_FATAL_FAILURE( |
| 2005 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2006 | |
| 2007 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 2008 | Color::BLUE, Color::WHITE)); |
| 2009 | |
| 2010 | Transaction().setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_V).apply(); |
| 2011 | |
| 2012 | screenshot()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED, |
| 2013 | Color::GREEN, true /* filtered */); |
| 2014 | } |
| 2015 | |
| 2016 | TEST_F(LayerTransactionTest, SetTransformToDisplayInverse_BufferState) { |
| 2017 | sp<SurfaceControl> layer; |
| 2018 | ASSERT_NO_FATAL_FAILURE( |
| 2019 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2020 | |
| 2021 | Transaction().setTransformToDisplayInverse(layer, false).apply(); |
| 2022 | |
| 2023 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::GREEN, 32, 32)); |
| 2024 | |
| 2025 | Transaction().setTransformToDisplayInverse(layer, true).apply(); |
| 2026 | } |
| 2027 | |
| 2028 | TEST_F(LayerTransactionTest, SetFenceBasic_BufferState) { |
| 2029 | sp<SurfaceControl> layer; |
| 2030 | ASSERT_NO_FATAL_FAILURE( |
| 2031 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2032 | |
| 2033 | sp<GraphicBuffer> buffer = |
| 2034 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2035 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2036 | BufferUsage::COMPOSER_OVERLAY, |
| 2037 | "test"); |
| 2038 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2039 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2040 | sp<Fence> fence = Fence::NO_FENCE; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2041 | |
| 2042 | Transaction() |
| 2043 | .setBuffer(layer, buffer) |
| 2044 | .setAcquireFence(layer, fence) |
| 2045 | .setSize(layer, 32, 32) |
| 2046 | .apply(); |
| 2047 | |
| 2048 | auto shot = screenshot(); |
| 2049 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2050 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2051 | } |
| 2052 | |
| 2053 | TEST_F(LayerTransactionTest, SetDataspaceBasic_BufferState) { |
| 2054 | sp<SurfaceControl> layer; |
| 2055 | ASSERT_NO_FATAL_FAILURE( |
| 2056 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2057 | |
| 2058 | sp<GraphicBuffer> buffer = |
| 2059 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2060 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2061 | BufferUsage::COMPOSER_OVERLAY, |
| 2062 | "test"); |
| 2063 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2064 | |
| 2065 | Transaction() |
| 2066 | .setBuffer(layer, buffer) |
| 2067 | .setDataspace(layer, ui::Dataspace::UNKNOWN) |
| 2068 | .setSize(layer, 32, 32) |
| 2069 | .apply(); |
| 2070 | |
| 2071 | auto shot = screenshot(); |
| 2072 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2073 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2074 | } |
| 2075 | |
| 2076 | TEST_F(LayerTransactionTest, SetHdrMetadataBasic_BufferState) { |
| 2077 | sp<SurfaceControl> layer; |
| 2078 | ASSERT_NO_FATAL_FAILURE( |
| 2079 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2080 | |
| 2081 | sp<GraphicBuffer> buffer = |
| 2082 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2083 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2084 | BufferUsage::COMPOSER_OVERLAY, |
| 2085 | "test"); |
| 2086 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2087 | |
| 2088 | HdrMetadata hdrMetadata; |
| 2089 | hdrMetadata.validTypes = 0; |
| 2090 | Transaction() |
| 2091 | .setBuffer(layer, buffer) |
| 2092 | .setHdrMetadata(layer, hdrMetadata) |
| 2093 | .setSize(layer, 32, 32) |
| 2094 | .apply(); |
| 2095 | |
| 2096 | auto shot = screenshot(); |
| 2097 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2098 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2099 | } |
| 2100 | |
| 2101 | TEST_F(LayerTransactionTest, SetSurfaceDamageRegionBasic_BufferState) { |
| 2102 | sp<SurfaceControl> layer; |
| 2103 | ASSERT_NO_FATAL_FAILURE( |
| 2104 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2105 | |
| 2106 | sp<GraphicBuffer> buffer = |
| 2107 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2108 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2109 | BufferUsage::COMPOSER_OVERLAY, |
| 2110 | "test"); |
| 2111 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2112 | |
| 2113 | Region region; |
| 2114 | region.set(32, 32); |
| 2115 | Transaction() |
| 2116 | .setBuffer(layer, buffer) |
| 2117 | .setSurfaceDamageRegion(layer, region) |
| 2118 | .setSize(layer, 32, 32) |
| 2119 | .apply(); |
| 2120 | |
| 2121 | auto shot = screenshot(); |
| 2122 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2123 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2124 | } |
| 2125 | |
| 2126 | TEST_F(LayerTransactionTest, SetApiBasic_BufferState) { |
| 2127 | sp<SurfaceControl> layer; |
| 2128 | ASSERT_NO_FATAL_FAILURE( |
| 2129 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2130 | |
| 2131 | sp<GraphicBuffer> buffer = |
| 2132 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2133 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2134 | BufferUsage::COMPOSER_OVERLAY, |
| 2135 | "test"); |
| 2136 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2137 | |
| 2138 | Transaction() |
| 2139 | .setBuffer(layer, buffer) |
| 2140 | .setApi(layer, NATIVE_WINDOW_API_CPU) |
| 2141 | .setSize(layer, 32, 32) |
| 2142 | .apply(); |
| 2143 | |
| 2144 | auto shot = screenshot(); |
| 2145 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2146 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2147 | } |
| 2148 | |
| 2149 | TEST_F(LayerTransactionTest, SetSidebandStreamNull_BufferState) { |
| 2150 | sp<SurfaceControl> layer; |
| 2151 | ASSERT_NO_FATAL_FAILURE( |
| 2152 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2153 | |
| 2154 | // verify this doesn't cause a crash |
| 2155 | Transaction().setSidebandStream(layer, nullptr).apply(); |
| 2156 | } |
| 2157 | |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2158 | class ColorTransformHelper { |
| 2159 | public: |
| 2160 | static void DegammaColorSingle(half& s) { |
| 2161 | if (s <= 0.03928f) |
| 2162 | s = s / 12.92f; |
| 2163 | else |
| 2164 | s = pow((s + 0.055f) / 1.055f, 2.4f); |
| 2165 | } |
| 2166 | |
| 2167 | static void DegammaColor(half3& color) { |
| 2168 | DegammaColorSingle(color.r); |
| 2169 | DegammaColorSingle(color.g); |
| 2170 | DegammaColorSingle(color.b); |
| 2171 | } |
| 2172 | |
| 2173 | static void GammaColorSingle(half& s) { |
| 2174 | if (s <= 0.0031308f) { |
| 2175 | s = s * 12.92f; |
| 2176 | } else { |
| 2177 | s = 1.055f * pow(s, (1.0f / 2.4f)) - 0.055f; |
| 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | static void GammaColor(half3& color) { |
| 2182 | GammaColorSingle(color.r); |
| 2183 | GammaColorSingle(color.g); |
| 2184 | GammaColorSingle(color.b); |
| 2185 | } |
| 2186 | |
| 2187 | static void applyMatrix(half3& color, const mat3& mat) { |
| 2188 | half3 ret = half3(0); |
| 2189 | |
| 2190 | for (int i = 0; i < 3; i++) { |
| 2191 | for (int j = 0; j < 3; j++) { |
| 2192 | ret[i] = ret[i] + color[j] * mat[j][i]; |
| 2193 | } |
| 2194 | } |
| 2195 | color = ret; |
| 2196 | } |
| 2197 | }; |
| 2198 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2199 | TEST_F(LayerTransactionTest, SetColorTransformBasic) { |
| 2200 | sp<SurfaceControl> colorLayer; |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 2201 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 2202 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 2203 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 2204 | Transaction() |
| 2205 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 2206 | .setLayer(colorLayer, mLayerZBase + 1) |
| 2207 | .apply(); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2208 | { |
| 2209 | SCOPED_TRACE("default color"); |
| 2210 | screenshot()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
| 2211 | } |
| 2212 | |
| 2213 | 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] | 2214 | half3 expected = color; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2215 | mat3 matrix; |
| 2216 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; |
| 2217 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; |
| 2218 | 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] | 2219 | |
| 2220 | // degamma before applying the matrix |
| 2221 | if (mColorManagementUsed) { |
| 2222 | ColorTransformHelper::DegammaColor(expected); |
| 2223 | } |
| 2224 | |
| 2225 | ColorTransformHelper::applyMatrix(expected, matrix); |
| 2226 | |
| 2227 | if (mColorManagementUsed) { |
| 2228 | ColorTransformHelper::GammaColor(expected); |
| 2229 | } |
| 2230 | |
| 2231 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), |
| 2232 | uint8_t(expected.b * 255), 255}; |
| 2233 | |
| 2234 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 2235 | // channel) should be less than one |
| 2236 | const uint8_t tolerance = 1; |
| 2237 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2238 | Transaction().setColor(colorLayer, color) |
| 2239 | .setColorTransform(colorLayer, matrix, vec3()).apply(); |
| 2240 | { |
| 2241 | SCOPED_TRACE("new color"); |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2242 | screenshot()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2243 | } |
| 2244 | } |
| 2245 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2246 | class ExpectedResult { |
| 2247 | public: |
| 2248 | enum Transaction { |
| 2249 | NOT_PRESENTED = 0, |
| 2250 | PRESENTED, |
| 2251 | }; |
| 2252 | |
| 2253 | enum Buffer { |
| 2254 | NOT_ACQUIRED = 0, |
| 2255 | ACQUIRED, |
| 2256 | }; |
| 2257 | |
| 2258 | enum PreviousBuffer { |
| 2259 | NOT_RELEASED = 0, |
| 2260 | RELEASED, |
| 2261 | }; |
| 2262 | |
| 2263 | void reset() { |
| 2264 | mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; |
| 2265 | mExpectedSurfaceResults.clear(); |
| 2266 | } |
| 2267 | |
| 2268 | void addSurface(ExpectedResult::Transaction transactionResult, const sp<SurfaceControl>& layer, |
| 2269 | ExpectedResult::Buffer bufferResult = NOT_ACQUIRED, |
| 2270 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { |
| 2271 | mTransactionResult = transactionResult; |
| 2272 | mExpectedSurfaceResults.emplace(std::piecewise_construct, |
| 2273 | std::forward_as_tuple(layer->getHandle()), |
| 2274 | std::forward_as_tuple(bufferResult, previousBufferResult)); |
| 2275 | } |
| 2276 | |
| 2277 | void addSurfaces(ExpectedResult::Transaction transactionResult, |
| 2278 | const std::vector<sp<SurfaceControl>>& layers, |
| 2279 | ExpectedResult::Buffer bufferResult = NOT_ACQUIRED, |
| 2280 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { |
| 2281 | for (const auto& layer : layers) { |
| 2282 | addSurface(transactionResult, layer, bufferResult, previousBufferResult); |
| 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | void verifyTransactionStats(const TransactionStats& transactionStats) const { |
| 2287 | const auto& [latchTime, presentTime, surfaceStats] = transactionStats; |
| 2288 | if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) { |
| 2289 | ASSERT_GE(latchTime, 0) << "bad latch time"; |
| 2290 | ASSERT_GE(presentTime, 0) << "bad present time"; |
| 2291 | } else { |
| 2292 | ASSERT_EQ(presentTime, -1) << "transaction shouldn't have been presented"; |
| 2293 | ASSERT_EQ(latchTime, -1) << "unpresented transactions shouldn't be latched"; |
| 2294 | } |
| 2295 | |
| 2296 | ASSERT_EQ(surfaceStats.size(), mExpectedSurfaceResults.size()) |
| 2297 | << "wrong number of surfaces"; |
| 2298 | |
| 2299 | for (const auto& stats : surfaceStats) { |
| 2300 | const auto& expectedSurfaceResult = mExpectedSurfaceResults.find(stats.surfaceControl); |
| 2301 | ASSERT_NE(expectedSurfaceResult, mExpectedSurfaceResults.end()) |
| 2302 | << "unexpected surface control"; |
| 2303 | expectedSurfaceResult->second.verifySurfaceStats(stats, latchTime); |
| 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | private: |
| 2308 | class ExpectedSurfaceResult { |
| 2309 | public: |
| 2310 | ExpectedSurfaceResult(ExpectedResult::Buffer bufferResult, |
| 2311 | ExpectedResult::PreviousBuffer previousBufferResult) |
| 2312 | : mBufferResult(bufferResult), mPreviousBufferResult(previousBufferResult) {} |
| 2313 | |
| 2314 | void verifySurfaceStats(const SurfaceStats& surfaceStats, nsecs_t latchTime) const { |
| 2315 | const auto& [surfaceControl, acquireTime, releasePreviousBuffer] = surfaceStats; |
| 2316 | |
| 2317 | ASSERT_EQ(acquireTime > 0, mBufferResult == ExpectedResult::Buffer::ACQUIRED) |
| 2318 | << "bad acquire time"; |
| 2319 | ASSERT_LE(acquireTime, latchTime) << "acquire time should be <= latch time"; |
| 2320 | ASSERT_EQ(releasePreviousBuffer, |
| 2321 | mPreviousBufferResult == ExpectedResult::PreviousBuffer::RELEASED) |
| 2322 | << "bad previous buffer released"; |
| 2323 | } |
| 2324 | |
| 2325 | private: |
| 2326 | ExpectedResult::Buffer mBufferResult; |
| 2327 | ExpectedResult::PreviousBuffer mPreviousBufferResult; |
| 2328 | }; |
| 2329 | |
| 2330 | struct IBinderHash { |
| 2331 | std::size_t operator()(const sp<IBinder>& strongPointer) const { |
| 2332 | return std::hash<IBinder*>{}(strongPointer.get()); |
| 2333 | } |
| 2334 | }; |
| 2335 | ExpectedResult::Transaction mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; |
| 2336 | std::unordered_map<sp<IBinder>, ExpectedSurfaceResult, IBinderHash> mExpectedSurfaceResults; |
| 2337 | }; |
| 2338 | |
| 2339 | class CallbackHelper { |
| 2340 | public: |
| 2341 | static void function(void* callbackContext, const TransactionStats& transactionStats) { |
| 2342 | if (!callbackContext) { |
| 2343 | ALOGE("failed to get callback context"); |
| 2344 | } |
| 2345 | CallbackHelper* helper = static_cast<CallbackHelper*>(callbackContext); |
| 2346 | std::lock_guard lock(helper->mMutex); |
| 2347 | helper->mTransactionStatsQueue.push(transactionStats); |
| 2348 | helper->mConditionVariable.notify_all(); |
| 2349 | } |
| 2350 | |
| 2351 | void getTransactionStats(TransactionStats* outStats) { |
| 2352 | std::unique_lock lock(mMutex); |
| 2353 | |
| 2354 | if (mTransactionStatsQueue.empty()) { |
| 2355 | ASSERT_NE(mConditionVariable.wait_for(lock, std::chrono::seconds(3)), |
| 2356 | std::cv_status::timeout) |
| 2357 | << "did not receive callback"; |
| 2358 | } |
| 2359 | |
| 2360 | *outStats = std::move(mTransactionStatsQueue.front()); |
| 2361 | mTransactionStatsQueue.pop(); |
| 2362 | } |
| 2363 | |
| 2364 | void verifyFinalState() { |
| 2365 | // Wait to see if there are extra callbacks |
| 2366 | std::this_thread::sleep_for(500ms); |
| 2367 | |
| 2368 | std::lock_guard lock(mMutex); |
| 2369 | EXPECT_EQ(mTransactionStatsQueue.size(), 0) << "extra callbacks received"; |
| 2370 | mTransactionStatsQueue = {}; |
| 2371 | } |
| 2372 | |
| 2373 | void* getContext() { return static_cast<void*>(this); } |
| 2374 | |
| 2375 | std::mutex mMutex; |
| 2376 | std::condition_variable mConditionVariable; |
| 2377 | std::queue<TransactionStats> mTransactionStatsQueue; |
| 2378 | }; |
| 2379 | |
| 2380 | class LayerCallbackTest : public LayerTransactionTest { |
| 2381 | protected: |
| 2382 | virtual sp<SurfaceControl> createBufferStateLayer() { |
| 2383 | return createLayer(mClient, "test", mWidth, mHeight, |
| 2384 | ISurfaceComposerClient::eFXSurfaceBufferState); |
| 2385 | } |
| 2386 | |
| 2387 | virtual void fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, |
| 2388 | const sp<SurfaceControl>& layer = nullptr) { |
| 2389 | if (layer) { |
| 2390 | sp<GraphicBuffer> buffer = |
| 2391 | new GraphicBuffer(mWidth, mHeight, PIXEL_FORMAT_RGBA_8888, 1, |
| 2392 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2393 | BufferUsage::COMPOSER_OVERLAY | |
| 2394 | BufferUsage::GPU_TEXTURE, |
| 2395 | "test"); |
| 2396 | fillGraphicBufferColor(buffer, Rect(0, 0, mWidth, mHeight), Color::RED); |
| 2397 | |
| 2398 | sp<Fence> fence = new Fence(-1); |
| 2399 | |
| 2400 | transaction.setBuffer(layer, buffer) |
| 2401 | .setAcquireFence(layer, fence) |
| 2402 | .setSize(layer, mWidth, mHeight); |
| 2403 | } |
| 2404 | |
| 2405 | transaction.addTransactionCompletedCallback(callbackHelper->function, |
| 2406 | callbackHelper->getContext()); |
| 2407 | } |
| 2408 | |
| 2409 | void waitForCallback(CallbackHelper& helper, const ExpectedResult& expectedResult, |
| 2410 | bool finalState = false) { |
| 2411 | TransactionStats transactionStats; |
| 2412 | ASSERT_NO_FATAL_FAILURE(helper.getTransactionStats(&transactionStats)); |
| 2413 | EXPECT_NO_FATAL_FAILURE(expectedResult.verifyTransactionStats(transactionStats)); |
| 2414 | |
| 2415 | if (finalState) { |
| 2416 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | void waitForCallbacks(CallbackHelper& helper, |
| 2421 | const std::vector<ExpectedResult>& expectedResults, |
| 2422 | bool finalState = false) { |
| 2423 | for (const auto& expectedResult : expectedResults) { |
| 2424 | waitForCallback(helper, expectedResult); |
| 2425 | } |
| 2426 | if (finalState) { |
| 2427 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 2428 | } |
| 2429 | } |
| 2430 | |
| 2431 | uint32_t mWidth = 32; |
| 2432 | uint32_t mHeight = 32; |
| 2433 | }; |
| 2434 | |
| 2435 | TEST_F(LayerCallbackTest, Basic) { |
| 2436 | sp<SurfaceControl> layer; |
| 2437 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2438 | |
| 2439 | Transaction transaction; |
| 2440 | CallbackHelper callback; |
| 2441 | fillTransaction(transaction, &callback, layer); |
| 2442 | |
| 2443 | transaction.apply(); |
| 2444 | |
| 2445 | ExpectedResult expected; |
| 2446 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2447 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2448 | } |
| 2449 | |
| 2450 | TEST_F(LayerCallbackTest, NoBuffer) { |
| 2451 | sp<SurfaceControl> layer; |
| 2452 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2453 | |
| 2454 | Transaction transaction; |
| 2455 | CallbackHelper callback; |
| 2456 | fillTransaction(transaction, &callback); |
| 2457 | |
| 2458 | transaction.setPosition(layer, mWidth, mHeight).apply(); |
| 2459 | |
| 2460 | ExpectedResult expected; |
| 2461 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer); |
| 2462 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2463 | } |
| 2464 | |
| 2465 | TEST_F(LayerCallbackTest, NoStateChange) { |
| 2466 | Transaction transaction; |
| 2467 | CallbackHelper callback; |
| 2468 | fillTransaction(transaction, &callback); |
| 2469 | |
| 2470 | transaction.apply(); |
| 2471 | |
| 2472 | ExpectedResult expected; |
| 2473 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2474 | } |
| 2475 | |
| 2476 | TEST_F(LayerCallbackTest, OffScreen) { |
| 2477 | sp<SurfaceControl> layer; |
| 2478 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2479 | |
| 2480 | Transaction transaction; |
| 2481 | CallbackHelper callback; |
| 2482 | fillTransaction(transaction, &callback, layer); |
| 2483 | |
| 2484 | transaction.setPosition(layer, -100, -100).apply(); |
| 2485 | |
| 2486 | ExpectedResult expected; |
| 2487 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2488 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2489 | } |
| 2490 | |
| 2491 | TEST_F(LayerCallbackTest, Merge) { |
| 2492 | sp<SurfaceControl> layer1, layer2; |
| 2493 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 2494 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 2495 | |
| 2496 | Transaction transaction1, transaction2; |
| 2497 | CallbackHelper callback1, callback2; |
| 2498 | fillTransaction(transaction1, &callback1, layer1); |
| 2499 | fillTransaction(transaction2, &callback2, layer2); |
| 2500 | |
| 2501 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2502 | |
| 2503 | ExpectedResult expected; |
| 2504 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2505 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2506 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2507 | } |
| 2508 | |
| 2509 | TEST_F(LayerCallbackTest, Merge_SameCallback) { |
| 2510 | sp<SurfaceControl> layer1, layer2; |
| 2511 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 2512 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 2513 | |
| 2514 | Transaction transaction1, transaction2; |
| 2515 | CallbackHelper callback; |
| 2516 | fillTransaction(transaction1, &callback, layer1); |
| 2517 | fillTransaction(transaction2, &callback, layer2); |
| 2518 | |
| 2519 | transaction2.merge(std::move(transaction1)).apply(); |
| 2520 | |
| 2521 | ExpectedResult expected; |
| 2522 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2523 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 2524 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 2525 | } |
| 2526 | |
| 2527 | TEST_F(LayerCallbackTest, Merge_SameLayer) { |
| 2528 | sp<SurfaceControl> layer; |
| 2529 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2530 | |
| 2531 | Transaction transaction1, transaction2; |
| 2532 | CallbackHelper callback1, callback2; |
| 2533 | fillTransaction(transaction1, &callback1, layer); |
| 2534 | fillTransaction(transaction2, &callback2, layer); |
| 2535 | |
| 2536 | transaction2.merge(std::move(transaction1)).apply(); |
| 2537 | |
| 2538 | ExpectedResult expected; |
| 2539 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2540 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2541 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2542 | } |
| 2543 | |
| 2544 | TEST_F(LayerCallbackTest, Merge_SingleBuffer) { |
| 2545 | sp<SurfaceControl> layer1, layer2; |
| 2546 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 2547 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 2548 | |
| 2549 | Transaction transaction1, transaction2; |
| 2550 | CallbackHelper callback1, callback2; |
| 2551 | fillTransaction(transaction1, &callback1, layer1); |
| 2552 | fillTransaction(transaction2, &callback2); |
| 2553 | |
| 2554 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2555 | |
| 2556 | ExpectedResult expected; |
| 2557 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2558 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2559 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2560 | } |
| 2561 | |
| 2562 | TEST_F(LayerCallbackTest, Merge_DifferentClients) { |
| 2563 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 2564 | client2(new SurfaceComposerClient); |
| 2565 | |
| 2566 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2567 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2568 | |
| 2569 | sp<SurfaceControl> layer1, layer2; |
| 2570 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", mWidth, mHeight, |
| 2571 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2572 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", mWidth, mHeight, |
| 2573 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2574 | |
| 2575 | Transaction transaction1, transaction2; |
| 2576 | CallbackHelper callback1, callback2; |
| 2577 | fillTransaction(transaction1, &callback1, layer1); |
| 2578 | fillTransaction(transaction2, &callback2, layer2); |
| 2579 | |
| 2580 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2581 | |
| 2582 | ExpectedResult expected; |
| 2583 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2584 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2585 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2586 | } |
| 2587 | |
| 2588 | TEST_F(LayerCallbackTest, MultipleTransactions) { |
| 2589 | sp<SurfaceControl> layer; |
| 2590 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2591 | |
| 2592 | Transaction transaction; |
| 2593 | CallbackHelper callback; |
| 2594 | for (size_t i = 0; i < 10; i++) { |
| 2595 | fillTransaction(transaction, &callback, layer); |
| 2596 | |
| 2597 | transaction.apply(); |
| 2598 | |
| 2599 | ExpectedResult expected; |
| 2600 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 2601 | ExpectedResult::Buffer::NOT_ACQUIRED, |
| 2602 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 2603 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 2604 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 2605 | } |
| 2606 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 2607 | } |
| 2608 | |
| 2609 | TEST_F(LayerCallbackTest, MultipleTransactions_NoStateChange) { |
| 2610 | sp<SurfaceControl> layer; |
| 2611 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2612 | |
| 2613 | Transaction transaction; |
| 2614 | CallbackHelper callback; |
| 2615 | for (size_t i = 0; i < 10; i++) { |
| 2616 | ExpectedResult expected; |
| 2617 | |
| 2618 | if (i == 0) { |
| 2619 | fillTransaction(transaction, &callback, layer); |
| 2620 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2621 | } else { |
| 2622 | fillTransaction(transaction, &callback); |
| 2623 | } |
| 2624 | |
| 2625 | transaction.apply(); |
| 2626 | |
| 2627 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 2628 | } |
| 2629 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 2630 | } |
| 2631 | |
| 2632 | TEST_F(LayerCallbackTest, MultipleTransactions_SameStateChange) { |
| 2633 | sp<SurfaceControl> layer; |
| 2634 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2635 | |
| 2636 | Transaction transaction; |
| 2637 | CallbackHelper callback; |
| 2638 | for (size_t i = 0; i < 10; i++) { |
| 2639 | if (i == 0) { |
| 2640 | fillTransaction(transaction, &callback, layer); |
| 2641 | } else { |
| 2642 | fillTransaction(transaction, &callback); |
| 2643 | } |
| 2644 | |
| 2645 | transaction.setPosition(layer, mWidth, mHeight).apply(); |
| 2646 | |
| 2647 | ExpectedResult expected; |
| 2648 | expected.addSurface((i == 0) ? ExpectedResult::Transaction::PRESENTED |
| 2649 | : ExpectedResult::Transaction::NOT_PRESENTED, |
| 2650 | layer); |
| 2651 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, i == 0)); |
| 2652 | } |
| 2653 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 2654 | } |
| 2655 | |
| 2656 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge) { |
| 2657 | sp<SurfaceControl> layer1, layer2; |
| 2658 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 2659 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 2660 | |
| 2661 | Transaction transaction1, transaction2; |
| 2662 | CallbackHelper callback1, callback2; |
| 2663 | for (size_t i = 0; i < 10; i++) { |
| 2664 | fillTransaction(transaction1, &callback1, layer1); |
| 2665 | fillTransaction(transaction2, &callback2, layer2); |
| 2666 | |
| 2667 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2668 | |
| 2669 | ExpectedResult expected; |
| 2670 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 2671 | ExpectedResult::Buffer::NOT_ACQUIRED, |
| 2672 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 2673 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 2674 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 2675 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 2676 | } |
| 2677 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 2678 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 2679 | } |
| 2680 | |
| 2681 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients) { |
| 2682 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 2683 | client2(new SurfaceComposerClient); |
| 2684 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2685 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2686 | |
| 2687 | sp<SurfaceControl> layer1, layer2; |
| 2688 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", mWidth, mHeight, |
| 2689 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2690 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", mWidth, mHeight, |
| 2691 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2692 | |
| 2693 | Transaction transaction1, transaction2; |
| 2694 | CallbackHelper callback1, callback2; |
| 2695 | for (size_t i = 0; i < 10; i++) { |
| 2696 | fillTransaction(transaction1, &callback1, layer1); |
| 2697 | fillTransaction(transaction2, &callback2, layer2); |
| 2698 | |
| 2699 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2700 | |
| 2701 | ExpectedResult expected; |
| 2702 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 2703 | ExpectedResult::Buffer::NOT_ACQUIRED, |
| 2704 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 2705 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 2706 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 2707 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 2708 | } |
| 2709 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 2710 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 2711 | } |
| 2712 | |
| 2713 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_NoStateChange) { |
| 2714 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 2715 | client2(new SurfaceComposerClient); |
| 2716 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2717 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2718 | |
| 2719 | sp<SurfaceControl> layer1, layer2; |
| 2720 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", mWidth, mHeight, |
| 2721 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2722 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", mWidth, mHeight, |
| 2723 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2724 | |
| 2725 | Transaction transaction1, transaction2; |
| 2726 | CallbackHelper callback1, callback2; |
| 2727 | |
| 2728 | // Normal call to set up test |
| 2729 | fillTransaction(transaction1, &callback1, layer1); |
| 2730 | fillTransaction(transaction2, &callback2, layer2); |
| 2731 | |
| 2732 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2733 | |
| 2734 | ExpectedResult expected; |
| 2735 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2736 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2737 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2738 | expected.reset(); |
| 2739 | |
| 2740 | // Test |
| 2741 | fillTransaction(transaction1, &callback1); |
| 2742 | fillTransaction(transaction2, &callback2); |
| 2743 | |
| 2744 | transaction2.merge(std::move(transaction1)).apply(); |
| 2745 | |
| 2746 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2747 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2748 | } |
| 2749 | |
| 2750 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_SameStateChange) { |
| 2751 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 2752 | client2(new SurfaceComposerClient); |
| 2753 | |
| 2754 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2755 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 2756 | |
| 2757 | sp<SurfaceControl> layer1, layer2; |
| 2758 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", mWidth, mHeight, |
| 2759 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2760 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", mWidth, mHeight, |
| 2761 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2762 | |
| 2763 | Transaction transaction1, transaction2; |
| 2764 | CallbackHelper callback1, callback2; |
| 2765 | |
| 2766 | // Normal call to set up test |
| 2767 | fillTransaction(transaction1, &callback1, layer1); |
| 2768 | fillTransaction(transaction2, &callback2, layer2); |
| 2769 | |
| 2770 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2771 | |
| 2772 | ExpectedResult expected; |
| 2773 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 2774 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2775 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2776 | expected.reset(); |
| 2777 | |
| 2778 | // Test |
| 2779 | fillTransaction(transaction1, &callback1); |
| 2780 | fillTransaction(transaction2, &callback2); |
| 2781 | |
| 2782 | transaction2.setPosition(layer2, mWidth, mHeight).merge(std::move(transaction1)).apply(); |
| 2783 | |
| 2784 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer2); |
| 2785 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 2786 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 2787 | } |
| 2788 | |
| 2789 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame) { |
| 2790 | sp<SurfaceControl> layer; |
| 2791 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2792 | |
| 2793 | Transaction transaction; |
| 2794 | CallbackHelper callback; |
| 2795 | std::vector<ExpectedResult> expectedResults(50); |
| 2796 | ExpectedResult::PreviousBuffer previousBufferResult = |
| 2797 | ExpectedResult::PreviousBuffer::NOT_RELEASED; |
| 2798 | for (auto& expected : expectedResults) { |
| 2799 | expected.reset(); |
| 2800 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 2801 | ExpectedResult::Buffer::NOT_ACQUIRED, previousBufferResult); |
| 2802 | previousBufferResult = ExpectedResult::PreviousBuffer::RELEASED; |
| 2803 | |
| 2804 | fillTransaction(transaction, &callback, layer); |
| 2805 | |
| 2806 | transaction.apply(); |
| 2807 | std::this_thread::sleep_for(200ms); |
| 2808 | } |
| 2809 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 2810 | } |
| 2811 | |
| 2812 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_NoStateChange) { |
| 2813 | sp<SurfaceControl> layer; |
| 2814 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2815 | |
| 2816 | Transaction transaction; |
| 2817 | CallbackHelper callback; |
| 2818 | std::vector<ExpectedResult> expectedResults(50); |
| 2819 | bool first = true; |
| 2820 | for (auto& expected : expectedResults) { |
| 2821 | expected.reset(); |
| 2822 | |
| 2823 | if (first) { |
| 2824 | fillTransaction(transaction, &callback, layer); |
| 2825 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2826 | first = false; |
| 2827 | } else { |
| 2828 | fillTransaction(transaction, &callback); |
| 2829 | } |
| 2830 | |
| 2831 | transaction.apply(); |
| 2832 | std::this_thread::sleep_for(200ms); |
| 2833 | } |
| 2834 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 2835 | } |
| 2836 | |
| 2837 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_SameStateChange) { |
| 2838 | sp<SurfaceControl> layer; |
| 2839 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 2840 | |
| 2841 | // Normal call to set up test |
| 2842 | Transaction transaction; |
| 2843 | CallbackHelper callback; |
| 2844 | fillTransaction(transaction, &callback, layer); |
| 2845 | |
| 2846 | transaction.setPosition(layer, mWidth, mHeight).apply(); |
| 2847 | |
| 2848 | ExpectedResult expectedResult; |
| 2849 | expectedResult.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 2850 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expectedResult, true)); |
| 2851 | |
| 2852 | // Test |
| 2853 | std::vector<ExpectedResult> expectedResults(50); |
| 2854 | for (auto& expected : expectedResults) { |
| 2855 | expected.reset(); |
| 2856 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer); |
| 2857 | |
| 2858 | fillTransaction(transaction, &callback); |
| 2859 | |
| 2860 | transaction.setPosition(layer, mWidth, mHeight).apply(); |
| 2861 | |
| 2862 | std::this_thread::sleep_for(200ms); |
| 2863 | } |
| 2864 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 2865 | } |
| 2866 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 2867 | class LayerUpdateTest : public LayerTransactionTest { |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2868 | protected: |
| 2869 | virtual void SetUp() { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2870 | LayerTransactionTest::SetUp(); |
| 2871 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2872 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2873 | sp<IBinder> display( |
| 2874 | SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 2875 | DisplayInfo info; |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 2876 | SurfaceComposerClient::getDisplayInfo(display, &info); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 2877 | |
| 2878 | ssize_t displayWidth = info.w; |
| 2879 | ssize_t displayHeight = info.h; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2880 | |
| 2881 | // Background surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2882 | mBGSurfaceControl = createLayer(String8("BG Test Surface"), displayWidth, |
| 2883 | displayHeight, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 2884 | ASSERT_TRUE(mBGSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2885 | ASSERT_TRUE(mBGSurfaceControl->isValid()); |
| 2886 | fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195); |
| 2887 | |
| 2888 | // Foreground surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2889 | mFGSurfaceControl = createLayer(String8("FG Test Surface"), 64, 64, 0); |
| 2890 | |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 2891 | ASSERT_TRUE(mFGSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2892 | ASSERT_TRUE(mFGSurfaceControl->isValid()); |
| 2893 | |
| 2894 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 2895 | |
| 2896 | // Synchronization surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2897 | mSyncSurfaceControl = createLayer(String8("Sync Test Surface"), 1, 1, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 2898 | ASSERT_TRUE(mSyncSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2899 | ASSERT_TRUE(mSyncSurfaceControl->isValid()); |
| 2900 | |
| 2901 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 2902 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2903 | asTransaction([&](Transaction& t) { |
| 2904 | t.setDisplayLayerStack(display, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2905 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2906 | t.setLayer(mBGSurfaceControl, INT32_MAX - 2).show(mBGSurfaceControl); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 2907 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2908 | t.setLayer(mFGSurfaceControl, INT32_MAX - 1) |
| 2909 | .setPosition(mFGSurfaceControl, 64, 64) |
| 2910 | .show(mFGSurfaceControl); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2911 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2912 | t.setLayer(mSyncSurfaceControl, INT32_MAX - 1) |
| 2913 | .setPosition(mSyncSurfaceControl, displayWidth - 2, displayHeight - 2) |
| 2914 | .show(mSyncSurfaceControl); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2915 | }); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | virtual void TearDown() { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2919 | LayerTransactionTest::TearDown(); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2920 | mBGSurfaceControl = 0; |
| 2921 | mFGSurfaceControl = 0; |
| 2922 | mSyncSurfaceControl = 0; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | void waitForPostedBuffers() { |
| 2926 | // Since the sync surface is in synchronous mode (i.e. double buffered) |
| 2927 | // posting three buffers to it should ensure that at least two |
| 2928 | // SurfaceFlinger::handlePageFlip calls have been made, which should |
| 2929 | // guaranteed that a buffer posted to another Surface has been retired. |
| 2930 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 2931 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 2932 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 2933 | } |
| 2934 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 2935 | void asTransaction(const std::function<void(Transaction&)>& exec) { |
| 2936 | Transaction t; |
| 2937 | exec(t); |
| 2938 | t.apply(true); |
| 2939 | } |
| 2940 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 2941 | sp<SurfaceControl> mBGSurfaceControl; |
| 2942 | sp<SurfaceControl> mFGSurfaceControl; |
| 2943 | |
| 2944 | // This surface is used to ensure that the buffers posted to |
| 2945 | // mFGSurfaceControl have been picked up by SurfaceFlinger. |
| 2946 | sp<SurfaceControl> mSyncSurfaceControl; |
| 2947 | }; |
| 2948 | |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2949 | TEST_F(LayerUpdateTest, RelativesAreNotDetached) { |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2950 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 2951 | std::unique_ptr<ScreenCapture> sc; |
| 2952 | |
| 2953 | sp<SurfaceControl> relative = createLayer(String8("relativeTestSurface"), 10, 10, 0); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2954 | fillSurfaceRGBA8(relative, 10, 10, 10); |
| 2955 | waitForPostedBuffers(); |
| 2956 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2957 | Transaction{} |
| 2958 | .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1) |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2959 | .setPosition(relative, 64, 64) |
| 2960 | .apply(); |
| 2961 | |
| 2962 | { |
| 2963 | // The relative should be on top of the FG control. |
| 2964 | ScreenCapture::captureScreen(&sc); |
| 2965 | sc->checkPixel(64, 64, 10, 10, 10); |
| 2966 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2967 | Transaction{}.detachChildren(mFGSurfaceControl).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2968 | |
| 2969 | { |
| 2970 | // Nothing should change at this point. |
| 2971 | ScreenCapture::captureScreen(&sc); |
| 2972 | sc->checkPixel(64, 64, 10, 10, 10); |
| 2973 | } |
| 2974 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2975 | Transaction{}.hide(relative).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 2976 | |
| 2977 | { |
| 2978 | // Ensure that the relative was actually hidden, rather than |
| 2979 | // being left in the detached but visible state. |
| 2980 | ScreenCapture::captureScreen(&sc); |
| 2981 | sc->expectFGColor(64, 64); |
| 2982 | } |
| 2983 | } |
| 2984 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 2985 | class GeometryLatchingTest : public LayerUpdateTest { |
| 2986 | protected: |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2987 | void EXPECT_INITIAL_STATE(const char* trace) { |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 2988 | SCOPED_TRACE(trace); |
| 2989 | ScreenCapture::captureScreen(&sc); |
| 2990 | // We find the leading edge of the FG surface. |
| 2991 | sc->expectFGColor(127, 127); |
| 2992 | sc->expectBGColor(128, 128); |
| 2993 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 2994 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 2995 | void lockAndFillFGBuffer() { fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false); } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 2996 | |
| 2997 | void unlockFGBuffer() { |
| 2998 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 2999 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 3000 | waitForPostedBuffers(); |
| 3001 | } |
| 3002 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 3003 | void completeFGResize() { |
| 3004 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 3005 | waitForPostedBuffers(); |
| 3006 | } |
| 3007 | void restoreInitialState() { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3008 | asTransaction([&](Transaction& t) { |
| 3009 | t.setSize(mFGSurfaceControl, 64, 64); |
| 3010 | t.setPosition(mFGSurfaceControl, 64, 64); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3011 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 64, 64)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3012 | }); |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 3013 | |
| 3014 | EXPECT_INITIAL_STATE("After restoring initial state"); |
| 3015 | } |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3016 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 3017 | }; |
| 3018 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 3019 | class CropLatchingTest : public GeometryLatchingTest { |
| 3020 | protected: |
| 3021 | void EXPECT_CROPPED_STATE(const char* trace) { |
| 3022 | SCOPED_TRACE(trace); |
| 3023 | ScreenCapture::captureScreen(&sc); |
| 3024 | // The edge should be moved back one pixel by our crop. |
| 3025 | sc->expectFGColor(126, 126); |
| 3026 | sc->expectBGColor(127, 127); |
| 3027 | sc->expectBGColor(128, 128); |
| 3028 | } |
chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 3029 | |
| 3030 | void EXPECT_RESIZE_STATE(const char* trace) { |
| 3031 | SCOPED_TRACE(trace); |
| 3032 | ScreenCapture::captureScreen(&sc); |
| 3033 | // The FG is now resized too 128,128 at 64,64 |
| 3034 | sc->expectFGColor(64, 64); |
| 3035 | sc->expectFGColor(191, 191); |
| 3036 | sc->expectBGColor(192, 192); |
| 3037 | } |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 3038 | }; |
| 3039 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3040 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3041 | std::unique_ptr<ScreenCapture> sc; |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3042 | { |
| 3043 | SCOPED_TRACE("before anything"); |
| 3044 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 3045 | sc->expectBGColor(32, 32); |
| 3046 | sc->expectFGColor(96, 96); |
| 3047 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | // set up two deferred transactions on different frames |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3051 | asTransaction([&](Transaction& t) { |
| 3052 | t.setAlpha(mFGSurfaceControl, 0.75); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3053 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
| 3054 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3055 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3056 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3057 | asTransaction([&](Transaction& t) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3058 | t.setPosition(mFGSurfaceControl, 128, 128); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3059 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
| 3060 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3061 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3062 | |
| 3063 | { |
| 3064 | SCOPED_TRACE("before any trigger"); |
| 3065 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 3066 | sc->expectBGColor(32, 32); |
| 3067 | sc->expectFGColor(96, 96); |
| 3068 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | // should trigger the first deferred transaction, but not the second one |
| 3072 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 3073 | { |
| 3074 | SCOPED_TRACE("after first trigger"); |
| 3075 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 3076 | sc->expectBGColor(32, 32); |
| 3077 | sc->checkPixel(96, 96, 162, 63, 96); |
| 3078 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | // should show up immediately since it's not deferred |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3082 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 1.0); }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3083 | |
| 3084 | // trigger the second deferred transaction |
| 3085 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 3086 | { |
| 3087 | SCOPED_TRACE("after second trigger"); |
| 3088 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 3089 | sc->expectBGColor(32, 32); |
| 3090 | sc->expectBGColor(96, 96); |
| 3091 | sc->expectFGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 3092 | } |
| 3093 | } |
| 3094 | |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3095 | TEST_F(LayerUpdateTest, LayerWithNoBuffersResizesImmediately) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3096 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3097 | |
| 3098 | sp<SurfaceControl> childNoBuffer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3099 | createSurface(mClient, "Bufferless child", 0 /* buffer width */, 0 /* buffer height */, |
| 3100 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 3101 | sp<SurfaceControl> childBuffer = createSurface(mClient, "Buffered child", 20, 20, |
| 3102 | PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get()); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3103 | fillSurfaceRGBA8(childBuffer, 200, 200, 200); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3104 | SurfaceComposerClient::Transaction{} |
| 3105 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 10, 10)) |
| 3106 | .show(childNoBuffer) |
| 3107 | .show(childBuffer) |
| 3108 | .apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3109 | { |
| 3110 | ScreenCapture::captureScreen(&sc); |
| 3111 | sc->expectChildColor(73, 73); |
| 3112 | sc->expectFGColor(74, 74); |
| 3113 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3114 | SurfaceComposerClient::Transaction{} |
| 3115 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 20, 20)) |
| 3116 | .apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 3117 | { |
| 3118 | ScreenCapture::captureScreen(&sc); |
| 3119 | sc->expectChildColor(73, 73); |
| 3120 | sc->expectChildColor(74, 74); |
| 3121 | } |
| 3122 | } |
| 3123 | |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 3124 | TEST_F(LayerUpdateTest, MergingTransactions) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3125 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 3126 | { |
| 3127 | SCOPED_TRACE("before move"); |
| 3128 | ScreenCapture::captureScreen(&sc); |
| 3129 | sc->expectBGColor(0, 12); |
| 3130 | sc->expectFGColor(75, 75); |
| 3131 | sc->expectBGColor(145, 145); |
| 3132 | } |
| 3133 | |
| 3134 | Transaction t1, t2; |
| 3135 | t1.setPosition(mFGSurfaceControl, 128, 128); |
| 3136 | t2.setPosition(mFGSurfaceControl, 0, 0); |
| 3137 | // We expect that the position update from t2 now |
| 3138 | // overwrites the position update from t1. |
| 3139 | t1.merge(std::move(t2)); |
| 3140 | t1.apply(); |
| 3141 | |
| 3142 | { |
| 3143 | ScreenCapture::captureScreen(&sc); |
| 3144 | sc->expectFGColor(1, 1); |
| 3145 | } |
| 3146 | } |
| 3147 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3148 | class ChildLayerTest : public LayerUpdateTest { |
| 3149 | protected: |
| 3150 | void SetUp() override { |
| 3151 | LayerUpdateTest::SetUp(); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3152 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, |
| 3153 | mFGSurfaceControl.get()); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3154 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 3155 | |
| 3156 | { |
| 3157 | SCOPED_TRACE("before anything"); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3158 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3159 | mCapture->expectChildColor(64, 64); |
| 3160 | } |
| 3161 | } |
| 3162 | void TearDown() override { |
| 3163 | LayerUpdateTest::TearDown(); |
| 3164 | mChild = 0; |
| 3165 | } |
| 3166 | |
| 3167 | sp<SurfaceControl> mChild; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3168 | std::unique_ptr<ScreenCapture> mCapture; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3169 | }; |
| 3170 | |
| 3171 | TEST_F(ChildLayerTest, ChildLayerPositioning) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3172 | asTransaction([&](Transaction& t) { |
| 3173 | t.show(mChild); |
| 3174 | t.setPosition(mChild, 10, 10); |
| 3175 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3176 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3177 | |
| 3178 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3179 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3180 | // Top left of foreground must now be visible |
| 3181 | mCapture->expectFGColor(64, 64); |
| 3182 | // But 10 pixels in we should see the child surface |
| 3183 | mCapture->expectChildColor(74, 74); |
| 3184 | // And 10 more pixels we should be back to the foreground surface |
| 3185 | mCapture->expectFGColor(84, 84); |
| 3186 | } |
| 3187 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3188 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3189 | |
| 3190 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3191 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3192 | // Top left of foreground should now be at 0, 0 |
| 3193 | mCapture->expectFGColor(0, 0); |
| 3194 | // But 10 pixels in we should see the child surface |
| 3195 | mCapture->expectChildColor(10, 10); |
| 3196 | // And 10 more pixels we should be back to the foreground surface |
| 3197 | mCapture->expectFGColor(20, 20); |
| 3198 | } |
| 3199 | } |
| 3200 | |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 3201 | TEST_F(ChildLayerTest, ChildLayerCropping) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3202 | asTransaction([&](Transaction& t) { |
| 3203 | t.show(mChild); |
| 3204 | t.setPosition(mChild, 0, 0); |
| 3205 | t.setPosition(mFGSurfaceControl, 0, 0); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3206 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 5, 5)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3207 | }); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 3208 | |
| 3209 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3210 | mCapture = screenshot(); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 3211 | mCapture->expectChildColor(0, 0); |
| 3212 | mCapture->expectChildColor(4, 4); |
| 3213 | mCapture->expectBGColor(5, 5); |
| 3214 | } |
| 3215 | } |
| 3216 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3217 | TEST_F(ChildLayerTest, ChildLayerConstraints) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3218 | asTransaction([&](Transaction& t) { |
| 3219 | t.show(mChild); |
| 3220 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 3221 | t.setPosition(mChild, 63, 63); |
| 3222 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3223 | |
| 3224 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3225 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3226 | mCapture->expectFGColor(0, 0); |
| 3227 | // Last pixel in foreground should now be the child. |
| 3228 | mCapture->expectChildColor(63, 63); |
| 3229 | // But the child should be constrained and the next pixel |
| 3230 | // must be the background |
| 3231 | mCapture->expectBGColor(64, 64); |
| 3232 | } |
| 3233 | } |
| 3234 | |
| 3235 | TEST_F(ChildLayerTest, ChildLayerScaling) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3236 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3237 | |
| 3238 | // Find the boundary between the parent and child |
| 3239 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3240 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3241 | mCapture->expectChildColor(9, 9); |
| 3242 | mCapture->expectFGColor(10, 10); |
| 3243 | } |
| 3244 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3245 | asTransaction([&](Transaction& t) { t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3246 | |
| 3247 | // The boundary should be twice as far from the origin now. |
| 3248 | // The pixels from the last test should all be child now |
| 3249 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3250 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 3251 | mCapture->expectChildColor(9, 9); |
| 3252 | mCapture->expectChildColor(10, 10); |
| 3253 | mCapture->expectChildColor(19, 19); |
| 3254 | mCapture->expectFGColor(20, 20); |
| 3255 | } |
| 3256 | } |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3257 | |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3258 | TEST_F(ChildLayerTest, ChildLayerAlpha) { |
| 3259 | fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254); |
| 3260 | fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0); |
| 3261 | fillSurfaceRGBA8(mChild, 0, 254, 0); |
| 3262 | waitForPostedBuffers(); |
| 3263 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3264 | asTransaction([&](Transaction& t) { |
| 3265 | t.show(mChild); |
| 3266 | t.setPosition(mChild, 0, 0); |
| 3267 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 3268 | }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3269 | |
| 3270 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3271 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3272 | // Unblended child color |
| 3273 | mCapture->checkPixel(0, 0, 0, 254, 0); |
| 3274 | } |
| 3275 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3276 | asTransaction([&](Transaction& t) { t.setAlpha(mChild, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3277 | |
| 3278 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3279 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3280 | // Child and BG blended. |
| 3281 | mCapture->checkPixel(0, 0, 127, 127, 0); |
| 3282 | } |
| 3283 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3284 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3285 | |
| 3286 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3287 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 3288 | // Child and BG blended. |
| 3289 | mCapture->checkPixel(0, 0, 95, 64, 95); |
| 3290 | } |
| 3291 | } |
| 3292 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3293 | TEST_F(ChildLayerTest, ReparentChildren) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3294 | asTransaction([&](Transaction& t) { |
| 3295 | t.show(mChild); |
| 3296 | t.setPosition(mChild, 10, 10); |
| 3297 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3298 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3299 | |
| 3300 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3301 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3302 | // Top left of foreground must now be visible |
| 3303 | mCapture->expectFGColor(64, 64); |
| 3304 | // But 10 pixels in we should see the child surface |
| 3305 | mCapture->expectChildColor(74, 74); |
| 3306 | // And 10 more pixels we should be back to the foreground surface |
| 3307 | mCapture->expectFGColor(84, 84); |
| 3308 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3309 | |
| 3310 | asTransaction([&](Transaction& t) { |
| 3311 | t.reparentChildren(mFGSurfaceControl, mBGSurfaceControl->getHandle()); |
| 3312 | }); |
| 3313 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3314 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3315 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3316 | mCapture->expectFGColor(64, 64); |
| 3317 | // In reparenting we should have exposed the entire foreground surface. |
| 3318 | mCapture->expectFGColor(74, 74); |
| 3319 | // And the child layer should now begin at 10, 10 (since the BG |
| 3320 | // layer is at (0, 0)). |
| 3321 | mCapture->expectBGColor(9, 9); |
| 3322 | mCapture->expectChildColor(10, 10); |
| 3323 | } |
| 3324 | } |
| 3325 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 3326 | TEST_F(ChildLayerTest, ChildrenSurviveParentDestruction) { |
| 3327 | sp<SurfaceControl> mGrandChild = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3328 | 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] | 3329 | fillSurfaceRGBA8(mGrandChild, 111, 111, 111); |
| 3330 | |
| 3331 | { |
| 3332 | SCOPED_TRACE("Grandchild visible"); |
| 3333 | ScreenCapture::captureScreen(&mCapture); |
| 3334 | mCapture->checkPixel(64, 64, 111, 111, 111); |
| 3335 | } |
| 3336 | |
| 3337 | mChild->clear(); |
| 3338 | |
| 3339 | { |
| 3340 | SCOPED_TRACE("After destroying child"); |
| 3341 | ScreenCapture::captureScreen(&mCapture); |
| 3342 | mCapture->expectFGColor(64, 64); |
| 3343 | } |
| 3344 | |
| 3345 | asTransaction([&](Transaction& t) { |
| 3346 | t.reparent(mGrandChild, mFGSurfaceControl->getHandle()); |
| 3347 | }); |
| 3348 | |
| 3349 | { |
| 3350 | SCOPED_TRACE("After reparenting grandchild"); |
| 3351 | ScreenCapture::captureScreen(&mCapture); |
| 3352 | mCapture->checkPixel(64, 64, 111, 111, 111); |
| 3353 | } |
| 3354 | } |
| 3355 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3356 | TEST_F(ChildLayerTest, DetachChildrenSameClient) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3357 | asTransaction([&](Transaction& t) { |
| 3358 | t.show(mChild); |
| 3359 | t.setPosition(mChild, 10, 10); |
| 3360 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3361 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3362 | |
| 3363 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3364 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3365 | // Top left of foreground must now be visible |
| 3366 | mCapture->expectFGColor(64, 64); |
| 3367 | // But 10 pixels in we should see the child surface |
| 3368 | mCapture->expectChildColor(74, 74); |
| 3369 | // And 10 more pixels we should be back to the foreground surface |
| 3370 | mCapture->expectFGColor(84, 84); |
| 3371 | } |
| 3372 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3373 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3374 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3375 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3376 | asTransaction([&](Transaction& t) { t.hide(mChild); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3377 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3378 | // Since the child has the same client as the parent, it will not get |
| 3379 | // detached and will be hidden. |
| 3380 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3381 | mCapture = screenshot(); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3382 | mCapture->expectFGColor(64, 64); |
| 3383 | mCapture->expectFGColor(74, 74); |
| 3384 | mCapture->expectFGColor(84, 84); |
| 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | TEST_F(ChildLayerTest, DetachChildrenDifferentClient) { |
| 3389 | sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient; |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3390 | sp<SurfaceControl> mChildNewClient = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3391 | createSurface(mNewComposerClient, "New Child Test Surface", 10, 10, |
| 3392 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3393 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3394 | ASSERT_TRUE(mChildNewClient->isValid()); |
| 3395 | |
| 3396 | fillSurfaceRGBA8(mChildNewClient, 200, 200, 200); |
| 3397 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3398 | asTransaction([&](Transaction& t) { |
| 3399 | t.hide(mChild); |
| 3400 | t.show(mChildNewClient); |
| 3401 | t.setPosition(mChildNewClient, 10, 10); |
| 3402 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3403 | }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3404 | |
| 3405 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3406 | mCapture = screenshot(); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3407 | // Top left of foreground must now be visible |
| 3408 | mCapture->expectFGColor(64, 64); |
| 3409 | // But 10 pixels in we should see the child surface |
| 3410 | mCapture->expectChildColor(74, 74); |
| 3411 | // And 10 more pixels we should be back to the foreground surface |
| 3412 | mCapture->expectFGColor(84, 84); |
| 3413 | } |
| 3414 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3415 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3416 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3417 | asTransaction([&](Transaction& t) { t.hide(mChildNewClient); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 3418 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3419 | // Nothing should have changed. |
| 3420 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3421 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 3422 | mCapture->expectFGColor(64, 64); |
| 3423 | mCapture->expectChildColor(74, 74); |
| 3424 | mCapture->expectFGColor(84, 84); |
| 3425 | } |
| 3426 | } |
| 3427 | |
chaviw | 5aedec9 | 2018-10-22 10:40:38 -0700 | [diff] [blame] | 3428 | TEST_F(ChildLayerTest, DetachChildrenThenAttach) { |
| 3429 | sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; |
| 3430 | sp<SurfaceControl> childNewClient = |
| 3431 | newComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, |
| 3432 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 3433 | |
| 3434 | ASSERT_TRUE(childNewClient != nullptr); |
| 3435 | ASSERT_TRUE(childNewClient->isValid()); |
| 3436 | |
| 3437 | fillSurfaceRGBA8(childNewClient, 200, 200, 200); |
| 3438 | |
| 3439 | Transaction() |
| 3440 | .hide(mChild) |
| 3441 | .show(childNewClient) |
| 3442 | .setPosition(childNewClient, 10, 10) |
| 3443 | .setPosition(mFGSurfaceControl, 64, 64) |
| 3444 | .apply(); |
| 3445 | |
| 3446 | { |
| 3447 | mCapture = screenshot(); |
| 3448 | // Top left of foreground must now be visible |
| 3449 | mCapture->expectFGColor(64, 64); |
| 3450 | // But 10 pixels in we should see the child surface |
| 3451 | mCapture->expectChildColor(74, 74); |
| 3452 | // And 10 more pixels we should be back to the foreground surface |
| 3453 | mCapture->expectFGColor(84, 84); |
| 3454 | } |
| 3455 | |
| 3456 | Transaction().detachChildren(mFGSurfaceControl).apply(); |
| 3457 | Transaction().hide(childNewClient).apply(); |
| 3458 | |
| 3459 | // Nothing should have changed. |
| 3460 | { |
| 3461 | mCapture = screenshot(); |
| 3462 | mCapture->expectFGColor(64, 64); |
| 3463 | mCapture->expectChildColor(74, 74); |
| 3464 | mCapture->expectFGColor(84, 84); |
| 3465 | } |
| 3466 | |
| 3467 | sp<SurfaceControl> newParentSurface = createLayer(String8("New Parent Surface"), 32, 32, 0); |
| 3468 | fillLayerColor(ISurfaceComposerClient::eFXSurfaceBufferQueue, newParentSurface, Color::RED, 32, |
| 3469 | 32); |
| 3470 | Transaction() |
| 3471 | .setLayer(newParentSurface, INT32_MAX - 1) |
| 3472 | .show(newParentSurface) |
| 3473 | .setPosition(newParentSurface, 20, 20) |
| 3474 | .reparent(childNewClient, newParentSurface->getHandle()) |
| 3475 | .apply(); |
| 3476 | { |
| 3477 | mCapture = screenshot(); |
| 3478 | // Child is now hidden. |
| 3479 | mCapture->expectColor(Rect(20, 20, 52, 52), Color::RED); |
| 3480 | } |
| 3481 | } |
| 3482 | |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3483 | TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3484 | asTransaction([&](Transaction& t) { |
| 3485 | t.show(mChild); |
| 3486 | t.setPosition(mChild, 0, 0); |
| 3487 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 3488 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3489 | |
| 3490 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3491 | mCapture = screenshot(); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3492 | // We've positioned the child in the top left. |
| 3493 | mCapture->expectChildColor(0, 0); |
| 3494 | // But it's only 10x10. |
| 3495 | mCapture->expectFGColor(10, 10); |
| 3496 | } |
| 3497 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3498 | asTransaction([&](Transaction& t) { |
| 3499 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 3500 | // We cause scaling by 2. |
| 3501 | t.setSize(mFGSurfaceControl, 128, 128); |
| 3502 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3503 | |
| 3504 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3505 | mCapture = screenshot(); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 3506 | // We've positioned the child in the top left. |
| 3507 | mCapture->expectChildColor(0, 0); |
| 3508 | mCapture->expectChildColor(10, 10); |
| 3509 | mCapture->expectChildColor(19, 19); |
| 3510 | // And now it should be scaled all the way to 20x20 |
| 3511 | mCapture->expectFGColor(20, 20); |
| 3512 | } |
| 3513 | } |
| 3514 | |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3515 | // Regression test for b/37673612 |
| 3516 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3517 | asTransaction([&](Transaction& t) { |
| 3518 | t.show(mChild); |
| 3519 | t.setPosition(mChild, 0, 0); |
| 3520 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 3521 | }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3522 | |
| 3523 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3524 | mCapture = screenshot(); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3525 | // We've positioned the child in the top left. |
| 3526 | mCapture->expectChildColor(0, 0); |
| 3527 | // But it's only 10x10. |
| 3528 | mCapture->expectFGColor(10, 10); |
| 3529 | } |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3530 | // We set things up as in b/37673612 so that there is a mismatch between the buffer size and |
| 3531 | // the WM specified state size. |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3532 | asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3533 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 3534 | auto anw = static_cast<ANativeWindow*>(s.get()); |
| 3535 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 3536 | native_window_set_buffers_dimensions(anw, 64, 128); |
| 3537 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 3538 | waitForPostedBuffers(); |
| 3539 | |
| 3540 | { |
| 3541 | // The child should still be in the same place and not have any strange scaling as in |
| 3542 | // b/37673612. |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3543 | mCapture = screenshot(); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 3544 | mCapture->expectChildColor(0, 0); |
| 3545 | mCapture->expectFGColor(10, 10); |
| 3546 | } |
| 3547 | } |
| 3548 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 3549 | TEST_F(ChildLayerTest, Bug36858924) { |
| 3550 | // Destroy the child layer |
| 3551 | mChild.clear(); |
| 3552 | |
| 3553 | // Now recreate it as hidden |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3554 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 3555 | ISurfaceComposerClient::eHidden, mFGSurfaceControl.get()); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 3556 | |
| 3557 | // Show the child layer in a deferred transaction |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3558 | asTransaction([&](Transaction& t) { |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 3559 | t.deferTransactionUntil_legacy(mChild, mFGSurfaceControl->getHandle(), |
| 3560 | mFGSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3561 | t.show(mChild); |
| 3562 | }); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 3563 | |
| 3564 | // Render the foreground surface a few times |
| 3565 | // |
| 3566 | // Prior to the bugfix for b/36858924, this would usually hang while trying to fill the third |
| 3567 | // frame because SurfaceFlinger would never process the deferred transaction and would therefore |
| 3568 | // never acquire/release the first buffer |
| 3569 | ALOGI("Filling 1"); |
| 3570 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 3571 | ALOGI("Filling 2"); |
| 3572 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 0, 255); |
| 3573 | ALOGI("Filling 3"); |
| 3574 | fillSurfaceRGBA8(mFGSurfaceControl, 255, 0, 0); |
| 3575 | ALOGI("Filling 4"); |
| 3576 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 3577 | } |
| 3578 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3579 | TEST_F(ChildLayerTest, Reparent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3580 | asTransaction([&](Transaction& t) { |
| 3581 | t.show(mChild); |
| 3582 | t.setPosition(mChild, 10, 10); |
| 3583 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3584 | }); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 3585 | |
| 3586 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3587 | mCapture = screenshot(); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 3588 | // Top left of foreground must now be visible |
| 3589 | mCapture->expectFGColor(64, 64); |
| 3590 | // But 10 pixels in we should see the child surface |
| 3591 | mCapture->expectChildColor(74, 74); |
| 3592 | // And 10 more pixels we should be back to the foreground surface |
| 3593 | mCapture->expectFGColor(84, 84); |
| 3594 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3595 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3596 | asTransaction([&](Transaction& t) { t.reparent(mChild, mBGSurfaceControl->getHandle()); }); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3597 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 3598 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3599 | mCapture = screenshot(); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 3600 | mCapture->expectFGColor(64, 64); |
| 3601 | // In reparenting we should have exposed the entire foreground surface. |
| 3602 | mCapture->expectFGColor(74, 74); |
| 3603 | // And the child layer should now begin at 10, 10 (since the BG |
| 3604 | // layer is at (0, 0)). |
| 3605 | mCapture->expectBGColor(9, 9); |
| 3606 | mCapture->expectChildColor(10, 10); |
| 3607 | } |
| 3608 | } |
| 3609 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3610 | TEST_F(ChildLayerTest, ReparentToNoParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3611 | asTransaction([&](Transaction& t) { |
| 3612 | t.show(mChild); |
| 3613 | t.setPosition(mChild, 10, 10); |
| 3614 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3615 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3616 | |
| 3617 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3618 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3619 | // Top left of foreground must now be visible |
| 3620 | mCapture->expectFGColor(64, 64); |
| 3621 | // But 10 pixels in we should see the child surface |
| 3622 | mCapture->expectChildColor(74, 74); |
| 3623 | // And 10 more pixels we should be back to the foreground surface |
| 3624 | mCapture->expectFGColor(84, 84); |
| 3625 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3626 | asTransaction([&](Transaction& t) { t.reparent(mChild, nullptr); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3627 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3628 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3629 | // Nothing should have changed. |
| 3630 | mCapture->expectFGColor(64, 64); |
| 3631 | mCapture->expectChildColor(74, 74); |
| 3632 | mCapture->expectFGColor(84, 84); |
| 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | TEST_F(ChildLayerTest, ReparentFromNoParent) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3637 | sp<SurfaceControl> newSurface = createLayer(String8("New Surface"), 10, 10, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 3638 | ASSERT_TRUE(newSurface != nullptr); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3639 | ASSERT_TRUE(newSurface->isValid()); |
| 3640 | |
| 3641 | fillSurfaceRGBA8(newSurface, 63, 195, 63); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3642 | asTransaction([&](Transaction& t) { |
| 3643 | t.hide(mChild); |
| 3644 | t.show(newSurface); |
| 3645 | t.setPosition(newSurface, 10, 10); |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3646 | t.setLayer(newSurface, INT32_MAX - 2); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3647 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 3648 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3649 | |
| 3650 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3651 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3652 | // Top left of foreground must now be visible |
| 3653 | mCapture->expectFGColor(64, 64); |
| 3654 | // At 10, 10 we should see the new surface |
| 3655 | mCapture->checkPixel(10, 10, 63, 195, 63); |
| 3656 | } |
| 3657 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3658 | asTransaction([&](Transaction& t) { t.reparent(newSurface, mFGSurfaceControl->getHandle()); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3659 | |
| 3660 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3661 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 3662 | // newSurface will now be a child of mFGSurface so it will be 10, 10 offset from |
| 3663 | // mFGSurface, putting it at 74, 74. |
| 3664 | mCapture->expectFGColor(64, 64); |
| 3665 | mCapture->checkPixel(74, 74, 63, 195, 63); |
| 3666 | mCapture->expectFGColor(84, 84); |
| 3667 | } |
| 3668 | } |
| 3669 | |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 3670 | TEST_F(ChildLayerTest, NestedChildren) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3671 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 10, 10, |
| 3672 | PIXEL_FORMAT_RGBA_8888, 0, mChild.get()); |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 3673 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 3674 | |
| 3675 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3676 | mCapture = screenshot(); |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 3677 | // Expect the grandchild to begin at 64, 64 because it's a child of mChild layer |
| 3678 | // which begins at 64, 64 |
| 3679 | mCapture->checkPixel(64, 64, 50, 50, 50); |
| 3680 | } |
| 3681 | } |
| 3682 | |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 3683 | TEST_F(ChildLayerTest, ChildLayerRelativeLayer) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3684 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 128, 128, 0); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 3685 | fillSurfaceRGBA8(relative, 255, 255, 255); |
| 3686 | |
| 3687 | Transaction t; |
| 3688 | t.setLayer(relative, INT32_MAX) |
| 3689 | .setRelativeLayer(mChild, relative->getHandle(), 1) |
| 3690 | .setPosition(mFGSurfaceControl, 0, 0) |
| 3691 | .apply(true); |
| 3692 | |
| 3693 | // We expect that the child should have been elevated above our |
| 3694 | // INT_MAX layer even though it's not a child of it. |
| 3695 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3696 | mCapture = screenshot(); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 3697 | mCapture->expectChildColor(0, 0); |
| 3698 | mCapture->expectChildColor(9, 9); |
| 3699 | mCapture->checkPixel(10, 10, 255, 255, 255); |
| 3700 | } |
| 3701 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3702 | class BoundlessLayerTest : public LayerUpdateTest { |
| 3703 | protected: |
| 3704 | std::unique_ptr<ScreenCapture> mCapture; |
| 3705 | }; |
| 3706 | |
| 3707 | // Verify setting a size on a buffer layer has no effect. |
| 3708 | TEST_F(BoundlessLayerTest, BufferLayerIgnoresSize) { |
| 3709 | sp<SurfaceControl> bufferLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3710 | createSurface(mClient, "BufferLayer", 45, 45, PIXEL_FORMAT_RGBA_8888, 0, |
| 3711 | mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3712 | ASSERT_TRUE(bufferLayer->isValid()); |
| 3713 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::BLACK, 30, 30)); |
| 3714 | asTransaction([&](Transaction& t) { t.show(bufferLayer); }); |
| 3715 | { |
| 3716 | mCapture = screenshot(); |
| 3717 | // Top left of background must now be visible |
| 3718 | mCapture->expectBGColor(0, 0); |
| 3719 | // Foreground Surface bounds must be color layer |
| 3720 | mCapture->expectColor(Rect(64, 64, 94, 94), Color::BLACK); |
| 3721 | // Buffer layer should not extend past buffer bounds |
| 3722 | mCapture->expectFGColor(95, 95); |
| 3723 | } |
| 3724 | } |
| 3725 | |
| 3726 | // Verify a boundless color layer will fill its parent bounds. The parent has a buffer size |
| 3727 | // which will crop the color layer. |
| 3728 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentBufferBounds) { |
| 3729 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3730 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3731 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3732 | ASSERT_TRUE(colorLayer->isValid()); |
| 3733 | asTransaction([&](Transaction& t) { |
| 3734 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3735 | t.show(colorLayer); |
| 3736 | }); |
| 3737 | { |
| 3738 | mCapture = screenshot(); |
| 3739 | // Top left of background must now be visible |
| 3740 | mCapture->expectBGColor(0, 0); |
| 3741 | // Foreground Surface bounds must be color layer |
| 3742 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 3743 | // Color layer should not extend past foreground bounds |
| 3744 | mCapture->expectBGColor(129, 129); |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | // Verify a boundless color layer will fill its parent bounds. The parent has no buffer but has |
| 3749 | // a crop which will be used to crop the color layer. |
| 3750 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentCropBounds) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3751 | sp<SurfaceControl> cropLayer = createSurface(mClient, "CropLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3752 | 0 /* flags */, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3753 | ASSERT_TRUE(cropLayer->isValid()); |
| 3754 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3755 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3756 | ISurfaceComposerClient::eFXSurfaceColor, cropLayer.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3757 | ASSERT_TRUE(colorLayer->isValid()); |
| 3758 | asTransaction([&](Transaction& t) { |
| 3759 | t.setCrop_legacy(cropLayer, Rect(5, 5, 10, 10)); |
| 3760 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3761 | t.show(cropLayer); |
| 3762 | t.show(colorLayer); |
| 3763 | }); |
| 3764 | { |
| 3765 | mCapture = screenshot(); |
| 3766 | // Top left of background must now be visible |
| 3767 | mCapture->expectBGColor(0, 0); |
| 3768 | // Top left of foreground must now be visible |
| 3769 | mCapture->expectFGColor(64, 64); |
| 3770 | // 5 pixels from the foreground we should see the child surface |
| 3771 | mCapture->expectColor(Rect(69, 69, 74, 74), Color::BLACK); |
| 3772 | // 10 pixels from the foreground we should be back to the foreground surface |
| 3773 | mCapture->expectFGColor(74, 74); |
| 3774 | } |
| 3775 | } |
| 3776 | |
| 3777 | // Verify for boundless layer with no children, their transforms have no effect. |
| 3778 | TEST_F(BoundlessLayerTest, BoundlessColorLayerTransformHasNoEffect) { |
| 3779 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3780 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3781 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3782 | ASSERT_TRUE(colorLayer->isValid()); |
| 3783 | asTransaction([&](Transaction& t) { |
| 3784 | t.setPosition(colorLayer, 320, 320); |
| 3785 | t.setMatrix(colorLayer, 2, 0, 0, 2); |
| 3786 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3787 | t.show(colorLayer); |
| 3788 | }); |
| 3789 | { |
| 3790 | mCapture = screenshot(); |
| 3791 | // Top left of background must now be visible |
| 3792 | mCapture->expectBGColor(0, 0); |
| 3793 | // Foreground Surface bounds must be color layer |
| 3794 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 3795 | // Color layer should not extend past foreground bounds |
| 3796 | mCapture->expectBGColor(129, 129); |
| 3797 | } |
| 3798 | } |
| 3799 | |
| 3800 | // Verify for boundless layer with children, their transforms have an effect. |
| 3801 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerCanSetTransform) { |
| 3802 | sp<SurfaceControl> boundlessLayerRightShift = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3803 | createSurface(mClient, "BoundlessLayerRightShift", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3804 | 0 /* flags */, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3805 | ASSERT_TRUE(boundlessLayerRightShift->isValid()); |
| 3806 | sp<SurfaceControl> boundlessLayerDownShift = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3807 | createSurface(mClient, "BoundlessLayerLeftShift", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3808 | 0 /* flags */, boundlessLayerRightShift.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3809 | ASSERT_TRUE(boundlessLayerDownShift->isValid()); |
| 3810 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3811 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3812 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayerDownShift.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3813 | ASSERT_TRUE(colorLayer->isValid()); |
| 3814 | asTransaction([&](Transaction& t) { |
| 3815 | t.setPosition(boundlessLayerRightShift, 32, 0); |
| 3816 | t.show(boundlessLayerRightShift); |
| 3817 | t.setPosition(boundlessLayerDownShift, 0, 32); |
| 3818 | t.show(boundlessLayerDownShift); |
| 3819 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 3820 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3821 | t.show(colorLayer); |
| 3822 | }); |
| 3823 | { |
| 3824 | mCapture = screenshot(); |
| 3825 | // Top left of background must now be visible |
| 3826 | mCapture->expectBGColor(0, 0); |
| 3827 | // Top left of foreground must now be visible |
| 3828 | mCapture->expectFGColor(64, 64); |
| 3829 | // Foreground Surface bounds must be color layer |
| 3830 | mCapture->expectColor(Rect(96, 96, 128, 128), Color::BLACK); |
| 3831 | // Color layer should not extend past foreground bounds |
| 3832 | mCapture->expectBGColor(129, 129); |
| 3833 | } |
| 3834 | } |
| 3835 | |
| 3836 | // Verify child layers do not get clipped if they temporarily move into the negative |
| 3837 | // coordinate space as the result of an intermediate transformation. |
| 3838 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerDoNotCrop) { |
| 3839 | sp<SurfaceControl> boundlessLayer = |
| 3840 | mClient->createSurface(String8("BoundlessLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3841 | 0 /* flags */, mFGSurfaceControl.get()); |
| 3842 | ASSERT_TRUE(boundlessLayer != nullptr); |
| 3843 | ASSERT_TRUE(boundlessLayer->isValid()); |
| 3844 | sp<SurfaceControl> colorLayer = |
| 3845 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3846 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayer.get()); |
| 3847 | ASSERT_TRUE(colorLayer != nullptr); |
| 3848 | ASSERT_TRUE(colorLayer->isValid()); |
| 3849 | asTransaction([&](Transaction& t) { |
| 3850 | // shift child layer off bounds. If this layer was not boundless, we will |
| 3851 | // expect the child layer to be cropped. |
| 3852 | t.setPosition(boundlessLayer, 32, 32); |
| 3853 | t.show(boundlessLayer); |
| 3854 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 3855 | // undo shift by parent |
| 3856 | t.setPosition(colorLayer, -32, -32); |
| 3857 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3858 | t.show(colorLayer); |
| 3859 | }); |
| 3860 | { |
| 3861 | mCapture = screenshot(); |
| 3862 | // Top left of background must now be visible |
| 3863 | mCapture->expectBGColor(0, 0); |
| 3864 | // Foreground Surface bounds must be color layer |
| 3865 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 3866 | // Color layer should not extend past foreground bounds |
| 3867 | mCapture->expectBGColor(129, 129); |
| 3868 | } |
| 3869 | } |
| 3870 | |
| 3871 | // Verify for boundless root layers with children, their transforms have an effect. |
| 3872 | TEST_F(BoundlessLayerTest, RootBoundlessLayerCanSetTransform) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3873 | sp<SurfaceControl> rootBoundlessLayer = createSurface(mClient, "RootBoundlessLayer", 0, 0, |
| 3874 | PIXEL_FORMAT_RGBA_8888, 0 /* flags */); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3875 | ASSERT_TRUE(rootBoundlessLayer->isValid()); |
| 3876 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3877 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 3878 | ISurfaceComposerClient::eFXSurfaceColor, rootBoundlessLayer.get()); |
| 3879 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 3880 | ASSERT_TRUE(colorLayer->isValid()); |
| 3881 | asTransaction([&](Transaction& t) { |
| 3882 | t.setLayer(rootBoundlessLayer, INT32_MAX - 1); |
| 3883 | t.setPosition(rootBoundlessLayer, 32, 32); |
| 3884 | t.show(rootBoundlessLayer); |
| 3885 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 3886 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 3887 | t.show(colorLayer); |
| 3888 | t.hide(mFGSurfaceControl); |
| 3889 | }); |
| 3890 | { |
| 3891 | mCapture = screenshot(); |
| 3892 | // Top left of background must now be visible |
| 3893 | mCapture->expectBGColor(0, 0); |
| 3894 | // Top left of foreground must now be visible |
| 3895 | mCapture->expectBGColor(31, 31); |
| 3896 | // Foreground Surface bounds must be color layer |
| 3897 | mCapture->expectColor(Rect(32, 32, 96, 96), Color::BLACK); |
| 3898 | // Color layer should not extend past foreground bounds |
| 3899 | mCapture->expectBGColor(97, 97); |
| 3900 | } |
| 3901 | } |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 3902 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3903 | class ScreenCaptureTest : public LayerUpdateTest { |
| 3904 | protected: |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 3905 | std::unique_ptr<ScreenCapture> mCapture; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3906 | }; |
| 3907 | |
| 3908 | TEST_F(ScreenCaptureTest, CaptureSingleLayer) { |
| 3909 | auto bgHandle = mBGSurfaceControl->getHandle(); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 3910 | ScreenCapture::captureLayers(&mCapture, bgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3911 | mCapture->expectBGColor(0, 0); |
| 3912 | // Doesn't capture FG layer which is at 64, 64 |
| 3913 | mCapture->expectBGColor(64, 64); |
| 3914 | } |
| 3915 | |
| 3916 | TEST_F(ScreenCaptureTest, CaptureLayerWithChild) { |
| 3917 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3918 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3919 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 3920 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3921 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3922 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3923 | SurfaceComposerClient::Transaction().show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3924 | |
| 3925 | // Captures mFGSurfaceControl layer and its child. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 3926 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 3927 | mCapture->expectFGColor(10, 10); |
| 3928 | mCapture->expectChildColor(0, 0); |
| 3929 | } |
| 3930 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 3931 | TEST_F(ScreenCaptureTest, CaptureLayerChildOnly) { |
| 3932 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3933 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3934 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 3935 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 3936 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3937 | |
| 3938 | SurfaceComposerClient::Transaction().show(child).apply(true); |
| 3939 | |
| 3940 | // Captures mFGSurfaceControl's child |
| 3941 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); |
| 3942 | mCapture->checkPixel(10, 10, 0, 0, 0); |
| 3943 | mCapture->expectChildColor(0, 0); |
| 3944 | } |
| 3945 | |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 3946 | TEST_F(ScreenCaptureTest, CaptureTransparent) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3947 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 3948 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 3949 | |
| 3950 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3951 | |
| 3952 | SurfaceComposerClient::Transaction().show(child).apply(true); |
| 3953 | |
| 3954 | auto childHandle = child->getHandle(); |
| 3955 | |
| 3956 | // Captures child |
| 3957 | ScreenCapture::captureLayers(&mCapture, childHandle, {0, 0, 10, 20}); |
| 3958 | mCapture->expectColor(Rect(0, 0, 9, 9), {200, 200, 200, 255}); |
| 3959 | // Area outside of child's bounds is transparent. |
| 3960 | mCapture->expectColor(Rect(0, 10, 9, 19), {0, 0, 0, 0}); |
| 3961 | } |
| 3962 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 3963 | TEST_F(ScreenCaptureTest, DontCaptureRelativeOutsideTree) { |
| 3964 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3965 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3966 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 3967 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 3968 | ASSERT_NE(nullptr, child.get()) << "failed to create surface"; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3969 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 10, 10, 0); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 3970 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3971 | fillSurfaceRGBA8(relative, 100, 100, 100); |
| 3972 | |
| 3973 | SurfaceComposerClient::Transaction() |
| 3974 | .show(child) |
| 3975 | // Set relative layer above fg layer so should be shown above when computing all layers. |
| 3976 | .setRelativeLayer(relative, fgHandle, 1) |
| 3977 | .show(relative) |
| 3978 | .apply(true); |
| 3979 | |
| 3980 | // Captures mFGSurfaceControl layer and its child. Relative layer shouldn't be captured. |
| 3981 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
| 3982 | mCapture->expectFGColor(10, 10); |
| 3983 | mCapture->expectChildColor(0, 0); |
| 3984 | } |
| 3985 | |
| 3986 | TEST_F(ScreenCaptureTest, CaptureRelativeInTree) { |
| 3987 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 3988 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 3989 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 3990 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 3991 | sp<SurfaceControl> relative = createSurface(mClient, "Relative surface", 10, 10, |
| 3992 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 3993 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 3994 | fillSurfaceRGBA8(relative, 100, 100, 100); |
| 3995 | |
| 3996 | SurfaceComposerClient::Transaction() |
| 3997 | .show(child) |
| 3998 | // Set relative layer below fg layer but relative to child layer so it should be shown |
| 3999 | // above child layer. |
| 4000 | .setLayer(relative, -1) |
| 4001 | .setRelativeLayer(relative, child->getHandle(), 1) |
| 4002 | .show(relative) |
| 4003 | .apply(true); |
| 4004 | |
| 4005 | // Captures mFGSurfaceControl layer and its children. Relative layer is a child of fg so its |
| 4006 | // relative value should be taken into account, placing it above child layer. |
| 4007 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
| 4008 | mCapture->expectFGColor(10, 10); |
| 4009 | // Relative layer is showing on top of child layer |
| 4010 | mCapture->expectColor(Rect(0, 0, 9, 9), {100, 100, 100, 255}); |
| 4011 | } |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 4012 | |
| 4013 | // In the following tests we verify successful skipping of a parent layer, |
| 4014 | // so we use the same verification logic and only change how we mutate |
| 4015 | // the parent layer to verify that various properties are ignored. |
| 4016 | class ScreenCaptureChildOnlyTest : public LayerUpdateTest { |
| 4017 | public: |
| 4018 | void SetUp() override { |
| 4019 | LayerUpdateTest::SetUp(); |
| 4020 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4021 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, |
| 4022 | mFGSurfaceControl.get()); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 4023 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 4024 | |
| 4025 | SurfaceComposerClient::Transaction().show(mChild).apply(true); |
| 4026 | } |
| 4027 | |
| 4028 | void verify() { |
| 4029 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 4030 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); |
| 4031 | mCapture->checkPixel(10, 10, 0, 0, 0); |
| 4032 | mCapture->expectChildColor(0, 0); |
| 4033 | } |
| 4034 | |
| 4035 | std::unique_ptr<ScreenCapture> mCapture; |
| 4036 | sp<SurfaceControl> mChild; |
| 4037 | }; |
| 4038 | |
| 4039 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentVisibility) { |
| 4040 | |
| 4041 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); |
| 4042 | |
| 4043 | // Even though the parent is hidden we should still capture the child. |
| 4044 | verify(); |
| 4045 | } |
| 4046 | |
| 4047 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentCrop) { |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4048 | SurfaceComposerClient::Transaction() |
| 4049 | .setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 1, 1)) |
| 4050 | .apply(true); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 4051 | |
| 4052 | // Even though the parent is cropped out we should still capture the child. |
| 4053 | verify(); |
| 4054 | } |
| 4055 | |
| 4056 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresTransform) { |
| 4057 | |
| 4058 | SurfaceComposerClient::Transaction().setMatrix(mFGSurfaceControl, 2, 0, 0, 2); |
| 4059 | |
| 4060 | // We should not inherit the parent scaling. |
| 4061 | verify(); |
| 4062 | } |
| 4063 | |
Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 4064 | TEST_F(ScreenCaptureChildOnlyTest, RegressionTest76099859) { |
| 4065 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); |
| 4066 | |
| 4067 | // Even though the parent is hidden we should still capture the child. |
| 4068 | verify(); |
| 4069 | |
| 4070 | // Verify everything was properly hidden when rendering the full-screen. |
| 4071 | screenshot()->expectBGColor(0,0); |
| 4072 | } |
| 4073 | |
| 4074 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4075 | TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) { |
| 4076 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 4077 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4078 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 4079 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4080 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4081 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4082 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, |
| 4083 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4084 | |
| 4085 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 4086 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4087 | .show(child) |
| 4088 | .setPosition(grandchild, 5, 5) |
| 4089 | .show(grandchild) |
| 4090 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4091 | |
| 4092 | // Captures mFGSurfaceControl, its child, and the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4093 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4094 | mCapture->expectFGColor(10, 10); |
| 4095 | mCapture->expectChildColor(0, 0); |
| 4096 | mCapture->checkPixel(5, 5, 50, 50, 50); |
| 4097 | } |
| 4098 | |
| 4099 | TEST_F(ScreenCaptureTest, CaptureChildOnly) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4100 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 4101 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4102 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4103 | auto childHandle = child->getHandle(); |
| 4104 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4105 | SurfaceComposerClient::Transaction().setPosition(child, 5, 5).show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4106 | |
| 4107 | // Captures only the child layer, and not the parent. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4108 | ScreenCapture::captureLayers(&mCapture, childHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4109 | mCapture->expectChildColor(0, 0); |
| 4110 | mCapture->expectChildColor(9, 9); |
| 4111 | } |
| 4112 | |
| 4113 | TEST_F(ScreenCaptureTest, CaptureGrandchildOnly) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4114 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 4115 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4116 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4117 | auto childHandle = child->getHandle(); |
| 4118 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4119 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, |
| 4120 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4121 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 4122 | |
| 4123 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4124 | .show(child) |
| 4125 | .setPosition(grandchild, 5, 5) |
| 4126 | .show(grandchild) |
| 4127 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4128 | |
| 4129 | auto grandchildHandle = grandchild->getHandle(); |
| 4130 | |
| 4131 | // Captures only the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4132 | ScreenCapture::captureLayers(&mCapture, grandchildHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4133 | mCapture->checkPixel(0, 0, 50, 50, 50); |
| 4134 | mCapture->checkPixel(4, 4, 50, 50, 50); |
| 4135 | } |
| 4136 | |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4137 | TEST_F(ScreenCaptureTest, CaptureCrop) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4138 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4139 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, |
| 4140 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4141 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4142 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
| 4143 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4144 | |
| 4145 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4146 | .setLayer(redLayer, INT32_MAX - 1) |
| 4147 | .show(redLayer) |
| 4148 | .show(blueLayer) |
| 4149 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4150 | |
| 4151 | auto redLayerHandle = redLayer->getHandle(); |
| 4152 | |
| 4153 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4154 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 4155 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 4156 | // red area below the blue area |
| 4157 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 4158 | // red area to the right of the blue area |
| 4159 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4160 | |
| 4161 | Rect crop = Rect(0, 0, 30, 30); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4162 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, crop); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4163 | // Capturing the cropped screen, cropping out the shown red area, should leave only the blue |
| 4164 | // area visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4165 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4166 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 4167 | } |
| 4168 | |
| 4169 | TEST_F(ScreenCaptureTest, CaptureSize) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4170 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4171 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, |
| 4172 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4173 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4174 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
| 4175 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4176 | |
| 4177 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4178 | .setLayer(redLayer, INT32_MAX - 1) |
| 4179 | .show(redLayer) |
| 4180 | .show(blueLayer) |
| 4181 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4182 | |
| 4183 | auto redLayerHandle = redLayer->getHandle(); |
| 4184 | |
| 4185 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4186 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 4187 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 4188 | // red area below the blue area |
| 4189 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 4190 | // red area to the right of the blue area |
| 4191 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4192 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4193 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, Rect::EMPTY_RECT, 0.5); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4194 | // 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] | 4195 | mCapture->expectColor(Rect(0, 0, 14, 14), Color::BLUE); |
| 4196 | // red area below the blue area |
| 4197 | mCapture->expectColor(Rect(0, 15, 29, 29), Color::RED); |
| 4198 | // red area to the right of the blue area |
| 4199 | mCapture->expectColor(Rect(15, 0, 29, 29), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4200 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 4201 | } |
| 4202 | |
| 4203 | TEST_F(ScreenCaptureTest, CaptureInvalidLayer) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4204 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4205 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4206 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4207 | |
| 4208 | auto redLayerHandle = redLayer->getHandle(); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4209 | mClient->destroySurface(redLayerHandle); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4210 | SurfaceComposerClient::Transaction().apply(true); |
| 4211 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4212 | sp<GraphicBuffer> outBuffer; |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 4213 | |
| 4214 | // Layer was deleted so captureLayers should fail with NAME_NOT_FOUND |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4215 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 4216 | 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] | 4217 | } |
| 4218 | |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 4219 | |
| 4220 | class DereferenceSurfaceControlTest : public LayerTransactionTest { |
| 4221 | protected: |
| 4222 | void SetUp() override { |
| 4223 | LayerTransactionTest::SetUp(); |
| 4224 | bgLayer = createLayer("BG layer", 20, 20); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4225 | fillBufferQueueLayerColor(bgLayer, Color::RED, 20, 20); |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 4226 | fgLayer = createLayer("FG layer", 20, 20); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 4227 | fillBufferQueueLayerColor(fgLayer, Color::BLUE, 20, 20); |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 4228 | Transaction().setLayer(fgLayer, mLayerZBase + 1).apply(); |
| 4229 | { |
| 4230 | SCOPED_TRACE("before anything"); |
| 4231 | auto shot = screenshot(); |
| 4232 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); |
| 4233 | } |
| 4234 | } |
| 4235 | void TearDown() override { |
| 4236 | LayerTransactionTest::TearDown(); |
| 4237 | bgLayer = 0; |
| 4238 | fgLayer = 0; |
| 4239 | } |
| 4240 | |
| 4241 | sp<SurfaceControl> bgLayer; |
| 4242 | sp<SurfaceControl> fgLayer; |
| 4243 | }; |
| 4244 | |
| 4245 | TEST_F(DereferenceSurfaceControlTest, LayerNotInTransaction) { |
| 4246 | fgLayer = nullptr; |
| 4247 | { |
| 4248 | SCOPED_TRACE("after setting null"); |
| 4249 | auto shot = screenshot(); |
| 4250 | shot->expectColor(Rect(0, 0, 20, 20), Color::RED); |
| 4251 | } |
| 4252 | } |
| 4253 | |
| 4254 | TEST_F(DereferenceSurfaceControlTest, LayerInTransaction) { |
| 4255 | auto transaction = Transaction().show(fgLayer); |
| 4256 | fgLayer = nullptr; |
| 4257 | { |
| 4258 | SCOPED_TRACE("after setting null"); |
| 4259 | auto shot = screenshot(); |
| 4260 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); |
| 4261 | } |
| 4262 | } |
| 4263 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4264 | } // namespace android |