Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 17 | #undef LOG_TAG |
| 18 | #define LOG_TAG "RenderEngineTest" |
| 19 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 20 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 21 | #pragma clang diagnostic push |
| 22 | #pragma clang diagnostic ignored "-Wconversion" |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 23 | #pragma clang diagnostic ignored "-Wextra" |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 24 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 25 | #include <cutils/properties.h> |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 26 | #include <gtest/gtest.h> |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 27 | #include <renderengine/ExternalTexture.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 28 | #include <renderengine/RenderEngine.h> |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 29 | #include <renderengine/impl/ExternalTexture.h> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 30 | #include <sync/sync.h> |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 31 | #include <system/graphics-base-v1.0.h> |
| 32 | #include <tonemap/tonemap.h> |
| 33 | #include <ui/ColorSpace.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 34 | #include <ui/PixelFormat.h> |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 35 | |
| 36 | #include <chrono> |
| 37 | #include <condition_variable> |
| 38 | #include <fstream> |
| 39 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 40 | #include "../skia/SkiaGLRenderEngine.h" |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 41 | #include "../skia/SkiaVkRenderEngine.h" |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame] | 42 | #include "../threaded/RenderEngineThreaded.h" |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 43 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 44 | constexpr int DEFAULT_DISPLAY_WIDTH = 128; |
| 45 | constexpr int DEFAULT_DISPLAY_HEIGHT = 256; |
| 46 | constexpr int DEFAULT_DISPLAY_OFFSET = 64; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 47 | constexpr bool WRITE_BUFFER_TO_FILE_ON_FAILURE = false; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 48 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 49 | namespace android { |
Derek Sollenberger | d3f6065 | 2021-06-11 15:34:36 -0400 | [diff] [blame] | 50 | namespace renderengine { |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 51 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 52 | namespace { |
| 53 | |
| 54 | double EOTF_PQ(double channel) { |
| 55 | float m1 = (2610.0 / 4096.0) / 4.0; |
| 56 | float m2 = (2523.0 / 4096.0) * 128.0; |
| 57 | float c1 = (3424.0 / 4096.0); |
| 58 | float c2 = (2413.0 / 4096.0) * 32.0; |
| 59 | float c3 = (2392.0 / 4096.0) * 32.0; |
| 60 | |
| 61 | float tmp = std::pow(std::clamp(channel, 0.0, 1.0), 1.0 / m2); |
| 62 | tmp = std::fmax(tmp - c1, 0.0) / (c2 - c3 * tmp); |
| 63 | return std::pow(tmp, 1.0 / m1); |
| 64 | } |
| 65 | |
| 66 | vec3 EOTF_PQ(vec3 color) { |
| 67 | return vec3(EOTF_PQ(color.r), EOTF_PQ(color.g), EOTF_PQ(color.b)); |
| 68 | } |
| 69 | |
| 70 | double EOTF_HLG(double channel) { |
| 71 | const float a = 0.17883277; |
| 72 | const float b = 0.28466892; |
| 73 | const float c = 0.55991073; |
| 74 | return channel <= 0.5 ? channel * channel / 3.0 : (exp((channel - c) / a) + b) / 12.0; |
| 75 | } |
| 76 | |
| 77 | vec3 EOTF_HLG(vec3 color) { |
| 78 | return vec3(EOTF_HLG(color.r), EOTF_HLG(color.g), EOTF_HLG(color.b)); |
| 79 | } |
| 80 | |
| 81 | double OETF_sRGB(double channel) { |
| 82 | return channel <= 0.0031308 ? channel * 12.92 : (pow(channel, 1.0 / 2.4) * 1.055) - 0.055; |
| 83 | } |
| 84 | |
| 85 | int sign(float in) { |
| 86 | return in >= 0.0 ? 1 : -1; |
| 87 | } |
| 88 | |
| 89 | vec3 OETF_sRGB(vec3 linear) { |
| 90 | return vec3(sign(linear.r) * OETF_sRGB(linear.r), sign(linear.g) * OETF_sRGB(linear.g), |
| 91 | sign(linear.b) * OETF_sRGB(linear.b)); |
| 92 | } |
| 93 | |
Alec Mouri | 9bcd1d1 | 2022-04-21 22:16:56 +0000 | [diff] [blame] | 94 | // clang-format off |
| 95 | // Converts red channels to green channels, and zeroes out an existing green channel. |
| 96 | static const auto kRemoveGreenAndMoveRedToGreenMat4 = mat4(0, 1, 0, 0, |
| 97 | 0, 0, 0, 0, |
| 98 | 0, 0, 1, 0, |
| 99 | 0, 0, 0, 1); |
| 100 | // clang-format on |
| 101 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 102 | } // namespace |
| 103 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 104 | class RenderEngineFactory { |
| 105 | public: |
| 106 | virtual ~RenderEngineFactory() = default; |
| 107 | |
| 108 | virtual std::string name() = 0; |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 109 | virtual renderengine::RenderEngine::RenderEngineType type() = 0; |
| 110 | virtual std::unique_ptr<renderengine::RenderEngine> createRenderEngine() = 0; |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 111 | virtual bool typeSupported() = 0; |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 112 | virtual bool useColorManagement() const = 0; |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 113 | }; |
| 114 | |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 115 | class SkiaVkRenderEngineFactory : public RenderEngineFactory { |
| 116 | public: |
| 117 | std::string name() override { return "SkiaVkRenderEngineFactory"; } |
| 118 | |
| 119 | renderengine::RenderEngine::RenderEngineType type() { |
| 120 | return renderengine::RenderEngine::RenderEngineType::SKIA_VK; |
| 121 | } |
| 122 | |
| 123 | std::unique_ptr<renderengine::RenderEngine> createRenderEngine() override { |
| 124 | std::unique_ptr<renderengine::RenderEngine> re = createSkiaVkRenderEngine(); |
| 125 | return re; |
| 126 | } |
| 127 | |
| 128 | std::unique_ptr<renderengine::skia::SkiaVkRenderEngine> createSkiaVkRenderEngine() { |
| 129 | renderengine::RenderEngineCreationArgs reCreationArgs = |
| 130 | renderengine::RenderEngineCreationArgs::Builder() |
| 131 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) |
| 132 | .setImageCacheSize(1) |
| 133 | .setUseColorManagerment(false) |
| 134 | .setEnableProtectedContext(false) |
| 135 | .setPrecacheToneMapperShaderOnly(false) |
| 136 | .setSupportsBackgroundBlur(true) |
| 137 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) |
| 138 | .setRenderEngineType(type()) |
| 139 | .setUseColorManagerment(useColorManagement()) |
| 140 | .build(); |
| 141 | return renderengine::skia::SkiaVkRenderEngine::create(reCreationArgs); |
| 142 | } |
| 143 | |
| 144 | bool typeSupported() override { |
| 145 | return skia::SkiaVkRenderEngine::canSupportSkiaVkRenderEngine(); |
| 146 | } |
| 147 | bool useColorManagement() const override { return false; } |
| 148 | void skip() { GTEST_SKIP(); } |
| 149 | }; |
| 150 | |
| 151 | class SkiaVkCMRenderEngineFactory : public SkiaVkRenderEngineFactory { |
| 152 | public: |
| 153 | bool useColorManagement() const override { return true; } |
| 154 | }; |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 155 | class SkiaGLESRenderEngineFactory : public RenderEngineFactory { |
| 156 | public: |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 157 | std::string name() override { return "SkiaGLRenderEngineFactory"; } |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 158 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 159 | renderengine::RenderEngine::RenderEngineType type() { |
| 160 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; |
| 161 | } |
| 162 | |
| 163 | std::unique_ptr<renderengine::RenderEngine> createRenderEngine() override { |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 164 | renderengine::RenderEngineCreationArgs reCreationArgs = |
| 165 | renderengine::RenderEngineCreationArgs::Builder() |
| 166 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) |
| 167 | .setImageCacheSize(1) |
| 168 | .setEnableProtectedContext(false) |
| 169 | .setPrecacheToneMapperShaderOnly(false) |
| 170 | .setSupportsBackgroundBlur(true) |
| 171 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 172 | .setRenderEngineType(type()) |
Alec Mouri | d2bcbae | 2021-06-28 17:02:17 -0700 | [diff] [blame] | 173 | .setUseColorManagerment(useColorManagement()) |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 174 | .build(); |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 175 | return renderengine::skia::SkiaGLRenderEngine::create(reCreationArgs); |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 176 | } |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 177 | |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 178 | bool typeSupported() override { return true; } |
Alec Mouri | d2bcbae | 2021-06-28 17:02:17 -0700 | [diff] [blame] | 179 | bool useColorManagement() const override { return false; } |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | class SkiaGLESCMRenderEngineFactory : public RenderEngineFactory { |
| 183 | public: |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 184 | std::string name() override { return "SkiaGLCMRenderEngineFactory"; } |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 185 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 186 | renderengine::RenderEngine::RenderEngineType type() { |
| 187 | return renderengine::RenderEngine::RenderEngineType::SKIA_GL; |
| 188 | } |
| 189 | |
| 190 | std::unique_ptr<renderengine::RenderEngine> createRenderEngine() override { |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 191 | renderengine::RenderEngineCreationArgs reCreationArgs = |
| 192 | renderengine::RenderEngineCreationArgs::Builder() |
| 193 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) |
| 194 | .setImageCacheSize(1) |
| 195 | .setEnableProtectedContext(false) |
| 196 | .setPrecacheToneMapperShaderOnly(false) |
| 197 | .setSupportsBackgroundBlur(true) |
| 198 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 199 | .setRenderEngineType(type()) |
Alec Mouri | d2bcbae | 2021-06-28 17:02:17 -0700 | [diff] [blame] | 200 | .setUseColorManagerment(useColorManagement()) |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 201 | .build(); |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 202 | return renderengine::skia::SkiaGLRenderEngine::create(reCreationArgs); |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 203 | } |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 204 | |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 205 | bool typeSupported() override { return true; } |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 206 | bool useColorManagement() const override { return true; } |
Alec Mouri | 0eab3e8 | 2020-12-08 18:10:27 -0800 | [diff] [blame] | 207 | }; |
| 208 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 209 | class RenderEngineTest : public ::testing::TestWithParam<std::shared_ptr<RenderEngineFactory>> { |
| 210 | public: |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 211 | std::shared_ptr<renderengine::ExternalTexture> allocateDefaultBuffer() { |
| 212 | return std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 213 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 214 | ExternalTexture>(sp<GraphicBuffer>:: |
| 215 | make(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT, |
| 216 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 217 | GRALLOC_USAGE_SW_READ_OFTEN | |
| 218 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 219 | GRALLOC_USAGE_HW_RENDER | |
| 220 | GRALLOC_USAGE_HW_TEXTURE, |
| 221 | "output"), |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 222 | *mRE, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 223 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 224 | renderengine::impl::ExternalTexture::Usage:: |
| 225 | WRITEABLE); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 228 | // Allocates a 1x1 buffer to fill with a solid color |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 229 | std::shared_ptr<renderengine::ExternalTexture> allocateSourceBuffer(uint32_t width, |
| 230 | uint32_t height) { |
| 231 | return std::make_shared< |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 232 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 233 | ExternalTexture>(sp<GraphicBuffer>:: |
| 234 | make(width, height, HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 235 | GRALLOC_USAGE_SW_READ_OFTEN | |
| 236 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 237 | GRALLOC_USAGE_HW_TEXTURE, |
| 238 | "input"), |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 239 | *mRE, |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 240 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 241 | renderengine::impl::ExternalTexture::Usage:: |
| 242 | WRITEABLE); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 245 | std::shared_ptr<renderengine::ExternalTexture> allocateAndFillSourceBuffer(uint32_t width, |
| 246 | uint32_t height, |
| 247 | ubyte4 color) { |
| 248 | const auto buffer = allocateSourceBuffer(width, height); |
| 249 | uint8_t* pixels; |
| 250 | buffer->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 251 | reinterpret_cast<void**>(&pixels)); |
Leon Scroggins III | 2c1d9ef | 2022-01-21 13:46:56 -0500 | [diff] [blame] | 252 | for (uint32_t j = 0; j < height; j++) { |
| 253 | uint8_t* dst = pixels + (buffer->getBuffer()->getStride() * j * 4); |
| 254 | for (uint32_t i = 0; i < width; i++) { |
| 255 | dst[0] = color.r; |
| 256 | dst[1] = color.g; |
| 257 | dst[2] = color.b; |
| 258 | dst[3] = color.a; |
| 259 | dst += 4; |
| 260 | } |
| 261 | } |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 262 | buffer->getBuffer()->unlock(); |
| 263 | return buffer; |
| 264 | } |
| 265 | |
Leon Scroggins III | 2c1d9ef | 2022-01-21 13:46:56 -0500 | [diff] [blame] | 266 | std::shared_ptr<renderengine::ExternalTexture> allocateR8Buffer(int width, int height) { |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 267 | const auto kUsageFlags = |
| 268 | static_cast<uint64_t>(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 269 | GRALLOC_USAGE_HW_TEXTURE); |
| 270 | auto buffer = |
| 271 | sp<GraphicBuffer>::make(static_cast<uint32_t>(width), static_cast<uint32_t>(height), |
| 272 | android::PIXEL_FORMAT_R_8, 1u, kUsageFlags, "r8"); |
Leon Scroggins III | 2c1d9ef | 2022-01-21 13:46:56 -0500 | [diff] [blame] | 273 | if (buffer->initCheck() != 0) { |
| 274 | // Devices are not required to support R8. |
| 275 | return nullptr; |
| 276 | } |
| 277 | return std::make_shared< |
| 278 | renderengine::impl::ExternalTexture>(std::move(buffer), *mRE, |
| 279 | renderengine::impl::ExternalTexture::Usage:: |
| 280 | READABLE); |
| 281 | } |
| 282 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 283 | RenderEngineTest() { |
| 284 | const ::testing::TestInfo* const test_info = |
| 285 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 286 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 287 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 288 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 289 | ~RenderEngineTest() { |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 290 | if (WRITE_BUFFER_TO_FILE_ON_FAILURE && ::testing::Test::HasFailure()) { |
| 291 | writeBufferToFile("/data/texture_out_"); |
| 292 | } |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 293 | for (uint32_t texName : mTexNames) { |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 294 | mRE->deleteTextures(1, &texName); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 295 | } |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 296 | const ::testing::TestInfo* const test_info = |
| 297 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 298 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 301 | void writeBufferToFile(const char* basename) { |
| 302 | std::string filename(basename); |
| 303 | filename.append(::testing::UnitTest::GetInstance()->current_test_info()->name()); |
| 304 | filename.append(".ppm"); |
| 305 | std::ofstream file(filename.c_str(), std::ios::binary); |
| 306 | if (!file.is_open()) { |
| 307 | ALOGE("Unable to open file: %s", filename.c_str()); |
| 308 | ALOGE("You may need to do: \"adb shell setenforce 0\" to enable " |
| 309 | "surfaceflinger to write debug images"); |
| 310 | return; |
| 311 | } |
| 312 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 313 | uint8_t* pixels; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 314 | mBuffer->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 315 | reinterpret_cast<void**>(&pixels)); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 316 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 317 | file << "P6\n"; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 318 | file << mBuffer->getBuffer()->getWidth() << "\n"; |
| 319 | file << mBuffer->getBuffer()->getHeight() << "\n"; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 320 | file << 255 << "\n"; |
| 321 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 322 | std::vector<uint8_t> outBuffer(mBuffer->getBuffer()->getWidth() * |
| 323 | mBuffer->getBuffer()->getHeight() * 3); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 324 | auto outPtr = reinterpret_cast<uint8_t*>(outBuffer.data()); |
| 325 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 326 | for (int32_t j = 0; j < mBuffer->getBuffer()->getHeight(); j++) { |
| 327 | const uint8_t* src = pixels + (mBuffer->getBuffer()->getStride() * j) * 4; |
| 328 | for (int32_t i = 0; i < mBuffer->getBuffer()->getWidth(); i++) { |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 329 | // Only copy R, G and B components |
| 330 | outPtr[0] = src[0]; |
| 331 | outPtr[1] = src[1]; |
| 332 | outPtr[2] = src[2]; |
| 333 | outPtr += 3; |
| 334 | |
| 335 | src += 4; |
| 336 | } |
| 337 | } |
| 338 | file.write(reinterpret_cast<char*>(outBuffer.data()), outBuffer.size()); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 339 | mBuffer->getBuffer()->unlock(); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void expectBufferColor(const Region& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { |
| 343 | size_t c; |
| 344 | Rect const* rect = region.getArray(&c); |
| 345 | for (size_t i = 0; i < c; i++, rect++) { |
| 346 | expectBufferColor(*rect, r, g, b, a); |
| 347 | } |
| 348 | } |
| 349 | |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 350 | void expectBufferColor(const Point& point, uint8_t r, uint8_t g, uint8_t b, uint8_t a, |
| 351 | uint8_t tolerance = 0) { |
| 352 | expectBufferColor(Rect(point.x, point.y, point.x + 1, point.y + 1), r, g, b, a, tolerance); |
| 353 | } |
| 354 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 355 | void expectBufferColor(const Rect& rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a, |
| 356 | uint8_t tolerance = 0) { |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 357 | auto generator = [=](Point) { return ubyte4(r, g, b, a); }; |
| 358 | expectBufferColor(rect, generator, tolerance); |
| 359 | } |
| 360 | |
| 361 | using ColorGenerator = std::function<ubyte4(Point location)>; |
| 362 | |
| 363 | void expectBufferColor(const Rect& rect, ColorGenerator generator, uint8_t tolerance = 0) { |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 364 | auto colorCompare = [tolerance](const uint8_t* colorA, const uint8_t* colorB) { |
| 365 | auto colorBitCompare = [tolerance](uint8_t a, uint8_t b) { |
| 366 | uint8_t tmp = a >= b ? a - b : b - a; |
| 367 | return tmp <= tolerance; |
| 368 | }; |
| 369 | return std::equal(colorA, colorA + 4, colorB, colorBitCompare); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 370 | }; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 371 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 372 | expectBufferColor(rect, generator, colorCompare); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 375 | void expectBufferColor(const Rect& region, ColorGenerator generator, |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 376 | std::function<bool(const uint8_t* a, const uint8_t* b)> colorCompare) { |
| 377 | uint8_t* pixels; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 378 | mBuffer->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 379 | reinterpret_cast<void**>(&pixels)); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 380 | int32_t maxFails = 10; |
| 381 | int32_t fails = 0; |
| 382 | for (int32_t j = 0; j < region.getHeight(); j++) { |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 383 | const uint8_t* src = pixels + |
| 384 | (mBuffer->getBuffer()->getStride() * (region.top + j) + region.left) * 4; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 385 | for (int32_t i = 0; i < region.getWidth(); i++) { |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 386 | const auto location = Point(region.left + i, region.top + j); |
| 387 | const ubyte4 colors = generator(location); |
| 388 | const uint8_t expected[4] = {colors.r, colors.g, colors.b, colors.a}; |
| 389 | bool colorMatches = colorCompare(src, expected); |
| 390 | EXPECT_TRUE(colorMatches) |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 391 | << GetParam()->name().c_str() << ": " |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 392 | << "pixel @ (" << location.x << ", " << location.y << "): " |
| 393 | << "expected (" << static_cast<uint32_t>(colors.r) << ", " |
| 394 | << static_cast<uint32_t>(colors.g) << ", " |
| 395 | << static_cast<uint32_t>(colors.b) << ", " |
| 396 | << static_cast<uint32_t>(colors.a) << "), " |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 397 | << "got (" << static_cast<uint32_t>(src[0]) << ", " |
| 398 | << static_cast<uint32_t>(src[1]) << ", " << static_cast<uint32_t>(src[2]) |
| 399 | << ", " << static_cast<uint32_t>(src[3]) << ")"; |
| 400 | src += 4; |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 401 | if (!colorMatches && ++fails >= maxFails) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 402 | break; |
| 403 | } |
| 404 | } |
| 405 | if (fails >= maxFails) { |
| 406 | break; |
| 407 | } |
| 408 | } |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 409 | mBuffer->getBuffer()->unlock(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 412 | void expectAlpha(const Rect& rect, uint8_t a) { |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 413 | auto generator = [=](Point) { return ubyte4(0, 0, 0, a); }; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 414 | auto colorCompare = [](const uint8_t* colorA, const uint8_t* colorB) { |
| 415 | return colorA[3] == colorB[3]; |
| 416 | }; |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 417 | expectBufferColor(rect, generator, colorCompare); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void expectShadowColor(const renderengine::LayerSettings& castingLayer, |
| 421 | const renderengine::ShadowSettings& shadow, const ubyte4& casterColor, |
| 422 | const ubyte4& backgroundColor) { |
| 423 | const Rect casterRect(castingLayer.geometry.boundaries); |
| 424 | Region casterRegion = Region(casterRect); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 425 | const float casterCornerRadius = (castingLayer.geometry.roundedCornersRadius.x + |
| 426 | castingLayer.geometry.roundedCornersRadius.y) / |
| 427 | 2.0; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 428 | if (casterCornerRadius > 0.0f) { |
| 429 | // ignore the corners if a corner radius is set |
| 430 | Rect cornerRect(casterCornerRadius, casterCornerRadius); |
| 431 | casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.left, casterRect.top)); |
| 432 | casterRegion.subtractSelf( |
| 433 | cornerRect.offsetTo(casterRect.right - casterCornerRadius, casterRect.top)); |
| 434 | casterRegion.subtractSelf( |
| 435 | cornerRect.offsetTo(casterRect.left, casterRect.bottom - casterCornerRadius)); |
| 436 | casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.right - casterCornerRadius, |
| 437 | casterRect.bottom - casterCornerRadius)); |
| 438 | } |
| 439 | |
| 440 | const float shadowInset = shadow.length * -1.0f; |
| 441 | const Rect casterWithShadow = |
| 442 | Rect(casterRect).inset(shadowInset, shadowInset, shadowInset, shadowInset); |
| 443 | const Region shadowRegion = Region(casterWithShadow).subtractSelf(casterRect); |
| 444 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); |
| 445 | |
| 446 | // verify casting layer |
| 447 | expectBufferColor(casterRegion, casterColor.r, casterColor.g, casterColor.b, casterColor.a); |
| 448 | |
| 449 | // verify shadows by testing just the alpha since its difficult to validate the shadow color |
| 450 | size_t c; |
| 451 | Rect const* r = shadowRegion.getArray(&c); |
| 452 | for (size_t i = 0; i < c; i++, r++) { |
| 453 | expectAlpha(*r, 255); |
| 454 | } |
| 455 | |
| 456 | // verify background |
| 457 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, |
| 458 | backgroundColor.a); |
| 459 | } |
| 460 | |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 461 | void expectShadowColorWithoutCaster(const FloatRect& casterBounds, |
| 462 | const renderengine::ShadowSettings& shadow, |
| 463 | const ubyte4& backgroundColor) { |
| 464 | const float shadowInset = shadow.length * -1.0f; |
| 465 | const Rect casterRect(casterBounds); |
| 466 | const Rect shadowRect = |
| 467 | Rect(casterRect).inset(shadowInset, shadowInset, shadowInset, shadowInset); |
| 468 | |
| 469 | const Region backgroundRegion = |
| 470 | Region(fullscreenRect()).subtractSelf(casterRect).subtractSelf(shadowRect); |
| 471 | |
| 472 | expectAlpha(shadowRect, 255); |
| 473 | // (0, 0, 0) fill on the bounds of the layer should be ignored. |
| 474 | expectBufferColor(casterRect, 255, 255, 255, 255, 254); |
| 475 | |
| 476 | // verify background |
| 477 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, |
| 478 | backgroundColor.a); |
| 479 | } |
| 480 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 481 | static renderengine::ShadowSettings getShadowSettings(const vec2& casterPos, float shadowLength, |
| 482 | bool casterIsTranslucent) { |
| 483 | renderengine::ShadowSettings shadow; |
| 484 | shadow.ambientColor = {0.0f, 0.0f, 0.0f, 0.039f}; |
| 485 | shadow.spotColor = {0.0f, 0.0f, 0.0f, 0.19f}; |
| 486 | shadow.lightPos = vec3(casterPos.x, casterPos.y, 0); |
| 487 | shadow.lightRadius = 0.0f; |
| 488 | shadow.length = shadowLength; |
| 489 | shadow.casterIsTranslucent = casterIsTranslucent; |
| 490 | return shadow; |
| 491 | } |
| 492 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 493 | static Rect fullscreenRect() { return Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); } |
| 494 | |
| 495 | static Rect offsetRect() { |
| 496 | return Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, |
| 497 | DEFAULT_DISPLAY_HEIGHT); |
| 498 | } |
| 499 | |
| 500 | static Rect offsetRectAtZero() { |
| 501 | return Rect(DEFAULT_DISPLAY_WIDTH - DEFAULT_DISPLAY_OFFSET, |
| 502 | DEFAULT_DISPLAY_HEIGHT - DEFAULT_DISPLAY_OFFSET); |
| 503 | } |
| 504 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 505 | void invokeDraw(const renderengine::DisplaySettings& settings, |
| 506 | const std::vector<renderengine::LayerSettings>& layers) { |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 507 | ftl::Future<FenceResult> future = |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 508 | mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd()); |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 509 | ASSERT_TRUE(future.valid()); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 510 | |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 511 | auto result = future.get(); |
| 512 | ASSERT_TRUE(result.ok()); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 513 | |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 514 | auto fence = result.value(); |
| 515 | fence->waitForever(LOG_TAG); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 518 | void drawEmptyLayers() { |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 519 | renderengine::DisplaySettings settings; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 520 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 521 | invokeDraw(settings, layers); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 524 | template <typename SourceVariant> |
| 525 | void fillBuffer(half r, half g, half b, half a); |
| 526 | |
| 527 | template <typename SourceVariant> |
| 528 | void fillRedBuffer(); |
| 529 | |
| 530 | template <typename SourceVariant> |
| 531 | void fillGreenBuffer(); |
| 532 | |
| 533 | template <typename SourceVariant> |
| 534 | void fillBlueBuffer(); |
| 535 | |
| 536 | template <typename SourceVariant> |
| 537 | void fillRedTransparentBuffer(); |
| 538 | |
| 539 | template <typename SourceVariant> |
| 540 | void fillRedOffsetBuffer(); |
| 541 | |
| 542 | template <typename SourceVariant> |
| 543 | void fillBufferPhysicalOffset(); |
| 544 | |
| 545 | template <typename SourceVariant> |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 546 | void fillBufferCheckers(uint32_t rotation); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 547 | |
| 548 | template <typename SourceVariant> |
| 549 | void fillBufferCheckersRotate0(); |
| 550 | |
| 551 | template <typename SourceVariant> |
| 552 | void fillBufferCheckersRotate90(); |
| 553 | |
| 554 | template <typename SourceVariant> |
| 555 | void fillBufferCheckersRotate180(); |
| 556 | |
| 557 | template <typename SourceVariant> |
| 558 | void fillBufferCheckersRotate270(); |
| 559 | |
| 560 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 561 | void fillBufferWithLayerTransform(); |
| 562 | |
| 563 | template <typename SourceVariant> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 564 | void fillBufferLayerTransform(); |
| 565 | |
| 566 | template <typename SourceVariant> |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 567 | void fillBufferWithColorTransform(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 568 | |
| 569 | template <typename SourceVariant> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 570 | void fillBufferColorTransform(); |
| 571 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 572 | template <typename SourceVariant> |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 573 | void fillBufferWithColorTransformAndSourceDataspace(const ui::Dataspace sourceDataspace); |
| 574 | |
| 575 | template <typename SourceVariant> |
| 576 | void fillBufferColorTransformAndSourceDataspace(); |
| 577 | |
| 578 | template <typename SourceVariant> |
| 579 | void fillBufferWithColorTransformAndOutputDataspace(const ui::Dataspace outputDataspace); |
| 580 | |
| 581 | template <typename SourceVariant> |
| 582 | void fillBufferColorTransformAndOutputDataspace(); |
| 583 | |
| 584 | template <typename SourceVariant> |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 585 | void fillBufferWithColorTransformZeroLayerAlpha(); |
| 586 | |
| 587 | template <typename SourceVariant> |
| 588 | void fillBufferColorTransformZeroLayerAlpha(); |
| 589 | |
| 590 | template <typename SourceVariant> |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 591 | void fillRedBufferWithRoundedCorners(); |
| 592 | |
| 593 | template <typename SourceVariant> |
| 594 | void fillBufferWithRoundedCorners(); |
| 595 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 596 | template <typename SourceVariant> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 597 | void fillBufferAndBlurBackground(); |
| 598 | |
| 599 | template <typename SourceVariant> |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 600 | void fillSmallLayerAndBlurBackground(); |
| 601 | |
| 602 | template <typename SourceVariant> |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 603 | void overlayCorners(); |
| 604 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 605 | void fillRedBufferTextureTransform(); |
| 606 | |
| 607 | void fillBufferTextureTransform(); |
| 608 | |
| 609 | void fillRedBufferWithPremultiplyAlpha(); |
| 610 | |
| 611 | void fillBufferWithPremultiplyAlpha(); |
| 612 | |
| 613 | void fillRedBufferWithoutPremultiplyAlpha(); |
| 614 | |
| 615 | void fillBufferWithoutPremultiplyAlpha(); |
| 616 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 617 | void fillGreenColorBufferThenClearRegion(); |
| 618 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 619 | template <typename SourceVariant> |
| 620 | void drawShadow(const renderengine::LayerSettings& castingLayer, |
| 621 | const renderengine::ShadowSettings& shadow, const ubyte4& casterColor, |
| 622 | const ubyte4& backgroundColor); |
| 623 | |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 624 | void drawShadowWithoutCaster(const FloatRect& castingBounds, |
| 625 | const renderengine::ShadowSettings& shadow, |
| 626 | const ubyte4& backgroundColor); |
| 627 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 628 | // Tonemaps grey values from sourceDataspace -> Display P3 and checks that GPU and CPU |
| 629 | // implementations are identical Also implicitly checks that the injected tonemap shader |
| 630 | // compiles |
| 631 | void tonemap(ui::Dataspace sourceDataspace, std::function<vec3(vec3)> eotf, |
| 632 | std::function<vec3(vec3, float)> scaleOotf); |
| 633 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 634 | void initializeRenderEngine(); |
| 635 | |
| 636 | std::unique_ptr<renderengine::RenderEngine> mRE; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 637 | std::shared_ptr<renderengine::ExternalTexture> mBuffer; |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 638 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 639 | std::vector<uint32_t> mTexNames; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 640 | }; |
| 641 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 642 | void RenderEngineTest::initializeRenderEngine() { |
| 643 | const auto& renderEngineFactory = GetParam(); |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 644 | mRE = renderEngineFactory->createRenderEngine(); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 645 | mBuffer = allocateDefaultBuffer(); |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 646 | } |
| 647 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 648 | struct ColorSourceVariant { |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 649 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 650 | RenderEngineTest* /*fixture*/) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 651 | layer.source.solidColor = half3(r, g, b); |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 652 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 653 | } |
| 654 | }; |
| 655 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 656 | struct RelaxOpaqueBufferVariant { |
| 657 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 658 | layer.source.buffer.isOpaque = false; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 659 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static uint8_t getAlphaChannel() { return 255; } |
| 663 | }; |
| 664 | |
| 665 | struct ForceOpaqueBufferVariant { |
| 666 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 667 | layer.source.buffer.isOpaque = true; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 668 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | static uint8_t getAlphaChannel() { |
| 672 | // The isOpaque bit will override the alpha channel, so this should be |
| 673 | // arbitrary. |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 674 | return 50; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 675 | } |
| 676 | }; |
| 677 | |
| 678 | template <typename OpaquenessVariant> |
| 679 | struct BufferSourceVariant { |
| 680 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 681 | RenderEngineTest* fixture) { |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 682 | const auto buf = fixture->allocateSourceBuffer(1, 1); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 683 | uint32_t texName; |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 684 | fixture->mRE->genTextures(1, &texName); |
| 685 | fixture->mTexNames.push_back(texName); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 686 | |
| 687 | uint8_t* pixels; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 688 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 689 | reinterpret_cast<void**>(&pixels)); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 690 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 691 | for (int32_t j = 0; j < buf->getBuffer()->getHeight(); j++) { |
| 692 | uint8_t* iter = pixels + (buf->getBuffer()->getStride() * j) * 4; |
| 693 | for (int32_t i = 0; i < buf->getBuffer()->getWidth(); i++) { |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 694 | iter[0] = uint8_t(r * 255); |
| 695 | iter[1] = uint8_t(g * 255); |
| 696 | iter[2] = uint8_t(b * 255); |
| 697 | iter[3] = OpaquenessVariant::getAlphaChannel(); |
| 698 | iter += 4; |
| 699 | } |
| 700 | } |
| 701 | |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 702 | buf->getBuffer()->unlock(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 703 | |
| 704 | layer.source.buffer.buffer = buf; |
| 705 | layer.source.buffer.textureName = texName; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 706 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 707 | OpaquenessVariant::setOpaqueBit(layer); |
| 708 | } |
| 709 | }; |
| 710 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 711 | template <typename SourceVariant> |
| 712 | void RenderEngineTest::fillBuffer(half r, half g, half b, half a) { |
| 713 | renderengine::DisplaySettings settings; |
| 714 | settings.physicalDisplay = fullscreenRect(); |
| 715 | settings.clip = fullscreenRect(); |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 716 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 717 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 718 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 719 | |
| 720 | renderengine::LayerSettings layer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 721 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 722 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 723 | SourceVariant::fillColor(layer, r, g, b, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 724 | layer.alpha = a; |
| 725 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 726 | layers.push_back(layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 727 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 728 | invokeDraw(settings, layers); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | template <typename SourceVariant> |
| 732 | void RenderEngineTest::fillRedBuffer() { |
| 733 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, 1.0f); |
| 734 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 735 | } |
| 736 | |
| 737 | template <typename SourceVariant> |
| 738 | void RenderEngineTest::fillGreenBuffer() { |
| 739 | fillBuffer<SourceVariant>(0.0f, 1.0f, 0.0f, 1.0f); |
| 740 | expectBufferColor(fullscreenRect(), 0, 255, 0, 255); |
| 741 | } |
| 742 | |
| 743 | template <typename SourceVariant> |
| 744 | void RenderEngineTest::fillBlueBuffer() { |
| 745 | fillBuffer<SourceVariant>(0.0f, 0.0f, 1.0f, 1.0f); |
| 746 | expectBufferColor(fullscreenRect(), 0, 0, 255, 255); |
| 747 | } |
| 748 | |
| 749 | template <typename SourceVariant> |
| 750 | void RenderEngineTest::fillRedTransparentBuffer() { |
| 751 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, .2f); |
| 752 | expectBufferColor(fullscreenRect(), 51, 0, 0, 51); |
| 753 | } |
| 754 | |
| 755 | template <typename SourceVariant> |
| 756 | void RenderEngineTest::fillRedOffsetBuffer() { |
| 757 | renderengine::DisplaySettings settings; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 758 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 759 | settings.physicalDisplay = offsetRect(); |
| 760 | settings.clip = offsetRectAtZero(); |
| 761 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 762 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 763 | |
| 764 | renderengine::LayerSettings layer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 765 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 766 | layer.geometry.boundaries = offsetRectAtZero().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 767 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 768 | layer.alpha = 1.0f; |
| 769 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 770 | layers.push_back(layer); |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 771 | invokeDraw(settings, layers); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | template <typename SourceVariant> |
| 775 | void RenderEngineTest::fillBufferPhysicalOffset() { |
| 776 | fillRedOffsetBuffer<SourceVariant>(); |
| 777 | |
| 778 | expectBufferColor(Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, |
| 779 | DEFAULT_DISPLAY_HEIGHT), |
| 780 | 255, 0, 0, 255); |
| 781 | Rect offsetRegionLeft(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_HEIGHT); |
| 782 | Rect offsetRegionTop(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_OFFSET); |
| 783 | |
| 784 | expectBufferColor(offsetRegionLeft, 0, 0, 0, 0); |
| 785 | expectBufferColor(offsetRegionTop, 0, 0, 0, 0); |
| 786 | } |
| 787 | |
| 788 | template <typename SourceVariant> |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 789 | void RenderEngineTest::fillBufferCheckers(uint32_t orientationFlag) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 790 | renderengine::DisplaySettings settings; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 791 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 792 | settings.physicalDisplay = fullscreenRect(); |
| 793 | // Here logical space is 2x2 |
| 794 | settings.clip = Rect(2, 2); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 795 | settings.orientation = orientationFlag; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 796 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 797 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 798 | |
| 799 | renderengine::LayerSettings layerOne; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 800 | layerOne.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 801 | Rect rectOne(0, 0, 1, 1); |
| 802 | layerOne.geometry.boundaries = rectOne.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 803 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 804 | layerOne.alpha = 1.0f; |
| 805 | |
| 806 | renderengine::LayerSettings layerTwo; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 807 | layerTwo.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 808 | Rect rectTwo(0, 1, 1, 2); |
| 809 | layerTwo.geometry.boundaries = rectTwo.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 810 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 811 | layerTwo.alpha = 1.0f; |
| 812 | |
| 813 | renderengine::LayerSettings layerThree; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 814 | layerThree.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 815 | Rect rectThree(1, 0, 2, 1); |
| 816 | layerThree.geometry.boundaries = rectThree.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 817 | SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 818 | layerThree.alpha = 1.0f; |
| 819 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 820 | layers.push_back(layerOne); |
| 821 | layers.push_back(layerTwo); |
| 822 | layers.push_back(layerThree); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 823 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 824 | invokeDraw(settings, layers); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | template <typename SourceVariant> |
| 828 | void RenderEngineTest::fillBufferCheckersRotate0() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 829 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_0); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 830 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, |
| 831 | 255); |
| 832 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 833 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 834 | 0, 0, 255, 255); |
| 835 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 836 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 837 | 0, 0, 0, 0); |
| 838 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 839 | DEFAULT_DISPLAY_HEIGHT), |
| 840 | 0, 255, 0, 255); |
| 841 | } |
| 842 | |
| 843 | template <typename SourceVariant> |
| 844 | void RenderEngineTest::fillBufferCheckersRotate90() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 845 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_90); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 846 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 255, 0, |
| 847 | 255); |
| 848 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 849 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 850 | 255, 0, 0, 255); |
| 851 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 852 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 853 | 0, 0, 255, 255); |
| 854 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 855 | DEFAULT_DISPLAY_HEIGHT), |
| 856 | 0, 0, 0, 0); |
| 857 | } |
| 858 | |
| 859 | template <typename SourceVariant> |
| 860 | void RenderEngineTest::fillBufferCheckersRotate180() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 861 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_180); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 862 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, |
| 863 | 0); |
| 864 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 865 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 866 | 0, 255, 0, 255); |
| 867 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 868 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 869 | 255, 0, 0, 255); |
| 870 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 871 | DEFAULT_DISPLAY_HEIGHT), |
| 872 | 0, 0, 255, 255); |
| 873 | } |
| 874 | |
| 875 | template <typename SourceVariant> |
| 876 | void RenderEngineTest::fillBufferCheckersRotate270() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 877 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_270); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 878 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255, |
| 879 | 255); |
| 880 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 881 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 882 | 0, 0, 0, 0); |
| 883 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 884 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 885 | 0, 255, 0, 255); |
| 886 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 887 | DEFAULT_DISPLAY_HEIGHT), |
| 888 | 255, 0, 0, 255); |
| 889 | } |
| 890 | |
| 891 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 892 | void RenderEngineTest::fillBufferWithLayerTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 893 | renderengine::DisplaySettings settings; |
| 894 | settings.physicalDisplay = fullscreenRect(); |
| 895 | // Here logical space is 2x2 |
| 896 | settings.clip = Rect(2, 2); |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 897 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 898 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 899 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 900 | |
| 901 | renderengine::LayerSettings layer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 902 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 903 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 904 | // Translate one pixel diagonally |
| 905 | layer.geometry.positionTransform = mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 906 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 907 | layer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 908 | layer.alpha = 1.0f; |
| 909 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 910 | layers.push_back(layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 911 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 912 | invokeDraw(settings, layers); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 913 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 914 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 915 | template <typename SourceVariant> |
| 916 | void RenderEngineTest::fillBufferLayerTransform() { |
| 917 | fillBufferWithLayerTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 918 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, 0); |
| 919 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 920 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 921 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 922 | 255, 0, 0, 255); |
| 923 | } |
| 924 | |
| 925 | template <typename SourceVariant> |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 926 | void RenderEngineTest::fillBufferWithColorTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 927 | renderengine::DisplaySettings settings; |
| 928 | settings.physicalDisplay = fullscreenRect(); |
| 929 | settings.clip = Rect(1, 1); |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 930 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 931 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 932 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 933 | |
| 934 | renderengine::LayerSettings layer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 935 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 936 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 937 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 938 | layer.alpha = 1.0f; |
| 939 | |
| 940 | // construct a fake color matrix |
| 941 | // annihilate green and blue channels |
KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 942 | settings.colorTransform = mat4::scale(vec4(0.9f, 0, 0, 1)); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 943 | // set red channel to red + green |
| 944 | layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 945 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 946 | layer.alpha = 1.0f; |
| 947 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 948 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 949 | layers.push_back(layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 950 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 951 | invokeDraw(settings, layers); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 952 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 953 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 954 | template <typename SourceVariant> |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 955 | void RenderEngineTest::fillBufferWithColorTransformAndSourceDataspace( |
| 956 | const ui::Dataspace sourceDataspace) { |
| 957 | renderengine::DisplaySettings settings; |
| 958 | settings.physicalDisplay = fullscreenRect(); |
| 959 | settings.clip = Rect(1, 1); |
| 960 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 961 | |
| 962 | std::vector<renderengine::LayerSettings> layers; |
| 963 | |
| 964 | renderengine::LayerSettings layer; |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 965 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 966 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 967 | layer.sourceDataspace = sourceDataspace; |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 968 | layer.alpha = 1.0f; |
| 969 | |
| 970 | // construct a fake color matrix |
| 971 | // annihilate green and blue channels |
| 972 | settings.colorTransform = mat4::scale(vec4(0.9f, 0, 0, 1)); |
| 973 | // set red channel to red + green |
| 974 | layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 975 | |
| 976 | layer.alpha = 1.0f; |
| 977 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 978 | |
| 979 | layers.push_back(layer); |
| 980 | |
| 981 | invokeDraw(settings, layers); |
| 982 | } |
| 983 | |
| 984 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 985 | void RenderEngineTest::fillBufferColorTransform() { |
| 986 | fillBufferWithColorTransform<SourceVariant>(); |
KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 987 | expectBufferColor(fullscreenRect(), 172, 0, 0, 255, 1); |
| 988 | } |
| 989 | |
| 990 | template <typename SourceVariant> |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 991 | void RenderEngineTest::fillBufferColorTransformAndSourceDataspace() { |
| 992 | unordered_map<ui::Dataspace, ubyte4> dataspaceToColorMap; |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 993 | dataspaceToColorMap[ui::Dataspace::V0_BT709] = {77, 0, 0, 255}; |
| 994 | dataspaceToColorMap[ui::Dataspace::BT2020] = {101, 0, 0, 255}; |
| 995 | dataspaceToColorMap[ui::Dataspace::ADOBE_RGB] = {75, 0, 0, 255}; |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 996 | ui::Dataspace customizedDataspace = static_cast<ui::Dataspace>( |
| 997 | ui::Dataspace::STANDARD_BT709 | ui::Dataspace::TRANSFER_GAMMA2_2 | |
| 998 | ui::Dataspace::RANGE_FULL); |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 999 | dataspaceToColorMap[customizedDataspace] = {61, 0, 0, 255}; |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1000 | for (const auto& [sourceDataspace, color] : dataspaceToColorMap) { |
| 1001 | fillBufferWithColorTransformAndSourceDataspace<SourceVariant>(sourceDataspace); |
| 1002 | expectBufferColor(fullscreenRect(), color.r, color.g, color.b, color.a, 1); |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | template <typename SourceVariant> |
| 1007 | void RenderEngineTest::fillBufferWithColorTransformAndOutputDataspace( |
| 1008 | const ui::Dataspace outputDataspace) { |
| 1009 | renderengine::DisplaySettings settings; |
| 1010 | settings.physicalDisplay = fullscreenRect(); |
| 1011 | settings.clip = Rect(1, 1); |
| 1012 | settings.outputDataspace = outputDataspace; |
| 1013 | |
| 1014 | std::vector<renderengine::LayerSettings> layers; |
| 1015 | |
| 1016 | renderengine::LayerSettings layer; |
| 1017 | layer.sourceDataspace = ui::Dataspace::V0_SCRGB_LINEAR; |
| 1018 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 1019 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); |
| 1020 | layer.alpha = 1.0f; |
| 1021 | |
| 1022 | // construct a fake color matrix |
| 1023 | // annihilate green and blue channels |
| 1024 | settings.colorTransform = mat4::scale(vec4(0.9f, 0, 0, 1)); |
| 1025 | // set red channel to red + green |
| 1026 | layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 1027 | |
| 1028 | layer.alpha = 1.0f; |
| 1029 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 1030 | |
| 1031 | layers.push_back(layer); |
| 1032 | |
| 1033 | invokeDraw(settings, layers); |
| 1034 | } |
| 1035 | |
| 1036 | template <typename SourceVariant> |
| 1037 | void RenderEngineTest::fillBufferColorTransformAndOutputDataspace() { |
| 1038 | unordered_map<ui::Dataspace, ubyte4> dataspaceToColorMap; |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1039 | dataspaceToColorMap[ui::Dataspace::V0_BT709] = {198, 0, 0, 255}; |
| 1040 | dataspaceToColorMap[ui::Dataspace::BT2020] = {187, 0, 0, 255}; |
| 1041 | dataspaceToColorMap[ui::Dataspace::ADOBE_RGB] = {192, 0, 0, 255}; |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1042 | ui::Dataspace customizedDataspace = static_cast<ui::Dataspace>( |
| 1043 | ui::Dataspace::STANDARD_BT709 | ui::Dataspace::TRANSFER_GAMMA2_6 | |
| 1044 | ui::Dataspace::RANGE_FULL); |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1045 | dataspaceToColorMap[customizedDataspace] = {205, 0, 0, 255}; |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1046 | for (const auto& [outputDataspace, color] : dataspaceToColorMap) { |
| 1047 | fillBufferWithColorTransformAndOutputDataspace<SourceVariant>(outputDataspace); |
| 1048 | expectBufferColor(fullscreenRect(), color.r, color.g, color.b, color.a, 1); |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | template <typename SourceVariant> |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1053 | void RenderEngineTest::fillBufferWithColorTransformZeroLayerAlpha() { |
| 1054 | renderengine::DisplaySettings settings; |
| 1055 | settings.physicalDisplay = fullscreenRect(); |
| 1056 | settings.clip = Rect(1, 1); |
| 1057 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1058 | std::vector<renderengine::LayerSettings> layers; |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1059 | |
| 1060 | renderengine::LayerSettings layer; |
| 1061 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 1062 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); |
| 1063 | layer.alpha = 0; |
| 1064 | |
| 1065 | // construct a fake color matrix |
| 1066 | // simple inverse color |
| 1067 | settings.colorTransform = mat4(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 1, 1, 1, 1); |
| 1068 | |
| 1069 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 1070 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1071 | layers.push_back(layer); |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1072 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1073 | invokeDraw(settings, layers); |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | template <typename SourceVariant> |
| 1077 | void RenderEngineTest::fillBufferColorTransformZeroLayerAlpha() { |
| 1078 | fillBufferWithColorTransformZeroLayerAlpha<SourceVariant>(); |
| 1079 | expectBufferColor(fullscreenRect(), 0, 0, 0, 0); |
| 1080 | } |
| 1081 | |
| 1082 | template <typename SourceVariant> |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1083 | void RenderEngineTest::fillRedBufferWithRoundedCorners() { |
| 1084 | renderengine::DisplaySettings settings; |
| 1085 | settings.physicalDisplay = fullscreenRect(); |
| 1086 | settings.clip = fullscreenRect(); |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1087 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1088 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1089 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1090 | |
| 1091 | renderengine::LayerSettings layer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1092 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1093 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 1094 | layer.geometry.roundedCornersRadius = {5.0f, 5.0f}; |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1095 | layer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 1096 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1097 | layer.alpha = 1.0f; |
| 1098 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1099 | layers.push_back(layer); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1100 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1101 | invokeDraw(settings, layers); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | template <typename SourceVariant> |
| 1105 | void RenderEngineTest::fillBufferWithRoundedCorners() { |
| 1106 | fillRedBufferWithRoundedCorners<SourceVariant>(); |
| 1107 | // Corners should be ignored... |
| 1108 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); |
| 1109 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); |
| 1110 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 1111 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, |
| 1112 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 1113 | 0, 0, 0, 0); |
| 1114 | // ...And the non-rounded portion should be red. |
| 1115 | // Other pixels may be anti-aliased, so let's not check those. |
| 1116 | expectBufferColor(Rect(5, 5, DEFAULT_DISPLAY_WIDTH - 5, DEFAULT_DISPLAY_HEIGHT - 5), 255, 0, 0, |
| 1117 | 255); |
| 1118 | } |
| 1119 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1120 | template <typename SourceVariant> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1121 | void RenderEngineTest::fillBufferAndBlurBackground() { |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1122 | auto blurRadius = 50; |
| 1123 | auto center = DEFAULT_DISPLAY_WIDTH / 2; |
| 1124 | |
| 1125 | renderengine::DisplaySettings settings; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1126 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1127 | settings.physicalDisplay = fullscreenRect(); |
| 1128 | settings.clip = fullscreenRect(); |
| 1129 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1130 | std::vector<renderengine::LayerSettings> layers; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1131 | |
| 1132 | renderengine::LayerSettings backgroundLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1133 | backgroundLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1134 | backgroundLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1135 | SourceVariant::fillColor(backgroundLayer, 0.0f, 1.0f, 0.0f, this); |
| 1136 | backgroundLayer.alpha = 1.0f; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1137 | layers.emplace_back(backgroundLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1138 | |
| 1139 | renderengine::LayerSettings leftLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1140 | leftLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1141 | leftLayer.geometry.boundaries = |
| 1142 | Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT).toFloatRect(); |
| 1143 | SourceVariant::fillColor(leftLayer, 1.0f, 0.0f, 0.0f, this); |
| 1144 | leftLayer.alpha = 1.0f; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1145 | layers.emplace_back(leftLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1146 | |
| 1147 | renderengine::LayerSettings blurLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1148 | blurLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1149 | blurLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1150 | blurLayer.backgroundBlurRadius = blurRadius; |
Derek Sollenberger | ecb2146 | 2021-01-29 16:53:49 -0500 | [diff] [blame] | 1151 | SourceVariant::fillColor(blurLayer, 0.0f, 0.0f, 1.0f, this); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1152 | blurLayer.alpha = 0; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1153 | layers.emplace_back(blurLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1154 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1155 | invokeDraw(settings, layers); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1156 | |
Derek Sollenberger | ecb2146 | 2021-01-29 16:53:49 -0500 | [diff] [blame] | 1157 | // solid color |
| 1158 | expectBufferColor(Rect(0, 0, 1, 1), 255, 0, 0, 255, 0 /* tolerance */); |
| 1159 | |
Derek Sollenberger | b399837 | 2021-02-16 15:16:56 -0500 | [diff] [blame] | 1160 | if (mRE->supportsBackgroundBlur()) { |
| 1161 | // blurred color (downsampling should result in the center color being close to 128) |
| 1162 | expectBufferColor(Rect(center - 1, center - 5, center + 1, center + 5), 128, 128, 0, 255, |
Nathaniel Nifong | 53494f3 | 2021-04-30 14:05:39 -0400 | [diff] [blame] | 1163 | 50 /* tolerance */); |
Derek Sollenberger | b399837 | 2021-02-16 15:16:56 -0500 | [diff] [blame] | 1164 | } |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | template <typename SourceVariant> |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1168 | void RenderEngineTest::fillSmallLayerAndBlurBackground() { |
| 1169 | auto blurRadius = 50; |
| 1170 | renderengine::DisplaySettings settings; |
| 1171 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1172 | settings.physicalDisplay = fullscreenRect(); |
| 1173 | settings.clip = fullscreenRect(); |
| 1174 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1175 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1176 | |
| 1177 | renderengine::LayerSettings backgroundLayer; |
| 1178 | backgroundLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1179 | backgroundLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1180 | SourceVariant::fillColor(backgroundLayer, 1.0f, 0.0f, 0.0f, this); |
| 1181 | backgroundLayer.alpha = 1.0f; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1182 | layers.push_back(backgroundLayer); |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1183 | |
| 1184 | renderengine::LayerSettings blurLayer; |
| 1185 | blurLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1186 | blurLayer.geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f); |
| 1187 | blurLayer.backgroundBlurRadius = blurRadius; |
| 1188 | SourceVariant::fillColor(blurLayer, 0.0f, 0.0f, 1.0f, this); |
| 1189 | blurLayer.alpha = 0; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1190 | layers.push_back(blurLayer); |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1191 | |
| 1192 | invokeDraw(settings, layers); |
| 1193 | |
| 1194 | // Give a generous tolerance - the blur rectangle is very small and this test is |
| 1195 | // mainly concerned with ensuring that there's no device failure. |
| 1196 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), 255, 0, 0, 255, |
| 1197 | 40 /* tolerance */); |
| 1198 | } |
| 1199 | |
| 1200 | template <typename SourceVariant> |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1201 | void RenderEngineTest::overlayCorners() { |
| 1202 | renderengine::DisplaySettings settings; |
| 1203 | settings.physicalDisplay = fullscreenRect(); |
| 1204 | settings.clip = fullscreenRect(); |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1205 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1206 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1207 | std::vector<renderengine::LayerSettings> layersFirst; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1208 | |
| 1209 | renderengine::LayerSettings layerOne; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1210 | layerOne.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1211 | layerOne.geometry.boundaries = |
| 1212 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0); |
| 1213 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
| 1214 | layerOne.alpha = 0.2; |
| 1215 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1216 | layersFirst.push_back(layerOne); |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1217 | invokeDraw(settings, layersFirst); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1218 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51); |
| 1219 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 1220 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 1221 | 0, 0, 0, 0); |
| 1222 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1223 | std::vector<renderengine::LayerSettings> layersSecond; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1224 | renderengine::LayerSettings layerTwo; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1225 | layerTwo.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1226 | layerTwo.geometry.boundaries = |
| 1227 | FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0, |
| 1228 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); |
| 1229 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
| 1230 | layerTwo.alpha = 1.0f; |
| 1231 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1232 | layersSecond.push_back(layerTwo); |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1233 | invokeDraw(settings, layersSecond); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1234 | |
| 1235 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0); |
| 1236 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 1237 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 1238 | 0, 255, 0, 255); |
| 1239 | } |
| 1240 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1241 | void RenderEngineTest::fillRedBufferTextureTransform() { |
| 1242 | renderengine::DisplaySettings settings; |
| 1243 | settings.physicalDisplay = fullscreenRect(); |
| 1244 | settings.clip = Rect(1, 1); |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1245 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1246 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1247 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1248 | |
| 1249 | renderengine::LayerSettings layer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1250 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1251 | // Here will allocate a checker board texture, but transform texture |
| 1252 | // coordinates so that only the upper left is applied. |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1253 | const auto buf = allocateSourceBuffer(2, 2); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1254 | uint32_t texName; |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1255 | RenderEngineTest::mRE->genTextures(1, &texName); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1256 | this->mTexNames.push_back(texName); |
| 1257 | |
| 1258 | uint8_t* pixels; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1259 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1260 | reinterpret_cast<void**>(&pixels)); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1261 | // Red top left, Green top right, Blue bottom left, Black bottom right |
| 1262 | pixels[0] = 255; |
| 1263 | pixels[1] = 0; |
| 1264 | pixels[2] = 0; |
| 1265 | pixels[3] = 255; |
| 1266 | pixels[4] = 0; |
| 1267 | pixels[5] = 255; |
| 1268 | pixels[6] = 0; |
| 1269 | pixels[7] = 255; |
| 1270 | pixels[8] = 0; |
| 1271 | pixels[9] = 0; |
| 1272 | pixels[10] = 255; |
| 1273 | pixels[11] = 255; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1274 | buf->getBuffer()->unlock(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1275 | |
| 1276 | layer.source.buffer.buffer = buf; |
| 1277 | layer.source.buffer.textureName = texName; |
| 1278 | // Transform coordinates to only be inside the red quadrant. |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 1279 | layer.source.buffer.textureTransform = mat4::scale(vec4(0.2f, 0.2f, 1.f, 1.f)); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1280 | layer.alpha = 1.0f; |
| 1281 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 1282 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1283 | layers.push_back(layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1284 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1285 | invokeDraw(settings, layers); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | void RenderEngineTest::fillBufferTextureTransform() { |
| 1289 | fillRedBufferTextureTransform(); |
| 1290 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 1291 | } |
| 1292 | |
| 1293 | void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() { |
| 1294 | renderengine::DisplaySettings settings; |
| 1295 | settings.physicalDisplay = fullscreenRect(); |
| 1296 | // Here logical space is 1x1 |
| 1297 | settings.clip = Rect(1, 1); |
| 1298 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1299 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1300 | |
| 1301 | renderengine::LayerSettings layer; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1302 | const auto buf = allocateSourceBuffer(1, 1); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1303 | uint32_t texName; |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1304 | RenderEngineTest::mRE->genTextures(1, &texName); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1305 | this->mTexNames.push_back(texName); |
| 1306 | |
| 1307 | uint8_t* pixels; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1308 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1309 | reinterpret_cast<void**>(&pixels)); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1310 | pixels[0] = 255; |
| 1311 | pixels[1] = 0; |
| 1312 | pixels[2] = 0; |
| 1313 | pixels[3] = 255; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1314 | buf->getBuffer()->unlock(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1315 | |
| 1316 | layer.source.buffer.buffer = buf; |
| 1317 | layer.source.buffer.textureName = texName; |
| 1318 | layer.source.buffer.usePremultipliedAlpha = true; |
| 1319 | layer.alpha = 0.5f; |
| 1320 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 1321 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1322 | layers.push_back(layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1323 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1324 | invokeDraw(settings, layers); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | void RenderEngineTest::fillBufferWithPremultiplyAlpha() { |
| 1328 | fillRedBufferWithPremultiplyAlpha(); |
| 1329 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128); |
| 1330 | } |
| 1331 | |
| 1332 | void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() { |
| 1333 | renderengine::DisplaySettings settings; |
| 1334 | settings.physicalDisplay = fullscreenRect(); |
| 1335 | // Here logical space is 1x1 |
| 1336 | settings.clip = Rect(1, 1); |
| 1337 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1338 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1339 | |
| 1340 | renderengine::LayerSettings layer; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1341 | const auto buf = allocateSourceBuffer(1, 1); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1342 | uint32_t texName; |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1343 | RenderEngineTest::mRE->genTextures(1, &texName); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1344 | this->mTexNames.push_back(texName); |
| 1345 | |
| 1346 | uint8_t* pixels; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1347 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1348 | reinterpret_cast<void**>(&pixels)); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1349 | pixels[0] = 255; |
| 1350 | pixels[1] = 0; |
| 1351 | pixels[2] = 0; |
| 1352 | pixels[3] = 255; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1353 | buf->getBuffer()->unlock(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1354 | |
| 1355 | layer.source.buffer.buffer = buf; |
| 1356 | layer.source.buffer.textureName = texName; |
| 1357 | layer.source.buffer.usePremultipliedAlpha = false; |
| 1358 | layer.alpha = 0.5f; |
| 1359 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 1360 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1361 | layers.push_back(layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1362 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1363 | invokeDraw(settings, layers); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() { |
| 1367 | fillRedBufferWithoutPremultiplyAlpha(); |
wukui1 | 6f3c0bb | 2020-08-05 20:35:29 +0800 | [diff] [blame] | 1368 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128, 1); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1369 | } |
| 1370 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1371 | template <typename SourceVariant> |
| 1372 | void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer, |
| 1373 | const renderengine::ShadowSettings& shadow, |
| 1374 | const ubyte4& casterColor, const ubyte4& backgroundColor) { |
| 1375 | renderengine::DisplaySettings settings; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1376 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1377 | settings.physicalDisplay = fullscreenRect(); |
| 1378 | settings.clip = fullscreenRect(); |
| 1379 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1380 | std::vector<renderengine::LayerSettings> layers; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1381 | |
| 1382 | // add background layer |
| 1383 | renderengine::LayerSettings bgLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1384 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1385 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1386 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 1387 | backgroundColor.b / 255.0f, this); |
| 1388 | bgLayer.alpha = backgroundColor.a / 255.0f; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1389 | layers.push_back(bgLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1390 | |
| 1391 | // add shadow layer |
| 1392 | renderengine::LayerSettings shadowLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1393 | shadowLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1394 | shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries; |
| 1395 | shadowLayer.alpha = castingLayer.alpha; |
| 1396 | shadowLayer.shadow = shadow; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1397 | layers.push_back(shadowLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1398 | |
| 1399 | // add layer casting the shadow |
| 1400 | renderengine::LayerSettings layer = castingLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1401 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1402 | SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f, |
| 1403 | casterColor.b / 255.0f, this); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1404 | layers.push_back(layer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1405 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1406 | invokeDraw(settings, layers); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1407 | } |
| 1408 | |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1409 | void RenderEngineTest::drawShadowWithoutCaster(const FloatRect& castingBounds, |
| 1410 | const renderengine::ShadowSettings& shadow, |
| 1411 | const ubyte4& backgroundColor) { |
| 1412 | renderengine::DisplaySettings settings; |
| 1413 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1414 | settings.physicalDisplay = fullscreenRect(); |
| 1415 | settings.clip = fullscreenRect(); |
| 1416 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1417 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1418 | |
| 1419 | // add background layer |
| 1420 | renderengine::LayerSettings bgLayer; |
| 1421 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1422 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1423 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 1424 | backgroundColor.b / 255.0f, this); |
| 1425 | bgLayer.alpha = backgroundColor.a / 255.0f; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1426 | layers.push_back(bgLayer); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1427 | |
| 1428 | // add shadow layer |
| 1429 | renderengine::LayerSettings shadowLayer; |
| 1430 | shadowLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1431 | shadowLayer.geometry.boundaries = castingBounds; |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 1432 | shadowLayer.skipContentDraw = true; |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1433 | shadowLayer.alpha = 1.0f; |
| 1434 | ColorSourceVariant::fillColor(shadowLayer, 0, 0, 0, this); |
| 1435 | shadowLayer.shadow = shadow; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1436 | layers.push_back(shadowLayer); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1437 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1438 | invokeDraw(settings, layers); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1439 | } |
| 1440 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1441 | void RenderEngineTest::tonemap(ui::Dataspace sourceDataspace, std::function<vec3(vec3)> eotf, |
| 1442 | std::function<vec3(vec3, float)> scaleOotf) { |
| 1443 | constexpr int32_t kGreyLevels = 256; |
| 1444 | |
| 1445 | const auto rect = Rect(0, 0, kGreyLevels, 1); |
| 1446 | |
| 1447 | constexpr float kMaxLuminance = 750.f; |
| 1448 | constexpr float kCurrentLuminanceNits = 500.f; |
| 1449 | const renderengine::DisplaySettings display{ |
| 1450 | .physicalDisplay = rect, |
| 1451 | .clip = rect, |
| 1452 | .maxLuminance = kMaxLuminance, |
| 1453 | .currentLuminanceNits = kCurrentLuminanceNits, |
| 1454 | .outputDataspace = ui::Dataspace::DISPLAY_P3, |
| 1455 | }; |
| 1456 | |
| 1457 | auto buf = std::make_shared< |
| 1458 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1459 | ExternalTexture>(sp<GraphicBuffer>::make(kGreyLevels, 1, |
| 1460 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 1461 | GRALLOC_USAGE_SW_READ_OFTEN | |
| 1462 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 1463 | GRALLOC_USAGE_HW_RENDER | |
| 1464 | GRALLOC_USAGE_HW_TEXTURE, |
| 1465 | "input"), |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1466 | *mRE, |
| 1467 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 1468 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
| 1469 | ASSERT_EQ(0, buf->getBuffer()->initCheck()); |
| 1470 | { |
| 1471 | uint8_t* pixels; |
| 1472 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1473 | reinterpret_cast<void**>(&pixels)); |
| 1474 | |
| 1475 | uint8_t color = 0; |
| 1476 | for (int32_t j = 0; j < buf->getBuffer()->getHeight(); j++) { |
| 1477 | uint8_t* dest = pixels + (buf->getBuffer()->getStride() * j * 4); |
| 1478 | for (int32_t i = 0; i < buf->getBuffer()->getWidth(); i++) { |
| 1479 | dest[0] = color; |
| 1480 | dest[1] = color; |
| 1481 | dest[2] = color; |
| 1482 | dest[3] = 255; |
| 1483 | color++; |
| 1484 | dest += 4; |
| 1485 | } |
| 1486 | } |
| 1487 | buf->getBuffer()->unlock(); |
| 1488 | } |
| 1489 | |
| 1490 | mBuffer = std::make_shared< |
| 1491 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1492 | ExternalTexture>(sp<GraphicBuffer>::make(kGreyLevels, 1, |
| 1493 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 1494 | GRALLOC_USAGE_SW_READ_OFTEN | |
| 1495 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 1496 | GRALLOC_USAGE_HW_RENDER | |
| 1497 | GRALLOC_USAGE_HW_TEXTURE, |
| 1498 | "output"), |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1499 | *mRE, |
| 1500 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 1501 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
| 1502 | ASSERT_EQ(0, mBuffer->getBuffer()->initCheck()); |
| 1503 | |
| 1504 | const renderengine::LayerSettings layer{.geometry.boundaries = rect.toFloatRect(), |
| 1505 | .source = |
| 1506 | renderengine::PixelSource{ |
| 1507 | .buffer = |
| 1508 | renderengine::Buffer{ |
| 1509 | .buffer = |
| 1510 | std::move(buf), |
| 1511 | .usePremultipliedAlpha = |
| 1512 | true, |
| 1513 | }, |
| 1514 | }, |
| 1515 | .alpha = 1.0f, |
| 1516 | .sourceDataspace = sourceDataspace}; |
| 1517 | |
| 1518 | std::vector<renderengine::LayerSettings> layers{layer}; |
| 1519 | invokeDraw(display, layers); |
| 1520 | |
| 1521 | ColorSpace displayP3 = ColorSpace::DisplayP3(); |
| 1522 | ColorSpace bt2020 = ColorSpace::BT2020(); |
| 1523 | |
| 1524 | tonemap::Metadata metadata{.displayMaxLuminance = 750.0f}; |
| 1525 | |
| 1526 | auto generator = [=](Point location) { |
| 1527 | const double normColor = static_cast<double>(location.x) / (kGreyLevels - 1); |
| 1528 | const vec3 rgb = vec3(normColor, normColor, normColor); |
| 1529 | |
| 1530 | const vec3 linearRGB = eotf(rgb); |
| 1531 | |
| 1532 | const vec3 xyz = bt2020.getRGBtoXYZ() * linearRGB; |
| 1533 | |
| 1534 | const vec3 scaledXYZ = scaleOotf(xyz, kCurrentLuminanceNits); |
Alec Mouri | 196b0f2 | 2022-03-04 22:13:48 +0000 | [diff] [blame] | 1535 | const auto gains = |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1536 | tonemap::getToneMapper() |
| 1537 | ->lookupTonemapGain(static_cast<aidl::android::hardware::graphics::common:: |
| 1538 | Dataspace>(sourceDataspace), |
| 1539 | static_cast<aidl::android::hardware::graphics::common:: |
| 1540 | Dataspace>( |
| 1541 | ui::Dataspace::DISPLAY_P3), |
Alec Mouri | 196b0f2 | 2022-03-04 22:13:48 +0000 | [diff] [blame] | 1542 | {tonemap:: |
| 1543 | Color{.linearRGB = |
| 1544 | scaleOotf(linearRGB, |
| 1545 | kCurrentLuminanceNits), |
| 1546 | .xyz = scaledXYZ}}, |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1547 | metadata); |
Alec Mouri | 196b0f2 | 2022-03-04 22:13:48 +0000 | [diff] [blame] | 1548 | EXPECT_EQ(1, gains.size()); |
| 1549 | const double gain = gains.front(); |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1550 | const vec3 normalizedXYZ = scaledXYZ * gain / metadata.displayMaxLuminance; |
| 1551 | |
| 1552 | const vec3 targetRGB = OETF_sRGB(displayP3.getXYZtoRGB() * normalizedXYZ) * 255; |
| 1553 | return ubyte4(static_cast<uint8_t>(targetRGB.r), static_cast<uint8_t>(targetRGB.g), |
| 1554 | static_cast<uint8_t>(targetRGB.b), 255); |
| 1555 | }; |
| 1556 | |
| 1557 | expectBufferColor(Rect(kGreyLevels, 1), generator, 2); |
| 1558 | } |
| 1559 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1560 | INSTANTIATE_TEST_SUITE_P(PerRenderEngineType, RenderEngineTest, |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1561 | testing::Values(std::make_shared<SkiaGLESRenderEngineFactory>(), |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1562 | std::make_shared<SkiaGLESCMRenderEngineFactory>(), |
| 1563 | std::make_shared<SkiaVkRenderEngineFactory>(), |
| 1564 | std::make_shared<SkiaVkCMRenderEngineFactory>())); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1565 | |
| 1566 | TEST_P(RenderEngineTest, drawLayers_noLayersToDraw) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1567 | if (!GetParam()->typeSupported()) { |
| 1568 | GTEST_SKIP(); |
| 1569 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1570 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1571 | drawEmptyLayers(); |
| 1572 | } |
| 1573 | |
Sally Qi | 1fed86e | 2022-06-23 15:33:52 -0700 | [diff] [blame] | 1574 | TEST_P(RenderEngineTest, drawLayers_fillRedBufferAndEmptyBuffer) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1575 | if (!GetParam()->typeSupported()) { |
| 1576 | GTEST_SKIP(); |
| 1577 | } |
Sally Qi | 1fed86e | 2022-06-23 15:33:52 -0700 | [diff] [blame] | 1578 | initializeRenderEngine(); |
| 1579 | renderengine::DisplaySettings settings; |
| 1580 | settings.physicalDisplay = fullscreenRect(); |
| 1581 | settings.clip = fullscreenRect(); |
| 1582 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1583 | |
| 1584 | // add a red layer |
| 1585 | renderengine::LayerSettings layerOne{ |
| 1586 | .geometry.boundaries = fullscreenRect().toFloatRect(), |
| 1587 | .source.solidColor = half3(1.0f, 0.0f, 0.0f), |
| 1588 | .alpha = 1.f, |
| 1589 | }; |
| 1590 | |
| 1591 | std::vector<renderengine::LayerSettings> layersFirst{layerOne}; |
| 1592 | invokeDraw(settings, layersFirst); |
| 1593 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 1594 | |
| 1595 | // re-draw with an empty layer above it, and we get a transparent black one |
| 1596 | std::vector<renderengine::LayerSettings> layersSecond; |
| 1597 | invokeDraw(settings, layersSecond); |
| 1598 | expectBufferColor(fullscreenRect(), 0, 0, 0, 0); |
| 1599 | } |
| 1600 | |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1601 | TEST_P(RenderEngineTest, drawLayers_withoutBuffers_withColorTransform) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1602 | if (!GetParam()->typeSupported()) { |
| 1603 | GTEST_SKIP(); |
| 1604 | } |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1605 | initializeRenderEngine(); |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1606 | |
| 1607 | renderengine::DisplaySettings settings; |
| 1608 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1609 | settings.physicalDisplay = fullscreenRect(); |
| 1610 | settings.clip = fullscreenRect(); |
| 1611 | |
| 1612 | // 255, 255, 255, 255 is full opaque white. |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 1613 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 1614 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1615 | // Create layer with given color. |
| 1616 | renderengine::LayerSettings bgLayer; |
| 1617 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1618 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1619 | bgLayer.source.solidColor = half3(backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 1620 | backgroundColor.b / 255.0f); |
| 1621 | bgLayer.alpha = backgroundColor.a / 255.0f; |
| 1622 | // Transform the red color. |
| 1623 | bgLayer.colorTransform = mat4(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 1624 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1625 | std::vector<renderengine::LayerSettings> layers; |
| 1626 | layers.push_back(bgLayer); |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1627 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1628 | invokeDraw(settings, layers); |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1629 | |
| 1630 | // Expect to see full opaque pixel (with inverted red from the transform). |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1631 | expectBufferColor(Rect(0, 0, 10, 10), 0.f, backgroundColor.g, backgroundColor.b, |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1632 | backgroundColor.a); |
| 1633 | } |
| 1634 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1635 | TEST_P(RenderEngineTest, drawLayers_nullOutputBuffer) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1636 | if (!GetParam()->typeSupported()) { |
| 1637 | GTEST_SKIP(); |
| 1638 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1639 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1640 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1641 | renderengine::DisplaySettings settings; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1642 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1643 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1644 | renderengine::LayerSettings layer; |
| 1645 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1646 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1647 | layers.push_back(layer); |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 1648 | ftl::Future<FenceResult> future = |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 1649 | mRE->drawLayers(settings, layers, nullptr, true, base::unique_fd()); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1650 | |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 1651 | ASSERT_TRUE(future.valid()); |
| 1652 | auto result = future.get(); |
| 1653 | ASSERT_FALSE(result.ok()); |
| 1654 | ASSERT_EQ(BAD_VALUE, result.error()); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1657 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1658 | if (!GetParam()->typeSupported()) { |
| 1659 | GTEST_SKIP(); |
| 1660 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1661 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1662 | fillRedBuffer<ColorSourceVariant>(); |
| 1663 | } |
| 1664 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1665 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1666 | if (!GetParam()->typeSupported()) { |
| 1667 | GTEST_SKIP(); |
| 1668 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1669 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1670 | fillGreenBuffer<ColorSourceVariant>(); |
| 1671 | } |
| 1672 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1673 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1674 | if (!GetParam()->typeSupported()) { |
| 1675 | GTEST_SKIP(); |
| 1676 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1677 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1678 | fillBlueBuffer<ColorSourceVariant>(); |
| 1679 | } |
| 1680 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1681 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1682 | if (!GetParam()->typeSupported()) { |
| 1683 | GTEST_SKIP(); |
| 1684 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1685 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1686 | fillRedTransparentBuffer<ColorSourceVariant>(); |
| 1687 | } |
| 1688 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1689 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1690 | if (!GetParam()->typeSupported()) { |
| 1691 | GTEST_SKIP(); |
| 1692 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1693 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1694 | fillBufferPhysicalOffset<ColorSourceVariant>(); |
| 1695 | } |
| 1696 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1697 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1698 | if (!GetParam()->typeSupported()) { |
| 1699 | GTEST_SKIP(); |
| 1700 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1701 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1702 | fillBufferCheckersRotate0<ColorSourceVariant>(); |
| 1703 | } |
| 1704 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1705 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1706 | if (!GetParam()->typeSupported()) { |
| 1707 | GTEST_SKIP(); |
| 1708 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1709 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1710 | fillBufferCheckersRotate90<ColorSourceVariant>(); |
| 1711 | } |
| 1712 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1713 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1714 | if (!GetParam()->typeSupported()) { |
| 1715 | GTEST_SKIP(); |
| 1716 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1717 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1718 | fillBufferCheckersRotate180<ColorSourceVariant>(); |
| 1719 | } |
| 1720 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1721 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1722 | if (!GetParam()->typeSupported()) { |
| 1723 | GTEST_SKIP(); |
| 1724 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1725 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1726 | fillBufferCheckersRotate270<ColorSourceVariant>(); |
| 1727 | } |
| 1728 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1729 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1730 | if (!GetParam()->typeSupported()) { |
| 1731 | GTEST_SKIP(); |
| 1732 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1733 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1734 | fillBufferLayerTransform<ColorSourceVariant>(); |
| 1735 | } |
| 1736 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1737 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1738 | if (!GetParam()->typeSupported()) { |
| 1739 | GTEST_SKIP(); |
| 1740 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1741 | initializeRenderEngine(); |
KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1742 | fillBufferColorTransform<ColorSourceVariant>(); |
| 1743 | } |
| 1744 | |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1745 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_sourceDataspace) { |
| 1746 | const auto& renderEngineFactory = GetParam(); |
| 1747 | // skip for non color management |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1748 | if (!renderEngineFactory->typeSupported() || !renderEngineFactory->useColorManagement()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1749 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | initializeRenderEngine(); |
| 1753 | fillBufferColorTransformAndSourceDataspace<ColorSourceVariant>(); |
| 1754 | } |
| 1755 | |
| 1756 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_outputDataspace) { |
| 1757 | const auto& renderEngineFactory = GetParam(); |
| 1758 | // skip for non color management |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1759 | if (!renderEngineFactory->typeSupported() || !renderEngineFactory->useColorManagement()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1760 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | initializeRenderEngine(); |
| 1764 | fillBufferColorTransformAndOutputDataspace<ColorSourceVariant>(); |
| 1765 | } |
| 1766 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1767 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1768 | if (!GetParam()->typeSupported()) { |
| 1769 | GTEST_SKIP(); |
| 1770 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1771 | initializeRenderEngine(); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1772 | fillBufferWithRoundedCorners<ColorSourceVariant>(); |
| 1773 | } |
| 1774 | |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1775 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1776 | if (!GetParam()->typeSupported()) { |
| 1777 | GTEST_SKIP(); |
| 1778 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1779 | initializeRenderEngine(); |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1780 | fillBufferColorTransformZeroLayerAlpha<ColorSourceVariant>(); |
| 1781 | } |
| 1782 | |
Nathaniel Nifong | 53494f3 | 2021-04-30 14:05:39 -0400 | [diff] [blame] | 1783 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1784 | if (!GetParam()->typeSupported()) { |
| 1785 | GTEST_SKIP(); |
| 1786 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1787 | initializeRenderEngine(); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1788 | fillBufferAndBlurBackground<ColorSourceVariant>(); |
| 1789 | } |
| 1790 | |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1791 | TEST_P(RenderEngineTest, drawLayers_fillSmallLayerAndBlurBackground_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1792 | if (!GetParam()->typeSupported()) { |
| 1793 | GTEST_SKIP(); |
| 1794 | } |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1795 | initializeRenderEngine(); |
| 1796 | fillSmallLayerAndBlurBackground<ColorSourceVariant>(); |
| 1797 | } |
| 1798 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1799 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_colorSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1800 | if (!GetParam()->typeSupported()) { |
| 1801 | GTEST_SKIP(); |
| 1802 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1803 | initializeRenderEngine(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1804 | overlayCorners<ColorSourceVariant>(); |
| 1805 | } |
| 1806 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1807 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1808 | if (!GetParam()->typeSupported()) { |
| 1809 | GTEST_SKIP(); |
| 1810 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1811 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1812 | fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1813 | } |
| 1814 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1815 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1816 | if (!GetParam()->typeSupported()) { |
| 1817 | GTEST_SKIP(); |
| 1818 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1819 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1820 | fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1821 | } |
| 1822 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1823 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1824 | if (!GetParam()->typeSupported()) { |
| 1825 | GTEST_SKIP(); |
| 1826 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1827 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1828 | fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1829 | } |
| 1830 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1831 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1832 | if (!GetParam()->typeSupported()) { |
| 1833 | GTEST_SKIP(); |
| 1834 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1835 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1836 | fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1837 | } |
| 1838 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1839 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1840 | if (!GetParam()->typeSupported()) { |
| 1841 | GTEST_SKIP(); |
| 1842 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1843 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1844 | fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1845 | } |
| 1846 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1847 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1848 | if (!GetParam()->typeSupported()) { |
| 1849 | GTEST_SKIP(); |
| 1850 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1851 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1852 | fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1853 | } |
| 1854 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1855 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1856 | if (!GetParam()->typeSupported()) { |
| 1857 | GTEST_SKIP(); |
| 1858 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1859 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1860 | fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1861 | } |
| 1862 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1863 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1864 | if (!GetParam()->typeSupported()) { |
| 1865 | GTEST_SKIP(); |
| 1866 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1867 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1868 | fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1869 | } |
| 1870 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1871 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1872 | if (!GetParam()->typeSupported()) { |
| 1873 | GTEST_SKIP(); |
| 1874 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1875 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1876 | fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1877 | } |
| 1878 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1879 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1880 | if (!GetParam()->typeSupported()) { |
| 1881 | GTEST_SKIP(); |
| 1882 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1883 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1884 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1885 | } |
| 1886 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1887 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1888 | if (!GetParam()->typeSupported()) { |
| 1889 | GTEST_SKIP(); |
| 1890 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1891 | initializeRenderEngine(); |
KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1892 | fillBufferColorTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1893 | } |
| 1894 | |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1895 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndSourceDataspace_opaqueBufferSource) { |
| 1896 | const auto& renderEngineFactory = GetParam(); |
| 1897 | // skip for non color management |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1898 | if (!renderEngineFactory->typeSupported() || !renderEngineFactory->useColorManagement()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1899 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | initializeRenderEngine(); |
| 1903 | fillBufferColorTransformAndSourceDataspace<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1904 | } |
| 1905 | |
| 1906 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndOutputDataspace_opaqueBufferSource) { |
| 1907 | const auto& renderEngineFactory = GetParam(); |
| 1908 | // skip for non color management |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1909 | if (!renderEngineFactory->typeSupported() || !renderEngineFactory->useColorManagement()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1910 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | initializeRenderEngine(); |
| 1914 | fillBufferColorTransformAndOutputDataspace<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1915 | } |
| 1916 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1917 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1918 | if (!GetParam()->typeSupported()) { |
| 1919 | GTEST_SKIP(); |
| 1920 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1921 | initializeRenderEngine(); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1922 | fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1923 | } |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1924 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1925 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1926 | if (!GetParam()->typeSupported()) { |
| 1927 | GTEST_SKIP(); |
| 1928 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1929 | initializeRenderEngine(); |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1930 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1931 | } |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1932 | |
Nathaniel Nifong | 53494f3 | 2021-04-30 14:05:39 -0400 | [diff] [blame] | 1933 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1934 | if (!GetParam()->typeSupported()) { |
| 1935 | GTEST_SKIP(); |
| 1936 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1937 | initializeRenderEngine(); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1938 | fillBufferAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1939 | } |
| 1940 | |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1941 | TEST_P(RenderEngineTest, drawLayers_fillSmallLayerAndBlurBackground_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1942 | if (!GetParam()->typeSupported()) { |
| 1943 | GTEST_SKIP(); |
| 1944 | } |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1945 | initializeRenderEngine(); |
| 1946 | fillSmallLayerAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1947 | } |
| 1948 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1949 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1950 | if (!GetParam()->typeSupported()) { |
| 1951 | GTEST_SKIP(); |
| 1952 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1953 | initializeRenderEngine(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1954 | overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1955 | } |
| 1956 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1957 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1958 | if (!GetParam()->typeSupported()) { |
| 1959 | GTEST_SKIP(); |
| 1960 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1961 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1962 | fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1963 | } |
| 1964 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1965 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1966 | if (!GetParam()->typeSupported()) { |
| 1967 | GTEST_SKIP(); |
| 1968 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1969 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1970 | fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1971 | } |
| 1972 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1973 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1974 | if (!GetParam()->typeSupported()) { |
| 1975 | GTEST_SKIP(); |
| 1976 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1977 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1978 | fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1979 | } |
| 1980 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1981 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1982 | if (!GetParam()->typeSupported()) { |
| 1983 | GTEST_SKIP(); |
| 1984 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1985 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1986 | fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1987 | } |
| 1988 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1989 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1990 | if (!GetParam()->typeSupported()) { |
| 1991 | GTEST_SKIP(); |
| 1992 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1993 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1994 | fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1995 | } |
| 1996 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1997 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 1998 | if (!GetParam()->typeSupported()) { |
| 1999 | GTEST_SKIP(); |
| 2000 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2001 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2002 | fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2003 | } |
| 2004 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2005 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2006 | if (!GetParam()->typeSupported()) { |
| 2007 | GTEST_SKIP(); |
| 2008 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2009 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2010 | fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2011 | } |
| 2012 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2013 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2014 | if (!GetParam()->typeSupported()) { |
| 2015 | GTEST_SKIP(); |
| 2016 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2017 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2018 | fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2019 | } |
| 2020 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2021 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2022 | if (!GetParam()->typeSupported()) { |
| 2023 | GTEST_SKIP(); |
| 2024 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2025 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2026 | fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2027 | } |
| 2028 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2029 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2030 | if (!GetParam()->typeSupported()) { |
| 2031 | GTEST_SKIP(); |
| 2032 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2033 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2034 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2035 | } |
| 2036 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2037 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2038 | if (!GetParam()->typeSupported()) { |
| 2039 | GTEST_SKIP(); |
| 2040 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2041 | initializeRenderEngine(); |
KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 2042 | fillBufferColorTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2043 | } |
| 2044 | |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 2045 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndSourceDataspace_bufferSource) { |
| 2046 | const auto& renderEngineFactory = GetParam(); |
| 2047 | // skip for non color management |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2048 | if (!renderEngineFactory->typeSupported() || !renderEngineFactory->useColorManagement()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 2049 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | initializeRenderEngine(); |
| 2053 | fillBufferColorTransformAndSourceDataspace<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2054 | } |
| 2055 | |
| 2056 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndOutputDataspace_bufferSource) { |
| 2057 | const auto& renderEngineFactory = GetParam(); |
| 2058 | // skip for non color management |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2059 | if (!renderEngineFactory->typeSupported() || !renderEngineFactory->useColorManagement()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 2060 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 2061 | } |
| 2062 | |
| 2063 | initializeRenderEngine(); |
| 2064 | fillBufferColorTransformAndOutputDataspace<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2065 | } |
| 2066 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2067 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2068 | if (!GetParam()->typeSupported()) { |
| 2069 | GTEST_SKIP(); |
| 2070 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2071 | initializeRenderEngine(); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 2072 | fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2073 | } |
| 2074 | |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 2075 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2076 | if (!GetParam()->typeSupported()) { |
| 2077 | GTEST_SKIP(); |
| 2078 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2079 | initializeRenderEngine(); |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 2080 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2081 | } |
| 2082 | |
Nathaniel Nifong | 53494f3 | 2021-04-30 14:05:39 -0400 | [diff] [blame] | 2083 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2084 | if (!GetParam()->typeSupported()) { |
| 2085 | GTEST_SKIP(); |
| 2086 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2087 | initializeRenderEngine(); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 2088 | fillBufferAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2089 | } |
| 2090 | |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 2091 | TEST_P(RenderEngineTest, drawLayers_fillSmallLayerAndBlurBackground_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2092 | if (!GetParam()->typeSupported()) { |
| 2093 | GTEST_SKIP(); |
| 2094 | } |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 2095 | initializeRenderEngine(); |
| 2096 | fillSmallLayerAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2097 | } |
| 2098 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2099 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_bufferSource) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2100 | if (!GetParam()->typeSupported()) { |
| 2101 | GTEST_SKIP(); |
| 2102 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2103 | initializeRenderEngine(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 2104 | overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2105 | } |
| 2106 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2107 | TEST_P(RenderEngineTest, drawLayers_fillBufferTextureTransform) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2108 | if (!GetParam()->typeSupported()) { |
| 2109 | GTEST_SKIP(); |
| 2110 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2111 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2112 | fillBufferTextureTransform(); |
| 2113 | } |
| 2114 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2115 | TEST_P(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2116 | if (!GetParam()->typeSupported()) { |
| 2117 | GTEST_SKIP(); |
| 2118 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2119 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2120 | fillBufferWithPremultiplyAlpha(); |
| 2121 | } |
| 2122 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2123 | TEST_P(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2124 | if (!GetParam()->typeSupported()) { |
| 2125 | GTEST_SKIP(); |
| 2126 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2127 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2128 | fillBufferWithoutPremultiplyAlpha(); |
| 2129 | } |
| 2130 | |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 2131 | TEST_P(RenderEngineTest, drawLayers_fillShadow_castsWithoutCasterLayer) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2132 | if (!GetParam()->typeSupported()) { |
| 2133 | GTEST_SKIP(); |
| 2134 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2135 | initializeRenderEngine(); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 2136 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2137 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2138 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 2139 | const float shadowLength = 5.0f; |
| 2140 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2141 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2142 | renderengine::ShadowSettings settings = |
| 2143 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 2144 | false /* casterIsTranslucent */); |
| 2145 | |
| 2146 | drawShadowWithoutCaster(casterBounds.toFloatRect(), settings, backgroundColor); |
| 2147 | expectShadowColorWithoutCaster(casterBounds.toFloatRect(), settings, backgroundColor); |
| 2148 | } |
| 2149 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2150 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterLayerMinSize) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2151 | if (!GetParam()->typeSupported()) { |
| 2152 | GTEST_SKIP(); |
| 2153 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2154 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2155 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2156 | const ubyte4 casterColor(static_cast<uint8_t>(255), static_cast<uint8_t>(0), |
| 2157 | static_cast<uint8_t>(0), static_cast<uint8_t>(255)); |
| 2158 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2159 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2160 | const float shadowLength = 5.0f; |
| 2161 | Rect casterBounds(1, 1); |
| 2162 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2163 | renderengine::LayerSettings castingLayer; |
| 2164 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 2165 | castingLayer.alpha = 1.0f; |
| 2166 | renderengine::ShadowSettings settings = |
| 2167 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 2168 | false /* casterIsTranslucent */); |
| 2169 | |
| 2170 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 2171 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 2172 | } |
| 2173 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2174 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterColorLayer) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2175 | if (!GetParam()->typeSupported()) { |
| 2176 | GTEST_SKIP(); |
| 2177 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2178 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2179 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2180 | const ubyte4 casterColor(static_cast<uint8_t>(255), static_cast<uint8_t>(0), |
| 2181 | static_cast<uint8_t>(0), static_cast<uint8_t>(255)); |
| 2182 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2183 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2184 | const float shadowLength = 5.0f; |
| 2185 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2186 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2187 | renderengine::LayerSettings castingLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 2188 | castingLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2189 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 2190 | castingLayer.alpha = 1.0f; |
| 2191 | renderengine::ShadowSettings settings = |
| 2192 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 2193 | false /* casterIsTranslucent */); |
| 2194 | |
| 2195 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 2196 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 2197 | } |
| 2198 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2199 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterOpaqueBufferLayer) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2200 | if (!GetParam()->typeSupported()) { |
| 2201 | GTEST_SKIP(); |
| 2202 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2203 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2204 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2205 | const ubyte4 casterColor(static_cast<uint8_t>(255), static_cast<uint8_t>(0), |
| 2206 | static_cast<uint8_t>(0), static_cast<uint8_t>(255)); |
| 2207 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2208 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2209 | const float shadowLength = 5.0f; |
| 2210 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2211 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2212 | renderengine::LayerSettings castingLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 2213 | castingLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2214 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 2215 | castingLayer.alpha = 1.0f; |
| 2216 | renderengine::ShadowSettings settings = |
| 2217 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 2218 | false /* casterIsTranslucent */); |
| 2219 | |
| 2220 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 2221 | backgroundColor); |
| 2222 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 2223 | } |
| 2224 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2225 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterWithRoundedCorner) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2226 | if (!GetParam()->typeSupported()) { |
| 2227 | GTEST_SKIP(); |
| 2228 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2229 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2230 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2231 | const ubyte4 casterColor(static_cast<uint8_t>(255), static_cast<uint8_t>(0), |
| 2232 | static_cast<uint8_t>(0), static_cast<uint8_t>(255)); |
| 2233 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2234 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2235 | const float shadowLength = 5.0f; |
| 2236 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2237 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2238 | renderengine::LayerSettings castingLayer; |
| 2239 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2240 | castingLayer.geometry.roundedCornersRadius = {3.0f, 3.0f}; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2241 | castingLayer.geometry.roundedCornersCrop = casterBounds.toFloatRect(); |
| 2242 | castingLayer.alpha = 1.0f; |
| 2243 | renderengine::ShadowSettings settings = |
| 2244 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 2245 | false /* casterIsTranslucent */); |
| 2246 | |
| 2247 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 2248 | backgroundColor); |
| 2249 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 2250 | } |
| 2251 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2252 | TEST_P(RenderEngineTest, drawLayers_fillShadow_translucentCasterWithAlpha) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2253 | if (!GetParam()->typeSupported()) { |
| 2254 | GTEST_SKIP(); |
| 2255 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2256 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2257 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2258 | const ubyte4 casterColor(255, 0, 0, 255); |
| 2259 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 2260 | const float shadowLength = 5.0f; |
| 2261 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2262 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2263 | renderengine::LayerSettings castingLayer; |
| 2264 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 2265 | castingLayer.alpha = 0.5f; |
| 2266 | renderengine::ShadowSettings settings = |
| 2267 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 2268 | true /* casterIsTranslucent */); |
| 2269 | |
| 2270 | drawShadow<BufferSourceVariant<RelaxOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 2271 | backgroundColor); |
| 2272 | |
| 2273 | // verify only the background since the shadow will draw behind the caster |
| 2274 | const float shadowInset = settings.length * -1.0f; |
| 2275 | const Rect casterWithShadow = |
| 2276 | Rect(casterBounds).inset(shadowInset, shadowInset, shadowInset, shadowInset); |
| 2277 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); |
| 2278 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, |
| 2279 | backgroundColor.a); |
| 2280 | } |
| 2281 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2282 | TEST_P(RenderEngineTest, cleanupPostRender_cleansUpOnce) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2283 | if (!GetParam()->typeSupported()) { |
| 2284 | GTEST_SKIP(); |
| 2285 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2286 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2287 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2288 | renderengine::DisplaySettings settings; |
| 2289 | settings.physicalDisplay = fullscreenRect(); |
| 2290 | settings.clip = fullscreenRect(); |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 2291 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2292 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2293 | std::vector<renderengine::LayerSettings> layers; |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2294 | renderengine::LayerSettings layer; |
| 2295 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 2296 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 2297 | layer.alpha = 1.0; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2298 | layers.push_back(layer); |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2299 | |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 2300 | ftl::Future<FenceResult> futureOne = |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 2301 | mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd()); |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 2302 | ASSERT_TRUE(futureOne.valid()); |
| 2303 | auto resultOne = futureOne.get(); |
| 2304 | ASSERT_TRUE(resultOne.ok()); |
| 2305 | auto fenceOne = resultOne.value(); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 2306 | |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 2307 | ftl::Future<FenceResult> futureTwo = |
| 2308 | mRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd(fenceOne->dup())); |
| 2309 | ASSERT_TRUE(futureTwo.valid()); |
| 2310 | auto resultTwo = futureTwo.get(); |
| 2311 | ASSERT_TRUE(resultTwo.ok()); |
| 2312 | auto fenceTwo = resultTwo.value(); |
| 2313 | fenceTwo->waitForever(LOG_TAG); |
Derek Sollenberger | ec41121 | 2021-08-25 10:54:47 -0400 | [diff] [blame] | 2314 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2315 | // Only cleanup the first time. |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2316 | if (mRE->canSkipPostRenderCleanup()) { |
| 2317 | // Skia's Vk backend may keep the texture alive beyond drawLayersInternal, so |
| 2318 | // it never gets added to the cleanup list. In those cases, we can skip. |
| 2319 | EXPECT_TRUE(GetParam()->type() == renderengine::RenderEngine::RenderEngineType::SKIA_VK); |
| 2320 | } else { |
| 2321 | mRE->cleanupPostRender(); |
| 2322 | EXPECT_TRUE(mRE->canSkipPostRenderCleanup()); |
| 2323 | } |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2326 | TEST_P(RenderEngineTest, testRoundedCornersCrop) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2327 | if (!GetParam()->typeSupported()) { |
| 2328 | GTEST_SKIP(); |
| 2329 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2330 | initializeRenderEngine(); |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2331 | |
| 2332 | renderengine::DisplaySettings settings; |
| 2333 | settings.physicalDisplay = fullscreenRect(); |
| 2334 | settings.clip = fullscreenRect(); |
| 2335 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2336 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2337 | std::vector<renderengine::LayerSettings> layers; |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2338 | |
| 2339 | renderengine::LayerSettings redLayer; |
| 2340 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2341 | redLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2342 | redLayer.geometry.roundedCornersRadius = {5.0f, 5.0f}; |
| 2343 | |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2344 | redLayer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 2345 | // Red background. |
| 2346 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 2347 | redLayer.alpha = 1.0f; |
| 2348 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2349 | layers.push_back(redLayer); |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2350 | |
| 2351 | // Green layer with 1/3 size. |
| 2352 | renderengine::LayerSettings greenLayer; |
| 2353 | greenLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2354 | greenLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2355 | greenLayer.geometry.roundedCornersRadius = {5.0f, 5.0f}; |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2356 | // Bottom right corner is not going to be rounded. |
| 2357 | greenLayer.geometry.roundedCornersCrop = |
| 2358 | Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3, DEFAULT_DISPLAY_HEIGHT, |
| 2359 | DEFAULT_DISPLAY_HEIGHT) |
| 2360 | .toFloatRect(); |
| 2361 | greenLayer.source.solidColor = half3(0.0f, 1.0f, 0.0f); |
| 2362 | greenLayer.alpha = 1.0f; |
| 2363 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2364 | layers.push_back(greenLayer); |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2365 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2366 | invokeDraw(settings, layers); |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2367 | |
| 2368 | // Corners should be ignored... |
| 2369 | // Screen size: width is 128, height is 256. |
| 2370 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); |
| 2371 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); |
| 2372 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 2373 | // Bottom right corner is kept out of the clipping, and it's green. |
| 2374 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, |
| 2375 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 2376 | 0, 255, 0, 255); |
| 2377 | } |
| 2378 | |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2379 | TEST_P(RenderEngineTest, testRoundedCornersParentCrop) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2380 | if (!GetParam()->typeSupported()) { |
| 2381 | GTEST_SKIP(); |
| 2382 | } |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2383 | initializeRenderEngine(); |
| 2384 | |
| 2385 | renderengine::DisplaySettings settings; |
| 2386 | settings.physicalDisplay = fullscreenRect(); |
| 2387 | settings.clip = fullscreenRect(); |
| 2388 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2389 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2390 | std::vector<renderengine::LayerSettings> layers; |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2391 | |
| 2392 | renderengine::LayerSettings redLayer; |
| 2393 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2394 | redLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2395 | redLayer.geometry.roundedCornersRadius = {5.0f, 5.0f}; |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2396 | redLayer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 2397 | // Red background. |
| 2398 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 2399 | redLayer.alpha = 1.0f; |
| 2400 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2401 | layers.push_back(redLayer); |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2402 | |
| 2403 | // Green layer with 1/2 size with parent crop rect. |
| 2404 | renderengine::LayerSettings greenLayer = redLayer; |
| 2405 | greenLayer.geometry.boundaries = |
| 2406 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2); |
| 2407 | greenLayer.source.solidColor = half3(0.0f, 1.0f, 0.0f); |
| 2408 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2409 | layers.push_back(greenLayer); |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2410 | |
| 2411 | invokeDraw(settings, layers); |
| 2412 | |
| 2413 | // Due to roundedCornersRadius, the corners are untouched. |
| 2414 | expectBufferColor(Point(0, 0), 0, 0, 0, 0); |
| 2415 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 0), 0, 0, 0, 0); |
| 2416 | expectBufferColor(Point(0, DEFAULT_DISPLAY_HEIGHT - 1), 0, 0, 0, 0); |
| 2417 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1), 0, 0, 0, 0); |
| 2418 | |
| 2419 | // top middle should be green and the bottom middle red |
| 2420 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH / 2, 0), 0, 255, 0, 255); |
| 2421 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, 255); |
| 2422 | |
| 2423 | // the bottom edge of the green layer should not be rounded |
| 2424 | expectBufferColor(Point(0, (DEFAULT_DISPLAY_HEIGHT / 2) - 1), 0, 255, 0, 255); |
| 2425 | } |
| 2426 | |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2427 | TEST_P(RenderEngineTest, testRoundedCornersParentCropSmallBounds) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2428 | if (!GetParam()->typeSupported()) { |
| 2429 | GTEST_SKIP(); |
| 2430 | } |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2431 | initializeRenderEngine(); |
| 2432 | |
| 2433 | renderengine::DisplaySettings settings; |
| 2434 | settings.physicalDisplay = fullscreenRect(); |
| 2435 | settings.clip = fullscreenRect(); |
| 2436 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2437 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2438 | std::vector<renderengine::LayerSettings> layers; |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2439 | |
| 2440 | renderengine::LayerSettings redLayer; |
| 2441 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2442 | redLayer.geometry.boundaries = FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH, 32); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2443 | redLayer.geometry.roundedCornersRadius = {64.0f, 64.0f}; |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2444 | redLayer.geometry.roundedCornersCrop = FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH, 128); |
| 2445 | // Red background. |
| 2446 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 2447 | redLayer.alpha = 1.0f; |
| 2448 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2449 | layers.push_back(redLayer); |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2450 | invokeDraw(settings, layers); |
| 2451 | |
| 2452 | // Due to roundedCornersRadius, the top corners are untouched. |
| 2453 | expectBufferColor(Point(0, 0), 0, 0, 0, 0); |
| 2454 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 0), 0, 0, 0, 0); |
| 2455 | |
| 2456 | // ensure that the entire height of the red layer was clipped by the rounded corners crop. |
| 2457 | expectBufferColor(Point(0, 31), 0, 0, 0, 0); |
| 2458 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 31), 0, 0, 0, 0); |
| 2459 | |
| 2460 | // the bottom middle should be red |
| 2461 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH / 2, 31), 255, 0, 0, 255); |
| 2462 | } |
| 2463 | |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2464 | TEST_P(RenderEngineTest, testRoundedCornersXY) { |
| 2465 | if (GetParam()->type() != renderengine::RenderEngine::RenderEngineType::SKIA_GL) { |
| 2466 | GTEST_SKIP(); |
| 2467 | } |
| 2468 | |
| 2469 | initializeRenderEngine(); |
| 2470 | |
| 2471 | renderengine::DisplaySettings settings; |
| 2472 | settings.physicalDisplay = fullscreenRect(); |
| 2473 | settings.clip = fullscreenRect(); |
| 2474 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2475 | |
| 2476 | std::vector<renderengine::LayerSettings> layers; |
| 2477 | |
| 2478 | renderengine::LayerSettings redLayer; |
| 2479 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2480 | redLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 2481 | redLayer.geometry.roundedCornersRadius = {5.0f, 20.0f}; |
| 2482 | redLayer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 2483 | // Red background. |
| 2484 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 2485 | redLayer.alpha = 1.0f; |
| 2486 | |
| 2487 | layers.push_back(redLayer); |
| 2488 | |
| 2489 | invokeDraw(settings, layers); |
| 2490 | |
| 2491 | // Due to roundedCornersRadius, the corners are untouched. |
| 2492 | expectBufferColor(Point(0, 0), 0, 0, 0, 0); |
| 2493 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 0), 0, 0, 0, 0); |
| 2494 | expectBufferColor(Point(0, DEFAULT_DISPLAY_HEIGHT - 1), 0, 0, 0, 0); |
| 2495 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1), 0, 0, 0, 0); |
| 2496 | |
| 2497 | // Y-axis draws a larger radius, check that its untouched as well |
| 2498 | expectBufferColor(Point(0, DEFAULT_DISPLAY_HEIGHT - 5), 0, 0, 0, 0); |
| 2499 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 5), 0, 0, 0, 0); |
| 2500 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 5), 0, 0, 0, 0); |
| 2501 | expectBufferColor(Point(0, 5), 0, 0, 0, 0); |
| 2502 | |
| 2503 | // middle should be red |
| 2504 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, 255); |
| 2505 | } |
| 2506 | |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2507 | TEST_P(RenderEngineTest, testClear) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2508 | if (!GetParam()->typeSupported()) { |
| 2509 | GTEST_SKIP(); |
| 2510 | } |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2511 | initializeRenderEngine(); |
| 2512 | |
| 2513 | const auto rect = fullscreenRect(); |
| 2514 | const renderengine::DisplaySettings display{ |
| 2515 | .physicalDisplay = rect, |
| 2516 | .clip = rect, |
| 2517 | }; |
| 2518 | |
| 2519 | const renderengine::LayerSettings redLayer{ |
| 2520 | .geometry.boundaries = rect.toFloatRect(), |
| 2521 | .source.solidColor = half3(1.0f, 0.0f, 0.0f), |
| 2522 | .alpha = 1.0f, |
| 2523 | }; |
| 2524 | |
| 2525 | // This mimics prepareClearClientComposition. This layer should overwrite |
| 2526 | // the redLayer, so that the buffer is transparent, rather than red. |
| 2527 | const renderengine::LayerSettings clearLayer{ |
| 2528 | .geometry.boundaries = rect.toFloatRect(), |
| 2529 | .source.solidColor = half3(0.0f, 0.0f, 0.0f), |
| 2530 | .alpha = 0.0f, |
| 2531 | .disableBlending = true, |
| 2532 | }; |
| 2533 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2534 | std::vector<renderengine::LayerSettings> layers{redLayer, clearLayer}; |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2535 | invokeDraw(display, layers); |
| 2536 | expectBufferColor(rect, 0, 0, 0, 0); |
| 2537 | } |
| 2538 | |
| 2539 | TEST_P(RenderEngineTest, testDisableBlendingBuffer) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2540 | if (!GetParam()->typeSupported()) { |
| 2541 | GTEST_SKIP(); |
| 2542 | } |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2543 | initializeRenderEngine(); |
| 2544 | |
| 2545 | const auto rect = Rect(0, 0, 1, 1); |
| 2546 | const renderengine::DisplaySettings display{ |
| 2547 | .physicalDisplay = rect, |
| 2548 | .clip = rect, |
| 2549 | }; |
| 2550 | |
| 2551 | const renderengine::LayerSettings redLayer{ |
| 2552 | .geometry.boundaries = rect.toFloatRect(), |
| 2553 | .source.solidColor = half3(1.0f, 0.0f, 0.0f), |
| 2554 | .alpha = 1.0f, |
| 2555 | }; |
| 2556 | |
| 2557 | // The next layer will overwrite redLayer with a GraphicBuffer that is green |
| 2558 | // applied with a translucent alpha. |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 2559 | const auto buf = allocateSourceBuffer(1, 1); |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2560 | { |
| 2561 | uint8_t* pixels; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 2562 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 2563 | reinterpret_cast<void**>(&pixels)); |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2564 | pixels[0] = 0; |
| 2565 | pixels[1] = 255; |
| 2566 | pixels[2] = 0; |
| 2567 | pixels[3] = 255; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 2568 | buf->getBuffer()->unlock(); |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | const renderengine::LayerSettings greenLayer{ |
| 2572 | .geometry.boundaries = rect.toFloatRect(), |
| 2573 | .source = |
| 2574 | renderengine::PixelSource{ |
| 2575 | .buffer = |
| 2576 | renderengine::Buffer{ |
| 2577 | .buffer = buf, |
| 2578 | .usePremultipliedAlpha = true, |
| 2579 | }, |
| 2580 | }, |
| 2581 | .alpha = 0.5f, |
| 2582 | .disableBlending = true, |
| 2583 | }; |
| 2584 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2585 | std::vector<renderengine::LayerSettings> layers{redLayer, greenLayer}; |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2586 | invokeDraw(display, layers); |
| 2587 | expectBufferColor(rect, 0, 128, 0, 128); |
| 2588 | } |
| 2589 | |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2590 | TEST_P(RenderEngineTest, testBorder) { |
| 2591 | if (GetParam()->type() != renderengine::RenderEngine::RenderEngineType::SKIA_GL) { |
| 2592 | GTEST_SKIP(); |
| 2593 | } |
| 2594 | |
| 2595 | if (!GetParam()->useColorManagement()) { |
| 2596 | GTEST_SKIP(); |
| 2597 | } |
| 2598 | |
| 2599 | initializeRenderEngine(); |
| 2600 | |
| 2601 | const ui::Dataspace dataspace = ui::Dataspace::V0_SRGB; |
| 2602 | |
| 2603 | const auto displayRect = Rect(1080, 2280); |
| 2604 | renderengine::DisplaySettings display{ |
| 2605 | .physicalDisplay = displayRect, |
| 2606 | .clip = displayRect, |
| 2607 | .outputDataspace = dataspace, |
| 2608 | }; |
| 2609 | display.borderInfoList.clear(); |
| 2610 | renderengine::BorderRenderInfo info; |
| 2611 | info.combinedRegion = Region(Rect(99, 99, 199, 199)); |
Tianhao Yao | 10cea3c | 2022-03-30 01:37:22 +0000 | [diff] [blame] | 2612 | info.width = 20.0f; |
| 2613 | info.color = half4{1.0f, 128.0f / 255.0f, 0.0f, 1.0f}; |
Tianhao Yao | 67dd712 | 2022-02-22 17:48:33 +0000 | [diff] [blame] | 2614 | display.borderInfoList.emplace_back(info); |
| 2615 | |
| 2616 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2617 | const renderengine::LayerSettings greenLayer{ |
| 2618 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2619 | .source = |
| 2620 | renderengine::PixelSource{ |
| 2621 | .buffer = |
| 2622 | renderengine::Buffer{ |
| 2623 | .buffer = greenBuffer, |
| 2624 | .usePremultipliedAlpha = true, |
| 2625 | }, |
| 2626 | }, |
| 2627 | .alpha = 1.0f, |
| 2628 | .sourceDataspace = dataspace, |
| 2629 | .whitePointNits = 200.f, |
| 2630 | }; |
| 2631 | |
| 2632 | std::vector<renderengine::LayerSettings> layers; |
| 2633 | layers.emplace_back(greenLayer); |
| 2634 | invokeDraw(display, layers); |
| 2635 | |
| 2636 | expectBufferColor(Rect(99, 99, 101, 101), 255, 128, 0, 255, 1); |
| 2637 | } |
| 2638 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2639 | TEST_P(RenderEngineTest, testDimming) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2640 | if (!GetParam()->typeSupported()) { |
| 2641 | GTEST_SKIP(); |
| 2642 | } |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2643 | initializeRenderEngine(); |
| 2644 | |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2645 | const ui::Dataspace dataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2646 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2647 | const auto displayRect = Rect(3, 1); |
| 2648 | const renderengine::DisplaySettings display{ |
| 2649 | .physicalDisplay = displayRect, |
| 2650 | .clip = displayRect, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2651 | .outputDataspace = dataspace, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2652 | .targetLuminanceNits = 1000.f, |
| 2653 | }; |
| 2654 | |
| 2655 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2656 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2657 | const auto redBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(255, 0, 0, 255)); |
| 2658 | |
| 2659 | const renderengine::LayerSettings greenLayer{ |
| 2660 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2661 | .source = |
| 2662 | renderengine::PixelSource{ |
| 2663 | .buffer = |
| 2664 | renderengine::Buffer{ |
| 2665 | .buffer = greenBuffer, |
| 2666 | .usePremultipliedAlpha = true, |
| 2667 | }, |
| 2668 | }, |
| 2669 | .alpha = 1.0f, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2670 | .sourceDataspace = dataspace, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2671 | .whitePointNits = 200.f, |
| 2672 | }; |
| 2673 | |
| 2674 | const renderengine::LayerSettings blueLayer{ |
| 2675 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2676 | .source = |
| 2677 | renderengine::PixelSource{ |
| 2678 | .buffer = |
| 2679 | renderengine::Buffer{ |
| 2680 | .buffer = blueBuffer, |
| 2681 | .usePremultipliedAlpha = true, |
| 2682 | }, |
| 2683 | }, |
| 2684 | .alpha = 1.0f, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2685 | .sourceDataspace = dataspace, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2686 | .whitePointNits = 1000.f / 51.f, |
| 2687 | }; |
| 2688 | |
| 2689 | const renderengine::LayerSettings redLayer{ |
| 2690 | .geometry.boundaries = FloatRect(2.f, 0.f, 3.f, 1.f), |
| 2691 | .source = |
| 2692 | renderengine::PixelSource{ |
| 2693 | .buffer = |
| 2694 | renderengine::Buffer{ |
| 2695 | .buffer = redBuffer, |
| 2696 | .usePremultipliedAlpha = true, |
| 2697 | }, |
| 2698 | }, |
| 2699 | .alpha = 1.0f, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2700 | .sourceDataspace = dataspace, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2701 | // When the white point is not set for a layer, just ignore it and treat it as the same |
| 2702 | // as the max layer |
| 2703 | .whitePointNits = -1.f, |
| 2704 | }; |
| 2705 | |
| 2706 | std::vector<renderengine::LayerSettings> layers{greenLayer, blueLayer, redLayer}; |
| 2707 | invokeDraw(display, layers); |
| 2708 | |
| 2709 | expectBufferColor(Rect(1, 1), 0, 51, 0, 255, 1); |
| 2710 | expectBufferColor(Rect(1, 0, 2, 1), 0, 0, 5, 255, 1); |
| 2711 | expectBufferColor(Rect(2, 0, 3, 1), 51, 0, 0, 255, 1); |
| 2712 | } |
| 2713 | |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2714 | TEST_P(RenderEngineTest, testDimming_inGammaSpace) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2715 | if (!GetParam()->typeSupported()) { |
| 2716 | GTEST_SKIP(); |
| 2717 | } |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2718 | initializeRenderEngine(); |
| 2719 | |
| 2720 | const ui::Dataspace dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_BT709 | |
| 2721 | ui::Dataspace::TRANSFER_GAMMA2_2 | |
| 2722 | ui::Dataspace::RANGE_FULL); |
| 2723 | |
| 2724 | const auto displayRect = Rect(3, 1); |
| 2725 | const renderengine::DisplaySettings display{ |
| 2726 | .physicalDisplay = displayRect, |
| 2727 | .clip = displayRect, |
| 2728 | .outputDataspace = dataspace, |
| 2729 | .targetLuminanceNits = 1000.f, |
| 2730 | .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF, |
| 2731 | }; |
| 2732 | |
| 2733 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2734 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2735 | const auto redBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(255, 0, 0, 255)); |
| 2736 | |
| 2737 | const renderengine::LayerSettings greenLayer{ |
| 2738 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2739 | .source = |
| 2740 | renderengine::PixelSource{ |
| 2741 | .buffer = |
| 2742 | renderengine::Buffer{ |
| 2743 | .buffer = greenBuffer, |
| 2744 | .usePremultipliedAlpha = true, |
| 2745 | }, |
| 2746 | }, |
| 2747 | .alpha = 1.0f, |
| 2748 | .sourceDataspace = dataspace, |
| 2749 | .whitePointNits = 200.f, |
| 2750 | }; |
| 2751 | |
| 2752 | const renderengine::LayerSettings blueLayer{ |
| 2753 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2754 | .source = |
| 2755 | renderengine::PixelSource{ |
| 2756 | .buffer = |
| 2757 | renderengine::Buffer{ |
| 2758 | .buffer = blueBuffer, |
| 2759 | .usePremultipliedAlpha = true, |
| 2760 | }, |
| 2761 | }, |
| 2762 | .alpha = 1.0f, |
| 2763 | .sourceDataspace = dataspace, |
| 2764 | .whitePointNits = 1000.f / 51.f, |
| 2765 | }; |
| 2766 | |
| 2767 | const renderengine::LayerSettings redLayer{ |
| 2768 | .geometry.boundaries = FloatRect(2.f, 0.f, 3.f, 1.f), |
| 2769 | .source = |
| 2770 | renderengine::PixelSource{ |
| 2771 | .buffer = |
| 2772 | renderengine::Buffer{ |
| 2773 | .buffer = redBuffer, |
| 2774 | .usePremultipliedAlpha = true, |
| 2775 | }, |
| 2776 | }, |
| 2777 | .alpha = 1.0f, |
| 2778 | .sourceDataspace = dataspace, |
| 2779 | // When the white point is not set for a layer, just ignore it and treat it as the same |
| 2780 | // as the max layer |
| 2781 | .whitePointNits = -1.f, |
| 2782 | }; |
| 2783 | |
| 2784 | std::vector<renderengine::LayerSettings> layers{greenLayer, blueLayer, redLayer}; |
| 2785 | invokeDraw(display, layers); |
| 2786 | |
| 2787 | expectBufferColor(Rect(1, 1), 0, 122, 0, 255, 1); |
| 2788 | expectBufferColor(Rect(1, 0, 2, 1), 0, 0, 42, 255, 1); |
| 2789 | expectBufferColor(Rect(2, 0, 3, 1), 122, 0, 0, 255, 1); |
| 2790 | } |
| 2791 | |
Alec Mouri | 9bcd1d1 | 2022-04-21 22:16:56 +0000 | [diff] [blame] | 2792 | TEST_P(RenderEngineTest, testDimming_inGammaSpace_withDisplayColorTransform) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2793 | if (!GetParam()->typeSupported()) { |
| 2794 | GTEST_SKIP(); |
| 2795 | } |
Alec Mouri | 9bcd1d1 | 2022-04-21 22:16:56 +0000 | [diff] [blame] | 2796 | initializeRenderEngine(); |
| 2797 | |
| 2798 | const ui::Dataspace dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_BT709 | |
| 2799 | ui::Dataspace::TRANSFER_GAMMA2_2 | |
| 2800 | ui::Dataspace::RANGE_FULL); |
| 2801 | |
| 2802 | const auto displayRect = Rect(3, 1); |
| 2803 | const renderengine::DisplaySettings display{ |
| 2804 | .physicalDisplay = displayRect, |
| 2805 | .clip = displayRect, |
| 2806 | .outputDataspace = dataspace, |
| 2807 | .colorTransform = kRemoveGreenAndMoveRedToGreenMat4, |
| 2808 | .targetLuminanceNits = 1000.f, |
| 2809 | .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF, |
| 2810 | }; |
| 2811 | |
| 2812 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2813 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2814 | const auto redBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(255, 0, 0, 255)); |
| 2815 | |
| 2816 | const renderengine::LayerSettings greenLayer{ |
| 2817 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2818 | .source = |
| 2819 | renderengine::PixelSource{ |
| 2820 | .buffer = |
| 2821 | renderengine::Buffer{ |
| 2822 | .buffer = greenBuffer, |
| 2823 | .usePremultipliedAlpha = true, |
| 2824 | }, |
| 2825 | }, |
| 2826 | .alpha = 1.0f, |
| 2827 | .sourceDataspace = dataspace, |
| 2828 | .whitePointNits = 200.f, |
| 2829 | }; |
| 2830 | |
| 2831 | const renderengine::LayerSettings redLayer{ |
| 2832 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2833 | .source = |
| 2834 | renderengine::PixelSource{ |
| 2835 | .buffer = |
| 2836 | renderengine::Buffer{ |
| 2837 | .buffer = redBuffer, |
| 2838 | .usePremultipliedAlpha = true, |
| 2839 | }, |
| 2840 | }, |
| 2841 | .alpha = 1.0f, |
| 2842 | .sourceDataspace = dataspace, |
| 2843 | // When the white point is not set for a layer, just ignore it and treat it as the same |
| 2844 | // as the max layer |
| 2845 | .whitePointNits = -1.f, |
| 2846 | }; |
| 2847 | |
| 2848 | std::vector<renderengine::LayerSettings> layers{greenLayer, redLayer}; |
| 2849 | invokeDraw(display, layers); |
| 2850 | |
| 2851 | expectBufferColor(Rect(1, 1), 0, 0, 0, 255, 1); |
| 2852 | expectBufferColor(Rect(1, 0, 2, 1), 0, 122, 0, 255, 1); |
| 2853 | } |
| 2854 | |
| 2855 | TEST_P(RenderEngineTest, testDimming_inGammaSpace_withDisplayColorTransform_deviceHandles) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2856 | if (!GetParam()->typeSupported()) { |
| 2857 | GTEST_SKIP(); |
| 2858 | } |
Alec Mouri | 9bcd1d1 | 2022-04-21 22:16:56 +0000 | [diff] [blame] | 2859 | initializeRenderEngine(); |
| 2860 | |
| 2861 | const ui::Dataspace dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_BT709 | |
| 2862 | ui::Dataspace::TRANSFER_GAMMA2_2 | |
| 2863 | ui::Dataspace::RANGE_FULL); |
| 2864 | |
| 2865 | const auto displayRect = Rect(3, 1); |
| 2866 | const renderengine::DisplaySettings display{ |
| 2867 | .physicalDisplay = displayRect, |
| 2868 | .clip = displayRect, |
| 2869 | .outputDataspace = dataspace, |
| 2870 | .colorTransform = kRemoveGreenAndMoveRedToGreenMat4, |
| 2871 | .deviceHandlesColorTransform = true, |
| 2872 | .targetLuminanceNits = 1000.f, |
| 2873 | .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF, |
| 2874 | }; |
| 2875 | |
| 2876 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2877 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2878 | const auto redBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(255, 0, 0, 255)); |
| 2879 | |
| 2880 | const renderengine::LayerSettings greenLayer{ |
| 2881 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2882 | .source = |
| 2883 | renderengine::PixelSource{ |
| 2884 | .buffer = |
| 2885 | renderengine::Buffer{ |
| 2886 | .buffer = greenBuffer, |
| 2887 | .usePremultipliedAlpha = true, |
| 2888 | }, |
| 2889 | }, |
| 2890 | .alpha = 1.0f, |
| 2891 | .sourceDataspace = dataspace, |
| 2892 | .whitePointNits = 200.f, |
| 2893 | }; |
| 2894 | |
| 2895 | const renderengine::LayerSettings redLayer{ |
| 2896 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2897 | .source = |
| 2898 | renderengine::PixelSource{ |
| 2899 | .buffer = |
| 2900 | renderengine::Buffer{ |
| 2901 | .buffer = redBuffer, |
| 2902 | .usePremultipliedAlpha = true, |
| 2903 | }, |
| 2904 | }, |
| 2905 | .alpha = 1.0f, |
| 2906 | .sourceDataspace = dataspace, |
| 2907 | // When the white point is not set for a layer, just ignore it and treat it as the same |
| 2908 | // as the max layer |
| 2909 | .whitePointNits = -1.f, |
| 2910 | }; |
| 2911 | |
| 2912 | std::vector<renderengine::LayerSettings> layers{greenLayer, redLayer}; |
| 2913 | invokeDraw(display, layers); |
| 2914 | |
| 2915 | expectBufferColor(Rect(1, 1), 0, 122, 0, 255, 1); |
| 2916 | expectBufferColor(Rect(1, 0, 2, 1), 122, 0, 0, 255, 1); |
| 2917 | } |
| 2918 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2919 | TEST_P(RenderEngineTest, testDimming_withoutTargetLuminance) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2920 | if (!GetParam()->typeSupported()) { |
| 2921 | GTEST_SKIP(); |
| 2922 | } |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2923 | initializeRenderEngine(); |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2924 | |
| 2925 | const auto displayRect = Rect(2, 1); |
| 2926 | const renderengine::DisplaySettings display{ |
| 2927 | .physicalDisplay = displayRect, |
| 2928 | .clip = displayRect, |
| 2929 | .outputDataspace = ui::Dataspace::V0_SRGB_LINEAR, |
| 2930 | .targetLuminanceNits = -1.f, |
| 2931 | }; |
| 2932 | |
| 2933 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2934 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2935 | |
| 2936 | const renderengine::LayerSettings greenLayer{ |
| 2937 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2938 | .source = |
| 2939 | renderengine::PixelSource{ |
| 2940 | .buffer = |
| 2941 | renderengine::Buffer{ |
| 2942 | .buffer = greenBuffer, |
| 2943 | .usePremultipliedAlpha = true, |
| 2944 | }, |
| 2945 | }, |
| 2946 | .alpha = 1.0f, |
| 2947 | .sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR, |
| 2948 | .whitePointNits = 200.f, |
| 2949 | }; |
| 2950 | |
| 2951 | const renderengine::LayerSettings blueLayer{ |
| 2952 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2953 | .source = |
| 2954 | renderengine::PixelSource{ |
| 2955 | .buffer = |
| 2956 | renderengine::Buffer{ |
| 2957 | .buffer = blueBuffer, |
| 2958 | .usePremultipliedAlpha = true, |
| 2959 | }, |
| 2960 | }, |
| 2961 | .alpha = 1.0f, |
| 2962 | .sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR, |
| 2963 | .whitePointNits = 1000.f, |
| 2964 | }; |
| 2965 | |
| 2966 | std::vector<renderengine::LayerSettings> layers{greenLayer, blueLayer}; |
| 2967 | invokeDraw(display, layers); |
| 2968 | |
| 2969 | expectBufferColor(Rect(1, 1), 0, 51, 0, 255, 1); |
| 2970 | expectBufferColor(Rect(1, 0, 2, 1), 0, 0, 255, 255); |
| 2971 | } |
| 2972 | |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 2973 | TEST_P(RenderEngineTest, test_isOpaque) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 2974 | if (!GetParam()->typeSupported()) { |
| 2975 | GTEST_SKIP(); |
| 2976 | } |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 2977 | initializeRenderEngine(); |
| 2978 | |
| 2979 | const auto rect = Rect(0, 0, 1, 1); |
| 2980 | const renderengine::DisplaySettings display{ |
| 2981 | .physicalDisplay = rect, |
| 2982 | .clip = rect, |
| 2983 | .outputDataspace = ui::Dataspace::DISPLAY_P3, |
| 2984 | }; |
| 2985 | |
| 2986 | // Create an unpremul buffer that is green with no alpha. Using isOpaque |
| 2987 | // should make the green show. |
| 2988 | const auto buf = allocateSourceBuffer(1, 1); |
| 2989 | { |
| 2990 | uint8_t* pixels; |
| 2991 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 2992 | reinterpret_cast<void**>(&pixels)); |
| 2993 | pixels[0] = 0; |
| 2994 | pixels[1] = 255; |
| 2995 | pixels[2] = 0; |
| 2996 | pixels[3] = 0; |
| 2997 | buf->getBuffer()->unlock(); |
| 2998 | } |
| 2999 | |
| 3000 | const renderengine::LayerSettings greenLayer{ |
| 3001 | .geometry.boundaries = rect.toFloatRect(), |
| 3002 | .source = |
| 3003 | renderengine::PixelSource{ |
| 3004 | .buffer = |
| 3005 | renderengine::Buffer{ |
| 3006 | .buffer = buf, |
| 3007 | // Although the pixels are not |
| 3008 | // premultiplied in practice, this |
| 3009 | // matches the input we see. |
| 3010 | .usePremultipliedAlpha = true, |
| 3011 | .isOpaque = true, |
| 3012 | }, |
| 3013 | }, |
| 3014 | .alpha = 1.0f, |
| 3015 | }; |
| 3016 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 3017 | std::vector<renderengine::LayerSettings> layers{greenLayer}; |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 3018 | invokeDraw(display, layers); |
| 3019 | |
| 3020 | if (GetParam()->useColorManagement()) { |
| 3021 | expectBufferColor(rect, 117, 251, 76, 255); |
| 3022 | } else { |
| 3023 | expectBufferColor(rect, 0, 255, 0, 255); |
| 3024 | } |
| 3025 | } |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 3026 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 3027 | TEST_P(RenderEngineTest, test_tonemapPQMatches) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 3028 | if (!GetParam()->typeSupported() || !GetParam()->useColorManagement()) { |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 3029 | GTEST_SKIP(); |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 3032 | initializeRenderEngine(); |
| 3033 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 3034 | tonemap( |
| 3035 | static_cast<ui::Dataspace>(HAL_DATASPACE_STANDARD_BT2020 | |
| 3036 | HAL_DATASPACE_TRANSFER_ST2084 | HAL_DATASPACE_RANGE_FULL), |
| 3037 | [](vec3 color) { return EOTF_PQ(color); }, |
| 3038 | [](vec3 color, float) { |
| 3039 | static constexpr float kMaxPQLuminance = 10000.f; |
| 3040 | return color * kMaxPQLuminance; |
| 3041 | }); |
| 3042 | } |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 3043 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 3044 | TEST_P(RenderEngineTest, test_tonemapHLGMatches) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 3045 | if (!GetParam()->typeSupported() || !GetParam()->useColorManagement()) { |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 3046 | GTEST_SKIP(); |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 3049 | initializeRenderEngine(); |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 3050 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 3051 | tonemap( |
| 3052 | static_cast<ui::Dataspace>(HAL_DATASPACE_STANDARD_BT2020 | HAL_DATASPACE_TRANSFER_HLG | |
| 3053 | HAL_DATASPACE_RANGE_FULL), |
| 3054 | [](vec3 color) { return EOTF_HLG(color); }, |
| 3055 | [](vec3 color, float currentLuminaceNits) { |
| 3056 | static constexpr float kMaxHLGLuminance = 1000.f; |
Alec Mouri | 7a57745 | 2022-03-04 23:41:38 +0000 | [diff] [blame] | 3057 | return color * kMaxHLGLuminance; |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 3058 | }); |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 3059 | } |
Leon Scroggins III | 2c1d9ef | 2022-01-21 13:46:56 -0500 | [diff] [blame] | 3060 | |
| 3061 | TEST_P(RenderEngineTest, r8_behaves_as_mask) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 3062 | if (!GetParam()->typeSupported()) { |
| 3063 | GTEST_SKIP(); |
| 3064 | } |
Leon Scroggins III | 2c1d9ef | 2022-01-21 13:46:56 -0500 | [diff] [blame] | 3065 | initializeRenderEngine(); |
| 3066 | |
| 3067 | const auto r8Buffer = allocateR8Buffer(2, 1); |
| 3068 | if (!r8Buffer) { |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 3069 | GTEST_SKIP() << "Test is only necessary on devices that support r8"; |
Leon Scroggins III | 2c1d9ef | 2022-01-21 13:46:56 -0500 | [diff] [blame] | 3070 | return; |
| 3071 | } |
| 3072 | { |
| 3073 | uint8_t* pixels; |
| 3074 | r8Buffer->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 3075 | reinterpret_cast<void**>(&pixels)); |
| 3076 | // This will be drawn on top of a green buffer. We'll verify that 255 |
| 3077 | // results in keeping the original green and 0 results in black. |
| 3078 | pixels[0] = 0; |
| 3079 | pixels[1] = 255; |
| 3080 | r8Buffer->getBuffer()->unlock(); |
| 3081 | } |
| 3082 | |
| 3083 | const auto rect = Rect(0, 0, 2, 1); |
| 3084 | const renderengine::DisplaySettings display{ |
| 3085 | .physicalDisplay = rect, |
| 3086 | .clip = rect, |
| 3087 | .outputDataspace = ui::Dataspace::SRGB, |
| 3088 | }; |
| 3089 | |
| 3090 | const auto greenBuffer = allocateAndFillSourceBuffer(2, 1, ubyte4(0, 255, 0, 255)); |
| 3091 | const renderengine::LayerSettings greenLayer{ |
| 3092 | .geometry.boundaries = rect.toFloatRect(), |
| 3093 | .source = |
| 3094 | renderengine::PixelSource{ |
| 3095 | .buffer = |
| 3096 | renderengine::Buffer{ |
| 3097 | .buffer = greenBuffer, |
| 3098 | }, |
| 3099 | }, |
| 3100 | .alpha = 1.0f, |
| 3101 | }; |
| 3102 | const renderengine::LayerSettings r8Layer{ |
| 3103 | .geometry.boundaries = rect.toFloatRect(), |
| 3104 | .source = |
| 3105 | renderengine::PixelSource{ |
| 3106 | .buffer = |
| 3107 | renderengine::Buffer{ |
| 3108 | .buffer = r8Buffer, |
| 3109 | }, |
| 3110 | }, |
| 3111 | .alpha = 1.0f, |
| 3112 | }; |
| 3113 | |
| 3114 | std::vector<renderengine::LayerSettings> layers{greenLayer, r8Layer}; |
| 3115 | invokeDraw(display, layers); |
| 3116 | |
| 3117 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 255); |
| 3118 | expectBufferColor(Rect(1, 0, 2, 1), 0, 255, 0, 255); |
| 3119 | } |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 3120 | |
| 3121 | TEST_P(RenderEngineTest, r8_respects_color_transform) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 3122 | if (!GetParam()->typeSupported()) { |
| 3123 | GTEST_SKIP(); |
| 3124 | } |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 3125 | initializeRenderEngine(); |
| 3126 | |
| 3127 | const auto r8Buffer = allocateR8Buffer(2, 1); |
| 3128 | if (!r8Buffer) { |
| 3129 | GTEST_SKIP() << "Test is only necessary on devices that support r8"; |
| 3130 | return; |
| 3131 | } |
| 3132 | { |
| 3133 | uint8_t* pixels; |
| 3134 | r8Buffer->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 3135 | reinterpret_cast<void**>(&pixels)); |
| 3136 | pixels[0] = 0; |
| 3137 | pixels[1] = 255; |
| 3138 | r8Buffer->getBuffer()->unlock(); |
| 3139 | } |
| 3140 | |
| 3141 | const auto rect = Rect(0, 0, 2, 1); |
| 3142 | const renderengine::DisplaySettings display{ |
| 3143 | .physicalDisplay = rect, |
| 3144 | .clip = rect, |
| 3145 | .outputDataspace = ui::Dataspace::SRGB, |
| 3146 | // Verify that the R8 layer respects the color transform when |
| 3147 | // deviceHandlesColorTransform is false. This transform converts |
| 3148 | // pure red to pure green. That will occur when the R8 buffer is |
| 3149 | // 255. When the R8 buffer is 0, it will still change to black, as |
| 3150 | // with r8_behaves_as_mask. |
Alec Mouri | 9bcd1d1 | 2022-04-21 22:16:56 +0000 | [diff] [blame] | 3151 | .colorTransform = kRemoveGreenAndMoveRedToGreenMat4, |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 3152 | .deviceHandlesColorTransform = false, |
| 3153 | }; |
| 3154 | |
| 3155 | const auto redBuffer = allocateAndFillSourceBuffer(2, 1, ubyte4(255, 0, 0, 255)); |
| 3156 | const renderengine::LayerSettings redLayer{ |
| 3157 | .geometry.boundaries = rect.toFloatRect(), |
| 3158 | .source = |
| 3159 | renderengine::PixelSource{ |
| 3160 | .buffer = |
| 3161 | renderengine::Buffer{ |
| 3162 | .buffer = redBuffer, |
| 3163 | }, |
| 3164 | }, |
| 3165 | .alpha = 1.0f, |
| 3166 | }; |
| 3167 | const renderengine::LayerSettings r8Layer{ |
| 3168 | .geometry.boundaries = rect.toFloatRect(), |
| 3169 | .source = |
| 3170 | renderengine::PixelSource{ |
| 3171 | .buffer = |
| 3172 | renderengine::Buffer{ |
| 3173 | .buffer = r8Buffer, |
| 3174 | }, |
| 3175 | }, |
| 3176 | .alpha = 1.0f, |
| 3177 | }; |
| 3178 | |
| 3179 | std::vector<renderengine::LayerSettings> layers{redLayer, r8Layer}; |
| 3180 | invokeDraw(display, layers); |
| 3181 | |
| 3182 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 255); |
| 3183 | expectBufferColor(Rect(1, 0, 2, 1), 0, 255, 0, 255); |
| 3184 | } |
| 3185 | |
| 3186 | TEST_P(RenderEngineTest, r8_respects_color_transform_when_device_handles) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 3187 | if (!GetParam()->typeSupported()) { |
| 3188 | GTEST_SKIP(); |
| 3189 | } |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 3190 | initializeRenderEngine(); |
| 3191 | |
| 3192 | const auto r8Buffer = allocateR8Buffer(2, 1); |
| 3193 | if (!r8Buffer) { |
| 3194 | GTEST_SKIP() << "Test is only necessary on devices that support r8"; |
| 3195 | return; |
| 3196 | } |
| 3197 | { |
| 3198 | uint8_t* pixels; |
| 3199 | r8Buffer->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 3200 | reinterpret_cast<void**>(&pixels)); |
| 3201 | pixels[0] = 0; |
| 3202 | pixels[1] = 255; |
| 3203 | r8Buffer->getBuffer()->unlock(); |
| 3204 | } |
| 3205 | |
| 3206 | const auto rect = Rect(0, 0, 2, 1); |
| 3207 | const renderengine::DisplaySettings display{ |
| 3208 | .physicalDisplay = rect, |
| 3209 | .clip = rect, |
| 3210 | .outputDataspace = ui::Dataspace::SRGB, |
| 3211 | // If deviceHandlesColorTransform is true, pixels where the A8 |
| 3212 | // buffer is opaque are unaffected. If the colorTransform is |
| 3213 | // invertible, pixels where the A8 buffer are transparent have the |
| 3214 | // inverse applied to them so that the DPU will convert them back to |
| 3215 | // black. Test with an arbitrary, invertible matrix. |
| 3216 | .colorTransform = mat4(1, 0, 0, 2, |
| 3217 | 3, 1, 2, 5, |
| 3218 | 0, 5, 3, 0, |
| 3219 | 0, 1, 0, 2), |
| 3220 | .deviceHandlesColorTransform = true, |
| 3221 | }; |
| 3222 | |
| 3223 | const auto redBuffer = allocateAndFillSourceBuffer(2, 1, ubyte4(255, 0, 0, 255)); |
| 3224 | const renderengine::LayerSettings redLayer{ |
| 3225 | .geometry.boundaries = rect.toFloatRect(), |
| 3226 | .source = |
| 3227 | renderengine::PixelSource{ |
| 3228 | .buffer = |
| 3229 | renderengine::Buffer{ |
| 3230 | .buffer = redBuffer, |
| 3231 | }, |
| 3232 | }, |
| 3233 | .alpha = 1.0f, |
| 3234 | }; |
| 3235 | const renderengine::LayerSettings r8Layer{ |
| 3236 | .geometry.boundaries = rect.toFloatRect(), |
| 3237 | .source = |
| 3238 | renderengine::PixelSource{ |
| 3239 | .buffer = |
| 3240 | renderengine::Buffer{ |
| 3241 | .buffer = r8Buffer, |
| 3242 | }, |
| 3243 | }, |
| 3244 | .alpha = 1.0f, |
| 3245 | }; |
| 3246 | |
| 3247 | std::vector<renderengine::LayerSettings> layers{redLayer, r8Layer}; |
| 3248 | invokeDraw(display, layers); |
| 3249 | |
| 3250 | expectBufferColor(Rect(1, 0, 2, 1), 255, 0, 0, 255); // Still red. |
| 3251 | expectBufferColor(Rect(0, 0, 1, 1), 0, 70, 0, 255); |
| 3252 | } |
Leon Scroggins III | 45be918 | 2022-04-27 10:37:11 -0400 | [diff] [blame] | 3253 | |
| 3254 | TEST_P(RenderEngineTest, primeShaderCache) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame^] | 3255 | if (!GetParam()->typeSupported()) { |
| 3256 | GTEST_SKIP(); |
| 3257 | } |
Leon Scroggins III | 45be918 | 2022-04-27 10:37:11 -0400 | [diff] [blame] | 3258 | initializeRenderEngine(); |
| 3259 | |
| 3260 | auto fut = mRE->primeCache(); |
| 3261 | if (fut.valid()) { |
| 3262 | fut.wait(); |
| 3263 | } |
| 3264 | |
| 3265 | const int minimumExpectedShadersCompiled = GetParam()->useColorManagement() ? 60 : 30; |
| 3266 | ASSERT_GT(static_cast<skia::SkiaGLRenderEngine*>(mRE.get())->reportShadersCompiled(), |
| 3267 | minimumExpectedShadersCompiled); |
| 3268 | } |
Derek Sollenberger | d3f6065 | 2021-06-11 15:34:36 -0400 | [diff] [blame] | 3269 | } // namespace renderengine |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 3270 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 3271 | |
| 3272 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 3273 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |