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