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