blob: 3bc3ae54b3c82acf4de859ff6eac343edf941ba0 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Dan Stoza9e56aa02015-11-02 13:00:03 -080021// #define LOG_NDEBUG 0
22#undef LOG_TAG
23#define LOG_TAG "DisplayDevice"
24
Ady Abraham690f4612021-07-01 23:24:03 -070025#define ATRACE_TAG ATRACE_TAG_GRAPHICS
26
Lloyd Pique45a165a2018-10-19 11:54:47 -070027#include <compositionengine/CompositionEngine.h>
28#include <compositionengine/Display.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070029#include <compositionengine/DisplayColorProfile.h>
30#include <compositionengine/DisplayColorProfileCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070031#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070032#include <compositionengine/DisplaySurface.h>
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020033#include <compositionengine/ProjectionSpace.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070034#include <compositionengine/RenderSurface.h>
35#include <compositionengine/RenderSurfaceCreationArgs.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070036#include <compositionengine/impl/OutputCompositionState.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070037#include <configstore/Utils.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070038#include <log/log.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080039#include <system/window.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070040#include <ui/GraphicTypes.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070042#include "DisplayDevice.h"
Mathias Agopian13127d82013-03-05 17:47:11 -080043#include "Layer.h"
Ady Abraham1b11bc62021-06-03 19:51:19 -070044#include "RefreshRateOverlay.h"
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070045#include "SurfaceFlinger.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070046
Peiyong Linfd997e02018-03-28 15:29:00 -070047namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048
Peiyong Lin65248e02020-04-18 21:15:07 -070049namespace hal = hardware::graphics::composer::hal;
50
Dominik Laskowski718f9602019-11-09 20:01:35 -080051ui::Transform::RotationFlags DisplayDevice::sPrimaryDisplayRotationFlags = ui::Transform::ROT_0;
Pablo Ceballos021623b2016-04-15 17:31:51 -070052
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070053DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010054 const sp<SurfaceFlinger>& flinger, HWComposer& hwComposer, const wp<IBinder>& displayToken,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070055 std::shared_ptr<compositionengine::Display> compositionDisplay)
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010056 : flinger(flinger),
57 hwComposer(hwComposer),
58 displayToken(displayToken),
59 compositionDisplay(compositionDisplay) {}
Chia-I Wube02ec02018-05-18 10:59:36 -070060
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070061DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args)
Lloyd Pique32cbe282018-10-19 13:09:22 -070062 : mFlinger(args.flinger),
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010063 mHwComposer(args.hwComposer),
Lloyd Pique2eef1d22018-09-18 21:30:04 -070064 mDisplayToken(args.displayToken),
Dominik Laskowskie9774092018-12-11 10:04:24 -080065 mSequenceId(args.sequenceId),
Dominik Laskowski55c85402020-01-21 16:25:47 -080066 mConnectionType(args.connectionType),
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070067 mCompositionDisplay{args.compositionDisplay},
Ady Abraham690f4612021-07-01 23:24:03 -070068 mActiveModeFPSTrace("ActiveModeFPS -" + to_string(getId())),
69 mActiveModeFPSHwcTrace("ActiveModeFPS_HWC -" + to_string(getId())),
Dominik Laskowski718f9602019-11-09 20:01:35 -080070 mPhysicalOrientation(args.physicalOrientation),
Marin Shalamanov5801c942020-12-17 17:00:13 +010071 mSupportedModes(std::move(args.supportedModes)),
Ady Abraham3efa3942021-06-24 19:01:25 -070072 mIsPrimary(args.isPrimary),
73 mRefreshRateConfigs(std::move(args.refreshRateConfigs)) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070074 mCompositionDisplay->editState().isSecure = args.isSecure;
Lloyd Pique31cb2942018-10-19 17:23:03 -070075 mCompositionDisplay->createRenderSurface(
Dominik Laskowskib9ac3e12021-04-23 13:01:16 -070076 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 Pique31cb2942018-10-19 17:23:03 -070084
Vishnu Nair9b079a22020-01-21 14:36:08 -080085 if (!mFlinger->mDisableClientCompositionCache &&
86 SurfaceFlinger::maxFrameBufferAcquiredBuffers > 0) {
87 mCompositionDisplay->createClientCompositionCache(
88 static_cast<uint32_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers));
89 }
90
Vishnu Naira3140382022-02-24 14:07:11 -080091 mCompositionDisplay->setPredictCompositionStrategy(mFlinger->mPredictCompositionStrategy);
Alec Mouridda07d92022-04-25 22:39:25 +000092 mCompositionDisplay->setTreat170mAsSrgb(mFlinger->mTreat170mAsSrgb);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070093 mCompositionDisplay->createDisplayColorProfile(
Kriti Dang646f8ec2022-01-18 14:35:02 +010094 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 Pique3d0c02e2018-10-19 18:38:12 -0700100
Lloyd Pique32cbe282018-10-19 13:09:22 -0700101 if (!mCompositionDisplay->isValid()) {
102 ALOGE("Composition Display did not validate!");
103 }
104
Lloyd Pique31cb2942018-10-19 17:23:03 -0700105 mCompositionDisplay->getRenderSurface()->initialize();
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700106
Lloyd Pique32cbe282018-10-19 13:09:22 -0700107 setPowerMode(args.initialPowerMode);
Alec Mouriba013fa2018-10-16 12:43:11 -0700108
Jesse Hallffe1f192013-03-22 15:13:48 -0700109 // initialize the display orientation transform.
Dominik Laskowski718f9602019-11-09 20:01:35 -0800110 setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111}
112
Lloyd Pique09594832018-01-22 17:48:03 -0800113DisplayDevice::~DisplayDevice() = default;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700114
Lloyd Pique45a165a2018-10-19 11:54:47 -0700115void DisplayDevice::disconnect() {
116 mCompositionDisplay->disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700117}
118
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700119int DisplayDevice::getWidth() const {
Angel Aguayob108a6d2021-08-06 21:34:57 +0000120 return mCompositionDisplay->getState().displaySpace.getBounds().width;
Mathias Agopiana4912602012-07-12 14:25:33 -0700121}
122
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700123int DisplayDevice::getHeight() const {
Angel Aguayob108a6d2021-08-06 21:34:57 +0000124 return mCompositionDisplay->getState().displaySpace.getBounds().height;
Mathias Agopiana4912602012-07-12 14:25:33 -0700125}
126
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700127void DisplayDevice::setDisplayName(const std::string& displayName) {
128 if (!displayName.empty()) {
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700129 // never override the name with an empty name
130 mDisplayName = displayName;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700131 mCompositionDisplay->setName(displayName);
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700132 }
133}
134
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200135void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info) {
136 mDeviceProductInfo = std::move(info);
137}
138
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700139uint32_t DisplayDevice::getPageFlipCount() const {
Lloyd Pique31cb2942018-10-19 17:23:03 -0700140 return mCompositionDisplay->getRenderSurface()->getPageFlipCount();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800141}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800142
Dominik Laskowski9f410f02022-01-08 16:22:46 -0800143auto DisplayDevice::getInputInfo() const -> InputInfo {
Prabir Pradhan48f8cb92021-08-26 14:05:36 -0700144 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 Laskowski9f410f02022-01-08 16:22:46 -0800168
169 return {.info = info,
170 .transform = displayTransform,
171 .receivesInput = receivesInput(),
172 .isSecure = isSecure()};
Prabir Pradhan48f8cb92021-08-26 14:05:36 -0700173}
174
Peiyong Lin65248e02020-04-18 21:15:07 -0700175void DisplayDevice::setPowerMode(hal::PowerMode mode) {
joenchene72ba5e2022-08-24 13:08:58 +0000176 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 Malani2c9b11f2014-05-25 01:36:31 -0700185 mPowerMode = mode;
Peiyong Lin65248e02020-04-18 21:15:07 -0700186 getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700187}
188
Alec Mouri023c1882021-05-08 16:36:33 -0700189void DisplayDevice::enableLayerCaching(bool enable) {
190 getCompositionDisplay()->setLayerCachingEnabled(enable);
191}
192
Peiyong Lin65248e02020-04-18 21:15:07 -0700193hal::PowerMode DisplayDevice::getPowerMode() const {
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700194 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700195}
196
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700197bool DisplayDevice::isPoweredOn() const {
Peiyong Lin65248e02020-04-18 21:15:07 -0700198 return mPowerMode != hal::PowerMode::OFF;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700199}
200
Marin Shalamanov5801c942020-12-17 17:00:13 +0100201void DisplayDevice::setActiveMode(DisplayModeId id) {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100202 const auto mode = getMode(id);
203 LOG_FATAL_IF(!mode, "Cannot set active mode which is not supported.");
Ady Abraham690f4612021-07-01 23:24:03 -0700204 ATRACE_INT(mActiveModeFPSTrace.c_str(), mode->getFps().getIntValue());
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100205 mActiveMode = mode;
Ady Abraham3efa3942021-06-24 19:01:25 -0700206 if (mRefreshRateConfigs) {
Dominik Laskowskib0054a22022-03-03 09:03:06 -0800207 mRefreshRateConfigs->setActiveModeId(mActiveMode->getId());
Ady Abraham3efa3942021-06-24 19:01:25 -0700208 }
Ady Abraham1b11bc62021-06-03 19:51:19 -0700209 if (mRefreshRateOverlay) {
210 mRefreshRateOverlay->changeRefreshRate(mActiveMode->getFps());
211 }
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700212}
213
Ady Abraham690f4612021-07-01 23:24:03 -0700214status_t DisplayDevice::initiateModeChange(const ActiveModeInfo& info,
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100215 const hal::VsyncPeriodChangeConstraints& constraints,
Ady Abraham690f4612021-07-01 23:24:03 -0700216 hal::VsyncPeriodChangeTimeline* outTimeline) {
217 if (!info.mode || info.mode->getPhysicalDisplayId() != getPhysicalId()) {
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100218 ALOGE("Trying to initiate a mode change to invalid mode %s on display %s",
Ady Abraham690f4612021-07-01 23:24:03 -0700219 info.mode ? std::to_string(info.mode->getId().value()).c_str() : "null",
220 to_string(getId()).c_str());
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100221 return BAD_VALUE;
222 }
Ady Abrahama92a5682022-06-07 23:35:38 +0000223 mNumModeSwitchesInPolicy++;
Ady Abraham690f4612021-07-01 23:24:03 -0700224 mUpcomingActiveMode = info;
225 ATRACE_INT(mActiveModeFPSHwcTrace.c_str(), info.mode->getFps().getIntValue());
226 return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), info.mode->getHwcId(),
227 constraints, outTimeline);
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100228}
229
Marin Shalamanov5801c942020-12-17 17:00:13 +0100230const DisplayModePtr& DisplayDevice::getActiveMode() const {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100231 return mActiveMode;
Marin Shalamanov5801c942020-12-17 17:00:13 +0100232}
233
234const DisplayModes& DisplayDevice::getSupportedModes() const {
235 return mSupportedModes;
236}
237
238DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const {
Dominik Laskowskib0054a22022-03-03 09:03:06 -0800239 const DisplayModePtr nullMode;
240 return mSupportedModes.get(modeId).value_or(std::cref(nullMode));
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700241}
242
Dominik Laskowski6c7b36e2022-03-03 08:27:58 -0800243std::optional<DisplayModeId> DisplayDevice::translateModeId(hal::HWConfigId hwcId) const {
244 const auto it =
245 std::find_if(mSupportedModes.begin(), mSupportedModes.end(),
Dominik Laskowskib0054a22022-03-03 09:03:06 -0800246 [hwcId](const auto& pair) { return pair.second->getHwcId() == hwcId; });
Kriti Dang30e378d2022-02-18 15:09:12 +0100247 if (it != mSupportedModes.end()) {
Dominik Laskowskib0054a22022-03-03 09:03:06 -0800248 return it->second->getId();
Kriti Dang30e378d2022-02-18 15:09:12 +0100249 }
Dominik Laskowski6c7b36e2022-03-03 08:27:58 -0800250 return {};
Kriti Dang30e378d2022-02-18 15:09:12 +0100251}
252
Marin Shalamanov045b7002021-01-07 16:56:24 +0100253nsecs_t DisplayDevice::getVsyncPeriodFromHWC() const {
254 const auto physicalId = getPhysicalId();
255 if (!mHwComposer.isConnected(physicalId)) {
256 return 0;
257 }
258
259 nsecs_t vsyncPeriod;
260 const auto status = mHwComposer.getDisplayVsyncPeriod(physicalId, &vsyncPeriod);
261 if (status == NO_ERROR) {
262 return vsyncPeriod;
263 }
264
265 return getActiveMode()->getFps().getPeriodNsecs();
266}
267
268nsecs_t DisplayDevice::getRefreshTimestamp() const {
269 const nsecs_t now = systemTime(CLOCK_MONOTONIC);
270 const auto vsyncPeriodNanos = getVsyncPeriodFromHWC();
271 return now - ((now - mLastHwVsync) % vsyncPeriodNanos);
272}
273
274void DisplayDevice::onVsync(nsecs_t timestamp) {
275 mLastHwVsync = timestamp;
276}
277
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800278ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700279 return mCompositionDisplay->getState().dataspace;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800280}
281
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800282void DisplayDevice::setLayerStack(ui::LayerStack stack) {
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700283 mCompositionDisplay->setLayerFilter({stack, isInternal()});
Ady Abraham1b11bc62021-06-03 19:51:19 -0700284 if (mRefreshRateOverlay) {
285 mRefreshRateOverlay->setLayerStack(stack);
286 }
Mathias Agopian28947d72012-08-08 18:51:15 -0700287}
288
Evan Rosky2239b372021-05-20 13:43:47 -0700289void DisplayDevice::setFlags(uint32_t flags) {
290 mFlags = flags;
291}
292
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800293void DisplayDevice::setDisplaySize(int width, int height) {
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200294 LOG_FATAL_IF(!isVirtual(), "Changing the display size is supported only for virtual displays.");
Ady Abraham1b11bc62021-06-03 19:51:19 -0700295 const auto size = ui::Size(width, height);
296 mCompositionDisplay->setDisplaySize(size);
297 if (mRefreshRateOverlay) {
298 mRefreshRateOverlay->setViewport(size);
299 }
Michael Lentine47e45402014-07-18 15:34:25 -0700300}
301
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200302void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpaceRect,
303 Rect orientedDisplaySpaceRect) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700304 mOrientation = orientation;
305
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200306 if (isPrimary()) {
307 sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation);
308 }
309
Marin Shalamanov8c23c4e2020-08-19 15:26:31 +0200310 // We need to take care of display rotation for globalTransform for case if the panel is not
311 // installed aligned with device orientation.
312 const auto transformOrientation = orientation + mPhysicalOrientation;
Alec Mouri168f6cc2022-04-07 20:58:00 +0000313
314 const auto& state = getCompositionDisplay()->getState();
315
316 // If the layer stack and destination frames have never been set, then configure them to be the
317 // same as the physical device, taking into account the total transform.
318 if (!orientedDisplaySpaceRect.isValid()) {
319 ui::Size bounds = state.displaySpace.getBounds();
320 bounds.rotate(transformOrientation);
321 orientedDisplaySpaceRect = Rect(bounds);
322 }
323 if (layerStackSpaceRect.isEmpty()) {
324 ui::Size bounds = state.framebufferSpace.getBounds();
325 bounds.rotate(transformOrientation);
326 layerStackSpaceRect = Rect(bounds);
327 }
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200328 getCompositionDisplay()->setProjection(transformOrientation, layerStackSpaceRect,
329 orientedDisplaySpaceRect);
Mathias Agopian1b031492012-06-20 17:51:20 -0700330}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700331
Alec Mouricdf16792021-12-10 13:16:06 -0800332void DisplayDevice::stageBrightness(float brightness) {
333 mStagedBrightness = brightness;
334}
335
336void DisplayDevice::persistBrightness(bool needsComposite) {
337 if (needsComposite && mStagedBrightness && mBrightness != *mStagedBrightness) {
338 getCompositionDisplay()->setNextBrightness(*mStagedBrightness);
339 mBrightness = *mStagedBrightness;
340 }
341 mStagedBrightness = std::nullopt;
342}
343
344std::optional<float> DisplayDevice::getStagedBrightness() const {
345 return mStagedBrightness;
346}
347
Dominik Laskowski718f9602019-11-09 20:01:35 -0800348ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() {
349 return sPrimaryDisplayRotationFlags;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700350}
351
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700352std::string DisplayDevice::getDebugName() const {
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700353 using namespace std::string_literals;
354
355 std::string name = "Display "s + to_string(getId()) + " ("s;
356
Dominik Laskowski55c85402020-01-21 16:25:47 -0800357 if (mConnectionType) {
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700358 name += isInternal() ? "internal"s : "external"s;
359 } else {
360 name += "virtual"s;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800361 }
362
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700363 if (isPrimary()) {
364 name += ", primary"s;
365 }
366
367 return name + ", \""s + mDisplayName + "\")"s;
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700368}
369
Yiwei Zhang5434a782018-12-05 18:06:32 -0800370void DisplayDevice::dump(std::string& result) const {
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700371 using namespace std::string_literals;
Marin Shalamanov5801c942020-12-17 17:00:13 +0100372
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700373 result += getDebugName();
374
375 if (!isVirtual()) {
376 result += "\n deviceProductInfo="s;
377 if (mDeviceProductInfo) {
378 mDeviceProductInfo->dump(result);
379 } else {
380 result += "{}"s;
381 }
Marin Shalamanov5801c942020-12-17 17:00:13 +0100382 }
Dominik Laskowskib0054a22022-03-03 09:03:06 -0800383
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700384 result += "\n powerMode="s;
385 result += to_string(mPowerMode);
386 result += '\n';
Ady Abraham3efa3942021-06-24 19:01:25 -0700387
388 if (mRefreshRateConfigs) {
389 mRefreshRateConfigs->dump(result);
390 }
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700391}
Irvelffc9efc2016-07-27 15:16:37 -0700392
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700393bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const {
394 return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent);
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700395}
396
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200397DisplayId DisplayDevice::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700398 return mCompositionDisplay->getId();
399}
400
401bool DisplayDevice::isSecure() const {
402 return mCompositionDisplay->isSecure();
403}
404
Angel Aguayob108a6d2021-08-06 21:34:57 +0000405const Rect DisplayDevice::getBounds() const {
406 return mCompositionDisplay->getState().displaySpace.getBoundsAsRect();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700407}
408
409const Region& DisplayDevice::getUndefinedRegion() const {
410 return mCompositionDisplay->getState().undefinedRegion;
411}
412
413bool DisplayDevice::needsFiltering() const {
414 return mCompositionDisplay->getState().needsFiltering;
415}
416
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800417ui::LayerStack DisplayDevice::getLayerStack() const {
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700418 return mCompositionDisplay->getState().layerFilter.layerStack;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700419}
420
Garfield Tan54edd912020-10-21 16:31:41 -0700421ui::Transform::RotationFlags DisplayDevice::getTransformHint() const {
422 return mCompositionDisplay->getTransformHint();
423}
424
Lloyd Pique32cbe282018-10-19 13:09:22 -0700425const ui::Transform& DisplayDevice::getTransform() const {
426 return mCompositionDisplay->getState().transform;
427}
428
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200429const Rect& DisplayDevice::getLayerStackSpaceRect() const {
Angel Aguayob108a6d2021-08-06 21:34:57 +0000430 return mCompositionDisplay->getState().layerStackSpace.getContent();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700431}
432
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200433const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const {
Angel Aguayob108a6d2021-08-06 21:34:57 +0000434 return mCompositionDisplay->getState().orientedDisplaySpace.getContent();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700435}
436
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700437bool DisplayDevice::hasWideColorGamut() const {
438 return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut();
439}
440
441bool DisplayDevice::hasHDR10PlusSupport() const {
442 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport();
443}
444
445bool DisplayDevice::hasHDR10Support() const {
446 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support();
447}
448
449bool DisplayDevice::hasHLGSupport() const {
450 return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport();
451}
452
453bool DisplayDevice::hasDolbyVisionSupport() const {
454 return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport();
455}
456
457int DisplayDevice::getSupportedPerFrameMetadata() const {
458 return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata();
459}
460
Kriti Dang49ad4132021-01-08 11:49:56 +0100461void DisplayDevice::overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes) {
462 mOverrideHdrTypes = hdrTypes;
463}
464
465HdrCapabilities DisplayDevice::getHdrCapabilities() const {
466 const HdrCapabilities& capabilities =
467 mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities();
468 std::vector<ui::Hdr> hdrTypes = capabilities.getSupportedHdrTypes();
469 if (!mOverrideHdrTypes.empty()) {
470 hdrTypes = mOverrideHdrTypes;
471 }
472 return HdrCapabilities(hdrTypes, capabilities.getDesiredMaxLuminance(),
473 capabilities.getDesiredMaxAverageLuminance(),
474 capabilities.getDesiredMinLuminance());
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700475}
476
Ady Abraham1b11bc62021-06-03 19:51:19 -0700477void DisplayDevice::enableRefreshRateOverlay(bool enable, bool showSpinnner) {
478 if (!enable) {
479 mRefreshRateOverlay.reset();
480 return;
481 }
482
Dominik Laskowski8c4356c2022-03-21 08:19:54 -0700483 const auto fpsRange = mRefreshRateConfigs->getSupportedRefreshRateRange();
484 mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(fpsRange, showSpinnner);
Ady Abraham1b11bc62021-06-03 19:51:19 -0700485 mRefreshRateOverlay->setLayerStack(getLayerStack());
486 mRefreshRateOverlay->setViewport(getSize());
487 mRefreshRateOverlay->changeRefreshRate(getActiveMode()->getFps());
488}
489
490bool DisplayDevice::onKernelTimerChanged(std::optional<DisplayModeId> desiredModeId,
491 bool timerExpired) {
492 if (mRefreshRateConfigs && mRefreshRateOverlay) {
493 const auto newRefreshRate =
494 mRefreshRateConfigs->onKernelTimerChanged(desiredModeId, timerExpired);
495 if (newRefreshRate) {
496 mRefreshRateOverlay->changeRefreshRate(*newRefreshRate);
497 return true;
498 }
499 }
500
501 return false;
502}
503
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700504void DisplayDevice::animateRefreshRateOverlay() {
Ady Abraham1b11bc62021-06-03 19:51:19 -0700505 if (mRefreshRateOverlay) {
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700506 mRefreshRateOverlay->animate();
Ady Abraham1b11bc62021-06-03 19:51:19 -0700507 }
508}
509
Ady Abraham690f4612021-07-01 23:24:03 -0700510bool DisplayDevice::setDesiredActiveMode(const ActiveModeInfo& info) {
511 ATRACE_CALL();
512
513 LOG_ALWAYS_FATAL_IF(!info.mode, "desired mode not provided");
514 LOG_ALWAYS_FATAL_IF(getPhysicalId() != info.mode->getPhysicalDisplayId(), "DisplayId mismatch");
515
516 ALOGV("%s(%s)", __func__, to_string(*info.mode).c_str());
517
518 std::scoped_lock lock(mActiveModeLock);
519 if (mDesiredActiveModeChanged) {
520 // If a mode change is pending, just cache the latest request in mDesiredActiveMode
Dominik Laskowski068173d2021-08-11 17:22:59 -0700521 const auto prevConfig = mDesiredActiveMode.event;
Ady Abraham690f4612021-07-01 23:24:03 -0700522 mDesiredActiveMode = info;
523 mDesiredActiveMode.event = mDesiredActiveMode.event | prevConfig;
524 return false;
525 }
526
527 // Check if we are already at the desired mode
528 if (getActiveMode()->getId() == info.mode->getId()) {
529 return false;
530 }
531
532 // Initiate a mode change.
533 mDesiredActiveModeChanged = true;
534 mDesiredActiveMode = info;
535 return true;
536}
537
538std::optional<DisplayDevice::ActiveModeInfo> DisplayDevice::getDesiredActiveMode() const {
539 std::scoped_lock lock(mActiveModeLock);
540 if (mDesiredActiveModeChanged) return mDesiredActiveMode;
541 return std::nullopt;
542}
543
544void DisplayDevice::clearDesiredActiveModeState() {
545 std::scoped_lock lock(mActiveModeLock);
Dominik Laskowski068173d2021-08-11 17:22:59 -0700546 mDesiredActiveMode.event = scheduler::DisplayModeEvent::None;
Ady Abraham690f4612021-07-01 23:24:03 -0700547 mDesiredActiveModeChanged = false;
548}
549
Ady Abrahama92a5682022-06-07 23:35:38 +0000550status_t DisplayDevice::setRefreshRatePolicy(
551 const std::optional<scheduler::RefreshRateConfigs::Policy>& policy, bool overridePolicy) {
552 const auto oldPolicy = mRefreshRateConfigs->getCurrentPolicy();
553 const status_t setPolicyResult = overridePolicy
554 ? mRefreshRateConfigs->setOverridePolicy(policy)
555 : mRefreshRateConfigs->setDisplayManagerPolicy(*policy);
556
557 if (setPolicyResult == OK) {
558 const int numModeChanges = mNumModeSwitchesInPolicy.exchange(0);
559
560 ALOGI("Display %s policy changed\n"
561 "Previous: {%s}\n"
562 "Current: {%s}\n"
563 "%d mode changes were performed under the previous policy",
564 to_string(getId()).c_str(), oldPolicy.toString().c_str(),
565 policy ? policy->toString().c_str() : "null", numModeChanges);
566 }
567
568 return setPolicyResult;
569}
570
Dominik Laskowski663bd282018-04-19 15:26:54 -0700571std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1);
Peiyong Linfd997e02018-03-28 15:29:00 -0700572
573} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800574
575// TODO(b/129481165): remove the #pragma below and fix conversion issues
576#pragma clang diagnostic pop // ignored "-Wconversion"