blob: eeab0cd78fa4506bfb20a29bd8aed8c74715cb50 [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
Dominik Laskowskib363c4c2022-08-02 14:03:41 -070042#include "Display/DisplaySnapshot.h"
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070043#include "DisplayDevice.h"
Mathias Agopian13127d82013-03-05 17:47:11 -080044#include "Layer.h"
Ady Abraham1b11bc62021-06-03 19:51:19 -070045#include "RefreshRateOverlay.h"
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070046#include "SurfaceFlinger.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070047
Peiyong Linfd997e02018-03-28 15:29:00 -070048namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049
Peiyong Lin65248e02020-04-18 21:15:07 -070050namespace hal = hardware::graphics::composer::hal;
51
Dominik Laskowski718f9602019-11-09 20:01:35 -080052ui::Transform::RotationFlags DisplayDevice::sPrimaryDisplayRotationFlags = ui::Transform::ROT_0;
Pablo Ceballos021623b2016-04-15 17:31:51 -070053
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070054DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010055 const sp<SurfaceFlinger>& flinger, HWComposer& hwComposer, const wp<IBinder>& displayToken,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070056 std::shared_ptr<compositionengine::Display> compositionDisplay)
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010057 : flinger(flinger),
58 hwComposer(hwComposer),
59 displayToken(displayToken),
60 compositionDisplay(compositionDisplay) {}
Chia-I Wube02ec02018-05-18 10:59:36 -070061
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070062DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args)
Lloyd Pique32cbe282018-10-19 13:09:22 -070063 : mFlinger(args.flinger),
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010064 mHwComposer(args.hwComposer),
Lloyd Pique2eef1d22018-09-18 21:30:04 -070065 mDisplayToken(args.displayToken),
Dominik Laskowskie9774092018-12-11 10:04:24 -080066 mSequenceId(args.sequenceId),
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),
Ady Abraham3efa3942021-06-24 19:01:25 -070071 mIsPrimary(args.isPrimary),
72 mRefreshRateConfigs(std::move(args.refreshRateConfigs)) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070073 mCompositionDisplay->editState().isSecure = args.isSecure;
Lloyd Pique31cb2942018-10-19 17:23:03 -070074 mCompositionDisplay->createRenderSurface(
Dominik Laskowskib9ac3e12021-04-23 13:01:16 -070075 compositionengine::RenderSurfaceCreationArgsBuilder()
76 .setDisplayWidth(ANativeWindow_getWidth(args.nativeWindow.get()))
77 .setDisplayHeight(ANativeWindow_getHeight(args.nativeWindow.get()))
78 .setNativeWindow(std::move(args.nativeWindow))
79 .setDisplaySurface(std::move(args.displaySurface))
80 .setMaxTextureCacheSize(
81 static_cast<size_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers))
82 .build());
Lloyd Pique31cb2942018-10-19 17:23:03 -070083
Vishnu Nair9b079a22020-01-21 14:36:08 -080084 if (!mFlinger->mDisableClientCompositionCache &&
85 SurfaceFlinger::maxFrameBufferAcquiredBuffers > 0) {
86 mCompositionDisplay->createClientCompositionCache(
87 static_cast<uint32_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers));
88 }
89
Vishnu Naira3140382022-02-24 14:07:11 -080090 mCompositionDisplay->setPredictCompositionStrategy(mFlinger->mPredictCompositionStrategy);
Alec Mouridda07d92022-04-25 22:39:25 +000091 mCompositionDisplay->setTreat170mAsSrgb(mFlinger->mTreat170mAsSrgb);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070092 mCompositionDisplay->createDisplayColorProfile(
Kriti Dang646f8ec2022-01-18 14:35:02 +010093 compositionengine::DisplayColorProfileCreationArgsBuilder()
94 .setHasWideColorGamut(args.hasWideColorGamut)
95 .setHdrCapabilities(std::move(args.hdrCapabilities))
96 .setSupportedPerFrameMetadata(args.supportedPerFrameMetadata)
97 .setHwcColorModes(std::move(args.hwcColorModes))
98 .Build());
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070099
Lloyd Pique32cbe282018-10-19 13:09:22 -0700100 if (!mCompositionDisplay->isValid()) {
101 ALOGE("Composition Display did not validate!");
102 }
103
Lloyd Pique31cb2942018-10-19 17:23:03 -0700104 mCompositionDisplay->getRenderSurface()->initialize();
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700105
linpeter1c69cd32022-07-13 19:20:48 +0800106 if (args.initialPowerMode.has_value()) setPowerMode(args.initialPowerMode.value());
Alec Mouriba013fa2018-10-16 12:43:11 -0700107
Jesse Hallffe1f192013-03-22 15:13:48 -0700108 // initialize the display orientation transform.
Dominik Laskowski718f9602019-11-09 20:01:35 -0800109 setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110}
111
Lloyd Pique09594832018-01-22 17:48:03 -0800112DisplayDevice::~DisplayDevice() = default;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700113
Lloyd Pique45a165a2018-10-19 11:54:47 -0700114void DisplayDevice::disconnect() {
115 mCompositionDisplay->disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700116}
117
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700118int DisplayDevice::getWidth() const {
Angel Aguayob108a6d2021-08-06 21:34:57 +0000119 return mCompositionDisplay->getState().displaySpace.getBounds().width;
Mathias Agopiana4912602012-07-12 14:25:33 -0700120}
121
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700122int DisplayDevice::getHeight() const {
Angel Aguayob108a6d2021-08-06 21:34:57 +0000123 return mCompositionDisplay->getState().displaySpace.getBounds().height;
Mathias Agopiana4912602012-07-12 14:25:33 -0700124}
125
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700126void DisplayDevice::setDisplayName(const std::string& displayName) {
127 if (!displayName.empty()) {
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700128 // never override the name with an empty name
129 mDisplayName = displayName;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700130 mCompositionDisplay->setName(displayName);
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700131 }
132}
133
Dominik Laskowski9f410f02022-01-08 16:22:46 -0800134auto DisplayDevice::getInputInfo() const -> InputInfo {
Prabir Pradhan48f8cb92021-08-26 14:05:36 -0700135 gui::DisplayInfo info;
136 info.displayId = getLayerStack().id;
137
138 // The physical orientation is set when the orientation of the display panel is
139 // different than the default orientation of the device. Other services like
140 // InputFlinger do not know about this, so we do not need to expose the physical
141 // orientation of the panel outside of SurfaceFlinger.
142 const ui::Rotation inversePhysicalOrientation = ui::ROTATION_0 - mPhysicalOrientation;
143 auto width = getWidth();
144 auto height = getHeight();
145 if (inversePhysicalOrientation == ui::ROTATION_90 ||
146 inversePhysicalOrientation == ui::ROTATION_270) {
147 std::swap(width, height);
148 }
149 const ui::Transform undoPhysicalOrientation(ui::Transform::toRotationFlags(
150 inversePhysicalOrientation),
151 width, height);
152 const auto& displayTransform = undoPhysicalOrientation * getTransform();
153 // Send the inverse display transform to input so it can convert display coordinates to
154 // logical display.
155 info.transform = displayTransform.inverse();
156
157 info.logicalWidth = getLayerStackSpaceRect().width();
158 info.logicalHeight = getLayerStackSpaceRect().height();
Dominik Laskowski9f410f02022-01-08 16:22:46 -0800159
160 return {.info = info,
161 .transform = displayTransform,
162 .receivesInput = receivesInput(),
163 .isSecure = isSecure()};
Prabir Pradhan48f8cb92021-08-26 14:05:36 -0700164}
165
Peiyong Lin65248e02020-04-18 21:15:07 -0700166void DisplayDevice::setPowerMode(hal::PowerMode mode) {
joenchene72ba5e2022-08-24 13:08:58 +0000167 if (mode == hal::PowerMode::OFF || mode == hal::PowerMode::ON) {
168 if (mStagedBrightness && mBrightness != *mStagedBrightness) {
169 getCompositionDisplay()->setNextBrightness(*mStagedBrightness);
170 mBrightness = *mStagedBrightness;
171 }
172 mStagedBrightness = std::nullopt;
173 getCompositionDisplay()->applyDisplayBrightness(true);
174 }
175
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700176 mPowerMode = mode;
linpeter1c69cd32022-07-13 19:20:48 +0800177
178 getCompositionDisplay()->setCompositionEnabled(mPowerMode.has_value() &&
179 *mPowerMode != hal::PowerMode::OFF);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700180}
181
Alec Mouri023c1882021-05-08 16:36:33 -0700182void DisplayDevice::enableLayerCaching(bool enable) {
183 getCompositionDisplay()->setLayerCachingEnabled(enable);
184}
185
linpeter1c69cd32022-07-13 19:20:48 +0800186std::optional<hal::PowerMode> DisplayDevice::getPowerMode() const {
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700187 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700188}
189
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700190bool DisplayDevice::isPoweredOn() const {
linpeter1c69cd32022-07-13 19:20:48 +0800191 return mPowerMode && *mPowerMode != hal::PowerMode::OFF;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700192}
193
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700194void DisplayDevice::setActiveMode(DisplayModeId modeId, const display::DisplaySnapshot& snapshot) {
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700195 const auto fpsOpt = snapshot.displayModes().get(modeId).transform(
196 [](const DisplayModePtr& mode) { return mode->getFps(); });
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700197
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700198 LOG_ALWAYS_FATAL_IF(!fpsOpt, "Unknown mode");
199 const Fps fps = *fpsOpt;
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700200
201 ATRACE_INT(mActiveModeFPSTrace.c_str(), fps.getIntValue());
202
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700203 mRefreshRateConfigs->setActiveModeId(modeId);
204
Ady Abraham1b11bc62021-06-03 19:51:19 -0700205 if (mRefreshRateOverlay) {
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700206 mRefreshRateOverlay->changeRefreshRate(fps);
Ady Abraham1b11bc62021-06-03 19:51:19 -0700207 }
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700208}
209
Ady Abraham690f4612021-07-01 23:24:03 -0700210status_t DisplayDevice::initiateModeChange(const ActiveModeInfo& info,
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100211 const hal::VsyncPeriodChangeConstraints& constraints,
Ady Abraham690f4612021-07-01 23:24:03 -0700212 hal::VsyncPeriodChangeTimeline* outTimeline) {
213 if (!info.mode || info.mode->getPhysicalDisplayId() != getPhysicalId()) {
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100214 ALOGE("Trying to initiate a mode change to invalid mode %s on display %s",
Ady Abraham690f4612021-07-01 23:24:03 -0700215 info.mode ? std::to_string(info.mode->getId().value()).c_str() : "null",
216 to_string(getId()).c_str());
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100217 return BAD_VALUE;
218 }
Ady Abrahama92a5682022-06-07 23:35:38 +0000219 mNumModeSwitchesInPolicy++;
Ady Abraham690f4612021-07-01 23:24:03 -0700220 mUpcomingActiveMode = info;
221 ATRACE_INT(mActiveModeFPSHwcTrace.c_str(), info.mode->getFps().getIntValue());
222 return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), info.mode->getHwcId(),
223 constraints, outTimeline);
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100224}
225
Marin Shalamanov045b7002021-01-07 16:56:24 +0100226nsecs_t DisplayDevice::getVsyncPeriodFromHWC() const {
227 const auto physicalId = getPhysicalId();
228 if (!mHwComposer.isConnected(physicalId)) {
229 return 0;
230 }
231
232 nsecs_t vsyncPeriod;
233 const auto status = mHwComposer.getDisplayVsyncPeriod(physicalId, &vsyncPeriod);
234 if (status == NO_ERROR) {
235 return vsyncPeriod;
236 }
237
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700238 return refreshRateConfigs().getActiveModePtr()->getVsyncPeriod();
Marin Shalamanov045b7002021-01-07 16:56:24 +0100239}
240
241nsecs_t DisplayDevice::getRefreshTimestamp() const {
242 const nsecs_t now = systemTime(CLOCK_MONOTONIC);
243 const auto vsyncPeriodNanos = getVsyncPeriodFromHWC();
244 return now - ((now - mLastHwVsync) % vsyncPeriodNanos);
245}
246
247void DisplayDevice::onVsync(nsecs_t timestamp) {
248 mLastHwVsync = timestamp;
249}
250
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800251ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700252 return mCompositionDisplay->getState().dataspace;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800253}
254
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700255void DisplayDevice::setLayerFilter(ui::LayerFilter filter) {
256 mCompositionDisplay->setLayerFilter(filter);
Ady Abraham1b11bc62021-06-03 19:51:19 -0700257 if (mRefreshRateOverlay) {
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700258 mRefreshRateOverlay->setLayerStack(filter.layerStack);
Ady Abraham1b11bc62021-06-03 19:51:19 -0700259 }
Mathias Agopian28947d72012-08-08 18:51:15 -0700260}
261
Evan Rosky2239b372021-05-20 13:43:47 -0700262void DisplayDevice::setFlags(uint32_t flags) {
263 mFlags = flags;
264}
265
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800266void DisplayDevice::setDisplaySize(int width, int height) {
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200267 LOG_FATAL_IF(!isVirtual(), "Changing the display size is supported only for virtual displays.");
Ady Abraham1b11bc62021-06-03 19:51:19 -0700268 const auto size = ui::Size(width, height);
269 mCompositionDisplay->setDisplaySize(size);
270 if (mRefreshRateOverlay) {
271 mRefreshRateOverlay->setViewport(size);
272 }
Michael Lentine47e45402014-07-18 15:34:25 -0700273}
274
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200275void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpaceRect,
276 Rect orientedDisplaySpaceRect) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700277 mOrientation = orientation;
278
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200279 if (isPrimary()) {
280 sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation);
281 }
282
Marin Shalamanov8c23c4e2020-08-19 15:26:31 +0200283 // We need to take care of display rotation for globalTransform for case if the panel is not
284 // installed aligned with device orientation.
285 const auto transformOrientation = orientation + mPhysicalOrientation;
Alec Mouri168f6cc2022-04-07 20:58:00 +0000286
287 const auto& state = getCompositionDisplay()->getState();
288
289 // If the layer stack and destination frames have never been set, then configure them to be the
290 // same as the physical device, taking into account the total transform.
291 if (!orientedDisplaySpaceRect.isValid()) {
292 ui::Size bounds = state.displaySpace.getBounds();
293 bounds.rotate(transformOrientation);
294 orientedDisplaySpaceRect = Rect(bounds);
295 }
296 if (layerStackSpaceRect.isEmpty()) {
297 ui::Size bounds = state.framebufferSpace.getBounds();
298 bounds.rotate(transformOrientation);
299 layerStackSpaceRect = Rect(bounds);
300 }
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200301 getCompositionDisplay()->setProjection(transformOrientation, layerStackSpaceRect,
302 orientedDisplaySpaceRect);
Mathias Agopian1b031492012-06-20 17:51:20 -0700303}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700304
Alec Mouricdf16792021-12-10 13:16:06 -0800305void DisplayDevice::stageBrightness(float brightness) {
306 mStagedBrightness = brightness;
307}
308
309void DisplayDevice::persistBrightness(bool needsComposite) {
joenchen42928102022-09-06 18:03:57 +0000310 if (mStagedBrightness && mBrightness != *mStagedBrightness) {
311 if (needsComposite) {
312 getCompositionDisplay()->setNextBrightness(*mStagedBrightness);
313 }
Alec Mouricdf16792021-12-10 13:16:06 -0800314 mBrightness = *mStagedBrightness;
315 }
316 mStagedBrightness = std::nullopt;
317}
318
319std::optional<float> DisplayDevice::getStagedBrightness() const {
320 return mStagedBrightness;
321}
322
Dominik Laskowski718f9602019-11-09 20:01:35 -0800323ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() {
324 return sPrimaryDisplayRotationFlags;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700325}
326
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700327std::string DisplayDevice::getDebugName() const {
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700328 using namespace std::string_literals;
329
330 std::string name = "Display "s + to_string(getId()) + " ("s;
331
Dominik Laskowskib363c4c2022-08-02 14:03:41 -0700332 name += isVirtual() ? "virtual"s : "physical"s;
Dominik Laskowski55c85402020-01-21 16:25:47 -0800333
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700334 if (isPrimary()) {
335 name += ", primary"s;
336 }
337
338 return name + ", \""s + mDisplayName + "\")"s;
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700339}
340
Dominik Laskowskie70461a2022-08-30 14:42:01 -0700341void DisplayDevice::dump(utils::Dumper& dumper) const {
342 using namespace std::string_view_literals;
Marin Shalamanov5801c942020-12-17 17:00:13 +0100343
Dominik Laskowskie70461a2022-08-30 14:42:01 -0700344 dumper.dump({}, getDebugName());
Dominik Laskowski0acc3842022-04-07 11:23:42 -0700345
Dominik Laskowskie70461a2022-08-30 14:42:01 -0700346 utils::Dumper::Indent indent(dumper);
347 dumper.dump("powerMode"sv, mPowerMode);
Ady Abraham3efa3942021-06-24 19:01:25 -0700348
349 if (mRefreshRateConfigs) {
Dominik Laskowskie70461a2022-08-30 14:42:01 -0700350 mRefreshRateConfigs->dump(dumper);
Ady Abraham3efa3942021-06-24 19:01:25 -0700351 }
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700352}
Irvelffc9efc2016-07-27 15:16:37 -0700353
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700354bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const {
355 return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent);
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700356}
357
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200358DisplayId DisplayDevice::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700359 return mCompositionDisplay->getId();
360}
361
362bool DisplayDevice::isSecure() const {
363 return mCompositionDisplay->isSecure();
364}
365
Angel Aguayob108a6d2021-08-06 21:34:57 +0000366const Rect DisplayDevice::getBounds() const {
367 return mCompositionDisplay->getState().displaySpace.getBoundsAsRect();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700368}
369
370const Region& DisplayDevice::getUndefinedRegion() const {
371 return mCompositionDisplay->getState().undefinedRegion;
372}
373
374bool DisplayDevice::needsFiltering() const {
375 return mCompositionDisplay->getState().needsFiltering;
376}
377
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800378ui::LayerStack DisplayDevice::getLayerStack() const {
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700379 return mCompositionDisplay->getState().layerFilter.layerStack;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700380}
381
Garfield Tan54edd912020-10-21 16:31:41 -0700382ui::Transform::RotationFlags DisplayDevice::getTransformHint() const {
383 return mCompositionDisplay->getTransformHint();
384}
385
Lloyd Pique32cbe282018-10-19 13:09:22 -0700386const ui::Transform& DisplayDevice::getTransform() const {
387 return mCompositionDisplay->getState().transform;
388}
389
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200390const Rect& DisplayDevice::getLayerStackSpaceRect() const {
Angel Aguayob108a6d2021-08-06 21:34:57 +0000391 return mCompositionDisplay->getState().layerStackSpace.getContent();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700392}
393
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200394const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const {
Angel Aguayob108a6d2021-08-06 21:34:57 +0000395 return mCompositionDisplay->getState().orientedDisplaySpace.getContent();
Lloyd Pique32cbe282018-10-19 13:09:22 -0700396}
397
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700398bool DisplayDevice::hasWideColorGamut() const {
399 return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut();
400}
401
402bool DisplayDevice::hasHDR10PlusSupport() const {
403 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport();
404}
405
406bool DisplayDevice::hasHDR10Support() const {
407 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support();
408}
409
410bool DisplayDevice::hasHLGSupport() const {
411 return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport();
412}
413
414bool DisplayDevice::hasDolbyVisionSupport() const {
415 return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport();
416}
417
418int DisplayDevice::getSupportedPerFrameMetadata() const {
419 return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata();
420}
421
Kriti Dang49ad4132021-01-08 11:49:56 +0100422void DisplayDevice::overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes) {
423 mOverrideHdrTypes = hdrTypes;
424}
425
426HdrCapabilities DisplayDevice::getHdrCapabilities() const {
427 const HdrCapabilities& capabilities =
428 mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities();
429 std::vector<ui::Hdr> hdrTypes = capabilities.getSupportedHdrTypes();
430 if (!mOverrideHdrTypes.empty()) {
431 hdrTypes = mOverrideHdrTypes;
432 }
433 return HdrCapabilities(hdrTypes, capabilities.getDesiredMaxLuminance(),
434 capabilities.getDesiredMaxAverageLuminance(),
435 capabilities.getDesiredMinLuminance());
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700436}
437
Ady Abraham1b11bc62021-06-03 19:51:19 -0700438void DisplayDevice::enableRefreshRateOverlay(bool enable, bool showSpinnner) {
439 if (!enable) {
440 mRefreshRateOverlay.reset();
441 return;
442 }
443
Dominik Laskowski8c4356c2022-03-21 08:19:54 -0700444 const auto fpsRange = mRefreshRateConfigs->getSupportedRefreshRateRange();
445 mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(fpsRange, showSpinnner);
Ady Abraham1b11bc62021-06-03 19:51:19 -0700446 mRefreshRateOverlay->setLayerStack(getLayerStack());
447 mRefreshRateOverlay->setViewport(getSize());
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700448 mRefreshRateOverlay->changeRefreshRate(getActiveMode().getFps());
Ady Abraham1b11bc62021-06-03 19:51:19 -0700449}
450
451bool DisplayDevice::onKernelTimerChanged(std::optional<DisplayModeId> desiredModeId,
452 bool timerExpired) {
453 if (mRefreshRateConfigs && mRefreshRateOverlay) {
454 const auto newRefreshRate =
455 mRefreshRateConfigs->onKernelTimerChanged(desiredModeId, timerExpired);
456 if (newRefreshRate) {
457 mRefreshRateOverlay->changeRefreshRate(*newRefreshRate);
458 return true;
459 }
460 }
461
462 return false;
463}
464
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700465void DisplayDevice::animateRefreshRateOverlay() {
Ady Abraham1b11bc62021-06-03 19:51:19 -0700466 if (mRefreshRateOverlay) {
Dominik Laskowskie0e0cde2021-07-30 10:42:05 -0700467 mRefreshRateOverlay->animate();
Ady Abraham1b11bc62021-06-03 19:51:19 -0700468 }
469}
470
Ady Abraham690f4612021-07-01 23:24:03 -0700471bool DisplayDevice::setDesiredActiveMode(const ActiveModeInfo& info) {
472 ATRACE_CALL();
473
474 LOG_ALWAYS_FATAL_IF(!info.mode, "desired mode not provided");
475 LOG_ALWAYS_FATAL_IF(getPhysicalId() != info.mode->getPhysicalDisplayId(), "DisplayId mismatch");
476
477 ALOGV("%s(%s)", __func__, to_string(*info.mode).c_str());
478
479 std::scoped_lock lock(mActiveModeLock);
480 if (mDesiredActiveModeChanged) {
481 // If a mode change is pending, just cache the latest request in mDesiredActiveMode
Dominik Laskowski068173d2021-08-11 17:22:59 -0700482 const auto prevConfig = mDesiredActiveMode.event;
Ady Abraham690f4612021-07-01 23:24:03 -0700483 mDesiredActiveMode = info;
484 mDesiredActiveMode.event = mDesiredActiveMode.event | prevConfig;
485 return false;
486 }
487
488 // Check if we are already at the desired mode
Dominik Laskowski02bb2072022-08-26 15:02:52 -0700489 if (refreshRateConfigs().getActiveModePtr()->getId() == info.mode->getId()) {
Ady Abraham690f4612021-07-01 23:24:03 -0700490 return false;
491 }
492
493 // Initiate a mode change.
494 mDesiredActiveModeChanged = true;
495 mDesiredActiveMode = info;
496 return true;
497}
498
499std::optional<DisplayDevice::ActiveModeInfo> DisplayDevice::getDesiredActiveMode() const {
500 std::scoped_lock lock(mActiveModeLock);
501 if (mDesiredActiveModeChanged) return mDesiredActiveMode;
502 return std::nullopt;
503}
504
505void DisplayDevice::clearDesiredActiveModeState() {
506 std::scoped_lock lock(mActiveModeLock);
Dominik Laskowski068173d2021-08-11 17:22:59 -0700507 mDesiredActiveMode.event = scheduler::DisplayModeEvent::None;
Ady Abraham690f4612021-07-01 23:24:03 -0700508 mDesiredActiveModeChanged = false;
509}
510
Ady Abrahama92a5682022-06-07 23:35:38 +0000511status_t DisplayDevice::setRefreshRatePolicy(
512 const std::optional<scheduler::RefreshRateConfigs::Policy>& policy, bool overridePolicy) {
513 const auto oldPolicy = mRefreshRateConfigs->getCurrentPolicy();
514 const status_t setPolicyResult = overridePolicy
515 ? mRefreshRateConfigs->setOverridePolicy(policy)
516 : mRefreshRateConfigs->setDisplayManagerPolicy(*policy);
517
518 if (setPolicyResult == OK) {
519 const int numModeChanges = mNumModeSwitchesInPolicy.exchange(0);
520
521 ALOGI("Display %s policy changed\n"
522 "Previous: {%s}\n"
523 "Current: {%s}\n"
524 "%d mode changes were performed under the previous policy",
525 to_string(getId()).c_str(), oldPolicy.toString().c_str(),
526 policy ? policy->toString().c_str() : "null", numModeChanges);
527 }
528
529 return setPolicyResult;
530}
531
Dominik Laskowski663bd282018-04-19 15:26:54 -0700532std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1);
Peiyong Linfd997e02018-03-28 15:29:00 -0700533
534} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800535
536// TODO(b/129481165): remove the #pragma below and fix conversion issues
537#pragma clang diagnostic pop // ignored "-Wconversion"