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