1 /*
2  * Copyright 2020 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 #pragma once
18 
19 #include <apex/choreographer.h>
20 #include <inttypes.h>
21 #include <jni.h>
22 
23 namespace android {
24 
25 // Registers the global JVM for AChoreographer
26 void AChoreographer_initJVM(JNIEnv* env);
27 
28 // Signals all AChoregorapher* instances that a new vsync period is available
29 // for consumption by callbacks.
30 void AChoreographer_signalRefreshRateCallbacks(int64_t vsyncPeriod);
31 
32 // Returns the vsync id of the last frame callback. Client are expected to call
33 // this function from their frame callback function to get the vsyncId and pass
34 // it together with a buffer or transaction to the Surface Composer. Calling
35 // this function from anywhere else will return an undefined value.
36 int64_t AChoreographer_getVsyncId(const AChoreographer* choreographer);
37 
38 // Returns the deadline timestamp (in CLOCK_MONOTONIC) of the last frame callback.
39 // Client are expected to call this function from their frame callback function
40 // to get the deadline and use it to know whether a frame is likely to miss
41 // presentation. Calling this function from anywhere else will return an undefined
42 // value.
43 int64_t AChoreographer_getFrameDeadline(const AChoreographer* choreographer);
44 
45 // Returns the current interval in ns between frames.
46 // Client are expected to call this function from their frame callback function.
47 // Calling this function from anywhere else will return an undefined value.
48 int64_t AChoreographer_getFrameInterval(const AChoreographer* choreographer);
49 
50 // Trampoline functions allowing libandroid.so to define the NDK symbols without including
51 // the entirety of libnativedisplay as a whole static lib. As libnativedisplay
52 // maintains global state, libnativedisplay can never be directly statically
53 // linked so that global state won't be duplicated. This way libandroid.so can
54 // reroute the NDK methods into the implementations defined by libnativedisplay
55 AChoreographer* AChoreographer_routeGetInstance();
56 void AChoreographer_routePostFrameCallback(AChoreographer* choreographer,
57                                            AChoreographer_frameCallback callback, void* data);
58 void AChoreographer_routePostFrameCallbackDelayed(AChoreographer* choreographer,
59                                                   AChoreographer_frameCallback callback, void* data,
60                                                   long delayMillis);
61 void AChoreographer_routePostFrameCallback64(AChoreographer* choreographer,
62                                              AChoreographer_frameCallback64 callback, void* data);
63 void AChoreographer_routePostFrameCallbackDelayed64(AChoreographer* choreographer,
64                                                     AChoreographer_frameCallback64 callback,
65                                                     void* data, uint32_t delayMillis);
66 void AChoreographer_routeRegisterRefreshRateCallback(AChoreographer* choreographer,
67                                                      AChoreographer_refreshRateCallback callback,
68                                                      void* data);
69 void AChoreographer_routeUnregisterRefreshRateCallback(AChoreographer* choreographer,
70                                                        AChoreographer_refreshRateCallback callback,
71                                                        void* data);
72 
73 } // namespace android
74