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