Loading services/surfaceflinger/SurfaceFlinger.cpp +23 −3 Original line number Original line Diff line number Diff line Loading @@ -1530,10 +1530,25 @@ void SurfaceFlinger::onRefreshReceived(int sequenceId, hwc2_display_t /*hwcDispl void SurfaceFlinger::setPrimaryVsyncEnabled(bool enabled) { void SurfaceFlinger::setPrimaryVsyncEnabled(bool enabled) { ATRACE_CALL(); ATRACE_CALL(); Mutex::Autolock lock(mStateLock); // Enable / Disable HWVsync from the main thread to avoid race conditions with // display power state. postMessageAsync(new LambdaMessage( [=]() NO_THREAD_SAFETY_ANALYSIS { setPrimaryVsyncEnabledInternal(enabled); })); } void SurfaceFlinger::setPrimaryVsyncEnabledInternal(bool enabled) { ATRACE_CALL(); if (const auto displayId = getInternalDisplayIdLocked()) { if (const auto displayId = getInternalDisplayIdLocked()) { sp<DisplayDevice> display = getDefaultDisplayDeviceLocked(); if (display && display->isPoweredOn()) { getHwComposer().setVsyncEnabled(*displayId, getHwComposer().setVsyncEnabled(*displayId, enabled ? HWC2::Vsync::Enable : HWC2::Vsync::Disable); enabled ? HWC2::Vsync::Enable : HWC2::Vsync::Disable); } else { // Cache the latest vsync state and apply it when screen is on again mEnableHWVsyncScreenOn = enabled; } } } } } Loading Loading @@ -4431,6 +4446,11 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, int // Turn on the display // Turn on the display getHwComposer().setPowerMode(*displayId, mode); getHwComposer().setPowerMode(*displayId, mode); if (display->isPrimary() && mode != HWC_POWER_MODE_DOZE_SUSPEND) { if (display->isPrimary() && mode != HWC_POWER_MODE_DOZE_SUSPEND) { if (mEnableHWVsyncScreenOn) { setPrimaryVsyncEnabledInternal(mEnableHWVsyncScreenOn); mEnableHWVsyncScreenOn = false; } mScheduler->onScreenAcquired(mAppConnectionHandle); mScheduler->onScreenAcquired(mAppConnectionHandle); mScheduler->resyncToHardwareVsync(true, getVsyncPeriod()); mScheduler->resyncToHardwareVsync(true, getVsyncPeriod()); } } Loading services/surfaceflinger/SurfaceFlinger.h +6 −0 Original line number Original line Diff line number Diff line Loading @@ -293,6 +293,9 @@ public: // TODO: this should be made accessible only to EventThread // TODO: this should be made accessible only to EventThread void setPrimaryVsyncEnabled(bool enabled); void setPrimaryVsyncEnabled(bool enabled); // main thread function to enable/disable h/w composer event void setPrimaryVsyncEnabledInternal(bool enabled); // called on the main thread by MessageQueue when an internal message // called on the main thread by MessageQueue when an internal message // is received // is received // TODO: this should be made accessible only to MessageQueue // TODO: this should be made accessible only to MessageQueue Loading Loading @@ -1168,6 +1171,9 @@ private: // The Layer pointer is removed from the set when the destructor is called so there shouldn't // The Layer pointer is removed from the set when the destructor is called so there shouldn't // be any issues with a raw pointer referencing an invalid object. // be any issues with a raw pointer referencing an invalid object. std::unordered_set<Layer*> mOffscreenLayers; std::unordered_set<Layer*> mOffscreenLayers; // Flag to indicate whether to re-enable HWVsync when screen is on bool mEnableHWVsyncScreenOn = false; }; }; } // namespace android } // namespace android Loading
services/surfaceflinger/SurfaceFlinger.cpp +23 −3 Original line number Original line Diff line number Diff line Loading @@ -1530,10 +1530,25 @@ void SurfaceFlinger::onRefreshReceived(int sequenceId, hwc2_display_t /*hwcDispl void SurfaceFlinger::setPrimaryVsyncEnabled(bool enabled) { void SurfaceFlinger::setPrimaryVsyncEnabled(bool enabled) { ATRACE_CALL(); ATRACE_CALL(); Mutex::Autolock lock(mStateLock); // Enable / Disable HWVsync from the main thread to avoid race conditions with // display power state. postMessageAsync(new LambdaMessage( [=]() NO_THREAD_SAFETY_ANALYSIS { setPrimaryVsyncEnabledInternal(enabled); })); } void SurfaceFlinger::setPrimaryVsyncEnabledInternal(bool enabled) { ATRACE_CALL(); if (const auto displayId = getInternalDisplayIdLocked()) { if (const auto displayId = getInternalDisplayIdLocked()) { sp<DisplayDevice> display = getDefaultDisplayDeviceLocked(); if (display && display->isPoweredOn()) { getHwComposer().setVsyncEnabled(*displayId, getHwComposer().setVsyncEnabled(*displayId, enabled ? HWC2::Vsync::Enable : HWC2::Vsync::Disable); enabled ? HWC2::Vsync::Enable : HWC2::Vsync::Disable); } else { // Cache the latest vsync state and apply it when screen is on again mEnableHWVsyncScreenOn = enabled; } } } } } Loading Loading @@ -4431,6 +4446,11 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, int // Turn on the display // Turn on the display getHwComposer().setPowerMode(*displayId, mode); getHwComposer().setPowerMode(*displayId, mode); if (display->isPrimary() && mode != HWC_POWER_MODE_DOZE_SUSPEND) { if (display->isPrimary() && mode != HWC_POWER_MODE_DOZE_SUSPEND) { if (mEnableHWVsyncScreenOn) { setPrimaryVsyncEnabledInternal(mEnableHWVsyncScreenOn); mEnableHWVsyncScreenOn = false; } mScheduler->onScreenAcquired(mAppConnectionHandle); mScheduler->onScreenAcquired(mAppConnectionHandle); mScheduler->resyncToHardwareVsync(true, getVsyncPeriod()); mScheduler->resyncToHardwareVsync(true, getVsyncPeriod()); } } Loading
services/surfaceflinger/SurfaceFlinger.h +6 −0 Original line number Original line Diff line number Diff line Loading @@ -293,6 +293,9 @@ public: // TODO: this should be made accessible only to EventThread // TODO: this should be made accessible only to EventThread void setPrimaryVsyncEnabled(bool enabled); void setPrimaryVsyncEnabled(bool enabled); // main thread function to enable/disable h/w composer event void setPrimaryVsyncEnabledInternal(bool enabled); // called on the main thread by MessageQueue when an internal message // called on the main thread by MessageQueue when an internal message // is received // is received // TODO: this should be made accessible only to MessageQueue // TODO: this should be made accessible only to MessageQueue Loading Loading @@ -1168,6 +1171,9 @@ private: // The Layer pointer is removed from the set when the destructor is called so there shouldn't // The Layer pointer is removed from the set when the destructor is called so there shouldn't // be any issues with a raw pointer referencing an invalid object. // be any issues with a raw pointer referencing an invalid object. std::unordered_set<Layer*> mOffscreenLayers; std::unordered_set<Layer*> mOffscreenLayers; // Flag to indicate whether to re-enable HWVsync when screen is on bool mEnableHWVsyncScreenOn = false; }; }; } // namespace android } // namespace android