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