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 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 25 | #include <cutils/properties.h> |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame^] | 26 | #include <gtest/gtest.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" |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame^] | 31 | #include "../threaded/RenderEngineThreaded.h" |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 32 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 33 | constexpr int DEFAULT_DISPLAY_WIDTH = 128; |
| 34 | constexpr int DEFAULT_DISPLAY_HEIGHT = 256; |
| 35 | constexpr int DEFAULT_DISPLAY_OFFSET = 64; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 36 | constexpr bool WRITE_BUFFER_TO_FILE_ON_FAILURE = false; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 37 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 38 | namespace android { |
| 39 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 40 | struct RenderEngineTest : public ::testing::Test { |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 41 | static void SetUpTestSuite() { |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 42 | sRE = renderengine::gl::GLESRenderEngine::create( |
| 43 | renderengine::RenderEngineCreationArgs::Builder() |
Ana Krulec | 9bc9dc6 | 2020-02-26 12:16:40 -0800 | [diff] [blame^] | 44 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) |
| 45 | .setImageCacheSize(1) |
| 46 | .setUseColorManagerment(false) |
| 47 | .setEnableProtectedContext(false) |
| 48 | .setPrecacheToneMapperShaderOnly(false) |
| 49 | .setSupportsBackgroundBlur(true) |
| 50 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) |
| 51 | .setRenderEngineType(renderengine::RenderEngine::RenderEngineType::GLES) |
| 52 | .build()); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | static void TearDownTestSuite() { |
| 56 | // The ordering here is important - sCurrentBuffer must live longer |
| 57 | // than RenderEngine to avoid a null reference on tear-down. |
| 58 | sRE = nullptr; |
| 59 | sCurrentBuffer = nullptr; |
| 60 | } |
| 61 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 62 | static sp<GraphicBuffer> allocateDefaultBuffer() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 63 | return new GraphicBuffer(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT, |
| 64 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 65 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 66 | GRALLOC_USAGE_HW_RENDER, |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 67 | "output"); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 70 | // Allocates a 1x1 buffer to fill with a solid color |
| 71 | static sp<GraphicBuffer> allocateSourceBuffer(uint32_t width, uint32_t height) { |
| 72 | return new GraphicBuffer(width, height, HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 73 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 74 | GRALLOC_USAGE_HW_TEXTURE, |
| 75 | "input"); |
| 76 | } |
| 77 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 78 | RenderEngineTest() { mBuffer = allocateDefaultBuffer(); } |
| 79 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 80 | ~RenderEngineTest() { |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 81 | if (WRITE_BUFFER_TO_FILE_ON_FAILURE && ::testing::Test::HasFailure()) { |
| 82 | writeBufferToFile("/data/texture_out_"); |
| 83 | } |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 84 | for (uint32_t texName : mTexNames) { |
| 85 | sRE->deleteTextures(1, &texName); |
| 86 | } |
| 87 | } |
| 88 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 89 | void writeBufferToFile(const char* basename) { |
| 90 | std::string filename(basename); |
| 91 | filename.append(::testing::UnitTest::GetInstance()->current_test_info()->name()); |
| 92 | filename.append(".ppm"); |
| 93 | std::ofstream file(filename.c_str(), std::ios::binary); |
| 94 | if (!file.is_open()) { |
| 95 | ALOGE("Unable to open file: %s", filename.c_str()); |
| 96 | ALOGE("You may need to do: \"adb shell setenforce 0\" to enable " |
| 97 | "surfaceflinger to write debug images"); |
| 98 | return; |
| 99 | } |
| 100 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 101 | uint8_t* pixels; |
| 102 | mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 103 | reinterpret_cast<void**>(&pixels)); |
| 104 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 105 | file << "P6\n"; |
| 106 | file << mBuffer->getWidth() << "\n"; |
| 107 | file << mBuffer->getHeight() << "\n"; |
| 108 | file << 255 << "\n"; |
| 109 | |
| 110 | std::vector<uint8_t> outBuffer(mBuffer->getWidth() * mBuffer->getHeight() * 3); |
| 111 | auto outPtr = reinterpret_cast<uint8_t*>(outBuffer.data()); |
| 112 | |
| 113 | for (int32_t j = 0; j < mBuffer->getHeight(); j++) { |
| 114 | const uint8_t* src = pixels + (mBuffer->getStride() * j) * 4; |
| 115 | for (int32_t i = 0; i < mBuffer->getWidth(); i++) { |
| 116 | // Only copy R, G and B components |
| 117 | outPtr[0] = src[0]; |
| 118 | outPtr[1] = src[1]; |
| 119 | outPtr[2] = src[2]; |
| 120 | outPtr += 3; |
| 121 | |
| 122 | src += 4; |
| 123 | } |
| 124 | } |
| 125 | file.write(reinterpret_cast<char*>(outBuffer.data()), outBuffer.size()); |
| 126 | mBuffer->unlock(); |
| 127 | } |
| 128 | |
| 129 | void expectBufferColor(const Region& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a) { |
| 130 | size_t c; |
| 131 | Rect const* rect = region.getArray(&c); |
| 132 | for (size_t i = 0; i < c; i++, rect++) { |
| 133 | expectBufferColor(*rect, r, g, b, a); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | void expectBufferColor(const Rect& rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a, |
| 138 | uint8_t tolerance = 0) { |
| 139 | auto colorCompare = [tolerance](const uint8_t* colorA, const uint8_t* colorB) { |
| 140 | auto colorBitCompare = [tolerance](uint8_t a, uint8_t b) { |
| 141 | uint8_t tmp = a >= b ? a - b : b - a; |
| 142 | return tmp <= tolerance; |
| 143 | }; |
| 144 | return std::equal(colorA, colorA + 4, colorB, colorBitCompare); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 145 | }; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 146 | |
| 147 | expectBufferColor(rect, r, g, b, a, colorCompare); |
| 148 | } |
| 149 | |
| 150 | void expectBufferColor(const Rect& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a, |
| 151 | std::function<bool(const uint8_t* a, const uint8_t* b)> colorCompare) { |
| 152 | uint8_t* pixels; |
| 153 | mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 154 | reinterpret_cast<void**>(&pixels)); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 155 | int32_t maxFails = 10; |
| 156 | int32_t fails = 0; |
| 157 | for (int32_t j = 0; j < region.getHeight(); j++) { |
| 158 | const uint8_t* src = |
| 159 | pixels + (mBuffer->getStride() * (region.top + j) + region.left) * 4; |
| 160 | for (int32_t i = 0; i < region.getWidth(); i++) { |
| 161 | const uint8_t expected[4] = {r, g, b, a}; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 162 | bool equal = colorCompare(src, expected); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 163 | EXPECT_TRUE(equal) |
| 164 | << "pixel @ (" << region.left + i << ", " << region.top + j << "): " |
| 165 | << "expected (" << static_cast<uint32_t>(r) << ", " |
| 166 | << static_cast<uint32_t>(g) << ", " << static_cast<uint32_t>(b) << ", " |
| 167 | << static_cast<uint32_t>(a) << "), " |
| 168 | << "got (" << static_cast<uint32_t>(src[0]) << ", " |
| 169 | << static_cast<uint32_t>(src[1]) << ", " << static_cast<uint32_t>(src[2]) |
| 170 | << ", " << static_cast<uint32_t>(src[3]) << ")"; |
| 171 | src += 4; |
| 172 | if (!equal && ++fails >= maxFails) { |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | if (fails >= maxFails) { |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | mBuffer->unlock(); |
| 181 | } |
| 182 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 183 | void expectAlpha(const Rect& rect, uint8_t a) { |
| 184 | auto colorCompare = [](const uint8_t* colorA, const uint8_t* colorB) { |
| 185 | return colorA[3] == colorB[3]; |
| 186 | }; |
| 187 | expectBufferColor(rect, 0.0f /* r */, 0.0f /*g */, 0.0f /* b */, a, colorCompare); |
| 188 | } |
| 189 | |
| 190 | void expectShadowColor(const renderengine::LayerSettings& castingLayer, |
| 191 | const renderengine::ShadowSettings& shadow, const ubyte4& casterColor, |
| 192 | const ubyte4& backgroundColor) { |
| 193 | const Rect casterRect(castingLayer.geometry.boundaries); |
| 194 | Region casterRegion = Region(casterRect); |
| 195 | const float casterCornerRadius = castingLayer.geometry.roundedCornersRadius; |
| 196 | if (casterCornerRadius > 0.0f) { |
| 197 | // ignore the corners if a corner radius is set |
| 198 | Rect cornerRect(casterCornerRadius, casterCornerRadius); |
| 199 | casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.left, casterRect.top)); |
| 200 | casterRegion.subtractSelf( |
| 201 | cornerRect.offsetTo(casterRect.right - casterCornerRadius, casterRect.top)); |
| 202 | casterRegion.subtractSelf( |
| 203 | cornerRect.offsetTo(casterRect.left, casterRect.bottom - casterCornerRadius)); |
| 204 | casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.right - casterCornerRadius, |
| 205 | casterRect.bottom - casterCornerRadius)); |
| 206 | } |
| 207 | |
| 208 | const float shadowInset = shadow.length * -1.0f; |
| 209 | const Rect casterWithShadow = |
| 210 | Rect(casterRect).inset(shadowInset, shadowInset, shadowInset, shadowInset); |
| 211 | const Region shadowRegion = Region(casterWithShadow).subtractSelf(casterRect); |
| 212 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); |
| 213 | |
| 214 | // verify casting layer |
| 215 | expectBufferColor(casterRegion, casterColor.r, casterColor.g, casterColor.b, casterColor.a); |
| 216 | |
| 217 | // verify shadows by testing just the alpha since its difficult to validate the shadow color |
| 218 | size_t c; |
| 219 | Rect const* r = shadowRegion.getArray(&c); |
| 220 | for (size_t i = 0; i < c; i++, r++) { |
| 221 | expectAlpha(*r, 255); |
| 222 | } |
| 223 | |
| 224 | // verify background |
| 225 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, |
| 226 | backgroundColor.a); |
| 227 | } |
| 228 | |
| 229 | static renderengine::ShadowSettings getShadowSettings(const vec2& casterPos, float shadowLength, |
| 230 | bool casterIsTranslucent) { |
| 231 | renderengine::ShadowSettings shadow; |
| 232 | shadow.ambientColor = {0.0f, 0.0f, 0.0f, 0.039f}; |
| 233 | shadow.spotColor = {0.0f, 0.0f, 0.0f, 0.19f}; |
| 234 | shadow.lightPos = vec3(casterPos.x, casterPos.y, 0); |
| 235 | shadow.lightRadius = 0.0f; |
| 236 | shadow.length = shadowLength; |
| 237 | shadow.casterIsTranslucent = casterIsTranslucent; |
| 238 | return shadow; |
| 239 | } |
| 240 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 241 | static Rect fullscreenRect() { return Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); } |
| 242 | |
| 243 | static Rect offsetRect() { |
| 244 | return Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, |
| 245 | DEFAULT_DISPLAY_HEIGHT); |
| 246 | } |
| 247 | |
| 248 | static Rect offsetRectAtZero() { |
| 249 | return Rect(DEFAULT_DISPLAY_WIDTH - DEFAULT_DISPLAY_OFFSET, |
| 250 | DEFAULT_DISPLAY_HEIGHT - DEFAULT_DISPLAY_OFFSET); |
| 251 | } |
| 252 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 253 | void invokeDraw(renderengine::DisplaySettings settings, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 254 | std::vector<const renderengine::LayerSettings*> layers, |
| 255 | sp<GraphicBuffer> buffer) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 256 | base::unique_fd fence; |
Ana Krulec | fc874ae | 2020-02-22 15:39:32 -0800 | [diff] [blame] | 257 | status_t status = |
| 258 | sRE->drawLayers(settings, layers, buffer, true, base::unique_fd(), &fence); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 259 | sCurrentBuffer = buffer; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 260 | |
| 261 | int fd = fence.release(); |
| 262 | if (fd >= 0) { |
| 263 | sync_wait(fd, -1); |
| 264 | close(fd); |
| 265 | } |
| 266 | |
| 267 | ASSERT_EQ(NO_ERROR, status); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 268 | if (layers.size() > 0) { |
| 269 | ASSERT_TRUE(sRE->isFramebufferImageCachedForTesting(buffer->getId())); |
| 270 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 273 | void drawEmptyLayers() { |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 274 | renderengine::DisplaySettings settings; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 275 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 276 | // Meaningless buffer since we don't do any drawing |
| 277 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 278 | invokeDraw(settings, layers, buffer); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 281 | template <typename SourceVariant> |
| 282 | void fillBuffer(half r, half g, half b, half a); |
| 283 | |
| 284 | template <typename SourceVariant> |
| 285 | void fillRedBuffer(); |
| 286 | |
| 287 | template <typename SourceVariant> |
| 288 | void fillGreenBuffer(); |
| 289 | |
| 290 | template <typename SourceVariant> |
| 291 | void fillBlueBuffer(); |
| 292 | |
| 293 | template <typename SourceVariant> |
| 294 | void fillRedTransparentBuffer(); |
| 295 | |
| 296 | template <typename SourceVariant> |
| 297 | void fillRedOffsetBuffer(); |
| 298 | |
| 299 | template <typename SourceVariant> |
| 300 | void fillBufferPhysicalOffset(); |
| 301 | |
| 302 | template <typename SourceVariant> |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 303 | void fillBufferCheckers(uint32_t rotation); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 304 | |
| 305 | template <typename SourceVariant> |
| 306 | void fillBufferCheckersRotate0(); |
| 307 | |
| 308 | template <typename SourceVariant> |
| 309 | void fillBufferCheckersRotate90(); |
| 310 | |
| 311 | template <typename SourceVariant> |
| 312 | void fillBufferCheckersRotate180(); |
| 313 | |
| 314 | template <typename SourceVariant> |
| 315 | void fillBufferCheckersRotate270(); |
| 316 | |
| 317 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 318 | void fillBufferWithLayerTransform(); |
| 319 | |
| 320 | template <typename SourceVariant> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 321 | void fillBufferLayerTransform(); |
| 322 | |
| 323 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 324 | void fillBufferWithColorTransform(); |
| 325 | |
| 326 | template <typename SourceVariant> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 327 | void fillBufferColorTransform(); |
| 328 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 329 | template <typename SourceVariant> |
| 330 | void fillRedBufferWithRoundedCorners(); |
| 331 | |
| 332 | template <typename SourceVariant> |
| 333 | void fillBufferWithRoundedCorners(); |
| 334 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 335 | template <typename SourceVariant> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 336 | void fillBufferAndBlurBackground(); |
| 337 | |
| 338 | template <typename SourceVariant> |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 339 | void overlayCorners(); |
| 340 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 341 | void fillRedBufferTextureTransform(); |
| 342 | |
| 343 | void fillBufferTextureTransform(); |
| 344 | |
| 345 | void fillRedBufferWithPremultiplyAlpha(); |
| 346 | |
| 347 | void fillBufferWithPremultiplyAlpha(); |
| 348 | |
| 349 | void fillRedBufferWithoutPremultiplyAlpha(); |
| 350 | |
| 351 | void fillBufferWithoutPremultiplyAlpha(); |
| 352 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 353 | void fillGreenColorBufferThenClearRegion(); |
| 354 | |
| 355 | void clearLeftRegion(); |
| 356 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 357 | void clearRegion(); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 358 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 359 | template <typename SourceVariant> |
| 360 | void drawShadow(const renderengine::LayerSettings& castingLayer, |
| 361 | const renderengine::ShadowSettings& shadow, const ubyte4& casterColor, |
| 362 | const ubyte4& backgroundColor); |
| 363 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 364 | // Keep around the same renderengine object to save on initialization time. |
| 365 | // For now, exercise the GL backend directly so that some caching specifics |
| 366 | // can be tested without changing the interface. |
| 367 | static std::unique_ptr<renderengine::gl::GLESRenderEngine> sRE; |
| 368 | // Dumb hack to avoid NPE in the EGL driver: the GraphicBuffer needs to |
| 369 | // be freed *after* RenderEngine is destroyed, so that the EGL image is |
| 370 | // destroyed first. |
| 371 | static sp<GraphicBuffer> sCurrentBuffer; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 372 | |
| 373 | sp<GraphicBuffer> mBuffer; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 374 | |
| 375 | std::vector<uint32_t> mTexNames; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 376 | }; |
| 377 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 378 | std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRE = nullptr; |
| 379 | sp<GraphicBuffer> RenderEngineTest::sCurrentBuffer = nullptr; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 380 | |
| 381 | struct ColorSourceVariant { |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 382 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
| 383 | RenderEngineTest* /*fixture*/) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 384 | layer.source.solidColor = half3(r, g, b); |
| 385 | } |
| 386 | }; |
| 387 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 388 | struct RelaxOpaqueBufferVariant { |
| 389 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 390 | layer.source.buffer.isOpaque = false; |
| 391 | } |
| 392 | |
| 393 | static uint8_t getAlphaChannel() { return 255; } |
| 394 | }; |
| 395 | |
| 396 | struct ForceOpaqueBufferVariant { |
| 397 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 398 | layer.source.buffer.isOpaque = true; |
| 399 | } |
| 400 | |
| 401 | static uint8_t getAlphaChannel() { |
| 402 | // The isOpaque bit will override the alpha channel, so this should be |
| 403 | // arbitrary. |
| 404 | return 10; |
| 405 | } |
| 406 | }; |
| 407 | |
| 408 | template <typename OpaquenessVariant> |
| 409 | struct BufferSourceVariant { |
| 410 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
| 411 | RenderEngineTest* fixture) { |
| 412 | sp<GraphicBuffer> buf = RenderEngineTest::allocateSourceBuffer(1, 1); |
| 413 | uint32_t texName; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 414 | fixture->sRE->genTextures(1, &texName); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 415 | fixture->mTexNames.push_back(texName); |
| 416 | |
| 417 | uint8_t* pixels; |
| 418 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 419 | reinterpret_cast<void**>(&pixels)); |
| 420 | |
| 421 | for (int32_t j = 0; j < buf->getHeight(); j++) { |
| 422 | uint8_t* iter = pixels + (buf->getStride() * j) * 4; |
| 423 | for (int32_t i = 0; i < buf->getWidth(); i++) { |
| 424 | iter[0] = uint8_t(r * 255); |
| 425 | iter[1] = uint8_t(g * 255); |
| 426 | iter[2] = uint8_t(b * 255); |
| 427 | iter[3] = OpaquenessVariant::getAlphaChannel(); |
| 428 | iter += 4; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | buf->unlock(); |
| 433 | |
| 434 | layer.source.buffer.buffer = buf; |
| 435 | layer.source.buffer.textureName = texName; |
| 436 | OpaquenessVariant::setOpaqueBit(layer); |
| 437 | } |
| 438 | }; |
| 439 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 440 | template <typename SourceVariant> |
| 441 | void RenderEngineTest::fillBuffer(half r, half g, half b, half a) { |
| 442 | renderengine::DisplaySettings settings; |
| 443 | settings.physicalDisplay = fullscreenRect(); |
| 444 | settings.clip = fullscreenRect(); |
| 445 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 446 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 447 | |
| 448 | renderengine::LayerSettings layer; |
| 449 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 450 | SourceVariant::fillColor(layer, r, g, b, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 451 | layer.alpha = a; |
| 452 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 453 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 454 | |
| 455 | invokeDraw(settings, layers, mBuffer); |
| 456 | } |
| 457 | |
| 458 | template <typename SourceVariant> |
| 459 | void RenderEngineTest::fillRedBuffer() { |
| 460 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, 1.0f); |
| 461 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 462 | } |
| 463 | |
| 464 | template <typename SourceVariant> |
| 465 | void RenderEngineTest::fillGreenBuffer() { |
| 466 | fillBuffer<SourceVariant>(0.0f, 1.0f, 0.0f, 1.0f); |
| 467 | expectBufferColor(fullscreenRect(), 0, 255, 0, 255); |
| 468 | } |
| 469 | |
| 470 | template <typename SourceVariant> |
| 471 | void RenderEngineTest::fillBlueBuffer() { |
| 472 | fillBuffer<SourceVariant>(0.0f, 0.0f, 1.0f, 1.0f); |
| 473 | expectBufferColor(fullscreenRect(), 0, 0, 255, 255); |
| 474 | } |
| 475 | |
| 476 | template <typename SourceVariant> |
| 477 | void RenderEngineTest::fillRedTransparentBuffer() { |
| 478 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, .2f); |
| 479 | expectBufferColor(fullscreenRect(), 51, 0, 0, 51); |
| 480 | } |
| 481 | |
| 482 | template <typename SourceVariant> |
| 483 | void RenderEngineTest::fillRedOffsetBuffer() { |
| 484 | renderengine::DisplaySettings settings; |
| 485 | settings.physicalDisplay = offsetRect(); |
| 486 | settings.clip = offsetRectAtZero(); |
| 487 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 488 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 489 | |
| 490 | renderengine::LayerSettings layer; |
| 491 | layer.geometry.boundaries = offsetRectAtZero().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 492 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 493 | layer.alpha = 1.0f; |
| 494 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 495 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 496 | invokeDraw(settings, layers, mBuffer); |
| 497 | } |
| 498 | |
| 499 | template <typename SourceVariant> |
| 500 | void RenderEngineTest::fillBufferPhysicalOffset() { |
| 501 | fillRedOffsetBuffer<SourceVariant>(); |
| 502 | |
| 503 | expectBufferColor(Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, |
| 504 | DEFAULT_DISPLAY_HEIGHT), |
| 505 | 255, 0, 0, 255); |
| 506 | Rect offsetRegionLeft(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_HEIGHT); |
| 507 | Rect offsetRegionTop(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_OFFSET); |
| 508 | |
| 509 | expectBufferColor(offsetRegionLeft, 0, 0, 0, 0); |
| 510 | expectBufferColor(offsetRegionTop, 0, 0, 0, 0); |
| 511 | } |
| 512 | |
| 513 | template <typename SourceVariant> |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 514 | void RenderEngineTest::fillBufferCheckers(uint32_t orientationFlag) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 515 | renderengine::DisplaySettings settings; |
| 516 | settings.physicalDisplay = fullscreenRect(); |
| 517 | // Here logical space is 2x2 |
| 518 | settings.clip = Rect(2, 2); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 519 | settings.orientation = orientationFlag; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 520 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 521 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 522 | |
| 523 | renderengine::LayerSettings layerOne; |
| 524 | Rect rectOne(0, 0, 1, 1); |
| 525 | layerOne.geometry.boundaries = rectOne.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 526 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 527 | layerOne.alpha = 1.0f; |
| 528 | |
| 529 | renderengine::LayerSettings layerTwo; |
| 530 | Rect rectTwo(0, 1, 1, 2); |
| 531 | layerTwo.geometry.boundaries = rectTwo.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 532 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 533 | layerTwo.alpha = 1.0f; |
| 534 | |
| 535 | renderengine::LayerSettings layerThree; |
| 536 | Rect rectThree(1, 0, 2, 1); |
| 537 | layerThree.geometry.boundaries = rectThree.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 538 | SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 539 | layerThree.alpha = 1.0f; |
| 540 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 541 | layers.push_back(&layerOne); |
| 542 | layers.push_back(&layerTwo); |
| 543 | layers.push_back(&layerThree); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 544 | |
| 545 | invokeDraw(settings, layers, mBuffer); |
| 546 | } |
| 547 | |
| 548 | template <typename SourceVariant> |
| 549 | void RenderEngineTest::fillBufferCheckersRotate0() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 550 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_0); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 551 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, |
| 552 | 255); |
| 553 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 554 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 555 | 0, 0, 255, 255); |
| 556 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 557 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 558 | 0, 0, 0, 0); |
| 559 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 560 | DEFAULT_DISPLAY_HEIGHT), |
| 561 | 0, 255, 0, 255); |
| 562 | } |
| 563 | |
| 564 | template <typename SourceVariant> |
| 565 | void RenderEngineTest::fillBufferCheckersRotate90() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 566 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_90); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 567 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 255, 0, |
| 568 | 255); |
| 569 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 570 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 571 | 255, 0, 0, 255); |
| 572 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 573 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 574 | 0, 0, 255, 255); |
| 575 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 576 | DEFAULT_DISPLAY_HEIGHT), |
| 577 | 0, 0, 0, 0); |
| 578 | } |
| 579 | |
| 580 | template <typename SourceVariant> |
| 581 | void RenderEngineTest::fillBufferCheckersRotate180() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 582 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_180); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 583 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, |
| 584 | 0); |
| 585 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 586 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 587 | 0, 255, 0, 255); |
| 588 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 589 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 590 | 255, 0, 0, 255); |
| 591 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 592 | DEFAULT_DISPLAY_HEIGHT), |
| 593 | 0, 0, 255, 255); |
| 594 | } |
| 595 | |
| 596 | template <typename SourceVariant> |
| 597 | void RenderEngineTest::fillBufferCheckersRotate270() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 598 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_270); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 599 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255, |
| 600 | 255); |
| 601 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 602 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 603 | 0, 0, 0, 0); |
| 604 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 605 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 606 | 0, 255, 0, 255); |
| 607 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 608 | DEFAULT_DISPLAY_HEIGHT), |
| 609 | 255, 0, 0, 255); |
| 610 | } |
| 611 | |
| 612 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 613 | void RenderEngineTest::fillBufferWithLayerTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 614 | renderengine::DisplaySettings settings; |
| 615 | settings.physicalDisplay = fullscreenRect(); |
| 616 | // Here logical space is 2x2 |
| 617 | settings.clip = Rect(2, 2); |
| 618 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 619 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 620 | |
| 621 | renderengine::LayerSettings layer; |
| 622 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 623 | // Translate one pixel diagonally |
| 624 | layer.geometry.positionTransform = mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 625 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 626 | layer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 627 | layer.alpha = 1.0f; |
| 628 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 629 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 630 | |
| 631 | invokeDraw(settings, layers, mBuffer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 632 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 633 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 634 | template <typename SourceVariant> |
| 635 | void RenderEngineTest::fillBufferLayerTransform() { |
| 636 | fillBufferWithLayerTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 637 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, 0); |
| 638 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 639 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 640 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 641 | 255, 0, 0, 255); |
| 642 | } |
| 643 | |
| 644 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 645 | void RenderEngineTest::fillBufferWithColorTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 646 | renderengine::DisplaySettings settings; |
| 647 | settings.physicalDisplay = fullscreenRect(); |
| 648 | settings.clip = Rect(1, 1); |
| 649 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 650 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 651 | |
| 652 | renderengine::LayerSettings layer; |
| 653 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 654 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 655 | layer.alpha = 1.0f; |
| 656 | |
| 657 | // construct a fake color matrix |
| 658 | // annihilate green and blue channels |
| 659 | settings.colorTransform = mat4::scale(vec4(1, 0, 0, 1)); |
| 660 | // set red channel to red + green |
| 661 | layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 662 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 663 | layer.alpha = 1.0f; |
| 664 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 665 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 666 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 667 | |
| 668 | invokeDraw(settings, layers, mBuffer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 669 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 670 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 671 | template <typename SourceVariant> |
| 672 | void RenderEngineTest::fillBufferColorTransform() { |
| 673 | fillBufferWithColorTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 674 | expectBufferColor(fullscreenRect(), 191, 0, 0, 255); |
| 675 | } |
| 676 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 677 | template <typename SourceVariant> |
| 678 | void RenderEngineTest::fillRedBufferWithRoundedCorners() { |
| 679 | renderengine::DisplaySettings settings; |
| 680 | settings.physicalDisplay = fullscreenRect(); |
| 681 | settings.clip = fullscreenRect(); |
| 682 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 683 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 684 | |
| 685 | renderengine::LayerSettings layer; |
| 686 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 687 | layer.geometry.roundedCornersRadius = 5.0f; |
| 688 | layer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 689 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 690 | layer.alpha = 1.0f; |
| 691 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 692 | layers.push_back(&layer); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 693 | |
| 694 | invokeDraw(settings, layers, mBuffer); |
| 695 | } |
| 696 | |
| 697 | template <typename SourceVariant> |
| 698 | void RenderEngineTest::fillBufferWithRoundedCorners() { |
| 699 | fillRedBufferWithRoundedCorners<SourceVariant>(); |
| 700 | // Corners should be ignored... |
| 701 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); |
| 702 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); |
| 703 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 704 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, |
| 705 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 706 | 0, 0, 0, 0); |
| 707 | // ...And the non-rounded portion should be red. |
| 708 | // Other pixels may be anti-aliased, so let's not check those. |
| 709 | expectBufferColor(Rect(5, 5, DEFAULT_DISPLAY_WIDTH - 5, DEFAULT_DISPLAY_HEIGHT - 5), 255, 0, 0, |
| 710 | 255); |
| 711 | } |
| 712 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 713 | template <typename SourceVariant> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 714 | void RenderEngineTest::fillBufferAndBlurBackground() { |
| 715 | char value[PROPERTY_VALUE_MAX]; |
| 716 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 717 | if (!atoi(value)) { |
| 718 | // This device doesn't support blurs, no-op. |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | auto blurRadius = 50; |
| 723 | auto center = DEFAULT_DISPLAY_WIDTH / 2; |
| 724 | |
| 725 | renderengine::DisplaySettings settings; |
| 726 | settings.physicalDisplay = fullscreenRect(); |
| 727 | settings.clip = fullscreenRect(); |
| 728 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 729 | std::vector<const renderengine::LayerSettings*> layers; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 730 | |
| 731 | renderengine::LayerSettings backgroundLayer; |
| 732 | backgroundLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 733 | SourceVariant::fillColor(backgroundLayer, 0.0f, 1.0f, 0.0f, this); |
| 734 | backgroundLayer.alpha = 1.0f; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 735 | layers.push_back(&backgroundLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 736 | |
| 737 | renderengine::LayerSettings leftLayer; |
| 738 | leftLayer.geometry.boundaries = |
| 739 | Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT).toFloatRect(); |
| 740 | SourceVariant::fillColor(leftLayer, 1.0f, 0.0f, 0.0f, this); |
| 741 | leftLayer.alpha = 1.0f; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 742 | layers.push_back(&leftLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 743 | |
| 744 | renderengine::LayerSettings blurLayer; |
| 745 | blurLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 746 | blurLayer.backgroundBlurRadius = blurRadius; |
| 747 | blurLayer.alpha = 0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 748 | layers.push_back(&blurLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 749 | |
| 750 | invokeDraw(settings, layers, mBuffer); |
| 751 | |
| 752 | expectBufferColor(Rect(center - 1, center - 5, center, center + 5), 150, 150, 0, 255, |
| 753 | 50 /* tolerance */); |
| 754 | expectBufferColor(Rect(center, center - 5, center + 1, center + 5), 150, 150, 0, 255, |
| 755 | 50 /* tolerance */); |
| 756 | } |
| 757 | |
| 758 | template <typename SourceVariant> |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 759 | void RenderEngineTest::overlayCorners() { |
| 760 | renderengine::DisplaySettings settings; |
| 761 | settings.physicalDisplay = fullscreenRect(); |
| 762 | settings.clip = fullscreenRect(); |
| 763 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 764 | std::vector<const renderengine::LayerSettings*> layersFirst; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 765 | |
| 766 | renderengine::LayerSettings layerOne; |
| 767 | layerOne.geometry.boundaries = |
| 768 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0); |
| 769 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
| 770 | layerOne.alpha = 0.2; |
| 771 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 772 | layersFirst.push_back(&layerOne); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 773 | invokeDraw(settings, layersFirst, mBuffer); |
| 774 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51); |
| 775 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 776 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 777 | 0, 0, 0, 0); |
| 778 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 779 | std::vector<const renderengine::LayerSettings*> layersSecond; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 780 | renderengine::LayerSettings layerTwo; |
| 781 | layerTwo.geometry.boundaries = |
| 782 | FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0, |
| 783 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); |
| 784 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
| 785 | layerTwo.alpha = 1.0f; |
| 786 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 787 | layersSecond.push_back(&layerTwo); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 788 | invokeDraw(settings, layersSecond, mBuffer); |
| 789 | |
| 790 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0); |
| 791 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 792 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 793 | 0, 255, 0, 255); |
| 794 | } |
| 795 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 796 | void RenderEngineTest::fillRedBufferTextureTransform() { |
| 797 | renderengine::DisplaySettings settings; |
| 798 | settings.physicalDisplay = fullscreenRect(); |
| 799 | settings.clip = Rect(1, 1); |
| 800 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 801 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 802 | |
| 803 | renderengine::LayerSettings layer; |
| 804 | // Here will allocate a checker board texture, but transform texture |
| 805 | // coordinates so that only the upper left is applied. |
| 806 | sp<GraphicBuffer> buf = allocateSourceBuffer(2, 2); |
| 807 | uint32_t texName; |
| 808 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 809 | this->mTexNames.push_back(texName); |
| 810 | |
| 811 | uint8_t* pixels; |
| 812 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 813 | reinterpret_cast<void**>(&pixels)); |
| 814 | // Red top left, Green top right, Blue bottom left, Black bottom right |
| 815 | pixels[0] = 255; |
| 816 | pixels[1] = 0; |
| 817 | pixels[2] = 0; |
| 818 | pixels[3] = 255; |
| 819 | pixels[4] = 0; |
| 820 | pixels[5] = 255; |
| 821 | pixels[6] = 0; |
| 822 | pixels[7] = 255; |
| 823 | pixels[8] = 0; |
| 824 | pixels[9] = 0; |
| 825 | pixels[10] = 255; |
| 826 | pixels[11] = 255; |
| 827 | buf->unlock(); |
| 828 | |
| 829 | layer.source.buffer.buffer = buf; |
| 830 | layer.source.buffer.textureName = texName; |
| 831 | // Transform coordinates to only be inside the red quadrant. |
| 832 | layer.source.buffer.textureTransform = mat4::scale(vec4(0.2, 0.2, 1, 1)); |
| 833 | layer.alpha = 1.0f; |
| 834 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 835 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 836 | layers.push_back(&layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 837 | |
| 838 | invokeDraw(settings, layers, mBuffer); |
| 839 | } |
| 840 | |
| 841 | void RenderEngineTest::fillBufferTextureTransform() { |
| 842 | fillRedBufferTextureTransform(); |
| 843 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 844 | } |
| 845 | |
| 846 | void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() { |
| 847 | renderengine::DisplaySettings settings; |
| 848 | settings.physicalDisplay = fullscreenRect(); |
| 849 | // Here logical space is 1x1 |
| 850 | settings.clip = Rect(1, 1); |
| 851 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 852 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 853 | |
| 854 | renderengine::LayerSettings layer; |
| 855 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 856 | uint32_t texName; |
| 857 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 858 | this->mTexNames.push_back(texName); |
| 859 | |
| 860 | uint8_t* pixels; |
| 861 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 862 | reinterpret_cast<void**>(&pixels)); |
| 863 | pixels[0] = 255; |
| 864 | pixels[1] = 0; |
| 865 | pixels[2] = 0; |
| 866 | pixels[3] = 255; |
| 867 | buf->unlock(); |
| 868 | |
| 869 | layer.source.buffer.buffer = buf; |
| 870 | layer.source.buffer.textureName = texName; |
| 871 | layer.source.buffer.usePremultipliedAlpha = true; |
| 872 | layer.alpha = 0.5f; |
| 873 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 874 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 875 | layers.push_back(&layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 876 | |
| 877 | invokeDraw(settings, layers, mBuffer); |
| 878 | } |
| 879 | |
| 880 | void RenderEngineTest::fillBufferWithPremultiplyAlpha() { |
| 881 | fillRedBufferWithPremultiplyAlpha(); |
| 882 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128); |
| 883 | } |
| 884 | |
| 885 | void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() { |
| 886 | renderengine::DisplaySettings settings; |
| 887 | settings.physicalDisplay = fullscreenRect(); |
| 888 | // Here logical space is 1x1 |
| 889 | settings.clip = Rect(1, 1); |
| 890 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 891 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 892 | |
| 893 | renderengine::LayerSettings layer; |
| 894 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 895 | uint32_t texName; |
| 896 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 897 | this->mTexNames.push_back(texName); |
| 898 | |
| 899 | uint8_t* pixels; |
| 900 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 901 | reinterpret_cast<void**>(&pixels)); |
| 902 | pixels[0] = 255; |
| 903 | pixels[1] = 0; |
| 904 | pixels[2] = 0; |
| 905 | pixels[3] = 255; |
| 906 | buf->unlock(); |
| 907 | |
| 908 | layer.source.buffer.buffer = buf; |
| 909 | layer.source.buffer.textureName = texName; |
| 910 | layer.source.buffer.usePremultipliedAlpha = false; |
| 911 | layer.alpha = 0.5f; |
| 912 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 913 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 914 | layers.push_back(&layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 915 | |
| 916 | invokeDraw(settings, layers, mBuffer); |
| 917 | } |
| 918 | |
| 919 | void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() { |
| 920 | fillRedBufferWithoutPremultiplyAlpha(); |
| 921 | expectBufferColor(fullscreenRect(), 128, 0, 0, 64, 1); |
| 922 | } |
| 923 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 924 | void RenderEngineTest::clearLeftRegion() { |
| 925 | renderengine::DisplaySettings settings; |
| 926 | settings.physicalDisplay = fullscreenRect(); |
| 927 | // Here logical space is 4x4 |
| 928 | settings.clip = Rect(4, 4); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 929 | settings.clearRegion = Region(Rect(2, 4)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 930 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 931 | // dummy layer, without bounds should not render anything |
| 932 | renderengine::LayerSettings layer; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 933 | layers.push_back(&layer); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 934 | invokeDraw(settings, layers, mBuffer); |
| 935 | } |
| 936 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 937 | void RenderEngineTest::clearRegion() { |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 938 | // Reuse mBuffer |
| 939 | clearLeftRegion(); |
| 940 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 255); |
| 941 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 942 | DEFAULT_DISPLAY_HEIGHT), |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 943 | 0, 0, 0, 0); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 944 | } |
| 945 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 946 | template <typename SourceVariant> |
| 947 | void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer, |
| 948 | const renderengine::ShadowSettings& shadow, |
| 949 | const ubyte4& casterColor, const ubyte4& backgroundColor) { |
| 950 | renderengine::DisplaySettings settings; |
| 951 | settings.physicalDisplay = fullscreenRect(); |
| 952 | settings.clip = fullscreenRect(); |
| 953 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 954 | std::vector<const renderengine::LayerSettings*> layers; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 955 | |
| 956 | // add background layer |
| 957 | renderengine::LayerSettings bgLayer; |
| 958 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 959 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 960 | backgroundColor.b / 255.0f, this); |
| 961 | bgLayer.alpha = backgroundColor.a / 255.0f; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 962 | layers.push_back(&bgLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 963 | |
| 964 | // add shadow layer |
| 965 | renderengine::LayerSettings shadowLayer; |
| 966 | shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries; |
| 967 | shadowLayer.alpha = castingLayer.alpha; |
| 968 | shadowLayer.shadow = shadow; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 969 | layers.push_back(&shadowLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 970 | |
| 971 | // add layer casting the shadow |
| 972 | renderengine::LayerSettings layer = castingLayer; |
| 973 | SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f, |
| 974 | casterColor.b / 255.0f, this); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 975 | layers.push_back(&layer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 976 | |
| 977 | invokeDraw(settings, layers, mBuffer); |
| 978 | } |
| 979 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 980 | TEST_F(RenderEngineTest, drawLayers_noLayersToDraw) { |
| 981 | drawEmptyLayers(); |
| 982 | } |
| 983 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 984 | TEST_F(RenderEngineTest, drawLayers_nullOutputBuffer) { |
| 985 | renderengine::DisplaySettings settings; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 986 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 987 | renderengine::LayerSettings layer; |
| 988 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 989 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 990 | layers.push_back(&layer); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 991 | base::unique_fd fence; |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 992 | 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] | 993 | |
| 994 | ASSERT_EQ(BAD_VALUE, status); |
| 995 | } |
| 996 | |
| 997 | TEST_F(RenderEngineTest, drawLayers_nullOutputFence) { |
| 998 | renderengine::DisplaySettings settings; |
| 999 | settings.physicalDisplay = fullscreenRect(); |
| 1000 | settings.clip = fullscreenRect(); |
| 1001 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1002 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1003 | renderengine::LayerSettings layer; |
| 1004 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1005 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1006 | layer.alpha = 1.0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1007 | layers.push_back(&layer); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1008 | |
Ana Krulec | fc874ae | 2020-02-22 15:39:32 -0800 | [diff] [blame] | 1009 | status_t status = sRE->drawLayers(settings, layers, mBuffer, true, base::unique_fd(), nullptr); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 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 | |
Ana Krulec | fc874ae | 2020-02-22 15:39:32 -0800 | [diff] [blame] | 1027 | status_t status = sRE->drawLayers(settings, layers, mBuffer, false, base::unique_fd(), nullptr); |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 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 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [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 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [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 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [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 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [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 | |
Lingfeng Yang | 2e4fef6 | 2020-04-24 14:48:43 +0000 | [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, true, base::unique_fd(), &fenceOne); |
| 1418 | base::unique_fd fenceTwo; |
| 1419 | sRE->drawLayers(settings, layers, mBuffer, true, std::move(fenceOne), &fenceTwo); |
| 1420 | |
| 1421 | const int fd = fenceTwo.get(); |
| 1422 | if (fd >= 0) { |
| 1423 | sync_wait(fd, -1); |
| 1424 | } |
| 1425 | |
| 1426 | // Only cleanup the first time. |
| 1427 | EXPECT_TRUE(sRE->cleanupPostRender()); |
| 1428 | EXPECT_FALSE(sRE->cleanupPostRender()); |
| 1429 | } |
| 1430 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1431 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1432 | |
| 1433 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1434 | #pragma clang diagnostic pop // ignored "-Wconversion" |