summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJen-Chih Chang <jen-chih.chang@mediatek.com>2022-08-03 11:31:30 +0800
committerAdy Abraham <adyabr@google.com>2023-08-24 05:14:38 +0000
commit837c4a1ddfdef5007f79e2c7c769f36d8631892e (patch)
treed1755b60a093ac877d08c66ba013e22ed0bce73c
parent7e087dec7e2c83a047695141ffc1d4acc0accca3 (diff)
downloadnative-837c4a1ddfdef5007f79e2c7c769f36d8631892e.tar.gz
DO NOT MERGE Extend mPreviousPresentFences for high refresh rate
To provide hardware enough time to display a frame under high refresh rate with long sf-duration, we extend mPreviousPresentFences by storing extra slots. We check proper present fence at different moment according to vsync period and sf-duration. Bug: 241193992 Change-Id: I618dd7abdb1f9ca2cb92623cc4d423389d62e402 (cherry picked from commit 1febfb87aadcdc59be95c0fd2d821ba89bc933ec)
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp17
-rw-r--r--services/surfaceflinger/SurfaceFlinger.h3
2 files changed, 16 insertions, 4 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 38a067d1b3..c7c98107de 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2170,8 +2170,17 @@ bool SurfaceFlinger::wouldPresentEarly(TimePoint frameTime, Period vsyncPeriod)
auto SurfaceFlinger::getPreviousPresentFence(TimePoint frameTime, Period vsyncPeriod) const
-> const FenceTimePtr& {
const bool isTwoVsyncsAhead = mExpectedPresentTime - frameTime > vsyncPeriod;
- const size_t i = static_cast<size_t>(isTwoVsyncsAhead);
- return mPreviousPresentFences[i].fenceTime;
+
+ size_t shift = 0;
+ if (isTwoVsyncsAhead) {
+ shift = static_cast<size_t>(
+ Duration(mExpectedPresentTime - frameTime).ns() / vsyncPeriod.ns());
+ if (shift >= mPreviousPresentFences.size()) {
+ shift = mPreviousPresentFences.size() - 1;
+ }
+ }
+ ATRACE_FORMAT("previousFrameFence shift=%zu", shift);
+ return mPreviousPresentFences[shift].fenceTime;
}
bool SurfaceFlinger::isFencePending(const FenceTimePtr& fence, int graceTimeMs) {
@@ -2849,7 +2858,9 @@ void SurfaceFlinger::postComposition(nsecs_t callTime) {
glCompositionDoneFenceTime = FenceTime::NO_FENCE;
}
- mPreviousPresentFences[1] = mPreviousPresentFences[0];
+ for (size_t i = mPreviousPresentFences.size()-1; i >= 1; i--) {
+ mPreviousPresentFences[i] = mPreviousPresentFences[i-1];
+ }
auto presentFence = defaultDisplay
? getHwComposer().getPresentFence(defaultDisplay->getPhysicalId())
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 0bc506f1fe..be3a06ece7 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -1335,7 +1335,8 @@ private:
sp<Fence> fence = Fence::NO_FENCE;
FenceTimePtr fenceTime = FenceTime::NO_FENCE;
};
- std::array<FenceWithFenceTime, 2> mPreviousPresentFences;
+ // size should be longest sf-duration / shortest vsync period and round up
+ std::array<FenceWithFenceTime, 5> mPreviousPresentFences; // currently consider 166hz.
TimePoint mScheduledPresentTime GUARDED_BY(kMainThreadContext);
TimePoint mExpectedPresentTime GUARDED_BY(kMainThreadContext);