From a2eb34cfbe089deb9a519e9702e17d9dfe26f9e8 Mon Sep 17 00:00:00 2001 From: Ian Elliott Date: Tue, 18 Jul 2017 11:05:49 -0600 Subject: 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: I106a7bd27461d381f0bd84df70d804de56a128ab (cherry picked from commit d11b044864be525a1646f93106ab496195bb8239) --- libs/gui/IGraphicBufferProducer.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'libs/gui/IGraphicBufferProducer.cpp') diff --git a/libs/gui/IGraphicBufferProducer.cpp b/libs/gui/IGraphicBufferProducer.cpp index 1b0fe06810..8406a52544 100644 --- a/libs/gui/IGraphicBufferProducer.cpp +++ b/libs/gui/IGraphicBufferProducer.cpp @@ -124,9 +124,9 @@ public: return result; } - virtual status_t dequeueBuffer(int *buf, sp* fence, uint32_t width, - uint32_t height, PixelFormat format, uint64_t usage, - FrameEventHistoryDelta* outTimestamps) { + virtual status_t dequeueBuffer(int* buf, sp* fence, uint32_t width, uint32_t height, + PixelFormat format, uint64_t usage, uint64_t* outBufferAge, + FrameEventHistoryDelta* outTimestamps) { Parcel data, reply; bool getFrameTimestamps = (outTimestamps != nullptr); @@ -149,6 +149,17 @@ public: fence->clear(); return result; } + if (outBufferAge) { + result = reply.readUint64(outBufferAge); + } else { + // Read the value even if outBufferAge is nullptr: + uint64_t bufferAge; + result = reply.readUint64(&bufferAge); + } + if (result != NO_ERROR) { + ALOGE("IGBP::dequeueBuffer failed to read buffer age: %d", result); + return result; + } if (getFrameTimestamps) { result = reply.read(*outTimestamps); if (result != NO_ERROR) { @@ -516,11 +527,10 @@ public: return mBase->setAsyncMode(async); } - status_t dequeueBuffer(int* slot, sp* fence, uint32_t w, uint32_t h, - PixelFormat format, uint64_t usage, - FrameEventHistoryDelta* outTimestamps) override { - return mBase->dequeueBuffer( - slot, fence, w, h, format, usage, outTimestamps); + status_t dequeueBuffer(int* slot, sp* fence, uint32_t w, uint32_t h, PixelFormat format, + uint64_t usage, uint64_t* outBufferAge, + FrameEventHistoryDelta* outTimestamps) override { + return mBase->dequeueBuffer(slot, fence, w, h, format, usage, outBufferAge, outTimestamps); } status_t detachBuffer(int slot) override { @@ -655,16 +665,18 @@ status_t BnGraphicBufferProducer::onTransact( uint32_t height = data.readUint32(); PixelFormat format = static_cast(data.readInt32()); uint64_t usage = data.readUint64(); + uint64_t bufferAge = 0; bool getTimestamps = data.readBool(); int buf = 0; sp fence = Fence::NO_FENCE; FrameEventHistoryDelta frameTimestamps; - int result = dequeueBuffer(&buf, &fence, width, height, format, - usage, getTimestamps ? &frameTimestamps : nullptr); + int result = dequeueBuffer(&buf, &fence, width, height, format, usage, &bufferAge, + getTimestamps ? &frameTimestamps : nullptr); reply->writeInt32(buf); reply->write(*fence); + reply->writeUint64(bufferAge); if (getTimestamps) { reply->write(frameTimestamps); } -- cgit v1.2.3