• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.graphics;
18 
19 import android.annotation.LongDef;
20 
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 
24 /**
25  * Class that contains all the timing information for the current frame. This
26  * is used in conjunction with the hardware renderer to provide
27  * continuous-monitoring jank events
28  *
29  * All times in nanoseconds from CLOCK_MONOTONIC/System.nanoTime()
30  *
31  * To minimize overhead from System.nanoTime() calls we infer durations of
32  * things by knowing the ordering of the events. For example, to know how
33  * long layout & measure took it's displayListRecordStart - performTraversalsStart.
34  *
35  * These constants must be kept in sync with FrameInfo.h in libhwui and are
36  * used for indexing into AttachInfo's frameInfo long[], which is intended
37  * to be quick to pass down to native via JNI, hence a pre-packed format
38  *
39  * @hide
40  */
41 public final class FrameInfo {
42 
43     public long[] frameInfo = new long[FRAME_INFO_SIZE];
44 
45     // Various flags set to provide extra metadata about the current frame
46     public static final int FLAGS = 0;
47 
48     // Is this the first-draw following a window layout?
49     public static final long FLAG_WINDOW_VISIBILITY_CHANGED = 1;
50 
51     // A renderer associated with just a Surface, not with a ViewRootImpl instance.
52     public static final long FLAG_SURFACE_CANVAS = 1 << 2;
53 
54     // An invalid vsync id to be used when FRAME_TIMELINE_VSYNC_ID is unknown
55     // Needs to be in sync with android::ISurfaceComposer::INVALID_VSYNC_ID in native code
56     public static final long INVALID_VSYNC_ID = -1;
57 
58     @LongDef(flag = true, value = {
59             FLAG_WINDOW_VISIBILITY_CHANGED, FLAG_SURFACE_CANVAS })
60     @Retention(RetentionPolicy.SOURCE)
61     public @interface FrameInfoFlags {}
62 
63     public static final int FRAME_TIMELINE_VSYNC_ID = 1;
64 
65     // The intended vsync time, unadjusted by jitter
66     public static final int INTENDED_VSYNC = 2;
67 
68     // Jitter-adjusted vsync time, this is what was used as input into the
69     // animation & drawing system
70     public static final int VSYNC = 3;
71 
72     // The id of the input event that caused the current frame
73     public static final int INPUT_EVENT_ID = 4;
74 
75     // When input event handling started
76     public static final int HANDLE_INPUT_START = 5;
77 
78     // When animation evaluations started
79     public static final int ANIMATION_START = 6;
80 
81     // When ViewRootImpl#performTraversals() started
82     public static final int PERFORM_TRAVERSALS_START = 7;
83 
84     // When View:draw() started
85     public static final int DRAW_START = 8;
86 
87     // When the frame needs to be ready by
88     public static final int FRAME_DEADLINE = 9;
89 
90     // When frame actually started.
91     public static final int FRAME_START_TIME = 10;
92 
93     // Interval between two consecutive frames
94     public static final int FRAME_INTERVAL = 11;
95 
96     // Must be the last one
97     // This value must be in sync with `UI_THREAD_FRAME_INFO_SIZE` in FrameInfo.h
98     private static final int FRAME_INFO_SIZE = FRAME_INTERVAL + 1;
99 
100     /** checkstyle */
setVsync(long intendedVsync, long usedVsync, long frameTimelineVsyncId, long frameDeadline, long frameStartTime, long frameInterval)101     public void setVsync(long intendedVsync, long usedVsync, long frameTimelineVsyncId,
102             long frameDeadline, long frameStartTime, long frameInterval) {
103         frameInfo[FRAME_TIMELINE_VSYNC_ID] = frameTimelineVsyncId;
104         frameInfo[INTENDED_VSYNC] = intendedVsync;
105         frameInfo[VSYNC] = usedVsync;
106         frameInfo[FLAGS] = 0;
107         frameInfo[FRAME_DEADLINE] = frameDeadline;
108         frameInfo[FRAME_START_TIME] = frameStartTime;
109         frameInfo[FRAME_INTERVAL] = frameInterval;
110     }
111 
112     /** checkstyle */
markInputHandlingStart()113     public void markInputHandlingStart() {
114         frameInfo[HANDLE_INPUT_START] = System.nanoTime();
115     }
116 
117     /** checkstyle */
markAnimationsStart()118     public void markAnimationsStart() {
119         frameInfo[ANIMATION_START] = System.nanoTime();
120     }
121 
122     /** checkstyle */
markPerformTraversalsStart()123     public void markPerformTraversalsStart() {
124         frameInfo[PERFORM_TRAVERSALS_START] = System.nanoTime();
125     }
126 
127     /** checkstyle */
addFlags(@rameInfoFlags long flags)128     public void addFlags(@FrameInfoFlags long flags) {
129         frameInfo[FLAGS] |= flags;
130     }
131 }
132