1 /*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "graphics_composer_hidl_hal_readback_tests@2.2"
18
19 #include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
20 #include <composer-vts/2.1/GraphicsComposerCallback.h>
21 #include <composer-vts/2.1/TestCommandReader.h>
22 #include <composer-vts/2.2/ComposerVts.h>
23 #include <composer-vts/2.2/ReadbackVts.h>
24 #include <composer-vts/2.2/RenderEngineVts.h>
25 #include <gtest/gtest.h>
26 #include <hidl/GtestPrinter.h>
27 #include <hidl/ServiceManagement.h>
28 #include <ui/GraphicBuffer.h>
29 #include <ui/PixelFormat.h>
30 #include <ui/Rect.h>
31 #include <ui/Region.h>
32
33 namespace android {
34 namespace hardware {
35 namespace graphics {
36 namespace composer {
37 namespace V2_2 {
38 namespace vts {
39 namespace {
40
41 using android::Rect;
42 using common::V1_1::BufferUsage;
43 using common::V1_1::Dataspace;
44 using common::V1_1::PixelFormat;
45 using V2_1::Config;
46 using V2_1::Display;
47 using V2_1::vts::TestCommandReader;
48
49 class GraphicsCompositionTestBase : public ::testing::Test {
50 protected:
51 using PowerMode = V2_1::IComposerClient::PowerMode;
SetUpBase(const std::string & service_name)52 void SetUpBase(const std::string& service_name) {
53 ASSERT_NO_FATAL_FAILURE(
54 mComposer = std::make_unique<Composer>(IComposer::getService(service_name)));
55 ASSERT_NO_FATAL_FAILURE(mComposerClient = mComposer->createClient());
56 mComposerCallback = new V2_1::vts::GraphicsComposerCallback;
57 mComposerClient->registerCallback(mComposerCallback);
58
59 // assume the first display is primary and is never removed
60 mPrimaryDisplay = waitForFirstDisplay();
61 Config activeConfig;
62 ASSERT_NO_FATAL_FAILURE(activeConfig = mComposerClient->getActiveConfig(mPrimaryDisplay));
63 ASSERT_NO_FATAL_FAILURE(
64 mDisplayWidth = mComposerClient->getDisplayAttribute(
65 mPrimaryDisplay, activeConfig, IComposerClient::Attribute::WIDTH));
66 ASSERT_NO_FATAL_FAILURE(
67 mDisplayHeight = mComposerClient->getDisplayAttribute(
68 mPrimaryDisplay, activeConfig, IComposerClient::Attribute::HEIGHT));
69
70 setTestColorModes();
71
72 // explicitly disable vsync
73 ASSERT_NO_FATAL_FAILURE(mComposerClient->setVsyncEnabled(mPrimaryDisplay, false));
74 mComposerCallback->setVsyncAllowed(false);
75
76 // set up command writer/reader and gralloc
77 mWriter = std::make_shared<CommandWriterBase>(1024);
78 mReader = std::make_unique<TestCommandReader>();
79
80 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode(mPrimaryDisplay, PowerMode::ON));
81
82 ASSERT_NO_FATAL_FAILURE(
83 mTestRenderEngine = std::unique_ptr<TestRenderEngine>(new TestRenderEngine(
84 renderengine::RenderEngineCreationArgs::Builder()
85 .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888))
86 .setImageCacheSize(TestRenderEngine::sMaxFrameBufferAcquireBuffers)
87 .setEnableProtectedContext(false)
88 .setPrecacheToneMapperShaderOnly(false)
89 .setContextPriority(
90 renderengine::RenderEngine::ContextPriority::HIGH)
91 .build())));
92
93 renderengine::DisplaySettings clientCompositionDisplay;
94 clientCompositionDisplay.physicalDisplay = Rect(mDisplayWidth, mDisplayHeight);
95 clientCompositionDisplay.clip = clientCompositionDisplay.physicalDisplay;
96
97 mTestRenderEngine->initGraphicBuffer(
98 static_cast<uint32_t>(mDisplayWidth), static_cast<uint32_t>(mDisplayHeight), 1,
99 static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
100 BufferUsage::GPU_RENDER_TARGET));
101 mTestRenderEngine->setDisplaySettings(clientCompositionDisplay);
102 }
103
TearDown()104 void TearDown() override {
105 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode(mPrimaryDisplay, PowerMode::OFF));
106 EXPECT_EQ(0, mReader->mErrors.size());
107 EXPECT_EQ(0, mReader->mCompositionChanges.size());
108 if (mComposerCallback != nullptr) {
109 EXPECT_EQ(0, mComposerCallback->getInvalidHotplugCount());
110 EXPECT_EQ(0, mComposerCallback->getInvalidRefreshCount());
111 EXPECT_EQ(0, mComposerCallback->getInvalidVsyncCount());
112 }
113 }
114
clearCommandReaderState()115 void clearCommandReaderState() {
116 mReader->mCompositionChanges.clear();
117 mReader->mErrors.clear();
118 }
119
writeLayers(const std::vector<std::shared_ptr<TestLayer>> & layers)120 void writeLayers(const std::vector<std::shared_ptr<TestLayer>>& layers) {
121 for (auto layer : layers) {
122 layer->write(mWriter);
123 }
124 execute();
125 }
126
execute()127 void execute() {
128 ASSERT_NO_FATAL_FAILURE(mComposerClient->execute(mReader.get(), mWriter.get()));
129 }
130
131 std::unique_ptr<Composer> mComposer;
132 std::shared_ptr<ComposerClient> mComposerClient;
133
134 sp<V2_1::vts::GraphicsComposerCallback> mComposerCallback;
135 // the first display and is assumed never to be removed
136 Display mPrimaryDisplay;
137 int32_t mDisplayWidth;
138 int32_t mDisplayHeight;
139 std::vector<ColorMode> mTestColorModes;
140 std::shared_ptr<CommandWriterBase> mWriter;
141 std::unique_ptr<TestCommandReader> mReader;
142 std::unique_ptr<TestRenderEngine> mTestRenderEngine;
143
144 bool mHasReadbackBuffer;
145 PixelFormat mPixelFormat;
146 Dataspace mDataspace;
147
148 static constexpr uint32_t kClientTargetSlotCount = 64;
149
150 private:
waitForFirstDisplay()151 Display waitForFirstDisplay() {
152 while (true) {
153 std::vector<Display> displays = mComposerCallback->getDisplays();
154 if (displays.empty()) {
155 usleep(5 * 1000);
156 continue;
157 }
158 return displays[0];
159 }
160 }
161
setTestColorModes()162 void setTestColorModes() {
163 mTestColorModes.clear();
164 mComposerClient->getRaw()->getColorModes_2_2(mPrimaryDisplay, [&](const auto& tmpError,
165 const auto& tmpModes) {
166 ASSERT_EQ(Error::NONE, tmpError);
167 for (ColorMode mode : tmpModes) {
168 if (std::find(ReadbackHelper::colorModes.begin(), ReadbackHelper::colorModes.end(),
169 mode) != ReadbackHelper::colorModes.end()) {
170 mTestColorModes.push_back(mode);
171 }
172 }
173 });
174 }
175 };
176
177 class GraphicsCompositionTest : public GraphicsCompositionTestBase,
178 public testing::WithParamInterface<std::string> {
179 public:
SetUp()180 void SetUp() override { SetUpBase(GetParam()); }
181 };
182
TEST_P(GraphicsCompositionTest,SingleSolidColorLayer)183 TEST_P(GraphicsCompositionTest, SingleSolidColorLayer) {
184 for (ColorMode mode : mTestColorModes) {
185 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
186 << std::endl;
187 mWriter->selectDisplay(mPrimaryDisplay);
188 ASSERT_NO_FATAL_FAILURE(
189 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
190
191 mComposerClient->getRaw()->getReadbackBufferAttributes(
192 mPrimaryDisplay,
193 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
194 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
195 tmpDataspace, tmpError);
196 mPixelFormat = tmpPixelFormat;
197 mDataspace = tmpDataspace;
198 });
199
200 if (!mHasReadbackBuffer) {
201 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
202 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
203 return;
204 }
205
206 auto layer = std::make_shared<TestColorLayer>(mComposerClient, mPrimaryDisplay);
207 IComposerClient::Rect coloredSquare({0, 0, mDisplayWidth, mDisplayHeight});
208 layer->setColor(BLUE);
209 layer->setDisplayFrame(coloredSquare);
210 layer->setZOrder(10);
211
212 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
213
214 // expected color for each pixel
215 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
216 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth, coloredSquare, BLUE);
217
218 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
219 mDisplayHeight, mPixelFormat, mDataspace);
220 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
221
222 writeLayers(layers);
223 ASSERT_EQ(0, mReader->mErrors.size());
224 mWriter->validateDisplay();
225 execute();
226 // if hwc cannot handle and asks for composition change,
227 // just succeed the test
228 if (mReader->mCompositionChanges.size() != 0) {
229 clearCommandReaderState();
230 GTEST_SUCCEED();
231 return;
232 }
233 ASSERT_EQ(0, mReader->mErrors.size());
234 mWriter->presentDisplay();
235 execute();
236 ASSERT_EQ(0, mReader->mErrors.size());
237
238 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
239 mTestRenderEngine->setRenderLayers(layers);
240 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
241 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
242 }
243 }
244
TEST_P(GraphicsCompositionTest,SetLayerBuffer)245 TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
246 for (ColorMode mode : mTestColorModes) {
247 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
248 << std::endl;
249 mWriter->selectDisplay(mPrimaryDisplay);
250 ASSERT_NO_FATAL_FAILURE(
251 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
252
253 mComposerClient->getRaw()->getReadbackBufferAttributes(
254 mPrimaryDisplay,
255 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
256 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
257 tmpDataspace, tmpError);
258 mPixelFormat = tmpPixelFormat;
259 mDataspace = tmpDataspace;
260 });
261
262 if (!mHasReadbackBuffer) {
263 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
264 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
265 return;
266 }
267
268 mWriter->selectDisplay(mPrimaryDisplay);
269
270 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
271 mDisplayHeight, mPixelFormat, mDataspace);
272 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
273 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
274 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
275 {0, 0, mDisplayWidth, mDisplayHeight / 4}, RED);
276 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
277 {0, mDisplayHeight / 4, mDisplayWidth, mDisplayHeight / 2},
278 GREEN);
279 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
280 {0, mDisplayHeight / 2, mDisplayWidth, mDisplayHeight},
281 BLUE);
282
283 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
284 mPrimaryDisplay, mDisplayWidth,
285 mDisplayHeight, PixelFormat::RGBA_8888);
286 layer->setDisplayFrame({0, 0, mDisplayWidth, mDisplayHeight});
287 layer->setZOrder(10);
288 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
289 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
290
291 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
292
293 writeLayers(layers);
294 ASSERT_EQ(0, mReader->mErrors.size());
295 mWriter->validateDisplay();
296 execute();
297
298 if (mReader->mCompositionChanges.size() != 0) {
299 clearCommandReaderState();
300 GTEST_SUCCEED();
301 return;
302 }
303 ASSERT_EQ(0, mReader->mErrors.size());
304
305 mWriter->presentDisplay();
306 execute();
307
308 ASSERT_EQ(0, mReader->mErrors.size());
309
310 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
311 mTestRenderEngine->setRenderLayers(layers);
312 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
313 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
314 }
315 }
316
TEST_P(GraphicsCompositionTest,SetLayerBufferNoEffect)317 TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
318 for (ColorMode mode : mTestColorModes) {
319 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
320 << std::endl;
321 mWriter->selectDisplay(mPrimaryDisplay);
322 ASSERT_NO_FATAL_FAILURE(
323 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
324
325 mComposerClient->getRaw()->getReadbackBufferAttributes(
326 mPrimaryDisplay,
327 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
328 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
329 tmpDataspace, tmpError);
330 mPixelFormat = tmpPixelFormat;
331 mDataspace = tmpDataspace;
332 });
333
334 if (!mHasReadbackBuffer) {
335 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
336 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
337 return;
338 }
339
340 auto layer = std::make_shared<TestColorLayer>(mComposerClient, mPrimaryDisplay);
341 IComposerClient::Rect coloredSquare({0, 0, mDisplayWidth, mDisplayHeight});
342 layer->setColor(BLUE);
343 layer->setDisplayFrame(coloredSquare);
344 layer->setZOrder(10);
345 layer->write(mWriter);
346
347 // This following buffer call should have no effect
348 uint64_t usage =
349 static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN);
350 sp<GraphicBuffer> buffer = sp<GraphicBuffer>::make(
351 mDisplayWidth, mDisplayHeight, (int32_t)PixelFormat::RGBA_8888, 1, usage);
352 ASSERT_EQ(STATUS_OK, buffer->initCheck());
353 mWriter->setLayerBuffer(0, buffer->handle, -1);
354
355 // expected color for each pixel
356 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
357 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth, coloredSquare, BLUE);
358
359 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
360 mDisplayHeight, mPixelFormat, mDataspace);
361 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
362
363 mWriter->validateDisplay();
364 execute();
365
366 if (mReader->mCompositionChanges.size() != 0) {
367 clearCommandReaderState();
368 GTEST_SUCCEED();
369 return;
370 }
371 ASSERT_EQ(0, mReader->mErrors.size());
372 mWriter->presentDisplay();
373 execute();
374 ASSERT_EQ(0, mReader->mErrors.size());
375
376 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
377 }
378 }
379
TEST_P(GraphicsCompositionTest,ClientComposition)380 TEST_P(GraphicsCompositionTest, ClientComposition) {
381 ASSERT_NO_FATAL_FAILURE(
382 mComposerClient->setClientTargetSlotCount(mPrimaryDisplay, kClientTargetSlotCount));
383
384 for (ColorMode mode : mTestColorModes) {
385 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
386 << std::endl;
387 mWriter->selectDisplay(mPrimaryDisplay);
388 ASSERT_NO_FATAL_FAILURE(
389 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
390
391 mComposerClient->getRaw()->getReadbackBufferAttributes(
392 mPrimaryDisplay,
393 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
394 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
395 tmpDataspace, tmpError);
396 mPixelFormat = tmpPixelFormat;
397 mDataspace = tmpDataspace;
398 });
399
400 if (!mHasReadbackBuffer) {
401 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
402 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
403 return;
404 }
405
406 mWriter->selectDisplay(mPrimaryDisplay);
407
408 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
409 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
410 {0, 0, mDisplayWidth, mDisplayHeight / 4}, RED);
411 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
412 {0, mDisplayHeight / 4, mDisplayWidth, mDisplayHeight / 2},
413 GREEN);
414 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
415 {0, mDisplayHeight / 2, mDisplayWidth, mDisplayHeight},
416 BLUE);
417
418 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
419 mPrimaryDisplay, mDisplayWidth,
420 mDisplayHeight, PixelFormat::RGBA_FP16);
421 layer->setDisplayFrame({0, 0, mDisplayWidth, mDisplayHeight});
422 layer->setZOrder(10);
423 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
424
425 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
426
427 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
428 mDisplayHeight, mPixelFormat, mDataspace);
429 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
430 writeLayers(layers);
431 ASSERT_EQ(0, mReader->mErrors.size());
432 mWriter->validateDisplay();
433 execute();
434
435 if (mReader->mCompositionChanges.size() != 0) {
436 ASSERT_EQ(1, mReader->mCompositionChanges.size());
437 ASSERT_EQ(1, mReader->mCompositionChanges[0].second);
438
439 PixelFormat clientFormat = PixelFormat::RGBA_8888;
440 uint64_t clientUsage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN |
441 BufferUsage::CPU_WRITE_OFTEN |
442 BufferUsage::COMPOSER_CLIENT_TARGET);
443 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
444 IComposerClient::Rect damage{0, 0, mDisplayWidth, mDisplayHeight};
445
446 bool clientTargetSupported = mComposerClient->getClientTargetSupport_2_2(
447 mPrimaryDisplay, layer->mWidth, layer->mHeight, clientFormat, clientDataspace);
448 // if the client target format is not supported, skip this
449 // configuration
450 if (!clientTargetSupported) {
451 std::cout << "Client target configuration width: " << layer->mWidth
452 << " height: " << layer->mHeight
453 << " pixel format: PixelFormat::RGBA_8888 dataspace: "
454 << ReadbackHelper::getDataspaceString(clientDataspace)
455 << " unsupported for display" << std::endl;
456 mReader->mCompositionChanges.clear();
457 continue;
458 }
459
460 // create client target buffer
461 sp<GraphicBuffer> clientBuffer =
462 sp<GraphicBuffer>::make(layer->mWidth, layer->mHeight, (int32_t)clientFormat,
463 layer->mLayerCount, clientUsage);
464 ASSERT_EQ(STATUS_OK, clientBuffer->initCheck());
465
466 void* clientBufData = nullptr;
467 ASSERT_EQ(STATUS_OK, clientBuffer->lock(clientUsage, &clientBufData));
468
469 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(layer->mWidth, layer->mHeight,
470 clientBuffer->stride, clientBufData,
471 clientFormat, expectedColors));
472 clientBuffer->unlock();
473
474 mWriter->setClientTarget(0, clientBuffer->handle, -1, clientDataspace,
475 std::vector<IComposerClient::Rect>(1, damage));
476
477 layer->setToClientComposition(mWriter);
478 mWriter->validateDisplay();
479 execute();
480 ASSERT_EQ(0, mReader->mCompositionChanges.size());
481 }
482 ASSERT_EQ(0, mReader->mErrors.size());
483
484 mWriter->presentDisplay();
485 execute();
486
487 ASSERT_EQ(0, mReader->mErrors.size());
488
489 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
490 }
491 }
492
TEST_P(GraphicsCompositionTest,DeviceAndClientComposition)493 TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
494 ASSERT_NO_FATAL_FAILURE(
495 mComposerClient->setClientTargetSlotCount(mPrimaryDisplay, kClientTargetSlotCount));
496
497 for (ColorMode mode : mTestColorModes) {
498 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
499 << std::endl;
500 mWriter->selectDisplay(mPrimaryDisplay);
501 ASSERT_NO_FATAL_FAILURE(
502 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
503
504 mComposerClient->getRaw()->getReadbackBufferAttributes(
505 mPrimaryDisplay,
506 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
507 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
508 tmpDataspace, tmpError);
509 mPixelFormat = tmpPixelFormat;
510 mDataspace = tmpDataspace;
511 });
512
513 if (!mHasReadbackBuffer) {
514 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
515 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
516 return;
517 }
518
519 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
520 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
521 {0, 0, mDisplayWidth, mDisplayHeight / 2}, GREEN);
522 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
523 {0, mDisplayHeight / 2, mDisplayWidth, mDisplayHeight}, RED);
524
525 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
526 mDisplayHeight, mPixelFormat, mDataspace);
527 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
528
529 auto deviceLayer = std::make_shared<TestBufferLayer>(
530 mComposerClient, *mTestRenderEngine, mPrimaryDisplay, mDisplayWidth,
531 mDisplayHeight / 2, PixelFormat::RGBA_8888);
532 std::vector<IComposerClient::Color> deviceColors(deviceLayer->mWidth *
533 deviceLayer->mHeight);
534 ReadbackHelper::fillColorsArea(deviceColors, deviceLayer->mWidth,
535 {0, 0, static_cast<int32_t>(deviceLayer->mWidth),
536 static_cast<int32_t>(deviceLayer->mHeight)},
537 GREEN);
538 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->mWidth),
539 static_cast<int32_t>(deviceLayer->mHeight)});
540 deviceLayer->setZOrder(10);
541 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
542 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
543 deviceLayer->write(mWriter);
544
545 PixelFormat clientFormat = PixelFormat::RGBA_8888;
546 uint64_t clientUsage =
547 static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
548 BufferUsage::COMPOSER_CLIENT_TARGET);
549 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
550 int32_t clientWidth = mDisplayWidth;
551 int32_t clientHeight = mDisplayHeight / 2;
552
553 bool clientTargetSupported = mComposerClient->getClientTargetSupport_2_2(
554 mPrimaryDisplay, clientWidth, clientHeight, clientFormat, clientDataspace);
555 // if the client target format is not supported, skip this
556 // configuration
557 if (!clientTargetSupported) {
558 std::cout << "Client target configuration width: " << clientWidth
559 << " height: " << clientHeight
560 << " pixel format: PixelFormat::RGBA_8888 dataspace: "
561 << ReadbackHelper::getDataspaceString(clientDataspace)
562 << " unsupported for display" << std::endl;
563 continue;
564 }
565
566 auto clientLayer = std::make_shared<TestBufferLayer>(
567 mComposerClient, *mTestRenderEngine, mPrimaryDisplay, clientWidth, clientHeight,
568 PixelFormat::RGBA_FP16, IComposerClient::Composition::DEVICE);
569 IComposerClient::Rect clientFrame = {0, mDisplayHeight / 2, mDisplayWidth, mDisplayHeight};
570 clientLayer->setDisplayFrame(clientFrame);
571 clientLayer->setZOrder(0);
572 clientLayer->write(mWriter);
573 mWriter->validateDisplay();
574 execute();
575
576 if (mReader->mCompositionChanges.size() != 1) {
577 std::cout << "HWC asked for none or more than 1 composition change, skipping"
578 << std::endl;
579 mReader->mCompositionChanges.clear();
580 continue;
581 }
582 // create client target buffer
583 ASSERT_EQ(1, mReader->mCompositionChanges[0].second);
584 sp<GraphicBuffer> clientBuffer =
585 sp<GraphicBuffer>::make(mDisplayWidth, mDisplayHeight, (int32_t)clientFormat,
586 clientLayer->mLayerCount, clientUsage);
587 ASSERT_EQ(STATUS_OK, clientBuffer->initCheck());
588
589 void* clientBufData = nullptr;
590 ASSERT_EQ(STATUS_OK, clientBuffer->lock(clientUsage, &clientBufData));
591
592 std::vector<IComposerClient::Color> clientColors(mDisplayWidth * mDisplayHeight);
593 ReadbackHelper::fillColorsArea(clientColors, mDisplayWidth, clientFrame, RED);
594 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(mDisplayWidth, mDisplayHeight,
595 clientBuffer->stride, clientBufData,
596 clientFormat, clientColors));
597 EXPECT_EQ(STATUS_OK, clientBuffer->unlock());
598
599 mWriter->setClientTarget(0, clientBuffer->handle, -1, clientDataspace,
600 std::vector<IComposerClient::Rect>(1, clientFrame));
601 clientLayer->setToClientComposition(mWriter);
602 mWriter->validateDisplay();
603 execute();
604 ASSERT_EQ(0, mReader->mCompositionChanges.size());
605 ASSERT_EQ(0, mReader->mErrors.size());
606
607 mWriter->presentDisplay();
608 execute();
609 ASSERT_EQ(0, mReader->mErrors.size());
610 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
611 }
612 }
613
TEST_P(GraphicsCompositionTest,SetLayerDamage)614 TEST_P(GraphicsCompositionTest, SetLayerDamage) {
615 for (ColorMode mode : mTestColorModes) {
616 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
617 << std::endl;
618 mWriter->selectDisplay(mPrimaryDisplay);
619 ASSERT_NO_FATAL_FAILURE(
620 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
621
622 mComposerClient->getRaw()->getReadbackBufferAttributes(
623 mPrimaryDisplay,
624 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
625 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
626 tmpDataspace, tmpError);
627 mPixelFormat = tmpPixelFormat;
628 mDataspace = tmpDataspace;
629 });
630
631 if (!mHasReadbackBuffer) {
632 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
633 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
634 return;
635 }
636
637 mWriter->selectDisplay(mPrimaryDisplay);
638
639 IComposerClient::Rect redRect = {0, 0, mDisplayWidth / 4, mDisplayHeight / 4};
640
641 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
642 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth, redRect, RED);
643
644 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
645 mPrimaryDisplay, mDisplayWidth,
646 mDisplayHeight, PixelFormat::RGBA_8888);
647 layer->setDisplayFrame({0, 0, mDisplayWidth, mDisplayHeight});
648 layer->setZOrder(10);
649 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
650 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
651
652 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
653
654 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
655 mDisplayHeight, mPixelFormat, mDataspace);
656 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
657
658 writeLayers(layers);
659 ASSERT_EQ(0, mReader->mErrors.size());
660 mWriter->validateDisplay();
661 execute();
662 if (mReader->mCompositionChanges.size() != 0) {
663 clearCommandReaderState();
664 GTEST_SUCCEED();
665 return;
666 }
667 ASSERT_EQ(0, mReader->mErrors.size());
668 mWriter->presentDisplay();
669 execute();
670 ASSERT_EQ(0, mReader->mErrors.size());
671
672 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
673
674 // update surface damage and recheck
675 redRect = {mDisplayWidth / 4, mDisplayHeight / 4, mDisplayWidth / 2, mDisplayHeight / 2};
676 ReadbackHelper::clearColors(expectedColors, mDisplayWidth, mDisplayHeight, mDisplayWidth);
677 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth, redRect, RED);
678
679 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
680 layer->setSurfaceDamage(std::vector<IComposerClient::Rect>(
681 1, {0, 0, mDisplayWidth / 2, mDisplayWidth / 2}));
682
683 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
684
685 writeLayers(layers);
686 ASSERT_EQ(0, mReader->mErrors.size());
687 mWriter->validateDisplay();
688 execute();
689 ASSERT_EQ(0, mReader->mErrors.size());
690 ASSERT_EQ(0, mReader->mCompositionChanges.size());
691 mWriter->presentDisplay();
692 execute();
693 ASSERT_EQ(0, mReader->mErrors.size());
694
695 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
696 }
697 }
698
TEST_P(GraphicsCompositionTest,SetLayerPlaneAlpha)699 TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
700 for (ColorMode mode : mTestColorModes) {
701 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
702 << std::endl;
703 mWriter->selectDisplay(mPrimaryDisplay);
704 ASSERT_NO_FATAL_FAILURE(
705 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
706
707 mComposerClient->getRaw()->getReadbackBufferAttributes(
708 mPrimaryDisplay,
709 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
710 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
711 tmpDataspace, tmpError);
712 mPixelFormat = tmpPixelFormat;
713 mDataspace = tmpDataspace;
714 });
715
716 if (!mHasReadbackBuffer) {
717 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
718 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
719 return;
720 }
721
722 auto layer = std::make_shared<TestColorLayer>(mComposerClient, mPrimaryDisplay);
723 layer->setColor(RED);
724 layer->setDisplayFrame({0, 0, mDisplayWidth, mDisplayHeight});
725 layer->setZOrder(10);
726 layer->setAlpha(0);
727 layer->setBlendMode(IComposerClient::BlendMode::PREMULTIPLIED);
728
729 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
730
731 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
732 mDisplayHeight, mPixelFormat, mDataspace);
733
734 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
735
736 writeLayers(layers);
737 ASSERT_EQ(0, mReader->mErrors.size());
738 mWriter->validateDisplay();
739 execute();
740 if (mReader->mCompositionChanges.size() != 0) {
741 clearCommandReaderState();
742 GTEST_SUCCEED();
743 return;
744 }
745 ASSERT_EQ(0, mReader->mErrors.size());
746
747 mWriter->presentDisplay();
748 execute();
749 ASSERT_EQ(0, mReader->mErrors.size());
750
751 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
752
753 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
754 mTestRenderEngine->setRenderLayers(layers);
755 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
756 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
757 }
758 }
759
TEST_P(GraphicsCompositionTest,SetLayerSourceCrop)760 TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
761 for (ColorMode mode : mTestColorModes) {
762 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
763 << std::endl;
764 mWriter->selectDisplay(mPrimaryDisplay);
765 ASSERT_NO_FATAL_FAILURE(
766 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
767
768 mComposerClient->getRaw()->getReadbackBufferAttributes(
769 mPrimaryDisplay,
770 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
771 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
772 tmpDataspace, tmpError);
773 mPixelFormat = tmpPixelFormat;
774 mDataspace = tmpDataspace;
775 });
776
777 if (!mHasReadbackBuffer) {
778 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
779 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
780 return;
781 }
782
783 mWriter->selectDisplay(mPrimaryDisplay);
784
785 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
786 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
787 {0, 0, mDisplayWidth, mDisplayHeight / 4}, RED);
788 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
789 {0, mDisplayHeight / 2, mDisplayWidth, mDisplayHeight},
790 BLUE);
791
792 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
793 mPrimaryDisplay, mDisplayWidth,
794 mDisplayHeight, PixelFormat::RGBA_8888);
795 layer->setDisplayFrame({0, 0, mDisplayWidth, mDisplayHeight});
796 layer->setZOrder(10);
797 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
798 layer->setSourceCrop({0, static_cast<float>(mDisplayHeight / 2),
799 static_cast<float>(mDisplayWidth),
800 static_cast<float>(mDisplayHeight)});
801 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
802
803 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
804
805 // update expected colors to match crop
806 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
807 {0, 0, mDisplayWidth, mDisplayHeight}, BLUE);
808 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
809 mDisplayHeight, mPixelFormat, mDataspace);
810 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
811 writeLayers(layers);
812 ASSERT_EQ(0, mReader->mErrors.size());
813 mWriter->validateDisplay();
814 execute();
815 if (mReader->mCompositionChanges.size() != 0) {
816 clearCommandReaderState();
817 GTEST_SUCCEED();
818 return;
819 }
820 ASSERT_EQ(0, mReader->mErrors.size());
821 mWriter->presentDisplay();
822 execute();
823 ASSERT_EQ(0, mReader->mErrors.size());
824 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
825 mTestRenderEngine->setRenderLayers(layers);
826 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
827 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
828 }
829 }
830
TEST_P(GraphicsCompositionTest,SetLayerZOrder)831 TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
832 for (ColorMode mode : mTestColorModes) {
833 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
834 << std::endl;
835 mWriter->selectDisplay(mPrimaryDisplay);
836 ASSERT_NO_FATAL_FAILURE(
837 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
838
839 mComposerClient->getRaw()->getReadbackBufferAttributes(
840 mPrimaryDisplay,
841 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
842 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
843 tmpDataspace, tmpError);
844 mPixelFormat = tmpPixelFormat;
845 mDataspace = tmpDataspace;
846 });
847
848 if (!mHasReadbackBuffer) {
849 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
850 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
851 return;
852 }
853
854 IComposerClient::Rect redRect = {0, 0, mDisplayWidth, mDisplayHeight / 2};
855 IComposerClient::Rect blueRect = {0, mDisplayHeight / 4, mDisplayWidth, mDisplayHeight};
856 auto redLayer = std::make_shared<TestColorLayer>(mComposerClient, mPrimaryDisplay);
857 redLayer->setColor(RED);
858 redLayer->setDisplayFrame(redRect);
859
860 auto blueLayer = std::make_shared<TestColorLayer>(mComposerClient, mPrimaryDisplay);
861 blueLayer->setColor(BLUE);
862 blueLayer->setDisplayFrame(blueRect);
863 blueLayer->setZOrder(5);
864
865 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
866 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
867
868 // red in front of blue
869 redLayer->setZOrder(10);
870
871 // fill blue first so that red will overwrite on overlap
872 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth, blueRect, BLUE);
873 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth, redRect, RED);
874
875 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
876 mDisplayHeight, mPixelFormat, mDataspace);
877 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
878
879 writeLayers(layers);
880 ASSERT_EQ(0, mReader->mErrors.size());
881 mWriter->validateDisplay();
882 execute();
883 if (mReader->mCompositionChanges.size() != 0) {
884 clearCommandReaderState();
885 GTEST_SUCCEED();
886 return;
887 }
888 mWriter->presentDisplay();
889 execute();
890 ASSERT_EQ(0, mReader->mErrors.size());
891
892 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
893
894 redLayer->setZOrder(1);
895 ReadbackHelper::clearColors(expectedColors, mDisplayWidth, mDisplayHeight, mDisplayWidth);
896 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth, redRect, RED);
897 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth, blueRect, BLUE);
898
899 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
900
901 writeLayers(layers);
902 ASSERT_EQ(0, mReader->mErrors.size());
903 mWriter->validateDisplay();
904 execute();
905 ASSERT_EQ(0, mReader->mCompositionChanges.size());
906 ASSERT_EQ(0, mReader->mErrors.size());
907 mWriter->presentDisplay();
908 execute();
909 ASSERT_EQ(0, mReader->mErrors.size());
910
911 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
912 mTestRenderEngine->setRenderLayers(layers);
913 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
914 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
915 }
916 }
917
918 class GraphicsBlendModeCompositionTest
919 : public GraphicsCompositionTestBase,
920 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
921 public:
SetUp()922 void SetUp() override {
923 SetUpBase(std::get<0>(GetParam()));
924 mTestColorModes = {ColorMode::SRGB}; // TODO: add more color mode support
925 mBackgroundColor = BLACK;
926 mTopLayerColor = RED;
927 }
928
setBackgroundColor(IComposerClient::Color color)929 void setBackgroundColor(IComposerClient::Color color) { mBackgroundColor = color; }
930
setTopLayerColor(IComposerClient::Color color)931 void setTopLayerColor(IComposerClient::Color color) { mTopLayerColor = color; }
932
setUpLayers(IComposerClient::BlendMode blendMode)933 void setUpLayers(IComposerClient::BlendMode blendMode) {
934 mLayers.clear();
935 std::vector<IComposerClient::Color> topLayerPixelColors(mDisplayWidth * mDisplayHeight);
936 ReadbackHelper::fillColorsArea(topLayerPixelColors, mDisplayWidth,
937 {0, 0, mDisplayWidth, mDisplayHeight}, mTopLayerColor);
938
939 auto backgroundLayer = std::make_shared<TestColorLayer>(mComposerClient, mPrimaryDisplay);
940 backgroundLayer->setDisplayFrame({0, 0, mDisplayWidth, mDisplayHeight});
941 backgroundLayer->setZOrder(0);
942 backgroundLayer->setColor(mBackgroundColor);
943
944 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
945 mPrimaryDisplay, mDisplayWidth,
946 mDisplayHeight, PixelFormat::RGBA_8888);
947 layer->setDisplayFrame({0, 0, mDisplayWidth, mDisplayHeight});
948 layer->setZOrder(10);
949 layer->setDataspace(Dataspace::UNKNOWN, mWriter);
950 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
951
952 layer->setBlendMode(blendMode);
953 layer->setAlpha(std::stof(std::get<1>(GetParam())));
954
955 mLayers.push_back(backgroundLayer);
956 mLayers.push_back(layer);
957 }
958
setExpectedColors(std::vector<IComposerClient::Color> & expectedColors)959 void setExpectedColors(std::vector<IComposerClient::Color>& expectedColors) {
960 ASSERT_EQ(2, mLayers.size());
961 ReadbackHelper::clearColors(expectedColors, mDisplayWidth, mDisplayHeight, mDisplayWidth);
962
963 auto layer = mLayers[1];
964 IComposerClient::BlendMode blendMode = layer->mBlendMode;
965 float alpha = mTopLayerColor.a / 255.0 * layer->mAlpha;
966 if (blendMode == IComposerClient::BlendMode::NONE) {
967 for (int i = 0; i < expectedColors.size(); i++) {
968 expectedColors[i].r = mTopLayerColor.r * layer->mAlpha;
969 expectedColors[i].g = mTopLayerColor.g * layer->mAlpha;
970 expectedColors[i].b = mTopLayerColor.b * layer->mAlpha;
971 expectedColors[i].a = alpha * 255.0;
972 }
973 } else if (blendMode == IComposerClient::BlendMode::PREMULTIPLIED) {
974 for (int i = 0; i < expectedColors.size(); i++) {
975 expectedColors[i].r =
976 mTopLayerColor.r * layer->mAlpha + mBackgroundColor.r * (1.0 - alpha);
977 expectedColors[i].g =
978 mTopLayerColor.g * layer->mAlpha + mBackgroundColor.g * (1.0 - alpha);
979 expectedColors[i].b =
980 mTopLayerColor.b * layer->mAlpha + mBackgroundColor.b * (1.0 - alpha);
981 expectedColors[i].a = alpha + mBackgroundColor.a * (1.0 - alpha);
982 }
983 } else if (blendMode == IComposerClient::BlendMode::COVERAGE) {
984 for (int i = 0; i < expectedColors.size(); i++) {
985 expectedColors[i].r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0 - alpha);
986 expectedColors[i].g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0 - alpha);
987 expectedColors[i].b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0 - alpha);
988 expectedColors[i].a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0 - alpha);
989 }
990 }
991 }
992
993 protected:
994 std::vector<std::shared_ptr<TestLayer>> mLayers;
995 IComposerClient::Color mBackgroundColor;
996 IComposerClient::Color mTopLayerColor;
997 };
998
999 // TODO(b/145557764): Re-enable after the bug is fixed.
TEST_P(GraphicsBlendModeCompositionTest,DISABLED_None)1000 TEST_P(GraphicsBlendModeCompositionTest, DISABLED_None) {
1001 for (ColorMode mode : mTestColorModes) {
1002 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
1003 << std::endl;
1004 mWriter->selectDisplay(mPrimaryDisplay);
1005 ASSERT_NO_FATAL_FAILURE(
1006 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
1007
1008 mComposerClient->getRaw()->getReadbackBufferAttributes(
1009 mPrimaryDisplay,
1010 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
1011 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
1012 tmpDataspace, tmpError);
1013 mPixelFormat = tmpPixelFormat;
1014 mDataspace = tmpDataspace;
1015 });
1016
1017 if (!mHasReadbackBuffer) {
1018 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
1019 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1020 return;
1021 }
1022
1023 mWriter->selectDisplay(mPrimaryDisplay);
1024
1025 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
1026
1027 setBackgroundColor(BLACK);
1028 setTopLayerColor(TRANSLUCENT_RED);
1029 setUpLayers(IComposerClient::BlendMode::NONE);
1030 setExpectedColors(expectedColors);
1031
1032 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
1033 mDisplayHeight, mPixelFormat, mDataspace);
1034 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1035 writeLayers(mLayers);
1036 ASSERT_EQ(0, mReader->mErrors.size());
1037 mWriter->validateDisplay();
1038 execute();
1039 if (mReader->mCompositionChanges.size() != 0) {
1040 clearCommandReaderState();
1041 GTEST_SUCCEED();
1042 return;
1043 }
1044 ASSERT_EQ(0, mReader->mErrors.size());
1045 mWriter->presentDisplay();
1046 execute();
1047 ASSERT_EQ(0, mReader->mErrors.size());
1048
1049 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1050 mTestRenderEngine->setRenderLayers(mLayers);
1051 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1052 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1053 }
1054 }
1055
1056 // TODO: bug 116865056: Readback returns (245, 0, 0) for layer plane
1057 // alpha of .2, expected 10.2
TEST_P(GraphicsBlendModeCompositionTest,DISABLED_Coverage)1058 TEST_P(GraphicsBlendModeCompositionTest, DISABLED_Coverage) {
1059 for (ColorMode mode : mTestColorModes) {
1060 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
1061 << std::endl;
1062 mWriter->selectDisplay(mPrimaryDisplay);
1063 ASSERT_NO_FATAL_FAILURE(
1064 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
1065
1066 mComposerClient->getRaw()->getReadbackBufferAttributes(
1067 mPrimaryDisplay,
1068 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
1069 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
1070 tmpDataspace, tmpError);
1071 mPixelFormat = tmpPixelFormat;
1072 mDataspace = tmpDataspace;
1073 });
1074
1075 if (!mHasReadbackBuffer) {
1076 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
1077 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1078 return;
1079 }
1080
1081 mWriter->selectDisplay(mPrimaryDisplay);
1082
1083 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
1084
1085 setBackgroundColor(BLACK);
1086 setTopLayerColor(TRANSLUCENT_RED);
1087
1088 setUpLayers(IComposerClient::BlendMode::COVERAGE);
1089 setExpectedColors(expectedColors);
1090
1091 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
1092 mDisplayHeight, mPixelFormat, mDataspace);
1093 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1094 writeLayers(mLayers);
1095 ASSERT_EQ(0, mReader->mErrors.size());
1096 mWriter->validateDisplay();
1097 execute();
1098 if (mReader->mCompositionChanges.size() != 0) {
1099 clearCommandReaderState();
1100 GTEST_SUCCEED();
1101 return;
1102 }
1103 ASSERT_EQ(0, mReader->mErrors.size());
1104 mWriter->presentDisplay();
1105 execute();
1106 ASSERT_EQ(0, mReader->mErrors.size());
1107 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1108 }
1109 }
1110
TEST_P(GraphicsBlendModeCompositionTest,Premultiplied)1111 TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1112 for (ColorMode mode : mTestColorModes) {
1113 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
1114 << std::endl;
1115 mWriter->selectDisplay(mPrimaryDisplay);
1116 ASSERT_NO_FATAL_FAILURE(
1117 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
1118
1119 mComposerClient->getRaw()->getReadbackBufferAttributes(
1120 mPrimaryDisplay,
1121 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
1122 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
1123 tmpDataspace, tmpError);
1124 mPixelFormat = tmpPixelFormat;
1125 mDataspace = tmpDataspace;
1126 });
1127
1128 if (!mHasReadbackBuffer) {
1129 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
1130 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1131 return;
1132 }
1133 mWriter->selectDisplay(mPrimaryDisplay);
1134
1135 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
1136
1137 setBackgroundColor(BLACK);
1138 setTopLayerColor(TRANSLUCENT_RED);
1139 setUpLayers(IComposerClient::BlendMode::PREMULTIPLIED);
1140 setExpectedColors(expectedColors);
1141
1142 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
1143 mDisplayHeight, mPixelFormat, mDataspace);
1144 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1145 writeLayers(mLayers);
1146 ASSERT_EQ(0, mReader->mErrors.size());
1147 mWriter->validateDisplay();
1148 execute();
1149 if (mReader->mCompositionChanges.size() != 0) {
1150 clearCommandReaderState();
1151 GTEST_SUCCEED();
1152 return;
1153 }
1154 ASSERT_EQ(0, mReader->mErrors.size());
1155 mWriter->presentDisplay();
1156 execute();
1157 ASSERT_EQ(0, mReader->mErrors.size());
1158 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1159 mTestRenderEngine->setRenderLayers(mLayers);
1160 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1161 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1162 }
1163 }
1164
1165 class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1166 protected:
SetUp()1167 void SetUp() override {
1168 GraphicsCompositionTest::SetUp();
1169
1170 mWriter->selectDisplay(mPrimaryDisplay);
1171
1172 auto backgroundLayer = std::make_shared<TestColorLayer>(mComposerClient, mPrimaryDisplay);
1173 backgroundLayer->setColor({0, 0, 0, 0});
1174 backgroundLayer->setDisplayFrame({0, 0, mDisplayWidth, mDisplayHeight});
1175 backgroundLayer->setZOrder(0);
1176
1177 mSideLength = mDisplayWidth < mDisplayHeight ? mDisplayWidth : mDisplayHeight;
1178 IComposerClient::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1179 IComposerClient::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength,
1180 mSideLength};
1181
1182 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1183 mPrimaryDisplay, mSideLength, mSideLength,
1184 PixelFormat::RGBA_8888);
1185 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1186 mLayer->setZOrder(10);
1187
1188 std::vector<IComposerClient::Color> baseColors(mSideLength * mSideLength);
1189 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1190 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1191 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1192
1193 mLayers = {backgroundLayer, mLayer};
1194 }
1195
1196 protected:
1197 std::shared_ptr<TestBufferLayer> mLayer;
1198 std::vector<IComposerClient::Color> baseColors;
1199 std::vector<std::shared_ptr<TestLayer>> mLayers;
1200 int mSideLength;
1201 };
1202
TEST_P(GraphicsTransformCompositionTest,FLIP_H)1203 TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1204 for (ColorMode mode : mTestColorModes) {
1205 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
1206 << std::endl;
1207 mWriter->selectDisplay(mPrimaryDisplay);
1208 ASSERT_NO_FATAL_FAILURE(
1209 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
1210
1211 mComposerClient->getRaw()->getReadbackBufferAttributes(
1212 mPrimaryDisplay,
1213 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
1214 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
1215 tmpDataspace, tmpError);
1216 mPixelFormat = tmpPixelFormat;
1217 mDataspace = tmpDataspace;
1218 });
1219
1220 if (!mHasReadbackBuffer) {
1221 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
1222 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1223 return;
1224 }
1225 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
1226 mDisplayHeight, mPixelFormat, mDataspace);
1227 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1228 mLayer->setTransform(Transform::FLIP_H);
1229 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1230
1231 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
1232 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
1233 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
1234 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
1235 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1236
1237 writeLayers(mLayers);
1238 ASSERT_EQ(0, mReader->mErrors.size());
1239 mWriter->validateDisplay();
1240 execute();
1241 if (mReader->mCompositionChanges.size() != 0) {
1242 clearCommandReaderState();
1243 GTEST_SUCCEED();
1244 return;
1245 }
1246 ASSERT_EQ(0, mReader->mErrors.size());
1247 mWriter->presentDisplay();
1248 execute();
1249 ASSERT_EQ(0, mReader->mErrors.size());
1250
1251 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1252 mTestRenderEngine->setRenderLayers(mLayers);
1253 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1254 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1255 }
1256 }
1257
TEST_P(GraphicsTransformCompositionTest,FLIP_V)1258 TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1259 for (ColorMode mode : mTestColorModes) {
1260 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
1261 << std::endl;
1262 mWriter->selectDisplay(mPrimaryDisplay);
1263 ASSERT_NO_FATAL_FAILURE(
1264 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
1265
1266 mComposerClient->getRaw()->getReadbackBufferAttributes(
1267 mPrimaryDisplay,
1268 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
1269 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
1270 tmpDataspace, tmpError);
1271 mPixelFormat = tmpPixelFormat;
1272 mDataspace = tmpDataspace;
1273 });
1274
1275 if (!mHasReadbackBuffer) {
1276 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
1277 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1278 return;
1279 }
1280 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
1281 mDisplayHeight, mPixelFormat, mDataspace);
1282 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1283
1284 mLayer->setTransform(Transform::FLIP_V);
1285 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1286
1287 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
1288 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
1289 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
1290 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
1291 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1292
1293 writeLayers(mLayers);
1294 ASSERT_EQ(0, mReader->mErrors.size());
1295 mWriter->validateDisplay();
1296 execute();
1297 if (mReader->mCompositionChanges.size() != 0) {
1298 clearCommandReaderState();
1299 GTEST_SUCCEED();
1300 return;
1301 }
1302 ASSERT_EQ(0, mReader->mErrors.size());
1303 mWriter->presentDisplay();
1304 execute();
1305 ASSERT_EQ(0, mReader->mErrors.size());
1306 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1307 mTestRenderEngine->setRenderLayers(mLayers);
1308 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1309 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1310 }
1311 }
1312
TEST_P(GraphicsTransformCompositionTest,ROT_180)1313 TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1314 for (ColorMode mode : mTestColorModes) {
1315 std::cout << "---Testing Color Mode " << ReadbackHelper::getColorModeString(mode) << "---"
1316 << std::endl;
1317 mWriter->selectDisplay(mPrimaryDisplay);
1318 ASSERT_NO_FATAL_FAILURE(
1319 mComposerClient->setColorMode(mPrimaryDisplay, mode, RenderIntent::COLORIMETRIC));
1320
1321 mComposerClient->getRaw()->getReadbackBufferAttributes(
1322 mPrimaryDisplay,
1323 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
1324 mHasReadbackBuffer = ReadbackHelper::readbackSupported(tmpPixelFormat,
1325 tmpDataspace, tmpError);
1326 mPixelFormat = tmpPixelFormat;
1327 mDataspace = tmpDataspace;
1328 });
1329
1330 if (!mHasReadbackBuffer) {
1331 std::cout << "Readback not supported or unsupported pixelFormat/dataspace" << std::endl;
1332 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1333 return;
1334 }
1335 ReadbackBuffer readbackBuffer(mPrimaryDisplay, mComposerClient, mDisplayWidth,
1336 mDisplayHeight, mPixelFormat, mDataspace);
1337 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1338
1339 mLayer->setTransform(Transform::ROT_180);
1340 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1341
1342 std::vector<IComposerClient::Color> expectedColors(mDisplayWidth * mDisplayHeight);
1343 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
1344 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1345 RED);
1346 ReadbackHelper::fillColorsArea(expectedColors, mDisplayWidth,
1347 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1348
1349 writeLayers(mLayers);
1350 ASSERT_EQ(0, mReader->mErrors.size());
1351 mWriter->validateDisplay();
1352 execute();
1353 if (mReader->mCompositionChanges.size() != 0) {
1354 clearCommandReaderState();
1355 GTEST_SUCCEED();
1356 return;
1357 }
1358 ASSERT_EQ(0, mReader->mErrors.size());
1359 mWriter->presentDisplay();
1360 execute();
1361 ASSERT_EQ(0, mReader->mErrors.size());
1362 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1363 mTestRenderEngine->setRenderLayers(mLayers);
1364 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1365 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1366 }
1367 }
1368
1369 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1370 INSTANTIATE_TEST_SUITE_P(
1371 PerInstance, GraphicsCompositionTest,
1372 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IComposer::descriptor)),
1373 android::hardware::PrintInstanceNameToString);
1374
1375 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1376 INSTANTIATE_TEST_CASE_P(
1377 BlendModeTest, GraphicsBlendModeCompositionTest,
1378 testing::Combine(
1379 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IComposer::descriptor)),
1380 testing::Values("0.2", "1.0")),
1381 android::hardware::PrintInstanceTupleNameToString<>);
1382
1383 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1384 INSTANTIATE_TEST_SUITE_P(
1385 PerInstance, GraphicsTransformCompositionTest,
1386 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IComposer::descriptor)),
1387 android::hardware::PrintInstanceNameToString);
1388
1389 } // anonymous namespace
1390 } // namespace vts
1391 } // namespace V2_2
1392 } // namespace composer
1393 } // namespace graphics
1394 } // namespace hardware
1395 } // namespace android
1396