blob: 8263e4e7104b5fc0083ba138b17731c8e0916e58 [file] [log] [blame]
Daniel Lam6b091c52012-01-22 15:26:27 -08001/*
2 * Copyright (C) 2012 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#define LOG_TAG "BufferQueue"
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080018#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Jamie Gennisfa5b40e2012-03-15 14:01:24 -070019//#define LOG_NDEBUG 0
Daniel Lam6b091c52012-01-22 15:26:27 -080020
21#define GL_GLEXT_PROTOTYPES
22#define EGL_EGLEXT_PROTOTYPES
23
24#include <EGL/egl.h>
25#include <EGL/eglext.h>
26
27#include <gui/BufferQueue.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080028#include <gui/ISurfaceComposer.h>
Daniel Lam6b091c52012-01-22 15:26:27 -080029#include <private/gui/ComposerService.h>
Daniel Lam6b091c52012-01-22 15:26:27 -080030
31#include <utils/Log.h>
Daniel Lameae59d22012-01-22 15:26:27 -080032#include <gui/SurfaceTexture.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080033#include <utils/Trace.h>
Daniel Lam6b091c52012-01-22 15:26:27 -080034
35// This compile option causes SurfaceTexture to return the buffer that is currently
36// attached to the GL texture from dequeueBuffer when no other buffers are
37// available. It requires the drivers (Gralloc, GL, OMX IL, and Camera) to do
38// implicit cross-process synchronization to prevent the buffer from being
39// written to before the buffer has (a) been detached from the GL texture and
40// (b) all GL reads from the buffer have completed.
Daniel Lameae59d22012-01-22 15:26:27 -080041
42// During refactoring, do not support dequeuing the current buffer
43#undef ALLOW_DEQUEUE_CURRENT_BUFFER
44
Daniel Lam6b091c52012-01-22 15:26:27 -080045#ifdef ALLOW_DEQUEUE_CURRENT_BUFFER
46#define FLAG_ALLOW_DEQUEUE_CURRENT_BUFFER true
47#warning "ALLOW_DEQUEUE_CURRENT_BUFFER enabled"
48#else
49#define FLAG_ALLOW_DEQUEUE_CURRENT_BUFFER false
50#endif
51
52// Macros for including the BufferQueue name in log messages
Daniel Lameae59d22012-01-22 15:26:27 -080053#define ST_LOGV(x, ...) ALOGV("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
54#define ST_LOGD(x, ...) ALOGD("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
55#define ST_LOGI(x, ...) ALOGI("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
56#define ST_LOGW(x, ...) ALOGW("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
57#define ST_LOGE(x, ...) ALOGE("[%s] "x, mConsumerName.string(), ##__VA_ARGS__)
Daniel Lam6b091c52012-01-22 15:26:27 -080058
Mathias Agopian546ed2d2012-03-01 22:11:25 -080059#define ATRACE_BUFFER_INDEX(index) \
60 char ___traceBuf[1024]; \
61 snprintf(___traceBuf, 1024, "%s: %d", mConsumerName.string(), (index)); \
62 android::ScopedTrace ___bufTracer(ATRACE_TAG, ___traceBuf);
63
Daniel Lam6b091c52012-01-22 15:26:27 -080064namespace android {
65
66// Get an ID that's unique within this process.
67static int32_t createProcessUniqueId() {
68 static volatile int32_t globalCounter = 0;
69 return android_atomic_inc(&globalCounter);
70}
71
Daniel Lamabe61bf2012-03-26 20:37:15 -070072BufferQueue::BufferQueue( bool allowSynchronousMode, int bufferCount ) :
Daniel Lam6b091c52012-01-22 15:26:27 -080073 mDefaultWidth(1),
74 mDefaultHeight(1),
75 mPixelFormat(PIXEL_FORMAT_RGBA_8888),
Daniel Lamabe61bf2012-03-26 20:37:15 -070076 mMinUndequeuedBuffers(bufferCount),
77 mMinAsyncBufferSlots(bufferCount + 1),
78 mMinSyncBufferSlots(bufferCount),
79 mBufferCount(mMinAsyncBufferSlots),
Daniel Lam6b091c52012-01-22 15:26:27 -080080 mClientBufferCount(0),
Daniel Lamabe61bf2012-03-26 20:37:15 -070081 mServerBufferCount(mMinAsyncBufferSlots),
Daniel Lam6b091c52012-01-22 15:26:27 -080082 mSynchronousMode(false),
83 mAllowSynchronousMode(allowSynchronousMode),
84 mConnectedApi(NO_CONNECTED_API),
85 mAbandoned(false),
Daniel Lameae59d22012-01-22 15:26:27 -080086 mFrameCounter(0),
Daniel Lamb2675792012-02-23 14:35:13 -080087 mBufferHasBeenQueued(false),
88 mDefaultBufferFormat(0),
89 mConsumerUsageBits(0),
90 mTransformHint(0)
Daniel Lam6b091c52012-01-22 15:26:27 -080091{
92 // Choose a name using the PID and a process-unique ID.
Daniel Lameae59d22012-01-22 15:26:27 -080093 mConsumerName = String8::format("unnamed-%d-%d", getpid(), createProcessUniqueId());
Daniel Lam6b091c52012-01-22 15:26:27 -080094
95 ST_LOGV("BufferQueue");
96 sp<ISurfaceComposer> composer(ComposerService::getComposerService());
97 mGraphicBufferAlloc = composer->createGraphicBufferAlloc();
Daniel Lamabe61bf2012-03-26 20:37:15 -070098 if (mGraphicBufferAlloc == 0) {
99 ST_LOGE("createGraphicBufferAlloc() failed in BufferQueue()");
100 }
Daniel Lam6b091c52012-01-22 15:26:27 -0800101}
102
103BufferQueue::~BufferQueue() {
104 ST_LOGV("~BufferQueue");
105}
106
107status_t BufferQueue::setBufferCountServerLocked(int bufferCount) {
108 if (bufferCount > NUM_BUFFER_SLOTS)
109 return BAD_VALUE;
110
111 // special-case, nothing to do
112 if (bufferCount == mBufferCount)
113 return OK;
114
115 if (!mClientBufferCount &&
116 bufferCount >= mBufferCount) {
117 // easy, we just have more buffers
118 mBufferCount = bufferCount;
119 mServerBufferCount = bufferCount;
Dave Burke74ff8c22012-03-12 21:49:41 -0700120 mDequeueCondition.broadcast();
Daniel Lam6b091c52012-01-22 15:26:27 -0800121 } else {
122 // we're here because we're either
123 // - reducing the number of available buffers
124 // - or there is a client-buffer-count in effect
125
126 // less than 2 buffers is never allowed
127 if (bufferCount < 2)
128 return BAD_VALUE;
129
130 // when there is non client-buffer-count in effect, the client is not
131 // allowed to dequeue more than one buffer at a time,
132 // so the next time they dequeue a buffer, we know that they don't
133 // own one. the actual resizing will happen during the next
134 // dequeueBuffer.
135
136 mServerBufferCount = bufferCount;
Daniel Lamb2675792012-02-23 14:35:13 -0800137 mDequeueCondition.broadcast();
Daniel Lam6b091c52012-01-22 15:26:27 -0800138 }
139 return OK;
140}
141
Daniel Lameae59d22012-01-22 15:26:27 -0800142bool BufferQueue::isSynchronousMode() const {
143 Mutex::Autolock lock(mMutex);
144 return mSynchronousMode;
145}
146
147void BufferQueue::setConsumerName(const String8& name) {
148 Mutex::Autolock lock(mMutex);
149 mConsumerName = name;
150}
151
Daniel Lamb2675792012-02-23 14:35:13 -0800152status_t BufferQueue::setDefaultBufferFormat(uint32_t defaultFormat) {
153 Mutex::Autolock lock(mMutex);
154 mDefaultBufferFormat = defaultFormat;
155 return OK;
156}
157
158status_t BufferQueue::setConsumerUsageBits(uint32_t usage) {
159 Mutex::Autolock lock(mMutex);
160 mConsumerUsageBits = usage;
161 return OK;
162}
163
164status_t BufferQueue::setTransformHint(uint32_t hint) {
165 Mutex::Autolock lock(mMutex);
166 mTransformHint = hint;
167 return OK;
168}
169
Daniel Lam6b091c52012-01-22 15:26:27 -0800170status_t BufferQueue::setBufferCount(int bufferCount) {
171 ST_LOGV("setBufferCount: count=%d", bufferCount);
Daniel Lam6b091c52012-01-22 15:26:27 -0800172
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700173 sp<ConsumerListener> listener;
174 {
175 Mutex::Autolock lock(mMutex);
Daniel Lam6b091c52012-01-22 15:26:27 -0800176
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700177 if (mAbandoned) {
178 ST_LOGE("setBufferCount: SurfaceTexture has been abandoned!");
179 return NO_INIT;
Daniel Lam6b091c52012-01-22 15:26:27 -0800180 }
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700181 if (bufferCount > NUM_BUFFER_SLOTS) {
182 ST_LOGE("setBufferCount: bufferCount larger than slots available");
183 return BAD_VALUE;
184 }
185
186 // Error out if the user has dequeued buffers
187 for (int i=0 ; i<mBufferCount ; i++) {
188 if (mSlots[i].mBufferState == BufferSlot::DEQUEUED) {
189 ST_LOGE("setBufferCount: client owns some buffers");
190 return -EINVAL;
191 }
192 }
193
194 const int minBufferSlots = mSynchronousMode ?
Daniel Lamabe61bf2012-03-26 20:37:15 -0700195 mMinSyncBufferSlots : mMinAsyncBufferSlots;
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700196 if (bufferCount == 0) {
197 mClientBufferCount = 0;
198 bufferCount = (mServerBufferCount >= minBufferSlots) ?
199 mServerBufferCount : minBufferSlots;
200 return setBufferCountServerLocked(bufferCount);
201 }
202
203 if (bufferCount < minBufferSlots) {
204 ST_LOGE("setBufferCount: requested buffer count (%d) is less than "
205 "minimum (%d)", bufferCount, minBufferSlots);
206 return BAD_VALUE;
207 }
208
209 // here we're guaranteed that the client doesn't have dequeued buffers
210 // and will release all of its buffer references.
211 freeAllBuffersLocked();
212 mBufferCount = bufferCount;
213 mClientBufferCount = bufferCount;
214 mBufferHasBeenQueued = false;
215 mQueue.clear();
216 mDequeueCondition.broadcast();
217 listener = mConsumerListener;
218 } // scope for lock
219
220 if (listener != NULL) {
221 listener->onBuffersReleased();
Daniel Lam6b091c52012-01-22 15:26:27 -0800222 }
223
Daniel Lam6b091c52012-01-22 15:26:27 -0800224 return OK;
225}
226
Daniel Lamb8560522012-01-30 15:51:27 -0800227int BufferQueue::query(int what, int* outValue)
228{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800229 ATRACE_CALL();
Daniel Lamb8560522012-01-30 15:51:27 -0800230 Mutex::Autolock lock(mMutex);
231
232 if (mAbandoned) {
233 ST_LOGE("query: SurfaceTexture has been abandoned!");
234 return NO_INIT;
235 }
236
237 int value;
238 switch (what) {
239 case NATIVE_WINDOW_WIDTH:
240 value = mDefaultWidth;
241 break;
242 case NATIVE_WINDOW_HEIGHT:
243 value = mDefaultHeight;
244 break;
245 case NATIVE_WINDOW_FORMAT:
246 value = mPixelFormat;
247 break;
248 case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS:
249 value = mSynchronousMode ?
Daniel Lamabe61bf2012-03-26 20:37:15 -0700250 (mMinUndequeuedBuffers-1) : mMinUndequeuedBuffers;
Daniel Lamb8560522012-01-30 15:51:27 -0800251 break;
252 default:
253 return BAD_VALUE;
254 }
255 outValue[0] = value;
256 return NO_ERROR;
257}
258
Daniel Lam6b091c52012-01-22 15:26:27 -0800259status_t BufferQueue::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800260 ATRACE_CALL();
Daniel Lam6b091c52012-01-22 15:26:27 -0800261 ST_LOGV("requestBuffer: slot=%d", slot);
262 Mutex::Autolock lock(mMutex);
263 if (mAbandoned) {
264 ST_LOGE("requestBuffer: SurfaceTexture has been abandoned!");
265 return NO_INIT;
266 }
267 if (slot < 0 || mBufferCount <= slot) {
268 ST_LOGE("requestBuffer: slot index out of range [0, %d]: %d",
269 mBufferCount, slot);
270 return BAD_VALUE;
271 }
272 mSlots[slot].mRequestBufferCalled = true;
273 *buf = mSlots[slot].mGraphicBuffer;
274 return NO_ERROR;
275}
276
277status_t BufferQueue::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
278 uint32_t format, uint32_t usage) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800279 ATRACE_CALL();
Daniel Lam6b091c52012-01-22 15:26:27 -0800280 ST_LOGV("dequeueBuffer: w=%d h=%d fmt=%#x usage=%#x", w, h, format, usage);
281
282 if ((w && !h) || (!w && h)) {
283 ST_LOGE("dequeueBuffer: invalid size: w=%u, h=%u", w, h);
284 return BAD_VALUE;
285 }
286
287 status_t returnFlags(OK);
288 EGLDisplay dpy = EGL_NO_DISPLAY;
289 EGLSyncKHR fence = EGL_NO_SYNC_KHR;
290
291 { // Scope for the lock
292 Mutex::Autolock lock(mMutex);
293
Daniel Lamb2675792012-02-23 14:35:13 -0800294 if (format == 0) {
295 format = mDefaultBufferFormat;
296 }
297 // turn on usage bits the consumer requested
298 usage |= mConsumerUsageBits;
299
Daniel Lam6b091c52012-01-22 15:26:27 -0800300 int found = -1;
301 int foundSync = -1;
302 int dequeuedCount = 0;
303 bool tryAgain = true;
304 while (tryAgain) {
305 if (mAbandoned) {
306 ST_LOGE("dequeueBuffer: SurfaceTexture has been abandoned!");
307 return NO_INIT;
308 }
309
310 // We need to wait for the FIFO to drain if the number of buffer
311 // needs to change.
312 //
313 // The condition "number of buffers needs to change" is true if
314 // - the client doesn't care about how many buffers there are
315 // - AND the actual number of buffer is different from what was
316 // set in the last setBufferCountServer()
317 // - OR -
318 // setBufferCountServer() was set to a value incompatible with
319 // the synchronization mode (for instance because the sync mode
320 // changed since)
321 //
322 // As long as this condition is true AND the FIFO is not empty, we
323 // wait on mDequeueCondition.
324
325 const int minBufferCountNeeded = mSynchronousMode ?
Daniel Lamabe61bf2012-03-26 20:37:15 -0700326 mMinSyncBufferSlots : mMinAsyncBufferSlots;
Daniel Lam6b091c52012-01-22 15:26:27 -0800327
328 const bool numberOfBuffersNeedsToChange = !mClientBufferCount &&
329 ((mServerBufferCount != mBufferCount) ||
330 (mServerBufferCount < minBufferCountNeeded));
331
332 if (!mQueue.isEmpty() && numberOfBuffersNeedsToChange) {
333 // wait for the FIFO to drain
334 mDequeueCondition.wait(mMutex);
335 // NOTE: we continue here because we need to reevaluate our
336 // whole state (eg: we could be abandoned or disconnected)
337 continue;
338 }
339
340 if (numberOfBuffersNeedsToChange) {
341 // here we're guaranteed that mQueue is empty
342 freeAllBuffersLocked();
343 mBufferCount = mServerBufferCount;
344 if (mBufferCount < minBufferCountNeeded)
345 mBufferCount = minBufferCountNeeded;
Daniel Lameae59d22012-01-22 15:26:27 -0800346 mBufferHasBeenQueued = false;
Daniel Lam6b091c52012-01-22 15:26:27 -0800347 returnFlags |= ISurfaceTexture::RELEASE_ALL_BUFFERS;
348 }
349
350 // look for a free buffer to give to the client
351 found = INVALID_BUFFER_SLOT;
352 foundSync = INVALID_BUFFER_SLOT;
353 dequeuedCount = 0;
354 for (int i = 0; i < mBufferCount; i++) {
355 const int state = mSlots[i].mBufferState;
356 if (state == BufferSlot::DEQUEUED) {
357 dequeuedCount++;
358 }
359
Daniel Lameae59d22012-01-22 15:26:27 -0800360 // this logic used to be if (FLAG_ALLOW_DEQUEUE_CURRENT_BUFFER)
361 // but dequeuing the current buffer is disabled.
362 if (false) {
363 // This functionality has been temporarily removed so
364 // BufferQueue and SurfaceTexture can be refactored into
365 // separate objects
Daniel Lam6b091c52012-01-22 15:26:27 -0800366 } else {
367 if (state == BufferSlot::FREE) {
368 /* We return the oldest of the free buffers to avoid
369 * stalling the producer if possible. This is because
370 * the consumer may still have pending reads of the
371 * buffers in flight.
372 */
373 bool isOlder = mSlots[i].mFrameNumber <
374 mSlots[found].mFrameNumber;
375 if (found < 0 || isOlder) {
376 foundSync = i;
377 found = i;
378 }
379 }
380 }
381 }
382
383 // clients are not allowed to dequeue more than one buffer
384 // if they didn't set a buffer count.
385 if (!mClientBufferCount && dequeuedCount) {
386 ST_LOGE("dequeueBuffer: can't dequeue multiple buffers without "
387 "setting the buffer count");
388 return -EINVAL;
389 }
390
391 // See whether a buffer has been queued since the last
392 // setBufferCount so we know whether to perform the
Daniel Lamabe61bf2012-03-26 20:37:15 -0700393 // mMinUndequeuedBuffers check below.
Daniel Lameae59d22012-01-22 15:26:27 -0800394 if (mBufferHasBeenQueued) {
Daniel Lam6b091c52012-01-22 15:26:27 -0800395 // make sure the client is not trying to dequeue more buffers
396 // than allowed.
397 const int avail = mBufferCount - (dequeuedCount+1);
Daniel Lamabe61bf2012-03-26 20:37:15 -0700398 if (avail < (mMinUndequeuedBuffers-int(mSynchronousMode))) {
399 ST_LOGE("dequeueBuffer: mMinUndequeuedBuffers=%d exceeded "
Daniel Lam6b091c52012-01-22 15:26:27 -0800400 "(dequeued=%d)",
Daniel Lamabe61bf2012-03-26 20:37:15 -0700401 mMinUndequeuedBuffers-int(mSynchronousMode),
Daniel Lam6b091c52012-01-22 15:26:27 -0800402 dequeuedCount);
403 return -EBUSY;
404 }
405 }
406
Daniel Lamc2c1f2f2012-03-07 14:11:29 -0800407 // if no buffer is found, wait for a buffer to be released
408 tryAgain = found == INVALID_BUFFER_SLOT;
Daniel Lam6b091c52012-01-22 15:26:27 -0800409 if (tryAgain) {
410 mDequeueCondition.wait(mMutex);
411 }
412 }
413
Daniel Lam6b091c52012-01-22 15:26:27 -0800414
415 if (found == INVALID_BUFFER_SLOT) {
416 // This should not happen.
417 ST_LOGE("dequeueBuffer: no available buffer slots");
418 return -EBUSY;
419 }
420
421 const int buf = found;
422 *outBuf = found;
423
Mathias Agopian546ed2d2012-03-01 22:11:25 -0800424 ATRACE_BUFFER_INDEX(buf);
425
Daniel Lam6b091c52012-01-22 15:26:27 -0800426 const bool useDefaultSize = !w && !h;
427 if (useDefaultSize) {
428 // use the default size
429 w = mDefaultWidth;
430 h = mDefaultHeight;
431 }
432
433 const bool updateFormat = (format != 0);
434 if (!updateFormat) {
435 // keep the current (or default) format
436 format = mPixelFormat;
437 }
438
439 // buffer is now in DEQUEUED (but can also be current at the same time,
440 // if we're in synchronous mode)
441 mSlots[buf].mBufferState = BufferSlot::DEQUEUED;
442
443 const sp<GraphicBuffer>& buffer(mSlots[buf].mGraphicBuffer);
444 if ((buffer == NULL) ||
445 (uint32_t(buffer->width) != w) ||
446 (uint32_t(buffer->height) != h) ||
447 (uint32_t(buffer->format) != format) ||
448 ((uint32_t(buffer->usage) & usage) != usage))
449 {
450 usage |= GraphicBuffer::USAGE_HW_TEXTURE;
451 status_t error;
452 sp<GraphicBuffer> graphicBuffer(
453 mGraphicBufferAlloc->createGraphicBuffer(
454 w, h, format, usage, &error));
455 if (graphicBuffer == 0) {
456 ST_LOGE("dequeueBuffer: SurfaceComposer::createGraphicBuffer "
457 "failed");
458 return error;
459 }
460 if (updateFormat) {
461 mPixelFormat = format;
462 }
Daniel Lameae59d22012-01-22 15:26:27 -0800463
464 mSlots[buf].mAcquireCalled = false;
Daniel Lam6b091c52012-01-22 15:26:27 -0800465 mSlots[buf].mGraphicBuffer = graphicBuffer;
466 mSlots[buf].mRequestBufferCalled = false;
467 mSlots[buf].mFence = EGL_NO_SYNC_KHR;
Daniel Lameae59d22012-01-22 15:26:27 -0800468 mSlots[buf].mEglDisplay = EGL_NO_DISPLAY;
469
Daniel Lam6b091c52012-01-22 15:26:27 -0800470 returnFlags |= ISurfaceTexture::BUFFER_NEEDS_REALLOCATION;
471 }
472
473 dpy = mSlots[buf].mEglDisplay;
474 fence = mSlots[buf].mFence;
475 mSlots[buf].mFence = EGL_NO_SYNC_KHR;
Daniel Lameae59d22012-01-22 15:26:27 -0800476 } // end lock scope
Daniel Lam6b091c52012-01-22 15:26:27 -0800477
478 if (fence != EGL_NO_SYNC_KHR) {
479 EGLint result = eglClientWaitSyncKHR(dpy, fence, 0, 1000000000);
480 // If something goes wrong, log the error, but return the buffer without
481 // synchronizing access to it. It's too late at this point to abort the
482 // dequeue operation.
483 if (result == EGL_FALSE) {
484 ALOGE("dequeueBuffer: error waiting for fence: %#x", eglGetError());
485 } else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
486 ALOGE("dequeueBuffer: timeout waiting for fence");
487 }
488 eglDestroySyncKHR(dpy, fence);
489 }
490
491 ST_LOGV("dequeueBuffer: returning slot=%d buf=%p flags=%#x", *outBuf,
492 mSlots[*outBuf].mGraphicBuffer->handle, returnFlags);
493
494 return returnFlags;
495}
496
497status_t BufferQueue::setSynchronousMode(bool enabled) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800498 ATRACE_CALL();
Daniel Lam6b091c52012-01-22 15:26:27 -0800499 ST_LOGV("setSynchronousMode: enabled=%d", enabled);
500 Mutex::Autolock lock(mMutex);
501
502 if (mAbandoned) {
503 ST_LOGE("setSynchronousMode: SurfaceTexture has been abandoned!");
504 return NO_INIT;
505 }
506
507 status_t err = OK;
508 if (!mAllowSynchronousMode && enabled)
509 return err;
510
511 if (!enabled) {
512 // going to asynchronous mode, drain the queue
513 err = drainQueueLocked();
514 if (err != NO_ERROR)
515 return err;
516 }
517
518 if (mSynchronousMode != enabled) {
519 // - if we're going to asynchronous mode, the queue is guaranteed to be
520 // empty here
521 // - if the client set the number of buffers, we're guaranteed that
522 // we have at least 3 (because we don't allow less)
523 mSynchronousMode = enabled;
Dave Burke74ff8c22012-03-12 21:49:41 -0700524 mDequeueCondition.broadcast();
Daniel Lam6b091c52012-01-22 15:26:27 -0800525 }
526 return err;
527}
528
529status_t BufferQueue::queueBuffer(int buf, int64_t timestamp,
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700530 const Rect& crop, int scalingMode, uint32_t transform,
Daniel Lam6b091c52012-01-22 15:26:27 -0800531 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800532 ATRACE_CALL();
Mathias Agopian546ed2d2012-03-01 22:11:25 -0800533 ATRACE_BUFFER_INDEX(buf);
534
Daniel Lam6b091c52012-01-22 15:26:27 -0800535 ST_LOGV("queueBuffer: slot=%d time=%lld", buf, timestamp);
536
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700537 sp<ConsumerListener> listener;
Daniel Lam6b091c52012-01-22 15:26:27 -0800538
539 { // scope for the lock
540 Mutex::Autolock lock(mMutex);
541 if (mAbandoned) {
542 ST_LOGE("queueBuffer: SurfaceTexture has been abandoned!");
543 return NO_INIT;
544 }
545 if (buf < 0 || buf >= mBufferCount) {
546 ST_LOGE("queueBuffer: slot index out of range [0, %d]: %d",
547 mBufferCount, buf);
548 return -EINVAL;
549 } else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
550 ST_LOGE("queueBuffer: slot %d is not owned by the client "
551 "(state=%d)", buf, mSlots[buf].mBufferState);
552 return -EINVAL;
Daniel Lam6b091c52012-01-22 15:26:27 -0800553 } else if (!mSlots[buf].mRequestBufferCalled) {
554 ST_LOGE("queueBuffer: slot %d was enqueued without requesting a "
555 "buffer", buf);
556 return -EINVAL;
557 }
558
559 if (mSynchronousMode) {
560 // In synchronous mode we queue all buffers in a FIFO.
561 mQueue.push_back(buf);
562
563 // Synchronous mode always signals that an additional frame should
564 // be consumed.
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700565 listener = mConsumerListener;
Daniel Lam6b091c52012-01-22 15:26:27 -0800566 } else {
567 // In asynchronous mode we only keep the most recent buffer.
568 if (mQueue.empty()) {
569 mQueue.push_back(buf);
570
571 // Asynchronous mode only signals that a frame should be
572 // consumed if no previous frame was pending. If a frame were
573 // pending then the consumer would have already been notified.
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700574 listener = mConsumerListener;
Daniel Lam6b091c52012-01-22 15:26:27 -0800575 } else {
576 Fifo::iterator front(mQueue.begin());
577 // buffer currently queued is freed
578 mSlots[*front].mBufferState = BufferSlot::FREE;
579 // and we record the new buffer index in the queued list
580 *front = buf;
581 }
582 }
583
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700584 switch (scalingMode) {
585 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
586 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
587 break;
588 default:
589 ST_LOGE("unknown scaling mode: %d (ignoring)", scalingMode);
590 scalingMode = mSlots[buf].mScalingMode;
591 break;
592 }
593
Daniel Lam6b091c52012-01-22 15:26:27 -0800594 mSlots[buf].mBufferState = BufferSlot::QUEUED;
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700595 mSlots[buf].mCrop = crop;
596 mSlots[buf].mTransform = transform;
597 mSlots[buf].mScalingMode = scalingMode;
Daniel Lam6b091c52012-01-22 15:26:27 -0800598 mSlots[buf].mTimestamp = timestamp;
599 mFrameCounter++;
600 mSlots[buf].mFrameNumber = mFrameCounter;
601
Daniel Lameae59d22012-01-22 15:26:27 -0800602 mBufferHasBeenQueued = true;
Dave Burke74ff8c22012-03-12 21:49:41 -0700603 mDequeueCondition.broadcast();
Daniel Lam6b091c52012-01-22 15:26:27 -0800604
605 *outWidth = mDefaultWidth;
606 *outHeight = mDefaultHeight;
Daniel Lamb2675792012-02-23 14:35:13 -0800607 *outTransform = mTransformHint;
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800608
609 ATRACE_INT(mConsumerName.string(), mQueue.size());
Daniel Lam6b091c52012-01-22 15:26:27 -0800610 } // scope for the lock
611
612 // call back without lock held
613 if (listener != 0) {
614 listener->onFrameAvailable();
615 }
616 return OK;
617}
618
619void BufferQueue::cancelBuffer(int buf) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800620 ATRACE_CALL();
Daniel Lam6b091c52012-01-22 15:26:27 -0800621 ST_LOGV("cancelBuffer: slot=%d", buf);
622 Mutex::Autolock lock(mMutex);
623
624 if (mAbandoned) {
625 ST_LOGW("cancelBuffer: BufferQueue has been abandoned!");
626 return;
627 }
628
629 if (buf < 0 || buf >= mBufferCount) {
630 ST_LOGE("cancelBuffer: slot index out of range [0, %d]: %d",
631 mBufferCount, buf);
632 return;
633 } else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
634 ST_LOGE("cancelBuffer: slot %d is not owned by the client (state=%d)",
635 buf, mSlots[buf].mBufferState);
636 return;
637 }
638 mSlots[buf].mBufferState = BufferSlot::FREE;
639 mSlots[buf].mFrameNumber = 0;
Dave Burke74ff8c22012-03-12 21:49:41 -0700640 mDequeueCondition.broadcast();
Daniel Lam6b091c52012-01-22 15:26:27 -0800641}
642
Daniel Lam6b091c52012-01-22 15:26:27 -0800643status_t BufferQueue::connect(int api,
644 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800645 ATRACE_CALL();
Daniel Lam6b091c52012-01-22 15:26:27 -0800646 ST_LOGV("connect: api=%d", api);
647 Mutex::Autolock lock(mMutex);
648
649 if (mAbandoned) {
650 ST_LOGE("connect: BufferQueue has been abandoned!");
651 return NO_INIT;
652 }
653
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700654 if (mConsumerListener == NULL) {
655 ST_LOGE("connect: BufferQueue has no consumer!");
656 return NO_INIT;
657 }
658
Daniel Lam6b091c52012-01-22 15:26:27 -0800659 int err = NO_ERROR;
660 switch (api) {
661 case NATIVE_WINDOW_API_EGL:
662 case NATIVE_WINDOW_API_CPU:
663 case NATIVE_WINDOW_API_MEDIA:
664 case NATIVE_WINDOW_API_CAMERA:
665 if (mConnectedApi != NO_CONNECTED_API) {
666 ST_LOGE("connect: already connected (cur=%d, req=%d)",
667 mConnectedApi, api);
668 err = -EINVAL;
669 } else {
670 mConnectedApi = api;
671 *outWidth = mDefaultWidth;
672 *outHeight = mDefaultHeight;
673 *outTransform = 0;
674 }
675 break;
676 default:
677 err = -EINVAL;
678 break;
679 }
Daniel Lameae59d22012-01-22 15:26:27 -0800680
681 mBufferHasBeenQueued = false;
682
Daniel Lam6b091c52012-01-22 15:26:27 -0800683 return err;
684}
685
686status_t BufferQueue::disconnect(int api) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800687 ATRACE_CALL();
Daniel Lam6b091c52012-01-22 15:26:27 -0800688 ST_LOGV("disconnect: api=%d", api);
Daniel Lam6b091c52012-01-22 15:26:27 -0800689
690 int err = NO_ERROR;
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700691 sp<ConsumerListener> listener;
692
693 { // Scope for the lock
694 Mutex::Autolock lock(mMutex);
695
696 if (mAbandoned) {
697 // it is not really an error to disconnect after the surface
698 // has been abandoned, it should just be a no-op.
699 return NO_ERROR;
700 }
701
702 switch (api) {
703 case NATIVE_WINDOW_API_EGL:
704 case NATIVE_WINDOW_API_CPU:
705 case NATIVE_WINDOW_API_MEDIA:
706 case NATIVE_WINDOW_API_CAMERA:
707 if (mConnectedApi == api) {
708 drainQueueAndFreeBuffersLocked();
709 mConnectedApi = NO_CONNECTED_API;
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700710 mDequeueCondition.broadcast();
711 listener = mConsumerListener;
712 } else {
713 ST_LOGE("disconnect: connected to another api (cur=%d, req=%d)",
714 mConnectedApi, api);
715 err = -EINVAL;
716 }
717 break;
718 default:
719 ST_LOGE("disconnect: unknown API %d", api);
Daniel Lam6b091c52012-01-22 15:26:27 -0800720 err = -EINVAL;
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700721 break;
722 }
Daniel Lam6b091c52012-01-22 15:26:27 -0800723 }
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700724
725 if (listener != NULL) {
726 listener->onBuffersReleased();
727 }
728
Daniel Lam6b091c52012-01-22 15:26:27 -0800729 return err;
730}
731
Daniel Lameae59d22012-01-22 15:26:27 -0800732void BufferQueue::dump(String8& result) const
733{
734 char buffer[1024];
735 BufferQueue::dump(result, "", buffer, 1024);
736}
737
738void BufferQueue::dump(String8& result, const char* prefix,
739 char* buffer, size_t SIZE) const
740{
741 Mutex::Autolock _l(mMutex);
Daniel Lameae59d22012-01-22 15:26:27 -0800742
743 String8 fifo;
744 int fifoSize = 0;
745 Fifo::const_iterator i(mQueue.begin());
746 while (i != mQueue.end()) {
747 snprintf(buffer, SIZE, "%02d ", *i++);
748 fifoSize++;
749 fifo.append(buffer);
750 }
751
752 snprintf(buffer, SIZE,
753 "%s-BufferQueue mBufferCount=%d, mSynchronousMode=%d, default-size=[%dx%d], "
754 "mPixelFormat=%d, FIFO(%d)={%s}\n",
755 prefix, mBufferCount, mSynchronousMode, mDefaultWidth,
756 mDefaultHeight, mPixelFormat, fifoSize, fifo.string());
757 result.append(buffer);
758
759
760 struct {
761 const char * operator()(int state) const {
762 switch (state) {
763 case BufferSlot::DEQUEUED: return "DEQUEUED";
764 case BufferSlot::QUEUED: return "QUEUED";
765 case BufferSlot::FREE: return "FREE";
766 case BufferSlot::ACQUIRED: return "ACQUIRED";
767 default: return "Unknown";
768 }
769 }
770 } stateName;
771
772 for (int i=0 ; i<mBufferCount ; i++) {
773 const BufferSlot& slot(mSlots[i]);
774 snprintf(buffer, SIZE,
775 "%s%s[%02d] "
776 "state=%-8s, crop=[%d,%d,%d,%d], "
777 "transform=0x%02x, timestamp=%lld",
778 prefix, (slot.mBufferState == BufferSlot::ACQUIRED)?">":" ", i,
779 stateName(slot.mBufferState),
780 slot.mCrop.left, slot.mCrop.top, slot.mCrop.right,
781 slot.mCrop.bottom, slot.mTransform, slot.mTimestamp
782 );
783 result.append(buffer);
784
785 const sp<GraphicBuffer>& buf(slot.mGraphicBuffer);
786 if (buf != NULL) {
787 snprintf(buffer, SIZE,
788 ", %p [%4ux%4u:%4u,%3X]",
789 buf->handle, buf->width, buf->height, buf->stride,
790 buf->format);
791 result.append(buffer);
792 }
793 result.append("\n");
794 }
795}
796
Daniel Lam6b091c52012-01-22 15:26:27 -0800797void BufferQueue::freeBufferLocked(int i) {
798 mSlots[i].mGraphicBuffer = 0;
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700799 if (mSlots[i].mBufferState == BufferSlot::ACQUIRED) {
800 mSlots[i].mNeedsCleanupOnRelease = true;
801 }
Daniel Lam6b091c52012-01-22 15:26:27 -0800802 mSlots[i].mBufferState = BufferSlot::FREE;
803 mSlots[i].mFrameNumber = 0;
Daniel Lameae59d22012-01-22 15:26:27 -0800804 mSlots[i].mAcquireCalled = false;
805
806 // destroy fence as BufferQueue now takes ownership
807 if (mSlots[i].mFence != EGL_NO_SYNC_KHR) {
808 eglDestroySyncKHR(mSlots[i].mEglDisplay, mSlots[i].mFence);
809 mSlots[i].mFence = EGL_NO_SYNC_KHR;
Daniel Lam6b091c52012-01-22 15:26:27 -0800810 }
811}
812
813void BufferQueue::freeAllBuffersLocked() {
814 ALOGW_IF(!mQueue.isEmpty(),
815 "freeAllBuffersLocked called but mQueue is not empty");
Daniel Lameae59d22012-01-22 15:26:27 -0800816 mQueue.clear();
817 mBufferHasBeenQueued = false;
Daniel Lam6b091c52012-01-22 15:26:27 -0800818 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
819 freeBufferLocked(i);
820 }
821}
822
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700823status_t BufferQueue::acquireBuffer(BufferItem *buffer) {
Mathias Agopian546ed2d2012-03-01 22:11:25 -0800824 ATRACE_CALL();
Daniel Lameae59d22012-01-22 15:26:27 -0800825 Mutex::Autolock _l(mMutex);
826 // check if queue is empty
827 // In asynchronous mode the list is guaranteed to be one buffer
828 // deep, while in synchronous mode we use the oldest buffer.
829 if (!mQueue.empty()) {
830 Fifo::iterator front(mQueue.begin());
831 int buf = *front;
832
Mathias Agopian546ed2d2012-03-01 22:11:25 -0800833 ATRACE_BUFFER_INDEX(buf);
834
Daniel Lameae59d22012-01-22 15:26:27 -0800835 if (mSlots[buf].mAcquireCalled) {
836 buffer->mGraphicBuffer = NULL;
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700837 } else {
Daniel Lameae59d22012-01-22 15:26:27 -0800838 buffer->mGraphicBuffer = mSlots[buf].mGraphicBuffer;
839 }
840 buffer->mCrop = mSlots[buf].mCrop;
841 buffer->mTransform = mSlots[buf].mTransform;
842 buffer->mScalingMode = mSlots[buf].mScalingMode;
843 buffer->mFrameNumber = mSlots[buf].mFrameNumber;
Daniel Lam3fcee502012-03-02 10:17:34 -0800844 buffer->mTimestamp = mSlots[buf].mTimestamp;
Daniel Lameae59d22012-01-22 15:26:27 -0800845 buffer->mBuf = buf;
846 mSlots[buf].mAcquireCalled = true;
847
848 mSlots[buf].mBufferState = BufferSlot::ACQUIRED;
849 mQueue.erase(front);
Dave Burke74ff8c22012-03-12 21:49:41 -0700850 mDequeueCondition.broadcast();
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800851
852 ATRACE_INT(mConsumerName.string(), mQueue.size());
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700853 } else {
Daniel Lamfbcda932012-04-09 22:51:52 -0700854 return NO_BUFFER_AVAILABLE;
Daniel Lameae59d22012-01-22 15:26:27 -0800855 }
856
857 return OK;
858}
859
860status_t BufferQueue::releaseBuffer(int buf, EGLDisplay display,
861 EGLSyncKHR fence) {
Mathias Agopian546ed2d2012-03-01 22:11:25 -0800862 ATRACE_CALL();
863 ATRACE_BUFFER_INDEX(buf);
864
Daniel Lameae59d22012-01-22 15:26:27 -0800865 Mutex::Autolock _l(mMutex);
866
867 if (buf == INVALID_BUFFER_SLOT) {
868 return -EINVAL;
869 }
870
871 mSlots[buf].mEglDisplay = display;
872 mSlots[buf].mFence = fence;
873
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700874 // The buffer can now only be released if its in the acquired state
875 if (mSlots[buf].mBufferState == BufferSlot::ACQUIRED) {
Daniel Lameae59d22012-01-22 15:26:27 -0800876 mSlots[buf].mBufferState = BufferSlot::FREE;
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700877 } else if (mSlots[buf].mNeedsCleanupOnRelease) {
878 ST_LOGV("releasing a stale buf %d its state was %d", buf, mSlots[buf].mBufferState);
879 mSlots[buf].mNeedsCleanupOnRelease = false;
880 return STALE_BUFFER_SLOT;
881 } else {
882 ST_LOGE("attempted to release buf %d but its state was %d", buf, mSlots[buf].mBufferState);
883 return -EINVAL;
Daniel Lameae59d22012-01-22 15:26:27 -0800884 }
Daniel Lameae59d22012-01-22 15:26:27 -0800885
Daniel Lam9abe1eb2012-03-26 20:37:15 -0700886 mDequeueCondition.broadcast();
Daniel Lameae59d22012-01-22 15:26:27 -0800887 return OK;
888}
889
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700890status_t BufferQueue::consumerConnect(const sp<ConsumerListener>& consumerListener) {
891 ST_LOGV("consumerConnect");
Daniel Lameae59d22012-01-22 15:26:27 -0800892 Mutex::Autolock lock(mMutex);
Daniel Lamb2675792012-02-23 14:35:13 -0800893
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700894 if (mAbandoned) {
895 ST_LOGE("consumerConnect: BufferQueue has been abandoned!");
896 return NO_INIT;
897 }
Daniel Lamb2675792012-02-23 14:35:13 -0800898
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700899 mConsumerListener = consumerListener;
900
901 return OK;
902}
903
904status_t BufferQueue::consumerDisconnect() {
905 ST_LOGV("consumerDisconnect");
906 Mutex::Autolock lock(mMutex);
907
908 if (mConsumerListener == NULL) {
909 ST_LOGE("consumerDisconnect: No consumer is connected!");
910 return -EINVAL;
911 }
912
913 mAbandoned = true;
914 mConsumerListener = NULL;
Daniel Lamb2675792012-02-23 14:35:13 -0800915 mQueue.clear();
Daniel Lameae59d22012-01-22 15:26:27 -0800916 freeAllBuffersLocked();
Dave Burke74ff8c22012-03-12 21:49:41 -0700917 mDequeueCondition.broadcast();
Daniel Lameae59d22012-01-22 15:26:27 -0800918 return OK;
919}
920
Jamie Gennisfa5b40e2012-03-15 14:01:24 -0700921status_t BufferQueue::getReleasedBuffers(uint32_t* slotMask) {
922 ST_LOGV("getReleasedBuffers");
923 Mutex::Autolock lock(mMutex);
924
925 if (mAbandoned) {
926 ST_LOGE("getReleasedBuffers: BufferQueue has been abandoned!");
927 return NO_INIT;
928 }
929
930 uint32_t mask = 0;
931 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
932 if (!mSlots[i].mAcquireCalled) {
933 mask |= 1 << i;
934 }
935 }
936 *slotMask = mask;
937
938 ST_LOGV("getReleasedBuffers: returning mask %#x", mask);
939 return NO_ERROR;
940}
941
Daniel Lameae59d22012-01-22 15:26:27 -0800942status_t BufferQueue::setDefaultBufferSize(uint32_t w, uint32_t h)
943{
944 ST_LOGV("setDefaultBufferSize: w=%d, h=%d", w, h);
945 if (!w || !h) {
946 ST_LOGE("setDefaultBufferSize: dimensions cannot be 0 (w=%d, h=%d)",
947 w, h);
948 return BAD_VALUE;
949 }
950
951 Mutex::Autolock lock(mMutex);
952 mDefaultWidth = w;
953 mDefaultHeight = h;
954 return OK;
955}
956
957status_t BufferQueue::setBufferCountServer(int bufferCount) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800958 ATRACE_CALL();
Daniel Lameae59d22012-01-22 15:26:27 -0800959 Mutex::Autolock lock(mMutex);
960 return setBufferCountServerLocked(bufferCount);
961}
962
Daniel Lam6b091c52012-01-22 15:26:27 -0800963void BufferQueue::freeAllBuffersExceptHeadLocked() {
964 ALOGW_IF(!mQueue.isEmpty(),
965 "freeAllBuffersExceptCurrentLocked called but mQueue is not empty");
966 int head = -1;
967 if (!mQueue.empty()) {
968 Fifo::iterator front(mQueue.begin());
969 head = *front;
970 }
Daniel Lameae59d22012-01-22 15:26:27 -0800971 mBufferHasBeenQueued = false;
Daniel Lam6b091c52012-01-22 15:26:27 -0800972 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
973 if (i != head) {
974 freeBufferLocked(i);
975 }
976 }
977}
978
979status_t BufferQueue::drainQueueLocked() {
980 while (mSynchronousMode && !mQueue.isEmpty()) {
981 mDequeueCondition.wait(mMutex);
982 if (mAbandoned) {
983 ST_LOGE("drainQueueLocked: BufferQueue has been abandoned!");
984 return NO_INIT;
985 }
986 if (mConnectedApi == NO_CONNECTED_API) {
987 ST_LOGE("drainQueueLocked: BufferQueue is not connected!");
988 return NO_INIT;
989 }
990 }
991 return NO_ERROR;
992}
993
994status_t BufferQueue::drainQueueAndFreeBuffersLocked() {
995 status_t err = drainQueueLocked();
996 if (err == NO_ERROR) {
997 if (mSynchronousMode) {
998 freeAllBuffersLocked();
999 } else {
1000 freeAllBuffersExceptHeadLocked();
1001 }
1002 }
1003 return err;
1004}
1005
Jamie Gennisfa5b40e2012-03-15 14:01:24 -07001006BufferQueue::ProxyConsumerListener::ProxyConsumerListener(
1007 const wp<BufferQueue::ConsumerListener>& consumerListener):
1008 mConsumerListener(consumerListener) {}
1009
1010BufferQueue::ProxyConsumerListener::~ProxyConsumerListener() {}
1011
1012void BufferQueue::ProxyConsumerListener::onFrameAvailable() {
1013 sp<BufferQueue::ConsumerListener> listener(mConsumerListener.promote());
1014 if (listener != NULL) {
1015 listener->onFrameAvailable();
1016 }
1017}
1018
1019void BufferQueue::ProxyConsumerListener::onBuffersReleased() {
1020 sp<BufferQueue::ConsumerListener> listener(mConsumerListener.promote());
1021 if (listener != NULL) {
1022 listener->onBuffersReleased();
1023 }
1024}
1025
Daniel Lam6b091c52012-01-22 15:26:27 -08001026}; // namespace android