diff options
author | 2017-06-01 06:23:36 +0000 | |
---|---|---|
committer | 2017-06-01 06:23:36 +0000 | |
commit | 8c9cc460d7694a8d03fe97eee45c0ed28beaa9d5 (patch) | |
tree | a65d1b097e66284bbe7cc8487d7d3a12c804900f | |
parent | e2cc7337ccd1afb2fbfc401918648d557be0da3a (diff) | |
parent | 46b9841653f180f8aa73a3190b4fb5eb5ffb6872 (diff) |
libgui: Add Surface::getLastDequeueStartTime am: 932f008485
am: 46b9841653
Change-Id: Id3dd6920b3341c5675b5308a9c80e276a5b03ce2
-rw-r--r-- | include/gui/Surface.h | 6 | ||||
-rw-r--r-- | libs/gui/Surface.cpp | 12 | ||||
-rw-r--r-- | libs/gui/tests/Surface_test.cpp | 18 |
3 files changed, 33 insertions, 3 deletions
diff --git a/include/gui/Surface.h b/include/gui/Surface.h index c836543b16..0f7e12a228 100644 --- a/include/gui/Surface.h +++ b/include/gui/Surface.h @@ -160,6 +160,9 @@ public: status_t getUniqueId(uint64_t* outId) const; + // Returns the CLOCK_MONOTONIC start time of the last dequeueBuffer call + nsecs_t getLastDequeueStartTime() const; + protected: virtual ~Surface(); @@ -421,6 +424,9 @@ protected: nsecs_t mLastDequeueDuration = 0; nsecs_t mLastQueueDuration = 0; + // Stores the time right before we call IGBP::dequeueBuffer + nsecs_t mLastDequeueStartTime = 0; + Condition mQueueBufferCondition; uint64_t mNextFrameNumber = 1; diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index d471dbf047..409a3cb076 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -503,13 +503,13 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { int buf = -1; sp<Fence> 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" @@ -526,6 +526,9 @@ int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { Mutex::Autolock lock(mMutex); + // Write this while holding the mutex + mLastDequeueStartTime = startTime; + sp<GraphicBuffer>& gbuf(mSlots[buf].buffer); // this should never happen @@ -1711,6 +1714,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<sp<GraphicBuffer>>* out) { if (out == nullptr) { ALOGE("%s: out must not be null!", __FUNCTION__); diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index fcaa23a4e5..81820def1c 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -393,6 +393,22 @@ TEST_F(SurfaceTest, GetAndFlushRemovedBuffers) { ASSERT_LE(removedBuffers.size(), 1u); } +TEST_F(SurfaceTest, TestGetLastDequeueStartTime) { + sp<ANativeWindow> anw(mSurface); + ASSERT_EQ(NO_ERROR, native_window_api_connect(anw.get(), NATIVE_WINDOW_API_CPU)); + + ANativeWindowBuffer* buffer = nullptr; + int32_t fenceFd = -1; + + nsecs_t before = systemTime(CLOCK_MONOTONIC); + anw->dequeueBuffer(anw.get(), &buffer, &fenceFd); + nsecs_t after = systemTime(CLOCK_MONOTONIC); + + nsecs_t lastDequeueTime = mSurface->getLastDequeueStartTime(); + ASSERT_LE(before, lastDequeueTime); + ASSERT_GE(after, lastDequeueTime); +} + class FakeConsumer : public BnConsumerListener { public: void onFrameAvailable(const BufferItem& /*item*/) override {} @@ -1568,4 +1584,4 @@ TEST_F(GetFrameTimestampsTest, PresentUnsupportedNoSync) { EXPECT_EQ(-1, outDisplayPresentTime); } -} +} // namespace android |