blob: 4445eea60435c52b35fa4263ba8759c8ff6b8cc4 [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
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -070027#include <android-base/stringprintf.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070028#include <compositionengine/CompositionEngine.h>
29#include <compositionengine/Display.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070030#include <compositionengine/DisplayColorProfile.h>
31#include <compositionengine/DisplayColorProfileCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070032#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070033#include <compositionengine/DisplaySurface.h>
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020034#include <compositionengine/ProjectionSpace.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070035#include <compositionengine/RenderSurface.h>
36#include <compositionengine/RenderSurfaceCreationArgs.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070037#include <compositionengine/impl/OutputCompositionState.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070038#include <configstore/Utils.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070039#include <log/log.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080040#include <system/window.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070041#include <ui/GraphicTypes.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
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
Yiwei Zhang5434a782018-12-05 18:06:32 -080052using android::base::StringAppendF;
Jaesoo Lee720a7242017-01-31 15:26:18 +090053
Dominik Laskowski718f9602019-11-09 20:01:35 -080054ui::Transform::RotationFlags DisplayDevice::sPrimaryDisplayRotationFlags = ui::Transform::ROT_0;
Pablo Ceballos021623b2016-04-15 17:31:51 -070055
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070056DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010057 const sp<SurfaceFlinger>& flinger, HWComposer& hwComposer, const wp<IBinder>& displayToken,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070058 std::shared_ptr<compositionengine::Display> compositionDisplay)
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010059 : flinger(flinger),
60 hwComposer(hwComposer),
61 displayToken(displayToken),
62 compositionDisplay(compositionDisplay) {}
Chia-I Wube02ec02018-05-18 10:59:36 -070063
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070064DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args)
Lloyd Pique32cbe282018-10-19 13:09:22 -070065 : mFlinger(args.flinger),
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010066 mHwComposer(args.hwComposer),
Lloyd Pique2eef1d22018-09-18 21:30:04 -070067 mDisplayToken(args.displayToken),
Dominik Laskowskie9774092018-12-11 10:04:24 -080068 mSequenceId(args.sequenceId),
Dominik Laskowski55c85402020-01-21 16:25:47 -080069 mConnectionType(args.connectionType),
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070070 mCompositionDisplay{args.compositionDisplay},
Ady Abraham690f4612021-07-01 23:24:03 -070071 mActiveModeFPSTrace("ActiveModeFPS -" + to_string(getId())),
72 mActiveModeFPSHwcTrace("ActiveModeFPS_HWC -" + to_string(getId())),
Dominik Laskowski718f9602019-11-09 20:01:35 -080073 mPhysicalOrientation(args.physicalOrientation),
Marin Shalamanov5801c942020-12-17 17:00:13 +010074 mSupportedModes(std::move(args.supportedModes)),
Ady Abraham3efa3942021-06-24 19:01:25 -070075 mIsPrimary(args.isPrimary),
76 mRefreshRateConfigs(std::move(args.refreshRateConfigs)) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070077 mCompositionDisplay->editState().isSecure = args.isSecure;
Lloyd Pique31cb2942018-10-19 17:23:03 -070078 mCompositionDisplay->createRenderSurface(
Dominik Laskowskib9ac3e12021-04-23 13:01:16 -070079 compositionengine::RenderSurfaceCreationArgsBuilder()
80 .setDisplayWidth(ANativeWindow_getWidth(args.nativeWindow.get()))
81 .setDisplayHeight(ANativeWindow_getHeight(args.nativeWindow.get()))
82 .setNativeWindow(std::move(args.nativeWindow))
83 .setDisplaySurface(std::move(args.displaySurface))
84 .setMaxTextureCacheSize(
85 static_cast<size_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers))
86 .build());
Lloyd Pique31cb2942018-10-19 17:23:03 -070087
Vishnu Nair9b079a22020-01-21 14:36:08 -080088 if (!mFlinger->mDisableClientCompositionCache &&
89 SurfaceFlinger::maxFrameBufferAcquiredBuffers > 0) {
90 mCompositionDisplay->createClientCompositionCache(
91 static_cast<uint32_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers));
92 }
93
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070094 mCompositionDisplay->createDisplayColorProfile(
95 compositionengine::DisplayColorProfileCreationArgs{args.hasWideColorGamut,
96 std::move(args.hdrCapabilities),
97 args.supportedPerFrameMetadata,
98 args.hwcColorModes});
99
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
Lloyd Pique32cbe282018-10-19 13:09:22 -0700106 setPowerMode(args.initialPowerMode);
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 {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200119 return mCompositionDisplay->getState().displaySpace.bounds.getWidth();
Mathias Agopiana4912602012-07-12 14:25:33 -0700120}
121
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700122int DisplayDevice::getHeight() const {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200123 return mCompositionDisplay->getState().displaySpace.bounds.getHeight();
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
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200134void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info) {
135 mDeviceProductInfo = std::move(info);
136}
137
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700138uint32_t DisplayDevice::getPageFlipCount() const {
Lloyd Pique31cb2942018-10-19 17:23:03 -0700139 return mCompositionDisplay->getRenderSurface()->getPageFlipCount();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800140}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800141
Mathias Agopian1b031492012-06-20 17:51:20 -0700142// ----------------------------------------------------------------------------
Peiyong Lin65248e02020-04-18 21:15:07 -0700143void DisplayDevice::setPowerMode(hal::PowerMode mode) {
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700144 mPowerMode = mode;
Peiyong Lin65248e02020-04-18 21:15:07 -0700145 getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700146}
147
Alec Mouri023c1882021-05-08 16:36:33 -0700148void DisplayDevice::enableLayerCaching(bool enable) {
149 getCompositionDisplay()->setLayerCachingEnabled(enable);
150}
151
Peiyong Lin65248e02020-04-18 21:15:07 -0700152hal::PowerMode DisplayDevice::getPowerMode() const {
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700153 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700154}
155
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700156bool DisplayDevice::isPoweredOn() const {
Peiyong Lin65248e02020-04-18 21:15:07 -0700157 return mPowerMode != hal::PowerMode::OFF;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700158}
159
Marin Shalamanov5801c942020-12-17 17:00:13 +0100160void DisplayDevice::setActiveMode(DisplayModeId id) {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100161 const auto mode = getMode(id);
162 LOG_FATAL_IF(!mode, "Cannot set active mode which is not supported.");
Ady Abraham690f4612021-07-01 23:24:03 -0700163 ATRACE_INT(mActiveModeFPSTrace.c_str(), mode->getFps().getIntValue());
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100164 mActiveMode = mode;
Ady Abraham3efa3942021-06-24 19:01:25 -0700165 if (mRefreshRateConfigs) {
166 mRefreshRateConfigs->setCurrentModeId(mActiveMode->getId());
167 }
Ady Abraham1b11bc62021-06-03 19:51:19 -0700168 if (mRefreshRateOverlay) {
169 mRefreshRateOverlay->changeRefreshRate(mActiveMode->getFps());
170 }
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700171}
172
Ady Abraham690f4612021-07-01 23:24:03 -0700173status_t DisplayDevice::initiateModeChange(const ActiveModeInfo& info,
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100174 const hal::VsyncPeriodChangeConstraints& constraints,
Ady Abraham690f4612021-07-01 23:24:03 -0700175 hal::VsyncPeriodChangeTimeline* outTimeline) {
176 if (!info.mode || info.mode->getPhysicalDisplayId() != getPhysicalId()) {
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100177 ALOGE("Trying to initiate a mode change to invalid mode %s on display %s",
Ady Abraham690f4612021-07-01 23:24:03 -0700178 info.mode ? std::to_string(info.mode->getId().value()).c_str() : "null",
179 to_string(getId()).c_str());
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100180 return BAD_VALUE;
181 }
Ady Abraham690f4612021-07-01 23:24:03 -0700182 mUpcomingActiveMode = info;
183 ATRACE_INT(mActiveModeFPSHwcTrace.c_str(), info.mode->getFps().getIntValue());
184 return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), info.mode->getHwcId(),
185 constraints, outTimeline);
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100186}
187
Marin Shalamanov5801c942020-12-17 17:00:13 +0100188const DisplayModePtr& DisplayDevice::getActiveMode() const {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100189 return mActiveMode;
Marin Shalamanov5801c942020-12-17 17:00:13 +0100190}
191
192const DisplayModes& DisplayDevice::getSupportedModes() const {
193 return mSupportedModes;
194}
195
196DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100197 const auto it = std::find_if(mSupportedModes.begin(), mSupportedModes.end(),
198 [&](DisplayModePtr mode) { return mode->getId() == modeId; });
199 if (it != mSupportedModes.end()) {
200 return *it;
Marin Shalamanov5801c942020-12-17 17:00:13 +0100201 }
202 return nullptr;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700203}
204
Marin Shalamanov045b7002021-01-07 16:56:24 +0100205nsecs_t DisplayDevice::getVsyncPeriodFromHWC() const {
206 const auto physicalId = getPhysicalId();
207 if (!mHwComposer.isConnected(physicalId)) {
208 return 0;
209 }
210
211 nsecs_t vsyncPeriod;
212 const auto status = mHwComposer.getDisplayVsyncPeriod(physicalId, &vsyncPeriod);
213 if (status == NO_ERROR) {
214 return vsyncPeriod;
215 }
216
217 return getActiveMode()->getFps().getPeriodNsecs();
218}
219
220nsecs_t DisplayDevice::getRefreshTimestamp() const {
221 const nsecs_t now = systemTime(CLOCK_MONOTONIC);
222 const auto vsyncPeriodNanos = getVsyncPeriodFromHWC();
223 return now - ((now - mLastHwVsync) % vsyncPeriodNanos);
224}
225
226void DisplayDevice::onVsync(nsecs_t timestamp) {
227 mLastHwVsync = timestamp;
228}
229
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800230ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700231 return mCompositionDisplay->getState().dataspace;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800232}
233
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800234void DisplayDevice::setLayerStack(ui::LayerStack stack) {
Ady Abraham7825c682021-05-17 15:12:14 -0700235 mCompositionDisplay->setLayerStackFilter(stack, isInternal());
Ady Abraham1b11bc62021-06-03 19:51:19 -0700236 if (mRefreshRateOverlay) {
237 mRefreshRateOverlay->setLayerStack(stack);
238 }
Mathias Agopian28947d72012-08-08 18:51:15 -0700239}
240
Evan Rosky2239b372021-05-20 13:43:47 -0700241void DisplayDevice::setFlags(uint32_t flags) {
242 mFlags = flags;
243}
244
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800245void DisplayDevice::setDisplaySize(int width, int height) {
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200246 LOG_FATAL_IF(!isVirtual(), "Changing the display size is supported only for virtual displays.");
Ady Abraham1b11bc62021-06-03 19:51:19 -0700247 const auto size = ui::Size(width, height);
248 mCompositionDisplay->setDisplaySize(size);
249 if (mRefreshRateOverlay) {
250 mRefreshRateOverlay->setViewport(size);
251 }
Michael Lentine47e45402014-07-18 15:34:25 -0700252}
253
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200254void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpaceRect,
255 Rect orientedDisplaySpaceRect) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700256 mOrientation = orientation;
257
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200258 if (isPrimary()) {
259 sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation);
260 }
261
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200262 if (!orientedDisplaySpaceRect.isValid()) {
Marin Shalamanov4429cac2020-10-01 12:56:24 +0200263 // The destination frame can be invalid if it has never been set,
264 // in that case we assume the whole display size.
265 orientedDisplaySpaceRect = getCompositionDisplay()->getState().displaySpace.bounds;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800266 }
267
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200268 if (layerStackSpaceRect.isEmpty()) {
Marin Shalamanov4429cac2020-10-01 12:56:24 +0200269 // The layerStackSpaceRect can be invalid if it has never been set, in that case
270 // we assume the whole framebuffer size.
271 layerStackSpaceRect = getCompositionDisplay()->getState().framebufferSpace.bounds;
Marin Shalamanov8c23c4e2020-08-19 15:26:31 +0200272 if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200273 std::swap(layerStackSpaceRect.right, layerStackSpaceRect.bottom);
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800274 }
275 }
276
Marin Shalamanov8c23c4e2020-08-19 15:26:31 +0200277 // We need to take care of display rotation for globalTransform for case if the panel is not
278 // installed aligned with device orientation.
279 const auto transformOrientation = orientation + mPhysicalOrientation;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200280 getCompositionDisplay()->setProjection(transformOrientation, layerStackSpaceRect,
281 orientedDisplaySpaceRect);
Mathias Agopian1b031492012-06-20 17:51:20 -0700282}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700283
Dominik Laskowski718f9602019-11-09 20:01:35 -0800284ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() {
285 return sPrimaryDisplayRotationFlags;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700286}
287
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700288std::string DisplayDevice::getDebugName() const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800289 const char* type = "virtual";
290 if (mConnectionType) {
Ady Abraham7825c682021-05-17 15:12:14 -0700291 type = isInternal() ? "internal" : "external";
Dominik Laskowski55c85402020-01-21 16:25:47 -0800292 }
293
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200294 return base::StringPrintf("DisplayDevice{%s, %s%s, \"%s\"}", to_string(getId()).c_str(), type,
Dominik Laskowski55c85402020-01-21 16:25:47 -0800295 isPrimary() ? ", primary" : "", mDisplayName.c_str());
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700296}
297
Yiwei Zhang5434a782018-12-05 18:06:32 -0800298void DisplayDevice::dump(std::string& result) const {
Yiwei Zhang5434a782018-12-05 18:06:32 -0800299 StringAppendF(&result, "+ %s\n", getDebugName().c_str());
Marin Shalamanov5801c942020-12-17 17:00:13 +0100300 StringAppendF(&result, " powerMode=%s (%d)\n", to_string(mPowerMode).c_str(),
Peiyong Lin65248e02020-04-18 21:15:07 -0700301 static_cast<int32_t>(mPowerMode));
Marin Shalamanov84b85482021-05-05 13:54:35 +0200302 const auto activeMode = getActiveMode();
Alec Mouri934e0cf2021-02-09 14:54:10 -0800303 StringAppendF(&result, " activeMode=%s\n",
Marin Shalamanov84b85482021-05-05 13:54:35 +0200304 activeMode ? to_string(*activeMode).c_str() : "none");
Marin Shalamanov5801c942020-12-17 17:00:13 +0100305
306 result.append(" supportedModes=\n");
307
308 for (const auto& mode : mSupportedModes) {
309 result.append(" ");
310 result.append(to_string(*mode));
311 result.append("\n");
312 }
313 StringAppendF(&result, " deviceProductInfo=");
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200314 if (mDeviceProductInfo) {
315 mDeviceProductInfo->dump(result);
316 } else {
317 result.append("{}");
318 }
Marin Shalamanov5801c942020-12-17 17:00:13 +0100319 result.append("\n");
Lloyd Pique32cbe282018-10-19 13:09:22 -0700320 getCompositionDisplay()->dump(result);
Ady Abraham3efa3942021-06-24 19:01:25 -0700321
322 if (mRefreshRateConfigs) {
323 mRefreshRateConfigs->dump(result);
324 }
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700325}
Irvelffc9efc2016-07-27 15:16:37 -0700326
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700327bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const {
328 return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent);
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700329}
330
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200331DisplayId DisplayDevice::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700332 return mCompositionDisplay->getId();
333}
334
335bool DisplayDevice::isSecure() const {
336 return mCompositionDisplay->isSecure();
337}
338
Lloyd Pique32cbe282018-10-19 13:09:22 -0700339const Rect& DisplayDevice::getBounds() const {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200340 return mCompositionDisplay->getState().displaySpace.bounds;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700341}
342
343const Region& DisplayDevice::getUndefinedRegion() const {
344 return mCompositionDisplay->getState().undefinedRegion;
345}
346
347bool DisplayDevice::needsFiltering() const {
348 return mCompositionDisplay->getState().needsFiltering;
349}
350
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800351ui::LayerStack DisplayDevice::getLayerStack() const {
Lloyd Piqueef36b002019-01-23 17:52:04 -0800352 return mCompositionDisplay->getState().layerStackId;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700353}
354
Garfield Tan54edd912020-10-21 16:31:41 -0700355ui::Transform::RotationFlags DisplayDevice::getTransformHint() const {
356 return mCompositionDisplay->getTransformHint();
357}
358
Lloyd Pique32cbe282018-10-19 13:09:22 -0700359const ui::Transform& DisplayDevice::getTransform() const {
360 return mCompositionDisplay->getState().transform;
361}
362
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200363const Rect& DisplayDevice::getLayerStackSpaceRect() const {
364 return mCompositionDisplay->getState().layerStackSpace.content;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700365}
366
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200367const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const {
368 return mCompositionDisplay->getState().orientedDisplaySpace.content;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700369}
370
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700371bool DisplayDevice::hasWideColorGamut() const {
372 return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut();
373}
374
375bool DisplayDevice::hasHDR10PlusSupport() const {
376 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport();
377}
378
379bool DisplayDevice::hasHDR10Support() const {
380 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support();
381}
382
383bool DisplayDevice::hasHLGSupport() const {
384 return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport();
385}
386
387bool DisplayDevice::hasDolbyVisionSupport() const {
388 return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport();
389}
390
391int DisplayDevice::getSupportedPerFrameMetadata() const {
392 return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata();
393}
394
Kriti Dang49ad4132021-01-08 11:49:56 +0100395void DisplayDevice::overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes) {
396 mOverrideHdrTypes = hdrTypes;
397}
398
399HdrCapabilities DisplayDevice::getHdrCapabilities() const {
400 const HdrCapabilities& capabilities =
401 mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities();
402 std::vector<ui::Hdr> hdrTypes = capabilities.getSupportedHdrTypes();
403 if (!mOverrideHdrTypes.empty()) {
404 hdrTypes = mOverrideHdrTypes;
405 }
406 return HdrCapabilities(hdrTypes, capabilities.getDesiredMaxLuminance(),
407 capabilities.getDesiredMaxAverageLuminance(),
408 capabilities.getDesiredMinLuminance());
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700409}
410
Ady Abraham1b11bc62021-06-03 19:51:19 -0700411void DisplayDevice::enableRefreshRateOverlay(bool enable, bool showSpinnner) {
412 if (!enable) {
413 mRefreshRateOverlay.reset();
414 return;
415 }
416
417 const auto [lowFps, highFps] = mRefreshRateConfigs->getSupportedRefreshRateRange();
418 mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(*mFlinger, lowFps.getIntValue(),
419 highFps.getIntValue(), showSpinnner);
420 mRefreshRateOverlay->setLayerStack(getLayerStack());
421 mRefreshRateOverlay->setViewport(getSize());
422 mRefreshRateOverlay->changeRefreshRate(getActiveMode()->getFps());
423}
424
425bool DisplayDevice::onKernelTimerChanged(std::optional<DisplayModeId> desiredModeId,
426 bool timerExpired) {
427 if (mRefreshRateConfigs && mRefreshRateOverlay) {
428 const auto newRefreshRate =
429 mRefreshRateConfigs->onKernelTimerChanged(desiredModeId, timerExpired);
430 if (newRefreshRate) {
431 mRefreshRateOverlay->changeRefreshRate(*newRefreshRate);
432 return true;
433 }
434 }
435
436 return false;
437}
438
439void DisplayDevice::onInvalidate() {
440 if (mRefreshRateOverlay) {
441 mRefreshRateOverlay->onInvalidate();
442 }
443}
444
Ady Abraham690f4612021-07-01 23:24:03 -0700445bool DisplayDevice::setDesiredActiveMode(const ActiveModeInfo& info) {
446 ATRACE_CALL();
447
448 LOG_ALWAYS_FATAL_IF(!info.mode, "desired mode not provided");
449 LOG_ALWAYS_FATAL_IF(getPhysicalId() != info.mode->getPhysicalDisplayId(), "DisplayId mismatch");
450
451 ALOGV("%s(%s)", __func__, to_string(*info.mode).c_str());
452
453 std::scoped_lock lock(mActiveModeLock);
454 if (mDesiredActiveModeChanged) {
455 // If a mode change is pending, just cache the latest request in mDesiredActiveMode
456 const Scheduler::ModeEvent prevConfig = mDesiredActiveMode.event;
457 mDesiredActiveMode = info;
458 mDesiredActiveMode.event = mDesiredActiveMode.event | prevConfig;
459 return false;
460 }
461
462 // Check if we are already at the desired mode
463 if (getActiveMode()->getId() == info.mode->getId()) {
464 return false;
465 }
466
467 // Initiate a mode change.
468 mDesiredActiveModeChanged = true;
469 mDesiredActiveMode = info;
470 return true;
471}
472
473std::optional<DisplayDevice::ActiveModeInfo> DisplayDevice::getDesiredActiveMode() const {
474 std::scoped_lock lock(mActiveModeLock);
475 if (mDesiredActiveModeChanged) return mDesiredActiveMode;
476 return std::nullopt;
477}
478
479void DisplayDevice::clearDesiredActiveModeState() {
480 std::scoped_lock lock(mActiveModeLock);
481 mDesiredActiveMode.event = Scheduler::ModeEvent::None;
482 mDesiredActiveModeChanged = false;
483}
484
Dominik Laskowski663bd282018-04-19 15:26:54 -0700485std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1);
Peiyong Linfd997e02018-03-28 15:29:00 -0700486
487} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800488
489// TODO(b/129481165): remove the #pragma below and fix conversion issues
490#pragma clang diagnostic pop // ignored "-Wconversion"