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 // TODO(b/222698397): remove getSfInstance/this class usage and use vsyncId for transactions
28 public final class SfVsyncFrameCallbackProvider implements AnimationFrameCallbackProvider {
29 
30     private final Choreographer mChoreographer;
31 
SfVsyncFrameCallbackProvider()32     public SfVsyncFrameCallbackProvider() {
33         mChoreographer = Choreographer.getSfInstance();
34     }
35 
SfVsyncFrameCallbackProvider(Choreographer choreographer)36     public SfVsyncFrameCallbackProvider(Choreographer choreographer) {
37         mChoreographer = choreographer;
38     }
39 
40     @Override
postFrameCallback(Choreographer.FrameCallback callback)41     public void postFrameCallback(Choreographer.FrameCallback callback) {
42         mChoreographer.postFrameCallback(callback);
43     }
44 
45     @Override
postCommitCallback(Runnable runnable)46     public void postCommitCallback(Runnable runnable) {
47         mChoreographer.postCallback(Choreographer.CALLBACK_COMMIT, runnable, null);
48     }
49 
50     @Override
getFrameTime()51     public long getFrameTime() {
52         return mChoreographer.getFrameTime();
53     }
54 
55     @Override
getFrameDelay()56     public long getFrameDelay() {
57         return Choreographer.getFrameDelay();
58     }
59 
60     @Override
setFrameDelay(long delay)61     public void setFrameDelay(long delay) {
62         Choreographer.setFrameDelay(delay);
63     }
64 }