| Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 20 | #include <stdarg.h> | 
| Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 21 |  | 
|  | 22 | // apex is a superset of the NDK | 
|  | 23 | #include <android/native_window.h> | 
|  | 24 |  | 
|  | 25 | __BEGIN_DECLS | 
|  | 26 |  | 
| Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 27 | /* | 
|  | 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 | */ | 
|  | 33 | enum 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 Abraham | dd5bfa9 | 2021-01-07 17:56:08 -0800 | [diff] [blame] | 42 | /* | 
|  | 43 | * Internal extension of compatibility value for ANativeWindow_setFrameRate. */ | 
|  | 44 | enum 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 Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 55 | /** | 
|  | 56 | * Prototype of the function that an ANativeWindow implementation would call | 
|  | 57 | * when ANativeWindow_cancelBuffer is called. | 
|  | 58 | */ | 
|  | 59 | typedef 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 | */ | 
|  | 68 | typedef 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 | */ | 
|  | 77 | typedef 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 | */ | 
|  | 86 | typedef 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 | */ | 
|  | 95 | typedef 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 | */ | 
|  | 103 | typedef 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 | */ | 
|  | 111 | typedef 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 | */ | 
|  | 120 | typedef 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 | */ | 
|  | 137 | int 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 | */ | 
|  | 153 | int 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 | */ | 
|  | 168 | int 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 | */ | 
|  | 182 | int ANativeWindow_setQueueBufferInterceptor(ANativeWindow* window, | 
|  | 183 | ANativeWindow_queueBufferInterceptor interceptor, | 
|  | 184 | void* data); | 
|  | 185 |  | 
| Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 186 | /** | 
|  | 187 | * Retrieves how long it took for the last time a buffer was dequeued. | 
|  | 188 | * | 
| Alec Mouri | d41a1be | 2020-02-14 15:18:11 -0800 | [diff] [blame] | 189 | * \return the dequeue duration in nanoseconds | 
| Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 190 | */ | 
| Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 191 | int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window); | 
| Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 192 |  | 
| Alec Mouri | 0d1398b | 2019-08-14 10:53:50 -0700 | [diff] [blame] | 193 | /** | 
|  | 194 | * Retrieves how long it took for the last time a buffer was queued. | 
|  | 195 | * | 
| Alec Mouri | d41a1be | 2020-02-14 15:18:11 -0800 | [diff] [blame] | 196 | * \return the queue duration in nanoseconds | 
| Alec Mouri | 0d1398b | 2019-08-14 10:53:50 -0700 | [diff] [blame] | 197 | */ | 
| Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 198 | int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window); | 
| Alec Mouri | 0d1398b | 2019-08-14 10:53:50 -0700 | [diff] [blame] | 199 |  | 
| Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 200 | /** | 
|  | 201 | * Retrieves the system time in nanoseconds when the last time a buffer | 
| Alec Mouri | d41a1be | 2020-02-14 15:18:11 -0800 | [diff] [blame] | 202 | * started to be dequeued. | 
| Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 203 | * | 
| Alec Mouri | d41a1be | 2020-02-14 15:18:11 -0800 | [diff] [blame] | 204 | * \return the start time in nanoseconds | 
| Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 205 | */ | 
|  | 206 | int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window); | 
|  | 207 |  | 
| Alec Mouri | 04fdb60 | 2019-08-23 19:41:43 -0700 | [diff] [blame] | 208 | /** | 
|  | 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 Mouri | d41a1be | 2020-02-14 15:18:11 -0800 | [diff] [blame] | 213 | * 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 Mouri | 04fdb60 | 2019-08-23 19:41:43 -0700 | [diff] [blame] | 220 | */ | 
|  | 221 | int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout); | 
|  | 222 |  | 
| Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 223 | __END_DECLS |