BufferQueueCore.h revision 9de7293b0a1b01ebe6fb1ab4a498f144adc8029f
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 201c87e474d87d6d1380fb61d476d606b1a2fda1c1Dan Stoza#include <gui/BufferItem.h> 213e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza#include <gui/BufferQueueDefs.h> 22289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <gui/BufferSlot.h> 23289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 24289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/Condition.h> 25289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/Mutex.h> 26399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall#include <utils/NativeHandle.h> 27289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/RefBase.h> 28289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/String8.h> 29289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/StrongPointer.h> 30289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/Trace.h> 31289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/Vector.h> 32289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 330de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza#include <list> 340de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza#include <set> 350de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza 367d831871032675e252490b52ddbb29a63e5497bfDan Albert#define BQ_LOGV(x, ...) ALOGV("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) 377d831871032675e252490b52ddbb29a63e5497bfDan Albert#define BQ_LOGD(x, ...) ALOGD("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) 387d831871032675e252490b52ddbb29a63e5497bfDan Albert#define BQ_LOGI(x, ...) ALOGI("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) 397d831871032675e252490b52ddbb29a63e5497bfDan Albert#define BQ_LOGW(x, ...) ALOGW("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) 407d831871032675e252490b52ddbb29a63e5497bfDan Albert#define BQ_LOGE(x, ...) ALOGE("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) 41289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 42289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define ATRACE_BUFFER_INDEX(index) \ 43289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza if (ATRACE_ENABLED()) { \ 44289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza char ___traceBuf[1024]; \ 45289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza snprintf(___traceBuf, 1024, "%s: %d", \ 46289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza mCore->mConsumerName.string(), (index)); \ 47289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza android::ScopedTrace ___bufTracer(ATRACE_TAG, ___traceBuf); \ 48289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza } 49289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 50289ade165e60b5f71734d30e535f16eb1f4313adDan Stozanamespace android { 51289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 52289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass IConsumerListener; 53289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass IGraphicBufferAlloc; 54f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stozaclass IProducerListener; 55289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 56289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass BufferQueueCore : public virtual RefBase { 57289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 58289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza friend class BufferQueueProducer; 59289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza friend class BufferQueueConsumer; 60289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 61289ade165e60b5f71734d30e535f16eb1f4313adDan Stozapublic: 62289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // Used as a placeholder slot number when the value isn't pointing to an 63289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // existing buffer. 641c87e474d87d6d1380fb61d476d606b1a2fda1c1Dan Stoza enum { INVALID_BUFFER_SLOT = BufferItem::INVALID_BUFFER_SLOT }; 65289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 66289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // We reserve two slots in order to guarantee that the producer and 67289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // consumer can run asynchronously. 683e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza enum { MAX_MAX_ACQUIRED_BUFFERS = BufferQueueDefs::NUM_BUFFER_SLOTS - 2 }; 69289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 70289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // The default API number used to indicate that no producer is connected 71289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza enum { NO_CONNECTED_API = 0 }; 72289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 73289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza typedef Vector<BufferItem> Fifo; 74289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 75289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // BufferQueueCore manages a pool of gralloc memory slots to be used by 76289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // producers and consumers. allocator is used to allocate all the needed 77289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // gralloc buffers. 78289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza BufferQueueCore(const sp<IGraphicBufferAlloc>& allocator = NULL); 79289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza virtual ~BufferQueueCore(); 80289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 81289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaprivate: 823e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // Dump our state in a string 83289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza void dump(String8& result, const char* prefix) const; 84289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 853e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // getMinUndequeuedBufferCountLocked returns the minimum number of buffers 863e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // that must remain in a state other than DEQUEUED. The async parameter 873e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // tells whether we're in asynchronous mode. 88289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza int getMinUndequeuedBufferCountLocked(bool async) const; 893e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 903e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // getMinMaxBufferCountLocked returns the minimum number of buffers allowed 913e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // given the current BufferQueue state. The async parameter tells whether 923e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // we're in asynchonous mode. 93289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza int getMinMaxBufferCountLocked(bool async) const; 943e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 953e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // getMaxBufferCountLocked returns the maximum number of buffers that can be 963e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // allocated at once. This value depends on the following member variables: 973e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // 983e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mDequeueBufferCannotBlock 993e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mMaxAcquiredBufferCount 1003e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mDefaultMaxBufferCount 1013e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mOverrideMaxBufferCount 1023e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // async parameter 1033e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // 1043e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // Any time one of these member variables is changed while a producer is 1053e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // connected, mDequeueCondition must be broadcast. 106289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza int getMaxBufferCountLocked(bool async) const; 1073e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1083e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // setDefaultMaxBufferCountLocked sets the maximum number of buffer slots 1093e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // that will be used if the producer does not override the buffer slot 1103e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // count. The count must be between 2 and NUM_BUFFER_SLOTS, inclusive. The 1113e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // initial default is 2. 112289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza status_t setDefaultMaxBufferCountLocked(int count); 1133e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1143e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // freeBufferLocked frees the GraphicBuffer and sync resources for the 1153e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // given slot. 116289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza void freeBufferLocked(int slot); 1173e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1183e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // freeAllBuffersLocked frees the GraphicBuffer and sync resources for 1193e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // all slots. 120289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza void freeAllBuffersLocked(); 1213e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1223e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // stillTracking returns true iff the buffer item is still being tracked 1233e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // in one of the slots. 124289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool stillTracking(const BufferItem* item) const; 125289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 12678014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour // waitWhileAllocatingLocked blocks until mIsAllocating is false. 12778014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour void waitWhileAllocatingLocked() const; 12878014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour 1290de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza // validateConsistencyLocked ensures that the free lists are in sync with 1300de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza // the information stored in mSlots 1310de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza void validateConsistencyLocked() const; 1320de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza 1333e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mAllocator is the connection to SurfaceFlinger that is used to allocate 1343e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // new GraphicBuffer objects. 1353e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza sp<IGraphicBufferAlloc> mAllocator; 1363e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1373e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mMutex is the mutex used to prevent concurrent access to the member 1383e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // variables of BufferQueueCore objects. It must be locked whenever any 1393e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // member variable is accessed. 140289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza mutable Mutex mMutex; 1413e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1423e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mIsAbandoned indicates that the BufferQueue will no longer be used to 1433e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // consume image buffers pushed to it using the IGraphicBufferProducer 1443e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // interface. It is initialized to false, and set to true in the 1453e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // consumerDisconnect method. A BufferQueue that is abandoned will return 1463e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // the NO_INIT error from all IGraphicBufferProducer methods capable of 1473e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // returning an error. 148289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool mIsAbandoned; 1493e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1503e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mConsumerControlledByApp indicates whether the connected consumer is 1513e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // controlled by the application. 152289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool mConsumerControlledByApp; 1533e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1543e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mConsumerName is a string used to identify the BufferQueue in log 1553e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // messages. It is set by the IGraphicBufferConsumer::setConsumerName 1563e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // method. 157289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza String8 mConsumerName; 1583e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1593e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mConsumerListener is used to notify the connected consumer of 1603e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // asynchronous events that it may wish to react to. It is initially 1613e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // set to NULL and is written by consumerConnect and consumerDisconnect. 162289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza sp<IConsumerListener> mConsumerListener; 1633e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1643e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mConsumerUsageBits contains flags that the consumer wants for 1653e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // GraphicBuffers. 166289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza uint32_t mConsumerUsageBits; 1673e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1683e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mConnectedApi indicates the producer API that is currently connected 1693e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // to this BufferQueue. It defaults to NO_CONNECTED_API, and gets updated 1703e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // by the connect and disconnect methods. 171289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza int mConnectedApi; 1723e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1733e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mConnectedProducerToken is used to set a binder death notification on 1743e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // the producer. 175f0eaf25e9247edf4d124bedaeb863f7abdf35a3eDan Stoza sp<IProducerListener> mConnectedProducerListener; 1763e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1773e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mSlots is an array of buffer slots that must be mirrored on the producer 1783e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // side. This allows buffer ownership to be transferred between the producer 1793e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // and consumer without sending a GraphicBuffer over Binder. The entire 1803e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // array is initialized to NULL at construction time, and buffers are 1813e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // allocated for a slot when requestBuffer is called with that slot's index. 1823e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza BufferQueueDefs::SlotsType mSlots; 1833e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1843e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mQueue is a FIFO of queued buffers used in synchronous mode. 185289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza Fifo mQueue; 1863e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 1870de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza // mFreeSlots contains all of the slots which are FREE and do not currently 1880de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza // have a buffer attached 1890de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza std::set<int> mFreeSlots; 1900de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza 1910de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza // mFreeBuffers contains all of the slots which are FREE and currently have 1920de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza // a buffer attached 1930de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza std::list<int> mFreeBuffers; 1940de7ea752900b5da29ad19c2799040235477f3c5Dan Stoza 1953e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mOverrideMaxBufferCount is the limit on the number of buffers that will 1963e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // be allocated at one time. This value is set by the producer by calling 1973e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // setBufferCount. The default is 0, which means that the producer doesn't 1983e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // care about the number of buffers in the pool. In that case, 1993e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mDefaultMaxBufferCount is used as the limit. 200289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza int mOverrideMaxBufferCount; 2013e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2023e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mDequeueCondition is a condition variable used for dequeueBuffer in 2033e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // synchronous mode. 204289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza mutable Condition mDequeueCondition; 2053e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2063e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mUseAsyncBuffer indicates whether an extra buffer is used in async mode 2073e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // to prevent dequeueBuffer from blocking. 208289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool mUseAsyncBuffer; 2093e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2103e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mDequeueBufferCannotBlock indicates whether dequeueBuffer is allowed to 2113e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // block. This flag is set during connect when both the producer and 2123e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // consumer are controlled by the application. 213289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool mDequeueBufferCannotBlock; 2143e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2153e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mDefaultBufferFormat can be set so it will override the buffer format 2163e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // when it isn't specified in dequeueBuffer. 2173be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza PixelFormat mDefaultBufferFormat; 2183e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2193e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mDefaultWidth holds the default width of allocated buffers. It is used 2203e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // in dequeueBuffer if a width and height of 0 are specified. 2213be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza uint32_t mDefaultWidth; 2223e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2233e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mDefaultHeight holds the default height of allocated buffers. It is used 2243e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // in dequeueBuffer if a width and height of 0 are specified. 2253be1c6b60a188dc10025e2ce156c11fac050625dDan Stoza uint32_t mDefaultHeight; 2263e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 22782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala // mDefaultBufferDataSpace holds the default dataSpace of queued buffers. 22882c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala // It is used in queueBuffer if a dataspace of 0 (HAL_DATASPACE_UNKNOWN) 22982c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala // is specified. 23082c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala android_dataspace mDefaultBufferDataSpace; 23182c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala 2323e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mDefaultMaxBufferCount is the default limit on the number of buffers that 2333e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // will be allocated at one time. This default limit is set by the consumer. 2343e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // The limit (as opposed to the default limit) may be overriden by the 2353e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // producer. 236289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza int mDefaultMaxBufferCount; 2373e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2383e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mMaxAcquiredBufferCount is the number of buffers that the consumer may 2393e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // acquire at one time. It defaults to 1, and can be changed by the consumer 2403e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // via setMaxAcquiredBufferCount, but this may only be done while no 2413e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // producer is connected to the BufferQueue. This value is used to derive 2423e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // the value returned for the MIN_UNDEQUEUED_BUFFERS query to the producer. 243289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza int mMaxAcquiredBufferCount; 2443e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2453e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mBufferHasBeenQueued is true once a buffer has been queued. It is reset 2463e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // when something causes all buffers to be freed (e.g., changing the buffer 2473e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // count). 248289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool mBufferHasBeenQueued; 2493e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2503e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mFrameCounter is the free running counter, incremented on every 2513e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // successful queueBuffer call and buffer allocation. 252289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza uint64_t mFrameCounter; 2533e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza 2543e96f1982fda358424b0b75f394cbf7c1794a072Dan Stoza // mTransformHint is used to optimize for screen rotations. 255289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza uint32_t mTransformHint; 256289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 257399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall // mSidebandStream is a handle to the sideband buffer stream, if any 258399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall sp<NativeHandle> mSidebandStream; 259399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall 26078014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour // mIsAllocating indicates whether a producer is currently trying to allocate buffers (which 26178014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour // releases mMutex while doing the allocation proper). Producers should not modify any of the 26278014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour // FREE slots while this is true. mIsAllocatingCondition is signaled when this value changes to 26378014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour // false. 26478014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour bool mIsAllocating; 26578014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour 26678014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour // mIsAllocatingCondition is a condition variable used by producers to wait until mIsAllocating 26778014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour // becomes false. 26878014f32da6d0ebf52fb34ebb7663863000520a0Antoine Labour mutable Condition mIsAllocatingCondition; 2699de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza 2709de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza // mAllowAllocation determines whether dequeueBuffer is allowed to allocate 2719de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza // new buffers 2729de7293b0a1b01ebe6fb1ab4a498f144adc8029fDan Stoza bool mAllowAllocation; 273289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza}; // class BufferQueueCore 274289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 275289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza} // namespace android 276289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 277289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#endif 278