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