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