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