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