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