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 @android.ravenwood.annotation.RavenwoodKeepWholeClass 42 public final class FrameInfo { 43 44 public long[] frameInfo = new long[FRAME_INFO_SIZE]; 45 46 // Various flags set to provide extra metadata about the current frame 47 public static final int FLAGS = 0; 48 49 // Is this the first-draw following a window layout? 50 public static final long FLAG_WINDOW_VISIBILITY_CHANGED = 1; 51 52 // A renderer associated with just a Surface, not with a ViewRootImpl instance. 53 public static final long FLAG_SURFACE_CANVAS = 1 << 2; 54 55 // An invalid vsync id to be used when FRAME_TIMELINE_VSYNC_ID is unknown 56 // Needs to be in sync with android::ISurfaceComposer::INVALID_VSYNC_ID in native code 57 public static final long INVALID_VSYNC_ID = -1; 58 59 @LongDef(flag = true, value = { 60 FLAG_WINDOW_VISIBILITY_CHANGED, FLAG_SURFACE_CANVAS }) 61 @Retention(RetentionPolicy.SOURCE) 62 public @interface FrameInfoFlags {} 63 64 public static final int FRAME_TIMELINE_VSYNC_ID = 1; 65 66 // The intended vsync time, unadjusted by jitter 67 public static final int INTENDED_VSYNC = 2; 68 69 // Jitter-adjusted vsync time, this is what was used as input into the 70 // animation & drawing system 71 public static final int VSYNC = 3; 72 73 // The id of the input event that caused the current frame 74 public static final int INPUT_EVENT_ID = 4; 75 76 // When input event handling started 77 public static final int HANDLE_INPUT_START = 5; 78 79 // When animation evaluations started 80 public static final int ANIMATION_START = 6; 81 82 // When ViewRootImpl#performTraversals() started 83 public static final int PERFORM_TRAVERSALS_START = 7; 84 85 // When View:draw() started 86 public static final int DRAW_START = 8; 87 88 // When the frame needs to be ready by 89 public static final int FRAME_DEADLINE = 9; 90 91 // When frame actually started. 92 public static final int FRAME_START_TIME = 10; 93 94 // Interval between two consecutive frames 95 public static final int FRAME_INTERVAL = 11; 96 97 // Workload target deadline for a frame 98 public static final int WORKLOAD_TARGET = 12; 99 100 // Must be the last one 101 // This value must be in sync with `UI_THREAD_FRAME_INFO_SIZE` in FrameInfo.h 102 private static final int FRAME_INFO_SIZE = WORKLOAD_TARGET + 1; 103 104 /** checkstyle */ setVsync(long intendedVsync, long usedVsync, long frameTimelineVsyncId, long frameDeadline, long frameStartTime, long frameInterval)105 public void setVsync(long intendedVsync, long usedVsync, long frameTimelineVsyncId, 106 long frameDeadline, long frameStartTime, long frameInterval) { 107 frameInfo[FRAME_TIMELINE_VSYNC_ID] = frameTimelineVsyncId; 108 frameInfo[INTENDED_VSYNC] = intendedVsync; 109 frameInfo[VSYNC] = usedVsync; 110 frameInfo[FLAGS] = 0; 111 frameInfo[FRAME_DEADLINE] = frameDeadline; 112 frameInfo[FRAME_START_TIME] = frameStartTime; 113 frameInfo[FRAME_INTERVAL] = frameInterval; 114 frameInfo[WORKLOAD_TARGET] = frameDeadline - intendedVsync; 115 } 116 117 /** checkstyle */ markInputHandlingStart()118 public void markInputHandlingStart() { 119 frameInfo[HANDLE_INPUT_START] = System.nanoTime(); 120 } 121 122 /** checkstyle */ markAnimationsStart()123 public void markAnimationsStart() { 124 frameInfo[ANIMATION_START] = System.nanoTime(); 125 } 126 127 /** checkstyle */ markPerformTraversalsStart()128 public void markPerformTraversalsStart() { 129 frameInfo[PERFORM_TRAVERSALS_START] = System.nanoTime(); 130 } 131 132 /** checkstyle */ addFlags(@rameInfoFlags long flags)133 public void addFlags(@FrameInfoFlags long flags) { 134 frameInfo[FLAGS] |= flags; 135 } 136 } 137