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

Commit 82110471 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

DO NOT MERGE ANYWHERE: BufferQueue consumers: Add discardFreeBuffer method

This method releases all free buffers owned by the buffer queue,
in order to save memory (at the cost of potential future
reallocation of buffers).

Bug: 28695173
Change-Id: I458d10373e639e3144faf673af2ba01aca36e65a
parent 083f4ecc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -136,6 +136,9 @@ public:
    // Retrieve the sideband buffer stream, if any.
    virtual sp<NativeHandle> getSidebandStream() const;

    // See IGraphicBufferConsumer::discardFreeBuffers
    virtual status_t discardFreeBuffers() override;

    // dump our state in a String
    virtual void dump(String8& result, const char* prefix) const;

+5 −0
Original line number Diff line number Diff line
@@ -124,6 +124,11 @@ private:
    // all slots, even if they're currently dequeued, queued, or acquired.
    void freeAllBuffersLocked();

    // discardFreeBuffersLocked releases all currently-free buffers held by the
    // queue, in order to reduce the memory consumption of the queue to the
    // minimum possible without discarding data.
    void discardFreeBuffersLocked();

    // If delta is positive, makes more slots available. If negative, takes
    // away slots. Returns false if the request can't be met.
    bool adjustAvailableSlotsLocked(int delta);
+3 −0
Original line number Diff line number Diff line
@@ -85,6 +85,9 @@ public:
    // See IGraphicBufferConsumer::setDefaultBufferDataSpace
    status_t setDefaultBufferDataSpace(android_dataspace defaultDataSpace);

    // See IGraphicBufferConsumer::discardFreeBuffers
    status_t discardFreeBuffers();

private:
    ConsumerBase(const ConsumerBase&);
    void operator=(const ConsumerBase&);
+5 −0
Original line number Diff line number Diff line
@@ -265,6 +265,11 @@ public:
    // Retrieve the sideband buffer stream, if any.
    virtual sp<NativeHandle> getSidebandStream() const = 0;

    // discardFreeBuffers releases all currently-free buffers held by the queue,
    // in order to reduce the memory consumption of the queue to the minimum
    // possible without discarding data.
    virtual status_t discardFreeBuffers() = 0;

    // dump state into a string
    virtual void dump(String8& result, const char* prefix) const = 0;

+6 −0
Original line number Diff line number Diff line
@@ -717,6 +717,12 @@ sp<NativeHandle> BufferQueueConsumer::getSidebandStream() const {
    return mCore->mSidebandStream;
}

status_t BufferQueueConsumer::discardFreeBuffers() {
    Mutex::Autolock lock(mCore->mMutex);
    mCore->discardFreeBuffersLocked();
    return NO_ERROR;
}

void BufferQueueConsumer::dump(String8& result, const char* prefix) const {
    const IPCThreadState* ipc = IPCThreadState::self();
    const pid_t pid = ipc->getCallingPid();
Loading