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 | |
Mark Salyzyn | 8f515ce | 2014-06-09 14:32:04 -0700 | [diff] [blame] | 17 | #include <inttypes.h> |
| 18 | |
Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 19 | #define LOG_TAG "BufferQueueConsumer" |
| 20 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 21 | //#define LOG_NDEBUG 0 |
| 22 | |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 23 | #include <gui/BufferItem.h> |
| 24 | #include <gui/BufferQueueConsumer.h> |
| 25 | #include <gui/BufferQueueCore.h> |
| 26 | #include <gui/IConsumerListener.h> |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 27 | #include <gui/IProducerListener.h> |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | BufferQueueConsumer::BufferQueueConsumer(const sp<BufferQueueCore>& core) : |
| 32 | mCore(core), |
| 33 | mSlots(core->mSlots), |
| 34 | mConsumerName() {} |
| 35 | |
| 36 | BufferQueueConsumer::~BufferQueueConsumer() {} |
| 37 | |
| 38 | status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer, |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 39 | nsecs_t expectedPresent, uint64_t maxFrameNumber) { |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 40 | ATRACE_CALL(); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 41 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 42 | int numDroppedBuffers = 0; |
| 43 | sp<IProducerListener> listener; |
| 44 | { |
| 45 | Mutex::Autolock lock(mCore->mMutex); |
| 46 | |
| 47 | // Check that the consumer doesn't currently have the maximum number of |
| 48 | // buffers acquired. We allow the max buffer count to be exceeded by one |
| 49 | // buffer so that the consumer can successfully set up the newly acquired |
| 50 | // buffer before releasing the old one. |
| 51 | int numAcquiredBuffers = 0; |
| 52 | for (int s = 0; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 53 | if (mSlots[s].mBufferState.isAcquired()) { |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 54 | ++numAcquiredBuffers; |
| 55 | } |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 56 | } |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 57 | if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1) { |
| 58 | BQ_LOGE("acquireBuffer: max acquired buffer count reached: %d (max %d)", |
| 59 | numAcquiredBuffers, mCore->mMaxAcquiredBufferCount); |
| 60 | return INVALID_OPERATION; |
| 61 | } |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 62 | |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 63 | bool sharedBufferAvailable = mCore->mSingleBufferMode && |
| 64 | mCore->mSingleBufferSlot != |
| 65 | BufferQueueCore::INVALID_BUFFER_SLOT; |
| 66 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 67 | // In asynchronous mode the list is guaranteed to be one buffer deep, |
| 68 | // while in synchronous mode we use the oldest buffer. |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 69 | if (mCore->mQueue.empty() && !sharedBufferAvailable) { |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 70 | return NO_BUFFER_AVAILABLE; |
| 71 | } |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 72 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 73 | BufferQueueCore::Fifo::iterator front(mCore->mQueue.begin()); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 74 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 75 | // If expectedPresent is specified, we may not want to return a buffer yet. |
| 76 | // If it's specified and there's more than one buffer queued, we may want |
| 77 | // to drop a buffer. |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 78 | // Skip this if we're in single buffer mode and the queue is empty, |
| 79 | // since in that case we'll just return the shared buffer. |
| 80 | if (expectedPresent != 0 && !mCore->mQueue.empty()) { |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 81 | const int MAX_REASONABLE_NSEC = 1000000000ULL; // 1 second |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 82 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 83 | // The 'expectedPresent' argument indicates when the buffer is expected |
| 84 | // to be presented on-screen. If the buffer's desired present time is |
| 85 | // earlier (less) than expectedPresent -- meaning it will be displayed |
| 86 | // on time or possibly late if we show it as soon as possible -- we |
| 87 | // acquire and return it. If we don't want to display it until after the |
| 88 | // expectedPresent time, we return PRESENT_LATER without acquiring it. |
| 89 | // |
| 90 | // To be safe, we don't defer acquisition if expectedPresent is more |
| 91 | // than one second in the future beyond the desired present time |
| 92 | // (i.e., we'd be holding the buffer for a long time). |
| 93 | // |
| 94 | // NOTE: Code assumes monotonic time values from the system clock |
| 95 | // are positive. |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 96 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 97 | // Start by checking to see if we can drop frames. We skip this check if |
| 98 | // the timestamps are being auto-generated by Surface. If the app isn't |
| 99 | // generating timestamps explicitly, it probably doesn't want frames to |
| 100 | // be discarded based on them. |
| 101 | while (mCore->mQueue.size() > 1 && !mCore->mQueue[0].mIsAutoTimestamp) { |
| 102 | const BufferItem& bufferItem(mCore->mQueue[1]); |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 103 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 104 | // If dropping entry[0] would leave us with a buffer that the |
| 105 | // consumer is not yet ready for, don't drop it. |
| 106 | if (maxFrameNumber && bufferItem.mFrameNumber > maxFrameNumber) { |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | // If entry[1] is timely, drop entry[0] (and repeat). We apply an |
| 111 | // additional criterion here: we only drop the earlier buffer if our |
| 112 | // desiredPresent falls within +/- 1 second of the expected present. |
| 113 | // Otherwise, bogus desiredPresent times (e.g., 0 or a small |
| 114 | // relative timestamp), which normally mean "ignore the timestamp |
| 115 | // and acquire immediately", would cause us to drop frames. |
| 116 | // |
| 117 | // We may want to add an additional criterion: don't drop the |
| 118 | // earlier buffer if entry[1]'s fence hasn't signaled yet. |
| 119 | nsecs_t desiredPresent = bufferItem.mTimestamp; |
| 120 | if (desiredPresent < expectedPresent - MAX_REASONABLE_NSEC || |
| 121 | desiredPresent > expectedPresent) { |
| 122 | // This buffer is set to display in the near future, or |
| 123 | // desiredPresent is garbage. Either way we don't want to drop |
| 124 | // the previous buffer just to get this on the screen sooner. |
| 125 | BQ_LOGV("acquireBuffer: nodrop desire=%" PRId64 " expect=%" |
| 126 | PRId64 " (%" PRId64 ") now=%" PRId64, |
| 127 | desiredPresent, expectedPresent, |
| 128 | desiredPresent - expectedPresent, |
| 129 | systemTime(CLOCK_MONOTONIC)); |
| 130 | break; |
| 131 | } |
| 132 | |
| 133 | BQ_LOGV("acquireBuffer: drop desire=%" PRId64 " expect=%" PRId64 |
| 134 | " size=%zu", |
| 135 | desiredPresent, expectedPresent, mCore->mQueue.size()); |
| 136 | if (mCore->stillTracking(front)) { |
| 137 | // Front buffer is still in mSlots, so mark the slot as free |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 138 | mSlots[front->mSlot].mBufferState.freeQueued(); |
| 139 | |
| 140 | // After leaving single buffer mode, the shared buffer will |
| 141 | // still be around. Mark it as no longer shared if this |
| 142 | // operation causes it to be free. |
| 143 | if (!mCore->mSingleBufferMode && |
| 144 | mSlots[front->mSlot].mBufferState.isFree()) { |
| 145 | mSlots[front->mSlot].mBufferState.mShared = false; |
| 146 | } |
| 147 | // Don't put the shared buffer on the free list. |
| 148 | if (!mSlots[front->mSlot].mBufferState.isShared()) { |
| 149 | mCore->mFreeBuffers.push_back(front->mSlot); |
| 150 | } |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 151 | listener = mCore->mConnectedProducerListener; |
| 152 | ++numDroppedBuffers; |
| 153 | } |
| 154 | mCore->mQueue.erase(front); |
| 155 | front = mCore->mQueue.begin(); |
Dan Stoza | ecc5040 | 2015-04-28 14:42:06 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 158 | // See if the front buffer is ready to be acquired |
| 159 | nsecs_t desiredPresent = front->mTimestamp; |
| 160 | bool bufferIsDue = desiredPresent <= expectedPresent || |
| 161 | desiredPresent > expectedPresent + MAX_REASONABLE_NSEC; |
| 162 | bool consumerIsReady = maxFrameNumber > 0 ? |
| 163 | front->mFrameNumber <= maxFrameNumber : true; |
| 164 | if (!bufferIsDue || !consumerIsReady) { |
| 165 | BQ_LOGV("acquireBuffer: defer desire=%" PRId64 " expect=%" PRId64 |
| 166 | " (%" PRId64 ") now=%" PRId64 " frame=%" PRIu64 |
| 167 | " consumer=%" PRIu64, |
Mark Salyzyn | 8f515ce | 2014-06-09 14:32:04 -0700 | [diff] [blame] | 168 | desiredPresent, expectedPresent, |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 169 | desiredPresent - expectedPresent, |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 170 | systemTime(CLOCK_MONOTONIC), |
| 171 | front->mFrameNumber, maxFrameNumber); |
| 172 | return PRESENT_LATER; |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 175 | BQ_LOGV("acquireBuffer: accept desire=%" PRId64 " expect=%" PRId64 " " |
| 176 | "(%" PRId64 ") now=%" PRId64, desiredPresent, expectedPresent, |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 177 | desiredPresent - expectedPresent, |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 178 | systemTime(CLOCK_MONOTONIC)); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 181 | int slot = BufferQueueCore::INVALID_BUFFER_SLOT; |
| 182 | |
| 183 | if (sharedBufferAvailable && mCore->mQueue.empty()) { |
| 184 | // make sure the buffer has finished allocating before acquiring it |
| 185 | mCore->waitWhileAllocatingLocked(); |
| 186 | |
| 187 | slot = mCore->mSingleBufferSlot; |
| 188 | |
| 189 | // Recreate the BufferItem for the shared buffer from the data that |
| 190 | // was cached when it was last queued. |
| 191 | outBuffer->mGraphicBuffer = mSlots[slot].mGraphicBuffer; |
| 192 | outBuffer->mFence = Fence::NO_FENCE; |
| 193 | outBuffer->mCrop = mCore->mSingleBufferCache.crop; |
| 194 | outBuffer->mTransform = mCore->mSingleBufferCache.transform & |
| 195 | ~static_cast<uint32_t>( |
| 196 | NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY); |
| 197 | outBuffer->mScalingMode = mCore->mSingleBufferCache.scalingMode; |
| 198 | outBuffer->mDataSpace = mCore->mSingleBufferCache.dataspace; |
| 199 | outBuffer->mFrameNumber = mCore->mFrameCounter; |
| 200 | outBuffer->mSlot = slot; |
| 201 | outBuffer->mAcquireCalled = mSlots[slot].mAcquireCalled; |
| 202 | outBuffer->mTransformToDisplayInverse = |
| 203 | (mCore->mSingleBufferCache.transform & |
| 204 | NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY) != 0; |
| 205 | outBuffer->mSurfaceDamage = Region::INVALID_REGION; |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 206 | outBuffer->mSingleBufferMode = true; |
| 207 | outBuffer->mQueuedBuffer = false; |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 208 | } else { |
| 209 | slot = front->mSlot; |
| 210 | *outBuffer = *front; |
| 211 | } |
| 212 | |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 213 | outBuffer->mSingleBufferMode = mCore->mSingleBufferMode; |
| 214 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 215 | ATRACE_BUFFER_INDEX(slot); |
| 216 | |
| 217 | BQ_LOGV("acquireBuffer: acquiring { slot=%d/%" PRIu64 " buffer=%p }", |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 218 | slot, outBuffer->mFrameNumber, outBuffer->mGraphicBuffer->handle); |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 219 | // If the front buffer is still being tracked, update its slot state |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 220 | if (mCore->stillTracking(outBuffer)) { |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 221 | mSlots[slot].mAcquireCalled = true; |
| 222 | mSlots[slot].mNeedsCleanupOnRelease = false; |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 223 | // Don't decrease the queue count if the BufferItem wasn't |
| 224 | // previously in the queue. This happens in single buffer mode when |
| 225 | // the queue is empty and the BufferItem is created above. |
| 226 | if (mCore->mQueue.empty()) { |
| 227 | mSlots[slot].mBufferState.acquireNotInQueue(); |
| 228 | } else { |
| 229 | mSlots[slot].mBufferState.acquire(); |
| 230 | } |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 231 | mSlots[slot].mFence = Fence::NO_FENCE; |
| 232 | } |
| 233 | |
| 234 | // If the buffer has previously been acquired by the consumer, set |
| 235 | // mGraphicBuffer to NULL to avoid unnecessarily remapping this buffer |
| 236 | // on the consumer side |
| 237 | if (outBuffer->mAcquireCalled) { |
| 238 | outBuffer->mGraphicBuffer = NULL; |
| 239 | } |
| 240 | |
| 241 | mCore->mQueue.erase(front); |
| 242 | |
| 243 | // We might have freed a slot while dropping old buffers, or the producer |
| 244 | // may be blocked waiting for the number of buffers in the queue to |
| 245 | // decrease. |
| 246 | mCore->mDequeueCondition.broadcast(); |
| 247 | |
| 248 | ATRACE_INT(mCore->mConsumerName.string(), mCore->mQueue.size()); |
| 249 | |
| 250 | mCore->validateConsistencyLocked(); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Lajos Molnar | 5f920c1 | 2015-07-13 16:04:24 -0700 | [diff] [blame] | 253 | if (listener != NULL) { |
| 254 | for (int i = 0; i < numDroppedBuffers; ++i) { |
| 255 | listener->onBufferReleased(); |
| 256 | } |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 259 | return NO_ERROR; |
| 260 | } |
| 261 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 262 | status_t BufferQueueConsumer::detachBuffer(int slot) { |
| 263 | ATRACE_CALL(); |
| 264 | ATRACE_BUFFER_INDEX(slot); |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 265 | BQ_LOGV("detachBuffer: slot %d", slot); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 266 | Mutex::Autolock lock(mCore->mMutex); |
| 267 | |
| 268 | if (mCore->mIsAbandoned) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 269 | BQ_LOGE("detachBuffer: BufferQueue has been abandoned"); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 270 | return NO_INIT; |
| 271 | } |
| 272 | |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 273 | if (mCore->mSingleBufferMode) { |
| 274 | BQ_LOGE("detachBuffer: detachBuffer not allowed in single buffer" |
| 275 | "mode"); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 276 | return BAD_VALUE; |
| 277 | } |
| 278 | |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 279 | if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) { |
| 280 | BQ_LOGE("detachBuffer: slot index %d out of range [0, %d)", |
| 281 | slot, BufferQueueDefs::NUM_BUFFER_SLOTS); |
| 282 | return BAD_VALUE; |
| 283 | } else if (!mSlots[slot].mBufferState.isAcquired()) { |
| 284 | BQ_LOGE("detachBuffer: slot %d is not owned by the consumer " |
| 285 | "(state = %s)", slot, mSlots[slot].mBufferState.string()); |
| 286 | return BAD_VALUE; |
| 287 | } |
| 288 | |
| 289 | mSlots[slot].mBufferState.detachConsumer(); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 290 | mCore->freeBufferLocked(slot); |
| 291 | mCore->mDequeueCondition.broadcast(); |
Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 292 | mCore->validateConsistencyLocked(); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 293 | |
| 294 | return NO_ERROR; |
| 295 | } |
| 296 | |
| 297 | status_t BufferQueueConsumer::attachBuffer(int* outSlot, |
| 298 | const sp<android::GraphicBuffer>& buffer) { |
| 299 | ATRACE_CALL(); |
| 300 | |
| 301 | if (outSlot == NULL) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 302 | BQ_LOGE("attachBuffer: outSlot must not be NULL"); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 303 | return BAD_VALUE; |
| 304 | } else if (buffer == NULL) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 305 | BQ_LOGE("attachBuffer: cannot attach NULL buffer"); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 306 | return BAD_VALUE; |
| 307 | } |
| 308 | |
| 309 | Mutex::Autolock lock(mCore->mMutex); |
| 310 | |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 311 | if (mCore->mSingleBufferMode) { |
| 312 | BQ_LOGE("attachBuffer: cannot attach a buffer in single buffer" |
| 313 | "mode"); |
| 314 | return BAD_VALUE; |
| 315 | } |
| 316 | |
Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 317 | // Make sure we don't have too many acquired buffers |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 318 | int numAcquiredBuffers = 0; |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 319 | for (int s = 0; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 320 | if (mSlots[s].mBufferState.isAcquired()) { |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 321 | ++numAcquiredBuffers; |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| 325 | if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 326 | BQ_LOGE("attachBuffer: max acquired buffer count reached: %d " |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 327 | "(max %d)", numAcquiredBuffers, |
| 328 | mCore->mMaxAcquiredBufferCount); |
| 329 | return INVALID_OPERATION; |
| 330 | } |
Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 331 | |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 332 | if (buffer->getGenerationNumber() != mCore->mGenerationNumber) { |
| 333 | BQ_LOGE("attachBuffer: generation number mismatch [buffer %u] " |
| 334 | "[queue %u]", buffer->getGenerationNumber(), |
| 335 | mCore->mGenerationNumber); |
| 336 | return BAD_VALUE; |
| 337 | } |
| 338 | |
Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 339 | // Find a free slot to put the buffer into |
| 340 | int found = BufferQueueCore::INVALID_BUFFER_SLOT; |
| 341 | if (!mCore->mFreeSlots.empty()) { |
| 342 | auto slot = mCore->mFreeSlots.begin(); |
| 343 | found = *slot; |
| 344 | mCore->mFreeSlots.erase(slot); |
| 345 | } else if (!mCore->mFreeBuffers.empty()) { |
| 346 | found = mCore->mFreeBuffers.front(); |
| 347 | mCore->mFreeBuffers.remove(found); |
| 348 | } |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 349 | if (found == BufferQueueCore::INVALID_BUFFER_SLOT) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 350 | BQ_LOGE("attachBuffer: could not find free buffer slot"); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 351 | return NO_MEMORY; |
| 352 | } |
| 353 | |
| 354 | *outSlot = found; |
| 355 | ATRACE_BUFFER_INDEX(*outSlot); |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 356 | BQ_LOGV("attachBuffer: returning slot %d", *outSlot); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 357 | |
| 358 | mSlots[*outSlot].mGraphicBuffer = buffer; |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 359 | mSlots[*outSlot].mBufferState.attachConsumer(); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 360 | mSlots[*outSlot].mAttachedByConsumer = true; |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 361 | mSlots[*outSlot].mNeedsCleanupOnRelease = false; |
| 362 | mSlots[*outSlot].mFence = Fence::NO_FENCE; |
| 363 | mSlots[*outSlot].mFrameNumber = 0; |
| 364 | |
Dan Stoza | 99b18b4 | 2014-03-28 15:34:33 -0700 | [diff] [blame] | 365 | // mAcquireCalled tells BufferQueue that it doesn't need to send a valid |
| 366 | // GraphicBuffer pointer on the next acquireBuffer call, which decreases |
| 367 | // Binder traffic by not un/flattening the GraphicBuffer. However, it |
| 368 | // requires that the consumer maintain a cached copy of the slot <--> buffer |
| 369 | // mappings, which is why the consumer doesn't need the valid pointer on |
| 370 | // acquire. |
| 371 | // |
| 372 | // The StreamSplitter is one of the primary users of the attach/detach |
| 373 | // logic, and while it is running, all buffers it acquires are immediately |
| 374 | // detached, and all buffers it eventually releases are ones that were |
| 375 | // attached (as opposed to having been obtained from acquireBuffer), so it |
| 376 | // doesn't make sense to maintain the slot/buffer mappings, which would |
| 377 | // become invalid for every buffer during detach/attach. By setting this to |
| 378 | // false, the valid GraphicBuffer pointer will always be sent with acquire |
| 379 | // for attached buffers. |
| 380 | mSlots[*outSlot].mAcquireCalled = false; |
| 381 | |
Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 382 | mCore->validateConsistencyLocked(); |
| 383 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 384 | return NO_ERROR; |
| 385 | } |
| 386 | |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 387 | status_t BufferQueueConsumer::releaseBuffer(int slot, uint64_t frameNumber, |
| 388 | const sp<Fence>& releaseFence, EGLDisplay eglDisplay, |
| 389 | EGLSyncKHR eglFence) { |
| 390 | ATRACE_CALL(); |
| 391 | ATRACE_BUFFER_INDEX(slot); |
| 392 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 393 | if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS || |
| 394 | releaseFence == NULL) { |
Dan Stoza | 52937cd | 2015-05-01 16:42:55 -0700 | [diff] [blame] | 395 | BQ_LOGE("releaseBuffer: slot %d out of range or fence %p NULL", slot, |
| 396 | releaseFence.get()); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 397 | return BAD_VALUE; |
| 398 | } |
| 399 | |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 400 | sp<IProducerListener> listener; |
| 401 | { // Autolock scope |
| 402 | Mutex::Autolock lock(mCore->mMutex); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 403 | |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 404 | // If the frame number has changed because the buffer has been reallocated, |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 405 | // we can ignore this releaseBuffer for the old buffer. |
| 406 | // Ignore this for the shared buffer where the frame number can easily |
| 407 | // get out of sync due to the buffer being queued and acquired at the |
| 408 | // same time. |
| 409 | if (frameNumber != mSlots[slot].mFrameNumber && |
| 410 | !mSlots[slot].mBufferState.isShared()) { |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 411 | return STALE_BUFFER_SLOT; |
| 412 | } |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 413 | |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 414 | |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 415 | if (mSlots[slot].mBufferState.isAcquired()) { |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 416 | mSlots[slot].mEglDisplay = eglDisplay; |
| 417 | mSlots[slot].mEglFence = eglFence; |
| 418 | mSlots[slot].mFence = releaseFence; |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 419 | mSlots[slot].mBufferState.release(); |
| 420 | |
| 421 | // After leaving single buffer mode, the shared buffer will |
| 422 | // still be around. Mark it as no longer shared if this |
| 423 | // operation causes it to be free. |
| 424 | if (!mCore->mSingleBufferMode && |
| 425 | mSlots[slot].mBufferState.isFree()) { |
| 426 | mSlots[slot].mBufferState.mShared = false; |
| 427 | } |
| 428 | // Don't put the shared buffer on the free list. |
| 429 | if (!mSlots[slot].mBufferState.isShared()) { |
| 430 | mCore->mFreeBuffers.push_back(slot); |
| 431 | } |
| 432 | |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 433 | listener = mCore->mConnectedProducerListener; |
| 434 | BQ_LOGV("releaseBuffer: releasing slot %d", slot); |
| 435 | } else if (mSlots[slot].mNeedsCleanupOnRelease) { |
| 436 | BQ_LOGV("releaseBuffer: releasing a stale buffer slot %d " |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 437 | "(state = %s)", slot, mSlots[slot].mBufferState.string()); |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 438 | mSlots[slot].mNeedsCleanupOnRelease = false; |
| 439 | return STALE_BUFFER_SLOT; |
| 440 | } else { |
Dan Stoza | 52937cd | 2015-05-01 16:42:55 -0700 | [diff] [blame] | 441 | BQ_LOGE("releaseBuffer: attempted to release buffer slot %d " |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 442 | "but its state was %s", slot, |
| 443 | mSlots[slot].mBufferState.string()); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 444 | return BAD_VALUE; |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 445 | } |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 446 | |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 447 | mCore->mDequeueCondition.broadcast(); |
Dan Stoza | 0de7ea7 | 2015-04-23 13:20:51 -0700 | [diff] [blame] | 448 | mCore->validateConsistencyLocked(); |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 449 | } // Autolock scope |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 450 | |
Dan Stoza | d1c1036 | 2014-03-28 15:19:08 -0700 | [diff] [blame] | 451 | // Call back without lock held |
| 452 | if (listener != NULL) { |
| 453 | listener->onBufferReleased(); |
| 454 | } |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 455 | |
| 456 | return NO_ERROR; |
| 457 | } |
| 458 | |
| 459 | status_t BufferQueueConsumer::connect( |
| 460 | const sp<IConsumerListener>& consumerListener, bool controlledByApp) { |
| 461 | ATRACE_CALL(); |
| 462 | |
| 463 | if (consumerListener == NULL) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 464 | BQ_LOGE("connect: consumerListener may not be NULL"); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 465 | return BAD_VALUE; |
| 466 | } |
| 467 | |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 468 | BQ_LOGV("connect: controlledByApp=%s", |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 469 | controlledByApp ? "true" : "false"); |
| 470 | |
| 471 | Mutex::Autolock lock(mCore->mMutex); |
| 472 | |
| 473 | if (mCore->mIsAbandoned) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 474 | BQ_LOGE("connect: BufferQueue has been abandoned"); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 475 | return NO_INIT; |
| 476 | } |
| 477 | |
| 478 | mCore->mConsumerListener = consumerListener; |
| 479 | mCore->mConsumerControlledByApp = controlledByApp; |
| 480 | |
| 481 | return NO_ERROR; |
| 482 | } |
| 483 | |
| 484 | status_t BufferQueueConsumer::disconnect() { |
| 485 | ATRACE_CALL(); |
| 486 | |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 487 | BQ_LOGV("disconnect"); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 488 | |
| 489 | Mutex::Autolock lock(mCore->mMutex); |
| 490 | |
| 491 | if (mCore->mConsumerListener == NULL) { |
Pablo Ceballos | ccdfd60 | 2015-10-07 15:05:45 -0700 | [diff] [blame] | 492 | BQ_LOGE("disconnect: no consumer is connected"); |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 493 | return BAD_VALUE; |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | mCore->mIsAbandoned = true; |
| 497 | mCore->mConsumerListener = NULL; |
| 498 | mCore->mQueue.clear(); |
| 499 | mCore->freeAllBuffersLocked(); |
| 500 | mCore->mDequeueCondition.broadcast(); |
| 501 | return NO_ERROR; |
| 502 | } |
| 503 | |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 504 | status_t BufferQueueConsumer::getReleasedBuffers(uint64_t *outSlotMask) { |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 505 | ATRACE_CALL(); |
| 506 | |
| 507 | if (outSlotMask == NULL) { |
| 508 | BQ_LOGE("getReleasedBuffers: outSlotMask may not be NULL"); |
| 509 | return BAD_VALUE; |
| 510 | } |
| 511 | |
| 512 | Mutex::Autolock lock(mCore->mMutex); |
| 513 | |
| 514 | if (mCore->mIsAbandoned) { |
| 515 | BQ_LOGE("getReleasedBuffers: BufferQueue has been abandoned"); |
| 516 | return NO_INIT; |
| 517 | } |
| 518 | |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 519 | uint64_t mask = 0; |
Dan Stoza | 3e96f19 | 2014-03-03 10:16:19 -0800 | [diff] [blame] | 520 | for (int s = 0; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) { |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 521 | if (!mSlots[s].mAcquireCalled) { |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 522 | mask |= (1ULL << s); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | |
| 526 | // Remove from the mask queued buffers for which acquire has been called, |
| 527 | // since the consumer will not receive their buffer addresses and so must |
| 528 | // retain their cached information |
| 529 | BufferQueueCore::Fifo::iterator current(mCore->mQueue.begin()); |
| 530 | while (current != mCore->mQueue.end()) { |
| 531 | if (current->mAcquireCalled) { |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 532 | mask &= ~(1ULL << current->mSlot); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 533 | } |
| 534 | ++current; |
| 535 | } |
| 536 | |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 537 | BQ_LOGV("getReleasedBuffers: returning mask %#" PRIx64, mask); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 538 | *outSlotMask = mask; |
| 539 | return NO_ERROR; |
| 540 | } |
| 541 | |
| 542 | status_t BufferQueueConsumer::setDefaultBufferSize(uint32_t width, |
| 543 | uint32_t height) { |
| 544 | ATRACE_CALL(); |
| 545 | |
| 546 | if (width == 0 || height == 0) { |
| 547 | BQ_LOGV("setDefaultBufferSize: dimensions cannot be 0 (width=%u " |
| 548 | "height=%u)", width, height); |
| 549 | return BAD_VALUE; |
| 550 | } |
| 551 | |
| 552 | BQ_LOGV("setDefaultBufferSize: width=%u height=%u", width, height); |
| 553 | |
| 554 | Mutex::Autolock lock(mCore->mMutex); |
| 555 | mCore->mDefaultWidth = width; |
| 556 | mCore->mDefaultHeight = height; |
| 557 | return NO_ERROR; |
| 558 | } |
| 559 | |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 560 | status_t BufferQueueConsumer::setMaxBufferCount(int bufferCount) { |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 561 | ATRACE_CALL(); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 562 | |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 563 | if (bufferCount < 1 || bufferCount > BufferQueueDefs::NUM_BUFFER_SLOTS) { |
| 564 | BQ_LOGE("setMaxBufferCount: invalid count %d", bufferCount); |
| 565 | return BAD_VALUE; |
| 566 | } |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 567 | |
| 568 | Mutex::Autolock lock(mCore->mMutex); |
| 569 | |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 570 | if (mCore->mConnectedApi != BufferQueueCore::NO_CONNECTED_API) { |
| 571 | BQ_LOGE("setMaxBufferCount: producer is already connected"); |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 572 | return INVALID_OPERATION; |
| 573 | } |
| 574 | |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 575 | if (bufferCount < mCore->mMaxAcquiredBufferCount) { |
| 576 | BQ_LOGE("setMaxBufferCount: invalid buffer count (%d) less than" |
| 577 | "mMaxAcquiredBufferCount (%d)", bufferCount, |
| 578 | mCore->mMaxAcquiredBufferCount); |
| 579 | return BAD_VALUE; |
| 580 | } |
| 581 | |
| 582 | mCore->mMaxBufferCount = bufferCount; |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 583 | return NO_ERROR; |
| 584 | } |
| 585 | |
| 586 | status_t BufferQueueConsumer::setMaxAcquiredBufferCount( |
| 587 | int maxAcquiredBuffers) { |
| 588 | ATRACE_CALL(); |
| 589 | |
| 590 | if (maxAcquiredBuffers < 1 || |
| 591 | maxAcquiredBuffers > BufferQueueCore::MAX_MAX_ACQUIRED_BUFFERS) { |
| 592 | BQ_LOGE("setMaxAcquiredBufferCount: invalid count %d", |
| 593 | maxAcquiredBuffers); |
| 594 | return BAD_VALUE; |
| 595 | } |
| 596 | |
| 597 | Mutex::Autolock lock(mCore->mMutex); |
| 598 | |
| 599 | if (mCore->mConnectedApi != BufferQueueCore::NO_CONNECTED_API) { |
| 600 | BQ_LOGE("setMaxAcquiredBufferCount: producer is already connected"); |
| 601 | return INVALID_OPERATION; |
| 602 | } |
| 603 | |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 604 | if ((maxAcquiredBuffers + mCore->mMaxDequeuedBufferCount + |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 605 | (mCore->mAsyncMode || mCore->mDequeueBufferCannotBlock ? 1 : 0)) > |
| 606 | mCore->mMaxBufferCount) { |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 607 | BQ_LOGE("setMaxAcquiredBufferCount: %d acquired buffers would exceed " |
| 608 | "the maxBufferCount (%d) (maxDequeued %d async %d)", |
| 609 | maxAcquiredBuffers, mCore->mMaxBufferCount, |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 610 | mCore->mMaxDequeuedBufferCount, mCore->mAsyncMode || |
| 611 | mCore->mDequeueBufferCannotBlock); |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 612 | return BAD_VALUE; |
| 613 | } |
| 614 | |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 615 | BQ_LOGV("setMaxAcquiredBufferCount: %d", maxAcquiredBuffers); |
| 616 | mCore->mMaxAcquiredBufferCount = maxAcquiredBuffers; |
| 617 | return NO_ERROR; |
| 618 | } |
| 619 | |
| 620 | void BufferQueueConsumer::setConsumerName(const String8& name) { |
| 621 | ATRACE_CALL(); |
| 622 | BQ_LOGV("setConsumerName: '%s'", name.string()); |
| 623 | Mutex::Autolock lock(mCore->mMutex); |
| 624 | mCore->mConsumerName = name; |
| 625 | mConsumerName = name; |
| 626 | } |
| 627 | |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 628 | status_t BufferQueueConsumer::setDefaultBufferFormat(PixelFormat defaultFormat) { |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 629 | ATRACE_CALL(); |
| 630 | BQ_LOGV("setDefaultBufferFormat: %u", defaultFormat); |
| 631 | Mutex::Autolock lock(mCore->mMutex); |
| 632 | mCore->mDefaultBufferFormat = defaultFormat; |
| 633 | return NO_ERROR; |
| 634 | } |
| 635 | |
Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 636 | status_t BufferQueueConsumer::setDefaultBufferDataSpace( |
| 637 | android_dataspace defaultDataSpace) { |
| 638 | ATRACE_CALL(); |
| 639 | BQ_LOGV("setDefaultBufferDataSpace: %u", defaultDataSpace); |
| 640 | Mutex::Autolock lock(mCore->mMutex); |
| 641 | mCore->mDefaultBufferDataSpace = defaultDataSpace; |
| 642 | return NO_ERROR; |
| 643 | } |
| 644 | |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 645 | status_t BufferQueueConsumer::setConsumerUsageBits(uint32_t usage) { |
| 646 | ATRACE_CALL(); |
| 647 | BQ_LOGV("setConsumerUsageBits: %#x", usage); |
| 648 | Mutex::Autolock lock(mCore->mMutex); |
| 649 | mCore->mConsumerUsageBits = usage; |
| 650 | return NO_ERROR; |
| 651 | } |
| 652 | |
| 653 | status_t BufferQueueConsumer::setTransformHint(uint32_t hint) { |
| 654 | ATRACE_CALL(); |
| 655 | BQ_LOGV("setTransformHint: %#x", hint); |
| 656 | Mutex::Autolock lock(mCore->mMutex); |
| 657 | mCore->mTransformHint = hint; |
| 658 | return NO_ERROR; |
| 659 | } |
| 660 | |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 661 | sp<NativeHandle> BufferQueueConsumer::getSidebandStream() const { |
| 662 | return mCore->mSidebandStream; |
| 663 | } |
| 664 | |
Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 665 | void BufferQueueConsumer::dump(String8& result, const char* prefix) const { |
| 666 | mCore->dump(result, prefix); |
| 667 | } |
| 668 | |
| 669 | } // namespace android |