1289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza/*
2289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Copyright 2014 The Android Open Source Project
3289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *
4289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Licensed under the Apache License, Version 2.0 (the "License");
5289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * you may not use this file except in compliance with the License.
6289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * You may obtain a copy of the License at
7289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *
8289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *      http://www.apache.org/licenses/LICENSE-2.0
9289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *
10289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Unless required by applicable law or agreed to in writing, software
11289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * distributed under the License is distributed on an "AS IS" BASIS,
12289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * See the License for the specific language governing permissions and
14289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * limitations under the License.
15289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza */
16289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
17289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#ifndef ANDROID_GUI_BUFFERQUEUECORE_H
18289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define ANDROID_GUI_BUFFERQUEUECORE_H
19289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
203e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza#include <gui/BufferQueueDefs.h>
21289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <gui/BufferSlot.h>
22289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
23289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/Condition.h>
24289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/Mutex.h>
25399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall#include <utils/NativeHandle.h>
26289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/RefBase.h>
27289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/String8.h>
28289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/StrongPointer.h>
29289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/Trace.h>
30289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/Vector.h>
31289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
32289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define BQ_LOGV(x, ...) ALOGV("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
33289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define BQ_LOGD(x, ...) ALOGD("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
34289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define BQ_LOGI(x, ...) ALOGI("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
35289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define BQ_LOGW(x, ...) ALOGW("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
36289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define BQ_LOGE(x, ...) ALOGE("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
37289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
38289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define ATRACE_BUFFER_INDEX(index)                                   \
39289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    if (ATRACE_ENABLED()) {                                          \
40289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza        char ___traceBuf[1024];                                      \
41289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza        snprintf(___traceBuf, 1024, "%s: %d",                        \
42289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza                mCore->mConsumerName.string(), (index));             \
43289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza        android::ScopedTrace ___bufTracer(ATRACE_TAG, ___traceBuf);  \
44289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    }
45289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
46289ade165e60b5f71734d30e535f16eb1f4313adDan Stozanamespace android {
47289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
48289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass BufferItem;
49289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass IConsumerListener;
50289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass IGraphicBufferAlloc;
51f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stozaclass IProducerListener;
52289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
53289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass BufferQueueCore : public virtual RefBase {
54289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
55289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    friend class BufferQueueProducer;
56289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    friend class BufferQueueConsumer;
57289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
58289ade165e60b5f71734d30e535f16eb1f4313adDan Stozapublic:
59289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // Used as a placeholder slot number when the value isn't pointing to an
60289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // existing buffer.
61289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    enum { INVALID_BUFFER_SLOT = -1 }; // TODO: Extract from IGBC::BufferItem
62289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
63289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // We reserve two slots in order to guarantee that the producer and
64289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // consumer can run asynchronously.
653e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    enum { MAX_MAX_ACQUIRED_BUFFERS = BufferQueueDefs::NUM_BUFFER_SLOTS - 2 };
66289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
67289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // The default API number used to indicate that no producer is connected
68289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    enum { NO_CONNECTED_API = 0 };
69289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
70289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    typedef Vector<BufferItem> Fifo;
71289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
72289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // BufferQueueCore manages a pool of gralloc memory slots to be used by
73289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // producers and consumers. allocator is used to allocate all the needed
74289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // gralloc buffers.
75289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    BufferQueueCore(const sp<IGraphicBufferAlloc>& allocator = NULL);
76289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    virtual ~BufferQueueCore();
77289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
78289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaprivate:
793e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // Dump our state in a string
80289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    void dump(String8& result, const char* prefix) const;
81289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
823e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // getMinUndequeuedBufferCountLocked returns the minimum number of buffers
833e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // that must remain in a state other than DEQUEUED. The async parameter
843e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // tells whether we're in asynchronous mode.
85289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    int getMinUndequeuedBufferCountLocked(bool async) const;
863e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
873e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // getMinMaxBufferCountLocked returns the minimum number of buffers allowed
883e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // given the current BufferQueue state. The async parameter tells whether
893e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // we're in asynchonous mode.
90289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    int getMinMaxBufferCountLocked(bool async) const;
913e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
923e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // getMaxBufferCountLocked returns the maximum number of buffers that can be
933e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // allocated at once. This value depends on the following member variables:
943e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    //
953e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    //     mDequeueBufferCannotBlock
963e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    //     mMaxAcquiredBufferCount
973e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    //     mDefaultMaxBufferCount
983e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    //     mOverrideMaxBufferCount
993e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    //     async parameter
1003e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    //
1013e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // Any time one of these member variables is changed while a producer is
1023e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // connected, mDequeueCondition must be broadcast.
103289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    int getMaxBufferCountLocked(bool async) const;
1043e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1053e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots
1063e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // that will be used if the producer does not override the buffer slot
1073e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. The
1083e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // initial default is 2.
109289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    status_t setDefaultMaxBufferCountLocked(int count);
1103e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1113e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // freeBufferLocked frees the GraphicBuffer and sync resources for the
1123e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // given slot.
113289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    void freeBufferLocked(int slot);
1143e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1153e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // freeAllBuffersLocked frees the GraphicBuffer and sync resources for
1163e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // all slots.
117289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    void freeAllBuffersLocked();
1183e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1193e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // stillTracking returns true iff the buffer item is still being tracked
1203e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // in one of the slots.
121289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    bool stillTracking(const BufferItem* item) const;
122289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
12378014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    // waitWhileAllocatingLocked blocks until mIsAllocating is false.
12478014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    void waitWhileAllocatingLocked() const;
12578014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour
1263e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mAllocator is the connection to SurfaceFlinger that is used to allocate
1273e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // new GraphicBuffer objects.
1283e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    sp<IGraphicBufferAlloc> mAllocator;
1293e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1303e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mMutex is the mutex used to prevent concurrent access to the member
1313e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // variables of BufferQueueCore objects. It must be locked whenever any
1323e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // member variable is accessed.
133289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    mutable Mutex mMutex;
1343e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1353e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mIsAbandoned indicates that the BufferQueue will no longer be used to
1363e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // consume image buffers pushed to it using the IGraphicBufferProducer
1373e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // interface. It is initialized to false, and set to true in the
1383e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // consumerDisconnect method. A BufferQueue that is abandoned will return
1393e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // the NO_INIT error from all IGraphicBufferProducer methods capable of
1403e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // returning an error.
141289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    bool mIsAbandoned;
1423e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1433e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mConsumerControlledByApp indicates whether the connected consumer is
1443e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // controlled by the application.
145289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    bool mConsumerControlledByApp;
1463e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1473e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mConsumerName is a string used to identify the BufferQueue in log
1483e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // messages. It is set by the IGraphicBufferConsumer::setConsumerName
1493e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // method.
150289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    String8 mConsumerName;
1513e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1523e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mConsumerListener is used to notify the connected consumer of
1533e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // asynchronous events that it may wish to react to. It is initially
1543e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // set to NULL and is written by consumerConnect and consumerDisconnect.
155289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    sp<IConsumerListener> mConsumerListener;
1563e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1573e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mConsumerUsageBits contains flags that the consumer wants for
1583e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // GraphicBuffers.
159289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    uint32_t mConsumerUsageBits;
1603e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1613e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mConnectedApi indicates the producer API that is currently connected
1623e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // to this BufferQueue. It defaults to NO_CONNECTED_API, and gets updated
1633e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // by the connect and disconnect methods.
164289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    int mConnectedApi;
1653e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1663e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mConnectedProducerToken is used to set a binder death notification on
1673e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // the producer.
168f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza    sp<IProducerListener> mConnectedProducerListener;
1693e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1703e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mSlots is an array of buffer slots that must be mirrored on the producer
1713e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // side. This allows buffer ownership to be transferred between the producer
1723e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // and consumer without sending a GraphicBuffer over Binder. The entire
1733e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // array is initialized to NULL at construction time, and buffers are
1743e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // allocated for a slot when requestBuffer is called with that slot's index.
1753e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    BufferQueueDefs::SlotsType mSlots;
1763e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1773e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mQueue is a FIFO of queued buffers used in synchronous mode.
178289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    Fifo mQueue;
1793e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1803e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mOverrideMaxBufferCount is the limit on the number of buffers that will
1813e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // be allocated at one time. This value is set by the producer by calling
1823e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // setBufferCount. The default is 0, which means that the producer doesn't
1833e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // care about the number of buffers in the pool. In that case,
1843e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mDefaultMaxBufferCount is used as the limit.
185289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    int mOverrideMaxBufferCount;
1863e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1873e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mDequeueCondition is a condition variable used for dequeueBuffer in
1883e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // synchronous mode.
189289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    mutable Condition mDequeueCondition;
1903e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1913e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mUseAsyncBuffer indicates whether an extra buffer is used in async mode
1923e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // to prevent dequeueBuffer from blocking.
193289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    bool mUseAsyncBuffer;
1943e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
1953e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mDequeueBufferCannotBlock indicates whether dequeueBuffer is allowed to
1963e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // block. This flag is set during connect when both the producer and
1973e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // consumer are controlled by the application.
198289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    bool mDequeueBufferCannotBlock;
1993e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
2003e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mDefaultBufferFormat can be set so it will override the buffer format
2013e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // when it isn't specified in dequeueBuffer.
202289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    uint32_t mDefaultBufferFormat;
2033e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
2043e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mDefaultWidth holds the default width of allocated buffers. It is used
2053e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // in dequeueBuffer if a width and height of 0 are specified.
206289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    int mDefaultWidth;
2073e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
2083e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mDefaultHeight holds the default height of allocated buffers. It is used
2093e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // in dequeueBuffer if a width and height of 0 are specified.
210289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    int mDefaultHeight;
2113e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
2123e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mDefaultMaxBufferCount is the default limit on the number of buffers that
2133e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // will be allocated at one time. This default limit is set by the consumer.
2143e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // The limit (as opposed to the default limit) may be overriden by the
2153e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // producer.
216289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    int mDefaultMaxBufferCount;
2173e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
2183e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mMaxAcquiredBufferCount is the number of buffers that the consumer may
2193e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // acquire at one time. It defaults to 1, and can be changed by the consumer
2203e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // via setMaxAcquiredBufferCount, but this may only be done while no
2213e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // producer is connected to the BufferQueue. This value is used to derive
2223e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // the value returned for the MIN_UNDEQUEUED_BUFFERS query to the producer.
223289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    int mMaxAcquiredBufferCount;
2243e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
2253e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mBufferHasBeenQueued is true once a buffer has been queued. It is reset
2263e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // when something causes all buffers to be freed (e.g., changing the buffer
2273e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // count).
228289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    bool mBufferHasBeenQueued;
2293e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
2303e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mFrameCounter is the free running counter, incremented on every
2313e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // successful queueBuffer call and buffer allocation.
232289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    uint64_t mFrameCounter;
2333e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza
2343e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza    // mTransformHint is used to optimize for screen rotations.
235289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    uint32_t mTransformHint;
236289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
237399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    // mSidebandStream is a handle to the sideband buffer stream, if any
238399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall    sp<NativeHandle> mSidebandStream;
239399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall
24078014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    // mIsAllocating indicates whether a producer is currently trying to allocate buffers (which
24178014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    // releases mMutex while doing the allocation proper). Producers should not modify any of the
24278014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    // FREE slots while this is true. mIsAllocatingCondition is signaled when this value changes to
24378014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    // false.
24478014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    bool mIsAllocating;
24578014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour
24678014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    // mIsAllocatingCondition is a condition variable used by producers to wait until mIsAllocating
24778014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    // becomes false.
24878014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour    mutable Condition mIsAllocatingCondition;
249289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza}; // class BufferQueueCore
250289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
251289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza} // namespace android
252289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
253289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#endif
254