From 4de4ee3cb3ccb3bcf4ea507f7bd6e02ab29aeb75 Mon Sep 17 00:00:00 2001 From: Matthew Bouyack Date: Fri, 12 May 2017 12:49:32 -0700 Subject: [PATCH] Fixes vsync behavior in power mode transitions. Calling EventThread::onScreenAcquired enables hardware vsync and calling EventThread::onScreenReleased disables hardware vsync. The power modes 'NORMAL' and 'DOZE' should have hardware vsync enabled while power modes 'OFF' and 'DOZE_SUSPEND' should have hardware vsync disabled. This change correctly handles the transitions from 'OFF' to 'DOZE_SUSPEND' and from either 'OFF' or 'DOZE_SUSPEND' to 'NORMAL'. Previously these cases were handled incorrectly. Note that redundant calls to onScreenAcquired or onScreenReleased are safe. Fixes bug: 38232221 Change-Id: I7b00f97a67b157366364b3d26fe94533da07c263 --- services/surfaceflinger/SurfaceFlinger.cpp | 7 +++++-- services/surfaceflinger/SurfaceFlinger_hwc1.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 78aa673842..448f12ac95 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2619,7 +2619,8 @@ void SurfaceFlinger::setPowerModeInternal(const sp& hw, if (currentMode == HWC_POWER_MODE_OFF) { // Turn on the display getHwComposer().setPowerMode(type, mode); - if (type == DisplayDevice::DISPLAY_PRIMARY) { + if (type == DisplayDevice::DISPLAY_PRIMARY && + mode != HWC_POWER_MODE_DOZE_SUSPEND) { // FIXME: eventthread only knows about the main display right now mEventThread->onScreenAcquired(); resyncToHardwareVsync(true); @@ -2651,7 +2652,8 @@ void SurfaceFlinger::setPowerModeInternal(const sp& hw, getHwComposer().setPowerMode(type, mode); mVisibleRegionsDirty = true; // from this point on, SF will stop drawing on this display - } else if (mode == HWC_POWER_MODE_DOZE) { + } else if (mode == HWC_POWER_MODE_DOZE || + mode == HWC_POWER_MODE_NORMAL) { // Update display while dozing getHwComposer().setPowerMode(type, mode); if (type == DisplayDevice::DISPLAY_PRIMARY) { @@ -2668,6 +2670,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp& hw, } getHwComposer().setPowerMode(type, mode); } else { + ALOGE("Attempting to set unknown power mode: %d\n", mode); getHwComposer().setPowerMode(type, mode); } } diff --git a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp index 627bcc3255..a371c76e6d 100644 --- a/services/surfaceflinger/SurfaceFlinger_hwc1.cpp +++ b/services/surfaceflinger/SurfaceFlinger_hwc1.cpp @@ -2535,7 +2535,8 @@ void SurfaceFlinger::setPowerModeInternal(const sp& hw, if (currentMode == HWC_POWER_MODE_OFF) { // Turn on the display getHwComposer().setPowerMode(type, mode); - if (type == DisplayDevice::DISPLAY_PRIMARY) { + if (type == DisplayDevice::DISPLAY_PRIMARY && + mode != HWC_POWER_MODE_DOZE_SUSPEND) { // FIXME: eventthread only knows about the main display right now mEventThread->onScreenAcquired(); resyncToHardwareVsync(true); @@ -2567,7 +2568,8 @@ void SurfaceFlinger::setPowerModeInternal(const sp& hw, getHwComposer().setPowerMode(type, mode); mVisibleRegionsDirty = true; // from this point on, SF will stop drawing on this display - } else if (mode == HWC_POWER_MODE_DOZE) { + } else if (mode == HWC_POWER_MODE_DOZE || + mode == HWC_POWER_MODE_NORMAL) { // Update display while dozing getHwComposer().setPowerMode(type, mode); if (type == DisplayDevice::DISPLAY_PRIMARY) { @@ -2584,6 +2586,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp& hw, } getHwComposer().setPowerMode(type, mode); } else { + ALOGE("Attempting to set unknown power mode: %d\n", mode); getHwComposer().setPowerMode(type, mode); } } -- 2.11.0