|
1 /* |
|
2 * Copyright (C) 2012 The Android Open Source Project |
|
3 * Copyright (C) 2013 Mozilla Foundation |
|
4 * |
|
5 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 * you may not use this file except in compliance with the License. |
|
7 * You may obtain a copy of the License at |
|
8 * |
|
9 * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 * |
|
11 * Unless required by applicable law or agreed to in writing, software |
|
12 * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 * See the License for the specific language governing permissions and |
|
15 * limitations under the License. |
|
16 */ |
|
17 |
|
18 #ifndef NATIVEWINDOW_GONKBUFFERQUEUE_KK_H |
|
19 #define NATIVEWINDOW_GONKBUFFERQUEUE_KK_H |
|
20 |
|
21 #include <gui/IConsumerListener.h> |
|
22 #include <gui/IGraphicBufferAlloc.h> |
|
23 #include <gui/IGraphicBufferProducer.h> |
|
24 #include "IGonkGraphicBufferConsumer.h" |
|
25 |
|
26 #include <ui/Fence.h> |
|
27 #include <ui/GraphicBuffer.h> |
|
28 |
|
29 #include <utils/String8.h> |
|
30 #include <utils/Vector.h> |
|
31 #include <utils/threads.h> |
|
32 |
|
33 #include "mozilla/layers/LayersSurfaces.h" |
|
34 #include "mozilla/layers/TextureClient.h" |
|
35 |
|
36 namespace android { |
|
37 // ---------------------------------------------------------------------------- |
|
38 |
|
39 class GonkBufferQueue : public BnGraphicBufferProducer, |
|
40 public BnGonkGraphicBufferConsumer, |
|
41 private IBinder::DeathRecipient { |
|
42 typedef mozilla::layers::TextureClient TextureClient; |
|
43 |
|
44 public: |
|
45 enum { MIN_UNDEQUEUED_BUFFERS = 2 }; |
|
46 enum { NUM_BUFFER_SLOTS = 32 }; |
|
47 enum { NO_CONNECTED_API = 0 }; |
|
48 enum { INVALID_BUFFER_SLOT = -1 }; |
|
49 enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE, PRESENT_LATER }; |
|
50 |
|
51 // When in async mode we reserve two slots in order to guarantee that the |
|
52 // producer and consumer can run asynchronously. |
|
53 enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 }; |
|
54 |
|
55 // for backward source compatibility |
|
56 typedef ::android::ConsumerListener ConsumerListener; |
|
57 |
|
58 // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak |
|
59 // reference to the actual consumer object. It forwards all calls to that |
|
60 // consumer object so long as it exists. |
|
61 // |
|
62 // This class exists to avoid having a circular reference between the |
|
63 // GonkBufferQueue object and the consumer object. The reason this can't be a weak |
|
64 // reference in the GonkBufferQueue class is because we're planning to expose the |
|
65 // consumer side of a GonkBufferQueue as a binder interface, which doesn't support |
|
66 // weak references. |
|
67 class ProxyConsumerListener : public BnConsumerListener { |
|
68 public: |
|
69 ProxyConsumerListener(const wp<ConsumerListener>& consumerListener); |
|
70 virtual ~ProxyConsumerListener(); |
|
71 virtual void onFrameAvailable(); |
|
72 virtual void onBuffersReleased(); |
|
73 private: |
|
74 // mConsumerListener is a weak reference to the IConsumerListener. This is |
|
75 // the raison d'etre of ProxyConsumerListener. |
|
76 wp<ConsumerListener> mConsumerListener; |
|
77 }; |
|
78 |
|
79 |
|
80 // BufferQueue manages a pool of gralloc memory slots to be used by |
|
81 // producers and consumers. allocator is used to allocate all the |
|
82 // needed gralloc buffers. |
|
83 GonkBufferQueue(bool allowSynchronousMode = true, |
|
84 const sp<IGraphicBufferAlloc>& allocator = NULL); |
|
85 virtual ~GonkBufferQueue(); |
|
86 |
|
87 /* |
|
88 * IBinder::DeathRecipient interface |
|
89 */ |
|
90 |
|
91 virtual void binderDied(const wp<IBinder>& who); |
|
92 |
|
93 /* |
|
94 * IGraphicBufferProducer interface |
|
95 */ |
|
96 |
|
97 // Query native window attributes. The "what" values are enumerated in |
|
98 // window.h (e.g. NATIVE_WINDOW_FORMAT). |
|
99 virtual int query(int what, int* value); |
|
100 |
|
101 // setBufferCount updates the number of available buffer slots. If this |
|
102 // method succeeds, buffer slots will be both unallocated and owned by |
|
103 // the GonkBufferQueue object (i.e. they are not owned by the producer or |
|
104 // consumer). |
|
105 // |
|
106 // This will fail if the producer has dequeued any buffers, or if |
|
107 // bufferCount is invalid. bufferCount must generally be a value |
|
108 // between the minimum undequeued buffer count and NUM_BUFFER_SLOTS |
|
109 // (inclusive). It may also be set to zero (the default) to indicate |
|
110 // that the producer does not wish to set a value. The minimum value |
|
111 // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, |
|
112 // ...). |
|
113 // |
|
114 // This may only be called by the producer. The consumer will be told |
|
115 // to discard buffers through the onBuffersReleased callback. |
|
116 virtual status_t setBufferCount(int bufferCount); |
|
117 |
|
118 // requestBuffer returns the GraphicBuffer for slot N. |
|
119 // |
|
120 // In normal operation, this is called the first time slot N is returned |
|
121 // by dequeueBuffer. It must be called again if dequeueBuffer returns |
|
122 // flags indicating that previously-returned buffers are no longer valid. |
|
123 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf); |
|
124 |
|
125 // dequeueBuffer gets the next buffer slot index for the producer to use. |
|
126 // If a buffer slot is available then that slot index is written to the |
|
127 // location pointed to by the buf argument and a status of OK is returned. |
|
128 // If no slot is available then a status of -EBUSY is returned and buf is |
|
129 // unmodified. |
|
130 // |
|
131 // The fence parameter will be updated to hold the fence associated with |
|
132 // the buffer. The contents of the buffer must not be overwritten until the |
|
133 // fence signals. If the fence is Fence::NO_FENCE, the buffer may be |
|
134 // written immediately. |
|
135 // |
|
136 // The width and height parameters must be no greater than the minimum of |
|
137 // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). |
|
138 // An error due to invalid dimensions might not be reported until |
|
139 // updateTexImage() is called. If width and height are both zero, the |
|
140 // default values specified by setDefaultBufferSize() are used instead. |
|
141 // |
|
142 // The pixel formats are enumerated in graphics.h, e.g. |
|
143 // HAL_PIXEL_FORMAT_RGBA_8888. If the format is 0, the default format |
|
144 // will be used. |
|
145 // |
|
146 // The usage argument specifies gralloc buffer usage flags. The values |
|
147 // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER. These |
|
148 // will be merged with the usage flags specified by setConsumerUsageBits. |
|
149 // |
|
150 // The return value may be a negative error value or a non-negative |
|
151 // collection of flags. If the flags are set, the return values are |
|
152 // valid, but additional actions must be performed. |
|
153 // |
|
154 // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the |
|
155 // producer must discard cached GraphicBuffer references for the slot |
|
156 // returned in buf. |
|
157 // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer |
|
158 // must discard cached GraphicBuffer references for all slots. |
|
159 // |
|
160 // In both cases, the producer will need to call requestBuffer to get a |
|
161 // GraphicBuffer handle for the returned slot. |
|
162 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async, |
|
163 uint32_t width, uint32_t height, uint32_t format, uint32_t usage); |
|
164 |
|
165 // queueBuffer returns a filled buffer to the GonkBufferQueue. |
|
166 // |
|
167 // Additional data is provided in the QueueBufferInput struct. Notably, |
|
168 // a timestamp must be provided for the buffer. The timestamp is in |
|
169 // nanoseconds, and must be monotonically increasing. Its other semantics |
|
170 // (zero point, etc) are producer-specific and should be documented by the |
|
171 // producer. |
|
172 // |
|
173 // The caller may provide a fence that signals when all rendering |
|
174 // operations have completed. Alternatively, NO_FENCE may be used, |
|
175 // indicating that the buffer is ready immediately. |
|
176 // |
|
177 // Some values are returned in the output struct: the current settings |
|
178 // for default width and height, the current transform hint, and the |
|
179 // number of queued buffers. |
|
180 virtual status_t queueBuffer(int buf, |
|
181 const QueueBufferInput& input, QueueBufferOutput* output); |
|
182 |
|
183 // cancelBuffer returns a dequeued buffer to the GonkBufferQueue, but doesn't |
|
184 // queue it for use by the consumer. |
|
185 // |
|
186 // The buffer will not be overwritten until the fence signals. The fence |
|
187 // will usually be the one obtained from dequeueBuffer. |
|
188 virtual void cancelBuffer(int buf, const sp<Fence>& fence); |
|
189 |
|
190 // connect attempts to connect a producer API to the GonkBufferQueue. This |
|
191 // must be called before any other IGraphicBufferProducer methods are |
|
192 // called except for getAllocator. A consumer must already be connected. |
|
193 // |
|
194 // This method will fail if connect was previously called on the |
|
195 // GonkBufferQueue and no corresponding disconnect call was made (i.e. if |
|
196 // it's still connected to a producer). |
|
197 // |
|
198 // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU). |
|
199 virtual status_t connect(const sp<IBinder>& token, |
|
200 int api, bool producerControlledByApp, QueueBufferOutput* output); |
|
201 |
|
202 // disconnect attempts to disconnect a producer API from the GonkBufferQueue. |
|
203 // Calling this method will cause any subsequent calls to other |
|
204 // IGraphicBufferProducer methods to fail except for getAllocator and connect. |
|
205 // Successfully calling connect after this will allow the other methods to |
|
206 // succeed again. |
|
207 // |
|
208 // This method will fail if the the GonkBufferQueue is not currently |
|
209 // connected to the specified producer API. |
|
210 virtual status_t disconnect(int api); |
|
211 |
|
212 /* |
|
213 * IGraphicBufferConsumer interface |
|
214 */ |
|
215 |
|
216 // acquireBuffer attempts to acquire ownership of the next pending buffer in |
|
217 // the GonkBufferQueue. If no buffer is pending then it returns -EINVAL. If a |
|
218 // buffer is successfully acquired, the information about the buffer is |
|
219 // returned in BufferItem. If the buffer returned had previously been |
|
220 // acquired then the BufferItem::mGraphicBuffer field of buffer is set to |
|
221 // NULL and it is assumed that the consumer still holds a reference to the |
|
222 // buffer. |
|
223 // |
|
224 // If presentWhen is nonzero, it indicates the time when the buffer will |
|
225 // be displayed on screen. If the buffer's timestamp is farther in the |
|
226 // future, the buffer won't be acquired, and PRESENT_LATER will be |
|
227 // returned. The presentation time is in nanoseconds, and the time base |
|
228 // is CLOCK_MONOTONIC. |
|
229 virtual status_t acquireBuffer(BufferItem *buffer, nsecs_t presentWhen); |
|
230 |
|
231 // releaseBuffer releases a buffer slot from the consumer back to the |
|
232 // GonkBufferQueue. This may be done while the buffer's contents are still |
|
233 // being accessed. The fence will signal when the buffer is no longer |
|
234 // in use. frameNumber is used to indentify the exact buffer returned. |
|
235 // |
|
236 // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free |
|
237 // any references to the just-released buffer that it might have, as if it |
|
238 // had received a onBuffersReleased() call with a mask set for the released |
|
239 // buffer. |
|
240 // |
|
241 // Note that the dependencies on EGL will be removed once we switch to using |
|
242 // the Android HW Sync HAL. |
|
243 virtual status_t releaseBuffer(int buf, uint64_t frameNumber, |
|
244 const sp<Fence>& releaseFence); |
|
245 |
|
246 // consumerConnect connects a consumer to the GonkBufferQueue. Only one |
|
247 // consumer may be connected, and when that consumer disconnects the |
|
248 // GonkBufferQueue is placed into the "abandoned" state, causing most |
|
249 // interactions with the GonkBufferQueue by the producer to fail. |
|
250 // controlledByApp indicates whether the consumer is controlled by |
|
251 // the application. |
|
252 // |
|
253 // consumer may not be NULL. |
|
254 virtual status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp); |
|
255 |
|
256 // consumerDisconnect disconnects a consumer from the GonkBufferQueue. All |
|
257 // buffers will be freed and the GonkBufferQueue is placed in the "abandoned" |
|
258 // state, causing most interactions with the GonkBufferQueue by the producer to |
|
259 // fail. |
|
260 virtual status_t consumerDisconnect(); |
|
261 |
|
262 // getReleasedBuffers sets the value pointed to by slotMask to a bit mask |
|
263 // indicating which buffer slots have been released by the GonkBufferQueue |
|
264 // but have not yet been released by the consumer. |
|
265 // |
|
266 // This should be called from the onBuffersReleased() callback. |
|
267 virtual status_t getReleasedBuffers(uint32_t* slotMask); |
|
268 |
|
269 // setDefaultBufferSize is used to set the size of buffers returned by |
|
270 // dequeueBuffer when a width and height of zero is requested. Default |
|
271 // is 1x1. |
|
272 virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h); |
|
273 |
|
274 // setDefaultMaxBufferCount sets the default value for the maximum buffer |
|
275 // count (the initial default is 2). If the producer has requested a |
|
276 // buffer count using setBufferCount, the default buffer count will only |
|
277 // take effect if the producer sets the count back to zero. |
|
278 // |
|
279 // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. |
|
280 virtual status_t setDefaultMaxBufferCount(int bufferCount); |
|
281 |
|
282 // disableAsyncBuffer disables the extra buffer used in async mode |
|
283 // (when both producer and consumer have set their "isControlledByApp" |
|
284 // flag) and has dequeueBuffer() return WOULD_BLOCK instead. |
|
285 // |
|
286 // This can only be called before consumerConnect(). |
|
287 virtual status_t disableAsyncBuffer(); |
|
288 |
|
289 // setMaxAcquiredBufferCount sets the maximum number of buffers that can |
|
290 // be acquired by the consumer at one time (default 1). This call will |
|
291 // fail if a producer is connected to the GonkBufferQueue. |
|
292 virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers); |
|
293 |
|
294 // setConsumerName sets the name used in logging |
|
295 virtual void setConsumerName(const String8& name); |
|
296 |
|
297 // setDefaultBufferFormat allows the GonkBufferQueue to create |
|
298 // GraphicBuffers of a defaultFormat if no format is specified |
|
299 // in dequeueBuffer. Formats are enumerated in graphics.h; the |
|
300 // initial default is HAL_PIXEL_FORMAT_RGBA_8888. |
|
301 virtual status_t setDefaultBufferFormat(uint32_t defaultFormat); |
|
302 |
|
303 // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. |
|
304 // These are merged with the bits passed to dequeueBuffer. The values are |
|
305 // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0. |
|
306 virtual status_t setConsumerUsageBits(uint32_t usage); |
|
307 |
|
308 // setTransformHint bakes in rotation to buffers so overlays can be used. |
|
309 // The values are enumerated in window.h, e.g. |
|
310 // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). |
|
311 virtual status_t setTransformHint(uint32_t hint); |
|
312 |
|
313 // dump our state in a String |
|
314 virtual void dump(String8& result, const char* prefix) const; |
|
315 |
|
316 mozilla::TemporaryRef<TextureClient> getTextureClientFromBuffer(ANativeWindowBuffer* buffer); |
|
317 |
|
318 int getSlotFromTextureClientLocked(TextureClient* client) const; |
|
319 |
|
320 private: |
|
321 // freeBufferLocked frees the GraphicBuffer and sync resources for the |
|
322 // given slot. |
|
323 //void freeBufferLocked(int index); |
|
324 |
|
325 // freeAllBuffersLocked frees the GraphicBuffer and sync resources for |
|
326 // all slots. |
|
327 //void freeAllBuffersLocked(); |
|
328 void freeAllBuffersLocked(); |
|
329 |
|
330 // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots |
|
331 // that will be used if the producer does not override the buffer slot |
|
332 // count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. |
|
333 // The initial default is 2. |
|
334 status_t setDefaultMaxBufferCountLocked(int count); |
|
335 |
|
336 // getMinUndequeuedBufferCount returns the minimum number of buffers |
|
337 // that must remain in a state other than DEQUEUED. |
|
338 // The async parameter tells whether we're in asynchronous mode. |
|
339 int getMinUndequeuedBufferCount(bool async) const; |
|
340 |
|
341 // getMinBufferCountLocked returns the minimum number of buffers allowed |
|
342 // given the current GonkBufferQueue state. |
|
343 // The async parameter tells whether we're in asynchronous mode. |
|
344 int getMinMaxBufferCountLocked(bool async) const; |
|
345 |
|
346 // getMaxBufferCountLocked returns the maximum number of buffers that can |
|
347 // be allocated at once. This value depends upon the following member |
|
348 // variables: |
|
349 // |
|
350 // mDequeueBufferCannotBlock |
|
351 // mMaxAcquiredBufferCount |
|
352 // mDefaultMaxBufferCount |
|
353 // mOverrideMaxBufferCount |
|
354 // async parameter |
|
355 // |
|
356 // Any time one of these member variables is changed while a producer is |
|
357 // connected, mDequeueCondition must be broadcast. |
|
358 int getMaxBufferCountLocked(bool async) const; |
|
359 |
|
360 // stillTracking returns true iff the buffer item is still being tracked |
|
361 // in one of the slots. |
|
362 bool stillTracking(const BufferItem *item) const; |
|
363 |
|
364 struct BufferSlot { |
|
365 |
|
366 BufferSlot() |
|
367 : mBufferState(BufferSlot::FREE), |
|
368 mRequestBufferCalled(false), |
|
369 mFrameNumber(0), |
|
370 mAcquireCalled(false), |
|
371 mNeedsCleanupOnRelease(false) { |
|
372 } |
|
373 |
|
374 // mGraphicBuffer points to the buffer allocated for this slot or is NULL |
|
375 // if no buffer has been allocated. |
|
376 sp<GraphicBuffer> mGraphicBuffer; |
|
377 |
|
378 // mTextureClient is a thin abstraction over remotely allocated GraphicBuffer. |
|
379 mozilla::RefPtr<TextureClient> mTextureClient; |
|
380 |
|
381 // BufferState represents the different states in which a buffer slot |
|
382 // can be. All slots are initially FREE. |
|
383 enum BufferState { |
|
384 // FREE indicates that the buffer is available to be dequeued |
|
385 // by the producer. The buffer may be in use by the consumer for |
|
386 // a finite time, so the buffer must not be modified until the |
|
387 // associated fence is signaled. |
|
388 // |
|
389 // The slot is "owned" by GonkBufferQueue. It transitions to DEQUEUED |
|
390 // when dequeueBuffer is called. |
|
391 FREE = 0, |
|
392 |
|
393 // DEQUEUED indicates that the buffer has been dequeued by the |
|
394 // producer, but has not yet been queued or canceled. The |
|
395 // producer may modify the buffer's contents as soon as the |
|
396 // associated ready fence is signaled. |
|
397 // |
|
398 // The slot is "owned" by the producer. It can transition to |
|
399 // QUEUED (via queueBuffer) or back to FREE (via cancelBuffer). |
|
400 DEQUEUED = 1, |
|
401 |
|
402 // QUEUED indicates that the buffer has been filled by the |
|
403 // producer and queued for use by the consumer. The buffer |
|
404 // contents may continue to be modified for a finite time, so |
|
405 // the contents must not be accessed until the associated fence |
|
406 // is signaled. |
|
407 // |
|
408 // The slot is "owned" by GonkBufferQueue. It can transition to |
|
409 // ACQUIRED (via acquireBuffer) or to FREE (if another buffer is |
|
410 // queued in asynchronous mode). |
|
411 QUEUED = 2, |
|
412 |
|
413 // ACQUIRED indicates that the buffer has been acquired by the |
|
414 // consumer. As with QUEUED, the contents must not be accessed |
|
415 // by the consumer until the fence is signaled. |
|
416 // |
|
417 // The slot is "owned" by the consumer. It transitions to FREE |
|
418 // when releaseBuffer is called. |
|
419 ACQUIRED = 3 |
|
420 }; |
|
421 |
|
422 // mBufferState is the current state of this buffer slot. |
|
423 BufferState mBufferState; |
|
424 |
|
425 // mRequestBufferCalled is used for validating that the producer did |
|
426 // call requestBuffer() when told to do so. Technically this is not |
|
427 // needed but useful for debugging and catching producer bugs. |
|
428 bool mRequestBufferCalled; |
|
429 |
|
430 // mFrameNumber is the number of the queued frame for this slot. This |
|
431 // is used to dequeue buffers in LRU order (useful because buffers |
|
432 // may be released before their release fence is signaled). |
|
433 uint64_t mFrameNumber; |
|
434 |
|
435 // mFence is a fence which will signal when work initiated by the |
|
436 // previous owner of the buffer is finished. When the buffer is FREE, |
|
437 // the fence indicates when the consumer has finished reading |
|
438 // from the buffer, or when the producer has finished writing if it |
|
439 // called cancelBuffer after queueing some writes. When the buffer is |
|
440 // QUEUED, it indicates when the producer has finished filling the |
|
441 // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been |
|
442 // passed to the consumer or producer along with ownership of the |
|
443 // buffer, and mFence is set to NO_FENCE. |
|
444 sp<Fence> mFence; |
|
445 |
|
446 // Indicates whether this buffer has been seen by a consumer yet |
|
447 bool mAcquireCalled; |
|
448 |
|
449 // Indicates whether this buffer needs to be cleaned up by the |
|
450 // consumer. This is set when a buffer in ACQUIRED state is freed. |
|
451 // It causes releaseBuffer to return STALE_BUFFER_SLOT. |
|
452 bool mNeedsCleanupOnRelease; |
|
453 }; |
|
454 |
|
455 // mSlots is the array of buffer slots that must be mirrored on the |
|
456 // producer side. This allows buffer ownership to be transferred between |
|
457 // the producer and consumer without sending a GraphicBuffer over binder. |
|
458 // The entire array is initialized to NULL at construction time, and |
|
459 // buffers are allocated for a slot when requestBuffer is called with |
|
460 // that slot's index. |
|
461 BufferSlot mSlots[NUM_BUFFER_SLOTS]; |
|
462 |
|
463 // mDefaultWidth holds the default width of allocated buffers. It is used |
|
464 // in dequeueBuffer() if a width and height of zero is specified. |
|
465 uint32_t mDefaultWidth; |
|
466 |
|
467 // mDefaultHeight holds the default height of allocated buffers. It is used |
|
468 // in dequeueBuffer() if a width and height of zero is specified. |
|
469 uint32_t mDefaultHeight; |
|
470 |
|
471 // mMaxAcquiredBufferCount is the number of buffers that the consumer may |
|
472 // acquire at one time. It defaults to 1 and can be changed by the |
|
473 // consumer via the setMaxAcquiredBufferCount method, but this may only be |
|
474 // done when no producer is connected to the GonkBufferQueue. |
|
475 // |
|
476 // This value is used to derive the value returned for the |
|
477 // MIN_UNDEQUEUED_BUFFERS query by the producer. |
|
478 int mMaxAcquiredBufferCount; |
|
479 |
|
480 // mDefaultMaxBufferCount is the default limit on the number of buffers |
|
481 // that will be allocated at one time. This default limit is set by the |
|
482 // consumer. The limit (as opposed to the default limit) may be |
|
483 // overridden by the producer. |
|
484 int mDefaultMaxBufferCount; |
|
485 |
|
486 // mOverrideMaxBufferCount is the limit on the number of buffers that will |
|
487 // be allocated at one time. This value is set by the image producer by |
|
488 // calling setBufferCount. The default is zero, which means the producer |
|
489 // doesn't care about the number of buffers in the pool. In that case |
|
490 // mDefaultMaxBufferCount is used as the limit. |
|
491 int mOverrideMaxBufferCount; |
|
492 |
|
493 // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to |
|
494 // allocate new GraphicBuffer objects. |
|
495 sp<IGraphicBufferAlloc> mGraphicBufferAlloc; |
|
496 |
|
497 // mConsumerListener is used to notify the connected consumer of |
|
498 // asynchronous events that it may wish to react to. It is initially set |
|
499 // to NULL and is written by consumerConnect and consumerDisconnect. |
|
500 sp<IConsumerListener> mConsumerListener; |
|
501 |
|
502 // mConsumerControlledByApp whether the connected consumer is controlled by the |
|
503 // application. |
|
504 bool mConsumerControlledByApp; |
|
505 |
|
506 // mDequeueBufferCannotBlock whether dequeueBuffer() isn't allowed to block. |
|
507 // this flag is set during connect() when both consumer and producer are controlled |
|
508 // by the application. |
|
509 bool mDequeueBufferCannotBlock; |
|
510 |
|
511 // mUseAsyncBuffer whether an extra buffer is used in async mode to prevent |
|
512 // dequeueBuffer() from ever blocking. |
|
513 bool mUseAsyncBuffer; |
|
514 |
|
515 // mConnectedApi indicates the producer API that is currently connected |
|
516 // to this GonkBufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets |
|
517 // updated by the connect and disconnect methods. |
|
518 int mConnectedApi; |
|
519 |
|
520 // mDequeueCondition condition used for dequeueBuffer in synchronous mode |
|
521 mutable Condition mDequeueCondition; |
|
522 |
|
523 // mQueue is a FIFO of queued buffers used in synchronous mode |
|
524 typedef Vector<BufferItem> Fifo; |
|
525 Fifo mQueue; |
|
526 |
|
527 // mAbandoned indicates that the GonkBufferQueue will no longer be used to |
|
528 // consume image buffers pushed to it using the IGraphicBufferProducer |
|
529 // interface. It is initialized to false, and set to true in the |
|
530 // consumerDisconnect method. A GonkBufferQueue that has been abandoned will |
|
531 // return the NO_INIT error from all IGraphicBufferProducer methods |
|
532 // capable of returning an error. |
|
533 bool mAbandoned; |
|
534 |
|
535 // mConsumerName is a string used to identify the GonkBufferQueue in log |
|
536 // messages. It is set by the setConsumerName method. |
|
537 String8 mConsumerName; |
|
538 |
|
539 // mMutex is the mutex used to prevent concurrent access to the member |
|
540 // variables of GonkBufferQueue objects. It must be locked whenever the |
|
541 // member variables are accessed. |
|
542 mutable Mutex mMutex; |
|
543 |
|
544 // mFrameCounter is the free running counter, incremented on every |
|
545 // successful queueBuffer call, and buffer allocation. |
|
546 uint64_t mFrameCounter; |
|
547 |
|
548 // mBufferHasBeenQueued is true once a buffer has been queued. It is |
|
549 // reset when something causes all buffers to be freed (e.g. changing the |
|
550 // buffer count). |
|
551 bool mBufferHasBeenQueued; |
|
552 |
|
553 // mDefaultBufferFormat can be set so it will override |
|
554 // the buffer format when it isn't specified in dequeueBuffer |
|
555 uint32_t mDefaultBufferFormat; |
|
556 |
|
557 // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers |
|
558 uint32_t mConsumerUsageBits; |
|
559 |
|
560 // mTransformHint is used to optimize for screen rotations |
|
561 uint32_t mTransformHint; |
|
562 |
|
563 // mConnectedProducerToken is used to set a binder death notification on the producer |
|
564 sp<IBinder> mConnectedProducerToken; |
|
565 }; |
|
566 |
|
567 // ---------------------------------------------------------------------------- |
|
568 }; // namespace android |
|
569 |
|
570 #endif // ANDROID_GUI_BUFFERQUEUE_H |