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