blob: 166127dfae2e0eb2829e6d5b336db4b0ba95f9bd [file] [log] [blame]
ramindanibab8ba92021-11-18 01:24:11 +00001/**
2 * Copyright (c) 2021, 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_aidl_hal_readback_tests@3"
18
19#include <aidl/Gtest.h>
20#include <aidl/Vintf.h>
Ady Abraham46219f52021-12-20 09:44:31 -080021#include <aidl/android/hardware/graphics/composer3/IComposer.h>
ramindanibab8ba92021-11-18 01:24:11 +000022#include <gtest/gtest.h>
Alec Mouri51067012022-01-06 17:28:39 -080023#include <ui/DisplayId.h>
24#include <ui/DisplayIdentification.h>
ramindanibab8ba92021-11-18 01:24:11 +000025#include <ui/GraphicBuffer.h>
ramindanibab8ba92021-11-18 01:24:11 +000026#include <ui/PixelFormat.h>
27#include <ui/Rect.h>
ramindani458e53e2022-02-23 17:30:16 +000028#include "GraphicsComposerCallback.h"
29#include "ReadbackVts.h"
30#include "RenderEngineVts.h"
31#include "VtsComposerClient.h"
Alec Mouri51067012022-01-06 17:28:39 -080032
33// tinyxml2 does implicit conversions >:(
34#pragma clang diagnostic push
35#pragma clang diagnostic ignored "-Wconversion"
36#include <tinyxml2.h>
37#pragma clang diagnostic pop
ramindanibab8ba92021-11-18 01:24:11 +000038
39namespace aidl::android::hardware::graphics::composer3::vts {
40namespace {
41
42using ::android::Rect;
43using common::Dataspace;
44using common::PixelFormat;
45
46class GraphicsCompositionTestBase : public ::testing::Test {
47 protected:
48 void SetUpBase(const std::string& name) {
ramindanidcecfd42022-02-03 23:52:19 +000049 mComposerClient = std::make_shared<VtsComposerClient>(name);
50 ASSERT_TRUE(mComposerClient->createClient().isOk());
ramindanibab8ba92021-11-18 01:24:11 +000051
ramindanidcecfd42022-02-03 23:52:19 +000052 const auto& [status, displays] = mComposerClient->getDisplays();
53 ASSERT_TRUE(status.isOk());
54 mDisplays = displays;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -040055 mWriter.reset(new ComposerClientWriter(getPrimaryDisplayId()));
ramindanibab8ba92021-11-18 01:24:11 +000056
57 setTestColorModes();
58
59 // explicitly disable vsync
ramindanidcecfd42022-02-03 23:52:19 +000060 for (const auto& display : mDisplays) {
61 EXPECT_TRUE(mComposerClient->setVsync(display.getDisplayId(), /*enable*/ false).isOk());
62 }
63 mComposerClient->setVsyncAllowed(/*isAllowed*/ false);
ramindanibab8ba92021-11-18 01:24:11 +000064
ramindanidcecfd42022-02-03 23:52:19 +000065 EXPECT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::ON).isOk());
ramindanibab8ba92021-11-18 01:24:11 +000066
67 ASSERT_NO_FATAL_FAILURE(
68 mTestRenderEngine = std::unique_ptr<TestRenderEngine>(new TestRenderEngine(
69 ::android::renderengine::RenderEngineCreationArgs::Builder()
70 .setPixelFormat(static_cast<int>(common::PixelFormat::RGBA_8888))
71 .setImageCacheSize(TestRenderEngine::sMaxFrameBufferAcquireBuffers)
72 .setUseColorManagerment(true)
73 .setEnableProtectedContext(false)
74 .setPrecacheToneMapperShaderOnly(false)
75 .setContextPriority(::android::renderengine::RenderEngine::
76 ContextPriority::HIGH)
77 .build())));
78
79 ::android::renderengine::DisplaySettings clientCompositionDisplay;
ramindanidcecfd42022-02-03 23:52:19 +000080 clientCompositionDisplay.physicalDisplay = Rect(getDisplayWidth(), getDisplayHeight());
ramindanibab8ba92021-11-18 01:24:11 +000081 clientCompositionDisplay.clip = clientCompositionDisplay.physicalDisplay;
82
Brian Lindahld103cd62022-12-09 07:26:28 -070083 mTestRenderEngine->initGraphicBuffer(static_cast<uint32_t>(getDisplayWidth()),
84 static_cast<uint32_t>(getDisplayHeight()),
85 /*layerCount*/ 1U,
86 GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_SW_READ_OFTEN |
87 GRALLOC_USAGE_SW_WRITE_OFTEN);
ramindanibab8ba92021-11-18 01:24:11 +000088 mTestRenderEngine->setDisplaySettings(clientCompositionDisplay);
89 }
90
91 void TearDown() override {
ramindanidcecfd42022-02-03 23:52:19 +000092 ASSERT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::OFF).isOk());
93 ASSERT_TRUE(mComposerClient->tearDown());
94 mComposerClient.reset();
Ady Abraham3192f3d2021-12-03 16:08:56 -080095 const auto errors = mReader.takeErrors();
96 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +000097 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
ramindanibab8ba92021-11-18 01:24:11 +000098 }
99
ramindanidcecfd42022-02-03 23:52:19 +0000100 const VtsDisplay& getPrimaryDisplay() const { return mDisplays[0]; }
101
102 int64_t getPrimaryDisplayId() const { return getPrimaryDisplay().getDisplayId(); }
103
104 int64_t getInvalidDisplayId() const { return mComposerClient->getInvalidDisplayId(); }
105
106 int32_t getDisplayWidth() const { return getPrimaryDisplay().getDisplayWidth(); }
107
108 int32_t getDisplayHeight() const { return getPrimaryDisplay().getDisplayHeight(); }
109
ramindanid5751092022-04-22 22:30:20 +0000110 void assertServiceSpecificError(const ScopedAStatus& status, int32_t serviceSpecificError) {
111 ASSERT_EQ(status.getExceptionCode(), EX_SERVICE_SPECIFIC);
112 ASSERT_EQ(status.getServiceSpecificError(), serviceSpecificError);
113 }
114
Brian Lindahld103cd62022-12-09 07:26:28 -0700115 sp<GraphicBuffer> allocateBuffer(uint32_t width, uint32_t height, uint64_t usage) {
116 sp<GraphicBuffer> graphicBuffer =
117 sp<GraphicBuffer>::make(width, height, ::android::PIXEL_FORMAT_RGBA_8888,
118 /*layerCount*/ 1u, static_cast<uint32_t>(usage),
119 "VtsHalGraphicsComposer3_ReadbackTest");
ramindani0a2bee42022-02-10 01:27:42 +0000120
121 if (graphicBuffer && ::android::OK == graphicBuffer->initCheck()) {
Brian Lindahld103cd62022-12-09 07:26:28 -0700122 return graphicBuffer;
ramindani0a2bee42022-02-10 01:27:42 +0000123 }
Brian Lindahld103cd62022-12-09 07:26:28 -0700124 return nullptr;
125 }
126
127 sp<GraphicBuffer> allocateBuffer(uint64_t usage) {
128 return allocateBuffer(static_cast<uint32_t>(getDisplayWidth()),
129 static_cast<uint32_t>(getDisplayHeight()), usage);
ramindanibab8ba92021-11-18 01:24:11 +0000130 }
131
Alec Mouri51067012022-01-06 17:28:39 -0800132 uint64_t getStableDisplayId(int64_t display) {
ramindanidcecfd42022-02-03 23:52:19 +0000133 const auto& [status, identification] =
134 mComposerClient->getDisplayIdentificationData(display);
135 EXPECT_TRUE(status.isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800136
137 if (const auto info = ::android::parseDisplayIdentificationData(
138 static_cast<uint8_t>(identification.port), identification.data)) {
139 return info->id.value;
140 }
141
142 return ::android::PhysicalDisplayId::fromPort(static_cast<uint8_t>(identification.port))
143 .value;
144 }
145
146 // Gets the per-display XML config
147 std::unique_ptr<tinyxml2::XMLDocument> getDisplayConfigXml(int64_t display) {
148 std::stringstream pathBuilder;
149 pathBuilder << "/vendor/etc/displayconfig/display_id_" << getStableDisplayId(display)
150 << ".xml";
151 const std::string path = pathBuilder.str();
152 auto document = std::make_unique<tinyxml2::XMLDocument>();
153 const tinyxml2::XMLError error = document->LoadFile(path.c_str());
154 if (error == tinyxml2::XML_SUCCESS) {
155 return document;
156 } else {
157 return nullptr;
158 }
159 }
160
161 // Gets the max display brightness for this display.
162 // If the display config xml does not exist, then assume that the display is not well-configured
163 // enough to provide a display brightness, so return nullopt.
164 std::optional<float> getMaxDisplayBrightnessNits(int64_t display) {
165 const auto document = getDisplayConfigXml(display);
166 if (!document) {
167 // Assume the device doesn't support display brightness
168 return std::nullopt;
169 }
170
171 const auto root = document->RootElement();
172 if (!root) {
173 // If there's somehow no root element, then this isn't a valid config
174 return std::nullopt;
175 }
176
177 const auto screenBrightnessMap = root->FirstChildElement("screenBrightnessMap");
178 if (!screenBrightnessMap) {
179 // A valid display config must have a screen brightness map
180 return std::nullopt;
181 }
182
183 auto point = screenBrightnessMap->FirstChildElement("point");
184 float maxNits = -1.f;
185 while (point != nullptr) {
186 const auto nits = point->FirstChildElement("nits");
187 if (nits) {
188 maxNits = std::max(maxNits, nits->FloatText(-1.f));
189 }
190 point = point->NextSiblingElement("point");
191 }
192
193 if (maxNits < 0.f) {
194 // If we got here, then there were no point elements containing a nit value, so this
195 // config isn't valid
196 return std::nullopt;
197 }
198
199 return maxNits;
200 }
201
ramindanibab8ba92021-11-18 01:24:11 +0000202 void writeLayers(const std::vector<std::shared_ptr<TestLayer>>& layers) {
ramindanidcecfd42022-02-03 23:52:19 +0000203 for (const auto& layer : layers) {
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400204 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000205 }
206 execute();
207 }
208
209 void execute() {
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400210 const auto& commands = mWriter->getPendingCommands();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800211 if (commands.empty()) {
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400212 mWriter->reset();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800213 return;
ramindanibab8ba92021-11-18 01:24:11 +0000214 }
215
ramindanidcecfd42022-02-03 23:52:19 +0000216 auto [status, results] = mComposerClient->executeCommands(commands);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800217 ASSERT_TRUE(status.isOk()) << "executeCommands failed " << status.getDescription();
ramindanibab8ba92021-11-18 01:24:11 +0000218
Ady Abraham46219f52021-12-20 09:44:31 -0800219 mReader.parse(std::move(results));
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400220 mWriter->reset();
ramindanibab8ba92021-11-18 01:24:11 +0000221 }
222
ramindani44c952f2022-02-28 23:29:29 +0000223 bool getHasReadbackBuffer() {
ramindanidcecfd42022-02-03 23:52:19 +0000224 auto [status, readBackBufferAttributes] =
225 mComposerClient->getReadbackBufferAttributes(getPrimaryDisplayId());
226 if (status.isOk()) {
227 mPixelFormat = readBackBufferAttributes.format;
228 mDataspace = readBackBufferAttributes.dataspace;
ramindani44c952f2022-02-28 23:29:29 +0000229 return ReadbackHelper::readbackSupported(mPixelFormat, mDataspace);
ramindanidcecfd42022-02-03 23:52:19 +0000230 }
ramindanid5751092022-04-22 22:30:20 +0000231 EXPECT_NO_FATAL_FAILURE(
232 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
ramindani44c952f2022-02-28 23:29:29 +0000233 return false;
ramindanib27f33b2021-12-03 19:36:10 +0000234 }
235
ramindanidcecfd42022-02-03 23:52:19 +0000236 std::shared_ptr<VtsComposerClient> mComposerClient;
237 std::vector<VtsDisplay> mDisplays;
238 // use the slot count usually set by SF
ramindanibab8ba92021-11-18 01:24:11 +0000239 std::vector<ColorMode> mTestColorModes;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400240 std::unique_ptr<ComposerClientWriter> mWriter;
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800241 ComposerClientReader mReader;
ramindanibab8ba92021-11-18 01:24:11 +0000242 std::unique_ptr<TestRenderEngine> mTestRenderEngine;
ramindanibab8ba92021-11-18 01:24:11 +0000243 common::PixelFormat mPixelFormat;
244 common::Dataspace mDataspace;
245
246 static constexpr uint32_t kClientTargetSlotCount = 64;
247
248 private:
ramindanibab8ba92021-11-18 01:24:11 +0000249 void setTestColorModes() {
250 mTestColorModes.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000251 const auto& [status, modes] = mComposerClient->getColorModes(getPrimaryDisplayId());
252 ASSERT_TRUE(status.isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000253
254 for (ColorMode mode : modes) {
255 if (std::find(ReadbackHelper::colorModes.begin(), ReadbackHelper::colorModes.end(),
256 mode) != ReadbackHelper::colorModes.end()) {
257 mTestColorModes.push_back(mode);
258 }
259 }
260 }
261};
262
263class GraphicsCompositionTest : public GraphicsCompositionTestBase,
264 public testing::WithParamInterface<std::string> {
265 public:
266 void SetUp() override { SetUpBase(GetParam()); }
267};
268
269TEST_P(GraphicsCompositionTest, SingleSolidColorLayer) {
270 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000271 EXPECT_TRUE(mComposerClient
272 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
273 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000274
ramindani44c952f2022-02-28 23:29:29 +0000275 bool isSupported;
276 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000277 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000278 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
279 return;
280 }
281
ramindanidcecfd42022-02-03 23:52:19 +0000282 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
283 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000284 layer->setColor(BLUE);
285 layer->setDisplayFrame(coloredSquare);
286 layer->setZOrder(10);
287
288 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
289
290 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000291 std::vector<Color> expectedColors(
292 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
293 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000294
ramindanidcecfd42022-02-03 23:52:19 +0000295 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -0700296 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000297 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
298
299 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800300 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400301 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000302 execute();
303 // if hwc cannot handle and asks for composition change,
304 // just succeed the test
ramindanidcecfd42022-02-03 23:52:19 +0000305 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000306 GTEST_SUCCEED();
307 return;
308 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800309 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400310 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000311 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800312 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000313
314 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
315 mTestRenderEngine->setRenderLayers(layers);
316 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
317 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
318 }
319}
320
321TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
322 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000323 EXPECT_TRUE(mComposerClient
324 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
325 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000326
ramindani44c952f2022-02-28 23:29:29 +0000327 bool isSupported;
328 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000329 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000330 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
331 return;
332 }
333
ramindanidcecfd42022-02-03 23:52:19 +0000334 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -0700335 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000336 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000337 std::vector<Color> expectedColors(
338 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
339 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
340 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
341 ReadbackHelper::fillColorsArea(
342 expectedColors, getDisplayWidth(),
343 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
344 ReadbackHelper::fillColorsArea(
345 expectedColors, getDisplayWidth(),
346 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000347
348 auto layer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000349 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
350 getDisplayHeight(), common::PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000351 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000352 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400353 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000354 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
355
356 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
357
358 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800359 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400360 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000361 execute();
362
ramindanidcecfd42022-02-03 23:52:19 +0000363 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000364 GTEST_SUCCEED();
365 return;
366 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800367 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000368
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400369 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000370 execute();
371
Ady Abraham3192f3d2021-12-03 16:08:56 -0800372 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000373
374 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
375 mTestRenderEngine->setRenderLayers(layers);
376 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
377 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
378 }
379}
380
Brian Lindahld103cd62022-12-09 07:26:28 -0700381TEST_P(GraphicsCompositionTest, SetLayerBufferWithSlotsToClear) {
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700382 const auto& [versionStatus, version] = mComposerClient->getInterfaceVersion();
383 ASSERT_TRUE(versionStatus.isOk());
384 if (version == 1) {
385 GTEST_SUCCEED() << "Device does not support the new API for clearing buffer slots";
386 return;
387 }
388
389 const auto& [readbackStatus, readbackBufferAttributes] =
Brian Lindahld103cd62022-12-09 07:26:28 -0700390 mComposerClient->getReadbackBufferAttributes(getPrimaryDisplayId());
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700391 if (!readbackStatus.isOk()) {
Brian Lindahld103cd62022-12-09 07:26:28 -0700392 GTEST_SUCCEED() << "Readback not supported";
393 return;
394 }
395
396 sp<GraphicBuffer> readbackBuffer;
397 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::createReadbackBuffer(
398 readbackBufferAttributes, getPrimaryDisplay(), &readbackBuffer));
399 if (readbackBuffer == nullptr) {
400 GTEST_SUCCEED() << "Unsupported readback buffer attributes";
401 return;
402 }
403 // no fence needed for the readback buffer
404 ScopedFileDescriptor noFence(-1);
405
Brian Lindahld103cd62022-12-09 07:26:28 -0700406 // red buffer
407 uint64_t usage = GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN;
408 sp<GraphicBuffer> redBuffer = allocateBuffer(usage);
409 ASSERT_NE(nullptr, redBuffer);
410 int redFence;
411 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBufferAndGetFence(redBuffer, RED, &redFence));
412
413 // blue buffer
414 sp<GraphicBuffer> blueBuffer = allocateBuffer(usage);
415 ASSERT_NE(nullptr, blueBuffer);
416 int blueFence;
417 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBufferAndGetFence(blueBuffer, BLUE, &blueFence));
418
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700419 // green buffer
420 sp<GraphicBuffer> greenBuffer = allocateBuffer(usage);
421 ASSERT_NE(nullptr, greenBuffer);
422 int greenFence;
423 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBufferAndGetFence(greenBuffer, GREEN, &greenFence));
424
Brian Lindahld103cd62022-12-09 07:26:28 -0700425 // layer defaults
426 common::Rect rectFullDisplay = {0, 0, getDisplayWidth(), getDisplayHeight()};
427 int64_t display = getPrimaryDisplayId();
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700428 const auto& [layerStatus, layer] = mComposerClient->createLayer(getPrimaryDisplayId(), 3);
Brian Lindahld103cd62022-12-09 07:26:28 -0700429 ASSERT_TRUE(layerStatus.isOk());
430 mWriter->setLayerDisplayFrame(display, layer, rectFullDisplay);
431 mWriter->setLayerCompositionType(display, layer, Composition::DEVICE);
432
433 // set the layer to the blue buffer
434 // should be blue
435 {
436 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
437 ASSERT_TRUE(status.isOk());
438 mWriter->setLayerBuffer(display, layer, /*slot*/ 0, blueBuffer->handle, blueFence);
439 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
440 execute();
441 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
442 ASSERT_TRUE(mReader.takeErrors().empty());
443 mWriter->presentDisplay(display);
444 execute();
445 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
446 ASSERT_TRUE(fenceStatus.isOk());
447 ReadbackHelper::compareColorToBuffer(BLUE, readbackBuffer, fence);
448 }
449
450 // change the layer to the red buffer
451 // should be red
452 {
453 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
454 ASSERT_TRUE(status.isOk());
455 mWriter->setLayerBuffer(display, layer, /*slot*/ 1, redBuffer->handle, redFence);
456 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
457 execute();
458 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
459 ASSERT_TRUE(mReader.takeErrors().empty());
460 mWriter->presentDisplay(display);
461 execute();
462 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
463 ASSERT_TRUE(fenceStatus.isOk());
464 ReadbackHelper::compareColorToBuffer(RED, readbackBuffer, fence);
465 }
466
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700467 // change the layer to the green buffer
468 // should be green
Brian Lindahld103cd62022-12-09 07:26:28 -0700469 {
470 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
471 ASSERT_TRUE(status.isOk());
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700472 mWriter->setLayerBuffer(display, layer, /*slot*/ 2, greenBuffer->handle, greenFence);
Brian Lindahld103cd62022-12-09 07:26:28 -0700473 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
474 execute();
475 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
476 ASSERT_TRUE(mReader.takeErrors().empty());
477 mWriter->presentDisplay(display);
478 execute();
479 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
480 ASSERT_TRUE(fenceStatus.isOk());
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700481 ReadbackHelper::compareColorToBuffer(GREEN, readbackBuffer, fence);
Brian Lindahld103cd62022-12-09 07:26:28 -0700482 }
483
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700484 // clear the slots for all buffers
485 // should still be green since the active buffer should not be cleared by the HAL implementation
486 {
487 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
488 ASSERT_TRUE(status.isOk());
489 mWriter->setLayerBufferSlotsToClear(display, layer, /*slotsToClear*/ {0, 1, 2});
490 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
491 execute();
492 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
493 ASSERT_TRUE(mReader.takeErrors().empty());
494 mWriter->presentDisplay(display);
495 execute();
496 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
497 ASSERT_TRUE(fenceStatus.isOk());
498 ReadbackHelper::compareColorToBuffer(GREEN, readbackBuffer, fence);
499 }
500
501 // clear the slot for the green buffer, and set the buffer with the same slot to the blue buffer
Brian Lindahld103cd62022-12-09 07:26:28 -0700502 // should be blue
503 {
504 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
505 ASSERT_TRUE(status.isOk());
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700506 mWriter->setLayerBufferSlotsToClear(display, layer, /*slotsToClear*/ {2});
507 mWriter->setLayerBuffer(display, layer, /*slot*/ 2, blueBuffer->handle, blueFence);
508 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
509 execute();
510 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
511 ASSERT_TRUE(mReader.takeErrors().empty());
512 mWriter->presentDisplay(display);
513 execute();
514 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
515 ASSERT_TRUE(fenceStatus.isOk());
516 ReadbackHelper::compareColorToBuffer(BLUE, readbackBuffer, fence);
517 }
518}
519
520TEST_P(GraphicsCompositionTest, SetLayerBufferWithSlotsToClear_backwardsCompatible) {
521 const auto& [versionStatus, version] = mComposerClient->getInterfaceVersion();
522 ASSERT_TRUE(versionStatus.isOk());
523 if (version > 1) {
524 GTEST_SUCCEED() << "Device does not need a backwards compatible way to clear buffer slots";
525 return;
526 }
527
528 const auto& [readbackStatus, readbackBufferAttributes] =
529 mComposerClient->getReadbackBufferAttributes(getPrimaryDisplayId());
530 if (!readbackStatus.isOk()) {
531 GTEST_SUCCEED() << "Readback not supported";
532 return;
533 }
534
535 sp<GraphicBuffer> readbackBuffer;
536 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::createReadbackBuffer(
537 readbackBufferAttributes, getPrimaryDisplay(), &readbackBuffer));
538 if (readbackBuffer == nullptr) {
539 GTEST_SUCCEED() << "Unsupported readback buffer attributes";
540 return;
541 }
542 // no fence needed for the readback buffer
543 ScopedFileDescriptor noFence(-1);
544
545 sp<GraphicBuffer> clearSlotBuffer = allocateBuffer(1u, 1u, GRALLOC_USAGE_HW_COMPOSER);
546 ASSERT_NE(nullptr, clearSlotBuffer);
547
548 // red buffer
549 uint64_t usage = GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN;
550 sp<GraphicBuffer> redBuffer = allocateBuffer(usage);
551 ASSERT_NE(nullptr, redBuffer);
552 int redFence;
553 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBufferAndGetFence(redBuffer, RED, &redFence));
554
555 // blue buffer
556 sp<GraphicBuffer> blueBuffer = allocateBuffer(usage);
557 ASSERT_NE(nullptr, blueBuffer);
558 int blueFence;
559 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBufferAndGetFence(blueBuffer, BLUE, &blueFence));
560
561 // green buffer
562 sp<GraphicBuffer> greenBuffer = allocateBuffer(usage);
563 ASSERT_NE(nullptr, greenBuffer);
564 int greenFence;
565 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBufferAndGetFence(greenBuffer, GREEN, &greenFence));
566
567 // layer defaults
568 common::Rect rectFullDisplay = {0, 0, getDisplayWidth(), getDisplayHeight()};
569 int64_t display = getPrimaryDisplayId();
570 const auto& [layerStatus, layer] = mComposerClient->createLayer(getPrimaryDisplayId(), 3);
571 ASSERT_TRUE(layerStatus.isOk());
572 mWriter->setLayerDisplayFrame(display, layer, rectFullDisplay);
573 mWriter->setLayerCompositionType(display, layer, Composition::DEVICE);
574
575 // set the layer to the blue buffer
576 // should be blue
577 {
578 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
579 ASSERT_TRUE(status.isOk());
580 mWriter->setLayerBuffer(display, layer, /*slot*/ 0, blueBuffer->handle, blueFence);
Brian Lindahld103cd62022-12-09 07:26:28 -0700581 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
582 execute();
583 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
584 ASSERT_TRUE(mReader.takeErrors().empty());
585 mWriter->presentDisplay(display);
586 execute();
587 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
588 ASSERT_TRUE(fenceStatus.isOk());
589 ReadbackHelper::compareColorToBuffer(BLUE, readbackBuffer, fence);
590 }
591
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700592 // change the layer to the red buffer
593 // should be red
Brian Lindahld103cd62022-12-09 07:26:28 -0700594 {
595 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
596 ASSERT_TRUE(status.isOk());
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700597 mWriter->setLayerBuffer(display, layer, /*slot*/ 1, redBuffer->handle, redFence);
Brian Lindahld103cd62022-12-09 07:26:28 -0700598 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
599 execute();
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700600 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
Brian Lindahld103cd62022-12-09 07:26:28 -0700601 ASSERT_TRUE(mReader.takeErrors().empty());
602 mWriter->presentDisplay(display);
603 execute();
604 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
605 ASSERT_TRUE(fenceStatus.isOk());
Brian Lindahl78ff2d62022-12-18 11:21:41 -0700606 ReadbackHelper::compareColorToBuffer(RED, readbackBuffer, fence);
607 }
608
609 // change the layer to the green buffer
610 // should be green
611 {
612 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
613 ASSERT_TRUE(status.isOk());
614 mWriter->setLayerBuffer(display, layer, /*slot*/ 2, greenBuffer->handle, greenFence);
615 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
616 execute();
617 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
618 ASSERT_TRUE(mReader.takeErrors().empty());
619 mWriter->presentDisplay(display);
620 execute();
621 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
622 ASSERT_TRUE(fenceStatus.isOk());
623 ReadbackHelper::compareColorToBuffer(GREEN, readbackBuffer, fence);
624 }
625
626 // clear the slot for the blue buffer
627 // should still be green
628 {
629 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
630 ASSERT_TRUE(status.isOk());
631 mWriter->setLayerBufferWithNewCommand(display, layer, /*slot*/ 0, clearSlotBuffer->handle,
632 /*fence*/ -1);
633 // SurfaceFlinger will re-set the active buffer slot after other buffer slots are cleared
634 mWriter->setLayerBufferWithNewCommand(display, layer, /*slot*/ 2, /*handle*/ nullptr,
635 /*fence*/ -1);
636 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
637 execute();
638 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
639 ASSERT_TRUE(mReader.takeErrors().empty());
640 mWriter->presentDisplay(display);
641 execute();
642 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
643 ASSERT_TRUE(fenceStatus.isOk());
644 ReadbackHelper::compareColorToBuffer(GREEN, readbackBuffer, fence);
645 }
646
647 // clear the slot for all buffers, and set the buffer with the same slot as the green buffer
648 // should be blue now
649 {
650 auto status = mComposerClient->setReadbackBuffer(display, readbackBuffer->handle, noFence);
651 ASSERT_TRUE(status.isOk());
652 mWriter->setLayerBufferWithNewCommand(display, layer, /*slot*/ 0, clearSlotBuffer->handle,
653 /*fence*/ -1);
654 mWriter->setLayerBufferWithNewCommand(display, layer, /*slot*/ 1, clearSlotBuffer->handle,
655 /*fence*/ -1);
656 // SurfaceFlinger will never clear the active buffer (slot 2), but will free up the
657 // buffer slot so it will be re-used for the next setLayerBuffer command
658 mWriter->setLayerBuffer(display, layer, /*slot*/ 2, blueBuffer->handle, blueFence);
659 mWriter->validateDisplay(display, ComposerClientWriter::kNoTimestamp);
660 execute();
661 ASSERT_TRUE(mReader.takeChangedCompositionTypes(display).empty());
662 ASSERT_TRUE(mReader.takeErrors().empty());
663 mWriter->presentDisplay(display);
664 execute();
665 auto [fenceStatus, fence] = mComposerClient->getReadbackBufferFence(display);
666 ASSERT_TRUE(fenceStatus.isOk());
667 ReadbackHelper::compareColorToBuffer(BLUE, readbackBuffer, fence);
Brian Lindahld103cd62022-12-09 07:26:28 -0700668 }
669}
670
ramindanibab8ba92021-11-18 01:24:11 +0000671TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
672 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000673 EXPECT_TRUE(mComposerClient
674 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
675 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000676
ramindani44c952f2022-02-28 23:29:29 +0000677 bool isSupported;
678 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000679 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000680 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
681 return;
682 }
683
ramindanidcecfd42022-02-03 23:52:19 +0000684 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
685 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000686 layer->setColor(BLUE);
687 layer->setDisplayFrame(coloredSquare);
688 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400689 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000690
691 // This following buffer call should have no effect
Brian Lindahld103cd62022-12-09 07:26:28 -0700692 uint64_t usage = GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN;
693 sp<GraphicBuffer> graphicBuffer = allocateBuffer(usage);
694 ASSERT_NE(nullptr, graphicBuffer);
ramindani0a2bee42022-02-10 01:27:42 +0000695 const auto& buffer = graphicBuffer->handle;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400696 mWriter->setLayerBuffer(getPrimaryDisplayId(), layer->getLayer(), /*slot*/ 0, buffer,
697 /*acquireFence*/ -1);
ramindanibab8ba92021-11-18 01:24:11 +0000698
699 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000700 std::vector<Color> expectedColors(
701 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
702 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000703
ramindanidcecfd42022-02-03 23:52:19 +0000704 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -0700705 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000706 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
707
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400708 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000709 execute();
710
ramindanidcecfd42022-02-03 23:52:19 +0000711 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000712 GTEST_SUCCEED();
713 return;
714 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800715 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400716 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000717 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800718 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000719
720 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
721 }
722}
723
ramindanib27f33b2021-12-03 19:36:10 +0000724TEST_P(GraphicsCompositionTest, SetReadbackBuffer) {
ramindani44c952f2022-02-28 23:29:29 +0000725 bool isSupported;
726 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000727 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000728 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
729 return;
730 }
731
ramindanidcecfd42022-02-03 23:52:19 +0000732 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -0700733 getDisplayHeight(), mPixelFormat);
ramindanib27f33b2021-12-03 19:36:10 +0000734
735 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
736}
737
ramindanidcecfd42022-02-03 23:52:19 +0000738TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadDisplay) {
ramindani44c952f2022-02-28 23:29:29 +0000739 bool isSupported;
740 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000741 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000742 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
743 return;
744 }
745
Brian Lindahld103cd62022-12-09 07:26:28 -0700746 uint64_t usage = GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN;
747 sp<GraphicBuffer> graphicBuffer = allocateBuffer(usage);
748 ASSERT_NE(nullptr, graphicBuffer);
ramindani0a2bee42022-02-10 01:27:42 +0000749 const auto& bufferHandle = graphicBuffer->handle;
ramindanib27f33b2021-12-03 19:36:10 +0000750 ::ndk::ScopedFileDescriptor fence = ::ndk::ScopedFileDescriptor(-1);
751
ramindanidcecfd42022-02-03 23:52:19 +0000752 const auto status =
753 mComposerClient->setReadbackBuffer(getInvalidDisplayId(), bufferHandle, fence);
ramindanib27f33b2021-12-03 19:36:10 +0000754
ramindanidcecfd42022-02-03 23:52:19 +0000755 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000756 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
ramindanib27f33b2021-12-03 19:36:10 +0000757}
758
ramindanidcecfd42022-02-03 23:52:19 +0000759TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadParameter) {
ramindani44c952f2022-02-28 23:29:29 +0000760 bool isSupported;
761 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000762 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000763 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
764 return;
765 }
766
ramindanidcecfd42022-02-03 23:52:19 +0000767 const native_handle_t bufferHandle{};
ramindanib27f33b2021-12-03 19:36:10 +0000768 ndk::ScopedFileDescriptor releaseFence = ndk::ScopedFileDescriptor(-1);
ramindanidcecfd42022-02-03 23:52:19 +0000769 const auto status =
770 mComposerClient->setReadbackBuffer(getPrimaryDisplayId(), &bufferHandle, releaseFence);
ramindanib27f33b2021-12-03 19:36:10 +0000771
ramindanidcecfd42022-02-03 23:52:19 +0000772 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000773 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
ramindanib27f33b2021-12-03 19:36:10 +0000774}
775
776TEST_P(GraphicsCompositionTest, GetReadbackBufferFenceInactive) {
ramindani44c952f2022-02-28 23:29:29 +0000777 bool isSupported;
778 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000779 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000780 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
781 return;
782 }
783
ramindanidcecfd42022-02-03 23:52:19 +0000784 const auto& [status, releaseFence] =
785 mComposerClient->getReadbackBufferFence(getPrimaryDisplayId());
ramindanib27f33b2021-12-03 19:36:10 +0000786
ramindanidcecfd42022-02-03 23:52:19 +0000787 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000788 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
Alec Mouri62ae37b2022-01-20 17:16:38 -0800789 EXPECT_EQ(-1, releaseFence.get());
ramindanib27f33b2021-12-03 19:36:10 +0000790}
791
ramindanibab8ba92021-11-18 01:24:11 +0000792TEST_P(GraphicsCompositionTest, ClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000793 EXPECT_TRUE(
794 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
795 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000796
797 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000798 EXPECT_TRUE(mComposerClient
799 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
ramindanibab8ba92021-11-18 01:24:11 +0000800 .isOk());
801
ramindani44c952f2022-02-28 23:29:29 +0000802 bool isSupported;
803 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000804 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000805 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
806 return;
807 }
808
ramindanidcecfd42022-02-03 23:52:19 +0000809 std::vector<Color> expectedColors(
810 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
811 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
812 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
813 ReadbackHelper::fillColorsArea(
814 expectedColors, getDisplayWidth(),
815 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
816 ReadbackHelper::fillColorsArea(
817 expectedColors, getDisplayWidth(),
818 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000819
ramindani0a2bee42022-02-10 01:27:42 +0000820 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
821 getPrimaryDisplayId(), getDisplayWidth(),
822 getDisplayHeight(), PixelFormat::RGBA_FP16);
ramindanidcecfd42022-02-03 23:52:19 +0000823 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000824 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400825 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000826
827 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
828
ramindanidcecfd42022-02-03 23:52:19 +0000829 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -0700830 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000831 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
832 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800833 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400834 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000835 execute();
836
ramindanidcecfd42022-02-03 23:52:19 +0000837 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800838 if (!changedCompositionTypes.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800839 ASSERT_EQ(1, changedCompositionTypes.size());
Ady Abraham46219f52021-12-20 09:44:31 -0800840 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindanibab8ba92021-11-18 01:24:11 +0000841
842 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahld103cd62022-12-09 07:26:28 -0700843 auto clientUsage = GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_OFTEN |
844 GRALLOC_USAGE_SW_WRITE_OFTEN;
ramindanibab8ba92021-11-18 01:24:11 +0000845 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000846 common::Rect damage{0, 0, getDisplayWidth(), getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000847
848 // create client target buffer
Brian Lindahld103cd62022-12-09 07:26:28 -0700849 sp<GraphicBuffer> graphicBuffer = allocateBuffer(clientUsage);
850 ASSERT_NE(nullptr, graphicBuffer);
ramindani0a2bee42022-02-10 01:27:42 +0000851 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000852 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000853 const auto stride = static_cast<uint32_t>(graphicBuffer->stride);
854 graphicBuffer->lock(clientUsage, layer->getAccessRegion(), &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000855
856 ASSERT_NO_FATAL_FAILURE(
ramindani0a2bee42022-02-10 01:27:42 +0000857 ReadbackHelper::fillBuffer(layer->getWidth(), layer->getHeight(), stride,
ramindanibab8ba92021-11-18 01:24:11 +0000858 clientBufData, clientFormat, expectedColors));
ramindanib1144212022-02-10 01:51:24 +0000859 int32_t clientFence;
860 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
861 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400862 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
863 clientDataspace, std::vector<common::Rect>(1, damage));
864 layer->setToClientComposition(*mWriter);
865 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000866 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000867 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800868 ASSERT_TRUE(changedCompositionTypes.empty());
ramindanibab8ba92021-11-18 01:24:11 +0000869 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800870 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000871
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400872 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000873 execute();
874
Ady Abraham3192f3d2021-12-03 16:08:56 -0800875 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000876
877 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
878 }
879}
880
881TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000882 ASSERT_TRUE(
883 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
884 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000885
886 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000887 EXPECT_TRUE(mComposerClient
888 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
889 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000890
ramindani44c952f2022-02-28 23:29:29 +0000891 bool isSupported;
892 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000893 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000894 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
895 return;
896 }
897
ramindanidcecfd42022-02-03 23:52:19 +0000898 std::vector<Color> expectedColors(
899 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
900 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
901 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
902 ReadbackHelper::fillColorsArea(
903 expectedColors, getDisplayWidth(),
904 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000905
ramindanidcecfd42022-02-03 23:52:19 +0000906 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -0700907 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +0000908 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
909
910 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000911 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
912 getDisplayHeight() / 2, PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +0000913 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
914 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
915 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
916 static_cast<int32_t>(deviceLayer->getHeight())},
917 GREEN);
918 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
919 static_cast<int32_t>(deviceLayer->getHeight())});
920 deviceLayer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400921 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000922 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400923 deviceLayer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000924
925 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahld103cd62022-12-09 07:26:28 -0700926 auto clientUsage =
927 GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
ramindanibab8ba92021-11-18 01:24:11 +0000928 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000929 int32_t clientWidth = getDisplayWidth();
930 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000931
932 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000933 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
934 clientHeight, PixelFormat::RGBA_FP16, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000935 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
936 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000937 clientLayer->setDisplayFrame(clientFrame);
938 clientLayer->setZOrder(0);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400939 clientLayer->write(*mWriter);
940 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000941 execute();
942
ramindanidcecfd42022-02-03 23:52:19 +0000943 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800944 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000945 continue;
946 }
947 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800948 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
Brian Lindahld103cd62022-12-09 07:26:28 -0700949 sp<GraphicBuffer> graphicBuffer = allocateBuffer(clientUsage);
950 ASSERT_NE(nullptr, graphicBuffer);
ramindani0a2bee42022-02-10 01:27:42 +0000951 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000952
953 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000954 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
955 &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000956
ramindanidcecfd42022-02-03 23:52:19 +0000957 std::vector<Color> clientColors(
958 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
959 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000960 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000961 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
ramindani0a2bee42022-02-10 01:27:42 +0000962 graphicBuffer->getStride(), clientBufData, clientFormat, clientColors));
ramindanib1144212022-02-10 01:51:24 +0000963 int32_t clientFence;
964 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
965 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400966 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
967 clientDataspace, std::vector<common::Rect>(1, clientFrame));
968 clientLayer->setToClientComposition(*mWriter);
969 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000970 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000971 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800972 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800973 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000974
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400975 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000976 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800977 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000978 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
979 }
980}
981
982TEST_P(GraphicsCompositionTest, SetLayerDamage) {
983 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000984 EXPECT_TRUE(mComposerClient
985 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
986 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000987
ramindani44c952f2022-02-28 23:29:29 +0000988 bool isSupported;
989 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000990 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000991 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
992 return;
993 }
994
ramindanidcecfd42022-02-03 23:52:19 +0000995 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000996
ramindanidcecfd42022-02-03 23:52:19 +0000997 std::vector<Color> expectedColors(
998 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
999 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +00001000
ramindani0a2bee42022-02-10 01:27:42 +00001001 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1002 getPrimaryDisplayId(), getDisplayWidth(),
1003 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +00001004 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001005 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001006 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001007 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
1008
1009 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
1010
ramindanidcecfd42022-02-03 23:52:19 +00001011 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001012 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001013 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1014
1015 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001016 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001017 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001018 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001019 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001020 GTEST_SUCCEED();
1021 return;
1022 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001023 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001024 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001025 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001026 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001027
1028 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1029
1030 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +00001031 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
1032 getDisplayHeight() / 2};
1033 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1034 getDisplayWidth());
1035 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +00001036
1037 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
1038 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +00001039 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +00001040
1041 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1042
1043 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001044 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001045 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001046 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001047 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001048 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001049 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001050 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001051 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001052
1053 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1054 }
1055}
1056
1057TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
1058 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001059 EXPECT_TRUE(mComposerClient
1060 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1061 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001062
ramindani44c952f2022-02-28 23:29:29 +00001063 bool isSupported;
1064 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001065 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001066 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1067 return;
1068 }
1069
ramindanidcecfd42022-02-03 23:52:19 +00001070 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001071 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +00001072 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001073 layer->setZOrder(10);
1074 layer->setAlpha(0);
1075 layer->setBlendMode(BlendMode::PREMULTIPLIED);
1076
1077 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
1078
ramindanidcecfd42022-02-03 23:52:19 +00001079 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001080 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001081
1082 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1083
1084 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001085 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001086 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001087 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001088 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001089 GTEST_SUCCEED();
1090 return;
1091 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001092 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001093
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001094 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001095 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001096 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001097
ramindanidcecfd42022-02-03 23:52:19 +00001098 std::vector<Color> expectedColors(
1099 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001100
1101 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1102 mTestRenderEngine->setRenderLayers(layers);
1103 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1104 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1105 }
1106}
1107
1108TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
1109 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001110 EXPECT_TRUE(mComposerClient
1111 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1112 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001113
ramindani44c952f2022-02-28 23:29:29 +00001114 bool isSupported;
1115 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001116 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001117 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1118 return;
1119 }
1120
ramindanidcecfd42022-02-03 23:52:19 +00001121 std::vector<Color> expectedColors(
1122 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1123 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
1124 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
1125 ReadbackHelper::fillColorsArea(
1126 expectedColors, getDisplayWidth(),
1127 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +00001128
ramindani0a2bee42022-02-10 01:27:42 +00001129 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1130 getPrimaryDisplayId(), getDisplayWidth(),
1131 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +00001132 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001133 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001134 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +00001135 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
1136 static_cast<float>(getDisplayWidth()),
1137 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +00001138 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
1139
1140 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
1141
1142 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +00001143 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
1144 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
1145 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001146 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001147 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1148 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001149 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001150 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001151 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001152 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001153 GTEST_SUCCEED();
1154 return;
1155 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001156 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001157 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001158 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001159 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001160 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1161 mTestRenderEngine->setRenderLayers(layers);
1162 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1163 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1164 }
1165}
1166
1167TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
1168 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001169 EXPECT_TRUE(mComposerClient
1170 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1171 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001172
ramindani44c952f2022-02-28 23:29:29 +00001173 bool isSupported;
1174 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001175 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001176 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1177 return;
1178 }
1179
ramindanidcecfd42022-02-03 23:52:19 +00001180 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
1181 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
1182 auto redLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001183 redLayer->setColor(RED);
1184 redLayer->setDisplayFrame(redRect);
1185
ramindanidcecfd42022-02-03 23:52:19 +00001186 auto blueLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001187 blueLayer->setColor(BLUE);
1188 blueLayer->setDisplayFrame(blueRect);
1189 blueLayer->setZOrder(5);
1190
1191 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +00001192 std::vector<Color> expectedColors(
1193 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001194
1195 // red in front of blue
1196 redLayer->setZOrder(10);
1197
1198 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +00001199 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
1200 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +00001201
ramindanidcecfd42022-02-03 23:52:19 +00001202 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001203 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001204 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1205
1206 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001207 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001208 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001209 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001210 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001211 GTEST_SUCCEED();
1212 return;
1213 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001214 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001215 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001216 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001217
1218 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1219
1220 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +00001221 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1222 getDisplayWidth());
1223 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
1224 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +00001225
1226 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1227
1228 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001229 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001230 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001231 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001232 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -08001233 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001234 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001235 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001236 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001237
1238 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1239 mTestRenderEngine->setRenderLayers(layers);
1240 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1241 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1242 }
1243}
1244
Alec Mourib1f16722022-02-07 13:03:44 -08001245TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
ramindanidcecfd42022-02-03 23:52:19 +00001246 const auto& [status, capabilities] =
1247 mComposerClient->getDisplayCapabilities(getPrimaryDisplayId());
1248 ASSERT_TRUE(status.isOk());
Alec Mouri51067012022-01-06 17:28:39 -08001249
1250 const bool brightnessSupport = std::find(capabilities.begin(), capabilities.end(),
1251 DisplayCapability::BRIGHTNESS) != capabilities.end();
1252
1253 if (!brightnessSupport) {
1254 GTEST_SUCCEED() << "Cannot verify dimming behavior without brightness support";
1255 return;
1256 }
1257
1258 const std::optional<float> maxBrightnessNitsOptional =
ramindanidcecfd42022-02-03 23:52:19 +00001259 getMaxDisplayBrightnessNits(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001260
1261 ASSERT_TRUE(maxBrightnessNitsOptional.has_value());
1262
1263 const float maxBrightnessNits = *maxBrightnessNitsOptional;
1264
1265 // Preconditions to successfully run are knowing the max brightness and successfully applying
1266 // the max brightness
1267 ASSERT_GT(maxBrightnessNits, 0.f);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001268 mWriter->setDisplayBrightness(getPrimaryDisplayId(), /*brightness*/ 1.f, maxBrightnessNits);
Alec Mouri51067012022-01-06 17:28:39 -08001269 execute();
1270 ASSERT_TRUE(mReader.takeErrors().empty());
1271
1272 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001273 EXPECT_TRUE(mComposerClient
1274 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1275 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -08001276
ramindani44c952f2022-02-28 23:29:29 +00001277 bool isSupported;
1278 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001279 if (!isSupported) {
Alec Mouri51067012022-01-06 17:28:39 -08001280 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
1281 "color mode: "
1282 << toString(mode);
1283 continue;
1284 }
ramindanidcecfd42022-02-03 23:52:19 +00001285 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
1286 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
1287 getDisplayHeight()};
1288 const auto redLayer =
1289 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001290 redLayer->setColor(RED);
1291 redLayer->setDisplayFrame(redRect);
1292 redLayer->setWhitePointNits(maxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -08001293 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -08001294
1295 const auto dimmerRedLayer =
ramindanidcecfd42022-02-03 23:52:19 +00001296 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001297 dimmerRedLayer->setColor(RED);
1298 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
1299 // Intentionally use a small dimming ratio as some implementations may be more likely to
1300 // kick into GPU composition to apply dithering when the dimming ratio is high.
1301 static constexpr float kDimmingRatio = 0.9f;
1302 dimmerRedLayer->setWhitePointNits(maxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -08001303 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -08001304
1305 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +00001306 std::vector<Color> expectedColors(
1307 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -08001308
ramindanidcecfd42022-02-03 23:52:19 +00001309 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
1310 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -08001311
ramindanidcecfd42022-02-03 23:52:19 +00001312 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001313 getDisplayHeight(), mPixelFormat);
Alec Mouri51067012022-01-06 17:28:39 -08001314 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1315
1316 writeLayers(layers);
1317 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001318 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
Alec Mouri51067012022-01-06 17:28:39 -08001319 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001320 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -08001321 GTEST_SUCCEED()
1322 << "Readback verification not supported for GPU composition for color mode: "
1323 << toString(mode);
1324 continue;
1325 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001326 mWriter->presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001327 execute();
1328 ASSERT_TRUE(mReader.takeErrors().empty());
1329
1330 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1331 mTestRenderEngine->setRenderLayers(layers);
1332 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1333 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1334 }
1335}
1336
ramindanibab8ba92021-11-18 01:24:11 +00001337class GraphicsBlendModeCompositionTest
1338 : public GraphicsCompositionTestBase,
1339 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
1340 public:
1341 void SetUp() override {
1342 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +00001343 // TODO(b/219590743) we should remove the below SRGB color mode
1344 // once we have the BlendMode test fix for all the versions of the ColorMode
ramindania4e76362022-03-02 01:48:06 +00001345 mTestColorModes.erase(
1346 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
1347 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
1348 mTestColorModes.end());
ramindanibab8ba92021-11-18 01:24:11 +00001349 mBackgroundColor = BLACK;
1350 mTopLayerColor = RED;
1351 }
1352
1353 void setBackgroundColor(Color color) { mBackgroundColor = color; }
1354
1355 void setTopLayerColor(Color color) { mTopLayerColor = color; }
1356
1357 void setUpLayers(BlendMode blendMode) {
1358 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +00001359 std::vector<Color> topLayerPixelColors(
1360 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1361 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
1362 {0, 0, getDisplayWidth(), getDisplayHeight()},
1363 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +00001364
ramindanidcecfd42022-02-03 23:52:19 +00001365 auto backgroundLayer =
1366 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
1367 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001368 backgroundLayer->setZOrder(0);
1369 backgroundLayer->setColor(mBackgroundColor);
1370
ramindani0a2bee42022-02-10 01:27:42 +00001371 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1372 getPrimaryDisplayId(), getDisplayWidth(),
1373 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +00001374 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001375 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001376 layer->setDataspace(Dataspace::UNKNOWN, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001377 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
1378
1379 layer->setBlendMode(blendMode);
1380 layer->setAlpha(std::stof(std::get<1>(GetParam())));
1381
1382 mLayers.push_back(backgroundLayer);
1383 mLayers.push_back(layer);
1384 }
1385
1386 void setExpectedColors(std::vector<Color>& expectedColors) {
1387 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001388 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1389 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001390
1391 auto layer = mLayers[1];
1392 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001393 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001394 if (blendMode == BlendMode::NONE) {
1395 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001396 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1397 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1398 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1399 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001400 }
1401 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1402 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001403 expectedColor.r =
1404 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1405 expectedColor.g =
1406 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1407 expectedColor.b =
1408 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1409 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001410 }
1411 } else if (blendMode == BlendMode::COVERAGE) {
1412 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001413 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1414 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1415 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1416 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001417 }
1418 }
1419 }
1420
1421 protected:
1422 std::vector<std::shared_ptr<TestLayer>> mLayers;
1423 Color mBackgroundColor;
1424 Color mTopLayerColor;
1425};
ramindanic7585d92022-04-15 18:30:41 +00001426
1427TEST_P(GraphicsBlendModeCompositionTest, None) {
ramindanibab8ba92021-11-18 01:24:11 +00001428 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001429 EXPECT_TRUE(mComposerClient
1430 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1431 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001432
ramindani44c952f2022-02-28 23:29:29 +00001433 bool isSupported;
1434 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001435 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001436 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1437 return;
1438 }
1439
ramindanidcecfd42022-02-03 23:52:19 +00001440 std::vector<Color> expectedColors(
1441 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001442
1443 setBackgroundColor(BLACK);
1444 setTopLayerColor(TRANSLUCENT_RED);
1445 setUpLayers(BlendMode::NONE);
1446 setExpectedColors(expectedColors);
1447
ramindanidcecfd42022-02-03 23:52:19 +00001448 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001449 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001450 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1451 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001452 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001453 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001454 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001455 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001456 GTEST_SUCCEED();
1457 return;
1458 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001459 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001460 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001461 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001462 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001463
1464 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1465 mTestRenderEngine->setRenderLayers(mLayers);
1466 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1467 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1468 }
1469}
1470
ramindani07e6f842022-02-15 15:28:33 +00001471TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001472 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001473 EXPECT_TRUE(mComposerClient
1474 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1475 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001476
ramindani44c952f2022-02-28 23:29:29 +00001477 bool isSupported;
1478 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001479 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001480 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1481 return;
1482 }
1483
ramindanidcecfd42022-02-03 23:52:19 +00001484 std::vector<Color> expectedColors(
1485 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001486
1487 setBackgroundColor(BLACK);
1488 setTopLayerColor(TRANSLUCENT_RED);
1489
1490 setUpLayers(BlendMode::COVERAGE);
1491 setExpectedColors(expectedColors);
1492
ramindanidcecfd42022-02-03 23:52:19 +00001493 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001494 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001495 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1496 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001497 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001498 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001499 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001500 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001501 GTEST_SUCCEED();
1502 return;
1503 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001504 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001505 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001506 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001507 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001508 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1509 }
1510}
1511
1512TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1513 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001514 EXPECT_TRUE(mComposerClient
1515 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1516 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001517
ramindani44c952f2022-02-28 23:29:29 +00001518 bool isSupported;
1519 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001520 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001521 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1522 return;
1523 }
ramindanibab8ba92021-11-18 01:24:11 +00001524
ramindanidcecfd42022-02-03 23:52:19 +00001525 std::vector<Color> expectedColors(
1526 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001527
1528 setBackgroundColor(BLACK);
1529 setTopLayerColor(TRANSLUCENT_RED);
1530 setUpLayers(BlendMode::PREMULTIPLIED);
1531 setExpectedColors(expectedColors);
1532
ramindanidcecfd42022-02-03 23:52:19 +00001533 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001534 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001535 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1536 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001537 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001538 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001539 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001540 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001541 GTEST_SUCCEED();
1542 return;
1543 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001544 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001545 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001546 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001547 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001548 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1549 mTestRenderEngine->setRenderLayers(mLayers);
1550 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1551 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1552 }
1553}
1554
1555class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1556 protected:
1557 void SetUp() override {
1558 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001559
ramindanidcecfd42022-02-03 23:52:19 +00001560 auto backgroundLayer =
1561 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001562 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001563 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001564 backgroundLayer->setZOrder(0);
1565
ramindanidcecfd42022-02-03 23:52:19 +00001566 mSideLength =
1567 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001568 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1569 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1570
ramindani0a2bee42022-02-10 01:27:42 +00001571 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1572 getPrimaryDisplayId(), mSideLength, mSideLength,
1573 PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +00001574 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1575 mLayer->setZOrder(10);
1576
1577 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1578 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1579 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1580 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1581 mLayers = {backgroundLayer, mLayer};
1582 }
1583
1584 protected:
1585 std::shared_ptr<TestBufferLayer> mLayer;
1586 std::vector<std::shared_ptr<TestLayer>> mLayers;
1587 int mSideLength;
1588};
1589
1590TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1591 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001592 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1593 RenderIntent::COLORIMETRIC);
ramindanid5751092022-04-22 22:30:20 +00001594 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
ramindanidcecfd42022-02-03 23:52:19 +00001595 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1596 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001597 SUCCEED() << "ColorMode not supported, skip test";
1598 return;
1599 }
1600
ramindani44c952f2022-02-28 23:29:29 +00001601 bool isSupported;
1602 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001603 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001604 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1605 return;
1606 }
ramindanidcecfd42022-02-03 23:52:19 +00001607 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001608 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001609 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1610 mLayer->setTransform(Transform::FLIP_H);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001611 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001612
ramindanidcecfd42022-02-03 23:52:19 +00001613 std::vector<Color> expectedColors(
1614 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1615 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001616 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001617 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001618 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1619
1620 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001621 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001622 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001623 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001624 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001625 GTEST_SUCCEED();
1626 return;
1627 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001628 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001629 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001630 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001631 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001632
1633 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1634 mTestRenderEngine->setRenderLayers(mLayers);
1635 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1636 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1637 }
1638}
1639
1640TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1641 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001642 EXPECT_TRUE(mComposerClient
1643 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1644 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001645
ramindani44c952f2022-02-28 23:29:29 +00001646 bool isSupported;
1647 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001648 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001649 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1650 return;
1651 }
ramindanidcecfd42022-02-03 23:52:19 +00001652 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001653 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001654 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1655
1656 mLayer->setTransform(Transform::FLIP_V);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001657 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001658
ramindanidcecfd42022-02-03 23:52:19 +00001659 std::vector<Color> expectedColors(
1660 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1661 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001662 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001663 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001664 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1665
1666 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001667 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001668 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001669 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001670 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001671 GTEST_SUCCEED();
1672 return;
1673 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001674 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001675 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001676 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001677 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001678 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1679 mTestRenderEngine->setRenderLayers(mLayers);
1680 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1681 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1682 }
1683}
1684
1685TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1686 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001687 EXPECT_TRUE(mComposerClient
1688 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1689 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001690
ramindani44c952f2022-02-28 23:29:29 +00001691 bool isSupported;
1692 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001693 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001694 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1695 return;
1696 }
ramindanidcecfd42022-02-03 23:52:19 +00001697 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahld103cd62022-12-09 07:26:28 -07001698 getDisplayHeight(), mPixelFormat);
ramindanibab8ba92021-11-18 01:24:11 +00001699 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1700
1701 mLayer->setTransform(Transform::ROT_180);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001702 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001703
ramindanidcecfd42022-02-03 23:52:19 +00001704 std::vector<Color> expectedColors(
1705 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1706 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001707 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1708 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001709 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001710 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1711
1712 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001713 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001714 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001715 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001716 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001717 GTEST_SUCCEED();
1718 return;
1719 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001720 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001721 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001722 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001723 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001724 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1725 mTestRenderEngine->setRenderLayers(mLayers);
1726 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1727 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1728 }
1729}
1730
1731GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1732INSTANTIATE_TEST_SUITE_P(
1733 PerInstance, GraphicsCompositionTest,
1734 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1735 ::android::PrintInstanceNameToString);
1736
1737GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1738INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1739 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1740 IComposer::descriptor)),
1741 testing::Values("0.2", "1.0")));
1742
1743GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1744INSTANTIATE_TEST_SUITE_P(
1745 PerInstance, GraphicsTransformCompositionTest,
1746 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1747 ::android::PrintInstanceNameToString);
1748
1749} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001750} // namespace aidl::android::hardware::graphics::composer3::vts