1 /*
2  * Copyright (C) 2014 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.os.Parcel;
20 import android.os.Parcelable;
21 
22 /**
23  * This is the base class for frame statistics.
24  */
25 public abstract class FrameStats {
26     /**
27      * Undefined time.
28      */
29     public static final long UNDEFINED_TIME_NANO = -1;
30 
31     /** @hide */
32     protected long mRefreshPeriodNano;
33 
34     /** @hide */
35     protected long[] mFramesPresentedTimeNano;
36 
37     /**
38      * Gets the refresh period of the display hosting the window(s) for
39      * which these statistics apply.
40      *
41      * @return The refresh period in nanoseconds.
42      */
getRefreshPeriodNano()43     public final long getRefreshPeriodNano() {
44         return mRefreshPeriodNano;
45     }
46 
47     /**
48      * Gets the number of frames for which there is data.
49      *
50      * @return The number of frames.
51      */
getFrameCount()52     public final int getFrameCount() {
53         return mFramesPresentedTimeNano != null
54                 ? mFramesPresentedTimeNano.length : 0;
55     }
56 
57     /**
58      * Gets the start time of the interval for which these statistics
59      * apply. The start interval is the time when the first frame was
60      * presented.
61      *
62      * @return The start time in nanoseconds or {@link #UNDEFINED_TIME_NANO}
63      *         if there is no frame data.
64      */
getStartTimeNano()65     public final long getStartTimeNano() {
66         if (getFrameCount() <= 0) {
67             return UNDEFINED_TIME_NANO;
68         }
69         return mFramesPresentedTimeNano[0];
70     }
71 
72     /**
73      * Gets the end time of the interval for which these statistics
74      * apply. The end interval is the time when the last frame was
75      * presented.
76      *
77      * @return The end time in nanoseconds or {@link #UNDEFINED_TIME_NANO}
78      *         if there is no frame data.
79      */
getEndTimeNano()80     public final long getEndTimeNano() {
81         if (getFrameCount() <= 0) {
82             return UNDEFINED_TIME_NANO;
83         }
84         return mFramesPresentedTimeNano[mFramesPresentedTimeNano.length - 1];
85     }
86 
87     /**
88      * Get the time a frame at a given index was presented.
89      *
90      * @param index The frame index.
91      * @return The presented time in nanoseconds or {@link #UNDEFINED_TIME_NANO}
92      *         if the frame is not presented yet.
93      */
getFramePresentedTimeNano(int index)94     public final long getFramePresentedTimeNano(int index) {
95         if (mFramesPresentedTimeNano == null) {
96             throw new IndexOutOfBoundsException();
97         }
98         return mFramesPresentedTimeNano[index];
99     }
100 }
101