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