Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 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> |
Courtney Goeltzenleuchter | 5ecd86a | 2018-01-12 14:00:56 -0800 | [diff] [blame] | 27 | #include <composer-command-buffer/2.1/ComposerCommandBuffer.h> |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 28 | #include <utils/StrongPointer.h> |
| 29 | |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 30 | #include "TestCommandReader.h" |
| 31 | |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 32 | namespace android { |
| 33 | namespace hardware { |
| 34 | namespace graphics { |
| 35 | namespace composer { |
| 36 | namespace V2_1 { |
| 37 | namespace tests { |
| 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(); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 50 | explicit Composer(const std::string& name); |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 51 | |
| 52 | sp<IComposer> getRaw() const; |
| 53 | |
| 54 | // Returns true when the composer supports the specified capability. |
| 55 | bool hasCapability(IComposer::Capability capability) const; |
| 56 | |
| 57 | std::vector<IComposer::Capability> getCapabilities(); |
| 58 | std::string dumpDebugInfo(); |
| 59 | std::unique_ptr<ComposerClient> createClient(); |
| 60 | |
Courtney Goeltzenleuchter | be92bb9 | 2018-01-11 08:50:03 -0800 | [diff] [blame] | 61 | protected: |
| 62 | sp<IComposer> mComposer; |
| 63 | |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 64 | private: |
| 65 | void init(); |
| 66 | |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 67 | std::unordered_set<IComposer::Capability> mCapabilities; |
| 68 | }; |
| 69 | |
| 70 | // A wrapper to IComposerClient. |
| 71 | class ComposerClient { |
| 72 | public: |
| 73 | ComposerClient(const sp<IComposerClient>& client); |
| 74 | ~ComposerClient(); |
| 75 | |
| 76 | sp<IComposerClient> getRaw() const; |
| 77 | |
| 78 | void registerCallback(const sp<IComposerCallback>& callback); |
| 79 | uint32_t getMaxVirtualDisplayCount(); |
| 80 | |
| 81 | Display createVirtualDisplay(uint32_t width, uint32_t height, |
| 82 | PixelFormat formatHint, |
| 83 | uint32_t outputBufferSlotCount, |
| 84 | PixelFormat* outFormat); |
| 85 | void destroyVirtualDisplay(Display display); |
| 86 | |
| 87 | Layer createLayer(Display display, uint32_t bufferSlotCount); |
| 88 | void destroyLayer(Display display, Layer layer); |
| 89 | |
| 90 | Config getActiveConfig(Display display); |
| 91 | bool getClientTargetSupport(Display display, uint32_t width, uint32_t height, |
| 92 | PixelFormat format, Dataspace dataspace); |
| 93 | std::vector<ColorMode> getColorModes(Display display); |
| 94 | int32_t getDisplayAttribute(Display display, Config config, |
| 95 | IComposerClient::Attribute attribute); |
| 96 | std::vector<Config> getDisplayConfigs(Display display); |
| 97 | std::string getDisplayName(Display display); |
| 98 | IComposerClient::DisplayType getDisplayType(Display display); |
| 99 | bool getDozeSupport(Display display); |
| 100 | std::vector<Hdr> getHdrCapabilities(Display display, float* outMaxLuminance, |
| 101 | float* outMaxAverageLuminance, |
| 102 | float* outMinLuminance); |
| 103 | |
| 104 | void setClientTargetSlotCount(Display display, |
| 105 | uint32_t clientTargetSlotCount); |
| 106 | void setActiveConfig(Display display, Config config); |
| 107 | void setColorMode(Display display, ColorMode mode); |
| 108 | void setPowerMode(Display display, IComposerClient::PowerMode mode); |
| 109 | void setVsyncEnabled(Display display, bool enabled); |
| 110 | |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 111 | void execute(TestCommandReader* reader, CommandWriterBase* writer); |
| 112 | |
Chia-I Wu | 8cc5a15 | 2017-02-24 14:34:02 -0800 | [diff] [blame] | 113 | private: |
| 114 | sp<IComposerClient> mClient; |
| 115 | |
| 116 | // Keep track of all virtual displays and layers. When a test fails with |
| 117 | // ASSERT_*, the destructor will clean up the resources for the test. |
| 118 | struct DisplayResource { |
| 119 | DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {} |
| 120 | |
| 121 | bool isVirtual; |
| 122 | std::unordered_set<Layer> layers; |
| 123 | }; |
| 124 | std::unordered_map<Display, DisplayResource> mDisplayResources; |
| 125 | }; |
| 126 | |
| 127 | } // namespace tests |
| 128 | } // namespace V2_1 |
| 129 | } // namespace composer |
| 130 | } // namespace graphics |
| 131 | } // namespace hardware |
| 132 | } // namespace android |
| 133 | |
| 134 | #endif // VTS_HAL_GRAPHICS_COMPOSER_UTILS |