• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 // TODO(b/129481165): remove the #pragma below and fix conversion issues
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wconversion"
20 
21 // #define LOG_NDEBUG 0
22 #undef LOG_TAG
23 #define LOG_TAG "DisplayDevice"
24 
25 #define ATRACE_TAG ATRACE_TAG_GRAPHICS
26 
27 #include <compositionengine/CompositionEngine.h>
28 #include <compositionengine/Display.h>
29 #include <compositionengine/DisplayColorProfile.h>
30 #include <compositionengine/DisplayColorProfileCreationArgs.h>
31 #include <compositionengine/DisplayCreationArgs.h>
32 #include <compositionengine/DisplaySurface.h>
33 #include <compositionengine/ProjectionSpace.h>
34 #include <compositionengine/RenderSurface.h>
35 #include <compositionengine/RenderSurfaceCreationArgs.h>
36 #include <compositionengine/impl/OutputCompositionState.h>
37 #include <configstore/Utils.h>
38 #include <log/log.h>
39 #include <system/window.h>
40 #include <ui/GraphicTypes.h>
41 
42 #include "DisplayDevice.h"
43 #include "Layer.h"
44 #include "RefreshRateOverlay.h"
45 #include "SurfaceFlinger.h"
46 
47 namespace android {
48 
49 namespace hal = hardware::graphics::composer::hal;
50 
51 ui::Transform::RotationFlags DisplayDevice::sPrimaryDisplayRotationFlags = ui::Transform::ROT_0;
52 
DisplayDeviceCreationArgs(const sp<SurfaceFlinger> & flinger,HWComposer & hwComposer,const wp<IBinder> & displayToken,std::shared_ptr<compositionengine::Display> compositionDisplay)53 DisplayDeviceCreationArgs::DisplayDeviceCreationArgs(
54         const sp<SurfaceFlinger>& flinger, HWComposer& hwComposer, const wp<IBinder>& displayToken,
55         std::shared_ptr<compositionengine::Display> compositionDisplay)
56       : flinger(flinger),
57         hwComposer(hwComposer),
58         displayToken(displayToken),
59         compositionDisplay(compositionDisplay) {}
60 
DisplayDevice(DisplayDeviceCreationArgs & args)61 DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args)
62       : mFlinger(args.flinger),
63         mHwComposer(args.hwComposer),
64         mDisplayToken(args.displayToken),
65         mSequenceId(args.sequenceId),
66         mConnectionType(args.connectionType),
67         mCompositionDisplay{args.compositionDisplay},
68         mActiveModeFPSTrace("ActiveModeFPS -" + to_string(getId())),
69         mActiveModeFPSHwcTrace("ActiveModeFPS_HWC -" + to_string(getId())),
70         mPhysicalOrientation(args.physicalOrientation),
71         mSupportedModes(std::move(args.supportedModes)),
72         mIsPrimary(args.isPrimary),
73         mRefreshRateConfigs(std::move(args.refreshRateConfigs)) {
74     mCompositionDisplay->editState().isSecure = args.isSecure;
75     mCompositionDisplay->createRenderSurface(
76             compositionengine::RenderSurfaceCreationArgsBuilder()
77                     .setDisplayWidth(ANativeWindow_getWidth(args.nativeWindow.get()))
78                     .setDisplayHeight(ANativeWindow_getHeight(args.nativeWindow.get()))
79                     .setNativeWindow(std::move(args.nativeWindow))
80                     .setDisplaySurface(std::move(args.displaySurface))
81                     .setMaxTextureCacheSize(
82                             static_cast<size_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers))
83                     .build());
84 
85     if (!mFlinger->mDisableClientCompositionCache &&
86         SurfaceFlinger::maxFrameBufferAcquiredBuffers > 0) {
87         mCompositionDisplay->createClientCompositionCache(
88                 static_cast<uint32_t>(SurfaceFlinger::maxFrameBufferAcquiredBuffers));
89     }
90 
91     mCompositionDisplay->setPredictCompositionStrategy(mFlinger->mPredictCompositionStrategy);
92     mCompositionDisplay->setTreat170mAsSrgb(mFlinger->mTreat170mAsSrgb);
93     mCompositionDisplay->createDisplayColorProfile(
94             compositionengine::DisplayColorProfileCreationArgsBuilder()
95                     .setHasWideColorGamut(args.hasWideColorGamut)
96                     .setHdrCapabilities(std::move(args.hdrCapabilities))
97                     .setSupportedPerFrameMetadata(args.supportedPerFrameMetadata)
98                     .setHwcColorModes(std::move(args.hwcColorModes))
99                     .Build());
100 
101     if (!mCompositionDisplay->isValid()) {
102         ALOGE("Composition Display did not validate!");
103     }
104 
105     mCompositionDisplay->getRenderSurface()->initialize();
106 
107     if (args.initialPowerMode.has_value()) setPowerMode(args.initialPowerMode.value());
108 
109     // initialize the display orientation transform.
110     setProjection(ui::ROTATION_0, Rect::INVALID_RECT, Rect::INVALID_RECT);
111 }
112 
113 DisplayDevice::~DisplayDevice() = default;
114 
disconnect()115 void DisplayDevice::disconnect() {
116     mCompositionDisplay->disconnect();
117 }
118 
getWidth() const119 int DisplayDevice::getWidth() const {
120     return mCompositionDisplay->getState().displaySpace.getBounds().width;
121 }
122 
getHeight() const123 int DisplayDevice::getHeight() const {
124     return mCompositionDisplay->getState().displaySpace.getBounds().height;
125 }
126 
setDisplayName(const std::string & displayName)127 void DisplayDevice::setDisplayName(const std::string& displayName) {
128     if (!displayName.empty()) {
129         // never override the name with an empty name
130         mDisplayName = displayName;
131         mCompositionDisplay->setName(displayName);
132     }
133 }
134 
setDeviceProductInfo(std::optional<DeviceProductInfo> info)135 void DisplayDevice::setDeviceProductInfo(std::optional<DeviceProductInfo> info) {
136     mDeviceProductInfo = std::move(info);
137 }
138 
getPageFlipCount() const139 uint32_t DisplayDevice::getPageFlipCount() const {
140     return mCompositionDisplay->getRenderSurface()->getPageFlipCount();
141 }
142 
getInputInfo() const143 auto DisplayDevice::getInputInfo() const -> InputInfo {
144     gui::DisplayInfo info;
145     info.displayId = getLayerStack().id;
146 
147     // The physical orientation is set when the orientation of the display panel is
148     // different than the default orientation of the device. Other services like
149     // InputFlinger do not know about this, so we do not need to expose the physical
150     // orientation of the panel outside of SurfaceFlinger.
151     const ui::Rotation inversePhysicalOrientation = ui::ROTATION_0 - mPhysicalOrientation;
152     auto width = getWidth();
153     auto height = getHeight();
154     if (inversePhysicalOrientation == ui::ROTATION_90 ||
155         inversePhysicalOrientation == ui::ROTATION_270) {
156         std::swap(width, height);
157     }
158     const ui::Transform undoPhysicalOrientation(ui::Transform::toRotationFlags(
159                                                         inversePhysicalOrientation),
160                                                 width, height);
161     const auto& displayTransform = undoPhysicalOrientation * getTransform();
162     // Send the inverse display transform to input so it can convert display coordinates to
163     // logical display.
164     info.transform = displayTransform.inverse();
165 
166     info.logicalWidth = getLayerStackSpaceRect().width();
167     info.logicalHeight = getLayerStackSpaceRect().height();
168 
169     return {.info = info,
170             .transform = displayTransform,
171             .receivesInput = receivesInput(),
172             .isSecure = isSecure()};
173 }
174 
setPowerMode(hal::PowerMode mode)175 void DisplayDevice::setPowerMode(hal::PowerMode mode) {
176     if (mode == hal::PowerMode::OFF || mode == hal::PowerMode::ON) {
177         if (mStagedBrightness && mBrightness != mStagedBrightness) {
178             getCompositionDisplay()->setNextBrightness(*mStagedBrightness);
179             mBrightness = *mStagedBrightness;
180         }
181         mStagedBrightness = std::nullopt;
182         getCompositionDisplay()->applyDisplayBrightness(true);
183     }
184 
185     mPowerMode = mode;
186 
187     getCompositionDisplay()->setCompositionEnabled(mPowerMode.has_value() &&
188                                                    *mPowerMode != hal::PowerMode::OFF);
189 }
190 
enableLayerCaching(bool enable)191 void DisplayDevice::enableLayerCaching(bool enable) {
192     getCompositionDisplay()->setLayerCachingEnabled(enable);
193 }
194 
getPowerMode() const195 std::optional<hal::PowerMode> DisplayDevice::getPowerMode() const {
196     return mPowerMode;
197 }
198 
isPoweredOn() const199 bool DisplayDevice::isPoweredOn() const {
200     return mPowerMode && *mPowerMode != hal::PowerMode::OFF;
201 }
202 
setActiveMode(DisplayModeId id)203 void DisplayDevice::setActiveMode(DisplayModeId id) {
204     const auto mode = getMode(id);
205     LOG_FATAL_IF(!mode, "Cannot set active mode which is not supported.");
206     ATRACE_INT(mActiveModeFPSTrace.c_str(), mode->getFps().getIntValue());
207     mActiveMode = mode;
208     if (mRefreshRateConfigs) {
209         mRefreshRateConfigs->setActiveModeId(mActiveMode->getId());
210     }
211     if (mRefreshRateOverlay) {
212         mRefreshRateOverlay->changeRefreshRate(mActiveMode->getFps());
213     }
214 }
215 
initiateModeChange(const ActiveModeInfo & info,const hal::VsyncPeriodChangeConstraints & constraints,hal::VsyncPeriodChangeTimeline * outTimeline)216 status_t DisplayDevice::initiateModeChange(const ActiveModeInfo& info,
217                                            const hal::VsyncPeriodChangeConstraints& constraints,
218                                            hal::VsyncPeriodChangeTimeline* outTimeline) {
219     if (!info.mode || info.mode->getPhysicalDisplayId() != getPhysicalId()) {
220         ALOGE("Trying to initiate a mode change to invalid mode %s on display %s",
221               info.mode ? std::to_string(info.mode->getId().value()).c_str() : "null",
222               to_string(getId()).c_str());
223         return BAD_VALUE;
224     }
225     mNumModeSwitchesInPolicy++;
226     mUpcomingActiveMode = info;
227     ATRACE_INT(mActiveModeFPSHwcTrace.c_str(), info.mode->getFps().getIntValue());
228     return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), info.mode->getHwcId(),
229                                                     constraints, outTimeline);
230 }
231 
getActiveMode() const232 const DisplayModePtr& DisplayDevice::getActiveMode() const {
233     return mActiveMode;
234 }
235 
getSupportedModes() const236 const DisplayModes& DisplayDevice::getSupportedModes() const {
237     return mSupportedModes;
238 }
239 
getMode(DisplayModeId modeId) const240 DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const {
241     const DisplayModePtr nullMode;
242     return mSupportedModes.get(modeId).value_or(std::cref(nullMode));
243 }
244 
translateModeId(hal::HWConfigId hwcId) const245 std::optional<DisplayModeId> DisplayDevice::translateModeId(hal::HWConfigId hwcId) const {
246     const auto it =
247             std::find_if(mSupportedModes.begin(), mSupportedModes.end(),
248                          [hwcId](const auto& pair) { return pair.second->getHwcId() == hwcId; });
249     if (it != mSupportedModes.end()) {
250         return it->second->getId();
251     }
252     return {};
253 }
254 
getVsyncPeriodFromHWC() const255 nsecs_t DisplayDevice::getVsyncPeriodFromHWC() const {
256     const auto physicalId = getPhysicalId();
257     if (!mHwComposer.isConnected(physicalId)) {
258         return 0;
259     }
260 
261     nsecs_t vsyncPeriod;
262     const auto status = mHwComposer.getDisplayVsyncPeriod(physicalId, &vsyncPeriod);
263     if (status == NO_ERROR) {
264         return vsyncPeriod;
265     }
266 
267     return getActiveMode()->getFps().getPeriodNsecs();
268 }
269 
getRefreshTimestamp() const270 nsecs_t DisplayDevice::getRefreshTimestamp() const {
271     const nsecs_t now = systemTime(CLOCK_MONOTONIC);
272     const auto vsyncPeriodNanos = getVsyncPeriodFromHWC();
273     return now - ((now - mLastHwVsync) % vsyncPeriodNanos);
274 }
275 
onVsync(nsecs_t timestamp)276 void DisplayDevice::onVsync(nsecs_t timestamp) {
277     mLastHwVsync = timestamp;
278 }
279 
getCompositionDataSpace() const280 ui::Dataspace DisplayDevice::getCompositionDataSpace() const {
281     return mCompositionDisplay->getState().dataspace;
282 }
283 
setLayerStack(ui::LayerStack stack)284 void DisplayDevice::setLayerStack(ui::LayerStack stack) {
285     mCompositionDisplay->setLayerFilter({stack, isInternal()});
286     if (mRefreshRateOverlay) {
287         mRefreshRateOverlay->setLayerStack(stack);
288     }
289 }
290 
setFlags(uint32_t flags)291 void DisplayDevice::setFlags(uint32_t flags) {
292     mFlags = flags;
293 }
294 
setDisplaySize(int width,int height)295 void DisplayDevice::setDisplaySize(int width, int height) {
296     LOG_FATAL_IF(!isVirtual(), "Changing the display size is supported only for virtual displays.");
297     const auto size = ui::Size(width, height);
298     mCompositionDisplay->setDisplaySize(size);
299     if (mRefreshRateOverlay) {
300         mRefreshRateOverlay->setViewport(size);
301     }
302 }
303 
setProjection(ui::Rotation orientation,Rect layerStackSpaceRect,Rect orientedDisplaySpaceRect)304 void DisplayDevice::setProjection(ui::Rotation orientation, Rect layerStackSpaceRect,
305                                   Rect orientedDisplaySpaceRect) {
306     mOrientation = orientation;
307 
308     if (isPrimary()) {
309         sPrimaryDisplayRotationFlags = ui::Transform::toRotationFlags(orientation);
310     }
311 
312     // We need to take care of display rotation for globalTransform for case if the panel is not
313     // installed aligned with device orientation.
314     const auto transformOrientation = orientation + mPhysicalOrientation;
315 
316     const auto& state = getCompositionDisplay()->getState();
317 
318     // If the layer stack and destination frames have never been set, then configure them to be the
319     // same as the physical device, taking into account the total transform.
320     if (!orientedDisplaySpaceRect.isValid()) {
321         ui::Size bounds = state.displaySpace.getBounds();
322         bounds.rotate(transformOrientation);
323         orientedDisplaySpaceRect = Rect(bounds);
324     }
325     if (layerStackSpaceRect.isEmpty()) {
326         ui::Size bounds = state.framebufferSpace.getBounds();
327         bounds.rotate(transformOrientation);
328         layerStackSpaceRect = Rect(bounds);
329     }
330     getCompositionDisplay()->setProjection(transformOrientation, layerStackSpaceRect,
331                                            orientedDisplaySpaceRect);
332 }
333 
stageBrightness(float brightness)334 void DisplayDevice::stageBrightness(float brightness) {
335     mStagedBrightness = brightness;
336 }
337 
persistBrightness(bool needsComposite)338 void DisplayDevice::persistBrightness(bool needsComposite) {
339     if (mStagedBrightness && mBrightness != mStagedBrightness) {
340         if (needsComposite) {
341             getCompositionDisplay()->setNextBrightness(*mStagedBrightness);
342         }
343         mBrightness = *mStagedBrightness;
344     }
345     mStagedBrightness = std::nullopt;
346 }
347 
getStagedBrightness() const348 std::optional<float> DisplayDevice::getStagedBrightness() const {
349     return mStagedBrightness;
350 }
351 
getPrimaryDisplayRotationFlags()352 ui::Transform::RotationFlags DisplayDevice::getPrimaryDisplayRotationFlags() {
353     return sPrimaryDisplayRotationFlags;
354 }
355 
getDebugName() const356 std::string DisplayDevice::getDebugName() const {
357     using namespace std::string_literals;
358 
359     std::string name = "Display "s + to_string(getId()) + " ("s;
360 
361     if (mConnectionType) {
362         name += isInternal() ? "internal"s : "external"s;
363     } else {
364         name += "virtual"s;
365     }
366 
367     if (isPrimary()) {
368         name += ", primary"s;
369     }
370 
371     return name + ", \""s + mDisplayName + "\")"s;
372 }
373 
dump(std::string & result) const374 void DisplayDevice::dump(std::string& result) const {
375     using namespace std::string_literals;
376 
377     result += getDebugName();
378 
379     if (!isVirtual()) {
380         result += "\n   deviceProductInfo="s;
381         if (mDeviceProductInfo) {
382             mDeviceProductInfo->dump(result);
383         } else {
384             result += "{}"s;
385         }
386     }
387 
388     result += "\n   powerMode="s;
389     result += mPowerMode.has_value() ? to_string(mPowerMode.value()) : "OFF(reset)";
390     result += '\n';
391 
392     if (mRefreshRateConfigs) {
393         mRefreshRateConfigs->dump(result);
394     }
395 }
396 
hasRenderIntent(ui::RenderIntent intent) const397 bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const {
398     return mCompositionDisplay->getDisplayColorProfile()->hasRenderIntent(intent);
399 }
400 
getId() const401 DisplayId DisplayDevice::getId() const {
402     return mCompositionDisplay->getId();
403 }
404 
isSecure() const405 bool DisplayDevice::isSecure() const {
406     return mCompositionDisplay->isSecure();
407 }
408 
getBounds() const409 const Rect DisplayDevice::getBounds() const {
410     return mCompositionDisplay->getState().displaySpace.getBoundsAsRect();
411 }
412 
getUndefinedRegion() const413 const Region& DisplayDevice::getUndefinedRegion() const {
414     return mCompositionDisplay->getState().undefinedRegion;
415 }
416 
needsFiltering() const417 bool DisplayDevice::needsFiltering() const {
418     return mCompositionDisplay->getState().needsFiltering;
419 }
420 
getLayerStack() const421 ui::LayerStack DisplayDevice::getLayerStack() const {
422     return mCompositionDisplay->getState().layerFilter.layerStack;
423 }
424 
getTransformHint() const425 ui::Transform::RotationFlags DisplayDevice::getTransformHint() const {
426     return mCompositionDisplay->getTransformHint();
427 }
428 
getTransform() const429 const ui::Transform& DisplayDevice::getTransform() const {
430     return mCompositionDisplay->getState().transform;
431 }
432 
getLayerStackSpaceRect() const433 const Rect& DisplayDevice::getLayerStackSpaceRect() const {
434     return mCompositionDisplay->getState().layerStackSpace.getContent();
435 }
436 
getOrientedDisplaySpaceRect() const437 const Rect& DisplayDevice::getOrientedDisplaySpaceRect() const {
438     return mCompositionDisplay->getState().orientedDisplaySpace.getContent();
439 }
440 
hasWideColorGamut() const441 bool DisplayDevice::hasWideColorGamut() const {
442     return mCompositionDisplay->getDisplayColorProfile()->hasWideColorGamut();
443 }
444 
hasHDR10PlusSupport() const445 bool DisplayDevice::hasHDR10PlusSupport() const {
446     return mCompositionDisplay->getDisplayColorProfile()->hasHDR10PlusSupport();
447 }
448 
hasHDR10Support() const449 bool DisplayDevice::hasHDR10Support() const {
450     return mCompositionDisplay->getDisplayColorProfile()->hasHDR10Support();
451 }
452 
hasHLGSupport() const453 bool DisplayDevice::hasHLGSupport() const {
454     return mCompositionDisplay->getDisplayColorProfile()->hasHLGSupport();
455 }
456 
hasDolbyVisionSupport() const457 bool DisplayDevice::hasDolbyVisionSupport() const {
458     return mCompositionDisplay->getDisplayColorProfile()->hasDolbyVisionSupport();
459 }
460 
getSupportedPerFrameMetadata() const461 int DisplayDevice::getSupportedPerFrameMetadata() const {
462     return mCompositionDisplay->getDisplayColorProfile()->getSupportedPerFrameMetadata();
463 }
464 
overrideHdrTypes(const std::vector<ui::Hdr> & hdrTypes)465 void DisplayDevice::overrideHdrTypes(const std::vector<ui::Hdr>& hdrTypes) {
466     mOverrideHdrTypes = hdrTypes;
467 }
468 
getHdrCapabilities() const469 HdrCapabilities DisplayDevice::getHdrCapabilities() const {
470     const HdrCapabilities& capabilities =
471             mCompositionDisplay->getDisplayColorProfile()->getHdrCapabilities();
472     std::vector<ui::Hdr> hdrTypes = capabilities.getSupportedHdrTypes();
473     if (!mOverrideHdrTypes.empty()) {
474         hdrTypes = mOverrideHdrTypes;
475     }
476     return HdrCapabilities(hdrTypes, capabilities.getDesiredMaxLuminance(),
477                            capabilities.getDesiredMaxAverageLuminance(),
478                            capabilities.getDesiredMinLuminance());
479 }
480 
enableRefreshRateOverlay(bool enable,bool showSpinnner)481 void DisplayDevice::enableRefreshRateOverlay(bool enable, bool showSpinnner) {
482     if (!enable) {
483         mRefreshRateOverlay.reset();
484         return;
485     }
486 
487     const auto fpsRange = mRefreshRateConfigs->getSupportedRefreshRateRange();
488     mRefreshRateOverlay = std::make_unique<RefreshRateOverlay>(fpsRange, showSpinnner);
489     mRefreshRateOverlay->setLayerStack(getLayerStack());
490     mRefreshRateOverlay->setViewport(getSize());
491     mRefreshRateOverlay->changeRefreshRate(getActiveMode()->getFps());
492 }
493 
onKernelTimerChanged(std::optional<DisplayModeId> desiredModeId,bool timerExpired)494 bool DisplayDevice::onKernelTimerChanged(std::optional<DisplayModeId> desiredModeId,
495                                          bool timerExpired) {
496     if (mRefreshRateConfigs && mRefreshRateOverlay) {
497         const auto newRefreshRate =
498                 mRefreshRateConfigs->onKernelTimerChanged(desiredModeId, timerExpired);
499         if (newRefreshRate) {
500             mRefreshRateOverlay->changeRefreshRate(*newRefreshRate);
501             return true;
502         }
503     }
504 
505     return false;
506 }
507 
animateRefreshRateOverlay()508 void DisplayDevice::animateRefreshRateOverlay() {
509     if (mRefreshRateOverlay) {
510         mRefreshRateOverlay->animate();
511     }
512 }
513 
setDesiredActiveMode(const ActiveModeInfo & info,bool force)514 bool DisplayDevice::setDesiredActiveMode(const ActiveModeInfo& info, bool force) {
515     ATRACE_CALL();
516 
517     LOG_ALWAYS_FATAL_IF(!info.mode, "desired mode not provided");
518     LOG_ALWAYS_FATAL_IF(getPhysicalId() != info.mode->getPhysicalDisplayId(), "DisplayId mismatch");
519 
520     ALOGV("%s(%s)", __func__, to_string(*info.mode).c_str());
521 
522     std::scoped_lock lock(mActiveModeLock);
523     if (mDesiredActiveModeChanged) {
524         // If a mode change is pending, just cache the latest request in mDesiredActiveMode
525         const auto prevConfig = mDesiredActiveMode.event;
526         mDesiredActiveMode = info;
527         mDesiredActiveMode.event = mDesiredActiveMode.event | prevConfig;
528         return false;
529     }
530 
531     // Check if we are already at the desired mode
532     if (!force && getActiveMode()->getId() == info.mode->getId()) {
533         return false;
534     }
535 
536     // Initiate a mode change.
537     mDesiredActiveModeChanged = true;
538     mDesiredActiveMode = info;
539     return true;
540 }
541 
getDesiredActiveMode() const542 std::optional<DisplayDevice::ActiveModeInfo> DisplayDevice::getDesiredActiveMode() const {
543     std::scoped_lock lock(mActiveModeLock);
544     if (mDesiredActiveModeChanged) return mDesiredActiveMode;
545     return std::nullopt;
546 }
547 
clearDesiredActiveModeState()548 void DisplayDevice::clearDesiredActiveModeState() {
549     std::scoped_lock lock(mActiveModeLock);
550     mDesiredActiveMode.event = scheduler::DisplayModeEvent::None;
551     mDesiredActiveModeChanged = false;
552 }
553 
setRefreshRatePolicy(const std::optional<scheduler::RefreshRateConfigs::Policy> & policy,bool overridePolicy)554 status_t DisplayDevice::setRefreshRatePolicy(
555         const std::optional<scheduler::RefreshRateConfigs::Policy>& policy, bool overridePolicy) {
556     const auto oldPolicy = mRefreshRateConfigs->getCurrentPolicy();
557     const status_t setPolicyResult = overridePolicy
558             ? mRefreshRateConfigs->setOverridePolicy(policy)
559             : mRefreshRateConfigs->setDisplayManagerPolicy(*policy);
560 
561     if (setPolicyResult == OK) {
562         const int numModeChanges = mNumModeSwitchesInPolicy.exchange(0);
563 
564         ALOGI("Display %s policy changed\n"
565               "Previous: {%s}\n"
566               "Current:  {%s}\n"
567               "%d mode changes were performed under the previous policy",
568               to_string(getId()).c_str(), oldPolicy.toString().c_str(),
569               policy ? policy->toString().c_str() : "null", numModeChanges);
570     }
571 
572     return setPolicyResult;
573 }
574 
575 std::atomic<int32_t> DisplayDeviceState::sNextSequenceId(1);
576 
577 }  // namespace android
578 
579 // TODO(b/129481165): remove the #pragma below and fix conversion issues
580 #pragma clang diagnostic pop // ignored "-Wconversion"
581