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 <mapper-vts/2.0/MapperVts.h>
24
25 #include <VtsHalHidlTargetTestBase.h>
26 #include <VtsHalHidlTargetTestEnvBase.h>
27 #include <unistd.h>
28
29 #include <algorithm>
30 #include <array>
31 #include <memory>
32 #include <mutex>
33 #include <unordered_set>
34 #include <vector>
35
36 namespace android {
37 namespace hardware {
38 namespace graphics {
39 namespace composer {
40 namespace V2_1 {
41 namespace vts {
42 namespace {
43
44 using android::hardware::graphics::common::V1_0::BufferUsage;
45 using android::hardware::graphics::common::V1_0::ColorMode;
46 using android::hardware::graphics::common::V1_0::ColorTransform;
47 using android::hardware::graphics::common::V1_0::Dataspace;
48 using android::hardware::graphics::common::V1_0::PixelFormat;
49 using android::hardware::graphics::common::V1_0::Transform;
50 using android::hardware::graphics::mapper::V2_0::IMapper;
51 using android::hardware::graphics::mapper::V2_0::vts::Gralloc;
52 using GrallocError = android::hardware::graphics::mapper::V2_0::Error;
53
54 // Test environment for graphics.composer
55 class GraphicsComposerHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
56 public:
57 // get the test environment singleton
Instance()58 static GraphicsComposerHidlEnvironment* Instance() {
59 static GraphicsComposerHidlEnvironment* instance = new GraphicsComposerHidlEnvironment;
60 return instance;
61 }
62
registerTestServices()63 virtual void registerTestServices() override { registerTestService<IComposer>(); }
64
65 private:
GraphicsComposerHidlEnvironment()66 GraphicsComposerHidlEnvironment() {}
67
68 GTEST_DISALLOW_COPY_AND_ASSIGN_(GraphicsComposerHidlEnvironment);
69 };
70
71 class GraphicsComposerHidlTest : public ::testing::VtsHalHidlTargetTestBase {
72 protected:
SetUp()73 void SetUp() override {
74 ASSERT_NO_FATAL_FAILURE(
75 mComposer = std::make_unique<Composer>(
76 GraphicsComposerHidlEnvironment::Instance()->getServiceName<IComposer>()));
77 ASSERT_NO_FATAL_FAILURE(mComposerClient = mComposer->createClient());
78
79 mComposerCallback = new GraphicsComposerCallback;
80 mComposerClient->registerCallback(mComposerCallback);
81
82 // assume the first display is primary and is never removed
83 mPrimaryDisplay = waitForFirstDisplay();
84
85 // explicitly disable vsync
86 mComposerClient->setVsyncEnabled(mPrimaryDisplay, false);
87 mComposerCallback->setVsyncAllowed(false);
88 }
89
TearDown()90 void TearDown() override {
91 if (mComposerCallback != nullptr) {
92 EXPECT_EQ(0, mComposerCallback->getInvalidHotplugCount());
93 EXPECT_EQ(0, mComposerCallback->getInvalidRefreshCount());
94 EXPECT_EQ(0, mComposerCallback->getInvalidVsyncCount());
95 }
96 }
97
98 // use the slot count usually set by SF
99 static constexpr uint32_t kBufferSlotCount = 64;
100
101 std::unique_ptr<Composer> mComposer;
102 std::unique_ptr<ComposerClient> mComposerClient;
103 sp<GraphicsComposerCallback> mComposerCallback;
104 // the first display and is assumed never to be removed
105 Display mPrimaryDisplay;
106
107 private:
waitForFirstDisplay()108 Display waitForFirstDisplay() {
109 while (true) {
110 std::vector<Display> displays = mComposerCallback->getDisplays();
111 if (displays.empty()) {
112 usleep(5 * 1000);
113 continue;
114 }
115
116 return displays[0];
117 }
118 }
119 };
120
121 /**
122 * Test IComposer::getCapabilities.
123 *
124 * Test that IComposer::getCapabilities returns no invalid capabilities.
125 */
TEST_F(GraphicsComposerHidlTest,GetCapabilities)126 TEST_F(GraphicsComposerHidlTest, GetCapabilities) {
127 auto capabilities = mComposer->getCapabilities();
128 ASSERT_EQ(capabilities.end(),
129 std::find(capabilities.begin(), capabilities.end(), IComposer::Capability::INVALID));
130 }
131
132 /**
133 * Test IComposer::dumpDebugInfo.
134 */
TEST_F(GraphicsComposerHidlTest,DumpDebugInfo)135 TEST_F(GraphicsComposerHidlTest, DumpDebugInfo) {
136 mComposer->dumpDebugInfo();
137 }
138
139 /**
140 * Test IComposer::createClient.
141 *
142 * Test that IComposerClient is a singleton.
143 */
TEST_F(GraphicsComposerHidlTest,CreateClientSingleton)144 TEST_F(GraphicsComposerHidlTest, CreateClientSingleton) {
145 mComposer->getRaw()->createClient(
146 [&](const auto& tmpError, const auto&) { EXPECT_EQ(Error::NO_RESOURCES, tmpError); });
147 }
148
149 /**
150 * Test IComposerClient::createVirtualDisplay and
151 * IComposerClient::destroyVirtualDisplay.
152 *
153 * Test that virtual displays can be created and has the correct display type.
154 */
TEST_F(GraphicsComposerHidlTest,CreateVirtualDisplay)155 TEST_F(GraphicsComposerHidlTest, CreateVirtualDisplay) {
156 if (mComposerClient->getMaxVirtualDisplayCount() == 0) {
157 GTEST_SUCCEED() << "no virtual display support";
158 return;
159 }
160
161 Display display;
162 PixelFormat format;
163 ASSERT_NO_FATAL_FAILURE(
164 display = mComposerClient->createVirtualDisplay(64, 64, PixelFormat::IMPLEMENTATION_DEFINED,
165 kBufferSlotCount, &format));
166
167 // test display type
168 IComposerClient::DisplayType type = mComposerClient->getDisplayType(display);
169 EXPECT_EQ(IComposerClient::DisplayType::VIRTUAL, type);
170
171 mComposerClient->destroyVirtualDisplay(display);
172 }
173
174 /**
175 * Test IComposerClient::createLayer and IComposerClient::destroyLayer.
176 *
177 * Test that layers can be created and destroyed.
178 */
TEST_F(GraphicsComposerHidlTest,CreateLayer)179 TEST_F(GraphicsComposerHidlTest, CreateLayer) {
180 Layer layer;
181 ASSERT_NO_FATAL_FAILURE(layer =
182 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
183
184 mComposerClient->destroyLayer(mPrimaryDisplay, layer);
185 }
186
187 /**
188 * Test IComposerClient::getDisplayName.
189 */
TEST_F(GraphicsComposerHidlTest,GetDisplayName)190 TEST_F(GraphicsComposerHidlTest, GetDisplayName) {
191 mComposerClient->getDisplayName(mPrimaryDisplay);
192 }
193
194 /**
195 * Test IComposerClient::getDisplayType.
196 *
197 * Test that IComposerClient::getDisplayType returns the correct display type
198 * for the primary display.
199 */
TEST_F(GraphicsComposerHidlTest,GetDisplayType)200 TEST_F(GraphicsComposerHidlTest, GetDisplayType) {
201 ASSERT_EQ(IComposerClient::DisplayType::PHYSICAL,
202 mComposerClient->getDisplayType(mPrimaryDisplay));
203 }
204
205 /**
206 * Test IComposerClient::getClientTargetSupport.
207 *
208 * Test that IComposerClient::getClientTargetSupport returns true for the
209 * required client targets.
210 */
TEST_F(GraphicsComposerHidlTest,GetClientTargetSupport)211 TEST_F(GraphicsComposerHidlTest, GetClientTargetSupport) {
212 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
213 for (auto config : configs) {
214 int32_t width = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
215 IComposerClient::Attribute::WIDTH);
216 int32_t height = mComposerClient->getDisplayAttribute(mPrimaryDisplay, config,
217 IComposerClient::Attribute::HEIGHT);
218 ASSERT_LT(0, width);
219 ASSERT_LT(0, height);
220
221 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
222
223 ASSERT_TRUE(mComposerClient->getClientTargetSupport(
224 mPrimaryDisplay, width, height, PixelFormat::RGBA_8888, Dataspace::UNKNOWN));
225 }
226 }
227
228 /**
229 * Test IComposerClient::getDisplayAttribute.
230 *
231 * Test that IComposerClient::getDisplayAttribute succeeds for the required
232 * formats, and succeeds or fails correctly for optional attributes.
233 */
TEST_F(GraphicsComposerHidlTest,GetDisplayAttribute)234 TEST_F(GraphicsComposerHidlTest, GetDisplayAttribute) {
235 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
236 for (auto config : configs) {
237 const std::array<IComposerClient::Attribute, 3> requiredAttributes = {{
238 IComposerClient::Attribute::WIDTH, IComposerClient::Attribute::HEIGHT,
239 IComposerClient::Attribute::VSYNC_PERIOD,
240 }};
241 for (auto attribute : requiredAttributes) {
242 mComposerClient->getDisplayAttribute(mPrimaryDisplay, config, attribute);
243 }
244
245 const std::array<IComposerClient::Attribute, 2> optionalAttributes = {{
246 IComposerClient::Attribute::DPI_X, IComposerClient::Attribute::DPI_Y,
247 }};
248 for (auto attribute : optionalAttributes) {
249 mComposerClient->getRaw()->getDisplayAttribute(
250 mPrimaryDisplay, config, attribute, [&](const auto& tmpError, const auto&) {
251 EXPECT_TRUE(tmpError == Error::NONE || tmpError == Error::UNSUPPORTED);
252 });
253 }
254 }
255 }
256
257 /**
258 * Test IComposerClient::getHdrCapabilities.
259 */
TEST_F(GraphicsComposerHidlTest,GetHdrCapabilities)260 TEST_F(GraphicsComposerHidlTest, GetHdrCapabilities) {
261 float maxLuminance;
262 float maxAverageLuminance;
263 float minLuminance;
264 mComposerClient->getHdrCapabilities(mPrimaryDisplay, &maxLuminance, &maxAverageLuminance,
265 &minLuminance);
266 }
267
268 /**
269 * Test IComposerClient::setClientTargetSlotCount.
270 */
TEST_F(GraphicsComposerHidlTest,SetClientTargetSlotCount)271 TEST_F(GraphicsComposerHidlTest, SetClientTargetSlotCount) {
272 mComposerClient->setClientTargetSlotCount(mPrimaryDisplay, kBufferSlotCount);
273 }
274
275 /**
276 * Test IComposerClient::setActiveConfig.
277 *
278 * Test that IComposerClient::setActiveConfig succeeds for all display
279 * configs.
280 */
TEST_F(GraphicsComposerHidlTest,SetActiveConfig)281 TEST_F(GraphicsComposerHidlTest, SetActiveConfig) {
282 std::vector<Config> configs = mComposerClient->getDisplayConfigs(mPrimaryDisplay);
283 for (auto config : configs) {
284 mComposerClient->setActiveConfig(mPrimaryDisplay, config);
285 ASSERT_EQ(config, mComposerClient->getActiveConfig(mPrimaryDisplay));
286 }
287 }
288
289 /**
290 * Test IComposerClient::setColorMode.
291 *
292 * Test that IComposerClient::setColorMode succeeds for all color modes.
293 */
TEST_F(GraphicsComposerHidlTest,SetColorMode)294 TEST_F(GraphicsComposerHidlTest, SetColorMode) {
295 std::unordered_set<ColorMode> validModes;
296 for (auto mode : hidl_enum_iterator<ColorMode>()) {
297 validModes.insert(mode);
298 }
299
300 std::vector<ColorMode> modes = mComposerClient->getColorModes(mPrimaryDisplay);
301 for (auto mode : modes) {
302 if (validModes.count(mode)) {
303 mComposerClient->setColorMode(mPrimaryDisplay, mode);
304 }
305 }
306 }
307
308 /**
309 * Test IComposerClient::setPowerMode.
310 *
311 * Test that IComposerClient::setPowerMode succeeds for all power modes.
312 */
TEST_F(GraphicsComposerHidlTest,SetPowerMode)313 TEST_F(GraphicsComposerHidlTest, SetPowerMode) {
314 std::vector<IComposerClient::PowerMode> modes;
315 modes.push_back(IComposerClient::PowerMode::OFF);
316
317 if (mComposerClient->getDozeSupport(mPrimaryDisplay)) {
318 modes.push_back(IComposerClient::PowerMode::DOZE);
319 modes.push_back(IComposerClient::PowerMode::DOZE_SUSPEND);
320 }
321
322 // push ON last
323 modes.push_back(IComposerClient::PowerMode::ON);
324
325 for (auto mode : modes) {
326 mComposerClient->setPowerMode(mPrimaryDisplay, mode);
327 }
328 }
329
330 /**
331 * Test IComposerClient::setVsyncEnabled.
332 *
333 * Test that IComposerClient::setVsyncEnabled succeeds and there is no
334 * spurious vsync events.
335 */
TEST_F(GraphicsComposerHidlTest,SetVsyncEnabled)336 TEST_F(GraphicsComposerHidlTest, SetVsyncEnabled) {
337 mComposerCallback->setVsyncAllowed(true);
338
339 mComposerClient->setVsyncEnabled(mPrimaryDisplay, true);
340 usleep(60 * 1000);
341 mComposerClient->setVsyncEnabled(mPrimaryDisplay, false);
342
343 mComposerCallback->setVsyncAllowed(false);
344 }
345
346 // Tests for IComposerClient::Command.
347 class GraphicsComposerHidlCommandTest : public GraphicsComposerHidlTest {
348 protected:
SetUp()349 void SetUp() override {
350 ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::SetUp());
351
352 ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>());
353
354 mWriter = std::make_unique<CommandWriterBase>(1024);
355 mReader = std::make_unique<TestCommandReader>();
356 }
357
TearDown()358 void TearDown() override { ASSERT_NO_FATAL_FAILURE(GraphicsComposerHidlTest::TearDown()); }
359
allocate()360 const native_handle_t* allocate() {
361 IMapper::BufferDescriptorInfo info{};
362 info.width = 64;
363 info.height = 64;
364 info.layerCount = 1;
365 info.format = PixelFormat::RGBA_8888;
366 info.usage =
367 static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN | BufferUsage::CPU_READ_OFTEN);
368
369 return mGralloc->allocate(info);
370 }
371
execute()372 void execute() { mComposerClient->execute(mReader.get(), mWriter.get()); }
373
374 std::unique_ptr<CommandWriterBase> mWriter;
375 std::unique_ptr<TestCommandReader> mReader;
376
377 private:
378 std::unique_ptr<Gralloc> mGralloc;
379 };
380
381 /**
382 * Test IComposerClient::Command::SET_COLOR_TRANSFORM.
383 */
TEST_F(GraphicsComposerHidlCommandTest,SET_COLOR_TRANSFORM)384 TEST_F(GraphicsComposerHidlCommandTest, SET_COLOR_TRANSFORM) {
385 const std::array<float, 16> identity = {{
386 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,
387 1.0f,
388 }};
389
390 mWriter->selectDisplay(mPrimaryDisplay);
391 mWriter->setColorTransform(identity.data(), ColorTransform::IDENTITY);
392
393 execute();
394 }
395
396 /**
397 * Test IComposerClient::Command::SET_CLIENT_TARGET.
398 */
TEST_F(GraphicsComposerHidlCommandTest,SET_CLIENT_TARGET)399 TEST_F(GraphicsComposerHidlCommandTest, SET_CLIENT_TARGET) {
400 mComposerClient->setClientTargetSlotCount(mPrimaryDisplay, kBufferSlotCount);
401
402 mWriter->selectDisplay(mPrimaryDisplay);
403 mWriter->setClientTarget(0, nullptr, -1, Dataspace::UNKNOWN,
404 std::vector<IComposerClient::Rect>());
405
406 execute();
407 }
408
409 /**
410 * Test IComposerClient::Command::SET_OUTPUT_BUFFER.
411 */
TEST_F(GraphicsComposerHidlCommandTest,SET_OUTPUT_BUFFER)412 TEST_F(GraphicsComposerHidlCommandTest, SET_OUTPUT_BUFFER) {
413 if (mComposerClient->getMaxVirtualDisplayCount() == 0) {
414 GTEST_SUCCEED() << "no virtual display support";
415 return;
416 }
417
418 Display display;
419 PixelFormat format;
420 ASSERT_NO_FATAL_FAILURE(
421 display = mComposerClient->createVirtualDisplay(64, 64, PixelFormat::IMPLEMENTATION_DEFINED,
422 kBufferSlotCount, &format));
423
424 const native_handle_t* handle;
425 ASSERT_NO_FATAL_FAILURE(handle = allocate());
426
427 mWriter->selectDisplay(display);
428 mWriter->setOutputBuffer(0, handle, -1);
429 execute();
430 }
431
432 /**
433 * Test IComposerClient::Command::VALIDATE_DISPLAY.
434 */
TEST_F(GraphicsComposerHidlCommandTest,VALIDATE_DISPLAY)435 TEST_F(GraphicsComposerHidlCommandTest, VALIDATE_DISPLAY) {
436 mWriter->selectDisplay(mPrimaryDisplay);
437 mWriter->validateDisplay();
438 execute();
439 }
440
441 /**
442 * Test IComposerClient::Command::ACCEPT_DISPLAY_CHANGES.
443 */
TEST_F(GraphicsComposerHidlCommandTest,ACCEPT_DISPLAY_CHANGES)444 TEST_F(GraphicsComposerHidlCommandTest, ACCEPT_DISPLAY_CHANGES) {
445 mWriter->selectDisplay(mPrimaryDisplay);
446 mWriter->validateDisplay();
447 mWriter->acceptDisplayChanges();
448 execute();
449 }
450
451 /**
452 * Test IComposerClient::Command::PRESENT_DISPLAY.
453 */
TEST_F(GraphicsComposerHidlCommandTest,PRESENT_DISPLAY)454 TEST_F(GraphicsComposerHidlCommandTest, PRESENT_DISPLAY) {
455 mWriter->selectDisplay(mPrimaryDisplay);
456 mWriter->validateDisplay();
457 mWriter->presentDisplay();
458 execute();
459 }
460
461 /**
462 * Test IComposerClient::Command::SET_LAYER_CURSOR_POSITION.
463 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_CURSOR_POSITION)464 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_CURSOR_POSITION) {
465 Layer layer;
466 ASSERT_NO_FATAL_FAILURE(layer =
467 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
468
469 mWriter->selectDisplay(mPrimaryDisplay);
470 mWriter->selectLayer(layer);
471 mWriter->setLayerCursorPosition(1, 1);
472 mWriter->setLayerCursorPosition(0, 0);
473 execute();
474 }
475
476 /**
477 * Test IComposerClient::Command::SET_LAYER_BUFFER.
478 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_BUFFER)479 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_BUFFER) {
480 auto handle = allocate();
481 ASSERT_NE(nullptr, handle);
482
483 Layer layer;
484 ASSERT_NO_FATAL_FAILURE(layer =
485 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
486
487 mWriter->selectDisplay(mPrimaryDisplay);
488 mWriter->selectLayer(layer);
489 mWriter->setLayerBuffer(0, handle, -1);
490 execute();
491 }
492
493 /**
494 * Test IComposerClient::Command::SET_LAYER_SURFACE_DAMAGE.
495 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_SURFACE_DAMAGE)496 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_SURFACE_DAMAGE) {
497 Layer layer;
498 ASSERT_NO_FATAL_FAILURE(layer =
499 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
500
501 IComposerClient::Rect empty{0, 0, 0, 0};
502 IComposerClient::Rect unit{0, 0, 1, 1};
503
504 mWriter->selectDisplay(mPrimaryDisplay);
505 mWriter->selectLayer(layer);
506 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, empty));
507 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>(1, unit));
508 mWriter->setLayerSurfaceDamage(std::vector<IComposerClient::Rect>());
509 execute();
510 }
511
512 /**
513 * Test IComposerClient::Command::SET_LAYER_BLEND_MODE.
514 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_BLEND_MODE)515 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_BLEND_MODE) {
516 Layer layer;
517 ASSERT_NO_FATAL_FAILURE(layer =
518 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
519
520 mWriter->selectDisplay(mPrimaryDisplay);
521 mWriter->selectLayer(layer);
522 mWriter->setLayerBlendMode(IComposerClient::BlendMode::NONE);
523 mWriter->setLayerBlendMode(IComposerClient::BlendMode::PREMULTIPLIED);
524 mWriter->setLayerBlendMode(IComposerClient::BlendMode::COVERAGE);
525 execute();
526 }
527
528 /**
529 * Test IComposerClient::Command::SET_LAYER_COLOR.
530 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_COLOR)531 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_COLOR) {
532 Layer layer;
533 ASSERT_NO_FATAL_FAILURE(layer =
534 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
535
536 mWriter->selectDisplay(mPrimaryDisplay);
537 mWriter->selectLayer(layer);
538 mWriter->setLayerColor(IComposerClient::Color{0xff, 0xff, 0xff, 0xff});
539 mWriter->setLayerColor(IComposerClient::Color{0, 0, 0, 0});
540 execute();
541 }
542
543 /**
544 * Test IComposerClient::Command::SET_LAYER_COMPOSITION_TYPE.
545 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_COMPOSITION_TYPE)546 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_COMPOSITION_TYPE) {
547 Layer layer;
548 ASSERT_NO_FATAL_FAILURE(layer =
549 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
550
551 mWriter->selectDisplay(mPrimaryDisplay);
552 mWriter->selectLayer(layer);
553 mWriter->setLayerCompositionType(IComposerClient::Composition::CLIENT);
554 mWriter->setLayerCompositionType(IComposerClient::Composition::DEVICE);
555 mWriter->setLayerCompositionType(IComposerClient::Composition::SOLID_COLOR);
556 mWriter->setLayerCompositionType(IComposerClient::Composition::CURSOR);
557 execute();
558 }
559
560 /**
561 * Test IComposerClient::Command::SET_LAYER_DATASPACE.
562 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_DATASPACE)563 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_DATASPACE) {
564 Layer layer;
565 ASSERT_NO_FATAL_FAILURE(layer =
566 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
567
568 mWriter->selectDisplay(mPrimaryDisplay);
569 mWriter->selectLayer(layer);
570 mWriter->setLayerDataspace(Dataspace::UNKNOWN);
571 execute();
572 }
573
574 /**
575 * Test IComposerClient::Command::SET_LAYER_DISPLAY_FRAME.
576 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_DISPLAY_FRAME)577 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_DISPLAY_FRAME) {
578 Layer layer;
579 ASSERT_NO_FATAL_FAILURE(layer =
580 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
581
582 mWriter->selectDisplay(mPrimaryDisplay);
583 mWriter->selectLayer(layer);
584 mWriter->setLayerDisplayFrame(IComposerClient::Rect{0, 0, 1, 1});
585 execute();
586 }
587
588 /**
589 * Test IComposerClient::Command::SET_LAYER_PLANE_ALPHA.
590 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_PLANE_ALPHA)591 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_PLANE_ALPHA) {
592 Layer layer;
593 ASSERT_NO_FATAL_FAILURE(layer =
594 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
595
596 mWriter->selectDisplay(mPrimaryDisplay);
597 mWriter->selectLayer(layer);
598 mWriter->setLayerPlaneAlpha(0.0f);
599 mWriter->setLayerPlaneAlpha(1.0f);
600 execute();
601 }
602
603 /**
604 * Test IComposerClient::Command::SET_LAYER_SIDEBAND_STREAM.
605 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_SIDEBAND_STREAM)606 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_SIDEBAND_STREAM) {
607 if (!mComposer->hasCapability(IComposer::Capability::SIDEBAND_STREAM)) {
608 GTEST_SUCCEED() << "no sideband stream support";
609 return;
610 }
611
612 auto handle = allocate();
613 ASSERT_NE(nullptr, handle);
614
615 Layer layer;
616 ASSERT_NO_FATAL_FAILURE(layer =
617 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
618
619 mWriter->selectDisplay(mPrimaryDisplay);
620 mWriter->selectLayer(layer);
621 mWriter->setLayerSidebandStream(handle);
622 execute();
623 }
624
625 /**
626 * Test IComposerClient::Command::SET_LAYER_SOURCE_CROP.
627 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_SOURCE_CROP)628 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_SOURCE_CROP) {
629 Layer layer;
630 ASSERT_NO_FATAL_FAILURE(layer =
631 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
632
633 mWriter->selectDisplay(mPrimaryDisplay);
634 mWriter->selectLayer(layer);
635 mWriter->setLayerSourceCrop(IComposerClient::FRect{0.0f, 0.0f, 1.0f, 1.0f});
636 execute();
637 }
638
639 /**
640 * Test IComposerClient::Command::SET_LAYER_TRANSFORM.
641 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_TRANSFORM)642 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_TRANSFORM) {
643 Layer layer;
644 ASSERT_NO_FATAL_FAILURE(layer =
645 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
646
647 mWriter->selectDisplay(mPrimaryDisplay);
648 mWriter->selectLayer(layer);
649 mWriter->setLayerTransform(static_cast<Transform>(0));
650 mWriter->setLayerTransform(Transform::FLIP_H);
651 mWriter->setLayerTransform(Transform::FLIP_V);
652 mWriter->setLayerTransform(Transform::ROT_90);
653 mWriter->setLayerTransform(Transform::ROT_180);
654 mWriter->setLayerTransform(Transform::ROT_270);
655 mWriter->setLayerTransform(static_cast<Transform>(Transform::FLIP_H | Transform::ROT_90));
656 mWriter->setLayerTransform(static_cast<Transform>(Transform::FLIP_V | Transform::ROT_90));
657 execute();
658 }
659
660 /**
661 * Test IComposerClient::Command::SET_LAYER_VISIBLE_REGION.
662 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_VISIBLE_REGION)663 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_VISIBLE_REGION) {
664 Layer layer;
665 ASSERT_NO_FATAL_FAILURE(layer =
666 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
667
668 IComposerClient::Rect empty{0, 0, 0, 0};
669 IComposerClient::Rect unit{0, 0, 1, 1};
670
671 mWriter->selectDisplay(mPrimaryDisplay);
672 mWriter->selectLayer(layer);
673 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, empty));
674 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>(1, unit));
675 mWriter->setLayerVisibleRegion(std::vector<IComposerClient::Rect>());
676 execute();
677 }
678
679 /**
680 * Test IComposerClient::Command::SET_LAYER_Z_ORDER.
681 */
TEST_F(GraphicsComposerHidlCommandTest,SET_LAYER_Z_ORDER)682 TEST_F(GraphicsComposerHidlCommandTest, SET_LAYER_Z_ORDER) {
683 Layer layer;
684 ASSERT_NO_FATAL_FAILURE(layer =
685 mComposerClient->createLayer(mPrimaryDisplay, kBufferSlotCount));
686
687 mWriter->selectDisplay(mPrimaryDisplay);
688 mWriter->selectLayer(layer);
689 mWriter->setLayerZOrder(10);
690 mWriter->setLayerZOrder(0);
691 execute();
692 }
693
694 } // namespace
695 } // namespace vts
696 } // namespace V2_1
697 } // namespace composer
698 } // namespace graphics
699 } // namespace hardware
700 } // namespace android
701
main(int argc,char ** argv)702 int main(int argc, char** argv) {
703 using android::hardware::graphics::composer::V2_1::vts::GraphicsComposerHidlEnvironment;
704 ::testing::AddGlobalTestEnvironment(GraphicsComposerHidlEnvironment::Instance());
705 ::testing::InitGoogleTest(&argc, argv);
706 GraphicsComposerHidlEnvironment::Instance()->init(&argc, argv);
707 int status = RUN_ALL_TESTS();
708 ALOGI("Test result = %d", status);
709 return status;
710 }
711