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