blob: a3fa701be26a3b7f55ce7a8ec68f670338d0f5c4 [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>
Dominik Laskowski075d3172018-05-24 15:50:06 -070020#include <optional>
Peiyong Linefefaac2018-08-17 12:27:51 -070021#include <string>
Peiyong Lin136fbbc2018-04-17 15:09:44 -070022#include <unordered_map>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023
Dominik Laskowski298b08e2022-02-15 13:45:02 -080024#include <android-base/thread_annotations.h>
Alec Mourif6fd29e2018-11-17 04:56:41 +000025#include <android/native_window.h>
Dan Stoza9e56aa02015-11-02 13:00:03 -080026#include <binder/IBinder.h>
Leon Scroggins III4c2bed72023-02-07 11:51:02 -050027#include <ftl/concat.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"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054namespace android {
55
Dan Stoza9e56aa02015-11-02 13:00:03 -080056class Fence;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070057class HWComposer;
Sally Qi147581b2023-06-27 11:55:34 -070058class HdrSdrRatioOverlay;
Jesse Hall9e663de2013-08-16 14:28:37 -070059class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080060class Layer;
Ady Abraham1b11bc62021-06-03 19:51:19 -070061class RefreshRateOverlay;
Mathias Agopian86303202012-07-24 22:46:10 -070062class SurfaceFlinger;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070063
David Sodmanfb95bcc2017-12-22 15:45:30 -080064struct CompositionInfo;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070065struct DisplayDeviceCreationArgs;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066
Lloyd Pique45a165a2018-10-19 11:54:47 -070067namespace compositionengine {
68class Display;
Lloyd Pique542307f2018-10-19 13:24:08 -070069class DisplaySurface;
Lloyd Pique45a165a2018-10-19 11:54:47 -070070} // namespace compositionengine
71
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070072namespace display {
73class DisplaySnapshot;
74} // namespace display
75
Marin Shalamanov1c434292020-06-12 01:47:29 +020076class DisplayDevice : public RefBase {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077public:
Peiyong Linfb069302018-04-25 14:34:31 -070078 constexpr static float sDefaultMinLumiance = 0.0;
79 constexpr static float sDefaultMaxLumiance = 500.0;
Evan Rosky2239b372021-05-20 13:43:47 -070080 enum { eReceivesInput = 0x01 };
Peiyong Linfb069302018-04-25 14:34:31 -070081
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070082 explicit DisplayDevice(DisplayDeviceCreationArgs& args);
Marin Shalamanov1c434292020-06-12 01:47:29 +020083
84 // Must be destroyed on the main thread because it may call into HWComposer.
Lloyd Pique45a165a2018-10-19 11:54:47 -070085 virtual ~DisplayDevice();
86
87 std::shared_ptr<compositionengine::Display> getCompositionDisplay() const {
88 return mCompositionDisplay;
89 }
Mathias Agopian92a979a2012-08-02 18:32:23 -070090
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070091 bool isVirtual() const { return VirtualDisplayId::tryCast(getId()).has_value(); }
Dominik Laskowski075d3172018-05-24 15:50:06 -070092 bool isPrimary() const { return mIsPrimary; }
Mathias Agopian92a979a2012-08-02 18:32:23 -070093
Jamie Gennisdd3cb842012-10-19 18:19:11 -070094 // isSecure indicates whether this display can be trusted to display
95 // secure surfaces.
Lloyd Pique45a165a2018-10-19 11:54:47 -070096 bool isSecure() const;
Jamie Gennisdd3cb842012-10-19 18:19:11 -070097
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080098 int getWidth() const;
99 int getHeight() const;
100 ui::Size getSize() const { return {getWidth(), getHeight()}; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -0700101
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700102 void setLayerFilter(ui::LayerFilter);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800103 void setDisplaySize(int width, int height);
Dominik Laskowski718f9602019-11-09 20:01:35 -0800104 void setProjection(ui::Rotation orientation, Rect viewport, Rect frame);
Dominik Laskowski298b08e2022-02-15 13:45:02 -0800105 void stageBrightness(float brightness) REQUIRES(kMainThreadContext);
106 void persistBrightness(bool needsComposite) REQUIRES(kMainThreadContext);
107 bool isBrightnessStale() const REQUIRES(kMainThreadContext);
Evan Rosky2239b372021-05-20 13:43:47 -0700108 void setFlags(uint32_t flags);
Dominik Laskowski718f9602019-11-09 20:01:35 -0800109
110 ui::Rotation getPhysicalOrientation() const { return mPhysicalOrientation; }
111 ui::Rotation getOrientation() const { return mOrientation; }
112
Dominik Laskowski298b08e2022-02-15 13:45:02 -0800113 std::optional<float> getStagedBrightness() const REQUIRES(kMainThreadContext);
Garfield Tan54edd912020-10-21 16:31:41 -0700114 ui::Transform::RotationFlags getTransformHint() const;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700115 const ui::Transform& getTransform() const;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200116 const Rect& getLayerStackSpaceRect() const;
117 const Rect& getOrientedDisplaySpaceRect() const;
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800118 ui::LayerStack getLayerStack() const;
Evan Rosky2239b372021-05-20 13:43:47 -0700119 bool receivesInput() const { return mFlags & eReceivesInput; }
Dominik Laskowski075d3172018-05-24 15:50:06 -0700120
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800121 DisplayId getId() const;
122
123 // Shorthand to upcast the ID of a display whose type is known as a precondition.
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200124 PhysicalDisplayId getPhysicalId() const {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800125 const auto id = PhysicalDisplayId::tryCast(getId());
126 LOG_FATAL_IF(!id);
127 return *id;
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200128 }
129
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800130 VirtualDisplayId getVirtualId() const {
131 const auto id = VirtualDisplayId::tryCast(getId());
132 LOG_FATAL_IF(!id);
133 return *id;
134 }
135
Dominik Laskowski075d3172018-05-24 15:50:06 -0700136 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Dominik Laskowskie9774092018-12-11 10:04:24 -0800137 int32_t getSequenceId() const { return mSequenceId; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700138
Lloyd Pique32cbe282018-10-19 13:09:22 -0700139 const Region& getUndefinedRegion() const;
140
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700141 int32_t getSupportedPerFrameMetadata() const;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700142
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700143 bool hasWideColorGamut() const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700144 // Whether h/w composer has native support for specific HDR type.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700145 bool hasHDR10PlusSupport() const;
146 bool hasHDR10Support() const;
147 bool hasHLGSupport() const;
148 bool hasDolbyVisionSupport() const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700149
Kriti Dang4bc7cdf2021-01-08 11:49:56 +0100150 void overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes);
151
Peiyong Linfb069302018-04-25 14:34:31 -0700152 // The returned HdrCapabilities is the combination of HDR capabilities from
153 // hardware composer and RenderEngine. When the DisplayDevice supports wide
154 // color gamut, RenderEngine is able to simulate HDR support in Display P3
155 // color space for both PQ and HLG HDR contents. The minimum and maximum
156 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
157 // respectively if hardware composer doesn't return meaningful values.
Kriti Dang4bc7cdf2021-01-08 11:49:56 +0100158 HdrCapabilities getHdrCapabilities() const;
Jesse Hall38efe862013-04-06 23:12:29 -0700159
Chia-I Wube02ec02018-05-18 10:59:36 -0700160 // Return true if intent is supported by the display.
161 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700162
Angel Aguayob108a6d2021-08-06 21:34:57 +0000163 const Rect getBounds() const;
164 const Rect bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700166 void setDisplayName(const std::string& displayName);
167 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700168
Vishnu Nairaf6d2972022-11-18 06:26:38 +0000169 surfaceflinger::frontend::DisplayInfo getFrontEndInfo() const;
Prabir Pradhan48f8cb92021-08-26 14:05:36 -0700170
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700171 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700172 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700173 */
linpeter1c69cd32022-07-13 19:20:48 +0800174 std::optional<hardware::graphics::composer::hal::PowerMode> getPowerMode() const;
Peiyong Lin65248e02020-04-18 21:15:07 -0700175 void setPowerMode(hardware::graphics::composer::hal::PowerMode mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700176 bool isPoweredOn() const;
Ady Abraham66452722023-03-14 17:41:47 -0700177 void tracePowerMode();
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700178
Alec Mouridd8bf2d2021-05-08 16:36:33 -0700179 // Enables layer caching on this DisplayDevice
180 void enableLayerCaching(bool enable);
181
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800182 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700183
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700184 /* ------------------------------------------------------------------------
Marin Shalamanov5801c942020-12-17 17:00:13 +0100185 * Display mode management.
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700186 */
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400187
188 // TODO(b/241285876): Replace ActiveModeInfo and DisplayModeEvent with DisplayModeRequest.
Ady Abraham690f4612021-07-01 23:24:03 -0700189 struct ActiveModeInfo {
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400190 using Event = scheduler::DisplayModeEvent;
191
192 ActiveModeInfo() = default;
Ady Abrahamace3d052022-11-17 16:25:05 -0800193 ActiveModeInfo(scheduler::FrameRateMode mode, Event event)
194 : modeOpt(std::move(mode)), event(event) {}
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400195
196 explicit ActiveModeInfo(display::DisplayModeRequest&& request)
Ady Abrahamace3d052022-11-17 16:25:05 -0800197 : ActiveModeInfo(std::move(request.mode),
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400198 request.emitEvent ? Event::Changed : Event::None) {}
199
Ady Abrahamace3d052022-11-17 16:25:05 -0800200 ftl::Optional<scheduler::FrameRateMode> modeOpt;
Dominik Laskowski530d6bd2022-10-10 16:55:54 -0400201 Event event = Event::None;
Ady Abraham690f4612021-07-01 23:24:03 -0700202
203 bool operator!=(const ActiveModeInfo& other) const {
Ady Abrahamace3d052022-11-17 16:25:05 -0800204 return modeOpt != other.modeOpt || event != other.event;
Ady Abraham690f4612021-07-01 23:24:03 -0700205 }
206 };
207
Ady Abrahamace3d052022-11-17 16:25:05 -0800208 enum class DesiredActiveModeAction {
209 None,
210 InitiateDisplayModeSwitch,
211 InitiateRenderRateSwitch
212 };
Dominik Laskowskifc378b02022-12-02 14:56:05 -0500213 DesiredActiveModeAction setDesiredActiveMode(const ActiveModeInfo&, bool force = false)
214 EXCLUDES(mActiveModeLock);
Ady Abraham690f4612021-07-01 23:24:03 -0700215 std::optional<ActiveModeInfo> getDesiredActiveMode() const EXCLUDES(mActiveModeLock);
216 void clearDesiredActiveModeState() EXCLUDES(mActiveModeLock);
Dominik Laskowski298b08e2022-02-15 13:45:02 -0800217 ActiveModeInfo getUpcomingActiveMode() const REQUIRES(kMainThreadContext) {
Ady Abraham690f4612021-07-01 23:24:03 -0700218 return mUpcomingActiveMode;
219 }
220
Dominik Laskowskifdac5652023-06-29 12:01:13 -0400221 bool isModeSetPending() const REQUIRES(kMainThreadContext) { return mIsModeSetPending; }
222
Ady Abrahamace3d052022-11-17 16:25:05 -0800223 scheduler::FrameRateMode getActiveMode() const REQUIRES(kMainThreadContext) {
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400224 return mRefreshRateSelector->getActiveMode();
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700225 }
226
Ady Abrahamace3d052022-11-17 16:25:05 -0800227 void setActiveMode(DisplayModeId, Fps displayFps, Fps renderFps);
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700228
Ady Abraham690f4612021-07-01 23:24:03 -0700229 status_t initiateModeChange(const ActiveModeInfo&,
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100230 const hal::VsyncPeriodChangeConstraints& constraints,
Ady Abraham690f4612021-07-01 23:24:03 -0700231 hal::VsyncPeriodChangeTimeline* outTimeline)
Dominik Laskowski298b08e2022-02-15 13:45:02 -0800232 REQUIRES(kMainThreadContext);
Marin Shalamanov5801c942020-12-17 17:00:13 +0100233
Dominik Laskowskifdac5652023-06-29 12:01:13 -0400234 void finalizeModeChange(DisplayModeId, Fps displayFps, Fps renderFps)
235 REQUIRES(kMainThreadContext);
236
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400237 scheduler::RefreshRateSelector& refreshRateSelector() const { return *mRefreshRateSelector; }
Ady Abraham3efa3942021-06-24 19:01:25 -0700238
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400239 // Extends the lifetime of the RefreshRateSelector, so it can outlive this DisplayDevice.
240 std::shared_ptr<scheduler::RefreshRateSelector> holdRefreshRateSelector() const {
241 return mRefreshRateSelector;
Ady Abraham3efa3942021-06-24 19:01:25 -0700242 }
243
Sally Qi147581b2023-06-27 11:55:34 -0700244 void animateOverlay();
245
Ady Abraham1b11bc62021-06-03 19:51:19 -0700246 // Enables an overlay to be displayed with the current refresh rate
Lloyd Pique30db6402023-06-26 18:56:51 +0000247 void enableRefreshRateOverlay(bool enable, bool setByHwc, bool showSpinner, bool showRenderRate,
248 bool showInMiddle) REQUIRES(kMainThreadContext);
ramindanib2158ee2023-02-13 20:29:59 -0800249 void updateRefreshRateOverlayRate(Fps displayFps, Fps renderFps, bool setByHwc = false);
Ady Abraham1b11bc62021-06-03 19:51:19 -0700250 bool isRefreshRateOverlayEnabled() const { return mRefreshRateOverlay != nullptr; }
251 bool onKernelTimerChanged(std::optional<DisplayModeId>, bool timerExpired);
Sally Qi147581b2023-06-27 11:55:34 -0700252
253 // Enables an overlay to be display with the hdr/sdr ratio
254 void enableHdrSdrRatioOverlay(bool enable) REQUIRES(kMainThreadContext);
255 void updateHdrSdrRatioOverlayRatio(float currentHdrSdrRatio);
256 bool isHdrSdrRatioOverlayEnabled() const { return mHdrSdrRatioOverlay != nullptr; }
Ady Abraham1b11bc62021-06-03 19:51:19 -0700257
Marin Shalamanov045b7002021-01-07 16:56:24 +0100258 nsecs_t getVsyncPeriodFromHWC() const;
Marin Shalamanov045b7002021-01-07 16:56:24 +0100259
Huihong Luo1768cb02022-10-11 11:10:34 -0700260 Fps getAdjustedRefreshRate() const { return mAdjustedRefreshRate; }
261
Leon Scroggins III1af0fb62023-03-02 14:21:44 -0500262 // Round the requested refresh rate to match a divisor of the pacesetter
Huihong Luo1768cb02022-10-11 11:10:34 -0700263 // display's refresh rate. Only supported for virtual displays.
Leon Scroggins III1af0fb62023-03-02 14:21:44 -0500264 void adjustRefreshRate(Fps pacesetterDisplayRefreshRate);
Huihong Luo1768cb02022-10-11 11:10:34 -0700265
Jesse Hall02d86562013-03-25 14:43:23 -0700266 // release HWC resources (if any) for removable displays
Lloyd Pique45a165a2018-10-19 11:54:47 -0700267 void disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700268
Dominik Laskowskie70461a2022-08-30 14:42:01 -0700269 void dump(utils::Dumper&) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700270
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800271private:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700272 const sp<SurfaceFlinger> mFlinger;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100273 HWComposer& mHwComposer;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700274 const wp<IBinder> mDisplayToken;
Dominik Laskowskie9774092018-12-11 10:04:24 -0800275 const int32_t mSequenceId;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700276
Lloyd Pique45a165a2018-10-19 11:54:47 -0700277 const std::shared_ptr<compositionengine::Display> mCompositionDisplay;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700278
Lloyd Pique31cb2942018-10-19 17:23:03 -0700279 std::string mDisplayName;
Ady Abraham690f4612021-07-01 23:24:03 -0700280 std::string mActiveModeFPSTrace;
281 std::string mActiveModeFPSHwcTrace;
Ady Abrahamace3d052022-11-17 16:25:05 -0800282 std::string mRenderFrameRateFPSTrace;
Mathias Agopian03e40722012-04-26 16:11:59 -0700283
Dominik Laskowski718f9602019-11-09 20:01:35 -0800284 const ui::Rotation mPhysicalOrientation;
285 ui::Rotation mOrientation = ui::ROTATION_0;
Sally Qi147581b2023-06-27 11:55:34 -0700286 bool mIsOrientationChanged = false;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700287
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700288 // Allow nullopt as initial power mode.
Ady Abraham66452722023-03-14 17:41:47 -0700289 using TracedPowerMode = TracedOrdinal<hardware::graphics::composer::hal::PowerMode>;
290 std::optional<TracedPowerMode> mPowerMode;
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700291
292 std::optional<float> mStagedBrightness;
linpeterdcfd4e62022-12-29 09:39:14 +0800293 std::optional<float> mBrightness;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600294
Dominik Laskowskif8db0f02021-04-19 11:05:25 -0700295 // TODO(b/182939859): Remove special cases for primary display.
Dominik Laskowski075d3172018-05-24 15:50:06 -0700296 const bool mIsPrimary;
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200297
Evan Rosky2239b372021-05-20 13:43:47 -0700298 uint32_t mFlags = 0;
299
Huihong Luo1768cb02022-10-11 11:10:34 -0700300 // Requested refresh rate in fps, supported only for virtual displays.
301 // when this value is non zero, SurfaceFlinger will try to drop frames
302 // for virtual displays to match this requested refresh rate.
303 const Fps mRequestedRefreshRate;
304
Leon Scroggins III1af0fb62023-03-02 14:21:44 -0500305 // Adjusted refresh rate, rounded to match a divisor of the pacesetter
Huihong Luo1768cb02022-10-11 11:10:34 -0700306 // display's refresh rate. Only supported for virtual displays.
307 Fps mAdjustedRefreshRate = 0_Hz;
308
Kriti Dang4bc7cdf2021-01-08 11:49:56 +0100309 std::vector<ui::Hdr> mOverrideHdrTypes;
Ady Abraham3efa3942021-06-24 19:01:25 -0700310
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400311 std::shared_ptr<scheduler::RefreshRateSelector> mRefreshRateSelector;
Ady Abraham1b11bc62021-06-03 19:51:19 -0700312 std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay;
Sally Qi147581b2023-06-27 11:55:34 -0700313 std::unique_ptr<HdrSdrRatioOverlay> mHdrSdrRatioOverlay;
314 // This parameter is only used for hdr/sdr ratio overlay
315 float mHdrSdrRatio = 1.0f;
Ady Abraham690f4612021-07-01 23:24:03 -0700316
317 mutable std::mutex mActiveModeLock;
318 ActiveModeInfo mDesiredActiveMode GUARDED_BY(mActiveModeLock);
Leon Scroggins III4c2bed72023-02-07 11:51:02 -0500319 TracedOrdinal<bool> mDesiredActiveModeChanged GUARDED_BY(mActiveModeLock) =
320 {ftl::Concat("DesiredActiveModeChanged-", getId().value).c_str(), false};
Dominik Laskowskifdac5652023-06-29 12:01:13 -0400321
Dominik Laskowski298b08e2022-02-15 13:45:02 -0800322 ActiveModeInfo mUpcomingActiveMode GUARDED_BY(kMainThreadContext);
Dominik Laskowskifdac5652023-06-29 12:01:13 -0400323 bool mIsModeSetPending GUARDED_BY(kMainThreadContext) = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800324};
325
Irvelffc9efc2016-07-27 15:16:37 -0700326struct DisplayDeviceState {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800327 struct Physical {
Marin Shalamanova524a092020-07-27 21:39:55 +0200328 PhysicalDisplayId id;
Peiyong Lin65248e02020-04-18 21:15:07 -0700329 hardware::graphics::composer::hal::HWDisplayId hwcDisplayId;
Marin Shalamanova903d032020-12-29 20:35:13 +0100330 DisplayModePtr activeMode;
331
Dominik Laskowski55c85402020-01-21 16:25:47 -0800332 bool operator==(const Physical& other) const {
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700333 return id == other.id && hwcDisplayId == other.hwcDisplayId;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800334 }
335 };
336
337 bool isVirtual() const { return !physical; }
Irvelffc9efc2016-07-27 15:16:37 -0700338
Dominik Laskowski663bd282018-04-19 15:26:54 -0700339 int32_t sequenceId = sNextSequenceId++;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800340 std::optional<Physical> physical;
Irvelffc9efc2016-07-27 15:16:37 -0700341 sp<IGraphicBufferProducer> surface;
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700342 ui::LayerStack layerStack;
Evan Rosky2239b372021-05-20 13:43:47 -0700343 uint32_t flags = 0;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200344 Rect layerStackSpaceRect;
345 Rect orientedDisplaySpaceRect;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800346 ui::Rotation orientation = ui::ROTATION_0;
Irvelffc9efc2016-07-27 15:16:37 -0700347 uint32_t width = 0;
348 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700349 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700350 bool isSecure = false;
Huihong Luo1768cb02022-10-11 11:10:34 -0700351 // Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only
352 Fps requestedRefreshRate;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700353
354private:
355 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700356};
357
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700358struct DisplayDeviceCreationArgs {
359 // We use a constructor to ensure some of the values are set, without
360 // assuming a default value.
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100361 DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, HWComposer& hwComposer,
362 const wp<IBinder>& displayToken,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700363 std::shared_ptr<compositionengine::Display>);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700364 const sp<SurfaceFlinger> flinger;
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100365 HWComposer& hwComposer;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700366 const wp<IBinder> displayToken;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700367 const std::shared_ptr<compositionengine::Display> compositionDisplay;
Dominik Laskowskid82e0f02022-10-26 15:23:04 -0400368 std::shared_ptr<scheduler::RefreshRateSelector> refreshRateSelector;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700369
Dominik Laskowskie9774092018-12-11 10:04:24 -0800370 int32_t sequenceId{0};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700371 bool isSecure{false};
372 sp<ANativeWindow> nativeWindow;
Lloyd Pique542307f2018-10-19 13:24:08 -0700373 sp<compositionengine::DisplaySurface> displaySurface;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800374 ui::Rotation physicalOrientation{ui::ROTATION_0};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700375 bool hasWideColorGamut{false};
376 HdrCapabilities hdrCapabilities;
377 int32_t supportedPerFrameMetadata{0};
378 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
linpeter1c69cd32022-07-13 19:20:48 +0800379 std::optional<hardware::graphics::composer::hal::PowerMode> initialPowerMode;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700380 bool isPrimary{false};
Ady Abraham3efa3942021-06-24 19:01:25 -0700381 DisplayModeId activeModeId;
Huihong Luo1768cb02022-10-11 11:10:34 -0700382 // Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only
383 Fps requestedRefreshRate;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700384};
385
Dominik Laskowski718f9602019-11-09 20:01:35 -0800386} // namespace android