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 <composer-vts/2.1/ComposerVts.h>
21 #include <composer-vts/2.1/GraphicsComposerCallback.h>
22 #include <composer-vts/2.1/TestCommandReader.h>
23 #include <gtest/gtest.h>
24 #include <hardware/hwcomposer2.h>
25 #include <hidl/GtestPrinter.h>
26 #include <hidl/ServiceManagement.h>
27 #include <mapper-vts/2.0/MapperVts.h>
28 #include <mapper-vts/3.0/MapperVts.h>
29 #include <mapper-vts/4.0/MapperVts.h>
30
31 #include <unistd.h>
32
33 #include <algorithm>
34 #include <array>
35 #include <memory>
36 #include <mutex>
37 #include <unordered_set>
38 #include <vector>
39
40 namespace android {
41 namespace hardware {
42 namespace graphics {
43 namespace composer {
44 namespace V2_1 {
45 namespace vts {
46 namespace {
47
48 using android::hardware::graphics::common::V1_0::BufferUsage;
49 using android::hardware::graphics::common::V1_0::ColorMode;
50 using android::hardware::graphics::common::V1_0::ColorTransform;
51 using android::hardware::graphics::common::V1_0::Dataspace;
52 using android::hardware::graphics::common::V1_0::PixelFormat;
53 using android::hardware::graphics::common::V1_0::Transform;
54 using GrallocError = android::hardware::graphics::mapper::V2_0::Error;
55
56 class GraphicsComposerHidlTest : public ::testing::TestWithParam<std::string> {
57 protected:
SetUp()58 void SetUp() override {
59 ASSERT_NO_FATAL_FAILURE(
60 mComposer = std::make_unique<Composer>(IComposer::getService(GetParam())));
61 ASSERT_NO_FATAL_FAILURE(mComposerClient = mComposer->createClient());
62
63 mComposerCallback = new GraphicsComposerCallback;
64 mComposerClient->registerCallback(mComposerCallback);
65
66 // assume the first display is primary and is never removed
67 mPrimaryDisplay = waitForFirstDisplay();
68
69 // explicitly disable vsync
70 mComposerClient->setVsyncEnabled(mPrimaryDisplay, false);
71 mComposerCallback->setVsyncAllowed(false);
72
73 mInvalidDisplayId = GetInvalidDisplayId();
74
75 // Although 0 could be an invalid display, a return value of 0
76 // from GetInvalidDisplayId means all other ids are in use, a condition which
77 // we are assuming a device will never have
78 ASSERT_NE(0, mInvalidDisplayId);
79 }
80
TearDown()81 void TearDown() override {
82 if (mComposerCallback != nullptr) {
83 EXPECT_EQ(0, mComposerCallback->getInvalidHotplugCount());
84 EXPECT_EQ(0, mComposerCallback->getInvalidRefreshCount());
85 EXPECT_EQ(0, mComposerCallback->getInvalidVsyncCount());
86 }
87 }
88
89 // returns an invalid display id (one that has not been registered to a
90 // display. Currently assuming that a device will never have close to
91 // std::numeric_limit<uint64_t>::max() displays registered while running tests
GetInvalidDisplayId()92 Display GetInvalidDisplayId() {
93 std::vector<Display> validDisplays = mComposerCallback->getDisplays();
94
95 uint64_t id = std::numeric_limits<uint64_t>::max();
96 while (id > 0) {
97 if (std::find(validDisplays.begin(), validDisplays.end(), id) == validDisplays.end()) {
98 return id;
99 }
100 id--;
101 }
102
103 return 0;
104 }
105
106 // use the slot count usually set by SF
107 static constexpr uint32_t kBufferSlotCount = 64;
108
109 std::unique_ptr<Composer> mComposer;
110 std::unique_ptr<ComposerClient> mComposerClient;
111 sp<GraphicsComposerCallback> mComposerCallback;
112 // the first display and is assumed never to be removed
113 Display mPrimaryDisplay;
114 Display mInvalidDisplayId;
115
116 private:
waitForFirstDisplay()117 Display waitForFirstDisplay() {
118 while (true) {
119 std::vector<Display> displays = mComposerCallback->getDisplays();
120 if (displays.empty()) {
121 usleep(5 * 1000);
122 continue;
123 }
124
125 return displays[0];
126 }
127 }
128 };
129
130 /**
131 * Test IComposer::getCapabilities.
132 *
133 * Test that IComposer::getCapabilities returns no invalid capabilities.
134 */
TEST_P(GraphicsComposerHidlTest,GetCapabilities)135 TEST_P(GraphicsComposerHidlTest, GetCapabilities) {
136 auto capabilities = mComposer->getCapabilities();
137 ASSERT_EQ(capabilities.end(),
138 std::find(capabilities.begin(), capabilities.end(), IComposer::Capability::INVALID));
139 }
140
141 /**
142 * Test IComposer::dumpDebugInfo.
143 */
TEST_P(GraphicsComposerHidlTest,DumpDebugInfo)144 TEST_P(GraphicsComposerHidlTest, DumpDebugInfo) {
145 mComposer->dumpDebugInfo();
146 }
147
148 /**
149 * Test IComposer::createClient.
150 *
151 * Test that IComposerClient is a singleton.
152 */
TEST_P(GraphicsComposerHidlTest,CreateClientSingleton)153 TEST_P(GraphicsComposerHidlTest, CreateClientSingleton) {
154 mComposer->getRaw()->createClient(
155 [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::NO_RESOURCES, tmpError); });
156 }
157
158 /**
159 * Test IComposerClient::createVirtualDisplay and
160 * IComposerClient::destroyVirtualDisplay.
161 *
162 * Test that virtual displays can be created and has the correct display type.
163 */
TEST_P(GraphicsComposerHidlTest,CreateVirtualDisplay)164 TEST_P(GraphicsComposerHidlTest, CreateVirtualDisplay) {
165 if (mComposerClient->getMaxVirtualDisplayCount() == 0) {
166 GTEST_SUCCEED() << "no virtual display support";
167 return;
168 }
169
170 Display display;
171 PixelFormat format;
172 ASSERT_NO_FATAL_FAILURE(
173 display = mComposerClient->createVirtualDisplay(64, 64, PixelFormat::IMPLEMENTATION_DEFINED,
174 kBufferSlotCount, &format));
175
176 // test display type
177 IComposerClient::DisplayType type = mComposerClient->getDisplayType(display);
178 EXPECT_EQ(IComposerClient::DisplayType::VIRTUAL, type);
179
180 mComposerClient->destroyVirtualDisplay(display);
181 }
182
183 /**
184 * Test IComposerClient::destroyVirtualDisplay
185 *
186 * Test that passing a bad display handle to destroyVirtualDisplay
187 * returns a BAD_DISPLAY error
188 */
TEST_P(GraphicsComposerHidlTest,DestroyVirtualDisplayBadDisplay)189 TEST_P(GraphicsComposerHidlTest, DestroyVirtualDisplayBadDisplay) {
190 if (mComposerClient->getMaxVirtualDisplayCount() == 0) {
191 GTEST_SUCCEED() << "no virtual display support";
192 return;
193 }
194
195 Error error = mComposerClient->getRaw()->destroyVirtualDisplay(mInvalidDisplayId);
196 ASSERT_EQ(Error::BAD_DISPLAY, error);
197 }
198
199 /**
200 * Test IComposerClient::createLayer and IComposerClient::destroyLayer.
201 *
202 * Test that layers can be created and destroyed.
203 */
TEST_P(GraphicsComposerHidlTest,CreateLayer)204 TEST_P(GraphicsComposerHidlTest, CreateLayer) {
205 Layer layer;
206 ASSERT_NO_FATAL_FAILURE(layer =
207 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
208
209 mComposerClient->destroyLayer(mPrimaryDisplay, layer);
210 }
211
212 /**
213 * Test IComposerClient::createLayer
214 *
215 * Test that passing in an invalid display handle to createLayer returns
216 * BAD_DISPLAY.
217 */
TEST_P(GraphicsComposerHidlTest,CreateLayerBadDisplay)218 TEST_P(GraphicsComposerHidlTest, CreateLayerBadDisplay) {
219 Error error;
220 mComposerClient->getRaw()->createLayer(
221 mInvalidDisplayId, kBufferSlotCount,
222 [&](const auto& tmpOutError, const auto&) { error = tmpOutError; });
223 ASSERT_EQ(Error::BAD_DISPLAY, error);
224 }
225
226 /**
227 * Test IComposerClient::destroyLayer
228 *
229 * Test that passing in an invalid display handle to destroyLayer returns
230 * BAD_DISPLAY
231 */
TEST_P(GraphicsComposerHidlTest,DestroyLayerBadDisplay)232 TEST_P(GraphicsComposerHidlTest, DestroyLayerBadDisplay) {
233 Error error;
234 Layer layer;
235 ASSERT_NO_FATAL_FAILURE(layer =
236 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
237
238 error = mComposerClient->getRaw()->destroyLayer(mInvalidDisplayId, layer);
239
240 EXPECT_EQ(Error::BAD_DISPLAY, error);
241
242 ASSERT_NO_FATAL_FAILURE(mComposerClient->destroyLayer(mPrimaryDisplay, layer));
243 }
244
245 /**
246 * Test IComposerClient::destroyLayer
247 *
248 * Test that passing in an invalid layer handle to destroyLayer returns
249 * BAD_LAYER
250 */
TEST_P(GraphicsComposerHidlTest,DestroyLayerBadLayerError)251 TEST_P(GraphicsComposerHidlTest, DestroyLayerBadLayerError) {
252 // We haven't created any layers yet, so any id should be invalid
253 Error error = mComposerClient->getRaw()->destroyLayer(mPrimaryDisplay, 1);
254
255 EXPECT_EQ(Error::BAD_LAYER, error);
256 }
257
258 /**
259 * Test IComposerClient::getActiveConfig
260 *
261 * Test that passing in a bad display handle to getActiveConfig generates a
262 * BAD_DISPLAY error
263 */
TEST_P(GraphicsComposerHidlTest,GetActiveConfigBadDisplay)264 TEST_P(GraphicsComposerHidlTest, GetActiveConfigBadDisplay) {
265 Error error;
266 mComposerClient->getRaw()->getActiveConfig(
267 mInvalidDisplayId, [&](const auto& tmpOutError, const auto&) { error = tmpOutError; });
268 ASSERT_EQ(Error::BAD_DISPLAY, error);
269 }
270
271 /**
272 * Test IComposerClient::getDisplayConfigs
273 *
274 * Test IComposerClient::getDisplayConfigs returns no error
275 * when passed in a valid display
276 */
TEST_P(GraphicsComposerHidlTest,GetDisplayConfig)277 TEST_P(GraphicsComposerHidlTest, GetDisplayConfig) {
278 std::vector<Config> configs;
279 ASSERT_NO_FATAL_FAILURE(configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay));
280 }
281
282 /**
283 * Test IComposerClient::getDisplayConfigs
284 *
285 * Test IComposerClient::getDisplayConfigs returns BAD_DISPLAY
286 * when passed in an invalid display handle
287 */
TEST_P(GraphicsComposerHidlTest,GetDisplayConfigBadDisplay)288 TEST_P(GraphicsComposerHidlTest, GetDisplayConfigBadDisplay) {
289 Error error;
290 mComposerClient->getRaw()->getDisplayConfigs(
291 mInvalidDisplayId, [&](const auto& tmpOutError, const auto&) { error = tmpOutError; });
292 ASSERT_EQ(Error::BAD_DISPLAY, error);
293 }
294
295 /**
296 * Test IComposerClient::getDisplayName.
297 */
TEST_P(GraphicsComposerHidlTest,GetDisplayName)298 TEST_P(GraphicsComposerHidlTest, GetDisplayName) {
299 mComposerClient->getDisplayName(mPrimaryDisplay);
300 }
301
302 /**
303 * Test IComposerClient::getDisplayType.
304 *
305 * Test that IComposerClient::getDisplayType returns the correct display type
306 * for the primary display.
307 */
TEST_P(GraphicsComposerHidlTest,GetDisplayType)308 TEST_P(GraphicsComposerHidlTest, GetDisplayType) {
309 ASSERT_EQ(IComposerClient::DisplayType::PHYSICAL,
310 mComposerClient->getDisplayType(mPrimaryDisplay));
311 }
312
313 /**
314 * Test IComposerClient::getClientTargetSupport.
315 *
316 * Test that IComposerClient::getClientTargetSupport returns true for the
317 * required client targets.
318 */
TEST_P(GraphicsComposerHidlTest,GetClientTargetSupport)319 TEST_P(GraphicsComposerHidlTest, GetClientTargetSupport) {
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 ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>());
654 Config activeConfig = mComposerClient->getActiveConfig(mPrimaryDisplay);
655 mDisplayWidth = mComposerClient->getDisplayAttribute(mPrimaryDisplay, activeConfig,
656 IComposerClient::Attribute::WIDTH);
657 mDisplayHeight = mComposerClient->getDisplayAttribute(mPrimaryDisplay, activeConfig,
658 IComposerClient::Attribute::HEIGHT);
659 mWriter = std::make_unique<CommandWriterBase>(1024);
660 mReader = std::make_unique<TestCommandReader>();
661 }
662
TearDown()663 void TearDown() override {
664 ASSERT_EQ(0, mReader->mErrors.size());
665 ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::TearDown());
666 }
667
allocate()668 const native_handle_t* allocate() {
669 uint64_t usage =
670 static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN |
671 BufferUsage::COMPOSER_OVERLAY);
672 return mGralloc->allocate(mDisplayWidth, mDisplayHeight, 1, PixelFormat::RGBA_8888, usage);
673 }
674
execute()675 void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
676
677 std::unique_ptr<CommandWriterBase> mWriter;
678 std::unique_ptr<TestCommandReader> mReader;
679 int32_t mDisplayWidth;
680 int32_t mDisplayHeight;
681
682 private:
683 std::unique_ptr<Gralloc> mGralloc;
684 };
685
686 /**
687 * Test IComposerClient::Command::SET_COLOR_TRANSFORM.
688 */
TEST_P(GraphicsComposerHidlCommandTest,SET_COLOR_TRANSFORM)689 TEST_P(GraphicsComposerHidlCommandTest, SET_COLOR_TRANSFORM) {
690 const std::array<float, 16> identity = {{
691 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,
692 1.0f,
693 }};
694
695 mWriter->selectDisplay(mPrimaryDisplay);
696 mWriter->setColorTransform(identity.data(), ColorTransform::IDENTITY);
697
698 execute();
699 }
700
701 /**
702 * Test IComposerClient::Command::SET_CLIENT_TARGET.
703 */
TEST_P(GraphicsComposerHidlCommandTest,SET_CLIENT_TARGET)704 TEST_P(GraphicsComposerHidlCommandTest, SET_CLIENT_TARGET) {
705 mComposerClient->setClientTargetSlotCount(mPrimaryDisplay, kBufferSlotCount);
706
707 mWriter->selectDisplay(mPrimaryDisplay);
708 mWriter->setClientTarget(0, nullptr, -1, Dataspace::UNKNOWN,
709 std::vector<IComposerClient::Rect>());
710
711 execute();
712 }
713
714 /**
715 * Test IComposerClient::Command::SET_OUTPUT_BUFFER.
716 */
TEST_P(GraphicsComposerHidlCommandTest,SET_OUTPUT_BUFFER)717 TEST_P(GraphicsComposerHidlCommandTest, SET_OUTPUT_BUFFER) {
718 if (mComposerClient->getMaxVirtualDisplayCount() == 0) {
719 GTEST_SUCCEED() << "no virtual display support";
720 return;
721 }
722
723 Display display;
724 PixelFormat format;
725 ASSERT_NO_FATAL_FAILURE(
726 display = mComposerClient->createVirtualDisplay(64, 64, PixelFormat::IMPLEMENTATION_DEFINED,
727 kBufferSlotCount, &format));
728
729 const native_handle_t* handle;
730 ASSERT_NO_FATAL_FAILURE(handle = allocate());
731
732 mWriter->selectDisplay(display);
733 mWriter->setOutputBuffer(0, handle, -1);
734 execute();
735 }
736
737 /**
738 * Test IComposerClient::Command::VALIDATE_DISPLAY.
739 */
TEST_P(GraphicsComposerHidlCommandTest,VALIDATE_DISPLAY)740 TEST_P(GraphicsComposerHidlCommandTest, VALIDATE_DISPLAY) {
741 mWriter->selectDisplay(mPrimaryDisplay);
742 mWriter->validateDisplay();
743 execute();
744 }
745
746 /**
747 * Test IComposerClient::Command::ACCEPT_DISPLAY_CHANGES.
748 */
TEST_P(GraphicsComposerHidlCommandTest,ACCEPT_DISPLAY_CHANGES)749 TEST_P(GraphicsComposerHidlCommandTest, ACCEPT_DISPLAY_CHANGES) {
750 mWriter->selectDisplay(mPrimaryDisplay);
751 mWriter->validateDisplay();
752 mWriter->acceptDisplayChanges();
753 execute();
754 }
755
756 /**
757 * Test IComposerClient::Command::PRESENT_DISPLAY.
758 */
TEST_P(GraphicsComposerHidlCommandTest,PRESENT_DISPLAY)759 TEST_P(GraphicsComposerHidlCommandTest, PRESENT_DISPLAY) {
760 mWriter->selectDisplay(mPrimaryDisplay);
761 mWriter->validateDisplay();
762 mWriter->presentDisplay();
763 execute();
764 }
765
766 /**
767 * Test IComposerClient::Command::PRESENT_DISPLAY
768 *
769 * Test that IComposerClient::Command::PRESENT_DISPLAY works without
770 * additional call to validateDisplay when only the layer buffer handle and
771 * surface damage have been set
772 */
TEST_P(GraphicsComposerHidlCommandTest,PRESENT_DISPLAY_NO_LAYER_STATE_CHANGES)773 TEST_P(GraphicsComposerHidlCommandTest, PRESENT_DISPLAY_NO_LAYER_STATE_CHANGES) {
774 if (!mComposer->hasCapability(
775 static_cast<IComposer::Capability>(HWC2_CAPABILITY_SKIP_VALIDATE))) {
776 std::cout << "Device does not have skip validate capability, skipping" << std::endl;
777 GTEST_SUCCEED();
778 return;
779 }
780 mWriter->selectDisplay(mPrimaryDisplay);
781 mComposerClient->setPowerMode(mPrimaryDisplay, IComposerClient::PowerMode::ON);
782 mComposerClient->setColorMode(mPrimaryDisplay, ColorMode::NATIVE);
783
784 auto handle = allocate();
785 ASSERT_NE(nullptr, handle);
786
787 IComposerClient::Rect displayFrame{0, 0, mDisplayWidth, mDisplayHeight};
788
789 Layer layer;
790 ASSERT_NO_FATAL_FAILURE(layer =
791 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
792 mWriter->selectLayer(layer);
793 mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
794 mWriter->setLayerDisplayFrame(displayFrame);
795 mWriter->setLayerPlaneAlpha(1);
796 mWriter->setLayerSourceCrop({0, 0, (float)mDisplayWidth, (float)mDisplayHeight});
797 mWriter->setLayerTransform(static_cast<Transform>(0));
798 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, displayFrame));
799 mWriter->setLayerZOrder(10);
800 mWriter->setLayerBlendMode(IComposerClient::BlendMode::NONE);
801 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, displayFrame));
802 mWriter->setLayerBuffer(0, handle, -1);
803 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
804
805 mWriter->validateDisplay();
806 execute();
807 if (mReader->mCompositionChanges.size() != 0) {
808 GTEST_SUCCEED() << "Composition change requested, skipping test";
809 return;
810 }
811
812 ASSERT_EQ(0, mReader->mErrors.size());
813 mWriter->presentDisplay();
814 execute();
815 ASSERT_EQ(0, mReader->mErrors.size());
816
817 mWriter->selectLayer(layer);
818 auto handle2 = allocate();
819 ASSERT_NE(nullptr, handle2);
820 mWriter->setLayerBuffer(0, handle2, -1);
821 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, {0, 0, 10, 10}));
822 mWriter->presentDisplay();
823 execute();
824 }
825
826 /**
827 * Test IComposerClient::Command::SET_LAYER_CURSOR_POSITION.
828 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_CURSOR_POSITION)829 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_CURSOR_POSITION) {
830 Layer layer;
831 ASSERT_NO_FATAL_FAILURE(layer =
832 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
833
834 auto handle = allocate();
835 ASSERT_NE(nullptr, handle);
836 IComposerClient::Rect displayFrame{0, 0, mDisplayWidth, mDisplayHeight};
837
838 mWriter->selectDisplay(mPrimaryDisplay);
839 mWriter->selectLayer(layer);
840 mWriter->setLayerBuffer(0, handle, -1);
841 mWriter->setLayerCompositionType(IComposerClient::Composition::CURSOR);
842 mWriter->setLayerDisplayFrame(displayFrame);
843 mWriter->setLayerPlaneAlpha(1);
844 mWriter->setLayerSourceCrop({0, 0, (float)mDisplayWidth, (float)mDisplayHeight});
845 mWriter->setLayerTransform(static_cast<Transform>(0));
846 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, displayFrame));
847 mWriter->setLayerZOrder(10);
848 mWriter->setLayerBlendMode(IComposerClient::BlendMode::NONE);
849 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, displayFrame));
850 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
851 mWriter->validateDisplay();
852
853 execute();
854 if (mReader->mCompositionChanges.size() != 0) {
855 GTEST_SUCCEED() << "Composition change requested, skipping test";
856 return;
857 }
858 mWriter->presentDisplay();
859 ASSERT_EQ(0, mReader->mErrors.size());
860
861 mWriter->setLayerCursorPosition(1, 1);
862 mWriter->setLayerCursorPosition(0, 0);
863 mWriter->validateDisplay();
864 mWriter->presentDisplay();
865 execute();
866 }
867
868 /**
869 * Test IComposerClient::Command::SET_LAYER_BUFFER.
870 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_BUFFER)871 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BUFFER) {
872 auto handle = allocate();
873 ASSERT_NE(nullptr, handle);
874
875 Layer layer;
876 ASSERT_NO_FATAL_FAILURE(layer =
877 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
878
879 mWriter->selectDisplay(mPrimaryDisplay);
880 mWriter->selectLayer(layer);
881 mWriter->setLayerBuffer(0, handle, -1);
882 execute();
883 }
884
885 /**
886 * Test IComposerClient::Command::SET_LAYER_SURFACE_DAMAGE.
887 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_SURFACE_DAMAGE)888 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_SURFACE_DAMAGE) {
889 Layer layer;
890 ASSERT_NO_FATAL_FAILURE(layer =
891 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
892
893 IComposerClient::Rect empty{0, 0, 0, 0};
894 IComposerClient::Rect unit{0, 0, 1, 1};
895
896 mWriter->selectDisplay(mPrimaryDisplay);
897 mWriter->selectLayer(layer);
898 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, empty));
899 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, unit));
900 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>());
901 execute();
902 }
903
904 /**
905 * Test IComposerClient::Command::SET_LAYER_BLEND_MODE.
906 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_BLEND_MODE)907 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_BLEND_MODE) {
908 Layer layer;
909 ASSERT_NO_FATAL_FAILURE(layer =
910 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
911
912 mWriter->selectDisplay(mPrimaryDisplay);
913 mWriter->selectLayer(layer);
914 mWriter->setLayerBlendMode(IComposerClient::BlendMode::NONE);
915 mWriter->setLayerBlendMode(IComposerClient::BlendMode::PREMULTIPLIED);
916 mWriter->setLayerBlendMode(IComposerClient::BlendMode::COVERAGE);
917 execute();
918 }
919
920 /**
921 * Test IComposerClient::Command::SET_LAYER_COLOR.
922 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_COLOR)923 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_COLOR) {
924 Layer layer;
925 ASSERT_NO_FATAL_FAILURE(layer =
926 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
927
928 mWriter->selectDisplay(mPrimaryDisplay);
929 mWriter->selectLayer(layer);
930 mWriter->setLayerColor(IComposerClient::Color{0xff, 0xff, 0xff, 0xff});
931 mWriter->setLayerColor(IComposerClient::Color{0, 0, 0, 0});
932 execute();
933 }
934
935 /**
936 * Test IComposerClient::Command::SET_LAYER_COMPOSITION_TYPE.
937 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_COMPOSITION_TYPE)938 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_COMPOSITION_TYPE) {
939 Layer layer;
940 ASSERT_NO_FATAL_FAILURE(layer =
941 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
942
943 mWriter->selectDisplay(mPrimaryDisplay);
944 mWriter->selectLayer(layer);
945 mWriter->setLayerCompositionType(IComposerClient::Composition::CLIENT);
946 mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
947 mWriter->setLayerCompositionType(IComposerClient::Composition::SOLID_COLOR);
948 mWriter->setLayerCompositionType(IComposerClient::Composition::CURSOR);
949 execute();
950 }
951
952 /**
953 * Test IComposerClient::Command::SET_LAYER_DATASPACE.
954 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_DATASPACE)955 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_DATASPACE) {
956 Layer layer;
957 ASSERT_NO_FATAL_FAILURE(layer =
958 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
959
960 mWriter->selectDisplay(mPrimaryDisplay);
961 mWriter->selectLayer(layer);
962 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
963 execute();
964 }
965
966 /**
967 * Test IComposerClient::Command::SET_LAYER_DISPLAY_FRAME.
968 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_DISPLAY_FRAME)969 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_DISPLAY_FRAME) {
970 Layer layer;
971 ASSERT_NO_FATAL_FAILURE(layer =
972 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
973
974 mWriter->selectDisplay(mPrimaryDisplay);
975 mWriter->selectLayer(layer);
976 mWriter->setLayerDisplayFrame(IComposerClient::Rect{0, 0, 1, 1});
977 execute();
978 }
979
980 /**
981 * Test IComposerClient::Command::SET_LAYER_PLANE_ALPHA.
982 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_PLANE_ALPHA)983 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_PLANE_ALPHA) {
984 Layer layer;
985 ASSERT_NO_FATAL_FAILURE(layer =
986 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
987
988 mWriter->selectDisplay(mPrimaryDisplay);
989 mWriter->selectLayer(layer);
990 mWriter->setLayerPlaneAlpha(0.0f);
991 mWriter->setLayerPlaneAlpha(1.0f);
992 execute();
993 }
994
995 /**
996 * Test IComposerClient::Command::SET_LAYER_SIDEBAND_STREAM.
997 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_SIDEBAND_STREAM)998 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_SIDEBAND_STREAM) {
999 if (!mComposer->hasCapability(IComposer::Capability::SIDEBAND_STREAM)) {
1000 GTEST_SUCCEED() << "no sideband stream support";
1001 return;
1002 }
1003
1004 auto handle = allocate();
1005 ASSERT_NE(nullptr, handle);
1006
1007 Layer layer;
1008 ASSERT_NO_FATAL_FAILURE(layer =
1009 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1010
1011 mWriter->selectDisplay(mPrimaryDisplay);
1012 mWriter->selectLayer(layer);
1013 mWriter->setLayerSidebandStream(handle);
1014 execute();
1015 }
1016
1017 /**
1018 * Test IComposerClient::Command::SET_LAYER_SOURCE_CROP.
1019 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_SOURCE_CROP)1020 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_SOURCE_CROP) {
1021 Layer layer;
1022 ASSERT_NO_FATAL_FAILURE(layer =
1023 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1024
1025 mWriter->selectDisplay(mPrimaryDisplay);
1026 mWriter->selectLayer(layer);
1027 mWriter->setLayerSourceCrop(IComposerClient::FRect{0.0f, 0.0f, 1.0f, 1.0f});
1028 execute();
1029 }
1030
1031 /**
1032 * Test IComposerClient::Command::SET_LAYER_TRANSFORM.
1033 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_TRANSFORM)1034 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_TRANSFORM) {
1035 Layer layer;
1036 ASSERT_NO_FATAL_FAILURE(layer =
1037 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1038
1039 mWriter->selectDisplay(mPrimaryDisplay);
1040 mWriter->selectLayer(layer);
1041 mWriter->setLayerTransform(static_cast<Transform>(0));
1042 mWriter->setLayerTransform(Transform::FLIP_H);
1043 mWriter->setLayerTransform(Transform::FLIP_V);
1044 mWriter->setLayerTransform(Transform::ROT_90);
1045 mWriter->setLayerTransform(Transform::ROT_180);
1046 mWriter->setLayerTransform(Transform::ROT_270);
1047 mWriter->setLayerTransform(static_cast<Transform>(Transform::FLIP_H | Transform::ROT_90));
1048 mWriter->setLayerTransform(static_cast<Transform>(Transform::FLIP_V | Transform::ROT_90));
1049 execute();
1050 }
1051
1052 /**
1053 * Test IComposerClient::Command::SET_LAYER_VISIBLE_REGION.
1054 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_VISIBLE_REGION)1055 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_VISIBLE_REGION) {
1056 Layer layer;
1057 ASSERT_NO_FATAL_FAILURE(layer =
1058 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1059
1060 IComposerClient::Rect empty{0, 0, 0, 0};
1061 IComposerClient::Rect unit{0, 0, 1, 1};
1062
1063 mWriter->selectDisplay(mPrimaryDisplay);
1064 mWriter->selectLayer(layer);
1065 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, empty));
1066 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, unit));
1067 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>());
1068 execute();
1069 }
1070
1071 /**
1072 * Test IComposerClient::Command::SET_LAYER_Z_ORDER.
1073 */
TEST_P(GraphicsComposerHidlCommandTest,SET_LAYER_Z_ORDER)1074 TEST_P(GraphicsComposerHidlCommandTest, SET_LAYER_Z_ORDER) {
1075 Layer layer;
1076 ASSERT_NO_FATAL_FAILURE(layer =
1077 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
1078
1079 mWriter->selectDisplay(mPrimaryDisplay);
1080 mWriter->selectLayer(layer);
1081 mWriter->setLayerZOrder(10);
1082 mWriter->setLayerZOrder(0);
1083 execute();
1084 }
1085
1086 INSTANTIATE_TEST_SUITE_P(
1087 PerInstance, GraphicsComposerHidlCommandTest,
1088 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IComposer::descriptor)),
1089 android::hardware::PrintInstanceNameToString);
1090
1091 INSTANTIATE_TEST_SUITE_P(
1092 PerInstance, GraphicsComposerHidlTest,
1093 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IComposer::descriptor)),
1094 android::hardware::PrintInstanceNameToString);
1095
1096 } // namespace
1097 } // namespace vts
1098 } // namespace V2_1
1099 } // namespace composer
1100 } // namespace graphics
1101 } // namespace hardware
1102 } // namespace android
1103