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 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 29 | #include <binder/ProcessState.h> |
| 30 | #include <gui/BufferItemConsumer.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 31 | #include <gui/ISurfaceComposer.h> |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 32 | #include <gui/LayerState.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 33 | #include <gui/Surface.h> |
| 34 | #include <gui/SurfaceComposerClient.h> |
| 35 | #include <private/gui/ComposerService.h> |
| 36 | |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 37 | #include <ui/ColorSpace.h> |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 38 | #include <ui/DisplayInfo.h> |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 39 | #include <ui/Rect.h> |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 40 | #include <utils/String8.h> |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 41 | |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 42 | #include <math.h> |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 43 | #include <math/vec3.h> |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 44 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 45 | #include "BufferGenerator.h" |
| 46 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 47 | namespace android { |
| 48 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 49 | namespace { |
| 50 | |
| 51 | struct Color { |
| 52 | uint8_t r; |
| 53 | uint8_t g; |
| 54 | uint8_t b; |
| 55 | uint8_t a; |
| 56 | |
| 57 | static const Color RED; |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 58 | static const Color GREEN; |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 59 | static const Color BLUE; |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 60 | static const Color WHITE; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 61 | static const Color BLACK; |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 62 | static const Color TRANSPARENT; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | const Color Color::RED{255, 0, 0, 255}; |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 66 | const Color Color::GREEN{0, 255, 0, 255}; |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 67 | const Color Color::BLUE{0, 0, 255, 255}; |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 68 | const Color Color::WHITE{255, 255, 255, 255}; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 69 | const Color Color::BLACK{0, 0, 0, 255}; |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 70 | const Color Color::TRANSPARENT{0, 0, 0, 0}; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 71 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 72 | using android::hardware::graphics::common::V1_1::BufferUsage; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 73 | using namespace std::chrono_literals; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 74 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 75 | std::ostream& operator<<(std::ostream& os, const Color& color) { |
| 76 | os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a); |
| 77 | return os; |
| 78 | } |
| 79 | |
| 80 | // Fill a region with the specified color. |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 81 | void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect, |
| 82 | const Color& color) { |
| 83 | Rect r(0, 0, buffer.width, buffer.height); |
| 84 | if (!r.intersect(rect, &r)) { |
| 85 | return; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 88 | int32_t width = r.right - r.left; |
| 89 | int32_t height = r.bottom - r.top; |
| 90 | |
| 91 | for (int32_t row = 0; row < height; row++) { |
| 92 | uint8_t* dst = |
| 93 | static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (r.top + row) + r.left) * 4; |
| 94 | for (int32_t column = 0; column < width; column++) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 95 | dst[0] = color.r; |
| 96 | dst[1] = color.g; |
| 97 | dst[2] = color.b; |
| 98 | dst[3] = color.a; |
| 99 | dst += 4; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 104 | // Fill a region with the specified color. |
| 105 | void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect, const Color& color) { |
| 106 | Rect r(0, 0, buffer->width, buffer->height); |
| 107 | if (!r.intersect(rect, &r)) { |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | int32_t width = r.right - r.left; |
| 112 | int32_t height = r.bottom - r.top; |
| 113 | |
| 114 | uint8_t* pixels; |
| 115 | buffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 116 | reinterpret_cast<void**>(&pixels)); |
| 117 | |
| 118 | for (int32_t row = 0; row < height; row++) { |
| 119 | uint8_t* dst = pixels + (buffer->getStride() * (r.top + row) + r.left) * 4; |
| 120 | for (int32_t column = 0; column < width; column++) { |
| 121 | dst[0] = color.r; |
| 122 | dst[1] = color.g; |
| 123 | dst[2] = color.b; |
| 124 | dst[3] = color.a; |
| 125 | dst += 4; |
| 126 | } |
| 127 | } |
| 128 | buffer->unlock(); |
| 129 | } |
| 130 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 131 | // Check if a region has the specified color. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 132 | 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] | 133 | const Color& color, uint8_t tolerance) { |
| 134 | int32_t x = rect.left; |
| 135 | int32_t y = rect.top; |
| 136 | int32_t width = rect.right - rect.left; |
| 137 | int32_t height = rect.bottom - rect.top; |
| 138 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 139 | int32_t bufferWidth = int32_t(outBuffer->getWidth()); |
| 140 | int32_t bufferHeight = int32_t(outBuffer->getHeight()); |
| 141 | if (x + width > bufferWidth) { |
| 142 | x = std::min(x, bufferWidth); |
| 143 | width = bufferWidth - x; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 144 | } |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 145 | if (y + height > bufferHeight) { |
| 146 | y = std::min(y, bufferHeight); |
| 147 | height = bufferHeight - y; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | auto colorCompare = [tolerance](uint8_t a, uint8_t b) { |
| 151 | uint8_t tmp = a >= b ? a - b : b - a; |
| 152 | return tmp <= tolerance; |
| 153 | }; |
| 154 | for (int32_t j = 0; j < height; j++) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 155 | const uint8_t* src = pixels + (outBuffer->getStride() * (y + j) + x) * 4; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 156 | for (int32_t i = 0; i < width; i++) { |
| 157 | const uint8_t expected[4] = {color.r, color.g, color.b, color.a}; |
| 158 | EXPECT_TRUE(std::equal(src, src + 4, expected, colorCompare)) |
| 159 | << "pixel @ (" << x + i << ", " << y + j << "): " |
| 160 | << "expected (" << color << "), " |
| 161 | << "got (" << Color{src[0], src[1], src[2], src[3]} << ")"; |
| 162 | src += 4; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | } // anonymous namespace |
| 168 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 169 | using Transaction = SurfaceComposerClient::Transaction; |
| 170 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 171 | // Fill an RGBA_8888 formatted surface with a single color. |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 172 | static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b, |
| 173 | bool unlock = true) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 174 | ANativeWindow_Buffer outBuffer; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 175 | sp<Surface> s = sc->getSurface(); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 176 | ASSERT_TRUE(s != nullptr); |
| 177 | ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, nullptr)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 178 | uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 179 | for (int y = 0; y < outBuffer.height; y++) { |
| 180 | for (int x = 0; x < outBuffer.width; x++) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 181 | uint8_t* pixel = img + (4 * (y * outBuffer.stride + x)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 182 | pixel[0] = r; |
| 183 | pixel[1] = g; |
| 184 | pixel[2] = b; |
| 185 | pixel[3] = 255; |
| 186 | } |
| 187 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 188 | if (unlock) { |
| 189 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 190 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | // A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check |
| 194 | // individual pixel values for testing purposes. |
| 195 | class ScreenCapture : public RefBase { |
| 196 | public: |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 197 | static void captureScreen(std::unique_ptr<ScreenCapture>* sc) { |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 198 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 199 | sp<IBinder> display(sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 200 | SurfaceComposerClient::Transaction().apply(true); |
| 201 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 202 | sp<GraphicBuffer> outBuffer; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 203 | ASSERT_EQ(NO_ERROR, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 204 | sf->captureScreen(display, &outBuffer, Rect(), 0, 0, false)); |
| 205 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, |
| 209 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { |
| 210 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 211 | SurfaceComposerClient::Transaction().apply(true); |
| 212 | |
| 213 | sp<GraphicBuffer> outBuffer; |
| 214 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale)); |
| 215 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 218 | static void captureChildLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, |
| 219 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { |
| 220 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 221 | SurfaceComposerClient::Transaction().apply(true); |
| 222 | |
| 223 | sp<GraphicBuffer> outBuffer; |
| 224 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale, true)); |
| 225 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
| 226 | } |
| 227 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 228 | void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 229 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
| 230 | expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 234 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 235 | const bool leftBorder = rect.left > 0; |
| 236 | const bool topBorder = rect.top > 0; |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 237 | const bool rightBorder = rect.right < int32_t(mOutBuffer->getWidth()); |
| 238 | const bool bottomBorder = rect.bottom < int32_t(mOutBuffer->getHeight()); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 239 | |
| 240 | if (topBorder) { |
| 241 | Rect top(rect.left, rect.top - 1, rect.right, rect.top); |
| 242 | if (leftBorder) { |
| 243 | top.left -= 1; |
| 244 | } |
| 245 | if (rightBorder) { |
| 246 | top.right += 1; |
| 247 | } |
| 248 | expectColor(top, color, tolerance); |
| 249 | } |
| 250 | if (leftBorder) { |
| 251 | Rect left(rect.left - 1, rect.top, rect.left, rect.bottom); |
| 252 | expectColor(left, color, tolerance); |
| 253 | } |
| 254 | if (rightBorder) { |
| 255 | Rect right(rect.right, rect.top, rect.right + 1, rect.bottom); |
| 256 | expectColor(right, color, tolerance); |
| 257 | } |
| 258 | if (bottomBorder) { |
| 259 | Rect bottom(rect.left, rect.bottom, rect.right, rect.bottom + 1); |
| 260 | if (leftBorder) { |
| 261 | bottom.left -= 1; |
| 262 | } |
| 263 | if (rightBorder) { |
| 264 | bottom.right += 1; |
| 265 | } |
| 266 | expectColor(bottom, color, tolerance); |
| 267 | } |
| 268 | } |
| 269 | |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 270 | void expectQuadrant(const Rect& rect, const Color& topLeft, const Color& topRight, |
| 271 | const Color& bottomLeft, const Color& bottomRight, bool filtered = false, |
| 272 | uint8_t tolerance = 0) { |
| 273 | ASSERT_TRUE((rect.right - rect.left) % 2 == 0 && (rect.bottom - rect.top) % 2 == 0); |
| 274 | |
| 275 | const int32_t centerX = rect.left + (rect.right - rect.left) / 2; |
| 276 | const int32_t centerY = rect.top + (rect.bottom - rect.top) / 2; |
| 277 | // avoid checking borders due to unspecified filtering behavior |
| 278 | const int32_t offsetX = filtered ? 2 : 0; |
| 279 | const int32_t offsetY = filtered ? 2 : 0; |
| 280 | expectColor(Rect(rect.left, rect.top, centerX - offsetX, centerY - offsetY), topLeft, |
| 281 | tolerance); |
| 282 | expectColor(Rect(centerX + offsetX, rect.top, rect.right, centerY - offsetY), topRight, |
| 283 | tolerance); |
| 284 | expectColor(Rect(rect.left, centerY + offsetY, centerX - offsetX, rect.bottom), bottomLeft, |
| 285 | tolerance); |
| 286 | expectColor(Rect(centerX + offsetX, centerY + offsetY, rect.right, rect.bottom), |
| 287 | bottomRight, tolerance); |
| 288 | } |
| 289 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 290 | 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] | 291 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
| 292 | const uint8_t* pixel = mPixels + (4 * (y * mOutBuffer->getStride() + x)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 293 | if (r != pixel[0] || g != pixel[1] || b != pixel[2]) { |
| 294 | String8 err(String8::format("pixel @ (%3d, %3d): " |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 295 | "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]", |
| 296 | x, y, r, g, b, pixel[0], pixel[1], pixel[2])); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 297 | EXPECT_EQ(String8(), err) << err.string(); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 301 | 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] | 302 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 303 | 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] | 304 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 305 | 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] | 306 | |
Chih-Hung Hsieh | 2274904 | 2018-12-20 15:50:39 -0800 | [diff] [blame] | 307 | explicit ScreenCapture(const sp<GraphicBuffer>& outBuffer) : mOutBuffer(outBuffer) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 308 | mOutBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&mPixels)); |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 309 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 310 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 311 | ~ScreenCapture() { mOutBuffer->unlock(); } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 312 | |
| 313 | private: |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 314 | sp<GraphicBuffer> mOutBuffer; |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 315 | uint8_t* mPixels = nullptr; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 316 | }; |
| 317 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 318 | class LayerTransactionTest : public ::testing::Test { |
| 319 | protected: |
| 320 | void SetUp() override { |
| 321 | mClient = new SurfaceComposerClient; |
| 322 | ASSERT_EQ(NO_ERROR, mClient->initCheck()) << "failed to create SurfaceComposerClient"; |
| 323 | |
| 324 | ASSERT_NO_FATAL_FAILURE(SetUpDisplay()); |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 325 | |
| 326 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 327 | sp<IBinder> binder = sf->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain); |
Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 328 | ASSERT_NO_FATAL_FAILURE(sf->getColorManagement(&mColorManagementUsed)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 329 | } |
| 330 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 331 | virtual void TearDown() { |
| 332 | mBlackBgSurface = 0; |
| 333 | mClient->dispose(); |
| 334 | mClient = 0; |
| 335 | } |
| 336 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 337 | virtual sp<SurfaceControl> createLayer(const sp<SurfaceComposerClient>& client, |
| 338 | const char* name, uint32_t width, uint32_t height, |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 339 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { |
| 340 | auto layer = |
| 341 | createSurface(client, name, width, height, PIXEL_FORMAT_RGBA_8888, flags, parent); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 342 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 343 | Transaction t; |
| 344 | t.setLayerStack(layer, mDisplayLayerStack).setLayer(layer, mLayerZBase); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 345 | |
| 346 | status_t error = t.apply(); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 347 | if (error != NO_ERROR) { |
| 348 | ADD_FAILURE() << "failed to initialize SurfaceControl"; |
| 349 | layer.clear(); |
| 350 | } |
| 351 | |
| 352 | return layer; |
| 353 | } |
| 354 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 355 | virtual sp<SurfaceControl> createSurface(const sp<SurfaceComposerClient>& client, |
| 356 | const char* name, uint32_t width, uint32_t height, |
| 357 | PixelFormat format, uint32_t flags, |
| 358 | SurfaceControl* parent = nullptr) { |
| 359 | auto layer = client->createSurface(String8(name), width, height, format, flags, parent); |
| 360 | EXPECT_NE(nullptr, layer.get()) << "failed to create SurfaceControl"; |
| 361 | return layer; |
| 362 | } |
| 363 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 364 | virtual sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 365 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { |
| 366 | return createLayer(mClient, name, width, height, flags, parent); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 369 | ANativeWindow_Buffer getBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 370 | // wait for previous transactions (such as setSize) to complete |
| 371 | Transaction().apply(true); |
| 372 | |
| 373 | ANativeWindow_Buffer buffer = {}; |
| 374 | EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr)); |
| 375 | |
| 376 | return buffer; |
| 377 | } |
| 378 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 379 | void postBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 380 | ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost()); |
| 381 | |
| 382 | // wait for the newly posted buffer to be latched |
| 383 | waitForLayerBuffers(); |
| 384 | } |
| 385 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 386 | virtual void fillBufferQueueLayerColor(const sp<SurfaceControl>& layer, const Color& color, |
| 387 | int32_t bufferWidth, int32_t bufferHeight) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 388 | ANativeWindow_Buffer buffer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 389 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 390 | fillANativeWindowBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); |
| 391 | postBufferQueueLayerBuffer(layer); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 394 | virtual void fillBufferStateLayerColor(const sp<SurfaceControl>& layer, const Color& color, |
| 395 | int32_t bufferWidth, int32_t bufferHeight) { |
| 396 | sp<GraphicBuffer> buffer = |
| 397 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, |
| 398 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 399 | BufferUsage::COMPOSER_OVERLAY, |
| 400 | "test"); |
| 401 | fillGraphicBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 402 | Transaction().setBuffer(layer, buffer).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void fillLayerColor(uint32_t mLayerType, const sp<SurfaceControl>& layer, const Color& color, |
| 406 | int32_t bufferWidth, int32_t bufferHeight) { |
| 407 | switch (mLayerType) { |
| 408 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 409 | fillBufferQueueLayerColor(layer, color, bufferWidth, bufferHeight); |
| 410 | break; |
| 411 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 412 | fillBufferStateLayerColor(layer, color, bufferWidth, bufferHeight); |
| 413 | break; |
| 414 | default: |
| 415 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | void fillLayerQuadrant(uint32_t mLayerType, const sp<SurfaceControl>& layer, |
| 420 | int32_t bufferWidth, int32_t bufferHeight, const Color& topLeft, |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 421 | const Color& topRight, const Color& bottomLeft, |
| 422 | const Color& bottomRight) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 423 | switch (mLayerType) { |
| 424 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 425 | fillBufferQueueLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, |
| 426 | bottomLeft, bottomRight); |
| 427 | break; |
| 428 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 429 | fillBufferStateLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, |
| 430 | bottomLeft, bottomRight); |
| 431 | break; |
| 432 | default: |
| 433 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | virtual void fillBufferQueueLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 438 | int32_t bufferHeight, const Color& topLeft, |
| 439 | const Color& topRight, const Color& bottomLeft, |
| 440 | const Color& bottomRight) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 441 | ANativeWindow_Buffer buffer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 442 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 443 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 444 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 445 | const int32_t halfW = bufferWidth / 2; |
| 446 | const int32_t halfH = bufferHeight / 2; |
| 447 | fillANativeWindowBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); |
| 448 | fillANativeWindowBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); |
| 449 | fillANativeWindowBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); |
| 450 | fillANativeWindowBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), |
| 451 | bottomRight); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 452 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 453 | postBufferQueueLayerBuffer(layer); |
| 454 | } |
| 455 | |
| 456 | virtual void fillBufferStateLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 457 | int32_t bufferHeight, const Color& topLeft, |
| 458 | const Color& topRight, const Color& bottomLeft, |
| 459 | const Color& bottomRight) { |
| 460 | sp<GraphicBuffer> buffer = |
| 461 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, |
| 462 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 463 | BufferUsage::COMPOSER_OVERLAY, |
| 464 | "test"); |
| 465 | |
| 466 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); |
| 467 | |
| 468 | const int32_t halfW = bufferWidth / 2; |
| 469 | const int32_t halfH = bufferHeight / 2; |
| 470 | fillGraphicBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); |
| 471 | fillGraphicBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); |
| 472 | fillGraphicBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); |
| 473 | fillGraphicBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), bottomRight); |
| 474 | |
| 475 | Transaction().setBuffer(layer, buffer).setSize(layer, bufferWidth, bufferHeight).apply(); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 476 | } |
| 477 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 478 | std::unique_ptr<ScreenCapture> screenshot() { |
| 479 | std::unique_ptr<ScreenCapture> screenshot; |
| 480 | ScreenCapture::captureScreen(&screenshot); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 481 | return screenshot; |
| 482 | } |
| 483 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 484 | static status_t getBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) { |
| 485 | static BufferGenerator bufferGenerator; |
| 486 | return bufferGenerator.get(outBuffer, outFence); |
| 487 | } |
| 488 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 489 | sp<SurfaceComposerClient> mClient; |
| 490 | |
| 491 | sp<IBinder> mDisplay; |
| 492 | uint32_t mDisplayWidth; |
| 493 | uint32_t mDisplayHeight; |
| 494 | uint32_t mDisplayLayerStack; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 495 | Rect mDisplayRect = Rect::INVALID_RECT; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 496 | |
| 497 | // leave room for ~256 layers |
| 498 | const int32_t mLayerZBase = std::numeric_limits<int32_t>::max() - 256; |
| 499 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 500 | sp<SurfaceControl> mBlackBgSurface; |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 501 | bool mColorManagementUsed; |
| 502 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 503 | private: |
| 504 | void SetUpDisplay() { |
| 505 | mDisplay = mClient->getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain); |
| 506 | ASSERT_NE(nullptr, mDisplay.get()) << "failed to get built-in display"; |
| 507 | |
| 508 | // get display width/height |
| 509 | DisplayInfo info; |
| 510 | SurfaceComposerClient::getDisplayInfo(mDisplay, &info); |
| 511 | mDisplayWidth = info.w; |
| 512 | mDisplayHeight = info.h; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 513 | mDisplayRect = |
| 514 | Rect(static_cast<int32_t>(mDisplayWidth), static_cast<int32_t>(mDisplayHeight)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 515 | |
| 516 | // After a new buffer is queued, SurfaceFlinger is notified and will |
| 517 | // latch the new buffer on next vsync. Let's heuristically wait for 3 |
| 518 | // vsyncs. |
| 519 | mBufferPostDelay = int32_t(1e6 / info.fps) * 3; |
| 520 | |
| 521 | mDisplayLayerStack = 0; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 522 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 523 | mBlackBgSurface = |
| 524 | createSurface(mClient, "BaseSurface", 0 /* buffer width */, 0 /* buffer height */, |
| 525 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 526 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 527 | // set layer stack (b/68888219) |
| 528 | Transaction t; |
| 529 | t.setDisplayLayerStack(mDisplay, mDisplayLayerStack); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 530 | t.setCrop_legacy(mBlackBgSurface, Rect(0, 0, mDisplayWidth, mDisplayHeight)); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 531 | t.setLayerStack(mBlackBgSurface, mDisplayLayerStack); |
| 532 | t.setColor(mBlackBgSurface, half3{0, 0, 0}); |
| 533 | t.setLayer(mBlackBgSurface, mLayerZBase); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 534 | t.apply(); |
| 535 | } |
| 536 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 537 | void waitForLayerBuffers() { |
| 538 | // Request an empty transaction to get applied synchronously to ensure the buffer is |
| 539 | // latched. |
| 540 | Transaction().apply(true); |
| 541 | usleep(mBufferPostDelay); |
| 542 | } |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 543 | |
| 544 | int32_t mBufferPostDelay; |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 545 | |
| 546 | friend class LayerRenderPathTestHarness; |
| 547 | }; |
| 548 | enum class RenderPath { SCREENSHOT, VIRTUAL_DISPLAY }; |
| 549 | |
| 550 | class LayerRenderPathTestHarness { |
| 551 | public: |
| 552 | LayerRenderPathTestHarness(LayerTransactionTest* delegate, RenderPath renderPath) |
| 553 | : mDelegate(delegate), mRenderPath(renderPath) {} |
| 554 | |
| 555 | std::unique_ptr<ScreenCapture> getScreenCapture() { |
| 556 | switch (mRenderPath) { |
| 557 | case RenderPath::SCREENSHOT: |
| 558 | return mDelegate->screenshot(); |
| 559 | case RenderPath::VIRTUAL_DISPLAY: |
| 560 | |
| 561 | sp<IBinder> mainDisplay = |
| 562 | SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain); |
| 563 | DisplayInfo mainDisplayInfo; |
| 564 | SurfaceComposerClient::getDisplayInfo(mainDisplay, &mainDisplayInfo); |
| 565 | |
| 566 | sp<IBinder> vDisplay; |
| 567 | sp<IGraphicBufferProducer> producer; |
| 568 | sp<IGraphicBufferConsumer> consumer; |
| 569 | sp<BufferItemConsumer> itemConsumer; |
| 570 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 571 | |
| 572 | consumer->setConsumerName(String8("Virtual disp consumer")); |
| 573 | consumer->setDefaultBufferSize(mainDisplayInfo.w, mainDisplayInfo.h); |
| 574 | |
| 575 | itemConsumer = new BufferItemConsumer(consumer, |
| 576 | // Sample usage bits from screenrecord |
| 577 | GRALLOC_USAGE_HW_VIDEO_ENCODER | |
| 578 | GRALLOC_USAGE_SW_READ_OFTEN); |
| 579 | |
| 580 | vDisplay = SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), |
| 581 | false /*secure*/); |
| 582 | |
| 583 | SurfaceComposerClient::Transaction t; |
| 584 | t.setDisplaySurface(vDisplay, producer); |
| 585 | t.setDisplayLayerStack(vDisplay, 0); |
| 586 | t.setDisplayProjection(vDisplay, mainDisplayInfo.orientation, |
| 587 | Rect(mainDisplayInfo.viewportW, mainDisplayInfo.viewportH), |
| 588 | Rect(mainDisplayInfo.w, mainDisplayInfo.h)); |
| 589 | t.apply(); |
| 590 | SurfaceComposerClient::Transaction().apply(true); |
| 591 | BufferItem item; |
| 592 | itemConsumer->acquireBuffer(&item, 0, true); |
| 593 | auto sc = std::make_unique<ScreenCapture>(item.mGraphicBuffer); |
| 594 | itemConsumer->releaseBuffer(item); |
| 595 | SurfaceComposerClient::destroyDisplay(vDisplay); |
| 596 | return sc; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | protected: |
| 601 | LayerTransactionTest* mDelegate; |
| 602 | RenderPath mRenderPath; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 603 | }; |
| 604 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 605 | class LayerTypeTransactionHarness : public LayerTransactionTest { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 606 | public: |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 607 | LayerTypeTransactionHarness(uint32_t layerType) : mLayerType(layerType) {} |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 608 | |
| 609 | sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 610 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 611 | // if the flags already have a layer type specified, return an error |
| 612 | if (flags & ISurfaceComposerClient::eFXSurfaceMask) { |
| 613 | return nullptr; |
| 614 | } |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 615 | return LayerTransactionTest::createLayer(name, width, height, flags | mLayerType, parent); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color, int32_t bufferWidth, |
| 619 | int32_t bufferHeight) { |
| 620 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerColor(mLayerType, layer, color, |
| 621 | bufferWidth, bufferHeight)); |
| 622 | } |
| 623 | |
| 624 | void fillLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 625 | int32_t bufferHeight, const Color& topLeft, const Color& topRight, |
| 626 | const Color& bottomLeft, const Color& bottomRight) { |
| 627 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerQuadrant(mLayerType, layer, |
| 628 | bufferWidth, bufferHeight, |
| 629 | topLeft, topRight, |
| 630 | bottomLeft, bottomRight)); |
| 631 | } |
| 632 | |
| 633 | protected: |
| 634 | uint32_t mLayerType; |
| 635 | }; |
| 636 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 637 | class LayerTypeTransactionTest : public LayerTypeTransactionHarness, |
| 638 | public ::testing::WithParamInterface<uint32_t> { |
| 639 | public: |
| 640 | LayerTypeTransactionTest() : LayerTypeTransactionHarness(GetParam()) {} |
| 641 | }; |
| 642 | |
| 643 | class LayerTypeAndRenderTypeTransactionTest |
| 644 | : public LayerTypeTransactionHarness, |
| 645 | public ::testing::WithParamInterface<std::tuple<uint32_t, RenderPath>> { |
| 646 | public: |
| 647 | LayerTypeAndRenderTypeTransactionTest() |
| 648 | : LayerTypeTransactionHarness(std::get<0>(GetParam())), |
| 649 | mRenderPathHarness(LayerRenderPathTestHarness(this, std::get<1>(GetParam()))) {} |
| 650 | |
| 651 | std::unique_ptr<ScreenCapture> getScreenCapture() { |
| 652 | return mRenderPathHarness.getScreenCapture(); |
| 653 | } |
| 654 | |
| 655 | protected: |
| 656 | LayerRenderPathTestHarness mRenderPathHarness; |
| 657 | }; |
| 658 | |
| 659 | // Environment for starting up binder threads. This is required for testing |
| 660 | // virtual displays, as BufferQueue parameters may be queried over binder. |
| 661 | class BinderEnvironment : public ::testing::Environment { |
| 662 | public: |
| 663 | void SetUp() override { ProcessState::self()->startThreadPool(); } |
| 664 | }; |
| 665 | |
| 666 | ::testing::Environment* const binderEnv = |
| 667 | ::testing::AddGlobalTestEnvironment(new BinderEnvironment()); |
| 668 | |
| 669 | class LayerRenderTypeTransactionTest : public LayerTransactionTest, |
| 670 | public ::testing::WithParamInterface<RenderPath> { |
| 671 | public: |
| 672 | LayerRenderTypeTransactionTest() : mHarness(LayerRenderPathTestHarness(this, GetParam())) {} |
| 673 | |
| 674 | std::unique_ptr<ScreenCapture> getScreenCapture() { return mHarness.getScreenCapture(); } |
| 675 | void setRelativeZBasicHelper(uint32_t layerType); |
| 676 | void setRelativeZGroupHelper(uint32_t layerType); |
| 677 | void setAlphaBasicHelper(uint32_t layerType); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 678 | void setBackgroundColorHelper(uint32_t layerType, bool priorColor, bool bufferFill, float alpha, |
| 679 | Color finalColor); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 680 | |
| 681 | protected: |
| 682 | LayerRenderPathTestHarness mHarness; |
| 683 | }; |
| 684 | |
| 685 | INSTANTIATE_TEST_CASE_P( |
| 686 | LayerTypeAndRenderTypeTransactionTests, LayerTypeAndRenderTypeTransactionTest, |
| 687 | ::testing::Combine( |
| 688 | ::testing::Values( |
| 689 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferQueue), |
| 690 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferState)), |
| 691 | ::testing::Values(RenderPath::VIRTUAL_DISPLAY, RenderPath::SCREENSHOT))); |
| 692 | |
| 693 | INSTANTIATE_TEST_CASE_P(LayerRenderTypeTransactionTests, LayerRenderTypeTransactionTest, |
| 694 | ::testing::Values(RenderPath::VIRTUAL_DISPLAY, RenderPath::SCREENSHOT)); |
| 695 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 696 | INSTANTIATE_TEST_CASE_P( |
| 697 | LayerTypeTransactionTests, LayerTypeTransactionTest, |
| 698 | ::testing::Values(static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferQueue), |
| 699 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferState))); |
| 700 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 701 | TEST_P(LayerRenderTypeTransactionTest, SetPositionBasic_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 702 | sp<SurfaceControl> layer; |
| 703 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 704 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 705 | |
| 706 | { |
| 707 | SCOPED_TRACE("default position"); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 708 | const Rect rect(0, 0, 32, 32); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 709 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 710 | shot->expectColor(rect, Color::RED); |
| 711 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | Transaction().setPosition(layer, 5, 10).apply(); |
| 715 | { |
| 716 | SCOPED_TRACE("new position"); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 717 | const Rect rect(5, 10, 37, 42); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 718 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 719 | shot->expectColor(rect, Color::RED); |
| 720 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 724 | TEST_P(LayerRenderTypeTransactionTest, SetPositionRounding_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 725 | sp<SurfaceControl> layer; |
| 726 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 727 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 728 | |
| 729 | // GLES requires only 4 bits of subpixel precision during rasterization |
| 730 | // XXX GLES composition does not match HWC composition due to precision |
| 731 | // loss (b/69315223) |
| 732 | const float epsilon = 1.0f / 16.0f; |
| 733 | Transaction().setPosition(layer, 0.5f - epsilon, 0.5f - epsilon).apply(); |
| 734 | { |
| 735 | SCOPED_TRACE("rounding down"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 736 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | Transaction().setPosition(layer, 0.5f + epsilon, 0.5f + epsilon).apply(); |
| 740 | { |
| 741 | SCOPED_TRACE("rounding up"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 742 | getScreenCapture()->expectColor(Rect(1, 1, 33, 33), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 746 | TEST_P(LayerRenderTypeTransactionTest, SetPositionOutOfBounds_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 747 | sp<SurfaceControl> layer; |
| 748 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 749 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 750 | |
| 751 | Transaction().setPosition(layer, -32, -32).apply(); |
| 752 | { |
| 753 | SCOPED_TRACE("negative coordinates"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 754 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | Transaction().setPosition(layer, mDisplayWidth, mDisplayHeight).apply(); |
| 758 | { |
| 759 | SCOPED_TRACE("positive coordinates"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 760 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 764 | TEST_P(LayerRenderTypeTransactionTest, SetPositionPartiallyOutOfBounds_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 765 | sp<SurfaceControl> layer; |
| 766 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 767 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 768 | |
| 769 | // partially out of bounds |
| 770 | Transaction().setPosition(layer, -30, -30).apply(); |
| 771 | { |
| 772 | SCOPED_TRACE("negative coordinates"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 773 | getScreenCapture()->expectColor(Rect(0, 0, 2, 2), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | Transaction().setPosition(layer, mDisplayWidth - 2, mDisplayHeight - 2).apply(); |
| 777 | { |
| 778 | SCOPED_TRACE("positive coordinates"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 779 | getScreenCapture()->expectColor(Rect(mDisplayWidth - 2, mDisplayHeight - 2, mDisplayWidth, |
| 780 | mDisplayHeight), |
| 781 | Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 785 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithResize_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 786 | sp<SurfaceControl> layer; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 787 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 788 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 789 | |
| 790 | // setPosition is applied immediately by default, with or without resize |
| 791 | // pending |
| 792 | Transaction().setPosition(layer, 5, 10).setSize(layer, 64, 64).apply(); |
| 793 | { |
| 794 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 795 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 796 | const Rect rect(5, 10, 37, 42); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 797 | shot->expectColor(rect, Color::RED); |
| 798 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 801 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 802 | { |
| 803 | SCOPED_TRACE("resize applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 804 | getScreenCapture()->expectColor(Rect(5, 10, 69, 74), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 808 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithNextResize_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 809 | sp<SurfaceControl> layer; |
| 810 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 811 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 812 | |
| 813 | // request setPosition to be applied with the next resize |
| 814 | Transaction().setPosition(layer, 5, 10).setGeometryAppliesWithResize(layer).apply(); |
| 815 | { |
| 816 | SCOPED_TRACE("new position pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 817 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | Transaction().setPosition(layer, 15, 20).apply(); |
| 821 | { |
| 822 | SCOPED_TRACE("pending new position modified"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 823 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | Transaction().setSize(layer, 64, 64).apply(); |
| 827 | { |
| 828 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 829 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | // finally resize and latch the buffer |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 833 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 834 | { |
| 835 | SCOPED_TRACE("new position applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 836 | getScreenCapture()->expectColor(Rect(15, 20, 79, 84), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 837 | } |
| 838 | } |
| 839 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 840 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithNextResizeScaleToWindow_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 841 | sp<SurfaceControl> layer; |
| 842 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 843 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 844 | |
| 845 | // setPosition is not immediate even with SCALE_TO_WINDOW override |
| 846 | Transaction() |
| 847 | .setPosition(layer, 5, 10) |
| 848 | .setSize(layer, 64, 64) |
| 849 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 850 | .setGeometryAppliesWithResize(layer) |
| 851 | .apply(); |
| 852 | { |
| 853 | SCOPED_TRACE("new position pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 854 | getScreenCapture()->expectColor(Rect(0, 0, 64, 64), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 855 | } |
| 856 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 857 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 858 | { |
| 859 | SCOPED_TRACE("new position applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 860 | getScreenCapture()->expectColor(Rect(5, 10, 69, 74), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 864 | TEST_P(LayerRenderTypeTransactionTest, SetSizeBasic_BufferQueue) { |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 865 | sp<SurfaceControl> layer; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 866 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 867 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 868 | |
| 869 | Transaction().setSize(layer, 64, 64).apply(); |
| 870 | { |
| 871 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 872 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 873 | const Rect rect(0, 0, 32, 32); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 874 | shot->expectColor(rect, Color::RED); |
| 875 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 878 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 879 | { |
| 880 | SCOPED_TRACE("resize applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 881 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 882 | const Rect rect(0, 0, 64, 64); |
| 883 | shot->expectColor(rect, Color::RED); |
| 884 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 888 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetSizeInvalid) { |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 889 | // cannot test robustness against invalid sizes (zero or really huge) |
| 890 | } |
| 891 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 892 | TEST_P(LayerRenderTypeTransactionTest, SetSizeWithScaleToWindow_BufferQueue) { |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 893 | sp<SurfaceControl> layer; |
| 894 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 895 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 896 | |
| 897 | // setSize is immediate with SCALE_TO_WINDOW, unlike setPosition |
| 898 | Transaction() |
| 899 | .setSize(layer, 64, 64) |
| 900 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 901 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 902 | getScreenCapture()->expectColor(Rect(0, 0, 64, 64), Color::RED); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 905 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetZBasic) { |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 906 | sp<SurfaceControl> layerR; |
| 907 | sp<SurfaceControl> layerG; |
| 908 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 909 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 910 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 911 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 912 | |
| 913 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); |
| 914 | { |
| 915 | SCOPED_TRACE("layerR"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 916 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | Transaction().setLayer(layerG, mLayerZBase + 2).apply(); |
| 920 | { |
| 921 | SCOPED_TRACE("layerG"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 922 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::GREEN); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 926 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetZNegative) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 927 | sp<SurfaceControl> parent = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 928 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 929 | ISurfaceComposerClient::eFXSurfaceContainer); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 930 | Transaction().setCrop_legacy(parent, Rect(0, 0, mDisplayWidth, mDisplayHeight)).apply(); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 931 | sp<SurfaceControl> layerR; |
| 932 | sp<SurfaceControl> layerG; |
| 933 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 934 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 935 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 936 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 937 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 938 | Transaction() |
| 939 | .reparent(layerR, parent->getHandle()) |
| 940 | .reparent(layerG, parent->getHandle()) |
| 941 | .apply(); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 942 | Transaction().setLayer(layerR, -1).setLayer(layerG, -2).apply(); |
| 943 | { |
| 944 | SCOPED_TRACE("layerR"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 945 | auto shot = getScreenCapture(); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 946 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | Transaction().setLayer(layerR, -3).apply(); |
| 950 | { |
| 951 | SCOPED_TRACE("layerG"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 952 | auto shot = getScreenCapture(); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 953 | shot->expectColor(Rect(0, 0, 32, 32), Color::GREEN); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 954 | } |
| 955 | } |
| 956 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 957 | void LayerRenderTypeTransactionTest::setRelativeZBasicHelper(uint32_t layerType) { |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 958 | sp<SurfaceControl> layerR; |
| 959 | sp<SurfaceControl> layerG; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 960 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32, layerType)); |
| 961 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerR, Color::RED, 32, 32)); |
| 962 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32, layerType)); |
| 963 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 964 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 965 | switch (layerType) { |
| 966 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 967 | Transaction() |
| 968 | .setPosition(layerG, 16, 16) |
| 969 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 970 | .apply(); |
| 971 | break; |
| 972 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 973 | Transaction() |
| 974 | .setFrame(layerR, Rect(0, 0, 32, 32)) |
| 975 | .setFrame(layerG, Rect(16, 16, 48, 48)) |
| 976 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 977 | .apply(); |
| 978 | break; |
| 979 | default: |
| 980 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 981 | } |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 982 | { |
| 983 | SCOPED_TRACE("layerG above"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 984 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 985 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 986 | shot->expectColor(Rect(16, 16, 48, 48), Color::GREEN); |
| 987 | } |
| 988 | |
| 989 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).apply(); |
| 990 | { |
| 991 | SCOPED_TRACE("layerG below"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 992 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 993 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 994 | shot->expectColor(Rect(32, 32, 48, 48), Color::GREEN); |
| 995 | } |
| 996 | } |
| 997 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 998 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZBasic_BufferQueue) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 999 | ASSERT_NO_FATAL_FAILURE(setRelativeZBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); |
| 1000 | } |
| 1001 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1002 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZBasic_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1003 | ASSERT_NO_FATAL_FAILURE(setRelativeZBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1004 | } |
| 1005 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1006 | TEST_P(LayerTypeTransactionTest, SetRelativeZNegative) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1007 | sp<SurfaceControl> parent = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1008 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1009 | ISurfaceComposerClient::eFXSurfaceContainer); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1010 | Transaction().setCrop_legacy(parent, Rect(0, 0, mDisplayWidth, mDisplayHeight)).apply(); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1011 | sp<SurfaceControl> layerR; |
| 1012 | sp<SurfaceControl> layerG; |
| 1013 | sp<SurfaceControl> layerB; |
| 1014 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1015 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1016 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1017 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1018 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1019 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1020 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1021 | Transaction() |
| 1022 | .reparent(layerB, parent->getHandle()) |
| 1023 | .apply(); |
| 1024 | |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1025 | // layerR = mLayerZBase, layerG = layerR - 1, layerB = -2 |
| 1026 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).setLayer(layerB, -2).apply(); |
| 1027 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1028 | std::unique_ptr<ScreenCapture> screenshot; |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1029 | // only layerB is in this range |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1030 | sp<IBinder> parentHandle = parent->getHandle(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1031 | ScreenCapture::captureLayers(&screenshot, parentHandle, Rect(0, 0, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1032 | screenshot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 1033 | } |
| 1034 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1035 | void LayerRenderTypeTransactionTest::setRelativeZGroupHelper(uint32_t layerType) { |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1036 | sp<SurfaceControl> layerR; |
| 1037 | sp<SurfaceControl> layerG; |
| 1038 | sp<SurfaceControl> layerB; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1039 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test", 32, 32, layerType)); |
| 1040 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerR, Color::RED, 32, 32)); |
| 1041 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test", 32, 32, layerType)); |
| 1042 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerG, Color::GREEN, 32, 32)); |
| 1043 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test", 32, 32, layerType)); |
| 1044 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerB, Color::BLUE, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1045 | |
| 1046 | // layerR = 0, layerG = layerR + 3, layerB = 2 |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1047 | switch (layerType) { |
| 1048 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 1049 | Transaction() |
| 1050 | .setPosition(layerG, 8, 8) |
| 1051 | .setRelativeLayer(layerG, layerR->getHandle(), 3) |
| 1052 | .setPosition(layerB, 16, 16) |
| 1053 | .setLayer(layerB, mLayerZBase + 2) |
| 1054 | .apply(); |
| 1055 | break; |
| 1056 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 1057 | Transaction() |
| 1058 | .setFrame(layerR, Rect(0, 0, 32, 32)) |
| 1059 | .setFrame(layerG, Rect(8, 8, 40, 40)) |
| 1060 | .setRelativeLayer(layerG, layerR->getHandle(), 3) |
| 1061 | .setFrame(layerB, Rect(16, 16, 48, 48)) |
| 1062 | .setLayer(layerB, mLayerZBase + 2) |
| 1063 | .apply(); |
| 1064 | break; |
| 1065 | default: |
| 1066 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 1067 | } |
| 1068 | |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1069 | { |
| 1070 | SCOPED_TRACE("(layerR < layerG) < layerB"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1071 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1072 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); |
| 1073 | shot->expectColor(Rect(8, 8, 16, 16), Color::GREEN); |
| 1074 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); |
| 1075 | } |
| 1076 | |
| 1077 | // layerR = 4, layerG = layerR + 3, layerB = 2 |
| 1078 | Transaction().setLayer(layerR, mLayerZBase + 4).apply(); |
| 1079 | { |
| 1080 | SCOPED_TRACE("layerB < (layerR < layerG)"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1081 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1082 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); |
| 1083 | shot->expectColor(Rect(8, 8, 40, 40), Color::GREEN); |
| 1084 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); |
| 1085 | } |
| 1086 | |
| 1087 | // layerR = 4, layerG = layerR - 3, layerB = 2 |
| 1088 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -3).apply(); |
| 1089 | { |
| 1090 | SCOPED_TRACE("layerB < (layerG < layerR)"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1091 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1092 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1093 | shot->expectColor(Rect(32, 32, 40, 40), Color::GREEN); |
| 1094 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); |
| 1095 | } |
| 1096 | |
| 1097 | // restore to absolute z |
| 1098 | // layerR = 4, layerG = 0, layerB = 2 |
| 1099 | Transaction().setLayer(layerG, mLayerZBase).apply(); |
| 1100 | { |
| 1101 | SCOPED_TRACE("layerG < layerB < layerR"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1102 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1103 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1104 | shot->expectColor(Rect(32, 32, 48, 48), Color::BLUE); |
| 1105 | } |
| 1106 | |
| 1107 | // layerR should not affect layerG anymore |
| 1108 | // layerR = 1, layerG = 0, layerB = 2 |
| 1109 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); |
| 1110 | { |
| 1111 | SCOPED_TRACE("layerG < layerR < layerB"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1112 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1113 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 1114 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); |
| 1115 | } |
| 1116 | } |
| 1117 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1118 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZGroup_BufferQueue) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1119 | ASSERT_NO_FATAL_FAILURE(setRelativeZGroupHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); |
| 1120 | } |
| 1121 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1122 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZGroup_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1123 | ASSERT_NO_FATAL_FAILURE(setRelativeZGroupHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1124 | } |
| 1125 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1126 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetRelativeZBug64572777) { |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1127 | sp<SurfaceControl> layerR; |
| 1128 | sp<SurfaceControl> layerG; |
| 1129 | |
| 1130 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1131 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1132 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1133 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1134 | |
| 1135 | Transaction() |
| 1136 | .setPosition(layerG, 16, 16) |
| 1137 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 1138 | .apply(); |
| 1139 | |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1140 | layerG->clear(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1141 | // layerG should have been removed |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1142 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1145 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetFlagsHidden) { |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1146 | sp<SurfaceControl> layer; |
| 1147 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1148 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1149 | |
| 1150 | Transaction().setFlags(layer, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden).apply(); |
| 1151 | { |
| 1152 | SCOPED_TRACE("layer hidden"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1153 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | Transaction().setFlags(layer, 0, layer_state_t::eLayerHidden).apply(); |
| 1157 | { |
| 1158 | SCOPED_TRACE("layer shown"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1159 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1163 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetFlagsOpaque) { |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1164 | const Color translucentRed = {100, 0, 0, 100}; |
| 1165 | sp<SurfaceControl> layerR; |
| 1166 | sp<SurfaceControl> layerG; |
| 1167 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1168 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, translucentRed, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1169 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1170 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1171 | |
| 1172 | Transaction() |
| 1173 | .setLayer(layerR, mLayerZBase + 1) |
| 1174 | .setFlags(layerR, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque) |
| 1175 | .apply(); |
| 1176 | { |
| 1177 | SCOPED_TRACE("layerR opaque"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1178 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {100, 0, 0, 255}); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | Transaction().setFlags(layerR, 0, layer_state_t::eLayerOpaque).apply(); |
| 1182 | { |
| 1183 | SCOPED_TRACE("layerR translucent"); |
| 1184 | const uint8_t g = uint8_t(255 - translucentRed.a); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1185 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {100, g, 0, 255}); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1189 | TEST_P(LayerTypeTransactionTest, SetFlagsSecure) { |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1190 | sp<SurfaceControl> layer; |
| 1191 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1192 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1193 | |
| 1194 | sp<ISurfaceComposer> composer = ComposerService::getComposerService(); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 1195 | sp<GraphicBuffer> outBuffer; |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1196 | Transaction() |
| 1197 | .setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure) |
| 1198 | .apply(true); |
| 1199 | ASSERT_EQ(PERMISSION_DENIED, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1200 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1201 | |
| 1202 | Transaction().setFlags(layer, 0, layer_state_t::eLayerSecure).apply(true); |
| 1203 | ASSERT_EQ(NO_ERROR, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1204 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1207 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintBasic_BufferQueue) { |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1208 | const Rect top(0, 0, 32, 16); |
| 1209 | const Rect bottom(0, 16, 32, 32); |
| 1210 | sp<SurfaceControl> layer; |
| 1211 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1212 | |
| 1213 | ANativeWindow_Buffer buffer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1214 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 1215 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::TRANSPARENT)); |
| 1216 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::RED)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1217 | // setTransparentRegionHint always applies to the following buffer |
| 1218 | Transaction().setTransparentRegionHint(layer, Region(top)).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1219 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1220 | { |
| 1221 | SCOPED_TRACE("top transparent"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1222 | auto shot = getScreenCapture(); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1223 | shot->expectColor(top, Color::BLACK); |
| 1224 | shot->expectColor(bottom, Color::RED); |
| 1225 | } |
| 1226 | |
| 1227 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); |
| 1228 | { |
| 1229 | SCOPED_TRACE("transparent region hint pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1230 | auto shot = getScreenCapture(); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1231 | shot->expectColor(top, Color::BLACK); |
| 1232 | shot->expectColor(bottom, Color::RED); |
| 1233 | } |
| 1234 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1235 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 1236 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::RED)); |
| 1237 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::TRANSPARENT)); |
| 1238 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1239 | { |
| 1240 | SCOPED_TRACE("bottom transparent"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1241 | auto shot = getScreenCapture(); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1242 | shot->expectColor(top, Color::RED); |
| 1243 | shot->expectColor(bottom, Color::BLACK); |
| 1244 | } |
| 1245 | } |
| 1246 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1247 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1248 | const Rect top(0, 0, 32, 16); |
| 1249 | const Rect bottom(0, 16, 32, 32); |
| 1250 | sp<SurfaceControl> layer; |
| 1251 | ASSERT_NO_FATAL_FAILURE( |
| 1252 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1253 | |
| 1254 | sp<GraphicBuffer> buffer = |
| 1255 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 1256 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 1257 | BufferUsage::COMPOSER_OVERLAY, |
| 1258 | "test"); |
| 1259 | |
| 1260 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::TRANSPARENT)); |
| 1261 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::RED)); |
| 1262 | Transaction() |
| 1263 | .setTransparentRegionHint(layer, Region(top)) |
| 1264 | .setBuffer(layer, buffer) |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1265 | .setFrame(layer, Rect(0, 0, 32, 32)) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1266 | .apply(); |
| 1267 | { |
| 1268 | SCOPED_TRACE("top transparent"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1269 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1270 | shot->expectColor(top, Color::BLACK); |
| 1271 | shot->expectColor(bottom, Color::RED); |
| 1272 | } |
| 1273 | |
| 1274 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); |
| 1275 | { |
| 1276 | SCOPED_TRACE("transparent region hint intermediate"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1277 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1278 | shot->expectColor(top, Color::BLACK); |
| 1279 | shot->expectColor(bottom, Color::BLACK); |
| 1280 | } |
| 1281 | |
| 1282 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 1283 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 1284 | BufferUsage::COMPOSER_OVERLAY, |
| 1285 | "test"); |
| 1286 | |
| 1287 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::RED)); |
| 1288 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::TRANSPARENT)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1289 | Transaction().setBuffer(layer, buffer).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1290 | { |
| 1291 | SCOPED_TRACE("bottom transparent"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1292 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1293 | shot->expectColor(top, Color::RED); |
| 1294 | shot->expectColor(bottom, Color::BLACK); |
| 1295 | } |
| 1296 | } |
| 1297 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1298 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintOutOfBounds_BufferQueue) { |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1299 | sp<SurfaceControl> layerTransparent; |
| 1300 | sp<SurfaceControl> layerR; |
| 1301 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); |
| 1302 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 1303 | |
| 1304 | // check that transparent region hint is bound by the layer size |
| 1305 | Transaction() |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1306 | .setTransparentRegionHint(layerTransparent, Region(mDisplayRect)) |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1307 | .setPosition(layerR, 16, 16) |
| 1308 | .setLayer(layerR, mLayerZBase + 1) |
| 1309 | .apply(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1310 | ASSERT_NO_FATAL_FAILURE( |
| 1311 | fillBufferQueueLayerColor(layerTransparent, Color::TRANSPARENT, 32, 32)); |
| 1312 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layerR, Color::RED, 32, 32)); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1313 | getScreenCapture()->expectColor(Rect(16, 16, 48, 48), Color::RED); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1316 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintOutOfBounds_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1317 | sp<SurfaceControl> layerTransparent; |
| 1318 | sp<SurfaceControl> layerR; |
| 1319 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); |
| 1320 | ASSERT_NO_FATAL_FAILURE( |
| 1321 | layerR = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1322 | |
| 1323 | // check that transparent region hint is bound by the layer size |
| 1324 | Transaction() |
| 1325 | .setTransparentRegionHint(layerTransparent, Region(mDisplayRect)) |
| 1326 | .setFrame(layerR, Rect(16, 16, 48, 48)) |
| 1327 | .setLayer(layerR, mLayerZBase + 1) |
| 1328 | .apply(); |
| 1329 | ASSERT_NO_FATAL_FAILURE( |
| 1330 | fillBufferQueueLayerColor(layerTransparent, Color::TRANSPARENT, 32, 32)); |
| 1331 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layerR, Color::RED, 32, 32)); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1332 | getScreenCapture()->expectColor(Rect(16, 16, 48, 48), Color::RED); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1335 | void LayerRenderTypeTransactionTest::setAlphaBasicHelper(uint32_t layerType) { |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1336 | sp<SurfaceControl> layer1; |
| 1337 | sp<SurfaceControl> layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1338 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer("test 1", 32, 32, layerType)); |
| 1339 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer("test 2", 32, 32, layerType)); |
| 1340 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer1, {64, 0, 0, 255}, 32, 32)); |
| 1341 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer2, {0, 64, 0, 255}, 32, 32)); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1342 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1343 | switch (layerType) { |
| 1344 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 1345 | Transaction() |
| 1346 | .setAlpha(layer1, 0.25f) |
| 1347 | .setAlpha(layer2, 0.75f) |
| 1348 | .setPosition(layer2, 16, 0) |
| 1349 | .setLayer(layer2, mLayerZBase + 1) |
| 1350 | .apply(); |
| 1351 | break; |
| 1352 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 1353 | Transaction() |
| 1354 | .setAlpha(layer1, 0.25f) |
| 1355 | .setAlpha(layer2, 0.75f) |
| 1356 | .setFrame(layer1, Rect(0, 0, 32, 32)) |
| 1357 | .setFrame(layer2, Rect(16, 0, 48, 32)) |
| 1358 | .setLayer(layer2, mLayerZBase + 1) |
| 1359 | .apply(); |
| 1360 | break; |
| 1361 | default: |
| 1362 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 1363 | } |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1364 | { |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1365 | auto shot = getScreenCapture(); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1366 | uint8_t r = 16; // 64 * 0.25f |
| 1367 | uint8_t g = 48; // 64 * 0.75f |
| 1368 | shot->expectColor(Rect(0, 0, 16, 32), {r, 0, 0, 255}); |
| 1369 | shot->expectColor(Rect(32, 0, 48, 32), {0, g, 0, 255}); |
| 1370 | |
| 1371 | r /= 4; // r * (1.0f - 0.75f) |
| 1372 | shot->expectColor(Rect(16, 0, 32, 32), {r, g, 0, 255}); |
| 1373 | } |
| 1374 | } |
| 1375 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1376 | TEST_P(LayerRenderTypeTransactionTest, SetAlphaBasic_BufferQueue) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1377 | ASSERT_NO_FATAL_FAILURE(setAlphaBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); |
| 1378 | } |
| 1379 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1380 | TEST_P(LayerRenderTypeTransactionTest, SetAlphaBasic_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1381 | ASSERT_NO_FATAL_FAILURE(setAlphaBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1382 | } |
| 1383 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1384 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetAlphaClamped) { |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1385 | const Color color = {64, 0, 0, 255}; |
| 1386 | sp<SurfaceControl> layer; |
| 1387 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1388 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, color, 32, 32)); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1389 | |
| 1390 | Transaction().setAlpha(layer, 2.0f).apply(); |
| 1391 | { |
| 1392 | SCOPED_TRACE("clamped to 1.0f"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1393 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), color); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | Transaction().setAlpha(layer, -1.0f).apply(); |
| 1397 | { |
| 1398 | SCOPED_TRACE("clamped to 0.0f"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1399 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1403 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadius) { |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1404 | sp<SurfaceControl> layer; |
| 1405 | const uint8_t size = 64; |
| 1406 | const uint8_t testArea = 4; |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1407 | const float cornerRadius = 20.0f; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1408 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", size, size)); |
| 1409 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, size, size)); |
| 1410 | |
| 1411 | Transaction() |
| 1412 | .setCornerRadius(layer, cornerRadius) |
| 1413 | .apply(); |
| 1414 | { |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1415 | const uint8_t bottom = size - 1; |
| 1416 | const uint8_t right = size - 1; |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1417 | auto shot = getScreenCapture(); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1418 | // Transparent corners |
| 1419 | shot->expectColor(Rect(0, 0, testArea, testArea), Color::BLACK); |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1420 | shot->expectColor(Rect(size - testArea, 0, right, testArea), Color::BLACK); |
| 1421 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); |
| 1422 | shot->expectColor(Rect(size - testArea, bottom - testArea, right, bottom), Color::BLACK); |
| 1423 | } |
| 1424 | } |
| 1425 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1426 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusChildCrop) { |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1427 | sp<SurfaceControl> parent; |
| 1428 | sp<SurfaceControl> child; |
| 1429 | const uint8_t size = 64; |
| 1430 | const uint8_t testArea = 4; |
| 1431 | const float cornerRadius = 20.0f; |
| 1432 | ASSERT_NO_FATAL_FAILURE(parent = createLayer("parent", size, size)); |
| 1433 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(parent, Color::RED, size, size)); |
| 1434 | ASSERT_NO_FATAL_FAILURE(child = createLayer("child", size, size / 2)); |
| 1435 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(child, Color::GREEN, size, size / 2)); |
| 1436 | |
| 1437 | Transaction() |
| 1438 | .setCornerRadius(parent, cornerRadius) |
| 1439 | .reparent(child, parent->getHandle()) |
| 1440 | .setPosition(child, 0, size / 2) |
| 1441 | .apply(); |
| 1442 | { |
| 1443 | const uint8_t bottom = size - 1; |
| 1444 | const uint8_t right = size - 1; |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1445 | auto shot = getScreenCapture(); |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1446 | // Top edge of child should not have rounded corners because it's translated in the parent |
| 1447 | shot->expectColor(Rect(0, size / 2, right, static_cast<int>(bottom - cornerRadius)), |
| 1448 | Color::GREEN); |
| 1449 | // But bottom edges should have been clipped according to parent bounds |
| 1450 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); |
| 1451 | shot->expectColor(Rect(right - testArea, bottom - testArea, right, bottom), Color::BLACK); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1455 | TEST_P(LayerRenderTypeTransactionTest, SetColorBasic) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1456 | sp<SurfaceControl> bufferLayer; |
| 1457 | sp<SurfaceControl> colorLayer; |
| 1458 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1459 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1460 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 1461 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 1462 | ISurfaceComposerClient::eFXSurfaceColor)); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1463 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1464 | Transaction() |
| 1465 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 1466 | .setLayer(colorLayer, mLayerZBase + 1) |
| 1467 | .apply(); |
| 1468 | |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1469 | { |
| 1470 | SCOPED_TRACE("default color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1471 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1475 | const Color expected = {15, 51, 85, 255}; |
| 1476 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 1477 | // channel) should be less than one |
| 1478 | const uint8_t tolerance = 1; |
| 1479 | Transaction().setColor(colorLayer, color).apply(); |
| 1480 | { |
| 1481 | SCOPED_TRACE("new color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1482 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expected, tolerance); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1483 | } |
| 1484 | } |
| 1485 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1486 | // RED: Color layer base color and BufferQueueLayer/BufferStateLayer fill |
| 1487 | // BLUE: prior background color |
| 1488 | // GREEN: final background color |
| 1489 | // BLACK: no color or fill |
| 1490 | void LayerRenderTypeTransactionTest::setBackgroundColorHelper(uint32_t layerType, bool priorColor, |
| 1491 | bool bufferFill, float alpha, |
| 1492 | Color finalColor) { |
| 1493 | sp<SurfaceControl> layer; |
| 1494 | int32_t width = 500; |
| 1495 | int32_t height = 500; |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1496 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1497 | Color fillColor = Color::RED; |
| 1498 | Color priorBgColor = Color::BLUE; |
| 1499 | Color expectedColor = Color::BLACK; |
| 1500 | switch (layerType) { |
| 1501 | case ISurfaceComposerClient::eFXSurfaceColor: |
| 1502 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 0, 0, layerType)); |
| 1503 | Transaction() |
| 1504 | .setCrop_legacy(layer, Rect(0, 0, width, height)) |
| 1505 | .setColor(layer, half3(1.0f, 0, 0)) |
| 1506 | .apply(); |
| 1507 | expectedColor = fillColor; |
| 1508 | break; |
| 1509 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 1510 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", width, height)); |
| 1511 | if (bufferFill) { |
| 1512 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, fillColor, width, height)); |
| 1513 | expectedColor = fillColor; |
| 1514 | } |
| 1515 | Transaction().setCrop_legacy(layer, Rect(0, 0, width, height)).apply(); |
| 1516 | break; |
| 1517 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 1518 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", width, height, layerType)); |
| 1519 | if (bufferFill) { |
| 1520 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, fillColor, width, height)); |
| 1521 | expectedColor = fillColor; |
| 1522 | } |
| 1523 | Transaction().setFrame(layer, Rect(0, 0, width, height)).apply(); |
| 1524 | break; |
| 1525 | default: |
| 1526 | GTEST_FAIL() << "Unknown layer type in setBackgroundColorHelper"; |
| 1527 | return; |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1528 | } |
| 1529 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1530 | if (priorColor && layerType != ISurfaceComposerClient::eFXSurfaceColor) { |
| 1531 | Transaction() |
| 1532 | .setBackgroundColor(layer, half3(0, 0, 1.0f), 1.0f, ui::Dataspace::UNKNOWN) |
| 1533 | .apply(); |
| 1534 | if (!bufferFill) { |
| 1535 | expectedColor = priorBgColor; |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | { |
| 1540 | SCOPED_TRACE("default before setting background color layer"); |
| 1541 | screenshot()->expectColor(Rect(0, 0, width, height), expectedColor); |
| 1542 | } |
| 1543 | |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1544 | Transaction() |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1545 | .setBackgroundColor(layer, half3(0, 1.0f, 0), alpha, ui::Dataspace::UNKNOWN) |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1546 | .apply(); |
| 1547 | |
| 1548 | { |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1549 | auto shot = screenshot(); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1550 | shot->expectColor(Rect(0, 0, width, height), finalColor); |
| 1551 | shot->expectBorder(Rect(0, 0, width, height), Color::BLACK); |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1555 | TEST_P(LayerRenderTypeTransactionTest, SetBackgroundColor_Color_NoEffect) { |
| 1556 | bool priorColor = false; |
| 1557 | bool bufferFill = false; |
| 1558 | float alpha = 1.0f; |
| 1559 | Color finalColor = Color::RED; |
| 1560 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceColor, |
| 1561 | priorColor, bufferFill, alpha, finalColor)); |
| 1562 | } |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1563 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1564 | TEST_P(LayerRenderTypeTransactionTest, |
| 1565 | SetBackgroundColor_BufferQueue_BufferFill_NoPriorColor_Basic) { |
| 1566 | bool priorColor = false; |
| 1567 | bool bufferFill = true; |
| 1568 | float alpha = 1.0f; |
| 1569 | Color finalColor = Color::RED; |
| 1570 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1571 | priorColor, bufferFill, alpha, finalColor)); |
| 1572 | } |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1573 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1574 | TEST_P(LayerRenderTypeTransactionTest, |
| 1575 | SetBackgroundColor_BufferQueue_NoBufferFill_NoPriorColor_Basic) { |
| 1576 | bool priorColor = false; |
| 1577 | bool bufferFill = false; |
| 1578 | float alpha = 1.0f; |
| 1579 | Color finalColor = Color::GREEN; |
| 1580 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1581 | priorColor, bufferFill, alpha, finalColor)); |
| 1582 | } |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1583 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1584 | TEST_P(LayerRenderTypeTransactionTest, SetBackgroundColor_BufferQueue_BufferFill_PriorColor_Basic) { |
| 1585 | bool priorColor = true; |
| 1586 | bool bufferFill = true; |
| 1587 | float alpha = 1.0f; |
| 1588 | Color finalColor = Color::RED; |
| 1589 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1590 | priorColor, bufferFill, alpha, finalColor)); |
| 1591 | } |
| 1592 | |
| 1593 | TEST_P(LayerRenderTypeTransactionTest, |
| 1594 | SetBackgroundColor_BufferQueue_NoBufferFill_PriorColor_Basic) { |
| 1595 | bool priorColor = true; |
| 1596 | bool bufferFill = false; |
| 1597 | float alpha = 1.0f; |
| 1598 | Color finalColor = Color::GREEN; |
| 1599 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1600 | priorColor, bufferFill, alpha, finalColor)); |
| 1601 | } |
| 1602 | TEST_P(LayerRenderTypeTransactionTest, |
| 1603 | SetBackgroundColor_BufferQueue_NoPriorColor_ZeroAlpha_NoEffect) { |
| 1604 | bool priorColor = false; |
| 1605 | bool bufferFill = false; |
| 1606 | float alpha = 0; |
| 1607 | Color finalColor = Color::BLACK; |
| 1608 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1609 | priorColor, bufferFill, alpha, finalColor)); |
| 1610 | } |
| 1611 | |
| 1612 | TEST_P(LayerRenderTypeTransactionTest, |
| 1613 | SetBackgroundColor_BufferQueue_PriorColor_ZeroAlpha_DeleteBackground) { |
| 1614 | bool priorColor = true; |
| 1615 | bool bufferFill = false; |
| 1616 | float alpha = 0; |
| 1617 | Color finalColor = Color::BLACK; |
| 1618 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1619 | priorColor, bufferFill, alpha, finalColor)); |
| 1620 | } |
| 1621 | |
| 1622 | TEST_P(LayerRenderTypeTransactionTest, |
| 1623 | SetBackgroundColor_BufferState_BufferFill_NoPriorColor_Basic) { |
| 1624 | bool priorColor = false; |
| 1625 | bool bufferFill = true; |
| 1626 | float alpha = 1.0f; |
| 1627 | Color finalColor = Color::RED; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame^] | 1628 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1629 | priorColor, bufferFill, alpha, finalColor)); |
| 1630 | } |
| 1631 | |
| 1632 | TEST_P(LayerRenderTypeTransactionTest, |
| 1633 | SetBackgroundColor_BufferState_NoBufferFill_NoPriorColor_Basic) { |
| 1634 | bool priorColor = false; |
| 1635 | bool bufferFill = false; |
| 1636 | float alpha = 1.0f; |
| 1637 | Color finalColor = Color::GREEN; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame^] | 1638 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1639 | priorColor, bufferFill, alpha, finalColor)); |
| 1640 | } |
| 1641 | |
| 1642 | TEST_P(LayerRenderTypeTransactionTest, |
| 1643 | SetBackgroundColor_BufferState_NoBufferFill_PriorColor_Basic) { |
| 1644 | bool priorColor = true; |
| 1645 | bool bufferFill = false; |
| 1646 | float alpha = 1.0f; |
| 1647 | Color finalColor = Color::GREEN; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame^] | 1648 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1649 | priorColor, bufferFill, alpha, finalColor)); |
| 1650 | } |
| 1651 | |
| 1652 | TEST_P(LayerRenderTypeTransactionTest, |
| 1653 | SetBackgroundColor_BufferState_NoPriorColor_ZeroAlpha_NoEffect) { |
| 1654 | bool priorColor = false; |
| 1655 | bool bufferFill = false; |
| 1656 | float alpha = 0; |
| 1657 | Color finalColor = Color::BLACK; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame^] | 1658 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1659 | priorColor, bufferFill, alpha, finalColor)); |
| 1660 | } |
| 1661 | |
| 1662 | TEST_P(LayerRenderTypeTransactionTest, |
| 1663 | SetBackgroundColor_BufferState_PriorColor_ZeroAlpha_DeleteBackground) { |
| 1664 | bool priorColor = true; |
| 1665 | bool bufferFill = false; |
| 1666 | float alpha = 0; |
| 1667 | Color finalColor = Color::BLACK; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame^] | 1668 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1669 | priorColor, bufferFill, alpha, finalColor)); |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1670 | } |
| 1671 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1672 | TEST_P(LayerRenderTypeTransactionTest, SetColorClamped) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1673 | sp<SurfaceControl> colorLayer; |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1674 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 1675 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 1676 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 1677 | Transaction() |
| 1678 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 1679 | .setColor(colorLayer, half3(2.0f, -1.0f, 0.0f)) |
| 1680 | .apply(); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1681 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1682 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1685 | TEST_P(LayerRenderTypeTransactionTest, SetColorWithAlpha) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1686 | sp<SurfaceControl> bufferLayer; |
| 1687 | sp<SurfaceControl> colorLayer; |
| 1688 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1689 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1690 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 1691 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 1692 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 1693 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1694 | |
| 1695 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1696 | const float alpha = 0.25f; |
| 1697 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); |
| 1698 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 1699 | // channel) should be less than one |
| 1700 | const uint8_t tolerance = 1; |
| 1701 | Transaction() |
| 1702 | .setColor(colorLayer, color) |
| 1703 | .setAlpha(colorLayer, alpha) |
| 1704 | .setLayer(colorLayer, mLayerZBase + 1) |
| 1705 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1706 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, |
| 1707 | tolerance); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1710 | TEST_P(LayerRenderTypeTransactionTest, SetColorWithParentAlpha_Bug74220420) { |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1711 | sp<SurfaceControl> bufferLayer; |
| 1712 | sp<SurfaceControl> parentLayer; |
| 1713 | sp<SurfaceControl> colorLayer; |
| 1714 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
| 1715 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parentWithAlpha", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1716 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1717 | ASSERT_NO_FATAL_FAILURE(colorLayer = createLayer("childWithColor", 0 /* buffer width */, |
| 1718 | 0 /* buffer height */, |
| 1719 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 1720 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1721 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1722 | const float alpha = 0.25f; |
| 1723 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); |
| 1724 | // this is handwavy, but the precision loss scaled by 255 (8-bit per |
| 1725 | // channel) should be less than one |
| 1726 | const uint8_t tolerance = 1; |
| 1727 | Transaction() |
| 1728 | .reparent(colorLayer, parentLayer->getHandle()) |
| 1729 | .setColor(colorLayer, color) |
| 1730 | .setAlpha(parentLayer, alpha) |
| 1731 | .setLayer(parentLayer, mLayerZBase + 1) |
| 1732 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1733 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, |
| 1734 | tolerance); |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1737 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetColorWithBuffer) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1738 | sp<SurfaceControl> bufferLayer; |
| 1739 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1740 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED, 32, 32)); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1741 | |
| 1742 | // color is ignored |
| 1743 | Transaction().setColor(bufferLayer, half3(0.0f, 1.0f, 0.0f)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1744 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1747 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetLayerStackBasic) { |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1748 | sp<SurfaceControl> layer; |
| 1749 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1750 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1751 | |
| 1752 | Transaction().setLayerStack(layer, mDisplayLayerStack + 1).apply(); |
| 1753 | { |
| 1754 | SCOPED_TRACE("non-existing layer stack"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1755 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | Transaction().setLayerStack(layer, mDisplayLayerStack).apply(); |
| 1759 | { |
| 1760 | SCOPED_TRACE("original layer stack"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1761 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1762 | } |
| 1763 | } |
| 1764 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1765 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixBasic_BufferQueue) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1766 | sp<SurfaceControl> layer; |
| 1767 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1768 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1769 | Color::BLUE, Color::WHITE)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1770 | |
| 1771 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 0, 0).apply(); |
| 1772 | { |
| 1773 | SCOPED_TRACE("IDENTITY"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1774 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1775 | Color::BLUE, Color::WHITE); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 32, 0).apply(); |
| 1779 | { |
| 1780 | SCOPED_TRACE("FLIP_H"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1781 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, |
| 1782 | Color::WHITE, Color::BLUE); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).setPosition(layer, 0, 32).apply(); |
| 1786 | { |
| 1787 | SCOPED_TRACE("FLIP_V"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1788 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, |
| 1789 | Color::RED, Color::GREEN); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).setPosition(layer, 32, 0).apply(); |
| 1793 | { |
| 1794 | SCOPED_TRACE("ROT_90"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1795 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, |
| 1796 | Color::WHITE, Color::GREEN); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setPosition(layer, 0, 0).apply(); |
| 1800 | { |
| 1801 | SCOPED_TRACE("SCALE"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1802 | getScreenCapture()->expectQuadrant(Rect(0, 0, 64, 64), Color::RED, Color::GREEN, |
| 1803 | Color::BLUE, Color::WHITE, true /* filtered */); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1807 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixBasic_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1808 | sp<SurfaceControl> layer; |
| 1809 | ASSERT_NO_FATAL_FAILURE( |
| 1810 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1811 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1812 | Color::BLUE, Color::WHITE)); |
| 1813 | |
| 1814 | Transaction() |
| 1815 | .setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f) |
| 1816 | .setFrame(layer, Rect(0, 0, 32, 32)) |
| 1817 | .apply(); |
| 1818 | { |
| 1819 | SCOPED_TRACE("IDENTITY"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1820 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1821 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).apply(); |
| 1825 | { |
| 1826 | SCOPED_TRACE("FLIP_H"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1827 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1828 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).apply(); |
| 1832 | { |
| 1833 | SCOPED_TRACE("FLIP_V"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1834 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1835 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).apply(); |
| 1839 | { |
| 1840 | SCOPED_TRACE("ROT_90"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1841 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1842 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).apply(); |
| 1846 | { |
| 1847 | SCOPED_TRACE("SCALE"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1848 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1849 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1850 | } |
| 1851 | } |
| 1852 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1853 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixRot45_BufferQueue) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1854 | sp<SurfaceControl> layer; |
| 1855 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1856 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1857 | Color::BLUE, Color::WHITE)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1858 | |
| 1859 | const float rot = M_SQRT1_2; // 45 degrees |
| 1860 | const float trans = M_SQRT2 * 16.0f; |
| 1861 | Transaction().setMatrix(layer, rot, rot, -rot, rot).setPosition(layer, trans, 0).apply(); |
| 1862 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1863 | auto shot = getScreenCapture(); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1864 | // check a 8x8 region inside each color |
| 1865 | auto get8x8Rect = [](int32_t centerX, int32_t centerY) { |
| 1866 | const int32_t halfL = 4; |
| 1867 | return Rect(centerX - halfL, centerY - halfL, centerX + halfL, centerY + halfL); |
| 1868 | }; |
| 1869 | const int32_t unit = int32_t(trans / 2); |
| 1870 | shot->expectColor(get8x8Rect(2 * unit, 1 * unit), Color::RED); |
| 1871 | shot->expectColor(get8x8Rect(3 * unit, 2 * unit), Color::GREEN); |
| 1872 | shot->expectColor(get8x8Rect(1 * unit, 2 * unit), Color::BLUE); |
| 1873 | shot->expectColor(get8x8Rect(2 * unit, 3 * unit), Color::WHITE); |
| 1874 | } |
| 1875 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1876 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixWithResize_BufferQueue) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1877 | sp<SurfaceControl> layer; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1878 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1879 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1880 | |
| 1881 | // setMatrix is applied after any pending resize, unlike setPosition |
| 1882 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setSize(layer, 64, 64).apply(); |
| 1883 | { |
| 1884 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1885 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1886 | const Rect rect(0, 0, 32, 32); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1887 | shot->expectColor(rect, Color::RED); |
| 1888 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1891 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1892 | { |
| 1893 | SCOPED_TRACE("resize applied"); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1894 | const Rect rect(0, 0, 128, 128); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1895 | getScreenCapture()->expectColor(rect, Color::RED); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1896 | } |
| 1897 | } |
| 1898 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1899 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixWithScaleToWindow_BufferQueue) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1900 | sp<SurfaceControl> layer; |
| 1901 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1902 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1903 | |
| 1904 | // setMatrix is immediate with SCALE_TO_WINDOW, unlike setPosition |
| 1905 | Transaction() |
| 1906 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
| 1907 | .setSize(layer, 64, 64) |
| 1908 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1909 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1910 | getScreenCapture()->expectColor(Rect(0, 0, 128, 128), Color::RED); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1913 | TEST_P(LayerRenderTypeTransactionTest, SetOverrideScalingModeBasic_BufferQueue) { |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1914 | sp<SurfaceControl> layer; |
| 1915 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1916 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1917 | Color::BLUE, Color::WHITE)); |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1918 | |
| 1919 | // XXX SCALE_CROP is not respected; calling setSize and |
| 1920 | // setOverrideScalingMode in separate transactions does not work |
| 1921 | // (b/69315456) |
| 1922 | Transaction() |
| 1923 | .setSize(layer, 64, 16) |
| 1924 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1925 | .apply(); |
| 1926 | { |
| 1927 | SCOPED_TRACE("SCALE_TO_WINDOW"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1928 | getScreenCapture()->expectQuadrant(Rect(0, 0, 64, 16), Color::RED, Color::GREEN, |
| 1929 | Color::BLUE, Color::WHITE, true /* filtered */); |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1930 | } |
| 1931 | } |
| 1932 | |
Dan Stoza | 000dd01 | 2018-08-01 13:31:52 -0700 | [diff] [blame] | 1933 | TEST_P(LayerTypeTransactionTest, RefreshRateIsInitialized) { |
| 1934 | sp<SurfaceControl> layer; |
| 1935 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1936 | |
| 1937 | sp<IBinder> handle = layer->getHandle(); |
| 1938 | ASSERT_TRUE(handle != nullptr); |
| 1939 | |
| 1940 | FrameStats frameStats; |
| 1941 | mClient->getLayerFrameStats(handle, &frameStats); |
| 1942 | |
| 1943 | ASSERT_GT(frameStats.refreshPeriodNano, static_cast<nsecs_t>(0)); |
| 1944 | } |
| 1945 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1946 | TEST_P(LayerRenderTypeTransactionTest, SetCropBasic_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1947 | sp<SurfaceControl> layer; |
| 1948 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1949 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1950 | const Rect crop(8, 8, 24, 24); |
| 1951 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1952 | Transaction().setCrop_legacy(layer, crop).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1953 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1954 | shot->expectColor(crop, Color::RED); |
| 1955 | shot->expectBorder(crop, Color::BLACK); |
| 1956 | } |
| 1957 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1958 | TEST_P(LayerRenderTypeTransactionTest, SetCropBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1959 | sp<SurfaceControl> layer; |
| 1960 | ASSERT_NO_FATAL_FAILURE( |
| 1961 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1962 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1963 | const Rect crop(8, 8, 24, 24); |
| 1964 | |
| 1965 | Transaction().setCrop(layer, crop).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1966 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1967 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1968 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1971 | TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1972 | sp<SurfaceControl> layer; |
| 1973 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1974 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1975 | |
| 1976 | { |
| 1977 | SCOPED_TRACE("empty rect"); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1978 | Transaction().setCrop_legacy(layer, Rect(8, 8, 8, 8)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1979 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | { |
| 1983 | SCOPED_TRACE("negative rect"); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1984 | Transaction().setCrop_legacy(layer, Rect(8, 8, 0, 0)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1985 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1986 | } |
| 1987 | } |
| 1988 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1989 | TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1990 | sp<SurfaceControl> layer; |
| 1991 | ASSERT_NO_FATAL_FAILURE( |
| 1992 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1993 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 1994 | |
| 1995 | { |
| 1996 | SCOPED_TRACE("empty rect"); |
| 1997 | Transaction().setCrop(layer, Rect(8, 8, 8, 8)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1998 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | { |
| 2002 | SCOPED_TRACE("negative rect"); |
| 2003 | Transaction().setCrop(layer, Rect(8, 8, 0, 0)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2004 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2005 | } |
| 2006 | } |
| 2007 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2008 | TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2009 | sp<SurfaceControl> layer; |
| 2010 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2011 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2012 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2013 | Transaction().setCrop_legacy(layer, Rect(-128, -64, 128, 64)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2014 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2015 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2016 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2017 | } |
| 2018 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2019 | TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferState) { |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2020 | sp<SurfaceControl> layer; |
| 2021 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", mDisplayWidth, mDisplayHeight / 2, |
| 2022 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2023 | sp<GraphicBuffer> buffer = |
| 2024 | new GraphicBuffer(mDisplayWidth, mDisplayHeight / 2, PIXEL_FORMAT_RGBA_8888, 1, |
| 2025 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2026 | BufferUsage::COMPOSER_OVERLAY, |
| 2027 | "test"); |
| 2028 | fillGraphicBufferColor(buffer, Rect(0, 0, mDisplayWidth, mDisplayHeight / 4), Color::BLUE); |
| 2029 | fillGraphicBufferColor(buffer, Rect(0, mDisplayHeight / 4, mDisplayWidth, mDisplayHeight / 2), |
| 2030 | Color::RED); |
| 2031 | |
| 2032 | Transaction().setBuffer(layer, buffer).apply(); |
| 2033 | |
| 2034 | // Partially out of bounds in the negative (upper left) direction |
| 2035 | Transaction().setCrop(layer, Rect(-128, -128, mDisplayWidth, mDisplayHeight / 4)).apply(); |
| 2036 | { |
| 2037 | SCOPED_TRACE("out of bounds, negative (upper left) direction"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2038 | auto shot = getScreenCapture(); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2039 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::BLUE); |
| 2040 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::BLACK); |
| 2041 | } |
| 2042 | |
| 2043 | // Partially out of bounds in the positive (lower right) direction |
| 2044 | Transaction() |
| 2045 | .setCrop(layer, Rect(0, mDisplayHeight / 4, mDisplayWidth + 1, mDisplayHeight)) |
| 2046 | .apply(); |
| 2047 | { |
| 2048 | SCOPED_TRACE("out of bounds, positive (lower right) direction"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2049 | auto shot = getScreenCapture(); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2050 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::RED); |
| 2051 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::BLACK); |
| 2052 | } |
| 2053 | |
| 2054 | // Fully out of buffer space bounds |
| 2055 | Transaction().setCrop(layer, Rect(-128, -128, -1, -1)).apply(); |
| 2056 | { |
| 2057 | SCOPED_TRACE("Fully out of bounds"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2058 | auto shot = getScreenCapture(); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2059 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight / 4), Color::BLUE); |
| 2060 | shot->expectColor(Rect(0, mDisplayHeight / 4, mDisplayWidth, mDisplayHeight / 2), |
| 2061 | Color::RED); |
| 2062 | } |
| 2063 | } |
| 2064 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2065 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithTranslation_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2066 | sp<SurfaceControl> layer; |
| 2067 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2068 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2069 | |
| 2070 | const Point position(32, 32); |
| 2071 | const Rect crop(8, 8, 24, 24); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2072 | Transaction().setPosition(layer, position.x, position.y).setCrop_legacy(layer, crop).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2073 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2074 | shot->expectColor(crop + position, Color::RED); |
| 2075 | shot->expectBorder(crop + position, Color::BLACK); |
| 2076 | } |
| 2077 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2078 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithTranslation_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2079 | sp<SurfaceControl> layer; |
| 2080 | ASSERT_NO_FATAL_FAILURE( |
| 2081 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2082 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2083 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2084 | const Rect frame(32, 32, 64, 64); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2085 | const Rect crop(8, 8, 24, 24); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2086 | Transaction().setFrame(layer, frame).setCrop(layer, crop).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2087 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2088 | shot->expectColor(frame, Color::RED); |
| 2089 | shot->expectBorder(frame, Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2092 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithScale_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2093 | sp<SurfaceControl> layer; |
| 2094 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2095 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2096 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2097 | // crop_legacy is affected by matrix |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2098 | Transaction() |
| 2099 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2100 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2101 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2102 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2103 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 2104 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); |
| 2105 | } |
| 2106 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2107 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithResize_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2108 | sp<SurfaceControl> layer; |
| 2109 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2110 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2111 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2112 | // setCrop_legacy is applied immediately by default, with or without resize pending |
| 2113 | 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] | 2114 | { |
| 2115 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2116 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2117 | shot->expectColor(Rect(8, 8, 24, 24), Color::RED); |
| 2118 | shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK); |
| 2119 | } |
| 2120 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2121 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2122 | { |
| 2123 | SCOPED_TRACE("resize applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2124 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2125 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 2126 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 2127 | } |
| 2128 | } |
| 2129 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2130 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithNextResize_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2131 | sp<SurfaceControl> layer; |
| 2132 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2133 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2134 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2135 | // request setCrop_legacy to be applied with the next resize |
| 2136 | Transaction() |
| 2137 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) |
| 2138 | .setGeometryAppliesWithResize(layer) |
| 2139 | .apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2140 | { |
| 2141 | SCOPED_TRACE("waiting for next resize"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2142 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2145 | Transaction().setCrop_legacy(layer, Rect(4, 4, 12, 12)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2146 | { |
| 2147 | SCOPED_TRACE("pending crop modified"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2148 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | Transaction().setSize(layer, 16, 16).apply(); |
| 2152 | { |
| 2153 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2154 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | // finally resize |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2158 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2159 | { |
| 2160 | SCOPED_TRACE("new crop applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2161 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2162 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 2163 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 2164 | } |
| 2165 | } |
| 2166 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2167 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithNextResizeScaleToWindow_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2168 | sp<SurfaceControl> layer; |
| 2169 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2170 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2171 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2172 | // setCrop_legacy is not immediate even with SCALE_TO_WINDOW override |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2173 | Transaction() |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2174 | .setCrop_legacy(layer, Rect(4, 4, 12, 12)) |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2175 | .setSize(layer, 16, 16) |
| 2176 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 2177 | .setGeometryAppliesWithResize(layer) |
| 2178 | .apply(); |
| 2179 | { |
| 2180 | SCOPED_TRACE("new crop pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2181 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2182 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 2183 | shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK); |
| 2184 | } |
| 2185 | |
| 2186 | // XXX crop is never latched without other geometry change (b/69315677) |
| 2187 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2188 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2189 | Transaction().setPosition(layer, 0, 0).apply(); |
| 2190 | { |
| 2191 | SCOPED_TRACE("new crop applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2192 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2193 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 2194 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 2195 | } |
| 2196 | } |
| 2197 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2198 | TEST_P(LayerRenderTypeTransactionTest, SetFrameBasic_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2199 | sp<SurfaceControl> layer; |
| 2200 | ASSERT_NO_FATAL_FAILURE( |
| 2201 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2202 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2203 | const Rect frame(8, 8, 24, 24); |
| 2204 | |
| 2205 | Transaction().setFrame(layer, frame).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2206 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2207 | shot->expectColor(frame, Color::RED); |
| 2208 | shot->expectBorder(frame, Color::BLACK); |
| 2209 | } |
| 2210 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2211 | TEST_P(LayerRenderTypeTransactionTest, SetFrameEmpty_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2212 | sp<SurfaceControl> layer; |
| 2213 | ASSERT_NO_FATAL_FAILURE( |
| 2214 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2215 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2216 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2217 | { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2218 | SCOPED_TRACE("empty rect"); |
| 2219 | Transaction().setFrame(layer, Rect(8, 8, 8, 8)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2220 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2223 | { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2224 | SCOPED_TRACE("negative rect"); |
| 2225 | Transaction().setFrame(layer, Rect(8, 8, 0, 0)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2226 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2227 | } |
| 2228 | } |
| 2229 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2230 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultParentless_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2231 | sp<SurfaceControl> layer; |
| 2232 | ASSERT_NO_FATAL_FAILURE( |
| 2233 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2234 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 10, 10)); |
| 2235 | |
| 2236 | // A parentless layer will default to a frame with the same size as the buffer |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2237 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2238 | shot->expectColor(Rect(0, 0, 10, 10), Color::RED); |
| 2239 | shot->expectBorder(Rect(0, 0, 10, 10), Color::BLACK); |
| 2240 | } |
| 2241 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2242 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultBSParent_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2243 | sp<SurfaceControl> parent, child; |
| 2244 | ASSERT_NO_FATAL_FAILURE( |
| 2245 | parent = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2246 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(parent, Color::RED, 32, 32)); |
| 2247 | Transaction().setFrame(parent, Rect(0, 0, 32, 32)).apply(); |
| 2248 | |
| 2249 | ASSERT_NO_FATAL_FAILURE( |
| 2250 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2251 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); |
| 2252 | |
| 2253 | Transaction().reparent(child, parent->getHandle()).apply(); |
| 2254 | |
| 2255 | // A layer will default to the frame of its parent |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2256 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2257 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 2258 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2259 | } |
| 2260 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2261 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultBQParent_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2262 | sp<SurfaceControl> parent, child; |
| 2263 | ASSERT_NO_FATAL_FAILURE(parent = createLayer("test", 32, 32)); |
| 2264 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(parent, Color::RED, 32, 32)); |
| 2265 | |
| 2266 | ASSERT_NO_FATAL_FAILURE( |
| 2267 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2268 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); |
| 2269 | |
| 2270 | Transaction().reparent(child, parent->getHandle()).apply(); |
| 2271 | |
| 2272 | // A layer will default to the frame of its parent |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2273 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2274 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 2275 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2276 | } |
| 2277 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2278 | TEST_P(LayerRenderTypeTransactionTest, SetFrameUpdate_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2279 | sp<SurfaceControl> layer; |
| 2280 | ASSERT_NO_FATAL_FAILURE( |
| 2281 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2282 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2283 | Transaction().setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 2284 | |
| 2285 | std::this_thread::sleep_for(500ms); |
| 2286 | |
| 2287 | Transaction().setFrame(layer, Rect(16, 16, 48, 48)).apply(); |
| 2288 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2289 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2290 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 2291 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); |
| 2292 | } |
| 2293 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2294 | TEST_P(LayerRenderTypeTransactionTest, SetFrameOutsideBounds_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2295 | sp<SurfaceControl> parent, child; |
| 2296 | ASSERT_NO_FATAL_FAILURE( |
| 2297 | parent = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2298 | ASSERT_NO_FATAL_FAILURE( |
| 2299 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2300 | Transaction().reparent(child, parent->getHandle()).apply(); |
| 2301 | |
| 2302 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(parent, Color::RED, 32, 32)); |
| 2303 | Transaction().setFrame(parent, Rect(0, 0, 32, 32)).apply(); |
| 2304 | |
| 2305 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); |
| 2306 | Transaction().setFrame(child, Rect(0, 16, 32, 32)).apply(); |
| 2307 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2308 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2309 | shot->expectColor(Rect(0, 0, 32, 16), Color::RED); |
| 2310 | shot->expectColor(Rect(0, 16, 32, 32), Color::BLUE); |
| 2311 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2312 | } |
| 2313 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2314 | TEST_P(LayerRenderTypeTransactionTest, SetBufferBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2315 | sp<SurfaceControl> layer; |
| 2316 | ASSERT_NO_FATAL_FAILURE( |
| 2317 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2318 | |
| 2319 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2320 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2321 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2322 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2323 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2324 | } |
| 2325 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2326 | TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleBuffers_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2327 | sp<SurfaceControl> layer; |
| 2328 | ASSERT_NO_FATAL_FAILURE( |
| 2329 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2330 | |
| 2331 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2332 | |
| 2333 | { |
| 2334 | SCOPED_TRACE("set buffer 1"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2335 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2336 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2337 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2338 | } |
| 2339 | |
| 2340 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::BLUE, 32, 32)); |
| 2341 | |
| 2342 | { |
| 2343 | SCOPED_TRACE("set buffer 2"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2344 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2345 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 2346 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2347 | } |
| 2348 | |
| 2349 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2350 | |
| 2351 | { |
| 2352 | SCOPED_TRACE("set buffer 3"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2353 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2354 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2355 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2356 | } |
| 2357 | } |
| 2358 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2359 | TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleLayers_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2360 | sp<SurfaceControl> layer1; |
| 2361 | ASSERT_NO_FATAL_FAILURE( |
| 2362 | layer1 = createLayer("test", 64, 64, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2363 | |
| 2364 | sp<SurfaceControl> layer2; |
| 2365 | ASSERT_NO_FATAL_FAILURE( |
| 2366 | layer2 = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2367 | |
| 2368 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::RED, 64, 64)); |
| 2369 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2370 | Transaction().setFrame(layer1, Rect(0, 0, 64, 64)).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2371 | { |
| 2372 | SCOPED_TRACE("set layer 1 buffer red"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2373 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2374 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 2375 | } |
| 2376 | |
| 2377 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::BLUE, 32, 32)); |
| 2378 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2379 | Transaction().setFrame(layer2, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2380 | { |
| 2381 | SCOPED_TRACE("set layer 2 buffer blue"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2382 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2383 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 2384 | shot->expectColor(Rect(0, 32, 64, 64), Color::RED); |
| 2385 | shot->expectColor(Rect(0, 32, 32, 64), Color::RED); |
| 2386 | } |
| 2387 | |
| 2388 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::GREEN, 64, 64)); |
| 2389 | { |
| 2390 | SCOPED_TRACE("set layer 1 buffer green"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2391 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2392 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 2393 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); |
| 2394 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); |
| 2395 | } |
| 2396 | |
| 2397 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::WHITE, 32, 32)); |
| 2398 | |
| 2399 | { |
| 2400 | SCOPED_TRACE("set layer 2 buffer white"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2401 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2402 | shot->expectColor(Rect(0, 0, 32, 32), Color::WHITE); |
| 2403 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); |
| 2404 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); |
| 2405 | } |
| 2406 | } |
| 2407 | |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame^] | 2408 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_BufferState) { |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2409 | sp<SurfaceControl> layer; |
| 2410 | ASSERT_NO_FATAL_FAILURE( |
| 2411 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2412 | |
| 2413 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; |
| 2414 | |
| 2415 | std::array<sp<GraphicBuffer>, 10> buffers; |
| 2416 | |
| 2417 | size_t idx = 0; |
| 2418 | for (auto& buffer : buffers) { |
| 2419 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2420 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2421 | BufferUsage::COMPOSER_OVERLAY, |
| 2422 | "test"); |
| 2423 | Color color = colors[idx % colors.size()]; |
| 2424 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); |
| 2425 | idx++; |
| 2426 | } |
| 2427 | |
| 2428 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the |
| 2429 | // cache is working. |
| 2430 | idx = 0; |
| 2431 | for (auto& buffer : buffers) { |
| 2432 | for (int i = 0; i < 2; i++) { |
| 2433 | Transaction().setBuffer(layer, buffer).apply(); |
| 2434 | |
| 2435 | Color color = colors[idx % colors.size()]; |
| 2436 | auto shot = screenshot(); |
| 2437 | shot->expectColor(Rect(0, 0, 32, 32), color); |
| 2438 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2439 | } |
| 2440 | idx++; |
| 2441 | } |
| 2442 | } |
| 2443 | |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame^] | 2444 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_LeastRecentlyUsed_BufferState) { |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2445 | sp<SurfaceControl> layer; |
| 2446 | ASSERT_NO_FATAL_FAILURE( |
| 2447 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2448 | |
| 2449 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; |
| 2450 | |
| 2451 | std::array<sp<GraphicBuffer>, 70> buffers; |
| 2452 | |
| 2453 | size_t idx = 0; |
| 2454 | for (auto& buffer : buffers) { |
| 2455 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2456 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2457 | BufferUsage::COMPOSER_OVERLAY, |
| 2458 | "test"); |
| 2459 | Color color = colors[idx % colors.size()]; |
| 2460 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); |
| 2461 | idx++; |
| 2462 | } |
| 2463 | |
| 2464 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the |
| 2465 | // cache is working. |
| 2466 | idx = 0; |
| 2467 | for (auto& buffer : buffers) { |
| 2468 | for (int i = 0; i < 2; i++) { |
| 2469 | Transaction().setBuffer(layer, buffer).apply(); |
| 2470 | |
| 2471 | Color color = colors[idx % colors.size()]; |
| 2472 | auto shot = screenshot(); |
| 2473 | shot->expectColor(Rect(0, 0, 32, 32), color); |
| 2474 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2475 | } |
| 2476 | idx++; |
| 2477 | } |
| 2478 | } |
| 2479 | |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame^] | 2480 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_DestroyedBuffer_BufferState) { |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2481 | sp<SurfaceControl> layer; |
| 2482 | ASSERT_NO_FATAL_FAILURE( |
| 2483 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2484 | |
| 2485 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; |
| 2486 | |
| 2487 | std::array<sp<GraphicBuffer>, 65> buffers; |
| 2488 | |
| 2489 | size_t idx = 0; |
| 2490 | for (auto& buffer : buffers) { |
| 2491 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2492 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2493 | BufferUsage::COMPOSER_OVERLAY, |
| 2494 | "test"); |
| 2495 | Color color = colors[idx % colors.size()]; |
| 2496 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); |
| 2497 | idx++; |
| 2498 | } |
| 2499 | |
| 2500 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the |
| 2501 | // cache is working. |
| 2502 | idx = 0; |
| 2503 | for (auto& buffer : buffers) { |
| 2504 | for (int i = 0; i < 2; i++) { |
| 2505 | Transaction().setBuffer(layer, buffer).apply(); |
| 2506 | |
| 2507 | Color color = colors[idx % colors.size()]; |
| 2508 | auto shot = screenshot(); |
| 2509 | shot->expectColor(Rect(0, 0, 32, 32), color); |
| 2510 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2511 | } |
| 2512 | if (idx == 0) { |
| 2513 | buffers[0].clear(); |
| 2514 | } |
| 2515 | idx++; |
| 2516 | } |
| 2517 | } |
| 2518 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2519 | TEST_P(LayerRenderTypeTransactionTest, SetTransformRotate90_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2520 | sp<SurfaceControl> layer; |
| 2521 | ASSERT_NO_FATAL_FAILURE( |
| 2522 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2523 | |
| 2524 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 2525 | Color::BLUE, Color::WHITE)); |
| 2526 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2527 | Transaction() |
| 2528 | .setFrame(layer, Rect(0, 0, 32, 32)) |
| 2529 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_ROT_90) |
| 2530 | .apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2531 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2532 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE, |
| 2533 | Color::GREEN, true /* filtered */); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2536 | TEST_P(LayerRenderTypeTransactionTest, SetTransformFlipH_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2537 | sp<SurfaceControl> layer; |
| 2538 | ASSERT_NO_FATAL_FAILURE( |
| 2539 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2540 | |
| 2541 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 2542 | Color::BLUE, Color::WHITE)); |
| 2543 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2544 | Transaction() |
| 2545 | .setFrame(layer, Rect(0, 0, 32, 32)) |
| 2546 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_H) |
| 2547 | .apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2548 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2549 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE, |
| 2550 | Color::BLUE, true /* filtered */); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2553 | TEST_P(LayerRenderTypeTransactionTest, SetTransformFlipV_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2554 | sp<SurfaceControl> layer; |
| 2555 | ASSERT_NO_FATAL_FAILURE( |
| 2556 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2557 | |
| 2558 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 2559 | Color::BLUE, Color::WHITE)); |
| 2560 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2561 | Transaction() |
| 2562 | .setFrame(layer, Rect(0, 0, 32, 32)) |
| 2563 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_V) |
| 2564 | .apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2565 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2566 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED, |
| 2567 | Color::GREEN, true /* filtered */); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | TEST_F(LayerTransactionTest, SetTransformToDisplayInverse_BufferState) { |
| 2571 | sp<SurfaceControl> layer; |
| 2572 | ASSERT_NO_FATAL_FAILURE( |
| 2573 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2574 | |
| 2575 | Transaction().setTransformToDisplayInverse(layer, false).apply(); |
| 2576 | |
| 2577 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::GREEN, 32, 32)); |
| 2578 | |
| 2579 | Transaction().setTransformToDisplayInverse(layer, true).apply(); |
| 2580 | } |
| 2581 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2582 | TEST_P(LayerRenderTypeTransactionTest, SetFenceBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2583 | sp<SurfaceControl> layer; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2584 | Transaction transaction; |
| 2585 | ASSERT_NO_FATAL_FAILURE( |
| 2586 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2587 | |
| 2588 | sp<GraphicBuffer> buffer = |
| 2589 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2590 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2591 | BufferUsage::COMPOSER_OVERLAY, |
| 2592 | "test"); |
| 2593 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2594 | |
| 2595 | sp<Fence> fence; |
| 2596 | if (getBuffer(nullptr, &fence) != NO_ERROR) { |
| 2597 | GTEST_SUCCEED() << "test not supported"; |
| 2598 | return; |
| 2599 | } |
| 2600 | |
| 2601 | Transaction().setBuffer(layer, buffer).setAcquireFence(layer, fence).apply(); |
| 2602 | |
| 2603 | status_t status = fence->wait(1000); |
| 2604 | ASSERT_NE(static_cast<status_t>(Fence::Status::Unsignaled), status); |
| 2605 | std::this_thread::sleep_for(200ms); |
| 2606 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2607 | auto shot = getScreenCapture(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2608 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2609 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2610 | } |
| 2611 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2612 | TEST_P(LayerRenderTypeTransactionTest, SetFenceNull_BufferState) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2613 | sp<SurfaceControl> layer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2614 | ASSERT_NO_FATAL_FAILURE( |
| 2615 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2616 | |
| 2617 | sp<GraphicBuffer> buffer = |
| 2618 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2619 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2620 | BufferUsage::COMPOSER_OVERLAY, |
| 2621 | "test"); |
| 2622 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2623 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2624 | sp<Fence> fence = Fence::NO_FENCE; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2625 | |
| 2626 | Transaction() |
| 2627 | .setBuffer(layer, buffer) |
| 2628 | .setAcquireFence(layer, fence) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2629 | .apply(); |
| 2630 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2631 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2632 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2633 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2634 | } |
| 2635 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2636 | TEST_P(LayerRenderTypeTransactionTest, SetDataspaceBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2637 | sp<SurfaceControl> layer; |
| 2638 | ASSERT_NO_FATAL_FAILURE( |
| 2639 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2640 | |
| 2641 | sp<GraphicBuffer> buffer = |
| 2642 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2643 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2644 | BufferUsage::COMPOSER_OVERLAY, |
| 2645 | "test"); |
| 2646 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2647 | |
| 2648 | Transaction() |
| 2649 | .setBuffer(layer, buffer) |
| 2650 | .setDataspace(layer, ui::Dataspace::UNKNOWN) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2651 | .apply(); |
| 2652 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2653 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2654 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2655 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2656 | } |
| 2657 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2658 | TEST_P(LayerRenderTypeTransactionTest, SetHdrMetadataBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2659 | sp<SurfaceControl> layer; |
| 2660 | ASSERT_NO_FATAL_FAILURE( |
| 2661 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2662 | |
| 2663 | sp<GraphicBuffer> buffer = |
| 2664 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2665 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2666 | BufferUsage::COMPOSER_OVERLAY, |
| 2667 | "test"); |
| 2668 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2669 | |
| 2670 | HdrMetadata hdrMetadata; |
| 2671 | hdrMetadata.validTypes = 0; |
| 2672 | Transaction() |
| 2673 | .setBuffer(layer, buffer) |
| 2674 | .setHdrMetadata(layer, hdrMetadata) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2675 | .apply(); |
| 2676 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2677 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2678 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2679 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2680 | } |
| 2681 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2682 | TEST_P(LayerRenderTypeTransactionTest, SetSurfaceDamageRegionBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2683 | sp<SurfaceControl> layer; |
| 2684 | ASSERT_NO_FATAL_FAILURE( |
| 2685 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2686 | |
| 2687 | sp<GraphicBuffer> buffer = |
| 2688 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2689 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2690 | BufferUsage::COMPOSER_OVERLAY, |
| 2691 | "test"); |
| 2692 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2693 | |
| 2694 | Region region; |
| 2695 | region.set(32, 32); |
| 2696 | Transaction() |
| 2697 | .setBuffer(layer, buffer) |
| 2698 | .setSurfaceDamageRegion(layer, region) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2699 | .apply(); |
| 2700 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2701 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2702 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2703 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2704 | } |
| 2705 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2706 | TEST_P(LayerRenderTypeTransactionTest, SetApiBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2707 | sp<SurfaceControl> layer; |
| 2708 | ASSERT_NO_FATAL_FAILURE( |
| 2709 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2710 | |
| 2711 | sp<GraphicBuffer> buffer = |
| 2712 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2713 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2714 | BufferUsage::COMPOSER_OVERLAY, |
| 2715 | "test"); |
| 2716 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2717 | |
| 2718 | Transaction() |
| 2719 | .setBuffer(layer, buffer) |
| 2720 | .setApi(layer, NATIVE_WINDOW_API_CPU) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2721 | .apply(); |
| 2722 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2723 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2724 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 2725 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2726 | } |
| 2727 | |
| 2728 | TEST_F(LayerTransactionTest, SetSidebandStreamNull_BufferState) { |
| 2729 | sp<SurfaceControl> layer; |
| 2730 | ASSERT_NO_FATAL_FAILURE( |
| 2731 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2732 | |
| 2733 | // verify this doesn't cause a crash |
| 2734 | Transaction().setSidebandStream(layer, nullptr).apply(); |
| 2735 | } |
| 2736 | |
Robert Carr | 54cf5b1 | 2019-01-25 14:02:28 -0800 | [diff] [blame] | 2737 | TEST_F(LayerTransactionTest, ReparentToSelf) { |
| 2738 | sp<SurfaceControl> layer; |
| 2739 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 2740 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
| 2741 | Transaction().reparent(layer, layer->getHandle()).apply(); |
| 2742 | |
| 2743 | { |
| 2744 | // We expect the transaction to be silently dropped, but for SurfaceFlinger |
| 2745 | // to still be functioning. |
| 2746 | SCOPED_TRACE("after reparent to self"); |
| 2747 | const Rect rect(0, 0, 32, 32); |
| 2748 | auto shot = screenshot(); |
| 2749 | shot->expectColor(rect, Color::RED); |
| 2750 | shot->expectBorder(rect, Color::BLACK); |
| 2751 | } |
| 2752 | } |
| 2753 | |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2754 | class ColorTransformHelper { |
| 2755 | public: |
| 2756 | static void DegammaColorSingle(half& s) { |
| 2757 | if (s <= 0.03928f) |
| 2758 | s = s / 12.92f; |
| 2759 | else |
| 2760 | s = pow((s + 0.055f) / 1.055f, 2.4f); |
| 2761 | } |
| 2762 | |
| 2763 | static void DegammaColor(half3& color) { |
| 2764 | DegammaColorSingle(color.r); |
| 2765 | DegammaColorSingle(color.g); |
| 2766 | DegammaColorSingle(color.b); |
| 2767 | } |
| 2768 | |
| 2769 | static void GammaColorSingle(half& s) { |
| 2770 | if (s <= 0.0031308f) { |
| 2771 | s = s * 12.92f; |
| 2772 | } else { |
| 2773 | s = 1.055f * pow(s, (1.0f / 2.4f)) - 0.055f; |
| 2774 | } |
| 2775 | } |
| 2776 | |
| 2777 | static void GammaColor(half3& color) { |
| 2778 | GammaColorSingle(color.r); |
| 2779 | GammaColorSingle(color.g); |
| 2780 | GammaColorSingle(color.b); |
| 2781 | } |
| 2782 | |
| 2783 | static void applyMatrix(half3& color, const mat3& mat) { |
| 2784 | half3 ret = half3(0); |
| 2785 | |
| 2786 | for (int i = 0; i < 3; i++) { |
| 2787 | for (int j = 0; j < 3; j++) { |
| 2788 | ret[i] = ret[i] + color[j] * mat[j][i]; |
| 2789 | } |
| 2790 | } |
| 2791 | color = ret; |
| 2792 | } |
| 2793 | }; |
| 2794 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2795 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformBasic) { |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2796 | sp<SurfaceControl> colorLayer; |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 2797 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 2798 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 2799 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 2800 | Transaction() |
| 2801 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 2802 | .setLayer(colorLayer, mLayerZBase + 1) |
| 2803 | .apply(); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2804 | { |
| 2805 | SCOPED_TRACE("default color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2806 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | 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] | 2810 | half3 expected = color; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2811 | mat3 matrix; |
| 2812 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; |
| 2813 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; |
| 2814 | 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] | 2815 | |
| 2816 | // degamma before applying the matrix |
| 2817 | if (mColorManagementUsed) { |
| 2818 | ColorTransformHelper::DegammaColor(expected); |
| 2819 | } |
| 2820 | |
| 2821 | ColorTransformHelper::applyMatrix(expected, matrix); |
| 2822 | |
| 2823 | if (mColorManagementUsed) { |
| 2824 | ColorTransformHelper::GammaColor(expected); |
| 2825 | } |
| 2826 | |
| 2827 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), |
| 2828 | uint8_t(expected.b * 255), 255}; |
| 2829 | |
| 2830 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 2831 | // channel) should be less than one |
| 2832 | const uint8_t tolerance = 1; |
| 2833 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2834 | Transaction().setColor(colorLayer, color) |
| 2835 | .setColorTransform(colorLayer, matrix, vec3()).apply(); |
| 2836 | { |
| 2837 | SCOPED_TRACE("new color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2838 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2839 | } |
| 2840 | } |
| 2841 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2842 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformOnParent) { |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2843 | sp<SurfaceControl> parentLayer; |
| 2844 | sp<SurfaceControl> colorLayer; |
| 2845 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parent", 0 /* buffer width */, |
| 2846 | 0 /* buffer height */, |
| 2847 | ISurfaceComposerClient::eFXSurfaceContainer)); |
| 2848 | ASSERT_NO_FATAL_FAILURE( |
| 2849 | colorLayer = createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 2850 | ISurfaceComposerClient::eFXSurfaceColor, parentLayer.get())); |
| 2851 | |
| 2852 | Transaction() |
| 2853 | .setCrop_legacy(parentLayer, Rect(0, 0, 100, 100)) |
| 2854 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 2855 | .setLayer(parentLayer, mLayerZBase + 1) |
| 2856 | .apply(); |
| 2857 | { |
| 2858 | SCOPED_TRACE("default color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2859 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | const half3 color(50.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f); |
| 2863 | half3 expected = color; |
| 2864 | mat3 matrix; |
| 2865 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; |
| 2866 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; |
| 2867 | matrix[0][2] = 0.3; matrix[1][2] = 0.59; matrix[2][2] = 0.11; |
| 2868 | |
| 2869 | // degamma before applying the matrix |
| 2870 | if (mColorManagementUsed) { |
| 2871 | ColorTransformHelper::DegammaColor(expected); |
| 2872 | } |
| 2873 | |
| 2874 | ColorTransformHelper::applyMatrix(expected, matrix); |
| 2875 | |
| 2876 | if (mColorManagementUsed) { |
| 2877 | ColorTransformHelper::GammaColor(expected); |
| 2878 | } |
| 2879 | |
| 2880 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), |
| 2881 | uint8_t(expected.b * 255), 255}; |
| 2882 | |
| 2883 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 2884 | // channel) should be less than one |
| 2885 | const uint8_t tolerance = 1; |
| 2886 | |
| 2887 | Transaction() |
| 2888 | .setColor(colorLayer, color) |
| 2889 | .setColorTransform(parentLayer, matrix, vec3()) |
| 2890 | .apply(); |
| 2891 | { |
| 2892 | SCOPED_TRACE("new color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2893 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2894 | } |
| 2895 | } |
| 2896 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2897 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformOnChildAndParent) { |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2898 | sp<SurfaceControl> parentLayer; |
| 2899 | sp<SurfaceControl> colorLayer; |
| 2900 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parent", 0 /* buffer width */, |
| 2901 | 0 /* buffer height */, |
| 2902 | ISurfaceComposerClient::eFXSurfaceContainer)); |
| 2903 | ASSERT_NO_FATAL_FAILURE( |
| 2904 | colorLayer = createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 2905 | ISurfaceComposerClient::eFXSurfaceColor, parentLayer.get())); |
| 2906 | |
| 2907 | Transaction() |
| 2908 | .setCrop_legacy(parentLayer, Rect(0, 0, 100, 100)) |
| 2909 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 2910 | .setLayer(parentLayer, mLayerZBase + 1) |
| 2911 | .apply(); |
| 2912 | { |
| 2913 | SCOPED_TRACE("default color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2914 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | const half3 color(50.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f); |
| 2918 | half3 expected = color; |
| 2919 | mat3 matrixChild; |
| 2920 | matrixChild[0][0] = 0.3; matrixChild[1][0] = 0.59; matrixChild[2][0] = 0.11; |
| 2921 | matrixChild[0][1] = 0.3; matrixChild[1][1] = 0.59; matrixChild[2][1] = 0.11; |
| 2922 | matrixChild[0][2] = 0.3; matrixChild[1][2] = 0.59; matrixChild[2][2] = 0.11; |
| 2923 | mat3 matrixParent; |
| 2924 | matrixParent[0][0] = 0.2; matrixParent[1][0] = 0.4; matrixParent[2][0] = 0.10; |
| 2925 | matrixParent[0][1] = 0.2; matrixParent[1][1] = 0.4; matrixParent[2][1] = 0.10; |
| 2926 | matrixParent[0][2] = 0.2; matrixParent[1][2] = 0.4; matrixParent[2][2] = 0.10; |
| 2927 | |
| 2928 | // degamma before applying the matrix |
| 2929 | if (mColorManagementUsed) { |
| 2930 | ColorTransformHelper::DegammaColor(expected); |
| 2931 | } |
| 2932 | |
| 2933 | ColorTransformHelper::applyMatrix(expected, matrixChild); |
| 2934 | ColorTransformHelper::applyMatrix(expected, matrixParent); |
| 2935 | |
| 2936 | if (mColorManagementUsed) { |
| 2937 | ColorTransformHelper::GammaColor(expected); |
| 2938 | } |
| 2939 | |
| 2940 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), |
| 2941 | uint8_t(expected.b * 255), 255}; |
| 2942 | |
| 2943 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 2944 | // channel) should be less than one |
| 2945 | const uint8_t tolerance = 1; |
| 2946 | |
| 2947 | Transaction() |
| 2948 | .setColor(colorLayer, color) |
| 2949 | .setColorTransform(parentLayer, matrixParent, vec3()) |
| 2950 | .setColorTransform(colorLayer, matrixChild, vec3()) |
| 2951 | .apply(); |
| 2952 | { |
| 2953 | SCOPED_TRACE("new color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2954 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 2958 | struct CallbackData { |
| 2959 | CallbackData() = default; |
| 2960 | CallbackData(nsecs_t time, const sp<Fence>& fence, |
| 2961 | const std::vector<SurfaceControlStats>& stats) |
| 2962 | : latchTime(time), presentFence(fence), surfaceControlStats(stats) {} |
| 2963 | |
| 2964 | nsecs_t latchTime; |
| 2965 | sp<Fence> presentFence; |
| 2966 | std::vector<SurfaceControlStats> surfaceControlStats; |
| 2967 | }; |
| 2968 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2969 | class ExpectedResult { |
| 2970 | public: |
| 2971 | enum Transaction { |
| 2972 | NOT_PRESENTED = 0, |
| 2973 | PRESENTED, |
| 2974 | }; |
| 2975 | |
| 2976 | enum Buffer { |
| 2977 | NOT_ACQUIRED = 0, |
| 2978 | ACQUIRED, |
| 2979 | }; |
| 2980 | |
| 2981 | enum PreviousBuffer { |
| 2982 | NOT_RELEASED = 0, |
| 2983 | RELEASED, |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 2984 | UNKNOWN, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2985 | }; |
| 2986 | |
| 2987 | void reset() { |
| 2988 | mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; |
| 2989 | mExpectedSurfaceResults.clear(); |
| 2990 | } |
| 2991 | |
| 2992 | void addSurface(ExpectedResult::Transaction transactionResult, const sp<SurfaceControl>& layer, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2993 | ExpectedResult::Buffer bufferResult = ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2994 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { |
| 2995 | mTransactionResult = transactionResult; |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 2996 | mExpectedSurfaceResults.emplace(std::piecewise_construct, std::forward_as_tuple(layer), |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2997 | std::forward_as_tuple(bufferResult, previousBufferResult)); |
| 2998 | } |
| 2999 | |
| 3000 | void addSurfaces(ExpectedResult::Transaction transactionResult, |
| 3001 | const std::vector<sp<SurfaceControl>>& layers, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3002 | ExpectedResult::Buffer bufferResult = ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3003 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { |
| 3004 | for (const auto& layer : layers) { |
| 3005 | addSurface(transactionResult, layer, bufferResult, previousBufferResult); |
| 3006 | } |
| 3007 | } |
| 3008 | |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3009 | void addExpectedPresentTime(nsecs_t expectedPresentTime) { |
| 3010 | mExpectedPresentTime = expectedPresentTime; |
| 3011 | } |
| 3012 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3013 | void verifyCallbackData(const CallbackData& callbackData) const { |
| 3014 | const auto& [latchTime, presentFence, surfaceControlStats] = callbackData; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3015 | if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) { |
| 3016 | ASSERT_GE(latchTime, 0) << "bad latch time"; |
Valerie Hau | 63258a1 | 2018-12-14 14:31:48 -0800 | [diff] [blame] | 3017 | ASSERT_NE(presentFence, nullptr); |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3018 | if (mExpectedPresentTime >= 0) { |
| 3019 | ASSERT_EQ(presentFence->wait(3000), NO_ERROR); |
| 3020 | ASSERT_GE(presentFence->getSignalTime(), mExpectedPresentTime - nsecs_t(5 * 1e6)); |
| 3021 | // if the panel is running at 30 hz, at the worst case, our expected time just |
| 3022 | // misses vsync and we have to wait another 33.3ms |
| 3023 | ASSERT_LE(presentFence->getSignalTime(), |
| 3024 | mExpectedPresentTime + nsecs_t(66.666666 * 1e6)); |
| 3025 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3026 | } else { |
Valerie Hau | 63258a1 | 2018-12-14 14:31:48 -0800 | [diff] [blame] | 3027 | ASSERT_EQ(presentFence, nullptr) << "transaction shouldn't have been presented"; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3028 | ASSERT_EQ(latchTime, -1) << "unpresented transactions shouldn't be latched"; |
| 3029 | } |
| 3030 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3031 | ASSERT_EQ(surfaceControlStats.size(), mExpectedSurfaceResults.size()) |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3032 | << "wrong number of surfaces"; |
| 3033 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3034 | for (const auto& stats : surfaceControlStats) { |
| 3035 | ASSERT_NE(stats.surfaceControl, nullptr) << "returned null surface control"; |
| 3036 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3037 | const auto& expectedSurfaceResult = mExpectedSurfaceResults.find(stats.surfaceControl); |
| 3038 | ASSERT_NE(expectedSurfaceResult, mExpectedSurfaceResults.end()) |
| 3039 | << "unexpected surface control"; |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3040 | expectedSurfaceResult->second.verifySurfaceControlStats(stats, latchTime); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | private: |
| 3045 | class ExpectedSurfaceResult { |
| 3046 | public: |
| 3047 | ExpectedSurfaceResult(ExpectedResult::Buffer bufferResult, |
| 3048 | ExpectedResult::PreviousBuffer previousBufferResult) |
| 3049 | : mBufferResult(bufferResult), mPreviousBufferResult(previousBufferResult) {} |
| 3050 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3051 | void verifySurfaceControlStats(const SurfaceControlStats& surfaceControlStats, |
| 3052 | nsecs_t latchTime) const { |
| 3053 | const auto& [surfaceControl, acquireTime, previousReleaseFence] = surfaceControlStats; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3054 | |
| 3055 | ASSERT_EQ(acquireTime > 0, mBufferResult == ExpectedResult::Buffer::ACQUIRED) |
| 3056 | << "bad acquire time"; |
| 3057 | ASSERT_LE(acquireTime, latchTime) << "acquire time should be <= latch time"; |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3058 | |
| 3059 | if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::RELEASED) { |
| 3060 | ASSERT_NE(previousReleaseFence, nullptr) |
| 3061 | << "failed to set release prev buffer fence"; |
| 3062 | } else if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::NOT_RELEASED) { |
| 3063 | ASSERT_EQ(previousReleaseFence, nullptr) |
| 3064 | << "should not have set released prev buffer fence"; |
| 3065 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | private: |
| 3069 | ExpectedResult::Buffer mBufferResult; |
| 3070 | ExpectedResult::PreviousBuffer mPreviousBufferResult; |
| 3071 | }; |
| 3072 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3073 | struct SCHash { |
| 3074 | std::size_t operator()(const sp<SurfaceControl>& sc) const { |
| 3075 | return std::hash<IBinder*>{}(sc->getHandle().get()); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3076 | } |
| 3077 | }; |
| 3078 | ExpectedResult::Transaction mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3079 | nsecs_t mExpectedPresentTime = -1; |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3080 | std::unordered_map<sp<SurfaceControl>, ExpectedSurfaceResult, SCHash> mExpectedSurfaceResults; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3081 | }; |
| 3082 | |
| 3083 | class CallbackHelper { |
| 3084 | public: |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3085 | static void function(void* callbackContext, nsecs_t latchTime, const sp<Fence>& presentFence, |
| 3086 | const std::vector<SurfaceControlStats>& stats) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3087 | if (!callbackContext) { |
| 3088 | ALOGE("failed to get callback context"); |
| 3089 | } |
| 3090 | CallbackHelper* helper = static_cast<CallbackHelper*>(callbackContext); |
| 3091 | std::lock_guard lock(helper->mMutex); |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3092 | helper->mCallbackDataQueue.emplace(latchTime, presentFence, stats); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3093 | helper->mConditionVariable.notify_all(); |
| 3094 | } |
| 3095 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3096 | void getCallbackData(CallbackData* outData) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3097 | std::unique_lock lock(mMutex); |
| 3098 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3099 | if (mCallbackDataQueue.empty()) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3100 | ASSERT_NE(mConditionVariable.wait_for(lock, std::chrono::seconds(3)), |
| 3101 | std::cv_status::timeout) |
| 3102 | << "did not receive callback"; |
| 3103 | } |
| 3104 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3105 | *outData = std::move(mCallbackDataQueue.front()); |
| 3106 | mCallbackDataQueue.pop(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | void verifyFinalState() { |
| 3110 | // Wait to see if there are extra callbacks |
| 3111 | std::this_thread::sleep_for(500ms); |
| 3112 | |
| 3113 | std::lock_guard lock(mMutex); |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3114 | EXPECT_EQ(mCallbackDataQueue.size(), 0) << "extra callbacks received"; |
| 3115 | mCallbackDataQueue = {}; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | void* getContext() { return static_cast<void*>(this); } |
| 3119 | |
| 3120 | std::mutex mMutex; |
| 3121 | std::condition_variable mConditionVariable; |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3122 | std::queue<CallbackData> mCallbackDataQueue; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3123 | }; |
| 3124 | |
| 3125 | class LayerCallbackTest : public LayerTransactionTest { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3126 | public: |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3127 | virtual sp<SurfaceControl> createBufferStateLayer() { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3128 | return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3129 | } |
| 3130 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3131 | static int fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, |
| 3132 | const sp<SurfaceControl>& layer = nullptr) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3133 | if (layer) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3134 | sp<GraphicBuffer> buffer; |
| 3135 | sp<Fence> fence; |
| 3136 | int err = getBuffer(&buffer, &fence); |
| 3137 | if (err != NO_ERROR) { |
| 3138 | return err; |
| 3139 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3140 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3141 | transaction.setBuffer(layer, buffer).setAcquireFence(layer, fence); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3142 | } |
| 3143 | |
| 3144 | transaction.addTransactionCompletedCallback(callbackHelper->function, |
| 3145 | callbackHelper->getContext()); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3146 | return NO_ERROR; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3147 | } |
| 3148 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3149 | static void waitForCallback(CallbackHelper& helper, const ExpectedResult& expectedResult, |
| 3150 | bool finalState = false) { |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3151 | CallbackData callbackData; |
| 3152 | ASSERT_NO_FATAL_FAILURE(helper.getCallbackData(&callbackData)); |
| 3153 | EXPECT_NO_FATAL_FAILURE(expectedResult.verifyCallbackData(callbackData)); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3154 | |
| 3155 | if (finalState) { |
| 3156 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 3157 | } |
| 3158 | } |
| 3159 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3160 | static void waitForCallbacks(CallbackHelper& helper, |
| 3161 | const std::vector<ExpectedResult>& expectedResults, |
| 3162 | bool finalState = false) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3163 | for (const auto& expectedResult : expectedResults) { |
| 3164 | waitForCallback(helper, expectedResult); |
| 3165 | } |
| 3166 | if (finalState) { |
| 3167 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 3168 | } |
| 3169 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3170 | }; |
| 3171 | |
| 3172 | TEST_F(LayerCallbackTest, Basic) { |
| 3173 | sp<SurfaceControl> layer; |
| 3174 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3175 | |
| 3176 | Transaction transaction; |
| 3177 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3178 | int err = fillTransaction(transaction, &callback, layer); |
| 3179 | if (err) { |
| 3180 | GTEST_SUCCEED() << "test not supported"; |
| 3181 | return; |
| 3182 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3183 | |
| 3184 | transaction.apply(); |
| 3185 | |
| 3186 | ExpectedResult expected; |
| 3187 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3188 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3189 | } |
| 3190 | |
| 3191 | TEST_F(LayerCallbackTest, NoBuffer) { |
| 3192 | sp<SurfaceControl> layer; |
| 3193 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3194 | |
| 3195 | Transaction transaction; |
| 3196 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3197 | int err = fillTransaction(transaction, &callback); |
| 3198 | if (err) { |
| 3199 | GTEST_SUCCEED() << "test not supported"; |
| 3200 | return; |
| 3201 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3202 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3203 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3204 | |
| 3205 | ExpectedResult expected; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3206 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, |
| 3207 | ExpectedResult::Buffer::NOT_ACQUIRED); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3208 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3209 | } |
| 3210 | |
| 3211 | TEST_F(LayerCallbackTest, NoStateChange) { |
| 3212 | Transaction transaction; |
| 3213 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3214 | int err = fillTransaction(transaction, &callback); |
| 3215 | if (err) { |
| 3216 | GTEST_SUCCEED() << "test not supported"; |
| 3217 | return; |
| 3218 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3219 | |
| 3220 | transaction.apply(); |
| 3221 | |
| 3222 | ExpectedResult expected; |
| 3223 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3224 | } |
| 3225 | |
| 3226 | TEST_F(LayerCallbackTest, OffScreen) { |
| 3227 | sp<SurfaceControl> layer; |
| 3228 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3229 | |
| 3230 | Transaction transaction; |
| 3231 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3232 | int err = fillTransaction(transaction, &callback, layer); |
| 3233 | if (err) { |
| 3234 | GTEST_SUCCEED() << "test not supported"; |
| 3235 | return; |
| 3236 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3237 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3238 | transaction.setFrame(layer, Rect(-100, -100, 100, 100)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3239 | |
| 3240 | ExpectedResult expected; |
| 3241 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3242 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3243 | } |
| 3244 | |
| 3245 | TEST_F(LayerCallbackTest, Merge) { |
| 3246 | sp<SurfaceControl> layer1, layer2; |
| 3247 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 3248 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 3249 | |
| 3250 | Transaction transaction1, transaction2; |
| 3251 | CallbackHelper callback1, callback2; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3252 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3253 | if (err) { |
| 3254 | GTEST_SUCCEED() << "test not supported"; |
| 3255 | return; |
| 3256 | } |
| 3257 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3258 | if (err) { |
| 3259 | GTEST_SUCCEED() << "test not supported"; |
| 3260 | return; |
| 3261 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3262 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3263 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3264 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3265 | |
| 3266 | ExpectedResult expected; |
| 3267 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3268 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3269 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3270 | } |
| 3271 | |
| 3272 | TEST_F(LayerCallbackTest, Merge_SameCallback) { |
| 3273 | sp<SurfaceControl> layer1, layer2; |
| 3274 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 3275 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 3276 | |
| 3277 | Transaction transaction1, transaction2; |
| 3278 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3279 | int err = fillTransaction(transaction1, &callback, layer1); |
| 3280 | if (err) { |
| 3281 | GTEST_SUCCEED() << "test not supported"; |
| 3282 | return; |
| 3283 | } |
| 3284 | err = fillTransaction(transaction2, &callback, layer2); |
| 3285 | if (err) { |
| 3286 | GTEST_SUCCEED() << "test not supported"; |
| 3287 | return; |
| 3288 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3289 | |
| 3290 | transaction2.merge(std::move(transaction1)).apply(); |
| 3291 | |
| 3292 | ExpectedResult expected; |
| 3293 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3294 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 3295 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3296 | } |
| 3297 | |
| 3298 | TEST_F(LayerCallbackTest, Merge_SameLayer) { |
| 3299 | sp<SurfaceControl> layer; |
| 3300 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3301 | |
| 3302 | Transaction transaction1, transaction2; |
| 3303 | CallbackHelper callback1, callback2; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3304 | int err = fillTransaction(transaction1, &callback1, layer); |
| 3305 | if (err) { |
| 3306 | GTEST_SUCCEED() << "test not supported"; |
| 3307 | return; |
| 3308 | } |
| 3309 | err = fillTransaction(transaction2, &callback2, layer); |
| 3310 | if (err) { |
| 3311 | GTEST_SUCCEED() << "test not supported"; |
| 3312 | return; |
| 3313 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3314 | |
| 3315 | transaction2.merge(std::move(transaction1)).apply(); |
| 3316 | |
| 3317 | ExpectedResult expected; |
| 3318 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3319 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3320 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3321 | } |
| 3322 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3323 | TEST_F(LayerCallbackTest, Merge_DifferentClients) { |
| 3324 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 3325 | client2(new SurfaceComposerClient); |
| 3326 | |
| 3327 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3328 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3329 | |
| 3330 | sp<SurfaceControl> layer1, layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3331 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3332 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3333 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3334 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 3335 | |
| 3336 | Transaction transaction1, transaction2; |
| 3337 | CallbackHelper callback1, callback2; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3338 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3339 | if (err) { |
| 3340 | GTEST_SUCCEED() << "test not supported"; |
| 3341 | return; |
| 3342 | } |
| 3343 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3344 | if (err) { |
| 3345 | GTEST_SUCCEED() << "test not supported"; |
| 3346 | return; |
| 3347 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3348 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3349 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3350 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3351 | |
| 3352 | ExpectedResult expected; |
| 3353 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3354 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3355 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3356 | } |
| 3357 | |
| 3358 | TEST_F(LayerCallbackTest, MultipleTransactions) { |
| 3359 | sp<SurfaceControl> layer; |
| 3360 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3361 | |
| 3362 | Transaction transaction; |
| 3363 | CallbackHelper callback; |
| 3364 | for (size_t i = 0; i < 10; i++) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3365 | int err = fillTransaction(transaction, &callback, layer); |
| 3366 | if (err) { |
| 3367 | GTEST_SUCCEED() << "test not supported"; |
| 3368 | return; |
| 3369 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3370 | |
| 3371 | transaction.apply(); |
| 3372 | |
| 3373 | ExpectedResult expected; |
| 3374 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3375 | ExpectedResult::Buffer::ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3376 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 3377 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 3378 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 3379 | } |
| 3380 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 3381 | } |
| 3382 | |
| 3383 | TEST_F(LayerCallbackTest, MultipleTransactions_NoStateChange) { |
| 3384 | sp<SurfaceControl> layer; |
| 3385 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3386 | |
| 3387 | Transaction transaction; |
| 3388 | CallbackHelper callback; |
| 3389 | for (size_t i = 0; i < 10; i++) { |
| 3390 | ExpectedResult expected; |
| 3391 | |
| 3392 | if (i == 0) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3393 | int err = fillTransaction(transaction, &callback, layer); |
| 3394 | if (err) { |
| 3395 | GTEST_SUCCEED() << "test not supported"; |
| 3396 | return; |
| 3397 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3398 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3399 | } else { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3400 | int err = fillTransaction(transaction, &callback); |
| 3401 | if (err) { |
| 3402 | GTEST_SUCCEED() << "test not supported"; |
| 3403 | return; |
| 3404 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3405 | } |
| 3406 | |
| 3407 | transaction.apply(); |
| 3408 | |
| 3409 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 3410 | } |
| 3411 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 3412 | } |
| 3413 | |
| 3414 | TEST_F(LayerCallbackTest, MultipleTransactions_SameStateChange) { |
| 3415 | sp<SurfaceControl> layer; |
| 3416 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3417 | |
| 3418 | Transaction transaction; |
| 3419 | CallbackHelper callback; |
| 3420 | for (size_t i = 0; i < 10; i++) { |
| 3421 | if (i == 0) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3422 | int err = fillTransaction(transaction, &callback, layer); |
| 3423 | if (err) { |
| 3424 | GTEST_SUCCEED() << "test not supported"; |
| 3425 | return; |
| 3426 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3427 | } else { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3428 | int err = fillTransaction(transaction, &callback); |
| 3429 | if (err) { |
| 3430 | GTEST_SUCCEED() << "test not supported"; |
| 3431 | return; |
| 3432 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3435 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3436 | |
| 3437 | ExpectedResult expected; |
| 3438 | expected.addSurface((i == 0) ? ExpectedResult::Transaction::PRESENTED |
| 3439 | : ExpectedResult::Transaction::NOT_PRESENTED, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3440 | layer, |
| 3441 | (i == 0) ? ExpectedResult::Buffer::ACQUIRED |
| 3442 | : ExpectedResult::Buffer::NOT_ACQUIRED); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3443 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, i == 0)); |
| 3444 | } |
| 3445 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 3446 | } |
| 3447 | |
| 3448 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge) { |
| 3449 | sp<SurfaceControl> layer1, layer2; |
| 3450 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 3451 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 3452 | |
| 3453 | Transaction transaction1, transaction2; |
| 3454 | CallbackHelper callback1, callback2; |
| 3455 | for (size_t i = 0; i < 10; i++) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3456 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3457 | if (err) { |
| 3458 | GTEST_SUCCEED() << "test not supported"; |
| 3459 | return; |
| 3460 | } |
| 3461 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3462 | if (err) { |
| 3463 | GTEST_SUCCEED() << "test not supported"; |
| 3464 | return; |
| 3465 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3466 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3467 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3468 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3469 | |
| 3470 | ExpectedResult expected; |
| 3471 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3472 | ExpectedResult::Buffer::ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3473 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 3474 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 3475 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 3476 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 3477 | } |
| 3478 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 3479 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 3480 | } |
| 3481 | |
| 3482 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients) { |
| 3483 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 3484 | client2(new SurfaceComposerClient); |
| 3485 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3486 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3487 | |
| 3488 | sp<SurfaceControl> layer1, layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3489 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3490 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3491 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3492 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 3493 | |
| 3494 | Transaction transaction1, transaction2; |
| 3495 | CallbackHelper callback1, callback2; |
| 3496 | for (size_t i = 0; i < 10; i++) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3497 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3498 | if (err) { |
| 3499 | GTEST_SUCCEED() << "test not supported"; |
| 3500 | return; |
| 3501 | } |
| 3502 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3503 | if (err) { |
| 3504 | GTEST_SUCCEED() << "test not supported"; |
| 3505 | return; |
| 3506 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3507 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3508 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3509 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3510 | |
| 3511 | ExpectedResult expected; |
| 3512 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3513 | ExpectedResult::Buffer::ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3514 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 3515 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 3516 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 3517 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 3518 | } |
| 3519 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 3520 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 3521 | } |
| 3522 | |
| 3523 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_NoStateChange) { |
| 3524 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 3525 | client2(new SurfaceComposerClient); |
| 3526 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3527 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3528 | |
| 3529 | sp<SurfaceControl> layer1, layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3530 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3531 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3532 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3533 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 3534 | |
| 3535 | Transaction transaction1, transaction2; |
| 3536 | CallbackHelper callback1, callback2; |
| 3537 | |
| 3538 | // Normal call to set up test |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3539 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3540 | if (err) { |
| 3541 | GTEST_SUCCEED() << "test not supported"; |
| 3542 | return; |
| 3543 | } |
| 3544 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3545 | if (err) { |
| 3546 | GTEST_SUCCEED() << "test not supported"; |
| 3547 | return; |
| 3548 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3549 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3550 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3551 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3552 | |
| 3553 | ExpectedResult expected; |
| 3554 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3555 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3556 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3557 | expected.reset(); |
| 3558 | |
| 3559 | // Test |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3560 | err = fillTransaction(transaction1, &callback1); |
| 3561 | if (err) { |
| 3562 | GTEST_SUCCEED() << "test not supported"; |
| 3563 | return; |
| 3564 | } |
| 3565 | err = fillTransaction(transaction2, &callback2); |
| 3566 | if (err) { |
| 3567 | GTEST_SUCCEED() << "test not supported"; |
| 3568 | return; |
| 3569 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3570 | |
| 3571 | transaction2.merge(std::move(transaction1)).apply(); |
| 3572 | |
| 3573 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3574 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3575 | } |
| 3576 | |
| 3577 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_SameStateChange) { |
| 3578 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 3579 | client2(new SurfaceComposerClient); |
| 3580 | |
| 3581 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3582 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3583 | |
| 3584 | sp<SurfaceControl> layer1, layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3585 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3586 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3587 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3588 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 3589 | |
| 3590 | Transaction transaction1, transaction2; |
| 3591 | CallbackHelper callback1, callback2; |
| 3592 | |
| 3593 | // Normal call to set up test |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3594 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3595 | if (err) { |
| 3596 | GTEST_SUCCEED() << "test not supported"; |
| 3597 | return; |
| 3598 | } |
| 3599 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3600 | if (err) { |
| 3601 | GTEST_SUCCEED() << "test not supported"; |
| 3602 | return; |
| 3603 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3604 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3605 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3606 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3607 | |
| 3608 | ExpectedResult expected; |
| 3609 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3610 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3611 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3612 | expected.reset(); |
| 3613 | |
| 3614 | // Test |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3615 | err = fillTransaction(transaction1, &callback1); |
| 3616 | if (err) { |
| 3617 | GTEST_SUCCEED() << "test not supported"; |
| 3618 | return; |
| 3619 | } |
| 3620 | err = fillTransaction(transaction2, &callback2); |
| 3621 | if (err) { |
| 3622 | GTEST_SUCCEED() << "test not supported"; |
| 3623 | return; |
| 3624 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3625 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3626 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3627 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3628 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer2, |
| 3629 | ExpectedResult::Buffer::NOT_ACQUIRED); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3630 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3631 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3632 | } |
| 3633 | |
| 3634 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame) { |
| 3635 | sp<SurfaceControl> layer; |
| 3636 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3637 | |
| 3638 | Transaction transaction; |
| 3639 | CallbackHelper callback; |
| 3640 | std::vector<ExpectedResult> expectedResults(50); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3641 | for (auto& expected : expectedResults) { |
| 3642 | expected.reset(); |
| 3643 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3644 | ExpectedResult::Buffer::ACQUIRED, |
| 3645 | ExpectedResult::PreviousBuffer::UNKNOWN); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3646 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3647 | int err = fillTransaction(transaction, &callback, layer); |
| 3648 | if (err) { |
| 3649 | GTEST_SUCCEED() << "test not supported"; |
| 3650 | return; |
| 3651 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3652 | |
| 3653 | transaction.apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3654 | } |
| 3655 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 3656 | } |
| 3657 | |
| 3658 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_NoStateChange) { |
| 3659 | sp<SurfaceControl> layer; |
| 3660 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3661 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3662 | // Normal call to set up test |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3663 | Transaction transaction; |
| 3664 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3665 | int err = fillTransaction(transaction, &callback, layer); |
| 3666 | if (err) { |
| 3667 | GTEST_SUCCEED() << "test not supported"; |
| 3668 | return; |
| 3669 | } |
| 3670 | |
| 3671 | transaction.apply(); |
| 3672 | |
| 3673 | ExpectedResult expected; |
| 3674 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3675 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3676 | |
| 3677 | // Test |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3678 | std::vector<ExpectedResult> expectedResults(50); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3679 | for (auto& expected : expectedResults) { |
| 3680 | expected.reset(); |
| 3681 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3682 | err = fillTransaction(transaction, &callback); |
| 3683 | if (err) { |
| 3684 | GTEST_SUCCEED() << "test not supported"; |
| 3685 | return; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | transaction.apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3689 | } |
| 3690 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 3691 | } |
| 3692 | |
| 3693 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_SameStateChange) { |
| 3694 | sp<SurfaceControl> layer; |
| 3695 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3696 | |
| 3697 | // Normal call to set up test |
| 3698 | Transaction transaction; |
| 3699 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3700 | int err = fillTransaction(transaction, &callback, layer); |
| 3701 | if (err) { |
| 3702 | GTEST_SUCCEED() << "test not supported"; |
| 3703 | return; |
| 3704 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3705 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3706 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3707 | |
| 3708 | ExpectedResult expectedResult; |
| 3709 | expectedResult.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3710 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expectedResult, true)); |
| 3711 | |
| 3712 | // Test |
| 3713 | std::vector<ExpectedResult> expectedResults(50); |
| 3714 | for (auto& expected : expectedResults) { |
| 3715 | expected.reset(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3716 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, |
| 3717 | ExpectedResult::Buffer::NOT_ACQUIRED); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3718 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3719 | err = fillTransaction(transaction, &callback); |
| 3720 | if (err) { |
| 3721 | GTEST_SUCCEED() << "test not supported"; |
| 3722 | return; |
| 3723 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3724 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3725 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3726 | } |
| 3727 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 3728 | } |
| 3729 | |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3730 | TEST_F(LayerCallbackTest, DesiredPresentTime) { |
| 3731 | sp<SurfaceControl> layer; |
| 3732 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3733 | |
| 3734 | Transaction transaction; |
| 3735 | CallbackHelper callback; |
| 3736 | int err = fillTransaction(transaction, &callback, layer); |
| 3737 | if (err) { |
| 3738 | GTEST_SUCCEED() << "test not supported"; |
| 3739 | return; |
| 3740 | } |
| 3741 | |
| 3742 | // Try to present 100ms in the future |
| 3743 | nsecs_t time = systemTime() + (100 * 1e6); |
| 3744 | |
| 3745 | transaction.setDesiredPresentTime(time); |
| 3746 | transaction.apply(); |
| 3747 | |
| 3748 | ExpectedResult expected; |
| 3749 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3750 | expected.addExpectedPresentTime(time); |
| 3751 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3752 | } |
| 3753 | |
| 3754 | TEST_F(LayerCallbackTest, DesiredPresentTime_Multiple) { |
| 3755 | sp<SurfaceControl> layer; |
| 3756 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3757 | |
| 3758 | Transaction transaction; |
| 3759 | CallbackHelper callback1; |
| 3760 | int err = fillTransaction(transaction, &callback1, layer); |
| 3761 | if (err) { |
| 3762 | GTEST_SUCCEED() << "test not supported"; |
| 3763 | return; |
| 3764 | } |
| 3765 | |
| 3766 | // Try to present 100ms in the future |
| 3767 | nsecs_t time = systemTime() + (100 * 1e6); |
| 3768 | |
| 3769 | transaction.setDesiredPresentTime(time); |
| 3770 | transaction.apply(); |
| 3771 | |
| 3772 | ExpectedResult expected1; |
| 3773 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3774 | expected1.addExpectedPresentTime(time); |
| 3775 | |
| 3776 | CallbackHelper callback2; |
| 3777 | err = fillTransaction(transaction, &callback2, layer); |
| 3778 | if (err) { |
| 3779 | GTEST_SUCCEED() << "test not supported"; |
| 3780 | return; |
| 3781 | } |
| 3782 | |
| 3783 | // Try to present 33ms after the first frame |
| 3784 | time += (33.3 * 1e6); |
| 3785 | |
| 3786 | transaction.setDesiredPresentTime(time); |
| 3787 | transaction.apply(); |
| 3788 | |
| 3789 | ExpectedResult expected2; |
| 3790 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 3791 | ExpectedResult::Buffer::ACQUIRED, |
| 3792 | ExpectedResult::PreviousBuffer::RELEASED); |
| 3793 | expected2.addExpectedPresentTime(time); |
| 3794 | |
| 3795 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); |
| 3796 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); |
| 3797 | } |
| 3798 | |
| 3799 | TEST_F(LayerCallbackTest, DesiredPresentTime_OutOfOrder) { |
| 3800 | sp<SurfaceControl> layer; |
| 3801 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3802 | |
| 3803 | Transaction transaction; |
| 3804 | CallbackHelper callback1; |
| 3805 | int err = fillTransaction(transaction, &callback1, layer); |
| 3806 | if (err) { |
| 3807 | GTEST_SUCCEED() << "test not supported"; |
| 3808 | return; |
| 3809 | } |
| 3810 | |
| 3811 | // Try to present 100ms in the future |
| 3812 | nsecs_t time = systemTime() + (100 * 1e6); |
| 3813 | |
| 3814 | transaction.setDesiredPresentTime(time); |
| 3815 | transaction.apply(); |
| 3816 | |
| 3817 | ExpectedResult expected1; |
| 3818 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3819 | expected1.addExpectedPresentTime(time); |
| 3820 | |
| 3821 | CallbackHelper callback2; |
| 3822 | err = fillTransaction(transaction, &callback2, layer); |
| 3823 | if (err) { |
| 3824 | GTEST_SUCCEED() << "test not supported"; |
| 3825 | return; |
| 3826 | } |
| 3827 | |
| 3828 | // Try to present 33ms before the previous frame |
| 3829 | time -= (33.3 * 1e6); |
| 3830 | |
| 3831 | transaction.setDesiredPresentTime(time); |
| 3832 | transaction.apply(); |
| 3833 | |
| 3834 | ExpectedResult expected2; |
| 3835 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 3836 | ExpectedResult::Buffer::ACQUIRED, |
| 3837 | ExpectedResult::PreviousBuffer::RELEASED); |
| 3838 | |
| 3839 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); |
| 3840 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); |
| 3841 | } |
| 3842 | |
| 3843 | TEST_F(LayerCallbackTest, DesiredPresentTime_Past) { |
| 3844 | sp<SurfaceControl> layer; |
| 3845 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3846 | |
| 3847 | Transaction transaction; |
| 3848 | CallbackHelper callback; |
| 3849 | int err = fillTransaction(transaction, &callback, layer); |
| 3850 | if (err) { |
| 3851 | GTEST_SUCCEED() << "test not supported"; |
| 3852 | return; |
| 3853 | } |
| 3854 | |
| 3855 | // Try to present 100ms in the past |
| 3856 | nsecs_t time = systemTime() - (100 * 1e6); |
| 3857 | |
| 3858 | transaction.setDesiredPresentTime(time); |
| 3859 | transaction.apply(); |
| 3860 | |
| 3861 | ExpectedResult expected; |
| 3862 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3863 | expected.addExpectedPresentTime(systemTime()); |
| 3864 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3865 | } |
| 3866 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 3867 | class LayerUpdateTest : public LayerTransactionTest { |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3868 | protected: |
| 3869 | virtual void SetUp() { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3870 | LayerTransactionTest::SetUp(); |
| 3871 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3872 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3873 | sp<IBinder> display( |
| 3874 | SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 3875 | DisplayInfo info; |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 3876 | SurfaceComposerClient::getDisplayInfo(display, &info); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 3877 | |
| 3878 | ssize_t displayWidth = info.w; |
| 3879 | ssize_t displayHeight = info.h; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3880 | |
| 3881 | // Background surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3882 | mBGSurfaceControl = createLayer(String8("BG Test Surface"), displayWidth, |
| 3883 | displayHeight, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 3884 | ASSERT_TRUE(mBGSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3885 | ASSERT_TRUE(mBGSurfaceControl->isValid()); |
| 3886 | fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195); |
| 3887 | |
| 3888 | // Foreground surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3889 | mFGSurfaceControl = createLayer(String8("FG Test Surface"), 64, 64, 0); |
| 3890 | |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 3891 | ASSERT_TRUE(mFGSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3892 | ASSERT_TRUE(mFGSurfaceControl->isValid()); |
| 3893 | |
| 3894 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 3895 | |
| 3896 | // Synchronization surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3897 | mSyncSurfaceControl = createLayer(String8("Sync Test Surface"), 1, 1, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 3898 | ASSERT_TRUE(mSyncSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3899 | ASSERT_TRUE(mSyncSurfaceControl->isValid()); |
| 3900 | |
| 3901 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 3902 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3903 | asTransaction([&](Transaction& t) { |
| 3904 | t.setDisplayLayerStack(display, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3905 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3906 | t.setLayer(mBGSurfaceControl, INT32_MAX - 2).show(mBGSurfaceControl); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 3907 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3908 | t.setLayer(mFGSurfaceControl, INT32_MAX - 1) |
| 3909 | .setPosition(mFGSurfaceControl, 64, 64) |
| 3910 | .show(mFGSurfaceControl); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3911 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3912 | t.setLayer(mSyncSurfaceControl, INT32_MAX - 1) |
| 3913 | .setPosition(mSyncSurfaceControl, displayWidth - 2, displayHeight - 2) |
| 3914 | .show(mSyncSurfaceControl); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3915 | }); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | virtual void TearDown() { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3919 | LayerTransactionTest::TearDown(); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3920 | mBGSurfaceControl = 0; |
| 3921 | mFGSurfaceControl = 0; |
| 3922 | mSyncSurfaceControl = 0; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
| 3925 | void waitForPostedBuffers() { |
| 3926 | // Since the sync surface is in synchronous mode (i.e. double buffered) |
| 3927 | // posting three buffers to it should ensure that at least two |
| 3928 | // SurfaceFlinger::handlePageFlip calls have been made, which should |
| 3929 | // guaranteed that a buffer posted to another Surface has been retired. |
| 3930 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 3931 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 3932 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 3933 | } |
| 3934 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3935 | void asTransaction(const std::function<void(Transaction&)>& exec) { |
| 3936 | Transaction t; |
| 3937 | exec(t); |
| 3938 | t.apply(true); |
| 3939 | } |
| 3940 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3941 | sp<SurfaceControl> mBGSurfaceControl; |
| 3942 | sp<SurfaceControl> mFGSurfaceControl; |
| 3943 | |
| 3944 | // This surface is used to ensure that the buffers posted to |
| 3945 | // mFGSurfaceControl have been picked up by SurfaceFlinger. |
| 3946 | sp<SurfaceControl> mSyncSurfaceControl; |
| 3947 | }; |
| 3948 | |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3949 | TEST_F(LayerUpdateTest, RelativesAreNotDetached) { |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3950 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3951 | std::unique_ptr<ScreenCapture> sc; |
| 3952 | |
| 3953 | sp<SurfaceControl> relative = createLayer(String8("relativeTestSurface"), 10, 10, 0); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3954 | fillSurfaceRGBA8(relative, 10, 10, 10); |
| 3955 | waitForPostedBuffers(); |
| 3956 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3957 | Transaction{} |
| 3958 | .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1) |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3959 | .setPosition(relative, 64, 64) |
| 3960 | .apply(); |
| 3961 | |
| 3962 | { |
| 3963 | // The relative should be on top of the FG control. |
| 3964 | ScreenCapture::captureScreen(&sc); |
| 3965 | sc->checkPixel(64, 64, 10, 10, 10); |
| 3966 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3967 | Transaction{}.detachChildren(mFGSurfaceControl).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3968 | |
| 3969 | { |
| 3970 | // Nothing should change at this point. |
| 3971 | ScreenCapture::captureScreen(&sc); |
| 3972 | sc->checkPixel(64, 64, 10, 10, 10); |
| 3973 | } |
| 3974 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3975 | Transaction{}.hide(relative).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3976 | |
| 3977 | { |
| 3978 | // Ensure that the relative was actually hidden, rather than |
| 3979 | // being left in the detached but visible state. |
| 3980 | ScreenCapture::captureScreen(&sc); |
| 3981 | sc->expectFGColor(64, 64); |
| 3982 | } |
| 3983 | } |
| 3984 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 3985 | class GeometryLatchingTest : public LayerUpdateTest { |
| 3986 | protected: |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3987 | void EXPECT_INITIAL_STATE(const char* trace) { |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 3988 | SCOPED_TRACE(trace); |
| 3989 | ScreenCapture::captureScreen(&sc); |
| 3990 | // We find the leading edge of the FG surface. |
| 3991 | sc->expectFGColor(127, 127); |
| 3992 | sc->expectBGColor(128, 128); |
| 3993 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 3994 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3995 | void lockAndFillFGBuffer() { fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false); } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 3996 | |
| 3997 | void unlockFGBuffer() { |
| 3998 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 3999 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 4000 | waitForPostedBuffers(); |
| 4001 | } |
| 4002 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4003 | void completeFGResize() { |
| 4004 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 4005 | waitForPostedBuffers(); |
| 4006 | } |
| 4007 | void restoreInitialState() { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4008 | asTransaction([&](Transaction& t) { |
| 4009 | t.setSize(mFGSurfaceControl, 64, 64); |
| 4010 | t.setPosition(mFGSurfaceControl, 64, 64); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4011 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 64, 64)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4012 | }); |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4013 | |
| 4014 | EXPECT_INITIAL_STATE("After restoring initial state"); |
| 4015 | } |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4016 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4017 | }; |
| 4018 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4019 | class CropLatchingTest : public GeometryLatchingTest { |
| 4020 | protected: |
| 4021 | void EXPECT_CROPPED_STATE(const char* trace) { |
| 4022 | SCOPED_TRACE(trace); |
| 4023 | ScreenCapture::captureScreen(&sc); |
| 4024 | // The edge should be moved back one pixel by our crop. |
| 4025 | sc->expectFGColor(126, 126); |
| 4026 | sc->expectBGColor(127, 127); |
| 4027 | sc->expectBGColor(128, 128); |
| 4028 | } |
chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 4029 | |
| 4030 | void EXPECT_RESIZE_STATE(const char* trace) { |
| 4031 | SCOPED_TRACE(trace); |
| 4032 | ScreenCapture::captureScreen(&sc); |
| 4033 | // The FG is now resized too 128,128 at 64,64 |
| 4034 | sc->expectFGColor(64, 64); |
| 4035 | sc->expectFGColor(191, 191); |
| 4036 | sc->expectBGColor(192, 192); |
| 4037 | } |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4038 | }; |
| 4039 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4040 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4041 | std::unique_ptr<ScreenCapture> sc; |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4042 | { |
| 4043 | SCOPED_TRACE("before anything"); |
| 4044 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4045 | sc->expectBGColor(32, 32); |
| 4046 | sc->expectFGColor(96, 96); |
| 4047 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4048 | } |
| 4049 | |
| 4050 | // set up two deferred transactions on different frames |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4051 | asTransaction([&](Transaction& t) { |
| 4052 | t.setAlpha(mFGSurfaceControl, 0.75); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4053 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
| 4054 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4055 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4056 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4057 | asTransaction([&](Transaction& t) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4058 | t.setPosition(mFGSurfaceControl, 128, 128); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4059 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
| 4060 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4061 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4062 | |
| 4063 | { |
| 4064 | SCOPED_TRACE("before any trigger"); |
| 4065 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4066 | sc->expectBGColor(32, 32); |
| 4067 | sc->expectFGColor(96, 96); |
| 4068 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | // should trigger the first deferred transaction, but not the second one |
| 4072 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 4073 | { |
| 4074 | SCOPED_TRACE("after first trigger"); |
| 4075 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4076 | sc->expectBGColor(32, 32); |
| 4077 | sc->checkPixel(96, 96, 162, 63, 96); |
| 4078 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | // should show up immediately since it's not deferred |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4082 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 1.0); }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4083 | |
| 4084 | // trigger the second deferred transaction |
| 4085 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 4086 | { |
| 4087 | SCOPED_TRACE("after second trigger"); |
| 4088 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4089 | sc->expectBGColor(32, 32); |
| 4090 | sc->expectBGColor(96, 96); |
| 4091 | sc->expectFGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4092 | } |
| 4093 | } |
| 4094 | |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4095 | TEST_F(LayerUpdateTest, LayerWithNoBuffersResizesImmediately) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4096 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4097 | |
| 4098 | sp<SurfaceControl> childNoBuffer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4099 | createSurface(mClient, "Bufferless child", 0 /* buffer width */, 0 /* buffer height */, |
| 4100 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 4101 | sp<SurfaceControl> childBuffer = createSurface(mClient, "Buffered child", 20, 20, |
| 4102 | PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get()); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4103 | fillSurfaceRGBA8(childBuffer, 200, 200, 200); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4104 | SurfaceComposerClient::Transaction{} |
| 4105 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 10, 10)) |
| 4106 | .show(childNoBuffer) |
| 4107 | .show(childBuffer) |
| 4108 | .apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4109 | { |
| 4110 | ScreenCapture::captureScreen(&sc); |
| 4111 | sc->expectChildColor(73, 73); |
| 4112 | sc->expectFGColor(74, 74); |
| 4113 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4114 | SurfaceComposerClient::Transaction{} |
| 4115 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 20, 20)) |
| 4116 | .apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4117 | { |
| 4118 | ScreenCapture::captureScreen(&sc); |
| 4119 | sc->expectChildColor(73, 73); |
| 4120 | sc->expectChildColor(74, 74); |
| 4121 | } |
| 4122 | } |
| 4123 | |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 4124 | TEST_F(LayerUpdateTest, MergingTransactions) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4125 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 4126 | { |
| 4127 | SCOPED_TRACE("before move"); |
| 4128 | ScreenCapture::captureScreen(&sc); |
| 4129 | sc->expectBGColor(0, 12); |
| 4130 | sc->expectFGColor(75, 75); |
| 4131 | sc->expectBGColor(145, 145); |
| 4132 | } |
| 4133 | |
| 4134 | Transaction t1, t2; |
| 4135 | t1.setPosition(mFGSurfaceControl, 128, 128); |
| 4136 | t2.setPosition(mFGSurfaceControl, 0, 0); |
| 4137 | // We expect that the position update from t2 now |
| 4138 | // overwrites the position update from t1. |
| 4139 | t1.merge(std::move(t2)); |
| 4140 | t1.apply(); |
| 4141 | |
| 4142 | { |
| 4143 | ScreenCapture::captureScreen(&sc); |
| 4144 | sc->expectFGColor(1, 1); |
| 4145 | } |
| 4146 | } |
| 4147 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4148 | class ChildLayerTest : public LayerUpdateTest { |
| 4149 | protected: |
| 4150 | void SetUp() override { |
| 4151 | LayerUpdateTest::SetUp(); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4152 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, |
| 4153 | mFGSurfaceControl.get()); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4154 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 4155 | |
| 4156 | { |
| 4157 | SCOPED_TRACE("before anything"); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4158 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4159 | mCapture->expectChildColor(64, 64); |
| 4160 | } |
| 4161 | } |
| 4162 | void TearDown() override { |
| 4163 | LayerUpdateTest::TearDown(); |
| 4164 | mChild = 0; |
| 4165 | } |
| 4166 | |
| 4167 | sp<SurfaceControl> mChild; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4168 | std::unique_ptr<ScreenCapture> mCapture; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4169 | }; |
| 4170 | |
| 4171 | TEST_F(ChildLayerTest, ChildLayerPositioning) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4172 | asTransaction([&](Transaction& t) { |
| 4173 | t.show(mChild); |
| 4174 | t.setPosition(mChild, 10, 10); |
| 4175 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4176 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4177 | |
| 4178 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4179 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4180 | // Top left of foreground must now be visible |
| 4181 | mCapture->expectFGColor(64, 64); |
| 4182 | // But 10 pixels in we should see the child surface |
| 4183 | mCapture->expectChildColor(74, 74); |
| 4184 | // And 10 more pixels we should be back to the foreground surface |
| 4185 | mCapture->expectFGColor(84, 84); |
| 4186 | } |
| 4187 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4188 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4189 | |
| 4190 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4191 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4192 | // Top left of foreground should now be at 0, 0 |
| 4193 | mCapture->expectFGColor(0, 0); |
| 4194 | // But 10 pixels in we should see the child surface |
| 4195 | mCapture->expectChildColor(10, 10); |
| 4196 | // And 10 more pixels we should be back to the foreground surface |
| 4197 | mCapture->expectFGColor(20, 20); |
| 4198 | } |
| 4199 | } |
| 4200 | |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4201 | TEST_F(ChildLayerTest, ChildLayerCropping) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4202 | asTransaction([&](Transaction& t) { |
| 4203 | t.show(mChild); |
| 4204 | t.setPosition(mChild, 0, 0); |
| 4205 | t.setPosition(mFGSurfaceControl, 0, 0); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4206 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 5, 5)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4207 | }); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4208 | |
| 4209 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4210 | mCapture = screenshot(); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4211 | mCapture->expectChildColor(0, 0); |
| 4212 | mCapture->expectChildColor(4, 4); |
| 4213 | mCapture->expectBGColor(5, 5); |
| 4214 | } |
| 4215 | } |
| 4216 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4217 | TEST_F(ChildLayerTest, ChildLayerConstraints) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4218 | asTransaction([&](Transaction& t) { |
| 4219 | t.show(mChild); |
| 4220 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4221 | t.setPosition(mChild, 63, 63); |
| 4222 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4223 | |
| 4224 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4225 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4226 | mCapture->expectFGColor(0, 0); |
| 4227 | // Last pixel in foreground should now be the child. |
| 4228 | mCapture->expectChildColor(63, 63); |
| 4229 | // But the child should be constrained and the next pixel |
| 4230 | // must be the background |
| 4231 | mCapture->expectBGColor(64, 64); |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | TEST_F(ChildLayerTest, ChildLayerScaling) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4236 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4237 | |
| 4238 | // Find the boundary between the parent and child |
| 4239 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4240 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4241 | mCapture->expectChildColor(9, 9); |
| 4242 | mCapture->expectFGColor(10, 10); |
| 4243 | } |
| 4244 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4245 | asTransaction([&](Transaction& t) { t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4246 | |
| 4247 | // The boundary should be twice as far from the origin now. |
| 4248 | // The pixels from the last test should all be child now |
| 4249 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4250 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4251 | mCapture->expectChildColor(9, 9); |
| 4252 | mCapture->expectChildColor(10, 10); |
| 4253 | mCapture->expectChildColor(19, 19); |
| 4254 | mCapture->expectFGColor(20, 20); |
| 4255 | } |
| 4256 | } |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4257 | |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4258 | TEST_F(ChildLayerTest, ChildLayerAlpha) { |
| 4259 | fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254); |
| 4260 | fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0); |
| 4261 | fillSurfaceRGBA8(mChild, 0, 254, 0); |
| 4262 | waitForPostedBuffers(); |
| 4263 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4264 | asTransaction([&](Transaction& t) { |
| 4265 | t.show(mChild); |
| 4266 | t.setPosition(mChild, 0, 0); |
| 4267 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4268 | }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4269 | |
| 4270 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4271 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4272 | // Unblended child color |
| 4273 | mCapture->checkPixel(0, 0, 0, 254, 0); |
| 4274 | } |
| 4275 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4276 | asTransaction([&](Transaction& t) { t.setAlpha(mChild, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4277 | |
| 4278 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4279 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4280 | // Child and BG blended. |
| 4281 | mCapture->checkPixel(0, 0, 127, 127, 0); |
| 4282 | } |
| 4283 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4284 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4285 | |
| 4286 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4287 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4288 | // Child and BG blended. |
| 4289 | mCapture->checkPixel(0, 0, 95, 64, 95); |
| 4290 | } |
| 4291 | } |
| 4292 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4293 | TEST_F(ChildLayerTest, ReparentChildren) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4294 | asTransaction([&](Transaction& t) { |
| 4295 | t.show(mChild); |
| 4296 | t.setPosition(mChild, 10, 10); |
| 4297 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4298 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4299 | |
| 4300 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4301 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4302 | // Top left of foreground must now be visible |
| 4303 | mCapture->expectFGColor(64, 64); |
| 4304 | // But 10 pixels in we should see the child surface |
| 4305 | mCapture->expectChildColor(74, 74); |
| 4306 | // And 10 more pixels we should be back to the foreground surface |
| 4307 | mCapture->expectFGColor(84, 84); |
| 4308 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4309 | |
| 4310 | asTransaction([&](Transaction& t) { |
| 4311 | t.reparentChildren(mFGSurfaceControl, mBGSurfaceControl->getHandle()); |
| 4312 | }); |
| 4313 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4314 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4315 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4316 | mCapture->expectFGColor(64, 64); |
| 4317 | // In reparenting we should have exposed the entire foreground surface. |
| 4318 | mCapture->expectFGColor(74, 74); |
| 4319 | // And the child layer should now begin at 10, 10 (since the BG |
| 4320 | // layer is at (0, 0)). |
| 4321 | mCapture->expectBGColor(9, 9); |
| 4322 | mCapture->expectChildColor(10, 10); |
| 4323 | } |
| 4324 | } |
| 4325 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4326 | TEST_F(ChildLayerTest, ChildrenSurviveParentDestruction) { |
| 4327 | sp<SurfaceControl> mGrandChild = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4328 | 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] | 4329 | fillSurfaceRGBA8(mGrandChild, 111, 111, 111); |
| 4330 | |
| 4331 | { |
| 4332 | SCOPED_TRACE("Grandchild visible"); |
| 4333 | ScreenCapture::captureScreen(&mCapture); |
| 4334 | mCapture->checkPixel(64, 64, 111, 111, 111); |
| 4335 | } |
| 4336 | |
| 4337 | mChild->clear(); |
| 4338 | |
| 4339 | { |
| 4340 | SCOPED_TRACE("After destroying child"); |
| 4341 | ScreenCapture::captureScreen(&mCapture); |
| 4342 | mCapture->expectFGColor(64, 64); |
| 4343 | } |
| 4344 | |
| 4345 | asTransaction([&](Transaction& t) { |
| 4346 | t.reparent(mGrandChild, mFGSurfaceControl->getHandle()); |
| 4347 | }); |
| 4348 | |
| 4349 | { |
| 4350 | SCOPED_TRACE("After reparenting grandchild"); |
| 4351 | ScreenCapture::captureScreen(&mCapture); |
| 4352 | mCapture->checkPixel(64, 64, 111, 111, 111); |
| 4353 | } |
| 4354 | } |
| 4355 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4356 | TEST_F(ChildLayerTest, DetachChildrenSameClient) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4357 | asTransaction([&](Transaction& t) { |
| 4358 | t.show(mChild); |
| 4359 | t.setPosition(mChild, 10, 10); |
| 4360 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4361 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4362 | |
| 4363 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4364 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4365 | // Top left of foreground must now be visible |
| 4366 | mCapture->expectFGColor(64, 64); |
| 4367 | // But 10 pixels in we should see the child surface |
| 4368 | mCapture->expectChildColor(74, 74); |
| 4369 | // And 10 more pixels we should be back to the foreground surface |
| 4370 | mCapture->expectFGColor(84, 84); |
| 4371 | } |
| 4372 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4373 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4374 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4375 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4376 | asTransaction([&](Transaction& t) { t.hide(mChild); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4377 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4378 | // Since the child has the same client as the parent, it will not get |
| 4379 | // detached and will be hidden. |
| 4380 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4381 | mCapture = screenshot(); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4382 | mCapture->expectFGColor(64, 64); |
| 4383 | mCapture->expectFGColor(74, 74); |
| 4384 | mCapture->expectFGColor(84, 84); |
| 4385 | } |
| 4386 | } |
| 4387 | |
| 4388 | TEST_F(ChildLayerTest, DetachChildrenDifferentClient) { |
| 4389 | sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient; |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4390 | sp<SurfaceControl> mChildNewClient = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4391 | createSurface(mNewComposerClient, "New Child Test Surface", 10, 10, |
| 4392 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4393 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4394 | ASSERT_TRUE(mChildNewClient->isValid()); |
| 4395 | |
| 4396 | fillSurfaceRGBA8(mChildNewClient, 200, 200, 200); |
| 4397 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4398 | asTransaction([&](Transaction& t) { |
| 4399 | t.hide(mChild); |
| 4400 | t.show(mChildNewClient); |
| 4401 | t.setPosition(mChildNewClient, 10, 10); |
| 4402 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4403 | }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4404 | |
| 4405 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4406 | mCapture = screenshot(); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4407 | // Top left of foreground must now be visible |
| 4408 | mCapture->expectFGColor(64, 64); |
| 4409 | // But 10 pixels in we should see the child surface |
| 4410 | mCapture->expectChildColor(74, 74); |
| 4411 | // And 10 more pixels we should be back to the foreground surface |
| 4412 | mCapture->expectFGColor(84, 84); |
| 4413 | } |
| 4414 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4415 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4416 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4417 | asTransaction([&](Transaction& t) { t.hide(mChildNewClient); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4418 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4419 | // Nothing should have changed. |
| 4420 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4421 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4422 | mCapture->expectFGColor(64, 64); |
| 4423 | mCapture->expectChildColor(74, 74); |
| 4424 | mCapture->expectFGColor(84, 84); |
| 4425 | } |
| 4426 | } |
| 4427 | |
chaviw | 5aedec9 | 2018-10-22 10:40:38 -0700 | [diff] [blame] | 4428 | TEST_F(ChildLayerTest, DetachChildrenThenAttach) { |
| 4429 | sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; |
| 4430 | sp<SurfaceControl> childNewClient = |
| 4431 | newComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, |
| 4432 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 4433 | |
| 4434 | ASSERT_TRUE(childNewClient != nullptr); |
| 4435 | ASSERT_TRUE(childNewClient->isValid()); |
| 4436 | |
| 4437 | fillSurfaceRGBA8(childNewClient, 200, 200, 200); |
| 4438 | |
| 4439 | Transaction() |
| 4440 | .hide(mChild) |
| 4441 | .show(childNewClient) |
| 4442 | .setPosition(childNewClient, 10, 10) |
| 4443 | .setPosition(mFGSurfaceControl, 64, 64) |
| 4444 | .apply(); |
| 4445 | |
| 4446 | { |
| 4447 | mCapture = screenshot(); |
| 4448 | // Top left of foreground must now be visible |
| 4449 | mCapture->expectFGColor(64, 64); |
| 4450 | // But 10 pixels in we should see the child surface |
| 4451 | mCapture->expectChildColor(74, 74); |
| 4452 | // And 10 more pixels we should be back to the foreground surface |
| 4453 | mCapture->expectFGColor(84, 84); |
| 4454 | } |
| 4455 | |
| 4456 | Transaction().detachChildren(mFGSurfaceControl).apply(); |
| 4457 | Transaction().hide(childNewClient).apply(); |
| 4458 | |
| 4459 | // Nothing should have changed. |
| 4460 | { |
| 4461 | mCapture = screenshot(); |
| 4462 | mCapture->expectFGColor(64, 64); |
| 4463 | mCapture->expectChildColor(74, 74); |
| 4464 | mCapture->expectFGColor(84, 84); |
| 4465 | } |
| 4466 | |
| 4467 | sp<SurfaceControl> newParentSurface = createLayer(String8("New Parent Surface"), 32, 32, 0); |
| 4468 | fillLayerColor(ISurfaceComposerClient::eFXSurfaceBufferQueue, newParentSurface, Color::RED, 32, |
| 4469 | 32); |
| 4470 | Transaction() |
| 4471 | .setLayer(newParentSurface, INT32_MAX - 1) |
| 4472 | .show(newParentSurface) |
| 4473 | .setPosition(newParentSurface, 20, 20) |
| 4474 | .reparent(childNewClient, newParentSurface->getHandle()) |
| 4475 | .apply(); |
| 4476 | { |
| 4477 | mCapture = screenshot(); |
| 4478 | // Child is now hidden. |
| 4479 | mCapture->expectColor(Rect(20, 20, 52, 52), Color::RED); |
| 4480 | } |
| 4481 | } |
| 4482 | |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4483 | TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4484 | asTransaction([&](Transaction& t) { |
| 4485 | t.show(mChild); |
| 4486 | t.setPosition(mChild, 0, 0); |
| 4487 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4488 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4489 | |
| 4490 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4491 | mCapture = screenshot(); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4492 | // We've positioned the child in the top left. |
| 4493 | mCapture->expectChildColor(0, 0); |
| 4494 | // But it's only 10x10. |
| 4495 | mCapture->expectFGColor(10, 10); |
| 4496 | } |
| 4497 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4498 | asTransaction([&](Transaction& t) { |
| 4499 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 4500 | // We cause scaling by 2. |
| 4501 | t.setSize(mFGSurfaceControl, 128, 128); |
| 4502 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4503 | |
| 4504 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4505 | mCapture = screenshot(); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4506 | // We've positioned the child in the top left. |
| 4507 | mCapture->expectChildColor(0, 0); |
| 4508 | mCapture->expectChildColor(10, 10); |
| 4509 | mCapture->expectChildColor(19, 19); |
| 4510 | // And now it should be scaled all the way to 20x20 |
| 4511 | mCapture->expectFGColor(20, 20); |
| 4512 | } |
| 4513 | } |
| 4514 | |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4515 | // Regression test for b/37673612 |
| 4516 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4517 | asTransaction([&](Transaction& t) { |
| 4518 | t.show(mChild); |
| 4519 | t.setPosition(mChild, 0, 0); |
| 4520 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4521 | }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4522 | |
| 4523 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4524 | mCapture = screenshot(); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4525 | // We've positioned the child in the top left. |
| 4526 | mCapture->expectChildColor(0, 0); |
| 4527 | // But it's only 10x10. |
| 4528 | mCapture->expectFGColor(10, 10); |
| 4529 | } |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4530 | // We set things up as in b/37673612 so that there is a mismatch between the buffer size and |
| 4531 | // the WM specified state size. |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4532 | asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4533 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 4534 | auto anw = static_cast<ANativeWindow*>(s.get()); |
| 4535 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 4536 | native_window_set_buffers_dimensions(anw, 64, 128); |
| 4537 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 4538 | waitForPostedBuffers(); |
| 4539 | |
| 4540 | { |
| 4541 | // The child should still be in the same place and not have any strange scaling as in |
| 4542 | // b/37673612. |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4543 | mCapture = screenshot(); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4544 | mCapture->expectChildColor(0, 0); |
| 4545 | mCapture->expectFGColor(10, 10); |
| 4546 | } |
| 4547 | } |
| 4548 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 4549 | TEST_F(ChildLayerTest, Bug36858924) { |
| 4550 | // Destroy the child layer |
| 4551 | mChild.clear(); |
| 4552 | |
| 4553 | // Now recreate it as hidden |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4554 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 4555 | ISurfaceComposerClient::eHidden, mFGSurfaceControl.get()); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 4556 | |
| 4557 | // Show the child layer in a deferred transaction |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4558 | asTransaction([&](Transaction& t) { |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4559 | t.deferTransactionUntil_legacy(mChild, mFGSurfaceControl->getHandle(), |
| 4560 | mFGSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4561 | t.show(mChild); |
| 4562 | }); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 4563 | |
| 4564 | // Render the foreground surface a few times |
| 4565 | // |
| 4566 | // Prior to the bugfix for b/36858924, this would usually hang while trying to fill the third |
| 4567 | // frame because SurfaceFlinger would never process the deferred transaction and would therefore |
| 4568 | // never acquire/release the first buffer |
| 4569 | ALOGI("Filling 1"); |
| 4570 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 4571 | ALOGI("Filling 2"); |
| 4572 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 0, 255); |
| 4573 | ALOGI("Filling 3"); |
| 4574 | fillSurfaceRGBA8(mFGSurfaceControl, 255, 0, 0); |
| 4575 | ALOGI("Filling 4"); |
| 4576 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 4577 | } |
| 4578 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4579 | TEST_F(ChildLayerTest, Reparent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4580 | asTransaction([&](Transaction& t) { |
| 4581 | t.show(mChild); |
| 4582 | t.setPosition(mChild, 10, 10); |
| 4583 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4584 | }); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4585 | |
| 4586 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4587 | mCapture = screenshot(); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4588 | // Top left of foreground must now be visible |
| 4589 | mCapture->expectFGColor(64, 64); |
| 4590 | // But 10 pixels in we should see the child surface |
| 4591 | mCapture->expectChildColor(74, 74); |
| 4592 | // And 10 more pixels we should be back to the foreground surface |
| 4593 | mCapture->expectFGColor(84, 84); |
| 4594 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4595 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4596 | asTransaction([&](Transaction& t) { t.reparent(mChild, mBGSurfaceControl->getHandle()); }); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4597 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4598 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4599 | mCapture = screenshot(); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4600 | mCapture->expectFGColor(64, 64); |
| 4601 | // In reparenting we should have exposed the entire foreground surface. |
| 4602 | mCapture->expectFGColor(74, 74); |
| 4603 | // And the child layer should now begin at 10, 10 (since the BG |
| 4604 | // layer is at (0, 0)). |
| 4605 | mCapture->expectBGColor(9, 9); |
| 4606 | mCapture->expectChildColor(10, 10); |
| 4607 | } |
| 4608 | } |
| 4609 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4610 | TEST_F(ChildLayerTest, ReparentToNoParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4611 | asTransaction([&](Transaction& t) { |
| 4612 | t.show(mChild); |
| 4613 | t.setPosition(mChild, 10, 10); |
| 4614 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4615 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4616 | |
| 4617 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4618 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4619 | // Top left of foreground must now be visible |
| 4620 | mCapture->expectFGColor(64, 64); |
| 4621 | // But 10 pixels in we should see the child surface |
| 4622 | mCapture->expectChildColor(74, 74); |
| 4623 | // And 10 more pixels we should be back to the foreground surface |
| 4624 | mCapture->expectFGColor(84, 84); |
| 4625 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4626 | asTransaction([&](Transaction& t) { t.reparent(mChild, nullptr); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4627 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4628 | mCapture = screenshot(); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4629 | // The surface should now be offscreen. |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4630 | mCapture->expectFGColor(64, 64); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4631 | mCapture->expectFGColor(74, 74); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4632 | mCapture->expectFGColor(84, 84); |
| 4633 | } |
| 4634 | } |
| 4635 | |
| 4636 | TEST_F(ChildLayerTest, ReparentFromNoParent) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4637 | sp<SurfaceControl> newSurface = createLayer(String8("New Surface"), 10, 10, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 4638 | ASSERT_TRUE(newSurface != nullptr); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4639 | ASSERT_TRUE(newSurface->isValid()); |
| 4640 | |
| 4641 | fillSurfaceRGBA8(newSurface, 63, 195, 63); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4642 | asTransaction([&](Transaction& t) { |
| 4643 | t.hide(mChild); |
| 4644 | t.show(newSurface); |
| 4645 | t.setPosition(newSurface, 10, 10); |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4646 | t.setLayer(newSurface, INT32_MAX - 2); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4647 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4648 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4649 | |
| 4650 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4651 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4652 | // Top left of foreground must now be visible |
| 4653 | mCapture->expectFGColor(64, 64); |
| 4654 | // At 10, 10 we should see the new surface |
| 4655 | mCapture->checkPixel(10, 10, 63, 195, 63); |
| 4656 | } |
| 4657 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4658 | asTransaction([&](Transaction& t) { t.reparent(newSurface, mFGSurfaceControl->getHandle()); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4659 | |
| 4660 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4661 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4662 | // newSurface will now be a child of mFGSurface so it will be 10, 10 offset from |
| 4663 | // mFGSurface, putting it at 74, 74. |
| 4664 | mCapture->expectFGColor(64, 64); |
| 4665 | mCapture->checkPixel(74, 74, 63, 195, 63); |
| 4666 | mCapture->expectFGColor(84, 84); |
| 4667 | } |
| 4668 | } |
| 4669 | |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 4670 | TEST_F(ChildLayerTest, NestedChildren) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4671 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 10, 10, |
| 4672 | PIXEL_FORMAT_RGBA_8888, 0, mChild.get()); |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 4673 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 4674 | |
| 4675 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4676 | mCapture = screenshot(); |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 4677 | // Expect the grandchild to begin at 64, 64 because it's a child of mChild layer |
| 4678 | // which begins at 64, 64 |
| 4679 | mCapture->checkPixel(64, 64, 50, 50, 50); |
| 4680 | } |
| 4681 | } |
| 4682 | |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4683 | TEST_F(ChildLayerTest, ChildLayerRelativeLayer) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4684 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 128, 128, 0); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4685 | fillSurfaceRGBA8(relative, 255, 255, 255); |
| 4686 | |
| 4687 | Transaction t; |
| 4688 | t.setLayer(relative, INT32_MAX) |
| 4689 | .setRelativeLayer(mChild, relative->getHandle(), 1) |
| 4690 | .setPosition(mFGSurfaceControl, 0, 0) |
| 4691 | .apply(true); |
| 4692 | |
| 4693 | // We expect that the child should have been elevated above our |
| 4694 | // INT_MAX layer even though it's not a child of it. |
| 4695 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4696 | mCapture = screenshot(); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4697 | mCapture->expectChildColor(0, 0); |
| 4698 | mCapture->expectChildColor(9, 9); |
| 4699 | mCapture->checkPixel(10, 10, 255, 255, 255); |
| 4700 | } |
| 4701 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4702 | class BoundlessLayerTest : public LayerUpdateTest { |
| 4703 | protected: |
| 4704 | std::unique_ptr<ScreenCapture> mCapture; |
| 4705 | }; |
| 4706 | |
| 4707 | // Verify setting a size on a buffer layer has no effect. |
| 4708 | TEST_F(BoundlessLayerTest, BufferLayerIgnoresSize) { |
| 4709 | sp<SurfaceControl> bufferLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4710 | createSurface(mClient, "BufferLayer", 45, 45, PIXEL_FORMAT_RGBA_8888, 0, |
| 4711 | mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4712 | ASSERT_TRUE(bufferLayer->isValid()); |
| 4713 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::BLACK, 30, 30)); |
| 4714 | asTransaction([&](Transaction& t) { t.show(bufferLayer); }); |
| 4715 | { |
| 4716 | mCapture = screenshot(); |
| 4717 | // Top left of background must now be visible |
| 4718 | mCapture->expectBGColor(0, 0); |
| 4719 | // Foreground Surface bounds must be color layer |
| 4720 | mCapture->expectColor(Rect(64, 64, 94, 94), Color::BLACK); |
| 4721 | // Buffer layer should not extend past buffer bounds |
| 4722 | mCapture->expectFGColor(95, 95); |
| 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | // Verify a boundless color layer will fill its parent bounds. The parent has a buffer size |
| 4727 | // which will crop the color layer. |
| 4728 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentBufferBounds) { |
| 4729 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4730 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4731 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4732 | ASSERT_TRUE(colorLayer->isValid()); |
| 4733 | asTransaction([&](Transaction& t) { |
| 4734 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 4735 | t.show(colorLayer); |
| 4736 | }); |
| 4737 | { |
| 4738 | mCapture = screenshot(); |
| 4739 | // Top left of background must now be visible |
| 4740 | mCapture->expectBGColor(0, 0); |
| 4741 | // Foreground Surface bounds must be color layer |
| 4742 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 4743 | // Color layer should not extend past foreground bounds |
| 4744 | mCapture->expectBGColor(129, 129); |
| 4745 | } |
| 4746 | } |
| 4747 | |
| 4748 | // Verify a boundless color layer will fill its parent bounds. The parent has no buffer but has |
| 4749 | // a crop which will be used to crop the color layer. |
| 4750 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentCropBounds) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4751 | sp<SurfaceControl> cropLayer = createSurface(mClient, "CropLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4752 | 0 /* flags */, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4753 | ASSERT_TRUE(cropLayer->isValid()); |
| 4754 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4755 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4756 | ISurfaceComposerClient::eFXSurfaceColor, cropLayer.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4757 | ASSERT_TRUE(colorLayer->isValid()); |
| 4758 | asTransaction([&](Transaction& t) { |
| 4759 | t.setCrop_legacy(cropLayer, Rect(5, 5, 10, 10)); |
| 4760 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 4761 | t.show(cropLayer); |
| 4762 | t.show(colorLayer); |
| 4763 | }); |
| 4764 | { |
| 4765 | mCapture = screenshot(); |
| 4766 | // Top left of background must now be visible |
| 4767 | mCapture->expectBGColor(0, 0); |
| 4768 | // Top left of foreground must now be visible |
| 4769 | mCapture->expectFGColor(64, 64); |
| 4770 | // 5 pixels from the foreground we should see the child surface |
| 4771 | mCapture->expectColor(Rect(69, 69, 74, 74), Color::BLACK); |
| 4772 | // 10 pixels from the foreground we should be back to the foreground surface |
| 4773 | mCapture->expectFGColor(74, 74); |
| 4774 | } |
| 4775 | } |
| 4776 | |
| 4777 | // Verify for boundless layer with no children, their transforms have no effect. |
| 4778 | TEST_F(BoundlessLayerTest, BoundlessColorLayerTransformHasNoEffect) { |
| 4779 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4780 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4781 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4782 | ASSERT_TRUE(colorLayer->isValid()); |
| 4783 | asTransaction([&](Transaction& t) { |
| 4784 | t.setPosition(colorLayer, 320, 320); |
| 4785 | t.setMatrix(colorLayer, 2, 0, 0, 2); |
| 4786 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 4787 | t.show(colorLayer); |
| 4788 | }); |
| 4789 | { |
| 4790 | mCapture = screenshot(); |
| 4791 | // Top left of background must now be visible |
| 4792 | mCapture->expectBGColor(0, 0); |
| 4793 | // Foreground Surface bounds must be color layer |
| 4794 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 4795 | // Color layer should not extend past foreground bounds |
| 4796 | mCapture->expectBGColor(129, 129); |
| 4797 | } |
| 4798 | } |
| 4799 | |
| 4800 | // Verify for boundless layer with children, their transforms have an effect. |
| 4801 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerCanSetTransform) { |
| 4802 | sp<SurfaceControl> boundlessLayerRightShift = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4803 | createSurface(mClient, "BoundlessLayerRightShift", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4804 | 0 /* flags */, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4805 | ASSERT_TRUE(boundlessLayerRightShift->isValid()); |
| 4806 | sp<SurfaceControl> boundlessLayerDownShift = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4807 | createSurface(mClient, "BoundlessLayerLeftShift", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4808 | 0 /* flags */, boundlessLayerRightShift.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4809 | ASSERT_TRUE(boundlessLayerDownShift->isValid()); |
| 4810 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4811 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4812 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayerDownShift.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4813 | ASSERT_TRUE(colorLayer->isValid()); |
| 4814 | asTransaction([&](Transaction& t) { |
| 4815 | t.setPosition(boundlessLayerRightShift, 32, 0); |
| 4816 | t.show(boundlessLayerRightShift); |
| 4817 | t.setPosition(boundlessLayerDownShift, 0, 32); |
| 4818 | t.show(boundlessLayerDownShift); |
| 4819 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 4820 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 4821 | t.show(colorLayer); |
| 4822 | }); |
| 4823 | { |
| 4824 | mCapture = screenshot(); |
| 4825 | // Top left of background must now be visible |
| 4826 | mCapture->expectBGColor(0, 0); |
| 4827 | // Top left of foreground must now be visible |
| 4828 | mCapture->expectFGColor(64, 64); |
| 4829 | // Foreground Surface bounds must be color layer |
| 4830 | mCapture->expectColor(Rect(96, 96, 128, 128), Color::BLACK); |
| 4831 | // Color layer should not extend past foreground bounds |
| 4832 | mCapture->expectBGColor(129, 129); |
| 4833 | } |
| 4834 | } |
| 4835 | |
| 4836 | // Verify child layers do not get clipped if they temporarily move into the negative |
| 4837 | // coordinate space as the result of an intermediate transformation. |
| 4838 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerDoNotCrop) { |
| 4839 | sp<SurfaceControl> boundlessLayer = |
| 4840 | mClient->createSurface(String8("BoundlessLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4841 | 0 /* flags */, mFGSurfaceControl.get()); |
| 4842 | ASSERT_TRUE(boundlessLayer != nullptr); |
| 4843 | ASSERT_TRUE(boundlessLayer->isValid()); |
| 4844 | sp<SurfaceControl> colorLayer = |
| 4845 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4846 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayer.get()); |
| 4847 | ASSERT_TRUE(colorLayer != nullptr); |
| 4848 | ASSERT_TRUE(colorLayer->isValid()); |
| 4849 | asTransaction([&](Transaction& t) { |
| 4850 | // shift child layer off bounds. If this layer was not boundless, we will |
| 4851 | // expect the child layer to be cropped. |
| 4852 | t.setPosition(boundlessLayer, 32, 32); |
| 4853 | t.show(boundlessLayer); |
| 4854 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 4855 | // undo shift by parent |
| 4856 | t.setPosition(colorLayer, -32, -32); |
| 4857 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 4858 | t.show(colorLayer); |
| 4859 | }); |
| 4860 | { |
| 4861 | mCapture = screenshot(); |
| 4862 | // Top left of background must now be visible |
| 4863 | mCapture->expectBGColor(0, 0); |
| 4864 | // Foreground Surface bounds must be color layer |
| 4865 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 4866 | // Color layer should not extend past foreground bounds |
| 4867 | mCapture->expectBGColor(129, 129); |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | // Verify for boundless root layers with children, their transforms have an effect. |
| 4872 | TEST_F(BoundlessLayerTest, RootBoundlessLayerCanSetTransform) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4873 | sp<SurfaceControl> rootBoundlessLayer = createSurface(mClient, "RootBoundlessLayer", 0, 0, |
| 4874 | PIXEL_FORMAT_RGBA_8888, 0 /* flags */); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4875 | ASSERT_TRUE(rootBoundlessLayer->isValid()); |
| 4876 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4877 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 4878 | ISurfaceComposerClient::eFXSurfaceColor, rootBoundlessLayer.get()); |
| 4879 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4880 | ASSERT_TRUE(colorLayer->isValid()); |
| 4881 | asTransaction([&](Transaction& t) { |
| 4882 | t.setLayer(rootBoundlessLayer, INT32_MAX - 1); |
| 4883 | t.setPosition(rootBoundlessLayer, 32, 32); |
| 4884 | t.show(rootBoundlessLayer); |
| 4885 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 4886 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 4887 | t.show(colorLayer); |
| 4888 | t.hide(mFGSurfaceControl); |
| 4889 | }); |
| 4890 | { |
| 4891 | mCapture = screenshot(); |
| 4892 | // Top left of background must now be visible |
| 4893 | mCapture->expectBGColor(0, 0); |
| 4894 | // Top left of foreground must now be visible |
| 4895 | mCapture->expectBGColor(31, 31); |
| 4896 | // Foreground Surface bounds must be color layer |
| 4897 | mCapture->expectColor(Rect(32, 32, 96, 96), Color::BLACK); |
| 4898 | // Color layer should not extend past foreground bounds |
| 4899 | mCapture->expectBGColor(97, 97); |
| 4900 | } |
| 4901 | } |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4902 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4903 | class ScreenCaptureTest : public LayerUpdateTest { |
| 4904 | protected: |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4905 | std::unique_ptr<ScreenCapture> mCapture; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4906 | }; |
| 4907 | |
| 4908 | TEST_F(ScreenCaptureTest, CaptureSingleLayer) { |
| 4909 | auto bgHandle = mBGSurfaceControl->getHandle(); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4910 | ScreenCapture::captureLayers(&mCapture, bgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4911 | mCapture->expectBGColor(0, 0); |
| 4912 | // Doesn't capture FG layer which is at 64, 64 |
| 4913 | mCapture->expectBGColor(64, 64); |
| 4914 | } |
| 4915 | |
| 4916 | TEST_F(ScreenCaptureTest, CaptureLayerWithChild) { |
| 4917 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 4918 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4919 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 4920 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4921 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4922 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4923 | SurfaceComposerClient::Transaction().show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4924 | |
| 4925 | // Captures mFGSurfaceControl layer and its child. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4926 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4927 | mCapture->expectFGColor(10, 10); |
| 4928 | mCapture->expectChildColor(0, 0); |
| 4929 | } |
| 4930 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 4931 | TEST_F(ScreenCaptureTest, CaptureLayerChildOnly) { |
| 4932 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 4933 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4934 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 4935 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 4936 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4937 | |
| 4938 | SurfaceComposerClient::Transaction().show(child).apply(true); |
| 4939 | |
| 4940 | // Captures mFGSurfaceControl's child |
| 4941 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); |
| 4942 | mCapture->checkPixel(10, 10, 0, 0, 0); |
| 4943 | mCapture->expectChildColor(0, 0); |
| 4944 | } |
| 4945 | |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 4946 | TEST_F(ScreenCaptureTest, CaptureTransparent) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4947 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 4948 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 4949 | |
| 4950 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4951 | |
| 4952 | SurfaceComposerClient::Transaction().show(child).apply(true); |
| 4953 | |
| 4954 | auto childHandle = child->getHandle(); |
| 4955 | |
| 4956 | // Captures child |
| 4957 | ScreenCapture::captureLayers(&mCapture, childHandle, {0, 0, 10, 20}); |
| 4958 | mCapture->expectColor(Rect(0, 0, 9, 9), {200, 200, 200, 255}); |
| 4959 | // Area outside of child's bounds is transparent. |
| 4960 | mCapture->expectColor(Rect(0, 10, 9, 19), {0, 0, 0, 0}); |
| 4961 | } |
| 4962 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 4963 | TEST_F(ScreenCaptureTest, DontCaptureRelativeOutsideTree) { |
| 4964 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 4965 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4966 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 4967 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 4968 | ASSERT_NE(nullptr, child.get()) << "failed to create surface"; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4969 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 10, 10, 0); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 4970 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4971 | fillSurfaceRGBA8(relative, 100, 100, 100); |
| 4972 | |
| 4973 | SurfaceComposerClient::Transaction() |
| 4974 | .show(child) |
| 4975 | // Set relative layer above fg layer so should be shown above when computing all layers. |
| 4976 | .setRelativeLayer(relative, fgHandle, 1) |
| 4977 | .show(relative) |
| 4978 | .apply(true); |
| 4979 | |
| 4980 | // Captures mFGSurfaceControl layer and its child. Relative layer shouldn't be captured. |
| 4981 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
| 4982 | mCapture->expectFGColor(10, 10); |
| 4983 | mCapture->expectChildColor(0, 0); |
| 4984 | } |
| 4985 | |
| 4986 | TEST_F(ScreenCaptureTest, CaptureRelativeInTree) { |
| 4987 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 4988 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4989 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 4990 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 4991 | sp<SurfaceControl> relative = createSurface(mClient, "Relative surface", 10, 10, |
| 4992 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 4993 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 4994 | fillSurfaceRGBA8(relative, 100, 100, 100); |
| 4995 | |
| 4996 | SurfaceComposerClient::Transaction() |
| 4997 | .show(child) |
| 4998 | // Set relative layer below fg layer but relative to child layer so it should be shown |
| 4999 | // above child layer. |
| 5000 | .setLayer(relative, -1) |
| 5001 | .setRelativeLayer(relative, child->getHandle(), 1) |
| 5002 | .show(relative) |
| 5003 | .apply(true); |
| 5004 | |
| 5005 | // Captures mFGSurfaceControl layer and its children. Relative layer is a child of fg so its |
| 5006 | // relative value should be taken into account, placing it above child layer. |
| 5007 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
| 5008 | mCapture->expectFGColor(10, 10); |
| 5009 | // Relative layer is showing on top of child layer |
| 5010 | mCapture->expectColor(Rect(0, 0, 9, 9), {100, 100, 100, 255}); |
| 5011 | } |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5012 | |
| 5013 | // In the following tests we verify successful skipping of a parent layer, |
| 5014 | // so we use the same verification logic and only change how we mutate |
| 5015 | // the parent layer to verify that various properties are ignored. |
| 5016 | class ScreenCaptureChildOnlyTest : public LayerUpdateTest { |
| 5017 | public: |
| 5018 | void SetUp() override { |
| 5019 | LayerUpdateTest::SetUp(); |
| 5020 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5021 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, |
| 5022 | mFGSurfaceControl.get()); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5023 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 5024 | |
| 5025 | SurfaceComposerClient::Transaction().show(mChild).apply(true); |
| 5026 | } |
| 5027 | |
| 5028 | void verify() { |
| 5029 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 5030 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); |
| 5031 | mCapture->checkPixel(10, 10, 0, 0, 0); |
| 5032 | mCapture->expectChildColor(0, 0); |
| 5033 | } |
| 5034 | |
| 5035 | std::unique_ptr<ScreenCapture> mCapture; |
| 5036 | sp<SurfaceControl> mChild; |
| 5037 | }; |
| 5038 | |
| 5039 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentVisibility) { |
| 5040 | |
| 5041 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); |
| 5042 | |
| 5043 | // Even though the parent is hidden we should still capture the child. |
| 5044 | verify(); |
| 5045 | } |
| 5046 | |
| 5047 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentCrop) { |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 5048 | SurfaceComposerClient::Transaction() |
| 5049 | .setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 1, 1)) |
| 5050 | .apply(true); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5051 | |
| 5052 | // Even though the parent is cropped out we should still capture the child. |
| 5053 | verify(); |
| 5054 | } |
| 5055 | |
| 5056 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresTransform) { |
| 5057 | |
| 5058 | SurfaceComposerClient::Transaction().setMatrix(mFGSurfaceControl, 2, 0, 0, 2); |
| 5059 | |
| 5060 | // We should not inherit the parent scaling. |
| 5061 | verify(); |
| 5062 | } |
| 5063 | |
Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 5064 | TEST_F(ScreenCaptureChildOnlyTest, RegressionTest76099859) { |
| 5065 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); |
| 5066 | |
| 5067 | // Even though the parent is hidden we should still capture the child. |
| 5068 | verify(); |
| 5069 | |
| 5070 | // Verify everything was properly hidden when rendering the full-screen. |
| 5071 | screenshot()->expectBGColor(0,0); |
| 5072 | } |
| 5073 | |
| 5074 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5075 | TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) { |
| 5076 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 5077 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5078 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5079 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5080 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5081 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5082 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, |
| 5083 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5084 | |
| 5085 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 5086 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5087 | .show(child) |
| 5088 | .setPosition(grandchild, 5, 5) |
| 5089 | .show(grandchild) |
| 5090 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5091 | |
| 5092 | // Captures mFGSurfaceControl, its child, and the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5093 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5094 | mCapture->expectFGColor(10, 10); |
| 5095 | mCapture->expectChildColor(0, 0); |
| 5096 | mCapture->checkPixel(5, 5, 50, 50, 50); |
| 5097 | } |
| 5098 | |
| 5099 | TEST_F(ScreenCaptureTest, CaptureChildOnly) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5100 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5101 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5102 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5103 | auto childHandle = child->getHandle(); |
| 5104 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5105 | SurfaceComposerClient::Transaction().setPosition(child, 5, 5).show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5106 | |
| 5107 | // Captures only the child layer, and not the parent. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5108 | ScreenCapture::captureLayers(&mCapture, childHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5109 | mCapture->expectChildColor(0, 0); |
| 5110 | mCapture->expectChildColor(9, 9); |
| 5111 | } |
| 5112 | |
| 5113 | TEST_F(ScreenCaptureTest, CaptureGrandchildOnly) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5114 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5115 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5116 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5117 | auto childHandle = child->getHandle(); |
| 5118 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5119 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, |
| 5120 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5121 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 5122 | |
| 5123 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5124 | .show(child) |
| 5125 | .setPosition(grandchild, 5, 5) |
| 5126 | .show(grandchild) |
| 5127 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5128 | |
| 5129 | auto grandchildHandle = grandchild->getHandle(); |
| 5130 | |
| 5131 | // Captures only the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5132 | ScreenCapture::captureLayers(&mCapture, grandchildHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5133 | mCapture->checkPixel(0, 0, 50, 50, 50); |
| 5134 | mCapture->checkPixel(4, 4, 50, 50, 50); |
| 5135 | } |
| 5136 | |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5137 | TEST_F(ScreenCaptureTest, CaptureCrop) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5138 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5139 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, |
| 5140 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5141 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5142 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
| 5143 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5144 | |
| 5145 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5146 | .setLayer(redLayer, INT32_MAX - 1) |
| 5147 | .show(redLayer) |
| 5148 | .show(blueLayer) |
| 5149 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5150 | |
| 5151 | auto redLayerHandle = redLayer->getHandle(); |
| 5152 | |
| 5153 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5154 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 5155 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 5156 | // red area below the blue area |
| 5157 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 5158 | // red area to the right of the blue area |
| 5159 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5160 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 5161 | const Rect crop = Rect(0, 0, 30, 30); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5162 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, crop); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5163 | // Capturing the cropped screen, cropping out the shown red area, should leave only the blue |
| 5164 | // area visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5165 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5166 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 5167 | } |
| 5168 | |
| 5169 | TEST_F(ScreenCaptureTest, CaptureSize) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5170 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5171 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, |
| 5172 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5173 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5174 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
| 5175 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5176 | |
| 5177 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5178 | .setLayer(redLayer, INT32_MAX - 1) |
| 5179 | .show(redLayer) |
| 5180 | .show(blueLayer) |
| 5181 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5182 | |
| 5183 | auto redLayerHandle = redLayer->getHandle(); |
| 5184 | |
| 5185 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5186 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 5187 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 5188 | // red area below the blue area |
| 5189 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 5190 | // red area to the right of the blue area |
| 5191 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5192 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5193 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, Rect::EMPTY_RECT, 0.5); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5194 | // 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] | 5195 | mCapture->expectColor(Rect(0, 0, 14, 14), Color::BLUE); |
| 5196 | // red area below the blue area |
| 5197 | mCapture->expectColor(Rect(0, 15, 29, 29), Color::RED); |
| 5198 | // red area to the right of the blue area |
| 5199 | mCapture->expectColor(Rect(15, 0, 29, 29), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5200 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 5201 | } |
| 5202 | |
| 5203 | TEST_F(ScreenCaptureTest, CaptureInvalidLayer) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5204 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5205 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5206 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5207 | |
| 5208 | auto redLayerHandle = redLayer->getHandle(); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5209 | redLayer->clear(); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5210 | SurfaceComposerClient::Transaction().apply(true); |
| 5211 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5212 | sp<GraphicBuffer> outBuffer; |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5213 | |
| 5214 | // Layer was deleted so captureLayers should fail with NAME_NOT_FOUND |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5215 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 5216 | 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] | 5217 | } |
| 5218 | |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5219 | |
| 5220 | class DereferenceSurfaceControlTest : public LayerTransactionTest { |
| 5221 | protected: |
| 5222 | void SetUp() override { |
| 5223 | LayerTransactionTest::SetUp(); |
| 5224 | bgLayer = createLayer("BG layer", 20, 20); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5225 | fillBufferQueueLayerColor(bgLayer, Color::RED, 20, 20); |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5226 | fgLayer = createLayer("FG layer", 20, 20); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5227 | fillBufferQueueLayerColor(fgLayer, Color::BLUE, 20, 20); |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5228 | Transaction().setLayer(fgLayer, mLayerZBase + 1).apply(); |
| 5229 | { |
| 5230 | SCOPED_TRACE("before anything"); |
| 5231 | auto shot = screenshot(); |
| 5232 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); |
| 5233 | } |
| 5234 | } |
| 5235 | void TearDown() override { |
| 5236 | LayerTransactionTest::TearDown(); |
| 5237 | bgLayer = 0; |
| 5238 | fgLayer = 0; |
| 5239 | } |
| 5240 | |
| 5241 | sp<SurfaceControl> bgLayer; |
| 5242 | sp<SurfaceControl> fgLayer; |
| 5243 | }; |
| 5244 | |
| 5245 | TEST_F(DereferenceSurfaceControlTest, LayerNotInTransaction) { |
| 5246 | fgLayer = nullptr; |
| 5247 | { |
| 5248 | SCOPED_TRACE("after setting null"); |
| 5249 | auto shot = screenshot(); |
| 5250 | shot->expectColor(Rect(0, 0, 20, 20), Color::RED); |
| 5251 | } |
| 5252 | } |
| 5253 | |
| 5254 | TEST_F(DereferenceSurfaceControlTest, LayerInTransaction) { |
| 5255 | auto transaction = Transaction().show(fgLayer); |
| 5256 | fgLayer = nullptr; |
| 5257 | { |
| 5258 | SCOPED_TRACE("after setting null"); |
| 5259 | auto shot = screenshot(); |
| 5260 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); |
| 5261 | } |
| 5262 | } |
| 5263 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5264 | } // namespace android |