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