blob: f75af853004b8236d3af8345acde201393722864 [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
ramindanidcecfd42022-02-03 23:52:19 +0000217 std::pair<ScopedAStatus, bool> getHasReadbackBuffer() {
218 auto [status, readBackBufferAttributes] =
219 mComposerClient->getReadbackBufferAttributes(getPrimaryDisplayId());
220 if (status.isOk()) {
221 mPixelFormat = readBackBufferAttributes.format;
222 mDataspace = readBackBufferAttributes.dataspace;
223 return {std::move(status), ReadbackHelper::readbackSupported(mPixelFormat, mDataspace)};
224 }
225 return {std::move(status), false};
ramindanib27f33b2021-12-03 19:36:10 +0000226 }
227
ramindanidcecfd42022-02-03 23:52:19 +0000228 std::shared_ptr<VtsComposerClient> mComposerClient;
229 std::vector<VtsDisplay> mDisplays;
230 // use the slot count usually set by SF
ramindanibab8ba92021-11-18 01:24:11 +0000231 std::vector<ColorMode> mTestColorModes;
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800232 ComposerClientWriter mWriter;
233 ComposerClientReader mReader;
ramindanibab8ba92021-11-18 01:24:11 +0000234 std::unique_ptr<TestRenderEngine> mTestRenderEngine;
ramindanibab8ba92021-11-18 01:24:11 +0000235 common::PixelFormat mPixelFormat;
236 common::Dataspace mDataspace;
237
238 static constexpr uint32_t kClientTargetSlotCount = 64;
239
240 private:
ramindanibab8ba92021-11-18 01:24:11 +0000241 void setTestColorModes() {
242 mTestColorModes.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000243 const auto& [status, modes] = mComposerClient->getColorModes(getPrimaryDisplayId());
244 ASSERT_TRUE(status.isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000245
246 for (ColorMode mode : modes) {
247 if (std::find(ReadbackHelper::colorModes.begin(), ReadbackHelper::colorModes.end(),
248 mode) != ReadbackHelper::colorModes.end()) {
249 mTestColorModes.push_back(mode);
250 }
251 }
252 }
253};
254
255class GraphicsCompositionTest : public GraphicsCompositionTestBase,
256 public testing::WithParamInterface<std::string> {
257 public:
258 void SetUp() override { SetUpBase(GetParam()); }
259};
260
261TEST_P(GraphicsCompositionTest, SingleSolidColorLayer) {
262 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000263 EXPECT_TRUE(mComposerClient
264 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
265 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000266
ramindanidcecfd42022-02-03 23:52:19 +0000267 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
268 EXPECT_TRUE(readbackStatus.isOk());
269 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000270 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
271 return;
272 }
273
ramindanidcecfd42022-02-03 23:52:19 +0000274 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
275 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000276 layer->setColor(BLUE);
277 layer->setDisplayFrame(coloredSquare);
278 layer->setZOrder(10);
279
280 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
281
282 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000283 std::vector<Color> expectedColors(
284 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
285 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000286
ramindanidcecfd42022-02-03 23:52:19 +0000287 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
288 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000289 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
290
291 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800292 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000293 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000294 execute();
295 // if hwc cannot handle and asks for composition change,
296 // just succeed the test
ramindanidcecfd42022-02-03 23:52:19 +0000297 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000298 GTEST_SUCCEED();
299 return;
300 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800301 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000302 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000303 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800304 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000305
306 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
307 mTestRenderEngine->setRenderLayers(layers);
308 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
309 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
310 }
311}
312
313TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
314 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000315 EXPECT_TRUE(mComposerClient
316 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
317 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000318
ramindanidcecfd42022-02-03 23:52:19 +0000319 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
320 EXPECT_TRUE(readbackStatus.isOk());
321 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000322 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
323 return;
324 }
325
ramindanidcecfd42022-02-03 23:52:19 +0000326 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
327 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000328 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000329 std::vector<Color> expectedColors(
330 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
331 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
332 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
333 ReadbackHelper::fillColorsArea(
334 expectedColors, getDisplayWidth(),
335 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
336 ReadbackHelper::fillColorsArea(
337 expectedColors, getDisplayWidth(),
338 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000339
340 auto layer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000341 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
342 getDisplayHeight(), common::PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000343 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000344 layer->setZOrder(10);
345 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
346 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
347
348 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
349
350 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800351 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000352 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000353 execute();
354
ramindanidcecfd42022-02-03 23:52:19 +0000355 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000356 GTEST_SUCCEED();
357 return;
358 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800359 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000360
ramindanidcecfd42022-02-03 23:52:19 +0000361 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000362 execute();
363
Ady Abraham3192f3d2021-12-03 16:08:56 -0800364 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000365
366 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
367 mTestRenderEngine->setRenderLayers(layers);
368 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
369 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
370 }
371}
372
373TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
374 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000375 EXPECT_TRUE(mComposerClient
376 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
377 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000378
ramindanidcecfd42022-02-03 23:52:19 +0000379 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
380 EXPECT_TRUE(readbackStatus.isOk());
381 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000382 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
383 return;
384 }
385
ramindanidcecfd42022-02-03 23:52:19 +0000386 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
387 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000388 layer->setColor(BLUE);
389 layer->setDisplayFrame(coloredSquare);
390 layer->setZOrder(10);
391 layer->write(mWriter);
392
393 // This following buffer call should have no effect
ramindani0a2bee42022-02-10 01:27:42 +0000394 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
395 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
396 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
397 ASSERT_TRUE(graphicBufferStatus);
398 const auto& buffer = graphicBuffer->handle;
399 mWriter.setLayerBuffer(getPrimaryDisplayId(), layer->getLayer(), /*slot*/ 0, buffer,
ramindanidcecfd42022-02-03 23:52:19 +0000400 /*acquireFence*/ -1);
ramindanibab8ba92021-11-18 01:24:11 +0000401
402 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000403 std::vector<Color> expectedColors(
404 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
405 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000406
ramindanidcecfd42022-02-03 23:52:19 +0000407 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
408 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000409 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
410
ramindanidcecfd42022-02-03 23:52:19 +0000411 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000412 execute();
413
ramindanidcecfd42022-02-03 23:52:19 +0000414 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000415 GTEST_SUCCEED();
416 return;
417 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800418 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000419 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000420 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800421 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000422
423 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
424 }
425}
426
ramindanib27f33b2021-12-03 19:36:10 +0000427TEST_P(GraphicsCompositionTest, SetReadbackBuffer) {
ramindanidcecfd42022-02-03 23:52:19 +0000428 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
429 EXPECT_TRUE(readbackStatus.isOk());
430 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000431 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
432 return;
433 }
434
ramindanidcecfd42022-02-03 23:52:19 +0000435 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
436 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanib27f33b2021-12-03 19:36:10 +0000437
438 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
439}
440
ramindanidcecfd42022-02-03 23:52:19 +0000441TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadDisplay) {
442 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
443 EXPECT_TRUE(readbackStatus.isOk());
444 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000445 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
446 return;
447 }
448
ramindani0a2bee42022-02-10 01:27:42 +0000449 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
450 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
451 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
452 ASSERT_TRUE(graphicBufferStatus);
453 const auto& bufferHandle = graphicBuffer->handle;
ramindanib27f33b2021-12-03 19:36:10 +0000454 ::ndk::ScopedFileDescriptor fence = ::ndk::ScopedFileDescriptor(-1);
455
ramindanidcecfd42022-02-03 23:52:19 +0000456 const auto status =
457 mComposerClient->setReadbackBuffer(getInvalidDisplayId(), bufferHandle, fence);
ramindanib27f33b2021-12-03 19:36:10 +0000458
ramindanidcecfd42022-02-03 23:52:19 +0000459 EXPECT_FALSE(status.isOk());
460 ASSERT_EQ(IComposerClient::EX_BAD_DISPLAY, status.getServiceSpecificError());
ramindanib27f33b2021-12-03 19:36:10 +0000461}
462
ramindanidcecfd42022-02-03 23:52:19 +0000463TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadParameter) {
464 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
465 EXPECT_TRUE(readbackStatus.isOk());
466 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000467 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
468 return;
469 }
470
ramindanidcecfd42022-02-03 23:52:19 +0000471 const native_handle_t bufferHandle{};
ramindanib27f33b2021-12-03 19:36:10 +0000472 ndk::ScopedFileDescriptor releaseFence = ndk::ScopedFileDescriptor(-1);
ramindanidcecfd42022-02-03 23:52:19 +0000473 const auto status =
474 mComposerClient->setReadbackBuffer(getPrimaryDisplayId(), &bufferHandle, releaseFence);
ramindanib27f33b2021-12-03 19:36:10 +0000475
ramindanidcecfd42022-02-03 23:52:19 +0000476 EXPECT_FALSE(status.isOk());
477 ASSERT_EQ(IComposerClient::EX_BAD_PARAMETER, status.getServiceSpecificError());
ramindanib27f33b2021-12-03 19:36:10 +0000478}
479
480TEST_P(GraphicsCompositionTest, GetReadbackBufferFenceInactive) {
ramindanidcecfd42022-02-03 23:52:19 +0000481 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
482 EXPECT_TRUE(readbackStatus.isOk());
483 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000484 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
485 return;
486 }
487
ramindanidcecfd42022-02-03 23:52:19 +0000488 const auto& [status, releaseFence] =
489 mComposerClient->getReadbackBufferFence(getPrimaryDisplayId());
ramindanib27f33b2021-12-03 19:36:10 +0000490
ramindanidcecfd42022-02-03 23:52:19 +0000491 EXPECT_FALSE(status.isOk());
492 EXPECT_EQ(IComposerClient::EX_UNSUPPORTED, status.getServiceSpecificError());
Alec Mouri62ae37b2022-01-20 17:16:38 -0800493 EXPECT_EQ(-1, releaseFence.get());
ramindanib27f33b2021-12-03 19:36:10 +0000494}
495
ramindanibab8ba92021-11-18 01:24:11 +0000496TEST_P(GraphicsCompositionTest, ClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000497 EXPECT_TRUE(
498 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
499 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000500
501 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000502 EXPECT_TRUE(mComposerClient
503 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
ramindanibab8ba92021-11-18 01:24:11 +0000504 .isOk());
505
ramindanidcecfd42022-02-03 23:52:19 +0000506 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
507 EXPECT_TRUE(readbackStatus.isOk());
508 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000509 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
510 return;
511 }
512
ramindanidcecfd42022-02-03 23:52:19 +0000513 std::vector<Color> expectedColors(
514 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
515 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
516 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
517 ReadbackHelper::fillColorsArea(
518 expectedColors, getDisplayWidth(),
519 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
520 ReadbackHelper::fillColorsArea(
521 expectedColors, getDisplayWidth(),
522 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000523
ramindani0a2bee42022-02-10 01:27:42 +0000524 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
525 getPrimaryDisplayId(), getDisplayWidth(),
526 getDisplayHeight(), PixelFormat::RGBA_FP16);
ramindanidcecfd42022-02-03 23:52:19 +0000527 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000528 layer->setZOrder(10);
529 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
530
531 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
532
ramindanidcecfd42022-02-03 23:52:19 +0000533 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
534 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000535 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
536 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800537 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000538 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000539 execute();
540
ramindanidcecfd42022-02-03 23:52:19 +0000541 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800542 if (!changedCompositionTypes.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800543 ASSERT_EQ(1, changedCompositionTypes.size());
Ady Abraham46219f52021-12-20 09:44:31 -0800544 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindanibab8ba92021-11-18 01:24:11 +0000545
546 PixelFormat clientFormat = PixelFormat::RGBA_8888;
547 auto clientUsage = static_cast<uint32_t>(
548 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN) |
549 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
550 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
551 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000552 common::Rect damage{0, 0, getDisplayWidth(), getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000553
554 // create client target buffer
ramindani0a2bee42022-02-10 01:27:42 +0000555 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
556 ASSERT_TRUE(graphicBufferStatus);
557 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000558 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000559 const auto stride = static_cast<uint32_t>(graphicBuffer->stride);
560 graphicBuffer->lock(clientUsage, layer->getAccessRegion(), &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000561
562 ASSERT_NO_FATAL_FAILURE(
ramindani0a2bee42022-02-10 01:27:42 +0000563 ReadbackHelper::fillBuffer(layer->getWidth(), layer->getHeight(), stride,
ramindanibab8ba92021-11-18 01:24:11 +0000564 clientBufData, clientFormat, expectedColors));
ramindanib1144212022-02-10 01:51:24 +0000565 int32_t clientFence;
566 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
567 ASSERT_EQ(::android::OK, unlockStatus);
ramindanib1144212022-02-10 01:51:24 +0000568 mWriter.setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
ramindani0a2bee42022-02-10 01:27:42 +0000569 clientDataspace, std::vector<common::Rect>(1, damage));
ramindanib1144212022-02-10 01:51:24 +0000570 layer->setToClientComposition(mWriter);
571 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000572 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000573 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800574 ASSERT_TRUE(changedCompositionTypes.empty());
ramindanibab8ba92021-11-18 01:24:11 +0000575 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800576 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000577
ramindanidcecfd42022-02-03 23:52:19 +0000578 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000579 execute();
580
Ady Abraham3192f3d2021-12-03 16:08:56 -0800581 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000582
583 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
584 }
585}
586
587TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000588 ASSERT_TRUE(
589 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
590 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000591
592 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000593 EXPECT_TRUE(mComposerClient
594 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
595 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000596
ramindanidcecfd42022-02-03 23:52:19 +0000597 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
598 EXPECT_TRUE(readbackStatus.isOk());
599 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000600 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
601 return;
602 }
603
ramindanidcecfd42022-02-03 23:52:19 +0000604 std::vector<Color> expectedColors(
605 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
606 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
607 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
608 ReadbackHelper::fillColorsArea(
609 expectedColors, getDisplayWidth(),
610 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000611
ramindanidcecfd42022-02-03 23:52:19 +0000612 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
613 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000614 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
615
616 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000617 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
618 getDisplayHeight() / 2, PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +0000619 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
620 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
621 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
622 static_cast<int32_t>(deviceLayer->getHeight())},
623 GREEN);
624 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
625 static_cast<int32_t>(deviceLayer->getHeight())});
626 deviceLayer->setZOrder(10);
627 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
628 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
629 deviceLayer->write(mWriter);
630
631 PixelFormat clientFormat = PixelFormat::RGBA_8888;
632 auto clientUsage = static_cast<uint32_t>(
633 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
634 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
635 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
636 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000637 int32_t clientWidth = getDisplayWidth();
638 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000639
640 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000641 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
642 clientHeight, PixelFormat::RGBA_FP16, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000643 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
644 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000645 clientLayer->setDisplayFrame(clientFrame);
646 clientLayer->setZOrder(0);
647 clientLayer->write(mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000648 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000649 execute();
650
ramindanidcecfd42022-02-03 23:52:19 +0000651 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800652 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000653 continue;
654 }
655 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800656 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindani0a2bee42022-02-10 01:27:42 +0000657 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
658 ASSERT_TRUE(graphicBufferStatus);
659 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000660
661 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000662 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
663 &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000664
ramindanidcecfd42022-02-03 23:52:19 +0000665 std::vector<Color> clientColors(
666 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
667 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000668 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000669 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
ramindani0a2bee42022-02-10 01:27:42 +0000670 graphicBuffer->getStride(), clientBufData, clientFormat, clientColors));
ramindanib1144212022-02-10 01:51:24 +0000671 int32_t clientFence;
672 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
673 ASSERT_EQ(::android::OK, unlockStatus);
ramindanib1144212022-02-10 01:51:24 +0000674 mWriter.setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
ramindani0a2bee42022-02-10 01:27:42 +0000675 clientDataspace, std::vector<common::Rect>(1, clientFrame));
ramindanib1144212022-02-10 01:51:24 +0000676 clientLayer->setToClientComposition(mWriter);
677 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000678 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000679 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800680 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800681 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000682
ramindanidcecfd42022-02-03 23:52:19 +0000683 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000684 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800685 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000686 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
687 }
688}
689
690TEST_P(GraphicsCompositionTest, SetLayerDamage) {
691 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000692 EXPECT_TRUE(mComposerClient
693 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
694 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000695
ramindanidcecfd42022-02-03 23:52:19 +0000696 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
697 EXPECT_TRUE(readbackStatus.isOk());
698 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000699 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
700 return;
701 }
702
ramindanidcecfd42022-02-03 23:52:19 +0000703 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000704
ramindanidcecfd42022-02-03 23:52:19 +0000705 std::vector<Color> expectedColors(
706 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
707 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000708
ramindani0a2bee42022-02-10 01:27:42 +0000709 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
710 getPrimaryDisplayId(), getDisplayWidth(),
711 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000712 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000713 layer->setZOrder(10);
714 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
715 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
716
717 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
718
ramindanidcecfd42022-02-03 23:52:19 +0000719 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
720 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000721 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
722
723 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800724 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000725 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000726 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000727 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000728 GTEST_SUCCEED();
729 return;
730 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800731 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000732 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000733 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800734 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000735
736 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
737
738 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +0000739 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
740 getDisplayHeight() / 2};
741 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
742 getDisplayWidth());
743 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000744
745 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
746 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +0000747 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +0000748
749 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
750
751 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800752 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000753 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000754 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800755 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000756 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
757 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000758 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800759 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000760
761 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
762 }
763}
764
765TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
766 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000767 EXPECT_TRUE(mComposerClient
768 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
769 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000770
ramindanidcecfd42022-02-03 23:52:19 +0000771 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
772 EXPECT_TRUE(readbackStatus.isOk());
773 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000774 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
775 return;
776 }
777
ramindanidcecfd42022-02-03 23:52:19 +0000778 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000779 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +0000780 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000781 layer->setZOrder(10);
782 layer->setAlpha(0);
783 layer->setBlendMode(BlendMode::PREMULTIPLIED);
784
785 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
786
ramindanidcecfd42022-02-03 23:52:19 +0000787 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
788 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000789
790 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
791
792 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800793 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000794 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000795 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000796 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000797 GTEST_SUCCEED();
798 return;
799 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800800 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000801
ramindanidcecfd42022-02-03 23:52:19 +0000802 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000803 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800804 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000805
ramindanidcecfd42022-02-03 23:52:19 +0000806 std::vector<Color> expectedColors(
807 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000808
809 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
810 mTestRenderEngine->setRenderLayers(layers);
811 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
812 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
813 }
814}
815
816TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
817 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000818 EXPECT_TRUE(mComposerClient
819 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
820 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000821
ramindanidcecfd42022-02-03 23:52:19 +0000822 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
823 EXPECT_TRUE(readbackStatus.isOk());
824 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000825 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
826 return;
827 }
828
ramindanidcecfd42022-02-03 23:52:19 +0000829 std::vector<Color> expectedColors(
830 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
831 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
832 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
833 ReadbackHelper::fillColorsArea(
834 expectedColors, getDisplayWidth(),
835 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000836
ramindani0a2bee42022-02-10 01:27:42 +0000837 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
838 getPrimaryDisplayId(), getDisplayWidth(),
839 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000840 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000841 layer->setZOrder(10);
842 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000843 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
844 static_cast<float>(getDisplayWidth()),
845 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +0000846 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
847
848 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
849
850 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +0000851 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
852 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
853 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
854 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000855 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
856 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800857 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000858 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000859 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000860 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000861 GTEST_SUCCEED();
862 return;
863 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800864 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000865 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000866 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800867 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000868 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
869 mTestRenderEngine->setRenderLayers(layers);
870 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
871 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
872 }
873}
874
875TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
876 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000877 EXPECT_TRUE(mComposerClient
878 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
879 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000880
ramindanidcecfd42022-02-03 23:52:19 +0000881 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
882 EXPECT_TRUE(readbackStatus.isOk());
883 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000884 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
885 return;
886 }
887
ramindanidcecfd42022-02-03 23:52:19 +0000888 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
889 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
890 auto redLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000891 redLayer->setColor(RED);
892 redLayer->setDisplayFrame(redRect);
893
ramindanidcecfd42022-02-03 23:52:19 +0000894 auto blueLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000895 blueLayer->setColor(BLUE);
896 blueLayer->setDisplayFrame(blueRect);
897 blueLayer->setZOrder(5);
898
899 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000900 std::vector<Color> expectedColors(
901 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000902
903 // red in front of blue
904 redLayer->setZOrder(10);
905
906 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +0000907 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
908 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000909
ramindanidcecfd42022-02-03 23:52:19 +0000910 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
911 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000912 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
913
914 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800915 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000916 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000917 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000918 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000919 GTEST_SUCCEED();
920 return;
921 }
ramindanidcecfd42022-02-03 23:52:19 +0000922 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000923 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800924 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000925
926 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
927
928 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +0000929 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
930 getDisplayWidth());
931 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
932 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000933
934 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
935
936 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800937 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000938 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000939 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000940 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800941 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000942 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000943 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800944 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000945
946 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
947 mTestRenderEngine->setRenderLayers(layers);
948 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
949 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
950 }
951}
952
Alec Mourib1f16722022-02-07 13:03:44 -0800953TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
ramindanidcecfd42022-02-03 23:52:19 +0000954 const auto& [status, capabilities] =
955 mComposerClient->getDisplayCapabilities(getPrimaryDisplayId());
956 ASSERT_TRUE(status.isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800957
958 const bool brightnessSupport = std::find(capabilities.begin(), capabilities.end(),
959 DisplayCapability::BRIGHTNESS) != capabilities.end();
960
961 if (!brightnessSupport) {
962 GTEST_SUCCEED() << "Cannot verify dimming behavior without brightness support";
963 return;
964 }
965
966 const std::optional<float> maxBrightnessNitsOptional =
ramindanidcecfd42022-02-03 23:52:19 +0000967 getMaxDisplayBrightnessNits(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800968
969 ASSERT_TRUE(maxBrightnessNitsOptional.has_value());
970
971 const float maxBrightnessNits = *maxBrightnessNitsOptional;
972
973 // Preconditions to successfully run are knowing the max brightness and successfully applying
974 // the max brightness
975 ASSERT_GT(maxBrightnessNits, 0.f);
ramindanidcecfd42022-02-03 23:52:19 +0000976 mWriter.setDisplayBrightness(getPrimaryDisplayId(), /*brightness*/ 1.f);
Alec Mouri51067012022-01-06 17:28:39 -0800977 execute();
978 ASSERT_TRUE(mReader.takeErrors().empty());
979
980 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000981 EXPECT_TRUE(mComposerClient
982 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
983 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800984
ramindanidcecfd42022-02-03 23:52:19 +0000985 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
986 EXPECT_TRUE(readbackStatus.isOk());
987 if (!isSupported) {
Alec Mouri51067012022-01-06 17:28:39 -0800988 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
989 "color mode: "
990 << toString(mode);
991 continue;
992 }
ramindanidcecfd42022-02-03 23:52:19 +0000993 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
994 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
995 getDisplayHeight()};
996 const auto redLayer =
997 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800998 redLayer->setColor(RED);
999 redLayer->setDisplayFrame(redRect);
1000 redLayer->setWhitePointNits(maxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -08001001 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -08001002
1003 const auto dimmerRedLayer =
ramindanidcecfd42022-02-03 23:52:19 +00001004 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001005 dimmerRedLayer->setColor(RED);
1006 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
1007 // Intentionally use a small dimming ratio as some implementations may be more likely to
1008 // kick into GPU composition to apply dithering when the dimming ratio is high.
1009 static constexpr float kDimmingRatio = 0.9f;
1010 dimmerRedLayer->setWhitePointNits(maxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -08001011 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -08001012
1013 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +00001014 std::vector<Color> expectedColors(
1015 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -08001016
ramindanidcecfd42022-02-03 23:52:19 +00001017 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
1018 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -08001019
ramindanidcecfd42022-02-03 23:52:19 +00001020 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1021 getDisplayHeight(), mPixelFormat, mDataspace);
Alec Mouri51067012022-01-06 17:28:39 -08001022 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1023
1024 writeLayers(layers);
1025 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001026 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
Alec Mouri51067012022-01-06 17:28:39 -08001027 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001028 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -08001029 GTEST_SUCCEED()
1030 << "Readback verification not supported for GPU composition for color mode: "
1031 << toString(mode);
1032 continue;
1033 }
ramindanidcecfd42022-02-03 23:52:19 +00001034 mWriter.presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001035 execute();
1036 ASSERT_TRUE(mReader.takeErrors().empty());
1037
1038 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1039 mTestRenderEngine->setRenderLayers(layers);
1040 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1041 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1042 }
1043}
1044
ramindanibab8ba92021-11-18 01:24:11 +00001045class GraphicsBlendModeCompositionTest
1046 : public GraphicsCompositionTestBase,
1047 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
1048 public:
1049 void SetUp() override {
1050 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +00001051 // TODO(b/219590743) we should remove the below SRGB color mode
1052 // once we have the BlendMode test fix for all the versions of the ColorMode
1053 mTestColorModes = {ColorMode::SRGB};
ramindanibab8ba92021-11-18 01:24:11 +00001054 mBackgroundColor = BLACK;
1055 mTopLayerColor = RED;
1056 }
1057
1058 void setBackgroundColor(Color color) { mBackgroundColor = color; }
1059
1060 void setTopLayerColor(Color color) { mTopLayerColor = color; }
1061
1062 void setUpLayers(BlendMode blendMode) {
1063 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +00001064 std::vector<Color> topLayerPixelColors(
1065 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1066 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
1067 {0, 0, getDisplayWidth(), getDisplayHeight()},
1068 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +00001069
ramindanidcecfd42022-02-03 23:52:19 +00001070 auto backgroundLayer =
1071 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
1072 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001073 backgroundLayer->setZOrder(0);
1074 backgroundLayer->setColor(mBackgroundColor);
1075
ramindani0a2bee42022-02-10 01:27:42 +00001076 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1077 getPrimaryDisplayId(), getDisplayWidth(),
1078 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +00001079 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001080 layer->setZOrder(10);
1081 layer->setDataspace(Dataspace::UNKNOWN, mWriter);
1082 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
1083
1084 layer->setBlendMode(blendMode);
1085 layer->setAlpha(std::stof(std::get<1>(GetParam())));
1086
1087 mLayers.push_back(backgroundLayer);
1088 mLayers.push_back(layer);
1089 }
1090
1091 void setExpectedColors(std::vector<Color>& expectedColors) {
1092 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001093 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1094 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001095
1096 auto layer = mLayers[1];
1097 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001098 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001099 if (blendMode == BlendMode::NONE) {
1100 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001101 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1102 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1103 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1104 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001105 }
1106 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1107 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001108 expectedColor.r =
1109 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1110 expectedColor.g =
1111 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1112 expectedColor.b =
1113 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1114 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001115 }
1116 } else if (blendMode == BlendMode::COVERAGE) {
1117 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001118 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1119 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1120 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1121 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001122 }
1123 }
1124 }
1125
1126 protected:
1127 std::vector<std::shared_ptr<TestLayer>> mLayers;
1128 Color mBackgroundColor;
1129 Color mTopLayerColor;
1130};
ramindanib636af22022-02-10 02:55:56 +00001131// TODO(b/219576457) Enable tests once we have fixed the bug on composer.
1132TEST_P(GraphicsBlendModeCompositionTest, DISABLED_None) {
ramindanibab8ba92021-11-18 01:24:11 +00001133 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001134 EXPECT_TRUE(mComposerClient
1135 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1136 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001137
ramindanidcecfd42022-02-03 23:52:19 +00001138 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
1139 EXPECT_TRUE(readbackStatus.isOk());
1140 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001141 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1142 return;
1143 }
1144
ramindanidcecfd42022-02-03 23:52:19 +00001145 std::vector<Color> expectedColors(
1146 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001147
1148 setBackgroundColor(BLACK);
1149 setTopLayerColor(TRANSLUCENT_RED);
1150 setUpLayers(BlendMode::NONE);
1151 setExpectedColors(expectedColors);
1152
ramindanidcecfd42022-02-03 23:52:19 +00001153 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1154 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001155 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1156 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001157 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001158 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001159 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001160 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001161 GTEST_SUCCEED();
1162 return;
1163 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001164 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001165 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001166 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001167 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001168
1169 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1170 mTestRenderEngine->setRenderLayers(mLayers);
1171 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1172 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1173 }
1174}
1175
ramindani07e6f842022-02-15 15:28:33 +00001176TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001177 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001178 EXPECT_TRUE(mComposerClient
1179 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1180 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001181
ramindanidcecfd42022-02-03 23:52:19 +00001182 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
1183 EXPECT_TRUE(readbackStatus.isOk());
1184 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001185 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1186 return;
1187 }
1188
ramindanidcecfd42022-02-03 23:52:19 +00001189 std::vector<Color> expectedColors(
1190 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001191
1192 setBackgroundColor(BLACK);
1193 setTopLayerColor(TRANSLUCENT_RED);
1194
1195 setUpLayers(BlendMode::COVERAGE);
1196 setExpectedColors(expectedColors);
1197
ramindanidcecfd42022-02-03 23:52:19 +00001198 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1199 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001200 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1201 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001202 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001203 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001204 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001205 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001206 GTEST_SUCCEED();
1207 return;
1208 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001209 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001210 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001211 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001212 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001213 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1214 }
1215}
1216
1217TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1218 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001219 EXPECT_TRUE(mComposerClient
1220 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1221 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001222
ramindanidcecfd42022-02-03 23:52:19 +00001223 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
1224 EXPECT_TRUE(readbackStatus.isOk());
1225 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001226 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1227 return;
1228 }
ramindanibab8ba92021-11-18 01:24:11 +00001229
ramindanidcecfd42022-02-03 23:52:19 +00001230 std::vector<Color> expectedColors(
1231 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001232
1233 setBackgroundColor(BLACK);
1234 setTopLayerColor(TRANSLUCENT_RED);
1235 setUpLayers(BlendMode::PREMULTIPLIED);
1236 setExpectedColors(expectedColors);
1237
ramindanidcecfd42022-02-03 23:52:19 +00001238 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1239 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001240 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1241 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001242 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001243 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001244 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001245 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001246 GTEST_SUCCEED();
1247 return;
1248 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001249 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001250 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001251 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001252 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001253 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1254 mTestRenderEngine->setRenderLayers(mLayers);
1255 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1256 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1257 }
1258}
1259
1260class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1261 protected:
1262 void SetUp() override {
1263 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001264
ramindanidcecfd42022-02-03 23:52:19 +00001265 auto backgroundLayer =
1266 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001267 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001268 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001269 backgroundLayer->setZOrder(0);
1270
ramindanidcecfd42022-02-03 23:52:19 +00001271 mSideLength =
1272 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001273 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1274 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1275
ramindani0a2bee42022-02-10 01:27:42 +00001276 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1277 getPrimaryDisplayId(), mSideLength, mSideLength,
1278 PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +00001279 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1280 mLayer->setZOrder(10);
1281
1282 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1283 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1284 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1285 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1286 mLayers = {backgroundLayer, mLayer};
1287 }
1288
1289 protected:
1290 std::shared_ptr<TestBufferLayer> mLayer;
1291 std::vector<std::shared_ptr<TestLayer>> mLayers;
1292 int mSideLength;
1293};
1294
1295TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1296 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001297 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1298 RenderIntent::COLORIMETRIC);
1299 if (!status.isOk() &&
1300 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1301 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001302 SUCCEED() << "ColorMode not supported, skip test";
1303 return;
1304 }
1305
ramindanidcecfd42022-02-03 23:52:19 +00001306 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
1307 EXPECT_TRUE(readbackStatus.isOk());
1308 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001309 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1310 return;
1311 }
ramindanidcecfd42022-02-03 23:52:19 +00001312 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1313 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001314 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1315 mLayer->setTransform(Transform::FLIP_H);
1316 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1317
ramindanidcecfd42022-02-03 23:52:19 +00001318 std::vector<Color> expectedColors(
1319 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1320 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001321 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001322 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001323 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1324
1325 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001326 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001327 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001328 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001329 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001330 GTEST_SUCCEED();
1331 return;
1332 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001333 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001334 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001335 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001336 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001337
1338 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1339 mTestRenderEngine->setRenderLayers(mLayers);
1340 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1341 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1342 }
1343}
1344
1345TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1346 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001347 EXPECT_TRUE(mComposerClient
1348 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1349 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001350
ramindanidcecfd42022-02-03 23:52:19 +00001351 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
1352 EXPECT_TRUE(readbackStatus.isOk());
1353 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001354 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1355 return;
1356 }
ramindanidcecfd42022-02-03 23:52:19 +00001357 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1358 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001359 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1360
1361 mLayer->setTransform(Transform::FLIP_V);
1362 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1363
ramindanidcecfd42022-02-03 23:52:19 +00001364 std::vector<Color> expectedColors(
1365 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1366 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001367 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001368 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001369 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1370
1371 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001372 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001373 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001374 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001375 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001376 GTEST_SUCCEED();
1377 return;
1378 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001379 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001380 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001381 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001382 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001383 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1384 mTestRenderEngine->setRenderLayers(mLayers);
1385 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1386 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1387 }
1388}
1389
1390TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1391 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001392 EXPECT_TRUE(mComposerClient
1393 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1394 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001395
ramindanidcecfd42022-02-03 23:52:19 +00001396 const auto& [readbackStatus, isSupported] = getHasReadbackBuffer();
1397 EXPECT_TRUE(readbackStatus.isOk());
1398 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001399 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1400 return;
1401 }
ramindanidcecfd42022-02-03 23:52:19 +00001402 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1403 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001404 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1405
1406 mLayer->setTransform(Transform::ROT_180);
1407 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), mWriter);
1408
ramindanidcecfd42022-02-03 23:52:19 +00001409 std::vector<Color> expectedColors(
1410 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1411 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001412 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1413 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001414 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001415 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1416
1417 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001418 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001419 mWriter.validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001420 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001421 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001422 GTEST_SUCCEED();
1423 return;
1424 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001425 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +00001426 mWriter.presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001427 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001428 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001429 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1430 mTestRenderEngine->setRenderLayers(mLayers);
1431 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1432 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1433 }
1434}
1435
1436GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1437INSTANTIATE_TEST_SUITE_P(
1438 PerInstance, GraphicsCompositionTest,
1439 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1440 ::android::PrintInstanceNameToString);
1441
1442GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1443INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1444 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1445 IComposer::descriptor)),
1446 testing::Values("0.2", "1.0")));
1447
1448GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1449INSTANTIATE_TEST_SUITE_P(
1450 PerInstance, GraphicsTransformCompositionTest,
1451 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1452 ::android::PrintInstanceNameToString);
1453
1454} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001455} // namespace aidl::android::hardware::graphics::composer3::vts