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> |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 301 | void fillBufferCheckers(uint32_t rotation); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 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> |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 512 | void RenderEngineTest::fillBufferCheckers(uint32_t orientationFlag) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 513 | renderengine::DisplaySettings settings; |
| 514 | settings.physicalDisplay = fullscreenRect(); |
| 515 | // Here logical space is 2x2 |
| 516 | settings.clip = Rect(2, 2); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 517 | settings.orientation = orientationFlag; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 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() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 548 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_0); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 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() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 564 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_90); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 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() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 580 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_180); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 581 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, |
| 582 | 0); |
| 583 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 584 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 585 | 0, 255, 0, 255); |
| 586 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 587 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 588 | 255, 0, 0, 255); |
| 589 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 590 | DEFAULT_DISPLAY_HEIGHT), |
| 591 | 0, 0, 255, 255); |
| 592 | } |
| 593 | |
| 594 | template <typename SourceVariant> |
| 595 | void RenderEngineTest::fillBufferCheckersRotate270() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 596 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_270); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 597 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255, |
| 598 | 255); |
| 599 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 600 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 601 | 0, 0, 0, 0); |
| 602 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 603 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 604 | 0, 255, 0, 255); |
| 605 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 606 | DEFAULT_DISPLAY_HEIGHT), |
| 607 | 255, 0, 0, 255); |
| 608 | } |
| 609 | |
| 610 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 611 | void RenderEngineTest::fillBufferWithLayerTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 612 | renderengine::DisplaySettings settings; |
| 613 | settings.physicalDisplay = fullscreenRect(); |
| 614 | // Here logical space is 2x2 |
| 615 | settings.clip = Rect(2, 2); |
| 616 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 617 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 618 | |
| 619 | renderengine::LayerSettings layer; |
| 620 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 621 | // Translate one pixel diagonally |
| 622 | 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] | 623 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 624 | layer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 625 | layer.alpha = 1.0f; |
| 626 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 627 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 628 | |
| 629 | invokeDraw(settings, layers, mBuffer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 630 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 631 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 632 | template <typename SourceVariant> |
| 633 | void RenderEngineTest::fillBufferLayerTransform() { |
| 634 | fillBufferWithLayerTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 635 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, 0); |
| 636 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 637 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 638 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 639 | 255, 0, 0, 255); |
| 640 | } |
| 641 | |
| 642 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 643 | void RenderEngineTest::fillBufferWithColorTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 644 | renderengine::DisplaySettings settings; |
| 645 | settings.physicalDisplay = fullscreenRect(); |
| 646 | settings.clip = Rect(1, 1); |
| 647 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 648 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 649 | |
| 650 | renderengine::LayerSettings layer; |
| 651 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 652 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 653 | layer.alpha = 1.0f; |
| 654 | |
| 655 | // construct a fake color matrix |
| 656 | // annihilate green and blue channels |
| 657 | settings.colorTransform = mat4::scale(vec4(1, 0, 0, 1)); |
| 658 | // set red channel to red + green |
| 659 | layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 660 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 661 | layer.alpha = 1.0f; |
| 662 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 663 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 664 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 665 | |
| 666 | invokeDraw(settings, layers, mBuffer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 667 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 668 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 669 | template <typename SourceVariant> |
| 670 | void RenderEngineTest::fillBufferColorTransform() { |
| 671 | fillBufferWithColorTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 672 | expectBufferColor(fullscreenRect(), 191, 0, 0, 255); |
| 673 | } |
| 674 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 675 | template <typename SourceVariant> |
| 676 | void RenderEngineTest::fillRedBufferWithRoundedCorners() { |
| 677 | renderengine::DisplaySettings settings; |
| 678 | settings.physicalDisplay = fullscreenRect(); |
| 679 | settings.clip = fullscreenRect(); |
| 680 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 681 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 682 | |
| 683 | renderengine::LayerSettings layer; |
| 684 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 685 | layer.geometry.roundedCornersRadius = 5.0f; |
| 686 | layer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 687 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 688 | layer.alpha = 1.0f; |
| 689 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 690 | layers.push_back(&layer); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 691 | |
| 692 | invokeDraw(settings, layers, mBuffer); |
| 693 | } |
| 694 | |
| 695 | template <typename SourceVariant> |
| 696 | void RenderEngineTest::fillBufferWithRoundedCorners() { |
| 697 | fillRedBufferWithRoundedCorners<SourceVariant>(); |
| 698 | // Corners should be ignored... |
| 699 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); |
| 700 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); |
| 701 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 702 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, |
| 703 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 704 | 0, 0, 0, 0); |
| 705 | // ...And the non-rounded portion should be red. |
| 706 | // Other pixels may be anti-aliased, so let's not check those. |
| 707 | expectBufferColor(Rect(5, 5, DEFAULT_DISPLAY_WIDTH - 5, DEFAULT_DISPLAY_HEIGHT - 5), 255, 0, 0, |
| 708 | 255); |
| 709 | } |
| 710 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 711 | template <typename SourceVariant> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 712 | void RenderEngineTest::fillBufferAndBlurBackground() { |
| 713 | char value[PROPERTY_VALUE_MAX]; |
| 714 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 715 | if (!atoi(value)) { |
| 716 | // This device doesn't support blurs, no-op. |
| 717 | return; |
| 718 | } |
| 719 | |
| 720 | auto blurRadius = 50; |
| 721 | auto center = DEFAULT_DISPLAY_WIDTH / 2; |
| 722 | |
| 723 | renderengine::DisplaySettings settings; |
| 724 | settings.physicalDisplay = fullscreenRect(); |
| 725 | settings.clip = fullscreenRect(); |
| 726 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 727 | std::vector<const renderengine::LayerSettings*> layers; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 728 | |
| 729 | renderengine::LayerSettings backgroundLayer; |
| 730 | backgroundLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 731 | SourceVariant::fillColor(backgroundLayer, 0.0f, 1.0f, 0.0f, this); |
| 732 | backgroundLayer.alpha = 1.0f; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 733 | layers.push_back(&backgroundLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 734 | |
| 735 | renderengine::LayerSettings leftLayer; |
| 736 | leftLayer.geometry.boundaries = |
| 737 | Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT).toFloatRect(); |
| 738 | SourceVariant::fillColor(leftLayer, 1.0f, 0.0f, 0.0f, this); |
| 739 | leftLayer.alpha = 1.0f; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 740 | layers.push_back(&leftLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 741 | |
| 742 | renderengine::LayerSettings blurLayer; |
| 743 | blurLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 744 | blurLayer.backgroundBlurRadius = blurRadius; |
| 745 | blurLayer.alpha = 0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 746 | layers.push_back(&blurLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 747 | |
| 748 | invokeDraw(settings, layers, mBuffer); |
| 749 | |
| 750 | expectBufferColor(Rect(center - 1, center - 5, center, center + 5), 150, 150, 0, 255, |
| 751 | 50 /* tolerance */); |
| 752 | expectBufferColor(Rect(center, center - 5, center + 1, center + 5), 150, 150, 0, 255, |
| 753 | 50 /* tolerance */); |
| 754 | } |
| 755 | |
| 756 | template <typename SourceVariant> |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 757 | void RenderEngineTest::overlayCorners() { |
| 758 | renderengine::DisplaySettings settings; |
| 759 | settings.physicalDisplay = fullscreenRect(); |
| 760 | settings.clip = fullscreenRect(); |
| 761 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 762 | std::vector<const renderengine::LayerSettings*> layersFirst; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 763 | |
| 764 | renderengine::LayerSettings layerOne; |
| 765 | layerOne.geometry.boundaries = |
| 766 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0); |
| 767 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
| 768 | layerOne.alpha = 0.2; |
| 769 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 770 | layersFirst.push_back(&layerOne); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 771 | invokeDraw(settings, layersFirst, mBuffer); |
| 772 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51); |
| 773 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 774 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 775 | 0, 0, 0, 0); |
| 776 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 777 | std::vector<const renderengine::LayerSettings*> layersSecond; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 778 | renderengine::LayerSettings layerTwo; |
| 779 | layerTwo.geometry.boundaries = |
| 780 | FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0, |
| 781 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); |
| 782 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
| 783 | layerTwo.alpha = 1.0f; |
| 784 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 785 | layersSecond.push_back(&layerTwo); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 786 | invokeDraw(settings, layersSecond, mBuffer); |
| 787 | |
| 788 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0); |
| 789 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 790 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 791 | 0, 255, 0, 255); |
| 792 | } |
| 793 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 794 | void RenderEngineTest::fillRedBufferTextureTransform() { |
| 795 | renderengine::DisplaySettings settings; |
| 796 | settings.physicalDisplay = fullscreenRect(); |
| 797 | settings.clip = Rect(1, 1); |
| 798 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 799 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 800 | |
| 801 | renderengine::LayerSettings layer; |
| 802 | // Here will allocate a checker board texture, but transform texture |
| 803 | // coordinates so that only the upper left is applied. |
| 804 | sp<GraphicBuffer> buf = allocateSourceBuffer(2, 2); |
| 805 | uint32_t texName; |
| 806 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 807 | this->mTexNames.push_back(texName); |
| 808 | |
| 809 | uint8_t* pixels; |
| 810 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 811 | reinterpret_cast<void**>(&pixels)); |
| 812 | // Red top left, Green top right, Blue bottom left, Black bottom right |
| 813 | pixels[0] = 255; |
| 814 | pixels[1] = 0; |
| 815 | pixels[2] = 0; |
| 816 | pixels[3] = 255; |
| 817 | pixels[4] = 0; |
| 818 | pixels[5] = 255; |
| 819 | pixels[6] = 0; |
| 820 | pixels[7] = 255; |
| 821 | pixels[8] = 0; |
| 822 | pixels[9] = 0; |
| 823 | pixels[10] = 255; |
| 824 | pixels[11] = 255; |
| 825 | buf->unlock(); |
| 826 | |
| 827 | layer.source.buffer.buffer = buf; |
| 828 | layer.source.buffer.textureName = texName; |
| 829 | // Transform coordinates to only be inside the red quadrant. |
| 830 | layer.source.buffer.textureTransform = mat4::scale(vec4(0.2, 0.2, 1, 1)); |
| 831 | layer.alpha = 1.0f; |
| 832 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 833 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 834 | layers.push_back(&layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 835 | |
| 836 | invokeDraw(settings, layers, mBuffer); |
| 837 | } |
| 838 | |
| 839 | void RenderEngineTest::fillBufferTextureTransform() { |
| 840 | fillRedBufferTextureTransform(); |
| 841 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 842 | } |
| 843 | |
| 844 | void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() { |
| 845 | renderengine::DisplaySettings settings; |
| 846 | settings.physicalDisplay = fullscreenRect(); |
| 847 | // Here logical space is 1x1 |
| 848 | settings.clip = Rect(1, 1); |
| 849 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 850 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 851 | |
| 852 | renderengine::LayerSettings layer; |
| 853 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 854 | uint32_t texName; |
| 855 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 856 | this->mTexNames.push_back(texName); |
| 857 | |
| 858 | uint8_t* pixels; |
| 859 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 860 | reinterpret_cast<void**>(&pixels)); |
| 861 | pixels[0] = 255; |
| 862 | pixels[1] = 0; |
| 863 | pixels[2] = 0; |
| 864 | pixels[3] = 255; |
| 865 | buf->unlock(); |
| 866 | |
| 867 | layer.source.buffer.buffer = buf; |
| 868 | layer.source.buffer.textureName = texName; |
| 869 | layer.source.buffer.usePremultipliedAlpha = true; |
| 870 | layer.alpha = 0.5f; |
| 871 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 872 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 873 | layers.push_back(&layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 874 | |
| 875 | invokeDraw(settings, layers, mBuffer); |
| 876 | } |
| 877 | |
| 878 | void RenderEngineTest::fillBufferWithPremultiplyAlpha() { |
| 879 | fillRedBufferWithPremultiplyAlpha(); |
| 880 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128); |
| 881 | } |
| 882 | |
| 883 | void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() { |
| 884 | renderengine::DisplaySettings settings; |
| 885 | settings.physicalDisplay = fullscreenRect(); |
| 886 | // Here logical space is 1x1 |
| 887 | settings.clip = Rect(1, 1); |
| 888 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 889 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 890 | |
| 891 | renderengine::LayerSettings layer; |
| 892 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 893 | uint32_t texName; |
| 894 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 895 | this->mTexNames.push_back(texName); |
| 896 | |
| 897 | uint8_t* pixels; |
| 898 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 899 | reinterpret_cast<void**>(&pixels)); |
| 900 | pixels[0] = 255; |
| 901 | pixels[1] = 0; |
| 902 | pixels[2] = 0; |
| 903 | pixels[3] = 255; |
| 904 | buf->unlock(); |
| 905 | |
| 906 | layer.source.buffer.buffer = buf; |
| 907 | layer.source.buffer.textureName = texName; |
| 908 | layer.source.buffer.usePremultipliedAlpha = false; |
| 909 | layer.alpha = 0.5f; |
| 910 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 911 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 912 | layers.push_back(&layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 913 | |
| 914 | invokeDraw(settings, layers, mBuffer); |
| 915 | } |
| 916 | |
| 917 | void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() { |
| 918 | fillRedBufferWithoutPremultiplyAlpha(); |
| 919 | expectBufferColor(fullscreenRect(), 128, 0, 0, 64, 1); |
| 920 | } |
| 921 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 922 | void RenderEngineTest::clearLeftRegion() { |
| 923 | renderengine::DisplaySettings settings; |
| 924 | settings.physicalDisplay = fullscreenRect(); |
| 925 | // Here logical space is 4x4 |
| 926 | settings.clip = Rect(4, 4); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 927 | settings.clearRegion = Region(Rect(2, 4)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 928 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 929 | // dummy layer, without bounds should not render anything |
| 930 | renderengine::LayerSettings layer; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 931 | layers.push_back(&layer); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 932 | invokeDraw(settings, layers, mBuffer); |
| 933 | } |
| 934 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 935 | void RenderEngineTest::clearRegion() { |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 936 | // Reuse mBuffer |
| 937 | clearLeftRegion(); |
| 938 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 255); |
| 939 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 940 | DEFAULT_DISPLAY_HEIGHT), |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 941 | 0, 0, 0, 0); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 942 | } |
| 943 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 944 | template <typename SourceVariant> |
| 945 | void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer, |
| 946 | const renderengine::ShadowSettings& shadow, |
| 947 | const ubyte4& casterColor, const ubyte4& backgroundColor) { |
| 948 | renderengine::DisplaySettings settings; |
| 949 | settings.physicalDisplay = fullscreenRect(); |
| 950 | settings.clip = fullscreenRect(); |
| 951 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 952 | std::vector<const renderengine::LayerSettings*> layers; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 953 | |
| 954 | // add background layer |
| 955 | renderengine::LayerSettings bgLayer; |
| 956 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 957 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 958 | backgroundColor.b / 255.0f, this); |
| 959 | bgLayer.alpha = backgroundColor.a / 255.0f; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 960 | layers.push_back(&bgLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 961 | |
| 962 | // add shadow layer |
| 963 | renderengine::LayerSettings shadowLayer; |
| 964 | shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries; |
| 965 | shadowLayer.alpha = castingLayer.alpha; |
| 966 | shadowLayer.shadow = shadow; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 967 | layers.push_back(&shadowLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 968 | |
| 969 | // add layer casting the shadow |
| 970 | renderengine::LayerSettings layer = castingLayer; |
| 971 | SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f, |
| 972 | casterColor.b / 255.0f, this); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 973 | layers.push_back(&layer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 974 | |
| 975 | invokeDraw(settings, layers, mBuffer); |
| 976 | } |
| 977 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 978 | TEST_F(RenderEngineTest, drawLayers_noLayersToDraw) { |
| 979 | drawEmptyLayers(); |
| 980 | } |
| 981 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 982 | TEST_F(RenderEngineTest, drawLayers_nullOutputBuffer) { |
| 983 | renderengine::DisplaySettings settings; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 984 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 985 | renderengine::LayerSettings layer; |
| 986 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 987 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 988 | layers.push_back(&layer); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 989 | base::unique_fd fence; |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 990 | 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] | 991 | |
| 992 | ASSERT_EQ(BAD_VALUE, status); |
| 993 | } |
| 994 | |
| 995 | TEST_F(RenderEngineTest, drawLayers_nullOutputFence) { |
| 996 | renderengine::DisplaySettings settings; |
| 997 | settings.physicalDisplay = fullscreenRect(); |
| 998 | settings.clip = fullscreenRect(); |
| 999 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1000 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1001 | renderengine::LayerSettings layer; |
| 1002 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1003 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1004 | layer.alpha = 1.0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1005 | layers.push_back(&layer); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1006 | |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1007 | status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1008 | base::unique_fd(), nullptr); |
| 1009 | sCurrentBuffer = mBuffer; |
| 1010 | ASSERT_EQ(NO_ERROR, status); |
| 1011 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 1012 | } |
| 1013 | |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1014 | TEST_F(RenderEngineTest, drawLayers_doesNotCacheFramebuffer) { |
| 1015 | renderengine::DisplaySettings settings; |
| 1016 | settings.physicalDisplay = fullscreenRect(); |
| 1017 | settings.clip = fullscreenRect(); |
| 1018 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1019 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1020 | renderengine::LayerSettings layer; |
| 1021 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1022 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1023 | layer.alpha = 1.0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1024 | layers.push_back(&layer); |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1025 | |
| 1026 | status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), false, |
| 1027 | base::unique_fd(), nullptr); |
| 1028 | sCurrentBuffer = mBuffer; |
| 1029 | ASSERT_EQ(NO_ERROR, status); |
| 1030 | ASSERT_FALSE(sRE->isFramebufferImageCachedForTesting(mBuffer->getId())); |
| 1031 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 1032 | } |
| 1033 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1034 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) { |
| 1035 | fillRedBuffer<ColorSourceVariant>(); |
| 1036 | } |
| 1037 | |
| 1038 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) { |
| 1039 | fillGreenBuffer<ColorSourceVariant>(); |
| 1040 | } |
| 1041 | |
| 1042 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) { |
| 1043 | fillBlueBuffer<ColorSourceVariant>(); |
| 1044 | } |
| 1045 | |
| 1046 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) { |
| 1047 | fillRedTransparentBuffer<ColorSourceVariant>(); |
| 1048 | } |
| 1049 | |
| 1050 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) { |
| 1051 | fillBufferPhysicalOffset<ColorSourceVariant>(); |
| 1052 | } |
| 1053 | |
| 1054 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) { |
| 1055 | fillBufferCheckersRotate0<ColorSourceVariant>(); |
| 1056 | } |
| 1057 | |
| 1058 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) { |
| 1059 | fillBufferCheckersRotate90<ColorSourceVariant>(); |
| 1060 | } |
| 1061 | |
| 1062 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) { |
| 1063 | fillBufferCheckersRotate180<ColorSourceVariant>(); |
| 1064 | } |
| 1065 | |
| 1066 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) { |
| 1067 | fillBufferCheckersRotate270<ColorSourceVariant>(); |
| 1068 | } |
| 1069 | |
| 1070 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) { |
| 1071 | fillBufferLayerTransform<ColorSourceVariant>(); |
| 1072 | } |
| 1073 | |
| 1074 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) { |
| 1075 | fillBufferLayerTransform<ColorSourceVariant>(); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1078 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) { |
| 1079 | fillBufferWithRoundedCorners<ColorSourceVariant>(); |
| 1080 | } |
| 1081 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1082 | TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_colorSource) { |
| 1083 | fillBufferAndBlurBackground<ColorSourceVariant>(); |
| 1084 | } |
| 1085 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1086 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_colorSource) { |
| 1087 | overlayCorners<ColorSourceVariant>(); |
| 1088 | } |
| 1089 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1090 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) { |
| 1091 | fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1092 | } |
| 1093 | |
| 1094 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) { |
| 1095 | fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1096 | } |
| 1097 | |
| 1098 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) { |
| 1099 | fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1100 | } |
| 1101 | |
| 1102 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) { |
| 1103 | fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1104 | } |
| 1105 | |
| 1106 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) { |
| 1107 | fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1108 | } |
| 1109 | |
| 1110 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) { |
| 1111 | fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1112 | } |
| 1113 | |
| 1114 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) { |
| 1115 | fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1116 | } |
| 1117 | |
| 1118 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) { |
| 1119 | fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1120 | } |
| 1121 | |
| 1122 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) { |
| 1123 | fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1124 | } |
| 1125 | |
| 1126 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) { |
| 1127 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1128 | } |
| 1129 | |
| 1130 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) { |
| 1131 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1132 | } |
| 1133 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1134 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) { |
| 1135 | fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1136 | } |
| 1137 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1138 | TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_opaqueBufferSource) { |
| 1139 | fillBufferAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1140 | } |
| 1141 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1142 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) { |
| 1143 | overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1144 | } |
| 1145 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1146 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) { |
| 1147 | fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1148 | } |
| 1149 | |
| 1150 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) { |
| 1151 | fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1152 | } |
| 1153 | |
| 1154 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) { |
| 1155 | fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1156 | } |
| 1157 | |
| 1158 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) { |
| 1159 | fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1160 | } |
| 1161 | |
| 1162 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) { |
| 1163 | fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1164 | } |
| 1165 | |
| 1166 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) { |
| 1167 | fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1168 | } |
| 1169 | |
| 1170 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) { |
| 1171 | fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1172 | } |
| 1173 | |
| 1174 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) { |
| 1175 | fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1176 | } |
| 1177 | |
| 1178 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) { |
| 1179 | fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1180 | } |
| 1181 | |
| 1182 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) { |
| 1183 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1184 | } |
| 1185 | |
| 1186 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) { |
| 1187 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1188 | } |
| 1189 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1190 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) { |
| 1191 | fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1192 | } |
| 1193 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1194 | TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_bufferSource) { |
| 1195 | fillBufferAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1196 | } |
| 1197 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1198 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_bufferSource) { |
| 1199 | overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1200 | } |
| 1201 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1202 | TEST_F(RenderEngineTest, drawLayers_fillBufferTextureTransform) { |
| 1203 | fillBufferTextureTransform(); |
| 1204 | } |
| 1205 | |
| 1206 | TEST_F(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) { |
| 1207 | fillBufferWithPremultiplyAlpha(); |
| 1208 | } |
| 1209 | |
| 1210 | TEST_F(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) { |
| 1211 | fillBufferWithoutPremultiplyAlpha(); |
| 1212 | } |
| 1213 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1214 | TEST_F(RenderEngineTest, drawLayers_clearRegion) { |
| 1215 | clearRegion(); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1216 | } |
| 1217 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1218 | TEST_F(RenderEngineTest, drawLayers_fillsBufferAndCachesImages) { |
| 1219 | renderengine::DisplaySettings settings; |
| 1220 | settings.physicalDisplay = fullscreenRect(); |
| 1221 | settings.clip = fullscreenRect(); |
| 1222 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1223 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1224 | |
| 1225 | renderengine::LayerSettings layer; |
| 1226 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1227 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1228 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1229 | layers.push_back(&layer); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1230 | invokeDraw(settings, layers, mBuffer); |
| 1231 | uint64_t bufferId = layer.source.buffer.buffer->getId(); |
| 1232 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1233 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1234 | sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1235 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1236 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1237 | [&]() REQUIRES(barrier->mutex) { |
| 1238 | return barrier->isOpen; |
| 1239 | })); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1240 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1241 | EXPECT_EQ(NO_ERROR, barrier->result); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1244 | TEST_F(RenderEngineTest, bindExternalBuffer_withNullBuffer) { |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1245 | status_t result = sRE->bindExternalTextureBuffer(0, nullptr, nullptr); |
| 1246 | ASSERT_EQ(BAD_VALUE, result); |
| 1247 | } |
| 1248 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1249 | TEST_F(RenderEngineTest, bindExternalBuffer_cachesImages) { |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1250 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 1251 | uint32_t texName; |
| 1252 | sRE->genTextures(1, &texName); |
| 1253 | mTexNames.push_back(texName); |
| 1254 | |
| 1255 | sRE->bindExternalTextureBuffer(texName, buf, nullptr); |
| 1256 | uint64_t bufferId = buf->getId(); |
| 1257 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1258 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1259 | sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1260 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1261 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1262 | [&]() REQUIRES(barrier->mutex) { |
| 1263 | return barrier->isOpen; |
| 1264 | })); |
| 1265 | EXPECT_EQ(NO_ERROR, barrier->result); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1266 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
| 1267 | } |
| 1268 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1269 | TEST_F(RenderEngineTest, cacheExternalBuffer_withNullBuffer) { |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1270 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1271 | sRE->cacheExternalTextureBufferForTesting(nullptr); |
| 1272 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1273 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1274 | [&]() REQUIRES(barrier->mutex) { |
| 1275 | return barrier->isOpen; |
| 1276 | })); |
| 1277 | EXPECT_TRUE(barrier->isOpen); |
| 1278 | EXPECT_EQ(BAD_VALUE, barrier->result); |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1281 | TEST_F(RenderEngineTest, cacheExternalBuffer_cachesImages) { |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1282 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 1283 | uint64_t bufferId = buf->getId(); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1284 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1285 | sRE->cacheExternalTextureBufferForTesting(buf); |
| 1286 | { |
| 1287 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1288 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1289 | [&]() REQUIRES(barrier->mutex) { |
| 1290 | return barrier->isOpen; |
| 1291 | })); |
| 1292 | EXPECT_EQ(NO_ERROR, barrier->result); |
| 1293 | } |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1294 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1295 | barrier = sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1296 | { |
| 1297 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1298 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1299 | [&]() REQUIRES(barrier->mutex) { |
| 1300 | return barrier->isOpen; |
| 1301 | })); |
| 1302 | EXPECT_EQ(NO_ERROR, barrier->result); |
| 1303 | } |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1304 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
| 1305 | } |
| 1306 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1307 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterLayerMinSize) { |
| 1308 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1309 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1310 | const float shadowLength = 5.0f; |
| 1311 | Rect casterBounds(1, 1); |
| 1312 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1313 | renderengine::LayerSettings castingLayer; |
| 1314 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1315 | castingLayer.alpha = 1.0f; |
| 1316 | renderengine::ShadowSettings settings = |
| 1317 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1318 | false /* casterIsTranslucent */); |
| 1319 | |
| 1320 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 1321 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1322 | } |
| 1323 | |
| 1324 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterColorLayer) { |
| 1325 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1326 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1327 | const float shadowLength = 5.0f; |
| 1328 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1329 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1330 | renderengine::LayerSettings castingLayer; |
| 1331 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1332 | castingLayer.alpha = 1.0f; |
| 1333 | renderengine::ShadowSettings settings = |
| 1334 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1335 | false /* casterIsTranslucent */); |
| 1336 | |
| 1337 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 1338 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1339 | } |
| 1340 | |
| 1341 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterOpaqueBufferLayer) { |
| 1342 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1343 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1344 | const float shadowLength = 5.0f; |
| 1345 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1346 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1347 | renderengine::LayerSettings castingLayer; |
| 1348 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1349 | castingLayer.alpha = 1.0f; |
| 1350 | renderengine::ShadowSettings settings = |
| 1351 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1352 | false /* casterIsTranslucent */); |
| 1353 | |
| 1354 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 1355 | backgroundColor); |
| 1356 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1357 | } |
| 1358 | |
| 1359 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterWithRoundedCorner) { |
| 1360 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1361 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1362 | const float shadowLength = 5.0f; |
| 1363 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1364 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1365 | renderengine::LayerSettings castingLayer; |
| 1366 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1367 | castingLayer.geometry.roundedCornersRadius = 3.0f; |
| 1368 | castingLayer.geometry.roundedCornersCrop = casterBounds.toFloatRect(); |
| 1369 | castingLayer.alpha = 1.0f; |
| 1370 | renderengine::ShadowSettings settings = |
| 1371 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1372 | false /* casterIsTranslucent */); |
| 1373 | |
| 1374 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 1375 | backgroundColor); |
| 1376 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1377 | } |
| 1378 | |
| 1379 | TEST_F(RenderEngineTest, drawLayers_fillShadow_translucentCasterWithAlpha) { |
| 1380 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1381 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1382 | const float shadowLength = 5.0f; |
| 1383 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1384 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1385 | renderengine::LayerSettings castingLayer; |
| 1386 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1387 | castingLayer.alpha = 0.5f; |
| 1388 | renderengine::ShadowSettings settings = |
| 1389 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1390 | true /* casterIsTranslucent */); |
| 1391 | |
| 1392 | drawShadow<BufferSourceVariant<RelaxOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 1393 | backgroundColor); |
| 1394 | |
| 1395 | // verify only the background since the shadow will draw behind the caster |
| 1396 | const float shadowInset = settings.length * -1.0f; |
| 1397 | const Rect casterWithShadow = |
| 1398 | Rect(casterBounds).inset(shadowInset, shadowInset, shadowInset, shadowInset); |
| 1399 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); |
| 1400 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, |
| 1401 | backgroundColor.a); |
| 1402 | } |
| 1403 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1404 | TEST_F(RenderEngineTest, cleanupPostRender_cleansUpOnce) { |
| 1405 | renderengine::DisplaySettings settings; |
| 1406 | settings.physicalDisplay = fullscreenRect(); |
| 1407 | settings.clip = fullscreenRect(); |
| 1408 | |
| 1409 | std::vector<const renderengine::LayerSettings*> layers; |
| 1410 | renderengine::LayerSettings layer; |
| 1411 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1412 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1413 | layer.alpha = 1.0; |
| 1414 | layers.push_back(&layer); |
| 1415 | |
| 1416 | base::unique_fd fenceOne; |
| 1417 | sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, base::unique_fd(), |
| 1418 | &fenceOne); |
| 1419 | base::unique_fd fenceTwo; |
| 1420 | sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, std::move(fenceOne), |
| 1421 | &fenceTwo); |
| 1422 | |
| 1423 | const int fd = fenceTwo.get(); |
| 1424 | if (fd >= 0) { |
| 1425 | sync_wait(fd, -1); |
| 1426 | } |
| 1427 | |
| 1428 | // Only cleanup the first time. |
| 1429 | EXPECT_TRUE(sRE->cleanupPostRender()); |
| 1430 | EXPECT_FALSE(sRE->cleanupPostRender()); |
| 1431 | } |
| 1432 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1433 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1434 | |
| 1435 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1436 | #pragma clang diagnostic pop // ignored "-Wconversion" |