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

Commit 8dc55396 authored by Dan Stoza's avatar Dan Stoza
Browse files

Add a BufferItem parameter to onFrameAvailable

Passes the BufferItem for the queued buffer to the onFrameAvailable
callback so the consumer can track the BufferQueue's contents. Also
adds an onFrameReplaced callback, which is necessary if the consumer
wants to do anything more than simple queue length tracking.

Bug: 18111837
Change-Id: If9d07229c9b586c668e5f99074e9b63b0468feb0
parent 793fc0e1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ class BufferItem : public Flattenable<BufferItem> {
    // The default value of mBuf, used to indicate this doesn't correspond to a slot.
    enum { INVALID_BUFFER_SLOT = -1 };
    BufferItem();
    ~BufferItem();
    operator IGraphicBufferConsumer::BufferItem() const;

    static const char* scalingModeName(uint32_t scalingMode);
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public:
    public:
        ProxyConsumerListener(const wp<ConsumerListener>& consumerListener);
        virtual ~ProxyConsumerListener();
        virtual void onFrameAvailable();
        virtual void onFrameAvailable(const android::BufferItem& item);
        virtual void onBuffersReleased();
        virtual void onSidebandStreamChanged();
    private:
+10 −0
Original line number Diff line number Diff line
@@ -203,6 +203,16 @@ private:
    // since the previous buffer might have already been acquired.
    sp<Fence> mLastQueueBufferFence;

    // Take-a-ticket system for ensuring that onFrame* callbacks are called in
    // the order that frames are queued. While the BufferQueue lock
    // (mCore->mMutex) is held, a ticket is retained by the producer. After
    // dropping the BufferQueue lock, the producer must wait on the condition
    // variable until the current callback ticket matches its retained ticket.
    Mutex mCallbackMutex;
    int mNextCallbackTicket; // Protected by mCore->mMutex
    int mCurrentCallbackTicket; // Protected by mCallbackMutex
    Condition mCallbackCondition;

}; // class BufferQueueProducer

} // namespace android
+2 −2
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public:
        //
        // This is called without any lock held and can be called concurrently
        // by multiple threads.
        virtual void onFrameAvailable() = 0;
        virtual void onFrameAvailable(const BufferItem& item) = 0;
    };

    virtual ~ConsumerBase();
@@ -106,7 +106,7 @@ protected:
    // the ConsumerBase implementation must be called from the derived class.
    // The ConsumerBase version of onSidebandStreamChanged does nothing and can
    // be overriden by derived classes if they want the notification.
    virtual void onFrameAvailable();
    virtual void onFrameAvailable(const BufferItem& item);
    virtual void onBuffersReleased();
    virtual void onSidebandStreamChanged();

+17 −2
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@
namespace android {
// ----------------------------------------------------------------------------

class BufferItem;

// ConsumerListener is the interface through which the BufferQueue notifies
// the consumer of events that the consumer may wish to react to.  Because
// the consumer will generally have a mutex that is locked during calls from
@@ -43,11 +45,24 @@ public:
    // frame becomes available for consumption. This means that frames that
    // are queued while in asynchronous mode only trigger the callback if no
    // previous frames are pending. Frames queued while in synchronous mode
    // always trigger the callback.
    // always trigger the callback. The item passed to the callback will contain
    // all of the information about the queued frame except for its
    // GraphicBuffer pointer, which will always be null.
    //
    // This is called without any lock held and can be called concurrently
    // by multiple threads.
    virtual void onFrameAvailable(const BufferItem& item) = 0; /* Asynchronous */

    // onFrameReplaced is called from queueBuffer if the frame being queued is
    // replacing an existing slot in the queue. Any call to queueBuffer that
    // doesn't call onFrameAvailable will call this callback instead. The item
    // passed to the callback will contain all of the information about the
    // queued frame except for its GraphicBuffer pointer, which will always be
    // null.
    //
    // This is called without any lock held and can be called concurrently
    // by multiple threads.
    virtual void onFrameAvailable() = 0; /* Asynchronous */
    virtual void onFrameReplaced(const BufferItem& item) {} /* Asynchronous */

    // onBuffersReleased is called to notify the buffer consumer that the
    // BufferQueue has released its references to one or more GraphicBuffers
Loading