From 3d4039d7a291cd9b6f2dd4b46fcdb576f2db3356 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 23 Sep 2016 16:31:30 -0700 Subject: Use FenceTime to share fence times and reduce open fds. FenceTimes are created and shared for each Fence that FrameTimestampHistory and FrameTracker care about. On the consumer side, the FenceTimes are also added to shared timelines that are owned by SurfaceFlinger or unshared timelines owned by Layer. The timelines are checked at the end of every frame to minimize the number of file descriptors open. On the producer side, the FenceTimes are added to the ConsumerFrameEventHistory instead, since the timelines that would be tracked by SurfaceFlinger are not shared with anyone else in the consumer's process. The timelines are checked just after a frame is queued to minimize the number of file descriptors open. Test: adb shell /data/nativetest/libgui_test/libgui_test --gtest_filter=*GetFrameTimestamps* Change-Id: Ifd4301affe1b24705b2bee7608c5a2c09dfb4041 --- libs/gui/Surface.cpp | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'libs/gui/Surface.cpp') diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 6a02a77592..c9e1c6c8a8 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -144,6 +144,19 @@ void Surface::enableFrameTimestamps(bool enable) { mEnableFrameTimestamps = enable; } +static void getFrameTimestamp(nsecs_t *dst, const nsecs_t& src) { + if (dst != nullptr) { + *dst = Fence::isValidTimestamp(src) ? src : 0; + } +} + +static void getFrameTimestampFence(nsecs_t *dst, const std::shared_ptr& src) { + if (dst != nullptr) { + nsecs_t signalTime = src->getSignalTime(); + *dst = Fence::isValidTimestamp(signalTime) ? signalTime : 0; + } +} + status_t Surface::getFrameTimestamps(uint64_t frameNumber, nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime, nsecs_t* outRefreshStartTime, nsecs_t* outGlCompositionDoneTime, @@ -188,29 +201,16 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber, return NAME_NOT_FOUND; } - events->checkFencesForCompletion(); + getFrameTimestamp(outRequestedPresentTime, events->requestedPresentTime); + getFrameTimestamp(outRefreshStartTime, events->firstRefreshStartTime); - if (outRequestedPresentTime) { - *outRequestedPresentTime = events->requestedPresentTime; - } - if (outAcquireTime) { - *outAcquireTime = events->acquireTime; - } - if (outRefreshStartTime) { - *outRefreshStartTime = events->firstRefreshStartTime; - } - if (outGlCompositionDoneTime) { - *outGlCompositionDoneTime = events->gpuCompositionDoneTime; - } - if (outDisplayPresentTime) { - *outDisplayPresentTime = events->displayPresentTime; - } - if (outDisplayRetireTime) { - *outDisplayRetireTime = events->displayRetireTime; - } - if (outReleaseTime) { - *outReleaseTime = events->releaseTime; - } + getFrameTimestampFence(outAcquireTime, events->acquireFence); + getFrameTimestampFence( + outGlCompositionDoneTime, events->gpuCompositionDoneFence); + getFrameTimestampFence( + outDisplayPresentTime, events->displayPresentFence); + getFrameTimestampFence(outDisplayRetireTime, events->displayRetireFence); + getFrameTimestampFence(outReleaseTime, events->releaseFence); return NO_ERROR; } @@ -571,7 +571,12 @@ int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { // Update timestamps with the local acquire fence. // The consumer doesn't send it back to prevent us from having two // file descriptors of the same fence. - mFrameEventHistory.updateAcquireFence(mNextFrameNumber, fence); + mFrameEventHistory.updateAcquireFence(mNextFrameNumber, + std::make_shared(std::move(fence))); + + // Cache timestamps of signaled fences so we can close their file + // descriptors. + mFrameEventHistory.updateSignalTimes(); } mDefaultWidth = output.width; -- cgit v1.2.3-59-g8ed1b