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