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