• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <mapper-vts/2.0/MapperVts.h>
29 #include <mapper-vts/3.0/MapperVts.h>
30 #include <mapper-vts/4.0/MapperVts.h>
31 #include <utils/StrongPointer.h>
32 
33 #include "gtest/gtest.h"
34 
35 namespace android {
36 namespace hardware {
37 namespace graphics {
38 namespace composer {
39 namespace V2_1 {
40 namespace vts {
41 
42 using android::hardware::graphics::common::V1_0::ColorMode;
43 using android::hardware::graphics::common::V1_0::Dataspace;
44 using android::hardware::graphics::common::V1_0::Hdr;
45 using android::hardware::graphics::common::V1_0::PixelFormat;
46 using IMapper2 = android::hardware::graphics::mapper::V2_0::IMapper;
47 using IMapper3 = android::hardware::graphics::mapper::V3_0::IMapper;
48 using IMapper4 = android::hardware::graphics::mapper::V4_0::IMapper;
49 using Gralloc2 = android::hardware::graphics::mapper::V2_0::vts::Gralloc;
50 using Gralloc3 = android::hardware::graphics::mapper::V3_0::vts::Gralloc;
51 using Gralloc4 = android::hardware::graphics::mapper::V4_0::vts::Gralloc;
52 using IAllocator = aidl::android::hardware::graphics::allocator::IAllocator;
53 
54 class ComposerClient;
55 
56 // A wrapper to IComposer.
57 class Composer {
58    public:
59     Composer();
60     explicit Composer(const std::string& name);
61     explicit Composer(const sp<IComposer>& composer);
62 
63     sp<IComposer> getRaw() const;
64 
65     // Returns true when the composer supports the specified capability.
66     bool hasCapability(IComposer::Capability capability) const;
67 
68     std::vector<IComposer::Capability> getCapabilities();
69     std::string dumpDebugInfo();
70     std::unique_ptr<ComposerClient> createClient();
71 
72    private:
73     const sp<IComposer> mComposer;
74 
75     std::unordered_set<IComposer::Capability> mCapabilities;
76 };
77 
78 // A wrapper to IComposerClient.
79 class ComposerClient {
80    public:
81     explicit ComposerClient(const sp<IComposerClient>& client);
82     ~ComposerClient();
83 
84     sp<IComposerClient> getRaw() const;
85 
86     void registerCallback(const sp<IComposerCallback>& callback);
87     uint32_t getMaxVirtualDisplayCount();
88 
89     Display createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat formatHint,
90                                  uint32_t outputBufferSlotCount, PixelFormat* outFormat);
91     void destroyVirtualDisplay(Display display);
92 
93     Layer createLayer(Display display, uint32_t bufferSlotCount);
94     void destroyLayer(Display display, Layer layer);
95 
96     Config getActiveConfig(Display display);
97     bool getClientTargetSupport(Display display, uint32_t width, uint32_t height,
98                                 PixelFormat format, Dataspace dataspace);
99     std::vector<ColorMode> getColorModes(Display display);
100     int32_t getDisplayAttribute(Display display, Config config,
101                                 IComposerClient::Attribute attribute);
102     std::vector<Config> getDisplayConfigs(Display display);
103     std::string getDisplayName(Display display);
104     IComposerClient::DisplayType getDisplayType(Display display);
105     bool getDozeSupport(Display display);
106     std::vector<Hdr> getHdrCapabilities(Display display, float* outMaxLuminance,
107                                         float* outMaxAverageLuminance, float* outMinLuminance);
108 
109     void setClientTargetSlotCount(Display display, uint32_t clientTargetSlotCount);
110     void setActiveConfig(Display display, Config config);
111     void setColorMode(Display display, ColorMode mode);
112     void setPowerMode(Display display, IComposerClient::PowerMode mode);
113     void setVsyncEnabled(Display display, bool enabled);
114 
115     void execute(TestCommandReader* reader, CommandWriterBase* writer);
116 
117    protected:
118     // Keep track of all virtual displays and layers.  When a test fails with
119     // ASSERT_*, the destructor will clean up the resources for the test.
120     struct DisplayResource {
DisplayResourceDisplayResource121         DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {}
122 
123         bool isVirtual;
124         std::unordered_set<Layer> layers;
125     };
126     std::unordered_map<Display, DisplayResource> mDisplayResources;
127 
128    private:
129     const sp<IComposerClient> mClient;
130 };
131 
132 class AccessRegion {
133   public:
134     int32_t left;
135     int32_t top;
136     int32_t width;
137     int32_t height;
138 };
139 
140 class Gralloc;
141 
142 // RAII wrapper around native_handle_t*
143 class NativeHandleWrapper {
144   public:
NativeHandleWrapper(Gralloc & gralloc,const native_handle_t * handle)145     NativeHandleWrapper(Gralloc& gralloc, const native_handle_t* handle)
146         : mGralloc(gralloc), mHandle(handle) {}
147 
148     ~NativeHandleWrapper();
149 
get()150     const native_handle_t* get() { return mHandle; }
151 
152   private:
153     Gralloc& mGralloc;
154     const native_handle_t* mHandle;
155 };
156 
157 class Gralloc {
158   public:
159     explicit Gralloc();
160 
161     const NativeHandleWrapper allocate(uint32_t width, uint32_t height, uint32_t layerCount,
162                                        PixelFormat format, uint64_t usage, bool import = true,
163                                        uint32_t* outStride = nullptr);
164 
165     void* lock(const native_handle_t* bufferHandle, uint64_t cpuUsage,
166                const AccessRegion& accessRegionRect, int acquireFence);
167 
168     int unlock(const native_handle_t* bufferHandle);
169 
170     void freeBuffer(const native_handle_t* bufferHandle);
171 
172   protected:
173     std::shared_ptr<Gralloc2> mGralloc2 = nullptr;
174     std::shared_ptr<Gralloc3> mGralloc3 = nullptr;
175     std::shared_ptr<Gralloc4> mGralloc4 = nullptr;
176 };
177 
178 }  // namespace vts
179 }  // namespace V2_1
180 }  // namespace composer
181 }  // namespace graphics
182 }  // namespace hardware
183 }  // namespace android
184