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