blob: f81289a5d3a2c54a1afbc004c10240c6a6145761 [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>
Sally Qife454362024-12-18 15:44:09 -080023#include <cutils/ashmem.h>
ramindanibab8ba92021-11-18 01:24:11 +000024#include <gtest/gtest.h>
Alec Mouri51067012022-01-06 17:28:39 -080025#include <ui/DisplayId.h>
26#include <ui/DisplayIdentification.h>
ramindanibab8ba92021-11-18 01:24:11 +000027#include <ui/GraphicBuffer.h>
ramindanibab8ba92021-11-18 01:24:11 +000028#include <ui/PixelFormat.h>
29#include <ui/Rect.h>
ramindani458e53e2022-02-23 17:30:16 +000030#include "GraphicsComposerCallback.h"
31#include "ReadbackVts.h"
32#include "RenderEngineVts.h"
33#include "VtsComposerClient.h"
Alec Mouri51067012022-01-06 17:28:39 -080034
ramindanibab8ba92021-11-18 01:24:11 +000035namespace aidl::android::hardware::graphics::composer3::vts {
36namespace {
37
38using ::android::Rect;
39using common::Dataspace;
40using common::PixelFormat;
41
42class GraphicsCompositionTestBase : public ::testing::Test {
43 protected:
44 void SetUpBase(const std::string& name) {
ramindanidcecfd42022-02-03 23:52:19 +000045 mComposerClient = std::make_shared<VtsComposerClient>(name);
46 ASSERT_TRUE(mComposerClient->createClient().isOk());
ramindanibab8ba92021-11-18 01:24:11 +000047
ramindanidcecfd42022-02-03 23:52:19 +000048 const auto& [status, displays] = mComposerClient->getDisplays();
49 ASSERT_TRUE(status.isOk());
50 mDisplays = displays;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -040051 mWriter.reset(new ComposerClientWriter(getPrimaryDisplayId()));
ramindanibab8ba92021-11-18 01:24:11 +000052
53 setTestColorModes();
54
55 // explicitly disable vsync
ramindanidcecfd42022-02-03 23:52:19 +000056 for (const auto& display : mDisplays) {
57 EXPECT_TRUE(mComposerClient->setVsync(display.getDisplayId(), /*enable*/ false).isOk());
58 }
59 mComposerClient->setVsyncAllowed(/*isAllowed*/ false);
ramindanibab8ba92021-11-18 01:24:11 +000060
ramindanidcecfd42022-02-03 23:52:19 +000061 EXPECT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::ON).isOk());
ramindanibab8ba92021-11-18 01:24:11 +000062
Alec Mouri19e90fa2024-05-13 17:09:25 +000063 const auto format = getHasReadbackBuffer() ? mPixelFormat : common::PixelFormat::RGBA_8888;
64
ramindanibab8ba92021-11-18 01:24:11 +000065 ASSERT_NO_FATAL_FAILURE(
66 mTestRenderEngine = std::unique_ptr<TestRenderEngine>(new TestRenderEngine(
67 ::android::renderengine::RenderEngineCreationArgs::Builder()
Alec Mouri19e90fa2024-05-13 17:09:25 +000068 .setPixelFormat(static_cast<int>(format))
ramindanibab8ba92021-11-18 01:24:11 +000069 .setImageCacheSize(TestRenderEngine::sMaxFrameBufferAcquireBuffers)
ramindanibab8ba92021-11-18 01:24:11 +000070 .setEnableProtectedContext(false)
71 .setPrecacheToneMapperShaderOnly(false)
72 .setContextPriority(::android::renderengine::RenderEngine::
73 ContextPriority::HIGH)
74 .build())));
75
Alec Mourif6c039a2023-10-06 23:02:17 +000076 mClientCompositionDisplaySettings.physicalDisplay =
77 Rect(getDisplayWidth(), getDisplayHeight());
78 mClientCompositionDisplaySettings.clip = mClientCompositionDisplaySettings.physicalDisplay;
ramindanibab8ba92021-11-18 01:24:11 +000079
Brian Lindahle887a252023-01-17 14:54:19 -070080 mTestRenderEngine->initGraphicBuffer(
81 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
82 /*layerCount*/ 1U,
83 static_cast<uint64_t>(
84 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
85 static_cast<uint64_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
86 static_cast<uint64_t>(common::BufferUsage::GPU_RENDER_TARGET)));
Alec Mourif6c039a2023-10-06 23:02:17 +000087 mTestRenderEngine->setDisplaySettings(mClientCompositionDisplaySettings);
ramindanibab8ba92021-11-18 01:24:11 +000088 }
89
90 void TearDown() override {
Leon Scroggins III94f4b202024-01-09 11:43:45 -050091 ASSERT_FALSE(mDisplays.empty());
ramindanidcecfd42022-02-03 23:52:19 +000092 ASSERT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::OFF).isOk());
Ady Abrahama00d2462023-12-26 14:21:20 -080093 ASSERT_TRUE(mComposerClient->tearDown(mWriter.get()));
ramindanidcecfd42022-02-03 23:52:19 +000094 mComposerClient.reset();
Ady Abraham3192f3d2021-12-03 16:08:56 -080095 const auto errors = mReader.takeErrors();
96 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +000097 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
ramindanibab8ba92021-11-18 01:24:11 +000098 }
99
ramindanidcecfd42022-02-03 23:52:19 +0000100 const VtsDisplay& getPrimaryDisplay() const { return mDisplays[0]; }
101
102 int64_t getPrimaryDisplayId() const { return getPrimaryDisplay().getDisplayId(); }
103
104 int64_t getInvalidDisplayId() const { return mComposerClient->getInvalidDisplayId(); }
105
106 int32_t getDisplayWidth() const { return getPrimaryDisplay().getDisplayWidth(); }
107
108 int32_t getDisplayHeight() const { return getPrimaryDisplay().getDisplayHeight(); }
109
ramindanid5751092022-04-22 22:30:20 +0000110 void assertServiceSpecificError(const ScopedAStatus& status, int32_t serviceSpecificError) {
111 ASSERT_EQ(status.getExceptionCode(), EX_SERVICE_SPECIFIC);
112 ASSERT_EQ(status.getServiceSpecificError(), serviceSpecificError);
113 }
114
Brian Lindahle887a252023-01-17 14:54:19 -0700115 std::pair<bool, ::android::sp<::android::GraphicBuffer>> allocateBuffer(uint32_t usage) {
116 const auto width = static_cast<uint32_t>(getDisplayWidth());
117 const auto height = static_cast<uint32_t>(getDisplayHeight());
118
119 const auto& graphicBuffer = ::android::sp<::android::GraphicBuffer>::make(
120 width, height, ::android::PIXEL_FORMAT_RGBA_8888,
121 /*layerCount*/ 1u, usage, "VtsHalGraphicsComposer3_ReadbackTest");
ramindani0a2bee42022-02-10 01:27:42 +0000122
123 if (graphicBuffer && ::android::OK == graphicBuffer->initCheck()) {
Brian Lindahle887a252023-01-17 14:54:19 -0700124 return {true, graphicBuffer};
ramindani0a2bee42022-02-10 01:27:42 +0000125 }
Brian Lindahle887a252023-01-17 14:54:19 -0700126 return {false, graphicBuffer};
ramindanibab8ba92021-11-18 01:24:11 +0000127 }
128
ramindanibab8ba92021-11-18 01:24:11 +0000129 void writeLayers(const std::vector<std::shared_ptr<TestLayer>>& layers) {
ramindanidcecfd42022-02-03 23:52:19 +0000130 for (const auto& layer : layers) {
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400131 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000132 }
133 execute();
134 }
135
136 void execute() {
Huihong Luo651806f2023-04-21 18:48:48 +0000137 auto commands = mWriter->takePendingCommands();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800138 if (commands.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800139 return;
ramindanibab8ba92021-11-18 01:24:11 +0000140 }
141
ramindanidcecfd42022-02-03 23:52:19 +0000142 auto [status, results] = mComposerClient->executeCommands(commands);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800143 ASSERT_TRUE(status.isOk()) << "executeCommands failed " << status.getDescription();
ramindanibab8ba92021-11-18 01:24:11 +0000144
Ady Abraham46219f52021-12-20 09:44:31 -0800145 mReader.parse(std::move(results));
ramindanibab8ba92021-11-18 01:24:11 +0000146 }
147
ramindani44c952f2022-02-28 23:29:29 +0000148 bool getHasReadbackBuffer() {
ramindanidcecfd42022-02-03 23:52:19 +0000149 auto [status, readBackBufferAttributes] =
150 mComposerClient->getReadbackBufferAttributes(getPrimaryDisplayId());
151 if (status.isOk()) {
152 mPixelFormat = readBackBufferAttributes.format;
153 mDataspace = readBackBufferAttributes.dataspace;
ramindani44c952f2022-02-28 23:29:29 +0000154 return ReadbackHelper::readbackSupported(mPixelFormat, mDataspace);
ramindanidcecfd42022-02-03 23:52:19 +0000155 }
ramindanid5751092022-04-22 22:30:20 +0000156 EXPECT_NO_FATAL_FAILURE(
157 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
ramindani44c952f2022-02-28 23:29:29 +0000158 return false;
ramindanib27f33b2021-12-03 19:36:10 +0000159 }
160
ramindanidcecfd42022-02-03 23:52:19 +0000161 std::shared_ptr<VtsComposerClient> mComposerClient;
162 std::vector<VtsDisplay> mDisplays;
163 // use the slot count usually set by SF
ramindanibab8ba92021-11-18 01:24:11 +0000164 std::vector<ColorMode> mTestColorModes;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400165 std::unique_ptr<ComposerClientWriter> mWriter;
Ady Abraham91c9d1a2021-12-15 18:14:45 -0800166 ComposerClientReader mReader;
ramindanibab8ba92021-11-18 01:24:11 +0000167 std::unique_ptr<TestRenderEngine> mTestRenderEngine;
ramindanibab8ba92021-11-18 01:24:11 +0000168 common::PixelFormat mPixelFormat;
169 common::Dataspace mDataspace;
Alec Mourif6c039a2023-10-06 23:02:17 +0000170 ::android::renderengine::DisplaySettings mClientCompositionDisplaySettings;
ramindanibab8ba92021-11-18 01:24:11 +0000171
172 static constexpr uint32_t kClientTargetSlotCount = 64;
173
174 private:
ramindanibab8ba92021-11-18 01:24:11 +0000175 void setTestColorModes() {
176 mTestColorModes.clear();
ramindanidcecfd42022-02-03 23:52:19 +0000177 const auto& [status, modes] = mComposerClient->getColorModes(getPrimaryDisplayId());
178 ASSERT_TRUE(status.isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000179
180 for (ColorMode mode : modes) {
181 if (std::find(ReadbackHelper::colorModes.begin(), ReadbackHelper::colorModes.end(),
182 mode) != ReadbackHelper::colorModes.end()) {
183 mTestColorModes.push_back(mode);
184 }
185 }
186 }
187};
188
189class GraphicsCompositionTest : public GraphicsCompositionTestBase,
190 public testing::WithParamInterface<std::string> {
191 public:
192 void SetUp() override { SetUpBase(GetParam()); }
193};
194
195TEST_P(GraphicsCompositionTest, SingleSolidColorLayer) {
196 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000197 EXPECT_TRUE(mComposerClient
198 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
199 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000200
ramindani44c952f2022-02-28 23:29:29 +0000201 bool isSupported;
202 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000203 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000204 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
205 return;
206 }
207
Ady Abrahama00d2462023-12-26 14:21:20 -0800208 auto layer =
209 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000210 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000211 layer->setColor(BLUE);
212 layer->setDisplayFrame(coloredSquare);
213 layer->setZOrder(10);
214
215 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
216
217 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000218 std::vector<Color> expectedColors(
219 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
220 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000221
ramindanidcecfd42022-02-03 23:52:19 +0000222 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700223 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000224 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
225
226 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800227 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800228 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
229 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000230 execute();
231 // if hwc cannot handle and asks for composition change,
232 // just succeed the test
ramindanidcecfd42022-02-03 23:52:19 +0000233 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000234 GTEST_SUCCEED();
235 return;
236 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800237 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400238 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000239 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800240 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000241
242 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
243 mTestRenderEngine->setRenderLayers(layers);
244 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
245 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
246 }
247}
248
249TEST_P(GraphicsCompositionTest, SetLayerBuffer) {
250 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000251 EXPECT_TRUE(mComposerClient
252 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
253 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000254
ramindani44c952f2022-02-28 23:29:29 +0000255 bool isSupported;
256 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000257 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000258 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
259 return;
260 }
261
ramindanidcecfd42022-02-03 23:52:19 +0000262 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700263 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000264 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000265 std::vector<Color> expectedColors(
266 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
267 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
268 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
269 ReadbackHelper::fillColorsArea(
270 expectedColors, getDisplayWidth(),
271 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
272 ReadbackHelper::fillColorsArea(
273 expectedColors, getDisplayWidth(),
274 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000275
276 auto layer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000277 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -0800278 getDisplayHeight(), common::PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000279 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000280 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000281 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000282 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
283
284 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
285
286 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800287 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800288 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
289 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000290 execute();
291
ramindanidcecfd42022-02-03 23:52:19 +0000292 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000293 GTEST_SUCCEED();
294 return;
295 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800296 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000297
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400298 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000299 execute();
300
Ady Abraham3192f3d2021-12-03 16:08:56 -0800301 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000302
303 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
304 mTestRenderEngine->setRenderLayers(layers);
305 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
306 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
307 }
308}
309
310TEST_P(GraphicsCompositionTest, SetLayerBufferNoEffect) {
311 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000312 EXPECT_TRUE(mComposerClient
313 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
314 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000315
ramindani44c952f2022-02-28 23:29:29 +0000316 bool isSupported;
317 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000318 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000319 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
320 return;
321 }
322
Ady Abrahama00d2462023-12-26 14:21:20 -0800323 auto layer =
324 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000325 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000326 layer->setColor(BLUE);
327 layer->setDisplayFrame(coloredSquare);
328 layer->setZOrder(10);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400329 layer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000330
331 // This following buffer call should have no effect
Brian Lindahle887a252023-01-17 14:54:19 -0700332 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
333 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
334 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
335 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000336 const auto& buffer = graphicBuffer->handle;
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400337 mWriter->setLayerBuffer(getPrimaryDisplayId(), layer->getLayer(), /*slot*/ 0, buffer,
338 /*acquireFence*/ -1);
ramindanibab8ba92021-11-18 01:24:11 +0000339
340 // expected color for each pixel
ramindanidcecfd42022-02-03 23:52:19 +0000341 std::vector<Color> expectedColors(
342 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
343 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000344
ramindanidcecfd42022-02-03 23:52:19 +0000345 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700346 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000347 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
348
ramindanicdcfcaf2023-11-09 10:00:10 -0800349 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
350 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000351 execute();
352
ramindanidcecfd42022-02-03 23:52:19 +0000353 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000354 GTEST_SUCCEED();
355 return;
356 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800357 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400358 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000359 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800360 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000361
362 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
363 }
364}
365
ramindanib27f33b2021-12-03 19:36:10 +0000366TEST_P(GraphicsCompositionTest, SetReadbackBuffer) {
ramindani44c952f2022-02-28 23:29:29 +0000367 bool isSupported;
368 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000369 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000370 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
371 return;
372 }
373
ramindanidcecfd42022-02-03 23:52:19 +0000374 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700375 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanib27f33b2021-12-03 19:36:10 +0000376
377 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
378}
379
ramindanidcecfd42022-02-03 23:52:19 +0000380TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadDisplay) {
ramindani44c952f2022-02-28 23:29:29 +0000381 bool isSupported;
382 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000383 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000384 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
385 return;
386 }
387
Brian Lindahle887a252023-01-17 14:54:19 -0700388 const auto usage = static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
389 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN);
390 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(usage);
391 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000392 const auto& bufferHandle = graphicBuffer->handle;
ramindanib27f33b2021-12-03 19:36:10 +0000393 ::ndk::ScopedFileDescriptor fence = ::ndk::ScopedFileDescriptor(-1);
394
ramindanidcecfd42022-02-03 23:52:19 +0000395 const auto status =
396 mComposerClient->setReadbackBuffer(getInvalidDisplayId(), bufferHandle, fence);
ramindanib27f33b2021-12-03 19:36:10 +0000397
ramindanidcecfd42022-02-03 23:52:19 +0000398 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000399 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
ramindanib27f33b2021-12-03 19:36:10 +0000400}
401
ramindanidcecfd42022-02-03 23:52:19 +0000402TEST_P(GraphicsCompositionTest, SetReadbackBuffer_BadParameter) {
ramindani44c952f2022-02-28 23:29:29 +0000403 bool isSupported;
404 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000405 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000406 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
407 return;
408 }
409
ramindanidcecfd42022-02-03 23:52:19 +0000410 const native_handle_t bufferHandle{};
ramindanib27f33b2021-12-03 19:36:10 +0000411 ndk::ScopedFileDescriptor releaseFence = ndk::ScopedFileDescriptor(-1);
ramindanidcecfd42022-02-03 23:52:19 +0000412 const auto status =
413 mComposerClient->setReadbackBuffer(getPrimaryDisplayId(), &bufferHandle, releaseFence);
ramindanib27f33b2021-12-03 19:36:10 +0000414
ramindanidcecfd42022-02-03 23:52:19 +0000415 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000416 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
ramindanib27f33b2021-12-03 19:36:10 +0000417}
418
419TEST_P(GraphicsCompositionTest, GetReadbackBufferFenceInactive) {
ramindani44c952f2022-02-28 23:29:29 +0000420 bool isSupported;
421 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000422 if (!isSupported) {
ramindanib27f33b2021-12-03 19:36:10 +0000423 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
424 return;
425 }
426
ramindanidcecfd42022-02-03 23:52:19 +0000427 const auto& [status, releaseFence] =
428 mComposerClient->getReadbackBufferFence(getPrimaryDisplayId());
ramindanib27f33b2021-12-03 19:36:10 +0000429
ramindanidcecfd42022-02-03 23:52:19 +0000430 EXPECT_FALSE(status.isOk());
ramindanid5751092022-04-22 22:30:20 +0000431 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
Alec Mouri62ae37b2022-01-20 17:16:38 -0800432 EXPECT_EQ(-1, releaseFence.get());
ramindanib27f33b2021-12-03 19:36:10 +0000433}
434
ramindanibab8ba92021-11-18 01:24:11 +0000435TEST_P(GraphicsCompositionTest, ClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000436 EXPECT_TRUE(
437 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
438 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000439
440 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000441 EXPECT_TRUE(mComposerClient
442 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
ramindanibab8ba92021-11-18 01:24:11 +0000443 .isOk());
444
ramindani44c952f2022-02-28 23:29:29 +0000445 bool isSupported;
446 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000447 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000448 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
449 return;
450 }
451
ramindanidcecfd42022-02-03 23:52:19 +0000452 std::vector<Color> expectedColors(
453 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
454 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
455 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
456 ReadbackHelper::fillColorsArea(
457 expectedColors, getDisplayWidth(),
458 {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
459 ReadbackHelper::fillColorsArea(
460 expectedColors, getDisplayWidth(),
461 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000462
Ady Abrahama00d2462023-12-26 14:21:20 -0800463 auto layer = std::make_shared<TestBufferLayer>(
464 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
465 getDisplayHeight(), PixelFormat::RGBA_FP16, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000466 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000467 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000468 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000469
470 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
471
ramindanidcecfd42022-02-03 23:52:19 +0000472 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700473 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000474 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
475 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800476 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800477 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
478 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000479 execute();
480
ramindanidcecfd42022-02-03 23:52:19 +0000481 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800482 if (!changedCompositionTypes.empty()) {
Ady Abraham3192f3d2021-12-03 16:08:56 -0800483 ASSERT_EQ(1, changedCompositionTypes.size());
Ady Abraham46219f52021-12-20 09:44:31 -0800484 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
ramindanibab8ba92021-11-18 01:24:11 +0000485
486 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700487 auto clientUsage = static_cast<uint32_t>(
488 static_cast<uint32_t>(common::BufferUsage::CPU_READ_OFTEN) |
489 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
490 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000491 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000492 common::Rect damage{0, 0, getDisplayWidth(), getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000493
494 // create client target buffer
Brian Lindahle887a252023-01-17 14:54:19 -0700495 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
496 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000497 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000498 void* clientBufData;
ramindani0a2bee42022-02-10 01:27:42 +0000499 const auto stride = static_cast<uint32_t>(graphicBuffer->stride);
Alec Mouri6a000222024-08-16 23:08:09 +0000500 int bytesPerPixel = -1;
501 int bytesPerStride = -1;
502 graphicBuffer->lock(clientUsage, layer->getAccessRegion(), &clientBufData,
503 &bytesPerPixel, &bytesPerStride);
ramindanibab8ba92021-11-18 01:24:11 +0000504
Alec Mouri6a000222024-08-16 23:08:09 +0000505 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
506 layer->getWidth(), layer->getHeight(), stride, bytesPerPixel, clientBufData,
507 clientFormat, expectedColors));
ramindanib1144212022-02-10 01:51:24 +0000508 int32_t clientFence;
509 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
510 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400511 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
Alec Mouri8062f1f2023-09-06 02:14:47 +0000512 clientDataspace, std::vector<common::Rect>(1, damage), 1.f);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400513 layer->setToClientComposition(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800514 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
515 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000516 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000517 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800518 ASSERT_TRUE(changedCompositionTypes.empty());
ramindanibab8ba92021-11-18 01:24:11 +0000519 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800520 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000521
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400522 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000523 execute();
524
Ady Abraham3192f3d2021-12-03 16:08:56 -0800525 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000526
527 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
528 }
529}
530
Sally Qife454362024-12-18 15:44:09 -0800531void generateLuts(Luts* luts, LutProperties::Dimension dimension, int32_t size,
532 LutProperties::SamplingKey key) {
533 size_t bufferSize = dimension == LutProperties::Dimension::ONE_D
534 ? static_cast<size_t>(size) * sizeof(float)
535 : static_cast<size_t>(size * size * size) * sizeof(float);
536 int32_t fd = ashmem_create_region("lut_shared_mem", bufferSize);
537 void* ptr = mmap(nullptr, bufferSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
538 std::vector<float> buffers(static_cast<size_t>(size), 0.5f);
539 memcpy(ptr, buffers.data(), bufferSize);
540 munmap(ptr, bufferSize);
541 luts->pfd = ndk::ScopedFileDescriptor(fd);
542 luts->offsets = std::vector<int32_t>{0};
543 luts->lutProperties = {LutProperties{dimension, size, {key}}};
544}
545
546TEST_P(GraphicsCompositionTest, Luts) {
547 ASSERT_TRUE(
548 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
549 .isOk());
550 const auto& [status, properties] = mComposerClient->getOverlaySupport();
551 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
552 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
553 GTEST_SKIP() << "getOverlaySupport is not supported";
554 return;
555 }
556
557 if (!properties.lutProperties) {
558 GTEST_SKIP() << "lutProperties is not supported";
559 return;
560 }
561
562 for (const auto& lutProperties : *properties.lutProperties) {
563 if (!lutProperties) {
564 continue;
565 }
566 auto& l = *lutProperties;
567
568 for (const auto& key : l.samplingKeys) {
569 for (ColorMode mode : mTestColorModes) {
570 EXPECT_TRUE(mComposerClient
571 ->setColorMode(getPrimaryDisplayId(), mode,
572 RenderIntent::COLORIMETRIC)
573 .isOk());
574
575 bool isSupported;
576 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
577 if (!isSupported) {
578 GTEST_SUCCEED()
579 << "Readback not supported or unsupported pixelFormat/dataspace";
580 return;
581 }
582
583 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
584
585 // expected color for each pixel
586 std::vector<Color> expectedColors(
587 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
588 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare,
589 WHITE);
590
591 auto layer = std::make_shared<TestBufferLayer>(
592 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(),
593 getDisplayWidth(), getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
594 layer->setDisplayFrame(coloredSquare);
595 layer->setZOrder(10);
596 layer->setDataspace(Dataspace::SRGB);
597
598 Luts luts;
599 generateLuts(&luts, l.dimension, l.size, key);
600 layer->setLuts(std::move(luts));
601
602 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
603
604 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
605
606 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient,
607 getDisplayWidth(), getDisplayHeight(), mPixelFormat,
608 mDataspace);
609 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
610
611 writeLayers(layers);
612 ASSERT_TRUE(mReader.takeErrors().empty());
613 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
614 VtsComposerClient::kNoFrameIntervalNs);
615 execute();
616 // if hwc cannot handle and asks for composition change,
617 // just succeed the test
618 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
619 GTEST_SUCCEED();
620 return;
621 }
622
623 auto changedCompositionTypes =
624 mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
625 ASSERT_TRUE(changedCompositionTypes.empty());
626
627 mWriter->presentDisplay(getPrimaryDisplayId());
628 execute();
629 ASSERT_TRUE(mReader.takeErrors().empty());
630
631 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare,
632 {188.f / 255.f, 188.f / 255.f, 188.f / 255.f, 1.0f});
633
634 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
635 mTestRenderEngine->setRenderLayers(layers);
636 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
637 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
638 }
639 }
640 }
641}
642
Sally Qi0ca29272024-02-23 11:07:08 -0800643TEST_P(GraphicsCompositionTest, MixedColorSpaces) {
644 ASSERT_TRUE(
645 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
646 .isOk());
647 const auto& [status, properties] = mComposerClient->getOverlaySupport();
648 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
649 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
650 GTEST_SUCCEED() << "getOverlaySupport is not supported";
651 return;
652 }
653
654 if (properties.supportMixedColorSpaces == false) {
655 GTEST_SUCCEED() << "supportMixedColorSpaces is not supported";
656 return;
657 }
658
659 for (ColorMode mode : mTestColorModes) {
660 EXPECT_TRUE(mComposerClient
661 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
662 .isOk());
663
664 bool isSupported;
665 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
666 if (!isSupported) {
667 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
668 return;
669 }
670
671 // sRGB layer
672 auto srgbLayer = std::make_shared<TestBufferLayer>(
673 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
674 getDisplayHeight() / 2, PixelFormat::RGBA_8888, *mWriter);
675 std::vector<Color> sRgbDeviceColors(srgbLayer->getWidth() * srgbLayer->getHeight());
676 ReadbackHelper::fillColorsArea(sRgbDeviceColors, getDisplayWidth(),
677 {0, 0, static_cast<int32_t>(srgbLayer->getWidth()),
678 static_cast<int32_t>(srgbLayer->getHeight())},
679 GREEN);
680 srgbLayer->setDisplayFrame({0, 0, static_cast<int32_t>(srgbLayer->getWidth()),
681 static_cast<int32_t>(srgbLayer->getHeight())});
682 srgbLayer->setZOrder(10);
683 srgbLayer->setDataspace(Dataspace::SRGB);
684 ASSERT_NO_FATAL_FAILURE(srgbLayer->setBuffer(sRgbDeviceColors));
685
686 // display P3 layer
687 auto displayP3Layer = std::make_shared<TestBufferLayer>(
688 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
689 getDisplayHeight() / 2, PixelFormat::RGBA_8888, *mWriter);
690 std::vector<Color> displayP3DeviceColors(
691 static_cast<size_t>(displayP3Layer->getWidth() * displayP3Layer->getHeight()));
692 ReadbackHelper::fillColorsArea(displayP3DeviceColors, getDisplayWidth(),
693 {0, 0, static_cast<int32_t>(displayP3Layer->getWidth()),
694 static_cast<int32_t>(displayP3Layer->getHeight())},
695 RED);
696 displayP3Layer->setDisplayFrame(
697 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()});
698 displayP3Layer->setZOrder(10);
699 displayP3Layer->setDataspace(Dataspace::DISPLAY_P3);
700 ASSERT_NO_FATAL_FAILURE(displayP3Layer->setBuffer(displayP3DeviceColors));
701
702 writeLayers({srgbLayer, displayP3Layer});
703
704 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
705 VtsComposerClient::kNoFrameIntervalNs);
706 execute();
707
708 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
709 ASSERT_TRUE(changedCompositionTypes.empty());
710
711 mWriter->presentDisplay(getPrimaryDisplayId());
712 execute();
713
714 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
715 ASSERT_TRUE(changedCompositionTypes.empty());
716 ASSERT_TRUE(mReader.takeErrors().empty());
717 }
718}
719
ramindanibab8ba92021-11-18 01:24:11 +0000720TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000721 ASSERT_TRUE(
722 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
723 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000724
725 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000726 EXPECT_TRUE(mComposerClient
727 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
728 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000729
ramindani44c952f2022-02-28 23:29:29 +0000730 bool isSupported;
731 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000732 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000733 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
734 return;
735 }
736
ramindanidcecfd42022-02-03 23:52:19 +0000737 std::vector<Color> expectedColors(
738 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
739 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
740 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
741 ReadbackHelper::fillColorsArea(
742 expectedColors, getDisplayWidth(),
743 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000744
ramindanidcecfd42022-02-03 23:52:19 +0000745 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700746 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000747 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
748
749 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000750 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -0800751 getDisplayHeight() / 2, PixelFormat::RGBA_8888, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000752 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
753 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
754 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
755 static_cast<int32_t>(deviceLayer->getHeight())},
756 GREEN);
757 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
758 static_cast<int32_t>(deviceLayer->getHeight())});
759 deviceLayer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000760 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000761 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400762 deviceLayer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000763
764 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700765 auto clientUsage = static_cast<uint32_t>(
766 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
767 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
768 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000769 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000770 int32_t clientWidth = getDisplayWidth();
771 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000772
773 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000774 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
Ady Abrahama00d2462023-12-26 14:21:20 -0800775 clientHeight, PixelFormat::RGBA_FP16, *mWriter, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000776 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
777 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000778 clientLayer->setDisplayFrame(clientFrame);
779 clientLayer->setZOrder(0);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400780 clientLayer->write(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800781 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
782 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000783 execute();
784
ramindanidcecfd42022-02-03 23:52:19 +0000785 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800786 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000787 continue;
788 }
789 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800790 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
Brian Lindahle887a252023-01-17 14:54:19 -0700791 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
792 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000793 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000794
795 void* clientBufData;
Alec Mouri6a000222024-08-16 23:08:09 +0000796 int bytesPerPixel = -1;
797 int bytesPerStride = -1;
ramindani0a2bee42022-02-10 01:27:42 +0000798 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
Alec Mouri6a000222024-08-16 23:08:09 +0000799 &clientBufData, &bytesPerPixel, &bytesPerStride);
ramindanibab8ba92021-11-18 01:24:11 +0000800
ramindanidcecfd42022-02-03 23:52:19 +0000801 std::vector<Color> clientColors(
802 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
803 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000804 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000805 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
Alec Mouri6a000222024-08-16 23:08:09 +0000806 graphicBuffer->getStride(), bytesPerPixel, clientBufData, clientFormat,
807 clientColors));
ramindanib1144212022-02-10 01:51:24 +0000808 int32_t clientFence;
809 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
810 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400811 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
Alec Mouri8062f1f2023-09-06 02:14:47 +0000812 clientDataspace, std::vector<common::Rect>(1, clientFrame), 1.f);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400813 clientLayer->setToClientComposition(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800814 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
815 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000816 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000817 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800818 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800819 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000820
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400821 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000822 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800823 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000824 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
825 }
826}
827
828TEST_P(GraphicsCompositionTest, SetLayerDamage) {
829 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000830 EXPECT_TRUE(mComposerClient
831 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
832 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000833
ramindani44c952f2022-02-28 23:29:29 +0000834 bool isSupported;
835 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000836 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000837 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
838 return;
839 }
840
ramindanidcecfd42022-02-03 23:52:19 +0000841 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000842
ramindanidcecfd42022-02-03 23:52:19 +0000843 std::vector<Color> expectedColors(
844 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
845 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000846
Ady Abrahama00d2462023-12-26 14:21:20 -0800847 auto layer = std::make_shared<TestBufferLayer>(
848 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
849 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000850 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000851 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000852 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000853 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
854
855 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
856
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 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800870 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400871 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000872 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800873 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000874
875 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
876
877 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +0000878 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
879 getDisplayHeight() / 2};
880 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
881 getDisplayWidth());
882 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000883
884 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
885 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +0000886 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +0000887
888 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
889
890 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800891 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800892 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
893 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000894 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800895 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000896 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400897 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000898 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800899 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000900
901 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
902 }
903}
904
905TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
906 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000907 EXPECT_TRUE(mComposerClient
908 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
909 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000910
ramindani44c952f2022-02-28 23:29:29 +0000911 bool isSupported;
912 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000913 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000914 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
915 return;
916 }
917
Ady Abrahama00d2462023-12-26 14:21:20 -0800918 auto layer =
919 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000920 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +0000921 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000922 layer->setZOrder(10);
923 layer->setAlpha(0);
924 layer->setBlendMode(BlendMode::PREMULTIPLIED);
925
926 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
927
ramindanidcecfd42022-02-03 23:52:19 +0000928 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700929 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000930
931 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
932
933 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800934 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800935 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
936 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000937 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000938 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000939 GTEST_SUCCEED();
940 return;
941 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800942 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000943
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400944 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000945 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800946 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000947
ramindanidcecfd42022-02-03 23:52:19 +0000948 std::vector<Color> expectedColors(
949 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000950
951 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
952 mTestRenderEngine->setRenderLayers(layers);
953 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
954 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
955 }
956}
957
958TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
959 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000960 EXPECT_TRUE(mComposerClient
961 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
962 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000963
ramindani44c952f2022-02-28 23:29:29 +0000964 bool isSupported;
965 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000966 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000967 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
968 return;
969 }
970
ramindanidcecfd42022-02-03 23:52:19 +0000971 std::vector<Color> expectedColors(
972 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
973 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
974 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
975 ReadbackHelper::fillColorsArea(
976 expectedColors, getDisplayWidth(),
977 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000978
Ady Abrahama00d2462023-12-26 14:21:20 -0800979 auto layer = std::make_shared<TestBufferLayer>(
980 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
981 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000982 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000983 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000984 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanidcecfd42022-02-03 23:52:19 +0000985 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
986 static_cast<float>(getDisplayWidth()),
987 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +0000988 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
989
990 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
991
992 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +0000993 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
994 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
995 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700996 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000997 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
998 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800999 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001000 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1001 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001002 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001003 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001004 GTEST_SUCCEED();
1005 return;
1006 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001007 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001008 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001009 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001010 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001011 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1012 mTestRenderEngine->setRenderLayers(layers);
1013 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1014 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1015 }
1016}
1017
1018TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
1019 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001020 EXPECT_TRUE(mComposerClient
1021 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1022 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001023
ramindani44c952f2022-02-28 23:29:29 +00001024 bool isSupported;
1025 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001026 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001027 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1028 return;
1029 }
1030
ramindanidcecfd42022-02-03 23:52:19 +00001031 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
1032 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
Ady Abrahama00d2462023-12-26 14:21:20 -08001033 auto redLayer =
1034 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001035 redLayer->setColor(RED);
1036 redLayer->setDisplayFrame(redRect);
1037
Ady Abrahama00d2462023-12-26 14:21:20 -08001038 auto blueLayer =
1039 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001040 blueLayer->setColor(BLUE);
1041 blueLayer->setDisplayFrame(blueRect);
1042 blueLayer->setZOrder(5);
1043
1044 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +00001045 std::vector<Color> expectedColors(
1046 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001047
1048 // red in front of blue
1049 redLayer->setZOrder(10);
1050
1051 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +00001052 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
1053 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +00001054
ramindanidcecfd42022-02-03 23:52:19 +00001055 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001056 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001057 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1058
1059 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001060 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001061 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1062 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001063 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001064 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001065 GTEST_SUCCEED();
1066 return;
1067 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001068 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001069 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001070 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001071
1072 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1073
1074 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +00001075 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1076 getDisplayWidth());
1077 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
1078 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +00001079
1080 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1081
1082 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001083 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001084 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1085 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001086 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001087 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -08001088 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001089 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001090 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001091 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001092
1093 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1094 mTestRenderEngine->setRenderLayers(layers);
1095 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1096 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1097 }
1098}
1099
Alec Mourib1f16722022-02-07 13:03:44 -08001100TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
Alec Mouri51067012022-01-06 17:28:39 -08001101 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001102 EXPECT_TRUE(mComposerClient
1103 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1104 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -08001105
ramindani44c952f2022-02-28 23:29:29 +00001106 bool isSupported;
1107 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001108 if (!isSupported) {
Alec Mouri51067012022-01-06 17:28:39 -08001109 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
1110 "color mode: "
1111 << toString(mode);
1112 continue;
1113 }
ramindanidcecfd42022-02-03 23:52:19 +00001114 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
1115 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
1116 getDisplayHeight()};
Alec Mouri712b3d92023-09-29 00:21:37 +00001117
1118 static constexpr float kMaxBrightnessNits = 300.f;
1119
ramindanidcecfd42022-02-03 23:52:19 +00001120 const auto redLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001121 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Alec Mouri51067012022-01-06 17:28:39 -08001122 redLayer->setColor(RED);
1123 redLayer->setDisplayFrame(redRect);
Alec Mouri712b3d92023-09-29 00:21:37 +00001124 redLayer->setWhitePointNits(kMaxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -08001125 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -08001126
1127 const auto dimmerRedLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001128 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Alec Mouri51067012022-01-06 17:28:39 -08001129 dimmerRedLayer->setColor(RED);
1130 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
1131 // Intentionally use a small dimming ratio as some implementations may be more likely to
1132 // kick into GPU composition to apply dithering when the dimming ratio is high.
1133 static constexpr float kDimmingRatio = 0.9f;
Alec Mouri712b3d92023-09-29 00:21:37 +00001134 dimmerRedLayer->setWhitePointNits(kMaxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -08001135 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -08001136
1137 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +00001138 std::vector<Color> expectedColors(
1139 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -08001140
ramindanidcecfd42022-02-03 23:52:19 +00001141 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
1142 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -08001143
ramindanidcecfd42022-02-03 23:52:19 +00001144 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001145 getDisplayHeight(), mPixelFormat, mDataspace);
Alec Mouri51067012022-01-06 17:28:39 -08001146 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1147
1148 writeLayers(layers);
1149 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001150 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1151 VtsComposerClient::kNoFrameIntervalNs);
Alec Mouri51067012022-01-06 17:28:39 -08001152 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001153 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -08001154 GTEST_SUCCEED()
1155 << "Readback verification not supported for GPU composition for color mode: "
1156 << toString(mode);
1157 continue;
1158 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001159 mWriter->presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001160 execute();
1161 ASSERT_TRUE(mReader.takeErrors().empty());
1162
1163 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1164 mTestRenderEngine->setRenderLayers(layers);
1165 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1166 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1167 }
1168}
1169
ramindanibab8ba92021-11-18 01:24:11 +00001170class GraphicsBlendModeCompositionTest
1171 : public GraphicsCompositionTestBase,
1172 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
1173 public:
1174 void SetUp() override {
1175 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +00001176 // TODO(b/219590743) we should remove the below SRGB color mode
1177 // once we have the BlendMode test fix for all the versions of the ColorMode
ramindania4e76362022-03-02 01:48:06 +00001178 mTestColorModes.erase(
1179 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
1180 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
1181 mTestColorModes.end());
ramindanibab8ba92021-11-18 01:24:11 +00001182 mBackgroundColor = BLACK;
1183 mTopLayerColor = RED;
1184 }
1185
1186 void setBackgroundColor(Color color) { mBackgroundColor = color; }
1187
1188 void setTopLayerColor(Color color) { mTopLayerColor = color; }
1189
1190 void setUpLayers(BlendMode blendMode) {
1191 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +00001192 std::vector<Color> topLayerPixelColors(
1193 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1194 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
1195 {0, 0, getDisplayWidth(), getDisplayHeight()},
1196 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +00001197
ramindanidcecfd42022-02-03 23:52:19 +00001198 auto backgroundLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001199 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +00001200 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001201 backgroundLayer->setZOrder(0);
1202 backgroundLayer->setColor(mBackgroundColor);
1203
Ady Abrahama00d2462023-12-26 14:21:20 -08001204 auto layer = std::make_shared<TestBufferLayer>(
1205 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
1206 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +00001207 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001208 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +00001209 layer->setDataspace(Dataspace::UNKNOWN);
ramindanibab8ba92021-11-18 01:24:11 +00001210 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
1211
1212 layer->setBlendMode(blendMode);
1213 layer->setAlpha(std::stof(std::get<1>(GetParam())));
1214
1215 mLayers.push_back(backgroundLayer);
1216 mLayers.push_back(layer);
1217 }
1218
1219 void setExpectedColors(std::vector<Color>& expectedColors) {
1220 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001221 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1222 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001223
1224 auto layer = mLayers[1];
1225 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001226 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001227 if (blendMode == BlendMode::NONE) {
1228 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001229 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1230 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1231 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1232 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001233 }
1234 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1235 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001236 expectedColor.r =
1237 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1238 expectedColor.g =
1239 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1240 expectedColor.b =
1241 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1242 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001243 }
1244 } else if (blendMode == BlendMode::COVERAGE) {
1245 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001246 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1247 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1248 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1249 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001250 }
1251 }
1252 }
1253
1254 protected:
1255 std::vector<std::shared_ptr<TestLayer>> mLayers;
1256 Color mBackgroundColor;
1257 Color mTopLayerColor;
1258};
ramindanic7585d92022-04-15 18:30:41 +00001259
1260TEST_P(GraphicsBlendModeCompositionTest, None) {
ramindanibab8ba92021-11-18 01:24:11 +00001261 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001262 EXPECT_TRUE(mComposerClient
1263 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1264 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001265
ramindani44c952f2022-02-28 23:29:29 +00001266 bool isSupported;
1267 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001268 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001269 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1270 return;
1271 }
1272
ramindanidcecfd42022-02-03 23:52:19 +00001273 std::vector<Color> expectedColors(
1274 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001275
1276 setBackgroundColor(BLACK);
1277 setTopLayerColor(TRANSLUCENT_RED);
1278 setUpLayers(BlendMode::NONE);
1279 setExpectedColors(expectedColors);
1280
ramindanidcecfd42022-02-03 23:52:19 +00001281 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001282 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001283 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1284 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001285 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001286 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1287 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001288 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001289 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001290 GTEST_SUCCEED();
1291 return;
1292 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001293 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001294 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001295 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001296 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001297
1298 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1299 mTestRenderEngine->setRenderLayers(mLayers);
1300 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1301 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1302 }
1303}
1304
ramindani07e6f842022-02-15 15:28:33 +00001305TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001306 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001307 EXPECT_TRUE(mComposerClient
1308 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1309 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001310
ramindani44c952f2022-02-28 23:29:29 +00001311 bool isSupported;
1312 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001313 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001314 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1315 return;
1316 }
1317
ramindanidcecfd42022-02-03 23:52:19 +00001318 std::vector<Color> expectedColors(
1319 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001320
1321 setBackgroundColor(BLACK);
1322 setTopLayerColor(TRANSLUCENT_RED);
1323
1324 setUpLayers(BlendMode::COVERAGE);
1325 setExpectedColors(expectedColors);
1326
ramindanidcecfd42022-02-03 23:52:19 +00001327 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001328 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001329 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1330 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001331 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001332 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1333 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001334 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001335 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001336 GTEST_SUCCEED();
1337 return;
1338 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001339 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001340 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001341 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001342 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001343 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1344 }
1345}
1346
1347TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1348 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001349 EXPECT_TRUE(mComposerClient
1350 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1351 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001352
ramindani44c952f2022-02-28 23:29:29 +00001353 bool isSupported;
1354 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001355 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001356 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1357 return;
1358 }
ramindanibab8ba92021-11-18 01:24:11 +00001359
ramindanidcecfd42022-02-03 23:52:19 +00001360 std::vector<Color> expectedColors(
1361 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001362
1363 setBackgroundColor(BLACK);
1364 setTopLayerColor(TRANSLUCENT_RED);
1365 setUpLayers(BlendMode::PREMULTIPLIED);
1366 setExpectedColors(expectedColors);
1367
ramindanidcecfd42022-02-03 23:52:19 +00001368 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001369 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001370 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1371 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001372 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001373 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1374 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001375 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001376 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001377 GTEST_SUCCEED();
1378 return;
1379 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001380 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001381 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001382 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001383 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001384 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1385 mTestRenderEngine->setRenderLayers(mLayers);
1386 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1387 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1388 }
1389}
1390
1391class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1392 protected:
1393 void SetUp() override {
1394 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001395
ramindanidcecfd42022-02-03 23:52:19 +00001396 auto backgroundLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001397 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001398 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001399 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001400 backgroundLayer->setZOrder(0);
1401
ramindanidcecfd42022-02-03 23:52:19 +00001402 mSideLength =
1403 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001404 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1405 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1406
ramindani0a2bee42022-02-10 01:27:42 +00001407 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1408 getPrimaryDisplayId(), mSideLength, mSideLength,
Ady Abrahama00d2462023-12-26 14:21:20 -08001409 PixelFormat::RGBA_8888, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001410 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1411 mLayer->setZOrder(10);
1412
1413 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1414 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1415 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1416 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1417 mLayers = {backgroundLayer, mLayer};
1418 }
1419
1420 protected:
1421 std::shared_ptr<TestBufferLayer> mLayer;
1422 std::vector<std::shared_ptr<TestLayer>> mLayers;
1423 int mSideLength;
1424};
1425
1426TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1427 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001428 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1429 RenderIntent::COLORIMETRIC);
ramindanid5751092022-04-22 22:30:20 +00001430 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
ramindanidcecfd42022-02-03 23:52:19 +00001431 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1432 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001433 SUCCEED() << "ColorMode not supported, skip test";
1434 return;
1435 }
1436
ramindani44c952f2022-02-28 23:29:29 +00001437 bool isSupported;
1438 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001439 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001440 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1441 return;
1442 }
ramindanidcecfd42022-02-03 23:52:19 +00001443 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001444 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001445 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1446 mLayer->setTransform(Transform::FLIP_H);
Alec Mourif6c039a2023-10-06 23:02:17 +00001447 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001448
ramindanidcecfd42022-02-03 23:52:19 +00001449 std::vector<Color> expectedColors(
1450 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1451 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001452 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001453 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001454 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1455
1456 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001457 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001458 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1459 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001460 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001461 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001462 GTEST_SUCCEED();
1463 return;
1464 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001465 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001466 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001467 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001468 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001469
1470 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1471 mTestRenderEngine->setRenderLayers(mLayers);
1472 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1473 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1474 }
1475}
1476
1477TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1478 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001479 EXPECT_TRUE(mComposerClient
1480 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1481 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001482
ramindani44c952f2022-02-28 23:29:29 +00001483 bool isSupported;
1484 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001485 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001486 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1487 return;
1488 }
ramindanidcecfd42022-02-03 23:52:19 +00001489 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001490 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001491 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1492
1493 mLayer->setTransform(Transform::FLIP_V);
Alec Mourif6c039a2023-10-06 23:02:17 +00001494 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001495
ramindanidcecfd42022-02-03 23:52:19 +00001496 std::vector<Color> expectedColors(
1497 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1498 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001499 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001500 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001501 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1502
1503 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001504 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001505 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1506 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001507 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001508 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001509 GTEST_SUCCEED();
1510 return;
1511 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001512 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001513 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001514 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001515 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001516 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1517 mTestRenderEngine->setRenderLayers(mLayers);
1518 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1519 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1520 }
1521}
1522
1523TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1524 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001525 EXPECT_TRUE(mComposerClient
1526 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1527 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001528
ramindani44c952f2022-02-28 23:29:29 +00001529 bool isSupported;
1530 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001531 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001532 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1533 return;
1534 }
ramindanidcecfd42022-02-03 23:52:19 +00001535 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001536 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001537 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1538
1539 mLayer->setTransform(Transform::ROT_180);
Alec Mourif6c039a2023-10-06 23:02:17 +00001540 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001541
ramindanidcecfd42022-02-03 23:52:19 +00001542 std::vector<Color> expectedColors(
1543 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1544 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001545 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1546 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001547 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001548 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1549
1550 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001551 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001552 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1553 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001554 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001555 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001556 GTEST_SUCCEED();
1557 return;
1558 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001559 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001560 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001561 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001562 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001563 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1564 mTestRenderEngine->setRenderLayers(mLayers);
1565 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1566 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1567 }
1568}
1569
Alec Mourif6c039a2023-10-06 23:02:17 +00001570class GraphicsColorManagementCompositionTest
1571 : public GraphicsCompositionTestBase,
1572 public testing::WithParamInterface<std::tuple<std::string, Dataspace, Dataspace, Dataspace>> {
1573 public:
1574 void SetUp() override {
1575 SetUpBase(std::get<0>(GetParam()));
1576 // for some reason only sRGB reliably works
1577 mTestColorModes.erase(
1578 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
1579 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
1580 mTestColorModes.end());
1581 auto standard = std::get<1>(GetParam());
1582 auto transfer = std::get<2>(GetParam());
1583 auto range = std::get<3>(GetParam());
1584
1585 mLayerDataspace = static_cast<Dataspace>(static_cast<int32_t>(standard) |
1586 static_cast<int32_t>(transfer) |
1587 static_cast<int32_t>(range));
1588 ALOGD("Invoking test for dataspace: {%s, %s, %s}", toString(standard).c_str(),
1589 toString(transfer).c_str(), toString(range).c_str());
1590 }
1591
1592 void makeLayer() {
1593 mLayer = std::make_shared<TestBufferLayer>(
1594 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -08001595 getDisplayHeight(), common::PixelFormat::RGBA_8888, *mWriter);
Alec Mourif6c039a2023-10-06 23:02:17 +00001596 mLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
1597 mLayer->setZOrder(10);
1598 mLayer->setAlpha(1.f);
1599 mLayer->setDataspace(mLayerDataspace);
1600 }
1601
1602 void fillColor(Color color) {
1603 std::vector<Color> baseColors(static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1604 ReadbackHelper::fillColorsArea(baseColors, getDisplayWidth(),
1605 common::Rect{.left = 0,
1606 .top = 0,
1607 .right = getDisplayWidth(),
1608 .bottom = getDisplayHeight()},
1609 color);
1610 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1611 }
1612
1613 Dataspace mLayerDataspace;
1614 std::shared_ptr<TestBufferLayer> mLayer;
1615};
1616
1617TEST_P(GraphicsColorManagementCompositionTest, ColorConversion) {
1618 for (ColorMode mode : mTestColorModes) {
1619 EXPECT_TRUE(mComposerClient
1620 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1621 .isOk());
1622
1623 bool isSupported;
1624 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
1625 if (!isSupported) {
1626 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1627 return;
1628 }
1629
1630 mClientCompositionDisplaySettings.outputDataspace =
1631 static_cast<::android::ui::Dataspace>(mDataspace);
1632 mTestRenderEngine->setDisplaySettings(mClientCompositionDisplaySettings);
1633
1634 makeLayer();
1635 for (auto color : {LIGHT_RED, LIGHT_GREEN, LIGHT_BLUE}) {
1636 ALOGD("Testing color: %f, %f, %f, %f with color mode: %d", color.r, color.g, color.b,
1637 color.a, mode);
1638 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1639 getDisplayHeight(), mPixelFormat, mDataspace);
1640 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1641 fillColor(color);
1642 writeLayers({mLayer});
1643 EXPECT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::ON).isOk());
1644
1645 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001646 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1647 VtsComposerClient::kNoFrameIntervalNs);
Alec Mourif6c039a2023-10-06 23:02:17 +00001648 execute();
1649 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
1650 continue;
1651 }
1652 ASSERT_TRUE(mReader.takeErrors().empty());
1653 mWriter->presentDisplay(getPrimaryDisplayId());
1654 execute();
1655 ASSERT_TRUE(mReader.takeErrors().empty());
1656
1657 mTestRenderEngine->setRenderLayers({mLayer});
1658 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1659 ASSERT_NO_FATAL_FAILURE(
1660 mTestRenderEngine->checkColorBuffer(readbackBuffer.getBuffer()));
1661 }
1662 }
1663}
1664
ramindanibab8ba92021-11-18 01:24:11 +00001665GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1666INSTANTIATE_TEST_SUITE_P(
1667 PerInstance, GraphicsCompositionTest,
1668 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1669 ::android::PrintInstanceNameToString);
1670
1671GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1672INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1673 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1674 IComposer::descriptor)),
1675 testing::Values("0.2", "1.0")));
1676
1677GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1678INSTANTIATE_TEST_SUITE_P(
1679 PerInstance, GraphicsTransformCompositionTest,
1680 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1681 ::android::PrintInstanceNameToString);
1682
Alec Mourif6c039a2023-10-06 23:02:17 +00001683GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsColorManagementCompositionTest);
1684INSTANTIATE_TEST_SUITE_P(PerInstance, GraphicsColorManagementCompositionTest,
1685 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1686 IComposer::descriptor)),
1687 // Only check sRGB, but verify that extended range
1688 // doesn't trigger any gamma shifts
1689 testing::Values(Dataspace::STANDARD_BT709),
1690 testing::Values(Dataspace::TRANSFER_SRGB),
1691 // Don't test limited range until we send YUV overlays
1692 testing::Values(Dataspace::RANGE_FULL,
1693 Dataspace::RANGE_EXTENDED)));
1694
ramindanibab8ba92021-11-18 01:24:11 +00001695} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001696} // namespace aidl::android::hardware::graphics::composer3::vts