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