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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 21 | #include <chrono> |
| 22 | #include <condition_variable> |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 23 | #include <fstream> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 24 | |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 25 | #include <gtest/gtest.h> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 26 | #include <cutils/properties.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 27 | #include <renderengine/RenderEngine.h> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 28 | #include <sync/sync.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 29 | #include <ui/PixelFormat.h> |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 30 | #include "../gl/GLESRenderEngine.h" |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 31 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 32 | constexpr int DEFAULT_DISPLAY_WIDTH = 128; |
| 33 | constexpr int DEFAULT_DISPLAY_HEIGHT = 256; |
| 34 | constexpr int DEFAULT_DISPLAY_OFFSET = 64; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 35 | constexpr bool WRITE_BUFFER_TO_FILE_ON_FAILURE = false; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 36 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 37 | namespace android { |
| 38 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 39 | struct RenderEngineTest : public ::testing::Test { |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 40 | static void SetUpTestSuite() { |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 41 | sRE = renderengine::gl::GLESRenderEngine::create( |
| 42 | renderengine::RenderEngineCreationArgs::Builder() |
| 43 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) |
| 44 | .setImageCacheSize(1) |
| 45 | .setUseColorManagerment(false) |
| 46 | .setEnableProtectedContext(false) |
| 47 | .setPrecacheToneMapperShaderOnly(false) |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 48 | .setSupportsBackgroundBlur(true) |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 49 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) |
| 50 | .build()); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static void TearDownTestSuite() { |
| 54 | // The ordering here is important - sCurrentBuffer must live longer |
| 55 | // than RenderEngine to avoid a null reference on tear-down. |
| 56 | sRE = nullptr; |
| 57 | sCurrentBuffer = nullptr; |
| 58 | } |
| 59 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 60 | static sp<GraphicBuffer> allocateDefaultBuffer() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 61 | return new GraphicBuffer(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT, |
| 62 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 63 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 64 | GRALLOC_USAGE_HW_RENDER, |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 65 | "output"); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 68 | // Allocates a 1x1 buffer to fill with a solid color |
| 69 | static sp<GraphicBuffer> allocateSourceBuffer(uint32_t width, uint32_t height) { |
| 70 | return new GraphicBuffer(width, height, HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 71 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 72 | GRALLOC_USAGE_HW_TEXTURE, |
| 73 | "input"); |
| 74 | } |
| 75 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 76 | RenderEngineTest() { mBuffer = allocateDefaultBuffer(); } |
| 77 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 78 | ~RenderEngineTest() { |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 79 | if (WRITE_BUFFER_TO_FILE_ON_FAILURE && ::testing::Test::HasFailure()) { |
| 80 | writeBufferToFile("/data/texture_out_"); |
| 81 | } |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 82 | for (uint32_t texName : mTexNames) { |
| 83 | sRE->deleteTextures(1, &texName); |
| 84 | } |
| 85 | } |
| 86 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 87 | void writeBufferToFile(const char* basename) { |
| 88 | std::string filename(basename); |
| 89 | filename.append(::testing::UnitTest::GetInstance()->current_test_info()->name()); |
| 90 | filename.append(".ppm"); |
| 91 | std::ofstream file(filename.c_str(), std::ios::binary); |
| 92 | if (!file.is_open()) { |
| 93 | ALOGE("Unable to open file: %s", filename.c_str()); |
| 94 | ALOGE("You may need to do: \"adb shell setenforce 0\" to enable " |
| 95 | "surfaceflinger to write debug images"); |
| 96 | return; |
| 97 | } |
| 98 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 99 | uint8_t* pixels; |
| 100 | mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 101 | reinterpret_cast<void**>(&pixels)); |
| 102 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 103 | file << "P6\n"; |
| 104 | file << mBuffer->getWidth() << "\n"; |
| 105 | file << mBuffer->getHeight() << "\n"; |
| 106 | file << 255 << "\n"; |
| 107 | |
| 108 | std::vector<uint8_t> outBuffer(mBuffer->getWidth() * mBuffer->getHeight() * 3); |
| 109 | auto outPtr = reinterpret_cast<uint8_t*>(outBuffer.data()); |
| 110 | |
| 111 | for (int32_t j = 0; j < mBuffer->getHeight(); j++) { |
| 112 | const uint8_t* src = pixels + (mBuffer->getStride() * j) * 4; |
| 113 | for (int32_t i = 0; i < mBuffer->getWidth(); i++) { |
| 114 | // Only copy R, G and B components |
| 115 | outPtr[0] = src[0]; |
| 116 | outPtr[1] = src[1]; |
| 117 | outPtr[2] = src[2]; |
| 118 | outPtr += 3; |
| 119 | |
| 120 | src += 4; |
| 121 | } |
| 122 | } |
| 123 | file.write(reinterpret_cast<char*>(outBuffer.data()), outBuffer.size()); |
| 124 | mBuffer->unlock(); |
| 125 | } |
| 126 | |
| 127 | void expectBufferColor(const Region& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { |
| 128 | size_t c; |
| 129 | Rect const* rect = region.getArray(&c); |
| 130 | for (size_t i = 0; i < c; i++, rect++) { |
| 131 | expectBufferColor(*rect, r, g, b, a); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void expectBufferColor(const Rect& rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a, |
| 136 | uint8_t tolerance = 0) { |
| 137 | auto colorCompare = [tolerance](const uint8_t* colorA, const uint8_t* colorB) { |
| 138 | auto colorBitCompare = [tolerance](uint8_t a, uint8_t b) { |
| 139 | uint8_t tmp = a >= b ? a - b : b - a; |
| 140 | return tmp <= tolerance; |
| 141 | }; |
| 142 | return std::equal(colorA, colorA + 4, colorB, colorBitCompare); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 143 | }; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 144 | |
| 145 | expectBufferColor(rect, r, g, b, a, colorCompare); |
| 146 | } |
| 147 | |
| 148 | void expectBufferColor(const Rect& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a, |
| 149 | std::function<bool(const uint8_t* a, const uint8_t* b)> colorCompare) { |
| 150 | uint8_t* pixels; |
| 151 | mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 152 | reinterpret_cast<void**>(&pixels)); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 153 | int32_t maxFails = 10; |
| 154 | int32_t fails = 0; |
| 155 | for (int32_t j = 0; j < region.getHeight(); j++) { |
| 156 | const uint8_t* src = |
| 157 | pixels + (mBuffer->getStride() * (region.top + j) + region.left) * 4; |
| 158 | for (int32_t i = 0; i < region.getWidth(); i++) { |
| 159 | const uint8_t expected[4] = {r, g, b, a}; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 160 | bool equal = colorCompare(src, expected); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 161 | EXPECT_TRUE(equal) |
| 162 | << "pixel @ (" << region.left + i << ", " << region.top + j << "): " |
| 163 | << "expected (" << static_cast<uint32_t>(r) << ", " |
| 164 | << static_cast<uint32_t>(g) << ", " << static_cast<uint32_t>(b) << ", " |
| 165 | << static_cast<uint32_t>(a) << "), " |
| 166 | << "got (" << static_cast<uint32_t>(src[0]) << ", " |
| 167 | << static_cast<uint32_t>(src[1]) << ", " << static_cast<uint32_t>(src[2]) |
| 168 | << ", " << static_cast<uint32_t>(src[3]) << ")"; |
| 169 | src += 4; |
| 170 | if (!equal && ++fails >= maxFails) { |
| 171 | break; |
| 172 | } |
| 173 | } |
| 174 | if (fails >= maxFails) { |
| 175 | break; |
| 176 | } |
| 177 | } |
| 178 | mBuffer->unlock(); |
| 179 | } |
| 180 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 181 | void expectAlpha(const Rect& rect, uint8_t a) { |
| 182 | auto colorCompare = [](const uint8_t* colorA, const uint8_t* colorB) { |
| 183 | return colorA[3] == colorB[3]; |
| 184 | }; |
| 185 | expectBufferColor(rect, 0.0f /* r */, 0.0f /*g */, 0.0f /* b */, a, colorCompare); |
| 186 | } |
| 187 | |
| 188 | void expectShadowColor(const renderengine::LayerSettings& castingLayer, |
| 189 | const renderengine::ShadowSettings& shadow, const ubyte4& casterColor, |
| 190 | const ubyte4& backgroundColor) { |
| 191 | const Rect casterRect(castingLayer.geometry.boundaries); |
| 192 | Region casterRegion = Region(casterRect); |
| 193 | const float casterCornerRadius = castingLayer.geometry.roundedCornersRadius; |
| 194 | if (casterCornerRadius > 0.0f) { |
| 195 | // ignore the corners if a corner radius is set |
| 196 | Rect cornerRect(casterCornerRadius, casterCornerRadius); |
| 197 | casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.left, casterRect.top)); |
| 198 | casterRegion.subtractSelf( |
| 199 | cornerRect.offsetTo(casterRect.right - casterCornerRadius, casterRect.top)); |
| 200 | casterRegion.subtractSelf( |
| 201 | cornerRect.offsetTo(casterRect.left, casterRect.bottom - casterCornerRadius)); |
| 202 | casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.right - casterCornerRadius, |
| 203 | casterRect.bottom - casterCornerRadius)); |
| 204 | } |
| 205 | |
| 206 | const float shadowInset = shadow.length * -1.0f; |
| 207 | const Rect casterWithShadow = |
| 208 | Rect(casterRect).inset(shadowInset, shadowInset, shadowInset, shadowInset); |
| 209 | const Region shadowRegion = Region(casterWithShadow).subtractSelf(casterRect); |
| 210 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); |
| 211 | |
| 212 | // verify casting layer |
| 213 | expectBufferColor(casterRegion, casterColor.r, casterColor.g, casterColor.b, casterColor.a); |
| 214 | |
| 215 | // verify shadows by testing just the alpha since its difficult to validate the shadow color |
| 216 | size_t c; |
| 217 | Rect const* r = shadowRegion.getArray(&c); |
| 218 | for (size_t i = 0; i < c; i++, r++) { |
| 219 | expectAlpha(*r, 255); |
| 220 | } |
| 221 | |
| 222 | // verify background |
| 223 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, |
| 224 | backgroundColor.a); |
| 225 | } |
| 226 | |
| 227 | static renderengine::ShadowSettings getShadowSettings(const vec2& casterPos, float shadowLength, |
| 228 | bool casterIsTranslucent) { |
| 229 | renderengine::ShadowSettings shadow; |
| 230 | shadow.ambientColor = {0.0f, 0.0f, 0.0f, 0.039f}; |
| 231 | shadow.spotColor = {0.0f, 0.0f, 0.0f, 0.19f}; |
| 232 | shadow.lightPos = vec3(casterPos.x, casterPos.y, 0); |
| 233 | shadow.lightRadius = 0.0f; |
| 234 | shadow.length = shadowLength; |
| 235 | shadow.casterIsTranslucent = casterIsTranslucent; |
| 236 | return shadow; |
| 237 | } |
| 238 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 239 | static Rect fullscreenRect() { return Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); } |
| 240 | |
| 241 | static Rect offsetRect() { |
| 242 | return Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, |
| 243 | DEFAULT_DISPLAY_HEIGHT); |
| 244 | } |
| 245 | |
| 246 | static Rect offsetRectAtZero() { |
| 247 | return Rect(DEFAULT_DISPLAY_WIDTH - DEFAULT_DISPLAY_OFFSET, |
| 248 | DEFAULT_DISPLAY_HEIGHT - DEFAULT_DISPLAY_OFFSET); |
| 249 | } |
| 250 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 251 | void invokeDraw(renderengine::DisplaySettings settings, |
| 252 | std::vector<renderengine::LayerSettings> layers, sp<GraphicBuffer> buffer) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 253 | base::unique_fd fence; |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 254 | status_t status = sRE->drawLayers(settings, layers, buffer->getNativeBuffer(), true, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 255 | base::unique_fd(), &fence); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 256 | sCurrentBuffer = buffer; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 257 | |
| 258 | int fd = fence.release(); |
| 259 | if (fd >= 0) { |
| 260 | sync_wait(fd, -1); |
| 261 | close(fd); |
| 262 | } |
| 263 | |
| 264 | ASSERT_EQ(NO_ERROR, status); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 265 | if (layers.size() > 0) { |
| 266 | ASSERT_TRUE(sRE->isFramebufferImageCachedForTesting(buffer->getId())); |
| 267 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 270 | void drawEmptyLayers() { |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 271 | renderengine::DisplaySettings settings; |
| 272 | std::vector<renderengine::LayerSettings> layers; |
| 273 | // Meaningless buffer since we don't do any drawing |
| 274 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 275 | invokeDraw(settings, layers, buffer); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 278 | template <typename SourceVariant> |
| 279 | void fillBuffer(half r, half g, half b, half a); |
| 280 | |
| 281 | template <typename SourceVariant> |
| 282 | void fillRedBuffer(); |
| 283 | |
| 284 | template <typename SourceVariant> |
| 285 | void fillGreenBuffer(); |
| 286 | |
| 287 | template <typename SourceVariant> |
| 288 | void fillBlueBuffer(); |
| 289 | |
| 290 | template <typename SourceVariant> |
| 291 | void fillRedTransparentBuffer(); |
| 292 | |
| 293 | template <typename SourceVariant> |
| 294 | void fillRedOffsetBuffer(); |
| 295 | |
| 296 | template <typename SourceVariant> |
| 297 | void fillBufferPhysicalOffset(); |
| 298 | |
| 299 | template <typename SourceVariant> |
| 300 | void fillBufferCheckers(mat4 transform); |
| 301 | |
| 302 | template <typename SourceVariant> |
| 303 | void fillBufferCheckersRotate0(); |
| 304 | |
| 305 | template <typename SourceVariant> |
| 306 | void fillBufferCheckersRotate90(); |
| 307 | |
| 308 | template <typename SourceVariant> |
| 309 | void fillBufferCheckersRotate180(); |
| 310 | |
| 311 | template <typename SourceVariant> |
| 312 | void fillBufferCheckersRotate270(); |
| 313 | |
| 314 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 315 | void fillBufferWithLayerTransform(); |
| 316 | |
| 317 | template <typename SourceVariant> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 318 | void fillBufferLayerTransform(); |
| 319 | |
| 320 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 321 | void fillBufferWithColorTransform(); |
| 322 | |
| 323 | template <typename SourceVariant> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 324 | void fillBufferColorTransform(); |
| 325 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 326 | template <typename SourceVariant> |
| 327 | void fillRedBufferWithRoundedCorners(); |
| 328 | |
| 329 | template <typename SourceVariant> |
| 330 | void fillBufferWithRoundedCorners(); |
| 331 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 332 | template <typename SourceVariant> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 333 | void fillBufferAndBlurBackground(); |
| 334 | |
| 335 | template <typename SourceVariant> |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 336 | void overlayCorners(); |
| 337 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 338 | void fillRedBufferTextureTransform(); |
| 339 | |
| 340 | void fillBufferTextureTransform(); |
| 341 | |
| 342 | void fillRedBufferWithPremultiplyAlpha(); |
| 343 | |
| 344 | void fillBufferWithPremultiplyAlpha(); |
| 345 | |
| 346 | void fillRedBufferWithoutPremultiplyAlpha(); |
| 347 | |
| 348 | void fillBufferWithoutPremultiplyAlpha(); |
| 349 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 350 | void fillGreenColorBufferThenClearRegion(); |
| 351 | |
| 352 | void clearLeftRegion(); |
| 353 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 354 | void clearRegion(); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 355 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 356 | template <typename SourceVariant> |
| 357 | void drawShadow(const renderengine::LayerSettings& castingLayer, |
| 358 | const renderengine::ShadowSettings& shadow, const ubyte4& casterColor, |
| 359 | const ubyte4& backgroundColor); |
| 360 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 361 | // Keep around the same renderengine object to save on initialization time. |
| 362 | // For now, exercise the GL backend directly so that some caching specifics |
| 363 | // can be tested without changing the interface. |
| 364 | static std::unique_ptr<renderengine::gl::GLESRenderEngine> sRE; |
| 365 | // Dumb hack to avoid NPE in the EGL driver: the GraphicBuffer needs to |
| 366 | // be freed *after* RenderEngine is destroyed, so that the EGL image is |
| 367 | // destroyed first. |
| 368 | static sp<GraphicBuffer> sCurrentBuffer; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 369 | |
| 370 | sp<GraphicBuffer> mBuffer; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 371 | |
| 372 | std::vector<uint32_t> mTexNames; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 373 | }; |
| 374 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 375 | std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRE = nullptr; |
| 376 | sp<GraphicBuffer> RenderEngineTest::sCurrentBuffer = nullptr; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 377 | |
| 378 | struct ColorSourceVariant { |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 379 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
| 380 | RenderEngineTest* /*fixture*/) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 381 | layer.source.solidColor = half3(r, g, b); |
| 382 | } |
| 383 | }; |
| 384 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 385 | struct RelaxOpaqueBufferVariant { |
| 386 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 387 | layer.source.buffer.isOpaque = false; |
| 388 | } |
| 389 | |
| 390 | static uint8_t getAlphaChannel() { return 255; } |
| 391 | }; |
| 392 | |
| 393 | struct ForceOpaqueBufferVariant { |
| 394 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 395 | layer.source.buffer.isOpaque = true; |
| 396 | } |
| 397 | |
| 398 | static uint8_t getAlphaChannel() { |
| 399 | // The isOpaque bit will override the alpha channel, so this should be |
| 400 | // arbitrary. |
| 401 | return 10; |
| 402 | } |
| 403 | }; |
| 404 | |
| 405 | template <typename OpaquenessVariant> |
| 406 | struct BufferSourceVariant { |
| 407 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
| 408 | RenderEngineTest* fixture) { |
| 409 | sp<GraphicBuffer> buf = RenderEngineTest::allocateSourceBuffer(1, 1); |
| 410 | uint32_t texName; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 411 | fixture->sRE->genTextures(1, &texName); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 412 | fixture->mTexNames.push_back(texName); |
| 413 | |
| 414 | uint8_t* pixels; |
| 415 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 416 | reinterpret_cast<void**>(&pixels)); |
| 417 | |
| 418 | for (int32_t j = 0; j < buf->getHeight(); j++) { |
| 419 | uint8_t* iter = pixels + (buf->getStride() * j) * 4; |
| 420 | for (int32_t i = 0; i < buf->getWidth(); i++) { |
| 421 | iter[0] = uint8_t(r * 255); |
| 422 | iter[1] = uint8_t(g * 255); |
| 423 | iter[2] = uint8_t(b * 255); |
| 424 | iter[3] = OpaquenessVariant::getAlphaChannel(); |
| 425 | iter += 4; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | buf->unlock(); |
| 430 | |
| 431 | layer.source.buffer.buffer = buf; |
| 432 | layer.source.buffer.textureName = texName; |
| 433 | OpaquenessVariant::setOpaqueBit(layer); |
| 434 | } |
| 435 | }; |
| 436 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 437 | template <typename SourceVariant> |
| 438 | void RenderEngineTest::fillBuffer(half r, half g, half b, half a) { |
| 439 | renderengine::DisplaySettings settings; |
| 440 | settings.physicalDisplay = fullscreenRect(); |
| 441 | settings.clip = fullscreenRect(); |
| 442 | |
| 443 | std::vector<renderengine::LayerSettings> layers; |
| 444 | |
| 445 | renderengine::LayerSettings layer; |
| 446 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 447 | SourceVariant::fillColor(layer, r, g, b, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 448 | layer.alpha = a; |
| 449 | |
| 450 | layers.push_back(layer); |
| 451 | |
| 452 | invokeDraw(settings, layers, mBuffer); |
| 453 | } |
| 454 | |
| 455 | template <typename SourceVariant> |
| 456 | void RenderEngineTest::fillRedBuffer() { |
| 457 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, 1.0f); |
| 458 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 459 | } |
| 460 | |
| 461 | template <typename SourceVariant> |
| 462 | void RenderEngineTest::fillGreenBuffer() { |
| 463 | fillBuffer<SourceVariant>(0.0f, 1.0f, 0.0f, 1.0f); |
| 464 | expectBufferColor(fullscreenRect(), 0, 255, 0, 255); |
| 465 | } |
| 466 | |
| 467 | template <typename SourceVariant> |
| 468 | void RenderEngineTest::fillBlueBuffer() { |
| 469 | fillBuffer<SourceVariant>(0.0f, 0.0f, 1.0f, 1.0f); |
| 470 | expectBufferColor(fullscreenRect(), 0, 0, 255, 255); |
| 471 | } |
| 472 | |
| 473 | template <typename SourceVariant> |
| 474 | void RenderEngineTest::fillRedTransparentBuffer() { |
| 475 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, .2f); |
| 476 | expectBufferColor(fullscreenRect(), 51, 0, 0, 51); |
| 477 | } |
| 478 | |
| 479 | template <typename SourceVariant> |
| 480 | void RenderEngineTest::fillRedOffsetBuffer() { |
| 481 | renderengine::DisplaySettings settings; |
| 482 | settings.physicalDisplay = offsetRect(); |
| 483 | settings.clip = offsetRectAtZero(); |
| 484 | |
| 485 | std::vector<renderengine::LayerSettings> layers; |
| 486 | |
| 487 | renderengine::LayerSettings layer; |
| 488 | layer.geometry.boundaries = offsetRectAtZero().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 489 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 490 | layer.alpha = 1.0f; |
| 491 | |
| 492 | layers.push_back(layer); |
| 493 | invokeDraw(settings, layers, mBuffer); |
| 494 | } |
| 495 | |
| 496 | template <typename SourceVariant> |
| 497 | void RenderEngineTest::fillBufferPhysicalOffset() { |
| 498 | fillRedOffsetBuffer<SourceVariant>(); |
| 499 | |
| 500 | expectBufferColor(Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, |
| 501 | DEFAULT_DISPLAY_HEIGHT), |
| 502 | 255, 0, 0, 255); |
| 503 | Rect offsetRegionLeft(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_HEIGHT); |
| 504 | Rect offsetRegionTop(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_OFFSET); |
| 505 | |
| 506 | expectBufferColor(offsetRegionLeft, 0, 0, 0, 0); |
| 507 | expectBufferColor(offsetRegionTop, 0, 0, 0, 0); |
| 508 | } |
| 509 | |
| 510 | template <typename SourceVariant> |
| 511 | void RenderEngineTest::fillBufferCheckers(mat4 transform) { |
| 512 | renderengine::DisplaySettings settings; |
| 513 | settings.physicalDisplay = fullscreenRect(); |
| 514 | // Here logical space is 2x2 |
| 515 | settings.clip = Rect(2, 2); |
| 516 | settings.globalTransform = transform; |
| 517 | |
| 518 | std::vector<renderengine::LayerSettings> layers; |
| 519 | |
| 520 | renderengine::LayerSettings layerOne; |
| 521 | Rect rectOne(0, 0, 1, 1); |
| 522 | layerOne.geometry.boundaries = rectOne.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 523 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 524 | layerOne.alpha = 1.0f; |
| 525 | |
| 526 | renderengine::LayerSettings layerTwo; |
| 527 | Rect rectTwo(0, 1, 1, 2); |
| 528 | layerTwo.geometry.boundaries = rectTwo.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 529 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 530 | layerTwo.alpha = 1.0f; |
| 531 | |
| 532 | renderengine::LayerSettings layerThree; |
| 533 | Rect rectThree(1, 0, 2, 1); |
| 534 | layerThree.geometry.boundaries = rectThree.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 535 | SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 536 | layerThree.alpha = 1.0f; |
| 537 | |
| 538 | layers.push_back(layerOne); |
| 539 | layers.push_back(layerTwo); |
| 540 | layers.push_back(layerThree); |
| 541 | |
| 542 | invokeDraw(settings, layers, mBuffer); |
| 543 | } |
| 544 | |
| 545 | template <typename SourceVariant> |
| 546 | void RenderEngineTest::fillBufferCheckersRotate0() { |
| 547 | fillBufferCheckers<SourceVariant>(mat4()); |
| 548 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, |
| 549 | 255); |
| 550 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 551 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 552 | 0, 0, 255, 255); |
| 553 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 554 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 555 | 0, 0, 0, 0); |
| 556 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 557 | DEFAULT_DISPLAY_HEIGHT), |
| 558 | 0, 255, 0, 255); |
| 559 | } |
| 560 | |
| 561 | template <typename SourceVariant> |
| 562 | void RenderEngineTest::fillBufferCheckersRotate90() { |
| 563 | mat4 matrix = mat4(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 1); |
| 564 | fillBufferCheckers<SourceVariant>(matrix); |
| 565 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 255, 0, |
| 566 | 255); |
| 567 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 568 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 569 | 255, 0, 0, 255); |
| 570 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 571 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 572 | 0, 0, 255, 255); |
| 573 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 574 | DEFAULT_DISPLAY_HEIGHT), |
| 575 | 0, 0, 0, 0); |
| 576 | } |
| 577 | |
| 578 | template <typename SourceVariant> |
| 579 | void RenderEngineTest::fillBufferCheckersRotate180() { |
| 580 | mat4 matrix = mat4(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 2, 2, 0, 1); |
| 581 | fillBufferCheckers<SourceVariant>(matrix); |
| 582 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, |
| 583 | 0); |
| 584 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 585 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 586 | 0, 255, 0, 255); |
| 587 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 588 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 589 | 255, 0, 0, 255); |
| 590 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 591 | DEFAULT_DISPLAY_HEIGHT), |
| 592 | 0, 0, 255, 255); |
| 593 | } |
| 594 | |
| 595 | template <typename SourceVariant> |
| 596 | void RenderEngineTest::fillBufferCheckersRotate270() { |
| 597 | mat4 matrix = mat4(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1); |
| 598 | fillBufferCheckers<SourceVariant>(matrix); |
| 599 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255, |
| 600 | 255); |
| 601 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 602 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 603 | 0, 0, 0, 0); |
| 604 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 605 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 606 | 0, 255, 0, 255); |
| 607 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 608 | DEFAULT_DISPLAY_HEIGHT), |
| 609 | 255, 0, 0, 255); |
| 610 | } |
| 611 | |
| 612 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 613 | void RenderEngineTest::fillBufferWithLayerTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 614 | renderengine::DisplaySettings settings; |
| 615 | settings.physicalDisplay = fullscreenRect(); |
| 616 | // Here logical space is 2x2 |
| 617 | settings.clip = Rect(2, 2); |
| 618 | |
| 619 | std::vector<renderengine::LayerSettings> layers; |
| 620 | |
| 621 | renderengine::LayerSettings layer; |
| 622 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 623 | // Translate one pixel diagonally |
| 624 | 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] | 625 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 626 | layer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 627 | layer.alpha = 1.0f; |
| 628 | |
| 629 | layers.push_back(layer); |
| 630 | |
| 631 | invokeDraw(settings, layers, mBuffer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 632 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 633 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 634 | template <typename SourceVariant> |
| 635 | void RenderEngineTest::fillBufferLayerTransform() { |
| 636 | fillBufferWithLayerTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 637 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, 0); |
| 638 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 639 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 640 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 641 | 255, 0, 0, 255); |
| 642 | } |
| 643 | |
| 644 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 645 | void RenderEngineTest::fillBufferWithColorTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 646 | renderengine::DisplaySettings settings; |
| 647 | settings.physicalDisplay = fullscreenRect(); |
| 648 | settings.clip = Rect(1, 1); |
| 649 | |
| 650 | std::vector<renderengine::LayerSettings> layers; |
| 651 | |
| 652 | renderengine::LayerSettings layer; |
| 653 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 654 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 655 | layer.alpha = 1.0f; |
| 656 | |
| 657 | // construct a fake color matrix |
| 658 | // annihilate green and blue channels |
| 659 | settings.colorTransform = mat4::scale(vec4(1, 0, 0, 1)); |
| 660 | // set red channel to red + green |
| 661 | layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 662 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 663 | layer.alpha = 1.0f; |
| 664 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 665 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 666 | layers.push_back(layer); |
| 667 | |
| 668 | invokeDraw(settings, layers, mBuffer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 669 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 670 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 671 | template <typename SourceVariant> |
| 672 | void RenderEngineTest::fillBufferColorTransform() { |
| 673 | fillBufferWithColorTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 674 | expectBufferColor(fullscreenRect(), 191, 0, 0, 255); |
| 675 | } |
| 676 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 677 | template <typename SourceVariant> |
| 678 | void RenderEngineTest::fillRedBufferWithRoundedCorners() { |
| 679 | renderengine::DisplaySettings settings; |
| 680 | settings.physicalDisplay = fullscreenRect(); |
| 681 | settings.clip = fullscreenRect(); |
| 682 | |
| 683 | std::vector<renderengine::LayerSettings> layers; |
| 684 | |
| 685 | renderengine::LayerSettings layer; |
| 686 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 687 | layer.geometry.roundedCornersRadius = 5.0f; |
| 688 | layer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 689 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 690 | layer.alpha = 1.0f; |
| 691 | |
| 692 | layers.push_back(layer); |
| 693 | |
| 694 | invokeDraw(settings, layers, mBuffer); |
| 695 | } |
| 696 | |
| 697 | template <typename SourceVariant> |
| 698 | void RenderEngineTest::fillBufferWithRoundedCorners() { |
| 699 | fillRedBufferWithRoundedCorners<SourceVariant>(); |
| 700 | // Corners should be ignored... |
| 701 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); |
| 702 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); |
| 703 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 704 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, |
| 705 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 706 | 0, 0, 0, 0); |
| 707 | // ...And the non-rounded portion should be red. |
| 708 | // Other pixels may be anti-aliased, so let's not check those. |
| 709 | expectBufferColor(Rect(5, 5, DEFAULT_DISPLAY_WIDTH - 5, DEFAULT_DISPLAY_HEIGHT - 5), 255, 0, 0, |
| 710 | 255); |
| 711 | } |
| 712 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 713 | template <typename SourceVariant> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 714 | void RenderEngineTest::fillBufferAndBlurBackground() { |
| 715 | char value[PROPERTY_VALUE_MAX]; |
| 716 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 717 | if (!atoi(value)) { |
| 718 | // This device doesn't support blurs, no-op. |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | auto blurRadius = 50; |
| 723 | auto center = DEFAULT_DISPLAY_WIDTH / 2; |
| 724 | |
| 725 | renderengine::DisplaySettings settings; |
| 726 | settings.physicalDisplay = fullscreenRect(); |
| 727 | settings.clip = fullscreenRect(); |
| 728 | |
| 729 | std::vector<renderengine::LayerSettings> layers; |
| 730 | |
| 731 | renderengine::LayerSettings backgroundLayer; |
| 732 | backgroundLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 733 | SourceVariant::fillColor(backgroundLayer, 0.0f, 1.0f, 0.0f, this); |
| 734 | backgroundLayer.alpha = 1.0f; |
| 735 | layers.push_back(backgroundLayer); |
| 736 | |
| 737 | renderengine::LayerSettings leftLayer; |
| 738 | leftLayer.geometry.boundaries = |
| 739 | Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT).toFloatRect(); |
| 740 | SourceVariant::fillColor(leftLayer, 1.0f, 0.0f, 0.0f, this); |
| 741 | leftLayer.alpha = 1.0f; |
| 742 | layers.push_back(leftLayer); |
| 743 | |
| 744 | renderengine::LayerSettings blurLayer; |
| 745 | blurLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 746 | blurLayer.backgroundBlurRadius = blurRadius; |
| 747 | blurLayer.alpha = 0; |
| 748 | layers.push_back(blurLayer); |
| 749 | |
| 750 | invokeDraw(settings, layers, mBuffer); |
| 751 | |
| 752 | expectBufferColor(Rect(center - 1, center - 5, center, center + 5), 150, 150, 0, 255, |
| 753 | 50 /* tolerance */); |
| 754 | expectBufferColor(Rect(center, center - 5, center + 1, center + 5), 150, 150, 0, 255, |
| 755 | 50 /* tolerance */); |
| 756 | } |
| 757 | |
| 758 | template <typename SourceVariant> |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 759 | void RenderEngineTest::overlayCorners() { |
| 760 | renderengine::DisplaySettings settings; |
| 761 | settings.physicalDisplay = fullscreenRect(); |
| 762 | settings.clip = fullscreenRect(); |
| 763 | |
| 764 | std::vector<renderengine::LayerSettings> layersFirst; |
| 765 | |
| 766 | renderengine::LayerSettings layerOne; |
| 767 | layerOne.geometry.boundaries = |
| 768 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0); |
| 769 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
| 770 | layerOne.alpha = 0.2; |
| 771 | |
| 772 | layersFirst.push_back(layerOne); |
| 773 | invokeDraw(settings, layersFirst, mBuffer); |
| 774 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51); |
| 775 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 776 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 777 | 0, 0, 0, 0); |
| 778 | |
| 779 | std::vector<renderengine::LayerSettings> layersSecond; |
| 780 | renderengine::LayerSettings layerTwo; |
| 781 | layerTwo.geometry.boundaries = |
| 782 | FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0, |
| 783 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); |
| 784 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
| 785 | layerTwo.alpha = 1.0f; |
| 786 | |
| 787 | layersSecond.push_back(layerTwo); |
| 788 | invokeDraw(settings, layersSecond, mBuffer); |
| 789 | |
| 790 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0); |
| 791 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 792 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 793 | 0, 255, 0, 255); |
| 794 | } |
| 795 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 796 | void RenderEngineTest::fillRedBufferTextureTransform() { |
| 797 | renderengine::DisplaySettings settings; |
| 798 | settings.physicalDisplay = fullscreenRect(); |
| 799 | settings.clip = Rect(1, 1); |
| 800 | |
| 801 | std::vector<renderengine::LayerSettings> layers; |
| 802 | |
| 803 | renderengine::LayerSettings layer; |
| 804 | // Here will allocate a checker board texture, but transform texture |
| 805 | // coordinates so that only the upper left is applied. |
| 806 | sp<GraphicBuffer> buf = allocateSourceBuffer(2, 2); |
| 807 | uint32_t texName; |
| 808 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 809 | this->mTexNames.push_back(texName); |
| 810 | |
| 811 | uint8_t* pixels; |
| 812 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 813 | reinterpret_cast<void**>(&pixels)); |
| 814 | // Red top left, Green top right, Blue bottom left, Black bottom right |
| 815 | pixels[0] = 255; |
| 816 | pixels[1] = 0; |
| 817 | pixels[2] = 0; |
| 818 | pixels[3] = 255; |
| 819 | pixels[4] = 0; |
| 820 | pixels[5] = 255; |
| 821 | pixels[6] = 0; |
| 822 | pixels[7] = 255; |
| 823 | pixels[8] = 0; |
| 824 | pixels[9] = 0; |
| 825 | pixels[10] = 255; |
| 826 | pixels[11] = 255; |
| 827 | buf->unlock(); |
| 828 | |
| 829 | layer.source.buffer.buffer = buf; |
| 830 | layer.source.buffer.textureName = texName; |
| 831 | // Transform coordinates to only be inside the red quadrant. |
| 832 | layer.source.buffer.textureTransform = mat4::scale(vec4(0.2, 0.2, 1, 1)); |
| 833 | layer.alpha = 1.0f; |
| 834 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 835 | |
| 836 | layers.push_back(layer); |
| 837 | |
| 838 | invokeDraw(settings, layers, mBuffer); |
| 839 | } |
| 840 | |
| 841 | void RenderEngineTest::fillBufferTextureTransform() { |
| 842 | fillRedBufferTextureTransform(); |
| 843 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 844 | } |
| 845 | |
| 846 | void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() { |
| 847 | renderengine::DisplaySettings settings; |
| 848 | settings.physicalDisplay = fullscreenRect(); |
| 849 | // Here logical space is 1x1 |
| 850 | settings.clip = Rect(1, 1); |
| 851 | |
| 852 | std::vector<renderengine::LayerSettings> layers; |
| 853 | |
| 854 | renderengine::LayerSettings layer; |
| 855 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 856 | uint32_t texName; |
| 857 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 858 | this->mTexNames.push_back(texName); |
| 859 | |
| 860 | uint8_t* pixels; |
| 861 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 862 | reinterpret_cast<void**>(&pixels)); |
| 863 | pixels[0] = 255; |
| 864 | pixels[1] = 0; |
| 865 | pixels[2] = 0; |
| 866 | pixels[3] = 255; |
| 867 | buf->unlock(); |
| 868 | |
| 869 | layer.source.buffer.buffer = buf; |
| 870 | layer.source.buffer.textureName = texName; |
| 871 | layer.source.buffer.usePremultipliedAlpha = true; |
| 872 | layer.alpha = 0.5f; |
| 873 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 874 | |
| 875 | layers.push_back(layer); |
| 876 | |
| 877 | invokeDraw(settings, layers, mBuffer); |
| 878 | } |
| 879 | |
| 880 | void RenderEngineTest::fillBufferWithPremultiplyAlpha() { |
| 881 | fillRedBufferWithPremultiplyAlpha(); |
| 882 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128); |
| 883 | } |
| 884 | |
| 885 | void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() { |
| 886 | renderengine::DisplaySettings settings; |
| 887 | settings.physicalDisplay = fullscreenRect(); |
| 888 | // Here logical space is 1x1 |
| 889 | settings.clip = Rect(1, 1); |
| 890 | |
| 891 | std::vector<renderengine::LayerSettings> layers; |
| 892 | |
| 893 | renderengine::LayerSettings layer; |
| 894 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 895 | uint32_t texName; |
| 896 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 897 | this->mTexNames.push_back(texName); |
| 898 | |
| 899 | uint8_t* pixels; |
| 900 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 901 | reinterpret_cast<void**>(&pixels)); |
| 902 | pixels[0] = 255; |
| 903 | pixels[1] = 0; |
| 904 | pixels[2] = 0; |
| 905 | pixels[3] = 255; |
| 906 | buf->unlock(); |
| 907 | |
| 908 | layer.source.buffer.buffer = buf; |
| 909 | layer.source.buffer.textureName = texName; |
| 910 | layer.source.buffer.usePremultipliedAlpha = false; |
| 911 | layer.alpha = 0.5f; |
| 912 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 913 | |
| 914 | layers.push_back(layer); |
| 915 | |
| 916 | invokeDraw(settings, layers, mBuffer); |
| 917 | } |
| 918 | |
| 919 | void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() { |
| 920 | fillRedBufferWithoutPremultiplyAlpha(); |
| 921 | expectBufferColor(fullscreenRect(), 128, 0, 0, 64, 1); |
| 922 | } |
| 923 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 924 | void RenderEngineTest::clearLeftRegion() { |
| 925 | renderengine::DisplaySettings settings; |
| 926 | settings.physicalDisplay = fullscreenRect(); |
| 927 | // Here logical space is 4x4 |
| 928 | settings.clip = Rect(4, 4); |
| 929 | settings.globalTransform = mat4::scale(vec4(2, 4, 0, 1)); |
| 930 | settings.clearRegion = Region(Rect(1, 1)); |
| 931 | std::vector<renderengine::LayerSettings> layers; |
| 932 | // dummy layer, without bounds should not render anything |
| 933 | renderengine::LayerSettings layer; |
| 934 | layers.push_back(layer); |
| 935 | invokeDraw(settings, layers, mBuffer); |
| 936 | } |
| 937 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 938 | void RenderEngineTest::clearRegion() { |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 939 | // Reuse mBuffer |
| 940 | clearLeftRegion(); |
| 941 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 255); |
| 942 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 943 | DEFAULT_DISPLAY_HEIGHT), |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 944 | 0, 0, 0, 0); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 945 | } |
| 946 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 947 | template <typename SourceVariant> |
| 948 | void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer, |
| 949 | const renderengine::ShadowSettings& shadow, |
| 950 | const ubyte4& casterColor, const ubyte4& backgroundColor) { |
| 951 | renderengine::DisplaySettings settings; |
| 952 | settings.physicalDisplay = fullscreenRect(); |
| 953 | settings.clip = fullscreenRect(); |
| 954 | |
| 955 | std::vector<renderengine::LayerSettings> layers; |
| 956 | |
| 957 | // add background layer |
| 958 | renderengine::LayerSettings bgLayer; |
| 959 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 960 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 961 | backgroundColor.b / 255.0f, this); |
| 962 | bgLayer.alpha = backgroundColor.a / 255.0f; |
| 963 | layers.push_back(bgLayer); |
| 964 | |
| 965 | // add shadow layer |
| 966 | renderengine::LayerSettings shadowLayer; |
| 967 | shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries; |
| 968 | shadowLayer.alpha = castingLayer.alpha; |
| 969 | shadowLayer.shadow = shadow; |
| 970 | layers.push_back(shadowLayer); |
| 971 | |
| 972 | // add layer casting the shadow |
| 973 | renderengine::LayerSettings layer = castingLayer; |
| 974 | SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f, |
| 975 | casterColor.b / 255.0f, this); |
| 976 | layers.push_back(layer); |
| 977 | |
| 978 | invokeDraw(settings, layers, mBuffer); |
| 979 | } |
| 980 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 981 | TEST_F(RenderEngineTest, drawLayers_noLayersToDraw) { |
| 982 | drawEmptyLayers(); |
| 983 | } |
| 984 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 985 | TEST_F(RenderEngineTest, drawLayers_nullOutputBuffer) { |
| 986 | renderengine::DisplaySettings settings; |
| 987 | std::vector<renderengine::LayerSettings> layers; |
| 988 | renderengine::LayerSettings layer; |
| 989 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 990 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 991 | layers.push_back(layer); |
| 992 | base::unique_fd fence; |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 993 | status_t status = sRE->drawLayers(settings, layers, nullptr, true, base::unique_fd(), &fence); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 994 | |
| 995 | ASSERT_EQ(BAD_VALUE, status); |
| 996 | } |
| 997 | |
| 998 | TEST_F(RenderEngineTest, drawLayers_nullOutputFence) { |
| 999 | renderengine::DisplaySettings settings; |
| 1000 | settings.physicalDisplay = fullscreenRect(); |
| 1001 | settings.clip = fullscreenRect(); |
| 1002 | |
| 1003 | std::vector<renderengine::LayerSettings> layers; |
| 1004 | renderengine::LayerSettings layer; |
| 1005 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1006 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1007 | layer.alpha = 1.0; |
| 1008 | layers.push_back(layer); |
| 1009 | |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1010 | status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1011 | base::unique_fd(), nullptr); |
| 1012 | sCurrentBuffer = mBuffer; |
| 1013 | ASSERT_EQ(NO_ERROR, status); |
| 1014 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 1015 | } |
| 1016 | |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1017 | TEST_F(RenderEngineTest, drawLayers_doesNotCacheFramebuffer) { |
| 1018 | renderengine::DisplaySettings settings; |
| 1019 | settings.physicalDisplay = fullscreenRect(); |
| 1020 | settings.clip = fullscreenRect(); |
| 1021 | |
| 1022 | std::vector<renderengine::LayerSettings> layers; |
| 1023 | renderengine::LayerSettings layer; |
| 1024 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1025 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1026 | layer.alpha = 1.0; |
| 1027 | layers.push_back(layer); |
| 1028 | |
| 1029 | status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), false, |
| 1030 | base::unique_fd(), nullptr); |
| 1031 | sCurrentBuffer = mBuffer; |
| 1032 | ASSERT_EQ(NO_ERROR, status); |
| 1033 | ASSERT_FALSE(sRE->isFramebufferImageCachedForTesting(mBuffer->getId())); |
| 1034 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 1035 | } |
| 1036 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1037 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) { |
| 1038 | fillRedBuffer<ColorSourceVariant>(); |
| 1039 | } |
| 1040 | |
| 1041 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) { |
| 1042 | fillGreenBuffer<ColorSourceVariant>(); |
| 1043 | } |
| 1044 | |
| 1045 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) { |
| 1046 | fillBlueBuffer<ColorSourceVariant>(); |
| 1047 | } |
| 1048 | |
| 1049 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) { |
| 1050 | fillRedTransparentBuffer<ColorSourceVariant>(); |
| 1051 | } |
| 1052 | |
| 1053 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) { |
| 1054 | fillBufferPhysicalOffset<ColorSourceVariant>(); |
| 1055 | } |
| 1056 | |
| 1057 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) { |
| 1058 | fillBufferCheckersRotate0<ColorSourceVariant>(); |
| 1059 | } |
| 1060 | |
| 1061 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) { |
| 1062 | fillBufferCheckersRotate90<ColorSourceVariant>(); |
| 1063 | } |
| 1064 | |
| 1065 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) { |
| 1066 | fillBufferCheckersRotate180<ColorSourceVariant>(); |
| 1067 | } |
| 1068 | |
| 1069 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) { |
| 1070 | fillBufferCheckersRotate270<ColorSourceVariant>(); |
| 1071 | } |
| 1072 | |
| 1073 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) { |
| 1074 | fillBufferLayerTransform<ColorSourceVariant>(); |
| 1075 | } |
| 1076 | |
| 1077 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) { |
| 1078 | fillBufferLayerTransform<ColorSourceVariant>(); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1081 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) { |
| 1082 | fillBufferWithRoundedCorners<ColorSourceVariant>(); |
| 1083 | } |
| 1084 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1085 | TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_colorSource) { |
| 1086 | fillBufferAndBlurBackground<ColorSourceVariant>(); |
| 1087 | } |
| 1088 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1089 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_colorSource) { |
| 1090 | overlayCorners<ColorSourceVariant>(); |
| 1091 | } |
| 1092 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1093 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) { |
| 1094 | fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1095 | } |
| 1096 | |
| 1097 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) { |
| 1098 | fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1099 | } |
| 1100 | |
| 1101 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) { |
| 1102 | fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1103 | } |
| 1104 | |
| 1105 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) { |
| 1106 | fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1107 | } |
| 1108 | |
| 1109 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) { |
| 1110 | fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1111 | } |
| 1112 | |
| 1113 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) { |
| 1114 | fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1115 | } |
| 1116 | |
| 1117 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) { |
| 1118 | fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1119 | } |
| 1120 | |
| 1121 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) { |
| 1122 | fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1123 | } |
| 1124 | |
| 1125 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) { |
| 1126 | fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1127 | } |
| 1128 | |
| 1129 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) { |
| 1130 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1131 | } |
| 1132 | |
| 1133 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) { |
| 1134 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1135 | } |
| 1136 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1137 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) { |
| 1138 | fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1139 | } |
| 1140 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1141 | TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_opaqueBufferSource) { |
| 1142 | fillBufferAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1143 | } |
| 1144 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1145 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) { |
| 1146 | overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1147 | } |
| 1148 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1149 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) { |
| 1150 | fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1151 | } |
| 1152 | |
| 1153 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) { |
| 1154 | fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1155 | } |
| 1156 | |
| 1157 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) { |
| 1158 | fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1159 | } |
| 1160 | |
| 1161 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) { |
| 1162 | fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1163 | } |
| 1164 | |
| 1165 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) { |
| 1166 | fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1167 | } |
| 1168 | |
| 1169 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) { |
| 1170 | fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1171 | } |
| 1172 | |
| 1173 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) { |
| 1174 | fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1175 | } |
| 1176 | |
| 1177 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) { |
| 1178 | fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1179 | } |
| 1180 | |
| 1181 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) { |
| 1182 | fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1183 | } |
| 1184 | |
| 1185 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) { |
| 1186 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1187 | } |
| 1188 | |
| 1189 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) { |
| 1190 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1191 | } |
| 1192 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1193 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) { |
| 1194 | fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1195 | } |
| 1196 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1197 | TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_bufferSource) { |
| 1198 | fillBufferAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1199 | } |
| 1200 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1201 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_bufferSource) { |
| 1202 | overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1203 | } |
| 1204 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1205 | TEST_F(RenderEngineTest, drawLayers_fillBufferTextureTransform) { |
| 1206 | fillBufferTextureTransform(); |
| 1207 | } |
| 1208 | |
| 1209 | TEST_F(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) { |
| 1210 | fillBufferWithPremultiplyAlpha(); |
| 1211 | } |
| 1212 | |
| 1213 | TEST_F(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) { |
| 1214 | fillBufferWithoutPremultiplyAlpha(); |
| 1215 | } |
| 1216 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1217 | TEST_F(RenderEngineTest, drawLayers_clearRegion) { |
| 1218 | clearRegion(); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1219 | } |
| 1220 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1221 | TEST_F(RenderEngineTest, drawLayers_fillsBufferAndCachesImages) { |
| 1222 | renderengine::DisplaySettings settings; |
| 1223 | settings.physicalDisplay = fullscreenRect(); |
| 1224 | settings.clip = fullscreenRect(); |
| 1225 | |
| 1226 | std::vector<renderengine::LayerSettings> layers; |
| 1227 | |
| 1228 | renderengine::LayerSettings layer; |
| 1229 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1230 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1231 | |
| 1232 | layers.push_back(layer); |
| 1233 | invokeDraw(settings, layers, mBuffer); |
| 1234 | uint64_t bufferId = layer.source.buffer.buffer->getId(); |
| 1235 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1236 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1237 | sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1238 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1239 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1240 | [&]() REQUIRES(barrier->mutex) { |
| 1241 | return barrier->isOpen; |
| 1242 | })); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1243 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1244 | EXPECT_EQ(NO_ERROR, barrier->result); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | TEST_F(RenderEngineTest, drawLayers_bindExternalBufferWithNullBuffer) { |
| 1248 | status_t result = sRE->bindExternalTextureBuffer(0, nullptr, nullptr); |
| 1249 | ASSERT_EQ(BAD_VALUE, result); |
| 1250 | } |
| 1251 | |
| 1252 | TEST_F(RenderEngineTest, drawLayers_bindExternalBufferCachesImages) { |
| 1253 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 1254 | uint32_t texName; |
| 1255 | sRE->genTextures(1, &texName); |
| 1256 | mTexNames.push_back(texName); |
| 1257 | |
| 1258 | sRE->bindExternalTextureBuffer(texName, buf, nullptr); |
| 1259 | uint64_t bufferId = buf->getId(); |
| 1260 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1261 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1262 | sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1263 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1264 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1265 | [&]() REQUIRES(barrier->mutex) { |
| 1266 | return barrier->isOpen; |
| 1267 | })); |
| 1268 | EXPECT_EQ(NO_ERROR, barrier->result); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1269 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
| 1270 | } |
| 1271 | |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1272 | TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferWithNullBuffer) { |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1273 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1274 | sRE->cacheExternalTextureBufferForTesting(nullptr); |
| 1275 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1276 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1277 | [&]() REQUIRES(barrier->mutex) { |
| 1278 | return barrier->isOpen; |
| 1279 | })); |
| 1280 | EXPECT_TRUE(barrier->isOpen); |
| 1281 | EXPECT_EQ(BAD_VALUE, barrier->result); |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferCachesImages) { |
| 1285 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 1286 | uint64_t bufferId = buf->getId(); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1287 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1288 | sRE->cacheExternalTextureBufferForTesting(buf); |
| 1289 | { |
| 1290 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1291 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1292 | [&]() REQUIRES(barrier->mutex) { |
| 1293 | return barrier->isOpen; |
| 1294 | })); |
| 1295 | EXPECT_EQ(NO_ERROR, barrier->result); |
| 1296 | } |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1297 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1298 | barrier = sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1299 | { |
| 1300 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1301 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1302 | [&]() REQUIRES(barrier->mutex) { |
| 1303 | return barrier->isOpen; |
| 1304 | })); |
| 1305 | EXPECT_EQ(NO_ERROR, barrier->result); |
| 1306 | } |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1307 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
| 1308 | } |
| 1309 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1310 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterLayerMinSize) { |
| 1311 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1312 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1313 | const float shadowLength = 5.0f; |
| 1314 | Rect casterBounds(1, 1); |
| 1315 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1316 | renderengine::LayerSettings castingLayer; |
| 1317 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1318 | castingLayer.alpha = 1.0f; |
| 1319 | renderengine::ShadowSettings settings = |
| 1320 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1321 | false /* casterIsTranslucent */); |
| 1322 | |
| 1323 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 1324 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1325 | } |
| 1326 | |
| 1327 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterColorLayer) { |
| 1328 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1329 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1330 | const float shadowLength = 5.0f; |
| 1331 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1332 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1333 | renderengine::LayerSettings castingLayer; |
| 1334 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1335 | castingLayer.alpha = 1.0f; |
| 1336 | renderengine::ShadowSettings settings = |
| 1337 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1338 | false /* casterIsTranslucent */); |
| 1339 | |
| 1340 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 1341 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1342 | } |
| 1343 | |
| 1344 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterOpaqueBufferLayer) { |
| 1345 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1346 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1347 | const float shadowLength = 5.0f; |
| 1348 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1349 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1350 | renderengine::LayerSettings castingLayer; |
| 1351 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1352 | castingLayer.alpha = 1.0f; |
| 1353 | renderengine::ShadowSettings settings = |
| 1354 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1355 | false /* casterIsTranslucent */); |
| 1356 | |
| 1357 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 1358 | backgroundColor); |
| 1359 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1360 | } |
| 1361 | |
| 1362 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterWithRoundedCorner) { |
| 1363 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1364 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1365 | const float shadowLength = 5.0f; |
| 1366 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1367 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1368 | renderengine::LayerSettings castingLayer; |
| 1369 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1370 | castingLayer.geometry.roundedCornersRadius = 3.0f; |
| 1371 | castingLayer.geometry.roundedCornersCrop = casterBounds.toFloatRect(); |
| 1372 | castingLayer.alpha = 1.0f; |
| 1373 | renderengine::ShadowSettings settings = |
| 1374 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1375 | false /* casterIsTranslucent */); |
| 1376 | |
| 1377 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 1378 | backgroundColor); |
| 1379 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1380 | } |
| 1381 | |
| 1382 | TEST_F(RenderEngineTest, drawLayers_fillShadow_translucentCasterWithAlpha) { |
| 1383 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1384 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1385 | const float shadowLength = 5.0f; |
| 1386 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1387 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1388 | renderengine::LayerSettings castingLayer; |
| 1389 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1390 | castingLayer.alpha = 0.5f; |
| 1391 | renderengine::ShadowSettings settings = |
| 1392 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1393 | true /* casterIsTranslucent */); |
| 1394 | |
| 1395 | drawShadow<BufferSourceVariant<RelaxOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 1396 | backgroundColor); |
| 1397 | |
| 1398 | // verify only the background since the shadow will draw behind the caster |
| 1399 | const float shadowInset = settings.length * -1.0f; |
| 1400 | const Rect casterWithShadow = |
| 1401 | Rect(casterBounds).inset(shadowInset, shadowInset, shadowInset, shadowInset); |
| 1402 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); |
| 1403 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, |
| 1404 | backgroundColor.a); |
| 1405 | } |
| 1406 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1407 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1408 | |
| 1409 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1410 | #pragma clang diagnostic pop // ignored "-Wconversion" |