Fix display power state reset in vr flinger path
Some code refactoring in ag/4355343 accidentally broke vr flinger. When
switching to vr flinger, we call setPowerModeInternal() to reset the
display state. With ag/4355343, we were incorrectly holding on to a
stale display, causing us to early exit from setPowerModeInternal() and
not apply the display power state change.
Bug: 111398862
Test: Manually ran vr flinger, confirmed it works again after applying
this CL.
Change-Id: Idbead0338f9219c80cb8a2d9f283daefff373a33
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 7680f2a..25b4cb7 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1429,9 +1429,13 @@
Mutex::Autolock _l(mStateLock);
- const auto display = getDefaultDisplayDeviceLocked();
+ sp<DisplayDevice> display = getDefaultDisplayDeviceLocked();
LOG_ALWAYS_FATAL_IF(!display);
const int currentDisplayPowerMode = display->getPowerMode();
+ // This DisplayDevice will no longer be relevant once resetDisplayState() is
+ // called below. Clear the reference now so we don't accidentally use it
+ // later.
+ display.clear();
if (!vrFlingerRequestsDisplay) {
mVrFlinger->SeizeDisplayOwnership();
@@ -1456,6 +1460,8 @@
invalidateHwcGeometry();
// Re-enable default display.
+ display = getDefaultDisplayDeviceLocked();
+ LOG_ALWAYS_FATAL_IF(!display);
setPowerModeInternal(display, currentDisplayPowerMode, /*stateLockHeld*/ true);
// Reset the timing values to account for the period of the swapped in HWC