blob: 3f829254551d0dc9c9a57c25843ef7cda48f72ec [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 {
Leon Scroggins III94f4b202024-01-09 11:43:45 -050088 ASSERT_FALSE(mDisplays.empty());
ramindanidcecfd42022-02-03 23:52:19 +000089 ASSERT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::OFF).isOk());
Ady Abrahama00d2462023-12-26 14:21:20 -080090 ASSERT_TRUE(mComposerClient->tearDown(mWriter.get()));
ramindanidcecfd42022-02-03 23:52:19 +000091 mComposerClient.reset();
Ady Abraham3192f3d2021-12-03 16:08:56 -080092 const auto errors = mReader.takeErrors();
93 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +000094 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
ramindanibab8ba92021-11-18 01:24:11 +000095 }
96
ramindanidcecfd42022-02-03 23:52:19 +000097 const VtsDisplay& getPrimaryDisplay() const { return mDisplays[0]; }
98
99 int64_t getPrimaryDisplayId() const { return getPrimaryDisplay().getDisplayId(); }
100
101 int64_t getInvalidDisplayId() const { return mComposerClient->getInvalidDisplayId(); }
102
103 int32_t getDisplayWidth() const { return getPrimaryDisplay().getDisplayWidth(); }
104
105 int32_t getDisplayHeight() const { return getPrimaryDisplay().getDisplayHeight(); }
106
ramindanid5751092022-04-22 22:30:20 +0000107 void assertServiceSpecificError(const ScopedAStatus& status, int32_t serviceSpecificError) {
108 ASSERT_EQ(status.getExceptionCode(), EX_SERVICE_SPECIFIC);
109 ASSERT_EQ(status.getServiceSpecificError(), serviceSpecificError);
110 }
111
Brian Lindahle887a252023-01-17 14:54:19 -0700112 std::pair<bool, ::android::sp<::android::GraphicBuffer>> allocateBuffer(uint32_t usage) {
113 const auto width = static_cast<uint32_t>(getDisplayWidth());
114 const auto height = static_cast<uint32_t>(getDisplayHeight());
115
116 const auto& graphicBuffer = ::android::sp<::android::GraphicBuffer>::make(
117 width, height, ::android::PIXEL_FORMAT_RGBA_8888,
118 /*layerCount*/ 1u, usage, "VtsHalGraphicsComposer3_ReadbackTest");
ramindani0a2bee42022-02-10 01:27:42 +0000119
120 if (graphicBuffer && ::android::OK == graphicBuffer->initCheck()) {
Brian Lindahle887a252023-01-17 14:54:19 -0700121 return {true, graphicBuffer};
ramindani0a2bee42022-02-10 01:27:42 +0000122 }
Brian Lindahle887a252023-01-17 14:54:19 -0700123 return {false, graphicBuffer};
ramindanibab8ba92021-11-18 01:24:11 +0000124 }
125
ramindanibab8ba92021-11-18 01:24:11 +0000126 void writeLayers(const std::vector<std::shared_ptr<TestLayer>>& layers) {
ramindanidcecfd42022-02-03 23:52:19 +0000127 for (const auto& layer : layers) {
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400128 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000129 }
130 execute();
131 }
132
133 void execute() {
Huihong Luo651806f2023-04-21 18:48:48 +0000134 auto commands = mWriter->takePendingCommands();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800135 if (commands.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800136 return;
ramindanibab8ba92021-11-18 01:24:11 +0000137 }
138
ramindanidcecfd42022-02-03 23:52:19 +0000139 auto [status, results] = mComposerClient->executeCommands(commands);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800140 ASSERT_TRUE(status.isOk()) << "executeCommands failed " << status.getDescription();
ramindanibab8ba92021-11-18 01:24:11 +0000141
Ady Abraham46219f52021-12-20 09:44:31 -0800142 mReader.parse(std::move(results));
ramindanibab8ba92021-11-18 01:24:11 +0000143 }
144
ramindani44c952f2022-02-28 23:29:29 +0000145 bool getHasReadbackBuffer() {
ramindanidcecfd42022-02-03 23:52:19 +0000146 auto [status, readBackBufferAttributes] =
147 mComposerClient->getReadbackBufferAttributes(getPrimaryDisplayId());
148 if (status.isOk()) {
149 mPixelFormat = readBackBufferAttributes.format;
150 mDataspace = readBackBufferAttributes.dataspace;
ramindani44c952f2022-02-28 23:29:29 +0000151 return ReadbackHelper::readbackSupported(mPixelFormat, mDataspace);
ramindanidcecfd42022-02-03 23:52:19 +0000152 }
ramindanid5751092022-04-22 22:30:20 +0000153 EXPECT_NO_FATAL_FAILURE(
154 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
ramindani44c952f2022-02-28 23:29:29 +0000155 return false;
ramindanib27f33b2021-12-03 19:36:10 +0000156 }
157
ramindanidcecfd42022-02-03 23:52:19 +0000158 std::shared_ptr<VtsComposerClient> mComposerClient;
159 std::vector<VtsDisplay> mDisplays;
160 // use the slot count usually set by SF
ramindanibab8ba92021-11-18 01:24:11 +0000161 std::vector<ColorMode> mTestColorModes;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400162 std::unique_ptr<ComposerClientWriter> mWriter;
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800163 ComposerClientReader mReader;
ramindanibab8ba92021-11-18 01:24:11 +0000164 std::unique_ptr<TestRenderEngine> mTestRenderEngine;
ramindanibab8ba92021-11-18 01:24:11 +0000165 common::PixelFormat mPixelFormat;
166 common::Dataspace mDataspace;
Alec Mourif6c039a2023-10-06 23:02:17 +0000167 ::android::renderengine::DisplaySettings mClientCompositionDisplaySettings;
ramindanibab8ba92021-11-18 01:24:11 +0000168
169 static constexpr uint32_t kClientTargetSlotCount = 64;
170
171 private:
ramindanibab8ba92021-11-18 01:24:11 +0000172 void setTestColorModes() {
173 mTestColorModes.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000174 const auto& [status, modes] = mComposerClient->getColorModes(getPrimaryDisplayId());
175 ASSERT_TRUE(status.isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000176
177 for (ColorMode mode : modes) {
178 if (std::find(ReadbackHelper::colorModes.begin(), ReadbackHelper::colorModes.end(),
179 mode) != ReadbackHelper::colorModes.end()) {
180 mTestColorModes.push_back(mode);
181 }
182 }
183 }
184};
185
186class GraphicsCompositionTest : public GraphicsCompositionTestBase,
187 public testing::WithParamInterface<std::string> {
188 public:
189 void SetUp() override { SetUpBase(GetParam()); }
190};
191
192TEST_P(GraphicsCompositionTest, SingleSolidColorLayer) {
193 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000194 EXPECT_TRUE(mComposerClient
195 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
196 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000197
ramindani44c952f2022-02-28 23:29:29 +0000198 bool isSupported;
199 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000200 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000201 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
202 return;
203 }
204
Ady Abrahama00d2462023-12-26 14:21:20 -0800205 auto layer =
206 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000207 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000208 layer->setColor(BLUE);
209 layer->setDisplayFrame(coloredSquare);
210 layer->setZOrder(10);
211
212 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
213
214 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000215 std::vector<Color> expectedColors(
216 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
217 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000218
ramindanidcecfd42022-02-03 23:52:19 +0000219 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700220 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000221 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
222
223 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800224 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800225 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
226 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000227 execute();
228 // if hwc cannot handle and asks for composition change,
229 // just succeed the test
ramindanidcecfd42022-02-03 23:52:19 +0000230 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000231 GTEST_SUCCEED();
232 return;
233 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800234 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400235 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000236 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800237 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000238
239 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
240 mTestRenderEngine->setRenderLayers(layers);
241 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
242 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
243 }
244}
245
246TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
247 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000248 EXPECT_TRUE(mComposerClient
249 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
250 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000251
ramindani44c952f2022-02-28 23:29:29 +0000252 bool isSupported;
253 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000254 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000255 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
256 return;
257 }
258
ramindanidcecfd42022-02-03 23:52:19 +0000259 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700260 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000261 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000262 std::vector<Color> expectedColors(
263 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
264 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
265 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
266 ReadbackHelper::fillColorsArea(
267 expectedColors, getDisplayWidth(),
268 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
269 ReadbackHelper::fillColorsArea(
270 expectedColors, getDisplayWidth(),
271 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000272
273 auto layer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000274 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -0800275 getDisplayHeight(), common::PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000276 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000277 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000278 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000279 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
280
281 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
282
283 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800284 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800285 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
286 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000287 execute();
288
ramindanidcecfd42022-02-03 23:52:19 +0000289 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000290 GTEST_SUCCEED();
291 return;
292 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800293 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000294
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400295 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000296 execute();
297
Ady Abraham3192f3d2021-12-03 16:08:56 -0800298 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000299
300 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
301 mTestRenderEngine->setRenderLayers(layers);
302 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
303 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
304 }
305}
306
307TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
308 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000309 EXPECT_TRUE(mComposerClient
310 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
311 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000312
ramindani44c952f2022-02-28 23:29:29 +0000313 bool isSupported;
314 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000315 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000316 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
317 return;
318 }
319
Ady Abrahama00d2462023-12-26 14:21:20 -0800320 auto layer =
321 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000322 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000323 layer->setColor(BLUE);
324 layer->setDisplayFrame(coloredSquare);
325 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400326 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000327
328 // This following buffer call should have no effect
Brian Lindahle887a252023-01-17 14:54:19 -0700329 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
330 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
331 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
332 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000333 const auto& buffer = graphicBuffer->handle;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400334 mWriter->setLayerBuffer(getPrimaryDisplayId(), layer->getLayer(), /*slot*/ 0, buffer,
335 /*acquireFence*/ -1);
ramindanibab8ba92021-11-18 01:24:11 +0000336
337 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000338 std::vector<Color> expectedColors(
339 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
340 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000341
ramindanidcecfd42022-02-03 23:52:19 +0000342 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700343 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000344 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
345
ramindanicdcfcaf2023-11-09 10:00:10 -0800346 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
347 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000348 execute();
349
ramindanidcecfd42022-02-03 23:52:19 +0000350 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000351 GTEST_SUCCEED();
352 return;
353 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800354 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400355 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000356 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800357 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000358
359 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
360 }
361}
362
ramindanib27f33b2021-12-03 19:36:10 +0000363TEST_P(GraphicsCompositionTest, SetReadbackBuffer) {
ramindani44c952f2022-02-28 23:29:29 +0000364 bool isSupported;
365 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000366 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000367 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
368 return;
369 }
370
ramindanidcecfd42022-02-03 23:52:19 +0000371 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700372 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanib27f33b2021-12-03 19:36:10 +0000373
374 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
375}
376
ramindanidcecfd42022-02-03 23:52:19 +0000377TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadDisplay) {
ramindani44c952f2022-02-28 23:29:29 +0000378 bool isSupported;
379 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000380 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000381 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
382 return;
383 }
384
Brian Lindahle887a252023-01-17 14:54:19 -0700385 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
386 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
387 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
388 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000389 const auto& bufferHandle = graphicBuffer->handle;
ramindanib27f33b2021-12-03 19:36:10 +0000390 ::ndk::ScopedFileDescriptor fence = ::ndk::ScopedFileDescriptor(-1);
391
ramindanidcecfd42022-02-03 23:52:19 +0000392 const auto status =
393 mComposerClient->setReadbackBuffer(getInvalidDisplayId(), bufferHandle, fence);
ramindanib27f33b2021-12-03 19:36:10 +0000394
ramindanidcecfd42022-02-03 23:52:19 +0000395 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000396 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
ramindanib27f33b2021-12-03 19:36:10 +0000397}
398
ramindanidcecfd42022-02-03 23:52:19 +0000399TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadParameter) {
ramindani44c952f2022-02-28 23:29:29 +0000400 bool isSupported;
401 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000402 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000403 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
404 return;
405 }
406
ramindanidcecfd42022-02-03 23:52:19 +0000407 const native_handle_t bufferHandle{};
ramindanib27f33b2021-12-03 19:36:10 +0000408 ndk::ScopedFileDescriptor releaseFence = ndk::ScopedFileDescriptor(-1);
ramindanidcecfd42022-02-03 23:52:19 +0000409 const auto status =
410 mComposerClient->setReadbackBuffer(getPrimaryDisplayId(), &bufferHandle, releaseFence);
ramindanib27f33b2021-12-03 19:36:10 +0000411
ramindanidcecfd42022-02-03 23:52:19 +0000412 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000413 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
ramindanib27f33b2021-12-03 19:36:10 +0000414}
415
416TEST_P(GraphicsCompositionTest, GetReadbackBufferFenceInactive) {
ramindani44c952f2022-02-28 23:29:29 +0000417 bool isSupported;
418 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000419 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000420 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
421 return;
422 }
423
ramindanidcecfd42022-02-03 23:52:19 +0000424 const auto& [status, releaseFence] =
425 mComposerClient->getReadbackBufferFence(getPrimaryDisplayId());
ramindanib27f33b2021-12-03 19:36:10 +0000426
ramindanidcecfd42022-02-03 23:52:19 +0000427 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000428 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
Alec Mouri62ae37b2022-01-20 17:16:38 -0800429 EXPECT_EQ(-1, releaseFence.get());
ramindanib27f33b2021-12-03 19:36:10 +0000430}
431
ramindanibab8ba92021-11-18 01:24:11 +0000432TEST_P(GraphicsCompositionTest, ClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000433 EXPECT_TRUE(
434 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
435 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000436
437 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000438 EXPECT_TRUE(mComposerClient
439 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
ramindanibab8ba92021-11-18 01:24:11 +0000440 .isOk());
441
ramindani44c952f2022-02-28 23:29:29 +0000442 bool isSupported;
443 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000444 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000445 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
446 return;
447 }
448
ramindanidcecfd42022-02-03 23:52:19 +0000449 std::vector<Color> expectedColors(
450 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
451 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
452 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
453 ReadbackHelper::fillColorsArea(
454 expectedColors, getDisplayWidth(),
455 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
456 ReadbackHelper::fillColorsArea(
457 expectedColors, getDisplayWidth(),
458 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000459
Ady Abrahama00d2462023-12-26 14:21:20 -0800460 auto layer = std::make_shared<TestBufferLayer>(
461 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
462 getDisplayHeight(), PixelFormat::RGBA_FP16, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000463 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000464 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000465 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000466
467 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
468
ramindanidcecfd42022-02-03 23:52:19 +0000469 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700470 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000471 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
472 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800473 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800474 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
475 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000476 execute();
477
ramindanidcecfd42022-02-03 23:52:19 +0000478 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800479 if (!changedCompositionTypes.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800480 ASSERT_EQ(1, changedCompositionTypes.size());
Ady Abraham46219f52021-12-20 09:44:31 -0800481 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindanibab8ba92021-11-18 01:24:11 +0000482
483 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700484 auto clientUsage = static_cast<uint32_t>(
485 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN) |
486 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
487 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000488 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000489 common::Rect damage{0, 0, getDisplayWidth(), getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000490
491 // create client target buffer
Brian Lindahle887a252023-01-17 14:54:19 -0700492 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
493 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000494 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000495 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000496 const auto stride = static_cast<uint32_t>(graphicBuffer->stride);
497 graphicBuffer->lock(clientUsage, layer->getAccessRegion(), &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000498
499 ASSERT_NO_FATAL_FAILURE(
ramindani0a2bee42022-02-10 01:27:42 +0000500 ReadbackHelper::fillBuffer(layer->getWidth(), layer->getHeight(), stride,
ramindanibab8ba92021-11-18 01:24:11 +0000501 clientBufData, clientFormat, expectedColors));
ramindanib1144212022-02-10 01:51:24 +0000502 int32_t clientFence;
503 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
504 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400505 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
Alec Mouri8062f1f2023-09-06 02:14:47 +0000506 clientDataspace, std::vector<common::Rect>(1, damage), 1.f);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400507 layer->setToClientComposition(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800508 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
509 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000510 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000511 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800512 ASSERT_TRUE(changedCompositionTypes.empty());
ramindanibab8ba92021-11-18 01:24:11 +0000513 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800514 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000515
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400516 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000517 execute();
518
Ady Abraham3192f3d2021-12-03 16:08:56 -0800519 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000520
521 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
522 }
523}
524
525TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000526 ASSERT_TRUE(
527 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
528 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000529
530 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000531 EXPECT_TRUE(mComposerClient
532 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
533 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000534
ramindani44c952f2022-02-28 23:29:29 +0000535 bool isSupported;
536 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000537 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000538 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
539 return;
540 }
541
ramindanidcecfd42022-02-03 23:52:19 +0000542 std::vector<Color> expectedColors(
543 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
544 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
545 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
546 ReadbackHelper::fillColorsArea(
547 expectedColors, getDisplayWidth(),
548 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000549
ramindanidcecfd42022-02-03 23:52:19 +0000550 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700551 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000552 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
553
554 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000555 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -0800556 getDisplayHeight() / 2, PixelFormat::RGBA_8888, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000557 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
558 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
559 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
560 static_cast<int32_t>(deviceLayer->getHeight())},
561 GREEN);
562 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
563 static_cast<int32_t>(deviceLayer->getHeight())});
564 deviceLayer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000565 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000566 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400567 deviceLayer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000568
569 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700570 auto clientUsage = static_cast<uint32_t>(
571 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
572 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
573 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000574 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000575 int32_t clientWidth = getDisplayWidth();
576 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000577
578 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000579 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
Ady Abrahama00d2462023-12-26 14:21:20 -0800580 clientHeight, PixelFormat::RGBA_FP16, *mWriter, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000581 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
582 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000583 clientLayer->setDisplayFrame(clientFrame);
584 clientLayer->setZOrder(0);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400585 clientLayer->write(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800586 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
587 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000588 execute();
589
ramindanidcecfd42022-02-03 23:52:19 +0000590 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800591 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000592 continue;
593 }
594 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800595 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
Brian Lindahle887a252023-01-17 14:54:19 -0700596 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
597 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000598 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000599
600 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000601 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
602 &clientBufData);
ramindanibab8ba92021-11-18 01:24:11 +0000603
ramindanidcecfd42022-02-03 23:52:19 +0000604 std::vector<Color> clientColors(
605 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
606 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000607 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000608 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
ramindani0a2bee42022-02-10 01:27:42 +0000609 graphicBuffer->getStride(), clientBufData, clientFormat, clientColors));
ramindanib1144212022-02-10 01:51:24 +0000610 int32_t clientFence;
611 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
612 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400613 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
Alec Mouri8062f1f2023-09-06 02:14:47 +0000614 clientDataspace, std::vector<common::Rect>(1, clientFrame), 1.f);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400615 clientLayer->setToClientComposition(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800616 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
617 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000618 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000619 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800620 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800621 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000622
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400623 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000624 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800625 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000626 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
627 }
628}
629
630TEST_P(GraphicsCompositionTest, SetLayerDamage) {
631 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000632 EXPECT_TRUE(mComposerClient
633 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
634 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000635
ramindani44c952f2022-02-28 23:29:29 +0000636 bool isSupported;
637 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000638 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000639 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
640 return;
641 }
642
ramindanidcecfd42022-02-03 23:52:19 +0000643 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000644
ramindanidcecfd42022-02-03 23:52:19 +0000645 std::vector<Color> expectedColors(
646 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
647 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000648
Ady Abrahama00d2462023-12-26 14:21:20 -0800649 auto layer = std::make_shared<TestBufferLayer>(
650 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
651 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000652 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000653 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000654 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000655 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
656
657 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
658
ramindanidcecfd42022-02-03 23:52:19 +0000659 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700660 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000661 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
662
663 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800664 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800665 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
666 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000667 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000668 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000669 GTEST_SUCCEED();
670 return;
671 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800672 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400673 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000674 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800675 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000676
677 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
678
679 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +0000680 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
681 getDisplayHeight() / 2};
682 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
683 getDisplayWidth());
684 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000685
686 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
687 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +0000688 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +0000689
690 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
691
692 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800693 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800694 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
695 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000696 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800697 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000698 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400699 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000700 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800701 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000702
703 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
704 }
705}
706
707TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
708 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000709 EXPECT_TRUE(mComposerClient
710 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
711 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000712
ramindani44c952f2022-02-28 23:29:29 +0000713 bool isSupported;
714 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000715 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000716 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
717 return;
718 }
719
Ady Abrahama00d2462023-12-26 14:21:20 -0800720 auto layer =
721 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000722 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +0000723 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000724 layer->setZOrder(10);
725 layer->setAlpha(0);
726 layer->setBlendMode(BlendMode::PREMULTIPLIED);
727
728 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
729
ramindanidcecfd42022-02-03 23:52:19 +0000730 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700731 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000732
733 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
734
735 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800736 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800737 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
738 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000739 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000740 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000741 GTEST_SUCCEED();
742 return;
743 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800744 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000745
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400746 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000747 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800748 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000749
ramindanidcecfd42022-02-03 23:52:19 +0000750 std::vector<Color> expectedColors(
751 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000752
753 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
754 mTestRenderEngine->setRenderLayers(layers);
755 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
756 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
757 }
758}
759
760TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
761 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000762 EXPECT_TRUE(mComposerClient
763 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
764 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000765
ramindani44c952f2022-02-28 23:29:29 +0000766 bool isSupported;
767 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000768 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000769 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
770 return;
771 }
772
ramindanidcecfd42022-02-03 23:52:19 +0000773 std::vector<Color> expectedColors(
774 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
775 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
776 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
777 ReadbackHelper::fillColorsArea(
778 expectedColors, getDisplayWidth(),
779 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000780
Ady Abrahama00d2462023-12-26 14:21:20 -0800781 auto layer = std::make_shared<TestBufferLayer>(
782 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
783 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000784 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000785 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000786 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanidcecfd42022-02-03 23:52:19 +0000787 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
788 static_cast<float>(getDisplayWidth()),
789 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +0000790 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
791
792 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
793
794 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +0000795 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
796 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
797 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700798 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000799 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
800 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800801 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800802 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
803 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000804 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000805 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000806 GTEST_SUCCEED();
807 return;
808 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800809 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400810 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000811 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800812 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000813 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
814 mTestRenderEngine->setRenderLayers(layers);
815 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
816 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
817 }
818}
819
820TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
821 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000822 EXPECT_TRUE(mComposerClient
823 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
824 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000825
ramindani44c952f2022-02-28 23:29:29 +0000826 bool isSupported;
827 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000828 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000829 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
830 return;
831 }
832
ramindanidcecfd42022-02-03 23:52:19 +0000833 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
834 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
Ady Abrahama00d2462023-12-26 14:21:20 -0800835 auto redLayer =
836 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000837 redLayer->setColor(RED);
838 redLayer->setDisplayFrame(redRect);
839
Ady Abrahama00d2462023-12-26 14:21:20 -0800840 auto blueLayer =
841 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000842 blueLayer->setColor(BLUE);
843 blueLayer->setDisplayFrame(blueRect);
844 blueLayer->setZOrder(5);
845
846 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000847 std::vector<Color> expectedColors(
848 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000849
850 // red in front of blue
851 redLayer->setZOrder(10);
852
853 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +0000854 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
855 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000856
ramindanidcecfd42022-02-03 23:52:19 +0000857 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700858 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000859 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
860
861 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800862 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800863 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
864 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000865 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000866 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000867 GTEST_SUCCEED();
868 return;
869 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400870 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000871 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800872 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000873
874 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
875
876 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +0000877 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
878 getDisplayWidth());
879 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
880 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000881
882 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
883
884 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800885 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800886 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
887 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000888 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000889 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800890 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400891 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000892 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800893 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000894
895 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
896 mTestRenderEngine->setRenderLayers(layers);
897 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
898 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
899 }
900}
901
Alec Mourib1f16722022-02-07 13:03:44 -0800902TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
Alec Mouri51067012022-01-06 17:28:39 -0800903 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000904 EXPECT_TRUE(mComposerClient
905 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
906 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -0800907
ramindani44c952f2022-02-28 23:29:29 +0000908 bool isSupported;
909 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000910 if (!isSupported) {
Alec Mouri51067012022-01-06 17:28:39 -0800911 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
912 "color mode: "
913 << toString(mode);
914 continue;
915 }
ramindanidcecfd42022-02-03 23:52:19 +0000916 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
917 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
918 getDisplayHeight()};
Alec Mouri712b3d92023-09-29 00:21:37 +0000919
920 static constexpr float kMaxBrightnessNits = 300.f;
921
ramindanidcecfd42022-02-03 23:52:19 +0000922 const auto redLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -0800923 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Alec Mouri51067012022-01-06 17:28:39 -0800924 redLayer->setColor(RED);
925 redLayer->setDisplayFrame(redRect);
Alec Mouri712b3d92023-09-29 00:21:37 +0000926 redLayer->setWhitePointNits(kMaxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -0800927 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -0800928
929 const auto dimmerRedLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -0800930 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Alec Mouri51067012022-01-06 17:28:39 -0800931 dimmerRedLayer->setColor(RED);
932 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
933 // Intentionally use a small dimming ratio as some implementations may be more likely to
934 // kick into GPU composition to apply dithering when the dimming ratio is high.
935 static constexpr float kDimmingRatio = 0.9f;
Alec Mouri712b3d92023-09-29 00:21:37 +0000936 dimmerRedLayer->setWhitePointNits(kMaxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -0800937 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -0800938
939 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +0000940 std::vector<Color> expectedColors(
941 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -0800942
ramindanidcecfd42022-02-03 23:52:19 +0000943 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
944 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -0800945
ramindanidcecfd42022-02-03 23:52:19 +0000946 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700947 getDisplayHeight(), mPixelFormat, mDataspace);
Alec Mouri51067012022-01-06 17:28:39 -0800948 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
949
950 writeLayers(layers);
951 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800952 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
953 VtsComposerClient::kNoFrameIntervalNs);
Alec Mouri51067012022-01-06 17:28:39 -0800954 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000955 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -0800956 GTEST_SUCCEED()
957 << "Readback verification not supported for GPU composition for color mode: "
958 << toString(mode);
959 continue;
960 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400961 mWriter->presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -0800962 execute();
963 ASSERT_TRUE(mReader.takeErrors().empty());
964
965 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
966 mTestRenderEngine->setRenderLayers(layers);
967 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
968 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
969 }
970}
971
ramindanibab8ba92021-11-18 01:24:11 +0000972class GraphicsBlendModeCompositionTest
973 : public GraphicsCompositionTestBase,
974 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
975 public:
976 void SetUp() override {
977 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +0000978 // TODO(b/219590743) we should remove the below SRGB color mode
979 // once we have the BlendMode test fix for all the versions of the ColorMode
ramindania4e76362022-03-02 01:48:06 +0000980 mTestColorModes.erase(
981 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
982 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
983 mTestColorModes.end());
ramindanibab8ba92021-11-18 01:24:11 +0000984 mBackgroundColor = BLACK;
985 mTopLayerColor = RED;
986 }
987
988 void setBackgroundColor(Color color) { mBackgroundColor = color; }
989
990 void setTopLayerColor(Color color) { mTopLayerColor = color; }
991
992 void setUpLayers(BlendMode blendMode) {
993 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000994 std::vector<Color> topLayerPixelColors(
995 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
996 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
997 {0, 0, getDisplayWidth(), getDisplayHeight()},
998 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +0000999
ramindanidcecfd42022-02-03 23:52:19 +00001000 auto backgroundLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001001 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +00001002 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001003 backgroundLayer->setZOrder(0);
1004 backgroundLayer->setColor(mBackgroundColor);
1005
Ady Abrahama00d2462023-12-26 14:21:20 -08001006 auto layer = std::make_shared<TestBufferLayer>(
1007 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
1008 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +00001009 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001010 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +00001011 layer->setDataspace(Dataspace::UNKNOWN);
ramindanibab8ba92021-11-18 01:24:11 +00001012 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
1013
1014 layer->setBlendMode(blendMode);
1015 layer->setAlpha(std::stof(std::get<1>(GetParam())));
1016
1017 mLayers.push_back(backgroundLayer);
1018 mLayers.push_back(layer);
1019 }
1020
1021 void setExpectedColors(std::vector<Color>& expectedColors) {
1022 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001023 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1024 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001025
1026 auto layer = mLayers[1];
1027 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001028 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001029 if (blendMode == BlendMode::NONE) {
1030 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001031 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1032 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1033 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1034 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001035 }
1036 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1037 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001038 expectedColor.r =
1039 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1040 expectedColor.g =
1041 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1042 expectedColor.b =
1043 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1044 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001045 }
1046 } else if (blendMode == BlendMode::COVERAGE) {
1047 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001048 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1049 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1050 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1051 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001052 }
1053 }
1054 }
1055
1056 protected:
1057 std::vector<std::shared_ptr<TestLayer>> mLayers;
1058 Color mBackgroundColor;
1059 Color mTopLayerColor;
1060};
ramindanic7585d92022-04-15 18:30:41 +00001061
1062TEST_P(GraphicsBlendModeCompositionTest, None) {
ramindanibab8ba92021-11-18 01:24:11 +00001063 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001064 EXPECT_TRUE(mComposerClient
1065 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1066 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001067
ramindani44c952f2022-02-28 23:29:29 +00001068 bool isSupported;
1069 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001070 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001071 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1072 return;
1073 }
1074
ramindanidcecfd42022-02-03 23:52:19 +00001075 std::vector<Color> expectedColors(
1076 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001077
1078 setBackgroundColor(BLACK);
1079 setTopLayerColor(TRANSLUCENT_RED);
1080 setUpLayers(BlendMode::NONE);
1081 setExpectedColors(expectedColors);
1082
ramindanidcecfd42022-02-03 23:52:19 +00001083 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001084 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001085 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1086 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001087 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001088 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1089 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001090 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001091 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001092 GTEST_SUCCEED();
1093 return;
1094 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001095 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001096 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001097 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001098 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001099
1100 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1101 mTestRenderEngine->setRenderLayers(mLayers);
1102 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1103 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1104 }
1105}
1106
ramindani07e6f842022-02-15 15:28:33 +00001107TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001108 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001109 EXPECT_TRUE(mComposerClient
1110 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1111 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001112
ramindani44c952f2022-02-28 23:29:29 +00001113 bool isSupported;
1114 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001115 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001116 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1117 return;
1118 }
1119
ramindanidcecfd42022-02-03 23:52:19 +00001120 std::vector<Color> expectedColors(
1121 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001122
1123 setBackgroundColor(BLACK);
1124 setTopLayerColor(TRANSLUCENT_RED);
1125
1126 setUpLayers(BlendMode::COVERAGE);
1127 setExpectedColors(expectedColors);
1128
ramindanidcecfd42022-02-03 23:52:19 +00001129 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001130 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001131 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1132 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001133 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001134 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1135 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001136 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001137 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001138 GTEST_SUCCEED();
1139 return;
1140 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001141 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001142 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001143 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001144 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001145 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1146 }
1147}
1148
1149TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1150 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001151 EXPECT_TRUE(mComposerClient
1152 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1153 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001154
ramindani44c952f2022-02-28 23:29:29 +00001155 bool isSupported;
1156 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001157 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001158 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1159 return;
1160 }
ramindanibab8ba92021-11-18 01:24:11 +00001161
ramindanidcecfd42022-02-03 23:52:19 +00001162 std::vector<Color> expectedColors(
1163 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001164
1165 setBackgroundColor(BLACK);
1166 setTopLayerColor(TRANSLUCENT_RED);
1167 setUpLayers(BlendMode::PREMULTIPLIED);
1168 setExpectedColors(expectedColors);
1169
ramindanidcecfd42022-02-03 23:52:19 +00001170 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001171 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001172 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1173 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001174 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001175 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1176 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001177 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001178 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001179 GTEST_SUCCEED();
1180 return;
1181 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001182 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001183 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001184 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001185 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001186 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1187 mTestRenderEngine->setRenderLayers(mLayers);
1188 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1189 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1190 }
1191}
1192
1193class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1194 protected:
1195 void SetUp() override {
1196 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001197
ramindanidcecfd42022-02-03 23:52:19 +00001198 auto backgroundLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001199 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001200 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001201 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001202 backgroundLayer->setZOrder(0);
1203
ramindanidcecfd42022-02-03 23:52:19 +00001204 mSideLength =
1205 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001206 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1207 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1208
ramindani0a2bee42022-02-10 01:27:42 +00001209 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1210 getPrimaryDisplayId(), mSideLength, mSideLength,
Ady Abrahama00d2462023-12-26 14:21:20 -08001211 PixelFormat::RGBA_8888, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001212 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1213 mLayer->setZOrder(10);
1214
1215 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1216 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1217 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1218 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1219 mLayers = {backgroundLayer, mLayer};
1220 }
1221
1222 protected:
1223 std::shared_ptr<TestBufferLayer> mLayer;
1224 std::vector<std::shared_ptr<TestLayer>> mLayers;
1225 int mSideLength;
1226};
1227
1228TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1229 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001230 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1231 RenderIntent::COLORIMETRIC);
ramindanid5751092022-04-22 22:30:20 +00001232 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
ramindanidcecfd42022-02-03 23:52:19 +00001233 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1234 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001235 SUCCEED() << "ColorMode not supported, skip test";
1236 return;
1237 }
1238
ramindani44c952f2022-02-28 23:29:29 +00001239 bool isSupported;
1240 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001241 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001242 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1243 return;
1244 }
ramindanidcecfd42022-02-03 23:52:19 +00001245 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001246 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001247 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1248 mLayer->setTransform(Transform::FLIP_H);
Alec Mourif6c039a2023-10-06 23:02:17 +00001249 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001250
ramindanidcecfd42022-02-03 23:52:19 +00001251 std::vector<Color> expectedColors(
1252 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1253 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001254 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001255 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001256 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1257
1258 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001259 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001260 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1261 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001262 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001263 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001264 GTEST_SUCCEED();
1265 return;
1266 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001267 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001268 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001269 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001270 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001271
1272 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1273 mTestRenderEngine->setRenderLayers(mLayers);
1274 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1275 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1276 }
1277}
1278
1279TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1280 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001281 EXPECT_TRUE(mComposerClient
1282 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1283 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001284
ramindani44c952f2022-02-28 23:29:29 +00001285 bool isSupported;
1286 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001287 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001288 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1289 return;
1290 }
ramindanidcecfd42022-02-03 23:52:19 +00001291 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001292 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001293 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1294
1295 mLayer->setTransform(Transform::FLIP_V);
Alec Mourif6c039a2023-10-06 23:02:17 +00001296 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001297
ramindanidcecfd42022-02-03 23:52:19 +00001298 std::vector<Color> expectedColors(
1299 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1300 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001301 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001302 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001303 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1304
1305 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001306 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001307 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1308 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001309 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001310 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001311 GTEST_SUCCEED();
1312 return;
1313 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001314 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001315 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001316 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001317 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001318 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1319 mTestRenderEngine->setRenderLayers(mLayers);
1320 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1321 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1322 }
1323}
1324
1325TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1326 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001327 EXPECT_TRUE(mComposerClient
1328 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1329 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001330
ramindani44c952f2022-02-28 23:29:29 +00001331 bool isSupported;
1332 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001333 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001334 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1335 return;
1336 }
ramindanidcecfd42022-02-03 23:52:19 +00001337 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001338 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001339 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1340
1341 mLayer->setTransform(Transform::ROT_180);
Alec Mourif6c039a2023-10-06 23:02:17 +00001342 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001343
ramindanidcecfd42022-02-03 23:52:19 +00001344 std::vector<Color> expectedColors(
1345 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1346 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001347 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1348 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001349 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001350 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1351
1352 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001353 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001354 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1355 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001356 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001357 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001358 GTEST_SUCCEED();
1359 return;
1360 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001361 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001362 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001363 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001364 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001365 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1366 mTestRenderEngine->setRenderLayers(mLayers);
1367 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1368 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1369 }
1370}
1371
Alec Mourif6c039a2023-10-06 23:02:17 +00001372class GraphicsColorManagementCompositionTest
1373 : public GraphicsCompositionTestBase,
1374 public testing::WithParamInterface<std::tuple<std::string, Dataspace, Dataspace, Dataspace>> {
1375 public:
1376 void SetUp() override {
1377 SetUpBase(std::get<0>(GetParam()));
1378 // for some reason only sRGB reliably works
1379 mTestColorModes.erase(
1380 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
1381 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
1382 mTestColorModes.end());
1383 auto standard = std::get<1>(GetParam());
1384 auto transfer = std::get<2>(GetParam());
1385 auto range = std::get<3>(GetParam());
1386
1387 mLayerDataspace = static_cast<Dataspace>(static_cast<int32_t>(standard) |
1388 static_cast<int32_t>(transfer) |
1389 static_cast<int32_t>(range));
1390 ALOGD("Invoking test for dataspace: {%s, %s, %s}", toString(standard).c_str(),
1391 toString(transfer).c_str(), toString(range).c_str());
1392 }
1393
1394 void makeLayer() {
1395 mLayer = std::make_shared<TestBufferLayer>(
1396 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -08001397 getDisplayHeight(), common::PixelFormat::RGBA_8888, *mWriter);
Alec Mourif6c039a2023-10-06 23:02:17 +00001398 mLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
1399 mLayer->setZOrder(10);
1400 mLayer->setAlpha(1.f);
1401 mLayer->setDataspace(mLayerDataspace);
1402 }
1403
1404 void fillColor(Color color) {
1405 std::vector<Color> baseColors(static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1406 ReadbackHelper::fillColorsArea(baseColors, getDisplayWidth(),
1407 common::Rect{.left = 0,
1408 .top = 0,
1409 .right = getDisplayWidth(),
1410 .bottom = getDisplayHeight()},
1411 color);
1412 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1413 }
1414
1415 Dataspace mLayerDataspace;
1416 std::shared_ptr<TestBufferLayer> mLayer;
1417};
1418
1419TEST_P(GraphicsColorManagementCompositionTest, ColorConversion) {
1420 for (ColorMode mode : mTestColorModes) {
1421 EXPECT_TRUE(mComposerClient
1422 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1423 .isOk());
1424
1425 bool isSupported;
1426 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
1427 if (!isSupported) {
1428 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1429 return;
1430 }
1431
1432 mClientCompositionDisplaySettings.outputDataspace =
1433 static_cast<::android::ui::Dataspace>(mDataspace);
1434 mTestRenderEngine->setDisplaySettings(mClientCompositionDisplaySettings);
1435
1436 makeLayer();
1437 for (auto color : {LIGHT_RED, LIGHT_GREEN, LIGHT_BLUE}) {
1438 ALOGD("Testing color: %f, %f, %f, %f with color mode: %d", color.r, color.g, color.b,
1439 color.a, mode);
1440 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1441 getDisplayHeight(), mPixelFormat, mDataspace);
1442 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1443 fillColor(color);
1444 writeLayers({mLayer});
1445 EXPECT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::ON).isOk());
1446
1447 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001448 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1449 VtsComposerClient::kNoFrameIntervalNs);
Alec Mourif6c039a2023-10-06 23:02:17 +00001450 execute();
1451 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
1452 continue;
1453 }
1454 ASSERT_TRUE(mReader.takeErrors().empty());
1455 mWriter->presentDisplay(getPrimaryDisplayId());
1456 execute();
1457 ASSERT_TRUE(mReader.takeErrors().empty());
1458
1459 mTestRenderEngine->setRenderLayers({mLayer});
1460 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1461 ASSERT_NO_FATAL_FAILURE(
1462 mTestRenderEngine->checkColorBuffer(readbackBuffer.getBuffer()));
1463 }
1464 }
1465}
1466
ramindanibab8ba92021-11-18 01:24:11 +00001467GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1468INSTANTIATE_TEST_SUITE_P(
1469 PerInstance, GraphicsCompositionTest,
1470 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1471 ::android::PrintInstanceNameToString);
1472
1473GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1474INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1475 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1476 IComposer::descriptor)),
1477 testing::Values("0.2", "1.0")));
1478
1479GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1480INSTANTIATE_TEST_SUITE_P(
1481 PerInstance, GraphicsTransformCompositionTest,
1482 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1483 ::android::PrintInstanceNameToString);
1484
Alec Mourif6c039a2023-10-06 23:02:17 +00001485GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsColorManagementCompositionTest);
1486INSTANTIATE_TEST_SUITE_P(PerInstance, GraphicsColorManagementCompositionTest,
1487 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1488 IComposer::descriptor)),
1489 // Only check sRGB, but verify that extended range
1490 // doesn't trigger any gamma shifts
1491 testing::Values(Dataspace::STANDARD_BT709),
1492 testing::Values(Dataspace::TRANSFER_SRGB),
1493 // Don't test limited range until we send YUV overlays
1494 testing::Values(Dataspace::RANGE_FULL,
1495 Dataspace::RANGE_EXTENDED)));
1496
ramindanibab8ba92021-11-18 01:24:11 +00001497} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001498} // namespace aidl::android::hardware::graphics::composer3::vts