blob: fd93b2d8f75aafca1836deaa37d85ed03f960e1f [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
Prabir Pradhan48f8cb92021-08-26 14:05:36 -0700142std::pair<gui::DisplayInfo, ui::Transform> DisplayDevice::getInputInfo() const {
143 gui::DisplayInfo info;
144 info.displayId = getLayerStack().id;
145
146 // The physical orientation is set when the orientation of the display panel is
147 // different than the default orientation of the device. Other services like
148 // InputFlinger do not know about this, so we do not need to expose the physical
149 // orientation of the panel outside of SurfaceFlinger.
150 const ui::Rotation inversePhysicalOrientation = ui::ROTATION_0 - mPhysicalOrientation;
151 auto width = getWidth();
152 auto height = getHeight();
153 if (inversePhysicalOrientation == ui::ROTATION_90 ||
154 inversePhysicalOrientation == ui::ROTATION_270) {
155 std::swap(width, height);
156 }
157 const ui::Transform undoPhysicalOrientation(ui::Transform::toRotationFlags(
158 inversePhysicalOrientation),
159 width, height);
160 const auto& displayTransform = undoPhysicalOrientation * getTransform();
161 // Send the inverse display transform to input so it can convert display coordinates to
162 // logical display.
163 info.transform = displayTransform.inverse();
164
165 info.logicalWidth = getLayerStackSpaceRect().width();
166 info.logicalHeight = getLayerStackSpaceRect().height();
167 return {info, displayTransform};
168}
169
Mathias Agopian1b031492012-06-20 17:51:20 -0700170// ----------------------------------------------------------------------------
Peiyong Lin65248e02020-04-18 21:15:07 -0700171void DisplayDevice::setPowerMode(hal::PowerMode mode) {
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700172 mPowerMode = mode;
Peiyong Lin65248e02020-04-18 21:15:07 -0700173 getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700174}
175
Alec Mouri023c1882021-05-08 16:36:33 -0700176void DisplayDevice::enableLayerCaching(bool enable) {
177 getCompositionDisplay()->setLayerCachingEnabled(enable);
178}
179
Peiyong Lin65248e02020-04-18 21:15:07 -0700180hal::PowerMode DisplayDevice::getPowerMode() const {
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700181 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700182}
183
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700184bool DisplayDevice::isPoweredOn() const {
Peiyong Lin65248e02020-04-18 21:15:07 -0700185 return mPowerMode != hal::PowerMode::OFF;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700186}
187
Marin Shalamanov5801c942020-12-17 17:00:13 +0100188void DisplayDevice::setActiveMode(DisplayModeId id) {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100189 const auto mode = getMode(id);
190 LOG_FATAL_IF(!mode, "Cannot set active mode which is not supported.");
Ady Abraham690f4612021-07-01 23:24:03 -0700191 ATRACE_INT(mActiveModeFPSTrace.c_str(), mode->getFps().getIntValue());
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100192 mActiveMode = mode;
Ady Abraham3efa3942021-06-24 19:01:25 -0700193 if (mRefreshRateConfigs) {
194 mRefreshRateConfigs->setCurrentModeId(mActiveMode->getId());
195 }
Ady Abraham1b11bc62021-06-03 19:51:19 -0700196 if (mRefreshRateOverlay) {
197 mRefreshRateOverlay->changeRefreshRate(mActiveMode->getFps());
198 }
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700199}
200
Ady Abraham690f4612021-07-01 23:24:03 -0700201status_t DisplayDevice::initiateModeChange(const ActiveModeInfo& info,
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100202 const hal::VsyncPeriodChangeConstraints& constraints,
Ady Abraham690f4612021-07-01 23:24:03 -0700203 hal::VsyncPeriodChangeTimeline* outTimeline) {
204 if (!info.mode || info.mode->getPhysicalDisplayId() != getPhysicalId()) {
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100205 ALOGE("Trying to initiate a mode change to invalid mode %s on display %s",
Ady Abraham690f4612021-07-01 23:24:03 -0700206 info.mode ? std::to_string(info.mode->getId().value()).c_str() : "null",
207 to_string(getId()).c_str());
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100208 return BAD_VALUE;
209 }
Ady Abraham690f4612021-07-01 23:24:03 -0700210 mUpcomingActiveMode = info;
211 ATRACE_INT(mActiveModeFPSHwcTrace.c_str(), info.mode->getFps().getIntValue());
212 return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), info.mode->getHwcId(),
213 constraints, outTimeline);
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100214}
215
Marin Shalamanov5801c942020-12-17 17:00:13 +0100216const DisplayModePtr& DisplayDevice::getActiveMode() const {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100217 return mActiveMode;
Marin Shalamanov5801c942020-12-17 17:00:13 +0100218}
219
220const DisplayModes& DisplayDevice::getSupportedModes() const {
221 return mSupportedModes;
222}
223
224DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100225 const auto it = std::find_if(mSupportedModes.begin(), mSupportedModes.end(),
226 [&](DisplayModePtr mode) { return mode->getId() == modeId; });
227 if (it != mSupportedModes.end()) {
228 return *it;
Marin Shalamanov5801c942020-12-17 17:00:13 +0100229 }
230 return nullptr;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700231}
232
Marin Shalamanov045b7002021-01-07 16:56:24 +0100233nsecs_t DisplayDevice::getVsyncPeriodFromHWC() const {
234 const auto physicalId = getPhysicalId();
235 if (!mHwComposer.isConnected(physicalId)) {
236 return 0;
237 }
238
239 nsecs_t vsyncPeriod;
240 const auto status = mHwComposer.getDisplayVsyncPeriod(physicalId, &vsyncPeriod);
241 if (status == NO_ERROR) {
242 return vsyncPeriod;
243 }
244
245 return getActiveMode()->getFps().getPeriodNsecs();
246}
247
248nsecs_t DisplayDevice::getRefreshTimestamp() const {
249 const nsecs_t now = systemTime(CLOCK_MONOTONIC);
250 const auto vsyncPeriodNanos = getVsyncPeriodFromHWC();
251 return now - ((now - mLastHwVsync) % vsyncPeriodNanos);
252}
253
254void DisplayDevice::onVsync(nsecs_t timestamp) {
255 mLastHwVsync = timestamp;
256}
257
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800258ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700259 return mCompositionDisplay->getState().dataspace;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800260}
261
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800262void DisplayDevice::setLayerStack(ui::LayerStack stack) {
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700263 mCompositionDisplay->setLayerFilter({stack, isInternal()});
Ady Abraham1b11bc62021-06-03 19:51:19 -0700264 if (mRefreshRateOverlay) {
265 mRefreshRateOverlay->setLayerStack(stack);
266 }
Mathias Agopian28947d72012-08-08 18:51:15 -0700267}
268
Evan Rosky2239b372021-05-20 13:43:47 -0700269void DisplayDevice::setFlags(uint32_t flags) {
270 mFlags = flags;
271}
272
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800273void DisplayDevice::setDisplaySize(int width, int height) {
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200274 LOG_FATAL_IF(!isVirtual(), "Changing the display size is supported only for virtual displays.");
Ady Abraham1b11bc62021-06-03 19:51:19 -0700275 const auto size = ui::Size(width, height);
276 mCompositionDisplay->setDisplaySize(size);
277 if (mRefreshRateOverlay) {
278 mRefreshRateOverlay->setViewport(size);
279 }
Michael Lentine47e45402014-07-18 15:34:25 -0700280}
281
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200282void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpaceRect,
283 Rect orientedDisplaySpaceRect) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700284 mOrientation = orientation;
285
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200286 if (isPrimary()) {
287 sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation);
288 }
289
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200290 if (!orientedDisplaySpaceRect.isValid()) {
Marin Shalamanov4429cac2020-10-01 12:56:24 +0200291 // The destination frame can be invalid if it has never been set,
292 // in that case we assume the whole display size.
293 orientedDisplaySpaceRect = getCompositionDisplay()->getState().displaySpace.bounds;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800294 }
295
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200296 if (layerStackSpaceRect.isEmpty()) {
Marin Shalamanov4429cac2020-10-01 12:56:24 +0200297 // The layerStackSpaceRect can be invalid if it has never been set, in that case
298 // we assume the whole framebuffer size.
299 layerStackSpaceRect = getCompositionDisplay()->getState().framebufferSpace.bounds;
Marin Shalamanov8c23c4e2020-08-19 15:26:31 +0200300 if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200301 std::swap(layerStackSpaceRect.right, layerStackSpaceRect.bottom);
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800302 }
303 }
304
Marin Shalamanov8c23c4e2020-08-19 15:26:31 +0200305 // We need to take care of display rotation for globalTransform for case if the panel is not
306 // installed aligned with device orientation.
307 const auto transformOrientation = orientation + mPhysicalOrientation;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200308 getCompositionDisplay()->setProjection(transformOrientation, layerStackSpaceRect,
309 orientedDisplaySpaceRect);
Mathias Agopian1b031492012-06-20 17:51:20 -0700310}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700311
Dominik Laskowski718f9602019-11-09 20:01:35 -0800312ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() {
313 return sPrimaryDisplayRotationFlags;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700314}
315
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700316std::string DisplayDevice::getDebugName() const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800317 const char* type = "virtual";
318 if (mConnectionType) {
Ady Abraham7825c682021-05-17 15:12:14 -0700319 type = isInternal() ? "internal" : "external";
Dominik Laskowski55c85402020-01-21 16:25:47 -0800320 }
321
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200322 return base::StringPrintf("DisplayDevice{%s, %s%s, \"%s\"}", to_string(getId()).c_str(), type,
Dominik Laskowski55c85402020-01-21 16:25:47 -0800323 isPrimary() ? ", primary" : "", mDisplayName.c_str());
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700324}
325
Yiwei Zhang5434a782018-12-05 18:06:32 -0800326void DisplayDevice::dump(std::string& result) const {
Yiwei Zhang5434a782018-12-05 18:06:32 -0800327 StringAppendF(&result, "+ %s\n", getDebugName().c_str());
Marin Shalamanov5801c942020-12-17 17:00:13 +0100328 StringAppendF(&result, " powerMode=%s (%d)\n", to_string(mPowerMode).c_str(),
Peiyong Lin65248e02020-04-18 21:15:07 -0700329 static_cast<int32_t>(mPowerMode));
Marin Shalamanov84b85482021-05-05 13:54:35 +0200330 const auto activeMode = getActiveMode();
Alec Mouri934e0cf2021-02-09 14:54:10 -0800331 StringAppendF(&result, " activeMode=%s\n",
Marin Shalamanov84b85482021-05-05 13:54:35 +0200332 activeMode ? to_string(*activeMode).c_str() : "none");
Marin Shalamanov5801c942020-12-17 17:00:13 +0100333
334 result.append(" supportedModes=\n");
335
336 for (const auto& mode : mSupportedModes) {
337 result.append(" ");
338 result.append(to_string(*mode));
339 result.append("\n");
340 }
341 StringAppendF(&result, " deviceProductInfo=");
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200342 if (mDeviceProductInfo) {
343 mDeviceProductInfo->dump(result);
344 } else {
345 result.append("{}");
346 }
Marin Shalamanov5801c942020-12-17 17:00:13 +0100347 result.append("\n");
Lloyd Pique32cbe282018-10-19 13:09:22 -0700348 getCompositionDisplay()->dump(result);
Ady Abraham3efa3942021-06-24 19:01:25 -0700349
350 if (mRefreshRateConfigs) {
351 mRefreshRateConfigs->dump(result);
352 }
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700353}
Irvelffc9efc2016-07-27 15:16:37 -0700354
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700355bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const {
356 return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent);
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700357}
358
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200359DisplayId DisplayDevice::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700360 return mCompositionDisplay->getId();
361}
362
363bool DisplayDevice::isSecure() const {
364 return mCompositionDisplay->isSecure();
365}
366
Lloyd Pique32cbe282018-10-19 13:09:22 -0700367const Rect& DisplayDevice::getBounds() const {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200368 return mCompositionDisplay->getState().displaySpace.bounds;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700369}
370
371const Region& DisplayDevice::getUndefinedRegion() const {
372 return mCompositionDisplay->getState().undefinedRegion;
373}
374
375bool DisplayDevice::needsFiltering() const {
376 return mCompositionDisplay->getState().needsFiltering;
377}
378
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800379ui::LayerStack DisplayDevice::getLayerStack() const {
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700380 return mCompositionDisplay->getState().layerFilter.layerStack;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700381}
382
Garfield Tan54edd912020-10-21 16:31:41 -0700383ui::Transform::RotationFlags DisplayDevice::getTransformHint() const {
384 return mCompositionDisplay->getTransformHint();
385}
386
Lloyd Pique32cbe282018-10-19 13:09:22 -0700387const ui::Transform& DisplayDevice::getTransform() const {
388 return mCompositionDisplay->getState().transform;
389}
390
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200391const Rect& DisplayDevice::getLayerStackSpaceRect() const {
392 return mCompositionDisplay->getState().layerStackSpace.content;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700393}
394
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200395const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const {
396 return mCompositionDisplay->getState().orientedDisplaySpace.content;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700397}
398
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700399bool DisplayDevice::hasWideColorGamut() const {
400 return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut();
401}
402
403bool DisplayDevice::hasHDR10PlusSupport() const {
404 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport();
405}
406
407bool DisplayDevice::hasHDR10Support() const {
408 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support();
409}
410
411bool DisplayDevice::hasHLGSupport() const {
412 return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport();
413}
414
415bool DisplayDevice::hasDolbyVisionSupport() const {
416 return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport();
417}
418
419int DisplayDevice::getSupportedPerFrameMetadata() const {
420 return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata();
421}
422
Kriti Dang49ad4132021-01-08 11:49:56 +0100423void DisplayDevice::overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes) {
424 mOverrideHdrTypes = hdrTypes;
425}
426
427HdrCapabilities DisplayDevice::getHdrCapabilities() const {
428 const HdrCapabilities& capabilities =
429 mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities();
430 std::vector<ui::Hdr> hdrTypes = capabilities.getSupportedHdrTypes();
431 if (!mOverrideHdrTypes.empty()) {
432 hdrTypes = mOverrideHdrTypes;
433 }
434 return HdrCapabilities(hdrTypes, capabilities.getDesiredMaxLuminance(),
435 capabilities.getDesiredMaxAverageLuminance(),
436 capabilities.getDesiredMinLuminance());
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700437}
438
Ady Abraham1b11bc62021-06-03 19:51:19 -0700439void DisplayDevice::enableRefreshRateOverlay(bool enable, bool showSpinnner) {
440 if (!enable) {
441 mRefreshRateOverlay.reset();
442 return;
443 }
444
445 const auto [lowFps, highFps] = mRefreshRateConfigs->getSupportedRefreshRateRange();
446 mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(*mFlinger, lowFps.getIntValue(),
447 highFps.getIntValue(), showSpinnner);
448 mRefreshRateOverlay->setLayerStack(getLayerStack());
449 mRefreshRateOverlay->setViewport(getSize());
450 mRefreshRateOverlay->changeRefreshRate(getActiveMode()->getFps());
451}
452
453bool DisplayDevice::onKernelTimerChanged(std::optional<DisplayModeId> desiredModeId,
454 bool timerExpired) {
455 if (mRefreshRateConfigs && mRefreshRateOverlay) {
456 const auto newRefreshRate =
457 mRefreshRateConfigs->onKernelTimerChanged(desiredModeId, timerExpired);
458 if (newRefreshRate) {
459 mRefreshRateOverlay->changeRefreshRate(*newRefreshRate);
460 return true;
461 }
462 }
463
464 return false;
465}
466
467void DisplayDevice::onInvalidate() {
468 if (mRefreshRateOverlay) {
469 mRefreshRateOverlay->onInvalidate();
470 }
471}
472
Ady Abraham690f4612021-07-01 23:24:03 -0700473bool DisplayDevice::setDesiredActiveMode(const ActiveModeInfo& info) {
474 ATRACE_CALL();
475
476 LOG_ALWAYS_FATAL_IF(!info.mode, "desired mode not provided");
477 LOG_ALWAYS_FATAL_IF(getPhysicalId() != info.mode->getPhysicalDisplayId(), "DisplayId mismatch");
478
479 ALOGV("%s(%s)", __func__, to_string(*info.mode).c_str());
480
481 std::scoped_lock lock(mActiveModeLock);
482 if (mDesiredActiveModeChanged) {
483 // If a mode change is pending, just cache the latest request in mDesiredActiveMode
484 const Scheduler::ModeEvent prevConfig = mDesiredActiveMode.event;
485 mDesiredActiveMode = info;
486 mDesiredActiveMode.event = mDesiredActiveMode.event | prevConfig;
487 return false;
488 }
489
490 // Check if we are already at the desired mode
491 if (getActiveMode()->getId() == info.mode->getId()) {
492 return false;
493 }
494
495 // Initiate a mode change.
496 mDesiredActiveModeChanged = true;
497 mDesiredActiveMode = info;
498 return true;
499}
500
501std::optional<DisplayDevice::ActiveModeInfo> DisplayDevice::getDesiredActiveMode() const {
502 std::scoped_lock lock(mActiveModeLock);
503 if (mDesiredActiveModeChanged) return mDesiredActiveMode;
504 return std::nullopt;
505}
506
507void DisplayDevice::clearDesiredActiveModeState() {
508 std::scoped_lock lock(mActiveModeLock);
509 mDesiredActiveMode.event = Scheduler::ModeEvent::None;
510 mDesiredActiveModeChanged = false;
511}
512
Dominik Laskowski663bd282018-04-19 15:26:54 -0700513std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1);
Peiyong Linfd997e02018-03-28 15:29:00 -0700514
515} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800516
517// TODO(b/129481165): remove the #pragma below and fix conversion issues
518#pragma clang diagnostic pop // ignored "-Wconversion"