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