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