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> |
Ady Abraham | df9df4a | 2019-03-12 17:32:05 -0700 | [diff] [blame] | 35 | #include <hardware/hwcomposer_defs.h> |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 36 | #include <private/android_filesystem_config.h> |
Ady Abraham | df9df4a | 2019-03-12 17:32:05 -0700 | [diff] [blame] | 37 | #include <private/gui/ComposerService.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 38 | |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 39 | #include <ui/ColorSpace.h> |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 40 | #include <ui/DisplayInfo.h> |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 41 | #include <ui/Rect.h> |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 42 | #include <utils/String8.h> |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 43 | |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 44 | #include <math.h> |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 45 | #include <math/vec3.h> |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 46 | #include <sys/types.h> |
| 47 | #include <unistd.h> |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 48 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 49 | #include "BufferGenerator.h" |
| 50 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 51 | namespace android { |
| 52 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 53 | namespace { |
| 54 | |
| 55 | struct Color { |
| 56 | uint8_t r; |
| 57 | uint8_t g; |
| 58 | uint8_t b; |
| 59 | uint8_t a; |
| 60 | |
| 61 | static const Color RED; |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 62 | static const Color GREEN; |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 63 | static const Color BLUE; |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 64 | static const Color WHITE; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 65 | static const Color BLACK; |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 66 | static const Color TRANSPARENT; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | const Color Color::RED{255, 0, 0, 255}; |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 70 | const Color Color::GREEN{0, 255, 0, 255}; |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 71 | const Color Color::BLUE{0, 0, 255, 255}; |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 72 | const Color Color::WHITE{255, 255, 255, 255}; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 73 | const Color Color::BLACK{0, 0, 0, 255}; |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 74 | const Color Color::TRANSPARENT{0, 0, 0, 0}; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 75 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 76 | using android::hardware::graphics::common::V1_1::BufferUsage; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 77 | using namespace std::chrono_literals; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 78 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 79 | std::ostream& operator<<(std::ostream& os, const Color& color) { |
| 80 | os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a); |
| 81 | return os; |
| 82 | } |
| 83 | |
| 84 | // Fill a region with the specified color. |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 85 | void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect, |
| 86 | const Color& color) { |
| 87 | Rect r(0, 0, buffer.width, buffer.height); |
| 88 | if (!r.intersect(rect, &r)) { |
| 89 | return; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 92 | int32_t width = r.right - r.left; |
| 93 | int32_t height = r.bottom - r.top; |
| 94 | |
| 95 | for (int32_t row = 0; row < height; row++) { |
| 96 | uint8_t* dst = |
| 97 | static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (r.top + row) + r.left) * 4; |
| 98 | for (int32_t column = 0; column < width; column++) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 99 | dst[0] = color.r; |
| 100 | dst[1] = color.g; |
| 101 | dst[2] = color.b; |
| 102 | dst[3] = color.a; |
| 103 | dst += 4; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 108 | // Fill a region with the specified color. |
| 109 | void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect, const Color& color) { |
| 110 | Rect r(0, 0, buffer->width, buffer->height); |
| 111 | if (!r.intersect(rect, &r)) { |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | int32_t width = r.right - r.left; |
| 116 | int32_t height = r.bottom - r.top; |
| 117 | |
| 118 | uint8_t* pixels; |
| 119 | buffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 120 | reinterpret_cast<void**>(&pixels)); |
| 121 | |
| 122 | for (int32_t row = 0; row < height; row++) { |
| 123 | uint8_t* dst = pixels + (buffer->getStride() * (r.top + row) + r.left) * 4; |
| 124 | for (int32_t column = 0; column < width; column++) { |
| 125 | dst[0] = color.r; |
| 126 | dst[1] = color.g; |
| 127 | dst[2] = color.b; |
| 128 | dst[3] = color.a; |
| 129 | dst += 4; |
| 130 | } |
| 131 | } |
| 132 | buffer->unlock(); |
| 133 | } |
| 134 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 135 | // Check if a region has the specified color. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 136 | 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] | 137 | const Color& color, uint8_t tolerance) { |
| 138 | int32_t x = rect.left; |
| 139 | int32_t y = rect.top; |
| 140 | int32_t width = rect.right - rect.left; |
| 141 | int32_t height = rect.bottom - rect.top; |
| 142 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 143 | int32_t bufferWidth = int32_t(outBuffer->getWidth()); |
| 144 | int32_t bufferHeight = int32_t(outBuffer->getHeight()); |
| 145 | if (x + width > bufferWidth) { |
| 146 | x = std::min(x, bufferWidth); |
| 147 | width = bufferWidth - x; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 148 | } |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 149 | if (y + height > bufferHeight) { |
| 150 | y = std::min(y, bufferHeight); |
| 151 | height = bufferHeight - y; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | auto colorCompare = [tolerance](uint8_t a, uint8_t b) { |
| 155 | uint8_t tmp = a >= b ? a - b : b - a; |
| 156 | return tmp <= tolerance; |
| 157 | }; |
| 158 | for (int32_t j = 0; j < height; j++) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 159 | const uint8_t* src = pixels + (outBuffer->getStride() * (y + j) + x) * 4; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 160 | for (int32_t i = 0; i < width; i++) { |
| 161 | const uint8_t expected[4] = {color.r, color.g, color.b, color.a}; |
| 162 | EXPECT_TRUE(std::equal(src, src + 4, expected, colorCompare)) |
| 163 | << "pixel @ (" << x + i << ", " << y + j << "): " |
| 164 | << "expected (" << color << "), " |
| 165 | << "got (" << Color{src[0], src[1], src[2], src[3]} << ")"; |
| 166 | src += 4; |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | } // anonymous namespace |
| 172 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 173 | using Transaction = SurfaceComposerClient::Transaction; |
| 174 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 175 | // Fill an RGBA_8888 formatted surface with a single color. |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 176 | static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b, |
| 177 | bool unlock = true) { |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 178 | ANativeWindow_Buffer outBuffer; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 179 | sp<Surface> s = sc->getSurface(); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 180 | ASSERT_TRUE(s != nullptr); |
| 181 | ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, nullptr)); |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 182 | uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 183 | for (int y = 0; y < outBuffer.height; y++) { |
| 184 | for (int x = 0; x < outBuffer.width; x++) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 185 | uint8_t* pixel = img + (4 * (y * outBuffer.stride + x)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 186 | pixel[0] = r; |
| 187 | pixel[1] = g; |
| 188 | pixel[2] = b; |
| 189 | pixel[3] = 255; |
| 190 | } |
| 191 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 192 | if (unlock) { |
| 193 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 194 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | // A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check |
| 198 | // individual pixel values for testing purposes. |
| 199 | class ScreenCapture : public RefBase { |
| 200 | public: |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 201 | static void captureScreen(std::unique_ptr<ScreenCapture>* sc) { |
Vishnu Nair | b927e1f | 2019-02-19 13:36:15 -0800 | [diff] [blame] | 202 | captureScreen(sc, SurfaceComposerClient::getInternalDisplayToken()); |
| 203 | } |
| 204 | |
| 205 | static void captureScreen(std::unique_ptr<ScreenCapture>* sc, sp<IBinder> displayToken) { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 206 | const auto sf = ComposerService::getComposerService(); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 207 | SurfaceComposerClient::Transaction().apply(true); |
| 208 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 209 | sp<GraphicBuffer> outBuffer; |
Vishnu Nair | b927e1f | 2019-02-19 13:36:15 -0800 | [diff] [blame] | 210 | ASSERT_EQ(NO_ERROR, sf->captureScreen(displayToken, &outBuffer, Rect(), 0, 0, false)); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 211 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, |
| 215 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { |
| 216 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 217 | SurfaceComposerClient::Transaction().apply(true); |
| 218 | |
| 219 | sp<GraphicBuffer> outBuffer; |
| 220 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale)); |
| 221 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 224 | static void captureChildLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, |
| 225 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { |
| 226 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 227 | SurfaceComposerClient::Transaction().apply(true); |
| 228 | |
| 229 | sp<GraphicBuffer> outBuffer; |
| 230 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale, true)); |
| 231 | *sc = std::make_unique<ScreenCapture>(outBuffer); |
| 232 | } |
| 233 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 234 | void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 235 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
| 236 | expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 240 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 241 | const bool leftBorder = rect.left > 0; |
| 242 | const bool topBorder = rect.top > 0; |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 243 | const bool rightBorder = rect.right < int32_t(mOutBuffer->getWidth()); |
| 244 | const bool bottomBorder = rect.bottom < int32_t(mOutBuffer->getHeight()); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 245 | |
| 246 | if (topBorder) { |
| 247 | Rect top(rect.left, rect.top - 1, rect.right, rect.top); |
| 248 | if (leftBorder) { |
| 249 | top.left -= 1; |
| 250 | } |
| 251 | if (rightBorder) { |
| 252 | top.right += 1; |
| 253 | } |
| 254 | expectColor(top, color, tolerance); |
| 255 | } |
| 256 | if (leftBorder) { |
| 257 | Rect left(rect.left - 1, rect.top, rect.left, rect.bottom); |
| 258 | expectColor(left, color, tolerance); |
| 259 | } |
| 260 | if (rightBorder) { |
| 261 | Rect right(rect.right, rect.top, rect.right + 1, rect.bottom); |
| 262 | expectColor(right, color, tolerance); |
| 263 | } |
| 264 | if (bottomBorder) { |
| 265 | Rect bottom(rect.left, rect.bottom, rect.right, rect.bottom + 1); |
| 266 | if (leftBorder) { |
| 267 | bottom.left -= 1; |
| 268 | } |
| 269 | if (rightBorder) { |
| 270 | bottom.right += 1; |
| 271 | } |
| 272 | expectColor(bottom, color, tolerance); |
| 273 | } |
| 274 | } |
| 275 | |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 276 | void expectQuadrant(const Rect& rect, const Color& topLeft, const Color& topRight, |
| 277 | const Color& bottomLeft, const Color& bottomRight, bool filtered = false, |
| 278 | uint8_t tolerance = 0) { |
| 279 | ASSERT_TRUE((rect.right - rect.left) % 2 == 0 && (rect.bottom - rect.top) % 2 == 0); |
| 280 | |
| 281 | const int32_t centerX = rect.left + (rect.right - rect.left) / 2; |
| 282 | const int32_t centerY = rect.top + (rect.bottom - rect.top) / 2; |
| 283 | // avoid checking borders due to unspecified filtering behavior |
| 284 | const int32_t offsetX = filtered ? 2 : 0; |
| 285 | const int32_t offsetY = filtered ? 2 : 0; |
| 286 | expectColor(Rect(rect.left, rect.top, centerX - offsetX, centerY - offsetY), topLeft, |
| 287 | tolerance); |
| 288 | expectColor(Rect(centerX + offsetX, rect.top, rect.right, centerY - offsetY), topRight, |
| 289 | tolerance); |
| 290 | expectColor(Rect(rect.left, centerY + offsetY, centerX - offsetX, rect.bottom), bottomLeft, |
| 291 | tolerance); |
| 292 | expectColor(Rect(centerX + offsetX, centerY + offsetY, rect.right, rect.bottom), |
| 293 | bottomRight, tolerance); |
| 294 | } |
| 295 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 296 | 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] | 297 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); |
| 298 | const uint8_t* pixel = mPixels + (4 * (y * mOutBuffer->getStride() + x)); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 299 | if (r != pixel[0] || g != pixel[1] || b != pixel[2]) { |
| 300 | String8 err(String8::format("pixel @ (%3d, %3d): " |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 301 | "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]", |
| 302 | x, y, r, g, b, pixel[0], pixel[1], pixel[2])); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 303 | EXPECT_EQ(String8(), err) << err.string(); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 307 | 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] | 308 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 309 | 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] | 310 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 311 | 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] | 312 | |
Chih-Hung Hsieh | 2274904 | 2018-12-20 15:50:39 -0800 | [diff] [blame] | 313 | explicit ScreenCapture(const sp<GraphicBuffer>& outBuffer) : mOutBuffer(outBuffer) { |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 314 | mOutBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&mPixels)); |
Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 315 | } |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 316 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 317 | ~ScreenCapture() { mOutBuffer->unlock(); } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 318 | |
| 319 | private: |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 320 | sp<GraphicBuffer> mOutBuffer; |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 321 | uint8_t* mPixels = nullptr; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 322 | }; |
| 323 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 324 | class LayerTransactionTest : public ::testing::Test { |
| 325 | protected: |
| 326 | void SetUp() override { |
| 327 | mClient = new SurfaceComposerClient; |
| 328 | ASSERT_EQ(NO_ERROR, mClient->initCheck()) << "failed to create SurfaceComposerClient"; |
| 329 | |
| 330 | ASSERT_NO_FATAL_FAILURE(SetUpDisplay()); |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 331 | |
| 332 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 333 | ASSERT_NO_FATAL_FAILURE(sf->getColorManagement(&mColorManagementUsed)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 334 | } |
| 335 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 336 | virtual void TearDown() { |
| 337 | mBlackBgSurface = 0; |
| 338 | mClient->dispose(); |
| 339 | mClient = 0; |
| 340 | } |
| 341 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 342 | virtual sp<SurfaceControl> createLayer(const sp<SurfaceComposerClient>& client, |
| 343 | const char* name, uint32_t width, uint32_t height, |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 344 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { |
| 345 | auto layer = |
| 346 | createSurface(client, name, width, height, PIXEL_FORMAT_RGBA_8888, flags, parent); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 347 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 348 | Transaction t; |
| 349 | t.setLayerStack(layer, mDisplayLayerStack).setLayer(layer, mLayerZBase); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 350 | |
| 351 | status_t error = t.apply(); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 352 | if (error != NO_ERROR) { |
| 353 | ADD_FAILURE() << "failed to initialize SurfaceControl"; |
| 354 | layer.clear(); |
| 355 | } |
| 356 | |
| 357 | return layer; |
| 358 | } |
| 359 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 360 | virtual sp<SurfaceControl> createSurface(const sp<SurfaceComposerClient>& client, |
| 361 | const char* name, uint32_t width, uint32_t height, |
| 362 | PixelFormat format, uint32_t flags, |
| 363 | SurfaceControl* parent = nullptr) { |
| 364 | auto layer = client->createSurface(String8(name), width, height, format, flags, parent); |
| 365 | EXPECT_NE(nullptr, layer.get()) << "failed to create SurfaceControl"; |
| 366 | return layer; |
| 367 | } |
| 368 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 369 | virtual sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 370 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { |
| 371 | return createLayer(mClient, name, width, height, flags, parent); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 374 | ANativeWindow_Buffer getBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 375 | // wait for previous transactions (such as setSize) to complete |
| 376 | Transaction().apply(true); |
| 377 | |
| 378 | ANativeWindow_Buffer buffer = {}; |
| 379 | EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr)); |
| 380 | |
| 381 | return buffer; |
| 382 | } |
| 383 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 384 | void postBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 385 | ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost()); |
| 386 | |
| 387 | // wait for the newly posted buffer to be latched |
| 388 | waitForLayerBuffers(); |
| 389 | } |
| 390 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 391 | virtual void fillBufferQueueLayerColor(const sp<SurfaceControl>& layer, const Color& color, |
| 392 | int32_t bufferWidth, int32_t bufferHeight) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 393 | ANativeWindow_Buffer buffer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 394 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 395 | fillANativeWindowBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); |
| 396 | postBufferQueueLayerBuffer(layer); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 399 | virtual void fillBufferStateLayerColor(const sp<SurfaceControl>& layer, const Color& color, |
| 400 | int32_t bufferWidth, int32_t bufferHeight) { |
| 401 | sp<GraphicBuffer> buffer = |
| 402 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, |
| 403 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 404 | BufferUsage::COMPOSER_OVERLAY, |
| 405 | "test"); |
| 406 | fillGraphicBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 407 | Transaction().setBuffer(layer, buffer).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void fillLayerColor(uint32_t mLayerType, const sp<SurfaceControl>& layer, const Color& color, |
| 411 | int32_t bufferWidth, int32_t bufferHeight) { |
| 412 | switch (mLayerType) { |
| 413 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 414 | fillBufferQueueLayerColor(layer, color, bufferWidth, bufferHeight); |
| 415 | break; |
| 416 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 417 | fillBufferStateLayerColor(layer, color, bufferWidth, bufferHeight); |
| 418 | break; |
| 419 | default: |
| 420 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | void fillLayerQuadrant(uint32_t mLayerType, const sp<SurfaceControl>& layer, |
| 425 | int32_t bufferWidth, int32_t bufferHeight, const Color& topLeft, |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 426 | const Color& topRight, const Color& bottomLeft, |
| 427 | const Color& bottomRight) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 428 | switch (mLayerType) { |
| 429 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 430 | fillBufferQueueLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, |
| 431 | bottomLeft, bottomRight); |
| 432 | break; |
| 433 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 434 | fillBufferStateLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, |
| 435 | bottomLeft, bottomRight); |
| 436 | break; |
| 437 | default: |
| 438 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | virtual void fillBufferQueueLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 443 | int32_t bufferHeight, const Color& topLeft, |
| 444 | const Color& topRight, const Color& bottomLeft, |
| 445 | const Color& bottomRight) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 446 | ANativeWindow_Buffer buffer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 447 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 448 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 449 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 450 | const int32_t halfW = bufferWidth / 2; |
| 451 | const int32_t halfH = bufferHeight / 2; |
| 452 | fillANativeWindowBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); |
| 453 | fillANativeWindowBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); |
| 454 | fillANativeWindowBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); |
| 455 | fillANativeWindowBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), |
| 456 | bottomRight); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 457 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 458 | postBufferQueueLayerBuffer(layer); |
| 459 | } |
| 460 | |
| 461 | virtual void fillBufferStateLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 462 | int32_t bufferHeight, const Color& topLeft, |
| 463 | const Color& topRight, const Color& bottomLeft, |
| 464 | const Color& bottomRight) { |
| 465 | sp<GraphicBuffer> buffer = |
| 466 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, |
| 467 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 468 | BufferUsage::COMPOSER_OVERLAY, |
| 469 | "test"); |
| 470 | |
| 471 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); |
| 472 | |
| 473 | const int32_t halfW = bufferWidth / 2; |
| 474 | const int32_t halfH = bufferHeight / 2; |
| 475 | fillGraphicBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); |
| 476 | fillGraphicBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); |
| 477 | fillGraphicBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); |
| 478 | fillGraphicBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), bottomRight); |
| 479 | |
| 480 | Transaction().setBuffer(layer, buffer).setSize(layer, bufferWidth, bufferHeight).apply(); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 481 | } |
| 482 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 483 | std::unique_ptr<ScreenCapture> screenshot() { |
| 484 | std::unique_ptr<ScreenCapture> screenshot; |
| 485 | ScreenCapture::captureScreen(&screenshot); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 486 | return screenshot; |
| 487 | } |
| 488 | |
Vishnu Nair | b927e1f | 2019-02-19 13:36:15 -0800 | [diff] [blame] | 489 | void asTransaction(const std::function<void(Transaction&)>& exec) { |
| 490 | Transaction t; |
| 491 | exec(t); |
| 492 | t.apply(true); |
| 493 | } |
| 494 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 495 | static status_t getBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) { |
| 496 | static BufferGenerator bufferGenerator; |
| 497 | return bufferGenerator.get(outBuffer, outFence); |
| 498 | } |
| 499 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 500 | sp<SurfaceComposerClient> mClient; |
| 501 | |
| 502 | sp<IBinder> mDisplay; |
| 503 | uint32_t mDisplayWidth; |
| 504 | uint32_t mDisplayHeight; |
| 505 | uint32_t mDisplayLayerStack; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 506 | Rect mDisplayRect = Rect::INVALID_RECT; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 507 | |
| 508 | // leave room for ~256 layers |
| 509 | const int32_t mLayerZBase = std::numeric_limits<int32_t>::max() - 256; |
| 510 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 511 | sp<SurfaceControl> mBlackBgSurface; |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 512 | bool mColorManagementUsed; |
| 513 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 514 | private: |
| 515 | void SetUpDisplay() { |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 516 | mDisplay = mClient->getInternalDisplayToken(); |
| 517 | ASSERT_FALSE(mDisplay == nullptr) << "failed to get display"; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 518 | |
| 519 | // get display width/height |
| 520 | DisplayInfo info; |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 521 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayInfo(mDisplay, &info)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 522 | mDisplayWidth = info.w; |
| 523 | mDisplayHeight = info.h; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 524 | mDisplayRect = |
| 525 | Rect(static_cast<int32_t>(mDisplayWidth), static_cast<int32_t>(mDisplayHeight)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 526 | |
| 527 | // After a new buffer is queued, SurfaceFlinger is notified and will |
| 528 | // latch the new buffer on next vsync. Let's heuristically wait for 3 |
| 529 | // vsyncs. |
| 530 | mBufferPostDelay = int32_t(1e6 / info.fps) * 3; |
| 531 | |
| 532 | mDisplayLayerStack = 0; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 533 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 534 | mBlackBgSurface = |
| 535 | createSurface(mClient, "BaseSurface", 0 /* buffer width */, 0 /* buffer height */, |
| 536 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 537 | |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 538 | // set layer stack (b/68888219) |
| 539 | Transaction t; |
| 540 | t.setDisplayLayerStack(mDisplay, mDisplayLayerStack); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 541 | t.setCrop_legacy(mBlackBgSurface, Rect(0, 0, mDisplayWidth, mDisplayHeight)); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 542 | t.setLayerStack(mBlackBgSurface, mDisplayLayerStack); |
| 543 | t.setColor(mBlackBgSurface, half3{0, 0, 0}); |
| 544 | t.setLayer(mBlackBgSurface, mLayerZBase); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 545 | t.apply(); |
| 546 | } |
| 547 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 548 | void waitForLayerBuffers() { |
| 549 | // Request an empty transaction to get applied synchronously to ensure the buffer is |
| 550 | // latched. |
| 551 | Transaction().apply(true); |
| 552 | usleep(mBufferPostDelay); |
| 553 | } |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 554 | |
| 555 | int32_t mBufferPostDelay; |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 556 | |
| 557 | friend class LayerRenderPathTestHarness; |
| 558 | }; |
| 559 | enum class RenderPath { SCREENSHOT, VIRTUAL_DISPLAY }; |
| 560 | |
| 561 | class LayerRenderPathTestHarness { |
| 562 | public: |
| 563 | LayerRenderPathTestHarness(LayerTransactionTest* delegate, RenderPath renderPath) |
| 564 | : mDelegate(delegate), mRenderPath(renderPath) {} |
| 565 | |
| 566 | std::unique_ptr<ScreenCapture> getScreenCapture() { |
| 567 | switch (mRenderPath) { |
| 568 | case RenderPath::SCREENSHOT: |
| 569 | return mDelegate->screenshot(); |
| 570 | case RenderPath::VIRTUAL_DISPLAY: |
| 571 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 572 | const auto mainDisplay = SurfaceComposerClient::getInternalDisplayToken(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 573 | DisplayInfo mainDisplayInfo; |
| 574 | SurfaceComposerClient::getDisplayInfo(mainDisplay, &mainDisplayInfo); |
| 575 | |
| 576 | sp<IBinder> vDisplay; |
| 577 | sp<IGraphicBufferProducer> producer; |
| 578 | sp<IGraphicBufferConsumer> consumer; |
| 579 | sp<BufferItemConsumer> itemConsumer; |
| 580 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 581 | |
| 582 | consumer->setConsumerName(String8("Virtual disp consumer")); |
| 583 | consumer->setDefaultBufferSize(mainDisplayInfo.w, mainDisplayInfo.h); |
| 584 | |
| 585 | itemConsumer = new BufferItemConsumer(consumer, |
| 586 | // Sample usage bits from screenrecord |
| 587 | GRALLOC_USAGE_HW_VIDEO_ENCODER | |
| 588 | GRALLOC_USAGE_SW_READ_OFTEN); |
| 589 | |
| 590 | vDisplay = SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), |
| 591 | false /*secure*/); |
| 592 | |
| 593 | SurfaceComposerClient::Transaction t; |
| 594 | t.setDisplaySurface(vDisplay, producer); |
| 595 | t.setDisplayLayerStack(vDisplay, 0); |
| 596 | t.setDisplayProjection(vDisplay, mainDisplayInfo.orientation, |
| 597 | Rect(mainDisplayInfo.viewportW, mainDisplayInfo.viewportH), |
| 598 | Rect(mainDisplayInfo.w, mainDisplayInfo.h)); |
| 599 | t.apply(); |
| 600 | SurfaceComposerClient::Transaction().apply(true); |
| 601 | BufferItem item; |
| 602 | itemConsumer->acquireBuffer(&item, 0, true); |
| 603 | auto sc = std::make_unique<ScreenCapture>(item.mGraphicBuffer); |
| 604 | itemConsumer->releaseBuffer(item); |
| 605 | SurfaceComposerClient::destroyDisplay(vDisplay); |
| 606 | return sc; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | protected: |
| 611 | LayerTransactionTest* mDelegate; |
| 612 | RenderPath mRenderPath; |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 613 | }; |
| 614 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 615 | class LayerTypeTransactionHarness : public LayerTransactionTest { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 616 | public: |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 617 | LayerTypeTransactionHarness(uint32_t layerType) : mLayerType(layerType) {} |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 618 | |
| 619 | sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 620 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 621 | // if the flags already have a layer type specified, return an error |
| 622 | if (flags & ISurfaceComposerClient::eFXSurfaceMask) { |
| 623 | return nullptr; |
| 624 | } |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 625 | return LayerTransactionTest::createLayer(name, width, height, flags | mLayerType, parent); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color, int32_t bufferWidth, |
| 629 | int32_t bufferHeight) { |
| 630 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerColor(mLayerType, layer, color, |
| 631 | bufferWidth, bufferHeight)); |
| 632 | } |
| 633 | |
| 634 | void fillLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, |
| 635 | int32_t bufferHeight, const Color& topLeft, const Color& topRight, |
| 636 | const Color& bottomLeft, const Color& bottomRight) { |
| 637 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerQuadrant(mLayerType, layer, |
| 638 | bufferWidth, bufferHeight, |
| 639 | topLeft, topRight, |
| 640 | bottomLeft, bottomRight)); |
| 641 | } |
| 642 | |
| 643 | protected: |
| 644 | uint32_t mLayerType; |
| 645 | }; |
| 646 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 647 | class LayerTypeTransactionTest : public LayerTypeTransactionHarness, |
| 648 | public ::testing::WithParamInterface<uint32_t> { |
| 649 | public: |
| 650 | LayerTypeTransactionTest() : LayerTypeTransactionHarness(GetParam()) {} |
| 651 | }; |
| 652 | |
| 653 | class LayerTypeAndRenderTypeTransactionTest |
| 654 | : public LayerTypeTransactionHarness, |
| 655 | public ::testing::WithParamInterface<std::tuple<uint32_t, RenderPath>> { |
| 656 | public: |
| 657 | LayerTypeAndRenderTypeTransactionTest() |
| 658 | : LayerTypeTransactionHarness(std::get<0>(GetParam())), |
| 659 | mRenderPathHarness(LayerRenderPathTestHarness(this, std::get<1>(GetParam()))) {} |
| 660 | |
| 661 | std::unique_ptr<ScreenCapture> getScreenCapture() { |
| 662 | return mRenderPathHarness.getScreenCapture(); |
| 663 | } |
| 664 | |
| 665 | protected: |
| 666 | LayerRenderPathTestHarness mRenderPathHarness; |
| 667 | }; |
| 668 | |
| 669 | // Environment for starting up binder threads. This is required for testing |
| 670 | // virtual displays, as BufferQueue parameters may be queried over binder. |
| 671 | class BinderEnvironment : public ::testing::Environment { |
| 672 | public: |
| 673 | void SetUp() override { ProcessState::self()->startThreadPool(); } |
| 674 | }; |
| 675 | |
| 676 | ::testing::Environment* const binderEnv = |
| 677 | ::testing::AddGlobalTestEnvironment(new BinderEnvironment()); |
| 678 | |
| 679 | class LayerRenderTypeTransactionTest : public LayerTransactionTest, |
| 680 | public ::testing::WithParamInterface<RenderPath> { |
| 681 | public: |
| 682 | LayerRenderTypeTransactionTest() : mHarness(LayerRenderPathTestHarness(this, GetParam())) {} |
| 683 | |
| 684 | std::unique_ptr<ScreenCapture> getScreenCapture() { return mHarness.getScreenCapture(); } |
| 685 | void setRelativeZBasicHelper(uint32_t layerType); |
| 686 | void setRelativeZGroupHelper(uint32_t layerType); |
| 687 | void setAlphaBasicHelper(uint32_t layerType); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 688 | void setBackgroundColorHelper(uint32_t layerType, bool priorColor, bool bufferFill, float alpha, |
| 689 | Color finalColor); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 690 | |
| 691 | protected: |
| 692 | LayerRenderPathTestHarness mHarness; |
| 693 | }; |
| 694 | |
| 695 | INSTANTIATE_TEST_CASE_P( |
| 696 | LayerTypeAndRenderTypeTransactionTests, LayerTypeAndRenderTypeTransactionTest, |
| 697 | ::testing::Combine( |
| 698 | ::testing::Values( |
| 699 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferQueue), |
| 700 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferState)), |
| 701 | ::testing::Values(RenderPath::VIRTUAL_DISPLAY, RenderPath::SCREENSHOT))); |
| 702 | |
| 703 | INSTANTIATE_TEST_CASE_P(LayerRenderTypeTransactionTests, LayerRenderTypeTransactionTest, |
| 704 | ::testing::Values(RenderPath::VIRTUAL_DISPLAY, RenderPath::SCREENSHOT)); |
| 705 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 706 | INSTANTIATE_TEST_CASE_P( |
| 707 | LayerTypeTransactionTests, LayerTypeTransactionTest, |
| 708 | ::testing::Values(static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferQueue), |
| 709 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferState))); |
| 710 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 711 | TEST_P(LayerRenderTypeTransactionTest, SetPositionBasic_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 712 | sp<SurfaceControl> layer; |
| 713 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 714 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 715 | |
| 716 | { |
| 717 | SCOPED_TRACE("default position"); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 718 | const Rect rect(0, 0, 32, 32); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 719 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 720 | shot->expectColor(rect, Color::RED); |
| 721 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | Transaction().setPosition(layer, 5, 10).apply(); |
| 725 | { |
| 726 | SCOPED_TRACE("new position"); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 727 | const Rect rect(5, 10, 37, 42); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 728 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 729 | shot->expectColor(rect, Color::RED); |
| 730 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 734 | TEST_P(LayerRenderTypeTransactionTest, SetPositionRounding_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 735 | sp<SurfaceControl> layer; |
| 736 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 737 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 738 | |
| 739 | // GLES requires only 4 bits of subpixel precision during rasterization |
| 740 | // XXX GLES composition does not match HWC composition due to precision |
| 741 | // loss (b/69315223) |
| 742 | const float epsilon = 1.0f / 16.0f; |
| 743 | Transaction().setPosition(layer, 0.5f - epsilon, 0.5f - epsilon).apply(); |
| 744 | { |
| 745 | SCOPED_TRACE("rounding down"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 746 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | Transaction().setPosition(layer, 0.5f + epsilon, 0.5f + epsilon).apply(); |
| 750 | { |
| 751 | SCOPED_TRACE("rounding up"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 752 | getScreenCapture()->expectColor(Rect(1, 1, 33, 33), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 756 | TEST_P(LayerRenderTypeTransactionTest, SetPositionOutOfBounds_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 757 | sp<SurfaceControl> layer; |
| 758 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 759 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 760 | |
| 761 | Transaction().setPosition(layer, -32, -32).apply(); |
| 762 | { |
| 763 | SCOPED_TRACE("negative coordinates"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 764 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | Transaction().setPosition(layer, mDisplayWidth, mDisplayHeight).apply(); |
| 768 | { |
| 769 | SCOPED_TRACE("positive coordinates"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 770 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 774 | TEST_P(LayerRenderTypeTransactionTest, SetPositionPartiallyOutOfBounds_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 775 | sp<SurfaceControl> layer; |
| 776 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 777 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 778 | |
| 779 | // partially out of bounds |
| 780 | Transaction().setPosition(layer, -30, -30).apply(); |
| 781 | { |
| 782 | SCOPED_TRACE("negative coordinates"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 783 | getScreenCapture()->expectColor(Rect(0, 0, 2, 2), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | Transaction().setPosition(layer, mDisplayWidth - 2, mDisplayHeight - 2).apply(); |
| 787 | { |
| 788 | SCOPED_TRACE("positive coordinates"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 789 | getScreenCapture()->expectColor(Rect(mDisplayWidth - 2, mDisplayHeight - 2, mDisplayWidth, |
| 790 | mDisplayHeight), |
| 791 | Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 792 | } |
| 793 | } |
| 794 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 795 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithResize_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 796 | sp<SurfaceControl> layer; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 797 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 798 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 799 | |
| 800 | // setPosition is applied immediately by default, with or without resize |
| 801 | // pending |
| 802 | Transaction().setPosition(layer, 5, 10).setSize(layer, 64, 64).apply(); |
| 803 | { |
| 804 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 805 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 806 | const Rect rect(5, 10, 37, 42); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 807 | shot->expectColor(rect, Color::RED); |
| 808 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 811 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 812 | { |
| 813 | SCOPED_TRACE("resize applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 814 | getScreenCapture()->expectColor(Rect(5, 10, 69, 74), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 818 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithNextResize_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 819 | sp<SurfaceControl> layer; |
| 820 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 821 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 822 | |
| 823 | // request setPosition to be applied with the next resize |
| 824 | Transaction().setPosition(layer, 5, 10).setGeometryAppliesWithResize(layer).apply(); |
| 825 | { |
| 826 | SCOPED_TRACE("new position pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 827 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | Transaction().setPosition(layer, 15, 20).apply(); |
| 831 | { |
| 832 | SCOPED_TRACE("pending new position modified"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 833 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | Transaction().setSize(layer, 64, 64).apply(); |
| 837 | { |
| 838 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 839 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | // finally resize and latch the buffer |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 843 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 844 | { |
| 845 | SCOPED_TRACE("new position applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 846 | getScreenCapture()->expectColor(Rect(15, 20, 79, 84), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 850 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithNextResizeScaleToWindow_BufferQueue) { |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 851 | sp<SurfaceControl> layer; |
| 852 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 853 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 854 | |
| 855 | // setPosition is not immediate even with SCALE_TO_WINDOW override |
| 856 | Transaction() |
| 857 | .setPosition(layer, 5, 10) |
| 858 | .setSize(layer, 64, 64) |
| 859 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 860 | .setGeometryAppliesWithResize(layer) |
| 861 | .apply(); |
| 862 | { |
| 863 | SCOPED_TRACE("new position pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 864 | getScreenCapture()->expectColor(Rect(0, 0, 64, 64), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 867 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 868 | { |
| 869 | SCOPED_TRACE("new position applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 870 | getScreenCapture()->expectColor(Rect(5, 10, 69, 74), Color::RED); |
Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 874 | TEST_P(LayerRenderTypeTransactionTest, SetSizeBasic_BufferQueue) { |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 875 | sp<SurfaceControl> layer; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 876 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 877 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 878 | |
| 879 | Transaction().setSize(layer, 64, 64).apply(); |
| 880 | { |
| 881 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 882 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 883 | const Rect rect(0, 0, 32, 32); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 884 | shot->expectColor(rect, Color::RED); |
| 885 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 888 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 889 | { |
| 890 | SCOPED_TRACE("resize applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 891 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 892 | const Rect rect(0, 0, 64, 64); |
| 893 | shot->expectColor(rect, Color::RED); |
| 894 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 898 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetSizeInvalid) { |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 899 | // cannot test robustness against invalid sizes (zero or really huge) |
| 900 | } |
| 901 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 902 | TEST_P(LayerRenderTypeTransactionTest, SetSizeWithScaleToWindow_BufferQueue) { |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 903 | sp<SurfaceControl> layer; |
| 904 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 905 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 906 | |
| 907 | // setSize is immediate with SCALE_TO_WINDOW, unlike setPosition |
| 908 | Transaction() |
| 909 | .setSize(layer, 64, 64) |
| 910 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 911 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 912 | getScreenCapture()->expectColor(Rect(0, 0, 64, 64), Color::RED); |
Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 915 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetZBasic) { |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 916 | sp<SurfaceControl> layerR; |
| 917 | sp<SurfaceControl> layerG; |
| 918 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 919 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 920 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 921 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 922 | |
| 923 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); |
| 924 | { |
| 925 | SCOPED_TRACE("layerR"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 926 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | Transaction().setLayer(layerG, mLayerZBase + 2).apply(); |
| 930 | { |
| 931 | SCOPED_TRACE("layerG"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 932 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::GREEN); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 936 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetZNegative) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 937 | sp<SurfaceControl> parent = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 938 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 939 | ISurfaceComposerClient::eFXSurfaceContainer); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 940 | Transaction().setCrop_legacy(parent, Rect(0, 0, mDisplayWidth, mDisplayHeight)).apply(); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 941 | sp<SurfaceControl> layerR; |
| 942 | sp<SurfaceControl> layerG; |
| 943 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 944 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 945 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 946 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 947 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 948 | Transaction() |
| 949 | .reparent(layerR, parent->getHandle()) |
| 950 | .reparent(layerG, parent->getHandle()) |
| 951 | .apply(); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 952 | Transaction().setLayer(layerR, -1).setLayer(layerG, -2).apply(); |
| 953 | { |
| 954 | SCOPED_TRACE("layerR"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 955 | auto shot = getScreenCapture(); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 956 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | Transaction().setLayer(layerR, -3).apply(); |
| 960 | { |
| 961 | SCOPED_TRACE("layerG"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 962 | auto shot = getScreenCapture(); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 963 | shot->expectColor(Rect(0, 0, 32, 32), Color::GREEN); |
Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 967 | void LayerRenderTypeTransactionTest::setRelativeZBasicHelper(uint32_t layerType) { |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 968 | sp<SurfaceControl> layerR; |
| 969 | sp<SurfaceControl> layerG; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 970 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32, layerType)); |
| 971 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerR, Color::RED, 32, 32)); |
| 972 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32, layerType)); |
| 973 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 974 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 975 | switch (layerType) { |
| 976 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 977 | Transaction() |
| 978 | .setPosition(layerG, 16, 16) |
| 979 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 980 | .apply(); |
| 981 | break; |
| 982 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 983 | Transaction() |
| 984 | .setFrame(layerR, Rect(0, 0, 32, 32)) |
| 985 | .setFrame(layerG, Rect(16, 16, 48, 48)) |
| 986 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 987 | .apply(); |
| 988 | break; |
| 989 | default: |
| 990 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 991 | } |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 992 | { |
| 993 | SCOPED_TRACE("layerG above"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 994 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 995 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 996 | shot->expectColor(Rect(16, 16, 48, 48), Color::GREEN); |
| 997 | } |
| 998 | |
| 999 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).apply(); |
| 1000 | { |
| 1001 | SCOPED_TRACE("layerG below"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1002 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1003 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1004 | shot->expectColor(Rect(32, 32, 48, 48), Color::GREEN); |
| 1005 | } |
| 1006 | } |
| 1007 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1008 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZBasic_BufferQueue) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1009 | ASSERT_NO_FATAL_FAILURE(setRelativeZBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); |
| 1010 | } |
| 1011 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1012 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZBasic_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1013 | ASSERT_NO_FATAL_FAILURE(setRelativeZBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1014 | } |
| 1015 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1016 | TEST_P(LayerTypeTransactionTest, SetRelativeZNegative) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1017 | sp<SurfaceControl> parent = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1018 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1019 | ISurfaceComposerClient::eFXSurfaceContainer); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1020 | Transaction().setCrop_legacy(parent, Rect(0, 0, mDisplayWidth, mDisplayHeight)).apply(); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1021 | sp<SurfaceControl> layerR; |
| 1022 | sp<SurfaceControl> layerG; |
| 1023 | sp<SurfaceControl> layerB; |
| 1024 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1025 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1026 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1027 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1028 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1029 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1030 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1031 | Transaction() |
| 1032 | .reparent(layerB, parent->getHandle()) |
| 1033 | .apply(); |
| 1034 | |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1035 | // layerR = mLayerZBase, layerG = layerR - 1, layerB = -2 |
| 1036 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).setLayer(layerB, -2).apply(); |
| 1037 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1038 | std::unique_ptr<ScreenCapture> screenshot; |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1039 | // only layerB is in this range |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1040 | sp<IBinder> parentHandle = parent->getHandle(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1041 | ScreenCapture::captureLayers(&screenshot, parentHandle, Rect(0, 0, 32, 32)); |
Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1042 | screenshot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 1043 | } |
| 1044 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1045 | void LayerRenderTypeTransactionTest::setRelativeZGroupHelper(uint32_t layerType) { |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1046 | sp<SurfaceControl> layerR; |
| 1047 | sp<SurfaceControl> layerG; |
| 1048 | sp<SurfaceControl> layerB; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1049 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test", 32, 32, layerType)); |
| 1050 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerR, Color::RED, 32, 32)); |
| 1051 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test", 32, 32, layerType)); |
| 1052 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerG, Color::GREEN, 32, 32)); |
| 1053 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test", 32, 32, layerType)); |
| 1054 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerB, Color::BLUE, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1055 | |
| 1056 | // layerR = 0, layerG = layerR + 3, layerB = 2 |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1057 | switch (layerType) { |
| 1058 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 1059 | Transaction() |
| 1060 | .setPosition(layerG, 8, 8) |
| 1061 | .setRelativeLayer(layerG, layerR->getHandle(), 3) |
| 1062 | .setPosition(layerB, 16, 16) |
| 1063 | .setLayer(layerB, mLayerZBase + 2) |
| 1064 | .apply(); |
| 1065 | break; |
| 1066 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 1067 | Transaction() |
| 1068 | .setFrame(layerR, Rect(0, 0, 32, 32)) |
| 1069 | .setFrame(layerG, Rect(8, 8, 40, 40)) |
| 1070 | .setRelativeLayer(layerG, layerR->getHandle(), 3) |
| 1071 | .setFrame(layerB, Rect(16, 16, 48, 48)) |
| 1072 | .setLayer(layerB, mLayerZBase + 2) |
| 1073 | .apply(); |
| 1074 | break; |
| 1075 | default: |
| 1076 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 1077 | } |
| 1078 | |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1079 | { |
| 1080 | SCOPED_TRACE("(layerR < layerG) < layerB"); |
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, 16, 16), Color::GREEN); |
| 1084 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); |
| 1085 | } |
| 1086 | |
| 1087 | // layerR = 4, layerG = layerR + 3, layerB = 2 |
| 1088 | Transaction().setLayer(layerR, mLayerZBase + 4).apply(); |
| 1089 | { |
| 1090 | SCOPED_TRACE("layerB < (layerR < layerG)"); |
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, 8, 8), Color::RED); |
| 1093 | shot->expectColor(Rect(8, 8, 40, 40), Color::GREEN); |
| 1094 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); |
| 1095 | } |
| 1096 | |
| 1097 | // layerR = 4, layerG = layerR - 3, layerB = 2 |
| 1098 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -3).apply(); |
| 1099 | { |
| 1100 | SCOPED_TRACE("layerB < (layerG < layerR)"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1101 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1102 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1103 | shot->expectColor(Rect(32, 32, 40, 40), Color::GREEN); |
| 1104 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); |
| 1105 | } |
| 1106 | |
| 1107 | // restore to absolute z |
| 1108 | // layerR = 4, layerG = 0, layerB = 2 |
| 1109 | Transaction().setLayer(layerG, mLayerZBase).apply(); |
| 1110 | { |
| 1111 | SCOPED_TRACE("layerG < layerB < layerR"); |
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, 32, 32), Color::RED); |
| 1114 | shot->expectColor(Rect(32, 32, 48, 48), Color::BLUE); |
| 1115 | } |
| 1116 | |
| 1117 | // layerR should not affect layerG anymore |
| 1118 | // layerR = 1, layerG = 0, layerB = 2 |
| 1119 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); |
| 1120 | { |
| 1121 | SCOPED_TRACE("layerG < layerR < layerB"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1122 | auto shot = getScreenCapture(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1123 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 1124 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); |
| 1125 | } |
| 1126 | } |
| 1127 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1128 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZGroup_BufferQueue) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1129 | ASSERT_NO_FATAL_FAILURE(setRelativeZGroupHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); |
| 1130 | } |
| 1131 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1132 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZGroup_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1133 | ASSERT_NO_FATAL_FAILURE(setRelativeZGroupHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1134 | } |
| 1135 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1136 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetRelativeZBug64572777) { |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1137 | sp<SurfaceControl> layerR; |
| 1138 | sp<SurfaceControl> layerG; |
| 1139 | |
| 1140 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1141 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1142 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1143 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1144 | |
| 1145 | Transaction() |
| 1146 | .setPosition(layerG, 16, 16) |
| 1147 | .setRelativeLayer(layerG, layerR->getHandle(), 1) |
| 1148 | .apply(); |
| 1149 | |
Robert Carr | 8724653 | 2019-02-04 15:20:26 -0800 | [diff] [blame] | 1150 | layerG.clear(); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1151 | // layerG should have been removed |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1152 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1155 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetFlagsHidden) { |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1156 | sp<SurfaceControl> layer; |
| 1157 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1158 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1159 | |
| 1160 | Transaction().setFlags(layer, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden).apply(); |
| 1161 | { |
| 1162 | SCOPED_TRACE("layer hidden"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1163 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | Transaction().setFlags(layer, 0, layer_state_t::eLayerHidden).apply(); |
| 1167 | { |
| 1168 | SCOPED_TRACE("layer shown"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1169 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1173 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetFlagsOpaque) { |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1174 | const Color translucentRed = {100, 0, 0, 100}; |
| 1175 | sp<SurfaceControl> layerR; |
| 1176 | sp<SurfaceControl> layerG; |
| 1177 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1178 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, translucentRed, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1179 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1180 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1181 | |
| 1182 | Transaction() |
| 1183 | .setLayer(layerR, mLayerZBase + 1) |
| 1184 | .setFlags(layerR, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque) |
| 1185 | .apply(); |
| 1186 | { |
| 1187 | SCOPED_TRACE("layerR opaque"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1188 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {100, 0, 0, 255}); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | Transaction().setFlags(layerR, 0, layer_state_t::eLayerOpaque).apply(); |
| 1192 | { |
| 1193 | SCOPED_TRACE("layerR translucent"); |
| 1194 | const uint8_t g = uint8_t(255 - translucentRed.a); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1195 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {100, g, 0, 255}); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1199 | TEST_P(LayerTypeTransactionTest, SetFlagsSecure) { |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1200 | sp<SurfaceControl> layer; |
| 1201 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1202 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1203 | |
| 1204 | sp<ISurfaceComposer> composer = ComposerService::getComposerService(); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 1205 | sp<GraphicBuffer> outBuffer; |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1206 | Transaction() |
| 1207 | .setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure) |
| 1208 | .apply(true); |
| 1209 | ASSERT_EQ(PERMISSION_DENIED, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1210 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1211 | |
| 1212 | Transaction().setFlags(layer, 0, layer_state_t::eLayerSecure).apply(true); |
| 1213 | ASSERT_EQ(NO_ERROR, |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1214 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); |
Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 1217 | /** RAII Wrapper around get/seteuid */ |
| 1218 | class UIDFaker { |
| 1219 | uid_t oldId; |
| 1220 | public: |
| 1221 | UIDFaker(uid_t uid) { |
| 1222 | oldId = geteuid(); |
| 1223 | seteuid(uid); |
| 1224 | } |
| 1225 | ~UIDFaker() { |
| 1226 | seteuid(oldId); |
| 1227 | } |
| 1228 | }; |
| 1229 | |
| 1230 | TEST_F(LayerTransactionTest, SetFlagsSecureEUidSystem) { |
| 1231 | sp<SurfaceControl> layer; |
| 1232 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1233 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
| 1234 | |
| 1235 | sp<ISurfaceComposer> composer = ComposerService::getComposerService(); |
| 1236 | sp<GraphicBuffer> outBuffer; |
| 1237 | Transaction() |
| 1238 | .setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure) |
| 1239 | .apply(true); |
| 1240 | ASSERT_EQ(PERMISSION_DENIED, |
| 1241 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); |
| 1242 | |
| 1243 | UIDFaker f(AID_SYSTEM); |
| 1244 | |
| 1245 | // By default the system can capture screenshots with secure layers but they |
| 1246 | // will be blacked out |
| 1247 | ASSERT_EQ(NO_ERROR, |
| 1248 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); |
| 1249 | |
| 1250 | { |
| 1251 | SCOPED_TRACE("as system"); |
| 1252 | auto shot = screenshot(); |
| 1253 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
| 1254 | } |
| 1255 | |
| 1256 | // Here we pass captureSecureLayers = true and since we are AID_SYSTEM we should be able |
| 1257 | // to receive them...we are expected to take care with the results. |
| 1258 | ASSERT_EQ(NO_ERROR, |
| 1259 | composer->captureScreen(mDisplay, &outBuffer, |
| 1260 | ui::Dataspace::V0_SRGB, ui::PixelFormat::RGBA_8888, |
| 1261 | Rect(), 0, 0, false, |
| 1262 | ISurfaceComposer::eRotateNone, true)); |
| 1263 | ScreenCapture sc(outBuffer); |
| 1264 | sc.expectColor(Rect(0, 0, 32, 32), Color::RED); |
| 1265 | } |
| 1266 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1267 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintBasic_BufferQueue) { |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1268 | const Rect top(0, 0, 32, 16); |
| 1269 | const Rect bottom(0, 16, 32, 32); |
| 1270 | sp<SurfaceControl> layer; |
| 1271 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1272 | |
| 1273 | ANativeWindow_Buffer buffer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1274 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 1275 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::TRANSPARENT)); |
| 1276 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::RED)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1277 | // setTransparentRegionHint always applies to the following buffer |
| 1278 | Transaction().setTransparentRegionHint(layer, Region(top)).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1279 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1280 | { |
| 1281 | SCOPED_TRACE("top transparent"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1282 | auto shot = getScreenCapture(); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1283 | shot->expectColor(top, Color::BLACK); |
| 1284 | shot->expectColor(bottom, Color::RED); |
| 1285 | } |
| 1286 | |
| 1287 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); |
| 1288 | { |
| 1289 | SCOPED_TRACE("transparent region hint pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1290 | auto shot = getScreenCapture(); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1291 | shot->expectColor(top, Color::BLACK); |
| 1292 | shot->expectColor(bottom, Color::RED); |
| 1293 | } |
| 1294 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1295 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); |
| 1296 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::RED)); |
| 1297 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::TRANSPARENT)); |
| 1298 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1299 | { |
| 1300 | SCOPED_TRACE("bottom transparent"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1301 | auto shot = getScreenCapture(); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1302 | shot->expectColor(top, Color::RED); |
| 1303 | shot->expectColor(bottom, Color::BLACK); |
| 1304 | } |
| 1305 | } |
| 1306 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1307 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1308 | const Rect top(0, 0, 32, 16); |
| 1309 | const Rect bottom(0, 16, 32, 32); |
| 1310 | sp<SurfaceControl> layer; |
| 1311 | ASSERT_NO_FATAL_FAILURE( |
| 1312 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1313 | |
| 1314 | sp<GraphicBuffer> buffer = |
| 1315 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 1316 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 1317 | BufferUsage::COMPOSER_OVERLAY, |
| 1318 | "test"); |
| 1319 | |
| 1320 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::TRANSPARENT)); |
| 1321 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::RED)); |
| 1322 | Transaction() |
| 1323 | .setTransparentRegionHint(layer, Region(top)) |
| 1324 | .setBuffer(layer, buffer) |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1325 | .setFrame(layer, Rect(0, 0, 32, 32)) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1326 | .apply(); |
| 1327 | { |
| 1328 | SCOPED_TRACE("top transparent"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1329 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1330 | shot->expectColor(top, Color::BLACK); |
| 1331 | shot->expectColor(bottom, Color::RED); |
| 1332 | } |
| 1333 | |
| 1334 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); |
| 1335 | { |
| 1336 | SCOPED_TRACE("transparent region hint intermediate"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1337 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1338 | shot->expectColor(top, Color::BLACK); |
| 1339 | shot->expectColor(bottom, Color::BLACK); |
| 1340 | } |
| 1341 | |
| 1342 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 1343 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 1344 | BufferUsage::COMPOSER_OVERLAY, |
| 1345 | "test"); |
| 1346 | |
| 1347 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::RED)); |
| 1348 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::TRANSPARENT)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1349 | Transaction().setBuffer(layer, buffer).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1350 | { |
| 1351 | SCOPED_TRACE("bottom transparent"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1352 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1353 | shot->expectColor(top, Color::RED); |
| 1354 | shot->expectColor(bottom, Color::BLACK); |
| 1355 | } |
| 1356 | } |
| 1357 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1358 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintOutOfBounds_BufferQueue) { |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1359 | sp<SurfaceControl> layerTransparent; |
| 1360 | sp<SurfaceControl> layerR; |
| 1361 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); |
| 1362 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); |
| 1363 | |
| 1364 | // check that transparent region hint is bound by the layer size |
| 1365 | Transaction() |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1366 | .setTransparentRegionHint(layerTransparent, Region(mDisplayRect)) |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1367 | .setPosition(layerR, 16, 16) |
| 1368 | .setLayer(layerR, mLayerZBase + 1) |
| 1369 | .apply(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1370 | ASSERT_NO_FATAL_FAILURE( |
| 1371 | fillBufferQueueLayerColor(layerTransparent, Color::TRANSPARENT, 32, 32)); |
| 1372 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layerR, Color::RED, 32, 32)); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1373 | getScreenCapture()->expectColor(Rect(16, 16, 48, 48), Color::RED); |
Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1376 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintOutOfBounds_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1377 | sp<SurfaceControl> layerTransparent; |
| 1378 | sp<SurfaceControl> layerR; |
| 1379 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); |
| 1380 | ASSERT_NO_FATAL_FAILURE( |
| 1381 | layerR = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1382 | |
| 1383 | // check that transparent region hint is bound by the layer size |
| 1384 | Transaction() |
| 1385 | .setTransparentRegionHint(layerTransparent, Region(mDisplayRect)) |
| 1386 | .setFrame(layerR, Rect(16, 16, 48, 48)) |
| 1387 | .setLayer(layerR, mLayerZBase + 1) |
| 1388 | .apply(); |
| 1389 | ASSERT_NO_FATAL_FAILURE( |
| 1390 | fillBufferQueueLayerColor(layerTransparent, Color::TRANSPARENT, 32, 32)); |
| 1391 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layerR, Color::RED, 32, 32)); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1392 | getScreenCapture()->expectColor(Rect(16, 16, 48, 48), Color::RED); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1395 | void LayerRenderTypeTransactionTest::setAlphaBasicHelper(uint32_t layerType) { |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1396 | sp<SurfaceControl> layer1; |
| 1397 | sp<SurfaceControl> layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1398 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer("test 1", 32, 32, layerType)); |
| 1399 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer("test 2", 32, 32, layerType)); |
| 1400 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer1, {64, 0, 0, 255}, 32, 32)); |
| 1401 | 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] | 1402 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1403 | switch (layerType) { |
| 1404 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 1405 | Transaction() |
| 1406 | .setAlpha(layer1, 0.25f) |
| 1407 | .setAlpha(layer2, 0.75f) |
| 1408 | .setPosition(layer2, 16, 0) |
| 1409 | .setLayer(layer2, mLayerZBase + 1) |
| 1410 | .apply(); |
| 1411 | break; |
| 1412 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 1413 | Transaction() |
| 1414 | .setAlpha(layer1, 0.25f) |
| 1415 | .setAlpha(layer2, 0.75f) |
| 1416 | .setFrame(layer1, Rect(0, 0, 32, 32)) |
| 1417 | .setFrame(layer2, Rect(16, 0, 48, 32)) |
| 1418 | .setLayer(layer2, mLayerZBase + 1) |
| 1419 | .apply(); |
| 1420 | break; |
| 1421 | default: |
| 1422 | ASSERT_FALSE(true) << "Unsupported layer type"; |
| 1423 | } |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1424 | { |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1425 | auto shot = getScreenCapture(); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1426 | uint8_t r = 16; // 64 * 0.25f |
| 1427 | uint8_t g = 48; // 64 * 0.75f |
| 1428 | shot->expectColor(Rect(0, 0, 16, 32), {r, 0, 0, 255}); |
| 1429 | shot->expectColor(Rect(32, 0, 48, 32), {0, g, 0, 255}); |
| 1430 | |
| 1431 | r /= 4; // r * (1.0f - 0.75f) |
| 1432 | shot->expectColor(Rect(16, 0, 32, 32), {r, g, 0, 255}); |
| 1433 | } |
| 1434 | } |
| 1435 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1436 | TEST_P(LayerRenderTypeTransactionTest, SetAlphaBasic_BufferQueue) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1437 | ASSERT_NO_FATAL_FAILURE(setAlphaBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); |
| 1438 | } |
| 1439 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1440 | TEST_P(LayerRenderTypeTransactionTest, SetAlphaBasic_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1441 | ASSERT_NO_FATAL_FAILURE(setAlphaBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1442 | } |
| 1443 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1444 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetAlphaClamped) { |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1445 | const Color color = {64, 0, 0, 255}; |
| 1446 | sp<SurfaceControl> layer; |
| 1447 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1448 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, color, 32, 32)); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1449 | |
| 1450 | Transaction().setAlpha(layer, 2.0f).apply(); |
| 1451 | { |
| 1452 | SCOPED_TRACE("clamped to 1.0f"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1453 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), color); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | Transaction().setAlpha(layer, -1.0f).apply(); |
| 1457 | { |
| 1458 | SCOPED_TRACE("clamped to 0.0f"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1459 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1463 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadius) { |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1464 | sp<SurfaceControl> layer; |
| 1465 | const uint8_t size = 64; |
| 1466 | const uint8_t testArea = 4; |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1467 | const float cornerRadius = 20.0f; |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1468 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", size, size)); |
| 1469 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, size, size)); |
| 1470 | |
| 1471 | Transaction() |
| 1472 | .setCornerRadius(layer, cornerRadius) |
| 1473 | .apply(); |
| 1474 | { |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1475 | const uint8_t bottom = size - 1; |
| 1476 | const uint8_t right = size - 1; |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1477 | auto shot = getScreenCapture(); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1478 | // Transparent corners |
| 1479 | shot->expectColor(Rect(0, 0, testArea, testArea), Color::BLACK); |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1480 | shot->expectColor(Rect(size - testArea, 0, right, testArea), Color::BLACK); |
| 1481 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); |
| 1482 | shot->expectColor(Rect(size - testArea, bottom - testArea, right, bottom), Color::BLACK); |
| 1483 | } |
| 1484 | } |
| 1485 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1486 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusChildCrop) { |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1487 | sp<SurfaceControl> parent; |
| 1488 | sp<SurfaceControl> child; |
| 1489 | const uint8_t size = 64; |
| 1490 | const uint8_t testArea = 4; |
| 1491 | const float cornerRadius = 20.0f; |
| 1492 | ASSERT_NO_FATAL_FAILURE(parent = createLayer("parent", size, size)); |
| 1493 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(parent, Color::RED, size, size)); |
| 1494 | ASSERT_NO_FATAL_FAILURE(child = createLayer("child", size, size / 2)); |
| 1495 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(child, Color::GREEN, size, size / 2)); |
| 1496 | |
| 1497 | Transaction() |
| 1498 | .setCornerRadius(parent, cornerRadius) |
| 1499 | .reparent(child, parent->getHandle()) |
| 1500 | .setPosition(child, 0, size / 2) |
| 1501 | .apply(); |
| 1502 | { |
| 1503 | const uint8_t bottom = size - 1; |
| 1504 | const uint8_t right = size - 1; |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1505 | auto shot = getScreenCapture(); |
Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1506 | // Top edge of child should not have rounded corners because it's translated in the parent |
| 1507 | shot->expectColor(Rect(0, size / 2, right, static_cast<int>(bottom - cornerRadius)), |
| 1508 | Color::GREEN); |
| 1509 | // But bottom edges should have been clipped according to parent bounds |
| 1510 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); |
| 1511 | shot->expectColor(Rect(right - testArea, bottom - testArea, right, bottom), Color::BLACK); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1512 | } |
| 1513 | } |
| 1514 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1515 | TEST_P(LayerRenderTypeTransactionTest, SetColorBasic) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1516 | sp<SurfaceControl> bufferLayer; |
| 1517 | sp<SurfaceControl> colorLayer; |
| 1518 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1519 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1520 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 1521 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 1522 | ISurfaceComposerClient::eFXSurfaceColor)); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1523 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1524 | Transaction() |
| 1525 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 1526 | .setLayer(colorLayer, mLayerZBase + 1) |
| 1527 | .apply(); |
| 1528 | |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1529 | { |
| 1530 | SCOPED_TRACE("default color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1531 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1535 | const Color expected = {15, 51, 85, 255}; |
| 1536 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 1537 | // channel) should be less than one |
| 1538 | const uint8_t tolerance = 1; |
| 1539 | Transaction().setColor(colorLayer, color).apply(); |
| 1540 | { |
| 1541 | SCOPED_TRACE("new color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1542 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expected, tolerance); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1546 | // RED: Color layer base color and BufferQueueLayer/BufferStateLayer fill |
| 1547 | // BLUE: prior background color |
| 1548 | // GREEN: final background color |
| 1549 | // BLACK: no color or fill |
| 1550 | void LayerRenderTypeTransactionTest::setBackgroundColorHelper(uint32_t layerType, bool priorColor, |
| 1551 | bool bufferFill, float alpha, |
| 1552 | Color finalColor) { |
| 1553 | sp<SurfaceControl> layer; |
| 1554 | int32_t width = 500; |
| 1555 | int32_t height = 500; |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1556 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1557 | Color fillColor = Color::RED; |
| 1558 | Color priorBgColor = Color::BLUE; |
| 1559 | Color expectedColor = Color::BLACK; |
| 1560 | switch (layerType) { |
| 1561 | case ISurfaceComposerClient::eFXSurfaceColor: |
| 1562 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 0, 0, layerType)); |
| 1563 | Transaction() |
| 1564 | .setCrop_legacy(layer, Rect(0, 0, width, height)) |
| 1565 | .setColor(layer, half3(1.0f, 0, 0)) |
| 1566 | .apply(); |
| 1567 | expectedColor = fillColor; |
| 1568 | break; |
| 1569 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: |
| 1570 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", width, height)); |
| 1571 | if (bufferFill) { |
| 1572 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, fillColor, width, height)); |
| 1573 | expectedColor = fillColor; |
| 1574 | } |
| 1575 | Transaction().setCrop_legacy(layer, Rect(0, 0, width, height)).apply(); |
| 1576 | break; |
| 1577 | case ISurfaceComposerClient::eFXSurfaceBufferState: |
| 1578 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", width, height, layerType)); |
| 1579 | if (bufferFill) { |
| 1580 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, fillColor, width, height)); |
| 1581 | expectedColor = fillColor; |
| 1582 | } |
| 1583 | Transaction().setFrame(layer, Rect(0, 0, width, height)).apply(); |
| 1584 | break; |
| 1585 | default: |
| 1586 | GTEST_FAIL() << "Unknown layer type in setBackgroundColorHelper"; |
| 1587 | return; |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1588 | } |
| 1589 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1590 | if (priorColor && layerType != ISurfaceComposerClient::eFXSurfaceColor) { |
| 1591 | Transaction() |
| 1592 | .setBackgroundColor(layer, half3(0, 0, 1.0f), 1.0f, ui::Dataspace::UNKNOWN) |
| 1593 | .apply(); |
| 1594 | if (!bufferFill) { |
| 1595 | expectedColor = priorBgColor; |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | { |
| 1600 | SCOPED_TRACE("default before setting background color layer"); |
| 1601 | screenshot()->expectColor(Rect(0, 0, width, height), expectedColor); |
| 1602 | } |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1603 | Transaction() |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1604 | .setBackgroundColor(layer, half3(0, 1.0f, 0), alpha, ui::Dataspace::UNKNOWN) |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1605 | .apply(); |
| 1606 | |
| 1607 | { |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1608 | auto shot = screenshot(); |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1609 | shot->expectColor(Rect(0, 0, width, height), finalColor); |
| 1610 | shot->expectBorder(Rect(0, 0, width, height), Color::BLACK); |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1611 | } |
| 1612 | } |
| 1613 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1614 | TEST_P(LayerRenderTypeTransactionTest, SetBackgroundColor_Color_NoEffect) { |
| 1615 | bool priorColor = false; |
| 1616 | bool bufferFill = false; |
| 1617 | float alpha = 1.0f; |
| 1618 | Color finalColor = Color::RED; |
| 1619 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceColor, |
| 1620 | priorColor, bufferFill, alpha, finalColor)); |
| 1621 | } |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1622 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1623 | TEST_P(LayerRenderTypeTransactionTest, |
| 1624 | SetBackgroundColor_BufferQueue_BufferFill_NoPriorColor_Basic) { |
| 1625 | bool priorColor = false; |
| 1626 | bool bufferFill = true; |
| 1627 | float alpha = 1.0f; |
| 1628 | Color finalColor = Color::RED; |
| 1629 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1630 | priorColor, bufferFill, alpha, finalColor)); |
| 1631 | } |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1632 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1633 | TEST_P(LayerRenderTypeTransactionTest, |
| 1634 | SetBackgroundColor_BufferQueue_NoBufferFill_NoPriorColor_Basic) { |
| 1635 | bool priorColor = false; |
| 1636 | bool bufferFill = false; |
| 1637 | float alpha = 1.0f; |
| 1638 | Color finalColor = Color::GREEN; |
| 1639 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1640 | priorColor, bufferFill, alpha, finalColor)); |
| 1641 | } |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1642 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1643 | TEST_P(LayerRenderTypeTransactionTest, SetBackgroundColor_BufferQueue_BufferFill_PriorColor_Basic) { |
| 1644 | bool priorColor = true; |
| 1645 | bool bufferFill = true; |
| 1646 | float alpha = 1.0f; |
| 1647 | Color finalColor = Color::RED; |
| 1648 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1649 | priorColor, bufferFill, alpha, finalColor)); |
| 1650 | } |
| 1651 | |
| 1652 | TEST_P(LayerRenderTypeTransactionTest, |
| 1653 | SetBackgroundColor_BufferQueue_NoBufferFill_PriorColor_Basic) { |
| 1654 | bool priorColor = true; |
| 1655 | bool bufferFill = false; |
| 1656 | float alpha = 1.0f; |
| 1657 | Color finalColor = Color::GREEN; |
| 1658 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1659 | priorColor, bufferFill, alpha, finalColor)); |
| 1660 | } |
| 1661 | TEST_P(LayerRenderTypeTransactionTest, |
| 1662 | SetBackgroundColor_BufferQueue_NoPriorColor_ZeroAlpha_NoEffect) { |
| 1663 | bool priorColor = false; |
| 1664 | bool bufferFill = false; |
| 1665 | float alpha = 0; |
| 1666 | Color finalColor = Color::BLACK; |
| 1667 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1668 | priorColor, bufferFill, alpha, finalColor)); |
| 1669 | } |
| 1670 | |
| 1671 | TEST_P(LayerRenderTypeTransactionTest, |
| 1672 | SetBackgroundColor_BufferQueue_PriorColor_ZeroAlpha_DeleteBackground) { |
| 1673 | bool priorColor = true; |
| 1674 | bool bufferFill = false; |
| 1675 | float alpha = 0; |
| 1676 | Color finalColor = Color::BLACK; |
| 1677 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, |
| 1678 | priorColor, bufferFill, alpha, finalColor)); |
| 1679 | } |
| 1680 | |
| 1681 | TEST_P(LayerRenderTypeTransactionTest, |
| 1682 | SetBackgroundColor_BufferState_BufferFill_NoPriorColor_Basic) { |
| 1683 | bool priorColor = false; |
| 1684 | bool bufferFill = true; |
| 1685 | float alpha = 1.0f; |
| 1686 | Color finalColor = Color::RED; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1687 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1688 | priorColor, bufferFill, alpha, finalColor)); |
| 1689 | } |
| 1690 | |
| 1691 | TEST_P(LayerRenderTypeTransactionTest, |
| 1692 | SetBackgroundColor_BufferState_NoBufferFill_NoPriorColor_Basic) { |
| 1693 | bool priorColor = false; |
| 1694 | bool bufferFill = false; |
| 1695 | float alpha = 1.0f; |
| 1696 | Color finalColor = Color::GREEN; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1697 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1698 | priorColor, bufferFill, alpha, finalColor)); |
| 1699 | } |
| 1700 | |
| 1701 | TEST_P(LayerRenderTypeTransactionTest, |
| 1702 | SetBackgroundColor_BufferState_NoBufferFill_PriorColor_Basic) { |
| 1703 | bool priorColor = true; |
| 1704 | bool bufferFill = false; |
| 1705 | float alpha = 1.0f; |
| 1706 | Color finalColor = Color::GREEN; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1707 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1708 | priorColor, bufferFill, alpha, finalColor)); |
| 1709 | } |
| 1710 | |
| 1711 | TEST_P(LayerRenderTypeTransactionTest, |
| 1712 | SetBackgroundColor_BufferState_NoPriorColor_ZeroAlpha_NoEffect) { |
| 1713 | bool priorColor = false; |
| 1714 | bool bufferFill = false; |
| 1715 | float alpha = 0; |
| 1716 | Color finalColor = Color::BLACK; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1717 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1718 | priorColor, bufferFill, alpha, finalColor)); |
| 1719 | } |
| 1720 | |
| 1721 | TEST_P(LayerRenderTypeTransactionTest, |
| 1722 | SetBackgroundColor_BufferState_PriorColor_ZeroAlpha_DeleteBackground) { |
| 1723 | bool priorColor = true; |
| 1724 | bool bufferFill = false; |
| 1725 | float alpha = 0; |
| 1726 | Color finalColor = Color::BLACK; |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1727 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1728 | priorColor, bufferFill, alpha, finalColor)); |
Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1729 | } |
| 1730 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1731 | TEST_P(LayerRenderTypeTransactionTest, SetColorClamped) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1732 | sp<SurfaceControl> colorLayer; |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1733 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 1734 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 1735 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 1736 | Transaction() |
| 1737 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 1738 | .setColor(colorLayer, half3(2.0f, -1.0f, 0.0f)) |
| 1739 | .apply(); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1740 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1741 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1744 | TEST_P(LayerRenderTypeTransactionTest, SetColorWithAlpha) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1745 | sp<SurfaceControl> bufferLayer; |
| 1746 | sp<SurfaceControl> colorLayer; |
| 1747 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1748 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1749 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 1750 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 1751 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 1752 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1753 | |
| 1754 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1755 | const float alpha = 0.25f; |
| 1756 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); |
| 1757 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 1758 | // channel) should be less than one |
| 1759 | const uint8_t tolerance = 1; |
| 1760 | Transaction() |
| 1761 | .setColor(colorLayer, color) |
| 1762 | .setAlpha(colorLayer, alpha) |
| 1763 | .setLayer(colorLayer, mLayerZBase + 1) |
| 1764 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1765 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, |
| 1766 | tolerance); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1769 | TEST_P(LayerRenderTypeTransactionTest, SetColorWithParentAlpha_Bug74220420) { |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1770 | sp<SurfaceControl> bufferLayer; |
| 1771 | sp<SurfaceControl> parentLayer; |
| 1772 | sp<SurfaceControl> colorLayer; |
| 1773 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); |
| 1774 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parentWithAlpha", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1775 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1776 | ASSERT_NO_FATAL_FAILURE(colorLayer = createLayer("childWithColor", 0 /* buffer width */, |
| 1777 | 0 /* buffer height */, |
| 1778 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 1779 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1780 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); |
| 1781 | const float alpha = 0.25f; |
| 1782 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); |
| 1783 | // this is handwavy, but the precision loss scaled by 255 (8-bit per |
| 1784 | // channel) should be less than one |
| 1785 | const uint8_t tolerance = 1; |
| 1786 | Transaction() |
| 1787 | .reparent(colorLayer, parentLayer->getHandle()) |
| 1788 | .setColor(colorLayer, color) |
| 1789 | .setAlpha(parentLayer, alpha) |
| 1790 | .setLayer(parentLayer, mLayerZBase + 1) |
| 1791 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1792 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, |
| 1793 | tolerance); |
Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1796 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetColorWithBuffer) { |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1797 | sp<SurfaceControl> bufferLayer; |
| 1798 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1799 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED, 32, 32)); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1800 | |
| 1801 | // color is ignored |
| 1802 | Transaction().setColor(bufferLayer, half3(0.0f, 1.0f, 0.0f)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1803 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1806 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetLayerStackBasic) { |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1807 | sp<SurfaceControl> layer; |
| 1808 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1809 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1810 | |
| 1811 | Transaction().setLayerStack(layer, mDisplayLayerStack + 1).apply(); |
| 1812 | { |
| 1813 | SCOPED_TRACE("non-existing layer stack"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1814 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | Transaction().setLayerStack(layer, mDisplayLayerStack).apply(); |
| 1818 | { |
| 1819 | SCOPED_TRACE("original layer stack"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1820 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1821 | } |
| 1822 | } |
| 1823 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1824 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixBasic_BufferQueue) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1825 | sp<SurfaceControl> layer; |
| 1826 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1827 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1828 | Color::BLUE, Color::WHITE)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1829 | |
| 1830 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 0, 0).apply(); |
| 1831 | { |
| 1832 | SCOPED_TRACE("IDENTITY"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1833 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1834 | Color::BLUE, Color::WHITE); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 32, 0).apply(); |
| 1838 | { |
| 1839 | SCOPED_TRACE("FLIP_H"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1840 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, |
| 1841 | Color::WHITE, Color::BLUE); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).setPosition(layer, 0, 32).apply(); |
| 1845 | { |
| 1846 | SCOPED_TRACE("FLIP_V"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1847 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, |
| 1848 | Color::RED, Color::GREEN); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).setPosition(layer, 32, 0).apply(); |
| 1852 | { |
| 1853 | SCOPED_TRACE("ROT_90"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1854 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, |
| 1855 | Color::WHITE, Color::GREEN); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setPosition(layer, 0, 0).apply(); |
| 1859 | { |
| 1860 | SCOPED_TRACE("SCALE"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1861 | getScreenCapture()->expectQuadrant(Rect(0, 0, 64, 64), Color::RED, Color::GREEN, |
| 1862 | Color::BLUE, Color::WHITE, true /* filtered */); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1863 | } |
| 1864 | } |
| 1865 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1866 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixBasic_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1867 | sp<SurfaceControl> layer; |
| 1868 | ASSERT_NO_FATAL_FAILURE( |
| 1869 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 1870 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1871 | Color::BLUE, Color::WHITE)); |
| 1872 | |
| 1873 | Transaction() |
| 1874 | .setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f) |
| 1875 | .setFrame(layer, Rect(0, 0, 32, 32)) |
| 1876 | .apply(); |
| 1877 | { |
| 1878 | SCOPED_TRACE("IDENTITY"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1879 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1880 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).apply(); |
| 1884 | { |
| 1885 | SCOPED_TRACE("FLIP_H"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1886 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1887 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).apply(); |
| 1891 | { |
| 1892 | SCOPED_TRACE("FLIP_V"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1893 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1894 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).apply(); |
| 1898 | { |
| 1899 | SCOPED_TRACE("ROT_90"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1900 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1901 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).apply(); |
| 1905 | { |
| 1906 | SCOPED_TRACE("SCALE"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1907 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, |
| 1908 | Color::BLUE, Color::WHITE); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1909 | } |
| 1910 | } |
| 1911 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1912 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixRot45_BufferQueue) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1913 | sp<SurfaceControl> layer; |
| 1914 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1915 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1916 | Color::BLUE, Color::WHITE)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1917 | |
| 1918 | const float rot = M_SQRT1_2; // 45 degrees |
| 1919 | const float trans = M_SQRT2 * 16.0f; |
| 1920 | Transaction().setMatrix(layer, rot, rot, -rot, rot).setPosition(layer, trans, 0).apply(); |
| 1921 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1922 | auto shot = getScreenCapture(); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1923 | // check a 8x8 region inside each color |
| 1924 | auto get8x8Rect = [](int32_t centerX, int32_t centerY) { |
| 1925 | const int32_t halfL = 4; |
| 1926 | return Rect(centerX - halfL, centerY - halfL, centerX + halfL, centerY + halfL); |
| 1927 | }; |
| 1928 | const int32_t unit = int32_t(trans / 2); |
| 1929 | shot->expectColor(get8x8Rect(2 * unit, 1 * unit), Color::RED); |
| 1930 | shot->expectColor(get8x8Rect(3 * unit, 2 * unit), Color::GREEN); |
| 1931 | shot->expectColor(get8x8Rect(1 * unit, 2 * unit), Color::BLUE); |
| 1932 | shot->expectColor(get8x8Rect(2 * unit, 3 * unit), Color::WHITE); |
| 1933 | } |
| 1934 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1935 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixWithResize_BufferQueue) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1936 | sp<SurfaceControl> layer; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1937 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1938 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1939 | |
| 1940 | // setMatrix is applied after any pending resize, unlike setPosition |
| 1941 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setSize(layer, 64, 64).apply(); |
| 1942 | { |
| 1943 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1944 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1945 | const Rect rect(0, 0, 32, 32); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1946 | shot->expectColor(rect, Color::RED); |
| 1947 | shot->expectBorder(rect, Color::BLACK); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1950 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1951 | { |
| 1952 | SCOPED_TRACE("resize applied"); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1953 | const Rect rect(0, 0, 128, 128); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1954 | getScreenCapture()->expectColor(rect, Color::RED); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1955 | } |
| 1956 | } |
| 1957 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1958 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixWithScaleToWindow_BufferQueue) { |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1959 | sp<SurfaceControl> layer; |
| 1960 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1961 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1962 | |
| 1963 | // setMatrix is immediate with SCALE_TO_WINDOW, unlike setPosition |
| 1964 | Transaction() |
| 1965 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
| 1966 | .setSize(layer, 64, 64) |
| 1967 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1968 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1969 | getScreenCapture()->expectColor(Rect(0, 0, 128, 128), Color::RED); |
Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1972 | TEST_P(LayerRenderTypeTransactionTest, SetOverrideScalingModeBasic_BufferQueue) { |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1973 | sp<SurfaceControl> layer; |
| 1974 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1975 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 1976 | Color::BLUE, Color::WHITE)); |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1977 | |
| 1978 | // XXX SCALE_CROP is not respected; calling setSize and |
| 1979 | // setOverrideScalingMode in separate transactions does not work |
| 1980 | // (b/69315456) |
| 1981 | Transaction() |
| 1982 | .setSize(layer, 64, 16) |
| 1983 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 1984 | .apply(); |
| 1985 | { |
| 1986 | SCOPED_TRACE("SCALE_TO_WINDOW"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1987 | getScreenCapture()->expectQuadrant(Rect(0, 0, 64, 16), Color::RED, Color::GREEN, |
| 1988 | Color::BLUE, Color::WHITE, true /* filtered */); |
Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1989 | } |
| 1990 | } |
| 1991 | |
Dan Stoza | 000dd01 | 2018-08-01 13:31:52 -0700 | [diff] [blame] | 1992 | TEST_P(LayerTypeTransactionTest, RefreshRateIsInitialized) { |
| 1993 | sp<SurfaceControl> layer; |
| 1994 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 1995 | |
| 1996 | sp<IBinder> handle = layer->getHandle(); |
| 1997 | ASSERT_TRUE(handle != nullptr); |
| 1998 | |
| 1999 | FrameStats frameStats; |
| 2000 | mClient->getLayerFrameStats(handle, &frameStats); |
| 2001 | |
| 2002 | ASSERT_GT(frameStats.refreshPeriodNano, static_cast<nsecs_t>(0)); |
| 2003 | } |
| 2004 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2005 | TEST_P(LayerRenderTypeTransactionTest, SetCropBasic_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2006 | sp<SurfaceControl> layer; |
| 2007 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2008 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2009 | const Rect crop(8, 8, 24, 24); |
| 2010 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2011 | Transaction().setCrop_legacy(layer, crop).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2012 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2013 | shot->expectColor(crop, Color::RED); |
| 2014 | shot->expectBorder(crop, Color::BLACK); |
| 2015 | } |
| 2016 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2017 | TEST_P(LayerRenderTypeTransactionTest, SetCropBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2018 | sp<SurfaceControl> layer; |
| 2019 | ASSERT_NO_FATAL_FAILURE( |
| 2020 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2021 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2022 | const Rect crop(8, 8, 24, 24); |
| 2023 | |
| 2024 | Transaction().setCrop(layer, crop).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2025 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2026 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2027 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2030 | TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2031 | sp<SurfaceControl> layer; |
| 2032 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2033 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2034 | |
| 2035 | { |
| 2036 | SCOPED_TRACE("empty rect"); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2037 | Transaction().setCrop_legacy(layer, Rect(8, 8, 8, 8)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2038 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | { |
| 2042 | SCOPED_TRACE("negative rect"); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2043 | Transaction().setCrop_legacy(layer, Rect(8, 8, 0, 0)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2044 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2045 | } |
| 2046 | } |
| 2047 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2048 | TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2049 | sp<SurfaceControl> layer; |
| 2050 | ASSERT_NO_FATAL_FAILURE( |
| 2051 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2052 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2053 | |
| 2054 | { |
| 2055 | SCOPED_TRACE("empty rect"); |
| 2056 | Transaction().setCrop(layer, Rect(8, 8, 8, 8)).apply(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2057 | getScreenCapture()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | { |
| 2061 | SCOPED_TRACE("negative rect"); |
| 2062 | Transaction().setCrop(layer, Rect(8, 8, 0, 0)).apply(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2063 | getScreenCapture()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2064 | } |
| 2065 | } |
| 2066 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2067 | TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2068 | sp<SurfaceControl> layer; |
| 2069 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2070 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2071 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2072 | Transaction().setCrop_legacy(layer, Rect(-128, -64, 128, 64)).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(Rect(0, 0, 32, 32), Color::RED); |
| 2075 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2076 | } |
| 2077 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2078 | TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferState) { |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2079 | sp<SurfaceControl> layer; |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2080 | ASSERT_NO_FATAL_FAILURE( |
| 2081 | layer = createLayer("test", 32, 64, ISurfaceComposerClient::eFXSurfaceBufferState)); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2082 | sp<GraphicBuffer> buffer = |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2083 | new GraphicBuffer(32, 64, PIXEL_FORMAT_RGBA_8888, 1, |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2084 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2085 | BufferUsage::COMPOSER_OVERLAY, |
| 2086 | "test"); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2087 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 16), Color::BLUE); |
| 2088 | fillGraphicBufferColor(buffer, Rect(0, 16, 32, 64), Color::RED); |
| 2089 | |
| 2090 | Transaction().setFrame(layer, Rect(0, 0, 64, 64)).apply(); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2091 | |
| 2092 | Transaction().setBuffer(layer, buffer).apply(); |
| 2093 | |
| 2094 | // Partially out of bounds in the negative (upper left) direction |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2095 | Transaction().setCrop(layer, Rect(-128, -128, 32, 16)).apply(); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2096 | { |
| 2097 | SCOPED_TRACE("out of bounds, negative (upper left) direction"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2098 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2099 | shot->expectColor(Rect(0, 0, 64, 64), Color::BLUE); |
| 2100 | shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | // Partially out of bounds in the positive (lower right) direction |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2104 | Transaction().setCrop(layer, Rect(0, 16, 128, 128)).apply(); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2105 | { |
| 2106 | SCOPED_TRACE("out of bounds, positive (lower right) direction"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2107 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2108 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 2109 | shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | // Fully out of buffer space bounds |
| 2113 | Transaction().setCrop(layer, Rect(-128, -128, -1, -1)).apply(); |
| 2114 | { |
| 2115 | SCOPED_TRACE("Fully out of bounds"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2116 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2117 | shot->expectColor(Rect(0, 0, 64, 16), Color::BLUE); |
| 2118 | shot->expectColor(Rect(0, 16, 64, 64), Color::RED); |
| 2119 | shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK); |
Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2120 | } |
| 2121 | } |
| 2122 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2123 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithTranslation_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2124 | sp<SurfaceControl> layer; |
| 2125 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2126 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2127 | |
| 2128 | const Point position(32, 32); |
| 2129 | const Rect crop(8, 8, 24, 24); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2130 | Transaction().setPosition(layer, position.x, position.y).setCrop_legacy(layer, crop).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2131 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2132 | shot->expectColor(crop + position, Color::RED); |
| 2133 | shot->expectBorder(crop + position, Color::BLACK); |
| 2134 | } |
| 2135 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2136 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithTranslation_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2137 | sp<SurfaceControl> layer; |
| 2138 | ASSERT_NO_FATAL_FAILURE( |
| 2139 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2140 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2141 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2142 | const Rect frame(32, 32, 64, 64); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2143 | const Rect crop(8, 8, 24, 24); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2144 | Transaction().setFrame(layer, frame).setCrop(layer, crop).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2145 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2146 | shot->expectColor(frame, Color::RED); |
| 2147 | shot->expectBorder(frame, Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2150 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithScale_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2151 | sp<SurfaceControl> layer; |
| 2152 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2153 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2154 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2155 | // crop_legacy is affected by matrix |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2156 | Transaction() |
| 2157 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2158 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2159 | .apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2160 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2161 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 2162 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); |
| 2163 | } |
| 2164 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2165 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithResize_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2166 | sp<SurfaceControl> layer; |
| 2167 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2168 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2169 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2170 | // setCrop_legacy is applied immediately by default, with or without resize pending |
| 2171 | 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] | 2172 | { |
| 2173 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2174 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2175 | shot->expectColor(Rect(8, 8, 24, 24), Color::RED); |
| 2176 | shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK); |
| 2177 | } |
| 2178 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2179 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2180 | { |
| 2181 | SCOPED_TRACE("resize applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2182 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2183 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); |
| 2184 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); |
| 2185 | } |
| 2186 | } |
| 2187 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2188 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithNextResize_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2189 | sp<SurfaceControl> layer; |
| 2190 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2191 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2192 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2193 | // request setCrop_legacy to be applied with the next resize |
| 2194 | Transaction() |
| 2195 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) |
| 2196 | .setGeometryAppliesWithResize(layer) |
| 2197 | .apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2198 | { |
| 2199 | SCOPED_TRACE("waiting for next resize"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2200 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2203 | Transaction().setCrop_legacy(layer, Rect(4, 4, 12, 12)).apply(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2204 | { |
| 2205 | SCOPED_TRACE("pending crop modified"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2206 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | Transaction().setSize(layer, 16, 16).apply(); |
| 2210 | { |
| 2211 | SCOPED_TRACE("resize pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2212 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | // finally resize |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2216 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2217 | { |
| 2218 | SCOPED_TRACE("new crop applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2219 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2220 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 2221 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 2222 | } |
| 2223 | } |
| 2224 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2225 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithNextResizeScaleToWindow_BufferQueue) { |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2226 | sp<SurfaceControl> layer; |
| 2227 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2228 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2229 | |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2230 | // setCrop_legacy is not immediate even with SCALE_TO_WINDOW override |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2231 | Transaction() |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2232 | .setCrop_legacy(layer, Rect(4, 4, 12, 12)) |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2233 | .setSize(layer, 16, 16) |
| 2234 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) |
| 2235 | .setGeometryAppliesWithResize(layer) |
| 2236 | .apply(); |
| 2237 | { |
| 2238 | SCOPED_TRACE("new crop pending"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2239 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2240 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); |
| 2241 | shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK); |
| 2242 | } |
| 2243 | |
| 2244 | // XXX crop is never latched without other geometry change (b/69315677) |
| 2245 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2246 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2247 | Transaction().setPosition(layer, 0, 0).apply(); |
| 2248 | { |
| 2249 | SCOPED_TRACE("new crop applied"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2250 | auto shot = getScreenCapture(); |
Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2251 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); |
| 2252 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); |
| 2253 | } |
| 2254 | } |
| 2255 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2256 | TEST_P(LayerRenderTypeTransactionTest, SetFrameBasic_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2257 | sp<SurfaceControl> layer; |
| 2258 | ASSERT_NO_FATAL_FAILURE( |
| 2259 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2260 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2261 | const Rect frame(8, 8, 24, 24); |
| 2262 | |
| 2263 | Transaction().setFrame(layer, frame).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2264 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2265 | shot->expectColor(frame, Color::RED); |
| 2266 | shot->expectBorder(frame, Color::BLACK); |
| 2267 | } |
| 2268 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2269 | TEST_P(LayerRenderTypeTransactionTest, SetFrameEmpty_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2270 | sp<SurfaceControl> layer; |
| 2271 | ASSERT_NO_FATAL_FAILURE( |
| 2272 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2273 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2274 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2275 | { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2276 | SCOPED_TRACE("empty rect"); |
| 2277 | Transaction().setFrame(layer, Rect(8, 8, 8, 8)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2278 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2281 | { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2282 | SCOPED_TRACE("negative rect"); |
| 2283 | Transaction().setFrame(layer, Rect(8, 8, 0, 0)).apply(); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2284 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2285 | } |
| 2286 | } |
| 2287 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2288 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultParentless_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2289 | sp<SurfaceControl> layer; |
| 2290 | ASSERT_NO_FATAL_FAILURE( |
| 2291 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2292 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 10, 10)); |
| 2293 | |
| 2294 | // 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] | 2295 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2296 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2297 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2300 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultBSParent_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2301 | sp<SurfaceControl> parent, child; |
| 2302 | ASSERT_NO_FATAL_FAILURE( |
| 2303 | parent = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2304 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(parent, Color::RED, 32, 32)); |
| 2305 | Transaction().setFrame(parent, Rect(0, 0, 32, 32)).apply(); |
| 2306 | |
| 2307 | ASSERT_NO_FATAL_FAILURE( |
| 2308 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2309 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); |
| 2310 | |
| 2311 | Transaction().reparent(child, parent->getHandle()).apply(); |
| 2312 | |
| 2313 | // A layer will default to the frame of its parent |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2314 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2315 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 2316 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2317 | } |
| 2318 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2319 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultBQParent_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2320 | sp<SurfaceControl> parent, child; |
| 2321 | ASSERT_NO_FATAL_FAILURE(parent = createLayer("test", 32, 32)); |
| 2322 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(parent, Color::RED, 32, 32)); |
| 2323 | |
| 2324 | ASSERT_NO_FATAL_FAILURE( |
| 2325 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2326 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); |
| 2327 | |
| 2328 | Transaction().reparent(child, parent->getHandle()).apply(); |
| 2329 | |
| 2330 | // A layer will default to the frame of its parent |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2331 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2332 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 2333 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2334 | } |
| 2335 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2336 | TEST_P(LayerRenderTypeTransactionTest, SetFrameUpdate_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2337 | sp<SurfaceControl> layer; |
| 2338 | ASSERT_NO_FATAL_FAILURE( |
| 2339 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2340 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2341 | Transaction().setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 2342 | |
| 2343 | std::this_thread::sleep_for(500ms); |
| 2344 | |
| 2345 | Transaction().setFrame(layer, Rect(16, 16, 48, 48)).apply(); |
| 2346 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2347 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2348 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); |
| 2349 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); |
| 2350 | } |
| 2351 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2352 | TEST_P(LayerRenderTypeTransactionTest, SetFrameOutsideBounds_BufferState) { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2353 | sp<SurfaceControl> parent, child; |
| 2354 | ASSERT_NO_FATAL_FAILURE( |
| 2355 | parent = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2356 | ASSERT_NO_FATAL_FAILURE( |
| 2357 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2358 | Transaction().reparent(child, parent->getHandle()).apply(); |
| 2359 | |
| 2360 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(parent, Color::RED, 32, 32)); |
| 2361 | Transaction().setFrame(parent, Rect(0, 0, 32, 32)).apply(); |
| 2362 | |
| 2363 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); |
| 2364 | Transaction().setFrame(child, Rect(0, 16, 32, 32)).apply(); |
| 2365 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2366 | auto shot = getScreenCapture(); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2367 | shot->expectColor(Rect(0, 0, 32, 16), Color::RED); |
| 2368 | shot->expectColor(Rect(0, 16, 32, 32), Color::BLUE); |
| 2369 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); |
| 2370 | } |
| 2371 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2372 | TEST_P(LayerRenderTypeTransactionTest, SetBufferBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2373 | sp<SurfaceControl> layer; |
| 2374 | ASSERT_NO_FATAL_FAILURE( |
| 2375 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2376 | |
| 2377 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2378 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2379 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2380 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2381 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2384 | TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleBuffers_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2385 | sp<SurfaceControl> layer; |
| 2386 | ASSERT_NO_FATAL_FAILURE( |
| 2387 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2388 | |
| 2389 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2390 | |
| 2391 | { |
| 2392 | SCOPED_TRACE("set buffer 1"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2393 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2394 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2395 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::BLUE, 32, 32)); |
| 2399 | |
| 2400 | { |
| 2401 | SCOPED_TRACE("set buffer 2"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2402 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2403 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLUE); |
| 2404 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); |
| 2408 | |
| 2409 | { |
| 2410 | SCOPED_TRACE("set buffer 3"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2411 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2412 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2413 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2414 | } |
| 2415 | } |
| 2416 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2417 | TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleLayers_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2418 | sp<SurfaceControl> layer1; |
| 2419 | ASSERT_NO_FATAL_FAILURE( |
| 2420 | layer1 = createLayer("test", 64, 64, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2421 | |
| 2422 | sp<SurfaceControl> layer2; |
| 2423 | ASSERT_NO_FATAL_FAILURE( |
| 2424 | layer2 = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2425 | |
| 2426 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::RED, 64, 64)); |
| 2427 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2428 | Transaction().setFrame(layer1, Rect(0, 0, 64, 64)).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2429 | { |
| 2430 | SCOPED_TRACE("set layer 1 buffer red"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2431 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2432 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); |
| 2433 | } |
| 2434 | |
| 2435 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::BLUE, 32, 32)); |
| 2436 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2437 | Transaction().setFrame(layer2, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2438 | { |
| 2439 | SCOPED_TRACE("set layer 2 buffer blue"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2440 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2441 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 2442 | shot->expectColor(Rect(0, 32, 64, 64), Color::RED); |
| 2443 | shot->expectColor(Rect(0, 32, 32, 64), Color::RED); |
| 2444 | } |
| 2445 | |
| 2446 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::GREEN, 64, 64)); |
| 2447 | { |
| 2448 | SCOPED_TRACE("set layer 1 buffer green"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2449 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2450 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); |
| 2451 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); |
| 2452 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); |
| 2453 | } |
| 2454 | |
| 2455 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::WHITE, 32, 32)); |
| 2456 | |
| 2457 | { |
| 2458 | SCOPED_TRACE("set layer 2 buffer white"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2459 | auto shot = getScreenCapture(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2460 | shot->expectColor(Rect(0, 0, 32, 32), Color::WHITE); |
| 2461 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); |
| 2462 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); |
| 2463 | } |
| 2464 | } |
| 2465 | |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 2466 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_BufferState) { |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2467 | sp<SurfaceControl> layer; |
| 2468 | ASSERT_NO_FATAL_FAILURE( |
| 2469 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2470 | |
| 2471 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; |
| 2472 | |
| 2473 | std::array<sp<GraphicBuffer>, 10> buffers; |
| 2474 | |
| 2475 | size_t idx = 0; |
| 2476 | for (auto& buffer : buffers) { |
| 2477 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2478 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2479 | BufferUsage::COMPOSER_OVERLAY, |
| 2480 | "test"); |
| 2481 | Color color = colors[idx % colors.size()]; |
| 2482 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); |
| 2483 | idx++; |
| 2484 | } |
| 2485 | |
| 2486 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the |
| 2487 | // cache is working. |
| 2488 | idx = 0; |
| 2489 | for (auto& buffer : buffers) { |
| 2490 | for (int i = 0; i < 2; i++) { |
| 2491 | Transaction().setBuffer(layer, buffer).apply(); |
| 2492 | |
| 2493 | Color color = colors[idx % colors.size()]; |
| 2494 | auto shot = screenshot(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2495 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), color); |
| 2496 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2497 | } |
| 2498 | idx++; |
| 2499 | } |
| 2500 | } |
| 2501 | |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 2502 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_LeastRecentlyUsed_BufferState) { |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2503 | sp<SurfaceControl> layer; |
| 2504 | ASSERT_NO_FATAL_FAILURE( |
| 2505 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2506 | |
| 2507 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; |
| 2508 | |
| 2509 | std::array<sp<GraphicBuffer>, 70> buffers; |
| 2510 | |
| 2511 | size_t idx = 0; |
| 2512 | for (auto& buffer : buffers) { |
| 2513 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2514 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2515 | BufferUsage::COMPOSER_OVERLAY, |
| 2516 | "test"); |
| 2517 | Color color = colors[idx % colors.size()]; |
| 2518 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); |
| 2519 | idx++; |
| 2520 | } |
| 2521 | |
| 2522 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the |
| 2523 | // cache is working. |
| 2524 | idx = 0; |
| 2525 | for (auto& buffer : buffers) { |
| 2526 | for (int i = 0; i < 2; i++) { |
| 2527 | Transaction().setBuffer(layer, buffer).apply(); |
| 2528 | |
| 2529 | Color color = colors[idx % colors.size()]; |
| 2530 | auto shot = screenshot(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2531 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), color); |
| 2532 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2533 | } |
| 2534 | idx++; |
| 2535 | } |
| 2536 | } |
| 2537 | |
Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 2538 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_DestroyedBuffer_BufferState) { |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2539 | sp<SurfaceControl> layer; |
| 2540 | ASSERT_NO_FATAL_FAILURE( |
| 2541 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2542 | |
| 2543 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; |
| 2544 | |
| 2545 | std::array<sp<GraphicBuffer>, 65> buffers; |
| 2546 | |
| 2547 | size_t idx = 0; |
| 2548 | for (auto& buffer : buffers) { |
| 2549 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2550 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2551 | BufferUsage::COMPOSER_OVERLAY, |
| 2552 | "test"); |
| 2553 | Color color = colors[idx % colors.size()]; |
| 2554 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); |
| 2555 | idx++; |
| 2556 | } |
| 2557 | |
| 2558 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the |
| 2559 | // cache is working. |
| 2560 | idx = 0; |
| 2561 | for (auto& buffer : buffers) { |
| 2562 | for (int i = 0; i < 2; i++) { |
| 2563 | Transaction().setBuffer(layer, buffer).apply(); |
| 2564 | |
| 2565 | Color color = colors[idx % colors.size()]; |
| 2566 | auto shot = screenshot(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2567 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), color); |
| 2568 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2569 | } |
| 2570 | if (idx == 0) { |
| 2571 | buffers[0].clear(); |
| 2572 | } |
| 2573 | idx++; |
| 2574 | } |
| 2575 | } |
| 2576 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2577 | TEST_P(LayerRenderTypeTransactionTest, SetTransformRotate90_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2578 | sp<SurfaceControl> layer; |
| 2579 | ASSERT_NO_FATAL_FAILURE( |
| 2580 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2581 | |
| 2582 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 2583 | Color::BLUE, Color::WHITE)); |
| 2584 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2585 | Transaction() |
| 2586 | .setFrame(layer, Rect(0, 0, 32, 32)) |
| 2587 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_ROT_90) |
| 2588 | .apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2589 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2590 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE, |
| 2591 | Color::GREEN, true /* filtered */); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2594 | TEST_P(LayerRenderTypeTransactionTest, SetTransformFlipH_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2595 | sp<SurfaceControl> layer; |
| 2596 | ASSERT_NO_FATAL_FAILURE( |
| 2597 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2598 | |
| 2599 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 2600 | Color::BLUE, Color::WHITE)); |
| 2601 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2602 | Transaction() |
| 2603 | .setFrame(layer, Rect(0, 0, 32, 32)) |
| 2604 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_H) |
| 2605 | .apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2606 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2607 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE, |
| 2608 | Color::BLUE, true /* filtered */); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2611 | TEST_P(LayerRenderTypeTransactionTest, SetTransformFlipV_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2612 | sp<SurfaceControl> layer; |
| 2613 | ASSERT_NO_FATAL_FAILURE( |
| 2614 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2615 | |
| 2616 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, |
| 2617 | Color::BLUE, Color::WHITE)); |
| 2618 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2619 | Transaction() |
| 2620 | .setFrame(layer, Rect(0, 0, 32, 32)) |
| 2621 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_V) |
| 2622 | .apply(); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2623 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2624 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED, |
| 2625 | Color::GREEN, true /* filtered */); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | TEST_F(LayerTransactionTest, SetTransformToDisplayInverse_BufferState) { |
| 2629 | sp<SurfaceControl> layer; |
| 2630 | ASSERT_NO_FATAL_FAILURE( |
| 2631 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2632 | |
| 2633 | Transaction().setTransformToDisplayInverse(layer, false).apply(); |
| 2634 | |
| 2635 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::GREEN, 32, 32)); |
| 2636 | |
| 2637 | Transaction().setTransformToDisplayInverse(layer, true).apply(); |
| 2638 | } |
| 2639 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2640 | TEST_P(LayerRenderTypeTransactionTest, SetFenceBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2641 | sp<SurfaceControl> layer; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2642 | Transaction transaction; |
| 2643 | ASSERT_NO_FATAL_FAILURE( |
| 2644 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2645 | |
| 2646 | sp<GraphicBuffer> buffer = |
| 2647 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2648 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2649 | BufferUsage::COMPOSER_OVERLAY, |
| 2650 | "test"); |
| 2651 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2652 | |
| 2653 | sp<Fence> fence; |
| 2654 | if (getBuffer(nullptr, &fence) != NO_ERROR) { |
| 2655 | GTEST_SUCCEED() << "test not supported"; |
| 2656 | return; |
| 2657 | } |
| 2658 | |
| 2659 | Transaction().setBuffer(layer, buffer).setAcquireFence(layer, fence).apply(); |
| 2660 | |
| 2661 | status_t status = fence->wait(1000); |
| 2662 | ASSERT_NE(static_cast<status_t>(Fence::Status::Unsignaled), status); |
| 2663 | std::this_thread::sleep_for(200ms); |
| 2664 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2665 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2666 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2667 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2668 | } |
| 2669 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2670 | TEST_P(LayerRenderTypeTransactionTest, SetFenceNull_BufferState) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2671 | sp<SurfaceControl> layer; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2672 | ASSERT_NO_FATAL_FAILURE( |
| 2673 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2674 | |
| 2675 | sp<GraphicBuffer> buffer = |
| 2676 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2677 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2678 | BufferUsage::COMPOSER_OVERLAY, |
| 2679 | "test"); |
| 2680 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2681 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2682 | sp<Fence> fence = Fence::NO_FENCE; |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2683 | |
| 2684 | Transaction() |
| 2685 | .setBuffer(layer, buffer) |
| 2686 | .setAcquireFence(layer, fence) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2687 | .apply(); |
| 2688 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2689 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2690 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2691 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2694 | TEST_P(LayerRenderTypeTransactionTest, SetDataspaceBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2695 | sp<SurfaceControl> layer; |
| 2696 | ASSERT_NO_FATAL_FAILURE( |
| 2697 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2698 | |
| 2699 | sp<GraphicBuffer> buffer = |
| 2700 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2701 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2702 | BufferUsage::COMPOSER_OVERLAY, |
| 2703 | "test"); |
| 2704 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2705 | |
| 2706 | Transaction() |
| 2707 | .setBuffer(layer, buffer) |
| 2708 | .setDataspace(layer, ui::Dataspace::UNKNOWN) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2709 | .apply(); |
| 2710 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2711 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2712 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2713 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2714 | } |
| 2715 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2716 | TEST_P(LayerRenderTypeTransactionTest, SetHdrMetadataBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2717 | sp<SurfaceControl> layer; |
| 2718 | ASSERT_NO_FATAL_FAILURE( |
| 2719 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2720 | |
| 2721 | sp<GraphicBuffer> buffer = |
| 2722 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2723 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2724 | BufferUsage::COMPOSER_OVERLAY, |
| 2725 | "test"); |
| 2726 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2727 | |
| 2728 | HdrMetadata hdrMetadata; |
| 2729 | hdrMetadata.validTypes = 0; |
| 2730 | Transaction() |
| 2731 | .setBuffer(layer, buffer) |
| 2732 | .setHdrMetadata(layer, hdrMetadata) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2733 | .apply(); |
| 2734 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2735 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2736 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2737 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2740 | TEST_P(LayerRenderTypeTransactionTest, SetSurfaceDamageRegionBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2741 | sp<SurfaceControl> layer; |
| 2742 | ASSERT_NO_FATAL_FAILURE( |
| 2743 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2744 | |
| 2745 | sp<GraphicBuffer> buffer = |
| 2746 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2747 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2748 | BufferUsage::COMPOSER_OVERLAY, |
| 2749 | "test"); |
| 2750 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2751 | |
| 2752 | Region region; |
| 2753 | region.set(32, 32); |
| 2754 | Transaction() |
| 2755 | .setBuffer(layer, buffer) |
| 2756 | .setSurfaceDamageRegion(layer, region) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2757 | .apply(); |
| 2758 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2759 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2760 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2761 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2764 | TEST_P(LayerRenderTypeTransactionTest, SetApiBasic_BufferState) { |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2765 | sp<SurfaceControl> layer; |
| 2766 | ASSERT_NO_FATAL_FAILURE( |
| 2767 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2768 | |
| 2769 | sp<GraphicBuffer> buffer = |
| 2770 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, |
| 2771 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | |
| 2772 | BufferUsage::COMPOSER_OVERLAY, |
| 2773 | "test"); |
| 2774 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); |
| 2775 | |
| 2776 | Transaction() |
| 2777 | .setBuffer(layer, buffer) |
| 2778 | .setApi(layer, NATIVE_WINDOW_API_CPU) |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2779 | .apply(); |
| 2780 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2781 | auto shot = getScreenCapture(); |
Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2782 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); |
| 2783 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | TEST_F(LayerTransactionTest, SetSidebandStreamNull_BufferState) { |
| 2787 | sp<SurfaceControl> layer; |
| 2788 | ASSERT_NO_FATAL_FAILURE( |
| 2789 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 2790 | |
| 2791 | // verify this doesn't cause a crash |
| 2792 | Transaction().setSidebandStream(layer, nullptr).apply(); |
| 2793 | } |
| 2794 | |
Robert Carr | 54cf5b1 | 2019-01-25 14:02:28 -0800 | [diff] [blame] | 2795 | TEST_F(LayerTransactionTest, ReparentToSelf) { |
| 2796 | sp<SurfaceControl> layer; |
| 2797 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); |
| 2798 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); |
| 2799 | Transaction().reparent(layer, layer->getHandle()).apply(); |
| 2800 | |
| 2801 | { |
| 2802 | // We expect the transaction to be silently dropped, but for SurfaceFlinger |
| 2803 | // to still be functioning. |
| 2804 | SCOPED_TRACE("after reparent to self"); |
| 2805 | const Rect rect(0, 0, 32, 32); |
| 2806 | auto shot = screenshot(); |
| 2807 | shot->expectColor(rect, Color::RED); |
| 2808 | shot->expectBorder(rect, Color::BLACK); |
| 2809 | } |
| 2810 | } |
| 2811 | |
Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2812 | class ColorTransformHelper { |
| 2813 | public: |
| 2814 | static void DegammaColorSingle(half& s) { |
| 2815 | if (s <= 0.03928f) |
| 2816 | s = s / 12.92f; |
| 2817 | else |
| 2818 | s = pow((s + 0.055f) / 1.055f, 2.4f); |
| 2819 | } |
| 2820 | |
| 2821 | static void DegammaColor(half3& color) { |
| 2822 | DegammaColorSingle(color.r); |
| 2823 | DegammaColorSingle(color.g); |
| 2824 | DegammaColorSingle(color.b); |
| 2825 | } |
| 2826 | |
| 2827 | static void GammaColorSingle(half& s) { |
| 2828 | if (s <= 0.0031308f) { |
| 2829 | s = s * 12.92f; |
| 2830 | } else { |
| 2831 | s = 1.055f * pow(s, (1.0f / 2.4f)) - 0.055f; |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | static void GammaColor(half3& color) { |
| 2836 | GammaColorSingle(color.r); |
| 2837 | GammaColorSingle(color.g); |
| 2838 | GammaColorSingle(color.b); |
| 2839 | } |
| 2840 | |
| 2841 | static void applyMatrix(half3& color, const mat3& mat) { |
| 2842 | half3 ret = half3(0); |
| 2843 | |
| 2844 | for (int i = 0; i < 3; i++) { |
| 2845 | for (int j = 0; j < 3; j++) { |
| 2846 | ret[i] = ret[i] + color[j] * mat[j][i]; |
| 2847 | } |
| 2848 | } |
| 2849 | color = ret; |
| 2850 | } |
| 2851 | }; |
| 2852 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2853 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformBasic) { |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2854 | sp<SurfaceControl> colorLayer; |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 2855 | ASSERT_NO_FATAL_FAILURE(colorLayer = |
| 2856 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 2857 | ISurfaceComposerClient::eFXSurfaceColor)); |
| 2858 | Transaction() |
| 2859 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 2860 | .setLayer(colorLayer, mLayerZBase + 1) |
| 2861 | .apply(); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2862 | { |
| 2863 | SCOPED_TRACE("default color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2864 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | 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] | 2868 | half3 expected = color; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2869 | mat3 matrix; |
| 2870 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; |
| 2871 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; |
| 2872 | 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] | 2873 | |
| 2874 | // degamma before applying the matrix |
| 2875 | if (mColorManagementUsed) { |
| 2876 | ColorTransformHelper::DegammaColor(expected); |
| 2877 | } |
| 2878 | |
| 2879 | ColorTransformHelper::applyMatrix(expected, matrix); |
| 2880 | |
| 2881 | if (mColorManagementUsed) { |
| 2882 | ColorTransformHelper::GammaColor(expected); |
| 2883 | } |
| 2884 | |
| 2885 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), |
| 2886 | uint8_t(expected.b * 255), 255}; |
| 2887 | |
| 2888 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 2889 | // channel) should be less than one |
| 2890 | const uint8_t tolerance = 1; |
| 2891 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2892 | Transaction().setColor(colorLayer, color) |
| 2893 | .setColorTransform(colorLayer, matrix, vec3()).apply(); |
| 2894 | { |
| 2895 | SCOPED_TRACE("new color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2896 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2897 | } |
| 2898 | } |
| 2899 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2900 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformOnParent) { |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2901 | sp<SurfaceControl> parentLayer; |
| 2902 | sp<SurfaceControl> colorLayer; |
| 2903 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parent", 0 /* buffer width */, |
| 2904 | 0 /* buffer height */, |
| 2905 | ISurfaceComposerClient::eFXSurfaceContainer)); |
| 2906 | ASSERT_NO_FATAL_FAILURE( |
| 2907 | colorLayer = createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 2908 | ISurfaceComposerClient::eFXSurfaceColor, parentLayer.get())); |
| 2909 | |
| 2910 | Transaction() |
| 2911 | .setCrop_legacy(parentLayer, Rect(0, 0, 100, 100)) |
| 2912 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 2913 | .setLayer(parentLayer, mLayerZBase + 1) |
| 2914 | .apply(); |
| 2915 | { |
| 2916 | SCOPED_TRACE("default color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2917 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | const half3 color(50.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f); |
| 2921 | half3 expected = color; |
| 2922 | mat3 matrix; |
| 2923 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; |
| 2924 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; |
| 2925 | matrix[0][2] = 0.3; matrix[1][2] = 0.59; matrix[2][2] = 0.11; |
| 2926 | |
| 2927 | // degamma before applying the matrix |
| 2928 | if (mColorManagementUsed) { |
| 2929 | ColorTransformHelper::DegammaColor(expected); |
| 2930 | } |
| 2931 | |
| 2932 | ColorTransformHelper::applyMatrix(expected, matrix); |
| 2933 | |
| 2934 | if (mColorManagementUsed) { |
| 2935 | ColorTransformHelper::GammaColor(expected); |
| 2936 | } |
| 2937 | |
| 2938 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), |
| 2939 | uint8_t(expected.b * 255), 255}; |
| 2940 | |
| 2941 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 2942 | // channel) should be less than one |
| 2943 | const uint8_t tolerance = 1; |
| 2944 | |
| 2945 | Transaction() |
| 2946 | .setColor(colorLayer, color) |
| 2947 | .setColorTransform(parentLayer, matrix, vec3()) |
| 2948 | .apply(); |
| 2949 | { |
| 2950 | SCOPED_TRACE("new color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2951 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2952 | } |
| 2953 | } |
| 2954 | |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2955 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformOnChildAndParent) { |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2956 | sp<SurfaceControl> parentLayer; |
| 2957 | sp<SurfaceControl> colorLayer; |
| 2958 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parent", 0 /* buffer width */, |
| 2959 | 0 /* buffer height */, |
| 2960 | ISurfaceComposerClient::eFXSurfaceContainer)); |
| 2961 | ASSERT_NO_FATAL_FAILURE( |
| 2962 | colorLayer = createLayer("test", 0 /* buffer width */, 0 /* buffer height */, |
| 2963 | ISurfaceComposerClient::eFXSurfaceColor, parentLayer.get())); |
| 2964 | |
| 2965 | Transaction() |
| 2966 | .setCrop_legacy(parentLayer, Rect(0, 0, 100, 100)) |
| 2967 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) |
| 2968 | .setLayer(parentLayer, mLayerZBase + 1) |
| 2969 | .apply(); |
| 2970 | { |
| 2971 | SCOPED_TRACE("default color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2972 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | const half3 color(50.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f); |
| 2976 | half3 expected = color; |
| 2977 | mat3 matrixChild; |
| 2978 | matrixChild[0][0] = 0.3; matrixChild[1][0] = 0.59; matrixChild[2][0] = 0.11; |
| 2979 | matrixChild[0][1] = 0.3; matrixChild[1][1] = 0.59; matrixChild[2][1] = 0.11; |
| 2980 | matrixChild[0][2] = 0.3; matrixChild[1][2] = 0.59; matrixChild[2][2] = 0.11; |
| 2981 | mat3 matrixParent; |
| 2982 | matrixParent[0][0] = 0.2; matrixParent[1][0] = 0.4; matrixParent[2][0] = 0.10; |
| 2983 | matrixParent[0][1] = 0.2; matrixParent[1][1] = 0.4; matrixParent[2][1] = 0.10; |
| 2984 | matrixParent[0][2] = 0.2; matrixParent[1][2] = 0.4; matrixParent[2][2] = 0.10; |
| 2985 | |
| 2986 | // degamma before applying the matrix |
| 2987 | if (mColorManagementUsed) { |
| 2988 | ColorTransformHelper::DegammaColor(expected); |
| 2989 | } |
| 2990 | |
| 2991 | ColorTransformHelper::applyMatrix(expected, matrixChild); |
| 2992 | ColorTransformHelper::applyMatrix(expected, matrixParent); |
| 2993 | |
| 2994 | if (mColorManagementUsed) { |
| 2995 | ColorTransformHelper::GammaColor(expected); |
| 2996 | } |
| 2997 | |
| 2998 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), |
| 2999 | uint8_t(expected.b * 255), 255}; |
| 3000 | |
| 3001 | // this is handwavy, but the precison loss scaled by 255 (8-bit per |
| 3002 | // channel) should be less than one |
| 3003 | const uint8_t tolerance = 1; |
| 3004 | |
| 3005 | Transaction() |
| 3006 | .setColor(colorLayer, color) |
| 3007 | .setColorTransform(parentLayer, matrixParent, vec3()) |
| 3008 | .setColorTransform(colorLayer, matrixChild, vec3()) |
| 3009 | .apply(); |
| 3010 | { |
| 3011 | SCOPED_TRACE("new color"); |
Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 3012 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); |
chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 3013 | } |
| 3014 | } |
| 3015 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3016 | struct CallbackData { |
| 3017 | CallbackData() = default; |
| 3018 | CallbackData(nsecs_t time, const sp<Fence>& fence, |
| 3019 | const std::vector<SurfaceControlStats>& stats) |
| 3020 | : latchTime(time), presentFence(fence), surfaceControlStats(stats) {} |
| 3021 | |
| 3022 | nsecs_t latchTime; |
| 3023 | sp<Fence> presentFence; |
| 3024 | std::vector<SurfaceControlStats> surfaceControlStats; |
| 3025 | }; |
| 3026 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3027 | class ExpectedResult { |
| 3028 | public: |
| 3029 | enum Transaction { |
| 3030 | NOT_PRESENTED = 0, |
| 3031 | PRESENTED, |
| 3032 | }; |
| 3033 | |
| 3034 | enum Buffer { |
| 3035 | NOT_ACQUIRED = 0, |
| 3036 | ACQUIRED, |
| 3037 | }; |
| 3038 | |
| 3039 | enum PreviousBuffer { |
| 3040 | NOT_RELEASED = 0, |
| 3041 | RELEASED, |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3042 | UNKNOWN, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3043 | }; |
| 3044 | |
| 3045 | void reset() { |
| 3046 | mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; |
| 3047 | mExpectedSurfaceResults.clear(); |
| 3048 | } |
| 3049 | |
| 3050 | void addSurface(ExpectedResult::Transaction transactionResult, const sp<SurfaceControl>& layer, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3051 | ExpectedResult::Buffer bufferResult = ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3052 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { |
| 3053 | mTransactionResult = transactionResult; |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3054 | mExpectedSurfaceResults.emplace(std::piecewise_construct, std::forward_as_tuple(layer), |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3055 | std::forward_as_tuple(bufferResult, previousBufferResult)); |
| 3056 | } |
| 3057 | |
| 3058 | void addSurfaces(ExpectedResult::Transaction transactionResult, |
| 3059 | const std::vector<sp<SurfaceControl>>& layers, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3060 | ExpectedResult::Buffer bufferResult = ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3061 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { |
| 3062 | for (const auto& layer : layers) { |
| 3063 | addSurface(transactionResult, layer, bufferResult, previousBufferResult); |
| 3064 | } |
| 3065 | } |
| 3066 | |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3067 | void addExpectedPresentTime(nsecs_t expectedPresentTime) { |
| 3068 | mExpectedPresentTime = expectedPresentTime; |
| 3069 | } |
| 3070 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3071 | void verifyCallbackData(const CallbackData& callbackData) const { |
| 3072 | const auto& [latchTime, presentFence, surfaceControlStats] = callbackData; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3073 | if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) { |
| 3074 | ASSERT_GE(latchTime, 0) << "bad latch time"; |
Valerie Hau | 63258a1 | 2018-12-14 14:31:48 -0800 | [diff] [blame] | 3075 | ASSERT_NE(presentFence, nullptr); |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3076 | if (mExpectedPresentTime >= 0) { |
| 3077 | ASSERT_EQ(presentFence->wait(3000), NO_ERROR); |
| 3078 | ASSERT_GE(presentFence->getSignalTime(), mExpectedPresentTime - nsecs_t(5 * 1e6)); |
| 3079 | // if the panel is running at 30 hz, at the worst case, our expected time just |
| 3080 | // misses vsync and we have to wait another 33.3ms |
| 3081 | ASSERT_LE(presentFence->getSignalTime(), |
| 3082 | mExpectedPresentTime + nsecs_t(66.666666 * 1e6)); |
| 3083 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3084 | } else { |
Valerie Hau | 63258a1 | 2018-12-14 14:31:48 -0800 | [diff] [blame] | 3085 | ASSERT_EQ(presentFence, nullptr) << "transaction shouldn't have been presented"; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3086 | ASSERT_EQ(latchTime, -1) << "unpresented transactions shouldn't be latched"; |
| 3087 | } |
| 3088 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3089 | ASSERT_EQ(surfaceControlStats.size(), mExpectedSurfaceResults.size()) |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3090 | << "wrong number of surfaces"; |
| 3091 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3092 | for (const auto& stats : surfaceControlStats) { |
| 3093 | ASSERT_NE(stats.surfaceControl, nullptr) << "returned null surface control"; |
| 3094 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3095 | const auto& expectedSurfaceResult = mExpectedSurfaceResults.find(stats.surfaceControl); |
| 3096 | ASSERT_NE(expectedSurfaceResult, mExpectedSurfaceResults.end()) |
| 3097 | << "unexpected surface control"; |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3098 | expectedSurfaceResult->second.verifySurfaceControlStats(stats, latchTime); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | |
| 3102 | private: |
| 3103 | class ExpectedSurfaceResult { |
| 3104 | public: |
| 3105 | ExpectedSurfaceResult(ExpectedResult::Buffer bufferResult, |
| 3106 | ExpectedResult::PreviousBuffer previousBufferResult) |
| 3107 | : mBufferResult(bufferResult), mPreviousBufferResult(previousBufferResult) {} |
| 3108 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3109 | void verifySurfaceControlStats(const SurfaceControlStats& surfaceControlStats, |
| 3110 | nsecs_t latchTime) const { |
| 3111 | const auto& [surfaceControl, acquireTime, previousReleaseFence] = surfaceControlStats; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3112 | |
| 3113 | ASSERT_EQ(acquireTime > 0, mBufferResult == ExpectedResult::Buffer::ACQUIRED) |
| 3114 | << "bad acquire time"; |
| 3115 | ASSERT_LE(acquireTime, latchTime) << "acquire time should be <= latch time"; |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3116 | |
| 3117 | if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::RELEASED) { |
| 3118 | ASSERT_NE(previousReleaseFence, nullptr) |
| 3119 | << "failed to set release prev buffer fence"; |
| 3120 | } else if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::NOT_RELEASED) { |
| 3121 | ASSERT_EQ(previousReleaseFence, nullptr) |
| 3122 | << "should not have set released prev buffer fence"; |
| 3123 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | private: |
| 3127 | ExpectedResult::Buffer mBufferResult; |
| 3128 | ExpectedResult::PreviousBuffer mPreviousBufferResult; |
| 3129 | }; |
| 3130 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3131 | struct SCHash { |
| 3132 | std::size_t operator()(const sp<SurfaceControl>& sc) const { |
| 3133 | return std::hash<IBinder*>{}(sc->getHandle().get()); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3134 | } |
| 3135 | }; |
| 3136 | ExpectedResult::Transaction mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3137 | nsecs_t mExpectedPresentTime = -1; |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3138 | std::unordered_map<sp<SurfaceControl>, ExpectedSurfaceResult, SCHash> mExpectedSurfaceResults; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3139 | }; |
| 3140 | |
| 3141 | class CallbackHelper { |
| 3142 | public: |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3143 | static void function(void* callbackContext, nsecs_t latchTime, const sp<Fence>& presentFence, |
| 3144 | const std::vector<SurfaceControlStats>& stats) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3145 | if (!callbackContext) { |
| 3146 | ALOGE("failed to get callback context"); |
| 3147 | } |
| 3148 | CallbackHelper* helper = static_cast<CallbackHelper*>(callbackContext); |
| 3149 | std::lock_guard lock(helper->mMutex); |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3150 | helper->mCallbackDataQueue.emplace(latchTime, presentFence, stats); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3151 | helper->mConditionVariable.notify_all(); |
| 3152 | } |
| 3153 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3154 | void getCallbackData(CallbackData* outData) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3155 | std::unique_lock lock(mMutex); |
| 3156 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3157 | if (mCallbackDataQueue.empty()) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3158 | ASSERT_NE(mConditionVariable.wait_for(lock, std::chrono::seconds(3)), |
| 3159 | std::cv_status::timeout) |
| 3160 | << "did not receive callback"; |
| 3161 | } |
| 3162 | |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3163 | *outData = std::move(mCallbackDataQueue.front()); |
| 3164 | mCallbackDataQueue.pop(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | void verifyFinalState() { |
| 3168 | // Wait to see if there are extra callbacks |
| 3169 | std::this_thread::sleep_for(500ms); |
| 3170 | |
| 3171 | std::lock_guard lock(mMutex); |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3172 | EXPECT_EQ(mCallbackDataQueue.size(), 0) << "extra callbacks received"; |
| 3173 | mCallbackDataQueue = {}; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | void* getContext() { return static_cast<void*>(this); } |
| 3177 | |
| 3178 | std::mutex mMutex; |
| 3179 | std::condition_variable mConditionVariable; |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3180 | std::queue<CallbackData> mCallbackDataQueue; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3181 | }; |
| 3182 | |
| 3183 | class LayerCallbackTest : public LayerTransactionTest { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3184 | public: |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3185 | virtual sp<SurfaceControl> createBufferStateLayer() { |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3186 | return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3189 | static int fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3190 | const sp<SurfaceControl>& layer = nullptr, bool setBuffer = true, |
| 3191 | bool setBackgroundColor = false) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3192 | if (layer) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3193 | sp<GraphicBuffer> buffer; |
| 3194 | sp<Fence> fence; |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3195 | if (setBuffer) { |
| 3196 | int err = getBuffer(&buffer, &fence); |
| 3197 | if (err != NO_ERROR) { |
| 3198 | return err; |
| 3199 | } |
| 3200 | |
| 3201 | transaction.setBuffer(layer, buffer); |
| 3202 | transaction.setAcquireFence(layer, fence); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3203 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3204 | |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3205 | if (setBackgroundColor) { |
| 3206 | transaction.setBackgroundColor(layer, /*color*/ half3(1.0f, 0, 0), /*alpha*/ 1.0f, |
| 3207 | ui::Dataspace::UNKNOWN); |
| 3208 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | transaction.addTransactionCompletedCallback(callbackHelper->function, |
| 3212 | callbackHelper->getContext()); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3213 | return NO_ERROR; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3216 | static void waitForCallback(CallbackHelper& helper, const ExpectedResult& expectedResult, |
| 3217 | bool finalState = false) { |
Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3218 | CallbackData callbackData; |
| 3219 | ASSERT_NO_FATAL_FAILURE(helper.getCallbackData(&callbackData)); |
| 3220 | EXPECT_NO_FATAL_FAILURE(expectedResult.verifyCallbackData(callbackData)); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3221 | |
| 3222 | if (finalState) { |
| 3223 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 3224 | } |
| 3225 | } |
| 3226 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3227 | static void waitForCallbacks(CallbackHelper& helper, |
| 3228 | const std::vector<ExpectedResult>& expectedResults, |
| 3229 | bool finalState = false) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3230 | for (const auto& expectedResult : expectedResults) { |
| 3231 | waitForCallback(helper, expectedResult); |
| 3232 | } |
| 3233 | if (finalState) { |
| 3234 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); |
| 3235 | } |
| 3236 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3237 | }; |
| 3238 | |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3239 | TEST_F(LayerCallbackTest, BufferColor) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3240 | sp<SurfaceControl> layer; |
| 3241 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3242 | |
| 3243 | Transaction transaction; |
| 3244 | CallbackHelper callback; |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3245 | int err = fillTransaction(transaction, &callback, layer, true, true); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3246 | if (err) { |
| 3247 | GTEST_SUCCEED() << "test not supported"; |
| 3248 | return; |
| 3249 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3250 | |
| 3251 | transaction.apply(); |
| 3252 | |
| 3253 | ExpectedResult expected; |
| 3254 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3255 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3256 | } |
| 3257 | |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3258 | TEST_F(LayerCallbackTest, NoBufferNoColor) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3259 | sp<SurfaceControl> layer; |
| 3260 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3261 | |
| 3262 | Transaction transaction; |
| 3263 | CallbackHelper callback; |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3264 | int err = fillTransaction(transaction, &callback, layer, false, false); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3265 | if (err) { |
| 3266 | GTEST_SUCCEED() << "test not supported"; |
| 3267 | return; |
| 3268 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3269 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3270 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3271 | |
| 3272 | ExpectedResult expected; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3273 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, |
| 3274 | ExpectedResult::Buffer::NOT_ACQUIRED); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3275 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3276 | } |
| 3277 | |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3278 | TEST_F(LayerCallbackTest, BufferNoColor) { |
| 3279 | sp<SurfaceControl> layer; |
| 3280 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3281 | |
| 3282 | Transaction transaction; |
| 3283 | CallbackHelper callback; |
| 3284 | int err = fillTransaction(transaction, &callback, layer, true, false); |
| 3285 | if (err) { |
| 3286 | GTEST_SUCCEED() << "test not supported"; |
| 3287 | return; |
| 3288 | } |
| 3289 | |
| 3290 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 3291 | |
| 3292 | ExpectedResult expected; |
| 3293 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3294 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3295 | } |
| 3296 | |
| 3297 | TEST_F(LayerCallbackTest, NoBufferColor) { |
| 3298 | sp<SurfaceControl> layer; |
| 3299 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3300 | |
| 3301 | Transaction transaction; |
| 3302 | CallbackHelper callback; |
| 3303 | int err = fillTransaction(transaction, &callback, layer, false, true); |
| 3304 | if (err) { |
| 3305 | GTEST_SUCCEED() << "test not supported"; |
| 3306 | return; |
| 3307 | } |
| 3308 | |
| 3309 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
| 3310 | |
| 3311 | ExpectedResult expected; |
| 3312 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 3313 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 3314 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3315 | } |
| 3316 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3317 | TEST_F(LayerCallbackTest, NoStateChange) { |
| 3318 | Transaction transaction; |
| 3319 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3320 | int err = fillTransaction(transaction, &callback); |
| 3321 | if (err) { |
| 3322 | GTEST_SUCCEED() << "test not supported"; |
| 3323 | return; |
| 3324 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3325 | |
| 3326 | transaction.apply(); |
| 3327 | |
| 3328 | ExpectedResult expected; |
| 3329 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3330 | } |
| 3331 | |
| 3332 | TEST_F(LayerCallbackTest, OffScreen) { |
| 3333 | sp<SurfaceControl> layer; |
| 3334 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3335 | |
| 3336 | Transaction transaction; |
| 3337 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3338 | int err = fillTransaction(transaction, &callback, layer); |
| 3339 | if (err) { |
| 3340 | GTEST_SUCCEED() << "test not supported"; |
| 3341 | return; |
| 3342 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3343 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3344 | transaction.setFrame(layer, Rect(-100, -100, 100, 100)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3345 | |
| 3346 | ExpectedResult expected; |
| 3347 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3348 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3349 | } |
| 3350 | |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3351 | TEST_F(LayerCallbackTest, MergeBufferNoColor) { |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3352 | sp<SurfaceControl> layer1, layer2; |
| 3353 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 3354 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 3355 | |
| 3356 | Transaction transaction1, transaction2; |
| 3357 | CallbackHelper callback1, callback2; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3358 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3359 | if (err) { |
| 3360 | GTEST_SUCCEED() << "test not supported"; |
| 3361 | return; |
| 3362 | } |
| 3363 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3364 | if (err) { |
| 3365 | GTEST_SUCCEED() << "test not supported"; |
| 3366 | return; |
| 3367 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3368 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3369 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3370 | 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] | 3371 | |
| 3372 | ExpectedResult expected; |
| 3373 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3374 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3375 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3376 | } |
| 3377 | |
Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3378 | TEST_F(LayerCallbackTest, MergeNoBufferColor) { |
| 3379 | sp<SurfaceControl> layer1, layer2; |
| 3380 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 3381 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 3382 | |
| 3383 | Transaction transaction1, transaction2; |
| 3384 | CallbackHelper callback1, callback2; |
| 3385 | int err = fillTransaction(transaction1, &callback1, layer1, false, true); |
| 3386 | if (err) { |
| 3387 | GTEST_SUCCEED() << "test not supported"; |
| 3388 | return; |
| 3389 | } |
| 3390 | err = fillTransaction(transaction2, &callback2, layer2, false, true); |
| 3391 | if (err) { |
| 3392 | GTEST_SUCCEED() << "test not supported"; |
| 3393 | return; |
| 3394 | } |
| 3395 | |
| 3396 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3397 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 3398 | |
| 3399 | ExpectedResult expected; |
| 3400 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
| 3401 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 3402 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3403 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3404 | } |
| 3405 | |
| 3406 | TEST_F(LayerCallbackTest, MergeOneBufferOneColor) { |
| 3407 | sp<SurfaceControl> layer1, layer2; |
| 3408 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 3409 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 3410 | |
| 3411 | Transaction transaction1, transaction2; |
| 3412 | CallbackHelper callback1, callback2; |
| 3413 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3414 | if (err) { |
| 3415 | GTEST_SUCCEED() << "test not supported"; |
| 3416 | return; |
| 3417 | } |
| 3418 | err = fillTransaction(transaction2, &callback2, layer2, false, true); |
| 3419 | if (err) { |
| 3420 | GTEST_SUCCEED() << "test not supported"; |
| 3421 | return; |
| 3422 | } |
| 3423 | |
| 3424 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3425 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); |
| 3426 | |
| 3427 | ExpectedResult expected; |
| 3428 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer1); |
| 3429 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer2, |
| 3430 | ExpectedResult::Buffer::NOT_ACQUIRED); |
| 3431 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3432 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3433 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3434 | TEST_F(LayerCallbackTest, Merge_SameCallback) { |
| 3435 | sp<SurfaceControl> layer1, layer2; |
| 3436 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 3437 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 3438 | |
| 3439 | Transaction transaction1, transaction2; |
| 3440 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3441 | int err = fillTransaction(transaction1, &callback, layer1); |
| 3442 | if (err) { |
| 3443 | GTEST_SUCCEED() << "test not supported"; |
| 3444 | return; |
| 3445 | } |
| 3446 | err = fillTransaction(transaction2, &callback, layer2); |
| 3447 | if (err) { |
| 3448 | GTEST_SUCCEED() << "test not supported"; |
| 3449 | return; |
| 3450 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3451 | |
| 3452 | transaction2.merge(std::move(transaction1)).apply(); |
| 3453 | |
| 3454 | ExpectedResult expected; |
| 3455 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3456 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 3457 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3458 | } |
| 3459 | |
| 3460 | TEST_F(LayerCallbackTest, Merge_SameLayer) { |
| 3461 | sp<SurfaceControl> layer; |
| 3462 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3463 | |
| 3464 | Transaction transaction1, transaction2; |
| 3465 | CallbackHelper callback1, callback2; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3466 | int err = fillTransaction(transaction1, &callback1, layer); |
| 3467 | if (err) { |
| 3468 | GTEST_SUCCEED() << "test not supported"; |
| 3469 | return; |
| 3470 | } |
| 3471 | err = fillTransaction(transaction2, &callback2, layer); |
| 3472 | if (err) { |
| 3473 | GTEST_SUCCEED() << "test not supported"; |
| 3474 | return; |
| 3475 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3476 | |
| 3477 | transaction2.merge(std::move(transaction1)).apply(); |
| 3478 | |
| 3479 | ExpectedResult expected; |
| 3480 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3481 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3482 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3483 | } |
| 3484 | |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3485 | TEST_F(LayerCallbackTest, Merge_DifferentClients) { |
| 3486 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 3487 | client2(new SurfaceComposerClient); |
| 3488 | |
| 3489 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3490 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3491 | |
| 3492 | sp<SurfaceControl> layer1, layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3493 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3494 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3495 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3496 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 3497 | |
| 3498 | Transaction transaction1, transaction2; |
| 3499 | CallbackHelper callback1, callback2; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3500 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3501 | if (err) { |
| 3502 | GTEST_SUCCEED() << "test not supported"; |
| 3503 | return; |
| 3504 | } |
| 3505 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3506 | if (err) { |
| 3507 | GTEST_SUCCEED() << "test not supported"; |
| 3508 | return; |
| 3509 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3510 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3511 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3512 | 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] | 3513 | |
| 3514 | ExpectedResult expected; |
| 3515 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3516 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3517 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3518 | } |
| 3519 | |
| 3520 | TEST_F(LayerCallbackTest, MultipleTransactions) { |
| 3521 | sp<SurfaceControl> layer; |
| 3522 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3523 | |
| 3524 | Transaction transaction; |
| 3525 | CallbackHelper callback; |
| 3526 | for (size_t i = 0; i < 10; i++) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3527 | int err = fillTransaction(transaction, &callback, layer); |
| 3528 | if (err) { |
| 3529 | GTEST_SUCCEED() << "test not supported"; |
| 3530 | return; |
| 3531 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3532 | |
| 3533 | transaction.apply(); |
| 3534 | |
| 3535 | ExpectedResult expected; |
| 3536 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3537 | ExpectedResult::Buffer::ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3538 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 3539 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 3540 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 3541 | } |
| 3542 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 3543 | } |
| 3544 | |
| 3545 | TEST_F(LayerCallbackTest, MultipleTransactions_NoStateChange) { |
| 3546 | sp<SurfaceControl> layer; |
| 3547 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3548 | |
| 3549 | Transaction transaction; |
| 3550 | CallbackHelper callback; |
| 3551 | for (size_t i = 0; i < 10; i++) { |
| 3552 | ExpectedResult expected; |
| 3553 | |
| 3554 | if (i == 0) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3555 | int err = fillTransaction(transaction, &callback, layer); |
| 3556 | if (err) { |
| 3557 | GTEST_SUCCEED() << "test not supported"; |
| 3558 | return; |
| 3559 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3560 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3561 | } else { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3562 | int err = fillTransaction(transaction, &callback); |
| 3563 | if (err) { |
| 3564 | GTEST_SUCCEED() << "test not supported"; |
| 3565 | return; |
| 3566 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | transaction.apply(); |
| 3570 | |
| 3571 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); |
| 3572 | } |
| 3573 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 3574 | } |
| 3575 | |
| 3576 | TEST_F(LayerCallbackTest, MultipleTransactions_SameStateChange) { |
| 3577 | sp<SurfaceControl> layer; |
| 3578 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3579 | |
| 3580 | Transaction transaction; |
| 3581 | CallbackHelper callback; |
| 3582 | for (size_t i = 0; i < 10; i++) { |
| 3583 | if (i == 0) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3584 | int err = fillTransaction(transaction, &callback, layer); |
| 3585 | if (err) { |
| 3586 | GTEST_SUCCEED() << "test not supported"; |
| 3587 | return; |
| 3588 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3589 | } else { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3590 | int err = fillTransaction(transaction, &callback); |
| 3591 | if (err) { |
| 3592 | GTEST_SUCCEED() << "test not supported"; |
| 3593 | return; |
| 3594 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3597 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3598 | |
| 3599 | ExpectedResult expected; |
| 3600 | expected.addSurface((i == 0) ? ExpectedResult::Transaction::PRESENTED |
| 3601 | : ExpectedResult::Transaction::NOT_PRESENTED, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3602 | layer, |
| 3603 | (i == 0) ? ExpectedResult::Buffer::ACQUIRED |
| 3604 | : ExpectedResult::Buffer::NOT_ACQUIRED); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3605 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, i == 0)); |
| 3606 | } |
| 3607 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); |
| 3608 | } |
| 3609 | |
| 3610 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge) { |
| 3611 | sp<SurfaceControl> layer1, layer2; |
| 3612 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); |
| 3613 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); |
| 3614 | |
| 3615 | Transaction transaction1, transaction2; |
| 3616 | CallbackHelper callback1, callback2; |
| 3617 | for (size_t i = 0; i < 10; i++) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3618 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3619 | if (err) { |
| 3620 | GTEST_SUCCEED() << "test not supported"; |
| 3621 | return; |
| 3622 | } |
| 3623 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3624 | if (err) { |
| 3625 | GTEST_SUCCEED() << "test not supported"; |
| 3626 | return; |
| 3627 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3628 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3629 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3630 | 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] | 3631 | |
| 3632 | ExpectedResult expected; |
| 3633 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3634 | ExpectedResult::Buffer::ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3635 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 3636 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 3637 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 3638 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 3639 | } |
| 3640 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 3641 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 3642 | } |
| 3643 | |
| 3644 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients) { |
| 3645 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 3646 | client2(new SurfaceComposerClient); |
| 3647 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3648 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3649 | |
| 3650 | sp<SurfaceControl> layer1, layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3651 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3652 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3653 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3654 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 3655 | |
| 3656 | Transaction transaction1, transaction2; |
| 3657 | CallbackHelper callback1, callback2; |
| 3658 | for (size_t i = 0; i < 10; i++) { |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3659 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3660 | if (err) { |
| 3661 | GTEST_SUCCEED() << "test not supported"; |
| 3662 | return; |
| 3663 | } |
| 3664 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3665 | if (err) { |
| 3666 | GTEST_SUCCEED() << "test not supported"; |
| 3667 | return; |
| 3668 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3669 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3670 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3671 | 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] | 3672 | |
| 3673 | ExpectedResult expected; |
| 3674 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3675 | ExpectedResult::Buffer::ACQUIRED, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3676 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED |
| 3677 | : ExpectedResult::PreviousBuffer::RELEASED); |
| 3678 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); |
| 3679 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); |
| 3680 | } |
| 3681 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); |
| 3682 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); |
| 3683 | } |
| 3684 | |
| 3685 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_NoStateChange) { |
| 3686 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 3687 | client2(new SurfaceComposerClient); |
| 3688 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3689 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3690 | |
| 3691 | sp<SurfaceControl> layer1, layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3692 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3693 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3694 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3695 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 3696 | |
| 3697 | Transaction transaction1, transaction2; |
| 3698 | CallbackHelper callback1, callback2; |
| 3699 | |
| 3700 | // Normal call to set up test |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3701 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3702 | if (err) { |
| 3703 | GTEST_SUCCEED() << "test not supported"; |
| 3704 | return; |
| 3705 | } |
| 3706 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3707 | if (err) { |
| 3708 | GTEST_SUCCEED() << "test not supported"; |
| 3709 | return; |
| 3710 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3711 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3712 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3713 | 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] | 3714 | |
| 3715 | ExpectedResult expected; |
| 3716 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3717 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3718 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3719 | expected.reset(); |
| 3720 | |
| 3721 | // Test |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3722 | err = fillTransaction(transaction1, &callback1); |
| 3723 | if (err) { |
| 3724 | GTEST_SUCCEED() << "test not supported"; |
| 3725 | return; |
| 3726 | } |
| 3727 | err = fillTransaction(transaction2, &callback2); |
| 3728 | if (err) { |
| 3729 | GTEST_SUCCEED() << "test not supported"; |
| 3730 | return; |
| 3731 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3732 | |
| 3733 | transaction2.merge(std::move(transaction1)).apply(); |
| 3734 | |
| 3735 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3736 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3737 | } |
| 3738 | |
| 3739 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_SameStateChange) { |
| 3740 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), |
| 3741 | client2(new SurfaceComposerClient); |
| 3742 | |
| 3743 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3744 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; |
| 3745 | |
| 3746 | sp<SurfaceControl> layer1, layer2; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3747 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3748 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3749 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3750 | ISurfaceComposerClient::eFXSurfaceBufferState)); |
| 3751 | |
| 3752 | Transaction transaction1, transaction2; |
| 3753 | CallbackHelper callback1, callback2; |
| 3754 | |
| 3755 | // Normal call to set up test |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3756 | int err = fillTransaction(transaction1, &callback1, layer1); |
| 3757 | if (err) { |
| 3758 | GTEST_SUCCEED() << "test not supported"; |
| 3759 | return; |
| 3760 | } |
| 3761 | err = fillTransaction(transaction2, &callback2, layer2); |
| 3762 | if (err) { |
| 3763 | GTEST_SUCCEED() << "test not supported"; |
| 3764 | return; |
| 3765 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3766 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3767 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); |
| 3768 | 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] | 3769 | |
| 3770 | ExpectedResult expected; |
| 3771 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); |
| 3772 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3773 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3774 | expected.reset(); |
| 3775 | |
| 3776 | // Test |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3777 | err = fillTransaction(transaction1, &callback1); |
| 3778 | if (err) { |
| 3779 | GTEST_SUCCEED() << "test not supported"; |
| 3780 | return; |
| 3781 | } |
| 3782 | err = fillTransaction(transaction2, &callback2); |
| 3783 | if (err) { |
| 3784 | GTEST_SUCCEED() << "test not supported"; |
| 3785 | return; |
| 3786 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3787 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3788 | 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] | 3789 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3790 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer2, |
| 3791 | ExpectedResult::Buffer::NOT_ACQUIRED); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3792 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); |
| 3793 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); |
| 3794 | } |
| 3795 | |
| 3796 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame) { |
| 3797 | sp<SurfaceControl> layer; |
| 3798 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3799 | |
| 3800 | Transaction transaction; |
| 3801 | CallbackHelper callback; |
| 3802 | std::vector<ExpectedResult> expectedResults(50); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3803 | for (auto& expected : expectedResults) { |
| 3804 | expected.reset(); |
| 3805 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3806 | ExpectedResult::Buffer::ACQUIRED, |
| 3807 | ExpectedResult::PreviousBuffer::UNKNOWN); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3808 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3809 | int err = fillTransaction(transaction, &callback, layer); |
| 3810 | if (err) { |
| 3811 | GTEST_SUCCEED() << "test not supported"; |
| 3812 | return; |
| 3813 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3814 | |
| 3815 | transaction.apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3816 | } |
| 3817 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 3818 | } |
| 3819 | |
| 3820 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_NoStateChange) { |
| 3821 | sp<SurfaceControl> layer; |
| 3822 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3823 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3824 | // Normal call to set up test |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3825 | Transaction transaction; |
| 3826 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3827 | int err = fillTransaction(transaction, &callback, layer); |
| 3828 | if (err) { |
| 3829 | GTEST_SUCCEED() << "test not supported"; |
| 3830 | return; |
| 3831 | } |
| 3832 | |
| 3833 | transaction.apply(); |
| 3834 | |
| 3835 | ExpectedResult expected; |
| 3836 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3837 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3838 | |
| 3839 | // Test |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3840 | std::vector<ExpectedResult> expectedResults(50); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3841 | for (auto& expected : expectedResults) { |
| 3842 | expected.reset(); |
| 3843 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3844 | err = fillTransaction(transaction, &callback); |
| 3845 | if (err) { |
| 3846 | GTEST_SUCCEED() << "test not supported"; |
| 3847 | return; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | transaction.apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3851 | } |
| 3852 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 3853 | } |
| 3854 | |
| 3855 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_SameStateChange) { |
| 3856 | sp<SurfaceControl> layer; |
| 3857 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3858 | |
| 3859 | // Normal call to set up test |
| 3860 | Transaction transaction; |
| 3861 | CallbackHelper callback; |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3862 | int err = fillTransaction(transaction, &callback, layer); |
| 3863 | if (err) { |
| 3864 | GTEST_SUCCEED() << "test not supported"; |
| 3865 | return; |
| 3866 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3867 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3868 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3869 | |
| 3870 | ExpectedResult expectedResult; |
| 3871 | expectedResult.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3872 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expectedResult, true)); |
| 3873 | |
| 3874 | // Test |
| 3875 | std::vector<ExpectedResult> expectedResults(50); |
| 3876 | for (auto& expected : expectedResults) { |
| 3877 | expected.reset(); |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3878 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, |
| 3879 | ExpectedResult::Buffer::NOT_ACQUIRED); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3880 | |
Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3881 | err = fillTransaction(transaction, &callback); |
| 3882 | if (err) { |
| 3883 | GTEST_SUCCEED() << "test not supported"; |
| 3884 | return; |
| 3885 | } |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3886 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3887 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3888 | } |
| 3889 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); |
| 3890 | } |
| 3891 | |
Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3892 | TEST_F(LayerCallbackTest, DesiredPresentTime) { |
| 3893 | sp<SurfaceControl> layer; |
| 3894 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3895 | |
| 3896 | Transaction transaction; |
| 3897 | CallbackHelper callback; |
| 3898 | int err = fillTransaction(transaction, &callback, layer); |
| 3899 | if (err) { |
| 3900 | GTEST_SUCCEED() << "test not supported"; |
| 3901 | return; |
| 3902 | } |
| 3903 | |
| 3904 | // Try to present 100ms in the future |
| 3905 | nsecs_t time = systemTime() + (100 * 1e6); |
| 3906 | |
| 3907 | transaction.setDesiredPresentTime(time); |
| 3908 | transaction.apply(); |
| 3909 | |
| 3910 | ExpectedResult expected; |
| 3911 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3912 | expected.addExpectedPresentTime(time); |
| 3913 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 3914 | } |
| 3915 | |
| 3916 | TEST_F(LayerCallbackTest, DesiredPresentTime_Multiple) { |
| 3917 | sp<SurfaceControl> layer; |
| 3918 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3919 | |
| 3920 | Transaction transaction; |
| 3921 | CallbackHelper callback1; |
| 3922 | int err = fillTransaction(transaction, &callback1, layer); |
| 3923 | if (err) { |
| 3924 | GTEST_SUCCEED() << "test not supported"; |
| 3925 | return; |
| 3926 | } |
| 3927 | |
| 3928 | // Try to present 100ms in the future |
| 3929 | nsecs_t time = systemTime() + (100 * 1e6); |
| 3930 | |
| 3931 | transaction.setDesiredPresentTime(time); |
| 3932 | transaction.apply(); |
| 3933 | |
| 3934 | ExpectedResult expected1; |
| 3935 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3936 | expected1.addExpectedPresentTime(time); |
| 3937 | |
| 3938 | CallbackHelper callback2; |
| 3939 | err = fillTransaction(transaction, &callback2, layer); |
| 3940 | if (err) { |
| 3941 | GTEST_SUCCEED() << "test not supported"; |
| 3942 | return; |
| 3943 | } |
| 3944 | |
| 3945 | // Try to present 33ms after the first frame |
| 3946 | time += (33.3 * 1e6); |
| 3947 | |
| 3948 | transaction.setDesiredPresentTime(time); |
| 3949 | transaction.apply(); |
| 3950 | |
| 3951 | ExpectedResult expected2; |
| 3952 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 3953 | ExpectedResult::Buffer::ACQUIRED, |
| 3954 | ExpectedResult::PreviousBuffer::RELEASED); |
| 3955 | expected2.addExpectedPresentTime(time); |
| 3956 | |
| 3957 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); |
| 3958 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); |
| 3959 | } |
| 3960 | |
| 3961 | TEST_F(LayerCallbackTest, DesiredPresentTime_OutOfOrder) { |
| 3962 | sp<SurfaceControl> layer; |
| 3963 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 3964 | |
| 3965 | Transaction transaction; |
| 3966 | CallbackHelper callback1; |
| 3967 | int err = fillTransaction(transaction, &callback1, layer); |
| 3968 | if (err) { |
| 3969 | GTEST_SUCCEED() << "test not supported"; |
| 3970 | return; |
| 3971 | } |
| 3972 | |
| 3973 | // Try to present 100ms in the future |
| 3974 | nsecs_t time = systemTime() + (100 * 1e6); |
| 3975 | |
| 3976 | transaction.setDesiredPresentTime(time); |
| 3977 | transaction.apply(); |
| 3978 | |
| 3979 | ExpectedResult expected1; |
| 3980 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 3981 | expected1.addExpectedPresentTime(time); |
| 3982 | |
| 3983 | CallbackHelper callback2; |
| 3984 | err = fillTransaction(transaction, &callback2, layer); |
| 3985 | if (err) { |
| 3986 | GTEST_SUCCEED() << "test not supported"; |
| 3987 | return; |
| 3988 | } |
| 3989 | |
| 3990 | // Try to present 33ms before the previous frame |
| 3991 | time -= (33.3 * 1e6); |
| 3992 | |
| 3993 | transaction.setDesiredPresentTime(time); |
| 3994 | transaction.apply(); |
| 3995 | |
| 3996 | ExpectedResult expected2; |
| 3997 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, |
| 3998 | ExpectedResult::Buffer::ACQUIRED, |
| 3999 | ExpectedResult::PreviousBuffer::RELEASED); |
| 4000 | |
| 4001 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); |
| 4002 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); |
| 4003 | } |
| 4004 | |
| 4005 | TEST_F(LayerCallbackTest, DesiredPresentTime_Past) { |
| 4006 | sp<SurfaceControl> layer; |
| 4007 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); |
| 4008 | |
| 4009 | Transaction transaction; |
| 4010 | CallbackHelper callback; |
| 4011 | int err = fillTransaction(transaction, &callback, layer); |
| 4012 | if (err) { |
| 4013 | GTEST_SUCCEED() << "test not supported"; |
| 4014 | return; |
| 4015 | } |
| 4016 | |
| 4017 | // Try to present 100ms in the past |
| 4018 | nsecs_t time = systemTime() - (100 * 1e6); |
| 4019 | |
| 4020 | transaction.setDesiredPresentTime(time); |
| 4021 | transaction.apply(); |
| 4022 | |
| 4023 | ExpectedResult expected; |
| 4024 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); |
| 4025 | expected.addExpectedPresentTime(systemTime()); |
| 4026 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); |
| 4027 | } |
| 4028 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4029 | class LayerUpdateTest : public LayerTransactionTest { |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4030 | protected: |
| 4031 | virtual void SetUp() { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4032 | LayerTransactionTest::SetUp(); |
| 4033 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4034 | |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 4035 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); |
| 4036 | ASSERT_FALSE(display == nullptr); |
| 4037 | |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 4038 | DisplayInfo info; |
Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 4039 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayInfo(display, &info)); |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 4040 | |
| 4041 | ssize_t displayWidth = info.w; |
| 4042 | ssize_t displayHeight = info.h; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4043 | |
| 4044 | // Background surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4045 | mBGSurfaceControl = createLayer(String8("BG Test Surface"), displayWidth, |
| 4046 | displayHeight, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 4047 | ASSERT_TRUE(mBGSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4048 | ASSERT_TRUE(mBGSurfaceControl->isValid()); |
| 4049 | fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195); |
| 4050 | |
| 4051 | // Foreground surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4052 | mFGSurfaceControl = createLayer(String8("FG Test Surface"), 64, 64, 0); |
| 4053 | |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 4054 | ASSERT_TRUE(mFGSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4055 | ASSERT_TRUE(mFGSurfaceControl->isValid()); |
| 4056 | |
| 4057 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 4058 | |
| 4059 | // Synchronization surface |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4060 | mSyncSurfaceControl = createLayer(String8("Sync Test Surface"), 1, 1, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 4061 | ASSERT_TRUE(mSyncSurfaceControl != nullptr); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4062 | ASSERT_TRUE(mSyncSurfaceControl->isValid()); |
| 4063 | |
| 4064 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 4065 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4066 | asTransaction([&](Transaction& t) { |
| 4067 | t.setDisplayLayerStack(display, 0); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4068 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4069 | t.setLayer(mBGSurfaceControl, INT32_MAX - 2).show(mBGSurfaceControl); |
Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 4070 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4071 | t.setLayer(mFGSurfaceControl, INT32_MAX - 1) |
| 4072 | .setPosition(mFGSurfaceControl, 64, 64) |
| 4073 | .show(mFGSurfaceControl); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4074 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4075 | t.setLayer(mSyncSurfaceControl, INT32_MAX - 1) |
| 4076 | .setPosition(mSyncSurfaceControl, displayWidth - 2, displayHeight - 2) |
| 4077 | .show(mSyncSurfaceControl); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4078 | }); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
| 4081 | virtual void TearDown() { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4082 | LayerTransactionTest::TearDown(); |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4083 | mBGSurfaceControl = 0; |
| 4084 | mFGSurfaceControl = 0; |
| 4085 | mSyncSurfaceControl = 0; |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | void waitForPostedBuffers() { |
| 4089 | // Since the sync surface is in synchronous mode (i.e. double buffered) |
| 4090 | // posting three buffers to it should ensure that at least two |
| 4091 | // SurfaceFlinger::handlePageFlip calls have been made, which should |
| 4092 | // guaranteed that a buffer posted to another Surface has been retired. |
| 4093 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 4094 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 4095 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 4096 | } |
| 4097 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4098 | |
Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4099 | sp<SurfaceControl> mBGSurfaceControl; |
| 4100 | sp<SurfaceControl> mFGSurfaceControl; |
| 4101 | |
| 4102 | // This surface is used to ensure that the buffers posted to |
| 4103 | // mFGSurfaceControl have been picked up by SurfaceFlinger. |
| 4104 | sp<SurfaceControl> mSyncSurfaceControl; |
| 4105 | }; |
| 4106 | |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4107 | TEST_F(LayerUpdateTest, RelativesAreNotDetached) { |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4108 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4109 | std::unique_ptr<ScreenCapture> sc; |
| 4110 | |
| 4111 | sp<SurfaceControl> relative = createLayer(String8("relativeTestSurface"), 10, 10, 0); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4112 | fillSurfaceRGBA8(relative, 10, 10, 10); |
| 4113 | waitForPostedBuffers(); |
| 4114 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4115 | Transaction{} |
| 4116 | .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1) |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4117 | .setPosition(relative, 64, 64) |
| 4118 | .apply(); |
| 4119 | |
| 4120 | { |
| 4121 | // The relative should be on top of the FG control. |
| 4122 | ScreenCapture::captureScreen(&sc); |
| 4123 | sc->checkPixel(64, 64, 10, 10, 10); |
| 4124 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4125 | Transaction{}.detachChildren(mFGSurfaceControl).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4126 | |
| 4127 | { |
| 4128 | // Nothing should change at this point. |
| 4129 | ScreenCapture::captureScreen(&sc); |
| 4130 | sc->checkPixel(64, 64, 10, 10, 10); |
| 4131 | } |
| 4132 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4133 | Transaction{}.hide(relative).apply(); |
Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4134 | |
| 4135 | { |
| 4136 | // Ensure that the relative was actually hidden, rather than |
| 4137 | // being left in the detached but visible state. |
| 4138 | ScreenCapture::captureScreen(&sc); |
| 4139 | sc->expectFGColor(64, 64); |
| 4140 | } |
| 4141 | } |
| 4142 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4143 | class GeometryLatchingTest : public LayerUpdateTest { |
| 4144 | protected: |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4145 | void EXPECT_INITIAL_STATE(const char* trace) { |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4146 | SCOPED_TRACE(trace); |
| 4147 | ScreenCapture::captureScreen(&sc); |
| 4148 | // We find the leading edge of the FG surface. |
| 4149 | sc->expectFGColor(127, 127); |
| 4150 | sc->expectBGColor(128, 128); |
| 4151 | } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 4152 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4153 | void lockAndFillFGBuffer() { fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false); } |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 4154 | |
| 4155 | void unlockFGBuffer() { |
| 4156 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 4157 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); |
| 4158 | waitForPostedBuffers(); |
| 4159 | } |
| 4160 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4161 | void completeFGResize() { |
| 4162 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 4163 | waitForPostedBuffers(); |
| 4164 | } |
| 4165 | void restoreInitialState() { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4166 | asTransaction([&](Transaction& t) { |
| 4167 | t.setSize(mFGSurfaceControl, 64, 64); |
| 4168 | t.setPosition(mFGSurfaceControl, 64, 64); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4169 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 64, 64)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4170 | }); |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4171 | |
| 4172 | EXPECT_INITIAL_STATE("After restoring initial state"); |
| 4173 | } |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4174 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4175 | }; |
| 4176 | |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4177 | class CropLatchingTest : public GeometryLatchingTest { |
| 4178 | protected: |
| 4179 | void EXPECT_CROPPED_STATE(const char* trace) { |
| 4180 | SCOPED_TRACE(trace); |
| 4181 | ScreenCapture::captureScreen(&sc); |
| 4182 | // The edge should be moved back one pixel by our crop. |
| 4183 | sc->expectFGColor(126, 126); |
| 4184 | sc->expectBGColor(127, 127); |
| 4185 | sc->expectBGColor(128, 128); |
| 4186 | } |
chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 4187 | |
| 4188 | void EXPECT_RESIZE_STATE(const char* trace) { |
| 4189 | SCOPED_TRACE(trace); |
| 4190 | ScreenCapture::captureScreen(&sc); |
| 4191 | // The FG is now resized too 128,128 at 64,64 |
| 4192 | sc->expectFGColor(64, 64); |
| 4193 | sc->expectFGColor(191, 191); |
| 4194 | sc->expectBGColor(192, 192); |
| 4195 | } |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4196 | }; |
| 4197 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4198 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4199 | std::unique_ptr<ScreenCapture> sc; |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4200 | { |
| 4201 | SCOPED_TRACE("before anything"); |
| 4202 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4203 | sc->expectBGColor(32, 32); |
| 4204 | sc->expectFGColor(96, 96); |
| 4205 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | // set up two deferred transactions on different frames |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4209 | asTransaction([&](Transaction& t) { |
| 4210 | t.setAlpha(mFGSurfaceControl, 0.75); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4211 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
| 4212 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4213 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4214 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4215 | asTransaction([&](Transaction& t) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4216 | t.setPosition(mFGSurfaceControl, 128, 128); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4217 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), |
| 4218 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4219 | }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4220 | |
| 4221 | { |
| 4222 | SCOPED_TRACE("before any trigger"); |
| 4223 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4224 | sc->expectBGColor(32, 32); |
| 4225 | sc->expectFGColor(96, 96); |
| 4226 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | // should trigger the first deferred transaction, but not the second one |
| 4230 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 4231 | { |
| 4232 | SCOPED_TRACE("after first trigger"); |
| 4233 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4234 | sc->expectBGColor(32, 32); |
| 4235 | sc->checkPixel(96, 96, 162, 63, 96); |
| 4236 | sc->expectBGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4237 | } |
| 4238 | |
| 4239 | // should show up immediately since it's not deferred |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4240 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 1.0); }); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4241 | |
| 4242 | // trigger the second deferred transaction |
| 4243 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); |
| 4244 | { |
| 4245 | SCOPED_TRACE("after second trigger"); |
| 4246 | ScreenCapture::captureScreen(&sc); |
Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4247 | sc->expectBGColor(32, 32); |
| 4248 | sc->expectBGColor(96, 96); |
| 4249 | sc->expectFGColor(160, 160); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4250 | } |
| 4251 | } |
| 4252 | |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4253 | TEST_F(LayerUpdateTest, LayerWithNoBuffersResizesImmediately) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4254 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4255 | |
| 4256 | sp<SurfaceControl> childNoBuffer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4257 | createSurface(mClient, "Bufferless child", 0 /* buffer width */, 0 /* buffer height */, |
| 4258 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 4259 | sp<SurfaceControl> childBuffer = createSurface(mClient, "Buffered child", 20, 20, |
| 4260 | PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get()); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4261 | fillSurfaceRGBA8(childBuffer, 200, 200, 200); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4262 | SurfaceComposerClient::Transaction{} |
| 4263 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 10, 10)) |
| 4264 | .show(childNoBuffer) |
| 4265 | .show(childBuffer) |
| 4266 | .apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4267 | { |
| 4268 | ScreenCapture::captureScreen(&sc); |
| 4269 | sc->expectChildColor(73, 73); |
| 4270 | sc->expectFGColor(74, 74); |
| 4271 | } |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4272 | SurfaceComposerClient::Transaction{} |
| 4273 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 20, 20)) |
| 4274 | .apply(true); |
Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4275 | { |
| 4276 | ScreenCapture::captureScreen(&sc); |
| 4277 | sc->expectChildColor(73, 73); |
| 4278 | sc->expectChildColor(74, 74); |
| 4279 | } |
| 4280 | } |
| 4281 | |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 4282 | TEST_F(LayerUpdateTest, MergingTransactions) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4283 | std::unique_ptr<ScreenCapture> sc; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 4284 | { |
| 4285 | SCOPED_TRACE("before move"); |
| 4286 | ScreenCapture::captureScreen(&sc); |
| 4287 | sc->expectBGColor(0, 12); |
| 4288 | sc->expectFGColor(75, 75); |
| 4289 | sc->expectBGColor(145, 145); |
| 4290 | } |
| 4291 | |
| 4292 | Transaction t1, t2; |
| 4293 | t1.setPosition(mFGSurfaceControl, 128, 128); |
| 4294 | t2.setPosition(mFGSurfaceControl, 0, 0); |
| 4295 | // We expect that the position update from t2 now |
| 4296 | // overwrites the position update from t1. |
| 4297 | t1.merge(std::move(t2)); |
| 4298 | t1.apply(); |
| 4299 | |
| 4300 | { |
| 4301 | ScreenCapture::captureScreen(&sc); |
| 4302 | sc->expectFGColor(1, 1); |
| 4303 | } |
| 4304 | } |
| 4305 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4306 | class ChildLayerTest : public LayerUpdateTest { |
| 4307 | protected: |
| 4308 | void SetUp() override { |
| 4309 | LayerUpdateTest::SetUp(); |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame^] | 4310 | mChild = createSurface(mClient, "Child surface", 10, 15, PIXEL_FORMAT_RGBA_8888, 0, |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4311 | mFGSurfaceControl.get()); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4312 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 4313 | |
| 4314 | { |
| 4315 | SCOPED_TRACE("before anything"); |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4316 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4317 | mCapture->expectChildColor(64, 64); |
| 4318 | } |
| 4319 | } |
| 4320 | void TearDown() override { |
| 4321 | LayerUpdateTest::TearDown(); |
| 4322 | mChild = 0; |
| 4323 | } |
| 4324 | |
| 4325 | sp<SurfaceControl> mChild; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4326 | std::unique_ptr<ScreenCapture> mCapture; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4327 | }; |
| 4328 | |
| 4329 | TEST_F(ChildLayerTest, ChildLayerPositioning) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4330 | asTransaction([&](Transaction& t) { |
| 4331 | t.show(mChild); |
| 4332 | t.setPosition(mChild, 10, 10); |
| 4333 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4334 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4335 | |
| 4336 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4337 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4338 | // Top left of foreground must now be visible |
| 4339 | mCapture->expectFGColor(64, 64); |
| 4340 | // But 10 pixels in we should see the child surface |
| 4341 | mCapture->expectChildColor(74, 74); |
| 4342 | // And 10 more pixels we should be back to the foreground surface |
| 4343 | mCapture->expectFGColor(84, 84); |
| 4344 | } |
| 4345 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4346 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4347 | |
| 4348 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4349 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4350 | // Top left of foreground should now be at 0, 0 |
| 4351 | mCapture->expectFGColor(0, 0); |
| 4352 | // But 10 pixels in we should see the child surface |
| 4353 | mCapture->expectChildColor(10, 10); |
| 4354 | // And 10 more pixels we should be back to the foreground surface |
| 4355 | mCapture->expectFGColor(20, 20); |
| 4356 | } |
| 4357 | } |
| 4358 | |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4359 | TEST_F(ChildLayerTest, ChildLayerCropping) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4360 | asTransaction([&](Transaction& t) { |
| 4361 | t.show(mChild); |
| 4362 | t.setPosition(mChild, 0, 0); |
| 4363 | t.setPosition(mFGSurfaceControl, 0, 0); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4364 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 5, 5)); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4365 | }); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4366 | |
| 4367 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4368 | mCapture = screenshot(); |
Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4369 | mCapture->expectChildColor(0, 0); |
| 4370 | mCapture->expectChildColor(4, 4); |
| 4371 | mCapture->expectBGColor(5, 5); |
| 4372 | } |
| 4373 | } |
| 4374 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4375 | TEST_F(ChildLayerTest, ChildLayerConstraints) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4376 | asTransaction([&](Transaction& t) { |
| 4377 | t.show(mChild); |
| 4378 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4379 | t.setPosition(mChild, 63, 63); |
| 4380 | }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4381 | |
| 4382 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4383 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4384 | mCapture->expectFGColor(0, 0); |
| 4385 | // Last pixel in foreground should now be the child. |
| 4386 | mCapture->expectChildColor(63, 63); |
| 4387 | // But the child should be constrained and the next pixel |
| 4388 | // must be the background |
| 4389 | mCapture->expectBGColor(64, 64); |
| 4390 | } |
| 4391 | } |
| 4392 | |
| 4393 | TEST_F(ChildLayerTest, ChildLayerScaling) { |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4394 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4395 | |
| 4396 | // Find the boundary between the parent and child |
| 4397 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4398 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4399 | mCapture->expectChildColor(9, 9); |
| 4400 | mCapture->expectFGColor(10, 10); |
| 4401 | } |
| 4402 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4403 | asTransaction([&](Transaction& t) { t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0); }); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4404 | |
| 4405 | // The boundary should be twice as far from the origin now. |
| 4406 | // The pixels from the last test should all be child now |
| 4407 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4408 | mCapture = screenshot(); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4409 | mCapture->expectChildColor(9, 9); |
| 4410 | mCapture->expectChildColor(10, 10); |
| 4411 | mCapture->expectChildColor(19, 19); |
| 4412 | mCapture->expectFGColor(20, 20); |
| 4413 | } |
| 4414 | } |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4415 | |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame^] | 4416 | // A child with a scale transform should be cropped by its parent bounds. |
| 4417 | TEST_F(ChildLayerTest, ChildLayerScalingCroppedByParent) { |
| 4418 | asTransaction([&](Transaction& t) { |
| 4419 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4420 | t.setPosition(mChild, 0, 0); |
| 4421 | }); |
| 4422 | |
| 4423 | // Find the boundary between the parent and child. |
| 4424 | { |
| 4425 | mCapture = screenshot(); |
| 4426 | mCapture->expectChildColor(0, 0); |
| 4427 | mCapture->expectChildColor(9, 9); |
| 4428 | mCapture->expectFGColor(10, 10); |
| 4429 | } |
| 4430 | |
| 4431 | asTransaction([&](Transaction& t) { t.setMatrix(mChild, 10.0, 0, 0, 10.0); }); |
| 4432 | |
| 4433 | // The child should fill its parent bounds and be cropped by it. |
| 4434 | { |
| 4435 | mCapture = screenshot(); |
| 4436 | mCapture->expectChildColor(0, 0); |
| 4437 | mCapture->expectChildColor(63, 63); |
| 4438 | mCapture->expectBGColor(64, 64); |
| 4439 | } |
| 4440 | } |
| 4441 | |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4442 | TEST_F(ChildLayerTest, ChildLayerAlpha) { |
| 4443 | fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254); |
| 4444 | fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0); |
| 4445 | fillSurfaceRGBA8(mChild, 0, 254, 0); |
| 4446 | waitForPostedBuffers(); |
| 4447 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4448 | asTransaction([&](Transaction& t) { |
| 4449 | t.show(mChild); |
| 4450 | t.setPosition(mChild, 0, 0); |
| 4451 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4452 | }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4453 | |
| 4454 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4455 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4456 | // Unblended child color |
| 4457 | mCapture->checkPixel(0, 0, 0, 254, 0); |
| 4458 | } |
| 4459 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4460 | asTransaction([&](Transaction& t) { t.setAlpha(mChild, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4461 | |
| 4462 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4463 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4464 | // Child and BG blended. |
| 4465 | mCapture->checkPixel(0, 0, 127, 127, 0); |
| 4466 | } |
| 4467 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4468 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 0.5); }); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4469 | |
| 4470 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4471 | mCapture = screenshot(); |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4472 | // Child and BG blended. |
| 4473 | mCapture->checkPixel(0, 0, 95, 64, 95); |
| 4474 | } |
| 4475 | } |
| 4476 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4477 | TEST_F(ChildLayerTest, ReparentChildren) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4478 | asTransaction([&](Transaction& t) { |
| 4479 | t.show(mChild); |
| 4480 | t.setPosition(mChild, 10, 10); |
| 4481 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4482 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4483 | |
| 4484 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4485 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4486 | // Top left of foreground must now be visible |
| 4487 | mCapture->expectFGColor(64, 64); |
| 4488 | // But 10 pixels in we should see the child surface |
| 4489 | mCapture->expectChildColor(74, 74); |
| 4490 | // And 10 more pixels we should be back to the foreground surface |
| 4491 | mCapture->expectFGColor(84, 84); |
| 4492 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4493 | |
| 4494 | asTransaction([&](Transaction& t) { |
| 4495 | t.reparentChildren(mFGSurfaceControl, mBGSurfaceControl->getHandle()); |
| 4496 | }); |
| 4497 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4498 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4499 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4500 | mCapture->expectFGColor(64, 64); |
| 4501 | // In reparenting we should have exposed the entire foreground surface. |
| 4502 | mCapture->expectFGColor(74, 74); |
| 4503 | // And the child layer should now begin at 10, 10 (since the BG |
| 4504 | // layer is at (0, 0)). |
| 4505 | mCapture->expectBGColor(9, 9); |
| 4506 | mCapture->expectChildColor(10, 10); |
| 4507 | } |
| 4508 | } |
| 4509 | |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4510 | TEST_F(ChildLayerTest, ChildrenSurviveParentDestruction) { |
| 4511 | sp<SurfaceControl> mGrandChild = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4512 | 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] | 4513 | fillSurfaceRGBA8(mGrandChild, 111, 111, 111); |
| 4514 | |
| 4515 | { |
| 4516 | SCOPED_TRACE("Grandchild visible"); |
| 4517 | ScreenCapture::captureScreen(&mCapture); |
| 4518 | mCapture->checkPixel(64, 64, 111, 111, 111); |
| 4519 | } |
| 4520 | |
Robert Carr | 8724653 | 2019-02-04 15:20:26 -0800 | [diff] [blame] | 4521 | mChild.clear(); |
Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4522 | |
| 4523 | { |
| 4524 | SCOPED_TRACE("After destroying child"); |
| 4525 | ScreenCapture::captureScreen(&mCapture); |
| 4526 | mCapture->expectFGColor(64, 64); |
| 4527 | } |
| 4528 | |
| 4529 | asTransaction([&](Transaction& t) { |
| 4530 | t.reparent(mGrandChild, mFGSurfaceControl->getHandle()); |
| 4531 | }); |
| 4532 | |
| 4533 | { |
| 4534 | SCOPED_TRACE("After reparenting grandchild"); |
| 4535 | ScreenCapture::captureScreen(&mCapture); |
| 4536 | mCapture->checkPixel(64, 64, 111, 111, 111); |
| 4537 | } |
| 4538 | } |
| 4539 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4540 | TEST_F(ChildLayerTest, DetachChildrenSameClient) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4541 | asTransaction([&](Transaction& t) { |
| 4542 | t.show(mChild); |
| 4543 | t.setPosition(mChild, 10, 10); |
| 4544 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4545 | }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4546 | |
| 4547 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4548 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4549 | // Top left of foreground must now be visible |
| 4550 | mCapture->expectFGColor(64, 64); |
| 4551 | // But 10 pixels in we should see the child surface |
| 4552 | mCapture->expectChildColor(74, 74); |
| 4553 | // And 10 more pixels we should be back to the foreground surface |
| 4554 | mCapture->expectFGColor(84, 84); |
| 4555 | } |
| 4556 | |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4557 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4558 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4559 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4560 | asTransaction([&](Transaction& t) { t.hide(mChild); }); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4561 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4562 | // Since the child has the same client as the parent, it will not get |
| 4563 | // detached and will be hidden. |
| 4564 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4565 | mCapture = screenshot(); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4566 | mCapture->expectFGColor(64, 64); |
| 4567 | mCapture->expectFGColor(74, 74); |
| 4568 | mCapture->expectFGColor(84, 84); |
| 4569 | } |
| 4570 | } |
| 4571 | |
| 4572 | TEST_F(ChildLayerTest, DetachChildrenDifferentClient) { |
| 4573 | sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient; |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4574 | sp<SurfaceControl> mChildNewClient = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4575 | createSurface(mNewComposerClient, "New Child Test Surface", 10, 10, |
| 4576 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4577 | |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4578 | ASSERT_TRUE(mChildNewClient->isValid()); |
| 4579 | |
| 4580 | fillSurfaceRGBA8(mChildNewClient, 200, 200, 200); |
| 4581 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4582 | asTransaction([&](Transaction& t) { |
| 4583 | t.hide(mChild); |
| 4584 | t.show(mChildNewClient); |
| 4585 | t.setPosition(mChildNewClient, 10, 10); |
| 4586 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4587 | }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4588 | |
| 4589 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4590 | mCapture = screenshot(); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4591 | // Top left of foreground must now be visible |
| 4592 | mCapture->expectFGColor(64, 64); |
| 4593 | // But 10 pixels in we should see the child surface |
| 4594 | mCapture->expectChildColor(74, 74); |
| 4595 | // And 10 more pixels we should be back to the foreground surface |
| 4596 | mCapture->expectFGColor(84, 84); |
| 4597 | } |
| 4598 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4599 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4600 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4601 | asTransaction([&](Transaction& t) { t.hide(mChildNewClient); }); |
chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4602 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4603 | // Nothing should have changed. |
| 4604 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4605 | mCapture = screenshot(); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4606 | mCapture->expectFGColor(64, 64); |
| 4607 | mCapture->expectChildColor(74, 74); |
| 4608 | mCapture->expectFGColor(84, 84); |
| 4609 | } |
| 4610 | } |
| 4611 | |
chaviw | 5aedec9 | 2018-10-22 10:40:38 -0700 | [diff] [blame] | 4612 | TEST_F(ChildLayerTest, DetachChildrenThenAttach) { |
| 4613 | sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; |
| 4614 | sp<SurfaceControl> childNewClient = |
| 4615 | newComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, |
| 4616 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 4617 | |
| 4618 | ASSERT_TRUE(childNewClient != nullptr); |
| 4619 | ASSERT_TRUE(childNewClient->isValid()); |
| 4620 | |
| 4621 | fillSurfaceRGBA8(childNewClient, 200, 200, 200); |
| 4622 | |
| 4623 | Transaction() |
| 4624 | .hide(mChild) |
| 4625 | .show(childNewClient) |
| 4626 | .setPosition(childNewClient, 10, 10) |
| 4627 | .setPosition(mFGSurfaceControl, 64, 64) |
| 4628 | .apply(); |
| 4629 | |
| 4630 | { |
| 4631 | mCapture = screenshot(); |
| 4632 | // Top left of foreground must now be visible |
| 4633 | mCapture->expectFGColor(64, 64); |
| 4634 | // But 10 pixels in we should see the child surface |
| 4635 | mCapture->expectChildColor(74, 74); |
| 4636 | // And 10 more pixels we should be back to the foreground surface |
| 4637 | mCapture->expectFGColor(84, 84); |
| 4638 | } |
| 4639 | |
| 4640 | Transaction().detachChildren(mFGSurfaceControl).apply(); |
| 4641 | Transaction().hide(childNewClient).apply(); |
| 4642 | |
| 4643 | // Nothing should have changed. |
| 4644 | { |
| 4645 | mCapture = screenshot(); |
| 4646 | mCapture->expectFGColor(64, 64); |
| 4647 | mCapture->expectChildColor(74, 74); |
| 4648 | mCapture->expectFGColor(84, 84); |
| 4649 | } |
| 4650 | |
| 4651 | sp<SurfaceControl> newParentSurface = createLayer(String8("New Parent Surface"), 32, 32, 0); |
| 4652 | fillLayerColor(ISurfaceComposerClient::eFXSurfaceBufferQueue, newParentSurface, Color::RED, 32, |
| 4653 | 32); |
| 4654 | Transaction() |
| 4655 | .setLayer(newParentSurface, INT32_MAX - 1) |
| 4656 | .show(newParentSurface) |
| 4657 | .setPosition(newParentSurface, 20, 20) |
| 4658 | .reparent(childNewClient, newParentSurface->getHandle()) |
| 4659 | .apply(); |
| 4660 | { |
| 4661 | mCapture = screenshot(); |
| 4662 | // Child is now hidden. |
| 4663 | mCapture->expectColor(Rect(20, 20, 52, 52), Color::RED); |
| 4664 | } |
| 4665 | } |
| 4666 | |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4667 | TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4668 | asTransaction([&](Transaction& t) { |
| 4669 | t.show(mChild); |
| 4670 | t.setPosition(mChild, 0, 0); |
| 4671 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4672 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4673 | |
| 4674 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4675 | mCapture = screenshot(); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4676 | // We've positioned the child in the top left. |
| 4677 | mCapture->expectChildColor(0, 0); |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame^] | 4678 | // But it's only 10x15. |
| 4679 | mCapture->expectFGColor(10, 15); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4680 | } |
| 4681 | |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4682 | asTransaction([&](Transaction& t) { |
| 4683 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 4684 | // We cause scaling by 2. |
| 4685 | t.setSize(mFGSurfaceControl, 128, 128); |
| 4686 | }); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4687 | |
| 4688 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4689 | mCapture = screenshot(); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4690 | // We've positioned the child in the top left. |
| 4691 | mCapture->expectChildColor(0, 0); |
| 4692 | mCapture->expectChildColor(10, 10); |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame^] | 4693 | mCapture->expectChildColor(19, 29); |
| 4694 | // And now it should be scaled all the way to 20x30 |
| 4695 | mCapture->expectFGColor(20, 30); |
Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4696 | } |
| 4697 | } |
| 4698 | |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4699 | // Regression test for b/37673612 |
| 4700 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4701 | asTransaction([&](Transaction& t) { |
| 4702 | t.show(mChild); |
| 4703 | t.setPosition(mChild, 0, 0); |
| 4704 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4705 | }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4706 | |
| 4707 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4708 | mCapture = screenshot(); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4709 | // We've positioned the child in the top left. |
| 4710 | mCapture->expectChildColor(0, 0); |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame^] | 4711 | mCapture->expectChildColor(9, 14); |
| 4712 | // But it's only 10x15. |
| 4713 | mCapture->expectFGColor(10, 15); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4714 | } |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4715 | // We set things up as in b/37673612 so that there is a mismatch between the buffer size and |
| 4716 | // the WM specified state size. |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4717 | asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); }); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4718 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 4719 | auto anw = static_cast<ANativeWindow*>(s.get()); |
| 4720 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 4721 | native_window_set_buffers_dimensions(anw, 64, 128); |
| 4722 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 4723 | waitForPostedBuffers(); |
| 4724 | |
| 4725 | { |
| 4726 | // The child should still be in the same place and not have any strange scaling as in |
| 4727 | // b/37673612. |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4728 | mCapture = screenshot(); |
Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4729 | mCapture->expectChildColor(0, 0); |
| 4730 | mCapture->expectFGColor(10, 10); |
| 4731 | } |
| 4732 | } |
| 4733 | |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame^] | 4734 | // A child with a buffer transform from its parents should be cropped by its parent bounds. |
| 4735 | TEST_F(ChildLayerTest, ChildCroppedByParentWithBufferTransform) { |
| 4736 | asTransaction([&](Transaction& t) { |
| 4737 | t.show(mChild); |
| 4738 | t.setPosition(mChild, 0, 0); |
| 4739 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4740 | t.setSize(mChild, 100, 100); |
| 4741 | }); |
| 4742 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 4743 | |
| 4744 | { |
| 4745 | mCapture = screenshot(); |
| 4746 | |
| 4747 | mCapture->expectChildColor(0, 0); |
| 4748 | mCapture->expectChildColor(63, 63); |
| 4749 | mCapture->expectBGColor(64, 64); |
| 4750 | } |
| 4751 | |
| 4752 | asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); }); |
| 4753 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 4754 | auto anw = static_cast<ANativeWindow*>(s.get()); |
| 4755 | // Apply a 90 transform on the buffer. |
| 4756 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 4757 | native_window_set_buffers_dimensions(anw, 64, 128); |
| 4758 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 4759 | waitForPostedBuffers(); |
| 4760 | |
| 4761 | // The child should be cropped by the new parent bounds. |
| 4762 | { |
| 4763 | mCapture = screenshot(); |
| 4764 | mCapture->expectChildColor(0, 0); |
| 4765 | mCapture->expectChildColor(99, 63); |
| 4766 | mCapture->expectFGColor(100, 63); |
| 4767 | mCapture->expectBGColor(128, 64); |
| 4768 | } |
| 4769 | } |
| 4770 | |
| 4771 | // A child with a scale transform from its parents should be cropped by its parent bounds. |
| 4772 | TEST_F(ChildLayerTest, ChildCroppedByParentWithBufferScale) { |
| 4773 | asTransaction([&](Transaction& t) { |
| 4774 | t.show(mChild); |
| 4775 | t.setPosition(mChild, 0, 0); |
| 4776 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4777 | t.setSize(mChild, 200, 200); |
| 4778 | }); |
| 4779 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 4780 | |
| 4781 | { |
| 4782 | mCapture = screenshot(); |
| 4783 | |
| 4784 | mCapture->expectChildColor(0, 0); |
| 4785 | mCapture->expectChildColor(63, 63); |
| 4786 | mCapture->expectBGColor(64, 64); |
| 4787 | } |
| 4788 | |
| 4789 | asTransaction([&](Transaction& t) { |
| 4790 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 4791 | // Set a scaling by 2. |
| 4792 | t.setSize(mFGSurfaceControl, 128, 128); |
| 4793 | }); |
| 4794 | |
| 4795 | // Child should inherit its parents scale but should be cropped by its parent bounds. |
| 4796 | { |
| 4797 | mCapture = screenshot(); |
| 4798 | mCapture->expectChildColor(0, 0); |
| 4799 | mCapture->expectChildColor(127, 127); |
| 4800 | mCapture->expectBGColor(128, 128); |
| 4801 | } |
| 4802 | } |
| 4803 | |
| 4804 | // Regression test for b/127368943 |
| 4805 | // Child should ignore the buffer transform but apply parent scale transform. |
| 4806 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransformAndScale) { |
| 4807 | asTransaction([&](Transaction& t) { |
| 4808 | t.show(mChild); |
| 4809 | t.setPosition(mChild, 0, 0); |
| 4810 | t.setPosition(mFGSurfaceControl, 0, 0); |
| 4811 | }); |
| 4812 | |
| 4813 | { |
| 4814 | mCapture = screenshot(); |
| 4815 | mCapture->expectChildColor(0, 0); |
| 4816 | mCapture->expectChildColor(9, 14); |
| 4817 | mCapture->expectFGColor(10, 15); |
| 4818 | } |
| 4819 | |
| 4820 | // Change the size of the foreground to 128 * 64 so we can test rotation as well. |
| 4821 | asTransaction([&](Transaction& t) { |
| 4822 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 4823 | t.setSize(mFGSurfaceControl, 128, 64); |
| 4824 | }); |
| 4825 | sp<Surface> s = mFGSurfaceControl->getSurface(); |
| 4826 | auto anw = static_cast<ANativeWindow*>(s.get()); |
| 4827 | // Apply a 90 transform on the buffer and submit a buffer half the expected size so that we |
| 4828 | // have an effective scale of 2.0 applied to the buffer along with a rotation transform. |
| 4829 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 4830 | native_window_set_buffers_dimensions(anw, 32, 64); |
| 4831 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); |
| 4832 | waitForPostedBuffers(); |
| 4833 | |
| 4834 | // The child should ignore the buffer transform but apply the 2.0 scale from parent. |
| 4835 | { |
| 4836 | mCapture = screenshot(); |
| 4837 | mCapture->expectChildColor(0, 0); |
| 4838 | mCapture->expectChildColor(19, 29); |
| 4839 | mCapture->expectFGColor(20, 30); |
| 4840 | } |
| 4841 | } |
| 4842 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 4843 | TEST_F(ChildLayerTest, Bug36858924) { |
| 4844 | // Destroy the child layer |
| 4845 | mChild.clear(); |
| 4846 | |
| 4847 | // Now recreate it as hidden |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4848 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, |
| 4849 | ISurfaceComposerClient::eHidden, mFGSurfaceControl.get()); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 4850 | |
| 4851 | // Show the child layer in a deferred transaction |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4852 | asTransaction([&](Transaction& t) { |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4853 | t.deferTransactionUntil_legacy(mChild, mFGSurfaceControl->getHandle(), |
| 4854 | mFGSurfaceControl->getSurface()->getNextFrameNumber()); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4855 | t.show(mChild); |
| 4856 | }); |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 4857 | |
| 4858 | // Render the foreground surface a few times |
| 4859 | // |
| 4860 | // Prior to the bugfix for b/36858924, this would usually hang while trying to fill the third |
| 4861 | // frame because SurfaceFlinger would never process the deferred transaction and would therefore |
| 4862 | // never acquire/release the first buffer |
| 4863 | ALOGI("Filling 1"); |
| 4864 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 4865 | ALOGI("Filling 2"); |
| 4866 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 0, 255); |
| 4867 | ALOGI("Filling 3"); |
| 4868 | fillSurfaceRGBA8(mFGSurfaceControl, 255, 0, 0); |
| 4869 | ALOGI("Filling 4"); |
| 4870 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); |
| 4871 | } |
| 4872 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4873 | TEST_F(ChildLayerTest, Reparent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4874 | asTransaction([&](Transaction& t) { |
| 4875 | t.show(mChild); |
| 4876 | t.setPosition(mChild, 10, 10); |
| 4877 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4878 | }); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4879 | |
| 4880 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4881 | mCapture = screenshot(); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4882 | // Top left of foreground must now be visible |
| 4883 | mCapture->expectFGColor(64, 64); |
| 4884 | // But 10 pixels in we should see the child surface |
| 4885 | mCapture->expectChildColor(74, 74); |
| 4886 | // And 10 more pixels we should be back to the foreground surface |
| 4887 | mCapture->expectFGColor(84, 84); |
| 4888 | } |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4889 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4890 | asTransaction([&](Transaction& t) { t.reparent(mChild, mBGSurfaceControl->getHandle()); }); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4891 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4892 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4893 | mCapture = screenshot(); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4894 | mCapture->expectFGColor(64, 64); |
| 4895 | // In reparenting we should have exposed the entire foreground surface. |
| 4896 | mCapture->expectFGColor(74, 74); |
| 4897 | // And the child layer should now begin at 10, 10 (since the BG |
| 4898 | // layer is at (0, 0)). |
| 4899 | mCapture->expectBGColor(9, 9); |
| 4900 | mCapture->expectChildColor(10, 10); |
| 4901 | } |
| 4902 | } |
| 4903 | |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4904 | TEST_F(ChildLayerTest, ReparentToNoParent) { |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4905 | asTransaction([&](Transaction& t) { |
| 4906 | t.show(mChild); |
| 4907 | t.setPosition(mChild, 10, 10); |
| 4908 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4909 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4910 | |
| 4911 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4912 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4913 | // Top left of foreground must now be visible |
| 4914 | mCapture->expectFGColor(64, 64); |
| 4915 | // But 10 pixels in we should see the child surface |
| 4916 | mCapture->expectChildColor(74, 74); |
| 4917 | // And 10 more pixels we should be back to the foreground surface |
| 4918 | mCapture->expectFGColor(84, 84); |
| 4919 | } |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4920 | asTransaction([&](Transaction& t) { t.reparent(mChild, nullptr); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4921 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4922 | mCapture = screenshot(); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4923 | // The surface should now be offscreen. |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4924 | mCapture->expectFGColor(64, 64); |
Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4925 | mCapture->expectFGColor(74, 74); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4926 | mCapture->expectFGColor(84, 84); |
| 4927 | } |
| 4928 | } |
| 4929 | |
| 4930 | TEST_F(ChildLayerTest, ReparentFromNoParent) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4931 | sp<SurfaceControl> newSurface = createLayer(String8("New Surface"), 10, 10, 0); |
Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 4932 | ASSERT_TRUE(newSurface != nullptr); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4933 | ASSERT_TRUE(newSurface->isValid()); |
| 4934 | |
| 4935 | fillSurfaceRGBA8(newSurface, 63, 195, 63); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4936 | asTransaction([&](Transaction& t) { |
| 4937 | t.hide(mChild); |
| 4938 | t.show(newSurface); |
| 4939 | t.setPosition(newSurface, 10, 10); |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4940 | t.setLayer(newSurface, INT32_MAX - 2); |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4941 | t.setPosition(mFGSurfaceControl, 64, 64); |
| 4942 | }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4943 | |
| 4944 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4945 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4946 | // Top left of foreground must now be visible |
| 4947 | mCapture->expectFGColor(64, 64); |
| 4948 | // At 10, 10 we should see the new surface |
| 4949 | mCapture->checkPixel(10, 10, 63, 195, 63); |
| 4950 | } |
| 4951 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4952 | asTransaction([&](Transaction& t) { t.reparent(newSurface, mFGSurfaceControl->getHandle()); }); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4953 | |
| 4954 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4955 | mCapture = screenshot(); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4956 | // newSurface will now be a child of mFGSurface so it will be 10, 10 offset from |
| 4957 | // mFGSurface, putting it at 74, 74. |
| 4958 | mCapture->expectFGColor(64, 64); |
| 4959 | mCapture->checkPixel(74, 74, 63, 195, 63); |
| 4960 | mCapture->expectFGColor(84, 84); |
| 4961 | } |
| 4962 | } |
| 4963 | |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 4964 | TEST_F(ChildLayerTest, NestedChildren) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4965 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 10, 10, |
| 4966 | PIXEL_FORMAT_RGBA_8888, 0, mChild.get()); |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 4967 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 4968 | |
| 4969 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4970 | mCapture = screenshot(); |
chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 4971 | // Expect the grandchild to begin at 64, 64 because it's a child of mChild layer |
| 4972 | // which begins at 64, 64 |
| 4973 | mCapture->checkPixel(64, 64, 50, 50, 50); |
| 4974 | } |
| 4975 | } |
| 4976 | |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4977 | TEST_F(ChildLayerTest, ChildLayerRelativeLayer) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4978 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 128, 128, 0); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4979 | fillSurfaceRGBA8(relative, 255, 255, 255); |
| 4980 | |
| 4981 | Transaction t; |
| 4982 | t.setLayer(relative, INT32_MAX) |
| 4983 | .setRelativeLayer(mChild, relative->getHandle(), 1) |
| 4984 | .setPosition(mFGSurfaceControl, 0, 0) |
| 4985 | .apply(true); |
| 4986 | |
| 4987 | // We expect that the child should have been elevated above our |
| 4988 | // INT_MAX layer even though it's not a child of it. |
| 4989 | { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4990 | mCapture = screenshot(); |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4991 | mCapture->expectChildColor(0, 0); |
| 4992 | mCapture->expectChildColor(9, 9); |
| 4993 | mCapture->checkPixel(10, 10, 255, 255, 255); |
| 4994 | } |
| 4995 | } |
Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame^] | 4996 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4997 | class BoundlessLayerTest : public LayerUpdateTest { |
| 4998 | protected: |
| 4999 | std::unique_ptr<ScreenCapture> mCapture; |
| 5000 | }; |
| 5001 | |
| 5002 | // Verify setting a size on a buffer layer has no effect. |
| 5003 | TEST_F(BoundlessLayerTest, BufferLayerIgnoresSize) { |
| 5004 | sp<SurfaceControl> bufferLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5005 | createSurface(mClient, "BufferLayer", 45, 45, PIXEL_FORMAT_RGBA_8888, 0, |
| 5006 | mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5007 | ASSERT_TRUE(bufferLayer->isValid()); |
| 5008 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::BLACK, 30, 30)); |
| 5009 | asTransaction([&](Transaction& t) { t.show(bufferLayer); }); |
| 5010 | { |
| 5011 | mCapture = screenshot(); |
| 5012 | // Top left of background must now be visible |
| 5013 | mCapture->expectBGColor(0, 0); |
| 5014 | // Foreground Surface bounds must be color layer |
| 5015 | mCapture->expectColor(Rect(64, 64, 94, 94), Color::BLACK); |
| 5016 | // Buffer layer should not extend past buffer bounds |
| 5017 | mCapture->expectFGColor(95, 95); |
| 5018 | } |
| 5019 | } |
| 5020 | |
| 5021 | // Verify a boundless color layer will fill its parent bounds. The parent has a buffer size |
| 5022 | // which will crop the color layer. |
| 5023 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentBufferBounds) { |
| 5024 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5025 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5026 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5027 | ASSERT_TRUE(colorLayer->isValid()); |
| 5028 | asTransaction([&](Transaction& t) { |
| 5029 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 5030 | t.show(colorLayer); |
| 5031 | }); |
| 5032 | { |
| 5033 | mCapture = screenshot(); |
| 5034 | // Top left of background must now be visible |
| 5035 | mCapture->expectBGColor(0, 0); |
| 5036 | // Foreground Surface bounds must be color layer |
| 5037 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 5038 | // Color layer should not extend past foreground bounds |
| 5039 | mCapture->expectBGColor(129, 129); |
| 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | // Verify a boundless color layer will fill its parent bounds. The parent has no buffer but has |
| 5044 | // a crop which will be used to crop the color layer. |
| 5045 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentCropBounds) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5046 | sp<SurfaceControl> cropLayer = createSurface(mClient, "CropLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5047 | 0 /* flags */, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5048 | ASSERT_TRUE(cropLayer->isValid()); |
| 5049 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5050 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5051 | ISurfaceComposerClient::eFXSurfaceColor, cropLayer.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5052 | ASSERT_TRUE(colorLayer->isValid()); |
| 5053 | asTransaction([&](Transaction& t) { |
| 5054 | t.setCrop_legacy(cropLayer, Rect(5, 5, 10, 10)); |
| 5055 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 5056 | t.show(cropLayer); |
| 5057 | t.show(colorLayer); |
| 5058 | }); |
| 5059 | { |
| 5060 | mCapture = screenshot(); |
| 5061 | // Top left of background must now be visible |
| 5062 | mCapture->expectBGColor(0, 0); |
| 5063 | // Top left of foreground must now be visible |
| 5064 | mCapture->expectFGColor(64, 64); |
| 5065 | // 5 pixels from the foreground we should see the child surface |
| 5066 | mCapture->expectColor(Rect(69, 69, 74, 74), Color::BLACK); |
| 5067 | // 10 pixels from the foreground we should be back to the foreground surface |
| 5068 | mCapture->expectFGColor(74, 74); |
| 5069 | } |
| 5070 | } |
| 5071 | |
| 5072 | // Verify for boundless layer with no children, their transforms have no effect. |
| 5073 | TEST_F(BoundlessLayerTest, BoundlessColorLayerTransformHasNoEffect) { |
| 5074 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5075 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5076 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5077 | ASSERT_TRUE(colorLayer->isValid()); |
| 5078 | asTransaction([&](Transaction& t) { |
| 5079 | t.setPosition(colorLayer, 320, 320); |
| 5080 | t.setMatrix(colorLayer, 2, 0, 0, 2); |
| 5081 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 5082 | t.show(colorLayer); |
| 5083 | }); |
| 5084 | { |
| 5085 | mCapture = screenshot(); |
| 5086 | // Top left of background must now be visible |
| 5087 | mCapture->expectBGColor(0, 0); |
| 5088 | // Foreground Surface bounds must be color layer |
| 5089 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 5090 | // Color layer should not extend past foreground bounds |
| 5091 | mCapture->expectBGColor(129, 129); |
| 5092 | } |
| 5093 | } |
| 5094 | |
| 5095 | // Verify for boundless layer with children, their transforms have an effect. |
| 5096 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerCanSetTransform) { |
| 5097 | sp<SurfaceControl> boundlessLayerRightShift = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5098 | createSurface(mClient, "BoundlessLayerRightShift", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5099 | 0 /* flags */, mFGSurfaceControl.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5100 | ASSERT_TRUE(boundlessLayerRightShift->isValid()); |
| 5101 | sp<SurfaceControl> boundlessLayerDownShift = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5102 | createSurface(mClient, "BoundlessLayerLeftShift", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5103 | 0 /* flags */, boundlessLayerRightShift.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5104 | ASSERT_TRUE(boundlessLayerDownShift->isValid()); |
| 5105 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5106 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5107 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayerDownShift.get()); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5108 | ASSERT_TRUE(colorLayer->isValid()); |
| 5109 | asTransaction([&](Transaction& t) { |
| 5110 | t.setPosition(boundlessLayerRightShift, 32, 0); |
| 5111 | t.show(boundlessLayerRightShift); |
| 5112 | t.setPosition(boundlessLayerDownShift, 0, 32); |
| 5113 | t.show(boundlessLayerDownShift); |
| 5114 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 5115 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 5116 | t.show(colorLayer); |
| 5117 | }); |
| 5118 | { |
| 5119 | mCapture = screenshot(); |
| 5120 | // Top left of background must now be visible |
| 5121 | mCapture->expectBGColor(0, 0); |
| 5122 | // Top left of foreground must now be visible |
| 5123 | mCapture->expectFGColor(64, 64); |
| 5124 | // Foreground Surface bounds must be color layer |
| 5125 | mCapture->expectColor(Rect(96, 96, 128, 128), Color::BLACK); |
| 5126 | // Color layer should not extend past foreground bounds |
| 5127 | mCapture->expectBGColor(129, 129); |
| 5128 | } |
| 5129 | } |
| 5130 | |
| 5131 | // Verify child layers do not get clipped if they temporarily move into the negative |
| 5132 | // coordinate space as the result of an intermediate transformation. |
| 5133 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerDoNotCrop) { |
| 5134 | sp<SurfaceControl> boundlessLayer = |
| 5135 | mClient->createSurface(String8("BoundlessLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5136 | 0 /* flags */, mFGSurfaceControl.get()); |
| 5137 | ASSERT_TRUE(boundlessLayer != nullptr); |
| 5138 | ASSERT_TRUE(boundlessLayer->isValid()); |
| 5139 | sp<SurfaceControl> colorLayer = |
| 5140 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5141 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayer.get()); |
| 5142 | ASSERT_TRUE(colorLayer != nullptr); |
| 5143 | ASSERT_TRUE(colorLayer->isValid()); |
| 5144 | asTransaction([&](Transaction& t) { |
| 5145 | // shift child layer off bounds. If this layer was not boundless, we will |
| 5146 | // expect the child layer to be cropped. |
| 5147 | t.setPosition(boundlessLayer, 32, 32); |
| 5148 | t.show(boundlessLayer); |
| 5149 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 5150 | // undo shift by parent |
| 5151 | t.setPosition(colorLayer, -32, -32); |
| 5152 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 5153 | t.show(colorLayer); |
| 5154 | }); |
| 5155 | { |
| 5156 | mCapture = screenshot(); |
| 5157 | // Top left of background must now be visible |
| 5158 | mCapture->expectBGColor(0, 0); |
| 5159 | // Foreground Surface bounds must be color layer |
| 5160 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); |
| 5161 | // Color layer should not extend past foreground bounds |
| 5162 | mCapture->expectBGColor(129, 129); |
| 5163 | } |
| 5164 | } |
| 5165 | |
| 5166 | // Verify for boundless root layers with children, their transforms have an effect. |
| 5167 | TEST_F(BoundlessLayerTest, RootBoundlessLayerCanSetTransform) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5168 | sp<SurfaceControl> rootBoundlessLayer = createSurface(mClient, "RootBoundlessLayer", 0, 0, |
| 5169 | PIXEL_FORMAT_RGBA_8888, 0 /* flags */); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5170 | ASSERT_TRUE(rootBoundlessLayer->isValid()); |
| 5171 | sp<SurfaceControl> colorLayer = |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5172 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, |
| 5173 | ISurfaceComposerClient::eFXSurfaceColor, rootBoundlessLayer.get()); |
| 5174 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5175 | ASSERT_TRUE(colorLayer->isValid()); |
| 5176 | asTransaction([&](Transaction& t) { |
| 5177 | t.setLayer(rootBoundlessLayer, INT32_MAX - 1); |
| 5178 | t.setPosition(rootBoundlessLayer, 32, 32); |
| 5179 | t.show(rootBoundlessLayer); |
| 5180 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); |
| 5181 | t.setColor(colorLayer, half3{0, 0, 0}); |
| 5182 | t.show(colorLayer); |
| 5183 | t.hide(mFGSurfaceControl); |
| 5184 | }); |
| 5185 | { |
| 5186 | mCapture = screenshot(); |
| 5187 | // Top left of background must now be visible |
| 5188 | mCapture->expectBGColor(0, 0); |
| 5189 | // Top left of foreground must now be visible |
| 5190 | mCapture->expectBGColor(31, 31); |
| 5191 | // Foreground Surface bounds must be color layer |
| 5192 | mCapture->expectColor(Rect(32, 32, 96, 96), Color::BLACK); |
| 5193 | // Color layer should not extend past foreground bounds |
| 5194 | mCapture->expectBGColor(97, 97); |
| 5195 | } |
| 5196 | } |
Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5197 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5198 | class ScreenCaptureTest : public LayerUpdateTest { |
| 5199 | protected: |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5200 | std::unique_ptr<ScreenCapture> mCapture; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5201 | }; |
| 5202 | |
| 5203 | TEST_F(ScreenCaptureTest, CaptureSingleLayer) { |
| 5204 | auto bgHandle = mBGSurfaceControl->getHandle(); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5205 | ScreenCapture::captureLayers(&mCapture, bgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5206 | mCapture->expectBGColor(0, 0); |
| 5207 | // Doesn't capture FG layer which is at 64, 64 |
| 5208 | mCapture->expectBGColor(64, 64); |
| 5209 | } |
| 5210 | |
| 5211 | TEST_F(ScreenCaptureTest, CaptureLayerWithChild) { |
| 5212 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 5213 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5214 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5215 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5216 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5217 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5218 | SurfaceComposerClient::Transaction().show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5219 | |
| 5220 | // Captures mFGSurfaceControl layer and its child. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5221 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5222 | mCapture->expectFGColor(10, 10); |
| 5223 | mCapture->expectChildColor(0, 0); |
| 5224 | } |
| 5225 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5226 | TEST_F(ScreenCaptureTest, CaptureLayerChildOnly) { |
| 5227 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 5228 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5229 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5230 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5231 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5232 | |
| 5233 | SurfaceComposerClient::Transaction().show(child).apply(true); |
| 5234 | |
| 5235 | // Captures mFGSurfaceControl's child |
| 5236 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); |
| 5237 | mCapture->checkPixel(10, 10, 0, 0, 0); |
| 5238 | mCapture->expectChildColor(0, 0); |
| 5239 | } |
| 5240 | |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 5241 | TEST_F(ScreenCaptureTest, CaptureTransparent) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5242 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5243 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 5244 | |
| 5245 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5246 | |
| 5247 | SurfaceComposerClient::Transaction().show(child).apply(true); |
| 5248 | |
| 5249 | auto childHandle = child->getHandle(); |
| 5250 | |
| 5251 | // Captures child |
| 5252 | ScreenCapture::captureLayers(&mCapture, childHandle, {0, 0, 10, 20}); |
| 5253 | mCapture->expectColor(Rect(0, 0, 9, 9), {200, 200, 200, 255}); |
| 5254 | // Area outside of child's bounds is transparent. |
| 5255 | mCapture->expectColor(Rect(0, 10, 9, 19), {0, 0, 0, 0}); |
| 5256 | } |
| 5257 | |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 5258 | TEST_F(ScreenCaptureTest, DontCaptureRelativeOutsideTree) { |
| 5259 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 5260 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5261 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5262 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 5263 | ASSERT_NE(nullptr, child.get()) << "failed to create surface"; |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5264 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 10, 10, 0); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 5265 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5266 | fillSurfaceRGBA8(relative, 100, 100, 100); |
| 5267 | |
| 5268 | SurfaceComposerClient::Transaction() |
| 5269 | .show(child) |
| 5270 | // Set relative layer above fg layer so should be shown above when computing all layers. |
| 5271 | .setRelativeLayer(relative, fgHandle, 1) |
| 5272 | .show(relative) |
| 5273 | .apply(true); |
| 5274 | |
| 5275 | // Captures mFGSurfaceControl layer and its child. Relative layer shouldn't be captured. |
| 5276 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
| 5277 | mCapture->expectFGColor(10, 10); |
| 5278 | mCapture->expectChildColor(0, 0); |
| 5279 | } |
| 5280 | |
| 5281 | TEST_F(ScreenCaptureTest, CaptureRelativeInTree) { |
| 5282 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 5283 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5284 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5285 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
| 5286 | sp<SurfaceControl> relative = createSurface(mClient, "Relative surface", 10, 10, |
| 5287 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 5288 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5289 | fillSurfaceRGBA8(relative, 100, 100, 100); |
| 5290 | |
| 5291 | SurfaceComposerClient::Transaction() |
| 5292 | .show(child) |
| 5293 | // Set relative layer below fg layer but relative to child layer so it should be shown |
| 5294 | // above child layer. |
| 5295 | .setLayer(relative, -1) |
| 5296 | .setRelativeLayer(relative, child->getHandle(), 1) |
| 5297 | .show(relative) |
| 5298 | .apply(true); |
| 5299 | |
| 5300 | // Captures mFGSurfaceControl layer and its children. Relative layer is a child of fg so its |
| 5301 | // relative value should be taken into account, placing it above child layer. |
| 5302 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
| 5303 | mCapture->expectFGColor(10, 10); |
| 5304 | // Relative layer is showing on top of child layer |
| 5305 | mCapture->expectColor(Rect(0, 0, 9, 9), {100, 100, 100, 255}); |
| 5306 | } |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5307 | |
| 5308 | // In the following tests we verify successful skipping of a parent layer, |
| 5309 | // so we use the same verification logic and only change how we mutate |
| 5310 | // the parent layer to verify that various properties are ignored. |
| 5311 | class ScreenCaptureChildOnlyTest : public LayerUpdateTest { |
| 5312 | public: |
| 5313 | void SetUp() override { |
| 5314 | LayerUpdateTest::SetUp(); |
| 5315 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5316 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, |
| 5317 | mFGSurfaceControl.get()); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5318 | fillSurfaceRGBA8(mChild, 200, 200, 200); |
| 5319 | |
| 5320 | SurfaceComposerClient::Transaction().show(mChild).apply(true); |
| 5321 | } |
| 5322 | |
Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5323 | void verify(std::function<void()> verifyStartingState) { |
| 5324 | // Verify starting state before a screenshot is taken. |
| 5325 | verifyStartingState(); |
| 5326 | |
| 5327 | // Verify child layer does not inherit any of the properties of its |
| 5328 | // parent when its screenshot is captured. |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5329 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 5330 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); |
| 5331 | mCapture->checkPixel(10, 10, 0, 0, 0); |
| 5332 | mCapture->expectChildColor(0, 0); |
Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5333 | |
| 5334 | // Verify all assumptions are still true after the screenshot is taken. |
| 5335 | verifyStartingState(); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | std::unique_ptr<ScreenCapture> mCapture; |
| 5339 | sp<SurfaceControl> mChild; |
| 5340 | }; |
| 5341 | |
Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5342 | // Regression test b/76099859 |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5343 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentVisibility) { |
| 5344 | |
| 5345 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); |
| 5346 | |
| 5347 | // Even though the parent is hidden we should still capture the child. |
Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5348 | |
| 5349 | // Before and after reparenting, verify child is properly hidden |
| 5350 | // when rendering full-screen. |
| 5351 | verify([&] { screenshot()->expectBGColor(64, 64); }); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5352 | } |
| 5353 | |
| 5354 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentCrop) { |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 5355 | SurfaceComposerClient::Transaction() |
| 5356 | .setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 1, 1)) |
| 5357 | .apply(true); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5358 | |
| 5359 | // Even though the parent is cropped out we should still capture the child. |
Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5360 | |
| 5361 | // Before and after reparenting, verify child is cropped by parent. |
| 5362 | verify([&] { screenshot()->expectBGColor(65, 65); }); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5363 | } |
| 5364 | |
Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5365 | // Regression test b/124372894 |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5366 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresTransform) { |
Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5367 | SurfaceComposerClient::Transaction().setMatrix(mFGSurfaceControl, 2, 0, 0, 2).apply(true); |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5368 | |
| 5369 | // We should not inherit the parent scaling. |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5370 | |
Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5371 | // Before and after reparenting, verify child is properly scaled. |
| 5372 | verify([&] { screenshot()->expectChildColor(80, 80); }); |
Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 5373 | } |
| 5374 | |
| 5375 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5376 | TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) { |
| 5377 | auto fgHandle = mFGSurfaceControl->getHandle(); |
| 5378 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5379 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5380 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5381 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5382 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5383 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, |
| 5384 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5385 | |
| 5386 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 5387 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5388 | .show(child) |
| 5389 | .setPosition(grandchild, 5, 5) |
| 5390 | .show(grandchild) |
| 5391 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5392 | |
| 5393 | // Captures mFGSurfaceControl, its child, and the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5394 | ScreenCapture::captureLayers(&mCapture, fgHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5395 | mCapture->expectFGColor(10, 10); |
| 5396 | mCapture->expectChildColor(0, 0); |
| 5397 | mCapture->checkPixel(5, 5, 50, 50, 50); |
| 5398 | } |
| 5399 | |
| 5400 | TEST_F(ScreenCaptureTest, CaptureChildOnly) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5401 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5402 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5403 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5404 | auto childHandle = child->getHandle(); |
| 5405 | |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5406 | SurfaceComposerClient::Transaction().setPosition(child, 5, 5).show(child).apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5407 | |
| 5408 | // Captures only the child layer, and not the parent. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5409 | ScreenCapture::captureLayers(&mCapture, childHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5410 | mCapture->expectChildColor(0, 0); |
| 5411 | mCapture->expectChildColor(9, 9); |
| 5412 | } |
| 5413 | |
| 5414 | TEST_F(ScreenCaptureTest, CaptureGrandchildOnly) { |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5415 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, |
| 5416 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5417 | fillSurfaceRGBA8(child, 200, 200, 200); |
| 5418 | auto childHandle = child->getHandle(); |
| 5419 | |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5420 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, |
| 5421 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5422 | fillSurfaceRGBA8(grandchild, 50, 50, 50); |
| 5423 | |
| 5424 | SurfaceComposerClient::Transaction() |
Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5425 | .show(child) |
| 5426 | .setPosition(grandchild, 5, 5) |
| 5427 | .show(grandchild) |
| 5428 | .apply(true); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5429 | |
| 5430 | auto grandchildHandle = grandchild->getHandle(); |
| 5431 | |
| 5432 | // Captures only the grandchild. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5433 | ScreenCapture::captureLayers(&mCapture, grandchildHandle); |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5434 | mCapture->checkPixel(0, 0, 50, 50, 50); |
| 5435 | mCapture->checkPixel(4, 4, 50, 50, 50); |
| 5436 | } |
| 5437 | |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5438 | TEST_F(ScreenCaptureTest, CaptureCrop) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5439 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5440 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, |
| 5441 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5442 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5443 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
| 5444 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5445 | |
| 5446 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5447 | .setLayer(redLayer, INT32_MAX - 1) |
| 5448 | .show(redLayer) |
| 5449 | .show(blueLayer) |
| 5450 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5451 | |
| 5452 | auto redLayerHandle = redLayer->getHandle(); |
| 5453 | |
| 5454 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5455 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 5456 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 5457 | // red area below the blue area |
| 5458 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 5459 | // red area to the right of the blue area |
| 5460 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5461 | |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 5462 | const Rect crop = Rect(0, 0, 30, 30); |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5463 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, crop); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5464 | // Capturing the cropped screen, cropping out the shown red area, should leave only the blue |
| 5465 | // area visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5466 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5467 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 5468 | } |
| 5469 | |
| 5470 | TEST_F(ScreenCaptureTest, CaptureSize) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5471 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5472 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, |
| 5473 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5474 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5475 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
| 5476 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5477 | |
| 5478 | SurfaceComposerClient::Transaction() |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5479 | .setLayer(redLayer, INT32_MAX - 1) |
| 5480 | .show(redLayer) |
| 5481 | .show(blueLayer) |
| 5482 | .apply(true); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5483 | |
| 5484 | auto redLayerHandle = redLayer->getHandle(); |
| 5485 | |
| 5486 | // Capturing full screen should have both red and blue are visible. |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5487 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); |
| 5488 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); |
| 5489 | // red area below the blue area |
| 5490 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); |
| 5491 | // red area to the right of the blue area |
| 5492 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5493 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5494 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, Rect::EMPTY_RECT, 0.5); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5495 | // 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] | 5496 | mCapture->expectColor(Rect(0, 0, 14, 14), Color::BLUE); |
| 5497 | // red area below the blue area |
| 5498 | mCapture->expectColor(Rect(0, 15, 29, 29), Color::RED); |
| 5499 | // red area to the right of the blue area |
| 5500 | mCapture->expectColor(Rect(15, 0, 29, 29), Color::RED); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5501 | mCapture->checkPixel(30, 30, 0, 0, 0); |
| 5502 | } |
| 5503 | |
| 5504 | TEST_F(ScreenCaptureTest, CaptureInvalidLayer) { |
chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5505 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5506 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5507 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5508 | |
| 5509 | auto redLayerHandle = redLayer->getHandle(); |
Robert Carr | 8724653 | 2019-02-04 15:20:26 -0800 | [diff] [blame] | 5510 | redLayer.clear(); |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5511 | SurfaceComposerClient::Transaction().apply(true); |
| 5512 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5513 | sp<GraphicBuffer> outBuffer; |
chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5514 | |
| 5515 | // Layer was deleted so captureLayers should fail with NAME_NOT_FOUND |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5516 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); |
| 5517 | 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] | 5518 | } |
| 5519 | |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5520 | |
| 5521 | class DereferenceSurfaceControlTest : public LayerTransactionTest { |
| 5522 | protected: |
| 5523 | void SetUp() override { |
| 5524 | LayerTransactionTest::SetUp(); |
| 5525 | bgLayer = createLayer("BG layer", 20, 20); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5526 | fillBufferQueueLayerColor(bgLayer, Color::RED, 20, 20); |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5527 | fgLayer = createLayer("FG layer", 20, 20); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5528 | fillBufferQueueLayerColor(fgLayer, Color::BLUE, 20, 20); |
chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5529 | Transaction().setLayer(fgLayer, mLayerZBase + 1).apply(); |
| 5530 | { |
| 5531 | SCOPED_TRACE("before anything"); |
| 5532 | auto shot = screenshot(); |
| 5533 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); |
| 5534 | } |
| 5535 | } |
| 5536 | void TearDown() override { |
| 5537 | LayerTransactionTest::TearDown(); |
| 5538 | bgLayer = 0; |
| 5539 | fgLayer = 0; |
| 5540 | } |
| 5541 | |
| 5542 | sp<SurfaceControl> bgLayer; |
| 5543 | sp<SurfaceControl> fgLayer; |
| 5544 | }; |
| 5545 | |
| 5546 | TEST_F(DereferenceSurfaceControlTest, LayerNotInTransaction) { |
| 5547 | fgLayer = nullptr; |
| 5548 | { |
| 5549 | SCOPED_TRACE("after setting null"); |
| 5550 | auto shot = screenshot(); |
| 5551 | shot->expectColor(Rect(0, 0, 20, 20), Color::RED); |
| 5552 | } |
| 5553 | } |
| 5554 | |
| 5555 | TEST_F(DereferenceSurfaceControlTest, LayerInTransaction) { |
| 5556 | auto transaction = Transaction().show(fgLayer); |
| 5557 | fgLayer = nullptr; |
| 5558 | { |
| 5559 | SCOPED_TRACE("after setting null"); |
| 5560 | auto shot = screenshot(); |
| 5561 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); |
| 5562 | } |
| 5563 | } |
| 5564 | |
Vishnu Nair | b927e1f | 2019-02-19 13:36:15 -0800 | [diff] [blame] | 5565 | class MultiDisplayLayerBoundsTest : public LayerTransactionTest { |
| 5566 | protected: |
| 5567 | virtual void SetUp() { |
| 5568 | LayerTransactionTest::SetUp(); |
| 5569 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); |
| 5570 | |
| 5571 | mMainDisplay = SurfaceComposerClient::getInternalDisplayToken(); |
| 5572 | SurfaceComposerClient::getDisplayInfo(mMainDisplay, &mMainDisplayInfo); |
| 5573 | |
| 5574 | sp<IGraphicBufferConsumer> consumer; |
| 5575 | BufferQueue::createBufferQueue(&mProducer, &consumer); |
| 5576 | consumer->setConsumerName(String8("Virtual disp consumer")); |
| 5577 | consumer->setDefaultBufferSize(mMainDisplayInfo.w, mMainDisplayInfo.h); |
| 5578 | } |
| 5579 | |
| 5580 | virtual void TearDown() { |
| 5581 | SurfaceComposerClient::destroyDisplay(mVirtualDisplay); |
| 5582 | LayerTransactionTest::TearDown(); |
| 5583 | mColorLayer = 0; |
| 5584 | } |
| 5585 | |
| 5586 | void createDisplay(const Rect& layerStackRect, uint32_t layerStack) { |
| 5587 | mVirtualDisplay = |
| 5588 | SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), false /*secure*/); |
| 5589 | asTransaction([&](Transaction& t) { |
| 5590 | t.setDisplaySurface(mVirtualDisplay, mProducer); |
| 5591 | t.setDisplayLayerStack(mVirtualDisplay, layerStack); |
| 5592 | t.setDisplayProjection(mVirtualDisplay, mMainDisplayInfo.orientation, layerStackRect, |
| 5593 | Rect(mMainDisplayInfo.w, mMainDisplayInfo.h)); |
| 5594 | }); |
| 5595 | } |
| 5596 | |
| 5597 | void createColorLayer(uint32_t layerStack) { |
| 5598 | mColorLayer = |
| 5599 | createSurface(mClient, "ColorLayer", 0 /* buffer width */, 0 /* buffer height */, |
| 5600 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor); |
| 5601 | ASSERT_TRUE(mColorLayer != nullptr); |
| 5602 | ASSERT_TRUE(mColorLayer->isValid()); |
| 5603 | asTransaction([&](Transaction& t) { |
| 5604 | t.setLayerStack(mColorLayer, layerStack); |
| 5605 | t.setCrop_legacy(mColorLayer, Rect(0, 0, 30, 40)); |
| 5606 | t.setLayer(mColorLayer, INT32_MAX - 2); |
| 5607 | t.setColor(mColorLayer, |
| 5608 | half3{mExpectedColor.r / 255.0f, mExpectedColor.g / 255.0f, |
| 5609 | mExpectedColor.b / 255.0f}); |
| 5610 | t.show(mColorLayer); |
| 5611 | }); |
| 5612 | } |
| 5613 | |
| 5614 | DisplayInfo mMainDisplayInfo; |
| 5615 | sp<IBinder> mMainDisplay; |
| 5616 | sp<IBinder> mVirtualDisplay; |
| 5617 | sp<IGraphicBufferProducer> mProducer; |
| 5618 | sp<SurfaceControl> mColorLayer; |
| 5619 | Color mExpectedColor = {63, 63, 195, 255}; |
| 5620 | }; |
| 5621 | |
| 5622 | TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInVirtualDisplay) { |
| 5623 | createDisplay({mMainDisplayInfo.viewportW, mMainDisplayInfo.viewportH}, 1 /* layerStack */); |
| 5624 | createColorLayer(1 /* layerStack */); |
| 5625 | |
| 5626 | asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); }); |
| 5627 | |
| 5628 | // Verify color layer does not render on main display. |
| 5629 | std::unique_ptr<ScreenCapture> sc; |
| 5630 | ScreenCapture::captureScreen(&sc, mMainDisplay); |
| 5631 | sc->expectColor(Rect(10, 10, 40, 50), {0, 0, 0, 255}); |
| 5632 | sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255}); |
| 5633 | |
| 5634 | // Verify color layer renders correctly on virtual display. |
| 5635 | ScreenCapture::captureScreen(&sc, mVirtualDisplay); |
| 5636 | sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor); |
| 5637 | sc->expectColor(Rect(1, 1, 9, 9), {0, 0, 0, 0}); |
| 5638 | } |
| 5639 | |
| 5640 | TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInMirroredVirtualDisplay) { |
| 5641 | // Create a display and set its layer stack to the main display's layer stack so |
| 5642 | // the contents of the main display are mirrored on to the virtual display. |
| 5643 | |
| 5644 | // Assumption here is that the new mirrored display has the same viewport as the |
| 5645 | // primary display that it is mirroring. |
| 5646 | createDisplay({mMainDisplayInfo.viewportW, mMainDisplayInfo.viewportH}, 0 /* layerStack */); |
| 5647 | createColorLayer(0 /* layerStack */); |
| 5648 | |
| 5649 | asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); }); |
| 5650 | |
| 5651 | // Verify color layer renders correctly on main display and it is mirrored on the |
| 5652 | // virtual display. |
| 5653 | std::unique_ptr<ScreenCapture> sc; |
| 5654 | ScreenCapture::captureScreen(&sc, mMainDisplay); |
| 5655 | sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor); |
| 5656 | sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255}); |
| 5657 | |
| 5658 | ScreenCapture::captureScreen(&sc, mVirtualDisplay); |
| 5659 | sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor); |
| 5660 | sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255}); |
| 5661 | } |
| 5662 | |
Ady Abraham | df9df4a | 2019-03-12 17:32:05 -0700 | [diff] [blame] | 5663 | class DisplayActiveConfigTest : public ::testing::Test { |
| 5664 | protected: |
| 5665 | void SetUp() override { |
| 5666 | mDisplayToken = SurfaceComposerClient::getInternalDisplayToken(); |
| 5667 | SurfaceComposerClient::getDisplayConfigs(mDisplayToken, &mDisplayconfigs); |
| 5668 | EXPECT_GT(mDisplayconfigs.size(), 0); |
| 5669 | |
| 5670 | // set display power to on to make sure config can be changed |
| 5671 | SurfaceComposerClient::setDisplayPowerMode(mDisplayToken, HWC_POWER_MODE_NORMAL); |
| 5672 | } |
| 5673 | |
| 5674 | sp<IBinder> mDisplayToken; |
| 5675 | Vector<DisplayInfo> mDisplayconfigs; |
| 5676 | }; |
| 5677 | |
| 5678 | TEST_F(DisplayActiveConfigTest, allConfigsAllowed) { |
| 5679 | std::vector<int32_t> allowedConfigs; |
| 5680 | |
| 5681 | // Add all configs to the allowed configs |
| 5682 | for (int i = 0; i < mDisplayconfigs.size(); i++) { |
| 5683 | allowedConfigs.push_back(i); |
| 5684 | } |
| 5685 | |
| 5686 | status_t res = SurfaceComposerClient::setAllowedDisplayConfigs(mDisplayToken, allowedConfigs); |
| 5687 | EXPECT_EQ(res, NO_ERROR); |
| 5688 | |
| 5689 | std::vector<int32_t> outConfigs; |
| 5690 | res = SurfaceComposerClient::getAllowedDisplayConfigs(mDisplayToken, &outConfigs); |
| 5691 | EXPECT_EQ(res, NO_ERROR); |
| 5692 | EXPECT_EQ(allowedConfigs, outConfigs); |
| 5693 | } |
| 5694 | |
| 5695 | TEST_F(DisplayActiveConfigTest, changeAllowedConfig) { |
| 5696 | // we need at least 2 configs available for this test |
| 5697 | if (mDisplayconfigs.size() <= 1) return; |
| 5698 | |
| 5699 | int activeConfig = SurfaceComposerClient::getActiveConfig(mDisplayToken); |
| 5700 | |
| 5701 | // We want to set the allowed config to everything but the active config |
| 5702 | std::vector<int32_t> allowedConfigs; |
| 5703 | for (int i = 0; i < mDisplayconfigs.size(); i++) { |
| 5704 | if (i != activeConfig) { |
| 5705 | allowedConfigs.push_back(i); |
| 5706 | } |
| 5707 | } |
| 5708 | |
| 5709 | status_t res = SurfaceComposerClient::setAllowedDisplayConfigs(mDisplayToken, allowedConfigs); |
| 5710 | EXPECT_EQ(res, NO_ERROR); |
| 5711 | |
| 5712 | // Allow some time for the config change |
| 5713 | std::this_thread::sleep_for(200ms); |
| 5714 | |
| 5715 | int newActiveConfig = SurfaceComposerClient::getActiveConfig(mDisplayToken); |
| 5716 | EXPECT_NE(activeConfig, newActiveConfig); |
| 5717 | |
| 5718 | // Make sure the new config is part of allowed config |
| 5719 | EXPECT_TRUE(std::find(allowedConfigs.begin(), allowedConfigs.end(), newActiveConfig) != |
| 5720 | allowedConfigs.end()); |
| 5721 | } |
| 5722 | |
Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5723 | } // namespace android |