1 /*
2 * Copyright (C) 2018 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_hidl_hal_test@2.2"
18
19 #include <android-base/logging.h>
20 #include <android-base/properties.h>
21 #include <android/hardware/graphics/mapper/2.0/IMapper.h>
22 #include <composer-vts/2.1/GraphicsComposerCallback.h>
23 #include <composer-vts/2.1/TestCommandReader.h>
24 #include <composer-vts/2.2/ComposerVts.h>
25 #include <gtest/gtest.h>
26 #include <hidl/GtestPrinter.h>
27 #include <hidl/ServiceManagement.h>
28 #include <mapper-vts/2.0/MapperVts.h>
29
30 namespace android {
31 namespace hardware {
32 namespace graphics {
33 namespace composer {
34 namespace V2_2 {
35 namespace vts {
36 namespace {
37
38 using common::V1_0::BufferUsage;
39 using common::V1_1::ColorMode;
40 using common::V1_1::Dataspace;
41 using common::V1_1::PixelFormat;
42 using common::V1_1::RenderIntent;
43 using V2_1::vts::NativeHandleWrapper;
44
45 class GraphicsComposerHidlTest : public ::testing::TestWithParam<std::string> {
46 protected:
SetUp()47 void SetUp() override {
48 ASSERT_NO_FATAL_FAILURE(
49 mComposer = std::make_unique<Composer>(IComposer::getService(GetParam())));
50 ASSERT_NO_FATAL_FAILURE(mComposerClient = mComposer->createClient());
51
52 mComposerCallback = new V2_1::vts::GraphicsComposerCallback;
53 mComposerClient->registerCallback(mComposerCallback);
54
55 // assume the first display is primary and is never removed
56 mPrimaryDisplay = waitForFirstDisplay();
57
58 Config config = mComposerClient->getActiveConfig(mPrimaryDisplay);
59 mDisplayWidth = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
60 IComposerClient::Attribute::WIDTH);
61 mDisplayHeight = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
62 IComposerClient::Attribute::HEIGHT);
63
64 // explicitly disable vsync
65 mComposerClient->setVsyncEnabled(mPrimaryDisplay, false);
66 mComposerCallback->setVsyncAllowed(false);
67
68 mComposerClient->getRaw()->getReadbackBufferAttributes(
69 mPrimaryDisplay,
70 [&](const auto& tmpError, const auto& tmpPixelFormat, const auto& tmpDataspace) {
71 mHasReadbackBuffer = tmpError == Error::NONE;
72 if (mHasReadbackBuffer) {
73 mReadbackPixelFormat = tmpPixelFormat;
74 mReadbackDataspace = tmpDataspace;
75 ASSERT_LT(static_cast<PixelFormat>(0), mReadbackPixelFormat);
76 ASSERT_NE(Dataspace::UNKNOWN, mReadbackDataspace);
77 }
78 });
79
80 mInvalidDisplayId = GetInvalidDisplayId();
81 }
82
TearDown()83 void TearDown() override {
84 if (mComposerCallback != nullptr) {
85 EXPECT_EQ(0, mComposerCallback->getInvalidHotplugCount());
86 EXPECT_EQ(0, mComposerCallback->getInvalidRefreshCount());
87 EXPECT_EQ(0, mComposerCallback->getInvalidVsyncCount());
88 }
89 }
90
91 // returns an invalid display id (one that has not been registered to a
92 // display. Currently assuming that a device will never have close to
93 // std::numeric_limit<uint64_t>::max() displays registered while running tests
GetInvalidDisplayId()94 Display GetInvalidDisplayId() {
95 std::vector<Display> validDisplays = mComposerCallback->getDisplays();
96 uint64_t id = std::numeric_limits<uint64_t>::max();
97 while (id > 0) {
98 if (std::find(validDisplays.begin(), validDisplays.end(), id) == validDisplays.end()) {
99 return id;
100 }
101 id--;
102 }
103
104 return 0;
105 }
106
107 // use the slot count usually set by SF
108 static constexpr uint32_t kBufferSlotCount = 64;
109
110 std::unique_ptr<Composer> mComposer;
111 std::unique_ptr<ComposerClient> mComposerClient;
112 sp<V2_1::vts::GraphicsComposerCallback> mComposerCallback;
113 // the first display and is assumed never to be removed
114 Display mPrimaryDisplay;
115 int32_t mDisplayWidth;
116 int32_t mDisplayHeight;
117
118 bool mHasReadbackBuffer;
119
120 uint64_t mInvalidDisplayId;
121 PixelFormat mReadbackPixelFormat;
122 Dataspace mReadbackDataspace;
123
124 private:
waitForFirstDisplay()125 Display waitForFirstDisplay() {
126 while (true) {
127 std::vector<Display> displays = mComposerCallback->getDisplays();
128 if (displays.empty()) {
129 usleep(5 * 1000);
130 continue;
131 }
132
133 return displays[0];
134 }
135 }
136 };
137
138 // Tests for IComposerClient::Command.
139 class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
140 protected:
SetUp()141 void SetUp() override {
142 ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::SetUp());
143
144 ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>());
145
146 mWriter = std::make_unique<CommandWriterBase>(1024);
147 mReader = std::make_unique<V2_1::vts::TestCommandReader>();
148 }
149
TearDown()150 void TearDown() override {
151 ASSERT_EQ(0, mReader->mErrors.size());
152 ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::TearDown());
153 }
154
allocate()155 NativeHandleWrapper allocate() {
156 uint64_t usage =
157 static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN);
158 return mGralloc->allocate(/*width*/ 64, /*height*/ 64, /*layerCount*/ 1,
159 PixelFormat::RGBA_8888, usage);
160 }
161
execute()162 void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
163
164 std::unique_ptr<CommandWriterBase> mWriter;
165 std::unique_ptr<V2_1::vts::TestCommandReader> mReader;
166
167 private:
168 std::unique_ptr<Gralloc> mGralloc;
169 };
170
171 /**
172 * Test IComposerClient::Command::SET_LAYER_PER_FRAME_METADATA.
173 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_PER_FRAME_METADATA)174 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_PER_FRAME_METADATA) {
175 Layer layer;
176 ASSERT_NO_FATAL_FAILURE(layer =
177 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
178
179 mWriter->selectDisplay(mPrimaryDisplay);
180 mWriter->selectLayer(layer);
181
182 /**
183 * DISPLAY_P3 is a color space that uses the DCI_P3 primaries,
184 * the D65 white point and the SRGB transfer functions.
185 * Rendering Intent: Colorimetric
186 * Primaries:
187 * x y
188 * green 0.265 0.690
189 * blue 0.150 0.060
190 * red 0.680 0.320
191 * white (D65) 0.3127 0.3290
192 */
193
194 std::vector<IComposerClient::PerFrameMetadata> hidlMetadata;
195 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, 0.680});
196 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, 0.320});
197 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, 0.265});
198 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, 0.690});
199 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, 0.150});
200 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, 0.060});
201 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::WHITE_POINT_X, 0.3127});
202 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::WHITE_POINT_Y, 0.3290});
203 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::MAX_LUMINANCE, 100.0});
204 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::MIN_LUMINANCE, 0.1});
205 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, 78.0});
206 hidlMetadata.push_back(
207 {IComposerClient::PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, 62.0});
208 mWriter->setLayerPerFrameMetadata(hidlMetadata);
209 execute();
210
211 if (mReader->mErrors.size() == 1 &&
212 static_cast<Error>(mReader->mErrors[0].second) == Error::UNSUPPORTED) {
213 mReader->mErrors.clear();
214 GTEST_SUCCEED() << "SetLayerPerFrameMetadata is not supported";
215 ASSERT_NO_FATAL_FAILURE(mComposerClient->destroyLayer(mPrimaryDisplay, layer));
216 return;
217 }
218
219 ASSERT_NO_FATAL_FAILURE(mComposerClient->destroyLayer(mPrimaryDisplay, layer));
220 }
221
222 /**
223 * Test IComposerClient::getPerFrameMetadataKeys.
224 */
TEST_P(GraphicsComposerHidlTest,GetPerFrameMetadataKeys)225 TEST_P(GraphicsComposerHidlTest, GetPerFrameMetadataKeys) {
226 std::vector<IComposerClient::PerFrameMetadataKey> keys;
227 Error error = Error::NONE;
228 mComposerClient->getRaw()->getPerFrameMetadataKeys(
229 mPrimaryDisplay, [&](const auto& tmpError, const auto& tmpKeys) {
230 error = tmpError;
231 keys = tmpKeys;
232 });
233 if (error == Error::UNSUPPORTED) {
234 GTEST_SUCCEED() << "getPerFrameMetadataKeys is not supported";
235 return;
236 }
237 ASSERT_EQ(Error::NONE, error);
238 ASSERT_TRUE(keys.size() >= 0);
239 }
240
241 /**
242 * Test IComposerClient::createVirtualDisplay_2_2 and
243 * IComposerClient::destroyVirtualDisplay.
244 *
245 * Test that virtual displays can be created and has the correct display type.
246 */
TEST_P(GraphicsComposerHidlTest,CreateVirtualDisplay_2_2)247 TEST_P(GraphicsComposerHidlTest, CreateVirtualDisplay_2_2) {
248 if (mComposerClient->getMaxVirtualDisplayCount() == 0) {
249 GTEST_SUCCEED() << "no virtual display support";
250 return;
251 }
252
253 Display display;
254 PixelFormat format;
255 ASSERT_NO_FATAL_FAILURE(
256 display = mComposerClient->createVirtualDisplay_2_2(
257 64, 64, PixelFormat::IMPLEMENTATION_DEFINED, kBufferSlotCount, &format));
258
259 // test display type
260 IComposerClient::DisplayType type = mComposerClient->getDisplayType(display);
261 EXPECT_EQ(IComposerClient::DisplayType::VIRTUAL, type);
262
263 mComposerClient->destroyVirtualDisplay(display);
264 }
265
266 /**
267 * Test IComposerClient::getClientTargetSupport_2_2.
268 *
269 * Test that IComposerClient::getClientTargetSupport returns true for the
270 * required client targets.
271 */
TEST_P(GraphicsComposerHidlTest,GetClientTargetSupport_2_2)272 TEST_P(GraphicsComposerHidlTest, GetClientTargetSupport_2_2) {
273 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
274 for (auto config : configs) {
275 int32_t width = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
276 IComposerClient::Attribute::WIDTH);
277 int32_t height = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
278 IComposerClient::Attribute::HEIGHT);
279 ASSERT_LT(0, width);
280 ASSERT_LT(0, height);
281
282 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
283
284 ASSERT_TRUE(mComposerClient->getClientTargetSupport_2_2(
285 mPrimaryDisplay, width, height, PixelFormat::RGBA_8888, Dataspace::UNKNOWN));
286 }
287 }
288
289 /**
290 * Test IComposerClient::getClientTargetSupport_2_2
291 *
292 * Test that IComposerClient::getClientTargetSupport_2_2 returns
293 * Error::BAD_DISPLAY when passed in an invalid display handle
294 */
295
TEST_P(GraphicsComposerHidlTest,GetClientTargetSupport_2_2BadDisplay)296 TEST_P(GraphicsComposerHidlTest, GetClientTargetSupport_2_2BadDisplay) {
297 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
298 for (auto config : configs) {
299 int32_t width = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
300 IComposerClient::Attribute::WIDTH);
301 int32_t height = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
302 IComposerClient::Attribute::HEIGHT);
303 ASSERT_LT(0, width);
304 ASSERT_LT(0, height);
305
306 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
307
308 Error error = mComposerClient->getRaw()->getClientTargetSupport_2_2(
309 mInvalidDisplayId, width, height, PixelFormat::RGBA_8888, Dataspace::UNKNOWN);
310
311 EXPECT_EQ(Error::BAD_DISPLAY, error);
312 }
313 }
314
315 /**
316 * Test IComposerClient::setPowerMode_2_2.
317 */
TEST_P(GraphicsComposerHidlTest,SetPowerMode_2_2)318 TEST_P(GraphicsComposerHidlTest, SetPowerMode_2_2) {
319 std::vector<IComposerClient::PowerMode> modes;
320 modes.push_back(IComposerClient::PowerMode::OFF);
321 modes.push_back(IComposerClient::PowerMode::ON_SUSPEND);
322 modes.push_back(IComposerClient::PowerMode::ON);
323
324 for (auto mode : modes) {
325 mComposerClient->setPowerMode_2_2(mPrimaryDisplay, mode);
326 }
327 }
328
329 /**
330 * Test IComposerClient::setPowerMode_2_2
331 *
332 * Test that IComposerClient::setPowerMode_2_2 succeeds for different varations
333 * of PowerMode
334 */
TEST_P(GraphicsComposerHidlTest,SetPowerMode_2_2Variations)335 TEST_P(GraphicsComposerHidlTest, SetPowerMode_2_2Variations) {
336 std::vector<IComposerClient::PowerMode> modes;
337
338 modes.push_back(IComposerClient::PowerMode::OFF);
339 modes.push_back(IComposerClient::PowerMode::OFF);
340
341 for (auto mode : modes) {
342 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode_2_2(mPrimaryDisplay, mode));
343 }
344
345 modes.clear();
346
347 modes.push_back(IComposerClient::PowerMode::ON);
348 modes.push_back(IComposerClient::PowerMode::ON);
349
350 for (auto mode : modes) {
351 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode_2_2(mPrimaryDisplay, mode));
352 }
353
354 modes.clear();
355
356 modes.push_back(IComposerClient::PowerMode::ON_SUSPEND);
357 modes.push_back(IComposerClient::PowerMode::ON_SUSPEND);
358
359 for (auto mode : modes) {
360 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode_2_2(mPrimaryDisplay, mode));
361 }
362
363 if (mComposerClient->getDozeSupport(mPrimaryDisplay)) {
364 modes.clear();
365
366 modes.push_back(IComposerClient::PowerMode::DOZE);
367 modes.push_back(IComposerClient::PowerMode::DOZE);
368
369 for (auto mode : modes) {
370 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode_2_2(mPrimaryDisplay, mode));
371 }
372
373 modes.clear();
374
375 modes.push_back(IComposerClient::PowerMode::DOZE_SUSPEND);
376 modes.push_back(IComposerClient::PowerMode::DOZE_SUSPEND);
377
378 for (auto mode : modes) {
379 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode_2_2(mPrimaryDisplay, mode));
380 }
381 }
382 }
383
384 /**
385 * Test IComposerClient::setPowerMode_2_2
386 *
387 * Tests that IComposerClient::setPowerMode_2_2 returns BAD_DISPLAY when passed an
388 * invalid display handle
389 */
TEST_P(GraphicsComposerHidlTest,SetPowerMode_2_2BadDisplay)390 TEST_P(GraphicsComposerHidlTest, SetPowerMode_2_2BadDisplay) {
391 Error error = mComposerClient->getRaw()->setPowerMode_2_2(mInvalidDisplayId,
392 IComposerClient::PowerMode::ON);
393 ASSERT_EQ(Error::BAD_DISPLAY, error);
394 }
395
396 /**
397 * Test IComposerClient::setPowerMode_2_2
398 *
399 * Test that IComposerClient::setPowerMode_2_2 returns BAD_PARAMETER when passed
400 * an invalid PowerMode
401 */
TEST_P(GraphicsComposerHidlTest,SetPowerMode_2_2BadParameter)402 TEST_P(GraphicsComposerHidlTest, SetPowerMode_2_2BadParameter) {
403 Error error = mComposerClient->getRaw()->setPowerMode_2_2(
404 mPrimaryDisplay, static_cast<IComposerClient::PowerMode>(-1));
405 ASSERT_EQ(Error::BAD_PARAMETER, error);
406 }
407
408 /**
409 * Test IComposerClient::setPowerMode_2_2
410 *
411 * Test that IComposerClient::setPowerMode_2_2 returns UNSUPPORTED when passed
412 * DOZE or DOZE_SUPPORT on a device that does not support these modes
413 */
TEST_P(GraphicsComposerHidlTest,SetPowerMode_2_2Unsupported)414 TEST_P(GraphicsComposerHidlTest, SetPowerMode_2_2Unsupported) {
415 if (!mComposerClient->getDozeSupport(mPrimaryDisplay)) {
416 Error error = mComposerClient->getRaw()->setPowerMode_2_2(mPrimaryDisplay,
417 IComposerClient::PowerMode::DOZE);
418 EXPECT_EQ(Error::UNSUPPORTED, error);
419
420 error = mComposerClient->getRaw()->setPowerMode_2_2(
421 mPrimaryDisplay, IComposerClient::PowerMode::DOZE_SUSPEND);
422 EXPECT_EQ(Error::UNSUPPORTED, error);
423 }
424 }
425
426 /**
427 * Test IComposerClient::setReadbackBuffer
428 *
429 * Test IComposerClient::setReadbackBuffer
430 */
TEST_P(GraphicsComposerHidlTest,SetReadbackBuffer)431 TEST_P(GraphicsComposerHidlTest, SetReadbackBuffer) {
432 if (!mHasReadbackBuffer) {
433 return;
434 }
435
436 // BufferUsage::COMPOSER_OUTPUT is missing
437 uint64_t usage =
438 static_cast<uint64_t>(BufferUsage::COMPOSER_OVERLAY | BufferUsage::CPU_READ_OFTEN);
439
440 std::unique_ptr<Gralloc> gralloc;
441 std::unique_ptr<NativeHandleWrapper> buffer;
442 ASSERT_NO_FATAL_FAILURE(gralloc = std::make_unique<Gralloc>());
443 ASSERT_NO_FATAL_FAILURE(buffer.reset(new NativeHandleWrapper(
444 gralloc->allocate(mDisplayWidth, mDisplayHeight, 1, mReadbackPixelFormat, usage))));
445
446 mComposerClient->setReadbackBuffer(mPrimaryDisplay, buffer->get(), -1);
447 }
448
449 /**
450 * Test IComposerClient::setReadbackBuffer
451 *
452 * Test that IComposerClient::setReadbackBuffer returns an Error::BAD_DISPLAY
453 * when passed an invalid display handle
454 */
TEST_P(GraphicsComposerHidlTest,SetReadbackBufferBadDisplay)455 TEST_P(GraphicsComposerHidlTest, SetReadbackBufferBadDisplay) {
456 if (!mHasReadbackBuffer) {
457 return;
458 }
459
460 uint64_t usage =
461 static_cast<uint64_t>(BufferUsage::COMPOSER_OVERLAY | BufferUsage::CPU_READ_OFTEN);
462
463 std::unique_ptr<Gralloc> gralloc;
464 std::unique_ptr<NativeHandleWrapper> buffer;
465 ASSERT_NO_FATAL_FAILURE(gralloc = std::make_unique<Gralloc>());
466 ASSERT_NO_FATAL_FAILURE(buffer.reset(new NativeHandleWrapper(
467 gralloc->allocate(mDisplayWidth, mDisplayHeight, 1, mReadbackPixelFormat, usage))));
468
469 Error error =
470 mComposerClient->getRaw()->setReadbackBuffer(mInvalidDisplayId, buffer->get(), nullptr);
471 ASSERT_EQ(Error::BAD_DISPLAY, error);
472 }
473
474 /**
475 * Test IComposerClient::setReadbackBuffer
476 *
477 * Test that IComposerClient::setReadbackBuffer returns Error::BAD_PARAMETER
478 * when passed an invalid buffer handle
479 */
TEST_P(GraphicsComposerHidlTest,SetReadbackBufferBadParameter)480 TEST_P(GraphicsComposerHidlTest, SetReadbackBufferBadParameter) {
481 if (!mHasReadbackBuffer) {
482 return;
483 }
484
485 Error error = mComposerClient->getRaw()->setReadbackBuffer(mPrimaryDisplay, nullptr, nullptr);
486 ASSERT_EQ(Error::BAD_PARAMETER, error);
487 }
488
TEST_P(GraphicsComposerHidlTest,GetReadbackBufferFenceInactive)489 TEST_P(GraphicsComposerHidlTest, GetReadbackBufferFenceInactive) {
490 if (!mHasReadbackBuffer) {
491 return;
492 }
493
494 mComposerClient->getRaw()->getReadbackBufferFence(
495 mPrimaryDisplay, [&](const auto& tmpError, const auto&) {
496 ASSERT_EQ(Error::UNSUPPORTED, tmpError) << "readback buffer is active";
497 });
498 }
499
500 /**
501 * Test IComposerClient::Command::SET_LAYER_FLOAT_COLOR.
502 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_FLOAT_COLOR)503 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_FLOAT_COLOR) {
504 V2_1::Layer layer;
505 ASSERT_NO_FATAL_FAILURE(layer =
506 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
507
508 mWriter->selectDisplay(mPrimaryDisplay);
509 mWriter->selectLayer(layer);
510 mWriter->setLayerCompositionType(IComposerClient::Composition::SOLID_COLOR);
511 mWriter->setLayerFloatColor(IComposerClient::FloatColor{1.0, 1.0, 1.0, 1.0});
512 mWriter->setLayerFloatColor(IComposerClient::FloatColor{0.0, 0.0, 0.0, 0.0});
513 execute();
514
515 if (mReader->mErrors.size() == 2 &&
516 static_cast<Error>(mReader->mErrors[0].second) == Error::UNSUPPORTED &&
517 static_cast<Error>(mReader->mErrors[1].second) == Error::UNSUPPORTED) {
518 mReader->mErrors.clear();
519 GTEST_SUCCEED() << "SetLayerFloatColor is not supported";
520 return;
521 }
522
523 // ensure setting float color on layer with composition type that is not
524 // SOLID_COLOR does not fail
525 V2_1::Layer clientLayer;
526 ASSERT_NO_FATAL_FAILURE(clientLayer =
527 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
528 mWriter->selectDisplay(mPrimaryDisplay);
529 mWriter->selectLayer(clientLayer);
530 mWriter->setLayerCompositionType(IComposerClient::Composition::CLIENT);
531 mWriter->setLayerFloatColor(IComposerClient::FloatColor{1.0, 1.0, 1.0, 1.0});
532 execute();
533
534 // At this point we know that this function is supported so there should be
535 // no errors (checked upon TearDown)
536 }
537
538 /**
539 * Test IComposerClient::getDataspaceSaturationMatrix.
540 */
TEST_P(GraphicsComposerHidlTest,GetDataspaceSaturationMatrix)541 TEST_P(GraphicsComposerHidlTest, GetDataspaceSaturationMatrix) {
542 auto matrix = mComposerClient->getDataspaceSaturationMatrix(Dataspace::SRGB_LINEAR);
543 // the last row is known
544 ASSERT_EQ(0.0f, matrix[12]);
545 ASSERT_EQ(0.0f, matrix[13]);
546 ASSERT_EQ(0.0f, matrix[14]);
547 ASSERT_EQ(1.0f, matrix[15]);
548 }
549
550 /*
551 * Test IComposerClient::getDataspaceSaturationMatrix
552 *
553 * Test that IComposerClient::getDataspaceSaturationMatrix returns
554 * Error::BAD_PARAMETER when passed a dataspace other than
555 * Dataspace::SRGB_LINEAR
556 */
TEST_P(GraphicsComposerHidlTest,GetDataspaceSaturationMatrixBadParameter)557 TEST_P(GraphicsComposerHidlTest, GetDataspaceSaturationMatrixBadParameter) {
558 mComposerClient->getRaw()->getDataspaceSaturationMatrix(
559 Dataspace::UNKNOWN,
560 [&](const auto& tmpError, const auto&) { ASSERT_EQ(Error::BAD_PARAMETER, tmpError); });
561 }
562
563 /**
564 * Test IComposerClient::getColorMode_2_2.
565 */
TEST_P(GraphicsComposerHidlTest,GetColorMode_2_2)566 TEST_P(GraphicsComposerHidlTest, GetColorMode_2_2) {
567 std::vector<ColorMode> modes = mComposerClient->getColorModes(mPrimaryDisplay);
568
569 auto nativeMode = std::find(modes.cbegin(), modes.cend(), ColorMode::NATIVE);
570 EXPECT_NE(modes.cend(), nativeMode);
571 }
572
573 /*
574 * Test IComposerClient::getColorMode_2_2
575 *
576 * Test that IComposerClient::getColorMode returns Error::BAD_DISPLAY when
577 * passed an invalid display handle
578 */
TEST_P(GraphicsComposerHidlTest,GetColorMode_2_2BadDisplay)579 TEST_P(GraphicsComposerHidlTest, GetColorMode_2_2BadDisplay) {
580 mComposerClient->getRaw()->getColorModes_2_2(
581 mInvalidDisplayId,
582 [&](const auto& tmpError, const auto&) { ASSERT_EQ(Error::BAD_DISPLAY, tmpError); });
583 }
584
585 /**
586 * Test IComposerClient::getRenderIntents.
587 */
TEST_P(GraphicsComposerHidlTest,GetRenderIntents)588 TEST_P(GraphicsComposerHidlTest, GetRenderIntents) {
589 std::vector<ColorMode> modes = mComposerClient->getColorModes(mPrimaryDisplay);
590 for (auto mode : modes) {
591 std::vector<RenderIntent> intents =
592 mComposerClient->getRenderIntents(mPrimaryDisplay, mode);
593
594 bool isHdr;
595 switch (mode) {
596 case ColorMode::BT2100_PQ:
597 case ColorMode::BT2100_HLG:
598 isHdr = true;
599 break;
600 default:
601 isHdr = false;
602 break;
603 }
604 RenderIntent requiredIntent =
605 isHdr ? RenderIntent::TONE_MAP_COLORIMETRIC : RenderIntent::COLORIMETRIC;
606
607 auto iter = std::find(intents.cbegin(), intents.cend(), requiredIntent);
608 EXPECT_NE(intents.cend(), iter);
609 }
610 }
611
612 /*
613 * Test IComposerClient::getRenderIntents
614 *
615 * Test that IComposerClient::getRenderIntent returns Error::BAD_DISPLAY when
616 * passed an invalid display handle
617 */
TEST_P(GraphicsComposerHidlTest,GetRenderIntentsBadDisplay)618 TEST_P(GraphicsComposerHidlTest, GetRenderIntentsBadDisplay) {
619 std::vector<ColorMode> modes = mComposerClient->getColorModes(mPrimaryDisplay);
620 for (auto mode : modes) {
621 mComposerClient->getRaw()->getRenderIntents(
622 mInvalidDisplayId, mode,
623 [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::BAD_DISPLAY, tmpError); });
624 }
625 }
626
627 /*
628 * Test IComposerClient::getRenderIntents
629 *
630 * Test that IComposerClient::getRenderIntents returns Error::BAD_PARAMETER when
631 * pased either an invalid Color mode or an invalid Render Intent
632 */
TEST_P(GraphicsComposerHidlTest,GetRenderIntentsBadParameter)633 TEST_P(GraphicsComposerHidlTest, GetRenderIntentsBadParameter) {
634 mComposerClient->getRaw()->getRenderIntents(
635 mPrimaryDisplay, static_cast<ColorMode>(-1),
636 [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::BAD_PARAMETER, tmpError); });
637 }
638
639 /**
640 * Test IComposerClient::setColorMode_2_2.
641 */
TEST_P(GraphicsComposerHidlTest,SetColorMode_2_2)642 TEST_P(GraphicsComposerHidlTest, SetColorMode_2_2) {
643 std::vector<ColorMode> modes = mComposerClient->getColorModes(mPrimaryDisplay);
644 for (auto mode : modes) {
645 std::vector<RenderIntent> intents =
646 mComposerClient->getRenderIntents(mPrimaryDisplay, mode);
647 for (auto intent : intents) {
648 mComposerClient->setColorMode(mPrimaryDisplay, mode, intent);
649 }
650 }
651
652 mComposerClient->setColorMode(mPrimaryDisplay, ColorMode::NATIVE, RenderIntent::COLORIMETRIC);
653 }
654
655 /*
656 * Test IComposerClient::setColorMode_2_2
657 *
658 * Test that IComposerClient::setColorMode_2_2 returns an Error::BAD_DISPLAY
659 * when passed an invalid display handle
660 */
TEST_P(GraphicsComposerHidlTest,SetColorMode_2_2BadDisplay)661 TEST_P(GraphicsComposerHidlTest, SetColorMode_2_2BadDisplay) {
662 Error error = mComposerClient->getRaw()->setColorMode_2_2(mInvalidDisplayId, ColorMode::NATIVE,
663 RenderIntent::COLORIMETRIC);
664
665 ASSERT_EQ(Error::BAD_DISPLAY, error);
666 }
667
668 /*
669 * Test IComposerClient::setColorMode_2_2
670 *
671 * Test that IComposerClient::setColorMode_2_2 returns Error::BAD_PARAMETER when
672 * passed an invalid Color mode or an invalid render intent
673 */
TEST_P(GraphicsComposerHidlTest,SetColorMode_2_2BadParameter)674 TEST_P(GraphicsComposerHidlTest, SetColorMode_2_2BadParameter) {
675 Error colorModeError = mComposerClient->getRaw()->setColorMode_2_2(
676 mPrimaryDisplay, static_cast<ColorMode>(-1), RenderIntent::COLORIMETRIC);
677 EXPECT_EQ(Error::BAD_PARAMETER, colorModeError);
678
679 Error renderIntentError = mComposerClient->getRaw()->setColorMode_2_2(
680 mPrimaryDisplay, ColorMode::NATIVE, static_cast<RenderIntent>(-1));
681 EXPECT_EQ(Error::BAD_PARAMETER, renderIntentError);
682 }
683
684 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerHidlTest);
685 INSTANTIATE_TEST_SUITE_P(
686 PerInstance, GraphicsComposerHidlTest,
687 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IComposer::descriptor)),
688 android::hardware::PrintInstanceNameToString);
689
690 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerHidlCommandTest);
691 INSTANTIATE_TEST_SUITE_P(
692 PerInstance, GraphicsComposerHidlCommandTest,
693 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IComposer::descriptor)),
694 android::hardware::PrintInstanceNameToString);
695
696 } // namespace
697 } // namespace vts
698 } // namespace V2_2
699 } // namespace composer
700 } // namespace graphics
701 } // namespace hardware
702 } // namespace android
703
main(int argc,char ** argv)704 int main(int argc, char** argv) {
705 ::testing::InitGoogleTest(&argc, argv);
706
707 using namespace std::chrono_literals;
708 if (!android::base::WaitForProperty("init.svc.surfaceflinger", "stopped", 10s)) {
709 ALOGE("Failed to stop init.svc.surfaceflinger");
710 return -1;
711 }
712
713 return RUN_ALL_TESTS();
714 }