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/opengl/include/EGL/eglext.h b/opengl/include/EGL/eglext.h
index 6485ae5..6572cab 100644
--- a/opengl/include/EGL/eglext.h
+++ b/opengl/include/EGL/eglext.h
@@ -632,24 +632,31 @@
#ifndef EGL_ANDROID_get_frame_timestamps
#define EGL_ANDROID_get_frame_timestamps 1
#define EGL_TIMESTAMPS_ANDROID 0x314D
-#define EGL_REQUESTED_PRESENT_TIME_ANDROID 0x314E
-#define EGL_RENDERING_COMPLETE_TIME_ANDROID 0x314F
-#define EGL_COMPOSITION_LATCH_TIME_ANDROID 0x3150
-#define EGL_FIRST_COMPOSITION_START_TIME_ANDROID 0x3151
-#define EGL_LAST_COMPOSITION_START_TIME_ANDROID 0x3152
-#define EGL_FIRST_COMPOSITION_FINISHED_TIME_ANDROID 0x3153
-#define EGL_DISPLAY_PRESENT_TIME_ANDROID 0x3154
-#define EGL_DISPLAY_RETIRE_TIME_ANDROID 0x3155
-#define EGL_DEQUEUE_READY_TIME_ANDROID 0x3156
-#define EGL_READS_DONE_TIME_ANDROID 0x3157
+#define EGL_COMPOSITE_DEADLINE_ANDROID 0x314E
+#define EGL_COMPOSITE_INTERVAL_ANDROID 0x314F
+#define EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID 0x3150
+#define EGL_REQUESTED_PRESENT_TIME_ANDROID 0x3151
+#define EGL_RENDERING_COMPLETE_TIME_ANDROID 0x3152
+#define EGL_COMPOSITION_LATCH_TIME_ANDROID 0x3153
+#define EGL_FIRST_COMPOSITION_START_TIME_ANDROID 0x3154
+#define EGL_LAST_COMPOSITION_START_TIME_ANDROID 0x3155
+#define EGL_FIRST_COMPOSITION_FINISHED_TIME_ANDROID 0x3156
+#define EGL_DISPLAY_PRESENT_TIME_ANDROID 0x3157
+#define EGL_DISPLAY_RETIRE_TIME_ANDROID 0x3158
+#define EGL_DEQUEUE_READY_TIME_ANDROID 0x3159
+#define EGL_READS_DONE_TIME_ANDROID 0x315A
#ifdef EGL_EGLEXT_PROTOTYPES
EGLAPI EGLBoolean eglGetNextFrameIdANDROID(EGLDisplay dpy, EGLSurface surface, EGLuint64KHR *frameId);
+EGLAPI EGLBoolean eglGetCompositorTimingANDROID(EGLDisplay dpy, EGLSurface surface, EGLint numTimestamps, const EGLint *names, EGLnsecsANDROID *values);
+EGLAPI EGLBoolean eglGetCompositorTimingSupportedANDROID(EGLDisplay dpy, EGLSurface surface, EGLint name);
EGLAPI EGLBoolean eglGetFrameTimestampsANDROID(EGLDisplay dpy, EGLSurface surface, EGLuint64KHR frameId, EGLint numTimestamps, const EGLint *timestamps, EGLnsecsANDROID *values);
-EGLAPI EGLBoolean eglQueryTimestampSupportedANDROID(EGLDisplay dpy, EGLSurface surface, EGLint timestamp);
+EGLAPI EGLBoolean eglGetFrameTimestampSupportedANDROID(EGLDisplay dpy, EGLSurface surface, EGLint timestamp);
#else
typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETNEXTFRAMEIDANDROID) (EGLDisplay dpy, EGLSurface surface, EGLuint64KHR *frameId);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETCOMPOSITORTIMINGANDROID) (EGLDisplay dpy, EGLSurface surface, EGLint numTimestamps, const EGLint *names, EGLnsecsANDROID *values);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETCOMPOSITORTIMINGSUPPORTEDANDROID) (EGLDisplay dpy, EGLSurface surface, EGLint name);
typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETFRAMETIMESTAMPSANDROID) (EGLDisplay dpy, EGLSurface surface, EGLuint64KHR frameId, EGLint numTimestamps, const EGLint *timestamps, EGLnsecsANDROID *values);
-typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYTIMESTAMPSUPPORTEDANDROID) (EGLDisplay dpy, EGLSurface surface, EGLint timestamp);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLGETFRAMETIMESTAMPSUPPORTEDANDROID) (EGLDisplay dpy, EGLSurface surface, EGLint timestamp);
#endif
#endif
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index c2fc6bd..42d01b2 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -218,10 +218,14 @@
// EGL_ANDROID_get_frame_timestamps
{ "eglGetNextFrameIdANDROID",
(__eglMustCastToProperFunctionPointerType)&eglGetNextFrameIdANDROID },
+ { "eglGetCompositorTimingANDROID",
+ (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingANDROID },
+ { "eglGetCompositorTimingSupportedANDROID",
+ (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingSupportedANDROID },
{ "eglGetFrameTimestampsANDROID",
(__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampsANDROID },
- { "eglQueryTimestampSupportedANDROID",
- (__eglMustCastToProperFunctionPointerType)&eglQueryTimestampSupportedANDROID },
+ { "eglGetFrameTimestampSupportedANDROID",
+ (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampSupportedANDROID },
};
/*
@@ -2078,6 +2082,97 @@
return EGL_TRUE;
}
+EGLBoolean eglGetCompositorTimingANDROID(EGLDisplay dpy, EGLSurface surface,
+ EGLint numTimestamps, const EGLint *names, EGLnsecsANDROID *values)
+{
+ clearError();
+
+ const egl_display_ptr dp = validate_display(dpy);
+ if (!dp) {
+ return setError(EGL_BAD_DISPLAY, EGL_FALSE);
+ }
+
+ SurfaceRef _s(dp.get(), surface);
+ if (!_s.get()) {
+ return setError(EGL_BAD_SURFACE, EGL_FALSE);
+ }
+
+ egl_surface_t const * const s = get_surface(surface);
+
+ if (!s->win.get()) {
+ return setError(EGL_BAD_SURFACE, EGL_FALSE);
+ }
+
+ nsecs_t* compositeDeadline = nullptr;
+ nsecs_t* compositeInterval = nullptr;
+ nsecs_t* compositeToPresentLatency = nullptr;
+
+ for (int i = 0; i < numTimestamps; i++) {
+ switch (names[i]) {
+ case EGL_COMPOSITE_DEADLINE_ANDROID:
+ compositeDeadline = &values[i];
+ break;
+ case EGL_COMPOSITE_INTERVAL_ANDROID:
+ compositeInterval = &values[i];
+ break;
+ case EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID:
+ compositeToPresentLatency = &values[i];
+ break;
+ default:
+ return setError(EGL_BAD_PARAMETER, EGL_FALSE);
+ }
+ }
+
+ status_t ret = native_window_get_compositor_timing(s->win.get(),
+ compositeDeadline, compositeInterval, compositeToPresentLatency);
+
+ switch (ret) {
+ case NO_ERROR:
+ return EGL_TRUE;
+ case INVALID_OPERATION:
+ return setError(EGL_BAD_SURFACE, EGL_FALSE);
+ default:
+ // This should not happen. Return an error that is not in the spec
+ // so it's obvious something is very wrong.
+ ALOGE("eglGetCompositorTiming: Unexpected error.");
+ return setError(EGL_NOT_INITIALIZED, EGL_FALSE);
+ }
+}
+
+EGLBoolean eglGetCompositorTimingSupportedANDROID(
+ EGLDisplay dpy, EGLSurface surface, EGLint name)
+{
+ clearError();
+
+ const egl_display_ptr dp = validate_display(dpy);
+ if (!dp) {
+ return setError(EGL_BAD_DISPLAY, EGL_FALSE);
+ }
+
+ SurfaceRef _s(dp.get(), surface);
+ if (!_s.get()) {
+ return setError(EGL_BAD_SURFACE, EGL_FALSE);
+ }
+
+ egl_surface_t const * const s = get_surface(surface);
+
+ ANativeWindow* window = s->win.get();
+ if (!window) {
+ return setError(EGL_BAD_SURFACE, EGL_FALSE);
+ }
+
+ switch (name) {
+#if ENABLE_EGL_ANDROID_GET_FRAME_TIMESTAMPS
+ case EGL_COMPOSITE_DEADLINE_ANDROID:
+ case EGL_COMPOSITE_INTERVAL_ANDROID:
+ case EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID:
+ return EGL_TRUE;
+#endif
+ default:
+ return EGL_FALSE;
+ }
+}
+
EGLBoolean eglGetFrameTimestampsANDROID(EGLDisplay dpy, EGLSurface surface,
EGLuint64KHR frameId, EGLint numTimestamps, const EGLint *timestamps,
EGLnsecsANDROID *values)
@@ -2170,8 +2265,8 @@
}
}
-EGLBoolean eglQueryTimestampSupportedANDROID(EGLDisplay dpy, EGLSurface surface,
- EGLint timestamp)
+EGLBoolean eglGetFrameTimestampSupportedANDROID(
+ EGLDisplay dpy, EGLSurface surface, EGLint timestamp)
{
clearError();
@@ -2194,6 +2289,9 @@
switch (timestamp) {
#if ENABLE_EGL_ANDROID_GET_FRAME_TIMESTAMPS
+ case EGL_COMPOSITE_DEADLINE_ANDROID:
+ case EGL_COMPOSITE_INTERVAL_ANDROID:
+ case EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID:
case EGL_REQUESTED_PRESENT_TIME_ANDROID:
case EGL_RENDERING_COMPLETE_TIME_ANDROID:
case EGL_COMPOSITION_LATCH_TIME_ANDROID:
diff --git a/opengl/specs/EGL_ANDROID_get_frame_timestamps.txt b/opengl/specs/EGL_ANDROID_get_frame_timestamps.txt
index f24d634..f946418 100644
--- a/opengl/specs/EGL_ANDROID_get_frame_timestamps.txt
+++ b/opengl/specs/EGL_ANDROID_get_frame_timestamps.txt
@@ -60,26 +60,33 @@
EGLBoolean eglGetNextFrameIdANDROID(EGLDisplay dpy, EGLSurface surface,
EGLuint64KHR *frameId);
+ EGLBoolean eglGetCompositorTimingANDROID(EGLDisplay dpy,
+ EGLSurface surface, EGLint numTimestamps,
+ const EGLint *names, EGLnsecsANDROID *values);
+
EGLBoolean eglGetFrameTimestampsANDROID(EGLDisplay dpy, EGLSurface surface,
EGLuint64KHR frameId, EGLint numTimestamps,
const EGLint *timestamps, EGLnsecsANDROID *values);
- EGLBoolean eglQueryTimestampSupportedANDROID(EGLDisplay dpy, EGLSurface
- surface, EGLint timestamp);
+ EGLBoolean eglQueryTimestampSupportedANDROID(EGLDisplay dpy,
+ EGLSurface surface, EGLint timestamp);
New Tokens
EGL_TIMESTAMPS_ANDROID 0x314D
- EGL_REQUESTED_PRESENT_TIME_ANDROID 0x314E
- EGL_RENDERING_COMPLETE_TIME_ANDROID 0x314F
- EGL_COMPOSITION_LATCH_TIME_ANDROID 0x3150
- EGL_FIRST_COMPOSITION_START_TIME_ANDROID 0x3151
- EGL_LAST_COMPOSITION_START_TIME_ANDROID 0x3152
- EGL_FIRST_COMPOSITION_FINISHED_TIME_ANDROID 0x3153
- EGL_DISPLAY_PRESENT_TIME_ANDROID 0x3154
- EGL_DISPLAY_RETIRE_TIME_ANDROID 0x3155
- EGL_DEQUEUE_READY_TIME_ANDROID 0x3156
- EGL_READS_DONE_TIME_ANDROID 0x3157
+ EGL_COMPOSITE_DEADLINE_ANDROID 0x314E
+ EGL_COMPOSITE_INTERVAL_ANDROID 0x314F
+ EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID 0x3150
+ EGL_REQUESTED_PRESENT_TIME_ANDROID 0x3151
+ EGL_RENDERING_COMPLETE_TIME_ANDROID 0x3152
+ EGL_COMPOSITION_LATCH_TIME_ANDROID 0x3153
+ EGL_FIRST_COMPOSITION_START_TIME_ANDROID 0x3154
+ EGL_LAST_COMPOSITION_START_TIME_ANDROID 0x3155
+ EGL_FIRST_COMPOSITION_FINISHED_TIME_ANDROID 0x3156
+ EGL_DISPLAY_PRESENT_TIME_ANDROID 0x3157
+ EGL_DISPLAY_RETIRE_TIME_ANDROID 0x3158
+ EGL_DEQUEUE_READY_TIME_ANDROID 0x3159
+ EGL_READS_DONE_TIME_ANDROID 0x315A
Add to the list of supported tokens for eglSurfaceAttrib in section 3.5.6
"Surface Attributes", page 43:
@@ -108,6 +115,29 @@
The function
+ EGLBoolean eglGetCompositorTimingANDROID(EGLDisplay dpy,
+ EGLSurface surface, EGLint numTimestamps,
+ const EGLint *names, EGLnsecsANDROID *values);
+
+ allows querying anticipated timestamps and durations related to the
+ composition and display of a window surface. The values are not associated
+ with a particular frame and can be retrieved before the first swap.
+
+ The eglGetCompositorTimingANDROID function takes an array of names to
+ query and returns their values in the corresponding indices of the values
+ array. The possible names that can be queried are:
+ - EGL_COMPOSITE_DEADLINE_ANDROID - The timestamp of the next time the
+ compositor will begin composition. This is effectively the deadline
+ for when the compositor must receive a newly queued frame.
+ - EGL_COMPOSITE_INTERVAL_ANDROID - The time delta between subsequent
+ composition events.
+ - EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID - The time delta between
+ the start of composition and the expected present time of that
+ composition. This can be used to estimate the latency of the
+ actual present time.
+
+ The function
+
EGLBoolean eglGetFrameTimestampsANDROID(EGLDisplay dpy,
EGLSurface surface, EGLuint64KHR frameId, EGLint numTimestamps,
const EGLint *timestamps, EGLnsecsANDROID *values);
@@ -162,12 +192,19 @@
purpose of display/composition were completed for this frame.
Not all implementations may support all of the above timestamp queries. The
- function
+ functions
- EGLBoolean eglQueryTimestampSupportedANDROID(EGLDisplay dpy, EGLSurface
- surface, EGLint timestamp);
+ EGLBoolean eglGetCompositorTimingSupportedANDROID(EGLDisplay dpy,
+ EGLSurface surface, EGLint name);
- allows querying which timestamps are supported on the implementation."
+ and
+
+ EGLBoolean eglGetFrameTimestampsSupportedANDROID(EGLDisplay dpy,
+ EGLSurface surface, EGLint timestamp);
+
+ allows querying which values are supported by the implementations of
+ eglGetCompositoTimingANDROID and eglGetFrameTimestampsSupportedANDROID
+ respectively."
Issues
@@ -189,3 +226,6 @@
#4 (Brian Anderson, January 10, 2017)
- Use an absolute frameId rather than a relative framesAgo.
+
+#5 (Brian Anderson, January 13, 2017)
+ - Add eglGetCompositorTimingANDROID.
diff --git a/opengl/specs/README b/opengl/specs/README
index 1853214..0c49023 100644
--- a/opengl/specs/README
+++ b/opengl/specs/README
@@ -20,14 +20,17 @@
0x314B EGL_IMAGE_CROP_BOTTOM_ANDROID (EGL_ANDROID_image_crop)
0x314C EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID (EGL_ANDROID_front_buffer_auto_refresh)
0x314D EGL_TIMESTAMPS_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x314E EGL_REQUESTED_PRESENT_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x314F EGL_RENDERING_COMPLETE_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x3150 EGL_COMPOSITION_LATCH_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x3151 EGL_FIRST_COMPOSITION_START_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x3152 EGL_LAST_COMPOSITION_START_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x3153 EGL_FIRST_COMPOSITION_FINISHED_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x3154 EGL_DISPLAY_PRESENT_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x3155 EGL_DISPLAY_RETIRE_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x3156 EGL_DEQUEUE_READY_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x3157 EGL_READS_DONE_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
-0x3158 - 0x315F (unused)
+0x314E EGL_COMPOSITE_DEADLINE_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x314F EGL_COMPOSITE_INTERVAL_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3150 EGL_COMPOSITE_TO_PRESENT_LATENCY_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3151 EGL_REQUESTED_PRESENT_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3152 EGL_RENDERING_COMPLETE_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3153 EGL_COMPOSITION_LATCH_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3154 EGL_FIRST_COMPOSITION_START_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3155 EGL_LAST_COMPOSITION_START_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3156 EGL_FIRST_COMPOSITION_FINISHED_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3157 EGL_DISPLAY_PRESENT_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3158 EGL_DISPLAY_RETIRE_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x3159 EGL_DEQUEUE_READY_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x315A EGL_READS_DONE_TIME_ANDROID (EGL_ANDROID_get_frame_timestamps)
+0x315B - 0x315F (unused)