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