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