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