blob: c70c1df203c4473963a06eefcaef6eb99322da34 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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
Dominik Laskowski718f9602019-11-09 20:01:35 -080017#pragma once
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080018
Peiyong Linefefaac2018-08-17 12:27:51 -070019#include <memory>
20#include <string>
Peiyong Lin136fbbc2018-04-17 15:09:44 -070021#include <unordered_map>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022
Dominik Laskowski298b08e2022-02-15 13:45:02 -080023#include <android-base/thread_annotations.h>
Alec Mourif6fd29e2018-11-17 04:56:41 +000024#include <android/native_window.h>
Dan Stoza9e56aa02015-11-02 13:00:03 -080025#include <binder/IBinder.h>
Leon Scroggins III4c2bed72023-02-07 11:51:02 -050026#include <ftl/concat.h>
Dominik Laskowski59746512023-11-19 09:30:24 -050027#include <ftl/optional.h>
Chia-I Wuf2aa3112018-08-27 14:54:37 -070028#include <gui/LayerState.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070029#include <math/mat4.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080030#include <renderengine/RenderEngine.h>
Alec Mourif6fd29e2018-11-17 04:56:41 +000031#include <system/window.h>
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +020032#include <ui/DisplayId.h>
Dominik Laskowski298b08e2022-02-15 13:45:02 -080033#include <ui/DisplayIdentification.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080034#include <ui/DisplayState.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070035#include <ui/GraphicTypes.h>
Peiyong Linfb069302018-04-25 14:34:31 -070036#include <ui/HdrCapabilities.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070037#include <ui/Region.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010038#include <ui/StaticDisplayInfo.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070039#include <ui/Transform.h>
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010040#include <utils/Errors.h>
Alec Mouri8d4f90a2018-11-14 22:33:24 +000041#include <utils/Mutex.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080042#include <utils/RefBase.h>
Mathias Agopian86303202012-07-24 22:46:10 -070043#include <utils/Timers.h>
44
Dominik Laskowski530d6bd2022-10-10 16:55:54 -040045#include "Display/DisplayModeRequest.h"
Marin Shalamanov23c44202020-12-22 19:09:20 +010046#include "DisplayHardware/DisplayMode.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070047#include "DisplayHardware/Hal.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080048#include "DisplayHardware/PowerAdvisor.h"
Vishnu Nairaf6d2972022-11-18 06:26:38 +000049#include "FrontEnd/DisplayInfo.h"
Dominik Laskowskid82e0f02022-10-26 15:23:04 -040050#include "Scheduler/RefreshRateSelector.h"
Dominik Laskowski298b08e2022-02-15 13:45:02 -080051#include "ThreadContext.h"
Ady Abraham690f4612021-07-01 23:24:03 -070052#include "TracedOrdinal.h"
Dominik Laskowskie70461a2022-08-30 14:42:01 -070053#include "Utils/Dumper.h"
Dominik Laskowski59746512023-11-19 09:30:24 -050054
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055namespace android {
56
Dan Stoza9e56aa02015-11-02 13:00:03 -080057class Fence;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070058class HWComposer;
Sally Qi147581b2023-06-27 11:55:34 -070059class HdrSdrRatioOverlay;
Jesse Hall9e663de2013-08-16 14:28:37 -070060class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080061class Layer;
Ady Abraham1b11bc62021-06-03 19:51:19 -070062class RefreshRateOverlay;
Mathias Agopian86303202012-07-24 22:46:10 -070063class SurfaceFlinger;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070064
David Sodmanfb95bcc2017-12-22 15:45:30 -080065struct CompositionInfo;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070066struct DisplayDeviceCreationArgs;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067
Lloyd Pique45a165a2018-10-19 11:54:47 -070068namespace compositionengine {
69class Display;
Lloyd Pique542307f2018-10-19 13:24:08 -070070class DisplaySurface;
Lloyd Pique45a165a2018-10-19 11:54:47 -070071} // namespace compositionengine
72
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070073namespace display {
74class DisplaySnapshot;
75} // namespace display
76
Marin Shalamanov1c434292020-06-12 01:47:29 +020077class DisplayDevice : public RefBase {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078public:
Peiyong Linfb069302018-04-25 14:34:31 -070079 constexpr static float sDefaultMinLumiance = 0.0;
80 constexpr static float sDefaultMaxLumiance = 500.0;
Evan Rosky2239b372021-05-20 13:43:47 -070081 enum { eReceivesInput = 0x01 };
Peiyong Linfb069302018-04-25 14:34:31 -070082
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070083 explicit DisplayDevice(DisplayDeviceCreationArgs& args);
Marin Shalamanov1c434292020-06-12 01:47:29 +020084
85 // Must be destroyed on the main thread because it may call into HWComposer.
Lloyd Pique45a165a2018-10-19 11:54:47 -070086 virtual ~DisplayDevice();
87
88 std::shared_ptr<compositionengine::Display> getCompositionDisplay() const {
89 return mCompositionDisplay;
90 }
Mathias Agopian92a979a2012-08-02 18:32:23 -070091
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070092 bool isVirtual() const { return VirtualDisplayId::tryCast(getId()).has_value(); }
Dominik Laskowski075d3172018-05-24 15:50:06 -070093 bool isPrimary() const { return mIsPrimary; }
Mathias Agopian92a979a2012-08-02 18:32:23 -070094
Jamie Gennisdd3cb842012-10-19 18:19:11 -070095 // isSecure indicates whether this display can be trusted to display
96 // secure surfaces.
Lloyd Pique45a165a2018-10-19 11:54:47 -070097 bool isSecure() const;
Jamie Gennisdd3cb842012-10-19 18:19:11 -070098
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080099 int getWidth() const;
100 int getHeight() const;
101 ui::Size getSize() const { return {getWidth(), getHeight()}; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700102
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700103 void setLayerFilter(ui::LayerFilter);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800104 void setDisplaySize(int width, int height);
Dominik Laskowski718f9602019-11-09 20:01:35 -0800105 void setProjection(ui::Rotation orientation, Rect viewport, Rect frame);
Dominik Laskowski298b08e2022-02-15 13:45:02 -0800106 void stageBrightness(float brightness) REQUIRES(kMainThreadContext);
107 void persistBrightness(bool needsComposite) REQUIRES(kMainThreadContext);
108 bool isBrightnessStale() const REQUIRES(kMainThreadContext);
Evan Rosky2239b372021-05-20 13:43:47 -0700109 void setFlags(uint32_t flags);
Dominik Laskowski718f9602019-11-09 20:01:35 -0800110
111 ui::Rotation getPhysicalOrientation() const { return mPhysicalOrientation; }
112 ui::Rotation getOrientation() const { return mOrientation; }
113
Dominik Laskowski298b08e2022-02-15 13:45:02 -0800114 std::optional<float> getStagedBrightness() const REQUIRES(kMainThreadContext);
Garfield Tan54edd912020-10-21 16:31:41 -0700115 ui::Transform::RotationFlags getTransformHint() const;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700116 const ui::Transform& getTransform() const;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200117 const Rect& getLayerStackSpaceRect() const;
118 const Rect& getOrientedDisplaySpaceRect() const;
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800119 ui::LayerStack getLayerStack() const;
Evan Rosky2239b372021-05-20 13:43:47 -0700120 bool receivesInput() const { return mFlags & eReceivesInput; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700121
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800122 DisplayId getId() const;
123
124 // Shorthand to upcast the ID of a display whose type is known as a precondition.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200125 PhysicalDisplayId getPhysicalId() const {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800126 const auto id = PhysicalDisplayId::tryCast(getId());
127 LOG_FATAL_IF(!id);
128 return *id;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200129 }
130
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800131 VirtualDisplayId getVirtualId() const {
132 const auto id = VirtualDisplayId::tryCast(getId());
133 LOG_FATAL_IF(!id);
134 return *id;
135 }
136
Dominik Laskowski075d3172018-05-24 15:50:06 -0700137 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Dominik Laskowskie9774092018-12-11 10:04:24 -0800138 int32_t getSequenceId() const { return mSequenceId; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700139
Lloyd Pique32cbe282018-10-19 13:09:22 -0700140 const Region& getUndefinedRegion() const;
141
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700142 int32_t getSupportedPerFrameMetadata() const;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700143
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700144 bool hasWideColorGamut() const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700145 // Whether h/w composer has native support for specific HDR type.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700146 bool hasHDR10PlusSupport() const;
147 bool hasHDR10Support() const;
148 bool hasHLGSupport() const;
149 bool hasDolbyVisionSupport() const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700150
Kriti Dang4bc7cdf2021-01-08 11:49:56 +0100151 void overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes);
152
Peiyong Linfb069302018-04-25 14:34:31 -0700153 // The returned HdrCapabilities is the combination of HDR capabilities from
154 // hardware composer and RenderEngine. When the DisplayDevice supports wide
155 // color gamut, RenderEngine is able to simulate HDR support in Display P3
156 // color space for both PQ and HLG HDR contents. The minimum and maximum
157 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
158 // respectively if hardware composer doesn't return meaningful values.
Kriti Dang4bc7cdf2021-01-08 11:49:56 +0100159 HdrCapabilities getHdrCapabilities() const;
Jesse Hall38efe862013-04-06 23:12:29 -0700160
Chia-I Wube02ec02018-05-18 10:59:36 -0700161 // Return true if intent is supported by the display.
162 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700163
Angel Aguayob108a6d2021-08-06 21:34:57 +0000164 const Rect getBounds() const;
165 const Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800166
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700167 void setDisplayName(const std::string& displayName);
168 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700169
Vishnu Nairaf6d2972022-11-18 06:26:38 +0000170 surfaceflinger::frontend::DisplayInfo getFrontEndInfo() const;
Prabir Pradhan48f8cb92021-08-26 14:05:36 -0700171
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700172 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700173 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700174 */
linpeter1c69cd32022-07-13 19:20:48 +0800175 std::optional<hardware::graphics::composer::hal::PowerMode> getPowerMode() const;
Peiyong Lin65248e02020-04-18 21:15:07 -0700176 void setPowerMode(hardware::graphics::composer::hal::PowerMode mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700177 bool isPoweredOn() const;
Ady Abraham66452722023-03-14 17:41:47 -0700178 void tracePowerMode();
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700179
Alec Mouridd8bf2d2021-05-08 16:36:33 -0700180 // Enables layer caching on this DisplayDevice
181 void enableLayerCaching(bool enable);
182
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800183 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700184
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700185 /* ------------------------------------------------------------------------
Marin Shalamanov5801c942020-12-17 17:00:13 +0100186 * Display mode management.
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700187 */
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400188
189 // TODO(b/241285876): Replace ActiveModeInfo and DisplayModeEvent with DisplayModeRequest.
Ady Abraham690f4612021-07-01 23:24:03 -0700190 struct ActiveModeInfo {
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400191 using Event = scheduler::DisplayModeEvent;
192
193 ActiveModeInfo() = default;
Ady Abrahamace3d052022-11-17 16:25:05 -0800194 ActiveModeInfo(scheduler::FrameRateMode mode, Event event)
195 : modeOpt(std::move(mode)), event(event) {}
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400196
197 explicit ActiveModeInfo(display::DisplayModeRequest&& request)
Ady Abrahamace3d052022-11-17 16:25:05 -0800198 : ActiveModeInfo(std::move(request.mode),
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400199 request.emitEvent ? Event::Changed : Event::None) {}
200
Ady Abrahamace3d052022-11-17 16:25:05 -0800201 ftl::Optional<scheduler::FrameRateMode> modeOpt;
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400202 Event event = Event::None;
Ady Abraham690f4612021-07-01 23:24:03 -0700203
204 bool operator!=(const ActiveModeInfo& other) const {
Ady Abrahamace3d052022-11-17 16:25:05 -0800205 return modeOpt != other.modeOpt || event != other.event;
Ady Abraham690f4612021-07-01 23:24:03 -0700206 }
207 };
208
Dominik Laskowski59746512023-11-19 09:30:24 -0500209 enum class DesiredModeAction { None, InitiateDisplayModeSwitch, InitiateRenderRateSwitch };
Ady Abraham690f4612021-07-01 23:24:03 -0700210
Dominik Laskowski59746512023-11-19 09:30:24 -0500211 DesiredModeAction setDesiredMode(const ActiveModeInfo&, bool force = false)
212 EXCLUDES(mDesiredModeLock);
213
214 ftl::Optional<ActiveModeInfo> getDesiredMode() const EXCLUDES(mDesiredModeLock);
215 void clearDesiredMode() EXCLUDES(mDesiredModeLock);
216
217 ActiveModeInfo getPendingMode() const REQUIRES(kMainThreadContext) { return mPendingMode; }
Dominik Laskowskifdac5652023-06-29 12:01:13 -0400218 bool isModeSetPending() const REQUIRES(kMainThreadContext) { return mIsModeSetPending; }
219
Ady Abrahamace3d052022-11-17 16:25:05 -0800220 scheduler::FrameRateMode getActiveMode() const REQUIRES(kMainThreadContext) {
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400221 return mRefreshRateSelector->getActiveMode();
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700222 }
223
ramindania04b8a52023-08-07 18:49:47 -0700224 void setActiveMode(DisplayModeId, Fps vsyncRate, Fps renderFps);
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700225
Ady Abraham690f4612021-07-01 23:24:03 -0700226 status_t initiateModeChange(const ActiveModeInfo&,
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100227 const hal::VsyncPeriodChangeConstraints& constraints,
Ady Abraham690f4612021-07-01 23:24:03 -0700228 hal::VsyncPeriodChangeTimeline* outTimeline)
Dominik Laskowski298b08e2022-02-15 13:45:02 -0800229 REQUIRES(kMainThreadContext);
Marin Shalamanov5801c942020-12-17 17:00:13 +0100230
ramindania04b8a52023-08-07 18:49:47 -0700231 void finalizeModeChange(DisplayModeId, Fps vsyncRate, Fps renderFps)
Dominik Laskowskifdac5652023-06-29 12:01:13 -0400232 REQUIRES(kMainThreadContext);
233
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400234 scheduler::RefreshRateSelector& refreshRateSelector() const { return *mRefreshRateSelector; }
Ady Abraham3efa3942021-06-24 19:01:25 -0700235
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400236 // Extends the lifetime of the RefreshRateSelector, so it can outlive this DisplayDevice.
237 std::shared_ptr<scheduler::RefreshRateSelector> holdRefreshRateSelector() const {
238 return mRefreshRateSelector;
Ady Abraham3efa3942021-06-24 19:01:25 -0700239 }
240
Sally Qi147581b2023-06-27 11:55:34 -0700241 void animateOverlay();
242
Ady Abraham1b11bc62021-06-03 19:51:19 -0700243 // Enables an overlay to be displayed with the current refresh rate
Lloyd Pique30db6402023-06-26 18:56:51 +0000244 void enableRefreshRateOverlay(bool enable, bool setByHwc, bool showSpinner, bool showRenderRate,
245 bool showInMiddle) REQUIRES(kMainThreadContext);
ramindania04b8a52023-08-07 18:49:47 -0700246 void updateRefreshRateOverlayRate(Fps vsyncRate, Fps renderFps, bool setByHwc = false);
Ady Abraham1b11bc62021-06-03 19:51:19 -0700247 bool isRefreshRateOverlayEnabled() const { return mRefreshRateOverlay != nullptr; }
248 bool onKernelTimerChanged(std::optional<DisplayModeId>, bool timerExpired);
Sally Qi147581b2023-06-27 11:55:34 -0700249
250 // Enables an overlay to be display with the hdr/sdr ratio
251 void enableHdrSdrRatioOverlay(bool enable) REQUIRES(kMainThreadContext);
252 void updateHdrSdrRatioOverlayRatio(float currentHdrSdrRatio);
253 bool isHdrSdrRatioOverlayEnabled() const { return mHdrSdrRatioOverlay != nullptr; }
Ady Abraham1b11bc62021-06-03 19:51:19 -0700254
Marin Shalamanov045b7002021-01-07 16:56:24 +0100255 nsecs_t getVsyncPeriodFromHWC() const;
Marin Shalamanov045b7002021-01-07 16:56:24 +0100256
Huihong Luo1768cb02022-10-11 11:10:34 -0700257 Fps getAdjustedRefreshRate() const { return mAdjustedRefreshRate; }
258
Leon Scroggins III1af0fb62023-03-02 14:21:44 -0500259 // Round the requested refresh rate to match a divisor of the pacesetter
Huihong Luo1768cb02022-10-11 11:10:34 -0700260 // display's refresh rate. Only supported for virtual displays.
Leon Scroggins III1af0fb62023-03-02 14:21:44 -0500261 void adjustRefreshRate(Fps pacesetterDisplayRefreshRate);
Huihong Luo1768cb02022-10-11 11:10:34 -0700262
Jesse Hall02d86562013-03-25 14:43:23 -0700263 // release HWC resources (if any) for removable displays
Lloyd Pique45a165a2018-10-19 11:54:47 -0700264 void disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700265
Dominik Laskowskie70461a2022-08-30 14:42:01 -0700266 void dump(utils::Dumper&) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700267
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800268private:
Dominik Laskowski0784adc2023-10-13 18:35:37 -0400269 template <size_t N>
270 inline std::string concatId(const char (&str)[N]) const {
271 return std::string(ftl::Concat(str, ' ', getId().value).str());
272 }
273
Dominik Laskowski075d3172018-05-24 15:50:06 -0700274 const sp<SurfaceFlinger> mFlinger;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100275 HWComposer& mHwComposer;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700276 const wp<IBinder> mDisplayToken;
Dominik Laskowskie9774092018-12-11 10:04:24 -0800277 const int32_t mSequenceId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700278
Lloyd Pique45a165a2018-10-19 11:54:47 -0700279 const std::shared_ptr<compositionengine::Display> mCompositionDisplay;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700280
Lloyd Pique31cb2942018-10-19 17:23:03 -0700281 std::string mDisplayName;
Dominik Laskowski59746512023-11-19 09:30:24 -0500282 std::string mPendingModeFpsTrace;
283 std::string mActiveModeFpsTrace;
284 std::string mRenderRateFpsTrace;
Mathias Agopian03e40722012-04-26 16:11:59 -0700285
Dominik Laskowski718f9602019-11-09 20:01:35 -0800286 const ui::Rotation mPhysicalOrientation;
287 ui::Rotation mOrientation = ui::ROTATION_0;
Sally Qi147581b2023-06-27 11:55:34 -0700288 bool mIsOrientationChanged = false;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700289
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700290 // Allow nullopt as initial power mode.
Ady Abraham66452722023-03-14 17:41:47 -0700291 using TracedPowerMode = TracedOrdinal<hardware::graphics::composer::hal::PowerMode>;
292 std::optional<TracedPowerMode> mPowerMode;
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700293
294 std::optional<float> mStagedBrightness;
linpeterdcfd4e62022-12-29 09:39:14 +0800295 std::optional<float> mBrightness;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600296
Dominik Laskowskif8db0f02021-04-19 11:05:25 -0700297 // TODO(b/182939859): Remove special cases for primary display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700298 const bool mIsPrimary;
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200299
Evan Rosky2239b372021-05-20 13:43:47 -0700300 uint32_t mFlags = 0;
301
Huihong Luo1768cb02022-10-11 11:10:34 -0700302 // Requested refresh rate in fps, supported only for virtual displays.
303 // when this value is non zero, SurfaceFlinger will try to drop frames
304 // for virtual displays to match this requested refresh rate.
305 const Fps mRequestedRefreshRate;
306
Leon Scroggins III1af0fb62023-03-02 14:21:44 -0500307 // Adjusted refresh rate, rounded to match a divisor of the pacesetter
Huihong Luo1768cb02022-10-11 11:10:34 -0700308 // display's refresh rate. Only supported for virtual displays.
309 Fps mAdjustedRefreshRate = 0_Hz;
310
Kriti Dang4bc7cdf2021-01-08 11:49:56 +0100311 std::vector<ui::Hdr> mOverrideHdrTypes;
Ady Abraham3efa3942021-06-24 19:01:25 -0700312
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400313 std::shared_ptr<scheduler::RefreshRateSelector> mRefreshRateSelector;
Ady Abraham1b11bc62021-06-03 19:51:19 -0700314 std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay;
Sally Qi147581b2023-06-27 11:55:34 -0700315 std::unique_ptr<HdrSdrRatioOverlay> mHdrSdrRatioOverlay;
316 // This parameter is only used for hdr/sdr ratio overlay
317 float mHdrSdrRatio = 1.0f;
Ady Abraham690f4612021-07-01 23:24:03 -0700318
Dominik Laskowski59746512023-11-19 09:30:24 -0500319 mutable std::mutex mDesiredModeLock;
320 ActiveModeInfo mDesiredMode GUARDED_BY(mDesiredModeLock);
321 TracedOrdinal<bool> mDesiredModeChanged GUARDED_BY(mDesiredModeLock);
Dominik Laskowskifdac5652023-06-29 12:01:13 -0400322
Dominik Laskowski59746512023-11-19 09:30:24 -0500323 ActiveModeInfo mPendingMode GUARDED_BY(kMainThreadContext);
Dominik Laskowskifdac5652023-06-29 12:01:13 -0400324 bool mIsModeSetPending GUARDED_BY(kMainThreadContext) = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800325};
326
Irvelffc9efc2016-07-27 15:16:37 -0700327struct DisplayDeviceState {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800328 struct Physical {
Marin Shalamanova524a092020-07-27 21:39:55 +0200329 PhysicalDisplayId id;
Peiyong Lin65248e02020-04-18 21:15:07 -0700330 hardware::graphics::composer::hal::HWDisplayId hwcDisplayId;
Marin Shalamanova903d032020-12-29 20:35:13 +0100331 DisplayModePtr activeMode;
332
Dominik Laskowski55c85402020-01-21 16:25:47 -0800333 bool operator==(const Physical& other) const {
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700334 return id == other.id && hwcDisplayId == other.hwcDisplayId;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800335 }
336 };
337
338 bool isVirtual() const { return !physical; }
Irvelffc9efc2016-07-27 15:16:37 -0700339
Dominik Laskowski663bd282018-04-19 15:26:54 -0700340 int32_t sequenceId = sNextSequenceId++;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800341 std::optional<Physical> physical;
Irvelffc9efc2016-07-27 15:16:37 -0700342 sp<IGraphicBufferProducer> surface;
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700343 ui::LayerStack layerStack;
Evan Rosky2239b372021-05-20 13:43:47 -0700344 uint32_t flags = 0;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200345 Rect layerStackSpaceRect;
346 Rect orientedDisplaySpaceRect;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800347 ui::Rotation orientation = ui::ROTATION_0;
Irvelffc9efc2016-07-27 15:16:37 -0700348 uint32_t width = 0;
349 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700350 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700351 bool isSecure = false;
Huihong Luo1768cb02022-10-11 11:10:34 -0700352 // Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only
353 Fps requestedRefreshRate;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700354
355private:
356 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700357};
358
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700359struct DisplayDeviceCreationArgs {
360 // We use a constructor to ensure some of the values are set, without
361 // assuming a default value.
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100362 DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, HWComposer& hwComposer,
363 const wp<IBinder>& displayToken,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700364 std::shared_ptr<compositionengine::Display>);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700365 const sp<SurfaceFlinger> flinger;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100366 HWComposer& hwComposer;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700367 const wp<IBinder> displayToken;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700368 const std::shared_ptr<compositionengine::Display> compositionDisplay;
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400369 std::shared_ptr<scheduler::RefreshRateSelector> refreshRateSelector;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700370
Dominik Laskowskie9774092018-12-11 10:04:24 -0800371 int32_t sequenceId{0};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700372 bool isSecure{false};
373 sp<ANativeWindow> nativeWindow;
Lloyd Pique542307f2018-10-19 13:24:08 -0700374 sp<compositionengine::DisplaySurface> displaySurface;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800375 ui::Rotation physicalOrientation{ui::ROTATION_0};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700376 bool hasWideColorGamut{false};
377 HdrCapabilities hdrCapabilities;
378 int32_t supportedPerFrameMetadata{0};
379 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
linpeter1c69cd32022-07-13 19:20:48 +0800380 std::optional<hardware::graphics::composer::hal::PowerMode> initialPowerMode;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700381 bool isPrimary{false};
Ady Abraham3efa3942021-06-24 19:01:25 -0700382 DisplayModeId activeModeId;
Huihong Luo1768cb02022-10-11 11:10:34 -0700383 // Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only
384 Fps requestedRefreshRate;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700385};
386
Dominik Laskowski718f9602019-11-09 20:01:35 -0800387} // namespace android