widget/gonk/nativewindow/GonkBufferQueueJB.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Copyright (C) 2012 The Android Open Source Project
     3  * Copyright (C) 2013 Mozilla Foundation
     4  *
     5  * Licensed under the Apache License, Version 2.0 (the "License");
     6  * you may not use this file except in compliance with the License.
     7  * You may obtain a copy of the License at
     8  *
     9  *      http://www.apache.org/licenses/LICENSE-2.0
    10  *
    11  * Unless required by applicable law or agreed to in writing, software
    12  * distributed under the License is distributed on an "AS IS" BASIS,
    13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  * See the License for the specific language governing permissions and
    15  * limitations under the License.
    16  */
    18 #ifndef NATIVEWINDOW_GONKBUFFERQUEUE_JB_H
    19 #define NATIVEWINDOW_GONKBUFFERQUEUE_JB_H
    21 #include <gui/IGraphicBufferAlloc.h>
    22 #if ANDROID_VERSION == 17
    23 #include <gui/ISurfaceTexture.h>
    24 #else
    25 #include <gui/IGraphicBufferProducer.h>
    26 #endif
    28 #include <ui/Fence.h>
    29 #include <ui/GraphicBuffer.h>
    31 #include <utils/String8.h>
    32 #include <utils/Vector.h>
    33 #include <utils/threads.h>
    35 #include "mozilla/layers/LayersSurfaces.h"
    36 #include "mozilla/layers/TextureClient.h"
    38 #if ANDROID_VERSION == 17
    39 #define IGraphicBufferProducer ISurfaceTexture
    40 #endif
    42 namespace android {
    43 // ----------------------------------------------------------------------------
    45 #if ANDROID_VERSION == 17
    46 class GonkBufferQueue : public BnSurfaceTexture {
    47 #else
    48 class GonkBufferQueue : public BnGraphicBufferProducer {
    49 #endif
    50     typedef mozilla::layers::TextureClient TextureClient;
    52 public:
    53     enum { MIN_UNDEQUEUED_BUFFERS = 2 };
    54     enum { NUM_BUFFER_SLOTS = 32 };
    55     enum { NO_CONNECTED_API = 0 };
    56     enum { INVALID_BUFFER_SLOT = -1 };
    57     enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE };
    59     // When in async mode we reserve two slots in order to guarantee that the
    60     // producer and consumer can run asynchronously.
    61     enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 };
    63     // ConsumerListener is the interface through which the GonkBufferQueue notifies
    64     // the consumer of events that the consumer may wish to react to.  Because
    65     // the consumer will generally have a mutex that is locked during calls from
    66     // the consumer to the GonkBufferQueue, these calls from the GonkBufferQueue to the
    67     // consumer *MUST* be called only when the GonkBufferQueue mutex is NOT locked.
    68     struct ConsumerListener : public virtual RefBase {
    69         // onFrameAvailable is called from queueBuffer each time an additional
    70         // frame becomes available for consumption. This means that frames that
    71         // are queued while in asynchronous mode only trigger the callback if no
    72         // previous frames are pending. Frames queued while in synchronous mode
    73         // always trigger the callback.
    74         //
    75         // This is called without any lock held and can be called concurrently
    76         // by multiple threads.
    77         virtual void onFrameAvailable() = 0;
    79         // onBuffersReleased is called to notify the buffer consumer that the
    80         // GonkBufferQueue has released its references to one or more GraphicBuffers
    81         // contained in its slots.  The buffer consumer should then call
    82         // GonkBufferQueue::getReleasedBuffers to retrieve the list of buffers
    83         //
    84         // This is called without any lock held and can be called concurrently
    85         // by multiple threads.
    86         virtual void onBuffersReleased() = 0;
    87     };
    89     // ProxyConsumerListener is a ConsumerListener implementation that keeps a weak
    90     // reference to the actual consumer object.  It forwards all calls to that
    91     // consumer object so long as it exists.
    92     //
    93     // This class exists to avoid having a circular reference between the
    94     // GonkBufferQueue object and the consumer object.  The reason this can't be a weak
    95     // reference in the GonkBufferQueue class is because we're planning to expose the
    96     // consumer side of a GonkBufferQueue as a binder interface, which doesn't support
    97     // weak references.
    98     class ProxyConsumerListener : public GonkBufferQueue::ConsumerListener {
    99     public:
   101         ProxyConsumerListener(const wp<GonkBufferQueue::ConsumerListener>& consumerListener);
   102         virtual ~ProxyConsumerListener();
   103         virtual void onFrameAvailable();
   104         virtual void onBuffersReleased();
   106     private:
   108         // mConsumerListener is a weak reference to the ConsumerListener.  This is
   109         // the raison d'etre of ProxyConsumerListener.
   110         wp<GonkBufferQueue::ConsumerListener> mConsumerListener;
   111     };
   114     // GonkBufferQueue manages a pool of gralloc memory slots to be used by
   115     // producers and consumers. allowSynchronousMode specifies whether or not
   116     // synchronous mode can be enabled by the producer. allocator is used to
   117     // allocate all the needed gralloc buffers.
   118     GonkBufferQueue(bool allowSynchronousMode = true,
   119             const sp<IGraphicBufferAlloc>& allocator = NULL);
   120     virtual ~GonkBufferQueue();
   122     // Query native window attributes.  The "what" values are enumerated in
   123     // window.h (e.g. NATIVE_WINDOW_FORMAT).
   124     virtual int query(int what, int* value);
   126     // setBufferCount updates the number of available buffer slots.  If this
   127     // method succeeds, buffer slots will be both unallocated and owned by
   128     // the GonkBufferQueue object (i.e. they are not owned by the producer or
   129     // consumer).
   130     //
   131     // This will fail if the producer has dequeued any buffers, or if
   132     // bufferCount is invalid.  bufferCount must generally be a value
   133     // between the minimum undequeued buffer count and NUM_BUFFER_SLOTS
   134     // (inclusive).  It may also be set to zero (the default) to indicate
   135     // that the producer does not wish to set a value.  The minimum value
   136     // can be obtained by calling query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
   137     // ...).
   138     //
   139     // This may only be called by the producer.  The consumer will be told
   140     // to discard buffers through the onBuffersReleased callback.
   141     virtual status_t setBufferCount(int bufferCount);
   143     // requestBuffer returns the GraphicBuffer for slot N.
   144     //
   145     // In normal operation, this is called the first time slot N is returned
   146     // by dequeueBuffer.  It must be called again if dequeueBuffer returns
   147     // flags indicating that previously-returned buffers are no longer valid.
   148     virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
   150     // dequeueBuffer gets the next buffer slot index for the producer to use.
   151     // If a buffer slot is available then that slot index is written to the
   152     // location pointed to by the buf argument and a status of OK is returned.
   153     // If no slot is available then a status of -EBUSY is returned and buf is
   154     // unmodified.
   155     //
   156     // The fence parameter will be updated to hold the fence associated with
   157     // the buffer. The contents of the buffer must not be overwritten until the
   158     // fence signals. If the fence is Fence::NO_FENCE, the buffer may be
   159     // written immediately.
   160     //
   161     // The width and height parameters must be no greater than the minimum of
   162     // GL_MAX_VIEWPORT_DIMS and GL_MAX_TEXTURE_SIZE (see: glGetIntegerv).
   163     // An error due to invalid dimensions might not be reported until
   164     // updateTexImage() is called.  If width and height are both zero, the
   165     // default values specified by setDefaultBufferSize() are used instead.
   166     //
   167     // The pixel formats are enumerated in graphics.h, e.g.
   168     // HAL_PIXEL_FORMAT_RGBA_8888.  If the format is 0, the default format
   169     // will be used.
   170     //
   171     // The usage argument specifies gralloc buffer usage flags.  The values
   172     // are enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER.  These
   173     // will be merged with the usage flags specified by setConsumerUsageBits.
   174     //
   175     // The return value may be a negative error value or a non-negative
   176     // collection of flags.  If the flags are set, the return values are
   177     // valid, but additional actions must be performed.
   178     //
   179     // If IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION is set, the
   180     // producer must discard cached GraphicBuffer references for the slot
   181     // returned in buf.
   182     // If IGraphicBufferProducer::RELEASE_ALL_BUFFERS is set, the producer
   183     // must discard cached GraphicBuffer references for all slots.
   184     //
   185     // In both cases, the producer will need to call requestBuffer to get a
   186     // GraphicBuffer handle for the returned slot.
   187 #if ANDROID_VERSION == 17
   188     virtual status_t dequeueBuffer(int *buf, sp<Fence>& fence,
   189             uint32_t width, uint32_t height, uint32_t format, uint32_t usage) {
   190         return dequeueBuffer(buf, &fence, width, height, format, usage);
   191     }
   192 #endif
   194     virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence,
   195             uint32_t width, uint32_t height, uint32_t format, uint32_t usage);
   197     // queueBuffer returns a filled buffer to the GonkBufferQueue.
   198     //
   199     // Additional data is provided in the QueueBufferInput struct.  Notably,
   200     // a timestamp must be provided for the buffer. The timestamp is in
   201     // nanoseconds, and must be monotonically increasing. Its other semantics
   202     // (zero point, etc) are producer-specific and should be documented by the
   203     // producer.
   204     //
   205     // The caller may provide a fence that signals when all rendering
   206     // operations have completed.  Alternatively, NO_FENCE may be used,
   207     // indicating that the buffer is ready immediately.
   208     //
   209     // Some values are returned in the output struct: the current settings
   210     // for default width and height, the current transform hint, and the
   211     // number of queued buffers.
   212     virtual status_t queueBuffer(int buf,
   213             const QueueBufferInput& input, QueueBufferOutput* output);
   215     // cancelBuffer returns a dequeued buffer to the GonkBufferQueue, but doesn't
   216     // queue it for use by the consumer.
   217     //
   218     // The buffer will not be overwritten until the fence signals.  The fence
   219     // will usually be the one obtained from dequeueBuffer.
   220 #if ANDROID_VERSION == 17
   221     virtual void cancelBuffer(int buf, sp<Fence> fence);
   222 #else
   223     virtual void cancelBuffer(int buf, const sp<Fence>& fence);
   224 #endif
   226     // setSynchronousMode sets whether dequeueBuffer is synchronous or
   227     // asynchronous. In synchronous mode, dequeueBuffer blocks until
   228     // a buffer is available, the currently bound buffer can be dequeued and
   229     // queued buffers will be acquired in order.  In asynchronous mode,
   230     // a queued buffer may be replaced by a subsequently queued buffer.
   231     //
   232     // The default mode is asynchronous.
   233     virtual status_t setSynchronousMode(bool enabled);
   235     // connect attempts to connect a producer API to the GonkBufferQueue.  This
   236     // must be called before any other IGraphicBufferProducer methods are
   237     // called except for getAllocator.  A consumer must already be connected.
   238     //
   239     // This method will fail if connect was previously called on the
   240     // GonkBufferQueue and no corresponding disconnect call was made (i.e. if
   241     // it's still connected to a producer).
   242     //
   243     // APIs are enumerated in window.h (e.g. NATIVE_WINDOW_API_CPU).
   244     virtual status_t connect(int api, QueueBufferOutput* output);
   246     // disconnect attempts to disconnect a producer API from the GonkBufferQueue.
   247     // Calling this method will cause any subsequent calls to other
   248     // IGraphicBufferProducer methods to fail except for getAllocator and connect.
   249     // Successfully calling connect after this will allow the other methods to
   250     // succeed again.
   251     //
   252     // This method will fail if the the GonkBufferQueue is not currently
   253     // connected to the specified producer API.
   254     virtual status_t disconnect(int api);
   256     // dump our state in a String
   257     virtual void dump(String8& result) const;
   258     virtual void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
   260     // public facing structure for BufferSlot
   261     struct BufferItem {
   263         BufferItem()
   264          :
   265            mTransform(0),
   266            mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
   267            mTimestamp(0),
   268            mFrameNumber(0),
   269            mBuf(INVALID_BUFFER_SLOT) {
   270              mCrop.makeInvalid();
   271         }
   272         // mGraphicBuffer points to the buffer allocated for this slot, or is NULL
   273         // if the buffer in this slot has been acquired in the past (see
   274         // BufferSlot.mAcquireCalled).
   275         sp<GraphicBuffer> mGraphicBuffer;
   277         // mCrop is the current crop rectangle for this buffer slot.
   278         Rect mCrop;
   280         // mTransform is the current transform flags for this buffer slot.
   281         uint32_t mTransform;
   283         // mScalingMode is the current scaling mode for this buffer slot.
   284         uint32_t mScalingMode;
   286         // mTimestamp is the current timestamp for this buffer slot. This gets
   287         // to set by queueBuffer each time this slot is queued.
   288         int64_t mTimestamp;
   290         // mFrameNumber is the number of the queued frame for this slot.
   291         uint64_t mFrameNumber;
   293         // mBuf is the slot index of this buffer
   294         int mBuf;
   296         // mFence is a fence that will signal when the buffer is idle.
   297         sp<Fence> mFence;
   298     };
   300     // The following public functions are the consumer-facing interface
   302     // acquireBuffer attempts to acquire ownership of the next pending buffer in
   303     // the GonkBufferQueue.  If no buffer is pending then it returns -EINVAL.  If a
   304     // buffer is successfully acquired, the information about the buffer is
   305     // returned in BufferItem.  If the buffer returned had previously been
   306     // acquired then the BufferItem::mGraphicBuffer field of buffer is set to
   307     // NULL and it is assumed that the consumer still holds a reference to the
   308     // buffer.
   309     status_t acquireBuffer(BufferItem *buffer);
   311     // releaseBuffer releases a buffer slot from the consumer back to the
   312     // GonkBufferQueue.  This may be done while the buffer's contents are still
   313     // being accessed.  The fence will signal when the buffer is no longer
   314     // in use.
   315     //
   316     // If releaseBuffer returns STALE_BUFFER_SLOT, then the consumer must free
   317     // any references to the just-released buffer that it might have, as if it
   318     // had received a onBuffersReleased() call with a mask set for the released
   319     // buffer.
   320     //
   321     // Note that the dependencies on EGL will be removed once we switch to using
   322     // the Android HW Sync HAL.
   323     status_t releaseBuffer(int buf, const sp<Fence>& releaseFence);
   325     // consumerConnect connects a consumer to the GonkBufferQueue.  Only one
   326     // consumer may be connected, and when that consumer disconnects the
   327     // GonkBufferQueue is placed into the "abandoned" state, causing most
   328     // interactions with the GonkBufferQueue by the producer to fail.
   329     //
   330     // consumer may not be NULL.
   331     status_t consumerConnect(const sp<ConsumerListener>& consumer);
   333     // consumerDisconnect disconnects a consumer from the GonkBufferQueue. All
   334     // buffers will be freed and the GonkBufferQueue is placed in the "abandoned"
   335     // state, causing most interactions with the GonkBufferQueue by the producer to
   336     // fail.
   337     status_t consumerDisconnect();
   339     // getReleasedBuffers sets the value pointed to by slotMask to a bit mask
   340     // indicating which buffer slots have been released by the GonkBufferQueue
   341     // but have not yet been released by the consumer.
   342     //
   343     // This should be called from the onBuffersReleased() callback.
   344     status_t getReleasedBuffers(uint32_t* slotMask);
   346     // setDefaultBufferSize is used to set the size of buffers returned by
   347     // dequeueBuffer when a width and height of zero is requested.  Default
   348     // is 1x1.
   349     status_t setDefaultBufferSize(uint32_t w, uint32_t h);
   351     // setDefaultMaxBufferCount sets the default value for the maximum buffer
   352     // count (the initial default is 2). If the producer has requested a
   353     // buffer count using setBufferCount, the default buffer count will only
   354     // take effect if the producer sets the count back to zero.
   355     //
   356     // The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
   357     status_t setDefaultMaxBufferCount(int bufferCount);
   359     // setMaxAcquiredBufferCount sets the maximum number of buffers that can
   360     // be acquired by the consumer at one time (default 1).  This call will
   361     // fail if a producer is connected to the GonkBufferQueue.
   362     status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers);
   364     // isSynchronousMode returns whether the GonkBufferQueue is currently in
   365     // synchronous mode.
   366     bool isSynchronousMode() const;
   368     // setConsumerName sets the name used in logging
   369     void setConsumerName(const String8& name);
   371     // setDefaultBufferFormat allows the GonkBufferQueue to create
   372     // GraphicBuffers of a defaultFormat if no format is specified
   373     // in dequeueBuffer.  Formats are enumerated in graphics.h; the
   374     // initial default is HAL_PIXEL_FORMAT_RGBA_8888.
   375     status_t setDefaultBufferFormat(uint32_t defaultFormat);
   377     // setConsumerUsageBits will turn on additional usage bits for dequeueBuffer.
   378     // These are merged with the bits passed to dequeueBuffer.  The values are
   379     // enumerated in gralloc.h, e.g. GRALLOC_USAGE_HW_RENDER; the default is 0.
   380     status_t setConsumerUsageBits(uint32_t usage);
   382     // setTransformHint bakes in rotation to buffers so overlays can be used.
   383     // The values are enumerated in window.h, e.g.
   384     // NATIVE_WINDOW_TRANSFORM_ROT_90.  The default is 0 (no transform).
   385     status_t setTransformHint(uint32_t hint);
   387     mozilla::TemporaryRef<TextureClient> getTextureClientFromBuffer(ANativeWindowBuffer* buffer);
   389     int getSlotFromTextureClientLocked(TextureClient* client) const;
   391 private:
   392     // freeBufferLocked frees the GraphicBuffer and sync resources for the
   393     // given slot.
   394     //void freeBufferLocked(int index);
   396     // freeAllBuffersLocked frees the GraphicBuffer and sync resources for
   397     // all slots.
   398     //void freeAllBuffersLocked();
   399     void freeAllBuffersLocked();
   401     // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots
   402     // that will be used if the producer does not override the buffer slot
   403     // count.  The count must be between 2 and NUM_BUFFER_SLOTS, inclusive.
   404     // The initial default is 2.
   405     status_t setDefaultMaxBufferCountLocked(int count);
   407     // getMinBufferCountLocked returns the minimum number of buffers allowed
   408     // given the current GonkBufferQueue state.
   409     int getMinMaxBufferCountLocked() const;
   411     // getMinUndequeuedBufferCountLocked returns the minimum number of buffers
   412     // that must remain in a state other than DEQUEUED.
   413     int getMinUndequeuedBufferCountLocked() const;
   415     // getMaxBufferCountLocked returns the maximum number of buffers that can
   416     // be allocated at once.  This value depends upon the following member
   417     // variables:
   418     //
   419     //      mSynchronousMode
   420     //      mMaxAcquiredBufferCount
   421     //      mDefaultMaxBufferCount
   422     //      mOverrideMaxBufferCount
   423     //
   424     // Any time one of these member variables is changed while a producer is
   425     // connected, mDequeueCondition must be broadcast.
   426     int getMaxBufferCountLocked() const;
   428     struct BufferSlot {
   430         BufferSlot()
   431         : mBufferState(BufferSlot::FREE),
   432           mRequestBufferCalled(false),
   433           mTransform(0),
   434           mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE),
   435           mTimestamp(0),
   436           mFrameNumber(0),
   437           mAcquireCalled(false),
   438           mNeedsCleanupOnRelease(false) {
   439             mCrop.makeInvalid();
   440         }
   442         // mGraphicBuffer points to the buffer allocated for this slot or is NULL
   443         // if no buffer has been allocated.
   444         sp<GraphicBuffer> mGraphicBuffer;
   446         // mTextureClient is a thin abstraction over remotely allocated GraphicBuffer.
   447         mozilla::RefPtr<TextureClient> mTextureClient;
   449         // BufferState represents the different states in which a buffer slot
   450         // can be.  All slots are initially FREE.
   451         enum BufferState {
   452             // FREE indicates that the buffer is available to be dequeued
   453             // by the producer.  The buffer may be in use by the consumer for
   454             // a finite time, so the buffer must not be modified until the
   455             // associated fence is signaled.
   456             //
   457             // The slot is "owned" by GonkBufferQueue.  It transitions to DEQUEUED
   458             // when dequeueBuffer is called.
   459             FREE = 0,
   461             // DEQUEUED indicates that the buffer has been dequeued by the
   462             // producer, but has not yet been queued or canceled.  The
   463             // producer may modify the buffer's contents as soon as the
   464             // associated ready fence is signaled.
   465             //
   466             // The slot is "owned" by the producer.  It can transition to
   467             // QUEUED (via queueBuffer) or back to FREE (via cancelBuffer).
   468             DEQUEUED = 1,
   470             // QUEUED indicates that the buffer has been filled by the
   471             // producer and queued for use by the consumer.  The buffer
   472             // contents may continue to be modified for a finite time, so
   473             // the contents must not be accessed until the associated fence
   474             // is signaled.
   475             //
   476             // The slot is "owned" by GonkBufferQueue.  It can transition to
   477             // ACQUIRED (via acquireBuffer) or to FREE (if another buffer is
   478             // queued in asynchronous mode).
   479             QUEUED = 2,
   481             // ACQUIRED indicates that the buffer has been acquired by the
   482             // consumer.  As with QUEUED, the contents must not be accessed
   483             // by the consumer until the fence is signaled.
   484             //
   485             // The slot is "owned" by the consumer.  It transitions to FREE
   486             // when releaseBuffer is called.
   487             ACQUIRED = 3
   488         };
   490         // mBufferState is the current state of this buffer slot.
   491         BufferState mBufferState;
   493         // mRequestBufferCalled is used for validating that the producer did
   494         // call requestBuffer() when told to do so. Technically this is not
   495         // needed but useful for debugging and catching producer bugs.
   496         bool mRequestBufferCalled;
   498         // mCrop is the current crop rectangle for this buffer slot.
   499         Rect mCrop;
   501         // mTransform is the current transform flags for this buffer slot.
   502         // (example: NATIVE_WINDOW_TRANSFORM_ROT_90)
   503         uint32_t mTransform;
   505         // mScalingMode is the current scaling mode for this buffer slot.
   506         // (example: NATIVE_WINDOW_SCALING_MODE_FREEZE)
   507         uint32_t mScalingMode;
   509         // mTimestamp is the current timestamp for this buffer slot. This gets
   510         // to set by queueBuffer each time this slot is queued.
   511         int64_t mTimestamp;
   513         // mFrameNumber is the number of the queued frame for this slot.  This
   514         // is used to dequeue buffers in LRU order (useful because buffers
   515         // may be released before their release fence is signaled).
   516         uint64_t mFrameNumber;
   518         // mEglFence is the EGL sync object that must signal before the buffer
   519         // associated with this buffer slot may be dequeued. It is initialized
   520         // to EGL_NO_SYNC_KHR when the buffer is created and may be set to a
   521         // new sync object in releaseBuffer.  (This is deprecated in favor of
   522         // mFence, below.)
   523         //EGLSyncKHR mEglFence;
   525         // mFence is a fence which will signal when work initiated by the
   526         // previous owner of the buffer is finished. When the buffer is FREE,
   527         // the fence indicates when the consumer has finished reading
   528         // from the buffer, or when the producer has finished writing if it
   529         // called cancelBuffer after queueing some writes. When the buffer is
   530         // QUEUED, it indicates when the producer has finished filling the
   531         // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been
   532         // passed to the consumer or producer along with ownership of the
   533         // buffer, and mFence is set to NO_FENCE.
   534         sp<Fence> mFence;
   536         // Indicates whether this buffer has been seen by a consumer yet
   537         bool mAcquireCalled;
   539         // Indicates whether this buffer needs to be cleaned up by the
   540         // consumer.  This is set when a buffer in ACQUIRED state is freed.
   541         // It causes releaseBuffer to return STALE_BUFFER_SLOT.
   542         bool mNeedsCleanupOnRelease;
   543     };
   545     // mSlots is the array of buffer slots that must be mirrored on the
   546     // producer side. This allows buffer ownership to be transferred between
   547     // the producer and consumer without sending a GraphicBuffer over binder.
   548     // The entire array is initialized to NULL at construction time, and
   549     // buffers are allocated for a slot when requestBuffer is called with
   550     // that slot's index.
   551     BufferSlot mSlots[NUM_BUFFER_SLOTS];
   553     // mDefaultWidth holds the default width of allocated buffers. It is used
   554     // in dequeueBuffer() if a width and height of zero is specified.
   555     uint32_t mDefaultWidth;
   557     // mDefaultHeight holds the default height of allocated buffers. It is used
   558     // in dequeueBuffer() if a width and height of zero is specified.
   559     uint32_t mDefaultHeight;
   561     // mMaxAcquiredBufferCount is the number of buffers that the consumer may
   562     // acquire at one time.  It defaults to 1 and can be changed by the
   563     // consumer via the setMaxAcquiredBufferCount method, but this may only be
   564     // done when no producer is connected to the GonkBufferQueue.
   565     //
   566     // This value is used to derive the value returned for the
   567     // MIN_UNDEQUEUED_BUFFERS query by the producer.
   568     int mMaxAcquiredBufferCount;
   570     // mDefaultMaxBufferCount is the default limit on the number of buffers
   571     // that will be allocated at one time.  This default limit is set by the
   572     // consumer.  The limit (as opposed to the default limit) may be
   573     // overridden by the producer.
   574     int mDefaultMaxBufferCount;
   576     // mOverrideMaxBufferCount is the limit on the number of buffers that will
   577     // be allocated at one time. This value is set by the image producer by
   578     // calling setBufferCount. The default is zero, which means the producer
   579     // doesn't care about the number of buffers in the pool. In that case
   580     // mDefaultMaxBufferCount is used as the limit.
   581     int mOverrideMaxBufferCount;
   583     // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
   584     // allocate new GraphicBuffer objects.
   585     sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
   587     // mConsumerListener is used to notify the connected consumer of
   588     // asynchronous events that it may wish to react to.  It is initially set
   589     // to NULL and is written by consumerConnect and consumerDisconnect.
   590     sp<ConsumerListener> mConsumerListener;
   592     // mSynchronousMode whether we're in synchronous mode or not
   593     bool mSynchronousMode;
   595     // mAllowSynchronousMode whether we allow synchronous mode or not.  Set
   596     // when the GonkBufferQueue is created (by the consumer).
   597     const bool mAllowSynchronousMode;
   599     // mConnectedApi indicates the producer API that is currently connected
   600     // to this GonkBufferQueue.  It defaults to NO_CONNECTED_API (= 0), and gets
   601     // updated by the connect and disconnect methods.
   602     int mConnectedApi;
   604     // mDequeueCondition condition used for dequeueBuffer in synchronous mode
   605     mutable Condition mDequeueCondition;
   607     // mQueue is a FIFO of queued buffers used in synchronous mode
   608     typedef Vector<int> Fifo;
   609     Fifo mQueue;
   611     // mAbandoned indicates that the GonkBufferQueue will no longer be used to
   612     // consume image buffers pushed to it using the IGraphicBufferProducer
   613     // interface.  It is initialized to false, and set to true in the
   614     // consumerDisconnect method.  A GonkBufferQueue that has been abandoned will
   615     // return the NO_INIT error from all IGraphicBufferProducer methods
   616     // capable of returning an error.
   617     bool mAbandoned;
   619     // mConsumerName is a string used to identify the GonkBufferQueue in log
   620     // messages.  It is set by the setConsumerName method.
   621     String8 mConsumerName;
   623     // mMutex is the mutex used to prevent concurrent access to the member
   624     // variables of GonkBufferQueue objects. It must be locked whenever the
   625     // member variables are accessed.
   626     mutable Mutex mMutex;
   628     // mFrameCounter is the free running counter, incremented on every
   629     // successful queueBuffer call.
   630     uint64_t mFrameCounter;
   632     // mBufferHasBeenQueued is true once a buffer has been queued.  It is
   633     // reset when something causes all buffers to be freed (e.g. changing the
   634     // buffer count).
   635     bool mBufferHasBeenQueued;
   637     // mDefaultBufferFormat can be set so it will override
   638     // the buffer format when it isn't specified in dequeueBuffer
   639     uint32_t mDefaultBufferFormat;
   641     // mConsumerUsageBits contains flags the consumer wants for GraphicBuffers
   642     uint32_t mConsumerUsageBits;
   644     // mTransformHint is used to optimize for screen rotations
   645     uint32_t mTransformHint;
   647 };
   649 // ----------------------------------------------------------------------------
   650 }; // namespace android
   652 #endif // ANDROID_GUI_BUFFERQUEUE_H

mercurial