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( |
| 54 | const sp<SurfaceFlinger>& flinger, const wp<IBinder>& displayToken, |
| 55 | std::shared_ptr<compositionengine::Display> compositionDisplay) |
| 56 | : flinger(flinger), displayToken(displayToken), compositionDisplay(compositionDisplay) {} |
Chia-I Wu | be02ec0 | 2018-05-18 10:59:36 -0700 | [diff] [blame] | 57 | |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 58 | DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args) |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 59 | : mFlinger(args.flinger), |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 60 | mDisplayToken(args.displayToken), |
Dominik Laskowski | e977409 | 2018-12-11 10:04:24 -0800 | [diff] [blame] | 61 | mSequenceId(args.sequenceId), |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 62 | mConnectionType(args.connectionType), |
Lloyd Pique | aad4ebf | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 63 | mCompositionDisplay{args.compositionDisplay}, |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 64 | mPhysicalOrientation(args.physicalOrientation), |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 65 | mIsPrimary(args.isPrimary) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 66 | mCompositionDisplay->editState().isSecure = args.isSecure; |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 67 | mCompositionDisplay->createRenderSurface( |
| 68 | compositionengine::RenderSurfaceCreationArgs{ANativeWindow_getWidth( |
| 69 | args.nativeWindow.get()), |
| 70 | ANativeWindow_getHeight( |
| 71 | args.nativeWindow.get()), |
| 72 | args.nativeWindow, args.displaySurface}); |
| 73 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 74 | if (!mFlinger->mDisableClientCompositionCache && |
| 75 | SurfaceFlinger::maxFrameBufferAcquiredBuffers > 0) { |
| 76 | mCompositionDisplay->createClientCompositionCache( |
| 77 | static_cast<uint32_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers)); |
| 78 | } |
| 79 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 80 | mCompositionDisplay->createDisplayColorProfile( |
| 81 | compositionengine::DisplayColorProfileCreationArgs{args.hasWideColorGamut, |
| 82 | std::move(args.hdrCapabilities), |
| 83 | args.supportedPerFrameMetadata, |
| 84 | args.hwcColorModes}); |
| 85 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 86 | if (!mCompositionDisplay->isValid()) { |
| 87 | ALOGE("Composition Display did not validate!"); |
| 88 | } |
| 89 | |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 90 | mCompositionDisplay->getRenderSurface()->initialize(); |
Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 91 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 92 | setPowerMode(args.initialPowerMode); |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 93 | |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 94 | // initialize the display orientation transform. |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 95 | 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] | 96 | } |
| 97 | |
Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 98 | DisplayDevice::~DisplayDevice() = default; |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 99 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 100 | void DisplayDevice::disconnect() { |
| 101 | mCompositionDisplay->disconnect(); |
Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 104 | int DisplayDevice::getWidth() const { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 105 | return mCompositionDisplay->getState().displaySpace.bounds.getWidth(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 108 | int DisplayDevice::getHeight() const { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 109 | return mCompositionDisplay->getState().displaySpace.bounds.getHeight(); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 112 | void DisplayDevice::setDisplayName(const std::string& displayName) { |
| 113 | if (!displayName.empty()) { |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 114 | // never override the name with an empty name |
| 115 | mDisplayName = displayName; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 116 | mCompositionDisplay->setName(displayName); |
Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 120 | void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info) { |
| 121 | mDeviceProductInfo = std::move(info); |
| 122 | } |
| 123 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 124 | uint32_t DisplayDevice::getPageFlipCount() const { |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 125 | return mCompositionDisplay->getRenderSurface()->getPageFlipCount(); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 126 | } |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 127 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 128 | // ---------------------------------------------------------------------------- |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 129 | void DisplayDevice::setPowerMode(hal::PowerMode mode) { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 130 | mPowerMode = mode; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 131 | getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF); |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 134 | hal::PowerMode DisplayDevice::getPowerMode() const { |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 135 | return mPowerMode; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 138 | bool DisplayDevice::isPoweredOn() const { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 139 | return mPowerMode != hal::PowerMode::OFF; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 142 | void DisplayDevice::setActiveConfig(HwcConfigIndexType mode) { |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 143 | mActiveConfig = mode; |
| 144 | } |
| 145 | |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 146 | HwcConfigIndexType DisplayDevice::getActiveConfig() const { |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 147 | return mActiveConfig; |
| 148 | } |
| 149 | |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 150 | ui::Dataspace DisplayDevice::getCompositionDataSpace() const { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 151 | return mCompositionDisplay->getState().dataspace; |
Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 154 | void DisplayDevice::setLayerStack(ui::LayerStack stack) { |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 155 | mCompositionDisplay->setLayerStackFilter(stack, isPrimary()); |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 158 | void DisplayDevice::setDisplaySize(int width, int height) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 159 | mCompositionDisplay->setDisplaySpaceSize(ui::Size(width, height)); |
Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 162 | void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpaceRect, |
| 163 | Rect orientedDisplaySpaceRect) { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 164 | mOrientation = orientation; |
| 165 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 166 | const Rect& displayBounds = getCompositionDisplay()->getState().displaySpace.bounds; |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 167 | const int displayWidth = displayBounds.width(); |
| 168 | const int displayHeight = displayBounds.height(); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 169 | |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 170 | ui::Transform rotation; |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 171 | if (const auto flags = ui::Transform::toRotationFlags(orientation); |
| 172 | flags != ui::Transform::ROT_INVALID) { |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 173 | rotation.set(flags, displayWidth, displayHeight); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 174 | } |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 175 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 176 | if (!orientedDisplaySpaceRect.isValid()) { |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 177 | // the destination frame can be invalid if it has never been set, |
| 178 | // in that case we assume the whole display frame. |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 179 | orientedDisplaySpaceRect = Rect(displayWidth, displayHeight); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 182 | if (layerStackSpaceRect.isEmpty()) { |
| 183 | // layerStackSpaceRect can be invalid if it has never been set, in that case |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 184 | // we assume the whole display size. |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 185 | // It's also invalid to have an empty layerStackSpaceRect, so we handle that |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 186 | // case in the same way. |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 187 | layerStackSpaceRect = Rect(displayWidth, displayHeight); |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 188 | if (rotation.getOrientation() & ui::Transform::ROT_90) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 189 | std::swap(layerStackSpaceRect.right, layerStackSpaceRect.bottom); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 193 | ui::Transform logicalTranslation, physicalTranslation, scale; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 194 | const float sourceWidth = layerStackSpaceRect.width(); |
| 195 | const float sourceHeight = layerStackSpaceRect.height(); |
| 196 | const float destWidth = orientedDisplaySpaceRect.width(); |
| 197 | const float destHeight = orientedDisplaySpaceRect.height(); |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 198 | if (sourceWidth != destWidth || sourceHeight != destHeight) { |
| 199 | const float scaleX = destWidth / sourceWidth; |
| 200 | const float scaleY = destHeight / sourceHeight; |
| 201 | scale.set(scaleX, 0, 0, scaleY); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 204 | const float sourceX = layerStackSpaceRect.left; |
| 205 | const float sourceY = layerStackSpaceRect.top; |
| 206 | const float destX = orientedDisplaySpaceRect.left; |
| 207 | const float destY = orientedDisplaySpaceRect.top; |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 208 | logicalTranslation.set(-sourceX, -sourceY); |
| 209 | physicalTranslation.set(destX, destY); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 210 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 211 | // need to take care of primary display rotation for globalTransform |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 212 | // for case if the panel is not installed aligned with device orientation |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 213 | if (isPrimary()) { |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 214 | if (const auto flags = ui::Transform::toRotationFlags(orientation + mPhysicalOrientation); |
| 215 | flags != ui::Transform::ROT_INVALID) { |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 216 | rotation.set(flags, displayWidth, displayHeight); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 217 | } |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 218 | } |
| 219 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 220 | // The layerStackSpaceRect and orientedDisplaySpaceRect are both in the logical orientation. |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 221 | // Apply the logical translation, scale to physical size, apply the |
| 222 | // physical translation and finally rotate to the physical orientation. |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 223 | ui::Transform globalTransform = rotation * physicalTranslation * scale * logicalTranslation; |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 224 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 225 | const uint8_t type = globalTransform.getType(); |
| 226 | const bool needsFiltering = |
| 227 | (!globalTransform.preserveRects() || (type >= ui::Transform::SCALE)); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 228 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 229 | Rect displaySpaceRect = globalTransform.transform(layerStackSpaceRect); |
| 230 | if (displaySpaceRect.isEmpty()) { |
| 231 | displaySpaceRect = displayBounds; |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 232 | } |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 233 | // Make sure the displaySpaceRect is contained in the display bounds |
| 234 | displaySpaceRect.intersect(displayBounds, &displaySpaceRect); |
Mathias Agopian | f5f714a | 2013-02-26 16:54:05 -0800 | [diff] [blame] | 235 | |
LuK1337 | a4adfb1 | 2019-09-18 18:44:49 +0200 | [diff] [blame] | 236 | uint32_t transformOrientation; |
| 237 | |
Dominik Laskowski | 281644e | 2018-04-19 15:47:35 -0700 | [diff] [blame] | 238 | if (isPrimary()) { |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 239 | sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation); |
| 240 | transformOrientation = ui::Transform::toRotationFlags(orientation + mPhysicalOrientation); |
LuK1337 | a4adfb1 | 2019-09-18 18:44:49 +0200 | [diff] [blame] | 241 | } else { |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 242 | transformOrientation = ui::Transform::toRotationFlags(orientation); |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 243 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 244 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 245 | getCompositionDisplay()->setProjection(globalTransform, transformOrientation, |
| 246 | orientedDisplaySpaceRect, layerStackSpaceRect, |
| 247 | displaySpaceRect, needsFiltering); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 248 | } |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 249 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 250 | ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() { |
| 251 | return sPrimaryDisplayRotationFlags; |
Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 254 | std::string DisplayDevice::getDebugName() const { |
Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 255 | std::string displayId; |
| 256 | if (const auto id = getId()) { |
| 257 | displayId = to_string(*id) + ", "; |
| 258 | } |
| 259 | |
| 260 | const char* type = "virtual"; |
| 261 | if (mConnectionType) { |
| 262 | type = *mConnectionType == DisplayConnectionType::Internal ? "internal" : "external"; |
| 263 | } |
| 264 | |
| 265 | return base::StringPrintf("DisplayDevice{%s%s%s, \"%s\"}", displayId.c_str(), type, |
| 266 | isPrimary() ? ", primary" : "", mDisplayName.c_str()); |
Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 269 | void DisplayDevice::dump(std::string& result) const { |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 270 | StringAppendF(&result, "+ %s\n", getDebugName().c_str()); |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 271 | |
| 272 | result.append(" "); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 273 | StringAppendF(&result, "powerMode=%s (%d), ", to_string(mPowerMode).c_str(), |
| 274 | static_cast<int32_t>(mPowerMode)); |
Ady Abraham | 2139f73 | 2019-11-13 18:56:40 -0800 | [diff] [blame] | 275 | StringAppendF(&result, "activeConfig=%d, ", mActiveConfig.value()); |
Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 276 | StringAppendF(&result, "deviceProductInfo="); |
| 277 | if (mDeviceProductInfo) { |
| 278 | mDeviceProductInfo->dump(result); |
| 279 | } else { |
| 280 | result.append("{}"); |
| 281 | } |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 282 | getCompositionDisplay()->dump(result); |
Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 283 | } |
Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 284 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 285 | bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const { |
| 286 | return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent); |
Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 289 | // ---------------------------------------------------------------------------- |
| 290 | |
| 291 | const std::optional<DisplayId>& DisplayDevice::getId() const { |
| 292 | return mCompositionDisplay->getId(); |
| 293 | } |
| 294 | |
| 295 | bool DisplayDevice::isSecure() const { |
| 296 | return mCompositionDisplay->isSecure(); |
| 297 | } |
| 298 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 299 | const Rect& DisplayDevice::getBounds() const { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 300 | return mCompositionDisplay->getState().displaySpace.bounds; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | const Region& DisplayDevice::getUndefinedRegion() const { |
| 304 | return mCompositionDisplay->getState().undefinedRegion; |
| 305 | } |
| 306 | |
| 307 | bool DisplayDevice::needsFiltering() const { |
| 308 | return mCompositionDisplay->getState().needsFiltering; |
| 309 | } |
| 310 | |
Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 311 | ui::LayerStack DisplayDevice::getLayerStack() const { |
Lloyd Pique | ef36b00 | 2019-01-23 17:52:04 -0800 | [diff] [blame] | 312 | return mCompositionDisplay->getState().layerStackId; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | const ui::Transform& DisplayDevice::getTransform() const { |
| 316 | return mCompositionDisplay->getState().transform; |
| 317 | } |
| 318 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 319 | const Rect& DisplayDevice::getLayerStackSpaceRect() const { |
| 320 | return mCompositionDisplay->getState().layerStackSpace.content; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 323 | const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const { |
| 324 | return mCompositionDisplay->getState().orientedDisplaySpace.content; |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 327 | bool DisplayDevice::hasWideColorGamut() const { |
| 328 | return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut(); |
| 329 | } |
| 330 | |
| 331 | bool DisplayDevice::hasHDR10PlusSupport() const { |
| 332 | return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport(); |
| 333 | } |
| 334 | |
| 335 | bool DisplayDevice::hasHDR10Support() const { |
| 336 | return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support(); |
| 337 | } |
| 338 | |
| 339 | bool DisplayDevice::hasHLGSupport() const { |
| 340 | return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport(); |
| 341 | } |
| 342 | |
| 343 | bool DisplayDevice::hasDolbyVisionSupport() const { |
| 344 | return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport(); |
| 345 | } |
| 346 | |
| 347 | int DisplayDevice::getSupportedPerFrameMetadata() const { |
| 348 | return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata(); |
| 349 | } |
| 350 | |
| 351 | const HdrCapabilities& DisplayDevice::getHdrCapabilities() const { |
| 352 | return mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities(); |
| 353 | } |
| 354 | |
Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 355 | std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1); |
Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 356 | |
| 357 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 358 | |
| 359 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 360 | #pragma clang diagnostic pop // ignored "-Wconversion" |