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