Svetoslav | 1376d60 | 2014-03-13 11:17:26 -0700 | [diff] [blame] | 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 class contains window animation frame statistics. For example, a window |
| 24 | * animation is usually performed when the application is transitioning from one |
| 25 | * activity to another. The frame statistics are a snapshot for the time interval |
| 26 | * from {@link #getStartTimeNano()} to {@link #getEndTimeNano()}. |
| 27 | * <p> |
| 28 | * The key idea is that in order to provide a smooth user experience the system should |
| 29 | * run window animations at a specific time interval obtained by calling {@link |
| 30 | * #getRefreshPeriodNano()}. If the system does not render a frame every refresh |
| 31 | * period the user will see irregular window transitions. The time when the frame was |
| 32 | * actually presented on the display by calling {@link #getFramePresentedTimeNano(int)}. |
| 33 | */ |
| 34 | public final class WindowAnimationFrameStats extends FrameStats implements Parcelable { |
| 35 | /** |
| 36 | * @hide |
| 37 | */ |
| 38 | public WindowAnimationFrameStats() { |
| 39 | /* do nothing */ |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Initializes this isntance. |
| 44 | * |
| 45 | * @param refreshPeriodNano The display refresh period. |
| 46 | * @param framesPresentedTimeNano The presented frame times. |
| 47 | * |
| 48 | * @hide |
| 49 | */ |
| 50 | public void init(long refreshPeriodNano, long[] framesPresentedTimeNano) { |
| 51 | mRefreshPeriodNano = refreshPeriodNano; |
| 52 | mFramesPresentedTimeNano = framesPresentedTimeNano; |
| 53 | } |
| 54 | |
| 55 | private WindowAnimationFrameStats(Parcel parcel) { |
| 56 | mRefreshPeriodNano = parcel.readLong(); |
| 57 | mFramesPresentedTimeNano = parcel.createLongArray(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public int describeContents() { |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void writeToParcel(Parcel parcel, int flags) { |
| 67 | parcel.writeLong(mRefreshPeriodNano); |
| 68 | parcel.writeLongArray(mFramesPresentedTimeNano); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public String toString() { |
| 73 | StringBuilder builder = new StringBuilder(); |
| 74 | builder.append("WindowAnimationFrameStats["); |
| 75 | builder.append("frameCount:" + getFrameCount()); |
| 76 | builder.append(", fromTimeNano:" + getStartTimeNano()); |
| 77 | builder.append(", toTimeNano:" + getEndTimeNano()); |
| 78 | builder.append(']'); |
| 79 | return builder.toString(); |
| 80 | } |
| 81 | |
| 82 | public static final Creator<WindowAnimationFrameStats> CREATOR = |
| 83 | new Creator<WindowAnimationFrameStats>() { |
| 84 | @Override |
| 85 | public WindowAnimationFrameStats createFromParcel(Parcel parcel) { |
| 86 | return new WindowAnimationFrameStats(parcel); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public WindowAnimationFrameStats[] newArray(int size) { |
| 91 | return new WindowAnimationFrameStats[size]; |
| 92 | } |
| 93 | }; |
| 94 | } |