1 /* 2 * Copyright (C) 2017 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 #ifndef VTS_HAL_GRAPHICS_COMPOSER_UTILS 18 #define VTS_HAL_GRAPHICS_COMPOSER_UTILS 19 20 #include <memory> 21 #include <string> 22 #include <unordered_map> 23 #include <unordered_set> 24 #include <vector> 25 26 #include <android/hardware/graphics/composer/2.1/IComposer.h> 27 #include <utils/StrongPointer.h> 28 29 namespace android { 30 namespace hardware { 31 namespace graphics { 32 namespace composer { 33 namespace V2_1 { 34 namespace tests { 35 36 using android::hardware::graphics::common::V1_0::ColorMode; 37 using android::hardware::graphics::common::V1_0::Dataspace; 38 using android::hardware::graphics::common::V1_0::Hdr; 39 using android::hardware::graphics::common::V1_0::PixelFormat; 40 41 class ComposerClient; 42 43 // A wrapper to IComposer. 44 class Composer { 45 public: 46 Composer(); 47 48 sp<IComposer> getRaw() const; 49 50 // Returns true when the composer supports the specified capability. 51 bool hasCapability(IComposer::Capability capability) const; 52 53 std::vector<IComposer::Capability> getCapabilities(); 54 std::string dumpDebugInfo(); 55 std::unique_ptr<ComposerClient> createClient(); 56 57 private: 58 void init(); 59 60 sp<IComposer> mComposer; 61 std::unordered_set<IComposer::Capability> mCapabilities; 62 }; 63 64 // A wrapper to IComposerClient. 65 class ComposerClient { 66 public: 67 ComposerClient(const sp<IComposerClient>& client); 68 ~ComposerClient(); 69 70 sp<IComposerClient> getRaw() const; 71 72 void registerCallback(const sp<IComposerCallback>& callback); 73 uint32_t getMaxVirtualDisplayCount(); 74 75 Display createVirtualDisplay(uint32_t width, uint32_t height, 76 PixelFormat formatHint, 77 uint32_t outputBufferSlotCount, 78 PixelFormat* outFormat); 79 void destroyVirtualDisplay(Display display); 80 81 Layer createLayer(Display display, uint32_t bufferSlotCount); 82 void destroyLayer(Display display, Layer layer); 83 84 Config getActiveConfig(Display display); 85 bool getClientTargetSupport(Display display, uint32_t width, uint32_t height, 86 PixelFormat format, Dataspace dataspace); 87 std::vector<ColorMode> getColorModes(Display display); 88 int32_t getDisplayAttribute(Display display, Config config, 89 IComposerClient::Attribute attribute); 90 std::vector<Config> getDisplayConfigs(Display display); 91 std::string getDisplayName(Display display); 92 IComposerClient::DisplayType getDisplayType(Display display); 93 bool getDozeSupport(Display display); 94 std::vector<Hdr> getHdrCapabilities(Display display, float* outMaxLuminance, 95 float* outMaxAverageLuminance, 96 float* outMinLuminance); 97 98 void setClientTargetSlotCount(Display display, 99 uint32_t clientTargetSlotCount); 100 void setActiveConfig(Display display, Config config); 101 void setColorMode(Display display, ColorMode mode); 102 void setPowerMode(Display display, IComposerClient::PowerMode mode); 103 void setVsyncEnabled(Display display, bool enabled); 104 105 private: 106 sp<IComposerClient> mClient; 107 108 // Keep track of all virtual displays and layers. When a test fails with 109 // ASSERT_*, the destructor will clean up the resources for the test. 110 struct DisplayResource { DisplayResourceDisplayResource111 DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {} 112 113 bool isVirtual; 114 std::unordered_set<Layer> layers; 115 }; 116 std::unordered_map<Display, DisplayResource> mDisplayResources; 117 }; 118 119 } // namespace tests 120 } // namespace V2_1 121 } // namespace composer 122 } // namespace graphics 123 } // namespace hardware 124 } // namespace android 125 126 #endif // VTS_HAL_GRAPHICS_COMPOSER_UTILS 127