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