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