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