xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/DisplayHardware/AidlComposerHal.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2021 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include "ComposerHal.h"
20*38e8c45fSAndroid Build Coastguard Worker 
21*38e8c45fSAndroid Build Coastguard Worker #include <ftl/shared_mutex.h>
22*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayMap.h>
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker #include <functional>
25*38e8c45fSAndroid Build Coastguard Worker #include <optional>
26*38e8c45fSAndroid Build Coastguard Worker #include <string>
27*38e8c45fSAndroid Build Coastguard Worker #include <utility>
28*38e8c45fSAndroid Build Coastguard Worker #include <vector>
29*38e8c45fSAndroid Build Coastguard Worker 
30*38e8c45fSAndroid Build Coastguard Worker #include <android/hardware/graphics/composer/2.4/IComposer.h>
31*38e8c45fSAndroid Build Coastguard Worker #include <android/hardware/graphics/composer/2.4/IComposerClient.h>
32*38e8c45fSAndroid Build Coastguard Worker 
33*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/IComposer.h>
34*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/IComposerClient.h>
35*38e8c45fSAndroid Build Coastguard Worker #include <android/hardware/graphics/composer3/ComposerClientReader.h>
36*38e8c45fSAndroid Build Coastguard Worker #include <android/hardware/graphics/composer3/ComposerClientWriter.h>
37*38e8c45fSAndroid Build Coastguard Worker 
38*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/Composition.h>
39*38e8c45fSAndroid Build Coastguard Worker #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
40*38e8c45fSAndroid Build Coastguard Worker 
41*38e8c45fSAndroid Build Coastguard Worker namespace android::Hwc2 {
42*38e8c45fSAndroid Build Coastguard Worker 
43*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::common::DisplayDecorationSupport;
44*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::common::HdrConversionCapability;
45*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::common::HdrConversionStrategy;
46*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::ComposerClientReader;
47*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::ComposerClientWriter;
48*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::Luts;
49*38e8c45fSAndroid Build Coastguard Worker using aidl::android::hardware::graphics::composer3::OverlayProperties;
50*38e8c45fSAndroid Build Coastguard Worker 
51*38e8c45fSAndroid Build Coastguard Worker class AidlIComposerCallbackWrapper;
52*38e8c45fSAndroid Build Coastguard Worker 
53*38e8c45fSAndroid Build Coastguard Worker // Composer is a wrapper to IComposer, a proxy to server-side composer.
54*38e8c45fSAndroid Build Coastguard Worker class AidlComposer final : public Hwc2::Composer {
55*38e8c45fSAndroid Build Coastguard Worker public:
56*38e8c45fSAndroid Build Coastguard Worker     static bool isDeclared(const std::string& serviceName);
57*38e8c45fSAndroid Build Coastguard Worker 
58*38e8c45fSAndroid Build Coastguard Worker     explicit AidlComposer(const std::string& serviceName);
59*38e8c45fSAndroid Build Coastguard Worker     ~AidlComposer() override;
60*38e8c45fSAndroid Build Coastguard Worker 
61*38e8c45fSAndroid Build Coastguard Worker     bool isSupported(OptionalFeature) const;
62*38e8c45fSAndroid Build Coastguard Worker     bool isVrrSupported() const;
63*38e8c45fSAndroid Build Coastguard Worker 
64*38e8c45fSAndroid Build Coastguard Worker     std::vector<aidl::android::hardware::graphics::composer3::Capability> getCapabilities()
65*38e8c45fSAndroid Build Coastguard Worker             override;
66*38e8c45fSAndroid Build Coastguard Worker     std::string dumpDebugInfo() override;
67*38e8c45fSAndroid Build Coastguard Worker 
68*38e8c45fSAndroid Build Coastguard Worker     void registerCallback(HWC2::ComposerCallback& callback) override;
69*38e8c45fSAndroid Build Coastguard Worker 
70*38e8c45fSAndroid Build Coastguard Worker     // Explicitly flush all pending commands in the command buffer.
71*38e8c45fSAndroid Build Coastguard Worker     Error executeCommands(Display) override;
72*38e8c45fSAndroid Build Coastguard Worker 
73*38e8c45fSAndroid Build Coastguard Worker     uint32_t getMaxVirtualDisplayCount() override;
74*38e8c45fSAndroid Build Coastguard Worker     Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
75*38e8c45fSAndroid Build Coastguard Worker                                Display* outDisplay) override;
76*38e8c45fSAndroid Build Coastguard Worker     Error destroyVirtualDisplay(Display display) override;
77*38e8c45fSAndroid Build Coastguard Worker 
78*38e8c45fSAndroid Build Coastguard Worker     Error acceptDisplayChanges(Display display) override;
79*38e8c45fSAndroid Build Coastguard Worker 
80*38e8c45fSAndroid Build Coastguard Worker     Error createLayer(Display display, Layer* outLayer) override;
81*38e8c45fSAndroid Build Coastguard Worker     Error destroyLayer(Display display, Layer layer) override;
82*38e8c45fSAndroid Build Coastguard Worker 
83*38e8c45fSAndroid Build Coastguard Worker     Error getActiveConfig(Display display, Config* outConfig) override;
84*38e8c45fSAndroid Build Coastguard Worker     Error getChangedCompositionTypes(
85*38e8c45fSAndroid Build Coastguard Worker             Display display, std::vector<Layer>* outLayers,
86*38e8c45fSAndroid Build Coastguard Worker             std::vector<aidl::android::hardware::graphics::composer3::Composition>* outTypes)
87*38e8c45fSAndroid Build Coastguard Worker             override;
88*38e8c45fSAndroid Build Coastguard Worker     Error getColorModes(Display display, std::vector<ColorMode>* outModes) override;
89*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayAttribute(Display display, Config config, IComposerClient::Attribute attribute,
90*38e8c45fSAndroid Build Coastguard Worker                               int32_t* outValue) override;
91*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs);
92*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayConfigurations(Display, int32_t maxFrameIntervalNs,
93*38e8c45fSAndroid Build Coastguard Worker                                    std::vector<DisplayConfiguration>*);
94*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayName(Display display, std::string* outName) override;
95*38e8c45fSAndroid Build Coastguard Worker 
96*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
97*38e8c45fSAndroid Build Coastguard Worker                              std::vector<Layer>* outLayers,
98*38e8c45fSAndroid Build Coastguard Worker                              std::vector<uint32_t>* outLayerRequestMasks) override;
99*38e8c45fSAndroid Build Coastguard Worker 
100*38e8c45fSAndroid Build Coastguard Worker     Error getDozeSupport(Display display, bool* outSupport) override;
101*38e8c45fSAndroid Build Coastguard Worker     Error hasDisplayIdleTimerCapability(Display display, bool* outSupport) override;
102*38e8c45fSAndroid Build Coastguard Worker     Error getHdrCapabilities(Display display, std::vector<Hdr>* outHdrTypes, float* outMaxLuminance,
103*38e8c45fSAndroid Build Coastguard Worker                              float* outMaxAverageLuminance, float* outMinLuminance) override;
104*38e8c45fSAndroid Build Coastguard Worker     Error getOverlaySupport(OverlayProperties* outProperties) override;
105*38e8c45fSAndroid Build Coastguard Worker 
106*38e8c45fSAndroid Build Coastguard Worker     Error getReleaseFences(Display display, std::vector<Layer>* outLayers,
107*38e8c45fSAndroid Build Coastguard Worker                            std::vector<int>* outReleaseFences) override;
108*38e8c45fSAndroid Build Coastguard Worker 
109*38e8c45fSAndroid Build Coastguard Worker     Error presentDisplay(Display display, int* outPresentFence) override;
110*38e8c45fSAndroid Build Coastguard Worker 
111*38e8c45fSAndroid Build Coastguard Worker     Error setActiveConfig(Display display, Config config) override;
112*38e8c45fSAndroid Build Coastguard Worker 
113*38e8c45fSAndroid Build Coastguard Worker     /*
114*38e8c45fSAndroid Build Coastguard Worker      * The composer caches client targets internally.  When target is nullptr,
115*38e8c45fSAndroid Build Coastguard Worker      * the composer uses slot to look up the client target from its cache.
116*38e8c45fSAndroid Build Coastguard Worker      * When target is not nullptr, the cache is updated with the new target.
117*38e8c45fSAndroid Build Coastguard Worker      */
118*38e8c45fSAndroid Build Coastguard Worker     Error setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
119*38e8c45fSAndroid Build Coastguard Worker                           int acquireFence, Dataspace dataspace,
120*38e8c45fSAndroid Build Coastguard Worker                           const std::vector<IComposerClient::Rect>& damage,
121*38e8c45fSAndroid Build Coastguard Worker                           float hdrSdrRatio) override;
122*38e8c45fSAndroid Build Coastguard Worker     Error setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) override;
123*38e8c45fSAndroid Build Coastguard Worker     Error setColorTransform(Display display, const float* matrix) override;
124*38e8c45fSAndroid Build Coastguard Worker     Error setOutputBuffer(Display display, const native_handle_t* buffer,
125*38e8c45fSAndroid Build Coastguard Worker                           int releaseFence) override;
126*38e8c45fSAndroid Build Coastguard Worker     Error setPowerMode(Display display, IComposerClient::PowerMode mode) override;
127*38e8c45fSAndroid Build Coastguard Worker     Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) override;
128*38e8c45fSAndroid Build Coastguard Worker 
129*38e8c45fSAndroid Build Coastguard Worker     Error setClientTargetSlotCount(Display display) override;
130*38e8c45fSAndroid Build Coastguard Worker 
131*38e8c45fSAndroid Build Coastguard Worker     Error validateDisplay(Display display, nsecs_t expectedPresentTime, int32_t frameIntervalNs,
132*38e8c45fSAndroid Build Coastguard Worker                           uint32_t* outNumTypes, uint32_t* outNumRequests) override;
133*38e8c45fSAndroid Build Coastguard Worker 
134*38e8c45fSAndroid Build Coastguard Worker     Error presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
135*38e8c45fSAndroid Build Coastguard Worker                                    int32_t frameIntervalNs, uint32_t* outNumTypes,
136*38e8c45fSAndroid Build Coastguard Worker                                    uint32_t* outNumRequests, int* outPresentFence,
137*38e8c45fSAndroid Build Coastguard Worker                                    uint32_t* state) override;
138*38e8c45fSAndroid Build Coastguard Worker 
139*38e8c45fSAndroid Build Coastguard Worker     Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) override;
140*38e8c45fSAndroid Build Coastguard Worker     /* see setClientTarget for the purpose of slot */
141*38e8c45fSAndroid Build Coastguard Worker     Error setLayerBuffer(Display display, Layer layer, uint32_t slot,
142*38e8c45fSAndroid Build Coastguard Worker                          const sp<GraphicBuffer>& buffer, int acquireFence) override;
143*38e8c45fSAndroid Build Coastguard Worker     Error setLayerBufferSlotsToClear(Display display, Layer layer,
144*38e8c45fSAndroid Build Coastguard Worker                                      const std::vector<uint32_t>& slotsToClear,
145*38e8c45fSAndroid Build Coastguard Worker                                      uint32_t activeBufferSlot) override;
146*38e8c45fSAndroid Build Coastguard Worker     Error setLayerSurfaceDamage(Display display, Layer layer,
147*38e8c45fSAndroid Build Coastguard Worker                                 const std::vector<IComposerClient::Rect>& damage) override;
148*38e8c45fSAndroid Build Coastguard Worker     Error setLayerBlendMode(Display display, Layer layer, IComposerClient::BlendMode mode) override;
149*38e8c45fSAndroid Build Coastguard Worker     Error setLayerColor(Display display, Layer layer, const Color& color) override;
150*38e8c45fSAndroid Build Coastguard Worker     Error setLayerCompositionType(
151*38e8c45fSAndroid Build Coastguard Worker             Display display, Layer layer,
152*38e8c45fSAndroid Build Coastguard Worker             aidl::android::hardware::graphics::composer3::Composition type) override;
153*38e8c45fSAndroid Build Coastguard Worker     Error setLayerDataspace(Display display, Layer layer, Dataspace dataspace) override;
154*38e8c45fSAndroid Build Coastguard Worker     Error setLayerDisplayFrame(Display display, Layer layer,
155*38e8c45fSAndroid Build Coastguard Worker                                const IComposerClient::Rect& frame) override;
156*38e8c45fSAndroid Build Coastguard Worker     Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) override;
157*38e8c45fSAndroid Build Coastguard Worker     Error setLayerSidebandStream(Display display, Layer layer,
158*38e8c45fSAndroid Build Coastguard Worker                                  const native_handle_t* stream) override;
159*38e8c45fSAndroid Build Coastguard Worker     Error setLayerSourceCrop(Display display, Layer layer,
160*38e8c45fSAndroid Build Coastguard Worker                              const IComposerClient::FRect& crop) override;
161*38e8c45fSAndroid Build Coastguard Worker     Error setLayerTransform(Display display, Layer layer, Transform transform) override;
162*38e8c45fSAndroid Build Coastguard Worker     Error setLayerVisibleRegion(Display display, Layer layer,
163*38e8c45fSAndroid Build Coastguard Worker                                 const std::vector<IComposerClient::Rect>& visible) override;
164*38e8c45fSAndroid Build Coastguard Worker     Error setLayerZOrder(Display display, Layer layer, uint32_t z) override;
165*38e8c45fSAndroid Build Coastguard Worker 
166*38e8c45fSAndroid Build Coastguard Worker     // Composer HAL 2.2
167*38e8c45fSAndroid Build Coastguard Worker     Error setLayerPerFrameMetadata(
168*38e8c45fSAndroid Build Coastguard Worker             Display display, Layer layer,
169*38e8c45fSAndroid Build Coastguard Worker             const std::vector<IComposerClient::PerFrameMetadata>& perFrameMetadatas) override;
170*38e8c45fSAndroid Build Coastguard Worker     std::vector<IComposerClient::PerFrameMetadataKey> getPerFrameMetadataKeys(
171*38e8c45fSAndroid Build Coastguard Worker             Display display) override;
172*38e8c45fSAndroid Build Coastguard Worker     Error getRenderIntents(Display display, ColorMode colorMode,
173*38e8c45fSAndroid Build Coastguard Worker                            std::vector<RenderIntent>* outRenderIntents) override;
174*38e8c45fSAndroid Build Coastguard Worker     Error getDataspaceSaturationMatrix(Dataspace dataspace, mat4* outMatrix) override;
175*38e8c45fSAndroid Build Coastguard Worker 
176*38e8c45fSAndroid Build Coastguard Worker     // Composer HAL 2.3
177*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayIdentificationData(Display display, uint8_t* outPort,
178*38e8c45fSAndroid Build Coastguard Worker                                        std::vector<uint8_t>* outData) override;
179*38e8c45fSAndroid Build Coastguard Worker     Error setLayerColorTransform(Display display, Layer layer, const float* matrix) override;
180*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayedContentSamplingAttributes(Display display, PixelFormat* outFormat,
181*38e8c45fSAndroid Build Coastguard Worker                                                 Dataspace* outDataspace,
182*38e8c45fSAndroid Build Coastguard Worker                                                 uint8_t* outComponentMask) override;
183*38e8c45fSAndroid Build Coastguard Worker     Error setDisplayContentSamplingEnabled(Display display, bool enabled, uint8_t componentMask,
184*38e8c45fSAndroid Build Coastguard Worker                                            uint64_t maxFrames) override;
185*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayedContentSample(Display display, uint64_t maxFrames, uint64_t timestamp,
186*38e8c45fSAndroid Build Coastguard Worker                                     DisplayedFrameStats* outStats) override;
187*38e8c45fSAndroid Build Coastguard Worker     Error setLayerPerFrameMetadataBlobs(
188*38e8c45fSAndroid Build Coastguard Worker             Display display, Layer layer,
189*38e8c45fSAndroid Build Coastguard Worker             const std::vector<IComposerClient::PerFrameMetadataBlob>& metadata) override;
190*38e8c45fSAndroid Build Coastguard Worker     Error setDisplayBrightness(Display display, float brightness, float brightnessNits,
191*38e8c45fSAndroid Build Coastguard Worker                                const DisplayBrightnessOptions& options) override;
192*38e8c45fSAndroid Build Coastguard Worker 
193*38e8c45fSAndroid Build Coastguard Worker     // Composer HAL 2.4
194*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayCapabilities(
195*38e8c45fSAndroid Build Coastguard Worker             Display display,
196*38e8c45fSAndroid Build Coastguard Worker             std::vector<aidl::android::hardware::graphics::composer3::DisplayCapability>*
197*38e8c45fSAndroid Build Coastguard Worker                     outCapabilities) override;
198*38e8c45fSAndroid Build Coastguard Worker     V2_4::Error getDisplayConnectionType(Display display,
199*38e8c45fSAndroid Build Coastguard Worker                                          IComposerClient::DisplayConnectionType* outType) override;
200*38e8c45fSAndroid Build Coastguard Worker     V2_4::Error getDisplayVsyncPeriod(Display display, VsyncPeriodNanos* outVsyncPeriod) override;
201*38e8c45fSAndroid Build Coastguard Worker     Error setActiveConfigWithConstraints(
202*38e8c45fSAndroid Build Coastguard Worker             Display display, Config config,
203*38e8c45fSAndroid Build Coastguard Worker             const IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
204*38e8c45fSAndroid Build Coastguard Worker             VsyncPeriodChangeTimeline* outTimeline) override;
205*38e8c45fSAndroid Build Coastguard Worker     V2_4::Error setAutoLowLatencyMode(Display displayId, bool on) override;
206*38e8c45fSAndroid Build Coastguard Worker     V2_4::Error getSupportedContentTypes(
207*38e8c45fSAndroid Build Coastguard Worker             Display displayId,
208*38e8c45fSAndroid Build Coastguard Worker             std::vector<IComposerClient::ContentType>* outSupportedContentTypes) override;
209*38e8c45fSAndroid Build Coastguard Worker     V2_4::Error setContentType(Display displayId,
210*38e8c45fSAndroid Build Coastguard Worker                                IComposerClient::ContentType contentType) override;
211*38e8c45fSAndroid Build Coastguard Worker     V2_4::Error setLayerGenericMetadata(Display display, Layer layer, const std::string& key,
212*38e8c45fSAndroid Build Coastguard Worker                                         bool mandatory, const std::vector<uint8_t>& value) override;
213*38e8c45fSAndroid Build Coastguard Worker     V2_4::Error getLayerGenericMetadataKeys(
214*38e8c45fSAndroid Build Coastguard Worker             std::vector<IComposerClient::LayerGenericMetadataKey>* outKeys) override;
215*38e8c45fSAndroid Build Coastguard Worker     Error getClientTargetProperty(
216*38e8c45fSAndroid Build Coastguard Worker             Display display,
217*38e8c45fSAndroid Build Coastguard Worker             aidl::android::hardware::graphics::composer3::ClientTargetPropertyWithBrightness*
218*38e8c45fSAndroid Build Coastguard Worker                     outClientTargetProperty) override;
219*38e8c45fSAndroid Build Coastguard Worker 
220*38e8c45fSAndroid Build Coastguard Worker     // AIDL Composer HAL
221*38e8c45fSAndroid Build Coastguard Worker     Error setLayerBrightness(Display display, Layer layer, float brightness) override;
222*38e8c45fSAndroid Build Coastguard Worker     Error setLayerBlockingRegion(Display display, Layer layer,
223*38e8c45fSAndroid Build Coastguard Worker                                  const std::vector<IComposerClient::Rect>& blocking) override;
224*38e8c45fSAndroid Build Coastguard Worker     Error setBootDisplayConfig(Display displayId, Config) override;
225*38e8c45fSAndroid Build Coastguard Worker     Error clearBootDisplayConfig(Display displayId) override;
226*38e8c45fSAndroid Build Coastguard Worker     Error getPreferredBootDisplayConfig(Display displayId, Config*) override;
227*38e8c45fSAndroid Build Coastguard Worker     Error getDisplayDecorationSupport(Display display,
228*38e8c45fSAndroid Build Coastguard Worker                                       std::optional<DisplayDecorationSupport>* support) override;
229*38e8c45fSAndroid Build Coastguard Worker     Error setIdleTimerEnabled(Display displayId, std::chrono::milliseconds timeout) override;
230*38e8c45fSAndroid Build Coastguard Worker 
231*38e8c45fSAndroid Build Coastguard Worker     Error getPhysicalDisplayOrientation(Display displayId,
232*38e8c45fSAndroid Build Coastguard Worker                                         AidlTransform* outDisplayOrientation) override;
233*38e8c45fSAndroid Build Coastguard Worker     void onHotplugConnect(Display) override;
234*38e8c45fSAndroid Build Coastguard Worker     void onHotplugDisconnect(Display) override;
235*38e8c45fSAndroid Build Coastguard Worker     Error getHdrConversionCapabilities(std::vector<HdrConversionCapability>*) override;
236*38e8c45fSAndroid Build Coastguard Worker     Error setHdrConversionStrategy(HdrConversionStrategy, Hdr*) override;
237*38e8c45fSAndroid Build Coastguard Worker     Error setRefreshRateChangedCallbackDebugEnabled(Display, bool) override;
238*38e8c45fSAndroid Build Coastguard Worker     Error notifyExpectedPresent(Display, nsecs_t expectedPresentTime,
239*38e8c45fSAndroid Build Coastguard Worker                                 int32_t frameIntervalNs) override;
240*38e8c45fSAndroid Build Coastguard Worker     Error getRequestedLuts(
241*38e8c45fSAndroid Build Coastguard Worker             Display display, std::vector<Layer>* outLayers,
242*38e8c45fSAndroid Build Coastguard Worker             std::vector<aidl::android::hardware::graphics::composer3::DisplayLuts::LayerLut>*
243*38e8c45fSAndroid Build Coastguard Worker                     outLuts) override;
244*38e8c45fSAndroid Build Coastguard Worker     Error setLayerLuts(Display display, Layer layer, Luts& luts) override;
245*38e8c45fSAndroid Build Coastguard Worker     Error getMaxLayerPictureProfiles(Display, int32_t* outMaxProfiles) override;
246*38e8c45fSAndroid Build Coastguard Worker     Error setDisplayPictureProfileId(Display, PictureProfileId id) override;
247*38e8c45fSAndroid Build Coastguard Worker     Error setLayerPictureProfileId(Display, Layer, PictureProfileId id) override;
248*38e8c45fSAndroid Build Coastguard Worker 
249*38e8c45fSAndroid Build Coastguard Worker private:
250*38e8c45fSAndroid Build Coastguard Worker     // Many public functions above simply write a command into the command
251*38e8c45fSAndroid Build Coastguard Worker     // queue to batch the calls.  validateDisplay and presentDisplay will call
252*38e8c45fSAndroid Build Coastguard Worker     // this function to execute the command queue.
253*38e8c45fSAndroid Build Coastguard Worker     Error execute(Display) REQUIRES_SHARED(mMutex);
254*38e8c45fSAndroid Build Coastguard Worker 
255*38e8c45fSAndroid Build Coastguard Worker     // returns the default instance name for the given service
256*38e8c45fSAndroid Build Coastguard Worker     static std::string instance(const std::string& serviceName);
257*38e8c45fSAndroid Build Coastguard Worker 
258*38e8c45fSAndroid Build Coastguard Worker     ftl::Optional<std::reference_wrapper<ComposerClientWriter>> getWriter(Display)
259*38e8c45fSAndroid Build Coastguard Worker             REQUIRES_SHARED(mMutex);
260*38e8c45fSAndroid Build Coastguard Worker     ftl::Optional<std::reference_wrapper<ComposerClientReader>> getReader(Display)
261*38e8c45fSAndroid Build Coastguard Worker             REQUIRES_SHARED(mMutex);
262*38e8c45fSAndroid Build Coastguard Worker     void addDisplay(Display) EXCLUDES(mMutex);
263*38e8c45fSAndroid Build Coastguard Worker     void removeDisplay(Display) EXCLUDES(mMutex);
264*38e8c45fSAndroid Build Coastguard Worker     void addReader(Display) REQUIRES(mMutex);
265*38e8c45fSAndroid Build Coastguard Worker     void removeReader(Display) REQUIRES(mMutex);
266*38e8c45fSAndroid Build Coastguard Worker     bool getLayerLifecycleBatchCommand();
267*38e8c45fSAndroid Build Coastguard Worker     bool hasMultiThreadedPresentSupport(Display);
268*38e8c45fSAndroid Build Coastguard Worker 
269*38e8c45fSAndroid Build Coastguard Worker     // 64KiB minus a small space for metadata such as read/write pointers
270*38e8c45fSAndroid Build Coastguard Worker     static constexpr size_t kWriterInitialSize = 64 * 1024 / sizeof(uint32_t) - 16;
271*38e8c45fSAndroid Build Coastguard Worker     // Max number of buffers that may be cached for a given layer
272*38e8c45fSAndroid Build Coastguard Worker     // We obtain this number by:
273*38e8c45fSAndroid Build Coastguard Worker     // 1. Tightly coupling this cache to the max size of BufferQueue
274*38e8c45fSAndroid Build Coastguard Worker     // 2. Adding an additional slot for the layer caching feature in SurfaceFlinger (see: Planner.h)
275*38e8c45fSAndroid Build Coastguard Worker     static const constexpr uint32_t kMaxLayerBufferCount = BufferQueue::NUM_BUFFER_SLOTS + 1;
276*38e8c45fSAndroid Build Coastguard Worker 
277*38e8c45fSAndroid Build Coastguard Worker     // Without DisplayCapability::MULTI_THREADED_PRESENT, we use a single reader
278*38e8c45fSAndroid Build Coastguard Worker     // for all displays. With the capability, we use a separate reader for each
279*38e8c45fSAndroid Build Coastguard Worker     // display.
280*38e8c45fSAndroid Build Coastguard Worker     bool mSingleReader = true;
281*38e8c45fSAndroid Build Coastguard Worker     // Invalid displayId used as a key to mReaders when mSingleReader is true.
282*38e8c45fSAndroid Build Coastguard Worker     static constexpr int64_t kSingleReaderKey = 0;
283*38e8c45fSAndroid Build Coastguard Worker 
284*38e8c45fSAndroid Build Coastguard Worker     ui::PhysicalDisplayMap<Display, ComposerClientWriter> mWriters GUARDED_BY(mMutex);
285*38e8c45fSAndroid Build Coastguard Worker     ui::PhysicalDisplayMap<Display, ComposerClientReader> mReaders GUARDED_BY(mMutex);
286*38e8c45fSAndroid Build Coastguard Worker 
287*38e8c45fSAndroid Build Coastguard Worker     // Protect access to mWriters and mReaders with a shared_mutex. Adding and
288*38e8c45fSAndroid Build Coastguard Worker     // removing a display require exclusive access, since the iterator or the
289*38e8c45fSAndroid Build Coastguard Worker     // writer/reader may be invalidated. Other calls need shared access while
290*38e8c45fSAndroid Build Coastguard Worker     // using the writer/reader, so they can use their display's writer/reader
291*38e8c45fSAndroid Build Coastguard Worker     // without it being deleted or the iterator being invalidated.
292*38e8c45fSAndroid Build Coastguard Worker     // TODO (b/257958323): Use std::shared_mutex and RAII once they support
293*38e8c45fSAndroid Build Coastguard Worker     // threading annotations.
294*38e8c45fSAndroid Build Coastguard Worker     ftl::SharedMutex mMutex;
295*38e8c45fSAndroid Build Coastguard Worker 
296*38e8c45fSAndroid Build Coastguard Worker     int32_t mComposerInterfaceVersion = 1;
297*38e8c45fSAndroid Build Coastguard Worker     bool mEnableLayerCommandBatchingFlag = false;
298*38e8c45fSAndroid Build Coastguard Worker     std::atomic<int64_t> mLayerID = 1;
299*38e8c45fSAndroid Build Coastguard Worker 
300*38e8c45fSAndroid Build Coastguard Worker     // Buffer slots for layers are cleared by setting the slot buffer to this buffer.
301*38e8c45fSAndroid Build Coastguard Worker     sp<GraphicBuffer> mClearSlotBuffer;
302*38e8c45fSAndroid Build Coastguard Worker 
303*38e8c45fSAndroid Build Coastguard Worker     // Aidl interface
304*38e8c45fSAndroid Build Coastguard Worker     using AidlIComposer = aidl::android::hardware::graphics::composer3::IComposer;
305*38e8c45fSAndroid Build Coastguard Worker     using AidlIComposerClient = aidl::android::hardware::graphics::composer3::IComposerClient;
306*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<AidlIComposer> mAidlComposer;
307*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<AidlIComposerClient> mAidlComposerClient;
308*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<AidlIComposerCallbackWrapper> mAidlComposerCallback;
309*38e8c45fSAndroid Build Coastguard Worker };
310*38e8c45fSAndroid Build Coastguard Worker 
311*38e8c45fSAndroid Build Coastguard Worker } // namespace android::Hwc2
312