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