• 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.view;
18 
19 import android.annotation.IntDef;
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  * continous-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 mFrameInfo 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 final class FrameInfo {
42 
43     long[] mFrameInfo = new long[9];
44 
45     // Various flags set to provide extra metadata about the current frame
46     private static final int FLAGS = 0;
47 
48     // Is this the first-draw following a window layout?
49     public static final long FLAG_WINDOW_LAYOUT_CHANGED = 1;
50 
51     @IntDef(flag = true, value = {
52             FLAG_WINDOW_LAYOUT_CHANGED })
53     @Retention(RetentionPolicy.SOURCE)
54     public @interface FrameInfoFlags {}
55 
56     // The intended vsync time, unadjusted by jitter
57     private static final int INTENDED_VSYNC = 1;
58 
59     // Jitter-adjusted vsync time, this is what was used as input into the
60     // animation & drawing system
61     private static final int VSYNC = 2;
62 
63     // The time of the oldest input event
64     private static final int OLDEST_INPUT_EVENT = 3;
65 
66     // The time of the newest input event
67     private static final int NEWEST_INPUT_EVENT = 4;
68 
69     // When input event handling started
70     private static final int HANDLE_INPUT_START = 5;
71 
72     // When animation evaluations started
73     private static final int ANIMATION_START = 6;
74 
75     // When ViewRootImpl#performTraversals() started
76     private static final int PERFORM_TRAVERSALS_START = 7;
77 
78     // When View:draw() started
79     private static final int DRAW_START = 8;
80 
setVsync(long intendedVsync, long usedVsync)81     public void setVsync(long intendedVsync, long usedVsync) {
82         mFrameInfo[INTENDED_VSYNC] = intendedVsync;
83         mFrameInfo[VSYNC] = usedVsync;
84         mFrameInfo[OLDEST_INPUT_EVENT] = Long.MAX_VALUE;
85         mFrameInfo[NEWEST_INPUT_EVENT] = 0;
86         mFrameInfo[FLAGS] = 0;
87     }
88 
updateInputEventTime(long inputEventTime, long inputEventOldestTime)89     public void updateInputEventTime(long inputEventTime, long inputEventOldestTime) {
90         if (inputEventOldestTime < mFrameInfo[OLDEST_INPUT_EVENT]) {
91             mFrameInfo[OLDEST_INPUT_EVENT] = inputEventOldestTime;
92         }
93         if (inputEventTime > mFrameInfo[NEWEST_INPUT_EVENT]) {
94             mFrameInfo[NEWEST_INPUT_EVENT] = inputEventTime;
95         }
96     }
97 
markInputHandlingStart()98     public void markInputHandlingStart() {
99         mFrameInfo[HANDLE_INPUT_START] = System.nanoTime();
100     }
101 
markAnimationsStart()102     public void markAnimationsStart() {
103         mFrameInfo[ANIMATION_START] = System.nanoTime();
104     }
105 
markPerformTraversalsStart()106     public void markPerformTraversalsStart() {
107         mFrameInfo[PERFORM_TRAVERSALS_START] = System.nanoTime();
108     }
109 
markDrawStart()110     public void markDrawStart() {
111         mFrameInfo[DRAW_START] = System.nanoTime();
112     }
113 
addFlags(@rameInfoFlags long flags)114     public void addFlags(@FrameInfoFlags long flags) {
115         mFrameInfo[FLAGS] |= flags;
116     }
117 
118 }
119