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 33 namespace android { 34 // ---------------------------------------------------------------------------- 35 36 class BufferQueue : public BnGraphicBufferProducer { 37 public: 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, char* buffer, size_t SIZE) const; 233 234 // public facing structure for BufferSlot 235 struct BufferItem { 236 BufferItemBufferItem237 BufferItem() 238 : 239 mTransform(0), 240 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), 241 mTimestamp(0), 242 mFrameNumber(0), 243 mBuf(INVALID_BUFFER_SLOT) { 244 mCrop.makeInvalid(); 245 } 246 // mGraphicBuffer points to the buffer allocated for this slot, or is NULL 247 // if the buffer in this slot has been acquired in the past (see 248 // BufferSlot.mAcquireCalled). 249 sp<GraphicBuffer> mGraphicBuffer; 250 251 // mCrop is the current crop rectangle for this buffer slot. 252 Rect mCrop; 253 254 // mTransform is the current transform flags for this buffer slot. 255 uint32_t mTransform; 256 257 // mScalingMode is the current scaling mode for this buffer slot. 258 uint32_t mScalingMode; 259 260 // mTimestamp is the current timestamp for this buffer slot. This gets 261 // to set by queueBuffer each time this slot is queued. 262 int64_t mTimestamp; 263 264 // mFrameNumber is the number of the queued frame for this slot. 265 uint64_t mFrameNumber; 266 267 // mBuf is the slot index of this buffer 268 int mBuf; 269 270 // mFence is a fence that will signal when the buffer is idle. 271 sp<Fence> mFence; 272 }; 273 274 // The following public functions are the consumer-facing interface 275 276 // acquireBuffer attempts to acquire ownership of the next pending buffer in 277 // the BufferQueue. If no buffer is pending then it returns -EINVAL. If a 278 // buffer is successfully acquired, the information about the buffer is 279 // returned in BufferItem. If the buffer returned had previously been 280 // acquired then the BufferItem::mGraphicBuffer field of buffer is set to 281 // NULL and it is assumed that the consumer still holds a reference to the 282 // buffer. 283 status_t acquireBuffer(BufferItem *buffer); 284 285 // releaseBuffer releases a buffer slot from the consumer back to the 286 // BufferQueue. This may be done while the buffer's contents are still 287 // being accessed. The fence will signal when the buffer is no longer 288 // in use. 289 // 290 // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free 291 // any references to the just-released buffer that it might have, as if it 292 // had received a onBuffersReleased() call with a mask set for the released 293 // buffer. 294 // 295 // Note that the dependencies on EGL will be removed once we switch to using 296 // the Android HW Sync HAL. 297 status_t releaseBuffer(int buf, EGLDisplay display, EGLSyncKHR fence, 298 const sp<Fence>& releaseFence); 299 300 // consumerConnect connects a consumer to the BufferQueue. Only one 301 // consumer may be connected, and when that consumer disconnects the 302 // BufferQueue is placed into the "abandoned" state, causing most 303 // interactions with the BufferQueue by the producer to fail. 304 // 305 // consumer may not be NULL. 306 status_t consumerConnect(const sp<ConsumerListener>& consumer); 307 308 // consumerDisconnect disconnects a consumer from the BufferQueue. All 309 // buffers will be freed and the BufferQueue is placed in the "abandoned" 310 // state, causing most interactions with the BufferQueue by the producer to 311 // fail. 312 status_t consumerDisconnect(); 313 314 // getReleasedBuffers sets the value pointed to by slotMask to a bit mask 315 // indicating which buffer slots have been released by the BufferQueue 316 // but have not yet been released by the consumer. 317 // 318 // This should be called from the onBuffersReleased() callback. 319 status_t getReleasedBuffers(uint32_t* slotMask); 320 321 // setDefaultBufferSize is used to set the size of buffers returned by 322 // dequeueBuffer when a width and height of zero is requested. Default 323 // is 1x1. 324 status_t setDefaultBufferSize(uint32_t w, uint32_t h); 325 326 // setDefaultMaxBufferCount sets the default value for the maximum buffer 327 // count (the initial default is 2). If the producer has requested a 328 // buffer count using setBufferCount, the default buffer count will only 329 // take effect if the producer sets the count back to zero. 330 // 331 // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. 332 status_t setDefaultMaxBufferCount(int bufferCount); 333 334 // setMaxAcquiredBufferCount sets the maximum number of buffers that can 335 // be acquired by the consumer at one time (default 1). This call will 336 // fail if a producer is connected to the BufferQueue. 337 status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers); 338 339 // isSynchronousMode returns whether the BufferQueue is currently in 340 // synchronous mode. 341 bool isSynchronousMode() const; 342 343 // setConsumerName sets the name used in logging 344 void setConsumerName(const String8& name); 345 346 // setDefaultBufferFormat allows the BufferQueue to create 347 // GraphicBuffers of a defaultFormat if no format is specified 348 // in dequeueBuffer. Formats are enumerated in graphics.h; the 349 // initial default is HAL_PIXEL_FORMAT_RGBA_8888. 350 status_t setDefaultBufferFormat(uint32_t defaultFormat); 351 352 // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. 353 // These are merged with the bits passed to dequeueBuffer. The values are 354 // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0. 355 status_t setConsumerUsageBits(uint32_t usage); 356 357 // setTransformHint bakes in rotation to buffers so overlays can be used. 358 // The values are enumerated in window.h, e.g. 359 // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). 360 status_t setTransformHint(uint32_t hint); 361 362 private: 363 // freeBufferLocked frees the GraphicBuffer and sync resources for the 364 // given slot. 365 void freeBufferLocked(int index); 366 367 // freeAllBuffersLocked frees the GraphicBuffer and sync resources for 368 // all slots. 369 void freeAllBuffersLocked(); 370 371 // freeAllBuffersExceptHeadLocked frees the GraphicBuffer and sync 372 // resources for all slots except the head of mQueue. 373 void freeAllBuffersExceptHeadLocked(); 374 375 // drainQueueLocked waits for the buffer queue to empty if we're in 376 // synchronous mode, or returns immediately otherwise. It returns NO_INIT 377 // if the BufferQueue is abandoned (consumer disconnected) or disconnected 378 // (producer disconnected) during the call. 379 status_t drainQueueLocked(); 380 381 // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in 382 // synchronous mode and free all buffers. In asynchronous mode, all buffers 383 // are freed except the currently queued buffer (if it exists). 384 status_t drainQueueAndFreeBuffersLocked(); 385 386 // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots 387 // that will be used if the producer does not override the buffer slot 388 // count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. 389 // The initial default is 2. 390 status_t setDefaultMaxBufferCountLocked(int count); 391 392 // getMinBufferCountLocked returns the minimum number of buffers allowed 393 // given the current BufferQueue state. 394 int getMinMaxBufferCountLocked() const; 395 396 // getMinUndequeuedBufferCountLocked returns the minimum number of buffers 397 // that must remain in a state other than DEQUEUED. 398 int getMinUndequeuedBufferCountLocked() const; 399 400 // getMaxBufferCountLocked returns the maximum number of buffers that can 401 // be allocated at once. This value depends upon the following member 402 // variables: 403 // 404 // mSynchronousMode 405 // mMaxAcquiredBufferCount 406 // mDefaultMaxBufferCount 407 // mOverrideMaxBufferCount 408 // 409 // Any time one of these member variables is changed while a producer is 410 // connected, mDequeueCondition must be broadcast. 411 int getMaxBufferCountLocked() const; 412 413 struct BufferSlot { 414 BufferSlotBufferSlot415 BufferSlot() 416 : mEglDisplay(EGL_NO_DISPLAY), 417 mBufferState(BufferSlot::FREE), 418 mRequestBufferCalled(false), 419 mTransform(0), 420 mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), 421 mTimestamp(0), 422 mFrameNumber(0), 423 mEglFence(EGL_NO_SYNC_KHR), 424 mAcquireCalled(false), 425 mNeedsCleanupOnRelease(false) { 426 mCrop.makeInvalid(); 427 } 428 429 // mGraphicBuffer points to the buffer allocated for this slot or is NULL 430 // if no buffer has been allocated. 431 sp<GraphicBuffer> mGraphicBuffer; 432 433 // mEglDisplay is the EGLDisplay used to create EGLSyncKHR objects. 434 EGLDisplay mEglDisplay; 435 436 // BufferState represents the different states in which a buffer slot 437 // can be. All slots are initially FREE. 438 enum BufferState { 439 // FREE indicates that the buffer is available to be dequeued 440 // by the producer. The buffer may be in use by the consumer for 441 // a finite time, so the buffer must not be modified until the 442 // associated fence is signaled. 443 // 444 // The slot is "owned" by BufferQueue. It transitions to DEQUEUED 445 // when dequeueBuffer is called. 446 FREE = 0, 447 448 // DEQUEUED indicates that the buffer has been dequeued by the 449 // producer, but has not yet been queued or canceled. The 450 // producer may modify the buffer's contents as soon as the 451 // associated ready fence is signaled. 452 // 453 // The slot is "owned" by the producer. It can transition to 454 // QUEUED (via queueBuffer) or back to FREE (via cancelBuffer). 455 DEQUEUED = 1, 456 457 // QUEUED indicates that the buffer has been filled by the 458 // producer and queued for use by the consumer. The buffer 459 // contents may continue to be modified for a finite time, so 460 // the contents must not be accessed until the associated fence 461 // is signaled. 462 // 463 // The slot is "owned" by BufferQueue. It can transition to 464 // ACQUIRED (via acquireBuffer) or to FREE (if another buffer is 465 // queued in asynchronous mode). 466 QUEUED = 2, 467 468 // ACQUIRED indicates that the buffer has been acquired by the 469 // consumer. As with QUEUED, the contents must not be accessed 470 // by the consumer until the fence is signaled. 471 // 472 // The slot is "owned" by the consumer. It transitions to FREE 473 // when releaseBuffer is called. 474 ACQUIRED = 3 475 }; 476 477 // mBufferState is the current state of this buffer slot. 478 BufferState mBufferState; 479 480 // mRequestBufferCalled is used for validating that the producer did 481 // call requestBuffer() when told to do so. Technically this is not 482 // needed but useful for debugging and catching producer bugs. 483 bool mRequestBufferCalled; 484 485 // mCrop is the current crop rectangle for this buffer slot. 486 Rect mCrop; 487 488 // mTransform is the current transform flags for this buffer slot. 489 // (example: NATIVE_WINDOW_TRANSFORM_ROT_90) 490 uint32_t mTransform; 491 492 // mScalingMode is the current scaling mode for this buffer slot. 493 // (example: NATIVE_WINDOW_SCALING_MODE_FREEZE) 494 uint32_t mScalingMode; 495 496 // mTimestamp is the current timestamp for this buffer slot. This gets 497 // to set by queueBuffer each time this slot is queued. 498 int64_t mTimestamp; 499 500 // mFrameNumber is the number of the queued frame for this slot. This 501 // is used to dequeue buffers in LRU order (useful because buffers 502 // may be released before their release fence is signaled). 503 uint64_t mFrameNumber; 504 505 // mEglFence is the EGL sync object that must signal before the buffer 506 // associated with this buffer slot may be dequeued. It is initialized 507 // to EGL_NO_SYNC_KHR when the buffer is created and may be set to a 508 // new sync object in releaseBuffer. (This is deprecated in favor of 509 // mFence, below.) 510 EGLSyncKHR mEglFence; 511 512 // mFence is a fence which will signal when work initiated by the 513 // previous owner of the buffer is finished. When the buffer is FREE, 514 // the fence indicates when the consumer has finished reading 515 // from the buffer, or when the producer has finished writing if it 516 // called cancelBuffer after queueing some writes. When the buffer is 517 // QUEUED, it indicates when the producer has finished filling the 518 // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been 519 // passed to the consumer or producer along with ownership of the 520 // buffer, and mFence is set to NO_FENCE. 521 sp<Fence> mFence; 522 523 // Indicates whether this buffer has been seen by a consumer yet 524 bool mAcquireCalled; 525 526 // Indicates whether this buffer needs to be cleaned up by the 527 // consumer. This is set when a buffer in ACQUIRED state is freed. 528 // It causes releaseBuffer to return STALE_BUFFER_SLOT. 529 bool mNeedsCleanupOnRelease; 530 }; 531 532 // mSlots is the array of buffer slots that must be mirrored on the 533 // producer side. This allows buffer ownership to be transferred between 534 // the producer and consumer without sending a GraphicBuffer over binder. 535 // The entire array is initialized to NULL at construction time, and 536 // buffers are allocated for a slot when requestBuffer is called with 537 // that slot's index. 538 BufferSlot mSlots[NUM_BUFFER_SLOTS]; 539 540 // mDefaultWidth holds the default width of allocated buffers. It is used 541 // in dequeueBuffer() if a width and height of zero is specified. 542 uint32_t mDefaultWidth; 543 544 // mDefaultHeight holds the default height of allocated buffers. It is used 545 // in dequeueBuffer() if a width and height of zero is specified. 546 uint32_t mDefaultHeight; 547 548 // mMaxAcquiredBufferCount is the number of buffers that the consumer may 549 // acquire at one time. It defaults to 1 and can be changed by the 550 // consumer via the setMaxAcquiredBufferCount method, but this may only be 551 // done when no producer is connected to the BufferQueue. 552 // 553 // This value is used to derive the value returned for the 554 // MIN_UNDEQUEUED_BUFFERS query by the producer. 555 int mMaxAcquiredBufferCount; 556 557 // mDefaultMaxBufferCount is the default limit on the number of buffers 558 // that will be allocated at one time. This default limit is set by the 559 // consumer. The limit (as opposed to the default limit) may be 560 // overridden by the producer. 561 int mDefaultMaxBufferCount; 562 563 // mOverrideMaxBufferCount is the limit on the number of buffers that will 564 // be allocated at one time. This value is set by the image producer by 565 // calling setBufferCount. The default is zero, which means the producer 566 // doesn't care about the number of buffers in the pool. In that case 567 // mDefaultMaxBufferCount is used as the limit. 568 int mOverrideMaxBufferCount; 569 570 // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to 571 // allocate new GraphicBuffer objects. 572 sp<IGraphicBufferAlloc> mGraphicBufferAlloc; 573 574 // mConsumerListener is used to notify the connected consumer of 575 // asynchronous events that it may wish to react to. It is initially set 576 // to NULL and is written by consumerConnect and consumerDisconnect. 577 sp<ConsumerListener> mConsumerListener; 578 579 // mSynchronousMode whether we're in synchronous mode or not 580 bool mSynchronousMode; 581 582 // mAllowSynchronousMode whether we allow synchronous mode or not. Set 583 // when the BufferQueue is created (by the consumer). 584 const bool mAllowSynchronousMode; 585 586 // mConnectedApi indicates the producer API that is currently connected 587 // to this BufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets 588 // updated by the connect and disconnect methods. 589 int mConnectedApi; 590 591 // mDequeueCondition condition used for dequeueBuffer in synchronous mode 592 mutable Condition mDequeueCondition; 593 594 // mQueue is a FIFO of queued buffers used in synchronous mode 595 typedef Vector<int> Fifo; 596 Fifo mQueue; 597 598 // mAbandoned indicates that the BufferQueue will no longer be used to 599 // consume image buffers pushed to it using the IGraphicBufferProducer 600 // interface. It is initialized to false, and set to true in the 601 // consumerDisconnect method. A BufferQueue that has been abandoned will 602 // return the NO_INIT error from all IGraphicBufferProducer methods 603 // capable of returning an error. 604 bool mAbandoned; 605 606 // mConsumerName is a string used to identify the BufferQueue in log 607 // messages. It is set by the setConsumerName method. 608 String8 mConsumerName; 609 610 // mMutex is the mutex used to prevent concurrent access to the member 611 // variables of BufferQueue objects. It must be locked whenever the 612 // member variables are accessed. 613 mutable Mutex mMutex; 614 615 // mFrameCounter is the free running counter, incremented on every 616 // successful queueBuffer call. 617 uint64_t mFrameCounter; 618 619 // mBufferHasBeenQueued is true once a buffer has been queued. It is 620 // reset when something causes all buffers to be freed (e.g. changing the 621 // buffer count). 622 bool mBufferHasBeenQueued; 623 624 // mDefaultBufferFormat can be set so it will override 625 // the buffer format when it isn't specified in dequeueBuffer 626 uint32_t mDefaultBufferFormat; 627 628 // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers 629 uint32_t mConsumerUsageBits; 630 631 // mTransformHint is used to optimize for screen rotations 632 uint32_t mTransformHint; 633 }; 634 635 // ---------------------------------------------------------------------------- 636 }; // namespace android 637 638 #endif // ANDROID_GUI_BUFFERQUEUE_H 639