BufferQueue.h revision c5d7b7d323bba8772a9005f7d300ad983a04733a
1/* 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> 21#include <EGL/eglext.h> 22 23#include <gui/IGraphicBufferAlloc.h> 24#include <gui/IGraphicBufferProducer.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 33namespace android { 34// ---------------------------------------------------------------------------- 35 36class BufferQueue : public BnGraphicBufferProducer { 37public: 38 enum { MIN_UNDEQUEUED_BUFFERS = 2 }; 39 enum { NUM_BUFFER_SLOTS = 32 }; 40 enum { NO_CONNECTED_API = 0 }; 41 enum { INVALID_BUFFER_SLOT = -1 }; 42 enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE }; 43 44 // When in async mode we reserve two slots in order to guarantee that the 45 // producer and consumer can run asynchronously. 46 enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 }; 47 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 // the 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 // Query native window attributes. The "what" values are enumerated in 108 // window.h (e.g. NATIVE_WINDOW_FORMAT). 109 virtual int query(int what, int* value); 110 111 // setBufferCount updates the number of available buffer slots. If this 112 // method succeeds, buffer slots will be both unallocated and owned by 113 // the BufferQueue object (i.e. they are not owned by the producer or 114 // consumer). 115 // 116 // This will fail if the producer has dequeued any buffers, or if 117 // bufferCount is invalid. bufferCount must generally be a value 118 // between the minimum undequeued buffer count and NUM_BUFFER_SLOTS 119 // (inclusive). It may also be set to zero (the default) to indicate 120 // that the producer does not wish to set a value. The minimum value 121 // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, 122 // ...). 123 // 124 // This may only be called by the producer. The consumer will be told 125 // to discard buffers through the onBuffersReleased callback. 126 virtual status_t setBufferCount(int bufferCount); 127 128 // requestBuffer returns the GraphicBuffer for slot N. 129 // 130 // In normal operation, this is called the first time slot N is returned 131 // by dequeueBuffer. It must be called again if dequeueBuffer returns 132 // flags indicating that previously-returned buffers are no longer valid. 133 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf); 134 135 // dequeueBuffer gets the next buffer slot index for the producer to use. 136 // If a buffer slot is available then that slot index is written to the 137 // location pointed to by the buf argument and a status of OK is returned. 138 // If no slot is available then a status of -EBUSY is returned and buf is 139 // unmodified. 140 // 141 // The fence parameter will be updated to hold the fence associated with 142 // the buffer. The contents of the buffer must not be overwritten until the 143 // fence signals. If the fence is Fence::NO_FENCE, the buffer may be 144 // written immediately. 145 // 146 // The width and height parameters must be no greater than the minimum of 147 // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). 148 // An error due to invalid dimensions might not be reported until 149 // updateTexImage() is called. If width and height are both zero, the 150 // default values specified by setDefaultBufferSize() are used instead. 151 // 152 // The pixel formats are enumerated in graphics.h, e.g. 153 // HAL_PIXEL_FORMAT_RGBA_8888. If the format is 0, the default format 154 // will be used. 155 // 156 // The usage argument specifies gralloc buffer usage flags. The values 157 // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER. These 158 // will be merged with the usage flags specified by setConsumerUsageBits. 159 // 160 // The return value may be a negative error value or a non-negative 161 // collection of flags. If the flags are set, the return values are 162 // valid, but additional actions must be performed. 163 // 164 // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the 165 // producer must discard cached GraphicBuffer references for the slot 166 // returned in buf. 167 // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer 168 // must discard cached GraphicBuffer references for all slots. 169 // 170 // In both cases, the producer will need to call requestBuffer to get a 171 // GraphicBuffer handle for the returned slot. 172 virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, 173 uint32_t width, uint32_t height, uint32_t format, uint32_t usage); 174 175 // queueBuffer returns a filled buffer to the BufferQueue. 176 // 177 // Additional data is provided in the QueueBufferInput struct. Notably, 178 // a timestamp must be provided for the buffer. The timestamp is in 179 // nanoseconds, and must be monotonically increasing. Its other semantics 180 // (zero point, etc) are producer-specific and should be documented by the 181 // producer. 182 // 183 // The caller may provide a fence that signals when all rendering 184 // operations have completed. Alternatively, NO_FENCE may be used, 185 // indicating that the buffer is ready immediately. 186 // 187 // Some values are returned in the output struct: the current settings 188 // for default width and height, the current transform hint, and the 189 // number of queued buffers. 190 virtual status_t queueBuffer(int buf, 191 const QueueBufferInput& input, QueueBufferOutput* output); 192 193 // cancelBuffer returns a dequeued buffer to the BufferQueue, but doesn't 194 // queue it for use by the consumer. 195 // 196 // The buffer will not be overwritten until the fence signals. The fence 197 // will usually be the one obtained from dequeueBuffer. 198 virtual void cancelBuffer(int buf, const sp<Fence>& fence); 199 200 // setSynchronousMode sets whether dequeueBuffer is synchronous or 201 // asynchronous. In synchronous mode, dequeueBuffer blocks until 202 // a buffer is available, the currently bound buffer can be dequeued and 203 // queued buffers will be acquired in order. In asynchronous mode, 204 // a queued buffer may be replaced by a subsequently queued buffer. 205 // 206 // The default mode is asynchronous. 207 virtual status_t setSynchronousMode(bool enabled); 208 209 // connect attempts to connect a producer API to the BufferQueue. This 210 // must be called before any other IGraphicBufferProducer methods are 211 // called except for getAllocator. A consumer must already be connected. 212 // 213 // This method will fail if connect was previously called on the 214 // BufferQueue and no corresponding disconnect call was made (i.e. if 215 // it's still connected to a producer). 216 // 217 // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU). 218 virtual status_t connect(int api, QueueBufferOutput* output); 219 220 // disconnect attempts to disconnect a producer API from the BufferQueue. 221 // Calling this method will cause any subsequent calls to other 222 // IGraphicBufferProducer methods to fail except for getAllocator and connect. 223 // Successfully calling connect after this will allow the other methods to 224 // succeed again. 225 // 226 // This method will fail if the the BufferQueue is not currently 227 // connected to the specified producer API. 228 virtual status_t disconnect(int api); 229 230 // dump our state in a String 231 virtual void dump(String8& result) const; 232 virtual void dump(String8& result, const char* prefix) const; 233 234 // public facing structure for BufferSlot 235 struct BufferItem { 236 237 BufferItem() 238 : 239 mTransform(0), 240 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), 241 mTimestamp(0), 242 mFrameNumber(0), 243 mBuf(INVALID_BUFFER_SLOT), 244 mAcquireCalled(false) { 245 mCrop.makeInvalid(); 246 } 247 // mGraphicBuffer points to the buffer allocated for this slot, or is NULL 248 // if the buffer in this slot has been acquired in the past (see 249 // BufferSlot.mAcquireCalled). 250 sp<GraphicBuffer> mGraphicBuffer; 251 252 // mCrop is the current crop rectangle for this buffer slot. 253 Rect mCrop; 254 255 // mTransform is the current transform flags for this buffer slot. 256 uint32_t mTransform; 257 258 // mScalingMode is the current scaling mode for this buffer slot. 259 uint32_t mScalingMode; 260 261 // mTimestamp is the current timestamp for this buffer slot. This gets 262 // to set by queueBuffer each time this slot is queued. 263 int64_t mTimestamp; 264 265 // mFrameNumber is the number of the queued frame for this slot. 266 uint64_t mFrameNumber; 267 268 // mBuf is the slot index of this buffer 269 int mBuf; 270 271 // mFence is a fence that will signal when the buffer is idle. 272 sp<Fence> mFence; 273 274 // Indicates whether this buffer has been seen by a consumer yet 275 bool mAcquireCalled; 276 }; 277 278 // The following public functions are the consumer-facing interface 279 280 // acquireBuffer attempts to acquire ownership of the next pending buffer in 281 // the BufferQueue. If no buffer is pending then it returns -EINVAL. If a 282 // buffer is successfully acquired, the information about the buffer is 283 // returned in BufferItem. If the buffer returned had previously been 284 // acquired then the BufferItem::mGraphicBuffer field of buffer is set to 285 // NULL and it is assumed that the consumer still holds a reference to the 286 // buffer. 287 status_t acquireBuffer(BufferItem *buffer); 288 289 // releaseBuffer releases a buffer slot from the consumer back to the 290 // BufferQueue. This may be done while the buffer's contents are still 291 // being accessed. The fence will signal when the buffer is no longer 292 // in use. frameNumber is used to indentify the exact buffer returned. 293 // 294 // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free 295 // any references to the just-released buffer that it might have, as if it 296 // had received a onBuffersReleased() call with a mask set for the released 297 // buffer. 298 // 299 // Note that the dependencies on EGL will be removed once we switch to using 300 // the Android HW Sync HAL. 301 status_t releaseBuffer(int buf, uint64_t frameNumber, 302 EGLDisplay display, EGLSyncKHR fence, 303 const sp<Fence>& releaseFence); 304 305 // consumerConnect connects a consumer to the BufferQueue. Only one 306 // consumer may be connected, and when that consumer disconnects the 307 // BufferQueue is placed into the "abandoned" state, causing most 308 // interactions with the BufferQueue by the producer to fail. 309 // 310 // consumer may not be NULL. 311 status_t consumerConnect(const sp<ConsumerListener>& consumer); 312 313 // consumerDisconnect disconnects a consumer from the BufferQueue. All 314 // buffers will be freed and the BufferQueue is placed in the "abandoned" 315 // state, causing most interactions with the BufferQueue by the producer to 316 // fail. 317 status_t consumerDisconnect(); 318 319 // getReleasedBuffers sets the value pointed to by slotMask to a bit mask 320 // indicating which buffer slots have been released by the BufferQueue 321 // but have not yet been released by the consumer. 322 // 323 // This should be called from the onBuffersReleased() callback. 324 status_t getReleasedBuffers(uint32_t* slotMask); 325 326 // setDefaultBufferSize is used to set the size of buffers returned by 327 // dequeueBuffer when a width and height of zero is requested. Default 328 // is 1x1. 329 status_t setDefaultBufferSize(uint32_t w, uint32_t h); 330 331 // setDefaultMaxBufferCount sets the default value for the maximum buffer 332 // count (the initial default is 2). If the producer has requested a 333 // buffer count using setBufferCount, the default buffer count will only 334 // take effect if the producer sets the count back to zero. 335 // 336 // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. 337 status_t setDefaultMaxBufferCount(int bufferCount); 338 339 // setMaxAcquiredBufferCount sets the maximum number of buffers that can 340 // be acquired by the consumer at one time (default 1). This call will 341 // fail if a producer is connected to the BufferQueue. 342 status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers); 343 344 // isSynchronousMode returns whether the BufferQueue is currently in 345 // synchronous mode. 346 bool isSynchronousMode() const; 347 348 // setConsumerName sets the name used in logging 349 void setConsumerName(const String8& name); 350 351 // setDefaultBufferFormat allows the BufferQueue to create 352 // GraphicBuffers of a defaultFormat if no format is specified 353 // in dequeueBuffer. Formats are enumerated in graphics.h; the 354 // initial default is HAL_PIXEL_FORMAT_RGBA_8888. 355 status_t setDefaultBufferFormat(uint32_t defaultFormat); 356 357 // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. 358 // These are merged with the bits passed to dequeueBuffer. The values are 359 // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0. 360 status_t setConsumerUsageBits(uint32_t usage); 361 362 // setTransformHint bakes in rotation to buffers so overlays can be used. 363 // The values are enumerated in window.h, e.g. 364 // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). 365 status_t setTransformHint(uint32_t hint); 366 367private: 368 // freeBufferLocked frees the GraphicBuffer and sync resources for the 369 // given slot. 370 void freeBufferLocked(int index); 371 372 // freeAllBuffersLocked frees the GraphicBuffer and sync resources for 373 // all slots. 374 void freeAllBuffersLocked(); 375 376 // freeAllBuffersExceptHeadLocked frees the GraphicBuffer and sync 377 // resources for all slots except the head of mQueue. 378 void freeAllBuffersExceptHeadLocked(); 379 380 // drainQueueLocked waits for the buffer queue to empty if we're in 381 // synchronous mode, or returns immediately otherwise. It returns NO_INIT 382 // if the BufferQueue is abandoned (consumer disconnected) or disconnected 383 // (producer disconnected) during the call. 384 status_t drainQueueLocked(); 385 386 // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in 387 // synchronous mode and free all buffers. In asynchronous mode, all buffers 388 // are freed except the currently queued buffer (if it exists). 389 status_t drainQueueAndFreeBuffersLocked(); 390 391 // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots 392 // that will be used if the producer does not override the buffer slot 393 // count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. 394 // The initial default is 2. 395 status_t setDefaultMaxBufferCountLocked(int count); 396 397 // getMinBufferCountLocked returns the minimum number of buffers allowed 398 // given the current BufferQueue state. 399 int getMinMaxBufferCountLocked() const; 400 401 // getMinUndequeuedBufferCountLocked returns the minimum number of buffers 402 // that must remain in a state other than DEQUEUED. 403 int getMinUndequeuedBufferCountLocked() const; 404 405 // getMaxBufferCountLocked returns the maximum number of buffers that can 406 // be allocated at once. This value depends upon the following member 407 // variables: 408 // 409 // mSynchronousMode 410 // mMaxAcquiredBufferCount 411 // mDefaultMaxBufferCount 412 // mOverrideMaxBufferCount 413 // 414 // Any time one of these member variables is changed while a producer is 415 // connected, mDequeueCondition must be broadcast. 416 int getMaxBufferCountLocked() const; 417 418 // stillTracking returns true iff the buffer item is still being tracked 419 // in one of the slots. 420 bool stillTracking(const BufferItem *item) const; 421 422 struct BufferSlot { 423 424 BufferSlot() 425 : mEglDisplay(EGL_NO_DISPLAY), 426 mBufferState(BufferSlot::FREE), 427 mRequestBufferCalled(false), 428 mFrameNumber(0), 429 mEglFence(EGL_NO_SYNC_KHR), 430 mAcquireCalled(false), 431 mNeedsCleanupOnRelease(false) { 432 } 433 434 // mGraphicBuffer points to the buffer allocated for this slot or is NULL 435 // if no buffer has been allocated. 436 sp<GraphicBuffer> mGraphicBuffer; 437 438 // mEglDisplay is the EGLDisplay used to create EGLSyncKHR objects. 439 EGLDisplay mEglDisplay; 440 441 // BufferState represents the different states in which a buffer slot 442 // can be. All slots are initially FREE. 443 enum BufferState { 444 // FREE indicates that the buffer is available to be dequeued 445 // by the producer. The buffer may be in use by the consumer for 446 // a finite time, so the buffer must not be modified until the 447 // associated fence is signaled. 448 // 449 // The slot is "owned" by BufferQueue. It transitions to DEQUEUED 450 // when dequeueBuffer is called. 451 FREE = 0, 452 453 // DEQUEUED indicates that the buffer has been dequeued by the 454 // producer, but has not yet been queued or canceled. The 455 // producer may modify the buffer's contents as soon as the 456 // associated ready fence is signaled. 457 // 458 // The slot is "owned" by the producer. It can transition to 459 // QUEUED (via queueBuffer) or back to FREE (via cancelBuffer). 460 DEQUEUED = 1, 461 462 // QUEUED indicates that the buffer has been filled by the 463 // producer and queued for use by the consumer. The buffer 464 // contents may continue to be modified for a finite time, so 465 // the contents must not be accessed until the associated fence 466 // is signaled. 467 // 468 // The slot is "owned" by BufferQueue. It can transition to 469 // ACQUIRED (via acquireBuffer) or to FREE (if another buffer is 470 // queued in asynchronous mode). 471 QUEUED = 2, 472 473 // ACQUIRED indicates that the buffer has been acquired by the 474 // consumer. As with QUEUED, the contents must not be accessed 475 // by the consumer until the fence is signaled. 476 // 477 // The slot is "owned" by the consumer. It transitions to FREE 478 // when releaseBuffer is called. 479 ACQUIRED = 3 480 }; 481 482 // mBufferState is the current state of this buffer slot. 483 BufferState mBufferState; 484 485 // mRequestBufferCalled is used for validating that the producer did 486 // call requestBuffer() when told to do so. Technically this is not 487 // needed but useful for debugging and catching producer bugs. 488 bool mRequestBufferCalled; 489 490 // mFrameNumber is the number of the queued frame for this slot. This 491 // is used to dequeue buffers in LRU order (useful because buffers 492 // may be released before their release fence is signaled). 493 uint64_t mFrameNumber; 494 495 // mEglFence is the EGL sync object that must signal before the buffer 496 // associated with this buffer slot may be dequeued. It is initialized 497 // to EGL_NO_SYNC_KHR when the buffer is created and may be set to a 498 // new sync object in releaseBuffer. (This is deprecated in favor of 499 // mFence, below.) 500 EGLSyncKHR mEglFence; 501 502 // mFence is a fence which will signal when work initiated by the 503 // previous owner of the buffer is finished. When the buffer is FREE, 504 // the fence indicates when the consumer has finished reading 505 // from the buffer, or when the producer has finished writing if it 506 // called cancelBuffer after queueing some writes. When the buffer is 507 // QUEUED, it indicates when the producer has finished filling the 508 // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been 509 // passed to the consumer or producer along with ownership of the 510 // buffer, and mFence is set to NO_FENCE. 511 sp<Fence> mFence; 512 513 // Indicates whether this buffer has been seen by a consumer yet 514 bool mAcquireCalled; 515 516 // Indicates whether this buffer needs to be cleaned up by the 517 // consumer. This is set when a buffer in ACQUIRED state is freed. 518 // It causes releaseBuffer to return STALE_BUFFER_SLOT. 519 bool mNeedsCleanupOnRelease; 520 }; 521 522 // mSlots is the array of buffer slots that must be mirrored on the 523 // producer side. This allows buffer ownership to be transferred between 524 // the producer and consumer without sending a GraphicBuffer over binder. 525 // The entire array is initialized to NULL at construction time, and 526 // buffers are allocated for a slot when requestBuffer is called with 527 // that slot's index. 528 BufferSlot mSlots[NUM_BUFFER_SLOTS]; 529 530 // mDefaultWidth holds the default width of allocated buffers. It is used 531 // in dequeueBuffer() if a width and height of zero is specified. 532 uint32_t mDefaultWidth; 533 534 // mDefaultHeight holds the default height of allocated buffers. It is used 535 // in dequeueBuffer() if a width and height of zero is specified. 536 uint32_t mDefaultHeight; 537 538 // mMaxAcquiredBufferCount is the number of buffers that the consumer may 539 // acquire at one time. It defaults to 1 and can be changed by the 540 // consumer via the setMaxAcquiredBufferCount method, but this may only be 541 // done when no producer is connected to the BufferQueue. 542 // 543 // This value is used to derive the value returned for the 544 // MIN_UNDEQUEUED_BUFFERS query by the producer. 545 int mMaxAcquiredBufferCount; 546 547 // mDefaultMaxBufferCount is the default limit on the number of buffers 548 // that will be allocated at one time. This default limit is set by the 549 // consumer. The limit (as opposed to the default limit) may be 550 // overridden by the producer. 551 int mDefaultMaxBufferCount; 552 553 // mOverrideMaxBufferCount is the limit on the number of buffers that will 554 // be allocated at one time. This value is set by the image producer by 555 // calling setBufferCount. The default is zero, which means the producer 556 // doesn't care about the number of buffers in the pool. In that case 557 // mDefaultMaxBufferCount is used as the limit. 558 int mOverrideMaxBufferCount; 559 560 // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to 561 // allocate new GraphicBuffer objects. 562 sp<IGraphicBufferAlloc> mGraphicBufferAlloc; 563 564 // mConsumerListener is used to notify the connected consumer of 565 // asynchronous events that it may wish to react to. It is initially set 566 // to NULL and is written by consumerConnect and consumerDisconnect. 567 sp<ConsumerListener> mConsumerListener; 568 569 // mSynchronousMode whether we're in synchronous mode or not 570 bool mSynchronousMode; 571 572 // mAllowSynchronousMode whether we allow synchronous mode or not. Set 573 // when the BufferQueue is created (by the consumer). 574 const bool mAllowSynchronousMode; 575 576 // mConnectedApi indicates the producer API that is currently connected 577 // to this BufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets 578 // updated by the connect and disconnect methods. 579 int mConnectedApi; 580 581 // mDequeueCondition condition used for dequeueBuffer in synchronous mode 582 mutable Condition mDequeueCondition; 583 584 // mQueue is a FIFO of queued buffers used in synchronous mode 585 typedef Vector<BufferItem> Fifo; 586 Fifo mQueue; 587 588 // mAbandoned indicates that the BufferQueue will no longer be used to 589 // consume image buffers pushed to it using the IGraphicBufferProducer 590 // interface. It is initialized to false, and set to true in the 591 // consumerDisconnect method. A BufferQueue that has been abandoned will 592 // return the NO_INIT error from all IGraphicBufferProducer methods 593 // capable of returning an error. 594 bool mAbandoned; 595 596 // mConsumerName is a string used to identify the BufferQueue in log 597 // messages. It is set by the setConsumerName method. 598 String8 mConsumerName; 599 600 // mMutex is the mutex used to prevent concurrent access to the member 601 // variables of BufferQueue objects. It must be locked whenever the 602 // member variables are accessed. 603 mutable Mutex mMutex; 604 605 // mFrameCounter is the free running counter, incremented on every 606 // successful queueBuffer call, and buffer allocation. 607 uint64_t mFrameCounter; 608 609 // mBufferHasBeenQueued is true once a buffer has been queued. It is 610 // reset when something causes all buffers to be freed (e.g. changing the 611 // buffer count). 612 bool mBufferHasBeenQueued; 613 614 // mDefaultBufferFormat can be set so it will override 615 // the buffer format when it isn't specified in dequeueBuffer 616 uint32_t mDefaultBufferFormat; 617 618 // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers 619 uint32_t mConsumerUsageBits; 620 621 // mTransformHint is used to optimize for screen rotations 622 uint32_t mTransformHint; 623}; 624 625// ---------------------------------------------------------------------------- 626}; // namespace android 627 628#endif // ANDROID_GUI_BUFFERQUEUE_H 629