blob: 4b0f336d298d020d6fbdfdf24ebea7075cd6cf78 [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>
Brian Lindahle887a252023-01-17 14:54:19 -070021#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
ramindanibab8ba92021-11-18 01:24:11 +000034namespace aidl::android::hardware::graphics::composer3::vts {
35namespace {
36
37using ::android::Rect;
38using common::Dataspace;
39using common::PixelFormat;
40
41class GraphicsCompositionTestBase : public ::testing::Test {
42 protected:
43 void SetUpBase(const std::string& name) {
ramindanidcecfd42022-02-03 23:52:19 +000044 mComposerClient = std::make_shared<VtsComposerClient>(name);
45 ASSERT_TRUE(mComposerClient->createClient().isOk());
ramindanibab8ba92021-11-18 01:24:11 +000046
ramindanidcecfd42022-02-03 23:52:19 +000047 const auto& [status, displays] = mComposerClient->getDisplays();
48 ASSERT_TRUE(status.isOk());
49 mDisplays = displays;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -040050 mWriter.reset(new ComposerClientWriter(getPrimaryDisplayId()));
ramindanibab8ba92021-11-18 01:24:11 +000051
52 setTestColorModes();
53
54 // explicitly disable vsync
ramindanidcecfd42022-02-03 23:52:19 +000055 for (const auto& display : mDisplays) {
56 EXPECT_TRUE(mComposerClient->setVsync(display.getDisplayId(), /*enable*/ false).isOk());
57 }
58 mComposerClient->setVsyncAllowed(/*isAllowed*/ false);
ramindanibab8ba92021-11-18 01:24:11 +000059
ramindanidcecfd42022-02-03 23:52:19 +000060 EXPECT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::ON).isOk());
ramindanibab8ba92021-11-18 01:24:11 +000061
62 ASSERT_NO_FATAL_FAILURE(
63 mTestRenderEngine = std::unique_ptr<TestRenderEngine>(new TestRenderEngine(
64 ::android::renderengine::RenderEngineCreationArgs::Builder()
65 .setPixelFormat(static_cast<int>(common::PixelFormat::RGBA_8888))
66 .setImageCacheSize(TestRenderEngine::sMaxFrameBufferAcquireBuffers)
ramindanibab8ba92021-11-18 01:24:11 +000067 .setEnableProtectedContext(false)
68 .setPrecacheToneMapperShaderOnly(false)
69 .setContextPriority(::android::renderengine::RenderEngine::
70 ContextPriority::HIGH)
71 .build())));
72
73 ::android::renderengine::DisplaySettings clientCompositionDisplay;
ramindanidcecfd42022-02-03 23:52:19 +000074 clientCompositionDisplay.physicalDisplay = Rect(getDisplayWidth(), getDisplayHeight());
ramindanibab8ba92021-11-18 01:24:11 +000075 clientCompositionDisplay.clip = clientCompositionDisplay.physicalDisplay;
76
Brian Lindahle887a252023-01-17 14:54:19 -070077 mTestRenderEngine->initGraphicBuffer(
78 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
79 /*layerCount*/ 1U,
80 static_cast<uint64_t>(
81 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
82 static_cast<uint64_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
83 static_cast<uint64_t>(common::BufferUsage::GPU_RENDER_TARGET)));
ramindanibab8ba92021-11-18 01:24:11 +000084 mTestRenderEngine->setDisplaySettings(clientCompositionDisplay);
85 }
86
87 void TearDown() override {
ramindanidcecfd42022-02-03 23:52:19 +000088 ASSERT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::OFF).isOk());
89 ASSERT_TRUE(mComposerClient->tearDown());
90 mComposerClient.reset();
Ady Abraham3192f3d2021-12-03 16:08:56 -080091 const auto errors = mReader.takeErrors();
92 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +000093 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
ramindanibab8ba92021-11-18 01:24:11 +000094 }
95
ramindanidcecfd42022-02-03 23:52:19 +000096 const VtsDisplay& getPrimaryDisplay() const { return mDisplays[0]; }
97
98 int64_t getPrimaryDisplayId() const { return getPrimaryDisplay().getDisplayId(); }
99
100 int64_t getInvalidDisplayId() const { return mComposerClient->getInvalidDisplayId(); }
101
102 int32_t getDisplayWidth() const { return getPrimaryDisplay().getDisplayWidth(); }
103
104 int32_t getDisplayHeight() const { return getPrimaryDisplay().getDisplayHeight(); }
105
ramindanid5751092022-04-22 22:30:20 +0000106 void assertServiceSpecificError(const ScopedAStatus& status, int32_t serviceSpecificError) {
107 ASSERT_EQ(status.getExceptionCode(), EX_SERVICE_SPECIFIC);
108 ASSERT_EQ(status.getServiceSpecificError(), serviceSpecificError);
109 }
110
Brian Lindahle887a252023-01-17 14:54:19 -0700111 std::pair<bool, ::android::sp<::android::GraphicBuffer>> allocateBuffer(uint32_t usage) {
112 const auto width = static_cast<uint32_t>(getDisplayWidth());
113 const auto height = static_cast<uint32_t>(getDisplayHeight());
114
115 const auto& graphicBuffer = ::android::sp<::android::GraphicBuffer>::make(
116 width, height, ::android::PIXEL_FORMAT_RGBA_8888,
117 /*layerCount*/ 1u, usage, "VtsHalGraphicsComposer3_ReadbackTest");
ramindani0a2bee42022-02-10 01:27:42 +0000118
119 if (graphicBuffer && ::android::OK == graphicBuffer->initCheck()) {
Brian Lindahle887a252023-01-17 14:54:19 -0700120 return {true, graphicBuffer};
ramindani0a2bee42022-02-10 01:27:42 +0000121 }
Brian Lindahle887a252023-01-17 14:54:19 -0700122 return {false, graphicBuffer};
ramindanibab8ba92021-11-18 01:24:11 +0000123 }
124
ramindanibab8ba92021-11-18 01:24:11 +0000125 void writeLayers(const std::vector<std::shared_ptr<TestLayer>>& layers) {
ramindanidcecfd42022-02-03 23:52:19 +0000126 for (const auto& layer : layers) {
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400127 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000128 }
129 execute();
130 }
131
132 void execute() {
Huihong Luo651806f2023-04-21 18:48:48 +0000133 auto commands = mWriter->takePendingCommands();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800134 if (commands.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800135 return;
ramindanibab8ba92021-11-18 01:24:11 +0000136 }
137
ramindanidcecfd42022-02-03 23:52:19 +0000138 auto [status, results] = mComposerClient->executeCommands(commands);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800139 ASSERT_TRUE(status.isOk()) << "executeCommands failed " << status.getDescription();
ramindanibab8ba92021-11-18 01:24:11 +0000140
Ady Abraham46219f52021-12-20 09:44:31 -0800141 mReader.parse(std::move(results));
ramindanibab8ba92021-11-18 01:24:11 +0000142 }
143
ramindani44c952f2022-02-28 23:29:29 +0000144 bool getHasReadbackBuffer() {
ramindanidcecfd42022-02-03 23:52:19 +0000145 auto [status, readBackBufferAttributes] =
146 mComposerClient->getReadbackBufferAttributes(getPrimaryDisplayId());
147 if (status.isOk()) {
148 mPixelFormat = readBackBufferAttributes.format;
149 mDataspace = readBackBufferAttributes.dataspace;
ramindani44c952f2022-02-28 23:29:29 +0000150 return ReadbackHelper::readbackSupported(mPixelFormat, mDataspace);
ramindanidcecfd42022-02-03 23:52:19 +0000151 }
ramindanid5751092022-04-22 22:30:20 +0000152 EXPECT_NO_FATAL_FAILURE(
153 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
ramindani44c952f2022-02-28 23:29:29 +0000154 return false;
ramindanib27f33b2021-12-03 19:36:10 +0000155 }
156
ramindanidcecfd42022-02-03 23:52:19 +0000157 std::shared_ptr<VtsComposerClient> mComposerClient;
158 std::vector<VtsDisplay> mDisplays;
159 // use the slot count usually set by SF
ramindanibab8ba92021-11-18 01:24:11 +0000160 std::vector<ColorMode> mTestColorModes;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400161 std::unique_ptr<ComposerClientWriter> mWriter;
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800162 ComposerClientReader mReader;
ramindanibab8ba92021-11-18 01:24:11 +0000163 std::unique_ptr<TestRenderEngine> mTestRenderEngine;
ramindanibab8ba92021-11-18 01:24:11 +0000164 common::PixelFormat mPixelFormat;
165 common::Dataspace mDataspace;
166
167 static constexpr uint32_t kClientTargetSlotCount = 64;
168
169 private:
ramindanibab8ba92021-11-18 01:24:11 +0000170 void setTestColorModes() {
171 mTestColorModes.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000172 const auto& [status, modes] = mComposerClient->getColorModes(getPrimaryDisplayId());
173 ASSERT_TRUE(status.isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000174
175 for (ColorMode mode : modes) {
176 if (std::find(ReadbackHelper::colorModes.begin(), ReadbackHelper::colorModes.end(),
177 mode) != ReadbackHelper::colorModes.end()) {
178 mTestColorModes.push_back(mode);
179 }
180 }
181 }
182};
183
184class GraphicsCompositionTest : public GraphicsCompositionTestBase,
185 public testing::WithParamInterface<std::string> {
186 public:
187 void SetUp() override { SetUpBase(GetParam()); }
188};
189
190TEST_P(GraphicsCompositionTest, SingleSolidColorLayer) {
191 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000192 EXPECT_TRUE(mComposerClient
193 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
194 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000195
ramindani44c952f2022-02-28 23:29:29 +0000196 bool isSupported;
197 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000198 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000199 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
200 return;
201 }
202
ramindanidcecfd42022-02-03 23:52:19 +0000203 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
204 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000205 layer->setColor(BLUE);
206 layer->setDisplayFrame(coloredSquare);
207 layer->setZOrder(10);
208
209 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
210
211 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000212 std::vector<Color> expectedColors(
213 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
214 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000215
ramindanidcecfd42022-02-03 23:52:19 +0000216 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700217 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000218 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
219
220 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800221 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400222 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000223 execute();
224 // if hwc cannot handle and asks for composition change,
225 // just succeed the test
ramindanidcecfd42022-02-03 23:52:19 +0000226 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000227 GTEST_SUCCEED();
228 return;
229 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800230 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400231 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000232 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800233 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000234
235 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
236 mTestRenderEngine->setRenderLayers(layers);
237 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
238 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
239 }
240}
241
242TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
243 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000244 EXPECT_TRUE(mComposerClient
245 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
246 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000247
ramindani44c952f2022-02-28 23:29:29 +0000248 bool isSupported;
249 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000250 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000251 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
252 return;
253 }
254
ramindanidcecfd42022-02-03 23:52:19 +0000255 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700256 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000257 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000258 std::vector<Color> expectedColors(
259 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
260 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
261 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
262 ReadbackHelper::fillColorsArea(
263 expectedColors, getDisplayWidth(),
264 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
265 ReadbackHelper::fillColorsArea(
266 expectedColors, getDisplayWidth(),
267 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000268
269 auto layer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000270 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
271 getDisplayHeight(), common::PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000272 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000273 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400274 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000275 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
276
277 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
278
279 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800280 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400281 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000282 execute();
283
ramindanidcecfd42022-02-03 23:52:19 +0000284 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000285 GTEST_SUCCEED();
286 return;
287 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800288 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000289
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400290 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000291 execute();
292
Ady Abraham3192f3d2021-12-03 16:08:56 -0800293 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000294
295 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
296 mTestRenderEngine->setRenderLayers(layers);
297 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
298 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
299 }
300}
301
302TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
303 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000304 EXPECT_TRUE(mComposerClient
305 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
306 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000307
ramindani44c952f2022-02-28 23:29:29 +0000308 bool isSupported;
309 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000310 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000311 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
312 return;
313 }
314
ramindanidcecfd42022-02-03 23:52:19 +0000315 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
316 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000317 layer->setColor(BLUE);
318 layer->setDisplayFrame(coloredSquare);
319 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400320 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000321
322 // This following buffer call should have no effect
Brian Lindahle887a252023-01-17 14:54:19 -0700323 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
324 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
325 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
326 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000327 const auto& buffer = graphicBuffer->handle;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400328 mWriter->setLayerBuffer(getPrimaryDisplayId(), layer->getLayer(), /*slot*/ 0, buffer,
329 /*acquireFence*/ -1);
ramindanibab8ba92021-11-18 01:24:11 +0000330
331 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000332 std::vector<Color> expectedColors(
333 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
334 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000335
ramindanidcecfd42022-02-03 23:52:19 +0000336 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700337 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000338 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
339
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400340 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000341 execute();
342
ramindanidcecfd42022-02-03 23:52:19 +0000343 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000344 GTEST_SUCCEED();
345 return;
346 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800347 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400348 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000349 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800350 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000351
352 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
353 }
354}
355
ramindanib27f33b2021-12-03 19:36:10 +0000356TEST_P(GraphicsCompositionTest, SetReadbackBuffer) {
ramindani44c952f2022-02-28 23:29:29 +0000357 bool isSupported;
358 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000359 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000360 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
361 return;
362 }
363
ramindanidcecfd42022-02-03 23:52:19 +0000364 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700365 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanib27f33b2021-12-03 19:36:10 +0000366
367 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
368}
369
ramindanidcecfd42022-02-03 23:52:19 +0000370TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadDisplay) {
ramindani44c952f2022-02-28 23:29:29 +0000371 bool isSupported;
372 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000373 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000374 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
375 return;
376 }
377
Brian Lindahle887a252023-01-17 14:54:19 -0700378 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
379 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
380 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
381 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000382 const auto& bufferHandle = graphicBuffer->handle;
ramindanib27f33b2021-12-03 19:36:10 +0000383 ::ndk::ScopedFileDescriptor fence = ::ndk::ScopedFileDescriptor(-1);
384
ramindanidcecfd42022-02-03 23:52:19 +0000385 const auto status =
386 mComposerClient->setReadbackBuffer(getInvalidDisplayId(), bufferHandle, fence);
ramindanib27f33b2021-12-03 19:36:10 +0000387
ramindanidcecfd42022-02-03 23:52:19 +0000388 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000389 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
ramindanib27f33b2021-12-03 19:36:10 +0000390}
391
ramindanidcecfd42022-02-03 23:52:19 +0000392TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadParameter) {
ramindani44c952f2022-02-28 23:29:29 +0000393 bool isSupported;
394 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000395 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000396 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
397 return;
398 }
399
ramindanidcecfd42022-02-03 23:52:19 +0000400 const native_handle_t bufferHandle{};
ramindanib27f33b2021-12-03 19:36:10 +0000401 ndk::ScopedFileDescriptor releaseFence = ndk::ScopedFileDescriptor(-1);
ramindanidcecfd42022-02-03 23:52:19 +0000402 const auto status =
403 mComposerClient->setReadbackBuffer(getPrimaryDisplayId(), &bufferHandle, releaseFence);
ramindanib27f33b2021-12-03 19:36:10 +0000404
ramindanidcecfd42022-02-03 23:52:19 +0000405 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000406 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
ramindanib27f33b2021-12-03 19:36:10 +0000407}
408
409TEST_P(GraphicsCompositionTest, GetReadbackBufferFenceInactive) {
ramindani44c952f2022-02-28 23:29:29 +0000410 bool isSupported;
411 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000412 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000413 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
414 return;
415 }
416
ramindanidcecfd42022-02-03 23:52:19 +0000417 const auto& [status, releaseFence] =
418 mComposerClient->getReadbackBufferFence(getPrimaryDisplayId());
ramindanib27f33b2021-12-03 19:36:10 +0000419
ramindanidcecfd42022-02-03 23:52:19 +0000420 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000421 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
Alec Mouri62ae37b2022-01-20 17:16:38 -0800422 EXPECT_EQ(-1, releaseFence.get());
ramindanib27f33b2021-12-03 19:36:10 +0000423}
424
ramindanibab8ba92021-11-18 01:24:11 +0000425TEST_P(GraphicsCompositionTest, ClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000426 EXPECT_TRUE(
427 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
428 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000429
430 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000431 EXPECT_TRUE(mComposerClient
432 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
ramindanibab8ba92021-11-18 01:24:11 +0000433 .isOk());
434
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) {
ramindanibab8ba92021-11-18 01:24:11 +0000438 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
439 return;
440 }
441
ramindanidcecfd42022-02-03 23:52:19 +0000442 std::vector<Color> expectedColors(
443 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
444 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
445 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
446 ReadbackHelper::fillColorsArea(
447 expectedColors, getDisplayWidth(),
448 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
449 ReadbackHelper::fillColorsArea(
450 expectedColors, getDisplayWidth(),
451 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000452
ramindani0a2bee42022-02-10 01:27:42 +0000453 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
454 getPrimaryDisplayId(), getDisplayWidth(),
455 getDisplayHeight(), PixelFormat::RGBA_FP16);
ramindanidcecfd42022-02-03 23:52:19 +0000456 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000457 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400458 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000459
460 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
461
ramindanidcecfd42022-02-03 23:52:19 +0000462 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700463 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000464 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
465 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800466 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400467 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000468 execute();
469
ramindanidcecfd42022-02-03 23:52:19 +0000470 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800471 if (!changedCompositionTypes.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800472 ASSERT_EQ(1, changedCompositionTypes.size());
Ady Abraham46219f52021-12-20 09:44:31 -0800473 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindanibab8ba92021-11-18 01:24:11 +0000474
475 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700476 auto clientUsage = static_cast<uint32_t>(
477 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN) |
478 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
479 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000480 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000481 common::Rect damage{0, 0, getDisplayWidth(), getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000482
483 // create client target buffer
Brian Lindahle887a252023-01-17 14:54:19 -0700484 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
485 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000486 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000487 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000488 const auto stride = static_cast<uint32_t>(graphicBuffer->stride);
489 graphicBuffer->lock(clientUsage, layer->getAccessRegion(), &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000490
491 ASSERT_NO_FATAL_FAILURE(
ramindani0a2bee42022-02-10 01:27:42 +0000492 ReadbackHelper::fillBuffer(layer->getWidth(), layer->getHeight(), stride,
ramindanibab8ba92021-11-18 01:24:11 +0000493 clientBufData, clientFormat, expectedColors));
ramindanib1144212022-02-10 01:51:24 +0000494 int32_t clientFence;
495 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
496 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400497 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
498 clientDataspace, std::vector<common::Rect>(1, damage));
499 layer->setToClientComposition(*mWriter);
500 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000501 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000502 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800503 ASSERT_TRUE(changedCompositionTypes.empty());
ramindanibab8ba92021-11-18 01:24:11 +0000504 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800505 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000506
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400507 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000508 execute();
509
Ady Abraham3192f3d2021-12-03 16:08:56 -0800510 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000511
512 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
513 }
514}
515
516TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000517 ASSERT_TRUE(
518 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
519 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000520
521 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000522 EXPECT_TRUE(mComposerClient
523 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
524 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000525
ramindani44c952f2022-02-28 23:29:29 +0000526 bool isSupported;
527 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000528 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000529 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
530 return;
531 }
532
ramindanidcecfd42022-02-03 23:52:19 +0000533 std::vector<Color> expectedColors(
534 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
535 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
536 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
537 ReadbackHelper::fillColorsArea(
538 expectedColors, getDisplayWidth(),
539 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000540
ramindanidcecfd42022-02-03 23:52:19 +0000541 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700542 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000543 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
544
545 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000546 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
547 getDisplayHeight() / 2, PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +0000548 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
549 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
550 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
551 static_cast<int32_t>(deviceLayer->getHeight())},
552 GREEN);
553 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
554 static_cast<int32_t>(deviceLayer->getHeight())});
555 deviceLayer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400556 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000557 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400558 deviceLayer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000559
560 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700561 auto clientUsage = static_cast<uint32_t>(
562 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
563 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
564 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000565 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000566 int32_t clientWidth = getDisplayWidth();
567 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000568
569 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000570 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
571 clientHeight, PixelFormat::RGBA_FP16, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000572 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
573 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000574 clientLayer->setDisplayFrame(clientFrame);
575 clientLayer->setZOrder(0);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400576 clientLayer->write(*mWriter);
577 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000578 execute();
579
ramindanidcecfd42022-02-03 23:52:19 +0000580 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800581 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000582 continue;
583 }
584 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800585 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
Brian Lindahle887a252023-01-17 14:54:19 -0700586 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
587 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000588 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000589
590 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000591 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
592 &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000593
ramindanidcecfd42022-02-03 23:52:19 +0000594 std::vector<Color> clientColors(
595 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
596 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000597 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000598 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
ramindani0a2bee42022-02-10 01:27:42 +0000599 graphicBuffer->getStride(), clientBufData, clientFormat, clientColors));
ramindanib1144212022-02-10 01:51:24 +0000600 int32_t clientFence;
601 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
602 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400603 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
604 clientDataspace, std::vector<common::Rect>(1, clientFrame));
605 clientLayer->setToClientComposition(*mWriter);
606 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000607 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000608 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800609 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800610 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000611
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400612 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000613 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800614 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000615 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
616 }
617}
618
619TEST_P(GraphicsCompositionTest, SetLayerDamage) {
620 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000621 EXPECT_TRUE(mComposerClient
622 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
623 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000624
ramindani44c952f2022-02-28 23:29:29 +0000625 bool isSupported;
626 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000627 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000628 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
629 return;
630 }
631
ramindanidcecfd42022-02-03 23:52:19 +0000632 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000633
ramindanidcecfd42022-02-03 23:52:19 +0000634 std::vector<Color> expectedColors(
635 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
636 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000637
ramindani0a2bee42022-02-10 01:27:42 +0000638 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
639 getPrimaryDisplayId(), getDisplayWidth(),
640 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000641 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000642 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400643 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000644 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
645
646 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
647
ramindanidcecfd42022-02-03 23:52:19 +0000648 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700649 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000650 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
651
652 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800653 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400654 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000655 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000656 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000657 GTEST_SUCCEED();
658 return;
659 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800660 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400661 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000662 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800663 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000664
665 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
666
667 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +0000668 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
669 getDisplayHeight() / 2};
670 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
671 getDisplayWidth());
672 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000673
674 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
675 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +0000676 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +0000677
678 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
679
680 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800681 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400682 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000683 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800684 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000685 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400686 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000687 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800688 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000689
690 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
691 }
692}
693
694TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
695 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000696 EXPECT_TRUE(mComposerClient
697 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
698 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000699
ramindani44c952f2022-02-28 23:29:29 +0000700 bool isSupported;
701 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000702 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000703 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
704 return;
705 }
706
ramindanidcecfd42022-02-03 23:52:19 +0000707 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000708 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +0000709 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000710 layer->setZOrder(10);
711 layer->setAlpha(0);
712 layer->setBlendMode(BlendMode::PREMULTIPLIED);
713
714 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
715
ramindanidcecfd42022-02-03 23:52:19 +0000716 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700717 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000718
719 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
720
721 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800722 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400723 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000724 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000725 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000726 GTEST_SUCCEED();
727 return;
728 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800729 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000730
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400731 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000732 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800733 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000734
ramindanidcecfd42022-02-03 23:52:19 +0000735 std::vector<Color> expectedColors(
736 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000737
738 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
739 mTestRenderEngine->setRenderLayers(layers);
740 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
741 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
742 }
743}
744
745TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
746 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000747 EXPECT_TRUE(mComposerClient
748 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
749 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000750
ramindani44c952f2022-02-28 23:29:29 +0000751 bool isSupported;
752 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000753 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000754 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
755 return;
756 }
757
ramindanidcecfd42022-02-03 23:52:19 +0000758 std::vector<Color> expectedColors(
759 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
760 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
761 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
762 ReadbackHelper::fillColorsArea(
763 expectedColors, getDisplayWidth(),
764 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000765
ramindani0a2bee42022-02-10 01:27:42 +0000766 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
767 getPrimaryDisplayId(), getDisplayWidth(),
768 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000769 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000770 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400771 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000772 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
773 static_cast<float>(getDisplayWidth()),
774 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +0000775 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
776
777 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
778
779 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +0000780 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
781 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
782 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700783 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000784 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
785 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800786 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400787 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000788 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000789 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000790 GTEST_SUCCEED();
791 return;
792 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800793 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400794 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000795 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800796 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000797 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
798 mTestRenderEngine->setRenderLayers(layers);
799 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
800 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
801 }
802}
803
804TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
805 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000806 EXPECT_TRUE(mComposerClient
807 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
808 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000809
ramindani44c952f2022-02-28 23:29:29 +0000810 bool isSupported;
811 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000812 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000813 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
814 return;
815 }
816
ramindanidcecfd42022-02-03 23:52:19 +0000817 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
818 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
819 auto redLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000820 redLayer->setColor(RED);
821 redLayer->setDisplayFrame(redRect);
822
ramindanidcecfd42022-02-03 23:52:19 +0000823 auto blueLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000824 blueLayer->setColor(BLUE);
825 blueLayer->setDisplayFrame(blueRect);
826 blueLayer->setZOrder(5);
827
828 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000829 std::vector<Color> expectedColors(
830 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000831
832 // red in front of blue
833 redLayer->setZOrder(10);
834
835 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +0000836 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
837 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000838
ramindanidcecfd42022-02-03 23:52:19 +0000839 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700840 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000841 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
842
843 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800844 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400845 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000846 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000847 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000848 GTEST_SUCCEED();
849 return;
850 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400851 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000852 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800853 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000854
855 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
856
857 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +0000858 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
859 getDisplayWidth());
860 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
861 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000862
863 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
864
865 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800866 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400867 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +0000868 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000869 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800870 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400871 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000872 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800873 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000874
875 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
Alec Mourib1f16722022-02-07 13:03:44 -0800882TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
Alec Mouri51067012022-01-06 17:28:39 -0800883 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000884 EXPECT_TRUE(mComposerClient
885 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
886 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800887
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) {
Alec Mouri51067012022-01-06 17:28:39 -0800891 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
892 "color mode: "
893 << toString(mode);
894 continue;
895 }
ramindanidcecfd42022-02-03 23:52:19 +0000896 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
897 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
898 getDisplayHeight()};
Alec Mouri712b3d92023-09-29 00:21:37 +0000899
900 static constexpr float kMaxBrightnessNits = 300.f;
901
ramindanidcecfd42022-02-03 23:52:19 +0000902 const auto redLayer =
903 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800904 redLayer->setColor(RED);
905 redLayer->setDisplayFrame(redRect);
Alec Mouri712b3d92023-09-29 00:21:37 +0000906 redLayer->setWhitePointNits(kMaxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -0800907 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -0800908
909 const auto dimmerRedLayer =
ramindanidcecfd42022-02-03 23:52:19 +0000910 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800911 dimmerRedLayer->setColor(RED);
912 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
913 // Intentionally use a small dimming ratio as some implementations may be more likely to
914 // kick into GPU composition to apply dithering when the dimming ratio is high.
915 static constexpr float kDimmingRatio = 0.9f;
Alec Mouri712b3d92023-09-29 00:21:37 +0000916 dimmerRedLayer->setWhitePointNits(kMaxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -0800917 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -0800918
919 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000920 std::vector<Color> expectedColors(
921 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -0800922
ramindanidcecfd42022-02-03 23:52:19 +0000923 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
924 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -0800925
ramindanidcecfd42022-02-03 23:52:19 +0000926 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700927 getDisplayHeight(), mPixelFormat, mDataspace);
Alec Mouri51067012022-01-06 17:28:39 -0800928 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
929
930 writeLayers(layers);
931 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400932 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
Alec Mouri51067012022-01-06 17:28:39 -0800933 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000934 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -0800935 GTEST_SUCCEED()
936 << "Readback verification not supported for GPU composition for color mode: "
937 << toString(mode);
938 continue;
939 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400940 mWriter->presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800941 execute();
942 ASSERT_TRUE(mReader.takeErrors().empty());
943
944 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
945 mTestRenderEngine->setRenderLayers(layers);
946 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
947 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
948 }
949}
950
ramindanibab8ba92021-11-18 01:24:11 +0000951class GraphicsBlendModeCompositionTest
952 : public GraphicsCompositionTestBase,
953 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
954 public:
955 void SetUp() override {
956 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +0000957 // TODO(b/219590743) we should remove the below SRGB color mode
958 // once we have the BlendMode test fix for all the versions of the ColorMode
ramindania4e76362022-03-02 01:48:06 +0000959 mTestColorModes.erase(
960 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
961 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
962 mTestColorModes.end());
ramindanibab8ba92021-11-18 01:24:11 +0000963 mBackgroundColor = BLACK;
964 mTopLayerColor = RED;
965 }
966
967 void setBackgroundColor(Color color) { mBackgroundColor = color; }
968
969 void setTopLayerColor(Color color) { mTopLayerColor = color; }
970
971 void setUpLayers(BlendMode blendMode) {
972 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000973 std::vector<Color> topLayerPixelColors(
974 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
975 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
976 {0, 0, getDisplayWidth(), getDisplayHeight()},
977 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +0000978
ramindanidcecfd42022-02-03 23:52:19 +0000979 auto backgroundLayer =
980 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
981 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000982 backgroundLayer->setZOrder(0);
983 backgroundLayer->setColor(mBackgroundColor);
984
ramindani0a2bee42022-02-10 01:27:42 +0000985 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
986 getPrimaryDisplayId(), getDisplayWidth(),
987 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000988 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000989 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400990 layer->setDataspace(Dataspace::UNKNOWN, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000991 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
992
993 layer->setBlendMode(blendMode);
994 layer->setAlpha(std::stof(std::get<1>(GetParam())));
995
996 mLayers.push_back(backgroundLayer);
997 mLayers.push_back(layer);
998 }
999
1000 void setExpectedColors(std::vector<Color>& expectedColors) {
1001 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001002 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1003 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001004
1005 auto layer = mLayers[1];
1006 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001007 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001008 if (blendMode == BlendMode::NONE) {
1009 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001010 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1011 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1012 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1013 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001014 }
1015 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1016 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001017 expectedColor.r =
1018 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1019 expectedColor.g =
1020 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1021 expectedColor.b =
1022 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1023 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001024 }
1025 } else if (blendMode == BlendMode::COVERAGE) {
1026 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001027 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1028 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1029 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1030 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001031 }
1032 }
1033 }
1034
1035 protected:
1036 std::vector<std::shared_ptr<TestLayer>> mLayers;
1037 Color mBackgroundColor;
1038 Color mTopLayerColor;
1039};
ramindanic7585d92022-04-15 18:30:41 +00001040
1041TEST_P(GraphicsBlendModeCompositionTest, None) {
ramindanibab8ba92021-11-18 01:24:11 +00001042 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001043 EXPECT_TRUE(mComposerClient
1044 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1045 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001046
ramindani44c952f2022-02-28 23:29:29 +00001047 bool isSupported;
1048 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001049 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001050 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1051 return;
1052 }
1053
ramindanidcecfd42022-02-03 23:52:19 +00001054 std::vector<Color> expectedColors(
1055 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001056
1057 setBackgroundColor(BLACK);
1058 setTopLayerColor(TRANSLUCENT_RED);
1059 setUpLayers(BlendMode::NONE);
1060 setExpectedColors(expectedColors);
1061
ramindanidcecfd42022-02-03 23:52:19 +00001062 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001063 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001064 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1065 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001066 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001067 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001068 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001069 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001070 GTEST_SUCCEED();
1071 return;
1072 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001073 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001074 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001075 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001076 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001077
1078 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1079 mTestRenderEngine->setRenderLayers(mLayers);
1080 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1081 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1082 }
1083}
1084
ramindani07e6f842022-02-15 15:28:33 +00001085TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001086 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001087 EXPECT_TRUE(mComposerClient
1088 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1089 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001090
ramindani44c952f2022-02-28 23:29:29 +00001091 bool isSupported;
1092 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001093 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001094 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1095 return;
1096 }
1097
ramindanidcecfd42022-02-03 23:52:19 +00001098 std::vector<Color> expectedColors(
1099 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001100
1101 setBackgroundColor(BLACK);
1102 setTopLayerColor(TRANSLUCENT_RED);
1103
1104 setUpLayers(BlendMode::COVERAGE);
1105 setExpectedColors(expectedColors);
1106
ramindanidcecfd42022-02-03 23:52:19 +00001107 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001108 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001109 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1110 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001111 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001112 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001113 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001114 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001115 GTEST_SUCCEED();
1116 return;
1117 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001118 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001119 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001120 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001121 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001122 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1123 }
1124}
1125
1126TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1127 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001128 EXPECT_TRUE(mComposerClient
1129 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1130 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001131
ramindani44c952f2022-02-28 23:29:29 +00001132 bool isSupported;
1133 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001134 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001135 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1136 return;
1137 }
ramindanibab8ba92021-11-18 01:24:11 +00001138
ramindanidcecfd42022-02-03 23:52:19 +00001139 std::vector<Color> expectedColors(
1140 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001141
1142 setBackgroundColor(BLACK);
1143 setTopLayerColor(TRANSLUCENT_RED);
1144 setUpLayers(BlendMode::PREMULTIPLIED);
1145 setExpectedColors(expectedColors);
1146
ramindanidcecfd42022-02-03 23:52:19 +00001147 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001148 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001149 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1150 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001151 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001152 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001153 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001154 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001155 GTEST_SUCCEED();
1156 return;
1157 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001158 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001159 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001160 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001161 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001162 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1163 mTestRenderEngine->setRenderLayers(mLayers);
1164 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1165 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1166 }
1167}
1168
1169class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1170 protected:
1171 void SetUp() override {
1172 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001173
ramindanidcecfd42022-02-03 23:52:19 +00001174 auto backgroundLayer =
1175 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001176 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001177 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001178 backgroundLayer->setZOrder(0);
1179
ramindanidcecfd42022-02-03 23:52:19 +00001180 mSideLength =
1181 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001182 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1183 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1184
ramindani0a2bee42022-02-10 01:27:42 +00001185 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1186 getPrimaryDisplayId(), mSideLength, mSideLength,
1187 PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +00001188 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1189 mLayer->setZOrder(10);
1190
1191 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1192 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1193 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1194 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1195 mLayers = {backgroundLayer, mLayer};
1196 }
1197
1198 protected:
1199 std::shared_ptr<TestBufferLayer> mLayer;
1200 std::vector<std::shared_ptr<TestLayer>> mLayers;
1201 int mSideLength;
1202};
1203
1204TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1205 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001206 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1207 RenderIntent::COLORIMETRIC);
ramindanid5751092022-04-22 22:30:20 +00001208 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
ramindanidcecfd42022-02-03 23:52:19 +00001209 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1210 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001211 SUCCEED() << "ColorMode not supported, skip test";
1212 return;
1213 }
1214
ramindani44c952f2022-02-28 23:29:29 +00001215 bool isSupported;
1216 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001217 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001218 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1219 return;
1220 }
ramindanidcecfd42022-02-03 23:52:19 +00001221 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001222 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001223 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1224 mLayer->setTransform(Transform::FLIP_H);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001225 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001226
ramindanidcecfd42022-02-03 23:52:19 +00001227 std::vector<Color> expectedColors(
1228 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1229 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001230 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001231 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001232 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1233
1234 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001235 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001236 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001237 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001238 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001239 GTEST_SUCCEED();
1240 return;
1241 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001242 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001243 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001244 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001245 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001246
1247 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1248 mTestRenderEngine->setRenderLayers(mLayers);
1249 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1250 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1251 }
1252}
1253
1254TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1255 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001256 EXPECT_TRUE(mComposerClient
1257 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1258 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001259
ramindani44c952f2022-02-28 23:29:29 +00001260 bool isSupported;
1261 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001262 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001263 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1264 return;
1265 }
ramindanidcecfd42022-02-03 23:52:19 +00001266 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001267 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001268 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1269
1270 mLayer->setTransform(Transform::FLIP_V);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001271 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001272
ramindanidcecfd42022-02-03 23:52:19 +00001273 std::vector<Color> expectedColors(
1274 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1275 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001276 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001277 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001278 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1279
1280 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001281 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001282 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001283 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001284 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001285 GTEST_SUCCEED();
1286 return;
1287 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001288 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001289 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001290 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001291 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001292 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1293 mTestRenderEngine->setRenderLayers(mLayers);
1294 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1295 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1296 }
1297}
1298
1299TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1300 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001301 EXPECT_TRUE(mComposerClient
1302 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1303 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001304
ramindani44c952f2022-02-28 23:29:29 +00001305 bool isSupported;
1306 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001307 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001308 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1309 return;
1310 }
ramindanidcecfd42022-02-03 23:52:19 +00001311 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001312 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001313 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1314
1315 mLayer->setTransform(Transform::ROT_180);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001316 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001317
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, mSideLength / 2, mSideLength, mSideLength},
1322 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001323 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001324 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1325
1326 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001327 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001328 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp);
ramindanibab8ba92021-11-18 01:24:11 +00001329 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001330 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001331 GTEST_SUCCEED();
1332 return;
1333 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001334 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001335 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001336 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001337 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001338 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
1345GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1346INSTANTIATE_TEST_SUITE_P(
1347 PerInstance, GraphicsCompositionTest,
1348 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1349 ::android::PrintInstanceNameToString);
1350
1351GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1352INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1353 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1354 IComposer::descriptor)),
1355 testing::Values("0.2", "1.0")));
1356
1357GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1358INSTANTIATE_TEST_SUITE_P(
1359 PerInstance, GraphicsTransformCompositionTest,
1360 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1361 ::android::PrintInstanceNameToString);
1362
1363} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001364} // namespace aidl::android::hardware::graphics::composer3::vts