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

Commit 595264f1 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

BufferQueue improvements and APIs changes

this is the first step of a series of improvements to
BufferQueue. A few things happen in this change:

- setSynchronousMode() goes away as well as the SynchronousModeAllowed flag
- BufferQueue now defaults to (what used to be) synchronous mode
- a new "controlled by app" flag is passed when creating consumers and producers
  those flags are used to put the BufferQueue in a mode where it
  will never block if both flags are set. This is achieved by:
  - returning an error from dequeueBuffer() if it would block
  - making sure a buffer is always available by replacing
    the previous buffer with the new one in queueBuffer()
    (note: this is similar to what asynchrnous mode used to be)

Note: in this change EGL's swap-interval 0 is broken; this will be
fixed in another change.

Change-Id: I691f9507d6e2e158287e3039f2a79a4d4434211d
parent 1962f651
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ bool GLHelper::getShaderProgram(const char* name, GLuint* outPgm) {

bool GLHelper::createNamedSurfaceTexture(GLuint name, uint32_t w, uint32_t h,
        sp<GLConsumer>* glConsumer, EGLSurface* surface) {
    sp<BufferQueue> bq = new BufferQueue(true, mGraphicBufferAlloc);
    sp<BufferQueue> bq = new BufferQueue(mGraphicBufferAlloc);
    sp<GLConsumer> glc = new GLConsumer(bq, name,
            GL_TEXTURE_EXTERNAL_OES, false);
    glc->setDefaultBufferSize(w, h);
+3 −1
Original line number Diff line number Diff line
@@ -51,9 +51,11 @@ class BufferItemConsumer: public ConsumerBase
    // the consumer usage flags passed to the graphics allocator. The
    // bufferCount parameter specifies how many buffers can be locked for user
    // access at the same time.
    // controlledByApp tells whether this consumer is controlled by the
    // application.
    BufferItemConsumer(const sp<BufferQueue>& bq, uint32_t consumerUsage,
            int bufferCount = BufferQueue::MIN_UNDEQUEUED_BUFFERS,
            bool synchronousMode = false);
            bool controlledByApp = false);

    virtual ~BufferItemConsumer();

+16 −24
Original line number Diff line number Diff line
@@ -97,11 +97,9 @@ public:


    // BufferQueue manages a pool of gralloc memory slots to be used by
    // producers and consumers. allowSynchronousMode specifies whether or not
    // synchronous mode can be enabled by the producer. allocator is used to
    // allocate all the needed gralloc buffers.
    BufferQueue(bool allowSynchronousMode = true,
            const sp<IGraphicBufferAlloc>& allocator = NULL);
    // producers and consumers. allocator is used to allocate all the
    // needed gralloc buffers.
    BufferQueue(const sp<IGraphicBufferAlloc>& allocator = NULL);
    virtual ~BufferQueue();

    // Query native window attributes.  The "what" values are enumerated in
@@ -197,15 +195,6 @@ public:
    // will usually be the one obtained from dequeueBuffer.
    virtual void cancelBuffer(int buf, const sp<Fence>& fence);

    // setSynchronousMode sets whether dequeueBuffer is synchronous or
    // asynchronous. In synchronous mode, dequeueBuffer blocks until
    // a buffer is available, the currently bound buffer can be dequeued and
    // queued buffers will be acquired in order.  In asynchronous mode,
    // a queued buffer may be replaced by a subsequently queued buffer.
    //
    // The default mode is asynchronous.
    virtual status_t setSynchronousMode(bool enabled);

    // connect attempts to connect a producer API to the BufferQueue.  This
    // must be called before any other IGraphicBufferProducer methods are
    // called except for getAllocator.  A consumer must already be connected.
@@ -215,7 +204,7 @@ public:
    // it's still connected to a producer).
    //
    // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU).
    virtual status_t connect(int api, QueueBufferOutput* output);
    virtual status_t connect(int api, bool producerControlledByApp, QueueBufferOutput* output);

    // disconnect attempts to disconnect a producer API from the BufferQueue.
    // Calling this method will cause any subsequent calls to other
@@ -312,9 +301,11 @@ public:
    // consumer may be connected, and when that consumer disconnects the
    // BufferQueue is placed into the "abandoned" state, causing most
    // interactions with the BufferQueue by the producer to fail.
    // controlledByApp indicates whether the consumer is controlled by
    // the application.
    //
    // consumer may not be NULL.
    status_t consumerConnect(const sp<ConsumerListener>& consumer);
    status_t consumerConnect(const sp<ConsumerListener>& consumer, bool controlledByApp);

    // consumerDisconnect disconnects a consumer from the BufferQueue. All
    // buffers will be freed and the BufferQueue is placed in the "abandoned"
@@ -347,10 +338,6 @@ public:
    // fail if a producer is connected to the BufferQueue.
    status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers);

    // isSynchronousMode returns whether the BufferQueue is currently in
    // synchronous mode.
    bool isSynchronousMode() const;

    // setConsumerName sets the name used in logging
    void setConsumerName(const String8& name);

@@ -568,13 +555,18 @@ private:
    // to NULL and is written by consumerConnect and consumerDisconnect.
    sp<ConsumerListener> mConsumerListener;

    // mConsumerControlledByApp whether the connected consumer is controlled by the
    // application.
    bool mConsumerControlledByApp;

    // mDequeueBufferCannotBlock whether dequeueBuffer() isn't allowed to block.
    // this flag is set durring connect() when both consumer and producer are controlled
    // by the application.
    bool mDequeueBufferCannotBlock;

    // mSynchronousMode whether we're in synchronous mode or not
    bool mSynchronousMode;

    // mAllowSynchronousMode whether we allow synchronous mode or not.  Set
    // when the BufferQueue is created (by the consumer).
    const bool mAllowSynchronousMode;

    // mConnectedApi indicates the producer API that is currently connected
    // to this BufferQueue.  It defaults to NO_CONNECTED_API (= 0), and gets
    // updated by the connect and disconnect methods.
+3 −1
Original line number Diff line number Diff line
@@ -87,7 +87,9 @@ protected:

    // ConsumerBase constructs a new ConsumerBase object to consume image
    // buffers from the given BufferQueue.
    ConsumerBase(const sp<BufferQueue> &bufferQueue);
    // The controlledByApp flag indicates that this consumer is under the application's
    // control.
    ConsumerBase(const sp<BufferQueue> &bufferQueue, bool controlledByApp = false);

    // onLastStrongRef gets called by RefBase just before the dtor of the most
    // derived class.  It is used to clean up the buffers so that ConsumerBase
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ class CpuConsumer : public ConsumerBase
    // Create a new CPU consumer. The maxLockedBuffers parameter specifies
    // how many buffers can be locked for user access at the same time.
    CpuConsumer(const sp<BufferQueue>& bq,
            uint32_t maxLockedBuffers, bool synchronousMode = true);
            uint32_t maxLockedBuffers, bool controlledByApp = false);

    virtual ~CpuConsumer();

Loading