| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2011 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 17 | #include <algorithm> | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 18 | #include <chrono> | 
|  | 19 | #include <cinttypes> | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 20 | #include <functional> | 
|  | 21 | #include <limits> | 
|  | 22 | #include <ostream> | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 23 | #include <thread> | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 24 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 25 | #include <gtest/gtest.h> | 
|  | 26 |  | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 27 | #include <android/native_window.h> | 
|  | 28 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 29 | #include <binder/ProcessState.h> | 
|  | 30 | #include <gui/BufferItemConsumer.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 31 | #include <gui/ISurfaceComposer.h> | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 32 | #include <gui/LayerState.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 33 | #include <gui/Surface.h> | 
|  | 34 | #include <gui/SurfaceComposerClient.h> | 
| Ady Abraham | df9df4a | 2019-03-12 17:32:05 -0700 | [diff] [blame] | 35 | #include <hardware/hwcomposer_defs.h> | 
| Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 36 | #include <private/android_filesystem_config.h> | 
| Ady Abraham | df9df4a | 2019-03-12 17:32:05 -0700 | [diff] [blame] | 37 | #include <private/gui/ComposerService.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 38 |  | 
| Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 39 | #include <ui/ColorSpace.h> | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 40 | #include <ui/DisplayInfo.h> | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 41 | #include <ui/Rect.h> | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 42 | #include <utils/String8.h> | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 43 |  | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 44 | #include <math.h> | 
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 45 | #include <math/vec3.h> | 
| Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 46 | #include <sys/types.h> | 
|  | 47 | #include <unistd.h> | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 48 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 49 | #include "BufferGenerator.h" | 
|  | 50 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 51 | namespace android { | 
|  | 52 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 53 | namespace { | 
|  | 54 |  | 
|  | 55 | struct Color { | 
|  | 56 | uint8_t r; | 
|  | 57 | uint8_t g; | 
|  | 58 | uint8_t b; | 
|  | 59 | uint8_t a; | 
|  | 60 |  | 
|  | 61 | static const Color RED; | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 62 | static const Color GREEN; | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 63 | static const Color BLUE; | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 64 | static const Color WHITE; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 65 | static const Color BLACK; | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 66 | static const Color TRANSPARENT; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 67 | }; | 
|  | 68 |  | 
|  | 69 | const Color Color::RED{255, 0, 0, 255}; | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 70 | const Color Color::GREEN{0, 255, 0, 255}; | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 71 | const Color Color::BLUE{0, 0, 255, 255}; | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 72 | const Color Color::WHITE{255, 255, 255, 255}; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 73 | const Color Color::BLACK{0, 0, 0, 255}; | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 74 | const Color Color::TRANSPARENT{0, 0, 0, 0}; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 75 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 76 | using android::hardware::graphics::common::V1_1::BufferUsage; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 77 | using namespace std::chrono_literals; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 78 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 79 | std::ostream& operator<<(std::ostream& os, const Color& color) { | 
|  | 80 | os << int(color.r) << ", " << int(color.g) << ", " << int(color.b) << ", " << int(color.a); | 
|  | 81 | return os; | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | // Fill a region with the specified color. | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 85 | void fillANativeWindowBufferColor(const ANativeWindow_Buffer& buffer, const Rect& rect, | 
|  | 86 | const Color& color) { | 
|  | 87 | Rect r(0, 0, buffer.width, buffer.height); | 
|  | 88 | if (!r.intersect(rect, &r)) { | 
|  | 89 | return; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 90 | } | 
|  | 91 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 92 | int32_t width = r.right - r.left; | 
|  | 93 | int32_t height = r.bottom - r.top; | 
|  | 94 |  | 
|  | 95 | for (int32_t row = 0; row < height; row++) { | 
|  | 96 | uint8_t* dst = | 
|  | 97 | static_cast<uint8_t*>(buffer.bits) + (buffer.stride * (r.top + row) + r.left) * 4; | 
|  | 98 | for (int32_t column = 0; column < width; column++) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 99 | dst[0] = color.r; | 
|  | 100 | dst[1] = color.g; | 
|  | 101 | dst[2] = color.b; | 
|  | 102 | dst[3] = color.a; | 
|  | 103 | dst += 4; | 
|  | 104 | } | 
|  | 105 | } | 
|  | 106 | } | 
|  | 107 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 108 | // Fill a region with the specified color. | 
|  | 109 | void fillGraphicBufferColor(const sp<GraphicBuffer>& buffer, const Rect& rect, const Color& color) { | 
|  | 110 | Rect r(0, 0, buffer->width, buffer->height); | 
|  | 111 | if (!r.intersect(rect, &r)) { | 
|  | 112 | return; | 
|  | 113 | } | 
|  | 114 |  | 
|  | 115 | int32_t width = r.right - r.left; | 
|  | 116 | int32_t height = r.bottom - r.top; | 
|  | 117 |  | 
|  | 118 | uint8_t* pixels; | 
|  | 119 | buffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, | 
|  | 120 | reinterpret_cast<void**>(&pixels)); | 
|  | 121 |  | 
|  | 122 | for (int32_t row = 0; row < height; row++) { | 
|  | 123 | uint8_t* dst = pixels + (buffer->getStride() * (r.top + row) + r.left) * 4; | 
|  | 124 | for (int32_t column = 0; column < width; column++) { | 
|  | 125 | dst[0] = color.r; | 
|  | 126 | dst[1] = color.g; | 
|  | 127 | dst[2] = color.b; | 
|  | 128 | dst[3] = color.a; | 
|  | 129 | dst += 4; | 
|  | 130 | } | 
|  | 131 | } | 
|  | 132 | buffer->unlock(); | 
|  | 133 | } | 
|  | 134 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 135 | // Check if a region has the specified color. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 136 | void expectBufferColor(const sp<GraphicBuffer>& outBuffer, uint8_t* pixels, const Rect& rect, | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 137 | const Color& color, uint8_t tolerance) { | 
|  | 138 | int32_t x = rect.left; | 
|  | 139 | int32_t y = rect.top; | 
|  | 140 | int32_t width = rect.right - rect.left; | 
|  | 141 | int32_t height = rect.bottom - rect.top; | 
|  | 142 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 143 | int32_t bufferWidth = int32_t(outBuffer->getWidth()); | 
|  | 144 | int32_t bufferHeight = int32_t(outBuffer->getHeight()); | 
|  | 145 | if (x + width > bufferWidth) { | 
|  | 146 | x = std::min(x, bufferWidth); | 
|  | 147 | width = bufferWidth - x; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 148 | } | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 149 | if (y + height > bufferHeight) { | 
|  | 150 | y = std::min(y, bufferHeight); | 
|  | 151 | height = bufferHeight - y; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 152 | } | 
|  | 153 |  | 
|  | 154 | auto colorCompare = [tolerance](uint8_t a, uint8_t b) { | 
|  | 155 | uint8_t tmp = a >= b ? a - b : b - a; | 
|  | 156 | return tmp <= tolerance; | 
|  | 157 | }; | 
|  | 158 | for (int32_t j = 0; j < height; j++) { | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 159 | const uint8_t* src = pixels + (outBuffer->getStride() * (y + j) + x) * 4; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 160 | for (int32_t i = 0; i < width; i++) { | 
|  | 161 | const uint8_t expected[4] = {color.r, color.g, color.b, color.a}; | 
|  | 162 | EXPECT_TRUE(std::equal(src, src + 4, expected, colorCompare)) | 
|  | 163 | << "pixel @ (" << x + i << ", " << y + j << "): " | 
|  | 164 | << "expected (" << color << "), " | 
|  | 165 | << "got (" << Color{src[0], src[1], src[2], src[3]} << ")"; | 
|  | 166 | src += 4; | 
|  | 167 | } | 
|  | 168 | } | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 | } // anonymous namespace | 
|  | 172 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 173 | using Transaction = SurfaceComposerClient::Transaction; | 
|  | 174 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 175 | // Fill an RGBA_8888 formatted surface with a single color. | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 176 | static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, uint8_t r, uint8_t g, uint8_t b, | 
|  | 177 | bool unlock = true) { | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 178 | ANativeWindow_Buffer outBuffer; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 179 | sp<Surface> s = sc->getSurface(); | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 180 | ASSERT_TRUE(s != nullptr); | 
|  | 181 | ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, nullptr)); | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 182 | uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 183 | for (int y = 0; y < outBuffer.height; y++) { | 
|  | 184 | for (int x = 0; x < outBuffer.width; x++) { | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 185 | uint8_t* pixel = img + (4 * (y * outBuffer.stride + x)); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 186 | pixel[0] = r; | 
|  | 187 | pixel[1] = g; | 
|  | 188 | pixel[2] = b; | 
|  | 189 | pixel[3] = 255; | 
|  | 190 | } | 
|  | 191 | } | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 192 | if (unlock) { | 
|  | 193 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); | 
|  | 194 | } | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 195 | } | 
|  | 196 |  | 
|  | 197 | // A ScreenCapture is a screenshot from SurfaceFlinger that can be used to check | 
|  | 198 | // individual pixel values for testing purposes. | 
|  | 199 | class ScreenCapture : public RefBase { | 
|  | 200 | public: | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 201 | static void captureScreen(std::unique_ptr<ScreenCapture>* sc) { | 
| Vishnu Nair | b927e1f | 2019-02-19 13:36:15 -0800 | [diff] [blame] | 202 | captureScreen(sc, SurfaceComposerClient::getInternalDisplayToken()); | 
|  | 203 | } | 
|  | 204 |  | 
|  | 205 | static void captureScreen(std::unique_ptr<ScreenCapture>* sc, sp<IBinder> displayToken) { | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 206 | const auto sf = ComposerService::getComposerService(); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 207 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 208 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 209 | sp<GraphicBuffer> outBuffer; | 
| Vishnu Nair | b927e1f | 2019-02-19 13:36:15 -0800 | [diff] [blame] | 210 | ASSERT_EQ(NO_ERROR, sf->captureScreen(displayToken, &outBuffer, Rect(), 0, 0, false)); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 211 | *sc = std::make_unique<ScreenCapture>(outBuffer); | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 212 | } | 
|  | 213 |  | 
|  | 214 | static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, | 
|  | 215 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { | 
|  | 216 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
|  | 217 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 218 |  | 
|  | 219 | sp<GraphicBuffer> outBuffer; | 
|  | 220 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale)); | 
|  | 221 | *sc = std::make_unique<ScreenCapture>(outBuffer); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 222 | } | 
|  | 223 |  | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 224 | static void captureChildLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, | 
|  | 225 | Rect crop = Rect::EMPTY_RECT, float frameScale = 1.0) { | 
|  | 226 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
|  | 227 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 228 |  | 
|  | 229 | sp<GraphicBuffer> outBuffer; | 
|  | 230 | ASSERT_EQ(NO_ERROR, sf->captureLayers(parentHandle, &outBuffer, crop, frameScale, true)); | 
|  | 231 | *sc = std::make_unique<ScreenCapture>(outBuffer); | 
|  | 232 | } | 
|  | 233 |  | 
| Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 234 | static void captureChildLayersExcluding( | 
|  | 235 | std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle, | 
|  | 236 | std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>> excludeLayers) { | 
|  | 237 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
|  | 238 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 239 |  | 
|  | 240 | sp<GraphicBuffer> outBuffer; | 
|  | 241 | ASSERT_EQ(NO_ERROR, | 
|  | 242 | sf->captureLayers(parentHandle, &outBuffer, ui::Dataspace::V0_SRGB, | 
|  | 243 | ui::PixelFormat::RGBA_8888, Rect::EMPTY_RECT, excludeLayers, | 
|  | 244 | 1.0f, true)); | 
|  | 245 | *sc = std::make_unique<ScreenCapture>(outBuffer); | 
|  | 246 | } | 
|  | 247 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 248 | void expectColor(const Rect& rect, const Color& color, uint8_t tolerance = 0) { | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 249 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); | 
|  | 250 | expectBufferColor(mOutBuffer, mPixels, rect, color, tolerance); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 251 | } | 
|  | 252 |  | 
|  | 253 | void expectBorder(const Rect& rect, const Color& color, uint8_t tolerance = 0) { | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 254 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 255 | const bool leftBorder = rect.left > 0; | 
|  | 256 | const bool topBorder = rect.top > 0; | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 257 | const bool rightBorder = rect.right < int32_t(mOutBuffer->getWidth()); | 
|  | 258 | const bool bottomBorder = rect.bottom < int32_t(mOutBuffer->getHeight()); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 259 |  | 
|  | 260 | if (topBorder) { | 
|  | 261 | Rect top(rect.left, rect.top - 1, rect.right, rect.top); | 
|  | 262 | if (leftBorder) { | 
|  | 263 | top.left -= 1; | 
|  | 264 | } | 
|  | 265 | if (rightBorder) { | 
|  | 266 | top.right += 1; | 
|  | 267 | } | 
|  | 268 | expectColor(top, color, tolerance); | 
|  | 269 | } | 
|  | 270 | if (leftBorder) { | 
|  | 271 | Rect left(rect.left - 1, rect.top, rect.left, rect.bottom); | 
|  | 272 | expectColor(left, color, tolerance); | 
|  | 273 | } | 
|  | 274 | if (rightBorder) { | 
|  | 275 | Rect right(rect.right, rect.top, rect.right + 1, rect.bottom); | 
|  | 276 | expectColor(right, color, tolerance); | 
|  | 277 | } | 
|  | 278 | if (bottomBorder) { | 
|  | 279 | Rect bottom(rect.left, rect.bottom, rect.right, rect.bottom + 1); | 
|  | 280 | if (leftBorder) { | 
|  | 281 | bottom.left -= 1; | 
|  | 282 | } | 
|  | 283 | if (rightBorder) { | 
|  | 284 | bottom.right += 1; | 
|  | 285 | } | 
|  | 286 | expectColor(bottom, color, tolerance); | 
|  | 287 | } | 
|  | 288 | } | 
|  | 289 |  | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 290 | void expectQuadrant(const Rect& rect, const Color& topLeft, const Color& topRight, | 
|  | 291 | const Color& bottomLeft, const Color& bottomRight, bool filtered = false, | 
|  | 292 | uint8_t tolerance = 0) { | 
|  | 293 | ASSERT_TRUE((rect.right - rect.left) % 2 == 0 && (rect.bottom - rect.top) % 2 == 0); | 
|  | 294 |  | 
|  | 295 | const int32_t centerX = rect.left + (rect.right - rect.left) / 2; | 
|  | 296 | const int32_t centerY = rect.top + (rect.bottom - rect.top) / 2; | 
|  | 297 | // avoid checking borders due to unspecified filtering behavior | 
|  | 298 | const int32_t offsetX = filtered ? 2 : 0; | 
|  | 299 | const int32_t offsetY = filtered ? 2 : 0; | 
|  | 300 | expectColor(Rect(rect.left, rect.top, centerX - offsetX, centerY - offsetY), topLeft, | 
|  | 301 | tolerance); | 
|  | 302 | expectColor(Rect(centerX + offsetX, rect.top, rect.right, centerY - offsetY), topRight, | 
|  | 303 | tolerance); | 
|  | 304 | expectColor(Rect(rect.left, centerY + offsetY, centerX - offsetX, rect.bottom), bottomLeft, | 
|  | 305 | tolerance); | 
|  | 306 | expectColor(Rect(centerX + offsetX, centerY + offsetY, rect.right, rect.bottom), | 
|  | 307 | bottomRight, tolerance); | 
|  | 308 | } | 
|  | 309 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 310 | 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] | 311 | ASSERT_EQ(HAL_PIXEL_FORMAT_RGBA_8888, mOutBuffer->getPixelFormat()); | 
|  | 312 | const uint8_t* pixel = mPixels + (4 * (y * mOutBuffer->getStride() + x)); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 313 | if (r != pixel[0] || g != pixel[1] || b != pixel[2]) { | 
|  | 314 | String8 err(String8::format("pixel @ (%3d, %3d): " | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 315 | "expected [%3d, %3d, %3d], got [%3d, %3d, %3d]", | 
|  | 316 | x, y, r, g, b, pixel[0], pixel[1], pixel[2])); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 317 | EXPECT_EQ(String8(), err) << err.string(); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 318 | } | 
|  | 319 | } | 
|  | 320 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 321 | 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] | 322 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 323 | 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] | 324 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 325 | 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] | 326 |  | 
| Chih-Hung Hsieh | 2274904 | 2018-12-20 15:50:39 -0800 | [diff] [blame] | 327 | explicit ScreenCapture(const sp<GraphicBuffer>& outBuffer) : mOutBuffer(outBuffer) { | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 328 | mOutBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&mPixels)); | 
| Michael Lentine | 5a16a62 | 2015-05-21 13:48:24 -0700 | [diff] [blame] | 329 | } | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 330 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 331 | ~ScreenCapture() { mOutBuffer->unlock(); } | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 332 |  | 
|  | 333 | private: | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 334 | sp<GraphicBuffer> mOutBuffer; | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 335 | uint8_t* mPixels = nullptr; | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 336 | }; | 
|  | 337 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 338 | class LayerTransactionTest : public ::testing::Test { | 
|  | 339 | protected: | 
|  | 340 | void SetUp() override { | 
|  | 341 | mClient = new SurfaceComposerClient; | 
|  | 342 | ASSERT_EQ(NO_ERROR, mClient->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 343 |  | 
|  | 344 | ASSERT_NO_FATAL_FAILURE(SetUpDisplay()); | 
| Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 345 |  | 
|  | 346 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
| Ady Abraham | 37965d4 | 2018-11-01 13:43:32 -0700 | [diff] [blame] | 347 | ASSERT_NO_FATAL_FAILURE(sf->getColorManagement(&mColorManagementUsed)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 348 | } | 
|  | 349 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 350 | virtual void TearDown() { | 
|  | 351 | mBlackBgSurface = 0; | 
|  | 352 | mClient->dispose(); | 
|  | 353 | mClient = 0; | 
|  | 354 | } | 
|  | 355 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 356 | virtual sp<SurfaceControl> createLayer(const sp<SurfaceComposerClient>& client, | 
|  | 357 | const char* name, uint32_t width, uint32_t height, | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 358 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { | 
|  | 359 | auto layer = | 
|  | 360 | createSurface(client, name, width, height, PIXEL_FORMAT_RGBA_8888, flags, parent); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 361 |  | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 362 | Transaction t; | 
|  | 363 | t.setLayerStack(layer, mDisplayLayerStack).setLayer(layer, mLayerZBase); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 364 |  | 
|  | 365 | status_t error = t.apply(); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 366 | if (error != NO_ERROR) { | 
|  | 367 | ADD_FAILURE() << "failed to initialize SurfaceControl"; | 
|  | 368 | layer.clear(); | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | return layer; | 
|  | 372 | } | 
|  | 373 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 374 | virtual sp<SurfaceControl> createSurface(const sp<SurfaceComposerClient>& client, | 
|  | 375 | const char* name, uint32_t width, uint32_t height, | 
|  | 376 | PixelFormat format, uint32_t flags, | 
|  | 377 | SurfaceControl* parent = nullptr) { | 
|  | 378 | auto layer = client->createSurface(String8(name), width, height, format, flags, parent); | 
|  | 379 | EXPECT_NE(nullptr, layer.get()) << "failed to create SurfaceControl"; | 
|  | 380 | return layer; | 
|  | 381 | } | 
|  | 382 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 383 | virtual sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 384 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { | 
|  | 385 | return createLayer(mClient, name, width, height, flags, parent); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 386 | } | 
|  | 387 |  | 
| Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 388 | sp<SurfaceControl> createColorLayer(const char* name, const Color& color, | 
|  | 389 | SurfaceControl* parent = nullptr) { | 
|  | 390 | auto colorLayer = createSurface(mClient, name, 0 /* buffer width */, 0 /* buffer height */, | 
|  | 391 | PIXEL_FORMAT_RGBA_8888, | 
|  | 392 | ISurfaceComposerClient::eFXSurfaceColor, parent); | 
|  | 393 | asTransaction([&](Transaction& t) { | 
|  | 394 | t.setColor(colorLayer, half3{color.r / 255.0f, color.g / 255.0f, color.b / 255.0f}); | 
|  | 395 | t.setAlpha(colorLayer, color.a / 255.0f); | 
|  | 396 | }); | 
|  | 397 | return colorLayer; | 
|  | 398 | } | 
|  | 399 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 400 | ANativeWindow_Buffer getBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 401 | // wait for previous transactions (such as setSize) to complete | 
|  | 402 | Transaction().apply(true); | 
|  | 403 |  | 
|  | 404 | ANativeWindow_Buffer buffer = {}; | 
|  | 405 | EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr)); | 
|  | 406 |  | 
|  | 407 | return buffer; | 
|  | 408 | } | 
|  | 409 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 410 | void postBufferQueueLayerBuffer(const sp<SurfaceControl>& layer) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 411 | ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost()); | 
|  | 412 |  | 
|  | 413 | // wait for the newly posted buffer to be latched | 
|  | 414 | waitForLayerBuffers(); | 
|  | 415 | } | 
|  | 416 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 417 | virtual void fillBufferQueueLayerColor(const sp<SurfaceControl>& layer, const Color& color, | 
|  | 418 | int32_t bufferWidth, int32_t bufferHeight) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 419 | ANativeWindow_Buffer buffer; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 420 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); | 
|  | 421 | fillANativeWindowBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); | 
|  | 422 | postBufferQueueLayerBuffer(layer); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 423 | } | 
|  | 424 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 425 | virtual void fillBufferStateLayerColor(const sp<SurfaceControl>& layer, const Color& color, | 
|  | 426 | int32_t bufferWidth, int32_t bufferHeight) { | 
|  | 427 | sp<GraphicBuffer> buffer = | 
|  | 428 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 429 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 430 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 431 | "test"); | 
|  | 432 | fillGraphicBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight), color); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 433 | Transaction().setBuffer(layer, buffer).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 434 | } | 
|  | 435 |  | 
|  | 436 | void fillLayerColor(uint32_t mLayerType, const sp<SurfaceControl>& layer, const Color& color, | 
|  | 437 | int32_t bufferWidth, int32_t bufferHeight) { | 
|  | 438 | switch (mLayerType) { | 
|  | 439 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 440 | fillBufferQueueLayerColor(layer, color, bufferWidth, bufferHeight); | 
|  | 441 | break; | 
|  | 442 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 443 | fillBufferStateLayerColor(layer, color, bufferWidth, bufferHeight); | 
|  | 444 | break; | 
|  | 445 | default: | 
|  | 446 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; | 
|  | 447 | } | 
|  | 448 | } | 
|  | 449 |  | 
|  | 450 | void fillLayerQuadrant(uint32_t mLayerType, const sp<SurfaceControl>& layer, | 
|  | 451 | int32_t bufferWidth, int32_t bufferHeight, const Color& topLeft, | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 452 | const Color& topRight, const Color& bottomLeft, | 
|  | 453 | const Color& bottomRight) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 454 | switch (mLayerType) { | 
|  | 455 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 456 | fillBufferQueueLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, | 
|  | 457 | bottomLeft, bottomRight); | 
|  | 458 | break; | 
|  | 459 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 460 | fillBufferStateLayerQuadrant(layer, bufferWidth, bufferHeight, topLeft, topRight, | 
|  | 461 | bottomLeft, bottomRight); | 
|  | 462 | break; | 
|  | 463 | default: | 
|  | 464 | ASSERT_TRUE(false) << "unsupported layer type: " << mLayerType; | 
|  | 465 | } | 
|  | 466 | } | 
|  | 467 |  | 
|  | 468 | virtual void fillBufferQueueLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, | 
|  | 469 | int32_t bufferHeight, const Color& topLeft, | 
|  | 470 | const Color& topRight, const Color& bottomLeft, | 
|  | 471 | const Color& bottomRight) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 472 | ANativeWindow_Buffer buffer; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 473 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); | 
|  | 474 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 475 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 476 | const int32_t halfW = bufferWidth / 2; | 
|  | 477 | const int32_t halfH = bufferHeight / 2; | 
|  | 478 | fillANativeWindowBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); | 
|  | 479 | fillANativeWindowBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); | 
|  | 480 | fillANativeWindowBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); | 
|  | 481 | fillANativeWindowBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), | 
|  | 482 | bottomRight); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 483 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 484 | postBufferQueueLayerBuffer(layer); | 
|  | 485 | } | 
|  | 486 |  | 
|  | 487 | virtual void fillBufferStateLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, | 
|  | 488 | int32_t bufferHeight, const Color& topLeft, | 
|  | 489 | const Color& topRight, const Color& bottomLeft, | 
|  | 490 | const Color& bottomRight) { | 
|  | 491 | sp<GraphicBuffer> buffer = | 
|  | 492 | new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 493 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 494 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 495 | "test"); | 
|  | 496 |  | 
|  | 497 | ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0); | 
|  | 498 |  | 
|  | 499 | const int32_t halfW = bufferWidth / 2; | 
|  | 500 | const int32_t halfH = bufferHeight / 2; | 
|  | 501 | fillGraphicBufferColor(buffer, Rect(0, 0, halfW, halfH), topLeft); | 
|  | 502 | fillGraphicBufferColor(buffer, Rect(halfW, 0, bufferWidth, halfH), topRight); | 
|  | 503 | fillGraphicBufferColor(buffer, Rect(0, halfH, halfW, bufferHeight), bottomLeft); | 
|  | 504 | fillGraphicBufferColor(buffer, Rect(halfW, halfH, bufferWidth, bufferHeight), bottomRight); | 
|  | 505 |  | 
|  | 506 | Transaction().setBuffer(layer, buffer).setSize(layer, bufferWidth, bufferHeight).apply(); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 507 | } | 
|  | 508 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 509 | std::unique_ptr<ScreenCapture> screenshot() { | 
|  | 510 | std::unique_ptr<ScreenCapture> screenshot; | 
|  | 511 | ScreenCapture::captureScreen(&screenshot); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 512 | return screenshot; | 
|  | 513 | } | 
|  | 514 |  | 
| Vishnu Nair | b927e1f | 2019-02-19 13:36:15 -0800 | [diff] [blame] | 515 | void asTransaction(const std::function<void(Transaction&)>& exec) { | 
|  | 516 | Transaction t; | 
|  | 517 | exec(t); | 
|  | 518 | t.apply(true); | 
|  | 519 | } | 
|  | 520 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 521 | static status_t getBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) { | 
|  | 522 | static BufferGenerator bufferGenerator; | 
|  | 523 | return bufferGenerator.get(outBuffer, outFence); | 
|  | 524 | } | 
|  | 525 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 526 | sp<SurfaceComposerClient> mClient; | 
|  | 527 |  | 
|  | 528 | sp<IBinder> mDisplay; | 
|  | 529 | uint32_t mDisplayWidth; | 
|  | 530 | uint32_t mDisplayHeight; | 
|  | 531 | uint32_t mDisplayLayerStack; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 532 | Rect mDisplayRect = Rect::INVALID_RECT; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 533 |  | 
|  | 534 | // leave room for ~256 layers | 
|  | 535 | const int32_t mLayerZBase = std::numeric_limits<int32_t>::max() - 256; | 
|  | 536 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 537 | sp<SurfaceControl> mBlackBgSurface; | 
| Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 538 | bool mColorManagementUsed; | 
|  | 539 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 540 | private: | 
|  | 541 | void SetUpDisplay() { | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 542 | mDisplay = mClient->getInternalDisplayToken(); | 
|  | 543 | ASSERT_FALSE(mDisplay == nullptr) << "failed to get display"; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 544 |  | 
|  | 545 | // get display width/height | 
|  | 546 | DisplayInfo info; | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 547 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayInfo(mDisplay, &info)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 548 | mDisplayWidth = info.w; | 
|  | 549 | mDisplayHeight = info.h; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 550 | mDisplayRect = | 
|  | 551 | Rect(static_cast<int32_t>(mDisplayWidth), static_cast<int32_t>(mDisplayHeight)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 552 |  | 
|  | 553 | // After a new buffer is queued, SurfaceFlinger is notified and will | 
|  | 554 | // latch the new buffer on next vsync.  Let's heuristically wait for 3 | 
|  | 555 | // vsyncs. | 
|  | 556 | mBufferPostDelay = int32_t(1e6 / info.fps) * 3; | 
|  | 557 |  | 
|  | 558 | mDisplayLayerStack = 0; | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 559 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 560 | mBlackBgSurface = | 
|  | 561 | createSurface(mClient, "BaseSurface", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 562 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 563 |  | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 564 | // set layer stack (b/68888219) | 
|  | 565 | Transaction t; | 
|  | 566 | t.setDisplayLayerStack(mDisplay, mDisplayLayerStack); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 567 | t.setCrop_legacy(mBlackBgSurface, Rect(0, 0, mDisplayWidth, mDisplayHeight)); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 568 | t.setLayerStack(mBlackBgSurface, mDisplayLayerStack); | 
|  | 569 | t.setColor(mBlackBgSurface, half3{0, 0, 0}); | 
|  | 570 | t.setLayer(mBlackBgSurface, mLayerZBase); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 571 | t.apply(); | 
|  | 572 | } | 
|  | 573 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 574 | void waitForLayerBuffers() { | 
|  | 575 | // Request an empty transaction to get applied synchronously to ensure the buffer is | 
|  | 576 | // latched. | 
|  | 577 | Transaction().apply(true); | 
|  | 578 | usleep(mBufferPostDelay); | 
|  | 579 | } | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 580 |  | 
|  | 581 | int32_t mBufferPostDelay; | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 582 |  | 
|  | 583 | friend class LayerRenderPathTestHarness; | 
|  | 584 | }; | 
|  | 585 | enum class RenderPath { SCREENSHOT, VIRTUAL_DISPLAY }; | 
|  | 586 |  | 
|  | 587 | class LayerRenderPathTestHarness { | 
|  | 588 | public: | 
|  | 589 | LayerRenderPathTestHarness(LayerTransactionTest* delegate, RenderPath renderPath) | 
|  | 590 | : mDelegate(delegate), mRenderPath(renderPath) {} | 
|  | 591 |  | 
|  | 592 | std::unique_ptr<ScreenCapture> getScreenCapture() { | 
|  | 593 | switch (mRenderPath) { | 
|  | 594 | case RenderPath::SCREENSHOT: | 
|  | 595 | return mDelegate->screenshot(); | 
|  | 596 | case RenderPath::VIRTUAL_DISPLAY: | 
|  | 597 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 598 | const auto mainDisplay = SurfaceComposerClient::getInternalDisplayToken(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 599 | DisplayInfo mainDisplayInfo; | 
|  | 600 | SurfaceComposerClient::getDisplayInfo(mainDisplay, &mainDisplayInfo); | 
|  | 601 |  | 
|  | 602 | sp<IBinder> vDisplay; | 
|  | 603 | sp<IGraphicBufferProducer> producer; | 
|  | 604 | sp<IGraphicBufferConsumer> consumer; | 
|  | 605 | sp<BufferItemConsumer> itemConsumer; | 
|  | 606 | BufferQueue::createBufferQueue(&producer, &consumer); | 
|  | 607 |  | 
|  | 608 | consumer->setConsumerName(String8("Virtual disp consumer")); | 
|  | 609 | consumer->setDefaultBufferSize(mainDisplayInfo.w, mainDisplayInfo.h); | 
|  | 610 |  | 
|  | 611 | itemConsumer = new BufferItemConsumer(consumer, | 
|  | 612 | // Sample usage bits from screenrecord | 
|  | 613 | GRALLOC_USAGE_HW_VIDEO_ENCODER | | 
|  | 614 | GRALLOC_USAGE_SW_READ_OFTEN); | 
|  | 615 |  | 
|  | 616 | vDisplay = SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), | 
|  | 617 | false /*secure*/); | 
|  | 618 |  | 
|  | 619 | SurfaceComposerClient::Transaction t; | 
|  | 620 | t.setDisplaySurface(vDisplay, producer); | 
|  | 621 | t.setDisplayLayerStack(vDisplay, 0); | 
|  | 622 | t.setDisplayProjection(vDisplay, mainDisplayInfo.orientation, | 
|  | 623 | Rect(mainDisplayInfo.viewportW, mainDisplayInfo.viewportH), | 
|  | 624 | Rect(mainDisplayInfo.w, mainDisplayInfo.h)); | 
|  | 625 | t.apply(); | 
|  | 626 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 627 | BufferItem item; | 
|  | 628 | itemConsumer->acquireBuffer(&item, 0, true); | 
|  | 629 | auto sc = std::make_unique<ScreenCapture>(item.mGraphicBuffer); | 
|  | 630 | itemConsumer->releaseBuffer(item); | 
|  | 631 | SurfaceComposerClient::destroyDisplay(vDisplay); | 
|  | 632 | return sc; | 
|  | 633 | } | 
|  | 634 | } | 
|  | 635 |  | 
|  | 636 | protected: | 
|  | 637 | LayerTransactionTest* mDelegate; | 
|  | 638 | RenderPath mRenderPath; | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 639 | }; | 
|  | 640 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 641 | class LayerTypeTransactionHarness : public LayerTransactionTest { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 642 | public: | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 643 | LayerTypeTransactionHarness(uint32_t layerType) : mLayerType(layerType) {} | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 644 |  | 
|  | 645 | sp<SurfaceControl> createLayer(const char* name, uint32_t width, uint32_t height, | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 646 | uint32_t flags = 0, SurfaceControl* parent = nullptr) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 647 | // if the flags already have a layer type specified, return an error | 
|  | 648 | if (flags & ISurfaceComposerClient::eFXSurfaceMask) { | 
|  | 649 | return nullptr; | 
|  | 650 | } | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 651 | return LayerTransactionTest::createLayer(name, width, height, flags | mLayerType, parent); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 652 | } | 
|  | 653 |  | 
|  | 654 | void fillLayerColor(const sp<SurfaceControl>& layer, const Color& color, int32_t bufferWidth, | 
|  | 655 | int32_t bufferHeight) { | 
|  | 656 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerColor(mLayerType, layer, color, | 
|  | 657 | bufferWidth, bufferHeight)); | 
|  | 658 | } | 
|  | 659 |  | 
|  | 660 | void fillLayerQuadrant(const sp<SurfaceControl>& layer, int32_t bufferWidth, | 
|  | 661 | int32_t bufferHeight, const Color& topLeft, const Color& topRight, | 
|  | 662 | const Color& bottomLeft, const Color& bottomRight) { | 
|  | 663 | ASSERT_NO_FATAL_FAILURE(LayerTransactionTest::fillLayerQuadrant(mLayerType, layer, | 
|  | 664 | bufferWidth, bufferHeight, | 
|  | 665 | topLeft, topRight, | 
|  | 666 | bottomLeft, bottomRight)); | 
|  | 667 | } | 
|  | 668 |  | 
|  | 669 | protected: | 
|  | 670 | uint32_t mLayerType; | 
|  | 671 | }; | 
|  | 672 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 673 | class LayerTypeTransactionTest : public LayerTypeTransactionHarness, | 
|  | 674 | public ::testing::WithParamInterface<uint32_t> { | 
|  | 675 | public: | 
|  | 676 | LayerTypeTransactionTest() : LayerTypeTransactionHarness(GetParam()) {} | 
|  | 677 | }; | 
|  | 678 |  | 
|  | 679 | class LayerTypeAndRenderTypeTransactionTest | 
|  | 680 | : public LayerTypeTransactionHarness, | 
|  | 681 | public ::testing::WithParamInterface<std::tuple<uint32_t, RenderPath>> { | 
|  | 682 | public: | 
|  | 683 | LayerTypeAndRenderTypeTransactionTest() | 
|  | 684 | : LayerTypeTransactionHarness(std::get<0>(GetParam())), | 
|  | 685 | mRenderPathHarness(LayerRenderPathTestHarness(this, std::get<1>(GetParam()))) {} | 
|  | 686 |  | 
|  | 687 | std::unique_ptr<ScreenCapture> getScreenCapture() { | 
|  | 688 | return mRenderPathHarness.getScreenCapture(); | 
|  | 689 | } | 
|  | 690 |  | 
|  | 691 | protected: | 
|  | 692 | LayerRenderPathTestHarness mRenderPathHarness; | 
|  | 693 | }; | 
|  | 694 |  | 
|  | 695 | // Environment for starting up binder threads. This is required for testing | 
|  | 696 | // virtual displays, as BufferQueue parameters may be queried over binder. | 
|  | 697 | class BinderEnvironment : public ::testing::Environment { | 
|  | 698 | public: | 
|  | 699 | void SetUp() override { ProcessState::self()->startThreadPool(); } | 
|  | 700 | }; | 
|  | 701 |  | 
|  | 702 | ::testing::Environment* const binderEnv = | 
|  | 703 | ::testing::AddGlobalTestEnvironment(new BinderEnvironment()); | 
|  | 704 |  | 
|  | 705 | class LayerRenderTypeTransactionTest : public LayerTransactionTest, | 
|  | 706 | public ::testing::WithParamInterface<RenderPath> { | 
|  | 707 | public: | 
|  | 708 | LayerRenderTypeTransactionTest() : mHarness(LayerRenderPathTestHarness(this, GetParam())) {} | 
|  | 709 |  | 
|  | 710 | std::unique_ptr<ScreenCapture> getScreenCapture() { return mHarness.getScreenCapture(); } | 
|  | 711 | void setRelativeZBasicHelper(uint32_t layerType); | 
|  | 712 | void setRelativeZGroupHelper(uint32_t layerType); | 
|  | 713 | void setAlphaBasicHelper(uint32_t layerType); | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 714 | void setBackgroundColorHelper(uint32_t layerType, bool priorColor, bool bufferFill, float alpha, | 
|  | 715 | Color finalColor); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 716 |  | 
|  | 717 | protected: | 
|  | 718 | LayerRenderPathTestHarness mHarness; | 
|  | 719 | }; | 
|  | 720 |  | 
|  | 721 | INSTANTIATE_TEST_CASE_P( | 
|  | 722 | LayerTypeAndRenderTypeTransactionTests, LayerTypeAndRenderTypeTransactionTest, | 
|  | 723 | ::testing::Combine( | 
|  | 724 | ::testing::Values( | 
|  | 725 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferQueue), | 
|  | 726 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferState)), | 
|  | 727 | ::testing::Values(RenderPath::VIRTUAL_DISPLAY, RenderPath::SCREENSHOT))); | 
|  | 728 |  | 
|  | 729 | INSTANTIATE_TEST_CASE_P(LayerRenderTypeTransactionTests, LayerRenderTypeTransactionTest, | 
|  | 730 | ::testing::Values(RenderPath::VIRTUAL_DISPLAY, RenderPath::SCREENSHOT)); | 
|  | 731 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 732 | INSTANTIATE_TEST_CASE_P( | 
|  | 733 | LayerTypeTransactionTests, LayerTypeTransactionTest, | 
|  | 734 | ::testing::Values(static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferQueue), | 
|  | 735 | static_cast<uint32_t>(ISurfaceComposerClient::eFXSurfaceBufferState))); | 
|  | 736 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 737 | TEST_P(LayerRenderTypeTransactionTest, SetPositionBasic_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 738 | sp<SurfaceControl> layer; | 
|  | 739 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 740 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 741 |  | 
|  | 742 | { | 
|  | 743 | SCOPED_TRACE("default position"); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 744 | const Rect rect(0, 0, 32, 32); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 745 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 746 | shot->expectColor(rect, Color::RED); | 
|  | 747 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 748 | } | 
|  | 749 |  | 
|  | 750 | Transaction().setPosition(layer, 5, 10).apply(); | 
|  | 751 | { | 
|  | 752 | SCOPED_TRACE("new position"); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 753 | const Rect rect(5, 10, 37, 42); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 754 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 755 | shot->expectColor(rect, Color::RED); | 
|  | 756 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 757 | } | 
|  | 758 | } | 
|  | 759 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 760 | TEST_P(LayerRenderTypeTransactionTest, SetPositionRounding_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 761 | sp<SurfaceControl> layer; | 
|  | 762 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 763 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 764 |  | 
|  | 765 | // GLES requires only 4 bits of subpixel precision during rasterization | 
|  | 766 | // XXX GLES composition does not match HWC composition due to precision | 
|  | 767 | // loss (b/69315223) | 
|  | 768 | const float epsilon = 1.0f / 16.0f; | 
|  | 769 | Transaction().setPosition(layer, 0.5f - epsilon, 0.5f - epsilon).apply(); | 
|  | 770 | { | 
|  | 771 | SCOPED_TRACE("rounding down"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 772 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 773 | } | 
|  | 774 |  | 
|  | 775 | Transaction().setPosition(layer, 0.5f + epsilon, 0.5f + epsilon).apply(); | 
|  | 776 | { | 
|  | 777 | SCOPED_TRACE("rounding up"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 778 | getScreenCapture()->expectColor(Rect(1, 1, 33, 33), 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, SetPositionOutOfBounds_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 783 | sp<SurfaceControl> layer; | 
|  | 784 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 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 | Transaction().setPosition(layer, -32, -32).apply(); | 
|  | 788 | { | 
|  | 789 | SCOPED_TRACE("negative coordinates"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 790 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 791 | } | 
|  | 792 |  | 
|  | 793 | Transaction().setPosition(layer, mDisplayWidth, mDisplayHeight).apply(); | 
|  | 794 | { | 
|  | 795 | SCOPED_TRACE("positive coordinates"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 796 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 797 | } | 
|  | 798 | } | 
|  | 799 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 800 | TEST_P(LayerRenderTypeTransactionTest, SetPositionPartiallyOutOfBounds_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 801 | sp<SurfaceControl> layer; | 
|  | 802 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 803 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 804 |  | 
|  | 805 | // partially out of bounds | 
|  | 806 | Transaction().setPosition(layer, -30, -30).apply(); | 
|  | 807 | { | 
|  | 808 | SCOPED_TRACE("negative coordinates"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 809 | getScreenCapture()->expectColor(Rect(0, 0, 2, 2), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 810 | } | 
|  | 811 |  | 
|  | 812 | Transaction().setPosition(layer, mDisplayWidth - 2, mDisplayHeight - 2).apply(); | 
|  | 813 | { | 
|  | 814 | SCOPED_TRACE("positive coordinates"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 815 | getScreenCapture()->expectColor(Rect(mDisplayWidth - 2, mDisplayHeight - 2, mDisplayWidth, | 
|  | 816 | mDisplayHeight), | 
|  | 817 | Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 818 | } | 
|  | 819 | } | 
|  | 820 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 821 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithResize_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 822 | sp<SurfaceControl> layer; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 823 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 824 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 825 |  | 
|  | 826 | // setPosition is applied immediately by default, with or without resize | 
|  | 827 | // pending | 
|  | 828 | Transaction().setPosition(layer, 5, 10).setSize(layer, 64, 64).apply(); | 
|  | 829 | { | 
|  | 830 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 831 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 832 | const Rect rect(5, 10, 37, 42); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 833 | shot->expectColor(rect, Color::RED); | 
|  | 834 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 835 | } | 
|  | 836 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 837 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 838 | { | 
|  | 839 | SCOPED_TRACE("resize applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 840 | getScreenCapture()->expectColor(Rect(5, 10, 69, 74), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 841 | } | 
|  | 842 | } | 
|  | 843 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 844 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithNextResize_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 845 | sp<SurfaceControl> layer; | 
|  | 846 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 847 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 848 |  | 
|  | 849 | // request setPosition to be applied with the next resize | 
|  | 850 | Transaction().setPosition(layer, 5, 10).setGeometryAppliesWithResize(layer).apply(); | 
|  | 851 | { | 
|  | 852 | SCOPED_TRACE("new position pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 853 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 854 | } | 
|  | 855 |  | 
|  | 856 | Transaction().setPosition(layer, 15, 20).apply(); | 
|  | 857 | { | 
|  | 858 | SCOPED_TRACE("pending new position modified"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 859 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 860 | } | 
|  | 861 |  | 
|  | 862 | Transaction().setSize(layer, 64, 64).apply(); | 
|  | 863 | { | 
|  | 864 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 865 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 866 | } | 
|  | 867 |  | 
|  | 868 | // finally resize and latch the buffer | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 869 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 870 | { | 
|  | 871 | SCOPED_TRACE("new position applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 872 | getScreenCapture()->expectColor(Rect(15, 20, 79, 84), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 873 | } | 
|  | 874 | } | 
|  | 875 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 876 | TEST_P(LayerRenderTypeTransactionTest, SetPositionWithNextResizeScaleToWindow_BufferQueue) { | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 877 | sp<SurfaceControl> layer; | 
|  | 878 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 879 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 880 |  | 
|  | 881 | // setPosition is not immediate even with SCALE_TO_WINDOW override | 
|  | 882 | Transaction() | 
|  | 883 | .setPosition(layer, 5, 10) | 
|  | 884 | .setSize(layer, 64, 64) | 
|  | 885 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 886 | .setGeometryAppliesWithResize(layer) | 
|  | 887 | .apply(); | 
|  | 888 | { | 
|  | 889 | SCOPED_TRACE("new position pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 890 | getScreenCapture()->expectColor(Rect(0, 0, 64, 64), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 891 | } | 
|  | 892 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 893 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 894 | { | 
|  | 895 | SCOPED_TRACE("new position applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 896 | getScreenCapture()->expectColor(Rect(5, 10, 69, 74), Color::RED); | 
| Chia-I Wu | 718daf8 | 2017-10-20 11:57:17 -0700 | [diff] [blame] | 897 | } | 
|  | 898 | } | 
|  | 899 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 900 | TEST_P(LayerRenderTypeTransactionTest, SetSizeBasic_BufferQueue) { | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 901 | sp<SurfaceControl> layer; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 902 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 903 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 904 |  | 
|  | 905 | Transaction().setSize(layer, 64, 64).apply(); | 
|  | 906 | { | 
|  | 907 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 908 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 909 | const Rect rect(0, 0, 32, 32); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 910 | shot->expectColor(rect, Color::RED); | 
|  | 911 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 912 | } | 
|  | 913 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 914 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 915 | { | 
|  | 916 | SCOPED_TRACE("resize applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 917 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 918 | const Rect rect(0, 0, 64, 64); | 
|  | 919 | shot->expectColor(rect, Color::RED); | 
|  | 920 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 921 | } | 
|  | 922 | } | 
|  | 923 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 924 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetSizeInvalid) { | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 925 | // cannot test robustness against invalid sizes (zero or really huge) | 
|  | 926 | } | 
|  | 927 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 928 | TEST_P(LayerRenderTypeTransactionTest, SetSizeWithScaleToWindow_BufferQueue) { | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 929 | sp<SurfaceControl> layer; | 
|  | 930 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 931 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 932 |  | 
|  | 933 | // setSize is immediate with SCALE_TO_WINDOW, unlike setPosition | 
|  | 934 | Transaction() | 
|  | 935 | .setSize(layer, 64, 64) | 
|  | 936 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 937 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 938 | getScreenCapture()->expectColor(Rect(0, 0, 64, 64), Color::RED); | 
| Chia-I Wu | 0eaea31 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 939 | } | 
|  | 940 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 941 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetZBasic) { | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 942 | sp<SurfaceControl> layerR; | 
|  | 943 | sp<SurfaceControl> layerG; | 
|  | 944 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 945 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 946 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 947 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 948 |  | 
|  | 949 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); | 
|  | 950 | { | 
|  | 951 | SCOPED_TRACE("layerR"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 952 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 953 | } | 
|  | 954 |  | 
|  | 955 | Transaction().setLayer(layerG, mLayerZBase + 2).apply(); | 
|  | 956 | { | 
|  | 957 | SCOPED_TRACE("layerG"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 958 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::GREEN); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 959 | } | 
|  | 960 | } | 
|  | 961 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 962 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetZNegative) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 963 | sp<SurfaceControl> parent = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 964 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 965 | ISurfaceComposerClient::eFXSurfaceContainer); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 966 | Transaction().setCrop_legacy(parent, Rect(0, 0, mDisplayWidth, mDisplayHeight)).apply(); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 967 | sp<SurfaceControl> layerR; | 
|  | 968 | sp<SurfaceControl> layerG; | 
|  | 969 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 970 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 971 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 972 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 973 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 974 | Transaction() | 
|  | 975 | .reparent(layerR, parent->getHandle()) | 
|  | 976 | .reparent(layerG, parent->getHandle()) | 
|  | 977 | .apply(); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 978 | Transaction().setLayer(layerR, -1).setLayer(layerG, -2).apply(); | 
|  | 979 | { | 
|  | 980 | SCOPED_TRACE("layerR"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 981 | auto shot = getScreenCapture(); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 982 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 983 | } | 
|  | 984 |  | 
|  | 985 | Transaction().setLayer(layerR, -3).apply(); | 
|  | 986 | { | 
|  | 987 | SCOPED_TRACE("layerG"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 988 | auto shot = getScreenCapture(); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 989 | shot->expectColor(Rect(0, 0, 32, 32), Color::GREEN); | 
| Chia-I Wu | 0ea0f82 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 990 | } | 
|  | 991 | } | 
|  | 992 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 993 | void LayerRenderTypeTransactionTest::setRelativeZBasicHelper(uint32_t layerType) { | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 994 | sp<SurfaceControl> layerR; | 
|  | 995 | sp<SurfaceControl> layerG; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 996 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32, layerType)); | 
|  | 997 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerR, Color::RED, 32, 32)); | 
|  | 998 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32, layerType)); | 
|  | 999 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1000 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1001 | switch (layerType) { | 
|  | 1002 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 1003 | Transaction() | 
|  | 1004 | .setPosition(layerG, 16, 16) | 
|  | 1005 | .setRelativeLayer(layerG, layerR->getHandle(), 1) | 
|  | 1006 | .apply(); | 
|  | 1007 | break; | 
|  | 1008 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 1009 | Transaction() | 
|  | 1010 | .setFrame(layerR, Rect(0, 0, 32, 32)) | 
|  | 1011 | .setFrame(layerG, Rect(16, 16, 48, 48)) | 
|  | 1012 | .setRelativeLayer(layerG, layerR->getHandle(), 1) | 
|  | 1013 | .apply(); | 
|  | 1014 | break; | 
|  | 1015 | default: | 
|  | 1016 | ASSERT_FALSE(true) << "Unsupported layer type"; | 
|  | 1017 | } | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1018 | { | 
|  | 1019 | SCOPED_TRACE("layerG above"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1020 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1021 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); | 
|  | 1022 | shot->expectColor(Rect(16, 16, 48, 48), Color::GREEN); | 
|  | 1023 | } | 
|  | 1024 |  | 
|  | 1025 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).apply(); | 
|  | 1026 | { | 
|  | 1027 | SCOPED_TRACE("layerG below"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1028 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1029 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 1030 | shot->expectColor(Rect(32, 32, 48, 48), Color::GREEN); | 
|  | 1031 | } | 
|  | 1032 | } | 
|  | 1033 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1034 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZBasic_BufferQueue) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1035 | ASSERT_NO_FATAL_FAILURE(setRelativeZBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); | 
|  | 1036 | } | 
|  | 1037 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1038 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZBasic_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1039 | ASSERT_NO_FATAL_FAILURE(setRelativeZBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1040 | } | 
|  | 1041 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1042 | TEST_P(LayerTypeTransactionTest, SetRelativeZNegative) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1043 | sp<SurfaceControl> parent = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1044 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1045 | ISurfaceComposerClient::eFXSurfaceContainer); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1046 | Transaction().setCrop_legacy(parent, Rect(0, 0, mDisplayWidth, mDisplayHeight)).apply(); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1047 | sp<SurfaceControl> layerR; | 
|  | 1048 | sp<SurfaceControl> layerG; | 
|  | 1049 | sp<SurfaceControl> layerB; | 
|  | 1050 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1051 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1052 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1053 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1054 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test B", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1055 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerB, Color::BLUE, 32, 32)); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1056 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1057 | Transaction() | 
|  | 1058 | .reparent(layerB, parent->getHandle()) | 
|  | 1059 | .apply(); | 
|  | 1060 |  | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1061 | // layerR = mLayerZBase, layerG = layerR - 1, layerB = -2 | 
|  | 1062 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -1).setLayer(layerB, -2).apply(); | 
|  | 1063 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1064 | std::unique_ptr<ScreenCapture> screenshot; | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1065 | // only layerB is in this range | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1066 | sp<IBinder> parentHandle = parent->getHandle(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1067 | ScreenCapture::captureLayers(&screenshot, parentHandle, Rect(0, 0, 32, 32)); | 
| Chia-I Wu | ec2d985 | 2017-11-21 09:21:01 -0800 | [diff] [blame] | 1068 | screenshot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 1069 | } | 
|  | 1070 |  | 
| chaviw | 3237758 | 2019-05-13 11:15:19 -0700 | [diff] [blame] | 1071 | TEST_P(LayerTypeTransactionTest, SetLayerAndRelative) { | 
|  | 1072 | sp<SurfaceControl> parent = | 
|  | 1073 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 1074 | ISurfaceComposerClient::eFXSurfaceColor); | 
|  | 1075 |  | 
|  | 1076 | sp<SurfaceControl> childLayer; | 
|  | 1077 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1078 | childLayer = LayerTransactionTest::createLayer("childLayer", 0 /* buffer width */, | 
|  | 1079 | 0 /* buffer height */, | 
|  | 1080 | ISurfaceComposerClient::eFXSurfaceColor, | 
|  | 1081 | parent.get())); | 
|  | 1082 | Transaction() | 
|  | 1083 | .setColor(childLayer, half3{1.0f, 0.0f, 0.0f}) | 
|  | 1084 | .setColor(parent, half3{0.0f, 0.0f, 0.0f}) | 
|  | 1085 | .show(childLayer) | 
|  | 1086 | .show(parent) | 
|  | 1087 | .setCrop_legacy(parent, Rect(0, 0, mDisplayWidth, mDisplayHeight)) | 
|  | 1088 | .setCrop_legacy(childLayer, Rect(0, 0, 20, 30)) | 
|  | 1089 | .apply(); | 
|  | 1090 |  | 
|  | 1091 | Transaction() | 
|  | 1092 | .setRelativeLayer(childLayer, parent->getHandle(), -1) | 
|  | 1093 | .setLayer(childLayer, 1) | 
|  | 1094 | .apply(); | 
|  | 1095 |  | 
|  | 1096 | { | 
|  | 1097 | SCOPED_TRACE("setLayer above"); | 
|  | 1098 | // Set layer should get applied and place the child above. | 
|  | 1099 | std::unique_ptr<ScreenCapture> screenshot; | 
|  | 1100 | ScreenCapture::captureScreen(&screenshot); | 
|  | 1101 | screenshot->expectColor(Rect(0, 0, 20, 30), Color::RED); | 
|  | 1102 | } | 
|  | 1103 |  | 
|  | 1104 | Transaction() | 
|  | 1105 | .setLayer(childLayer, 1) | 
|  | 1106 | .setRelativeLayer(childLayer, parent->getHandle(), -1) | 
|  | 1107 | .apply(); | 
|  | 1108 |  | 
|  | 1109 | { | 
|  | 1110 | SCOPED_TRACE("setRelative below"); | 
|  | 1111 | // Set relative layer should get applied and place the child below. | 
|  | 1112 | std::unique_ptr<ScreenCapture> screenshot; | 
|  | 1113 | ScreenCapture::captureScreen(&screenshot); | 
|  | 1114 | screenshot->expectColor(Rect(0, 0, 20, 30), Color::BLACK); | 
|  | 1115 | } | 
|  | 1116 | } | 
|  | 1117 |  | 
| Robert Carr | 1c5481e | 2019-07-01 14:42:27 -0700 | [diff] [blame] | 1118 | TEST_P(LayerTypeTransactionTest, HideRelativeParentHidesLayer) { | 
|  | 1119 | sp<SurfaceControl> parent = | 
|  | 1120 | LayerTransactionTest::createLayer("Parent", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 1121 | ISurfaceComposerClient::eFXSurfaceColor); | 
|  | 1122 | sp<SurfaceControl> relativeParent = | 
|  | 1123 | LayerTransactionTest::createLayer("RelativeParent", 0 /* buffer width */, | 
|  | 1124 | 0 /* buffer height */, ISurfaceComposerClient::eFXSurfaceColor); | 
|  | 1125 |  | 
|  | 1126 | sp<SurfaceControl> childLayer; | 
|  | 1127 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1128 | childLayer = LayerTransactionTest::createLayer("childLayer", 0 /* buffer width */, | 
|  | 1129 | 0 /* buffer height */, | 
|  | 1130 | ISurfaceComposerClient::eFXSurfaceColor, | 
|  | 1131 | parent.get())); | 
|  | 1132 | Transaction() | 
|  | 1133 | .setColor(childLayer, half3{1.0f, 0.0f, 0.0f}) | 
|  | 1134 | .setColor(parent, half3{0.0f, 0.0f, 0.0f}) | 
|  | 1135 | .setColor(relativeParent, half3{0.0f, 1.0f, 0.0f}) | 
|  | 1136 | .show(childLayer) | 
|  | 1137 | .show(parent) | 
|  | 1138 | .show(relativeParent) | 
|  | 1139 | .setLayer(parent, mLayerZBase - 1) | 
|  | 1140 | .setLayer(relativeParent, mLayerZBase) | 
|  | 1141 | .apply(); | 
|  | 1142 |  | 
|  | 1143 | Transaction() | 
|  | 1144 | .setRelativeLayer(childLayer, relativeParent->getHandle(), 1) | 
|  | 1145 | .apply(); | 
|  | 1146 |  | 
|  | 1147 | { | 
|  | 1148 | SCOPED_TRACE("setLayer above"); | 
|  | 1149 | // Set layer should get applied and place the child above. | 
|  | 1150 | std::unique_ptr<ScreenCapture> screenshot; | 
|  | 1151 | ScreenCapture::captureScreen(&screenshot); | 
|  | 1152 | screenshot->expectColor(Rect(0, 0, 20, 30), Color::RED); | 
|  | 1153 | } | 
|  | 1154 |  | 
|  | 1155 | Transaction() | 
|  | 1156 | .hide(relativeParent) | 
|  | 1157 | .apply(); | 
|  | 1158 |  | 
|  | 1159 | { | 
|  | 1160 | SCOPED_TRACE("hide relative parent"); | 
|  | 1161 | // The relative should no longer be visible. | 
|  | 1162 | std::unique_ptr<ScreenCapture> screenshot; | 
|  | 1163 | ScreenCapture::captureScreen(&screenshot); | 
|  | 1164 | screenshot->expectColor(Rect(0, 0, 20, 30), Color::BLACK); | 
|  | 1165 | } | 
|  | 1166 | } | 
|  | 1167 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1168 | void LayerRenderTypeTransactionTest::setRelativeZGroupHelper(uint32_t layerType) { | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1169 | sp<SurfaceControl> layerR; | 
|  | 1170 | sp<SurfaceControl> layerG; | 
|  | 1171 | sp<SurfaceControl> layerB; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1172 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test", 32, 32, layerType)); | 
|  | 1173 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerR, Color::RED, 32, 32)); | 
|  | 1174 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test", 32, 32, layerType)); | 
|  | 1175 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerG, Color::GREEN, 32, 32)); | 
|  | 1176 | ASSERT_NO_FATAL_FAILURE(layerB = createLayer("test", 32, 32, layerType)); | 
|  | 1177 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layerB, Color::BLUE, 32, 32)); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1178 |  | 
|  | 1179 | // layerR = 0, layerG = layerR + 3, layerB = 2 | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1180 | switch (layerType) { | 
|  | 1181 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 1182 | Transaction() | 
|  | 1183 | .setPosition(layerG, 8, 8) | 
|  | 1184 | .setRelativeLayer(layerG, layerR->getHandle(), 3) | 
|  | 1185 | .setPosition(layerB, 16, 16) | 
|  | 1186 | .setLayer(layerB, mLayerZBase + 2) | 
|  | 1187 | .apply(); | 
|  | 1188 | break; | 
|  | 1189 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 1190 | Transaction() | 
|  | 1191 | .setFrame(layerR, Rect(0, 0, 32, 32)) | 
|  | 1192 | .setFrame(layerG, Rect(8, 8, 40, 40)) | 
|  | 1193 | .setRelativeLayer(layerG, layerR->getHandle(), 3) | 
|  | 1194 | .setFrame(layerB, Rect(16, 16, 48, 48)) | 
|  | 1195 | .setLayer(layerB, mLayerZBase + 2) | 
|  | 1196 | .apply(); | 
|  | 1197 | break; | 
|  | 1198 | default: | 
|  | 1199 | ASSERT_FALSE(true) << "Unsupported layer type"; | 
|  | 1200 | } | 
|  | 1201 |  | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1202 | { | 
|  | 1203 | SCOPED_TRACE("(layerR < layerG) < layerB"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1204 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1205 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); | 
|  | 1206 | shot->expectColor(Rect(8, 8, 16, 16), Color::GREEN); | 
|  | 1207 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); | 
|  | 1208 | } | 
|  | 1209 |  | 
|  | 1210 | // layerR = 4, layerG = layerR + 3, layerB = 2 | 
|  | 1211 | Transaction().setLayer(layerR, mLayerZBase + 4).apply(); | 
|  | 1212 | { | 
|  | 1213 | SCOPED_TRACE("layerB < (layerR < layerG)"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1214 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1215 | shot->expectColor(Rect(0, 0, 8, 8), Color::RED); | 
|  | 1216 | shot->expectColor(Rect(8, 8, 40, 40), Color::GREEN); | 
|  | 1217 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); | 
|  | 1218 | } | 
|  | 1219 |  | 
|  | 1220 | // layerR = 4, layerG = layerR - 3, layerB = 2 | 
|  | 1221 | Transaction().setRelativeLayer(layerG, layerR->getHandle(), -3).apply(); | 
|  | 1222 | { | 
|  | 1223 | SCOPED_TRACE("layerB < (layerG < layerR)"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1224 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1225 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 1226 | shot->expectColor(Rect(32, 32, 40, 40), Color::GREEN); | 
|  | 1227 | shot->expectColor(Rect(40, 40, 48, 48), Color::BLUE); | 
|  | 1228 | } | 
|  | 1229 |  | 
|  | 1230 | // restore to absolute z | 
|  | 1231 | // layerR = 4, layerG = 0, layerB = 2 | 
|  | 1232 | Transaction().setLayer(layerG, mLayerZBase).apply(); | 
|  | 1233 | { | 
|  | 1234 | SCOPED_TRACE("layerG < layerB < layerR"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1235 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1236 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 1237 | shot->expectColor(Rect(32, 32, 48, 48), Color::BLUE); | 
|  | 1238 | } | 
|  | 1239 |  | 
|  | 1240 | // layerR should not affect layerG anymore | 
|  | 1241 | // layerR = 1, layerG = 0, layerB = 2 | 
|  | 1242 | Transaction().setLayer(layerR, mLayerZBase + 1).apply(); | 
|  | 1243 | { | 
|  | 1244 | SCOPED_TRACE("layerG < layerR < layerB"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1245 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1246 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); | 
|  | 1247 | shot->expectColor(Rect(16, 16, 48, 48), Color::BLUE); | 
|  | 1248 | } | 
|  | 1249 | } | 
|  | 1250 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1251 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZGroup_BufferQueue) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1252 | ASSERT_NO_FATAL_FAILURE(setRelativeZGroupHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); | 
|  | 1253 | } | 
|  | 1254 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1255 | TEST_P(LayerRenderTypeTransactionTest, SetRelativeZGroup_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1256 | ASSERT_NO_FATAL_FAILURE(setRelativeZGroupHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1257 | } | 
|  | 1258 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1259 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetRelativeZBug64572777) { | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1260 | sp<SurfaceControl> layerR; | 
|  | 1261 | sp<SurfaceControl> layerG; | 
|  | 1262 |  | 
|  | 1263 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1264 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, Color::RED, 32, 32)); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1265 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1266 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1267 |  | 
|  | 1268 | Transaction() | 
|  | 1269 | .setPosition(layerG, 16, 16) | 
|  | 1270 | .setRelativeLayer(layerG, layerR->getHandle(), 1) | 
|  | 1271 | .apply(); | 
|  | 1272 |  | 
| Robert Carr | 8724653 | 2019-02-04 15:20:26 -0800 | [diff] [blame] | 1273 | layerG.clear(); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1274 | // layerG should have been removed | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1275 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 4931330 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1276 | } | 
|  | 1277 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1278 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetFlagsHidden) { | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1279 | sp<SurfaceControl> layer; | 
|  | 1280 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1281 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1282 |  | 
|  | 1283 | Transaction().setFlags(layer, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden).apply(); | 
|  | 1284 | { | 
|  | 1285 | SCOPED_TRACE("layer hidden"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1286 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1287 | } | 
|  | 1288 |  | 
|  | 1289 | Transaction().setFlags(layer, 0, layer_state_t::eLayerHidden).apply(); | 
|  | 1290 | { | 
|  | 1291 | SCOPED_TRACE("layer shown"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1292 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1293 | } | 
|  | 1294 | } | 
|  | 1295 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1296 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetFlagsOpaque) { | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1297 | const Color translucentRed = {100, 0, 0, 100}; | 
|  | 1298 | sp<SurfaceControl> layerR; | 
|  | 1299 | sp<SurfaceControl> layerG; | 
|  | 1300 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1301 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerR, translucentRed, 32, 32)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1302 | ASSERT_NO_FATAL_FAILURE(layerG = createLayer("test G", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1303 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerG, Color::GREEN, 32, 32)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1304 |  | 
|  | 1305 | Transaction() | 
|  | 1306 | .setLayer(layerR, mLayerZBase + 1) | 
|  | 1307 | .setFlags(layerR, layer_state_t::eLayerOpaque, layer_state_t::eLayerOpaque) | 
|  | 1308 | .apply(); | 
|  | 1309 | { | 
|  | 1310 | SCOPED_TRACE("layerR opaque"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1311 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {100, 0, 0, 255}); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1312 | } | 
|  | 1313 |  | 
|  | 1314 | Transaction().setFlags(layerR, 0, layer_state_t::eLayerOpaque).apply(); | 
|  | 1315 | { | 
|  | 1316 | SCOPED_TRACE("layerR translucent"); | 
|  | 1317 | const uint8_t g = uint8_t(255 - translucentRed.a); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1318 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {100, g, 0, 255}); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1319 | } | 
|  | 1320 | } | 
|  | 1321 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1322 | TEST_P(LayerTypeTransactionTest, SetFlagsSecure) { | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1323 | sp<SurfaceControl> layer; | 
|  | 1324 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1325 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1326 |  | 
|  | 1327 | sp<ISurfaceComposer> composer = ComposerService::getComposerService(); | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 1328 | sp<GraphicBuffer> outBuffer; | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1329 | Transaction() | 
|  | 1330 | .setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure) | 
|  | 1331 | .apply(true); | 
|  | 1332 | ASSERT_EQ(PERMISSION_DENIED, | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1333 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1334 |  | 
|  | 1335 | Transaction().setFlags(layer, 0, layer_state_t::eLayerSecure).apply(true); | 
|  | 1336 | ASSERT_EQ(NO_ERROR, | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 1337 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); | 
| Chia-I Wu | 57b2750 | 2017-10-31 10:14:40 -0700 | [diff] [blame] | 1338 | } | 
|  | 1339 |  | 
| Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 1340 | /** RAII Wrapper around get/seteuid */ | 
|  | 1341 | class UIDFaker { | 
|  | 1342 | uid_t oldId; | 
|  | 1343 | public: | 
|  | 1344 | UIDFaker(uid_t uid) { | 
|  | 1345 | oldId = geteuid(); | 
|  | 1346 | seteuid(uid); | 
|  | 1347 | } | 
|  | 1348 | ~UIDFaker() { | 
|  | 1349 | seteuid(oldId); | 
|  | 1350 | } | 
|  | 1351 | }; | 
|  | 1352 |  | 
|  | 1353 | TEST_F(LayerTransactionTest, SetFlagsSecureEUidSystem) { | 
|  | 1354 | sp<SurfaceControl> layer; | 
|  | 1355 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 1356 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
|  | 1357 |  | 
|  | 1358 | sp<ISurfaceComposer> composer = ComposerService::getComposerService(); | 
|  | 1359 | sp<GraphicBuffer> outBuffer; | 
|  | 1360 | Transaction() | 
|  | 1361 | .setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure) | 
|  | 1362 | .apply(true); | 
|  | 1363 | ASSERT_EQ(PERMISSION_DENIED, | 
|  | 1364 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); | 
|  | 1365 |  | 
|  | 1366 | UIDFaker f(AID_SYSTEM); | 
|  | 1367 |  | 
|  | 1368 | // By default the system can capture screenshots with secure layers but they | 
|  | 1369 | // will be blacked out | 
|  | 1370 | ASSERT_EQ(NO_ERROR, | 
|  | 1371 | composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false)); | 
|  | 1372 |  | 
|  | 1373 | { | 
|  | 1374 | SCOPED_TRACE("as system"); | 
|  | 1375 | auto shot = screenshot(); | 
|  | 1376 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 1377 | } | 
|  | 1378 |  | 
|  | 1379 | // Here we pass captureSecureLayers = true and since we are AID_SYSTEM we should be able | 
|  | 1380 | // to receive them...we are expected to take care with the results. | 
| Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 1381 | bool outCapturedSecureLayers; | 
| Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 1382 | ASSERT_EQ(NO_ERROR, | 
| Robert Carr | 108b2c7 | 2019-04-02 16:32:58 -0700 | [diff] [blame] | 1383 | composer->captureScreen(mDisplay, &outBuffer, outCapturedSecureLayers, | 
|  | 1384 | ui::Dataspace::V0_SRGB, ui::PixelFormat::RGBA_8888, Rect(), 0, | 
|  | 1385 | 0, false, ISurfaceComposer::eRotateNone, true)); | 
|  | 1386 | ASSERT_EQ(true, outCapturedSecureLayers); | 
| Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 1387 | ScreenCapture sc(outBuffer); | 
|  | 1388 | sc.expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 1389 | } | 
|  | 1390 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1391 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintBasic_BufferQueue) { | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1392 | const Rect top(0, 0, 32, 16); | 
|  | 1393 | const Rect bottom(0, 16, 32, 32); | 
|  | 1394 | sp<SurfaceControl> layer; | 
|  | 1395 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 1396 |  | 
|  | 1397 | ANativeWindow_Buffer buffer; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1398 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); | 
|  | 1399 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::TRANSPARENT)); | 
|  | 1400 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::RED)); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1401 | // setTransparentRegionHint always applies to the following buffer | 
|  | 1402 | Transaction().setTransparentRegionHint(layer, Region(top)).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1403 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1404 | { | 
|  | 1405 | SCOPED_TRACE("top transparent"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1406 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1407 | shot->expectColor(top, Color::BLACK); | 
|  | 1408 | shot->expectColor(bottom, Color::RED); | 
|  | 1409 | } | 
|  | 1410 |  | 
|  | 1411 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); | 
|  | 1412 | { | 
|  | 1413 | SCOPED_TRACE("transparent region hint pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1414 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1415 | shot->expectColor(top, Color::BLACK); | 
|  | 1416 | shot->expectColor(bottom, Color::RED); | 
|  | 1417 | } | 
|  | 1418 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1419 | ASSERT_NO_FATAL_FAILURE(buffer = getBufferQueueLayerBuffer(layer)); | 
|  | 1420 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, top, Color::RED)); | 
|  | 1421 | ASSERT_NO_FATAL_FAILURE(fillANativeWindowBufferColor(buffer, bottom, Color::TRANSPARENT)); | 
|  | 1422 | ASSERT_NO_FATAL_FAILURE(postBufferQueueLayerBuffer(layer)); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1423 | { | 
|  | 1424 | SCOPED_TRACE("bottom transparent"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1425 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1426 | shot->expectColor(top, Color::RED); | 
|  | 1427 | shot->expectColor(bottom, Color::BLACK); | 
|  | 1428 | } | 
|  | 1429 | } | 
|  | 1430 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1431 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1432 | const Rect top(0, 0, 32, 16); | 
|  | 1433 | const Rect bottom(0, 16, 32, 32); | 
|  | 1434 | sp<SurfaceControl> layer; | 
|  | 1435 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1436 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1437 |  | 
|  | 1438 | sp<GraphicBuffer> buffer = | 
|  | 1439 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 1440 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 1441 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 1442 | "test"); | 
|  | 1443 |  | 
|  | 1444 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::TRANSPARENT)); | 
|  | 1445 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::RED)); | 
|  | 1446 | Transaction() | 
|  | 1447 | .setTransparentRegionHint(layer, Region(top)) | 
|  | 1448 | .setBuffer(layer, buffer) | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1449 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1450 | .apply(); | 
|  | 1451 | { | 
|  | 1452 | SCOPED_TRACE("top transparent"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1453 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1454 | shot->expectColor(top, Color::BLACK); | 
|  | 1455 | shot->expectColor(bottom, Color::RED); | 
|  | 1456 | } | 
|  | 1457 |  | 
|  | 1458 | Transaction().setTransparentRegionHint(layer, Region(bottom)).apply(); | 
|  | 1459 | { | 
|  | 1460 | SCOPED_TRACE("transparent region hint intermediate"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1461 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1462 | shot->expectColor(top, Color::BLACK); | 
|  | 1463 | shot->expectColor(bottom, Color::BLACK); | 
|  | 1464 | } | 
|  | 1465 |  | 
|  | 1466 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 1467 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 1468 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 1469 | "test"); | 
|  | 1470 |  | 
|  | 1471 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, top, Color::RED)); | 
|  | 1472 | ASSERT_NO_FATAL_FAILURE(fillGraphicBufferColor(buffer, bottom, Color::TRANSPARENT)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1473 | Transaction().setBuffer(layer, buffer).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1474 | { | 
|  | 1475 | SCOPED_TRACE("bottom transparent"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1476 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1477 | shot->expectColor(top, Color::RED); | 
|  | 1478 | shot->expectColor(bottom, Color::BLACK); | 
|  | 1479 | } | 
|  | 1480 | } | 
|  | 1481 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1482 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintOutOfBounds_BufferQueue) { | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1483 | sp<SurfaceControl> layerTransparent; | 
|  | 1484 | sp<SurfaceControl> layerR; | 
|  | 1485 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); | 
|  | 1486 | ASSERT_NO_FATAL_FAILURE(layerR = createLayer("test R", 32, 32)); | 
|  | 1487 |  | 
|  | 1488 | // check that transparent region hint is bound by the layer size | 
|  | 1489 | Transaction() | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1490 | .setTransparentRegionHint(layerTransparent, Region(mDisplayRect)) | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1491 | .setPosition(layerR, 16, 16) | 
|  | 1492 | .setLayer(layerR, mLayerZBase + 1) | 
|  | 1493 | .apply(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1494 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1495 | fillBufferQueueLayerColor(layerTransparent, Color::TRANSPARENT, 32, 32)); | 
|  | 1496 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layerR, Color::RED, 32, 32)); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1497 | getScreenCapture()->expectColor(Rect(16, 16, 48, 48), Color::RED); | 
| Chia-I Wu | 2113bdd | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1498 | } | 
|  | 1499 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1500 | TEST_P(LayerRenderTypeTransactionTest, SetTransparentRegionHintOutOfBounds_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1501 | sp<SurfaceControl> layerTransparent; | 
|  | 1502 | sp<SurfaceControl> layerR; | 
|  | 1503 | ASSERT_NO_FATAL_FAILURE(layerTransparent = createLayer("test transparent", 32, 32)); | 
|  | 1504 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1505 | layerR = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1506 |  | 
|  | 1507 | // check that transparent region hint is bound by the layer size | 
|  | 1508 | Transaction() | 
|  | 1509 | .setTransparentRegionHint(layerTransparent, Region(mDisplayRect)) | 
|  | 1510 | .setFrame(layerR, Rect(16, 16, 48, 48)) | 
|  | 1511 | .setLayer(layerR, mLayerZBase + 1) | 
|  | 1512 | .apply(); | 
|  | 1513 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1514 | fillBufferQueueLayerColor(layerTransparent, Color::TRANSPARENT, 32, 32)); | 
|  | 1515 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layerR, Color::RED, 32, 32)); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1516 | getScreenCapture()->expectColor(Rect(16, 16, 48, 48), Color::RED); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1517 | } | 
|  | 1518 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1519 | void LayerRenderTypeTransactionTest::setAlphaBasicHelper(uint32_t layerType) { | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1520 | sp<SurfaceControl> layer1; | 
|  | 1521 | sp<SurfaceControl> layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1522 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer("test 1", 32, 32, layerType)); | 
|  | 1523 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer("test 2", 32, 32, layerType)); | 
|  | 1524 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layerType, layer1, {64, 0, 0, 255}, 32, 32)); | 
|  | 1525 | 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] | 1526 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1527 | switch (layerType) { | 
|  | 1528 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 1529 | Transaction() | 
|  | 1530 | .setAlpha(layer1, 0.25f) | 
|  | 1531 | .setAlpha(layer2, 0.75f) | 
|  | 1532 | .setPosition(layer2, 16, 0) | 
|  | 1533 | .setLayer(layer2, mLayerZBase + 1) | 
|  | 1534 | .apply(); | 
|  | 1535 | break; | 
|  | 1536 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 1537 | Transaction() | 
|  | 1538 | .setAlpha(layer1, 0.25f) | 
|  | 1539 | .setAlpha(layer2, 0.75f) | 
|  | 1540 | .setFrame(layer1, Rect(0, 0, 32, 32)) | 
|  | 1541 | .setFrame(layer2, Rect(16, 0, 48, 32)) | 
|  | 1542 | .setLayer(layer2, mLayerZBase + 1) | 
|  | 1543 | .apply(); | 
|  | 1544 | break; | 
|  | 1545 | default: | 
|  | 1546 | ASSERT_FALSE(true) << "Unsupported layer type"; | 
|  | 1547 | } | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1548 | { | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1549 | auto shot = getScreenCapture(); | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1550 | uint8_t r = 16; // 64 * 0.25f | 
|  | 1551 | uint8_t g = 48; // 64 * 0.75f | 
|  | 1552 | shot->expectColor(Rect(0, 0, 16, 32), {r, 0, 0, 255}); | 
|  | 1553 | shot->expectColor(Rect(32, 0, 48, 32), {0, g, 0, 255}); | 
|  | 1554 |  | 
|  | 1555 | r /= 4; // r * (1.0f - 0.75f) | 
|  | 1556 | shot->expectColor(Rect(16, 0, 32, 32), {r, g, 0, 255}); | 
|  | 1557 | } | 
|  | 1558 | } | 
|  | 1559 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1560 | TEST_P(LayerRenderTypeTransactionTest, SetAlphaBasic_BufferQueue) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1561 | ASSERT_NO_FATAL_FAILURE(setAlphaBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue)); | 
|  | 1562 | } | 
|  | 1563 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1564 | TEST_P(LayerRenderTypeTransactionTest, SetAlphaBasic_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1565 | ASSERT_NO_FATAL_FAILURE(setAlphaBasicHelper(ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1566 | } | 
|  | 1567 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1568 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetAlphaClamped) { | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1569 | const Color color = {64, 0, 0, 255}; | 
|  | 1570 | sp<SurfaceControl> layer; | 
|  | 1571 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1572 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, color, 32, 32)); | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1573 |  | 
|  | 1574 | Transaction().setAlpha(layer, 2.0f).apply(); | 
|  | 1575 | { | 
|  | 1576 | SCOPED_TRACE("clamped to 1.0f"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1577 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), color); | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1578 | } | 
|  | 1579 |  | 
|  | 1580 | Transaction().setAlpha(layer, -1.0f).apply(); | 
|  | 1581 | { | 
|  | 1582 | SCOPED_TRACE("clamped to 0.0f"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1583 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Chia-I Wu | a8a515e | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1584 | } | 
|  | 1585 | } | 
|  | 1586 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1587 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadius) { | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1588 | sp<SurfaceControl> layer; | 
|  | 1589 | const uint8_t size = 64; | 
|  | 1590 | const uint8_t testArea = 4; | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1591 | const float cornerRadius = 20.0f; | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1592 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", size, size)); | 
|  | 1593 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, size, size)); | 
|  | 1594 |  | 
|  | 1595 | Transaction() | 
|  | 1596 | .setCornerRadius(layer, cornerRadius) | 
|  | 1597 | .apply(); | 
|  | 1598 | { | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1599 | const uint8_t bottom = size - 1; | 
|  | 1600 | const uint8_t right = size - 1; | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1601 | auto shot = getScreenCapture(); | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1602 | // Transparent corners | 
|  | 1603 | shot->expectColor(Rect(0, 0, testArea, testArea), Color::BLACK); | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1604 | shot->expectColor(Rect(size - testArea, 0, right, testArea), Color::BLACK); | 
|  | 1605 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); | 
|  | 1606 | shot->expectColor(Rect(size - testArea, bottom - testArea, right, bottom), Color::BLACK); | 
|  | 1607 | } | 
|  | 1608 | } | 
|  | 1609 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1610 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetCornerRadiusChildCrop) { | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1611 | sp<SurfaceControl> parent; | 
|  | 1612 | sp<SurfaceControl> child; | 
|  | 1613 | const uint8_t size = 64; | 
|  | 1614 | const uint8_t testArea = 4; | 
|  | 1615 | const float cornerRadius = 20.0f; | 
|  | 1616 | ASSERT_NO_FATAL_FAILURE(parent = createLayer("parent", size, size)); | 
|  | 1617 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(parent, Color::RED, size, size)); | 
|  | 1618 | ASSERT_NO_FATAL_FAILURE(child = createLayer("child", size, size / 2)); | 
|  | 1619 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(child, Color::GREEN, size, size / 2)); | 
|  | 1620 |  | 
|  | 1621 | Transaction() | 
|  | 1622 | .setCornerRadius(parent, cornerRadius) | 
|  | 1623 | .reparent(child, parent->getHandle()) | 
|  | 1624 | .setPosition(child, 0, size / 2) | 
|  | 1625 | .apply(); | 
|  | 1626 | { | 
|  | 1627 | const uint8_t bottom = size - 1; | 
|  | 1628 | const uint8_t right = size - 1; | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1629 | auto shot = getScreenCapture(); | 
| Lucas Dupin | a1d0e31 | 2018-12-04 22:30:27 -0800 | [diff] [blame] | 1630 | // Top edge of child should not have rounded corners because it's translated in the parent | 
|  | 1631 | shot->expectColor(Rect(0, size / 2, right, static_cast<int>(bottom - cornerRadius)), | 
|  | 1632 | Color::GREEN); | 
|  | 1633 | // But bottom edges should have been clipped according to parent bounds | 
|  | 1634 | shot->expectColor(Rect(0, bottom - testArea, testArea, bottom), Color::BLACK); | 
|  | 1635 | shot->expectColor(Rect(right - testArea, bottom - testArea, right, bottom), Color::BLACK); | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 1636 | } | 
|  | 1637 | } | 
|  | 1638 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1639 | TEST_P(LayerRenderTypeTransactionTest, SetColorBasic) { | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1640 | sp<SurfaceControl> bufferLayer; | 
|  | 1641 | sp<SurfaceControl> colorLayer; | 
|  | 1642 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1643 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1644 | ASSERT_NO_FATAL_FAILURE(colorLayer = | 
|  | 1645 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 1646 | ISurfaceComposerClient::eFXSurfaceColor)); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1647 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1648 | Transaction() | 
|  | 1649 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 1650 | .setLayer(colorLayer, mLayerZBase + 1) | 
|  | 1651 | .apply(); | 
|  | 1652 |  | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1653 | { | 
|  | 1654 | SCOPED_TRACE("default color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1655 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1656 | } | 
|  | 1657 |  | 
|  | 1658 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); | 
|  | 1659 | const Color expected = {15, 51, 85, 255}; | 
|  | 1660 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 1661 | // channel) should be less than one | 
|  | 1662 | const uint8_t tolerance = 1; | 
|  | 1663 | Transaction().setColor(colorLayer, color).apply(); | 
|  | 1664 | { | 
|  | 1665 | SCOPED_TRACE("new color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1666 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expected, tolerance); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1667 | } | 
|  | 1668 | } | 
|  | 1669 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1670 | // RED: Color layer base color and BufferQueueLayer/BufferStateLayer fill | 
|  | 1671 | // BLUE: prior background color | 
|  | 1672 | // GREEN: final background color | 
|  | 1673 | // BLACK: no color or fill | 
|  | 1674 | void LayerRenderTypeTransactionTest::setBackgroundColorHelper(uint32_t layerType, bool priorColor, | 
|  | 1675 | bool bufferFill, float alpha, | 
|  | 1676 | Color finalColor) { | 
|  | 1677 | sp<SurfaceControl> layer; | 
|  | 1678 | int32_t width = 500; | 
|  | 1679 | int32_t height = 500; | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1680 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1681 | Color fillColor = Color::RED; | 
|  | 1682 | Color priorBgColor = Color::BLUE; | 
|  | 1683 | Color expectedColor = Color::BLACK; | 
|  | 1684 | switch (layerType) { | 
|  | 1685 | case ISurfaceComposerClient::eFXSurfaceColor: | 
|  | 1686 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 0, 0, layerType)); | 
|  | 1687 | Transaction() | 
|  | 1688 | .setCrop_legacy(layer, Rect(0, 0, width, height)) | 
|  | 1689 | .setColor(layer, half3(1.0f, 0, 0)) | 
|  | 1690 | .apply(); | 
|  | 1691 | expectedColor = fillColor; | 
|  | 1692 | break; | 
|  | 1693 | case ISurfaceComposerClient::eFXSurfaceBufferQueue: | 
|  | 1694 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", width, height)); | 
|  | 1695 | if (bufferFill) { | 
|  | 1696 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, fillColor, width, height)); | 
|  | 1697 | expectedColor = fillColor; | 
|  | 1698 | } | 
|  | 1699 | Transaction().setCrop_legacy(layer, Rect(0, 0, width, height)).apply(); | 
|  | 1700 | break; | 
|  | 1701 | case ISurfaceComposerClient::eFXSurfaceBufferState: | 
|  | 1702 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", width, height, layerType)); | 
|  | 1703 | if (bufferFill) { | 
|  | 1704 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, fillColor, width, height)); | 
|  | 1705 | expectedColor = fillColor; | 
|  | 1706 | } | 
|  | 1707 | Transaction().setFrame(layer, Rect(0, 0, width, height)).apply(); | 
|  | 1708 | break; | 
|  | 1709 | default: | 
|  | 1710 | GTEST_FAIL() << "Unknown layer type in setBackgroundColorHelper"; | 
|  | 1711 | return; | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1712 | } | 
|  | 1713 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1714 | if (priorColor && layerType != ISurfaceComposerClient::eFXSurfaceColor) { | 
|  | 1715 | Transaction() | 
|  | 1716 | .setBackgroundColor(layer, half3(0, 0, 1.0f), 1.0f, ui::Dataspace::UNKNOWN) | 
|  | 1717 | .apply(); | 
|  | 1718 | if (!bufferFill) { | 
|  | 1719 | expectedColor = priorBgColor; | 
|  | 1720 | } | 
|  | 1721 | } | 
|  | 1722 |  | 
|  | 1723 | { | 
|  | 1724 | SCOPED_TRACE("default before setting background color layer"); | 
|  | 1725 | screenshot()->expectColor(Rect(0, 0, width, height), expectedColor); | 
|  | 1726 | } | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1727 | Transaction() | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1728 | .setBackgroundColor(layer, half3(0, 1.0f, 0), alpha, ui::Dataspace::UNKNOWN) | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1729 | .apply(); | 
|  | 1730 |  | 
|  | 1731 | { | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1732 | auto shot = screenshot(); | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1733 | shot->expectColor(Rect(0, 0, width, height), finalColor); | 
|  | 1734 | shot->expectBorder(Rect(0, 0, width, height), Color::BLACK); | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1735 | } | 
|  | 1736 | } | 
|  | 1737 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1738 | TEST_P(LayerRenderTypeTransactionTest, SetBackgroundColor_Color_NoEffect) { | 
|  | 1739 | bool priorColor = false; | 
|  | 1740 | bool bufferFill = false; | 
|  | 1741 | float alpha = 1.0f; | 
|  | 1742 | Color finalColor = Color::RED; | 
|  | 1743 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceColor, | 
|  | 1744 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1745 | } | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1746 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1747 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1748 | SetBackgroundColor_BufferQueue_BufferFill_NoPriorColor_Basic) { | 
|  | 1749 | bool priorColor = false; | 
|  | 1750 | bool bufferFill = true; | 
|  | 1751 | float alpha = 1.0f; | 
|  | 1752 | Color finalColor = Color::RED; | 
|  | 1753 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1754 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1755 | } | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1756 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1757 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1758 | SetBackgroundColor_BufferQueue_NoBufferFill_NoPriorColor_Basic) { | 
|  | 1759 | bool priorColor = false; | 
|  | 1760 | bool bufferFill = false; | 
|  | 1761 | float alpha = 1.0f; | 
|  | 1762 | Color finalColor = Color::GREEN; | 
|  | 1763 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1764 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1765 | } | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1766 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1767 | TEST_P(LayerRenderTypeTransactionTest, SetBackgroundColor_BufferQueue_BufferFill_PriorColor_Basic) { | 
|  | 1768 | bool priorColor = true; | 
|  | 1769 | bool bufferFill = true; | 
|  | 1770 | float alpha = 1.0f; | 
|  | 1771 | Color finalColor = Color::RED; | 
|  | 1772 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1773 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1774 | } | 
|  | 1775 |  | 
|  | 1776 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1777 | SetBackgroundColor_BufferQueue_NoBufferFill_PriorColor_Basic) { | 
|  | 1778 | bool priorColor = true; | 
|  | 1779 | bool bufferFill = false; | 
|  | 1780 | float alpha = 1.0f; | 
|  | 1781 | Color finalColor = Color::GREEN; | 
|  | 1782 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1783 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1784 | } | 
|  | 1785 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1786 | SetBackgroundColor_BufferQueue_NoPriorColor_ZeroAlpha_NoEffect) { | 
|  | 1787 | bool priorColor = false; | 
|  | 1788 | bool bufferFill = false; | 
|  | 1789 | float alpha = 0; | 
|  | 1790 | Color finalColor = Color::BLACK; | 
|  | 1791 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1792 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1793 | } | 
|  | 1794 |  | 
|  | 1795 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1796 | SetBackgroundColor_BufferQueue_PriorColor_ZeroAlpha_DeleteBackground) { | 
|  | 1797 | bool priorColor = true; | 
|  | 1798 | bool bufferFill = false; | 
|  | 1799 | float alpha = 0; | 
|  | 1800 | Color finalColor = Color::BLACK; | 
|  | 1801 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferQueue, | 
|  | 1802 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1803 | } | 
|  | 1804 |  | 
|  | 1805 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1806 | SetBackgroundColor_BufferState_BufferFill_NoPriorColor_Basic) { | 
|  | 1807 | bool priorColor = false; | 
|  | 1808 | bool bufferFill = true; | 
|  | 1809 | float alpha = 1.0f; | 
|  | 1810 | Color finalColor = Color::RED; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1811 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1812 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1813 | } | 
|  | 1814 |  | 
|  | 1815 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1816 | SetBackgroundColor_BufferState_NoBufferFill_NoPriorColor_Basic) { | 
|  | 1817 | bool priorColor = false; | 
|  | 1818 | bool bufferFill = false; | 
|  | 1819 | float alpha = 1.0f; | 
|  | 1820 | Color finalColor = Color::GREEN; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1821 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1822 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1823 | } | 
|  | 1824 |  | 
|  | 1825 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1826 | SetBackgroundColor_BufferState_NoBufferFill_PriorColor_Basic) { | 
|  | 1827 | bool priorColor = true; | 
|  | 1828 | bool bufferFill = false; | 
|  | 1829 | float alpha = 1.0f; | 
|  | 1830 | Color finalColor = Color::GREEN; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1831 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1832 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1833 | } | 
|  | 1834 |  | 
|  | 1835 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1836 | SetBackgroundColor_BufferState_NoPriorColor_ZeroAlpha_NoEffect) { | 
|  | 1837 | bool priorColor = false; | 
|  | 1838 | bool bufferFill = false; | 
|  | 1839 | float alpha = 0; | 
|  | 1840 | Color finalColor = Color::BLACK; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1841 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1842 | priorColor, bufferFill, alpha, finalColor)); | 
|  | 1843 | } | 
|  | 1844 |  | 
|  | 1845 | TEST_P(LayerRenderTypeTransactionTest, | 
|  | 1846 | SetBackgroundColor_BufferState_PriorColor_ZeroAlpha_DeleteBackground) { | 
|  | 1847 | bool priorColor = true; | 
|  | 1848 | bool bufferFill = false; | 
|  | 1849 | float alpha = 0; | 
|  | 1850 | Color finalColor = Color::BLACK; | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 1851 | ASSERT_NO_FATAL_FAILURE(setBackgroundColorHelper(ISurfaceComposerClient::eFXSurfaceBufferState, | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 1852 | priorColor, bufferFill, alpha, finalColor)); | 
| Valerie Hau | a72e281 | 2019-01-23 13:40:39 -0800 | [diff] [blame] | 1853 | } | 
|  | 1854 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1855 | TEST_P(LayerRenderTypeTransactionTest, SetColorClamped) { | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1856 | sp<SurfaceControl> colorLayer; | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1857 | ASSERT_NO_FATAL_FAILURE(colorLayer = | 
|  | 1858 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 1859 | ISurfaceComposerClient::eFXSurfaceColor)); | 
|  | 1860 | Transaction() | 
|  | 1861 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 1862 | .setColor(colorLayer, half3(2.0f, -1.0f, 0.0f)) | 
|  | 1863 | .apply(); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1864 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1865 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1866 | } | 
|  | 1867 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1868 | TEST_P(LayerRenderTypeTransactionTest, SetColorWithAlpha) { | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1869 | sp<SurfaceControl> bufferLayer; | 
|  | 1870 | sp<SurfaceControl> colorLayer; | 
|  | 1871 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1872 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1873 | ASSERT_NO_FATAL_FAILURE(colorLayer = | 
|  | 1874 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 1875 | ISurfaceComposerClient::eFXSurfaceColor)); | 
|  | 1876 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1877 |  | 
|  | 1878 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); | 
|  | 1879 | const float alpha = 0.25f; | 
|  | 1880 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); | 
|  | 1881 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 1882 | // channel) should be less than one | 
|  | 1883 | const uint8_t tolerance = 1; | 
|  | 1884 | Transaction() | 
|  | 1885 | .setColor(colorLayer, color) | 
|  | 1886 | .setAlpha(colorLayer, alpha) | 
|  | 1887 | .setLayer(colorLayer, mLayerZBase + 1) | 
|  | 1888 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1889 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, | 
|  | 1890 | tolerance); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1891 | } | 
|  | 1892 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1893 | TEST_P(LayerRenderTypeTransactionTest, SetColorWithParentAlpha_Bug74220420) { | 
| Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1894 | sp<SurfaceControl> bufferLayer; | 
|  | 1895 | sp<SurfaceControl> parentLayer; | 
|  | 1896 | sp<SurfaceControl> colorLayer; | 
|  | 1897 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test bg", 32, 32)); | 
|  | 1898 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parentWithAlpha", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1899 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::RED, 32, 32)); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 1900 | ASSERT_NO_FATAL_FAILURE(colorLayer = createLayer("childWithColor", 0 /* buffer width */, | 
|  | 1901 | 0 /* buffer height */, | 
|  | 1902 | ISurfaceComposerClient::eFXSurfaceColor)); | 
|  | 1903 | Transaction().setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)).apply(); | 
| Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1904 | const half3 color(15.0f / 255.0f, 51.0f / 255.0f, 85.0f / 255.0f); | 
|  | 1905 | const float alpha = 0.25f; | 
|  | 1906 | const ubyte3 expected((vec3(color) * alpha + vec3(1.0f, 0.0f, 0.0f) * (1.0f - alpha)) * 255.0f); | 
|  | 1907 | // this is handwavy, but the precision loss scaled by 255 (8-bit per | 
|  | 1908 | // channel) should be less than one | 
|  | 1909 | const uint8_t tolerance = 1; | 
|  | 1910 | Transaction() | 
|  | 1911 | .reparent(colorLayer, parentLayer->getHandle()) | 
|  | 1912 | .setColor(colorLayer, color) | 
|  | 1913 | .setAlpha(parentLayer, alpha) | 
|  | 1914 | .setLayer(parentLayer, mLayerZBase + 1) | 
|  | 1915 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1916 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), {expected.r, expected.g, expected.b, 255}, | 
|  | 1917 | tolerance); | 
| Adrian Roos | b7a9650 | 2018-04-08 11:38:55 -0700 | [diff] [blame] | 1918 | } | 
|  | 1919 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1920 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetColorWithBuffer) { | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1921 | sp<SurfaceControl> bufferLayer; | 
|  | 1922 | ASSERT_NO_FATAL_FAILURE(bufferLayer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1923 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(bufferLayer, Color::RED, 32, 32)); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1924 |  | 
|  | 1925 | // color is ignored | 
|  | 1926 | Transaction().setColor(bufferLayer, half3(0.0f, 1.0f, 0.0f)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1927 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | e4ef610 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 1928 | } | 
|  | 1929 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1930 | TEST_P(LayerTypeAndRenderTypeTransactionTest, SetLayerStackBasic) { | 
| Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1931 | sp<SurfaceControl> layer; | 
|  | 1932 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 1933 | ASSERT_NO_FATAL_FAILURE(fillLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1934 |  | 
|  | 1935 | Transaction().setLayerStack(layer, mDisplayLayerStack + 1).apply(); | 
|  | 1936 | { | 
|  | 1937 | SCOPED_TRACE("non-existing layer stack"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1938 | getScreenCapture()->expectColor(mDisplayRect, Color::BLACK); | 
| Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1939 | } | 
|  | 1940 |  | 
|  | 1941 | Transaction().setLayerStack(layer, mDisplayLayerStack).apply(); | 
|  | 1942 | { | 
|  | 1943 | SCOPED_TRACE("original layer stack"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1944 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 3d22f3a | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1945 | } | 
|  | 1946 | } | 
|  | 1947 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1948 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixBasic_BufferQueue) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1949 | sp<SurfaceControl> layer; | 
|  | 1950 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1951 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 1952 | Color::BLUE, Color::WHITE)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1953 |  | 
|  | 1954 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 0, 0).apply(); | 
|  | 1955 | { | 
|  | 1956 | SCOPED_TRACE("IDENTITY"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1957 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 1958 | Color::BLUE, Color::WHITE); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1959 | } | 
|  | 1960 |  | 
|  | 1961 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).setPosition(layer, 32, 0).apply(); | 
|  | 1962 | { | 
|  | 1963 | SCOPED_TRACE("FLIP_H"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1964 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, | 
|  | 1965 | Color::WHITE, Color::BLUE); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1966 | } | 
|  | 1967 |  | 
|  | 1968 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).setPosition(layer, 0, 32).apply(); | 
|  | 1969 | { | 
|  | 1970 | SCOPED_TRACE("FLIP_V"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1971 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, | 
|  | 1972 | Color::RED, Color::GREEN); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1973 | } | 
|  | 1974 |  | 
|  | 1975 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).setPosition(layer, 32, 0).apply(); | 
|  | 1976 | { | 
|  | 1977 | SCOPED_TRACE("ROT_90"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1978 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, | 
|  | 1979 | Color::WHITE, Color::GREEN); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1980 | } | 
|  | 1981 |  | 
|  | 1982 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setPosition(layer, 0, 0).apply(); | 
|  | 1983 | { | 
|  | 1984 | SCOPED_TRACE("SCALE"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1985 | getScreenCapture()->expectQuadrant(Rect(0, 0, 64, 64), Color::RED, Color::GREEN, | 
|  | 1986 | Color::BLUE, Color::WHITE, true /* filtered */); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 1987 | } | 
|  | 1988 | } | 
|  | 1989 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 1990 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixBasic_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 1991 | sp<SurfaceControl> layer; | 
|  | 1992 | ASSERT_NO_FATAL_FAILURE( | 
|  | 1993 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 1994 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 1995 | Color::BLUE, Color::WHITE)); | 
|  | 1996 |  | 
|  | 1997 | Transaction() | 
|  | 1998 | .setMatrix(layer, 1.0f, 0.0f, 0.0f, 1.0f) | 
|  | 1999 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
|  | 2000 | .apply(); | 
|  | 2001 | { | 
|  | 2002 | SCOPED_TRACE("IDENTITY"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2003 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 2004 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2005 | } | 
|  | 2006 |  | 
|  | 2007 | Transaction().setMatrix(layer, -1.0f, 0.0f, 0.0f, 1.0f).apply(); | 
|  | 2008 | { | 
|  | 2009 | SCOPED_TRACE("FLIP_H"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2010 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 2011 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2012 | } | 
|  | 2013 |  | 
|  | 2014 | Transaction().setMatrix(layer, 1.0f, 0.0f, 0.0f, -1.0f).apply(); | 
|  | 2015 | { | 
|  | 2016 | SCOPED_TRACE("FLIP_V"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2017 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 2018 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2019 | } | 
|  | 2020 |  | 
|  | 2021 | Transaction().setMatrix(layer, 0.0f, 1.0f, -1.0f, 0.0f).apply(); | 
|  | 2022 | { | 
|  | 2023 | SCOPED_TRACE("ROT_90"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2024 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 2025 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2026 | } | 
|  | 2027 |  | 
|  | 2028 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).apply(); | 
|  | 2029 | { | 
|  | 2030 | SCOPED_TRACE("SCALE"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2031 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::RED, Color::GREEN, | 
|  | 2032 | Color::BLUE, Color::WHITE); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2033 | } | 
|  | 2034 | } | 
|  | 2035 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2036 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixRot45_BufferQueue) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2037 | sp<SurfaceControl> layer; | 
|  | 2038 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2039 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 2040 | Color::BLUE, Color::WHITE)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2041 |  | 
|  | 2042 | const float rot = M_SQRT1_2; // 45 degrees | 
|  | 2043 | const float trans = M_SQRT2 * 16.0f; | 
|  | 2044 | Transaction().setMatrix(layer, rot, rot, -rot, rot).setPosition(layer, trans, 0).apply(); | 
|  | 2045 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2046 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2047 | // check a 8x8 region inside each color | 
|  | 2048 | auto get8x8Rect = [](int32_t centerX, int32_t centerY) { | 
|  | 2049 | const int32_t halfL = 4; | 
|  | 2050 | return Rect(centerX - halfL, centerY - halfL, centerX + halfL, centerY + halfL); | 
|  | 2051 | }; | 
|  | 2052 | const int32_t unit = int32_t(trans / 2); | 
|  | 2053 | shot->expectColor(get8x8Rect(2 * unit, 1 * unit), Color::RED); | 
|  | 2054 | shot->expectColor(get8x8Rect(3 * unit, 2 * unit), Color::GREEN); | 
|  | 2055 | shot->expectColor(get8x8Rect(1 * unit, 2 * unit), Color::BLUE); | 
|  | 2056 | shot->expectColor(get8x8Rect(2 * unit, 3 * unit), Color::WHITE); | 
|  | 2057 | } | 
|  | 2058 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2059 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixWithResize_BufferQueue) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2060 | sp<SurfaceControl> layer; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2061 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 2062 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2063 |  | 
|  | 2064 | // setMatrix is applied after any pending resize, unlike setPosition | 
|  | 2065 | Transaction().setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f).setSize(layer, 64, 64).apply(); | 
|  | 2066 | { | 
|  | 2067 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2068 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2069 | const Rect rect(0, 0, 32, 32); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2070 | shot->expectColor(rect, Color::RED); | 
|  | 2071 | shot->expectBorder(rect, Color::BLACK); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2072 | } | 
|  | 2073 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2074 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 64, 64)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2075 | { | 
|  | 2076 | SCOPED_TRACE("resize applied"); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2077 | const Rect rect(0, 0, 128, 128); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2078 | getScreenCapture()->expectColor(rect, Color::RED); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2079 | } | 
|  | 2080 | } | 
|  | 2081 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2082 | TEST_P(LayerRenderTypeTransactionTest, SetMatrixWithScaleToWindow_BufferQueue) { | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2083 | sp<SurfaceControl> layer; | 
|  | 2084 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2085 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2086 |  | 
|  | 2087 | // setMatrix is immediate with SCALE_TO_WINDOW, unlike setPosition | 
|  | 2088 | Transaction() | 
|  | 2089 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) | 
|  | 2090 | .setSize(layer, 64, 64) | 
|  | 2091 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 2092 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2093 | getScreenCapture()->expectColor(Rect(0, 0, 128, 128), Color::RED); | 
| Chia-I Wu | 93853fe | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2094 | } | 
|  | 2095 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2096 | TEST_P(LayerRenderTypeTransactionTest, SetOverrideScalingModeBasic_BufferQueue) { | 
| Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 2097 | sp<SurfaceControl> layer; | 
|  | 2098 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2099 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 2100 | Color::BLUE, Color::WHITE)); | 
| Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 2101 |  | 
|  | 2102 | // XXX SCALE_CROP is not respected; calling setSize and | 
|  | 2103 | // setOverrideScalingMode in separate transactions does not work | 
|  | 2104 | // (b/69315456) | 
|  | 2105 | Transaction() | 
|  | 2106 | .setSize(layer, 64, 16) | 
|  | 2107 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 2108 | .apply(); | 
|  | 2109 | { | 
|  | 2110 | SCOPED_TRACE("SCALE_TO_WINDOW"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2111 | getScreenCapture()->expectQuadrant(Rect(0, 0, 64, 16), Color::RED, Color::GREEN, | 
|  | 2112 | Color::BLUE, Color::WHITE, true /* filtered */); | 
| Chia-I Wu | a56b204 | 2017-11-01 15:16:35 -0700 | [diff] [blame] | 2113 | } | 
|  | 2114 | } | 
|  | 2115 |  | 
| Dan Stoza | 000dd01 | 2018-08-01 13:31:52 -0700 | [diff] [blame] | 2116 | TEST_P(LayerTypeTransactionTest, RefreshRateIsInitialized) { | 
|  | 2117 | sp<SurfaceControl> layer; | 
|  | 2118 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 2119 |  | 
|  | 2120 | sp<IBinder> handle = layer->getHandle(); | 
|  | 2121 | ASSERT_TRUE(handle != nullptr); | 
|  | 2122 |  | 
|  | 2123 | FrameStats frameStats; | 
|  | 2124 | mClient->getLayerFrameStats(handle, &frameStats); | 
|  | 2125 |  | 
|  | 2126 | ASSERT_GT(frameStats.refreshPeriodNano, static_cast<nsecs_t>(0)); | 
|  | 2127 | } | 
|  | 2128 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2129 | TEST_P(LayerRenderTypeTransactionTest, SetCropBasic_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2130 | sp<SurfaceControl> layer; | 
|  | 2131 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2132 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2133 | const Rect crop(8, 8, 24, 24); | 
|  | 2134 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2135 | Transaction().setCrop_legacy(layer, crop).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2136 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2137 | shot->expectColor(crop, Color::RED); | 
|  | 2138 | shot->expectBorder(crop, Color::BLACK); | 
|  | 2139 | } | 
|  | 2140 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2141 | TEST_P(LayerRenderTypeTransactionTest, SetCropBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2142 | sp<SurfaceControl> layer; | 
|  | 2143 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2144 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2145 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2146 | const Rect crop(8, 8, 24, 24); | 
|  | 2147 |  | 
|  | 2148 | Transaction().setCrop(layer, crop).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2149 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2150 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2151 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2152 | } | 
|  | 2153 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2154 | TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2155 | sp<SurfaceControl> layer; | 
|  | 2156 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2157 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2158 |  | 
|  | 2159 | { | 
|  | 2160 | SCOPED_TRACE("empty rect"); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2161 | Transaction().setCrop_legacy(layer, Rect(8, 8, 8, 8)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2162 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2163 | } | 
|  | 2164 |  | 
|  | 2165 | { | 
|  | 2166 | SCOPED_TRACE("negative rect"); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2167 | Transaction().setCrop_legacy(layer, Rect(8, 8, 0, 0)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2168 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2169 | } | 
|  | 2170 | } | 
|  | 2171 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2172 | TEST_P(LayerRenderTypeTransactionTest, SetCropEmpty_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2173 | sp<SurfaceControl> layer; | 
|  | 2174 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2175 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2176 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2177 |  | 
|  | 2178 | { | 
|  | 2179 | SCOPED_TRACE("empty rect"); | 
|  | 2180 | Transaction().setCrop(layer, Rect(8, 8, 8, 8)).apply(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2181 | getScreenCapture()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2182 | } | 
|  | 2183 |  | 
|  | 2184 | { | 
|  | 2185 | SCOPED_TRACE("negative rect"); | 
|  | 2186 | Transaction().setCrop(layer, Rect(8, 8, 0, 0)).apply(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2187 | getScreenCapture()->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2188 | } | 
|  | 2189 | } | 
|  | 2190 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2191 | TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2192 | sp<SurfaceControl> layer; | 
|  | 2193 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2194 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2195 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2196 | Transaction().setCrop_legacy(layer, Rect(-128, -64, 128, 64)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2197 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2198 | shot->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
|  | 2199 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2200 | } | 
|  | 2201 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2202 | TEST_P(LayerRenderTypeTransactionTest, SetCropOutOfBounds_BufferState) { | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2203 | sp<SurfaceControl> layer; | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2204 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2205 | layer = createLayer("test", 32, 64, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2206 | sp<GraphicBuffer> buffer = | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2207 | new GraphicBuffer(32, 64, PIXEL_FORMAT_RGBA_8888, 1, | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2208 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2209 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2210 | "test"); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2211 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 16), Color::BLUE); | 
|  | 2212 | fillGraphicBufferColor(buffer, Rect(0, 16, 32, 64), Color::RED); | 
|  | 2213 |  | 
|  | 2214 | Transaction().setFrame(layer, Rect(0, 0, 64, 64)).apply(); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2215 |  | 
|  | 2216 | Transaction().setBuffer(layer, buffer).apply(); | 
|  | 2217 |  | 
|  | 2218 | // Partially out of bounds in the negative (upper left) direction | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2219 | Transaction().setCrop(layer, Rect(-128, -128, 32, 16)).apply(); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2220 | { | 
|  | 2221 | SCOPED_TRACE("out of bounds, negative (upper left) direction"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2222 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2223 | shot->expectColor(Rect(0, 0, 64, 64), Color::BLUE); | 
|  | 2224 | shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2225 | } | 
|  | 2226 |  | 
|  | 2227 | // Partially out of bounds in the positive (lower right) direction | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2228 | Transaction().setCrop(layer, Rect(0, 16, 128, 128)).apply(); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2229 | { | 
|  | 2230 | SCOPED_TRACE("out of bounds, positive (lower right) direction"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2231 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2232 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); | 
|  | 2233 | shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2234 | } | 
|  | 2235 |  | 
|  | 2236 | // Fully out of buffer space bounds | 
|  | 2237 | Transaction().setCrop(layer, Rect(-128, -128, -1, -1)).apply(); | 
|  | 2238 | { | 
|  | 2239 | SCOPED_TRACE("Fully out of bounds"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2240 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2241 | shot->expectColor(Rect(0, 0, 64, 16), Color::BLUE); | 
|  | 2242 | shot->expectColor(Rect(0, 16, 64, 64), Color::RED); | 
|  | 2243 | shot->expectBorder(Rect(0, 0, 64, 64), Color::BLACK); | 
| Valerie Hau | 0bc0915 | 2018-12-20 07:42:47 -0800 | [diff] [blame] | 2244 | } | 
|  | 2245 | } | 
|  | 2246 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2247 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithTranslation_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2248 | sp<SurfaceControl> layer; | 
|  | 2249 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2250 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2251 |  | 
|  | 2252 | const Point position(32, 32); | 
|  | 2253 | const Rect crop(8, 8, 24, 24); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2254 | Transaction().setPosition(layer, position.x, position.y).setCrop_legacy(layer, crop).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2255 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2256 | shot->expectColor(crop + position, Color::RED); | 
|  | 2257 | shot->expectBorder(crop + position, Color::BLACK); | 
|  | 2258 | } | 
|  | 2259 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2260 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithTranslation_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2261 | sp<SurfaceControl> layer; | 
|  | 2262 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2263 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2264 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2265 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2266 | const Rect frame(32, 32, 64, 64); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2267 | const Rect crop(8, 8, 24, 24); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2268 | Transaction().setFrame(layer, frame).setCrop(layer, crop).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2269 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2270 | shot->expectColor(frame, Color::RED); | 
|  | 2271 | shot->expectBorder(frame, Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2272 | } | 
|  | 2273 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2274 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithScale_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2275 | sp<SurfaceControl> layer; | 
|  | 2276 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2277 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2278 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2279 | // crop_legacy is affected by matrix | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2280 | Transaction() | 
|  | 2281 | .setMatrix(layer, 2.0f, 0.0f, 0.0f, 2.0f) | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2282 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2283 | .apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2284 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2285 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); | 
|  | 2286 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); | 
|  | 2287 | } | 
|  | 2288 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2289 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithResize_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2290 | sp<SurfaceControl> layer; | 
|  | 2291 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2292 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2293 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2294 | // setCrop_legacy is applied immediately by default, with or without resize pending | 
|  | 2295 | 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] | 2296 | { | 
|  | 2297 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2298 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2299 | shot->expectColor(Rect(8, 8, 24, 24), Color::RED); | 
|  | 2300 | shot->expectBorder(Rect(8, 8, 24, 24), Color::BLACK); | 
|  | 2301 | } | 
|  | 2302 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2303 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2304 | { | 
|  | 2305 | SCOPED_TRACE("resize applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2306 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2307 | shot->expectColor(Rect(8, 8, 16, 16), Color::RED); | 
|  | 2308 | shot->expectBorder(Rect(8, 8, 16, 16), Color::BLACK); | 
|  | 2309 | } | 
|  | 2310 | } | 
|  | 2311 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2312 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithNextResize_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2313 | sp<SurfaceControl> layer; | 
|  | 2314 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2315 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2316 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2317 | // request setCrop_legacy to be applied with the next resize | 
|  | 2318 | Transaction() | 
|  | 2319 | .setCrop_legacy(layer, Rect(8, 8, 24, 24)) | 
|  | 2320 | .setGeometryAppliesWithResize(layer) | 
|  | 2321 | .apply(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2322 | { | 
|  | 2323 | SCOPED_TRACE("waiting for next resize"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2324 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2325 | } | 
|  | 2326 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2327 | Transaction().setCrop_legacy(layer, Rect(4, 4, 12, 12)).apply(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2328 | { | 
|  | 2329 | SCOPED_TRACE("pending crop modified"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2330 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2331 | } | 
|  | 2332 |  | 
|  | 2333 | Transaction().setSize(layer, 16, 16).apply(); | 
|  | 2334 | { | 
|  | 2335 | SCOPED_TRACE("resize pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2336 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::RED); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2337 | } | 
|  | 2338 |  | 
|  | 2339 | // finally resize | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2340 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2341 | { | 
|  | 2342 | SCOPED_TRACE("new crop applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2343 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2344 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); | 
|  | 2345 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); | 
|  | 2346 | } | 
|  | 2347 | } | 
|  | 2348 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2349 | TEST_P(LayerRenderTypeTransactionTest, SetCropWithNextResizeScaleToWindow_BufferQueue) { | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2350 | sp<SurfaceControl> layer; | 
|  | 2351 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2352 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2353 |  | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2354 | // setCrop_legacy is not immediate even with SCALE_TO_WINDOW override | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2355 | Transaction() | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 2356 | .setCrop_legacy(layer, Rect(4, 4, 12, 12)) | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2357 | .setSize(layer, 16, 16) | 
|  | 2358 | .setOverrideScalingMode(layer, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW) | 
|  | 2359 | .setGeometryAppliesWithResize(layer) | 
|  | 2360 | .apply(); | 
|  | 2361 | { | 
|  | 2362 | SCOPED_TRACE("new crop pending"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2363 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2364 | shot->expectColor(Rect(0, 0, 16, 16), Color::RED); | 
|  | 2365 | shot->expectBorder(Rect(0, 0, 16, 16), Color::BLACK); | 
|  | 2366 | } | 
|  | 2367 |  | 
|  | 2368 | // XXX crop is never latched without other geometry change (b/69315677) | 
|  | 2369 | Transaction().setPosition(layer, 1, 0).setGeometryAppliesWithResize(layer).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2370 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 16, 16)); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2371 | Transaction().setPosition(layer, 0, 0).apply(); | 
|  | 2372 | { | 
|  | 2373 | SCOPED_TRACE("new crop applied"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2374 | auto shot = getScreenCapture(); | 
| Chia-I Wu | 04dcca8 | 2017-11-02 08:30:27 -0700 | [diff] [blame] | 2375 | shot->expectColor(Rect(4, 4, 12, 12), Color::RED); | 
|  | 2376 | shot->expectBorder(Rect(4, 4, 12, 12), Color::BLACK); | 
|  | 2377 | } | 
|  | 2378 | } | 
|  | 2379 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2380 | TEST_P(LayerRenderTypeTransactionTest, SetFrameBasic_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2381 | sp<SurfaceControl> layer; | 
|  | 2382 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2383 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2384 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2385 | const Rect frame(8, 8, 24, 24); | 
|  | 2386 |  | 
|  | 2387 | Transaction().setFrame(layer, frame).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2388 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2389 | shot->expectColor(frame, Color::RED); | 
|  | 2390 | shot->expectBorder(frame, Color::BLACK); | 
|  | 2391 | } | 
|  | 2392 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2393 | TEST_P(LayerRenderTypeTransactionTest, SetFrameEmpty_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2394 | sp<SurfaceControl> layer; | 
|  | 2395 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2396 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2397 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2398 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2399 | { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2400 | SCOPED_TRACE("empty rect"); | 
|  | 2401 | Transaction().setFrame(layer, Rect(8, 8, 8, 8)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2402 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2403 | } | 
|  | 2404 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2405 | { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2406 | SCOPED_TRACE("negative rect"); | 
|  | 2407 | Transaction().setFrame(layer, Rect(8, 8, 0, 0)).apply(); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2408 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2409 | } | 
|  | 2410 | } | 
|  | 2411 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2412 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultParentless_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2413 | sp<SurfaceControl> layer; | 
|  | 2414 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2415 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2416 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 10, 10)); | 
|  | 2417 |  | 
|  | 2418 | // 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] | 2419 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2420 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2421 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2422 | } | 
|  | 2423 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2424 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultBSParent_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2425 | sp<SurfaceControl> parent, child; | 
|  | 2426 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2427 | parent = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2428 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(parent, Color::RED, 32, 32)); | 
|  | 2429 | Transaction().setFrame(parent, Rect(0, 0, 32, 32)).apply(); | 
|  | 2430 |  | 
|  | 2431 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2432 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2433 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); | 
|  | 2434 |  | 
|  | 2435 | Transaction().reparent(child, parent->getHandle()).apply(); | 
|  | 2436 |  | 
|  | 2437 | // A layer will default to the frame of its parent | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2438 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2439 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 2440 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2441 | } | 
|  | 2442 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2443 | TEST_P(LayerRenderTypeTransactionTest, SetFrameDefaultBQParent_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2444 | sp<SurfaceControl> parent, child; | 
|  | 2445 | ASSERT_NO_FATAL_FAILURE(parent = createLayer("test", 32, 32)); | 
|  | 2446 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(parent, Color::RED, 32, 32)); | 
|  | 2447 |  | 
|  | 2448 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2449 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2450 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); | 
|  | 2451 |  | 
|  | 2452 | Transaction().reparent(child, parent->getHandle()).apply(); | 
|  | 2453 |  | 
|  | 2454 | // A layer will default to the frame of its parent | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2455 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2456 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 2457 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2458 | } | 
|  | 2459 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2460 | TEST_P(LayerRenderTypeTransactionTest, SetFrameUpdate_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2461 | sp<SurfaceControl> layer; | 
|  | 2462 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2463 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2464 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2465 | Transaction().setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
|  | 2466 |  | 
|  | 2467 | std::this_thread::sleep_for(500ms); | 
|  | 2468 |  | 
|  | 2469 | Transaction().setFrame(layer, Rect(16, 16, 48, 48)).apply(); | 
|  | 2470 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2471 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2472 | shot->expectColor(Rect(16, 16, 48, 48), Color::RED); | 
|  | 2473 | shot->expectBorder(Rect(16, 16, 48, 48), Color::BLACK); | 
|  | 2474 | } | 
|  | 2475 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2476 | TEST_P(LayerRenderTypeTransactionTest, SetFrameOutsideBounds_BufferState) { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2477 | sp<SurfaceControl> parent, child; | 
|  | 2478 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2479 | parent = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2480 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2481 | child = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2482 | Transaction().reparent(child, parent->getHandle()).apply(); | 
|  | 2483 |  | 
|  | 2484 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(parent, Color::RED, 32, 32)); | 
|  | 2485 | Transaction().setFrame(parent, Rect(0, 0, 32, 32)).apply(); | 
|  | 2486 |  | 
|  | 2487 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(child, Color::BLUE, 10, 10)); | 
|  | 2488 | Transaction().setFrame(child, Rect(0, 16, 32, 32)).apply(); | 
|  | 2489 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2490 | auto shot = getScreenCapture(); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2491 | shot->expectColor(Rect(0, 0, 32, 16), Color::RED); | 
|  | 2492 | shot->expectColor(Rect(0, 16, 32, 32), Color::BLUE); | 
|  | 2493 | shot->expectBorder(Rect(0, 0, 32, 32), Color::BLACK); | 
|  | 2494 | } | 
|  | 2495 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2496 | TEST_P(LayerRenderTypeTransactionTest, SetBufferBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2497 | sp<SurfaceControl> layer; | 
|  | 2498 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2499 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2500 |  | 
|  | 2501 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2502 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2503 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2504 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2505 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2506 | } | 
|  | 2507 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2508 | TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleBuffers_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2509 | sp<SurfaceControl> layer; | 
|  | 2510 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2511 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2512 |  | 
|  | 2513 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2514 |  | 
|  | 2515 | { | 
|  | 2516 | SCOPED_TRACE("set buffer 1"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2517 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2518 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2519 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2520 | } | 
|  | 2521 |  | 
|  | 2522 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::BLUE, 32, 32)); | 
|  | 2523 |  | 
|  | 2524 | { | 
|  | 2525 | SCOPED_TRACE("set buffer 2"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2526 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2527 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLUE); | 
|  | 2528 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2529 | } | 
|  | 2530 |  | 
|  | 2531 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2532 |  | 
|  | 2533 | { | 
|  | 2534 | SCOPED_TRACE("set buffer 3"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2535 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2536 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2537 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2538 | } | 
|  | 2539 | } | 
|  | 2540 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2541 | TEST_P(LayerRenderTypeTransactionTest, SetBufferMultipleLayers_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2542 | sp<SurfaceControl> layer1; | 
|  | 2543 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2544 | layer1 = createLayer("test", 64, 64, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2545 |  | 
|  | 2546 | sp<SurfaceControl> layer2; | 
|  | 2547 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2548 | layer2 = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2549 |  | 
|  | 2550 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::RED, 64, 64)); | 
|  | 2551 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2552 | Transaction().setFrame(layer1, Rect(0, 0, 64, 64)).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2553 | { | 
|  | 2554 | SCOPED_TRACE("set layer 1 buffer red"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2555 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2556 | shot->expectColor(Rect(0, 0, 64, 64), Color::RED); | 
|  | 2557 | } | 
|  | 2558 |  | 
|  | 2559 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::BLUE, 32, 32)); | 
|  | 2560 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2561 | Transaction().setFrame(layer2, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2562 | { | 
|  | 2563 | SCOPED_TRACE("set layer 2 buffer blue"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2564 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2565 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 2566 | shot->expectColor(Rect(0, 32, 64, 64), Color::RED); | 
|  | 2567 | shot->expectColor(Rect(0, 32, 32, 64), Color::RED); | 
|  | 2568 | } | 
|  | 2569 |  | 
|  | 2570 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer1, Color::GREEN, 64, 64)); | 
|  | 2571 | { | 
|  | 2572 | SCOPED_TRACE("set layer 1 buffer green"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2573 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2574 | shot->expectColor(Rect(0, 0, 32, 32), Color::BLUE); | 
|  | 2575 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); | 
|  | 2576 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); | 
|  | 2577 | } | 
|  | 2578 |  | 
|  | 2579 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer2, Color::WHITE, 32, 32)); | 
|  | 2580 |  | 
|  | 2581 | { | 
|  | 2582 | SCOPED_TRACE("set layer 2 buffer white"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2583 | auto shot = getScreenCapture(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2584 | shot->expectColor(Rect(0, 0, 32, 32), Color::WHITE); | 
|  | 2585 | shot->expectColor(Rect(0, 32, 64, 64), Color::GREEN); | 
|  | 2586 | shot->expectColor(Rect(0, 32, 32, 64), Color::GREEN); | 
|  | 2587 | } | 
|  | 2588 | } | 
|  | 2589 |  | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 2590 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_BufferState) { | 
| Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2591 | sp<SurfaceControl> layer; | 
|  | 2592 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2593 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2594 |  | 
|  | 2595 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; | 
|  | 2596 |  | 
|  | 2597 | std::array<sp<GraphicBuffer>, 10> buffers; | 
|  | 2598 |  | 
|  | 2599 | size_t idx = 0; | 
|  | 2600 | for (auto& buffer : buffers) { | 
|  | 2601 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2602 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2603 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2604 | "test"); | 
|  | 2605 | Color color = colors[idx % colors.size()]; | 
|  | 2606 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); | 
|  | 2607 | idx++; | 
|  | 2608 | } | 
|  | 2609 |  | 
|  | 2610 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the | 
|  | 2611 | // cache is working. | 
|  | 2612 | idx = 0; | 
|  | 2613 | for (auto& buffer : buffers) { | 
|  | 2614 | for (int i = 0; i < 2; i++) { | 
|  | 2615 | Transaction().setBuffer(layer, buffer).apply(); | 
|  | 2616 |  | 
|  | 2617 | Color color = colors[idx % colors.size()]; | 
|  | 2618 | auto shot = screenshot(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2619 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), color); | 
|  | 2620 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2621 | } | 
|  | 2622 | idx++; | 
|  | 2623 | } | 
|  | 2624 | } | 
|  | 2625 |  | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 2626 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_LeastRecentlyUsed_BufferState) { | 
| Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2627 | sp<SurfaceControl> layer; | 
|  | 2628 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2629 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2630 |  | 
|  | 2631 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; | 
|  | 2632 |  | 
|  | 2633 | std::array<sp<GraphicBuffer>, 70> buffers; | 
|  | 2634 |  | 
|  | 2635 | size_t idx = 0; | 
|  | 2636 | for (auto& buffer : buffers) { | 
|  | 2637 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2638 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2639 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2640 | "test"); | 
|  | 2641 | Color color = colors[idx % colors.size()]; | 
|  | 2642 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); | 
|  | 2643 | idx++; | 
|  | 2644 | } | 
|  | 2645 |  | 
|  | 2646 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the | 
|  | 2647 | // cache is working. | 
|  | 2648 | idx = 0; | 
|  | 2649 | for (auto& buffer : buffers) { | 
|  | 2650 | for (int i = 0; i < 2; i++) { | 
|  | 2651 | Transaction().setBuffer(layer, buffer).apply(); | 
|  | 2652 |  | 
|  | 2653 | Color color = colors[idx % colors.size()]; | 
|  | 2654 | auto shot = screenshot(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2655 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), color); | 
|  | 2656 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2657 | } | 
|  | 2658 | idx++; | 
|  | 2659 | } | 
|  | 2660 | } | 
|  | 2661 |  | 
| Valerie Hau | a6b15a1 | 2019-02-05 14:16:30 -0800 | [diff] [blame] | 2662 | TEST_P(LayerRenderTypeTransactionTest, SetBufferCaching_DestroyedBuffer_BufferState) { | 
| Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2663 | sp<SurfaceControl> layer; | 
|  | 2664 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2665 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2666 |  | 
|  | 2667 | std::array<Color, 4> colors = {Color::RED, Color::BLUE, Color::WHITE, Color::GREEN}; | 
|  | 2668 |  | 
|  | 2669 | std::array<sp<GraphicBuffer>, 65> buffers; | 
|  | 2670 |  | 
|  | 2671 | size_t idx = 0; | 
|  | 2672 | for (auto& buffer : buffers) { | 
|  | 2673 | buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2674 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2675 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2676 | "test"); | 
|  | 2677 | Color color = colors[idx % colors.size()]; | 
|  | 2678 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color); | 
|  | 2679 | idx++; | 
|  | 2680 | } | 
|  | 2681 |  | 
|  | 2682 | // Set each buffer twice. The first time adds it to the cache, the second time tests that the | 
|  | 2683 | // cache is working. | 
|  | 2684 | idx = 0; | 
|  | 2685 | for (auto& buffer : buffers) { | 
|  | 2686 | for (int i = 0; i < 2; i++) { | 
|  | 2687 | Transaction().setBuffer(layer, buffer).apply(); | 
|  | 2688 |  | 
|  | 2689 | Color color = colors[idx % colors.size()]; | 
|  | 2690 | auto shot = screenshot(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2691 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), color); | 
|  | 2692 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 7341162 | 2019-01-25 10:45:41 -0800 | [diff] [blame] | 2693 | } | 
|  | 2694 | if (idx == 0) { | 
|  | 2695 | buffers[0].clear(); | 
|  | 2696 | } | 
|  | 2697 | idx++; | 
|  | 2698 | } | 
|  | 2699 | } | 
|  | 2700 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2701 | TEST_P(LayerRenderTypeTransactionTest, SetTransformRotate90_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2702 | sp<SurfaceControl> layer; | 
|  | 2703 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2704 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2705 |  | 
|  | 2706 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 2707 | Color::BLUE, Color::WHITE)); | 
|  | 2708 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2709 | Transaction() | 
|  | 2710 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
|  | 2711 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_ROT_90) | 
|  | 2712 | .apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2713 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2714 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::RED, Color::WHITE, | 
|  | 2715 | Color::GREEN, true /* filtered */); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2716 | } | 
|  | 2717 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2718 | TEST_P(LayerRenderTypeTransactionTest, SetTransformFlipH_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2719 | sp<SurfaceControl> layer; | 
|  | 2720 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2721 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2722 |  | 
|  | 2723 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 2724 | Color::BLUE, Color::WHITE)); | 
|  | 2725 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2726 | Transaction() | 
|  | 2727 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
|  | 2728 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_H) | 
|  | 2729 | .apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2730 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2731 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::GREEN, Color::RED, Color::WHITE, | 
|  | 2732 | Color::BLUE, true /* filtered */); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2733 | } | 
|  | 2734 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2735 | TEST_P(LayerRenderTypeTransactionTest, SetTransformFlipV_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2736 | sp<SurfaceControl> layer; | 
|  | 2737 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2738 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2739 |  | 
|  | 2740 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerQuadrant(layer, 32, 32, Color::RED, Color::GREEN, | 
|  | 2741 | Color::BLUE, Color::WHITE)); | 
|  | 2742 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 2743 | Transaction() | 
|  | 2744 | .setFrame(layer, Rect(0, 0, 32, 32)) | 
|  | 2745 | .setTransform(layer, NATIVE_WINDOW_TRANSFORM_FLIP_V) | 
|  | 2746 | .apply(); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2747 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2748 | getScreenCapture()->expectQuadrant(Rect(0, 0, 32, 32), Color::BLUE, Color::WHITE, Color::RED, | 
|  | 2749 | Color::GREEN, true /* filtered */); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2750 | } | 
|  | 2751 |  | 
|  | 2752 | TEST_F(LayerTransactionTest, SetTransformToDisplayInverse_BufferState) { | 
|  | 2753 | sp<SurfaceControl> layer; | 
|  | 2754 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2755 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2756 |  | 
|  | 2757 | Transaction().setTransformToDisplayInverse(layer, false).apply(); | 
|  | 2758 |  | 
|  | 2759 | ASSERT_NO_FATAL_FAILURE(fillBufferStateLayerColor(layer, Color::GREEN, 32, 32)); | 
|  | 2760 |  | 
|  | 2761 | Transaction().setTransformToDisplayInverse(layer, true).apply(); | 
|  | 2762 | } | 
|  | 2763 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2764 | TEST_P(LayerRenderTypeTransactionTest, SetFenceBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2765 | sp<SurfaceControl> layer; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2766 | Transaction transaction; | 
|  | 2767 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2768 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2769 |  | 
|  | 2770 | sp<GraphicBuffer> buffer = | 
|  | 2771 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2772 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2773 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2774 | "test"); | 
|  | 2775 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2776 |  | 
|  | 2777 | sp<Fence> fence; | 
|  | 2778 | if (getBuffer(nullptr, &fence) != NO_ERROR) { | 
|  | 2779 | GTEST_SUCCEED() << "test not supported"; | 
|  | 2780 | return; | 
|  | 2781 | } | 
|  | 2782 |  | 
|  | 2783 | Transaction().setBuffer(layer, buffer).setAcquireFence(layer, fence).apply(); | 
|  | 2784 |  | 
|  | 2785 | status_t status = fence->wait(1000); | 
|  | 2786 | ASSERT_NE(static_cast<status_t>(Fence::Status::Unsignaled), status); | 
|  | 2787 | std::this_thread::sleep_for(200ms); | 
|  | 2788 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2789 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2790 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2791 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2792 | } | 
|  | 2793 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2794 | TEST_P(LayerRenderTypeTransactionTest, SetFenceNull_BufferState) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 2795 | sp<SurfaceControl> layer; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2796 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2797 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2798 |  | 
|  | 2799 | sp<GraphicBuffer> buffer = | 
|  | 2800 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2801 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2802 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2803 | "test"); | 
|  | 2804 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2805 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 2806 | sp<Fence> fence = Fence::NO_FENCE; | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2807 |  | 
|  | 2808 | Transaction() | 
|  | 2809 | .setBuffer(layer, buffer) | 
|  | 2810 | .setAcquireFence(layer, fence) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2811 | .apply(); | 
|  | 2812 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2813 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2814 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2815 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2816 | } | 
|  | 2817 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2818 | TEST_P(LayerRenderTypeTransactionTest, SetDataspaceBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2819 | sp<SurfaceControl> layer; | 
|  | 2820 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2821 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2822 |  | 
|  | 2823 | sp<GraphicBuffer> buffer = | 
|  | 2824 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2825 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2826 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2827 | "test"); | 
|  | 2828 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2829 |  | 
|  | 2830 | Transaction() | 
|  | 2831 | .setBuffer(layer, buffer) | 
|  | 2832 | .setDataspace(layer, ui::Dataspace::UNKNOWN) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2833 | .apply(); | 
|  | 2834 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2835 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2836 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2837 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2838 | } | 
|  | 2839 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2840 | TEST_P(LayerRenderTypeTransactionTest, SetHdrMetadataBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2841 | sp<SurfaceControl> layer; | 
|  | 2842 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2843 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2844 |  | 
|  | 2845 | sp<GraphicBuffer> buffer = | 
|  | 2846 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2847 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2848 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2849 | "test"); | 
|  | 2850 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2851 |  | 
|  | 2852 | HdrMetadata hdrMetadata; | 
|  | 2853 | hdrMetadata.validTypes = 0; | 
|  | 2854 | Transaction() | 
|  | 2855 | .setBuffer(layer, buffer) | 
|  | 2856 | .setHdrMetadata(layer, hdrMetadata) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2857 | .apply(); | 
|  | 2858 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2859 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2860 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2861 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2862 | } | 
|  | 2863 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2864 | TEST_P(LayerRenderTypeTransactionTest, SetSurfaceDamageRegionBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2865 | sp<SurfaceControl> layer; | 
|  | 2866 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2867 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2868 |  | 
|  | 2869 | sp<GraphicBuffer> buffer = | 
|  | 2870 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2871 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2872 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2873 | "test"); | 
|  | 2874 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2875 |  | 
|  | 2876 | Region region; | 
|  | 2877 | region.set(32, 32); | 
|  | 2878 | Transaction() | 
|  | 2879 | .setBuffer(layer, buffer) | 
|  | 2880 | .setSurfaceDamageRegion(layer, region) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2881 | .apply(); | 
|  | 2882 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2883 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2884 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2885 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2886 | } | 
|  | 2887 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2888 | TEST_P(LayerRenderTypeTransactionTest, SetApiBasic_BufferState) { | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2889 | sp<SurfaceControl> layer; | 
|  | 2890 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2891 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2892 |  | 
|  | 2893 | sp<GraphicBuffer> buffer = | 
|  | 2894 | new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, | 
|  | 2895 | BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN | | 
|  | 2896 | BufferUsage::COMPOSER_OVERLAY, | 
|  | 2897 | "test"); | 
|  | 2898 | fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED); | 
|  | 2899 |  | 
|  | 2900 | Transaction() | 
|  | 2901 | .setBuffer(layer, buffer) | 
|  | 2902 | .setApi(layer, NATIVE_WINDOW_API_CPU) | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2903 | .apply(); | 
|  | 2904 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2905 | auto shot = getScreenCapture(); | 
| Marissa Wall | 290ad08 | 2019-03-06 13:23:47 -0800 | [diff] [blame] | 2906 | shot->expectColor(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::RED); | 
|  | 2907 | shot->expectBorder(Rect(0, 0, mDisplayWidth, mDisplayHeight), Color::BLACK); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 2908 | } | 
|  | 2909 |  | 
|  | 2910 | TEST_F(LayerTransactionTest, SetSidebandStreamNull_BufferState) { | 
|  | 2911 | sp<SurfaceControl> layer; | 
|  | 2912 | ASSERT_NO_FATAL_FAILURE( | 
|  | 2913 | layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 2914 |  | 
|  | 2915 | // verify this doesn't cause a crash | 
|  | 2916 | Transaction().setSidebandStream(layer, nullptr).apply(); | 
|  | 2917 | } | 
|  | 2918 |  | 
| Robert Carr | 54cf5b1 | 2019-01-25 14:02:28 -0800 | [diff] [blame] | 2919 | TEST_F(LayerTransactionTest, ReparentToSelf) { | 
|  | 2920 | sp<SurfaceControl> layer; | 
|  | 2921 | ASSERT_NO_FATAL_FAILURE(layer = createLayer("test", 32, 32)); | 
|  | 2922 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32)); | 
|  | 2923 | Transaction().reparent(layer, layer->getHandle()).apply(); | 
|  | 2924 |  | 
|  | 2925 | { | 
|  | 2926 | // We expect the transaction to be silently dropped, but for SurfaceFlinger | 
|  | 2927 | // to still be functioning. | 
|  | 2928 | SCOPED_TRACE("after reparent to self"); | 
|  | 2929 | const Rect rect(0, 0, 32, 32); | 
|  | 2930 | auto shot = screenshot(); | 
|  | 2931 | shot->expectColor(rect, Color::RED); | 
|  | 2932 | shot->expectBorder(rect, Color::BLACK); | 
|  | 2933 | } | 
|  | 2934 | } | 
|  | 2935 |  | 
| Ady Abraham | 2a6ab2a | 2018-10-26 14:25:30 -0700 | [diff] [blame] | 2936 | class ColorTransformHelper { | 
|  | 2937 | public: | 
|  | 2938 | static void DegammaColorSingle(half& s) { | 
|  | 2939 | if (s <= 0.03928f) | 
|  | 2940 | s = s / 12.92f; | 
|  | 2941 | else | 
|  | 2942 | s = pow((s + 0.055f) / 1.055f, 2.4f); | 
|  | 2943 | } | 
|  | 2944 |  | 
|  | 2945 | static void DegammaColor(half3& color) { | 
|  | 2946 | DegammaColorSingle(color.r); | 
|  | 2947 | DegammaColorSingle(color.g); | 
|  | 2948 | DegammaColorSingle(color.b); | 
|  | 2949 | } | 
|  | 2950 |  | 
|  | 2951 | static void GammaColorSingle(half& s) { | 
|  | 2952 | if (s <= 0.0031308f) { | 
|  | 2953 | s = s * 12.92f; | 
|  | 2954 | } else { | 
|  | 2955 | s = 1.055f * pow(s, (1.0f / 2.4f)) - 0.055f; | 
|  | 2956 | } | 
|  | 2957 | } | 
|  | 2958 |  | 
|  | 2959 | static void GammaColor(half3& color) { | 
|  | 2960 | GammaColorSingle(color.r); | 
|  | 2961 | GammaColorSingle(color.g); | 
|  | 2962 | GammaColorSingle(color.b); | 
|  | 2963 | } | 
|  | 2964 |  | 
|  | 2965 | static void applyMatrix(half3& color, const mat3& mat) { | 
|  | 2966 | half3 ret = half3(0); | 
|  | 2967 |  | 
|  | 2968 | for (int i = 0; i < 3; i++) { | 
|  | 2969 | for (int j = 0; j < 3; j++) { | 
|  | 2970 | ret[i] = ret[i] + color[j] * mat[j][i]; | 
|  | 2971 | } | 
|  | 2972 | } | 
|  | 2973 | color = ret; | 
|  | 2974 | } | 
|  | 2975 | }; | 
|  | 2976 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2977 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformBasic) { | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2978 | sp<SurfaceControl> colorLayer; | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 2979 | ASSERT_NO_FATAL_FAILURE(colorLayer = | 
|  | 2980 | createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 2981 | ISurfaceComposerClient::eFXSurfaceColor)); | 
|  | 2982 | Transaction() | 
|  | 2983 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 2984 | .setLayer(colorLayer, mLayerZBase + 1) | 
|  | 2985 | .apply(); | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2986 | { | 
|  | 2987 | SCOPED_TRACE("default color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 2988 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2989 | } | 
|  | 2990 |  | 
|  | 2991 | 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] | 2992 | half3 expected = color; | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 2993 | mat3 matrix; | 
|  | 2994 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; | 
|  | 2995 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; | 
|  | 2996 | 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] | 2997 |  | 
|  | 2998 | // degamma before applying the matrix | 
|  | 2999 | if (mColorManagementUsed) { | 
|  | 3000 | ColorTransformHelper::DegammaColor(expected); | 
|  | 3001 | } | 
|  | 3002 |  | 
|  | 3003 | ColorTransformHelper::applyMatrix(expected, matrix); | 
|  | 3004 |  | 
|  | 3005 | if (mColorManagementUsed) { | 
|  | 3006 | ColorTransformHelper::GammaColor(expected); | 
|  | 3007 | } | 
|  | 3008 |  | 
|  | 3009 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), | 
|  | 3010 | uint8_t(expected.b * 255), 255}; | 
|  | 3011 |  | 
|  | 3012 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 3013 | // channel) should be less than one | 
|  | 3014 | const uint8_t tolerance = 1; | 
|  | 3015 |  | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 3016 | Transaction().setColor(colorLayer, color) | 
|  | 3017 | .setColorTransform(colorLayer, matrix, vec3()).apply(); | 
|  | 3018 | { | 
|  | 3019 | SCOPED_TRACE("new color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 3020 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 3021 | } | 
|  | 3022 | } | 
|  | 3023 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 3024 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformOnParent) { | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 3025 | sp<SurfaceControl> parentLayer; | 
|  | 3026 | sp<SurfaceControl> colorLayer; | 
|  | 3027 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parent", 0 /* buffer width */, | 
|  | 3028 | 0 /* buffer height */, | 
|  | 3029 | ISurfaceComposerClient::eFXSurfaceContainer)); | 
|  | 3030 | ASSERT_NO_FATAL_FAILURE( | 
|  | 3031 | colorLayer = createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 3032 | ISurfaceComposerClient::eFXSurfaceColor, parentLayer.get())); | 
|  | 3033 |  | 
|  | 3034 | Transaction() | 
|  | 3035 | .setCrop_legacy(parentLayer, Rect(0, 0, 100, 100)) | 
|  | 3036 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 3037 | .setLayer(parentLayer, mLayerZBase + 1) | 
|  | 3038 | .apply(); | 
|  | 3039 | { | 
|  | 3040 | SCOPED_TRACE("default color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 3041 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 3042 | } | 
|  | 3043 |  | 
|  | 3044 | const half3 color(50.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f); | 
|  | 3045 | half3 expected = color; | 
|  | 3046 | mat3 matrix; | 
|  | 3047 | matrix[0][0] = 0.3; matrix[1][0] = 0.59; matrix[2][0] = 0.11; | 
|  | 3048 | matrix[0][1] = 0.3; matrix[1][1] = 0.59; matrix[2][1] = 0.11; | 
|  | 3049 | matrix[0][2] = 0.3; matrix[1][2] = 0.59; matrix[2][2] = 0.11; | 
|  | 3050 |  | 
|  | 3051 | // degamma before applying the matrix | 
|  | 3052 | if (mColorManagementUsed) { | 
|  | 3053 | ColorTransformHelper::DegammaColor(expected); | 
|  | 3054 | } | 
|  | 3055 |  | 
|  | 3056 | ColorTransformHelper::applyMatrix(expected, matrix); | 
|  | 3057 |  | 
|  | 3058 | if (mColorManagementUsed) { | 
|  | 3059 | ColorTransformHelper::GammaColor(expected); | 
|  | 3060 | } | 
|  | 3061 |  | 
|  | 3062 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), | 
|  | 3063 | uint8_t(expected.b * 255), 255}; | 
|  | 3064 |  | 
|  | 3065 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 3066 | // channel) should be less than one | 
|  | 3067 | const uint8_t tolerance = 1; | 
|  | 3068 |  | 
|  | 3069 | Transaction() | 
|  | 3070 | .setColor(colorLayer, color) | 
|  | 3071 | .setColorTransform(parentLayer, matrix, vec3()) | 
|  | 3072 | .apply(); | 
|  | 3073 | { | 
|  | 3074 | SCOPED_TRACE("new color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 3075 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 3076 | } | 
|  | 3077 | } | 
|  | 3078 |  | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 3079 | TEST_P(LayerRenderTypeTransactionTest, SetColorTransformOnChildAndParent) { | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 3080 | sp<SurfaceControl> parentLayer; | 
|  | 3081 | sp<SurfaceControl> colorLayer; | 
|  | 3082 | ASSERT_NO_FATAL_FAILURE(parentLayer = createLayer("parent", 0 /* buffer width */, | 
|  | 3083 | 0 /* buffer height */, | 
|  | 3084 | ISurfaceComposerClient::eFXSurfaceContainer)); | 
|  | 3085 | ASSERT_NO_FATAL_FAILURE( | 
|  | 3086 | colorLayer = createLayer("test", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 3087 | ISurfaceComposerClient::eFXSurfaceColor, parentLayer.get())); | 
|  | 3088 |  | 
|  | 3089 | Transaction() | 
|  | 3090 | .setCrop_legacy(parentLayer, Rect(0, 0, 100, 100)) | 
|  | 3091 | .setCrop_legacy(colorLayer, Rect(0, 0, 32, 32)) | 
|  | 3092 | .setLayer(parentLayer, mLayerZBase + 1) | 
|  | 3093 | .apply(); | 
|  | 3094 | { | 
|  | 3095 | SCOPED_TRACE("default color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 3096 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), Color::BLACK); | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 3097 | } | 
|  | 3098 |  | 
|  | 3099 | const half3 color(50.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f); | 
|  | 3100 | half3 expected = color; | 
|  | 3101 | mat3 matrixChild; | 
|  | 3102 | matrixChild[0][0] = 0.3; matrixChild[1][0] = 0.59; matrixChild[2][0] = 0.11; | 
|  | 3103 | matrixChild[0][1] = 0.3; matrixChild[1][1] = 0.59; matrixChild[2][1] = 0.11; | 
|  | 3104 | matrixChild[0][2] = 0.3; matrixChild[1][2] = 0.59; matrixChild[2][2] = 0.11; | 
|  | 3105 | mat3 matrixParent; | 
|  | 3106 | matrixParent[0][0] = 0.2; matrixParent[1][0] = 0.4; matrixParent[2][0] = 0.10; | 
|  | 3107 | matrixParent[0][1] = 0.2; matrixParent[1][1] = 0.4; matrixParent[2][1] = 0.10; | 
|  | 3108 | matrixParent[0][2] = 0.2; matrixParent[1][2] = 0.4; matrixParent[2][2] = 0.10; | 
|  | 3109 |  | 
|  | 3110 | // degamma before applying the matrix | 
|  | 3111 | if (mColorManagementUsed) { | 
|  | 3112 | ColorTransformHelper::DegammaColor(expected); | 
|  | 3113 | } | 
|  | 3114 |  | 
|  | 3115 | ColorTransformHelper::applyMatrix(expected, matrixChild); | 
|  | 3116 | ColorTransformHelper::applyMatrix(expected, matrixParent); | 
|  | 3117 |  | 
|  | 3118 | if (mColorManagementUsed) { | 
|  | 3119 | ColorTransformHelper::GammaColor(expected); | 
|  | 3120 | } | 
|  | 3121 |  | 
|  | 3122 | const Color expectedColor = {uint8_t(expected.r * 255), uint8_t(expected.g * 255), | 
|  | 3123 | uint8_t(expected.b * 255), 255}; | 
|  | 3124 |  | 
|  | 3125 | // this is handwavy, but the precison loss scaled by 255 (8-bit per | 
|  | 3126 | // channel) should be less than one | 
|  | 3127 | const uint8_t tolerance = 1; | 
|  | 3128 |  | 
|  | 3129 | Transaction() | 
|  | 3130 | .setColor(colorLayer, color) | 
|  | 3131 | .setColorTransform(parentLayer, matrixParent, vec3()) | 
|  | 3132 | .setColorTransform(colorLayer, matrixChild, vec3()) | 
|  | 3133 | .apply(); | 
|  | 3134 | { | 
|  | 3135 | SCOPED_TRACE("new color"); | 
| Alec Mouri | 80863a6 | 2019-01-17 15:19:35 -0800 | [diff] [blame] | 3136 | getScreenCapture()->expectColor(Rect(0, 0, 32, 32), expectedColor, tolerance); | 
| chaviw | f66724d | 2018-11-28 16:35:21 -0800 | [diff] [blame] | 3137 | } | 
|  | 3138 | } | 
|  | 3139 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3140 | struct CallbackData { | 
|  | 3141 | CallbackData() = default; | 
|  | 3142 | CallbackData(nsecs_t time, const sp<Fence>& fence, | 
|  | 3143 | const std::vector<SurfaceControlStats>& stats) | 
|  | 3144 | : latchTime(time), presentFence(fence), surfaceControlStats(stats) {} | 
|  | 3145 |  | 
|  | 3146 | nsecs_t latchTime; | 
|  | 3147 | sp<Fence> presentFence; | 
|  | 3148 | std::vector<SurfaceControlStats> surfaceControlStats; | 
|  | 3149 | }; | 
|  | 3150 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3151 | class ExpectedResult { | 
|  | 3152 | public: | 
|  | 3153 | enum Transaction { | 
|  | 3154 | NOT_PRESENTED = 0, | 
|  | 3155 | PRESENTED, | 
|  | 3156 | }; | 
|  | 3157 |  | 
|  | 3158 | enum Buffer { | 
|  | 3159 | NOT_ACQUIRED = 0, | 
|  | 3160 | ACQUIRED, | 
|  | 3161 | }; | 
|  | 3162 |  | 
|  | 3163 | enum PreviousBuffer { | 
|  | 3164 | NOT_RELEASED = 0, | 
|  | 3165 | RELEASED, | 
| Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3166 | UNKNOWN, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3167 | }; | 
|  | 3168 |  | 
|  | 3169 | void reset() { | 
|  | 3170 | mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; | 
|  | 3171 | mExpectedSurfaceResults.clear(); | 
|  | 3172 | } | 
|  | 3173 |  | 
|  | 3174 | void addSurface(ExpectedResult::Transaction transactionResult, const sp<SurfaceControl>& layer, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3175 | ExpectedResult::Buffer bufferResult = ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3176 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { | 
|  | 3177 | mTransactionResult = transactionResult; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3178 | mExpectedSurfaceResults.emplace(std::piecewise_construct, std::forward_as_tuple(layer), | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3179 | std::forward_as_tuple(bufferResult, previousBufferResult)); | 
|  | 3180 | } | 
|  | 3181 |  | 
|  | 3182 | void addSurfaces(ExpectedResult::Transaction transactionResult, | 
|  | 3183 | const std::vector<sp<SurfaceControl>>& layers, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3184 | ExpectedResult::Buffer bufferResult = ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3185 | ExpectedResult::PreviousBuffer previousBufferResult = NOT_RELEASED) { | 
|  | 3186 | for (const auto& layer : layers) { | 
|  | 3187 | addSurface(transactionResult, layer, bufferResult, previousBufferResult); | 
|  | 3188 | } | 
|  | 3189 | } | 
|  | 3190 |  | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3191 | void addExpectedPresentTime(nsecs_t expectedPresentTime) { | 
|  | 3192 | mExpectedPresentTime = expectedPresentTime; | 
|  | 3193 | } | 
|  | 3194 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3195 | void verifyCallbackData(const CallbackData& callbackData) const { | 
|  | 3196 | const auto& [latchTime, presentFence, surfaceControlStats] = callbackData; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3197 | if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) { | 
|  | 3198 | ASSERT_GE(latchTime, 0) << "bad latch time"; | 
| Valerie Hau | 63258a1 | 2018-12-14 14:31:48 -0800 | [diff] [blame] | 3199 | ASSERT_NE(presentFence, nullptr); | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3200 | if (mExpectedPresentTime >= 0) { | 
|  | 3201 | ASSERT_EQ(presentFence->wait(3000), NO_ERROR); | 
|  | 3202 | ASSERT_GE(presentFence->getSignalTime(), mExpectedPresentTime - nsecs_t(5 * 1e6)); | 
|  | 3203 | // if the panel is running at 30 hz, at the worst case, our expected time just | 
|  | 3204 | // misses vsync and we have to wait another 33.3ms | 
|  | 3205 | ASSERT_LE(presentFence->getSignalTime(), | 
|  | 3206 | mExpectedPresentTime + nsecs_t(66.666666 * 1e6)); | 
|  | 3207 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3208 | } else { | 
| Valerie Hau | 63258a1 | 2018-12-14 14:31:48 -0800 | [diff] [blame] | 3209 | ASSERT_EQ(presentFence, nullptr) << "transaction shouldn't have been presented"; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3210 | ASSERT_EQ(latchTime, -1) << "unpresented transactions shouldn't be latched"; | 
|  | 3211 | } | 
|  | 3212 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3213 | ASSERT_EQ(surfaceControlStats.size(), mExpectedSurfaceResults.size()) | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3214 | << "wrong number of surfaces"; | 
|  | 3215 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3216 | for (const auto& stats : surfaceControlStats) { | 
|  | 3217 | ASSERT_NE(stats.surfaceControl, nullptr) << "returned null surface control"; | 
|  | 3218 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3219 | const auto& expectedSurfaceResult = mExpectedSurfaceResults.find(stats.surfaceControl); | 
|  | 3220 | ASSERT_NE(expectedSurfaceResult, mExpectedSurfaceResults.end()) | 
|  | 3221 | << "unexpected surface control"; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3222 | expectedSurfaceResult->second.verifySurfaceControlStats(stats, latchTime); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3223 | } | 
|  | 3224 | } | 
|  | 3225 |  | 
|  | 3226 | private: | 
|  | 3227 | class ExpectedSurfaceResult { | 
|  | 3228 | public: | 
|  | 3229 | ExpectedSurfaceResult(ExpectedResult::Buffer bufferResult, | 
|  | 3230 | ExpectedResult::PreviousBuffer previousBufferResult) | 
|  | 3231 | : mBufferResult(bufferResult), mPreviousBufferResult(previousBufferResult) {} | 
|  | 3232 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3233 | void verifySurfaceControlStats(const SurfaceControlStats& surfaceControlStats, | 
|  | 3234 | nsecs_t latchTime) const { | 
|  | 3235 | const auto& [surfaceControl, acquireTime, previousReleaseFence] = surfaceControlStats; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3236 |  | 
|  | 3237 | ASSERT_EQ(acquireTime > 0, mBufferResult == ExpectedResult::Buffer::ACQUIRED) | 
|  | 3238 | << "bad acquire time"; | 
|  | 3239 | ASSERT_LE(acquireTime, latchTime) << "acquire time should be <= latch time"; | 
| Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3240 |  | 
|  | 3241 | if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::RELEASED) { | 
|  | 3242 | ASSERT_NE(previousReleaseFence, nullptr) | 
|  | 3243 | << "failed to set release prev buffer fence"; | 
|  | 3244 | } else if (mPreviousBufferResult == ExpectedResult::PreviousBuffer::NOT_RELEASED) { | 
|  | 3245 | ASSERT_EQ(previousReleaseFence, nullptr) | 
|  | 3246 | << "should not have set released prev buffer fence"; | 
|  | 3247 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3248 | } | 
|  | 3249 |  | 
|  | 3250 | private: | 
|  | 3251 | ExpectedResult::Buffer mBufferResult; | 
|  | 3252 | ExpectedResult::PreviousBuffer mPreviousBufferResult; | 
|  | 3253 | }; | 
|  | 3254 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3255 | struct SCHash { | 
|  | 3256 | std::size_t operator()(const sp<SurfaceControl>& sc) const { | 
|  | 3257 | return std::hash<IBinder*>{}(sc->getHandle().get()); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3258 | } | 
|  | 3259 | }; | 
|  | 3260 | ExpectedResult::Transaction mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED; | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 3261 | nsecs_t mExpectedPresentTime = -1; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3262 | std::unordered_map<sp<SurfaceControl>, ExpectedSurfaceResult, SCHash> mExpectedSurfaceResults; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3263 | }; | 
|  | 3264 |  | 
|  | 3265 | class CallbackHelper { | 
|  | 3266 | public: | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3267 | static void function(void* callbackContext, nsecs_t latchTime, const sp<Fence>& presentFence, | 
|  | 3268 | const std::vector<SurfaceControlStats>& stats) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3269 | if (!callbackContext) { | 
|  | 3270 | ALOGE("failed to get callback context"); | 
|  | 3271 | } | 
|  | 3272 | CallbackHelper* helper = static_cast<CallbackHelper*>(callbackContext); | 
|  | 3273 | std::lock_guard lock(helper->mMutex); | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3274 | helper->mCallbackDataQueue.emplace(latchTime, presentFence, stats); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3275 | helper->mConditionVariable.notify_all(); | 
|  | 3276 | } | 
|  | 3277 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3278 | void getCallbackData(CallbackData* outData) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3279 | std::unique_lock lock(mMutex); | 
|  | 3280 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3281 | if (mCallbackDataQueue.empty()) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3282 | ASSERT_NE(mConditionVariable.wait_for(lock, std::chrono::seconds(3)), | 
|  | 3283 | std::cv_status::timeout) | 
|  | 3284 | << "did not receive callback"; | 
|  | 3285 | } | 
|  | 3286 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3287 | *outData = std::move(mCallbackDataQueue.front()); | 
|  | 3288 | mCallbackDataQueue.pop(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3289 | } | 
|  | 3290 |  | 
|  | 3291 | void verifyFinalState() { | 
|  | 3292 | // Wait to see if there are extra callbacks | 
|  | 3293 | std::this_thread::sleep_for(500ms); | 
|  | 3294 |  | 
|  | 3295 | std::lock_guard lock(mMutex); | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3296 | EXPECT_EQ(mCallbackDataQueue.size(), 0) << "extra callbacks received"; | 
|  | 3297 | mCallbackDataQueue = {}; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3298 | } | 
|  | 3299 |  | 
|  | 3300 | void* getContext() { return static_cast<void*>(this); } | 
|  | 3301 |  | 
|  | 3302 | std::mutex mMutex; | 
|  | 3303 | std::condition_variable mConditionVariable; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3304 | std::queue<CallbackData> mCallbackDataQueue; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3305 | }; | 
|  | 3306 |  | 
|  | 3307 | class LayerCallbackTest : public LayerTransactionTest { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3308 | public: | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3309 | virtual sp<SurfaceControl> createBufferStateLayer() { | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3310 | return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3311 | } | 
|  | 3312 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3313 | static int fillTransaction(Transaction& transaction, CallbackHelper* callbackHelper, | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3314 | const sp<SurfaceControl>& layer = nullptr, bool setBuffer = true, | 
|  | 3315 | bool setBackgroundColor = false) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3316 | if (layer) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3317 | sp<GraphicBuffer> buffer; | 
|  | 3318 | sp<Fence> fence; | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3319 | if (setBuffer) { | 
|  | 3320 | int err = getBuffer(&buffer, &fence); | 
|  | 3321 | if (err != NO_ERROR) { | 
|  | 3322 | return err; | 
|  | 3323 | } | 
|  | 3324 |  | 
|  | 3325 | transaction.setBuffer(layer, buffer); | 
|  | 3326 | transaction.setAcquireFence(layer, fence); | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3327 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3328 |  | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3329 | if (setBackgroundColor) { | 
|  | 3330 | transaction.setBackgroundColor(layer, /*color*/ half3(1.0f, 0, 0), /*alpha*/ 1.0f, | 
|  | 3331 | ui::Dataspace::UNKNOWN); | 
|  | 3332 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3333 | } | 
|  | 3334 |  | 
|  | 3335 | transaction.addTransactionCompletedCallback(callbackHelper->function, | 
|  | 3336 | callbackHelper->getContext()); | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3337 | return NO_ERROR; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3338 | } | 
|  | 3339 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3340 | static void waitForCallback(CallbackHelper& helper, const ExpectedResult& expectedResult, | 
|  | 3341 | bool finalState = false) { | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 3342 | CallbackData callbackData; | 
|  | 3343 | ASSERT_NO_FATAL_FAILURE(helper.getCallbackData(&callbackData)); | 
|  | 3344 | EXPECT_NO_FATAL_FAILURE(expectedResult.verifyCallbackData(callbackData)); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3345 |  | 
|  | 3346 | if (finalState) { | 
|  | 3347 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); | 
|  | 3348 | } | 
|  | 3349 | } | 
|  | 3350 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3351 | static void waitForCallbacks(CallbackHelper& helper, | 
|  | 3352 | const std::vector<ExpectedResult>& expectedResults, | 
|  | 3353 | bool finalState = false) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3354 | for (const auto& expectedResult : expectedResults) { | 
|  | 3355 | waitForCallback(helper, expectedResult); | 
|  | 3356 | } | 
|  | 3357 | if (finalState) { | 
|  | 3358 | ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState()); | 
|  | 3359 | } | 
|  | 3360 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3361 | }; | 
|  | 3362 |  | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3363 | TEST_F(LayerCallbackTest, BufferColor) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3364 | sp<SurfaceControl> layer; | 
|  | 3365 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3366 |  | 
|  | 3367 | Transaction transaction; | 
|  | 3368 | CallbackHelper callback; | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3369 | int err = fillTransaction(transaction, &callback, layer, true, true); | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3370 | if (err) { | 
|  | 3371 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3372 | return; | 
|  | 3373 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3374 |  | 
|  | 3375 | transaction.apply(); | 
|  | 3376 |  | 
|  | 3377 | ExpectedResult expected; | 
|  | 3378 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3379 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3380 | } | 
|  | 3381 |  | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3382 | TEST_F(LayerCallbackTest, NoBufferNoColor) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3383 | sp<SurfaceControl> layer; | 
|  | 3384 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3385 |  | 
|  | 3386 | Transaction transaction; | 
|  | 3387 | CallbackHelper callback; | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3388 | int err = fillTransaction(transaction, &callback, layer, false, false); | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3389 | if (err) { | 
|  | 3390 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3391 | return; | 
|  | 3392 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3393 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3394 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3395 |  | 
|  | 3396 | ExpectedResult expected; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3397 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, | 
|  | 3398 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3399 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3400 | } | 
|  | 3401 |  | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3402 | TEST_F(LayerCallbackTest, BufferNoColor) { | 
|  | 3403 | sp<SurfaceControl> layer; | 
|  | 3404 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3405 |  | 
|  | 3406 | Transaction transaction; | 
|  | 3407 | CallbackHelper callback; | 
|  | 3408 | int err = fillTransaction(transaction, &callback, layer, true, false); | 
|  | 3409 | if (err) { | 
|  | 3410 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3411 | return; | 
|  | 3412 | } | 
|  | 3413 |  | 
|  | 3414 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
|  | 3415 |  | 
|  | 3416 | ExpectedResult expected; | 
|  | 3417 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3418 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3419 | } | 
|  | 3420 |  | 
|  | 3421 | TEST_F(LayerCallbackTest, NoBufferColor) { | 
|  | 3422 | sp<SurfaceControl> layer; | 
|  | 3423 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3424 |  | 
|  | 3425 | Transaction transaction; | 
|  | 3426 | CallbackHelper callback; | 
|  | 3427 | int err = fillTransaction(transaction, &callback, layer, false, true); | 
|  | 3428 | if (err) { | 
|  | 3429 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3430 | return; | 
|  | 3431 | } | 
|  | 3432 |  | 
|  | 3433 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
|  | 3434 |  | 
|  | 3435 | ExpectedResult expected; | 
|  | 3436 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 3437 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 3438 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3439 | } | 
|  | 3440 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3441 | TEST_F(LayerCallbackTest, NoStateChange) { | 
|  | 3442 | Transaction transaction; | 
|  | 3443 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3444 | int err = fillTransaction(transaction, &callback); | 
|  | 3445 | if (err) { | 
|  | 3446 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3447 | return; | 
|  | 3448 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3449 |  | 
|  | 3450 | transaction.apply(); | 
|  | 3451 |  | 
|  | 3452 | ExpectedResult expected; | 
|  | 3453 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3454 | } | 
|  | 3455 |  | 
|  | 3456 | TEST_F(LayerCallbackTest, OffScreen) { | 
|  | 3457 | sp<SurfaceControl> layer; | 
|  | 3458 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3459 |  | 
|  | 3460 | Transaction transaction; | 
|  | 3461 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3462 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3463 | if (err) { | 
|  | 3464 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3465 | return; | 
|  | 3466 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3467 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3468 | transaction.setFrame(layer, Rect(-100, -100, 100, 100)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3469 |  | 
|  | 3470 | ExpectedResult expected; | 
|  | 3471 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3472 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3473 | } | 
|  | 3474 |  | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3475 | TEST_F(LayerCallbackTest, MergeBufferNoColor) { | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3476 | sp<SurfaceControl> layer1, layer2; | 
|  | 3477 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 3478 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 3479 |  | 
|  | 3480 | Transaction transaction1, transaction2; | 
|  | 3481 | CallbackHelper callback1, callback2; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3482 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3483 | if (err) { | 
|  | 3484 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3485 | return; | 
|  | 3486 | } | 
|  | 3487 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3488 | if (err) { | 
|  | 3489 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3490 | return; | 
|  | 3491 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3492 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3493 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3494 | 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] | 3495 |  | 
|  | 3496 | ExpectedResult expected; | 
|  | 3497 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3498 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3499 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3500 | } | 
|  | 3501 |  | 
| Valerie Hau | aa19456 | 2019-02-05 16:21:38 -0800 | [diff] [blame] | 3502 | TEST_F(LayerCallbackTest, MergeNoBufferColor) { | 
|  | 3503 | sp<SurfaceControl> layer1, layer2; | 
|  | 3504 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 3505 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 3506 |  | 
|  | 3507 | Transaction transaction1, transaction2; | 
|  | 3508 | CallbackHelper callback1, callback2; | 
|  | 3509 | int err = fillTransaction(transaction1, &callback1, layer1, false, true); | 
|  | 3510 | if (err) { | 
|  | 3511 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3512 | return; | 
|  | 3513 | } | 
|  | 3514 | err = fillTransaction(transaction2, &callback2, layer2, false, true); | 
|  | 3515 | if (err) { | 
|  | 3516 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3517 | return; | 
|  | 3518 | } | 
|  | 3519 |  | 
|  | 3520 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3521 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
|  | 3522 |  | 
|  | 3523 | ExpectedResult expected; | 
|  | 3524 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, | 
|  | 3525 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 3526 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3527 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3528 | } | 
|  | 3529 |  | 
|  | 3530 | TEST_F(LayerCallbackTest, MergeOneBufferOneColor) { | 
|  | 3531 | sp<SurfaceControl> layer1, layer2; | 
|  | 3532 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 3533 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 3534 |  | 
|  | 3535 | Transaction transaction1, transaction2; | 
|  | 3536 | CallbackHelper callback1, callback2; | 
|  | 3537 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3538 | if (err) { | 
|  | 3539 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3540 | return; | 
|  | 3541 | } | 
|  | 3542 | err = fillTransaction(transaction2, &callback2, layer2, false, true); | 
|  | 3543 | if (err) { | 
|  | 3544 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3545 | return; | 
|  | 3546 | } | 
|  | 3547 |  | 
|  | 3548 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3549 | transaction2.setFrame(layer2, Rect(32, 32, 64, 64)).merge(std::move(transaction1)).apply(); | 
|  | 3550 |  | 
|  | 3551 | ExpectedResult expected; | 
|  | 3552 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer1); | 
|  | 3553 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer2, | 
|  | 3554 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
|  | 3555 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3556 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3557 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3558 | TEST_F(LayerCallbackTest, Merge_SameCallback) { | 
|  | 3559 | sp<SurfaceControl> layer1, layer2; | 
|  | 3560 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 3561 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 3562 |  | 
|  | 3563 | Transaction transaction1, transaction2; | 
|  | 3564 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3565 | int err = fillTransaction(transaction1, &callback, layer1); | 
|  | 3566 | if (err) { | 
|  | 3567 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3568 | return; | 
|  | 3569 | } | 
|  | 3570 | err = fillTransaction(transaction2, &callback, layer2); | 
|  | 3571 | if (err) { | 
|  | 3572 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3573 | return; | 
|  | 3574 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3575 |  | 
|  | 3576 | transaction2.merge(std::move(transaction1)).apply(); | 
|  | 3577 |  | 
|  | 3578 | ExpectedResult expected; | 
|  | 3579 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3580 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); | 
|  | 3581 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3582 | } | 
|  | 3583 |  | 
|  | 3584 | TEST_F(LayerCallbackTest, Merge_SameLayer) { | 
|  | 3585 | sp<SurfaceControl> layer; | 
|  | 3586 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3587 |  | 
|  | 3588 | Transaction transaction1, transaction2; | 
|  | 3589 | CallbackHelper callback1, callback2; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3590 | int err = fillTransaction(transaction1, &callback1, layer); | 
|  | 3591 | if (err) { | 
|  | 3592 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3593 | return; | 
|  | 3594 | } | 
|  | 3595 | err = fillTransaction(transaction2, &callback2, layer); | 
|  | 3596 | if (err) { | 
|  | 3597 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3598 | return; | 
|  | 3599 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3600 |  | 
|  | 3601 | transaction2.merge(std::move(transaction1)).apply(); | 
|  | 3602 |  | 
|  | 3603 | ExpectedResult expected; | 
|  | 3604 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3605 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3606 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3607 | } | 
|  | 3608 |  | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3609 | TEST_F(LayerCallbackTest, Merge_DifferentClients) { | 
|  | 3610 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 3611 | client2(new SurfaceComposerClient); | 
|  | 3612 |  | 
|  | 3613 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3614 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3615 |  | 
|  | 3616 | sp<SurfaceControl> layer1, layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3617 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3618 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3619 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3620 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 3621 |  | 
|  | 3622 | Transaction transaction1, transaction2; | 
|  | 3623 | CallbackHelper callback1, callback2; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3624 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3625 | if (err) { | 
|  | 3626 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3627 | return; | 
|  | 3628 | } | 
|  | 3629 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3630 | if (err) { | 
|  | 3631 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3632 | return; | 
|  | 3633 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3634 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3635 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3636 | 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] | 3637 |  | 
|  | 3638 | ExpectedResult expected; | 
|  | 3639 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3640 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3641 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3642 | } | 
|  | 3643 |  | 
|  | 3644 | TEST_F(LayerCallbackTest, MultipleTransactions) { | 
|  | 3645 | sp<SurfaceControl> layer; | 
|  | 3646 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3647 |  | 
|  | 3648 | Transaction transaction; | 
|  | 3649 | CallbackHelper callback; | 
|  | 3650 | for (size_t i = 0; i < 10; i++) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3651 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3652 | if (err) { | 
|  | 3653 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3654 | return; | 
|  | 3655 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3656 |  | 
|  | 3657 | transaction.apply(); | 
|  | 3658 |  | 
|  | 3659 | ExpectedResult expected; | 
|  | 3660 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3661 | ExpectedResult::Buffer::ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3662 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED | 
|  | 3663 | : ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 3664 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); | 
|  | 3665 | } | 
|  | 3666 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); | 
|  | 3667 | } | 
|  | 3668 |  | 
|  | 3669 | TEST_F(LayerCallbackTest, MultipleTransactions_NoStateChange) { | 
|  | 3670 | sp<SurfaceControl> layer; | 
|  | 3671 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3672 |  | 
|  | 3673 | Transaction transaction; | 
|  | 3674 | CallbackHelper callback; | 
|  | 3675 | for (size_t i = 0; i < 10; i++) { | 
|  | 3676 | ExpectedResult expected; | 
|  | 3677 |  | 
|  | 3678 | if (i == 0) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3679 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3680 | if (err) { | 
|  | 3681 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3682 | return; | 
|  | 3683 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3684 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3685 | } else { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3686 | int err = fillTransaction(transaction, &callback); | 
|  | 3687 | if (err) { | 
|  | 3688 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3689 | return; | 
|  | 3690 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3691 | } | 
|  | 3692 |  | 
|  | 3693 | transaction.apply(); | 
|  | 3694 |  | 
|  | 3695 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected)); | 
|  | 3696 | } | 
|  | 3697 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); | 
|  | 3698 | } | 
|  | 3699 |  | 
|  | 3700 | TEST_F(LayerCallbackTest, MultipleTransactions_SameStateChange) { | 
|  | 3701 | sp<SurfaceControl> layer; | 
|  | 3702 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3703 |  | 
|  | 3704 | Transaction transaction; | 
|  | 3705 | CallbackHelper callback; | 
|  | 3706 | for (size_t i = 0; i < 10; i++) { | 
|  | 3707 | if (i == 0) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3708 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3709 | if (err) { | 
|  | 3710 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3711 | return; | 
|  | 3712 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3713 | } else { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3714 | int err = fillTransaction(transaction, &callback); | 
|  | 3715 | if (err) { | 
|  | 3716 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3717 | return; | 
|  | 3718 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3719 | } | 
|  | 3720 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3721 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3722 |  | 
|  | 3723 | ExpectedResult expected; | 
|  | 3724 | expected.addSurface((i == 0) ? ExpectedResult::Transaction::PRESENTED | 
|  | 3725 | : ExpectedResult::Transaction::NOT_PRESENTED, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3726 | layer, | 
|  | 3727 | (i == 0) ? ExpectedResult::Buffer::ACQUIRED | 
|  | 3728 | : ExpectedResult::Buffer::NOT_ACQUIRED); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3729 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, i == 0)); | 
|  | 3730 | } | 
|  | 3731 | ASSERT_NO_FATAL_FAILURE(callback.verifyFinalState()); | 
|  | 3732 | } | 
|  | 3733 |  | 
|  | 3734 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge) { | 
|  | 3735 | sp<SurfaceControl> layer1, layer2; | 
|  | 3736 | ASSERT_NO_FATAL_FAILURE(layer1 = createBufferStateLayer()); | 
|  | 3737 | ASSERT_NO_FATAL_FAILURE(layer2 = createBufferStateLayer()); | 
|  | 3738 |  | 
|  | 3739 | Transaction transaction1, transaction2; | 
|  | 3740 | CallbackHelper callback1, callback2; | 
|  | 3741 | for (size_t i = 0; i < 10; i++) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3742 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3743 | if (err) { | 
|  | 3744 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3745 | return; | 
|  | 3746 | } | 
|  | 3747 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3748 | if (err) { | 
|  | 3749 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3750 | return; | 
|  | 3751 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3752 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3753 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3754 | 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] | 3755 |  | 
|  | 3756 | ExpectedResult expected; | 
|  | 3757 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3758 | ExpectedResult::Buffer::ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3759 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED | 
|  | 3760 | : ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 3761 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); | 
|  | 3762 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); | 
|  | 3763 | } | 
|  | 3764 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); | 
|  | 3765 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); | 
|  | 3766 | } | 
|  | 3767 |  | 
|  | 3768 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients) { | 
|  | 3769 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 3770 | client2(new SurfaceComposerClient); | 
|  | 3771 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3772 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3773 |  | 
|  | 3774 | sp<SurfaceControl> layer1, layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3775 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3776 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3777 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3778 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 3779 |  | 
|  | 3780 | Transaction transaction1, transaction2; | 
|  | 3781 | CallbackHelper callback1, callback2; | 
|  | 3782 | for (size_t i = 0; i < 10; i++) { | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3783 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3784 | if (err) { | 
|  | 3785 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3786 | return; | 
|  | 3787 | } | 
|  | 3788 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3789 | if (err) { | 
|  | 3790 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3791 | return; | 
|  | 3792 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3793 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3794 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3795 | 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] | 3796 |  | 
|  | 3797 | ExpectedResult expected; | 
|  | 3798 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}, | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3799 | ExpectedResult::Buffer::ACQUIRED, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3800 | (i == 0) ? ExpectedResult::PreviousBuffer::NOT_RELEASED | 
|  | 3801 | : ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 3802 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected)); | 
|  | 3803 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected)); | 
|  | 3804 | } | 
|  | 3805 | ASSERT_NO_FATAL_FAILURE(callback1.verifyFinalState()); | 
|  | 3806 | ASSERT_NO_FATAL_FAILURE(callback2.verifyFinalState()); | 
|  | 3807 | } | 
|  | 3808 |  | 
|  | 3809 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_NoStateChange) { | 
|  | 3810 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 3811 | client2(new SurfaceComposerClient); | 
|  | 3812 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3813 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3814 |  | 
|  | 3815 | sp<SurfaceControl> layer1, layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3816 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3817 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3818 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3819 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 3820 |  | 
|  | 3821 | Transaction transaction1, transaction2; | 
|  | 3822 | CallbackHelper callback1, callback2; | 
|  | 3823 |  | 
|  | 3824 | // Normal call to set up test | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3825 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3826 | if (err) { | 
|  | 3827 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3828 | return; | 
|  | 3829 | } | 
|  | 3830 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3831 | if (err) { | 
|  | 3832 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3833 | return; | 
|  | 3834 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3835 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3836 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3837 | 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] | 3838 |  | 
|  | 3839 | ExpectedResult expected; | 
|  | 3840 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3841 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3842 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3843 | expected.reset(); | 
|  | 3844 |  | 
|  | 3845 | // Test | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3846 | err = fillTransaction(transaction1, &callback1); | 
|  | 3847 | if (err) { | 
|  | 3848 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3849 | return; | 
|  | 3850 | } | 
|  | 3851 | err = fillTransaction(transaction2, &callback2); | 
|  | 3852 | if (err) { | 
|  | 3853 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3854 | return; | 
|  | 3855 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3856 |  | 
|  | 3857 | transaction2.merge(std::move(transaction1)).apply(); | 
|  | 3858 |  | 
|  | 3859 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3860 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3861 | } | 
|  | 3862 |  | 
|  | 3863 | TEST_F(LayerCallbackTest, MultipleTransactions_Merge_DifferentClients_SameStateChange) { | 
|  | 3864 | sp<SurfaceComposerClient> client1(new SurfaceComposerClient), | 
|  | 3865 | client2(new SurfaceComposerClient); | 
|  | 3866 |  | 
|  | 3867 | ASSERT_EQ(NO_ERROR, client1->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3868 | ASSERT_EQ(NO_ERROR, client2->initCheck()) << "failed to create SurfaceComposerClient"; | 
|  | 3869 |  | 
|  | 3870 | sp<SurfaceControl> layer1, layer2; | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3871 | ASSERT_NO_FATAL_FAILURE(layer1 = createLayer(client1, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3872 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3873 | ASSERT_NO_FATAL_FAILURE(layer2 = createLayer(client2, "test", 0, 0, | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3874 | ISurfaceComposerClient::eFXSurfaceBufferState)); | 
|  | 3875 |  | 
|  | 3876 | Transaction transaction1, transaction2; | 
|  | 3877 | CallbackHelper callback1, callback2; | 
|  | 3878 |  | 
|  | 3879 | // Normal call to set up test | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3880 | int err = fillTransaction(transaction1, &callback1, layer1); | 
|  | 3881 | if (err) { | 
|  | 3882 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3883 | return; | 
|  | 3884 | } | 
|  | 3885 | err = fillTransaction(transaction2, &callback2, layer2); | 
|  | 3886 | if (err) { | 
|  | 3887 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3888 | return; | 
|  | 3889 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3890 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3891 | transaction1.setFrame(layer1, Rect(0, 0, 32, 32)); | 
|  | 3892 | 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] | 3893 |  | 
|  | 3894 | ExpectedResult expected; | 
|  | 3895 | expected.addSurfaces(ExpectedResult::Transaction::PRESENTED, {layer1, layer2}); | 
|  | 3896 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3897 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3898 | expected.reset(); | 
|  | 3899 |  | 
|  | 3900 | // Test | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3901 | err = fillTransaction(transaction1, &callback1); | 
|  | 3902 | if (err) { | 
|  | 3903 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3904 | return; | 
|  | 3905 | } | 
|  | 3906 | err = fillTransaction(transaction2, &callback2); | 
|  | 3907 | if (err) { | 
|  | 3908 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3909 | return; | 
|  | 3910 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3911 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3912 | 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] | 3913 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3914 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer2, | 
|  | 3915 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3916 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected, true)); | 
|  | 3917 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected, true)); | 
|  | 3918 | } | 
|  | 3919 |  | 
|  | 3920 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame) { | 
|  | 3921 | sp<SurfaceControl> layer; | 
|  | 3922 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3923 |  | 
|  | 3924 | Transaction transaction; | 
|  | 3925 | CallbackHelper callback; | 
|  | 3926 | std::vector<ExpectedResult> expectedResults(50); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3927 | for (auto& expected : expectedResults) { | 
|  | 3928 | expected.reset(); | 
|  | 3929 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
| Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 3930 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 3931 | ExpectedResult::PreviousBuffer::UNKNOWN); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3932 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3933 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3934 | if (err) { | 
|  | 3935 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3936 | return; | 
|  | 3937 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3938 |  | 
|  | 3939 | transaction.apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3940 | } | 
|  | 3941 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); | 
|  | 3942 | } | 
|  | 3943 |  | 
|  | 3944 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_NoStateChange) { | 
|  | 3945 | sp<SurfaceControl> layer; | 
|  | 3946 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3947 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3948 | // Normal call to set up test | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3949 | Transaction transaction; | 
|  | 3950 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3951 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3952 | if (err) { | 
|  | 3953 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3954 | return; | 
|  | 3955 | } | 
|  | 3956 |  | 
|  | 3957 | transaction.apply(); | 
|  | 3958 |  | 
|  | 3959 | ExpectedResult expected; | 
|  | 3960 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3961 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 3962 |  | 
|  | 3963 | // Test | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3964 | std::vector<ExpectedResult> expectedResults(50); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3965 | for (auto& expected : expectedResults) { | 
|  | 3966 | expected.reset(); | 
|  | 3967 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3968 | err = fillTransaction(transaction, &callback); | 
|  | 3969 | if (err) { | 
|  | 3970 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3971 | return; | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3972 | } | 
|  | 3973 |  | 
|  | 3974 | transaction.apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3975 | } | 
|  | 3976 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); | 
|  | 3977 | } | 
|  | 3978 |  | 
|  | 3979 | TEST_F(LayerCallbackTest, MultipleTransactions_SingleFrame_SameStateChange) { | 
|  | 3980 | sp<SurfaceControl> layer; | 
|  | 3981 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 3982 |  | 
|  | 3983 | // Normal call to set up test | 
|  | 3984 | Transaction transaction; | 
|  | 3985 | CallbackHelper callback; | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 3986 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 3987 | if (err) { | 
|  | 3988 | GTEST_SUCCEED() << "test not supported"; | 
|  | 3989 | return; | 
|  | 3990 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3991 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 3992 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 3993 |  | 
|  | 3994 | ExpectedResult expectedResult; | 
|  | 3995 | expectedResult.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 3996 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expectedResult, true)); | 
|  | 3997 |  | 
|  | 3998 | // Test | 
|  | 3999 | std::vector<ExpectedResult> expectedResults(50); | 
|  | 4000 | for (auto& expected : expectedResults) { | 
|  | 4001 | expected.reset(); | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4002 | expected.addSurface(ExpectedResult::Transaction::NOT_PRESENTED, layer, | 
|  | 4003 | ExpectedResult::Buffer::NOT_ACQUIRED); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 4004 |  | 
| Marissa Wall | 713b63f | 2018-10-17 15:42:43 -0700 | [diff] [blame] | 4005 | err = fillTransaction(transaction, &callback); | 
|  | 4006 | if (err) { | 
|  | 4007 | GTEST_SUCCEED() << "test not supported"; | 
|  | 4008 | return; | 
|  | 4009 | } | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 4010 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 4011 | transaction.setFrame(layer, Rect(0, 0, 32, 32)).apply(); | 
| Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 4012 | } | 
|  | 4013 | EXPECT_NO_FATAL_FAILURE(waitForCallbacks(callback, expectedResults, true)); | 
|  | 4014 | } | 
|  | 4015 |  | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 4016 | TEST_F(LayerCallbackTest, DesiredPresentTime) { | 
|  | 4017 | sp<SurfaceControl> layer; | 
|  | 4018 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 4019 |  | 
|  | 4020 | Transaction transaction; | 
|  | 4021 | CallbackHelper callback; | 
|  | 4022 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 4023 | if (err) { | 
|  | 4024 | GTEST_SUCCEED() << "test not supported"; | 
|  | 4025 | return; | 
|  | 4026 | } | 
|  | 4027 |  | 
|  | 4028 | // Try to present 100ms in the future | 
|  | 4029 | nsecs_t time = systemTime() + (100 * 1e6); | 
|  | 4030 |  | 
|  | 4031 | transaction.setDesiredPresentTime(time); | 
|  | 4032 | transaction.apply(); | 
|  | 4033 |  | 
|  | 4034 | ExpectedResult expected; | 
|  | 4035 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 4036 | expected.addExpectedPresentTime(time); | 
|  | 4037 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 4038 | } | 
|  | 4039 |  | 
|  | 4040 | TEST_F(LayerCallbackTest, DesiredPresentTime_Multiple) { | 
|  | 4041 | sp<SurfaceControl> layer; | 
|  | 4042 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 4043 |  | 
|  | 4044 | Transaction transaction; | 
|  | 4045 | CallbackHelper callback1; | 
|  | 4046 | int err = fillTransaction(transaction, &callback1, layer); | 
|  | 4047 | if (err) { | 
|  | 4048 | GTEST_SUCCEED() << "test not supported"; | 
|  | 4049 | return; | 
|  | 4050 | } | 
|  | 4051 |  | 
|  | 4052 | // Try to present 100ms in the future | 
|  | 4053 | nsecs_t time = systemTime() + (100 * 1e6); | 
|  | 4054 |  | 
|  | 4055 | transaction.setDesiredPresentTime(time); | 
|  | 4056 | transaction.apply(); | 
|  | 4057 |  | 
|  | 4058 | ExpectedResult expected1; | 
|  | 4059 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 4060 | expected1.addExpectedPresentTime(time); | 
|  | 4061 |  | 
|  | 4062 | CallbackHelper callback2; | 
|  | 4063 | err = fillTransaction(transaction, &callback2, layer); | 
|  | 4064 | if (err) { | 
|  | 4065 | GTEST_SUCCEED() << "test not supported"; | 
|  | 4066 | return; | 
|  | 4067 | } | 
|  | 4068 |  | 
|  | 4069 | // Try to present 33ms after the first frame | 
|  | 4070 | time += (33.3 * 1e6); | 
|  | 4071 |  | 
|  | 4072 | transaction.setDesiredPresentTime(time); | 
|  | 4073 | transaction.apply(); | 
|  | 4074 |  | 
|  | 4075 | ExpectedResult expected2; | 
|  | 4076 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 4077 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 4078 | ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 4079 | expected2.addExpectedPresentTime(time); | 
|  | 4080 |  | 
|  | 4081 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); | 
|  | 4082 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); | 
|  | 4083 | } | 
|  | 4084 |  | 
|  | 4085 | TEST_F(LayerCallbackTest, DesiredPresentTime_OutOfOrder) { | 
|  | 4086 | sp<SurfaceControl> layer; | 
|  | 4087 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 4088 |  | 
|  | 4089 | Transaction transaction; | 
|  | 4090 | CallbackHelper callback1; | 
|  | 4091 | int err = fillTransaction(transaction, &callback1, layer); | 
|  | 4092 | if (err) { | 
|  | 4093 | GTEST_SUCCEED() << "test not supported"; | 
|  | 4094 | return; | 
|  | 4095 | } | 
|  | 4096 |  | 
|  | 4097 | // Try to present 100ms in the future | 
|  | 4098 | nsecs_t time = systemTime() + (100 * 1e6); | 
|  | 4099 |  | 
|  | 4100 | transaction.setDesiredPresentTime(time); | 
|  | 4101 | transaction.apply(); | 
|  | 4102 |  | 
|  | 4103 | ExpectedResult expected1; | 
|  | 4104 | expected1.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 4105 | expected1.addExpectedPresentTime(time); | 
|  | 4106 |  | 
|  | 4107 | CallbackHelper callback2; | 
|  | 4108 | err = fillTransaction(transaction, &callback2, layer); | 
|  | 4109 | if (err) { | 
|  | 4110 | GTEST_SUCCEED() << "test not supported"; | 
|  | 4111 | return; | 
|  | 4112 | } | 
|  | 4113 |  | 
|  | 4114 | // Try to present 33ms before the previous frame | 
|  | 4115 | time -= (33.3 * 1e6); | 
|  | 4116 |  | 
|  | 4117 | transaction.setDesiredPresentTime(time); | 
|  | 4118 | transaction.apply(); | 
|  | 4119 |  | 
|  | 4120 | ExpectedResult expected2; | 
|  | 4121 | expected2.addSurface(ExpectedResult::Transaction::PRESENTED, layer, | 
|  | 4122 | ExpectedResult::Buffer::ACQUIRED, | 
|  | 4123 | ExpectedResult::PreviousBuffer::RELEASED); | 
|  | 4124 |  | 
|  | 4125 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback1, expected1, true)); | 
|  | 4126 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback2, expected2, true)); | 
|  | 4127 | } | 
|  | 4128 |  | 
|  | 4129 | TEST_F(LayerCallbackTest, DesiredPresentTime_Past) { | 
|  | 4130 | sp<SurfaceControl> layer; | 
|  | 4131 | ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer()); | 
|  | 4132 |  | 
|  | 4133 | Transaction transaction; | 
|  | 4134 | CallbackHelper callback; | 
|  | 4135 | int err = fillTransaction(transaction, &callback, layer); | 
|  | 4136 | if (err) { | 
|  | 4137 | GTEST_SUCCEED() << "test not supported"; | 
|  | 4138 | return; | 
|  | 4139 | } | 
|  | 4140 |  | 
|  | 4141 | // Try to present 100ms in the past | 
|  | 4142 | nsecs_t time = systemTime() - (100 * 1e6); | 
|  | 4143 |  | 
|  | 4144 | transaction.setDesiredPresentTime(time); | 
|  | 4145 | transaction.apply(); | 
|  | 4146 |  | 
|  | 4147 | ExpectedResult expected; | 
|  | 4148 | expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer); | 
|  | 4149 | expected.addExpectedPresentTime(systemTime()); | 
|  | 4150 | EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true)); | 
|  | 4151 | } | 
|  | 4152 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 4153 | class LayerUpdateTest : public LayerTransactionTest { | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4154 | protected: | 
|  | 4155 | virtual void SetUp() { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4156 | LayerTransactionTest::SetUp(); | 
|  | 4157 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4158 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 4159 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); | 
|  | 4160 | ASSERT_FALSE(display == nullptr); | 
|  | 4161 |  | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 4162 | DisplayInfo info; | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 4163 | ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayInfo(display, &info)); | 
| Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 4164 |  | 
|  | 4165 | ssize_t displayWidth = info.w; | 
|  | 4166 | ssize_t displayHeight = info.h; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4167 |  | 
|  | 4168 | // Background surface | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4169 | mBGSurfaceControl = createLayer(String8("BG Test Surface"), displayWidth, | 
|  | 4170 | displayHeight, 0); | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 4171 | ASSERT_TRUE(mBGSurfaceControl != nullptr); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4172 | ASSERT_TRUE(mBGSurfaceControl->isValid()); | 
|  | 4173 | fillSurfaceRGBA8(mBGSurfaceControl, 63, 63, 195); | 
|  | 4174 |  | 
|  | 4175 | // Foreground surface | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4176 | mFGSurfaceControl = createLayer(String8("FG Test Surface"), 64, 64, 0); | 
|  | 4177 |  | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 4178 | ASSERT_TRUE(mFGSurfaceControl != nullptr); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4179 | ASSERT_TRUE(mFGSurfaceControl->isValid()); | 
|  | 4180 |  | 
|  | 4181 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 4182 |  | 
|  | 4183 | // Synchronization surface | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4184 | mSyncSurfaceControl = createLayer(String8("Sync Test Surface"), 1, 1, 0); | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 4185 | ASSERT_TRUE(mSyncSurfaceControl != nullptr); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4186 | ASSERT_TRUE(mSyncSurfaceControl->isValid()); | 
|  | 4187 |  | 
|  | 4188 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 4189 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4190 | asTransaction([&](Transaction& t) { | 
|  | 4191 | t.setDisplayLayerStack(display, 0); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4192 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4193 | t.setLayer(mBGSurfaceControl, INT32_MAX - 2).show(mBGSurfaceControl); | 
| Pablo Ceballos | 5e4fcbe | 2015-09-02 09:53:16 -0700 | [diff] [blame] | 4194 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4195 | t.setLayer(mFGSurfaceControl, INT32_MAX - 1) | 
|  | 4196 | .setPosition(mFGSurfaceControl, 64, 64) | 
|  | 4197 | .show(mFGSurfaceControl); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4198 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4199 | t.setLayer(mSyncSurfaceControl, INT32_MAX - 1) | 
|  | 4200 | .setPosition(mSyncSurfaceControl, displayWidth - 2, displayHeight - 2) | 
|  | 4201 | .show(mSyncSurfaceControl); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4202 | }); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4203 | } | 
|  | 4204 |  | 
|  | 4205 | virtual void TearDown() { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4206 | LayerTransactionTest::TearDown(); | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4207 | mBGSurfaceControl = 0; | 
|  | 4208 | mFGSurfaceControl = 0; | 
|  | 4209 | mSyncSurfaceControl = 0; | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4210 | } | 
|  | 4211 |  | 
|  | 4212 | void waitForPostedBuffers() { | 
|  | 4213 | // Since the sync surface is in synchronous mode (i.e. double buffered) | 
|  | 4214 | // posting three buffers to it should ensure that at least two | 
|  | 4215 | // SurfaceFlinger::handlePageFlip calls have been made, which should | 
|  | 4216 | // guaranteed that a buffer posted to another Surface has been retired. | 
|  | 4217 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 4218 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 4219 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 4220 | } | 
|  | 4221 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4222 |  | 
| Jamie Gennis | 23c2c5d | 2011-10-11 19:22:19 -0700 | [diff] [blame] | 4223 | sp<SurfaceControl> mBGSurfaceControl; | 
|  | 4224 | sp<SurfaceControl> mFGSurfaceControl; | 
|  | 4225 |  | 
|  | 4226 | // This surface is used to ensure that the buffers posted to | 
|  | 4227 | // mFGSurfaceControl have been picked up by SurfaceFlinger. | 
|  | 4228 | sp<SurfaceControl> mSyncSurfaceControl; | 
|  | 4229 | }; | 
|  | 4230 |  | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4231 | TEST_F(LayerUpdateTest, RelativesAreNotDetached) { | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4232 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4233 | std::unique_ptr<ScreenCapture> sc; | 
|  | 4234 |  | 
|  | 4235 | sp<SurfaceControl> relative = createLayer(String8("relativeTestSurface"), 10, 10, 0); | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4236 | fillSurfaceRGBA8(relative, 10, 10, 10); | 
|  | 4237 | waitForPostedBuffers(); | 
|  | 4238 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4239 | Transaction{} | 
|  | 4240 | .setRelativeLayer(relative, mFGSurfaceControl->getHandle(), 1) | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4241 | .setPosition(relative, 64, 64) | 
|  | 4242 | .apply(); | 
|  | 4243 |  | 
|  | 4244 | { | 
|  | 4245 | // The relative should be on top of the FG control. | 
|  | 4246 | ScreenCapture::captureScreen(&sc); | 
|  | 4247 | sc->checkPixel(64, 64, 10, 10, 10); | 
|  | 4248 | } | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4249 | Transaction{}.detachChildren(mFGSurfaceControl).apply(); | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4250 |  | 
|  | 4251 | { | 
|  | 4252 | // Nothing should change at this point. | 
|  | 4253 | ScreenCapture::captureScreen(&sc); | 
|  | 4254 | sc->checkPixel(64, 64, 10, 10, 10); | 
|  | 4255 | } | 
|  | 4256 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4257 | Transaction{}.hide(relative).apply(); | 
| Robert Carr | 7f619b2 | 2017-11-06 12:56:35 -0800 | [diff] [blame] | 4258 |  | 
|  | 4259 | { | 
|  | 4260 | // Ensure that the relative was actually hidden, rather than | 
|  | 4261 | // being left in the detached but visible state. | 
|  | 4262 | ScreenCapture::captureScreen(&sc); | 
|  | 4263 | sc->expectFGColor(64, 64); | 
|  | 4264 | } | 
|  | 4265 | } | 
|  | 4266 |  | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4267 | class GeometryLatchingTest : public LayerUpdateTest { | 
|  | 4268 | protected: | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4269 | void EXPECT_INITIAL_STATE(const char* trace) { | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4270 | SCOPED_TRACE(trace); | 
|  | 4271 | ScreenCapture::captureScreen(&sc); | 
|  | 4272 | // We find the leading edge of the FG surface. | 
|  | 4273 | sc->expectFGColor(127, 127); | 
|  | 4274 | sc->expectBGColor(128, 128); | 
|  | 4275 | } | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 4276 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4277 | void lockAndFillFGBuffer() { fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63, false); } | 
| Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 4278 |  | 
|  | 4279 | void unlockFGBuffer() { | 
|  | 4280 | sp<Surface> s = mFGSurfaceControl->getSurface(); | 
|  | 4281 | ASSERT_EQ(NO_ERROR, s->unlockAndPost()); | 
|  | 4282 | waitForPostedBuffers(); | 
|  | 4283 | } | 
|  | 4284 |  | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4285 | void completeFGResize() { | 
|  | 4286 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 4287 | waitForPostedBuffers(); | 
|  | 4288 | } | 
|  | 4289 | void restoreInitialState() { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4290 | asTransaction([&](Transaction& t) { | 
|  | 4291 | t.setSize(mFGSurfaceControl, 64, 64); | 
|  | 4292 | t.setPosition(mFGSurfaceControl, 64, 64); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4293 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 64, 64)); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4294 | }); | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4295 |  | 
|  | 4296 | EXPECT_INITIAL_STATE("After restoring initial state"); | 
|  | 4297 | } | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4298 | std::unique_ptr<ScreenCapture> sc; | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4299 | }; | 
|  | 4300 |  | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4301 | class CropLatchingTest : public GeometryLatchingTest { | 
|  | 4302 | protected: | 
|  | 4303 | void EXPECT_CROPPED_STATE(const char* trace) { | 
|  | 4304 | SCOPED_TRACE(trace); | 
|  | 4305 | ScreenCapture::captureScreen(&sc); | 
|  | 4306 | // The edge should be moved back one pixel by our crop. | 
|  | 4307 | sc->expectFGColor(126, 126); | 
|  | 4308 | sc->expectBGColor(127, 127); | 
|  | 4309 | sc->expectBGColor(128, 128); | 
|  | 4310 | } | 
| chaviw | 59f5c56 | 2017-06-28 16:39:06 -0700 | [diff] [blame] | 4311 |  | 
|  | 4312 | void EXPECT_RESIZE_STATE(const char* trace) { | 
|  | 4313 | SCOPED_TRACE(trace); | 
|  | 4314 | ScreenCapture::captureScreen(&sc); | 
|  | 4315 | // The FG is now resized too 128,128 at 64,64 | 
|  | 4316 | sc->expectFGColor(64, 64); | 
|  | 4317 | sc->expectFGColor(191, 191); | 
|  | 4318 | sc->expectBGColor(192, 192); | 
|  | 4319 | } | 
| Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 4320 | }; | 
|  | 4321 |  | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4322 | TEST_F(LayerUpdateTest, DeferredTransactionTest) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4323 | std::unique_ptr<ScreenCapture> sc; | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4324 | { | 
|  | 4325 | SCOPED_TRACE("before anything"); | 
|  | 4326 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4327 | sc->expectBGColor(32, 32); | 
|  | 4328 | sc->expectFGColor(96, 96); | 
|  | 4329 | sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4330 | } | 
|  | 4331 |  | 
|  | 4332 | // set up two deferred transactions on different frames | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4333 | asTransaction([&](Transaction& t) { | 
|  | 4334 | t.setAlpha(mFGSurfaceControl, 0.75); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4335 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), | 
|  | 4336 | mSyncSurfaceControl->getSurface()->getNextFrameNumber()); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4337 | }); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4338 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4339 | asTransaction([&](Transaction& t) { | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4340 | t.setPosition(mFGSurfaceControl, 128, 128); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4341 | t.deferTransactionUntil_legacy(mFGSurfaceControl, mSyncSurfaceControl->getHandle(), | 
|  | 4342 | mSyncSurfaceControl->getSurface()->getNextFrameNumber() + 1); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4343 | }); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4344 |  | 
|  | 4345 | { | 
|  | 4346 | SCOPED_TRACE("before any trigger"); | 
|  | 4347 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4348 | sc->expectBGColor(32, 32); | 
|  | 4349 | sc->expectFGColor(96, 96); | 
|  | 4350 | sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4351 | } | 
|  | 4352 |  | 
|  | 4353 | // should trigger the first deferred transaction, but not the second one | 
|  | 4354 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 4355 | { | 
|  | 4356 | SCOPED_TRACE("after first trigger"); | 
|  | 4357 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4358 | sc->expectBGColor(32, 32); | 
|  | 4359 | sc->checkPixel(96, 96, 162, 63, 96); | 
|  | 4360 | sc->expectBGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4361 | } | 
|  | 4362 |  | 
|  | 4363 | // should show up immediately since it's not deferred | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4364 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 1.0); }); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4365 |  | 
|  | 4366 | // trigger the second deferred transaction | 
|  | 4367 | fillSurfaceRGBA8(mSyncSurfaceControl, 31, 31, 31); | 
|  | 4368 | { | 
|  | 4369 | SCOPED_TRACE("after second trigger"); | 
|  | 4370 | ScreenCapture::captureScreen(&sc); | 
| Robert Carr | 2b91c82 | 2017-02-21 19:41:24 -0800 | [diff] [blame] | 4371 | sc->expectBGColor(32, 32); | 
|  | 4372 | sc->expectBGColor(96, 96); | 
|  | 4373 | sc->expectFGColor(160, 160); | 
| Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 4374 | } | 
|  | 4375 | } | 
|  | 4376 |  | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4377 | TEST_F(LayerUpdateTest, LayerWithNoBuffersResizesImmediately) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4378 | std::unique_ptr<ScreenCapture> sc; | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4379 |  | 
|  | 4380 | sp<SurfaceControl> childNoBuffer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4381 | createSurface(mClient, "Bufferless child", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 4382 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 4383 | sp<SurfaceControl> childBuffer = createSurface(mClient, "Buffered child", 20, 20, | 
|  | 4384 | PIXEL_FORMAT_RGBA_8888, 0, childNoBuffer.get()); | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4385 | fillSurfaceRGBA8(childBuffer, 200, 200, 200); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4386 | SurfaceComposerClient::Transaction{} | 
|  | 4387 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 10, 10)) | 
|  | 4388 | .show(childNoBuffer) | 
|  | 4389 | .show(childBuffer) | 
|  | 4390 | .apply(true); | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4391 | { | 
|  | 4392 | ScreenCapture::captureScreen(&sc); | 
|  | 4393 | sc->expectChildColor(73, 73); | 
|  | 4394 | sc->expectFGColor(74, 74); | 
|  | 4395 | } | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 4396 | SurfaceComposerClient::Transaction{} | 
|  | 4397 | .setCrop_legacy(childNoBuffer, Rect(0, 0, 20, 20)) | 
|  | 4398 | .apply(true); | 
| Robert Carr | e392b55 | 2017-09-19 12:16:05 -0700 | [diff] [blame] | 4399 | { | 
|  | 4400 | ScreenCapture::captureScreen(&sc); | 
|  | 4401 | sc->expectChildColor(73, 73); | 
|  | 4402 | sc->expectChildColor(74, 74); | 
|  | 4403 | } | 
|  | 4404 | } | 
|  | 4405 |  | 
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 4406 | TEST_F(LayerUpdateTest, MergingTransactions) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4407 | std::unique_ptr<ScreenCapture> sc; | 
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 4408 | { | 
|  | 4409 | SCOPED_TRACE("before move"); | 
|  | 4410 | ScreenCapture::captureScreen(&sc); | 
|  | 4411 | sc->expectBGColor(0, 12); | 
|  | 4412 | sc->expectFGColor(75, 75); | 
|  | 4413 | sc->expectBGColor(145, 145); | 
|  | 4414 | } | 
|  | 4415 |  | 
|  | 4416 | Transaction t1, t2; | 
|  | 4417 | t1.setPosition(mFGSurfaceControl, 128, 128); | 
|  | 4418 | t2.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4419 | // We expect that the position update from t2 now | 
|  | 4420 | // overwrites the position update from t1. | 
|  | 4421 | t1.merge(std::move(t2)); | 
|  | 4422 | t1.apply(); | 
|  | 4423 |  | 
|  | 4424 | { | 
|  | 4425 | ScreenCapture::captureScreen(&sc); | 
|  | 4426 | sc->expectFGColor(1, 1); | 
|  | 4427 | } | 
|  | 4428 | } | 
|  | 4429 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4430 | class ChildLayerTest : public LayerUpdateTest { | 
|  | 4431 | protected: | 
|  | 4432 | void SetUp() override { | 
|  | 4433 | LayerUpdateTest::SetUp(); | 
| Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 4434 | mChild = createSurface(mClient, "Child surface", 10, 15, PIXEL_FORMAT_RGBA_8888, 0, | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4435 | mFGSurfaceControl.get()); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4436 | fillSurfaceRGBA8(mChild, 200, 200, 200); | 
|  | 4437 |  | 
|  | 4438 | { | 
|  | 4439 | SCOPED_TRACE("before anything"); | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4440 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4441 | mCapture->expectChildColor(64, 64); | 
|  | 4442 | } | 
|  | 4443 | } | 
|  | 4444 | void TearDown() override { | 
|  | 4445 | LayerUpdateTest::TearDown(); | 
|  | 4446 | mChild = 0; | 
|  | 4447 | } | 
|  | 4448 |  | 
|  | 4449 | sp<SurfaceControl> mChild; | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4450 | std::unique_ptr<ScreenCapture> mCapture; | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4451 | }; | 
|  | 4452 |  | 
|  | 4453 | TEST_F(ChildLayerTest, ChildLayerPositioning) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4454 | asTransaction([&](Transaction& t) { | 
|  | 4455 | t.show(mChild); | 
|  | 4456 | t.setPosition(mChild, 10, 10); | 
|  | 4457 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4458 | }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4459 |  | 
|  | 4460 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4461 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4462 | // Top left of foreground must now be visible | 
|  | 4463 | mCapture->expectFGColor(64, 64); | 
|  | 4464 | // But 10 pixels in we should see the child surface | 
|  | 4465 | mCapture->expectChildColor(74, 74); | 
|  | 4466 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4467 | mCapture->expectFGColor(84, 84); | 
|  | 4468 | } | 
|  | 4469 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4470 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4471 |  | 
|  | 4472 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4473 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4474 | // Top left of foreground should now be at 0, 0 | 
|  | 4475 | mCapture->expectFGColor(0, 0); | 
|  | 4476 | // But 10 pixels in we should see the child surface | 
|  | 4477 | mCapture->expectChildColor(10, 10); | 
|  | 4478 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4479 | mCapture->expectFGColor(20, 20); | 
|  | 4480 | } | 
|  | 4481 | } | 
|  | 4482 |  | 
| Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4483 | TEST_F(ChildLayerTest, ChildLayerCropping) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4484 | asTransaction([&](Transaction& t) { | 
|  | 4485 | t.show(mChild); | 
|  | 4486 | t.setPosition(mChild, 0, 0); | 
|  | 4487 | t.setPosition(mFGSurfaceControl, 0, 0); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 4488 | t.setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 5, 5)); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4489 | }); | 
| Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4490 |  | 
|  | 4491 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4492 | mCapture = screenshot(); | 
| Robert Carr | 41b08b5 | 2017-06-01 16:11:34 -0700 | [diff] [blame] | 4493 | mCapture->expectChildColor(0, 0); | 
|  | 4494 | mCapture->expectChildColor(4, 4); | 
|  | 4495 | mCapture->expectBGColor(5, 5); | 
|  | 4496 | } | 
|  | 4497 | } | 
|  | 4498 |  | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4499 | TEST_F(ChildLayerTest, ChildLayerConstraints) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4500 | asTransaction([&](Transaction& t) { | 
|  | 4501 | t.show(mChild); | 
|  | 4502 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4503 | t.setPosition(mChild, 63, 63); | 
|  | 4504 | }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4505 |  | 
|  | 4506 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4507 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4508 | mCapture->expectFGColor(0, 0); | 
|  | 4509 | // Last pixel in foreground should now be the child. | 
|  | 4510 | mCapture->expectChildColor(63, 63); | 
|  | 4511 | // But the child should be constrained and the next pixel | 
|  | 4512 | // must be the background | 
|  | 4513 | mCapture->expectBGColor(64, 64); | 
|  | 4514 | } | 
|  | 4515 | } | 
|  | 4516 |  | 
|  | 4517 | TEST_F(ChildLayerTest, ChildLayerScaling) { | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4518 | asTransaction([&](Transaction& t) { t.setPosition(mFGSurfaceControl, 0, 0); }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4519 |  | 
|  | 4520 | // Find the boundary between the parent and child | 
|  | 4521 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4522 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4523 | mCapture->expectChildColor(9, 9); | 
|  | 4524 | mCapture->expectFGColor(10, 10); | 
|  | 4525 | } | 
|  | 4526 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4527 | asTransaction([&](Transaction& t) { t.setMatrix(mFGSurfaceControl, 2.0, 0, 0, 2.0); }); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4528 |  | 
|  | 4529 | // The boundary should be twice as far from the origin now. | 
|  | 4530 | // The pixels from the last test should all be child now | 
|  | 4531 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4532 | mCapture = screenshot(); | 
| Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 4533 | mCapture->expectChildColor(9, 9); | 
|  | 4534 | mCapture->expectChildColor(10, 10); | 
|  | 4535 | mCapture->expectChildColor(19, 19); | 
|  | 4536 | mCapture->expectFGColor(20, 20); | 
|  | 4537 | } | 
|  | 4538 | } | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4539 |  | 
| Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 4540 | // A child with a scale transform should be cropped by its parent bounds. | 
|  | 4541 | TEST_F(ChildLayerTest, ChildLayerScalingCroppedByParent) { | 
|  | 4542 | asTransaction([&](Transaction& t) { | 
|  | 4543 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4544 | t.setPosition(mChild, 0, 0); | 
|  | 4545 | }); | 
|  | 4546 |  | 
|  | 4547 | // Find the boundary between the parent and child. | 
|  | 4548 | { | 
|  | 4549 | mCapture = screenshot(); | 
|  | 4550 | mCapture->expectChildColor(0, 0); | 
|  | 4551 | mCapture->expectChildColor(9, 9); | 
|  | 4552 | mCapture->expectFGColor(10, 10); | 
|  | 4553 | } | 
|  | 4554 |  | 
|  | 4555 | asTransaction([&](Transaction& t) { t.setMatrix(mChild, 10.0, 0, 0, 10.0); }); | 
|  | 4556 |  | 
|  | 4557 | // The child should fill its parent bounds and be cropped by it. | 
|  | 4558 | { | 
|  | 4559 | mCapture = screenshot(); | 
|  | 4560 | mCapture->expectChildColor(0, 0); | 
|  | 4561 | mCapture->expectChildColor(63, 63); | 
|  | 4562 | mCapture->expectBGColor(64, 64); | 
|  | 4563 | } | 
|  | 4564 | } | 
|  | 4565 |  | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4566 | TEST_F(ChildLayerTest, ChildLayerAlpha) { | 
|  | 4567 | fillSurfaceRGBA8(mBGSurfaceControl, 0, 0, 254); | 
|  | 4568 | fillSurfaceRGBA8(mFGSurfaceControl, 254, 0, 0); | 
|  | 4569 | fillSurfaceRGBA8(mChild, 0, 254, 0); | 
|  | 4570 | waitForPostedBuffers(); | 
|  | 4571 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4572 | asTransaction([&](Transaction& t) { | 
|  | 4573 | t.show(mChild); | 
|  | 4574 | t.setPosition(mChild, 0, 0); | 
|  | 4575 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4576 | }); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4577 |  | 
|  | 4578 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4579 | mCapture = screenshot(); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4580 | // Unblended child color | 
|  | 4581 | mCapture->checkPixel(0, 0, 0, 254, 0); | 
|  | 4582 | } | 
|  | 4583 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4584 | asTransaction([&](Transaction& t) { t.setAlpha(mChild, 0.5); }); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4585 |  | 
|  | 4586 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4587 | mCapture = screenshot(); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4588 | // Child and BG blended. | 
|  | 4589 | mCapture->checkPixel(0, 0, 127, 127, 0); | 
|  | 4590 | } | 
|  | 4591 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4592 | asTransaction([&](Transaction& t) { t.setAlpha(mFGSurfaceControl, 0.5); }); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4593 |  | 
|  | 4594 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4595 | mCapture = screenshot(); | 
| Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 4596 | // Child and BG blended. | 
|  | 4597 | mCapture->checkPixel(0, 0, 95, 64, 95); | 
|  | 4598 | } | 
|  | 4599 | } | 
|  | 4600 |  | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4601 | TEST_F(ChildLayerTest, ReparentChildren) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4602 | asTransaction([&](Transaction& t) { | 
|  | 4603 | t.show(mChild); | 
|  | 4604 | t.setPosition(mChild, 10, 10); | 
|  | 4605 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4606 | }); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4607 |  | 
|  | 4608 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4609 | mCapture = screenshot(); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4610 | // Top left of foreground must now be visible | 
|  | 4611 | mCapture->expectFGColor(64, 64); | 
|  | 4612 | // But 10 pixels in we should see the child surface | 
|  | 4613 | mCapture->expectChildColor(74, 74); | 
|  | 4614 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4615 | mCapture->expectFGColor(84, 84); | 
|  | 4616 | } | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4617 |  | 
|  | 4618 | asTransaction([&](Transaction& t) { | 
|  | 4619 | t.reparentChildren(mFGSurfaceControl, mBGSurfaceControl->getHandle()); | 
|  | 4620 | }); | 
|  | 4621 |  | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4622 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4623 | mCapture = screenshot(); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4624 | mCapture->expectFGColor(64, 64); | 
|  | 4625 | // In reparenting we should have exposed the entire foreground surface. | 
|  | 4626 | mCapture->expectFGColor(74, 74); | 
|  | 4627 | // And the child layer should now begin at 10, 10 (since the BG | 
|  | 4628 | // layer is at (0, 0)). | 
|  | 4629 | mCapture->expectBGColor(9, 9); | 
|  | 4630 | mCapture->expectChildColor(10, 10); | 
|  | 4631 | } | 
|  | 4632 | } | 
|  | 4633 |  | 
| Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4634 | TEST_F(ChildLayerTest, ChildrenSurviveParentDestruction) { | 
|  | 4635 | sp<SurfaceControl> mGrandChild = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4636 | 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] | 4637 | fillSurfaceRGBA8(mGrandChild, 111, 111, 111); | 
|  | 4638 |  | 
|  | 4639 | { | 
|  | 4640 | SCOPED_TRACE("Grandchild visible"); | 
|  | 4641 | ScreenCapture::captureScreen(&mCapture); | 
|  | 4642 | mCapture->checkPixel(64, 64, 111, 111, 111); | 
|  | 4643 | } | 
|  | 4644 |  | 
| Robert Carr | 8724653 | 2019-02-04 15:20:26 -0800 | [diff] [blame] | 4645 | mChild.clear(); | 
| Robert Carr | 2e102c9 | 2018-10-23 12:11:15 -0700 | [diff] [blame] | 4646 |  | 
|  | 4647 | { | 
|  | 4648 | SCOPED_TRACE("After destroying child"); | 
|  | 4649 | ScreenCapture::captureScreen(&mCapture); | 
|  | 4650 | mCapture->expectFGColor(64, 64); | 
|  | 4651 | } | 
|  | 4652 |  | 
|  | 4653 | asTransaction([&](Transaction& t) { | 
|  | 4654 | t.reparent(mGrandChild, mFGSurfaceControl->getHandle()); | 
|  | 4655 | }); | 
|  | 4656 |  | 
|  | 4657 | { | 
|  | 4658 | SCOPED_TRACE("After reparenting grandchild"); | 
|  | 4659 | ScreenCapture::captureScreen(&mCapture); | 
|  | 4660 | mCapture->checkPixel(64, 64, 111, 111, 111); | 
|  | 4661 | } | 
|  | 4662 | } | 
|  | 4663 |  | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4664 | TEST_F(ChildLayerTest, DetachChildrenSameClient) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4665 | asTransaction([&](Transaction& t) { | 
|  | 4666 | t.show(mChild); | 
|  | 4667 | t.setPosition(mChild, 10, 10); | 
|  | 4668 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4669 | }); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4670 |  | 
|  | 4671 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4672 | mCapture = screenshot(); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4673 | // Top left of foreground must now be visible | 
|  | 4674 | mCapture->expectFGColor(64, 64); | 
|  | 4675 | // But 10 pixels in we should see the child surface | 
|  | 4676 | mCapture->expectChildColor(74, 74); | 
|  | 4677 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4678 | mCapture->expectFGColor(84, 84); | 
|  | 4679 | } | 
|  | 4680 |  | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4681 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4682 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4683 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4684 | asTransaction([&](Transaction& t) { t.hide(mChild); }); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4685 |  | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4686 | // Since the child has the same client as the parent, it will not get | 
|  | 4687 | // detached and will be hidden. | 
|  | 4688 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4689 | mCapture = screenshot(); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4690 | mCapture->expectFGColor(64, 64); | 
|  | 4691 | mCapture->expectFGColor(74, 74); | 
|  | 4692 | mCapture->expectFGColor(84, 84); | 
|  | 4693 | } | 
|  | 4694 | } | 
|  | 4695 |  | 
|  | 4696 | TEST_F(ChildLayerTest, DetachChildrenDifferentClient) { | 
|  | 4697 | sp<SurfaceComposerClient> mNewComposerClient = new SurfaceComposerClient; | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4698 | sp<SurfaceControl> mChildNewClient = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 4699 | createSurface(mNewComposerClient, "New Child Test Surface", 10, 10, | 
|  | 4700 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4701 |  | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4702 | ASSERT_TRUE(mChildNewClient->isValid()); | 
|  | 4703 |  | 
|  | 4704 | fillSurfaceRGBA8(mChildNewClient, 200, 200, 200); | 
|  | 4705 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4706 | asTransaction([&](Transaction& t) { | 
|  | 4707 | t.hide(mChild); | 
|  | 4708 | t.show(mChildNewClient); | 
|  | 4709 | t.setPosition(mChildNewClient, 10, 10); | 
|  | 4710 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 4711 | }); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4712 |  | 
|  | 4713 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4714 | mCapture = screenshot(); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4715 | // Top left of foreground must now be visible | 
|  | 4716 | mCapture->expectFGColor(64, 64); | 
|  | 4717 | // But 10 pixels in we should see the child surface | 
|  | 4718 | mCapture->expectChildColor(74, 74); | 
|  | 4719 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4720 | mCapture->expectFGColor(84, 84); | 
|  | 4721 | } | 
|  | 4722 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4723 | asTransaction([&](Transaction& t) { t.detachChildren(mFGSurfaceControl); }); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4724 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4725 | asTransaction([&](Transaction& t) { t.hide(mChildNewClient); }); | 
| chaviw | 161410b0 | 2017-07-27 10:46:08 -0700 | [diff] [blame] | 4726 |  | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4727 | // Nothing should have changed. | 
|  | 4728 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4729 | mCapture = screenshot(); | 
| Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 4730 | mCapture->expectFGColor(64, 64); | 
|  | 4731 | mCapture->expectChildColor(74, 74); | 
|  | 4732 | mCapture->expectFGColor(84, 84); | 
|  | 4733 | } | 
|  | 4734 | } | 
|  | 4735 |  | 
| chaviw | 5aedec9 | 2018-10-22 10:40:38 -0700 | [diff] [blame] | 4736 | TEST_F(ChildLayerTest, DetachChildrenThenAttach) { | 
|  | 4737 | sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; | 
|  | 4738 | sp<SurfaceControl> childNewClient = | 
|  | 4739 | newComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, | 
|  | 4740 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 4741 |  | 
|  | 4742 | ASSERT_TRUE(childNewClient != nullptr); | 
|  | 4743 | ASSERT_TRUE(childNewClient->isValid()); | 
|  | 4744 |  | 
|  | 4745 | fillSurfaceRGBA8(childNewClient, 200, 200, 200); | 
|  | 4746 |  | 
|  | 4747 | Transaction() | 
|  | 4748 | .hide(mChild) | 
|  | 4749 | .show(childNewClient) | 
|  | 4750 | .setPosition(childNewClient, 10, 10) | 
|  | 4751 | .setPosition(mFGSurfaceControl, 64, 64) | 
|  | 4752 | .apply(); | 
|  | 4753 |  | 
|  | 4754 | { | 
|  | 4755 | mCapture = screenshot(); | 
|  | 4756 | // Top left of foreground must now be visible | 
|  | 4757 | mCapture->expectFGColor(64, 64); | 
|  | 4758 | // But 10 pixels in we should see the child surface | 
|  | 4759 | mCapture->expectChildColor(74, 74); | 
|  | 4760 | // And 10 more pixels we should be back to the foreground surface | 
|  | 4761 | mCapture->expectFGColor(84, 84); | 
|  | 4762 | } | 
|  | 4763 |  | 
|  | 4764 | Transaction().detachChildren(mFGSurfaceControl).apply(); | 
|  | 4765 | Transaction().hide(childNewClient).apply(); | 
|  | 4766 |  | 
|  | 4767 | // Nothing should have changed. | 
|  | 4768 | { | 
|  | 4769 | mCapture = screenshot(); | 
|  | 4770 | mCapture->expectFGColor(64, 64); | 
|  | 4771 | mCapture->expectChildColor(74, 74); | 
|  | 4772 | mCapture->expectFGColor(84, 84); | 
|  | 4773 | } | 
|  | 4774 |  | 
|  | 4775 | sp<SurfaceControl> newParentSurface = createLayer(String8("New Parent Surface"), 32, 32, 0); | 
|  | 4776 | fillLayerColor(ISurfaceComposerClient::eFXSurfaceBufferQueue, newParentSurface, Color::RED, 32, | 
|  | 4777 | 32); | 
|  | 4778 | Transaction() | 
|  | 4779 | .setLayer(newParentSurface, INT32_MAX - 1) | 
|  | 4780 | .show(newParentSurface) | 
|  | 4781 | .setPosition(newParentSurface, 20, 20) | 
|  | 4782 | .reparent(childNewClient, newParentSurface->getHandle()) | 
|  | 4783 | .apply(); | 
|  | 4784 | { | 
|  | 4785 | mCapture = screenshot(); | 
|  | 4786 | // Child is now hidden. | 
|  | 4787 | mCapture->expectColor(Rect(20, 20, 52, 52), Color::RED); | 
|  | 4788 | } | 
|  | 4789 | } | 
| chaviw | 43cb3cb | 2019-05-31 15:23:41 -0700 | [diff] [blame] | 4790 | TEST_F(ChildLayerTest, DetachChildrenWithDeferredTransaction) { | 
|  | 4791 | sp<SurfaceComposerClient> newComposerClient = new SurfaceComposerClient; | 
|  | 4792 | sp<SurfaceControl> childNewClient = | 
|  | 4793 | newComposerClient->createSurface(String8("New Child Test Surface"), 10, 10, | 
|  | 4794 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 4795 |  | 
|  | 4796 | ASSERT_TRUE(childNewClient != nullptr); | 
|  | 4797 | ASSERT_TRUE(childNewClient->isValid()); | 
|  | 4798 |  | 
|  | 4799 | fillSurfaceRGBA8(childNewClient, 200, 200, 200); | 
|  | 4800 |  | 
|  | 4801 | Transaction() | 
|  | 4802 | .hide(mChild) | 
|  | 4803 | .show(childNewClient) | 
|  | 4804 | .setPosition(childNewClient, 10, 10) | 
|  | 4805 | .setPosition(mFGSurfaceControl, 64, 64) | 
|  | 4806 | .apply(); | 
|  | 4807 |  | 
|  | 4808 | { | 
|  | 4809 | mCapture = screenshot(); | 
|  | 4810 | Rect rect = Rect(74, 74, 84, 84); | 
|  | 4811 | mCapture->expectBorder(rect, Color{195, 63, 63, 255}); | 
|  | 4812 | mCapture->expectColor(rect, Color{200, 200, 200, 255}); | 
|  | 4813 | } | 
|  | 4814 |  | 
|  | 4815 | Transaction() | 
|  | 4816 | .deferTransactionUntil_legacy(childNewClient, mFGSurfaceControl->getHandle(), | 
|  | 4817 | mFGSurfaceControl->getSurface()->getNextFrameNumber()) | 
|  | 4818 | .apply(); | 
|  | 4819 | Transaction().detachChildren(mFGSurfaceControl).apply(); | 
|  | 4820 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(mFGSurfaceControl, Color::RED, 32, 32)); | 
|  | 4821 |  | 
|  | 4822 | // BufferLayer can still dequeue buffers even though there's a detached layer with a | 
|  | 4823 | // deferred transaction. | 
|  | 4824 | { | 
|  | 4825 | SCOPED_TRACE("new buffer"); | 
|  | 4826 | mCapture = screenshot(); | 
|  | 4827 | Rect rect = Rect(74, 74, 84, 84); | 
|  | 4828 | mCapture->expectBorder(rect, Color::RED); | 
|  | 4829 | mCapture->expectColor(rect, Color{200, 200, 200, 255}); | 
|  | 4830 | } | 
|  | 4831 | } | 
| chaviw | 5aedec9 | 2018-10-22 10:40:38 -0700 | [diff] [blame] | 4832 |  | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4833 | TEST_F(ChildLayerTest, ChildrenInheritNonTransformScalingFromParent) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4834 | asTransaction([&](Transaction& t) { | 
|  | 4835 | t.show(mChild); | 
|  | 4836 | t.setPosition(mChild, 0, 0); | 
|  | 4837 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4838 | }); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4839 |  | 
|  | 4840 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4841 | mCapture = screenshot(); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4842 | // We've positioned the child in the top left. | 
|  | 4843 | mCapture->expectChildColor(0, 0); | 
| Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 4844 | // But it's only 10x15. | 
|  | 4845 | mCapture->expectFGColor(10, 15); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4846 | } | 
|  | 4847 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4848 | asTransaction([&](Transaction& t) { | 
|  | 4849 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); | 
|  | 4850 | // We cause scaling by 2. | 
|  | 4851 | t.setSize(mFGSurfaceControl, 128, 128); | 
|  | 4852 | }); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4853 |  | 
|  | 4854 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4855 | mCapture = screenshot(); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4856 | // We've positioned the child in the top left. | 
|  | 4857 | mCapture->expectChildColor(0, 0); | 
|  | 4858 | mCapture->expectChildColor(10, 10); | 
| Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 4859 | mCapture->expectChildColor(19, 29); | 
|  | 4860 | // And now it should be scaled all the way to 20x30 | 
|  | 4861 | mCapture->expectFGColor(20, 30); | 
| Robert Carr | 9b429f4 | 2017-04-17 14:56:57 -0700 | [diff] [blame] | 4862 | } | 
|  | 4863 | } | 
|  | 4864 |  | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4865 | // Regression test for b/37673612 | 
|  | 4866 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransform) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 4867 | asTransaction([&](Transaction& t) { | 
|  | 4868 | t.show(mChild); | 
|  | 4869 | t.setPosition(mChild, 0, 0); | 
|  | 4870 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4871 | }); | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4872 |  | 
|  | 4873 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4874 | mCapture = screenshot(); | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4875 | // We've positioned the child in the top left. | 
|  | 4876 | mCapture->expectChildColor(0, 0); | 
| Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 4877 | mCapture->expectChildColor(9, 14); | 
|  | 4878 | // But it's only 10x15. | 
|  | 4879 | mCapture->expectFGColor(10, 15); | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4880 | } | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4881 | // We set things up as in b/37673612 so that there is a mismatch between the buffer size and | 
|  | 4882 | // the WM specified state size. | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 4883 | asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); }); | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4884 | sp<Surface> s = mFGSurfaceControl->getSurface(); | 
|  | 4885 | auto anw = static_cast<ANativeWindow*>(s.get()); | 
|  | 4886 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); | 
|  | 4887 | native_window_set_buffers_dimensions(anw, 64, 128); | 
|  | 4888 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 4889 | waitForPostedBuffers(); | 
|  | 4890 |  | 
|  | 4891 | { | 
|  | 4892 | // The child should still be in the same place and not have any strange scaling as in | 
|  | 4893 | // b/37673612. | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 4894 | mCapture = screenshot(); | 
| Robert Carr | 1725eee | 2017-04-26 18:32:15 -0700 | [diff] [blame] | 4895 | mCapture->expectChildColor(0, 0); | 
|  | 4896 | mCapture->expectFGColor(10, 10); | 
|  | 4897 | } | 
|  | 4898 | } | 
|  | 4899 |  | 
| Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 4900 | // A child with a buffer transform from its parents should be cropped by its parent bounds. | 
|  | 4901 | TEST_F(ChildLayerTest, ChildCroppedByParentWithBufferTransform) { | 
|  | 4902 | asTransaction([&](Transaction& t) { | 
|  | 4903 | t.show(mChild); | 
|  | 4904 | t.setPosition(mChild, 0, 0); | 
|  | 4905 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4906 | t.setSize(mChild, 100, 100); | 
|  | 4907 | }); | 
|  | 4908 | fillSurfaceRGBA8(mChild, 200, 200, 200); | 
|  | 4909 |  | 
|  | 4910 | { | 
|  | 4911 | mCapture = screenshot(); | 
|  | 4912 |  | 
|  | 4913 | mCapture->expectChildColor(0, 0); | 
|  | 4914 | mCapture->expectChildColor(63, 63); | 
|  | 4915 | mCapture->expectBGColor(64, 64); | 
|  | 4916 | } | 
|  | 4917 |  | 
|  | 4918 | asTransaction([&](Transaction& t) { t.setSize(mFGSurfaceControl, 128, 64); }); | 
|  | 4919 | sp<Surface> s = mFGSurfaceControl->getSurface(); | 
|  | 4920 | auto anw = static_cast<ANativeWindow*>(s.get()); | 
|  | 4921 | // Apply a 90 transform on the buffer. | 
|  | 4922 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); | 
|  | 4923 | native_window_set_buffers_dimensions(anw, 64, 128); | 
|  | 4924 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 4925 | waitForPostedBuffers(); | 
|  | 4926 |  | 
|  | 4927 | // The child should be cropped by the new parent bounds. | 
|  | 4928 | { | 
|  | 4929 | mCapture = screenshot(); | 
|  | 4930 | mCapture->expectChildColor(0, 0); | 
|  | 4931 | mCapture->expectChildColor(99, 63); | 
|  | 4932 | mCapture->expectFGColor(100, 63); | 
|  | 4933 | mCapture->expectBGColor(128, 64); | 
|  | 4934 | } | 
|  | 4935 | } | 
|  | 4936 |  | 
|  | 4937 | // A child with a scale transform from its parents should be cropped by its parent bounds. | 
|  | 4938 | TEST_F(ChildLayerTest, ChildCroppedByParentWithBufferScale) { | 
|  | 4939 | asTransaction([&](Transaction& t) { | 
|  | 4940 | t.show(mChild); | 
|  | 4941 | t.setPosition(mChild, 0, 0); | 
|  | 4942 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4943 | t.setSize(mChild, 200, 200); | 
|  | 4944 | }); | 
|  | 4945 | fillSurfaceRGBA8(mChild, 200, 200, 200); | 
|  | 4946 |  | 
|  | 4947 | { | 
|  | 4948 | mCapture = screenshot(); | 
|  | 4949 |  | 
|  | 4950 | mCapture->expectChildColor(0, 0); | 
|  | 4951 | mCapture->expectChildColor(63, 63); | 
|  | 4952 | mCapture->expectBGColor(64, 64); | 
|  | 4953 | } | 
|  | 4954 |  | 
|  | 4955 | asTransaction([&](Transaction& t) { | 
|  | 4956 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); | 
|  | 4957 | // Set a scaling by 2. | 
|  | 4958 | t.setSize(mFGSurfaceControl, 128, 128); | 
|  | 4959 | }); | 
|  | 4960 |  | 
|  | 4961 | // Child should inherit its parents scale but should be cropped by its parent bounds. | 
|  | 4962 | { | 
|  | 4963 | mCapture = screenshot(); | 
|  | 4964 | mCapture->expectChildColor(0, 0); | 
|  | 4965 | mCapture->expectChildColor(127, 127); | 
|  | 4966 | mCapture->expectBGColor(128, 128); | 
|  | 4967 | } | 
|  | 4968 | } | 
|  | 4969 |  | 
|  | 4970 | // Regression test for b/127368943 | 
|  | 4971 | // Child should ignore the buffer transform but apply parent scale transform. | 
|  | 4972 | TEST_F(ChildLayerTest, ChildrenWithParentBufferTransformAndScale) { | 
|  | 4973 | asTransaction([&](Transaction& t) { | 
|  | 4974 | t.show(mChild); | 
|  | 4975 | t.setPosition(mChild, 0, 0); | 
|  | 4976 | t.setPosition(mFGSurfaceControl, 0, 0); | 
|  | 4977 | }); | 
|  | 4978 |  | 
|  | 4979 | { | 
|  | 4980 | mCapture = screenshot(); | 
|  | 4981 | mCapture->expectChildColor(0, 0); | 
|  | 4982 | mCapture->expectChildColor(9, 14); | 
|  | 4983 | mCapture->expectFGColor(10, 15); | 
|  | 4984 | } | 
|  | 4985 |  | 
|  | 4986 | // Change the size of the foreground to 128 * 64 so we can test rotation as well. | 
|  | 4987 | asTransaction([&](Transaction& t) { | 
|  | 4988 | t.setOverrideScalingMode(mFGSurfaceControl, NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); | 
|  | 4989 | t.setSize(mFGSurfaceControl, 128, 64); | 
|  | 4990 | }); | 
|  | 4991 | sp<Surface> s = mFGSurfaceControl->getSurface(); | 
|  | 4992 | auto anw = static_cast<ANativeWindow*>(s.get()); | 
|  | 4993 | // Apply a 90 transform on the buffer and submit a buffer half the expected size so that we | 
|  | 4994 | // have an effective scale of 2.0 applied to the buffer along with a rotation transform. | 
|  | 4995 | native_window_set_buffers_transform(anw, NATIVE_WINDOW_TRANSFORM_ROT_90); | 
|  | 4996 | native_window_set_buffers_dimensions(anw, 32, 64); | 
|  | 4997 | fillSurfaceRGBA8(mFGSurfaceControl, 195, 63, 63); | 
|  | 4998 | waitForPostedBuffers(); | 
|  | 4999 |  | 
|  | 5000 | // The child should ignore the buffer transform but apply the 2.0 scale from parent. | 
|  | 5001 | { | 
|  | 5002 | mCapture = screenshot(); | 
|  | 5003 | mCapture->expectChildColor(0, 0); | 
|  | 5004 | mCapture->expectChildColor(19, 29); | 
|  | 5005 | mCapture->expectFGColor(20, 30); | 
|  | 5006 | } | 
|  | 5007 | } | 
|  | 5008 |  | 
| Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 5009 | TEST_F(ChildLayerTest, Bug36858924) { | 
|  | 5010 | // Destroy the child layer | 
|  | 5011 | mChild.clear(); | 
|  | 5012 |  | 
|  | 5013 | // Now recreate it as hidden | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5014 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, | 
|  | 5015 | ISurfaceComposerClient::eHidden, mFGSurfaceControl.get()); | 
| Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 5016 |  | 
|  | 5017 | // Show the child layer in a deferred transaction | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 5018 | asTransaction([&](Transaction& t) { | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 5019 | t.deferTransactionUntil_legacy(mChild, mFGSurfaceControl->getHandle(), | 
|  | 5020 | mFGSurfaceControl->getSurface()->getNextFrameNumber()); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 5021 | t.show(mChild); | 
|  | 5022 | }); | 
| Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 5023 |  | 
|  | 5024 | // Render the foreground surface a few times | 
|  | 5025 | // | 
|  | 5026 | // Prior to the bugfix for b/36858924, this would usually hang while trying to fill the third | 
|  | 5027 | // frame because SurfaceFlinger would never process the deferred transaction and would therefore | 
|  | 5028 | // never acquire/release the first buffer | 
|  | 5029 | ALOGI("Filling 1"); | 
|  | 5030 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); | 
|  | 5031 | ALOGI("Filling 2"); | 
|  | 5032 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 0, 255); | 
|  | 5033 | ALOGI("Filling 3"); | 
|  | 5034 | fillSurfaceRGBA8(mFGSurfaceControl, 255, 0, 0); | 
|  | 5035 | ALOGI("Filling 4"); | 
|  | 5036 | fillSurfaceRGBA8(mFGSurfaceControl, 0, 255, 0); | 
|  | 5037 | } | 
|  | 5038 |  | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5039 | TEST_F(ChildLayerTest, Reparent) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 5040 | asTransaction([&](Transaction& t) { | 
|  | 5041 | t.show(mChild); | 
|  | 5042 | t.setPosition(mChild, 10, 10); | 
|  | 5043 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 5044 | }); | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5045 |  | 
|  | 5046 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5047 | mCapture = screenshot(); | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5048 | // Top left of foreground must now be visible | 
|  | 5049 | mCapture->expectFGColor(64, 64); | 
|  | 5050 | // But 10 pixels in we should see the child surface | 
|  | 5051 | mCapture->expectChildColor(74, 74); | 
|  | 5052 | // And 10 more pixels we should be back to the foreground surface | 
|  | 5053 | mCapture->expectFGColor(84, 84); | 
|  | 5054 | } | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 5055 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5056 | asTransaction([&](Transaction& t) { t.reparent(mChild, mBGSurfaceControl->getHandle()); }); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 5057 |  | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5058 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5059 | mCapture = screenshot(); | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 5060 | mCapture->expectFGColor(64, 64); | 
|  | 5061 | // In reparenting we should have exposed the entire foreground surface. | 
|  | 5062 | mCapture->expectFGColor(74, 74); | 
|  | 5063 | // And the child layer should now begin at 10, 10 (since the BG | 
|  | 5064 | // layer is at (0, 0)). | 
|  | 5065 | mCapture->expectBGColor(9, 9); | 
|  | 5066 | mCapture->expectChildColor(10, 10); | 
|  | 5067 | } | 
|  | 5068 | } | 
|  | 5069 |  | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5070 | TEST_F(ChildLayerTest, ReparentToNoParent) { | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 5071 | asTransaction([&](Transaction& t) { | 
|  | 5072 | t.show(mChild); | 
|  | 5073 | t.setPosition(mChild, 10, 10); | 
|  | 5074 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 5075 | }); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5076 |  | 
|  | 5077 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5078 | mCapture = screenshot(); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5079 | // Top left of foreground must now be visible | 
|  | 5080 | mCapture->expectFGColor(64, 64); | 
|  | 5081 | // But 10 pixels in we should see the child surface | 
|  | 5082 | mCapture->expectChildColor(74, 74); | 
|  | 5083 | // And 10 more pixels we should be back to the foreground surface | 
|  | 5084 | mCapture->expectFGColor(84, 84); | 
|  | 5085 | } | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5086 | asTransaction([&](Transaction& t) { t.reparent(mChild, nullptr); }); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5087 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5088 | mCapture = screenshot(); | 
| Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5089 | // The surface should now be offscreen. | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5090 | mCapture->expectFGColor(64, 64); | 
| Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 5091 | mCapture->expectFGColor(74, 74); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5092 | mCapture->expectFGColor(84, 84); | 
|  | 5093 | } | 
|  | 5094 | } | 
|  | 5095 |  | 
|  | 5096 | TEST_F(ChildLayerTest, ReparentFromNoParent) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5097 | sp<SurfaceControl> newSurface = createLayer(String8("New Surface"), 10, 10, 0); | 
| Peiyong Lin | 566a3b4 | 2018-01-09 18:22:43 -0800 | [diff] [blame] | 5098 | ASSERT_TRUE(newSurface != nullptr); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5099 | ASSERT_TRUE(newSurface->isValid()); | 
|  | 5100 |  | 
|  | 5101 | fillSurfaceRGBA8(newSurface, 63, 195, 63); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 5102 | asTransaction([&](Transaction& t) { | 
|  | 5103 | t.hide(mChild); | 
|  | 5104 | t.show(newSurface); | 
|  | 5105 | t.setPosition(newSurface, 10, 10); | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5106 | t.setLayer(newSurface, INT32_MAX - 2); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 5107 | t.setPosition(mFGSurfaceControl, 64, 64); | 
|  | 5108 | }); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5109 |  | 
|  | 5110 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5111 | mCapture = screenshot(); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5112 | // Top left of foreground must now be visible | 
|  | 5113 | mCapture->expectFGColor(64, 64); | 
|  | 5114 | // At 10, 10 we should see the new surface | 
|  | 5115 | mCapture->checkPixel(10, 10, 63, 195, 63); | 
|  | 5116 | } | 
|  | 5117 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5118 | asTransaction([&](Transaction& t) { t.reparent(newSurface, mFGSurfaceControl->getHandle()); }); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5119 |  | 
|  | 5120 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5121 | mCapture = screenshot(); | 
| chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 5122 | // newSurface will now be a child of mFGSurface so it will be 10, 10 offset from | 
|  | 5123 | // mFGSurface, putting it at 74, 74. | 
|  | 5124 | mCapture->expectFGColor(64, 64); | 
|  | 5125 | mCapture->checkPixel(74, 74, 63, 195, 63); | 
|  | 5126 | mCapture->expectFGColor(84, 84); | 
|  | 5127 | } | 
|  | 5128 | } | 
|  | 5129 |  | 
| chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 5130 | TEST_F(ChildLayerTest, NestedChildren) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5131 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 10, 10, | 
|  | 5132 | PIXEL_FORMAT_RGBA_8888, 0, mChild.get()); | 
| chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 5133 | fillSurfaceRGBA8(grandchild, 50, 50, 50); | 
|  | 5134 |  | 
|  | 5135 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5136 | mCapture = screenshot(); | 
| chaviw | c967433 | 2017-08-28 12:32:18 -0700 | [diff] [blame] | 5137 | // Expect the grandchild to begin at 64, 64 because it's a child of mChild layer | 
|  | 5138 | // which begins at 64, 64 | 
|  | 5139 | mCapture->checkPixel(64, 64, 50, 50, 50); | 
|  | 5140 | } | 
|  | 5141 | } | 
|  | 5142 |  | 
| Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5143 | TEST_F(ChildLayerTest, ChildLayerRelativeLayer) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5144 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 128, 128, 0); | 
| Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5145 | fillSurfaceRGBA8(relative, 255, 255, 255); | 
|  | 5146 |  | 
|  | 5147 | Transaction t; | 
|  | 5148 | t.setLayer(relative, INT32_MAX) | 
|  | 5149 | .setRelativeLayer(mChild, relative->getHandle(), 1) | 
|  | 5150 | .setPosition(mFGSurfaceControl, 0, 0) | 
|  | 5151 | .apply(true); | 
|  | 5152 |  | 
|  | 5153 | // We expect that the child should have been elevated above our | 
|  | 5154 | // INT_MAX layer even though it's not a child of it. | 
|  | 5155 | { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5156 | mCapture = screenshot(); | 
| Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5157 | mCapture->expectChildColor(0, 0); | 
|  | 5158 | mCapture->expectChildColor(9, 9); | 
|  | 5159 | mCapture->checkPixel(10, 10, 255, 255, 255); | 
|  | 5160 | } | 
|  | 5161 | } | 
| Vishnu Nair | c652ff8 | 2019-03-15 12:48:54 -0700 | [diff] [blame] | 5162 |  | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5163 | class BoundlessLayerTest : public LayerUpdateTest { | 
|  | 5164 | protected: | 
|  | 5165 | std::unique_ptr<ScreenCapture> mCapture; | 
|  | 5166 | }; | 
|  | 5167 |  | 
|  | 5168 | // Verify setting a size on a buffer layer has no effect. | 
|  | 5169 | TEST_F(BoundlessLayerTest, BufferLayerIgnoresSize) { | 
|  | 5170 | sp<SurfaceControl> bufferLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5171 | createSurface(mClient, "BufferLayer", 45, 45, PIXEL_FORMAT_RGBA_8888, 0, | 
|  | 5172 | mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5173 | ASSERT_TRUE(bufferLayer->isValid()); | 
|  | 5174 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(bufferLayer, Color::BLACK, 30, 30)); | 
|  | 5175 | asTransaction([&](Transaction& t) { t.show(bufferLayer); }); | 
|  | 5176 | { | 
|  | 5177 | mCapture = screenshot(); | 
|  | 5178 | // Top left of background must now be visible | 
|  | 5179 | mCapture->expectBGColor(0, 0); | 
|  | 5180 | // Foreground Surface bounds must be color layer | 
|  | 5181 | mCapture->expectColor(Rect(64, 64, 94, 94), Color::BLACK); | 
|  | 5182 | // Buffer layer should not extend past buffer bounds | 
|  | 5183 | mCapture->expectFGColor(95, 95); | 
|  | 5184 | } | 
|  | 5185 | } | 
|  | 5186 |  | 
|  | 5187 | // Verify a boundless color layer will fill its parent bounds. The parent has a buffer size | 
|  | 5188 | // which will crop the color layer. | 
|  | 5189 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentBufferBounds) { | 
|  | 5190 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5191 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5192 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5193 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 5194 | asTransaction([&](Transaction& t) { | 
|  | 5195 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 5196 | t.show(colorLayer); | 
|  | 5197 | }); | 
|  | 5198 | { | 
|  | 5199 | mCapture = screenshot(); | 
|  | 5200 | // Top left of background must now be visible | 
|  | 5201 | mCapture->expectBGColor(0, 0); | 
|  | 5202 | // Foreground Surface bounds must be color layer | 
|  | 5203 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); | 
|  | 5204 | // Color layer should not extend past foreground bounds | 
|  | 5205 | mCapture->expectBGColor(129, 129); | 
|  | 5206 | } | 
|  | 5207 | } | 
|  | 5208 |  | 
|  | 5209 | // Verify a boundless color layer will fill its parent bounds. The parent has no buffer but has | 
|  | 5210 | // a crop which will be used to crop the color layer. | 
|  | 5211 | TEST_F(BoundlessLayerTest, BoundlessColorLayerFillsParentCropBounds) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5212 | sp<SurfaceControl> cropLayer = createSurface(mClient, "CropLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5213 | 0 /* flags */, mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5214 | ASSERT_TRUE(cropLayer->isValid()); | 
|  | 5215 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5216 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5217 | ISurfaceComposerClient::eFXSurfaceColor, cropLayer.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5218 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 5219 | asTransaction([&](Transaction& t) { | 
|  | 5220 | t.setCrop_legacy(cropLayer, Rect(5, 5, 10, 10)); | 
|  | 5221 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 5222 | t.show(cropLayer); | 
|  | 5223 | t.show(colorLayer); | 
|  | 5224 | }); | 
|  | 5225 | { | 
|  | 5226 | mCapture = screenshot(); | 
|  | 5227 | // Top left of background must now be visible | 
|  | 5228 | mCapture->expectBGColor(0, 0); | 
|  | 5229 | // Top left of foreground must now be visible | 
|  | 5230 | mCapture->expectFGColor(64, 64); | 
|  | 5231 | // 5 pixels from the foreground we should see the child surface | 
|  | 5232 | mCapture->expectColor(Rect(69, 69, 74, 74), Color::BLACK); | 
|  | 5233 | // 10 pixels from the foreground we should be back to the foreground surface | 
|  | 5234 | mCapture->expectFGColor(74, 74); | 
|  | 5235 | } | 
|  | 5236 | } | 
|  | 5237 |  | 
|  | 5238 | // Verify for boundless layer with no children, their transforms have no effect. | 
|  | 5239 | TEST_F(BoundlessLayerTest, BoundlessColorLayerTransformHasNoEffect) { | 
|  | 5240 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5241 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5242 | ISurfaceComposerClient::eFXSurfaceColor, mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5243 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 5244 | asTransaction([&](Transaction& t) { | 
|  | 5245 | t.setPosition(colorLayer, 320, 320); | 
|  | 5246 | t.setMatrix(colorLayer, 2, 0, 0, 2); | 
|  | 5247 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 5248 | t.show(colorLayer); | 
|  | 5249 | }); | 
|  | 5250 | { | 
|  | 5251 | mCapture = screenshot(); | 
|  | 5252 | // Top left of background must now be visible | 
|  | 5253 | mCapture->expectBGColor(0, 0); | 
|  | 5254 | // Foreground Surface bounds must be color layer | 
|  | 5255 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); | 
|  | 5256 | // Color layer should not extend past foreground bounds | 
|  | 5257 | mCapture->expectBGColor(129, 129); | 
|  | 5258 | } | 
|  | 5259 | } | 
|  | 5260 |  | 
|  | 5261 | // Verify for boundless layer with children, their transforms have an effect. | 
|  | 5262 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerCanSetTransform) { | 
|  | 5263 | sp<SurfaceControl> boundlessLayerRightShift = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5264 | createSurface(mClient, "BoundlessLayerRightShift", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5265 | 0 /* flags */, mFGSurfaceControl.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5266 | ASSERT_TRUE(boundlessLayerRightShift->isValid()); | 
|  | 5267 | sp<SurfaceControl> boundlessLayerDownShift = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5268 | createSurface(mClient, "BoundlessLayerLeftShift", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5269 | 0 /* flags */, boundlessLayerRightShift.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5270 | ASSERT_TRUE(boundlessLayerDownShift->isValid()); | 
|  | 5271 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5272 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5273 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayerDownShift.get()); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5274 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 5275 | asTransaction([&](Transaction& t) { | 
|  | 5276 | t.setPosition(boundlessLayerRightShift, 32, 0); | 
|  | 5277 | t.show(boundlessLayerRightShift); | 
|  | 5278 | t.setPosition(boundlessLayerDownShift, 0, 32); | 
|  | 5279 | t.show(boundlessLayerDownShift); | 
|  | 5280 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); | 
|  | 5281 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 5282 | t.show(colorLayer); | 
|  | 5283 | }); | 
|  | 5284 | { | 
|  | 5285 | mCapture = screenshot(); | 
|  | 5286 | // Top left of background must now be visible | 
|  | 5287 | mCapture->expectBGColor(0, 0); | 
|  | 5288 | // Top left of foreground must now be visible | 
|  | 5289 | mCapture->expectFGColor(64, 64); | 
|  | 5290 | // Foreground Surface bounds must be color layer | 
|  | 5291 | mCapture->expectColor(Rect(96, 96, 128, 128), Color::BLACK); | 
|  | 5292 | // Color layer should not extend past foreground bounds | 
|  | 5293 | mCapture->expectBGColor(129, 129); | 
|  | 5294 | } | 
|  | 5295 | } | 
|  | 5296 |  | 
|  | 5297 | // Verify child layers do not get clipped if they temporarily move into the negative | 
|  | 5298 | // coordinate space as the result of an intermediate transformation. | 
|  | 5299 | TEST_F(BoundlessLayerTest, IntermediateBoundlessLayerDoNotCrop) { | 
|  | 5300 | sp<SurfaceControl> boundlessLayer = | 
|  | 5301 | mClient->createSurface(String8("BoundlessLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5302 | 0 /* flags */, mFGSurfaceControl.get()); | 
|  | 5303 | ASSERT_TRUE(boundlessLayer != nullptr); | 
|  | 5304 | ASSERT_TRUE(boundlessLayer->isValid()); | 
|  | 5305 | sp<SurfaceControl> colorLayer = | 
|  | 5306 | mClient->createSurface(String8("ColorLayer"), 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5307 | ISurfaceComposerClient::eFXSurfaceColor, boundlessLayer.get()); | 
|  | 5308 | ASSERT_TRUE(colorLayer != nullptr); | 
|  | 5309 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 5310 | asTransaction([&](Transaction& t) { | 
|  | 5311 | // shift child layer off bounds. If this layer was not boundless, we will | 
|  | 5312 | // expect the child layer to be cropped. | 
|  | 5313 | t.setPosition(boundlessLayer, 32, 32); | 
|  | 5314 | t.show(boundlessLayer); | 
|  | 5315 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); | 
|  | 5316 | // undo shift by parent | 
|  | 5317 | t.setPosition(colorLayer, -32, -32); | 
|  | 5318 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 5319 | t.show(colorLayer); | 
|  | 5320 | }); | 
|  | 5321 | { | 
|  | 5322 | mCapture = screenshot(); | 
|  | 5323 | // Top left of background must now be visible | 
|  | 5324 | mCapture->expectBGColor(0, 0); | 
|  | 5325 | // Foreground Surface bounds must be color layer | 
|  | 5326 | mCapture->expectColor(Rect(64, 64, 128, 128), Color::BLACK); | 
|  | 5327 | // Color layer should not extend past foreground bounds | 
|  | 5328 | mCapture->expectBGColor(129, 129); | 
|  | 5329 | } | 
|  | 5330 | } | 
|  | 5331 |  | 
|  | 5332 | // Verify for boundless root layers with children, their transforms have an effect. | 
|  | 5333 | TEST_F(BoundlessLayerTest, RootBoundlessLayerCanSetTransform) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5334 | sp<SurfaceControl> rootBoundlessLayer = createSurface(mClient, "RootBoundlessLayer", 0, 0, | 
|  | 5335 | PIXEL_FORMAT_RGBA_8888, 0 /* flags */); | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5336 | ASSERT_TRUE(rootBoundlessLayer->isValid()); | 
|  | 5337 | sp<SurfaceControl> colorLayer = | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5338 | createSurface(mClient, "ColorLayer", 0, 0, PIXEL_FORMAT_RGBA_8888, | 
|  | 5339 | ISurfaceComposerClient::eFXSurfaceColor, rootBoundlessLayer.get()); | 
|  | 5340 |  | 
| Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 5341 | ASSERT_TRUE(colorLayer->isValid()); | 
|  | 5342 | asTransaction([&](Transaction& t) { | 
|  | 5343 | t.setLayer(rootBoundlessLayer, INT32_MAX - 1); | 
|  | 5344 | t.setPosition(rootBoundlessLayer, 32, 32); | 
|  | 5345 | t.show(rootBoundlessLayer); | 
|  | 5346 | t.setCrop_legacy(colorLayer, Rect(0, 0, 64, 64)); | 
|  | 5347 | t.setColor(colorLayer, half3{0, 0, 0}); | 
|  | 5348 | t.show(colorLayer); | 
|  | 5349 | t.hide(mFGSurfaceControl); | 
|  | 5350 | }); | 
|  | 5351 | { | 
|  | 5352 | mCapture = screenshot(); | 
|  | 5353 | // Top left of background must now be visible | 
|  | 5354 | mCapture->expectBGColor(0, 0); | 
|  | 5355 | // Top left of foreground must now be visible | 
|  | 5356 | mCapture->expectBGColor(31, 31); | 
|  | 5357 | // Foreground Surface bounds must be color layer | 
|  | 5358 | mCapture->expectColor(Rect(32, 32, 96, 96), Color::BLACK); | 
|  | 5359 | // Color layer should not extend past foreground bounds | 
|  | 5360 | mCapture->expectBGColor(97, 97); | 
|  | 5361 | } | 
|  | 5362 | } | 
| Robert Carr | 503c704 | 2017-09-27 15:06:08 -0700 | [diff] [blame] | 5363 |  | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5364 | class ScreenCaptureTest : public LayerUpdateTest { | 
|  | 5365 | protected: | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5366 | std::unique_ptr<ScreenCapture> mCapture; | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5367 | }; | 
|  | 5368 |  | 
|  | 5369 | TEST_F(ScreenCaptureTest, CaptureSingleLayer) { | 
|  | 5370 | auto bgHandle = mBGSurfaceControl->getHandle(); | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5371 | ScreenCapture::captureLayers(&mCapture, bgHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5372 | mCapture->expectBGColor(0, 0); | 
|  | 5373 | // Doesn't capture FG layer which is at 64, 64 | 
|  | 5374 | mCapture->expectBGColor(64, 64); | 
|  | 5375 | } | 
|  | 5376 |  | 
|  | 5377 | TEST_F(ScreenCaptureTest, CaptureLayerWithChild) { | 
|  | 5378 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5379 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5380 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5381 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5382 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5383 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5384 | SurfaceComposerClient::Transaction().show(child).apply(true); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5385 |  | 
|  | 5386 | // Captures mFGSurfaceControl layer and its child. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5387 | ScreenCapture::captureLayers(&mCapture, fgHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5388 | mCapture->expectFGColor(10, 10); | 
|  | 5389 | mCapture->expectChildColor(0, 0); | 
|  | 5390 | } | 
|  | 5391 |  | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5392 | TEST_F(ScreenCaptureTest, CaptureLayerChildOnly) { | 
|  | 5393 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5394 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5395 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5396 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5397 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5398 |  | 
|  | 5399 | SurfaceComposerClient::Transaction().show(child).apply(true); | 
|  | 5400 |  | 
|  | 5401 | // Captures mFGSurfaceControl's child | 
|  | 5402 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); | 
|  | 5403 | mCapture->checkPixel(10, 10, 0, 0, 0); | 
|  | 5404 | mCapture->expectChildColor(0, 0); | 
|  | 5405 | } | 
|  | 5406 |  | 
| Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 5407 | TEST_F(ScreenCaptureTest, CaptureLayerExclude) { | 
|  | 5408 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5409 |  | 
|  | 5410 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5411 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 5412 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5413 | sp<SurfaceControl> child2 = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5414 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 5415 | fillSurfaceRGBA8(child2, 200, 0, 200); | 
|  | 5416 |  | 
|  | 5417 | SurfaceComposerClient::Transaction() | 
|  | 5418 | .show(child) | 
|  | 5419 | .show(child2) | 
|  | 5420 | .setLayer(child, 1) | 
|  | 5421 | .setLayer(child2, 2) | 
|  | 5422 | .apply(true); | 
|  | 5423 |  | 
|  | 5424 | // Child2 would be visible but its excluded, so we should see child1 color instead. | 
|  | 5425 | ScreenCapture::captureChildLayersExcluding(&mCapture, fgHandle, {child2->getHandle()}); | 
|  | 5426 | mCapture->checkPixel(10, 10, 0, 0, 0); | 
|  | 5427 | mCapture->checkPixel(0, 0, 200, 200, 200); | 
|  | 5428 | } | 
|  | 5429 |  | 
|  | 5430 | // Like the last test but verifies that children are also exclude. | 
|  | 5431 | TEST_F(ScreenCaptureTest, CaptureLayerExcludeTree) { | 
|  | 5432 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5433 |  | 
|  | 5434 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5435 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 5436 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5437 | sp<SurfaceControl> child2 = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5438 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 5439 | fillSurfaceRGBA8(child2, 200, 0, 200); | 
|  | 5440 | sp<SurfaceControl> child3 = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5441 | PIXEL_FORMAT_RGBA_8888, 0, child2.get()); | 
|  | 5442 | fillSurfaceRGBA8(child2, 200, 0, 200); | 
|  | 5443 |  | 
|  | 5444 | SurfaceComposerClient::Transaction() | 
|  | 5445 | .show(child) | 
|  | 5446 | .show(child2) | 
|  | 5447 | .show(child3) | 
|  | 5448 | .setLayer(child, 1) | 
|  | 5449 | .setLayer(child2, 2) | 
|  | 5450 | .apply(true); | 
|  | 5451 |  | 
|  | 5452 | // Child2 would be visible but its excluded, so we should see child1 color instead. | 
|  | 5453 | ScreenCapture::captureChildLayersExcluding(&mCapture, fgHandle, {child2->getHandle()}); | 
|  | 5454 | mCapture->checkPixel(10, 10, 0, 0, 0); | 
|  | 5455 | mCapture->checkPixel(0, 0, 200, 200, 200); | 
|  | 5456 | } | 
|  | 5457 |  | 
| chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 5458 | TEST_F(ScreenCaptureTest, CaptureTransparent) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5459 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5460 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 5461 |  | 
|  | 5462 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5463 |  | 
|  | 5464 | SurfaceComposerClient::Transaction().show(child).apply(true); | 
|  | 5465 |  | 
|  | 5466 | auto childHandle = child->getHandle(); | 
|  | 5467 |  | 
|  | 5468 | // Captures child | 
|  | 5469 | ScreenCapture::captureLayers(&mCapture, childHandle, {0, 0, 10, 20}); | 
|  | 5470 | mCapture->expectColor(Rect(0, 0, 9, 9), {200, 200, 200, 255}); | 
|  | 5471 | // Area outside of child's bounds is transparent. | 
|  | 5472 | mCapture->expectColor(Rect(0, 10, 9, 19), {0, 0, 0, 0}); | 
|  | 5473 | } | 
|  | 5474 |  | 
| chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 5475 | TEST_F(ScreenCaptureTest, DontCaptureRelativeOutsideTree) { | 
|  | 5476 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5477 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5478 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5479 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 5480 | ASSERT_NE(nullptr, child.get()) << "failed to create surface"; | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5481 | sp<SurfaceControl> relative = createLayer(String8("Relative surface"), 10, 10, 0); | 
| chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 5482 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5483 | fillSurfaceRGBA8(relative, 100, 100, 100); | 
|  | 5484 |  | 
|  | 5485 | SurfaceComposerClient::Transaction() | 
|  | 5486 | .show(child) | 
|  | 5487 | // Set relative layer above fg layer so should be shown above when computing all layers. | 
|  | 5488 | .setRelativeLayer(relative, fgHandle, 1) | 
|  | 5489 | .show(relative) | 
|  | 5490 | .apply(true); | 
|  | 5491 |  | 
|  | 5492 | // Captures mFGSurfaceControl layer and its child. Relative layer shouldn't be captured. | 
|  | 5493 | ScreenCapture::captureLayers(&mCapture, fgHandle); | 
|  | 5494 | mCapture->expectFGColor(10, 10); | 
|  | 5495 | mCapture->expectChildColor(0, 0); | 
|  | 5496 | } | 
|  | 5497 |  | 
|  | 5498 | TEST_F(ScreenCaptureTest, CaptureRelativeInTree) { | 
|  | 5499 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5500 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5501 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5502 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
|  | 5503 | sp<SurfaceControl> relative = createSurface(mClient, "Relative surface", 10, 10, | 
|  | 5504 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | 4b129c2 | 2018-04-09 16:19:43 -0700 | [diff] [blame] | 5505 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5506 | fillSurfaceRGBA8(relative, 100, 100, 100); | 
|  | 5507 |  | 
|  | 5508 | SurfaceComposerClient::Transaction() | 
|  | 5509 | .show(child) | 
|  | 5510 | // Set relative layer below fg layer but relative to child layer so it should be shown | 
|  | 5511 | // above child layer. | 
|  | 5512 | .setLayer(relative, -1) | 
|  | 5513 | .setRelativeLayer(relative, child->getHandle(), 1) | 
|  | 5514 | .show(relative) | 
|  | 5515 | .apply(true); | 
|  | 5516 |  | 
|  | 5517 | // Captures mFGSurfaceControl layer and its children. Relative layer is a child of fg so its | 
|  | 5518 | // relative value should be taken into account, placing it above child layer. | 
|  | 5519 | ScreenCapture::captureLayers(&mCapture, fgHandle); | 
|  | 5520 | mCapture->expectFGColor(10, 10); | 
|  | 5521 | // Relative layer is showing on top of child layer | 
|  | 5522 | mCapture->expectColor(Rect(0, 0, 9, 9), {100, 100, 100, 255}); | 
|  | 5523 | } | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5524 |  | 
|  | 5525 | // In the following tests we verify successful skipping of a parent layer, | 
|  | 5526 | // so we use the same verification logic and only change how we mutate | 
|  | 5527 | // the parent layer to verify that various properties are ignored. | 
|  | 5528 | class ScreenCaptureChildOnlyTest : public LayerUpdateTest { | 
|  | 5529 | public: | 
|  | 5530 | void SetUp() override { | 
|  | 5531 | LayerUpdateTest::SetUp(); | 
|  | 5532 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5533 | mChild = createSurface(mClient, "Child surface", 10, 10, PIXEL_FORMAT_RGBA_8888, 0, | 
|  | 5534 | mFGSurfaceControl.get()); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5535 | fillSurfaceRGBA8(mChild, 200, 200, 200); | 
|  | 5536 |  | 
|  | 5537 | SurfaceComposerClient::Transaction().show(mChild).apply(true); | 
|  | 5538 | } | 
|  | 5539 |  | 
| Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5540 | void verify(std::function<void()> verifyStartingState) { | 
|  | 5541 | // Verify starting state before a screenshot is taken. | 
|  | 5542 | verifyStartingState(); | 
|  | 5543 |  | 
|  | 5544 | // Verify child layer does not inherit any of the properties of its | 
|  | 5545 | // parent when its screenshot is captured. | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5546 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5547 | ScreenCapture::captureChildLayers(&mCapture, fgHandle); | 
|  | 5548 | mCapture->checkPixel(10, 10, 0, 0, 0); | 
|  | 5549 | mCapture->expectChildColor(0, 0); | 
| Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5550 |  | 
|  | 5551 | // Verify all assumptions are still true after the screenshot is taken. | 
|  | 5552 | verifyStartingState(); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5553 | } | 
|  | 5554 |  | 
|  | 5555 | std::unique_ptr<ScreenCapture> mCapture; | 
|  | 5556 | sp<SurfaceControl> mChild; | 
|  | 5557 | }; | 
|  | 5558 |  | 
| Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5559 | // Regression test b/76099859 | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5560 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentVisibility) { | 
|  | 5561 |  | 
|  | 5562 | SurfaceComposerClient::Transaction().hide(mFGSurfaceControl).apply(true); | 
|  | 5563 |  | 
|  | 5564 | // Even though the parent is hidden we should still capture the child. | 
| Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5565 |  | 
|  | 5566 | // Before and after reparenting, verify child is properly hidden | 
|  | 5567 | // when rendering full-screen. | 
|  | 5568 | verify([&] { screenshot()->expectBGColor(64, 64); }); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5569 | } | 
|  | 5570 |  | 
|  | 5571 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresParentCrop) { | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 5572 | SurfaceComposerClient::Transaction() | 
|  | 5573 | .setCrop_legacy(mFGSurfaceControl, Rect(0, 0, 1, 1)) | 
|  | 5574 | .apply(true); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5575 |  | 
|  | 5576 | // Even though the parent is cropped out we should still capture the child. | 
| Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5577 |  | 
|  | 5578 | // Before and after reparenting, verify child is cropped by parent. | 
|  | 5579 | verify([&] { screenshot()->expectBGColor(65, 65); }); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5580 | } | 
|  | 5581 |  | 
| Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5582 | // Regression test b/124372894 | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5583 | TEST_F(ScreenCaptureChildOnlyTest, CaptureLayerIgnoresTransform) { | 
| Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5584 | SurfaceComposerClient::Transaction().setMatrix(mFGSurfaceControl, 2, 0, 0, 2).apply(true); | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5585 |  | 
|  | 5586 | // We should not inherit the parent scaling. | 
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5587 |  | 
| Vishnu Nair | 333a957 | 2019-02-15 16:05:56 -0800 | [diff] [blame] | 5588 | // Before and after reparenting, verify child is properly scaled. | 
|  | 5589 | verify([&] { screenshot()->expectChildColor(80, 80); }); | 
| Robert Carr | 15eae09 | 2018-03-23 13:43:53 -0700 | [diff] [blame] | 5590 | } | 
|  | 5591 |  | 
|  | 5592 |  | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5593 | TEST_F(ScreenCaptureTest, CaptureLayerWithGrandchild) { | 
|  | 5594 | auto fgHandle = mFGSurfaceControl->getHandle(); | 
|  | 5595 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5596 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5597 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5598 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5599 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5600 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, | 
|  | 5601 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5602 |  | 
|  | 5603 | fillSurfaceRGBA8(grandchild, 50, 50, 50); | 
|  | 5604 | SurfaceComposerClient::Transaction() | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5605 | .show(child) | 
|  | 5606 | .setPosition(grandchild, 5, 5) | 
|  | 5607 | .show(grandchild) | 
|  | 5608 | .apply(true); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5609 |  | 
|  | 5610 | // Captures mFGSurfaceControl, its child, and the grandchild. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5611 | ScreenCapture::captureLayers(&mCapture, fgHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5612 | mCapture->expectFGColor(10, 10); | 
|  | 5613 | mCapture->expectChildColor(0, 0); | 
|  | 5614 | mCapture->checkPixel(5, 5, 50, 50, 50); | 
|  | 5615 | } | 
|  | 5616 |  | 
|  | 5617 | TEST_F(ScreenCaptureTest, CaptureChildOnly) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5618 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5619 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5620 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5621 | auto childHandle = child->getHandle(); | 
|  | 5622 |  | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5623 | SurfaceComposerClient::Transaction().setPosition(child, 5, 5).show(child).apply(true); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5624 |  | 
|  | 5625 | // Captures only the child layer, and not the parent. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5626 | ScreenCapture::captureLayers(&mCapture, childHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5627 | mCapture->expectChildColor(0, 0); | 
|  | 5628 | mCapture->expectChildColor(9, 9); | 
|  | 5629 | } | 
|  | 5630 |  | 
|  | 5631 | TEST_F(ScreenCaptureTest, CaptureGrandchildOnly) { | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5632 | sp<SurfaceControl> child = createSurface(mClient, "Child surface", 10, 10, | 
|  | 5633 | PIXEL_FORMAT_RGBA_8888, 0, mFGSurfaceControl.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5634 | fillSurfaceRGBA8(child, 200, 200, 200); | 
|  | 5635 | auto childHandle = child->getHandle(); | 
|  | 5636 |  | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5637 | sp<SurfaceControl> grandchild = createSurface(mClient, "Grandchild surface", 5, 5, | 
|  | 5638 | PIXEL_FORMAT_RGBA_8888, 0, child.get()); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5639 | fillSurfaceRGBA8(grandchild, 50, 50, 50); | 
|  | 5640 |  | 
|  | 5641 | SurfaceComposerClient::Transaction() | 
| Chia-I Wu | 1078bbb | 2017-10-20 11:29:02 -0700 | [diff] [blame] | 5642 | .show(child) | 
|  | 5643 | .setPosition(grandchild, 5, 5) | 
|  | 5644 | .show(grandchild) | 
|  | 5645 | .apply(true); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5646 |  | 
|  | 5647 | auto grandchildHandle = grandchild->getHandle(); | 
|  | 5648 |  | 
|  | 5649 | // Captures only the grandchild. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5650 | ScreenCapture::captureLayers(&mCapture, grandchildHandle); | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5651 | mCapture->checkPixel(0, 0, 50, 50, 50); | 
|  | 5652 | mCapture->checkPixel(4, 4, 50, 50, 50); | 
|  | 5653 | } | 
|  | 5654 |  | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5655 | TEST_F(ScreenCaptureTest, CaptureCrop) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5656 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5657 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, | 
|  | 5658 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5659 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5660 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); | 
|  | 5661 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5662 |  | 
|  | 5663 | SurfaceComposerClient::Transaction() | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5664 | .setLayer(redLayer, INT32_MAX - 1) | 
|  | 5665 | .show(redLayer) | 
|  | 5666 | .show(blueLayer) | 
|  | 5667 | .apply(true); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5668 |  | 
|  | 5669 | auto redLayerHandle = redLayer->getHandle(); | 
|  | 5670 |  | 
|  | 5671 | // Capturing full screen should have both red and blue are visible. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5672 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); | 
|  | 5673 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); | 
|  | 5674 | // red area below the blue area | 
|  | 5675 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); | 
|  | 5676 | // red area to the right of the blue area | 
|  | 5677 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5678 |  | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 5679 | const Rect crop = Rect(0, 0, 30, 30); | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5680 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, crop); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5681 | // Capturing the cropped screen, cropping out the shown red area, should leave only the blue | 
|  | 5682 | // area visible. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5683 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5684 | mCapture->checkPixel(30, 30, 0, 0, 0); | 
|  | 5685 | } | 
|  | 5686 |  | 
|  | 5687 | TEST_F(ScreenCaptureTest, CaptureSize) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5688 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); | 
| Vishnu Nair | 88a11f2 | 2018-11-28 18:30:57 -0800 | [diff] [blame] | 5689 | sp<SurfaceControl> blueLayer = createSurface(mClient, "Blue surface", 30, 30, | 
|  | 5690 | PIXEL_FORMAT_RGBA_8888, 0, redLayer.get()); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5691 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5692 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); | 
|  | 5693 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(blueLayer, Color::BLUE, 30, 30)); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5694 |  | 
|  | 5695 | SurfaceComposerClient::Transaction() | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5696 | .setLayer(redLayer, INT32_MAX - 1) | 
|  | 5697 | .show(redLayer) | 
|  | 5698 | .show(blueLayer) | 
|  | 5699 | .apply(true); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5700 |  | 
|  | 5701 | auto redLayerHandle = redLayer->getHandle(); | 
|  | 5702 |  | 
|  | 5703 | // Capturing full screen should have both red and blue are visible. | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5704 | ScreenCapture::captureLayers(&mCapture, redLayerHandle); | 
|  | 5705 | mCapture->expectColor(Rect(0, 0, 29, 29), Color::BLUE); | 
|  | 5706 | // red area below the blue area | 
|  | 5707 | mCapture->expectColor(Rect(0, 30, 59, 59), Color::RED); | 
|  | 5708 | // red area to the right of the blue area | 
|  | 5709 | mCapture->expectColor(Rect(30, 0, 59, 59), Color::RED); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5710 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5711 | ScreenCapture::captureLayers(&mCapture, redLayerHandle, Rect::EMPTY_RECT, 0.5); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5712 | // 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] | 5713 | mCapture->expectColor(Rect(0, 0, 14, 14), Color::BLUE); | 
|  | 5714 | // red area below the blue area | 
|  | 5715 | mCapture->expectColor(Rect(0, 15, 29, 29), Color::RED); | 
|  | 5716 | // red area to the right of the blue area | 
|  | 5717 | mCapture->expectColor(Rect(15, 0, 29, 29), Color::RED); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5718 | mCapture->checkPixel(30, 30, 0, 0, 0); | 
|  | 5719 | } | 
|  | 5720 |  | 
|  | 5721 | TEST_F(ScreenCaptureTest, CaptureInvalidLayer) { | 
| chaviw | 0e3479f | 2018-09-10 16:49:30 -0700 | [diff] [blame] | 5722 | sp<SurfaceControl> redLayer = createLayer(String8("Red surface"), 60, 60, 0); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5723 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5724 | ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(redLayer, Color::RED, 60, 60)); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5725 |  | 
|  | 5726 | auto redLayerHandle = redLayer->getHandle(); | 
| Robert Carr | 8724653 | 2019-02-04 15:20:26 -0800 | [diff] [blame] | 5727 | redLayer.clear(); | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5728 | SurfaceComposerClient::Transaction().apply(true); | 
|  | 5729 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5730 | sp<GraphicBuffer> outBuffer; | 
| chaviw | 7206d49 | 2017-11-10 16:16:12 -0800 | [diff] [blame] | 5731 |  | 
|  | 5732 | // Layer was deleted so captureLayers should fail with NAME_NOT_FOUND | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 5733 | sp<ISurfaceComposer> sf(ComposerService::getComposerService()); | 
|  | 5734 | 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] | 5735 | } | 
|  | 5736 |  | 
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5737 |  | 
|  | 5738 | class DereferenceSurfaceControlTest : public LayerTransactionTest { | 
|  | 5739 | protected: | 
|  | 5740 | void SetUp() override { | 
|  | 5741 | LayerTransactionTest::SetUp(); | 
|  | 5742 | bgLayer = createLayer("BG layer", 20, 20); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5743 | fillBufferQueueLayerColor(bgLayer, Color::RED, 20, 20); | 
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5744 | fgLayer = createLayer("FG layer", 20, 20); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 5745 | fillBufferQueueLayerColor(fgLayer, Color::BLUE, 20, 20); | 
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 5746 | Transaction().setLayer(fgLayer, mLayerZBase + 1).apply(); | 
|  | 5747 | { | 
|  | 5748 | SCOPED_TRACE("before anything"); | 
|  | 5749 | auto shot = screenshot(); | 
|  | 5750 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); | 
|  | 5751 | } | 
|  | 5752 | } | 
|  | 5753 | void TearDown() override { | 
|  | 5754 | LayerTransactionTest::TearDown(); | 
|  | 5755 | bgLayer = 0; | 
|  | 5756 | fgLayer = 0; | 
|  | 5757 | } | 
|  | 5758 |  | 
|  | 5759 | sp<SurfaceControl> bgLayer; | 
|  | 5760 | sp<SurfaceControl> fgLayer; | 
|  | 5761 | }; | 
|  | 5762 |  | 
|  | 5763 | TEST_F(DereferenceSurfaceControlTest, LayerNotInTransaction) { | 
|  | 5764 | fgLayer = nullptr; | 
|  | 5765 | { | 
|  | 5766 | SCOPED_TRACE("after setting null"); | 
|  | 5767 | auto shot = screenshot(); | 
|  | 5768 | shot->expectColor(Rect(0, 0, 20, 20), Color::RED); | 
|  | 5769 | } | 
|  | 5770 | } | 
|  | 5771 |  | 
|  | 5772 | TEST_F(DereferenceSurfaceControlTest, LayerInTransaction) { | 
|  | 5773 | auto transaction = Transaction().show(fgLayer); | 
|  | 5774 | fgLayer = nullptr; | 
|  | 5775 | { | 
|  | 5776 | SCOPED_TRACE("after setting null"); | 
|  | 5777 | auto shot = screenshot(); | 
|  | 5778 | shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE); | 
|  | 5779 | } | 
|  | 5780 | } | 
|  | 5781 |  | 
| Vishnu Nair | b927e1f | 2019-02-19 13:36:15 -0800 | [diff] [blame] | 5782 | class MultiDisplayLayerBoundsTest : public LayerTransactionTest { | 
|  | 5783 | protected: | 
|  | 5784 | virtual void SetUp() { | 
|  | 5785 | LayerTransactionTest::SetUp(); | 
|  | 5786 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); | 
|  | 5787 |  | 
|  | 5788 | mMainDisplay = SurfaceComposerClient::getInternalDisplayToken(); | 
|  | 5789 | SurfaceComposerClient::getDisplayInfo(mMainDisplay, &mMainDisplayInfo); | 
|  | 5790 |  | 
|  | 5791 | sp<IGraphicBufferConsumer> consumer; | 
|  | 5792 | BufferQueue::createBufferQueue(&mProducer, &consumer); | 
|  | 5793 | consumer->setConsumerName(String8("Virtual disp consumer")); | 
|  | 5794 | consumer->setDefaultBufferSize(mMainDisplayInfo.w, mMainDisplayInfo.h); | 
|  | 5795 | } | 
|  | 5796 |  | 
|  | 5797 | virtual void TearDown() { | 
|  | 5798 | SurfaceComposerClient::destroyDisplay(mVirtualDisplay); | 
|  | 5799 | LayerTransactionTest::TearDown(); | 
|  | 5800 | mColorLayer = 0; | 
|  | 5801 | } | 
|  | 5802 |  | 
|  | 5803 | void createDisplay(const Rect& layerStackRect, uint32_t layerStack) { | 
|  | 5804 | mVirtualDisplay = | 
|  | 5805 | SurfaceComposerClient::createDisplay(String8("VirtualDisplay"), false /*secure*/); | 
|  | 5806 | asTransaction([&](Transaction& t) { | 
|  | 5807 | t.setDisplaySurface(mVirtualDisplay, mProducer); | 
|  | 5808 | t.setDisplayLayerStack(mVirtualDisplay, layerStack); | 
|  | 5809 | t.setDisplayProjection(mVirtualDisplay, mMainDisplayInfo.orientation, layerStackRect, | 
|  | 5810 | Rect(mMainDisplayInfo.w, mMainDisplayInfo.h)); | 
|  | 5811 | }); | 
|  | 5812 | } | 
|  | 5813 |  | 
|  | 5814 | void createColorLayer(uint32_t layerStack) { | 
|  | 5815 | mColorLayer = | 
|  | 5816 | createSurface(mClient, "ColorLayer", 0 /* buffer width */, 0 /* buffer height */, | 
|  | 5817 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor); | 
|  | 5818 | ASSERT_TRUE(mColorLayer != nullptr); | 
|  | 5819 | ASSERT_TRUE(mColorLayer->isValid()); | 
|  | 5820 | asTransaction([&](Transaction& t) { | 
|  | 5821 | t.setLayerStack(mColorLayer, layerStack); | 
|  | 5822 | t.setCrop_legacy(mColorLayer, Rect(0, 0, 30, 40)); | 
|  | 5823 | t.setLayer(mColorLayer, INT32_MAX - 2); | 
|  | 5824 | t.setColor(mColorLayer, | 
|  | 5825 | half3{mExpectedColor.r / 255.0f, mExpectedColor.g / 255.0f, | 
|  | 5826 | mExpectedColor.b / 255.0f}); | 
|  | 5827 | t.show(mColorLayer); | 
|  | 5828 | }); | 
|  | 5829 | } | 
|  | 5830 |  | 
|  | 5831 | DisplayInfo mMainDisplayInfo; | 
|  | 5832 | sp<IBinder> mMainDisplay; | 
|  | 5833 | sp<IBinder> mVirtualDisplay; | 
|  | 5834 | sp<IGraphicBufferProducer> mProducer; | 
|  | 5835 | sp<SurfaceControl> mColorLayer; | 
|  | 5836 | Color mExpectedColor = {63, 63, 195, 255}; | 
|  | 5837 | }; | 
|  | 5838 |  | 
|  | 5839 | TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInVirtualDisplay) { | 
|  | 5840 | createDisplay({mMainDisplayInfo.viewportW, mMainDisplayInfo.viewportH}, 1 /* layerStack */); | 
|  | 5841 | createColorLayer(1 /* layerStack */); | 
|  | 5842 |  | 
|  | 5843 | asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); }); | 
|  | 5844 |  | 
|  | 5845 | // Verify color layer does not render on main display. | 
|  | 5846 | std::unique_ptr<ScreenCapture> sc; | 
|  | 5847 | ScreenCapture::captureScreen(&sc, mMainDisplay); | 
|  | 5848 | sc->expectColor(Rect(10, 10, 40, 50), {0, 0, 0, 255}); | 
|  | 5849 | sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255}); | 
|  | 5850 |  | 
|  | 5851 | // Verify color layer renders correctly on virtual display. | 
|  | 5852 | ScreenCapture::captureScreen(&sc, mVirtualDisplay); | 
|  | 5853 | sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor); | 
|  | 5854 | sc->expectColor(Rect(1, 1, 9, 9), {0, 0, 0, 0}); | 
|  | 5855 | } | 
|  | 5856 |  | 
|  | 5857 | TEST_F(MultiDisplayLayerBoundsTest, RenderLayerInMirroredVirtualDisplay) { | 
|  | 5858 | // Create a display and set its layer stack to the main display's layer stack so | 
|  | 5859 | // the contents of the main display are mirrored on to the virtual display. | 
|  | 5860 |  | 
|  | 5861 | // Assumption here is that the new mirrored display has the same viewport as the | 
|  | 5862 | // primary display that it is mirroring. | 
|  | 5863 | createDisplay({mMainDisplayInfo.viewportW, mMainDisplayInfo.viewportH}, 0 /* layerStack */); | 
|  | 5864 | createColorLayer(0 /* layerStack */); | 
|  | 5865 |  | 
|  | 5866 | asTransaction([&](Transaction& t) { t.setPosition(mColorLayer, 10, 10); }); | 
|  | 5867 |  | 
|  | 5868 | // Verify color layer renders correctly on main display and it is mirrored on the | 
|  | 5869 | // virtual display. | 
|  | 5870 | std::unique_ptr<ScreenCapture> sc; | 
|  | 5871 | ScreenCapture::captureScreen(&sc, mMainDisplay); | 
|  | 5872 | sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor); | 
|  | 5873 | sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255}); | 
|  | 5874 |  | 
|  | 5875 | ScreenCapture::captureScreen(&sc, mVirtualDisplay); | 
|  | 5876 | sc->expectColor(Rect(10, 10, 40, 50), mExpectedColor); | 
|  | 5877 | sc->expectColor(Rect(0, 0, 9, 9), {0, 0, 0, 255}); | 
|  | 5878 | } | 
|  | 5879 |  | 
| Ady Abraham | df9df4a | 2019-03-12 17:32:05 -0700 | [diff] [blame] | 5880 | class DisplayActiveConfigTest : public ::testing::Test { | 
|  | 5881 | protected: | 
|  | 5882 | void SetUp() override { | 
|  | 5883 | mDisplayToken = SurfaceComposerClient::getInternalDisplayToken(); | 
|  | 5884 | SurfaceComposerClient::getDisplayConfigs(mDisplayToken, &mDisplayconfigs); | 
|  | 5885 | EXPECT_GT(mDisplayconfigs.size(), 0); | 
|  | 5886 |  | 
|  | 5887 | // set display power to on to make sure config can be changed | 
|  | 5888 | SurfaceComposerClient::setDisplayPowerMode(mDisplayToken, HWC_POWER_MODE_NORMAL); | 
|  | 5889 | } | 
|  | 5890 |  | 
|  | 5891 | sp<IBinder> mDisplayToken; | 
|  | 5892 | Vector<DisplayInfo> mDisplayconfigs; | 
|  | 5893 | }; | 
|  | 5894 |  | 
|  | 5895 | TEST_F(DisplayActiveConfigTest, allConfigsAllowed) { | 
|  | 5896 | std::vector<int32_t> allowedConfigs; | 
|  | 5897 |  | 
|  | 5898 | // Add all configs to the allowed configs | 
|  | 5899 | for (int i = 0; i < mDisplayconfigs.size(); i++) { | 
|  | 5900 | allowedConfigs.push_back(i); | 
|  | 5901 | } | 
|  | 5902 |  | 
|  | 5903 | status_t res = SurfaceComposerClient::setAllowedDisplayConfigs(mDisplayToken, allowedConfigs); | 
|  | 5904 | EXPECT_EQ(res, NO_ERROR); | 
|  | 5905 |  | 
|  | 5906 | std::vector<int32_t> outConfigs; | 
|  | 5907 | res = SurfaceComposerClient::getAllowedDisplayConfigs(mDisplayToken, &outConfigs); | 
|  | 5908 | EXPECT_EQ(res, NO_ERROR); | 
|  | 5909 | EXPECT_EQ(allowedConfigs, outConfigs); | 
|  | 5910 | } | 
|  | 5911 |  | 
|  | 5912 | TEST_F(DisplayActiveConfigTest, changeAllowedConfig) { | 
|  | 5913 | // we need at least 2 configs available for this test | 
|  | 5914 | if (mDisplayconfigs.size() <= 1) return; | 
|  | 5915 |  | 
|  | 5916 | int activeConfig = SurfaceComposerClient::getActiveConfig(mDisplayToken); | 
|  | 5917 |  | 
|  | 5918 | // We want to set the allowed config to everything but the active config | 
|  | 5919 | std::vector<int32_t> allowedConfigs; | 
|  | 5920 | for (int i = 0; i < mDisplayconfigs.size(); i++) { | 
|  | 5921 | if (i != activeConfig) { | 
|  | 5922 | allowedConfigs.push_back(i); | 
|  | 5923 | } | 
|  | 5924 | } | 
|  | 5925 |  | 
|  | 5926 | status_t res = SurfaceComposerClient::setAllowedDisplayConfigs(mDisplayToken, allowedConfigs); | 
|  | 5927 | EXPECT_EQ(res, NO_ERROR); | 
|  | 5928 |  | 
|  | 5929 | // Allow some time for the config change | 
|  | 5930 | std::this_thread::sleep_for(200ms); | 
|  | 5931 |  | 
|  | 5932 | int newActiveConfig = SurfaceComposerClient::getActiveConfig(mDisplayToken); | 
|  | 5933 | EXPECT_NE(activeConfig, newActiveConfig); | 
|  | 5934 |  | 
|  | 5935 | // Make sure the new config is part of allowed config | 
|  | 5936 | EXPECT_TRUE(std::find(allowedConfigs.begin(), allowedConfigs.end(), newActiveConfig) != | 
|  | 5937 | allowedConfigs.end()); | 
|  | 5938 | } | 
|  | 5939 |  | 
| Vishnu Nair | da9c85a | 2019-06-03 17:26:48 -0700 | [diff] [blame] | 5940 | class RelativeZTest : public LayerTransactionTest { | 
|  | 5941 | protected: | 
|  | 5942 | virtual void SetUp() { | 
|  | 5943 | LayerTransactionTest::SetUp(); | 
|  | 5944 | ASSERT_EQ(NO_ERROR, mClient->initCheck()); | 
|  | 5945 |  | 
|  | 5946 | const auto display = SurfaceComposerClient::getInternalDisplayToken(); | 
|  | 5947 | ASSERT_FALSE(display == nullptr); | 
|  | 5948 |  | 
|  | 5949 | // Back layer | 
|  | 5950 | mBackgroundLayer = createColorLayer("Background layer", Color::RED); | 
|  | 5951 |  | 
|  | 5952 | // Front layer | 
|  | 5953 | mForegroundLayer = createColorLayer("Foreground layer", Color::GREEN); | 
|  | 5954 |  | 
|  | 5955 | asTransaction([&](Transaction& t) { | 
|  | 5956 | t.setDisplayLayerStack(display, 0); | 
|  | 5957 | t.setLayer(mBackgroundLayer, INT32_MAX - 2).show(mBackgroundLayer); | 
|  | 5958 | t.setLayer(mForegroundLayer, INT32_MAX - 1).show(mForegroundLayer); | 
|  | 5959 | }); | 
|  | 5960 | } | 
|  | 5961 |  | 
|  | 5962 | virtual void TearDown() { | 
|  | 5963 | LayerTransactionTest::TearDown(); | 
|  | 5964 | mBackgroundLayer = 0; | 
|  | 5965 | mForegroundLayer = 0; | 
|  | 5966 | } | 
|  | 5967 |  | 
|  | 5968 | sp<SurfaceControl> mBackgroundLayer; | 
|  | 5969 | sp<SurfaceControl> mForegroundLayer; | 
|  | 5970 | }; | 
|  | 5971 |  | 
|  | 5972 | // When a layer is reparented offscreen, remove relative z order if the relative parent | 
|  | 5973 | // is still onscreen so that the layer is not drawn. | 
|  | 5974 | TEST_F(RelativeZTest, LayerRemoved) { | 
|  | 5975 | std::unique_ptr<ScreenCapture> sc; | 
|  | 5976 |  | 
|  | 5977 | // Background layer (RED) | 
|  | 5978 | //   Child layer (WHITE) (relative to foregroud layer) | 
|  | 5979 | // Foregroud layer (GREEN) | 
|  | 5980 | sp<SurfaceControl> childLayer = | 
|  | 5981 | createColorLayer("Child layer", Color::BLUE, mBackgroundLayer.get()); | 
|  | 5982 |  | 
|  | 5983 | Transaction{} | 
|  | 5984 | .setRelativeLayer(childLayer, mForegroundLayer->getHandle(), 1) | 
|  | 5985 | .show(childLayer) | 
|  | 5986 | .apply(); | 
|  | 5987 |  | 
|  | 5988 | { | 
|  | 5989 | // The childLayer should be in front of the FG control. | 
|  | 5990 | ScreenCapture::captureScreen(&sc); | 
|  | 5991 | sc->checkPixel(1, 1, Color::BLUE.r, Color::BLUE.g, Color::BLUE.b); | 
|  | 5992 | } | 
|  | 5993 |  | 
|  | 5994 | // Background layer (RED) | 
|  | 5995 | // Foregroud layer (GREEN) | 
|  | 5996 | Transaction{}.reparent(childLayer, nullptr).apply(); | 
|  | 5997 |  | 
|  | 5998 | // Background layer (RED) | 
|  | 5999 | //   Child layer (WHITE) | 
|  | 6000 | // Foregroud layer (GREEN) | 
|  | 6001 | Transaction{}.reparent(childLayer, mBackgroundLayer->getHandle()).apply(); | 
|  | 6002 |  | 
|  | 6003 | { | 
|  | 6004 | // The relative z info for child layer should be reset, leaving FG control on top. | 
|  | 6005 | ScreenCapture::captureScreen(&sc); | 
|  | 6006 | sc->checkPixel(1, 1, Color::GREEN.r, Color::GREEN.g, Color::GREEN.b); | 
|  | 6007 | } | 
|  | 6008 | } | 
|  | 6009 |  | 
|  | 6010 | // When a layer is reparented offscreen, preseve relative z order if the relative parent | 
|  | 6011 | // is also offscreen. Regression test b/132613412 | 
|  | 6012 | TEST_F(RelativeZTest, LayerRemovedOffscreenRelativeParent) { | 
|  | 6013 | std::unique_ptr<ScreenCapture> sc; | 
|  | 6014 |  | 
|  | 6015 | // Background layer (RED) | 
|  | 6016 | // Foregroud layer (GREEN) | 
|  | 6017 | //   child level 1 (WHITE) | 
|  | 6018 | //     child level 2a (BLUE) | 
|  | 6019 | //       child level 3 (GREEN) (relative to child level 2b) | 
|  | 6020 | //     child level 2b (BLACK) | 
|  | 6021 | sp<SurfaceControl> childLevel1 = | 
|  | 6022 | createColorLayer("child level 1", Color::WHITE, mForegroundLayer.get()); | 
|  | 6023 | sp<SurfaceControl> childLevel2a = | 
|  | 6024 | createColorLayer("child level 2a", Color::BLUE, childLevel1.get()); | 
|  | 6025 | sp<SurfaceControl> childLevel2b = | 
|  | 6026 | createColorLayer("child level 2b", Color::BLACK, childLevel1.get()); | 
|  | 6027 | sp<SurfaceControl> childLevel3 = | 
|  | 6028 | createColorLayer("child level 3", Color::GREEN, childLevel2a.get()); | 
|  | 6029 |  | 
|  | 6030 | Transaction{} | 
|  | 6031 | .setRelativeLayer(childLevel3, childLevel2b->getHandle(), 1) | 
|  | 6032 | .show(childLevel2a) | 
|  | 6033 | .show(childLevel2b) | 
|  | 6034 | .show(childLevel3) | 
|  | 6035 | .apply(); | 
|  | 6036 |  | 
|  | 6037 | { | 
|  | 6038 | // The childLevel3 should be in front of childLevel2b. | 
|  | 6039 | ScreenCapture::captureScreen(&sc); | 
|  | 6040 | sc->checkPixel(1, 1, Color::GREEN.r, Color::GREEN.g, Color::GREEN.b); | 
|  | 6041 | } | 
|  | 6042 |  | 
|  | 6043 | // Background layer (RED) | 
|  | 6044 | // Foregroud layer (GREEN) | 
|  | 6045 | Transaction{}.reparent(childLevel1, nullptr).apply(); | 
|  | 6046 |  | 
|  | 6047 | // Background layer (RED) | 
|  | 6048 | // Foregroud layer (GREEN) | 
|  | 6049 | //   child level 1 (WHITE) | 
|  | 6050 | //     child level 2 back (BLUE) | 
|  | 6051 | //       child level 3 (GREEN) (relative to child level 2b) | 
|  | 6052 | //     child level 2 front (BLACK) | 
|  | 6053 | Transaction{}.reparent(childLevel1, mForegroundLayer->getHandle()).apply(); | 
|  | 6054 |  | 
|  | 6055 | { | 
|  | 6056 | // Nothing should change at this point since relative z info was preserved. | 
|  | 6057 | ScreenCapture::captureScreen(&sc); | 
|  | 6058 | sc->checkPixel(1, 1, Color::GREEN.r, Color::GREEN.g, Color::GREEN.b); | 
|  | 6059 | } | 
|  | 6060 | } | 
|  | 6061 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 6062 | } // namespace android |