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 #pragma once 18 19 #include <memory> 20 #include <string> 21 #include <unordered_map> 22 #include <unordered_set> 23 #include <vector> 24 25 #include <android/hardware/graphics/composer/2.1/IComposer.h> 26 #include <composer-command-buffer/2.1/ComposerCommandBuffer.h> 27 #include <composer-vts/2.1/TestCommandReader.h> 28 #include <utils/StrongPointer.h> 29 30 #include "gtest/gtest.h" 31 32 namespace android { 33 namespace hardware { 34 namespace graphics { 35 namespace composer { 36 namespace V2_1 { 37 namespace vts { 38 39 using android::hardware::graphics::common::V1_0::ColorMode; 40 using android::hardware::graphics::common::V1_0::Dataspace; 41 using android::hardware::graphics::common::V1_0::Hdr; 42 using android::hardware::graphics::common::V1_0::PixelFormat; 43 44 class ComposerClient; 45 46 // A wrapper to IComposer. 47 class Composer { 48 public: 49 Composer(); 50 explicit Composer(const std::string& name); 51 explicit Composer(const sp<IComposer>& composer); 52 53 sp<IComposer> getRaw() const; 54 55 // Returns true when the composer supports the specified capability. 56 bool hasCapability(IComposer::Capability capability) const; 57 58 std::vector<IComposer::Capability> getCapabilities(); 59 std::string dumpDebugInfo(); 60 std::unique_ptr<ComposerClient> createClient(); 61 62 private: 63 const sp<IComposer> mComposer; 64 65 std::unordered_set<IComposer::Capability> mCapabilities; 66 }; 67 68 // A wrapper to IComposerClient. 69 class ComposerClient { 70 public: 71 explicit ComposerClient(const sp<IComposerClient>& client); 72 ~ComposerClient(); 73 74 sp<IComposerClient> getRaw() const; 75 76 void registerCallback(const sp<IComposerCallback>& callback); 77 uint32_t getMaxVirtualDisplayCount(); 78 79 Display createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat formatHint, 80 uint32_t outputBufferSlotCount, PixelFormat* outFormat); 81 void destroyVirtualDisplay(Display display); 82 83 Layer createLayer(Display display, uint32_t bufferSlotCount); 84 void destroyLayer(Display display, Layer layer); 85 86 Config getActiveConfig(Display display); 87 bool getClientTargetSupport(Display display, uint32_t width, uint32_t height, 88 PixelFormat format, Dataspace dataspace); 89 std::vector<ColorMode> getColorModes(Display display); 90 int32_t getDisplayAttribute(Display display, Config config, 91 IComposerClient::Attribute attribute); 92 std::vector<Config> getDisplayConfigs(Display display); 93 std::string getDisplayName(Display display); 94 IComposerClient::DisplayType getDisplayType(Display display); 95 bool getDozeSupport(Display display); 96 std::vector<Hdr> getHdrCapabilities(Display display, float* outMaxLuminance, 97 float* outMaxAverageLuminance, float* outMinLuminance); 98 99 void setClientTargetSlotCount(Display display, 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 void execute(TestCommandReader* reader, CommandWriterBase* writer); 106 107 protected: 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 private: 119 const sp<IComposerClient> mClient; 120 }; 121 122 } // namespace vts 123 } // namespace V2_1 124 } // namespace composer 125 } // namespace graphics 126 } // namespace hardware 127 } // namespace android 128