SF: Fix condition to activate display on power-on
Since [1], getDefaultDisplayDeviceLocked's fallback when the active
display is outdated is to return the primary display, not `nullptr`.
During the initial call to setPowerModeInternal, `activeDisplay` is
no longer `nullptr`, but the primary display.
After [2], onActiveDisplayChangedLocked is expected to be called for
the primary display during boot. This was not the case though, since
the DisplayDevice::setPowerMode() update precedes the DisplayDevice::
isPoweredOn() query.
Fix this by querying before updating. Also, clean up `nullptr` checks
around onActiveDisplayChangedLocked.
[1] If83c908446e5e5267dfcb15189a26b779d75b216
[2] I15e0f5a280e62baf6d4e6ea2748d95342e79ac44
Fixes: 260663220
Test: The leader display ID is logged during single-display boot.
Test: SetPowerModeInternalTest.designatesLeaderDisplay
Change-Id: I0d20ce7f7ab3f9e90ef1c72263b8166865486d62
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 365ffb7..1bbaf7b 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -4685,18 +4685,18 @@
.value_or(false);
const auto activeDisplay = getDisplayDeviceLocked(mActiveDisplayId);
- if (isInternalDisplay && activeDisplay != display && activeDisplay &&
- activeDisplay->isPoweredOn()) {
- ALOGW("Trying to change power mode on non active display while the active display is ON");
- }
+ const bool isActiveDisplayPoweredOn = activeDisplay && activeDisplay->isPoweredOn();
+
+ ALOGW_IF(display != activeDisplay && isInternalDisplay && isActiveDisplayPoweredOn,
+ "Trying to change power mode on inactive display without powering off active display");
display->setPowerMode(mode);
const auto refreshRate = display->refreshRateSelector().getActiveMode().modePtr->getFps();
if (!currentModeOpt || *currentModeOpt == hal::PowerMode::OFF) {
// Turn on the display
- if (isInternalDisplay && (!activeDisplay || !activeDisplay->isPoweredOn())) {
- onActiveDisplayChangedLocked(display);
+ if (isInternalDisplay && !isActiveDisplayPoweredOn) {
+ onActiveDisplayChangedLocked(activeDisplay, display);
}
// Keep uclamp in a separate syscall and set it before changing to RT due to b/190237315.
// We can merge the syscall later.
@@ -6995,17 +6995,14 @@
getRenderEngine().onActiveDisplaySizeChanged(activeDisplay->getSize());
}
-void SurfaceFlinger::onActiveDisplayChangedLocked(const sp<DisplayDevice>& activeDisplay) {
+void SurfaceFlinger::onActiveDisplayChangedLocked(const sp<DisplayDevice>& inactiveDisplay,
+ const sp<DisplayDevice>& activeDisplay) {
ATRACE_CALL();
- if (const auto display = getDisplayDeviceLocked(mActiveDisplayId)) {
- display->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false);
+ if (inactiveDisplay) {
+ inactiveDisplay->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false);
}
- if (!activeDisplay) {
- ALOGE("%s: activeDisplay is null", __func__);
- return;
- }
mActiveDisplayId = activeDisplay->getPhysicalId();
activeDisplay->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true);