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