• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2022, 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 #pragma once
17 
18 #include <aidl/android/hardware/graphics/common/BlendMode.h>
19 #include <aidl/android/hardware/graphics/common/BufferUsage.h>
20 #include <aidl/android/hardware/graphics/common/FRect.h>
21 #include <aidl/android/hardware/graphics/common/Rect.h>
22 #include <aidl/android/hardware/graphics/composer3/Composition.h>
23 #include <aidl/android/hardware/graphics/composer3/IComposer.h>
24 #include <android-base/properties.h>
25 #include <android/binder_manager.h>
26 #include <android/binder_process.h>
27 #include <android/hardware/graphics/composer3/ComposerClientReader.h>
28 #include <binder/ProcessState.h>
29 #include <gtest/gtest.h>
30 #include <ui/Fence.h>
31 #include <ui/GraphicBuffer.h>
32 #include <ui/PixelFormat.h>
33 #include <algorithm>
34 #include <numeric>
35 #include <string>
36 #include <thread>
37 #include <unordered_map>
38 #include <unordered_set>
39 #include "GraphicsComposerCallback.h"
40 
41 using aidl::android::hardware::graphics::common::Dataspace;
42 using aidl::android::hardware::graphics::common::DisplayDecorationSupport;
43 using aidl::android::hardware::graphics::common::FRect;
44 using aidl::android::hardware::graphics::common::PixelFormat;
45 using aidl::android::hardware::graphics::common::Rect;
46 using namespace ::ndk;
47 
48 namespace aidl::android::hardware::graphics::composer3::vts {
49 
50 class VtsDisplay;
51 /**
52  * A wrapper to IComposerClient.
53  * This wrapper manages the IComposerClient instance and manages the resources for
54  * the tests with respect to the IComposerClient calls.
55  */
56 class VtsComposerClient {
57   public:
58     VtsComposerClient(const std::string& name);
59 
60     ScopedAStatus createClient();
61 
62     bool tearDown();
63 
64     std::pair<ScopedAStatus, int32_t> getInterfaceVersion();
65 
66     std::pair<ScopedAStatus, VirtualDisplay> createVirtualDisplay(int32_t width, int32_t height,
67                                                                   PixelFormat pixelFormat,
68                                                                   int32_t bufferSlotCount);
69 
70     ScopedAStatus destroyVirtualDisplay(int64_t display);
71 
72     std::pair<ScopedAStatus, int64_t> createLayer(int64_t display, int32_t bufferSlotCount);
73 
74     ScopedAStatus destroyLayer(int64_t display, int64_t layer);
75 
76     std::pair<ScopedAStatus, int32_t> getActiveConfig(int64_t display);
77 
78     ScopedAStatus setActiveConfig(VtsDisplay* vtsDisplay, int32_t config);
79 
80     ScopedAStatus setPeakRefreshRateConfig(VtsDisplay* vtsDisplay);
81 
82     std::pair<ScopedAStatus, int32_t> getDisplayAttribute(int64_t display, int32_t config,
83                                                           DisplayAttribute displayAttribute);
84 
85     ScopedAStatus setPowerMode(int64_t display, PowerMode powerMode);
86 
87     ScopedAStatus setVsync(int64_t display, bool enable);
88 
89     void setVsyncAllowed(bool isAllowed);
90 
91     std::pair<ScopedAStatus, std::vector<float>> getDataspaceSaturationMatrix(Dataspace dataspace);
92 
93     std::pair<ScopedAStatus, std::vector<CommandResultPayload>> executeCommands(
94             const std::vector<DisplayCommand>& commands);
95 
96     std::optional<VsyncPeriodChangeTimeline> takeLastVsyncPeriodChangeTimeline();
97 
98     ScopedAStatus setContentType(int64_t display, ContentType contentType);
99 
100     std::pair<ScopedAStatus, VsyncPeriodChangeTimeline> setActiveConfigWithConstraints(
101             VtsDisplay* vtsDisplay, int32_t config,
102             const VsyncPeriodChangeConstraints& constraints);
103 
104     std::pair<ScopedAStatus, std::vector<DisplayCapability>> getDisplayCapabilities(
105             int64_t display);
106 
107     ScopedAStatus dumpDebugInfo();
108 
109     std::pair<ScopedAStatus, DisplayIdentification> getDisplayIdentificationData(int64_t display);
110 
111     std::pair<ScopedAStatus, HdrCapabilities> getHdrCapabilities(int64_t display);
112 
113     std::pair<ScopedAStatus, std::vector<PerFrameMetadataKey>> getPerFrameMetadataKeys(
114             int64_t display);
115 
116     std::pair<ScopedAStatus, ReadbackBufferAttributes> getReadbackBufferAttributes(int64_t display);
117 
118     ScopedAStatus setReadbackBuffer(int64_t display, const native_handle_t* buffer,
119                                     const ScopedFileDescriptor& releaseFence);
120 
121     std::pair<ScopedAStatus, ScopedFileDescriptor> getReadbackBufferFence(int64_t display);
122 
123     std::pair<ScopedAStatus, std::vector<ColorMode>> getColorModes(int64_t display);
124 
125     std::pair<ScopedAStatus, std::vector<RenderIntent>> getRenderIntents(int64_t display,
126                                                                          ColorMode colorMode);
127 
128     ScopedAStatus setColorMode(int64_t display, ColorMode colorMode, RenderIntent renderIntent);
129 
130     std::pair<ScopedAStatus, DisplayContentSamplingAttributes>
131     getDisplayedContentSamplingAttributes(int64_t display);
132 
133     ScopedAStatus setDisplayedContentSamplingEnabled(int64_t display, bool isEnabled,
134                                                      FormatColorComponent formatColorComponent,
135                                                      int64_t maxFrames);
136 
137     std::pair<ScopedAStatus, DisplayContentSample> getDisplayedContentSample(int64_t display,
138                                                                              int64_t maxFrames,
139                                                                              int64_t timestamp);
140 
141     std::pair<ScopedAStatus, DisplayConnectionType> getDisplayConnectionType(int64_t display);
142 
143     std::pair<ScopedAStatus, std::vector<int32_t>> getDisplayConfigs(int64_t display);
144 
145     std::pair<ScopedAStatus, int32_t> getDisplayVsyncPeriod(int64_t display);
146 
147     ScopedAStatus setAutoLowLatencyMode(int64_t display, bool isEnabled);
148 
149     std::pair<ScopedAStatus, std::vector<ContentType>> getSupportedContentTypes(int64_t display);
150 
151     std::pair<ScopedAStatus, std::optional<DisplayDecorationSupport>> getDisplayDecorationSupport(
152             int64_t display);
153 
154     std::pair<ScopedAStatus, int32_t> getMaxVirtualDisplayCount();
155 
156     std::pair<ScopedAStatus, std::string> getDisplayName(int64_t display);
157 
158     ScopedAStatus setClientTargetSlotCount(int64_t display, int32_t bufferSlotCount);
159 
160     std::pair<ScopedAStatus, std::vector<Capability>> getCapabilities();
161 
162     ScopedAStatus setBootDisplayConfig(int64_t display, int32_t config);
163 
164     ScopedAStatus clearBootDisplayConfig(int64_t display);
165 
166     std::pair<ScopedAStatus, int32_t> getPreferredBootDisplayConfig(int64_t display);
167 
168     std::pair<ScopedAStatus, std::vector<common::HdrConversionCapability>>
169     getHdrConversionCapabilities();
170 
171     std::pair<ScopedAStatus, common::Hdr> setHdrConversionStrategy(
172             const common::HdrConversionStrategy& conversionStrategy);
173 
174     std::pair<ScopedAStatus, common::Transform> getDisplayPhysicalOrientation(int64_t display);
175 
176     ScopedAStatus setIdleTimerEnabled(int64_t display, int32_t timeoutMs);
177 
178     int32_t getVsyncIdleCount();
179 
180     int64_t getVsyncIdleTime();
181 
182     int64_t getInvalidDisplayId();
183 
184     std::pair<ScopedAStatus, std::vector<VtsDisplay>> getDisplays();
185 
186     std::pair<ScopedAStatus, OverlayProperties> getOverlaySupport();
187 
188     ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled(int64_t display, bool enabled);
189 
190     std::vector<RefreshRateChangedDebugData> takeListOfRefreshRateChangedDebugData();
191 
192   private:
193     ScopedAStatus addDisplayConfig(VtsDisplay* vtsDisplay, int32_t config);
194     ScopedAStatus updateDisplayProperties(VtsDisplay* vtsDisplay, int32_t config);
195 
196     ScopedAStatus addDisplayToDisplayResources(int64_t display, bool isVirtual);
197 
198     ScopedAStatus addLayerToDisplayResources(int64_t display, int64_t layer);
199 
200     void removeLayerFromDisplayResources(int64_t display, int64_t layer);
201 
202     bool destroyAllLayers();
203 
204     bool verifyComposerCallbackParams();
205 
206     // Keep track of displays and layers. When a test fails/ends,
207     // the VtsComposerClient::tearDown should be called from the
208     // test tearDown to clean up the resources for the test.
209     struct DisplayResource {
DisplayResourceDisplayResource210         DisplayResource(bool isVirtual_) : isVirtual(isVirtual_) {}
211 
212         bool isVirtual;
213         std::unordered_set<int64_t> layers;
214     };
215 
216     std::shared_ptr<IComposer> mComposer;
217     std::shared_ptr<IComposerClient> mComposerClient;
218     std::shared_ptr<GraphicsComposerCallback> mComposerCallback;
219     std::unordered_map<int64_t, DisplayResource> mDisplayResources;
220 };
221 
222 class VtsDisplay {
223   public:
VtsDisplay(int64_t displayId)224     VtsDisplay(int64_t displayId) : mDisplayId(displayId), mDisplayWidth(0), mDisplayHeight(0) {}
225 
getDisplayId()226     int64_t getDisplayId() const { return mDisplayId; }
227 
getCrop()228     FRect getCrop() const {
229         return {0, 0, static_cast<float>(mDisplayWidth), static_cast<float>(mDisplayHeight)};
230     }
231 
getFrameRect()232     Rect getFrameRect() const { return {0, 0, mDisplayWidth, mDisplayHeight}; }
233 
setDimensions(int32_t displayWidth,int32_t displayHeight)234     void setDimensions(int32_t displayWidth, int32_t displayHeight) {
235         mDisplayWidth = displayWidth;
236         mDisplayHeight = displayHeight;
237     }
238 
getDisplayWidth()239     int32_t getDisplayWidth() const { return mDisplayWidth; }
240 
getDisplayHeight()241     int32_t getDisplayHeight() const { return mDisplayHeight; }
242 
243     struct DisplayConfig {
DisplayConfigDisplayConfig244         DisplayConfig(int32_t vsyncPeriod_, int32_t configGroup_)
245             : vsyncPeriod(vsyncPeriod_), configGroup(configGroup_) {}
246         int32_t vsyncPeriod;
247         int32_t configGroup;
248     };
249 
addDisplayConfig(int32_t config,DisplayConfig displayConfig)250     void addDisplayConfig(int32_t config, DisplayConfig displayConfig) {
251         mDisplayConfigs.insert({config, displayConfig});
252     }
253 
getDisplayConfig(int32_t config)254     DisplayConfig getDisplayConfig(int32_t config) { return mDisplayConfigs.find(config)->second; }
255 
getDisplayConfigs()256     std::unordered_map<int32_t, DisplayConfig> getDisplayConfigs() { return mDisplayConfigs; }
257 
258   private:
259     int64_t mDisplayId;
260     int32_t mDisplayWidth;
261     int32_t mDisplayHeight;
262     std::unordered_map<int32_t, DisplayConfig> mDisplayConfigs;
263 };
264 }  // namespace aidl::android::hardware::graphics::composer3::vts
265