1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gonk/nativewindow/GonkBufferQueueKK.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,570 @@ 1.4 +/* 1.5 + * Copyright (C) 2012 The Android Open Source Project 1.6 + * Copyright (C) 2013 Mozilla Foundation 1.7 + * 1.8 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.9 + * you may not use this file except in compliance with the License. 1.10 + * You may obtain a copy of the License at 1.11 + * 1.12 + * http://www.apache.org/licenses/LICENSE-2.0 1.13 + * 1.14 + * Unless required by applicable law or agreed to in writing, software 1.15 + * distributed under the License is distributed on an "AS IS" BASIS, 1.16 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.17 + * See the License for the specific language governing permissions and 1.18 + * limitations under the License. 1.19 + */ 1.20 + 1.21 +#ifndef NATIVEWINDOW_GONKBUFFERQUEUE_KK_H 1.22 +#define NATIVEWINDOW_GONKBUFFERQUEUE_KK_H 1.23 + 1.24 +#include <gui/IConsumerListener.h> 1.25 +#include <gui/IGraphicBufferAlloc.h> 1.26 +#include <gui/IGraphicBufferProducer.h> 1.27 +#include "IGonkGraphicBufferConsumer.h" 1.28 + 1.29 +#include <ui/Fence.h> 1.30 +#include <ui/GraphicBuffer.h> 1.31 + 1.32 +#include <utils/String8.h> 1.33 +#include <utils/Vector.h> 1.34 +#include <utils/threads.h> 1.35 + 1.36 +#include "mozilla/layers/LayersSurfaces.h" 1.37 +#include "mozilla/layers/TextureClient.h" 1.38 + 1.39 +namespace android { 1.40 +// ---------------------------------------------------------------------------- 1.41 + 1.42 +class GonkBufferQueue : public BnGraphicBufferProducer, 1.43 + public BnGonkGraphicBufferConsumer, 1.44 + private IBinder::DeathRecipient { 1.45 + typedef mozilla::layers::TextureClient TextureClient; 1.46 + 1.47 +public: 1.48 + enum { MIN_UNDEQUEUED_BUFFERS = 2 }; 1.49 + enum { NUM_BUFFER_SLOTS = 32 }; 1.50 + enum { NO_CONNECTED_API = 0 }; 1.51 + enum { INVALID_BUFFER_SLOT = -1 }; 1.52 + enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE, PRESENT_LATER }; 1.53 + 1.54 + // When in async mode we reserve two slots in order to guarantee that the 1.55 + // producer and consumer can run asynchronously. 1.56 + enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 }; 1.57 + 1.58 + // for backward source compatibility 1.59 + typedef ::android::ConsumerListener ConsumerListener; 1.60 + 1.61 + // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak 1.62 + // reference to the actual consumer object. It forwards all calls to that 1.63 + // consumer object so long as it exists. 1.64 + // 1.65 + // This class exists to avoid having a circular reference between the 1.66 + // GonkBufferQueue object and the consumer object. The reason this can't be a weak 1.67 + // reference in the GonkBufferQueue class is because we're planning to expose the 1.68 + // consumer side of a GonkBufferQueue as a binder interface, which doesn't support 1.69 + // weak references. 1.70 + class ProxyConsumerListener : public BnConsumerListener { 1.71 + public: 1.72 + ProxyConsumerListener(const wp<ConsumerListener>& consumerListener); 1.73 + virtual ~ProxyConsumerListener(); 1.74 + virtual void onFrameAvailable(); 1.75 + virtual void onBuffersReleased(); 1.76 + private: 1.77 + // mConsumerListener is a weak reference to the IConsumerListener. This is 1.78 + // the raison d'etre of ProxyConsumerListener. 1.79 + wp<ConsumerListener> mConsumerListener; 1.80 + }; 1.81 + 1.82 + 1.83 + // BufferQueue manages a pool of gralloc memory slots to be used by 1.84 + // producers and consumers. allocator is used to allocate all the 1.85 + // needed gralloc buffers. 1.86 + GonkBufferQueue(bool allowSynchronousMode = true, 1.87 + const sp<IGraphicBufferAlloc>& allocator = NULL); 1.88 + virtual ~GonkBufferQueue(); 1.89 + 1.90 + /* 1.91 + * IBinder::DeathRecipient interface 1.92 + */ 1.93 + 1.94 + virtual void binderDied(const wp<IBinder>& who); 1.95 + 1.96 + /* 1.97 + * IGraphicBufferProducer interface 1.98 + */ 1.99 + 1.100 + // Query native window attributes. The "what" values are enumerated in 1.101 + // window.h (e.g. NATIVE_WINDOW_FORMAT). 1.102 + virtual int query(int what, int* value); 1.103 + 1.104 + // setBufferCount updates the number of available buffer slots. If this 1.105 + // method succeeds, buffer slots will be both unallocated and owned by 1.106 + // the GonkBufferQueue object (i.e. they are not owned by the producer or 1.107 + // consumer). 1.108 + // 1.109 + // This will fail if the producer has dequeued any buffers, or if 1.110 + // bufferCount is invalid. bufferCount must generally be a value 1.111 + // between the minimum undequeued buffer count and NUM_BUFFER_SLOTS 1.112 + // (inclusive). It may also be set to zero (the default) to indicate 1.113 + // that the producer does not wish to set a value. The minimum value 1.114 + // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, 1.115 + // ...). 1.116 + // 1.117 + // This may only be called by the producer. The consumer will be told 1.118 + // to discard buffers through the onBuffersReleased callback. 1.119 + virtual status_t setBufferCount(int bufferCount); 1.120 + 1.121 + // requestBuffer returns the GraphicBuffer for slot N. 1.122 + // 1.123 + // In normal operation, this is called the first time slot N is returned 1.124 + // by dequeueBuffer. It must be called again if dequeueBuffer returns 1.125 + // flags indicating that previously-returned buffers are no longer valid. 1.126 + virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf); 1.127 + 1.128 + // dequeueBuffer gets the next buffer slot index for the producer to use. 1.129 + // If a buffer slot is available then that slot index is written to the 1.130 + // location pointed to by the buf argument and a status of OK is returned. 1.131 + // If no slot is available then a status of -EBUSY is returned and buf is 1.132 + // unmodified. 1.133 + // 1.134 + // The fence parameter will be updated to hold the fence associated with 1.135 + // the buffer. The contents of the buffer must not be overwritten until the 1.136 + // fence signals. If the fence is Fence::NO_FENCE, the buffer may be 1.137 + // written immediately. 1.138 + // 1.139 + // The width and height parameters must be no greater than the minimum of 1.140 + // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). 1.141 + // An error due to invalid dimensions might not be reported until 1.142 + // updateTexImage() is called. If width and height are both zero, the 1.143 + // default values specified by setDefaultBufferSize() are used instead. 1.144 + // 1.145 + // The pixel formats are enumerated in graphics.h, e.g. 1.146 + // HAL_PIXEL_FORMAT_RGBA_8888. If the format is 0, the default format 1.147 + // will be used. 1.148 + // 1.149 + // The usage argument specifies gralloc buffer usage flags. The values 1.150 + // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER. These 1.151 + // will be merged with the usage flags specified by setConsumerUsageBits. 1.152 + // 1.153 + // The return value may be a negative error value or a non-negative 1.154 + // collection of flags. If the flags are set, the return values are 1.155 + // valid, but additional actions must be performed. 1.156 + // 1.157 + // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the 1.158 + // producer must discard cached GraphicBuffer references for the slot 1.159 + // returned in buf. 1.160 + // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer 1.161 + // must discard cached GraphicBuffer references for all slots. 1.162 + // 1.163 + // In both cases, the producer will need to call requestBuffer to get a 1.164 + // GraphicBuffer handle for the returned slot. 1.165 + virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async, 1.166 + uint32_t width, uint32_t height, uint32_t format, uint32_t usage); 1.167 + 1.168 + // queueBuffer returns a filled buffer to the GonkBufferQueue. 1.169 + // 1.170 + // Additional data is provided in the QueueBufferInput struct. Notably, 1.171 + // a timestamp must be provided for the buffer. The timestamp is in 1.172 + // nanoseconds, and must be monotonically increasing. Its other semantics 1.173 + // (zero point, etc) are producer-specific and should be documented by the 1.174 + // producer. 1.175 + // 1.176 + // The caller may provide a fence that signals when all rendering 1.177 + // operations have completed. Alternatively, NO_FENCE may be used, 1.178 + // indicating that the buffer is ready immediately. 1.179 + // 1.180 + // Some values are returned in the output struct: the current settings 1.181 + // for default width and height, the current transform hint, and the 1.182 + // number of queued buffers. 1.183 + virtual status_t queueBuffer(int buf, 1.184 + const QueueBufferInput& input, QueueBufferOutput* output); 1.185 + 1.186 + // cancelBuffer returns a dequeued buffer to the GonkBufferQueue, but doesn't 1.187 + // queue it for use by the consumer. 1.188 + // 1.189 + // The buffer will not be overwritten until the fence signals. The fence 1.190 + // will usually be the one obtained from dequeueBuffer. 1.191 + virtual void cancelBuffer(int buf, const sp<Fence>& fence); 1.192 + 1.193 + // connect attempts to connect a producer API to the GonkBufferQueue. This 1.194 + // must be called before any other IGraphicBufferProducer methods are 1.195 + // called except for getAllocator. A consumer must already be connected. 1.196 + // 1.197 + // This method will fail if connect was previously called on the 1.198 + // GonkBufferQueue and no corresponding disconnect call was made (i.e. if 1.199 + // it's still connected to a producer). 1.200 + // 1.201 + // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU). 1.202 + virtual status_t connect(const sp<IBinder>& token, 1.203 + int api, bool producerControlledByApp, QueueBufferOutput* output); 1.204 + 1.205 + // disconnect attempts to disconnect a producer API from the GonkBufferQueue. 1.206 + // Calling this method will cause any subsequent calls to other 1.207 + // IGraphicBufferProducer methods to fail except for getAllocator and connect. 1.208 + // Successfully calling connect after this will allow the other methods to 1.209 + // succeed again. 1.210 + // 1.211 + // This method will fail if the the GonkBufferQueue is not currently 1.212 + // connected to the specified producer API. 1.213 + virtual status_t disconnect(int api); 1.214 + 1.215 + /* 1.216 + * IGraphicBufferConsumer interface 1.217 + */ 1.218 + 1.219 + // acquireBuffer attempts to acquire ownership of the next pending buffer in 1.220 + // the GonkBufferQueue. If no buffer is pending then it returns -EINVAL. If a 1.221 + // buffer is successfully acquired, the information about the buffer is 1.222 + // returned in BufferItem. If the buffer returned had previously been 1.223 + // acquired then the BufferItem::mGraphicBuffer field of buffer is set to 1.224 + // NULL and it is assumed that the consumer still holds a reference to the 1.225 + // buffer. 1.226 + // 1.227 + // If presentWhen is nonzero, it indicates the time when the buffer will 1.228 + // be displayed on screen. If the buffer's timestamp is farther in the 1.229 + // future, the buffer won't be acquired, and PRESENT_LATER will be 1.230 + // returned. The presentation time is in nanoseconds, and the time base 1.231 + // is CLOCK_MONOTONIC. 1.232 + virtual status_t acquireBuffer(BufferItem *buffer, nsecs_t presentWhen); 1.233 + 1.234 + // releaseBuffer releases a buffer slot from the consumer back to the 1.235 + // GonkBufferQueue. This may be done while the buffer's contents are still 1.236 + // being accessed. The fence will signal when the buffer is no longer 1.237 + // in use. frameNumber is used to indentify the exact buffer returned. 1.238 + // 1.239 + // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free 1.240 + // any references to the just-released buffer that it might have, as if it 1.241 + // had received a onBuffersReleased() call with a mask set for the released 1.242 + // buffer. 1.243 + // 1.244 + // Note that the dependencies on EGL will be removed once we switch to using 1.245 + // the Android HW Sync HAL. 1.246 + virtual status_t releaseBuffer(int buf, uint64_t frameNumber, 1.247 + const sp<Fence>& releaseFence); 1.248 + 1.249 + // consumerConnect connects a consumer to the GonkBufferQueue. Only one 1.250 + // consumer may be connected, and when that consumer disconnects the 1.251 + // GonkBufferQueue is placed into the "abandoned" state, causing most 1.252 + // interactions with the GonkBufferQueue by the producer to fail. 1.253 + // controlledByApp indicates whether the consumer is controlled by 1.254 + // the application. 1.255 + // 1.256 + // consumer may not be NULL. 1.257 + virtual status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp); 1.258 + 1.259 + // consumerDisconnect disconnects a consumer from the GonkBufferQueue. All 1.260 + // buffers will be freed and the GonkBufferQueue is placed in the "abandoned" 1.261 + // state, causing most interactions with the GonkBufferQueue by the producer to 1.262 + // fail. 1.263 + virtual status_t consumerDisconnect(); 1.264 + 1.265 + // getReleasedBuffers sets the value pointed to by slotMask to a bit mask 1.266 + // indicating which buffer slots have been released by the GonkBufferQueue 1.267 + // but have not yet been released by the consumer. 1.268 + // 1.269 + // This should be called from the onBuffersReleased() callback. 1.270 + virtual status_t getReleasedBuffers(uint32_t* slotMask); 1.271 + 1.272 + // setDefaultBufferSize is used to set the size of buffers returned by 1.273 + // dequeueBuffer when a width and height of zero is requested. Default 1.274 + // is 1x1. 1.275 + virtual status_t setDefaultBufferSize(uint32_t w, uint32_t h); 1.276 + 1.277 + // setDefaultMaxBufferCount sets the default value for the maximum buffer 1.278 + // count (the initial default is 2). If the producer has requested a 1.279 + // buffer count using setBufferCount, the default buffer count will only 1.280 + // take effect if the producer sets the count back to zero. 1.281 + // 1.282 + // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. 1.283 + virtual status_t setDefaultMaxBufferCount(int bufferCount); 1.284 + 1.285 + // disableAsyncBuffer disables the extra buffer used in async mode 1.286 + // (when both producer and consumer have set their "isControlledByApp" 1.287 + // flag) and has dequeueBuffer() return WOULD_BLOCK instead. 1.288 + // 1.289 + // This can only be called before consumerConnect(). 1.290 + virtual status_t disableAsyncBuffer(); 1.291 + 1.292 + // setMaxAcquiredBufferCount sets the maximum number of buffers that can 1.293 + // be acquired by the consumer at one time (default 1). This call will 1.294 + // fail if a producer is connected to the GonkBufferQueue. 1.295 + virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers); 1.296 + 1.297 + // setConsumerName sets the name used in logging 1.298 + virtual void setConsumerName(const String8& name); 1.299 + 1.300 + // setDefaultBufferFormat allows the GonkBufferQueue to create 1.301 + // GraphicBuffers of a defaultFormat if no format is specified 1.302 + // in dequeueBuffer. Formats are enumerated in graphics.h; the 1.303 + // initial default is HAL_PIXEL_FORMAT_RGBA_8888. 1.304 + virtual status_t setDefaultBufferFormat(uint32_t defaultFormat); 1.305 + 1.306 + // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. 1.307 + // These are merged with the bits passed to dequeueBuffer. The values are 1.308 + // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0. 1.309 + virtual status_t setConsumerUsageBits(uint32_t usage); 1.310 + 1.311 + // setTransformHint bakes in rotation to buffers so overlays can be used. 1.312 + // The values are enumerated in window.h, e.g. 1.313 + // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). 1.314 + virtual status_t setTransformHint(uint32_t hint); 1.315 + 1.316 + // dump our state in a String 1.317 + virtual void dump(String8& result, const char* prefix) const; 1.318 + 1.319 + mozilla::TemporaryRef<TextureClient> getTextureClientFromBuffer(ANativeWindowBuffer* buffer); 1.320 + 1.321 + int getSlotFromTextureClientLocked(TextureClient* client) const; 1.322 + 1.323 +private: 1.324 + // freeBufferLocked frees the GraphicBuffer and sync resources for the 1.325 + // given slot. 1.326 + //void freeBufferLocked(int index); 1.327 + 1.328 + // freeAllBuffersLocked frees the GraphicBuffer and sync resources for 1.329 + // all slots. 1.330 + //void freeAllBuffersLocked(); 1.331 + void freeAllBuffersLocked(); 1.332 + 1.333 + // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots 1.334 + // that will be used if the producer does not override the buffer slot 1.335 + // count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. 1.336 + // The initial default is 2. 1.337 + status_t setDefaultMaxBufferCountLocked(int count); 1.338 + 1.339 + // getMinUndequeuedBufferCount returns the minimum number of buffers 1.340 + // that must remain in a state other than DEQUEUED. 1.341 + // The async parameter tells whether we're in asynchronous mode. 1.342 + int getMinUndequeuedBufferCount(bool async) const; 1.343 + 1.344 + // getMinBufferCountLocked returns the minimum number of buffers allowed 1.345 + // given the current GonkBufferQueue state. 1.346 + // The async parameter tells whether we're in asynchronous mode. 1.347 + int getMinMaxBufferCountLocked(bool async) const; 1.348 + 1.349 + // getMaxBufferCountLocked returns the maximum number of buffers that can 1.350 + // be allocated at once. This value depends upon the following member 1.351 + // variables: 1.352 + // 1.353 + // mDequeueBufferCannotBlock 1.354 + // mMaxAcquiredBufferCount 1.355 + // mDefaultMaxBufferCount 1.356 + // mOverrideMaxBufferCount 1.357 + // async parameter 1.358 + // 1.359 + // Any time one of these member variables is changed while a producer is 1.360 + // connected, mDequeueCondition must be broadcast. 1.361 + int getMaxBufferCountLocked(bool async) const; 1.362 + 1.363 + // stillTracking returns true iff the buffer item is still being tracked 1.364 + // in one of the slots. 1.365 + bool stillTracking(const BufferItem *item) const; 1.366 + 1.367 + struct BufferSlot { 1.368 + 1.369 + BufferSlot() 1.370 + : mBufferState(BufferSlot::FREE), 1.371 + mRequestBufferCalled(false), 1.372 + mFrameNumber(0), 1.373 + mAcquireCalled(false), 1.374 + mNeedsCleanupOnRelease(false) { 1.375 + } 1.376 + 1.377 + // mGraphicBuffer points to the buffer allocated for this slot or is NULL 1.378 + // if no buffer has been allocated. 1.379 + sp<GraphicBuffer> mGraphicBuffer; 1.380 + 1.381 + // mTextureClient is a thin abstraction over remotely allocated GraphicBuffer. 1.382 + mozilla::RefPtr<TextureClient> mTextureClient; 1.383 + 1.384 + // BufferState represents the different states in which a buffer slot 1.385 + // can be. All slots are initially FREE. 1.386 + enum BufferState { 1.387 + // FREE indicates that the buffer is available to be dequeued 1.388 + // by the producer. The buffer may be in use by the consumer for 1.389 + // a finite time, so the buffer must not be modified until the 1.390 + // associated fence is signaled. 1.391 + // 1.392 + // The slot is "owned" by GonkBufferQueue. It transitions to DEQUEUED 1.393 + // when dequeueBuffer is called. 1.394 + FREE = 0, 1.395 + 1.396 + // DEQUEUED indicates that the buffer has been dequeued by the 1.397 + // producer, but has not yet been queued or canceled. The 1.398 + // producer may modify the buffer's contents as soon as the 1.399 + // associated ready fence is signaled. 1.400 + // 1.401 + // The slot is "owned" by the producer. It can transition to 1.402 + // QUEUED (via queueBuffer) or back to FREE (via cancelBuffer). 1.403 + DEQUEUED = 1, 1.404 + 1.405 + // QUEUED indicates that the buffer has been filled by the 1.406 + // producer and queued for use by the consumer. The buffer 1.407 + // contents may continue to be modified for a finite time, so 1.408 + // the contents must not be accessed until the associated fence 1.409 + // is signaled. 1.410 + // 1.411 + // The slot is "owned" by GonkBufferQueue. It can transition to 1.412 + // ACQUIRED (via acquireBuffer) or to FREE (if another buffer is 1.413 + // queued in asynchronous mode). 1.414 + QUEUED = 2, 1.415 + 1.416 + // ACQUIRED indicates that the buffer has been acquired by the 1.417 + // consumer. As with QUEUED, the contents must not be accessed 1.418 + // by the consumer until the fence is signaled. 1.419 + // 1.420 + // The slot is "owned" by the consumer. It transitions to FREE 1.421 + // when releaseBuffer is called. 1.422 + ACQUIRED = 3 1.423 + }; 1.424 + 1.425 + // mBufferState is the current state of this buffer slot. 1.426 + BufferState mBufferState; 1.427 + 1.428 + // mRequestBufferCalled is used for validating that the producer did 1.429 + // call requestBuffer() when told to do so. Technically this is not 1.430 + // needed but useful for debugging and catching producer bugs. 1.431 + bool mRequestBufferCalled; 1.432 + 1.433 + // mFrameNumber is the number of the queued frame for this slot. This 1.434 + // is used to dequeue buffers in LRU order (useful because buffers 1.435 + // may be released before their release fence is signaled). 1.436 + uint64_t mFrameNumber; 1.437 + 1.438 + // mFence is a fence which will signal when work initiated by the 1.439 + // previous owner of the buffer is finished. When the buffer is FREE, 1.440 + // the fence indicates when the consumer has finished reading 1.441 + // from the buffer, or when the producer has finished writing if it 1.442 + // called cancelBuffer after queueing some writes. When the buffer is 1.443 + // QUEUED, it indicates when the producer has finished filling the 1.444 + // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been 1.445 + // passed to the consumer or producer along with ownership of the 1.446 + // buffer, and mFence is set to NO_FENCE. 1.447 + sp<Fence> mFence; 1.448 + 1.449 + // Indicates whether this buffer has been seen by a consumer yet 1.450 + bool mAcquireCalled; 1.451 + 1.452 + // Indicates whether this buffer needs to be cleaned up by the 1.453 + // consumer. This is set when a buffer in ACQUIRED state is freed. 1.454 + // It causes releaseBuffer to return STALE_BUFFER_SLOT. 1.455 + bool mNeedsCleanupOnRelease; 1.456 + }; 1.457 + 1.458 + // mSlots is the array of buffer slots that must be mirrored on the 1.459 + // producer side. This allows buffer ownership to be transferred between 1.460 + // the producer and consumer without sending a GraphicBuffer over binder. 1.461 + // The entire array is initialized to NULL at construction time, and 1.462 + // buffers are allocated for a slot when requestBuffer is called with 1.463 + // that slot's index. 1.464 + BufferSlot mSlots[NUM_BUFFER_SLOTS]; 1.465 + 1.466 + // mDefaultWidth holds the default width of allocated buffers. It is used 1.467 + // in dequeueBuffer() if a width and height of zero is specified. 1.468 + uint32_t mDefaultWidth; 1.469 + 1.470 + // mDefaultHeight holds the default height of allocated buffers. It is used 1.471 + // in dequeueBuffer() if a width and height of zero is specified. 1.472 + uint32_t mDefaultHeight; 1.473 + 1.474 + // mMaxAcquiredBufferCount is the number of buffers that the consumer may 1.475 + // acquire at one time. It defaults to 1 and can be changed by the 1.476 + // consumer via the setMaxAcquiredBufferCount method, but this may only be 1.477 + // done when no producer is connected to the GonkBufferQueue. 1.478 + // 1.479 + // This value is used to derive the value returned for the 1.480 + // MIN_UNDEQUEUED_BUFFERS query by the producer. 1.481 + int mMaxAcquiredBufferCount; 1.482 + 1.483 + // mDefaultMaxBufferCount is the default limit on the number of buffers 1.484 + // that will be allocated at one time. This default limit is set by the 1.485 + // consumer. The limit (as opposed to the default limit) may be 1.486 + // overridden by the producer. 1.487 + int mDefaultMaxBufferCount; 1.488 + 1.489 + // mOverrideMaxBufferCount is the limit on the number of buffers that will 1.490 + // be allocated at one time. This value is set by the image producer by 1.491 + // calling setBufferCount. The default is zero, which means the producer 1.492 + // doesn't care about the number of buffers in the pool. In that case 1.493 + // mDefaultMaxBufferCount is used as the limit. 1.494 + int mOverrideMaxBufferCount; 1.495 + 1.496 + // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to 1.497 + // allocate new GraphicBuffer objects. 1.498 + sp<IGraphicBufferAlloc> mGraphicBufferAlloc; 1.499 + 1.500 + // mConsumerListener is used to notify the connected consumer of 1.501 + // asynchronous events that it may wish to react to. It is initially set 1.502 + // to NULL and is written by consumerConnect and consumerDisconnect. 1.503 + sp<IConsumerListener> mConsumerListener; 1.504 + 1.505 + // mConsumerControlledByApp whether the connected consumer is controlled by the 1.506 + // application. 1.507 + bool mConsumerControlledByApp; 1.508 + 1.509 + // mDequeueBufferCannotBlock whether dequeueBuffer() isn't allowed to block. 1.510 + // this flag is set during connect() when both consumer and producer are controlled 1.511 + // by the application. 1.512 + bool mDequeueBufferCannotBlock; 1.513 + 1.514 + // mUseAsyncBuffer whether an extra buffer is used in async mode to prevent 1.515 + // dequeueBuffer() from ever blocking. 1.516 + bool mUseAsyncBuffer; 1.517 + 1.518 + // mConnectedApi indicates the producer API that is currently connected 1.519 + // to this GonkBufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets 1.520 + // updated by the connect and disconnect methods. 1.521 + int mConnectedApi; 1.522 + 1.523 + // mDequeueCondition condition used for dequeueBuffer in synchronous mode 1.524 + mutable Condition mDequeueCondition; 1.525 + 1.526 + // mQueue is a FIFO of queued buffers used in synchronous mode 1.527 + typedef Vector<BufferItem> Fifo; 1.528 + Fifo mQueue; 1.529 + 1.530 + // mAbandoned indicates that the GonkBufferQueue will no longer be used to 1.531 + // consume image buffers pushed to it using the IGraphicBufferProducer 1.532 + // interface. It is initialized to false, and set to true in the 1.533 + // consumerDisconnect method. A GonkBufferQueue that has been abandoned will 1.534 + // return the NO_INIT error from all IGraphicBufferProducer methods 1.535 + // capable of returning an error. 1.536 + bool mAbandoned; 1.537 + 1.538 + // mConsumerName is a string used to identify the GonkBufferQueue in log 1.539 + // messages. It is set by the setConsumerName method. 1.540 + String8 mConsumerName; 1.541 + 1.542 + // mMutex is the mutex used to prevent concurrent access to the member 1.543 + // variables of GonkBufferQueue objects. It must be locked whenever the 1.544 + // member variables are accessed. 1.545 + mutable Mutex mMutex; 1.546 + 1.547 + // mFrameCounter is the free running counter, incremented on every 1.548 + // successful queueBuffer call, and buffer allocation. 1.549 + uint64_t mFrameCounter; 1.550 + 1.551 + // mBufferHasBeenQueued is true once a buffer has been queued. It is 1.552 + // reset when something causes all buffers to be freed (e.g. changing the 1.553 + // buffer count). 1.554 + bool mBufferHasBeenQueued; 1.555 + 1.556 + // mDefaultBufferFormat can be set so it will override 1.557 + // the buffer format when it isn't specified in dequeueBuffer 1.558 + uint32_t mDefaultBufferFormat; 1.559 + 1.560 + // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers 1.561 + uint32_t mConsumerUsageBits; 1.562 + 1.563 + // mTransformHint is used to optimize for screen rotations 1.564 + uint32_t mTransformHint; 1.565 + 1.566 + // mConnectedProducerToken is used to set a binder death notification on the producer 1.567 + sp<IBinder> mConnectedProducerToken; 1.568 +}; 1.569 + 1.570 +// ---------------------------------------------------------------------------- 1.571 +}; // namespace android 1.572 + 1.573 +#endif // ANDROID_GUI_BUFFERQUEUE_H