blob: cc5420e239de54af624423290f57be220906584c [file] [log] [blame]
Michael Wrightf5eee402015-12-07 15:26:38 -05001/*
2 * Copyright (C) 2015 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/**
18 * @addtogroup Choreographer
19 * @{
20 */
21
22/**
23 * @file choreographer.h
24 */
25
26#ifndef ANDROID_CHOREOGRAPHER_H
27#define ANDROID_CHOREOGRAPHER_H
28
Santos Cordon908d0082019-02-20 18:08:02 +000029#include <stdint.h>
Michael Wrightfb911b22016-01-26 16:05:54 -080030#include <sys/cdefs.h>
31
Michael Wrightf5eee402015-12-07 15:26:38 -050032__BEGIN_DECLS
33
34struct AChoreographer;
35typedef struct AChoreographer AChoreographer;
36
37/**
38 * Prototype of the function that is called when a new frame is being rendered.
39 * It's passed the time that the frame is being rendered as nanoseconds in the
40 * CLOCK_MONOTONIC time base, as well as the data pointer provided by the
41 * application that registered a callback. All callbacks that run as part of
42 * rendering a frame will observe the same frame time, so it should be used
43 * whenever events need to be synchronized (e.g. animations).
44 */
45typedef void (*AChoreographer_frameCallback)(long frameTimeNanos, void* data);
46
Santos Cordon908d0082019-02-20 18:08:02 +000047/**
48 * Prototype of the function that is called when a new frame is being rendered.
49 * It's passed the time that the frame is being rendered as nanoseconds in the
50 * CLOCK_MONOTONIC time base, as well as the data pointer provided by the
51 * application that registered a callback. All callbacks that run as part of
52 * rendering a frame will observe the same frame time, so it should be used
53 * whenever events need to be synchronized (e.g. animations).
54 */
55typedef void (*AChoreographer_frameCallback64)(int64_t frameTimeNanos, void* data);
56
Alec Mouri33682e92020-01-10 15:11:15 -080057/**
58 * Prototype of the function that is called when the display refresh rate
59 * changes. It's passed the new vsync period in nanoseconds, as well as the data
60 * pointer provided by the application that registered a callback.
61 */
62typedef void (*AChoreographer_refreshRateCallback)(int64_t vsyncPeriodNanos, void* data);
63
Michael Wrightf5eee402015-12-07 15:26:38 -050064/**
65 * Get the AChoreographer instance for the current thread. This must be called
66 * on an ALooper thread.
Elliott Hughes3d70e532019-10-29 08:59:39 -070067 *
68 * Available since API level 24.
Michael Wrightf5eee402015-12-07 15:26:38 -050069 */
Elliott Hughes9db409b2018-06-18 12:28:46 -070070AChoreographer* AChoreographer_getInstance() __INTRODUCED_IN(24);
Michael Wrightf5eee402015-12-07 15:26:38 -050071
72/**
Santos Cordon908d0082019-02-20 18:08:02 +000073 * Deprecated: Use AChoreographer_postFrameCallback64 instead.
Michael Wrightf5eee402015-12-07 15:26:38 -050074 */
75void AChoreographer_postFrameCallback(AChoreographer* choreographer,
Alec Mouri271de042020-04-27 22:38:19 -070076 AChoreographer_frameCallback callback, void* data)
77 __INTRODUCED_IN(24) __DEPRECATED_IN(29);
Elliott Hughes9db409b2018-06-18 12:28:46 -070078
Michael Wrightf5eee402015-12-07 15:26:38 -050079/**
Santos Cordon908d0082019-02-20 18:08:02 +000080 * Deprecated: Use AChoreographer_postFrameCallbackDelayed64 instead.
Michael Wrightf5eee402015-12-07 15:26:38 -050081 */
82void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer,
Alec Mouri271de042020-04-27 22:38:19 -070083 AChoreographer_frameCallback callback, void* data,
84 long delayMillis) __INTRODUCED_IN(24)
85 __DEPRECATED_IN(29);
Dan Albert494ed552016-09-23 15:57:45 -070086
Santos Cordon908d0082019-02-20 18:08:02 +000087/**
88 * Power a callback to be run on the next frame. The data pointer provided will
89 * be passed to the callback function when it's called.
Elliott Hughes3d70e532019-10-29 08:59:39 -070090 *
91 * Available since API level 29.
Santos Cordon908d0082019-02-20 18:08:02 +000092 */
Dillon Cower20e67fa2019-07-30 15:39:54 -070093void AChoreographer_postFrameCallback64(AChoreographer* choreographer,
Alec Mouri271de042020-04-27 22:38:19 -070094 AChoreographer_frameCallback64 callback, void* data)
95 __INTRODUCED_IN(29);
Santos Cordon908d0082019-02-20 18:08:02 +000096
97/**
98 * Post a callback to be run on the frame following the specified delay. The
99 * data pointer provided will be passed to the callback function when it's
100 * called.
Elliott Hughes3d70e532019-10-29 08:59:39 -0700101 *
102 * Available since API level 29.
Santos Cordon908d0082019-02-20 18:08:02 +0000103 */
104void AChoreographer_postFrameCallbackDelayed64(AChoreographer* choreographer,
Alec Mouri271de042020-04-27 22:38:19 -0700105 AChoreographer_frameCallback64 callback, void* data,
106 uint32_t delayMillis) __INTRODUCED_IN(29);
Santos Cordon908d0082019-02-20 18:08:02 +0000107
Alec Mouri33682e92020-01-10 15:11:15 -0800108/**
109 * Registers a callback to be run when the display refresh rate changes. The
110 * data pointer provided will be passed to the callback function when it's
111 * called. The same callback may be registered multiple times, provided that a
112 * different data pointer is provided each time.
113 *
114 * If an application registers a callback for this choreographer instance when
115 * no new callbacks were previously registered, that callback is guaranteed to
116 * be dispatched. However, if the callback and associated data pointer are
117 * unregistered prior to running the callback, then the callback may be silently
118 * dropped.
119 *
120 * This api is thread-safe. Any thread is allowed to register a new refresh
121 * rate callback for the choreographer instance.
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700122 *
Alec Mouri4a331652020-07-20 22:05:24 +0000123 * Note that in API level 30, this api is not guaranteed to be atomic with
124 * DisplayManager. That is, calling Display#getRefreshRate very soon after
125 * a refresh rate callback is invoked may return a stale refresh rate. If any
126 * Display properties would be required by this callback, then it is recommended
127 * to listen directly to DisplayManager.DisplayListener#onDisplayChanged events
128 * instead.
129 *
Alec Mouri7015fa92021-02-11 19:31:44 +0000130 * As of API level 31, this api is guaranteed to have a consistent view with DisplayManager;
131 * Display#getRefreshRate is guaranteed to not return a stale refresh rate when invoked from this
132 * callback.
133 *
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700134 * Available since API level 30.
Alec Mouri33682e92020-01-10 15:11:15 -0800135 */
136void AChoreographer_registerRefreshRateCallback(AChoreographer* choreographer,
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700137 AChoreographer_refreshRateCallback, void* data)
138 __INTRODUCED_IN(30);
Alec Mouri33682e92020-01-10 15:11:15 -0800139
140/**
141 * Unregisters a callback to be run when the display refresh rate changes, along
142 * with the data pointer previously provided when registering the callback. The
143 * callback is only unregistered when the data pointer matches one that was
144 * previously registered.
145 *
146 * This api is thread-safe. Any thread is allowed to unregister an existing
147 * refresh rate callback for the choreographer instance. When a refresh rate
148 * callback and associated data pointer are unregistered, then there is a
149 * guarantee that when the unregistration completes that that callback will not
150 * be run with the data pointer passed.
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700151 *
152 * Available since API level 30.
Alec Mouri33682e92020-01-10 15:11:15 -0800153 */
154void AChoreographer_unregisterRefreshRateCallback(AChoreographer* choreographer,
Elliott Hughes7be0e2d2020-06-02 13:05:04 -0700155 AChoreographer_refreshRateCallback, void* data)
156 __INTRODUCED_IN(30);
Alec Mouri33682e92020-01-10 15:11:15 -0800157
Michael Wrightf5eee402015-12-07 15:26:38 -0500158__END_DECLS
159
160#endif // ANDROID_CHOREOGRAPHER_H
161
162/** @} */