The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 17 | #pragma once |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 19 | #include <memory> |
| 20 | #include <string> |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 21 | #include <unordered_map> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 23 | #include <android-base/thread_annotations.h> |
Alec Mouri | f6fd29e | 2018-11-17 04:56:41 +0000 | [diff] [blame] | 24 | #include <android/native_window.h> |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 25 | #include <binder/IBinder.h> |
Leon Scroggins III | 4c2bed7 | 2023-02-07 11:51:02 -0500 | [diff] [blame] | 26 | #include <ftl/concat.h> |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 27 | #include <ftl/optional.h> |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 28 | #include <gui/LayerState.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 29 | #include <math/mat4.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 30 | #include <renderengine/RenderEngine.h> |
Alec Mouri | f6fd29e | 2018-11-17 04:56:41 +0000 | [diff] [blame] | 31 | #include <system/window.h> |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 32 | #include <ui/DisplayId.h> |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 33 | #include <ui/DisplayIdentification.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 34 | #include <ui/DisplayState.h> |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 35 | #include <ui/GraphicTypes.h> |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 36 | #include <ui/HdrCapabilities.h> |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 37 | #include <ui/Region.h> |
Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 38 | #include <ui/StaticDisplayInfo.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 39 | #include <ui/Transform.h> |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 40 | #include <utils/Errors.h> |
Alec Mouri | 8d4f90a | 2018-11-14 22:33:24 +0000 | [diff] [blame] | 41 | #include <utils/Mutex.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 42 | #include <utils/RefBase.h> |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 43 | #include <utils/Timers.h> |
| 44 | |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 45 | #include "Display/DisplayModeRequest.h" |
Marin Shalamanov | 23c4420 | 2020-12-22 19:09:20 +0100 | [diff] [blame] | 46 | #include "DisplayHardware/DisplayMode.h" |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 47 | #include "DisplayHardware/Hal.h" |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 48 | #include "DisplayHardware/PowerAdvisor.h" |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 49 | #include "FrontEnd/DisplayInfo.h" |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 50 | #include "Scheduler/RefreshRateSelector.h" |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 51 | #include "ThreadContext.h" |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 52 | #include "TracedOrdinal.h" |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 53 | #include "Utils/Dumper.h" |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 54 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | namespace android { |
| 56 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 57 | class Fence; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 58 | class HWComposer; |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 59 | class HdrSdrRatioOverlay; |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 60 | class IGraphicBufferProducer; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 61 | class Layer; |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 62 | class RefreshRateOverlay; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 63 | class SurfaceFlinger; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 64 | |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 65 | struct CompositionInfo; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 66 | struct DisplayDeviceCreationArgs; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 68 | namespace compositionengine { |
| 69 | class Display; |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 70 | class DisplaySurface; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 71 | } // namespace compositionengine |
| 72 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 73 | namespace display { |
| 74 | class DisplaySnapshot; |
| 75 | } // namespace display |
| 76 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 77 | class DisplayDevice : public RefBase { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | public: |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 79 | constexpr static float sDefaultMinLumiance = 0.0; |
| 80 | constexpr static float sDefaultMaxLumiance = 500.0; |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 81 | enum { eReceivesInput = 0x01 }; |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 82 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 83 | explicit DisplayDevice(DisplayDeviceCreationArgs& args); |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 84 | |
| 85 | // Must be destroyed on the main thread because it may call into HWComposer. |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 86 | virtual ~DisplayDevice(); |
| 87 | |
| 88 | std::shared_ptr<compositionengine::Display> getCompositionDisplay() const { |
| 89 | return mCompositionDisplay; |
| 90 | } |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 91 | |
Alan Ding | c9de92a | 2024-05-24 00:27:11 -0700 | [diff] [blame^] | 92 | bool isVirtual() const { return getId().isVirtual(); } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 93 | bool isPrimary() const { return mIsPrimary; } |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 94 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 95 | // isSecure indicates whether this display can be trusted to display |
| 96 | // secure surfaces. |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 97 | bool isSecure() const; |
Huihong Luo | 9ebb7a7 | 2023-06-27 17:01:50 -0700 | [diff] [blame] | 98 | void setSecure(bool secure); |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 99 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 100 | int getWidth() const; |
| 101 | int getHeight() const; |
| 102 | ui::Size getSize() const { return {getWidth(), getHeight()}; } |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 103 | |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 104 | void setLayerFilter(ui::LayerFilter); |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 105 | void setDisplaySize(int width, int height); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 106 | void setProjection(ui::Rotation orientation, Rect viewport, Rect frame); |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 107 | void stageBrightness(float brightness) REQUIRES(kMainThreadContext); |
| 108 | void persistBrightness(bool needsComposite) REQUIRES(kMainThreadContext); |
| 109 | bool isBrightnessStale() const REQUIRES(kMainThreadContext); |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 110 | void setFlags(uint32_t flags); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 111 | |
| 112 | ui::Rotation getPhysicalOrientation() const { return mPhysicalOrientation; } |
| 113 | ui::Rotation getOrientation() const { return mOrientation; } |
| 114 | |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 115 | std::optional<float> getStagedBrightness() const REQUIRES(kMainThreadContext); |
Garfield Tan | 54edd91 | 2020-10-21 16:31:41 -0700 | [diff] [blame] | 116 | ui::Transform::RotationFlags getTransformHint() const; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 117 | const ui::Transform& getTransform() const; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 118 | const Rect& getLayerStackSpaceRect() const; |
| 119 | const Rect& getOrientedDisplaySpaceRect() const; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 120 | ui::LayerStack getLayerStack() const; |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 121 | bool receivesInput() const { return mFlags & eReceivesInput; } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 122 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 123 | DisplayId getId() const; |
| 124 | |
| 125 | // Shorthand to upcast the ID of a display whose type is known as a precondition. |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 126 | PhysicalDisplayId getPhysicalId() const { |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 127 | const auto id = PhysicalDisplayId::tryCast(getId()); |
| 128 | LOG_FATAL_IF(!id); |
| 129 | return *id; |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 130 | } |
| 131 | |
Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 132 | VirtualDisplayId getVirtualId() const { |
| 133 | const auto id = VirtualDisplayId::tryCast(getId()); |
| 134 | LOG_FATAL_IF(!id); |
| 135 | return *id; |
| 136 | } |
| 137 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 138 | const wp<IBinder>& getDisplayToken() const { return mDisplayToken; } |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 139 | int32_t getSequenceId() const { return mSequenceId; } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 140 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 141 | const Region& getUndefinedRegion() const; |
| 142 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 143 | int32_t getSupportedPerFrameMetadata() const; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 144 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 145 | bool hasWideColorGamut() const; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 146 | // Whether h/w composer has native support for specific HDR type. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 147 | bool hasHDR10PlusSupport() const; |
| 148 | bool hasHDR10Support() const; |
| 149 | bool hasHLGSupport() const; |
| 150 | bool hasDolbyVisionSupport() const; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 151 | |
Kriti Dang | 4bc7cdf | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 152 | void overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes); |
| 153 | |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 154 | // The returned HdrCapabilities is the combination of HDR capabilities from |
| 155 | // hardware composer and RenderEngine. When the DisplayDevice supports wide |
| 156 | // color gamut, RenderEngine is able to simulate HDR support in Display P3 |
| 157 | // color space for both PQ and HLG HDR contents. The minimum and maximum |
| 158 | // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance |
| 159 | // respectively if hardware composer doesn't return meaningful values. |
Kriti Dang | 4bc7cdf | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 160 | HdrCapabilities getHdrCapabilities() const; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 161 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 162 | // Return true if intent is supported by the display. |
| 163 | bool hasRenderIntent(ui::RenderIntent intent) const; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 164 | |
Angel Aguayo | b108a6d | 2021-08-06 21:34:57 +0000 | [diff] [blame] | 165 | const Rect getBounds() const; |
| 166 | const Rect bounds() const { return getBounds(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 168 | void setDisplayName(const std::string& displayName); |
| 169 | const std::string& getDisplayName() const { return mDisplayName; } |
Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 170 | |
Vishnu Nair | af6d297 | 2022-11-18 06:26:38 +0000 | [diff] [blame] | 171 | surfaceflinger::frontend::DisplayInfo getFrontEndInfo() const; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 172 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 173 | /* ------------------------------------------------------------------------ |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 174 | * Display power mode management. |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 175 | */ |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 176 | hardware::graphics::composer::hal::PowerMode getPowerMode() const; |
| 177 | void setPowerMode(hardware::graphics::composer::hal::PowerMode); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 178 | bool isPoweredOn() const; |
Ady Abraham | 6645272 | 2023-03-14 17:41:47 -0700 | [diff] [blame] | 179 | void tracePowerMode(); |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 180 | |
Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 181 | // Enables layer caching on this DisplayDevice |
| 182 | void enableLayerCaching(bool enable); |
| 183 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 184 | ui::Dataspace getCompositionDataSpace() const; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 185 | |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 186 | /* ------------------------------------------------------------------------ |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 187 | * Display mode management. |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 188 | */ |
Dominik Laskowski | 530d6bd | 2022-10-10 16:55:54 -0400 | [diff] [blame] | 189 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 190 | enum class DesiredModeAction { None, InitiateDisplayModeSwitch, InitiateRenderRateSwitch }; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 191 | |
Dominik Laskowski | 8809687 | 2023-12-08 15:26:04 -0500 | [diff] [blame] | 192 | DesiredModeAction setDesiredMode(display::DisplayModeRequest&&) EXCLUDES(mDesiredModeLock); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 193 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 194 | using DisplayModeRequestOpt = ftl::Optional<display::DisplayModeRequest>; |
| 195 | |
| 196 | DisplayModeRequestOpt getDesiredMode() const EXCLUDES(mDesiredModeLock); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 197 | void clearDesiredMode() EXCLUDES(mDesiredModeLock); |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 198 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 199 | DisplayModeRequestOpt getPendingMode() const REQUIRES(kMainThreadContext) { |
| 200 | return mPendingModeOpt; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 201 | } |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 202 | bool isModeSetPending() const REQUIRES(kMainThreadContext) { return mIsModeSetPending; } |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 203 | |
Ady Abraham | ace3d05 | 2022-11-17 16:25:05 -0800 | [diff] [blame] | 204 | scheduler::FrameRateMode getActiveMode() const REQUIRES(kMainThreadContext) { |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 205 | return mRefreshRateSelector->getActiveMode(); |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 206 | } |
| 207 | |
ramindani | a04b8a5 | 2023-08-07 18:49:47 -0700 | [diff] [blame] | 208 | void setActiveMode(DisplayModeId, Fps vsyncRate, Fps renderFps); |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 209 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 210 | bool initiateModeChange(display::DisplayModeRequest&&, const hal::VsyncPeriodChangeConstraints&, |
Dominik Laskowski | 4b32e4b | 2023-11-19 10:24:51 -0500 | [diff] [blame] | 211 | hal::VsyncPeriodChangeTimeline& outTimeline) |
Dominik Laskowski | 298b08e | 2022-02-15 13:45:02 -0800 | [diff] [blame] | 212 | REQUIRES(kMainThreadContext); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 213 | |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 214 | void finalizeModeChange(DisplayModeId, Fps vsyncRate, Fps renderFps) |
| 215 | REQUIRES(kMainThreadContext); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 216 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 217 | scheduler::RefreshRateSelector& refreshRateSelector() const { return *mRefreshRateSelector; } |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 218 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 219 | // Extends the lifetime of the RefreshRateSelector, so it can outlive this DisplayDevice. |
| 220 | std::shared_ptr<scheduler::RefreshRateSelector> holdRefreshRateSelector() const { |
| 221 | return mRefreshRateSelector; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 224 | void animateOverlay(); |
| 225 | |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 226 | // Enables an overlay to be displayed with the current refresh rate |
Lloyd Pique | 30db640 | 2023-06-26 18:56:51 +0000 | [diff] [blame] | 227 | void enableRefreshRateOverlay(bool enable, bool setByHwc, bool showSpinner, bool showRenderRate, |
| 228 | bool showInMiddle) REQUIRES(kMainThreadContext); |
Ying Wei | 22d59cc | 2024-05-11 02:41:08 +0000 | [diff] [blame] | 229 | void updateRefreshRateOverlayRate(Fps refreshRate, Fps renderFps, bool setByHwc = false); |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 230 | bool isRefreshRateOverlayEnabled() const { return mRefreshRateOverlay != nullptr; } |
| 231 | bool onKernelTimerChanged(std::optional<DisplayModeId>, bool timerExpired); |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 232 | |
| 233 | // Enables an overlay to be display with the hdr/sdr ratio |
| 234 | void enableHdrSdrRatioOverlay(bool enable) REQUIRES(kMainThreadContext); |
| 235 | void updateHdrSdrRatioOverlayRatio(float currentHdrSdrRatio); |
| 236 | bool isHdrSdrRatioOverlayEnabled() const { return mHdrSdrRatioOverlay != nullptr; } |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 237 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 238 | nsecs_t getVsyncPeriodFromHWC() const; |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 239 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 240 | Fps getAdjustedRefreshRate() const { return mAdjustedRefreshRate; } |
| 241 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 242 | // Round the requested refresh rate to match a divisor of the pacesetter |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 243 | // display's refresh rate. Only supported for virtual displays. |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 244 | void adjustRefreshRate(Fps pacesetterDisplayRefreshRate); |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 245 | |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 246 | // release HWC resources (if any) for removable displays |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 247 | void disconnect(); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 248 | |
Dominik Laskowski | e70461a | 2022-08-30 14:42:01 -0700 | [diff] [blame] | 249 | void dump(utils::Dumper&) const; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 250 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | private: |
Dominik Laskowski | 0784adc | 2023-10-13 18:35:37 -0400 | [diff] [blame] | 252 | template <size_t N> |
| 253 | inline std::string concatId(const char (&str)[N]) const { |
| 254 | return std::string(ftl::Concat(str, ' ', getId().value).str()); |
| 255 | } |
| 256 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 257 | const sp<SurfaceFlinger> mFlinger; |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 258 | HWComposer& mHwComposer; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 259 | const wp<IBinder> mDisplayToken; |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 260 | const int32_t mSequenceId; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 261 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 262 | const std::shared_ptr<compositionengine::Display> mCompositionDisplay; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 263 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 264 | std::string mDisplayName; |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 265 | std::string mPendingModeFpsTrace; |
| 266 | std::string mActiveModeFpsTrace; |
| 267 | std::string mRenderRateFpsTrace; |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 268 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 269 | const ui::Rotation mPhysicalOrientation; |
| 270 | ui::Rotation mOrientation = ui::ROTATION_0; |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 271 | bool mIsOrientationChanged = false; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 272 | |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 273 | TracedOrdinal<hardware::graphics::composer::hal::PowerMode> mPowerMode; |
Dominik Laskowski | 02bb207 | 2022-08-26 15:02:52 -0700 | [diff] [blame] | 274 | |
| 275 | std::optional<float> mStagedBrightness; |
linpeter | dcfd4e6 | 2022-12-29 09:39:14 +0800 | [diff] [blame] | 276 | std::optional<float> mBrightness; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 277 | |
Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 278 | // TODO(b/182939859): Remove special cases for primary display. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 279 | const bool mIsPrimary; |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 280 | |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 281 | uint32_t mFlags = 0; |
| 282 | |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 283 | // Requested refresh rate in fps, supported only for virtual displays. |
| 284 | // when this value is non zero, SurfaceFlinger will try to drop frames |
| 285 | // for virtual displays to match this requested refresh rate. |
| 286 | const Fps mRequestedRefreshRate; |
| 287 | |
Leon Scroggins III | 1af0fb6 | 2023-03-02 14:21:44 -0500 | [diff] [blame] | 288 | // Adjusted refresh rate, rounded to match a divisor of the pacesetter |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 289 | // display's refresh rate. Only supported for virtual displays. |
| 290 | Fps mAdjustedRefreshRate = 0_Hz; |
| 291 | |
Kriti Dang | 4bc7cdf | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 292 | std::vector<ui::Hdr> mOverrideHdrTypes; |
Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 293 | |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 294 | std::shared_ptr<scheduler::RefreshRateSelector> mRefreshRateSelector; |
Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 295 | std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay; |
Sally Qi | 147581b | 2023-06-27 11:55:34 -0700 | [diff] [blame] | 296 | std::unique_ptr<HdrSdrRatioOverlay> mHdrSdrRatioOverlay; |
| 297 | // This parameter is only used for hdr/sdr ratio overlay |
| 298 | float mHdrSdrRatio = 1.0f; |
Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 299 | |
Dominik Laskowski | 5974651 | 2023-11-19 09:30:24 -0500 | [diff] [blame] | 300 | mutable std::mutex mDesiredModeLock; |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 301 | DisplayModeRequestOpt mDesiredModeOpt GUARDED_BY(mDesiredModeLock); |
| 302 | TracedOrdinal<bool> mHasDesiredModeTrace GUARDED_BY(mDesiredModeLock); |
Dominik Laskowski | fdac565 | 2023-06-29 12:01:13 -0400 | [diff] [blame] | 303 | |
Dominik Laskowski | 1ab20c5 | 2023-11-27 11:45:57 -0500 | [diff] [blame] | 304 | DisplayModeRequestOpt mPendingModeOpt GUARDED_BY(kMainThreadContext); |
Dominik Laskowski | 63abc2b | 2023-12-21 19:33:25 +0000 | [diff] [blame] | 305 | bool mIsModeSetPending GUARDED_BY(kMainThreadContext) = false; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | }; |
| 307 | |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 308 | struct DisplayDeviceState { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 309 | struct Physical { |
Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 310 | PhysicalDisplayId id; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 311 | hardware::graphics::composer::hal::HWDisplayId hwcDisplayId; |
Marin Shalamanov | a903d03 | 2020-12-29 20:35:13 +0100 | [diff] [blame] | 312 | DisplayModePtr activeMode; |
| 313 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 314 | bool operator==(const Physical& other) const { |
Dominik Laskowski | b363c4c | 2022-08-02 14:03:41 -0700 | [diff] [blame] | 315 | return id == other.id && hwcDisplayId == other.hwcDisplayId; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 316 | } |
| 317 | }; |
| 318 | |
| 319 | bool isVirtual() const { return !physical; } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 320 | |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 321 | int32_t sequenceId = sNextSequenceId++; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 322 | std::optional<Physical> physical; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 323 | sp<IGraphicBufferProducer> surface; |
Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 324 | ui::LayerStack layerStack; |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 325 | uint32_t flags = 0; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 326 | Rect layerStackSpaceRect; |
| 327 | Rect orientedDisplaySpaceRect; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 328 | ui::Rotation orientation = ui::ROTATION_0; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 329 | uint32_t width = 0; |
| 330 | uint32_t height = 0; |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 331 | std::string displayName; |
Alan Ding | fc6eab5 | 2024-05-02 18:28:45 -0700 | [diff] [blame] | 332 | std::string uniqueId; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 333 | bool isSecure = false; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 334 | bool isProtected = false; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 335 | // Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only |
| 336 | Fps requestedRefreshRate; |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 337 | |
| 338 | private: |
| 339 | static std::atomic<int32_t> sNextSequenceId; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 340 | }; |
| 341 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 342 | struct DisplayDeviceCreationArgs { |
| 343 | // We use a constructor to ensure some of the values are set, without |
| 344 | // assuming a default value. |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 345 | DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, HWComposer& hwComposer, |
| 346 | const wp<IBinder>& displayToken, |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 347 | std::shared_ptr<compositionengine::Display>); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 348 | const sp<SurfaceFlinger> flinger; |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 349 | HWComposer& hwComposer; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 350 | const wp<IBinder> displayToken; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 351 | const std::shared_ptr<compositionengine::Display> compositionDisplay; |
Dominik Laskowski | d82e0f0 | 2022-10-26 15:23:04 -0400 | [diff] [blame] | 352 | std::shared_ptr<scheduler::RefreshRateSelector> refreshRateSelector; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 353 | |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 354 | int32_t sequenceId{0}; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 355 | bool isSecure{false}; |
Chavi Weingarten | 18fa7c6 | 2023-11-28 21:16:03 +0000 | [diff] [blame] | 356 | bool isProtected{false}; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 357 | sp<ANativeWindow> nativeWindow; |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 358 | sp<compositionengine::DisplaySurface> displaySurface; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 359 | ui::Rotation physicalOrientation{ui::ROTATION_0}; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 360 | bool hasWideColorGamut{false}; |
| 361 | HdrCapabilities hdrCapabilities; |
| 362 | int32_t supportedPerFrameMetadata{0}; |
| 363 | std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes; |
Dominik Laskowski | a42d539 | 2022-09-29 14:26:53 -0400 | [diff] [blame] | 364 | hardware::graphics::composer::hal::PowerMode initialPowerMode{ |
| 365 | hardware::graphics::composer::hal::PowerMode::OFF}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 366 | bool isPrimary{false}; |
Huihong Luo | 1768cb0 | 2022-10-11 11:10:34 -0700 | [diff] [blame] | 367 | // Refer to DisplayDevice::mRequestedRefreshRate, for virtual display only |
| 368 | Fps requestedRefreshRate; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 369 | }; |
| 370 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 371 | } // namespace android |