| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_GUI_BUFFERQUEUECORE_H |
| 18 | #define ANDROID_GUI_BUFFERQUEUECORE_H |
| 19 | |
| Dan Stoza | 1c87e47 | 2015-03-13 14:40:34 -0700 | [diff] [blame] | 20 | #include <gui/BufferItem.h> |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 21 | #include <gui/BufferQueueDefs.h> |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 22 | #include <gui/BufferSlot.h> |
| Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 23 | #include <gui/OccupancyTracker.h> |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 24 | |
| 25 | #include <utils/Condition.h> |
| 26 | #include <utils/Mutex.h> |
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 27 | #include <utils/NativeHandle.h> |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
| 29 | #include <utils/String8.h> |
| 30 | #include <utils/StrongPointer.h> |
| 31 | #include <utils/Trace.h> |
| 32 | #include <utils/Vector.h> |
| 33 | |
| Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 34 | #include <list> |
| 35 | #include <set> |
| 36 | |
| Dan Albert | 7d83187 | 2014-09-09 09:21:28 -0700 | [diff] [blame] | 37 | #define BQ_LOGV(x, ...) ALOGV("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) |
| 38 | #define BQ_LOGD(x, ...) ALOGD("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) |
| 39 | #define BQ_LOGI(x, ...) ALOGI("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) |
| 40 | #define BQ_LOGW(x, ...) ALOGW("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) |
| 41 | #define BQ_LOGE(x, ...) ALOGE("[%s] " x, mConsumerName.string(), ##__VA_ARGS__) |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 42 | |
| 43 | #define ATRACE_BUFFER_INDEX(index) \ |
| 44 | if (ATRACE_ENABLED()) { \ |
| 45 | char ___traceBuf[1024]; \ |
| 46 | snprintf(___traceBuf, 1024, "%s: %d", \ |
| 47 | mCore->mConsumerName.string(), (index)); \ |
| 48 | android::ScopedTrace ___bufTracer(ATRACE_TAG, ___traceBuf); \ |
| 49 | } |
| 50 | |
| 51 | namespace android { |
| 52 | |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 53 | class IConsumerListener; |
| 54 | class IGraphicBufferAlloc; |
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 55 | class IProducerListener; |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 56 | |
| 57 | class BufferQueueCore : public virtual RefBase { |
| 58 | |
| 59 | friend class BufferQueueProducer; |
| 60 | friend class BufferQueueConsumer; |
| 61 | |
| 62 | public: |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 63 | // Used as a placeholder slot number when the value isn't pointing to an |
| 64 | // existing buffer. |
| Dan Stoza | 1c87e47 | 2015-03-13 14:40:34 -0700 | [diff] [blame] | 65 | enum { INVALID_BUFFER_SLOT = BufferItem::INVALID_BUFFER_SLOT }; |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 66 | |
| 67 | // We reserve two slots in order to guarantee that the producer and |
| 68 | // consumer can run asynchronously. |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 69 | enum { MAX_MAX_ACQUIRED_BUFFERS = BufferQueueDefs::NUM_BUFFER_SLOTS - 2 }; |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 70 | |
| Chong Zhang | 1b3a9ac | 2016-02-29 16:47:47 -0800 | [diff] [blame] | 71 | enum { |
| 72 | // The API number used to indicate the currently connected producer |
| 73 | CURRENTLY_CONNECTED_API = -1, |
| 74 | |
| 75 | // The API number used to indicate that no producer is connected |
| 76 | NO_CONNECTED_API = 0, |
| 77 | }; |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 78 | |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 79 | typedef Vector<BufferItem> Fifo; |
| 80 | |
| 81 | // BufferQueueCore manages a pool of gralloc memory slots to be used by |
| 82 | // producers and consumers. allocator is used to allocate all the needed |
| 83 | // gralloc buffers. |
| Dan Stoza | 70982a5 | 2016-01-11 23:40:44 +0000 | [diff] [blame] | 84 | BufferQueueCore(const sp<IGraphicBufferAlloc>& allocator = NULL); |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 85 | virtual ~BufferQueueCore(); |
| 86 | |
| 87 | private: |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 88 | // Dump our state in a string |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 89 | void dump(String8& result, const char* prefix) const; |
| 90 | |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 91 | // getMinUndequeuedBufferCountLocked returns the minimum number of buffers |
| 92 | // that must remain in a state other than DEQUEUED. The async parameter |
| 93 | // tells whether we're in asynchronous mode. |
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 94 | int getMinUndequeuedBufferCountLocked() const; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 95 | |
| 96 | // getMinMaxBufferCountLocked returns the minimum number of buffers allowed |
| 97 | // given the current BufferQueue state. The async parameter tells whether |
| 98 | // we're in asynchonous mode. |
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 99 | int getMinMaxBufferCountLocked() const; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 100 | |
| 101 | // getMaxBufferCountLocked returns the maximum number of buffers that can be |
| 102 | // allocated at once. This value depends on the following member variables: |
| 103 | // |
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 104 | // mMaxDequeuedBufferCount |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 105 | // mMaxAcquiredBufferCount |
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 106 | // mMaxBufferCount |
| 107 | // mAsyncMode |
| 108 | // mDequeueBufferCannotBlock |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 109 | // |
| 110 | // Any time one of these member variables is changed while a producer is |
| 111 | // connected, mDequeueCondition must be broadcast. |
| Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 112 | int getMaxBufferCountLocked() const; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 113 | |
| Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 114 | // This performs the same computation but uses the given arguments instead |
| 115 | // of the member variables for mMaxBufferCount, mAsyncMode, and |
| 116 | // mDequeueBufferCannotBlock. |
| 117 | int getMaxBufferCountLocked(bool asyncMode, |
| 118 | bool dequeueBufferCannotBlock, int maxBufferCount) const; |
| 119 | |
| 120 | // clearBufferSlotLocked frees the GraphicBuffer and sync resources for the |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 121 | // given slot. |
| Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 122 | void clearBufferSlotLocked(int slot); |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 123 | |
| 124 | // freeAllBuffersLocked frees the GraphicBuffer and sync resources for |
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 125 | // all slots, even if they're currently dequeued, queued, or acquired. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 126 | void freeAllBuffersLocked(); |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 127 | |
| Eino-Ville Talvala | bc2df65 | 2016-07-21 17:06:58 -0700 | [diff] [blame^] | 128 | // discardFreeBuffersLocked releases all currently-free buffers held by the |
| 129 | // queue, in order to reduce the memory consumption of the queue to the |
| 130 | // minimum possible without discarding data. |
| 131 | void discardFreeBuffersLocked(); |
| 132 | |
| Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 133 | // If delta is positive, makes more slots available. If negative, takes |
| 134 | // away slots. Returns false if the request can't be met. |
| 135 | bool adjustAvailableSlotsLocked(int delta); |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 136 | |
| Antoine Labour | 78014f3 | 2014-07-15 21:17:03 -0700 | [diff] [blame] | 137 | // waitWhileAllocatingLocked blocks until mIsAllocating is false. |
| 138 | void waitWhileAllocatingLocked() const; |
| 139 | |
| Pablo Ceballos | 9e31433 | 2016-01-12 13:49:19 -0800 | [diff] [blame] | 140 | #if DEBUG_ONLY_CODE |
| Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 141 | // validateConsistencyLocked ensures that the free lists are in sync with |
| 142 | // the information stored in mSlots |
| 143 | void validateConsistencyLocked() const; |
| Pablo Ceballos | 9e31433 | 2016-01-12 13:49:19 -0800 | [diff] [blame] | 144 | #endif |
| Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 145 | |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 146 | // mAllocator is the connection to SurfaceFlinger that is used to allocate |
| 147 | // new GraphicBuffer objects. |
| 148 | sp<IGraphicBufferAlloc> mAllocator; |
| 149 | |
| 150 | // mMutex is the mutex used to prevent concurrent access to the member |
| 151 | // variables of BufferQueueCore objects. It must be locked whenever any |
| 152 | // member variable is accessed. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 153 | mutable Mutex mMutex; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 154 | |
| 155 | // mIsAbandoned indicates that the BufferQueue will no longer be used to |
| 156 | // consume image buffers pushed to it using the IGraphicBufferProducer |
| 157 | // interface. It is initialized to false, and set to true in the |
| 158 | // consumerDisconnect method. A BufferQueue that is abandoned will return |
| 159 | // the NO_INIT error from all IGraphicBufferProducer methods capable of |
| 160 | // returning an error. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 161 | bool mIsAbandoned; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 162 | |
| 163 | // mConsumerControlledByApp indicates whether the connected consumer is |
| 164 | // controlled by the application. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 165 | bool mConsumerControlledByApp; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 166 | |
| 167 | // mConsumerName is a string used to identify the BufferQueue in log |
| 168 | // messages. It is set by the IGraphicBufferConsumer::setConsumerName |
| 169 | // method. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 170 | String8 mConsumerName; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 171 | |
| 172 | // mConsumerListener is used to notify the connected consumer of |
| 173 | // asynchronous events that it may wish to react to. It is initially |
| 174 | // set to NULL and is written by consumerConnect and consumerDisconnect. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 175 | sp<IConsumerListener> mConsumerListener; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 176 | |
| 177 | // mConsumerUsageBits contains flags that the consumer wants for |
| 178 | // GraphicBuffers. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 179 | uint32_t mConsumerUsageBits; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 180 | |
| 181 | // mConnectedApi indicates the producer API that is currently connected |
| 182 | // to this BufferQueue. It defaults to NO_CONNECTED_API, and gets updated |
| 183 | // by the connect and disconnect methods. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 184 | int mConnectedApi; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 185 | |
| 186 | // mConnectedProducerToken is used to set a binder death notification on |
| 187 | // the producer. |
| Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 188 | sp<IProducerListener> mConnectedProducerListener; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 189 | |
| 190 | // mSlots is an array of buffer slots that must be mirrored on the producer |
| 191 | // side. This allows buffer ownership to be transferred between the producer |
| 192 | // and consumer without sending a GraphicBuffer over Binder. The entire |
| 193 | // array is initialized to NULL at construction time, and buffers are |
| 194 | // allocated for a slot when requestBuffer is called with that slot's index. |
| 195 | BufferQueueDefs::SlotsType mSlots; |
| 196 | |
| 197 | // mQueue is a FIFO of queued buffers used in synchronous mode. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 198 | Fifo mQueue; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 199 | |
| Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 200 | // mFreeSlots contains all of the slots which are FREE and do not currently |
| Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 201 | // have a buffer attached. |
| Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 202 | std::set<int> mFreeSlots; |
| 203 | |
| 204 | // mFreeBuffers contains all of the slots which are FREE and currently have |
| Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 205 | // a buffer attached. |
| Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 206 | std::list<int> mFreeBuffers; |
| 207 | |
| Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 208 | // mUnusedSlots contains all slots that are currently unused. They should be |
| 209 | // free and not have a buffer attached. |
| 210 | std::list<int> mUnusedSlots; |
| 211 | |
| 212 | // mActiveBuffers contains all slots which have a non-FREE buffer attached. |
| 213 | std::set<int> mActiveBuffers; |
| 214 | |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 215 | // mDequeueCondition is a condition variable used for dequeueBuffer in |
| 216 | // synchronous mode. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 217 | mutable Condition mDequeueCondition; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 218 | |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 219 | // mDequeueBufferCannotBlock indicates whether dequeueBuffer is allowed to |
| 220 | // block. This flag is set during connect when both the producer and |
| 221 | // consumer are controlled by the application. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 222 | bool mDequeueBufferCannotBlock; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 223 | |
| 224 | // mDefaultBufferFormat can be set so it will override the buffer format |
| 225 | // when it isn't specified in dequeueBuffer. |
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 226 | PixelFormat mDefaultBufferFormat; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 227 | |
| 228 | // mDefaultWidth holds the default width of allocated buffers. It is used |
| 229 | // in dequeueBuffer if a width and height of 0 are specified. |
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 230 | uint32_t mDefaultWidth; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 231 | |
| 232 | // mDefaultHeight holds the default height of allocated buffers. It is used |
| 233 | // in dequeueBuffer if a width and height of 0 are specified. |
| Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 234 | uint32_t mDefaultHeight; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 235 | |
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 236 | // mDefaultBufferDataSpace holds the default dataSpace of queued buffers. |
| 237 | // It is used in queueBuffer if a dataspace of 0 (HAL_DATASPACE_UNKNOWN) |
| 238 | // is specified. |
| 239 | android_dataspace mDefaultBufferDataSpace; |
| 240 | |
| Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 241 | // mMaxBufferCount is the limit on the number of buffers that will be |
| 242 | // allocated at one time. This limit can be set by the consumer. |
| 243 | int mMaxBufferCount; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 244 | |
| 245 | // mMaxAcquiredBufferCount is the number of buffers that the consumer may |
| 246 | // acquire at one time. It defaults to 1, and can be changed by the consumer |
| 247 | // via setMaxAcquiredBufferCount, but this may only be done while no |
| 248 | // producer is connected to the BufferQueue. This value is used to derive |
| 249 | // the value returned for the MIN_UNDEQUEUED_BUFFERS query to the producer. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 250 | int mMaxAcquiredBufferCount; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 251 | |
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 252 | // mMaxDequeuedBufferCount is the number of buffers that the producer may |
| 253 | // dequeue at one time. It defaults to 1, and can be changed by the producer |
| 254 | // via setMaxDequeuedBufferCount. |
| 255 | int mMaxDequeuedBufferCount; |
| 256 | |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 257 | // mBufferHasBeenQueued is true once a buffer has been queued. It is reset |
| 258 | // when something causes all buffers to be freed (e.g., changing the buffer |
| 259 | // count). |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 260 | bool mBufferHasBeenQueued; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 261 | |
| 262 | // mFrameCounter is the free running counter, incremented on every |
| 263 | // successful queueBuffer call and buffer allocation. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 264 | uint64_t mFrameCounter; |
| Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 265 | |
| 266 | // mTransformHint is used to optimize for screen rotations. |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 267 | uint32_t mTransformHint; |
| 268 | |
| Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 269 | // mSidebandStream is a handle to the sideband buffer stream, if any |
| 270 | sp<NativeHandle> mSidebandStream; |
| 271 | |
| Antoine Labour | 78014f3 | 2014-07-15 21:17:03 -0700 | [diff] [blame] | 272 | // mIsAllocating indicates whether a producer is currently trying to allocate buffers (which |
| 273 | // releases mMutex while doing the allocation proper). Producers should not modify any of the |
| 274 | // FREE slots while this is true. mIsAllocatingCondition is signaled when this value changes to |
| 275 | // false. |
| 276 | bool mIsAllocating; |
| 277 | |
| 278 | // mIsAllocatingCondition is a condition variable used by producers to wait until mIsAllocating |
| 279 | // becomes false. |
| 280 | mutable Condition mIsAllocatingCondition; |
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 281 | |
| 282 | // mAllowAllocation determines whether dequeueBuffer is allowed to allocate |
| 283 | // new buffers |
| 284 | bool mAllowAllocation; |
| Dan Stoza | 4afd8b6 | 2015-02-25 16:49:08 -0800 | [diff] [blame] | 285 | |
| 286 | // mBufferAge tracks the age of the contents of the most recently dequeued |
| 287 | // buffer as the number of frames that have elapsed since it was last queued |
| 288 | uint64_t mBufferAge; |
| Dan Stoza | ecc5040 | 2015-04-28 14:42:06 -0700 | [diff] [blame] | 289 | |
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 290 | // mGenerationNumber stores the current generation number of the attached |
| 291 | // producer. Any attempt to attach a buffer with a different generation |
| 292 | // number will fail. |
| 293 | uint32_t mGenerationNumber; |
| 294 | |
| Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 295 | // mAsyncMode indicates whether or not async mode is enabled. |
| 296 | // In async mode an extra buffer will be allocated to allow the producer to |
| 297 | // enqueue buffers without blocking. |
| 298 | bool mAsyncMode; |
| 299 | |
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 300 | // mSharedBufferMode indicates whether or not shared buffer mode is enabled. |
| 301 | bool mSharedBufferMode; |
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 302 | |
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 303 | // When shared buffer mode is enabled, this indicates whether the consumer |
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 304 | // should acquire buffers even if BufferQueue doesn't indicate that they are |
| 305 | // available. |
| 306 | bool mAutoRefresh; |
| 307 | |
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 308 | // When shared buffer mode is enabled, this tracks which slot contains the |
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 309 | // shared buffer. |
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 310 | int mSharedBufferSlot; |
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 311 | |
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 312 | // Cached data about the shared buffer in shared buffer mode |
| 313 | struct SharedBufferCache { |
| 314 | SharedBufferCache(Rect _crop, uint32_t _transform, int _scalingMode, |
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 315 | android_dataspace _dataspace) |
| 316 | : crop(_crop), |
| 317 | transform(_transform), |
| 318 | scalingMode(_scalingMode), |
| 319 | dataspace(_dataspace) { |
| 320 | }; |
| 321 | |
| 322 | Rect crop; |
| 323 | uint32_t transform; |
| 324 | uint32_t scalingMode; |
| 325 | android_dataspace dataspace; |
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 326 | } mSharedBufferCache; |
| Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 327 | |
| Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 328 | // The slot of the last queued buffer |
| 329 | int mLastQueuedSlot; |
| 330 | |
| Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 331 | OccupancyTracker mOccupancyTracker; |
| 332 | |
| Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 333 | const uint64_t mUniqueId; |
| 334 | |
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 335 | }; // class BufferQueueCore |
| 336 | |
| 337 | } // namespace android |
| 338 | |
| 339 | #endif |