blob: 0923438eec66388d799b8737ea550479fd34c790 [file] [log] [blame]
Alec Mouri9fa2cb62019-07-15 17:36:26 -07001/*
2 * Copyright 2019 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 <nativebase/nativebase.h>
Alec Mouri09d122a2019-11-25 10:00:53 -080020#include <stdarg.h>
Alec Mouri9fa2cb62019-07-15 17:36:26 -070021
22// apex is a superset of the NDK
23#include <android/native_window.h>
24
25__BEGIN_DECLS
26
Alec Mouri09d122a2019-11-25 10:00:53 -080027/*
28 * perform bits that can be used with ANativeWindow_perform()
29 *
30 * This is only to support the intercepting methods below - these should notbe
31 * used directly otherwise.
32 */
33enum ANativeWindowPerform {
34 // clang-format off
35 ANATIVEWINDOW_PERFORM_SET_USAGE = 0,
36 ANATIVEWINDOW_PERFORM_SET_BUFFERS_GEOMETRY = 5,
37 ANATIVEWINDOW_PERFORM_SET_BUFFERS_FORMAT = 9,
38 ANATIVEWINDOW_PERFORM_SET_USAGE64 = 30,
39 // clang-format on
40};
41
Ady Abraham35018762021-01-07 17:56:08 -080042/*
43 * Internal extension of compatibility value for ANativeWindow_setFrameRate. */
44enum ANativeWindow_FrameRateCompatibilityInternal {
45 /**
46 * This surface belongs to an app on the High Refresh Rate Deny list, and needs the display
47 * to operate at the exact frame rate.
48 *
49 * This is used internally by the platform and should not be used by apps.
50 * @hide
51 */
52 ANATIVEWINDOW_FRAME_RATE_EXACT = 100,
53};
54
Alec Mouri09d122a2019-11-25 10:00:53 -080055/**
56 * Prototype of the function that an ANativeWindow implementation would call
57 * when ANativeWindow_cancelBuffer is called.
58 */
59typedef int (*ANativeWindow_cancelBufferFn)(ANativeWindow* window, ANativeWindowBuffer* buffer,
60 int fenceFd);
61
62/**
63 * Prototype of the function that intercepts an invocation of
64 * ANativeWindow_cancelBufferFn, along with a data pointer that's passed by the
65 * caller who set the interceptor, as well as arguments that would be
66 * passed to ANativeWindow_cancelBufferFn if it were to be called.
67 */
68typedef int (*ANativeWindow_cancelBufferInterceptor)(ANativeWindow* window,
69 ANativeWindow_cancelBufferFn cancelBuffer,
70 void* data, ANativeWindowBuffer* buffer,
71 int fenceFd);
72
73/**
74 * Prototype of the function that an ANativeWindow implementation would call
75 * when ANativeWindow_dequeueBuffer is called.
76 */
77typedef int (*ANativeWindow_dequeueBufferFn)(ANativeWindow* window, ANativeWindowBuffer** buffer,
78 int* fenceFd);
79
80/**
81 * Prototype of the function that intercepts an invocation of
82 * ANativeWindow_dequeueBufferFn, along with a data pointer that's passed by the
83 * caller who set the interceptor, as well as arguments that would be
84 * passed to ANativeWindow_dequeueBufferFn if it were to be called.
85 */
86typedef int (*ANativeWindow_dequeueBufferInterceptor)(ANativeWindow* window,
87 ANativeWindow_dequeueBufferFn dequeueBuffer,
88 void* data, ANativeWindowBuffer** buffer,
89 int* fenceFd);
90
91/**
92 * Prototype of the function that an ANativeWindow implementation would call
93 * when ANativeWindow_perform is called.
94 */
95typedef int (*ANativeWindow_performFn)(ANativeWindow* window, int operation, va_list args);
96
97/**
98 * Prototype of the function that intercepts an invocation of
99 * ANativeWindow_performFn, along with a data pointer that's passed by the
100 * caller who set the interceptor, as well as arguments that would be
101 * passed to ANativeWindow_performFn if it were to be called.
102 */
103typedef int (*ANativeWindow_performInterceptor)(ANativeWindow* window,
104 ANativeWindow_performFn perform, void* data,
105 int operation, va_list args);
106
107/**
108 * Prototype of the function that an ANativeWindow implementation would call
109 * when ANativeWindow_queueBuffer is called.
110 */
111typedef int (*ANativeWindow_queueBufferFn)(ANativeWindow* window, ANativeWindowBuffer* buffer,
112 int fenceFd);
113
114/**
115 * Prototype of the function that intercepts an invocation of
116 * ANativeWindow_queueBufferFn, along with a data pointer that's passed by the
117 * caller who set the interceptor, as well as arguments that would be
118 * passed to ANativeWindow_queueBufferFn if it were to be called.
119 */
120typedef int (*ANativeWindow_queueBufferInterceptor)(ANativeWindow* window,
121 ANativeWindow_queueBufferFn queueBuffer,
122 void* data, ANativeWindowBuffer* buffer,
123 int fenceFd);
124
125/**
126 * Registers an interceptor for ANativeWindow_cancelBuffer. Instead of calling
127 * the underlying cancelBuffer function, instead the provided interceptor is
128 * called, which may optionally call the underlying cancelBuffer function. An
129 * optional data pointer is also provided to side-channel additional arguments.
130 *
131 * Note that usage of this should only be used for specialized use-cases by
132 * either the system partition or to Mainline modules. This should never be
133 * exposed to NDK or LL-NDK.
134 *
135 * Returns NO_ERROR on success, -errno if registration failed.
136 */
137int ANativeWindow_setCancelBufferInterceptor(ANativeWindow* window,
138 ANativeWindow_cancelBufferInterceptor interceptor,
139 void* data);
140
141/**
142 * Registers an interceptor for ANativeWindow_dequeueBuffer. Instead of calling
143 * the underlying dequeueBuffer function, instead the provided interceptor is
144 * called, which may optionally call the underlying dequeueBuffer function. An
145 * optional data pointer is also provided to side-channel additional arguments.
146 *
147 * Note that usage of this should only be used for specialized use-cases by
148 * either the system partition or to Mainline modules. This should never be
149 * exposed to NDK or LL-NDK.
150 *
151 * Returns NO_ERROR on success, -errno if registration failed.
152 */
153int ANativeWindow_setDequeueBufferInterceptor(ANativeWindow* window,
154 ANativeWindow_dequeueBufferInterceptor interceptor,
155 void* data);
156/**
157 * Registers an interceptor for ANativeWindow_perform. Instead of calling
158 * the underlying perform function, instead the provided interceptor is
159 * called, which may optionally call the underlying perform function. An
160 * optional data pointer is also provided to side-channel additional arguments.
161 *
162 * Note that usage of this should only be used for specialized use-cases by
163 * either the system partition or to Mainline modules. This should never be
164 * exposed to NDK or LL-NDK.
165 *
166 * Returns NO_ERROR on success, -errno if registration failed.
167 */
168int ANativeWindow_setPerformInterceptor(ANativeWindow* window,
169 ANativeWindow_performInterceptor interceptor, void* data);
170/**
171 * Registers an interceptor for ANativeWindow_queueBuffer. Instead of calling
172 * the underlying queueBuffer function, instead the provided interceptor is
173 * called, which may optionally call the underlying queueBuffer function. An
174 * optional data pointer is also provided to side-channel additional arguments.
175 *
176 * Note that usage of this should only be used for specialized use-cases by
177 * either the system partition or to Mainline modules. This should never be
178 * exposed to NDK or LL-NDK.
179 *
180 * Returns NO_ERROR on success, -errno if registration failed.
181 */
182int ANativeWindow_setQueueBufferInterceptor(ANativeWindow* window,
183 ANativeWindow_queueBufferInterceptor interceptor,
184 void* data);
185
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700186/**
187 * Retrieves how long it took for the last time a buffer was dequeued.
188 *
Alec Mourid41a1be2020-02-14 15:18:11 -0800189 * \return the dequeue duration in nanoseconds
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700190 */
Alec Mouri72670c52019-08-31 01:54:33 -0700191int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window);
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700192
Alec Mouri0d1398b2019-08-14 10:53:50 -0700193/**
194 * Retrieves how long it took for the last time a buffer was queued.
195 *
Alec Mourid41a1be2020-02-14 15:18:11 -0800196 * \return the queue duration in nanoseconds
Alec Mouri0d1398b2019-08-14 10:53:50 -0700197 */
Alec Mouri72670c52019-08-31 01:54:33 -0700198int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window);
Alec Mouri0d1398b2019-08-14 10:53:50 -0700199
Alec Mouria1619662019-08-21 19:30:48 -0700200/**
201 * Retrieves the system time in nanoseconds when the last time a buffer
Alec Mourid41a1be2020-02-14 15:18:11 -0800202 * started to be dequeued.
Alec Mouria1619662019-08-21 19:30:48 -0700203 *
Alec Mourid41a1be2020-02-14 15:18:11 -0800204 * \return the start time in nanoseconds
Alec Mouria1619662019-08-21 19:30:48 -0700205 */
206int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window);
207
Alec Mouri04fdb602019-08-23 19:41:43 -0700208/**
209 * Sets a timeout in nanoseconds for dequeue calls. All subsequent dequeue calls
210 * made by the window will return -ETIMEDOUT after the timeout if the dequeue
211 * takes too long.
212 *
Alec Mourid41a1be2020-02-14 15:18:11 -0800213 * If the provided timeout is negative, hen this removes the previously configured
214 * timeout. The window then behaves as if ANativeWindow_setDequeueTimeout was
215 * never called.
216 *
217 * \return NO_ERROR on success
218 * \return BAD_VALUE if the dequeue timeout was unabled to be updated, as
219 * updating the dequeue timeout may change internals of the underlying window.
Alec Mouri04fdb602019-08-23 19:41:43 -0700220 */
221int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout);
222
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700223__END_DECLS