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 current interval in ns between frames.
33 // Client are expected to call this function from their frame callback function.
34 // Calling this function from anywhere else will return an undefined value.
35 int64_t AChoreographer_getFrameInterval(const AChoreographer* choreographer);
36 
37 // Trampoline functions allowing libandroid.so to define the NDK symbols without including
38 // the entirety of libnativedisplay as a whole static lib. As libnativedisplay
39 // maintains global state, libnativedisplay can never be directly statically
40 // linked so that global state won't be duplicated. This way libandroid.so can
41 // reroute the NDK methods into the implementations defined by libnativedisplay
42 AChoreographer* AChoreographer_routeGetInstance();
43 void AChoreographer_routePostFrameCallback(AChoreographer* choreographer,
44                                            AChoreographer_frameCallback callback, void* data);
45 void AChoreographer_routePostFrameCallbackDelayed(AChoreographer* choreographer,
46                                                   AChoreographer_frameCallback callback, void* data,
47                                                   long delayMillis);
48 void AChoreographer_routePostFrameCallback64(AChoreographer* choreographer,
49                                              AChoreographer_frameCallback64 callback, void* data);
50 void AChoreographer_routePostFrameCallbackDelayed64(AChoreographer* choreographer,
51                                                     AChoreographer_frameCallback64 callback,
52                                                     void* data, uint32_t delayMillis);
53 void AChoreographer_routePostVsyncCallback(AChoreographer* choreographer,
54                                            AChoreographer_vsyncCallback callback, void* data);
55 void AChoreographer_routeRegisterRefreshRateCallback(AChoreographer* choreographer,
56                                                      AChoreographer_refreshRateCallback callback,
57                                                      void* data);
58 void AChoreographer_routeUnregisterRefreshRateCallback(AChoreographer* choreographer,
59                                                        AChoreographer_refreshRateCallback callback,
60                                                        void* data);
61 int64_t AChoreographerFrameCallbackData_routeGetFrameTimeNanos(
62         const AChoreographerFrameCallbackData* data);
63 size_t AChoreographerFrameCallbackData_routeGetFrameTimelinesLength(
64         const AChoreographerFrameCallbackData* data);
65 size_t AChoreographerFrameCallbackData_routeGetPreferredFrameTimelineIndex(
66         const AChoreographerFrameCallbackData* data);
67 AVsyncId AChoreographerFrameCallbackData_routeGetFrameTimelineVsyncId(
68         const AChoreographerFrameCallbackData* data, size_t index);
69 int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineExpectedPresentationTimeNanos(
70         const AChoreographerFrameCallbackData* data, size_t index);
71 int64_t AChoreographerFrameCallbackData_routeGetFrameTimelineDeadlineNanos(
72         const AChoreographerFrameCallbackData* data, size_t index);
73 
74 // Gets the start time (dispatch time) in nanos of the callback, given a vsync ID. This does not
75 // account for clients that use multiple choreographers, because callbacks that give the same vsync
76 // ID may be dispatched at different times.
77 int64_t AChoreographer_getStartTimeNanosForVsyncId(AVsyncId vsyncId);
78 
79 } // namespace android
80