BufferQueue: Add NATIVE_WINDOW_BUFFER_AGE query

Adds a NATIVE_WINDOW_BUFFER_AGE query, which returns the age of the
contents of the most recently dequeued buffer as the number of frames
that have elapsed since it was last queued.

Change-Id: Ib6fd62945cb62d1e60133a65beee510363218a23
(cherry picked from commit 49f810c72df8d1d64128e376757079825c8decd4)
This commit is contained in:
Dan Stoza 2015-02-25 16:49:08 -08:00
parent 80640fca04
commit 4afd8b67f9
3 changed files with 21 additions and 1 deletions

View File

@ -270,6 +270,10 @@ private:
// mAllowAllocation determines whether dequeueBuffer is allowed to allocate
// new buffers
bool mAllowAllocation;
// mBufferAge tracks the age of the contents of the most recently dequeued
// buffer as the number of frames that have elapsed since it was last queued
uint64_t mBufferAge;
}; // class BufferQueueCore
} // namespace android

View File

@ -70,7 +70,8 @@ BufferQueueCore::BufferQueueCore(const sp<IGraphicBufferAlloc>& allocator) :
mTransformHint(0),
mIsAllocating(false),
mIsAllocatingCondition(),
mAllowAllocation(true)
mAllowAllocation(true),
mBufferAge(0)
{
if (allocator == NULL) {
sp<ISurfaceComposer> composer(ComposerService::getComposerService());

View File

@ -337,10 +337,18 @@ status_t BufferQueueProducer::dequeueBuffer(int *outSlot,
mSlots[found].mEglDisplay = EGL_NO_DISPLAY;
mSlots[found].mEglFence = EGL_NO_SYNC_KHR;
mSlots[found].mFence = Fence::NO_FENCE;
mCore->mBufferAge = 0;
returnFlags |= BUFFER_NEEDS_REALLOCATION;
} else {
// We add 1 because that will be the frame number when this buffer
// is queued
mCore->mBufferAge =
mCore->mFrameCounter + 1 - mSlots[found].mFrameNumber;
}
BQ_LOGV("dequeueBuffer: setting buffer age to %llu", mCore->mBufferAge);
if (CC_UNLIKELY(mSlots[found].mFence == NULL)) {
BQ_LOGE("dequeueBuffer: about to return a NULL fence - "
"slot=%d w=%d h=%d format=%u",
@ -784,6 +792,13 @@ int BufferQueueProducer::query(int what, int *outValue) {
case NATIVE_WINDOW_DEFAULT_DATASPACE:
value = static_cast<int32_t>(mCore->mDefaultBufferDataSpace);
break;
case NATIVE_WINDOW_BUFFER_AGE:
if (mCore->mBufferAge > INT32_MAX) {
value = 0;
} else {
value = static_cast<int32_t>(mCore->mBufferAge);
}
break;
default:
return BAD_VALUE;
}