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