• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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  * Idealy IComposerHal should use aidl NativeHandle not native_handle_t/buffer_handle_t.
20  * However current patten is the HWC lib does not own buffer resources (HWC lib
21  * does own the fences).
22  */
23 #include <aidl/android/hardware/common/NativeHandle.h>
24 #include <aidl/android/hardware/graphics/common/BlendMode.h>
25 #include <aidl/android/hardware/graphics/common/ColorTransform.h>
26 #include <aidl/android/hardware/graphics/common/Dataspace.h>
27 #include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h>
28 #include <aidl/android/hardware/graphics/common/FRect.h>
29 #include <aidl/android/hardware/graphics/common/Hdr.h>
30 #include <aidl/android/hardware/graphics/common/HdrConversionCapability.h>
31 #include <aidl/android/hardware/graphics/common/HdrConversionStrategy.h>
32 #include <aidl/android/hardware/graphics/common/PixelFormat.h>
33 #include <aidl/android/hardware/graphics/common/Point.h>
34 #include <aidl/android/hardware/graphics/common/Rect.h>
35 #include <aidl/android/hardware/graphics/common/Transform.h>
36 #include <aidl/android/hardware/graphics/composer3/Buffer.h>
37 #include <aidl/android/hardware/graphics/composer3/Capability.h>
38 #include <aidl/android/hardware/graphics/composer3/ChangedCompositionTypes.h>
39 #include <aidl/android/hardware/graphics/composer3/ClientTarget.h>
40 #include <aidl/android/hardware/graphics/composer3/ClientTargetProperty.h>
41 #include <aidl/android/hardware/graphics/composer3/ClientTargetPropertyWithBrightness.h>
42 #include <aidl/android/hardware/graphics/composer3/Color.h>
43 #include <aidl/android/hardware/graphics/composer3/ColorMode.h>
44 #include <aidl/android/hardware/graphics/composer3/CommandError.h>
45 #include <aidl/android/hardware/graphics/composer3/CommandResultPayload.h>
46 #include <aidl/android/hardware/graphics/composer3/Composition.h>
47 #include <aidl/android/hardware/graphics/composer3/ContentType.h>
48 #include <aidl/android/hardware/graphics/composer3/DimmingStage.h>
49 #include <aidl/android/hardware/graphics/composer3/DisplayAttribute.h>
50 #include <aidl/android/hardware/graphics/composer3/DisplayBrightness.h>
51 #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
52 #include <aidl/android/hardware/graphics/composer3/DisplayCommand.h>
53 #include <aidl/android/hardware/graphics/composer3/DisplayConfiguration.h>
54 #include <aidl/android/hardware/graphics/composer3/DisplayConnectionType.h>
55 #include <aidl/android/hardware/graphics/composer3/DisplayContentSample.h>
56 #include <aidl/android/hardware/graphics/composer3/DisplayContentSamplingAttributes.h>
57 #include <aidl/android/hardware/graphics/composer3/DisplayIdentification.h>
58 #include <aidl/android/hardware/graphics/composer3/DisplayRequest.h>
59 #include <aidl/android/hardware/graphics/composer3/FormatColorComponent.h>
60 #include <aidl/android/hardware/graphics/composer3/HdrCapabilities.h>
61 #include <aidl/android/hardware/graphics/composer3/LayerBrightness.h>
62 #include <aidl/android/hardware/graphics/composer3/LayerCommand.h>
63 #include <aidl/android/hardware/graphics/composer3/LayerLifecycleBatchCommandType.h>
64 #include <aidl/android/hardware/graphics/composer3/OverlayProperties.h>
65 #include <aidl/android/hardware/graphics/composer3/ParcelableBlendMode.h>
66 #include <aidl/android/hardware/graphics/composer3/ParcelableComposition.h>
67 #include <aidl/android/hardware/graphics/composer3/ParcelableDataspace.h>
68 #include <aidl/android/hardware/graphics/composer3/ParcelableTransform.h>
69 #include <aidl/android/hardware/graphics/composer3/PerFrameMetadata.h>
70 #include <aidl/android/hardware/graphics/composer3/PerFrameMetadataBlob.h>
71 #include <aidl/android/hardware/graphics/composer3/PerFrameMetadataKey.h>
72 #include <aidl/android/hardware/graphics/composer3/PlaneAlpha.h>
73 #include <aidl/android/hardware/graphics/composer3/PowerMode.h>
74 #include <aidl/android/hardware/graphics/composer3/PresentFence.h>
75 #include <aidl/android/hardware/graphics/composer3/PresentOrValidate.h>
76 #include <aidl/android/hardware/graphics/composer3/ReadbackBufferAttributes.h>
77 #include <aidl/android/hardware/graphics/composer3/RefreshRateChangedDebugData.h>
78 #include <aidl/android/hardware/graphics/composer3/ReleaseFences.h>
79 #include <aidl/android/hardware/graphics/composer3/RenderIntent.h>
80 #include <aidl/android/hardware/graphics/composer3/VirtualDisplay.h>
81 #include <aidl/android/hardware/graphics/composer3/VsyncPeriodChangeConstraints.h>
82 #include <aidl/android/hardware/graphics/composer3/VsyncPeriodChangeTimeline.h>
83 #include <aidl/android/hardware/graphics/composer3/ZOrder.h>
84 #include <cutils/native_handle.h>
85 #include <hardware/hwcomposer2.h>
86 // avoid naming conflict
87 using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
88 using AidlNativeHandle = aidl::android::hardware::common::NativeHandle;
89 using DisplayConfiguration = aidl::android::hardware::graphics::composer3::DisplayConfiguration;
90 
91 namespace aidl::android::hardware::graphics::composer3::impl {
92 
93 // Abstraction of ComposerHal. Returned error code is compatible with AIDL
94 // IComposerClient interface.
95 class IComposerHal {
96  public:
97      static std::unique_ptr<IComposerHal> create(int32_t composerInterfaceVersion);
98      virtual ~IComposerHal() = default;
99 
100      virtual void getCapabilities(std::vector<Capability>* caps) = 0;
101      virtual void dumpDebugInfo(std::string* output) = 0;
102      virtual bool hasCapability(Capability cap) = 0;
103 
104      class EventCallback {
105      public:
106          virtual ~EventCallback() = default;
107          virtual void onHotplug(int64_t display, bool connected) = 0;
108          virtual void onRefresh(int64_t display) = 0;
109          virtual void onVsync(int64_t display, int64_t timestamp, int32_t vsyncPeriodNanos) = 0;
110          virtual void onVsyncPeriodTimingChanged(int64_t display,
111                                                  const VsyncPeriodChangeTimeline& timeline) = 0;
112          virtual void onVsyncIdle(int64_t display) = 0;
113          virtual void onSeamlessPossible(int64_t display) = 0;
114          virtual void onRefreshRateChangedDebug(const RefreshRateChangedDebugData& data) = 0;
115          virtual void onHotplugEvent(int64_t display, common::DisplayHotplugEvent event) = 0;
116      };
117     virtual void registerEventCallback(EventCallback* callback) = 0;
118     virtual void unregisterEventCallback() = 0;
119 
120     virtual int32_t acceptDisplayChanges(int64_t display) = 0;
121     virtual int32_t createLayer(int64_t display, int64_t* outLayer) = 0;
122     virtual int32_t batchedCreateDestroyLayer(int64_t display, int64_t layer,
123                                               LayerLifecycleBatchCommandType cmd) = 0;
124     virtual int32_t createVirtualDisplay(uint32_t width, uint32_t height, AidlPixelFormat format,
125                                          VirtualDisplay* outDisplay) = 0;
126     virtual int32_t destroyLayer(int64_t display, int64_t layer) = 0;
127     virtual int32_t destroyVirtualDisplay(int64_t display) = 0;
128     virtual int32_t flushDisplayBrightnessChange(int64_t display) = 0;
129     virtual int32_t getActiveConfig(int64_t display, int32_t* outConfig) = 0;
130     virtual int32_t getColorModes(int64_t display, std::vector<ColorMode>* outModes) = 0;
131     virtual int32_t getDataspaceSaturationMatrix(common::Dataspace dataspace,
132                                                  std::vector<float>* matrix) = 0;
133     virtual int32_t getDisplayAttribute(int64_t display, int32_t config,
134                                       DisplayAttribute attribute, int32_t* outValue) = 0;
135     virtual int32_t getDisplayBrightnessSupport(int64_t display, bool& outSupport) = 0;
136     virtual int32_t getDisplayIdleTimerSupport(int64_t display, bool& outSupport) = 0;
137     virtual int32_t getDisplayMultiThreadedPresentSupport(const int64_t& display,
138                                                           bool& outSupport) = 0;
139     virtual int32_t getDisplayCapabilities(int64_t display,
140                                            std::vector<DisplayCapability>* caps) = 0;
141     virtual int32_t getDisplayConfigs(int64_t display, std::vector<int32_t>* configs) = 0;
142     virtual int32_t getDisplayConfigurations(int64_t display, int32_t maxFrameIntervalNs,
143                                              std::vector<DisplayConfiguration>* configs) = 0;
144     virtual int32_t notifyExpectedPresent(int64_t display,
145                                           const ClockMonotonicTimestamp& expectedPresentTime,
146                                           int32_t frameIntervalNs) = 0;
147     virtual int32_t getDisplayConnectionType(int64_t display, DisplayConnectionType* outType) = 0;
148     virtual int32_t getDisplayIdentificationData(int64_t display, DisplayIdentification *id) = 0;
149     virtual int32_t getDisplayName(int64_t display, std::string* outName) = 0;
150     virtual int32_t getDisplayVsyncPeriod(int64_t display, int32_t* outVsyncPeriod) = 0;
151     virtual int32_t getDisplayedContentSample(int64_t display, int64_t maxFrames,
152                                             int64_t timestamp, DisplayContentSample* samples) = 0;
153     virtual int32_t getDisplayedContentSamplingAttributes(
154             int64_t display, DisplayContentSamplingAttributes* attrs) = 0;
155     virtual int32_t getDisplayPhysicalOrientation(int64_t display,
156                                                   common::Transform* orientation) = 0;
157     virtual int32_t getDozeSupport(int64_t display, bool& outSupport) = 0;
158     virtual int32_t getHdrCapabilities(int64_t display, HdrCapabilities* caps) = 0;
159     virtual int32_t getOverlaySupport(OverlayProperties* caps) = 0;
160     virtual int32_t getMaxVirtualDisplayCount(int32_t* count) = 0;
161     virtual int32_t getPerFrameMetadataKeys(int64_t display,
162                                             std::vector<PerFrameMetadataKey>* keys) = 0;
163     virtual int32_t getReadbackBufferAttributes(int64_t display,
164                                                 ReadbackBufferAttributes* attrs) = 0;
165     virtual int32_t getReadbackBufferFence(int64_t display,
166                                            ndk::ScopedFileDescriptor* aqcuireFence) = 0;
167     virtual int32_t getRenderIntents(int64_t display, ColorMode mode,
168                                      std::vector<RenderIntent>* intents) = 0;
169     virtual int32_t getSupportedContentTypes(int64_t display, std::vector<ContentType>* types) = 0;
170     virtual int32_t presentDisplay(int64_t display, ndk::ScopedFileDescriptor& fence,
171                                    std::vector<int64_t>* outLayers,
172                                    std::vector<ndk::ScopedFileDescriptor>* outReleaseFences) = 0;
173     virtual int32_t setActiveConfig(int64_t display, int32_t config) = 0;
174     virtual int32_t setActiveConfigWithConstraints(
175             int64_t display, int32_t config,
176             const VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
177             VsyncPeriodChangeTimeline* timeline) = 0;
178     virtual int32_t setBootDisplayConfig(int64_t display, int32_t config) = 0;
179     virtual int32_t clearBootDisplayConfig(int64_t display) = 0;
180     virtual int32_t getPreferredBootDisplayConfig(int64_t display, int32_t* config) = 0;
181     virtual int32_t getHdrConversionCapabilities(std::vector<common::HdrConversionCapability>*) = 0;
182     virtual int32_t setHdrConversionStrategy(const common::HdrConversionStrategy&,
183                                              common::Hdr*) = 0;
184     virtual int32_t setAutoLowLatencyMode(int64_t display, bool on) = 0;
185     virtual int32_t setClientTarget(int64_t display, buffer_handle_t target,
186                                     const ndk::ScopedFileDescriptor& fence,
187                                     common::Dataspace dataspace,
188                                     const std::vector<common::Rect>& damage) = 0; // cmd
189     virtual int32_t getHasClientComposition(int64_t display, bool& outHasClientComp) = 0;
190     virtual int32_t setColorMode(int64_t display, ColorMode mode, RenderIntent intent) = 0;
191     virtual int32_t setColorTransform(int64_t display, const std::vector<float>& matrix) = 0; // cmd
192     virtual int32_t setContentType(int64_t display, ContentType contentType) = 0;
193     virtual int32_t setDisplayBrightness(int64_t display, float brightness) = 0;
194     virtual int32_t setDisplayedContentSamplingEnabled(int64_t display, bool enable,
195                                                        FormatColorComponent componentMask,
196                                                        int64_t maxFrames) = 0;
197     virtual int32_t setLayerBlendMode(int64_t display, int64_t layer, common::BlendMode mode) = 0;
198     virtual int32_t setLayerBuffer(int64_t display, int64_t layer, buffer_handle_t buffer,
199                                    const ndk::ScopedFileDescriptor& acquireFence) = 0;
200     virtual int32_t uncacheLayerBuffers(int64_t display, int64_t layer,
201                                         const std::vector<buffer_handle_t>& buffers,
202                                         std::vector<buffer_handle_t>& outClearableBuffers) = 0;
203     virtual int32_t setLayerColor(int64_t display, int64_t layer, Color color) = 0;
204     virtual int32_t setLayerColorTransform(int64_t display, int64_t layer,
205                                            const std::vector<float>& matrix) = 0;
206     virtual int32_t setLayerCompositionType(int64_t display, int64_t layer, Composition type) = 0;
207     virtual int32_t setLayerCursorPosition(int64_t display, int64_t layer, int32_t x,
208                                            int32_t y) = 0;
209     virtual int32_t setLayerDataspace(int64_t display, int64_t layer,
210                                       common::Dataspace dataspace) = 0;
211     virtual int32_t setLayerDisplayFrame(int64_t display, int64_t layer,
212                                          const common::Rect& frame) = 0;
213     virtual int32_t setLayerPerFrameMetadata(int64_t display, int64_t layer,
214                             const std::vector<std::optional<PerFrameMetadata>>& metadata) = 0;
215     virtual int32_t setLayerPerFrameMetadataBlobs(int64_t display, int64_t layer,
216                             const std::vector<std::optional<PerFrameMetadataBlob>>& blobs) = 0;
217     virtual int32_t setLayerPlaneAlpha(int64_t display, int64_t layer, float alpha) = 0;
218     virtual int32_t setLayerSidebandStream(int64_t display, int64_t layer,
219                                            buffer_handle_t stream) = 0;
220     virtual int32_t setLayerSourceCrop(int64_t display, int64_t layer,
221                                        const common::FRect& crop) = 0;
222     virtual int32_t setLayerSurfaceDamage(int64_t display, int64_t layer,
223                         const std::vector<std::optional<common::Rect>>& damage) = 0;
224     virtual int32_t setLayerTransform(int64_t display, int64_t layer,
225                                       common::Transform transform) = 0;
226     virtual int32_t setLayerVisibleRegion(int64_t display, int64_t layer,
227                                  const std::vector<std::optional<common::Rect>>& visible) = 0;
228     virtual int32_t setLayerBrightness(int64_t display, int64_t layer, float brightness) = 0;
229     virtual int32_t setLayerZOrder(int64_t display, int64_t layer, uint32_t z) = 0;
230     virtual int32_t setOutputBuffer(int64_t display, buffer_handle_t buffer,
231                                     const ndk::ScopedFileDescriptor& releaseFence) = 0;
232     virtual int32_t setPowerMode(int64_t display, PowerMode mode) = 0;
233     virtual int32_t getPowerMode(int64_t display, std::optional<PowerMode>& outMode) = 0;
234     virtual int32_t setReadbackBuffer(int64_t display, buffer_handle_t buffer,
235                                       const ndk::ScopedFileDescriptor& releaseFence) = 0;
236     virtual int32_t setVsyncEnabled(int64_t display, bool enabled) = 0;
237     virtual int32_t validateDisplay(int64_t display, std::vector<int64_t>* outChangedLayers,
238                                     std::vector<Composition>* outCompositionTypes,
239                                     uint32_t* outDisplayRequestMask,
240                                     std::vector<int64_t>* outRequestedLayers,
241                                     std::vector<int32_t>* outRequestMasks,
242                                     ClientTargetProperty* outClientTargetProperty,
243                                     DimmingStage* outDimmingStage) = 0;
244     virtual int32_t setExpectedPresentTime(
245             int64_t display, const std::optional<ClockMonotonicTimestamp> expectedPresentTime,
246             int frameIntervalNs) = 0;
247     virtual int32_t setIdleTimerEnabled(int64_t display, int32_t timeout) = 0;
248     virtual int32_t getRCDLayerSupport(int64_t display, bool& outSupport) = 0;
249     virtual int32_t setLayerBlockingRegion(
250             int64_t display, int64_t layer,
251             const std::vector<std::optional<common::Rect>>& blockingRegion) = 0;
252     virtual int32_t setRefreshRateChangedCallbackDebugEnabled(int64_t display, bool enabled) = 0;
253     virtual int32_t layerSf2Hwc(int64_t display, int64_t layer, hwc2_layer_t& outMappedLayer) = 0;
254 };
255 
256 } // namespace aidl::android::hardware::graphics::composer3::detail
257