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> |
| 23 | #include <string> |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 24 | #include <unordered_map> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 26 | #include <binder/IBinder.h> |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 27 | #include <gui/LayerState.h> |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 28 | #include <hardware/hwcomposer_defs.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 29 | #include <math/mat4.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 30 | #include <renderengine/Surface.h> |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 31 | #include <ui/GraphicTypes.h> |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 32 | #include <ui/HdrCapabilities.h> |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 33 | #include <ui/Region.h> |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 34 | #include <ui/Transform.h> |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 35 | #include <utils/RefBase.h> |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 36 | #include <utils/Mutex.h> |
Mathias Agopian | 4f4f094 | 2013-08-19 17:26:18 -0700 | [diff] [blame] | 37 | #include <utils/String8.h> |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 38 | #include <utils/Timers.h> |
| 39 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 40 | #include "RenderArea.h" |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 41 | |
Mathias Agopian | d8552d7 | 2012-08-04 21:39:11 -0700 | [diff] [blame] | 42 | struct ANativeWindow; |
| 43 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | namespace android { |
| 45 | |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 46 | class DisplaySurface; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 47 | class Fence; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 48 | class HWComposer; |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 49 | class IGraphicBufferProducer; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 50 | class Layer; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 51 | class SurfaceFlinger; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 52 | |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 53 | struct CompositionInfo; |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 54 | struct DisplayDeviceCreationArgs; |
| 55 | struct DisplayInfo; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | |
Mathias Agopian | 028a757 | 2012-08-05 01:23:51 -0700 | [diff] [blame] | 57 | class DisplayDevice : public LightRefBase<DisplayDevice> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | { |
| 59 | public: |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 60 | constexpr static float sDefaultMinLumiance = 0.0; |
| 61 | constexpr static float sDefaultMaxLumiance = 500.0; |
| 62 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 63 | // region in layer-stack space |
| 64 | mutable Region dirtyRegion; |
| 65 | // region in screen space |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 66 | Region undefinedRegion; |
Jesse Hall | b7a0549 | 2014-08-14 15:45:06 -0700 | [diff] [blame] | 67 | bool lastCompositionHadVisibleLayers; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 68 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 69 | enum DisplayType { |
| 70 | DISPLAY_ID_INVALID = -1, |
| 71 | DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY, |
| 72 | DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL, |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 73 | DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL, |
| 74 | NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES, |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | enum { |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 78 | NO_LAYER_STACK = 0xFFFFFFFF, |
| 79 | }; |
| 80 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 81 | explicit DisplayDevice(DisplayDeviceCreationArgs&& args); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | |
Mathias Agopian | 028a757 | 2012-08-05 01:23:51 -0700 | [diff] [blame] | 83 | ~DisplayDevice(); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 84 | |
| 85 | // whether this is a valid object. An invalid DisplayDevice is returned |
| 86 | // when an non existing id is requested |
| 87 | bool isValid() const; |
| 88 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 89 | // isSecure indicates whether this display can be trusted to display |
| 90 | // secure surfaces. |
| 91 | bool isSecure() const { return mIsSecure; } |
| 92 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | // Flip the front and back buffers if the back buffer is "dirty". Might |
| 94 | // be instantaneous, might involve copying the frame buffer around. |
Chia-I Wu | b02087d | 2017-11-09 10:19:54 -0800 | [diff] [blame] | 95 | void flip() const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | int getWidth() const; |
| 98 | int getHeight() const; |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 99 | int getInstallOrientation() const { return mDisplayInstallOrientation; } |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 100 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 101 | void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers); |
| 102 | const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const; |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 103 | void setLayersNeedingFences(const Vector< sp<Layer> >& layers); |
| 104 | const Vector< sp<Layer> >& getLayersNeedingFences() const; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 105 | Region getDirtyRegion(bool repaintEverything) const; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 106 | |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 107 | void setLayerStack(uint32_t stack); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 108 | void setDisplaySize(const int newWidth, const int newHeight); |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 109 | void setProjection(int orientation, const Rect& viewport, const Rect& frame); |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 110 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 111 | int getOrientation() const { return mOrientation; } |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 112 | uint32_t getOrientationTransform() const; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 113 | static uint32_t getPrimaryDisplayOrientationTransform(); |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 114 | const ui::Transform& getTransform() const { return mGlobalTransform; } |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 115 | const Rect getViewport() const { return mViewport; } |
| 116 | const Rect getFrame() const { return mFrame; } |
Mathias Agopian | 766dc49 | 2012-10-30 18:08:06 -0700 | [diff] [blame] | 117 | const Rect& getScissor() const { return mScissor; } |
Mathias Agopian | eba8c68 | 2012-09-19 23:14:45 -0700 | [diff] [blame] | 118 | bool needsFiltering() const { return mNeedsFiltering; } |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 119 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 120 | uint32_t getLayerStack() const { return mLayerStack; } |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 121 | int32_t getDisplayType() const { return mType; } |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 122 | bool isPrimary() const { return mType == DISPLAY_PRIMARY; } |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 123 | bool isVirtual() const { return mType == DISPLAY_VIRTUAL; } |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 124 | int32_t getId() const { return mId; } |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 125 | const wp<IBinder>& getDisplayToken() const { return mDisplayToken; } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 126 | |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 127 | int32_t getSupportedPerFrameMetadata() const { return mSupportedPerFrameMetadata; } |
| 128 | |
Dan Stoza | 7143316 | 2014-02-04 16:22:36 -0800 | [diff] [blame] | 129 | // We pass in mustRecompose so we can keep VirtualDisplaySurface's state |
| 130 | // machine happy without actually queueing a buffer if nothing has changed |
| 131 | status_t beginFrame(bool mustRecompose) const; |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 132 | status_t prepareFrame(HWComposer& hwc, std::vector<CompositionInfo>& compositionInfo); |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 133 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 134 | bool hasWideColorGamut() const { return mHasWideColorGamut; } |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 135 | // Whether h/w composer has native support for specific HDR type. |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 136 | bool hasHDR10Support() const { return mHasHdr10; } |
| 137 | bool hasHLGSupport() const { return mHasHLG; } |
| 138 | bool hasDolbyVisionSupport() const { return mHasDolbyVision; } |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 139 | |
Peiyong Lin | dfde511 | 2018-06-05 10:58:41 -0700 | [diff] [blame] | 140 | // Return true if the HDR dataspace is supported but |
| 141 | // there is no corresponding color mode. |
| 142 | bool hasLegacyHdrSupport(ui::Dataspace dataspace) const; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 143 | |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 144 | // The returned HdrCapabilities is the combination of HDR capabilities from |
| 145 | // hardware composer and RenderEngine. When the DisplayDevice supports wide |
| 146 | // color gamut, RenderEngine is able to simulate HDR support in Display P3 |
| 147 | // color space for both PQ and HLG HDR contents. The minimum and maximum |
| 148 | // luminance will be set to sDefaultMinLumiance and sDefaultMaxLumiance |
| 149 | // respectively if hardware composer doesn't return meaningful values. |
| 150 | const HdrCapabilities& getHdrCapabilities() const { return mHdrCapabilities; } |
Jesse Hall | 38efe86 | 2013-04-06 23:12:29 -0700 | [diff] [blame] | 151 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 152 | // Return true if intent is supported by the display. |
| 153 | bool hasRenderIntent(ui::RenderIntent intent) const; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 154 | |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 155 | void getBestColorMode(ui::Dataspace dataspace, ui::RenderIntent intent, |
| 156 | ui::Dataspace* outDataspace, ui::ColorMode* outMode, |
| 157 | ui::RenderIntent* outIntent) const; |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 158 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 159 | void swapBuffers(HWComposer& hwc) const; |
Jesse Hall | 01e2905 | 2013-02-19 16:13:35 -0800 | [diff] [blame] | 160 | |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 161 | // called after h/w composer has completed its set() call |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 162 | void onSwapBuffersCompleted() const; |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 163 | |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 164 | Rect getBounds() const { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 165 | return Rect(mDisplayWidth, mDisplayHeight); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | } |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 167 | inline Rect bounds() const { return getBounds(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 169 | void setDisplayName(const std::string& displayName); |
| 170 | const std::string& getDisplayName() const { return mDisplayName; } |
Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 171 | |
Chia-I Wu | f846a35 | 2017-11-10 09:22:52 -0800 | [diff] [blame] | 172 | bool makeCurrent() const; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 173 | void setViewportAndProjection() const; |
Mathias Agopian | bae92d0 | 2012-09-28 01:00:47 -0700 | [diff] [blame] | 174 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 175 | const sp<Fence>& getClientTargetAcquireFence() const; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 176 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 177 | /* ------------------------------------------------------------------------ |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 178 | * Display power mode management. |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 179 | */ |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 180 | int getPowerMode() const; |
| 181 | void setPowerMode(int mode); |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 182 | bool isPoweredOn() const; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 183 | |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 184 | ui::ColorMode getActiveColorMode() const; |
| 185 | void setActiveColorMode(ui::ColorMode mode); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 186 | ui::RenderIntent getActiveRenderIntent() const; |
| 187 | void setActiveRenderIntent(ui::RenderIntent renderIntent); |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 188 | android_color_transform_t getColorTransform() const; |
| 189 | void setColorTransform(const mat4& transform); |
Peiyong Lin | 34beb7a | 2018-03-28 11:57:12 -0700 | [diff] [blame] | 190 | void setCompositionDataSpace(ui::Dataspace dataspace); |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 191 | ui::Dataspace getCompositionDataSpace() const; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 192 | |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 193 | /* ------------------------------------------------------------------------ |
| 194 | * Display active config management. |
| 195 | */ |
| 196 | int getActiveConfig() const; |
| 197 | void setActiveConfig(int mode); |
| 198 | |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 199 | // release HWC resources (if any) for removable displays |
| 200 | void disconnect(HWComposer& hwc); |
| 201 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 202 | /* ------------------------------------------------------------------------ |
| 203 | * Debugging |
| 204 | */ |
| 205 | uint32_t getPageFlipCount() const; |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 206 | std::string getDebugName() const; |
Mathias Agopian | 74d211a | 2013-04-22 16:55:35 +0200 | [diff] [blame] | 207 | void dump(String8& result) const; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 208 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | private: |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 210 | /* |
| 211 | * Constants, set during initialization |
| 212 | */ |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 213 | sp<SurfaceFlinger> mFlinger; |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 214 | DisplayType mType; |
Dominik Laskowski | 7e04546 | 2018-05-30 13:02:02 -0700 | [diff] [blame] | 215 | int32_t mId; |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 216 | wp<IBinder> mDisplayToken; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 217 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 218 | // ANativeWindow this display is rendering into |
Mathias Agopian | d8552d7 | 2012-08-04 21:39:11 -0700 | [diff] [blame] | 219 | sp<ANativeWindow> mNativeWindow; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 220 | sp<DisplaySurface> mDisplaySurface; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 221 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 222 | std::unique_ptr<renderengine::Surface> mSurface; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 223 | int mDisplayWidth; |
| 224 | int mDisplayHeight; |
Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 225 | const int mDisplayInstallOrientation; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 226 | mutable uint32_t mPageFlipCount; |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 227 | std::string mDisplayName; |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 228 | bool mIsSecure; |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 229 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 230 | /* |
| 231 | * Can only accessed from the main thread, these members |
| 232 | * don't need synchronization. |
| 233 | */ |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 234 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 235 | // list of visible layers on that display |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 236 | Vector< sp<Layer> > mVisibleLayersSortedByZ; |
Chia-I Wu | 8380689 | 2017-11-16 10:50:20 -0800 | [diff] [blame] | 237 | // list of layers needing fences |
| 238 | Vector< sp<Layer> > mLayersNeedingFences; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 239 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 240 | /* |
| 241 | * Transaction state |
| 242 | */ |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 243 | static status_t orientationToTransfrom(int orientation, |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 244 | int w, int h, ui::Transform* tr); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 245 | |
Fabien Sanglard | f0c53d6 | 2017-03-03 18:58:50 -0800 | [diff] [blame] | 246 | // The identifier of the active layer stack for this display. Several displays |
| 247 | // can use the same layer stack: A z-ordered group of layers (sometimes called |
| 248 | // "surfaces"). Any given layer can only be on a single layer stack. |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 249 | uint32_t mLayerStack; |
Fabien Sanglard | f0c53d6 | 2017-03-03 18:58:50 -0800 | [diff] [blame] | 250 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 251 | int mOrientation; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 252 | static uint32_t sPrimaryDisplayOrientation; |
Mathias Agopian | 766dc49 | 2012-10-30 18:08:06 -0700 | [diff] [blame] | 253 | // user-provided visible area of the layer stack |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 254 | Rect mViewport; |
Mathias Agopian | 766dc49 | 2012-10-30 18:08:06 -0700 | [diff] [blame] | 255 | // user-provided rectangle where mViewport gets mapped to |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame] | 256 | Rect mFrame; |
Mathias Agopian | 766dc49 | 2012-10-30 18:08:06 -0700 | [diff] [blame] | 257 | // pre-computed scissor to apply to the display |
| 258 | Rect mScissor; |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 259 | ui::Transform mGlobalTransform; |
Mathias Agopian | eba8c68 | 2012-09-19 23:14:45 -0700 | [diff] [blame] | 260 | bool mNeedsFiltering; |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 261 | // Current power mode |
| 262 | int mPowerMode; |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 263 | // Current active config |
| 264 | int mActiveConfig; |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 265 | // current active color mode |
Chia-I Wu | 614e142 | 2018-05-23 02:17:03 -0700 | [diff] [blame] | 266 | ui::ColorMode mActiveColorMode = ui::ColorMode::NATIVE; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 267 | // Current active render intent. |
Chia-I Wu | 614e142 | 2018-05-23 02:17:03 -0700 | [diff] [blame] | 268 | ui::RenderIntent mActiveRenderIntent = ui::RenderIntent::COLORIMETRIC; |
| 269 | ui::Dataspace mCompositionDataSpace = ui::Dataspace::UNKNOWN; |
Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 270 | // Current color transform |
| 271 | android_color_transform_t mColorTransform; |
Courtney Goeltzenleuchter | 5d94389 | 2017-03-22 13:46:46 -0600 | [diff] [blame] | 272 | |
| 273 | // Need to know if display is wide-color capable or not. |
| 274 | // Initialized by SurfaceFlinger when the DisplayDevice is created. |
| 275 | // Fed to RenderEngine during composition. |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 276 | bool mHasWideColorGamut; |
| 277 | bool mHasHdr10; |
Peiyong Lin | 6266589 | 2018-04-16 11:07:44 -0700 | [diff] [blame] | 278 | bool mHasHLG; |
| 279 | bool mHasDolbyVision; |
Peiyong Lin | fb06930 | 2018-04-25 14:34:31 -0700 | [diff] [blame] | 280 | HdrCapabilities mHdrCapabilities; |
Peiyong Lin | 0ac5f4e | 2018-04-19 22:06:34 -0700 | [diff] [blame] | 281 | const int32_t mSupportedPerFrameMetadata; |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 282 | |
| 283 | // Mappings from desired Dataspace/RenderIntent to the supported |
| 284 | // Dataspace/ColorMode/RenderIntent. |
| 285 | using ColorModeKey = uint64_t; |
| 286 | struct ColorModeValue { |
| 287 | ui::Dataspace dataspace; |
| 288 | ui::ColorMode colorMode; |
| 289 | ui::RenderIntent renderIntent; |
| 290 | }; |
| 291 | |
| 292 | static ColorModeKey getColorModeKey(ui::Dataspace dataspace, ui::RenderIntent intent) { |
| 293 | return (static_cast<uint64_t>(dataspace) << 32) | static_cast<uint32_t>(intent); |
| 294 | } |
| 295 | void populateColorModes( |
| 296 | const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes); |
| 297 | void addColorMode( |
| 298 | const std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>>& hwcColorModes, |
| 299 | const ui::ColorMode mode, const ui::RenderIntent intent); |
| 300 | |
| 301 | std::unordered_map<ColorModeKey, ColorModeValue> mColorModes; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | }; |
| 303 | |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 304 | struct DisplayDeviceState { |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 305 | bool isVirtual() const { return type >= DisplayDevice::DISPLAY_VIRTUAL; } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 306 | |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 307 | int32_t sequenceId = sNextSequenceId++; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 308 | DisplayDevice::DisplayType type = DisplayDevice::DISPLAY_ID_INVALID; |
| 309 | sp<IGraphicBufferProducer> surface; |
| 310 | uint32_t layerStack = DisplayDevice::NO_LAYER_STACK; |
| 311 | Rect viewport; |
| 312 | Rect frame; |
| 313 | uint8_t orientation = 0; |
| 314 | uint32_t width = 0; |
| 315 | uint32_t height = 0; |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 316 | std::string displayName; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 317 | bool isSecure = false; |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 318 | |
| 319 | private: |
| 320 | static std::atomic<int32_t> sNextSequenceId; |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 321 | }; |
| 322 | |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 323 | struct DisplayDeviceCreationArgs { |
| 324 | // We use a constructor to ensure some of the values are set, without |
| 325 | // assuming a default value. |
| 326 | DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger, const wp<IBinder>& displayToken, |
| 327 | DisplayDevice::DisplayType type, int32_t id); |
| 328 | |
| 329 | const sp<SurfaceFlinger> flinger; |
| 330 | const wp<IBinder> displayToken; |
| 331 | const DisplayDevice::DisplayType type; |
| 332 | const int32_t id; |
| 333 | |
| 334 | bool isSecure{false}; |
| 335 | sp<ANativeWindow> nativeWindow; |
| 336 | sp<DisplaySurface> displaySurface; |
| 337 | std::unique_ptr<renderengine::Surface> renderSurface; |
| 338 | int displayWidth{0}; |
| 339 | int displayHeight{0}; |
| 340 | int displayInstallOrientation{DisplayState::eOrientationDefault}; |
| 341 | bool hasWideColorGamut{false}; |
| 342 | HdrCapabilities hdrCapabilities; |
| 343 | int32_t supportedPerFrameMetadata{0}; |
| 344 | std::unordered_map<ui::ColorMode, std::vector<ui::RenderIntent>> hwcColorModes; |
| 345 | int initialPowerMode{HWC_POWER_MODE_NORMAL}; |
| 346 | }; |
| 347 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 348 | class DisplayRenderArea : public RenderArea { |
| 349 | public: |
| 350 | DisplayRenderArea(const sp<const DisplayDevice> device, |
Chia-I Wu | c80dcbb | 2018-08-24 15:34:02 -0700 | [diff] [blame] | 351 | ui::Transform::orientation_flags rotation = ui::Transform::ROT_0) |
Chia-I Wu | 9d1abea | 2018-08-23 13:44:43 -0700 | [diff] [blame] | 352 | : DisplayRenderArea(device, device->getBounds(), device->getWidth(), device->getHeight(), |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 353 | device->getCompositionDataSpace(), rotation) {} |
Chia-I Wu | 9d1abea | 2018-08-23 13:44:43 -0700 | [diff] [blame] | 354 | DisplayRenderArea(const sp<const DisplayDevice> device, Rect sourceCrop, uint32_t reqWidth, |
Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 355 | uint32_t reqHeight, ui::Dataspace reqDataSpace, |
| 356 | ui::Transform::orientation_flags rotation) |
| 357 | : RenderArea(reqWidth, reqHeight, CaptureFill::OPAQUE, reqDataSpace, |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 358 | getDisplayRotation(rotation, device->getInstallOrientation())), |
| 359 | mDevice(device), |
| 360 | mSourceCrop(sourceCrop) {} |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 361 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 362 | const ui::Transform& getTransform() const override { return mDevice->getTransform(); } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 363 | Rect getBounds() const override { return mDevice->getBounds(); } |
| 364 | int getHeight() const override { return mDevice->getHeight(); } |
| 365 | int getWidth() const override { return mDevice->getWidth(); } |
| 366 | bool isSecure() const override { return mDevice->isSecure(); } |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 367 | |
| 368 | bool needsFiltering() const override { |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 369 | // check if the projection from the logical display to the physical |
| 370 | // display needs filtering |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 371 | if (mDevice->needsFiltering()) { |
| 372 | return true; |
| 373 | } |
| 374 | |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 375 | // check if the projection from the logical render area (i.e., the |
| 376 | // physical display) to the physical render area requires filtering |
Chia-I Wu | 5f6664c | 2018-08-28 11:01:44 -0700 | [diff] [blame] | 377 | const Rect sourceCrop = getSourceCrop(); |
| 378 | int width = sourceCrop.width(); |
| 379 | int height = sourceCrop.height(); |
| 380 | if (getRotationFlags() & ui::Transform::ROT_90) { |
| 381 | std::swap(width, height); |
| 382 | } |
| 383 | return width != getReqWidth() || height != getReqHeight(); |
| 384 | } |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 385 | |
| 386 | Rect getSourceCrop() const override { |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 387 | // use the (projected) logical display viewport by default |
| 388 | if (mSourceCrop.isEmpty()) { |
| 389 | return mDevice->getScissor(); |
| 390 | } |
| 391 | |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 392 | const int orientation = mDevice->getInstallOrientation(); |
| 393 | if (orientation == DisplayState::eOrientationDefault) { |
| 394 | return mSourceCrop; |
| 395 | } |
| 396 | |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 397 | // Install orientation is transparent to the callers. Apply it now. |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 398 | uint32_t flags = 0x00; |
| 399 | switch (orientation) { |
| 400 | case DisplayState::eOrientation90: |
| 401 | flags = ui::Transform::ROT_90; |
| 402 | break; |
| 403 | case DisplayState::eOrientation180: |
| 404 | flags = ui::Transform::ROT_180; |
| 405 | break; |
| 406 | case DisplayState::eOrientation270: |
| 407 | flags = ui::Transform::ROT_270; |
| 408 | break; |
| 409 | } |
| 410 | ui::Transform tr; |
| 411 | tr.set(flags, getWidth(), getHeight()); |
| 412 | return tr.transform(mSourceCrop); |
| 413 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 414 | |
| 415 | private: |
Chia-I Wu | 8730ba8 | 2018-08-29 09:25:59 -0700 | [diff] [blame] | 416 | // Install orientation is transparent to the callers. We need to cancel |
| 417 | // it out by modifying rotation flags. |
Chia-I Wu | f2aa311 | 2018-08-27 14:54:37 -0700 | [diff] [blame] | 418 | static ui::Transform::orientation_flags getDisplayRotation( |
| 419 | ui::Transform::orientation_flags rotation, int orientation) { |
| 420 | if (orientation == DisplayState::eOrientationDefault) { |
| 421 | return rotation; |
| 422 | } |
| 423 | |
| 424 | // convert hw orientation into flag presentation |
| 425 | // here inverse transform needed |
| 426 | uint8_t hw_rot_90 = 0x00; |
| 427 | uint8_t hw_flip_hv = 0x00; |
| 428 | switch (orientation) { |
| 429 | case DisplayState::eOrientation90: |
| 430 | hw_rot_90 = ui::Transform::ROT_90; |
| 431 | hw_flip_hv = ui::Transform::ROT_180; |
| 432 | break; |
| 433 | case DisplayState::eOrientation180: |
| 434 | hw_flip_hv = ui::Transform::ROT_180; |
| 435 | break; |
| 436 | case DisplayState::eOrientation270: |
| 437 | hw_rot_90 = ui::Transform::ROT_90; |
| 438 | break; |
| 439 | } |
| 440 | |
| 441 | // transform flags operation |
| 442 | // 1) flip H V if both have ROT_90 flag |
| 443 | // 2) XOR these flags |
| 444 | uint8_t rotation_rot_90 = rotation & ui::Transform::ROT_90; |
| 445 | uint8_t rotation_flip_hv = rotation & ui::Transform::ROT_180; |
| 446 | if (rotation_rot_90 & hw_rot_90) { |
| 447 | rotation_flip_hv = (~rotation_flip_hv) & ui::Transform::ROT_180; |
| 448 | } |
| 449 | |
| 450 | return static_cast<ui::Transform::orientation_flags>( |
| 451 | (rotation_rot_90 ^ hw_rot_90) | (rotation_flip_hv ^ hw_flip_hv)); |
| 452 | } |
| 453 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 454 | const sp<const DisplayDevice> mDevice; |
| 455 | const Rect mSourceCrop; |
| 456 | }; |
| 457 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 458 | }; // namespace android |
| 459 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 460 | #endif // ANDROID_DISPLAY_DEVICE_H |