blob: a720a27ed9e3f8304a68f155b162565d660036c0 [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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Alec Mouri16a99402019-07-29 16:37:30 -070021#include <chrono>
22#include <condition_variable>
Vishnu Nair16efdbf2019-12-10 11:55:42 -080023#include <fstream>
Alec Mouri6e57f682018-09-29 20:45:08 -070024
Alec Mouri16a99402019-07-29 16:37:30 -070025#include <gtest/gtest.h>
Lucas Dupin19c8f0e2019-11-25 17:55:44 -080026#include <cutils/properties.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070027#include <renderengine/RenderEngine.h>
Alec Mouri1089aed2018-10-25 21:33:57 -070028#include <sync/sync.h>
Alec Mouri6e57f682018-09-29 20:45:08 -070029#include <ui/PixelFormat.h>
Alec Mourid43ccab2019-03-13 12:23:45 -070030#include "../gl/GLESRenderEngine.h"
Alec Mouri6e57f682018-09-29 20:45:08 -070031
Alec Mouri1089aed2018-10-25 21:33:57 -070032constexpr int DEFAULT_DISPLAY_WIDTH = 128;
33constexpr int DEFAULT_DISPLAY_HEIGHT = 256;
34constexpr int DEFAULT_DISPLAY_OFFSET = 64;
Vishnu Nair16efdbf2019-12-10 11:55:42 -080035constexpr bool WRITE_BUFFER_TO_FILE_ON_FAILURE = false;
Alec Mouri1089aed2018-10-25 21:33:57 -070036
Alec Mouri6e57f682018-09-29 20:45:08 -070037namespace android {
38
Alec Mouri1089aed2018-10-25 21:33:57 -070039struct RenderEngineTest : public ::testing::Test {
Alec Mourid43ccab2019-03-13 12:23:45 -070040 static void SetUpTestSuite() {
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +080041 renderengine::RenderEngineCreationArgs reCreationArgs =
42 renderengine::RenderEngineCreationArgs::Builder()
43 .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888))
44 .setImageCacheSize(1)
45 .setUseColorManagerment(false)
46 .setEnableProtectedContext(false)
47 .setPrecacheToneMapperShaderOnly(false)
48 .setSupportsBackgroundBlur(true)
49 .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM)
50 .build();
51 sRE = renderengine::gl::GLESRenderEngine::create(reCreationArgs);
52
53 reCreationArgs.useColorManagement = true;
54 sRECM = renderengine::gl::GLESRenderEngine::create(reCreationArgs);
Alec Mourid43ccab2019-03-13 12:23:45 -070055 }
56
57 static void TearDownTestSuite() {
58 // The ordering here is important - sCurrentBuffer must live longer
59 // than RenderEngine to avoid a null reference on tear-down.
60 sRE = nullptr;
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +080061 sRECM = nullptr;
Alec Mourid43ccab2019-03-13 12:23:45 -070062 sCurrentBuffer = nullptr;
63 }
64
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080065 static sp<GraphicBuffer> allocateDefaultBuffer() {
Alec Mouri1089aed2018-10-25 21:33:57 -070066 return new GraphicBuffer(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT,
67 HAL_PIXEL_FORMAT_RGBA_8888, 1,
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080068 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
69 GRALLOC_USAGE_HW_RENDER,
Alec Mouri1089aed2018-10-25 21:33:57 -070070 "output");
Alec Mouri6e57f682018-09-29 20:45:08 -070071 }
72
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080073 // Allocates a 1x1 buffer to fill with a solid color
74 static sp<GraphicBuffer> allocateSourceBuffer(uint32_t width, uint32_t height) {
75 return new GraphicBuffer(width, height, HAL_PIXEL_FORMAT_RGBA_8888, 1,
76 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN |
77 GRALLOC_USAGE_HW_TEXTURE,
78 "input");
79 }
80
Alec Mouri1089aed2018-10-25 21:33:57 -070081 RenderEngineTest() { mBuffer = allocateDefaultBuffer(); }
82
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080083 ~RenderEngineTest() {
Vishnu Nair16efdbf2019-12-10 11:55:42 -080084 if (WRITE_BUFFER_TO_FILE_ON_FAILURE && ::testing::Test::HasFailure()) {
85 writeBufferToFile("/data/texture_out_");
86 }
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080087 for (uint32_t texName : mTexNames) {
88 sRE->deleteTextures(1, &texName);
89 }
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +080090 for (uint32_t texName : mTexNamesCM) {
91 sRECM->deleteTextures(1, &texName);
92 }
Alec Mouri0d5e1eb2018-11-10 20:40:12 -080093 }
94
Vishnu Nair16efdbf2019-12-10 11:55:42 -080095 void writeBufferToFile(const char* basename) {
96 std::string filename(basename);
97 filename.append(::testing::UnitTest::GetInstance()->current_test_info()->name());
98 filename.append(".ppm");
99 std::ofstream file(filename.c_str(), std::ios::binary);
100 if (!file.is_open()) {
101 ALOGE("Unable to open file: %s", filename.c_str());
102 ALOGE("You may need to do: \"adb shell setenforce 0\" to enable "
103 "surfaceflinger to write debug images");
104 return;
105 }
106
Alec Mouri1089aed2018-10-25 21:33:57 -0700107 uint8_t* pixels;
108 mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
109 reinterpret_cast<void**>(&pixels));
110
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800111 file << "P6\n";
112 file << mBuffer->getWidth() << "\n";
113 file << mBuffer->getHeight() << "\n";
114 file << 255 << "\n";
115
116 std::vector<uint8_t> outBuffer(mBuffer->getWidth() * mBuffer->getHeight() * 3);
117 auto outPtr = reinterpret_cast<uint8_t*>(outBuffer.data());
118
119 for (int32_t j = 0; j < mBuffer->getHeight(); j++) {
120 const uint8_t* src = pixels + (mBuffer->getStride() * j) * 4;
121 for (int32_t i = 0; i < mBuffer->getWidth(); i++) {
122 // Only copy R, G and B components
123 outPtr[0] = src[0];
124 outPtr[1] = src[1];
125 outPtr[2] = src[2];
126 outPtr += 3;
127
128 src += 4;
129 }
130 }
131 file.write(reinterpret_cast<char*>(outBuffer.data()), outBuffer.size());
132 mBuffer->unlock();
133 }
134
135 void expectBufferColor(const Region& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
136 size_t c;
137 Rect const* rect = region.getArray(&c);
138 for (size_t i = 0; i < c; i++, rect++) {
139 expectBufferColor(*rect, r, g, b, a);
140 }
141 }
142
143 void expectBufferColor(const Rect& rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a,
144 uint8_t tolerance = 0) {
145 auto colorCompare = [tolerance](const uint8_t* colorA, const uint8_t* colorB) {
146 auto colorBitCompare = [tolerance](uint8_t a, uint8_t b) {
147 uint8_t tmp = a >= b ? a - b : b - a;
148 return tmp <= tolerance;
149 };
150 return std::equal(colorA, colorA + 4, colorB, colorBitCompare);
Alec Mouri1089aed2018-10-25 21:33:57 -0700151 };
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800152
153 expectBufferColor(rect, r, g, b, a, colorCompare);
154 }
155
156 void expectBufferColor(const Rect& region, uint8_t r, uint8_t g, uint8_t b, uint8_t a,
157 std::function<bool(const uint8_t* a, const uint8_t* b)> colorCompare) {
158 uint8_t* pixels;
159 mBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
160 reinterpret_cast<void**>(&pixels));
Alec Mouri1089aed2018-10-25 21:33:57 -0700161 int32_t maxFails = 10;
162 int32_t fails = 0;
163 for (int32_t j = 0; j < region.getHeight(); j++) {
164 const uint8_t* src =
165 pixels + (mBuffer->getStride() * (region.top + j) + region.left) * 4;
166 for (int32_t i = 0; i < region.getWidth(); i++) {
167 const uint8_t expected[4] = {r, g, b, a};
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800168 bool equal = colorCompare(src, expected);
Alec Mouri1089aed2018-10-25 21:33:57 -0700169 EXPECT_TRUE(equal)
170 << "pixel @ (" << region.left + i << ", " << region.top + j << "): "
171 << "expected (" << static_cast<uint32_t>(r) << ", "
172 << static_cast<uint32_t>(g) << ", " << static_cast<uint32_t>(b) << ", "
173 << static_cast<uint32_t>(a) << "), "
174 << "got (" << static_cast<uint32_t>(src[0]) << ", "
175 << static_cast<uint32_t>(src[1]) << ", " << static_cast<uint32_t>(src[2])
176 << ", " << static_cast<uint32_t>(src[3]) << ")";
177 src += 4;
178 if (!equal && ++fails >= maxFails) {
179 break;
180 }
181 }
182 if (fails >= maxFails) {
183 break;
184 }
185 }
186 mBuffer->unlock();
187 }
188
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800189 void expectAlpha(const Rect& rect, uint8_t a) {
190 auto colorCompare = [](const uint8_t* colorA, const uint8_t* colorB) {
191 return colorA[3] == colorB[3];
192 };
193 expectBufferColor(rect, 0.0f /* r */, 0.0f /*g */, 0.0f /* b */, a, colorCompare);
194 }
195
196 void expectShadowColor(const renderengine::LayerSettings& castingLayer,
197 const renderengine::ShadowSettings& shadow, const ubyte4& casterColor,
198 const ubyte4& backgroundColor) {
199 const Rect casterRect(castingLayer.geometry.boundaries);
200 Region casterRegion = Region(casterRect);
201 const float casterCornerRadius = castingLayer.geometry.roundedCornersRadius;
202 if (casterCornerRadius > 0.0f) {
203 // ignore the corners if a corner radius is set
204 Rect cornerRect(casterCornerRadius, casterCornerRadius);
205 casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.left, casterRect.top));
206 casterRegion.subtractSelf(
207 cornerRect.offsetTo(casterRect.right - casterCornerRadius, casterRect.top));
208 casterRegion.subtractSelf(
209 cornerRect.offsetTo(casterRect.left, casterRect.bottom - casterCornerRadius));
210 casterRegion.subtractSelf(cornerRect.offsetTo(casterRect.right - casterCornerRadius,
211 casterRect.bottom - casterCornerRadius));
212 }
213
214 const float shadowInset = shadow.length * -1.0f;
215 const Rect casterWithShadow =
216 Rect(casterRect).inset(shadowInset, shadowInset, shadowInset, shadowInset);
217 const Region shadowRegion = Region(casterWithShadow).subtractSelf(casterRect);
218 const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow);
219
220 // verify casting layer
221 expectBufferColor(casterRegion, casterColor.r, casterColor.g, casterColor.b, casterColor.a);
222
223 // verify shadows by testing just the alpha since its difficult to validate the shadow color
224 size_t c;
225 Rect const* r = shadowRegion.getArray(&c);
226 for (size_t i = 0; i < c; i++, r++) {
227 expectAlpha(*r, 255);
228 }
229
230 // verify background
231 expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b,
232 backgroundColor.a);
233 }
234
235 static renderengine::ShadowSettings getShadowSettings(const vec2& casterPos, float shadowLength,
236 bool casterIsTranslucent) {
237 renderengine::ShadowSettings shadow;
238 shadow.ambientColor = {0.0f, 0.0f, 0.0f, 0.039f};
239 shadow.spotColor = {0.0f, 0.0f, 0.0f, 0.19f};
240 shadow.lightPos = vec3(casterPos.x, casterPos.y, 0);
241 shadow.lightRadius = 0.0f;
242 shadow.length = shadowLength;
243 shadow.casterIsTranslucent = casterIsTranslucent;
244 return shadow;
245 }
246
Alec Mouri1089aed2018-10-25 21:33:57 -0700247 static Rect fullscreenRect() { return Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); }
248
249 static Rect offsetRect() {
250 return Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH,
251 DEFAULT_DISPLAY_HEIGHT);
252 }
253
254 static Rect offsetRectAtZero() {
255 return Rect(DEFAULT_DISPLAY_WIDTH - DEFAULT_DISPLAY_OFFSET,
256 DEFAULT_DISPLAY_HEIGHT - DEFAULT_DISPLAY_OFFSET);
257 }
258
Alec Mourid43ccab2019-03-13 12:23:45 -0700259 void invokeDraw(renderengine::DisplaySettings settings,
Vishnu Nair9b079a22020-01-21 14:36:08 -0800260 std::vector<const renderengine::LayerSettings*> layers,
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800261 sp<GraphicBuffer> buffer,
262 bool useColorManagement = false) {
Alec Mouri1089aed2018-10-25 21:33:57 -0700263 base::unique_fd fence;
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800264 status_t status = useColorManagement ?
265 sRECM ->drawLayers(settings, layers, buffer->getNativeBuffer(), true,
266 base::unique_fd(), &fence) :
267 sRE->drawLayers(settings, layers, buffer->getNativeBuffer(), true,
Alec Mouri6338c9d2019-02-07 16:57:51 -0800268 base::unique_fd(), &fence);
Alec Mourid43ccab2019-03-13 12:23:45 -0700269 sCurrentBuffer = buffer;
Alec Mouri1089aed2018-10-25 21:33:57 -0700270
271 int fd = fence.release();
272 if (fd >= 0) {
273 sync_wait(fd, -1);
274 close(fd);
275 }
276
277 ASSERT_EQ(NO_ERROR, status);
Alec Mourid43ccab2019-03-13 12:23:45 -0700278 if (layers.size() > 0) {
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800279 if (useColorManagement) {
280 ASSERT_TRUE(sRECM->isFramebufferImageCachedForTesting(buffer->getId()));
281 } else {
282 ASSERT_TRUE(sRE->isFramebufferImageCachedForTesting(buffer->getId()));
283 }
Alec Mourid43ccab2019-03-13 12:23:45 -0700284 }
Alec Mouri1089aed2018-10-25 21:33:57 -0700285 }
286
Alec Mourid43ccab2019-03-13 12:23:45 -0700287 void drawEmptyLayers() {
Alec Mouri6e57f682018-09-29 20:45:08 -0700288 renderengine::DisplaySettings settings;
Vishnu Nair9b079a22020-01-21 14:36:08 -0800289 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri6e57f682018-09-29 20:45:08 -0700290 // Meaningless buffer since we don't do any drawing
291 sp<GraphicBuffer> buffer = new GraphicBuffer();
Alec Mouri1089aed2018-10-25 21:33:57 -0700292 invokeDraw(settings, layers, buffer);
Alec Mouri6e57f682018-09-29 20:45:08 -0700293 }
294
Alec Mouri1089aed2018-10-25 21:33:57 -0700295 template <typename SourceVariant>
296 void fillBuffer(half r, half g, half b, half a);
297
298 template <typename SourceVariant>
299 void fillRedBuffer();
300
301 template <typename SourceVariant>
302 void fillGreenBuffer();
303
304 template <typename SourceVariant>
305 void fillBlueBuffer();
306
307 template <typename SourceVariant>
308 void fillRedTransparentBuffer();
309
310 template <typename SourceVariant>
311 void fillRedOffsetBuffer();
312
313 template <typename SourceVariant>
314 void fillBufferPhysicalOffset();
315
316 template <typename SourceVariant>
Alec Mouri5a6d8572020-03-23 23:56:15 -0700317 void fillBufferCheckers(uint32_t rotation);
Alec Mouri1089aed2018-10-25 21:33:57 -0700318
319 template <typename SourceVariant>
320 void fillBufferCheckersRotate0();
321
322 template <typename SourceVariant>
323 void fillBufferCheckersRotate90();
324
325 template <typename SourceVariant>
326 void fillBufferCheckersRotate180();
327
328 template <typename SourceVariant>
329 void fillBufferCheckersRotate270();
330
331 template <typename SourceVariant>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800332 void fillBufferWithLayerTransform();
333
334 template <typename SourceVariant>
Alec Mouri1089aed2018-10-25 21:33:57 -0700335 void fillBufferLayerTransform();
336
337 template <typename SourceVariant>
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800338 void fillBufferWithColorTransform(bool useColorManagement = false);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800339
340 template <typename SourceVariant>
Alec Mouri1089aed2018-10-25 21:33:57 -0700341 void fillBufferColorTransform();
342
Alec Mouri7c94edb2018-12-03 21:23:26 -0800343 template <typename SourceVariant>
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800344 void fillBufferColorTransformCM();
345
346 template <typename SourceVariant>
Alec Mouri7c94edb2018-12-03 21:23:26 -0800347 void fillRedBufferWithRoundedCorners();
348
349 template <typename SourceVariant>
350 void fillBufferWithRoundedCorners();
351
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000352 template <typename SourceVariant>
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800353 void fillBufferAndBlurBackground();
354
355 template <typename SourceVariant>
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000356 void overlayCorners();
357
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800358 void fillRedBufferTextureTransform();
359
360 void fillBufferTextureTransform();
361
362 void fillRedBufferWithPremultiplyAlpha();
363
364 void fillBufferWithPremultiplyAlpha();
365
366 void fillRedBufferWithoutPremultiplyAlpha();
367
368 void fillBufferWithoutPremultiplyAlpha();
369
Alec Mouriac335532018-11-12 15:01:33 -0800370 void fillGreenColorBufferThenClearRegion();
371
372 void clearLeftRegion();
373
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000374 void clearRegion();
Alec Mouriac335532018-11-12 15:01:33 -0800375
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800376 template <typename SourceVariant>
377 void drawShadow(const renderengine::LayerSettings& castingLayer,
378 const renderengine::ShadowSettings& shadow, const ubyte4& casterColor,
379 const ubyte4& backgroundColor);
380
Alec Mourid43ccab2019-03-13 12:23:45 -0700381 // Keep around the same renderengine object to save on initialization time.
382 // For now, exercise the GL backend directly so that some caching specifics
383 // can be tested without changing the interface.
384 static std::unique_ptr<renderengine::gl::GLESRenderEngine> sRE;
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800385 // renderengine object with Color Management enabled
386 static std::unique_ptr<renderengine::gl::GLESRenderEngine> sRECM;
Alec Mourid43ccab2019-03-13 12:23:45 -0700387 // Dumb hack to avoid NPE in the EGL driver: the GraphicBuffer needs to
388 // be freed *after* RenderEngine is destroyed, so that the EGL image is
389 // destroyed first.
390 static sp<GraphicBuffer> sCurrentBuffer;
Alec Mouri1089aed2018-10-25 21:33:57 -0700391
392 sp<GraphicBuffer> mBuffer;
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800393
394 std::vector<uint32_t> mTexNames;
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800395 std::vector<uint32_t> mTexNamesCM;
Alec Mouri6e57f682018-09-29 20:45:08 -0700396};
397
Alec Mourid43ccab2019-03-13 12:23:45 -0700398std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRE = nullptr;
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800399std::unique_ptr<renderengine::gl::GLESRenderEngine> RenderEngineTest::sRECM = nullptr;
400
Alec Mourid43ccab2019-03-13 12:23:45 -0700401sp<GraphicBuffer> RenderEngineTest::sCurrentBuffer = nullptr;
Alec Mouri1089aed2018-10-25 21:33:57 -0700402
403struct ColorSourceVariant {
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800404 static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b,
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800405 RenderEngineTest* /*fixture*/, bool /*useColorManagement*/ = false) {
Alec Mouri1089aed2018-10-25 21:33:57 -0700406 layer.source.solidColor = half3(r, g, b);
407 }
408};
409
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800410struct RelaxOpaqueBufferVariant {
411 static void setOpaqueBit(renderengine::LayerSettings& layer) {
412 layer.source.buffer.isOpaque = false;
413 }
414
415 static uint8_t getAlphaChannel() { return 255; }
416};
417
418struct ForceOpaqueBufferVariant {
419 static void setOpaqueBit(renderengine::LayerSettings& layer) {
420 layer.source.buffer.isOpaque = true;
421 }
422
423 static uint8_t getAlphaChannel() {
424 // The isOpaque bit will override the alpha channel, so this should be
425 // arbitrary.
426 return 10;
427 }
428};
429
430template <typename OpaquenessVariant>
431struct BufferSourceVariant {
432 static void fillColor(renderengine::LayerSettings& layer, half r, half g, half b,
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800433 RenderEngineTest* fixture,
434 bool useColorManagement = false) {
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800435 sp<GraphicBuffer> buf = RenderEngineTest::allocateSourceBuffer(1, 1);
436 uint32_t texName;
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800437 if (useColorManagement) {
438 fixture->sRECM->genTextures(1, &texName);
439 fixture->mTexNamesCM.push_back(texName);
440 } else {
441 fixture->sRE->genTextures(1, &texName);
442 fixture->mTexNames.push_back(texName);
443 }
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800444
445 uint8_t* pixels;
446 buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
447 reinterpret_cast<void**>(&pixels));
448
449 for (int32_t j = 0; j < buf->getHeight(); j++) {
450 uint8_t* iter = pixels + (buf->getStride() * j) * 4;
451 for (int32_t i = 0; i < buf->getWidth(); i++) {
452 iter[0] = uint8_t(r * 255);
453 iter[1] = uint8_t(g * 255);
454 iter[2] = uint8_t(b * 255);
455 iter[3] = OpaquenessVariant::getAlphaChannel();
456 iter += 4;
457 }
458 }
459
460 buf->unlock();
461
462 layer.source.buffer.buffer = buf;
463 layer.source.buffer.textureName = texName;
464 OpaquenessVariant::setOpaqueBit(layer);
465 }
466};
467
Alec Mouri1089aed2018-10-25 21:33:57 -0700468template <typename SourceVariant>
469void RenderEngineTest::fillBuffer(half r, half g, half b, half a) {
470 renderengine::DisplaySettings settings;
471 settings.physicalDisplay = fullscreenRect();
472 settings.clip = fullscreenRect();
473
Vishnu Nair9b079a22020-01-21 14:36:08 -0800474 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri1089aed2018-10-25 21:33:57 -0700475
476 renderengine::LayerSettings layer;
477 layer.geometry.boundaries = fullscreenRect().toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800478 SourceVariant::fillColor(layer, r, g, b, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700479 layer.alpha = a;
480
Vishnu Nair9b079a22020-01-21 14:36:08 -0800481 layers.push_back(&layer);
Alec Mouri1089aed2018-10-25 21:33:57 -0700482
483 invokeDraw(settings, layers, mBuffer);
484}
485
486template <typename SourceVariant>
487void RenderEngineTest::fillRedBuffer() {
488 fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, 1.0f);
489 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
490}
491
492template <typename SourceVariant>
493void RenderEngineTest::fillGreenBuffer() {
494 fillBuffer<SourceVariant>(0.0f, 1.0f, 0.0f, 1.0f);
495 expectBufferColor(fullscreenRect(), 0, 255, 0, 255);
496}
497
498template <typename SourceVariant>
499void RenderEngineTest::fillBlueBuffer() {
500 fillBuffer<SourceVariant>(0.0f, 0.0f, 1.0f, 1.0f);
501 expectBufferColor(fullscreenRect(), 0, 0, 255, 255);
502}
503
504template <typename SourceVariant>
505void RenderEngineTest::fillRedTransparentBuffer() {
506 fillBuffer<SourceVariant>(1.0f, 0.0f, 0.0f, .2f);
507 expectBufferColor(fullscreenRect(), 51, 0, 0, 51);
508}
509
510template <typename SourceVariant>
511void RenderEngineTest::fillRedOffsetBuffer() {
512 renderengine::DisplaySettings settings;
513 settings.physicalDisplay = offsetRect();
514 settings.clip = offsetRectAtZero();
515
Vishnu Nair9b079a22020-01-21 14:36:08 -0800516 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri1089aed2018-10-25 21:33:57 -0700517
518 renderengine::LayerSettings layer;
519 layer.geometry.boundaries = offsetRectAtZero().toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800520 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700521 layer.alpha = 1.0f;
522
Vishnu Nair9b079a22020-01-21 14:36:08 -0800523 layers.push_back(&layer);
Alec Mouri1089aed2018-10-25 21:33:57 -0700524 invokeDraw(settings, layers, mBuffer);
525}
526
527template <typename SourceVariant>
528void RenderEngineTest::fillBufferPhysicalOffset() {
529 fillRedOffsetBuffer<SourceVariant>();
530
531 expectBufferColor(Rect(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_WIDTH,
532 DEFAULT_DISPLAY_HEIGHT),
533 255, 0, 0, 255);
534 Rect offsetRegionLeft(DEFAULT_DISPLAY_OFFSET, DEFAULT_DISPLAY_HEIGHT);
535 Rect offsetRegionTop(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_OFFSET);
536
537 expectBufferColor(offsetRegionLeft, 0, 0, 0, 0);
538 expectBufferColor(offsetRegionTop, 0, 0, 0, 0);
539}
540
541template <typename SourceVariant>
Alec Mouri5a6d8572020-03-23 23:56:15 -0700542void RenderEngineTest::fillBufferCheckers(uint32_t orientationFlag) {
Alec Mouri1089aed2018-10-25 21:33:57 -0700543 renderengine::DisplaySettings settings;
544 settings.physicalDisplay = fullscreenRect();
545 // Here logical space is 2x2
546 settings.clip = Rect(2, 2);
Alec Mouri5a6d8572020-03-23 23:56:15 -0700547 settings.orientation = orientationFlag;
Alec Mouri1089aed2018-10-25 21:33:57 -0700548
Vishnu Nair9b079a22020-01-21 14:36:08 -0800549 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri1089aed2018-10-25 21:33:57 -0700550
551 renderengine::LayerSettings layerOne;
552 Rect rectOne(0, 0, 1, 1);
553 layerOne.geometry.boundaries = rectOne.toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800554 SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700555 layerOne.alpha = 1.0f;
556
557 renderengine::LayerSettings layerTwo;
558 Rect rectTwo(0, 1, 1, 2);
559 layerTwo.geometry.boundaries = rectTwo.toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800560 SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700561 layerTwo.alpha = 1.0f;
562
563 renderengine::LayerSettings layerThree;
564 Rect rectThree(1, 0, 2, 1);
565 layerThree.geometry.boundaries = rectThree.toFloatRect();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800566 SourceVariant::fillColor(layerThree, 0.0f, 0.0f, 1.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700567 layerThree.alpha = 1.0f;
568
Vishnu Nair9b079a22020-01-21 14:36:08 -0800569 layers.push_back(&layerOne);
570 layers.push_back(&layerTwo);
571 layers.push_back(&layerThree);
Alec Mouri1089aed2018-10-25 21:33:57 -0700572
573 invokeDraw(settings, layers, mBuffer);
574}
575
576template <typename SourceVariant>
577void RenderEngineTest::fillBufferCheckersRotate0() {
Alec Mouri5a6d8572020-03-23 23:56:15 -0700578 fillBufferCheckers<SourceVariant>(ui::Transform::ROT_0);
Alec Mouri1089aed2018-10-25 21:33:57 -0700579 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 255, 0, 0,
580 255);
581 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
582 DEFAULT_DISPLAY_HEIGHT / 2),
583 0, 0, 255, 255);
584 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
585 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
586 0, 0, 0, 0);
587 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2,
588 DEFAULT_DISPLAY_HEIGHT),
589 0, 255, 0, 255);
590}
591
592template <typename SourceVariant>
593void RenderEngineTest::fillBufferCheckersRotate90() {
Alec Mouri5a6d8572020-03-23 23:56:15 -0700594 fillBufferCheckers<SourceVariant>(ui::Transform::ROT_90);
Alec Mouri1089aed2018-10-25 21:33:57 -0700595 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 255, 0,
596 255);
597 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
598 DEFAULT_DISPLAY_HEIGHT / 2),
599 255, 0, 0, 255);
600 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
601 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
602 0, 0, 255, 255);
603 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2,
604 DEFAULT_DISPLAY_HEIGHT),
605 0, 0, 0, 0);
606}
607
608template <typename SourceVariant>
609void RenderEngineTest::fillBufferCheckersRotate180() {
Alec Mouri5a6d8572020-03-23 23:56:15 -0700610 fillBufferCheckers<SourceVariant>(ui::Transform::ROT_180);
Alec Mouri1089aed2018-10-25 21:33:57 -0700611 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0,
612 0);
613 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
614 DEFAULT_DISPLAY_HEIGHT / 2),
615 0, 255, 0, 255);
616 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
617 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
618 255, 0, 0, 255);
619 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2,
620 DEFAULT_DISPLAY_HEIGHT),
621 0, 0, 255, 255);
622}
623
624template <typename SourceVariant>
625void RenderEngineTest::fillBufferCheckersRotate270() {
Alec Mouri5a6d8572020-03-23 23:56:15 -0700626 fillBufferCheckers<SourceVariant>(ui::Transform::ROT_270);
Alec Mouri1089aed2018-10-25 21:33:57 -0700627 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 255,
628 255);
629 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
630 DEFAULT_DISPLAY_HEIGHT / 2),
631 0, 0, 0, 0);
632 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
633 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
634 0, 255, 0, 255);
635 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT / 2, DEFAULT_DISPLAY_WIDTH / 2,
636 DEFAULT_DISPLAY_HEIGHT),
637 255, 0, 0, 255);
638}
639
640template <typename SourceVariant>
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800641void RenderEngineTest::fillBufferWithLayerTransform() {
Alec Mouri1089aed2018-10-25 21:33:57 -0700642 renderengine::DisplaySettings settings;
643 settings.physicalDisplay = fullscreenRect();
644 // Here logical space is 2x2
645 settings.clip = Rect(2, 2);
646
Vishnu Nair9b079a22020-01-21 14:36:08 -0800647 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri1089aed2018-10-25 21:33:57 -0700648
649 renderengine::LayerSettings layer;
650 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
651 // Translate one pixel diagonally
652 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 -0800653 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
Alec Mouri1089aed2018-10-25 21:33:57 -0700654 layer.source.solidColor = half3(1.0f, 0.0f, 0.0f);
655 layer.alpha = 1.0f;
656
Vishnu Nair9b079a22020-01-21 14:36:08 -0800657 layers.push_back(&layer);
Alec Mouri1089aed2018-10-25 21:33:57 -0700658
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::fillBufferLayerTransform() {
664 fillBufferWithLayerTransform<SourceVariant>();
Alec Mouri1089aed2018-10-25 21:33:57 -0700665 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT / 2), 0, 0, 0, 0);
666 expectBufferColor(Rect(0, 0, DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0);
667 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT / 2,
668 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
669 255, 0, 0, 255);
670}
671
672template <typename SourceVariant>
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800673void RenderEngineTest::fillBufferWithColorTransform(bool useColorManagement) {
Alec Mouri1089aed2018-10-25 21:33:57 -0700674 renderengine::DisplaySettings settings;
675 settings.physicalDisplay = fullscreenRect();
676 settings.clip = Rect(1, 1);
677
Vishnu Nair9b079a22020-01-21 14:36:08 -0800678 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri1089aed2018-10-25 21:33:57 -0700679
680 renderengine::LayerSettings layer;
681 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800682 SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this, useColorManagement);
Alec Mouri1089aed2018-10-25 21:33:57 -0700683 layer.alpha = 1.0f;
684
685 // construct a fake color matrix
686 // annihilate green and blue channels
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800687 settings.colorTransform = mat4::scale(vec4(0.9f, 0, 0, 1));
Alec Mouri1089aed2018-10-25 21:33:57 -0700688 // set red channel to red + green
689 layer.colorTransform = mat4(1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
690
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800691 layer.alpha = 1.0f;
692 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
693
Vishnu Nair9b079a22020-01-21 14:36:08 -0800694 layers.push_back(&layer);
Alec Mouri1089aed2018-10-25 21:33:57 -0700695
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800696 invokeDraw(settings, layers, mBuffer, useColorManagement);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800697}
Alec Mouri1089aed2018-10-25 21:33:57 -0700698
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800699template <typename SourceVariant>
700void RenderEngineTest::fillBufferColorTransform() {
701 fillBufferWithColorTransform<SourceVariant>();
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +0800702 expectBufferColor(fullscreenRect(), 172, 0, 0, 255, 1);
703}
704
705template <typename SourceVariant>
706void RenderEngineTest::fillBufferColorTransformCM() {
707 fillBufferWithColorTransform<SourceVariant>(true);
708 expectBufferColor(fullscreenRect(), 126, 0, 0, 255, 1);
Alec Mouri1089aed2018-10-25 21:33:57 -0700709}
710
Alec Mouri7c94edb2018-12-03 21:23:26 -0800711template <typename SourceVariant>
712void RenderEngineTest::fillRedBufferWithRoundedCorners() {
713 renderengine::DisplaySettings settings;
714 settings.physicalDisplay = fullscreenRect();
715 settings.clip = fullscreenRect();
716
Vishnu Nair9b079a22020-01-21 14:36:08 -0800717 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri7c94edb2018-12-03 21:23:26 -0800718
719 renderengine::LayerSettings layer;
720 layer.geometry.boundaries = fullscreenRect().toFloatRect();
721 layer.geometry.roundedCornersRadius = 5.0f;
722 layer.geometry.roundedCornersCrop = fullscreenRect().toFloatRect();
723 SourceVariant::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
724 layer.alpha = 1.0f;
725
Vishnu Nair9b079a22020-01-21 14:36:08 -0800726 layers.push_back(&layer);
Alec Mouri7c94edb2018-12-03 21:23:26 -0800727
728 invokeDraw(settings, layers, mBuffer);
729}
730
731template <typename SourceVariant>
732void RenderEngineTest::fillBufferWithRoundedCorners() {
733 fillRedBufferWithRoundedCorners<SourceVariant>();
734 // Corners should be ignored...
735 expectBufferColor(Rect(0, 0, 1, 1), 0, 0, 0, 0);
736 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, 0, DEFAULT_DISPLAY_WIDTH, 1), 0, 0, 0, 0);
737 expectBufferColor(Rect(0, DEFAULT_DISPLAY_HEIGHT - 1, 1, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 0);
738 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH - 1, DEFAULT_DISPLAY_HEIGHT - 1,
739 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
740 0, 0, 0, 0);
741 // ...And the non-rounded portion should be red.
742 // Other pixels may be anti-aliased, so let's not check those.
743 expectBufferColor(Rect(5, 5, DEFAULT_DISPLAY_WIDTH - 5, DEFAULT_DISPLAY_HEIGHT - 5), 255, 0, 0,
744 255);
745}
746
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000747template <typename SourceVariant>
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800748void RenderEngineTest::fillBufferAndBlurBackground() {
749 char value[PROPERTY_VALUE_MAX];
750 property_get("ro.surface_flinger.supports_background_blur", value, "0");
751 if (!atoi(value)) {
752 // This device doesn't support blurs, no-op.
753 return;
754 }
755
756 auto blurRadius = 50;
757 auto center = DEFAULT_DISPLAY_WIDTH / 2;
758
759 renderengine::DisplaySettings settings;
760 settings.physicalDisplay = fullscreenRect();
761 settings.clip = fullscreenRect();
762
Vishnu Nair9b079a22020-01-21 14:36:08 -0800763 std::vector<const renderengine::LayerSettings*> layers;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800764
765 renderengine::LayerSettings backgroundLayer;
766 backgroundLayer.geometry.boundaries = fullscreenRect().toFloatRect();
767 SourceVariant::fillColor(backgroundLayer, 0.0f, 1.0f, 0.0f, this);
768 backgroundLayer.alpha = 1.0f;
Vishnu Nair9b079a22020-01-21 14:36:08 -0800769 layers.push_back(&backgroundLayer);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800770
771 renderengine::LayerSettings leftLayer;
772 leftLayer.geometry.boundaries =
773 Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT).toFloatRect();
774 SourceVariant::fillColor(leftLayer, 1.0f, 0.0f, 0.0f, this);
775 leftLayer.alpha = 1.0f;
Vishnu Nair9b079a22020-01-21 14:36:08 -0800776 layers.push_back(&leftLayer);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800777
778 renderengine::LayerSettings blurLayer;
779 blurLayer.geometry.boundaries = fullscreenRect().toFloatRect();
780 blurLayer.backgroundBlurRadius = blurRadius;
781 blurLayer.alpha = 0;
Vishnu Nair9b079a22020-01-21 14:36:08 -0800782 layers.push_back(&blurLayer);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800783
784 invokeDraw(settings, layers, mBuffer);
785
786 expectBufferColor(Rect(center - 1, center - 5, center, center + 5), 150, 150, 0, 255,
787 50 /* tolerance */);
788 expectBufferColor(Rect(center, center - 5, center + 1, center + 5), 150, 150, 0, 255,
789 50 /* tolerance */);
790}
791
792template <typename SourceVariant>
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000793void RenderEngineTest::overlayCorners() {
794 renderengine::DisplaySettings settings;
795 settings.physicalDisplay = fullscreenRect();
796 settings.clip = fullscreenRect();
797
Vishnu Nair9b079a22020-01-21 14:36:08 -0800798 std::vector<const renderengine::LayerSettings*> layersFirst;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000799
800 renderengine::LayerSettings layerOne;
801 layerOne.geometry.boundaries =
802 FloatRect(0, 0, DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0);
803 SourceVariant::fillColor(layerOne, 1.0f, 0.0f, 0.0f, this);
804 layerOne.alpha = 0.2;
805
Vishnu Nair9b079a22020-01-21 14:36:08 -0800806 layersFirst.push_back(&layerOne);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000807 invokeDraw(settings, layersFirst, mBuffer);
808 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 51, 0, 0, 51);
809 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1,
810 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
811 0, 0, 0, 0);
812
Vishnu Nair9b079a22020-01-21 14:36:08 -0800813 std::vector<const renderengine::LayerSettings*> layersSecond;
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000814 renderengine::LayerSettings layerTwo;
815 layerTwo.geometry.boundaries =
816 FloatRect(DEFAULT_DISPLAY_WIDTH / 3.0, DEFAULT_DISPLAY_HEIGHT / 3.0,
817 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT);
818 SourceVariant::fillColor(layerTwo, 0.0f, 1.0f, 0.0f, this);
819 layerTwo.alpha = 1.0f;
820
Vishnu Nair9b079a22020-01-21 14:36:08 -0800821 layersSecond.push_back(&layerTwo);
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000822 invokeDraw(settings, layersSecond, mBuffer);
823
824 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3, DEFAULT_DISPLAY_HEIGHT / 3), 0, 0, 0, 0);
825 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 3 + 1, DEFAULT_DISPLAY_HEIGHT / 3 + 1,
826 DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT),
827 0, 255, 0, 255);
828}
829
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800830void RenderEngineTest::fillRedBufferTextureTransform() {
831 renderengine::DisplaySettings settings;
832 settings.physicalDisplay = fullscreenRect();
833 settings.clip = Rect(1, 1);
834
Vishnu Nair9b079a22020-01-21 14:36:08 -0800835 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800836
837 renderengine::LayerSettings layer;
838 // Here will allocate a checker board texture, but transform texture
839 // coordinates so that only the upper left is applied.
840 sp<GraphicBuffer> buf = allocateSourceBuffer(2, 2);
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 // Red top left, Green top right, Blue bottom left, Black bottom right
849 pixels[0] = 255;
850 pixels[1] = 0;
851 pixels[2] = 0;
852 pixels[3] = 255;
853 pixels[4] = 0;
854 pixels[5] = 255;
855 pixels[6] = 0;
856 pixels[7] = 255;
857 pixels[8] = 0;
858 pixels[9] = 0;
859 pixels[10] = 255;
860 pixels[11] = 255;
861 buf->unlock();
862
863 layer.source.buffer.buffer = buf;
864 layer.source.buffer.textureName = texName;
865 // Transform coordinates to only be inside the red quadrant.
866 layer.source.buffer.textureTransform = mat4::scale(vec4(0.2, 0.2, 1, 1));
867 layer.alpha = 1.0f;
868 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
869
Vishnu Nair9b079a22020-01-21 14:36:08 -0800870 layers.push_back(&layer);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800871
872 invokeDraw(settings, layers, mBuffer);
873}
874
875void RenderEngineTest::fillBufferTextureTransform() {
876 fillRedBufferTextureTransform();
877 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
878}
879
880void RenderEngineTest::fillRedBufferWithPremultiplyAlpha() {
881 renderengine::DisplaySettings settings;
882 settings.physicalDisplay = fullscreenRect();
883 // Here logical space is 1x1
884 settings.clip = Rect(1, 1);
885
Vishnu Nair9b079a22020-01-21 14:36:08 -0800886 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800887
888 renderengine::LayerSettings layer;
889 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
890 uint32_t texName;
891 RenderEngineTest::sRE->genTextures(1, &texName);
892 this->mTexNames.push_back(texName);
893
894 uint8_t* pixels;
895 buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
896 reinterpret_cast<void**>(&pixels));
897 pixels[0] = 255;
898 pixels[1] = 0;
899 pixels[2] = 0;
900 pixels[3] = 255;
901 buf->unlock();
902
903 layer.source.buffer.buffer = buf;
904 layer.source.buffer.textureName = texName;
905 layer.source.buffer.usePremultipliedAlpha = true;
906 layer.alpha = 0.5f;
907 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
908
Vishnu Nair9b079a22020-01-21 14:36:08 -0800909 layers.push_back(&layer);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800910
911 invokeDraw(settings, layers, mBuffer);
912}
913
914void RenderEngineTest::fillBufferWithPremultiplyAlpha() {
915 fillRedBufferWithPremultiplyAlpha();
916 expectBufferColor(fullscreenRect(), 128, 0, 0, 128);
917}
918
919void RenderEngineTest::fillRedBufferWithoutPremultiplyAlpha() {
920 renderengine::DisplaySettings settings;
921 settings.physicalDisplay = fullscreenRect();
922 // Here logical space is 1x1
923 settings.clip = Rect(1, 1);
924
Vishnu Nair9b079a22020-01-21 14:36:08 -0800925 std::vector<const renderengine::LayerSettings*> layers;
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800926
927 renderengine::LayerSettings layer;
928 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
929 uint32_t texName;
930 RenderEngineTest::sRE->genTextures(1, &texName);
931 this->mTexNames.push_back(texName);
932
933 uint8_t* pixels;
934 buf->lock(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
935 reinterpret_cast<void**>(&pixels));
936 pixels[0] = 255;
937 pixels[1] = 0;
938 pixels[2] = 0;
939 pixels[3] = 255;
940 buf->unlock();
941
942 layer.source.buffer.buffer = buf;
943 layer.source.buffer.textureName = texName;
944 layer.source.buffer.usePremultipliedAlpha = false;
945 layer.alpha = 0.5f;
946 layer.geometry.boundaries = Rect(1, 1).toFloatRect();
947
Vishnu Nair9b079a22020-01-21 14:36:08 -0800948 layers.push_back(&layer);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800949
950 invokeDraw(settings, layers, mBuffer);
951}
952
953void RenderEngineTest::fillBufferWithoutPremultiplyAlpha() {
954 fillRedBufferWithoutPremultiplyAlpha();
wukui16f3c0bb2020-08-05 20:35:29 +0800955 expectBufferColor(fullscreenRect(), 128, 0, 0, 128, 1);
Alec Mouri0d5e1eb2018-11-10 20:40:12 -0800956}
957
Alec Mouriac335532018-11-12 15:01:33 -0800958void RenderEngineTest::clearLeftRegion() {
959 renderengine::DisplaySettings settings;
960 settings.physicalDisplay = fullscreenRect();
961 // Here logical space is 4x4
962 settings.clip = Rect(4, 4);
Alec Mouri5a6d8572020-03-23 23:56:15 -0700963 settings.clearRegion = Region(Rect(2, 4));
Vishnu Nair9b079a22020-01-21 14:36:08 -0800964 std::vector<const renderengine::LayerSettings*> layers;
Xin Lie8b4e702020-08-29 01:34:09 -0700965 // fake layer, without bounds should not render anything
Alec Mouriac335532018-11-12 15:01:33 -0800966 renderengine::LayerSettings layer;
Vishnu Nair9b079a22020-01-21 14:36:08 -0800967 layers.push_back(&layer);
Alec Mouriac335532018-11-12 15:01:33 -0800968 invokeDraw(settings, layers, mBuffer);
969}
970
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000971void RenderEngineTest::clearRegion() {
Alec Mouriac335532018-11-12 15:01:33 -0800972 // Reuse mBuffer
973 clearLeftRegion();
974 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, DEFAULT_DISPLAY_HEIGHT), 0, 0, 0, 255);
975 expectBufferColor(Rect(DEFAULT_DISPLAY_WIDTH / 2, 0, DEFAULT_DISPLAY_WIDTH,
976 DEFAULT_DISPLAY_HEIGHT),
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000977 0, 0, 0, 0);
Alec Mouriac335532018-11-12 15:01:33 -0800978}
979
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800980template <typename SourceVariant>
981void RenderEngineTest::drawShadow(const renderengine::LayerSettings& castingLayer,
982 const renderengine::ShadowSettings& shadow,
983 const ubyte4& casterColor, const ubyte4& backgroundColor) {
984 renderengine::DisplaySettings settings;
985 settings.physicalDisplay = fullscreenRect();
986 settings.clip = fullscreenRect();
987
Vishnu Nair9b079a22020-01-21 14:36:08 -0800988 std::vector<const renderengine::LayerSettings*> layers;
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800989
990 // add background layer
991 renderengine::LayerSettings bgLayer;
992 bgLayer.geometry.boundaries = fullscreenRect().toFloatRect();
993 ColorSourceVariant::fillColor(bgLayer, backgroundColor.r / 255.0f, backgroundColor.g / 255.0f,
994 backgroundColor.b / 255.0f, this);
995 bgLayer.alpha = backgroundColor.a / 255.0f;
Vishnu Nair9b079a22020-01-21 14:36:08 -0800996 layers.push_back(&bgLayer);
Vishnu Nair16efdbf2019-12-10 11:55:42 -0800997
998 // add shadow layer
999 renderengine::LayerSettings shadowLayer;
1000 shadowLayer.geometry.boundaries = castingLayer.geometry.boundaries;
1001 shadowLayer.alpha = castingLayer.alpha;
1002 shadowLayer.shadow = shadow;
Vishnu Nair9b079a22020-01-21 14:36:08 -08001003 layers.push_back(&shadowLayer);
Vishnu Nair16efdbf2019-12-10 11:55:42 -08001004
1005 // add layer casting the shadow
1006 renderengine::LayerSettings layer = castingLayer;
1007 SourceVariant::fillColor(layer, casterColor.r / 255.0f, casterColor.g / 255.0f,
1008 casterColor.b / 255.0f, this);
Vishnu Nair9b079a22020-01-21 14:36:08 -08001009 layers.push_back(&layer);
Vishnu Nair16efdbf2019-12-10 11:55:42 -08001010
1011 invokeDraw(settings, layers, mBuffer);
1012}
1013
Alec Mouri1089aed2018-10-25 21:33:57 -07001014TEST_F(RenderEngineTest, drawLayers_noLayersToDraw) {
1015 drawEmptyLayers();
1016}
1017
Alec Mourid43ccab2019-03-13 12:23:45 -07001018TEST_F(RenderEngineTest, drawLayers_nullOutputBuffer) {
1019 renderengine::DisplaySettings settings;
Vishnu Nair9b079a22020-01-21 14:36:08 -08001020 std::vector<const renderengine::LayerSettings*> layers;
Alec Mourid43ccab2019-03-13 12:23:45 -07001021 renderengine::LayerSettings layer;
1022 layer.geometry.boundaries = fullscreenRect().toFloatRect();
1023 BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
Vishnu Nair9b079a22020-01-21 14:36:08 -08001024 layers.push_back(&layer);
Alec Mourid43ccab2019-03-13 12:23:45 -07001025 base::unique_fd fence;
Alec Mourife0d72b2019-03-21 14:05:56 -07001026 status_t status = sRE->drawLayers(settings, layers, nullptr, true, base::unique_fd(), &fence);
Alec Mourid43ccab2019-03-13 12:23:45 -07001027
1028 ASSERT_EQ(BAD_VALUE, status);
1029}
1030
1031TEST_F(RenderEngineTest, drawLayers_nullOutputFence) {
1032 renderengine::DisplaySettings settings;
1033 settings.physicalDisplay = fullscreenRect();
1034 settings.clip = fullscreenRect();
1035
Vishnu Nair9b079a22020-01-21 14:36:08 -08001036 std::vector<const renderengine::LayerSettings*> layers;
Alec Mourid43ccab2019-03-13 12:23:45 -07001037 renderengine::LayerSettings layer;
1038 layer.geometry.boundaries = fullscreenRect().toFloatRect();
1039 BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
1040 layer.alpha = 1.0;
Vishnu Nair9b079a22020-01-21 14:36:08 -08001041 layers.push_back(&layer);
Alec Mourid43ccab2019-03-13 12:23:45 -07001042
Alec Mourife0d72b2019-03-21 14:05:56 -07001043 status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true,
Alec Mourid43ccab2019-03-13 12:23:45 -07001044 base::unique_fd(), nullptr);
1045 sCurrentBuffer = mBuffer;
1046 ASSERT_EQ(NO_ERROR, status);
1047 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
1048}
1049
Alec Mourife0d72b2019-03-21 14:05:56 -07001050TEST_F(RenderEngineTest, drawLayers_doesNotCacheFramebuffer) {
1051 renderengine::DisplaySettings settings;
1052 settings.physicalDisplay = fullscreenRect();
1053 settings.clip = fullscreenRect();
1054
Vishnu Nair9b079a22020-01-21 14:36:08 -08001055 std::vector<const renderengine::LayerSettings*> layers;
Alec Mourife0d72b2019-03-21 14:05:56 -07001056 renderengine::LayerSettings layer;
1057 layer.geometry.boundaries = fullscreenRect().toFloatRect();
1058 BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
1059 layer.alpha = 1.0;
Vishnu Nair9b079a22020-01-21 14:36:08 -08001060 layers.push_back(&layer);
Alec Mourife0d72b2019-03-21 14:05:56 -07001061
1062 status_t status = sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), false,
1063 base::unique_fd(), nullptr);
1064 sCurrentBuffer = mBuffer;
1065 ASSERT_EQ(NO_ERROR, status);
1066 ASSERT_FALSE(sRE->isFramebufferImageCachedForTesting(mBuffer->getId()));
1067 expectBufferColor(fullscreenRect(), 255, 0, 0, 255);
1068}
1069
Alec Mouri1089aed2018-10-25 21:33:57 -07001070TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) {
1071 fillRedBuffer<ColorSourceVariant>();
1072}
1073
1074TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_colorSource) {
1075 fillGreenBuffer<ColorSourceVariant>();
1076}
1077
1078TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_colorSource) {
1079 fillBlueBuffer<ColorSourceVariant>();
1080}
1081
1082TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_colorSource) {
1083 fillRedTransparentBuffer<ColorSourceVariant>();
1084}
1085
1086TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_colorSource) {
1087 fillBufferPhysicalOffset<ColorSourceVariant>();
1088}
1089
1090TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_colorSource) {
1091 fillBufferCheckersRotate0<ColorSourceVariant>();
1092}
1093
1094TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_colorSource) {
1095 fillBufferCheckersRotate90<ColorSourceVariant>();
1096}
1097
1098TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_colorSource) {
1099 fillBufferCheckersRotate180<ColorSourceVariant>();
1100}
1101
1102TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_colorSource) {
1103 fillBufferCheckersRotate270<ColorSourceVariant>();
1104}
1105
1106TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_colorSource) {
1107 fillBufferLayerTransform<ColorSourceVariant>();
1108}
1109
1110TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_colorSource) {
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +08001111 fillBufferColorTransform<ColorSourceVariant>();
1112}
1113
1114TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransformCM_colorSource) {
1115 fillBufferColorTransformCM<ColorSourceVariant>();
Alec Mouri6e57f682018-09-29 20:45:08 -07001116}
1117
Alec Mouri7c94edb2018-12-03 21:23:26 -08001118TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_colorSource) {
1119 fillBufferWithRoundedCorners<ColorSourceVariant>();
1120}
1121
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08001122TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_colorSource) {
1123 fillBufferAndBlurBackground<ColorSourceVariant>();
1124}
1125
Alec Mourie7d1d4a2019-02-05 01:13:46 +00001126TEST_F(RenderEngineTest, drawLayers_overlayCorners_colorSource) {
1127 overlayCorners<ColorSourceVariant>();
1128}
1129
Alec Mouri0d5e1eb2018-11-10 20:40:12 -08001130TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_opaqueBufferSource) {
1131 fillRedBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1132}
1133
1134TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_opaqueBufferSource) {
1135 fillGreenBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1136}
1137
1138TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_opaqueBufferSource) {
1139 fillBlueBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1140}
1141
1142TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_opaqueBufferSource) {
1143 fillRedTransparentBuffer<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1144}
1145
1146TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_opaqueBufferSource) {
1147 fillBufferPhysicalOffset<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1148}
1149
1150TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_opaqueBufferSource) {
1151 fillBufferCheckersRotate0<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1152}
1153
1154TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_opaqueBufferSource) {
1155 fillBufferCheckersRotate90<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1156}
1157
1158TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_opaqueBufferSource) {
1159 fillBufferCheckersRotate180<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1160}
1161
1162TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_opaqueBufferSource) {
1163 fillBufferCheckersRotate270<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1164}
1165
1166TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_opaqueBufferSource) {
1167 fillBufferLayerTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1168}
1169
1170TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_opaqueBufferSource) {
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +08001171 fillBufferColorTransform<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1172}
1173
1174TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransformCM_opaqueBufferSource) {
1175 fillBufferColorTransformCM<BufferSourceVariant<ForceOpaqueBufferVariant>>();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -08001176}
1177
Alec Mouri7c94edb2018-12-03 21:23:26 -08001178TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_opaqueBufferSource) {
1179 fillBufferWithRoundedCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1180}
1181
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08001182TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_opaqueBufferSource) {
1183 fillBufferAndBlurBackground<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1184}
1185
Alec Mourie7d1d4a2019-02-05 01:13:46 +00001186TEST_F(RenderEngineTest, drawLayers_overlayCorners_opaqueBufferSource) {
1187 overlayCorners<BufferSourceVariant<ForceOpaqueBufferVariant>>();
1188}
1189
Alec Mouri0d5e1eb2018-11-10 20:40:12 -08001190TEST_F(RenderEngineTest, drawLayers_fillRedBuffer_bufferSource) {
1191 fillRedBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1192}
1193
1194TEST_F(RenderEngineTest, drawLayers_fillGreenBuffer_bufferSource) {
1195 fillGreenBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1196}
1197
1198TEST_F(RenderEngineTest, drawLayers_fillBlueBuffer_bufferSource) {
1199 fillBlueBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1200}
1201
1202TEST_F(RenderEngineTest, drawLayers_fillRedTransparentBuffer_bufferSource) {
1203 fillRedTransparentBuffer<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1204}
1205
1206TEST_F(RenderEngineTest, drawLayers_fillBufferPhysicalOffset_bufferSource) {
1207 fillBufferPhysicalOffset<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1208}
1209
1210TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate0_bufferSource) {
1211 fillBufferCheckersRotate0<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1212}
1213
1214TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate90_bufferSource) {
1215 fillBufferCheckersRotate90<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1216}
1217
1218TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate180_bufferSource) {
1219 fillBufferCheckersRotate180<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1220}
1221
1222TEST_F(RenderEngineTest, drawLayers_fillBufferCheckersRotate270_bufferSource) {
1223 fillBufferCheckersRotate270<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1224}
1225
1226TEST_F(RenderEngineTest, drawLayers_fillBufferLayerTransform_bufferSource) {
1227 fillBufferLayerTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1228}
1229
1230TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransform_bufferSource) {
KaiChieh Chuangba2f0bc2020-09-07 13:48:42 +08001231 fillBufferColorTransform<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1232}
1233
1234TEST_F(RenderEngineTest, drawLayers_fillBufferColorTransformCM_bufferSource) {
1235 fillBufferColorTransformCM<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
Alec Mouri0d5e1eb2018-11-10 20:40:12 -08001236}
1237
Alec Mouri7c94edb2018-12-03 21:23:26 -08001238TEST_F(RenderEngineTest, drawLayers_fillBufferRoundedCorners_bufferSource) {
1239 fillBufferWithRoundedCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1240}
1241
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08001242TEST_F(RenderEngineTest, drawLayers_fillBufferAndBlurBackground_bufferSource) {
1243 fillBufferAndBlurBackground<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1244}
1245
Alec Mourie7d1d4a2019-02-05 01:13:46 +00001246TEST_F(RenderEngineTest, drawLayers_overlayCorners_bufferSource) {
1247 overlayCorners<BufferSourceVariant<RelaxOpaqueBufferVariant>>();
1248}
1249
Alec Mouri0d5e1eb2018-11-10 20:40:12 -08001250TEST_F(RenderEngineTest, drawLayers_fillBufferTextureTransform) {
1251 fillBufferTextureTransform();
1252}
1253
1254TEST_F(RenderEngineTest, drawLayers_fillBuffer_premultipliesAlpha) {
1255 fillBufferWithPremultiplyAlpha();
1256}
1257
1258TEST_F(RenderEngineTest, drawLayers_fillBuffer_withoutPremultiplyingAlpha) {
1259 fillBufferWithoutPremultiplyAlpha();
1260}
1261
Alec Mourie7d1d4a2019-02-05 01:13:46 +00001262TEST_F(RenderEngineTest, drawLayers_clearRegion) {
1263 clearRegion();
Alec Mouriac335532018-11-12 15:01:33 -08001264}
1265
Alec Mourid43ccab2019-03-13 12:23:45 -07001266TEST_F(RenderEngineTest, drawLayers_fillsBufferAndCachesImages) {
1267 renderengine::DisplaySettings settings;
1268 settings.physicalDisplay = fullscreenRect();
1269 settings.clip = fullscreenRect();
1270
Vishnu Nair9b079a22020-01-21 14:36:08 -08001271 std::vector<const renderengine::LayerSettings*> layers;
Alec Mourid43ccab2019-03-13 12:23:45 -07001272
1273 renderengine::LayerSettings layer;
1274 layer.geometry.boundaries = fullscreenRect().toFloatRect();
1275 BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
1276
Vishnu Nair9b079a22020-01-21 14:36:08 -08001277 layers.push_back(&layer);
Alec Mourid43ccab2019-03-13 12:23:45 -07001278 invokeDraw(settings, layers, mBuffer);
1279 uint64_t bufferId = layer.source.buffer.buffer->getId();
1280 EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001281 std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier =
1282 sRE->unbindExternalTextureBufferForTesting(bufferId);
1283 std::lock_guard<std::mutex> lock(barrier->mutex);
1284 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1285 [&]() REQUIRES(barrier->mutex) {
1286 return barrier->isOpen;
1287 }));
Alec Mourid43ccab2019-03-13 12:23:45 -07001288 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001289 EXPECT_EQ(NO_ERROR, barrier->result);
Alec Mourid43ccab2019-03-13 12:23:45 -07001290}
1291
Alec Mouri4dde1782019-09-30 17:27:13 -07001292TEST_F(RenderEngineTest, bindExternalBuffer_withNullBuffer) {
Alec Mourid43ccab2019-03-13 12:23:45 -07001293 status_t result = sRE->bindExternalTextureBuffer(0, nullptr, nullptr);
1294 ASSERT_EQ(BAD_VALUE, result);
1295}
1296
Alec Mouri4dde1782019-09-30 17:27:13 -07001297TEST_F(RenderEngineTest, bindExternalBuffer_cachesImages) {
Alec Mourid43ccab2019-03-13 12:23:45 -07001298 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
1299 uint32_t texName;
1300 sRE->genTextures(1, &texName);
1301 mTexNames.push_back(texName);
1302
1303 sRE->bindExternalTextureBuffer(texName, buf, nullptr);
1304 uint64_t bufferId = buf->getId();
1305 EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001306 std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier =
1307 sRE->unbindExternalTextureBufferForTesting(bufferId);
1308 std::lock_guard<std::mutex> lock(barrier->mutex);
1309 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1310 [&]() REQUIRES(barrier->mutex) {
1311 return barrier->isOpen;
1312 }));
1313 EXPECT_EQ(NO_ERROR, barrier->result);
Alec Mourid43ccab2019-03-13 12:23:45 -07001314 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
1315}
1316
Alec Mouri4dde1782019-09-30 17:27:13 -07001317TEST_F(RenderEngineTest, cacheExternalBuffer_withNullBuffer) {
Alec Mouri16a99402019-07-29 16:37:30 -07001318 std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier =
1319 sRE->cacheExternalTextureBufferForTesting(nullptr);
1320 std::lock_guard<std::mutex> lock(barrier->mutex);
1321 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1322 [&]() REQUIRES(barrier->mutex) {
1323 return barrier->isOpen;
1324 }));
1325 EXPECT_TRUE(barrier->isOpen);
1326 EXPECT_EQ(BAD_VALUE, barrier->result);
Alec Mourid7b3a8b2019-03-21 11:44:18 -07001327}
1328
Alec Mouri4dde1782019-09-30 17:27:13 -07001329TEST_F(RenderEngineTest, cacheExternalBuffer_cachesImages) {
Alec Mourid7b3a8b2019-03-21 11:44:18 -07001330 sp<GraphicBuffer> buf = allocateSourceBuffer(1, 1);
1331 uint64_t bufferId = buf->getId();
Alec Mouri16a99402019-07-29 16:37:30 -07001332 std::shared_ptr<renderengine::gl::ImageManager::Barrier> barrier =
1333 sRE->cacheExternalTextureBufferForTesting(buf);
1334 {
1335 std::lock_guard<std::mutex> lock(barrier->mutex);
1336 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1337 [&]() REQUIRES(barrier->mutex) {
1338 return barrier->isOpen;
1339 }));
1340 EXPECT_EQ(NO_ERROR, barrier->result);
1341 }
Alec Mourid7b3a8b2019-03-21 11:44:18 -07001342 EXPECT_TRUE(sRE->isImageCachedForTesting(bufferId));
Alec Mouri16a99402019-07-29 16:37:30 -07001343 barrier = sRE->unbindExternalTextureBufferForTesting(bufferId);
1344 {
1345 std::lock_guard<std::mutex> lock(barrier->mutex);
1346 ASSERT_TRUE(barrier->condition.wait_for(barrier->mutex, std::chrono::seconds(5),
1347 [&]() REQUIRES(barrier->mutex) {
1348 return barrier->isOpen;
1349 }));
1350 EXPECT_EQ(NO_ERROR, barrier->result);
1351 }
Alec Mourid7b3a8b2019-03-21 11:44:18 -07001352 EXPECT_FALSE(sRE->isImageCachedForTesting(bufferId));
1353}
1354
Vishnu Nair16efdbf2019-12-10 11:55:42 -08001355TEST_F(RenderEngineTest, drawLayers_fillShadow_casterLayerMinSize) {
1356 const ubyte4 casterColor(255, 0, 0, 255);
1357 const ubyte4 backgroundColor(255, 255, 255, 255);
1358 const float shadowLength = 5.0f;
1359 Rect casterBounds(1, 1);
1360 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1361 renderengine::LayerSettings castingLayer;
1362 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1363 castingLayer.alpha = 1.0f;
1364 renderengine::ShadowSettings settings =
1365 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1366 false /* casterIsTranslucent */);
1367
1368 drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor);
1369 expectShadowColor(castingLayer, settings, casterColor, backgroundColor);
1370}
1371
1372TEST_F(RenderEngineTest, drawLayers_fillShadow_casterColorLayer) {
1373 const ubyte4 casterColor(255, 0, 0, 255);
1374 const ubyte4 backgroundColor(255, 255, 255, 255);
1375 const float shadowLength = 5.0f;
1376 Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f);
1377 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1378 renderengine::LayerSettings castingLayer;
1379 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1380 castingLayer.alpha = 1.0f;
1381 renderengine::ShadowSettings settings =
1382 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1383 false /* casterIsTranslucent */);
1384
1385 drawShadow<ColorSourceVariant>(castingLayer, settings, casterColor, backgroundColor);
1386 expectShadowColor(castingLayer, settings, casterColor, backgroundColor);
1387}
1388
1389TEST_F(RenderEngineTest, drawLayers_fillShadow_casterOpaqueBufferLayer) {
1390 const ubyte4 casterColor(255, 0, 0, 255);
1391 const ubyte4 backgroundColor(255, 255, 255, 255);
1392 const float shadowLength = 5.0f;
1393 Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f);
1394 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1395 renderengine::LayerSettings castingLayer;
1396 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1397 castingLayer.alpha = 1.0f;
1398 renderengine::ShadowSettings settings =
1399 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1400 false /* casterIsTranslucent */);
1401
1402 drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor,
1403 backgroundColor);
1404 expectShadowColor(castingLayer, settings, casterColor, backgroundColor);
1405}
1406
1407TEST_F(RenderEngineTest, drawLayers_fillShadow_casterWithRoundedCorner) {
1408 const ubyte4 casterColor(255, 0, 0, 255);
1409 const ubyte4 backgroundColor(255, 255, 255, 255);
1410 const float shadowLength = 5.0f;
1411 Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f);
1412 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1413 renderengine::LayerSettings castingLayer;
1414 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1415 castingLayer.geometry.roundedCornersRadius = 3.0f;
1416 castingLayer.geometry.roundedCornersCrop = casterBounds.toFloatRect();
1417 castingLayer.alpha = 1.0f;
1418 renderengine::ShadowSettings settings =
1419 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1420 false /* casterIsTranslucent */);
1421
1422 drawShadow<BufferSourceVariant<ForceOpaqueBufferVariant>>(castingLayer, settings, casterColor,
1423 backgroundColor);
1424 expectShadowColor(castingLayer, settings, casterColor, backgroundColor);
1425}
1426
1427TEST_F(RenderEngineTest, drawLayers_fillShadow_translucentCasterWithAlpha) {
1428 const ubyte4 casterColor(255, 0, 0, 255);
1429 const ubyte4 backgroundColor(255, 255, 255, 255);
1430 const float shadowLength = 5.0f;
1431 Rect casterBounds(DEFAULT_DISPLAY_WIDTH / 3.0f, DEFAULT_DISPLAY_HEIGHT / 3.0f);
1432 casterBounds.offsetBy(shadowLength + 1, shadowLength + 1);
1433 renderengine::LayerSettings castingLayer;
1434 castingLayer.geometry.boundaries = casterBounds.toFloatRect();
1435 castingLayer.alpha = 0.5f;
1436 renderengine::ShadowSettings settings =
1437 getShadowSettings(vec2(casterBounds.left, casterBounds.top), shadowLength,
1438 true /* casterIsTranslucent */);
1439
1440 drawShadow<BufferSourceVariant<RelaxOpaqueBufferVariant>>(castingLayer, settings, casterColor,
1441 backgroundColor);
1442
1443 // verify only the background since the shadow will draw behind the caster
1444 const float shadowInset = settings.length * -1.0f;
1445 const Rect casterWithShadow =
1446 Rect(casterBounds).inset(shadowInset, shadowInset, shadowInset, shadowInset);
1447 const Region backgroundRegion = Region(fullscreenRect()).subtractSelf(casterWithShadow);
1448 expectBufferColor(backgroundRegion, backgroundColor.r, backgroundColor.g, backgroundColor.b,
1449 backgroundColor.a);
1450}
1451
Alec Mouri4dde1782019-09-30 17:27:13 -07001452TEST_F(RenderEngineTest, cleanupPostRender_cleansUpOnce) {
1453 renderengine::DisplaySettings settings;
1454 settings.physicalDisplay = fullscreenRect();
1455 settings.clip = fullscreenRect();
1456
1457 std::vector<const renderengine::LayerSettings*> layers;
1458 renderengine::LayerSettings layer;
1459 layer.geometry.boundaries = fullscreenRect().toFloatRect();
1460 BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this);
1461 layer.alpha = 1.0;
1462 layers.push_back(&layer);
1463
1464 base::unique_fd fenceOne;
1465 sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, base::unique_fd(),
1466 &fenceOne);
1467 base::unique_fd fenceTwo;
1468 sRE->drawLayers(settings, layers, mBuffer->getNativeBuffer(), true, std::move(fenceOne),
1469 &fenceTwo);
1470
1471 const int fd = fenceTwo.get();
1472 if (fd >= 0) {
1473 sync_wait(fd, -1);
1474 }
1475
1476 // Only cleanup the first time.
1477 EXPECT_TRUE(sRE->cleanupPostRender());
1478 EXPECT_FALSE(sRE->cleanupPostRender());
1479}
1480
Alec Mouri6e57f682018-09-29 20:45:08 -07001481} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -08001482
1483// TODO(b/129481165): remove the #pragma below and fix conversion issues
1484#pragma clang diagnostic pop // ignored "-Wconversion"