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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 21 | // #define LOG_NDEBUG 0 |
| 22 | #undef LOG_TAG |
| 23 | #define LOG_TAG "DisplayDevice" |
| 24 | |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 25 | #include <android-base/stringprintf.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 26 | #include <compositionengine/CompositionEngine.h> |
| 27 | #include <compositionengine/Display.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 28 | #include <compositionengine/DisplayColorProfile.h> |
| 29 | #include <compositionengine/DisplayColorProfileCreationArgs.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 30 | #include <compositionengine/DisplayCreationArgs.h> |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 31 | #include <compositionengine/DisplaySurface.h> |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 32 | #include <compositionengine/ProjectionSpace.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 33 | #include <compositionengine/RenderSurface.h> |
| 34 | #include <compositionengine/RenderSurfaceCreationArgs.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 35 | #include <compositionengine/impl/OutputCompositionState.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 36 | #include <configstore/Utils.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 37 | #include <log/log.h> |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 38 | #include <system/window.h> |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 39 | #include <ui/GraphicTypes.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 41 | #include "DisplayDevice.h" |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 42 | #include "Layer.h" |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 43 | #include "SurfaceFlinger.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 44 | |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 45 | namespace android { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 47 | namespace hal = hardware::graphics::composer::hal; |
| 48 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 49 | using android::base::StringAppendF; |
Jaesoo Lee | 720a724 | 2017-01-31 15:26:18 +0900 | [diff] [blame] | 50 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 51 | ui::Transform::RotationFlags DisplayDevice::sPrimaryDisplayRotationFlags = ui::Transform::ROT_0; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 52 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 53 | DisplayDeviceCreationArgs::DisplayDeviceCreationArgs( |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 54 | const sp<SurfaceFlinger>& flinger, HWComposer& hwComposer, const wp<IBinder>& displayToken, |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 55 | std::shared_ptr<compositionengine::Display> compositionDisplay) |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 56 | : flinger(flinger), |
| 57 | hwComposer(hwComposer), |
| 58 | displayToken(displayToken), |
| 59 | compositionDisplay(compositionDisplay) {} |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 60 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 61 | DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args) |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 62 | : mFlinger(args.flinger), |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 63 | mHwComposer(args.hwComposer), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 64 | mDisplayToken(args.displayToken), |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 65 | mSequenceId(args.sequenceId), |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 66 | mConnectionType(args.connectionType), |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 67 | mCompositionDisplay{args.compositionDisplay}, |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 68 | mPhysicalOrientation(args.physicalOrientation), |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 69 | mSupportedModes(std::move(args.supportedModes)), |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 70 | mIsPrimary(args.isPrimary) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 71 | mCompositionDisplay->editState().isSecure = args.isSecure; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 72 | mCompositionDisplay->createRenderSurface( |
Dominik Laskowski | b9ac3e1 | 2021-04-23 13:01:16 -0700 | [diff] [blame] | 73 | compositionengine::RenderSurfaceCreationArgsBuilder() |
| 74 | .setDisplayWidth(ANativeWindow_getWidth(args.nativeWindow.get())) |
| 75 | .setDisplayHeight(ANativeWindow_getHeight(args.nativeWindow.get())) |
| 76 | .setNativeWindow(std::move(args.nativeWindow)) |
| 77 | .setDisplaySurface(std::move(args.displaySurface)) |
| 78 | .setMaxTextureCacheSize( |
| 79 | static_cast<size_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers)) |
| 80 | .build()); |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 81 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 82 | if (!mFlinger->mDisableClientCompositionCache && |
| 83 | SurfaceFlinger::maxFrameBufferAcquiredBuffers > 0) { |
| 84 | mCompositionDisplay->createClientCompositionCache( |
| 85 | static_cast<uint32_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers)); |
| 86 | } |
| 87 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 88 | mCompositionDisplay->createDisplayColorProfile( |
| 89 | compositionengine::DisplayColorProfileCreationArgs{args.hasWideColorGamut, |
| 90 | std::move(args.hdrCapabilities), |
| 91 | args.supportedPerFrameMetadata, |
| 92 | args.hwcColorModes}); |
| 93 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 94 | if (!mCompositionDisplay->isValid()) { |
| 95 | ALOGE("Composition Display did not validate!"); |
| 96 | } |
| 97 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 98 | mCompositionDisplay->getRenderSurface()->initialize(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 99 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 100 | setPowerMode(args.initialPowerMode); |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 101 | |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 102 | // initialize the display orientation transform. |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 103 | setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 106 | DisplayDevice::~DisplayDevice() = default; |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 107 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 108 | void DisplayDevice::disconnect() { |
| 109 | mCompositionDisplay->disconnect(); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 112 | int DisplayDevice::getWidth() const { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 113 | return mCompositionDisplay->getState().displaySpace.bounds.getWidth(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 116 | int DisplayDevice::getHeight() const { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 117 | return mCompositionDisplay->getState().displaySpace.bounds.getHeight(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 120 | void DisplayDevice::setDisplayName(const std::string& displayName) { |
| 121 | if (!displayName.empty()) { |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 122 | // never override the name with an empty name |
| 123 | mDisplayName = displayName; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 124 | mCompositionDisplay->setName(displayName); |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 128 | void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info) { |
| 129 | mDeviceProductInfo = std::move(info); |
| 130 | } |
| 131 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 132 | uint32_t DisplayDevice::getPageFlipCount() const { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 133 | return mCompositionDisplay->getRenderSurface()->getPageFlipCount(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 134 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 135 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 136 | // ---------------------------------------------------------------------------- |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 137 | void DisplayDevice::setPowerMode(hal::PowerMode mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 138 | mPowerMode = mode; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 139 | getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF); |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 142 | void DisplayDevice::enableLayerCaching(bool enable) { |
| 143 | getCompositionDisplay()->setLayerCachingEnabled(enable); |
| 144 | } |
| 145 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 146 | hal::PowerMode DisplayDevice::getPowerMode() const { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 147 | return mPowerMode; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 150 | bool DisplayDevice::isPoweredOn() const { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 151 | return mPowerMode != hal::PowerMode::OFF; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 154 | void DisplayDevice::setActiveMode(DisplayModeId id) { |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 155 | const auto mode = getMode(id); |
| 156 | LOG_FATAL_IF(!mode, "Cannot set active mode which is not supported."); |
| 157 | mActiveMode = mode; |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 160 | status_t DisplayDevice::initiateModeChange(DisplayModeId modeId, |
| 161 | const hal::VsyncPeriodChangeConstraints& constraints, |
| 162 | hal::VsyncPeriodChangeTimeline* outTimeline) const { |
| 163 | const auto mode = getMode(modeId); |
| 164 | if (!mode) { |
| 165 | ALOGE("Trying to initiate a mode change to invalid mode %s on display %s", |
| 166 | std::to_string(modeId.value()).c_str(), to_string(getId()).c_str()); |
| 167 | return BAD_VALUE; |
| 168 | } |
| 169 | return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), mode->getHwcId(), constraints, |
| 170 | outTimeline); |
| 171 | } |
| 172 | |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 173 | const DisplayModePtr& DisplayDevice::getActiveMode() const { |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 174 | return mActiveMode; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | const DisplayModes& DisplayDevice::getSupportedModes() const { |
| 178 | return mSupportedModes; |
| 179 | } |
| 180 | |
| 181 | DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const { |
Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 182 | const auto it = std::find_if(mSupportedModes.begin(), mSupportedModes.end(), |
| 183 | [&](DisplayModePtr mode) { return mode->getId() == modeId; }); |
| 184 | if (it != mSupportedModes.end()) { |
| 185 | return *it; |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 186 | } |
| 187 | return nullptr; |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 190 | nsecs_t DisplayDevice::getVsyncPeriodFromHWC() const { |
| 191 | const auto physicalId = getPhysicalId(); |
| 192 | if (!mHwComposer.isConnected(physicalId)) { |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | nsecs_t vsyncPeriod; |
| 197 | const auto status = mHwComposer.getDisplayVsyncPeriod(physicalId, &vsyncPeriod); |
| 198 | if (status == NO_ERROR) { |
| 199 | return vsyncPeriod; |
| 200 | } |
| 201 | |
| 202 | return getActiveMode()->getFps().getPeriodNsecs(); |
| 203 | } |
| 204 | |
| 205 | nsecs_t DisplayDevice::getRefreshTimestamp() const { |
| 206 | const nsecs_t now = systemTime(CLOCK_MONOTONIC); |
| 207 | const auto vsyncPeriodNanos = getVsyncPeriodFromHWC(); |
| 208 | return now - ((now - mLastHwVsync) % vsyncPeriodNanos); |
| 209 | } |
| 210 | |
| 211 | void DisplayDevice::onVsync(nsecs_t timestamp) { |
| 212 | mLastHwVsync = timestamp; |
| 213 | } |
| 214 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 215 | ui::Dataspace DisplayDevice::getCompositionDataSpace() const { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 216 | return mCompositionDisplay->getState().dataspace; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 219 | void DisplayDevice::setLayerStack(ui::LayerStack stack) { |
Ady Abraham | 7825c68 | 2021-05-17 15:12:14 -0700 | [diff] [blame^] | 220 | mCompositionDisplay->setLayerStackFilter(stack, isInternal()); |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 223 | void DisplayDevice::setFlags(uint32_t flags) { |
| 224 | mFlags = flags; |
| 225 | } |
| 226 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 227 | void DisplayDevice::setDisplaySize(int width, int height) { |
Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 228 | LOG_FATAL_IF(!isVirtual(), "Changing the display size is supported only for virtual displays."); |
| 229 | mCompositionDisplay->setDisplaySize(ui::Size(width, height)); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 232 | void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpaceRect, |
| 233 | Rect orientedDisplaySpaceRect) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 234 | mOrientation = orientation; |
| 235 | |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 236 | if (isPrimary()) { |
| 237 | sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation); |
| 238 | } |
| 239 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 240 | if (!orientedDisplaySpaceRect.isValid()) { |
Marin Shalamanov | 4429cac | 2020-10-01 12:56:24 +0200 | [diff] [blame] | 241 | // The destination frame can be invalid if it has never been set, |
| 242 | // in that case we assume the whole display size. |
| 243 | orientedDisplaySpaceRect = getCompositionDisplay()->getState().displaySpace.bounds; |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 246 | if (layerStackSpaceRect.isEmpty()) { |
Marin Shalamanov | 4429cac | 2020-10-01 12:56:24 +0200 | [diff] [blame] | 247 | // The layerStackSpaceRect can be invalid if it has never been set, in that case |
| 248 | // we assume the whole framebuffer size. |
| 249 | layerStackSpaceRect = getCompositionDisplay()->getState().framebufferSpace.bounds; |
Marin Shalamanov | 8c23c4e | 2020-08-19 15:26:31 +0200 | [diff] [blame] | 250 | if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 251 | std::swap(layerStackSpaceRect.right, layerStackSpaceRect.bottom); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Marin Shalamanov | 8c23c4e | 2020-08-19 15:26:31 +0200 | [diff] [blame] | 255 | // We need to take care of display rotation for globalTransform for case if the panel is not |
| 256 | // installed aligned with device orientation. |
| 257 | const auto transformOrientation = orientation + mPhysicalOrientation; |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 258 | getCompositionDisplay()->setProjection(transformOrientation, layerStackSpaceRect, |
| 259 | orientedDisplaySpaceRect); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 260 | } |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 261 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 262 | ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() { |
| 263 | return sPrimaryDisplayRotationFlags; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 266 | std::string DisplayDevice::getDebugName() const { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 267 | const char* type = "virtual"; |
| 268 | if (mConnectionType) { |
Ady Abraham | 7825c68 | 2021-05-17 15:12:14 -0700 | [diff] [blame^] | 269 | type = isInternal() ? "internal" : "external"; |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 272 | return base::StringPrintf("DisplayDevice{%s, %s%s, \"%s\"}", to_string(getId()).c_str(), type, |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 273 | isPrimary() ? ", primary" : "", mDisplayName.c_str()); |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 276 | void DisplayDevice::dump(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 277 | StringAppendF(&result, "+ %s\n", getDebugName().c_str()); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 278 | StringAppendF(&result, " powerMode=%s (%d)\n", to_string(mPowerMode).c_str(), |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 279 | static_cast<int32_t>(mPowerMode)); |
Marin Shalamanov | 84b8548 | 2021-05-05 13:54:35 +0200 | [diff] [blame] | 280 | const auto activeMode = getActiveMode(); |
Alec Mouri | 934e0cf | 2021-02-09 14:54:10 -0800 | [diff] [blame] | 281 | StringAppendF(&result, " activeMode=%s\n", |
Marin Shalamanov | 84b8548 | 2021-05-05 13:54:35 +0200 | [diff] [blame] | 282 | activeMode ? to_string(*activeMode).c_str() : "none"); |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 283 | |
| 284 | result.append(" supportedModes=\n"); |
| 285 | |
| 286 | for (const auto& mode : mSupportedModes) { |
| 287 | result.append(" "); |
| 288 | result.append(to_string(*mode)); |
| 289 | result.append("\n"); |
| 290 | } |
| 291 | StringAppendF(&result, " deviceProductInfo="); |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 292 | if (mDeviceProductInfo) { |
| 293 | mDeviceProductInfo->dump(result); |
| 294 | } else { |
| 295 | result.append("{}"); |
| 296 | } |
Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 297 | result.append("\n"); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 298 | getCompositionDisplay()->dump(result); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 299 | } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 300 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 301 | bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const { |
| 302 | return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent); |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 305 | DisplayId DisplayDevice::getId() const { |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 306 | return mCompositionDisplay->getId(); |
| 307 | } |
| 308 | |
| 309 | bool DisplayDevice::isSecure() const { |
| 310 | return mCompositionDisplay->isSecure(); |
| 311 | } |
| 312 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 313 | const Rect& DisplayDevice::getBounds() const { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 314 | return mCompositionDisplay->getState().displaySpace.bounds; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | const Region& DisplayDevice::getUndefinedRegion() const { |
| 318 | return mCompositionDisplay->getState().undefinedRegion; |
| 319 | } |
| 320 | |
| 321 | bool DisplayDevice::needsFiltering() const { |
| 322 | return mCompositionDisplay->getState().needsFiltering; |
| 323 | } |
| 324 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 325 | ui::LayerStack DisplayDevice::getLayerStack() const { |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 326 | return mCompositionDisplay->getState().layerStackId; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Garfield Tan | 54edd91 | 2020-10-21 16:31:41 -0700 | [diff] [blame] | 329 | ui::Transform::RotationFlags DisplayDevice::getTransformHint() const { |
| 330 | return mCompositionDisplay->getTransformHint(); |
| 331 | } |
| 332 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 333 | const ui::Transform& DisplayDevice::getTransform() const { |
| 334 | return mCompositionDisplay->getState().transform; |
| 335 | } |
| 336 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 337 | const Rect& DisplayDevice::getLayerStackSpaceRect() const { |
| 338 | return mCompositionDisplay->getState().layerStackSpace.content; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 341 | const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const { |
| 342 | return mCompositionDisplay->getState().orientedDisplaySpace.content; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 345 | bool DisplayDevice::hasWideColorGamut() const { |
| 346 | return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut(); |
| 347 | } |
| 348 | |
| 349 | bool DisplayDevice::hasHDR10PlusSupport() const { |
| 350 | return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport(); |
| 351 | } |
| 352 | |
| 353 | bool DisplayDevice::hasHDR10Support() const { |
| 354 | return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support(); |
| 355 | } |
| 356 | |
| 357 | bool DisplayDevice::hasHLGSupport() const { |
| 358 | return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport(); |
| 359 | } |
| 360 | |
| 361 | bool DisplayDevice::hasDolbyVisionSupport() const { |
| 362 | return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport(); |
| 363 | } |
| 364 | |
| 365 | int DisplayDevice::getSupportedPerFrameMetadata() const { |
| 366 | return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata(); |
| 367 | } |
| 368 | |
Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 369 | void DisplayDevice::overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes) { |
| 370 | mOverrideHdrTypes = hdrTypes; |
| 371 | } |
| 372 | |
| 373 | HdrCapabilities DisplayDevice::getHdrCapabilities() const { |
| 374 | const HdrCapabilities& capabilities = |
| 375 | mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities(); |
| 376 | std::vector<ui::Hdr> hdrTypes = capabilities.getSupportedHdrTypes(); |
| 377 | if (!mOverrideHdrTypes.empty()) { |
| 378 | hdrTypes = mOverrideHdrTypes; |
| 379 | } |
| 380 | return HdrCapabilities(hdrTypes, capabilities.getDesiredMaxLuminance(), |
| 381 | capabilities.getDesiredMaxAverageLuminance(), |
| 382 | capabilities.getDesiredMinLuminance()); |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 385 | std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1); |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 386 | |
| 387 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 388 | |
| 389 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 390 | #pragma clang diagnostic pop // ignored "-Wconversion" |