Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 17 | #include <chrono> |
| 18 | #include <condition_variable> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 19 | |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 20 | #include <gtest/gtest.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 21 | #include <renderengine/RenderEngine.h> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 22 | #include <sync/sync.h> |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 23 | #include <ui/PixelFormat.h> |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 24 | #include "../gl/GLESRenderEngine.h" |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 25 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 26 | constexpr int DEFAULT_DISPLAY_WIDTH = 128; |
| 27 | constexpr int DEFAULT_DISPLAY_HEIGHT = 256; |
| 28 | constexpr int DEFAULT_DISPLAY_OFFSET = 64; |
| 29 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 30 | namespace android { |
| 31 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 32 | struct RenderEngineTest : public ::testing::Test { |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 33 | static void SetUpTestSuite() { |
Peiyong Lin | 4137a1d | 2019-10-09 10:39:09 -0700 | [diff] [blame] | 34 | sRE = renderengine::gl::GLESRenderEngine::create( |
| 35 | renderengine::RenderEngineCreationArgs::Builder() |
| 36 | .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) |
| 37 | .setImageCacheSize(1) |
| 38 | .setUseColorManagerment(false) |
| 39 | .setEnableProtectedContext(false) |
| 40 | .setPrecacheToneMapperShaderOnly(false) |
| 41 | .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) |
| 42 | .build()); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static void TearDownTestSuite() { |
| 46 | // The ordering here is important - sCurrentBuffer must live longer |
| 47 | // than RenderEngine to avoid a null reference on tear-down. |
| 48 | sRE = nullptr; |
| 49 | sCurrentBuffer = nullptr; |
| 50 | } |
| 51 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 52 | static sp<GraphicBuffer> allocateDefaultBuffer() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 53 | return new GraphicBuffer(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT, |
| 54 | HAL_PIXEL_FORMAT_RGBA_8888, 1, |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 55 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 56 | GRALLOC_USAGE_HW_RENDER, |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 57 | "output"); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 60 | // Allocates a 1x1 buffer to fill with a solid color |
| 61 | static sp<GraphicBuffer> allocateSourceBuffer(uint32_t width, uint32_t height) { |
| 62 | return new GraphicBuffer(width, height, HAL_PIXEL_FORMAT_RGBA_8888, 1, |
| 63 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 64 | GRALLOC_USAGE_HW_TEXTURE, |
| 65 | "input"); |
| 66 | } |
| 67 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 68 | RenderEngineTest() { mBuffer = allocateDefaultBuffer(); } |
| 69 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 70 | ~RenderEngineTest() { |
| 71 | for (uint32_t texName : mTexNames) { |
| 72 | sRE->deleteTextures(1, &texName); |
| 73 | } |
| 74 | } |
| 75 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 76 | void expectBufferColor(const Rect& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a, |
| 77 | uint8_t tolerance = 0) { |
| 78 | uint8_t* pixels; |
| 79 | mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 80 | reinterpret_cast<void**>(&pixels)); |
| 81 | |
| 82 | auto colorCompare = [tolerance](uint8_t a, uint8_t b) { |
| 83 | uint8_t tmp = a >= b ? a - b : b - a; |
| 84 | return tmp <= tolerance; |
| 85 | }; |
| 86 | int32_t maxFails = 10; |
| 87 | int32_t fails = 0; |
| 88 | for (int32_t j = 0; j < region.getHeight(); j++) { |
| 89 | const uint8_t* src = |
| 90 | pixels + (mBuffer->getStride() * (region.top + j) + region.left) * 4; |
| 91 | for (int32_t i = 0; i < region.getWidth(); i++) { |
| 92 | const uint8_t expected[4] = {r, g, b, a}; |
| 93 | bool equal = std::equal(src, src + 4, expected, colorCompare); |
| 94 | EXPECT_TRUE(equal) |
| 95 | << "pixel @ (" << region.left + i << ", " << region.top + j << "): " |
| 96 | << "expected (" << static_cast<uint32_t>(r) << ", " |
| 97 | << static_cast<uint32_t>(g) << ", " << static_cast<uint32_t>(b) << ", " |
| 98 | << static_cast<uint32_t>(a) << "), " |
| 99 | << "got (" << static_cast<uint32_t>(src[0]) << ", " |
| 100 | << static_cast<uint32_t>(src[1]) << ", " << static_cast<uint32_t>(src[2]) |
| 101 | << ", " << static_cast<uint32_t>(src[3]) << ")"; |
| 102 | src += 4; |
| 103 | if (!equal && ++fails >= maxFails) { |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | if (fails >= maxFails) { |
| 108 | break; |
| 109 | } |
| 110 | } |
| 111 | mBuffer->unlock(); |
| 112 | } |
| 113 | |
| 114 | static Rect fullscreenRect() { return Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); } |
| 115 | |
| 116 | static Rect offsetRect() { |
| 117 | return Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, |
| 118 | DEFAULT_DISPLAY_HEIGHT); |
| 119 | } |
| 120 | |
| 121 | static Rect offsetRectAtZero() { |
| 122 | return Rect(DEFAULT_DISPLAY_WIDTH - DEFAULT_DISPLAY_OFFSET, |
| 123 | DEFAULT_DISPLAY_HEIGHT - DEFAULT_DISPLAY_OFFSET); |
| 124 | } |
| 125 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 126 | void invokeDraw(renderengine::DisplaySettings settings, |
| 127 | std::vector<renderengine::LayerSettings> layers, sp<GraphicBuffer> buffer) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 128 | base::unique_fd fence; |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 129 | status_t status = sRE->drawLayers(settings, layers, buffer->getNativeBuffer(), true, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 130 | base::unique_fd(), &fence); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 131 | sCurrentBuffer = buffer; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 132 | |
| 133 | int fd = fence.release(); |
| 134 | if (fd >= 0) { |
| 135 | sync_wait(fd, -1); |
| 136 | close(fd); |
| 137 | } |
| 138 | |
| 139 | ASSERT_EQ(NO_ERROR, status); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 140 | if (layers.size() > 0) { |
| 141 | ASSERT_TRUE(sRE->isFramebufferImageCachedForTesting(buffer->getId())); |
| 142 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 145 | void drawEmptyLayers() { |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 146 | renderengine::DisplaySettings settings; |
| 147 | std::vector<renderengine::LayerSettings> layers; |
| 148 | // Meaningless buffer since we don't do any drawing |
| 149 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 150 | invokeDraw(settings, layers, buffer); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 153 | template <typename SourceVariant> |
| 154 | void fillBuffer(half r, half g, half b, half a); |
| 155 | |
| 156 | template <typename SourceVariant> |
| 157 | void fillRedBuffer(); |
| 158 | |
| 159 | template <typename SourceVariant> |
| 160 | void fillGreenBuffer(); |
| 161 | |
| 162 | template <typename SourceVariant> |
| 163 | void fillBlueBuffer(); |
| 164 | |
| 165 | template <typename SourceVariant> |
| 166 | void fillRedTransparentBuffer(); |
| 167 | |
| 168 | template <typename SourceVariant> |
| 169 | void fillRedOffsetBuffer(); |
| 170 | |
| 171 | template <typename SourceVariant> |
| 172 | void fillBufferPhysicalOffset(); |
| 173 | |
| 174 | template <typename SourceVariant> |
| 175 | void fillBufferCheckers(mat4 transform); |
| 176 | |
| 177 | template <typename SourceVariant> |
| 178 | void fillBufferCheckersRotate0(); |
| 179 | |
| 180 | template <typename SourceVariant> |
| 181 | void fillBufferCheckersRotate90(); |
| 182 | |
| 183 | template <typename SourceVariant> |
| 184 | void fillBufferCheckersRotate180(); |
| 185 | |
| 186 | template <typename SourceVariant> |
| 187 | void fillBufferCheckersRotate270(); |
| 188 | |
| 189 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 190 | void fillBufferWithLayerTransform(); |
| 191 | |
| 192 | template <typename SourceVariant> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 193 | void fillBufferLayerTransform(); |
| 194 | |
| 195 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 196 | void fillBufferWithColorTransform(); |
| 197 | |
| 198 | template <typename SourceVariant> |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 199 | void fillBufferColorTransform(); |
| 200 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 201 | template <typename SourceVariant> |
| 202 | void fillRedBufferWithRoundedCorners(); |
| 203 | |
| 204 | template <typename SourceVariant> |
| 205 | void fillBufferWithRoundedCorners(); |
| 206 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 207 | template <typename SourceVariant> |
| 208 | void overlayCorners(); |
| 209 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 210 | void fillRedBufferTextureTransform(); |
| 211 | |
| 212 | void fillBufferTextureTransform(); |
| 213 | |
| 214 | void fillRedBufferWithPremultiplyAlpha(); |
| 215 | |
| 216 | void fillBufferWithPremultiplyAlpha(); |
| 217 | |
| 218 | void fillRedBufferWithoutPremultiplyAlpha(); |
| 219 | |
| 220 | void fillBufferWithoutPremultiplyAlpha(); |
| 221 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 222 | void fillGreenColorBufferThenClearRegion(); |
| 223 | |
| 224 | void clearLeftRegion(); |
| 225 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 226 | void clearRegion(); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 227 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 228 | // Keep around the same renderengine object to save on initialization time. |
| 229 | // For now, exercise the GL backend directly so that some caching specifics |
| 230 | // can be tested without changing the interface. |
| 231 | static std::unique_ptr<renderengine::gl::GLESRenderEngine> sRE; |
| 232 | // Dumb hack to avoid NPE in the EGL driver: the GraphicBuffer needs to |
| 233 | // be freed *after* RenderEngine is destroyed, so that the EGL image is |
| 234 | // destroyed first. |
| 235 | static sp<GraphicBuffer> sCurrentBuffer; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 236 | |
| 237 | sp<GraphicBuffer> mBuffer; |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 238 | |
| 239 | std::vector<uint32_t> mTexNames; |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 242 | std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRE = nullptr; |
| 243 | sp<GraphicBuffer> RenderEngineTest::sCurrentBuffer = nullptr; |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 244 | |
| 245 | struct ColorSourceVariant { |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 246 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
| 247 | RenderEngineTest* /*fixture*/) { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 248 | layer.source.solidColor = half3(r, g, b); |
| 249 | } |
| 250 | }; |
| 251 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 252 | struct RelaxOpaqueBufferVariant { |
| 253 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 254 | layer.source.buffer.isOpaque = false; |
| 255 | } |
| 256 | |
| 257 | static uint8_t getAlphaChannel() { return 255; } |
| 258 | }; |
| 259 | |
| 260 | struct ForceOpaqueBufferVariant { |
| 261 | static void setOpaqueBit(renderengine::LayerSettings& layer) { |
| 262 | layer.source.buffer.isOpaque = true; |
| 263 | } |
| 264 | |
| 265 | static uint8_t getAlphaChannel() { |
| 266 | // The isOpaque bit will override the alpha channel, so this should be |
| 267 | // arbitrary. |
| 268 | return 10; |
| 269 | } |
| 270 | }; |
| 271 | |
| 272 | template <typename OpaquenessVariant> |
| 273 | struct BufferSourceVariant { |
| 274 | static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b, |
| 275 | RenderEngineTest* fixture) { |
| 276 | sp<GraphicBuffer> buf = RenderEngineTest::allocateSourceBuffer(1, 1); |
| 277 | uint32_t texName; |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 278 | fixture->sRE->genTextures(1, &texName); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 279 | fixture->mTexNames.push_back(texName); |
| 280 | |
| 281 | uint8_t* pixels; |
| 282 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 283 | reinterpret_cast<void**>(&pixels)); |
| 284 | |
| 285 | for (int32_t j = 0; j < buf->getHeight(); j++) { |
| 286 | uint8_t* iter = pixels + (buf->getStride() * j) * 4; |
| 287 | for (int32_t i = 0; i < buf->getWidth(); i++) { |
| 288 | iter[0] = uint8_t(r * 255); |
| 289 | iter[1] = uint8_t(g * 255); |
| 290 | iter[2] = uint8_t(b * 255); |
| 291 | iter[3] = OpaquenessVariant::getAlphaChannel(); |
| 292 | iter += 4; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | buf->unlock(); |
| 297 | |
| 298 | layer.source.buffer.buffer = buf; |
| 299 | layer.source.buffer.textureName = texName; |
| 300 | OpaquenessVariant::setOpaqueBit(layer); |
| 301 | } |
| 302 | }; |
| 303 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 304 | template <typename SourceVariant> |
| 305 | void RenderEngineTest::fillBuffer(half r, half g, half b, half a) { |
| 306 | renderengine::DisplaySettings settings; |
| 307 | settings.physicalDisplay = fullscreenRect(); |
| 308 | settings.clip = fullscreenRect(); |
| 309 | |
| 310 | std::vector<renderengine::LayerSettings> layers; |
| 311 | |
| 312 | renderengine::LayerSettings layer; |
| 313 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 314 | SourceVariant::fillColor(layer, r, g, b, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 315 | layer.alpha = a; |
| 316 | |
| 317 | layers.push_back(layer); |
| 318 | |
| 319 | invokeDraw(settings, layers, mBuffer); |
| 320 | } |
| 321 | |
| 322 | template <typename SourceVariant> |
| 323 | void RenderEngineTest::fillRedBuffer() { |
| 324 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, 1.0f); |
| 325 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 326 | } |
| 327 | |
| 328 | template <typename SourceVariant> |
| 329 | void RenderEngineTest::fillGreenBuffer() { |
| 330 | fillBuffer<SourceVariant>(0.0f, 1.0f, 0.0f, 1.0f); |
| 331 | expectBufferColor(fullscreenRect(), 0, 255, 0, 255); |
| 332 | } |
| 333 | |
| 334 | template <typename SourceVariant> |
| 335 | void RenderEngineTest::fillBlueBuffer() { |
| 336 | fillBuffer<SourceVariant>(0.0f, 0.0f, 1.0f, 1.0f); |
| 337 | expectBufferColor(fullscreenRect(), 0, 0, 255, 255); |
| 338 | } |
| 339 | |
| 340 | template <typename SourceVariant> |
| 341 | void RenderEngineTest::fillRedTransparentBuffer() { |
| 342 | fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, .2f); |
| 343 | expectBufferColor(fullscreenRect(), 51, 0, 0, 51); |
| 344 | } |
| 345 | |
| 346 | template <typename SourceVariant> |
| 347 | void RenderEngineTest::fillRedOffsetBuffer() { |
| 348 | renderengine::DisplaySettings settings; |
| 349 | settings.physicalDisplay = offsetRect(); |
| 350 | settings.clip = offsetRectAtZero(); |
| 351 | |
| 352 | std::vector<renderengine::LayerSettings> layers; |
| 353 | |
| 354 | renderengine::LayerSettings layer; |
| 355 | layer.geometry.boundaries = offsetRectAtZero().toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 356 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 357 | layer.alpha = 1.0f; |
| 358 | |
| 359 | layers.push_back(layer); |
| 360 | invokeDraw(settings, layers, mBuffer); |
| 361 | } |
| 362 | |
| 363 | template <typename SourceVariant> |
| 364 | void RenderEngineTest::fillBufferPhysicalOffset() { |
| 365 | fillRedOffsetBuffer<SourceVariant>(); |
| 366 | |
| 367 | expectBufferColor(Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH, |
| 368 | DEFAULT_DISPLAY_HEIGHT), |
| 369 | 255, 0, 0, 255); |
| 370 | Rect offsetRegionLeft(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_HEIGHT); |
| 371 | Rect offsetRegionTop(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_OFFSET); |
| 372 | |
| 373 | expectBufferColor(offsetRegionLeft, 0, 0, 0, 0); |
| 374 | expectBufferColor(offsetRegionTop, 0, 0, 0, 0); |
| 375 | } |
| 376 | |
| 377 | template <typename SourceVariant> |
| 378 | void RenderEngineTest::fillBufferCheckers(mat4 transform) { |
| 379 | renderengine::DisplaySettings settings; |
| 380 | settings.physicalDisplay = fullscreenRect(); |
| 381 | // Here logical space is 2x2 |
| 382 | settings.clip = Rect(2, 2); |
| 383 | settings.globalTransform = transform; |
| 384 | |
| 385 | std::vector<renderengine::LayerSettings> layers; |
| 386 | |
| 387 | renderengine::LayerSettings layerOne; |
| 388 | Rect rectOne(0, 0, 1, 1); |
| 389 | layerOne.geometry.boundaries = rectOne.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 390 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 391 | layerOne.alpha = 1.0f; |
| 392 | |
| 393 | renderengine::LayerSettings layerTwo; |
| 394 | Rect rectTwo(0, 1, 1, 2); |
| 395 | layerTwo.geometry.boundaries = rectTwo.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 396 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 397 | layerTwo.alpha = 1.0f; |
| 398 | |
| 399 | renderengine::LayerSettings layerThree; |
| 400 | Rect rectThree(1, 0, 2, 1); |
| 401 | layerThree.geometry.boundaries = rectThree.toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 402 | SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 403 | layerThree.alpha = 1.0f; |
| 404 | |
| 405 | layers.push_back(layerOne); |
| 406 | layers.push_back(layerTwo); |
| 407 | layers.push_back(layerThree); |
| 408 | |
| 409 | invokeDraw(settings, layers, mBuffer); |
| 410 | } |
| 411 | |
| 412 | template <typename SourceVariant> |
| 413 | void RenderEngineTest::fillBufferCheckersRotate0() { |
| 414 | fillBufferCheckers<SourceVariant>(mat4()); |
| 415 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0, |
| 416 | 255); |
| 417 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 418 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 419 | 0, 0, 255, 255); |
| 420 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 421 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 422 | 0, 0, 0, 0); |
| 423 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 424 | DEFAULT_DISPLAY_HEIGHT), |
| 425 | 0, 255, 0, 255); |
| 426 | } |
| 427 | |
| 428 | template <typename SourceVariant> |
| 429 | void RenderEngineTest::fillBufferCheckersRotate90() { |
| 430 | mat4 matrix = mat4(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 1); |
| 431 | fillBufferCheckers<SourceVariant>(matrix); |
| 432 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 255, 0, |
| 433 | 255); |
| 434 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 435 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 436 | 255, 0, 0, 255); |
| 437 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 438 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 439 | 0, 0, 255, 255); |
| 440 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 441 | DEFAULT_DISPLAY_HEIGHT), |
| 442 | 0, 0, 0, 0); |
| 443 | } |
| 444 | |
| 445 | template <typename SourceVariant> |
| 446 | void RenderEngineTest::fillBufferCheckersRotate180() { |
| 447 | mat4 matrix = mat4(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 2, 2, 0, 1); |
| 448 | fillBufferCheckers<SourceVariant>(matrix); |
| 449 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, |
| 450 | 0); |
| 451 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 452 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 453 | 0, 255, 0, 255); |
| 454 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 455 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 456 | 255, 0, 0, 255); |
| 457 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 458 | DEFAULT_DISPLAY_HEIGHT), |
| 459 | 0, 0, 255, 255); |
| 460 | } |
| 461 | |
| 462 | template <typename SourceVariant> |
| 463 | void RenderEngineTest::fillBufferCheckersRotate270() { |
| 464 | mat4 matrix = mat4(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1); |
| 465 | fillBufferCheckers<SourceVariant>(matrix); |
| 466 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255, |
| 467 | 255); |
| 468 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 469 | DEFAULT_DISPLAY_HEIGHT / 2), |
| 470 | 0, 0, 0, 0); |
| 471 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 472 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 473 | 0, 255, 0, 255); |
| 474 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2, |
| 475 | DEFAULT_DISPLAY_HEIGHT), |
| 476 | 255, 0, 0, 255); |
| 477 | } |
| 478 | |
| 479 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 480 | void RenderEngineTest::fillBufferWithLayerTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 481 | renderengine::DisplaySettings settings; |
| 482 | settings.physicalDisplay = fullscreenRect(); |
| 483 | // Here logical space is 2x2 |
| 484 | settings.clip = Rect(2, 2); |
| 485 | |
| 486 | std::vector<renderengine::LayerSettings> layers; |
| 487 | |
| 488 | renderengine::LayerSettings layer; |
| 489 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 490 | // Translate one pixel diagonally |
| 491 | 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] | 492 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 493 | layer.source.solidColor = half3(1.0f, 0.0f, 0.0f); |
| 494 | layer.alpha = 1.0f; |
| 495 | |
| 496 | layers.push_back(layer); |
| 497 | |
| 498 | invokeDraw(settings, layers, mBuffer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 499 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 500 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 501 | template <typename SourceVariant> |
| 502 | void RenderEngineTest::fillBufferLayerTransform() { |
| 503 | fillBufferWithLayerTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 504 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, 0); |
| 505 | expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 506 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2, |
| 507 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 508 | 255, 0, 0, 255); |
| 509 | } |
| 510 | |
| 511 | template <typename SourceVariant> |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 512 | void RenderEngineTest::fillBufferWithColorTransform() { |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 513 | renderengine::DisplaySettings settings; |
| 514 | settings.physicalDisplay = fullscreenRect(); |
| 515 | settings.clip = Rect(1, 1); |
| 516 | |
| 517 | std::vector<renderengine::LayerSettings> layers; |
| 518 | |
| 519 | renderengine::LayerSettings layer; |
| 520 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 521 | SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 522 | layer.alpha = 1.0f; |
| 523 | |
| 524 | // construct a fake color matrix |
| 525 | // annihilate green and blue channels |
| 526 | settings.colorTransform = mat4::scale(vec4(1, 0, 0, 1)); |
| 527 | // set red channel to red + green |
| 528 | layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); |
| 529 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 530 | layer.alpha = 1.0f; |
| 531 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 532 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 533 | layers.push_back(layer); |
| 534 | |
| 535 | invokeDraw(settings, layers, mBuffer); |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 536 | } |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 537 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 538 | template <typename SourceVariant> |
| 539 | void RenderEngineTest::fillBufferColorTransform() { |
| 540 | fillBufferWithColorTransform<SourceVariant>(); |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 541 | expectBufferColor(fullscreenRect(), 191, 0, 0, 255); |
| 542 | } |
| 543 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 544 | template <typename SourceVariant> |
| 545 | void RenderEngineTest::fillRedBufferWithRoundedCorners() { |
| 546 | renderengine::DisplaySettings settings; |
| 547 | settings.physicalDisplay = fullscreenRect(); |
| 548 | settings.clip = fullscreenRect(); |
| 549 | |
| 550 | std::vector<renderengine::LayerSettings> layers; |
| 551 | |
| 552 | renderengine::LayerSettings layer; |
| 553 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 554 | layer.geometry.roundedCornersRadius = 5.0f; |
| 555 | layer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect(); |
| 556 | SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 557 | layer.alpha = 1.0f; |
| 558 | |
| 559 | layers.push_back(layer); |
| 560 | |
| 561 | invokeDraw(settings, layers, mBuffer); |
| 562 | } |
| 563 | |
| 564 | template <typename SourceVariant> |
| 565 | void RenderEngineTest::fillBufferWithRoundedCorners() { |
| 566 | fillRedBufferWithRoundedCorners<SourceVariant>(); |
| 567 | // Corners should be ignored... |
| 568 | expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0); |
| 569 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0); |
| 570 | expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0); |
| 571 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1, |
| 572 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 573 | 0, 0, 0, 0); |
| 574 | // ...And the non-rounded portion should be red. |
| 575 | // Other pixels may be anti-aliased, so let's not check those. |
| 576 | expectBufferColor(Rect(5, 5, DEFAULT_DISPLAY_WIDTH - 5, DEFAULT_DISPLAY_HEIGHT - 5), 255, 0, 0, |
| 577 | 255); |
| 578 | } |
| 579 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 580 | template <typename SourceVariant> |
| 581 | void RenderEngineTest::overlayCorners() { |
| 582 | renderengine::DisplaySettings settings; |
| 583 | settings.physicalDisplay = fullscreenRect(); |
| 584 | settings.clip = fullscreenRect(); |
| 585 | |
| 586 | std::vector<renderengine::LayerSettings> layersFirst; |
| 587 | |
| 588 | renderengine::LayerSettings layerOne; |
| 589 | layerOne.geometry.boundaries = |
| 590 | FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0); |
| 591 | SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this); |
| 592 | layerOne.alpha = 0.2; |
| 593 | |
| 594 | layersFirst.push_back(layerOne); |
| 595 | invokeDraw(settings, layersFirst, mBuffer); |
| 596 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51); |
| 597 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 598 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 599 | 0, 0, 0, 0); |
| 600 | |
| 601 | std::vector<renderengine::LayerSettings> layersSecond; |
| 602 | renderengine::LayerSettings layerTwo; |
| 603 | layerTwo.geometry.boundaries = |
| 604 | FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0, |
| 605 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); |
| 606 | SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this); |
| 607 | layerTwo.alpha = 1.0f; |
| 608 | |
| 609 | layersSecond.push_back(layerTwo); |
| 610 | invokeDraw(settings, layersSecond, mBuffer); |
| 611 | |
| 612 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0); |
| 613 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1, |
| 614 | DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 615 | 0, 255, 0, 255); |
| 616 | } |
| 617 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 618 | void RenderEngineTest::fillRedBufferTextureTransform() { |
| 619 | renderengine::DisplaySettings settings; |
| 620 | settings.physicalDisplay = fullscreenRect(); |
| 621 | settings.clip = Rect(1, 1); |
| 622 | |
| 623 | std::vector<renderengine::LayerSettings> layers; |
| 624 | |
| 625 | renderengine::LayerSettings layer; |
| 626 | // Here will allocate a checker board texture, but transform texture |
| 627 | // coordinates so that only the upper left is applied. |
| 628 | sp<GraphicBuffer> buf = allocateSourceBuffer(2, 2); |
| 629 | uint32_t texName; |
| 630 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 631 | this->mTexNames.push_back(texName); |
| 632 | |
| 633 | uint8_t* pixels; |
| 634 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 635 | reinterpret_cast<void**>(&pixels)); |
| 636 | // Red top left, Green top right, Blue bottom left, Black bottom right |
| 637 | pixels[0] = 255; |
| 638 | pixels[1] = 0; |
| 639 | pixels[2] = 0; |
| 640 | pixels[3] = 255; |
| 641 | pixels[4] = 0; |
| 642 | pixels[5] = 255; |
| 643 | pixels[6] = 0; |
| 644 | pixels[7] = 255; |
| 645 | pixels[8] = 0; |
| 646 | pixels[9] = 0; |
| 647 | pixels[10] = 255; |
| 648 | pixels[11] = 255; |
| 649 | buf->unlock(); |
| 650 | |
| 651 | layer.source.buffer.buffer = buf; |
| 652 | layer.source.buffer.textureName = texName; |
| 653 | // Transform coordinates to only be inside the red quadrant. |
| 654 | layer.source.buffer.textureTransform = mat4::scale(vec4(0.2, 0.2, 1, 1)); |
| 655 | layer.alpha = 1.0f; |
| 656 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 657 | |
| 658 | layers.push_back(layer); |
| 659 | |
| 660 | invokeDraw(settings, layers, mBuffer); |
| 661 | } |
| 662 | |
| 663 | void RenderEngineTest::fillBufferTextureTransform() { |
| 664 | fillRedBufferTextureTransform(); |
| 665 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 666 | } |
| 667 | |
| 668 | void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() { |
| 669 | renderengine::DisplaySettings settings; |
| 670 | settings.physicalDisplay = fullscreenRect(); |
| 671 | // Here logical space is 1x1 |
| 672 | settings.clip = Rect(1, 1); |
| 673 | |
| 674 | std::vector<renderengine::LayerSettings> layers; |
| 675 | |
| 676 | renderengine::LayerSettings layer; |
| 677 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 678 | uint32_t texName; |
| 679 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 680 | this->mTexNames.push_back(texName); |
| 681 | |
| 682 | uint8_t* pixels; |
| 683 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 684 | reinterpret_cast<void**>(&pixels)); |
| 685 | pixels[0] = 255; |
| 686 | pixels[1] = 0; |
| 687 | pixels[2] = 0; |
| 688 | pixels[3] = 255; |
| 689 | buf->unlock(); |
| 690 | |
| 691 | layer.source.buffer.buffer = buf; |
| 692 | layer.source.buffer.textureName = texName; |
| 693 | layer.source.buffer.usePremultipliedAlpha = true; |
| 694 | layer.alpha = 0.5f; |
| 695 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 696 | |
| 697 | layers.push_back(layer); |
| 698 | |
| 699 | invokeDraw(settings, layers, mBuffer); |
| 700 | } |
| 701 | |
| 702 | void RenderEngineTest::fillBufferWithPremultiplyAlpha() { |
| 703 | fillRedBufferWithPremultiplyAlpha(); |
| 704 | expectBufferColor(fullscreenRect(), 128, 0, 0, 128); |
| 705 | } |
| 706 | |
| 707 | void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() { |
| 708 | renderengine::DisplaySettings settings; |
| 709 | settings.physicalDisplay = fullscreenRect(); |
| 710 | // Here logical space is 1x1 |
| 711 | settings.clip = Rect(1, 1); |
| 712 | |
| 713 | std::vector<renderengine::LayerSettings> layers; |
| 714 | |
| 715 | renderengine::LayerSettings layer; |
| 716 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 717 | uint32_t texName; |
| 718 | RenderEngineTest::sRE->genTextures(1, &texName); |
| 719 | this->mTexNames.push_back(texName); |
| 720 | |
| 721 | uint8_t* pixels; |
| 722 | buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 723 | reinterpret_cast<void**>(&pixels)); |
| 724 | pixels[0] = 255; |
| 725 | pixels[1] = 0; |
| 726 | pixels[2] = 0; |
| 727 | pixels[3] = 255; |
| 728 | buf->unlock(); |
| 729 | |
| 730 | layer.source.buffer.buffer = buf; |
| 731 | layer.source.buffer.textureName = texName; |
| 732 | layer.source.buffer.usePremultipliedAlpha = false; |
| 733 | layer.alpha = 0.5f; |
| 734 | layer.geometry.boundaries = Rect(1, 1).toFloatRect(); |
| 735 | |
| 736 | layers.push_back(layer); |
| 737 | |
| 738 | invokeDraw(settings, layers, mBuffer); |
| 739 | } |
| 740 | |
| 741 | void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() { |
| 742 | fillRedBufferWithoutPremultiplyAlpha(); |
| 743 | expectBufferColor(fullscreenRect(), 128, 0, 0, 64, 1); |
| 744 | } |
| 745 | |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 746 | void RenderEngineTest::clearLeftRegion() { |
| 747 | renderengine::DisplaySettings settings; |
| 748 | settings.physicalDisplay = fullscreenRect(); |
| 749 | // Here logical space is 4x4 |
| 750 | settings.clip = Rect(4, 4); |
| 751 | settings.globalTransform = mat4::scale(vec4(2, 4, 0, 1)); |
| 752 | settings.clearRegion = Region(Rect(1, 1)); |
| 753 | std::vector<renderengine::LayerSettings> layers; |
| 754 | // dummy layer, without bounds should not render anything |
| 755 | renderengine::LayerSettings layer; |
| 756 | layers.push_back(layer); |
| 757 | invokeDraw(settings, layers, mBuffer); |
| 758 | } |
| 759 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 760 | void RenderEngineTest::clearRegion() { |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 761 | // Reuse mBuffer |
| 762 | clearLeftRegion(); |
| 763 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 255); |
| 764 | expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH, |
| 765 | DEFAULT_DISPLAY_HEIGHT), |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 766 | 0, 0, 0, 0); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 767 | } |
| 768 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 769 | TEST_F(RenderEngineTest, drawLayers_noLayersToDraw) { |
| 770 | drawEmptyLayers(); |
| 771 | } |
| 772 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 773 | TEST_F(RenderEngineTest, drawLayers_nullOutputBuffer) { |
| 774 | renderengine::DisplaySettings settings; |
| 775 | std::vector<renderengine::LayerSettings> layers; |
| 776 | renderengine::LayerSettings layer; |
| 777 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 778 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 779 | layers.push_back(layer); |
| 780 | base::unique_fd fence; |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 781 | 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] | 782 | |
| 783 | ASSERT_EQ(BAD_VALUE, status); |
| 784 | } |
| 785 | |
| 786 | TEST_F(RenderEngineTest, drawLayers_nullOutputFence) { |
| 787 | renderengine::DisplaySettings settings; |
| 788 | settings.physicalDisplay = fullscreenRect(); |
| 789 | settings.clip = fullscreenRect(); |
| 790 | |
| 791 | std::vector<renderengine::LayerSettings> layers; |
| 792 | renderengine::LayerSettings layer; |
| 793 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 794 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 795 | layer.alpha = 1.0; |
| 796 | layers.push_back(layer); |
| 797 | |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 798 | status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 799 | base::unique_fd(), nullptr); |
| 800 | sCurrentBuffer = mBuffer; |
| 801 | ASSERT_EQ(NO_ERROR, status); |
| 802 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 803 | } |
| 804 | |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 805 | TEST_F(RenderEngineTest, drawLayers_doesNotCacheFramebuffer) { |
| 806 | renderengine::DisplaySettings settings; |
| 807 | settings.physicalDisplay = fullscreenRect(); |
| 808 | settings.clip = fullscreenRect(); |
| 809 | |
| 810 | std::vector<renderengine::LayerSettings> layers; |
| 811 | renderengine::LayerSettings layer; |
| 812 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 813 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 814 | layer.alpha = 1.0; |
| 815 | layers.push_back(layer); |
| 816 | |
| 817 | status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), false, |
| 818 | base::unique_fd(), nullptr); |
| 819 | sCurrentBuffer = mBuffer; |
| 820 | ASSERT_EQ(NO_ERROR, status); |
| 821 | ASSERT_FALSE(sRE->isFramebufferImageCachedForTesting(mBuffer->getId())); |
| 822 | expectBufferColor(fullscreenRect(), 255, 0, 0, 255); |
| 823 | } |
| 824 | |
Alec Mouri | 1089aed | 2018-10-25 21:33:57 -0700 | [diff] [blame] | 825 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) { |
| 826 | fillRedBuffer<ColorSourceVariant>(); |
| 827 | } |
| 828 | |
| 829 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) { |
| 830 | fillGreenBuffer<ColorSourceVariant>(); |
| 831 | } |
| 832 | |
| 833 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) { |
| 834 | fillBlueBuffer<ColorSourceVariant>(); |
| 835 | } |
| 836 | |
| 837 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) { |
| 838 | fillRedTransparentBuffer<ColorSourceVariant>(); |
| 839 | } |
| 840 | |
| 841 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) { |
| 842 | fillBufferPhysicalOffset<ColorSourceVariant>(); |
| 843 | } |
| 844 | |
| 845 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) { |
| 846 | fillBufferCheckersRotate0<ColorSourceVariant>(); |
| 847 | } |
| 848 | |
| 849 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) { |
| 850 | fillBufferCheckersRotate90<ColorSourceVariant>(); |
| 851 | } |
| 852 | |
| 853 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) { |
| 854 | fillBufferCheckersRotate180<ColorSourceVariant>(); |
| 855 | } |
| 856 | |
| 857 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) { |
| 858 | fillBufferCheckersRotate270<ColorSourceVariant>(); |
| 859 | } |
| 860 | |
| 861 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) { |
| 862 | fillBufferLayerTransform<ColorSourceVariant>(); |
| 863 | } |
| 864 | |
| 865 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) { |
| 866 | fillBufferLayerTransform<ColorSourceVariant>(); |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 869 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) { |
| 870 | fillBufferWithRoundedCorners<ColorSourceVariant>(); |
| 871 | } |
| 872 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 873 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_colorSource) { |
| 874 | overlayCorners<ColorSourceVariant>(); |
| 875 | } |
| 876 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 877 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) { |
| 878 | fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 879 | } |
| 880 | |
| 881 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) { |
| 882 | fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 883 | } |
| 884 | |
| 885 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) { |
| 886 | fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 887 | } |
| 888 | |
| 889 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) { |
| 890 | fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 891 | } |
| 892 | |
| 893 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) { |
| 894 | fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 895 | } |
| 896 | |
| 897 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) { |
| 898 | fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 899 | } |
| 900 | |
| 901 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) { |
| 902 | fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 903 | } |
| 904 | |
| 905 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) { |
| 906 | fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 907 | } |
| 908 | |
| 909 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) { |
| 910 | fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 911 | } |
| 912 | |
| 913 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) { |
| 914 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 915 | } |
| 916 | |
| 917 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) { |
| 918 | fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 919 | } |
| 920 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 921 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) { |
| 922 | fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 923 | } |
| 924 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 925 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) { |
| 926 | overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>(); |
| 927 | } |
| 928 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 929 | TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) { |
| 930 | fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 931 | } |
| 932 | |
| 933 | TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) { |
| 934 | fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 935 | } |
| 936 | |
| 937 | TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) { |
| 938 | fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 939 | } |
| 940 | |
| 941 | TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) { |
| 942 | fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 943 | } |
| 944 | |
| 945 | TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) { |
| 946 | fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 947 | } |
| 948 | |
| 949 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) { |
| 950 | fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 951 | } |
| 952 | |
| 953 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) { |
| 954 | fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 955 | } |
| 956 | |
| 957 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) { |
| 958 | fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 959 | } |
| 960 | |
| 961 | TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) { |
| 962 | fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 963 | } |
| 964 | |
| 965 | TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) { |
| 966 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 967 | } |
| 968 | |
| 969 | TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) { |
| 970 | fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 971 | } |
| 972 | |
Alec Mouri | 7c94edb | 2018-12-03 21:23:26 -0800 | [diff] [blame] | 973 | TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) { |
| 974 | fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 975 | } |
| 976 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 977 | TEST_F(RenderEngineTest, drawLayers_overlayCorners_bufferSource) { |
| 978 | overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>(); |
| 979 | } |
| 980 | |
Alec Mouri | 0d5e1eb | 2018-11-10 20:40:12 -0800 | [diff] [blame] | 981 | TEST_F(RenderEngineTest, drawLayers_fillBufferTextureTransform) { |
| 982 | fillBufferTextureTransform(); |
| 983 | } |
| 984 | |
| 985 | TEST_F(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) { |
| 986 | fillBufferWithPremultiplyAlpha(); |
| 987 | } |
| 988 | |
| 989 | TEST_F(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) { |
| 990 | fillBufferWithoutPremultiplyAlpha(); |
| 991 | } |
| 992 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 993 | TEST_F(RenderEngineTest, drawLayers_clearRegion) { |
| 994 | clearRegion(); |
Alec Mouri | ac33553 | 2018-11-12 15:01:33 -0800 | [diff] [blame] | 995 | } |
| 996 | |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 997 | TEST_F(RenderEngineTest, drawLayers_fillsBufferAndCachesImages) { |
| 998 | renderengine::DisplaySettings settings; |
| 999 | settings.physicalDisplay = fullscreenRect(); |
| 1000 | settings.clip = fullscreenRect(); |
| 1001 | |
| 1002 | std::vector<renderengine::LayerSettings> layers; |
| 1003 | |
| 1004 | renderengine::LayerSettings layer; |
| 1005 | layer.geometry.boundaries = fullscreenRect().toFloatRect(); |
| 1006 | BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); |
| 1007 | |
| 1008 | layers.push_back(layer); |
| 1009 | invokeDraw(settings, layers, mBuffer); |
| 1010 | uint64_t bufferId = layer.source.buffer.buffer->getId(); |
| 1011 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1012 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1013 | sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1014 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1015 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1016 | [&]() REQUIRES(barrier->mutex) { |
| 1017 | return barrier->isOpen; |
| 1018 | })); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1019 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1020 | EXPECT_EQ(NO_ERROR, barrier->result); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | TEST_F(RenderEngineTest, drawLayers_bindExternalBufferWithNullBuffer) { |
| 1024 | status_t result = sRE->bindExternalTextureBuffer(0, nullptr, nullptr); |
| 1025 | ASSERT_EQ(BAD_VALUE, result); |
| 1026 | } |
| 1027 | |
| 1028 | TEST_F(RenderEngineTest, drawLayers_bindExternalBufferCachesImages) { |
| 1029 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 1030 | uint32_t texName; |
| 1031 | sRE->genTextures(1, &texName); |
| 1032 | mTexNames.push_back(texName); |
| 1033 | |
| 1034 | sRE->bindExternalTextureBuffer(texName, buf, nullptr); |
| 1035 | uint64_t bufferId = buf->getId(); |
| 1036 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1037 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1038 | sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1039 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1040 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1041 | [&]() REQUIRES(barrier->mutex) { |
| 1042 | return barrier->isOpen; |
| 1043 | })); |
| 1044 | EXPECT_EQ(NO_ERROR, barrier->result); |
Alec Mouri | d43ccab | 2019-03-13 12:23:45 -0700 | [diff] [blame] | 1045 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
| 1046 | } |
| 1047 | |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1048 | TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferWithNullBuffer) { |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1049 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1050 | sRE->cacheExternalTextureBufferForTesting(nullptr); |
| 1051 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1052 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1053 | [&]() REQUIRES(barrier->mutex) { |
| 1054 | return barrier->isOpen; |
| 1055 | })); |
| 1056 | EXPECT_TRUE(barrier->isOpen); |
| 1057 | EXPECT_EQ(BAD_VALUE, barrier->result); |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferCachesImages) { |
| 1061 | sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1); |
| 1062 | uint64_t bufferId = buf->getId(); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1063 | std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier = |
| 1064 | sRE->cacheExternalTextureBufferForTesting(buf); |
| 1065 | { |
| 1066 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1067 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1068 | [&]() REQUIRES(barrier->mutex) { |
| 1069 | return barrier->isOpen; |
| 1070 | })); |
| 1071 | EXPECT_EQ(NO_ERROR, barrier->result); |
| 1072 | } |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1073 | EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId)); |
Alec Mouri | 16a9940 | 2019-07-29 16:37:30 -0700 | [diff] [blame] | 1074 | barrier = sRE->unbindExternalTextureBufferForTesting(bufferId); |
| 1075 | { |
| 1076 | std::lock_guard<std::mutex> lock(barrier->mutex); |
| 1077 | ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5), |
| 1078 | [&]() REQUIRES(barrier->mutex) { |
| 1079 | return barrier->isOpen; |
| 1080 | })); |
| 1081 | EXPECT_EQ(NO_ERROR, barrier->result); |
| 1082 | } |
Alec Mouri | d7b3a8b | 2019-03-21 11:44:18 -0700 | [diff] [blame] | 1083 | EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId)); |
| 1084 | } |
| 1085 | |
Alec Mouri | 6e57f68 | 2018-09-29 20:45:08 -0700 | [diff] [blame] | 1086 | } // namespace android |