blob: fce5e69e5b50d335bc19cb203254030679e3408f [file] [log] [blame]
Alec Mouri6e57f682018-09-29 20:45:08 -07001/*
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 Mouri16a99402019-07-29 16:37:30 -070017#include <chrono>
18#include <condition_variable>
Alec Mouri6e57f682018-09-29 20:45:08 -070019
Alec Mouri16a99402019-07-29 16:37:30 -070020#include <gtest/gtest.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070021#include <renderengine/RenderEngine.h>
Alec Mouri1089aed2018-10-25 21:33:57 -070022#include <sync/sync.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070023#include <ui/PixelFormat.h>
Alec Mourid43ccab2019-03-13 12:23:45 -070024#include "../gl/GLESRenderEngine.h"
Alec Mouri6e57f682018-09-29 20:45:08 -070025
Alec Mouri1089aed2018-10-25 21:33:57 -070026constexpr int DEFAULT_DISPLAY_WIDTH = 128;
27constexpr int DEFAULT_DISPLAY_HEIGHT = 256;
28constexpr int DEFAULT_DISPLAY_OFFSET = 64;
29
Alec Mouri6e57f682018-09-29 20:45:08 -070030namespace android {
31
Alec Mouri1089aed2018-10-25 21:33:57 -070032struct RenderEngineTest : public ::testing::Test {
Alec Mourid43ccab2019-03-13 12:23:45 -070033 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 Mouri0d5e1eb2018-11-10 20:40:12 -080046 static sp<GraphicBuffer> allocateDefaultBuffer() {
Alec Mouri1089aed2018-10-25 21:33:57 -070047 return new GraphicBuffer(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT,
48 HAL_PIXEL_FORMAT_RGBA_8888, 1,
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080049 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
50 GRALLOC_USAGE_HW_RENDER,
Alec Mouri1089aed2018-10-25 21:33:57 -070051 "output");
Alec Mouri6e57f682018-09-29 20:45:08 -070052 }
53
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080054 // 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 Mouri1089aed2018-10-25 21:33:57 -070062 RenderEngineTest() { mBuffer = allocateDefaultBuffer(); }
63
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080064 ~RenderEngineTest() {
65 for (uint32_t texName : mTexNames) {
66 sRE->deleteTextures(1, &texName);
67 }
68 }
69
Alec Mouri1089aed2018-10-25 21:33:57 -070070 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 Mourid43ccab2019-03-13 12:23:45 -0700120 void invokeDraw(renderengine::DisplaySettings settings,
121 std::vector<renderengine::LayerSettings> layers, sp<GraphicBuffer> buffer) {
Alec Mouri1089aed2018-10-25 21:33:57 -0700122 base::unique_fd fence;
Alec Mourife0d72b2019-03-21 14:05:56 -0700123 status_t status = sRE->drawLayers(settings, layers, buffer->getNativeBuffer(), true,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800124 base::unique_fd(), &fence);
Alec Mourid43ccab2019-03-13 12:23:45 -0700125 sCurrentBuffer = buffer;
Alec Mouri1089aed2018-10-25 21:33:57 -0700126
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 Mourid43ccab2019-03-13 12:23:45 -0700134 if (layers.size() > 0) {
135 ASSERT_TRUE(sRE->isFramebufferImageCachedForTesting(buffer->getId()));
136 }
Alec Mouri1089aed2018-10-25 21:33:57 -0700137 }
138
Alec Mourid43ccab2019-03-13 12:23:45 -0700139 void drawEmptyLayers() {
Alec Mouri6e57f682018-09-29 20:45:08 -0700140 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 Mouri1089aed2018-10-25 21:33:57 -0700144 invokeDraw(settings, layers, buffer);
Alec Mouri6e57f682018-09-29 20:45:08 -0700145 }
146
Alec Mouri1089aed2018-10-25 21:33:57 -0700147 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 Mouri0d5e1eb2018-11-10 20:40:12 -0800184 void fillBufferWithLayerTransform();
185
186 template <typename SourceVariant>
Alec Mouri1089aed2018-10-25 21:33:57 -0700187 void fillBufferLayerTransform();
188
189 template <typename SourceVariant>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800190 void fillBufferWithColorTransform();
191
192 template <typename SourceVariant>
Alec Mouri1089aed2018-10-25 21:33:57 -0700193 void fillBufferColorTransform();
194
Alec Mouri7c94edb2018-12-03 21:23:26 -0800195 template <typename SourceVariant>
196 void fillRedBufferWithRoundedCorners();
197
198 template <typename SourceVariant>
199 void fillBufferWithRoundedCorners();
200
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000201 template <typename SourceVariant>
202 void overlayCorners();
203
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800204 void fillRedBufferTextureTransform();
205
206 void fillBufferTextureTransform();
207
208 void fillRedBufferWithPremultiplyAlpha();
209
210 void fillBufferWithPremultiplyAlpha();
211
212 void fillRedBufferWithoutPremultiplyAlpha();
213
214 void fillBufferWithoutPremultiplyAlpha();
215
Alec Mouriac335532018-11-12 15:01:33 -0800216 void fillGreenColorBufferThenClearRegion();
217
218 void clearLeftRegion();
219
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000220 void clearRegion();
Alec Mouriac335532018-11-12 15:01:33 -0800221
Alec Mourid43ccab2019-03-13 12:23:45 -0700222 // 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 Mouri1089aed2018-10-25 21:33:57 -0700230
231 sp<GraphicBuffer> mBuffer;
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800232
233 std::vector<uint32_t> mTexNames;
Alec Mouri6e57f682018-09-29 20:45:08 -0700234};
235
Alec Mourid43ccab2019-03-13 12:23:45 -0700236std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRE = nullptr;
237sp<GraphicBuffer> RenderEngineTest::sCurrentBuffer = nullptr;
Alec Mouri1089aed2018-10-25 21:33:57 -0700238
239struct ColorSourceVariant {
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800240 static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b,
241 RenderEngineTest* /*fixture*/) {
Alec Mouri1089aed2018-10-25 21:33:57 -0700242 layer.source.solidColor = half3(r, g, b);
243 }
244};
245
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800246struct 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
254struct 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
266template <typename OpaquenessVariant>
267struct 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 Mourid43ccab2019-03-13 12:23:45 -0700272 fixture->sRE->genTextures(1, &texName);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800273 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 Mouri1089aed2018-10-25 21:33:57 -0700298template <typename SourceVariant>
299void 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 Mouri0d5e1eb2018-11-10 20:40:12 -0800308 SourceVariant::fillColor(layer, r, g, b, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700309 layer.alpha = a;
310
311 layers.push_back(layer);
312
313 invokeDraw(settings, layers, mBuffer);
314}
315
316template <typename SourceVariant>
317void RenderEngineTest::fillRedBuffer() {
318 fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, 1.0f);
319 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
320}
321
322template <typename SourceVariant>
323void RenderEngineTest::fillGreenBuffer() {
324 fillBuffer<SourceVariant>(0.0f, 1.0f, 0.0f, 1.0f);
325 expectBufferColor(fullscreenRect(), 0, 255, 0, 255);
326}
327
328template <typename SourceVariant>
329void RenderEngineTest::fillBlueBuffer() {
330 fillBuffer<SourceVariant>(0.0f, 0.0f, 1.0f, 1.0f);
331 expectBufferColor(fullscreenRect(), 0, 0, 255, 255);
332}
333
334template <typename SourceVariant>
335void RenderEngineTest::fillRedTransparentBuffer() {
336 fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, .2f);
337 expectBufferColor(fullscreenRect(), 51, 0, 0, 51);
338}
339
340template <typename SourceVariant>
341void 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 Mouri0d5e1eb2018-11-10 20:40:12 -0800350 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700351 layer.alpha = 1.0f;
352
353 layers.push_back(layer);
354 invokeDraw(settings, layers, mBuffer);
355}
356
357template <typename SourceVariant>
358void 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
371template <typename SourceVariant>
372void 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 Mouri0d5e1eb2018-11-10 20:40:12 -0800384 SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700385 layerOne.alpha = 1.0f;
386
387 renderengine::LayerSettings layerTwo;
388 Rect rectTwo(0, 1, 1, 2);
389 layerTwo.geometry.boundaries = rectTwo.toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800390 SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700391 layerTwo.alpha = 1.0f;
392
393 renderengine::LayerSettings layerThree;
394 Rect rectThree(1, 0, 2, 1);
395 layerThree.geometry.boundaries = rectThree.toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800396 SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700397 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
406template <typename SourceVariant>
407void 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
422template <typename SourceVariant>
423void 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
439template <typename SourceVariant>
440void 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
456template <typename SourceVariant>
457void 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
473template <typename SourceVariant>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800474void RenderEngineTest::fillBufferWithLayerTransform() {
Alec Mouri1089aed2018-10-25 21:33:57 -0700475 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 Mouri0d5e1eb2018-11-10 20:40:12 -0800486 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700487 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 Mouri0d5e1eb2018-11-10 20:40:12 -0800493}
Alec Mouri1089aed2018-10-25 21:33:57 -0700494
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800495template <typename SourceVariant>
496void RenderEngineTest::fillBufferLayerTransform() {
497 fillBufferWithLayerTransform<SourceVariant>();
Alec Mouri1089aed2018-10-25 21:33:57 -0700498 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
505template <typename SourceVariant>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800506void RenderEngineTest::fillBufferWithColorTransform() {
Alec Mouri1089aed2018-10-25 21:33:57 -0700507 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 Mouri0d5e1eb2018-11-10 20:40:12 -0800515 SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700516 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 Mouri0d5e1eb2018-11-10 20:40:12 -0800524 layer.alpha = 1.0f;
525 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
526
Alec Mouri1089aed2018-10-25 21:33:57 -0700527 layers.push_back(layer);
528
529 invokeDraw(settings, layers, mBuffer);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800530}
Alec Mouri1089aed2018-10-25 21:33:57 -0700531
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800532template <typename SourceVariant>
533void RenderEngineTest::fillBufferColorTransform() {
534 fillBufferWithColorTransform<SourceVariant>();
Alec Mouri1089aed2018-10-25 21:33:57 -0700535 expectBufferColor(fullscreenRect(), 191, 0, 0, 255);
536}
537
Alec Mouri7c94edb2018-12-03 21:23:26 -0800538template <typename SourceVariant>
539void 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
558template <typename SourceVariant>
559void 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 Mourie7d1d4a2019-02-05 01:13:46 +0000574template <typename SourceVariant>
575void 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 Mouri0d5e1eb2018-11-10 20:40:12 -0800612void 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
657void RenderEngineTest::fillBufferTextureTransform() {
658 fillRedBufferTextureTransform();
659 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
660}
661
662void 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
696void RenderEngineTest::fillBufferWithPremultiplyAlpha() {
697 fillRedBufferWithPremultiplyAlpha();
698 expectBufferColor(fullscreenRect(), 128, 0, 0, 128);
699}
700
701void 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
735void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() {
736 fillRedBufferWithoutPremultiplyAlpha();
wukui16f3c0bb2020-08-05 20:35:29 +0800737 expectBufferColor(fullscreenRect(), 128, 0, 0, 128, 1);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800738}
739
Alec Mouriac335532018-11-12 15:01:33 -0800740void 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 Mourie7d1d4a2019-02-05 01:13:46 +0000754void RenderEngineTest::clearRegion() {
Alec Mouriac335532018-11-12 15:01:33 -0800755 // 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 Mourie7d1d4a2019-02-05 01:13:46 +0000760 0, 0, 0, 0);
Alec Mouriac335532018-11-12 15:01:33 -0800761}
762
Alec Mouri1089aed2018-10-25 21:33:57 -0700763TEST_F(RenderEngineTest, drawLayers_noLayersToDraw) {
764 drawEmptyLayers();
765}
766
Alec Mourid43ccab2019-03-13 12:23:45 -0700767TEST_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 Mourife0d72b2019-03-21 14:05:56 -0700775 status_t status = sRE->drawLayers(settings, layers, nullptr, true, base::unique_fd(), &fence);
Alec Mourid43ccab2019-03-13 12:23:45 -0700776
777 ASSERT_EQ(BAD_VALUE, status);
778}
779
780TEST_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 Mourife0d72b2019-03-21 14:05:56 -0700792 status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true,
Alec Mourid43ccab2019-03-13 12:23:45 -0700793 base::unique_fd(), nullptr);
794 sCurrentBuffer = mBuffer;
795 ASSERT_EQ(NO_ERROR, status);
796 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
797}
798
Alec Mourife0d72b2019-03-21 14:05:56 -0700799TEST_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 Mouri1089aed2018-10-25 21:33:57 -0700819TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) {
820 fillRedBuffer<ColorSourceVariant>();
821}
822
823TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) {
824 fillGreenBuffer<ColorSourceVariant>();
825}
826
827TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) {
828 fillBlueBuffer<ColorSourceVariant>();
829}
830
831TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) {
832 fillRedTransparentBuffer<ColorSourceVariant>();
833}
834
835TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) {
836 fillBufferPhysicalOffset<ColorSourceVariant>();
837}
838
839TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) {
840 fillBufferCheckersRotate0<ColorSourceVariant>();
841}
842
843TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) {
844 fillBufferCheckersRotate90<ColorSourceVariant>();
845}
846
847TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) {
848 fillBufferCheckersRotate180<ColorSourceVariant>();
849}
850
851TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) {
852 fillBufferCheckersRotate270<ColorSourceVariant>();
853}
854
855TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) {
856 fillBufferLayerTransform<ColorSourceVariant>();
857}
858
859TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) {
860 fillBufferLayerTransform<ColorSourceVariant>();
Alec Mouri6e57f682018-09-29 20:45:08 -0700861}
862
Alec Mouri7c94edb2018-12-03 21:23:26 -0800863TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) {
864 fillBufferWithRoundedCorners<ColorSourceVariant>();
865}
866
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000867TEST_F(RenderEngineTest, drawLayers_overlayCorners_colorSource) {
868 overlayCorners<ColorSourceVariant>();
869}
870
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800871TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) {
872 fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
873}
874
875TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) {
876 fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
877}
878
879TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) {
880 fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
881}
882
883TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) {
884 fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
885}
886
887TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) {
888 fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>();
889}
890
891TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) {
892 fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>();
893}
894
895TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) {
896 fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>();
897}
898
899TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) {
900 fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>();
901}
902
903TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) {
904 fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>();
905}
906
907TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) {
908 fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>();
909}
910
911TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) {
912 fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>();
913}
914
Alec Mouri7c94edb2018-12-03 21:23:26 -0800915TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) {
916 fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>();
917}
918
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000919TEST_F(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) {
920 overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>();
921}
922
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800923TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) {
924 fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
925}
926
927TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) {
928 fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
929}
930
931TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) {
932 fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
933}
934
935TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) {
936 fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
937}
938
939TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) {
940 fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
941}
942
943TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) {
944 fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
945}
946
947TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) {
948 fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
949}
950
951TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) {
952 fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
953}
954
955TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) {
956 fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
957}
958
959TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) {
960 fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
961}
962
963TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) {
964 fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
965}
966
Alec Mouri7c94edb2018-12-03 21:23:26 -0800967TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) {
968 fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
969}
970
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000971TEST_F(RenderEngineTest, drawLayers_overlayCorners_bufferSource) {
972 overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
973}
974
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800975TEST_F(RenderEngineTest, drawLayers_fillBufferTextureTransform) {
976 fillBufferTextureTransform();
977}
978
979TEST_F(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) {
980 fillBufferWithPremultiplyAlpha();
981}
982
983TEST_F(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) {
984 fillBufferWithoutPremultiplyAlpha();
985}
986
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000987TEST_F(RenderEngineTest, drawLayers_clearRegion) {
988 clearRegion();
Alec Mouriac335532018-11-12 15:01:33 -0800989}
990
Alec Mourid43ccab2019-03-13 12:23:45 -0700991TEST_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 Mouri16a99402019-07-29 16:37:30 -07001006 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 Mourid43ccab2019-03-13 12:23:45 -07001013 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001014 EXPECT_EQ(NO_ERROR, barrier->result);
Alec Mourid43ccab2019-03-13 12:23:45 -07001015}
1016
1017TEST_F(RenderEngineTest, drawLayers_bindExternalBufferWithNullBuffer) {
1018 status_t result = sRE->bindExternalTextureBuffer(0, nullptr, nullptr);
1019 ASSERT_EQ(BAD_VALUE, result);
1020}
1021
1022TEST_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 Mouri16a99402019-07-29 16:37:30 -07001031 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 Mourid43ccab2019-03-13 12:23:45 -07001039 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
1040}
1041
Alec Mourid7b3a8b2019-03-21 11:44:18 -07001042TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferWithNullBuffer) {
Alec Mouri16a99402019-07-29 16:37:30 -07001043 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 Mourid7b3a8b2019-03-21 11:44:18 -07001052}
1053
1054TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferCachesImages) {
1055 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
1056 uint64_t bufferId = buf->getId();
Alec Mouri16a99402019-07-29 16:37:30 -07001057 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 Mourid7b3a8b2019-03-21 11:44:18 -07001067 EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001068 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 Mourid7b3a8b2019-03-21 11:44:18 -07001077 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
1078}
1079
Alec Mouri6e57f682018-09-29 20:45:08 -07001080} // namespace android