1 /* 2 * Copyright (C) 2017 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 com.android.internal.graphics; 18 19 import android.animation.AnimationHandler.AnimationFrameCallbackProvider; 20 import android.view.Choreographer; 21 22 /** 23 * Provider of timing pulse that uses SurfaceFlinger Vsync Choreographer for frame callbacks. 24 * 25 * @hide 26 */ 27 public final class SfVsyncFrameCallbackProvider implements AnimationFrameCallbackProvider { 28 29 private final Choreographer mChoreographer; 30 SfVsyncFrameCallbackProvider()31 public SfVsyncFrameCallbackProvider() { 32 mChoreographer = Choreographer.getSfInstance(); 33 } 34 SfVsyncFrameCallbackProvider(Choreographer choreographer)35 public SfVsyncFrameCallbackProvider(Choreographer choreographer) { 36 mChoreographer = choreographer; 37 } 38 39 @Override postFrameCallback(Choreographer.FrameCallback callback)40 public void postFrameCallback(Choreographer.FrameCallback callback) { 41 mChoreographer.postFrameCallback(callback); 42 } 43 44 @Override postCommitCallback(Runnable runnable)45 public void postCommitCallback(Runnable runnable) { 46 mChoreographer.postCallback(Choreographer.CALLBACK_COMMIT, runnable, null); 47 } 48 49 @Override getFrameTime()50 public long getFrameTime() { 51 return mChoreographer.getFrameTime(); 52 } 53 54 @Override getFrameDelay()55 public long getFrameDelay() { 56 return Choreographer.getFrameDelay(); 57 } 58 59 @Override setFrameDelay(long delay)60 public void setFrameDelay(long delay) { 61 Choreographer.setFrameDelay(delay); 62 } 63 }