blob: 1f84750c508a88c0bef93236594c3f430cbb99c0 [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
Pablo Ceballos88f69282016-02-11 18:01:49 -080029#include <binder/IPCThreadState.h>
30#include <binder/PermissionCache.h>
31#include <private/android_filesystem_config.h>
32
Dan Stoza289ade12014-02-28 11:17:17 -080033namespace android {
34
35BufferQueueConsumer::BufferQueueConsumer(const sp<BufferQueueCore>& core) :
36 mCore(core),
37 mSlots(core->mSlots),
38 mConsumerName() {}
39
40BufferQueueConsumer::~BufferQueueConsumer() {}
41
42status_t BufferQueueConsumer::acquireBuffer(BufferItem* outBuffer,
43 nsecs_t expectedPresent) {
44 ATRACE_CALL();
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;
Dan Stoza3e96f192014-03-03 10:16:19 -080052 for (int s = 0; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) {
Dan Stoza289ade12014-02-28 11:17:17 -080053 if (mSlots[s].mBufferState == BufferSlot::ACQUIRED) {
54 ++numAcquiredBuffers;
55 }
56 }
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 }
62
63 // Check if the queue is empty.
64 // In asynchronous mode the list is guaranteed to be one buffer deep,
65 // while in synchronous mode we use the oldest buffer.
66 if (mCore->mQueue.empty()) {
67 return NO_BUFFER_AVAILABLE;
68 }
69
70 BufferQueueCore::Fifo::iterator front(mCore->mQueue.begin());
71
72 // If expectedPresent is specified, we may not want to return a buffer yet.
73 // If it's specified and there's more than one buffer queued, we may want
74 // to drop a buffer.
75 if (expectedPresent != 0) {
76 const int MAX_REASONABLE_NSEC = 1000000000ULL; // 1 second
77
78 // The 'expectedPresent' argument indicates when the buffer is expected
79 // to be presented on-screen. If the buffer's desired present time is
80 // earlier (less) than expectedPresent -- meaning it will be displayed
81 // on time or possibly late if we show it as soon as possible -- we
82 // acquire and return it. If we don't want to display it until after the
83 // expectedPresent time, we return PRESENT_LATER without acquiring it.
84 //
85 // To be safe, we don't defer acquisition if expectedPresent is more
86 // than one second in the future beyond the desired present time
87 // (i.e., we'd be holding the buffer for a long time).
88 //
89 // NOTE: Code assumes monotonic time values from the system clock
90 // are positive.
91
92 // Start by checking to see if we can drop frames. We skip this check if
93 // the timestamps are being auto-generated by Surface. If the app isn't
94 // generating timestamps explicitly, it probably doesn't want frames to
95 // be discarded based on them.
96 while (mCore->mQueue.size() > 1 && !mCore->mQueue[0].mIsAutoTimestamp) {
97 // If entry[1] is timely, drop entry[0] (and repeat). We apply an
98 // additional criterion here: we only drop the earlier buffer if our
99 // desiredPresent falls within +/- 1 second of the expected present.
100 // Otherwise, bogus desiredPresent times (e.g., 0 or a small
101 // relative timestamp), which normally mean "ignore the timestamp
102 // and acquire immediately", would cause us to drop frames.
103 //
104 // We may want to add an additional criterion: don't drop the
105 // earlier buffer if entry[1]'s fence hasn't signaled yet.
106 const BufferItem& bufferItem(mCore->mQueue[1]);
107 nsecs_t desiredPresent = bufferItem.mTimestamp;
108 if (desiredPresent < expectedPresent - MAX_REASONABLE_NSEC ||
109 desiredPresent > expectedPresent) {
110 // This buffer is set to display in the near future, or
111 // desiredPresent is garbage. Either way we don't want to drop
112 // the previous buffer just to get this on the screen sooner.
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700113 BQ_LOGV("acquireBuffer: nodrop desire=%" PRId64 " expect=%"
114 PRId64 " (%" PRId64 ") now=%" PRId64,
115 desiredPresent, expectedPresent,
Dan Stoza289ade12014-02-28 11:17:17 -0800116 desiredPresent - expectedPresent,
117 systemTime(CLOCK_MONOTONIC));
118 break;
119 }
120
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700121 BQ_LOGV("acquireBuffer: drop desire=%" PRId64 " expect=%" PRId64
122 " size=%zu",
Dan Stoza289ade12014-02-28 11:17:17 -0800123 desiredPresent, expectedPresent, mCore->mQueue.size());
124 if (mCore->stillTracking(front)) {
125 // Front buffer is still in mSlots, so mark the slot as free
126 mSlots[front->mSlot].mBufferState = BufferSlot::FREE;
127 }
128 mCore->mQueue.erase(front);
129 front = mCore->mQueue.begin();
130 }
131
132 // See if the front buffer is due
133 nsecs_t desiredPresent = front->mTimestamp;
134 if (desiredPresent > expectedPresent &&
135 desiredPresent < expectedPresent + MAX_REASONABLE_NSEC) {
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700136 BQ_LOGV("acquireBuffer: defer desire=%" PRId64 " expect=%" PRId64
137 " (%" PRId64 ") now=%" PRId64,
138 desiredPresent, expectedPresent,
Dan Stoza289ade12014-02-28 11:17:17 -0800139 desiredPresent - expectedPresent,
140 systemTime(CLOCK_MONOTONIC));
141 return PRESENT_LATER;
142 }
143
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700144 BQ_LOGV("acquireBuffer: accept desire=%" PRId64 " expect=%" PRId64 " "
145 "(%" PRId64 ") now=%" PRId64, desiredPresent, expectedPresent,
Dan Stoza289ade12014-02-28 11:17:17 -0800146 desiredPresent - expectedPresent,
147 systemTime(CLOCK_MONOTONIC));
148 }
149
150 int slot = front->mSlot;
151 *outBuffer = *front;
152 ATRACE_BUFFER_INDEX(slot);
153
Mark Salyzyn8f515ce2014-06-09 14:32:04 -0700154 BQ_LOGV("acquireBuffer: acquiring { slot=%d/%" PRIu64 " buffer=%p }",
Dan Stoza289ade12014-02-28 11:17:17 -0800155 slot, front->mFrameNumber, front->mGraphicBuffer->handle);
156 // If the front buffer is still being tracked, update its slot state
157 if (mCore->stillTracking(front)) {
158 mSlots[slot].mAcquireCalled = true;
159 mSlots[slot].mNeedsCleanupOnRelease = false;
160 mSlots[slot].mBufferState = BufferSlot::ACQUIRED;
161 mSlots[slot].mFence = Fence::NO_FENCE;
162 }
163
164 // If the buffer has previously been acquired by the consumer, set
165 // mGraphicBuffer to NULL to avoid unnecessarily remapping this buffer
166 // on the consumer side
167 if (outBuffer->mAcquireCalled) {
168 outBuffer->mGraphicBuffer = NULL;
169 }
170
171 mCore->mQueue.erase(front);
Dan Stozaae3c3682014-04-18 15:43:35 -0700172
173 // We might have freed a slot while dropping old buffers, or the producer
174 // may be blocked waiting for the number of buffers in the queue to
175 // decrease.
Dan Stoza289ade12014-02-28 11:17:17 -0800176 mCore->mDequeueCondition.broadcast();
177
178 ATRACE_INT(mCore->mConsumerName.string(), mCore->mQueue.size());
179
180 return NO_ERROR;
181}
182
Dan Stoza9f3053d2014-03-06 15:14:33 -0800183status_t BufferQueueConsumer::detachBuffer(int slot) {
184 ATRACE_CALL();
185 ATRACE_BUFFER_INDEX(slot);
186 BQ_LOGV("detachBuffer(C): slot %d", slot);
187 Mutex::Autolock lock(mCore->mMutex);
188
189 if (mCore->mIsAbandoned) {
190 BQ_LOGE("detachBuffer(C): BufferQueue has been abandoned");
191 return NO_INIT;
192 }
193
194 if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS) {
195 BQ_LOGE("detachBuffer(C): slot index %d out of range [0, %d)",
196 slot, BufferQueueDefs::NUM_BUFFER_SLOTS);
197 return BAD_VALUE;
198 } else if (mSlots[slot].mBufferState != BufferSlot::ACQUIRED) {
199 BQ_LOGE("detachBuffer(C): slot %d is not owned by the consumer "
200 "(state = %d)", slot, mSlots[slot].mBufferState);
201 return BAD_VALUE;
202 }
203
204 mCore->freeBufferLocked(slot);
205 mCore->mDequeueCondition.broadcast();
206
207 return NO_ERROR;
208}
209
210status_t BufferQueueConsumer::attachBuffer(int* outSlot,
211 const sp<android::GraphicBuffer>& buffer) {
212 ATRACE_CALL();
213
214 if (outSlot == NULL) {
215 BQ_LOGE("attachBuffer(P): outSlot must not be NULL");
216 return BAD_VALUE;
217 } else if (buffer == NULL) {
218 BQ_LOGE("attachBuffer(P): cannot attach NULL buffer");
219 return BAD_VALUE;
220 }
221
222 Mutex::Autolock lock(mCore->mMutex);
223
224 // Make sure we don't have too many acquired buffers and find a free slot
225 // to put the buffer into (the oldest if there are multiple).
226 int numAcquiredBuffers = 0;
227 int found = BufferQueueCore::INVALID_BUFFER_SLOT;
228 for (int s = 0; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) {
229 if (mSlots[s].mBufferState == BufferSlot::ACQUIRED) {
230 ++numAcquiredBuffers;
231 } else if (mSlots[s].mBufferState == BufferSlot::FREE) {
232 if (found == BufferQueueCore::INVALID_BUFFER_SLOT ||
233 mSlots[s].mFrameNumber < mSlots[found].mFrameNumber) {
234 found = s;
235 }
236 }
237 }
238
239 if (numAcquiredBuffers >= mCore->mMaxAcquiredBufferCount + 1) {
240 BQ_LOGE("attachBuffer(P): max acquired buffer count reached: %d "
241 "(max %d)", numAcquiredBuffers,
242 mCore->mMaxAcquiredBufferCount);
243 return INVALID_OPERATION;
244 }
245 if (found == BufferQueueCore::INVALID_BUFFER_SLOT) {
246 BQ_LOGE("attachBuffer(P): could not find free buffer slot");
247 return NO_MEMORY;
248 }
249
250 *outSlot = found;
251 ATRACE_BUFFER_INDEX(*outSlot);
252 BQ_LOGV("attachBuffer(C): returning slot %d", *outSlot);
253
254 mSlots[*outSlot].mGraphicBuffer = buffer;
255 mSlots[*outSlot].mBufferState = BufferSlot::ACQUIRED;
256 mSlots[*outSlot].mAttachedByConsumer = true;
Dan Stoza9f3053d2014-03-06 15:14:33 -0800257 mSlots[*outSlot].mNeedsCleanupOnRelease = false;
258 mSlots[*outSlot].mFence = Fence::NO_FENCE;
259 mSlots[*outSlot].mFrameNumber = 0;
260
Dan Stoza99b18b42014-03-28 15:34:33 -0700261 // mAcquireCalled tells BufferQueue that it doesn't need to send a valid
262 // GraphicBuffer pointer on the next acquireBuffer call, which decreases
263 // Binder traffic by not un/flattening the GraphicBuffer. However, it
264 // requires that the consumer maintain a cached copy of the slot <--> buffer
265 // mappings, which is why the consumer doesn't need the valid pointer on
266 // acquire.
267 //
268 // The StreamSplitter is one of the primary users of the attach/detach
269 // logic, and while it is running, all buffers it acquires are immediately
270 // detached, and all buffers it eventually releases are ones that were
271 // attached (as opposed to having been obtained from acquireBuffer), so it
272 // doesn't make sense to maintain the slot/buffer mappings, which would
273 // become invalid for every buffer during detach/attach. By setting this to
274 // false, the valid GraphicBuffer pointer will always be sent with acquire
275 // for attached buffers.
276 mSlots[*outSlot].mAcquireCalled = false;
277
Dan Stoza9f3053d2014-03-06 15:14:33 -0800278 return NO_ERROR;
279}
280
Dan Stoza289ade12014-02-28 11:17:17 -0800281status_t BufferQueueConsumer::releaseBuffer(int slot, uint64_t frameNumber,
282 const sp<Fence>& releaseFence, EGLDisplay eglDisplay,
283 EGLSyncKHR eglFence) {
284 ATRACE_CALL();
285 ATRACE_BUFFER_INDEX(slot);
286
Dan Stoza9f3053d2014-03-06 15:14:33 -0800287 if (slot < 0 || slot >= BufferQueueDefs::NUM_BUFFER_SLOTS ||
288 releaseFence == NULL) {
Dan Stoza289ade12014-02-28 11:17:17 -0800289 return BAD_VALUE;
290 }
291
Dan Stozad1c10362014-03-28 15:19:08 -0700292 sp<IProducerListener> listener;
293 { // Autolock scope
294 Mutex::Autolock lock(mCore->mMutex);
Dan Stoza289ade12014-02-28 11:17:17 -0800295
Dan Stozad1c10362014-03-28 15:19:08 -0700296 // If the frame number has changed because the buffer has been reallocated,
297 // we can ignore this releaseBuffer for the old buffer
298 if (frameNumber != mSlots[slot].mFrameNumber) {
299 return STALE_BUFFER_SLOT;
300 }
Dan Stoza289ade12014-02-28 11:17:17 -0800301
Dan Stozad1c10362014-03-28 15:19:08 -0700302 // Make sure this buffer hasn't been queued while acquired by the consumer
303 BufferQueueCore::Fifo::iterator current(mCore->mQueue.begin());
304 while (current != mCore->mQueue.end()) {
305 if (current->mSlot == slot) {
306 BQ_LOGE("releaseBuffer: buffer slot %d pending release is "
307 "currently queued", slot);
308 return BAD_VALUE;
309 }
310 ++current;
311 }
312
313 if (mSlots[slot].mBufferState == BufferSlot::ACQUIRED) {
314 mSlots[slot].mEglDisplay = eglDisplay;
315 mSlots[slot].mEglFence = eglFence;
316 mSlots[slot].mFence = releaseFence;
317 mSlots[slot].mBufferState = BufferSlot::FREE;
318 listener = mCore->mConnectedProducerListener;
319 BQ_LOGV("releaseBuffer: releasing slot %d", slot);
320 } else if (mSlots[slot].mNeedsCleanupOnRelease) {
321 BQ_LOGV("releaseBuffer: releasing a stale buffer slot %d "
322 "(state = %d)", slot, mSlots[slot].mBufferState);
323 mSlots[slot].mNeedsCleanupOnRelease = false;
324 return STALE_BUFFER_SLOT;
325 } else {
326 BQ_LOGV("releaseBuffer: attempted to release buffer slot %d "
327 "but its state was %d", slot, mSlots[slot].mBufferState);
Dan Stoza9f3053d2014-03-06 15:14:33 -0800328 return BAD_VALUE;
Dan Stoza289ade12014-02-28 11:17:17 -0800329 }
Dan Stoza289ade12014-02-28 11:17:17 -0800330
Dan Stozad1c10362014-03-28 15:19:08 -0700331 mCore->mDequeueCondition.broadcast();
332 } // Autolock scope
Dan Stoza289ade12014-02-28 11:17:17 -0800333
Dan Stozad1c10362014-03-28 15:19:08 -0700334 // Call back without lock held
335 if (listener != NULL) {
336 listener->onBufferReleased();
337 }
Dan Stoza289ade12014-02-28 11:17:17 -0800338
339 return NO_ERROR;
340}
341
342status_t BufferQueueConsumer::connect(
343 const sp<IConsumerListener>& consumerListener, bool controlledByApp) {
344 ATRACE_CALL();
345
346 if (consumerListener == NULL) {
347 BQ_LOGE("connect(C): consumerListener may not be NULL");
348 return BAD_VALUE;
349 }
350
351 BQ_LOGV("connect(C): controlledByApp=%s",
352 controlledByApp ? "true" : "false");
353
354 Mutex::Autolock lock(mCore->mMutex);
355
356 if (mCore->mIsAbandoned) {
357 BQ_LOGE("connect(C): BufferQueue has been abandoned");
358 return NO_INIT;
359 }
360
361 mCore->mConsumerListener = consumerListener;
362 mCore->mConsumerControlledByApp = controlledByApp;
363
364 return NO_ERROR;
365}
366
367status_t BufferQueueConsumer::disconnect() {
368 ATRACE_CALL();
369
370 BQ_LOGV("disconnect(C)");
371
372 Mutex::Autolock lock(mCore->mMutex);
373
374 if (mCore->mConsumerListener == NULL) {
375 BQ_LOGE("disconnect(C): no consumer is connected");
Dan Stoza9f3053d2014-03-06 15:14:33 -0800376 return BAD_VALUE;
Dan Stoza289ade12014-02-28 11:17:17 -0800377 }
378
379 mCore->mIsAbandoned = true;
380 mCore->mConsumerListener = NULL;
381 mCore->mQueue.clear();
382 mCore->freeAllBuffersLocked();
383 mCore->mDequeueCondition.broadcast();
384 return NO_ERROR;
385}
386
Dan Stozafebd4f42014-04-09 16:14:51 -0700387status_t BufferQueueConsumer::getReleasedBuffers(uint64_t *outSlotMask) {
Dan Stoza289ade12014-02-28 11:17:17 -0800388 ATRACE_CALL();
389
390 if (outSlotMask == NULL) {
391 BQ_LOGE("getReleasedBuffers: outSlotMask may not be NULL");
392 return BAD_VALUE;
393 }
394
395 Mutex::Autolock lock(mCore->mMutex);
396
397 if (mCore->mIsAbandoned) {
398 BQ_LOGE("getReleasedBuffers: BufferQueue has been abandoned");
399 return NO_INIT;
400 }
401
Dan Stozafebd4f42014-04-09 16:14:51 -0700402 uint64_t mask = 0;
Dan Stoza3e96f192014-03-03 10:16:19 -0800403 for (int s = 0; s < BufferQueueDefs::NUM_BUFFER_SLOTS; ++s) {
Dan Stoza289ade12014-02-28 11:17:17 -0800404 if (!mSlots[s].mAcquireCalled) {
Dan Stozafebd4f42014-04-09 16:14:51 -0700405 mask |= (1ULL << s);
Dan Stoza289ade12014-02-28 11:17:17 -0800406 }
407 }
408
409 // Remove from the mask queued buffers for which acquire has been called,
410 // since the consumer will not receive their buffer addresses and so must
411 // retain their cached information
412 BufferQueueCore::Fifo::iterator current(mCore->mQueue.begin());
413 while (current != mCore->mQueue.end()) {
414 if (current->mAcquireCalled) {
Dan Stozafebd4f42014-04-09 16:14:51 -0700415 mask &= ~(1ULL << current->mSlot);
Dan Stoza289ade12014-02-28 11:17:17 -0800416 }
417 ++current;
418 }
419
Dan Stozafebd4f42014-04-09 16:14:51 -0700420 BQ_LOGV("getReleasedBuffers: returning mask %#" PRIx64, mask);
Dan Stoza289ade12014-02-28 11:17:17 -0800421 *outSlotMask = mask;
422 return NO_ERROR;
423}
424
425status_t BufferQueueConsumer::setDefaultBufferSize(uint32_t width,
426 uint32_t height) {
427 ATRACE_CALL();
428
429 if (width == 0 || height == 0) {
430 BQ_LOGV("setDefaultBufferSize: dimensions cannot be 0 (width=%u "
431 "height=%u)", width, height);
432 return BAD_VALUE;
433 }
434
435 BQ_LOGV("setDefaultBufferSize: width=%u height=%u", width, height);
436
437 Mutex::Autolock lock(mCore->mMutex);
438 mCore->mDefaultWidth = width;
439 mCore->mDefaultHeight = height;
440 return NO_ERROR;
441}
442
443status_t BufferQueueConsumer::setDefaultMaxBufferCount(int bufferCount) {
444 ATRACE_CALL();
445 Mutex::Autolock lock(mCore->mMutex);
446 return mCore->setDefaultMaxBufferCountLocked(bufferCount);
447}
448
449status_t BufferQueueConsumer::disableAsyncBuffer() {
450 ATRACE_CALL();
451
452 Mutex::Autolock lock(mCore->mMutex);
453
454 if (mCore->mConsumerListener != NULL) {
455 BQ_LOGE("disableAsyncBuffer: consumer already connected");
456 return INVALID_OPERATION;
457 }
458
459 BQ_LOGV("disableAsyncBuffer");
460 mCore->mUseAsyncBuffer = false;
461 return NO_ERROR;
462}
463
464status_t BufferQueueConsumer::setMaxAcquiredBufferCount(
465 int maxAcquiredBuffers) {
466 ATRACE_CALL();
467
468 if (maxAcquiredBuffers < 1 ||
469 maxAcquiredBuffers > BufferQueueCore::MAX_MAX_ACQUIRED_BUFFERS) {
470 BQ_LOGE("setMaxAcquiredBufferCount: invalid count %d",
471 maxAcquiredBuffers);
472 return BAD_VALUE;
473 }
474
475 Mutex::Autolock lock(mCore->mMutex);
476
477 if (mCore->mConnectedApi != BufferQueueCore::NO_CONNECTED_API) {
478 BQ_LOGE("setMaxAcquiredBufferCount: producer is already connected");
479 return INVALID_OPERATION;
480 }
481
482 BQ_LOGV("setMaxAcquiredBufferCount: %d", maxAcquiredBuffers);
483 mCore->mMaxAcquiredBufferCount = maxAcquiredBuffers;
484 return NO_ERROR;
485}
486
487void BufferQueueConsumer::setConsumerName(const String8& name) {
488 ATRACE_CALL();
489 BQ_LOGV("setConsumerName: '%s'", name.string());
490 Mutex::Autolock lock(mCore->mMutex);
491 mCore->mConsumerName = name;
492 mConsumerName = name;
493}
494
495status_t BufferQueueConsumer::setDefaultBufferFormat(uint32_t defaultFormat) {
496 ATRACE_CALL();
497 BQ_LOGV("setDefaultBufferFormat: %u", defaultFormat);
498 Mutex::Autolock lock(mCore->mMutex);
499 mCore->mDefaultBufferFormat = defaultFormat;
500 return NO_ERROR;
501}
502
503status_t BufferQueueConsumer::setConsumerUsageBits(uint32_t usage) {
504 ATRACE_CALL();
505 BQ_LOGV("setConsumerUsageBits: %#x", usage);
506 Mutex::Autolock lock(mCore->mMutex);
507 mCore->mConsumerUsageBits = usage;
508 return NO_ERROR;
509}
510
511status_t BufferQueueConsumer::setTransformHint(uint32_t hint) {
512 ATRACE_CALL();
513 BQ_LOGV("setTransformHint: %#x", hint);
514 Mutex::Autolock lock(mCore->mMutex);
515 mCore->mTransformHint = hint;
516 return NO_ERROR;
517}
518
Jesse Hall399184a2014-03-03 15:42:54 -0800519sp<NativeHandle> BufferQueueConsumer::getSidebandStream() const {
520 return mCore->mSidebandStream;
521}
522
Dan Stoza289ade12014-02-28 11:17:17 -0800523void BufferQueueConsumer::dump(String8& result, const char* prefix) const {
Pablo Ceballos88f69282016-02-11 18:01:49 -0800524 const IPCThreadState* ipc = IPCThreadState::self();
525 const pid_t pid = ipc->getCallingPid();
526 const uid_t uid = ipc->getCallingUid();
527 if ((uid != AID_SHELL)
528 && !PermissionCache::checkPermission(String16(
529 "android.permission.DUMP"), pid, uid)) {
530 result.appendFormat("Permission Denial: can't dump BufferQueueConsumer "
531 "from pid=%d, uid=%d\n", pid, uid);
532 } else {
533 mCore->dump(result, prefix);
534 }
Dan Stoza289ade12014-02-28 11:17:17 -0800535}
536
537} // namespace android