• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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 
21 // TODO(b/129481165): remove the #pragma below and fix conversion issues
22 #pragma clang diagnostic push
23 #pragma clang diagnostic ignored "-Wconversion"
24 #pragma clang diagnostic ignored "-Wextra"
25 
26 #include <composer-command-buffer/2.4/ComposerCommandBuffer.h>
27 #include <gui/BufferQueue.h>
28 #include <gui/HdrMetadata.h>
29 #include <math/mat4.h>
30 #include <ui/DisplayedFrameStats.h>
31 #include <ui/GraphicBuffer.h>
32 #include <utils/StrongPointer.h>
33 
34 #include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h>
35 #include <aidl/android/hardware/graphics/common/HdrConversionCapability.h>
36 #include <aidl/android/hardware/graphics/common/HdrConversionStrategy.h>
37 #include <aidl/android/hardware/graphics/composer3/Capability.h>
38 #include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h>
39 #include <aidl/android/hardware/graphics/composer3/Color.h>
40 #include <aidl/android/hardware/graphics/composer3/Composition.h>
41 #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
42 #include <aidl/android/hardware/graphics/composer3/DisplayConfiguration.h>
43 #include <aidl/android/hardware/graphics/composer3/IComposerCallback.h>
44 #include <aidl/android/hardware/graphics/composer3/OverlayProperties.h>
45 
46 #include <aidl/android/hardware/graphics/common/Transform.h>
47 #include <optional>
48 
49 // TODO(b/129481165): remove the #pragma below and fix conversion issues
50 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
51 
52 namespace android {
53 namespace HWC2 {
54 struct ComposerCallback;
55 } // namespace HWC2
56 
57 namespace Hwc2 {
58 
59 namespace types = hardware::graphics::common;
60 
61 namespace V2_1 = hardware::graphics::composer::V2_1;
62 namespace V2_2 = hardware::graphics::composer::V2_2;
63 namespace V2_3 = hardware::graphics::composer::V2_3;
64 namespace V2_4 = hardware::graphics::composer::V2_4;
65 namespace V3_0 = ::aidl::android::hardware::graphics::composer3;
66 
67 using types::V1_0::ColorTransform;
68 using types::V1_0::Transform;
69 using types::V1_1::RenderIntent;
70 using types::V1_2::ColorMode;
71 using types::V1_2::Dataspace;
72 using types::V1_2::PixelFormat;
73 
74 using V2_1::Config;
75 using V2_1::Display;
76 using V2_1::Error;
77 using V2_1::Layer;
78 using V2_4::CommandReaderBase;
79 using V2_4::CommandWriterBase;
80 using V2_4::IComposer;
81 using V2_4::IComposerCallback;
82 using V2_4::IComposerClient;
83 using V2_4::VsyncPeriodChangeTimeline;
84 using V2_4::VsyncPeriodNanos;
85 using PerFrameMetadata = IComposerClient::PerFrameMetadata;
86 using PerFrameMetadataKey = IComposerClient::PerFrameMetadataKey;
87 using PerFrameMetadataBlob = IComposerClient::PerFrameMetadataBlob;
88 using AidlTransform = ::aidl::android::hardware::graphics::common::Transform;
89 using DisplayConfiguration = V3_0::DisplayConfiguration;
90 using aidl::android::hardware::graphics::common::Hdr;
91 
92 class Composer {
93 public:
94     static std::unique_ptr<Composer> create(const std::string& serviceName);
95 
96     virtual ~Composer() = 0;
97 
98     enum class OptionalFeature {
99         RefreshRateSwitching,
100         ExpectedPresentTime,
101         // Whether setDisplayBrightness is able to be applied as part of a display command.
102         DisplayBrightnessCommand,
103         KernelIdleTimer,
104         PhysicalDisplayOrientation,
105     };
106 
107     virtual bool isSupported(OptionalFeature) const = 0;
108     virtual bool isVrrSupported() const = 0;
109 
110     virtual std::vector<aidl::android::hardware::graphics::composer3::Capability>
111     getCapabilities() = 0;
112     virtual std::string dumpDebugInfo() = 0;
113 
114     virtual void registerCallback(HWC2::ComposerCallback& callback) = 0;
115 
116     // Explicitly flush all pending commands in the command buffer.
117     virtual Error executeCommands(Display) = 0;
118 
119     virtual uint32_t getMaxVirtualDisplayCount() = 0;
120     virtual Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat*,
121                                        Display* outDisplay) = 0;
122     virtual Error destroyVirtualDisplay(Display display) = 0;
123 
124     virtual Error acceptDisplayChanges(Display display) = 0;
125 
126     virtual Error createLayer(Display display, Layer* outLayer) = 0;
127     virtual Error destroyLayer(Display display, Layer layer) = 0;
128 
129     virtual Error getActiveConfig(Display display, Config* outConfig) = 0;
130     virtual Error getChangedCompositionTypes(Display display, std::vector<Layer>* outLayers,
131                                              std::vector<V3_0::Composition>* outTypes) = 0;
132     virtual Error getColorModes(Display display, std::vector<ColorMode>* outModes) = 0;
133     virtual Error getDisplayAttribute(Display display, Config config,
134                                       IComposerClient::Attribute attribute, int32_t* outValue) = 0;
135     virtual Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs) = 0;
136 
137     virtual Error getDisplayConfigurations(Display, int32_t maxFrameIntervalNs,
138                                            std::vector<DisplayConfiguration>*) = 0;
139 
140     virtual Error getDisplayName(Display display, std::string* outName) = 0;
141 
142     virtual Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
143                                      std::vector<Layer>* outLayers,
144                                      std::vector<uint32_t>* outLayerRequestMasks) = 0;
145 
146     virtual Error getDozeSupport(Display display, bool* outSupport) = 0;
147     virtual Error hasDisplayIdleTimerCapability(Display display, bool* outSupport) = 0;
148     virtual Error getHdrCapabilities(Display display, std::vector<Hdr>* outHdrTypes,
149                                      float* outMaxLuminance, float* outMaxAverageLuminance,
150                                      float* outMinLuminance) = 0;
151 
152     virtual Error getReleaseFences(Display display, std::vector<Layer>* outLayers,
153                                    std::vector<int>* outReleaseFences) = 0;
154 
155     virtual Error presentDisplay(Display display, int* outPresentFence) = 0;
156 
157     virtual Error setActiveConfig(Display display, Config config) = 0;
158 
159     /*
160      * The composer caches client targets internally.  When target is nullptr,
161      * the composer uses slot to look up the client target from its cache.
162      * When target is not nullptr, the cache is updated with the new target.
163      */
164     virtual Error setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
165                                   int acquireFence, Dataspace dataspace,
166                                   const std::vector<IComposerClient::Rect>& damage,
167                                   float hdrSdrRatio) = 0;
168     virtual Error setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) = 0;
169     virtual Error setColorTransform(Display display, const float* matrix) = 0;
170     virtual Error setOutputBuffer(Display display, const native_handle_t* buffer,
171                                   int releaseFence) = 0;
172     virtual Error setPowerMode(Display display, IComposerClient::PowerMode mode) = 0;
173     virtual Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) = 0;
174 
175     virtual Error setClientTargetSlotCount(Display display) = 0;
176 
177     virtual Error validateDisplay(Display display, nsecs_t expectedPresentTime,
178                                   int32_t frameIntervalNs, uint32_t* outNumTypes,
179                                   uint32_t* outNumRequests) = 0;
180 
181     virtual Error presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
182                                            int32_t frameIntervalNs, uint32_t* outNumTypes,
183                                            uint32_t* outNumRequests, int* outPresentFence,
184                                            uint32_t* state) = 0;
185 
186     virtual Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) = 0;
187     /* see setClientTarget for the purpose of slot */
188     virtual Error setLayerBuffer(Display display, Layer layer, uint32_t slot,
189                                  const sp<GraphicBuffer>& buffer, int acquireFence) = 0;
190     virtual Error setLayerBufferSlotsToClear(Display display, Layer layer,
191                                              const std::vector<uint32_t>& slotsToClear,
192                                              uint32_t activeBufferSlot) = 0;
193     virtual Error setLayerSurfaceDamage(Display display, Layer layer,
194                                         const std::vector<IComposerClient::Rect>& damage) = 0;
195     virtual Error setLayerBlendMode(Display display, Layer layer,
196                                     IComposerClient::BlendMode mode) = 0;
197     virtual Error setLayerColor(
198             Display display, Layer layer,
199             const aidl::android::hardware::graphics::composer3::Color& color) = 0;
200     virtual Error setLayerCompositionType(
201             Display display, Layer layer,
202             aidl::android::hardware::graphics::composer3::Composition type) = 0;
203     virtual Error setLayerDataspace(Display display, Layer layer, Dataspace dataspace) = 0;
204     virtual Error setLayerDisplayFrame(Display display, Layer layer,
205                                        const IComposerClient::Rect& frame) = 0;
206     virtual Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) = 0;
207     virtual Error setLayerSidebandStream(Display display, Layer layer,
208                                          const native_handle_t* stream) = 0;
209     virtual Error setLayerSourceCrop(Display display, Layer layer,
210                                      const IComposerClient::FRect& crop) = 0;
211     virtual Error setLayerTransform(Display display, Layer layer, Transform transform) = 0;
212     virtual Error setLayerVisibleRegion(Display display, Layer layer,
213                                         const std::vector<IComposerClient::Rect>& visible) = 0;
214     virtual Error setLayerZOrder(Display display, Layer layer, uint32_t z) = 0;
215 
216     // Composer HAL 2.2
217     virtual Error setLayerPerFrameMetadata(
218             Display display, Layer layer,
219             const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) = 0;
220     virtual std::vector<IComposerClient::PerFrameMetadataKey> getPerFrameMetadataKeys(
221             Display display) = 0;
222     virtual Error getRenderIntents(Display display, ColorMode colorMode,
223             std::vector<RenderIntent>* outRenderIntents) = 0;
224     virtual Error getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) = 0;
225 
226     // Composer HAL 2.3
227     virtual Error getDisplayIdentificationData(Display display, uint8_t* outPort,
228                                                std::vector<uint8_t>* outData) = 0;
229     virtual Error setLayerColorTransform(Display display, Layer layer,
230                                          const float* matrix) = 0;
231     virtual Error getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
232                                                         Dataspace* outDataspace,
233                                                         uint8_t* outComponentMask) = 0;
234     virtual Error setDisplayContentSamplingEnabled(Display display, bool enabled,
235                                                    uint8_t componentMask, uint64_t maxFrames) = 0;
236     virtual Error getDisplayedContentSample(Display display, uint64_t maxFrames, uint64_t timestamp,
237                                             DisplayedFrameStats* outStats) = 0;
238     virtual Error setLayerPerFrameMetadataBlobs(
239             Display display, Layer layer, const std::vector<PerFrameMetadataBlob>& metadata) = 0;
240     // Options for setting the display brightness
241     struct DisplayBrightnessOptions {
242         // If true, then immediately submits a brightness change request to composer. Otherwise,
243         // submission of the brightness change may be deferred until presenting the next frame.
244         // applyImmediately should only be false if OptionalFeature::DisplayBrightnessCommand is
245         // supported.
246         bool applyImmediately = true;
247 
248         bool operator==(const DisplayBrightnessOptions& other) const {
249             return applyImmediately == other.applyImmediately;
250         }
251     };
252     virtual Error setDisplayBrightness(Display display, float brightness, float brightnessNits,
253                                        const DisplayBrightnessOptions& options) = 0;
254 
255     // Composer HAL 2.4
256     virtual Error getDisplayCapabilities(Display display,
257                                          std::vector<V3_0::DisplayCapability>* outCapabilities) = 0;
258     virtual V2_4::Error getDisplayConnectionType(
259             Display display, IComposerClient::DisplayConnectionType* outType) = 0;
260     virtual V2_4::Error getDisplayVsyncPeriod(Display display,
261                                               VsyncPeriodNanos* outVsyncPeriod) = 0;
262     virtual V2_4::Error setActiveConfigWithConstraints(
263             Display display, Config config,
264             const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
265             VsyncPeriodChangeTimeline* outTimeline) = 0;
266 
267     virtual V2_4::Error setAutoLowLatencyMode(Display displayId, bool on) = 0;
268     virtual V2_4::Error getSupportedContentTypes(
269             Display displayId,
270             std::vector<IComposerClient::ContentType>* outSupportedContentTypes) = 0;
271     virtual V2_4::Error setContentType(Display displayId,
272                                        IComposerClient::ContentType contentType) = 0;
273     virtual V2_4::Error setLayerGenericMetadata(Display display, Layer layer,
274                                                 const std::string& key, bool mandatory,
275                                                 const std::vector<uint8_t>& value) = 0;
276     virtual V2_4::Error getLayerGenericMetadataKeys(
277             std::vector<IComposerClient::LayerGenericMetadataKey>* outKeys) = 0;
278 
279     virtual Error getClientTargetProperty(
280             Display display, V3_0::ClientTargetPropertyWithBrightness* outClientTargetProperty) = 0;
281 
282     // AIDL Composer
283     virtual Error setLayerBrightness(Display display, Layer layer, float brightness) = 0;
284     virtual Error setLayerBlockingRegion(Display display, Layer layer,
285                                          const std::vector<IComposerClient::Rect>& blocking) = 0;
286     virtual Error setBootDisplayConfig(Display displayId, Config) = 0;
287     virtual Error clearBootDisplayConfig(Display displayId) = 0;
288     virtual Error getPreferredBootDisplayConfig(Display displayId, Config*) = 0;
289     virtual Error getDisplayDecorationSupport(
290             Display display,
291             std::optional<::aidl::android::hardware::graphics::common::DisplayDecorationSupport>*
292                     support) = 0;
293     virtual Error setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) = 0;
294     virtual Error getPhysicalDisplayOrientation(Display displayId,
295                                                 AidlTransform* outDisplayOrientation) = 0;
296     virtual Error getOverlaySupport(V3_0::OverlayProperties* outProperties) = 0;
297     virtual void onHotplugConnect(Display) = 0;
298     virtual void onHotplugDisconnect(Display) = 0;
299     virtual Error getHdrConversionCapabilities(
300             std::vector<::aidl::android::hardware::graphics::common::HdrConversionCapability>*) = 0;
301     virtual Error setHdrConversionStrategy(
302             ::aidl::android::hardware::graphics::common::HdrConversionStrategy, Hdr*) = 0;
303     virtual Error setRefreshRateChangedCallbackDebugEnabled(Display, bool) = 0;
304     virtual Error notifyExpectedPresent(Display, nsecs_t expectedPresentTime,
305                                         int32_t frameIntervalNs) = 0;
306 };
307 
308 } // namespace Hwc2
309 } // namespace android
310