summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/SurfaceFlinger.cpp
diff options
context:
space:
mode:
author Ady Abraham <adyabr@google.com> 2021-06-15 16:56:21 -0700
committer Ady Abraham <adyabr@google.com> 2021-06-17 16:43:54 -0700
commit899dcdb63ad9cb81d1987e89be08dc9603aad89b (patch)
treece6ea8bb20845f18d901fab94e2ba9027d2757db /services/surfaceflinger/SurfaceFlinger.cpp
parent0bde6b5a9837ab96484c988bb3f148d0b9b3ab4e (diff)
SF: change acquired buffers based on the current refresh rate
BLASTBufferQueue set the max acquired buffers based on SF vsync configuration (sf.duration and app.duration). This is calculated based on the max supported refresh rate on the device, and it turn is propogated to apps via min_undequeued_buffers to the app could allocate enough buffers for maintaining the pipeline SF expects. This leads to a higher latency when the device is running in a lower refresh rate as there are more buffers on the buffer queue then required. In this change we are holding on the these "extra buffers" and not releasing them back to the buffer queue so the app would use the number of buffers it needs based on the current refresh rate, and to avoid having unnecessary long latency. Bug: 188553729 Test: Run backpressure based game on 60Hz and 120Hz and collect systraces Change-Id: I9d4e6278f0ddd28008ac437ab0576aa79d05166a
Diffstat (limited to 'services/surfaceflinger/SurfaceFlinger.cpp')
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index c1d28b1746..a39ae5819d 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -5247,7 +5247,7 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) {
case CAPTURE_DISPLAY:
case SET_FRAME_TIMELINE_INFO:
case GET_GPU_CONTEXT_PRIORITY:
- case GET_EXTRA_BUFFER_COUNT: {
+ case GET_MAX_ACQUIRED_BUFFER_COUNT: {
// This is not sensitive information, so should not require permission control.
return OK;
}
@@ -6800,25 +6800,38 @@ int SurfaceFlinger::getGPUContextPriority() {
return getRenderEngine().getContextPriority();
}
-int SurfaceFlinger::calculateExtraBufferCount(Fps maxSupportedRefreshRate,
- std::chrono::nanoseconds presentLatency) {
- auto pipelineDepth = presentLatency.count() / maxSupportedRefreshRate.getPeriodNsecs();
- if (presentLatency.count() % maxSupportedRefreshRate.getPeriodNsecs()) {
+int SurfaceFlinger::calculateMaxAcquiredBufferCount(Fps refreshRate,
+ std::chrono::nanoseconds presentLatency) {
+ auto pipelineDepth = presentLatency.count() / refreshRate.getPeriodNsecs();
+ if (presentLatency.count() % refreshRate.getPeriodNsecs()) {
pipelineDepth++;
}
- return std::max(0ll, pipelineDepth - 2);
+ return std::max(1ll, pipelineDepth - 1);
}
-status_t SurfaceFlinger::getExtraBufferCount(int* extraBuffers) const {
+status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const {
const auto maxSupportedRefreshRate = mRefreshRateConfigs->getSupportedRefreshRateRange().max;
- const auto vsyncConfig =
- mVsyncConfiguration->getConfigsForRefreshRate(maxSupportedRefreshRate).late;
- const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration;
-
- *extraBuffers = calculateExtraBufferCount(maxSupportedRefreshRate, presentLatency);
+ *buffers = getMaxAcquiredBufferCountForRefreshRate(maxSupportedRefreshRate);
return NO_ERROR;
}
+int SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t uid) const {
+ const auto refreshRate = [&] {
+ const auto frameRateOverride = mScheduler->getFrameRateOverride(uid);
+ if (frameRateOverride.has_value()) {
+ return frameRateOverride.value();
+ }
+ return mRefreshRateConfigs->getCurrentRefreshRate().getFps();
+ }();
+ return getMaxAcquiredBufferCountForRefreshRate(refreshRate);
+}
+
+int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const {
+ const auto vsyncConfig = mVsyncConfiguration->getConfigsForRefreshRate(refreshRate).late;
+ const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration;
+ return calculateMaxAcquiredBufferCount(refreshRate, presentLatency);
+}
+
void SurfaceFlinger::TransactionState::traverseStatesWithBuffers(
std::function<void(const layer_state_t&)> visitor) {
for (const auto& state : states) {