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