blob: e7fac3de66531e8e2156789fa70837c62207bc03 [file] [log] [blame]
Daniel Lam6b091c52012-01-22 15:26:27 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_GUI_BUFFERQUEUE_H
18#define ANDROID_GUI_BUFFERQUEUE_H
19
20#include <EGL/egl.h>
Daniel Lamf71c4ae2012-03-23 18:12:04 -070021#include <EGL/eglext.h>
Daniel Lam6b091c52012-01-22 15:26:27 -080022
Mathias Agopian90ac7992012-02-25 18:48:35 -080023#include <gui/IGraphicBufferAlloc.h>
Daniel Lam6b091c52012-01-22 15:26:27 -080024#include <gui/ISurfaceTexture.h>
25
Daniel Lam6b091c52012-01-22 15:26:27 -080026#include <ui/GraphicBuffer.h>
27
28#include <utils/String8.h>
29#include <utils/Vector.h>
30#include <utils/threads.h>
31
32namespace android {
33// ----------------------------------------------------------------------------
34
35class BufferQueue : public BnSurfaceTexture {
36public:
37 enum { MIN_UNDEQUEUED_BUFFERS = 2 };
Daniel Lam6b091c52012-01-22 15:26:27 -080038 enum { NUM_BUFFER_SLOTS = 32 };
39 enum { NO_CONNECTED_API = 0 };
Daniel Lameae59d22012-01-22 15:26:27 -080040 enum { INVALID_BUFFER_SLOT = -1 };
Daniel Lamfbcda932012-04-09 22:51:52 -070041 enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE };
Daniel Lam6b091c52012-01-22 15:26:27 -080042
Jamie Gennisfa5b40e2012-03-15 14:01:24 -070043 // ConsumerListener is the interface through which the BufferQueue notifies
44 // the consumer of events that the consumer may wish to react to. Because
45 // the consumer will generally have a mutex that is locked during calls from
46 // teh consumer to the BufferQueue, these calls from the BufferQueue to the
47 // consumer *MUST* be called only when the BufferQueue mutex is NOT locked.
48 struct ConsumerListener : public virtual RefBase {
49 // onFrameAvailable is called from queueBuffer each time an additional
50 // frame becomes available for consumption. This means that frames that
51 // are queued while in asynchronous mode only trigger the callback if no
52 // previous frames are pending. Frames queued while in synchronous mode
53 // always trigger the callback.
Daniel Lam6b091c52012-01-22 15:26:27 -080054 //
55 // This is called without any lock held and can be called concurrently
56 // by multiple threads.
57 virtual void onFrameAvailable() = 0;
Jamie Gennisfa5b40e2012-03-15 14:01:24 -070058
59 // onBuffersReleased is called to notify the buffer consumer that the
60 // BufferQueue has released its references to one or more GraphicBuffers
61 // contained in its slots. The buffer consumer should then call
62 // BufferQueue::getReleasedBuffers to retrieve the list of buffers
63 //
64 // This is called without any lock held and can be called concurrently
65 // by multiple threads.
66 virtual void onBuffersReleased() = 0;
Daniel Lam6b091c52012-01-22 15:26:27 -080067 };
68
Jamie Gennisfa5b40e2012-03-15 14:01:24 -070069 // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak
70 // reference to the actual consumer object. It forwards all calls to that
71 // consumer object so long as it exists.
72 //
73 // This class exists to avoid having a circular reference between the
74 // BufferQueue object and the consumer object. The reason this can't be a weak
75 // reference in the BufferQueue class is because we're planning to expose the
76 // consumer side of a BufferQueue as a binder interface, which doesn't support
77 // weak references.
78 class ProxyConsumerListener : public BufferQueue::ConsumerListener {
79 public:
80
81 ProxyConsumerListener(const wp<BufferQueue::ConsumerListener>& consumerListener);
82 virtual ~ProxyConsumerListener();
83 virtual void onFrameAvailable();
84 virtual void onBuffersReleased();
85
86 private:
87
88 // mConsumerListener is a weak reference to the ConsumerListener. This is
89 // the raison d'etre of ProxyConsumerListener.
90 wp<BufferQueue::ConsumerListener> mConsumerListener;
91 };
92
93
Daniel Lam6b091c52012-01-22 15:26:27 -080094 // BufferQueue manages a pool of gralloc memory slots to be used
95 // by producers and consumers.
96 // allowSynchronousMode specifies whether or not synchronous mode can be
97 // enabled.
Daniel Lamabe61bf2012-03-26 20:37:15 -070098 // bufferCount sets the minimum number of undequeued buffers for this queue
99 BufferQueue( bool allowSynchronousMode = true, int bufferCount = MIN_UNDEQUEUED_BUFFERS);
Daniel Lam6b091c52012-01-22 15:26:27 -0800100 virtual ~BufferQueue();
101
Daniel Lamb8560522012-01-30 15:51:27 -0800102 virtual int query(int what, int* value);
103
Daniel Lam6b091c52012-01-22 15:26:27 -0800104 // setBufferCount updates the number of available buffer slots. After
105 // calling this all buffer slots are both unallocated and owned by the
106 // BufferQueue object (i.e. they are not owned by the client).
107 virtual status_t setBufferCount(int bufferCount);
108
109 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
110
111 // dequeueBuffer gets the next buffer slot index for the client to use. If a
112 // buffer slot is available then that slot index is written to the location
113 // pointed to by the buf argument and a status of OK is returned. If no
114 // slot is available then a status of -EBUSY is returned and buf is
115 // unmodified.
116 // The width and height parameters must be no greater than the minimum of
117 // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
118 // An error due to invalid dimensions might not be reported until
119 // updateTexImage() is called.
120 virtual status_t dequeueBuffer(int *buf, uint32_t width, uint32_t height,
121 uint32_t format, uint32_t usage);
122
123 // queueBuffer returns a filled buffer to the BufferQueue. In addition, a
124 // timestamp must be provided for the buffer. The timestamp is in
125 // nanoseconds, and must be monotonically increasing. Its other semantics
126 // (zero point, etc) are client-dependent and should be documented by the
127 // client.
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700128 virtual status_t queueBuffer(int buf,
129 const QueueBufferInput& input, QueueBufferOutput* output);
130
Daniel Lam6b091c52012-01-22 15:26:27 -0800131 virtual void cancelBuffer(int buf);
Daniel Lam6b091c52012-01-22 15:26:27 -0800132
133 // setSynchronousMode set whether dequeueBuffer is synchronous or
134 // asynchronous. In synchronous mode, dequeueBuffer blocks until
135 // a buffer is available, the currently bound buffer can be dequeued and
136 // queued buffers will be retired in order.
137 // The default mode is asynchronous.
138 virtual status_t setSynchronousMode(bool enabled);
139
140 // connect attempts to connect a producer client API to the BufferQueue.
141 // This must be called before any other ISurfaceTexture methods are called
142 // except for getAllocator.
143 //
144 // This method will fail if the connect was previously called on the
145 // BufferQueue and no corresponding disconnect call was made.
Mathias Agopian24202f52012-04-23 14:28:58 -0700146 virtual status_t connect(int api, QueueBufferOutput* output);
Daniel Lam6b091c52012-01-22 15:26:27 -0800147
148 // disconnect attempts to disconnect a producer client API from the
149 // BufferQueue. Calling this method will cause any subsequent calls to other
150 // ISurfaceTexture methods to fail except for getAllocator and connect.
151 // Successfully calling connect after this will allow the other methods to
152 // succeed again.
153 //
154 // This method will fail if the the BufferQueue is not currently
155 // connected to the specified client API.
156 virtual status_t disconnect(int api);
157
Daniel Lameae59d22012-01-22 15:26:27 -0800158 // dump our state in a String
159 virtual void dump(String8& result) const;
160 virtual void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
Daniel Lam6b091c52012-01-22 15:26:27 -0800161
Daniel Lameae59d22012-01-22 15:26:27 -0800162 // public facing structure for BufferSlot
163 struct BufferItem {
164
165 BufferItem()
166 :
167 mTransform(0),
168 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
169 mTimestamp(0),
170 mFrameNumber(0),
171 mBuf(INVALID_BUFFER_SLOT) {
172 mCrop.makeInvalid();
Jamie Gennisefc7ab62012-04-17 19:36:18 -0700173 mActiveRect.makeInvalid();
Daniel Lameae59d22012-01-22 15:26:27 -0800174 }
175 // mGraphicBuffer points to the buffer allocated for this slot or is NULL
176 // if no buffer has been allocated.
177 sp<GraphicBuffer> mGraphicBuffer;
178
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700179 // mCrop is the current crop rectangle for this buffer slot.
Daniel Lameae59d22012-01-22 15:26:27 -0800180 Rect mCrop;
181
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700182 // mTransform is the current transform flags for this buffer slot.
Daniel Lameae59d22012-01-22 15:26:27 -0800183 uint32_t mTransform;
184
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700185 // mScalingMode is the current scaling mode for this buffer slot.
Daniel Lameae59d22012-01-22 15:26:27 -0800186 uint32_t mScalingMode;
187
188 // mTimestamp is the current timestamp for this buffer slot. This gets
189 // to set by queueBuffer each time this slot is queued.
190 int64_t mTimestamp;
191
192 // mFrameNumber is the number of the queued frame for this slot.
193 uint64_t mFrameNumber;
194
Jamie Gennisefc7ab62012-04-17 19:36:18 -0700195 // mBuf is the slot index of this buffer
Daniel Lameae59d22012-01-22 15:26:27 -0800196 int mBuf;
197
Jamie Gennisefc7ab62012-04-17 19:36:18 -0700198 // mActiveRect is the active rectangle for the buffer. Pixels outside
199 // this rectangle are considered completely transparent for the purposes
200 // of window composition.
201 Rect mActiveRect;
Daniel Lameae59d22012-01-22 15:26:27 -0800202 };
203
204 // The following public functions is the consumer facing interface
205
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700206 // acquireBuffer attempts to acquire ownership of the next pending buffer in
207 // the BufferQueue. If no buffer is pending then it returns -EINVAL. If a
208 // buffer is successfully acquired, the information about the buffer is
209 // returned in BufferItem. If the buffer returned had previously been
210 // acquired then the BufferItem::mGraphicBuffer field of buffer is set to
211 // NULL and it is assumed that the consumer still holds a reference to the
212 // buffer.
213 status_t acquireBuffer(BufferItem *buffer);
Daniel Lameae59d22012-01-22 15:26:27 -0800214
215 // releaseBuffer releases a buffer slot from the consumer back to the
216 // BufferQueue pending a fence sync.
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700217 //
218 // Note that the dependencies on EGL will be removed once we switch to using
219 // the Android HW Sync HAL.
Daniel Lameae59d22012-01-22 15:26:27 -0800220 status_t releaseBuffer(int buf, EGLDisplay display, EGLSyncKHR fence);
221
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700222 // consumerConnect connects a consumer to the BufferQueue. Only one
223 // consumer may be connected, and when that consumer disconnects the
224 // BufferQueue is placed into the "abandoned" state, causing most
225 // interactions with the BufferQueue by the producer to fail.
226 status_t consumerConnect(const sp<ConsumerListener>& consumer);
227
Daniel Lameae59d22012-01-22 15:26:27 -0800228 // consumerDisconnect disconnects a consumer from the BufferQueue. All
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700229 // buffers will be freed and the BufferQueue is placed in the "abandoned"
230 // state, causing most interactions with the BufferQueue by the producer to
231 // fail.
Daniel Lameae59d22012-01-22 15:26:27 -0800232 status_t consumerDisconnect();
233
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700234 // getReleasedBuffers sets the value pointed to by slotMask to a bit mask
235 // indicating which buffer slots the have been released by the BufferQueue
236 // but have not yet been released by the consumer.
237 status_t getReleasedBuffers(uint32_t* slotMask);
238
Daniel Lameae59d22012-01-22 15:26:27 -0800239 // setDefaultBufferSize is used to set the size of buffers returned by
240 // requestBuffers when a with and height of zero is requested.
241 status_t setDefaultBufferSize(uint32_t w, uint32_t h);
242
243 // setBufferCountServer set the buffer count. If the client has requested
244 // a buffer count using setBufferCount, the server-buffer count will
245 // take effect once the client sets the count back to zero.
246 status_t setBufferCountServer(int bufferCount);
247
248 // isSynchronousMode returns whether the SurfaceTexture is currently in
249 // synchronous mode.
250 bool isSynchronousMode() const;
251
252 // setConsumerName sets the name used in logging
253 void setConsumerName(const String8& name);
254
Daniel Lamb2675792012-02-23 14:35:13 -0800255 // setDefaultBufferFormat allows the BufferQueue to create
256 // GraphicBuffers of a defaultFormat if no format is specified
257 // in dequeueBuffer
258 status_t setDefaultBufferFormat(uint32_t defaultFormat);
259
260 // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer
261 status_t setConsumerUsageBits(uint32_t usage);
262
263 // setTransformHint bakes in rotation to buffers so overlays can be used
264 status_t setTransformHint(uint32_t hint);
Daniel Lameae59d22012-01-22 15:26:27 -0800265
266private:
Daniel Lam6b091c52012-01-22 15:26:27 -0800267 // freeBufferLocked frees the resources (both GraphicBuffer and EGLImage)
268 // for the given slot.
269 void freeBufferLocked(int index);
270
271 // freeAllBuffersLocked frees the resources (both GraphicBuffer and
272 // EGLImage) for all slots.
273 void freeAllBuffersLocked();
274
275 // freeAllBuffersExceptHeadLocked frees the resources (both GraphicBuffer
276 // and EGLImage) for all slots except the head of mQueue
277 void freeAllBuffersExceptHeadLocked();
278
279 // drainQueueLocked drains the buffer queue if we're in synchronous mode
280 // returns immediately otherwise. It returns NO_INIT if the BufferQueue
281 // became abandoned or disconnected during this call.
282 status_t drainQueueLocked();
283
284 // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in
285 // synchronous mode and free all buffers. In asynchronous mode, all buffers
286 // are freed except the current buffer.
287 status_t drainQueueAndFreeBuffersLocked();
288
289 status_t setBufferCountServerLocked(int bufferCount);
290
Daniel Lam6b091c52012-01-22 15:26:27 -0800291 struct BufferSlot {
292
293 BufferSlot()
Daniel Lameae59d22012-01-22 15:26:27 -0800294 : mEglDisplay(EGL_NO_DISPLAY),
Daniel Lam6b091c52012-01-22 15:26:27 -0800295 mBufferState(BufferSlot::FREE),
296 mRequestBufferCalled(false),
297 mTransform(0),
298 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
299 mTimestamp(0),
300 mFrameNumber(0),
Daniel Lameae59d22012-01-22 15:26:27 -0800301 mFence(EGL_NO_SYNC_KHR),
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700302 mAcquireCalled(false),
303 mNeedsCleanupOnRelease(false) {
Daniel Lam6b091c52012-01-22 15:26:27 -0800304 mCrop.makeInvalid();
Jamie Gennisefc7ab62012-04-17 19:36:18 -0700305 mActiveRect.makeInvalid();
Daniel Lam6b091c52012-01-22 15:26:27 -0800306 }
307
308 // mGraphicBuffer points to the buffer allocated for this slot or is NULL
309 // if no buffer has been allocated.
310 sp<GraphicBuffer> mGraphicBuffer;
311
Daniel Lam6b091c52012-01-22 15:26:27 -0800312 // mEglDisplay is the EGLDisplay used to create mEglImage.
313 EGLDisplay mEglDisplay;
314
315 // BufferState represents the different states in which a buffer slot
316 // can be.
317 enum BufferState {
318 // FREE indicates that the buffer is not currently being used and
319 // will not be used in the future until it gets dequeued and
320 // subsequently queued by the client.
Daniel Lameae59d22012-01-22 15:26:27 -0800321 // aka "owned by BufferQueue, ready to be dequeued"
Daniel Lam6b091c52012-01-22 15:26:27 -0800322 FREE = 0,
323
324 // DEQUEUED indicates that the buffer has been dequeued by the
325 // client, but has not yet been queued or canceled. The buffer is
326 // considered 'owned' by the client, and the server should not use
327 // it for anything.
328 //
329 // Note that when in synchronous-mode (mSynchronousMode == true),
330 // the buffer that's currently attached to the texture may be
331 // dequeued by the client. That means that the current buffer can
332 // be in either the DEQUEUED or QUEUED state. In asynchronous mode,
333 // however, the current buffer is always in the QUEUED state.
Daniel Lameae59d22012-01-22 15:26:27 -0800334 // aka "owned by producer, ready to be queued"
Daniel Lam6b091c52012-01-22 15:26:27 -0800335 DEQUEUED = 1,
336
337 // QUEUED indicates that the buffer has been queued by the client,
338 // and has not since been made available for the client to dequeue.
339 // Attaching the buffer to the texture does NOT transition the
340 // buffer away from the QUEUED state. However, in Synchronous mode
341 // the current buffer may be dequeued by the client under some
342 // circumstances. See the note about the current buffer in the
343 // documentation for DEQUEUED.
Daniel Lameae59d22012-01-22 15:26:27 -0800344 // aka "owned by BufferQueue, ready to be acquired"
Daniel Lam6b091c52012-01-22 15:26:27 -0800345 QUEUED = 2,
Daniel Lameae59d22012-01-22 15:26:27 -0800346
347 // aka "owned by consumer, ready to be released"
348 ACQUIRED = 3
Daniel Lam6b091c52012-01-22 15:26:27 -0800349 };
350
351 // mBufferState is the current state of this buffer slot.
352 BufferState mBufferState;
353
354 // mRequestBufferCalled is used for validating that the client did
355 // call requestBuffer() when told to do so. Technically this is not
356 // needed but useful for debugging and catching client bugs.
357 bool mRequestBufferCalled;
358
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700359 // mCrop is the current crop rectangle for this buffer slot.
Daniel Lam6b091c52012-01-22 15:26:27 -0800360 Rect mCrop;
361
Jamie Gennisefc7ab62012-04-17 19:36:18 -0700362 // mActiveRect is the current active rectangle for this buffer slot.
363 // Pixels outside of this rectangle are to be treated as completely
364 // transparent during window composition. The rectangle is in buffer
365 // pixel coordinates.
366 Rect mActiveRect;
367
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700368 // mTransform is the current transform flags for this buffer slot.
Daniel Lam6b091c52012-01-22 15:26:27 -0800369 uint32_t mTransform;
370
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700371 // mScalingMode is the current scaling mode for this buffer slot.
Daniel Lam6b091c52012-01-22 15:26:27 -0800372 uint32_t mScalingMode;
373
374 // mTimestamp is the current timestamp for this buffer slot. This gets
375 // to set by queueBuffer each time this slot is queued.
376 int64_t mTimestamp;
377
378 // mFrameNumber is the number of the queued frame for this slot.
379 uint64_t mFrameNumber;
380
381 // mFence is the EGL sync object that must signal before the buffer
382 // associated with this buffer slot may be dequeued. It is initialized
383 // to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
384 // on a compile-time option) set to a new sync object in updateTexImage.
385 EGLSyncKHR mFence;
Daniel Lameae59d22012-01-22 15:26:27 -0800386
387 // Indicates whether this buffer has been seen by a consumer yet
388 bool mAcquireCalled;
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700389
390 // Indicates whether this buffer needs to be cleaned up by consumer
391 bool mNeedsCleanupOnRelease;
Daniel Lam6b091c52012-01-22 15:26:27 -0800392 };
393
394 // mSlots is the array of buffer slots that must be mirrored on the client
395 // side. This allows buffer ownership to be transferred between the client
396 // and server without sending a GraphicBuffer over binder. The entire array
397 // is initialized to NULL at construction time, and buffers are allocated
398 // for a slot when requestBuffer is called with that slot's index.
399 BufferSlot mSlots[NUM_BUFFER_SLOTS];
400
Daniel Lam6b091c52012-01-22 15:26:27 -0800401 // mDefaultWidth holds the default width of allocated buffers. It is used
402 // in requestBuffers() if a width and height of zero is specified.
403 uint32_t mDefaultWidth;
404
405 // mDefaultHeight holds the default height of allocated buffers. It is used
406 // in requestBuffers() if a width and height of zero is specified.
407 uint32_t mDefaultHeight;
408
409 // mPixelFormat holds the pixel format of allocated buffers. It is used
410 // in requestBuffers() if a format of zero is specified.
411 uint32_t mPixelFormat;
412
Daniel Lamabe61bf2012-03-26 20:37:15 -0700413 // mMinUndequeuedBuffers is a constraint on the number of buffers
414 // not dequeued at any time
415 int mMinUndequeuedBuffers;
416
417 // mMinAsyncBufferSlots is a constraint on the minimum mBufferCount
418 // when this BufferQueue is in asynchronous mode
419 int mMinAsyncBufferSlots;
420
421 // mMinSyncBufferSlots is a constraint on the minimum mBufferCount
422 // when this BufferQueue is in synchronous mode
423 int mMinSyncBufferSlots;
424
Daniel Lam6b091c52012-01-22 15:26:27 -0800425 // mBufferCount is the number of buffer slots that the client and server
426 // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed
427 // by calling setBufferCount or setBufferCountServer
428 int mBufferCount;
429
430 // mClientBufferCount is the number of buffer slots requested by the client.
431 // The default is zero, which means the client doesn't care how many buffers
432 // there is.
433 int mClientBufferCount;
434
435 // mServerBufferCount buffer count requested by the server-side
436 int mServerBufferCount;
437
Daniel Lam6b091c52012-01-22 15:26:27 -0800438 // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
439 // allocate new GraphicBuffer objects.
440 sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
441
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700442 // mConsumerListener is used to notify the connected consumer of
443 // asynchronous events that it may wish to react to. It is initially set
444 // to NULL and is written by consumerConnect and consumerDisconnect.
445 sp<ConsumerListener> mConsumerListener;
Daniel Lam6b091c52012-01-22 15:26:27 -0800446
447 // mSynchronousMode whether we're in synchronous mode or not
448 bool mSynchronousMode;
449
450 // mAllowSynchronousMode whether we allow synchronous mode or not
451 const bool mAllowSynchronousMode;
452
453 // mConnectedApi indicates the API that is currently connected to this
454 // BufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets updated
455 // by the connect and disconnect methods.
456 int mConnectedApi;
457
458 // mDequeueCondition condition used for dequeueBuffer in synchronous mode
459 mutable Condition mDequeueCondition;
460
461 // mQueue is a FIFO of queued buffers used in synchronous mode
462 typedef Vector<int> Fifo;
463 Fifo mQueue;
464
465 // mAbandoned indicates that the BufferQueue will no longer be used to
466 // consume images buffers pushed to it using the ISurfaceTexture interface.
467 // It is initialized to false, and set to true in the abandon method. A
468 // BufferQueue that has been abandoned will return the NO_INIT error from
469 // all ISurfaceTexture methods capable of returning an error.
470 bool mAbandoned;
471
472 // mName is a string used to identify the BufferQueue in log messages.
473 // It is set by the setName method.
Daniel Lameae59d22012-01-22 15:26:27 -0800474 String8 mConsumerName;
Daniel Lam6b091c52012-01-22 15:26:27 -0800475
476 // mMutex is the mutex used to prevent concurrent access to the member
477 // variables of BufferQueue objects. It must be locked whenever the
478 // member variables are accessed.
479 mutable Mutex mMutex;
480
481 // mFrameCounter is the free running counter, incremented for every buffer queued
482 // with the surface Texture.
483 uint64_t mFrameCounter;
Daniel Lameae59d22012-01-22 15:26:27 -0800484
Daniel Lamb2675792012-02-23 14:35:13 -0800485 // mBufferHasBeenQueued is true once a buffer has been queued. It is reset
486 // by changing the buffer count.
Daniel Lameae59d22012-01-22 15:26:27 -0800487 bool mBufferHasBeenQueued;
Daniel Lamb2675792012-02-23 14:35:13 -0800488
489 // mDefaultBufferFormat can be set so it will override
490 // the buffer format when it isn't specified in dequeueBuffer
491 uint32_t mDefaultBufferFormat;
492
493 // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers
494 uint32_t mConsumerUsageBits;
495
496 // mTransformHint is used to optimize for screen rotations
497 uint32_t mTransformHint;
Daniel Lam6b091c52012-01-22 15:26:27 -0800498};
499
500// ----------------------------------------------------------------------------
501}; // namespace android
502
503#endif // ANDROID_GUI_BUFFERQUEUE_H