blob: 7c1fcb9abc0362e23905eee66ccf6e5655d983b1 [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
Jesse Hallef194142012-06-14 14:45:17 -070026#include <ui/Fence.h>
Daniel Lam6b091c52012-01-22 15:26:27 -080027#include <ui/GraphicBuffer.h>
28
29#include <utils/String8.h>
30#include <utils/Vector.h>
31#include <utils/threads.h>
32
33namespace android {
34// ----------------------------------------------------------------------------
35
36class BufferQueue : public BnSurfaceTexture {
37public:
38 enum { MIN_UNDEQUEUED_BUFFERS = 2 };
Daniel Lam6b091c52012-01-22 15:26:27 -080039 enum { NUM_BUFFER_SLOTS = 32 };
40 enum { NO_CONNECTED_API = 0 };
Daniel Lameae59d22012-01-22 15:26:27 -080041 enum { INVALID_BUFFER_SLOT = -1 };
Daniel Lamfbcda932012-04-09 22:51:52 -070042 enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE };
Daniel Lam6b091c52012-01-22 15:26:27 -080043
Jamie Gennisfa5b40e2012-03-15 14:01:24 -070044 // ConsumerListener is the interface through which the BufferQueue notifies
45 // the consumer of events that the consumer may wish to react to. Because
46 // the consumer will generally have a mutex that is locked during calls from
47 // teh consumer to the BufferQueue, these calls from the BufferQueue to the
48 // consumer *MUST* be called only when the BufferQueue mutex is NOT locked.
49 struct ConsumerListener : public virtual RefBase {
50 // onFrameAvailable is called from queueBuffer each time an additional
51 // frame becomes available for consumption. This means that frames that
52 // are queued while in asynchronous mode only trigger the callback if no
53 // previous frames are pending. Frames queued while in synchronous mode
54 // always trigger the callback.
Daniel Lam6b091c52012-01-22 15:26:27 -080055 //
56 // This is called without any lock held and can be called concurrently
57 // by multiple threads.
58 virtual void onFrameAvailable() = 0;
Jamie Gennisfa5b40e2012-03-15 14:01:24 -070059
60 // onBuffersReleased is called to notify the buffer consumer that the
61 // BufferQueue has released its references to one or more GraphicBuffers
62 // contained in its slots. The buffer consumer should then call
63 // BufferQueue::getReleasedBuffers to retrieve the list of buffers
64 //
65 // This is called without any lock held and can be called concurrently
66 // by multiple threads.
67 virtual void onBuffersReleased() = 0;
Daniel Lam6b091c52012-01-22 15:26:27 -080068 };
69
Jamie Gennisfa5b40e2012-03-15 14:01:24 -070070 // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak
71 // reference to the actual consumer object. It forwards all calls to that
72 // consumer object so long as it exists.
73 //
74 // This class exists to avoid having a circular reference between the
75 // BufferQueue object and the consumer object. The reason this can't be a weak
76 // reference in the BufferQueue class is because we're planning to expose the
77 // consumer side of a BufferQueue as a binder interface, which doesn't support
78 // weak references.
79 class ProxyConsumerListener : public BufferQueue::ConsumerListener {
80 public:
81
82 ProxyConsumerListener(const wp<BufferQueue::ConsumerListener>& consumerListener);
83 virtual ~ProxyConsumerListener();
84 virtual void onFrameAvailable();
85 virtual void onBuffersReleased();
86
87 private:
88
89 // mConsumerListener is a weak reference to the ConsumerListener. This is
90 // the raison d'etre of ProxyConsumerListener.
91 wp<BufferQueue::ConsumerListener> mConsumerListener;
92 };
93
94
Daniel Lam6b091c52012-01-22 15:26:27 -080095 // BufferQueue manages a pool of gralloc memory slots to be used
96 // by producers and consumers.
97 // allowSynchronousMode specifies whether or not synchronous mode can be
98 // enabled.
Daniel Lamabe61bf2012-03-26 20:37:15 -070099 // bufferCount sets the minimum number of undequeued buffers for this queue
Mathias Agopian3e876012012-06-07 17:52:54 -0700100 BufferQueue(bool allowSynchronousMode = true,
101 int bufferCount = MIN_UNDEQUEUED_BUFFERS,
102 const sp<IGraphicBufferAlloc>& allocator = NULL);
Daniel Lam6b091c52012-01-22 15:26:27 -0800103 virtual ~BufferQueue();
104
Daniel Lamb8560522012-01-30 15:51:27 -0800105 virtual int query(int what, int* value);
106
Daniel Lam6b091c52012-01-22 15:26:27 -0800107 // setBufferCount updates the number of available buffer slots. After
108 // calling this all buffer slots are both unallocated and owned by the
109 // BufferQueue object (i.e. they are not owned by the client).
110 virtual status_t setBufferCount(int bufferCount);
111
112 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
113
114 // dequeueBuffer gets the next buffer slot index for the client to use. If a
115 // buffer slot is available then that slot index is written to the location
116 // pointed to by the buf argument and a status of OK is returned. If no
117 // slot is available then a status of -EBUSY is returned and buf is
118 // unmodified.
Jesse Hallf7857542012-06-14 15:26:33 -0700119 //
120 // The fence parameter will be updated to hold the fence associated with
121 // the buffer. The contents of the buffer must not be overwritten until the
122 // fence signals. If the fence is NULL, the buffer may be written
123 // immediately.
124 //
Daniel Lam6b091c52012-01-22 15:26:27 -0800125 // The width and height parameters must be no greater than the minimum of
126 // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
127 // An error due to invalid dimensions might not be reported until
128 // updateTexImage() is called.
Jesse Hallf7857542012-06-14 15:26:33 -0700129 virtual status_t dequeueBuffer(int *buf, sp<Fence>& fence,
130 uint32_t width, uint32_t height, uint32_t format, uint32_t usage);
Daniel Lam6b091c52012-01-22 15:26:27 -0800131
132 // queueBuffer returns a filled buffer to the BufferQueue. In addition, a
133 // timestamp must be provided for the buffer. The timestamp is in
134 // nanoseconds, and must be monotonically increasing. Its other semantics
135 // (zero point, etc) are client-dependent and should be documented by the
136 // client.
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700137 virtual status_t queueBuffer(int buf,
138 const QueueBufferInput& input, QueueBufferOutput* output);
139
Jesse Hallc777b0b2012-06-28 12:52:05 -0700140 virtual void cancelBuffer(int buf, sp<Fence> fence);
Daniel Lam6b091c52012-01-22 15:26:27 -0800141
142 // setSynchronousMode set whether dequeueBuffer is synchronous or
143 // asynchronous. In synchronous mode, dequeueBuffer blocks until
144 // a buffer is available, the currently bound buffer can be dequeued and
145 // queued buffers will be retired in order.
146 // The default mode is asynchronous.
147 virtual status_t setSynchronousMode(bool enabled);
148
149 // connect attempts to connect a producer client API to the BufferQueue.
150 // This must be called before any other ISurfaceTexture methods are called
151 // except for getAllocator.
152 //
153 // This method will fail if the connect was previously called on the
154 // BufferQueue and no corresponding disconnect call was made.
Mathias Agopian24202f52012-04-23 14:28:58 -0700155 virtual status_t connect(int api, QueueBufferOutput* output);
Daniel Lam6b091c52012-01-22 15:26:27 -0800156
157 // disconnect attempts to disconnect a producer client API from the
158 // BufferQueue. Calling this method will cause any subsequent calls to other
159 // ISurfaceTexture methods to fail except for getAllocator and connect.
160 // Successfully calling connect after this will allow the other methods to
161 // succeed again.
162 //
163 // This method will fail if the the BufferQueue is not currently
164 // connected to the specified client API.
165 virtual status_t disconnect(int api);
166
Daniel Lameae59d22012-01-22 15:26:27 -0800167 // dump our state in a String
168 virtual void dump(String8& result) const;
169 virtual void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
Daniel Lam6b091c52012-01-22 15:26:27 -0800170
Daniel Lameae59d22012-01-22 15:26:27 -0800171 // public facing structure for BufferSlot
172 struct BufferItem {
173
174 BufferItem()
175 :
176 mTransform(0),
177 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
178 mTimestamp(0),
179 mFrameNumber(0),
180 mBuf(INVALID_BUFFER_SLOT) {
181 mCrop.makeInvalid();
182 }
183 // mGraphicBuffer points to the buffer allocated for this slot or is NULL
184 // if no buffer has been allocated.
185 sp<GraphicBuffer> mGraphicBuffer;
186
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700187 // mCrop is the current crop rectangle for this buffer slot.
Daniel Lameae59d22012-01-22 15:26:27 -0800188 Rect mCrop;
189
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700190 // mTransform is the current transform flags for this buffer slot.
Daniel Lameae59d22012-01-22 15:26:27 -0800191 uint32_t mTransform;
192
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700193 // mScalingMode is the current scaling mode for this buffer slot.
Daniel Lameae59d22012-01-22 15:26:27 -0800194 uint32_t mScalingMode;
195
196 // mTimestamp is the current timestamp for this buffer slot. This gets
197 // to set by queueBuffer each time this slot is queued.
198 int64_t mTimestamp;
199
200 // mFrameNumber is the number of the queued frame for this slot.
201 uint64_t mFrameNumber;
202
Jamie Gennisefc7ab62012-04-17 19:36:18 -0700203 // mBuf is the slot index of this buffer
Daniel Lameae59d22012-01-22 15:26:27 -0800204 int mBuf;
Daniel Lameae59d22012-01-22 15:26:27 -0800205 };
206
207 // The following public functions is the consumer facing interface
208
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700209 // acquireBuffer attempts to acquire ownership of the next pending buffer in
210 // the BufferQueue. If no buffer is pending then it returns -EINVAL. If a
211 // buffer is successfully acquired, the information about the buffer is
212 // returned in BufferItem. If the buffer returned had previously been
213 // acquired then the BufferItem::mGraphicBuffer field of buffer is set to
214 // NULL and it is assumed that the consumer still holds a reference to the
215 // buffer.
216 status_t acquireBuffer(BufferItem *buffer);
Daniel Lameae59d22012-01-22 15:26:27 -0800217
218 // releaseBuffer releases a buffer slot from the consumer back to the
219 // BufferQueue pending a fence sync.
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700220 //
Eino-Ville Talvalae41b3182012-04-16 17:54:33 -0700221 // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
222 // any references to the just-released buffer that it might have, as if it
223 // had received a onBuffersReleased() call with a mask set for the released
224 // buffer.
225 //
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700226 // Note that the dependencies on EGL will be removed once we switch to using
227 // the Android HW Sync HAL.
Jesse Hallef194142012-06-14 14:45:17 -0700228 status_t releaseBuffer(int buf, EGLDisplay display, EGLSyncKHR fence,
Jesse Hallf7857542012-06-14 15:26:33 -0700229 const sp<Fence>& releaseFence);
Daniel Lameae59d22012-01-22 15:26:27 -0800230
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700231 // consumerConnect connects a consumer to the BufferQueue. Only one
232 // consumer may be connected, and when that consumer disconnects the
233 // BufferQueue is placed into the "abandoned" state, causing most
234 // interactions with the BufferQueue by the producer to fail.
235 status_t consumerConnect(const sp<ConsumerListener>& consumer);
236
Daniel Lameae59d22012-01-22 15:26:27 -0800237 // consumerDisconnect disconnects a consumer from the BufferQueue. All
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700238 // buffers will be freed and the BufferQueue is placed in the "abandoned"
239 // state, causing most interactions with the BufferQueue by the producer to
240 // fail.
Daniel Lameae59d22012-01-22 15:26:27 -0800241 status_t consumerDisconnect();
242
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700243 // getReleasedBuffers sets the value pointed to by slotMask to a bit mask
244 // indicating which buffer slots the have been released by the BufferQueue
245 // but have not yet been released by the consumer.
246 status_t getReleasedBuffers(uint32_t* slotMask);
247
Daniel Lameae59d22012-01-22 15:26:27 -0800248 // setDefaultBufferSize is used to set the size of buffers returned by
249 // requestBuffers when a with and height of zero is requested.
250 status_t setDefaultBufferSize(uint32_t w, uint32_t h);
251
252 // setBufferCountServer set the buffer count. If the client has requested
253 // a buffer count using setBufferCount, the server-buffer count will
254 // take effect once the client sets the count back to zero.
255 status_t setBufferCountServer(int bufferCount);
256
257 // isSynchronousMode returns whether the SurfaceTexture is currently in
258 // synchronous mode.
259 bool isSynchronousMode() const;
260
261 // setConsumerName sets the name used in logging
262 void setConsumerName(const String8& name);
263
Daniel Lamb2675792012-02-23 14:35:13 -0800264 // setDefaultBufferFormat allows the BufferQueue to create
265 // GraphicBuffers of a defaultFormat if no format is specified
266 // in dequeueBuffer
267 status_t setDefaultBufferFormat(uint32_t defaultFormat);
268
269 // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer
270 status_t setConsumerUsageBits(uint32_t usage);
271
272 // setTransformHint bakes in rotation to buffers so overlays can be used
273 status_t setTransformHint(uint32_t hint);
Daniel Lameae59d22012-01-22 15:26:27 -0800274
275private:
Daniel Lam6b091c52012-01-22 15:26:27 -0800276 // freeBufferLocked frees the resources (both GraphicBuffer and EGLImage)
277 // for the given slot.
278 void freeBufferLocked(int index);
279
280 // freeAllBuffersLocked frees the resources (both GraphicBuffer and
281 // EGLImage) for all slots.
282 void freeAllBuffersLocked();
283
284 // freeAllBuffersExceptHeadLocked frees the resources (both GraphicBuffer
285 // and EGLImage) for all slots except the head of mQueue
286 void freeAllBuffersExceptHeadLocked();
287
288 // drainQueueLocked drains the buffer queue if we're in synchronous mode
289 // returns immediately otherwise. It returns NO_INIT if the BufferQueue
290 // became abandoned or disconnected during this call.
291 status_t drainQueueLocked();
292
293 // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in
294 // synchronous mode and free all buffers. In asynchronous mode, all buffers
295 // are freed except the current buffer.
296 status_t drainQueueAndFreeBuffersLocked();
297
298 status_t setBufferCountServerLocked(int bufferCount);
299
Daniel Lam6b091c52012-01-22 15:26:27 -0800300 struct BufferSlot {
301
302 BufferSlot()
Daniel Lameae59d22012-01-22 15:26:27 -0800303 : mEglDisplay(EGL_NO_DISPLAY),
Daniel Lam6b091c52012-01-22 15:26:27 -0800304 mBufferState(BufferSlot::FREE),
305 mRequestBufferCalled(false),
306 mTransform(0),
307 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
308 mTimestamp(0),
309 mFrameNumber(0),
Jesse Hallc777b0b2012-06-28 12:52:05 -0700310 mEglFence(EGL_NO_SYNC_KHR),
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700311 mAcquireCalled(false),
312 mNeedsCleanupOnRelease(false) {
Daniel Lam6b091c52012-01-22 15:26:27 -0800313 mCrop.makeInvalid();
314 }
315
316 // mGraphicBuffer points to the buffer allocated for this slot or is NULL
317 // if no buffer has been allocated.
318 sp<GraphicBuffer> mGraphicBuffer;
319
Daniel Lam6b091c52012-01-22 15:26:27 -0800320 // mEglDisplay is the EGLDisplay used to create mEglImage.
321 EGLDisplay mEglDisplay;
322
323 // BufferState represents the different states in which a buffer slot
324 // can be.
325 enum BufferState {
326 // FREE indicates that the buffer is not currently being used and
327 // will not be used in the future until it gets dequeued and
328 // subsequently queued by the client.
Daniel Lameae59d22012-01-22 15:26:27 -0800329 // aka "owned by BufferQueue, ready to be dequeued"
Daniel Lam6b091c52012-01-22 15:26:27 -0800330 FREE = 0,
331
332 // DEQUEUED indicates that the buffer has been dequeued by the
333 // client, but has not yet been queued or canceled. The buffer is
334 // considered 'owned' by the client, and the server should not use
335 // it for anything.
336 //
337 // Note that when in synchronous-mode (mSynchronousMode == true),
338 // the buffer that's currently attached to the texture may be
339 // dequeued by the client. That means that the current buffer can
340 // be in either the DEQUEUED or QUEUED state. In asynchronous mode,
341 // however, the current buffer is always in the QUEUED state.
Daniel Lameae59d22012-01-22 15:26:27 -0800342 // aka "owned by producer, ready to be queued"
Daniel Lam6b091c52012-01-22 15:26:27 -0800343 DEQUEUED = 1,
344
345 // QUEUED indicates that the buffer has been queued by the client,
346 // and has not since been made available for the client to dequeue.
347 // Attaching the buffer to the texture does NOT transition the
348 // buffer away from the QUEUED state. However, in Synchronous mode
349 // the current buffer may be dequeued by the client under some
350 // circumstances. See the note about the current buffer in the
351 // documentation for DEQUEUED.
Daniel Lameae59d22012-01-22 15:26:27 -0800352 // aka "owned by BufferQueue, ready to be acquired"
Daniel Lam6b091c52012-01-22 15:26:27 -0800353 QUEUED = 2,
Daniel Lameae59d22012-01-22 15:26:27 -0800354
355 // aka "owned by consumer, ready to be released"
356 ACQUIRED = 3
Daniel Lam6b091c52012-01-22 15:26:27 -0800357 };
358
359 // mBufferState is the current state of this buffer slot.
360 BufferState mBufferState;
361
362 // mRequestBufferCalled is used for validating that the client did
363 // call requestBuffer() when told to do so. Technically this is not
364 // needed but useful for debugging and catching client bugs.
365 bool mRequestBufferCalled;
366
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700367 // mCrop is the current crop rectangle for this buffer slot.
Daniel Lam6b091c52012-01-22 15:26:27 -0800368 Rect mCrop;
369
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700370 // mTransform is the current transform flags for this buffer slot.
Daniel Lam6b091c52012-01-22 15:26:27 -0800371 uint32_t mTransform;
372
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700373 // mScalingMode is the current scaling mode for this buffer slot.
Daniel Lam6b091c52012-01-22 15:26:27 -0800374 uint32_t mScalingMode;
375
376 // mTimestamp is the current timestamp for this buffer slot. This gets
377 // to set by queueBuffer each time this slot is queued.
378 int64_t mTimestamp;
379
380 // mFrameNumber is the number of the queued frame for this slot.
381 uint64_t mFrameNumber;
382
Jesse Hallc777b0b2012-06-28 12:52:05 -0700383 // mEglFence is the EGL sync object that must signal before the buffer
Daniel Lam6b091c52012-01-22 15:26:27 -0800384 // associated with this buffer slot may be dequeued. It is initialized
385 // to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
386 // on a compile-time option) set to a new sync object in updateTexImage.
Jesse Hallc777b0b2012-06-28 12:52:05 -0700387 EGLSyncKHR mEglFence;
Daniel Lameae59d22012-01-22 15:26:27 -0800388
Jesse Hallc777b0b2012-06-28 12:52:05 -0700389 // mFence is a fence which will signal when work initiated by the
390 // previous owner of the buffer is finished. When the buffer is FREE,
391 // the fence indicates when the consumer has finished reading
392 // from the buffer, or when the producer has finished writing if it
393 // called cancelBuffer after queueing some writes. When the buffer is
394 // QUEUED, it indicates when the producer has finished filling the
395 // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been
396 // passed to the consumer or producer along with ownership of the
397 // buffer, and mFence is empty.
398 sp<Fence> mFence;
Jesse Hallef194142012-06-14 14:45:17 -0700399
Daniel Lameae59d22012-01-22 15:26:27 -0800400 // Indicates whether this buffer has been seen by a consumer yet
401 bool mAcquireCalled;
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700402
403 // Indicates whether this buffer needs to be cleaned up by consumer
404 bool mNeedsCleanupOnRelease;
Daniel Lam6b091c52012-01-22 15:26:27 -0800405 };
406
407 // mSlots is the array of buffer slots that must be mirrored on the client
408 // side. This allows buffer ownership to be transferred between the client
409 // and server without sending a GraphicBuffer over binder. The entire array
410 // is initialized to NULL at construction time, and buffers are allocated
411 // for a slot when requestBuffer is called with that slot's index.
412 BufferSlot mSlots[NUM_BUFFER_SLOTS];
413
Daniel Lam6b091c52012-01-22 15:26:27 -0800414 // mDefaultWidth holds the default width of allocated buffers. It is used
415 // in requestBuffers() if a width and height of zero is specified.
416 uint32_t mDefaultWidth;
417
418 // mDefaultHeight holds the default height of allocated buffers. It is used
419 // in requestBuffers() if a width and height of zero is specified.
420 uint32_t mDefaultHeight;
421
422 // mPixelFormat holds the pixel format of allocated buffers. It is used
423 // in requestBuffers() if a format of zero is specified.
424 uint32_t mPixelFormat;
425
Daniel Lamabe61bf2012-03-26 20:37:15 -0700426 // mMinUndequeuedBuffers is a constraint on the number of buffers
427 // not dequeued at any time
428 int mMinUndequeuedBuffers;
429
430 // mMinAsyncBufferSlots is a constraint on the minimum mBufferCount
431 // when this BufferQueue is in asynchronous mode
432 int mMinAsyncBufferSlots;
433
434 // mMinSyncBufferSlots is a constraint on the minimum mBufferCount
435 // when this BufferQueue is in synchronous mode
436 int mMinSyncBufferSlots;
437
Daniel Lam6b091c52012-01-22 15:26:27 -0800438 // mBufferCount is the number of buffer slots that the client and server
439 // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed
440 // by calling setBufferCount or setBufferCountServer
441 int mBufferCount;
442
443 // mClientBufferCount is the number of buffer slots requested by the client.
444 // The default is zero, which means the client doesn't care how many buffers
445 // there is.
446 int mClientBufferCount;
447
448 // mServerBufferCount buffer count requested by the server-side
449 int mServerBufferCount;
450
Daniel Lam6b091c52012-01-22 15:26:27 -0800451 // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
452 // allocate new GraphicBuffer objects.
453 sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
454
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700455 // mConsumerListener is used to notify the connected consumer of
456 // asynchronous events that it may wish to react to. It is initially set
457 // to NULL and is written by consumerConnect and consumerDisconnect.
458 sp<ConsumerListener> mConsumerListener;
Daniel Lam6b091c52012-01-22 15:26:27 -0800459
460 // mSynchronousMode whether we're in synchronous mode or not
461 bool mSynchronousMode;
462
463 // mAllowSynchronousMode whether we allow synchronous mode or not
464 const bool mAllowSynchronousMode;
465
466 // mConnectedApi indicates the API that is currently connected to this
467 // BufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets updated
468 // by the connect and disconnect methods.
469 int mConnectedApi;
470
471 // mDequeueCondition condition used for dequeueBuffer in synchronous mode
472 mutable Condition mDequeueCondition;
473
474 // mQueue is a FIFO of queued buffers used in synchronous mode
475 typedef Vector<int> Fifo;
476 Fifo mQueue;
477
478 // mAbandoned indicates that the BufferQueue will no longer be used to
479 // consume images buffers pushed to it using the ISurfaceTexture interface.
480 // It is initialized to false, and set to true in the abandon method. A
481 // BufferQueue that has been abandoned will return the NO_INIT error from
482 // all ISurfaceTexture methods capable of returning an error.
483 bool mAbandoned;
484
485 // mName is a string used to identify the BufferQueue in log messages.
486 // It is set by the setName method.
Daniel Lameae59d22012-01-22 15:26:27 -0800487 String8 mConsumerName;
Daniel Lam6b091c52012-01-22 15:26:27 -0800488
489 // mMutex is the mutex used to prevent concurrent access to the member
490 // variables of BufferQueue objects. It must be locked whenever the
491 // member variables are accessed.
492 mutable Mutex mMutex;
493
494 // mFrameCounter is the free running counter, incremented for every buffer queued
495 // with the surface Texture.
496 uint64_t mFrameCounter;
Daniel Lameae59d22012-01-22 15:26:27 -0800497
Daniel Lamb2675792012-02-23 14:35:13 -0800498 // mBufferHasBeenQueued is true once a buffer has been queued. It is reset
499 // by changing the buffer count.
Daniel Lameae59d22012-01-22 15:26:27 -0800500 bool mBufferHasBeenQueued;
Daniel Lamb2675792012-02-23 14:35:13 -0800501
502 // mDefaultBufferFormat can be set so it will override
503 // the buffer format when it isn't specified in dequeueBuffer
504 uint32_t mDefaultBufferFormat;
505
506 // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers
507 uint32_t mConsumerUsageBits;
508
509 // mTransformHint is used to optimize for screen rotations
510 uint32_t mTransformHint;
Daniel Lam6b091c52012-01-22 15:26:27 -0800511};
512
513// ----------------------------------------------------------------------------
514}; // namespace android
515
516#endif // ANDROID_GUI_BUFFERQUEUE_H