diff options
| author | 2019-06-14 21:02:08 +0000 | |
|---|---|---|
| committer | 2019-06-14 21:02:08 +0000 | |
| commit | 49a3fb445f5c7b9d10c97bb089fef41cbdfbc927 (patch) | |
| tree | 860aa964e4dfb920278169e15fe9334ffc3ce2bb | |
| parent | 3d3e0ff0ee45fb25a0c13b2af3e78b6ad7181f21 (diff) | |
| parent | 616b83295e42d8fb700067bb8edf1fea7b071bdf (diff) | |
Merge "SurfaceFlinger: tune FPS detection logic" into qt-r1-dev
| -rw-r--r-- | services/surfaceflinger/Scheduler/LayerInfo.cpp | 6 | ||||
| -rw-r--r-- | services/surfaceflinger/Scheduler/LayerInfo.h | 24 | ||||
| -rw-r--r-- | services/surfaceflinger/Scheduler/SchedulerUtils.h | 8 |
3 files changed, 27 insertions, 11 deletions
diff --git a/services/surfaceflinger/Scheduler/LayerInfo.cpp b/services/surfaceflinger/Scheduler/LayerInfo.cpp index 95d7d31564..3104724041 100644 --- a/services/surfaceflinger/Scheduler/LayerInfo.cpp +++ b/services/surfaceflinger/Scheduler/LayerInfo.cpp @@ -38,6 +38,12 @@ void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime) { mLastUpdatedTime = std::max(lastPresentTime, systemTime()); mPresentTimeHistory.insertPresentTime(mLastUpdatedTime); + if (mLastPresentTime == 0) { + // First frame + mLastPresentTime = lastPresentTime; + return; + } + const nsecs_t timeDiff = lastPresentTime - mLastPresentTime; mLastPresentTime = lastPresentTime; // Ignore time diff that are too high - those are stale values diff --git a/services/surfaceflinger/Scheduler/LayerInfo.h b/services/surfaceflinger/Scheduler/LayerInfo.h index 02b6aefa2b..90d426969c 100644 --- a/services/surfaceflinger/Scheduler/LayerInfo.h +++ b/services/surfaceflinger/Scheduler/LayerInfo.h @@ -55,7 +55,7 @@ class LayerInfo { float getRefreshRateAvg() const { nsecs_t refreshDuration = mMinRefreshDuration; - if (mElements.size() == HISTORY_SIZE) { + if (mElements.size() > 0) { refreshDuration = scheduler::calculate_mean(mElements); } @@ -86,14 +86,23 @@ class LayerInfo { // Checks whether the present time that was inserted HISTORY_SIZE ago is within a // certain threshold: TIME_EPSILON_NS. bool isRelevant() const { + if (mElements.size() < 2) { + return false; + } + + // The layer had to publish at least HISTORY_SIZE or HISTORY_TIME of updates + if (mElements.size() != HISTORY_SIZE && + mElements.at(mElements.size() - 1) - mElements.at(0) < HISTORY_TIME.count()) { + return false; + } + + // The last update should not be older than TIME_EPSILON_NS nanoseconds. const int64_t obsoleteEpsilon = systemTime() - scheduler::TIME_EPSILON_NS.count(); - // The layer had to publish at least HISTORY_SIZE of updates, and the first - // update should not be older than TIME_EPSILON_NS nanoseconds. - if (mElements.size() == HISTORY_SIZE && - mElements.at(HISTORY_SIZE - 1) > obsoleteEpsilon) { - return true; + if (mElements.at(mElements.size() - 1) < obsoleteEpsilon) { + return false; } - return false; + + return true; } void clearHistory() { mElements.clear(); } @@ -101,6 +110,7 @@ class LayerInfo { private: std::deque<nsecs_t> mElements; static constexpr size_t HISTORY_SIZE = 10; + static constexpr std::chrono::nanoseconds HISTORY_TIME = 500ms; }; public: diff --git a/services/surfaceflinger/Scheduler/SchedulerUtils.h b/services/surfaceflinger/Scheduler/SchedulerUtils.h index 3bf3922edd..d3b1bd07c4 100644 --- a/services/surfaceflinger/Scheduler/SchedulerUtils.h +++ b/services/surfaceflinger/Scheduler/SchedulerUtils.h @@ -37,12 +37,12 @@ static constexpr int SCREEN_OFF_CONFIG_ID = -1; static constexpr uint32_t HWC2_SCREEN_OFF_CONFIG_ID = 0xffffffff; // This number is used when we try to determine how long does a given layer stay relevant. -// Currently it is set to 100ms, because that would indicate 10Hz rendering. -static constexpr std::chrono::nanoseconds TIME_EPSILON_NS = 100ms; +// The value is set based on testing different scenarios. +static constexpr std::chrono::nanoseconds TIME_EPSILON_NS = 200ms; // This number is used when we try to determine how long do we keep layer information around -// before we remove it. Currently it is set to 100ms. -static constexpr std::chrono::nanoseconds OBSOLETE_TIME_EPSILON_NS = 100ms; +// before we remove it. +static constexpr std::chrono::nanoseconds OBSOLETE_TIME_EPSILON_NS = 200ms; // Calculates the statistical mean (average) in the data structure (array, vector). The // function does not modify the contents of the array. |