michael@0: /* michael@0: * Copyright (C) 2012 The Android Open Source Project michael@0: * Copyright (C) 2013 Mozilla Foundation michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef NATIVEWINDOW_GONKBUFFERQUEUE_JB_H michael@0: #define NATIVEWINDOW_GONKBUFFERQUEUE_JB_H michael@0: michael@0: #include michael@0: #if ANDROID_VERSION == 17 michael@0: #include michael@0: #else michael@0: #include michael@0: #endif michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "mozilla/layers/LayersSurfaces.h" michael@0: #include "mozilla/layers/TextureClient.h" michael@0: michael@0: #if ANDROID_VERSION == 17 michael@0: #define IGraphicBufferProducer ISurfaceTexture michael@0: #endif michael@0: michael@0: namespace android { michael@0: // ---------------------------------------------------------------------------- michael@0: michael@0: #if ANDROID_VERSION == 17 michael@0: class GonkBufferQueue : public BnSurfaceTexture { michael@0: #else michael@0: class GonkBufferQueue : public BnGraphicBufferProducer { michael@0: #endif michael@0: typedef mozilla::layers::TextureClient TextureClient; michael@0: michael@0: public: michael@0: enum { MIN_UNDEQUEUED_BUFFERS = 2 }; michael@0: enum { NUM_BUFFER_SLOTS = 32 }; michael@0: enum { NO_CONNECTED_API = 0 }; michael@0: enum { INVALID_BUFFER_SLOT = -1 }; michael@0: enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE }; michael@0: michael@0: // When in async mode we reserve two slots in order to guarantee that the michael@0: // producer and consumer can run asynchronously. michael@0: enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 }; michael@0: michael@0: // ConsumerListener is the interface through which the GonkBufferQueue notifies michael@0: // the consumer of events that the consumer may wish to react to. Because michael@0: // the consumer will generally have a mutex that is locked during calls from michael@0: // the consumer to the GonkBufferQueue, these calls from the GonkBufferQueue to the michael@0: // consumer *MUST* be called only when the GonkBufferQueue mutex is NOT locked. michael@0: struct ConsumerListener : public virtual RefBase { michael@0: // onFrameAvailable is called from queueBuffer each time an additional michael@0: // frame becomes available for consumption. This means that frames that michael@0: // are queued while in asynchronous mode only trigger the callback if no michael@0: // previous frames are pending. Frames queued while in synchronous mode michael@0: // always trigger the callback. michael@0: // michael@0: // This is called without any lock held and can be called concurrently michael@0: // by multiple threads. michael@0: virtual void onFrameAvailable() = 0; michael@0: michael@0: // onBuffersReleased is called to notify the buffer consumer that the michael@0: // GonkBufferQueue has released its references to one or more GraphicBuffers michael@0: // contained in its slots. The buffer consumer should then call michael@0: // GonkBufferQueue::getReleasedBuffers to retrieve the list of buffers michael@0: // michael@0: // This is called without any lock held and can be called concurrently michael@0: // by multiple threads. michael@0: virtual void onBuffersReleased() = 0; michael@0: }; michael@0: michael@0: // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak michael@0: // reference to the actual consumer object. It forwards all calls to that michael@0: // consumer object so long as it exists. michael@0: // michael@0: // This class exists to avoid having a circular reference between the michael@0: // GonkBufferQueue object and the consumer object. The reason this can't be a weak michael@0: // reference in the GonkBufferQueue class is because we're planning to expose the michael@0: // consumer side of a GonkBufferQueue as a binder interface, which doesn't support michael@0: // weak references. michael@0: class ProxyConsumerListener : public GonkBufferQueue::ConsumerListener { michael@0: public: michael@0: michael@0: ProxyConsumerListener(const wp& consumerListener); michael@0: virtual ~ProxyConsumerListener(); michael@0: virtual void onFrameAvailable(); michael@0: virtual void onBuffersReleased(); michael@0: michael@0: private: michael@0: michael@0: // mConsumerListener is a weak reference to the ConsumerListener. This is michael@0: // the raison d'etre of ProxyConsumerListener. michael@0: wp mConsumerListener; michael@0: }; michael@0: michael@0: michael@0: // GonkBufferQueue manages a pool of gralloc memory slots to be used by michael@0: // producers and consumers. allowSynchronousMode specifies whether or not michael@0: // synchronous mode can be enabled by the producer. allocator is used to michael@0: // allocate all the needed gralloc buffers. michael@0: GonkBufferQueue(bool allowSynchronousMode = true, michael@0: const sp& allocator = NULL); michael@0: virtual ~GonkBufferQueue(); michael@0: michael@0: // Query native window attributes. The "what" values are enumerated in michael@0: // window.h (e.g. NATIVE_WINDOW_FORMAT). michael@0: virtual int query(int what, int* value); michael@0: michael@0: // setBufferCount updates the number of available buffer slots. If this michael@0: // method succeeds, buffer slots will be both unallocated and owned by michael@0: // the GonkBufferQueue object (i.e. they are not owned by the producer or michael@0: // consumer). michael@0: // michael@0: // This will fail if the producer has dequeued any buffers, or if michael@0: // bufferCount is invalid. bufferCount must generally be a value michael@0: // between the minimum undequeued buffer count and NUM_BUFFER_SLOTS michael@0: // (inclusive). It may also be set to zero (the default) to indicate michael@0: // that the producer does not wish to set a value. The minimum value michael@0: // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, michael@0: // ...). michael@0: // michael@0: // This may only be called by the producer. The consumer will be told michael@0: // to discard buffers through the onBuffersReleased callback. michael@0: virtual status_t setBufferCount(int bufferCount); michael@0: michael@0: // requestBuffer returns the GraphicBuffer for slot N. michael@0: // michael@0: // In normal operation, this is called the first time slot N is returned michael@0: // by dequeueBuffer. It must be called again if dequeueBuffer returns michael@0: // flags indicating that previously-returned buffers are no longer valid. michael@0: virtual status_t requestBuffer(int slot, sp* buf); michael@0: michael@0: // dequeueBuffer gets the next buffer slot index for the producer to use. michael@0: // If a buffer slot is available then that slot index is written to the michael@0: // location pointed to by the buf argument and a status of OK is returned. michael@0: // If no slot is available then a status of -EBUSY is returned and buf is michael@0: // unmodified. michael@0: // michael@0: // The fence parameter will be updated to hold the fence associated with michael@0: // the buffer. The contents of the buffer must not be overwritten until the michael@0: // fence signals. If the fence is Fence::NO_FENCE, the buffer may be michael@0: // written immediately. michael@0: // michael@0: // The width and height parameters must be no greater than the minimum of michael@0: // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv). michael@0: // An error due to invalid dimensions might not be reported until michael@0: // updateTexImage() is called. If width and height are both zero, the michael@0: // default values specified by setDefaultBufferSize() are used instead. michael@0: // michael@0: // The pixel formats are enumerated in graphics.h, e.g. michael@0: // HAL_PIXEL_FORMAT_RGBA_8888. If the format is 0, the default format michael@0: // will be used. michael@0: // michael@0: // The usage argument specifies gralloc buffer usage flags. The values michael@0: // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER. These michael@0: // will be merged with the usage flags specified by setConsumerUsageBits. michael@0: // michael@0: // The return value may be a negative error value or a non-negative michael@0: // collection of flags. If the flags are set, the return values are michael@0: // valid, but additional actions must be performed. michael@0: // michael@0: // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the michael@0: // producer must discard cached GraphicBuffer references for the slot michael@0: // returned in buf. michael@0: // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer michael@0: // must discard cached GraphicBuffer references for all slots. michael@0: // michael@0: // In both cases, the producer will need to call requestBuffer to get a michael@0: // GraphicBuffer handle for the returned slot. michael@0: #if ANDROID_VERSION == 17 michael@0: virtual status_t dequeueBuffer(int *buf, sp& fence, michael@0: uint32_t width, uint32_t height, uint32_t format, uint32_t usage) { michael@0: return dequeueBuffer(buf, &fence, width, height, format, usage); michael@0: } michael@0: #endif michael@0: michael@0: virtual status_t dequeueBuffer(int *buf, sp* fence, michael@0: uint32_t width, uint32_t height, uint32_t format, uint32_t usage); michael@0: michael@0: // queueBuffer returns a filled buffer to the GonkBufferQueue. michael@0: // michael@0: // Additional data is provided in the QueueBufferInput struct. Notably, michael@0: // a timestamp must be provided for the buffer. The timestamp is in michael@0: // nanoseconds, and must be monotonically increasing. Its other semantics michael@0: // (zero point, etc) are producer-specific and should be documented by the michael@0: // producer. michael@0: // michael@0: // The caller may provide a fence that signals when all rendering michael@0: // operations have completed. Alternatively, NO_FENCE may be used, michael@0: // indicating that the buffer is ready immediately. michael@0: // michael@0: // Some values are returned in the output struct: the current settings michael@0: // for default width and height, the current transform hint, and the michael@0: // number of queued buffers. michael@0: virtual status_t queueBuffer(int buf, michael@0: const QueueBufferInput& input, QueueBufferOutput* output); michael@0: michael@0: // cancelBuffer returns a dequeued buffer to the GonkBufferQueue, but doesn't michael@0: // queue it for use by the consumer. michael@0: // michael@0: // The buffer will not be overwritten until the fence signals. The fence michael@0: // will usually be the one obtained from dequeueBuffer. michael@0: #if ANDROID_VERSION == 17 michael@0: virtual void cancelBuffer(int buf, sp fence); michael@0: #else michael@0: virtual void cancelBuffer(int buf, const sp& fence); michael@0: #endif michael@0: michael@0: // setSynchronousMode sets whether dequeueBuffer is synchronous or michael@0: // asynchronous. In synchronous mode, dequeueBuffer blocks until michael@0: // a buffer is available, the currently bound buffer can be dequeued and michael@0: // queued buffers will be acquired in order. In asynchronous mode, michael@0: // a queued buffer may be replaced by a subsequently queued buffer. michael@0: // michael@0: // The default mode is asynchronous. michael@0: virtual status_t setSynchronousMode(bool enabled); michael@0: michael@0: // connect attempts to connect a producer API to the GonkBufferQueue. This michael@0: // must be called before any other IGraphicBufferProducer methods are michael@0: // called except for getAllocator. A consumer must already be connected. michael@0: // michael@0: // This method will fail if connect was previously called on the michael@0: // GonkBufferQueue and no corresponding disconnect call was made (i.e. if michael@0: // it's still connected to a producer). michael@0: // michael@0: // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU). michael@0: virtual status_t connect(int api, QueueBufferOutput* output); michael@0: michael@0: // disconnect attempts to disconnect a producer API from the GonkBufferQueue. michael@0: // Calling this method will cause any subsequent calls to other michael@0: // IGraphicBufferProducer methods to fail except for getAllocator and connect. michael@0: // Successfully calling connect after this will allow the other methods to michael@0: // succeed again. michael@0: // michael@0: // This method will fail if the the GonkBufferQueue is not currently michael@0: // connected to the specified producer API. michael@0: virtual status_t disconnect(int api); michael@0: michael@0: // dump our state in a String michael@0: virtual void dump(String8& result) const; michael@0: virtual void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const; michael@0: michael@0: // public facing structure for BufferSlot michael@0: struct BufferItem { michael@0: michael@0: BufferItem() michael@0: : michael@0: mTransform(0), michael@0: mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), michael@0: mTimestamp(0), michael@0: mFrameNumber(0), michael@0: mBuf(INVALID_BUFFER_SLOT) { michael@0: mCrop.makeInvalid(); michael@0: } michael@0: // mGraphicBuffer points to the buffer allocated for this slot, or is NULL michael@0: // if the buffer in this slot has been acquired in the past (see michael@0: // BufferSlot.mAcquireCalled). michael@0: sp mGraphicBuffer; michael@0: michael@0: // mCrop is the current crop rectangle for this buffer slot. michael@0: Rect mCrop; michael@0: michael@0: // mTransform is the current transform flags for this buffer slot. michael@0: uint32_t mTransform; michael@0: michael@0: // mScalingMode is the current scaling mode for this buffer slot. michael@0: uint32_t mScalingMode; michael@0: michael@0: // mTimestamp is the current timestamp for this buffer slot. This gets michael@0: // to set by queueBuffer each time this slot is queued. michael@0: int64_t mTimestamp; michael@0: michael@0: // mFrameNumber is the number of the queued frame for this slot. michael@0: uint64_t mFrameNumber; michael@0: michael@0: // mBuf is the slot index of this buffer michael@0: int mBuf; michael@0: michael@0: // mFence is a fence that will signal when the buffer is idle. michael@0: sp mFence; michael@0: }; michael@0: michael@0: // The following public functions are the consumer-facing interface michael@0: michael@0: // acquireBuffer attempts to acquire ownership of the next pending buffer in michael@0: // the GonkBufferQueue. If no buffer is pending then it returns -EINVAL. If a michael@0: // buffer is successfully acquired, the information about the buffer is michael@0: // returned in BufferItem. If the buffer returned had previously been michael@0: // acquired then the BufferItem::mGraphicBuffer field of buffer is set to michael@0: // NULL and it is assumed that the consumer still holds a reference to the michael@0: // buffer. michael@0: status_t acquireBuffer(BufferItem *buffer); michael@0: michael@0: // releaseBuffer releases a buffer slot from the consumer back to the michael@0: // GonkBufferQueue. This may be done while the buffer's contents are still michael@0: // being accessed. The fence will signal when the buffer is no longer michael@0: // in use. michael@0: // michael@0: // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free michael@0: // any references to the just-released buffer that it might have, as if it michael@0: // had received a onBuffersReleased() call with a mask set for the released michael@0: // buffer. michael@0: // michael@0: // Note that the dependencies on EGL will be removed once we switch to using michael@0: // the Android HW Sync HAL. michael@0: status_t releaseBuffer(int buf, const sp& releaseFence); michael@0: michael@0: // consumerConnect connects a consumer to the GonkBufferQueue. Only one michael@0: // consumer may be connected, and when that consumer disconnects the michael@0: // GonkBufferQueue is placed into the "abandoned" state, causing most michael@0: // interactions with the GonkBufferQueue by the producer to fail. michael@0: // michael@0: // consumer may not be NULL. michael@0: status_t consumerConnect(const sp& consumer); michael@0: michael@0: // consumerDisconnect disconnects a consumer from the GonkBufferQueue. All michael@0: // buffers will be freed and the GonkBufferQueue is placed in the "abandoned" michael@0: // state, causing most interactions with the GonkBufferQueue by the producer to michael@0: // fail. michael@0: status_t consumerDisconnect(); michael@0: michael@0: // getReleasedBuffers sets the value pointed to by slotMask to a bit mask michael@0: // indicating which buffer slots have been released by the GonkBufferQueue michael@0: // but have not yet been released by the consumer. michael@0: // michael@0: // This should be called from the onBuffersReleased() callback. michael@0: status_t getReleasedBuffers(uint32_t* slotMask); michael@0: michael@0: // setDefaultBufferSize is used to set the size of buffers returned by michael@0: // dequeueBuffer when a width and height of zero is requested. Default michael@0: // is 1x1. michael@0: status_t setDefaultBufferSize(uint32_t w, uint32_t h); michael@0: michael@0: // setDefaultMaxBufferCount sets the default value for the maximum buffer michael@0: // count (the initial default is 2). If the producer has requested a michael@0: // buffer count using setBufferCount, the default buffer count will only michael@0: // take effect if the producer sets the count back to zero. michael@0: // michael@0: // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. michael@0: status_t setDefaultMaxBufferCount(int bufferCount); michael@0: michael@0: // setMaxAcquiredBufferCount sets the maximum number of buffers that can michael@0: // be acquired by the consumer at one time (default 1). This call will michael@0: // fail if a producer is connected to the GonkBufferQueue. michael@0: status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers); michael@0: michael@0: // isSynchronousMode returns whether the GonkBufferQueue is currently in michael@0: // synchronous mode. michael@0: bool isSynchronousMode() const; michael@0: michael@0: // setConsumerName sets the name used in logging michael@0: void setConsumerName(const String8& name); michael@0: michael@0: // setDefaultBufferFormat allows the GonkBufferQueue to create michael@0: // GraphicBuffers of a defaultFormat if no format is specified michael@0: // in dequeueBuffer. Formats are enumerated in graphics.h; the michael@0: // initial default is HAL_PIXEL_FORMAT_RGBA_8888. michael@0: status_t setDefaultBufferFormat(uint32_t defaultFormat); michael@0: michael@0: // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer. michael@0: // These are merged with the bits passed to dequeueBuffer. The values are michael@0: // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0. michael@0: status_t setConsumerUsageBits(uint32_t usage); michael@0: michael@0: // setTransformHint bakes in rotation to buffers so overlays can be used. michael@0: // The values are enumerated in window.h, e.g. michael@0: // NATIVE_WINDOW_TRANSFORM_ROT_90. The default is 0 (no transform). michael@0: status_t setTransformHint(uint32_t hint); michael@0: michael@0: mozilla::TemporaryRef getTextureClientFromBuffer(ANativeWindowBuffer* buffer); michael@0: michael@0: int getSlotFromTextureClientLocked(TextureClient* client) const; michael@0: michael@0: private: michael@0: // freeBufferLocked frees the GraphicBuffer and sync resources for the michael@0: // given slot. michael@0: //void freeBufferLocked(int index); michael@0: michael@0: // freeAllBuffersLocked frees the GraphicBuffer and sync resources for michael@0: // all slots. michael@0: //void freeAllBuffersLocked(); michael@0: void freeAllBuffersLocked(); michael@0: michael@0: // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots michael@0: // that will be used if the producer does not override the buffer slot michael@0: // count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. michael@0: // The initial default is 2. michael@0: status_t setDefaultMaxBufferCountLocked(int count); michael@0: michael@0: // getMinBufferCountLocked returns the minimum number of buffers allowed michael@0: // given the current GonkBufferQueue state. michael@0: int getMinMaxBufferCountLocked() const; michael@0: michael@0: // getMinUndequeuedBufferCountLocked returns the minimum number of buffers michael@0: // that must remain in a state other than DEQUEUED. michael@0: int getMinUndequeuedBufferCountLocked() const; michael@0: michael@0: // getMaxBufferCountLocked returns the maximum number of buffers that can michael@0: // be allocated at once. This value depends upon the following member michael@0: // variables: michael@0: // michael@0: // mSynchronousMode michael@0: // mMaxAcquiredBufferCount michael@0: // mDefaultMaxBufferCount michael@0: // mOverrideMaxBufferCount michael@0: // michael@0: // Any time one of these member variables is changed while a producer is michael@0: // connected, mDequeueCondition must be broadcast. michael@0: int getMaxBufferCountLocked() const; michael@0: michael@0: struct BufferSlot { michael@0: michael@0: BufferSlot() michael@0: : mBufferState(BufferSlot::FREE), michael@0: mRequestBufferCalled(false), michael@0: mTransform(0), michael@0: mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), michael@0: mTimestamp(0), michael@0: mFrameNumber(0), michael@0: mAcquireCalled(false), michael@0: mNeedsCleanupOnRelease(false) { michael@0: mCrop.makeInvalid(); michael@0: } michael@0: michael@0: // mGraphicBuffer points to the buffer allocated for this slot or is NULL michael@0: // if no buffer has been allocated. michael@0: sp mGraphicBuffer; michael@0: michael@0: // mTextureClient is a thin abstraction over remotely allocated GraphicBuffer. michael@0: mozilla::RefPtr mTextureClient; michael@0: michael@0: // BufferState represents the different states in which a buffer slot michael@0: // can be. All slots are initially FREE. michael@0: enum BufferState { michael@0: // FREE indicates that the buffer is available to be dequeued michael@0: // by the producer. The buffer may be in use by the consumer for michael@0: // a finite time, so the buffer must not be modified until the michael@0: // associated fence is signaled. michael@0: // michael@0: // The slot is "owned" by GonkBufferQueue. It transitions to DEQUEUED michael@0: // when dequeueBuffer is called. michael@0: FREE = 0, michael@0: michael@0: // DEQUEUED indicates that the buffer has been dequeued by the michael@0: // producer, but has not yet been queued or canceled. The michael@0: // producer may modify the buffer's contents as soon as the michael@0: // associated ready fence is signaled. michael@0: // michael@0: // The slot is "owned" by the producer. It can transition to michael@0: // QUEUED (via queueBuffer) or back to FREE (via cancelBuffer). michael@0: DEQUEUED = 1, michael@0: michael@0: // QUEUED indicates that the buffer has been filled by the michael@0: // producer and queued for use by the consumer. The buffer michael@0: // contents may continue to be modified for a finite time, so michael@0: // the contents must not be accessed until the associated fence michael@0: // is signaled. michael@0: // michael@0: // The slot is "owned" by GonkBufferQueue. It can transition to michael@0: // ACQUIRED (via acquireBuffer) or to FREE (if another buffer is michael@0: // queued in asynchronous mode). michael@0: QUEUED = 2, michael@0: michael@0: // ACQUIRED indicates that the buffer has been acquired by the michael@0: // consumer. As with QUEUED, the contents must not be accessed michael@0: // by the consumer until the fence is signaled. michael@0: // michael@0: // The slot is "owned" by the consumer. It transitions to FREE michael@0: // when releaseBuffer is called. michael@0: ACQUIRED = 3 michael@0: }; michael@0: michael@0: // mBufferState is the current state of this buffer slot. michael@0: BufferState mBufferState; michael@0: michael@0: // mRequestBufferCalled is used for validating that the producer did michael@0: // call requestBuffer() when told to do so. Technically this is not michael@0: // needed but useful for debugging and catching producer bugs. michael@0: bool mRequestBufferCalled; michael@0: michael@0: // mCrop is the current crop rectangle for this buffer slot. michael@0: Rect mCrop; michael@0: michael@0: // mTransform is the current transform flags for this buffer slot. michael@0: // (example: NATIVE_WINDOW_TRANSFORM_ROT_90) michael@0: uint32_t mTransform; michael@0: michael@0: // mScalingMode is the current scaling mode for this buffer slot. michael@0: // (example: NATIVE_WINDOW_SCALING_MODE_FREEZE) michael@0: uint32_t mScalingMode; michael@0: michael@0: // mTimestamp is the current timestamp for this buffer slot. This gets michael@0: // to set by queueBuffer each time this slot is queued. michael@0: int64_t mTimestamp; michael@0: michael@0: // mFrameNumber is the number of the queued frame for this slot. This michael@0: // is used to dequeue buffers in LRU order (useful because buffers michael@0: // may be released before their release fence is signaled). michael@0: uint64_t mFrameNumber; michael@0: michael@0: // mEglFence is the EGL sync object that must signal before the buffer michael@0: // associated with this buffer slot may be dequeued. It is initialized michael@0: // to EGL_NO_SYNC_KHR when the buffer is created and may be set to a michael@0: // new sync object in releaseBuffer. (This is deprecated in favor of michael@0: // mFence, below.) michael@0: //EGLSyncKHR mEglFence; michael@0: michael@0: // mFence is a fence which will signal when work initiated by the michael@0: // previous owner of the buffer is finished. When the buffer is FREE, michael@0: // the fence indicates when the consumer has finished reading michael@0: // from the buffer, or when the producer has finished writing if it michael@0: // called cancelBuffer after queueing some writes. When the buffer is michael@0: // QUEUED, it indicates when the producer has finished filling the michael@0: // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been michael@0: // passed to the consumer or producer along with ownership of the michael@0: // buffer, and mFence is set to NO_FENCE. michael@0: sp mFence; michael@0: michael@0: // Indicates whether this buffer has been seen by a consumer yet michael@0: bool mAcquireCalled; michael@0: michael@0: // Indicates whether this buffer needs to be cleaned up by the michael@0: // consumer. This is set when a buffer in ACQUIRED state is freed. michael@0: // It causes releaseBuffer to return STALE_BUFFER_SLOT. michael@0: bool mNeedsCleanupOnRelease; michael@0: }; michael@0: michael@0: // mSlots is the array of buffer slots that must be mirrored on the michael@0: // producer side. This allows buffer ownership to be transferred between michael@0: // the producer and consumer without sending a GraphicBuffer over binder. michael@0: // The entire array is initialized to NULL at construction time, and michael@0: // buffers are allocated for a slot when requestBuffer is called with michael@0: // that slot's index. michael@0: BufferSlot mSlots[NUM_BUFFER_SLOTS]; michael@0: michael@0: // mDefaultWidth holds the default width of allocated buffers. It is used michael@0: // in dequeueBuffer() if a width and height of zero is specified. michael@0: uint32_t mDefaultWidth; michael@0: michael@0: // mDefaultHeight holds the default height of allocated buffers. It is used michael@0: // in dequeueBuffer() if a width and height of zero is specified. michael@0: uint32_t mDefaultHeight; michael@0: michael@0: // mMaxAcquiredBufferCount is the number of buffers that the consumer may michael@0: // acquire at one time. It defaults to 1 and can be changed by the michael@0: // consumer via the setMaxAcquiredBufferCount method, but this may only be michael@0: // done when no producer is connected to the GonkBufferQueue. michael@0: // michael@0: // This value is used to derive the value returned for the michael@0: // MIN_UNDEQUEUED_BUFFERS query by the producer. michael@0: int mMaxAcquiredBufferCount; michael@0: michael@0: // mDefaultMaxBufferCount is the default limit on the number of buffers michael@0: // that will be allocated at one time. This default limit is set by the michael@0: // consumer. The limit (as opposed to the default limit) may be michael@0: // overridden by the producer. michael@0: int mDefaultMaxBufferCount; michael@0: michael@0: // mOverrideMaxBufferCount is the limit on the number of buffers that will michael@0: // be allocated at one time. This value is set by the image producer by michael@0: // calling setBufferCount. The default is zero, which means the producer michael@0: // doesn't care about the number of buffers in the pool. In that case michael@0: // mDefaultMaxBufferCount is used as the limit. michael@0: int mOverrideMaxBufferCount; michael@0: michael@0: // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to michael@0: // allocate new GraphicBuffer objects. michael@0: sp mGraphicBufferAlloc; michael@0: michael@0: // mConsumerListener is used to notify the connected consumer of michael@0: // asynchronous events that it may wish to react to. It is initially set michael@0: // to NULL and is written by consumerConnect and consumerDisconnect. michael@0: sp mConsumerListener; michael@0: michael@0: // mSynchronousMode whether we're in synchronous mode or not michael@0: bool mSynchronousMode; michael@0: michael@0: // mAllowSynchronousMode whether we allow synchronous mode or not. Set michael@0: // when the GonkBufferQueue is created (by the consumer). michael@0: const bool mAllowSynchronousMode; michael@0: michael@0: // mConnectedApi indicates the producer API that is currently connected michael@0: // to this GonkBufferQueue. It defaults to NO_CONNECTED_API (= 0), and gets michael@0: // updated by the connect and disconnect methods. michael@0: int mConnectedApi; michael@0: michael@0: // mDequeueCondition condition used for dequeueBuffer in synchronous mode michael@0: mutable Condition mDequeueCondition; michael@0: michael@0: // mQueue is a FIFO of queued buffers used in synchronous mode michael@0: typedef Vector Fifo; michael@0: Fifo mQueue; michael@0: michael@0: // mAbandoned indicates that the GonkBufferQueue will no longer be used to michael@0: // consume image buffers pushed to it using the IGraphicBufferProducer michael@0: // interface. It is initialized to false, and set to true in the michael@0: // consumerDisconnect method. A GonkBufferQueue that has been abandoned will michael@0: // return the NO_INIT error from all IGraphicBufferProducer methods michael@0: // capable of returning an error. michael@0: bool mAbandoned; michael@0: michael@0: // mConsumerName is a string used to identify the GonkBufferQueue in log michael@0: // messages. It is set by the setConsumerName method. michael@0: String8 mConsumerName; michael@0: michael@0: // mMutex is the mutex used to prevent concurrent access to the member michael@0: // variables of GonkBufferQueue objects. It must be locked whenever the michael@0: // member variables are accessed. michael@0: mutable Mutex mMutex; michael@0: michael@0: // mFrameCounter is the free running counter, incremented on every michael@0: // successful queueBuffer call. michael@0: uint64_t mFrameCounter; michael@0: michael@0: // mBufferHasBeenQueued is true once a buffer has been queued. It is michael@0: // reset when something causes all buffers to be freed (e.g. changing the michael@0: // buffer count). michael@0: bool mBufferHasBeenQueued; michael@0: michael@0: // mDefaultBufferFormat can be set so it will override michael@0: // the buffer format when it isn't specified in dequeueBuffer michael@0: uint32_t mDefaultBufferFormat; michael@0: michael@0: // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers michael@0: uint32_t mConsumerUsageBits; michael@0: michael@0: // mTransformHint is used to optimize for screen rotations michael@0: uint32_t mTransformHint; michael@0: michael@0: }; michael@0: michael@0: // ---------------------------------------------------------------------------- michael@0: }; // namespace android michael@0: michael@0: #endif // ANDROID_GUI_BUFFERQUEUE_H