summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/BufferStateLayer.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/BufferStateLayer.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/BufferStateLayer.cpp')
-rw-r--r--services/surfaceflinger/BufferStateLayer.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index d68a0e0b47..955c2f88b0 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -44,12 +44,12 @@ using PresentState = frametimeline::SurfaceFrame::PresentState;
namespace {
void callReleaseBufferCallback(const sp<ITransactionCompletedListener>& listener,
const sp<GraphicBuffer>& buffer, const sp<Fence>& releaseFence,
- uint32_t transformHint) {
+ uint32_t transformHint, uint32_t currentMaxAcquiredBufferCount) {
if (!listener) {
return;
}
listener->onReleaseBuffer(buffer->getId(), releaseFence ? releaseFence : Fence::NO_FENCE,
- transformHint);
+ transformHint, currentMaxAcquiredBufferCount);
}
} // namespace
@@ -75,7 +75,9 @@ BufferStateLayer::~BufferStateLayer() {
if (mBufferInfo.mBuffer != nullptr && !isClone()) {
callReleaseBufferCallback(mDrawingState.releaseBufferListener,
mBufferInfo.mBuffer->getBuffer(), mBufferInfo.mFence,
- mTransformHint);
+ mTransformHint,
+ mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(
+ mOwnerUid));
}
}
@@ -199,6 +201,8 @@ void BufferStateLayer::releasePendingBuffer(nsecs_t dequeueReadyTime) {
for (const auto& handle : mDrawingState.callbackHandles) {
handle->transformHint = mTransformHint;
handle->dequeueReadyTime = dequeueReadyTime;
+ handle->currentMaxAcquiredBufferCount =
+ mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(mOwnerUid);
}
// If there are multiple transactions in this frame, set the previous id on the earliest
@@ -429,9 +433,10 @@ bool BufferStateLayer::setBuffer(const std::shared_ptr<renderengine::ExternalTex
// dropped and we should decrement the pending buffer count and
// call any release buffer callbacks if set.
callReleaseBufferCallback(mCurrentState.releaseBufferListener,
- mCurrentState.buffer->getBuffer(),
- mCurrentState.acquireFence,
- mTransformHint);
+ mCurrentState.buffer->getBuffer(), mCurrentState.acquireFence,
+ mTransformHint,
+ mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(
+ mOwnerUid));
decrementPendingBufferCount();
if (mCurrentState.bufferSurfaceFrameTX != nullptr) {
addSurfaceFrameDroppedForBuffer(mCurrentState.bufferSurfaceFrameTX);
@@ -951,7 +956,9 @@ void BufferStateLayer::bufferMayChange(const sp<GraphicBuffer>& newBuffer) {
// call any release buffer callbacks if set.
callReleaseBufferCallback(mDrawingState.releaseBufferListener,
mDrawingState.buffer->getBuffer(), mDrawingState.acquireFence,
- mTransformHint);
+ mTransformHint,
+ mFlinger->getMaxAcquiredBufferCountForCurrentRefreshRate(
+ mOwnerUid));
decrementPendingBufferCount();
}
}