Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0bde6b5a authored by Ady Abraham's avatar Ady Abraham
Browse files

SF: increase the number of buffers for SurfaceView

3 buffers are not sufficient for most apps to render at high refresh
rates. This change increases the maxAcquiredBufferCount on the buffer
queue for all surfaces, and removes the hwui-specific extra buffer
allocations. All Surfaces connected to SurfaceFlinger will have now
enough buffers to account for configured
'debug.sf.late.app.duration' value.

Test: Run backpressure based game on 60Hz and 120Hz and collect
traces
Bug: 188553729

Change-Id: Ib8fda5db3f48c3bfc6fbf07167b4313674512cee
parent 603a15d2
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -29,9 +29,10 @@
#include <gui/IProducerListener.h>
#include <gui/Surface.h>
#include <utils/Singleton.h>

#include <utils/Trace.h>

#include <private/gui/ComposerService.h>

#include <chrono>

using namespace std::chrono_literals;
@@ -158,6 +159,11 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont
    mBufferItemConsumer->setDefaultBufferFormat(convertBufferFormat(format));
    mBufferItemConsumer->setBlastBufferQueue(this);

    int extraBufferCount = 0;
    ComposerService::getComposerService()->getExtraBufferCount(&extraBufferCount);
    mMaxAcquiredBuffers = 1 + extraBufferCount;
    mBufferItemConsumer->setMaxAcquiredBufferCount(mMaxAcquiredBuffers);

    mTransformHint = mSurfaceControl->getTransformHint();
    mBufferItemConsumer->setTransformHint(mTransformHint);
    SurfaceComposerClient::Transaction()
@@ -567,7 +573,7 @@ void BLASTBufferQueue::setTransactionCompleteCallback(
// includeExtraAcquire is true to include this buffer to the count. Since this depends on the state
// of the buffer, the next acquire may return with NO_BUFFER_AVAILABLE.
bool BLASTBufferQueue::maxBuffersAcquired(bool includeExtraAcquire) const {
    int maxAcquiredBuffers = MAX_ACQUIRED_BUFFERS + (includeExtraAcquire ? 2 : 1);
    int maxAcquiredBuffers = mMaxAcquiredBuffers + (includeExtraAcquire ? 2 : 1);
    return mNumAcquired == maxAcquiredBuffers;
}

+0 −15
Original line number Diff line number Diff line
@@ -1501,9 +1501,6 @@ int Surface::perform(int operation, va_list args)
    case NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO:
        res = dispatchSetFrameTimelineInfo(args);
        break;
    case NATIVE_WINDOW_GET_EXTRA_BUFFER_COUNT:
        res = dispatchGetExtraBufferCount(args);
        break;
    default:
        res = NAME_NOT_FOUND;
        break;
@@ -1853,14 +1850,6 @@ int Surface::dispatchSetFrameTimelineInfo(va_list args) {
    return setFrameTimelineInfo({frameTimelineVsyncId, inputEventId});
}

int Surface::dispatchGetExtraBufferCount(va_list args) {
    ATRACE_CALL();
    auto extraBuffers = static_cast<int*>(va_arg(args, int*));

    ALOGV("Surface::dispatchGetExtraBufferCount");
    return getExtraBufferCount(extraBuffers);
}

bool Surface::transformToDisplayInverse() const {
    return (mTransform & NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY) ==
            NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
@@ -2632,8 +2621,4 @@ status_t Surface::setFrameTimelineInfo(const FrameTimelineInfo& frameTimelineInf
    return composerService()->setFrameTimelineInfo(mGraphicBufferProducer, frameTimelineInfo);
}

status_t Surface::getExtraBufferCount(int* extraBuffers) const {
    return composerService()->getExtraBufferCount(extraBuffers);
}

}; // namespace android
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ sp<Surface> SurfaceControl::generateSurfaceLocked()
                                 ISurfaceComposerClient::eOpaque);
    mBbqChild = mClient->createSurface(String8("bbq-wrapper"), 0, 0, mFormat,
                                       flags, mHandle, {}, &ignore);
    mBbq = new BLASTBufferQueue("bbq-adapter", mBbqChild, mWidth, mHeight, mFormat);
    mBbq = sp<BLASTBufferQueue>::make("bbq-adapter", mBbqChild, mWidth, mHeight, mFormat);

    // This surface is always consumed by SurfaceFlinger, so the
    // producerControlledByApp value doesn't matter; using false.
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ private:

    // BufferQueue internally allows 1 more than
    // the max to be acquired
    static const int MAX_ACQUIRED_BUFFERS = 1;
    int32_t mMaxAcquiredBuffers = 1;

    int32_t mNumFrameAvailable GUARDED_BY(mMutex);
    int32_t mNumAcquired GUARDED_BY(mMutex);
+0 −2
Original line number Diff line number Diff line
@@ -190,7 +190,6 @@ public:
    virtual status_t setFrameRate(float frameRate, int8_t compatibility,
                                  int8_t changeFrameRateStrategy);
    virtual status_t setFrameTimelineInfo(const FrameTimelineInfo& info);
    virtual status_t getExtraBufferCount(int* extraBuffers) const;

protected:
    virtual ~Surface();
@@ -278,7 +277,6 @@ private:
    int dispatchGetLastQueuedBuffer(va_list args);
    int dispatchGetLastQueuedBuffer2(va_list args);
    int dispatchSetFrameTimelineInfo(va_list args);
    int dispatchGetExtraBufferCount(va_list args);

protected:
    virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
Loading