blob: 350309aaa978b8f47fbc3a660ff114c11843f670 [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
Sally Qi0ec8e4a2025-01-08 10:58:32 -0800546// @VsrTest = 4.4-016
Sally Qife454362024-12-18 15:44:09 -0800547TEST_P(GraphicsCompositionTest, Luts) {
548 ASSERT_TRUE(
549 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
550 .isOk());
551 const auto& [status, properties] = mComposerClient->getOverlaySupport();
552 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
553 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
554 GTEST_SKIP() << "getOverlaySupport is not supported";
555 return;
556 }
557
558 if (!properties.lutProperties) {
559 GTEST_SKIP() << "lutProperties is not supported";
560 return;
561 }
562
563 for (const auto& lutProperties : *properties.lutProperties) {
564 if (!lutProperties) {
565 continue;
566 }
567 auto& l = *lutProperties;
568
569 for (const auto& key : l.samplingKeys) {
570 for (ColorMode mode : mTestColorModes) {
571 EXPECT_TRUE(mComposerClient
572 ->setColorMode(getPrimaryDisplayId(), mode,
573 RenderIntent::COLORIMETRIC)
574 .isOk());
575
576 bool isSupported;
577 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
578 if (!isSupported) {
579 GTEST_SUCCEED()
580 << "Readback not supported or unsupported pixelFormat/dataspace";
581 return;
582 }
583
584 common::Rect coloredSquare({0, 0, getDisplayWidth(), getDisplayHeight()});
585
586 // expected color for each pixel
587 std::vector<Color> expectedColors(
588 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
589 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare,
590 WHITE);
591
592 auto layer = std::make_shared<TestBufferLayer>(
593 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(),
594 getDisplayWidth(), getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
595 layer->setDisplayFrame(coloredSquare);
596 layer->setZOrder(10);
597 layer->setDataspace(Dataspace::SRGB);
598
599 Luts luts;
600 generateLuts(&luts, l.dimension, l.size, key);
601 layer->setLuts(std::move(luts));
602
603 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
604
605 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
606
607 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient,
608 getDisplayWidth(), getDisplayHeight(), mPixelFormat,
609 mDataspace);
610 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
611
612 writeLayers(layers);
613 ASSERT_TRUE(mReader.takeErrors().empty());
614 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
615 VtsComposerClient::kNoFrameIntervalNs);
616 execute();
617 // if hwc cannot handle and asks for composition change,
618 // just succeed the test
619 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
620 GTEST_SUCCEED();
621 return;
622 }
623
624 auto changedCompositionTypes =
625 mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
626 ASSERT_TRUE(changedCompositionTypes.empty());
627
628 mWriter->presentDisplay(getPrimaryDisplayId());
629 execute();
630 ASSERT_TRUE(mReader.takeErrors().empty());
631
632 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), coloredSquare,
633 {188.f / 255.f, 188.f / 255.f, 188.f / 255.f, 1.0f});
634
635 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
636 mTestRenderEngine->setRenderLayers(layers);
637 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
638 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
639 }
640 }
641 }
642}
643
Sally Qi0ca29272024-02-23 11:07:08 -0800644TEST_P(GraphicsCompositionTest, MixedColorSpaces) {
645 ASSERT_TRUE(
646 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
647 .isOk());
648 const auto& [status, properties] = mComposerClient->getOverlaySupport();
649 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
650 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
651 GTEST_SUCCEED() << "getOverlaySupport is not supported";
652 return;
653 }
654
655 if (properties.supportMixedColorSpaces == false) {
656 GTEST_SUCCEED() << "supportMixedColorSpaces is not supported";
657 return;
658 }
659
660 for (ColorMode mode : mTestColorModes) {
661 EXPECT_TRUE(mComposerClient
662 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
663 .isOk());
664
665 bool isSupported;
666 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
667 if (!isSupported) {
668 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
669 return;
670 }
671
672 // sRGB layer
673 auto srgbLayer = std::make_shared<TestBufferLayer>(
674 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
675 getDisplayHeight() / 2, PixelFormat::RGBA_8888, *mWriter);
676 std::vector<Color> sRgbDeviceColors(srgbLayer->getWidth() * srgbLayer->getHeight());
677 ReadbackHelper::fillColorsArea(sRgbDeviceColors, getDisplayWidth(),
678 {0, 0, static_cast<int32_t>(srgbLayer->getWidth()),
679 static_cast<int32_t>(srgbLayer->getHeight())},
680 GREEN);
681 srgbLayer->setDisplayFrame({0, 0, static_cast<int32_t>(srgbLayer->getWidth()),
682 static_cast<int32_t>(srgbLayer->getHeight())});
683 srgbLayer->setZOrder(10);
684 srgbLayer->setDataspace(Dataspace::SRGB);
685 ASSERT_NO_FATAL_FAILURE(srgbLayer->setBuffer(sRgbDeviceColors));
686
687 // display P3 layer
688 auto displayP3Layer = std::make_shared<TestBufferLayer>(
689 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
690 getDisplayHeight() / 2, PixelFormat::RGBA_8888, *mWriter);
691 std::vector<Color> displayP3DeviceColors(
692 static_cast<size_t>(displayP3Layer->getWidth() * displayP3Layer->getHeight()));
693 ReadbackHelper::fillColorsArea(displayP3DeviceColors, getDisplayWidth(),
694 {0, 0, static_cast<int32_t>(displayP3Layer->getWidth()),
695 static_cast<int32_t>(displayP3Layer->getHeight())},
696 RED);
697 displayP3Layer->setDisplayFrame(
698 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()});
699 displayP3Layer->setZOrder(10);
700 displayP3Layer->setDataspace(Dataspace::DISPLAY_P3);
701 ASSERT_NO_FATAL_FAILURE(displayP3Layer->setBuffer(displayP3DeviceColors));
702
703 writeLayers({srgbLayer, displayP3Layer});
704
705 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
706 VtsComposerClient::kNoFrameIntervalNs);
707 execute();
708
709 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
710 ASSERT_TRUE(changedCompositionTypes.empty());
711
712 mWriter->presentDisplay(getPrimaryDisplayId());
713 execute();
714
715 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
716 ASSERT_TRUE(changedCompositionTypes.empty());
717 ASSERT_TRUE(mReader.takeErrors().empty());
718 }
719}
720
ramindanibab8ba92021-11-18 01:24:11 +0000721TEST_P(GraphicsCompositionTest, DeviceAndClientComposition) {
ramindanidcecfd42022-02-03 23:52:19 +0000722 ASSERT_TRUE(
723 mComposerClient->setClientTargetSlotCount(getPrimaryDisplayId(), kClientTargetSlotCount)
724 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000725
726 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000727 EXPECT_TRUE(mComposerClient
728 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
729 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000730
ramindani44c952f2022-02-28 23:29:29 +0000731 bool isSupported;
732 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000733 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000734 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
735 return;
736 }
737
ramindanidcecfd42022-02-03 23:52:19 +0000738 std::vector<Color> expectedColors(
739 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
740 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
741 {0, 0, getDisplayWidth(), getDisplayHeight() / 2}, GREEN);
742 ReadbackHelper::fillColorsArea(
743 expectedColors, getDisplayWidth(),
744 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000745
ramindanidcecfd42022-02-03 23:52:19 +0000746 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700747 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000748 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
749
750 auto deviceLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000751 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -0800752 getDisplayHeight() / 2, PixelFormat::RGBA_8888, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000753 std::vector<Color> deviceColors(deviceLayer->getWidth() * deviceLayer->getHeight());
754 ReadbackHelper::fillColorsArea(deviceColors, static_cast<int32_t>(deviceLayer->getWidth()),
755 {0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
756 static_cast<int32_t>(deviceLayer->getHeight())},
757 GREEN);
758 deviceLayer->setDisplayFrame({0, 0, static_cast<int32_t>(deviceLayer->getWidth()),
759 static_cast<int32_t>(deviceLayer->getHeight())});
760 deviceLayer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000761 deviceLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000762 ASSERT_NO_FATAL_FAILURE(deviceLayer->setBuffer(deviceColors));
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400763 deviceLayer->write(*mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000764
765 PixelFormat clientFormat = PixelFormat::RGBA_8888;
Brian Lindahle887a252023-01-17 14:54:19 -0700766 auto clientUsage = static_cast<uint32_t>(
767 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
768 static_cast<uint32_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
769 static_cast<uint32_t>(common::BufferUsage::COMPOSER_CLIENT_TARGET));
ramindanibab8ba92021-11-18 01:24:11 +0000770 Dataspace clientDataspace = ReadbackHelper::getDataspaceForColorMode(mode);
ramindanidcecfd42022-02-03 23:52:19 +0000771 int32_t clientWidth = getDisplayWidth();
772 int32_t clientHeight = getDisplayHeight() / 2;
ramindanibab8ba92021-11-18 01:24:11 +0000773
774 auto clientLayer = std::make_shared<TestBufferLayer>(
ramindani0a2bee42022-02-10 01:27:42 +0000775 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), clientWidth,
Ady Abrahama00d2462023-12-26 14:21:20 -0800776 clientHeight, PixelFormat::RGBA_FP16, *mWriter, Composition::DEVICE);
ramindanidcecfd42022-02-03 23:52:19 +0000777 common::Rect clientFrame = {0, getDisplayHeight() / 2, getDisplayWidth(),
778 getDisplayHeight()};
ramindanibab8ba92021-11-18 01:24:11 +0000779 clientLayer->setDisplayFrame(clientFrame);
780 clientLayer->setZOrder(0);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400781 clientLayer->write(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800782 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
783 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000784 execute();
785
ramindanidcecfd42022-02-03 23:52:19 +0000786 auto changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800787 if (changedCompositionTypes.size() != 1) {
ramindanibab8ba92021-11-18 01:24:11 +0000788 continue;
789 }
790 // create client target buffer
Ady Abraham46219f52021-12-20 09:44:31 -0800791 ASSERT_EQ(Composition::CLIENT, changedCompositionTypes[0].composition);
Brian Lindahle887a252023-01-17 14:54:19 -0700792 const auto& [graphicBufferStatus, graphicBuffer] = allocateBuffer(clientUsage);
793 ASSERT_TRUE(graphicBufferStatus);
ramindani0a2bee42022-02-10 01:27:42 +0000794 const auto& buffer = graphicBuffer->handle;
ramindanibab8ba92021-11-18 01:24:11 +0000795
796 void* clientBufData;
Alec Mouri6a000222024-08-16 23:08:09 +0000797 int bytesPerPixel = -1;
798 int bytesPerStride = -1;
ramindani0a2bee42022-02-10 01:27:42 +0000799 graphicBuffer->lock(clientUsage, {0, 0, getDisplayWidth(), getDisplayHeight()},
Alec Mouri6a000222024-08-16 23:08:09 +0000800 &clientBufData, &bytesPerPixel, &bytesPerStride);
ramindanibab8ba92021-11-18 01:24:11 +0000801
ramindanidcecfd42022-02-03 23:52:19 +0000802 std::vector<Color> clientColors(
803 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
804 ReadbackHelper::fillColorsArea(clientColors, getDisplayWidth(), clientFrame, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000805 ASSERT_NO_FATAL_FAILURE(ReadbackHelper::fillBuffer(
ramindanidcecfd42022-02-03 23:52:19 +0000806 static_cast<uint32_t>(getDisplayWidth()), static_cast<uint32_t>(getDisplayHeight()),
Alec Mouri6a000222024-08-16 23:08:09 +0000807 graphicBuffer->getStride(), bytesPerPixel, clientBufData, clientFormat,
808 clientColors));
ramindanib1144212022-02-10 01:51:24 +0000809 int32_t clientFence;
810 const auto unlockStatus = graphicBuffer->unlockAsync(&clientFence);
811 ASSERT_EQ(::android::OK, unlockStatus);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400812 mWriter->setClientTarget(getPrimaryDisplayId(), /*slot*/ 0, buffer, clientFence,
Alec Mouri8062f1f2023-09-06 02:14:47 +0000813 clientDataspace, std::vector<common::Rect>(1, clientFrame), 1.f);
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400814 clientLayer->setToClientComposition(*mWriter);
ramindanicdcfcaf2023-11-09 10:00:10 -0800815 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
816 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000817 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000818 changedCompositionTypes = mReader.takeChangedCompositionTypes(getPrimaryDisplayId());
Ady Abraham46219f52021-12-20 09:44:31 -0800819 ASSERT_TRUE(changedCompositionTypes.empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -0800820 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000821
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400822 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000823 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800824 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000825 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
826 }
827}
828
829TEST_P(GraphicsCompositionTest, SetLayerDamage) {
830 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000831 EXPECT_TRUE(mComposerClient
832 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
833 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000834
ramindani44c952f2022-02-28 23:29:29 +0000835 bool isSupported;
836 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000837 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000838 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
839 return;
840 }
841
ramindanidcecfd42022-02-03 23:52:19 +0000842 common::Rect redRect = {0, 0, getDisplayWidth() / 4, getDisplayHeight() / 4};
ramindanibab8ba92021-11-18 01:24:11 +0000843
ramindanidcecfd42022-02-03 23:52:19 +0000844 std::vector<Color> expectedColors(
845 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
846 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000847
Ady Abrahama00d2462023-12-26 14:21:20 -0800848 auto layer = std::make_shared<TestBufferLayer>(
849 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
850 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000851 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000852 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000853 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +0000854 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
855
856 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
857
ramindanidcecfd42022-02-03 23:52:19 +0000858 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700859 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000860 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
861
862 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800863 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800864 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
865 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000866 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000867 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000868 GTEST_SUCCEED();
869 return;
870 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800871 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400872 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000873 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800874 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000875
876 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
877
878 // update surface damage and recheck
ramindanidcecfd42022-02-03 23:52:19 +0000879 redRect = {getDisplayWidth() / 4, getDisplayHeight() / 4, getDisplayWidth() / 2,
880 getDisplayHeight() / 2};
881 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
882 getDisplayWidth());
883 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +0000884
885 ASSERT_NO_FATAL_FAILURE(layer->fillBuffer(expectedColors));
886 layer->setSurfaceDamage(
ramindanidcecfd42022-02-03 23:52:19 +0000887 std::vector<common::Rect>(1, {0, 0, getDisplayWidth() / 2, getDisplayWidth() / 2}));
ramindanibab8ba92021-11-18 01:24:11 +0000888
889 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
890
891 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800892 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800893 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
894 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000895 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800896 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanidcecfd42022-02-03 23:52:19 +0000897 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400898 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000899 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800900 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000901
902 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
903 }
904}
905
906TEST_P(GraphicsCompositionTest, SetLayerPlaneAlpha) {
907 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000908 EXPECT_TRUE(mComposerClient
909 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
910 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000911
ramindani44c952f2022-02-28 23:29:29 +0000912 bool isSupported;
913 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000914 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000915 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
916 return;
917 }
918
Ady Abrahama00d2462023-12-26 14:21:20 -0800919 auto layer =
920 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +0000921 layer->setColor(RED);
ramindanidcecfd42022-02-03 23:52:19 +0000922 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000923 layer->setZOrder(10);
924 layer->setAlpha(0);
925 layer->setBlendMode(BlendMode::PREMULTIPLIED);
926
927 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
928
ramindanidcecfd42022-02-03 23:52:19 +0000929 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700930 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000931
932 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
933
934 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -0800935 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -0800936 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
937 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +0000938 execute();
ramindanidcecfd42022-02-03 23:52:19 +0000939 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +0000940 GTEST_SUCCEED();
941 return;
942 }
Ady Abraham3192f3d2021-12-03 16:08:56 -0800943 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000944
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -0400945 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +0000946 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -0800947 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +0000948
ramindanidcecfd42022-02-03 23:52:19 +0000949 std::vector<Color> expectedColors(
950 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +0000951
952 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
953 mTestRenderEngine->setRenderLayers(layers);
954 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
955 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
956 }
957}
958
959TEST_P(GraphicsCompositionTest, SetLayerSourceCrop) {
960 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +0000961 EXPECT_TRUE(mComposerClient
962 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
963 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +0000964
ramindani44c952f2022-02-28 23:29:29 +0000965 bool isSupported;
966 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +0000967 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +0000968 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
969 return;
970 }
971
ramindanidcecfd42022-02-03 23:52:19 +0000972 std::vector<Color> expectedColors(
973 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
974 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
975 {0, 0, getDisplayWidth(), getDisplayHeight() / 4}, RED);
976 ReadbackHelper::fillColorsArea(
977 expectedColors, getDisplayWidth(),
978 {0, getDisplayHeight() / 2, getDisplayWidth(), getDisplayHeight()}, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +0000979
Ady Abrahama00d2462023-12-26 14:21:20 -0800980 auto layer = std::make_shared<TestBufferLayer>(
981 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
982 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +0000983 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +0000984 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +0000985 layer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanidcecfd42022-02-03 23:52:19 +0000986 layer->setSourceCrop({0, static_cast<float>(getDisplayHeight() / 2),
987 static_cast<float>(getDisplayWidth()),
988 static_cast<float>(getDisplayHeight())});
ramindanibab8ba92021-11-18 01:24:11 +0000989 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(expectedColors));
990
991 std::vector<std::shared_ptr<TestLayer>> layers = {layer};
992
993 // update expected colors to match crop
ramindanidcecfd42022-02-03 23:52:19 +0000994 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
995 {0, 0, getDisplayWidth(), getDisplayHeight()}, BLUE);
996 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -0700997 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +0000998 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
999 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001000 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001001 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1002 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001003 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001004 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001005 GTEST_SUCCEED();
1006 return;
1007 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001008 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001009 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001010 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001011 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001012 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1013 mTestRenderEngine->setRenderLayers(layers);
1014 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1015 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1016 }
1017}
1018
1019TEST_P(GraphicsCompositionTest, SetLayerZOrder) {
1020 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001021 EXPECT_TRUE(mComposerClient
1022 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1023 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001024
ramindani44c952f2022-02-28 23:29:29 +00001025 bool isSupported;
1026 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001027 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001028 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1029 return;
1030 }
1031
ramindanidcecfd42022-02-03 23:52:19 +00001032 common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
1033 common::Rect blueRect = {0, getDisplayHeight() / 4, getDisplayWidth(), getDisplayHeight()};
Ady Abrahama00d2462023-12-26 14:21:20 -08001034 auto redLayer =
1035 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001036 redLayer->setColor(RED);
1037 redLayer->setDisplayFrame(redRect);
1038
Ady Abrahama00d2462023-12-26 14:21:20 -08001039 auto blueLayer =
1040 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001041 blueLayer->setColor(BLUE);
1042 blueLayer->setDisplayFrame(blueRect);
1043 blueLayer->setZOrder(5);
1044
1045 std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, blueLayer};
ramindanidcecfd42022-02-03 23:52:19 +00001046 std::vector<Color> expectedColors(
1047 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001048
1049 // red in front of blue
1050 redLayer->setZOrder(10);
1051
1052 // fill blue first so that red will overwrite on overlap
ramindanidcecfd42022-02-03 23:52:19 +00001053 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
1054 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
ramindanibab8ba92021-11-18 01:24:11 +00001055
ramindanidcecfd42022-02-03 23:52:19 +00001056 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001057 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001058 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1059
1060 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001061 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001062 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1063 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001064 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001065 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001066 GTEST_SUCCEED();
1067 return;
1068 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001069 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001070 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001071 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001072
1073 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1074
1075 redLayer->setZOrder(1);
ramindanidcecfd42022-02-03 23:52:19 +00001076 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1077 getDisplayWidth());
1078 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
1079 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), blueRect, BLUE);
ramindanibab8ba92021-11-18 01:24:11 +00001080
1081 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1082
1083 writeLayers(layers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001084 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001085 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1086 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001087 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001088 ASSERT_TRUE(mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty());
Ady Abraham3192f3d2021-12-03 16:08:56 -08001089 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001090 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001091 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001092 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001093
1094 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1095 mTestRenderEngine->setRenderLayers(layers);
1096 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1097 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1098 }
1099}
1100
Alec Mourib1f16722022-02-07 13:03:44 -08001101TEST_P(GraphicsCompositionTest, SetLayerBrightnessDims) {
Alec Mouri51067012022-01-06 17:28:39 -08001102 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001103 EXPECT_TRUE(mComposerClient
1104 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1105 .isOk());
Alec Mouri51067012022-01-06 17:28:39 -08001106
ramindani44c952f2022-02-28 23:29:29 +00001107 bool isSupported;
1108 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001109 if (!isSupported) {
Alec Mouri51067012022-01-06 17:28:39 -08001110 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace for "
1111 "color mode: "
1112 << toString(mode);
1113 continue;
1114 }
ramindanidcecfd42022-02-03 23:52:19 +00001115 const common::Rect redRect = {0, 0, getDisplayWidth(), getDisplayHeight() / 2};
1116 const common::Rect dimmerRedRect = {0, getDisplayHeight() / 2, getDisplayWidth(),
1117 getDisplayHeight()};
Alec Mouri712b3d92023-09-29 00:21:37 +00001118
1119 static constexpr float kMaxBrightnessNits = 300.f;
1120
ramindanidcecfd42022-02-03 23:52:19 +00001121 const auto redLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001122 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Alec Mouri51067012022-01-06 17:28:39 -08001123 redLayer->setColor(RED);
1124 redLayer->setDisplayFrame(redRect);
Alec Mouri712b3d92023-09-29 00:21:37 +00001125 redLayer->setWhitePointNits(kMaxBrightnessNits);
Alec Mourib1f16722022-02-07 13:03:44 -08001126 redLayer->setBrightness(1.f);
Alec Mouri51067012022-01-06 17:28:39 -08001127
1128 const auto dimmerRedLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001129 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Alec Mouri51067012022-01-06 17:28:39 -08001130 dimmerRedLayer->setColor(RED);
1131 dimmerRedLayer->setDisplayFrame(dimmerRedRect);
1132 // Intentionally use a small dimming ratio as some implementations may be more likely to
1133 // kick into GPU composition to apply dithering when the dimming ratio is high.
1134 static constexpr float kDimmingRatio = 0.9f;
Alec Mouri712b3d92023-09-29 00:21:37 +00001135 dimmerRedLayer->setWhitePointNits(kMaxBrightnessNits * kDimmingRatio);
Alec Mourib1f16722022-02-07 13:03:44 -08001136 dimmerRedLayer->setBrightness(kDimmingRatio);
Alec Mouri51067012022-01-06 17:28:39 -08001137
1138 const std::vector<std::shared_ptr<TestLayer>> layers = {redLayer, dimmerRedLayer};
ramindanidcecfd42022-02-03 23:52:19 +00001139 std::vector<Color> expectedColors(
1140 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
Alec Mouri51067012022-01-06 17:28:39 -08001141
ramindanidcecfd42022-02-03 23:52:19 +00001142 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), redRect, RED);
1143 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(), dimmerRedRect, DIM_RED);
Alec Mouri51067012022-01-06 17:28:39 -08001144
ramindanidcecfd42022-02-03 23:52:19 +00001145 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001146 getDisplayHeight(), mPixelFormat, mDataspace);
Alec Mouri51067012022-01-06 17:28:39 -08001147 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1148
1149 writeLayers(layers);
1150 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001151 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1152 VtsComposerClient::kNoFrameIntervalNs);
Alec Mouri51067012022-01-06 17:28:39 -08001153 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001154 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
Alec Mouri51067012022-01-06 17:28:39 -08001155 GTEST_SUCCEED()
1156 << "Readback verification not supported for GPU composition for color mode: "
1157 << toString(mode);
1158 continue;
1159 }
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001160 mWriter->presentDisplay(getPrimaryDisplayId());
Alec Mouri51067012022-01-06 17:28:39 -08001161 execute();
1162 ASSERT_TRUE(mReader.takeErrors().empty());
1163
1164 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1165 mTestRenderEngine->setRenderLayers(layers);
1166 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1167 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1168 }
1169}
1170
ramindanibab8ba92021-11-18 01:24:11 +00001171class GraphicsBlendModeCompositionTest
1172 : public GraphicsCompositionTestBase,
1173 public testing::WithParamInterface<std::tuple<std::string, std::string>> {
1174 public:
1175 void SetUp() override {
1176 SetUpBase(std::get<0>(GetParam()));
ramindanib636af22022-02-10 02:55:56 +00001177 // TODO(b/219590743) we should remove the below SRGB color mode
1178 // once we have the BlendMode test fix for all the versions of the ColorMode
ramindania4e76362022-03-02 01:48:06 +00001179 mTestColorModes.erase(
1180 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
1181 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
1182 mTestColorModes.end());
ramindanibab8ba92021-11-18 01:24:11 +00001183 mBackgroundColor = BLACK;
1184 mTopLayerColor = RED;
1185 }
1186
1187 void setBackgroundColor(Color color) { mBackgroundColor = color; }
1188
1189 void setTopLayerColor(Color color) { mTopLayerColor = color; }
1190
1191 void setUpLayers(BlendMode blendMode) {
1192 mLayers.clear();
ramindanidcecfd42022-02-03 23:52:19 +00001193 std::vector<Color> topLayerPixelColors(
1194 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1195 ReadbackHelper::fillColorsArea(topLayerPixelColors, getDisplayWidth(),
1196 {0, 0, getDisplayWidth(), getDisplayHeight()},
1197 mTopLayerColor);
ramindanibab8ba92021-11-18 01:24:11 +00001198
ramindanidcecfd42022-02-03 23:52:19 +00001199 auto backgroundLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001200 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +00001201 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001202 backgroundLayer->setZOrder(0);
1203 backgroundLayer->setColor(mBackgroundColor);
1204
Ady Abrahama00d2462023-12-26 14:21:20 -08001205 auto layer = std::make_shared<TestBufferLayer>(
1206 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
1207 getDisplayHeight(), PixelFormat::RGBA_8888, *mWriter);
ramindanidcecfd42022-02-03 23:52:19 +00001208 layer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001209 layer->setZOrder(10);
Alec Mourif6c039a2023-10-06 23:02:17 +00001210 layer->setDataspace(Dataspace::UNKNOWN);
ramindanibab8ba92021-11-18 01:24:11 +00001211 ASSERT_NO_FATAL_FAILURE(layer->setBuffer(topLayerPixelColors));
1212
1213 layer->setBlendMode(blendMode);
1214 layer->setAlpha(std::stof(std::get<1>(GetParam())));
1215
1216 mLayers.push_back(backgroundLayer);
1217 mLayers.push_back(layer);
1218 }
1219
1220 void setExpectedColors(std::vector<Color>& expectedColors) {
1221 ASSERT_EQ(2, mLayers.size());
ramindanidcecfd42022-02-03 23:52:19 +00001222 ReadbackHelper::clearColors(expectedColors, getDisplayWidth(), getDisplayHeight(),
1223 getDisplayWidth());
ramindanibab8ba92021-11-18 01:24:11 +00001224
1225 auto layer = mLayers[1];
1226 BlendMode blendMode = layer->getBlendMode();
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001227 float alpha = mTopLayerColor.a * layer->getAlpha();
ramindanibab8ba92021-11-18 01:24:11 +00001228 if (blendMode == BlendMode::NONE) {
1229 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001230 expectedColor.r = mTopLayerColor.r * layer->getAlpha();
1231 expectedColor.g = mTopLayerColor.g * layer->getAlpha();
1232 expectedColor.b = mTopLayerColor.b * layer->getAlpha();
1233 expectedColor.a = alpha;
ramindanibab8ba92021-11-18 01:24:11 +00001234 }
1235 } else if (blendMode == BlendMode::PREMULTIPLIED) {
1236 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001237 expectedColor.r =
1238 mTopLayerColor.r * layer->getAlpha() + mBackgroundColor.r * (1.0f - alpha);
1239 expectedColor.g =
1240 mTopLayerColor.g * layer->getAlpha() + mBackgroundColor.g * (1.0f - alpha);
1241 expectedColor.b =
1242 mTopLayerColor.b * layer->getAlpha() + mBackgroundColor.b * (1.0f - alpha);
1243 expectedColor.a = alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001244 }
1245 } else if (blendMode == BlendMode::COVERAGE) {
1246 for (auto& expectedColor : expectedColors) {
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001247 expectedColor.r = mTopLayerColor.r * alpha + mBackgroundColor.r * (1.0f - alpha);
1248 expectedColor.g = mTopLayerColor.g * alpha + mBackgroundColor.g * (1.0f - alpha);
1249 expectedColor.b = mTopLayerColor.b * alpha + mBackgroundColor.b * (1.0f - alpha);
1250 expectedColor.a = mTopLayerColor.a * alpha + mBackgroundColor.a * (1.0f - alpha);
ramindanibab8ba92021-11-18 01:24:11 +00001251 }
1252 }
1253 }
1254
1255 protected:
1256 std::vector<std::shared_ptr<TestLayer>> mLayers;
1257 Color mBackgroundColor;
1258 Color mTopLayerColor;
1259};
ramindanic7585d92022-04-15 18:30:41 +00001260
1261TEST_P(GraphicsBlendModeCompositionTest, None) {
ramindanibab8ba92021-11-18 01:24:11 +00001262 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001263 EXPECT_TRUE(mComposerClient
1264 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1265 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001266
ramindani44c952f2022-02-28 23:29:29 +00001267 bool isSupported;
1268 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001269 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001270 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1271 return;
1272 }
1273
ramindanidcecfd42022-02-03 23:52:19 +00001274 std::vector<Color> expectedColors(
1275 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001276
1277 setBackgroundColor(BLACK);
1278 setTopLayerColor(TRANSLUCENT_RED);
1279 setUpLayers(BlendMode::NONE);
1280 setExpectedColors(expectedColors);
1281
ramindanidcecfd42022-02-03 23:52:19 +00001282 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001283 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001284 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1285 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001286 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001287 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1288 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001289 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001290 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001291 GTEST_SUCCEED();
1292 return;
1293 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001294 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001295 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001296 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001297 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001298
1299 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1300 mTestRenderEngine->setRenderLayers(mLayers);
1301 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1302 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1303 }
1304}
1305
ramindani07e6f842022-02-15 15:28:33 +00001306TEST_P(GraphicsBlendModeCompositionTest, Coverage) {
ramindanibab8ba92021-11-18 01:24:11 +00001307 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001308 EXPECT_TRUE(mComposerClient
1309 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1310 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001311
ramindani44c952f2022-02-28 23:29:29 +00001312 bool isSupported;
1313 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001314 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001315 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1316 return;
1317 }
1318
ramindanidcecfd42022-02-03 23:52:19 +00001319 std::vector<Color> expectedColors(
1320 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001321
1322 setBackgroundColor(BLACK);
1323 setTopLayerColor(TRANSLUCENT_RED);
1324
1325 setUpLayers(BlendMode::COVERAGE);
1326 setExpectedColors(expectedColors);
1327
ramindanidcecfd42022-02-03 23:52:19 +00001328 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001329 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001330 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1331 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001332 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001333 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1334 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001335 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001336 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001337 GTEST_SUCCEED();
1338 return;
1339 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001340 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001341 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001342 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001343 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001344 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1345 }
1346}
1347
1348TEST_P(GraphicsBlendModeCompositionTest, Premultiplied) {
1349 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001350 EXPECT_TRUE(mComposerClient
1351 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1352 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001353
ramindani44c952f2022-02-28 23:29:29 +00001354 bool isSupported;
1355 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001356 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001357 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1358 return;
1359 }
ramindanibab8ba92021-11-18 01:24:11 +00001360
ramindanidcecfd42022-02-03 23:52:19 +00001361 std::vector<Color> expectedColors(
1362 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
ramindanibab8ba92021-11-18 01:24:11 +00001363
1364 setBackgroundColor(BLACK);
1365 setTopLayerColor(TRANSLUCENT_RED);
1366 setUpLayers(BlendMode::PREMULTIPLIED);
1367 setExpectedColors(expectedColors);
1368
ramindanidcecfd42022-02-03 23:52:19 +00001369 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001370 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001371 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1372 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001373 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001374 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1375 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001376 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001377 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001378 GTEST_SUCCEED();
1379 return;
1380 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001381 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001382 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001383 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001384 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001385 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1386 mTestRenderEngine->setRenderLayers(mLayers);
1387 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1388 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1389 }
1390}
1391
1392class GraphicsTransformCompositionTest : public GraphicsCompositionTest {
1393 protected:
1394 void SetUp() override {
1395 GraphicsCompositionTest::SetUp();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001396
ramindanidcecfd42022-02-03 23:52:19 +00001397 auto backgroundLayer =
Ady Abrahama00d2462023-12-26 14:21:20 -08001398 std::make_shared<TestColorLayer>(mComposerClient, getPrimaryDisplayId(), *mWriter);
Ady Abraham1bee7ab2022-01-06 17:22:08 -08001399 backgroundLayer->setColor({0.0f, 0.0f, 0.0f, 0.0f});
ramindanidcecfd42022-02-03 23:52:19 +00001400 backgroundLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
ramindanibab8ba92021-11-18 01:24:11 +00001401 backgroundLayer->setZOrder(0);
1402
ramindanidcecfd42022-02-03 23:52:19 +00001403 mSideLength =
1404 getDisplayWidth() < getDisplayHeight() ? getDisplayWidth() : getDisplayHeight();
ramindanibab8ba92021-11-18 01:24:11 +00001405 common::Rect redRect = {0, 0, mSideLength / 2, mSideLength / 2};
1406 common::Rect blueRect = {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength};
1407
ramindani0a2bee42022-02-10 01:27:42 +00001408 mLayer = std::make_shared<TestBufferLayer>(mComposerClient, *mTestRenderEngine,
1409 getPrimaryDisplayId(), mSideLength, mSideLength,
Ady Abrahama00d2462023-12-26 14:21:20 -08001410 PixelFormat::RGBA_8888, *mWriter);
ramindanibab8ba92021-11-18 01:24:11 +00001411 mLayer->setDisplayFrame({0, 0, mSideLength, mSideLength});
1412 mLayer->setZOrder(10);
1413
1414 std::vector<Color> baseColors(static_cast<size_t>(mSideLength * mSideLength));
1415 ReadbackHelper::fillColorsArea(baseColors, mSideLength, redRect, RED);
1416 ReadbackHelper::fillColorsArea(baseColors, mSideLength, blueRect, BLUE);
1417 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1418 mLayers = {backgroundLayer, mLayer};
1419 }
1420
1421 protected:
1422 std::shared_ptr<TestBufferLayer> mLayer;
1423 std::vector<std::shared_ptr<TestLayer>> mLayers;
1424 int mSideLength;
1425};
1426
1427TEST_P(GraphicsTransformCompositionTest, FLIP_H) {
1428 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001429 auto status = mComposerClient->setColorMode(getPrimaryDisplayId(), mode,
1430 RenderIntent::COLORIMETRIC);
ramindanid5751092022-04-22 22:30:20 +00001431 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
ramindanidcecfd42022-02-03 23:52:19 +00001432 (status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED ||
1433 status.getServiceSpecificError() == IComposerClient::EX_BAD_PARAMETER)) {
ramindanibab8ba92021-11-18 01:24:11 +00001434 SUCCEED() << "ColorMode not supported, skip test";
1435 return;
1436 }
1437
ramindani44c952f2022-02-28 23:29:29 +00001438 bool isSupported;
1439 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001440 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001441 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1442 return;
1443 }
ramindanidcecfd42022-02-03 23:52:19 +00001444 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001445 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001446 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1447 mLayer->setTransform(Transform::FLIP_H);
Alec Mourif6c039a2023-10-06 23:02:17 +00001448 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001449
ramindanidcecfd42022-02-03 23:52:19 +00001450 std::vector<Color> expectedColors(
1451 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1452 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001453 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001454 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001455 {0, mSideLength / 2, mSideLength / 2, mSideLength}, BLUE);
1456
1457 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001458 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001459 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1460 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001461 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001462 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001463 GTEST_SUCCEED();
1464 return;
1465 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001466 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001467 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001468 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001469 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001470
1471 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1472 mTestRenderEngine->setRenderLayers(mLayers);
1473 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1474 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1475 }
1476}
1477
1478TEST_P(GraphicsTransformCompositionTest, FLIP_V) {
1479 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001480 EXPECT_TRUE(mComposerClient
1481 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1482 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001483
ramindani44c952f2022-02-28 23:29:29 +00001484 bool isSupported;
1485 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001486 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001487 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1488 return;
1489 }
ramindanidcecfd42022-02-03 23:52:19 +00001490 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001491 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001492 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1493
1494 mLayer->setTransform(Transform::FLIP_V);
Alec Mourif6c039a2023-10-06 23:02:17 +00001495 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001496
ramindanidcecfd42022-02-03 23:52:19 +00001497 std::vector<Color> expectedColors(
1498 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1499 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001500 {0, mSideLength / 2, mSideLength / 2, mSideLength}, RED);
ramindanidcecfd42022-02-03 23:52:19 +00001501 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001502 {mSideLength / 2, 0, mSideLength, mSideLength / 2}, BLUE);
1503
1504 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001505 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001506 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1507 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001508 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001509 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001510 GTEST_SUCCEED();
1511 return;
1512 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001513 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001514 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001515 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001516 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001517 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1518 mTestRenderEngine->setRenderLayers(mLayers);
1519 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1520 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1521 }
1522}
1523
1524TEST_P(GraphicsTransformCompositionTest, ROT_180) {
1525 for (ColorMode mode : mTestColorModes) {
ramindanidcecfd42022-02-03 23:52:19 +00001526 EXPECT_TRUE(mComposerClient
1527 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1528 .isOk());
ramindanibab8ba92021-11-18 01:24:11 +00001529
ramindani44c952f2022-02-28 23:29:29 +00001530 bool isSupported;
1531 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
ramindanidcecfd42022-02-03 23:52:19 +00001532 if (!isSupported) {
ramindanibab8ba92021-11-18 01:24:11 +00001533 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1534 return;
1535 }
ramindanidcecfd42022-02-03 23:52:19 +00001536 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
Brian Lindahle887a252023-01-17 14:54:19 -07001537 getDisplayHeight(), mPixelFormat, mDataspace);
ramindanibab8ba92021-11-18 01:24:11 +00001538 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1539
1540 mLayer->setTransform(Transform::ROT_180);
Alec Mourif6c039a2023-10-06 23:02:17 +00001541 mLayer->setDataspace(ReadbackHelper::getDataspaceForColorMode(mode));
ramindanibab8ba92021-11-18 01:24:11 +00001542
ramindanidcecfd42022-02-03 23:52:19 +00001543 std::vector<Color> expectedColors(
1544 static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1545 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001546 {mSideLength / 2, mSideLength / 2, mSideLength, mSideLength},
1547 RED);
ramindanidcecfd42022-02-03 23:52:19 +00001548 ReadbackHelper::fillColorsArea(expectedColors, getDisplayWidth(),
ramindanibab8ba92021-11-18 01:24:11 +00001549 {0, 0, mSideLength / 2, mSideLength / 2}, BLUE);
1550
1551 writeLayers(mLayers);
Ady Abraham3192f3d2021-12-03 16:08:56 -08001552 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001553 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1554 VtsComposerClient::kNoFrameIntervalNs);
ramindanibab8ba92021-11-18 01:24:11 +00001555 execute();
ramindanidcecfd42022-02-03 23:52:19 +00001556 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
ramindanibab8ba92021-11-18 01:24:11 +00001557 GTEST_SUCCEED();
1558 return;
1559 }
Ady Abraham3192f3d2021-12-03 16:08:56 -08001560 ASSERT_TRUE(mReader.takeErrors().empty());
Leon Scroggins IIIc3d695d2022-09-16 15:34:59 -04001561 mWriter->presentDisplay(getPrimaryDisplayId());
ramindanibab8ba92021-11-18 01:24:11 +00001562 execute();
Ady Abraham3192f3d2021-12-03 16:08:56 -08001563 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanibab8ba92021-11-18 01:24:11 +00001564 ASSERT_NO_FATAL_FAILURE(readbackBuffer.checkReadbackBuffer(expectedColors));
1565 mTestRenderEngine->setRenderLayers(mLayers);
1566 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1567 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->checkColorBuffer(expectedColors));
1568 }
1569}
1570
Alec Mourif6c039a2023-10-06 23:02:17 +00001571class GraphicsColorManagementCompositionTest
1572 : public GraphicsCompositionTestBase,
1573 public testing::WithParamInterface<std::tuple<std::string, Dataspace, Dataspace, Dataspace>> {
1574 public:
1575 void SetUp() override {
1576 SetUpBase(std::get<0>(GetParam()));
1577 // for some reason only sRGB reliably works
1578 mTestColorModes.erase(
1579 std::remove_if(mTestColorModes.begin(), mTestColorModes.end(),
1580 [](ColorMode mode) { return mode != ColorMode::SRGB; }),
1581 mTestColorModes.end());
1582 auto standard = std::get<1>(GetParam());
1583 auto transfer = std::get<2>(GetParam());
1584 auto range = std::get<3>(GetParam());
1585
1586 mLayerDataspace = static_cast<Dataspace>(static_cast<int32_t>(standard) |
1587 static_cast<int32_t>(transfer) |
1588 static_cast<int32_t>(range));
1589 ALOGD("Invoking test for dataspace: {%s, %s, %s}", toString(standard).c_str(),
1590 toString(transfer).c_str(), toString(range).c_str());
1591 }
1592
1593 void makeLayer() {
1594 mLayer = std::make_shared<TestBufferLayer>(
1595 mComposerClient, *mTestRenderEngine, getPrimaryDisplayId(), getDisplayWidth(),
Ady Abrahama00d2462023-12-26 14:21:20 -08001596 getDisplayHeight(), common::PixelFormat::RGBA_8888, *mWriter);
Alec Mourif6c039a2023-10-06 23:02:17 +00001597 mLayer->setDisplayFrame({0, 0, getDisplayWidth(), getDisplayHeight()});
1598 mLayer->setZOrder(10);
1599 mLayer->setAlpha(1.f);
1600 mLayer->setDataspace(mLayerDataspace);
1601 }
1602
1603 void fillColor(Color color) {
1604 std::vector<Color> baseColors(static_cast<size_t>(getDisplayWidth() * getDisplayHeight()));
1605 ReadbackHelper::fillColorsArea(baseColors, getDisplayWidth(),
1606 common::Rect{.left = 0,
1607 .top = 0,
1608 .right = getDisplayWidth(),
1609 .bottom = getDisplayHeight()},
1610 color);
1611 ASSERT_NO_FATAL_FAILURE(mLayer->setBuffer(baseColors));
1612 }
1613
1614 Dataspace mLayerDataspace;
1615 std::shared_ptr<TestBufferLayer> mLayer;
1616};
1617
1618TEST_P(GraphicsColorManagementCompositionTest, ColorConversion) {
1619 for (ColorMode mode : mTestColorModes) {
1620 EXPECT_TRUE(mComposerClient
1621 ->setColorMode(getPrimaryDisplayId(), mode, RenderIntent::COLORIMETRIC)
1622 .isOk());
1623
1624 bool isSupported;
1625 ASSERT_NO_FATAL_FAILURE(isSupported = getHasReadbackBuffer());
1626 if (!isSupported) {
1627 GTEST_SUCCEED() << "Readback not supported or unsupported pixelFormat/dataspace";
1628 return;
1629 }
1630
1631 mClientCompositionDisplaySettings.outputDataspace =
1632 static_cast<::android::ui::Dataspace>(mDataspace);
1633 mTestRenderEngine->setDisplaySettings(mClientCompositionDisplaySettings);
1634
1635 makeLayer();
1636 for (auto color : {LIGHT_RED, LIGHT_GREEN, LIGHT_BLUE}) {
1637 ALOGD("Testing color: %f, %f, %f, %f with color mode: %d", color.r, color.g, color.b,
1638 color.a, mode);
1639 ReadbackBuffer readbackBuffer(getPrimaryDisplayId(), mComposerClient, getDisplayWidth(),
1640 getDisplayHeight(), mPixelFormat, mDataspace);
1641 ASSERT_NO_FATAL_FAILURE(readbackBuffer.setReadbackBuffer());
1642 fillColor(color);
1643 writeLayers({mLayer});
1644 EXPECT_TRUE(mComposerClient->setPowerMode(getPrimaryDisplayId(), PowerMode::ON).isOk());
1645
1646 ASSERT_TRUE(mReader.takeErrors().empty());
ramindanicdcfcaf2023-11-09 10:00:10 -08001647 mWriter->validateDisplay(getPrimaryDisplayId(), ComposerClientWriter::kNoTimestamp,
1648 VtsComposerClient::kNoFrameIntervalNs);
Alec Mourif6c039a2023-10-06 23:02:17 +00001649 execute();
1650 if (!mReader.takeChangedCompositionTypes(getPrimaryDisplayId()).empty()) {
1651 continue;
1652 }
1653 ASSERT_TRUE(mReader.takeErrors().empty());
1654 mWriter->presentDisplay(getPrimaryDisplayId());
1655 execute();
1656 ASSERT_TRUE(mReader.takeErrors().empty());
1657
1658 mTestRenderEngine->setRenderLayers({mLayer});
1659 ASSERT_NO_FATAL_FAILURE(mTestRenderEngine->drawLayers());
1660 ASSERT_NO_FATAL_FAILURE(
1661 mTestRenderEngine->checkColorBuffer(readbackBuffer.getBuffer()));
1662 }
1663 }
1664}
1665
ramindanibab8ba92021-11-18 01:24:11 +00001666GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsCompositionTest);
1667INSTANTIATE_TEST_SUITE_P(
1668 PerInstance, GraphicsCompositionTest,
1669 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1670 ::android::PrintInstanceNameToString);
1671
1672GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsBlendModeCompositionTest);
1673INSTANTIATE_TEST_SUITE_P(BlendMode, GraphicsBlendModeCompositionTest,
1674 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1675 IComposer::descriptor)),
1676 testing::Values("0.2", "1.0")));
1677
1678GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsTransformCompositionTest);
1679INSTANTIATE_TEST_SUITE_P(
1680 PerInstance, GraphicsTransformCompositionTest,
1681 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
1682 ::android::PrintInstanceNameToString);
1683
Alec Mourif6c039a2023-10-06 23:02:17 +00001684GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsColorManagementCompositionTest);
1685INSTANTIATE_TEST_SUITE_P(PerInstance, GraphicsColorManagementCompositionTest,
1686 testing::Combine(testing::ValuesIn(::android::getAidlHalInstanceNames(
1687 IComposer::descriptor)),
1688 // Only check sRGB, but verify that extended range
1689 // doesn't trigger any gamma shifts
1690 testing::Values(Dataspace::STANDARD_BT709),
1691 testing::Values(Dataspace::TRANSFER_SRGB),
1692 // Don't test limited range until we send YUV overlays
1693 testing::Values(Dataspace::RANGE_FULL,
1694 Dataspace::RANGE_EXTENDED)));
1695
ramindanibab8ba92021-11-18 01:24:11 +00001696} // namespace
Ady Abraham3192f3d2021-12-03 16:08:56 -08001697} // namespace aidl::android::hardware::graphics::composer3::vts