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) |
| 119 | .setSupportsBackgroundBlur(true) |
| 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(); |
| 1268 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128); |
| 1269 | } |
| 1270 | |
| 1271 | void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() { |
| 1272 | renderengine::DisplaySettings settings; |
| 1273 | settings.physicalDisplay = fullscreenRect(); |
| 1274 | // Here logical space is 1x1 |
| 1275 | settings.clip = Rect(1, 1); |
| 1276 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1277 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1278 | |
| 1279 | renderengine::LayerSettings layer; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1280 | const auto buf = allocateSourceBuffer(1, 1); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1281 | |
| 1282 | uint8_t* pixels; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1283 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1284 | reinterpret_cast<void**>(&pixels)); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1285 | pixels[0] = 255; |
| 1286 | pixels[1] = 0; |
| 1287 | pixels[2] = 0; |
| 1288 | pixels[3] = 255; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1289 | buf->getBuffer()->unlock(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1290 | |
| 1291 | layer.source.buffer.buffer = buf; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1292 | layer.source.buffer.usePremultipliedAlpha = false; |
| 1293 | layer.alpha = 0.5f; |
| 1294 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 1295 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1296 | layers.push_back(layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1297 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1298 | invokeDraw(settings, layers); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() { |
| 1302 | fillRedBufferWithoutPremultiplyAlpha(); |
wukui1 | 6f3c0bb | 2020-08-05 20:35:29 +0800 | [diff] [blame] | 1303 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128, 1); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1306 | template <typename SourceVariant> |
| 1307 | void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer, |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 1308 | const ShadowSettings& shadow, const ubyte4& casterColor, |
| 1309 | const ubyte4& backgroundColor) { |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1310 | renderengine::DisplaySettings settings; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1311 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1312 | settings.physicalDisplay = fullscreenRect(); |
| 1313 | settings.clip = fullscreenRect(); |
| 1314 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1315 | std::vector<renderengine::LayerSettings> layers; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1316 | |
| 1317 | // add background layer |
| 1318 | renderengine::LayerSettings bgLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1319 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1320 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1321 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 1322 | backgroundColor.b / 255.0f, this); |
| 1323 | bgLayer.alpha = backgroundColor.a / 255.0f; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1324 | layers.push_back(bgLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1325 | |
| 1326 | // add shadow layer |
| 1327 | renderengine::LayerSettings shadowLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1328 | shadowLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1329 | shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries; |
| 1330 | shadowLayer.alpha = castingLayer.alpha; |
| 1331 | shadowLayer.shadow = shadow; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1332 | layers.push_back(shadowLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1333 | |
| 1334 | // add layer casting the shadow |
| 1335 | renderengine::LayerSettings layer = castingLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1336 | layer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1337 | SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f, |
| 1338 | casterColor.b / 255.0f, this); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1339 | layers.push_back(layer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1340 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1341 | invokeDraw(settings, layers); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1342 | } |
| 1343 | |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1344 | void RenderEngineTest::drawShadowWithoutCaster(const FloatRect& castingBounds, |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 1345 | const ShadowSettings& shadow, |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1346 | const ubyte4& backgroundColor) { |
| 1347 | renderengine::DisplaySettings settings; |
| 1348 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1349 | settings.physicalDisplay = fullscreenRect(); |
| 1350 | settings.clip = fullscreenRect(); |
| 1351 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1352 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1353 | |
| 1354 | // add background layer |
| 1355 | renderengine::LayerSettings bgLayer; |
| 1356 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1357 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1358 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 1359 | backgroundColor.b / 255.0f, this); |
| 1360 | bgLayer.alpha = backgroundColor.a / 255.0f; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1361 | layers.push_back(bgLayer); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1362 | |
| 1363 | // add shadow layer |
| 1364 | renderengine::LayerSettings shadowLayer; |
| 1365 | shadowLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1366 | shadowLayer.geometry.boundaries = castingBounds; |
Derek Sollenberger | c31985e | 2021-05-18 16:38:17 -0400 | [diff] [blame] | 1367 | shadowLayer.skipContentDraw = true; |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1368 | shadowLayer.alpha = 1.0f; |
| 1369 | ColorSourceVariant::fillColor(shadowLayer, 0, 0, 0, this); |
| 1370 | shadowLayer.shadow = shadow; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1371 | layers.push_back(shadowLayer); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1372 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1373 | invokeDraw(settings, layers); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1376 | void RenderEngineTest::tonemap(ui::Dataspace sourceDataspace, std::function<vec3(vec3)> eotf, |
| 1377 | std::function<vec3(vec3, float)> scaleOotf) { |
| 1378 | constexpr int32_t kGreyLevels = 256; |
| 1379 | |
| 1380 | const auto rect = Rect(0, 0, kGreyLevels, 1); |
| 1381 | |
| 1382 | constexpr float kMaxLuminance = 750.f; |
| 1383 | constexpr float kCurrentLuminanceNits = 500.f; |
| 1384 | const renderengine::DisplaySettings display{ |
| 1385 | .physicalDisplay = rect, |
| 1386 | .clip = rect, |
| 1387 | .maxLuminance = kMaxLuminance, |
| 1388 | .currentLuminanceNits = kCurrentLuminanceNits, |
| 1389 | .outputDataspace = ui::Dataspace::DISPLAY_P3, |
| 1390 | }; |
| 1391 | |
| 1392 | auto buf = std::make_shared< |
| 1393 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1394 | ExternalTexture>(sp<GraphicBuffer>::make(kGreyLevels, 1, |
| 1395 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 1396 | GRALLOC_USAGE_SW_READ_OFTEN | |
| 1397 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 1398 | GRALLOC_USAGE_HW_RENDER | |
| 1399 | GRALLOC_USAGE_HW_TEXTURE, |
| 1400 | "input"), |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1401 | *mRE, |
| 1402 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 1403 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
| 1404 | ASSERT_EQ(0, buf->getBuffer()->initCheck()); |
| 1405 | { |
| 1406 | uint8_t* pixels; |
| 1407 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 1408 | reinterpret_cast<void**>(&pixels)); |
| 1409 | |
| 1410 | uint8_t color = 0; |
| 1411 | for (int32_t j = 0; j < buf->getBuffer()->getHeight(); j++) { |
| 1412 | uint8_t* dest = pixels + (buf->getBuffer()->getStride() * j * 4); |
| 1413 | for (int32_t i = 0; i < buf->getBuffer()->getWidth(); i++) { |
| 1414 | dest[0] = color; |
| 1415 | dest[1] = color; |
| 1416 | dest[2] = color; |
| 1417 | dest[3] = 255; |
| 1418 | color++; |
| 1419 | dest += 4; |
| 1420 | } |
| 1421 | } |
| 1422 | buf->getBuffer()->unlock(); |
| 1423 | } |
| 1424 | |
| 1425 | mBuffer = std::make_shared< |
| 1426 | renderengine::impl:: |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 1427 | ExternalTexture>(sp<GraphicBuffer>::make(kGreyLevels, 1, |
| 1428 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 1429 | GRALLOC_USAGE_SW_READ_OFTEN | |
| 1430 | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 1431 | GRALLOC_USAGE_HW_RENDER | |
| 1432 | GRALLOC_USAGE_HW_TEXTURE, |
| 1433 | "output"), |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1434 | *mRE, |
| 1435 | renderengine::impl::ExternalTexture::Usage::READABLE | |
| 1436 | renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
| 1437 | ASSERT_EQ(0, mBuffer->getBuffer()->initCheck()); |
| 1438 | |
| 1439 | const renderengine::LayerSettings layer{.geometry.boundaries = rect.toFloatRect(), |
| 1440 | .source = |
| 1441 | renderengine::PixelSource{ |
| 1442 | .buffer = |
| 1443 | renderengine::Buffer{ |
| 1444 | .buffer = |
| 1445 | std::move(buf), |
| 1446 | .usePremultipliedAlpha = |
| 1447 | true, |
| 1448 | }, |
| 1449 | }, |
| 1450 | .alpha = 1.0f, |
| 1451 | .sourceDataspace = sourceDataspace}; |
| 1452 | |
| 1453 | std::vector<renderengine::LayerSettings> layers{layer}; |
| 1454 | invokeDraw(display, layers); |
| 1455 | |
| 1456 | ColorSpace displayP3 = ColorSpace::DisplayP3(); |
| 1457 | ColorSpace bt2020 = ColorSpace::BT2020(); |
| 1458 | |
| 1459 | tonemap::Metadata metadata{.displayMaxLuminance = 750.0f}; |
| 1460 | |
| 1461 | auto generator = [=](Point location) { |
| 1462 | const double normColor = static_cast<double>(location.x) / (kGreyLevels - 1); |
| 1463 | const vec3 rgb = vec3(normColor, normColor, normColor); |
| 1464 | |
| 1465 | const vec3 linearRGB = eotf(rgb); |
| 1466 | |
| 1467 | const vec3 xyz = bt2020.getRGBtoXYZ() * linearRGB; |
| 1468 | |
| 1469 | const vec3 scaledXYZ = scaleOotf(xyz, kCurrentLuminanceNits); |
Alec Mouri | 196b0f2 | 2022-03-04 22:13:48 +0000 | [diff] [blame] | 1470 | const auto gains = |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1471 | tonemap::getToneMapper() |
| 1472 | ->lookupTonemapGain(static_cast<aidl::android::hardware::graphics::common:: |
| 1473 | Dataspace>(sourceDataspace), |
| 1474 | static_cast<aidl::android::hardware::graphics::common:: |
| 1475 | Dataspace>( |
| 1476 | ui::Dataspace::DISPLAY_P3), |
Alec Mouri | 196b0f2 | 2022-03-04 22:13:48 +0000 | [diff] [blame] | 1477 | {tonemap:: |
| 1478 | Color{.linearRGB = |
| 1479 | scaleOotf(linearRGB, |
| 1480 | kCurrentLuminanceNits), |
| 1481 | .xyz = scaledXYZ}}, |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1482 | metadata); |
Alec Mouri | 196b0f2 | 2022-03-04 22:13:48 +0000 | [diff] [blame] | 1483 | EXPECT_EQ(1, gains.size()); |
| 1484 | const double gain = gains.front(); |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 1485 | const vec3 normalizedXYZ = scaledXYZ * gain / metadata.displayMaxLuminance; |
| 1486 | |
| 1487 | const vec3 targetRGB = OETF_sRGB(displayP3.getXYZtoRGB() * normalizedXYZ) * 255; |
| 1488 | return ubyte4(static_cast<uint8_t>(targetRGB.r), static_cast<uint8_t>(targetRGB.g), |
| 1489 | static_cast<uint8_t>(targetRGB.b), 255); |
| 1490 | }; |
| 1491 | |
| 1492 | expectBufferColor(Rect(kGreyLevels, 1), generator, 2); |
| 1493 | } |
| 1494 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1495 | INSTANTIATE_TEST_SUITE_P(PerRenderEngineType, RenderEngineTest, |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1496 | testing::Values(std::make_shared<SkiaGLESRenderEngineFactory>(), |
Nolan Scobie | 195631a | 2024-03-26 12:22:23 -0400 | [diff] [blame^] | 1497 | std::make_shared<GaneshVkRenderEngineFactory>(), |
| 1498 | std::make_shared<GraphiteVkRenderEngineFactory>())); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1499 | |
| 1500 | TEST_P(RenderEngineTest, drawLayers_noLayersToDraw) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1501 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1502 | GTEST_SKIP(); |
| 1503 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1504 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1505 | drawEmptyLayers(); |
| 1506 | } |
| 1507 | |
Sally Qi | 1fed86e | 2022-06-23 15:33:52 -0700 | [diff] [blame] | 1508 | TEST_P(RenderEngineTest, drawLayers_fillRedBufferAndEmptyBuffer) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1509 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1510 | GTEST_SKIP(); |
| 1511 | } |
Sally Qi | 1fed86e | 2022-06-23 15:33:52 -0700 | [diff] [blame] | 1512 | initializeRenderEngine(); |
| 1513 | renderengine::DisplaySettings settings; |
| 1514 | settings.physicalDisplay = fullscreenRect(); |
| 1515 | settings.clip = fullscreenRect(); |
| 1516 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1517 | |
| 1518 | // add a red layer |
| 1519 | renderengine::LayerSettings layerOne{ |
| 1520 | .geometry.boundaries = fullscreenRect().toFloatRect(), |
| 1521 | .source.solidColor = half3(1.0f, 0.0f, 0.0f), |
| 1522 | .alpha = 1.f, |
| 1523 | }; |
| 1524 | |
| 1525 | std::vector<renderengine::LayerSettings> layersFirst{layerOne}; |
| 1526 | invokeDraw(settings, layersFirst); |
| 1527 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 1528 | |
| 1529 | // re-draw with an empty layer above it, and we get a transparent black one |
| 1530 | std::vector<renderengine::LayerSettings> layersSecond; |
| 1531 | invokeDraw(settings, layersSecond); |
| 1532 | expectBufferColor(fullscreenRect(), 0, 0, 0, 0); |
| 1533 | } |
| 1534 | |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1535 | TEST_P(RenderEngineTest, drawLayers_withoutBuffers_withColorTransform) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1536 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1537 | GTEST_SKIP(); |
| 1538 | } |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 1539 | initializeRenderEngine(); |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1540 | |
| 1541 | renderengine::DisplaySettings settings; |
| 1542 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1543 | settings.physicalDisplay = fullscreenRect(); |
| 1544 | settings.clip = fullscreenRect(); |
| 1545 | |
| 1546 | // 255, 255, 255, 255 is full opaque white. |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 1547 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 1548 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1549 | // Create layer with given color. |
| 1550 | renderengine::LayerSettings bgLayer; |
| 1551 | bgLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 1552 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1553 | bgLayer.source.solidColor = half3(backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 1554 | backgroundColor.b / 255.0f); |
| 1555 | bgLayer.alpha = backgroundColor.a / 255.0f; |
| 1556 | // Transform the red color. |
| 1557 | bgLayer.colorTransform = mat4(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 1558 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1559 | std::vector<renderengine::LayerSettings> layers; |
| 1560 | layers.push_back(bgLayer); |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1561 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1562 | invokeDraw(settings, layers); |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1563 | |
| 1564 | // Expect to see full opaque pixel (with inverted red from the transform). |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1565 | expectBufferColor(Rect(0, 0, 10, 10), 0.f, backgroundColor.g, backgroundColor.b, |
Ana Krulec | 07b98df | 2021-01-07 14:38:40 -0800 | [diff] [blame] | 1566 | backgroundColor.a); |
| 1567 | } |
| 1568 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1569 | TEST_P(RenderEngineTest, drawLayers_nullOutputBuffer) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1570 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1571 | GTEST_SKIP(); |
| 1572 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1573 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1574 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1575 | renderengine::DisplaySettings settings; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 1576 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1577 | std::vector<renderengine::LayerSettings> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1578 | renderengine::LayerSettings layer; |
| 1579 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1580 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 1581 | layers.push_back(layer); |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 1582 | ftl::Future<FenceResult> future = mRE->drawLayers(settings, layers, nullptr, base::unique_fd()); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1583 | |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 1584 | ASSERT_TRUE(future.valid()); |
| 1585 | auto result = future.get(); |
| 1586 | ASSERT_FALSE(result.ok()); |
| 1587 | ASSERT_EQ(BAD_VALUE, result.error()); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1590 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1591 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1592 | GTEST_SKIP(); |
| 1593 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1594 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1595 | fillRedBuffer<ColorSourceVariant>(); |
| 1596 | } |
| 1597 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1598 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1599 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1600 | GTEST_SKIP(); |
| 1601 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1602 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1603 | fillGreenBuffer<ColorSourceVariant>(); |
| 1604 | } |
| 1605 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1606 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1607 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1608 | GTEST_SKIP(); |
| 1609 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1610 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1611 | fillBlueBuffer<ColorSourceVariant>(); |
| 1612 | } |
| 1613 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1614 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1615 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1616 | GTEST_SKIP(); |
| 1617 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1618 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1619 | fillRedTransparentBuffer<ColorSourceVariant>(); |
| 1620 | } |
| 1621 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1622 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1623 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1624 | GTEST_SKIP(); |
| 1625 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1626 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1627 | fillBufferPhysicalOffset<ColorSourceVariant>(); |
| 1628 | } |
| 1629 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1630 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1631 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1632 | GTEST_SKIP(); |
| 1633 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1634 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1635 | fillBufferCheckersRotate0<ColorSourceVariant>(); |
| 1636 | } |
| 1637 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1638 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1639 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1640 | GTEST_SKIP(); |
| 1641 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1642 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1643 | fillBufferCheckersRotate90<ColorSourceVariant>(); |
| 1644 | } |
| 1645 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1646 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1647 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1648 | GTEST_SKIP(); |
| 1649 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1650 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1651 | fillBufferCheckersRotate180<ColorSourceVariant>(); |
| 1652 | } |
| 1653 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1654 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1655 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1656 | GTEST_SKIP(); |
| 1657 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1658 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1659 | fillBufferCheckersRotate270<ColorSourceVariant>(); |
| 1660 | } |
| 1661 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1662 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1663 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1664 | GTEST_SKIP(); |
| 1665 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1666 | initializeRenderEngine(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1667 | fillBufferLayerTransform<ColorSourceVariant>(); |
| 1668 | } |
| 1669 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1670 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1671 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1672 | GTEST_SKIP(); |
| 1673 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1674 | initializeRenderEngine(); |
KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1675 | fillBufferColorTransform<ColorSourceVariant>(); |
| 1676 | } |
| 1677 | |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1678 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_sourceDataspace) { |
| 1679 | const auto& renderEngineFactory = GetParam(); |
| 1680 | // skip for non color management |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1681 | if (!renderEngineFactory->apiSupported()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1682 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | initializeRenderEngine(); |
| 1686 | fillBufferColorTransformAndSourceDataspace<ColorSourceVariant>(); |
| 1687 | } |
| 1688 | |
| 1689 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_outputDataspace) { |
Nolan Scobie | 195631a | 2024-03-26 12:22:23 -0400 | [diff] [blame^] | 1690 | // TODO: b/331445583 - Fix in Graphite and re-enable. |
| 1691 | if (GetParam()->skiaBackend() == renderengine::RenderEngine::SkiaBackend::GRAPHITE) { |
| 1692 | GTEST_SKIP(); |
| 1693 | } |
| 1694 | |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 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) { |
Nolan Scobie | 195631a | 2024-03-26 12:22:23 -0400 | [diff] [blame^] | 1845 | // TODO: b/331447131 - Fix in Graphite and re-enable. |
| 1846 | if (GetParam()->skiaBackend() == renderengine::RenderEngine::SkiaBackend::GRAPHITE) { |
| 1847 | GTEST_SKIP(); |
| 1848 | } |
| 1849 | |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1850 | const auto& renderEngineFactory = GetParam(); |
| 1851 | // skip for non color management |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1852 | if (!renderEngineFactory->apiSupported()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1853 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | initializeRenderEngine(); |
| 1857 | fillBufferColorTransformAndOutputDataspace<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1858 | } |
| 1859 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1860 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1861 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1862 | GTEST_SKIP(); |
| 1863 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1864 | initializeRenderEngine(); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1865 | fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1866 | } |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1867 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1868 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_opaqueBufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1869 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1870 | GTEST_SKIP(); |
| 1871 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1872 | initializeRenderEngine(); |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1873 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1874 | } |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1875 | |
Nathaniel Nifong | 53494f3 | 2021-04-30 14:05:39 -0400 | [diff] [blame] | 1876 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_opaqueBufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1877 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1878 | GTEST_SKIP(); |
| 1879 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1880 | initializeRenderEngine(); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1881 | fillBufferAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1882 | } |
| 1883 | |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1884 | TEST_P(RenderEngineTest, drawLayers_fillSmallLayerAndBlurBackground_opaqueBufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1885 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1886 | GTEST_SKIP(); |
| 1887 | } |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 1888 | initializeRenderEngine(); |
| 1889 | fillSmallLayerAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1890 | } |
| 1891 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1892 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1893 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1894 | GTEST_SKIP(); |
| 1895 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1896 | initializeRenderEngine(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1897 | overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1898 | } |
| 1899 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1900 | TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1901 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1902 | GTEST_SKIP(); |
| 1903 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1904 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1905 | fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1906 | } |
| 1907 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1908 | TEST_P(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1909 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1910 | GTEST_SKIP(); |
| 1911 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1912 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1913 | fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1914 | } |
| 1915 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1916 | TEST_P(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1917 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1918 | GTEST_SKIP(); |
| 1919 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1920 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1921 | fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1922 | } |
| 1923 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1924 | TEST_P(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1925 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1926 | GTEST_SKIP(); |
| 1927 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1928 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1929 | fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1930 | } |
| 1931 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1932 | TEST_P(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1933 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1934 | GTEST_SKIP(); |
| 1935 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1936 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1937 | fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1938 | } |
| 1939 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1940 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1941 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1942 | GTEST_SKIP(); |
| 1943 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1944 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1945 | fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1946 | } |
| 1947 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1948 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1949 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1950 | GTEST_SKIP(); |
| 1951 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1952 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1953 | fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1954 | } |
| 1955 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1956 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1957 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1958 | GTEST_SKIP(); |
| 1959 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1960 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1961 | fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1962 | } |
| 1963 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1964 | TEST_P(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1965 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1966 | GTEST_SKIP(); |
| 1967 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1968 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1969 | fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1970 | } |
| 1971 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1972 | TEST_P(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1973 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1974 | GTEST_SKIP(); |
| 1975 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1976 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1977 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1978 | } |
| 1979 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 1980 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1981 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 1982 | GTEST_SKIP(); |
| 1983 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 1984 | initializeRenderEngine(); |
KaiChieh Chuang | 436fc19 | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1985 | fillBufferColorTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1986 | } |
| 1987 | |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1988 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndSourceDataspace_bufferSource) { |
| 1989 | const auto& renderEngineFactory = GetParam(); |
| 1990 | // skip for non color management |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 1991 | if (!renderEngineFactory->apiSupported()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 1992 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | initializeRenderEngine(); |
| 1996 | fillBufferColorTransformAndSourceDataspace<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1997 | } |
| 1998 | |
| 1999 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndOutputDataspace_bufferSource) { |
Nolan Scobie | 195631a | 2024-03-26 12:22:23 -0400 | [diff] [blame^] | 2000 | // TODO: b/331446495 - Fix in Graphite and re-enable. |
| 2001 | if (GetParam()->skiaBackend() == renderengine::RenderEngine::SkiaBackend::GRAPHITE) { |
| 2002 | GTEST_SKIP(); |
| 2003 | } |
| 2004 | |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 2005 | const auto& renderEngineFactory = GetParam(); |
| 2006 | // skip for non color management |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2007 | if (!renderEngineFactory->apiSupported()) { |
Alec Mouri | c16974e | 2022-09-13 17:35:48 +0000 | [diff] [blame] | 2008 | GTEST_SKIP(); |
Sally Qi | 2019fd2 | 2021-11-22 10:19:04 -0800 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | initializeRenderEngine(); |
| 2012 | fillBufferColorTransformAndOutputDataspace<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2013 | } |
| 2014 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2015 | TEST_P(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2016 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2017 | GTEST_SKIP(); |
| 2018 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2019 | initializeRenderEngine(); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 2020 | fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2021 | } |
| 2022 | |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 2023 | TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2024 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2025 | GTEST_SKIP(); |
| 2026 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2027 | initializeRenderEngine(); |
KaiChieh Chuang | da2845c | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 2028 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2029 | } |
| 2030 | |
Nathaniel Nifong | 53494f3 | 2021-04-30 14:05:39 -0400 | [diff] [blame] | 2031 | TEST_P(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2032 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2033 | GTEST_SKIP(); |
| 2034 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2035 | initializeRenderEngine(); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 2036 | fillBufferAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2037 | } |
| 2038 | |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 2039 | TEST_P(RenderEngineTest, drawLayers_fillSmallLayerAndBlurBackground_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2040 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2041 | GTEST_SKIP(); |
| 2042 | } |
Alec Mouri | e8489fd | 2021-04-29 16:08:56 -0700 | [diff] [blame] | 2043 | initializeRenderEngine(); |
| 2044 | fillSmallLayerAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2045 | } |
| 2046 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2047 | TEST_P(RenderEngineTest, drawLayers_overlayCorners_bufferSource) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2048 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2049 | GTEST_SKIP(); |
| 2050 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2051 | initializeRenderEngine(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 2052 | overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 2053 | } |
| 2054 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2055 | TEST_P(RenderEngineTest, drawLayers_fillBufferTextureTransform) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2056 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2057 | GTEST_SKIP(); |
| 2058 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2059 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2060 | fillBufferTextureTransform(); |
| 2061 | } |
| 2062 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2063 | TEST_P(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) { |
Nolan Scobie | 195631a | 2024-03-26 12:22:23 -0400 | [diff] [blame^] | 2064 | // TODO: b/331446496 - Fix in Graphite and re-enable. |
| 2065 | if (GetParam()->skiaBackend() == renderengine::RenderEngine::SkiaBackend::GRAPHITE) { |
| 2066 | GTEST_SKIP(); |
| 2067 | } |
| 2068 | |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2069 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2070 | GTEST_SKIP(); |
| 2071 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2072 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2073 | fillBufferWithPremultiplyAlpha(); |
| 2074 | } |
| 2075 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2076 | TEST_P(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2077 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2078 | GTEST_SKIP(); |
| 2079 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2080 | initializeRenderEngine(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 2081 | fillBufferWithoutPremultiplyAlpha(); |
| 2082 | } |
| 2083 | |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 2084 | TEST_P(RenderEngineTest, drawLayers_fillShadow_castsWithoutCasterLayer) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2085 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2086 | GTEST_SKIP(); |
| 2087 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2088 | initializeRenderEngine(); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 2089 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2090 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2091 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 2092 | const float shadowLength = 5.0f; |
| 2093 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2094 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 2095 | ShadowSettings settings = getShadowSettings(vec2(casterBounds.left, casterBounds.top), |
| 2096 | shadowLength, false /* casterIsTranslucent */); |
Alec Mouri | bd17b3b | 2020-12-17 11:08:30 -0800 | [diff] [blame] | 2097 | |
| 2098 | drawShadowWithoutCaster(casterBounds.toFloatRect(), settings, backgroundColor); |
| 2099 | expectShadowColorWithoutCaster(casterBounds.toFloatRect(), settings, backgroundColor); |
| 2100 | } |
| 2101 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2102 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterLayerMinSize) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2103 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2104 | GTEST_SKIP(); |
| 2105 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2106 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2107 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2108 | const ubyte4 casterColor(static_cast<uint8_t>(255), static_cast<uint8_t>(0), |
| 2109 | static_cast<uint8_t>(0), static_cast<uint8_t>(255)); |
| 2110 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2111 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2112 | const float shadowLength = 5.0f; |
| 2113 | Rect casterBounds(1, 1); |
| 2114 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2115 | renderengine::LayerSettings castingLayer; |
| 2116 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 2117 | castingLayer.alpha = 1.0f; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 2118 | ShadowSettings settings = getShadowSettings(vec2(casterBounds.left, casterBounds.top), |
| 2119 | shadowLength, false /* casterIsTranslucent */); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2120 | |
| 2121 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 2122 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 2123 | } |
| 2124 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2125 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterColorLayer) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2126 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2127 | GTEST_SKIP(); |
| 2128 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2129 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2130 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2131 | const ubyte4 casterColor(static_cast<uint8_t>(255), static_cast<uint8_t>(0), |
| 2132 | static_cast<uint8_t>(0), static_cast<uint8_t>(255)); |
| 2133 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2134 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2135 | const float shadowLength = 5.0f; |
| 2136 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2137 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2138 | renderengine::LayerSettings castingLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 2139 | castingLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2140 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 2141 | castingLayer.alpha = 1.0f; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 2142 | ShadowSettings settings = getShadowSettings(vec2(casterBounds.left, casterBounds.top), |
| 2143 | shadowLength, false /* casterIsTranslucent */); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2144 | |
| 2145 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 2146 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 2147 | } |
| 2148 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2149 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterOpaqueBufferLayer) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2150 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2151 | GTEST_SKIP(); |
| 2152 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2153 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2154 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2155 | const ubyte4 casterColor(static_cast<uint8_t>(255), static_cast<uint8_t>(0), |
| 2156 | static_cast<uint8_t>(0), static_cast<uint8_t>(255)); |
| 2157 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2158 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2159 | const float shadowLength = 5.0f; |
| 2160 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2161 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2162 | renderengine::LayerSettings castingLayer; |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 2163 | castingLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2164 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 2165 | castingLayer.alpha = 1.0f; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 2166 | ShadowSettings settings = getShadowSettings(vec2(casterBounds.left, casterBounds.top), |
| 2167 | shadowLength, false /* casterIsTranslucent */); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2168 | |
| 2169 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 2170 | backgroundColor); |
| 2171 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 2172 | } |
| 2173 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2174 | TEST_P(RenderEngineTest, drawLayers_fillShadow_casterWithRoundedCorner) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2175 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2176 | GTEST_SKIP(); |
| 2177 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2178 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2179 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2180 | const ubyte4 casterColor(static_cast<uint8_t>(255), static_cast<uint8_t>(0), |
| 2181 | static_cast<uint8_t>(0), static_cast<uint8_t>(255)); |
| 2182 | const ubyte4 backgroundColor(static_cast<uint8_t>(255), static_cast<uint8_t>(255), |
| 2183 | static_cast<uint8_t>(255), static_cast<uint8_t>(255)); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2184 | const float shadowLength = 5.0f; |
| 2185 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2186 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2187 | renderengine::LayerSettings castingLayer; |
| 2188 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2189 | castingLayer.geometry.roundedCornersRadius = {3.0f, 3.0f}; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2190 | castingLayer.geometry.roundedCornersCrop = casterBounds.toFloatRect(); |
| 2191 | castingLayer.alpha = 1.0f; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 2192 | ShadowSettings settings = getShadowSettings(vec2(casterBounds.left, casterBounds.top), |
| 2193 | shadowLength, false /* casterIsTranslucent */); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2194 | |
| 2195 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 2196 | backgroundColor); |
| 2197 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 2198 | } |
| 2199 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2200 | TEST_P(RenderEngineTest, drawLayers_fillShadow_translucentCasterWithAlpha) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2201 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2202 | GTEST_SKIP(); |
| 2203 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2204 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2205 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2206 | const ubyte4 casterColor(255, 0, 0, 255); |
| 2207 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 2208 | const float shadowLength = 5.0f; |
| 2209 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 2210 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 2211 | renderengine::LayerSettings castingLayer; |
| 2212 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 2213 | castingLayer.alpha = 0.5f; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 2214 | ShadowSettings settings = getShadowSettings(vec2(casterBounds.left, casterBounds.top), |
| 2215 | shadowLength, true /* casterIsTranslucent */); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 2216 | |
| 2217 | drawShadow<BufferSourceVariant<RelaxOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 2218 | backgroundColor); |
| 2219 | |
| 2220 | // verify only the background since the shadow will draw behind the caster |
| 2221 | const float shadowInset = settings.length * -1.0f; |
| 2222 | const Rect casterWithShadow = |
| 2223 | Rect(casterBounds).inset(shadowInset, shadowInset, shadowInset, shadowInset); |
| 2224 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); |
| 2225 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, |
| 2226 | backgroundColor.a); |
| 2227 | } |
| 2228 | |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2229 | TEST_P(RenderEngineTest, cleanupPostRender_cleansUpOnce) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2230 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2231 | GTEST_SKIP(); |
| 2232 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2233 | initializeRenderEngine(); |
Ana Krulec | 82ba2ec | 2020-11-21 13:33:20 -0800 | [diff] [blame] | 2234 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2235 | renderengine::DisplaySettings settings; |
| 2236 | settings.physicalDisplay = fullscreenRect(); |
| 2237 | settings.clip = fullscreenRect(); |
Ana Krulec | aa2fe7f | 2020-11-24 15:06:36 -0800 | [diff] [blame] | 2238 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2239 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2240 | std::vector<renderengine::LayerSettings> layers; |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2241 | renderengine::LayerSettings layer; |
| 2242 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 2243 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 2244 | layer.alpha = 1.0; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2245 | layers.push_back(layer); |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2246 | |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 2247 | ftl::Future<FenceResult> futureOne = |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 2248 | mRE->drawLayers(settings, layers, mBuffer, base::unique_fd()); |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 2249 | ASSERT_TRUE(futureOne.valid()); |
| 2250 | auto resultOne = futureOne.get(); |
| 2251 | ASSERT_TRUE(resultOne.ok()); |
| 2252 | auto fenceOne = resultOne.value(); |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 2253 | |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 2254 | ftl::Future<FenceResult> futureTwo = |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 2255 | mRE->drawLayers(settings, layers, mBuffer, base::unique_fd(fenceOne->dup())); |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 2256 | ASSERT_TRUE(futureTwo.valid()); |
| 2257 | auto resultTwo = futureTwo.get(); |
| 2258 | ASSERT_TRUE(resultTwo.ok()); |
| 2259 | auto fenceTwo = resultTwo.value(); |
| 2260 | fenceTwo->waitForever(LOG_TAG); |
Derek Sollenberger | ec41121 | 2021-08-25 10:54:47 -0400 | [diff] [blame] | 2261 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2262 | // Only cleanup the first time. |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2263 | if (mRE->canSkipPostRenderCleanup()) { |
| 2264 | // Skia's Vk backend may keep the texture alive beyond drawLayersInternal, so |
| 2265 | // 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] | 2266 | EXPECT_TRUE(GetParam()->graphicsApi() == renderengine::RenderEngine::GraphicsApi::VK); |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2267 | } else { |
| 2268 | mRE->cleanupPostRender(); |
| 2269 | EXPECT_TRUE(mRE->canSkipPostRenderCleanup()); |
| 2270 | } |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2273 | TEST_P(RenderEngineTest, testRoundedCornersCrop) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2274 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2275 | GTEST_SKIP(); |
| 2276 | } |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2277 | initializeRenderEngine(); |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2278 | |
| 2279 | renderengine::DisplaySettings settings; |
| 2280 | settings.physicalDisplay = fullscreenRect(); |
| 2281 | settings.clip = fullscreenRect(); |
| 2282 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2283 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2284 | std::vector<renderengine::LayerSettings> layers; |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2285 | |
| 2286 | renderengine::LayerSettings redLayer; |
| 2287 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2288 | redLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2289 | redLayer.geometry.roundedCornersRadius = {5.0f, 5.0f}; |
| 2290 | |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2291 | redLayer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 2292 | // Red background. |
| 2293 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 2294 | redLayer.alpha = 1.0f; |
| 2295 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2296 | layers.push_back(redLayer); |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2297 | |
| 2298 | // Green layer with 1/3 size. |
| 2299 | renderengine::LayerSettings greenLayer; |
| 2300 | greenLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2301 | greenLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2302 | greenLayer.geometry.roundedCornersRadius = {5.0f, 5.0f}; |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2303 | // Bottom right corner is not going to be rounded. |
| 2304 | greenLayer.geometry.roundedCornersCrop = |
| 2305 | Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3, DEFAULT_DISPLAY_HEIGHT, |
| 2306 | DEFAULT_DISPLAY_HEIGHT) |
| 2307 | .toFloatRect(); |
| 2308 | greenLayer.source.solidColor = half3(0.0f, 1.0f, 0.0f); |
| 2309 | greenLayer.alpha = 1.0f; |
| 2310 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2311 | layers.push_back(greenLayer); |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2312 | |
Alec Mouri | c0aae73 | 2021-01-12 13:32:18 -0800 | [diff] [blame] | 2313 | invokeDraw(settings, layers); |
Ana Krulec | f9a15d9 | 2020-12-11 08:35:00 -0800 | [diff] [blame] | 2314 | |
| 2315 | // Corners should be ignored... |
| 2316 | // Screen size: width is 128, height is 256. |
| 2317 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); |
| 2318 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); |
| 2319 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 2320 | // Bottom right corner is kept out of the clipping, and it's green. |
| 2321 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, |
| 2322 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 2323 | 0, 255, 0, 255); |
| 2324 | } |
| 2325 | |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2326 | TEST_P(RenderEngineTest, testRoundedCornersParentCrop) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2327 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2328 | GTEST_SKIP(); |
| 2329 | } |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2330 | initializeRenderEngine(); |
| 2331 | |
| 2332 | renderengine::DisplaySettings settings; |
| 2333 | settings.physicalDisplay = fullscreenRect(); |
| 2334 | settings.clip = fullscreenRect(); |
| 2335 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2336 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2337 | std::vector<renderengine::LayerSettings> layers; |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2338 | |
| 2339 | renderengine::LayerSettings redLayer; |
| 2340 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2341 | redLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2342 | redLayer.geometry.roundedCornersRadius = {5.0f, 5.0f}; |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2343 | redLayer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 2344 | // Red background. |
| 2345 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 2346 | redLayer.alpha = 1.0f; |
| 2347 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2348 | layers.push_back(redLayer); |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2349 | |
| 2350 | // Green layer with 1/2 size with parent crop rect. |
| 2351 | renderengine::LayerSettings greenLayer = redLayer; |
| 2352 | greenLayer.geometry.boundaries = |
| 2353 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2); |
| 2354 | greenLayer.source.solidColor = half3(0.0f, 1.0f, 0.0f); |
| 2355 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2356 | layers.push_back(greenLayer); |
Derek Sollenberger | 8e8b3bf | 2021-04-29 15:35:28 -0400 | [diff] [blame] | 2357 | |
| 2358 | invokeDraw(settings, layers); |
| 2359 | |
| 2360 | // Due to roundedCornersRadius, the corners are untouched. |
| 2361 | expectBufferColor(Point(0, 0), 0, 0, 0, 0); |
| 2362 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 0), 0, 0, 0, 0); |
| 2363 | expectBufferColor(Point(0, DEFAULT_DISPLAY_HEIGHT - 1), 0, 0, 0, 0); |
| 2364 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1), 0, 0, 0, 0); |
| 2365 | |
| 2366 | // top middle should be green and the bottom middle red |
| 2367 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH / 2, 0), 0, 255, 0, 255); |
| 2368 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, 255); |
| 2369 | |
| 2370 | // the bottom edge of the green layer should not be rounded |
| 2371 | expectBufferColor(Point(0, (DEFAULT_DISPLAY_HEIGHT / 2) - 1), 0, 255, 0, 255); |
| 2372 | } |
| 2373 | |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2374 | TEST_P(RenderEngineTest, testRoundedCornersParentCropSmallBounds) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2375 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2376 | GTEST_SKIP(); |
| 2377 | } |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2378 | initializeRenderEngine(); |
| 2379 | |
| 2380 | renderengine::DisplaySettings settings; |
| 2381 | settings.physicalDisplay = fullscreenRect(); |
| 2382 | settings.clip = fullscreenRect(); |
| 2383 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2384 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2385 | std::vector<renderengine::LayerSettings> layers; |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2386 | |
| 2387 | renderengine::LayerSettings redLayer; |
| 2388 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2389 | redLayer.geometry.boundaries = FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH, 32); |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2390 | redLayer.geometry.roundedCornersRadius = {64.0f, 64.0f}; |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2391 | redLayer.geometry.roundedCornersCrop = FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH, 128); |
| 2392 | // Red background. |
| 2393 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 2394 | redLayer.alpha = 1.0f; |
| 2395 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2396 | layers.push_back(redLayer); |
Derek Sollenberger | 547d0a6 | 2021-07-27 14:09:17 -0400 | [diff] [blame] | 2397 | invokeDraw(settings, layers); |
| 2398 | |
| 2399 | // Due to roundedCornersRadius, the top corners are untouched. |
| 2400 | expectBufferColor(Point(0, 0), 0, 0, 0, 0); |
| 2401 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 0), 0, 0, 0, 0); |
| 2402 | |
| 2403 | // ensure that the entire height of the red layer was clipped by the rounded corners crop. |
| 2404 | expectBufferColor(Point(0, 31), 0, 0, 0, 0); |
| 2405 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 31), 0, 0, 0, 0); |
| 2406 | |
| 2407 | // the bottom middle should be red |
| 2408 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH / 2, 31), 255, 0, 0, 255); |
| 2409 | } |
| 2410 | |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2411 | TEST_P(RenderEngineTest, testRoundedCornersXY) { |
Leon Scroggins III | 9ba31e3 | 2024-01-25 11:40:26 -0500 | [diff] [blame] | 2412 | if (!GetParam()->apiSupported()) { |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 2413 | GTEST_SKIP(); |
| 2414 | } |
| 2415 | |
| 2416 | initializeRenderEngine(); |
| 2417 | |
| 2418 | renderengine::DisplaySettings settings; |
| 2419 | settings.physicalDisplay = fullscreenRect(); |
| 2420 | settings.clip = fullscreenRect(); |
| 2421 | settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2422 | |
| 2423 | std::vector<renderengine::LayerSettings> layers; |
| 2424 | |
| 2425 | renderengine::LayerSettings redLayer; |
| 2426 | redLayer.sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2427 | redLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 2428 | redLayer.geometry.roundedCornersRadius = {5.0f, 20.0f}; |
| 2429 | redLayer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 2430 | // Red background. |
| 2431 | redLayer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 2432 | redLayer.alpha = 1.0f; |
| 2433 | |
| 2434 | layers.push_back(redLayer); |
| 2435 | |
| 2436 | invokeDraw(settings, layers); |
| 2437 | |
| 2438 | // Due to roundedCornersRadius, the corners are untouched. |
| 2439 | expectBufferColor(Point(0, 0), 0, 0, 0, 0); |
| 2440 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 0), 0, 0, 0, 0); |
| 2441 | expectBufferColor(Point(0, DEFAULT_DISPLAY_HEIGHT - 1), 0, 0, 0, 0); |
| 2442 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1), 0, 0, 0, 0); |
| 2443 | |
| 2444 | // Y-axis draws a larger radius, check that its untouched as well |
| 2445 | expectBufferColor(Point(0, DEFAULT_DISPLAY_HEIGHT - 5), 0, 0, 0, 0); |
| 2446 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 5), 0, 0, 0, 0); |
| 2447 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH - 1, 5), 0, 0, 0, 0); |
| 2448 | expectBufferColor(Point(0, 5), 0, 0, 0, 0); |
| 2449 | |
| 2450 | // middle should be red |
| 2451 | expectBufferColor(Point(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, 255); |
| 2452 | } |
| 2453 | |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2454 | TEST_P(RenderEngineTest, testClear) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2455 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2456 | GTEST_SKIP(); |
| 2457 | } |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2458 | initializeRenderEngine(); |
| 2459 | |
| 2460 | const auto rect = fullscreenRect(); |
| 2461 | const renderengine::DisplaySettings display{ |
| 2462 | .physicalDisplay = rect, |
| 2463 | .clip = rect, |
| 2464 | }; |
| 2465 | |
| 2466 | const renderengine::LayerSettings redLayer{ |
| 2467 | .geometry.boundaries = rect.toFloatRect(), |
| 2468 | .source.solidColor = half3(1.0f, 0.0f, 0.0f), |
| 2469 | .alpha = 1.0f, |
| 2470 | }; |
| 2471 | |
| 2472 | // This mimics prepareClearClientComposition. This layer should overwrite |
| 2473 | // the redLayer, so that the buffer is transparent, rather than red. |
| 2474 | const renderengine::LayerSettings clearLayer{ |
| 2475 | .geometry.boundaries = rect.toFloatRect(), |
| 2476 | .source.solidColor = half3(0.0f, 0.0f, 0.0f), |
| 2477 | .alpha = 0.0f, |
| 2478 | .disableBlending = true, |
| 2479 | }; |
| 2480 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2481 | std::vector<renderengine::LayerSettings> layers{redLayer, clearLayer}; |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2482 | invokeDraw(display, layers); |
| 2483 | expectBufferColor(rect, 0, 0, 0, 0); |
| 2484 | } |
| 2485 | |
| 2486 | TEST_P(RenderEngineTest, testDisableBlendingBuffer) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2487 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2488 | GTEST_SKIP(); |
| 2489 | } |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2490 | initializeRenderEngine(); |
| 2491 | |
| 2492 | const auto rect = Rect(0, 0, 1, 1); |
| 2493 | const renderengine::DisplaySettings display{ |
| 2494 | .physicalDisplay = rect, |
| 2495 | .clip = rect, |
| 2496 | }; |
| 2497 | |
| 2498 | const renderengine::LayerSettings redLayer{ |
| 2499 | .geometry.boundaries = rect.toFloatRect(), |
| 2500 | .source.solidColor = half3(1.0f, 0.0f, 0.0f), |
| 2501 | .alpha = 1.0f, |
| 2502 | }; |
| 2503 | |
| 2504 | // The next layer will overwrite redLayer with a GraphicBuffer that is green |
| 2505 | // applied with a translucent alpha. |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 2506 | const auto buf = allocateSourceBuffer(1, 1); |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2507 | { |
| 2508 | uint8_t* pixels; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 2509 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 2510 | reinterpret_cast<void**>(&pixels)); |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2511 | pixels[0] = 0; |
| 2512 | pixels[1] = 255; |
| 2513 | pixels[2] = 0; |
| 2514 | pixels[3] = 255; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 2515 | buf->getBuffer()->unlock(); |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | const renderengine::LayerSettings greenLayer{ |
| 2519 | .geometry.boundaries = rect.toFloatRect(), |
| 2520 | .source = |
| 2521 | renderengine::PixelSource{ |
| 2522 | .buffer = |
| 2523 | renderengine::Buffer{ |
| 2524 | .buffer = buf, |
| 2525 | .usePremultipliedAlpha = true, |
| 2526 | }, |
| 2527 | }, |
| 2528 | .alpha = 0.5f, |
| 2529 | .disableBlending = true, |
| 2530 | }; |
| 2531 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2532 | std::vector<renderengine::LayerSettings> layers{redLayer, greenLayer}; |
Leon Scroggins III | cf3d95c | 2021-03-19 13:06:32 -0400 | [diff] [blame] | 2533 | invokeDraw(display, layers); |
| 2534 | expectBufferColor(rect, 0, 128, 0, 128); |
| 2535 | } |
| 2536 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2537 | TEST_P(RenderEngineTest, testDimming) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2538 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2539 | GTEST_SKIP(); |
| 2540 | } |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2541 | initializeRenderEngine(); |
| 2542 | |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2543 | const ui::Dataspace dataspace = ui::Dataspace::V0_SRGB_LINEAR; |
| 2544 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2545 | const auto displayRect = Rect(3, 1); |
| 2546 | const renderengine::DisplaySettings display{ |
| 2547 | .physicalDisplay = displayRect, |
| 2548 | .clip = displayRect, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2549 | .outputDataspace = dataspace, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2550 | .targetLuminanceNits = 1000.f, |
| 2551 | }; |
| 2552 | |
| 2553 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2554 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2555 | const auto redBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(255, 0, 0, 255)); |
| 2556 | |
| 2557 | const renderengine::LayerSettings greenLayer{ |
| 2558 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2559 | .source = |
| 2560 | renderengine::PixelSource{ |
| 2561 | .buffer = |
| 2562 | renderengine::Buffer{ |
| 2563 | .buffer = greenBuffer, |
| 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 = 200.f, |
| 2570 | }; |
| 2571 | |
| 2572 | const renderengine::LayerSettings blueLayer{ |
| 2573 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2574 | .source = |
| 2575 | renderengine::PixelSource{ |
| 2576 | .buffer = |
| 2577 | renderengine::Buffer{ |
| 2578 | .buffer = blueBuffer, |
| 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 | .whitePointNits = 1000.f / 51.f, |
| 2585 | }; |
| 2586 | |
| 2587 | const renderengine::LayerSettings redLayer{ |
| 2588 | .geometry.boundaries = FloatRect(2.f, 0.f, 3.f, 1.f), |
| 2589 | .source = |
| 2590 | renderengine::PixelSource{ |
| 2591 | .buffer = |
| 2592 | renderengine::Buffer{ |
| 2593 | .buffer = redBuffer, |
| 2594 | .usePremultipliedAlpha = true, |
| 2595 | }, |
| 2596 | }, |
| 2597 | .alpha = 1.0f, |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2598 | .sourceDataspace = dataspace, |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2599 | // When the white point is not set for a layer, just ignore it and treat it as the same |
| 2600 | // as the max layer |
| 2601 | .whitePointNits = -1.f, |
| 2602 | }; |
| 2603 | |
| 2604 | std::vector<renderengine::LayerSettings> layers{greenLayer, blueLayer, redLayer}; |
| 2605 | invokeDraw(display, layers); |
| 2606 | |
| 2607 | expectBufferColor(Rect(1, 1), 0, 51, 0, 255, 1); |
| 2608 | expectBufferColor(Rect(1, 0, 2, 1), 0, 0, 5, 255, 1); |
| 2609 | expectBufferColor(Rect(2, 0, 3, 1), 51, 0, 0, 255, 1); |
| 2610 | } |
| 2611 | |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2612 | TEST_P(RenderEngineTest, testDimming_inGammaSpace) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2613 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2614 | GTEST_SKIP(); |
| 2615 | } |
Alec Mouri | 8506569 | 2022-03-18 00:58:26 +0000 | [diff] [blame] | 2616 | initializeRenderEngine(); |
| 2617 | |
| 2618 | const ui::Dataspace dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_BT709 | |
| 2619 | ui::Dataspace::TRANSFER_GAMMA2_2 | |
| 2620 | ui::Dataspace::RANGE_FULL); |
| 2621 | |
| 2622 | const auto displayRect = Rect(3, 1); |
| 2623 | const renderengine::DisplaySettings display{ |
| 2624 | .physicalDisplay = displayRect, |
| 2625 | .clip = displayRect, |
| 2626 | .outputDataspace = dataspace, |
| 2627 | .targetLuminanceNits = 1000.f, |
| 2628 | .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF, |
| 2629 | }; |
| 2630 | |
| 2631 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2632 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2633 | const auto redBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(255, 0, 0, 255)); |
| 2634 | |
| 2635 | const renderengine::LayerSettings greenLayer{ |
| 2636 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2637 | .source = |
| 2638 | renderengine::PixelSource{ |
| 2639 | .buffer = |
| 2640 | renderengine::Buffer{ |
| 2641 | .buffer = greenBuffer, |
| 2642 | .usePremultipliedAlpha = true, |
| 2643 | }, |
| 2644 | }, |
| 2645 | .alpha = 1.0f, |
| 2646 | .sourceDataspace = dataspace, |
| 2647 | .whitePointNits = 200.f, |
| 2648 | }; |
| 2649 | |
| 2650 | const renderengine::LayerSettings blueLayer{ |
| 2651 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2652 | .source = |
| 2653 | renderengine::PixelSource{ |
| 2654 | .buffer = |
| 2655 | renderengine::Buffer{ |
| 2656 | .buffer = blueBuffer, |
| 2657 | .usePremultipliedAlpha = true, |
| 2658 | }, |
| 2659 | }, |
| 2660 | .alpha = 1.0f, |
| 2661 | .sourceDataspace = dataspace, |
| 2662 | .whitePointNits = 1000.f / 51.f, |
| 2663 | }; |
| 2664 | |
| 2665 | const renderengine::LayerSettings redLayer{ |
| 2666 | .geometry.boundaries = FloatRect(2.f, 0.f, 3.f, 1.f), |
| 2667 | .source = |
| 2668 | renderengine::PixelSource{ |
| 2669 | .buffer = |
| 2670 | renderengine::Buffer{ |
| 2671 | .buffer = redBuffer, |
| 2672 | .usePremultipliedAlpha = true, |
| 2673 | }, |
| 2674 | }, |
| 2675 | .alpha = 1.0f, |
| 2676 | .sourceDataspace = dataspace, |
| 2677 | // When the white point is not set for a layer, just ignore it and treat it as the same |
| 2678 | // as the max layer |
| 2679 | .whitePointNits = -1.f, |
| 2680 | }; |
| 2681 | |
| 2682 | std::vector<renderengine::LayerSettings> layers{greenLayer, blueLayer, redLayer}; |
| 2683 | invokeDraw(display, layers); |
| 2684 | |
| 2685 | expectBufferColor(Rect(1, 1), 0, 122, 0, 255, 1); |
| 2686 | expectBufferColor(Rect(1, 0, 2, 1), 0, 0, 42, 255, 1); |
| 2687 | expectBufferColor(Rect(2, 0, 3, 1), 122, 0, 0, 255, 1); |
| 2688 | } |
| 2689 | |
Alec Mouri | 9bcd1d1 | 2022-04-21 22:16:56 +0000 | [diff] [blame] | 2690 | TEST_P(RenderEngineTest, testDimming_inGammaSpace_withDisplayColorTransform) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2691 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2692 | GTEST_SKIP(); |
| 2693 | } |
Alec Mouri | 9bcd1d1 | 2022-04-21 22:16:56 +0000 | [diff] [blame] | 2694 | initializeRenderEngine(); |
| 2695 | |
| 2696 | const ui::Dataspace dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_BT709 | |
| 2697 | ui::Dataspace::TRANSFER_GAMMA2_2 | |
| 2698 | ui::Dataspace::RANGE_FULL); |
| 2699 | |
| 2700 | const auto displayRect = Rect(3, 1); |
| 2701 | const renderengine::DisplaySettings display{ |
| 2702 | .physicalDisplay = displayRect, |
| 2703 | .clip = displayRect, |
| 2704 | .outputDataspace = dataspace, |
| 2705 | .colorTransform = kRemoveGreenAndMoveRedToGreenMat4, |
| 2706 | .targetLuminanceNits = 1000.f, |
| 2707 | .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF, |
| 2708 | }; |
| 2709 | |
| 2710 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2711 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2712 | const auto redBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(255, 0, 0, 255)); |
| 2713 | |
| 2714 | const renderengine::LayerSettings greenLayer{ |
| 2715 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2716 | .source = |
| 2717 | renderengine::PixelSource{ |
| 2718 | .buffer = |
| 2719 | renderengine::Buffer{ |
| 2720 | .buffer = greenBuffer, |
| 2721 | .usePremultipliedAlpha = true, |
| 2722 | }, |
| 2723 | }, |
| 2724 | .alpha = 1.0f, |
| 2725 | .sourceDataspace = dataspace, |
| 2726 | .whitePointNits = 200.f, |
| 2727 | }; |
| 2728 | |
| 2729 | const renderengine::LayerSettings redLayer{ |
| 2730 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2731 | .source = |
| 2732 | renderengine::PixelSource{ |
| 2733 | .buffer = |
| 2734 | renderengine::Buffer{ |
| 2735 | .buffer = redBuffer, |
| 2736 | .usePremultipliedAlpha = true, |
| 2737 | }, |
| 2738 | }, |
| 2739 | .alpha = 1.0f, |
| 2740 | .sourceDataspace = dataspace, |
| 2741 | // When the white point is not set for a layer, just ignore it and treat it as the same |
| 2742 | // as the max layer |
| 2743 | .whitePointNits = -1.f, |
| 2744 | }; |
| 2745 | |
| 2746 | std::vector<renderengine::LayerSettings> layers{greenLayer, redLayer}; |
| 2747 | invokeDraw(display, layers); |
| 2748 | |
| 2749 | expectBufferColor(Rect(1, 1), 0, 0, 0, 255, 1); |
| 2750 | expectBufferColor(Rect(1, 0, 2, 1), 0, 122, 0, 255, 1); |
| 2751 | } |
| 2752 | |
| 2753 | TEST_P(RenderEngineTest, testDimming_inGammaSpace_withDisplayColorTransform_deviceHandles) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2754 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2755 | GTEST_SKIP(); |
| 2756 | } |
Alec Mouri | 9bcd1d1 | 2022-04-21 22:16:56 +0000 | [diff] [blame] | 2757 | initializeRenderEngine(); |
| 2758 | |
| 2759 | const ui::Dataspace dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_BT709 | |
| 2760 | ui::Dataspace::TRANSFER_GAMMA2_2 | |
| 2761 | ui::Dataspace::RANGE_FULL); |
| 2762 | |
| 2763 | const auto displayRect = Rect(3, 1); |
| 2764 | const renderengine::DisplaySettings display{ |
| 2765 | .physicalDisplay = displayRect, |
| 2766 | .clip = displayRect, |
| 2767 | .outputDataspace = dataspace, |
| 2768 | .colorTransform = kRemoveGreenAndMoveRedToGreenMat4, |
| 2769 | .deviceHandlesColorTransform = true, |
| 2770 | .targetLuminanceNits = 1000.f, |
| 2771 | .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF, |
| 2772 | }; |
| 2773 | |
| 2774 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2775 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2776 | const auto redBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(255, 0, 0, 255)); |
| 2777 | |
| 2778 | const renderengine::LayerSettings greenLayer{ |
| 2779 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2780 | .source = |
| 2781 | renderengine::PixelSource{ |
| 2782 | .buffer = |
| 2783 | renderengine::Buffer{ |
| 2784 | .buffer = greenBuffer, |
| 2785 | .usePremultipliedAlpha = true, |
| 2786 | }, |
| 2787 | }, |
| 2788 | .alpha = 1.0f, |
| 2789 | .sourceDataspace = dataspace, |
| 2790 | .whitePointNits = 200.f, |
| 2791 | }; |
| 2792 | |
| 2793 | const renderengine::LayerSettings redLayer{ |
| 2794 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2795 | .source = |
| 2796 | renderengine::PixelSource{ |
| 2797 | .buffer = |
| 2798 | renderengine::Buffer{ |
| 2799 | .buffer = redBuffer, |
| 2800 | .usePremultipliedAlpha = true, |
| 2801 | }, |
| 2802 | }, |
| 2803 | .alpha = 1.0f, |
| 2804 | .sourceDataspace = dataspace, |
| 2805 | // When the white point is not set for a layer, just ignore it and treat it as the same |
| 2806 | // as the max layer |
| 2807 | .whitePointNits = -1.f, |
| 2808 | }; |
| 2809 | |
| 2810 | std::vector<renderengine::LayerSettings> layers{greenLayer, redLayer}; |
| 2811 | invokeDraw(display, layers); |
| 2812 | |
| 2813 | expectBufferColor(Rect(1, 1), 0, 122, 0, 255, 1); |
| 2814 | expectBufferColor(Rect(1, 0, 2, 1), 122, 0, 0, 255, 1); |
| 2815 | } |
| 2816 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2817 | TEST_P(RenderEngineTest, testDimming_withoutTargetLuminance) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2818 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2819 | GTEST_SKIP(); |
| 2820 | } |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2821 | initializeRenderEngine(); |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 2822 | |
| 2823 | const auto displayRect = Rect(2, 1); |
| 2824 | const renderengine::DisplaySettings display{ |
| 2825 | .physicalDisplay = displayRect, |
| 2826 | .clip = displayRect, |
| 2827 | .outputDataspace = ui::Dataspace::V0_SRGB_LINEAR, |
| 2828 | .targetLuminanceNits = -1.f, |
| 2829 | }; |
| 2830 | |
| 2831 | const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255)); |
| 2832 | const auto blueBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 0, 255, 255)); |
| 2833 | |
| 2834 | const renderengine::LayerSettings greenLayer{ |
| 2835 | .geometry.boundaries = FloatRect(0.f, 0.f, 1.f, 1.f), |
| 2836 | .source = |
| 2837 | renderengine::PixelSource{ |
| 2838 | .buffer = |
| 2839 | renderengine::Buffer{ |
| 2840 | .buffer = greenBuffer, |
| 2841 | .usePremultipliedAlpha = true, |
| 2842 | }, |
| 2843 | }, |
| 2844 | .alpha = 1.0f, |
| 2845 | .sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR, |
| 2846 | .whitePointNits = 200.f, |
| 2847 | }; |
| 2848 | |
| 2849 | const renderengine::LayerSettings blueLayer{ |
| 2850 | .geometry.boundaries = FloatRect(1.f, 0.f, 2.f, 1.f), |
| 2851 | .source = |
| 2852 | renderengine::PixelSource{ |
| 2853 | .buffer = |
| 2854 | renderengine::Buffer{ |
| 2855 | .buffer = blueBuffer, |
| 2856 | .usePremultipliedAlpha = true, |
| 2857 | }, |
| 2858 | }, |
| 2859 | .alpha = 1.0f, |
| 2860 | .sourceDataspace = ui::Dataspace::V0_SRGB_LINEAR, |
| 2861 | .whitePointNits = 1000.f, |
| 2862 | }; |
| 2863 | |
| 2864 | std::vector<renderengine::LayerSettings> layers{greenLayer, blueLayer}; |
| 2865 | invokeDraw(display, layers); |
| 2866 | |
| 2867 | expectBufferColor(Rect(1, 1), 0, 51, 0, 255, 1); |
| 2868 | expectBufferColor(Rect(1, 0, 2, 1), 0, 0, 255, 255); |
| 2869 | } |
| 2870 | |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 2871 | TEST_P(RenderEngineTest, test_isOpaque) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2872 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2873 | GTEST_SKIP(); |
| 2874 | } |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 2875 | initializeRenderEngine(); |
| 2876 | |
| 2877 | const auto rect = Rect(0, 0, 1, 1); |
| 2878 | const renderengine::DisplaySettings display{ |
| 2879 | .physicalDisplay = rect, |
| 2880 | .clip = rect, |
| 2881 | .outputDataspace = ui::Dataspace::DISPLAY_P3, |
| 2882 | }; |
| 2883 | |
| 2884 | // Create an unpremul buffer that is green with no alpha. Using isOpaque |
| 2885 | // should make the green show. |
| 2886 | const auto buf = allocateSourceBuffer(1, 1); |
| 2887 | { |
| 2888 | uint8_t* pixels; |
| 2889 | buf->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 2890 | reinterpret_cast<void**>(&pixels)); |
| 2891 | pixels[0] = 0; |
| 2892 | pixels[1] = 255; |
| 2893 | pixels[2] = 0; |
| 2894 | pixels[3] = 0; |
| 2895 | buf->getBuffer()->unlock(); |
| 2896 | } |
| 2897 | |
| 2898 | const renderengine::LayerSettings greenLayer{ |
| 2899 | .geometry.boundaries = rect.toFloatRect(), |
| 2900 | .source = |
| 2901 | renderengine::PixelSource{ |
| 2902 | .buffer = |
| 2903 | renderengine::Buffer{ |
| 2904 | .buffer = buf, |
| 2905 | // Although the pixels are not |
| 2906 | // premultiplied in practice, this |
| 2907 | // matches the input we see. |
| 2908 | .usePremultipliedAlpha = true, |
| 2909 | .isOpaque = true, |
| 2910 | }, |
| 2911 | }, |
| 2912 | .alpha = 1.0f, |
| 2913 | }; |
| 2914 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 2915 | std::vector<renderengine::LayerSettings> layers{greenLayer}; |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 2916 | invokeDraw(display, layers); |
| 2917 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 2918 | expectBufferColor(rect, 117, 251, 76, 255); |
Leon Scroggins III | c4e0cbd | 2021-05-25 10:25:20 -0400 | [diff] [blame] | 2919 | } |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2920 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2921 | TEST_P(RenderEngineTest, test_tonemapPQMatches) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2922 | if (!GetParam()->apiSupported()) { |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 2923 | GTEST_SKIP(); |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2926 | initializeRenderEngine(); |
| 2927 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 2928 | tonemap( |
| 2929 | static_cast<ui::Dataspace>(HAL_DATASPACE_STANDARD_BT2020 | |
| 2930 | HAL_DATASPACE_TRANSFER_ST2084 | HAL_DATASPACE_RANGE_FULL), |
| 2931 | [](vec3 color) { return EOTF_PQ(color); }, |
| 2932 | [](vec3 color, float) { |
| 2933 | static constexpr float kMaxPQLuminance = 10000.f; |
| 2934 | return color * kMaxPQLuminance; |
| 2935 | }); |
| 2936 | } |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2937 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 2938 | TEST_P(RenderEngineTest, test_tonemapHLGMatches) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2939 | if (!GetParam()->apiSupported()) { |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 2940 | GTEST_SKIP(); |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 2943 | initializeRenderEngine(); |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2944 | |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 2945 | tonemap( |
| 2946 | static_cast<ui::Dataspace>(HAL_DATASPACE_STANDARD_BT2020 | HAL_DATASPACE_TRANSFER_HLG | |
| 2947 | HAL_DATASPACE_RANGE_FULL), |
| 2948 | [](vec3 color) { return EOTF_HLG(color); }, |
| 2949 | [](vec3 color, float currentLuminaceNits) { |
| 2950 | static constexpr float kMaxHLGLuminance = 1000.f; |
Alec Mouri | 7a57745 | 2022-03-04 23:41:38 +0000 | [diff] [blame] | 2951 | return color * kMaxHLGLuminance; |
Alec Mouri | 5a49372 | 2022-01-26 16:43:02 -0800 | [diff] [blame] | 2952 | }); |
Alec Mouri | 4049b53 | 2021-10-15 20:59:33 -0700 | [diff] [blame] | 2953 | } |
Leon Scroggins III | 2c1d9ef | 2022-01-21 13:46:56 -0500 | [diff] [blame] | 2954 | |
| 2955 | TEST_P(RenderEngineTest, r8_behaves_as_mask) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 2956 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 2957 | GTEST_SKIP(); |
| 2958 | } |
Leon Scroggins III | 2c1d9ef | 2022-01-21 13:46:56 -0500 | [diff] [blame] | 2959 | initializeRenderEngine(); |
| 2960 | |
| 2961 | const auto r8Buffer = allocateR8Buffer(2, 1); |
| 2962 | if (!r8Buffer) { |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 2963 | GTEST_SKIP() << "Test is only necessary on devices that support r8"; |
Leon Scroggins III | 2c1d9ef | 2022-01-21 13:46:56 -0500 | [diff] [blame] | 2964 | return; |
| 2965 | } |
| 2966 | { |
| 2967 | uint8_t* pixels; |
| 2968 | r8Buffer->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 2969 | reinterpret_cast<void**>(&pixels)); |
| 2970 | // This will be drawn on top of a green buffer. We'll verify that 255 |
| 2971 | // results in keeping the original green and 0 results in black. |
| 2972 | pixels[0] = 0; |
| 2973 | pixels[1] = 255; |
| 2974 | r8Buffer->getBuffer()->unlock(); |
| 2975 | } |
| 2976 | |
| 2977 | const auto rect = Rect(0, 0, 2, 1); |
| 2978 | const renderengine::DisplaySettings display{ |
| 2979 | .physicalDisplay = rect, |
| 2980 | .clip = rect, |
| 2981 | .outputDataspace = ui::Dataspace::SRGB, |
| 2982 | }; |
| 2983 | |
| 2984 | const auto greenBuffer = allocateAndFillSourceBuffer(2, 1, ubyte4(0, 255, 0, 255)); |
| 2985 | const renderengine::LayerSettings greenLayer{ |
| 2986 | .geometry.boundaries = rect.toFloatRect(), |
| 2987 | .source = |
| 2988 | renderengine::PixelSource{ |
| 2989 | .buffer = |
| 2990 | renderengine::Buffer{ |
| 2991 | .buffer = greenBuffer, |
| 2992 | }, |
| 2993 | }, |
| 2994 | .alpha = 1.0f, |
| 2995 | }; |
| 2996 | const renderengine::LayerSettings r8Layer{ |
| 2997 | .geometry.boundaries = rect.toFloatRect(), |
| 2998 | .source = |
| 2999 | renderengine::PixelSource{ |
| 3000 | .buffer = |
| 3001 | renderengine::Buffer{ |
| 3002 | .buffer = r8Buffer, |
| 3003 | }, |
| 3004 | }, |
| 3005 | .alpha = 1.0f, |
| 3006 | }; |
| 3007 | |
| 3008 | std::vector<renderengine::LayerSettings> layers{greenLayer, r8Layer}; |
| 3009 | invokeDraw(display, layers); |
| 3010 | |
| 3011 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 255); |
| 3012 | expectBufferColor(Rect(1, 0, 2, 1), 0, 255, 0, 255); |
| 3013 | } |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 3014 | |
| 3015 | TEST_P(RenderEngineTest, r8_respects_color_transform) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 3016 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 3017 | GTEST_SKIP(); |
| 3018 | } |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 3019 | initializeRenderEngine(); |
| 3020 | |
| 3021 | const auto r8Buffer = allocateR8Buffer(2, 1); |
| 3022 | if (!r8Buffer) { |
| 3023 | GTEST_SKIP() << "Test is only necessary on devices that support r8"; |
| 3024 | return; |
| 3025 | } |
| 3026 | { |
| 3027 | uint8_t* pixels; |
| 3028 | r8Buffer->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 3029 | reinterpret_cast<void**>(&pixels)); |
| 3030 | pixels[0] = 0; |
| 3031 | pixels[1] = 255; |
| 3032 | r8Buffer->getBuffer()->unlock(); |
| 3033 | } |
| 3034 | |
| 3035 | const auto rect = Rect(0, 0, 2, 1); |
| 3036 | const renderengine::DisplaySettings display{ |
| 3037 | .physicalDisplay = rect, |
| 3038 | .clip = rect, |
| 3039 | .outputDataspace = ui::Dataspace::SRGB, |
| 3040 | // Verify that the R8 layer respects the color transform when |
| 3041 | // deviceHandlesColorTransform is false. This transform converts |
| 3042 | // pure red to pure green. That will occur when the R8 buffer is |
| 3043 | // 255. When the R8 buffer is 0, it will still change to black, as |
| 3044 | // with r8_behaves_as_mask. |
Alec Mouri | 9bcd1d1 | 2022-04-21 22:16:56 +0000 | [diff] [blame] | 3045 | .colorTransform = kRemoveGreenAndMoveRedToGreenMat4, |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 3046 | .deviceHandlesColorTransform = false, |
| 3047 | }; |
| 3048 | |
| 3049 | const auto redBuffer = allocateAndFillSourceBuffer(2, 1, ubyte4(255, 0, 0, 255)); |
| 3050 | const renderengine::LayerSettings redLayer{ |
| 3051 | .geometry.boundaries = rect.toFloatRect(), |
| 3052 | .source = |
| 3053 | renderengine::PixelSource{ |
| 3054 | .buffer = |
| 3055 | renderengine::Buffer{ |
| 3056 | .buffer = redBuffer, |
| 3057 | }, |
| 3058 | }, |
| 3059 | .alpha = 1.0f, |
| 3060 | }; |
| 3061 | const renderengine::LayerSettings r8Layer{ |
| 3062 | .geometry.boundaries = rect.toFloatRect(), |
| 3063 | .source = |
| 3064 | renderengine::PixelSource{ |
| 3065 | .buffer = |
| 3066 | renderengine::Buffer{ |
| 3067 | .buffer = r8Buffer, |
| 3068 | }, |
| 3069 | }, |
| 3070 | .alpha = 1.0f, |
| 3071 | }; |
| 3072 | |
| 3073 | std::vector<renderengine::LayerSettings> layers{redLayer, r8Layer}; |
| 3074 | invokeDraw(display, layers); |
| 3075 | |
| 3076 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 255); |
| 3077 | expectBufferColor(Rect(1, 0, 2, 1), 0, 255, 0, 255); |
| 3078 | } |
| 3079 | |
| 3080 | TEST_P(RenderEngineTest, r8_respects_color_transform_when_device_handles) { |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 3081 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 3082 | GTEST_SKIP(); |
| 3083 | } |
Leon Scroggins III | 745dcaa | 2022-01-26 11:55:58 -0500 | [diff] [blame] | 3084 | initializeRenderEngine(); |
| 3085 | |
| 3086 | const auto r8Buffer = allocateR8Buffer(2, 1); |
| 3087 | if (!r8Buffer) { |
| 3088 | GTEST_SKIP() << "Test is only necessary on devices that support r8"; |
| 3089 | return; |
| 3090 | } |
| 3091 | { |
| 3092 | uint8_t* pixels; |
| 3093 | r8Buffer->getBuffer()->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 3094 | reinterpret_cast<void**>(&pixels)); |
| 3095 | pixels[0] = 0; |
| 3096 | pixels[1] = 255; |
| 3097 | r8Buffer->getBuffer()->unlock(); |
| 3098 | } |
| 3099 | |
| 3100 | const auto rect = Rect(0, 0, 2, 1); |
| 3101 | const renderengine::DisplaySettings display{ |
| 3102 | .physicalDisplay = rect, |
| 3103 | .clip = rect, |
| 3104 | .outputDataspace = ui::Dataspace::SRGB, |
| 3105 | // If deviceHandlesColorTransform is true, pixels where the A8 |
| 3106 | // buffer is opaque are unaffected. If the colorTransform is |
| 3107 | // invertible, pixels where the A8 buffer are transparent have the |
| 3108 | // inverse applied to them so that the DPU will convert them back to |
| 3109 | // black. Test with an arbitrary, invertible matrix. |
| 3110 | .colorTransform = mat4(1, 0, 0, 2, |
| 3111 | 3, 1, 2, 5, |
| 3112 | 0, 5, 3, 0, |
| 3113 | 0, 1, 0, 2), |
| 3114 | .deviceHandlesColorTransform = true, |
| 3115 | }; |
| 3116 | |
| 3117 | const auto redBuffer = allocateAndFillSourceBuffer(2, 1, ubyte4(255, 0, 0, 255)); |
| 3118 | const renderengine::LayerSettings redLayer{ |
| 3119 | .geometry.boundaries = rect.toFloatRect(), |
| 3120 | .source = |
| 3121 | renderengine::PixelSource{ |
| 3122 | .buffer = |
| 3123 | renderengine::Buffer{ |
| 3124 | .buffer = redBuffer, |
| 3125 | }, |
| 3126 | }, |
| 3127 | .alpha = 1.0f, |
| 3128 | }; |
| 3129 | const renderengine::LayerSettings r8Layer{ |
| 3130 | .geometry.boundaries = rect.toFloatRect(), |
| 3131 | .source = |
| 3132 | renderengine::PixelSource{ |
| 3133 | .buffer = |
| 3134 | renderengine::Buffer{ |
| 3135 | .buffer = r8Buffer, |
| 3136 | }, |
| 3137 | }, |
| 3138 | .alpha = 1.0f, |
| 3139 | }; |
| 3140 | |
| 3141 | std::vector<renderengine::LayerSettings> layers{redLayer, r8Layer}; |
| 3142 | invokeDraw(display, layers); |
| 3143 | |
| 3144 | expectBufferColor(Rect(1, 0, 2, 1), 255, 0, 0, 255); // Still red. |
| 3145 | expectBufferColor(Rect(0, 0, 1, 1), 0, 70, 0, 255); |
| 3146 | } |
Leon Scroggins III | 45be918 | 2022-04-27 10:37:11 -0400 | [diff] [blame] | 3147 | |
| 3148 | TEST_P(RenderEngineTest, primeShaderCache) { |
Nolan Scobie | 195631a | 2024-03-26 12:22:23 -0400 | [diff] [blame^] | 3149 | // TODO: b/331447071 - Fix in Graphite and re-enable. |
| 3150 | if (GetParam()->skiaBackend() == renderengine::RenderEngine::SkiaBackend::GRAPHITE) { |
| 3151 | GTEST_SKIP(); |
| 3152 | } |
| 3153 | |
Leon Scroggins III | 696bf93 | 2024-01-24 15:21:05 -0500 | [diff] [blame] | 3154 | if (!GetParam()->apiSupported()) { |
Ian Elliott | 1f0911e | 2022-09-09 16:31:47 -0600 | [diff] [blame] | 3155 | GTEST_SKIP(); |
| 3156 | } |
Leon Scroggins III | 45be918 | 2022-04-27 10:37:11 -0400 | [diff] [blame] | 3157 | initializeRenderEngine(); |
| 3158 | |
Bruno BELANYI | b9b5b70 | 2023-10-13 13:25:11 +0000 | [diff] [blame] | 3159 | auto fut = mRE->primeCache(false); |
Leon Scroggins III | 45be918 | 2022-04-27 10:37:11 -0400 | [diff] [blame] | 3160 | if (fut.valid()) { |
| 3161 | fut.wait(); |
| 3162 | } |
| 3163 | |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3164 | static constexpr int kMinimumExpectedShadersCompiled = 60; |
Leon Scroggins III | 45be918 | 2022-04-27 10:37:11 -0400 | [diff] [blame] | 3165 | ASSERT_GT(static_cast<skia::SkiaGLRenderEngine*>(mRE.get())->reportShadersCompiled(), |
Alec Mouri | 47bcb07 | 2023-08-15 02:02:49 +0000 | [diff] [blame] | 3166 | kMinimumExpectedShadersCompiled); |
Leon Scroggins III | 45be918 | 2022-04-27 10:37:11 -0400 | [diff] [blame] | 3167 | } |
Derek Sollenberger | d3f6065 | 2021-06-11 15:34:36 -0400 | [diff] [blame] | 3168 | } // namespace renderengine |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 3169 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 3170 | |
| 3171 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 3172 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |