| 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 |  | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 17 | // #define LOG_NDEBUG 0 | 
|  | 18 | #undef LOG_TAG | 
|  | 19 | #define LOG_TAG "DisplayDevice" | 
|  | 20 |  | 
| Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 21 | #include <android-base/stringprintf.h> | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 22 | #include <compositionengine/CompositionEngine.h> | 
|  | 23 | #include <compositionengine/Display.h> | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 24 | #include <compositionengine/DisplayColorProfile.h> | 
|  | 25 | #include <compositionengine/DisplayColorProfileCreationArgs.h> | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 26 | #include <compositionengine/DisplayCreationArgs.h> | 
| Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 27 | #include <compositionengine/DisplaySurface.h> | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 28 | #include <compositionengine/RenderSurface.h> | 
|  | 29 | #include <compositionengine/RenderSurfaceCreationArgs.h> | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 30 | #include <compositionengine/impl/OutputCompositionState.h> | 
| Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 31 | #include <configstore/Utils.h> | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 32 | #include <log/log.h> | 
| Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 33 | #include <system/window.h> | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 34 | #include <ui/GraphicTypes.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 36 | #include "DisplayDevice.h" | 
| Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 37 | #include "Layer.h" | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 38 | #include "SurfaceFlinger.h" | 
| Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 39 |  | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 40 | namespace android { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 |  | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 42 | using android::base::StringAppendF; | 
| Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 43 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | /* | 
|  | 45 | * Initialize the display to the specified values. | 
|  | 46 | * | 
|  | 47 | */ | 
|  | 48 |  | 
| Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 49 | uint32_t DisplayDevice::sPrimaryDisplayOrientation = 0; | 
|  | 50 |  | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 51 | DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(const sp<SurfaceFlinger>& flinger, | 
|  | 52 | const wp<IBinder>& displayToken, | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 53 | const std::optional<DisplayId>& displayId) | 
|  | 54 | : flinger(flinger), displayToken(displayToken), displayId(displayId) {} | 
| Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 55 |  | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 56 | DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args) | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 57 | : mFlinger(args.flinger), | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 58 | mDisplayToken(args.displayToken), | 
| Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 59 | mSequenceId(args.sequenceId), | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 60 | mDisplayInstallOrientation(args.displayInstallOrientation), | 
|  | 61 | mCompositionDisplay{mFlinger->getCompositionEngine().createDisplay( | 
| Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 62 | compositionengine::DisplayCreationArgs{args.isVirtual, args.displayId, | 
|  | 63 | args.powerAdvisor})}, | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 64 | mIsVirtual(args.isVirtual), | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 65 | mOrientation(), | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 66 | mActiveConfig(0), | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 67 | mIsPrimary(args.isPrimary) { | 
| Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 68 | mCompositionDisplay->editState().isSecure = args.isSecure; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 69 | mCompositionDisplay->createRenderSurface( | 
|  | 70 | compositionengine::RenderSurfaceCreationArgs{ANativeWindow_getWidth( | 
|  | 71 | args.nativeWindow.get()), | 
|  | 72 | ANativeWindow_getHeight( | 
|  | 73 | args.nativeWindow.get()), | 
|  | 74 | args.nativeWindow, args.displaySurface}); | 
|  | 75 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 76 | mCompositionDisplay->createDisplayColorProfile( | 
|  | 77 | compositionengine::DisplayColorProfileCreationArgs{args.hasWideColorGamut, | 
|  | 78 | std::move(args.hdrCapabilities), | 
|  | 79 | args.supportedPerFrameMetadata, | 
|  | 80 | args.hwcColorModes}); | 
|  | 81 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 82 | if (!mCompositionDisplay->isValid()) { | 
|  | 83 | ALOGE("Composition Display did not validate!"); | 
|  | 84 | } | 
|  | 85 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 86 | mCompositionDisplay->getRenderSurface()->initialize(); | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 87 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 88 | setPowerMode(args.initialPowerMode); | 
| Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 89 |  | 
| Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 90 | // initialize the display orientation transform. | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 91 | setProjection(DisplayState::eOrientationDefault, Rect::INVALID_RECT, Rect::INVALID_RECT); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | } | 
|  | 93 |  | 
| Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 94 | DisplayDevice::~DisplayDevice() = default; | 
| Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 95 |  | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 96 | void DisplayDevice::disconnect() { | 
|  | 97 | mCompositionDisplay->disconnect(); | 
| Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 98 | } | 
|  | 99 |  | 
| Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 100 | int DisplayDevice::getWidth() const { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 101 | return mCompositionDisplay->getState().bounds.getWidth(); | 
| Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 102 | } | 
|  | 103 |  | 
| Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 104 | int DisplayDevice::getHeight() const { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 105 | return mCompositionDisplay->getState().bounds.getHeight(); | 
| Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 106 | } | 
|  | 107 |  | 
| Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 108 | void DisplayDevice::setDisplayName(const std::string& displayName) { | 
|  | 109 | if (!displayName.empty()) { | 
| Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 110 | // never override the name with an empty name | 
|  | 111 | mDisplayName = displayName; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 112 | mCompositionDisplay->setName(displayName); | 
| Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 113 | } | 
|  | 114 | } | 
|  | 115 |  | 
| Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 116 | uint32_t DisplayDevice::getPageFlipCount() const { | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 117 | return mCompositionDisplay->getRenderSurface()->getPageFlipCount(); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 118 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 119 |  | 
| Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 120 | // ---------------------------------------------------------------------------- | 
| Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 121 | void DisplayDevice::setPowerMode(int mode) { | 
|  | 122 | mPowerMode = mode; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 123 | getCompositionDisplay()->setCompositionEnabled(mPowerMode != HWC_POWER_MODE_OFF); | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 124 | } | 
|  | 125 |  | 
| Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 126 | int DisplayDevice::getPowerMode()  const { | 
|  | 127 | return mPowerMode; | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 128 | } | 
|  | 129 |  | 
| Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 130 | bool DisplayDevice::isPoweredOn() const { | 
|  | 131 | return mPowerMode != HWC_POWER_MODE_OFF; | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 132 | } | 
|  | 133 |  | 
|  | 134 | // ---------------------------------------------------------------------------- | 
| Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 135 | void DisplayDevice::setActiveConfig(HwcConfigIndexType mode) { | 
| Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 136 | mActiveConfig = mode; | 
|  | 137 | } | 
|  | 138 |  | 
| Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 139 | HwcConfigIndexType DisplayDevice::getActiveConfig() const { | 
| Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 140 | return mActiveConfig; | 
|  | 141 | } | 
|  | 142 |  | 
|  | 143 | // ---------------------------------------------------------------------------- | 
| Yiwei Zhang | 7c64f17 | 2018-03-07 14:52:28 -0800 | [diff] [blame] | 144 |  | 
| Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 145 | ui::Dataspace DisplayDevice::getCompositionDataSpace() const { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 146 | return mCompositionDisplay->getState().dataspace; | 
| Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 147 | } | 
|  | 148 |  | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 149 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 150 |  | 
| Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 151 | void DisplayDevice::setLayerStack(uint32_t stack) { | 
| Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 152 | mCompositionDisplay->setLayerStackFilter(stack, isPrimary()); | 
| Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 153 | } | 
|  | 154 |  | 
|  | 155 | // ---------------------------------------------------------------------------- | 
|  | 156 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 157 | uint32_t DisplayDevice::displayStateOrientationToTransformOrientation(int orientation) { | 
| Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 158 | switch (orientation) { | 
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 159 | case DisplayState::eOrientationDefault: | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 160 | return ui::Transform::ROT_0; | 
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 161 | case DisplayState::eOrientation90: | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 162 | return ui::Transform::ROT_90; | 
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 163 | case DisplayState::eOrientation180: | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 164 | return ui::Transform::ROT_180; | 
| Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 165 | case DisplayState::eOrientation270: | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 166 | return ui::Transform::ROT_270; | 
| Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 167 | default: | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 168 | return ui::Transform::ROT_INVALID; | 
|  | 169 | } | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | status_t DisplayDevice::orientationToTransfrom(int orientation, int w, int h, ui::Transform* tr) { | 
|  | 173 | uint32_t flags = displayStateOrientationToTransformOrientation(orientation); | 
|  | 174 | if (flags == ui::Transform::ROT_INVALID) { | 
| Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 175 | return BAD_VALUE; | 
|  | 176 | } | 
|  | 177 | tr->set(flags, w, h); | 
|  | 178 | return NO_ERROR; | 
|  | 179 | } | 
|  | 180 |  | 
| Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 181 | void DisplayDevice::setDisplaySize(const int newWidth, const int newHeight) { | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 182 | mCompositionDisplay->setBounds(ui::Size(newWidth, newHeight)); | 
| Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 183 | } | 
|  | 184 |  | 
| Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 185 | void DisplayDevice::setProjection(int orientation, | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 186 | const Rect& newViewport, const Rect& newFrame) { | 
|  | 187 | Rect viewport(newViewport); | 
|  | 188 | Rect frame(newFrame); | 
|  | 189 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 190 | mOrientation = orientation; | 
|  | 191 |  | 
|  | 192 | const Rect& displayBounds = getCompositionDisplay()->getState().bounds; | 
|  | 193 | const int w = displayBounds.width(); | 
|  | 194 | const int h = displayBounds.height(); | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 195 |  | 
| Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 196 | ui::Transform R; | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 197 | DisplayDevice::orientationToTransfrom(orientation, w, h, &R); | 
|  | 198 |  | 
|  | 199 | if (!frame.isValid()) { | 
|  | 200 | // the destination frame can be invalid if it has never been set, | 
|  | 201 | // in that case we assume the whole display frame. | 
|  | 202 | frame = Rect(w, h); | 
|  | 203 | } | 
|  | 204 |  | 
|  | 205 | if (viewport.isEmpty()) { | 
|  | 206 | // viewport can be invalid if it has never been set, in that case | 
|  | 207 | // we assume the whole display size. | 
|  | 208 | // it's also invalid to have an empty viewport, so we handle that | 
|  | 209 | // case in the same way. | 
|  | 210 | viewport = Rect(w, h); | 
| Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 211 | if (R.getOrientation() & ui::Transform::ROT_90) { | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 212 | // viewport is always specified in the logical orientation | 
|  | 213 | // of the display (ie: post-rotation). | 
| Peiyong Lin | 3db4234 | 2018-08-16 09:15:59 -0700 | [diff] [blame] | 214 | std::swap(viewport.right, viewport.bottom); | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 215 | } | 
|  | 216 | } | 
|  | 217 |  | 
| Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 218 | ui::Transform TL, TP, S; | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 219 | float src_width  = viewport.width(); | 
|  | 220 | float src_height = viewport.height(); | 
|  | 221 | float dst_width  = frame.width(); | 
|  | 222 | float dst_height = frame.height(); | 
|  | 223 | if (src_width != dst_width || src_height != dst_height) { | 
|  | 224 | float sx = dst_width  / src_width; | 
|  | 225 | float sy = dst_height / src_height; | 
|  | 226 | S.set(sx, 0, 0, sy); | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | float src_x = viewport.left; | 
|  | 230 | float src_y = viewport.top; | 
|  | 231 | float dst_x = frame.left; | 
|  | 232 | float dst_y = frame.top; | 
|  | 233 | TL.set(-src_x, -src_y); | 
|  | 234 | TP.set(dst_x, dst_y); | 
|  | 235 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 236 | // need to take care of primary display rotation for globalTransform | 
| Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 237 | // for case if the panel is not installed aligned with device orientation | 
| Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 238 | if (isPrimary()) { | 
| Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 239 | DisplayDevice::orientationToTransfrom( | 
| Chia-I Wu | a02871c | 2018-08-27 14:38:23 -0700 | [diff] [blame] | 240 | (orientation + mDisplayInstallOrientation) % (DisplayState::eOrientation270 + 1), | 
| Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 241 | w, h, &R); | 
|  | 242 | } | 
|  | 243 |  | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 244 | // The viewport and frame are both in the logical orientation. | 
|  | 245 | // Apply the logical translation, scale to physical size, apply the | 
|  | 246 | // physical translation and finally rotate to the physical orientation. | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 247 | ui::Transform globalTransform = R * TP * S * TL; | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 248 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 249 | const uint8_t type = globalTransform.getType(); | 
|  | 250 | const bool needsFiltering = | 
|  | 251 | (!globalTransform.preserveRects() || (type >= ui::Transform::SCALE)); | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 252 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 253 | Rect scissor = globalTransform.transform(viewport); | 
|  | 254 | if (scissor.isEmpty()) { | 
|  | 255 | scissor = displayBounds; | 
| Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 256 | } | 
|  | 257 |  | 
| LuK1337 | a4adfb1 | 2019-09-18 18:44:49 +0200 | [diff] [blame] | 258 | uint32_t transformOrientation; | 
|  | 259 |  | 
| Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 260 | if (isPrimary()) { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 261 | sPrimaryDisplayOrientation = displayStateOrientationToTransformOrientation(orientation); | 
| LuK1337 | a4adfb1 | 2019-09-18 18:44:49 +0200 | [diff] [blame] | 262 | transformOrientation = displayStateOrientationToTransformOrientation( | 
|  | 263 | (orientation + mDisplayInstallOrientation) % (DisplayState::eOrientation270 + 1)); | 
|  | 264 | } else { | 
|  | 265 | transformOrientation = displayStateOrientationToTransformOrientation(orientation); | 
| Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 266 | } | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 267 |  | 
| LuK1337 | a4adfb1 | 2019-09-18 18:44:49 +0200 | [diff] [blame] | 268 | getCompositionDisplay()->setProjection(globalTransform, transformOrientation, | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 269 | frame, viewport, scissor, needsFiltering); | 
| Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 270 | } | 
| Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 271 |  | 
| Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 272 | uint32_t DisplayDevice::getPrimaryDisplayOrientationTransform() { | 
|  | 273 | return sPrimaryDisplayOrientation; | 
|  | 274 | } | 
|  | 275 |  | 
| Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 276 | std::string DisplayDevice::getDebugName() const { | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 277 | const auto id = getId() ? to_string(*getId()) + ", " : std::string(); | 
| Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 278 | return base::StringPrintf("DisplayDevice{%s%s%s\"%s\"}", id.c_str(), | 
|  | 279 | isPrimary() ? "primary, " : "", isVirtual() ? "virtual, " : "", | 
|  | 280 | mDisplayName.c_str()); | 
|  | 281 | } | 
|  | 282 |  | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 283 | void DisplayDevice::dump(std::string& result) const { | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 284 | StringAppendF(&result, "+ %s\n", getDebugName().c_str()); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 285 |  | 
|  | 286 | result.append("   "); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 287 | StringAppendF(&result, "powerMode=%d, ", mPowerMode); | 
| Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 288 | StringAppendF(&result, "activeConfig=%d, ", mActiveConfig.value()); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 289 | getCompositionDisplay()->dump(result); | 
| Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 290 | } | 
| Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 291 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 292 | bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const { | 
|  | 293 | return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent); | 
| Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 294 | } | 
|  | 295 |  | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 296 | // ---------------------------------------------------------------------------- | 
|  | 297 |  | 
|  | 298 | const std::optional<DisplayId>& DisplayDevice::getId() const { | 
|  | 299 | return mCompositionDisplay->getId(); | 
|  | 300 | } | 
|  | 301 |  | 
|  | 302 | bool DisplayDevice::isSecure() const { | 
|  | 303 | return mCompositionDisplay->isSecure(); | 
|  | 304 | } | 
|  | 305 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 306 | const Rect& DisplayDevice::getBounds() const { | 
|  | 307 | return mCompositionDisplay->getState().bounds; | 
|  | 308 | } | 
|  | 309 |  | 
|  | 310 | const Region& DisplayDevice::getUndefinedRegion() const { | 
|  | 311 | return mCompositionDisplay->getState().undefinedRegion; | 
|  | 312 | } | 
|  | 313 |  | 
|  | 314 | bool DisplayDevice::needsFiltering() const { | 
|  | 315 | return mCompositionDisplay->getState().needsFiltering; | 
|  | 316 | } | 
|  | 317 |  | 
|  | 318 | uint32_t DisplayDevice::getLayerStack() const { | 
| Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 319 | return mCompositionDisplay->getState().layerStackId; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 320 | } | 
|  | 321 |  | 
|  | 322 | const ui::Transform& DisplayDevice::getTransform() const { | 
|  | 323 | return mCompositionDisplay->getState().transform; | 
|  | 324 | } | 
|  | 325 |  | 
|  | 326 | const Rect& DisplayDevice::getViewport() const { | 
|  | 327 | return mCompositionDisplay->getState().viewport; | 
|  | 328 | } | 
|  | 329 |  | 
|  | 330 | const Rect& DisplayDevice::getFrame() const { | 
|  | 331 | return mCompositionDisplay->getState().frame; | 
|  | 332 | } | 
|  | 333 |  | 
|  | 334 | const Rect& DisplayDevice::getScissor() const { | 
|  | 335 | return mCompositionDisplay->getState().scissor; | 
|  | 336 | } | 
|  | 337 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 338 | bool DisplayDevice::hasWideColorGamut() const { | 
|  | 339 | return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut(); | 
|  | 340 | } | 
|  | 341 |  | 
|  | 342 | bool DisplayDevice::hasHDR10PlusSupport() const { | 
|  | 343 | return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport(); | 
|  | 344 | } | 
|  | 345 |  | 
|  | 346 | bool DisplayDevice::hasHDR10Support() const { | 
|  | 347 | return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support(); | 
|  | 348 | } | 
|  | 349 |  | 
|  | 350 | bool DisplayDevice::hasHLGSupport() const { | 
|  | 351 | return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport(); | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 | bool DisplayDevice::hasDolbyVisionSupport() const { | 
|  | 355 | return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport(); | 
|  | 356 | } | 
|  | 357 |  | 
|  | 358 | int DisplayDevice::getSupportedPerFrameMetadata() const { | 
|  | 359 | return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata(); | 
|  | 360 | } | 
|  | 361 |  | 
|  | 362 | const HdrCapabilities& DisplayDevice::getHdrCapabilities() const { | 
|  | 363 | return mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities(); | 
|  | 364 | } | 
|  | 365 |  | 
| Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 366 | std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1); | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 367 |  | 
|  | 368 | }  // namespace android |