blob: 1b661907f1e013844a2806e5a7d0b188d172705f [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
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>
Chia-I Wuf2aa3112018-08-27 14:54:37 -070026#include <gui/LayerState.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070027#include <math/mat4.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080028#include <renderengine/RenderEngine.h>
Alec Mourif6fd29e2018-11-17 04:56:41 +000029#include <system/window.h>
Dominik Laskowski55c85402020-01-21 16:25:47 -080030#include <ui/DisplayInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080031#include <ui/DisplayState.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070032#include <ui/GraphicTypes.h>
Peiyong Linfb069302018-04-25 14:34:31 -070033#include <ui/HdrCapabilities.h>
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -070034#include <ui/Region.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070035#include <ui/Transform.h>
Alec Mouri8d4f90a2018-11-14 22:33:24 +000036#include <utils/Mutex.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080037#include <utils/RefBase.h>
Mathias Agopian86303202012-07-24 22:46:10 -070038#include <utils/Timers.h>
39
Dominik Laskowski075d3172018-05-24 15:50:06 -070040#include "DisplayHardware/DisplayIdentification.h"
Peiyong Line9d809e2020-04-14 13:10:48 -070041#include "DisplayHardware/Hal.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080042#include "DisplayHardware/PowerAdvisor.h"
Ady Abraham2139f732019-11-13 18:56:40 -080043#include "Scheduler/HwcStrongTypes.h"
Mathias Agopianf4358632012-08-22 17:16:19 -070044
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045namespace android {
46
Dan Stoza9e56aa02015-11-02 13:00:03 -080047class Fence;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070048class HWComposer;
Jesse Hall9e663de2013-08-16 14:28:37 -070049class IGraphicBufferProducer;
Mathias Agopian13127d82013-03-05 17:47:11 -080050class Layer;
Mathias Agopian86303202012-07-24 22:46:10 -070051class SurfaceFlinger;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070052
David Sodmanfb95bcc2017-12-22 15:45:30 -080053struct CompositionInfo;
Lloyd Pique2eef1d22018-09-18 21:30:04 -070054struct DisplayDeviceCreationArgs;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055
Lloyd Pique45a165a2018-10-19 11:54:47 -070056namespace compositionengine {
57class Display;
Lloyd Pique542307f2018-10-19 13:24:08 -070058class DisplaySurface;
Lloyd Pique45a165a2018-10-19 11:54:47 -070059} // namespace compositionengine
60
Marin Shalamanov1c434292020-06-12 01:47:29 +020061class DisplayDevice : public RefBase {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062public:
Peiyong Linfb069302018-04-25 14:34:31 -070063 constexpr static float sDefaultMinLumiance = 0.0;
64 constexpr static float sDefaultMaxLumiance = 500.0;
65
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070066 explicit DisplayDevice(DisplayDeviceCreationArgs& args);
Marin Shalamanov1c434292020-06-12 01:47:29 +020067
68 // Must be destroyed on the main thread because it may call into HWComposer.
Lloyd Pique45a165a2018-10-19 11:54:47 -070069 virtual ~DisplayDevice();
70
71 std::shared_ptr<compositionengine::Display> getCompositionDisplay() const {
72 return mCompositionDisplay;
73 }
Mathias Agopian92a979a2012-08-02 18:32:23 -070074
Dominik Laskowski55c85402020-01-21 16:25:47 -080075 std::optional<DisplayConnectionType> getConnectionType() const { return mConnectionType; }
76
77 bool isVirtual() const { return !mConnectionType; }
Dominik Laskowski075d3172018-05-24 15:50:06 -070078 bool isPrimary() const { return mIsPrimary; }
Mathias Agopian92a979a2012-08-02 18:32:23 -070079
Jamie Gennisdd3cb842012-10-19 18:19:11 -070080 // isSecure indicates whether this display can be trusted to display
81 // secure surfaces.
Lloyd Pique45a165a2018-10-19 11:54:47 -070082 bool isSecure() const;
Jamie Gennisdd3cb842012-10-19 18:19:11 -070083
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080084 int getWidth() const;
85 int getHeight() const;
86 ui::Size getSize() const { return {getWidth(), getHeight()}; }
Mathias Agopian3eb38cb2012-04-03 22:09:52 -070087
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080088 void setLayerStack(ui::LayerStack);
89 void setDisplaySize(int width, int height);
Dominik Laskowski718f9602019-11-09 20:01:35 -080090 void setProjection(ui::Rotation orientation, Rect viewport, Rect frame);
91
92 ui::Rotation getPhysicalOrientation() const { return mPhysicalOrientation; }
93 ui::Rotation getOrientation() const { return mOrientation; }
94
95 static ui::Transform::RotationFlags getPrimaryDisplayRotationFlags();
96
Dominik Laskowskib7251f42020-04-20 17:42:59 -070097 ui::Transform::RotationFlags getTransformHint() const {
98 return static_cast<ui::Transform::RotationFlags>(getTransform().getOrientation());
99 }
100
Lloyd Pique32cbe282018-10-19 13:09:22 -0700101 const ui::Transform& getTransform() const;
102 const Rect& getViewport() const;
103 const Rect& getFrame() const;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700104 bool needsFiltering() const;
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800105 ui::LayerStack getLayerStack() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700106
Lloyd Pique45a165a2018-10-19 11:54:47 -0700107 const std::optional<DisplayId>& getId() const;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700108 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
Dominik Laskowskie9774092018-12-11 10:04:24 -0800109 int32_t getSequenceId() const { return mSequenceId; }
Mathias Agopian87baae12012-07-31 12:38:26 -0700110
Lloyd Pique32cbe282018-10-19 13:09:22 -0700111 const Region& getUndefinedRegion() const;
112
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700113 int32_t getSupportedPerFrameMetadata() const;
Peiyong Lin0ac5f4e2018-04-19 22:06:34 -0700114
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700115 bool hasWideColorGamut() const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700116 // Whether h/w composer has native support for specific HDR type.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700117 bool hasHDR10PlusSupport() const;
118 bool hasHDR10Support() const;
119 bool hasHLGSupport() const;
120 bool hasDolbyVisionSupport() const;
Chia-I Wube02ec02018-05-18 10:59:36 -0700121
Peiyong Linfb069302018-04-25 14:34:31 -0700122 // The returned HdrCapabilities is the combination of HDR capabilities from
123 // hardware composer and RenderEngine. When the DisplayDevice supports wide
124 // color gamut, RenderEngine is able to simulate HDR support in Display P3
125 // color space for both PQ and HLG HDR contents. The minimum and maximum
126 // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance
127 // respectively if hardware composer doesn't return meaningful values.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700128 const HdrCapabilities& getHdrCapabilities() const;
Jesse Hall38efe862013-04-06 23:12:29 -0700129
Chia-I Wube02ec02018-05-18 10:59:36 -0700130 // Return true if intent is supported by the display.
131 bool hasRenderIntent(ui::RenderIntent intent) const;
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700132
Lloyd Pique32cbe282018-10-19 13:09:22 -0700133 const Rect& getBounds() const;
134 const Rect& bounds() const { return getBounds(); }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700136 void setDisplayName(const std::string& displayName);
137 const std::string& getDisplayName() const { return mDisplayName; }
Andy McFadden8dfa92f2012-09-17 18:27:17 -0700138
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200139 void setDeviceProductInfo(std::optional<DeviceProductInfo> info);
140 const std::optional<DeviceProductInfo>& getDeviceProductInfo() const {
141 return mDeviceProductInfo;
142 }
143
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700144 /* ------------------------------------------------------------------------
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700145 * Display power mode management.
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700146 */
Peiyong Lin65248e02020-04-18 21:15:07 -0700147 hardware::graphics::composer::hal::PowerMode getPowerMode() const;
148 void setPowerMode(hardware::graphics::composer::hal::PowerMode mode);
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700149 bool isPoweredOn() const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700150
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800151 ui::Dataspace getCompositionDataSpace() const;
Michael Wright28f24d02016-07-12 13:30:53 -0700152
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700153 /* ------------------------------------------------------------------------
154 * Display active config management.
155 */
Ady Abraham2139f732019-11-13 18:56:40 -0800156 HwcConfigIndexType getActiveConfig() const;
157 void setActiveConfig(HwcConfigIndexType mode);
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700158
Jesse Hall02d86562013-03-25 14:43:23 -0700159 // release HWC resources (if any) for removable displays
Lloyd Pique45a165a2018-10-19 11:54:47 -0700160 void disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700161
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700162 /* ------------------------------------------------------------------------
163 * Debugging
164 */
165 uint32_t getPageFlipCount() const;
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700166 std::string getDebugName() const;
Yiwei Zhang5434a782018-12-05 18:06:32 -0800167 void dump(std::string& result) const;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700168
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800169private:
Dominik Laskowski075d3172018-05-24 15:50:06 -0700170 const sp<SurfaceFlinger> mFlinger;
171 const wp<IBinder> mDisplayToken;
Dominik Laskowskie9774092018-12-11 10:04:24 -0800172 const int32_t mSequenceId;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800173 const std::optional<DisplayConnectionType> mConnectionType;
Dominik Laskowski075d3172018-05-24 15:50:06 -0700174
Lloyd Pique45a165a2018-10-19 11:54:47 -0700175 const std::shared_ptr<compositionengine::Display> mCompositionDisplay;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700176
Lloyd Pique31cb2942018-10-19 17:23:03 -0700177 std::string mDisplayName;
Mathias Agopian03e40722012-04-26 16:11:59 -0700178
Dominik Laskowski718f9602019-11-09 20:01:35 -0800179 const ui::Rotation mPhysicalOrientation;
180 ui::Rotation mOrientation = ui::ROTATION_0;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700181
Dominik Laskowski718f9602019-11-09 20:01:35 -0800182 static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags;
Mathias Agopianda8d0a52012-09-04 15:05:38 -0700183
Peiyong Lin65248e02020-04-18 21:15:07 -0700184 hardware::graphics::composer::hal::PowerMode mPowerMode =
185 hardware::graphics::composer::hal::PowerMode::OFF;
Ady Abraham2139f732019-11-13 18:56:40 -0800186 HwcConfigIndexType mActiveConfig;
Courtney Goeltzenleuchter5d943892017-03-22 13:46:46 -0600187
Dominik Laskowski075d3172018-05-24 15:50:06 -0700188 // TODO(b/74619554): Remove special cases for primary display.
189 const bool mIsPrimary;
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200190
191 std::optional<DeviceProductInfo> mDeviceProductInfo;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800192};
193
Irvelffc9efc2016-07-27 15:16:37 -0700194struct DisplayDeviceState {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800195 struct Physical {
196 DisplayId id;
197 DisplayConnectionType type;
Peiyong Lin65248e02020-04-18 21:15:07 -0700198 hardware::graphics::composer::hal::HWDisplayId hwcDisplayId;
Marin Shalamanov7ce87642020-05-06 13:45:58 +0200199 std::optional<DeviceProductInfo> deviceProductInfo;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800200 bool operator==(const Physical& other) const {
Marin Shalamanov4a42d432020-02-12 20:22:26 +0100201 return id == other.id && type == other.type && hwcDisplayId == other.hwcDisplayId;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800202 }
203 };
204
205 bool isVirtual() const { return !physical; }
Irvelffc9efc2016-07-27 15:16:37 -0700206
Dominik Laskowski663bd282018-04-19 15:26:54 -0700207 int32_t sequenceId = sNextSequenceId++;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800208 std::optional<Physical> physical;
Irvelffc9efc2016-07-27 15:16:37 -0700209 sp<IGraphicBufferProducer> surface;
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800210 ui::LayerStack layerStack = ui::NO_LAYER_STACK;
Irvelffc9efc2016-07-27 15:16:37 -0700211 Rect viewport;
212 Rect frame;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800213 ui::Rotation orientation = ui::ROTATION_0;
Irvelffc9efc2016-07-27 15:16:37 -0700214 uint32_t width = 0;
215 uint32_t height = 0;
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700216 std::string displayName;
Irvelffc9efc2016-07-27 15:16:37 -0700217 bool isSecure = false;
Dominik Laskowski663bd282018-04-19 15:26:54 -0700218
219private:
220 static std::atomic<int32_t> sNextSequenceId;
Irvelffc9efc2016-07-27 15:16:37 -0700221};
222
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700223struct DisplayDeviceCreationArgs {
224 // We use a constructor to ensure some of the values are set, without
225 // assuming a default value.
Dominik Laskowski55c85402020-01-21 16:25:47 -0800226 DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, const wp<IBinder>& displayToken,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700227 std::shared_ptr<compositionengine::Display>);
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700228 const sp<SurfaceFlinger> flinger;
229 const wp<IBinder> displayToken;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700230 const std::shared_ptr<compositionengine::Display> compositionDisplay;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700231
Dominik Laskowskie9774092018-12-11 10:04:24 -0800232 int32_t sequenceId{0};
Dominik Laskowski55c85402020-01-21 16:25:47 -0800233 std::optional<DisplayConnectionType> connectionType;
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700234 bool isSecure{false};
235 sp<ANativeWindow> nativeWindow;
Lloyd Pique542307f2018-10-19 13:24:08 -0700236 sp<compositionengine::DisplaySurface> displaySurface;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800237 ui::Rotation physicalOrientation{ui::ROTATION_0};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700238 bool hasWideColorGamut{false};
239 HdrCapabilities hdrCapabilities;
240 int32_t supportedPerFrameMetadata{0};
241 std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes;
Peiyong Lin65248e02020-04-18 21:15:07 -0700242 hardware::graphics::composer::hal::PowerMode initialPowerMode{
243 hardware::graphics::composer::hal::PowerMode::ON};
Dominik Laskowski075d3172018-05-24 15:50:06 -0700244 bool isPrimary{false};
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700245};
246
Dominik Laskowski718f9602019-11-09 20:01:35 -0800247} // namespace android