diff options
author | Dan Stoza <stoza@google.com> | 2015-02-25 16:49:08 -0800 |
---|---|---|
committer | Dan Stoza <stoza@google.com> | 2015-04-28 14:26:05 -0700 |
commit | 81cde67a5528af6fbb7a3d49930fd3ca8ff49b34 (patch) | |
tree | bbb270d49d9fd5de3dc48b4c0e0e49a384033023 | |
parent | 958f501189a29e53767f41bc8172e4af8d1ce2bf (diff) | |
download | frameworks_native-81cde67a5528af6fbb7a3d49930fd3ca8ff49b34.zip frameworks_native-81cde67a5528af6fbb7a3d49930fd3ca8ff49b34.tar.gz frameworks_native-81cde67a5528af6fbb7a3d49930fd3ca8ff49b34.tar.bz2 |
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
-rw-r--r-- | include/gui/BufferQueueCore.h | 4 | ||||
-rw-r--r-- | libs/gui/BufferQueueCore.cpp | 3 | ||||
-rw-r--r-- | libs/gui/BufferQueueProducer.cpp | 16 |
3 files changed, 22 insertions, 1 deletions
diff --git a/include/gui/BufferQueueCore.h b/include/gui/BufferQueueCore.h index 9a43516..e3624b7 100644 --- a/include/gui/BufferQueueCore.h +++ b/include/gui/BufferQueueCore.h @@ -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 diff --git a/libs/gui/BufferQueueCore.cpp b/libs/gui/BufferQueueCore.cpp index bc75ca7..887f2cb 100644 --- a/libs/gui/BufferQueueCore.cpp +++ b/libs/gui/BufferQueueCore.cpp @@ -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()); diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp index 86e45c8..7251d36 100644 --- a/libs/gui/BufferQueueProducer.cpp +++ b/libs/gui/BufferQueueProducer.cpp @@ -337,10 +337,19 @@ 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 %" PRIu64, + 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 +793,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; } |