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