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