summaryrefslogtreecommitdiff
path: root/libs/gui/Surface.cpp
diff options
context:
space:
mode:
author Ian Elliott <ianelliott@google.com> 2017-07-18 11:05:49 -0600
committer Ian Elliott <ianelliott@google.com> 2017-07-25 14:18:53 -0600
commitb4f7493fbdb1d9d5b437a1dcb82e98b1531f4e3e (patch)
treee6aef13bfd9d4ee5f0fb956e0715c95bc27801ac /libs/gui/Surface.cpp
parentb8b53824fb8b38c24072b482a18a95b4a55d8943 (diff)
Have the Surface class track the buffer age.
Have the Surface class track the buffer age, so that Surface::query() can return the buffer age without having to use a binder call to BufferQueueProducer::query(). The idea is for BufferQueueProducer::dequeueBuffer() to return the value, which the Surface class will cache for later use by Surface::query(). Bug: b/27903668 Test: Use systrace to no ensure query binder call after dequeueBuffer. Change-Id: I7a4d79d02ea68781b464a463f0ecdf64978b7fb8
Diffstat (limited to 'libs/gui/Surface.cpp')
-rw-r--r--libs/gui/Surface.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index 409a3cb076..78eb69d132 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -44,21 +44,19 @@
namespace android {
-Surface::Surface(
- const sp<IGraphicBufferProducer>& bufferProducer,
- bool controlledByApp)
- : mGraphicBufferProducer(bufferProducer),
- mCrop(Rect::EMPTY_RECT),
- mGenerationNumber(0),
- mSharedBufferMode(false),
- mAutoRefresh(false),
- mSharedBufferSlot(BufferItem::INVALID_BUFFER_SLOT),
- mSharedBufferHasBeenQueued(false),
- mQueriedSupportedTimestamps(false),
- mFrameTimestampsSupportsPresent(false),
- mEnableFrameTimestamps(false),
- mFrameEventHistory(std::make_unique<ProducerFrameEventHistory>())
-{
+Surface::Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp)
+ : mGraphicBufferProducer(bufferProducer),
+ mCrop(Rect::EMPTY_RECT),
+ mBufferAge(0),
+ mGenerationNumber(0),
+ mSharedBufferMode(false),
+ mAutoRefresh(false),
+ mSharedBufferSlot(BufferItem::INVALID_BUFFER_SLOT),
+ mSharedBufferHasBeenQueued(false),
+ mQueriedSupportedTimestamps(false),
+ mFrameTimestampsSupportsPresent(false),
+ mEnableFrameTimestamps(false),
+ mFrameEventHistory(std::make_unique<ProducerFrameEventHistory>()) {
// Initialize the ANativeWindow function pointers.
ANativeWindow::setSwapInterval = hook_setSwapInterval;
ANativeWindow::dequeueBuffer = hook_dequeueBuffer;
@@ -506,9 +504,10 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) {
nsecs_t startTime = systemTime();
FrameEventHistoryDelta frameTimestamps;
- status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence,
- reqWidth, reqHeight, reqFormat, reqUsage,
- enableFrameTimestamps ? &frameTimestamps : nullptr);
+ status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, reqWidth, reqHeight,
+ reqFormat, reqUsage, &mBufferAge,
+ enableFrameTimestamps ? &frameTimestamps
+ : nullptr);
mLastDequeueDuration = systemTime() - startTime;
if (result < 0) {
@@ -845,6 +844,14 @@ int Surface::query(int what, int* value) const {
}
return err;
}
+ case NATIVE_WINDOW_BUFFER_AGE: {
+ if (mBufferAge > INT32_MAX) {
+ *value = 0;
+ } else {
+ *value = static_cast<int32_t>(mBufferAge);
+ }
+ return NO_ERROR;
+ }
case NATIVE_WINDOW_LAST_DEQUEUE_DURATION: {
int64_t durationUs = mLastDequeueDuration / 1000;
*value = durationUs > std::numeric_limits<int>::max() ?