SF: Remove DisplayDevice::ActiveModeInfo
This type is redundant with DisplayModeRequest, so store the desired and
pending modes as DisplayModeRequestOpt. This is a step toward flowing
the request through one of desired/pending/active states.
Use the std::nullopt state of the desired mode instead of relying on the
implicitly associated TracedOrdinal<bool>.
Bug: 241285876
Test: presubmit
Change-Id: Ie12a5ad420745761c73b1ce2c536862f79a50665
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 6e6229a..b8d6f9e 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1190,7 +1190,7 @@
const auto mode = request.mode;
const bool emitEvent = request.emitEvent;
- switch (display->setDesiredMode(DisplayDevice::ActiveModeInfo(std::move(request)), force)) {
+ switch (display->setDesiredMode(std::move(request), force)) {
case DisplayDevice::DesiredModeAction::InitiateDisplayModeSwitch:
// DisplayDevice::setDesiredMode updated the render rate, so inform Scheduler.
mScheduler->setRenderRate(displayId,
@@ -1286,27 +1286,27 @@
const auto displayId = display.getPhysicalId();
ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str());
- const auto pendingMode = display.getPendingMode();
- if (!pendingMode.modeOpt) {
+ const auto pendingModeOpt = display.getPendingMode();
+ if (!pendingModeOpt) {
// There is no pending mode change. This can happen if the active
// display changed and the mode change happened on a different display.
return;
}
- if (display.getActiveMode().modePtr->getResolution() !=
- pendingMode.modeOpt->modePtr->getResolution()) {
+ const auto& activeMode = pendingModeOpt->mode;
+
+ if (display.getActiveMode().modePtr->getResolution() != activeMode.modePtr->getResolution()) {
auto& state = mCurrentState.displays.editValueFor(display.getDisplayToken());
// We need to generate new sequenceId in order to recreate the display (and this
// way the framebuffer).
state.sequenceId = DisplayDeviceState{}.sequenceId;
- state.physical->activeMode = pendingMode.modeOpt->modePtr.get();
+ state.physical->activeMode = activeMode.modePtr.get();
processDisplayChangesLocked();
// processDisplayChangesLocked will update all necessary components so we're done here.
return;
}
- const auto& activeMode = *pendingMode.modeOpt;
display.finalizeModeChange(activeMode.modePtr->getId(), activeMode.modePtr->getVsyncRate(),
activeMode.fps);
@@ -1315,7 +1315,7 @@
updatePhaseConfiguration(activeMode.fps);
}
- if (pendingMode.event != scheduler::DisplayModeEvent::None) {
+ if (pendingModeOpt->emitEvent) {
dispatchDisplayModeChangeEvent(displayId, activeMode);
}
}
@@ -1329,12 +1329,15 @@
}
void SurfaceFlinger::applyActiveMode(const sp<DisplayDevice>& display) {
- const auto desiredModeOpt = display->getDesiredMode();
- const auto& modeOpt = desiredModeOpt->modeOpt;
- const auto displayId = modeOpt->modePtr->getPhysicalDisplayId();
- const auto renderFps = modeOpt->fps;
+ const auto activeModeOpt = display->getDesiredMode();
+ auto activeModePtr = activeModeOpt->mode.modePtr;
+ const auto displayId = activeModePtr->getPhysicalDisplayId();
+ const auto renderFps = activeModeOpt->mode.fps;
+
dropModeRequest(display);
- mScheduler->resyncToHardwareVsync(displayId, true /* allowToEnable */, modeOpt->modePtr.get());
+
+ constexpr bool kAllowToEnable = true;
+ mScheduler->resyncToHardwareVsync(displayId, kAllowToEnable, std::move(activeModePtr).take());
mScheduler->setRenderRate(displayId, renderFps);
if (displayId == mActiveDisplayId) {
@@ -1351,7 +1354,7 @@
const auto display = getDisplayDeviceLocked(id);
if (!display) continue;
- const auto desiredModeOpt = display->getDesiredMode();
+ auto desiredModeOpt = display->getDesiredMode();
if (!desiredModeOpt) {
continue;
}
@@ -1361,7 +1364,7 @@
continue;
}
- const auto desiredModeId = desiredModeOpt->modeOpt->modePtr->getId();
+ const auto desiredModeId = desiredModeOpt->mode.modePtr->getId();
const auto displayModePtrOpt = physical.snapshot().displayModes().get(desiredModeId);
if (!displayModePtrOpt) {
@@ -1375,7 +1378,7 @@
to_string(displayModePtrOpt->get()->getVsyncRate()).c_str(),
to_string(display->getId()).c_str());
- if (display->getActiveMode() == desiredModeOpt->modeOpt) {
+ if (display->getActiveMode() == desiredModeOpt->mode) {
applyActiveMode(display);
continue;
}
@@ -1383,9 +1386,7 @@
// Desired active mode was set, it is different than the mode currently in use, however
// allowed modes might have changed by the time we process the refresh.
// Make sure the desired mode is still allowed
- const auto displayModeAllowed =
- display->refreshRateSelector().isModeAllowed(*desiredModeOpt->modeOpt);
- if (!displayModeAllowed) {
+ if (!display->refreshRateSelector().isModeAllowed(desiredModeOpt->mode)) {
dropModeRequest(display);
continue;
}
@@ -1396,7 +1397,7 @@
constraints.seamlessRequired = false;
hal::VsyncPeriodChangeTimeline outTimeline;
- if (!display->initiateModeChange(*desiredModeOpt, constraints, outTimeline)) {
+ if (!display->initiateModeChange(std::move(*desiredModeOpt), constraints, outTimeline)) {
continue;
}
@@ -1418,7 +1419,7 @@
finalizeDisplayModeChange(*display);
const auto desiredModeOpt = display->getDesiredMode();
- if (desiredModeOpt && display->getActiveMode() == desiredModeOpt->modeOpt) {
+ if (desiredModeOpt && display->getActiveMode() == desiredModeOpt->mode) {
applyActiveMode(display);
}
}
@@ -7286,8 +7287,8 @@
if (!display->isRefreshRateOverlayEnabled()) return;
const auto desiredModeIdOpt =
- display->getDesiredMode().transform([](const DisplayDevice::ActiveModeInfo& info) {
- return info.modeOpt->modePtr->getId();
+ display->getDesiredMode().transform([](const display::DisplayModeRequest& request) {
+ return request.mode.modePtr->getId();
});
const bool timerExpired = mKernelIdleTimerEnabled && expired;