blob: 164e6d5cabbbf1c4ee5d02e429b728c404645a8b [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
Alec Mourif6c039a2023-10-06 23:02:17 +000073 mClientCompositionDisplaySettings.physicalDisplay =
74 Rect(getDisplayWidth(), getDisplayHeight());
75 mClientCompositionDisplaySettings.clip = mClientCompositionDisplaySettings.physicalDisplay;
ramindanibab8ba92021-11-18 01:24:11 +000076
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)));
Alec Mourif6c039a2023-10-06 23:02:17 +000084 mTestRenderEngine->setDisplaySettings(mClientCompositionDisplaySettings);
ramindanibab8ba92021-11-18 01:24:11 +000085 }
86
87 void TearDown() override {
ramindanidcecfd42022-02-03 23:52:19 +000088 ASSERT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::OFF).isOk());
Ady Abrahama00d2462023-12-26 14:21:20 -080089 ASSERT_TRUE(mComposerClient->tearDown(mWriter.get()));
ramindanidcecfd42022-02-03 23:52:19 +000090 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;
Alec Mourif6c039a2023-10-06 23:02:17 +0000166 ::android::renderengine::DisplaySettings mClientCompositionDisplaySettings;
ramindanibab8ba92021-11-18 01:24:11 +0000167
168 static constexpr uint32_t kClientTargetSlotCount = 64;
169
170 private:
ramindanibab8ba92021-11-18 01:24:11 +0000171 void setTestColorModes() {
172 mTestColorModes.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000173 const auto& [status, modes] = mComposerClient->getColorModes(getPrimaryDisplayId());
174 ASSERT_TRUE(status.isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000175
176 for (ColorMode mode : modes) {
177 if (std::find(ReadbackHelper::colorModes.begin(), ReadbackHelper::colorModes.end(),
178 mode) != ReadbackHelper::colorModes.end()) {
179 mTestColorModes.push_back(mode);
180 }
181 }
182 }
183};
184
185class GraphicsCompositionTest : public GraphicsCompositionTestBase,
186 public testing::WithParamInterface<std::string> {
187 public:
188 void SetUp() override { SetUpBase(GetParam()); }
189};
190
191TEST_P(GraphicsCompositionTest, SingleSolidColorLayer) {
192 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000193 EXPECT_TRUE(mComposerClient
194 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
195 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000196
ramindani44c952f2022-02-28 23:29:29 +0000197 bool isSupported;
198 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000199 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000200 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
201 return;
202 }
203
Ady Abrahama00d2462023-12-26 14:21:20 -0800204 auto layer =
205 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000206 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000207 layer->setColor(BLUE);
208 layer->setDisplayFrame(coloredSquare);
209 layer->setZOrder(10);
210
211 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
212
213 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000214 std::vector<Color> expectedColors(
215 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
216 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000217
ramindanidcecfd42022-02-03 23:52:19 +0000218 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700219 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000220 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
221
222 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800223 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800224 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
225 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000226 execute();
227 // if hwc cannot handle and asks for composition change,
228 // just succeed the test
ramindanidcecfd42022-02-03 23:52:19 +0000229 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000230 GTEST_SUCCEED();
231 return;
232 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800233 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400234 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000235 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800236 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000237
238 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
239 mTestRenderEngine->setRenderLayers(layers);
240 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
241 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
242 }
243}
244
245TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
246 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000247 EXPECT_TRUE(mComposerClient
248 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
249 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000250
ramindani44c952f2022-02-28 23:29:29 +0000251 bool isSupported;
252 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000253 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000254 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
255 return;
256 }
257
ramindanidcecfd42022-02-03 23:52:19 +0000258 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700259 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000260 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000261 std::vector<Color> expectedColors(
262 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
263 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
264 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
265 ReadbackHelper::fillColorsArea(
266 expectedColors, getDisplayWidth(),
267 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
268 ReadbackHelper::fillColorsArea(
269 expectedColors, getDisplayWidth(),
270 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000271
272 auto layer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000273 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -0800274 getDisplayHeight(), common::PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000275 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000276 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000277 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000278 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
279
280 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
281
282 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800283 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800284 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
285 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000286 execute();
287
ramindanidcecfd42022-02-03 23:52:19 +0000288 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000289 GTEST_SUCCEED();
290 return;
291 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800292 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000293
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400294 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000295 execute();
296
Ady Abraham3192f3d2021-12-03 16:08:56 -0800297 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000298
299 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
300 mTestRenderEngine->setRenderLayers(layers);
301 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
302 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
303 }
304}
305
306TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
307 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000308 EXPECT_TRUE(mComposerClient
309 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
310 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000311
ramindani44c952f2022-02-28 23:29:29 +0000312 bool isSupported;
313 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000314 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000315 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
316 return;
317 }
318
Ady Abrahama00d2462023-12-26 14:21:20 -0800319 auto layer =
320 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000321 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000322 layer->setColor(BLUE);
323 layer->setDisplayFrame(coloredSquare);
324 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400325 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000326
327 // This following buffer call should have no effect
Brian Lindahle887a252023-01-17 14:54:19 -0700328 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
329 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
330 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
331 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000332 const auto& buffer = graphicBuffer->handle;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400333 mWriter->setLayerBuffer(getPrimaryDisplayId(), layer->getLayer(), /*slot*/ 0, buffer,
334 /*acquireFence*/ -1);
ramindanibab8ba92021-11-18 01:24:11 +0000335
336 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000337 std::vector<Color> expectedColors(
338 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
339 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000340
ramindanidcecfd42022-02-03 23:52:19 +0000341 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700342 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000343 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
344
ramindanicdcfcaf2023-11-09 10:00:10 -0800345 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
346 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000347 execute();
348
ramindanidcecfd42022-02-03 23:52:19 +0000349 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000350 GTEST_SUCCEED();
351 return;
352 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800353 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400354 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000355 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800356 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000357
358 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
359 }
360}
361
ramindanib27f33b2021-12-03 19:36:10 +0000362TEST_P(GraphicsCompositionTest, SetReadbackBuffer) {
ramindani44c952f2022-02-28 23:29:29 +0000363 bool isSupported;
364 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000365 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000366 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
367 return;
368 }
369
ramindanidcecfd42022-02-03 23:52:19 +0000370 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700371 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanib27f33b2021-12-03 19:36:10 +0000372
373 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
374}
375
ramindanidcecfd42022-02-03 23:52:19 +0000376TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadDisplay) {
ramindani44c952f2022-02-28 23:29:29 +0000377 bool isSupported;
378 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000379 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000380 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
381 return;
382 }
383
Brian Lindahle887a252023-01-17 14:54:19 -0700384 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
385 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
386 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
387 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000388 const auto& bufferHandle = graphicBuffer->handle;
ramindanib27f33b2021-12-03 19:36:10 +0000389 ::ndk::ScopedFileDescriptor fence = ::ndk::ScopedFileDescriptor(-1);
390
ramindanidcecfd42022-02-03 23:52:19 +0000391 const auto status =
392 mComposerClient->setReadbackBuffer(getInvalidDisplayId(), bufferHandle, fence);
ramindanib27f33b2021-12-03 19:36:10 +0000393
ramindanidcecfd42022-02-03 23:52:19 +0000394 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000395 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
ramindanib27f33b2021-12-03 19:36:10 +0000396}
397
ramindanidcecfd42022-02-03 23:52:19 +0000398TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadParameter) {
ramindani44c952f2022-02-28 23:29:29 +0000399 bool isSupported;
400 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000401 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000402 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
403 return;
404 }
405
ramindanidcecfd42022-02-03 23:52:19 +0000406 const native_handle_t bufferHandle{};
ramindanib27f33b2021-12-03 19:36:10 +0000407 ndk::ScopedFileDescriptor releaseFence = ndk::ScopedFileDescriptor(-1);
ramindanidcecfd42022-02-03 23:52:19 +0000408 const auto status =
409 mComposerClient->setReadbackBuffer(getPrimaryDisplayId(), &bufferHandle, releaseFence);
ramindanib27f33b2021-12-03 19:36:10 +0000410
ramindanidcecfd42022-02-03 23:52:19 +0000411 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000412 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
ramindanib27f33b2021-12-03 19:36:10 +0000413}
414
415TEST_P(GraphicsCompositionTest, GetReadbackBufferFenceInactive) {
ramindani44c952f2022-02-28 23:29:29 +0000416 bool isSupported;
417 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000418 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000419 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
420 return;
421 }
422
ramindanidcecfd42022-02-03 23:52:19 +0000423 const auto& [status, releaseFence] =
424 mComposerClient->getReadbackBufferFence(getPrimaryDisplayId());
ramindanib27f33b2021-12-03 19:36:10 +0000425
ramindanidcecfd42022-02-03 23:52:19 +0000426 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000427 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
Alec Mouri62ae37b2022-01-20 17:16:38 -0800428 EXPECT_EQ(-1, releaseFence.get());
ramindanib27f33b2021-12-03 19:36:10 +0000429}
430
ramindanibab8ba92021-11-18 01:24:11 +0000431TEST_P(GraphicsCompositionTest, ClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000432 EXPECT_TRUE(
433 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
434 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000435
436 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000437 EXPECT_TRUE(mComposerClient
438 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
ramindanibab8ba92021-11-18 01:24:11 +0000439 .isOk());
440
ramindani44c952f2022-02-28 23:29:29 +0000441 bool isSupported;
442 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000443 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000444 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
445 return;
446 }
447
ramindanidcecfd42022-02-03 23:52:19 +0000448 std::vector<Color> expectedColors(
449 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
450 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
451 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
452 ReadbackHelper::fillColorsArea(
453 expectedColors, getDisplayWidth(),
454 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
455 ReadbackHelper::fillColorsArea(
456 expectedColors, getDisplayWidth(),
457 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000458
Ady Abrahama00d2462023-12-26 14:21:20 -0800459 auto layer = std::make_shared<TestBufferLayer>(
460 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
461 getDisplayHeight(), PixelFormat::RGBA_FP16, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000462 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000463 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000464 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000465
466 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
467
ramindanidcecfd42022-02-03 23:52:19 +0000468 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700469 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000470 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
471 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800472 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800473 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
474 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000475 execute();
476
ramindanidcecfd42022-02-03 23:52:19 +0000477 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800478 if (!changedCompositionTypes.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800479 ASSERT_EQ(1, changedCompositionTypes.size());
Ady Abraham46219f52021-12-20 09:44:31 -0800480 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindanibab8ba92021-11-18 01:24:11 +0000481
482 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700483 auto clientUsage = static_cast<uint32_t>(
484 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN) |
485 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
486 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000487 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000488 common::Rect damage{0, 0, getDisplayWidth(), getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000489
490 // create client target buffer
Brian Lindahle887a252023-01-17 14:54:19 -0700491 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
492 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000493 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000494 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000495 const auto stride = static_cast<uint32_t>(graphicBuffer->stride);
496 graphicBuffer->lock(clientUsage, layer->getAccessRegion(), &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000497
498 ASSERT_NO_FATAL_FAILURE(
ramindani0a2bee42022-02-10 01:27:42 +0000499 ReadbackHelper::fillBuffer(layer->getWidth(), layer->getHeight(), stride,
ramindanibab8ba92021-11-18 01:24:11 +0000500 clientBufData, clientFormat, expectedColors));
ramindanib1144212022-02-10 01:51:24 +0000501 int32_t clientFence;
502 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
503 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400504 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
Alec Mouri8062f1f2023-09-06 02:14:47 +0000505 clientDataspace, std::vector<common::Rect>(1, damage), 1.f);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400506 layer->setToClientComposition(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800507 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
508 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000509 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000510 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800511 ASSERT_TRUE(changedCompositionTypes.empty());
ramindanibab8ba92021-11-18 01:24:11 +0000512 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800513 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000514
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400515 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000516 execute();
517
Ady Abraham3192f3d2021-12-03 16:08:56 -0800518 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000519
520 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
521 }
522}
523
524TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000525 ASSERT_TRUE(
526 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
527 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000528
529 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000530 EXPECT_TRUE(mComposerClient
531 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
532 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000533
ramindani44c952f2022-02-28 23:29:29 +0000534 bool isSupported;
535 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000536 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000537 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
538 return;
539 }
540
ramindanidcecfd42022-02-03 23:52:19 +0000541 std::vector<Color> expectedColors(
542 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
543 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
544 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
545 ReadbackHelper::fillColorsArea(
546 expectedColors, getDisplayWidth(),
547 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000548
ramindanidcecfd42022-02-03 23:52:19 +0000549 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700550 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000551 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
552
553 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000554 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -0800555 getDisplayHeight() / 2, PixelFormat::RGBA_8888, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000556 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
557 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
558 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
559 static_cast<int32_t>(deviceLayer->getHeight())},
560 GREEN);
561 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
562 static_cast<int32_t>(deviceLayer->getHeight())});
563 deviceLayer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000564 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000565 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400566 deviceLayer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000567
568 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700569 auto clientUsage = static_cast<uint32_t>(
570 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
571 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
572 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000573 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000574 int32_t clientWidth = getDisplayWidth();
575 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000576
577 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000578 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
Ady Abrahama00d2462023-12-26 14:21:20 -0800579 clientHeight, PixelFormat::RGBA_FP16, *mWriter, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000580 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
581 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000582 clientLayer->setDisplayFrame(clientFrame);
583 clientLayer->setZOrder(0);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400584 clientLayer->write(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800585 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
586 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000587 execute();
588
ramindanidcecfd42022-02-03 23:52:19 +0000589 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800590 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000591 continue;
592 }
593 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800594 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
Brian Lindahle887a252023-01-17 14:54:19 -0700595 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
596 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000597 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000598
599 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000600 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
601 &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000602
ramindanidcecfd42022-02-03 23:52:19 +0000603 std::vector<Color> clientColors(
604 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
605 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000606 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000607 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
ramindani0a2bee42022-02-10 01:27:42 +0000608 graphicBuffer->getStride(), clientBufData, clientFormat, clientColors));
ramindanib1144212022-02-10 01:51:24 +0000609 int32_t clientFence;
610 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
611 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400612 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
Alec Mouri8062f1f2023-09-06 02:14:47 +0000613 clientDataspace, std::vector<common::Rect>(1, clientFrame), 1.f);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400614 clientLayer->setToClientComposition(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800615 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
616 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000617 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000618 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800619 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800620 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000621
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400622 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000623 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800624 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000625 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
626 }
627}
628
629TEST_P(GraphicsCompositionTest, SetLayerDamage) {
630 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000631 EXPECT_TRUE(mComposerClient
632 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
633 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000634
ramindani44c952f2022-02-28 23:29:29 +0000635 bool isSupported;
636 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000637 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000638 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
639 return;
640 }
641
ramindanidcecfd42022-02-03 23:52:19 +0000642 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000643
ramindanidcecfd42022-02-03 23:52:19 +0000644 std::vector<Color> expectedColors(
645 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
646 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000647
Ady Abrahama00d2462023-12-26 14:21:20 -0800648 auto layer = std::make_shared<TestBufferLayer>(
649 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
650 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000651 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000652 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000653 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000654 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
655
656 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
657
ramindanidcecfd42022-02-03 23:52:19 +0000658 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700659 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000660 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
661
662 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800663 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800664 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
665 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000666 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000667 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000668 GTEST_SUCCEED();
669 return;
670 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800671 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400672 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000673 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800674 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000675
676 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
677
678 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +0000679 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
680 getDisplayHeight() / 2};
681 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
682 getDisplayWidth());
683 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000684
685 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
686 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +0000687 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +0000688
689 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
690
691 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800692 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800693 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
694 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000695 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800696 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000697 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400698 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000699 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800700 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000701
702 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
703 }
704}
705
706TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
707 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000708 EXPECT_TRUE(mComposerClient
709 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
710 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000711
ramindani44c952f2022-02-28 23:29:29 +0000712 bool isSupported;
713 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000714 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000715 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
716 return;
717 }
718
Ady Abrahama00d2462023-12-26 14:21:20 -0800719 auto layer =
720 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000721 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +0000722 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000723 layer->setZOrder(10);
724 layer->setAlpha(0);
725 layer->setBlendMode(BlendMode::PREMULTIPLIED);
726
727 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
728
ramindanidcecfd42022-02-03 23:52:19 +0000729 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700730 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000731
732 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
733
734 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800735 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800736 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
737 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000738 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000739 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000740 GTEST_SUCCEED();
741 return;
742 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800743 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000744
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400745 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000746 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800747 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000748
ramindanidcecfd42022-02-03 23:52:19 +0000749 std::vector<Color> expectedColors(
750 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000751
752 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
753 mTestRenderEngine->setRenderLayers(layers);
754 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
755 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
756 }
757}
758
759TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
760 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000761 EXPECT_TRUE(mComposerClient
762 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
763 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000764
ramindani44c952f2022-02-28 23:29:29 +0000765 bool isSupported;
766 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000767 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000768 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
769 return;
770 }
771
ramindanidcecfd42022-02-03 23:52:19 +0000772 std::vector<Color> expectedColors(
773 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
774 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
775 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
776 ReadbackHelper::fillColorsArea(
777 expectedColors, getDisplayWidth(),
778 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000779
Ady Abrahama00d2462023-12-26 14:21:20 -0800780 auto layer = std::make_shared<TestBufferLayer>(
781 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
782 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000783 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000784 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000785 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanidcecfd42022-02-03 23:52:19 +0000786 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
787 static_cast<float>(getDisplayWidth()),
788 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +0000789 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
790
791 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
792
793 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +0000794 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
795 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
796 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700797 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000798 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
799 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800800 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800801 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
802 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000803 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000804 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000805 GTEST_SUCCEED();
806 return;
807 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800808 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400809 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000810 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800811 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000812 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
813 mTestRenderEngine->setRenderLayers(layers);
814 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
815 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
816 }
817}
818
819TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
820 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000821 EXPECT_TRUE(mComposerClient
822 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
823 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000824
ramindani44c952f2022-02-28 23:29:29 +0000825 bool isSupported;
826 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000827 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000828 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
829 return;
830 }
831
ramindanidcecfd42022-02-03 23:52:19 +0000832 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
833 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
Ady Abrahama00d2462023-12-26 14:21:20 -0800834 auto redLayer =
835 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000836 redLayer->setColor(RED);
837 redLayer->setDisplayFrame(redRect);
838
Ady Abrahama00d2462023-12-26 14:21:20 -0800839 auto blueLayer =
840 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000841 blueLayer->setColor(BLUE);
842 blueLayer->setDisplayFrame(blueRect);
843 blueLayer->setZOrder(5);
844
845 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000846 std::vector<Color> expectedColors(
847 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000848
849 // red in front of blue
850 redLayer->setZOrder(10);
851
852 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +0000853 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
854 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000855
ramindanidcecfd42022-02-03 23:52:19 +0000856 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700857 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000858 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
859
860 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800861 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800862 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
863 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000864 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000865 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000866 GTEST_SUCCEED();
867 return;
868 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400869 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000870 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800871 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000872
873 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
874
875 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +0000876 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
877 getDisplayWidth());
878 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
879 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000880
881 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
882
883 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800884 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800885 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
886 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000887 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000888 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800889 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400890 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000891 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800892 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000893
894 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
895 mTestRenderEngine->setRenderLayers(layers);
896 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
897 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
898 }
899}
900
Alec Mourib1f16722022-02-07 13:03:44 -0800901TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
Alec Mouri51067012022-01-06 17:28:39 -0800902 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000903 EXPECT_TRUE(mComposerClient
904 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
905 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800906
ramindani44c952f2022-02-28 23:29:29 +0000907 bool isSupported;
908 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000909 if (!isSupported) {
Alec Mouri51067012022-01-06 17:28:39 -0800910 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
911 "color mode: "
912 << toString(mode);
913 continue;
914 }
ramindanidcecfd42022-02-03 23:52:19 +0000915 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
916 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
917 getDisplayHeight()};
Alec Mouri712b3d92023-09-29 00:21:37 +0000918
919 static constexpr float kMaxBrightnessNits = 300.f;
920
ramindanidcecfd42022-02-03 23:52:19 +0000921 const auto redLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -0800922 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Alec Mouri51067012022-01-06 17:28:39 -0800923 redLayer->setColor(RED);
924 redLayer->setDisplayFrame(redRect);
Alec Mouri712b3d92023-09-29 00:21:37 +0000925 redLayer->setWhitePointNits(kMaxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -0800926 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -0800927
928 const auto dimmerRedLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -0800929 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Alec Mouri51067012022-01-06 17:28:39 -0800930 dimmerRedLayer->setColor(RED);
931 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
932 // Intentionally use a small dimming ratio as some implementations may be more likely to
933 // kick into GPU composition to apply dithering when the dimming ratio is high.
934 static constexpr float kDimmingRatio = 0.9f;
Alec Mouri712b3d92023-09-29 00:21:37 +0000935 dimmerRedLayer->setWhitePointNits(kMaxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -0800936 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -0800937
938 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000939 std::vector<Color> expectedColors(
940 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -0800941
ramindanidcecfd42022-02-03 23:52:19 +0000942 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
943 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -0800944
ramindanidcecfd42022-02-03 23:52:19 +0000945 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700946 getDisplayHeight(), mPixelFormat, mDataspace);
Alec Mouri51067012022-01-06 17:28:39 -0800947 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
948
949 writeLayers(layers);
950 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800951 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
952 VtsComposerClient::kNoFrameIntervalNs);
Alec Mouri51067012022-01-06 17:28:39 -0800953 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000954 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -0800955 GTEST_SUCCEED()
956 << "Readback verification not supported for GPU composition for color mode: "
957 << toString(mode);
958 continue;
959 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400960 mWriter->presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800961 execute();
962 ASSERT_TRUE(mReader.takeErrors().empty());
963
964 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
965 mTestRenderEngine->setRenderLayers(layers);
966 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
967 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
968 }
969}
970
ramindanibab8ba92021-11-18 01:24:11 +0000971class GraphicsBlendModeCompositionTest
972 : public GraphicsCompositionTestBase,
973 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
974 public:
975 void SetUp() override {
976 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +0000977 // TODO(b/219590743) we should remove the below SRGB color mode
978 // once we have the BlendMode test fix for all the versions of the ColorMode
ramindania4e76362022-03-02 01:48:06 +0000979 mTestColorModes.erase(
980 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
981 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
982 mTestColorModes.end());
ramindanibab8ba92021-11-18 01:24:11 +0000983 mBackgroundColor = BLACK;
984 mTopLayerColor = RED;
985 }
986
987 void setBackgroundColor(Color color) { mBackgroundColor = color; }
988
989 void setTopLayerColor(Color color) { mTopLayerColor = color; }
990
991 void setUpLayers(BlendMode blendMode) {
992 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000993 std::vector<Color> topLayerPixelColors(
994 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
995 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
996 {0, 0, getDisplayWidth(), getDisplayHeight()},
997 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +0000998
ramindanidcecfd42022-02-03 23:52:19 +0000999 auto backgroundLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001000 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +00001001 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001002 backgroundLayer->setZOrder(0);
1003 backgroundLayer->setColor(mBackgroundColor);
1004
Ady Abrahama00d2462023-12-26 14:21:20 -08001005 auto layer = std::make_shared<TestBufferLayer>(
1006 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
1007 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +00001008 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001009 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +00001010 layer->setDataspace(Dataspace::UNKNOWN);
ramindanibab8ba92021-11-18 01:24:11 +00001011 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
1012
1013 layer->setBlendMode(blendMode);
1014 layer->setAlpha(std::stof(std::get<1>(GetParam())));
1015
1016 mLayers.push_back(backgroundLayer);
1017 mLayers.push_back(layer);
1018 }
1019
1020 void setExpectedColors(std::vector<Color>& expectedColors) {
1021 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001022 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1023 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001024
1025 auto layer = mLayers[1];
1026 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001027 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001028 if (blendMode == BlendMode::NONE) {
1029 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001030 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1031 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1032 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1033 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001034 }
1035 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1036 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001037 expectedColor.r =
1038 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1039 expectedColor.g =
1040 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1041 expectedColor.b =
1042 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1043 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001044 }
1045 } else if (blendMode == BlendMode::COVERAGE) {
1046 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001047 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1048 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1049 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1050 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001051 }
1052 }
1053 }
1054
1055 protected:
1056 std::vector<std::shared_ptr<TestLayer>> mLayers;
1057 Color mBackgroundColor;
1058 Color mTopLayerColor;
1059};
ramindanic7585d92022-04-15 18:30:41 +00001060
1061TEST_P(GraphicsBlendModeCompositionTest, None) {
ramindanibab8ba92021-11-18 01:24:11 +00001062 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001063 EXPECT_TRUE(mComposerClient
1064 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1065 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001066
ramindani44c952f2022-02-28 23:29:29 +00001067 bool isSupported;
1068 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001069 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001070 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1071 return;
1072 }
1073
ramindanidcecfd42022-02-03 23:52:19 +00001074 std::vector<Color> expectedColors(
1075 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001076
1077 setBackgroundColor(BLACK);
1078 setTopLayerColor(TRANSLUCENT_RED);
1079 setUpLayers(BlendMode::NONE);
1080 setExpectedColors(expectedColors);
1081
ramindanidcecfd42022-02-03 23:52:19 +00001082 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001083 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001084 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1085 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001086 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001087 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1088 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001089 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001090 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001091 GTEST_SUCCEED();
1092 return;
1093 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001094 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001095 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001096 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001097 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001098
1099 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1100 mTestRenderEngine->setRenderLayers(mLayers);
1101 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1102 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1103 }
1104}
1105
ramindani07e6f842022-02-15 15:28:33 +00001106TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001107 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001108 EXPECT_TRUE(mComposerClient
1109 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1110 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001111
ramindani44c952f2022-02-28 23:29:29 +00001112 bool isSupported;
1113 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001114 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001115 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1116 return;
1117 }
1118
ramindanidcecfd42022-02-03 23:52:19 +00001119 std::vector<Color> expectedColors(
1120 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001121
1122 setBackgroundColor(BLACK);
1123 setTopLayerColor(TRANSLUCENT_RED);
1124
1125 setUpLayers(BlendMode::COVERAGE);
1126 setExpectedColors(expectedColors);
1127
ramindanidcecfd42022-02-03 23:52:19 +00001128 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001129 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001130 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1131 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001132 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001133 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1134 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001135 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001136 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001137 GTEST_SUCCEED();
1138 return;
1139 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001140 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001141 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001142 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001143 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001144 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1145 }
1146}
1147
1148TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1149 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001150 EXPECT_TRUE(mComposerClient
1151 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1152 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001153
ramindani44c952f2022-02-28 23:29:29 +00001154 bool isSupported;
1155 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001156 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001157 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1158 return;
1159 }
ramindanibab8ba92021-11-18 01:24:11 +00001160
ramindanidcecfd42022-02-03 23:52:19 +00001161 std::vector<Color> expectedColors(
1162 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001163
1164 setBackgroundColor(BLACK);
1165 setTopLayerColor(TRANSLUCENT_RED);
1166 setUpLayers(BlendMode::PREMULTIPLIED);
1167 setExpectedColors(expectedColors);
1168
ramindanidcecfd42022-02-03 23:52:19 +00001169 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001170 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001171 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1172 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001173 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001174 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1175 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001176 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001177 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001178 GTEST_SUCCEED();
1179 return;
1180 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001181 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001182 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001183 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001184 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001185 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1186 mTestRenderEngine->setRenderLayers(mLayers);
1187 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1188 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1189 }
1190}
1191
1192class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1193 protected:
1194 void SetUp() override {
1195 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001196
ramindanidcecfd42022-02-03 23:52:19 +00001197 auto backgroundLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001198 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001199 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001200 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001201 backgroundLayer->setZOrder(0);
1202
ramindanidcecfd42022-02-03 23:52:19 +00001203 mSideLength =
1204 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001205 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1206 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1207
ramindani0a2bee42022-02-10 01:27:42 +00001208 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1209 getPrimaryDisplayId(), mSideLength, mSideLength,
Ady Abrahama00d2462023-12-26 14:21:20 -08001210 PixelFormat::RGBA_8888, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001211 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1212 mLayer->setZOrder(10);
1213
1214 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1215 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1216 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1217 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1218 mLayers = {backgroundLayer, mLayer};
1219 }
1220
1221 protected:
1222 std::shared_ptr<TestBufferLayer> mLayer;
1223 std::vector<std::shared_ptr<TestLayer>> mLayers;
1224 int mSideLength;
1225};
1226
1227TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1228 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001229 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1230 RenderIntent::COLORIMETRIC);
ramindanid5751092022-04-22 22:30:20 +00001231 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
ramindanidcecfd42022-02-03 23:52:19 +00001232 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1233 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001234 SUCCEED() << "ColorMode not supported, skip test";
1235 return;
1236 }
1237
ramindani44c952f2022-02-28 23:29:29 +00001238 bool isSupported;
1239 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001240 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001241 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1242 return;
1243 }
ramindanidcecfd42022-02-03 23:52:19 +00001244 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001245 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001246 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1247 mLayer->setTransform(Transform::FLIP_H);
Alec Mourif6c039a2023-10-06 23:02:17 +00001248 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001249
ramindanidcecfd42022-02-03 23:52:19 +00001250 std::vector<Color> expectedColors(
1251 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1252 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001253 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001254 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001255 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1256
1257 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001258 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001259 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1260 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001261 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001262 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001263 GTEST_SUCCEED();
1264 return;
1265 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001266 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001267 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001268 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001269 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001270
1271 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1272 mTestRenderEngine->setRenderLayers(mLayers);
1273 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1274 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1275 }
1276}
1277
1278TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1279 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001280 EXPECT_TRUE(mComposerClient
1281 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1282 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001283
ramindani44c952f2022-02-28 23:29:29 +00001284 bool isSupported;
1285 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001286 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001287 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1288 return;
1289 }
ramindanidcecfd42022-02-03 23:52:19 +00001290 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001291 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001292 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1293
1294 mLayer->setTransform(Transform::FLIP_V);
Alec Mourif6c039a2023-10-06 23:02:17 +00001295 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001296
ramindanidcecfd42022-02-03 23:52:19 +00001297 std::vector<Color> expectedColors(
1298 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1299 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001300 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001301 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001302 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1303
1304 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001305 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001306 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1307 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001308 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001309 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001310 GTEST_SUCCEED();
1311 return;
1312 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001313 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001314 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001315 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001316 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001317 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1318 mTestRenderEngine->setRenderLayers(mLayers);
1319 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1320 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1321 }
1322}
1323
1324TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1325 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001326 EXPECT_TRUE(mComposerClient
1327 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1328 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001329
ramindani44c952f2022-02-28 23:29:29 +00001330 bool isSupported;
1331 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001332 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001333 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1334 return;
1335 }
ramindanidcecfd42022-02-03 23:52:19 +00001336 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001337 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001338 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1339
1340 mLayer->setTransform(Transform::ROT_180);
Alec Mourif6c039a2023-10-06 23:02:17 +00001341 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001342
ramindanidcecfd42022-02-03 23:52:19 +00001343 std::vector<Color> expectedColors(
1344 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1345 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001346 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1347 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001348 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001349 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1350
1351 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001352 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001353 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1354 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001355 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001356 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001357 GTEST_SUCCEED();
1358 return;
1359 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001360 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001361 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001362 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001363 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001364 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1365 mTestRenderEngine->setRenderLayers(mLayers);
1366 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1367 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1368 }
1369}
1370
Alec Mourif6c039a2023-10-06 23:02:17 +00001371class GraphicsColorManagementCompositionTest
1372 : public GraphicsCompositionTestBase,
1373 public testing::WithParamInterface<std::tuple<std::string, Dataspace, Dataspace, Dataspace>> {
1374 public:
1375 void SetUp() override {
1376 SetUpBase(std::get<0>(GetParam()));
1377 // for some reason only sRGB reliably works
1378 mTestColorModes.erase(
1379 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
1380 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
1381 mTestColorModes.end());
1382 auto standard = std::get<1>(GetParam());
1383 auto transfer = std::get<2>(GetParam());
1384 auto range = std::get<3>(GetParam());
1385
1386 mLayerDataspace = static_cast<Dataspace>(static_cast<int32_t>(standard) |
1387 static_cast<int32_t>(transfer) |
1388 static_cast<int32_t>(range));
1389 ALOGD("Invoking test for dataspace: {%s, %s, %s}", toString(standard).c_str(),
1390 toString(transfer).c_str(), toString(range).c_str());
1391 }
1392
1393 void makeLayer() {
1394 mLayer = std::make_shared<TestBufferLayer>(
1395 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -08001396 getDisplayHeight(), common::PixelFormat::RGBA_8888, *mWriter);
Alec Mourif6c039a2023-10-06 23:02:17 +00001397 mLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
1398 mLayer->setZOrder(10);
1399 mLayer->setAlpha(1.f);
1400 mLayer->setDataspace(mLayerDataspace);
1401 }
1402
1403 void fillColor(Color color) {
1404 std::vector<Color> baseColors(static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1405 ReadbackHelper::fillColorsArea(baseColors, getDisplayWidth(),
1406 common::Rect{.left = 0,
1407 .top = 0,
1408 .right = getDisplayWidth(),
1409 .bottom = getDisplayHeight()},
1410 color);
1411 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1412 }
1413
1414 Dataspace mLayerDataspace;
1415 std::shared_ptr<TestBufferLayer> mLayer;
1416};
1417
1418TEST_P(GraphicsColorManagementCompositionTest, ColorConversion) {
1419 for (ColorMode mode : mTestColorModes) {
1420 EXPECT_TRUE(mComposerClient
1421 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1422 .isOk());
1423
1424 bool isSupported;
1425 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
1426 if (!isSupported) {
1427 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1428 return;
1429 }
1430
1431 mClientCompositionDisplaySettings.outputDataspace =
1432 static_cast<::android::ui::Dataspace>(mDataspace);
1433 mTestRenderEngine->setDisplaySettings(mClientCompositionDisplaySettings);
1434
1435 makeLayer();
1436 for (auto color : {LIGHT_RED, LIGHT_GREEN, LIGHT_BLUE}) {
1437 ALOGD("Testing color: %f, %f, %f, %f with color mode: %d", color.r, color.g, color.b,
1438 color.a, mode);
1439 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1440 getDisplayHeight(), mPixelFormat, mDataspace);
1441 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1442 fillColor(color);
1443 writeLayers({mLayer});
1444 EXPECT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::ON).isOk());
1445
1446 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001447 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1448 VtsComposerClient::kNoFrameIntervalNs);
Alec Mourif6c039a2023-10-06 23:02:17 +00001449 execute();
1450 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
1451 continue;
1452 }
1453 ASSERT_TRUE(mReader.takeErrors().empty());
1454 mWriter->presentDisplay(getPrimaryDisplayId());
1455 execute();
1456 ASSERT_TRUE(mReader.takeErrors().empty());
1457
1458 mTestRenderEngine->setRenderLayers({mLayer});
1459 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1460 ASSERT_NO_FATAL_FAILURE(
1461 mTestRenderEngine->checkColorBuffer(readbackBuffer.getBuffer()));
1462 }
1463 }
1464}
1465
ramindanibab8ba92021-11-18 01:24:11 +00001466GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1467INSTANTIATE_TEST_SUITE_P(
1468 PerInstance, GraphicsCompositionTest,
1469 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1470 ::android::PrintInstanceNameToString);
1471
1472GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1473INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1474 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1475 IComposer::descriptor)),
1476 testing::Values("0.2", "1.0")));
1477
1478GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1479INSTANTIATE_TEST_SUITE_P(
1480 PerInstance, GraphicsTransformCompositionTest,
1481 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1482 ::android::PrintInstanceNameToString);
1483
Alec Mourif6c039a2023-10-06 23:02:17 +00001484GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsColorManagementCompositionTest);
1485INSTANTIATE_TEST_SUITE_P(PerInstance, GraphicsColorManagementCompositionTest,
1486 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1487 IComposer::descriptor)),
1488 // Only check sRGB, but verify that extended range
1489 // doesn't trigger any gamma shifts
1490 testing::Values(Dataspace::STANDARD_BT709),
1491 testing::Values(Dataspace::TRANSFER_SRGB),
1492 // Don't test limited range until we send YUV overlays
1493 testing::Values(Dataspace::RANGE_FULL,
1494 Dataspace::RANGE_EXTENDED)));
1495
ramindanibab8ba92021-11-18 01:24:11 +00001496} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001497} // namespace aidl::android::hardware::graphics::composer3::vts