SurfaceFlinger: call to changeRefreshRate on state change only
Check if Scheduler's idle timer / content detection changed before
calling to changeRefreshRate to avoid sending config changed events when
those are not neeed.
Test: scroll within calendar app and observe systraces
Bug: 130759239
Change-Id: If7bce0ac096630918decbf62c568baa5e17408f2
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 1b154a4..88d2638 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -318,12 +318,24 @@
void Scheduler::updateFpsBasedOnContent() {
uint32_t refreshRate = std::round(mLayerHistory.getDesiredRefreshRate());
- ATRACE_INT("ContentFPS", refreshRate);
- if (refreshRate > 0) {
- contentChangeRefreshRate(ContentFeatureState::CONTENT_DETECTION_ON, refreshRate);
- } else {
- contentChangeRefreshRate(ContentFeatureState::CONTENT_DETECTION_OFF, 0);
+ RefreshRateType newRefreshRateType;
+ {
+ std::lock_guard<std::mutex> lock(mFeatureStateLock);
+ if (mContentRefreshRate == refreshRate) {
+ return;
+ }
+ mContentRefreshRate = refreshRate;
+ ATRACE_INT("ContentFPS", mContentRefreshRate);
+
+ mCurrentContentFeatureState = refreshRate > 0 ? ContentFeatureState::CONTENT_DETECTION_ON
+ : ContentFeatureState::CONTENT_DETECTION_OFF;
+ newRefreshRateType = calculateRefreshRateType();
+ if (mRefreshRateType == newRefreshRateType) {
+ return;
+ }
+ mRefreshRateType = newRefreshRateType;
}
+ changeRefreshRate(newRefreshRateType, ConfigEvent::Changed);
}
void Scheduler::setChangeRefreshRateCallback(
@@ -365,24 +377,19 @@
return stream.str();
}
-void Scheduler::contentChangeRefreshRate(ContentFeatureState contentFeatureState,
- uint32_t refreshRate) {
- RefreshRateType newRefreshRateType;
- {
- std::lock_guard<std::mutex> lock(mFeatureStateLock);
- mCurrentContentFeatureState = contentFeatureState;
- mContentRefreshRate = refreshRate;
- newRefreshRateType = calculateRefreshRateType();
- }
- changeRefreshRate(newRefreshRateType, ConfigEvent::Changed);
-}
-
void Scheduler::timerChangeRefreshRate(IdleTimerState idleTimerState) {
RefreshRateType newRefreshRateType;
{
std::lock_guard<std::mutex> lock(mFeatureStateLock);
+ if (mCurrentIdleTimerState == idleTimerState) {
+ return;
+ }
mCurrentIdleTimerState = idleTimerState;
newRefreshRateType = calculateRefreshRateType();
+ if (mRefreshRateType == newRefreshRateType) {
+ return;
+ }
+ mRefreshRateType = newRefreshRateType;
}
changeRefreshRate(newRefreshRateType, ConfigEvent::None);
}