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> |
KaiChieh Chuang | de09f10 | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 348 | void fillBufferWithColorTransformZeroLayerAlpha(); |
| 349 | |
| 350 | template <typename SourceVariant> |
| 351 | void fillBufferColorTransformZeroLayerAlpha(); |
| 352 | |
| 353 | template <typename SourceVariant> |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 354 | void fillRedBufferWithRoundedCorners(); |
| 355 | |
| 356 | template <typename SourceVariant> |
| 357 | void fillBufferWithRoundedCorners(); |
| 358 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 359 | template <typename SourceVariant> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 360 | void fillBufferAndBlurBackground(); |
| 361 | |
| 362 | template <typename SourceVariant> |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 363 | void overlayCorners(); |
| 364 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 365 | void fillRedBufferTextureTransform(); |
| 366 | |
| 367 | void fillBufferTextureTransform(); |
| 368 | |
| 369 | void fillRedBufferWithPremultiplyAlpha(); |
| 370 | |
| 371 | void fillBufferWithPremultiplyAlpha(); |
| 372 | |
| 373 | void fillRedBufferWithoutPremultiplyAlpha(); |
| 374 | |
| 375 | void fillBufferWithoutPremultiplyAlpha(); |
| 376 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 377 | void fillGreenColorBufferThenClearRegion(); |
| 378 | |
| 379 | void clearLeftRegion(); |
| 380 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 381 | void clearRegion(); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 382 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 383 | template <typename SourceVariant> |
| 384 | void drawShadow(const renderengine::LayerSettings& castingLayer, |
| 385 | const renderengine::ShadowSettings& shadow, const ubyte4& casterColor, |
| 386 | const ubyte4& backgroundColor); |
| 387 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 388 | // Keep around the same renderengine object to save on initialization time. |
| 389 | // For now, exercise the GL backend directly so that some caching specifics |
| 390 | // can be tested without changing the interface. |
| 391 | static std::unique_ptr<renderengine::gl::GLESRenderEngine> sRE; |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 392 | // renderengine object with Color Management enabled |
| 393 | static std::unique_ptr<renderengine::gl::GLESRenderEngine> sRECM; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 394 | // Dumb hack to avoid NPE in the EGL driver: the GraphicBuffer needs to |
| 395 | // be freed *after* RenderEngine is destroyed, so that the EGL image is |
| 396 | // destroyed first. |
| 397 | static sp<GraphicBuffer> sCurrentBuffer; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 398 | |
| 399 | sp<GraphicBuffer> mBuffer; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 400 | |
| 401 | std::vector<uint32_t> mTexNames; |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 402 | std::vector<uint32_t> mTexNamesCM; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 403 | }; |
| 404 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 405 | std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRE = nullptr; |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 406 | std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRECM = nullptr; |
| 407 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 408 | sp<GraphicBuffer> RenderEngineTest::sCurrentBuffer = nullptr; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 409 | |
| 410 | struct ColorSourceVariant { |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 411 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 412 | RenderEngineTest* /*fixture*/, bool /*useColorManagement*/ = false) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 413 | layer.source.solidColor = half3(r, g, b); |
| 414 | } |
| 415 | }; |
| 416 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 417 | struct RelaxOpaqueBufferVariant { |
| 418 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 419 | layer.source.buffer.isOpaque = false; |
| 420 | } |
| 421 | |
| 422 | static uint8_t getAlphaChannel() { return 255; } |
| 423 | }; |
| 424 | |
| 425 | struct ForceOpaqueBufferVariant { |
| 426 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 427 | layer.source.buffer.isOpaque = true; |
| 428 | } |
| 429 | |
| 430 | static uint8_t getAlphaChannel() { |
| 431 | // The isOpaque bit will override the alpha channel, so this should be |
| 432 | // arbitrary. |
| 433 | return 10; |
| 434 | } |
| 435 | }; |
| 436 | |
| 437 | template <typename OpaquenessVariant> |
| 438 | struct BufferSourceVariant { |
| 439 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 440 | RenderEngineTest* fixture, |
| 441 | bool useColorManagement = false) { |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 442 | sp<GraphicBuffer> buf = RenderEngineTest::allocateSourceBuffer(1, 1); |
| 443 | uint32_t texName; |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 444 | if (useColorManagement) { |
| 445 | fixture->sRECM->genTextures(1, &texName); |
| 446 | fixture->mTexNamesCM.push_back(texName); |
| 447 | } else { |
| 448 | fixture->sRE->genTextures(1, &texName); |
| 449 | fixture->mTexNames.push_back(texName); |
| 450 | } |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 451 | |
| 452 | uint8_t* pixels; |
| 453 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 454 | reinterpret_cast<void**>(&pixels)); |
| 455 | |
| 456 | for (int32_t j = 0; j < buf->getHeight(); j++) { |
| 457 | uint8_t* iter = pixels + (buf->getStride() * j) * 4; |
| 458 | for (int32_t i = 0; i < buf->getWidth(); i++) { |
| 459 | iter[0] = uint8_t(r * 255); |
| 460 | iter[1] = uint8_t(g * 255); |
| 461 | iter[2] = uint8_t(b * 255); |
| 462 | iter[3] = OpaquenessVariant::getAlphaChannel(); |
| 463 | iter += 4; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | buf->unlock(); |
| 468 | |
| 469 | layer.source.buffer.buffer = buf; |
| 470 | layer.source.buffer.textureName = texName; |
| 471 | OpaquenessVariant::setOpaqueBit(layer); |
| 472 | } |
| 473 | }; |
| 474 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 475 | template <typename SourceVariant> |
| 476 | void RenderEngineTest::fillBuffer(half r, half g, half b, half a) { |
| 477 | renderengine::DisplaySettings settings; |
| 478 | settings.physicalDisplay = fullscreenRect(); |
| 479 | settings.clip = fullscreenRect(); |
| 480 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 481 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 482 | |
| 483 | renderengine::LayerSettings layer; |
| 484 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 485 | SourceVariant::fillColor(layer, r, g, b, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 486 | layer.alpha = a; |
| 487 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 488 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 489 | |
| 490 | invokeDraw(settings, layers, mBuffer); |
| 491 | } |
| 492 | |
| 493 | template <typename SourceVariant> |
| 494 | void RenderEngineTest::fillRedBuffer() { |
| 495 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, 1.0f); |
| 496 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 497 | } |
| 498 | |
| 499 | template <typename SourceVariant> |
| 500 | void RenderEngineTest::fillGreenBuffer() { |
| 501 | fillBuffer<SourceVariant>(0.0f, 1.0f, 0.0f, 1.0f); |
| 502 | expectBufferColor(fullscreenRect(), 0, 255, 0, 255); |
| 503 | } |
| 504 | |
| 505 | template <typename SourceVariant> |
| 506 | void RenderEngineTest::fillBlueBuffer() { |
| 507 | fillBuffer<SourceVariant>(0.0f, 0.0f, 1.0f, 1.0f); |
| 508 | expectBufferColor(fullscreenRect(), 0, 0, 255, 255); |
| 509 | } |
| 510 | |
| 511 | template <typename SourceVariant> |
| 512 | void RenderEngineTest::fillRedTransparentBuffer() { |
| 513 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, .2f); |
| 514 | expectBufferColor(fullscreenRect(), 51, 0, 0, 51); |
| 515 | } |
| 516 | |
| 517 | template <typename SourceVariant> |
| 518 | void RenderEngineTest::fillRedOffsetBuffer() { |
| 519 | renderengine::DisplaySettings settings; |
| 520 | settings.physicalDisplay = offsetRect(); |
| 521 | settings.clip = offsetRectAtZero(); |
| 522 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 523 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 524 | |
| 525 | renderengine::LayerSettings layer; |
| 526 | layer.geometry.boundaries = offsetRectAtZero().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 527 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 528 | layer.alpha = 1.0f; |
| 529 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 530 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 531 | invokeDraw(settings, layers, mBuffer); |
| 532 | } |
| 533 | |
| 534 | template <typename SourceVariant> |
| 535 | void RenderEngineTest::fillBufferPhysicalOffset() { |
| 536 | fillRedOffsetBuffer<SourceVariant>(); |
| 537 | |
| 538 | expectBufferColor(Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, |
| 539 | DEFAULT_DISPLAY_HEIGHT), |
| 540 | 255, 0, 0, 255); |
| 541 | Rect offsetRegionLeft(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_HEIGHT); |
| 542 | Rect offsetRegionTop(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_OFFSET); |
| 543 | |
| 544 | expectBufferColor(offsetRegionLeft, 0, 0, 0, 0); |
| 545 | expectBufferColor(offsetRegionTop, 0, 0, 0, 0); |
| 546 | } |
| 547 | |
| 548 | template <typename SourceVariant> |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 549 | void RenderEngineTest::fillBufferCheckers(uint32_t orientationFlag) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 550 | renderengine::DisplaySettings settings; |
| 551 | settings.physicalDisplay = fullscreenRect(); |
| 552 | // Here logical space is 2x2 |
| 553 | settings.clip = Rect(2, 2); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 554 | settings.orientation = orientationFlag; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 555 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 556 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 557 | |
| 558 | renderengine::LayerSettings layerOne; |
| 559 | Rect rectOne(0, 0, 1, 1); |
| 560 | layerOne.geometry.boundaries = rectOne.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 561 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 562 | layerOne.alpha = 1.0f; |
| 563 | |
| 564 | renderengine::LayerSettings layerTwo; |
| 565 | Rect rectTwo(0, 1, 1, 2); |
| 566 | layerTwo.geometry.boundaries = rectTwo.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 567 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 568 | layerTwo.alpha = 1.0f; |
| 569 | |
| 570 | renderengine::LayerSettings layerThree; |
| 571 | Rect rectThree(1, 0, 2, 1); |
| 572 | layerThree.geometry.boundaries = rectThree.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 573 | SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 574 | layerThree.alpha = 1.0f; |
| 575 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 576 | layers.push_back(&layerOne); |
| 577 | layers.push_back(&layerTwo); |
| 578 | layers.push_back(&layerThree); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 579 | |
| 580 | invokeDraw(settings, layers, mBuffer); |
| 581 | } |
| 582 | |
| 583 | template <typename SourceVariant> |
| 584 | void RenderEngineTest::fillBufferCheckersRotate0() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 585 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_0); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 586 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, |
| 587 | 255); |
| 588 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 589 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 590 | 0, 0, 255, 255); |
| 591 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 592 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 593 | 0, 0, 0, 0); |
| 594 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 595 | DEFAULT_DISPLAY_HEIGHT), |
| 596 | 0, 255, 0, 255); |
| 597 | } |
| 598 | |
| 599 | template <typename SourceVariant> |
| 600 | void RenderEngineTest::fillBufferCheckersRotate90() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 601 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_90); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 602 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 255, 0, |
| 603 | 255); |
| 604 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 605 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 606 | 255, 0, 0, 255); |
| 607 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 608 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 609 | 0, 0, 255, 255); |
| 610 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 611 | DEFAULT_DISPLAY_HEIGHT), |
| 612 | 0, 0, 0, 0); |
| 613 | } |
| 614 | |
| 615 | template <typename SourceVariant> |
| 616 | void RenderEngineTest::fillBufferCheckersRotate180() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 617 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_180); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 618 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, |
| 619 | 0); |
| 620 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 621 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 622 | 0, 255, 0, 255); |
| 623 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 624 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 625 | 255, 0, 0, 255); |
| 626 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 627 | DEFAULT_DISPLAY_HEIGHT), |
| 628 | 0, 0, 255, 255); |
| 629 | } |
| 630 | |
| 631 | template <typename SourceVariant> |
| 632 | void RenderEngineTest::fillBufferCheckersRotate270() { |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 633 | fillBufferCheckers<SourceVariant>(ui::Transform::ROT_270); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 634 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255, |
| 635 | 255); |
| 636 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 637 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 638 | 0, 0, 0, 0); |
| 639 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 640 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 641 | 0, 255, 0, 255); |
| 642 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 643 | DEFAULT_DISPLAY_HEIGHT), |
| 644 | 255, 0, 0, 255); |
| 645 | } |
| 646 | |
| 647 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 648 | void RenderEngineTest::fillBufferWithLayerTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 649 | renderengine::DisplaySettings settings; |
| 650 | settings.physicalDisplay = fullscreenRect(); |
| 651 | // Here logical space is 2x2 |
| 652 | settings.clip = Rect(2, 2); |
| 653 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 654 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 655 | |
| 656 | renderengine::LayerSettings layer; |
| 657 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 658 | // Translate one pixel diagonally |
| 659 | 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] | 660 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 661 | layer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 662 | layer.alpha = 1.0f; |
| 663 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 664 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 665 | |
| 666 | invokeDraw(settings, layers, mBuffer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 667 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 668 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 669 | template <typename SourceVariant> |
| 670 | void RenderEngineTest::fillBufferLayerTransform() { |
| 671 | fillBufferWithLayerTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 672 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, 0); |
| 673 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 674 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 675 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 676 | 255, 0, 0, 255); |
| 677 | } |
| 678 | |
| 679 | template <typename SourceVariant> |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 680 | void RenderEngineTest::fillBufferWithColorTransform(bool useColorManagement) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 681 | renderengine::DisplaySettings settings; |
| 682 | settings.physicalDisplay = fullscreenRect(); |
| 683 | settings.clip = Rect(1, 1); |
| 684 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 685 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 686 | |
| 687 | renderengine::LayerSettings layer; |
| 688 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 689 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this, useColorManagement); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 690 | layer.alpha = 1.0f; |
| 691 | |
| 692 | // construct a fake color matrix |
| 693 | // annihilate green and blue channels |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 694 | settings.colorTransform = mat4::scale(vec4(0.9f, 0, 0, 1)); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 695 | // set red channel to red + green |
| 696 | layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 697 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 698 | layer.alpha = 1.0f; |
| 699 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 700 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 701 | layers.push_back(&layer); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 702 | |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 703 | invokeDraw(settings, layers, mBuffer, useColorManagement); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 704 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 705 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 706 | template <typename SourceVariant> |
| 707 | void RenderEngineTest::fillBufferColorTransform() { |
| 708 | fillBufferWithColorTransform<SourceVariant>(); |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 709 | expectBufferColor(fullscreenRect(), 172, 0, 0, 255, 1); |
| 710 | } |
| 711 | |
| 712 | template <typename SourceVariant> |
| 713 | void RenderEngineTest::fillBufferColorTransformCM() { |
| 714 | fillBufferWithColorTransform<SourceVariant>(true); |
| 715 | expectBufferColor(fullscreenRect(), 126, 0, 0, 255, 1); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 718 | template <typename SourceVariant> |
KaiChieh Chuang | de09f10 | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 719 | void RenderEngineTest::fillBufferWithColorTransformZeroLayerAlpha() { |
| 720 | renderengine::DisplaySettings settings; |
| 721 | settings.physicalDisplay = fullscreenRect(); |
| 722 | settings.clip = Rect(1, 1); |
| 723 | |
| 724 | std::vector<const renderengine::LayerSettings*> layers; |
| 725 | |
| 726 | renderengine::LayerSettings layer; |
| 727 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 728 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); |
| 729 | layer.alpha = 0; |
| 730 | |
| 731 | // construct a fake color matrix |
| 732 | // simple inverse color |
| 733 | settings.colorTransform = mat4(-1, 0, 0, 0, |
| 734 | 0, -1, 0, 0, |
| 735 | 0, 0, -1, 0, |
| 736 | 1, 1, 1, 1); |
| 737 | |
| 738 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 739 | |
| 740 | layers.push_back(&layer); |
| 741 | |
| 742 | invokeDraw(settings, layers, mBuffer); |
| 743 | } |
| 744 | |
| 745 | template <typename SourceVariant> |
| 746 | void RenderEngineTest::fillBufferColorTransformZeroLayerAlpha() { |
| 747 | fillBufferWithColorTransformZeroLayerAlpha<SourceVariant>(); |
| 748 | expectBufferColor(fullscreenRect(), 0, 0, 0, 0); |
| 749 | } |
| 750 | |
| 751 | template <typename SourceVariant> |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 752 | void RenderEngineTest::fillRedBufferWithRoundedCorners() { |
| 753 | renderengine::DisplaySettings settings; |
| 754 | settings.physicalDisplay = fullscreenRect(); |
| 755 | settings.clip = fullscreenRect(); |
| 756 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 757 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 758 | |
| 759 | renderengine::LayerSettings layer; |
| 760 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 761 | layer.geometry.roundedCornersRadius = 5.0f; |
| 762 | layer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 763 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 764 | layer.alpha = 1.0f; |
| 765 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 766 | layers.push_back(&layer); |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 767 | |
| 768 | invokeDraw(settings, layers, mBuffer); |
| 769 | } |
| 770 | |
| 771 | template <typename SourceVariant> |
| 772 | void RenderEngineTest::fillBufferWithRoundedCorners() { |
| 773 | fillRedBufferWithRoundedCorners<SourceVariant>(); |
| 774 | // Corners should be ignored... |
| 775 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); |
| 776 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); |
| 777 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 778 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, |
| 779 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 780 | 0, 0, 0, 0); |
| 781 | // ...And the non-rounded portion should be red. |
| 782 | // Other pixels may be anti-aliased, so let's not check those. |
| 783 | expectBufferColor(Rect(5, 5, DEFAULT_DISPLAY_WIDTH - 5, DEFAULT_DISPLAY_HEIGHT - 5), 255, 0, 0, |
| 784 | 255); |
| 785 | } |
| 786 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 787 | template <typename SourceVariant> |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 788 | void RenderEngineTest::fillBufferAndBlurBackground() { |
| 789 | char value[PROPERTY_VALUE_MAX]; |
| 790 | property_get("ro.surface_flinger.supports_background_blur", value, "0"); |
| 791 | if (!atoi(value)) { |
| 792 | // This device doesn't support blurs, no-op. |
| 793 | return; |
| 794 | } |
| 795 | |
| 796 | auto blurRadius = 50; |
| 797 | auto center = DEFAULT_DISPLAY_WIDTH / 2; |
| 798 | |
| 799 | renderengine::DisplaySettings settings; |
| 800 | settings.physicalDisplay = fullscreenRect(); |
| 801 | settings.clip = fullscreenRect(); |
| 802 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 803 | std::vector<const renderengine::LayerSettings*> layers; |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 804 | |
| 805 | renderengine::LayerSettings backgroundLayer; |
| 806 | backgroundLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 807 | SourceVariant::fillColor(backgroundLayer, 0.0f, 1.0f, 0.0f, this); |
| 808 | backgroundLayer.alpha = 1.0f; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 809 | layers.push_back(&backgroundLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 810 | |
| 811 | renderengine::LayerSettings leftLayer; |
| 812 | leftLayer.geometry.boundaries = |
| 813 | Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT).toFloatRect(); |
| 814 | SourceVariant::fillColor(leftLayer, 1.0f, 0.0f, 0.0f, this); |
| 815 | leftLayer.alpha = 1.0f; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 816 | layers.push_back(&leftLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 817 | |
| 818 | renderengine::LayerSettings blurLayer; |
| 819 | blurLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 820 | blurLayer.backgroundBlurRadius = blurRadius; |
| 821 | blurLayer.alpha = 0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 822 | layers.push_back(&blurLayer); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 823 | |
| 824 | invokeDraw(settings, layers, mBuffer); |
| 825 | |
| 826 | expectBufferColor(Rect(center - 1, center - 5, center, center + 5), 150, 150, 0, 255, |
| 827 | 50 /* tolerance */); |
| 828 | expectBufferColor(Rect(center, center - 5, center + 1, center + 5), 150, 150, 0, 255, |
| 829 | 50 /* tolerance */); |
| 830 | } |
| 831 | |
| 832 | template <typename SourceVariant> |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 833 | void RenderEngineTest::overlayCorners() { |
| 834 | renderengine::DisplaySettings settings; |
| 835 | settings.physicalDisplay = fullscreenRect(); |
| 836 | settings.clip = fullscreenRect(); |
| 837 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 838 | std::vector<const renderengine::LayerSettings*> layersFirst; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 839 | |
| 840 | renderengine::LayerSettings layerOne; |
| 841 | layerOne.geometry.boundaries = |
| 842 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0); |
| 843 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
| 844 | layerOne.alpha = 0.2; |
| 845 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 846 | layersFirst.push_back(&layerOne); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 847 | invokeDraw(settings, layersFirst, mBuffer); |
| 848 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51); |
| 849 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 850 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 851 | 0, 0, 0, 0); |
| 852 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 853 | std::vector<const renderengine::LayerSettings*> layersSecond; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 854 | renderengine::LayerSettings layerTwo; |
| 855 | layerTwo.geometry.boundaries = |
| 856 | FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0, |
| 857 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); |
| 858 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
| 859 | layerTwo.alpha = 1.0f; |
| 860 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 861 | layersSecond.push_back(&layerTwo); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 862 | invokeDraw(settings, layersSecond, mBuffer); |
| 863 | |
| 864 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0); |
| 865 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 866 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 867 | 0, 255, 0, 255); |
| 868 | } |
| 869 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 870 | void RenderEngineTest::fillRedBufferTextureTransform() { |
| 871 | renderengine::DisplaySettings settings; |
| 872 | settings.physicalDisplay = fullscreenRect(); |
| 873 | settings.clip = Rect(1, 1); |
| 874 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 875 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 876 | |
| 877 | renderengine::LayerSettings layer; |
| 878 | // Here will allocate a checker board texture, but transform texture |
| 879 | // coordinates so that only the upper left is applied. |
| 880 | sp<GraphicBuffer> buf = allocateSourceBuffer(2, 2); |
| 881 | uint32_t texName; |
| 882 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 883 | this->mTexNames.push_back(texName); |
| 884 | |
| 885 | uint8_t* pixels; |
| 886 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 887 | reinterpret_cast<void**>(&pixels)); |
| 888 | // Red top left, Green top right, Blue bottom left, Black bottom right |
| 889 | pixels[0] = 255; |
| 890 | pixels[1] = 0; |
| 891 | pixels[2] = 0; |
| 892 | pixels[3] = 255; |
| 893 | pixels[4] = 0; |
| 894 | pixels[5] = 255; |
| 895 | pixels[6] = 0; |
| 896 | pixels[7] = 255; |
| 897 | pixels[8] = 0; |
| 898 | pixels[9] = 0; |
| 899 | pixels[10] = 255; |
| 900 | pixels[11] = 255; |
| 901 | buf->unlock(); |
| 902 | |
| 903 | layer.source.buffer.buffer = buf; |
| 904 | layer.source.buffer.textureName = texName; |
| 905 | // Transform coordinates to only be inside the red quadrant. |
| 906 | layer.source.buffer.textureTransform = mat4::scale(vec4(0.2, 0.2, 1, 1)); |
| 907 | layer.alpha = 1.0f; |
| 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::fillBufferTextureTransform() { |
| 916 | fillRedBufferTextureTransform(); |
| 917 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 918 | } |
| 919 | |
| 920 | void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() { |
| 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 = true; |
| 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::fillBufferWithPremultiplyAlpha() { |
| 955 | fillRedBufferWithPremultiplyAlpha(); |
| 956 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128); |
| 957 | } |
| 958 | |
| 959 | void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() { |
| 960 | renderengine::DisplaySettings settings; |
| 961 | settings.physicalDisplay = fullscreenRect(); |
| 962 | // Here logical space is 1x1 |
| 963 | settings.clip = Rect(1, 1); |
| 964 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 965 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 966 | |
| 967 | renderengine::LayerSettings layer; |
| 968 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 969 | uint32_t texName; |
| 970 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 971 | this->mTexNames.push_back(texName); |
| 972 | |
| 973 | uint8_t* pixels; |
| 974 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 975 | reinterpret_cast<void**>(&pixels)); |
| 976 | pixels[0] = 255; |
| 977 | pixels[1] = 0; |
| 978 | pixels[2] = 0; |
| 979 | pixels[3] = 255; |
| 980 | buf->unlock(); |
| 981 | |
| 982 | layer.source.buffer.buffer = buf; |
| 983 | layer.source.buffer.textureName = texName; |
| 984 | layer.source.buffer.usePremultipliedAlpha = false; |
| 985 | layer.alpha = 0.5f; |
| 986 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 987 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 988 | layers.push_back(&layer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 989 | |
| 990 | invokeDraw(settings, layers, mBuffer); |
| 991 | } |
| 992 | |
| 993 | void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() { |
| 994 | fillRedBufferWithoutPremultiplyAlpha(); |
wukui1 | 6f3c0bb | 2020-08-05 20:35:29 +0800 | [diff] [blame] | 995 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128, 1); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 996 | } |
| 997 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 998 | void RenderEngineTest::clearLeftRegion() { |
| 999 | renderengine::DisplaySettings settings; |
| 1000 | settings.physicalDisplay = fullscreenRect(); |
| 1001 | // Here logical space is 4x4 |
| 1002 | settings.clip = Rect(4, 4); |
Alec Mouri | 5a6d857 | 2020-03-23 23:56:15 -0700 | [diff] [blame] | 1003 | settings.clearRegion = Region(Rect(2, 4)); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1004 | std::vector<const renderengine::LayerSettings*> layers; |
Xin Li | e8b4e70 | 2020-08-29 01:34:09 -0700 | [diff] [blame] | 1005 | // fake layer, without bounds should not render anything |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1006 | renderengine::LayerSettings layer; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1007 | layers.push_back(&layer); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1008 | invokeDraw(settings, layers, mBuffer); |
| 1009 | } |
| 1010 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1011 | void RenderEngineTest::clearRegion() { |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1012 | // Reuse mBuffer |
| 1013 | clearLeftRegion(); |
| 1014 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 255); |
| 1015 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 1016 | DEFAULT_DISPLAY_HEIGHT), |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1017 | 0, 0, 0, 0); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1020 | template <typename SourceVariant> |
| 1021 | void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer, |
| 1022 | const renderengine::ShadowSettings& shadow, |
| 1023 | const ubyte4& casterColor, const ubyte4& backgroundColor) { |
| 1024 | renderengine::DisplaySettings settings; |
| 1025 | settings.physicalDisplay = fullscreenRect(); |
| 1026 | settings.clip = fullscreenRect(); |
| 1027 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1028 | std::vector<const renderengine::LayerSettings*> layers; |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1029 | |
| 1030 | // add background layer |
| 1031 | renderengine::LayerSettings bgLayer; |
| 1032 | bgLayer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1033 | ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f, |
| 1034 | backgroundColor.b / 255.0f, this); |
| 1035 | bgLayer.alpha = backgroundColor.a / 255.0f; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1036 | layers.push_back(&bgLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1037 | |
| 1038 | // add shadow layer |
| 1039 | renderengine::LayerSettings shadowLayer; |
| 1040 | shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries; |
| 1041 | shadowLayer.alpha = castingLayer.alpha; |
| 1042 | shadowLayer.shadow = shadow; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1043 | layers.push_back(&shadowLayer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1044 | |
| 1045 | // add layer casting the shadow |
| 1046 | renderengine::LayerSettings layer = castingLayer; |
| 1047 | SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f, |
| 1048 | casterColor.b / 255.0f, this); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1049 | layers.push_back(&layer); |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1050 | |
| 1051 | invokeDraw(settings, layers, mBuffer); |
| 1052 | } |
| 1053 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1054 | TEST_F(RenderEngineTest, drawLayers_noLayersToDraw) { |
| 1055 | drawEmptyLayers(); |
| 1056 | } |
| 1057 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1058 | TEST_F(RenderEngineTest, drawLayers_nullOutputBuffer) { |
| 1059 | renderengine::DisplaySettings settings; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1060 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1061 | renderengine::LayerSettings layer; |
| 1062 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1063 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1064 | layers.push_back(&layer); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1065 | base::unique_fd fence; |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1066 | 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] | 1067 | |
| 1068 | ASSERT_EQ(BAD_VALUE, status); |
| 1069 | } |
| 1070 | |
| 1071 | TEST_F(RenderEngineTest, drawLayers_nullOutputFence) { |
| 1072 | renderengine::DisplaySettings settings; |
| 1073 | settings.physicalDisplay = fullscreenRect(); |
| 1074 | settings.clip = fullscreenRect(); |
| 1075 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1076 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1077 | renderengine::LayerSettings layer; |
| 1078 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1079 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1080 | layer.alpha = 1.0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1081 | layers.push_back(&layer); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1082 | |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1083 | status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1084 | base::unique_fd(), nullptr); |
| 1085 | sCurrentBuffer = mBuffer; |
| 1086 | ASSERT_EQ(NO_ERROR, status); |
| 1087 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 1088 | } |
| 1089 | |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1090 | TEST_F(RenderEngineTest, drawLayers_doesNotCacheFramebuffer) { |
| 1091 | renderengine::DisplaySettings settings; |
| 1092 | settings.physicalDisplay = fullscreenRect(); |
| 1093 | settings.clip = fullscreenRect(); |
| 1094 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1095 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1096 | renderengine::LayerSettings layer; |
| 1097 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1098 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1099 | layer.alpha = 1.0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1100 | layers.push_back(&layer); |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 1101 | |
| 1102 | status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), false, |
| 1103 | base::unique_fd(), nullptr); |
| 1104 | sCurrentBuffer = mBuffer; |
| 1105 | ASSERT_EQ(NO_ERROR, status); |
| 1106 | ASSERT_FALSE(sRE->isFramebufferImageCachedForTesting(mBuffer->getId())); |
| 1107 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 1108 | } |
| 1109 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 1110 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) { |
| 1111 | fillRedBuffer<ColorSourceVariant>(); |
| 1112 | } |
| 1113 | |
| 1114 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) { |
| 1115 | fillGreenBuffer<ColorSourceVariant>(); |
| 1116 | } |
| 1117 | |
| 1118 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) { |
| 1119 | fillBlueBuffer<ColorSourceVariant>(); |
| 1120 | } |
| 1121 | |
| 1122 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) { |
| 1123 | fillRedTransparentBuffer<ColorSourceVariant>(); |
| 1124 | } |
| 1125 | |
| 1126 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) { |
| 1127 | fillBufferPhysicalOffset<ColorSourceVariant>(); |
| 1128 | } |
| 1129 | |
| 1130 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) { |
| 1131 | fillBufferCheckersRotate0<ColorSourceVariant>(); |
| 1132 | } |
| 1133 | |
| 1134 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) { |
| 1135 | fillBufferCheckersRotate90<ColorSourceVariant>(); |
| 1136 | } |
| 1137 | |
| 1138 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) { |
| 1139 | fillBufferCheckersRotate180<ColorSourceVariant>(); |
| 1140 | } |
| 1141 | |
| 1142 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) { |
| 1143 | fillBufferCheckersRotate270<ColorSourceVariant>(); |
| 1144 | } |
| 1145 | |
| 1146 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) { |
| 1147 | fillBufferLayerTransform<ColorSourceVariant>(); |
| 1148 | } |
| 1149 | |
| 1150 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) { |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1151 | fillBufferColorTransform<ColorSourceVariant>(); |
| 1152 | } |
| 1153 | |
| 1154 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransformCM_colorSource) { |
| 1155 | fillBufferColorTransformCM<ColorSourceVariant>(); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
KaiChieh Chuang | de09f10 | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1158 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_colorSource) { |
| 1159 | fillBufferColorTransformZeroLayerAlpha<ColorSourceVariant>(); |
| 1160 | } |
| 1161 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1162 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) { |
| 1163 | fillBufferWithRoundedCorners<ColorSourceVariant>(); |
| 1164 | } |
| 1165 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1166 | TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_colorSource) { |
| 1167 | fillBufferAndBlurBackground<ColorSourceVariant>(); |
| 1168 | } |
| 1169 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1170 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_colorSource) { |
| 1171 | overlayCorners<ColorSourceVariant>(); |
| 1172 | } |
| 1173 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1174 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) { |
| 1175 | fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1176 | } |
| 1177 | |
| 1178 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) { |
| 1179 | fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1180 | } |
| 1181 | |
| 1182 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) { |
| 1183 | fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1184 | } |
| 1185 | |
| 1186 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) { |
| 1187 | fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1188 | } |
| 1189 | |
| 1190 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) { |
| 1191 | fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1192 | } |
| 1193 | |
| 1194 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) { |
| 1195 | fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1196 | } |
| 1197 | |
| 1198 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) { |
| 1199 | fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1200 | } |
| 1201 | |
| 1202 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) { |
| 1203 | fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1204 | } |
| 1205 | |
| 1206 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) { |
| 1207 | fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1208 | } |
| 1209 | |
| 1210 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) { |
| 1211 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1212 | } |
| 1213 | |
| 1214 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) { |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1215 | fillBufferColorTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1216 | } |
| 1217 | |
| 1218 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransformCM_opaqueBufferSource) { |
| 1219 | fillBufferColorTransformCM<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1220 | } |
| 1221 | |
KaiChieh Chuang | de09f10 | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1222 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_opaqueBufferSource) { |
| 1223 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1224 | } |
| 1225 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1226 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) { |
| 1227 | fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1228 | } |
| 1229 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1230 | TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_opaqueBufferSource) { |
| 1231 | fillBufferAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1232 | } |
| 1233 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1234 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) { |
| 1235 | overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 1236 | } |
| 1237 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1238 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) { |
| 1239 | fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1240 | } |
| 1241 | |
| 1242 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) { |
| 1243 | fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1244 | } |
| 1245 | |
| 1246 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) { |
| 1247 | fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1248 | } |
| 1249 | |
| 1250 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) { |
| 1251 | fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1252 | } |
| 1253 | |
| 1254 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) { |
| 1255 | fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1256 | } |
| 1257 | |
| 1258 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) { |
| 1259 | fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1260 | } |
| 1261 | |
| 1262 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) { |
| 1263 | fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1264 | } |
| 1265 | |
| 1266 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) { |
| 1267 | fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1268 | } |
| 1269 | |
| 1270 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) { |
| 1271 | fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1272 | } |
| 1273 | |
| 1274 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) { |
| 1275 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1276 | } |
| 1277 | |
| 1278 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) { |
KaiChieh Chuang | ba2f0bc | 2020-09-07 13:48:42 +0800 | [diff] [blame] | 1279 | fillBufferColorTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1280 | } |
| 1281 | |
| 1282 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransformCM_bufferSource) { |
| 1283 | fillBufferColorTransformCM<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1284 | } |
| 1285 | |
KaiChieh Chuang | de09f10 | 2020-12-14 16:49:38 +0800 | [diff] [blame] | 1286 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransformZeroLayerAlpha_bufferSource) { |
| 1287 | fillBufferColorTransformZeroLayerAlpha<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1288 | } |
| 1289 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 1290 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) { |
| 1291 | fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1292 | } |
| 1293 | |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 1294 | TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_bufferSource) { |
| 1295 | fillBufferAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1296 | } |
| 1297 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1298 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_bufferSource) { |
| 1299 | overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 1300 | } |
| 1301 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 1302 | TEST_F(RenderEngineTest, drawLayers_fillBufferTextureTransform) { |
| 1303 | fillBufferTextureTransform(); |
| 1304 | } |
| 1305 | |
| 1306 | TEST_F(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) { |
| 1307 | fillBufferWithPremultiplyAlpha(); |
| 1308 | } |
| 1309 | |
| 1310 | TEST_F(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) { |
| 1311 | fillBufferWithoutPremultiplyAlpha(); |
| 1312 | } |
| 1313 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 1314 | TEST_F(RenderEngineTest, drawLayers_clearRegion) { |
| 1315 | clearRegion(); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1318 | TEST_F(RenderEngineTest, drawLayers_fillsBufferAndCachesImages) { |
| 1319 | renderengine::DisplaySettings settings; |
| 1320 | settings.physicalDisplay = fullscreenRect(); |
| 1321 | settings.clip = fullscreenRect(); |
| 1322 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1323 | std::vector<const renderengine::LayerSettings*> layers; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1324 | |
| 1325 | renderengine::LayerSettings layer; |
| 1326 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1327 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1328 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 1329 | layers.push_back(&layer); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1330 | invokeDraw(settings, layers, mBuffer); |
| 1331 | uint64_t bufferId = layer.source.buffer.buffer->getId(); |
| 1332 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1333 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1334 | sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1335 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1336 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1337 | [&]() REQUIRES(barrier->mutex) { |
| 1338 | return barrier->isOpen; |
| 1339 | })); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1340 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1341 | EXPECT_EQ(NO_ERROR, barrier->result); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1344 | TEST_F(RenderEngineTest, bindExternalBuffer_withNullBuffer) { |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1345 | status_t result = sRE->bindExternalTextureBuffer(0, nullptr, nullptr); |
| 1346 | ASSERT_EQ(BAD_VALUE, result); |
| 1347 | } |
| 1348 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1349 | TEST_F(RenderEngineTest, bindExternalBuffer_cachesImages) { |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1350 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 1351 | uint32_t texName; |
| 1352 | sRE->genTextures(1, &texName); |
| 1353 | mTexNames.push_back(texName); |
| 1354 | |
| 1355 | sRE->bindExternalTextureBuffer(texName, buf, nullptr); |
| 1356 | uint64_t bufferId = buf->getId(); |
| 1357 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1358 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1359 | sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1360 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1361 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1362 | [&]() REQUIRES(barrier->mutex) { |
| 1363 | return barrier->isOpen; |
| 1364 | })); |
| 1365 | EXPECT_EQ(NO_ERROR, barrier->result); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1366 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
| 1367 | } |
| 1368 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1369 | TEST_F(RenderEngineTest, cacheExternalBuffer_withNullBuffer) { |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1370 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1371 | sRE->cacheExternalTextureBufferForTesting(nullptr); |
| 1372 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1373 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1374 | [&]() REQUIRES(barrier->mutex) { |
| 1375 | return barrier->isOpen; |
| 1376 | })); |
| 1377 | EXPECT_TRUE(barrier->isOpen); |
| 1378 | EXPECT_EQ(BAD_VALUE, barrier->result); |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1381 | TEST_F(RenderEngineTest, cacheExternalBuffer_cachesImages) { |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1382 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 1383 | uint64_t bufferId = buf->getId(); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1384 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1385 | sRE->cacheExternalTextureBufferForTesting(buf); |
| 1386 | { |
| 1387 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1388 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1389 | [&]() REQUIRES(barrier->mutex) { |
| 1390 | return barrier->isOpen; |
| 1391 | })); |
| 1392 | EXPECT_EQ(NO_ERROR, barrier->result); |
| 1393 | } |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1394 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1395 | barrier = sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1396 | { |
| 1397 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1398 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1399 | [&]() REQUIRES(barrier->mutex) { |
| 1400 | return barrier->isOpen; |
| 1401 | })); |
| 1402 | EXPECT_EQ(NO_ERROR, barrier->result); |
| 1403 | } |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1404 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
| 1405 | } |
| 1406 | |
Vishnu Nair | 16efdbf | 2019-12-10 11:55:42 -0800 | [diff] [blame] | 1407 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterLayerMinSize) { |
| 1408 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1409 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1410 | const float shadowLength = 5.0f; |
| 1411 | Rect casterBounds(1, 1); |
| 1412 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1413 | renderengine::LayerSettings castingLayer; |
| 1414 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1415 | castingLayer.alpha = 1.0f; |
| 1416 | renderengine::ShadowSettings settings = |
| 1417 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1418 | false /* casterIsTranslucent */); |
| 1419 | |
| 1420 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 1421 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1422 | } |
| 1423 | |
| 1424 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterColorLayer) { |
| 1425 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1426 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1427 | const float shadowLength = 5.0f; |
| 1428 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1429 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1430 | renderengine::LayerSettings castingLayer; |
| 1431 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1432 | castingLayer.alpha = 1.0f; |
| 1433 | renderengine::ShadowSettings settings = |
| 1434 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1435 | false /* casterIsTranslucent */); |
| 1436 | |
| 1437 | drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor); |
| 1438 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1439 | } |
| 1440 | |
| 1441 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterOpaqueBufferLayer) { |
| 1442 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1443 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1444 | const float shadowLength = 5.0f; |
| 1445 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1446 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1447 | renderengine::LayerSettings castingLayer; |
| 1448 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1449 | castingLayer.alpha = 1.0f; |
| 1450 | renderengine::ShadowSettings settings = |
| 1451 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1452 | false /* casterIsTranslucent */); |
| 1453 | |
| 1454 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 1455 | backgroundColor); |
| 1456 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1457 | } |
| 1458 | |
| 1459 | TEST_F(RenderEngineTest, drawLayers_fillShadow_casterWithRoundedCorner) { |
| 1460 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1461 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1462 | const float shadowLength = 5.0f; |
| 1463 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1464 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1465 | renderengine::LayerSettings castingLayer; |
| 1466 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1467 | castingLayer.geometry.roundedCornersRadius = 3.0f; |
| 1468 | castingLayer.geometry.roundedCornersCrop = casterBounds.toFloatRect(); |
| 1469 | castingLayer.alpha = 1.0f; |
| 1470 | renderengine::ShadowSettings settings = |
| 1471 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1472 | false /* casterIsTranslucent */); |
| 1473 | |
| 1474 | drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 1475 | backgroundColor); |
| 1476 | expectShadowColor(castingLayer, settings, casterColor, backgroundColor); |
| 1477 | } |
| 1478 | |
| 1479 | TEST_F(RenderEngineTest, drawLayers_fillShadow_translucentCasterWithAlpha) { |
| 1480 | const ubyte4 casterColor(255, 0, 0, 255); |
| 1481 | const ubyte4 backgroundColor(255, 255, 255, 255); |
| 1482 | const float shadowLength = 5.0f; |
| 1483 | Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f); |
| 1484 | casterBounds.offsetBy(shadowLength + 1, shadowLength + 1); |
| 1485 | renderengine::LayerSettings castingLayer; |
| 1486 | castingLayer.geometry.boundaries = casterBounds.toFloatRect(); |
| 1487 | castingLayer.alpha = 0.5f; |
| 1488 | renderengine::ShadowSettings settings = |
| 1489 | getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength, |
| 1490 | true /* casterIsTranslucent */); |
| 1491 | |
| 1492 | drawShadow<BufferSourceVariant<RelaxOpaqueBufferVariant>>(castingLayer, settings, casterColor, |
| 1493 | backgroundColor); |
| 1494 | |
| 1495 | // verify only the background since the shadow will draw behind the caster |
| 1496 | const float shadowInset = settings.length * -1.0f; |
| 1497 | const Rect casterWithShadow = |
| 1498 | Rect(casterBounds).inset(shadowInset, shadowInset, shadowInset, shadowInset); |
| 1499 | const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow); |
| 1500 | expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b, |
| 1501 | backgroundColor.a); |
| 1502 | } |
| 1503 | |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1504 | TEST_F(RenderEngineTest, cleanupPostRender_cleansUpOnce) { |
| 1505 | renderengine::DisplaySettings settings; |
| 1506 | settings.physicalDisplay = fullscreenRect(); |
| 1507 | settings.clip = fullscreenRect(); |
| 1508 | |
| 1509 | std::vector<const renderengine::LayerSettings*> layers; |
| 1510 | renderengine::LayerSettings layer; |
| 1511 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1512 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1513 | layer.alpha = 1.0; |
| 1514 | layers.push_back(&layer); |
| 1515 | |
| 1516 | base::unique_fd fenceOne; |
| 1517 | sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, base::unique_fd(), |
| 1518 | &fenceOne); |
| 1519 | base::unique_fd fenceTwo; |
| 1520 | sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, std::move(fenceOne), |
| 1521 | &fenceTwo); |
| 1522 | |
| 1523 | const int fd = fenceTwo.get(); |
| 1524 | if (fd >= 0) { |
| 1525 | sync_wait(fd, -1); |
| 1526 | } |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1527 | // Only cleanup the first time. |
Alec Mouri | 56f295e | 2020-08-13 10:14:29 -0700 | [diff] [blame] | 1528 | EXPECT_TRUE(sRE->cleanupPostRender( |
| 1529 | renderengine::RenderEngine::CleanupMode::CLEAN_OUTPUT_RESOURCES)); |
| 1530 | EXPECT_FALSE(sRE->cleanupPostRender( |
| 1531 | renderengine::RenderEngine::CleanupMode::CLEAN_OUTPUT_RESOURCES)); |
| 1532 | } |
| 1533 | |
| 1534 | TEST_F(RenderEngineTest, cleanupPostRender_whenCleaningAll_replacesTextureMemory) { |
| 1535 | renderengine::DisplaySettings settings; |
| 1536 | settings.physicalDisplay = fullscreenRect(); |
| 1537 | settings.clip = fullscreenRect(); |
| 1538 | |
| 1539 | std::vector<const renderengine::LayerSettings*> layers; |
| 1540 | renderengine::LayerSettings layer; |
| 1541 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1542 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1543 | layer.alpha = 1.0; |
| 1544 | layers.push_back(&layer); |
| 1545 | |
| 1546 | base::unique_fd fence; |
| 1547 | sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, base::unique_fd(), &fence); |
| 1548 | |
| 1549 | const int fd = fence.get(); |
| 1550 | if (fd >= 0) { |
| 1551 | sync_wait(fd, -1); |
| 1552 | } |
| 1553 | |
| 1554 | uint64_t bufferId = layer.source.buffer.buffer->getId(); |
| 1555 | uint32_t texName = layer.source.buffer.textureName; |
| 1556 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
| 1557 | EXPECT_EQ(bufferId, sRE->getBufferIdForTextureNameForTesting(texName)); |
| 1558 | |
| 1559 | EXPECT_TRUE(sRE->cleanupPostRender(renderengine::RenderEngine::CleanupMode::CLEAN_ALL)); |
| 1560 | |
| 1561 | // Now check that our view of memory is good. |
| 1562 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
| 1563 | EXPECT_EQ(std::nullopt, sRE->getBufferIdForTextureNameForTesting(bufferId)); |
| 1564 | EXPECT_TRUE(sRE->isTextureNameKnownForTesting(texName)); |
Alec Mouri | 4dde178 | 2019-09-30 17:27:13 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1567 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1568 | |
| 1569 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1570 | #pragma clang diagnostic pop // ignored "-Wconversion" |