| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2011 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 17 | #include <algorithm> | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 18 | #include <chrono> | 
|  | 19 | #include <cinttypes> | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 20 | #include <functional> | 
|  | 21 | #include <limits> | 
|  | 22 | #include <ostream> | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 23 | #include <thread> | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 24 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 25 | #include <gtest/gtest.h> | 
|  | 26 |  | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 27 | #include <android/native_window.h> | 
|  | 28 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 29 | #include <binder/ProcessState.h> | 
|  | 30 | #include <gui/BufferItemConsumer.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 31 | #include <gui/ISurfaceComposer.h> | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 32 | #include <gui/LayerState.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 33 | #include <gui/Surface.h> | 
|  | 34 | #include <gui/SurfaceComposerClient.h> | 
|  | 35 | #include <private/gui/ComposerService.h> | 
|  | 36 |  | 
| Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 37 | #include <ui/ColorSpace.h> | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 38 | #include <ui/DisplayInfo.h> | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 39 | #include <ui/Rect.h> | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 40 | #include <utils/String8.h> | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 41 |  | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 42 | #include <math.h> | 
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 43 | #include <math/vec3.h> | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 44 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 45 | #include "BufferGenerator.h" | 
|  | 46 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 47 | namespace android { | 
|  | 48 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 49 | namespace { | 
|  | 50 |  | 
|  | 51 | struct Color { | 
|  | 52 | uint8_t r; | 
|  | 53 | uint8_t g; | 
|  | 54 | uint8_t b; | 
|  | 55 | uint8_t a; | 
|  | 56 |  | 
|  | 57 | static const Color RED; | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 58 | static const Color GREEN; | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 59 | static const Color BLUE; | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 60 | static const Color WHITE; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 61 | static const Color BLACK; | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 62 | static const Color TRANSPARENT; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 63 | }; | 
|  | 64 |  | 
|  | 65 | const Color Color::RED{255, 0, 0, 255}; | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 66 | const Color Color::GREEN{0, 255, 0, 255}; | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 67 | const Color Color::BLUE{0, 0, 255, 255}; | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 68 | const Color Color::WHITE{255, 255, 255, 255}; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 69 | const Color Color::BLACK{0, 0, 0, 255}; | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 70 | const Color Color::TRANSPARENT{0, 0, 0, 0}; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 71 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 72 | using android::hardware::graphics::common::V1_1::BufferUsage; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 73 | using namespace std::chrono_literals; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 74 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 75 | std::ostream& operator<<(std::ostream& os, const Color& color) { | 
|  | 76 | os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a); | 
|  | 77 | return os; | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | // Fill a region with the specified color. | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 81 | void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect, | 
|  | 82 | const Color& color) { | 
|  | 83 | Rect r(0, 0, buffer.width, buffer.height); | 
|  | 84 | if (!r.intersect(rect, &r)) { | 
|  | 85 | return; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 86 | } | 
|  | 87 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 88 | int32_t width = r.right - r.left; | 
|  | 89 | int32_t height = r.bottom - r.top; | 
|  | 90 |  | 
|  | 91 | for (int32_t row = 0; row < height; row++) { | 
|  | 92 | uint8_t* dst = | 
|  | 93 | static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (r.top + row) + r.left) * 4; | 
|  | 94 | for (int32_t column = 0; column < width; column++) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 95 | dst[0] = color.r; | 
|  | 96 | dst[1] = color.g; | 
|  | 97 | dst[2] = color.b; | 
|  | 98 | dst[3] = color.a; | 
|  | 99 | dst += 4; | 
|  | 100 | } | 
|  | 101 | } | 
|  | 102 | } | 
|  | 103 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 104 | // Fill a region with the specified color. | 
|  | 105 | void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect, const Color& color) { | 
|  | 106 | Rect r(0, 0, buffer->width, buffer->height); | 
|  | 107 | if (!r.intersect(rect, &r)) { | 
|  | 108 | return; | 
|  | 109 | } | 
|  | 110 |  | 
|  | 111 | int32_t width = r.right - r.left; | 
|  | 112 | int32_t height = r.bottom - r.top; | 
|  | 113 |  | 
|  | 114 | uint8_t* pixels; | 
|  | 115 | buffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 116 | reinterpret_cast<void**>(&pixels)); | 
|  | 117 |  | 
|  | 118 | for (int32_t row = 0; row < height; row++) { | 
|  | 119 | uint8_t* dst = pixels + (buffer->getStride() * (r.top + row) + r.left) * 4; | 
|  | 120 | for (int32_t column = 0; column < width; column++) { | 
|  | 121 | dst[0] = color.r; | 
|  | 122 | dst[1] = color.g; | 
|  | 123 | dst[2] = color.b; | 
|  | 124 | dst[3] = color.a; | 
|  | 125 | dst += 4; | 
|  | 126 | } | 
|  | 127 | } | 
|  | 128 | buffer->unlock(); | 
|  | 129 | } | 
|  | 130 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 131 | // Check if a region has the specified color. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 132 | void expectBufferColor(const sp<GraphicBuffer>& outBuffer, uint8_t* pixels, const Rect& rect, | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 133 | const Color& color, uint8_t tolerance) { | 
|  | 134 | int32_t x = rect.left; | 
|  | 135 | int32_t y = rect.top; | 
|  | 136 | int32_t width = rect.right - rect.left; | 
|  | 137 | int32_t height = rect.bottom - rect.top; | 
|  | 138 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 139 | int32_t bufferWidth = int32_t(outBuffer->getWidth()); | 
|  | 140 | int32_t bufferHeight = int32_t(outBuffer->getHeight()); | 
|  | 141 | if (x + width > bufferWidth) { | 
|  | 142 | x = std::min(x, bufferWidth); | 
|  | 143 | width = bufferWidth - x; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 144 | } | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 145 | if (y + height > bufferHeight) { | 
|  | 146 | y = std::min(y, bufferHeight); | 
|  | 147 | height = bufferHeight - y; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 148 | } | 
|  | 149 |  | 
|  | 150 | auto colorCompare = [tolerance](uint8_t a, uint8_t b) { | 
|  | 151 | uint8_t tmp = a >= b ? a - b : b - a; | 
|  | 152 | return tmp <= tolerance; | 
|  | 153 | }; | 
|  | 154 | for (int32_t j = 0; j < height; j++) { | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 155 | const uint8_t* src = pixels + (outBuffer->getStride() * (y + j) + x) * 4; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 156 | for (int32_t i = 0; i < width; i++) { | 
|  | 157 | const uint8_t expected[4] = {color.r, color.g, color.b, color.a}; | 
|  | 158 | EXPECT_TRUE(std::equal(src, src + 4, expected, colorCompare)) | 
|  | 159 | << "pixel @ (" << x + i << ", " << y + j << "): " | 
|  | 160 | << "expected (" << color << "), " | 
|  | 161 | << "got (" << Color{src[0], src[1], src[2], src[3]} << ")"; | 
|  | 162 | src += 4; | 
|  | 163 | } | 
|  | 164 | } | 
|  | 165 | } | 
|  | 166 |  | 
|  | 167 | } // anonymous namespace | 
|  | 168 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 169 | using Transaction = SurfaceComposerClient::Transaction; | 
|  | 170 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 171 | // Fill an RGBA_8888 formatted surface with a single color. | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 172 | static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b, | 
|  | 173 | bool unlock = true) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 174 | ANativeWindow_Buffer outBuffer; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 175 | sp<Surface> s = sc->getSurface(); | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 176 | ASSERT_TRUE(s != nullptr); | 
|  | 177 | ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, nullptr)); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 178 | uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 179 | for (int y = 0; y < outBuffer.height; y++) { | 
|  | 180 | for (int x = 0; x < outBuffer.width; x++) { | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 181 | uint8_t* pixel = img + (4 * (y * outBuffer.stride + x)); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 182 | pixel[0] = r; | 
|  | 183 | pixel[1] = g; | 
|  | 184 | pixel[2] = b; | 
|  | 185 | pixel[3] = 255; | 
|  | 186 | } | 
|  | 187 | } | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 188 | if (unlock) { | 
|  | 189 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); | 
|  | 190 | } | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 191 | } | 
|  | 192 |  | 
|  | 193 | // A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check | 
|  | 194 | // individual pixel values for testing purposes. | 
|  | 195 | class ScreenCapture : public RefBase { | 
|  | 196 | public: | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 197 | static void captureScreen(std::unique_ptr<ScreenCapture>* sc) { | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 198 | const auto sf = ComposerService::getComposerService(); | 
|  | 199 | const auto token = sf->getInternalDisplayToken(); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 200 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 201 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 202 | sp<GraphicBuffer> outBuffer; | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 203 | ASSERT_EQ(NO_ERROR, sf->captureScreen(token, &outBuffer, Rect(), 0, 0, false)); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 204 | *sc = std::make_unique<ScreenCapture>(outBuffer); | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 205 | } | 
|  | 206 |  | 
|  | 207 | static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, | 
|  | 208 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { | 
|  | 209 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
|  | 210 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 211 |  | 
|  | 212 | sp<GraphicBuffer> outBuffer; | 
|  | 213 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale)); | 
|  | 214 | *sc = std::make_unique<ScreenCapture>(outBuffer); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 215 | } | 
|  | 216 |  | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 217 | static void captureChildLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, | 
|  | 218 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { | 
|  | 219 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
|  | 220 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 221 |  | 
|  | 222 | sp<GraphicBuffer> outBuffer; | 
|  | 223 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale, true)); | 
|  | 224 | *sc = std::make_unique<ScreenCapture>(outBuffer); | 
|  | 225 | } | 
|  | 226 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 227 | void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) { | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 228 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); | 
|  | 229 | expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 230 | } | 
|  | 231 |  | 
|  | 232 | void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) { | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 233 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 234 | const bool leftBorder = rect.left > 0; | 
|  | 235 | const bool topBorder = rect.top > 0; | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 236 | const bool rightBorder = rect.right < int32_t(mOutBuffer->getWidth()); | 
|  | 237 | const bool bottomBorder = rect.bottom < int32_t(mOutBuffer->getHeight()); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 238 |  | 
|  | 239 | if (topBorder) { | 
|  | 240 | Rect top(rect.left, rect.top - 1, rect.right, rect.top); | 
|  | 241 | if (leftBorder) { | 
|  | 242 | top.left -= 1; | 
|  | 243 | } | 
|  | 244 | if (rightBorder) { | 
|  | 245 | top.right += 1; | 
|  | 246 | } | 
|  | 247 | expectColor(top, color, tolerance); | 
|  | 248 | } | 
|  | 249 | if (leftBorder) { | 
|  | 250 | Rect left(rect.left - 1, rect.top, rect.left, rect.bottom); | 
|  | 251 | expectColor(left, color, tolerance); | 
|  | 252 | } | 
|  | 253 | if (rightBorder) { | 
|  | 254 | Rect right(rect.right, rect.top, rect.right + 1, rect.bottom); | 
|  | 255 | expectColor(right, color, tolerance); | 
|  | 256 | } | 
|  | 257 | if (bottomBorder) { | 
|  | 258 | Rect bottom(rect.left, rect.bottom, rect.right, rect.bottom + 1); | 
|  | 259 | if (leftBorder) { | 
|  | 260 | bottom.left -= 1; | 
|  | 261 | } | 
|  | 262 | if (rightBorder) { | 
|  | 263 | bottom.right += 1; | 
|  | 264 | } | 
|  | 265 | expectColor(bottom, color, tolerance); | 
|  | 266 | } | 
|  | 267 | } | 
|  | 268 |  | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 269 | void expectQuadrant(const Rect& rect, const Color& topLeft, const Color& topRight, | 
|  | 270 | const Color& bottomLeft, const Color& bottomRight, bool filtered = false, | 
|  | 271 | uint8_t tolerance = 0) { | 
|  | 272 | ASSERT_TRUE((rect.right - rect.left) % 2 == 0 && (rect.bottom - rect.top) % 2 == 0); | 
|  | 273 |  | 
|  | 274 | const int32_t centerX = rect.left + (rect.right - rect.left) / 2; | 
|  | 275 | const int32_t centerY = rect.top + (rect.bottom - rect.top) / 2; | 
|  | 276 | // avoid checking borders due to unspecified filtering behavior | 
|  | 277 | const int32_t offsetX = filtered ? 2 : 0; | 
|  | 278 | const int32_t offsetY = filtered ? 2 : 0; | 
|  | 279 | expectColor(Rect(rect.left, rect.top, centerX - offsetX, centerY - offsetY), topLeft, | 
|  | 280 | tolerance); | 
|  | 281 | expectColor(Rect(centerX + offsetX, rect.top, rect.right, centerY - offsetY), topRight, | 
|  | 282 | tolerance); | 
|  | 283 | expectColor(Rect(rect.left, centerY + offsetY, centerX - offsetX, rect.bottom), bottomLeft, | 
|  | 284 | tolerance); | 
|  | 285 | expectColor(Rect(centerX + offsetX, centerY + offsetY, rect.right, rect.bottom), | 
|  | 286 | bottomRight, tolerance); | 
|  | 287 | } | 
|  | 288 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 289 | 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] | 290 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); | 
|  | 291 | const uint8_t* pixel = mPixels + (4 * (y * mOutBuffer->getStride() + x)); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 292 | if (r != pixel[0] || g != pixel[1] || b != pixel[2]) { | 
|  | 293 | String8 err(String8::format("pixel @ (%3d, %3d): " | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 294 | "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]", | 
|  | 295 | x, y, r, g, b, pixel[0], pixel[1], pixel[2])); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 296 | EXPECT_EQ(String8(), err) << err.string(); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 297 | } | 
|  | 298 | } | 
|  | 299 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 300 | 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] | 301 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 302 | 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] | 303 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 304 | 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] | 305 |  | 
| Chih-Hung Hsieh | 2274904 | 2018-12-20 15:50:39 -0800 | [diff] [blame] | 306 | explicit ScreenCapture(const sp<GraphicBuffer>& outBuffer) : mOutBuffer(outBuffer) { | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 307 | mOutBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&mPixels)); | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 308 | } | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 309 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 310 | ~ScreenCapture() { mOutBuffer->unlock(); } | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 311 |  | 
|  | 312 | private: | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 313 | sp<GraphicBuffer> mOutBuffer; | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 314 | uint8_t* mPixels = nullptr; | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 315 | }; | 
|  | 316 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 317 | class LayerTransactionTest : public ::testing::Test { | 
|  | 318 | protected: | 
|  | 319 | void SetUp() override { | 
|  | 320 | mClient = new SurfaceComposerClient; | 
|  | 321 | ASSERT_EQ(NO_ERROR, mClient->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 322 |  | 
|  | 323 | ASSERT_NO_FATAL_FAILURE(SetUpDisplay()); | 
| Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 324 |  | 
|  | 325 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
| Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 326 | ASSERT_NO_FATAL_FAILURE(sf->getColorManagement(&mColorManagementUsed)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 327 | } | 
|  | 328 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 329 | virtual void TearDown() { | 
|  | 330 | mBlackBgSurface = 0; | 
|  | 331 | mClient->dispose(); | 
|  | 332 | mClient = 0; | 
|  | 333 | } | 
|  | 334 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 335 | virtual sp<SurfaceControl> createLayer(const sp<SurfaceComposerClient>& client, | 
|  | 336 | const char* name, uint32_t width, uint32_t height, | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 337 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { | 
|  | 338 | auto layer = | 
|  | 339 | createSurface(client, name, width, height, PIXEL_FORMAT_RGBA_8888, flags, parent); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 340 |  | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 341 | Transaction t; | 
|  | 342 | t.setLayerStack(layer, mDisplayLayerStack).setLayer(layer, mLayerZBase); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 343 |  | 
|  | 344 | status_t error = t.apply(); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 345 | if (error != NO_ERROR) { | 
|  | 346 | ADD_FAILURE() << "failed to initialize SurfaceControl"; | 
|  | 347 | layer.clear(); | 
|  | 348 | } | 
|  | 349 |  | 
|  | 350 | return layer; | 
|  | 351 | } | 
|  | 352 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 353 | virtual sp<SurfaceControl> createSurface(const sp<SurfaceComposerClient>& client, | 
|  | 354 | const char* name, uint32_t width, uint32_t height, | 
|  | 355 | PixelFormat format, uint32_t flags, | 
|  | 356 | SurfaceControl* parent = nullptr) { | 
|  | 357 | auto layer = client->createSurface(String8(name), width, height, format, flags, parent); | 
|  | 358 | EXPECT_NE(nullptr, layer.get()) << "failed to create SurfaceControl"; | 
|  | 359 | return layer; | 
|  | 360 | } | 
|  | 361 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 362 | virtual sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 363 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { | 
|  | 364 | return createLayer(mClient, name, width, height, flags, parent); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 365 | } | 
|  | 366 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 367 | ANativeWindow_Buffer getBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 368 | // wait for previous transactions (such as setSize) to complete | 
|  | 369 | Transaction().apply(true); | 
|  | 370 |  | 
|  | 371 | ANativeWindow_Buffer buffer = {}; | 
|  | 372 | EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr)); | 
|  | 373 |  | 
|  | 374 | return buffer; | 
|  | 375 | } | 
|  | 376 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 377 | void postBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 378 | ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost()); | 
|  | 379 |  | 
|  | 380 | // wait for the newly posted buffer to be latched | 
|  | 381 | waitForLayerBuffers(); | 
|  | 382 | } | 
|  | 383 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 384 | virtual void fillBufferQueueLayerColor(const sp<SurfaceControl>& layer, const Color& color, | 
|  | 385 | int32_t bufferWidth, int32_t bufferHeight) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 386 | ANativeWindow_Buffer buffer; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 387 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); | 
|  | 388 | fillANativeWindowBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); | 
|  | 389 | postBufferQueueLayerBuffer(layer); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 390 | } | 
|  | 391 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 392 | virtual void fillBufferStateLayerColor(const sp<SurfaceControl>& layer, const Color& color, | 
|  | 393 | int32_t bufferWidth, int32_t bufferHeight) { | 
|  | 394 | sp<GraphicBuffer> buffer = | 
|  | 395 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 396 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 397 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 398 | "test"); | 
|  | 399 | fillGraphicBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 400 | Transaction().setBuffer(layer, buffer).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 401 | } | 
|  | 402 |  | 
|  | 403 | void fillLayerColor(uint32_t mLayerType, const sp<SurfaceControl>& layer, const Color& color, | 
|  | 404 | int32_t bufferWidth, int32_t bufferHeight) { | 
|  | 405 | switch (mLayerType) { | 
|  | 406 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 407 | fillBufferQueueLayerColor(layer, color, bufferWidth, bufferHeight); | 
|  | 408 | break; | 
|  | 409 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 410 | fillBufferStateLayerColor(layer, color, bufferWidth, bufferHeight); | 
|  | 411 | break; | 
|  | 412 | default: | 
|  | 413 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; | 
|  | 414 | } | 
|  | 415 | } | 
|  | 416 |  | 
|  | 417 | void fillLayerQuadrant(uint32_t mLayerType, const sp<SurfaceControl>& layer, | 
|  | 418 | int32_t bufferWidth, int32_t bufferHeight, const Color& topLeft, | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 419 | const Color& topRight, const Color& bottomLeft, | 
|  | 420 | const Color& bottomRight) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 421 | switch (mLayerType) { | 
|  | 422 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 423 | fillBufferQueueLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, | 
|  | 424 | bottomLeft, bottomRight); | 
|  | 425 | break; | 
|  | 426 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 427 | fillBufferStateLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, | 
|  | 428 | bottomLeft, bottomRight); | 
|  | 429 | break; | 
|  | 430 | default: | 
|  | 431 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; | 
|  | 432 | } | 
|  | 433 | } | 
|  | 434 |  | 
|  | 435 | virtual void fillBufferQueueLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, | 
|  | 436 | int32_t bufferHeight, const Color& topLeft, | 
|  | 437 | const Color& topRight, const Color& bottomLeft, | 
|  | 438 | const Color& bottomRight) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 439 | ANativeWindow_Buffer buffer; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 440 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); | 
|  | 441 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 442 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 443 | const int32_t halfW = bufferWidth / 2; | 
|  | 444 | const int32_t halfH = bufferHeight / 2; | 
|  | 445 | fillANativeWindowBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); | 
|  | 446 | fillANativeWindowBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); | 
|  | 447 | fillANativeWindowBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); | 
|  | 448 | fillANativeWindowBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), | 
|  | 449 | bottomRight); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 450 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 451 | postBufferQueueLayerBuffer(layer); | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 | virtual void fillBufferStateLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, | 
|  | 455 | int32_t bufferHeight, const Color& topLeft, | 
|  | 456 | const Color& topRight, const Color& bottomLeft, | 
|  | 457 | const Color& bottomRight) { | 
|  | 458 | sp<GraphicBuffer> buffer = | 
|  | 459 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 460 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 461 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 462 | "test"); | 
|  | 463 |  | 
|  | 464 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); | 
|  | 465 |  | 
|  | 466 | const int32_t halfW = bufferWidth / 2; | 
|  | 467 | const int32_t halfH = bufferHeight / 2; | 
|  | 468 | fillGraphicBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); | 
|  | 469 | fillGraphicBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); | 
|  | 470 | fillGraphicBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); | 
|  | 471 | fillGraphicBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), bottomRight); | 
|  | 472 |  | 
|  | 473 | Transaction().setBuffer(layer, buffer).setSize(layer, bufferWidth, bufferHeight).apply(); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 474 | } | 
|  | 475 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 476 | std::unique_ptr<ScreenCapture> screenshot() { | 
|  | 477 | std::unique_ptr<ScreenCapture> screenshot; | 
|  | 478 | ScreenCapture::captureScreen(&screenshot); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 479 | return screenshot; | 
|  | 480 | } | 
|  | 481 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 482 | static status_t getBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) { | 
|  | 483 | static BufferGenerator bufferGenerator; | 
|  | 484 | return bufferGenerator.get(outBuffer, outFence); | 
|  | 485 | } | 
|  | 486 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 487 | sp<SurfaceComposerClient> mClient; | 
|  | 488 |  | 
|  | 489 | sp<IBinder> mDisplay; | 
|  | 490 | uint32_t mDisplayWidth; | 
|  | 491 | uint32_t mDisplayHeight; | 
|  | 492 | uint32_t mDisplayLayerStack; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 493 | Rect mDisplayRect = Rect::INVALID_RECT; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 494 |  | 
|  | 495 | // leave room for ~256 layers | 
|  | 496 | const int32_t mLayerZBase = std::numeric_limits<int32_t>::max() - 256; | 
|  | 497 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 498 | sp<SurfaceControl> mBlackBgSurface; | 
| Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 499 | bool mColorManagementUsed; | 
|  | 500 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 501 | private: | 
|  | 502 | void SetUpDisplay() { | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 503 | mDisplay = mClient->getInternalDisplayToken(); | 
|  | 504 | ASSERT_FALSE(mDisplay == nullptr) << "failed to get display"; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 505 |  | 
|  | 506 | // get display width/height | 
|  | 507 | DisplayInfo info; | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 508 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayInfo(mDisplay, &info)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 509 | mDisplayWidth = info.w; | 
|  | 510 | mDisplayHeight = info.h; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 511 | mDisplayRect = | 
|  | 512 | Rect(static_cast<int32_t>(mDisplayWidth), static_cast<int32_t>(mDisplayHeight)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 513 |  | 
|  | 514 | // After a new buffer is queued, SurfaceFlinger is notified and will | 
|  | 515 | // latch the new buffer on next vsync.  Let's heuristically wait for 3 | 
|  | 516 | // vsyncs. | 
|  | 517 | mBufferPostDelay = int32_t(1e6 / info.fps) * 3; | 
|  | 518 |  | 
|  | 519 | mDisplayLayerStack = 0; | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 520 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 521 | mBlackBgSurface = | 
|  | 522 | createSurface(mClient, "BaseSurface", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 523 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 524 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 525 | // set layer stack (b/68888219) | 
|  | 526 | Transaction t; | 
|  | 527 | t.setDisplayLayerStack(mDisplay, mDisplayLayerStack); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 528 | t.setCrop_legacy(mBlackBgSurface, Rect(0, 0, mDisplayWidth, mDisplayHeight)); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 529 | t.setLayerStack(mBlackBgSurface, mDisplayLayerStack); | 
|  | 530 | t.setColor(mBlackBgSurface, half3{0, 0, 0}); | 
|  | 531 | t.setLayer(mBlackBgSurface, mLayerZBase); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 532 | t.apply(); | 
|  | 533 | } | 
|  | 534 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 535 | void waitForLayerBuffers() { | 
|  | 536 | // Request an empty transaction to get applied synchronously to ensure the buffer is | 
|  | 537 | // latched. | 
|  | 538 | Transaction().apply(true); | 
|  | 539 | usleep(mBufferPostDelay); | 
|  | 540 | } | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 541 |  | 
|  | 542 | int32_t mBufferPostDelay; | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 543 |  | 
|  | 544 | friend class LayerRenderPathTestHarness; | 
|  | 545 | }; | 
|  | 546 | enum class RenderPath { SCREENSHOT, VIRTUAL_DISPLAY }; | 
|  | 547 |  | 
|  | 548 | class LayerRenderPathTestHarness { | 
|  | 549 | public: | 
|  | 550 | LayerRenderPathTestHarness(LayerTransactionTest* delegate, RenderPath renderPath) | 
|  | 551 | : mDelegate(delegate), mRenderPath(renderPath) {} | 
|  | 552 |  | 
|  | 553 | std::unique_ptr<ScreenCapture> getScreenCapture() { | 
|  | 554 | switch (mRenderPath) { | 
|  | 555 | case RenderPath::SCREENSHOT: | 
|  | 556 | return mDelegate->screenshot(); | 
|  | 557 | case RenderPath::VIRTUAL_DISPLAY: | 
|  | 558 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 559 | const auto mainDisplay = SurfaceComposerClient::getInternalDisplayToken(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 560 | DisplayInfo mainDisplayInfo; | 
|  | 561 | SurfaceComposerClient::getDisplayInfo(mainDisplay, &mainDisplayInfo); | 
|  | 562 |  | 
|  | 563 | sp<IBinder> vDisplay; | 
|  | 564 | sp<IGraphicBufferProducer> producer; | 
|  | 565 | sp<IGraphicBufferConsumer> consumer; | 
|  | 566 | sp<BufferItemConsumer> itemConsumer; | 
|  | 567 | BufferQueue::createBufferQueue(&producer, &consumer); | 
|  | 568 |  | 
|  | 569 | consumer->setConsumerName(String8("Virtual disp consumer")); | 
|  | 570 | consumer->setDefaultBufferSize(mainDisplayInfo.w, mainDisplayInfo.h); | 
|  | 571 |  | 
|  | 572 | itemConsumer = new BufferItemConsumer(consumer, | 
|  | 573 | // Sample usage bits from screenrecord | 
|  | 574 | GRALLOC_USAGE_HW_VIDEO_ENCODER | | 
|  | 575 | GRALLOC_USAGE_SW_READ_OFTEN); | 
|  | 576 |  | 
|  | 577 | vDisplay = SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), | 
|  | 578 | false /*secure*/); | 
|  | 579 |  | 
|  | 580 | SurfaceComposerClient::Transaction t; | 
|  | 581 | t.setDisplaySurface(vDisplay, producer); | 
|  | 582 | t.setDisplayLayerStack(vDisplay, 0); | 
|  | 583 | t.setDisplayProjection(vDisplay, mainDisplayInfo.orientation, | 
|  | 584 | Rect(mainDisplayInfo.viewportW, mainDisplayInfo.viewportH), | 
|  | 585 | Rect(mainDisplayInfo.w, mainDisplayInfo.h)); | 
|  | 586 | t.apply(); | 
|  | 587 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 588 | BufferItem item; | 
|  | 589 | itemConsumer->acquireBuffer(&item, 0, true); | 
|  | 590 | auto sc = std::make_unique<ScreenCapture>(item.mGraphicBuffer); | 
|  | 591 | itemConsumer->releaseBuffer(item); | 
|  | 592 | SurfaceComposerClient::destroyDisplay(vDisplay); | 
|  | 593 | return sc; | 
|  | 594 | } | 
|  | 595 | } | 
|  | 596 |  | 
|  | 597 | protected: | 
|  | 598 | LayerTransactionTest* mDelegate; | 
|  | 599 | RenderPath mRenderPath; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 600 | }; | 
|  | 601 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 602 | class LayerTypeTransactionHarness : public LayerTransactionTest { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 603 | public: | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 604 | LayerTypeTransactionHarness(uint32_t layerType) : mLayerType(layerType) {} | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 605 |  | 
|  | 606 | sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 607 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 608 | // if the flags already have a layer type specified, return an error | 
|  | 609 | if (flags & ISurfaceComposerClient::eFXSurfaceMask) { | 
|  | 610 | return nullptr; | 
|  | 611 | } | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 612 | return LayerTransactionTest::createLayer(name, width, height, flags | mLayerType, parent); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 613 | } | 
|  | 614 |  | 
|  | 615 | void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color, int32_t bufferWidth, | 
|  | 616 | int32_t bufferHeight) { | 
|  | 617 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerColor(mLayerType, layer, color, | 
|  | 618 | bufferWidth, bufferHeight)); | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 | void fillLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, | 
|  | 622 | int32_t bufferHeight, const Color& topLeft, const Color& topRight, | 
|  | 623 | const Color& bottomLeft, const Color& bottomRight) { | 
|  | 624 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerQuadrant(mLayerType, layer, | 
|  | 625 | bufferWidth, bufferHeight, | 
|  | 626 | topLeft, topRight, | 
|  | 627 | bottomLeft, bottomRight)); | 
|  | 628 | } | 
|  | 629 |  | 
|  | 630 | protected: | 
|  | 631 | uint32_t mLayerType; | 
|  | 632 | }; | 
|  | 633 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 634 | class LayerTypeTransactionTest : public LayerTypeTransactionHarness, | 
|  | 635 | public ::testing::WithParamInterface<uint32_t> { | 
|  | 636 | public: | 
|  | 637 | LayerTypeTransactionTest() : LayerTypeTransactionHarness(GetParam()) {} | 
|  | 638 | }; | 
|  | 639 |  | 
|  | 640 | class LayerTypeAndRenderTypeTransactionTest | 
|  | 641 | : public LayerTypeTransactionHarness, | 
|  | 642 | public ::testing::WithParamInterface<std::tuple<uint32_t, RenderPath>> { | 
|  | 643 | public: | 
|  | 644 | LayerTypeAndRenderTypeTransactionTest() | 
|  | 645 | : LayerTypeTransactionHarness(std::get<0>(GetParam())), | 
|  | 646 | mRenderPathHarness(LayerRenderPathTestHarness(this, std::get<1>(GetParam()))) {} | 
|  | 647 |  | 
|  | 648 | std::unique_ptr<ScreenCapture> getScreenCapture() { | 
|  | 649 | return mRenderPathHarness.getScreenCapture(); | 
|  | 650 | } | 
|  | 651 |  | 
|  | 652 | protected: | 
|  | 653 | LayerRenderPathTestHarness mRenderPathHarness; | 
|  | 654 | }; | 
|  | 655 |  | 
|  | 656 | // Environment for starting up binder threads. This is required for testing | 
|  | 657 | // virtual displays, as BufferQueue parameters may be queried over binder. | 
|  | 658 | class BinderEnvironment : public ::testing::Environment { | 
|  | 659 | public: | 
|  | 660 | void SetUp() override { ProcessState::self()->startThreadPool(); } | 
|  | 661 | }; | 
|  | 662 |  | 
|  | 663 | ::testing::Environment* const binderEnv = | 
|  | 664 | ::testing::AddGlobalTestEnvironment(new BinderEnvironment()); | 
|  | 665 |  | 
|  | 666 | class LayerRenderTypeTransactionTest : public LayerTransactionTest, | 
|  | 667 | public ::testing::WithParamInterface<RenderPath> { | 
|  | 668 | public: | 
|  | 669 | LayerRenderTypeTransactionTest() : mHarness(LayerRenderPathTestHarness(this, GetParam())) {} | 
|  | 670 |  | 
|  | 671 | std::unique_ptr<ScreenCapture> getScreenCapture() { return mHarness.getScreenCapture(); } | 
|  | 672 | void setRelativeZBasicHelper(uint32_t layerType); | 
|  | 673 | void setRelativeZGroupHelper(uint32_t layerType); | 
|  | 674 | void setAlphaBasicHelper(uint32_t layerType); | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 675 | void setBackgroundColorHelper(uint32_t layerType, bool priorColor, bool bufferFill, float alpha, | 
|  | 676 | Color finalColor); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 677 |  | 
|  | 678 | protected: | 
|  | 679 | LayerRenderPathTestHarness mHarness; | 
|  | 680 | }; | 
|  | 681 |  | 
|  | 682 | INSTANTIATE_TEST_CASE_P( | 
|  | 683 | LayerTypeAndRenderTypeTransactionTests, LayerTypeAndRenderTypeTransactionTest, | 
|  | 684 | ::testing::Combine( | 
|  | 685 | ::testing::Values( | 
|  | 686 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferQueue), | 
|  | 687 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferState)), | 
|  | 688 | ::testing::Values(RenderPath::VIRTUAL_DISPLAY, RenderPath::SCREENSHOT))); | 
|  | 689 |  | 
|  | 690 | INSTANTIATE_TEST_CASE_P(LayerRenderTypeTransactionTests, LayerRenderTypeTransactionTest, | 
|  | 691 | ::testing::Values(RenderPath::VIRTUAL_DISPLAY, RenderPath::SCREENSHOT)); | 
|  | 692 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 693 | INSTANTIATE_TEST_CASE_P( | 
|  | 694 | LayerTypeTransactionTests, LayerTypeTransactionTest, | 
|  | 695 | ::testing::Values(static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferQueue), | 
|  | 696 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferState))); | 
|  | 697 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 698 | TEST_P(LayerRenderTypeTransactionTest, SetPositionBasic_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 699 | sp<SurfaceControl> layer; | 
|  | 700 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 701 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 702 |  | 
|  | 703 | { | 
|  | 704 | SCOPED_TRACE("default position"); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 705 | const Rect rect(0, 0, 32, 32); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 706 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 707 | shot->expectColor(rect, Color::RED); | 
|  | 708 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 709 | } | 
|  | 710 |  | 
|  | 711 | Transaction().setPosition(layer, 5, 10).apply(); | 
|  | 712 | { | 
|  | 713 | SCOPED_TRACE("new position"); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 714 | const Rect rect(5, 10, 37, 42); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 715 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 716 | shot->expectColor(rect, Color::RED); | 
|  | 717 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 718 | } | 
|  | 719 | } | 
|  | 720 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 721 | TEST_P(LayerRenderTypeTransactionTest, SetPositionRounding_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 722 | sp<SurfaceControl> layer; | 
|  | 723 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 724 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 725 |  | 
|  | 726 | // GLES requires only 4 bits of subpixel precision during rasterization | 
|  | 727 | // XXX GLES composition does not match HWC composition due to precision | 
|  | 728 | // loss (b/69315223) | 
|  | 729 | const float epsilon = 1.0f / 16.0f; | 
|  | 730 | Transaction().setPosition(layer, 0.5f - epsilon, 0.5f - epsilon).apply(); | 
|  | 731 | { | 
|  | 732 | SCOPED_TRACE("rounding down"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 733 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 734 | } | 
|  | 735 |  | 
|  | 736 | Transaction().setPosition(layer, 0.5f + epsilon, 0.5f + epsilon).apply(); | 
|  | 737 | { | 
|  | 738 | SCOPED_TRACE("rounding up"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 739 | getScreenCapture()->expectColor(Rect(1, 1, 33, 33), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 740 | } | 
|  | 741 | } | 
|  | 742 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 743 | TEST_P(LayerRenderTypeTransactionTest, SetPositionOutOfBounds_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 744 | sp<SurfaceControl> layer; | 
|  | 745 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 746 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 747 |  | 
|  | 748 | Transaction().setPosition(layer, -32, -32).apply(); | 
|  | 749 | { | 
|  | 750 | SCOPED_TRACE("negative coordinates"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 751 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 752 | } | 
|  | 753 |  | 
|  | 754 | Transaction().setPosition(layer, mDisplayWidth, mDisplayHeight).apply(); | 
|  | 755 | { | 
|  | 756 | SCOPED_TRACE("positive coordinates"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 757 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 758 | } | 
|  | 759 | } | 
|  | 760 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 761 | TEST_P(LayerRenderTypeTransactionTest, SetPositionPartiallyOutOfBounds_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 762 | sp<SurfaceControl> layer; | 
|  | 763 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 764 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 765 |  | 
|  | 766 | // partially out of bounds | 
|  | 767 | Transaction().setPosition(layer, -30, -30).apply(); | 
|  | 768 | { | 
|  | 769 | SCOPED_TRACE("negative coordinates"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 770 | getScreenCapture()->expectColor(Rect(0, 0, 2, 2), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 771 | } | 
|  | 772 |  | 
|  | 773 | Transaction().setPosition(layer, mDisplayWidth - 2, mDisplayHeight - 2).apply(); | 
|  | 774 | { | 
|  | 775 | SCOPED_TRACE("positive coordinates"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 776 | getScreenCapture()->expectColor(Rect(mDisplayWidth - 2, mDisplayHeight - 2, mDisplayWidth, | 
|  | 777 | mDisplayHeight), | 
|  | 778 | Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 779 | } | 
|  | 780 | } | 
|  | 781 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 782 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithResize_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 783 | sp<SurfaceControl> layer; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 784 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 785 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 786 |  | 
|  | 787 | // setPosition is applied immediately by default, with or without resize | 
|  | 788 | // pending | 
|  | 789 | Transaction().setPosition(layer, 5, 10).setSize(layer, 64, 64).apply(); | 
|  | 790 | { | 
|  | 791 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 792 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 793 | const Rect rect(5, 10, 37, 42); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 794 | shot->expectColor(rect, Color::RED); | 
|  | 795 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 796 | } | 
|  | 797 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 798 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 799 | { | 
|  | 800 | SCOPED_TRACE("resize applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 801 | getScreenCapture()->expectColor(Rect(5, 10, 69, 74), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 802 | } | 
|  | 803 | } | 
|  | 804 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 805 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithNextResize_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 806 | sp<SurfaceControl> layer; | 
|  | 807 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 808 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 809 |  | 
|  | 810 | // request setPosition to be applied with the next resize | 
|  | 811 | Transaction().setPosition(layer, 5, 10).setGeometryAppliesWithResize(layer).apply(); | 
|  | 812 | { | 
|  | 813 | SCOPED_TRACE("new position pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 814 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 815 | } | 
|  | 816 |  | 
|  | 817 | Transaction().setPosition(layer, 15, 20).apply(); | 
|  | 818 | { | 
|  | 819 | SCOPED_TRACE("pending new position modified"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 820 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 821 | } | 
|  | 822 |  | 
|  | 823 | Transaction().setSize(layer, 64, 64).apply(); | 
|  | 824 | { | 
|  | 825 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 826 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 827 | } | 
|  | 828 |  | 
|  | 829 | // finally resize and latch the buffer | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 830 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 831 | { | 
|  | 832 | SCOPED_TRACE("new position applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 833 | getScreenCapture()->expectColor(Rect(15, 20, 79, 84), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 834 | } | 
|  | 835 | } | 
|  | 836 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 837 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithNextResizeScaleToWindow_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 838 | sp<SurfaceControl> layer; | 
|  | 839 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 840 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 841 |  | 
|  | 842 | // setPosition is not immediate even with SCALE_TO_WINDOW override | 
|  | 843 | Transaction() | 
|  | 844 | .setPosition(layer, 5, 10) | 
|  | 845 | .setSize(layer, 64, 64) | 
|  | 846 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 847 | .setGeometryAppliesWithResize(layer) | 
|  | 848 | .apply(); | 
|  | 849 | { | 
|  | 850 | SCOPED_TRACE("new position pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 851 | getScreenCapture()->expectColor(Rect(0, 0, 64, 64), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 852 | } | 
|  | 853 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 854 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 855 | { | 
|  | 856 | SCOPED_TRACE("new position applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 857 | getScreenCapture()->expectColor(Rect(5, 10, 69, 74), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 858 | } | 
|  | 859 | } | 
|  | 860 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 861 | TEST_P(LayerRenderTypeTransactionTest, SetSizeBasic_BufferQueue) { | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 862 | sp<SurfaceControl> layer; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 863 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 864 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 865 |  | 
|  | 866 | Transaction().setSize(layer, 64, 64).apply(); | 
|  | 867 | { | 
|  | 868 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 869 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 870 | const Rect rect(0, 0, 32, 32); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 871 | shot->expectColor(rect, Color::RED); | 
|  | 872 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 873 | } | 
|  | 874 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 875 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 876 | { | 
|  | 877 | SCOPED_TRACE("resize applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 878 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 879 | const Rect rect(0, 0, 64, 64); | 
|  | 880 | shot->expectColor(rect, Color::RED); | 
|  | 881 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 882 | } | 
|  | 883 | } | 
|  | 884 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 885 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetSizeInvalid) { | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 886 | // cannot test robustness against invalid sizes (zero or really huge) | 
|  | 887 | } | 
|  | 888 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 889 | TEST_P(LayerRenderTypeTransactionTest, SetSizeWithScaleToWindow_BufferQueue) { | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 890 | sp<SurfaceControl> layer; | 
|  | 891 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 892 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 893 |  | 
|  | 894 | // setSize is immediate with SCALE_TO_WINDOW, unlike setPosition | 
|  | 895 | Transaction() | 
|  | 896 | .setSize(layer, 64, 64) | 
|  | 897 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 898 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 899 | getScreenCapture()->expectColor(Rect(0, 0, 64, 64), Color::RED); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 900 | } | 
|  | 901 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 902 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetZBasic) { | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 903 | sp<SurfaceControl> layerR; | 
|  | 904 | sp<SurfaceControl> layerG; | 
|  | 905 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 906 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 907 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 908 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 909 |  | 
|  | 910 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); | 
|  | 911 | { | 
|  | 912 | SCOPED_TRACE("layerR"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 913 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 914 | } | 
|  | 915 |  | 
|  | 916 | Transaction().setLayer(layerG, mLayerZBase + 2).apply(); | 
|  | 917 | { | 
|  | 918 | SCOPED_TRACE("layerG"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 919 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::GREEN); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 920 | } | 
|  | 921 | } | 
|  | 922 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 923 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetZNegative) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 924 | sp<SurfaceControl> parent = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 925 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 926 | ISurfaceComposerClient::eFXSurfaceContainer); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 927 | Transaction().setCrop_legacy(parent, Rect(0, 0, mDisplayWidth, mDisplayHeight)).apply(); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 928 | sp<SurfaceControl> layerR; | 
|  | 929 | sp<SurfaceControl> layerG; | 
|  | 930 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 931 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 932 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 933 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 934 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 935 | Transaction() | 
|  | 936 | .reparent(layerR, parent->getHandle()) | 
|  | 937 | .reparent(layerG, parent->getHandle()) | 
|  | 938 | .apply(); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 939 | Transaction().setLayer(layerR, -1).setLayer(layerG, -2).apply(); | 
|  | 940 | { | 
|  | 941 | SCOPED_TRACE("layerR"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 942 | auto shot = getScreenCapture(); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 943 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 944 | } | 
|  | 945 |  | 
|  | 946 | Transaction().setLayer(layerR, -3).apply(); | 
|  | 947 | { | 
|  | 948 | SCOPED_TRACE("layerG"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 949 | auto shot = getScreenCapture(); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 950 | shot->expectColor(Rect(0, 0, 32, 32), Color::GREEN); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 951 | } | 
|  | 952 | } | 
|  | 953 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 954 | void LayerRenderTypeTransactionTest::setRelativeZBasicHelper(uint32_t layerType) { | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 955 | sp<SurfaceControl> layerR; | 
|  | 956 | sp<SurfaceControl> layerG; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 957 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32, layerType)); | 
|  | 958 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerR, Color::RED, 32, 32)); | 
|  | 959 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32, layerType)); | 
|  | 960 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 961 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 962 | switch (layerType) { | 
|  | 963 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 964 | Transaction() | 
|  | 965 | .setPosition(layerG, 16, 16) | 
|  | 966 | .setRelativeLayer(layerG, layerR->getHandle(), 1) | 
|  | 967 | .apply(); | 
|  | 968 | break; | 
|  | 969 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 970 | Transaction() | 
|  | 971 | .setFrame(layerR, Rect(0, 0, 32, 32)) | 
|  | 972 | .setFrame(layerG, Rect(16, 16, 48, 48)) | 
|  | 973 | .setRelativeLayer(layerG, layerR->getHandle(), 1) | 
|  | 974 | .apply(); | 
|  | 975 | break; | 
|  | 976 | default: | 
|  | 977 | ASSERT_FALSE(true) << "Unsupported layer type"; | 
|  | 978 | } | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 979 | { | 
|  | 980 | SCOPED_TRACE("layerG above"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 981 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 982 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); | 
|  | 983 | shot->expectColor(Rect(16, 16, 48, 48), Color::GREEN); | 
|  | 984 | } | 
|  | 985 |  | 
|  | 986 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).apply(); | 
|  | 987 | { | 
|  | 988 | SCOPED_TRACE("layerG below"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 989 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 990 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 991 | shot->expectColor(Rect(32, 32, 48, 48), Color::GREEN); | 
|  | 992 | } | 
|  | 993 | } | 
|  | 994 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 995 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZBasic_BufferQueue) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 996 | ASSERT_NO_FATAL_FAILURE(setRelativeZBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); | 
|  | 997 | } | 
|  | 998 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 999 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZBasic_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1000 | ASSERT_NO_FATAL_FAILURE(setRelativeZBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1001 | } | 
|  | 1002 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1003 | TEST_P(LayerTypeTransactionTest, SetRelativeZNegative) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1004 | sp<SurfaceControl> parent = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1005 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1006 | ISurfaceComposerClient::eFXSurfaceContainer); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1007 | Transaction().setCrop_legacy(parent, Rect(0, 0, mDisplayWidth, mDisplayHeight)).apply(); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1008 | sp<SurfaceControl> layerR; | 
|  | 1009 | sp<SurfaceControl> layerG; | 
|  | 1010 | sp<SurfaceControl> layerB; | 
|  | 1011 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1012 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1013 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1014 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1015 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1016 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE, 32, 32)); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1017 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1018 | Transaction() | 
|  | 1019 | .reparent(layerB, parent->getHandle()) | 
|  | 1020 | .apply(); | 
|  | 1021 |  | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1022 | // layerR = mLayerZBase, layerG = layerR - 1, layerB = -2 | 
|  | 1023 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).setLayer(layerB, -2).apply(); | 
|  | 1024 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1025 | std::unique_ptr<ScreenCapture> screenshot; | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1026 | // only layerB is in this range | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1027 | sp<IBinder> parentHandle = parent->getHandle(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1028 | ScreenCapture::captureLayers(&screenshot, parentHandle, Rect(0, 0, 32, 32)); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1029 | screenshot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 1030 | } | 
|  | 1031 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1032 | void LayerRenderTypeTransactionTest::setRelativeZGroupHelper(uint32_t layerType) { | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1033 | sp<SurfaceControl> layerR; | 
|  | 1034 | sp<SurfaceControl> layerG; | 
|  | 1035 | sp<SurfaceControl> layerB; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1036 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test", 32, 32, layerType)); | 
|  | 1037 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerR, Color::RED, 32, 32)); | 
|  | 1038 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test", 32, 32, layerType)); | 
|  | 1039 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerG, Color::GREEN, 32, 32)); | 
|  | 1040 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test", 32, 32, layerType)); | 
|  | 1041 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerB, Color::BLUE, 32, 32)); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1042 |  | 
|  | 1043 | // layerR = 0, layerG = layerR + 3, layerB = 2 | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1044 | switch (layerType) { | 
|  | 1045 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 1046 | Transaction() | 
|  | 1047 | .setPosition(layerG, 8, 8) | 
|  | 1048 | .setRelativeLayer(layerG, layerR->getHandle(), 3) | 
|  | 1049 | .setPosition(layerB, 16, 16) | 
|  | 1050 | .setLayer(layerB, mLayerZBase + 2) | 
|  | 1051 | .apply(); | 
|  | 1052 | break; | 
|  | 1053 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 1054 | Transaction() | 
|  | 1055 | .setFrame(layerR, Rect(0, 0, 32, 32)) | 
|  | 1056 | .setFrame(layerG, Rect(8, 8, 40, 40)) | 
|  | 1057 | .setRelativeLayer(layerG, layerR->getHandle(), 3) | 
|  | 1058 | .setFrame(layerB, Rect(16, 16, 48, 48)) | 
|  | 1059 | .setLayer(layerB, mLayerZBase + 2) | 
|  | 1060 | .apply(); | 
|  | 1061 | break; | 
|  | 1062 | default: | 
|  | 1063 | ASSERT_FALSE(true) << "Unsupported layer type"; | 
|  | 1064 | } | 
|  | 1065 |  | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1066 | { | 
|  | 1067 | SCOPED_TRACE("(layerR < layerG) < layerB"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1068 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1069 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); | 
|  | 1070 | shot->expectColor(Rect(8, 8, 16, 16), Color::GREEN); | 
|  | 1071 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); | 
|  | 1072 | } | 
|  | 1073 |  | 
|  | 1074 | // layerR = 4, layerG = layerR + 3, layerB = 2 | 
|  | 1075 | Transaction().setLayer(layerR, mLayerZBase + 4).apply(); | 
|  | 1076 | { | 
|  | 1077 | SCOPED_TRACE("layerB < (layerR < layerG)"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1078 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1079 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); | 
|  | 1080 | shot->expectColor(Rect(8, 8, 40, 40), Color::GREEN); | 
|  | 1081 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); | 
|  | 1082 | } | 
|  | 1083 |  | 
|  | 1084 | // layerR = 4, layerG = layerR - 3, layerB = 2 | 
|  | 1085 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -3).apply(); | 
|  | 1086 | { | 
|  | 1087 | SCOPED_TRACE("layerB < (layerG < layerR)"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1088 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1089 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 1090 | shot->expectColor(Rect(32, 32, 40, 40), Color::GREEN); | 
|  | 1091 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); | 
|  | 1092 | } | 
|  | 1093 |  | 
|  | 1094 | // restore to absolute z | 
|  | 1095 | // layerR = 4, layerG = 0, layerB = 2 | 
|  | 1096 | Transaction().setLayer(layerG, mLayerZBase).apply(); | 
|  | 1097 | { | 
|  | 1098 | SCOPED_TRACE("layerG < layerB < layerR"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1099 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1100 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 1101 | shot->expectColor(Rect(32, 32, 48, 48), Color::BLUE); | 
|  | 1102 | } | 
|  | 1103 |  | 
|  | 1104 | // layerR should not affect layerG anymore | 
|  | 1105 | // layerR = 1, layerG = 0, layerB = 2 | 
|  | 1106 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); | 
|  | 1107 | { | 
|  | 1108 | SCOPED_TRACE("layerG < layerR < layerB"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1109 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1110 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); | 
|  | 1111 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); | 
|  | 1112 | } | 
|  | 1113 | } | 
|  | 1114 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1115 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZGroup_BufferQueue) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1116 | ASSERT_NO_FATAL_FAILURE(setRelativeZGroupHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); | 
|  | 1117 | } | 
|  | 1118 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1119 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZGroup_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1120 | ASSERT_NO_FATAL_FAILURE(setRelativeZGroupHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1121 | } | 
|  | 1122 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1123 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetRelativeZBug64572777) { | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1124 | sp<SurfaceControl> layerR; | 
|  | 1125 | sp<SurfaceControl> layerG; | 
|  | 1126 |  | 
|  | 1127 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1128 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1129 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1130 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1131 |  | 
|  | 1132 | Transaction() | 
|  | 1133 | .setPosition(layerG, 16, 16) | 
|  | 1134 | .setRelativeLayer(layerG, layerR->getHandle(), 1) | 
|  | 1135 | .apply(); | 
|  | 1136 |  | 
| Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 1137 | layerG->clear(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1138 | // layerG should have been removed | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1139 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1140 | } | 
|  | 1141 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1142 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetFlagsHidden) { | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1143 | sp<SurfaceControl> layer; | 
|  | 1144 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1145 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1146 |  | 
|  | 1147 | Transaction().setFlags(layer, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden).apply(); | 
|  | 1148 | { | 
|  | 1149 | SCOPED_TRACE("layer hidden"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1150 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1151 | } | 
|  | 1152 |  | 
|  | 1153 | Transaction().setFlags(layer, 0, layer_state_t::eLayerHidden).apply(); | 
|  | 1154 | { | 
|  | 1155 | SCOPED_TRACE("layer shown"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1156 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1157 | } | 
|  | 1158 | } | 
|  | 1159 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1160 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetFlagsOpaque) { | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1161 | const Color translucentRed = {100, 0, 0, 100}; | 
|  | 1162 | sp<SurfaceControl> layerR; | 
|  | 1163 | sp<SurfaceControl> layerG; | 
|  | 1164 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1165 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, translucentRed, 32, 32)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1166 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1167 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1168 |  | 
|  | 1169 | Transaction() | 
|  | 1170 | .setLayer(layerR, mLayerZBase + 1) | 
|  | 1171 | .setFlags(layerR, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque) | 
|  | 1172 | .apply(); | 
|  | 1173 | { | 
|  | 1174 | SCOPED_TRACE("layerR opaque"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1175 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {100, 0, 0, 255}); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1176 | } | 
|  | 1177 |  | 
|  | 1178 | Transaction().setFlags(layerR, 0, layer_state_t::eLayerOpaque).apply(); | 
|  | 1179 | { | 
|  | 1180 | SCOPED_TRACE("layerR translucent"); | 
|  | 1181 | const uint8_t g = uint8_t(255 - translucentRed.a); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1182 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {100, g, 0, 255}); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1183 | } | 
|  | 1184 | } | 
|  | 1185 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1186 | TEST_P(LayerTypeTransactionTest, SetFlagsSecure) { | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1187 | sp<SurfaceControl> layer; | 
|  | 1188 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1189 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1190 |  | 
|  | 1191 | sp<ISurfaceComposer> composer = ComposerService::getComposerService(); | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 1192 | sp<GraphicBuffer> outBuffer; | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1193 | Transaction() | 
|  | 1194 | .setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure) | 
|  | 1195 | .apply(true); | 
|  | 1196 | ASSERT_EQ(PERMISSION_DENIED, | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1197 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1198 |  | 
|  | 1199 | Transaction().setFlags(layer, 0, layer_state_t::eLayerSecure).apply(true); | 
|  | 1200 | ASSERT_EQ(NO_ERROR, | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1201 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1202 | } | 
|  | 1203 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1204 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintBasic_BufferQueue) { | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1205 | const Rect top(0, 0, 32, 16); | 
|  | 1206 | const Rect bottom(0, 16, 32, 32); | 
|  | 1207 | sp<SurfaceControl> layer; | 
|  | 1208 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 1209 |  | 
|  | 1210 | ANativeWindow_Buffer buffer; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1211 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); | 
|  | 1212 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::TRANSPARENT)); | 
|  | 1213 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::RED)); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1214 | // setTransparentRegionHint always applies to the following buffer | 
|  | 1215 | Transaction().setTransparentRegionHint(layer, Region(top)).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1216 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1217 | { | 
|  | 1218 | SCOPED_TRACE("top transparent"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1219 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1220 | shot->expectColor(top, Color::BLACK); | 
|  | 1221 | shot->expectColor(bottom, Color::RED); | 
|  | 1222 | } | 
|  | 1223 |  | 
|  | 1224 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); | 
|  | 1225 | { | 
|  | 1226 | SCOPED_TRACE("transparent region hint pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1227 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1228 | shot->expectColor(top, Color::BLACK); | 
|  | 1229 | shot->expectColor(bottom, Color::RED); | 
|  | 1230 | } | 
|  | 1231 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1232 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); | 
|  | 1233 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::RED)); | 
|  | 1234 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::TRANSPARENT)); | 
|  | 1235 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1236 | { | 
|  | 1237 | SCOPED_TRACE("bottom transparent"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1238 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1239 | shot->expectColor(top, Color::RED); | 
|  | 1240 | shot->expectColor(bottom, Color::BLACK); | 
|  | 1241 | } | 
|  | 1242 | } | 
|  | 1243 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1244 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1245 | const Rect top(0, 0, 32, 16); | 
|  | 1246 | const Rect bottom(0, 16, 32, 32); | 
|  | 1247 | sp<SurfaceControl> layer; | 
|  | 1248 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1249 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1250 |  | 
|  | 1251 | sp<GraphicBuffer> buffer = | 
|  | 1252 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 1253 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 1254 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 1255 | "test"); | 
|  | 1256 |  | 
|  | 1257 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::TRANSPARENT)); | 
|  | 1258 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::RED)); | 
|  | 1259 | Transaction() | 
|  | 1260 | .setTransparentRegionHint(layer, Region(top)) | 
|  | 1261 | .setBuffer(layer, buffer) | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1262 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1263 | .apply(); | 
|  | 1264 | { | 
|  | 1265 | SCOPED_TRACE("top transparent"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1266 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1267 | shot->expectColor(top, Color::BLACK); | 
|  | 1268 | shot->expectColor(bottom, Color::RED); | 
|  | 1269 | } | 
|  | 1270 |  | 
|  | 1271 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); | 
|  | 1272 | { | 
|  | 1273 | SCOPED_TRACE("transparent region hint intermediate"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1274 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1275 | shot->expectColor(top, Color::BLACK); | 
|  | 1276 | shot->expectColor(bottom, Color::BLACK); | 
|  | 1277 | } | 
|  | 1278 |  | 
|  | 1279 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 1280 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 1281 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 1282 | "test"); | 
|  | 1283 |  | 
|  | 1284 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::RED)); | 
|  | 1285 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::TRANSPARENT)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1286 | Transaction().setBuffer(layer, buffer).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1287 | { | 
|  | 1288 | SCOPED_TRACE("bottom transparent"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1289 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1290 | shot->expectColor(top, Color::RED); | 
|  | 1291 | shot->expectColor(bottom, Color::BLACK); | 
|  | 1292 | } | 
|  | 1293 | } | 
|  | 1294 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1295 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintOutOfBounds_BufferQueue) { | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1296 | sp<SurfaceControl> layerTransparent; | 
|  | 1297 | sp<SurfaceControl> layerR; | 
|  | 1298 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); | 
|  | 1299 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
|  | 1300 |  | 
|  | 1301 | // check that transparent region hint is bound by the layer size | 
|  | 1302 | Transaction() | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1303 | .setTransparentRegionHint(layerTransparent, Region(mDisplayRect)) | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1304 | .setPosition(layerR, 16, 16) | 
|  | 1305 | .setLayer(layerR, mLayerZBase + 1) | 
|  | 1306 | .apply(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1307 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1308 | fillBufferQueueLayerColor(layerTransparent, Color::TRANSPARENT, 32, 32)); | 
|  | 1309 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layerR, Color::RED, 32, 32)); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1310 | getScreenCapture()->expectColor(Rect(16, 16, 48, 48), Color::RED); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1311 | } | 
|  | 1312 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1313 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintOutOfBounds_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1314 | sp<SurfaceControl> layerTransparent; | 
|  | 1315 | sp<SurfaceControl> layerR; | 
|  | 1316 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); | 
|  | 1317 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1318 | layerR = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1319 |  | 
|  | 1320 | // check that transparent region hint is bound by the layer size | 
|  | 1321 | Transaction() | 
|  | 1322 | .setTransparentRegionHint(layerTransparent, Region(mDisplayRect)) | 
|  | 1323 | .setFrame(layerR, Rect(16, 16, 48, 48)) | 
|  | 1324 | .setLayer(layerR, mLayerZBase + 1) | 
|  | 1325 | .apply(); | 
|  | 1326 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1327 | fillBufferQueueLayerColor(layerTransparent, Color::TRANSPARENT, 32, 32)); | 
|  | 1328 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layerR, Color::RED, 32, 32)); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1329 | getScreenCapture()->expectColor(Rect(16, 16, 48, 48), Color::RED); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1330 | } | 
|  | 1331 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1332 | void LayerRenderTypeTransactionTest::setAlphaBasicHelper(uint32_t layerType) { | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1333 | sp<SurfaceControl> layer1; | 
|  | 1334 | sp<SurfaceControl> layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1335 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer("test 1", 32, 32, layerType)); | 
|  | 1336 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer("test 2", 32, 32, layerType)); | 
|  | 1337 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer1, {64, 0, 0, 255}, 32, 32)); | 
|  | 1338 | 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] | 1339 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1340 | switch (layerType) { | 
|  | 1341 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 1342 | Transaction() | 
|  | 1343 | .setAlpha(layer1, 0.25f) | 
|  | 1344 | .setAlpha(layer2, 0.75f) | 
|  | 1345 | .setPosition(layer2, 16, 0) | 
|  | 1346 | .setLayer(layer2, mLayerZBase + 1) | 
|  | 1347 | .apply(); | 
|  | 1348 | break; | 
|  | 1349 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 1350 | Transaction() | 
|  | 1351 | .setAlpha(layer1, 0.25f) | 
|  | 1352 | .setAlpha(layer2, 0.75f) | 
|  | 1353 | .setFrame(layer1, Rect(0, 0, 32, 32)) | 
|  | 1354 | .setFrame(layer2, Rect(16, 0, 48, 32)) | 
|  | 1355 | .setLayer(layer2, mLayerZBase + 1) | 
|  | 1356 | .apply(); | 
|  | 1357 | break; | 
|  | 1358 | default: | 
|  | 1359 | ASSERT_FALSE(true) << "Unsupported layer type"; | 
|  | 1360 | } | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1361 | { | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1362 | auto shot = getScreenCapture(); | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1363 | uint8_t r = 16; // 64 * 0.25f | 
|  | 1364 | uint8_t g = 48; // 64 * 0.75f | 
|  | 1365 | shot->expectColor(Rect(0, 0, 16, 32), {r, 0, 0, 255}); | 
|  | 1366 | shot->expectColor(Rect(32, 0, 48, 32), {0, g, 0, 255}); | 
|  | 1367 |  | 
|  | 1368 | r /= 4; // r * (1.0f - 0.75f) | 
|  | 1369 | shot->expectColor(Rect(16, 0, 32, 32), {r, g, 0, 255}); | 
|  | 1370 | } | 
|  | 1371 | } | 
|  | 1372 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1373 | TEST_P(LayerRenderTypeTransactionTest, SetAlphaBasic_BufferQueue) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1374 | ASSERT_NO_FATAL_FAILURE(setAlphaBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); | 
|  | 1375 | } | 
|  | 1376 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1377 | TEST_P(LayerRenderTypeTransactionTest, SetAlphaBasic_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1378 | ASSERT_NO_FATAL_FAILURE(setAlphaBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1379 | } | 
|  | 1380 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1381 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetAlphaClamped) { | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1382 | const Color color = {64, 0, 0, 255}; | 
|  | 1383 | sp<SurfaceControl> layer; | 
|  | 1384 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1385 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, color, 32, 32)); | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1386 |  | 
|  | 1387 | Transaction().setAlpha(layer, 2.0f).apply(); | 
|  | 1388 | { | 
|  | 1389 | SCOPED_TRACE("clamped to 1.0f"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1390 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), color); | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1391 | } | 
|  | 1392 |  | 
|  | 1393 | Transaction().setAlpha(layer, -1.0f).apply(); | 
|  | 1394 | { | 
|  | 1395 | SCOPED_TRACE("clamped to 0.0f"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1396 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1397 | } | 
|  | 1398 | } | 
|  | 1399 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1400 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadius) { | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1401 | sp<SurfaceControl> layer; | 
|  | 1402 | const uint8_t size = 64; | 
|  | 1403 | const uint8_t testArea = 4; | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1404 | const float cornerRadius = 20.0f; | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1405 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", size, size)); | 
|  | 1406 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, size, size)); | 
|  | 1407 |  | 
|  | 1408 | Transaction() | 
|  | 1409 | .setCornerRadius(layer, cornerRadius) | 
|  | 1410 | .apply(); | 
|  | 1411 | { | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1412 | const uint8_t bottom = size - 1; | 
|  | 1413 | const uint8_t right = size - 1; | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1414 | auto shot = getScreenCapture(); | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1415 | // Transparent corners | 
|  | 1416 | shot->expectColor(Rect(0, 0, testArea, testArea), Color::BLACK); | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1417 | shot->expectColor(Rect(size - testArea, 0, right, testArea), Color::BLACK); | 
|  | 1418 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); | 
|  | 1419 | shot->expectColor(Rect(size - testArea, bottom - testArea, right, bottom), Color::BLACK); | 
|  | 1420 | } | 
|  | 1421 | } | 
|  | 1422 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1423 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusChildCrop) { | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1424 | sp<SurfaceControl> parent; | 
|  | 1425 | sp<SurfaceControl> child; | 
|  | 1426 | const uint8_t size = 64; | 
|  | 1427 | const uint8_t testArea = 4; | 
|  | 1428 | const float cornerRadius = 20.0f; | 
|  | 1429 | ASSERT_NO_FATAL_FAILURE(parent = createLayer("parent", size, size)); | 
|  | 1430 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(parent, Color::RED, size, size)); | 
|  | 1431 | ASSERT_NO_FATAL_FAILURE(child = createLayer("child", size, size / 2)); | 
|  | 1432 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(child, Color::GREEN, size, size / 2)); | 
|  | 1433 |  | 
|  | 1434 | Transaction() | 
|  | 1435 | .setCornerRadius(parent, cornerRadius) | 
|  | 1436 | .reparent(child, parent->getHandle()) | 
|  | 1437 | .setPosition(child, 0, size / 2) | 
|  | 1438 | .apply(); | 
|  | 1439 | { | 
|  | 1440 | const uint8_t bottom = size - 1; | 
|  | 1441 | const uint8_t right = size - 1; | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1442 | auto shot = getScreenCapture(); | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1443 | // Top edge of child should not have rounded corners because it's translated in the parent | 
|  | 1444 | shot->expectColor(Rect(0, size / 2, right, static_cast<int>(bottom - cornerRadius)), | 
|  | 1445 | Color::GREEN); | 
|  | 1446 | // But bottom edges should have been clipped according to parent bounds | 
|  | 1447 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); | 
|  | 1448 | shot->expectColor(Rect(right - testArea, bottom - testArea, right, bottom), Color::BLACK); | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1449 | } | 
|  | 1450 | } | 
|  | 1451 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1452 | TEST_P(LayerRenderTypeTransactionTest, SetColorBasic) { | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1453 | sp<SurfaceControl> bufferLayer; | 
|  | 1454 | sp<SurfaceControl> colorLayer; | 
|  | 1455 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1456 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1457 | ASSERT_NO_FATAL_FAILURE(colorLayer = | 
|  | 1458 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 1459 | ISurfaceComposerClient::eFXSurfaceColor)); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1460 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1461 | Transaction() | 
|  | 1462 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 1463 | .setLayer(colorLayer, mLayerZBase + 1) | 
|  | 1464 | .apply(); | 
|  | 1465 |  | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1466 | { | 
|  | 1467 | SCOPED_TRACE("default color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1468 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1469 | } | 
|  | 1470 |  | 
|  | 1471 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); | 
|  | 1472 | const Color expected = {15, 51, 85, 255}; | 
|  | 1473 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 1474 | // channel) should be less than one | 
|  | 1475 | const uint8_t tolerance = 1; | 
|  | 1476 | Transaction().setColor(colorLayer, color).apply(); | 
|  | 1477 | { | 
|  | 1478 | SCOPED_TRACE("new color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1479 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expected, tolerance); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1480 | } | 
|  | 1481 | } | 
|  | 1482 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1483 | // RED: Color layer base color and BufferQueueLayer/BufferStateLayer fill | 
|  | 1484 | // BLUE: prior background color | 
|  | 1485 | // GREEN: final background color | 
|  | 1486 | // BLACK: no color or fill | 
|  | 1487 | void LayerRenderTypeTransactionTest::setBackgroundColorHelper(uint32_t layerType, bool priorColor, | 
|  | 1488 | bool bufferFill, float alpha, | 
|  | 1489 | Color finalColor) { | 
|  | 1490 | sp<SurfaceControl> layer; | 
|  | 1491 | int32_t width = 500; | 
|  | 1492 | int32_t height = 500; | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1493 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1494 | Color fillColor = Color::RED; | 
|  | 1495 | Color priorBgColor = Color::BLUE; | 
|  | 1496 | Color expectedColor = Color::BLACK; | 
|  | 1497 | switch (layerType) { | 
|  | 1498 | case ISurfaceComposerClient::eFXSurfaceColor: | 
|  | 1499 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 0, 0, layerType)); | 
|  | 1500 | Transaction() | 
|  | 1501 | .setCrop_legacy(layer, Rect(0, 0, width, height)) | 
|  | 1502 | .setColor(layer, half3(1.0f, 0, 0)) | 
|  | 1503 | .apply(); | 
|  | 1504 | expectedColor = fillColor; | 
|  | 1505 | break; | 
|  | 1506 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 1507 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", width, height)); | 
|  | 1508 | if (bufferFill) { | 
|  | 1509 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, fillColor, width, height)); | 
|  | 1510 | expectedColor = fillColor; | 
|  | 1511 | } | 
|  | 1512 | Transaction().setCrop_legacy(layer, Rect(0, 0, width, height)).apply(); | 
|  | 1513 | break; | 
|  | 1514 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 1515 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", width, height, layerType)); | 
|  | 1516 | if (bufferFill) { | 
|  | 1517 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, fillColor, width, height)); | 
|  | 1518 | expectedColor = fillColor; | 
|  | 1519 | } | 
|  | 1520 | Transaction().setFrame(layer, Rect(0, 0, width, height)).apply(); | 
|  | 1521 | break; | 
|  | 1522 | default: | 
|  | 1523 | GTEST_FAIL() << "Unknown layer type in setBackgroundColorHelper"; | 
|  | 1524 | return; | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1525 | } | 
|  | 1526 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1527 | if (priorColor && layerType != ISurfaceComposerClient::eFXSurfaceColor) { | 
|  | 1528 | Transaction() | 
|  | 1529 | .setBackgroundColor(layer, half3(0, 0, 1.0f), 1.0f, ui::Dataspace::UNKNOWN) | 
|  | 1530 | .apply(); | 
|  | 1531 | if (!bufferFill) { | 
|  | 1532 | expectedColor = priorBgColor; | 
|  | 1533 | } | 
|  | 1534 | } | 
|  | 1535 |  | 
|  | 1536 | { | 
|  | 1537 | SCOPED_TRACE("default before setting background color layer"); | 
|  | 1538 | screenshot()->expectColor(Rect(0, 0, width, height), expectedColor); | 
|  | 1539 | } | 
|  | 1540 |  | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1541 | Transaction() | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1542 | .setBackgroundColor(layer, half3(0, 1.0f, 0), alpha, ui::Dataspace::UNKNOWN) | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1543 | .apply(); | 
|  | 1544 |  | 
|  | 1545 | { | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1546 | auto shot = screenshot(); | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1547 | shot->expectColor(Rect(0, 0, width, height), finalColor); | 
|  | 1548 | shot->expectBorder(Rect(0, 0, width, height), Color::BLACK); | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1549 | } | 
|  | 1550 | } | 
|  | 1551 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1552 | TEST_P(LayerRenderTypeTransactionTest, SetBackgroundColor_Color_NoEffect) { | 
|  | 1553 | bool priorColor = false; | 
|  | 1554 | bool bufferFill = false; | 
|  | 1555 | float alpha = 1.0f; | 
|  | 1556 | Color finalColor = Color::RED; | 
|  | 1557 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceColor, | 
|  | 1558 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1559 | } | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1560 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1561 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1562 | SetBackgroundColor_BufferQueue_BufferFill_NoPriorColor_Basic) { | 
|  | 1563 | bool priorColor = false; | 
|  | 1564 | bool bufferFill = true; | 
|  | 1565 | float alpha = 1.0f; | 
|  | 1566 | Color finalColor = Color::RED; | 
|  | 1567 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1568 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1569 | } | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1570 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1571 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1572 | SetBackgroundColor_BufferQueue_NoBufferFill_NoPriorColor_Basic) { | 
|  | 1573 | bool priorColor = false; | 
|  | 1574 | bool bufferFill = false; | 
|  | 1575 | float alpha = 1.0f; | 
|  | 1576 | Color finalColor = Color::GREEN; | 
|  | 1577 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1578 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1579 | } | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1580 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1581 | TEST_P(LayerRenderTypeTransactionTest, SetBackgroundColor_BufferQueue_BufferFill_PriorColor_Basic) { | 
|  | 1582 | bool priorColor = true; | 
|  | 1583 | bool bufferFill = true; | 
|  | 1584 | float alpha = 1.0f; | 
|  | 1585 | Color finalColor = Color::RED; | 
|  | 1586 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1587 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1588 | } | 
|  | 1589 |  | 
|  | 1590 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1591 | SetBackgroundColor_BufferQueue_NoBufferFill_PriorColor_Basic) { | 
|  | 1592 | bool priorColor = true; | 
|  | 1593 | bool bufferFill = false; | 
|  | 1594 | float alpha = 1.0f; | 
|  | 1595 | Color finalColor = Color::GREEN; | 
|  | 1596 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1597 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1598 | } | 
|  | 1599 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1600 | SetBackgroundColor_BufferQueue_NoPriorColor_ZeroAlpha_NoEffect) { | 
|  | 1601 | bool priorColor = false; | 
|  | 1602 | bool bufferFill = false; | 
|  | 1603 | float alpha = 0; | 
|  | 1604 | Color finalColor = Color::BLACK; | 
|  | 1605 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1606 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1607 | } | 
|  | 1608 |  | 
|  | 1609 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1610 | SetBackgroundColor_BufferQueue_PriorColor_ZeroAlpha_DeleteBackground) { | 
|  | 1611 | bool priorColor = true; | 
|  | 1612 | bool bufferFill = false; | 
|  | 1613 | float alpha = 0; | 
|  | 1614 | Color finalColor = Color::BLACK; | 
|  | 1615 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1616 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1617 | } | 
|  | 1618 |  | 
|  | 1619 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1620 | SetBackgroundColor_BufferState_BufferFill_NoPriorColor_Basic) { | 
|  | 1621 | bool priorColor = false; | 
|  | 1622 | bool bufferFill = true; | 
|  | 1623 | float alpha = 1.0f; | 
|  | 1624 | Color finalColor = Color::RED; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1625 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1626 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1627 | } | 
|  | 1628 |  | 
|  | 1629 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1630 | SetBackgroundColor_BufferState_NoBufferFill_NoPriorColor_Basic) { | 
|  | 1631 | bool priorColor = false; | 
|  | 1632 | bool bufferFill = false; | 
|  | 1633 | float alpha = 1.0f; | 
|  | 1634 | Color finalColor = Color::GREEN; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1635 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1636 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1637 | } | 
|  | 1638 |  | 
|  | 1639 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1640 | SetBackgroundColor_BufferState_NoBufferFill_PriorColor_Basic) { | 
|  | 1641 | bool priorColor = true; | 
|  | 1642 | bool bufferFill = false; | 
|  | 1643 | float alpha = 1.0f; | 
|  | 1644 | Color finalColor = Color::GREEN; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1645 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1646 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1647 | } | 
|  | 1648 |  | 
|  | 1649 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1650 | SetBackgroundColor_BufferState_NoPriorColor_ZeroAlpha_NoEffect) { | 
|  | 1651 | bool priorColor = false; | 
|  | 1652 | bool bufferFill = false; | 
|  | 1653 | float alpha = 0; | 
|  | 1654 | Color finalColor = Color::BLACK; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1655 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1656 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1657 | } | 
|  | 1658 |  | 
|  | 1659 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1660 | SetBackgroundColor_BufferState_PriorColor_ZeroAlpha_DeleteBackground) { | 
|  | 1661 | bool priorColor = true; | 
|  | 1662 | bool bufferFill = false; | 
|  | 1663 | float alpha = 0; | 
|  | 1664 | Color finalColor = Color::BLACK; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1665 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1666 | priorColor, bufferFill, alpha, finalColor)); | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1667 | } | 
|  | 1668 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1669 | TEST_P(LayerRenderTypeTransactionTest, SetColorClamped) { | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1670 | sp<SurfaceControl> colorLayer; | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1671 | ASSERT_NO_FATAL_FAILURE(colorLayer = | 
|  | 1672 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 1673 | ISurfaceComposerClient::eFXSurfaceColor)); | 
|  | 1674 | Transaction() | 
|  | 1675 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 1676 | .setColor(colorLayer, half3(2.0f, -1.0f, 0.0f)) | 
|  | 1677 | .apply(); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1678 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1679 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1680 | } | 
|  | 1681 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1682 | TEST_P(LayerRenderTypeTransactionTest, SetColorWithAlpha) { | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1683 | sp<SurfaceControl> bufferLayer; | 
|  | 1684 | sp<SurfaceControl> colorLayer; | 
|  | 1685 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1686 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1687 | ASSERT_NO_FATAL_FAILURE(colorLayer = | 
|  | 1688 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 1689 | ISurfaceComposerClient::eFXSurfaceColor)); | 
|  | 1690 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1691 |  | 
|  | 1692 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); | 
|  | 1693 | const float alpha = 0.25f; | 
|  | 1694 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); | 
|  | 1695 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 1696 | // channel) should be less than one | 
|  | 1697 | const uint8_t tolerance = 1; | 
|  | 1698 | Transaction() | 
|  | 1699 | .setColor(colorLayer, color) | 
|  | 1700 | .setAlpha(colorLayer, alpha) | 
|  | 1701 | .setLayer(colorLayer, mLayerZBase + 1) | 
|  | 1702 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1703 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, | 
|  | 1704 | tolerance); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1705 | } | 
|  | 1706 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1707 | TEST_P(LayerRenderTypeTransactionTest, SetColorWithParentAlpha_Bug74220420) { | 
| Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1708 | sp<SurfaceControl> bufferLayer; | 
|  | 1709 | sp<SurfaceControl> parentLayer; | 
|  | 1710 | sp<SurfaceControl> colorLayer; | 
|  | 1711 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); | 
|  | 1712 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parentWithAlpha", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1713 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1714 | ASSERT_NO_FATAL_FAILURE(colorLayer = createLayer("childWithColor", 0 /* buffer width */, | 
|  | 1715 | 0 /* buffer height */, | 
|  | 1716 | ISurfaceComposerClient::eFXSurfaceColor)); | 
|  | 1717 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); | 
| Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1718 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); | 
|  | 1719 | const float alpha = 0.25f; | 
|  | 1720 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); | 
|  | 1721 | // this is handwavy, but the precision loss scaled by 255 (8-bit per | 
|  | 1722 | // channel) should be less than one | 
|  | 1723 | const uint8_t tolerance = 1; | 
|  | 1724 | Transaction() | 
|  | 1725 | .reparent(colorLayer, parentLayer->getHandle()) | 
|  | 1726 | .setColor(colorLayer, color) | 
|  | 1727 | .setAlpha(parentLayer, alpha) | 
|  | 1728 | .setLayer(parentLayer, mLayerZBase + 1) | 
|  | 1729 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1730 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, | 
|  | 1731 | tolerance); | 
| Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1732 | } | 
|  | 1733 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1734 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetColorWithBuffer) { | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1735 | sp<SurfaceControl> bufferLayer; | 
|  | 1736 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1737 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED, 32, 32)); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1738 |  | 
|  | 1739 | // color is ignored | 
|  | 1740 | Transaction().setColor(bufferLayer, half3(0.0f, 1.0f, 0.0f)).apply(); | 
| 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(LayerTypeAndRenderTypeTransactionTest, SetLayerStackBasic) { | 
| Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1745 | sp<SurfaceControl> layer; | 
|  | 1746 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1747 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1748 |  | 
|  | 1749 | Transaction().setLayerStack(layer, mDisplayLayerStack + 1).apply(); | 
|  | 1750 | { | 
|  | 1751 | SCOPED_TRACE("non-existing layer stack"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1752 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); | 
| Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1753 | } | 
|  | 1754 |  | 
|  | 1755 | Transaction().setLayerStack(layer, mDisplayLayerStack).apply(); | 
|  | 1756 | { | 
|  | 1757 | SCOPED_TRACE("original layer stack"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1758 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1759 | } | 
|  | 1760 | } | 
|  | 1761 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1762 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixBasic_BufferQueue) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1763 | sp<SurfaceControl> layer; | 
|  | 1764 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1765 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 1766 | Color::BLUE, Color::WHITE)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1767 |  | 
|  | 1768 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 0, 0).apply(); | 
|  | 1769 | { | 
|  | 1770 | SCOPED_TRACE("IDENTITY"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1771 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 1772 | Color::BLUE, Color::WHITE); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1773 | } | 
|  | 1774 |  | 
|  | 1775 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 32, 0).apply(); | 
|  | 1776 | { | 
|  | 1777 | SCOPED_TRACE("FLIP_H"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1778 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, | 
|  | 1779 | Color::WHITE, Color::BLUE); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1780 | } | 
|  | 1781 |  | 
|  | 1782 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).setPosition(layer, 0, 32).apply(); | 
|  | 1783 | { | 
|  | 1784 | SCOPED_TRACE("FLIP_V"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1785 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, | 
|  | 1786 | Color::RED, Color::GREEN); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1787 | } | 
|  | 1788 |  | 
|  | 1789 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).setPosition(layer, 32, 0).apply(); | 
|  | 1790 | { | 
|  | 1791 | SCOPED_TRACE("ROT_90"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1792 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, | 
|  | 1793 | Color::WHITE, Color::GREEN); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1794 | } | 
|  | 1795 |  | 
|  | 1796 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setPosition(layer, 0, 0).apply(); | 
|  | 1797 | { | 
|  | 1798 | SCOPED_TRACE("SCALE"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1799 | getScreenCapture()->expectQuadrant(Rect(0, 0, 64, 64), Color::RED, Color::GREEN, | 
|  | 1800 | Color::BLUE, Color::WHITE, true /* filtered */); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1801 | } | 
|  | 1802 | } | 
|  | 1803 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1804 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixBasic_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1805 | sp<SurfaceControl> layer; | 
|  | 1806 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1807 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1808 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 1809 | Color::BLUE, Color::WHITE)); | 
|  | 1810 |  | 
|  | 1811 | Transaction() | 
|  | 1812 | .setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f) | 
|  | 1813 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
|  | 1814 | .apply(); | 
|  | 1815 | { | 
|  | 1816 | SCOPED_TRACE("IDENTITY"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1817 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 1818 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1819 | } | 
|  | 1820 |  | 
|  | 1821 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).apply(); | 
|  | 1822 | { | 
|  | 1823 | SCOPED_TRACE("FLIP_H"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1824 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 1825 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1826 | } | 
|  | 1827 |  | 
|  | 1828 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).apply(); | 
|  | 1829 | { | 
|  | 1830 | SCOPED_TRACE("FLIP_V"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1831 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 1832 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1833 | } | 
|  | 1834 |  | 
|  | 1835 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).apply(); | 
|  | 1836 | { | 
|  | 1837 | SCOPED_TRACE("ROT_90"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1838 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 1839 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1840 | } | 
|  | 1841 |  | 
|  | 1842 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).apply(); | 
|  | 1843 | { | 
|  | 1844 | SCOPED_TRACE("SCALE"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1845 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 1846 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1847 | } | 
|  | 1848 | } | 
|  | 1849 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1850 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixRot45_BufferQueue) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1851 | sp<SurfaceControl> layer; | 
|  | 1852 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1853 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 1854 | Color::BLUE, Color::WHITE)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1855 |  | 
|  | 1856 | const float rot = M_SQRT1_2; // 45 degrees | 
|  | 1857 | const float trans = M_SQRT2 * 16.0f; | 
|  | 1858 | Transaction().setMatrix(layer, rot, rot, -rot, rot).setPosition(layer, trans, 0).apply(); | 
|  | 1859 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1860 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1861 | // check a 8x8 region inside each color | 
|  | 1862 | auto get8x8Rect = [](int32_t centerX, int32_t centerY) { | 
|  | 1863 | const int32_t halfL = 4; | 
|  | 1864 | return Rect(centerX - halfL, centerY - halfL, centerX + halfL, centerY + halfL); | 
|  | 1865 | }; | 
|  | 1866 | const int32_t unit = int32_t(trans / 2); | 
|  | 1867 | shot->expectColor(get8x8Rect(2 * unit, 1 * unit), Color::RED); | 
|  | 1868 | shot->expectColor(get8x8Rect(3 * unit, 2 * unit), Color::GREEN); | 
|  | 1869 | shot->expectColor(get8x8Rect(1 * unit, 2 * unit), Color::BLUE); | 
|  | 1870 | shot->expectColor(get8x8Rect(2 * unit, 3 * unit), Color::WHITE); | 
|  | 1871 | } | 
|  | 1872 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1873 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixWithResize_BufferQueue) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1874 | sp<SurfaceControl> layer; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1875 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 1876 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1877 |  | 
|  | 1878 | // setMatrix is applied after any pending resize, unlike setPosition | 
|  | 1879 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setSize(layer, 64, 64).apply(); | 
|  | 1880 | { | 
|  | 1881 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1882 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1883 | const Rect rect(0, 0, 32, 32); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1884 | shot->expectColor(rect, Color::RED); | 
|  | 1885 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1886 | } | 
|  | 1887 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1888 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1889 | { | 
|  | 1890 | SCOPED_TRACE("resize applied"); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1891 | const Rect rect(0, 0, 128, 128); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1892 | getScreenCapture()->expectColor(rect, Color::RED); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1893 | } | 
|  | 1894 | } | 
|  | 1895 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1896 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixWithScaleToWindow_BufferQueue) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1897 | sp<SurfaceControl> layer; | 
|  | 1898 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1899 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1900 |  | 
|  | 1901 | // setMatrix is immediate with SCALE_TO_WINDOW, unlike setPosition | 
|  | 1902 | Transaction() | 
|  | 1903 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) | 
|  | 1904 | .setSize(layer, 64, 64) | 
|  | 1905 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 1906 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1907 | getScreenCapture()->expectColor(Rect(0, 0, 128, 128), Color::RED); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1908 | } | 
|  | 1909 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1910 | TEST_P(LayerRenderTypeTransactionTest, SetOverrideScalingModeBasic_BufferQueue) { | 
| Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1911 | sp<SurfaceControl> layer; | 
|  | 1912 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1913 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 1914 | Color::BLUE, Color::WHITE)); | 
| Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1915 |  | 
|  | 1916 | // XXX SCALE_CROP is not respected; calling setSize and | 
|  | 1917 | // setOverrideScalingMode in separate transactions does not work | 
|  | 1918 | // (b/69315456) | 
|  | 1919 | Transaction() | 
|  | 1920 | .setSize(layer, 64, 16) | 
|  | 1921 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 1922 | .apply(); | 
|  | 1923 | { | 
|  | 1924 | SCOPED_TRACE("SCALE_TO_WINDOW"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1925 | getScreenCapture()->expectQuadrant(Rect(0, 0, 64, 16), Color::RED, Color::GREEN, | 
|  | 1926 | Color::BLUE, Color::WHITE, true /* filtered */); | 
| Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1927 | } | 
|  | 1928 | } | 
|  | 1929 |  | 
| Dan Stoza | 000dd01 | 2018-08-01 13:31:52 -0700 | [diff] [blame] | 1930 | TEST_P(LayerTypeTransactionTest, RefreshRateIsInitialized) { | 
|  | 1931 | sp<SurfaceControl> layer; | 
|  | 1932 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 1933 |  | 
|  | 1934 | sp<IBinder> handle = layer->getHandle(); | 
|  | 1935 | ASSERT_TRUE(handle != nullptr); | 
|  | 1936 |  | 
|  | 1937 | FrameStats frameStats; | 
|  | 1938 | mClient->getLayerFrameStats(handle, &frameStats); | 
|  | 1939 |  | 
|  | 1940 | ASSERT_GT(frameStats.refreshPeriodNano, static_cast<nsecs_t>(0)); | 
|  | 1941 | } | 
|  | 1942 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1943 | TEST_P(LayerRenderTypeTransactionTest, SetCropBasic_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1944 | sp<SurfaceControl> layer; | 
|  | 1945 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1946 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1947 | const Rect crop(8, 8, 24, 24); | 
|  | 1948 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1949 | Transaction().setCrop_legacy(layer, crop).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1950 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1951 | shot->expectColor(crop, Color::RED); | 
|  | 1952 | shot->expectBorder(crop, Color::BLACK); | 
|  | 1953 | } | 
|  | 1954 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1955 | TEST_P(LayerRenderTypeTransactionTest, SetCropBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1956 | sp<SurfaceControl> layer; | 
|  | 1957 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1958 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1959 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 1960 | const Rect crop(8, 8, 24, 24); | 
|  | 1961 |  | 
|  | 1962 | Transaction().setCrop(layer, crop).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1963 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1964 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 1965 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1966 | } | 
|  | 1967 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1968 | TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1969 | sp<SurfaceControl> layer; | 
|  | 1970 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1971 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1972 |  | 
|  | 1973 | { | 
|  | 1974 | SCOPED_TRACE("empty rect"); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1975 | Transaction().setCrop_legacy(layer, Rect(8, 8, 8, 8)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1976 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1977 | } | 
|  | 1978 |  | 
|  | 1979 | { | 
|  | 1980 | SCOPED_TRACE("negative rect"); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 1981 | Transaction().setCrop_legacy(layer, Rect(8, 8, 0, 0)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1982 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1983 | } | 
|  | 1984 | } | 
|  | 1985 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1986 | TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1987 | sp<SurfaceControl> layer; | 
|  | 1988 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1989 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1990 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 1991 |  | 
|  | 1992 | { | 
|  | 1993 | SCOPED_TRACE("empty rect"); | 
|  | 1994 | Transaction().setCrop(layer, Rect(8, 8, 8, 8)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1995 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1996 | } | 
|  | 1997 |  | 
|  | 1998 | { | 
|  | 1999 | SCOPED_TRACE("negative rect"); | 
|  | 2000 | Transaction().setCrop(layer, Rect(8, 8, 0, 0)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2001 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2002 | } | 
|  | 2003 | } | 
|  | 2004 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2005 | TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_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 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2010 | Transaction().setCrop_legacy(layer, Rect(-128, -64, 128, 64)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2011 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2012 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2013 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2014 | } | 
|  | 2015 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2016 | TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferState) { | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2017 | sp<SurfaceControl> layer; | 
|  | 2018 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", mDisplayWidth, mDisplayHeight / 2, | 
|  | 2019 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2020 | sp<GraphicBuffer> buffer = | 
|  | 2021 | new GraphicBuffer(mDisplayWidth, mDisplayHeight / 2, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2022 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2023 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2024 | "test"); | 
|  | 2025 | fillGraphicBufferColor(buffer, Rect(0, 0, mDisplayWidth, mDisplayHeight / 4), Color::BLUE); | 
|  | 2026 | fillGraphicBufferColor(buffer, Rect(0, mDisplayHeight / 4, mDisplayWidth, mDisplayHeight / 2), | 
|  | 2027 | Color::RED); | 
|  | 2028 |  | 
|  | 2029 | Transaction().setBuffer(layer, buffer).apply(); | 
|  | 2030 |  | 
|  | 2031 | // Partially out of bounds in the negative (upper left) direction | 
|  | 2032 | Transaction().setCrop(layer, Rect(-128, -128, mDisplayWidth, mDisplayHeight / 4)).apply(); | 
|  | 2033 | { | 
|  | 2034 | SCOPED_TRACE("out of bounds, negative (upper left) direction"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2035 | auto shot = getScreenCapture(); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2036 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::BLUE); | 
|  | 2037 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::BLACK); | 
|  | 2038 | } | 
|  | 2039 |  | 
|  | 2040 | // Partially out of bounds in the positive (lower right) direction | 
|  | 2041 | Transaction() | 
|  | 2042 | .setCrop(layer, Rect(0, mDisplayHeight / 4, mDisplayWidth + 1, mDisplayHeight)) | 
|  | 2043 | .apply(); | 
|  | 2044 | { | 
|  | 2045 | SCOPED_TRACE("out of bounds, positive (lower right) direction"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2046 | auto shot = getScreenCapture(); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2047 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::RED); | 
|  | 2048 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight / 2), Color::BLACK); | 
|  | 2049 | } | 
|  | 2050 |  | 
|  | 2051 | // Fully out of buffer space bounds | 
|  | 2052 | Transaction().setCrop(layer, Rect(-128, -128, -1, -1)).apply(); | 
|  | 2053 | { | 
|  | 2054 | SCOPED_TRACE("Fully out of bounds"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2055 | auto shot = getScreenCapture(); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2056 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight / 4), Color::BLUE); | 
|  | 2057 | shot->expectColor(Rect(0, mDisplayHeight / 4, mDisplayWidth, mDisplayHeight / 2), | 
|  | 2058 | Color::RED); | 
|  | 2059 | } | 
|  | 2060 | } | 
|  | 2061 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2062 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithTranslation_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2063 | sp<SurfaceControl> layer; | 
|  | 2064 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2065 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2066 |  | 
|  | 2067 | const Point position(32, 32); | 
|  | 2068 | const Rect crop(8, 8, 24, 24); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2069 | Transaction().setPosition(layer, position.x, position.y).setCrop_legacy(layer, crop).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2070 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2071 | shot->expectColor(crop + position, Color::RED); | 
|  | 2072 | shot->expectBorder(crop + position, Color::BLACK); | 
|  | 2073 | } | 
|  | 2074 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2075 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithTranslation_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2076 | sp<SurfaceControl> layer; | 
|  | 2077 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2078 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2079 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2080 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2081 | const Rect frame(32, 32, 64, 64); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2082 | const Rect crop(8, 8, 24, 24); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2083 | Transaction().setFrame(layer, frame).setCrop(layer, crop).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2084 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2085 | shot->expectColor(frame, Color::RED); | 
|  | 2086 | shot->expectBorder(frame, Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2087 | } | 
|  | 2088 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2089 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithScale_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2090 | sp<SurfaceControl> layer; | 
|  | 2091 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2092 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2093 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2094 | // crop_legacy is affected by matrix | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2095 | Transaction() | 
|  | 2096 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2097 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2098 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2099 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2100 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); | 
|  | 2101 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); | 
|  | 2102 | } | 
|  | 2103 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2104 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithResize_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2105 | sp<SurfaceControl> layer; | 
|  | 2106 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2107 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2108 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2109 | // setCrop_legacy is applied immediately by default, with or without resize pending | 
|  | 2110 | 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] | 2111 | { | 
|  | 2112 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2113 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2114 | shot->expectColor(Rect(8, 8, 24, 24), Color::RED); | 
|  | 2115 | shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK); | 
|  | 2116 | } | 
|  | 2117 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2118 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2119 | { | 
|  | 2120 | SCOPED_TRACE("resize applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2121 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2122 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); | 
|  | 2123 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); | 
|  | 2124 | } | 
|  | 2125 | } | 
|  | 2126 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2127 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithNextResize_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2128 | sp<SurfaceControl> layer; | 
|  | 2129 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2130 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2131 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2132 | // request setCrop_legacy to be applied with the next resize | 
|  | 2133 | Transaction() | 
|  | 2134 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) | 
|  | 2135 | .setGeometryAppliesWithResize(layer) | 
|  | 2136 | .apply(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2137 | { | 
|  | 2138 | SCOPED_TRACE("waiting for next resize"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2139 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2140 | } | 
|  | 2141 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2142 | Transaction().setCrop_legacy(layer, Rect(4, 4, 12, 12)).apply(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2143 | { | 
|  | 2144 | SCOPED_TRACE("pending crop modified"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2145 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2146 | } | 
|  | 2147 |  | 
|  | 2148 | Transaction().setSize(layer, 16, 16).apply(); | 
|  | 2149 | { | 
|  | 2150 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2151 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2152 | } | 
|  | 2153 |  | 
|  | 2154 | // finally resize | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2155 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2156 | { | 
|  | 2157 | SCOPED_TRACE("new crop applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2158 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2159 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); | 
|  | 2160 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); | 
|  | 2161 | } | 
|  | 2162 | } | 
|  | 2163 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2164 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithNextResizeScaleToWindow_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2165 | sp<SurfaceControl> layer; | 
|  | 2166 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2167 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2168 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2169 | // setCrop_legacy is not immediate even with SCALE_TO_WINDOW override | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2170 | Transaction() | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2171 | .setCrop_legacy(layer, Rect(4, 4, 12, 12)) | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2172 | .setSize(layer, 16, 16) | 
|  | 2173 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 2174 | .setGeometryAppliesWithResize(layer) | 
|  | 2175 | .apply(); | 
|  | 2176 | { | 
|  | 2177 | SCOPED_TRACE("new crop pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2178 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2179 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); | 
|  | 2180 | shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK); | 
|  | 2181 | } | 
|  | 2182 |  | 
|  | 2183 | // XXX crop is never latched without other geometry change (b/69315677) | 
|  | 2184 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2185 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2186 | Transaction().setPosition(layer, 0, 0).apply(); | 
|  | 2187 | { | 
|  | 2188 | SCOPED_TRACE("new crop applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2189 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2190 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); | 
|  | 2191 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); | 
|  | 2192 | } | 
|  | 2193 | } | 
|  | 2194 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2195 | TEST_P(LayerRenderTypeTransactionTest, SetFrameBasic_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2196 | sp<SurfaceControl> layer; | 
|  | 2197 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2198 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2199 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2200 | const Rect frame(8, 8, 24, 24); | 
|  | 2201 |  | 
|  | 2202 | Transaction().setFrame(layer, frame).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2203 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2204 | shot->expectColor(frame, Color::RED); | 
|  | 2205 | shot->expectBorder(frame, Color::BLACK); | 
|  | 2206 | } | 
|  | 2207 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2208 | TEST_P(LayerRenderTypeTransactionTest, SetFrameEmpty_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2209 | sp<SurfaceControl> layer; | 
|  | 2210 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2211 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2212 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2213 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2214 | { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2215 | SCOPED_TRACE("empty rect"); | 
|  | 2216 | Transaction().setFrame(layer, Rect(8, 8, 8, 8)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2217 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2218 | } | 
|  | 2219 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2220 | { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2221 | SCOPED_TRACE("negative rect"); | 
|  | 2222 | Transaction().setFrame(layer, Rect(8, 8, 0, 0)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2223 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2224 | } | 
|  | 2225 | } | 
|  | 2226 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2227 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultParentless_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2228 | sp<SurfaceControl> layer; | 
|  | 2229 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2230 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2231 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 10, 10)); | 
|  | 2232 |  | 
|  | 2233 | // 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] | 2234 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2235 | shot->expectColor(Rect(0, 0, 10, 10), Color::RED); | 
|  | 2236 | shot->expectBorder(Rect(0, 0, 10, 10), Color::BLACK); | 
|  | 2237 | } | 
|  | 2238 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2239 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultBSParent_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2240 | sp<SurfaceControl> parent, child; | 
|  | 2241 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2242 | parent = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2243 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(parent, Color::RED, 32, 32)); | 
|  | 2244 | Transaction().setFrame(parent, Rect(0, 0, 32, 32)).apply(); | 
|  | 2245 |  | 
|  | 2246 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2247 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2248 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); | 
|  | 2249 |  | 
|  | 2250 | Transaction().reparent(child, parent->getHandle()).apply(); | 
|  | 2251 |  | 
|  | 2252 | // A layer will default to the frame of its parent | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2253 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2254 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 2255 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2256 | } | 
|  | 2257 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2258 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultBQParent_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2259 | sp<SurfaceControl> parent, child; | 
|  | 2260 | ASSERT_NO_FATAL_FAILURE(parent = createLayer("test", 32, 32)); | 
|  | 2261 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(parent, Color::RED, 32, 32)); | 
|  | 2262 |  | 
|  | 2263 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2264 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2265 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); | 
|  | 2266 |  | 
|  | 2267 | Transaction().reparent(child, parent->getHandle()).apply(); | 
|  | 2268 |  | 
|  | 2269 | // A layer will default to the frame of its parent | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2270 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2271 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 2272 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2273 | } | 
|  | 2274 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2275 | TEST_P(LayerRenderTypeTransactionTest, SetFrameUpdate_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2276 | sp<SurfaceControl> layer; | 
|  | 2277 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2278 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2279 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2280 | Transaction().setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
|  | 2281 |  | 
|  | 2282 | std::this_thread::sleep_for(500ms); | 
|  | 2283 |  | 
|  | 2284 | Transaction().setFrame(layer, Rect(16, 16, 48, 48)).apply(); | 
|  | 2285 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2286 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2287 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); | 
|  | 2288 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); | 
|  | 2289 | } | 
|  | 2290 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2291 | TEST_P(LayerRenderTypeTransactionTest, SetFrameOutsideBounds_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2292 | sp<SurfaceControl> parent, child; | 
|  | 2293 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2294 | parent = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2295 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2296 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2297 | Transaction().reparent(child, parent->getHandle()).apply(); | 
|  | 2298 |  | 
|  | 2299 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(parent, Color::RED, 32, 32)); | 
|  | 2300 | Transaction().setFrame(parent, Rect(0, 0, 32, 32)).apply(); | 
|  | 2301 |  | 
|  | 2302 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); | 
|  | 2303 | Transaction().setFrame(child, Rect(0, 16, 32, 32)).apply(); | 
|  | 2304 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2305 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2306 | shot->expectColor(Rect(0, 0, 32, 16), Color::RED); | 
|  | 2307 | shot->expectColor(Rect(0, 16, 32, 32), Color::BLUE); | 
|  | 2308 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2309 | } | 
|  | 2310 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2311 | TEST_P(LayerRenderTypeTransactionTest, SetBufferBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2312 | sp<SurfaceControl> layer; | 
|  | 2313 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2314 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2315 |  | 
|  | 2316 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2317 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2318 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2319 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2320 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2321 | } | 
|  | 2322 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2323 | TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleBuffers_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2324 | sp<SurfaceControl> layer; | 
|  | 2325 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2326 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2327 |  | 
|  | 2328 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2329 |  | 
|  | 2330 | { | 
|  | 2331 | SCOPED_TRACE("set buffer 1"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2332 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2333 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2334 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2335 | } | 
|  | 2336 |  | 
|  | 2337 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::BLUE, 32, 32)); | 
|  | 2338 |  | 
|  | 2339 | { | 
|  | 2340 | SCOPED_TRACE("set buffer 2"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2341 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2342 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 2343 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2344 | } | 
|  | 2345 |  | 
|  | 2346 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2347 |  | 
|  | 2348 | { | 
|  | 2349 | SCOPED_TRACE("set buffer 3"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2350 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2351 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2352 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2353 | } | 
|  | 2354 | } | 
|  | 2355 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2356 | TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleLayers_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2357 | sp<SurfaceControl> layer1; | 
|  | 2358 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2359 | layer1 = createLayer("test", 64, 64, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2360 |  | 
|  | 2361 | sp<SurfaceControl> layer2; | 
|  | 2362 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2363 | layer2 = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2364 |  | 
|  | 2365 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::RED, 64, 64)); | 
|  | 2366 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2367 | Transaction().setFrame(layer1, Rect(0, 0, 64, 64)).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2368 | { | 
|  | 2369 | SCOPED_TRACE("set layer 1 buffer red"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2370 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2371 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); | 
|  | 2372 | } | 
|  | 2373 |  | 
|  | 2374 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::BLUE, 32, 32)); | 
|  | 2375 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2376 | Transaction().setFrame(layer2, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2377 | { | 
|  | 2378 | SCOPED_TRACE("set layer 2 buffer blue"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2379 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2380 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 2381 | shot->expectColor(Rect(0, 32, 64, 64), Color::RED); | 
|  | 2382 | shot->expectColor(Rect(0, 32, 32, 64), Color::RED); | 
|  | 2383 | } | 
|  | 2384 |  | 
|  | 2385 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::GREEN, 64, 64)); | 
|  | 2386 | { | 
|  | 2387 | SCOPED_TRACE("set layer 1 buffer green"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2388 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2389 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 2390 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); | 
|  | 2391 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); | 
|  | 2392 | } | 
|  | 2393 |  | 
|  | 2394 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::WHITE, 32, 32)); | 
|  | 2395 |  | 
|  | 2396 | { | 
|  | 2397 | SCOPED_TRACE("set layer 2 buffer white"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2398 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2399 | shot->expectColor(Rect(0, 0, 32, 32), Color::WHITE); | 
|  | 2400 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); | 
|  | 2401 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); | 
|  | 2402 | } | 
|  | 2403 | } | 
|  | 2404 |  | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 2405 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_BufferState) { | 
| Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2406 | sp<SurfaceControl> layer; | 
|  | 2407 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2408 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2409 |  | 
|  | 2410 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; | 
|  | 2411 |  | 
|  | 2412 | std::array<sp<GraphicBuffer>, 10> buffers; | 
|  | 2413 |  | 
|  | 2414 | size_t idx = 0; | 
|  | 2415 | for (auto& buffer : buffers) { | 
|  | 2416 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2417 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2418 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2419 | "test"); | 
|  | 2420 | Color color = colors[idx % colors.size()]; | 
|  | 2421 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); | 
|  | 2422 | idx++; | 
|  | 2423 | } | 
|  | 2424 |  | 
|  | 2425 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the | 
|  | 2426 | // cache is working. | 
|  | 2427 | idx = 0; | 
|  | 2428 | for (auto& buffer : buffers) { | 
|  | 2429 | for (int i = 0; i < 2; i++) { | 
|  | 2430 | Transaction().setBuffer(layer, buffer).apply(); | 
|  | 2431 |  | 
|  | 2432 | Color color = colors[idx % colors.size()]; | 
|  | 2433 | auto shot = screenshot(); | 
|  | 2434 | shot->expectColor(Rect(0, 0, 32, 32), color); | 
|  | 2435 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2436 | } | 
|  | 2437 | idx++; | 
|  | 2438 | } | 
|  | 2439 | } | 
|  | 2440 |  | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 2441 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_LeastRecentlyUsed_BufferState) { | 
| Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2442 | sp<SurfaceControl> layer; | 
|  | 2443 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2444 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2445 |  | 
|  | 2446 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; | 
|  | 2447 |  | 
|  | 2448 | std::array<sp<GraphicBuffer>, 70> buffers; | 
|  | 2449 |  | 
|  | 2450 | size_t idx = 0; | 
|  | 2451 | for (auto& buffer : buffers) { | 
|  | 2452 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2453 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2454 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2455 | "test"); | 
|  | 2456 | Color color = colors[idx % colors.size()]; | 
|  | 2457 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); | 
|  | 2458 | idx++; | 
|  | 2459 | } | 
|  | 2460 |  | 
|  | 2461 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the | 
|  | 2462 | // cache is working. | 
|  | 2463 | idx = 0; | 
|  | 2464 | for (auto& buffer : buffers) { | 
|  | 2465 | for (int i = 0; i < 2; i++) { | 
|  | 2466 | Transaction().setBuffer(layer, buffer).apply(); | 
|  | 2467 |  | 
|  | 2468 | Color color = colors[idx % colors.size()]; | 
|  | 2469 | auto shot = screenshot(); | 
|  | 2470 | shot->expectColor(Rect(0, 0, 32, 32), color); | 
|  | 2471 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2472 | } | 
|  | 2473 | idx++; | 
|  | 2474 | } | 
|  | 2475 | } | 
|  | 2476 |  | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 2477 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_DestroyedBuffer_BufferState) { | 
| Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2478 | sp<SurfaceControl> layer; | 
|  | 2479 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2480 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2481 |  | 
|  | 2482 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; | 
|  | 2483 |  | 
|  | 2484 | std::array<sp<GraphicBuffer>, 65> buffers; | 
|  | 2485 |  | 
|  | 2486 | size_t idx = 0; | 
|  | 2487 | for (auto& buffer : buffers) { | 
|  | 2488 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2489 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2490 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2491 | "test"); | 
|  | 2492 | Color color = colors[idx % colors.size()]; | 
|  | 2493 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); | 
|  | 2494 | idx++; | 
|  | 2495 | } | 
|  | 2496 |  | 
|  | 2497 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the | 
|  | 2498 | // cache is working. | 
|  | 2499 | idx = 0; | 
|  | 2500 | for (auto& buffer : buffers) { | 
|  | 2501 | for (int i = 0; i < 2; i++) { | 
|  | 2502 | Transaction().setBuffer(layer, buffer).apply(); | 
|  | 2503 |  | 
|  | 2504 | Color color = colors[idx % colors.size()]; | 
|  | 2505 | auto shot = screenshot(); | 
|  | 2506 | shot->expectColor(Rect(0, 0, 32, 32), color); | 
|  | 2507 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2508 | } | 
|  | 2509 | if (idx == 0) { | 
|  | 2510 | buffers[0].clear(); | 
|  | 2511 | } | 
|  | 2512 | idx++; | 
|  | 2513 | } | 
|  | 2514 | } | 
|  | 2515 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2516 | TEST_P(LayerRenderTypeTransactionTest, SetTransformRotate90_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2517 | sp<SurfaceControl> layer; | 
|  | 2518 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2519 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2520 |  | 
|  | 2521 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 2522 | Color::BLUE, Color::WHITE)); | 
|  | 2523 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2524 | Transaction() | 
|  | 2525 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
|  | 2526 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_ROT_90) | 
|  | 2527 | .apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2528 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2529 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE, | 
|  | 2530 | Color::GREEN, true /* filtered */); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2531 | } | 
|  | 2532 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2533 | TEST_P(LayerRenderTypeTransactionTest, SetTransformFlipH_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2534 | sp<SurfaceControl> layer; | 
|  | 2535 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2536 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2537 |  | 
|  | 2538 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 2539 | Color::BLUE, Color::WHITE)); | 
|  | 2540 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2541 | Transaction() | 
|  | 2542 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
|  | 2543 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_H) | 
|  | 2544 | .apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2545 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2546 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE, | 
|  | 2547 | Color::BLUE, true /* filtered */); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2548 | } | 
|  | 2549 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2550 | TEST_P(LayerRenderTypeTransactionTest, SetTransformFlipV_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2551 | sp<SurfaceControl> layer; | 
|  | 2552 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2553 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2554 |  | 
|  | 2555 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 2556 | Color::BLUE, Color::WHITE)); | 
|  | 2557 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2558 | Transaction() | 
|  | 2559 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
|  | 2560 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_V) | 
|  | 2561 | .apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2562 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2563 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED, | 
|  | 2564 | Color::GREEN, true /* filtered */); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2565 | } | 
|  | 2566 |  | 
|  | 2567 | TEST_F(LayerTransactionTest, SetTransformToDisplayInverse_BufferState) { | 
|  | 2568 | sp<SurfaceControl> layer; | 
|  | 2569 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2570 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2571 |  | 
|  | 2572 | Transaction().setTransformToDisplayInverse(layer, false).apply(); | 
|  | 2573 |  | 
|  | 2574 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::GREEN, 32, 32)); | 
|  | 2575 |  | 
|  | 2576 | Transaction().setTransformToDisplayInverse(layer, true).apply(); | 
|  | 2577 | } | 
|  | 2578 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2579 | TEST_P(LayerRenderTypeTransactionTest, SetFenceBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2580 | sp<SurfaceControl> layer; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2581 | Transaction transaction; | 
|  | 2582 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2583 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2584 |  | 
|  | 2585 | sp<GraphicBuffer> buffer = | 
|  | 2586 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2587 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2588 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2589 | "test"); | 
|  | 2590 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2591 |  | 
|  | 2592 | sp<Fence> fence; | 
|  | 2593 | if (getBuffer(nullptr, &fence) != NO_ERROR) { | 
|  | 2594 | GTEST_SUCCEED() << "test not supported"; | 
|  | 2595 | return; | 
|  | 2596 | } | 
|  | 2597 |  | 
|  | 2598 | Transaction().setBuffer(layer, buffer).setAcquireFence(layer, fence).apply(); | 
|  | 2599 |  | 
|  | 2600 | status_t status = fence->wait(1000); | 
|  | 2601 | ASSERT_NE(static_cast<status_t>(Fence::Status::Unsignaled), status); | 
|  | 2602 | std::this_thread::sleep_for(200ms); | 
|  | 2603 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2604 | auto shot = getScreenCapture(); | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2605 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2606 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2607 | } | 
|  | 2608 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2609 | TEST_P(LayerRenderTypeTransactionTest, SetFenceNull_BufferState) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2610 | sp<SurfaceControl> layer; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2611 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2612 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2613 |  | 
|  | 2614 | sp<GraphicBuffer> buffer = | 
|  | 2615 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2616 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2617 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2618 | "test"); | 
|  | 2619 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2620 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2621 | sp<Fence> fence = Fence::NO_FENCE; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2622 |  | 
|  | 2623 | Transaction() | 
|  | 2624 | .setBuffer(layer, buffer) | 
|  | 2625 | .setAcquireFence(layer, fence) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2626 | .apply(); | 
|  | 2627 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2628 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2629 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2630 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2631 | } | 
|  | 2632 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2633 | TEST_P(LayerRenderTypeTransactionTest, SetDataspaceBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2634 | sp<SurfaceControl> layer; | 
|  | 2635 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2636 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2637 |  | 
|  | 2638 | sp<GraphicBuffer> buffer = | 
|  | 2639 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2640 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2641 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2642 | "test"); | 
|  | 2643 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2644 |  | 
|  | 2645 | Transaction() | 
|  | 2646 | .setBuffer(layer, buffer) | 
|  | 2647 | .setDataspace(layer, ui::Dataspace::UNKNOWN) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2648 | .apply(); | 
|  | 2649 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2650 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2651 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2652 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2653 | } | 
|  | 2654 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2655 | TEST_P(LayerRenderTypeTransactionTest, SetHdrMetadataBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2656 | sp<SurfaceControl> layer; | 
|  | 2657 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2658 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2659 |  | 
|  | 2660 | sp<GraphicBuffer> buffer = | 
|  | 2661 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2662 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2663 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2664 | "test"); | 
|  | 2665 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2666 |  | 
|  | 2667 | HdrMetadata hdrMetadata; | 
|  | 2668 | hdrMetadata.validTypes = 0; | 
|  | 2669 | Transaction() | 
|  | 2670 | .setBuffer(layer, buffer) | 
|  | 2671 | .setHdrMetadata(layer, hdrMetadata) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2672 | .apply(); | 
|  | 2673 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2674 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2675 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2676 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2677 | } | 
|  | 2678 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2679 | TEST_P(LayerRenderTypeTransactionTest, SetSurfaceDamageRegionBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2680 | sp<SurfaceControl> layer; | 
|  | 2681 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2682 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2683 |  | 
|  | 2684 | sp<GraphicBuffer> buffer = | 
|  | 2685 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2686 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2687 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2688 | "test"); | 
|  | 2689 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2690 |  | 
|  | 2691 | Region region; | 
|  | 2692 | region.set(32, 32); | 
|  | 2693 | Transaction() | 
|  | 2694 | .setBuffer(layer, buffer) | 
|  | 2695 | .setSurfaceDamageRegion(layer, region) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2696 | .apply(); | 
|  | 2697 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2698 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2699 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2700 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2701 | } | 
|  | 2702 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2703 | TEST_P(LayerRenderTypeTransactionTest, SetApiBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2704 | sp<SurfaceControl> layer; | 
|  | 2705 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2706 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2707 |  | 
|  | 2708 | sp<GraphicBuffer> buffer = | 
|  | 2709 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2710 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2711 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2712 | "test"); | 
|  | 2713 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2714 |  | 
|  | 2715 | Transaction() | 
|  | 2716 | .setBuffer(layer, buffer) | 
|  | 2717 | .setApi(layer, NATIVE_WINDOW_API_CPU) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2718 | .apply(); | 
|  | 2719 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2720 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2721 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2722 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2723 | } | 
|  | 2724 |  | 
|  | 2725 | TEST_F(LayerTransactionTest, SetSidebandStreamNull_BufferState) { | 
|  | 2726 | sp<SurfaceControl> layer; | 
|  | 2727 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2728 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2729 |  | 
|  | 2730 | // verify this doesn't cause a crash | 
|  | 2731 | Transaction().setSidebandStream(layer, nullptr).apply(); | 
|  | 2732 | } | 
|  | 2733 |  | 
| Robert Carr | 54cf5b1 | 2019-01-25 14:02:28 -0800 | [diff] [blame] | 2734 | TEST_F(LayerTransactionTest, ReparentToSelf) { | 
|  | 2735 | sp<SurfaceControl> layer; | 
|  | 2736 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 2737 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2738 | Transaction().reparent(layer, layer->getHandle()).apply(); | 
|  | 2739 |  | 
|  | 2740 | { | 
|  | 2741 | // We expect the transaction to be silently dropped, but for SurfaceFlinger | 
|  | 2742 | // to still be functioning. | 
|  | 2743 | SCOPED_TRACE("after reparent to self"); | 
|  | 2744 | const Rect rect(0, 0, 32, 32); | 
|  | 2745 | auto shot = screenshot(); | 
|  | 2746 | shot->expectColor(rect, Color::RED); | 
|  | 2747 | shot->expectBorder(rect, Color::BLACK); | 
|  | 2748 | } | 
|  | 2749 | } | 
|  | 2750 |  | 
| Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2751 | class ColorTransformHelper { | 
|  | 2752 | public: | 
|  | 2753 | static void DegammaColorSingle(half& s) { | 
|  | 2754 | if (s <= 0.03928f) | 
|  | 2755 | s = s / 12.92f; | 
|  | 2756 | else | 
|  | 2757 | s = pow((s + 0.055f) / 1.055f, 2.4f); | 
|  | 2758 | } | 
|  | 2759 |  | 
|  | 2760 | static void DegammaColor(half3& color) { | 
|  | 2761 | DegammaColorSingle(color.r); | 
|  | 2762 | DegammaColorSingle(color.g); | 
|  | 2763 | DegammaColorSingle(color.b); | 
|  | 2764 | } | 
|  | 2765 |  | 
|  | 2766 | static void GammaColorSingle(half& s) { | 
|  | 2767 | if (s <= 0.0031308f) { | 
|  | 2768 | s = s * 12.92f; | 
|  | 2769 | } else { | 
|  | 2770 | s = 1.055f * pow(s, (1.0f / 2.4f)) - 0.055f; | 
|  | 2771 | } | 
|  | 2772 | } | 
|  | 2773 |  | 
|  | 2774 | static void GammaColor(half3& color) { | 
|  | 2775 | GammaColorSingle(color.r); | 
|  | 2776 | GammaColorSingle(color.g); | 
|  | 2777 | GammaColorSingle(color.b); | 
|  | 2778 | } | 
|  | 2779 |  | 
|  | 2780 | static void applyMatrix(half3& color, const mat3& mat) { | 
|  | 2781 | half3 ret = half3(0); | 
|  | 2782 |  | 
|  | 2783 | for (int i = 0; i < 3; i++) { | 
|  | 2784 | for (int j = 0; j < 3; j++) { | 
|  | 2785 | ret[i] = ret[i] + color[j] * mat[j][i]; | 
|  | 2786 | } | 
|  | 2787 | } | 
|  | 2788 | color = ret; | 
|  | 2789 | } | 
|  | 2790 | }; | 
|  | 2791 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2792 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformBasic) { | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2793 | sp<SurfaceControl> colorLayer; | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 2794 | ASSERT_NO_FATAL_FAILURE(colorLayer = | 
|  | 2795 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 2796 | ISurfaceComposerClient::eFXSurfaceColor)); | 
|  | 2797 | Transaction() | 
|  | 2798 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 2799 | .setLayer(colorLayer, mLayerZBase + 1) | 
|  | 2800 | .apply(); | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2801 | { | 
|  | 2802 | SCOPED_TRACE("default color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2803 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2804 | } | 
|  | 2805 |  | 
|  | 2806 | 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] | 2807 | half3 expected = color; | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2808 | mat3 matrix; | 
|  | 2809 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; | 
|  | 2810 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; | 
|  | 2811 | 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] | 2812 |  | 
|  | 2813 | // degamma before applying the matrix | 
|  | 2814 | if (mColorManagementUsed) { | 
|  | 2815 | ColorTransformHelper::DegammaColor(expected); | 
|  | 2816 | } | 
|  | 2817 |  | 
|  | 2818 | ColorTransformHelper::applyMatrix(expected, matrix); | 
|  | 2819 |  | 
|  | 2820 | if (mColorManagementUsed) { | 
|  | 2821 | ColorTransformHelper::GammaColor(expected); | 
|  | 2822 | } | 
|  | 2823 |  | 
|  | 2824 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), | 
|  | 2825 | uint8_t(expected.b * 255), 255}; | 
|  | 2826 |  | 
|  | 2827 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 2828 | // channel) should be less than one | 
|  | 2829 | const uint8_t tolerance = 1; | 
|  | 2830 |  | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2831 | Transaction().setColor(colorLayer, color) | 
|  | 2832 | .setColorTransform(colorLayer, matrix, vec3()).apply(); | 
|  | 2833 | { | 
|  | 2834 | SCOPED_TRACE("new color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2835 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2836 | } | 
|  | 2837 | } | 
|  | 2838 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2839 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformOnParent) { | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2840 | sp<SurfaceControl> parentLayer; | 
|  | 2841 | sp<SurfaceControl> colorLayer; | 
|  | 2842 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parent", 0 /* buffer width */, | 
|  | 2843 | 0 /* buffer height */, | 
|  | 2844 | ISurfaceComposerClient::eFXSurfaceContainer)); | 
|  | 2845 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2846 | colorLayer = createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 2847 | ISurfaceComposerClient::eFXSurfaceColor, parentLayer.get())); | 
|  | 2848 |  | 
|  | 2849 | Transaction() | 
|  | 2850 | .setCrop_legacy(parentLayer, Rect(0, 0, 100, 100)) | 
|  | 2851 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 2852 | .setLayer(parentLayer, mLayerZBase + 1) | 
|  | 2853 | .apply(); | 
|  | 2854 | { | 
|  | 2855 | SCOPED_TRACE("default color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2856 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2857 | } | 
|  | 2858 |  | 
|  | 2859 | const half3 color(50.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f); | 
|  | 2860 | half3 expected = color; | 
|  | 2861 | mat3 matrix; | 
|  | 2862 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; | 
|  | 2863 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; | 
|  | 2864 | matrix[0][2] = 0.3; matrix[1][2] = 0.59; matrix[2][2] = 0.11; | 
|  | 2865 |  | 
|  | 2866 | // degamma before applying the matrix | 
|  | 2867 | if (mColorManagementUsed) { | 
|  | 2868 | ColorTransformHelper::DegammaColor(expected); | 
|  | 2869 | } | 
|  | 2870 |  | 
|  | 2871 | ColorTransformHelper::applyMatrix(expected, matrix); | 
|  | 2872 |  | 
|  | 2873 | if (mColorManagementUsed) { | 
|  | 2874 | ColorTransformHelper::GammaColor(expected); | 
|  | 2875 | } | 
|  | 2876 |  | 
|  | 2877 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), | 
|  | 2878 | uint8_t(expected.b * 255), 255}; | 
|  | 2879 |  | 
|  | 2880 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 2881 | // channel) should be less than one | 
|  | 2882 | const uint8_t tolerance = 1; | 
|  | 2883 |  | 
|  | 2884 | Transaction() | 
|  | 2885 | .setColor(colorLayer, color) | 
|  | 2886 | .setColorTransform(parentLayer, matrix, vec3()) | 
|  | 2887 | .apply(); | 
|  | 2888 | { | 
|  | 2889 | SCOPED_TRACE("new color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2890 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2891 | } | 
|  | 2892 | } | 
|  | 2893 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2894 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformOnChildAndParent) { | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2895 | sp<SurfaceControl> parentLayer; | 
|  | 2896 | sp<SurfaceControl> colorLayer; | 
|  | 2897 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parent", 0 /* buffer width */, | 
|  | 2898 | 0 /* buffer height */, | 
|  | 2899 | ISurfaceComposerClient::eFXSurfaceContainer)); | 
|  | 2900 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2901 | colorLayer = createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 2902 | ISurfaceComposerClient::eFXSurfaceColor, parentLayer.get())); | 
|  | 2903 |  | 
|  | 2904 | Transaction() | 
|  | 2905 | .setCrop_legacy(parentLayer, Rect(0, 0, 100, 100)) | 
|  | 2906 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 2907 | .setLayer(parentLayer, mLayerZBase + 1) | 
|  | 2908 | .apply(); | 
|  | 2909 | { | 
|  | 2910 | SCOPED_TRACE("default color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2911 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 2912 | } | 
|  | 2913 |  | 
|  | 2914 | const half3 color(50.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f); | 
|  | 2915 | half3 expected = color; | 
|  | 2916 | mat3 matrixChild; | 
|  | 2917 | matrixChild[0][0] = 0.3; matrixChild[1][0] = 0.59; matrixChild[2][0] = 0.11; | 
|  | 2918 | matrixChild[0][1] = 0.3; matrixChild[1][1] = 0.59; matrixChild[2][1] = 0.11; | 
|  | 2919 | matrixChild[0][2] = 0.3; matrixChild[1][2] = 0.59; matrixChild[2][2] = 0.11; | 
|  | 2920 | mat3 matrixParent; | 
|  | 2921 | matrixParent[0][0] = 0.2; matrixParent[1][0] = 0.4; matrixParent[2][0] = 0.10; | 
|  | 2922 | matrixParent[0][1] = 0.2; matrixParent[1][1] = 0.4; matrixParent[2][1] = 0.10; | 
|  | 2923 | matrixParent[0][2] = 0.2; matrixParent[1][2] = 0.4; matrixParent[2][2] = 0.10; | 
|  | 2924 |  | 
|  | 2925 | // degamma before applying the matrix | 
|  | 2926 | if (mColorManagementUsed) { | 
|  | 2927 | ColorTransformHelper::DegammaColor(expected); | 
|  | 2928 | } | 
|  | 2929 |  | 
|  | 2930 | ColorTransformHelper::applyMatrix(expected, matrixChild); | 
|  | 2931 | ColorTransformHelper::applyMatrix(expected, matrixParent); | 
|  | 2932 |  | 
|  | 2933 | if (mColorManagementUsed) { | 
|  | 2934 | ColorTransformHelper::GammaColor(expected); | 
|  | 2935 | } | 
|  | 2936 |  | 
|  | 2937 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), | 
|  | 2938 | uint8_t(expected.b * 255), 255}; | 
|  | 2939 |  | 
|  | 2940 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 2941 | // channel) should be less than one | 
|  | 2942 | const uint8_t tolerance = 1; | 
|  | 2943 |  | 
|  | 2944 | Transaction() | 
|  | 2945 | .setColor(colorLayer, color) | 
|  | 2946 | .setColorTransform(parentLayer, matrixParent, vec3()) | 
|  | 2947 | .setColorTransform(colorLayer, matrixChild, 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 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 2955 | struct CallbackData { | 
|  | 2956 | CallbackData() = default; | 
|  | 2957 | CallbackData(nsecs_t time, const sp<Fence>& fence, | 
|  | 2958 | const std::vector<SurfaceControlStats>& stats) | 
|  | 2959 | : latchTime(time), presentFence(fence), surfaceControlStats(stats) {} | 
|  | 2960 |  | 
|  | 2961 | nsecs_t latchTime; | 
|  | 2962 | sp<Fence> presentFence; | 
|  | 2963 | std::vector<SurfaceControlStats> surfaceControlStats; | 
|  | 2964 | }; | 
|  | 2965 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2966 | class ExpectedResult { | 
|  | 2967 | public: | 
|  | 2968 | enum Transaction { | 
|  | 2969 | NOT_PRESENTED = 0, | 
|  | 2970 | PRESENTED, | 
|  | 2971 | }; | 
|  | 2972 |  | 
|  | 2973 | enum Buffer { | 
|  | 2974 | NOT_ACQUIRED = 0, | 
|  | 2975 | ACQUIRED, | 
|  | 2976 | }; | 
|  | 2977 |  | 
|  | 2978 | enum PreviousBuffer { | 
|  | 2979 | NOT_RELEASED = 0, | 
|  | 2980 | RELEASED, | 
| Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 2981 | UNKNOWN, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2982 | }; | 
|  | 2983 |  | 
|  | 2984 | void reset() { | 
|  | 2985 | mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; | 
|  | 2986 | mExpectedSurfaceResults.clear(); | 
|  | 2987 | } | 
|  | 2988 |  | 
|  | 2989 | void addSurface(ExpectedResult::Transaction transactionResult, const sp<SurfaceControl>& layer, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2990 | ExpectedResult::Buffer bufferResult = ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2991 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { | 
|  | 2992 | mTransactionResult = transactionResult; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 2993 | mExpectedSurfaceResults.emplace(std::piecewise_construct, std::forward_as_tuple(layer), | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2994 | std::forward_as_tuple(bufferResult, previousBufferResult)); | 
|  | 2995 | } | 
|  | 2996 |  | 
|  | 2997 | void addSurfaces(ExpectedResult::Transaction transactionResult, | 
|  | 2998 | const std::vector<sp<SurfaceControl>>& layers, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2999 | ExpectedResult::Buffer bufferResult = ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3000 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { | 
|  | 3001 | for (const auto& layer : layers) { | 
|  | 3002 | addSurface(transactionResult, layer, bufferResult, previousBufferResult); | 
|  | 3003 | } | 
|  | 3004 | } | 
|  | 3005 |  | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3006 | void addExpectedPresentTime(nsecs_t expectedPresentTime) { | 
|  | 3007 | mExpectedPresentTime = expectedPresentTime; | 
|  | 3008 | } | 
|  | 3009 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3010 | void verifyCallbackData(const CallbackData& callbackData) const { | 
|  | 3011 | const auto& [latchTime, presentFence, surfaceControlStats] = callbackData; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3012 | if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) { | 
|  | 3013 | ASSERT_GE(latchTime, 0) << "bad latch time"; | 
| Valerie Hau | 63258a1 | 2018-12-14 14:31:48 -0800 | [diff] [blame] | 3014 | ASSERT_NE(presentFence, nullptr); | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3015 | if (mExpectedPresentTime >= 0) { | 
|  | 3016 | ASSERT_EQ(presentFence->wait(3000), NO_ERROR); | 
|  | 3017 | ASSERT_GE(presentFence->getSignalTime(), mExpectedPresentTime - nsecs_t(5 * 1e6)); | 
|  | 3018 | // if the panel is running at 30 hz, at the worst case, our expected time just | 
|  | 3019 | // misses vsync and we have to wait another 33.3ms | 
|  | 3020 | ASSERT_LE(presentFence->getSignalTime(), | 
|  | 3021 | mExpectedPresentTime + nsecs_t(66.666666 * 1e6)); | 
|  | 3022 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3023 | } else { | 
| Valerie Hau | 63258a1 | 2018-12-14 14:31:48 -0800 | [diff] [blame] | 3024 | ASSERT_EQ(presentFence, nullptr) << "transaction shouldn't have been presented"; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3025 | ASSERT_EQ(latchTime, -1) << "unpresented transactions shouldn't be latched"; | 
|  | 3026 | } | 
|  | 3027 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3028 | ASSERT_EQ(surfaceControlStats.size(), mExpectedSurfaceResults.size()) | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3029 | << "wrong number of surfaces"; | 
|  | 3030 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3031 | for (const auto& stats : surfaceControlStats) { | 
|  | 3032 | ASSERT_NE(stats.surfaceControl, nullptr) << "returned null surface control"; | 
|  | 3033 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3034 | const auto& expectedSurfaceResult = mExpectedSurfaceResults.find(stats.surfaceControl); | 
|  | 3035 | ASSERT_NE(expectedSurfaceResult, mExpectedSurfaceResults.end()) | 
|  | 3036 | << "unexpected surface control"; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3037 | expectedSurfaceResult->second.verifySurfaceControlStats(stats, latchTime); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3038 | } | 
|  | 3039 | } | 
|  | 3040 |  | 
|  | 3041 | private: | 
|  | 3042 | class ExpectedSurfaceResult { | 
|  | 3043 | public: | 
|  | 3044 | ExpectedSurfaceResult(ExpectedResult::Buffer bufferResult, | 
|  | 3045 | ExpectedResult::PreviousBuffer previousBufferResult) | 
|  | 3046 | : mBufferResult(bufferResult), mPreviousBufferResult(previousBufferResult) {} | 
|  | 3047 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3048 | void verifySurfaceControlStats(const SurfaceControlStats& surfaceControlStats, | 
|  | 3049 | nsecs_t latchTime) const { | 
|  | 3050 | const auto& [surfaceControl, acquireTime, previousReleaseFence] = surfaceControlStats; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3051 |  | 
|  | 3052 | ASSERT_EQ(acquireTime > 0, mBufferResult == ExpectedResult::Buffer::ACQUIRED) | 
|  | 3053 | << "bad acquire time"; | 
|  | 3054 | ASSERT_LE(acquireTime, latchTime) << "acquire time should be <= latch time"; | 
| Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3055 |  | 
|  | 3056 | if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::RELEASED) { | 
|  | 3057 | ASSERT_NE(previousReleaseFence, nullptr) | 
|  | 3058 | << "failed to set release prev buffer fence"; | 
|  | 3059 | } else if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::NOT_RELEASED) { | 
|  | 3060 | ASSERT_EQ(previousReleaseFence, nullptr) | 
|  | 3061 | << "should not have set released prev buffer fence"; | 
|  | 3062 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3063 | } | 
|  | 3064 |  | 
|  | 3065 | private: | 
|  | 3066 | ExpectedResult::Buffer mBufferResult; | 
|  | 3067 | ExpectedResult::PreviousBuffer mPreviousBufferResult; | 
|  | 3068 | }; | 
|  | 3069 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3070 | struct SCHash { | 
|  | 3071 | std::size_t operator()(const sp<SurfaceControl>& sc) const { | 
|  | 3072 | return std::hash<IBinder*>{}(sc->getHandle().get()); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3073 | } | 
|  | 3074 | }; | 
|  | 3075 | ExpectedResult::Transaction mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3076 | nsecs_t mExpectedPresentTime = -1; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3077 | std::unordered_map<sp<SurfaceControl>, ExpectedSurfaceResult, SCHash> mExpectedSurfaceResults; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3078 | }; | 
|  | 3079 |  | 
|  | 3080 | class CallbackHelper { | 
|  | 3081 | public: | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3082 | static void function(void* callbackContext, nsecs_t latchTime, const sp<Fence>& presentFence, | 
|  | 3083 | const std::vector<SurfaceControlStats>& stats) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3084 | if (!callbackContext) { | 
|  | 3085 | ALOGE("failed to get callback context"); | 
|  | 3086 | } | 
|  | 3087 | CallbackHelper* helper = static_cast<CallbackHelper*>(callbackContext); | 
|  | 3088 | std::lock_guard lock(helper->mMutex); | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3089 | helper->mCallbackDataQueue.emplace(latchTime, presentFence, stats); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3090 | helper->mConditionVariable.notify_all(); | 
|  | 3091 | } | 
|  | 3092 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3093 | void getCallbackData(CallbackData* outData) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3094 | std::unique_lock lock(mMutex); | 
|  | 3095 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3096 | if (mCallbackDataQueue.empty()) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3097 | ASSERT_NE(mConditionVariable.wait_for(lock, std::chrono::seconds(3)), | 
|  | 3098 | std::cv_status::timeout) | 
|  | 3099 | << "did not receive callback"; | 
|  | 3100 | } | 
|  | 3101 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3102 | *outData = std::move(mCallbackDataQueue.front()); | 
|  | 3103 | mCallbackDataQueue.pop(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3104 | } | 
|  | 3105 |  | 
|  | 3106 | void verifyFinalState() { | 
|  | 3107 | // Wait to see if there are extra callbacks | 
|  | 3108 | std::this_thread::sleep_for(500ms); | 
|  | 3109 |  | 
|  | 3110 | std::lock_guard lock(mMutex); | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3111 | EXPECT_EQ(mCallbackDataQueue.size(), 0) << "extra callbacks received"; | 
|  | 3112 | mCallbackDataQueue = {}; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3113 | } | 
|  | 3114 |  | 
|  | 3115 | void* getContext() { return static_cast<void*>(this); } | 
|  | 3116 |  | 
|  | 3117 | std::mutex mMutex; | 
|  | 3118 | std::condition_variable mConditionVariable; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3119 | std::queue<CallbackData> mCallbackDataQueue; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3120 | }; | 
|  | 3121 |  | 
|  | 3122 | class LayerCallbackTest : public LayerTransactionTest { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3123 | public: | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3124 | virtual sp<SurfaceControl> createBufferStateLayer() { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3125 | return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3126 | } | 
|  | 3127 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3128 | static int fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, | 
|  | 3129 | const sp<SurfaceControl>& layer = nullptr) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3130 | if (layer) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3131 | sp<GraphicBuffer> buffer; | 
|  | 3132 | sp<Fence> fence; | 
|  | 3133 | int err = getBuffer(&buffer, &fence); | 
|  | 3134 | if (err != NO_ERROR) { | 
|  | 3135 | return err; | 
|  | 3136 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3137 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3138 | transaction.setBuffer(layer, buffer).setAcquireFence(layer, fence); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3139 | } | 
|  | 3140 |  | 
|  | 3141 | transaction.addTransactionCompletedCallback(callbackHelper->function, | 
|  | 3142 | callbackHelper->getContext()); | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3143 | return NO_ERROR; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3144 | } | 
|  | 3145 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3146 | static void waitForCallback(CallbackHelper& helper, const ExpectedResult& expectedResult, | 
|  | 3147 | bool finalState = false) { | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3148 | CallbackData callbackData; | 
|  | 3149 | ASSERT_NO_FATAL_FAILURE(helper.getCallbackData(&callbackData)); | 
|  | 3150 | EXPECT_NO_FATAL_FAILURE(expectedResult.verifyCallbackData(callbackData)); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3151 |  | 
|  | 3152 | if (finalState) { | 
|  | 3153 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); | 
|  | 3154 | } | 
|  | 3155 | } | 
|  | 3156 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3157 | static void waitForCallbacks(CallbackHelper& helper, | 
|  | 3158 | const std::vector<ExpectedResult>& expectedResults, | 
|  | 3159 | bool finalState = false) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3160 | for (const auto& expectedResult : expectedResults) { | 
|  | 3161 | waitForCallback(helper, expectedResult); | 
|  | 3162 | } | 
|  | 3163 | if (finalState) { | 
|  | 3164 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); | 
|  | 3165 | } | 
|  | 3166 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3167 | }; | 
|  | 3168 |  | 
|  | 3169 | TEST_F(LayerCallbackTest, Basic) { | 
|  | 3170 | sp<SurfaceControl> layer; | 
|  | 3171 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3172 |  | 
|  | 3173 | Transaction transaction; | 
|  | 3174 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3175 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3176 | if (err) { | 
|  | 3177 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3178 | return; | 
|  | 3179 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3180 |  | 
|  | 3181 | transaction.apply(); | 
|  | 3182 |  | 
|  | 3183 | ExpectedResult expected; | 
|  | 3184 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3185 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3186 | } | 
|  | 3187 |  | 
|  | 3188 | TEST_F(LayerCallbackTest, NoBuffer) { | 
|  | 3189 | sp<SurfaceControl> layer; | 
|  | 3190 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3191 |  | 
|  | 3192 | Transaction transaction; | 
|  | 3193 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3194 | int err = fillTransaction(transaction, &callback); | 
|  | 3195 | if (err) { | 
|  | 3196 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3197 | return; | 
|  | 3198 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3199 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3200 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3201 |  | 
|  | 3202 | ExpectedResult expected; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3203 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, | 
|  | 3204 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3205 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3206 | } | 
|  | 3207 |  | 
|  | 3208 | TEST_F(LayerCallbackTest, NoStateChange) { | 
|  | 3209 | Transaction transaction; | 
|  | 3210 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3211 | int err = fillTransaction(transaction, &callback); | 
|  | 3212 | if (err) { | 
|  | 3213 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3214 | return; | 
|  | 3215 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3216 |  | 
|  | 3217 | transaction.apply(); | 
|  | 3218 |  | 
|  | 3219 | ExpectedResult expected; | 
|  | 3220 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3221 | } | 
|  | 3222 |  | 
|  | 3223 | TEST_F(LayerCallbackTest, OffScreen) { | 
|  | 3224 | sp<SurfaceControl> layer; | 
|  | 3225 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3226 |  | 
|  | 3227 | Transaction transaction; | 
|  | 3228 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3229 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3230 | if (err) { | 
|  | 3231 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3232 | return; | 
|  | 3233 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3234 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3235 | transaction.setFrame(layer, Rect(-100, -100, 100, 100)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3236 |  | 
|  | 3237 | ExpectedResult expected; | 
|  | 3238 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3239 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3240 | } | 
|  | 3241 |  | 
|  | 3242 | TEST_F(LayerCallbackTest, Merge) { | 
|  | 3243 | sp<SurfaceControl> layer1, layer2; | 
|  | 3244 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 3245 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 3246 |  | 
|  | 3247 | Transaction transaction1, transaction2; | 
|  | 3248 | CallbackHelper callback1, callback2; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3249 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3250 | if (err) { | 
|  | 3251 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3252 | return; | 
|  | 3253 | } | 
|  | 3254 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3255 | if (err) { | 
|  | 3256 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3257 | return; | 
|  | 3258 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3259 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3260 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3261 | 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] | 3262 |  | 
|  | 3263 | ExpectedResult expected; | 
|  | 3264 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3265 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3266 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3267 | } | 
|  | 3268 |  | 
|  | 3269 | TEST_F(LayerCallbackTest, Merge_SameCallback) { | 
|  | 3270 | sp<SurfaceControl> layer1, layer2; | 
|  | 3271 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 3272 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 3273 |  | 
|  | 3274 | Transaction transaction1, transaction2; | 
|  | 3275 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3276 | int err = fillTransaction(transaction1, &callback, layer1); | 
|  | 3277 | if (err) { | 
|  | 3278 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3279 | return; | 
|  | 3280 | } | 
|  | 3281 | err = fillTransaction(transaction2, &callback, layer2); | 
|  | 3282 | if (err) { | 
|  | 3283 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3284 | return; | 
|  | 3285 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3286 |  | 
|  | 3287 | transaction2.merge(std::move(transaction1)).apply(); | 
|  | 3288 |  | 
|  | 3289 | ExpectedResult expected; | 
|  | 3290 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3291 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); | 
|  | 3292 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3293 | } | 
|  | 3294 |  | 
|  | 3295 | TEST_F(LayerCallbackTest, Merge_SameLayer) { | 
|  | 3296 | sp<SurfaceControl> layer; | 
|  | 3297 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3298 |  | 
|  | 3299 | Transaction transaction1, transaction2; | 
|  | 3300 | CallbackHelper callback1, callback2; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3301 | int err = fillTransaction(transaction1, &callback1, layer); | 
|  | 3302 | if (err) { | 
|  | 3303 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3304 | return; | 
|  | 3305 | } | 
|  | 3306 | err = fillTransaction(transaction2, &callback2, layer); | 
|  | 3307 | if (err) { | 
|  | 3308 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3309 | return; | 
|  | 3310 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3311 |  | 
|  | 3312 | transaction2.merge(std::move(transaction1)).apply(); | 
|  | 3313 |  | 
|  | 3314 | ExpectedResult expected; | 
|  | 3315 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3316 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3317 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3318 | } | 
|  | 3319 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3320 | TEST_F(LayerCallbackTest, Merge_DifferentClients) { | 
|  | 3321 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 3322 | client2(new SurfaceComposerClient); | 
|  | 3323 |  | 
|  | 3324 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3325 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3326 |  | 
|  | 3327 | sp<SurfaceControl> layer1, layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3328 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3329 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3330 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3331 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 3332 |  | 
|  | 3333 | Transaction transaction1, transaction2; | 
|  | 3334 | CallbackHelper callback1, callback2; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3335 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3336 | if (err) { | 
|  | 3337 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3338 | return; | 
|  | 3339 | } | 
|  | 3340 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3341 | if (err) { | 
|  | 3342 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3343 | return; | 
|  | 3344 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3345 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3346 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3347 | 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] | 3348 |  | 
|  | 3349 | ExpectedResult expected; | 
|  | 3350 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3351 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3352 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3353 | } | 
|  | 3354 |  | 
|  | 3355 | TEST_F(LayerCallbackTest, MultipleTransactions) { | 
|  | 3356 | sp<SurfaceControl> layer; | 
|  | 3357 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3358 |  | 
|  | 3359 | Transaction transaction; | 
|  | 3360 | CallbackHelper callback; | 
|  | 3361 | for (size_t i = 0; i < 10; i++) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3362 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3363 | if (err) { | 
|  | 3364 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3365 | return; | 
|  | 3366 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3367 |  | 
|  | 3368 | transaction.apply(); | 
|  | 3369 |  | 
|  | 3370 | ExpectedResult expected; | 
|  | 3371 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3372 | ExpectedResult::Buffer::ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3373 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED | 
|  | 3374 | : ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 3375 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); | 
|  | 3376 | } | 
|  | 3377 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); | 
|  | 3378 | } | 
|  | 3379 |  | 
|  | 3380 | TEST_F(LayerCallbackTest, MultipleTransactions_NoStateChange) { | 
|  | 3381 | sp<SurfaceControl> layer; | 
|  | 3382 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3383 |  | 
|  | 3384 | Transaction transaction; | 
|  | 3385 | CallbackHelper callback; | 
|  | 3386 | for (size_t i = 0; i < 10; i++) { | 
|  | 3387 | ExpectedResult expected; | 
|  | 3388 |  | 
|  | 3389 | if (i == 0) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3390 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3391 | if (err) { | 
|  | 3392 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3393 | return; | 
|  | 3394 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3395 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3396 | } else { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3397 | int err = fillTransaction(transaction, &callback); | 
|  | 3398 | if (err) { | 
|  | 3399 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3400 | return; | 
|  | 3401 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3402 | } | 
|  | 3403 |  | 
|  | 3404 | transaction.apply(); | 
|  | 3405 |  | 
|  | 3406 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); | 
|  | 3407 | } | 
|  | 3408 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); | 
|  | 3409 | } | 
|  | 3410 |  | 
|  | 3411 | TEST_F(LayerCallbackTest, MultipleTransactions_SameStateChange) { | 
|  | 3412 | sp<SurfaceControl> layer; | 
|  | 3413 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3414 |  | 
|  | 3415 | Transaction transaction; | 
|  | 3416 | CallbackHelper callback; | 
|  | 3417 | for (size_t i = 0; i < 10; i++) { | 
|  | 3418 | if (i == 0) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3419 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3420 | if (err) { | 
|  | 3421 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3422 | return; | 
|  | 3423 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3424 | } else { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3425 | int err = fillTransaction(transaction, &callback); | 
|  | 3426 | if (err) { | 
|  | 3427 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3428 | return; | 
|  | 3429 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3430 | } | 
|  | 3431 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3432 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3433 |  | 
|  | 3434 | ExpectedResult expected; | 
|  | 3435 | expected.addSurface((i == 0) ? ExpectedResult::Transaction::PRESENTED | 
|  | 3436 | : ExpectedResult::Transaction::NOT_PRESENTED, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3437 | layer, | 
|  | 3438 | (i == 0) ? ExpectedResult::Buffer::ACQUIRED | 
|  | 3439 | : ExpectedResult::Buffer::NOT_ACQUIRED); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3440 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, i == 0)); | 
|  | 3441 | } | 
|  | 3442 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); | 
|  | 3443 | } | 
|  | 3444 |  | 
|  | 3445 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge) { | 
|  | 3446 | sp<SurfaceControl> layer1, layer2; | 
|  | 3447 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 3448 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 3449 |  | 
|  | 3450 | Transaction transaction1, transaction2; | 
|  | 3451 | CallbackHelper callback1, callback2; | 
|  | 3452 | for (size_t i = 0; i < 10; i++) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3453 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3454 | if (err) { | 
|  | 3455 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3456 | return; | 
|  | 3457 | } | 
|  | 3458 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3459 | if (err) { | 
|  | 3460 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3461 | return; | 
|  | 3462 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3463 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3464 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3465 | 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] | 3466 |  | 
|  | 3467 | ExpectedResult expected; | 
|  | 3468 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3469 | ExpectedResult::Buffer::ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3470 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED | 
|  | 3471 | : ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 3472 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); | 
|  | 3473 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); | 
|  | 3474 | } | 
|  | 3475 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); | 
|  | 3476 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); | 
|  | 3477 | } | 
|  | 3478 |  | 
|  | 3479 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients) { | 
|  | 3480 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 3481 | client2(new SurfaceComposerClient); | 
|  | 3482 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3483 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3484 |  | 
|  | 3485 | sp<SurfaceControl> layer1, layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3486 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3487 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3488 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3489 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 3490 |  | 
|  | 3491 | Transaction transaction1, transaction2; | 
|  | 3492 | CallbackHelper callback1, callback2; | 
|  | 3493 | for (size_t i = 0; i < 10; i++) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3494 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3495 | if (err) { | 
|  | 3496 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3497 | return; | 
|  | 3498 | } | 
|  | 3499 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3500 | if (err) { | 
|  | 3501 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3502 | return; | 
|  | 3503 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3504 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3505 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3506 | 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] | 3507 |  | 
|  | 3508 | ExpectedResult expected; | 
|  | 3509 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3510 | ExpectedResult::Buffer::ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3511 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED | 
|  | 3512 | : ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 3513 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); | 
|  | 3514 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); | 
|  | 3515 | } | 
|  | 3516 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); | 
|  | 3517 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); | 
|  | 3518 | } | 
|  | 3519 |  | 
|  | 3520 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_NoStateChange) { | 
|  | 3521 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 3522 | client2(new SurfaceComposerClient); | 
|  | 3523 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3524 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3525 |  | 
|  | 3526 | sp<SurfaceControl> layer1, layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3527 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3528 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3529 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3530 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 3531 |  | 
|  | 3532 | Transaction transaction1, transaction2; | 
|  | 3533 | CallbackHelper callback1, callback2; | 
|  | 3534 |  | 
|  | 3535 | // Normal call to set up test | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3536 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3537 | if (err) { | 
|  | 3538 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3539 | return; | 
|  | 3540 | } | 
|  | 3541 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3542 | if (err) { | 
|  | 3543 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3544 | return; | 
|  | 3545 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3546 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3547 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3548 | 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] | 3549 |  | 
|  | 3550 | ExpectedResult expected; | 
|  | 3551 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3552 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3553 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3554 | expected.reset(); | 
|  | 3555 |  | 
|  | 3556 | // Test | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3557 | err = fillTransaction(transaction1, &callback1); | 
|  | 3558 | if (err) { | 
|  | 3559 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3560 | return; | 
|  | 3561 | } | 
|  | 3562 | err = fillTransaction(transaction2, &callback2); | 
|  | 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 | transaction2.merge(std::move(transaction1)).apply(); | 
|  | 3569 |  | 
|  | 3570 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3571 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3572 | } | 
|  | 3573 |  | 
|  | 3574 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_SameStateChange) { | 
|  | 3575 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 3576 | client2(new SurfaceComposerClient); | 
|  | 3577 |  | 
|  | 3578 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3579 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3580 |  | 
|  | 3581 | sp<SurfaceControl> layer1, layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3582 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3583 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3584 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3585 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 3586 |  | 
|  | 3587 | Transaction transaction1, transaction2; | 
|  | 3588 | CallbackHelper callback1, callback2; | 
|  | 3589 |  | 
|  | 3590 | // Normal call to set up test | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3591 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3592 | if (err) { | 
|  | 3593 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3594 | return; | 
|  | 3595 | } | 
|  | 3596 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3597 | if (err) { | 
|  | 3598 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3599 | return; | 
|  | 3600 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3601 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3602 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3603 | 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] | 3604 |  | 
|  | 3605 | ExpectedResult expected; | 
|  | 3606 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3607 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3608 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3609 | expected.reset(); | 
|  | 3610 |  | 
|  | 3611 | // Test | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3612 | err = fillTransaction(transaction1, &callback1); | 
|  | 3613 | if (err) { | 
|  | 3614 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3615 | return; | 
|  | 3616 | } | 
|  | 3617 | err = fillTransaction(transaction2, &callback2); | 
|  | 3618 | if (err) { | 
|  | 3619 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3620 | return; | 
|  | 3621 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3622 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3623 | 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] | 3624 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3625 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer2, | 
|  | 3626 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3627 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3628 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3629 | } | 
|  | 3630 |  | 
|  | 3631 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame) { | 
|  | 3632 | sp<SurfaceControl> layer; | 
|  | 3633 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3634 |  | 
|  | 3635 | Transaction transaction; | 
|  | 3636 | CallbackHelper callback; | 
|  | 3637 | std::vector<ExpectedResult> expectedResults(50); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3638 | for (auto& expected : expectedResults) { | 
|  | 3639 | expected.reset(); | 
|  | 3640 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
| Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3641 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 3642 | ExpectedResult::PreviousBuffer::UNKNOWN); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3643 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3644 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3645 | if (err) { | 
|  | 3646 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3647 | return; | 
|  | 3648 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3649 |  | 
|  | 3650 | transaction.apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3651 | } | 
|  | 3652 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); | 
|  | 3653 | } | 
|  | 3654 |  | 
|  | 3655 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_NoStateChange) { | 
|  | 3656 | sp<SurfaceControl> layer; | 
|  | 3657 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3658 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3659 | // Normal call to set up test | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3660 | Transaction transaction; | 
|  | 3661 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3662 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3663 | if (err) { | 
|  | 3664 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3665 | return; | 
|  | 3666 | } | 
|  | 3667 |  | 
|  | 3668 | transaction.apply(); | 
|  | 3669 |  | 
|  | 3670 | ExpectedResult expected; | 
|  | 3671 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3672 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3673 |  | 
|  | 3674 | // Test | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3675 | std::vector<ExpectedResult> expectedResults(50); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3676 | for (auto& expected : expectedResults) { | 
|  | 3677 | expected.reset(); | 
|  | 3678 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3679 | err = fillTransaction(transaction, &callback); | 
|  | 3680 | if (err) { | 
|  | 3681 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3682 | return; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3683 | } | 
|  | 3684 |  | 
|  | 3685 | transaction.apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3686 | } | 
|  | 3687 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); | 
|  | 3688 | } | 
|  | 3689 |  | 
|  | 3690 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_SameStateChange) { | 
|  | 3691 | sp<SurfaceControl> layer; | 
|  | 3692 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3693 |  | 
|  | 3694 | // Normal call to set up test | 
|  | 3695 | Transaction transaction; | 
|  | 3696 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3697 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3698 | if (err) { | 
|  | 3699 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3700 | return; | 
|  | 3701 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3702 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3703 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3704 |  | 
|  | 3705 | ExpectedResult expectedResult; | 
|  | 3706 | expectedResult.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3707 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expectedResult, true)); | 
|  | 3708 |  | 
|  | 3709 | // Test | 
|  | 3710 | std::vector<ExpectedResult> expectedResults(50); | 
|  | 3711 | for (auto& expected : expectedResults) { | 
|  | 3712 | expected.reset(); | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3713 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, | 
|  | 3714 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3715 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3716 | err = fillTransaction(transaction, &callback); | 
|  | 3717 | if (err) { | 
|  | 3718 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3719 | return; | 
|  | 3720 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3721 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3722 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3723 | } | 
|  | 3724 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); | 
|  | 3725 | } | 
|  | 3726 |  | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3727 | TEST_F(LayerCallbackTest, DesiredPresentTime) { | 
|  | 3728 | sp<SurfaceControl> layer; | 
|  | 3729 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3730 |  | 
|  | 3731 | Transaction transaction; | 
|  | 3732 | CallbackHelper callback; | 
|  | 3733 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3734 | if (err) { | 
|  | 3735 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3736 | return; | 
|  | 3737 | } | 
|  | 3738 |  | 
|  | 3739 | // Try to present 100ms in the future | 
|  | 3740 | nsecs_t time = systemTime() + (100 * 1e6); | 
|  | 3741 |  | 
|  | 3742 | transaction.setDesiredPresentTime(time); | 
|  | 3743 | transaction.apply(); | 
|  | 3744 |  | 
|  | 3745 | ExpectedResult expected; | 
|  | 3746 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3747 | expected.addExpectedPresentTime(time); | 
|  | 3748 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3749 | } | 
|  | 3750 |  | 
|  | 3751 | TEST_F(LayerCallbackTest, DesiredPresentTime_Multiple) { | 
|  | 3752 | sp<SurfaceControl> layer; | 
|  | 3753 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3754 |  | 
|  | 3755 | Transaction transaction; | 
|  | 3756 | CallbackHelper callback1; | 
|  | 3757 | int err = fillTransaction(transaction, &callback1, layer); | 
|  | 3758 | if (err) { | 
|  | 3759 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3760 | return; | 
|  | 3761 | } | 
|  | 3762 |  | 
|  | 3763 | // Try to present 100ms in the future | 
|  | 3764 | nsecs_t time = systemTime() + (100 * 1e6); | 
|  | 3765 |  | 
|  | 3766 | transaction.setDesiredPresentTime(time); | 
|  | 3767 | transaction.apply(); | 
|  | 3768 |  | 
|  | 3769 | ExpectedResult expected1; | 
|  | 3770 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3771 | expected1.addExpectedPresentTime(time); | 
|  | 3772 |  | 
|  | 3773 | CallbackHelper callback2; | 
|  | 3774 | err = fillTransaction(transaction, &callback2, layer); | 
|  | 3775 | if (err) { | 
|  | 3776 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3777 | return; | 
|  | 3778 | } | 
|  | 3779 |  | 
|  | 3780 | // Try to present 33ms after the first frame | 
|  | 3781 | time += (33.3 * 1e6); | 
|  | 3782 |  | 
|  | 3783 | transaction.setDesiredPresentTime(time); | 
|  | 3784 | transaction.apply(); | 
|  | 3785 |  | 
|  | 3786 | ExpectedResult expected2; | 
|  | 3787 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 3788 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 3789 | ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 3790 | expected2.addExpectedPresentTime(time); | 
|  | 3791 |  | 
|  | 3792 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); | 
|  | 3793 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); | 
|  | 3794 | } | 
|  | 3795 |  | 
|  | 3796 | TEST_F(LayerCallbackTest, DesiredPresentTime_OutOfOrder) { | 
|  | 3797 | sp<SurfaceControl> layer; | 
|  | 3798 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3799 |  | 
|  | 3800 | Transaction transaction; | 
|  | 3801 | CallbackHelper callback1; | 
|  | 3802 | int err = fillTransaction(transaction, &callback1, layer); | 
|  | 3803 | if (err) { | 
|  | 3804 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3805 | return; | 
|  | 3806 | } | 
|  | 3807 |  | 
|  | 3808 | // Try to present 100ms in the future | 
|  | 3809 | nsecs_t time = systemTime() + (100 * 1e6); | 
|  | 3810 |  | 
|  | 3811 | transaction.setDesiredPresentTime(time); | 
|  | 3812 | transaction.apply(); | 
|  | 3813 |  | 
|  | 3814 | ExpectedResult expected1; | 
|  | 3815 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3816 | expected1.addExpectedPresentTime(time); | 
|  | 3817 |  | 
|  | 3818 | CallbackHelper callback2; | 
|  | 3819 | err = fillTransaction(transaction, &callback2, layer); | 
|  | 3820 | if (err) { | 
|  | 3821 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3822 | return; | 
|  | 3823 | } | 
|  | 3824 |  | 
|  | 3825 | // Try to present 33ms before the previous frame | 
|  | 3826 | time -= (33.3 * 1e6); | 
|  | 3827 |  | 
|  | 3828 | transaction.setDesiredPresentTime(time); | 
|  | 3829 | transaction.apply(); | 
|  | 3830 |  | 
|  | 3831 | ExpectedResult expected2; | 
|  | 3832 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 3833 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 3834 | ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 3835 |  | 
|  | 3836 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); | 
|  | 3837 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); | 
|  | 3838 | } | 
|  | 3839 |  | 
|  | 3840 | TEST_F(LayerCallbackTest, DesiredPresentTime_Past) { | 
|  | 3841 | sp<SurfaceControl> layer; | 
|  | 3842 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3843 |  | 
|  | 3844 | Transaction transaction; | 
|  | 3845 | CallbackHelper callback; | 
|  | 3846 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3847 | if (err) { | 
|  | 3848 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3849 | return; | 
|  | 3850 | } | 
|  | 3851 |  | 
|  | 3852 | // Try to present 100ms in the past | 
|  | 3853 | nsecs_t time = systemTime() - (100 * 1e6); | 
|  | 3854 |  | 
|  | 3855 | transaction.setDesiredPresentTime(time); | 
|  | 3856 | transaction.apply(); | 
|  | 3857 |  | 
|  | 3858 | ExpectedResult expected; | 
|  | 3859 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3860 | expected.addExpectedPresentTime(systemTime()); | 
|  | 3861 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3862 | } | 
|  | 3863 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 3864 | class LayerUpdateTest : public LayerTransactionTest { | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3865 | protected: | 
|  | 3866 | virtual void SetUp() { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3867 | LayerTransactionTest::SetUp(); | 
|  | 3868 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3869 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 3870 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); | 
|  | 3871 | ASSERT_FALSE(display == nullptr); | 
|  | 3872 |  | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 3873 | DisplayInfo info; | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 3874 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayInfo(display, &info)); | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 3875 |  | 
|  | 3876 | ssize_t displayWidth = info.w; | 
|  | 3877 | ssize_t displayHeight = info.h; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3878 |  | 
|  | 3879 | // Background surface | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3880 | mBGSurfaceControl = createLayer(String8("BG Test Surface"), displayWidth, | 
|  | 3881 | displayHeight, 0); | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 3882 | ASSERT_TRUE(mBGSurfaceControl != nullptr); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3883 | ASSERT_TRUE(mBGSurfaceControl->isValid()); | 
|  | 3884 | fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195); | 
|  | 3885 |  | 
|  | 3886 | // Foreground surface | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3887 | mFGSurfaceControl = createLayer(String8("FG Test Surface"), 64, 64, 0); | 
|  | 3888 |  | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 3889 | ASSERT_TRUE(mFGSurfaceControl != nullptr); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3890 | ASSERT_TRUE(mFGSurfaceControl->isValid()); | 
|  | 3891 |  | 
|  | 3892 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 3893 |  | 
|  | 3894 | // Synchronization surface | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3895 | mSyncSurfaceControl = createLayer(String8("Sync Test Surface"), 1, 1, 0); | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 3896 | ASSERT_TRUE(mSyncSurfaceControl != nullptr); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3897 | ASSERT_TRUE(mSyncSurfaceControl->isValid()); | 
|  | 3898 |  | 
|  | 3899 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 3900 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3901 | asTransaction([&](Transaction& t) { | 
|  | 3902 | t.setDisplayLayerStack(display, 0); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3903 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3904 | t.setLayer(mBGSurfaceControl, INT32_MAX - 2).show(mBGSurfaceControl); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 3905 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3906 | t.setLayer(mFGSurfaceControl, INT32_MAX - 1) | 
|  | 3907 | .setPosition(mFGSurfaceControl, 64, 64) | 
|  | 3908 | .show(mFGSurfaceControl); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3909 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3910 | t.setLayer(mSyncSurfaceControl, INT32_MAX - 1) | 
|  | 3911 | .setPosition(mSyncSurfaceControl, displayWidth - 2, displayHeight - 2) | 
|  | 3912 | .show(mSyncSurfaceControl); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3913 | }); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3914 | } | 
|  | 3915 |  | 
|  | 3916 | virtual void TearDown() { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3917 | LayerTransactionTest::TearDown(); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3918 | mBGSurfaceControl = 0; | 
|  | 3919 | mFGSurfaceControl = 0; | 
|  | 3920 | mSyncSurfaceControl = 0; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3921 | } | 
|  | 3922 |  | 
|  | 3923 | void waitForPostedBuffers() { | 
|  | 3924 | // Since the sync surface is in synchronous mode (i.e. double buffered) | 
|  | 3925 | // posting three buffers to it should ensure that at least two | 
|  | 3926 | // SurfaceFlinger::handlePageFlip calls have been made, which should | 
|  | 3927 | // guaranteed that a buffer posted to another Surface has been retired. | 
|  | 3928 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 3929 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 3930 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 3931 | } | 
|  | 3932 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 3933 | void asTransaction(const std::function<void(Transaction&)>& exec) { | 
|  | 3934 | Transaction t; | 
|  | 3935 | exec(t); | 
|  | 3936 | t.apply(true); | 
|  | 3937 | } | 
|  | 3938 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 3939 | sp<SurfaceControl> mBGSurfaceControl; | 
|  | 3940 | sp<SurfaceControl> mFGSurfaceControl; | 
|  | 3941 |  | 
|  | 3942 | // This surface is used to ensure that the buffers posted to | 
|  | 3943 | // mFGSurfaceControl have been picked up by SurfaceFlinger. | 
|  | 3944 | sp<SurfaceControl> mSyncSurfaceControl; | 
|  | 3945 | }; | 
|  | 3946 |  | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3947 | TEST_F(LayerUpdateTest, RelativesAreNotDetached) { | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3948 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 3949 | std::unique_ptr<ScreenCapture> sc; | 
|  | 3950 |  | 
|  | 3951 | sp<SurfaceControl> relative = createLayer(String8("relativeTestSurface"), 10, 10, 0); | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3952 | fillSurfaceRGBA8(relative, 10, 10, 10); | 
|  | 3953 | waitForPostedBuffers(); | 
|  | 3954 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3955 | Transaction{} | 
|  | 3956 | .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1) | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3957 | .setPosition(relative, 64, 64) | 
|  | 3958 | .apply(); | 
|  | 3959 |  | 
|  | 3960 | { | 
|  | 3961 | // The relative should be on top of the FG control. | 
|  | 3962 | ScreenCapture::captureScreen(&sc); | 
|  | 3963 | sc->checkPixel(64, 64, 10, 10, 10); | 
|  | 3964 | } | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3965 | Transaction{}.detachChildren(mFGSurfaceControl).apply(); | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3966 |  | 
|  | 3967 | { | 
|  | 3968 | // Nothing should change at this point. | 
|  | 3969 | ScreenCapture::captureScreen(&sc); | 
|  | 3970 | sc->checkPixel(64, 64, 10, 10, 10); | 
|  | 3971 | } | 
|  | 3972 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3973 | Transaction{}.hide(relative).apply(); | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 3974 |  | 
|  | 3975 | { | 
|  | 3976 | // Ensure that the relative was actually hidden, rather than | 
|  | 3977 | // being left in the detached but visible state. | 
|  | 3978 | ScreenCapture::captureScreen(&sc); | 
|  | 3979 | sc->expectFGColor(64, 64); | 
|  | 3980 | } | 
|  | 3981 | } | 
|  | 3982 |  | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 3983 | class GeometryLatchingTest : public LayerUpdateTest { | 
|  | 3984 | protected: | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3985 | void EXPECT_INITIAL_STATE(const char* trace) { | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 3986 | SCOPED_TRACE(trace); | 
|  | 3987 | ScreenCapture::captureScreen(&sc); | 
|  | 3988 | // We find the leading edge of the FG surface. | 
|  | 3989 | sc->expectFGColor(127, 127); | 
|  | 3990 | sc->expectBGColor(128, 128); | 
|  | 3991 | } | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 3992 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 3993 | void lockAndFillFGBuffer() { fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false); } | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 3994 |  | 
|  | 3995 | void unlockFGBuffer() { | 
|  | 3996 | sp<Surface> s = mFGSurfaceControl->getSurface(); | 
|  | 3997 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); | 
|  | 3998 | waitForPostedBuffers(); | 
|  | 3999 | } | 
|  | 4000 |  | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4001 | void completeFGResize() { | 
|  | 4002 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 4003 | waitForPostedBuffers(); | 
|  | 4004 | } | 
|  | 4005 | void restoreInitialState() { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4006 | asTransaction([&](Transaction& t) { | 
|  | 4007 | t.setSize(mFGSurfaceControl, 64, 64); | 
|  | 4008 | t.setPosition(mFGSurfaceControl, 64, 64); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4009 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 64, 64)); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4010 | }); | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4011 |  | 
|  | 4012 | EXPECT_INITIAL_STATE("After restoring initial state"); | 
|  | 4013 | } | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4014 | std::unique_ptr<ScreenCapture> sc; | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4015 | }; | 
|  | 4016 |  | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4017 | class CropLatchingTest : public GeometryLatchingTest { | 
|  | 4018 | protected: | 
|  | 4019 | void EXPECT_CROPPED_STATE(const char* trace) { | 
|  | 4020 | SCOPED_TRACE(trace); | 
|  | 4021 | ScreenCapture::captureScreen(&sc); | 
|  | 4022 | // The edge should be moved back one pixel by our crop. | 
|  | 4023 | sc->expectFGColor(126, 126); | 
|  | 4024 | sc->expectBGColor(127, 127); | 
|  | 4025 | sc->expectBGColor(128, 128); | 
|  | 4026 | } | 
| chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 4027 |  | 
|  | 4028 | void EXPECT_RESIZE_STATE(const char* trace) { | 
|  | 4029 | SCOPED_TRACE(trace); | 
|  | 4030 | ScreenCapture::captureScreen(&sc); | 
|  | 4031 | // The FG is now resized too 128,128 at 64,64 | 
|  | 4032 | sc->expectFGColor(64, 64); | 
|  | 4033 | sc->expectFGColor(191, 191); | 
|  | 4034 | sc->expectBGColor(192, 192); | 
|  | 4035 | } | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4036 | }; | 
|  | 4037 |  | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4038 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4039 | std::unique_ptr<ScreenCapture> sc; | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4040 | { | 
|  | 4041 | SCOPED_TRACE("before anything"); | 
|  | 4042 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4043 | sc->expectBGColor(32, 32); | 
|  | 4044 | sc->expectFGColor(96, 96); | 
|  | 4045 | sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4046 | } | 
|  | 4047 |  | 
|  | 4048 | // set up two deferred transactions on different frames | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4049 | asTransaction([&](Transaction& t) { | 
|  | 4050 | t.setAlpha(mFGSurfaceControl, 0.75); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4051 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), | 
|  | 4052 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4053 | }); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4054 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4055 | asTransaction([&](Transaction& t) { | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4056 | t.setPosition(mFGSurfaceControl, 128, 128); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4057 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), | 
|  | 4058 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4059 | }); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4060 |  | 
|  | 4061 | { | 
|  | 4062 | SCOPED_TRACE("before any trigger"); | 
|  | 4063 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4064 | sc->expectBGColor(32, 32); | 
|  | 4065 | sc->expectFGColor(96, 96); | 
|  | 4066 | sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4067 | } | 
|  | 4068 |  | 
|  | 4069 | // should trigger the first deferred transaction, but not the second one | 
|  | 4070 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 4071 | { | 
|  | 4072 | SCOPED_TRACE("after first trigger"); | 
|  | 4073 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4074 | sc->expectBGColor(32, 32); | 
|  | 4075 | sc->checkPixel(96, 96, 162, 63, 96); | 
|  | 4076 | sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4077 | } | 
|  | 4078 |  | 
|  | 4079 | // should show up immediately since it's not deferred | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4080 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 1.0); }); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4081 |  | 
|  | 4082 | // trigger the second deferred transaction | 
|  | 4083 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 4084 | { | 
|  | 4085 | SCOPED_TRACE("after second trigger"); | 
|  | 4086 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4087 | sc->expectBGColor(32, 32); | 
|  | 4088 | sc->expectBGColor(96, 96); | 
|  | 4089 | sc->expectFGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4090 | } | 
|  | 4091 | } | 
|  | 4092 |  | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4093 | TEST_F(LayerUpdateTest, LayerWithNoBuffersResizesImmediately) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4094 | std::unique_ptr<ScreenCapture> sc; | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4095 |  | 
|  | 4096 | sp<SurfaceControl> childNoBuffer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4097 | createSurface(mClient, "Bufferless child", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 4098 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 4099 | sp<SurfaceControl> childBuffer = createSurface(mClient, "Buffered child", 20, 20, | 
|  | 4100 | PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get()); | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4101 | fillSurfaceRGBA8(childBuffer, 200, 200, 200); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4102 | SurfaceComposerClient::Transaction{} | 
|  | 4103 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 10, 10)) | 
|  | 4104 | .show(childNoBuffer) | 
|  | 4105 | .show(childBuffer) | 
|  | 4106 | .apply(true); | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4107 | { | 
|  | 4108 | ScreenCapture::captureScreen(&sc); | 
|  | 4109 | sc->expectChildColor(73, 73); | 
|  | 4110 | sc->expectFGColor(74, 74); | 
|  | 4111 | } | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4112 | SurfaceComposerClient::Transaction{} | 
|  | 4113 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 20, 20)) | 
|  | 4114 | .apply(true); | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4115 | { | 
|  | 4116 | ScreenCapture::captureScreen(&sc); | 
|  | 4117 | sc->expectChildColor(73, 73); | 
|  | 4118 | sc->expectChildColor(74, 74); | 
|  | 4119 | } | 
|  | 4120 | } | 
|  | 4121 |  | 
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 4122 | TEST_F(LayerUpdateTest, MergingTransactions) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4123 | std::unique_ptr<ScreenCapture> sc; | 
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 4124 | { | 
|  | 4125 | SCOPED_TRACE("before move"); | 
|  | 4126 | ScreenCapture::captureScreen(&sc); | 
|  | 4127 | sc->expectBGColor(0, 12); | 
|  | 4128 | sc->expectFGColor(75, 75); | 
|  | 4129 | sc->expectBGColor(145, 145); | 
|  | 4130 | } | 
|  | 4131 |  | 
|  | 4132 | Transaction t1, t2; | 
|  | 4133 | t1.setPosition(mFGSurfaceControl, 128, 128); | 
|  | 4134 | t2.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4135 | // We expect that the position update from t2 now | 
|  | 4136 | // overwrites the position update from t1. | 
|  | 4137 | t1.merge(std::move(t2)); | 
|  | 4138 | t1.apply(); | 
|  | 4139 |  | 
|  | 4140 | { | 
|  | 4141 | ScreenCapture::captureScreen(&sc); | 
|  | 4142 | sc->expectFGColor(1, 1); | 
|  | 4143 | } | 
|  | 4144 | } | 
|  | 4145 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4146 | class ChildLayerTest : public LayerUpdateTest { | 
|  | 4147 | protected: | 
|  | 4148 | void SetUp() override { | 
|  | 4149 | LayerUpdateTest::SetUp(); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4150 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, | 
|  | 4151 | mFGSurfaceControl.get()); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4152 | fillSurfaceRGBA8(mChild, 200, 200, 200); | 
|  | 4153 |  | 
|  | 4154 | { | 
|  | 4155 | SCOPED_TRACE("before anything"); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4156 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4157 | mCapture->expectChildColor(64, 64); | 
|  | 4158 | } | 
|  | 4159 | } | 
|  | 4160 | void TearDown() override { | 
|  | 4161 | LayerUpdateTest::TearDown(); | 
|  | 4162 | mChild = 0; | 
|  | 4163 | } | 
|  | 4164 |  | 
|  | 4165 | sp<SurfaceControl> mChild; | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4166 | std::unique_ptr<ScreenCapture> mCapture; | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4167 | }; | 
|  | 4168 |  | 
|  | 4169 | TEST_F(ChildLayerTest, ChildLayerPositioning) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4170 | asTransaction([&](Transaction& t) { | 
|  | 4171 | t.show(mChild); | 
|  | 4172 | t.setPosition(mChild, 10, 10); | 
|  | 4173 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4174 | }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4175 |  | 
|  | 4176 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4177 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4178 | // Top left of foreground must now be visible | 
|  | 4179 | mCapture->expectFGColor(64, 64); | 
|  | 4180 | // But 10 pixels in we should see the child surface | 
|  | 4181 | mCapture->expectChildColor(74, 74); | 
|  | 4182 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4183 | mCapture->expectFGColor(84, 84); | 
|  | 4184 | } | 
|  | 4185 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4186 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4187 |  | 
|  | 4188 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4189 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4190 | // Top left of foreground should now be at 0, 0 | 
|  | 4191 | mCapture->expectFGColor(0, 0); | 
|  | 4192 | // But 10 pixels in we should see the child surface | 
|  | 4193 | mCapture->expectChildColor(10, 10); | 
|  | 4194 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4195 | mCapture->expectFGColor(20, 20); | 
|  | 4196 | } | 
|  | 4197 | } | 
|  | 4198 |  | 
| Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4199 | TEST_F(ChildLayerTest, ChildLayerCropping) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4200 | asTransaction([&](Transaction& t) { | 
|  | 4201 | t.show(mChild); | 
|  | 4202 | t.setPosition(mChild, 0, 0); | 
|  | 4203 | t.setPosition(mFGSurfaceControl, 0, 0); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4204 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 5, 5)); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4205 | }); | 
| Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4206 |  | 
|  | 4207 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4208 | mCapture = screenshot(); | 
| Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4209 | mCapture->expectChildColor(0, 0); | 
|  | 4210 | mCapture->expectChildColor(4, 4); | 
|  | 4211 | mCapture->expectBGColor(5, 5); | 
|  | 4212 | } | 
|  | 4213 | } | 
|  | 4214 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4215 | TEST_F(ChildLayerTest, ChildLayerConstraints) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4216 | asTransaction([&](Transaction& t) { | 
|  | 4217 | t.show(mChild); | 
|  | 4218 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4219 | t.setPosition(mChild, 63, 63); | 
|  | 4220 | }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4221 |  | 
|  | 4222 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4223 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4224 | mCapture->expectFGColor(0, 0); | 
|  | 4225 | // Last pixel in foreground should now be the child. | 
|  | 4226 | mCapture->expectChildColor(63, 63); | 
|  | 4227 | // But the child should be constrained and the next pixel | 
|  | 4228 | // must be the background | 
|  | 4229 | mCapture->expectBGColor(64, 64); | 
|  | 4230 | } | 
|  | 4231 | } | 
|  | 4232 |  | 
|  | 4233 | TEST_F(ChildLayerTest, ChildLayerScaling) { | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4234 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4235 |  | 
|  | 4236 | // Find the boundary between the parent and child | 
|  | 4237 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4238 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4239 | mCapture->expectChildColor(9, 9); | 
|  | 4240 | mCapture->expectFGColor(10, 10); | 
|  | 4241 | } | 
|  | 4242 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4243 | asTransaction([&](Transaction& t) { t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0); }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4244 |  | 
|  | 4245 | // The boundary should be twice as far from the origin now. | 
|  | 4246 | // The pixels from the last test should all be child now | 
|  | 4247 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4248 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4249 | mCapture->expectChildColor(9, 9); | 
|  | 4250 | mCapture->expectChildColor(10, 10); | 
|  | 4251 | mCapture->expectChildColor(19, 19); | 
|  | 4252 | mCapture->expectFGColor(20, 20); | 
|  | 4253 | } | 
|  | 4254 | } | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4255 |  | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4256 | TEST_F(ChildLayerTest, ChildLayerAlpha) { | 
|  | 4257 | fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254); | 
|  | 4258 | fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0); | 
|  | 4259 | fillSurfaceRGBA8(mChild, 0, 254, 0); | 
|  | 4260 | waitForPostedBuffers(); | 
|  | 4261 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4262 | asTransaction([&](Transaction& t) { | 
|  | 4263 | t.show(mChild); | 
|  | 4264 | t.setPosition(mChild, 0, 0); | 
|  | 4265 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4266 | }); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4267 |  | 
|  | 4268 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4269 | mCapture = screenshot(); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4270 | // Unblended child color | 
|  | 4271 | mCapture->checkPixel(0, 0, 0, 254, 0); | 
|  | 4272 | } | 
|  | 4273 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4274 | asTransaction([&](Transaction& t) { t.setAlpha(mChild, 0.5); }); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4275 |  | 
|  | 4276 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4277 | mCapture = screenshot(); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4278 | // Child and BG blended. | 
|  | 4279 | mCapture->checkPixel(0, 0, 127, 127, 0); | 
|  | 4280 | } | 
|  | 4281 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4282 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 0.5); }); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4283 |  | 
|  | 4284 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4285 | mCapture = screenshot(); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4286 | // Child and BG blended. | 
|  | 4287 | mCapture->checkPixel(0, 0, 95, 64, 95); | 
|  | 4288 | } | 
|  | 4289 | } | 
|  | 4290 |  | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4291 | TEST_F(ChildLayerTest, ReparentChildren) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4292 | asTransaction([&](Transaction& t) { | 
|  | 4293 | t.show(mChild); | 
|  | 4294 | t.setPosition(mChild, 10, 10); | 
|  | 4295 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4296 | }); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4297 |  | 
|  | 4298 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4299 | mCapture = screenshot(); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4300 | // Top left of foreground must now be visible | 
|  | 4301 | mCapture->expectFGColor(64, 64); | 
|  | 4302 | // But 10 pixels in we should see the child surface | 
|  | 4303 | mCapture->expectChildColor(74, 74); | 
|  | 4304 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4305 | mCapture->expectFGColor(84, 84); | 
|  | 4306 | } | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4307 |  | 
|  | 4308 | asTransaction([&](Transaction& t) { | 
|  | 4309 | t.reparentChildren(mFGSurfaceControl, mBGSurfaceControl->getHandle()); | 
|  | 4310 | }); | 
|  | 4311 |  | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4312 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4313 | mCapture = screenshot(); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4314 | mCapture->expectFGColor(64, 64); | 
|  | 4315 | // In reparenting we should have exposed the entire foreground surface. | 
|  | 4316 | mCapture->expectFGColor(74, 74); | 
|  | 4317 | // And the child layer should now begin at 10, 10 (since the BG | 
|  | 4318 | // layer is at (0, 0)). | 
|  | 4319 | mCapture->expectBGColor(9, 9); | 
|  | 4320 | mCapture->expectChildColor(10, 10); | 
|  | 4321 | } | 
|  | 4322 | } | 
|  | 4323 |  | 
| Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4324 | TEST_F(ChildLayerTest, ChildrenSurviveParentDestruction) { | 
|  | 4325 | sp<SurfaceControl> mGrandChild = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4326 | 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] | 4327 | fillSurfaceRGBA8(mGrandChild, 111, 111, 111); | 
|  | 4328 |  | 
|  | 4329 | { | 
|  | 4330 | SCOPED_TRACE("Grandchild visible"); | 
|  | 4331 | ScreenCapture::captureScreen(&mCapture); | 
|  | 4332 | mCapture->checkPixel(64, 64, 111, 111, 111); | 
|  | 4333 | } | 
|  | 4334 |  | 
|  | 4335 | mChild->clear(); | 
|  | 4336 |  | 
|  | 4337 | { | 
|  | 4338 | SCOPED_TRACE("After destroying child"); | 
|  | 4339 | ScreenCapture::captureScreen(&mCapture); | 
|  | 4340 | mCapture->expectFGColor(64, 64); | 
|  | 4341 | } | 
|  | 4342 |  | 
|  | 4343 | asTransaction([&](Transaction& t) { | 
|  | 4344 | t.reparent(mGrandChild, mFGSurfaceControl->getHandle()); | 
|  | 4345 | }); | 
|  | 4346 |  | 
|  | 4347 | { | 
|  | 4348 | SCOPED_TRACE("After reparenting grandchild"); | 
|  | 4349 | ScreenCapture::captureScreen(&mCapture); | 
|  | 4350 | mCapture->checkPixel(64, 64, 111, 111, 111); | 
|  | 4351 | } | 
|  | 4352 | } | 
|  | 4353 |  | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4354 | TEST_F(ChildLayerTest, DetachChildrenSameClient) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4355 | asTransaction([&](Transaction& t) { | 
|  | 4356 | t.show(mChild); | 
|  | 4357 | t.setPosition(mChild, 10, 10); | 
|  | 4358 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4359 | }); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4360 |  | 
|  | 4361 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4362 | mCapture = screenshot(); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4363 | // Top left of foreground must now be visible | 
|  | 4364 | mCapture->expectFGColor(64, 64); | 
|  | 4365 | // But 10 pixels in we should see the child surface | 
|  | 4366 | mCapture->expectChildColor(74, 74); | 
|  | 4367 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4368 | mCapture->expectFGColor(84, 84); | 
|  | 4369 | } | 
|  | 4370 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4371 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4372 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4373 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4374 | asTransaction([&](Transaction& t) { t.hide(mChild); }); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4375 |  | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4376 | // Since the child has the same client as the parent, it will not get | 
|  | 4377 | // detached and will be hidden. | 
|  | 4378 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4379 | mCapture = screenshot(); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4380 | mCapture->expectFGColor(64, 64); | 
|  | 4381 | mCapture->expectFGColor(74, 74); | 
|  | 4382 | mCapture->expectFGColor(84, 84); | 
|  | 4383 | } | 
|  | 4384 | } | 
|  | 4385 |  | 
|  | 4386 | TEST_F(ChildLayerTest, DetachChildrenDifferentClient) { | 
|  | 4387 | sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient; | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4388 | sp<SurfaceControl> mChildNewClient = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4389 | createSurface(mNewComposerClient, "New Child Test Surface", 10, 10, | 
|  | 4390 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4391 |  | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4392 | ASSERT_TRUE(mChildNewClient->isValid()); | 
|  | 4393 |  | 
|  | 4394 | fillSurfaceRGBA8(mChildNewClient, 200, 200, 200); | 
|  | 4395 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4396 | asTransaction([&](Transaction& t) { | 
|  | 4397 | t.hide(mChild); | 
|  | 4398 | t.show(mChildNewClient); | 
|  | 4399 | t.setPosition(mChildNewClient, 10, 10); | 
|  | 4400 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4401 | }); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4402 |  | 
|  | 4403 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4404 | mCapture = screenshot(); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4405 | // Top left of foreground must now be visible | 
|  | 4406 | mCapture->expectFGColor(64, 64); | 
|  | 4407 | // But 10 pixels in we should see the child surface | 
|  | 4408 | mCapture->expectChildColor(74, 74); | 
|  | 4409 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4410 | mCapture->expectFGColor(84, 84); | 
|  | 4411 | } | 
|  | 4412 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4413 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4414 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4415 | asTransaction([&](Transaction& t) { t.hide(mChildNewClient); }); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4416 |  | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4417 | // Nothing should have changed. | 
|  | 4418 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4419 | mCapture = screenshot(); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4420 | mCapture->expectFGColor(64, 64); | 
|  | 4421 | mCapture->expectChildColor(74, 74); | 
|  | 4422 | mCapture->expectFGColor(84, 84); | 
|  | 4423 | } | 
|  | 4424 | } | 
|  | 4425 |  | 
| chaviw | 5aedec9 | 2018-10-22 10:40:38 -0700 | [diff] [blame] | 4426 | TEST_F(ChildLayerTest, DetachChildrenThenAttach) { | 
|  | 4427 | sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; | 
|  | 4428 | sp<SurfaceControl> childNewClient = | 
|  | 4429 | newComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, | 
|  | 4430 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 4431 |  | 
|  | 4432 | ASSERT_TRUE(childNewClient != nullptr); | 
|  | 4433 | ASSERT_TRUE(childNewClient->isValid()); | 
|  | 4434 |  | 
|  | 4435 | fillSurfaceRGBA8(childNewClient, 200, 200, 200); | 
|  | 4436 |  | 
|  | 4437 | Transaction() | 
|  | 4438 | .hide(mChild) | 
|  | 4439 | .show(childNewClient) | 
|  | 4440 | .setPosition(childNewClient, 10, 10) | 
|  | 4441 | .setPosition(mFGSurfaceControl, 64, 64) | 
|  | 4442 | .apply(); | 
|  | 4443 |  | 
|  | 4444 | { | 
|  | 4445 | mCapture = screenshot(); | 
|  | 4446 | // Top left of foreground must now be visible | 
|  | 4447 | mCapture->expectFGColor(64, 64); | 
|  | 4448 | // But 10 pixels in we should see the child surface | 
|  | 4449 | mCapture->expectChildColor(74, 74); | 
|  | 4450 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4451 | mCapture->expectFGColor(84, 84); | 
|  | 4452 | } | 
|  | 4453 |  | 
|  | 4454 | Transaction().detachChildren(mFGSurfaceControl).apply(); | 
|  | 4455 | Transaction().hide(childNewClient).apply(); | 
|  | 4456 |  | 
|  | 4457 | // Nothing should have changed. | 
|  | 4458 | { | 
|  | 4459 | mCapture = screenshot(); | 
|  | 4460 | mCapture->expectFGColor(64, 64); | 
|  | 4461 | mCapture->expectChildColor(74, 74); | 
|  | 4462 | mCapture->expectFGColor(84, 84); | 
|  | 4463 | } | 
|  | 4464 |  | 
|  | 4465 | sp<SurfaceControl> newParentSurface = createLayer(String8("New Parent Surface"), 32, 32, 0); | 
|  | 4466 | fillLayerColor(ISurfaceComposerClient::eFXSurfaceBufferQueue, newParentSurface, Color::RED, 32, | 
|  | 4467 | 32); | 
|  | 4468 | Transaction() | 
|  | 4469 | .setLayer(newParentSurface, INT32_MAX - 1) | 
|  | 4470 | .show(newParentSurface) | 
|  | 4471 | .setPosition(newParentSurface, 20, 20) | 
|  | 4472 | .reparent(childNewClient, newParentSurface->getHandle()) | 
|  | 4473 | .apply(); | 
|  | 4474 | { | 
|  | 4475 | mCapture = screenshot(); | 
|  | 4476 | // Child is now hidden. | 
|  | 4477 | mCapture->expectColor(Rect(20, 20, 52, 52), Color::RED); | 
|  | 4478 | } | 
|  | 4479 | } | 
|  | 4480 |  | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4481 | TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4482 | asTransaction([&](Transaction& t) { | 
|  | 4483 | t.show(mChild); | 
|  | 4484 | t.setPosition(mChild, 0, 0); | 
|  | 4485 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4486 | }); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4487 |  | 
|  | 4488 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4489 | mCapture = screenshot(); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4490 | // We've positioned the child in the top left. | 
|  | 4491 | mCapture->expectChildColor(0, 0); | 
|  | 4492 | // But it's only 10x10. | 
|  | 4493 | mCapture->expectFGColor(10, 10); | 
|  | 4494 | } | 
|  | 4495 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4496 | asTransaction([&](Transaction& t) { | 
|  | 4497 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); | 
|  | 4498 | // We cause scaling by 2. | 
|  | 4499 | t.setSize(mFGSurfaceControl, 128, 128); | 
|  | 4500 | }); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4501 |  | 
|  | 4502 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4503 | mCapture = screenshot(); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4504 | // We've positioned the child in the top left. | 
|  | 4505 | mCapture->expectChildColor(0, 0); | 
|  | 4506 | mCapture->expectChildColor(10, 10); | 
|  | 4507 | mCapture->expectChildColor(19, 19); | 
|  | 4508 | // And now it should be scaled all the way to 20x20 | 
|  | 4509 | mCapture->expectFGColor(20, 20); | 
|  | 4510 | } | 
|  | 4511 | } | 
|  | 4512 |  | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4513 | // Regression test for b/37673612 | 
|  | 4514 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4515 | asTransaction([&](Transaction& t) { | 
|  | 4516 | t.show(mChild); | 
|  | 4517 | t.setPosition(mChild, 0, 0); | 
|  | 4518 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4519 | }); | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4520 |  | 
|  | 4521 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4522 | mCapture = screenshot(); | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4523 | // We've positioned the child in the top left. | 
|  | 4524 | mCapture->expectChildColor(0, 0); | 
|  | 4525 | // But it's only 10x10. | 
|  | 4526 | mCapture->expectFGColor(10, 10); | 
|  | 4527 | } | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4528 | // We set things up as in b/37673612 so that there is a mismatch between the buffer size and | 
|  | 4529 | // the WM specified state size. | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4530 | asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); }); | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4531 | sp<Surface> s = mFGSurfaceControl->getSurface(); | 
|  | 4532 | auto anw = static_cast<ANativeWindow*>(s.get()); | 
|  | 4533 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); | 
|  | 4534 | native_window_set_buffers_dimensions(anw, 64, 128); | 
|  | 4535 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 4536 | waitForPostedBuffers(); | 
|  | 4537 |  | 
|  | 4538 | { | 
|  | 4539 | // The child should still be in the same place and not have any strange scaling as in | 
|  | 4540 | // b/37673612. | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4541 | mCapture = screenshot(); | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4542 | mCapture->expectChildColor(0, 0); | 
|  | 4543 | mCapture->expectFGColor(10, 10); | 
|  | 4544 | } | 
|  | 4545 | } | 
|  | 4546 |  | 
| Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 4547 | TEST_F(ChildLayerTest, Bug36858924) { | 
|  | 4548 | // Destroy the child layer | 
|  | 4549 | mChild.clear(); | 
|  | 4550 |  | 
|  | 4551 | // Now recreate it as hidden | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4552 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, | 
|  | 4553 | ISurfaceComposerClient::eHidden, mFGSurfaceControl.get()); | 
| Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 4554 |  | 
|  | 4555 | // Show the child layer in a deferred transaction | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4556 | asTransaction([&](Transaction& t) { | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4557 | t.deferTransactionUntil_legacy(mChild, mFGSurfaceControl->getHandle(), | 
|  | 4558 | mFGSurfaceControl->getSurface()->getNextFrameNumber()); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4559 | t.show(mChild); | 
|  | 4560 | }); | 
| Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 4561 |  | 
|  | 4562 | // Render the foreground surface a few times | 
|  | 4563 | // | 
|  | 4564 | // Prior to the bugfix for b/36858924, this would usually hang while trying to fill the third | 
|  | 4565 | // frame because SurfaceFlinger would never process the deferred transaction and would therefore | 
|  | 4566 | // never acquire/release the first buffer | 
|  | 4567 | ALOGI("Filling 1"); | 
|  | 4568 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); | 
|  | 4569 | ALOGI("Filling 2"); | 
|  | 4570 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 0, 255); | 
|  | 4571 | ALOGI("Filling 3"); | 
|  | 4572 | fillSurfaceRGBA8(mFGSurfaceControl, 255, 0, 0); | 
|  | 4573 | ALOGI("Filling 4"); | 
|  | 4574 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); | 
|  | 4575 | } | 
|  | 4576 |  | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4577 | TEST_F(ChildLayerTest, Reparent) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4578 | asTransaction([&](Transaction& t) { | 
|  | 4579 | t.show(mChild); | 
|  | 4580 | t.setPosition(mChild, 10, 10); | 
|  | 4581 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4582 | }); | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4583 |  | 
|  | 4584 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4585 | mCapture = screenshot(); | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4586 | // Top left of foreground must now be visible | 
|  | 4587 | mCapture->expectFGColor(64, 64); | 
|  | 4588 | // But 10 pixels in we should see the child surface | 
|  | 4589 | mCapture->expectChildColor(74, 74); | 
|  | 4590 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4591 | mCapture->expectFGColor(84, 84); | 
|  | 4592 | } | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4593 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4594 | asTransaction([&](Transaction& t) { t.reparent(mChild, mBGSurfaceControl->getHandle()); }); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4595 |  | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4596 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4597 | mCapture = screenshot(); | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 4598 | mCapture->expectFGColor(64, 64); | 
|  | 4599 | // In reparenting we should have exposed the entire foreground surface. | 
|  | 4600 | mCapture->expectFGColor(74, 74); | 
|  | 4601 | // And the child layer should now begin at 10, 10 (since the BG | 
|  | 4602 | // layer is at (0, 0)). | 
|  | 4603 | mCapture->expectBGColor(9, 9); | 
|  | 4604 | mCapture->expectChildColor(10, 10); | 
|  | 4605 | } | 
|  | 4606 | } | 
|  | 4607 |  | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4608 | TEST_F(ChildLayerTest, ReparentToNoParent) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4609 | asTransaction([&](Transaction& t) { | 
|  | 4610 | t.show(mChild); | 
|  | 4611 | t.setPosition(mChild, 10, 10); | 
|  | 4612 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4613 | }); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4614 |  | 
|  | 4615 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4616 | mCapture = screenshot(); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4617 | // Top left of foreground must now be visible | 
|  | 4618 | mCapture->expectFGColor(64, 64); | 
|  | 4619 | // But 10 pixels in we should see the child surface | 
|  | 4620 | mCapture->expectChildColor(74, 74); | 
|  | 4621 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4622 | mCapture->expectFGColor(84, 84); | 
|  | 4623 | } | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4624 | asTransaction([&](Transaction& t) { t.reparent(mChild, nullptr); }); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4625 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4626 | mCapture = screenshot(); | 
| Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4627 | // The surface should now be offscreen. | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4628 | mCapture->expectFGColor(64, 64); | 
| Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 4629 | mCapture->expectFGColor(74, 74); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4630 | mCapture->expectFGColor(84, 84); | 
|  | 4631 | } | 
|  | 4632 | } | 
|  | 4633 |  | 
|  | 4634 | TEST_F(ChildLayerTest, ReparentFromNoParent) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4635 | sp<SurfaceControl> newSurface = createLayer(String8("New Surface"), 10, 10, 0); | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 4636 | ASSERT_TRUE(newSurface != nullptr); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4637 | ASSERT_TRUE(newSurface->isValid()); | 
|  | 4638 |  | 
|  | 4639 | fillSurfaceRGBA8(newSurface, 63, 195, 63); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4640 | asTransaction([&](Transaction& t) { | 
|  | 4641 | t.hide(mChild); | 
|  | 4642 | t.show(newSurface); | 
|  | 4643 | t.setPosition(newSurface, 10, 10); | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4644 | t.setLayer(newSurface, INT32_MAX - 2); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4645 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4646 | }); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4647 |  | 
|  | 4648 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4649 | mCapture = screenshot(); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4650 | // Top left of foreground must now be visible | 
|  | 4651 | mCapture->expectFGColor(64, 64); | 
|  | 4652 | // At 10, 10 we should see the new surface | 
|  | 4653 | mCapture->checkPixel(10, 10, 63, 195, 63); | 
|  | 4654 | } | 
|  | 4655 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4656 | asTransaction([&](Transaction& t) { t.reparent(newSurface, mFGSurfaceControl->getHandle()); }); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4657 |  | 
|  | 4658 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4659 | mCapture = screenshot(); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 4660 | // newSurface will now be a child of mFGSurface so it will be 10, 10 offset from | 
|  | 4661 | // mFGSurface, putting it at 74, 74. | 
|  | 4662 | mCapture->expectFGColor(64, 64); | 
|  | 4663 | mCapture->checkPixel(74, 74, 63, 195, 63); | 
|  | 4664 | mCapture->expectFGColor(84, 84); | 
|  | 4665 | } | 
|  | 4666 | } | 
|  | 4667 |  | 
| chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 4668 | TEST_F(ChildLayerTest, NestedChildren) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4669 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 10, 10, | 
|  | 4670 | PIXEL_FORMAT_RGBA_8888, 0, mChild.get()); | 
| chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 4671 | fillSurfaceRGBA8(grandchild, 50, 50, 50); | 
|  | 4672 |  | 
|  | 4673 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4674 | mCapture = screenshot(); | 
| chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 4675 | // Expect the grandchild to begin at 64, 64 because it's a child of mChild layer | 
|  | 4676 | // which begins at 64, 64 | 
|  | 4677 | mCapture->checkPixel(64, 64, 50, 50, 50); | 
|  | 4678 | } | 
|  | 4679 | } | 
|  | 4680 |  | 
| Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4681 | TEST_F(ChildLayerTest, ChildLayerRelativeLayer) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4682 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 128, 128, 0); | 
| Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4683 | fillSurfaceRGBA8(relative, 255, 255, 255); | 
|  | 4684 |  | 
|  | 4685 | Transaction t; | 
|  | 4686 | t.setLayer(relative, INT32_MAX) | 
|  | 4687 | .setRelativeLayer(mChild, relative->getHandle(), 1) | 
|  | 4688 | .setPosition(mFGSurfaceControl, 0, 0) | 
|  | 4689 | .apply(true); | 
|  | 4690 |  | 
|  | 4691 | // We expect that the child should have been elevated above our | 
|  | 4692 | // INT_MAX layer even though it's not a child of it. | 
|  | 4693 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4694 | mCapture = screenshot(); | 
| Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4695 | mCapture->expectChildColor(0, 0); | 
|  | 4696 | mCapture->expectChildColor(9, 9); | 
|  | 4697 | mCapture->checkPixel(10, 10, 255, 255, 255); | 
|  | 4698 | } | 
|  | 4699 | } | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4700 | class BoundlessLayerTest : public LayerUpdateTest { | 
|  | 4701 | protected: | 
|  | 4702 | std::unique_ptr<ScreenCapture> mCapture; | 
|  | 4703 | }; | 
|  | 4704 |  | 
|  | 4705 | // Verify setting a size on a buffer layer has no effect. | 
|  | 4706 | TEST_F(BoundlessLayerTest, BufferLayerIgnoresSize) { | 
|  | 4707 | sp<SurfaceControl> bufferLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4708 | createSurface(mClient, "BufferLayer", 45, 45, PIXEL_FORMAT_RGBA_8888, 0, | 
|  | 4709 | mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4710 | ASSERT_TRUE(bufferLayer->isValid()); | 
|  | 4711 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::BLACK, 30, 30)); | 
|  | 4712 | asTransaction([&](Transaction& t) { t.show(bufferLayer); }); | 
|  | 4713 | { | 
|  | 4714 | mCapture = screenshot(); | 
|  | 4715 | // Top left of background must now be visible | 
|  | 4716 | mCapture->expectBGColor(0, 0); | 
|  | 4717 | // Foreground Surface bounds must be color layer | 
|  | 4718 | mCapture->expectColor(Rect(64, 64, 94, 94), Color::BLACK); | 
|  | 4719 | // Buffer layer should not extend past buffer bounds | 
|  | 4720 | mCapture->expectFGColor(95, 95); | 
|  | 4721 | } | 
|  | 4722 | } | 
|  | 4723 |  | 
|  | 4724 | // Verify a boundless color layer will fill its parent bounds. The parent has a buffer size | 
|  | 4725 | // which will crop the color layer. | 
|  | 4726 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentBufferBounds) { | 
|  | 4727 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4728 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4729 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4730 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 4731 | asTransaction([&](Transaction& t) { | 
|  | 4732 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 4733 | t.show(colorLayer); | 
|  | 4734 | }); | 
|  | 4735 | { | 
|  | 4736 | mCapture = screenshot(); | 
|  | 4737 | // Top left of background must now be visible | 
|  | 4738 | mCapture->expectBGColor(0, 0); | 
|  | 4739 | // Foreground Surface bounds must be color layer | 
|  | 4740 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); | 
|  | 4741 | // Color layer should not extend past foreground bounds | 
|  | 4742 | mCapture->expectBGColor(129, 129); | 
|  | 4743 | } | 
|  | 4744 | } | 
|  | 4745 |  | 
|  | 4746 | // Verify a boundless color layer will fill its parent bounds. The parent has no buffer but has | 
|  | 4747 | // a crop which will be used to crop the color layer. | 
|  | 4748 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentCropBounds) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4749 | sp<SurfaceControl> cropLayer = createSurface(mClient, "CropLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4750 | 0 /* flags */, mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4751 | ASSERT_TRUE(cropLayer->isValid()); | 
|  | 4752 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4753 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4754 | ISurfaceComposerClient::eFXSurfaceColor, cropLayer.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4755 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 4756 | asTransaction([&](Transaction& t) { | 
|  | 4757 | t.setCrop_legacy(cropLayer, Rect(5, 5, 10, 10)); | 
|  | 4758 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 4759 | t.show(cropLayer); | 
|  | 4760 | t.show(colorLayer); | 
|  | 4761 | }); | 
|  | 4762 | { | 
|  | 4763 | mCapture = screenshot(); | 
|  | 4764 | // Top left of background must now be visible | 
|  | 4765 | mCapture->expectBGColor(0, 0); | 
|  | 4766 | // Top left of foreground must now be visible | 
|  | 4767 | mCapture->expectFGColor(64, 64); | 
|  | 4768 | // 5 pixels from the foreground we should see the child surface | 
|  | 4769 | mCapture->expectColor(Rect(69, 69, 74, 74), Color::BLACK); | 
|  | 4770 | // 10 pixels from the foreground we should be back to the foreground surface | 
|  | 4771 | mCapture->expectFGColor(74, 74); | 
|  | 4772 | } | 
|  | 4773 | } | 
|  | 4774 |  | 
|  | 4775 | // Verify for boundless layer with no children, their transforms have no effect. | 
|  | 4776 | TEST_F(BoundlessLayerTest, BoundlessColorLayerTransformHasNoEffect) { | 
|  | 4777 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4778 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4779 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4780 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 4781 | asTransaction([&](Transaction& t) { | 
|  | 4782 | t.setPosition(colorLayer, 320, 320); | 
|  | 4783 | t.setMatrix(colorLayer, 2, 0, 0, 2); | 
|  | 4784 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 4785 | t.show(colorLayer); | 
|  | 4786 | }); | 
|  | 4787 | { | 
|  | 4788 | mCapture = screenshot(); | 
|  | 4789 | // Top left of background must now be visible | 
|  | 4790 | mCapture->expectBGColor(0, 0); | 
|  | 4791 | // Foreground Surface bounds must be color layer | 
|  | 4792 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); | 
|  | 4793 | // Color layer should not extend past foreground bounds | 
|  | 4794 | mCapture->expectBGColor(129, 129); | 
|  | 4795 | } | 
|  | 4796 | } | 
|  | 4797 |  | 
|  | 4798 | // Verify for boundless layer with children, their transforms have an effect. | 
|  | 4799 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerCanSetTransform) { | 
|  | 4800 | sp<SurfaceControl> boundlessLayerRightShift = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4801 | createSurface(mClient, "BoundlessLayerRightShift", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4802 | 0 /* flags */, mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4803 | ASSERT_TRUE(boundlessLayerRightShift->isValid()); | 
|  | 4804 | sp<SurfaceControl> boundlessLayerDownShift = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4805 | createSurface(mClient, "BoundlessLayerLeftShift", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4806 | 0 /* flags */, boundlessLayerRightShift.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4807 | ASSERT_TRUE(boundlessLayerDownShift->isValid()); | 
|  | 4808 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4809 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4810 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayerDownShift.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4811 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 4812 | asTransaction([&](Transaction& t) { | 
|  | 4813 | t.setPosition(boundlessLayerRightShift, 32, 0); | 
|  | 4814 | t.show(boundlessLayerRightShift); | 
|  | 4815 | t.setPosition(boundlessLayerDownShift, 0, 32); | 
|  | 4816 | t.show(boundlessLayerDownShift); | 
|  | 4817 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); | 
|  | 4818 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 4819 | t.show(colorLayer); | 
|  | 4820 | }); | 
|  | 4821 | { | 
|  | 4822 | mCapture = screenshot(); | 
|  | 4823 | // Top left of background must now be visible | 
|  | 4824 | mCapture->expectBGColor(0, 0); | 
|  | 4825 | // Top left of foreground must now be visible | 
|  | 4826 | mCapture->expectFGColor(64, 64); | 
|  | 4827 | // Foreground Surface bounds must be color layer | 
|  | 4828 | mCapture->expectColor(Rect(96, 96, 128, 128), Color::BLACK); | 
|  | 4829 | // Color layer should not extend past foreground bounds | 
|  | 4830 | mCapture->expectBGColor(129, 129); | 
|  | 4831 | } | 
|  | 4832 | } | 
|  | 4833 |  | 
|  | 4834 | // Verify child layers do not get clipped if they temporarily move into the negative | 
|  | 4835 | // coordinate space as the result of an intermediate transformation. | 
|  | 4836 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerDoNotCrop) { | 
|  | 4837 | sp<SurfaceControl> boundlessLayer = | 
|  | 4838 | mClient->createSurface(String8("BoundlessLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4839 | 0 /* flags */, mFGSurfaceControl.get()); | 
|  | 4840 | ASSERT_TRUE(boundlessLayer != nullptr); | 
|  | 4841 | ASSERT_TRUE(boundlessLayer->isValid()); | 
|  | 4842 | sp<SurfaceControl> colorLayer = | 
|  | 4843 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4844 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayer.get()); | 
|  | 4845 | ASSERT_TRUE(colorLayer != nullptr); | 
|  | 4846 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 4847 | asTransaction([&](Transaction& t) { | 
|  | 4848 | // shift child layer off bounds. If this layer was not boundless, we will | 
|  | 4849 | // expect the child layer to be cropped. | 
|  | 4850 | t.setPosition(boundlessLayer, 32, 32); | 
|  | 4851 | t.show(boundlessLayer); | 
|  | 4852 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); | 
|  | 4853 | // undo shift by parent | 
|  | 4854 | t.setPosition(colorLayer, -32, -32); | 
|  | 4855 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 4856 | t.show(colorLayer); | 
|  | 4857 | }); | 
|  | 4858 | { | 
|  | 4859 | mCapture = screenshot(); | 
|  | 4860 | // Top left of background must now be visible | 
|  | 4861 | mCapture->expectBGColor(0, 0); | 
|  | 4862 | // Foreground Surface bounds must be color layer | 
|  | 4863 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); | 
|  | 4864 | // Color layer should not extend past foreground bounds | 
|  | 4865 | mCapture->expectBGColor(129, 129); | 
|  | 4866 | } | 
|  | 4867 | } | 
|  | 4868 |  | 
|  | 4869 | // Verify for boundless root layers with children, their transforms have an effect. | 
|  | 4870 | TEST_F(BoundlessLayerTest, RootBoundlessLayerCanSetTransform) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4871 | sp<SurfaceControl> rootBoundlessLayer = createSurface(mClient, "RootBoundlessLayer", 0, 0, | 
|  | 4872 | PIXEL_FORMAT_RGBA_8888, 0 /* flags */); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4873 | ASSERT_TRUE(rootBoundlessLayer->isValid()); | 
|  | 4874 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4875 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 4876 | ISurfaceComposerClient::eFXSurfaceColor, rootBoundlessLayer.get()); | 
|  | 4877 |  | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4878 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 4879 | asTransaction([&](Transaction& t) { | 
|  | 4880 | t.setLayer(rootBoundlessLayer, INT32_MAX - 1); | 
|  | 4881 | t.setPosition(rootBoundlessLayer, 32, 32); | 
|  | 4882 | t.show(rootBoundlessLayer); | 
|  | 4883 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); | 
|  | 4884 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 4885 | t.show(colorLayer); | 
|  | 4886 | t.hide(mFGSurfaceControl); | 
|  | 4887 | }); | 
|  | 4888 | { | 
|  | 4889 | mCapture = screenshot(); | 
|  | 4890 | // Top left of background must now be visible | 
|  | 4891 | mCapture->expectBGColor(0, 0); | 
|  | 4892 | // Top left of foreground must now be visible | 
|  | 4893 | mCapture->expectBGColor(31, 31); | 
|  | 4894 | // Foreground Surface bounds must be color layer | 
|  | 4895 | mCapture->expectColor(Rect(32, 32, 96, 96), Color::BLACK); | 
|  | 4896 | // Color layer should not extend past foreground bounds | 
|  | 4897 | mCapture->expectBGColor(97, 97); | 
|  | 4898 | } | 
|  | 4899 | } | 
| Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 4900 |  | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4901 | class ScreenCaptureTest : public LayerUpdateTest { | 
|  | 4902 | protected: | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4903 | std::unique_ptr<ScreenCapture> mCapture; | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4904 | }; | 
|  | 4905 |  | 
|  | 4906 | TEST_F(ScreenCaptureTest, CaptureSingleLayer) { | 
|  | 4907 | auto bgHandle = mBGSurfaceControl->getHandle(); | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4908 | ScreenCapture::captureLayers(&mCapture, bgHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4909 | mCapture->expectBGColor(0, 0); | 
|  | 4910 | // Doesn't capture FG layer which is at 64, 64 | 
|  | 4911 | mCapture->expectBGColor(64, 64); | 
|  | 4912 | } | 
|  | 4913 |  | 
|  | 4914 | TEST_F(ScreenCaptureTest, CaptureLayerWithChild) { | 
|  | 4915 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 4916 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4917 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 4918 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4919 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 4920 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4921 | SurfaceComposerClient::Transaction().show(child).apply(true); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4922 |  | 
|  | 4923 | // Captures mFGSurfaceControl layer and its child. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4924 | ScreenCapture::captureLayers(&mCapture, fgHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4925 | mCapture->expectFGColor(10, 10); | 
|  | 4926 | mCapture->expectChildColor(0, 0); | 
|  | 4927 | } | 
|  | 4928 |  | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 4929 | TEST_F(ScreenCaptureTest, CaptureLayerChildOnly) { | 
|  | 4930 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 4931 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4932 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 4933 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 4934 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 4935 |  | 
|  | 4936 | SurfaceComposerClient::Transaction().show(child).apply(true); | 
|  | 4937 |  | 
|  | 4938 | // Captures mFGSurfaceControl's child | 
|  | 4939 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); | 
|  | 4940 | mCapture->checkPixel(10, 10, 0, 0, 0); | 
|  | 4941 | mCapture->expectChildColor(0, 0); | 
|  | 4942 | } | 
|  | 4943 |  | 
| chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 4944 | TEST_F(ScreenCaptureTest, CaptureTransparent) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4945 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 4946 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 4947 |  | 
|  | 4948 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 4949 |  | 
|  | 4950 | SurfaceComposerClient::Transaction().show(child).apply(true); | 
|  | 4951 |  | 
|  | 4952 | auto childHandle = child->getHandle(); | 
|  | 4953 |  | 
|  | 4954 | // Captures child | 
|  | 4955 | ScreenCapture::captureLayers(&mCapture, childHandle, {0, 0, 10, 20}); | 
|  | 4956 | mCapture->expectColor(Rect(0, 0, 9, 9), {200, 200, 200, 255}); | 
|  | 4957 | // Area outside of child's bounds is transparent. | 
|  | 4958 | mCapture->expectColor(Rect(0, 10, 9, 19), {0, 0, 0, 0}); | 
|  | 4959 | } | 
|  | 4960 |  | 
| chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 4961 | TEST_F(ScreenCaptureTest, DontCaptureRelativeOutsideTree) { | 
|  | 4962 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 4963 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4964 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 4965 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 4966 | ASSERT_NE(nullptr, child.get()) << "failed to create surface"; | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4967 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 10, 10, 0); | 
| chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 4968 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 4969 | fillSurfaceRGBA8(relative, 100, 100, 100); | 
|  | 4970 |  | 
|  | 4971 | SurfaceComposerClient::Transaction() | 
|  | 4972 | .show(child) | 
|  | 4973 | // Set relative layer above fg layer so should be shown above when computing all layers. | 
|  | 4974 | .setRelativeLayer(relative, fgHandle, 1) | 
|  | 4975 | .show(relative) | 
|  | 4976 | .apply(true); | 
|  | 4977 |  | 
|  | 4978 | // Captures mFGSurfaceControl layer and its child. Relative layer shouldn't be captured. | 
|  | 4979 | ScreenCapture::captureLayers(&mCapture, fgHandle); | 
|  | 4980 | mCapture->expectFGColor(10, 10); | 
|  | 4981 | mCapture->expectChildColor(0, 0); | 
|  | 4982 | } | 
|  | 4983 |  | 
|  | 4984 | TEST_F(ScreenCaptureTest, CaptureRelativeInTree) { | 
|  | 4985 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 4986 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4987 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 4988 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 4989 | sp<SurfaceControl> relative = createSurface(mClient, "Relative surface", 10, 10, | 
|  | 4990 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 4991 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 4992 | fillSurfaceRGBA8(relative, 100, 100, 100); | 
|  | 4993 |  | 
|  | 4994 | SurfaceComposerClient::Transaction() | 
|  | 4995 | .show(child) | 
|  | 4996 | // Set relative layer below fg layer but relative to child layer so it should be shown | 
|  | 4997 | // above child layer. | 
|  | 4998 | .setLayer(relative, -1) | 
|  | 4999 | .setRelativeLayer(relative, child->getHandle(), 1) | 
|  | 5000 | .show(relative) | 
|  | 5001 | .apply(true); | 
|  | 5002 |  | 
|  | 5003 | // Captures mFGSurfaceControl layer and its children. Relative layer is a child of fg so its | 
|  | 5004 | // relative value should be taken into account, placing it above child layer. | 
|  | 5005 | ScreenCapture::captureLayers(&mCapture, fgHandle); | 
|  | 5006 | mCapture->expectFGColor(10, 10); | 
|  | 5007 | // Relative layer is showing on top of child layer | 
|  | 5008 | mCapture->expectColor(Rect(0, 0, 9, 9), {100, 100, 100, 255}); | 
|  | 5009 | } | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5010 |  | 
|  | 5011 | // In the following tests we verify successful skipping of a parent layer, | 
|  | 5012 | // so we use the same verification logic and only change how we mutate | 
|  | 5013 | // the parent layer to verify that various properties are ignored. | 
|  | 5014 | class ScreenCaptureChildOnlyTest : public LayerUpdateTest { | 
|  | 5015 | public: | 
|  | 5016 | void SetUp() override { | 
|  | 5017 | LayerUpdateTest::SetUp(); | 
|  | 5018 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5019 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, | 
|  | 5020 | mFGSurfaceControl.get()); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5021 | fillSurfaceRGBA8(mChild, 200, 200, 200); | 
|  | 5022 |  | 
|  | 5023 | SurfaceComposerClient::Transaction().show(mChild).apply(true); | 
|  | 5024 | } | 
|  | 5025 |  | 
|  | 5026 | void verify() { | 
|  | 5027 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5028 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); | 
|  | 5029 | mCapture->checkPixel(10, 10, 0, 0, 0); | 
|  | 5030 | mCapture->expectChildColor(0, 0); | 
|  | 5031 | } | 
|  | 5032 |  | 
|  | 5033 | std::unique_ptr<ScreenCapture> mCapture; | 
|  | 5034 | sp<SurfaceControl> mChild; | 
|  | 5035 | }; | 
|  | 5036 |  | 
|  | 5037 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentVisibility) { | 
|  | 5038 |  | 
|  | 5039 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); | 
|  | 5040 |  | 
|  | 5041 | // Even though the parent is hidden we should still capture the child. | 
|  | 5042 | verify(); | 
|  | 5043 | } | 
|  | 5044 |  | 
|  | 5045 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentCrop) { | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 5046 | SurfaceComposerClient::Transaction() | 
|  | 5047 | .setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 1, 1)) | 
|  | 5048 | .apply(true); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5049 |  | 
|  | 5050 | // Even though the parent is cropped out we should still capture the child. | 
|  | 5051 | verify(); | 
|  | 5052 | } | 
|  | 5053 |  | 
|  | 5054 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresTransform) { | 
|  | 5055 |  | 
|  | 5056 | SurfaceComposerClient::Transaction().setMatrix(mFGSurfaceControl, 2, 0, 0, 2); | 
|  | 5057 |  | 
|  | 5058 | // We should not inherit the parent scaling. | 
|  | 5059 | verify(); | 
|  | 5060 | } | 
|  | 5061 |  | 
| Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 5062 | TEST_F(ScreenCaptureChildOnlyTest, RegressionTest76099859) { | 
|  | 5063 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); | 
|  | 5064 |  | 
|  | 5065 | // Even though the parent is hidden we should still capture the child. | 
|  | 5066 | verify(); | 
|  | 5067 |  | 
|  | 5068 | // Verify everything was properly hidden when rendering the full-screen. | 
|  | 5069 | screenshot()->expectBGColor(0,0); | 
|  | 5070 | } | 
|  | 5071 |  | 
|  | 5072 |  | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5073 | TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) { | 
|  | 5074 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5075 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5076 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5077 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5078 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5079 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5080 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, | 
|  | 5081 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5082 |  | 
|  | 5083 | fillSurfaceRGBA8(grandchild, 50, 50, 50); | 
|  | 5084 | SurfaceComposerClient::Transaction() | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5085 | .show(child) | 
|  | 5086 | .setPosition(grandchild, 5, 5) | 
|  | 5087 | .show(grandchild) | 
|  | 5088 | .apply(true); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5089 |  | 
|  | 5090 | // Captures mFGSurfaceControl, its child, and the grandchild. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5091 | ScreenCapture::captureLayers(&mCapture, fgHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5092 | mCapture->expectFGColor(10, 10); | 
|  | 5093 | mCapture->expectChildColor(0, 0); | 
|  | 5094 | mCapture->checkPixel(5, 5, 50, 50, 50); | 
|  | 5095 | } | 
|  | 5096 |  | 
|  | 5097 | TEST_F(ScreenCaptureTest, CaptureChildOnly) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5098 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5099 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5100 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5101 | auto childHandle = child->getHandle(); | 
|  | 5102 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5103 | SurfaceComposerClient::Transaction().setPosition(child, 5, 5).show(child).apply(true); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5104 |  | 
|  | 5105 | // Captures only the child layer, and not the parent. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5106 | ScreenCapture::captureLayers(&mCapture, childHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5107 | mCapture->expectChildColor(0, 0); | 
|  | 5108 | mCapture->expectChildColor(9, 9); | 
|  | 5109 | } | 
|  | 5110 |  | 
|  | 5111 | TEST_F(ScreenCaptureTest, CaptureGrandchildOnly) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5112 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5113 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5114 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5115 | auto childHandle = child->getHandle(); | 
|  | 5116 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5117 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, | 
|  | 5118 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5119 | fillSurfaceRGBA8(grandchild, 50, 50, 50); | 
|  | 5120 |  | 
|  | 5121 | SurfaceComposerClient::Transaction() | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5122 | .show(child) | 
|  | 5123 | .setPosition(grandchild, 5, 5) | 
|  | 5124 | .show(grandchild) | 
|  | 5125 | .apply(true); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5126 |  | 
|  | 5127 | auto grandchildHandle = grandchild->getHandle(); | 
|  | 5128 |  | 
|  | 5129 | // Captures only the grandchild. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5130 | ScreenCapture::captureLayers(&mCapture, grandchildHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5131 | mCapture->checkPixel(0, 0, 50, 50, 50); | 
|  | 5132 | mCapture->checkPixel(4, 4, 50, 50, 50); | 
|  | 5133 | } | 
|  | 5134 |  | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5135 | TEST_F(ScreenCaptureTest, CaptureCrop) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5136 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5137 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, | 
|  | 5138 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5139 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5140 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); | 
|  | 5141 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5142 |  | 
|  | 5143 | SurfaceComposerClient::Transaction() | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5144 | .setLayer(redLayer, INT32_MAX - 1) | 
|  | 5145 | .show(redLayer) | 
|  | 5146 | .show(blueLayer) | 
|  | 5147 | .apply(true); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5148 |  | 
|  | 5149 | auto redLayerHandle = redLayer->getHandle(); | 
|  | 5150 |  | 
|  | 5151 | // Capturing full screen should have both red and blue are visible. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5152 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); | 
|  | 5153 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); | 
|  | 5154 | // red area below the blue area | 
|  | 5155 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); | 
|  | 5156 | // red area to the right of the blue area | 
|  | 5157 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5158 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 5159 | const Rect crop = Rect(0, 0, 30, 30); | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5160 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, crop); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5161 | // Capturing the cropped screen, cropping out the shown red area, should leave only the blue | 
|  | 5162 | // area visible. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5163 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5164 | mCapture->checkPixel(30, 30, 0, 0, 0); | 
|  | 5165 | } | 
|  | 5166 |  | 
|  | 5167 | TEST_F(ScreenCaptureTest, CaptureSize) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5168 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5169 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, | 
|  | 5170 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5171 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5172 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); | 
|  | 5173 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5174 |  | 
|  | 5175 | SurfaceComposerClient::Transaction() | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5176 | .setLayer(redLayer, INT32_MAX - 1) | 
|  | 5177 | .show(redLayer) | 
|  | 5178 | .show(blueLayer) | 
|  | 5179 | .apply(true); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5180 |  | 
|  | 5181 | auto redLayerHandle = redLayer->getHandle(); | 
|  | 5182 |  | 
|  | 5183 | // Capturing full screen should have both red and blue are visible. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5184 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); | 
|  | 5185 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); | 
|  | 5186 | // red area below the blue area | 
|  | 5187 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); | 
|  | 5188 | // red area to the right of the blue area | 
|  | 5189 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5190 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5191 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, Rect::EMPTY_RECT, 0.5); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5192 | // 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] | 5193 | mCapture->expectColor(Rect(0, 0, 14, 14), Color::BLUE); | 
|  | 5194 | // red area below the blue area | 
|  | 5195 | mCapture->expectColor(Rect(0, 15, 29, 29), Color::RED); | 
|  | 5196 | // red area to the right of the blue area | 
|  | 5197 | mCapture->expectColor(Rect(15, 0, 29, 29), Color::RED); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5198 | mCapture->checkPixel(30, 30, 0, 0, 0); | 
|  | 5199 | } | 
|  | 5200 |  | 
|  | 5201 | TEST_F(ScreenCaptureTest, CaptureInvalidLayer) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5202 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5203 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5204 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5205 |  | 
|  | 5206 | auto redLayerHandle = redLayer->getHandle(); | 
| Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5207 | redLayer->clear(); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5208 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 5209 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5210 | sp<GraphicBuffer> outBuffer; | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5211 |  | 
|  | 5212 | // Layer was deleted so captureLayers should fail with NAME_NOT_FOUND | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5213 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
|  | 5214 | 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] | 5215 | } | 
|  | 5216 |  | 
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5217 |  | 
|  | 5218 | class DereferenceSurfaceControlTest : public LayerTransactionTest { | 
|  | 5219 | protected: | 
|  | 5220 | void SetUp() override { | 
|  | 5221 | LayerTransactionTest::SetUp(); | 
|  | 5222 | bgLayer = createLayer("BG layer", 20, 20); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5223 | fillBufferQueueLayerColor(bgLayer, Color::RED, 20, 20); | 
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5224 | fgLayer = createLayer("FG layer", 20, 20); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5225 | fillBufferQueueLayerColor(fgLayer, Color::BLUE, 20, 20); | 
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5226 | Transaction().setLayer(fgLayer, mLayerZBase + 1).apply(); | 
|  | 5227 | { | 
|  | 5228 | SCOPED_TRACE("before anything"); | 
|  | 5229 | auto shot = screenshot(); | 
|  | 5230 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); | 
|  | 5231 | } | 
|  | 5232 | } | 
|  | 5233 | void TearDown() override { | 
|  | 5234 | LayerTransactionTest::TearDown(); | 
|  | 5235 | bgLayer = 0; | 
|  | 5236 | fgLayer = 0; | 
|  | 5237 | } | 
|  | 5238 |  | 
|  | 5239 | sp<SurfaceControl> bgLayer; | 
|  | 5240 | sp<SurfaceControl> fgLayer; | 
|  | 5241 | }; | 
|  | 5242 |  | 
|  | 5243 | TEST_F(DereferenceSurfaceControlTest, LayerNotInTransaction) { | 
|  | 5244 | fgLayer = nullptr; | 
|  | 5245 | { | 
|  | 5246 | SCOPED_TRACE("after setting null"); | 
|  | 5247 | auto shot = screenshot(); | 
|  | 5248 | shot->expectColor(Rect(0, 0, 20, 20), Color::RED); | 
|  | 5249 | } | 
|  | 5250 | } | 
|  | 5251 |  | 
|  | 5252 | TEST_F(DereferenceSurfaceControlTest, LayerInTransaction) { | 
|  | 5253 | auto transaction = Transaction().show(fgLayer); | 
|  | 5254 | fgLayer = nullptr; | 
|  | 5255 | { | 
|  | 5256 | SCOPED_TRACE("after setting null"); | 
|  | 5257 | auto shot = screenshot(); | 
|  | 5258 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); | 
|  | 5259 | } | 
|  | 5260 | } | 
|  | 5261 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5262 | } // namespace android |