summaryrefslogtreecommitdiff
path: root/libs/gui/Surface.cpp
diff options
context:
space:
mode:
author Brian Anderson <brianderson@google.com> 2016-09-23 16:31:30 -0700
committer Brian Anderson <brianderson@google.com> 2016-12-13 13:06:16 -0800
commit3d4039d7a291cd9b6f2dd4b46fcdb576f2db3356 (patch)
tree4f98394f38900a920987db69e74446ba1a88aa09 /libs/gui/Surface.cpp
parent13e4db237135006e801d3f9d75adaca82687002a (diff)
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
Diffstat (limited to 'libs/gui/Surface.cpp')
-rw-r--r--libs/gui/Surface.cpp51
1 files changed, 28 insertions, 23 deletions
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<FenceTime>& 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<FenceTime>(std::move(fence)));
+
+ // Cache timestamps of signaled fences so we can close their file
+ // descriptors.
+ mFrameEventHistory.updateSignalTimes();
}
mDefaultWidth = output.width;