blob: 2d1354cdf1fc58b99ace66325bd67a1a43474dc5 [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
42/**
43 * Prototype of the function that an ANativeWindow implementation would call
44 * when ANativeWindow_cancelBuffer is called.
45 */
46typedef int (*ANativeWindow_cancelBufferFn)(ANativeWindow* window, ANativeWindowBuffer* buffer,
47 int fenceFd);
48
49/**
50 * Prototype of the function that intercepts an invocation of
51 * ANativeWindow_cancelBufferFn, along with a data pointer that's passed by the
52 * caller who set the interceptor, as well as arguments that would be
53 * passed to ANativeWindow_cancelBufferFn if it were to be called.
54 */
55typedef int (*ANativeWindow_cancelBufferInterceptor)(ANativeWindow* window,
56 ANativeWindow_cancelBufferFn cancelBuffer,
57 void* data, ANativeWindowBuffer* buffer,
58 int fenceFd);
59
60/**
61 * Prototype of the function that an ANativeWindow implementation would call
62 * when ANativeWindow_dequeueBuffer is called.
63 */
64typedef int (*ANativeWindow_dequeueBufferFn)(ANativeWindow* window, ANativeWindowBuffer** buffer,
65 int* fenceFd);
66
67/**
68 * Prototype of the function that intercepts an invocation of
69 * ANativeWindow_dequeueBufferFn, along with a data pointer that's passed by the
70 * caller who set the interceptor, as well as arguments that would be
71 * passed to ANativeWindow_dequeueBufferFn if it were to be called.
72 */
73typedef int (*ANativeWindow_dequeueBufferInterceptor)(ANativeWindow* window,
74 ANativeWindow_dequeueBufferFn dequeueBuffer,
75 void* data, ANativeWindowBuffer** buffer,
76 int* fenceFd);
77
78/**
79 * Prototype of the function that an ANativeWindow implementation would call
80 * when ANativeWindow_perform is called.
81 */
82typedef int (*ANativeWindow_performFn)(ANativeWindow* window, int operation, va_list args);
83
84/**
85 * Prototype of the function that intercepts an invocation of
86 * ANativeWindow_performFn, along with a data pointer that's passed by the
87 * caller who set the interceptor, as well as arguments that would be
88 * passed to ANativeWindow_performFn if it were to be called.
89 */
90typedef int (*ANativeWindow_performInterceptor)(ANativeWindow* window,
91 ANativeWindow_performFn perform, void* data,
92 int operation, va_list args);
93
94/**
95 * Prototype of the function that an ANativeWindow implementation would call
96 * when ANativeWindow_queueBuffer is called.
97 */
98typedef int (*ANativeWindow_queueBufferFn)(ANativeWindow* window, ANativeWindowBuffer* buffer,
99 int fenceFd);
100
101/**
102 * Prototype of the function that intercepts an invocation of
103 * ANativeWindow_queueBufferFn, along with a data pointer that's passed by the
104 * caller who set the interceptor, as well as arguments that would be
105 * passed to ANativeWindow_queueBufferFn if it were to be called.
106 */
107typedef int (*ANativeWindow_queueBufferInterceptor)(ANativeWindow* window,
108 ANativeWindow_queueBufferFn queueBuffer,
109 void* data, ANativeWindowBuffer* buffer,
110 int fenceFd);
111
112/**
113 * Registers an interceptor for ANativeWindow_cancelBuffer. Instead of calling
114 * the underlying cancelBuffer function, instead the provided interceptor is
115 * called, which may optionally call the underlying cancelBuffer function. An
116 * optional data pointer is also provided to side-channel additional arguments.
117 *
118 * Note that usage of this should only be used for specialized use-cases by
119 * either the system partition or to Mainline modules. This should never be
120 * exposed to NDK or LL-NDK.
121 *
122 * Returns NO_ERROR on success, -errno if registration failed.
123 */
124int ANativeWindow_setCancelBufferInterceptor(ANativeWindow* window,
125 ANativeWindow_cancelBufferInterceptor interceptor,
126 void* data);
127
128/**
129 * Registers an interceptor for ANativeWindow_dequeueBuffer. Instead of calling
130 * the underlying dequeueBuffer function, instead the provided interceptor is
131 * called, which may optionally call the underlying dequeueBuffer function. An
132 * optional data pointer is also provided to side-channel additional arguments.
133 *
134 * Note that usage of this should only be used for specialized use-cases by
135 * either the system partition or to Mainline modules. This should never be
136 * exposed to NDK or LL-NDK.
137 *
138 * Returns NO_ERROR on success, -errno if registration failed.
139 */
140int ANativeWindow_setDequeueBufferInterceptor(ANativeWindow* window,
141 ANativeWindow_dequeueBufferInterceptor interceptor,
142 void* data);
143/**
144 * Registers an interceptor for ANativeWindow_perform. Instead of calling
145 * the underlying perform function, instead the provided interceptor is
146 * called, which may optionally call the underlying perform function. An
147 * optional data pointer is also provided to side-channel additional arguments.
148 *
149 * Note that usage of this should only be used for specialized use-cases by
150 * either the system partition or to Mainline modules. This should never be
151 * exposed to NDK or LL-NDK.
152 *
153 * Returns NO_ERROR on success, -errno if registration failed.
154 */
155int ANativeWindow_setPerformInterceptor(ANativeWindow* window,
156 ANativeWindow_performInterceptor interceptor, void* data);
157/**
158 * Registers an interceptor for ANativeWindow_queueBuffer. Instead of calling
159 * the underlying queueBuffer function, instead the provided interceptor is
160 * called, which may optionally call the underlying queueBuffer function. An
161 * optional data pointer is also provided to side-channel additional arguments.
162 *
163 * Note that usage of this should only be used for specialized use-cases by
164 * either the system partition or to Mainline modules. This should never be
165 * exposed to NDK or LL-NDK.
166 *
167 * Returns NO_ERROR on success, -errno if registration failed.
168 */
169int ANativeWindow_setQueueBufferInterceptor(ANativeWindow* window,
170 ANativeWindow_queueBufferInterceptor interceptor,
171 void* data);
172
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700173/**
174 * Retrieves how long it took for the last time a buffer was dequeued.
175 *
Alec Mourid41a1be2020-02-14 15:18:11 -0800176 * \return the dequeue duration in nanoseconds
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700177 */
Alec Mouri72670c52019-08-31 01:54:33 -0700178int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window);
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700179
Alec Mouri0d1398b2019-08-14 10:53:50 -0700180/**
181 * Retrieves how long it took for the last time a buffer was queued.
182 *
Alec Mourid41a1be2020-02-14 15:18:11 -0800183 * \return the queue duration in nanoseconds
Alec Mouri0d1398b2019-08-14 10:53:50 -0700184 */
Alec Mouri72670c52019-08-31 01:54:33 -0700185int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window);
Alec Mouri0d1398b2019-08-14 10:53:50 -0700186
Alec Mouria1619662019-08-21 19:30:48 -0700187/**
188 * Retrieves the system time in nanoseconds when the last time a buffer
Alec Mourid41a1be2020-02-14 15:18:11 -0800189 * started to be dequeued.
Alec Mouria1619662019-08-21 19:30:48 -0700190 *
Alec Mourid41a1be2020-02-14 15:18:11 -0800191 * \return the start time in nanoseconds
Alec Mouria1619662019-08-21 19:30:48 -0700192 */
193int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window);
194
Alec Mouri04fdb602019-08-23 19:41:43 -0700195/**
196 * Sets a timeout in nanoseconds for dequeue calls. All subsequent dequeue calls
197 * made by the window will return -ETIMEDOUT after the timeout if the dequeue
198 * takes too long.
199 *
Alec Mourid41a1be2020-02-14 15:18:11 -0800200 * If the provided timeout is negative, hen this removes the previously configured
201 * timeout. The window then behaves as if ANativeWindow_setDequeueTimeout was
202 * never called.
203 *
204 * \return NO_ERROR on success
205 * \return BAD_VALUE if the dequeue timeout was unabled to be updated, as
206 * updating the dequeue timeout may change internals of the underlying window.
Alec Mouri04fdb602019-08-23 19:41:43 -0700207 */
208int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout);
209
Alec Mouri9fa2cb62019-07-15 17:36:26 -0700210__END_DECLS