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 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_DISPLAY_DEVICE_H |
| 18 | #define ANDROID_DISPLAY_DEVICE_H |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdlib.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 21 | |
| 22 | #include <memory> |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 23 | #include <optional> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 24 | #include <string> |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 25 | #include <unordered_map> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
Alec Mouri | f6fd29e | 2018-11-17 04:56:41 +0000 | [diff] [blame] | 27 | #include <android/native_window.h> |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 28 | #include <binder/IBinder.h> |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 29 | #include <gui/LayerState.h> |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 30 | #include <hardware/hwcomposer_defs.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 31 | #include <math/mat4.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 32 | #include <renderengine/RenderEngine.h> |
Alec Mouri | f6fd29e | 2018-11-17 04:56:41 +0000 | [diff] [blame] | 33 | #include <system/window.h> |
Huihong Luo | d6f1fc2 | 2019-09-10 14:29:20 -0700 | [diff] [blame^] | 34 | #include <ui/DisplayInfo.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> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 38 | #include <ui/Transform.h> |
Alec Mouri | 8d4f90a | 2018-11-14 22:33:24 +0000 | [diff] [blame] | 39 | #include <utils/Mutex.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 40 | #include <utils/RefBase.h> |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 41 | #include <utils/Timers.h> |
| 42 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 43 | #include "DisplayHardware/DisplayIdentification.h" |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 44 | #include "DisplayHardware/PowerAdvisor.h" |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 45 | #include "RenderArea.h" |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 46 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | namespace android { |
| 48 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 49 | class Fence; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 50 | class HWComposer; |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 51 | class IGraphicBufferProducer; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 52 | class Layer; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 53 | class SurfaceFlinger; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 54 | |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 55 | struct CompositionInfo; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 56 | struct DisplayDeviceCreationArgs; |
| 57 | struct DisplayInfo; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 59 | namespace compositionengine { |
| 60 | class Display; |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 61 | class DisplaySurface; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 62 | } // namespace compositionengine |
| 63 | |
| 64 | class DisplayDevice : public LightRefBase<DisplayDevice> { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | public: |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 66 | constexpr static float sDefaultMinLumiance = 0.0; |
| 67 | constexpr static float sDefaultMaxLumiance = 500.0; |
| 68 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 69 | explicit DisplayDevice(DisplayDeviceCreationArgs&& args); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 70 | virtual ~DisplayDevice(); |
| 71 | |
| 72 | std::shared_ptr<compositionengine::Display> getCompositionDisplay() const { |
| 73 | return mCompositionDisplay; |
| 74 | } |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 75 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 76 | bool isVirtual() const { return mIsVirtual; } |
| 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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | int getWidth() const; |
| 84 | int getHeight() const; |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 85 | int getInstallOrientation() const { return mDisplayInstallOrientation; } |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 86 | |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 87 | void setLayerStack(uint32_t stack); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 88 | void setDisplaySize(const int newWidth, const int newHeight); |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 89 | void setProjection(int orientation, const Rect& viewport, const Rect& frame); |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 90 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 91 | int getOrientation() const { return mOrientation; } |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 92 | static uint32_t getPrimaryDisplayOrientationTransform(); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 93 | const ui::Transform& getTransform() const; |
| 94 | const Rect& getViewport() const; |
| 95 | const Rect& getFrame() const; |
| 96 | const Rect& getScissor() const; |
| 97 | bool needsFiltering() const; |
| 98 | uint32_t getLayerStack() const; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 99 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 100 | const std::optional<DisplayId>& getId() const; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 101 | const wp<IBinder>& getDisplayToken() const { return mDisplayToken; } |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 102 | int32_t getSequenceId() const { return mSequenceId; } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 103 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 104 | const Region& getUndefinedRegion() const; |
| 105 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 106 | int32_t getSupportedPerFrameMetadata() const; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 107 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 108 | bool hasWideColorGamut() const; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 109 | // Whether h/w composer has native support for specific HDR type. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 110 | bool hasHDR10PlusSupport() const; |
| 111 | bool hasHDR10Support() const; |
| 112 | bool hasHLGSupport() const; |
| 113 | bool hasDolbyVisionSupport() const; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 114 | |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 115 | // The returned HdrCapabilities is the combination of HDR capabilities from |
| 116 | // hardware composer and RenderEngine. When the DisplayDevice supports wide |
| 117 | // color gamut, RenderEngine is able to simulate HDR support in Display P3 |
| 118 | // color space for both PQ and HLG HDR contents. The minimum and maximum |
| 119 | // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance |
| 120 | // respectively if hardware composer doesn't return meaningful values. |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 121 | const HdrCapabilities& getHdrCapabilities() const; |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 122 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 123 | // Return true if intent is supported by the display. |
| 124 | bool hasRenderIntent(ui::RenderIntent intent) const; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 125 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 126 | const Rect& getBounds() const; |
| 127 | const Rect& bounds() const { return getBounds(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 129 | void setDisplayName(const std::string& displayName); |
| 130 | const std::string& getDisplayName() const { return mDisplayName; } |
Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 131 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 132 | /* ------------------------------------------------------------------------ |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 133 | * Display power mode management. |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 134 | */ |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 135 | int getPowerMode() const; |
| 136 | void setPowerMode(int mode); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 137 | bool isPoweredOn() const; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 138 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 139 | ui::Dataspace getCompositionDataSpace() const; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 140 | |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 141 | /* ------------------------------------------------------------------------ |
| 142 | * Display active config management. |
| 143 | */ |
| 144 | int getActiveConfig() const; |
| 145 | void setActiveConfig(int mode); |
| 146 | |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 147 | // release HWC resources (if any) for removable displays |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 148 | void disconnect(); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 149 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 150 | /* ------------------------------------------------------------------------ |
| 151 | * Debugging |
| 152 | */ |
| 153 | uint32_t getPageFlipCount() const; |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 154 | std::string getDebugName() const; |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 155 | void dump(std::string& result) const; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 156 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | private: |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 158 | /* |
| 159 | * Constants, set during initialization |
| 160 | */ |
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 | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 164 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 165 | const int mDisplayInstallOrientation; |
| 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; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 169 | const bool mIsVirtual; |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 170 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 171 | /* |
| 172 | * Can only accessed from the main thread, these members |
| 173 | * don't need synchronization. |
| 174 | */ |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 175 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 176 | /* |
| 177 | * Transaction state |
| 178 | */ |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 179 | static uint32_t displayStateOrientationToTransformOrientation(int orientation); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 180 | static status_t orientationToTransfrom(int orientation, |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 181 | int w, int h, ui::Transform* tr); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 182 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 183 | int mOrientation; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 184 | static uint32_t sPrimaryDisplayOrientation; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 185 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 186 | // Current power mode |
| 187 | int mPowerMode; |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 188 | // Current active config |
| 189 | int mActiveConfig; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 190 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 191 | // TODO(b/74619554): Remove special cases for primary display. |
| 192 | const bool mIsPrimary; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | }; |
| 194 | |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 195 | struct DisplayDeviceState { |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 196 | bool isVirtual() const { return !displayId.has_value(); } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 197 | |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 198 | int32_t sequenceId = sNextSequenceId++; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 199 | std::optional<DisplayId> displayId; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 200 | sp<IGraphicBufferProducer> surface; |
Huihong Luo | d6f1fc2 | 2019-09-10 14:29:20 -0700 | [diff] [blame^] | 201 | uint32_t layerStack = NO_LAYER_STACK; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 202 | Rect viewport; |
| 203 | Rect frame; |
| 204 | uint8_t orientation = 0; |
| 205 | uint32_t width = 0; |
| 206 | uint32_t height = 0; |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 207 | std::string displayName; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 208 | bool isSecure = false; |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 209 | |
| 210 | private: |
| 211 | static std::atomic<int32_t> sNextSequenceId; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 214 | struct DisplayDeviceCreationArgs { |
| 215 | // We use a constructor to ensure some of the values are set, without |
| 216 | // assuming a default value. |
| 217 | DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger, const wp<IBinder>& displayToken, |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 218 | const std::optional<DisplayId>& displayId); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 219 | |
| 220 | const sp<SurfaceFlinger> flinger; |
| 221 | const wp<IBinder> displayToken; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 222 | const std::optional<DisplayId> displayId; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 223 | |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 224 | int32_t sequenceId{0}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 225 | bool isVirtual{false}; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 226 | bool isSecure{false}; |
| 227 | sp<ANativeWindow> nativeWindow; |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 228 | sp<compositionengine::DisplaySurface> displaySurface; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 229 | int displayInstallOrientation{DisplayState::eOrientationDefault}; |
| 230 | bool hasWideColorGamut{false}; |
| 231 | HdrCapabilities hdrCapabilities; |
| 232 | int32_t supportedPerFrameMetadata{0}; |
| 233 | std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes; |
| 234 | int initialPowerMode{HWC_POWER_MODE_NORMAL}; |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 235 | bool isPrimary{false}; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 236 | Hwc2::PowerAdvisor* powerAdvisor{nullptr}; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 237 | }; |
| 238 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 239 | class DisplayRenderArea : public RenderArea { |
| 240 | public: |
| 241 | DisplayRenderArea(const sp<const DisplayDevice> device, |
Chia-I Wu | c80dcbb | 2018-08-24 15:34:02 -0700 | [diff] [blame] | 242 | ui::Transform::orientation_flags rotation = ui::Transform::ROT_0) |
Chia-I Wu | 9d1abea | 2018-08-23 13:44:43 -0700 | [diff] [blame] | 243 | : DisplayRenderArea(device, device->getBounds(), device->getWidth(), device->getHeight(), |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 244 | device->getCompositionDataSpace(), rotation) {} |
Chia-I Wu | 9d1abea | 2018-08-23 13:44:43 -0700 | [diff] [blame] | 245 | DisplayRenderArea(const sp<const DisplayDevice> device, Rect sourceCrop, uint32_t reqWidth, |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 246 | uint32_t reqHeight, ui::Dataspace reqDataSpace, |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 247 | ui::Transform::orientation_flags rotation, bool allowSecureLayers = true) |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 248 | : RenderArea(reqWidth, reqHeight, CaptureFill::OPAQUE, reqDataSpace, |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 249 | getDisplayRotation(rotation, device->getInstallOrientation())), |
| 250 | mDevice(device), |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 251 | mSourceCrop(sourceCrop), |
| 252 | mAllowSecureLayers(allowSecureLayers) {} |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 253 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 254 | const ui::Transform& getTransform() const override { return mDevice->getTransform(); } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 255 | Rect getBounds() const override { return mDevice->getBounds(); } |
| 256 | int getHeight() const override { return mDevice->getHeight(); } |
| 257 | int getWidth() const override { return mDevice->getWidth(); } |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 258 | bool isSecure() const override { return mAllowSecureLayers && mDevice->isSecure(); } |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 259 | const sp<const DisplayDevice> getDisplayDevice() const override { return mDevice; } |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 260 | |
| 261 | bool needsFiltering() const override { |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 262 | // check if the projection from the logical display to the physical |
| 263 | // display needs filtering |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 264 | if (mDevice->needsFiltering()) { |
| 265 | return true; |
| 266 | } |
| 267 | |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 268 | // check if the projection from the logical render area (i.e., the |
| 269 | // physical display) to the physical render area requires filtering |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 270 | const Rect sourceCrop = getSourceCrop(); |
| 271 | int width = sourceCrop.width(); |
| 272 | int height = sourceCrop.height(); |
| 273 | if (getRotationFlags() & ui::Transform::ROT_90) { |
| 274 | std::swap(width, height); |
| 275 | } |
| 276 | return width != getReqWidth() || height != getReqHeight(); |
| 277 | } |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 278 | |
| 279 | Rect getSourceCrop() const override { |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 280 | // use the projected display viewport by default. |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 281 | if (mSourceCrop.isEmpty()) { |
| 282 | return mDevice->getScissor(); |
| 283 | } |
| 284 | |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 285 | // Recompute the device transformation for the source crop. |
| 286 | ui::Transform rotation; |
| 287 | ui::Transform translatePhysical; |
| 288 | ui::Transform translateLogical; |
| 289 | ui::Transform scale; |
| 290 | const Rect& viewport = mDevice->getViewport(); |
| 291 | const Rect& scissor = mDevice->getScissor(); |
| 292 | const Rect& frame = mDevice->getFrame(); |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 293 | |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 294 | const int orientation = mDevice->getInstallOrientation(); |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 295 | // Install orientation is transparent to the callers. Apply it now. |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 296 | uint32_t flags = 0x00; |
| 297 | switch (orientation) { |
| 298 | case DisplayState::eOrientation90: |
| 299 | flags = ui::Transform::ROT_90; |
| 300 | break; |
| 301 | case DisplayState::eOrientation180: |
| 302 | flags = ui::Transform::ROT_180; |
| 303 | break; |
| 304 | case DisplayState::eOrientation270: |
| 305 | flags = ui::Transform::ROT_270; |
| 306 | break; |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 307 | default: |
| 308 | break; |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 309 | } |
Alec Mouri | adb75f4 | 2019-03-28 21:42:24 -0700 | [diff] [blame] | 310 | rotation.set(flags, getWidth(), getHeight()); |
| 311 | translateLogical.set(-viewport.left, -viewport.top); |
| 312 | translatePhysical.set(scissor.left, scissor.top); |
| 313 | scale.set(frame.getWidth() / float(viewport.getWidth()), 0, 0, |
| 314 | frame.getHeight() / float(viewport.getHeight())); |
| 315 | const ui::Transform finalTransform = |
| 316 | rotation * translatePhysical * scale * translateLogical; |
| 317 | return finalTransform.transform(mSourceCrop); |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 318 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 319 | |
| 320 | private: |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 321 | // Install orientation is transparent to the callers. We need to cancel |
| 322 | // it out by modifying rotation flags. |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 323 | static ui::Transform::orientation_flags getDisplayRotation( |
| 324 | ui::Transform::orientation_flags rotation, int orientation) { |
| 325 | if (orientation == DisplayState::eOrientationDefault) { |
| 326 | return rotation; |
| 327 | } |
| 328 | |
| 329 | // convert hw orientation into flag presentation |
| 330 | // here inverse transform needed |
| 331 | uint8_t hw_rot_90 = 0x00; |
| 332 | uint8_t hw_flip_hv = 0x00; |
| 333 | switch (orientation) { |
| 334 | case DisplayState::eOrientation90: |
| 335 | hw_rot_90 = ui::Transform::ROT_90; |
| 336 | hw_flip_hv = ui::Transform::ROT_180; |
| 337 | break; |
| 338 | case DisplayState::eOrientation180: |
| 339 | hw_flip_hv = ui::Transform::ROT_180; |
| 340 | break; |
| 341 | case DisplayState::eOrientation270: |
| 342 | hw_rot_90 = ui::Transform::ROT_90; |
| 343 | break; |
| 344 | } |
| 345 | |
| 346 | // transform flags operation |
| 347 | // 1) flip H V if both have ROT_90 flag |
| 348 | // 2) XOR these flags |
| 349 | uint8_t rotation_rot_90 = rotation & ui::Transform::ROT_90; |
| 350 | uint8_t rotation_flip_hv = rotation & ui::Transform::ROT_180; |
| 351 | if (rotation_rot_90 & hw_rot_90) { |
| 352 | rotation_flip_hv = (~rotation_flip_hv) & ui::Transform::ROT_180; |
| 353 | } |
| 354 | |
| 355 | return static_cast<ui::Transform::orientation_flags>( |
| 356 | (rotation_rot_90 ^ hw_rot_90) | (rotation_flip_hv ^ hw_flip_hv)); |
| 357 | } |
| 358 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 359 | const sp<const DisplayDevice> mDevice; |
| 360 | const Rect mSourceCrop; |
Robert Carr | fa8855f | 2019-02-19 10:05:00 -0800 | [diff] [blame] | 361 | const bool mAllowSecureLayers; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 362 | }; |
| 363 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 364 | }; // namespace android |
| 365 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 366 | #endif // ANDROID_DISPLAY_DEVICE_H |