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