blob: 336ddb667d68024b8a38206e7b84a324d1e89a60 [file] [log] [blame]
Dan Stoza289ade12014-02-28 11:17:17 -08001/*
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 Salyzyn8f515ce2014-06-09 14:32:04 -070017#include <inttypes.h>
18
Dan Stoza3e96f192014-03-03 10:16:19 -080019#define LOG_TAG "BufferQueueConsumer"
20#define ATRACE_TAG ATRACE_TAG_GRAPHICS
21//#define LOG_NDEBUG 0
22
Dan Stoza289ade12014-02-28 11:17:17 -080023#include <gui/BufferItem.h>
24#include <gui/BufferQueueConsumer.h>
25#include <gui/BufferQueueCore.h>
26#include <gui/IConsumerListener.h>
Dan Stozad1c10362014-03-28 15:19:08 -070027#include <gui/IProducerListener.h>
Dan Stoza289ade12014-02-28 11:17:17 -080028
29namespace android {
30
31BufferQueueConsumer::BufferQueueConsumer(const sp<BufferQueueCore>& core) :
32 mCore(core),
33 mSlots(core->mSlots),
34 mConsumerName() {}
35
36BufferQueueConsumer::~BufferQueueConsumer() {}
37
38status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer,
39 nsecs_t expectedPresent) {
40 ATRACE_CALL();
41 Mutex::Autolock lock(mCore->mMutex);
42
43 // Check that the consumer doesn't currently have the maximum number of
44 // buffers acquired. We allow the max buffer count to be exceeded by one
45 // buffer so that the consumer can successfully set up the newly acquired
46 // buffer before releasing the old one.
47 int numAcquiredBuffers = 0;
Dan Stoza3e96f192014-03-03 10:16:19 -080048 for (int s = 0; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) {
Dan Stoza289ade12014-02-28 11:17:17 -080049 if (mSlots[s].mBufferState == BufferSlot::ACQUIRED) {
50 ++numAcquiredBuffers;
51 }
52 }
53 if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1) {
54 BQ_LOGE("acquireBuffer: max acquired buffer count reached: %d (max %d)",
55 numAcquiredBuffers, mCore->mMaxAcquiredBufferCount);
56 return INVALID_OPERATION;
57 }
58
59 // Check if the queue is empty.
60 // In asynchronous mode the list is guaranteed to be one buffer deep,
61 // while in synchronous mode we use the oldest buffer.
62 if (mCore->mQueue.empty()) {
63 return NO_BUFFER_AVAILABLE;
64 }
65
66 BufferQueueCore::Fifo::iterator front(mCore->mQueue.begin());
67
68 // If expectedPresent is specified, we may not want to return a buffer yet.
69 // If it's specified and there's more than one buffer queued, we may want
70 // to drop a buffer.
71 if (expectedPresent != 0) {
72 const int MAX_REASONABLE_NSEC = 1000000000ULL; // 1 second
73
74 // The 'expectedPresent' argument indicates when the buffer is expected
75 // to be presented on-screen. If the buffer's desired present time is
76 // earlier (less) than expectedPresent -- meaning it will be displayed
77 // on time or possibly late if we show it as soon as possible -- we
78 // acquire and return it. If we don't want to display it until after the
79 // expectedPresent time, we return PRESENT_LATER without acquiring it.
80 //
81 // To be safe, we don't defer acquisition if expectedPresent is more
82 // than one second in the future beyond the desired present time
83 // (i.e., we'd be holding the buffer for a long time).
84 //
85 // NOTE: Code assumes monotonic time values from the system clock
86 // are positive.
87
88 // Start by checking to see if we can drop frames. We skip this check if
89 // the timestamps are being auto-generated by Surface. If the app isn't
90 // generating timestamps explicitly, it probably doesn't want frames to
91 // be discarded based on them.
Dan Stozaecc50402015-04-28 14:42:06 -070092 //
93 // If the consumer is shadowing our queue, we also make sure that we
94 // don't drop so many buffers that the consumer hasn't received the
95 // onFrameAvailable callback for the buffer it acquires. That is, we
96 // want the buffer we return to be in the consumer's shadow queue.
97 size_t droppableBuffers = mCore->mConsumerShadowQueueSize > 1 ?
98 mCore->mConsumerShadowQueueSize - 1 : 0;
Dan Stoza289ade12014-02-28 11:17:17 -080099 while (mCore->mQueue.size() > 1 && !mCore->mQueue[0].mIsAutoTimestamp) {
Dan Stozaecc50402015-04-28 14:42:06 -0700100 if (mCore->mConsumerHasShadowQueue && droppableBuffers == 0) {
101 BQ_LOGV("acquireBuffer: no droppable buffers in consumer's"
102 " shadow queue, continuing");
103 break;
104 }
105
Dan Stoza289ade12014-02-28 11:17:17 -0800106 // If entry[1] is timely, drop entry[0] (and repeat). We apply an
107 // additional criterion here: we only drop the earlier buffer if our
108 // desiredPresent falls within +/- 1 second of the expected present.
109 // Otherwise, bogus desiredPresent times (e.g., 0 or a small
110 // relative timestamp), which normally mean "ignore the timestamp
111 // and acquire immediately", would cause us to drop frames.
112 //
113 // We may want to add an additional criterion: don't drop the
114 // earlier buffer if entry[1]'s fence hasn't signaled yet.
115 const BufferItem& bufferItem(mCore->mQueue[1]);
116 nsecs_t desiredPresent = bufferItem.mTimestamp;
117 if (desiredPresent < expectedPresent - MAX_REASONABLE_NSEC ||
118 desiredPresent > expectedPresent) {
119 // This buffer is set to display in the near future, or
120 // desiredPresent is garbage. Either way we don't want to drop
121 // the previous buffer just to get this on the screen sooner.
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700122 BQ_LOGV("acquireBuffer: nodrop desire=%" PRId64 " expect=%"
123 PRId64 " (%" PRId64 ") now=%" PRId64,
124 desiredPresent, expectedPresent,
Dan Stoza289ade12014-02-28 11:17:17 -0800125 desiredPresent - expectedPresent,
126 systemTime(CLOCK_MONOTONIC));
127 break;
128 }
129
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700130 BQ_LOGV("acquireBuffer: drop desire=%" PRId64 " expect=%" PRId64
131 " size=%zu",
Dan Stoza289ade12014-02-28 11:17:17 -0800132 desiredPresent, expectedPresent, mCore->mQueue.size());
133 if (mCore->stillTracking(front)) {
134 // Front buffer is still in mSlots, so mark the slot as free
135 mSlots[front->mSlot].mBufferState = BufferSlot::FREE;
Dan Stoza0de7ea72015-04-23 13:20:51 -0700136 mCore->mFreeBuffers.push_back(front->mSlot);
Dan Stoza289ade12014-02-28 11:17:17 -0800137 }
138 mCore->mQueue.erase(front);
139 front = mCore->mQueue.begin();
Dan Stozaecc50402015-04-28 14:42:06 -0700140 --droppableBuffers;
Dan Stoza289ade12014-02-28 11:17:17 -0800141 }
142
143 // See if the front buffer is due
144 nsecs_t desiredPresent = front->mTimestamp;
145 if (desiredPresent > expectedPresent &&
146 desiredPresent < expectedPresent + MAX_REASONABLE_NSEC) {
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700147 BQ_LOGV("acquireBuffer: defer desire=%" PRId64 " expect=%" PRId64
148 " (%" PRId64 ") now=%" PRId64,
149 desiredPresent, expectedPresent,
Dan Stoza289ade12014-02-28 11:17:17 -0800150 desiredPresent - expectedPresent,
151 systemTime(CLOCK_MONOTONIC));
152 return PRESENT_LATER;
153 }
154
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700155 BQ_LOGV("acquireBuffer: accept desire=%" PRId64 " expect=%" PRId64 " "
156 "(%" PRId64 ") now=%" PRId64, desiredPresent, expectedPresent,
Dan Stoza289ade12014-02-28 11:17:17 -0800157 desiredPresent - expectedPresent,
158 systemTime(CLOCK_MONOTONIC));
159 }
160
161 int slot = front->mSlot;
162 *outBuffer = *front;
163 ATRACE_BUFFER_INDEX(slot);
164
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700165 BQ_LOGV("acquireBuffer: acquiring { slot=%d/%" PRIu64 " buffer=%p }",
Dan Stoza289ade12014-02-28 11:17:17 -0800166 slot, front->mFrameNumber, front->mGraphicBuffer->handle);
167 // If the front buffer is still being tracked, update its slot state
168 if (mCore->stillTracking(front)) {
169 mSlots[slot].mAcquireCalled = true;
170 mSlots[slot].mNeedsCleanupOnRelease = false;
171 mSlots[slot].mBufferState = BufferSlot::ACQUIRED;
172 mSlots[slot].mFence = Fence::NO_FENCE;
173 }
174
175 // If the buffer has previously been acquired by the consumer, set
176 // mGraphicBuffer to NULL to avoid unnecessarily remapping this buffer
177 // on the consumer side
178 if (outBuffer->mAcquireCalled) {
179 outBuffer->mGraphicBuffer = NULL;
180 }
181
182 mCore->mQueue.erase(front);
Dan Stozaae3c3682014-04-18 15:43:35 -0700183
184 // We might have freed a slot while dropping old buffers, or the producer
185 // may be blocked waiting for the number of buffers in the queue to
186 // decrease.
Dan Stoza289ade12014-02-28 11:17:17 -0800187 mCore->mDequeueCondition.broadcast();
188
189 ATRACE_INT(mCore->mConsumerName.string(), mCore->mQueue.size());
190
Dan Stoza0de7ea72015-04-23 13:20:51 -0700191 mCore->validateConsistencyLocked();
192
Dan Stoza289ade12014-02-28 11:17:17 -0800193 return NO_ERROR;
194}
195
Dan Stoza9f3053d2014-03-06 15:14:33 -0800196status_t BufferQueueConsumer::detachBuffer(int slot) {
197 ATRACE_CALL();
198 ATRACE_BUFFER_INDEX(slot);
199 BQ_LOGV("detachBuffer(C): slot %d", slot);
200 Mutex::Autolock lock(mCore->mMutex);
201
202 if (mCore->mIsAbandoned) {
203 BQ_LOGE("detachBuffer(C): BufferQueue has been abandoned");
204 return NO_INIT;
205 }
206
207 if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) {
208 BQ_LOGE("detachBuffer(C): slot index %d out of range [0, %d)",
209 slot, BufferQueueDefs::NUM_BUFFER_SLOTS);
210 return BAD_VALUE;
211 } else if (mSlots[slot].mBufferState != BufferSlot::ACQUIRED) {
212 BQ_LOGE("detachBuffer(C): slot %d is not owned by the consumer "
213 "(state = %d)", slot, mSlots[slot].mBufferState);
214 return BAD_VALUE;
215 }
216
217 mCore->freeBufferLocked(slot);
218 mCore->mDequeueCondition.broadcast();
Dan Stoza0de7ea72015-04-23 13:20:51 -0700219 mCore->validateConsistencyLocked();
Dan Stoza9f3053d2014-03-06 15:14:33 -0800220
221 return NO_ERROR;
222}
223
224status_t BufferQueueConsumer::attachBuffer(int* outSlot,
225 const sp<android::GraphicBuffer>& buffer) {
226 ATRACE_CALL();
227
228 if (outSlot == NULL) {
229 BQ_LOGE("attachBuffer(P): outSlot must not be NULL");
230 return BAD_VALUE;
231 } else if (buffer == NULL) {
232 BQ_LOGE("attachBuffer(P): cannot attach NULL buffer");
233 return BAD_VALUE;
234 }
235
236 Mutex::Autolock lock(mCore->mMutex);
237
Dan Stoza0de7ea72015-04-23 13:20:51 -0700238 // Make sure we don't have too many acquired buffers
Dan Stoza9f3053d2014-03-06 15:14:33 -0800239 int numAcquiredBuffers = 0;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800240 for (int s = 0; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) {
241 if (mSlots[s].mBufferState == BufferSlot::ACQUIRED) {
242 ++numAcquiredBuffers;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800243 }
244 }
245
246 if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1) {
247 BQ_LOGE("attachBuffer(P): max acquired buffer count reached: %d "
248 "(max %d)", numAcquiredBuffers,
249 mCore->mMaxAcquiredBufferCount);
250 return INVALID_OPERATION;
251 }
Dan Stoza0de7ea72015-04-23 13:20:51 -0700252
253 // Find a free slot to put the buffer into
254 int found = BufferQueueCore::INVALID_BUFFER_SLOT;
255 if (!mCore->mFreeSlots.empty()) {
256 auto slot = mCore->mFreeSlots.begin();
257 found = *slot;
258 mCore->mFreeSlots.erase(slot);
259 } else if (!mCore->mFreeBuffers.empty()) {
260 found = mCore->mFreeBuffers.front();
261 mCore->mFreeBuffers.remove(found);
262 }
Dan Stoza9f3053d2014-03-06 15:14:33 -0800263 if (found == BufferQueueCore::INVALID_BUFFER_SLOT) {
264 BQ_LOGE("attachBuffer(P): could not find free buffer slot");
265 return NO_MEMORY;
266 }
267
268 *outSlot = found;
269 ATRACE_BUFFER_INDEX(*outSlot);
270 BQ_LOGV("attachBuffer(C): returning slot %d", *outSlot);
271
272 mSlots[*outSlot].mGraphicBuffer = buffer;
273 mSlots[*outSlot].mBufferState = BufferSlot::ACQUIRED;
274 mSlots[*outSlot].mAttachedByConsumer = true;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800275 mSlots[*outSlot].mNeedsCleanupOnRelease = false;
276 mSlots[*outSlot].mFence = Fence::NO_FENCE;
277 mSlots[*outSlot].mFrameNumber = 0;
278
Dan Stoza99b18b42014-03-28 15:34:33 -0700279 // mAcquireCalled tells BufferQueue that it doesn't need to send a valid
280 // GraphicBuffer pointer on the next acquireBuffer call, which decreases
281 // Binder traffic by not un/flattening the GraphicBuffer. However, it
282 // requires that the consumer maintain a cached copy of the slot <--> buffer
283 // mappings, which is why the consumer doesn't need the valid pointer on
284 // acquire.
285 //
286 // The StreamSplitter is one of the primary users of the attach/detach
287 // logic, and while it is running, all buffers it acquires are immediately
288 // detached, and all buffers it eventually releases are ones that were
289 // attached (as opposed to having been obtained from acquireBuffer), so it
290 // doesn't make sense to maintain the slot/buffer mappings, which would
291 // become invalid for every buffer during detach/attach. By setting this to
292 // false, the valid GraphicBuffer pointer will always be sent with acquire
293 // for attached buffers.
294 mSlots[*outSlot].mAcquireCalled = false;
295
Dan Stoza0de7ea72015-04-23 13:20:51 -0700296 mCore->validateConsistencyLocked();
297
Dan Stoza9f3053d2014-03-06 15:14:33 -0800298 return NO_ERROR;
299}
300
Dan Stoza289ade12014-02-28 11:17:17 -0800301status_t BufferQueueConsumer::releaseBuffer(int slot, uint64_t frameNumber,
302 const sp<Fence>& releaseFence, EGLDisplay eglDisplay,
303 EGLSyncKHR eglFence) {
304 ATRACE_CALL();
305 ATRACE_BUFFER_INDEX(slot);
306
Dan Stoza9f3053d2014-03-06 15:14:33 -0800307 if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS ||
308 releaseFence == NULL) {
Dan Stoza52937cd2015-05-01 16:42:55 -0700309 BQ_LOGE("releaseBuffer: slot %d out of range or fence %p NULL", slot,
310 releaseFence.get());
Dan Stoza289ade12014-02-28 11:17:17 -0800311 return BAD_VALUE;
312 }
313
Dan Stozad1c10362014-03-28 15:19:08 -0700314 sp<IProducerListener> listener;
315 { // Autolock scope
316 Mutex::Autolock lock(mCore->mMutex);
Dan Stoza289ade12014-02-28 11:17:17 -0800317
Dan Stozad1c10362014-03-28 15:19:08 -0700318 // If the frame number has changed because the buffer has been reallocated,
319 // we can ignore this releaseBuffer for the old buffer
320 if (frameNumber != mSlots[slot].mFrameNumber) {
321 return STALE_BUFFER_SLOT;
322 }
Dan Stoza289ade12014-02-28 11:17:17 -0800323
Dan Stozad1c10362014-03-28 15:19:08 -0700324 // Make sure this buffer hasn't been queued while acquired by the consumer
325 BufferQueueCore::Fifo::iterator current(mCore->mQueue.begin());
326 while (current != mCore->mQueue.end()) {
327 if (current->mSlot == slot) {
328 BQ_LOGE("releaseBuffer: buffer slot %d pending release is "
329 "currently queued", slot);
330 return BAD_VALUE;
331 }
332 ++current;
333 }
334
335 if (mSlots[slot].mBufferState == BufferSlot::ACQUIRED) {
336 mSlots[slot].mEglDisplay = eglDisplay;
337 mSlots[slot].mEglFence = eglFence;
338 mSlots[slot].mFence = releaseFence;
339 mSlots[slot].mBufferState = BufferSlot::FREE;
Dan Stoza0de7ea72015-04-23 13:20:51 -0700340 mCore->mFreeBuffers.push_back(slot);
Dan Stozad1c10362014-03-28 15:19:08 -0700341 listener = mCore->mConnectedProducerListener;
342 BQ_LOGV("releaseBuffer: releasing slot %d", slot);
343 } else if (mSlots[slot].mNeedsCleanupOnRelease) {
344 BQ_LOGV("releaseBuffer: releasing a stale buffer slot %d "
345 "(state = %d)", slot, mSlots[slot].mBufferState);
346 mSlots[slot].mNeedsCleanupOnRelease = false;
347 return STALE_BUFFER_SLOT;
348 } else {
Dan Stoza52937cd2015-05-01 16:42:55 -0700349 BQ_LOGE("releaseBuffer: attempted to release buffer slot %d "
Dan Stozad1c10362014-03-28 15:19:08 -0700350 "but its state was %d", slot, mSlots[slot].mBufferState);
Dan Stoza9f3053d2014-03-06 15:14:33 -0800351 return BAD_VALUE;
Dan Stoza289ade12014-02-28 11:17:17 -0800352 }
Dan Stoza289ade12014-02-28 11:17:17 -0800353
Dan Stozad1c10362014-03-28 15:19:08 -0700354 mCore->mDequeueCondition.broadcast();
Dan Stoza0de7ea72015-04-23 13:20:51 -0700355 mCore->validateConsistencyLocked();
Dan Stozad1c10362014-03-28 15:19:08 -0700356 } // Autolock scope
Dan Stoza289ade12014-02-28 11:17:17 -0800357
Dan Stozad1c10362014-03-28 15:19:08 -0700358 // Call back without lock held
359 if (listener != NULL) {
360 listener->onBufferReleased();
361 }
Dan Stoza289ade12014-02-28 11:17:17 -0800362
363 return NO_ERROR;
364}
365
366status_t BufferQueueConsumer::connect(
367 const sp<IConsumerListener>& consumerListener, bool controlledByApp) {
368 ATRACE_CALL();
369
370 if (consumerListener == NULL) {
371 BQ_LOGE("connect(C): consumerListener may not be NULL");
372 return BAD_VALUE;
373 }
374
375 BQ_LOGV("connect(C): controlledByApp=%s",
376 controlledByApp ? "true" : "false");
377
378 Mutex::Autolock lock(mCore->mMutex);
379
380 if (mCore->mIsAbandoned) {
381 BQ_LOGE("connect(C): BufferQueue has been abandoned");
382 return NO_INIT;
383 }
384
385 mCore->mConsumerListener = consumerListener;
386 mCore->mConsumerControlledByApp = controlledByApp;
387
388 return NO_ERROR;
389}
390
391status_t BufferQueueConsumer::disconnect() {
392 ATRACE_CALL();
393
394 BQ_LOGV("disconnect(C)");
395
396 Mutex::Autolock lock(mCore->mMutex);
397
398 if (mCore->mConsumerListener == NULL) {
399 BQ_LOGE("disconnect(C): no consumer is connected");
Dan Stoza9f3053d2014-03-06 15:14:33 -0800400 return BAD_VALUE;
Dan Stoza289ade12014-02-28 11:17:17 -0800401 }
402
403 mCore->mIsAbandoned = true;
404 mCore->mConsumerListener = NULL;
405 mCore->mQueue.clear();
406 mCore->freeAllBuffersLocked();
407 mCore->mDequeueCondition.broadcast();
408 return NO_ERROR;
409}
410
Dan Stozafebd4f42014-04-09 16:14:51 -0700411status_t BufferQueueConsumer::getReleasedBuffers(uint64_t *outSlotMask) {
Dan Stoza289ade12014-02-28 11:17:17 -0800412 ATRACE_CALL();
413
414 if (outSlotMask == NULL) {
415 BQ_LOGE("getReleasedBuffers: outSlotMask may not be NULL");
416 return BAD_VALUE;
417 }
418
419 Mutex::Autolock lock(mCore->mMutex);
420
421 if (mCore->mIsAbandoned) {
422 BQ_LOGE("getReleasedBuffers: BufferQueue has been abandoned");
423 return NO_INIT;
424 }
425
Dan Stozafebd4f42014-04-09 16:14:51 -0700426 uint64_t mask = 0;
Dan Stoza3e96f192014-03-03 10:16:19 -0800427 for (int s = 0; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) {
Dan Stoza289ade12014-02-28 11:17:17 -0800428 if (!mSlots[s].mAcquireCalled) {
Dan Stozafebd4f42014-04-09 16:14:51 -0700429 mask |= (1ULL << s);
Dan Stoza289ade12014-02-28 11:17:17 -0800430 }
431 }
432
433 // Remove from the mask queued buffers for which acquire has been called,
434 // since the consumer will not receive their buffer addresses and so must
435 // retain their cached information
436 BufferQueueCore::Fifo::iterator current(mCore->mQueue.begin());
437 while (current != mCore->mQueue.end()) {
438 if (current->mAcquireCalled) {
Dan Stozafebd4f42014-04-09 16:14:51 -0700439 mask &= ~(1ULL << current->mSlot);
Dan Stoza289ade12014-02-28 11:17:17 -0800440 }
441 ++current;
442 }
443
Dan Stozafebd4f42014-04-09 16:14:51 -0700444 BQ_LOGV("getReleasedBuffers: returning mask %#" PRIx64, mask);
Dan Stoza289ade12014-02-28 11:17:17 -0800445 *outSlotMask = mask;
446 return NO_ERROR;
447}
448
449status_t BufferQueueConsumer::setDefaultBufferSize(uint32_t width,
450 uint32_t height) {
451 ATRACE_CALL();
452
453 if (width == 0 || height == 0) {
454 BQ_LOGV("setDefaultBufferSize: dimensions cannot be 0 (width=%u "
455 "height=%u)", width, height);
456 return BAD_VALUE;
457 }
458
459 BQ_LOGV("setDefaultBufferSize: width=%u height=%u", width, height);
460
461 Mutex::Autolock lock(mCore->mMutex);
462 mCore->mDefaultWidth = width;
463 mCore->mDefaultHeight = height;
464 return NO_ERROR;
465}
466
467status_t BufferQueueConsumer::setDefaultMaxBufferCount(int bufferCount) {
468 ATRACE_CALL();
469 Mutex::Autolock lock(mCore->mMutex);
470 return mCore->setDefaultMaxBufferCountLocked(bufferCount);
471}
472
473status_t BufferQueueConsumer::disableAsyncBuffer() {
474 ATRACE_CALL();
475
476 Mutex::Autolock lock(mCore->mMutex);
477
478 if (mCore->mConsumerListener != NULL) {
479 BQ_LOGE("disableAsyncBuffer: consumer already connected");
480 return INVALID_OPERATION;
481 }
482
483 BQ_LOGV("disableAsyncBuffer");
484 mCore->mUseAsyncBuffer = false;
485 return NO_ERROR;
486}
487
488status_t BufferQueueConsumer::setMaxAcquiredBufferCount(
489 int maxAcquiredBuffers) {
490 ATRACE_CALL();
491
492 if (maxAcquiredBuffers < 1 ||
493 maxAcquiredBuffers > BufferQueueCore::MAX_MAX_ACQUIRED_BUFFERS) {
494 BQ_LOGE("setMaxAcquiredBufferCount: invalid count %d",
495 maxAcquiredBuffers);
496 return BAD_VALUE;
497 }
498
499 Mutex::Autolock lock(mCore->mMutex);
500
501 if (mCore->mConnectedApi != BufferQueueCore::NO_CONNECTED_API) {
502 BQ_LOGE("setMaxAcquiredBufferCount: producer is already connected");
503 return INVALID_OPERATION;
504 }
505
506 BQ_LOGV("setMaxAcquiredBufferCount: %d", maxAcquiredBuffers);
507 mCore->mMaxAcquiredBufferCount = maxAcquiredBuffers;
508 return NO_ERROR;
509}
510
511void BufferQueueConsumer::setConsumerName(const String8& name) {
512 ATRACE_CALL();
513 BQ_LOGV("setConsumerName: '%s'", name.string());
514 Mutex::Autolock lock(mCore->mMutex);
515 mCore->mConsumerName = name;
516 mConsumerName = name;
517}
518
Dan Stoza3be1c6b2014-11-18 10:24:03 -0800519status_t BufferQueueConsumer::setDefaultBufferFormat(PixelFormat defaultFormat) {
Dan Stoza289ade12014-02-28 11:17:17 -0800520 ATRACE_CALL();
521 BQ_LOGV("setDefaultBufferFormat: %u", defaultFormat);
522 Mutex::Autolock lock(mCore->mMutex);
523 mCore->mDefaultBufferFormat = defaultFormat;
524 return NO_ERROR;
525}
526
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -0800527status_t BufferQueueConsumer::setDefaultBufferDataSpace(
528 android_dataspace defaultDataSpace) {
529 ATRACE_CALL();
530 BQ_LOGV("setDefaultBufferDataSpace: %u", defaultDataSpace);
531 Mutex::Autolock lock(mCore->mMutex);
532 mCore->mDefaultBufferDataSpace = defaultDataSpace;
533 return NO_ERROR;
534}
535
Dan Stoza289ade12014-02-28 11:17:17 -0800536status_t BufferQueueConsumer::setConsumerUsageBits(uint32_t usage) {
537 ATRACE_CALL();
538 BQ_LOGV("setConsumerUsageBits: %#x", usage);
539 Mutex::Autolock lock(mCore->mMutex);
540 mCore->mConsumerUsageBits = usage;
541 return NO_ERROR;
542}
543
544status_t BufferQueueConsumer::setTransformHint(uint32_t hint) {
545 ATRACE_CALL();
546 BQ_LOGV("setTransformHint: %#x", hint);
547 Mutex::Autolock lock(mCore->mMutex);
548 mCore->mTransformHint = hint;
549 return NO_ERROR;
550}
551
Jesse Hall399184a2014-03-03 15:42:54 -0800552sp<NativeHandle> BufferQueueConsumer::getSidebandStream() const {
553 return mCore->mSidebandStream;
554}
555
Dan Stozaecc50402015-04-28 14:42:06 -0700556void BufferQueueConsumer::setShadowQueueSize(size_t size) {
557 ATRACE_CALL();
558 BQ_LOGV("setShadowQueueSize: %zu", size);
559 Mutex::Autolock lock(mCore->mMutex);
560 mCore->mConsumerHasShadowQueue = true;
561 mCore->mConsumerShadowQueueSize = size;
562}
563
Dan Stoza289ade12014-02-28 11:17:17 -0800564void BufferQueueConsumer::dump(String8& result, const char* prefix) const {
565 mCore->dump(result, prefix);
566}
567
568} // namespace android