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