blob: 58eca6ed543c4bd8c755014dbb13b3ecda7076ee [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());
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;
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
ramindanidcecfd42022-02-03 23:52:19 +0000204 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
205 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000206 layer->setColor(BLUE);
207 layer->setDisplayFrame(coloredSquare);
208 layer->setZOrder(10);
209
210 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
211
212 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000213 std::vector<Color> expectedColors(
214 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
215 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000216
ramindanidcecfd42022-02-03 23:52:19 +0000217 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700218 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000219 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
220
221 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800222 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800223 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
224 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000225 execute();
226 // if hwc cannot handle and asks for composition change,
227 // just succeed the test
ramindanidcecfd42022-02-03 23:52:19 +0000228 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000229 GTEST_SUCCEED();
230 return;
231 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800232 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400233 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000234 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800235 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000236
237 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
238 mTestRenderEngine->setRenderLayers(layers);
239 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
240 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
241 }
242}
243
244TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
245 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000246 EXPECT_TRUE(mComposerClient
247 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
248 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000249
ramindani44c952f2022-02-28 23:29:29 +0000250 bool isSupported;
251 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000252 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000253 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
254 return;
255 }
256
ramindanidcecfd42022-02-03 23:52:19 +0000257 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700258 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000259 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000260 std::vector<Color> expectedColors(
261 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
262 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
263 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
264 ReadbackHelper::fillColorsArea(
265 expectedColors, getDisplayWidth(),
266 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
267 ReadbackHelper::fillColorsArea(
268 expectedColors, getDisplayWidth(),
269 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000270
271 auto layer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000272 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
273 getDisplayHeight(), common::PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000274 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000275 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000276 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000277 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
278
279 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
280
281 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800282 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800283 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
284 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000285 execute();
286
ramindanidcecfd42022-02-03 23:52:19 +0000287 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000288 GTEST_SUCCEED();
289 return;
290 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800291 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000292
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400293 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000294 execute();
295
Ady Abraham3192f3d2021-12-03 16:08:56 -0800296 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000297
298 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
299 mTestRenderEngine->setRenderLayers(layers);
300 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
301 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
302 }
303}
304
305TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
306 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000307 EXPECT_TRUE(mComposerClient
308 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
309 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000310
ramindani44c952f2022-02-28 23:29:29 +0000311 bool isSupported;
312 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000313 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000314 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
315 return;
316 }
317
ramindanidcecfd42022-02-03 23:52:19 +0000318 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
319 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000320 layer->setColor(BLUE);
321 layer->setDisplayFrame(coloredSquare);
322 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400323 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000324
325 // This following buffer call should have no effect
Brian Lindahle887a252023-01-17 14:54:19 -0700326 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
327 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
328 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
329 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000330 const auto& buffer = graphicBuffer->handle;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400331 mWriter->setLayerBuffer(getPrimaryDisplayId(), layer->getLayer(), /*slot*/ 0, buffer,
332 /*acquireFence*/ -1);
ramindanibab8ba92021-11-18 01:24:11 +0000333
334 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000335 std::vector<Color> expectedColors(
336 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
337 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000338
ramindanidcecfd42022-02-03 23:52:19 +0000339 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700340 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000341 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
342
ramindanicdcfcaf2023-11-09 10:00:10 -0800343 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
344 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000345 execute();
346
ramindanidcecfd42022-02-03 23:52:19 +0000347 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000348 GTEST_SUCCEED();
349 return;
350 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800351 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400352 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000353 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800354 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000355
356 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
357 }
358}
359
ramindanib27f33b2021-12-03 19:36:10 +0000360TEST_P(GraphicsCompositionTest, SetReadbackBuffer) {
ramindani44c952f2022-02-28 23:29:29 +0000361 bool isSupported;
362 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000363 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000364 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
365 return;
366 }
367
ramindanidcecfd42022-02-03 23:52:19 +0000368 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700369 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanib27f33b2021-12-03 19:36:10 +0000370
371 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
372}
373
ramindanidcecfd42022-02-03 23:52:19 +0000374TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadDisplay) {
ramindani44c952f2022-02-28 23:29:29 +0000375 bool isSupported;
376 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000377 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000378 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
379 return;
380 }
381
Brian Lindahle887a252023-01-17 14:54:19 -0700382 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
383 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
384 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
385 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000386 const auto& bufferHandle = graphicBuffer->handle;
ramindanib27f33b2021-12-03 19:36:10 +0000387 ::ndk::ScopedFileDescriptor fence = ::ndk::ScopedFileDescriptor(-1);
388
ramindanidcecfd42022-02-03 23:52:19 +0000389 const auto status =
390 mComposerClient->setReadbackBuffer(getInvalidDisplayId(), bufferHandle, fence);
ramindanib27f33b2021-12-03 19:36:10 +0000391
ramindanidcecfd42022-02-03 23:52:19 +0000392 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000393 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
ramindanib27f33b2021-12-03 19:36:10 +0000394}
395
ramindanidcecfd42022-02-03 23:52:19 +0000396TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadParameter) {
ramindani44c952f2022-02-28 23:29:29 +0000397 bool isSupported;
398 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000399 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000400 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
401 return;
402 }
403
ramindanidcecfd42022-02-03 23:52:19 +0000404 const native_handle_t bufferHandle{};
ramindanib27f33b2021-12-03 19:36:10 +0000405 ndk::ScopedFileDescriptor releaseFence = ndk::ScopedFileDescriptor(-1);
ramindanidcecfd42022-02-03 23:52:19 +0000406 const auto status =
407 mComposerClient->setReadbackBuffer(getPrimaryDisplayId(), &bufferHandle, releaseFence);
ramindanib27f33b2021-12-03 19:36:10 +0000408
ramindanidcecfd42022-02-03 23:52:19 +0000409 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000410 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
ramindanib27f33b2021-12-03 19:36:10 +0000411}
412
413TEST_P(GraphicsCompositionTest, GetReadbackBufferFenceInactive) {
ramindani44c952f2022-02-28 23:29:29 +0000414 bool isSupported;
415 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000416 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000417 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
418 return;
419 }
420
ramindanidcecfd42022-02-03 23:52:19 +0000421 const auto& [status, releaseFence] =
422 mComposerClient->getReadbackBufferFence(getPrimaryDisplayId());
ramindanib27f33b2021-12-03 19:36:10 +0000423
ramindanidcecfd42022-02-03 23:52:19 +0000424 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000425 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
Alec Mouri62ae37b2022-01-20 17:16:38 -0800426 EXPECT_EQ(-1, releaseFence.get());
ramindanib27f33b2021-12-03 19:36:10 +0000427}
428
ramindanibab8ba92021-11-18 01:24:11 +0000429TEST_P(GraphicsCompositionTest, ClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000430 EXPECT_TRUE(
431 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
432 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000433
434 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000435 EXPECT_TRUE(mComposerClient
436 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
ramindanibab8ba92021-11-18 01:24:11 +0000437 .isOk());
438
ramindani44c952f2022-02-28 23:29:29 +0000439 bool isSupported;
440 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000441 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000442 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
443 return;
444 }
445
ramindanidcecfd42022-02-03 23:52:19 +0000446 std::vector<Color> expectedColors(
447 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
448 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
449 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
450 ReadbackHelper::fillColorsArea(
451 expectedColors, getDisplayWidth(),
452 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
453 ReadbackHelper::fillColorsArea(
454 expectedColors, getDisplayWidth(),
455 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000456
ramindani0a2bee42022-02-10 01:27:42 +0000457 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
458 getPrimaryDisplayId(), getDisplayWidth(),
459 getDisplayHeight(), PixelFormat::RGBA_FP16);
ramindanidcecfd42022-02-03 23:52:19 +0000460 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000461 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000462 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000463
464 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
465
ramindanidcecfd42022-02-03 23:52:19 +0000466 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700467 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000468 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
469 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800470 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800471 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
472 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000473 execute();
474
ramindanidcecfd42022-02-03 23:52:19 +0000475 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800476 if (!changedCompositionTypes.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800477 ASSERT_EQ(1, changedCompositionTypes.size());
Ady Abraham46219f52021-12-20 09:44:31 -0800478 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindanibab8ba92021-11-18 01:24:11 +0000479
480 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700481 auto clientUsage = static_cast<uint32_t>(
482 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN) |
483 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
484 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000485 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000486 common::Rect damage{0, 0, getDisplayWidth(), getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000487
488 // create client target buffer
Brian Lindahle887a252023-01-17 14:54:19 -0700489 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
490 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000491 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000492 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000493 const auto stride = static_cast<uint32_t>(graphicBuffer->stride);
494 graphicBuffer->lock(clientUsage, layer->getAccessRegion(), &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000495
496 ASSERT_NO_FATAL_FAILURE(
ramindani0a2bee42022-02-10 01:27:42 +0000497 ReadbackHelper::fillBuffer(layer->getWidth(), layer->getHeight(), stride,
ramindanibab8ba92021-11-18 01:24:11 +0000498 clientBufData, clientFormat, expectedColors));
ramindanib1144212022-02-10 01:51:24 +0000499 int32_t clientFence;
500 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
501 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400502 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
503 clientDataspace, std::vector<common::Rect>(1, damage));
504 layer->setToClientComposition(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800505 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
506 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000507 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000508 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800509 ASSERT_TRUE(changedCompositionTypes.empty());
ramindanibab8ba92021-11-18 01:24:11 +0000510 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800511 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000512
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400513 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000514 execute();
515
Ady Abraham3192f3d2021-12-03 16:08:56 -0800516 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000517
518 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
519 }
520}
521
522TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000523 ASSERT_TRUE(
524 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
525 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000526
527 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000528 EXPECT_TRUE(mComposerClient
529 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
530 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000531
ramindani44c952f2022-02-28 23:29:29 +0000532 bool isSupported;
533 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000534 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000535 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
536 return;
537 }
538
ramindanidcecfd42022-02-03 23:52:19 +0000539 std::vector<Color> expectedColors(
540 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
541 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
542 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
543 ReadbackHelper::fillColorsArea(
544 expectedColors, getDisplayWidth(),
545 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000546
ramindanidcecfd42022-02-03 23:52:19 +0000547 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700548 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000549 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
550
551 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000552 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
553 getDisplayHeight() / 2, PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +0000554 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
555 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
556 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
557 static_cast<int32_t>(deviceLayer->getHeight())},
558 GREEN);
559 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
560 static_cast<int32_t>(deviceLayer->getHeight())});
561 deviceLayer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000562 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000563 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400564 deviceLayer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000565
566 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700567 auto clientUsage = static_cast<uint32_t>(
568 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
569 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
570 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000571 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000572 int32_t clientWidth = getDisplayWidth();
573 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000574
575 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000576 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
577 clientHeight, PixelFormat::RGBA_FP16, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000578 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
579 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000580 clientLayer->setDisplayFrame(clientFrame);
581 clientLayer->setZOrder(0);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400582 clientLayer->write(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800583 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
584 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000585 execute();
586
ramindanidcecfd42022-02-03 23:52:19 +0000587 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800588 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000589 continue;
590 }
591 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800592 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
Brian Lindahle887a252023-01-17 14:54:19 -0700593 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
594 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000595 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000596
597 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000598 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
599 &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000600
ramindanidcecfd42022-02-03 23:52:19 +0000601 std::vector<Color> clientColors(
602 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
603 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000604 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000605 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
ramindani0a2bee42022-02-10 01:27:42 +0000606 graphicBuffer->getStride(), clientBufData, clientFormat, clientColors));
ramindanib1144212022-02-10 01:51:24 +0000607 int32_t clientFence;
608 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
609 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400610 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
611 clientDataspace, std::vector<common::Rect>(1, clientFrame));
612 clientLayer->setToClientComposition(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800613 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
614 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000615 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000616 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800617 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800618 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000619
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400620 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000621 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800622 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000623 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
624 }
625}
626
627TEST_P(GraphicsCompositionTest, SetLayerDamage) {
628 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000629 EXPECT_TRUE(mComposerClient
630 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
631 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000632
ramindani44c952f2022-02-28 23:29:29 +0000633 bool isSupported;
634 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000635 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000636 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
637 return;
638 }
639
ramindanidcecfd42022-02-03 23:52:19 +0000640 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000641
ramindanidcecfd42022-02-03 23:52:19 +0000642 std::vector<Color> expectedColors(
643 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
644 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000645
ramindani0a2bee42022-02-10 01:27:42 +0000646 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
647 getPrimaryDisplayId(), getDisplayWidth(),
648 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000649 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000650 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000651 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000652 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
653
654 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
655
ramindanidcecfd42022-02-03 23:52:19 +0000656 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700657 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000658 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
659
660 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800661 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800662 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
663 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000664 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000665 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000666 GTEST_SUCCEED();
667 return;
668 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800669 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400670 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000671 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800672 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000673
674 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
675
676 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +0000677 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
678 getDisplayHeight() / 2};
679 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
680 getDisplayWidth());
681 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000682
683 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
684 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +0000685 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +0000686
687 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
688
689 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800690 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800691 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
692 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000693 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800694 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000695 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400696 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000697 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800698 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000699
700 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
701 }
702}
703
704TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
705 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000706 EXPECT_TRUE(mComposerClient
707 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
708 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000709
ramindani44c952f2022-02-28 23:29:29 +0000710 bool isSupported;
711 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000712 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000713 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
714 return;
715 }
716
ramindanidcecfd42022-02-03 23:52:19 +0000717 auto layer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000718 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +0000719 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000720 layer->setZOrder(10);
721 layer->setAlpha(0);
722 layer->setBlendMode(BlendMode::PREMULTIPLIED);
723
724 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
725
ramindanidcecfd42022-02-03 23:52:19 +0000726 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700727 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000728
729 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
730
731 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800732 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800733 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
734 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000735 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000736 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000737 GTEST_SUCCEED();
738 return;
739 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800740 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000741
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400742 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000743 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800744 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000745
ramindanidcecfd42022-02-03 23:52:19 +0000746 std::vector<Color> expectedColors(
747 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000748
749 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
750 mTestRenderEngine->setRenderLayers(layers);
751 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
752 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
753 }
754}
755
756TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
757 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000758 EXPECT_TRUE(mComposerClient
759 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
760 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000761
ramindani44c952f2022-02-28 23:29:29 +0000762 bool isSupported;
763 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000764 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000765 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
766 return;
767 }
768
ramindanidcecfd42022-02-03 23:52:19 +0000769 std::vector<Color> expectedColors(
770 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
771 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
772 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
773 ReadbackHelper::fillColorsArea(
774 expectedColors, getDisplayWidth(),
775 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000776
ramindani0a2bee42022-02-10 01:27:42 +0000777 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
778 getPrimaryDisplayId(), getDisplayWidth(),
779 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +0000780 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000781 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000782 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanidcecfd42022-02-03 23:52:19 +0000783 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
784 static_cast<float>(getDisplayWidth()),
785 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +0000786 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
787
788 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
789
790 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +0000791 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
792 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
793 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700794 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000795 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
796 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800797 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800798 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
799 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000800 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000801 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000802 GTEST_SUCCEED();
803 return;
804 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800805 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400806 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000807 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800808 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000809 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
810 mTestRenderEngine->setRenderLayers(layers);
811 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
812 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
813 }
814}
815
816TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
817 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000818 EXPECT_TRUE(mComposerClient
819 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
820 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000821
ramindani44c952f2022-02-28 23:29:29 +0000822 bool isSupported;
823 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000824 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000825 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
826 return;
827 }
828
ramindanidcecfd42022-02-03 23:52:19 +0000829 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
830 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
831 auto redLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000832 redLayer->setColor(RED);
833 redLayer->setDisplayFrame(redRect);
834
ramindanidcecfd42022-02-03 23:52:19 +0000835 auto blueLayer = std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000836 blueLayer->setColor(BLUE);
837 blueLayer->setDisplayFrame(blueRect);
838 blueLayer->setZOrder(5);
839
840 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000841 std::vector<Color> expectedColors(
842 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000843
844 // red in front of blue
845 redLayer->setZOrder(10);
846
847 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +0000848 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
849 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000850
ramindanidcecfd42022-02-03 23:52:19 +0000851 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700852 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000853 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
854
855 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800856 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800857 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
858 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000859 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000860 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000861 GTEST_SUCCEED();
862 return;
863 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400864 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000865 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800866 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000867
868 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
869
870 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +0000871 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
872 getDisplayWidth());
873 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
874 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000875
876 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
877
878 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800879 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800880 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
881 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000882 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000883 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800884 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400885 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000886 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800887 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000888
889 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
890 mTestRenderEngine->setRenderLayers(layers);
891 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
892 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
893 }
894}
895
Alec Mourib1f16722022-02-07 13:03:44 -0800896TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
Alec Mouri51067012022-01-06 17:28:39 -0800897 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000898 EXPECT_TRUE(mComposerClient
899 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
900 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800901
ramindani44c952f2022-02-28 23:29:29 +0000902 bool isSupported;
903 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000904 if (!isSupported) {
Alec Mouri51067012022-01-06 17:28:39 -0800905 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
906 "color mode: "
907 << toString(mode);
908 continue;
909 }
ramindanidcecfd42022-02-03 23:52:19 +0000910 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
911 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
912 getDisplayHeight()};
Alec Mouri712b3d92023-09-29 00:21:37 +0000913
914 static constexpr float kMaxBrightnessNits = 300.f;
915
ramindanidcecfd42022-02-03 23:52:19 +0000916 const auto redLayer =
917 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800918 redLayer->setColor(RED);
919 redLayer->setDisplayFrame(redRect);
Alec Mouri712b3d92023-09-29 00:21:37 +0000920 redLayer->setWhitePointNits(kMaxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -0800921 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -0800922
923 const auto dimmerRedLayer =
ramindanidcecfd42022-02-03 23:52:19 +0000924 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800925 dimmerRedLayer->setColor(RED);
926 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
927 // Intentionally use a small dimming ratio as some implementations may be more likely to
928 // kick into GPU composition to apply dithering when the dimming ratio is high.
929 static constexpr float kDimmingRatio = 0.9f;
Alec Mouri712b3d92023-09-29 00:21:37 +0000930 dimmerRedLayer->setWhitePointNits(kMaxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -0800931 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -0800932
933 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000934 std::vector<Color> expectedColors(
935 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -0800936
ramindanidcecfd42022-02-03 23:52:19 +0000937 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
938 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -0800939
ramindanidcecfd42022-02-03 23:52:19 +0000940 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700941 getDisplayHeight(), mPixelFormat, mDataspace);
Alec Mouri51067012022-01-06 17:28:39 -0800942 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
943
944 writeLayers(layers);
945 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800946 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
947 VtsComposerClient::kNoFrameIntervalNs);
Alec Mouri51067012022-01-06 17:28:39 -0800948 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000949 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -0800950 GTEST_SUCCEED()
951 << "Readback verification not supported for GPU composition for color mode: "
952 << toString(mode);
953 continue;
954 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400955 mWriter->presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800956 execute();
957 ASSERT_TRUE(mReader.takeErrors().empty());
958
959 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
960 mTestRenderEngine->setRenderLayers(layers);
961 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
962 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
963 }
964}
965
ramindanibab8ba92021-11-18 01:24:11 +0000966class GraphicsBlendModeCompositionTest
967 : public GraphicsCompositionTestBase,
968 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
969 public:
970 void SetUp() override {
971 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +0000972 // TODO(b/219590743) we should remove the below SRGB color mode
973 // once we have the BlendMode test fix for all the versions of the ColorMode
ramindania4e76362022-03-02 01:48:06 +0000974 mTestColorModes.erase(
975 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
976 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
977 mTestColorModes.end());
ramindanibab8ba92021-11-18 01:24:11 +0000978 mBackgroundColor = BLACK;
979 mTopLayerColor = RED;
980 }
981
982 void setBackgroundColor(Color color) { mBackgroundColor = color; }
983
984 void setTopLayerColor(Color color) { mTopLayerColor = color; }
985
986 void setUpLayers(BlendMode blendMode) {
987 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000988 std::vector<Color> topLayerPixelColors(
989 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
990 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
991 {0, 0, getDisplayWidth(), getDisplayHeight()},
992 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +0000993
ramindanidcecfd42022-02-03 23:52:19 +0000994 auto backgroundLayer =
995 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
996 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000997 backgroundLayer->setZOrder(0);
998 backgroundLayer->setColor(mBackgroundColor);
999
ramindani0a2bee42022-02-10 01:27:42 +00001000 auto layer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1001 getPrimaryDisplayId(), getDisplayWidth(),
1002 getDisplayHeight(), PixelFormat::RGBA_8888);
ramindanidcecfd42022-02-03 23:52:19 +00001003 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001004 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +00001005 layer->setDataspace(Dataspace::UNKNOWN);
ramindanibab8ba92021-11-18 01:24:11 +00001006 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
1007
1008 layer->setBlendMode(blendMode);
1009 layer->setAlpha(std::stof(std::get<1>(GetParam())));
1010
1011 mLayers.push_back(backgroundLayer);
1012 mLayers.push_back(layer);
1013 }
1014
1015 void setExpectedColors(std::vector<Color>& expectedColors) {
1016 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001017 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1018 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001019
1020 auto layer = mLayers[1];
1021 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001022 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001023 if (blendMode == BlendMode::NONE) {
1024 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001025 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1026 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1027 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1028 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001029 }
1030 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1031 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001032 expectedColor.r =
1033 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1034 expectedColor.g =
1035 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1036 expectedColor.b =
1037 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1038 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001039 }
1040 } else if (blendMode == BlendMode::COVERAGE) {
1041 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001042 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1043 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1044 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1045 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001046 }
1047 }
1048 }
1049
1050 protected:
1051 std::vector<std::shared_ptr<TestLayer>> mLayers;
1052 Color mBackgroundColor;
1053 Color mTopLayerColor;
1054};
ramindanic7585d92022-04-15 18:30:41 +00001055
1056TEST_P(GraphicsBlendModeCompositionTest, None) {
ramindanibab8ba92021-11-18 01:24:11 +00001057 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001058 EXPECT_TRUE(mComposerClient
1059 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1060 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001061
ramindani44c952f2022-02-28 23:29:29 +00001062 bool isSupported;
1063 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001064 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001065 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1066 return;
1067 }
1068
ramindanidcecfd42022-02-03 23:52:19 +00001069 std::vector<Color> expectedColors(
1070 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001071
1072 setBackgroundColor(BLACK);
1073 setTopLayerColor(TRANSLUCENT_RED);
1074 setUpLayers(BlendMode::NONE);
1075 setExpectedColors(expectedColors);
1076
ramindanidcecfd42022-02-03 23:52:19 +00001077 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001078 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001079 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1080 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001081 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001082 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1083 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001084 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001085 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001086 GTEST_SUCCEED();
1087 return;
1088 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001089 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001090 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001091 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001092 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001093
1094 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1095 mTestRenderEngine->setRenderLayers(mLayers);
1096 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1097 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1098 }
1099}
1100
ramindani07e6f842022-02-15 15:28:33 +00001101TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001102 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001103 EXPECT_TRUE(mComposerClient
1104 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1105 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001106
ramindani44c952f2022-02-28 23:29:29 +00001107 bool isSupported;
1108 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001109 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001110 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1111 return;
1112 }
1113
ramindanidcecfd42022-02-03 23:52:19 +00001114 std::vector<Color> expectedColors(
1115 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001116
1117 setBackgroundColor(BLACK);
1118 setTopLayerColor(TRANSLUCENT_RED);
1119
1120 setUpLayers(BlendMode::COVERAGE);
1121 setExpectedColors(expectedColors);
1122
ramindanidcecfd42022-02-03 23:52:19 +00001123 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001124 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001125 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1126 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001127 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001128 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1129 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001130 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001131 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001132 GTEST_SUCCEED();
1133 return;
1134 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001135 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001136 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001137 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001138 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001139 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1140 }
1141}
1142
1143TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1144 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001145 EXPECT_TRUE(mComposerClient
1146 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1147 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001148
ramindani44c952f2022-02-28 23:29:29 +00001149 bool isSupported;
1150 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001151 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001152 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1153 return;
1154 }
ramindanibab8ba92021-11-18 01:24:11 +00001155
ramindanidcecfd42022-02-03 23:52:19 +00001156 std::vector<Color> expectedColors(
1157 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001158
1159 setBackgroundColor(BLACK);
1160 setTopLayerColor(TRANSLUCENT_RED);
1161 setUpLayers(BlendMode::PREMULTIPLIED);
1162 setExpectedColors(expectedColors);
1163
ramindanidcecfd42022-02-03 23:52:19 +00001164 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001165 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001166 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1167 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001168 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001169 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1170 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001171 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001172 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001173 GTEST_SUCCEED();
1174 return;
1175 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001176 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001177 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001178 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001179 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001180 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1181 mTestRenderEngine->setRenderLayers(mLayers);
1182 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1183 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1184 }
1185}
1186
1187class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1188 protected:
1189 void SetUp() override {
1190 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001191
ramindanidcecfd42022-02-03 23:52:19 +00001192 auto backgroundLayer =
1193 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId());
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001194 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001195 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001196 backgroundLayer->setZOrder(0);
1197
ramindanidcecfd42022-02-03 23:52:19 +00001198 mSideLength =
1199 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001200 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1201 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1202
ramindani0a2bee42022-02-10 01:27:42 +00001203 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1204 getPrimaryDisplayId(), mSideLength, mSideLength,
1205 PixelFormat::RGBA_8888);
ramindanibab8ba92021-11-18 01:24:11 +00001206 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1207 mLayer->setZOrder(10);
1208
1209 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1210 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1211 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1212 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1213 mLayers = {backgroundLayer, mLayer};
1214 }
1215
1216 protected:
1217 std::shared_ptr<TestBufferLayer> mLayer;
1218 std::vector<std::shared_ptr<TestLayer>> mLayers;
1219 int mSideLength;
1220};
1221
1222TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1223 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001224 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1225 RenderIntent::COLORIMETRIC);
ramindanid5751092022-04-22 22:30:20 +00001226 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
ramindanidcecfd42022-02-03 23:52:19 +00001227 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1228 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001229 SUCCEED() << "ColorMode not supported, skip test";
1230 return;
1231 }
1232
ramindani44c952f2022-02-28 23:29:29 +00001233 bool isSupported;
1234 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001235 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001236 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1237 return;
1238 }
ramindanidcecfd42022-02-03 23:52:19 +00001239 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001240 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001241 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1242 mLayer->setTransform(Transform::FLIP_H);
Alec Mourif6c039a2023-10-06 23:02:17 +00001243 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001244
ramindanidcecfd42022-02-03 23:52:19 +00001245 std::vector<Color> expectedColors(
1246 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1247 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001248 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001249 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001250 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1251
1252 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001253 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001254 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1255 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001256 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001257 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001258 GTEST_SUCCEED();
1259 return;
1260 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001261 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001262 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001263 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001264 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001265
1266 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1267 mTestRenderEngine->setRenderLayers(mLayers);
1268 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1269 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1270 }
1271}
1272
1273TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1274 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001275 EXPECT_TRUE(mComposerClient
1276 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1277 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001278
ramindani44c952f2022-02-28 23:29:29 +00001279 bool isSupported;
1280 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001281 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001282 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1283 return;
1284 }
ramindanidcecfd42022-02-03 23:52:19 +00001285 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001286 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001287 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1288
1289 mLayer->setTransform(Transform::FLIP_V);
Alec Mourif6c039a2023-10-06 23:02:17 +00001290 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001291
ramindanidcecfd42022-02-03 23:52:19 +00001292 std::vector<Color> expectedColors(
1293 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1294 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001295 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001296 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001297 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1298
1299 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001300 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001301 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1302 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001303 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001304 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001305 GTEST_SUCCEED();
1306 return;
1307 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001308 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001309 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001310 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001311 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001312 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1313 mTestRenderEngine->setRenderLayers(mLayers);
1314 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1315 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1316 }
1317}
1318
1319TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1320 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001321 EXPECT_TRUE(mComposerClient
1322 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1323 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001324
ramindani44c952f2022-02-28 23:29:29 +00001325 bool isSupported;
1326 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001327 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001328 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1329 return;
1330 }
ramindanidcecfd42022-02-03 23:52:19 +00001331 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001332 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001333 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1334
1335 mLayer->setTransform(Transform::ROT_180);
Alec Mourif6c039a2023-10-06 23:02:17 +00001336 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001337
ramindanidcecfd42022-02-03 23:52:19 +00001338 std::vector<Color> expectedColors(
1339 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1340 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001341 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1342 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001343 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001344 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1345
1346 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001347 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001348 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1349 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001350 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001351 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001352 GTEST_SUCCEED();
1353 return;
1354 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001355 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001356 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001357 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001358 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001359 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1360 mTestRenderEngine->setRenderLayers(mLayers);
1361 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1362 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1363 }
1364}
1365
Alec Mourif6c039a2023-10-06 23:02:17 +00001366class GraphicsColorManagementCompositionTest
1367 : public GraphicsCompositionTestBase,
1368 public testing::WithParamInterface<std::tuple<std::string, Dataspace, Dataspace, Dataspace>> {
1369 public:
1370 void SetUp() override {
1371 SetUpBase(std::get<0>(GetParam()));
1372 // for some reason only sRGB reliably works
1373 mTestColorModes.erase(
1374 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
1375 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
1376 mTestColorModes.end());
1377 auto standard = std::get<1>(GetParam());
1378 auto transfer = std::get<2>(GetParam());
1379 auto range = std::get<3>(GetParam());
1380
1381 mLayerDataspace = static_cast<Dataspace>(static_cast<int32_t>(standard) |
1382 static_cast<int32_t>(transfer) |
1383 static_cast<int32_t>(range));
1384 ALOGD("Invoking test for dataspace: {%s, %s, %s}", toString(standard).c_str(),
1385 toString(transfer).c_str(), toString(range).c_str());
1386 }
1387
1388 void makeLayer() {
1389 mLayer = std::make_shared<TestBufferLayer>(
1390 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
1391 getDisplayHeight(), common::PixelFormat::RGBA_8888);
1392 mLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
1393 mLayer->setZOrder(10);
1394 mLayer->setAlpha(1.f);
1395 mLayer->setDataspace(mLayerDataspace);
1396 }
1397
1398 void fillColor(Color color) {
1399 std::vector<Color> baseColors(static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1400 ReadbackHelper::fillColorsArea(baseColors, getDisplayWidth(),
1401 common::Rect{.left = 0,
1402 .top = 0,
1403 .right = getDisplayWidth(),
1404 .bottom = getDisplayHeight()},
1405 color);
1406 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1407 }
1408
1409 Dataspace mLayerDataspace;
1410 std::shared_ptr<TestBufferLayer> mLayer;
1411};
1412
1413TEST_P(GraphicsColorManagementCompositionTest, ColorConversion) {
1414 for (ColorMode mode : mTestColorModes) {
1415 EXPECT_TRUE(mComposerClient
1416 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1417 .isOk());
1418
1419 bool isSupported;
1420 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
1421 if (!isSupported) {
1422 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1423 return;
1424 }
1425
1426 mClientCompositionDisplaySettings.outputDataspace =
1427 static_cast<::android::ui::Dataspace>(mDataspace);
1428 mTestRenderEngine->setDisplaySettings(mClientCompositionDisplaySettings);
1429
1430 makeLayer();
1431 for (auto color : {LIGHT_RED, LIGHT_GREEN, LIGHT_BLUE}) {
1432 ALOGD("Testing color: %f, %f, %f, %f with color mode: %d", color.r, color.g, color.b,
1433 color.a, mode);
1434 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1435 getDisplayHeight(), mPixelFormat, mDataspace);
1436 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1437 fillColor(color);
1438 writeLayers({mLayer});
1439 EXPECT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::ON).isOk());
1440
1441 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001442 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1443 VtsComposerClient::kNoFrameIntervalNs);
Alec Mourif6c039a2023-10-06 23:02:17 +00001444 execute();
1445 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
1446 continue;
1447 }
1448 ASSERT_TRUE(mReader.takeErrors().empty());
1449 mWriter->presentDisplay(getPrimaryDisplayId());
1450 execute();
1451 ASSERT_TRUE(mReader.takeErrors().empty());
1452
1453 mTestRenderEngine->setRenderLayers({mLayer});
1454 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1455 ASSERT_NO_FATAL_FAILURE(
1456 mTestRenderEngine->checkColorBuffer(readbackBuffer.getBuffer()));
1457 }
1458 }
1459}
1460
ramindanibab8ba92021-11-18 01:24:11 +00001461GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1462INSTANTIATE_TEST_SUITE_P(
1463 PerInstance, GraphicsCompositionTest,
1464 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1465 ::android::PrintInstanceNameToString);
1466
1467GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1468INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1469 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1470 IComposer::descriptor)),
1471 testing::Values("0.2", "1.0")));
1472
1473GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1474INSTANTIATE_TEST_SUITE_P(
1475 PerInstance, GraphicsTransformCompositionTest,
1476 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1477 ::android::PrintInstanceNameToString);
1478
Alec Mourif6c039a2023-10-06 23:02:17 +00001479GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsColorManagementCompositionTest);
1480INSTANTIATE_TEST_SUITE_P(PerInstance, GraphicsColorManagementCompositionTest,
1481 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1482 IComposer::descriptor)),
1483 // Only check sRGB, but verify that extended range
1484 // doesn't trigger any gamma shifts
1485 testing::Values(Dataspace::STANDARD_BT709),
1486 testing::Values(Dataspace::TRANSFER_SRGB),
1487 // Don't test limited range until we send YUV overlays
1488 testing::Values(Dataspace::RANGE_FULL,
1489 Dataspace::RANGE_EXTENDED)));
1490
ramindanibab8ba92021-11-18 01:24:11 +00001491} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001492} // namespace aidl::android::hardware::graphics::composer3::vts