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 <chrono>
18 #include <condition_variable>
19
20 #include <gtest/gtest.h>
21 #include <renderengine/RenderEngine.h>
22 #include <sync/sync.h>
23 #include <ui/PixelFormat.h>
24 #include "../gl/GLESRenderEngine.h"
25
26 constexpr int DEFAULT_DISPLAY_WIDTH = 128;
27 constexpr int DEFAULT_DISPLAY_HEIGHT = 256;
28 constexpr int DEFAULT_DISPLAY_OFFSET = 64;
29
30 namespace android {
31
32 struct RenderEngineTest : public ::testing::Test {
SetUpTestSuiteandroid::RenderEngineTest33 static void SetUpTestSuite() {
34 sRE = renderengine::gl::GLESRenderEngine::create(static_cast<int32_t>(
35 ui::PixelFormat::RGBA_8888),
36 0, 1);
37 }
38
TearDownTestSuiteandroid::RenderEngineTest39 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
allocateDefaultBufferandroid::RenderEngineTest46 static sp<GraphicBuffer> allocateDefaultBuffer() {
47 return new GraphicBuffer(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT,
48 HAL_PIXEL_FORMAT_RGBA_8888, 1,
49 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
50 GRALLOC_USAGE_HW_RENDER,
51 "output");
52 }
53
54 // Allocates a 1x1 buffer to fill with a solid color
allocateSourceBufferandroid::RenderEngineTest55 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
RenderEngineTestandroid::RenderEngineTest62 RenderEngineTest() { mBuffer = allocateDefaultBuffer(); }
63
~RenderEngineTestandroid::RenderEngineTest64 ~RenderEngineTest() {
65 for (uint32_t texName : mTexNames) {
66 sRE->deleteTextures(1, &texName);
67 }
68 }
69
expectBufferColorandroid::RenderEngineTest70 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
fullscreenRectandroid::RenderEngineTest108 static Rect fullscreenRect() { return Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); }
109
offsetRectandroid::RenderEngineTest110 static Rect offsetRect() {
111 return Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH,
112 DEFAULT_DISPLAY_HEIGHT);
113 }
114
offsetRectAtZeroandroid::RenderEngineTest115 static Rect offsetRectAtZero() {
116 return Rect(DEFAULT_DISPLAY_WIDTH - DEFAULT_DISPLAY_OFFSET,
117 DEFAULT_DISPLAY_HEIGHT - DEFAULT_DISPLAY_OFFSET);
118 }
119
invokeDrawandroid::RenderEngineTest120 void invokeDraw(renderengine::DisplaySettings settings,
121 std::vector<renderengine::LayerSettings> layers, sp<GraphicBuffer> buffer) {
122 base::unique_fd fence;
123 status_t status = sRE->drawLayers(settings, layers, buffer->getNativeBuffer(), true,
124 base::unique_fd(), &fence);
125 sCurrentBuffer = buffer;
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);
134 if (layers.size() > 0) {
135 ASSERT_TRUE(sRE->isFramebufferImageCachedForTesting(buffer->getId()));
136 }
137 }
138
drawEmptyLayersandroid::RenderEngineTest139 void drawEmptyLayers() {
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();
144 invokeDraw(settings, layers, buffer);
145 }
146
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>
184 void fillBufferWithLayerTransform();
185
186 template <typename SourceVariant>
187 void fillBufferLayerTransform();
188
189 template <typename SourceVariant>
190 void fillBufferWithColorTransform();
191
192 template <typename SourceVariant>
193 void fillBufferColorTransform();
194
195 template <typename SourceVariant>
196 void fillRedBufferWithRoundedCorners();
197
198 template <typename SourceVariant>
199 void fillBufferWithRoundedCorners();
200
201 template <typename SourceVariant>
202 void overlayCorners();
203
204 void fillRedBufferTextureTransform();
205
206 void fillBufferTextureTransform();
207
208 void fillRedBufferWithPremultiplyAlpha();
209
210 void fillBufferWithPremultiplyAlpha();
211
212 void fillRedBufferWithoutPremultiplyAlpha();
213
214 void fillBufferWithoutPremultiplyAlpha();
215
216 void fillGreenColorBufferThenClearRegion();
217
218 void clearLeftRegion();
219
220 void clearRegion();
221
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;
230
231 sp<GraphicBuffer> mBuffer;
232
233 std::vector<uint32_t> mTexNames;
234 };
235
236 std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRE = nullptr;
237 sp<GraphicBuffer> RenderEngineTest::sCurrentBuffer = nullptr;
238
239 struct ColorSourceVariant {
fillColorandroid::ColorSourceVariant240 static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b,
241 RenderEngineTest* /*fixture*/) {
242 layer.source.solidColor = half3(r, g, b);
243 }
244 };
245
246 struct RelaxOpaqueBufferVariant {
setOpaqueBitandroid::RelaxOpaqueBufferVariant247 static void setOpaqueBit(renderengine::LayerSettings& layer) {
248 layer.source.buffer.isOpaque = false;
249 }
250
getAlphaChannelandroid::RelaxOpaqueBufferVariant251 static uint8_t getAlphaChannel() { return 255; }
252 };
253
254 struct ForceOpaqueBufferVariant {
setOpaqueBitandroid::ForceOpaqueBufferVariant255 static void setOpaqueBit(renderengine::LayerSettings& layer) {
256 layer.source.buffer.isOpaque = true;
257 }
258
getAlphaChannelandroid::ForceOpaqueBufferVariant259 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 {
fillColorandroid::BufferSourceVariant268 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;
272 fixture->sRE->genTextures(1, &texName);
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
298 template <typename SourceVariant>
fillBuffer(half r,half g,half b,half a)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();
308 SourceVariant::fillColor(layer, r, g, b, this);
309 layer.alpha = a;
310
311 layers.push_back(layer);
312
313 invokeDraw(settings, layers, mBuffer);
314 }
315
316 template <typename SourceVariant>
fillRedBuffer()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>
fillGreenBuffer()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>
fillBlueBuffer()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>
fillRedTransparentBuffer()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>
fillRedOffsetBuffer()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();
350 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
351 layer.alpha = 1.0f;
352
353 layers.push_back(layer);
354 invokeDraw(settings, layers, mBuffer);
355 }
356
357 template <typename SourceVariant>
fillBufferPhysicalOffset()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>
fillBufferCheckers(mat4 transform)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();
384 SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this);
385 layerOne.alpha = 1.0f;
386
387 renderengine::LayerSettings layerTwo;
388 Rect rectTwo(0, 1, 1, 2);
389 layerTwo.geometry.boundaries = rectTwo.toFloatRect();
390 SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this);
391 layerTwo.alpha = 1.0f;
392
393 renderengine::LayerSettings layerThree;
394 Rect rectThree(1, 0, 2, 1);
395 layerThree.geometry.boundaries = rectThree.toFloatRect();
396 SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this);
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>
fillBufferCheckersRotate0()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>
fillBufferCheckersRotate90()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>
fillBufferCheckersRotate180()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>
fillBufferCheckersRotate270()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>
fillBufferWithLayerTransform()474 void RenderEngineTest::fillBufferWithLayerTransform() {
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);
486 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
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);
493 }
494
495 template <typename SourceVariant>
fillBufferLayerTransform()496 void RenderEngineTest::fillBufferLayerTransform() {
497 fillBufferWithLayerTransform<SourceVariant>();
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>
fillBufferWithColorTransform()506 void RenderEngineTest::fillBufferWithColorTransform() {
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();
515 SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this);
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
524 layer.alpha = 1.0f;
525 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
526
527 layers.push_back(layer);
528
529 invokeDraw(settings, layers, mBuffer);
530 }
531
532 template <typename SourceVariant>
fillBufferColorTransform()533 void RenderEngineTest::fillBufferColorTransform() {
534 fillBufferWithColorTransform<SourceVariant>();
535 expectBufferColor(fullscreenRect(), 191, 0, 0, 255);
536 }
537
538 template <typename SourceVariant>
fillRedBufferWithRoundedCorners()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>
fillBufferWithRoundedCorners()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
574 template <typename SourceVariant>
overlayCorners()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
fillRedBufferTextureTransform()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
fillBufferTextureTransform()657 void RenderEngineTest::fillBufferTextureTransform() {
658 fillRedBufferTextureTransform();
659 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
660 }
661
fillRedBufferWithPremultiplyAlpha()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
fillBufferWithPremultiplyAlpha()696 void RenderEngineTest::fillBufferWithPremultiplyAlpha() {
697 fillRedBufferWithPremultiplyAlpha();
698 expectBufferColor(fullscreenRect(), 128, 0, 0, 128);
699 }
700
fillRedBufferWithoutPremultiplyAlpha()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
fillBufferWithoutPremultiplyAlpha()735 void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() {
736 fillRedBufferWithoutPremultiplyAlpha();
737 expectBufferColor(fullscreenRect(), 128, 0, 0, 64, 1);
738 }
739
clearLeftRegion()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
clearRegion()754 void RenderEngineTest::clearRegion() {
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),
760 0, 0, 0, 0);
761 }
762
TEST_F(RenderEngineTest,drawLayers_noLayersToDraw)763 TEST_F(RenderEngineTest, drawLayers_noLayersToDraw) {
764 drawEmptyLayers();
765 }
766
TEST_F(RenderEngineTest,drawLayers_nullOutputBuffer)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;
775 status_t status = sRE->drawLayers(settings, layers, nullptr, true, base::unique_fd(), &fence);
776
777 ASSERT_EQ(BAD_VALUE, status);
778 }
779
TEST_F(RenderEngineTest,drawLayers_nullOutputFence)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
792 status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true,
793 base::unique_fd(), nullptr);
794 sCurrentBuffer = mBuffer;
795 ASSERT_EQ(NO_ERROR, status);
796 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
797 }
798
TEST_F(RenderEngineTest,drawLayers_doesNotCacheFramebuffer)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
TEST_F(RenderEngineTest,drawLayers_fillRedBuffer_colorSource)819 TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) {
820 fillRedBuffer<ColorSourceVariant>();
821 }
822
TEST_F(RenderEngineTest,drawLayers_fillGreenBuffer_colorSource)823 TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) {
824 fillGreenBuffer<ColorSourceVariant>();
825 }
826
TEST_F(RenderEngineTest,drawLayers_fillBlueBuffer_colorSource)827 TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) {
828 fillBlueBuffer<ColorSourceVariant>();
829 }
830
TEST_F(RenderEngineTest,drawLayers_fillRedTransparentBuffer_colorSource)831 TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) {
832 fillRedTransparentBuffer<ColorSourceVariant>();
833 }
834
TEST_F(RenderEngineTest,drawLayers_fillBufferPhysicalOffset_colorSource)835 TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) {
836 fillBufferPhysicalOffset<ColorSourceVariant>();
837 }
838
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate0_colorSource)839 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) {
840 fillBufferCheckersRotate0<ColorSourceVariant>();
841 }
842
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate90_colorSource)843 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) {
844 fillBufferCheckersRotate90<ColorSourceVariant>();
845 }
846
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate180_colorSource)847 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) {
848 fillBufferCheckersRotate180<ColorSourceVariant>();
849 }
850
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate270_colorSource)851 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) {
852 fillBufferCheckersRotate270<ColorSourceVariant>();
853 }
854
TEST_F(RenderEngineTest,drawLayers_fillBufferLayerTransform_colorSource)855 TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) {
856 fillBufferLayerTransform<ColorSourceVariant>();
857 }
858
TEST_F(RenderEngineTest,drawLayers_fillBufferColorTransform_colorSource)859 TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) {
860 fillBufferLayerTransform<ColorSourceVariant>();
861 }
862
TEST_F(RenderEngineTest,drawLayers_fillBufferRoundedCorners_colorSource)863 TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) {
864 fillBufferWithRoundedCorners<ColorSourceVariant>();
865 }
866
TEST_F(RenderEngineTest,drawLayers_overlayCorners_colorSource)867 TEST_F(RenderEngineTest, drawLayers_overlayCorners_colorSource) {
868 overlayCorners<ColorSourceVariant>();
869 }
870
TEST_F(RenderEngineTest,drawLayers_fillRedBuffer_opaqueBufferSource)871 TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) {
872 fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
873 }
874
TEST_F(RenderEngineTest,drawLayers_fillGreenBuffer_opaqueBufferSource)875 TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) {
876 fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
877 }
878
TEST_F(RenderEngineTest,drawLayers_fillBlueBuffer_opaqueBufferSource)879 TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) {
880 fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
881 }
882
TEST_F(RenderEngineTest,drawLayers_fillRedTransparentBuffer_opaqueBufferSource)883 TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) {
884 fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
885 }
886
TEST_F(RenderEngineTest,drawLayers_fillBufferPhysicalOffset_opaqueBufferSource)887 TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) {
888 fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>();
889 }
890
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate0_opaqueBufferSource)891 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) {
892 fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>();
893 }
894
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate90_opaqueBufferSource)895 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) {
896 fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>();
897 }
898
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate180_opaqueBufferSource)899 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) {
900 fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>();
901 }
902
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate270_opaqueBufferSource)903 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) {
904 fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>();
905 }
906
TEST_F(RenderEngineTest,drawLayers_fillBufferLayerTransform_opaqueBufferSource)907 TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) {
908 fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>();
909 }
910
TEST_F(RenderEngineTest,drawLayers_fillBufferColorTransform_opaqueBufferSource)911 TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) {
912 fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>();
913 }
914
TEST_F(RenderEngineTest,drawLayers_fillBufferRoundedCorners_opaqueBufferSource)915 TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) {
916 fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>();
917 }
918
TEST_F(RenderEngineTest,drawLayers_overlayCorners_opaqueBufferSource)919 TEST_F(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) {
920 overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>();
921 }
922
TEST_F(RenderEngineTest,drawLayers_fillRedBuffer_bufferSource)923 TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) {
924 fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
925 }
926
TEST_F(RenderEngineTest,drawLayers_fillGreenBuffer_bufferSource)927 TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) {
928 fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
929 }
930
TEST_F(RenderEngineTest,drawLayers_fillBlueBuffer_bufferSource)931 TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) {
932 fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
933 }
934
TEST_F(RenderEngineTest,drawLayers_fillRedTransparentBuffer_bufferSource)935 TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) {
936 fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
937 }
938
TEST_F(RenderEngineTest,drawLayers_fillBufferPhysicalOffset_bufferSource)939 TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) {
940 fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
941 }
942
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate0_bufferSource)943 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) {
944 fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
945 }
946
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate90_bufferSource)947 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) {
948 fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
949 }
950
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate180_bufferSource)951 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) {
952 fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
953 }
954
TEST_F(RenderEngineTest,drawLayers_fillBufferCheckersRotate270_bufferSource)955 TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) {
956 fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
957 }
958
TEST_F(RenderEngineTest,drawLayers_fillBufferLayerTransform_bufferSource)959 TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) {
960 fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
961 }
962
TEST_F(RenderEngineTest,drawLayers_fillBufferColorTransform_bufferSource)963 TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) {
964 fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
965 }
966
TEST_F(RenderEngineTest,drawLayers_fillBufferRoundedCorners_bufferSource)967 TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) {
968 fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
969 }
970
TEST_F(RenderEngineTest,drawLayers_overlayCorners_bufferSource)971 TEST_F(RenderEngineTest, drawLayers_overlayCorners_bufferSource) {
972 overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
973 }
974
TEST_F(RenderEngineTest,drawLayers_fillBufferTextureTransform)975 TEST_F(RenderEngineTest, drawLayers_fillBufferTextureTransform) {
976 fillBufferTextureTransform();
977 }
978
TEST_F(RenderEngineTest,drawLayers_fillBuffer_premultipliesAlpha)979 TEST_F(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) {
980 fillBufferWithPremultiplyAlpha();
981 }
982
TEST_F(RenderEngineTest,drawLayers_fillBuffer_withoutPremultiplyingAlpha)983 TEST_F(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) {
984 fillBufferWithoutPremultiplyAlpha();
985 }
986
TEST_F(RenderEngineTest,drawLayers_clearRegion)987 TEST_F(RenderEngineTest, drawLayers_clearRegion) {
988 clearRegion();
989 }
990
TEST_F(RenderEngineTest,drawLayers_fillsBufferAndCachesImages)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));
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 }));
1013 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
1014 EXPECT_EQ(NO_ERROR, barrier->result);
1015 }
1016
TEST_F(RenderEngineTest,drawLayers_bindExternalBufferWithNullBuffer)1017 TEST_F(RenderEngineTest, drawLayers_bindExternalBufferWithNullBuffer) {
1018 status_t result = sRE->bindExternalTextureBuffer(0, nullptr, nullptr);
1019 ASSERT_EQ(BAD_VALUE, result);
1020 }
1021
TEST_F(RenderEngineTest,drawLayers_bindExternalBufferCachesImages)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));
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);
1039 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
1040 }
1041
TEST_F(RenderEngineTest,drawLayers_cacheExternalBufferWithNullBuffer)1042 TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferWithNullBuffer) {
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);
1052 }
1053
TEST_F(RenderEngineTest,drawLayers_cacheExternalBufferCachesImages)1054 TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferCachesImages) {
1055 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
1056 uint64_t bufferId = buf->getId();
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 }
1067 EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId));
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 }
1077 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
1078 }
1079
1080 } // namespace android
1081