| 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> | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 20 | #include <optional> | 
| Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 21 | #include <string> | 
| Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 22 | #include <unordered_map> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 |  | 
| 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> | 
| Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 26 | #include <gui/LayerState.h> | 
| Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 27 | #include <math/mat4.h> | 
| Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 28 | #include <renderengine/RenderEngine.h> | 
| Alec Mouri | f6fd29e | 2018-11-17 04:56:41 +0000 | [diff] [blame] | 29 | #include <system/window.h> | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 30 | #include <ui/DisplayId.h> | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 31 | #include <ui/DisplayState.h> | 
| Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 32 | #include <ui/GraphicTypes.h> | 
| Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 33 | #include <ui/HdrCapabilities.h> | 
| Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 34 | #include <ui/Region.h> | 
| Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 35 | #include <ui/StaticDisplayInfo.h> | 
| Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 36 | #include <ui/Transform.h> | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 37 | #include <utils/Errors.h> | 
| Alec Mouri | 8d4f90a | 2018-11-14 22:33:24 +0000 | [diff] [blame] | 38 | #include <utils/Mutex.h> | 
| Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 39 | #include <utils/RefBase.h> | 
| Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 40 | #include <utils/Timers.h> | 
|  | 41 |  | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 42 | #include "MainThreadGuard.h" | 
|  | 43 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 44 | #include "DisplayHardware/DisplayIdentification.h" | 
| Marin Shalamanov | 23c4420 | 2020-12-22 19:09:20 +0100 | [diff] [blame] | 45 | #include "DisplayHardware/DisplayMode.h" | 
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 46 | #include "DisplayHardware/Hal.h" | 
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 47 | #include "DisplayHardware/PowerAdvisor.h" | 
| Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 48 |  | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 49 | #include "Scheduler/RefreshRateConfigs.h" | 
|  | 50 |  | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 51 | #include "TracedOrdinal.h" | 
|  | 52 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | namespace android { | 
|  | 54 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 55 | class Fence; | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 56 | class HWComposer; | 
| Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 57 | class IGraphicBufferProducer; | 
| Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 58 | class Layer; | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 59 | class RefreshRateOverlay; | 
| Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 60 | class SurfaceFlinger; | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 61 |  | 
| David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 62 | struct CompositionInfo; | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 63 | struct DisplayDeviceCreationArgs; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 |  | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 65 | namespace compositionengine { | 
|  | 66 | class Display; | 
| Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 67 | class DisplaySurface; | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 68 | } // namespace compositionengine | 
|  | 69 |  | 
| Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 70 | class DisplayDevice : public RefBase { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | public: | 
| Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 72 | constexpr static float sDefaultMinLumiance = 0.0; | 
|  | 73 | constexpr static float sDefaultMaxLumiance = 500.0; | 
| Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 74 | enum { eReceivesInput = 0x01 }; | 
| Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 75 |  | 
| Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 76 | explicit DisplayDevice(DisplayDeviceCreationArgs& args); | 
| Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 77 |  | 
|  | 78 | // 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] | 79 | virtual ~DisplayDevice(); | 
|  | 80 |  | 
|  | 81 | std::shared_ptr<compositionengine::Display> getCompositionDisplay() const { | 
|  | 82 | return mCompositionDisplay; | 
|  | 83 | } | 
| Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 84 |  | 
| Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 85 | std::optional<ui::DisplayConnectionType> getConnectionType() const { return mConnectionType; } | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 86 |  | 
|  | 87 | bool isVirtual() const { return !mConnectionType; } | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 88 | bool isPrimary() const { return mIsPrimary; } | 
| Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 89 | bool isInternal() const { return mConnectionType == ui::DisplayConnectionType::Internal; } | 
| Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 90 |  | 
| Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 91 | // isSecure indicates whether this display can be trusted to display | 
|  | 92 | // secure surfaces. | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 93 | bool isSecure() const; | 
| Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 94 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 95 | int getWidth() const; | 
|  | 96 | int getHeight() const; | 
|  | 97 | ui::Size getSize() const { return {getWidth(), getHeight()}; } | 
| Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 98 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 99 | void setLayerStack(ui::LayerStack); | 
|  | 100 | void setDisplaySize(int width, int height); | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 101 | void setProjection(ui::Rotation orientation, Rect viewport, Rect frame); | 
| Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 102 | void stageBrightness(float brightness) REQUIRES(SF_MAIN_THREAD); | 
|  | 103 | void persistBrightness(bool needsComposite) REQUIRES(SF_MAIN_THREAD); | 
|  | 104 | bool isBrightnessStale() const REQUIRES(SF_MAIN_THREAD); | 
| Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 105 | void setFlags(uint32_t flags); | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 106 |  | 
|  | 107 | ui::Rotation getPhysicalOrientation() const { return mPhysicalOrientation; } | 
|  | 108 | ui::Rotation getOrientation() const { return mOrientation; } | 
|  | 109 |  | 
|  | 110 | static ui::Transform::RotationFlags getPrimaryDisplayRotationFlags(); | 
|  | 111 |  | 
| Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 112 | std::optional<float> getStagedBrightness() const REQUIRES(SF_MAIN_THREAD); | 
| Garfield Tan | 54edd91 | 2020-10-21 16:31:41 -0700 | [diff] [blame] | 113 | ui::Transform::RotationFlags getTransformHint() const; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 114 | const ui::Transform& getTransform() const; | 
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 115 | const Rect& getLayerStackSpaceRect() const; | 
|  | 116 | const Rect& getOrientedDisplaySpaceRect() const; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 117 | bool needsFiltering() const; | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 118 | ui::LayerStack getLayerStack() const; | 
| Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 119 | bool receivesInput() const { return mFlags & eReceivesInput; } | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 120 |  | 
| Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 121 | DisplayId getId() const; | 
|  | 122 |  | 
|  | 123 | // 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] | 124 | PhysicalDisplayId getPhysicalId() const { | 
| Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 125 | const auto id = PhysicalDisplayId::tryCast(getId()); | 
|  | 126 | LOG_FATAL_IF(!id); | 
|  | 127 | return *id; | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 128 | } | 
|  | 129 |  | 
| Dominik Laskowski | 3dce4f4 | 2021-03-08 20:48:28 -0800 | [diff] [blame] | 130 | VirtualDisplayId getVirtualId() const { | 
|  | 131 | const auto id = VirtualDisplayId::tryCast(getId()); | 
|  | 132 | LOG_FATAL_IF(!id); | 
|  | 133 | return *id; | 
|  | 134 | } | 
|  | 135 |  | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 136 | const wp<IBinder>& getDisplayToken() const { return mDisplayToken; } | 
| Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 137 | int32_t getSequenceId() const { return mSequenceId; } | 
| Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 138 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 139 | const Region& getUndefinedRegion() const; | 
|  | 140 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 141 | int32_t getSupportedPerFrameMetadata() const; | 
| Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 142 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 143 | bool hasWideColorGamut() const; | 
| Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 144 | // Whether h/w composer has native support for specific HDR type. | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 145 | bool hasHDR10PlusSupport() const; | 
|  | 146 | bool hasHDR10Support() const; | 
|  | 147 | bool hasHLGSupport() const; | 
|  | 148 | bool hasDolbyVisionSupport() const; | 
| Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 149 |  | 
| Kriti Dang | 4bc7cdf | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 150 | void overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes); | 
|  | 151 |  | 
| Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 152 | // 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 Dang | 4bc7cdf | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 158 | HdrCapabilities getHdrCapabilities() const; | 
| Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 159 |  | 
| Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 160 | // Return true if intent is supported by the display. | 
|  | 161 | bool hasRenderIntent(ui::RenderIntent intent) const; | 
| Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 162 |  | 
| Angel Aguayo | b108a6d | 2021-08-06 21:34:57 +0000 | [diff] [blame] | 163 | const Rect getBounds() const; | 
|  | 164 | const Rect bounds() const { return getBounds(); } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 |  | 
| Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 166 | void setDisplayName(const std::string& displayName); | 
|  | 167 | const std::string& getDisplayName() const { return mDisplayName; } | 
| Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 168 |  | 
| Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 169 | void setDeviceProductInfo(std::optional<DeviceProductInfo> info); | 
|  | 170 | const std::optional<DeviceProductInfo>& getDeviceProductInfo() const { | 
|  | 171 | return mDeviceProductInfo; | 
|  | 172 | } | 
|  | 173 |  | 
| Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 174 | // Get the DisplayInfo that will be sent to InputFlinger, and the display transform that should | 
|  | 175 | // be applied to all the input windows on the display. | 
|  | 176 | std::pair<gui::DisplayInfo, ui::Transform> getInputInfo() const; | 
|  | 177 |  | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 178 | /* ------------------------------------------------------------------------ | 
| Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 179 | * Display power mode management. | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 180 | */ | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 181 | hardware::graphics::composer::hal::PowerMode getPowerMode() const; | 
|  | 182 | void setPowerMode(hardware::graphics::composer::hal::PowerMode mode); | 
| Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 183 | bool isPoweredOn() const; | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 184 |  | 
| Alec Mouri | dd8bf2d | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 185 | // Enables layer caching on this DisplayDevice | 
|  | 186 | void enableLayerCaching(bool enable); | 
|  | 187 |  | 
| Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 188 | ui::Dataspace getCompositionDataSpace() const; | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 189 |  | 
| Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 190 | /* ------------------------------------------------------------------------ | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 191 | * Display mode management. | 
| Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 192 | */ | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 193 | const DisplayModePtr& getActiveMode() const; | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 194 |  | 
|  | 195 | struct ActiveModeInfo { | 
|  | 196 | DisplayModePtr mode; | 
| Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 197 | scheduler::DisplayModeEvent event = scheduler::DisplayModeEvent::None; | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 198 |  | 
|  | 199 | bool operator!=(const ActiveModeInfo& other) const { | 
|  | 200 | return mode != other.mode || event != other.event; | 
|  | 201 | } | 
|  | 202 | }; | 
|  | 203 |  | 
|  | 204 | bool setDesiredActiveMode(const ActiveModeInfo&) EXCLUDES(mActiveModeLock); | 
|  | 205 | std::optional<ActiveModeInfo> getDesiredActiveMode() const EXCLUDES(mActiveModeLock); | 
|  | 206 | void clearDesiredActiveModeState() EXCLUDES(mActiveModeLock); | 
|  | 207 | ActiveModeInfo getUpcomingActiveMode() const REQUIRES(SF_MAIN_THREAD) { | 
|  | 208 | return mUpcomingActiveMode; | 
|  | 209 | } | 
|  | 210 |  | 
|  | 211 | void setActiveMode(DisplayModeId) REQUIRES(SF_MAIN_THREAD); | 
|  | 212 | status_t initiateModeChange(const ActiveModeInfo&, | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 213 | const hal::VsyncPeriodChangeConstraints& constraints, | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 214 | hal::VsyncPeriodChangeTimeline* outTimeline) | 
|  | 215 | REQUIRES(SF_MAIN_THREAD); | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 216 |  | 
|  | 217 | // Return the immutable list of supported display modes. The HWC may report different modes | 
|  | 218 | // after a hotplug reconnect event, in which case the DisplayDevice object will be recreated. | 
|  | 219 | // Hotplug reconnects are common for external displays. | 
|  | 220 | const DisplayModes& getSupportedModes() const; | 
|  | 221 |  | 
|  | 222 | // Returns nullptr if the given mode ID is not supported. A previously | 
|  | 223 | // supported mode may be no longer supported for some devices like TVs and | 
|  | 224 | // set-top boxes after a hotplug reconnect. | 
|  | 225 | DisplayModePtr getMode(DisplayModeId) const; | 
| Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 226 |  | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 227 | // Returns the refresh rate configs for this display. | 
|  | 228 | scheduler::RefreshRateConfigs& refreshRateConfigs() const { return *mRefreshRateConfigs; } | 
|  | 229 |  | 
|  | 230 | // Returns a shared pointer to the refresh rate configs for this display. | 
|  | 231 | // Clients can store this refresh rate configs and use it even if the DisplayDevice | 
|  | 232 | // is destroyed. | 
|  | 233 | std::shared_ptr<scheduler::RefreshRateConfigs> holdRefreshRateConfigs() const { | 
|  | 234 | return mRefreshRateConfigs; | 
|  | 235 | } | 
|  | 236 |  | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 237 | // Enables an overlay to be displayed with the current refresh rate | 
|  | 238 | void enableRefreshRateOverlay(bool enable, bool showSpinner); | 
|  | 239 | bool isRefreshRateOverlayEnabled() const { return mRefreshRateOverlay != nullptr; } | 
|  | 240 | bool onKernelTimerChanged(std::optional<DisplayModeId>, bool timerExpired); | 
| Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 241 | void animateRefreshRateOverlay(); | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 242 |  | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 243 | void onVsync(nsecs_t timestamp); | 
|  | 244 | nsecs_t getVsyncPeriodFromHWC() const; | 
|  | 245 | nsecs_t getRefreshTimestamp() const; | 
|  | 246 |  | 
| Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 247 | // release HWC resources (if any) for removable displays | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 248 | void disconnect(); | 
| Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 249 |  | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 250 | /* ------------------------------------------------------------------------ | 
|  | 251 | * Debugging | 
|  | 252 | */ | 
|  | 253 | uint32_t getPageFlipCount() const; | 
| Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 254 | std::string getDebugName() const; | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 255 | void dump(std::string& result) const; | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 256 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | private: | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 258 | const sp<SurfaceFlinger> mFlinger; | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 259 | HWComposer& mHwComposer; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 260 | const wp<IBinder> mDisplayToken; | 
| Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 261 | const int32_t mSequenceId; | 
| Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 262 | const std::optional<ui::DisplayConnectionType> mConnectionType; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 263 |  | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 264 | const std::shared_ptr<compositionengine::Display> mCompositionDisplay; | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 265 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 266 | std::string mDisplayName; | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 267 | std::string mActiveModeFPSTrace; | 
|  | 268 | std::string mActiveModeFPSHwcTrace; | 
| Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 269 |  | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 270 | const ui::Rotation mPhysicalOrientation; | 
|  | 271 | ui::Rotation mOrientation = ui::ROTATION_0; | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 272 |  | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 273 | static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags; | 
| Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 274 |  | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 275 | hardware::graphics::composer::hal::PowerMode mPowerMode = | 
|  | 276 | hardware::graphics::composer::hal::PowerMode::OFF; | 
| Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 277 | DisplayModePtr mActiveMode; | 
| Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 278 | std::optional<float> mStagedBrightness = std::nullopt; | 
|  | 279 | float mBrightness = -1.f; | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 280 | const DisplayModes mSupportedModes; | 
| Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 281 |  | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 282 | std::atomic<nsecs_t> mLastHwVsync = 0; | 
|  | 283 |  | 
| Dominik Laskowski | f8db0f0 | 2021-04-19 11:05:25 -0700 | [diff] [blame] | 284 | // TODO(b/182939859): Remove special cases for primary display. | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 285 | const bool mIsPrimary; | 
| Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 286 |  | 
| Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 287 | uint32_t mFlags = 0; | 
|  | 288 |  | 
| Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 289 | std::optional<DeviceProductInfo> mDeviceProductInfo; | 
| Kriti Dang | 4bc7cdf | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 290 |  | 
|  | 291 | std::vector<ui::Hdr> mOverrideHdrTypes; | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 292 |  | 
|  | 293 | std::shared_ptr<scheduler::RefreshRateConfigs> mRefreshRateConfigs; | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 294 | std::unique_ptr<RefreshRateOverlay> mRefreshRateOverlay; | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 295 |  | 
|  | 296 | mutable std::mutex mActiveModeLock; | 
|  | 297 | ActiveModeInfo mDesiredActiveMode GUARDED_BY(mActiveModeLock); | 
|  | 298 | TracedOrdinal<bool> mDesiredActiveModeChanged | 
|  | 299 | GUARDED_BY(mActiveModeLock) = {"DesiredActiveModeChanged", false}; | 
|  | 300 | ActiveModeInfo mUpcomingActiveMode GUARDED_BY(SF_MAIN_THREAD); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | }; | 
|  | 302 |  | 
| Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 303 | struct DisplayDeviceState { | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 304 | struct Physical { | 
| Marin Shalamanov | a524a09 | 2020-07-27 21:39:55 +0200 | [diff] [blame] | 305 | PhysicalDisplayId id; | 
| Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 306 | ui::DisplayConnectionType type; | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 307 | hardware::graphics::composer::hal::HWDisplayId hwcDisplayId; | 
| Marin Shalamanov | 7ce8764 | 2020-05-06 13:45:58 +0200 | [diff] [blame] | 308 | std::optional<DeviceProductInfo> deviceProductInfo; | 
| Marin Shalamanov | a903d03 | 2020-12-29 20:35:13 +0100 | [diff] [blame] | 309 | DisplayModes supportedModes; | 
|  | 310 | DisplayModePtr activeMode; | 
|  | 311 |  | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 312 | bool operator==(const Physical& other) const { | 
| Marin Shalamanov | 4a42d43 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 313 | return id == other.id && type == other.type && hwcDisplayId == other.hwcDisplayId; | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 314 | } | 
|  | 315 | }; | 
|  | 316 |  | 
|  | 317 | bool isVirtual() const { return !physical; } | 
| Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 318 |  | 
| Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 319 | int32_t sequenceId = sNextSequenceId++; | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 320 | std::optional<Physical> physical; | 
| Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 321 | sp<IGraphicBufferProducer> surface; | 
| Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 322 | ui::LayerStack layerStack; | 
| Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 323 | uint32_t flags = 0; | 
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 324 | Rect layerStackSpaceRect; | 
|  | 325 | Rect orientedDisplaySpaceRect; | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 326 | ui::Rotation orientation = ui::ROTATION_0; | 
| Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 327 | uint32_t width = 0; | 
|  | 328 | uint32_t height = 0; | 
| Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 329 | std::string displayName; | 
| Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 330 | bool isSecure = false; | 
| Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 331 |  | 
|  | 332 | private: | 
|  | 333 | static std::atomic<int32_t> sNextSequenceId; | 
| Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 334 | }; | 
|  | 335 |  | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 336 | struct DisplayDeviceCreationArgs { | 
|  | 337 | // We use a constructor to ensure some of the values are set, without | 
|  | 338 | // assuming a default value. | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 339 | DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, HWComposer& hwComposer, | 
|  | 340 | const wp<IBinder>& displayToken, | 
| Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 341 | std::shared_ptr<compositionengine::Display>); | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 342 | const sp<SurfaceFlinger> flinger; | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 343 | HWComposer& hwComposer; | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 344 | const wp<IBinder> displayToken; | 
| Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 345 | const std::shared_ptr<compositionengine::Display> compositionDisplay; | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 346 | std::shared_ptr<scheduler::RefreshRateConfigs> refreshRateConfigs; | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 347 |  | 
| Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 348 | int32_t sequenceId{0}; | 
| Marin Shalamanov | 228f46b | 2021-01-28 21:11:45 +0100 | [diff] [blame] | 349 | std::optional<ui::DisplayConnectionType> connectionType; | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 350 | bool isSecure{false}; | 
|  | 351 | sp<ANativeWindow> nativeWindow; | 
| Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 352 | sp<compositionengine::DisplaySurface> displaySurface; | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 353 | ui::Rotation physicalOrientation{ui::ROTATION_0}; | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 354 | bool hasWideColorGamut{false}; | 
|  | 355 | HdrCapabilities hdrCapabilities; | 
|  | 356 | int32_t supportedPerFrameMetadata{0}; | 
|  | 357 | std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes; | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 358 | hardware::graphics::composer::hal::PowerMode initialPowerMode{ | 
|  | 359 | hardware::graphics::composer::hal::PowerMode::ON}; | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 360 | bool isPrimary{false}; | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 361 | DisplayModes supportedModes; | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 362 | DisplayModeId activeModeId; | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 363 | }; | 
|  | 364 |  | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 365 | } // namespace android |