blob: 46dde09dd404775fdd9912fff8cd08fa87888a46 [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
ramindanid5751092022-04-22 22:30:20 +0000112 void assertServiceSpecificError(const ScopedAStatus& status, int32_t serviceSpecificError) {
113 ASSERT_EQ(status.getExceptionCode(), EX_SERVICE_SPECIFIC);
114 ASSERT_EQ(status.getServiceSpecificError(), serviceSpecificError);
115 }
116
ramindani0a2bee42022-02-10 01:27:42 +0000117 std::pair<bool, ::android::sp<::android::GraphicBuffer>> allocateBuffer(uint32_t usage) {
ramindanidcecfd42022-02-03 23:52:19 +0000118 const auto width = static_cast<uint32_t>(getDisplayWidth());
119 const auto height = static_cast<uint32_t>(getDisplayHeight());
Ady Abraham46219f52021-12-20 09:44:31 -0800120
ramindani0a2bee42022-02-10 01:27:42 +0000121 const auto& graphicBuffer = ::android::sp<::android::GraphicBuffer>::make(
Ady Abraham46219f52021-12-20 09:44:31 -0800122 width, height, ::android::PIXEL_FORMAT_RGBA_8888,
123 /*layerCount*/ 1u, usage, "VtsHalGraphicsComposer3_ReadbackTest");
ramindani0a2bee42022-02-10 01:27:42 +0000124
125 if (graphicBuffer && ::android::OK == graphicBuffer->initCheck()) {
126 return {true, graphicBuffer};
127 }
128 return {false, graphicBuffer};
ramindanibab8ba92021-11-18 01:24:11 +0000129 }
130
Alec Mouri51067012022-01-06 17:28:39 -0800131 uint64_t getStableDisplayId(int64_t display) {
ramindanidcecfd42022-02-03 23:52:19 +0000132 const auto& [status, identification] =
133 mComposerClient->getDisplayIdentificationData(display);
134 EXPECT_TRUE(status.isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800135
136 if (const auto info = ::android::parseDisplayIdentificationData(
137 static_cast<uint8_t>(identification.port), identification.data)) {
138 return info->id.value;
139 }
140
141 return ::android::PhysicalDisplayId::fromPort(static_cast<uint8_t>(identification.port))
142 .value;
143 }
144
145 // Gets the per-display XML config
146 std::unique_ptr<tinyxml2::XMLDocument> getDisplayConfigXml(int64_t display) {
147 std::stringstream pathBuilder;
148 pathBuilder << "/vendor/etc/displayconfig/display_id_" << getStableDisplayId(display)
149 << ".xml";
150 const std::string path = pathBuilder.str();
151 auto document = std::make_unique<tinyxml2::XMLDocument>();
152 const tinyxml2::XMLError error = document->LoadFile(path.c_str());
153 if (error == tinyxml2::XML_SUCCESS) {
154 return document;
155 } else {
156 return nullptr;
157 }
158 }
159
160 // Gets the max display brightness for this display.
161 // If the display config xml does not exist, then assume that the display is not well-configured
162 // enough to provide a display brightness, so return nullopt.
163 std::optional<float> getMaxDisplayBrightnessNits(int64_t display) {
164 const auto document = getDisplayConfigXml(display);
165 if (!document) {
166 // Assume the device doesn't support display brightness
167 return std::nullopt;
168 }
169
170 const auto root = document->RootElement();
171 if (!root) {
172 // If there's somehow no root element, then this isn't a valid config
173 return std::nullopt;
174 }
175
176 const auto screenBrightnessMap = root->FirstChildElement("screenBrightnessMap");
177 if (!screenBrightnessMap) {
178 // A valid display config must have a screen brightness map
179 return std::nullopt;
180 }
181
182 auto point = screenBrightnessMap->FirstChildElement("point");
183 float maxNits = -1.f;
184 while (point != nullptr) {
185 const auto nits = point->FirstChildElement("nits");
186 if (nits) {
187 maxNits = std::max(maxNits, nits->FloatText(-1.f));
188 }
189 point = point->NextSiblingElement("point");
190 }
191
192 if (maxNits < 0.f) {
193 // If we got here, then there were no point elements containing a nit value, so this
194 // config isn't valid
195 return std::nullopt;
196 }
197
198 return maxNits;
199 }
200
ramindanibab8ba92021-11-18 01:24:11 +0000201 void writeLayers(const std::vector<std::shared_ptr<TestLayer>>& layers) {
ramindanidcecfd42022-02-03 23:52:19 +0000202 for (const auto& layer : layers) {
ramindanibab8ba92021-11-18 01:24:11 +0000203 layer->write(mWriter);
204 }
205 execute();
206 }
207
208 void execute() {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800209 const auto& commands = mWriter.getPendingCommands();
210 if (commands.empty()) {
211 mWriter.reset();
212 return;
ramindanibab8ba92021-11-18 01:24:11 +0000213 }
214
ramindanidcecfd42022-02-03 23:52:19 +0000215 auto [status, results] = mComposerClient->executeCommands(commands);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800216 ASSERT_TRUE(status.isOk()) << "executeCommands failed " << status.getDescription();
ramindanibab8ba92021-11-18 01:24:11 +0000217
Ady Abraham46219f52021-12-20 09:44:31 -0800218 mReader.parse(std::move(results));
Ady Abraham3192f3d2021-12-03 16:08:56 -0800219 mWriter.reset();
ramindanibab8ba92021-11-18 01:24:11 +0000220 }
221
ramindani44c952f2022-02-28 23:29:29 +0000222 bool getHasReadbackBuffer() {
ramindanidcecfd42022-02-03 23:52:19 +0000223 auto [status, readBackBufferAttributes] =
224 mComposerClient->getReadbackBufferAttributes(getPrimaryDisplayId());
225 if (status.isOk()) {
226 mPixelFormat = readBackBufferAttributes.format;
227 mDataspace = readBackBufferAttributes.dataspace;
ramindani44c952f2022-02-28 23:29:29 +0000228 return ReadbackHelper::readbackSupported(mPixelFormat, mDataspace);
ramindanidcecfd42022-02-03 23:52:19 +0000229 }
ramindanid5751092022-04-22 22:30:20 +0000230 EXPECT_NO_FATAL_FAILURE(
231 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
ramindani44c952f2022-02-28 23:29:29 +0000232 return false;
ramindanib27f33b2021-12-03 19:36:10 +0000233 }
234
ramindanidcecfd42022-02-03 23:52:19 +0000235 std::shared_ptr<VtsComposerClient> mComposerClient;
236 std::vector<VtsDisplay> mDisplays;
237 // use the slot count usually set by SF
ramindanibab8ba92021-11-18 01:24:11 +0000238 std::vector<ColorMode> mTestColorModes;
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800239 ComposerClientWriter mWriter;
240 ComposerClientReader mReader;
ramindanibab8ba92021-11-18 01:24:11 +0000241 std::unique_ptr<TestRenderEngine> mTestRenderEngine;
ramindanibab8ba92021-11-18 01:24:11 +0000242 common::PixelFormat mPixelFormat;
243 common::Dataspace mDataspace;
244
245 static constexpr uint32_t kClientTargetSlotCount = 64;
246
247 private:
ramindanibab8ba92021-11-18 01:24:11 +0000248 void setTestColorModes() {
249 mTestColorModes.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000250 const auto& [status, modes] = mComposerClient->getColorModes(getPrimaryDisplayId());
251 ASSERT_TRUE(status.isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000252
253 for (ColorMode mode : modes) {
254 if (std::find(ReadbackHelper::colorModes.begin(), ReadbackHelper::colorModes.end(),
255 mode) != ReadbackHelper::colorModes.end()) {
256 mTestColorModes.push_back(mode);
257 }
258 }
259 }
260};
261
262class GraphicsCompositionTest : public GraphicsCompositionTestBase,
263 public testing::WithParamInterface<std::string> {
264 public:
265 void SetUp() override { SetUpBase(GetParam()); }
266};
267
268TEST_P(GraphicsCompositionTest, SingleSolidColorLayer) {
269 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000270 EXPECT_TRUE(mComposerClient
271 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
272 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000273
ramindani44c952f2022-02-28 23:29:29 +0000274 bool isSupported;
275 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000276 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000277 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
278 return;
279 }
280
ramindanidcecfd42022-02-03 23:52:19 +0000281 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
282 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000283 layer->setColor(BLUE);
284 layer->setDisplayFrame(coloredSquare);
285 layer->setZOrder(10);
286
287 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
288
289 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000290 std::vector<Color> expectedColors(
291 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
292 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000293
ramindanidcecfd42022-02-03 23:52:19 +0000294 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
295 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000296 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
297
298 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800299 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000300 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000301 execute();
302 // if hwc cannot handle and asks for composition change,
303 // just succeed the test
ramindanidcecfd42022-02-03 23:52:19 +0000304 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000305 GTEST_SUCCEED();
306 return;
307 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800308 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000309 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000310 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800311 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000312
313 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
314 mTestRenderEngine->setRenderLayers(layers);
315 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
316 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
317 }
318}
319
320TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
321 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000322 EXPECT_TRUE(mComposerClient
323 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
324 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000325
ramindani44c952f2022-02-28 23:29:29 +0000326 bool isSupported;
327 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000328 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000329 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
330 return;
331 }
332
ramindanidcecfd42022-02-03 23:52:19 +0000333 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
334 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000335 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000336 std::vector<Color> expectedColors(
337 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
338 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
339 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
340 ReadbackHelper::fillColorsArea(
341 expectedColors, getDisplayWidth(),
342 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
343 ReadbackHelper::fillColorsArea(
344 expectedColors, getDisplayWidth(),
345 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000346
347 auto layer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000348 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
349 getDisplayHeight(), common::PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000350 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000351 layer->setZOrder(10);
352 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
353 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
354
355 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
356
357 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800358 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000359 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000360 execute();
361
ramindanidcecfd42022-02-03 23:52:19 +0000362 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000363 GTEST_SUCCEED();
364 return;
365 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800366 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000367
ramindanidcecfd42022-02-03 23:52:19 +0000368 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000369 execute();
370
Ady Abraham3192f3d2021-12-03 16:08:56 -0800371 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000372
373 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
374 mTestRenderEngine->setRenderLayers(layers);
375 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
376 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
377 }
378}
379
380TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
381 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000382 EXPECT_TRUE(mComposerClient
383 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
384 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000385
ramindani44c952f2022-02-28 23:29:29 +0000386 bool isSupported;
387 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000388 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000389 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
390 return;
391 }
392
ramindanidcecfd42022-02-03 23:52:19 +0000393 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
394 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000395 layer->setColor(BLUE);
396 layer->setDisplayFrame(coloredSquare);
397 layer->setZOrder(10);
398 layer->write(mWriter);
399
400 // This following buffer call should have no effect
ramindani0a2bee42022-02-10 01:27:42 +0000401 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
402 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
403 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
404 ASSERT_TRUE(graphicBufferStatus);
405 const auto& buffer = graphicBuffer->handle;
406 mWriter.setLayerBuffer(getPrimaryDisplayId(), layer->getLayer(), /*slot*/ 0, buffer,
ramindanidcecfd42022-02-03 23:52:19 +0000407 /*acquireFence*/ -1);
ramindanibab8ba92021-11-18 01:24:11 +0000408
409 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000410 std::vector<Color> expectedColors(
411 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
412 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000413
ramindanidcecfd42022-02-03 23:52:19 +0000414 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
415 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000416 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
417
ramindanidcecfd42022-02-03 23:52:19 +0000418 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000419 execute();
420
ramindanidcecfd42022-02-03 23:52:19 +0000421 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000422 GTEST_SUCCEED();
423 return;
424 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800425 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000426 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000427 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800428 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000429
430 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
431 }
432}
433
ramindanib27f33b2021-12-03 19:36:10 +0000434TEST_P(GraphicsCompositionTest, SetReadbackBuffer) {
ramindani44c952f2022-02-28 23:29:29 +0000435 bool isSupported;
436 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000437 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000438 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
439 return;
440 }
441
ramindanidcecfd42022-02-03 23:52:19 +0000442 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
443 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanib27f33b2021-12-03 19:36:10 +0000444
445 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
446}
447
ramindanidcecfd42022-02-03 23:52:19 +0000448TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadDisplay) {
ramindani44c952f2022-02-28 23:29:29 +0000449 bool isSupported;
450 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000451 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000452 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
453 return;
454 }
455
ramindani0a2bee42022-02-10 01:27:42 +0000456 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
457 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
458 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
459 ASSERT_TRUE(graphicBufferStatus);
460 const auto& bufferHandle = graphicBuffer->handle;
ramindanib27f33b2021-12-03 19:36:10 +0000461 ::ndk::ScopedFileDescriptor fence = ::ndk::ScopedFileDescriptor(-1);
462
ramindanidcecfd42022-02-03 23:52:19 +0000463 const auto status =
464 mComposerClient->setReadbackBuffer(getInvalidDisplayId(), bufferHandle, fence);
ramindanib27f33b2021-12-03 19:36:10 +0000465
ramindanidcecfd42022-02-03 23:52:19 +0000466 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000467 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
ramindanib27f33b2021-12-03 19:36:10 +0000468}
469
ramindanidcecfd42022-02-03 23:52:19 +0000470TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadParameter) {
ramindani44c952f2022-02-28 23:29:29 +0000471 bool isSupported;
472 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000473 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000474 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
475 return;
476 }
477
ramindanidcecfd42022-02-03 23:52:19 +0000478 const native_handle_t bufferHandle{};
ramindanib27f33b2021-12-03 19:36:10 +0000479 ndk::ScopedFileDescriptor releaseFence = ndk::ScopedFileDescriptor(-1);
ramindanidcecfd42022-02-03 23:52:19 +0000480 const auto status =
481 mComposerClient->setReadbackBuffer(getPrimaryDisplayId(), &bufferHandle, releaseFence);
ramindanib27f33b2021-12-03 19:36:10 +0000482
ramindanidcecfd42022-02-03 23:52:19 +0000483 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000484 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
ramindanib27f33b2021-12-03 19:36:10 +0000485}
486
487TEST_P(GraphicsCompositionTest, GetReadbackBufferFenceInactive) {
ramindani44c952f2022-02-28 23:29:29 +0000488 bool isSupported;
489 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000490 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000491 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
492 return;
493 }
494
ramindanidcecfd42022-02-03 23:52:19 +0000495 const auto& [status, releaseFence] =
496 mComposerClient->getReadbackBufferFence(getPrimaryDisplayId());
ramindanib27f33b2021-12-03 19:36:10 +0000497
ramindanidcecfd42022-02-03 23:52:19 +0000498 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000499 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
Alec Mouri62ae37b2022-01-20 17:16:38 -0800500 EXPECT_EQ(-1, releaseFence.get());
ramindanib27f33b2021-12-03 19:36:10 +0000501}
502
ramindanibab8ba92021-11-18 01:24:11 +0000503TEST_P(GraphicsCompositionTest, ClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000504 EXPECT_TRUE(
505 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
506 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000507
508 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000509 EXPECT_TRUE(mComposerClient
510 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
ramindanibab8ba92021-11-18 01:24:11 +0000511 .isOk());
512
ramindani44c952f2022-02-28 23:29:29 +0000513 bool isSupported;
514 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000515 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000516 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
517 return;
518 }
519
ramindanidcecfd42022-02-03 23:52:19 +0000520 std::vector<Color> expectedColors(
521 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
522 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
523 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
524 ReadbackHelper::fillColorsArea(
525 expectedColors, getDisplayWidth(),
526 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
527 ReadbackHelper::fillColorsArea(
528 expectedColors, getDisplayWidth(),
529 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000530
ramindani0a2bee42022-02-10 01:27:42 +0000531 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
532 getPrimaryDisplayId(), getDisplayWidth(),
533 getDisplayHeight(), PixelFormat::RGBA_FP16);
ramindanidcecfd42022-02-03 23:52:19 +0000534 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000535 layer->setZOrder(10);
536 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
537
538 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
539
ramindanidcecfd42022-02-03 23:52:19 +0000540 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
541 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000542 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
543 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800544 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000545 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000546 execute();
547
ramindanidcecfd42022-02-03 23:52:19 +0000548 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800549 if (!changedCompositionTypes.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800550 ASSERT_EQ(1, changedCompositionTypes.size());
Ady Abraham46219f52021-12-20 09:44:31 -0800551 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindanibab8ba92021-11-18 01:24:11 +0000552
553 PixelFormat clientFormat = PixelFormat::RGBA_8888;
554 auto clientUsage = static_cast<uint32_t>(
555 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN) |
556 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
557 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
558 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000559 common::Rect damage{0, 0, getDisplayWidth(), getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000560
561 // create client target buffer
ramindani0a2bee42022-02-10 01:27:42 +0000562 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
563 ASSERT_TRUE(graphicBufferStatus);
564 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000565 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000566 const auto stride = static_cast<uint32_t>(graphicBuffer->stride);
567 graphicBuffer->lock(clientUsage, layer->getAccessRegion(), &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000568
569 ASSERT_NO_FATAL_FAILURE(
ramindani0a2bee42022-02-10 01:27:42 +0000570 ReadbackHelper::fillBuffer(layer->getWidth(), layer->getHeight(), stride,
ramindanibab8ba92021-11-18 01:24:11 +0000571 clientBufData, clientFormat, expectedColors));
ramindanib1144212022-02-10 01:51:24 +0000572 int32_t clientFence;
573 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
574 ASSERT_EQ(::android::OK, unlockStatus);
ramindanib1144212022-02-10 01:51:24 +0000575 mWriter.setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
ramindani0a2bee42022-02-10 01:27:42 +0000576 clientDataspace, std::vector<common::Rect>(1, damage));
ramindanib1144212022-02-10 01:51:24 +0000577 layer->setToClientComposition(mWriter);
578 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000579 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000580 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800581 ASSERT_TRUE(changedCompositionTypes.empty());
ramindanibab8ba92021-11-18 01:24:11 +0000582 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800583 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000584
ramindanidcecfd42022-02-03 23:52:19 +0000585 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000586 execute();
587
Ady Abraham3192f3d2021-12-03 16:08:56 -0800588 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000589
590 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
591 }
592}
593
594TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000595 ASSERT_TRUE(
596 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
597 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000598
599 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000600 EXPECT_TRUE(mComposerClient
601 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
602 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000603
ramindani44c952f2022-02-28 23:29:29 +0000604 bool isSupported;
605 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000606 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000607 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
608 return;
609 }
610
ramindanidcecfd42022-02-03 23:52:19 +0000611 std::vector<Color> expectedColors(
612 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
613 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
614 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
615 ReadbackHelper::fillColorsArea(
616 expectedColors, getDisplayWidth(),
617 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000618
ramindanidcecfd42022-02-03 23:52:19 +0000619 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
620 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000621 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
622
623 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000624 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
625 getDisplayHeight() / 2, PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +0000626 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
627 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
628 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
629 static_cast<int32_t>(deviceLayer->getHeight())},
630 GREEN);
631 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
632 static_cast<int32_t>(deviceLayer->getHeight())});
633 deviceLayer->setZOrder(10);
634 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
635 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
636 deviceLayer->write(mWriter);
637
638 PixelFormat clientFormat = PixelFormat::RGBA_8888;
639 auto clientUsage = static_cast<uint32_t>(
640 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
641 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
642 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
643 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000644 int32_t clientWidth = getDisplayWidth();
645 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000646
647 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000648 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
649 clientHeight, PixelFormat::RGBA_FP16, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000650 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
651 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000652 clientLayer->setDisplayFrame(clientFrame);
653 clientLayer->setZOrder(0);
654 clientLayer->write(mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000655 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000656 execute();
657
ramindanidcecfd42022-02-03 23:52:19 +0000658 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800659 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000660 continue;
661 }
662 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800663 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindani0a2bee42022-02-10 01:27:42 +0000664 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
665 ASSERT_TRUE(graphicBufferStatus);
666 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000667
668 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000669 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
670 &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000671
ramindanidcecfd42022-02-03 23:52:19 +0000672 std::vector<Color> clientColors(
673 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
674 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000675 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000676 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
ramindani0a2bee42022-02-10 01:27:42 +0000677 graphicBuffer->getStride(), clientBufData, clientFormat, clientColors));
ramindanib1144212022-02-10 01:51:24 +0000678 int32_t clientFence;
679 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
680 ASSERT_EQ(::android::OK, unlockStatus);
ramindanib1144212022-02-10 01:51:24 +0000681 mWriter.setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
ramindani0a2bee42022-02-10 01:27:42 +0000682 clientDataspace, std::vector<common::Rect>(1, clientFrame));
ramindanib1144212022-02-10 01:51:24 +0000683 clientLayer->setToClientComposition(mWriter);
684 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000685 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000686 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800687 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800688 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000689
ramindanidcecfd42022-02-03 23:52:19 +0000690 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000691 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800692 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000693 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
694 }
695}
696
697TEST_P(GraphicsCompositionTest, SetLayerDamage) {
698 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000699 EXPECT_TRUE(mComposerClient
700 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
701 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000702
ramindani44c952f2022-02-28 23:29:29 +0000703 bool isSupported;
704 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000705 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000706 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
707 return;
708 }
709
ramindanidcecfd42022-02-03 23:52:19 +0000710 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000711
ramindanidcecfd42022-02-03 23:52:19 +0000712 std::vector<Color> expectedColors(
713 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
714 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000715
ramindani0a2bee42022-02-10 01:27:42 +0000716 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
717 getPrimaryDisplayId(), getDisplayWidth(),
718 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000719 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000720 layer->setZOrder(10);
721 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
722 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
723
724 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
725
ramindanidcecfd42022-02-03 23:52:19 +0000726 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
727 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000728 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
729
730 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800731 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000732 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000733 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000734 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000735 GTEST_SUCCEED();
736 return;
737 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800738 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000739 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000740 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800741 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000742
743 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
744
745 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +0000746 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
747 getDisplayHeight() / 2};
748 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
749 getDisplayWidth());
750 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000751
752 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
753 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +0000754 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +0000755
756 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
757
758 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800759 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000760 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000761 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800762 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000763 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
764 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000765 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800766 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000767
768 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
769 }
770}
771
772TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
773 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000774 EXPECT_TRUE(mComposerClient
775 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
776 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000777
ramindani44c952f2022-02-28 23:29:29 +0000778 bool isSupported;
779 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000780 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000781 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
782 return;
783 }
784
ramindanidcecfd42022-02-03 23:52:19 +0000785 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000786 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +0000787 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000788 layer->setZOrder(10);
789 layer->setAlpha(0);
790 layer->setBlendMode(BlendMode::PREMULTIPLIED);
791
792 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
793
ramindanidcecfd42022-02-03 23:52:19 +0000794 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
795 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000796
797 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
798
799 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800800 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000801 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000802 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000803 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000804 GTEST_SUCCEED();
805 return;
806 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800807 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000808
ramindanidcecfd42022-02-03 23:52:19 +0000809 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000810 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800811 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000812
ramindanidcecfd42022-02-03 23:52:19 +0000813 std::vector<Color> expectedColors(
814 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000815
816 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
817 mTestRenderEngine->setRenderLayers(layers);
818 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
819 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
820 }
821}
822
823TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
824 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000825 EXPECT_TRUE(mComposerClient
826 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
827 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000828
ramindani44c952f2022-02-28 23:29:29 +0000829 bool isSupported;
830 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000831 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000832 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
833 return;
834 }
835
ramindanidcecfd42022-02-03 23:52:19 +0000836 std::vector<Color> expectedColors(
837 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
838 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
839 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
840 ReadbackHelper::fillColorsArea(
841 expectedColors, getDisplayWidth(),
842 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000843
ramindani0a2bee42022-02-10 01:27:42 +0000844 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
845 getPrimaryDisplayId(), getDisplayWidth(),
846 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000847 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000848 layer->setZOrder(10);
849 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000850 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
851 static_cast<float>(getDisplayWidth()),
852 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +0000853 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
854
855 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
856
857 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +0000858 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
859 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
860 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
861 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000862 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
863 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800864 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000865 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000866 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000867 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000868 GTEST_SUCCEED();
869 return;
870 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800871 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000872 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000873 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800874 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000875 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
876 mTestRenderEngine->setRenderLayers(layers);
877 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
878 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
879 }
880}
881
882TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
883 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000884 EXPECT_TRUE(mComposerClient
885 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
886 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000887
ramindani44c952f2022-02-28 23:29:29 +0000888 bool isSupported;
889 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000890 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000891 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
892 return;
893 }
894
ramindanidcecfd42022-02-03 23:52:19 +0000895 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
896 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
897 auto redLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000898 redLayer->setColor(RED);
899 redLayer->setDisplayFrame(redRect);
900
ramindanidcecfd42022-02-03 23:52:19 +0000901 auto blueLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000902 blueLayer->setColor(BLUE);
903 blueLayer->setDisplayFrame(blueRect);
904 blueLayer->setZOrder(5);
905
906 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000907 std::vector<Color> expectedColors(
908 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000909
910 // red in front of blue
911 redLayer->setZOrder(10);
912
913 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +0000914 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
915 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000916
ramindanidcecfd42022-02-03 23:52:19 +0000917 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
918 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000919 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
920
921 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800922 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000923 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000924 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000925 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000926 GTEST_SUCCEED();
927 return;
928 }
ramindanidcecfd42022-02-03 23:52:19 +0000929 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000930 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800931 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000932
933 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
934
935 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +0000936 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
937 getDisplayWidth());
938 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
939 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000940
941 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
942
943 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800944 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000945 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000946 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000947 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800948 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000949 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000950 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800951 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000952
953 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
954 mTestRenderEngine->setRenderLayers(layers);
955 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
956 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
957 }
958}
959
Alec Mourib1f16722022-02-07 13:03:44 -0800960TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
ramindanidcecfd42022-02-03 23:52:19 +0000961 const auto& [status, capabilities] =
962 mComposerClient->getDisplayCapabilities(getPrimaryDisplayId());
963 ASSERT_TRUE(status.isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800964
965 const bool brightnessSupport = std::find(capabilities.begin(), capabilities.end(),
966 DisplayCapability::BRIGHTNESS) != capabilities.end();
967
968 if (!brightnessSupport) {
969 GTEST_SUCCEED() << "Cannot verify dimming behavior without brightness support";
970 return;
971 }
972
973 const std::optional<float> maxBrightnessNitsOptional =
ramindanidcecfd42022-02-03 23:52:19 +0000974 getMaxDisplayBrightnessNits(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800975
976 ASSERT_TRUE(maxBrightnessNitsOptional.has_value());
977
978 const float maxBrightnessNits = *maxBrightnessNitsOptional;
979
980 // Preconditions to successfully run are knowing the max brightness and successfully applying
981 // the max brightness
982 ASSERT_GT(maxBrightnessNits, 0.f);
Alec Mouri03b6daa2022-03-23 18:45:02 +0000983 mWriter.setDisplayBrightness(getPrimaryDisplayId(), /*brightness*/ 1.f, maxBrightnessNits);
Alec Mouri51067012022-01-06 17:28:39 -0800984 execute();
985 ASSERT_TRUE(mReader.takeErrors().empty());
986
987 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000988 EXPECT_TRUE(mComposerClient
989 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
990 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800991
ramindani44c952f2022-02-28 23:29:29 +0000992 bool isSupported;
993 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000994 if (!isSupported) {
Alec Mouri51067012022-01-06 17:28:39 -0800995 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
996 "color mode: "
997 << toString(mode);
998 continue;
999 }
ramindanidcecfd42022-02-03 23:52:19 +00001000 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
1001 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
1002 getDisplayHeight()};
1003 const auto redLayer =
1004 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001005 redLayer->setColor(RED);
1006 redLayer->setDisplayFrame(redRect);
1007 redLayer->setWhitePointNits(maxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -08001008 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -08001009
1010 const auto dimmerRedLayer =
ramindanidcecfd42022-02-03 23:52:19 +00001011 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001012 dimmerRedLayer->setColor(RED);
1013 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
1014 // Intentionally use a small dimming ratio as some implementations may be more likely to
1015 // kick into GPU composition to apply dithering when the dimming ratio is high.
1016 static constexpr float kDimmingRatio = 0.9f;
1017 dimmerRedLayer->setWhitePointNits(maxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -08001018 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -08001019
1020 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +00001021 std::vector<Color> expectedColors(
1022 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -08001023
ramindanidcecfd42022-02-03 23:52:19 +00001024 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
1025 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -08001026
ramindanidcecfd42022-02-03 23:52:19 +00001027 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1028 getDisplayHeight(), mPixelFormat, mDataspace);
Alec Mouri51067012022-01-06 17:28:39 -08001029 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1030
1031 writeLayers(layers);
1032 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001033 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
Alec Mouri51067012022-01-06 17:28:39 -08001034 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001035 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -08001036 GTEST_SUCCEED()
1037 << "Readback verification not supported for GPU composition for color mode: "
1038 << toString(mode);
1039 continue;
1040 }
ramindanidcecfd42022-02-03 23:52:19 +00001041 mWriter.presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001042 execute();
1043 ASSERT_TRUE(mReader.takeErrors().empty());
1044
1045 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1046 mTestRenderEngine->setRenderLayers(layers);
1047 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1048 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1049 }
1050}
1051
ramindanibab8ba92021-11-18 01:24:11 +00001052class GraphicsBlendModeCompositionTest
1053 : public GraphicsCompositionTestBase,
1054 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
1055 public:
1056 void SetUp() override {
1057 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +00001058 // TODO(b/219590743) we should remove the below SRGB color mode
1059 // once we have the BlendMode test fix for all the versions of the ColorMode
ramindania4e76362022-03-02 01:48:06 +00001060 mTestColorModes.erase(
1061 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
1062 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
1063 mTestColorModes.end());
ramindanibab8ba92021-11-18 01:24:11 +00001064 mBackgroundColor = BLACK;
1065 mTopLayerColor = RED;
1066 }
1067
1068 void setBackgroundColor(Color color) { mBackgroundColor = color; }
1069
1070 void setTopLayerColor(Color color) { mTopLayerColor = color; }
1071
1072 void setUpLayers(BlendMode blendMode) {
1073 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +00001074 std::vector<Color> topLayerPixelColors(
1075 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1076 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
1077 {0, 0, getDisplayWidth(), getDisplayHeight()},
1078 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +00001079
ramindanidcecfd42022-02-03 23:52:19 +00001080 auto backgroundLayer =
1081 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
1082 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001083 backgroundLayer->setZOrder(0);
1084 backgroundLayer->setColor(mBackgroundColor);
1085
ramindani0a2bee42022-02-10 01:27:42 +00001086 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1087 getPrimaryDisplayId(), getDisplayWidth(),
1088 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +00001089 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001090 layer->setZOrder(10);
1091 layer->setDataspace(Dataspace::UNKNOWN, mWriter);
1092 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
1093
1094 layer->setBlendMode(blendMode);
1095 layer->setAlpha(std::stof(std::get<1>(GetParam())));
1096
1097 mLayers.push_back(backgroundLayer);
1098 mLayers.push_back(layer);
1099 }
1100
1101 void setExpectedColors(std::vector<Color>& expectedColors) {
1102 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001103 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1104 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001105
1106 auto layer = mLayers[1];
1107 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001108 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001109 if (blendMode == BlendMode::NONE) {
1110 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001111 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1112 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1113 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1114 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001115 }
1116 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1117 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001118 expectedColor.r =
1119 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1120 expectedColor.g =
1121 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1122 expectedColor.b =
1123 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1124 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001125 }
1126 } else if (blendMode == BlendMode::COVERAGE) {
1127 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001128 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1129 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1130 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1131 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001132 }
1133 }
1134 }
1135
1136 protected:
1137 std::vector<std::shared_ptr<TestLayer>> mLayers;
1138 Color mBackgroundColor;
1139 Color mTopLayerColor;
1140};
ramindanic7585d92022-04-15 18:30:41 +00001141
1142TEST_P(GraphicsBlendModeCompositionTest, None) {
ramindanibab8ba92021-11-18 01:24:11 +00001143 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001144 EXPECT_TRUE(mComposerClient
1145 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1146 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001147
ramindani44c952f2022-02-28 23:29:29 +00001148 bool isSupported;
1149 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001150 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001151 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1152 return;
1153 }
1154
ramindanidcecfd42022-02-03 23:52:19 +00001155 std::vector<Color> expectedColors(
1156 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001157
1158 setBackgroundColor(BLACK);
1159 setTopLayerColor(TRANSLUCENT_RED);
1160 setUpLayers(BlendMode::NONE);
1161 setExpectedColors(expectedColors);
1162
ramindanidcecfd42022-02-03 23:52:19 +00001163 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1164 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001165 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1166 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001167 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001168 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001169 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001170 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001171 GTEST_SUCCEED();
1172 return;
1173 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001174 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001175 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001176 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001177 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001178
1179 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1180 mTestRenderEngine->setRenderLayers(mLayers);
1181 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1182 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1183 }
1184}
1185
ramindani07e6f842022-02-15 15:28:33 +00001186TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001187 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001188 EXPECT_TRUE(mComposerClient
1189 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1190 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001191
ramindani44c952f2022-02-28 23:29:29 +00001192 bool isSupported;
1193 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001194 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001195 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1196 return;
1197 }
1198
ramindanidcecfd42022-02-03 23:52:19 +00001199 std::vector<Color> expectedColors(
1200 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001201
1202 setBackgroundColor(BLACK);
1203 setTopLayerColor(TRANSLUCENT_RED);
1204
1205 setUpLayers(BlendMode::COVERAGE);
1206 setExpectedColors(expectedColors);
1207
ramindanidcecfd42022-02-03 23:52:19 +00001208 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1209 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001210 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1211 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001212 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001213 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001214 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001215 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001216 GTEST_SUCCEED();
1217 return;
1218 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001219 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001220 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001221 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001222 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001223 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1224 }
1225}
1226
1227TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1228 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001229 EXPECT_TRUE(mComposerClient
1230 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1231 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001232
ramindani44c952f2022-02-28 23:29:29 +00001233 bool isSupported;
1234 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001235 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001236 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1237 return;
1238 }
ramindanibab8ba92021-11-18 01:24:11 +00001239
ramindanidcecfd42022-02-03 23:52:19 +00001240 std::vector<Color> expectedColors(
1241 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001242
1243 setBackgroundColor(BLACK);
1244 setTopLayerColor(TRANSLUCENT_RED);
1245 setUpLayers(BlendMode::PREMULTIPLIED);
1246 setExpectedColors(expectedColors);
1247
ramindanidcecfd42022-02-03 23:52:19 +00001248 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1249 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001250 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1251 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001252 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001253 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001254 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001255 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001256 GTEST_SUCCEED();
1257 return;
1258 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001259 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001260 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001261 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001262 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001263 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1264 mTestRenderEngine->setRenderLayers(mLayers);
1265 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1266 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1267 }
1268}
1269
1270class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1271 protected:
1272 void SetUp() override {
1273 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001274
ramindanidcecfd42022-02-03 23:52:19 +00001275 auto backgroundLayer =
1276 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001277 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001278 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001279 backgroundLayer->setZOrder(0);
1280
ramindanidcecfd42022-02-03 23:52:19 +00001281 mSideLength =
1282 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001283 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1284 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1285
ramindani0a2bee42022-02-10 01:27:42 +00001286 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1287 getPrimaryDisplayId(), mSideLength, mSideLength,
1288 PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +00001289 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1290 mLayer->setZOrder(10);
1291
1292 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1293 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1294 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1295 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1296 mLayers = {backgroundLayer, mLayer};
1297 }
1298
1299 protected:
1300 std::shared_ptr<TestBufferLayer> mLayer;
1301 std::vector<std::shared_ptr<TestLayer>> mLayers;
1302 int mSideLength;
1303};
1304
1305TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1306 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001307 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1308 RenderIntent::COLORIMETRIC);
ramindanid5751092022-04-22 22:30:20 +00001309 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
ramindanidcecfd42022-02-03 23:52:19 +00001310 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1311 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001312 SUCCEED() << "ColorMode not supported, skip test";
1313 return;
1314 }
1315
ramindani44c952f2022-02-28 23:29:29 +00001316 bool isSupported;
1317 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001318 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001319 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1320 return;
1321 }
ramindanidcecfd42022-02-03 23:52:19 +00001322 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1323 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001324 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1325 mLayer->setTransform(Transform::FLIP_H);
1326 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1327
ramindanidcecfd42022-02-03 23:52:19 +00001328 std::vector<Color> expectedColors(
1329 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1330 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001331 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001332 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001333 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1334
1335 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001336 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001337 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001338 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001339 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001340 GTEST_SUCCEED();
1341 return;
1342 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001343 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001344 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001345 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001346 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001347
1348 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1349 mTestRenderEngine->setRenderLayers(mLayers);
1350 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1351 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1352 }
1353}
1354
1355TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1356 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001357 EXPECT_TRUE(mComposerClient
1358 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1359 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001360
ramindani44c952f2022-02-28 23:29:29 +00001361 bool isSupported;
1362 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001363 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001364 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1365 return;
1366 }
ramindanidcecfd42022-02-03 23:52:19 +00001367 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1368 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001369 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1370
1371 mLayer->setTransform(Transform::FLIP_V);
1372 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1373
ramindanidcecfd42022-02-03 23:52:19 +00001374 std::vector<Color> expectedColors(
1375 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1376 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001377 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001378 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001379 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1380
1381 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001382 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001383 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001384 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001385 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001386 GTEST_SUCCEED();
1387 return;
1388 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001389 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001390 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001391 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001392 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001393 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1394 mTestRenderEngine->setRenderLayers(mLayers);
1395 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1396 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1397 }
1398}
1399
1400TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1401 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001402 EXPECT_TRUE(mComposerClient
1403 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1404 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001405
ramindani44c952f2022-02-28 23:29:29 +00001406 bool isSupported;
1407 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001408 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001409 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1410 return;
1411 }
ramindanidcecfd42022-02-03 23:52:19 +00001412 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1413 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001414 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1415
1416 mLayer->setTransform(Transform::ROT_180);
1417 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1418
ramindanidcecfd42022-02-03 23:52:19 +00001419 std::vector<Color> expectedColors(
1420 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1421 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001422 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1423 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001424 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001425 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1426
1427 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001428 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001429 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001430 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001431 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001432 GTEST_SUCCEED();
1433 return;
1434 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001435 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001436 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001437 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001438 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001439 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1440 mTestRenderEngine->setRenderLayers(mLayers);
1441 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1442 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1443 }
1444}
1445
1446GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1447INSTANTIATE_TEST_SUITE_P(
1448 PerInstance, GraphicsCompositionTest,
1449 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1450 ::android::PrintInstanceNameToString);
1451
1452GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1453INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1454 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1455 IComposer::descriptor)),
1456 testing::Values("0.2", "1.0")));
1457
1458GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1459INSTANTIATE_TEST_SUITE_P(
1460 PerInstance, GraphicsTransformCompositionTest,
1461 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1462 ::android::PrintInstanceNameToString);
1463
1464} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001465} // namespace aidl::android::hardware::graphics::composer3::vts