blob: ba5a3f55501480a940d2f4a89c60824277ca6a8f [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>
Vishnu Nair16efdbf2019-12-10 11:55:42 -080019#include <fstream>
Alec Mouri6e57f682018-09-29 20:45:08 -070020
Alec Mouri16a99402019-07-29 16:37:30 -070021#include <gtest/gtest.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070022#include <renderengine/RenderEngine.h>
Alec Mouri1089aed2018-10-25 21:33:57 -070023#include <sync/sync.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070024#include <ui/PixelFormat.h>
Alec Mourid43ccab2019-03-13 12:23:45 -070025#include "../gl/GLESRenderEngine.h"
Alec Mouri6e57f682018-09-29 20:45:08 -070026
Alec Mouri1089aed2018-10-25 21:33:57 -070027constexpr int DEFAULT_DISPLAY_WIDTH = 128;
28constexpr int DEFAULT_DISPLAY_HEIGHT = 256;
29constexpr int DEFAULT_DISPLAY_OFFSET = 64;
Vishnu Nair16efdbf2019-12-10 11:55:42 -080030constexpr bool WRITE_BUFFER_TO_FILE_ON_FAILURE = false;
Alec Mouri1089aed2018-10-25 21:33:57 -070031
Alec Mouri6e57f682018-09-29 20:45:08 -070032namespace android {
33
Alec Mouri1089aed2018-10-25 21:33:57 -070034struct RenderEngineTest : public ::testing::Test {
Alec Mourid43ccab2019-03-13 12:23:45 -070035 static void SetUpTestSuite() {
Peiyong Lin4137a1d2019-10-09 10:39:09 -070036 sRE = renderengine::gl::GLESRenderEngine::create(
37 renderengine::RenderEngineCreationArgs::Builder()
38 .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888))
39 .setImageCacheSize(1)
40 .setUseColorManagerment(false)
41 .setEnableProtectedContext(false)
42 .setPrecacheToneMapperShaderOnly(false)
43 .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM)
44 .build());
Alec Mourid43ccab2019-03-13 12:23:45 -070045 }
46
47 static void TearDownTestSuite() {
48 // The ordering here is important - sCurrentBuffer must live longer
49 // than RenderEngine to avoid a null reference on tear-down.
50 sRE = nullptr;
51 sCurrentBuffer = nullptr;
52 }
53
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080054 static sp<GraphicBuffer> allocateDefaultBuffer() {
Alec Mouri1089aed2018-10-25 21:33:57 -070055 return new GraphicBuffer(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT,
56 HAL_PIXEL_FORMAT_RGBA_8888, 1,
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080057 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
58 GRALLOC_USAGE_HW_RENDER,
Alec Mouri1089aed2018-10-25 21:33:57 -070059 "output");
Alec Mouri6e57f682018-09-29 20:45:08 -070060 }
61
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080062 // Allocates a 1x1 buffer to fill with a solid color
63 static sp<GraphicBuffer> allocateSourceBuffer(uint32_t width, uint32_t height) {
64 return new GraphicBuffer(width, height, HAL_PIXEL_FORMAT_RGBA_8888, 1,
65 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
66 GRALLOC_USAGE_HW_TEXTURE,
67 "input");
68 }
69
Alec Mouri1089aed2018-10-25 21:33:57 -070070 RenderEngineTest() { mBuffer = allocateDefaultBuffer(); }
71
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080072 ~RenderEngineTest() {
Vishnu Nair16efdbf2019-12-10 11:55:42 -080073 if (WRITE_BUFFER_TO_FILE_ON_FAILURE && ::testing::Test::HasFailure()) {
74 writeBufferToFile("/data/texture_out_");
75 }
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080076 for (uint32_t texName : mTexNames) {
77 sRE->deleteTextures(1, &texName);
78 }
79 }
80
Vishnu Nair16efdbf2019-12-10 11:55:42 -080081 void writeBufferToFile(const char* basename) {
82 std::string filename(basename);
83 filename.append(::testing::UnitTest::GetInstance()->current_test_info()->name());
84 filename.append(".ppm");
85 std::ofstream file(filename.c_str(), std::ios::binary);
86 if (!file.is_open()) {
87 ALOGE("Unable to open file: %s", filename.c_str());
88 ALOGE("You may need to do: \"adb shell setenforce 0\" to enable "
89 "surfaceflinger to write debug images");
90 return;
91 }
92
Alec Mouri1089aed2018-10-25 21:33:57 -070093 uint8_t* pixels;
94 mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
95 reinterpret_cast<void**>(&pixels));
96
Vishnu Nair16efdbf2019-12-10 11:55:42 -080097 file << "P6\n";
98 file << mBuffer->getWidth() << "\n";
99 file << mBuffer->getHeight() << "\n";
100 file << 255 << "\n";
101
102 std::vector<uint8_t> outBuffer(mBuffer->getWidth() * mBuffer->getHeight() * 3);
103 auto outPtr = reinterpret_cast<uint8_t*>(outBuffer.data());
104
105 for (int32_t j = 0; j < mBuffer->getHeight(); j++) {
106 const uint8_t* src = pixels + (mBuffer->getStride() * j) * 4;
107 for (int32_t i = 0; i < mBuffer->getWidth(); i++) {
108 // Only copy R, G and B components
109 outPtr[0] = src[0];
110 outPtr[1] = src[1];
111 outPtr[2] = src[2];
112 outPtr += 3;
113
114 src += 4;
115 }
116 }
117 file.write(reinterpret_cast<char*>(outBuffer.data()), outBuffer.size());
118 mBuffer->unlock();
119 }
120
121 void expectBufferColor(const Region& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
122 size_t c;
123 Rect const* rect = region.getArray(&c);
124 for (size_t i = 0; i < c; i++, rect++) {
125 expectBufferColor(*rect, r, g, b, a);
126 }
127 }
128
129 void expectBufferColor(const Rect& rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a,
130 uint8_t tolerance = 0) {
131 auto colorCompare = [tolerance](const uint8_t* colorA, const uint8_t* colorB) {
132 auto colorBitCompare = [tolerance](uint8_t a, uint8_t b) {
133 uint8_t tmp = a >= b ? a - b : b - a;
134 return tmp <= tolerance;
135 };
136 return std::equal(colorA, colorA + 4, colorB, colorBitCompare);
Alec Mouri1089aed2018-10-25 21:33:57 -0700137 };
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800138
139 expectBufferColor(rect, r, g, b, a, colorCompare);
140 }
141
142 void expectBufferColor(const Rect& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a,
143 std::function<bool(const uint8_t* a, const uint8_t* b)> colorCompare) {
144 uint8_t* pixels;
145 mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
146 reinterpret_cast<void**>(&pixels));
Alec Mouri1089aed2018-10-25 21:33:57 -0700147 int32_t maxFails = 10;
148 int32_t fails = 0;
149 for (int32_t j = 0; j < region.getHeight(); j++) {
150 const uint8_t* src =
151 pixels + (mBuffer->getStride() * (region.top + j) + region.left) * 4;
152 for (int32_t i = 0; i < region.getWidth(); i++) {
153 const uint8_t expected[4] = {r, g, b, a};
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800154 bool equal = colorCompare(src, expected);
Alec Mouri1089aed2018-10-25 21:33:57 -0700155 EXPECT_TRUE(equal)
156 << "pixel @ (" << region.left + i << ", " << region.top + j << "): "
157 << "expected (" << static_cast<uint32_t>(r) << ", "
158 << static_cast<uint32_t>(g) << ", " << static_cast<uint32_t>(b) << ", "
159 << static_cast<uint32_t>(a) << "), "
160 << "got (" << static_cast<uint32_t>(src[0]) << ", "
161 << static_cast<uint32_t>(src[1]) << ", " << static_cast<uint32_t>(src[2])
162 << ", " << static_cast<uint32_t>(src[3]) << ")";
163 src += 4;
164 if (!equal && ++fails >= maxFails) {
165 break;
166 }
167 }
168 if (fails >= maxFails) {
169 break;
170 }
171 }
172 mBuffer->unlock();
173 }
174
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800175 void expectAlpha(const Rect& rect, uint8_t a) {
176 auto colorCompare = [](const uint8_t* colorA, const uint8_t* colorB) {
177 return colorA[3] == colorB[3];
178 };
179 expectBufferColor(rect, 0.0f /* r */, 0.0f /*g */, 0.0f /* b */, a, colorCompare);
180 }
181
182 void expectShadowColor(const renderengine::LayerSettings& castingLayer,
183 const renderengine::ShadowSettings& shadow, const ubyte4& casterColor,
184 const ubyte4& backgroundColor) {
185 const Rect casterRect(castingLayer.geometry.boundaries);
186 Region casterRegion = Region(casterRect);
187 const float casterCornerRadius = castingLayer.geometry.roundedCornersRadius;
188 if (casterCornerRadius > 0.0f) {
189 // ignore the corners if a corner radius is set
190 Rect cornerRect(casterCornerRadius, casterCornerRadius);
191 casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.left, casterRect.top));
192 casterRegion.subtractSelf(
193 cornerRect.offsetTo(casterRect.right - casterCornerRadius, casterRect.top));
194 casterRegion.subtractSelf(
195 cornerRect.offsetTo(casterRect.left, casterRect.bottom - casterCornerRadius));
196 casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.right - casterCornerRadius,
197 casterRect.bottom - casterCornerRadius));
198 }
199
200 const float shadowInset = shadow.length * -1.0f;
201 const Rect casterWithShadow =
202 Rect(casterRect).inset(shadowInset, shadowInset, shadowInset, shadowInset);
203 const Region shadowRegion = Region(casterWithShadow).subtractSelf(casterRect);
204 const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow);
205
206 // verify casting layer
207 expectBufferColor(casterRegion, casterColor.r, casterColor.g, casterColor.b, casterColor.a);
208
209 // verify shadows by testing just the alpha since its difficult to validate the shadow color
210 size_t c;
211 Rect const* r = shadowRegion.getArray(&c);
212 for (size_t i = 0; i < c; i++, r++) {
213 expectAlpha(*r, 255);
214 }
215
216 // verify background
217 expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b,
218 backgroundColor.a);
219 }
220
221 static renderengine::ShadowSettings getShadowSettings(const vec2& casterPos, float shadowLength,
222 bool casterIsTranslucent) {
223 renderengine::ShadowSettings shadow;
224 shadow.ambientColor = {0.0f, 0.0f, 0.0f, 0.039f};
225 shadow.spotColor = {0.0f, 0.0f, 0.0f, 0.19f};
226 shadow.lightPos = vec3(casterPos.x, casterPos.y, 0);
227 shadow.lightRadius = 0.0f;
228 shadow.length = shadowLength;
229 shadow.casterIsTranslucent = casterIsTranslucent;
230 return shadow;
231 }
232
Alec Mouri1089aed2018-10-25 21:33:57 -0700233 static Rect fullscreenRect() { return Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); }
234
235 static Rect offsetRect() {
236 return Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH,
237 DEFAULT_DISPLAY_HEIGHT);
238 }
239
240 static Rect offsetRectAtZero() {
241 return Rect(DEFAULT_DISPLAY_WIDTH - DEFAULT_DISPLAY_OFFSET,
242 DEFAULT_DISPLAY_HEIGHT - DEFAULT_DISPLAY_OFFSET);
243 }
244
Alec Mourid43ccab2019-03-13 12:23:45 -0700245 void invokeDraw(renderengine::DisplaySettings settings,
246 std::vector<renderengine::LayerSettings> layers, sp<GraphicBuffer> buffer) {
Alec Mouri1089aed2018-10-25 21:33:57 -0700247 base::unique_fd fence;
Alec Mourife0d72b2019-03-21 14:05:56 -0700248 status_t status = sRE->drawLayers(settings, layers, buffer->getNativeBuffer(), true,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800249 base::unique_fd(), &fence);
Alec Mourid43ccab2019-03-13 12:23:45 -0700250 sCurrentBuffer = buffer;
Alec Mouri1089aed2018-10-25 21:33:57 -0700251
252 int fd = fence.release();
253 if (fd >= 0) {
254 sync_wait(fd, -1);
255 close(fd);
256 }
257
258 ASSERT_EQ(NO_ERROR, status);
Alec Mourid43ccab2019-03-13 12:23:45 -0700259 if (layers.size() > 0) {
260 ASSERT_TRUE(sRE->isFramebufferImageCachedForTesting(buffer->getId()));
261 }
Alec Mouri1089aed2018-10-25 21:33:57 -0700262 }
263
Alec Mourid43ccab2019-03-13 12:23:45 -0700264 void drawEmptyLayers() {
Alec Mouri6e57f682018-09-29 20:45:08 -0700265 renderengine::DisplaySettings settings;
266 std::vector<renderengine::LayerSettings> layers;
267 // Meaningless buffer since we don't do any drawing
268 sp<GraphicBuffer> buffer = new GraphicBuffer();
Alec Mouri1089aed2018-10-25 21:33:57 -0700269 invokeDraw(settings, layers, buffer);
Alec Mouri6e57f682018-09-29 20:45:08 -0700270 }
271
Alec Mouri1089aed2018-10-25 21:33:57 -0700272 template <typename SourceVariant>
273 void fillBuffer(half r, half g, half b, half a);
274
275 template <typename SourceVariant>
276 void fillRedBuffer();
277
278 template <typename SourceVariant>
279 void fillGreenBuffer();
280
281 template <typename SourceVariant>
282 void fillBlueBuffer();
283
284 template <typename SourceVariant>
285 void fillRedTransparentBuffer();
286
287 template <typename SourceVariant>
288 void fillRedOffsetBuffer();
289
290 template <typename SourceVariant>
291 void fillBufferPhysicalOffset();
292
293 template <typename SourceVariant>
294 void fillBufferCheckers(mat4 transform);
295
296 template <typename SourceVariant>
297 void fillBufferCheckersRotate0();
298
299 template <typename SourceVariant>
300 void fillBufferCheckersRotate90();
301
302 template <typename SourceVariant>
303 void fillBufferCheckersRotate180();
304
305 template <typename SourceVariant>
306 void fillBufferCheckersRotate270();
307
308 template <typename SourceVariant>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800309 void fillBufferWithLayerTransform();
310
311 template <typename SourceVariant>
Alec Mouri1089aed2018-10-25 21:33:57 -0700312 void fillBufferLayerTransform();
313
314 template <typename SourceVariant>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800315 void fillBufferWithColorTransform();
316
317 template <typename SourceVariant>
Alec Mouri1089aed2018-10-25 21:33:57 -0700318 void fillBufferColorTransform();
319
Alec Mouri7c94edb2018-12-03 21:23:26 -0800320 template <typename SourceVariant>
321 void fillRedBufferWithRoundedCorners();
322
323 template <typename SourceVariant>
324 void fillBufferWithRoundedCorners();
325
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000326 template <typename SourceVariant>
327 void overlayCorners();
328
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800329 void fillRedBufferTextureTransform();
330
331 void fillBufferTextureTransform();
332
333 void fillRedBufferWithPremultiplyAlpha();
334
335 void fillBufferWithPremultiplyAlpha();
336
337 void fillRedBufferWithoutPremultiplyAlpha();
338
339 void fillBufferWithoutPremultiplyAlpha();
340
Alec Mouriac335532018-11-12 15:01:33 -0800341 void fillGreenColorBufferThenClearRegion();
342
343 void clearLeftRegion();
344
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000345 void clearRegion();
Alec Mouriac335532018-11-12 15:01:33 -0800346
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800347 template <typename SourceVariant>
348 void drawShadow(const renderengine::LayerSettings& castingLayer,
349 const renderengine::ShadowSettings& shadow, const ubyte4& casterColor,
350 const ubyte4& backgroundColor);
351
Alec Mourid43ccab2019-03-13 12:23:45 -0700352 // Keep around the same renderengine object to save on initialization time.
353 // For now, exercise the GL backend directly so that some caching specifics
354 // can be tested without changing the interface.
355 static std::unique_ptr<renderengine::gl::GLESRenderEngine> sRE;
356 // Dumb hack to avoid NPE in the EGL driver: the GraphicBuffer needs to
357 // be freed *after* RenderEngine is destroyed, so that the EGL image is
358 // destroyed first.
359 static sp<GraphicBuffer> sCurrentBuffer;
Alec Mouri1089aed2018-10-25 21:33:57 -0700360
361 sp<GraphicBuffer> mBuffer;
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800362
363 std::vector<uint32_t> mTexNames;
Alec Mouri6e57f682018-09-29 20:45:08 -0700364};
365
Alec Mourid43ccab2019-03-13 12:23:45 -0700366std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRE = nullptr;
367sp<GraphicBuffer> RenderEngineTest::sCurrentBuffer = nullptr;
Alec Mouri1089aed2018-10-25 21:33:57 -0700368
369struct ColorSourceVariant {
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800370 static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b,
371 RenderEngineTest* /*fixture*/) {
Alec Mouri1089aed2018-10-25 21:33:57 -0700372 layer.source.solidColor = half3(r, g, b);
373 }
374};
375
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800376struct RelaxOpaqueBufferVariant {
377 static void setOpaqueBit(renderengine::LayerSettings& layer) {
378 layer.source.buffer.isOpaque = false;
379 }
380
381 static uint8_t getAlphaChannel() { return 255; }
382};
383
384struct ForceOpaqueBufferVariant {
385 static void setOpaqueBit(renderengine::LayerSettings& layer) {
386 layer.source.buffer.isOpaque = true;
387 }
388
389 static uint8_t getAlphaChannel() {
390 // The isOpaque bit will override the alpha channel, so this should be
391 // arbitrary.
392 return 10;
393 }
394};
395
396template <typename OpaquenessVariant>
397struct BufferSourceVariant {
398 static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b,
399 RenderEngineTest* fixture) {
400 sp<GraphicBuffer> buf = RenderEngineTest::allocateSourceBuffer(1, 1);
401 uint32_t texName;
Alec Mourid43ccab2019-03-13 12:23:45 -0700402 fixture->sRE->genTextures(1, &texName);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800403 fixture->mTexNames.push_back(texName);
404
405 uint8_t* pixels;
406 buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
407 reinterpret_cast<void**>(&pixels));
408
409 for (int32_t j = 0; j < buf->getHeight(); j++) {
410 uint8_t* iter = pixels + (buf->getStride() * j) * 4;
411 for (int32_t i = 0; i < buf->getWidth(); i++) {
412 iter[0] = uint8_t(r * 255);
413 iter[1] = uint8_t(g * 255);
414 iter[2] = uint8_t(b * 255);
415 iter[3] = OpaquenessVariant::getAlphaChannel();
416 iter += 4;
417 }
418 }
419
420 buf->unlock();
421
422 layer.source.buffer.buffer = buf;
423 layer.source.buffer.textureName = texName;
424 OpaquenessVariant::setOpaqueBit(layer);
425 }
426};
427
Alec Mouri1089aed2018-10-25 21:33:57 -0700428template <typename SourceVariant>
429void RenderEngineTest::fillBuffer(half r, half g, half b, half a) {
430 renderengine::DisplaySettings settings;
431 settings.physicalDisplay = fullscreenRect();
432 settings.clip = fullscreenRect();
433
434 std::vector<renderengine::LayerSettings> layers;
435
436 renderengine::LayerSettings layer;
437 layer.geometry.boundaries = fullscreenRect().toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800438 SourceVariant::fillColor(layer, r, g, b, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700439 layer.alpha = a;
440
441 layers.push_back(layer);
442
443 invokeDraw(settings, layers, mBuffer);
444}
445
446template <typename SourceVariant>
447void RenderEngineTest::fillRedBuffer() {
448 fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, 1.0f);
449 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
450}
451
452template <typename SourceVariant>
453void RenderEngineTest::fillGreenBuffer() {
454 fillBuffer<SourceVariant>(0.0f, 1.0f, 0.0f, 1.0f);
455 expectBufferColor(fullscreenRect(), 0, 255, 0, 255);
456}
457
458template <typename SourceVariant>
459void RenderEngineTest::fillBlueBuffer() {
460 fillBuffer<SourceVariant>(0.0f, 0.0f, 1.0f, 1.0f);
461 expectBufferColor(fullscreenRect(), 0, 0, 255, 255);
462}
463
464template <typename SourceVariant>
465void RenderEngineTest::fillRedTransparentBuffer() {
466 fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, .2f);
467 expectBufferColor(fullscreenRect(), 51, 0, 0, 51);
468}
469
470template <typename SourceVariant>
471void RenderEngineTest::fillRedOffsetBuffer() {
472 renderengine::DisplaySettings settings;
473 settings.physicalDisplay = offsetRect();
474 settings.clip = offsetRectAtZero();
475
476 std::vector<renderengine::LayerSettings> layers;
477
478 renderengine::LayerSettings layer;
479 layer.geometry.boundaries = offsetRectAtZero().toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800480 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700481 layer.alpha = 1.0f;
482
483 layers.push_back(layer);
484 invokeDraw(settings, layers, mBuffer);
485}
486
487template <typename SourceVariant>
488void RenderEngineTest::fillBufferPhysicalOffset() {
489 fillRedOffsetBuffer<SourceVariant>();
490
491 expectBufferColor(Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH,
492 DEFAULT_DISPLAY_HEIGHT),
493 255, 0, 0, 255);
494 Rect offsetRegionLeft(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_HEIGHT);
495 Rect offsetRegionTop(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_OFFSET);
496
497 expectBufferColor(offsetRegionLeft, 0, 0, 0, 0);
498 expectBufferColor(offsetRegionTop, 0, 0, 0, 0);
499}
500
501template <typename SourceVariant>
502void RenderEngineTest::fillBufferCheckers(mat4 transform) {
503 renderengine::DisplaySettings settings;
504 settings.physicalDisplay = fullscreenRect();
505 // Here logical space is 2x2
506 settings.clip = Rect(2, 2);
507 settings.globalTransform = transform;
508
509 std::vector<renderengine::LayerSettings> layers;
510
511 renderengine::LayerSettings layerOne;
512 Rect rectOne(0, 0, 1, 1);
513 layerOne.geometry.boundaries = rectOne.toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800514 SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700515 layerOne.alpha = 1.0f;
516
517 renderengine::LayerSettings layerTwo;
518 Rect rectTwo(0, 1, 1, 2);
519 layerTwo.geometry.boundaries = rectTwo.toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800520 SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700521 layerTwo.alpha = 1.0f;
522
523 renderengine::LayerSettings layerThree;
524 Rect rectThree(1, 0, 2, 1);
525 layerThree.geometry.boundaries = rectThree.toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800526 SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700527 layerThree.alpha = 1.0f;
528
529 layers.push_back(layerOne);
530 layers.push_back(layerTwo);
531 layers.push_back(layerThree);
532
533 invokeDraw(settings, layers, mBuffer);
534}
535
536template <typename SourceVariant>
537void RenderEngineTest::fillBufferCheckersRotate0() {
538 fillBufferCheckers<SourceVariant>(mat4());
539 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0,
540 255);
541 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
542 DEFAULT_DISPLAY_HEIGHT / 2),
543 0, 0, 255, 255);
544 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
545 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
546 0, 0, 0, 0);
547 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2,
548 DEFAULT_DISPLAY_HEIGHT),
549 0, 255, 0, 255);
550}
551
552template <typename SourceVariant>
553void RenderEngineTest::fillBufferCheckersRotate90() {
554 mat4 matrix = mat4(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 1);
555 fillBufferCheckers<SourceVariant>(matrix);
556 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 255, 0,
557 255);
558 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
559 DEFAULT_DISPLAY_HEIGHT / 2),
560 255, 0, 0, 255);
561 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
562 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
563 0, 0, 255, 255);
564 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2,
565 DEFAULT_DISPLAY_HEIGHT),
566 0, 0, 0, 0);
567}
568
569template <typename SourceVariant>
570void RenderEngineTest::fillBufferCheckersRotate180() {
571 mat4 matrix = mat4(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 2, 2, 0, 1);
572 fillBufferCheckers<SourceVariant>(matrix);
573 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0,
574 0);
575 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
576 DEFAULT_DISPLAY_HEIGHT / 2),
577 0, 255, 0, 255);
578 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
579 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
580 255, 0, 0, 255);
581 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2,
582 DEFAULT_DISPLAY_HEIGHT),
583 0, 0, 255, 255);
584}
585
586template <typename SourceVariant>
587void RenderEngineTest::fillBufferCheckersRotate270() {
588 mat4 matrix = mat4(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 1);
589 fillBufferCheckers<SourceVariant>(matrix);
590 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255,
591 255);
592 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
593 DEFAULT_DISPLAY_HEIGHT / 2),
594 0, 0, 0, 0);
595 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
596 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
597 0, 255, 0, 255);
598 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2,
599 DEFAULT_DISPLAY_HEIGHT),
600 255, 0, 0, 255);
601}
602
603template <typename SourceVariant>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800604void RenderEngineTest::fillBufferWithLayerTransform() {
Alec Mouri1089aed2018-10-25 21:33:57 -0700605 renderengine::DisplaySettings settings;
606 settings.physicalDisplay = fullscreenRect();
607 // Here logical space is 2x2
608 settings.clip = Rect(2, 2);
609
610 std::vector<renderengine::LayerSettings> layers;
611
612 renderengine::LayerSettings layer;
613 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
614 // Translate one pixel diagonally
615 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 -0800616 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700617 layer.source.solidColor = half3(1.0f, 0.0f, 0.0f);
618 layer.alpha = 1.0f;
619
620 layers.push_back(layer);
621
622 invokeDraw(settings, layers, mBuffer);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800623}
Alec Mouri1089aed2018-10-25 21:33:57 -0700624
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800625template <typename SourceVariant>
626void RenderEngineTest::fillBufferLayerTransform() {
627 fillBufferWithLayerTransform<SourceVariant>();
Alec Mouri1089aed2018-10-25 21:33:57 -0700628 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, 0);
629 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0);
630 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
631 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
632 255, 0, 0, 255);
633}
634
635template <typename SourceVariant>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800636void RenderEngineTest::fillBufferWithColorTransform() {
Alec Mouri1089aed2018-10-25 21:33:57 -0700637 renderengine::DisplaySettings settings;
638 settings.physicalDisplay = fullscreenRect();
639 settings.clip = Rect(1, 1);
640
641 std::vector<renderengine::LayerSettings> layers;
642
643 renderengine::LayerSettings layer;
644 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800645 SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700646 layer.alpha = 1.0f;
647
648 // construct a fake color matrix
649 // annihilate green and blue channels
650 settings.colorTransform = mat4::scale(vec4(1, 0, 0, 1));
651 // set red channel to red + green
652 layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
653
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800654 layer.alpha = 1.0f;
655 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
656
Alec Mouri1089aed2018-10-25 21:33:57 -0700657 layers.push_back(layer);
658
659 invokeDraw(settings, layers, mBuffer);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800660}
Alec Mouri1089aed2018-10-25 21:33:57 -0700661
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800662template <typename SourceVariant>
663void RenderEngineTest::fillBufferColorTransform() {
664 fillBufferWithColorTransform<SourceVariant>();
Alec Mouri1089aed2018-10-25 21:33:57 -0700665 expectBufferColor(fullscreenRect(), 191, 0, 0, 255);
666}
667
Alec Mouri7c94edb2018-12-03 21:23:26 -0800668template <typename SourceVariant>
669void RenderEngineTest::fillRedBufferWithRoundedCorners() {
670 renderengine::DisplaySettings settings;
671 settings.physicalDisplay = fullscreenRect();
672 settings.clip = fullscreenRect();
673
674 std::vector<renderengine::LayerSettings> layers;
675
676 renderengine::LayerSettings layer;
677 layer.geometry.boundaries = fullscreenRect().toFloatRect();
678 layer.geometry.roundedCornersRadius = 5.0f;
679 layer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect();
680 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
681 layer.alpha = 1.0f;
682
683 layers.push_back(layer);
684
685 invokeDraw(settings, layers, mBuffer);
686}
687
688template <typename SourceVariant>
689void RenderEngineTest::fillBufferWithRoundedCorners() {
690 fillRedBufferWithRoundedCorners<SourceVariant>();
691 // Corners should be ignored...
692 expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0);
693 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0);
694 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0);
695 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1,
696 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
697 0, 0, 0, 0);
698 // ...And the non-rounded portion should be red.
699 // Other pixels may be anti-aliased, so let's not check those.
700 expectBufferColor(Rect(5, 5, DEFAULT_DISPLAY_WIDTH - 5, DEFAULT_DISPLAY_HEIGHT - 5), 255, 0, 0,
701 255);
702}
703
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000704template <typename SourceVariant>
705void RenderEngineTest::overlayCorners() {
706 renderengine::DisplaySettings settings;
707 settings.physicalDisplay = fullscreenRect();
708 settings.clip = fullscreenRect();
709
710 std::vector<renderengine::LayerSettings> layersFirst;
711
712 renderengine::LayerSettings layerOne;
713 layerOne.geometry.boundaries =
714 FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0);
715 SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this);
716 layerOne.alpha = 0.2;
717
718 layersFirst.push_back(layerOne);
719 invokeDraw(settings, layersFirst, mBuffer);
720 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51);
721 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1,
722 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
723 0, 0, 0, 0);
724
725 std::vector<renderengine::LayerSettings> layersSecond;
726 renderengine::LayerSettings layerTwo;
727 layerTwo.geometry.boundaries =
728 FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0,
729 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
730 SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this);
731 layerTwo.alpha = 1.0f;
732
733 layersSecond.push_back(layerTwo);
734 invokeDraw(settings, layersSecond, mBuffer);
735
736 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0);
737 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1,
738 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
739 0, 255, 0, 255);
740}
741
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800742void RenderEngineTest::fillRedBufferTextureTransform() {
743 renderengine::DisplaySettings settings;
744 settings.physicalDisplay = fullscreenRect();
745 settings.clip = Rect(1, 1);
746
747 std::vector<renderengine::LayerSettings> layers;
748
749 renderengine::LayerSettings layer;
750 // Here will allocate a checker board texture, but transform texture
751 // coordinates so that only the upper left is applied.
752 sp<GraphicBuffer> buf = allocateSourceBuffer(2, 2);
753 uint32_t texName;
754 RenderEngineTest::sRE->genTextures(1, &texName);
755 this->mTexNames.push_back(texName);
756
757 uint8_t* pixels;
758 buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
759 reinterpret_cast<void**>(&pixels));
760 // Red top left, Green top right, Blue bottom left, Black bottom right
761 pixels[0] = 255;
762 pixels[1] = 0;
763 pixels[2] = 0;
764 pixels[3] = 255;
765 pixels[4] = 0;
766 pixels[5] = 255;
767 pixels[6] = 0;
768 pixels[7] = 255;
769 pixels[8] = 0;
770 pixels[9] = 0;
771 pixels[10] = 255;
772 pixels[11] = 255;
773 buf->unlock();
774
775 layer.source.buffer.buffer = buf;
776 layer.source.buffer.textureName = texName;
777 // Transform coordinates to only be inside the red quadrant.
778 layer.source.buffer.textureTransform = mat4::scale(vec4(0.2, 0.2, 1, 1));
779 layer.alpha = 1.0f;
780 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
781
782 layers.push_back(layer);
783
784 invokeDraw(settings, layers, mBuffer);
785}
786
787void RenderEngineTest::fillBufferTextureTransform() {
788 fillRedBufferTextureTransform();
789 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
790}
791
792void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() {
793 renderengine::DisplaySettings settings;
794 settings.physicalDisplay = fullscreenRect();
795 // Here logical space is 1x1
796 settings.clip = Rect(1, 1);
797
798 std::vector<renderengine::LayerSettings> layers;
799
800 renderengine::LayerSettings layer;
801 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
802 uint32_t texName;
803 RenderEngineTest::sRE->genTextures(1, &texName);
804 this->mTexNames.push_back(texName);
805
806 uint8_t* pixels;
807 buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
808 reinterpret_cast<void**>(&pixels));
809 pixels[0] = 255;
810 pixels[1] = 0;
811 pixels[2] = 0;
812 pixels[3] = 255;
813 buf->unlock();
814
815 layer.source.buffer.buffer = buf;
816 layer.source.buffer.textureName = texName;
817 layer.source.buffer.usePremultipliedAlpha = true;
818 layer.alpha = 0.5f;
819 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
820
821 layers.push_back(layer);
822
823 invokeDraw(settings, layers, mBuffer);
824}
825
826void RenderEngineTest::fillBufferWithPremultiplyAlpha() {
827 fillRedBufferWithPremultiplyAlpha();
828 expectBufferColor(fullscreenRect(), 128, 0, 0, 128);
829}
830
831void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() {
832 renderengine::DisplaySettings settings;
833 settings.physicalDisplay = fullscreenRect();
834 // Here logical space is 1x1
835 settings.clip = Rect(1, 1);
836
837 std::vector<renderengine::LayerSettings> layers;
838
839 renderengine::LayerSettings layer;
840 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
841 uint32_t texName;
842 RenderEngineTest::sRE->genTextures(1, &texName);
843 this->mTexNames.push_back(texName);
844
845 uint8_t* pixels;
846 buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
847 reinterpret_cast<void**>(&pixels));
848 pixels[0] = 255;
849 pixels[1] = 0;
850 pixels[2] = 0;
851 pixels[3] = 255;
852 buf->unlock();
853
854 layer.source.buffer.buffer = buf;
855 layer.source.buffer.textureName = texName;
856 layer.source.buffer.usePremultipliedAlpha = false;
857 layer.alpha = 0.5f;
858 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
859
860 layers.push_back(layer);
861
862 invokeDraw(settings, layers, mBuffer);
863}
864
865void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() {
866 fillRedBufferWithoutPremultiplyAlpha();
867 expectBufferColor(fullscreenRect(), 128, 0, 0, 64, 1);
868}
869
Alec Mouriac335532018-11-12 15:01:33 -0800870void RenderEngineTest::clearLeftRegion() {
871 renderengine::DisplaySettings settings;
872 settings.physicalDisplay = fullscreenRect();
873 // Here logical space is 4x4
874 settings.clip = Rect(4, 4);
875 settings.globalTransform = mat4::scale(vec4(2, 4, 0, 1));
876 settings.clearRegion = Region(Rect(1, 1));
877 std::vector<renderengine::LayerSettings> layers;
878 // dummy layer, without bounds should not render anything
879 renderengine::LayerSettings layer;
880 layers.push_back(layer);
881 invokeDraw(settings, layers, mBuffer);
882}
883
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000884void RenderEngineTest::clearRegion() {
Alec Mouriac335532018-11-12 15:01:33 -0800885 // Reuse mBuffer
886 clearLeftRegion();
887 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 255);
888 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
889 DEFAULT_DISPLAY_HEIGHT),
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000890 0, 0, 0, 0);
Alec Mouriac335532018-11-12 15:01:33 -0800891}
892
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800893template <typename SourceVariant>
894void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer,
895 const renderengine::ShadowSettings& shadow,
896 const ubyte4& casterColor, const ubyte4& backgroundColor) {
897 renderengine::DisplaySettings settings;
898 settings.physicalDisplay = fullscreenRect();
899 settings.clip = fullscreenRect();
900
901 std::vector<renderengine::LayerSettings> layers;
902
903 // add background layer
904 renderengine::LayerSettings bgLayer;
905 bgLayer.geometry.boundaries = fullscreenRect().toFloatRect();
906 ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f,
907 backgroundColor.b / 255.0f, this);
908 bgLayer.alpha = backgroundColor.a / 255.0f;
909 layers.push_back(bgLayer);
910
911 // add shadow layer
912 renderengine::LayerSettings shadowLayer;
913 shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries;
914 shadowLayer.alpha = castingLayer.alpha;
915 shadowLayer.shadow = shadow;
916 layers.push_back(shadowLayer);
917
918 // add layer casting the shadow
919 renderengine::LayerSettings layer = castingLayer;
920 SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f,
921 casterColor.b / 255.0f, this);
922 layers.push_back(layer);
923
924 invokeDraw(settings, layers, mBuffer);
925}
926
Alec Mouri1089aed2018-10-25 21:33:57 -0700927TEST_F(RenderEngineTest, drawLayers_noLayersToDraw) {
928 drawEmptyLayers();
929}
930
Alec Mourid43ccab2019-03-13 12:23:45 -0700931TEST_F(RenderEngineTest, drawLayers_nullOutputBuffer) {
932 renderengine::DisplaySettings settings;
933 std::vector<renderengine::LayerSettings> layers;
934 renderengine::LayerSettings layer;
935 layer.geometry.boundaries = fullscreenRect().toFloatRect();
936 BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
937 layers.push_back(layer);
938 base::unique_fd fence;
Alec Mourife0d72b2019-03-21 14:05:56 -0700939 status_t status = sRE->drawLayers(settings, layers, nullptr, true, base::unique_fd(), &fence);
Alec Mourid43ccab2019-03-13 12:23:45 -0700940
941 ASSERT_EQ(BAD_VALUE, status);
942}
943
944TEST_F(RenderEngineTest, drawLayers_nullOutputFence) {
945 renderengine::DisplaySettings settings;
946 settings.physicalDisplay = fullscreenRect();
947 settings.clip = fullscreenRect();
948
949 std::vector<renderengine::LayerSettings> layers;
950 renderengine::LayerSettings layer;
951 layer.geometry.boundaries = fullscreenRect().toFloatRect();
952 BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
953 layer.alpha = 1.0;
954 layers.push_back(layer);
955
Alec Mourife0d72b2019-03-21 14:05:56 -0700956 status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true,
Alec Mourid43ccab2019-03-13 12:23:45 -0700957 base::unique_fd(), nullptr);
958 sCurrentBuffer = mBuffer;
959 ASSERT_EQ(NO_ERROR, status);
960 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
961}
962
Alec Mourife0d72b2019-03-21 14:05:56 -0700963TEST_F(RenderEngineTest, drawLayers_doesNotCacheFramebuffer) {
964 renderengine::DisplaySettings settings;
965 settings.physicalDisplay = fullscreenRect();
966 settings.clip = fullscreenRect();
967
968 std::vector<renderengine::LayerSettings> layers;
969 renderengine::LayerSettings layer;
970 layer.geometry.boundaries = fullscreenRect().toFloatRect();
971 BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
972 layer.alpha = 1.0;
973 layers.push_back(layer);
974
975 status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), false,
976 base::unique_fd(), nullptr);
977 sCurrentBuffer = mBuffer;
978 ASSERT_EQ(NO_ERROR, status);
979 ASSERT_FALSE(sRE->isFramebufferImageCachedForTesting(mBuffer->getId()));
980 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
981}
982
Alec Mouri1089aed2018-10-25 21:33:57 -0700983TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) {
984 fillRedBuffer<ColorSourceVariant>();
985}
986
987TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) {
988 fillGreenBuffer<ColorSourceVariant>();
989}
990
991TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) {
992 fillBlueBuffer<ColorSourceVariant>();
993}
994
995TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) {
996 fillRedTransparentBuffer<ColorSourceVariant>();
997}
998
999TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) {
1000 fillBufferPhysicalOffset<ColorSourceVariant>();
1001}
1002
1003TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) {
1004 fillBufferCheckersRotate0<ColorSourceVariant>();
1005}
1006
1007TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) {
1008 fillBufferCheckersRotate90<ColorSourceVariant>();
1009}
1010
1011TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) {
1012 fillBufferCheckersRotate180<ColorSourceVariant>();
1013}
1014
1015TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) {
1016 fillBufferCheckersRotate270<ColorSourceVariant>();
1017}
1018
1019TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) {
1020 fillBufferLayerTransform<ColorSourceVariant>();
1021}
1022
1023TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) {
1024 fillBufferLayerTransform<ColorSourceVariant>();
Alec Mouri6e57f682018-09-29 20:45:08 -07001025}
1026
Alec Mouri7c94edb2018-12-03 21:23:26 -08001027TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) {
1028 fillBufferWithRoundedCorners<ColorSourceVariant>();
1029}
1030
Alec Mourie7d1d4a2019-02-05 01:13:46 +00001031TEST_F(RenderEngineTest, drawLayers_overlayCorners_colorSource) {
1032 overlayCorners<ColorSourceVariant>();
1033}
1034
Alec Mouri0d5e1eb2018-11-10 20:40:12 -08001035TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) {
1036 fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1037}
1038
1039TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) {
1040 fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1041}
1042
1043TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) {
1044 fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1045}
1046
1047TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) {
1048 fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1049}
1050
1051TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) {
1052 fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1053}
1054
1055TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) {
1056 fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1057}
1058
1059TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) {
1060 fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1061}
1062
1063TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) {
1064 fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1065}
1066
1067TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) {
1068 fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1069}
1070
1071TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) {
1072 fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1073}
1074
1075TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) {
1076 fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1077}
1078
Alec Mouri7c94edb2018-12-03 21:23:26 -08001079TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) {
1080 fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1081}
1082
Alec Mourie7d1d4a2019-02-05 01:13:46 +00001083TEST_F(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) {
1084 overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1085}
1086
Alec Mouri0d5e1eb2018-11-10 20:40:12 -08001087TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) {
1088 fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1089}
1090
1091TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) {
1092 fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1093}
1094
1095TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) {
1096 fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1097}
1098
1099TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) {
1100 fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1101}
1102
1103TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) {
1104 fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1105}
1106
1107TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) {
1108 fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1109}
1110
1111TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) {
1112 fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1113}
1114
1115TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) {
1116 fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1117}
1118
1119TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) {
1120 fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1121}
1122
1123TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) {
1124 fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1125}
1126
1127TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) {
1128 fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1129}
1130
Alec Mouri7c94edb2018-12-03 21:23:26 -08001131TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) {
1132 fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1133}
1134
Alec Mourie7d1d4a2019-02-05 01:13:46 +00001135TEST_F(RenderEngineTest, drawLayers_overlayCorners_bufferSource) {
1136 overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1137}
1138
Alec Mouri0d5e1eb2018-11-10 20:40:12 -08001139TEST_F(RenderEngineTest, drawLayers_fillBufferTextureTransform) {
1140 fillBufferTextureTransform();
1141}
1142
1143TEST_F(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) {
1144 fillBufferWithPremultiplyAlpha();
1145}
1146
1147TEST_F(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) {
1148 fillBufferWithoutPremultiplyAlpha();
1149}
1150
Alec Mourie7d1d4a2019-02-05 01:13:46 +00001151TEST_F(RenderEngineTest, drawLayers_clearRegion) {
1152 clearRegion();
Alec Mouriac335532018-11-12 15:01:33 -08001153}
1154
Alec Mourid43ccab2019-03-13 12:23:45 -07001155TEST_F(RenderEngineTest, drawLayers_fillsBufferAndCachesImages) {
1156 renderengine::DisplaySettings settings;
1157 settings.physicalDisplay = fullscreenRect();
1158 settings.clip = fullscreenRect();
1159
1160 std::vector<renderengine::LayerSettings> layers;
1161
1162 renderengine::LayerSettings layer;
1163 layer.geometry.boundaries = fullscreenRect().toFloatRect();
1164 BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
1165
1166 layers.push_back(layer);
1167 invokeDraw(settings, layers, mBuffer);
1168 uint64_t bufferId = layer.source.buffer.buffer->getId();
1169 EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001170 std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier =
1171 sRE->unbindExternalTextureBufferForTesting(bufferId);
1172 std::lock_guard<std::mutex> lock(barrier->mutex);
1173 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1174 [&]() REQUIRES(barrier->mutex) {
1175 return barrier->isOpen;
1176 }));
Alec Mourid43ccab2019-03-13 12:23:45 -07001177 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001178 EXPECT_EQ(NO_ERROR, barrier->result);
Alec Mourid43ccab2019-03-13 12:23:45 -07001179}
1180
1181TEST_F(RenderEngineTest, drawLayers_bindExternalBufferWithNullBuffer) {
1182 status_t result = sRE->bindExternalTextureBuffer(0, nullptr, nullptr);
1183 ASSERT_EQ(BAD_VALUE, result);
1184}
1185
1186TEST_F(RenderEngineTest, drawLayers_bindExternalBufferCachesImages) {
1187 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
1188 uint32_t texName;
1189 sRE->genTextures(1, &texName);
1190 mTexNames.push_back(texName);
1191
1192 sRE->bindExternalTextureBuffer(texName, buf, nullptr);
1193 uint64_t bufferId = buf->getId();
1194 EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001195 std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier =
1196 sRE->unbindExternalTextureBufferForTesting(bufferId);
1197 std::lock_guard<std::mutex> lock(barrier->mutex);
1198 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1199 [&]() REQUIRES(barrier->mutex) {
1200 return barrier->isOpen;
1201 }));
1202 EXPECT_EQ(NO_ERROR, barrier->result);
Alec Mourid43ccab2019-03-13 12:23:45 -07001203 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
1204}
1205
Alec Mourid7b3a8b2019-03-21 11:44:18 -07001206TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferWithNullBuffer) {
Alec Mouri16a99402019-07-29 16:37:30 -07001207 std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier =
1208 sRE->cacheExternalTextureBufferForTesting(nullptr);
1209 std::lock_guard<std::mutex> lock(barrier->mutex);
1210 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1211 [&]() REQUIRES(barrier->mutex) {
1212 return barrier->isOpen;
1213 }));
1214 EXPECT_TRUE(barrier->isOpen);
1215 EXPECT_EQ(BAD_VALUE, barrier->result);
Alec Mourid7b3a8b2019-03-21 11:44:18 -07001216}
1217
1218TEST_F(RenderEngineTest, drawLayers_cacheExternalBufferCachesImages) {
1219 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
1220 uint64_t bufferId = buf->getId();
Alec Mouri16a99402019-07-29 16:37:30 -07001221 std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier =
1222 sRE->cacheExternalTextureBufferForTesting(buf);
1223 {
1224 std::lock_guard<std::mutex> lock(barrier->mutex);
1225 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1226 [&]() REQUIRES(barrier->mutex) {
1227 return barrier->isOpen;
1228 }));
1229 EXPECT_EQ(NO_ERROR, barrier->result);
1230 }
Alec Mourid7b3a8b2019-03-21 11:44:18 -07001231 EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001232 barrier = sRE->unbindExternalTextureBufferForTesting(bufferId);
1233 {
1234 std::lock_guard<std::mutex> lock(barrier->mutex);
1235 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1236 [&]() REQUIRES(barrier->mutex) {
1237 return barrier->isOpen;
1238 }));
1239 EXPECT_EQ(NO_ERROR, barrier->result);
1240 }
Alec Mourid7b3a8b2019-03-21 11:44:18 -07001241 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
1242}
1243
Vishnu Nair16efdbf2019-12-10 11:55:42 -08001244TEST_F(RenderEngineTest, drawLayers_fillShadow_casterLayerMinSize) {
1245 const ubyte4 casterColor(255, 0, 0, 255);
1246 const ubyte4 backgroundColor(255, 255, 255, 255);
1247 const float shadowLength = 5.0f;
1248 Rect casterBounds(1, 1);
1249 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1250 renderengine::LayerSettings castingLayer;
1251 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1252 castingLayer.alpha = 1.0f;
1253 renderengine::ShadowSettings settings =
1254 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1255 false /* casterIsTranslucent */);
1256
1257 drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor);
1258 expectShadowColor(castingLayer, settings, casterColor, backgroundColor);
1259}
1260
1261TEST_F(RenderEngineTest, drawLayers_fillShadow_casterColorLayer) {
1262 const ubyte4 casterColor(255, 0, 0, 255);
1263 const ubyte4 backgroundColor(255, 255, 255, 255);
1264 const float shadowLength = 5.0f;
1265 Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f);
1266 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1267 renderengine::LayerSettings castingLayer;
1268 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1269 castingLayer.alpha = 1.0f;
1270 renderengine::ShadowSettings settings =
1271 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1272 false /* casterIsTranslucent */);
1273
1274 drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor);
1275 expectShadowColor(castingLayer, settings, casterColor, backgroundColor);
1276}
1277
1278TEST_F(RenderEngineTest, drawLayers_fillShadow_casterOpaqueBufferLayer) {
1279 const ubyte4 casterColor(255, 0, 0, 255);
1280 const ubyte4 backgroundColor(255, 255, 255, 255);
1281 const float shadowLength = 5.0f;
1282 Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f);
1283 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1284 renderengine::LayerSettings castingLayer;
1285 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1286 castingLayer.alpha = 1.0f;
1287 renderengine::ShadowSettings settings =
1288 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1289 false /* casterIsTranslucent */);
1290
1291 drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor,
1292 backgroundColor);
1293 expectShadowColor(castingLayer, settings, casterColor, backgroundColor);
1294}
1295
1296TEST_F(RenderEngineTest, drawLayers_fillShadow_casterWithRoundedCorner) {
1297 const ubyte4 casterColor(255, 0, 0, 255);
1298 const ubyte4 backgroundColor(255, 255, 255, 255);
1299 const float shadowLength = 5.0f;
1300 Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f);
1301 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1302 renderengine::LayerSettings castingLayer;
1303 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1304 castingLayer.geometry.roundedCornersRadius = 3.0f;
1305 castingLayer.geometry.roundedCornersCrop = casterBounds.toFloatRect();
1306 castingLayer.alpha = 1.0f;
1307 renderengine::ShadowSettings settings =
1308 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1309 false /* casterIsTranslucent */);
1310
1311 drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor,
1312 backgroundColor);
1313 expectShadowColor(castingLayer, settings, casterColor, backgroundColor);
1314}
1315
1316TEST_F(RenderEngineTest, drawLayers_fillShadow_translucentCasterWithAlpha) {
1317 const ubyte4 casterColor(255, 0, 0, 255);
1318 const ubyte4 backgroundColor(255, 255, 255, 255);
1319 const float shadowLength = 5.0f;
1320 Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f);
1321 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1322 renderengine::LayerSettings castingLayer;
1323 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1324 castingLayer.alpha = 0.5f;
1325 renderengine::ShadowSettings settings =
1326 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1327 true /* casterIsTranslucent */);
1328
1329 drawShadow<BufferSourceVariant<RelaxOpaqueBufferVariant>>(castingLayer, settings, casterColor,
1330 backgroundColor);
1331
1332 // verify only the background since the shadow will draw behind the caster
1333 const float shadowInset = settings.length * -1.0f;
1334 const Rect casterWithShadow =
1335 Rect(casterBounds).inset(shadowInset, shadowInset, shadowInset, shadowInset);
1336 const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow);
1337 expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b,
1338 backgroundColor.a);
1339}
1340
Alec Mouri6e57f682018-09-29 20:45:08 -07001341} // namespace android