From f4c2a52be31fe94b281dce1f902145b144cc32a0 Mon Sep 17 00:00:00 2001 From: Bryan Cassell Date: Wed, 22 Feb 2017 08:09:50 -0800 Subject: [PATCH] Added VSYNC and INTENDED_VSYNC timestamps to FrameMetrics API. BUG: b/31650117 Test: cts-tradefed run singleCommand cts --skip-device-info --skip-preconditions -m CtsViewTestCases -t android.view.cts.FrameMetricsListenerTest Change-Id: I8341809b6dac420859dad8c21f30d4ee8897425d --- api/current.txt | 2 ++ api/system-current.txt | 2 ++ api/test-current.txt | 2 ++ core/java/android/view/FrameMetrics.java | 28 +++++++++++++++++++++++- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/api/current.txt b/api/current.txt index 6d71f441fdcfc..487a856e0f7c8 100644 --- a/api/current.txt +++ b/api/current.txt @@ -43115,11 +43115,13 @@ package android.view { field public static final int DRAW_DURATION = 4; // 0x4 field public static final int FIRST_DRAW_FRAME = 9; // 0x9 field public static final int INPUT_HANDLING_DURATION = 1; // 0x1 + field public static final int INTENDED_VSYNC_TIMESTAMP = 10; // 0xa field public static final int LAYOUT_MEASURE_DURATION = 3; // 0x3 field public static final int SWAP_BUFFERS_DURATION = 7; // 0x7 field public static final int SYNC_DURATION = 5; // 0x5 field public static final int TOTAL_DURATION = 8; // 0x8 field public static final int UNKNOWN_DELAY_DURATION = 0; // 0x0 + field public static final int VSYNC_TIMESTAMP = 11; // 0xb } public abstract class FrameStats { diff --git a/api/system-current.txt b/api/system-current.txt index 8413036182df4..b97623dce39e8 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -46660,11 +46660,13 @@ package android.view { field public static final int DRAW_DURATION = 4; // 0x4 field public static final int FIRST_DRAW_FRAME = 9; // 0x9 field public static final int INPUT_HANDLING_DURATION = 1; // 0x1 + field public static final int INTENDED_VSYNC_TIMESTAMP = 10; // 0xa field public static final int LAYOUT_MEASURE_DURATION = 3; // 0x3 field public static final int SWAP_BUFFERS_DURATION = 7; // 0x7 field public static final int SYNC_DURATION = 5; // 0x5 field public static final int TOTAL_DURATION = 8; // 0x8 field public static final int UNKNOWN_DELAY_DURATION = 0; // 0x0 + field public static final int VSYNC_TIMESTAMP = 11; // 0xb } public abstract class FrameStats { diff --git a/api/test-current.txt b/api/test-current.txt index 00a83394df36e..9219b3d8435a5 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -43468,11 +43468,13 @@ package android.view { field public static final int DRAW_DURATION = 4; // 0x4 field public static final int FIRST_DRAW_FRAME = 9; // 0x9 field public static final int INPUT_HANDLING_DURATION = 1; // 0x1 + field public static final int INTENDED_VSYNC_TIMESTAMP = 10; // 0xa field public static final int LAYOUT_MEASURE_DURATION = 3; // 0x3 field public static final int SWAP_BUFFERS_DURATION = 7; // 0x7 field public static final int SYNC_DURATION = 5; // 0x5 field public static final int TOTAL_DURATION = 8; // 0x8 field public static final int UNKNOWN_DELAY_DURATION = 0; // 0x0 + field public static final int VSYNC_TIMESTAMP = 11; // 0xb } public abstract class FrameStats { diff --git a/core/java/android/view/FrameMetrics.java b/core/java/android/view/FrameMetrics.java index 92f0e8f81f119..358a2d1e70d8a 100644 --- a/core/java/android/view/FrameMetrics.java +++ b/core/java/android/view/FrameMetrics.java @@ -132,6 +132,26 @@ public final class FrameMetrics { */ public static final int FIRST_DRAW_FRAME = 9; + /** + * Metric identifier for the timestamp of the intended vsync for this frame. + *

+ * The intended start point for the frame. If this value is different from + * {@link #VSYNC_TIMESTAMP}, there was work occurring on the UI thread that + * prevented it from responding to the vsync signal in a timely fashion. + *

+ */ + public static final int INTENDED_VSYNC_TIMESTAMP = 10; + + /** + * Metric identifier for the timestamp of the actual vsync for this frame. + *

+ * The time value that was used in all the vsync listeners and drawing for + * the frame (Choreographer frame callbacks, animations, + * {@link View#getDrawingTime()}, etc…) + *

+ */ + public static final int VSYNC_TIMESTAMP = 11; + private static final int FRAME_INFO_FLAG_FIRST_DRAW = 1 << 0; /** @@ -151,6 +171,8 @@ public final class FrameMetrics { SWAP_BUFFERS_DURATION, TOTAL_DURATION, FIRST_DRAW_FRAME, + INTENDED_VSYNC_TIMESTAMP, + VSYNC_TIMESTAMP, }) @Retention(RetentionPolicy.SOURCE) public @interface Metric {} @@ -261,7 +283,7 @@ public final class FrameMetrics { * @return the value of the metric or -1 if it is not available. */ public long getMetric(@Metric int id) { - if (id < UNKNOWN_DELAY_DURATION || id > FIRST_DRAW_FRAME) { + if (id < UNKNOWN_DELAY_DURATION || id > VSYNC_TIMESTAMP) { return -1; } @@ -271,6 +293,10 @@ public final class FrameMetrics { if (id == FIRST_DRAW_FRAME) { return (mTimingData[Index.FLAGS] & FRAME_INFO_FLAG_FIRST_DRAW) != 0 ? 1 : 0; + } else if (id == INTENDED_VSYNC_TIMESTAMP) { + return mTimingData[Index.INTENDED_VSYNC]; + } else if (id == VSYNC_TIMESTAMP) { + return mTimingData[Index.VSYNC]; } int durationsIdx = 2 * id;