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