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