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