blob: 4fadc17db638a7b2fdbc396cb8b7c87d0c2e7a71 [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>
21#include <aidl/android/hardware/graphics/common/BufferUsage.h>
Ady Abraham46219f52021-12-20 09:44:31 -080022#include <aidl/android/hardware/graphics/composer3/IComposer.h>
ramindanibab8ba92021-11-18 01:24:11 +000023#include <gtest/gtest.h>
Alec Mouri51067012022-01-06 17:28:39 -080024#include <ui/DisplayId.h>
25#include <ui/DisplayIdentification.h>
ramindanibab8ba92021-11-18 01:24:11 +000026#include <ui/GraphicBuffer.h>
ramindanibab8ba92021-11-18 01:24:11 +000027#include <ui/PixelFormat.h>
28#include <ui/Rect.h>
ramindani458e53e2022-02-23 17:30:16 +000029#include "GraphicsComposerCallback.h"
30#include "ReadbackVts.h"
31#include "RenderEngineVts.h"
32#include "VtsComposerClient.h"
Alec Mouri51067012022-01-06 17:28:39 -080033
34// tinyxml2 does implicit conversions >:(
35#pragma clang diagnostic push
36#pragma clang diagnostic ignored "-Wconversion"
37#include <tinyxml2.h>
38#pragma clang diagnostic pop
ramindanibab8ba92021-11-18 01:24:11 +000039
40namespace aidl::android::hardware::graphics::composer3::vts {
41namespace {
42
43using ::android::Rect;
44using common::Dataspace;
45using common::PixelFormat;
46
47class GraphicsCompositionTestBase : public ::testing::Test {
48 protected:
49 void SetUpBase(const std::string& name) {
ramindanidcecfd42022-02-03 23:52:19 +000050 mComposerClient = std::make_shared<VtsComposerClient>(name);
51 ASSERT_TRUE(mComposerClient->createClient().isOk());
ramindanibab8ba92021-11-18 01:24:11 +000052
ramindanidcecfd42022-02-03 23:52:19 +000053 const auto& [status, displays] = mComposerClient->getDisplays();
54 ASSERT_TRUE(status.isOk());
55 mDisplays = displays;
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
83 mTestRenderEngine->initGraphicBuffer(
ramindanidcecfd42022-02-03 23:52:19 +000084 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
85 /*layerCount*/ 1U,
ramindanibab8ba92021-11-18 01:24:11 +000086 static_cast<uint64_t>(
87 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
88 static_cast<uint64_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
89 static_cast<uint64_t>(common::BufferUsage::GPU_RENDER_TARGET)));
90 mTestRenderEngine->setDisplaySettings(clientCompositionDisplay);
91 }
92
93 void TearDown() override {
ramindanidcecfd42022-02-03 23:52:19 +000094 ASSERT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::OFF).isOk());
95 ASSERT_TRUE(mComposerClient->tearDown());
96 mComposerClient.reset();
Ady Abraham3192f3d2021-12-03 16:08:56 -080097 const auto errors = mReader.takeErrors();
98 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +000099 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
ramindanibab8ba92021-11-18 01:24:11 +0000100 }
101
ramindanidcecfd42022-02-03 23:52:19 +0000102 const VtsDisplay& getPrimaryDisplay() const { return mDisplays[0]; }
103
104 int64_t getPrimaryDisplayId() const { return getPrimaryDisplay().getDisplayId(); }
105
106 int64_t getInvalidDisplayId() const { return mComposerClient->getInvalidDisplayId(); }
107
108 int32_t getDisplayWidth() const { return getPrimaryDisplay().getDisplayWidth(); }
109
110 int32_t getDisplayHeight() const { return getPrimaryDisplay().getDisplayHeight(); }
111
ramindani0a2bee42022-02-10 01:27:42 +0000112 std::pair<bool, ::android::sp<::android::GraphicBuffer>> allocateBuffer(uint32_t usage) {
ramindanidcecfd42022-02-03 23:52:19 +0000113 const auto width = static_cast<uint32_t>(getDisplayWidth());
114 const auto height = static_cast<uint32_t>(getDisplayHeight());
Ady Abraham46219f52021-12-20 09:44:31 -0800115
ramindani0a2bee42022-02-10 01:27:42 +0000116 const auto& graphicBuffer = ::android::sp<::android::GraphicBuffer>::make(
Ady Abraham46219f52021-12-20 09:44:31 -0800117 width, height, ::android::PIXEL_FORMAT_RGBA_8888,
118 /*layerCount*/ 1u, usage, "VtsHalGraphicsComposer3_ReadbackTest");
ramindani0a2bee42022-02-10 01:27:42 +0000119
120 if (graphicBuffer && ::android::OK == graphicBuffer->initCheck()) {
121 return {true, graphicBuffer};
122 }
123 return {false, graphicBuffer};
ramindanibab8ba92021-11-18 01:24:11 +0000124 }
125
Alec Mouri51067012022-01-06 17:28:39 -0800126 uint64_t getStableDisplayId(int64_t display) {
ramindanidcecfd42022-02-03 23:52:19 +0000127 const auto& [status, identification] =
128 mComposerClient->getDisplayIdentificationData(display);
129 EXPECT_TRUE(status.isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800130
131 if (const auto info = ::android::parseDisplayIdentificationData(
132 static_cast<uint8_t>(identification.port), identification.data)) {
133 return info->id.value;
134 }
135
136 return ::android::PhysicalDisplayId::fromPort(static_cast<uint8_t>(identification.port))
137 .value;
138 }
139
140 // Gets the per-display XML config
141 std::unique_ptr<tinyxml2::XMLDocument> getDisplayConfigXml(int64_t display) {
142 std::stringstream pathBuilder;
143 pathBuilder << "/vendor/etc/displayconfig/display_id_" << getStableDisplayId(display)
144 << ".xml";
145 const std::string path = pathBuilder.str();
146 auto document = std::make_unique<tinyxml2::XMLDocument>();
147 const tinyxml2::XMLError error = document->LoadFile(path.c_str());
148 if (error == tinyxml2::XML_SUCCESS) {
149 return document;
150 } else {
151 return nullptr;
152 }
153 }
154
155 // Gets the max display brightness for this display.
156 // If the display config xml does not exist, then assume that the display is not well-configured
157 // enough to provide a display brightness, so return nullopt.
158 std::optional<float> getMaxDisplayBrightnessNits(int64_t display) {
159 const auto document = getDisplayConfigXml(display);
160 if (!document) {
161 // Assume the device doesn't support display brightness
162 return std::nullopt;
163 }
164
165 const auto root = document->RootElement();
166 if (!root) {
167 // If there's somehow no root element, then this isn't a valid config
168 return std::nullopt;
169 }
170
171 const auto screenBrightnessMap = root->FirstChildElement("screenBrightnessMap");
172 if (!screenBrightnessMap) {
173 // A valid display config must have a screen brightness map
174 return std::nullopt;
175 }
176
177 auto point = screenBrightnessMap->FirstChildElement("point");
178 float maxNits = -1.f;
179 while (point != nullptr) {
180 const auto nits = point->FirstChildElement("nits");
181 if (nits) {
182 maxNits = std::max(maxNits, nits->FloatText(-1.f));
183 }
184 point = point->NextSiblingElement("point");
185 }
186
187 if (maxNits < 0.f) {
188 // If we got here, then there were no point elements containing a nit value, so this
189 // config isn't valid
190 return std::nullopt;
191 }
192
193 return maxNits;
194 }
195
ramindanibab8ba92021-11-18 01:24:11 +0000196 void writeLayers(const std::vector<std::shared_ptr<TestLayer>>& layers) {
ramindanidcecfd42022-02-03 23:52:19 +0000197 for (const auto& layer : layers) {
ramindanibab8ba92021-11-18 01:24:11 +0000198 layer->write(mWriter);
199 }
200 execute();
201 }
202
203 void execute() {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800204 const auto& commands = mWriter.getPendingCommands();
205 if (commands.empty()) {
206 mWriter.reset();
207 return;
ramindanibab8ba92021-11-18 01:24:11 +0000208 }
209
ramindanidcecfd42022-02-03 23:52:19 +0000210 auto [status, results] = mComposerClient->executeCommands(commands);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800211 ASSERT_TRUE(status.isOk()) << "executeCommands failed " << status.getDescription();
ramindanibab8ba92021-11-18 01:24:11 +0000212
Ady Abraham46219f52021-12-20 09:44:31 -0800213 mReader.parse(std::move(results));
Ady Abraham3192f3d2021-12-03 16:08:56 -0800214 mWriter.reset();
ramindanibab8ba92021-11-18 01:24:11 +0000215 }
216
ramindani44c952f2022-02-28 23:29:29 +0000217 bool getHasReadbackBuffer() {
ramindanidcecfd42022-02-03 23:52:19 +0000218 auto [status, readBackBufferAttributes] =
219 mComposerClient->getReadbackBufferAttributes(getPrimaryDisplayId());
220 if (status.isOk()) {
221 mPixelFormat = readBackBufferAttributes.format;
222 mDataspace = readBackBufferAttributes.dataspace;
ramindani44c952f2022-02-28 23:29:29 +0000223 return ReadbackHelper::readbackSupported(mPixelFormat, mDataspace);
ramindanidcecfd42022-02-03 23:52:19 +0000224 }
ramindani44c952f2022-02-28 23:29:29 +0000225 EXPECT_EQ(IComposerClient::EX_UNSUPPORTED, status.getServiceSpecificError());
226 return false;
ramindanib27f33b2021-12-03 19:36:10 +0000227 }
228
ramindanidcecfd42022-02-03 23:52:19 +0000229 std::shared_ptr<VtsComposerClient> mComposerClient;
230 std::vector<VtsDisplay> mDisplays;
231 // use the slot count usually set by SF
ramindanibab8ba92021-11-18 01:24:11 +0000232 std::vector<ColorMode> mTestColorModes;
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800233 ComposerClientWriter mWriter;
234 ComposerClientReader mReader;
ramindanibab8ba92021-11-18 01:24:11 +0000235 std::unique_ptr<TestRenderEngine> mTestRenderEngine;
ramindanibab8ba92021-11-18 01:24:11 +0000236 common::PixelFormat mPixelFormat;
237 common::Dataspace mDataspace;
238
239 static constexpr uint32_t kClientTargetSlotCount = 64;
240
241 private:
ramindanibab8ba92021-11-18 01:24:11 +0000242 void setTestColorModes() {
243 mTestColorModes.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000244 const auto& [status, modes] = mComposerClient->getColorModes(getPrimaryDisplayId());
245 ASSERT_TRUE(status.isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000246
247 for (ColorMode mode : modes) {
248 if (std::find(ReadbackHelper::colorModes.begin(), ReadbackHelper::colorModes.end(),
249 mode) != ReadbackHelper::colorModes.end()) {
250 mTestColorModes.push_back(mode);
251 }
252 }
253 }
254};
255
256class GraphicsCompositionTest : public GraphicsCompositionTestBase,
257 public testing::WithParamInterface<std::string> {
258 public:
259 void SetUp() override { SetUpBase(GetParam()); }
260};
261
262TEST_P(GraphicsCompositionTest, SingleSolidColorLayer) {
263 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000264 EXPECT_TRUE(mComposerClient
265 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
266 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000267
ramindani44c952f2022-02-28 23:29:29 +0000268 bool isSupported;
269 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000270 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000271 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
272 return;
273 }
274
ramindanidcecfd42022-02-03 23:52:19 +0000275 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
276 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000277 layer->setColor(BLUE);
278 layer->setDisplayFrame(coloredSquare);
279 layer->setZOrder(10);
280
281 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
282
283 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000284 std::vector<Color> expectedColors(
285 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
286 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000287
ramindanidcecfd42022-02-03 23:52:19 +0000288 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
289 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000290 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
291
292 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800293 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000294 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000295 execute();
296 // if hwc cannot handle and asks for composition change,
297 // just succeed the test
ramindanidcecfd42022-02-03 23:52:19 +0000298 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000299 GTEST_SUCCEED();
300 return;
301 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800302 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000303 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000304 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800305 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000306
307 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
308 mTestRenderEngine->setRenderLayers(layers);
309 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
310 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
311 }
312}
313
314TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
315 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000316 EXPECT_TRUE(mComposerClient
317 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
318 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000319
ramindani44c952f2022-02-28 23:29:29 +0000320 bool isSupported;
321 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000322 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000323 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
324 return;
325 }
326
ramindanidcecfd42022-02-03 23:52:19 +0000327 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
328 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000329 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000330 std::vector<Color> expectedColors(
331 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
332 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
333 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
334 ReadbackHelper::fillColorsArea(
335 expectedColors, getDisplayWidth(),
336 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
337 ReadbackHelper::fillColorsArea(
338 expectedColors, getDisplayWidth(),
339 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000340
341 auto layer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000342 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
343 getDisplayHeight(), common::PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000344 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000345 layer->setZOrder(10);
346 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
347 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
348
349 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
350
351 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800352 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000353 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000354 execute();
355
ramindanidcecfd42022-02-03 23:52:19 +0000356 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000357 GTEST_SUCCEED();
358 return;
359 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800360 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000361
ramindanidcecfd42022-02-03 23:52:19 +0000362 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000363 execute();
364
Ady Abraham3192f3d2021-12-03 16:08:56 -0800365 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000366
367 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
368 mTestRenderEngine->setRenderLayers(layers);
369 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
370 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
371 }
372}
373
374TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
375 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000376 EXPECT_TRUE(mComposerClient
377 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
378 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000379
ramindani44c952f2022-02-28 23:29:29 +0000380 bool isSupported;
381 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000382 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000383 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
384 return;
385 }
386
ramindanidcecfd42022-02-03 23:52:19 +0000387 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
388 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000389 layer->setColor(BLUE);
390 layer->setDisplayFrame(coloredSquare);
391 layer->setZOrder(10);
392 layer->write(mWriter);
393
394 // This following buffer call should have no effect
ramindani0a2bee42022-02-10 01:27:42 +0000395 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
396 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
397 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
398 ASSERT_TRUE(graphicBufferStatus);
399 const auto& buffer = graphicBuffer->handle;
400 mWriter.setLayerBuffer(getPrimaryDisplayId(), layer->getLayer(), /*slot*/ 0, buffer,
ramindanidcecfd42022-02-03 23:52:19 +0000401 /*acquireFence*/ -1);
ramindanibab8ba92021-11-18 01:24:11 +0000402
403 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000404 std::vector<Color> expectedColors(
405 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
406 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000407
ramindanidcecfd42022-02-03 23:52:19 +0000408 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
409 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000410 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
411
ramindanidcecfd42022-02-03 23:52:19 +0000412 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000413 execute();
414
ramindanidcecfd42022-02-03 23:52:19 +0000415 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000416 GTEST_SUCCEED();
417 return;
418 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800419 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000420 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000421 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800422 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000423
424 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
425 }
426}
427
ramindanib27f33b2021-12-03 19:36:10 +0000428TEST_P(GraphicsCompositionTest, SetReadbackBuffer) {
ramindani44c952f2022-02-28 23:29:29 +0000429 bool isSupported;
430 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000431 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000432 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
433 return;
434 }
435
ramindanidcecfd42022-02-03 23:52:19 +0000436 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
437 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanib27f33b2021-12-03 19:36:10 +0000438
439 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
440}
441
ramindanidcecfd42022-02-03 23:52:19 +0000442TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadDisplay) {
ramindani44c952f2022-02-28 23:29:29 +0000443 bool isSupported;
444 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000445 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000446 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
447 return;
448 }
449
ramindani0a2bee42022-02-10 01:27:42 +0000450 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
451 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
452 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
453 ASSERT_TRUE(graphicBufferStatus);
454 const auto& bufferHandle = graphicBuffer->handle;
ramindanib27f33b2021-12-03 19:36:10 +0000455 ::ndk::ScopedFileDescriptor fence = ::ndk::ScopedFileDescriptor(-1);
456
ramindanidcecfd42022-02-03 23:52:19 +0000457 const auto status =
458 mComposerClient->setReadbackBuffer(getInvalidDisplayId(), bufferHandle, fence);
ramindanib27f33b2021-12-03 19:36:10 +0000459
ramindanidcecfd42022-02-03 23:52:19 +0000460 EXPECT_FALSE(status.isOk());
461 ASSERT_EQ(IComposerClient::EX_BAD_DISPLAY, status.getServiceSpecificError());
ramindanib27f33b2021-12-03 19:36:10 +0000462}
463
ramindanidcecfd42022-02-03 23:52:19 +0000464TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadParameter) {
ramindani44c952f2022-02-28 23:29:29 +0000465 bool isSupported;
466 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000467 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000468 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
469 return;
470 }
471
ramindanidcecfd42022-02-03 23:52:19 +0000472 const native_handle_t bufferHandle{};
ramindanib27f33b2021-12-03 19:36:10 +0000473 ndk::ScopedFileDescriptor releaseFence = ndk::ScopedFileDescriptor(-1);
ramindanidcecfd42022-02-03 23:52:19 +0000474 const auto status =
475 mComposerClient->setReadbackBuffer(getPrimaryDisplayId(), &bufferHandle, releaseFence);
ramindanib27f33b2021-12-03 19:36:10 +0000476
ramindanidcecfd42022-02-03 23:52:19 +0000477 EXPECT_FALSE(status.isOk());
478 ASSERT_EQ(IComposerClient::EX_BAD_PARAMETER, status.getServiceSpecificError());
ramindanib27f33b2021-12-03 19:36:10 +0000479}
480
481TEST_P(GraphicsCompositionTest, GetReadbackBufferFenceInactive) {
ramindani44c952f2022-02-28 23:29:29 +0000482 bool isSupported;
483 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000484 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000485 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
486 return;
487 }
488
ramindanidcecfd42022-02-03 23:52:19 +0000489 const auto& [status, releaseFence] =
490 mComposerClient->getReadbackBufferFence(getPrimaryDisplayId());
ramindanib27f33b2021-12-03 19:36:10 +0000491
ramindanidcecfd42022-02-03 23:52:19 +0000492 EXPECT_FALSE(status.isOk());
493 EXPECT_EQ(IComposerClient::EX_UNSUPPORTED, status.getServiceSpecificError());
Alec Mouri62ae37b2022-01-20 17:16:38 -0800494 EXPECT_EQ(-1, releaseFence.get());
ramindanib27f33b2021-12-03 19:36:10 +0000495}
496
ramindanibab8ba92021-11-18 01:24:11 +0000497TEST_P(GraphicsCompositionTest, ClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000498 EXPECT_TRUE(
499 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
500 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000501
502 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000503 EXPECT_TRUE(mComposerClient
504 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
ramindanibab8ba92021-11-18 01:24:11 +0000505 .isOk());
506
ramindani44c952f2022-02-28 23:29:29 +0000507 bool isSupported;
508 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000509 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000510 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
511 return;
512 }
513
ramindanidcecfd42022-02-03 23:52:19 +0000514 std::vector<Color> expectedColors(
515 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
516 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
517 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
518 ReadbackHelper::fillColorsArea(
519 expectedColors, getDisplayWidth(),
520 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
521 ReadbackHelper::fillColorsArea(
522 expectedColors, getDisplayWidth(),
523 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000524
ramindani0a2bee42022-02-10 01:27:42 +0000525 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
526 getPrimaryDisplayId(), getDisplayWidth(),
527 getDisplayHeight(), PixelFormat::RGBA_FP16);
ramindanidcecfd42022-02-03 23:52:19 +0000528 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000529 layer->setZOrder(10);
530 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
531
532 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
533
ramindanidcecfd42022-02-03 23:52:19 +0000534 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
535 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000536 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
537 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800538 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000539 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000540 execute();
541
ramindanidcecfd42022-02-03 23:52:19 +0000542 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800543 if (!changedCompositionTypes.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800544 ASSERT_EQ(1, changedCompositionTypes.size());
Ady Abraham46219f52021-12-20 09:44:31 -0800545 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindanibab8ba92021-11-18 01:24:11 +0000546
547 PixelFormat clientFormat = PixelFormat::RGBA_8888;
548 auto clientUsage = static_cast<uint32_t>(
549 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN) |
550 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
551 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
552 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000553 common::Rect damage{0, 0, getDisplayWidth(), getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000554
555 // create client target buffer
ramindani0a2bee42022-02-10 01:27:42 +0000556 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
557 ASSERT_TRUE(graphicBufferStatus);
558 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000559 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000560 const auto stride = static_cast<uint32_t>(graphicBuffer->stride);
561 graphicBuffer->lock(clientUsage, layer->getAccessRegion(), &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000562
563 ASSERT_NO_FATAL_FAILURE(
ramindani0a2bee42022-02-10 01:27:42 +0000564 ReadbackHelper::fillBuffer(layer->getWidth(), layer->getHeight(), stride,
ramindanibab8ba92021-11-18 01:24:11 +0000565 clientBufData, clientFormat, expectedColors));
ramindanib1144212022-02-10 01:51:24 +0000566 int32_t clientFence;
567 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
568 ASSERT_EQ(::android::OK, unlockStatus);
ramindanib1144212022-02-10 01:51:24 +0000569 mWriter.setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
ramindani0a2bee42022-02-10 01:27:42 +0000570 clientDataspace, std::vector<common::Rect>(1, damage));
ramindanib1144212022-02-10 01:51:24 +0000571 layer->setToClientComposition(mWriter);
572 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000573 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000574 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800575 ASSERT_TRUE(changedCompositionTypes.empty());
ramindanibab8ba92021-11-18 01:24:11 +0000576 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800577 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000578
ramindanidcecfd42022-02-03 23:52:19 +0000579 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000580 execute();
581
Ady Abraham3192f3d2021-12-03 16:08:56 -0800582 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000583
584 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
585 }
586}
587
588TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000589 ASSERT_TRUE(
590 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
591 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000592
593 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000594 EXPECT_TRUE(mComposerClient
595 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
596 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000597
ramindani44c952f2022-02-28 23:29:29 +0000598 bool isSupported;
599 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000600 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000601 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
602 return;
603 }
604
ramindanidcecfd42022-02-03 23:52:19 +0000605 std::vector<Color> expectedColors(
606 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
607 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
608 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
609 ReadbackHelper::fillColorsArea(
610 expectedColors, getDisplayWidth(),
611 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000612
ramindanidcecfd42022-02-03 23:52:19 +0000613 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
614 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000615 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
616
617 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000618 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
619 getDisplayHeight() / 2, PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +0000620 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
621 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
622 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
623 static_cast<int32_t>(deviceLayer->getHeight())},
624 GREEN);
625 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
626 static_cast<int32_t>(deviceLayer->getHeight())});
627 deviceLayer->setZOrder(10);
628 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
629 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
630 deviceLayer->write(mWriter);
631
632 PixelFormat clientFormat = PixelFormat::RGBA_8888;
633 auto clientUsage = static_cast<uint32_t>(
634 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
635 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
636 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
637 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000638 int32_t clientWidth = getDisplayWidth();
639 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000640
641 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000642 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
643 clientHeight, PixelFormat::RGBA_FP16, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000644 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
645 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000646 clientLayer->setDisplayFrame(clientFrame);
647 clientLayer->setZOrder(0);
648 clientLayer->write(mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000649 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000650 execute();
651
ramindanidcecfd42022-02-03 23:52:19 +0000652 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800653 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000654 continue;
655 }
656 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800657 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindani0a2bee42022-02-10 01:27:42 +0000658 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
659 ASSERT_TRUE(graphicBufferStatus);
660 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000661
662 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000663 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
664 &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000665
ramindanidcecfd42022-02-03 23:52:19 +0000666 std::vector<Color> clientColors(
667 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
668 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000669 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000670 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
ramindani0a2bee42022-02-10 01:27:42 +0000671 graphicBuffer->getStride(), clientBufData, clientFormat, clientColors));
ramindanib1144212022-02-10 01:51:24 +0000672 int32_t clientFence;
673 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
674 ASSERT_EQ(::android::OK, unlockStatus);
ramindanib1144212022-02-10 01:51:24 +0000675 mWriter.setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
ramindani0a2bee42022-02-10 01:27:42 +0000676 clientDataspace, std::vector<common::Rect>(1, clientFrame));
ramindanib1144212022-02-10 01:51:24 +0000677 clientLayer->setToClientComposition(mWriter);
678 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000679 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000680 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800681 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800682 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000683
ramindanidcecfd42022-02-03 23:52:19 +0000684 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000685 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800686 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000687 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
688 }
689}
690
691TEST_P(GraphicsCompositionTest, SetLayerDamage) {
692 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000693 EXPECT_TRUE(mComposerClient
694 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
695 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000696
ramindani44c952f2022-02-28 23:29:29 +0000697 bool isSupported;
698 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000699 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000700 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
701 return;
702 }
703
ramindanidcecfd42022-02-03 23:52:19 +0000704 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000705
ramindanidcecfd42022-02-03 23:52:19 +0000706 std::vector<Color> expectedColors(
707 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
708 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000709
ramindani0a2bee42022-02-10 01:27:42 +0000710 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
711 getPrimaryDisplayId(), getDisplayWidth(),
712 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000713 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000714 layer->setZOrder(10);
715 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
716 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
717
718 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
719
ramindanidcecfd42022-02-03 23:52:19 +0000720 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
721 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000722 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
723
724 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800725 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000726 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000727 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000728 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000729 GTEST_SUCCEED();
730 return;
731 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800732 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000733 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000734 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800735 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000736
737 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
738
739 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +0000740 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
741 getDisplayHeight() / 2};
742 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
743 getDisplayWidth());
744 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000745
746 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
747 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +0000748 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +0000749
750 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
751
752 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800753 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000754 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000755 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800756 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000757 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
758 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000759 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800760 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000761
762 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
763 }
764}
765
766TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
767 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000768 EXPECT_TRUE(mComposerClient
769 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
770 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000771
ramindani44c952f2022-02-28 23:29:29 +0000772 bool isSupported;
773 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000774 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000775 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
776 return;
777 }
778
ramindanidcecfd42022-02-03 23:52:19 +0000779 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000780 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +0000781 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000782 layer->setZOrder(10);
783 layer->setAlpha(0);
784 layer->setBlendMode(BlendMode::PREMULTIPLIED);
785
786 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
787
ramindanidcecfd42022-02-03 23:52:19 +0000788 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
789 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000790
791 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
792
793 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800794 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000795 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000796 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000797 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000798 GTEST_SUCCEED();
799 return;
800 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800801 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000802
ramindanidcecfd42022-02-03 23:52:19 +0000803 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000804 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800805 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000806
ramindanidcecfd42022-02-03 23:52:19 +0000807 std::vector<Color> expectedColors(
808 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000809
810 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
811 mTestRenderEngine->setRenderLayers(layers);
812 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
813 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
814 }
815}
816
817TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
818 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000819 EXPECT_TRUE(mComposerClient
820 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
821 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000822
ramindani44c952f2022-02-28 23:29:29 +0000823 bool isSupported;
824 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000825 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000826 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
827 return;
828 }
829
ramindanidcecfd42022-02-03 23:52:19 +0000830 std::vector<Color> expectedColors(
831 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
832 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
833 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
834 ReadbackHelper::fillColorsArea(
835 expectedColors, getDisplayWidth(),
836 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000837
ramindani0a2bee42022-02-10 01:27:42 +0000838 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
839 getPrimaryDisplayId(), getDisplayWidth(),
840 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000841 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000842 layer->setZOrder(10);
843 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000844 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
845 static_cast<float>(getDisplayWidth()),
846 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +0000847 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
848
849 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
850
851 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +0000852 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
853 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
854 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
855 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000856 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
857 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800858 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000859 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000860 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000861 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000862 GTEST_SUCCEED();
863 return;
864 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800865 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000866 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000867 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800868 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000869 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
870 mTestRenderEngine->setRenderLayers(layers);
871 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
872 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
873 }
874}
875
876TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
877 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000878 EXPECT_TRUE(mComposerClient
879 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
880 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000881
ramindani44c952f2022-02-28 23:29:29 +0000882 bool isSupported;
883 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000884 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000885 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
886 return;
887 }
888
ramindanidcecfd42022-02-03 23:52:19 +0000889 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
890 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
891 auto redLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000892 redLayer->setColor(RED);
893 redLayer->setDisplayFrame(redRect);
894
ramindanidcecfd42022-02-03 23:52:19 +0000895 auto blueLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000896 blueLayer->setColor(BLUE);
897 blueLayer->setDisplayFrame(blueRect);
898 blueLayer->setZOrder(5);
899
900 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000901 std::vector<Color> expectedColors(
902 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000903
904 // red in front of blue
905 redLayer->setZOrder(10);
906
907 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +0000908 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
909 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000910
ramindanidcecfd42022-02-03 23:52:19 +0000911 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
912 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000913 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
914
915 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800916 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000917 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000918 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000919 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000920 GTEST_SUCCEED();
921 return;
922 }
ramindanidcecfd42022-02-03 23:52:19 +0000923 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000924 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800925 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000926
927 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
928
929 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +0000930 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
931 getDisplayWidth());
932 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
933 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000934
935 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
936
937 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800938 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000939 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000940 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000941 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800942 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000943 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000944 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800945 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000946
947 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
948 mTestRenderEngine->setRenderLayers(layers);
949 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
950 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
951 }
952}
953
Alec Mourib1f16722022-02-07 13:03:44 -0800954TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
ramindanidcecfd42022-02-03 23:52:19 +0000955 const auto& [status, capabilities] =
956 mComposerClient->getDisplayCapabilities(getPrimaryDisplayId());
957 ASSERT_TRUE(status.isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800958
959 const bool brightnessSupport = std::find(capabilities.begin(), capabilities.end(),
960 DisplayCapability::BRIGHTNESS) != capabilities.end();
961
962 if (!brightnessSupport) {
963 GTEST_SUCCEED() << "Cannot verify dimming behavior without brightness support";
964 return;
965 }
966
967 const std::optional<float> maxBrightnessNitsOptional =
ramindanidcecfd42022-02-03 23:52:19 +0000968 getMaxDisplayBrightnessNits(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800969
970 ASSERT_TRUE(maxBrightnessNitsOptional.has_value());
971
972 const float maxBrightnessNits = *maxBrightnessNitsOptional;
973
974 // Preconditions to successfully run are knowing the max brightness and successfully applying
975 // the max brightness
976 ASSERT_GT(maxBrightnessNits, 0.f);
ramindanidcecfd42022-02-03 23:52:19 +0000977 mWriter.setDisplayBrightness(getPrimaryDisplayId(), /*brightness*/ 1.f);
Alec Mouri51067012022-01-06 17:28:39 -0800978 execute();
979 ASSERT_TRUE(mReader.takeErrors().empty());
980
981 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000982 EXPECT_TRUE(mComposerClient
983 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
984 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800985
ramindani44c952f2022-02-28 23:29:29 +0000986 bool isSupported;
987 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000988 if (!isSupported) {
Alec Mouri51067012022-01-06 17:28:39 -0800989 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
990 "color mode: "
991 << toString(mode);
992 continue;
993 }
ramindanidcecfd42022-02-03 23:52:19 +0000994 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
995 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
996 getDisplayHeight()};
997 const auto redLayer =
998 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800999 redLayer->setColor(RED);
1000 redLayer->setDisplayFrame(redRect);
1001 redLayer->setWhitePointNits(maxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -08001002 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -08001003
1004 const auto dimmerRedLayer =
ramindanidcecfd42022-02-03 23:52:19 +00001005 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001006 dimmerRedLayer->setColor(RED);
1007 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
1008 // Intentionally use a small dimming ratio as some implementations may be more likely to
1009 // kick into GPU composition to apply dithering when the dimming ratio is high.
1010 static constexpr float kDimmingRatio = 0.9f;
1011 dimmerRedLayer->setWhitePointNits(maxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -08001012 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -08001013
1014 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +00001015 std::vector<Color> expectedColors(
1016 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -08001017
ramindanidcecfd42022-02-03 23:52:19 +00001018 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
1019 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -08001020
ramindanidcecfd42022-02-03 23:52:19 +00001021 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1022 getDisplayHeight(), mPixelFormat, mDataspace);
Alec Mouri51067012022-01-06 17:28:39 -08001023 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1024
1025 writeLayers(layers);
1026 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001027 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
Alec Mouri51067012022-01-06 17:28:39 -08001028 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001029 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -08001030 GTEST_SUCCEED()
1031 << "Readback verification not supported for GPU composition for color mode: "
1032 << toString(mode);
1033 continue;
1034 }
ramindanidcecfd42022-02-03 23:52:19 +00001035 mWriter.presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001036 execute();
1037 ASSERT_TRUE(mReader.takeErrors().empty());
1038
1039 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1040 mTestRenderEngine->setRenderLayers(layers);
1041 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1042 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1043 }
1044}
1045
ramindanibab8ba92021-11-18 01:24:11 +00001046class GraphicsBlendModeCompositionTest
1047 : public GraphicsCompositionTestBase,
1048 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
1049 public:
1050 void SetUp() override {
1051 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +00001052 // TODO(b/219590743) we should remove the below SRGB color mode
1053 // once we have the BlendMode test fix for all the versions of the ColorMode
1054 mTestColorModes = {ColorMode::SRGB};
ramindanibab8ba92021-11-18 01:24:11 +00001055 mBackgroundColor = BLACK;
1056 mTopLayerColor = RED;
1057 }
1058
1059 void setBackgroundColor(Color color) { mBackgroundColor = color; }
1060
1061 void setTopLayerColor(Color color) { mTopLayerColor = color; }
1062
1063 void setUpLayers(BlendMode blendMode) {
1064 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +00001065 std::vector<Color> topLayerPixelColors(
1066 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1067 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
1068 {0, 0, getDisplayWidth(), getDisplayHeight()},
1069 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +00001070
ramindanidcecfd42022-02-03 23:52:19 +00001071 auto backgroundLayer =
1072 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
1073 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001074 backgroundLayer->setZOrder(0);
1075 backgroundLayer->setColor(mBackgroundColor);
1076
ramindani0a2bee42022-02-10 01:27:42 +00001077 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1078 getPrimaryDisplayId(), getDisplayWidth(),
1079 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +00001080 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001081 layer->setZOrder(10);
1082 layer->setDataspace(Dataspace::UNKNOWN, mWriter);
1083 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
1084
1085 layer->setBlendMode(blendMode);
1086 layer->setAlpha(std::stof(std::get<1>(GetParam())));
1087
1088 mLayers.push_back(backgroundLayer);
1089 mLayers.push_back(layer);
1090 }
1091
1092 void setExpectedColors(std::vector<Color>& expectedColors) {
1093 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001094 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1095 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001096
1097 auto layer = mLayers[1];
1098 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001099 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001100 if (blendMode == BlendMode::NONE) {
1101 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001102 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1103 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1104 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1105 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001106 }
1107 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1108 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001109 expectedColor.r =
1110 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1111 expectedColor.g =
1112 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1113 expectedColor.b =
1114 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1115 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001116 }
1117 } else if (blendMode == BlendMode::COVERAGE) {
1118 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001119 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1120 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1121 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1122 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001123 }
1124 }
1125 }
1126
1127 protected:
1128 std::vector<std::shared_ptr<TestLayer>> mLayers;
1129 Color mBackgroundColor;
1130 Color mTopLayerColor;
1131};
ramindanib636af22022-02-10 02:55:56 +00001132// TODO(b/219576457) Enable tests once we have fixed the bug on composer.
1133TEST_P(GraphicsBlendModeCompositionTest, DISABLED_None) {
ramindanibab8ba92021-11-18 01:24:11 +00001134 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001135 EXPECT_TRUE(mComposerClient
1136 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1137 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001138
ramindani44c952f2022-02-28 23:29:29 +00001139 bool isSupported;
1140 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001141 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001142 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1143 return;
1144 }
1145
ramindanidcecfd42022-02-03 23:52:19 +00001146 std::vector<Color> expectedColors(
1147 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001148
1149 setBackgroundColor(BLACK);
1150 setTopLayerColor(TRANSLUCENT_RED);
1151 setUpLayers(BlendMode::NONE);
1152 setExpectedColors(expectedColors);
1153
ramindanidcecfd42022-02-03 23:52:19 +00001154 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1155 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001156 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1157 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001158 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001159 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001160 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001161 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001162 GTEST_SUCCEED();
1163 return;
1164 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001165 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001166 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001167 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001168 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001169
1170 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1171 mTestRenderEngine->setRenderLayers(mLayers);
1172 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1173 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1174 }
1175}
1176
ramindani07e6f842022-02-15 15:28:33 +00001177TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001178 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001179 EXPECT_TRUE(mComposerClient
1180 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1181 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001182
ramindani44c952f2022-02-28 23:29:29 +00001183 bool isSupported;
1184 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001185 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001186 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1187 return;
1188 }
1189
ramindanidcecfd42022-02-03 23:52:19 +00001190 std::vector<Color> expectedColors(
1191 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001192
1193 setBackgroundColor(BLACK);
1194 setTopLayerColor(TRANSLUCENT_RED);
1195
1196 setUpLayers(BlendMode::COVERAGE);
1197 setExpectedColors(expectedColors);
1198
ramindanidcecfd42022-02-03 23:52:19 +00001199 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1200 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001201 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1202 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001203 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001204 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001205 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001206 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001207 GTEST_SUCCEED();
1208 return;
1209 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001210 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001211 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001212 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001213 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001214 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1215 }
1216}
1217
1218TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1219 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001220 EXPECT_TRUE(mComposerClient
1221 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1222 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001223
ramindani44c952f2022-02-28 23:29:29 +00001224 bool isSupported;
1225 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001226 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001227 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1228 return;
1229 }
ramindanibab8ba92021-11-18 01:24:11 +00001230
ramindanidcecfd42022-02-03 23:52:19 +00001231 std::vector<Color> expectedColors(
1232 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001233
1234 setBackgroundColor(BLACK);
1235 setTopLayerColor(TRANSLUCENT_RED);
1236 setUpLayers(BlendMode::PREMULTIPLIED);
1237 setExpectedColors(expectedColors);
1238
ramindanidcecfd42022-02-03 23:52:19 +00001239 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1240 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001241 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1242 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001243 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001244 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001245 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001246 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001247 GTEST_SUCCEED();
1248 return;
1249 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001250 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001251 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001252 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001253 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001254 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1255 mTestRenderEngine->setRenderLayers(mLayers);
1256 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1257 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1258 }
1259}
1260
1261class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1262 protected:
1263 void SetUp() override {
1264 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001265
ramindanidcecfd42022-02-03 23:52:19 +00001266 auto backgroundLayer =
1267 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001268 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001269 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001270 backgroundLayer->setZOrder(0);
1271
ramindanidcecfd42022-02-03 23:52:19 +00001272 mSideLength =
1273 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001274 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1275 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1276
ramindani0a2bee42022-02-10 01:27:42 +00001277 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1278 getPrimaryDisplayId(), mSideLength, mSideLength,
1279 PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +00001280 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1281 mLayer->setZOrder(10);
1282
1283 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1284 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1285 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1286 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1287 mLayers = {backgroundLayer, mLayer};
1288 }
1289
1290 protected:
1291 std::shared_ptr<TestBufferLayer> mLayer;
1292 std::vector<std::shared_ptr<TestLayer>> mLayers;
1293 int mSideLength;
1294};
1295
1296TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1297 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001298 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1299 RenderIntent::COLORIMETRIC);
1300 if (!status.isOk() &&
1301 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1302 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001303 SUCCEED() << "ColorMode not supported, skip test";
1304 return;
1305 }
1306
ramindani44c952f2022-02-28 23:29:29 +00001307 bool isSupported;
1308 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001309 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001310 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1311 return;
1312 }
ramindanidcecfd42022-02-03 23:52:19 +00001313 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1314 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001315 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1316 mLayer->setTransform(Transform::FLIP_H);
1317 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1318
ramindanidcecfd42022-02-03 23:52:19 +00001319 std::vector<Color> expectedColors(
1320 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1321 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001322 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001323 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001324 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1325
1326 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001327 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001328 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001329 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001330 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001331 GTEST_SUCCEED();
1332 return;
1333 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001334 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001335 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001336 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001337 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001338
1339 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1340 mTestRenderEngine->setRenderLayers(mLayers);
1341 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1342 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1343 }
1344}
1345
1346TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1347 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001348 EXPECT_TRUE(mComposerClient
1349 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1350 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001351
ramindani44c952f2022-02-28 23:29:29 +00001352 bool isSupported;
1353 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001354 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001355 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1356 return;
1357 }
ramindanidcecfd42022-02-03 23:52:19 +00001358 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1359 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001360 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1361
1362 mLayer->setTransform(Transform::FLIP_V);
1363 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1364
ramindanidcecfd42022-02-03 23:52:19 +00001365 std::vector<Color> expectedColors(
1366 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1367 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001368 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001369 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001370 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1371
1372 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001373 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001374 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001375 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001376 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001377 GTEST_SUCCEED();
1378 return;
1379 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001380 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001381 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001382 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001383 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001384 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1385 mTestRenderEngine->setRenderLayers(mLayers);
1386 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1387 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1388 }
1389}
1390
1391TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1392 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001393 EXPECT_TRUE(mComposerClient
1394 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1395 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001396
ramindani44c952f2022-02-28 23:29:29 +00001397 bool isSupported;
1398 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001399 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001400 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1401 return;
1402 }
ramindanidcecfd42022-02-03 23:52:19 +00001403 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1404 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001405 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1406
1407 mLayer->setTransform(Transform::ROT_180);
1408 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1409
ramindanidcecfd42022-02-03 23:52:19 +00001410 std::vector<Color> expectedColors(
1411 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1412 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001413 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1414 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001415 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001416 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1417
1418 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001419 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001420 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001421 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001422 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001423 GTEST_SUCCEED();
1424 return;
1425 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001426 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001427 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001428 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001429 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001430 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1431 mTestRenderEngine->setRenderLayers(mLayers);
1432 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1433 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1434 }
1435}
1436
1437GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1438INSTANTIATE_TEST_SUITE_P(
1439 PerInstance, GraphicsCompositionTest,
1440 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1441 ::android::PrintInstanceNameToString);
1442
1443GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1444INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1445 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1446 IComposer::descriptor)),
1447 testing::Values("0.2", "1.0")));
1448
1449GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1450INSTANTIATE_TEST_SUITE_P(
1451 PerInstance, GraphicsTransformCompositionTest,
1452 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1453 ::android::PrintInstanceNameToString);
1454
1455} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001456} // namespace aidl::android::hardware::graphics::composer3::vts