| 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 |  | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 25 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
|  | 26 |  | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 27 | #include <compositionengine/CompositionEngine.h> | 
|  | 28 | #include <compositionengine/Display.h> | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 29 | #include <compositionengine/DisplayColorProfile.h> | 
|  | 30 | #include <compositionengine/DisplayColorProfileCreationArgs.h> | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 31 | #include <compositionengine/DisplayCreationArgs.h> | 
| Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 32 | #include <compositionengine/DisplaySurface.h> | 
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 33 | #include <compositionengine/ProjectionSpace.h> | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 34 | #include <compositionengine/RenderSurface.h> | 
|  | 35 | #include <compositionengine/RenderSurfaceCreationArgs.h> | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 36 | #include <compositionengine/impl/OutputCompositionState.h> | 
| Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 37 | #include <configstore/Utils.h> | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 38 | #include <log/log.h> | 
| Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 39 | #include <system/window.h> | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 40 | #include <ui/GraphicTypes.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 42 | #include "DisplayDevice.h" | 
| Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 43 | #include "Layer.h" | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 44 | #include "RefreshRateOverlay.h" | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 45 | #include "SurfaceFlinger.h" | 
| Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 46 |  | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 47 | namespace android { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 |  | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 49 | namespace hal = hardware::graphics::composer::hal; | 
|  | 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}, | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 68 | mActiveModeFPSTrace("ActiveModeFPS -" + to_string(getId())), | 
|  | 69 | mActiveModeFPSHwcTrace("ActiveModeFPS_HWC -" + to_string(getId())), | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 70 | mPhysicalOrientation(args.physicalOrientation), | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 71 | mSupportedModes(std::move(args.supportedModes)), | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 72 | mIsPrimary(args.isPrimary), | 
|  | 73 | mRefreshRateConfigs(std::move(args.refreshRateConfigs)) { | 
| Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 74 | mCompositionDisplay->editState().isSecure = args.isSecure; | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 75 | mCompositionDisplay->createRenderSurface( | 
| Dominik Laskowski | b9ac3e1 | 2021-04-23 13:01:16 -0700 | [diff] [blame] | 76 | compositionengine::RenderSurfaceCreationArgsBuilder() | 
|  | 77 | .setDisplayWidth(ANativeWindow_getWidth(args.nativeWindow.get())) | 
|  | 78 | .setDisplayHeight(ANativeWindow_getHeight(args.nativeWindow.get())) | 
|  | 79 | .setNativeWindow(std::move(args.nativeWindow)) | 
|  | 80 | .setDisplaySurface(std::move(args.displaySurface)) | 
|  | 81 | .setMaxTextureCacheSize( | 
|  | 82 | static_cast<size_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers)) | 
|  | 83 | .build()); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 84 |  | 
| Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 85 | if (!mFlinger->mDisableClientCompositionCache && | 
|  | 86 | SurfaceFlinger::maxFrameBufferAcquiredBuffers > 0) { | 
|  | 87 | mCompositionDisplay->createClientCompositionCache( | 
|  | 88 | static_cast<uint32_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers)); | 
|  | 89 | } | 
|  | 90 |  | 
| Vishnu Nair | a314038 | 2022-02-24 14:07:11 -0800 | [diff] [blame] | 91 | mCompositionDisplay->setPredictCompositionStrategy(mFlinger->mPredictCompositionStrategy); | 
| Alec Mouri | dda07d9 | 2022-04-25 22:39:25 +0000 | [diff] [blame] | 92 | mCompositionDisplay->setTreat170mAsSrgb(mFlinger->mTreat170mAsSrgb); | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 93 | mCompositionDisplay->createDisplayColorProfile( | 
| Kriti Dang | 646f8ec | 2022-01-18 14:35:02 +0100 | [diff] [blame] | 94 | compositionengine::DisplayColorProfileCreationArgsBuilder() | 
|  | 95 | .setHasWideColorGamut(args.hasWideColorGamut) | 
|  | 96 | .setHdrCapabilities(std::move(args.hdrCapabilities)) | 
|  | 97 | .setSupportedPerFrameMetadata(args.supportedPerFrameMetadata) | 
|  | 98 | .setHwcColorModes(std::move(args.hwcColorModes)) | 
|  | 99 | .Build()); | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 100 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 101 | if (!mCompositionDisplay->isValid()) { | 
|  | 102 | ALOGE("Composition Display did not validate!"); | 
|  | 103 | } | 
|  | 104 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 105 | mCompositionDisplay->getRenderSurface()->initialize(); | 
| Lloyd Pique | 2eef1d2 | 2018-09-18 21:30:04 -0700 | [diff] [blame] | 106 |  | 
| linpeter | e805932 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 107 | if (args.initialPowerMode.has_value()) setPowerMode(args.initialPowerMode.value()); | 
| Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 108 |  | 
| Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame] | 109 | // initialize the display orientation transform. | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 110 | 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] | 111 | } | 
|  | 112 |  | 
| Lloyd Pique | 0959483 | 2018-01-22 17:48:03 -0800 | [diff] [blame] | 113 | DisplayDevice::~DisplayDevice() = default; | 
| Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 114 |  | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 115 | void DisplayDevice::disconnect() { | 
|  | 116 | mCompositionDisplay->disconnect(); | 
| Jesse Hall | 02d8656 | 2013-03-25 14:43:23 -0700 | [diff] [blame] | 117 | } | 
|  | 118 |  | 
| Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 119 | int DisplayDevice::getWidth() const { | 
| Angel Aguayo | b108a6d | 2021-08-06 21:34:57 +0000 | [diff] [blame] | 120 | return mCompositionDisplay->getState().displaySpace.getBounds().width; | 
| Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 121 | } | 
|  | 122 |  | 
| Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 123 | int DisplayDevice::getHeight() const { | 
| Angel Aguayo | b108a6d | 2021-08-06 21:34:57 +0000 | [diff] [blame] | 124 | return mCompositionDisplay->getState().displaySpace.getBounds().height; | 
| Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 125 | } | 
|  | 126 |  | 
| Dominik Laskowski | bf170d9 | 2018-04-19 15:08:05 -0700 | [diff] [blame] | 127 | void DisplayDevice::setDisplayName(const std::string& displayName) { | 
|  | 128 | if (!displayName.empty()) { | 
| Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 129 | // never override the name with an empty name | 
|  | 130 | mDisplayName = displayName; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 131 | mCompositionDisplay->setName(displayName); | 
| Mathias Agopian | 9e2463e | 2012-09-21 18:26:16 -0700 | [diff] [blame] | 132 | } | 
|  | 133 | } | 
|  | 134 |  | 
| Marin Shalamanov | e5cceea | 2020-04-30 18:13:10 +0200 | [diff] [blame] | 135 | void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info) { | 
|  | 136 | mDeviceProductInfo = std::move(info); | 
|  | 137 | } | 
|  | 138 |  | 
| Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 139 | uint32_t DisplayDevice::getPageFlipCount() const { | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 140 | return mCompositionDisplay->getRenderSurface()->getPageFlipCount(); | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 141 | } | 
| Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 142 |  | 
| Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 143 | auto DisplayDevice::getInputInfo() const -> InputInfo { | 
| Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 144 | gui::DisplayInfo info; | 
|  | 145 | info.displayId = getLayerStack().id; | 
|  | 146 |  | 
|  | 147 | // The physical orientation is set when the orientation of the display panel is | 
|  | 148 | // different than the default orientation of the device. Other services like | 
|  | 149 | // InputFlinger do not know about this, so we do not need to expose the physical | 
|  | 150 | // orientation of the panel outside of SurfaceFlinger. | 
|  | 151 | const ui::Rotation inversePhysicalOrientation = ui::ROTATION_0 - mPhysicalOrientation; | 
|  | 152 | auto width = getWidth(); | 
|  | 153 | auto height = getHeight(); | 
|  | 154 | if (inversePhysicalOrientation == ui::ROTATION_90 || | 
|  | 155 | inversePhysicalOrientation == ui::ROTATION_270) { | 
|  | 156 | std::swap(width, height); | 
|  | 157 | } | 
|  | 158 | const ui::Transform undoPhysicalOrientation(ui::Transform::toRotationFlags( | 
|  | 159 | inversePhysicalOrientation), | 
|  | 160 | width, height); | 
|  | 161 | const auto& displayTransform = undoPhysicalOrientation * getTransform(); | 
|  | 162 | // Send the inverse display transform to input so it can convert display coordinates to | 
|  | 163 | // logical display. | 
|  | 164 | info.transform = displayTransform.inverse(); | 
|  | 165 |  | 
|  | 166 | info.logicalWidth = getLayerStackSpaceRect().width(); | 
|  | 167 | info.logicalHeight = getLayerStackSpaceRect().height(); | 
| Dominik Laskowski | 9f410f0 | 2022-01-08 16:22:46 -0800 | [diff] [blame] | 168 |  | 
|  | 169 | return {.info = info, | 
|  | 170 | .transform = displayTransform, | 
|  | 171 | .receivesInput = receivesInput(), | 
|  | 172 | .isSecure = isSecure()}; | 
| Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 173 | } | 
|  | 174 |  | 
| Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 175 | void DisplayDevice::setPowerMode(hal::PowerMode mode) { | 
| joenchen | e72ba5e | 2022-08-24 13:08:58 +0000 | [diff] [blame] | 176 | if (mode == hal::PowerMode::OFF || mode == hal::PowerMode::ON) { | 
|  | 177 | if (mStagedBrightness && mBrightness != *mStagedBrightness) { | 
|  | 178 | getCompositionDisplay()->setNextBrightness(*mStagedBrightness); | 
|  | 179 | mBrightness = *mStagedBrightness; | 
|  | 180 | } | 
|  | 181 | mStagedBrightness = std::nullopt; | 
|  | 182 | getCompositionDisplay()->applyDisplayBrightness(true); | 
|  | 183 | } | 
|  | 184 |  | 
| Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 185 | mPowerMode = mode; | 
| linpeter | e805932 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 186 |  | 
|  | 187 | getCompositionDisplay()->setCompositionEnabled(mPowerMode.has_value() && | 
|  | 188 | *mPowerMode != hal::PowerMode::OFF); | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 189 | } | 
|  | 190 |  | 
| Alec Mouri | 023c188 | 2021-05-08 16:36:33 -0700 | [diff] [blame] | 191 | void DisplayDevice::enableLayerCaching(bool enable) { | 
|  | 192 | getCompositionDisplay()->setLayerCachingEnabled(enable); | 
|  | 193 | } | 
|  | 194 |  | 
| linpeter | e805932 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 195 | std::optional<hal::PowerMode> DisplayDevice::getPowerMode() const { | 
| Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 196 | return mPowerMode; | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 197 | } | 
|  | 198 |  | 
| Dominik Laskowski | eecd659 | 2018-05-29 10:25:41 -0700 | [diff] [blame] | 199 | bool DisplayDevice::isPoweredOn() const { | 
| linpeter | e805932 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 200 | return mPowerMode && *mPowerMode != hal::PowerMode::OFF; | 
| Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 201 | } | 
|  | 202 |  | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 203 | void DisplayDevice::setActiveMode(DisplayModeId id) { | 
| Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 204 | const auto mode = getMode(id); | 
|  | 205 | LOG_FATAL_IF(!mode, "Cannot set active mode which is not supported."); | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 206 | ATRACE_INT(mActiveModeFPSTrace.c_str(), mode->getFps().getIntValue()); | 
| Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 207 | mActiveMode = mode; | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 208 | if (mRefreshRateConfigs) { | 
| Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 209 | mRefreshRateConfigs->setActiveModeId(mActiveMode->getId()); | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 210 | } | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 211 | if (mRefreshRateOverlay) { | 
|  | 212 | mRefreshRateOverlay->changeRefreshRate(mActiveMode->getFps()); | 
|  | 213 | } | 
| Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 214 | } | 
|  | 215 |  | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 216 | status_t DisplayDevice::initiateModeChange(const ActiveModeInfo& info, | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 217 | const hal::VsyncPeriodChangeConstraints& constraints, | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 218 | hal::VsyncPeriodChangeTimeline* outTimeline) { | 
|  | 219 | if (!info.mode || info.mode->getPhysicalDisplayId() != getPhysicalId()) { | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 220 | ALOGE("Trying to initiate a mode change to invalid mode %s on display %s", | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 221 | info.mode ? std::to_string(info.mode->getId().value()).c_str() : "null", | 
|  | 222 | to_string(getId()).c_str()); | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 223 | return BAD_VALUE; | 
|  | 224 | } | 
| Ady Abraham | a92a568 | 2022-06-07 23:35:38 +0000 | [diff] [blame] | 225 | mNumModeSwitchesInPolicy++; | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 226 | mUpcomingActiveMode = info; | 
|  | 227 | ATRACE_INT(mActiveModeFPSHwcTrace.c_str(), info.mode->getFps().getIntValue()); | 
|  | 228 | return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), info.mode->getHwcId(), | 
|  | 229 | constraints, outTimeline); | 
| Marin Shalamanov | 12c9e5a | 2021-01-07 00:25:35 +0100 | [diff] [blame] | 230 | } | 
|  | 231 |  | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 232 | const DisplayModePtr& DisplayDevice::getActiveMode() const { | 
| Marin Shalamanov | f22e6ac | 2021-02-10 20:45:15 +0100 | [diff] [blame] | 233 | return mActiveMode; | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 234 | } | 
|  | 235 |  | 
|  | 236 | const DisplayModes& DisplayDevice::getSupportedModes() const { | 
|  | 237 | return mSupportedModes; | 
|  | 238 | } | 
|  | 239 |  | 
|  | 240 | DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const { | 
| Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 241 | const DisplayModePtr nullMode; | 
|  | 242 | return mSupportedModes.get(modeId).value_or(std::cref(nullMode)); | 
| Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 243 | } | 
|  | 244 |  | 
| Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 245 | std::optional<DisplayModeId> DisplayDevice::translateModeId(hal::HWConfigId hwcId) const { | 
|  | 246 | const auto it = | 
|  | 247 | std::find_if(mSupportedModes.begin(), mSupportedModes.end(), | 
| Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 248 | [hwcId](const auto& pair) { return pair.second->getHwcId() == hwcId; }); | 
| Kriti Dang | 30e378d | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 249 | if (it != mSupportedModes.end()) { | 
| Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 250 | return it->second->getId(); | 
| Kriti Dang | 30e378d | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 251 | } | 
| Dominik Laskowski | 6c7b36e | 2022-03-03 08:27:58 -0800 | [diff] [blame] | 252 | return {}; | 
| Kriti Dang | 30e378d | 2022-02-18 15:09:12 +0100 | [diff] [blame] | 253 | } | 
|  | 254 |  | 
| Marin Shalamanov | 045b700 | 2021-01-07 16:56:24 +0100 | [diff] [blame] | 255 | nsecs_t DisplayDevice::getVsyncPeriodFromHWC() const { | 
|  | 256 | const auto physicalId = getPhysicalId(); | 
|  | 257 | if (!mHwComposer.isConnected(physicalId)) { | 
|  | 258 | return 0; | 
|  | 259 | } | 
|  | 260 |  | 
|  | 261 | nsecs_t vsyncPeriod; | 
|  | 262 | const auto status = mHwComposer.getDisplayVsyncPeriod(physicalId, &vsyncPeriod); | 
|  | 263 | if (status == NO_ERROR) { | 
|  | 264 | return vsyncPeriod; | 
|  | 265 | } | 
|  | 266 |  | 
|  | 267 | return getActiveMode()->getFps().getPeriodNsecs(); | 
|  | 268 | } | 
|  | 269 |  | 
|  | 270 | nsecs_t DisplayDevice::getRefreshTimestamp() const { | 
|  | 271 | const nsecs_t now = systemTime(CLOCK_MONOTONIC); | 
|  | 272 | const auto vsyncPeriodNanos = getVsyncPeriodFromHWC(); | 
|  | 273 | return now - ((now - mLastHwVsync) % vsyncPeriodNanos); | 
|  | 274 | } | 
|  | 275 |  | 
|  | 276 | void DisplayDevice::onVsync(nsecs_t timestamp) { | 
|  | 277 | mLastHwVsync = timestamp; | 
|  | 278 | } | 
|  | 279 |  | 
| Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 280 | ui::Dataspace DisplayDevice::getCompositionDataSpace() const { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 281 | return mCompositionDisplay->getState().dataspace; | 
| Peiyong Lin | dd9b2ae | 2018-03-01 16:22:45 -0800 | [diff] [blame] | 282 | } | 
|  | 283 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 284 | void DisplayDevice::setLayerStack(ui::LayerStack stack) { | 
| Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 285 | mCompositionDisplay->setLayerFilter({stack, isInternal()}); | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 286 | if (mRefreshRateOverlay) { | 
|  | 287 | mRefreshRateOverlay->setLayerStack(stack); | 
|  | 288 | } | 
| Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 289 | } | 
|  | 290 |  | 
| Evan Rosky | 2239b37 | 2021-05-20 13:43:47 -0700 | [diff] [blame] | 291 | void DisplayDevice::setFlags(uint32_t flags) { | 
|  | 292 | mFlags = flags; | 
|  | 293 | } | 
|  | 294 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 295 | void DisplayDevice::setDisplaySize(int width, int height) { | 
| Marin Shalamanov | b15d227 | 2020-09-17 21:41:52 +0200 | [diff] [blame] | 296 | LOG_FATAL_IF(!isVirtual(), "Changing the display size is supported only for virtual displays."); | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 297 | const auto size = ui::Size(width, height); | 
|  | 298 | mCompositionDisplay->setDisplaySize(size); | 
|  | 299 | if (mRefreshRateOverlay) { | 
|  | 300 | mRefreshRateOverlay->setViewport(size); | 
|  | 301 | } | 
| Michael Lentine | 47e4540 | 2014-07-18 15:34:25 -0700 | [diff] [blame] | 302 | } | 
|  | 303 |  | 
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 304 | void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpaceRect, | 
|  | 305 | Rect orientedDisplaySpaceRect) { | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 306 | mOrientation = orientation; | 
|  | 307 |  | 
| Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 308 | if (isPrimary()) { | 
|  | 309 | sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation); | 
|  | 310 | } | 
|  | 311 |  | 
| Marin Shalamanov | 8c23c4e | 2020-08-19 15:26:31 +0200 | [diff] [blame] | 312 | // We need to take care of display rotation for globalTransform for case if the panel is not | 
|  | 313 | // installed aligned with device orientation. | 
|  | 314 | const auto transformOrientation = orientation + mPhysicalOrientation; | 
| Alec Mouri | 168f6cc | 2022-04-07 20:58:00 +0000 | [diff] [blame] | 315 |  | 
|  | 316 | const auto& state = getCompositionDisplay()->getState(); | 
|  | 317 |  | 
|  | 318 | // If the layer stack and destination frames have never been set, then configure them to be the | 
|  | 319 | // same as the physical device, taking into account the total transform. | 
|  | 320 | if (!orientedDisplaySpaceRect.isValid()) { | 
|  | 321 | ui::Size bounds = state.displaySpace.getBounds(); | 
|  | 322 | bounds.rotate(transformOrientation); | 
|  | 323 | orientedDisplaySpaceRect = Rect(bounds); | 
|  | 324 | } | 
|  | 325 | if (layerStackSpaceRect.isEmpty()) { | 
|  | 326 | ui::Size bounds = state.framebufferSpace.getBounds(); | 
|  | 327 | bounds.rotate(transformOrientation); | 
|  | 328 | layerStackSpaceRect = Rect(bounds); | 
|  | 329 | } | 
| Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 330 | getCompositionDisplay()->setProjection(transformOrientation, layerStackSpaceRect, | 
|  | 331 | orientedDisplaySpaceRect); | 
| Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 332 | } | 
| Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 333 |  | 
| Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 334 | void DisplayDevice::stageBrightness(float brightness) { | 
|  | 335 | mStagedBrightness = brightness; | 
|  | 336 | } | 
|  | 337 |  | 
|  | 338 | void DisplayDevice::persistBrightness(bool needsComposite) { | 
| joenchen | 4292810 | 2022-09-06 18:03:57 +0000 | [diff] [blame] | 339 | if (mStagedBrightness && mBrightness != *mStagedBrightness) { | 
|  | 340 | if (needsComposite) { | 
|  | 341 | getCompositionDisplay()->setNextBrightness(*mStagedBrightness); | 
|  | 342 | } | 
| Alec Mouri | cdf1679 | 2021-12-10 13:16:06 -0800 | [diff] [blame] | 343 | mBrightness = *mStagedBrightness; | 
|  | 344 | } | 
|  | 345 | mStagedBrightness = std::nullopt; | 
|  | 346 | } | 
|  | 347 |  | 
|  | 348 | std::optional<float> DisplayDevice::getStagedBrightness() const { | 
|  | 349 | return mStagedBrightness; | 
|  | 350 | } | 
|  | 351 |  | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 352 | ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() { | 
|  | 353 | return sPrimaryDisplayRotationFlags; | 
| Pablo Ceballos | 021623b | 2016-04-15 17:31:51 -0700 | [diff] [blame] | 354 | } | 
|  | 355 |  | 
| Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 356 | std::string DisplayDevice::getDebugName() const { | 
| Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 357 | using namespace std::string_literals; | 
|  | 358 |  | 
|  | 359 | std::string name = "Display "s + to_string(getId()) + " ("s; | 
|  | 360 |  | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 361 | if (mConnectionType) { | 
| Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 362 | name += isInternal() ? "internal"s : "external"s; | 
|  | 363 | } else { | 
|  | 364 | name += "virtual"s; | 
| Dominik Laskowski | 55c8540 | 2020-01-21 16:25:47 -0800 | [diff] [blame] | 365 | } | 
|  | 366 |  | 
| Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 367 | if (isPrimary()) { | 
|  | 368 | name += ", primary"s; | 
|  | 369 | } | 
|  | 370 |  | 
|  | 371 | return name + ", \""s + mDisplayName + "\")"s; | 
| Dominik Laskowski | 9b17b2c2 | 2018-11-01 14:49:03 -0700 | [diff] [blame] | 372 | } | 
|  | 373 |  | 
| Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 374 | void DisplayDevice::dump(std::string& result) const { | 
| Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 375 | using namespace std::string_literals; | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 376 |  | 
| Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 377 | result += getDebugName(); | 
|  | 378 |  | 
|  | 379 | if (!isVirtual()) { | 
|  | 380 | result += "\n   deviceProductInfo="s; | 
|  | 381 | if (mDeviceProductInfo) { | 
|  | 382 | mDeviceProductInfo->dump(result); | 
|  | 383 | } else { | 
|  | 384 | result += "{}"s; | 
|  | 385 | } | 
| Marin Shalamanov | 5801c94 | 2020-12-17 17:00:13 +0100 | [diff] [blame] | 386 | } | 
| Dominik Laskowski | b0054a2 | 2022-03-03 09:03:06 -0800 | [diff] [blame] | 387 |  | 
| Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 388 | result += "\n   powerMode="s; | 
| linpeter | e805932 | 2022-07-13 19:20:48 +0800 | [diff] [blame] | 389 | result += mPowerMode.has_value() ? to_string(mPowerMode.value()) : "OFF(reset)"; | 
| Dominik Laskowski | 0acc384 | 2022-04-07 11:23:42 -0700 | [diff] [blame] | 390 | result += '\n'; | 
| Ady Abraham | 3efa394 | 2021-06-24 19:01:25 -0700 | [diff] [blame] | 391 |  | 
|  | 392 | if (mRefreshRateConfigs) { | 
|  | 393 | mRefreshRateConfigs->dump(result); | 
|  | 394 | } | 
| Mathias Agopian | 1d12d8a | 2012-09-18 01:38:00 -0700 | [diff] [blame] | 395 | } | 
| Irvel | ffc9efc | 2016-07-27 15:16:37 -0700 | [diff] [blame] | 396 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 397 | bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const { | 
|  | 398 | return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent); | 
| Peiyong Lin | 136fbbc | 2018-04-17 15:09:44 -0700 | [diff] [blame] | 399 | } | 
|  | 400 |  | 
| Marin Shalamanov | 0f10d0d | 2020-08-06 20:04:06 +0200 | [diff] [blame] | 401 | DisplayId DisplayDevice::getId() const { | 
| Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 402 | return mCompositionDisplay->getId(); | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | bool DisplayDevice::isSecure() const { | 
|  | 406 | return mCompositionDisplay->isSecure(); | 
|  | 407 | } | 
|  | 408 |  | 
| Angel Aguayo | b108a6d | 2021-08-06 21:34:57 +0000 | [diff] [blame] | 409 | const Rect DisplayDevice::getBounds() const { | 
|  | 410 | return mCompositionDisplay->getState().displaySpace.getBoundsAsRect(); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 411 | } | 
|  | 412 |  | 
|  | 413 | const Region& DisplayDevice::getUndefinedRegion() const { | 
|  | 414 | return mCompositionDisplay->getState().undefinedRegion; | 
|  | 415 | } | 
|  | 416 |  | 
|  | 417 | bool DisplayDevice::needsFiltering() const { | 
|  | 418 | return mCompositionDisplay->getState().needsFiltering; | 
|  | 419 | } | 
|  | 420 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 421 | ui::LayerStack DisplayDevice::getLayerStack() const { | 
| Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 422 | return mCompositionDisplay->getState().layerFilter.layerStack; | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 423 | } | 
|  | 424 |  | 
| Garfield Tan | 54edd91 | 2020-10-21 16:31:41 -0700 | [diff] [blame] | 425 | ui::Transform::RotationFlags DisplayDevice::getTransformHint() const { | 
|  | 426 | return mCompositionDisplay->getTransformHint(); | 
|  | 427 | } | 
|  | 428 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 429 | const ui::Transform& DisplayDevice::getTransform() const { | 
|  | 430 | return mCompositionDisplay->getState().transform; | 
|  | 431 | } | 
|  | 432 |  | 
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 433 | const Rect& DisplayDevice::getLayerStackSpaceRect() const { | 
| Angel Aguayo | b108a6d | 2021-08-06 21:34:57 +0000 | [diff] [blame] | 434 | return mCompositionDisplay->getState().layerStackSpace.getContent(); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 435 | } | 
|  | 436 |  | 
| Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 437 | const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const { | 
| Angel Aguayo | b108a6d | 2021-08-06 21:34:57 +0000 | [diff] [blame] | 438 | return mCompositionDisplay->getState().orientedDisplaySpace.getContent(); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 439 | } | 
|  | 440 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 441 | bool DisplayDevice::hasWideColorGamut() const { | 
|  | 442 | return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut(); | 
|  | 443 | } | 
|  | 444 |  | 
|  | 445 | bool DisplayDevice::hasHDR10PlusSupport() const { | 
|  | 446 | return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport(); | 
|  | 447 | } | 
|  | 448 |  | 
|  | 449 | bool DisplayDevice::hasHDR10Support() const { | 
|  | 450 | return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support(); | 
|  | 451 | } | 
|  | 452 |  | 
|  | 453 | bool DisplayDevice::hasHLGSupport() const { | 
|  | 454 | return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport(); | 
|  | 455 | } | 
|  | 456 |  | 
|  | 457 | bool DisplayDevice::hasDolbyVisionSupport() const { | 
|  | 458 | return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport(); | 
|  | 459 | } | 
|  | 460 |  | 
|  | 461 | int DisplayDevice::getSupportedPerFrameMetadata() const { | 
|  | 462 | return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata(); | 
|  | 463 | } | 
|  | 464 |  | 
| Kriti Dang | 49ad413 | 2021-01-08 11:49:56 +0100 | [diff] [blame] | 465 | void DisplayDevice::overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes) { | 
|  | 466 | mOverrideHdrTypes = hdrTypes; | 
|  | 467 | } | 
|  | 468 |  | 
|  | 469 | HdrCapabilities DisplayDevice::getHdrCapabilities() const { | 
|  | 470 | const HdrCapabilities& capabilities = | 
|  | 471 | mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities(); | 
|  | 472 | std::vector<ui::Hdr> hdrTypes = capabilities.getSupportedHdrTypes(); | 
|  | 473 | if (!mOverrideHdrTypes.empty()) { | 
|  | 474 | hdrTypes = mOverrideHdrTypes; | 
|  | 475 | } | 
|  | 476 | return HdrCapabilities(hdrTypes, capabilities.getDesiredMaxLuminance(), | 
|  | 477 | capabilities.getDesiredMaxAverageLuminance(), | 
|  | 478 | capabilities.getDesiredMinLuminance()); | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 479 | } | 
|  | 480 |  | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 481 | void DisplayDevice::enableRefreshRateOverlay(bool enable, bool showSpinnner) { | 
|  | 482 | if (!enable) { | 
|  | 483 | mRefreshRateOverlay.reset(); | 
|  | 484 | return; | 
|  | 485 | } | 
|  | 486 |  | 
| Dominik Laskowski | 8c4356c | 2022-03-21 08:19:54 -0700 | [diff] [blame] | 487 | const auto fpsRange = mRefreshRateConfigs->getSupportedRefreshRateRange(); | 
|  | 488 | mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(fpsRange, showSpinnner); | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 489 | mRefreshRateOverlay->setLayerStack(getLayerStack()); | 
|  | 490 | mRefreshRateOverlay->setViewport(getSize()); | 
|  | 491 | mRefreshRateOverlay->changeRefreshRate(getActiveMode()->getFps()); | 
|  | 492 | } | 
|  | 493 |  | 
|  | 494 | bool DisplayDevice::onKernelTimerChanged(std::optional<DisplayModeId> desiredModeId, | 
|  | 495 | bool timerExpired) { | 
|  | 496 | if (mRefreshRateConfigs && mRefreshRateOverlay) { | 
|  | 497 | const auto newRefreshRate = | 
|  | 498 | mRefreshRateConfigs->onKernelTimerChanged(desiredModeId, timerExpired); | 
|  | 499 | if (newRefreshRate) { | 
|  | 500 | mRefreshRateOverlay->changeRefreshRate(*newRefreshRate); | 
|  | 501 | return true; | 
|  | 502 | } | 
|  | 503 | } | 
|  | 504 |  | 
|  | 505 | return false; | 
|  | 506 | } | 
|  | 507 |  | 
| Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 508 | void DisplayDevice::animateRefreshRateOverlay() { | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 509 | if (mRefreshRateOverlay) { | 
| Dominik Laskowski | e0e0cde | 2021-07-30 10:42:05 -0700 | [diff] [blame] | 510 | mRefreshRateOverlay->animate(); | 
| Ady Abraham | 1b11bc6 | 2021-06-03 19:51:19 -0700 | [diff] [blame] | 511 | } | 
|  | 512 | } | 
|  | 513 |  | 
| Dominik Laskowski | 7674284 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 514 | bool DisplayDevice::setDesiredActiveMode(const ActiveModeInfo& info, bool force) { | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 515 | ATRACE_CALL(); | 
|  | 516 |  | 
|  | 517 | LOG_ALWAYS_FATAL_IF(!info.mode, "desired mode not provided"); | 
|  | 518 | LOG_ALWAYS_FATAL_IF(getPhysicalId() != info.mode->getPhysicalDisplayId(), "DisplayId mismatch"); | 
|  | 519 |  | 
|  | 520 | ALOGV("%s(%s)", __func__, to_string(*info.mode).c_str()); | 
|  | 521 |  | 
|  | 522 | std::scoped_lock lock(mActiveModeLock); | 
|  | 523 | if (mDesiredActiveModeChanged) { | 
|  | 524 | // If a mode change is pending, just cache the latest request in mDesiredActiveMode | 
| Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 525 | const auto prevConfig = mDesiredActiveMode.event; | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 526 | mDesiredActiveMode = info; | 
|  | 527 | mDesiredActiveMode.event = mDesiredActiveMode.event | prevConfig; | 
|  | 528 | return false; | 
|  | 529 | } | 
|  | 530 |  | 
|  | 531 | // Check if we are already at the desired mode | 
| Dominik Laskowski | 7674284 | 2022-12-02 14:56:05 -0500 | [diff] [blame] | 532 | if (!force && getActiveMode()->getId() == info.mode->getId()) { | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 533 | return false; | 
|  | 534 | } | 
|  | 535 |  | 
|  | 536 | // Initiate a mode change. | 
|  | 537 | mDesiredActiveModeChanged = true; | 
|  | 538 | mDesiredActiveMode = info; | 
|  | 539 | return true; | 
|  | 540 | } | 
|  | 541 |  | 
|  | 542 | std::optional<DisplayDevice::ActiveModeInfo> DisplayDevice::getDesiredActiveMode() const { | 
|  | 543 | std::scoped_lock lock(mActiveModeLock); | 
|  | 544 | if (mDesiredActiveModeChanged) return mDesiredActiveMode; | 
|  | 545 | return std::nullopt; | 
|  | 546 | } | 
|  | 547 |  | 
|  | 548 | void DisplayDevice::clearDesiredActiveModeState() { | 
|  | 549 | std::scoped_lock lock(mActiveModeLock); | 
| Dominik Laskowski | 068173d | 2021-08-11 17:22:59 -0700 | [diff] [blame] | 550 | mDesiredActiveMode.event = scheduler::DisplayModeEvent::None; | 
| Ady Abraham | 690f461 | 2021-07-01 23:24:03 -0700 | [diff] [blame] | 551 | mDesiredActiveModeChanged = false; | 
|  | 552 | } | 
|  | 553 |  | 
| Ady Abraham | a92a568 | 2022-06-07 23:35:38 +0000 | [diff] [blame] | 554 | status_t DisplayDevice::setRefreshRatePolicy( | 
|  | 555 | const std::optional<scheduler::RefreshRateConfigs::Policy>& policy, bool overridePolicy) { | 
|  | 556 | const auto oldPolicy = mRefreshRateConfigs->getCurrentPolicy(); | 
|  | 557 | const status_t setPolicyResult = overridePolicy | 
|  | 558 | ? mRefreshRateConfigs->setOverridePolicy(policy) | 
|  | 559 | : mRefreshRateConfigs->setDisplayManagerPolicy(*policy); | 
|  | 560 |  | 
|  | 561 | if (setPolicyResult == OK) { | 
|  | 562 | const int numModeChanges = mNumModeSwitchesInPolicy.exchange(0); | 
|  | 563 |  | 
|  | 564 | ALOGI("Display %s policy changed\n" | 
|  | 565 | "Previous: {%s}\n" | 
|  | 566 | "Current:  {%s}\n" | 
|  | 567 | "%d mode changes were performed under the previous policy", | 
|  | 568 | to_string(getId()).c_str(), oldPolicy.toString().c_str(), | 
|  | 569 | policy ? policy->toString().c_str() : "null", numModeChanges); | 
|  | 570 | } | 
|  | 571 |  | 
|  | 572 | return setPolicyResult; | 
|  | 573 | } | 
|  | 574 |  | 
| Dominik Laskowski | 663bd28 | 2018-04-19 15:26:54 -0700 | [diff] [blame] | 575 | std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1); | 
| Peiyong Lin | fd997e0 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 576 |  | 
|  | 577 | }  // namespace android | 
| Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 578 |  | 
|  | 579 | // TODO(b/129481165): remove the #pragma below and fix conversion issues | 
|  | 580 | #pragma clang diagnostic pop // ignored "-Wconversion" |