blob: 60f2408ada54f235662ece18a227afd22556f4a1 [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
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -070025#include <android-base/stringprintf.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070026#include <compositionengine/CompositionEngine.h>
27#include <compositionengine/Display.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070028#include <compositionengine/DisplayColorProfile.h>
29#include <compositionengine/DisplayColorProfileCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070030#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique542307f2018-10-19 13:24:08 -070031#include <compositionengine/DisplaySurface.h>
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020032#include <compositionengine/ProjectionSpace.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070033#include <compositionengine/RenderSurface.h>
34#include <compositionengine/RenderSurfaceCreationArgs.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070035#include <compositionengine/impl/OutputCompositionState.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070036#include <configstore/Utils.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070037#include <log/log.h>
Alec Mouri0a9c7b82018-11-16 13:05:25 -080038#include <system/window.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070039#include <ui/GraphicTypes.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070041#include "DisplayDevice.h"
Mathias Agopian13127d82013-03-05 17:47:11 -080042#include "Layer.h"
Ady Abraham1b11bc62021-06-03 19:51:19 -070043#include "RefreshRateOverlay.h"
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070044#include "SurfaceFlinger.h"
Mathias Agopian1f7bec62010-06-25 18:02:21 -070045
Peiyong Linfd997e02018-03-28 15:29:00 -070046namespace android {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047
Peiyong Lin65248e02020-04-18 21:15:07 -070048namespace hal = hardware::graphics::composer::hal;
49
Yiwei Zhang5434a782018-12-05 18:06:32 -080050using android::base::StringAppendF;
Jaesoo Lee720a7242017-01-31 15:26:18 +090051
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),
Dominik Laskowski55c85402020-01-21 16:25:47 -080067 mConnectionType(args.connectionType),
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070068 mCompositionDisplay{args.compositionDisplay},
Dominik Laskowski718f9602019-11-09 20:01:35 -080069 mPhysicalOrientation(args.physicalOrientation),
Marin Shalamanov5801c942020-12-17 17:00:13 +010070 mSupportedModes(std::move(args.supportedModes)),
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
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070090 mCompositionDisplay->createDisplayColorProfile(
91 compositionengine::DisplayColorProfileCreationArgs{args.hasWideColorGamut,
92 std::move(args.hdrCapabilities),
93 args.supportedPerFrameMetadata,
94 args.hwcColorModes});
95
Lloyd Pique32cbe282018-10-19 13:09:22 -070096 if (!mCompositionDisplay->isValid()) {
97 ALOGE("Composition Display did not validate!");
98 }
99
Lloyd Pique31cb2942018-10-19 17:23:03 -0700100 mCompositionDisplay->getRenderSurface()->initialize();
Lloyd Pique2eef1d22018-09-18 21:30:04 -0700101
Lloyd Pique32cbe282018-10-19 13:09:22 -0700102 setPowerMode(args.initialPowerMode);
Alec Mouriba013fa2018-10-16 12:43:11 -0700103
Jesse Hallffe1f192013-03-22 15:13:48 -0700104 // initialize the display orientation transform.
Dominik Laskowski718f9602019-11-09 20:01:35 -0800105 setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106}
107
Lloyd Pique09594832018-01-22 17:48:03 -0800108DisplayDevice::~DisplayDevice() = default;
Mathias Agopian92a979a2012-08-02 18:32:23 -0700109
Lloyd Pique45a165a2018-10-19 11:54:47 -0700110void DisplayDevice::disconnect() {
111 mCompositionDisplay->disconnect();
Jesse Hall02d86562013-03-25 14:43:23 -0700112}
113
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700114int DisplayDevice::getWidth() const {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200115 return mCompositionDisplay->getState().displaySpace.bounds.getWidth();
Mathias Agopiana4912602012-07-12 14:25:33 -0700116}
117
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700118int DisplayDevice::getHeight() const {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200119 return mCompositionDisplay->getState().displaySpace.bounds.getHeight();
Mathias Agopiana4912602012-07-12 14:25:33 -0700120}
121
Dominik Laskowskibf170d92018-04-19 15:08:05 -0700122void DisplayDevice::setDisplayName(const std::string& displayName) {
123 if (!displayName.empty()) {
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700124 // never override the name with an empty name
125 mDisplayName = displayName;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700126 mCompositionDisplay->setName(displayName);
Mathias Agopian9e2463e2012-09-21 18:26:16 -0700127 }
128}
129
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200130void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info) {
131 mDeviceProductInfo = std::move(info);
132}
133
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -0700134uint32_t DisplayDevice::getPageFlipCount() const {
Lloyd Pique31cb2942018-10-19 17:23:03 -0700135 return mCompositionDisplay->getRenderSurface()->getPageFlipCount();
Dan Stoza9e56aa02015-11-02 13:00:03 -0800136}
Dan Stoza9e56aa02015-11-02 13:00:03 -0800137
Mathias Agopian1b031492012-06-20 17:51:20 -0700138// ----------------------------------------------------------------------------
Peiyong Lin65248e02020-04-18 21:15:07 -0700139void DisplayDevice::setPowerMode(hal::PowerMode mode) {
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700140 mPowerMode = mode;
Peiyong Lin65248e02020-04-18 21:15:07 -0700141 getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF);
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700142}
143
Alec Mouri023c1882021-05-08 16:36:33 -0700144void DisplayDevice::enableLayerCaching(bool enable) {
145 getCompositionDisplay()->setLayerCachingEnabled(enable);
146}
147
Peiyong Lin65248e02020-04-18 21:15:07 -0700148hal::PowerMode DisplayDevice::getPowerMode() const {
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700149 return mPowerMode;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700150}
151
Dominik Laskowskieecd6592018-05-29 10:25:41 -0700152bool DisplayDevice::isPoweredOn() const {
Peiyong Lin65248e02020-04-18 21:15:07 -0700153 return mPowerMode != hal::PowerMode::OFF;
Mathias Agopiand3ee2312012-08-02 14:01:42 -0700154}
155
Marin Shalamanov5801c942020-12-17 17:00:13 +0100156void DisplayDevice::setActiveMode(DisplayModeId id) {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100157 const auto mode = getMode(id);
158 LOG_FATAL_IF(!mode, "Cannot set active mode which is not supported.");
159 mActiveMode = mode;
Ady Abraham3efa3942021-06-24 19:01:25 -0700160 if (mRefreshRateConfigs) {
161 mRefreshRateConfigs->setCurrentModeId(mActiveMode->getId());
162 }
Ady Abraham1b11bc62021-06-03 19:51:19 -0700163 if (mRefreshRateOverlay) {
164 mRefreshRateOverlay->changeRefreshRate(mActiveMode->getFps());
165 }
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700166}
167
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +0100168status_t DisplayDevice::initiateModeChange(DisplayModeId modeId,
169 const hal::VsyncPeriodChangeConstraints& constraints,
170 hal::VsyncPeriodChangeTimeline* outTimeline) const {
171 const auto mode = getMode(modeId);
172 if (!mode) {
173 ALOGE("Trying to initiate a mode change to invalid mode %s on display %s",
174 std::to_string(modeId.value()).c_str(), to_string(getId()).c_str());
175 return BAD_VALUE;
176 }
177 return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), mode->getHwcId(), constraints,
178 outTimeline);
179}
180
Marin Shalamanov5801c942020-12-17 17:00:13 +0100181const DisplayModePtr& DisplayDevice::getActiveMode() const {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100182 return mActiveMode;
Marin Shalamanov5801c942020-12-17 17:00:13 +0100183}
184
185const DisplayModes& DisplayDevice::getSupportedModes() const {
186 return mSupportedModes;
187}
188
189DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const {
Marin Shalamanovf22e6ac2021-02-10 20:45:15 +0100190 const auto it = std::find_if(mSupportedModes.begin(), mSupportedModes.end(),
191 [&](DisplayModePtr mode) { return mode->getId() == modeId; });
192 if (it != mSupportedModes.end()) {
193 return *it;
Marin Shalamanov5801c942020-12-17 17:00:13 +0100194 }
195 return nullptr;
Michael Lentine6c9e34a2014-07-14 13:48:55 -0700196}
197
Marin Shalamanov045b7002021-01-07 16:56:24 +0100198nsecs_t DisplayDevice::getVsyncPeriodFromHWC() const {
199 const auto physicalId = getPhysicalId();
200 if (!mHwComposer.isConnected(physicalId)) {
201 return 0;
202 }
203
204 nsecs_t vsyncPeriod;
205 const auto status = mHwComposer.getDisplayVsyncPeriod(physicalId, &vsyncPeriod);
206 if (status == NO_ERROR) {
207 return vsyncPeriod;
208 }
209
210 return getActiveMode()->getFps().getPeriodNsecs();
211}
212
213nsecs_t DisplayDevice::getRefreshTimestamp() const {
214 const nsecs_t now = systemTime(CLOCK_MONOTONIC);
215 const auto vsyncPeriodNanos = getVsyncPeriodFromHWC();
216 return now - ((now - mLastHwVsync) % vsyncPeriodNanos);
217}
218
219void DisplayDevice::onVsync(nsecs_t timestamp) {
220 mLastHwVsync = timestamp;
221}
222
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800223ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700224 return mCompositionDisplay->getState().dataspace;
Peiyong Lindd9b2ae2018-03-01 16:22:45 -0800225}
226
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800227void DisplayDevice::setLayerStack(ui::LayerStack stack) {
Ady Abraham7825c682021-05-17 15:12:14 -0700228 mCompositionDisplay->setLayerStackFilter(stack, isInternal());
Ady Abraham1b11bc62021-06-03 19:51:19 -0700229 if (mRefreshRateOverlay) {
230 mRefreshRateOverlay->setLayerStack(stack);
231 }
Mathias Agopian28947d72012-08-08 18:51:15 -0700232}
233
Evan Rosky2239b372021-05-20 13:43:47 -0700234void DisplayDevice::setFlags(uint32_t flags) {
235 mFlags = flags;
236}
237
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800238void DisplayDevice::setDisplaySize(int width, int height) {
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200239 LOG_FATAL_IF(!isVirtual(), "Changing the display size is supported only for virtual displays.");
Ady Abraham1b11bc62021-06-03 19:51:19 -0700240 const auto size = ui::Size(width, height);
241 mCompositionDisplay->setDisplaySize(size);
242 if (mRefreshRateOverlay) {
243 mRefreshRateOverlay->setViewport(size);
244 }
Michael Lentine47e45402014-07-18 15:34:25 -0700245}
246
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200247void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpaceRect,
248 Rect orientedDisplaySpaceRect) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700249 mOrientation = orientation;
250
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200251 if (isPrimary()) {
252 sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation);
253 }
254
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200255 if (!orientedDisplaySpaceRect.isValid()) {
Marin Shalamanov4429cac2020-10-01 12:56:24 +0200256 // The destination frame can be invalid if it has never been set,
257 // in that case we assume the whole display size.
258 orientedDisplaySpaceRect = getCompositionDisplay()->getState().displaySpace.bounds;
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800259 }
260
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200261 if (layerStackSpaceRect.isEmpty()) {
Marin Shalamanov4429cac2020-10-01 12:56:24 +0200262 // The layerStackSpaceRect can be invalid if it has never been set, in that case
263 // we assume the whole framebuffer size.
264 layerStackSpaceRect = getCompositionDisplay()->getState().framebufferSpace.bounds;
Marin Shalamanov8c23c4e2020-08-19 15:26:31 +0200265 if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200266 std::swap(layerStackSpaceRect.right, layerStackSpaceRect.bottom);
Mathias Agopianf5f714a2013-02-26 16:54:05 -0800267 }
268 }
269
Marin Shalamanov8c23c4e2020-08-19 15:26:31 +0200270 // We need to take care of display rotation for globalTransform for case if the panel is not
271 // installed aligned with device orientation.
272 const auto transformOrientation = orientation + mPhysicalOrientation;
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200273 getCompositionDisplay()->setProjection(transformOrientation, layerStackSpaceRect,
274 orientedDisplaySpaceRect);
Mathias Agopian1b031492012-06-20 17:51:20 -0700275}
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700276
Dominik Laskowski718f9602019-11-09 20:01:35 -0800277ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() {
278 return sPrimaryDisplayRotationFlags;
Pablo Ceballos021623b2016-04-15 17:31:51 -0700279}
280
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700281std::string DisplayDevice::getDebugName() const {
Dominik Laskowski55c85402020-01-21 16:25:47 -0800282 const char* type = "virtual";
283 if (mConnectionType) {
Ady Abraham7825c682021-05-17 15:12:14 -0700284 type = isInternal() ? "internal" : "external";
Dominik Laskowski55c85402020-01-21 16:25:47 -0800285 }
286
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200287 return base::StringPrintf("DisplayDevice{%s, %s%s, \"%s\"}", to_string(getId()).c_str(), type,
Dominik Laskowski55c85402020-01-21 16:25:47 -0800288 isPrimary() ? ", primary" : "", mDisplayName.c_str());
Dominik Laskowski9b17b2c22018-11-01 14:49:03 -0700289}
290
Yiwei Zhang5434a782018-12-05 18:06:32 -0800291void DisplayDevice::dump(std::string& result) const {
Yiwei Zhang5434a782018-12-05 18:06:32 -0800292 StringAppendF(&result, "+ %s\n", getDebugName().c_str());
Marin Shalamanov5801c942020-12-17 17:00:13 +0100293 StringAppendF(&result, " powerMode=%s (%d)\n", to_string(mPowerMode).c_str(),
Peiyong Lin65248e02020-04-18 21:15:07 -0700294 static_cast<int32_t>(mPowerMode));
Marin Shalamanov84b85482021-05-05 13:54:35 +0200295 const auto activeMode = getActiveMode();
Alec Mouri934e0cf2021-02-09 14:54:10 -0800296 StringAppendF(&result, " activeMode=%s\n",
Marin Shalamanov84b85482021-05-05 13:54:35 +0200297 activeMode ? to_string(*activeMode).c_str() : "none");
Marin Shalamanov5801c942020-12-17 17:00:13 +0100298
299 result.append(" supportedModes=\n");
300
301 for (const auto& mode : mSupportedModes) {
302 result.append(" ");
303 result.append(to_string(*mode));
304 result.append("\n");
305 }
306 StringAppendF(&result, " deviceProductInfo=");
Marin Shalamanove5cceea2020-04-30 18:13:10 +0200307 if (mDeviceProductInfo) {
308 mDeviceProductInfo->dump(result);
309 } else {
310 result.append("{}");
311 }
Marin Shalamanov5801c942020-12-17 17:00:13 +0100312 result.append("\n");
Lloyd Pique32cbe282018-10-19 13:09:22 -0700313 getCompositionDisplay()->dump(result);
Ady Abraham3efa3942021-06-24 19:01:25 -0700314
315 if (mRefreshRateConfigs) {
316 mRefreshRateConfigs->dump(result);
317 }
Mathias Agopian1d12d8a2012-09-18 01:38:00 -0700318}
Irvelffc9efc2016-07-27 15:16:37 -0700319
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700320bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const {
321 return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent);
Peiyong Lin136fbbc2018-04-17 15:09:44 -0700322}
323
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200324DisplayId DisplayDevice::getId() const {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700325 return mCompositionDisplay->getId();
326}
327
328bool DisplayDevice::isSecure() const {
329 return mCompositionDisplay->isSecure();
330}
331
Lloyd Pique32cbe282018-10-19 13:09:22 -0700332const Rect& DisplayDevice::getBounds() const {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200333 return mCompositionDisplay->getState().displaySpace.bounds;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700334}
335
336const Region& DisplayDevice::getUndefinedRegion() const {
337 return mCompositionDisplay->getState().undefinedRegion;
338}
339
340bool DisplayDevice::needsFiltering() const {
341 return mCompositionDisplay->getState().needsFiltering;
342}
343
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800344ui::LayerStack DisplayDevice::getLayerStack() const {
Lloyd Piqueef36b002019-01-23 17:52:04 -0800345 return mCompositionDisplay->getState().layerStackId;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700346}
347
Garfield Tan54edd912020-10-21 16:31:41 -0700348ui::Transform::RotationFlags DisplayDevice::getTransformHint() const {
349 return mCompositionDisplay->getTransformHint();
350}
351
Lloyd Pique32cbe282018-10-19 13:09:22 -0700352const ui::Transform& DisplayDevice::getTransform() const {
353 return mCompositionDisplay->getState().transform;
354}
355
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200356const Rect& DisplayDevice::getLayerStackSpaceRect() const {
357 return mCompositionDisplay->getState().layerStackSpace.content;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700358}
359
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200360const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const {
361 return mCompositionDisplay->getState().orientedDisplaySpace.content;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700362}
363
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700364bool DisplayDevice::hasWideColorGamut() const {
365 return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut();
366}
367
368bool DisplayDevice::hasHDR10PlusSupport() const {
369 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport();
370}
371
372bool DisplayDevice::hasHDR10Support() const {
373 return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support();
374}
375
376bool DisplayDevice::hasHLGSupport() const {
377 return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport();
378}
379
380bool DisplayDevice::hasDolbyVisionSupport() const {
381 return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport();
382}
383
384int DisplayDevice::getSupportedPerFrameMetadata() const {
385 return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata();
386}
387
Kriti Dang49ad4132021-01-08 11:49:56 +0100388void DisplayDevice::overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes) {
389 mOverrideHdrTypes = hdrTypes;
390}
391
392HdrCapabilities DisplayDevice::getHdrCapabilities() const {
393 const HdrCapabilities& capabilities =
394 mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities();
395 std::vector<ui::Hdr> hdrTypes = capabilities.getSupportedHdrTypes();
396 if (!mOverrideHdrTypes.empty()) {
397 hdrTypes = mOverrideHdrTypes;
398 }
399 return HdrCapabilities(hdrTypes, capabilities.getDesiredMaxLuminance(),
400 capabilities.getDesiredMaxAverageLuminance(),
401 capabilities.getDesiredMinLuminance());
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700402}
403
Ady Abraham1b11bc62021-06-03 19:51:19 -0700404void DisplayDevice::enableRefreshRateOverlay(bool enable, bool showSpinnner) {
405 if (!enable) {
406 mRefreshRateOverlay.reset();
407 return;
408 }
409
410 const auto [lowFps, highFps] = mRefreshRateConfigs->getSupportedRefreshRateRange();
411 mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(*mFlinger, lowFps.getIntValue(),
412 highFps.getIntValue(), showSpinnner);
413 mRefreshRateOverlay->setLayerStack(getLayerStack());
414 mRefreshRateOverlay->setViewport(getSize());
415 mRefreshRateOverlay->changeRefreshRate(getActiveMode()->getFps());
416}
417
418bool DisplayDevice::onKernelTimerChanged(std::optional<DisplayModeId> desiredModeId,
419 bool timerExpired) {
420 if (mRefreshRateConfigs && mRefreshRateOverlay) {
421 const auto newRefreshRate =
422 mRefreshRateConfigs->onKernelTimerChanged(desiredModeId, timerExpired);
423 if (newRefreshRate) {
424 mRefreshRateOverlay->changeRefreshRate(*newRefreshRate);
425 return true;
426 }
427 }
428
429 return false;
430}
431
432void DisplayDevice::onInvalidate() {
433 if (mRefreshRateOverlay) {
434 mRefreshRateOverlay->onInvalidate();
435 }
436}
437
Dominik Laskowski663bd282018-04-19 15:26:54 -0700438std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1);
Peiyong Linfd997e02018-03-28 15:29:00 -0700439
440} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800441
442// TODO(b/129481165): remove the #pragma below and fix conversion issues
443#pragma clang diagnostic pop // ignored "-Wconversion"