EGL: Add eglGetCompositorTimingANDROID.
Exposes the composite deadline, composite interval, and
the composite to present latency.
A history of composite and present fences are stored.
When the present fence's timestamp becomes known,
the composite to present latency is updated with
sampling jitter removed.
The values are updated in the producer when timestamps
are enabled and on queue and dequeue.
The deadline is snapped to the next expected deadline
based on the current systemTime().
Test: adb shell /data/nativetest/libgui_test/libgui_test
--gtest_filter=*GetFrameTimestamps*
Change-Id: I406814258613b984b56488236632494f2f61ff2e
diff --git a/include/gui/FrameTimestamps.h b/include/gui/FrameTimestamps.h
index 46ca2c2..9e1ae94 100644
--- a/include/gui/FrameTimestamps.h
+++ b/include/gui/FrameTimestamps.h
@@ -95,6 +95,11 @@
std::shared_ptr<FenceTime> releaseFence{FenceTime::NO_FENCE};
};
+struct CompositorTiming {
+ nsecs_t deadline{0};
+ nsecs_t interval{16666667};
+ nsecs_t presentLatency{0};
+};
// A short history of frames that are synchronized between the consumer and
// producer via deltas.
@@ -111,6 +116,8 @@
protected:
std::array<FrameEvents, MAX_FRAME_HISTORY> mFrames;
+
+ CompositorTiming mCompositorTiming;
};
@@ -119,6 +126,16 @@
public:
~ProducerFrameEventHistory() override;
+ // Public for testing.
+ static nsecs_t snapToNextTick(
+ nsecs_t timestamp, nsecs_t tickPhase, nsecs_t tickInterval);
+
+ nsecs_t getNextCompositeDeadline(const nsecs_t now) const;
+ nsecs_t getCompositeInterval() const { return mCompositorTiming.interval; }
+ nsecs_t getCompositeToPresentLatency() const {
+ return mCompositorTiming.presentLatency;
+ }
+
// virtual for testing.
virtual void updateAcquireFence(
uint64_t frameNumber, std::shared_ptr<FenceTime>&& acquire);
@@ -189,12 +206,15 @@
public:
~ConsumerFrameEventHistory() override;
+ void initializeCompositorTiming(const CompositorTiming& compositorTiming);
+
void addQueue(const NewFrameEventsEntry& newEntry);
void addLatch(uint64_t frameNumber, nsecs_t latchTime);
void addPreComposition(uint64_t frameNumber, nsecs_t refreshStartTime);
void addPostComposition(uint64_t frameNumber,
const std::shared_ptr<FenceTime>& gpuCompositionDone,
- const std::shared_ptr<FenceTime>& displayPresent);
+ const std::shared_ptr<FenceTime>& displayPresent,
+ const CompositorTiming& compositorTiming);
void addRetire(uint64_t frameNumber,
const std::shared_ptr<FenceTime>& displayRetire);
void addRelease(uint64_t frameNumber, nsecs_t dequeueReadyTime,
@@ -244,7 +264,7 @@
size_t& count);
private:
- static size_t minFlattenedSize();
+ static constexpr size_t minFlattenedSize();
size_t mIndex{0};
uint64_t mFrameNumber{0};
@@ -306,9 +326,10 @@
size_t& count);
private:
- static size_t minFlattenedSize();
+ static constexpr size_t minFlattenedSize();
std::vector<FrameEventsDelta> mDeltas;
+ CompositorTiming mCompositorTiming;
};
diff --git a/include/gui/Surface.h b/include/gui/Surface.h
index 4baa6aa..d05d930 100644
--- a/include/gui/Surface.h
+++ b/include/gui/Surface.h
@@ -137,12 +137,18 @@
status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
sp<Fence>* outFence, float outTransformMatrix[16]);
+ status_t getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration);
+
/* Enables or disables frame timestamp tracking. It is disabled by default
* to avoid overhead during queue and dequeue for applications that don't
* need the feature. If disabled, calls to getFrameTimestamps will fail.
*/
void enableFrameTimestamps(bool enable);
+ status_t getCompositorTiming(
+ nsecs_t* compositeDeadline, nsecs_t* compositeInterval,
+ nsecs_t* compositeToPresentLatency);
+
// See IGraphicBufferProducer::getFrameTimestamps
status_t getFrameTimestamps(uint64_t frameNumber,
nsecs_t* outRequestedPresentTime, nsecs_t* outAcquireTime,
@@ -150,7 +156,6 @@
nsecs_t* outLastRefreshStartTime, nsecs_t* outGlCompositionDoneTime,
nsecs_t* outDisplayPresentTime, nsecs_t* outDisplayRetireTime,
nsecs_t* outDequeueReadyTime, nsecs_t* outReleaseTime);
- status_t getDisplayRefreshCycleDuration(nsecs_t* outRefreshDuration);
status_t getUniqueId(uint64_t* outId) const;
@@ -159,6 +164,7 @@
// Virtual for testing.
virtual sp<ISurfaceComposer> composerService() const;
+ virtual nsecs_t now() const;
private:
// can't be copied
@@ -206,10 +212,11 @@
int dispatchSetSurfaceDamage(va_list args);
int dispatchSetSharedBufferMode(va_list args);
int dispatchSetAutoRefresh(va_list args);
+ int dispatchGetDisplayRefreshCycleDuration(va_list args);
int dispatchGetNextFrameId(va_list args);
int dispatchEnableFrameTimestamps(va_list args);
+ int dispatchGetCompositorTiming(va_list args);
int dispatchGetFrameTimestamps(va_list args);
- int dispatchGetDisplayRefreshCycleDuration(va_list args);
protected:
virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);