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