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> 20 #include <stdarg.h> 21 22 // apex is a superset of the NDK 23 #include <android/native_window.h> 24 25 __BEGIN_DECLS 26 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 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 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 186 /** 187 * Retrieves how long it took for the last time a buffer was dequeued. 188 * 189 * \return the dequeue duration in nanoseconds 190 */ 191 int64_t ANativeWindow_getLastDequeueDuration(ANativeWindow* window); 192 193 /** 194 * Retrieves how long it took for the last time a buffer was queued. 195 * 196 * \return the queue duration in nanoseconds 197 */ 198 int64_t ANativeWindow_getLastQueueDuration(ANativeWindow* window); 199 200 /** 201 * Retrieves the system time in nanoseconds when the last time a buffer 202 * started to be dequeued. 203 * 204 * \return the start time in nanoseconds 205 */ 206 int64_t ANativeWindow_getLastDequeueStartTime(ANativeWindow* window); 207 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 * 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. 220 */ 221 int ANativeWindow_setDequeueTimeout(ANativeWindow* window, int64_t timeout); 222 223 __END_DECLS 224