xref: /aosp_15_r20/frameworks/native/include/android/choreographer.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker /**
18*38e8c45fSAndroid Build Coastguard Worker  * @addtogroup Choreographer
19*38e8c45fSAndroid Build Coastguard Worker  *
20*38e8c45fSAndroid Build Coastguard Worker  * Choreographer coordinates the timing of frame rendering. This is the C
21*38e8c45fSAndroid Build Coastguard Worker  * version of the android.view.Choreographer object in Java. If you do not use
22*38e8c45fSAndroid Build Coastguard Worker  * Choreographer to pace your render loop, you may render too quickly for the
23*38e8c45fSAndroid Build Coastguard Worker  * display, increasing latency between frame submission and presentation.
24*38e8c45fSAndroid Build Coastguard Worker  *
25*38e8c45fSAndroid Build Coastguard Worker  * Input events are guaranteed to be processed before the frame callback is
26*38e8c45fSAndroid Build Coastguard Worker  * called, and will not be run concurrently. Input and sensor events should not
27*38e8c45fSAndroid Build Coastguard Worker  * be handled in the Choregrapher callback.
28*38e8c45fSAndroid Build Coastguard Worker  *
29*38e8c45fSAndroid Build Coastguard Worker  * The frame callback is also the appropriate place to run any per-frame state
30*38e8c45fSAndroid Build Coastguard Worker  * update logic. For example, in a game, the frame callback should be
31*38e8c45fSAndroid Build Coastguard Worker  * responsible for updating things like physics, AI, game state, and rendering
32*38e8c45fSAndroid Build Coastguard Worker  * the frame. Input and sensors should be handled separately via callbacks
33*38e8c45fSAndroid Build Coastguard Worker  * registered with AInputQueue and ASensorManager.
34*38e8c45fSAndroid Build Coastguard Worker  *
35*38e8c45fSAndroid Build Coastguard Worker  * As of API level 33, apps can follow proper frame pacing and even choose a future frame to render.
36*38e8c45fSAndroid Build Coastguard Worker  * The API is used as follows:
37*38e8c45fSAndroid Build Coastguard Worker  * 1. The app posts an {@link AChoreographer_vsyncCallback} to Choreographer to run on the next
38*38e8c45fSAndroid Build Coastguard Worker  * frame.
39*38e8c45fSAndroid Build Coastguard Worker  * 2. The callback is called when it is the time to start the frame with an {@link
40*38e8c45fSAndroid Build Coastguard Worker  * AChoreographerFrameCallbackData} payload: information about multiple possible frame
41*38e8c45fSAndroid Build Coastguard Worker  * timelines.
42*38e8c45fSAndroid Build Coastguard Worker  * 3. Apps can choose a frame timeline from the {@link
43*38e8c45fSAndroid Build Coastguard Worker  * AChoreographerFrameCallbackData} payload, depending on the frame deadline they can meet when
44*38e8c45fSAndroid Build Coastguard Worker  * rendering the frame and their desired presentation time, and subsequently
45*38e8c45fSAndroid Build Coastguard Worker  * {@link ASurfaceTransaction_setFrameTimeline notify SurfaceFlinger}
46*38e8c45fSAndroid Build Coastguard Worker  * of the choice. Alternatively, for apps that do not choose a frame timeline, their frame would be
47*38e8c45fSAndroid Build Coastguard Worker  * presented at the earliest possible timeline.
48*38e8c45fSAndroid Build Coastguard Worker  *   - The preferred frame timeline is the default frame
49*38e8c45fSAndroid Build Coastguard Worker  * timeline that the platform scheduled for the app, based on device configuration.
50*38e8c45fSAndroid Build Coastguard Worker  * 4. SurfaceFlinger attempts to follow the chosen frame timeline, by not applying transactions or
51*38e8c45fSAndroid Build Coastguard Worker  * latching buffers before the desired presentation time.
52*38e8c45fSAndroid Build Coastguard Worker  *
53*38e8c45fSAndroid Build Coastguard Worker  * On older devices, AChoreographer_postFrameCallback64 or
54*38e8c45fSAndroid Build Coastguard Worker  * AChoreographer_postFrameCallback can be used to lesser effect. They cannot be
55*38e8c45fSAndroid Build Coastguard Worker  * used to precisely plan your render timeline, but will rate limit to avoid
56*38e8c45fSAndroid Build Coastguard Worker  * overloading the display pipeline and increasing frame latency.
57*38e8c45fSAndroid Build Coastguard Worker  *
58*38e8c45fSAndroid Build Coastguard Worker  * @{
59*38e8c45fSAndroid Build Coastguard Worker  */
60*38e8c45fSAndroid Build Coastguard Worker 
61*38e8c45fSAndroid Build Coastguard Worker /**
62*38e8c45fSAndroid Build Coastguard Worker  * @file choreographer.h
63*38e8c45fSAndroid Build Coastguard Worker  */
64*38e8c45fSAndroid Build Coastguard Worker 
65*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_CHOREOGRAPHER_H
66*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_CHOREOGRAPHER_H
67*38e8c45fSAndroid Build Coastguard Worker 
68*38e8c45fSAndroid Build Coastguard Worker #include <stddef.h>
69*38e8c45fSAndroid Build Coastguard Worker #include <stdint.h>
70*38e8c45fSAndroid Build Coastguard Worker #include <sys/cdefs.h>
71*38e8c45fSAndroid Build Coastguard Worker 
72*38e8c45fSAndroid Build Coastguard Worker // This file may also be built on glibc or on Windows/MacOS libc's, so no-op
73*38e8c45fSAndroid Build Coastguard Worker // and deprecated definitions are provided.
74*38e8c45fSAndroid Build Coastguard Worker #if !defined(__INTRODUCED_IN)
75*38e8c45fSAndroid Build Coastguard Worker #define __INTRODUCED_IN(__api_level) /* nothing */
76*38e8c45fSAndroid Build Coastguard Worker #endif
77*38e8c45fSAndroid Build Coastguard Worker #if !defined(__DEPRECATED_IN)
78*38e8c45fSAndroid Build Coastguard Worker #define __DEPRECATED_IN(__api_level, ...) __attribute__((__deprecated__))
79*38e8c45fSAndroid Build Coastguard Worker #endif
80*38e8c45fSAndroid Build Coastguard Worker 
81*38e8c45fSAndroid Build Coastguard Worker __BEGIN_DECLS
82*38e8c45fSAndroid Build Coastguard Worker 
83*38e8c45fSAndroid Build Coastguard Worker struct AChoreographer;
84*38e8c45fSAndroid Build Coastguard Worker /**
85*38e8c45fSAndroid Build Coastguard Worker  * Opaque type that provides access to an AChoreographer object.
86*38e8c45fSAndroid Build Coastguard Worker  *
87*38e8c45fSAndroid Build Coastguard Worker  * A pointer can be obtained using {@link AChoreographer_getInstance()}.
88*38e8c45fSAndroid Build Coastguard Worker  */
89*38e8c45fSAndroid Build Coastguard Worker typedef struct AChoreographer AChoreographer;
90*38e8c45fSAndroid Build Coastguard Worker 
91*38e8c45fSAndroid Build Coastguard Worker 
92*38e8c45fSAndroid Build Coastguard Worker /**
93*38e8c45fSAndroid Build Coastguard Worker  * The identifier of a frame timeline.
94*38e8c45fSAndroid Build Coastguard Worker  */
95*38e8c45fSAndroid Build Coastguard Worker typedef int64_t AVsyncId;
96*38e8c45fSAndroid Build Coastguard Worker 
97*38e8c45fSAndroid Build Coastguard Worker struct AChoreographerFrameCallbackData;
98*38e8c45fSAndroid Build Coastguard Worker /**
99*38e8c45fSAndroid Build Coastguard Worker  * Opaque type that provides access to an AChoreographerFrameCallbackData object, which contains
100*38e8c45fSAndroid Build Coastguard Worker  * various methods to extract frame information.
101*38e8c45fSAndroid Build Coastguard Worker  */
102*38e8c45fSAndroid Build Coastguard Worker typedef struct AChoreographerFrameCallbackData AChoreographerFrameCallbackData;
103*38e8c45fSAndroid Build Coastguard Worker 
104*38e8c45fSAndroid Build Coastguard Worker /**
105*38e8c45fSAndroid Build Coastguard Worker  * Prototype of the function that is called when a new frame is being rendered.
106*38e8c45fSAndroid Build Coastguard Worker  * It's passed the time that the frame is being rendered as nanoseconds in the
107*38e8c45fSAndroid Build Coastguard Worker  * CLOCK_MONOTONIC time base, as well as the data pointer provided by the
108*38e8c45fSAndroid Build Coastguard Worker  * application that registered a callback. All callbacks that run as part of
109*38e8c45fSAndroid Build Coastguard Worker  * rendering a frame will observe the same frame time, so it should be used
110*38e8c45fSAndroid Build Coastguard Worker  * whenever events need to be synchronized (e.g. animations).
111*38e8c45fSAndroid Build Coastguard Worker  */
112*38e8c45fSAndroid Build Coastguard Worker typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void* data);
113*38e8c45fSAndroid Build Coastguard Worker 
114*38e8c45fSAndroid Build Coastguard Worker /**
115*38e8c45fSAndroid Build Coastguard Worker  * Prototype of the function that is called when a new frame is being rendered.
116*38e8c45fSAndroid Build Coastguard Worker  * It's passed the time that the frame is being rendered as nanoseconds in the
117*38e8c45fSAndroid Build Coastguard Worker  * CLOCK_MONOTONIC time base, as well as the data pointer provided by the
118*38e8c45fSAndroid Build Coastguard Worker  * application that registered a callback. All callbacks that run as part of
119*38e8c45fSAndroid Build Coastguard Worker  * rendering a frame will observe the same frame time, so it should be used
120*38e8c45fSAndroid Build Coastguard Worker  * whenever events need to be synchronized (e.g. animations).
121*38e8c45fSAndroid Build Coastguard Worker  */
122*38e8c45fSAndroid Build Coastguard Worker typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void* data);
123*38e8c45fSAndroid Build Coastguard Worker 
124*38e8c45fSAndroid Build Coastguard Worker /**
125*38e8c45fSAndroid Build Coastguard Worker  * Prototype of the function that is called when a new frame is being rendered.
126*38e8c45fSAndroid Build Coastguard Worker  * It is called with \c callbackData describing multiple frame timelines, as well as the \c data
127*38e8c45fSAndroid Build Coastguard Worker  * pointer provided by the application that registered a callback. The \c callbackData does not
128*38e8c45fSAndroid Build Coastguard Worker  * outlive the callback.
129*38e8c45fSAndroid Build Coastguard Worker  */
130*38e8c45fSAndroid Build Coastguard Worker typedef void (*AChoreographer_vsyncCallback)(
131*38e8c45fSAndroid Build Coastguard Worker         const AChoreographerFrameCallbackData* callbackData, void* data);
132*38e8c45fSAndroid Build Coastguard Worker 
133*38e8c45fSAndroid Build Coastguard Worker /**
134*38e8c45fSAndroid Build Coastguard Worker  * Prototype of the function that is called when the display refresh rate
135*38e8c45fSAndroid Build Coastguard Worker  * changes. It's passed the new vsync period in nanoseconds, as well as the data
136*38e8c45fSAndroid Build Coastguard Worker  * pointer provided by the application that registered a callback.
137*38e8c45fSAndroid Build Coastguard Worker  */
138*38e8c45fSAndroid Build Coastguard Worker typedef void (*AChoreographer_refreshRateCallback)(int64_t vsyncPeriodNanos, void* data);
139*38e8c45fSAndroid Build Coastguard Worker 
140*38e8c45fSAndroid Build Coastguard Worker /**
141*38e8c45fSAndroid Build Coastguard Worker  * Get the AChoreographer instance for the current thread. This must be called
142*38e8c45fSAndroid Build Coastguard Worker  * on an ALooper thread.
143*38e8c45fSAndroid Build Coastguard Worker  *
144*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 24.
145*38e8c45fSAndroid Build Coastguard Worker  */
146*38e8c45fSAndroid Build Coastguard Worker AChoreographer* AChoreographer_getInstance() __INTRODUCED_IN(24);
147*38e8c45fSAndroid Build Coastguard Worker 
148*38e8c45fSAndroid Build Coastguard Worker /**
149*38e8c45fSAndroid Build Coastguard Worker  * Post a callback to be run when the application should begin rendering the
150*38e8c45fSAndroid Build Coastguard Worker  * next frame. The data pointer provided will be passed to the callback function
151*38e8c45fSAndroid Build Coastguard Worker  * when it's called.
152*38e8c45fSAndroid Build Coastguard Worker  *
153*38e8c45fSAndroid Build Coastguard Worker  * The callback will only be run for the next frame, not all subsequent frames,
154*38e8c45fSAndroid Build Coastguard Worker  * so to render continuously the callback should itself call
155*38e8c45fSAndroid Build Coastguard Worker  * AChoreographer_postFrameCallback.
156*38e8c45fSAndroid Build Coastguard Worker  *
157*38e8c45fSAndroid Build Coastguard Worker  * \bug The callback receives the frame time in nanoseconds as a long. On 32-bit
158*38e8c45fSAndroid Build Coastguard Worker  * systems, long is 32-bit, so the frame time will roll over roughly every two
159*38e8c45fSAndroid Build Coastguard Worker  * seconds. If your minSdkVersion is 29 or higher, switch to
160*38e8c45fSAndroid Build Coastguard Worker  * AChoreographer_postFrameCallback64, which uses a 64-bit frame time for all
161*38e8c45fSAndroid Build Coastguard Worker  * platforms. For older OS versions, you must combine the argument with the
162*38e8c45fSAndroid Build Coastguard Worker  * upper bits of clock_gettime(CLOCK_MONOTONIC, ...) on 32-bit systems.
163*38e8c45fSAndroid Build Coastguard Worker  *
164*38e8c45fSAndroid Build Coastguard Worker  * \deprecated Use AChoreographer_postFrameCallback64, which does not have the
165*38e8c45fSAndroid Build Coastguard Worker  * bug described above.
166*38e8c45fSAndroid Build Coastguard Worker  */
167*38e8c45fSAndroid Build Coastguard Worker void AChoreographer_postFrameCallback(AChoreographer* choreographer,
168*38e8c45fSAndroid Build Coastguard Worker                                       AChoreographer_frameCallback callback, void* data)
169*38e8c45fSAndroid Build Coastguard Worker         __INTRODUCED_IN(24) __DEPRECATED_IN(29, "Use AChoreographer_postFrameCallback64 instead");
170*38e8c45fSAndroid Build Coastguard Worker 
171*38e8c45fSAndroid Build Coastguard Worker /**
172*38e8c45fSAndroid Build Coastguard Worker  * Post a callback to be run when the application should begin rendering the
173*38e8c45fSAndroid Build Coastguard Worker  * next frame following the specified delay. The data pointer provided will be
174*38e8c45fSAndroid Build Coastguard Worker  * passed to the callback function when it's called.
175*38e8c45fSAndroid Build Coastguard Worker  *
176*38e8c45fSAndroid Build Coastguard Worker  * The callback will only be run for the next frame after the delay, not all
177*38e8c45fSAndroid Build Coastguard Worker  * subsequent frames, so to render continuously the callback should itself call
178*38e8c45fSAndroid Build Coastguard Worker  * AChoreographer_postFrameCallbackDelayed.
179*38e8c45fSAndroid Build Coastguard Worker  *
180*38e8c45fSAndroid Build Coastguard Worker  * \bug The callback receives the frame time in nanoseconds as a long. On 32-bit
181*38e8c45fSAndroid Build Coastguard Worker  * systems, long is 32-bit, so the frame time will roll over roughly every two
182*38e8c45fSAndroid Build Coastguard Worker  * seconds. If your minSdkVersion is 29 or higher, switch to
183*38e8c45fSAndroid Build Coastguard Worker  * AChoreographer_postFrameCallbackDelayed64, which uses a 64-bit frame time for
184*38e8c45fSAndroid Build Coastguard Worker  * all platforms. For older OS versions, you must combine the argument with the
185*38e8c45fSAndroid Build Coastguard Worker  * upper bits of clock_gettime(CLOCK_MONOTONIC, ...) on 32-bit systems.
186*38e8c45fSAndroid Build Coastguard Worker  *
187*38e8c45fSAndroid Build Coastguard Worker  * \deprecated Use AChoreographer_postFrameCallbackDelayed64, which does not
188*38e8c45fSAndroid Build Coastguard Worker  * have the bug described above.
189*38e8c45fSAndroid Build Coastguard Worker  */
190*38e8c45fSAndroid Build Coastguard Worker void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer,
191*38e8c45fSAndroid Build Coastguard Worker                                              AChoreographer_frameCallback callback, void* data,
192*38e8c45fSAndroid Build Coastguard Worker                                              long delayMillis) __INTRODUCED_IN(24)
193*38e8c45fSAndroid Build Coastguard Worker         __DEPRECATED_IN(29, "Use AChoreographer_postFrameCallbackDelayed64 instead");
194*38e8c45fSAndroid Build Coastguard Worker 
195*38e8c45fSAndroid Build Coastguard Worker /**
196*38e8c45fSAndroid Build Coastguard Worker  * Post a callback to be run when the application should begin rendering the
197*38e8c45fSAndroid Build Coastguard Worker  * next frame. The data pointer provided will be passed to the callback function
198*38e8c45fSAndroid Build Coastguard Worker  * when it's called.
199*38e8c45fSAndroid Build Coastguard Worker  *
200*38e8c45fSAndroid Build Coastguard Worker  * The callback will only be run on the next frame, not all subsequent frames,
201*38e8c45fSAndroid Build Coastguard Worker  * so to render continuously the callback should itself call
202*38e8c45fSAndroid Build Coastguard Worker  * AChoreographer_postFrameCallback64.
203*38e8c45fSAndroid Build Coastguard Worker  *
204*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
205*38e8c45fSAndroid Build Coastguard Worker  */
206*38e8c45fSAndroid Build Coastguard Worker void AChoreographer_postFrameCallback64(AChoreographer* choreographer,
207*38e8c45fSAndroid Build Coastguard Worker                                         AChoreographer_frameCallback64 callback, void* data)
208*38e8c45fSAndroid Build Coastguard Worker         __INTRODUCED_IN(29);
209*38e8c45fSAndroid Build Coastguard Worker 
210*38e8c45fSAndroid Build Coastguard Worker /**
211*38e8c45fSAndroid Build Coastguard Worker  * Post a callback to be run when the application should begin rendering the
212*38e8c45fSAndroid Build Coastguard Worker  * next frame following the specified delay. The data pointer provided will be
213*38e8c45fSAndroid Build Coastguard Worker  * passed to the callback function when it's called.
214*38e8c45fSAndroid Build Coastguard Worker  *
215*38e8c45fSAndroid Build Coastguard Worker  * The callback will only be run for the next frame after the delay, not all
216*38e8c45fSAndroid Build Coastguard Worker  * subsequent frames, so to render continuously the callback should itself call
217*38e8c45fSAndroid Build Coastguard Worker  * AChoreographer_postFrameCallbackDelayed64.
218*38e8c45fSAndroid Build Coastguard Worker  *
219*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
220*38e8c45fSAndroid Build Coastguard Worker  */
221*38e8c45fSAndroid Build Coastguard Worker void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer,
222*38e8c45fSAndroid Build Coastguard Worker                                                AChoreographer_frameCallback64 callback, void* data,
223*38e8c45fSAndroid Build Coastguard Worker                                                uint32_t delayMillis) __INTRODUCED_IN(29);
224*38e8c45fSAndroid Build Coastguard Worker 
225*38e8c45fSAndroid Build Coastguard Worker /**
226*38e8c45fSAndroid Build Coastguard Worker  * Posts a callback to be run when the application should begin rendering the
227*38e8c45fSAndroid Build Coastguard Worker  * next frame. The data pointer provided will be passed to the callback function
228*38e8c45fSAndroid Build Coastguard Worker  * when it's called.
229*38e8c45fSAndroid Build Coastguard Worker  *
230*38e8c45fSAndroid Build Coastguard Worker  * The callback will only be run for the next frame, not all subsequent frames,
231*38e8c45fSAndroid Build Coastguard Worker  * so to render continuously the callback should itself call
232*38e8c45fSAndroid Build Coastguard Worker  * AChoreographer_postVsyncCallback.
233*38e8c45fSAndroid Build Coastguard Worker  *
234*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
235*38e8c45fSAndroid Build Coastguard Worker  */
236*38e8c45fSAndroid Build Coastguard Worker void AChoreographer_postVsyncCallback(AChoreographer* choreographer,
237*38e8c45fSAndroid Build Coastguard Worker                                         AChoreographer_vsyncCallback callback, void* data)
238*38e8c45fSAndroid Build Coastguard Worker         __INTRODUCED_IN(33);
239*38e8c45fSAndroid Build Coastguard Worker 
240*38e8c45fSAndroid Build Coastguard Worker /**
241*38e8c45fSAndroid Build Coastguard Worker  * Registers a callback to be run when the display refresh rate changes. The
242*38e8c45fSAndroid Build Coastguard Worker  * data pointer provided will be passed to the callback function when it's
243*38e8c45fSAndroid Build Coastguard Worker  * called. The same callback may be registered multiple times, provided that a
244*38e8c45fSAndroid Build Coastguard Worker  * different data pointer is provided each time.
245*38e8c45fSAndroid Build Coastguard Worker  *
246*38e8c45fSAndroid Build Coastguard Worker  * If an application registers a callback for this choreographer instance when
247*38e8c45fSAndroid Build Coastguard Worker  * no new callbacks were previously registered, that callback is guaranteed to
248*38e8c45fSAndroid Build Coastguard Worker  * be dispatched. However, if the callback and associated data pointer are
249*38e8c45fSAndroid Build Coastguard Worker  * unregistered prior to running the callback, then the callback may be silently
250*38e8c45fSAndroid Build Coastguard Worker  * dropped.
251*38e8c45fSAndroid Build Coastguard Worker  *
252*38e8c45fSAndroid Build Coastguard Worker  * This api is thread-safe. Any thread is allowed to register a new refresh
253*38e8c45fSAndroid Build Coastguard Worker  * rate callback for the choreographer instance.
254*38e8c45fSAndroid Build Coastguard Worker  *
255*38e8c45fSAndroid Build Coastguard Worker  * Note that in API level 30, this api is not guaranteed to be atomic with
256*38e8c45fSAndroid Build Coastguard Worker  * DisplayManager. That is, calling Display#getRefreshRate very soon after
257*38e8c45fSAndroid Build Coastguard Worker  * a refresh rate callback is invoked may return a stale refresh rate. If any
258*38e8c45fSAndroid Build Coastguard Worker  * Display properties would be required by this callback, then it is recommended
259*38e8c45fSAndroid Build Coastguard Worker  * to listen directly to DisplayManager.DisplayListener#onDisplayChanged events
260*38e8c45fSAndroid Build Coastguard Worker  * instead.
261*38e8c45fSAndroid Build Coastguard Worker  *
262*38e8c45fSAndroid Build Coastguard Worker  * As of API level 31, this api is guaranteed to have a consistent view with DisplayManager;
263*38e8c45fSAndroid Build Coastguard Worker  * Display#getRefreshRate is guaranteed to not return a stale refresh rate when invoked from this
264*38e8c45fSAndroid Build Coastguard Worker  * callback.
265*38e8c45fSAndroid Build Coastguard Worker  *
266*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 30.
267*38e8c45fSAndroid Build Coastguard Worker  */
268*38e8c45fSAndroid Build Coastguard Worker void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer,
269*38e8c45fSAndroid Build Coastguard Worker                                                 AChoreographer_refreshRateCallback, void* data)
270*38e8c45fSAndroid Build Coastguard Worker         __INTRODUCED_IN(30);
271*38e8c45fSAndroid Build Coastguard Worker 
272*38e8c45fSAndroid Build Coastguard Worker /**
273*38e8c45fSAndroid Build Coastguard Worker  * Unregisters a callback to be run when the display refresh rate changes, along
274*38e8c45fSAndroid Build Coastguard Worker  * with the data pointer previously provided when registering the callback. The
275*38e8c45fSAndroid Build Coastguard Worker  * callback is only unregistered when the data pointer matches one that was
276*38e8c45fSAndroid Build Coastguard Worker  * previously registered.
277*38e8c45fSAndroid Build Coastguard Worker  *
278*38e8c45fSAndroid Build Coastguard Worker  * This api is thread-safe. Any thread is allowed to unregister an existing
279*38e8c45fSAndroid Build Coastguard Worker  * refresh rate callback for the choreographer instance. When a refresh rate
280*38e8c45fSAndroid Build Coastguard Worker  * callback and associated data pointer are unregistered, then there is a
281*38e8c45fSAndroid Build Coastguard Worker  * guarantee that when the unregistration completes that that callback will not
282*38e8c45fSAndroid Build Coastguard Worker  * be run with the data pointer passed.
283*38e8c45fSAndroid Build Coastguard Worker  *
284*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 30.
285*38e8c45fSAndroid Build Coastguard Worker  */
286*38e8c45fSAndroid Build Coastguard Worker void AChoreographer_unregisterRefreshRateCallback(AChoreographer* choreographer,
287*38e8c45fSAndroid Build Coastguard Worker                                                   AChoreographer_refreshRateCallback, void* data)
288*38e8c45fSAndroid Build Coastguard Worker         __INTRODUCED_IN(30);
289*38e8c45fSAndroid Build Coastguard Worker 
290*38e8c45fSAndroid Build Coastguard Worker /**
291*38e8c45fSAndroid Build Coastguard Worker  * The time in nanoseconds at which the frame started being rendered.
292*38e8c45fSAndroid Build Coastguard Worker  *
293*38e8c45fSAndroid Build Coastguard Worker  * Note that this time should \b not be used to advance animation clocks.
294*38e8c45fSAndroid Build Coastguard Worker  * Instead, see AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentationTimeNanos().
295*38e8c45fSAndroid Build Coastguard Worker  *
296*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
297*38e8c45fSAndroid Build Coastguard Worker  */
298*38e8c45fSAndroid Build Coastguard Worker int64_t AChoreographerFrameCallbackData_getFrameTimeNanos(
299*38e8c45fSAndroid Build Coastguard Worker         const AChoreographerFrameCallbackData* data) __INTRODUCED_IN(33);
300*38e8c45fSAndroid Build Coastguard Worker 
301*38e8c45fSAndroid Build Coastguard Worker /**
302*38e8c45fSAndroid Build Coastguard Worker  * The number of possible frame timelines.
303*38e8c45fSAndroid Build Coastguard Worker  *
304*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
305*38e8c45fSAndroid Build Coastguard Worker  */
306*38e8c45fSAndroid Build Coastguard Worker size_t AChoreographerFrameCallbackData_getFrameTimelinesLength(
307*38e8c45fSAndroid Build Coastguard Worker         const AChoreographerFrameCallbackData* data) __INTRODUCED_IN(33);
308*38e8c45fSAndroid Build Coastguard Worker 
309*38e8c45fSAndroid Build Coastguard Worker /**
310*38e8c45fSAndroid Build Coastguard Worker  * Gets the index of the platform-preferred frame timeline.
311*38e8c45fSAndroid Build Coastguard Worker  * The preferred frame timeline is the default
312*38e8c45fSAndroid Build Coastguard Worker  * by which the platform scheduled the app, based on the device configuration.
313*38e8c45fSAndroid Build Coastguard Worker  *
314*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
315*38e8c45fSAndroid Build Coastguard Worker  */
316*38e8c45fSAndroid Build Coastguard Worker size_t AChoreographerFrameCallbackData_getPreferredFrameTimelineIndex(
317*38e8c45fSAndroid Build Coastguard Worker         const AChoreographerFrameCallbackData* data) __INTRODUCED_IN(33);
318*38e8c45fSAndroid Build Coastguard Worker 
319*38e8c45fSAndroid Build Coastguard Worker /**
320*38e8c45fSAndroid Build Coastguard Worker  * Gets the token used by the platform to identify the frame timeline at the given \c index.
321*38e8c45fSAndroid Build Coastguard Worker  *
322*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
323*38e8c45fSAndroid Build Coastguard Worker  *
324*38e8c45fSAndroid Build Coastguard Worker  * \param index index of a frame timeline, in \f( [0, FrameTimelinesLength) \f). See
325*38e8c45fSAndroid Build Coastguard Worker  * AChoreographerFrameCallbackData_getFrameTimelinesLength()
326*38e8c45fSAndroid Build Coastguard Worker  *
327*38e8c45fSAndroid Build Coastguard Worker  */
328*38e8c45fSAndroid Build Coastguard Worker AVsyncId AChoreographerFrameCallbackData_getFrameTimelineVsyncId(
329*38e8c45fSAndroid Build Coastguard Worker         const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
330*38e8c45fSAndroid Build Coastguard Worker 
331*38e8c45fSAndroid Build Coastguard Worker /**
332*38e8c45fSAndroid Build Coastguard Worker  * Gets the time in nanoseconds at which the frame described at the given \c index is expected to
333*38e8c45fSAndroid Build Coastguard Worker  * be presented. This time should be used to advance any animation clocks.
334*38e8c45fSAndroid Build Coastguard Worker  *
335*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
336*38e8c45fSAndroid Build Coastguard Worker  *
337*38e8c45fSAndroid Build Coastguard Worker  * \param index index of a frame timeline, in \f( [0, FrameTimelinesLength) \f). See
338*38e8c45fSAndroid Build Coastguard Worker  * AChoreographerFrameCallbackData_getFrameTimelinesLength()
339*38e8c45fSAndroid Build Coastguard Worker  */
340*38e8c45fSAndroid Build Coastguard Worker int64_t AChoreographerFrameCallbackData_getFrameTimelineExpectedPresentationTimeNanos(
341*38e8c45fSAndroid Build Coastguard Worker         const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
342*38e8c45fSAndroid Build Coastguard Worker 
343*38e8c45fSAndroid Build Coastguard Worker /**
344*38e8c45fSAndroid Build Coastguard Worker  * Gets the time in nanoseconds at which the frame described at the given \c index needs to be
345*38e8c45fSAndroid Build Coastguard Worker  * ready by in order to be presented on time.
346*38e8c45fSAndroid Build Coastguard Worker  *
347*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
348*38e8c45fSAndroid Build Coastguard Worker  *
349*38e8c45fSAndroid Build Coastguard Worker  * \param index index of a frame timeline, in \f( [0, FrameTimelinesLength) \f). See
350*38e8c45fSAndroid Build Coastguard Worker  * AChoreographerFrameCallbackData_getFrameTimelinesLength()
351*38e8c45fSAndroid Build Coastguard Worker  */
352*38e8c45fSAndroid Build Coastguard Worker int64_t AChoreographerFrameCallbackData_getFrameTimelineDeadlineNanos(
353*38e8c45fSAndroid Build Coastguard Worker         const AChoreographerFrameCallbackData* data, size_t index) __INTRODUCED_IN(33);
354*38e8c45fSAndroid Build Coastguard Worker 
355*38e8c45fSAndroid Build Coastguard Worker __END_DECLS
356*38e8c45fSAndroid Build Coastguard Worker 
357*38e8c45fSAndroid Build Coastguard Worker #endif // ANDROID_CHOREOGRAPHER_H
358*38e8c45fSAndroid Build Coastguard Worker 
359*38e8c45fSAndroid Build Coastguard Worker /** @} */
360