BufferQueue.h revision c68f2ecfa02037144d1a3856f637a77f523cf416
19ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat/*
29ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat * Copyright (C) 2012 The Android Open Source Project
39ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat *
49ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat * Licensed under the Apache License, Version 2.0 (the "License");
59ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat * you may not use this file except in compliance with the License.
69ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat * You may obtain a copy of the License at
79ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat *
89ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat *      http://www.apache.org/licenses/LICENSE-2.0
99ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat *
109ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat * Unless required by applicable law or agreed to in writing, software
119ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat * distributed under the License is distributed on an "AS IS" BASIS,
129ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat * See the License for the specific language governing permissions and
149ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat * limitations under the License.
159ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat */
169ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat
179ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat#ifndef ANDROID_GUI_BUFFERQUEUE_H
189ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat#define ANDROID_GUI_BUFFERQUEUE_H
199ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat
209ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat#include <EGL/egl.h>
219ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat#include <EGL/eglext.h>
22fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
23fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt#include <gui/IGraphicBufferAlloc.h>
249ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat#include <gui/ISurfaceTexture.h>
259ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat
269ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat#include <ui/Fence.h>
27fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt#include <ui/GraphicBuffer.h>
289ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat
299ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat#include <utils/String8.h>
30fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt#include <utils/Vector.h>
31fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt#include <utils/threads.h>
320031cead820149e2fe3ccb3cc2fe05758a3cb5c2JP Abgrall
339ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehatnamespace android {
348e188ed5c989ddcc07f0f5e9839493c22d17e7b6Jeff Sharkey// ----------------------------------------------------------------------------
358e188ed5c989ddcc07f0f5e9839493c22d17e7b6Jeff Sharkey
368e188ed5c989ddcc07f0f5e9839493c22d17e7b6Jeff Sharkeyclass BufferQueue : public BnSurfaceTexture {
379ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehatpublic:
381caafe66a6b927fa5d8eb4c59ec9eb48b0b1b075Robert Greenwalt    enum { MIN_UNDEQUEUED_BUFFERS = 2 };
39fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    enum { NUM_BUFFER_SLOTS = 32 };
401caafe66a6b927fa5d8eb4c59ec9eb48b0b1b075Robert Greenwalt    enum { NO_CONNECTED_API = 0 };
419ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat    enum { INVALID_BUFFER_SLOT = -1 };
42fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE };
43fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt
44fc97b82e02979f246d56a4bfd60e4aab8686d3f6Robert Greenwalt    // When in async mode we reserve two slots in order to guarantee that the
459ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat    // producer and consumer can run asynchronously.
469ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat    enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 };
479ff78fb7da7158f5bd7c86d89a842691820259cfSan Mehat
48    // ConsumerListener is the interface through which the BufferQueue notifies
49    // the consumer of events that the consumer may wish to react to.  Because
50    // the consumer will generally have a mutex that is locked during calls from
51    // teh consumer to the BufferQueue, these calls from the BufferQueue to the
52    // consumer *MUST* be called only when the BufferQueue mutex is NOT locked.
53    struct ConsumerListener : public virtual RefBase {
54        // onFrameAvailable is called from queueBuffer each time an additional
55        // frame becomes available for consumption. This means that frames that
56        // are queued while in asynchronous mode only trigger the callback if no
57        // previous frames are pending. Frames queued while in synchronous mode
58        // always trigger the callback.
59        //
60        // This is called without any lock held and can be called concurrently
61        // by multiple threads.
62        virtual void onFrameAvailable() = 0;
63
64        // onBuffersReleased is called to notify the buffer consumer that the
65        // BufferQueue has released its references to one or more GraphicBuffers
66        // contained in its slots.  The buffer consumer should then call
67        // BufferQueue::getReleasedBuffers to retrieve the list of buffers
68        //
69        // This is called without any lock held and can be called concurrently
70        // by multiple threads.
71        virtual void onBuffersReleased() = 0;
72    };
73
74    // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak
75    // reference to the actual consumer object.  It forwards all calls to that
76    // consumer object so long as it exists.
77    //
78    // This class exists to avoid having a circular reference between the
79    // BufferQueue object and the consumer object.  The reason this can't be a weak
80    // reference in the BufferQueue class is because we're planning to expose the
81    // consumer side of a BufferQueue as a binder interface, which doesn't support
82    // weak references.
83    class ProxyConsumerListener : public BufferQueue::ConsumerListener {
84    public:
85
86        ProxyConsumerListener(const wp<BufferQueue::ConsumerListener>& consumerListener);
87        virtual ~ProxyConsumerListener();
88        virtual void onFrameAvailable();
89        virtual void onBuffersReleased();
90
91    private:
92
93        // mConsumerListener is a weak reference to the ConsumerListener.  This is
94        // the raison d'etre of ProxyConsumerListener.
95        wp<BufferQueue::ConsumerListener> mConsumerListener;
96    };
97
98
99    // BufferQueue manages a pool of gralloc memory slots to be used by
100    // producers and consumers. allowSynchronousMode specifies whether or not
101    // synchronous mode can be enabled by the producer. allocator is used to
102    // allocate all the needed gralloc buffers.
103    BufferQueue(bool allowSynchronousMode = true,
104            const sp<IGraphicBufferAlloc>& allocator = NULL);
105    virtual ~BufferQueue();
106
107    virtual int query(int what, int* value);
108
109    // setBufferCount updates the number of available buffer slots.  After
110    // calling this all buffer slots are both unallocated and owned by the
111    // BufferQueue object (i.e. they are not owned by the client).
112    virtual status_t setBufferCount(int bufferCount);
113
114    virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
115
116    // dequeueBuffer gets the next buffer slot index for the client to use. If a
117    // buffer slot is available then that slot index is written to the location
118    // pointed to by the buf argument and a status of OK is returned.  If no
119    // slot is available then a status of -EBUSY is returned and buf is
120    // unmodified.
121    //
122    // The fence parameter will be updated to hold the fence associated with
123    // the buffer. The contents of the buffer must not be overwritten until the
124    // fence signals. If the fence is NULL, the buffer may be written
125    // immediately.
126    //
127    // The width and height parameters must be no greater than the minimum of
128    // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
129    // An error due to invalid dimensions might not be reported until
130    // updateTexImage() is called.
131    virtual status_t dequeueBuffer(int *buf, sp<Fence>& fence,
132            uint32_t width, uint32_t height, uint32_t format, uint32_t usage);
133
134    // queueBuffer returns a filled buffer to the BufferQueue. In addition, a
135    // timestamp must be provided for the buffer. The timestamp is in
136    // nanoseconds, and must be monotonically increasing. Its other semantics
137    // (zero point, etc) are client-dependent and should be documented by the
138    // client.
139    virtual status_t queueBuffer(int buf,
140            const QueueBufferInput& input, QueueBufferOutput* output);
141
142    virtual void cancelBuffer(int buf, sp<Fence> fence);
143
144    // setSynchronousMode set whether dequeueBuffer is synchronous or
145    // asynchronous. In synchronous mode, dequeueBuffer blocks until
146    // a buffer is available, the currently bound buffer can be dequeued and
147    // queued buffers will be retired in order.
148    // The default mode is asynchronous.
149    virtual status_t setSynchronousMode(bool enabled);
150
151    // connect attempts to connect a producer client API to the BufferQueue.
152    // This must be called before any other ISurfaceTexture methods are called
153    // except for getAllocator.
154    //
155    // This method will fail if the connect was previously called on the
156    // BufferQueue and no corresponding disconnect call was made.
157    virtual status_t connect(int api, QueueBufferOutput* output);
158
159    // disconnect attempts to disconnect a producer client API from the
160    // BufferQueue. Calling this method will cause any subsequent calls to other
161    // ISurfaceTexture methods to fail except for getAllocator and connect.
162    // Successfully calling connect after this will allow the other methods to
163    // succeed again.
164    //
165    // This method will fail if the the BufferQueue is not currently
166    // connected to the specified client API.
167    virtual status_t disconnect(int api);
168
169    // dump our state in a String
170    virtual void dump(String8& result) const;
171    virtual void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
172
173    // public facing structure for BufferSlot
174    struct BufferItem {
175
176        BufferItem()
177         :
178           mTransform(0),
179           mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
180           mTimestamp(0),
181           mFrameNumber(0),
182           mBuf(INVALID_BUFFER_SLOT) {
183             mCrop.makeInvalid();
184         }
185        // mGraphicBuffer points to the buffer allocated for this slot or is NULL
186        // if no buffer has been allocated.
187        sp<GraphicBuffer> mGraphicBuffer;
188
189        // mCrop is the current crop rectangle for this buffer slot.
190        Rect mCrop;
191
192        // mTransform is the current transform flags for this buffer slot.
193        uint32_t mTransform;
194
195        // mScalingMode is the current scaling mode for this buffer slot.
196        uint32_t mScalingMode;
197
198        // mTimestamp is the current timestamp for this buffer slot. This gets
199        // to set by queueBuffer each time this slot is queued.
200        int64_t mTimestamp;
201
202        // mFrameNumber is the number of the queued frame for this slot.
203        uint64_t mFrameNumber;
204
205        // mBuf is the slot index of this buffer
206        int mBuf;
207
208        // mFence is a fence that will signal when the buffer is idle.
209        sp<Fence> mFence;
210    };
211
212    // The following public functions is the consumer facing interface
213
214    // acquireBuffer attempts to acquire ownership of the next pending buffer in
215    // the BufferQueue.  If no buffer is pending then it returns -EINVAL.  If a
216    // buffer is successfully acquired, the information about the buffer is
217    // returned in BufferItem.  If the buffer returned had previously been
218    // acquired then the BufferItem::mGraphicBuffer field of buffer is set to
219    // NULL and it is assumed that the consumer still holds a reference to the
220    // buffer.
221    status_t acquireBuffer(BufferItem *buffer);
222
223    // releaseBuffer releases a buffer slot from the consumer back to the
224    // BufferQueue pending a fence sync.
225    //
226    // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
227    // any references to the just-released buffer that it might have, as if it
228    // had received a onBuffersReleased() call with a mask set for the released
229    // buffer.
230    //
231    // Note that the dependencies on EGL will be removed once we switch to using
232    // the Android HW Sync HAL.
233    status_t releaseBuffer(int buf, EGLDisplay display, EGLSyncKHR fence,
234            const sp<Fence>& releaseFence);
235
236    // consumerConnect connects a consumer to the BufferQueue.  Only one
237    // consumer may be connected, and when that consumer disconnects the
238    // BufferQueue is placed into the "abandoned" state, causing most
239    // interactions with the BufferQueue by the producer to fail.
240    status_t consumerConnect(const sp<ConsumerListener>& consumer);
241
242    // consumerDisconnect disconnects a consumer from the BufferQueue. All
243    // buffers will be freed and the BufferQueue is placed in the "abandoned"
244    // state, causing most interactions with the BufferQueue by the producer to
245    // fail.
246    status_t consumerDisconnect();
247
248    // getReleasedBuffers sets the value pointed to by slotMask to a bit mask
249    // indicating which buffer slots the have been released by the BufferQueue
250    // but have not yet been released by the consumer.
251    status_t getReleasedBuffers(uint32_t* slotMask);
252
253    // setDefaultBufferSize is used to set the size of buffers returned by
254    // requestBuffers when a with and height of zero is requested.
255    status_t setDefaultBufferSize(uint32_t w, uint32_t h);
256
257    // setDefaultBufferCount set the buffer count. If the client has requested
258    // a buffer count using setBufferCount, the server-buffer count will
259    // take effect once the client sets the count back to zero.
260    status_t setDefaultMaxBufferCount(int bufferCount);
261
262    // setMaxAcquiredBufferCount sets the maximum number of buffers that can
263    // be acquired by the consumer at one time.  This call will fail if a
264    // producer is connected to the BufferQueue.
265    status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers);
266
267    // isSynchronousMode returns whether the SurfaceTexture is currently in
268    // synchronous mode.
269    bool isSynchronousMode() const;
270
271    // setConsumerName sets the name used in logging
272    void setConsumerName(const String8& name);
273
274    // setDefaultBufferFormat allows the BufferQueue to create
275    // GraphicBuffers of a defaultFormat if no format is specified
276    // in dequeueBuffer
277    status_t setDefaultBufferFormat(uint32_t defaultFormat);
278
279    // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer
280    status_t setConsumerUsageBits(uint32_t usage);
281
282    // setTransformHint bakes in rotation to buffers so overlays can be used
283    status_t setTransformHint(uint32_t hint);
284
285private:
286    // freeBufferLocked frees the resources (both GraphicBuffer and EGLImage)
287    // for the given slot.
288    void freeBufferLocked(int index);
289
290    // freeAllBuffersLocked frees the resources (both GraphicBuffer and
291    // EGLImage) for all slots.
292    void freeAllBuffersLocked();
293
294    // freeAllBuffersExceptHeadLocked frees the resources (both GraphicBuffer
295    // and EGLImage) for all slots except the head of mQueue
296    void freeAllBuffersExceptHeadLocked();
297
298    // drainQueueLocked drains the buffer queue if we're in synchronous mode
299    // returns immediately otherwise. It returns NO_INIT if the BufferQueue
300    // became abandoned or disconnected during this call.
301    status_t drainQueueLocked();
302
303    // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in
304    // synchronous mode and free all buffers. In asynchronous mode, all buffers
305    // are freed except the current buffer.
306    status_t drainQueueAndFreeBuffersLocked();
307
308    // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots
309    // that will be used if the producer does not override the buffer slot
310    // count.
311    status_t setDefaultMaxBufferCountLocked(int count);
312
313    // getMinBufferCountLocked returns the minimum number of buffers allowed
314    // given the current BufferQueue state.
315    int getMinMaxBufferCountLocked() const;
316
317    // getMinUndequeuedBufferCountLocked returns the minimum number of buffers
318    // that must remain in a state other than DEQUEUED.
319    int getMinUndequeuedBufferCountLocked() const;
320
321    // getMaxBufferCountLocked returns the maximum number of buffers that can
322    // be allocated at once.  This value depends upon the following member
323    // variables:
324    //
325    //      mSynchronousMode
326    //      mMaxAcquiredBufferCount
327    //      mDefaultMaxBufferCount
328    //      mOverrideMaxBufferCount
329    //
330    // Any time one of these member variables is changed while a producer is
331    // connected, mDequeueCondition must be broadcast.
332    int getMaxBufferCountLocked() const;
333
334    struct BufferSlot {
335
336        BufferSlot()
337        : mEglDisplay(EGL_NO_DISPLAY),
338          mBufferState(BufferSlot::FREE),
339          mRequestBufferCalled(false),
340          mTransform(0),
341          mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
342          mTimestamp(0),
343          mFrameNumber(0),
344          mEglFence(EGL_NO_SYNC_KHR),
345          mAcquireCalled(false),
346          mNeedsCleanupOnRelease(false) {
347            mCrop.makeInvalid();
348        }
349
350        // mGraphicBuffer points to the buffer allocated for this slot or is NULL
351        // if no buffer has been allocated.
352        sp<GraphicBuffer> mGraphicBuffer;
353
354        // mEglDisplay is the EGLDisplay used to create mEglImage.
355        EGLDisplay mEglDisplay;
356
357        // BufferState represents the different states in which a buffer slot
358        // can be.
359        enum BufferState {
360            // FREE indicates that the buffer is not currently being used and
361            // will not be used in the future until it gets dequeued and
362            // subsequently queued by the client.
363            // aka "owned by BufferQueue, ready to be dequeued"
364            FREE = 0,
365
366            // DEQUEUED indicates that the buffer has been dequeued by the
367            // client, but has not yet been queued or canceled. The buffer is
368            // considered 'owned' by the client, and the server should not use
369            // it for anything.
370            //
371            // Note that when in synchronous-mode (mSynchronousMode == true),
372            // the buffer that's currently attached to the texture may be
373            // dequeued by the client.  That means that the current buffer can
374            // be in either the DEQUEUED or QUEUED state.  In asynchronous mode,
375            // however, the current buffer is always in the QUEUED state.
376            // aka "owned by producer, ready to be queued"
377            DEQUEUED = 1,
378
379            // QUEUED indicates that the buffer has been queued by the client,
380            // and has not since been made available for the client to dequeue.
381            // Attaching the buffer to the texture does NOT transition the
382            // buffer away from the QUEUED state. However, in Synchronous mode
383            // the current buffer may be dequeued by the client under some
384            // circumstances. See the note about the current buffer in the
385            // documentation for DEQUEUED.
386            // aka "owned by BufferQueue, ready to be acquired"
387            QUEUED = 2,
388
389            // aka "owned by consumer, ready to be released"
390            ACQUIRED = 3
391        };
392
393        // mBufferState is the current state of this buffer slot.
394        BufferState mBufferState;
395
396        // mRequestBufferCalled is used for validating that the client did
397        // call requestBuffer() when told to do so. Technically this is not
398        // needed but useful for debugging and catching client bugs.
399        bool mRequestBufferCalled;
400
401        // mCrop is the current crop rectangle for this buffer slot.
402        Rect mCrop;
403
404        // mTransform is the current transform flags for this buffer slot.
405        uint32_t mTransform;
406
407        // mScalingMode is the current scaling mode for this buffer slot.
408        uint32_t mScalingMode;
409
410        // mTimestamp is the current timestamp for this buffer slot. This gets
411        // to set by queueBuffer each time this slot is queued.
412        int64_t mTimestamp;
413
414        // mFrameNumber is the number of the queued frame for this slot.
415        uint64_t mFrameNumber;
416
417        // mEglFence is the EGL sync object that must signal before the buffer
418        // associated with this buffer slot may be dequeued. It is initialized
419        // to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
420        // on a compile-time option) set to a new sync object in updateTexImage.
421        EGLSyncKHR mEglFence;
422
423        // mFence is a fence which will signal when work initiated by the
424        // previous owner of the buffer is finished. When the buffer is FREE,
425        // the fence indicates when the consumer has finished reading
426        // from the buffer, or when the producer has finished writing if it
427        // called cancelBuffer after queueing some writes. When the buffer is
428        // QUEUED, it indicates when the producer has finished filling the
429        // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been
430        // passed to the consumer or producer along with ownership of the
431        // buffer, and mFence is empty.
432        sp<Fence> mFence;
433
434        // Indicates whether this buffer has been seen by a consumer yet
435        bool mAcquireCalled;
436
437        // Indicates whether this buffer needs to be cleaned up by consumer
438        bool mNeedsCleanupOnRelease;
439    };
440
441    // mSlots is the array of buffer slots that must be mirrored on the client
442    // side. This allows buffer ownership to be transferred between the client
443    // and server without sending a GraphicBuffer over binder. The entire array
444    // is initialized to NULL at construction time, and buffers are allocated
445    // for a slot when requestBuffer is called with that slot's index.
446    BufferSlot mSlots[NUM_BUFFER_SLOTS];
447
448    // mDefaultWidth holds the default width of allocated buffers. It is used
449    // in requestBuffers() if a width and height of zero is specified.
450    uint32_t mDefaultWidth;
451
452    // mDefaultHeight holds the default height of allocated buffers. It is used
453    // in requestBuffers() if a width and height of zero is specified.
454    uint32_t mDefaultHeight;
455
456    // mMaxAcquiredBufferCount is the number of buffers that the consumer may
457    // acquire at one time.  It defaults to 1 and can be changed by the
458    // consumer via the setMaxAcquiredBufferCount method, but this may only be
459    // done when no producer is connected to the BufferQueue.
460    //
461    // This value is used to derive the value returned for the
462    // MIN_UNDEQUEUED_BUFFERS query by the producer.
463    int mMaxAcquiredBufferCount;
464
465    // mDefaultMaxBufferCount is the default limit on the number of buffers
466    // that will be allocated at one time.  This default limit is set by the
467    // consumer.  The limit (as opposed to the default limit) may be
468    // overridden by the producer.
469    int mDefaultMaxBufferCount;
470
471    // mOverrideMaxBufferCount is the limit on the number of buffers that will
472    // be allocated at one time. This value is set by the image producer by
473    // calling setBufferCount. The default is zero, which means the producer
474    // doesn't care about the number of buffers in the pool. In that case
475    // mDefaultMaxBufferCount is used as the limit.
476    int mOverrideMaxBufferCount;
477
478    // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
479    // allocate new GraphicBuffer objects.
480    sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
481
482    // mConsumerListener is used to notify the connected consumer of
483    // asynchronous events that it may wish to react to.  It is initially set
484    // to NULL and is written by consumerConnect and consumerDisconnect.
485    sp<ConsumerListener> mConsumerListener;
486
487    // mSynchronousMode whether we're in synchronous mode or not
488    bool mSynchronousMode;
489
490    // mAllowSynchronousMode whether we allow synchronous mode or not
491    const bool mAllowSynchronousMode;
492
493    // mConnectedApi indicates the API that is currently connected to this
494    // BufferQueue.  It defaults to NO_CONNECTED_API (= 0), and gets updated
495    // by the connect and disconnect methods.
496    int mConnectedApi;
497
498    // mDequeueCondition condition used for dequeueBuffer in synchronous mode
499    mutable Condition mDequeueCondition;
500
501    // mQueue is a FIFO of queued buffers used in synchronous mode
502    typedef Vector<int> Fifo;
503    Fifo mQueue;
504
505    // mAbandoned indicates that the BufferQueue will no longer be used to
506    // consume images buffers pushed to it using the ISurfaceTexture interface.
507    // It is initialized to false, and set to true in the abandon method.  A
508    // BufferQueue that has been abandoned will return the NO_INIT error from
509    // all ISurfaceTexture methods capable of returning an error.
510    bool mAbandoned;
511
512    // mName is a string used to identify the BufferQueue in log messages.
513    // It is set by the setName method.
514    String8 mConsumerName;
515
516    // mMutex is the mutex used to prevent concurrent access to the member
517    // variables of BufferQueue objects. It must be locked whenever the
518    // member variables are accessed.
519    mutable Mutex mMutex;
520
521    // mFrameCounter is the free running counter, incremented for every buffer queued
522    // with the surface Texture.
523    uint64_t mFrameCounter;
524
525    // mBufferHasBeenQueued is true once a buffer has been queued.  It is reset
526    // by changing the buffer count.
527    bool mBufferHasBeenQueued;
528
529    // mDefaultBufferFormat can be set so it will override
530    // the buffer format when it isn't specified in dequeueBuffer
531    uint32_t mDefaultBufferFormat;
532
533    // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers
534    uint32_t mConsumerUsageBits;
535
536    // mTransformHint is used to optimize for screen rotations
537    uint32_t mTransformHint;
538};
539
540// ----------------------------------------------------------------------------
541}; // namespace android
542
543#endif // ANDROID_GUI_BUFFERQUEUE_H
544