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