1 /*
2 * Copyright (C) 2016 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"
18
19 #include <android-base/logging.h>
20 #include <android-base/properties.h>
21 #include <composer-vts/2.1/ComposerVts.h>
22 #include <composer-vts/2.1/GraphicsComposerCallback.h>
23 #include <composer-vts/2.1/TestCommandReader.h>
24 #include <gtest/gtest.h>
25 #include <hardware/hwcomposer2.h>
26 #include <hidl/GtestPrinter.h>
27 #include <hidl/ServiceManagement.h>
28 #include <ui/GraphicBuffer.h>
29
30 #include <unistd.h>
31
32 #include <algorithm>
33 #include <array>
34 #include <memory>
35 #include <mutex>
36 #include <unordered_set>
37 #include <vector>
38
39 namespace android {
40 namespace hardware {
41 namespace graphics {
42 namespace composer {
43 namespace V2_1 {
44 namespace vts {
45 namespace {
46
47 using android::hardware::graphics::common::V1_0::BufferUsage;
48 using android::hardware::graphics::common::V1_0::ColorMode;
49 using android::hardware::graphics::common::V1_0::ColorTransform;
50 using android::hardware::graphics::common::V1_0::Dataspace;
51 using android::hardware::graphics::common::V1_0::PixelFormat;
52 using android::hardware::graphics::common::V1_0::Transform;
53
54 class GraphicsComposerHidlTest : public ::testing::TestWithParam<std::string> {
55 protected:
SetUp()56 void SetUp() override {
57 ASSERT_NO_FATAL_FAILURE(
58 mComposer = std::make_unique<Composer>(IComposer::getService(GetParam())));
59 ASSERT_NO_FATAL_FAILURE(mComposerClient = mComposer->createClient());
60
61 mComposerCallback = new GraphicsComposerCallback;
62 mComposerClient->registerCallback(mComposerCallback);
63
64 // assume the first display is primary and is never removed
65 mPrimaryDisplay = waitForFirstDisplay();
66
67 // explicitly disable vsync
68 mComposerClient->setVsyncEnabled(mPrimaryDisplay, false);
69 mComposerCallback->setVsyncAllowed(false);
70
71 mInvalidDisplayId = GetInvalidDisplayId();
72
73 // Although 0 could be an invalid display, a return value of 0
74 // from GetInvalidDisplayId means all other ids are in use, a condition which
75 // we are assuming a device will never have
76 ASSERT_NE(0, mInvalidDisplayId);
77 }
78
TearDown()79 void TearDown() override {
80 if (mComposerCallback != nullptr) {
81 EXPECT_EQ(0, mComposerCallback->getInvalidHotplugCount());
82 EXPECT_EQ(0, mComposerCallback->getInvalidRefreshCount());
83 EXPECT_EQ(0, mComposerCallback->getInvalidVsyncCount());
84 }
85 }
86
87 // returns an invalid display id (one that has not been registered to a
88 // display. Currently assuming that a device will never have close to
89 // std::numeric_limit<uint64_t>::max() displays registered while running tests
GetInvalidDisplayId()90 Display GetInvalidDisplayId() {
91 std::vector<Display> validDisplays = mComposerCallback->getDisplays();
92
93 uint64_t id = std::numeric_limits<uint64_t>::max();
94 while (id > 0) {
95 if (std::find(validDisplays.begin(), validDisplays.end(), id) == validDisplays.end()) {
96 return id;
97 }
98 id--;
99 }
100
101 return 0;
102 }
103
104 // use the slot count usually set by SF
105 static constexpr uint32_t kBufferSlotCount = 64;
106
107 std::unique_ptr<Composer> mComposer;
108 std::unique_ptr<ComposerClient> mComposerClient;
109 sp<GraphicsComposerCallback> mComposerCallback;
110 // the first display and is assumed never to be removed
111 Display mPrimaryDisplay;
112 Display mInvalidDisplayId;
113
114 private:
waitForFirstDisplay()115 Display waitForFirstDisplay() {
116 while (true) {
117 std::vector<Display> displays = mComposerCallback->getDisplays();
118 if (displays.empty()) {
119 usleep(5 * 1000);
120 continue;
121 }
122
123 return displays[0];
124 }
125 }
126 };
127
128 /**
129 * Test IComposer::getCapabilities.
130 *
131 * Test that IComposer::getCapabilities returns no invalid capabilities.
132 */
TEST_P(GraphicsComposerHidlTest,GetCapabilities)133 TEST_P(GraphicsComposerHidlTest, GetCapabilities) {
134 auto capabilities = mComposer->getCapabilities();
135 ASSERT_EQ(capabilities.end(),
136 std::find(capabilities.begin(), capabilities.end(), IComposer::Capability::INVALID));
137 }
138
139 /**
140 * Test IComposer::dumpDebugInfo.
141 */
TEST_P(GraphicsComposerHidlTest,DumpDebugInfo)142 TEST_P(GraphicsComposerHidlTest, DumpDebugInfo) {
143 mComposer->dumpDebugInfo();
144 }
145
146 /**
147 * Test IComposer::createClient.
148 *
149 * Test that IComposerClient is a singleton.
150 */
TEST_P(GraphicsComposerHidlTest,CreateClientSingleton)151 TEST_P(GraphicsComposerHidlTest, CreateClientSingleton) {
152 mComposer->getRaw()->createClient(
153 [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::NO_RESOURCES, tmpError); });
154 }
155
156 /**
157 * Test IComposerClient::createVirtualDisplay and
158 * IComposerClient::destroyVirtualDisplay.
159 *
160 * Test that virtual displays can be created and has the correct display type.
161 */
TEST_P(GraphicsComposerHidlTest,CreateVirtualDisplay)162 TEST_P(GraphicsComposerHidlTest, CreateVirtualDisplay) {
163 if (mComposerClient->getMaxVirtualDisplayCount() == 0) {
164 GTEST_SUCCEED() << "no virtual display support";
165 return;
166 }
167
168 Display display;
169 PixelFormat format;
170 ASSERT_NO_FATAL_FAILURE(
171 display = mComposerClient->createVirtualDisplay(64, 64, PixelFormat::IMPLEMENTATION_DEFINED,
172 kBufferSlotCount, &format));
173
174 // test display type
175 IComposerClient::DisplayType type = mComposerClient->getDisplayType(display);
176 EXPECT_EQ(IComposerClient::DisplayType::VIRTUAL, type);
177
178 mComposerClient->destroyVirtualDisplay(display);
179 }
180
181 /**
182 * Test IComposerClient::destroyVirtualDisplay
183 *
184 * Test that passing a bad display handle to destroyVirtualDisplay
185 * returns a BAD_DISPLAY error
186 */
TEST_P(GraphicsComposerHidlTest,DestroyVirtualDisplayBadDisplay)187 TEST_P(GraphicsComposerHidlTest, DestroyVirtualDisplayBadDisplay) {
188 if (mComposerClient->getMaxVirtualDisplayCount() == 0) {
189 GTEST_SUCCEED() << "no virtual display support";
190 return;
191 }
192
193 Error error = mComposerClient->getRaw()->destroyVirtualDisplay(mInvalidDisplayId);
194 ASSERT_EQ(Error::BAD_DISPLAY, error);
195 }
196
197 /**
198 * Test IComposerClient::createLayer and IComposerClient::destroyLayer.
199 *
200 * Test that layers can be created and destroyed.
201 */
TEST_P(GraphicsComposerHidlTest,CreateLayer)202 TEST_P(GraphicsComposerHidlTest, CreateLayer) {
203 Layer layer;
204 ASSERT_NO_FATAL_FAILURE(layer =
205 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
206
207 mComposerClient->destroyLayer(mPrimaryDisplay, layer);
208 }
209
210 /**
211 * Test IComposerClient::createLayer
212 *
213 * Test that passing in an invalid display handle to createLayer returns
214 * BAD_DISPLAY.
215 */
TEST_P(GraphicsComposerHidlTest,CreateLayerBadDisplay)216 TEST_P(GraphicsComposerHidlTest, CreateLayerBadDisplay) {
217 Error error;
218 mComposerClient->getRaw()->createLayer(
219 mInvalidDisplayId, kBufferSlotCount,
220 [&](const auto& tmpOutError, const auto&) { error = tmpOutError; });
221 ASSERT_EQ(Error::BAD_DISPLAY, error);
222 }
223
224 /**
225 * Test IComposerClient::destroyLayer
226 *
227 * Test that passing in an invalid display handle to destroyLayer returns
228 * BAD_DISPLAY
229 */
TEST_P(GraphicsComposerHidlTest,DestroyLayerBadDisplay)230 TEST_P(GraphicsComposerHidlTest, DestroyLayerBadDisplay) {
231 Error error;
232 Layer layer;
233 ASSERT_NO_FATAL_FAILURE(layer =
234 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
235
236 error = mComposerClient->getRaw()->destroyLayer(mInvalidDisplayId, layer);
237
238 EXPECT_EQ(Error::BAD_DISPLAY, error);
239
240 ASSERT_NO_FATAL_FAILURE(mComposerClient->destroyLayer(mPrimaryDisplay, layer));
241 }
242
243 /**
244 * Test IComposerClient::destroyLayer
245 *
246 * Test that passing in an invalid layer handle to destroyLayer returns
247 * BAD_LAYER
248 */
TEST_P(GraphicsComposerHidlTest,DestroyLayerBadLayerError)249 TEST_P(GraphicsComposerHidlTest, DestroyLayerBadLayerError) {
250 // We haven't created any layers yet, so any id should be invalid
251 Error error = mComposerClient->getRaw()->destroyLayer(mPrimaryDisplay, 1);
252
253 EXPECT_EQ(Error::BAD_LAYER, error);
254 }
255
256 /**
257 * Test IComposerClient::getActiveConfig
258 *
259 * Test that passing in a bad display handle to getActiveConfig generates a
260 * BAD_DISPLAY error
261 */
TEST_P(GraphicsComposerHidlTest,GetActiveConfigBadDisplay)262 TEST_P(GraphicsComposerHidlTest, GetActiveConfigBadDisplay) {
263 Error error;
264 mComposerClient->getRaw()->getActiveConfig(
265 mInvalidDisplayId, [&](const auto& tmpOutError, const auto&) { error = tmpOutError; });
266 ASSERT_EQ(Error::BAD_DISPLAY, error);
267 }
268
269 /**
270 * Test IComposerClient::getDisplayConfigs
271 *
272 * Test IComposerClient::getDisplayConfigs returns no error
273 * when passed in a valid display
274 */
TEST_P(GraphicsComposerHidlTest,GetDisplayConfig)275 TEST_P(GraphicsComposerHidlTest, GetDisplayConfig) {
276 std::vector<Config> configs;
277 ASSERT_NO_FATAL_FAILURE(configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay));
278 }
279
280 /**
281 * Test IComposerClient::getDisplayConfigs
282 *
283 * Test IComposerClient::getDisplayConfigs returns BAD_DISPLAY
284 * when passed in an invalid display handle
285 */
TEST_P(GraphicsComposerHidlTest,GetDisplayConfigBadDisplay)286 TEST_P(GraphicsComposerHidlTest, GetDisplayConfigBadDisplay) {
287 Error error;
288 mComposerClient->getRaw()->getDisplayConfigs(
289 mInvalidDisplayId, [&](const auto& tmpOutError, const auto&) { error = tmpOutError; });
290 ASSERT_EQ(Error::BAD_DISPLAY, error);
291 }
292
293 /**
294 * Test IComposerClient::getDisplayName.
295 */
TEST_P(GraphicsComposerHidlTest,GetDisplayName)296 TEST_P(GraphicsComposerHidlTest, GetDisplayName) {
297 mComposerClient->getDisplayName(mPrimaryDisplay);
298 }
299
300 /**
301 * Test IComposerClient::getDisplayType.
302 *
303 * Test that IComposerClient::getDisplayType returns the correct display type
304 * for the primary display.
305 */
TEST_P(GraphicsComposerHidlTest,GetDisplayType)306 TEST_P(GraphicsComposerHidlTest, GetDisplayType) {
307 ASSERT_EQ(IComposerClient::DisplayType::PHYSICAL,
308 mComposerClient->getDisplayType(mPrimaryDisplay));
309 }
310
311 /**
312 * Test IComposerClient::getClientTargetSupport.
313 *
314 * Test that IComposerClient::getClientTargetSupport returns true for the
315 * required client targets.
316 */
TEST_P(GraphicsComposerHidlTest,GetClientTargetSupport)317 TEST_P(GraphicsComposerHidlTest, GetClientTargetSupport) {
318 ASSERT_NO_FATAL_FAILURE(
319 mComposerClient->setPowerMode(mPrimaryDisplay, IComposerClient::PowerMode::ON));
320 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
321 for (auto config : configs) {
322 int32_t width = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
323 IComposerClient::Attribute::WIDTH);
324 int32_t height = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
325 IComposerClient::Attribute::HEIGHT);
326 ASSERT_LT(0, width);
327 ASSERT_LT(0, height);
328
329 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
330
331 ASSERT_TRUE(mComposerClient->getClientTargetSupport(
332 mPrimaryDisplay, width, height, PixelFormat::RGBA_8888, Dataspace::UNKNOWN));
333 }
334 }
335
336 /**
337 * Test IComposerClient::getClientTargetSupport
338 *
339 * Test that IComposerClient::getClientTargetSupport returns BAD_DISPLAY when
340 * passed an invalid display handle
341 */
TEST_P(GraphicsComposerHidlTest,GetClientTargetSupportBadDisplay)342 TEST_P(GraphicsComposerHidlTest, GetClientTargetSupportBadDisplay) {
343 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
344 for (auto config : configs) {
345 int32_t width = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
346 IComposerClient::Attribute::WIDTH);
347 int32_t height = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
348 IComposerClient::Attribute::HEIGHT);
349 ASSERT_LT(0, width);
350 ASSERT_LT(0, height);
351
352 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
353
354 Error error = mComposerClient->getRaw()->getClientTargetSupport(
355 mInvalidDisplayId, width, height, PixelFormat::RGBA_8888, Dataspace::UNKNOWN);
356 EXPECT_EQ(Error::BAD_DISPLAY, error);
357 }
358 }
359
360 /**
361 * Test IComposerClient::getDisplayAttribute.
362 *
363 * Test that IComposerClient::getDisplayAttribute succeeds for the required
364 * formats, and succeeds or fails correctly for optional attributes.
365 */
TEST_P(GraphicsComposerHidlTest,GetDisplayAttribute)366 TEST_P(GraphicsComposerHidlTest, GetDisplayAttribute) {
367 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
368 for (auto config : configs) {
369 const std::array<IComposerClient::Attribute, 3> requiredAttributes = {{
370 IComposerClient::Attribute::WIDTH, IComposerClient::Attribute::HEIGHT,
371 IComposerClient::Attribute::VSYNC_PERIOD,
372 }};
373 for (auto attribute : requiredAttributes) {
374 mComposerClient->getDisplayAttribute(mPrimaryDisplay, config, attribute);
375 }
376
377 const std::array<IComposerClient::Attribute, 2> optionalAttributes = {{
378 IComposerClient::Attribute::DPI_X, IComposerClient::Attribute::DPI_Y,
379 }};
380 for (auto attribute : optionalAttributes) {
381 mComposerClient->getRaw()->getDisplayAttribute(
382 mPrimaryDisplay, config, attribute, [&](const auto& tmpError, const auto&) {
383 EXPECT_TRUE(tmpError == Error::NONE || tmpError == Error::UNSUPPORTED);
384 });
385 }
386 }
387 }
388
389 /**
390 * Test IComposerClient::getHdrCapabilities.
391 */
TEST_P(GraphicsComposerHidlTest,GetHdrCapabilities)392 TEST_P(GraphicsComposerHidlTest, GetHdrCapabilities) {
393 float maxLuminance;
394 float maxAverageLuminance;
395 float minLuminance;
396 mComposerClient->getHdrCapabilities(mPrimaryDisplay, &maxLuminance, &maxAverageLuminance,
397 &minLuminance);
398 }
399
400 /**
401 * Test IComposerClient::setClientTargetSlotCount.
402 */
TEST_P(GraphicsComposerHidlTest,SetClientTargetSlotCount)403 TEST_P(GraphicsComposerHidlTest, SetClientTargetSlotCount) {
404 mComposerClient->setClientTargetSlotCount(mPrimaryDisplay, kBufferSlotCount);
405 }
406
407 /**
408 * Test IComposerClient::setActiveConfig.
409 *
410 * Test that IComposerClient::setActiveConfig succeeds for all display
411 * configs.
412 */
TEST_P(GraphicsComposerHidlTest,SetActiveConfig)413 TEST_P(GraphicsComposerHidlTest, SetActiveConfig) {
414 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
415 for (auto config : configs) {
416 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
417 ASSERT_EQ(config, mComposerClient->getActiveConfig(mPrimaryDisplay));
418 }
419 }
420
421 /**
422 * Test IComposerClient::setActiveConfig
423 *
424 * Test that config set during IComposerClient::setActiveConfig is maintained
425 * during a display on/off power cycle
426 */
TEST_P(GraphicsComposerHidlTest,SetActiveConfigPowerCycle)427 TEST_P(GraphicsComposerHidlTest, SetActiveConfigPowerCycle) {
428 ASSERT_NO_FATAL_FAILURE(
429 mComposerClient->setPowerMode(mPrimaryDisplay, IComposerClient::PowerMode::OFF));
430 ASSERT_NO_FATAL_FAILURE(
431 mComposerClient->setPowerMode(mPrimaryDisplay, IComposerClient::PowerMode::ON));
432
433 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
434 for (auto config : configs) {
435 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
436 ASSERT_EQ(config, mComposerClient->getActiveConfig(mPrimaryDisplay));
437
438 ASSERT_NO_FATAL_FAILURE(
439 mComposerClient->setPowerMode(mPrimaryDisplay, IComposerClient::PowerMode::OFF));
440 ASSERT_NO_FATAL_FAILURE(
441 mComposerClient->setPowerMode(mPrimaryDisplay, IComposerClient::PowerMode::ON));
442 ASSERT_EQ(config, mComposerClient->getActiveConfig(mPrimaryDisplay));
443 }
444 }
445
446 /**
447 * Test IComposerClient::getColorMode
448 *
449 * Test that IComposerClient::getColorMode always returns ColorMode::NATIVE
450 */
TEST_P(GraphicsComposerHidlTest,GetColorModes)451 TEST_P(GraphicsComposerHidlTest, GetColorModes) {
452 std::vector<ColorMode> modes = mComposerClient->getColorModes(mPrimaryDisplay);
453 auto nativeModeLocation = std::find(modes.begin(), modes.end(), ColorMode::NATIVE);
454
455 ASSERT_NE(modes.end(), nativeModeLocation);
456 }
457
458 /**
459 * Test IComposerClient::setColorMode.
460 *
461 * Test that IComposerClient::setColorMode succeeds for all color modes.
462 */
TEST_P(GraphicsComposerHidlTest,SetColorMode)463 TEST_P(GraphicsComposerHidlTest, SetColorMode) {
464 std::unordered_set<ColorMode> validModes;
465 for (auto mode : hidl_enum_range<ColorMode>()) {
466 validModes.insert(mode);
467 }
468
469 std::vector<ColorMode> modes = mComposerClient->getColorModes(mPrimaryDisplay);
470 for (auto mode : modes) {
471 if (validModes.count(mode)) {
472 mComposerClient->setColorMode(mPrimaryDisplay, mode);
473 }
474 }
475 }
476
477 /**
478 * Test IComposerClient::setColorMode
479 *
480 * Test that IComposerClient::setColorMode returns BAD_DISPLAY for
481 * an invalid display handle
482 */
TEST_P(GraphicsComposerHidlTest,SetColorModeBadDisplay)483 TEST_P(GraphicsComposerHidlTest, SetColorModeBadDisplay) {
484 std::vector<ColorMode> modes = mComposerClient->getColorModes(mPrimaryDisplay);
485 for (auto mode : modes) {
486 Error error = mComposerClient->getRaw()->setColorMode(mInvalidDisplayId, mode);
487 EXPECT_EQ(Error::BAD_DISPLAY, error);
488 }
489 }
490
491 /**
492 * Test IComposerClient::setColorMode
493 *
494 * Test that IComposerClient::setColorMode returns BAD_PARAMETER when passed in
495 * an invalid color mode
496 */
TEST_P(GraphicsComposerHidlTest,SetColorModeBadParameter)497 TEST_P(GraphicsComposerHidlTest, SetColorModeBadParameter) {
498 Error error =
499 mComposerClient->getRaw()->setColorMode(mPrimaryDisplay, static_cast<ColorMode>(-1));
500 ASSERT_EQ(Error::BAD_PARAMETER, error);
501 }
502
503 /**
504 * Test IComposerClient::getDozeSupport
505 *
506 * Test that IComposerClient::getDozeSupport returns
507 * BAD_DISPLAY when passed an invalid display handle
508 */
TEST_P(GraphicsComposerHidlTest,GetDozeSupportBadDisplay)509 TEST_P(GraphicsComposerHidlTest, GetDozeSupportBadDisplay) {
510 Error error;
511 mComposerClient->getRaw()->getDozeSupport(
512 mInvalidDisplayId, [&](const auto& tmpOutError, const auto&) { error = tmpOutError; });
513 ASSERT_EQ(Error::BAD_DISPLAY, error);
514 }
515
516 /**
517 * Test IComposerClient::setPowerMode.
518 *
519 * Test that IComposerClient::setPowerMode succeeds for all power modes.
520 */
TEST_P(GraphicsComposerHidlTest,SetPowerMode)521 TEST_P(GraphicsComposerHidlTest, SetPowerMode) {
522 std::vector<IComposerClient::PowerMode> modes;
523 modes.push_back(IComposerClient::PowerMode::OFF);
524
525 if (mComposerClient->getDozeSupport(mPrimaryDisplay)) {
526 modes.push_back(IComposerClient::PowerMode::DOZE);
527 modes.push_back(IComposerClient::PowerMode::DOZE_SUSPEND);
528 }
529
530 // push ON last
531 modes.push_back(IComposerClient::PowerMode::ON);
532
533 for (auto mode : modes) {
534 mComposerClient->setPowerMode(mPrimaryDisplay, mode);
535 }
536 }
537
538 /**
539 * Test IComposerClient::setPowerMode
540 *
541 * Test IComposerClient::setPowerMode succeeds with different
542 * orderings of power modes
543 */
TEST_P(GraphicsComposerHidlTest,SetPowerModeVariations)544 TEST_P(GraphicsComposerHidlTest, SetPowerModeVariations) {
545 std::vector<IComposerClient::PowerMode> modes;
546 modes.push_back(IComposerClient::PowerMode::OFF);
547 modes.push_back(IComposerClient::PowerMode::ON);
548 modes.push_back(IComposerClient::PowerMode::OFF);
549 for (auto mode : modes) {
550 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode(mPrimaryDisplay, mode));
551 }
552
553 modes.clear();
554
555 modes.push_back(IComposerClient::PowerMode::OFF);
556 modes.push_back(IComposerClient::PowerMode::OFF);
557 for (auto mode : modes) {
558 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode(mPrimaryDisplay, mode));
559 }
560
561 modes.clear();
562 if (mComposerClient->getDozeSupport(mPrimaryDisplay)) {
563 modes.push_back(IComposerClient::PowerMode::DOZE);
564 modes.push_back(IComposerClient::PowerMode::DOZE);
565
566 for (auto mode : modes) {
567 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode(mPrimaryDisplay, mode));
568 }
569
570 modes.clear();
571
572 modes.push_back(IComposerClient::PowerMode::DOZE_SUSPEND);
573 modes.push_back(IComposerClient::PowerMode::DOZE_SUSPEND);
574
575 for (auto mode : modes) {
576 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode(mPrimaryDisplay, mode));
577 }
578 }
579
580 modes.clear();
581
582 modes.push_back(IComposerClient::PowerMode::ON);
583 modes.push_back(IComposerClient::PowerMode::ON);
584 for (auto mode : modes) {
585 ASSERT_NO_FATAL_FAILURE(mComposerClient->setPowerMode(mPrimaryDisplay, mode));
586 }
587 }
588
589 /**
590 * Test IComposerClient::setPowerMode
591 *
592 * Test IComposerClient::setPowerMode returns BAD_DISPLAY when passed an invalid
593 * display handle
594 */
TEST_P(GraphicsComposerHidlTest,SetPowerModeBadDisplay)595 TEST_P(GraphicsComposerHidlTest, SetPowerModeBadDisplay) {
596 Error error =
597 mComposerClient->getRaw()->setPowerMode(mInvalidDisplayId, IComposerClient::PowerMode::ON);
598 ASSERT_EQ(Error::BAD_DISPLAY, error);
599 }
600
601 /**
602 * Test IComposerClient::setPowerMode
603 *
604 * Test that IComposerClient::setPowerMode returns UNSUPPORTED when passed DOZE
605 * or DOZE_SUSPEND on devices that do not support DOZE/DOZE_SUSPEND
606 */
TEST_P(GraphicsComposerHidlTest,SetPowerModeUnsupported)607 TEST_P(GraphicsComposerHidlTest, SetPowerModeUnsupported) {
608 if (!mComposerClient->getDozeSupport(mPrimaryDisplay)) {
609 Error error = mComposerClient->getRaw()->setPowerMode(mPrimaryDisplay,
610 IComposerClient::PowerMode::DOZE);
611 EXPECT_EQ(Error::UNSUPPORTED, error);
612
613 error = mComposerClient->getRaw()->setPowerMode(mPrimaryDisplay,
614 IComposerClient::PowerMode::DOZE_SUSPEND);
615 EXPECT_EQ(Error::UNSUPPORTED, error);
616 }
617 }
618
619 /**
620 * Test IComposerClient::setPowerMode
621 *
622 * Tests that IComposerClient::setPowerMode returns BAD_PARAMETER when passed an invalid
623 * PowerMode
624 */
TEST_P(GraphicsComposerHidlTest,SetPowerModeBadParameter)625 TEST_P(GraphicsComposerHidlTest, SetPowerModeBadParameter) {
626 Error error = mComposerClient->getRaw()->setPowerMode(
627 mPrimaryDisplay, static_cast<IComposerClient::PowerMode>(-1));
628 ASSERT_EQ(Error::BAD_PARAMETER, error);
629 }
630
631 /**
632 * Test IComposerClient::setVsyncEnabled.
633 *
634 * Test that IComposerClient::setVsyncEnabled succeeds and there is no
635 * spurious vsync events.
636 */
TEST_P(GraphicsComposerHidlTest,SetVsyncEnabled)637 TEST_P(GraphicsComposerHidlTest, SetVsyncEnabled) {
638 mComposerCallback->setVsyncAllowed(true);
639
640 mComposerClient->setVsyncEnabled(mPrimaryDisplay, true);
641 usleep(60 * 1000);
642 mComposerClient->setVsyncEnabled(mPrimaryDisplay, false);
643
644 mComposerCallback->setVsyncAllowed(false);
645 }
646
647 // Tests for IComposerClient::Command.
648 class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
649 protected:
SetUp()650 void SetUp() override {
651 ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::SetUp());
652
653 Config activeConfig = mComposerClient->getActiveConfig(mPrimaryDisplay);
654 mDisplayWidth = mComposerClient->getDisplayAttribute(mPrimaryDisplay, activeConfig,
655 IComposerClient::Attribute::WIDTH);
656 mDisplayHeight = mComposerClient->getDisplayAttribute(mPrimaryDisplay, activeConfig,
657 IComposerClient::Attribute::HEIGHT);
658 mWriter = std::make_unique<CommandWriterBase>(1024);
659 mReader = std::make_unique<TestCommandReader>();
660 }
661
TearDown()662 void TearDown() override {
663 ASSERT_EQ(0, mReader->mErrors.size());
664 ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::TearDown());
665 }
666
allocate()667 sp<GraphicBuffer> allocate() { return allocate(mDisplayWidth, mDisplayHeight); }
668
allocate(int32_t width,int32_t height)669 sp<GraphicBuffer> allocate(int32_t width, int32_t height) {
670 auto result = sp<GraphicBuffer>::make(
671 width, height, static_cast<int32_t>(PixelFormat::RGBA_8888), /*layerCount*/ 1,
672 static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN |
673 BufferUsage::COMPOSER_OVERLAY));
674 if (result->initCheck() != STATUS_OK) {
675 return nullptr;
676 }
677 return result;
678 }
679
execute()680 void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
681
682 std::unique_ptr<CommandWriterBase> mWriter;
683 std::unique_ptr<TestCommandReader> mReader;
684 int32_t mDisplayWidth;
685 int32_t mDisplayHeight;
686 };
687
688 /**
689 * Test IComposerClient::Command::SET_COLOR_TRANSFORM.
690 */
TEST_P(GraphicsComposerHidlCommandTest,SET_COLOR_TRANSFORM)691 TEST_P(GraphicsComposerHidlCommandTest, SET_COLOR_TRANSFORM) {
692 const std::array<float, 16> identity = {{
693 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
694 1.0f,
695 }};
696
697 mWriter->selectDisplay(mPrimaryDisplay);
698 mWriter->setColorTransform(identity.data(), ColorTransform::IDENTITY);
699
700 execute();
701 }
702
703 /**
704 * Test IComposerClient::Command::SET_CLIENT_TARGET.
705 */
TEST_P(GraphicsComposerHidlCommandTest,SET_CLIENT_TARGET)706 TEST_P(GraphicsComposerHidlCommandTest, SET_CLIENT_TARGET) {
707 mComposerClient->setClientTargetSlotCount(mPrimaryDisplay, kBufferSlotCount);
708
709 mWriter->selectDisplay(mPrimaryDisplay);
710 mWriter->setClientTarget(0, nullptr, -1, Dataspace::UNKNOWN,
711 std::vector<IComposerClient::Rect>());
712
713 execute();
714 }
715
716 /**
717 * Test IComposerClient::Command::SET_OUTPUT_BUFFER.
718 */
TEST_P(GraphicsComposerHidlCommandTest,SET_OUTPUT_BUFFER)719 TEST_P(GraphicsComposerHidlCommandTest, SET_OUTPUT_BUFFER) {
720 if (mComposerClient->getMaxVirtualDisplayCount() == 0) {
721 GTEST_SUCCEED() << "no virtual display support";
722 return;
723 }
724
725 Display display;
726 PixelFormat format;
727 ASSERT_NO_FATAL_FAILURE(
728 display = mComposerClient->createVirtualDisplay(64, 64, PixelFormat::IMPLEMENTATION_DEFINED,
729 kBufferSlotCount, &format));
730
731 auto handle = allocate();
732 ASSERT_TRUE(handle);
733
734 mWriter->selectDisplay(display);
735 mWriter->setOutputBuffer(0, handle->handle, -1);
736 execute();
737 }
738
739 /**
740 * Test IComposerClient::Command::VALIDATE_DISPLAY.
741 */
TEST_P(GraphicsComposerHidlCommandTest,VALIDATE_DISPLAY)742 TEST_P(GraphicsComposerHidlCommandTest, VALIDATE_DISPLAY) {
743 mWriter->selectDisplay(mPrimaryDisplay);
744 mWriter->validateDisplay();
745 execute();
746 }
747
748 /**
749 * Test IComposerClient::Command::ACCEPT_DISPLAY_CHANGES.
750 */
TEST_P(GraphicsComposerHidlCommandTest,ACCEPT_DISPLAY_CHANGES)751 TEST_P(GraphicsComposerHidlCommandTest, ACCEPT_DISPLAY_CHANGES) {
752 mWriter->selectDisplay(mPrimaryDisplay);
753 mWriter->validateDisplay();
754 mWriter->acceptDisplayChanges();
755 execute();
756 }
757
758 /**
759 * Test IComposerClient::Command::PRESENT_DISPLAY.
760 */
TEST_P(GraphicsComposerHidlCommandTest,PRESENT_DISPLAY)761 TEST_P(GraphicsComposerHidlCommandTest, PRESENT_DISPLAY) {
762 mWriter->selectDisplay(mPrimaryDisplay);
763 mWriter->validateDisplay();
764 mWriter->presentDisplay();
765 execute();
766 }
767
768 /**
769 * Test IComposerClient::Command::PRESENT_DISPLAY
770 *
771 * Test that IComposerClient::Command::PRESENT_DISPLAY works without
772 * additional call to validateDisplay when only the layer buffer handle and
773 * surface damage have been set
774 */
TEST_P(GraphicsComposerHidlCommandTest,PRESENT_DISPLAY_NO_LAYER_STATE_CHANGES)775 TEST_P(GraphicsComposerHidlCommandTest, PRESENT_DISPLAY_NO_LAYER_STATE_CHANGES) {
776 if (!mComposer->hasCapability(
777 static_cast<IComposer::Capability>(HWC2_CAPABILITY_SKIP_VALIDATE))) {
778 std::cout << "Device does not have skip validate capability, skipping" << std::endl;
779 GTEST_SUCCEED();
780 return;
781 }
782 mWriter->selectDisplay(mPrimaryDisplay);
783 mComposerClient->setPowerMode(mPrimaryDisplay, IComposerClient::PowerMode::ON);
784 mComposerClient->setColorMode(mPrimaryDisplay, ColorMode::NATIVE);
785
786 auto handle = allocate();
787 ASSERT_NE(nullptr, handle.get());
788
789 IComposerClient::Rect displayFrame{0, 0, mDisplayWidth, mDisplayHeight};
790
791 Layer layer;
792 ASSERT_NO_FATAL_FAILURE(layer =
793 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
794 mWriter->selectLayer(layer);
795 mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
796 mWriter->setLayerDisplayFrame(displayFrame);
797 mWriter->setLayerPlaneAlpha(1);
798 mWriter->setLayerSourceCrop({0, 0, (float)mDisplayWidth, (float)mDisplayHeight});
799 mWriter->setLayerTransform(static_cast<Transform>(0));
800 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, displayFrame));
801 mWriter->setLayerZOrder(10);
802 mWriter->setLayerBlendMode(IComposerClient::BlendMode::NONE);
803 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, displayFrame));
804 mWriter->setLayerBuffer(0, handle->handle, -1);
805 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
806
807 mWriter->validateDisplay();
808 execute();
809 if (mReader->mCompositionChanges.size() != 0) {
810 GTEST_SUCCEED() << "Composition change requested, skipping test";
811 return;
812 }
813
814 ASSERT_EQ(0, mReader->mErrors.size());
815 mWriter->presentDisplay();
816 execute();
817 ASSERT_EQ(0, mReader->mErrors.size());
818
819 mWriter->selectLayer(layer);
820 auto handle2 = allocate();
821 ASSERT_NE(nullptr, handle2.get());
822 mWriter->setLayerBuffer(0, handle2->handle, -1);
823 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, {0, 0, 10, 10}));
824 mWriter->presentDisplay();
825 execute();
826 }
827
828 /**
829 * Test IComposerClient::Command::SET_LAYER_CURSOR_POSITION.
830 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_CURSOR_POSITION)831 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_CURSOR_POSITION) {
832 Layer layer;
833 ASSERT_NO_FATAL_FAILURE(layer =
834 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
835
836 auto handle = allocate();
837 ASSERT_NE(nullptr, handle.get());
838 IComposerClient::Rect displayFrame{0, 0, mDisplayWidth, mDisplayHeight};
839
840 mWriter->selectDisplay(mPrimaryDisplay);
841 mWriter->selectLayer(layer);
842 mWriter->setLayerBuffer(0, handle->handle, -1);
843 mWriter->setLayerCompositionType(IComposerClient::Composition::CURSOR);
844 mWriter->setLayerDisplayFrame(displayFrame);
845 mWriter->setLayerPlaneAlpha(1);
846 mWriter->setLayerSourceCrop({0, 0, (float)mDisplayWidth, (float)mDisplayHeight});
847 mWriter->setLayerTransform(static_cast<Transform>(0));
848 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, displayFrame));
849 mWriter->setLayerZOrder(10);
850 mWriter->setLayerBlendMode(IComposerClient::BlendMode::NONE);
851 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, displayFrame));
852 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
853 mWriter->validateDisplay();
854
855 execute();
856 if (mReader->mCompositionChanges.size() != 0) {
857 GTEST_SUCCEED() << "Composition change requested, skipping test";
858 return;
859 }
860 mWriter->presentDisplay();
861 ASSERT_EQ(0, mReader->mErrors.size());
862
863 mWriter->setLayerCursorPosition(1, 1);
864 mWriter->setLayerCursorPosition(0, 0);
865 mWriter->validateDisplay();
866 mWriter->presentDisplay();
867 execute();
868 }
869
870 /**
871 * Test IComposerClient::Command::SET_LAYER_BUFFER.
872 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_BUFFER)873 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BUFFER) {
874 auto handle = allocate();
875 ASSERT_NE(nullptr, handle.get());
876
877 Layer layer;
878 ASSERT_NO_FATAL_FAILURE(layer =
879 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
880
881 mWriter->selectDisplay(mPrimaryDisplay);
882 mWriter->selectLayer(layer);
883 mWriter->setLayerBuffer(0, handle->handle, -1);
884 execute();
885 }
886
887 /**
888 * Test IComposerClient::Command::SET_LAYER_BUFFER with the behavior used for clearing buffer slots.
889 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_BUFFER_multipleTimes)890 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BUFFER_multipleTimes) {
891 // A placeholder buffer used to clear buffer slots
892 auto clearSlotBuffer = allocate(1u, 1u);
893
894 //
895 // Set the layer buffer to the first buffer
896 //
897 auto handle1 = allocate();
898 ASSERT_NE(nullptr, handle1.get());
899 IComposerClient::Rect displayFrame{0, 0, mDisplayWidth, mDisplayHeight};
900 Layer layer;
901 ASSERT_NO_FATAL_FAILURE(
902 layer = mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
903 mWriter->selectDisplay(mPrimaryDisplay);
904 mWriter->selectLayer(layer);
905 mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
906 mWriter->setLayerDisplayFrame(displayFrame);
907 mWriter->setLayerBuffer(0, handle1->handle, -1);
908 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
909 mWriter->validateDisplay();
910 execute();
911 if (mReader->mCompositionChanges.size() != 0) {
912 GTEST_SUCCEED() << "Composition change requested, skipping test";
913 return;
914 }
915 ASSERT_EQ(0, mReader->mErrors.size());
916 mWriter->selectDisplay(mPrimaryDisplay);
917 mWriter->presentDisplay();
918 execute();
919 ASSERT_EQ(0, mReader->mErrors.size());
920
921 //
922 // Set the layer buffer to the second buffer
923 //
924 auto handle2 = allocate();
925 ASSERT_NE(nullptr, handle2.get());
926 mWriter->selectDisplay(mPrimaryDisplay);
927 mWriter->selectLayer(layer);
928 mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
929 mWriter->setLayerDisplayFrame(displayFrame);
930 mWriter->setLayerBuffer(1, handle2->handle, -1);
931 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
932 mWriter->validateDisplay();
933 execute();
934 if (mReader->mCompositionChanges.size() != 0) {
935 GTEST_SUCCEED() << "Composition change requested, skipping test";
936 return;
937 }
938 ASSERT_EQ(0, mReader->mErrors.size());
939 mWriter->selectDisplay(mPrimaryDisplay);
940 mWriter->presentDisplay();
941 execute();
942 ASSERT_EQ(0, mReader->mErrors.size());
943
944 //
945 // Set the layer buffer to the third buffer
946 //
947 auto handle3 = allocate();
948 ASSERT_NE(nullptr, handle3.get());
949 mWriter->selectDisplay(mPrimaryDisplay);
950 mWriter->selectLayer(layer);
951 mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
952 mWriter->setLayerDisplayFrame(displayFrame);
953 mWriter->setLayerBuffer(2, handle3->handle, -1);
954 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
955 mWriter->validateDisplay();
956 execute();
957 if (mReader->mCompositionChanges.size() != 0) {
958 GTEST_SUCCEED() << "Composition change requested, skipping test";
959 return;
960 }
961 ASSERT_EQ(0, mReader->mErrors.size());
962 mWriter->selectDisplay(mPrimaryDisplay);
963 mWriter->presentDisplay();
964 execute();
965 ASSERT_EQ(0, mReader->mErrors.size());
966
967 // Ensure we can clear multiple buffer slots and then restore the active buffer at the end
968 mWriter->selectDisplay(mPrimaryDisplay);
969 mWriter->selectLayer(layer);
970 mWriter->setLayerBuffer(0, clearSlotBuffer->handle, -1);
971 mWriter->selectDisplay(mPrimaryDisplay);
972 mWriter->selectLayer(layer);
973 mWriter->setLayerBuffer(1, clearSlotBuffer->handle, -1);
974 mWriter->selectDisplay(mPrimaryDisplay);
975 mWriter->selectLayer(layer);
976 mWriter->setLayerBuffer(2, nullptr, -1);
977 mWriter->validateDisplay();
978 execute();
979 ASSERT_EQ(0, mReader->mErrors.size());
980
981 mWriter->selectDisplay(mPrimaryDisplay);
982 mWriter->presentDisplay();
983 execute();
984 ASSERT_EQ(0, mReader->mErrors.size());
985 }
986
987 /**
988 * Test IComposerClient::Command::SET_LAYER_SURFACE_DAMAGE.
989 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_SURFACE_DAMAGE)990 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_SURFACE_DAMAGE) {
991 Layer layer;
992 ASSERT_NO_FATAL_FAILURE(layer =
993 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
994
995 IComposerClient::Rect empty{0, 0, 0, 0};
996 IComposerClient::Rect unit{0, 0, 1, 1};
997
998 mWriter->selectDisplay(mPrimaryDisplay);
999 mWriter->selectLayer(layer);
1000 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, empty));
1001 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, unit));
1002 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>());
1003 execute();
1004 }
1005
1006 /**
1007 * Test IComposerClient::Command::SET_LAYER_BLEND_MODE.
1008 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_BLEND_MODE)1009 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BLEND_MODE) {
1010 Layer layer;
1011 ASSERT_NO_FATAL_FAILURE(layer =
1012 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1013
1014 mWriter->selectDisplay(mPrimaryDisplay);
1015 mWriter->selectLayer(layer);
1016 mWriter->setLayerBlendMode(IComposerClient::BlendMode::NONE);
1017 mWriter->setLayerBlendMode(IComposerClient::BlendMode::PREMULTIPLIED);
1018 mWriter->setLayerBlendMode(IComposerClient::BlendMode::COVERAGE);
1019 execute();
1020 }
1021
1022 /**
1023 * Test IComposerClient::Command::SET_LAYER_COLOR.
1024 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_COLOR)1025 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_COLOR) {
1026 Layer layer;
1027 ASSERT_NO_FATAL_FAILURE(layer =
1028 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1029
1030 mWriter->selectDisplay(mPrimaryDisplay);
1031 mWriter->selectLayer(layer);
1032 mWriter->setLayerColor(IComposerClient::Color{0xff, 0xff, 0xff, 0xff});
1033 mWriter->setLayerColor(IComposerClient::Color{0, 0, 0, 0});
1034 execute();
1035 }
1036
1037 /**
1038 * Test IComposerClient::Command::SET_LAYER_COMPOSITION_TYPE.
1039 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_COMPOSITION_TYPE)1040 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_COMPOSITION_TYPE) {
1041 Layer layer;
1042 ASSERT_NO_FATAL_FAILURE(layer =
1043 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1044
1045 mWriter->selectDisplay(mPrimaryDisplay);
1046 mWriter->selectLayer(layer);
1047 mWriter->setLayerCompositionType(IComposerClient::Composition::CLIENT);
1048 mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
1049 mWriter->setLayerCompositionType(IComposerClient::Composition::SOLID_COLOR);
1050 mWriter->setLayerCompositionType(IComposerClient::Composition::CURSOR);
1051 execute();
1052 }
1053
1054 /**
1055 * Test IComposerClient::Command::SET_LAYER_DATASPACE.
1056 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_DATASPACE)1057 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_DATASPACE) {
1058 Layer layer;
1059 ASSERT_NO_FATAL_FAILURE(layer =
1060 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1061
1062 mWriter->selectDisplay(mPrimaryDisplay);
1063 mWriter->selectLayer(layer);
1064 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
1065 execute();
1066 }
1067
1068 /**
1069 * Test IComposerClient::Command::SET_LAYER_DISPLAY_FRAME.
1070 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_DISPLAY_FRAME)1071 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_DISPLAY_FRAME) {
1072 Layer layer;
1073 ASSERT_NO_FATAL_FAILURE(layer =
1074 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1075
1076 mWriter->selectDisplay(mPrimaryDisplay);
1077 mWriter->selectLayer(layer);
1078 mWriter->setLayerDisplayFrame(IComposerClient::Rect{0, 0, 1, 1});
1079 execute();
1080 }
1081
1082 /**
1083 * Test IComposerClient::Command::SET_LAYER_PLANE_ALPHA.
1084 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_PLANE_ALPHA)1085 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_PLANE_ALPHA) {
1086 Layer layer;
1087 ASSERT_NO_FATAL_FAILURE(layer =
1088 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1089
1090 mWriter->selectDisplay(mPrimaryDisplay);
1091 mWriter->selectLayer(layer);
1092 mWriter->setLayerPlaneAlpha(0.0f);
1093 mWriter->setLayerPlaneAlpha(1.0f);
1094 execute();
1095 }
1096
1097 /**
1098 * Test IComposerClient::Command::SET_LAYER_SIDEBAND_STREAM.
1099 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_SIDEBAND_STREAM)1100 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_SIDEBAND_STREAM) {
1101 if (!mComposer->hasCapability(IComposer::Capability::SIDEBAND_STREAM)) {
1102 GTEST_SUCCEED() << "no sideband stream support";
1103 return;
1104 }
1105
1106 auto handle = allocate();
1107 ASSERT_NE(nullptr, handle.get());
1108
1109 Layer layer;
1110 ASSERT_NO_FATAL_FAILURE(layer =
1111 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1112
1113 mWriter->selectDisplay(mPrimaryDisplay);
1114 mWriter->selectLayer(layer);
1115 mWriter->setLayerSidebandStream(handle->handle);
1116 execute();
1117 }
1118
1119 /**
1120 * Test IComposerClient::Command::SET_LAYER_SOURCE_CROP.
1121 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_SOURCE_CROP)1122 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_SOURCE_CROP) {
1123 Layer layer;
1124 ASSERT_NO_FATAL_FAILURE(layer =
1125 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1126
1127 mWriter->selectDisplay(mPrimaryDisplay);
1128 mWriter->selectLayer(layer);
1129 mWriter->setLayerSourceCrop(IComposerClient::FRect{0.0f, 0.0f, 1.0f, 1.0f});
1130 execute();
1131 }
1132
1133 /**
1134 * Test IComposerClient::Command::SET_LAYER_TRANSFORM.
1135 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_TRANSFORM)1136 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_TRANSFORM) {
1137 Layer layer;
1138 ASSERT_NO_FATAL_FAILURE(layer =
1139 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1140
1141 mWriter->selectDisplay(mPrimaryDisplay);
1142 mWriter->selectLayer(layer);
1143 mWriter->setLayerTransform(static_cast<Transform>(0));
1144 mWriter->setLayerTransform(Transform::FLIP_H);
1145 mWriter->setLayerTransform(Transform::FLIP_V);
1146 mWriter->setLayerTransform(Transform::ROT_90);
1147 mWriter->setLayerTransform(Transform::ROT_180);
1148 mWriter->setLayerTransform(Transform::ROT_270);
1149 mWriter->setLayerTransform(static_cast<Transform>(Transform::FLIP_H | Transform::ROT_90));
1150 mWriter->setLayerTransform(static_cast<Transform>(Transform::FLIP_V | Transform::ROT_90));
1151 execute();
1152 }
1153
1154 /**
1155 * Test IComposerClient::Command::SET_LAYER_VISIBLE_REGION.
1156 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_VISIBLE_REGION)1157 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_VISIBLE_REGION) {
1158 Layer layer;
1159 ASSERT_NO_FATAL_FAILURE(layer =
1160 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1161
1162 IComposerClient::Rect empty{0, 0, 0, 0};
1163 IComposerClient::Rect unit{0, 0, 1, 1};
1164
1165 mWriter->selectDisplay(mPrimaryDisplay);
1166 mWriter->selectLayer(layer);
1167 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, empty));
1168 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, unit));
1169 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>());
1170 execute();
1171 }
1172
1173 /**
1174 * Test IComposerClient::Command::SET_LAYER_Z_ORDER.
1175 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_Z_ORDER)1176 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_Z_ORDER) {
1177 Layer layer;
1178 ASSERT_NO_FATAL_FAILURE(layer =
1179 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1180
1181 mWriter->selectDisplay(mPrimaryDisplay);
1182 mWriter->selectLayer(layer);
1183 mWriter->setLayerZOrder(10);
1184 mWriter->setLayerZOrder(0);
1185 execute();
1186 }
1187
1188 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerHidlCommandTest);
1189 INSTANTIATE_TEST_SUITE_P(
1190 PerInstance, GraphicsComposerHidlCommandTest,
1191 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IComposer::descriptor)),
1192 android::hardware::PrintInstanceNameToString);
1193
1194 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerHidlTest);
1195 INSTANTIATE_TEST_SUITE_P(
1196 PerInstance, GraphicsComposerHidlTest,
1197 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IComposer::descriptor)),
1198 android::hardware::PrintInstanceNameToString);
1199
1200 } // namespace
1201 } // namespace vts
1202 } // namespace V2_1
1203 } // namespace composer
1204 } // namespace graphics
1205 } // namespace hardware
1206 } // namespace android
1207
main(int argc,char ** argv)1208 int main(int argc, char** argv) {
1209 ::testing::InitGoogleTest(&argc, argv);
1210
1211 using namespace std::chrono_literals;
1212 if (!android::base::WaitForProperty("init.svc.surfaceflinger", "stopped", 10s)) {
1213 ALOGE("Failed to stop init.svc.surfaceflinger");
1214 return -1;
1215 }
1216
1217 return RUN_ALL_TESTS();
1218 }
1219