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
diff --git a/services/surfaceflinger/FrameTracker.h b/services/surfaceflinger/FrameTracker.h
index cd5e3f3..adcdfb5 100644
--- a/services/surfaceflinger/FrameTracker.h
+++ b/services/surfaceflinger/FrameTracker.h
@@ -17,6 +17,8 @@
#ifndef ANDROID_FRAMETRACKER_H
#define ANDROID_FRAMETRACKER_H
+#include <ui/FenceTime.h>
+
#include <stddef.h>
#include <utils/Mutex.h>
@@ -26,7 +28,6 @@
namespace android {
class String8;
-class Fence;
// FrameTracker tracks information about the most recently rendered frames. It
// uses a circular buffer of frame records, and is *NOT* thread-safe -
@@ -60,7 +61,7 @@
// setFrameReadyFence sets the fence that is used to get the time at which
// the current frame became ready to be presented to the user.
- void setFrameReadyFence(const sp<Fence>& readyFence);
+ void setFrameReadyFence(std::shared_ptr<FenceTime>&& readyFence);
// setActualPresentTime sets the timestamp at which the current frame became
// visible to the user.
@@ -68,7 +69,7 @@
// setActualPresentFence sets the fence that is used to get the time
// at which the current frame became visible to the user.
- void setActualPresentFence(const sp<Fence>& fence);
+ void setActualPresentFence(std::shared_ptr<FenceTime>&& fence);
// setDisplayRefreshPeriod sets the display refresh period in nanoseconds.
// This is used to compute frame presentation duration statistics relative
@@ -100,8 +101,8 @@
nsecs_t desiredPresentTime;
nsecs_t frameReadyTime;
nsecs_t actualPresentTime;
- sp<Fence> frameReadyFence;
- sp<Fence> actualPresentFence;
+ std::shared_ptr<FenceTime> frameReadyFence;
+ std::shared_ptr<FenceTime> actualPresentFence;
};
// processFences iterates over all the frame records that have a fence set