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.3"
18
19 #include <algorithm>
20
21 #include <VtsHalHidlTargetTestBase.h>
22 #include <android-base/logging.h>
23 #include <android/hardware/graphics/mapper/2.0/IMapper.h>
24 #include <composer-command-buffer/2.3/ComposerCommandBuffer.h>
25 #include <composer-vts/2.1/GraphicsComposerCallback.h>
26 #include <composer-vts/2.1/TestCommandReader.h>
27 #include <composer-vts/2.3/ComposerVts.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_3 {
35 namespace vts {
36 namespace {
37
38 using common::V1_0::BufferUsage;
39 using common::V1_1::RenderIntent;
40 using common::V1_2::ColorMode;
41 using common::V1_2::Dataspace;
42 using common::V1_2::PixelFormat;
43 using mapper::V2_0::IMapper;
44 using V2_2::vts::Gralloc;
45
46 // Test environment for graphics.composer
47 class GraphicsComposerHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
48 public:
49 // get the test environment singleton
Instance()50 static GraphicsComposerHidlEnvironment* Instance() {
51 static GraphicsComposerHidlEnvironment* instance = new GraphicsComposerHidlEnvironment;
52 return instance;
53 }
54
registerTestServices()55 virtual void registerTestServices() override { registerTestService<IComposer>(); }
56
57 private:
GraphicsComposerHidlEnvironment()58 GraphicsComposerHidlEnvironment() {}
59
60 GTEST_DISALLOW_COPY_AND_ASSIGN_(GraphicsComposerHidlEnvironment);
61 };
62
63 class GraphicsComposerHidlTest : public ::testing::VtsHalHidlTargetTestBase {
64 protected:
SetUp()65 void SetUp() override {
66 ASSERT_NO_FATAL_FAILURE(
67 mComposer = std::make_unique<Composer>(
68 GraphicsComposerHidlEnvironment::Instance()->getServiceName<IComposer>()));
69 ASSERT_NO_FATAL_FAILURE(mComposerClient = mComposer->createClient());
70
71 mComposerCallback = new V2_1::vts::GraphicsComposerCallback;
72 mComposerClient->registerCallback(mComposerCallback);
73
74 // assume the first display is primary and is never removed
75 mPrimaryDisplay = waitForFirstDisplay();
76
77 mInvalidDisplayId = GetInvalidDisplayId();
78
79 // explicitly disable vsync
80 mComposerClient->setVsyncEnabled(mPrimaryDisplay, false);
81 mComposerCallback->setVsyncAllowed(false);
82
83 mWriter = std::make_unique<CommandWriterBase>(1024);
84 mReader = std::make_unique<V2_1::vts::TestCommandReader>();
85 }
86
TearDown()87 void TearDown() override {
88 ASSERT_EQ(0, mReader->mErrors.size());
89 ASSERT_EQ(0, mReader->mCompositionChanges.size());
90 if (mComposerCallback != nullptr) {
91 EXPECT_EQ(0, mComposerCallback->getInvalidHotplugCount());
92 EXPECT_EQ(0, mComposerCallback->getInvalidRefreshCount());
93 EXPECT_EQ(0, mComposerCallback->getInvalidVsyncCount());
94 }
95 }
96
97 // returns an invalid display id (one that has not been registered to a
98 // display. Currently assuming that a device will never have close to
99 // std::numeric_limit<uint64_t>::max() displays registered while running tests
GetInvalidDisplayId()100 Display GetInvalidDisplayId() {
101 std::vector<Display> validDisplays = mComposerCallback->getDisplays();
102 uint64_t id = std::numeric_limits<uint64_t>::max();
103 while (id > 0) {
104 if (std::find(validDisplays.begin(), validDisplays.end(), id) == validDisplays.end()) {
105 return id;
106 }
107 id--;
108 }
109
110 return 0;
111 }
112
execute()113 void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
114
115 // use the slot count usually set by SF
116 static constexpr uint32_t kBufferSlotCount = 64;
117
118 std::unique_ptr<Composer> mComposer;
119 std::unique_ptr<ComposerClient> mComposerClient;
120 sp<V2_1::vts::GraphicsComposerCallback> mComposerCallback;
121 // the first display and is assumed never to be removed
122 Display mPrimaryDisplay;
123 Display mInvalidDisplayId;
124 std::unique_ptr<CommandWriterBase> mWriter;
125 std::unique_ptr<V2_1::vts::TestCommandReader> mReader;
126
127 private:
waitForFirstDisplay()128 Display waitForFirstDisplay() {
129 while (true) {
130 std::vector<Display> displays = mComposerCallback->getDisplays();
131 if (displays.empty()) {
132 usleep(5 * 1000);
133 continue;
134 }
135
136 return displays[0];
137 }
138 }
139 };
140
141 // Tests for IComposerClient::Command.
142 class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
143 protected:
SetUp()144 void SetUp() override {
145 ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::SetUp());
146
147 ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>());
148
149 mWriter = std::make_unique<CommandWriterBase>(1024);
150 mReader = std::make_unique<V2_1::vts::TestCommandReader>();
151 }
152
TearDown()153 void TearDown() override {
154 ASSERT_EQ(0, mReader->mErrors.size());
155 ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::TearDown());
156 }
157
allocate()158 const native_handle_t* allocate() {
159 return mGralloc->allocate(
160 64, 64, 1, static_cast<common::V1_1::PixelFormat>(PixelFormat::RGBA_8888),
161 static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN));
162 }
163
execute()164 void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
165
166 std::unique_ptr<CommandWriterBase> mWriter;
167 std::unique_ptr<V2_1::vts::TestCommandReader> mReader;
168
169 private:
170 std::unique_ptr<Gralloc> mGralloc;
171 };
172
173 /**
174 * Test IComposerClient::getDisplayIdentificationData.
175 *
176 * TODO: Check that ports are unique for multiple displays.
177 */
TEST_F(GraphicsComposerHidlTest,GetDisplayIdentificationData)178 TEST_F(GraphicsComposerHidlTest, GetDisplayIdentificationData) {
179 uint8_t port0;
180 std::vector<uint8_t> data0;
181 if (mComposerClient->getDisplayIdentificationData(mPrimaryDisplay, &port0, &data0)) {
182 uint8_t port1;
183 std::vector<uint8_t> data1;
184 ASSERT_TRUE(mComposerClient->getDisplayIdentificationData(mPrimaryDisplay, &port1, &data1));
185
186 ASSERT_EQ(port0, port1) << "ports are not stable";
187 ASSERT_TRUE(data0.size() == data1.size() &&
188 std::equal(data0.begin(), data0.end(), data1.begin()))
189 << "data is not stable";
190 }
191 }
192
193 /**
194 * Test IComposerClient::Command::SET_LAYER_PER_FRAME_METADATA.
195 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_PER_FRAME_METADATA)196 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_PER_FRAME_METADATA) {
197 Layer layer;
198 ASSERT_NO_FATAL_FAILURE(layer =
199 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
200
201 mWriter->selectDisplay(mPrimaryDisplay);
202 mWriter->selectLayer(layer);
203
204 /**
205 * DISPLAY_P3 is a color space that uses the DCI_P3 primaries,
206 * the D65 white point and the SRGB transfer functions.
207 * Rendering Intent: Colorimetric
208 * Primaries:
209 * x y
210 * green 0.265 0.690
211 * blue 0.150 0.060
212 * red 0.680 0.320
213 * white (D65) 0.3127 0.3290
214 */
215
216 std::vector<IComposerClient::PerFrameMetadata> hidlMetadata;
217 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, 0.680});
218 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, 0.320});
219 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, 0.265});
220 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, 0.690});
221 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, 0.150});
222 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, 0.060});
223 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::WHITE_POINT_X, 0.3127});
224 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::WHITE_POINT_Y, 0.3290});
225 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::MAX_LUMINANCE, 100.0});
226 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::MIN_LUMINANCE, 0.1});
227 hidlMetadata.push_back({IComposerClient::PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, 78.0});
228 hidlMetadata.push_back(
229 {IComposerClient::PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, 62.0});
230 mWriter->setLayerPerFrameMetadata(hidlMetadata);
231 execute();
232
233 if (mReader->mErrors.size() == 1 &&
234 static_cast<Error>(mReader->mErrors[0].second) == Error::UNSUPPORTED) {
235 mReader->mErrors.clear();
236 GTEST_SUCCEED() << "SetLayerPerFrameMetadata is not supported";
237 ASSERT_NO_FATAL_FAILURE(mComposerClient->destroyLayer(mPrimaryDisplay, layer));
238 return;
239 }
240
241 ASSERT_NO_FATAL_FAILURE(mComposerClient->destroyLayer(mPrimaryDisplay, layer));
242 }
243
244 /**
245 * Test IComposerClient::getHdrCapabilities_2_3
246 */
TEST_F(GraphicsComposerHidlTest,GetHdrCapabilities_2_3)247 TEST_F(GraphicsComposerHidlTest, GetHdrCapabilities_2_3) {
248 float maxLuminance;
249 float maxAverageLuminance;
250 float minLuminance;
251 ASSERT_NO_FATAL_FAILURE(mComposerClient->getHdrCapabilities_2_3(
252 mPrimaryDisplay, &maxLuminance, &maxAverageLuminance, &minLuminance));
253 ASSERT_TRUE(maxLuminance >= minLuminance);
254 }
255
256 /**
257 * Test IComposerClient::getPerFrameMetadataKeys_2_3
258 */
TEST_F(GraphicsComposerHidlTest,GetPerFrameMetadataKeys_2_3)259 TEST_F(GraphicsComposerHidlTest, GetPerFrameMetadataKeys_2_3) {
260 std::vector<IComposerClient::PerFrameMetadataKey> keys;
261 mComposerClient->getRaw()->getPerFrameMetadataKeys_2_3(
262 mPrimaryDisplay, [&](const auto tmpError, const auto outKeys) {
263 if (tmpError != Error::UNSUPPORTED) {
264 ASSERT_EQ(Error::NONE, tmpError);
265 keys = outKeys;
266 }
267 });
268 }
269
270 /**
271 * TestIComposerClient::getReadbackBufferAttributes_2_3
272 */
TEST_F(GraphicsComposerHidlTest,GetReadbackBufferAttributes_2_3)273 TEST_F(GraphicsComposerHidlTest, GetReadbackBufferAttributes_2_3) {
274 Dataspace dataspace;
275 PixelFormat pixelFormat;
276
277 mComposerClient->getRaw()->getReadbackBufferAttributes_2_3(
278 mPrimaryDisplay,
279 [&](const auto tmpError, const auto outPixelFormat, const auto outDataspace) {
280 if (tmpError != Error::UNSUPPORTED) {
281 ASSERT_EQ(Error::NONE, tmpError);
282 dataspace = outDataspace;
283 pixelFormat = outPixelFormat;
284 }
285 });
286 }
287
288 /**
289 * Test IComposerClient::getClientTargetSupport_2_3
290 */
TEST_F(GraphicsComposerHidlTest,GetClientTargetSupport_2_3)291 TEST_F(GraphicsComposerHidlTest, GetClientTargetSupport_2_3) {
292 std::vector<V2_1::Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
293 for (auto config : configs) {
294 int32_t width = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
295 IComposerClient::Attribute::WIDTH);
296 int32_t height = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
297 IComposerClient::Attribute::HEIGHT);
298 ASSERT_LT(0, width);
299 ASSERT_LT(0, height);
300
301 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
302
303 ASSERT_TRUE(mComposerClient->getClientTargetSupport_2_3(
304 mPrimaryDisplay, width, height, PixelFormat::RGBA_8888, Dataspace::UNKNOWN));
305 }
306 }
307 /**
308 * Test IComposerClient::getClientTargetSupport_2_3
309 *
310 * Test that IComposerClient::getClientTargetSupport_2_3 returns
311 * Error::BAD_DISPLAY when passed in an invalid display handle
312 */
313
TEST_F(GraphicsComposerHidlTest,GetClientTargetSupport_2_3BadDisplay)314 TEST_F(GraphicsComposerHidlTest, GetClientTargetSupport_2_3BadDisplay) {
315 std::vector<V2_1::Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
316 for (auto config : configs) {
317 int32_t width = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
318 IComposerClient::Attribute::WIDTH);
319 int32_t height = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
320 IComposerClient::Attribute::HEIGHT);
321 ASSERT_LT(0, width);
322 ASSERT_LT(0, height);
323
324 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
325
326 Error error = mComposerClient->getRaw()->getClientTargetSupport_2_3(
327 mInvalidDisplayId, width, height, PixelFormat::RGBA_8888, Dataspace::UNKNOWN);
328
329 EXPECT_EQ(Error::BAD_DISPLAY, error);
330 }
331 }
332
333 /**
334 * Test IComposerClient::getRenderIntents_2_3
335 */
TEST_F(GraphicsComposerHidlTest,GetRenderIntents_2_3)336 TEST_F(GraphicsComposerHidlTest, GetRenderIntents_2_3) {
337 std::vector<ColorMode> modes = mComposerClient->getColorModes_2_3(mPrimaryDisplay);
338 for (auto mode : modes) {
339 std::vector<RenderIntent> intents =
340 mComposerClient->getRenderIntents_2_3(mPrimaryDisplay, mode);
341
342 bool isHdr;
343 switch (mode) {
344 case ColorMode::BT2100_PQ:
345 case ColorMode::BT2100_HLG:
346 isHdr = true;
347 break;
348 default:
349 isHdr = false;
350 break;
351 }
352 RenderIntent requiredIntent =
353 isHdr ? RenderIntent::TONE_MAP_COLORIMETRIC : RenderIntent::COLORIMETRIC;
354
355 auto iter = std::find(intents.cbegin(), intents.cend(), requiredIntent);
356 EXPECT_NE(intents.cend(), iter);
357 }
358 }
359
360 /*
361 * Test IComposerClient::getRenderIntents_2_3
362 *
363 * Test that IComposerClient::getRenderIntents_2_3 returns Error::BAD_DISPLAY when
364 * passed an invalid display handle
365 */
TEST_F(GraphicsComposerHidlTest,GetRenderIntents_2_3BadDisplay)366 TEST_F(GraphicsComposerHidlTest, GetRenderIntents_2_3BadDisplay) {
367 std::vector<ColorMode> modes = mComposerClient->getColorModes_2_3(mPrimaryDisplay);
368 for (auto mode : modes) {
369 mComposerClient->getRaw()->getRenderIntents_2_3(
370 mInvalidDisplayId, mode,
371 [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::BAD_DISPLAY, tmpError); });
372 }
373 }
374
375 /*
376 * Test IComposerClient::getRenderIntents_2_3
377 *
378 * Test that IComposerClient::getRenderIntents_2_3 returns Error::BAD_PARAMETER when
379 * pased either an invalid Color mode or an invalid Render Intent
380 */
TEST_F(GraphicsComposerHidlTest,GetRenderIntents_2_3BadParameter)381 TEST_F(GraphicsComposerHidlTest, GetRenderIntents_2_3BadParameter) {
382 mComposerClient->getRaw()->getRenderIntents_2_3(
383 mPrimaryDisplay, static_cast<ColorMode>(-1),
384 [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::BAD_PARAMETER, tmpError); });
385 }
386
387 /**
388 * IComposerClient::getColorModes_2_3
389 */
TEST_F(GraphicsComposerHidlTest,GetColorModes_2_3)390 TEST_F(GraphicsComposerHidlTest, GetColorModes_2_3) {
391 std::vector<ColorMode> colorModes = mComposerClient->getColorModes_2_3(mPrimaryDisplay);
392
393 auto native = std::find(colorModes.cbegin(), colorModes.cend(), ColorMode::NATIVE);
394 ASSERT_NE(colorModes.cend(), native);
395 }
396
397 /*
398 * Test IComposerClient::getColorModes_2_3
399 *
400 * Test that IComposerClient::getColorModes_2_3 returns Error::BAD_DISPLAY when
401 * passed an invalid display handle
402 */
TEST_F(GraphicsComposerHidlTest,GetColorMode_2_3BadDisplay)403 TEST_F(GraphicsComposerHidlTest, GetColorMode_2_3BadDisplay) {
404 mComposerClient->getRaw()->getColorModes_2_3(
405 mInvalidDisplayId,
406 [&](const auto& tmpError, const auto&) { ASSERT_EQ(Error::BAD_DISPLAY, tmpError); });
407 }
408
409 /**
410 * IComposerClient::setColorMode_2_3
411 */
TEST_F(GraphicsComposerHidlTest,SetColorMode_2_3)412 TEST_F(GraphicsComposerHidlTest, SetColorMode_2_3) {
413 std::vector<ColorMode> colorModes = mComposerClient->getColorModes_2_3(mPrimaryDisplay);
414 for (auto mode : colorModes) {
415 std::vector<RenderIntent> intents =
416 mComposerClient->getRenderIntents_2_3(mPrimaryDisplay, mode);
417 for (auto intent : intents) {
418 ASSERT_NO_FATAL_FAILURE(
419 mComposerClient->setColorMode_2_3(mPrimaryDisplay, mode, intent));
420 }
421 }
422
423 ASSERT_NO_FATAL_FAILURE(mComposerClient->setColorMode_2_3(mPrimaryDisplay, ColorMode::NATIVE,
424 RenderIntent::COLORIMETRIC));
425 }
426
427 /*
428 * Test IComposerClient::setColorMode_2_3
429 *
430 * Test that IComposerClient::setColorMode_2_3 returns an Error::BAD_DISPLAY
431 * when passed an invalid display handle
432 */
TEST_F(GraphicsComposerHidlTest,SetColorMode_2_3BadDisplay)433 TEST_F(GraphicsComposerHidlTest, SetColorMode_2_3BadDisplay) {
434 Error error = mComposerClient->getRaw()->setColorMode_2_3(mInvalidDisplayId, ColorMode::NATIVE,
435 RenderIntent::COLORIMETRIC);
436
437 ASSERT_EQ(Error::BAD_DISPLAY, error);
438 }
439
440 /*
441 * Test IComposerClient::setColorMode_2_3
442 *
443 * Test that IComposerClient::setColorMode_2_3 returns Error::BAD_PARAMETER when
444 * passed an invalid Color mode or an invalid render intent
445 */
TEST_F(GraphicsComposerHidlTest,SetColorMode_2_3BadParameter)446 TEST_F(GraphicsComposerHidlTest, SetColorMode_2_3BadParameter) {
447 Error colorModeError = mComposerClient->getRaw()->setColorMode_2_3(
448 mPrimaryDisplay, static_cast<ColorMode>(-1), RenderIntent::COLORIMETRIC);
449 EXPECT_EQ(Error::BAD_PARAMETER, colorModeError);
450
451 Error renderIntentError = mComposerClient->getRaw()->setColorMode_2_3(
452 mPrimaryDisplay, ColorMode::NATIVE, static_cast<RenderIntent>(-1));
453 EXPECT_EQ(Error::BAD_PARAMETER, renderIntentError);
454 }
455
456 /**
457 * Test IComposerClient::Command::SET_LAYER_COLOR_TRANSFORM.
458 * TODO Add color to the layer, use matrix to keep only red component,
459 * and check.
460 */
TEST_F(GraphicsComposerHidlTest,SetLayerColorTransform)461 TEST_F(GraphicsComposerHidlTest, SetLayerColorTransform) {
462 Layer layer;
463 ASSERT_NO_FATAL_FAILURE(layer =
464 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
465 mWriter->selectDisplay(mPrimaryDisplay);
466 mWriter->selectLayer(layer);
467
468 // clang-format off
469 const std::array<float, 16> matrix = {{
470 1.0f, 0.0f, 0.0f, 0.0f,
471 0.0f, 1.0f, 0.0f, 0.0f,
472 0.0f, 0.0f, 1.0f, 0.0f,
473 0.0f, 0.0f, 0.0f, 1.0f,
474 }};
475 // clang-format on
476
477 mWriter->setLayerColorTransform(matrix.data());
478 execute();
479
480 if (mReader->mErrors.size() == 1 &&
481 static_cast<Error>(mReader->mErrors[0].second) == Error::UNSUPPORTED) {
482 mReader->mErrors.clear();
483 GTEST_SUCCEED() << "setLayerColorTransform is not supported";
484 return;
485 }
486 }
487
TEST_F(GraphicsComposerHidlTest,GetDisplayedContentSamplingAttributes)488 TEST_F(GraphicsComposerHidlTest, GetDisplayedContentSamplingAttributes) {
489 int constexpr invalid = -1;
490 auto format = static_cast<PixelFormat>(invalid);
491 auto dataspace = static_cast<Dataspace>(invalid);
492 auto componentMask = static_cast<hidl_bitfield<IComposerClient::FormatColorComponent>>(invalid);
493 auto error = mComposerClient->getDisplayedContentSamplingAttributes(mPrimaryDisplay, format,
494 dataspace, componentMask);
495
496 if (error == Error::UNSUPPORTED) {
497 SUCCEED() << "Device does not support optional extension. Test skipped";
498 return;
499 }
500
501 EXPECT_EQ(error, Error::NONE);
502 EXPECT_NE(format, static_cast<PixelFormat>(invalid));
503 EXPECT_NE(dataspace, static_cast<Dataspace>(invalid));
504 EXPECT_NE(componentMask,
505 static_cast<hidl_bitfield<IComposerClient::FormatColorComponent>>(invalid));
506 };
507
TEST_F(GraphicsComposerHidlTest,SetDisplayedContentSamplingEnabled)508 TEST_F(GraphicsComposerHidlTest, SetDisplayedContentSamplingEnabled) {
509 auto const maxFrames = 10;
510 auto const enableAllComponents = 0;
511 auto error = mComposerClient->setDisplayedContentSamplingEnabled(
512 mPrimaryDisplay, IComposerClient::DisplayedContentSampling::ENABLE, enableAllComponents,
513 maxFrames);
514 if (error == Error::UNSUPPORTED) {
515 SUCCEED() << "Device does not support optional extension. Test skipped";
516 return;
517 }
518 EXPECT_EQ(error, Error::NONE);
519
520 error = mComposerClient->setDisplayedContentSamplingEnabled(
521 mPrimaryDisplay, IComposerClient::DisplayedContentSampling::DISABLE, enableAllComponents,
522 maxFrames);
523 EXPECT_EQ(error, Error::NONE);
524 }
525
TEST_F(GraphicsComposerHidlTest,GetDisplayedContentSample)526 TEST_F(GraphicsComposerHidlTest, GetDisplayedContentSample) {
527 int constexpr invalid = -1;
528 auto format = static_cast<PixelFormat>(invalid);
529 auto dataspace = static_cast<Dataspace>(invalid);
530 auto componentMask = static_cast<hidl_bitfield<IComposerClient::FormatColorComponent>>(invalid);
531 auto error = mComposerClient->getDisplayedContentSamplingAttributes(mPrimaryDisplay, format,
532 dataspace, componentMask);
533
534 uint64_t maxFrames = 10;
535 uint64_t timestamp = 0;
536 uint64_t frameCount = 0;
537 hidl_array<hidl_vec<uint64_t>, 4> histogram;
538 error = mComposerClient->getDisplayedContentSample(mPrimaryDisplay, maxFrames, timestamp,
539 frameCount, histogram[0], histogram[1],
540 histogram[2], histogram[3]);
541 if (error == Error::UNSUPPORTED) {
542 SUCCEED() << "Device does not support optional extension. Test skipped";
543 return;
544 }
545
546 EXPECT_EQ(error, Error::NONE);
547 EXPECT_LE(frameCount, maxFrames);
548 for (auto i = 0; i < histogram.size(); i++) {
549 if (componentMask & (1 << i)) {
550 EXPECT_NE(histogram[i].size(), 0);
551 } else {
552 EXPECT_EQ(histogram[i].size(), 0);
553 }
554 }
555 }
556
557 /*
558 * getDisplayCapabilities is required in composer 2.3
559 * Test some constraints.
560 */
TEST_F(GraphicsComposerHidlTest,getDisplayCapabilitiesBasic)561 TEST_F(GraphicsComposerHidlTest, getDisplayCapabilitiesBasic) {
562 std::vector<IComposerClient::DisplayCapability> capabilities;
563 const auto error = mComposerClient->getDisplayCapabilities(mPrimaryDisplay, &capabilities);
564 ASSERT_EQ(Error::NONE, error);
565 const bool hasDozeSupport =
566 std::find(capabilities.begin(), capabilities.end(),
567 IComposerClient::DisplayCapability::DOZE) != capabilities.end();
568 EXPECT_EQ(mComposerClient->getDozeSupport(mPrimaryDisplay), hasDozeSupport);
569 bool hasBrightnessSupport =
570 std::find(capabilities.begin(), capabilities.end(),
571 IComposerClient::DisplayCapability::BRIGHTNESS) != capabilities.end();
572 EXPECT_EQ(mComposerClient->getDisplayBrightnessSupport(mPrimaryDisplay), hasBrightnessSupport);
573 }
574
TEST_F(GraphicsComposerHidlTest,getDisplayCapabilitiesBadDisplay)575 TEST_F(GraphicsComposerHidlTest, getDisplayCapabilitiesBadDisplay) {
576 std::vector<IComposerClient::DisplayCapability> capabilities;
577 const auto error = mComposerClient->getDisplayCapabilities(mInvalidDisplayId, &capabilities);
578 EXPECT_EQ(Error::BAD_DISPLAY, error);
579 }
580
TEST_F(GraphicsComposerHidlTest,SetLayerPerFrameMetadataBlobs)581 TEST_F(GraphicsComposerHidlTest, SetLayerPerFrameMetadataBlobs) {
582 Layer layer;
583 ASSERT_NO_FATAL_FAILURE(layer =
584 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
585
586 mWriter->selectDisplay(mPrimaryDisplay);
587 mWriter->selectLayer(layer);
588
589 std::vector<IComposerClient::PerFrameMetadataBlob> metadata;
590 metadata.push_back(
591 {IComposerClient::PerFrameMetadataKey::HDR10_PLUS_SEI, std::vector<uint8_t>(1, 0xff)});
592
593 mWriter->setLayerPerFrameMetadataBlobs(metadata);
594 execute();
595
596 if (mReader->mErrors.size() == 1 &&
597 static_cast<Error>(mReader->mErrors[0].second) == Error::UNSUPPORTED) {
598 mReader->mErrors.clear();
599 GTEST_SUCCEED() << "setLayerDynamicPerFrameMetadata is not supported";
600 return;
601 }
602 }
603
604 /*
605 * Test that if brightness operations are supported, setDisplayBrightness works as expected.
606 */
TEST_F(GraphicsComposerHidlTest,setDisplayBrightness)607 TEST_F(GraphicsComposerHidlTest, setDisplayBrightness) {
608 std::vector<IComposerClient::DisplayCapability> capabilities;
609 const auto error = mComposerClient->getDisplayCapabilities(mPrimaryDisplay, &capabilities);
610 ASSERT_EQ(Error::NONE, error);
611 bool brightnessSupport =
612 std::find(capabilities.begin(), capabilities.end(),
613 IComposerClient::DisplayCapability::BRIGHTNESS) != capabilities.end();
614 if (!brightnessSupport) {
615 EXPECT_EQ(mComposerClient->getRaw()->setDisplayBrightness(mPrimaryDisplay, 0.5f),
616 Error::UNSUPPORTED);
617 GTEST_SUCCEED() << "Brightness operations are not supported";
618 return;
619 }
620
621 EXPECT_EQ(mComposerClient->setDisplayBrightness(mPrimaryDisplay, 0.0f), Error::NONE);
622 EXPECT_EQ(mComposerClient->setDisplayBrightness(mPrimaryDisplay, 0.5f), Error::NONE);
623 EXPECT_EQ(mComposerClient->setDisplayBrightness(mPrimaryDisplay, 1.0f), Error::NONE);
624 EXPECT_EQ(mComposerClient->setDisplayBrightness(mPrimaryDisplay, -1.0f), Error::NONE);
625
626 EXPECT_EQ(mComposerClient->setDisplayBrightness(mPrimaryDisplay, +2.0f), Error::BAD_PARAMETER);
627 EXPECT_EQ(mComposerClient->setDisplayBrightness(mPrimaryDisplay, -2.0f), Error::BAD_PARAMETER);
628 }
629
630 } // namespace
631 } // namespace vts
632 } // namespace V2_3
633 } // namespace composer
634 } // namespace graphics
635 } // namespace hardware
636 } // namespace android
637
main(int argc,char ** argv)638 int main(int argc, char** argv) {
639 using android::hardware::graphics::composer::V2_3::vts::GraphicsComposerHidlEnvironment;
640 ::testing::AddGlobalTestEnvironment(GraphicsComposerHidlEnvironment::Instance());
641 ::testing::InitGoogleTest(&argc, argv);
642 GraphicsComposerHidlEnvironment::Instance()->init(&argc, argv);
643 int status = RUN_ALL_TESTS();
644 return status;
645 }
646