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