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