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 | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 27 | #include <hardware/hwcomposer_defs.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 28 | #include <math/mat4.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 29 | #include <renderengine/RenderEngine.h> |
Alec Mouri | f6fd29e | 2018-11-17 04:56:41 +0000 | [diff] [blame] | 30 | #include <system/window.h> |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 31 | #include <ui/DisplayInfo.h> |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 32 | #include <ui/DisplayState.h> |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 33 | #include <ui/GraphicTypes.h> |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 34 | #include <ui/HdrCapabilities.h> |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 35 | #include <ui/Region.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 36 | #include <ui/Transform.h> |
Alec Mouri | 8d4f90a | 2018-11-14 22:33:24 +0000 | [diff] [blame] | 37 | #include <utils/Mutex.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 38 | #include <utils/RefBase.h> |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 39 | #include <utils/Timers.h> |
| 40 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 41 | #include "DisplayHardware/DisplayIdentification.h" |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 42 | #include "DisplayHardware/PowerAdvisor.h" |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 43 | #include "RenderArea.h" |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 44 | #include "Scheduler/HwcStrongTypes.h" |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 45 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | namespace android { |
| 47 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 48 | class Fence; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 49 | class HWComposer; |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 50 | class IGraphicBufferProducer; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 51 | class Layer; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 52 | class SurfaceFlinger; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 53 | |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 54 | struct CompositionInfo; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 55 | struct DisplayDeviceCreationArgs; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 57 | namespace compositionengine { |
| 58 | class Display; |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 59 | class DisplaySurface; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 60 | } // namespace compositionengine |
| 61 | |
| 62 | class DisplayDevice : public LightRefBase<DisplayDevice> { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | public: |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 64 | constexpr static float sDefaultMinLumiance = 0.0; |
| 65 | constexpr static float sDefaultMaxLumiance = 500.0; |
| 66 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 67 | explicit DisplayDevice(DisplayDeviceCreationArgs& args); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 68 | virtual ~DisplayDevice(); |
| 69 | |
| 70 | std::shared_ptr<compositionengine::Display> getCompositionDisplay() const { |
| 71 | return mCompositionDisplay; |
| 72 | } |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 73 | |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 74 | std::optional<DisplayConnectionType> getConnectionType() const { return mConnectionType; } |
| 75 | |
| 76 | bool isVirtual() const { return !mConnectionType; } |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 77 | bool isPrimary() const { return mIsPrimary; } |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 78 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 79 | // isSecure indicates whether this display can be trusted to display |
| 80 | // secure surfaces. |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 81 | bool isSecure() const; |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 82 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 83 | int getWidth() const; |
| 84 | int getHeight() const; |
| 85 | ui::Size getSize() const { return {getWidth(), getHeight()}; } |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 86 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 87 | void setLayerStack(ui::LayerStack); |
| 88 | void setDisplaySize(int width, int height); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 89 | void setProjection(ui::Rotation orientation, Rect viewport, Rect frame); |
| 90 | |
| 91 | ui::Rotation getPhysicalOrientation() const { return mPhysicalOrientation; } |
| 92 | ui::Rotation getOrientation() const { return mOrientation; } |
| 93 | |
| 94 | static ui::Transform::RotationFlags getPrimaryDisplayRotationFlags(); |
| 95 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 96 | const ui::Transform& getTransform() const; |
| 97 | const Rect& getViewport() const; |
| 98 | const Rect& getFrame() const; |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 99 | const Rect& getSourceClip() const; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 100 | bool needsFiltering() const; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 101 | ui::LayerStack getLayerStack() const; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 102 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 103 | const std::optional<DisplayId>& getId() const; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 104 | const wp<IBinder>& getDisplayToken() const { return mDisplayToken; } |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 105 | int32_t getSequenceId() const { return mSequenceId; } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 106 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 107 | const Region& getUndefinedRegion() const; |
| 108 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 109 | int32_t getSupportedPerFrameMetadata() const; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 110 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 111 | bool hasWideColorGamut() const; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 112 | // Whether h/w composer has native support for specific HDR type. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 113 | bool hasHDR10PlusSupport() const; |
| 114 | bool hasHDR10Support() const; |
| 115 | bool hasHLGSupport() const; |
| 116 | bool hasDolbyVisionSupport() const; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 117 | |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 118 | // The returned HdrCapabilities is the combination of HDR capabilities from |
| 119 | // hardware composer and RenderEngine. When the DisplayDevice supports wide |
| 120 | // color gamut, RenderEngine is able to simulate HDR support in Display P3 |
| 121 | // color space for both PQ and HLG HDR contents. The minimum and maximum |
| 122 | // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance |
| 123 | // respectively if hardware composer doesn't return meaningful values. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 124 | const HdrCapabilities& getHdrCapabilities() const; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 125 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 126 | // Return true if intent is supported by the display. |
| 127 | bool hasRenderIntent(ui::RenderIntent intent) const; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 128 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 129 | const Rect& getBounds() const; |
| 130 | const Rect& bounds() const { return getBounds(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 132 | void setDisplayName(const std::string& displayName); |
| 133 | const std::string& getDisplayName() const { return mDisplayName; } |
Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 134 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 135 | /* ------------------------------------------------------------------------ |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 136 | * Display power mode management. |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 137 | */ |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 138 | int getPowerMode() const; |
| 139 | void setPowerMode(int mode); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 140 | bool isPoweredOn() const; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 141 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 142 | ui::Dataspace getCompositionDataSpace() const; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 143 | |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 144 | /* ------------------------------------------------------------------------ |
| 145 | * Display active config management. |
| 146 | */ |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 147 | HwcConfigIndexType getActiveConfig() const; |
| 148 | void setActiveConfig(HwcConfigIndexType mode); |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 149 | |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 150 | // release HWC resources (if any) for removable displays |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 151 | void disconnect(); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 152 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 153 | /* ------------------------------------------------------------------------ |
| 154 | * Debugging |
| 155 | */ |
| 156 | uint32_t getPageFlipCount() const; |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 157 | std::string getDebugName() const; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 158 | void dump(std::string& result) const; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 159 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | private: |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 161 | const sp<SurfaceFlinger> mFlinger; |
| 162 | const wp<IBinder> mDisplayToken; |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 163 | const int32_t mSequenceId; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 164 | const std::optional<DisplayConnectionType> mConnectionType; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 165 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 166 | const std::shared_ptr<compositionengine::Display> mCompositionDisplay; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 167 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 168 | std::string mDisplayName; |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 169 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 170 | const ui::Rotation mPhysicalOrientation; |
| 171 | ui::Rotation mOrientation = ui::ROTATION_0; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 172 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 173 | static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags; |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 174 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 175 | int mPowerMode = HWC_POWER_MODE_OFF; |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 176 | HwcConfigIndexType mActiveConfig; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 177 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 178 | // TODO(b/74619554): Remove special cases for primary display. |
| 179 | const bool mIsPrimary; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | }; |
| 181 | |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 182 | struct DisplayDeviceState { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 183 | struct Physical { |
| 184 | DisplayId id; |
| 185 | DisplayConnectionType type; |
| 186 | |
| 187 | bool operator==(const Physical& other) const { |
| 188 | return id == other.id && type == other.type; |
| 189 | } |
| 190 | }; |
| 191 | |
| 192 | bool isVirtual() const { return !physical; } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 193 | |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 194 | int32_t sequenceId = sNextSequenceId++; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 195 | std::optional<Physical> physical; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 196 | sp<IGraphicBufferProducer> surface; |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 197 | ui::LayerStack layerStack = ui::NO_LAYER_STACK; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 198 | Rect viewport; |
| 199 | Rect frame; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 200 | ui::Rotation orientation = ui::ROTATION_0; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 201 | uint32_t width = 0; |
| 202 | uint32_t height = 0; |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 203 | std::string displayName; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 204 | bool isSecure = false; |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 205 | |
| 206 | private: |
| 207 | static std::atomic<int32_t> sNextSequenceId; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 210 | struct DisplayDeviceCreationArgs { |
| 211 | // We use a constructor to ensure some of the values are set, without |
| 212 | // assuming a default value. |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 213 | DisplayDeviceCreationArgs(const sp<SurfaceFlinger>&, const wp<IBinder>& displayToken, |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 214 | std::shared_ptr<compositionengine::Display>); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 215 | const sp<SurfaceFlinger> flinger; |
| 216 | const wp<IBinder> displayToken; |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 217 | const std::shared_ptr<compositionengine::Display> compositionDisplay; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 218 | |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 219 | int32_t sequenceId{0}; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 220 | std::optional<DisplayConnectionType> connectionType; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 221 | bool isSecure{false}; |
| 222 | sp<ANativeWindow> nativeWindow; |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 223 | sp<compositionengine::DisplaySurface> displaySurface; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 224 | ui::Rotation physicalOrientation{ui::ROTATION_0}; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 225 | bool hasWideColorGamut{false}; |
| 226 | HdrCapabilities hdrCapabilities; |
| 227 | int32_t supportedPerFrameMetadata{0}; |
| 228 | std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes; |
| 229 | int initialPowerMode{HWC_POWER_MODE_NORMAL}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 230 | bool isPrimary{false}; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 233 | class DisplayRenderArea : public RenderArea { |
| 234 | public: |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 235 | DisplayRenderArea(const sp<const DisplayDevice>& display, |
| 236 | RotationFlags rotation = ui::Transform::ROT_0) |
Ady Abraham | 8a82ba6 | 2020-01-17 12:43:17 -0800 | [diff] [blame] | 237 | : DisplayRenderArea(display, display->getBounds(), |
| 238 | static_cast<uint32_t>(display->getWidth()), |
| 239 | static_cast<uint32_t>(display->getHeight()), |
| 240 | display->getCompositionDataSpace(), rotation) {} |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 241 | |
| 242 | DisplayRenderArea(sp<const DisplayDevice> display, const Rect& sourceCrop, uint32_t reqWidth, |
| 243 | uint32_t reqHeight, ui::Dataspace reqDataSpace, RotationFlags rotation, |
| 244 | bool allowSecureLayers = true) |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 245 | : RenderArea(reqWidth, reqHeight, CaptureFill::OPAQUE, reqDataSpace, |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 246 | display->getViewport(), |
| 247 | applyInversePhysicalOrientation(rotation, |
| 248 | display->getPhysicalOrientation())), |
| 249 | mDisplay(std::move(display)), |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 250 | mSourceCrop(sourceCrop), |
| 251 | mAllowSecureLayers(allowSecureLayers) {} |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 252 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 253 | const ui::Transform& getTransform() const override { return mDisplay->getTransform(); } |
| 254 | Rect getBounds() const override { return mDisplay->getBounds(); } |
| 255 | int getHeight() const override { return mDisplay->getHeight(); } |
| 256 | int getWidth() const override { return mDisplay->getWidth(); } |
| 257 | bool isSecure() const override { return mAllowSecureLayers && mDisplay->isSecure(); } |
| 258 | sp<const DisplayDevice> getDisplayDevice() const override { return mDisplay; } |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 259 | |
| 260 | bool needsFiltering() const override { |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 261 | // check if the projection from the logical display to the physical |
| 262 | // display needs filtering |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 263 | if (mDisplay->needsFiltering()) { |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 264 | return true; |
| 265 | } |
| 266 | |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 267 | // check if the projection from the logical render area (i.e., the |
| 268 | // physical display) to the physical render area requires filtering |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 269 | const Rect sourceCrop = getSourceCrop(); |
| 270 | int width = sourceCrop.width(); |
| 271 | int height = sourceCrop.height(); |
| 272 | if (getRotationFlags() & ui::Transform::ROT_90) { |
| 273 | std::swap(width, height); |
| 274 | } |
| 275 | return width != getReqWidth() || height != getReqHeight(); |
| 276 | } |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 277 | |
| 278 | Rect getSourceCrop() const override { |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 279 | // use the projected display viewport by default. |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 280 | if (mSourceCrop.isEmpty()) { |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 281 | return mDisplay->getSourceClip(); |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 284 | // Recompute the device transformation for the source crop. |
| 285 | ui::Transform rotation; |
| 286 | ui::Transform translatePhysical; |
| 287 | ui::Transform translateLogical; |
| 288 | ui::Transform scale; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 289 | const Rect& viewport = mDisplay->getViewport(); |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 290 | const Rect& sourceClip = mDisplay->getSourceClip(); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 291 | const Rect& frame = mDisplay->getFrame(); |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 292 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 293 | const auto flags = ui::Transform::toRotationFlags(mDisplay->getPhysicalOrientation()); |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 294 | rotation.set(flags, getWidth(), getHeight()); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 295 | |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 296 | translateLogical.set(-viewport.left, -viewport.top); |
Lloyd Pique | e8fe474 | 2020-01-21 15:26:18 -0800 | [diff] [blame] | 297 | translatePhysical.set(sourceClip.left, sourceClip.top); |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 298 | scale.set(frame.getWidth() / float(viewport.getWidth()), 0, 0, |
| 299 | frame.getHeight() / float(viewport.getHeight())); |
| 300 | const ui::Transform finalTransform = |
| 301 | rotation * translatePhysical * scale * translateLogical; |
| 302 | return finalTransform.transform(mSourceCrop); |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 303 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 304 | |
| 305 | private: |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 306 | static RotationFlags applyInversePhysicalOrientation(RotationFlags orientation, |
| 307 | ui::Rotation physicalOrientation) { |
| 308 | uint32_t inverseRotate90 = 0; |
| 309 | uint32_t inverseReflect = 0; |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 310 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 311 | switch (physicalOrientation) { |
| 312 | case ui::ROTATION_0: |
| 313 | return orientation; |
| 314 | |
| 315 | case ui::ROTATION_90: |
| 316 | inverseRotate90 = ui::Transform::ROT_90; |
| 317 | inverseReflect = ui::Transform::ROT_180; |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 318 | break; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 319 | |
| 320 | case ui::ROTATION_180: |
| 321 | inverseReflect = ui::Transform::ROT_180; |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 322 | break; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 323 | |
| 324 | case ui::ROTATION_270: |
| 325 | inverseRotate90 = ui::Transform::ROT_90; |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 326 | break; |
| 327 | } |
| 328 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 329 | const uint32_t rotate90 = orientation & ui::Transform::ROT_90; |
| 330 | uint32_t reflect = orientation & ui::Transform::ROT_180; |
| 331 | |
| 332 | // Apply reflection for double rotation. |
| 333 | if (rotate90 & inverseRotate90) { |
| 334 | reflect = ~reflect & ui::Transform::ROT_180; |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 337 | return static_cast<RotationFlags>((rotate90 ^ inverseRotate90) | |
| 338 | (reflect ^ inverseReflect)); |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 341 | const sp<const DisplayDevice> mDisplay; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 342 | const Rect mSourceCrop; |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 343 | const bool mAllowSecureLayers; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 344 | }; |
| 345 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 346 | } // namespace android |