From 932f008485dbb6fb452c8616abd7586f914f72ce Mon Sep 17 00:00:00 2001 From: Dan Stoza Date: Wed, 31 May 2017 13:50:16 -0700 Subject: libgui: Add Surface::getLastDequeueStartTime Adds the getLastDequeueStartTime method, which allows the caller to determine whether the last dequeueBuffer call fell into a given time window. Bug: 62213889 Test: SurfaceTest.TestGetLastDequeueStartTime in libgui_test Change-Id: I1684deb09273745a3adc751554624d2257fa890e --- libs/gui/Surface.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 6583a622f5..7b2b5c37f1 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -501,13 +501,13 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { int buf = -1; sp fence; - nsecs_t now = systemTime(); + nsecs_t startTime = systemTime(); FrameEventHistoryDelta frameTimestamps; status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, reqWidth, reqHeight, reqFormat, reqUsage, enableFrameTimestamps ? &frameTimestamps : nullptr); - mLastDequeueDuration = systemTime() - now; + mLastDequeueDuration = systemTime() - startTime; if (result < 0) { ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer" @@ -524,6 +524,9 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { Mutex::Autolock lock(mMutex); + // Write this while holding the mutex + mLastDequeueStartTime = startTime; + sp& gbuf(mSlots[buf].buffer); // this should never happen @@ -1699,6 +1702,11 @@ status_t Surface::getUniqueId(uint64_t* outId) const { return mGraphicBufferProducer->getUniqueId(outId); } +nsecs_t Surface::getLastDequeueStartTime() const { + Mutex::Autolock lock(mMutex); + return mLastDequeueStartTime; +} + status_t Surface::getAndFlushRemovedBuffers(std::vector>* out) { if (out == nullptr) { ALOGE("%s: out must not be null!", __FUNCTION__); -- cgit v1.2.3-59-g8ed1b