From 82dbc7429f5f9f2b303b31dc5b9f2bfd1bbe6add Mon Sep 17 00:00:00 2001 From: Jamie Gennis Date: Thu, 8 Nov 2012 19:23:28 -0800 Subject: SurfaceFlinger: refactor frame time tracking This change moves the frame time history tracking code out of Layer and into a new class called FrameTracker. It also changes the tracking to use signal timestamps from fences when available for more accurate results. Change-Id: I323c5f075c58bf86ce363b52af885ad0f6365f2b --- libs/ui/Fence.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libs/ui/Fence.cpp') diff --git a/libs/ui/Fence.cpp b/libs/ui/Fence.cpp index d214b97..84f5a47 100644 --- a/libs/ui/Fence.cpp +++ b/libs/ui/Fence.cpp @@ -18,6 +18,9 @@ #define ATRACE_TAG ATRACE_TAG_GRAPHICS //#define LOG_NDEBUG 0 + // This is needed for stdint.h to define INT64_MAX in C++ + #define __STDC_LIMIT_MACROS + #include #include #include @@ -86,6 +89,32 @@ int Fence::dup() const { return ::dup(mFenceFd); } +nsecs_t Fence::getSignalTime() const { + if (mFenceFd == -1) { + return -1; + } + + struct sync_fence_info_data* finfo = sync_fence_info(mFenceFd); + if (finfo == NULL) { + ALOGE("sync_fence_info returned NULL for fd %d", mFenceFd); + return -1; + } + if (finfo->status != 1) { + return INT64_MAX; + } + + struct sync_pt_info* pinfo = NULL; + uint64_t timestamp = 0; + while ((pinfo = sync_pt_info(finfo, pinfo)) != NULL) { + if (pinfo->timestamp_ns > timestamp) { + timestamp = pinfo->timestamp_ns; + } + } + sync_fence_info_free(finfo); + + return nsecs_t(timestamp); +} + size_t Fence::getFlattenedSize() const { return 0; } -- cgit v1.1