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