xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/DisplayDevice.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2007 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 <memory>
20*38e8c45fSAndroid Build Coastguard Worker #include <string>
21*38e8c45fSAndroid Build Coastguard Worker #include <unordered_map>
22*38e8c45fSAndroid Build Coastguard Worker 
23*38e8c45fSAndroid Build Coastguard Worker #include <android-base/thread_annotations.h>
24*38e8c45fSAndroid Build Coastguard Worker #include <android/native_window.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <binder/IBinder.h>
26*38e8c45fSAndroid Build Coastguard Worker #include <gui/LayerState.h>
27*38e8c45fSAndroid Build Coastguard Worker #include <math/mat4.h>
28*38e8c45fSAndroid Build Coastguard Worker #include <renderengine/RenderEngine.h>
29*38e8c45fSAndroid Build Coastguard Worker #include <system/window.h>
30*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayId.h>
31*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayIdentification.h>
32*38e8c45fSAndroid Build Coastguard Worker #include <ui/DisplayState.h>
33*38e8c45fSAndroid Build Coastguard Worker #include <ui/GraphicTypes.h>
34*38e8c45fSAndroid Build Coastguard Worker #include <ui/HdrCapabilities.h>
35*38e8c45fSAndroid Build Coastguard Worker #include <ui/Region.h>
36*38e8c45fSAndroid Build Coastguard Worker #include <ui/StaticDisplayInfo.h>
37*38e8c45fSAndroid Build Coastguard Worker #include <ui/Transform.h>
38*38e8c45fSAndroid Build Coastguard Worker #include <utils/Errors.h>
39*38e8c45fSAndroid Build Coastguard Worker #include <utils/Mutex.h>
40*38e8c45fSAndroid Build Coastguard Worker #include <utils/RefBase.h>
41*38e8c45fSAndroid Build Coastguard Worker #include <utils/Timers.h>
42*38e8c45fSAndroid Build Coastguard Worker 
43*38e8c45fSAndroid Build Coastguard Worker #include "DisplayHardware/DisplayMode.h"
44*38e8c45fSAndroid Build Coastguard Worker #include "DisplayHardware/Hal.h"
45*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/DisplayInfo.h"
46*38e8c45fSAndroid Build Coastguard Worker #include "Scheduler/RefreshRateSelector.h"
47*38e8c45fSAndroid Build Coastguard Worker #include "ThreadContext.h"
48*38e8c45fSAndroid Build Coastguard Worker #include "TracedOrdinal.h"
49*38e8c45fSAndroid Build Coastguard Worker #include "Utils/Dumper.h"
50*38e8c45fSAndroid Build Coastguard Worker 
51*38e8c45fSAndroid Build Coastguard Worker namespace android {
52*38e8c45fSAndroid Build Coastguard Worker 
53*38e8c45fSAndroid Build Coastguard Worker class Fence;
54*38e8c45fSAndroid Build Coastguard Worker class HWComposer;
55*38e8c45fSAndroid Build Coastguard Worker class HdrSdrRatioOverlay;
56*38e8c45fSAndroid Build Coastguard Worker class IGraphicBufferProducer;
57*38e8c45fSAndroid Build Coastguard Worker class Layer;
58*38e8c45fSAndroid Build Coastguard Worker class RefreshRateOverlay;
59*38e8c45fSAndroid Build Coastguard Worker class SurfaceFlinger;
60*38e8c45fSAndroid Build Coastguard Worker 
61*38e8c45fSAndroid Build Coastguard Worker struct CompositionInfo;
62*38e8c45fSAndroid Build Coastguard Worker struct DisplayDeviceCreationArgs;
63*38e8c45fSAndroid Build Coastguard Worker 
64*38e8c45fSAndroid Build Coastguard Worker namespace compositionengine {
65*38e8c45fSAndroid Build Coastguard Worker class Display;
66*38e8c45fSAndroid Build Coastguard Worker class DisplaySurface;
67*38e8c45fSAndroid Build Coastguard Worker } // namespace compositionengine
68*38e8c45fSAndroid Build Coastguard Worker 
69*38e8c45fSAndroid Build Coastguard Worker namespace display {
70*38e8c45fSAndroid Build Coastguard Worker class DisplaySnapshot;
71*38e8c45fSAndroid Build Coastguard Worker } // namespace display
72*38e8c45fSAndroid Build Coastguard Worker 
73*38e8c45fSAndroid Build Coastguard Worker class DisplayDevice : public RefBase {
74*38e8c45fSAndroid Build Coastguard Worker public:
75*38e8c45fSAndroid Build Coastguard Worker     constexpr static float sDefaultMinLumiance = 0.0;
76*38e8c45fSAndroid Build Coastguard Worker     constexpr static float sDefaultMaxLumiance = 500.0;
77*38e8c45fSAndroid Build Coastguard Worker     enum { eReceivesInput = 0x01 };
78*38e8c45fSAndroid Build Coastguard Worker 
79*38e8c45fSAndroid Build Coastguard Worker     explicit DisplayDevice(DisplayDeviceCreationArgs& args);
80*38e8c45fSAndroid Build Coastguard Worker 
81*38e8c45fSAndroid Build Coastguard Worker     // Must be destroyed on the main thread because it may call into HWComposer.
82*38e8c45fSAndroid Build Coastguard Worker     virtual ~DisplayDevice();
83*38e8c45fSAndroid Build Coastguard Worker 
getCompositionDisplay()84*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<compositionengine::Display> getCompositionDisplay() const {
85*38e8c45fSAndroid Build Coastguard Worker         return mCompositionDisplay;
86*38e8c45fSAndroid Build Coastguard Worker     }
87*38e8c45fSAndroid Build Coastguard Worker 
isVirtual()88*38e8c45fSAndroid Build Coastguard Worker     bool isVirtual() const { return getId().isVirtual(); }
isPrimary()89*38e8c45fSAndroid Build Coastguard Worker     bool isPrimary() const { return mIsPrimary; }
90*38e8c45fSAndroid Build Coastguard Worker 
91*38e8c45fSAndroid Build Coastguard Worker     // isSecure indicates whether this display can be trusted to display
92*38e8c45fSAndroid Build Coastguard Worker     // secure surfaces.
93*38e8c45fSAndroid Build Coastguard Worker     bool isSecure() const;
94*38e8c45fSAndroid Build Coastguard Worker     void setSecure(bool secure);
95*38e8c45fSAndroid Build Coastguard Worker 
96*38e8c45fSAndroid Build Coastguard Worker     int getWidth() const;
97*38e8c45fSAndroid Build Coastguard Worker     int getHeight() const;
getSize()98*38e8c45fSAndroid Build Coastguard Worker     ui::Size getSize() const { return {getWidth(), getHeight()}; }
99*38e8c45fSAndroid Build Coastguard Worker 
100*38e8c45fSAndroid Build Coastguard Worker     void setLayerFilter(ui::LayerFilter);
101*38e8c45fSAndroid Build Coastguard Worker     void setDisplaySize(int width, int height);
102*38e8c45fSAndroid Build Coastguard Worker     void setProjection(ui::Rotation orientation, Rect viewport, Rect frame);
103*38e8c45fSAndroid Build Coastguard Worker     void stageBrightness(float brightness) REQUIRES(kMainThreadContext);
104*38e8c45fSAndroid Build Coastguard Worker     void persistBrightness(bool needsComposite) REQUIRES(kMainThreadContext);
105*38e8c45fSAndroid Build Coastguard Worker     bool isBrightnessStale() const REQUIRES(kMainThreadContext);
106*38e8c45fSAndroid Build Coastguard Worker     void setFlags(uint32_t flags);
107*38e8c45fSAndroid Build Coastguard Worker 
getPhysicalOrientation()108*38e8c45fSAndroid Build Coastguard Worker     ui::Rotation getPhysicalOrientation() const { return mPhysicalOrientation; }
getOrientation()109*38e8c45fSAndroid Build Coastguard Worker     ui::Rotation getOrientation() const { return mOrientation; }
110*38e8c45fSAndroid Build Coastguard Worker 
111*38e8c45fSAndroid Build Coastguard Worker     std::optional<float> getStagedBrightness() const REQUIRES(kMainThreadContext);
112*38e8c45fSAndroid Build Coastguard Worker     ui::Transform::RotationFlags getTransformHint() const;
113*38e8c45fSAndroid Build Coastguard Worker     const ui::Transform& getTransform() const;
114*38e8c45fSAndroid Build Coastguard Worker     const Rect& getLayerStackSpaceRect() const;
115*38e8c45fSAndroid Build Coastguard Worker     const Rect& getOrientedDisplaySpaceRect() const;
116*38e8c45fSAndroid Build Coastguard Worker     ui::LayerStack getLayerStack() const;
receivesInput()117*38e8c45fSAndroid Build Coastguard Worker     bool receivesInput() const { return mFlags & eReceivesInput; }
118*38e8c45fSAndroid Build Coastguard Worker 
119*38e8c45fSAndroid Build Coastguard Worker     DisplayId getId() const;
120*38e8c45fSAndroid Build Coastguard Worker 
121*38e8c45fSAndroid Build Coastguard Worker     // Shorthand to upcast the ID of a display whose type is known as a precondition.
getPhysicalId()122*38e8c45fSAndroid Build Coastguard Worker     PhysicalDisplayId getPhysicalId() const {
123*38e8c45fSAndroid Build Coastguard Worker         const auto id = PhysicalDisplayId::tryCast(getId());
124*38e8c45fSAndroid Build Coastguard Worker         LOG_FATAL_IF(!id);
125*38e8c45fSAndroid Build Coastguard Worker         return *id;
126*38e8c45fSAndroid Build Coastguard Worker     }
127*38e8c45fSAndroid Build Coastguard Worker 
getVirtualId()128*38e8c45fSAndroid Build Coastguard Worker     VirtualDisplayId getVirtualId() const {
129*38e8c45fSAndroid Build Coastguard Worker         const auto id = VirtualDisplayId::tryCast(getId());
130*38e8c45fSAndroid Build Coastguard Worker         LOG_FATAL_IF(!id);
131*38e8c45fSAndroid Build Coastguard Worker         return *id;
132*38e8c45fSAndroid Build Coastguard Worker     }
133*38e8c45fSAndroid Build Coastguard Worker 
getDisplayToken()134*38e8c45fSAndroid Build Coastguard Worker     const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
getSequenceId()135*38e8c45fSAndroid Build Coastguard Worker     int32_t getSequenceId() const { return mSequenceId; }
136*38e8c45fSAndroid Build Coastguard Worker 
137*38e8c45fSAndroid Build Coastguard Worker     const Region& getUndefinedRegion() const;
138*38e8c45fSAndroid Build Coastguard Worker 
139*38e8c45fSAndroid Build Coastguard Worker     int32_t getSupportedPerFrameMetadata() const;
140*38e8c45fSAndroid Build Coastguard Worker 
141*38e8c45fSAndroid Build Coastguard Worker     bool hasWideColorGamut() const;
142*38e8c45fSAndroid Build Coastguard Worker     // Whether h/w composer has native support for specific HDR type.
143*38e8c45fSAndroid Build Coastguard Worker     bool hasHDR10PlusSupport() const;
144*38e8c45fSAndroid Build Coastguard Worker     bool hasHDR10Support() const;
145*38e8c45fSAndroid Build Coastguard Worker     bool hasHLGSupport() const;
146*38e8c45fSAndroid Build Coastguard Worker     bool hasDolbyVisionSupport() const;
147*38e8c45fSAndroid Build Coastguard Worker 
148*38e8c45fSAndroid Build Coastguard Worker     void overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes);
149*38e8c45fSAndroid Build Coastguard Worker 
150*38e8c45fSAndroid Build Coastguard Worker     // The returned HdrCapabilities is the combination of HDR capabilities from
151*38e8c45fSAndroid Build Coastguard Worker     // hardware composer and RenderEngine. When the DisplayDevice supports wide
152*38e8c45fSAndroid Build Coastguard Worker     // color gamut, RenderEngine is able to simulate HDR support in Display P3
153*38e8c45fSAndroid Build Coastguard Worker     // color space for both PQ and HLG HDR contents. The minimum and maximum
154*38e8c45fSAndroid Build Coastguard Worker     // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
155*38e8c45fSAndroid Build Coastguard Worker     // respectively if hardware composer doesn't return meaningful values.
156*38e8c45fSAndroid Build Coastguard Worker     HdrCapabilities getHdrCapabilities() const;
157*38e8c45fSAndroid Build Coastguard Worker 
158*38e8c45fSAndroid Build Coastguard Worker     // Return true if intent is supported by the display.
159*38e8c45fSAndroid Build Coastguard Worker     bool hasRenderIntent(ui::RenderIntent intent) const;
160*38e8c45fSAndroid Build Coastguard Worker 
161*38e8c45fSAndroid Build Coastguard Worker     const Rect getBounds() const;
bounds()162*38e8c45fSAndroid Build Coastguard Worker     const Rect bounds() const { return getBounds(); }
163*38e8c45fSAndroid Build Coastguard Worker 
164*38e8c45fSAndroid Build Coastguard Worker     void setDisplayName(const std::string& displayName);
getDisplayName()165*38e8c45fSAndroid Build Coastguard Worker     const std::string& getDisplayName() const { return mDisplayName; }
166*38e8c45fSAndroid Build Coastguard Worker 
167*38e8c45fSAndroid Build Coastguard Worker     surfaceflinger::frontend::DisplayInfo getFrontEndInfo() const;
168*38e8c45fSAndroid Build Coastguard Worker 
169*38e8c45fSAndroid Build Coastguard Worker     /* ------------------------------------------------------------------------
170*38e8c45fSAndroid Build Coastguard Worker      * Display power mode management.
171*38e8c45fSAndroid Build Coastguard Worker      */
172*38e8c45fSAndroid Build Coastguard Worker     hardware::graphics::composer::hal::PowerMode getPowerMode() const;
173*38e8c45fSAndroid Build Coastguard Worker     void setPowerMode(hardware::graphics::composer::hal::PowerMode);
174*38e8c45fSAndroid Build Coastguard Worker     bool isPoweredOn() const;
175*38e8c45fSAndroid Build Coastguard Worker     bool isRefreshable() const;
176*38e8c45fSAndroid Build Coastguard Worker     void tracePowerMode();
177*38e8c45fSAndroid Build Coastguard Worker 
178*38e8c45fSAndroid Build Coastguard Worker     // Enables layer caching on this DisplayDevice
179*38e8c45fSAndroid Build Coastguard Worker     void enableLayerCaching(bool enable);
180*38e8c45fSAndroid Build Coastguard Worker 
181*38e8c45fSAndroid Build Coastguard Worker     ui::Dataspace getCompositionDataSpace() const;
182*38e8c45fSAndroid Build Coastguard Worker 
refreshRateSelector()183*38e8c45fSAndroid Build Coastguard Worker     scheduler::RefreshRateSelector& refreshRateSelector() const { return *mRefreshRateSelector; }
184*38e8c45fSAndroid Build Coastguard Worker 
185*38e8c45fSAndroid Build Coastguard Worker     // Extends the lifetime of the RefreshRateSelector, so it can outlive this DisplayDevice.
holdRefreshRateSelector()186*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<scheduler::RefreshRateSelector> holdRefreshRateSelector() const {
187*38e8c45fSAndroid Build Coastguard Worker         return mRefreshRateSelector;
188*38e8c45fSAndroid Build Coastguard Worker     }
189*38e8c45fSAndroid Build Coastguard Worker 
190*38e8c45fSAndroid Build Coastguard Worker     // Enables an overlay to be displayed with the current refresh rate
191*38e8c45fSAndroid Build Coastguard Worker     // TODO(b/241285876): Move overlay to DisplayModeController.
192*38e8c45fSAndroid Build Coastguard Worker     void enableRefreshRateOverlay(bool enable, bool setByHwc, Fps refreshRate, Fps renderFps,
193*38e8c45fSAndroid Build Coastguard Worker                                   bool showSpinner, bool showRenderRate, bool showInMiddle)
194*38e8c45fSAndroid Build Coastguard Worker             REQUIRES(kMainThreadContext);
195*38e8c45fSAndroid Build Coastguard Worker     void updateRefreshRateOverlayRate(Fps refreshRate, Fps renderFps, bool setByHwc = false);
isRefreshRateOverlayEnabled()196*38e8c45fSAndroid Build Coastguard Worker     bool isRefreshRateOverlayEnabled() const { return mRefreshRateOverlay != nullptr; }
197*38e8c45fSAndroid Build Coastguard Worker     void animateOverlay();
198*38e8c45fSAndroid Build Coastguard Worker     bool onKernelTimerChanged(std::optional<DisplayModeId>, bool timerExpired);
199*38e8c45fSAndroid Build Coastguard Worker     void onVrrIdle(bool idle);
200*38e8c45fSAndroid Build Coastguard Worker 
201*38e8c45fSAndroid Build Coastguard Worker     // Enables an overlay to be display with the hdr/sdr ratio
202*38e8c45fSAndroid Build Coastguard Worker     void enableHdrSdrRatioOverlay(bool enable) REQUIRES(kMainThreadContext);
203*38e8c45fSAndroid Build Coastguard Worker     void updateHdrSdrRatioOverlayRatio(float currentHdrSdrRatio);
isHdrSdrRatioOverlayEnabled()204*38e8c45fSAndroid Build Coastguard Worker     bool isHdrSdrRatioOverlayEnabled() const { return mHdrSdrRatioOverlay != nullptr; }
205*38e8c45fSAndroid Build Coastguard Worker 
getAdjustedRefreshRate()206*38e8c45fSAndroid Build Coastguard Worker     Fps getAdjustedRefreshRate() const { return mAdjustedRefreshRate; }
207*38e8c45fSAndroid Build Coastguard Worker 
208*38e8c45fSAndroid Build Coastguard Worker     // Round the requested refresh rate to match a divisor of the pacesetter
209*38e8c45fSAndroid Build Coastguard Worker     // display's refresh rate. Only supported for virtual displays.
210*38e8c45fSAndroid Build Coastguard Worker     void adjustRefreshRate(Fps pacesetterDisplayRefreshRate);
211*38e8c45fSAndroid Build Coastguard Worker 
212*38e8c45fSAndroid Build Coastguard Worker     // release HWC resources (if any) for removable displays
213*38e8c45fSAndroid Build Coastguard Worker     void disconnect();
214*38e8c45fSAndroid Build Coastguard Worker 
215*38e8c45fSAndroid Build Coastguard Worker     void dump(utils::Dumper&) const;
216*38e8c45fSAndroid Build Coastguard Worker 
217*38e8c45fSAndroid Build Coastguard Worker private:
218*38e8c45fSAndroid Build Coastguard Worker     const sp<SurfaceFlinger> mFlinger;
219*38e8c45fSAndroid Build Coastguard Worker     HWComposer& mHwComposer;
220*38e8c45fSAndroid Build Coastguard Worker     const wp<IBinder> mDisplayToken;
221*38e8c45fSAndroid Build Coastguard Worker     const int32_t mSequenceId;
222*38e8c45fSAndroid Build Coastguard Worker 
223*38e8c45fSAndroid Build Coastguard Worker     const std::shared_ptr<compositionengine::Display> mCompositionDisplay;
224*38e8c45fSAndroid Build Coastguard Worker 
225*38e8c45fSAndroid Build Coastguard Worker     std::string mDisplayName;
226*38e8c45fSAndroid Build Coastguard Worker 
227*38e8c45fSAndroid Build Coastguard Worker     const ui::Rotation mPhysicalOrientation;
228*38e8c45fSAndroid Build Coastguard Worker     ui::Rotation mOrientation = ui::ROTATION_0;
229*38e8c45fSAndroid Build Coastguard Worker     bool mIsOrientationChanged = false;
230*38e8c45fSAndroid Build Coastguard Worker 
231*38e8c45fSAndroid Build Coastguard Worker     TracedOrdinal<hardware::graphics::composer::hal::PowerMode> mPowerMode;
232*38e8c45fSAndroid Build Coastguard Worker 
233*38e8c45fSAndroid Build Coastguard Worker     std::optional<float> mStagedBrightness;
234*38e8c45fSAndroid Build Coastguard Worker     std::optional<float> mBrightness;
235*38e8c45fSAndroid Build Coastguard Worker 
236*38e8c45fSAndroid Build Coastguard Worker     // TODO(b/182939859): Remove special cases for primary display.
237*38e8c45fSAndroid Build Coastguard Worker     const bool mIsPrimary;
238*38e8c45fSAndroid Build Coastguard Worker 
239*38e8c45fSAndroid Build Coastguard Worker     uint32_t mFlags = 0;
240*38e8c45fSAndroid Build Coastguard Worker 
241*38e8c45fSAndroid Build Coastguard Worker     // Requested refresh rate in fps, supported only for virtual displays.
242*38e8c45fSAndroid Build Coastguard Worker     // when this value is non zero, SurfaceFlinger will try to drop frames
243*38e8c45fSAndroid Build Coastguard Worker     // for virtual displays to match this requested refresh rate.
244*38e8c45fSAndroid Build Coastguard Worker     const Fps mRequestedRefreshRate;
245*38e8c45fSAndroid Build Coastguard Worker 
246*38e8c45fSAndroid Build Coastguard Worker     // Adjusted refresh rate, rounded to match a divisor of the pacesetter
247*38e8c45fSAndroid Build Coastguard Worker     // display's refresh rate. Only supported for virtual displays.
248*38e8c45fSAndroid Build Coastguard Worker     Fps mAdjustedRefreshRate = 0_Hz;
249*38e8c45fSAndroid Build Coastguard Worker 
250*38e8c45fSAndroid Build Coastguard Worker     std::vector<ui::Hdr> mOverrideHdrTypes;
251*38e8c45fSAndroid Build Coastguard Worker 
252*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<scheduler::RefreshRateSelector> mRefreshRateSelector;
253*38e8c45fSAndroid Build Coastguard Worker     std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay;
254*38e8c45fSAndroid Build Coastguard Worker     std::unique_ptr<HdrSdrRatioOverlay> mHdrSdrRatioOverlay;
255*38e8c45fSAndroid Build Coastguard Worker     // This parameter is only used for hdr/sdr ratio overlay
256*38e8c45fSAndroid Build Coastguard Worker     float mHdrSdrRatio = 1.0f;
257*38e8c45fSAndroid Build Coastguard Worker };
258*38e8c45fSAndroid Build Coastguard Worker 
259*38e8c45fSAndroid Build Coastguard Worker struct DisplayDeviceState {
260*38e8c45fSAndroid Build Coastguard Worker     struct Physical {
261*38e8c45fSAndroid Build Coastguard Worker         PhysicalDisplayId id;
262*38e8c45fSAndroid Build Coastguard Worker         hardware::graphics::composer::hal::HWDisplayId hwcDisplayId;
263*38e8c45fSAndroid Build Coastguard Worker         DisplayModePtr activeMode;
264*38e8c45fSAndroid Build Coastguard Worker 
265*38e8c45fSAndroid Build Coastguard Worker         bool operator==(const Physical& other) const {
266*38e8c45fSAndroid Build Coastguard Worker             return id == other.id && hwcDisplayId == other.hwcDisplayId;
267*38e8c45fSAndroid Build Coastguard Worker         }
268*38e8c45fSAndroid Build Coastguard Worker     };
269*38e8c45fSAndroid Build Coastguard Worker 
isVirtualDisplayDeviceState270*38e8c45fSAndroid Build Coastguard Worker     bool isVirtual() const { return !physical; }
271*38e8c45fSAndroid Build Coastguard Worker 
272*38e8c45fSAndroid Build Coastguard Worker     int32_t sequenceId = sNextSequenceId++;
273*38e8c45fSAndroid Build Coastguard Worker     std::optional<Physical> physical;
274*38e8c45fSAndroid Build Coastguard Worker     sp<IGraphicBufferProducer> surface;
275*38e8c45fSAndroid Build Coastguard Worker     ui::LayerStack layerStack;
276*38e8c45fSAndroid Build Coastguard Worker     uint32_t flags = 0;
277*38e8c45fSAndroid Build Coastguard Worker     Rect layerStackSpaceRect;
278*38e8c45fSAndroid Build Coastguard Worker     Rect orientedDisplaySpaceRect;
279*38e8c45fSAndroid Build Coastguard Worker     ui::Rotation orientation = ui::ROTATION_0;
280*38e8c45fSAndroid Build Coastguard Worker     uint32_t width = 0;
281*38e8c45fSAndroid Build Coastguard Worker     uint32_t height = 0;
282*38e8c45fSAndroid Build Coastguard Worker     std::string displayName;
283*38e8c45fSAndroid Build Coastguard Worker     std::string uniqueId;
284*38e8c45fSAndroid Build Coastguard Worker     bool isSecure = false;
285*38e8c45fSAndroid Build Coastguard Worker     bool isProtected = false;
286*38e8c45fSAndroid Build Coastguard Worker     // Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only
287*38e8c45fSAndroid Build Coastguard Worker     Fps requestedRefreshRate;
288*38e8c45fSAndroid Build Coastguard Worker     int32_t maxLayerPictureProfiles = 0;
289*38e8c45fSAndroid Build Coastguard Worker     bool hasPictureProcessing = false;
290*38e8c45fSAndroid Build Coastguard Worker 
291*38e8c45fSAndroid Build Coastguard Worker private:
292*38e8c45fSAndroid Build Coastguard Worker     static std::atomic<int32_t> sNextSequenceId;
293*38e8c45fSAndroid Build Coastguard Worker };
294*38e8c45fSAndroid Build Coastguard Worker 
295*38e8c45fSAndroid Build Coastguard Worker struct DisplayDeviceCreationArgs {
296*38e8c45fSAndroid Build Coastguard Worker     // We use a constructor to ensure some of the values are set, without
297*38e8c45fSAndroid Build Coastguard Worker     // assuming a default value.
298*38e8c45fSAndroid Build Coastguard Worker     DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, HWComposer& hwComposer,
299*38e8c45fSAndroid Build Coastguard Worker                               const wp<IBinder>& displayToken,
300*38e8c45fSAndroid Build Coastguard Worker                               std::shared_ptr<compositionengine::Display>);
301*38e8c45fSAndroid Build Coastguard Worker     const sp<SurfaceFlinger> flinger;
302*38e8c45fSAndroid Build Coastguard Worker     HWComposer& hwComposer;
303*38e8c45fSAndroid Build Coastguard Worker     const wp<IBinder> displayToken;
304*38e8c45fSAndroid Build Coastguard Worker     const std::shared_ptr<compositionengine::Display> compositionDisplay;
305*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<scheduler::RefreshRateSelector> refreshRateSelector;
306*38e8c45fSAndroid Build Coastguard Worker 
307*38e8c45fSAndroid Build Coastguard Worker     int32_t sequenceId{0};
308*38e8c45fSAndroid Build Coastguard Worker     bool isSecure{false};
309*38e8c45fSAndroid Build Coastguard Worker     bool isProtected{false};
310*38e8c45fSAndroid Build Coastguard Worker     sp<ANativeWindow> nativeWindow;
311*38e8c45fSAndroid Build Coastguard Worker     sp<compositionengine::DisplaySurface> displaySurface;
312*38e8c45fSAndroid Build Coastguard Worker     ui::Rotation physicalOrientation{ui::ROTATION_0};
313*38e8c45fSAndroid Build Coastguard Worker     bool hasWideColorGamut{false};
314*38e8c45fSAndroid Build Coastguard Worker     HdrCapabilities hdrCapabilities;
315*38e8c45fSAndroid Build Coastguard Worker     int32_t supportedPerFrameMetadata{0};
316*38e8c45fSAndroid Build Coastguard Worker     std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
317*38e8c45fSAndroid Build Coastguard Worker     hardware::graphics::composer::hal::PowerMode initialPowerMode{
318*38e8c45fSAndroid Build Coastguard Worker             hardware::graphics::composer::hal::PowerMode::OFF};
319*38e8c45fSAndroid Build Coastguard Worker     bool isPrimary{false};
320*38e8c45fSAndroid Build Coastguard Worker     // Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only
321*38e8c45fSAndroid Build Coastguard Worker     Fps requestedRefreshRate;
322*38e8c45fSAndroid Build Coastguard Worker };
323*38e8c45fSAndroid Build Coastguard Worker 
324*38e8c45fSAndroid Build Coastguard Worker } // namespace android
325