Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | * |
| 19 | * IMPORTANT: |
| 20 | * |
| 21 | * There is an old copy of this file in system/core/include/system/window.h, which exists only |
| 22 | * for backward source compatibility. |
| 23 | * But there are binaries out there as well, so this version of window.h must stay binary |
| 24 | * backward compatible with the one found in system/core. |
| 25 | * |
| 26 | * |
| 27 | * Source compatibility is also required for now, because this is how we're handling the |
| 28 | * transition from system/core/include (global include path) to nativewindow/include. |
| 29 | * |
| 30 | *************************************************************************************************/ |
| 31 | |
| 32 | #pragma once |
| 33 | |
| 34 | #include <cutils/native_handle.h> |
| 35 | #include <errno.h> |
| 36 | #include <limits.h> |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 37 | #include <stdbool.h> |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 38 | #include <stdint.h> |
| 39 | #include <string.h> |
| 40 | #include <sys/cdefs.h> |
| 41 | #include <system/graphics.h> |
| 42 | #include <unistd.h> |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 43 | |
John Reck | db164ff | 2024-04-03 16:59:28 -0400 | [diff] [blame] | 44 | #include <vndk/hardware_buffer.h> |
| 45 | |
Alec Mouri | 9fa2cb6 | 2019-07-15 17:36:26 -0700 | [diff] [blame] | 46 | // system/window.h is a superset of the vndk and apex apis |
| 47 | #include <apex/window.h> |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 48 | #include <vndk/window.h> |
| 49 | |
| 50 | |
| 51 | #ifndef __UNUSED |
| 52 | #define __UNUSED __attribute__((__unused__)) |
| 53 | #endif |
| 54 | #ifndef __deprecated |
| 55 | #define __deprecated __attribute__((__deprecated__)) |
| 56 | #endif |
| 57 | |
| 58 | __BEGIN_DECLS |
| 59 | |
| 60 | /*****************************************************************************/ |
| 61 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 62 | #define ANDROID_NATIVE_WINDOW_MAGIC ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d') |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 63 | |
| 64 | // --------------------------------------------------------------------------- |
| 65 | |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 66 | /* attributes queriable with query() */ |
| 67 | enum { |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 68 | NATIVE_WINDOW_WIDTH = 0, |
| 69 | NATIVE_WINDOW_HEIGHT = 1, |
| 70 | NATIVE_WINDOW_FORMAT = 2, |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 71 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 72 | /* see ANativeWindowQuery in vndk/window.h */ |
| 73 | NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS, |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 74 | |
| 75 | /* Check whether queueBuffer operations on the ANativeWindow send the buffer |
| 76 | * to the window compositor. The query sets the returned 'value' argument |
| 77 | * to 1 if the ANativeWindow DOES send queued buffers directly to the window |
| 78 | * compositor and 0 if the buffers do not go directly to the window |
| 79 | * compositor. |
| 80 | * |
| 81 | * This can be used to determine whether protected buffer content should be |
| 82 | * sent to the ANativeWindow. Note, however, that a result of 1 does NOT |
| 83 | * indicate that queued buffers will be protected from applications or users |
| 84 | * capturing their contents. If that behavior is desired then some other |
| 85 | * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in |
| 86 | * conjunction with this query. |
| 87 | */ |
| 88 | NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4, |
| 89 | |
| 90 | /* Get the concrete type of a ANativeWindow. See below for the list of |
| 91 | * possible return values. |
| 92 | * |
| 93 | * This query should not be used outside the Android framework and will |
| 94 | * likely be removed in the near future. |
| 95 | */ |
| 96 | NATIVE_WINDOW_CONCRETE_TYPE = 5, |
| 97 | |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 98 | /* |
| 99 | * Default width and height of ANativeWindow buffers, these are the |
| 100 | * dimensions of the window buffers irrespective of the |
| 101 | * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window |
| 102 | * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS. |
| 103 | */ |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 104 | NATIVE_WINDOW_DEFAULT_WIDTH = ANATIVEWINDOW_QUERY_DEFAULT_WIDTH, |
| 105 | NATIVE_WINDOW_DEFAULT_HEIGHT = ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT, |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 106 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 107 | /* see ANativeWindowQuery in vndk/window.h */ |
| 108 | NATIVE_WINDOW_TRANSFORM_HINT = ANATIVEWINDOW_QUERY_TRANSFORM_HINT, |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 109 | |
| 110 | /* |
| 111 | * Boolean that indicates whether the consumer is running more than |
| 112 | * one buffer behind the producer. |
| 113 | */ |
| 114 | NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9, |
| 115 | |
| 116 | /* |
| 117 | * The consumer gralloc usage bits currently set by the consumer. |
| 118 | * The values are defined in hardware/libhardware/include/gralloc.h. |
| 119 | */ |
Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 120 | NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10, /* deprecated */ |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * Transformation that will by applied to buffers by the hwcomposer. |
| 124 | * This must not be set or checked by producer endpoints, and will |
| 125 | * disable the transform hint set in SurfaceFlinger (see |
| 126 | * NATIVE_WINDOW_TRANSFORM_HINT). |
| 127 | * |
| 128 | * INTENDED USE: |
| 129 | * Temporary - Please do not use this. This is intended only to be used |
| 130 | * by the camera's LEGACY mode. |
| 131 | * |
| 132 | * In situations where a SurfaceFlinger client wishes to set a transform |
| 133 | * that is not visible to the producer, and will always be applied in the |
| 134 | * hardware composer, the client can set this flag with |
| 135 | * native_window_set_buffers_sticky_transform. This can be used to rotate |
| 136 | * and flip buffers consumed by hardware composer without actually changing |
| 137 | * the aspect ratio of the buffers produced. |
| 138 | */ |
| 139 | NATIVE_WINDOW_STICKY_TRANSFORM = 11, |
| 140 | |
| 141 | /** |
| 142 | * The default data space for the buffers as set by the consumer. |
| 143 | * The values are defined in graphics.h. |
| 144 | */ |
| 145 | NATIVE_WINDOW_DEFAULT_DATASPACE = 12, |
| 146 | |
Mathias Agopian | 000879a | 2017-03-20 18:07:26 -0700 | [diff] [blame] | 147 | /* see ANativeWindowQuery in vndk/window.h */ |
| 148 | NATIVE_WINDOW_BUFFER_AGE = ANATIVEWINDOW_QUERY_BUFFER_AGE, |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * Returns the duration of the last dequeueBuffer call in microseconds |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 152 | * Deprecated: please use NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION in |
| 153 | * perform() instead, which supports nanosecond precision. |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 154 | */ |
| 155 | NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14, |
| 156 | |
| 157 | /* |
| 158 | * Returns the duration of the last queueBuffer call in microseconds |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 159 | * Deprecated: please use NATIVE_WINDOW_GET_LAST_QUEUE_DURATION in |
| 160 | * perform() instead, which supports nanosecond precision. |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 161 | */ |
| 162 | NATIVE_WINDOW_LAST_QUEUE_DURATION = 15, |
| 163 | |
| 164 | /* |
| 165 | * Returns the number of image layers that the ANativeWindow buffer |
| 166 | * contains. By default this is 1, unless a buffer is explicitly allocated |
| 167 | * to contain multiple layers. |
| 168 | */ |
| 169 | NATIVE_WINDOW_LAYER_COUNT = 16, |
| 170 | |
| 171 | /* |
| 172 | * Returns 1 if the native window is valid, 0 otherwise. native window is valid |
| 173 | * if it is safe (i.e. no crash will occur) to call any method on it. |
| 174 | */ |
| 175 | NATIVE_WINDOW_IS_VALID = 17, |
Brian Anderson | 6b37671 | 2017-04-04 10:51:39 -0700 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * Returns 1 if NATIVE_WINDOW_GET_FRAME_TIMESTAMPS will return display |
| 179 | * present info, 0 if it won't. |
| 180 | */ |
| 181 | NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18, |
Jiwen 'Steve' Cai | 2041913 | 2017-04-21 18:49:53 -0700 | [diff] [blame] | 182 | |
| 183 | /* |
| 184 | * The consumer end is capable of handling protected buffers, i.e. buffer |
| 185 | * with GRALLOC_USAGE_PROTECTED usage bits on. |
| 186 | */ |
| 187 | NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19, |
Peiyong Lin | 654f87b | 2018-01-30 14:21:33 -0800 | [diff] [blame] | 188 | |
| 189 | /* |
| 190 | * Returns data space for the buffers. |
| 191 | */ |
| 192 | NATIVE_WINDOW_DATASPACE = 20, |
Yiwei Zhang | dbd9615 | 2018-02-08 14:22:53 -0800 | [diff] [blame] | 193 | |
| 194 | /* |
| 195 | * Returns maxBufferCount set by BufferQueueConsumer |
| 196 | */ |
| 197 | NATIVE_WINDOW_MAX_BUFFER_COUNT = 21, |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | /* Valid operations for the (*perform)() hook. |
| 201 | * |
| 202 | * Values marked as 'deprecated' are supported, but have been superceded by |
| 203 | * other functionality. |
| 204 | * |
| 205 | * Values marked as 'private' should be considered private to the framework. |
| 206 | * HAL implementation code with access to an ANativeWindow should not use these, |
| 207 | * as it may not interact properly with the framework's use of the |
| 208 | * ANativeWindow. |
| 209 | */ |
| 210 | enum { |
Valerie Hau | a82679d | 2018-11-21 09:31:43 -0800 | [diff] [blame] | 211 | // clang-format off |
Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 212 | NATIVE_WINDOW_SET_USAGE = ANATIVEWINDOW_PERFORM_SET_USAGE, /* deprecated */ |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 213 | NATIVE_WINDOW_CONNECT = 1, /* deprecated */ |
| 214 | NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */ |
| 215 | NATIVE_WINDOW_SET_CROP = 3, /* private */ |
| 216 | NATIVE_WINDOW_SET_BUFFER_COUNT = 4, |
Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 217 | NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = ANATIVEWINDOW_PERFORM_SET_BUFFERS_GEOMETRY, /* deprecated */ |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 218 | NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6, |
| 219 | NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7, |
| 220 | NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8, |
Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 221 | NATIVE_WINDOW_SET_BUFFERS_FORMAT = ANATIVEWINDOW_PERFORM_SET_BUFFERS_FORMAT, |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 222 | NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */ |
| 223 | NATIVE_WINDOW_LOCK = 11, /* private */ |
| 224 | NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */ |
| 225 | NATIVE_WINDOW_API_CONNECT = 13, /* private */ |
| 226 | NATIVE_WINDOW_API_DISCONNECT = 14, /* private */ |
| 227 | NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */ |
| 228 | NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* deprecated, unimplemented */ |
| 229 | NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17, /* private */ |
| 230 | NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18, |
| 231 | NATIVE_WINDOW_SET_BUFFERS_DATASPACE = 19, |
| 232 | NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */ |
| 233 | NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21, |
| 234 | NATIVE_WINDOW_SET_AUTO_REFRESH = 22, |
| 235 | NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION = 23, |
| 236 | NATIVE_WINDOW_GET_NEXT_FRAME_ID = 24, |
| 237 | NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS = 25, |
| 238 | NATIVE_WINDOW_GET_COMPOSITOR_TIMING = 26, |
| 239 | NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 27, |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 240 | /* 28, removed: NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT */ |
| 241 | /* 29, removed: NATIVE_WINDOW_GET_HDR_SUPPORT */ |
Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 242 | NATIVE_WINDOW_SET_USAGE64 = ANATIVEWINDOW_PERFORM_SET_USAGE64, |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 243 | NATIVE_WINDOW_GET_CONSUMER_USAGE64 = 31, |
| 244 | NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA = 32, |
| 245 | NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA = 33, |
Valerie Hau | a82679d | 2018-11-21 09:31:43 -0800 | [diff] [blame] | 246 | NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA = 34, |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 247 | NATIVE_WINDOW_SET_AUTO_PREROTATION = 35, |
Alec Mouri | a161966 | 2019-08-21 19:30:48 -0700 | [diff] [blame] | 248 | NATIVE_WINDOW_GET_LAST_DEQUEUE_START = 36, /* private */ |
Alec Mouri | 04fdb60 | 2019-08-23 19:41:43 -0700 | [diff] [blame] | 249 | NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT = 37, /* private */ |
Alec Mouri | 72670c5 | 2019-08-31 01:54:33 -0700 | [diff] [blame] | 250 | NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION = 38, /* private */ |
| 251 | NATIVE_WINDOW_GET_LAST_QUEUE_DURATION = 39, /* private */ |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 252 | NATIVE_WINDOW_SET_FRAME_RATE = 40, |
Alec Mouri | 09d122a | 2019-11-25 10:00:53 -0800 | [diff] [blame] | 253 | NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR = 41, /* private */ |
| 254 | NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR = 42, /* private */ |
| 255 | NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR = 43, /* private */ |
| 256 | NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR = 44, /* private */ |
Alec Mouri | 74aef6d | 2019-12-09 17:10:24 -0800 | [diff] [blame] | 257 | NATIVE_WINDOW_ALLOCATE_BUFFERS = 45, /* private */ |
Alec Mouri | ef0b153 | 2019-12-17 09:39:07 -0800 | [diff] [blame] | 258 | NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER = 46, /* private */ |
John Reck | 401cda6 | 2020-05-07 16:04:41 -0700 | [diff] [blame] | 259 | NATIVE_WINDOW_SET_QUERY_INTERCEPTOR = 47, /* private */ |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 260 | NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO = 48, /* private */ |
Ady Abraham | 0bde6b5 | 2021-05-18 13:57:02 -0700 | [diff] [blame] | 261 | NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2 = 49, /* private */ |
John Reck | db164ff | 2024-04-03 16:59:28 -0400 | [diff] [blame] | 262 | NATIVE_WINDOW_SET_BUFFERS_ADDITIONAL_OPTIONS = 50, |
Valerie Hau | a82679d | 2018-11-21 09:31:43 -0800 | [diff] [blame] | 263 | // clang-format on |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | /* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */ |
| 267 | enum { |
| 268 | /* Buffers will be queued by EGL via eglSwapBuffers after being filled using |
| 269 | * OpenGL ES. |
| 270 | */ |
| 271 | NATIVE_WINDOW_API_EGL = 1, |
| 272 | |
| 273 | /* Buffers will be queued after being filled using the CPU |
| 274 | */ |
| 275 | NATIVE_WINDOW_API_CPU = 2, |
| 276 | |
| 277 | /* Buffers will be queued by Stagefright after being filled by a video |
| 278 | * decoder. The video decoder can either be a software or hardware decoder. |
| 279 | */ |
| 280 | NATIVE_WINDOW_API_MEDIA = 3, |
| 281 | |
| 282 | /* Buffers will be queued by the the camera HAL. |
| 283 | */ |
| 284 | NATIVE_WINDOW_API_CAMERA = 4, |
| 285 | }; |
| 286 | |
| 287 | /* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */ |
| 288 | enum { |
| 289 | /* flip source image horizontally */ |
| 290 | NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H , |
| 291 | /* flip source image vertically */ |
| 292 | NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, |
| 293 | /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */ |
| 294 | NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, |
| 295 | /* rotate source image 180 degrees */ |
| 296 | NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, |
| 297 | /* rotate source image 270 degrees clock-wise */ |
| 298 | NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, |
| 299 | /* transforms source by the inverse transform of the screen it is displayed onto. This |
| 300 | * transform is applied last */ |
| 301 | NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08 |
| 302 | }; |
| 303 | |
| 304 | /* parameter for NATIVE_WINDOW_SET_SCALING_MODE |
| 305 | * keep in sync with Surface.java in frameworks/base */ |
| 306 | enum { |
| 307 | /* the window content is not updated (frozen) until a buffer of |
| 308 | * the window size is received (enqueued) |
| 309 | */ |
| 310 | NATIVE_WINDOW_SCALING_MODE_FREEZE = 0, |
| 311 | /* the buffer is scaled in both dimensions to match the window size */ |
| 312 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1, |
| 313 | /* the buffer is scaled uniformly such that the smaller dimension |
| 314 | * of the buffer matches the window size (cropping in the process) |
| 315 | */ |
| 316 | NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2, |
| 317 | /* the window is clipped to the size of the buffer's crop rectangle; pixels |
| 318 | * outside the crop rectangle are treated as if they are completely |
| 319 | * transparent. |
| 320 | */ |
| 321 | NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3, |
| 322 | }; |
| 323 | |
| 324 | /* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */ |
| 325 | enum { |
| 326 | NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */ |
| 327 | NATIVE_WINDOW_SURFACE = 1, /* Surface */ |
| 328 | }; |
| 329 | |
| 330 | /* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP |
| 331 | * |
| 332 | * Special timestamp value to indicate that timestamps should be auto-generated |
| 333 | * by the native window when queueBuffer is called. This is equal to INT64_MIN, |
| 334 | * defined directly to avoid problems with C99/C++ inclusion of stdint.h. |
| 335 | */ |
| 336 | static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1); |
| 337 | |
Brian Anderson | dc96fdf | 2017-03-20 16:54:25 -0700 | [diff] [blame] | 338 | /* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS |
| 339 | * |
| 340 | * Special timestamp value to indicate the timestamps aren't yet known or |
| 341 | * that they are invalid. |
| 342 | */ |
| 343 | static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2; |
| 344 | static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1; |
| 345 | |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 346 | struct ANativeWindow |
| 347 | { |
| 348 | #ifdef __cplusplus |
| 349 | ANativeWindow() |
| 350 | : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) |
| 351 | { |
| 352 | common.magic = ANDROID_NATIVE_WINDOW_MAGIC; |
| 353 | common.version = sizeof(ANativeWindow); |
| 354 | memset(common.reserved, 0, sizeof(common.reserved)); |
| 355 | } |
| 356 | |
| 357 | /* Implement the methods that sp<ANativeWindow> expects so that it |
| 358 | can be used to automatically refcount ANativeWindow's. */ |
| 359 | void incStrong(const void* /*id*/) const { |
| 360 | common.incRef(const_cast<android_native_base_t*>(&common)); |
| 361 | } |
| 362 | void decStrong(const void* /*id*/) const { |
| 363 | common.decRef(const_cast<android_native_base_t*>(&common)); |
| 364 | } |
| 365 | #endif |
| 366 | |
| 367 | struct android_native_base_t common; |
| 368 | |
| 369 | /* flags describing some attributes of this surface or its updater */ |
| 370 | const uint32_t flags; |
| 371 | |
| 372 | /* min swap interval supported by this updated */ |
| 373 | const int minSwapInterval; |
| 374 | |
| 375 | /* max swap interval supported by this updated */ |
| 376 | const int maxSwapInterval; |
| 377 | |
| 378 | /* horizontal and vertical resolution in DPI */ |
| 379 | const float xdpi; |
| 380 | const float ydpi; |
| 381 | |
| 382 | /* Some storage reserved for the OEM's driver. */ |
| 383 | intptr_t oem[4]; |
| 384 | |
| 385 | /* |
| 386 | * Set the swap interval for this surface. |
| 387 | * |
| 388 | * Returns 0 on success or -errno on error. |
| 389 | */ |
| 390 | int (*setSwapInterval)(struct ANativeWindow* window, |
| 391 | int interval); |
| 392 | |
| 393 | /* |
| 394 | * Hook called by EGL to acquire a buffer. After this call, the buffer |
| 395 | * is not locked, so its content cannot be modified. This call may block if |
| 396 | * no buffers are available. |
| 397 | * |
| 398 | * The window holds a reference to the buffer between dequeueBuffer and |
| 399 | * either queueBuffer or cancelBuffer, so clients only need their own |
| 400 | * reference if they might use the buffer after queueing or canceling it. |
| 401 | * Holding a reference to a buffer after queueing or canceling it is only |
| 402 | * allowed if a specific buffer count has been set. |
| 403 | * |
| 404 | * Returns 0 on success or -errno on error. |
| 405 | * |
| 406 | * XXX: This function is deprecated. It will continue to work for some |
| 407 | * time for binary compatibility, but the new dequeueBuffer function that |
| 408 | * outputs a fence file descriptor should be used in its place. |
| 409 | */ |
| 410 | int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window, |
| 411 | struct ANativeWindowBuffer** buffer); |
| 412 | |
| 413 | /* |
| 414 | * hook called by EGL to lock a buffer. This MUST be called before modifying |
| 415 | * the content of a buffer. The buffer must have been acquired with |
| 416 | * dequeueBuffer first. |
| 417 | * |
| 418 | * Returns 0 on success or -errno on error. |
| 419 | * |
| 420 | * XXX: This function is deprecated. It will continue to work for some |
| 421 | * time for binary compatibility, but it is essentially a no-op, and calls |
| 422 | * to it should be removed. |
| 423 | */ |
| 424 | int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window, |
| 425 | struct ANativeWindowBuffer* buffer); |
| 426 | |
| 427 | /* |
| 428 | * Hook called by EGL when modifications to the render buffer are done. |
| 429 | * This unlocks and post the buffer. |
| 430 | * |
| 431 | * The window holds a reference to the buffer between dequeueBuffer and |
| 432 | * either queueBuffer or cancelBuffer, so clients only need their own |
| 433 | * reference if they might use the buffer after queueing or canceling it. |
| 434 | * Holding a reference to a buffer after queueing or canceling it is only |
| 435 | * allowed if a specific buffer count has been set. |
| 436 | * |
| 437 | * Buffers MUST be queued in the same order than they were dequeued. |
| 438 | * |
| 439 | * Returns 0 on success or -errno on error. |
| 440 | * |
| 441 | * XXX: This function is deprecated. It will continue to work for some |
| 442 | * time for binary compatibility, but the new queueBuffer function that |
| 443 | * takes a fence file descriptor should be used in its place (pass a value |
| 444 | * of -1 for the fence file descriptor if there is no valid one to pass). |
| 445 | */ |
| 446 | int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window, |
| 447 | struct ANativeWindowBuffer* buffer); |
| 448 | |
| 449 | /* |
| 450 | * hook used to retrieve information about the native window. |
| 451 | * |
| 452 | * Returns 0 on success or -errno on error. |
| 453 | */ |
| 454 | int (*query)(const struct ANativeWindow* window, |
| 455 | int what, int* value); |
| 456 | |
| 457 | /* |
| 458 | * hook used to perform various operations on the surface. |
| 459 | * (*perform)() is a generic mechanism to add functionality to |
| 460 | * ANativeWindow while keeping backward binary compatibility. |
| 461 | * |
| 462 | * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions |
| 463 | * defined below. |
| 464 | * |
| 465 | * (*perform)() returns -ENOENT if the 'what' parameter is not supported |
| 466 | * by the surface's implementation. |
| 467 | * |
| 468 | * See above for a list of valid operations, such as |
| 469 | * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT |
| 470 | */ |
| 471 | int (*perform)(struct ANativeWindow* window, |
| 472 | int operation, ... ); |
| 473 | |
| 474 | /* |
| 475 | * Hook used to cancel a buffer that has been dequeued. |
| 476 | * No synchronization is performed between dequeue() and cancel(), so |
| 477 | * either external synchronization is needed, or these functions must be |
| 478 | * called from the same thread. |
| 479 | * |
| 480 | * The window holds a reference to the buffer between dequeueBuffer and |
| 481 | * either queueBuffer or cancelBuffer, so clients only need their own |
| 482 | * reference if they might use the buffer after queueing or canceling it. |
| 483 | * Holding a reference to a buffer after queueing or canceling it is only |
| 484 | * allowed if a specific buffer count has been set. |
| 485 | * |
| 486 | * XXX: This function is deprecated. It will continue to work for some |
| 487 | * time for binary compatibility, but the new cancelBuffer function that |
| 488 | * takes a fence file descriptor should be used in its place (pass a value |
| 489 | * of -1 for the fence file descriptor if there is no valid one to pass). |
| 490 | */ |
| 491 | int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window, |
| 492 | struct ANativeWindowBuffer* buffer); |
| 493 | |
| 494 | /* |
| 495 | * Hook called by EGL to acquire a buffer. This call may block if no |
| 496 | * buffers are available. |
| 497 | * |
| 498 | * The window holds a reference to the buffer between dequeueBuffer and |
| 499 | * either queueBuffer or cancelBuffer, so clients only need their own |
| 500 | * reference if they might use the buffer after queueing or canceling it. |
| 501 | * Holding a reference to a buffer after queueing or canceling it is only |
| 502 | * allowed if a specific buffer count has been set. |
| 503 | * |
| 504 | * The libsync fence file descriptor returned in the int pointed to by the |
| 505 | * fenceFd argument will refer to the fence that must signal before the |
| 506 | * dequeued buffer may be written to. A value of -1 indicates that the |
| 507 | * caller may access the buffer immediately without waiting on a fence. If |
| 508 | * a valid file descriptor is returned (i.e. any value except -1) then the |
| 509 | * caller is responsible for closing the file descriptor. |
| 510 | * |
| 511 | * Returns 0 on success or -errno on error. |
| 512 | */ |
| 513 | int (*dequeueBuffer)(struct ANativeWindow* window, |
| 514 | struct ANativeWindowBuffer** buffer, int* fenceFd); |
| 515 | |
| 516 | /* |
| 517 | * Hook called by EGL when modifications to the render buffer are done. |
| 518 | * This unlocks and post the buffer. |
| 519 | * |
| 520 | * The window holds a reference to the buffer between dequeueBuffer and |
| 521 | * either queueBuffer or cancelBuffer, so clients only need their own |
| 522 | * reference if they might use the buffer after queueing or canceling it. |
| 523 | * Holding a reference to a buffer after queueing or canceling it is only |
| 524 | * allowed if a specific buffer count has been set. |
| 525 | * |
| 526 | * The fenceFd argument specifies a libsync fence file descriptor for a |
| 527 | * fence that must signal before the buffer can be accessed. If the buffer |
| 528 | * can be accessed immediately then a value of -1 should be used. The |
| 529 | * caller must not use the file descriptor after it is passed to |
| 530 | * queueBuffer, and the ANativeWindow implementation is responsible for |
| 531 | * closing it. |
| 532 | * |
| 533 | * Returns 0 on success or -errno on error. |
| 534 | */ |
| 535 | int (*queueBuffer)(struct ANativeWindow* window, |
| 536 | struct ANativeWindowBuffer* buffer, int fenceFd); |
| 537 | |
| 538 | /* |
| 539 | * Hook used to cancel a buffer that has been dequeued. |
| 540 | * No synchronization is performed between dequeue() and cancel(), so |
| 541 | * either external synchronization is needed, or these functions must be |
| 542 | * called from the same thread. |
| 543 | * |
| 544 | * The window holds a reference to the buffer between dequeueBuffer and |
| 545 | * either queueBuffer or cancelBuffer, so clients only need their own |
| 546 | * reference if they might use the buffer after queueing or canceling it. |
| 547 | * Holding a reference to a buffer after queueing or canceling it is only |
| 548 | * allowed if a specific buffer count has been set. |
| 549 | * |
| 550 | * The fenceFd argument specifies a libsync fence file decsriptor for a |
| 551 | * fence that must signal before the buffer can be accessed. If the buffer |
| 552 | * can be accessed immediately then a value of -1 should be used. |
| 553 | * |
| 554 | * Note that if the client has not waited on the fence that was returned |
| 555 | * from dequeueBuffer, that same fence should be passed to cancelBuffer to |
| 556 | * ensure that future uses of the buffer are preceded by a wait on that |
| 557 | * fence. The caller must not use the file descriptor after it is passed |
| 558 | * to cancelBuffer, and the ANativeWindow implementation is responsible for |
| 559 | * closing it. |
| 560 | * |
| 561 | * Returns 0 on success or -errno on error. |
| 562 | */ |
| 563 | int (*cancelBuffer)(struct ANativeWindow* window, |
| 564 | struct ANativeWindowBuffer* buffer, int fenceFd); |
| 565 | }; |
| 566 | |
| 567 | /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C). |
| 568 | * android_native_window_t is deprecated. |
| 569 | */ |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 570 | typedef struct ANativeWindow android_native_window_t __deprecated; |
| 571 | |
| 572 | /* |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 573 | * native_window_set_usage64(..., usage) |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 574 | * Sets the intended usage flags for the next buffers |
| 575 | * acquired with (*lockBuffer)() and on. |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 576 | * |
| 577 | * Valid usage flags are defined in android/hardware_buffer.h |
| 578 | * All AHARDWAREBUFFER_USAGE_* flags can be specified as needed. |
| 579 | * |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 580 | * Calling this function will usually cause following buffers to be |
| 581 | * reallocated. |
| 582 | */ |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 583 | static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) { |
| 584 | return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage); |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* deprecated. Always returns 0. Don't call. */ |
| 588 | static inline int native_window_connect( |
| 589 | struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated; |
| 590 | |
| 591 | static inline int native_window_connect( |
| 592 | struct ANativeWindow* window __UNUSED, int api __UNUSED) { |
| 593 | return 0; |
| 594 | } |
| 595 | |
| 596 | /* deprecated. Always returns 0. Don't call. */ |
| 597 | static inline int native_window_disconnect( |
| 598 | struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated; |
| 599 | |
| 600 | static inline int native_window_disconnect( |
| 601 | struct ANativeWindow* window __UNUSED, int api __UNUSED) { |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | /* |
| 606 | * native_window_set_crop(..., crop) |
| 607 | * Sets which region of the next queued buffers needs to be considered. |
| 608 | * Depending on the scaling mode, a buffer's crop region is scaled and/or |
| 609 | * cropped to match the surface's size. This function sets the crop in |
| 610 | * pre-transformed buffer pixel coordinates. |
| 611 | * |
| 612 | * The specified crop region applies to all buffers queued after it is called. |
| 613 | * |
| 614 | * If 'crop' is NULL, subsequently queued buffers won't be cropped. |
| 615 | * |
| 616 | * An error is returned if for instance the crop region is invalid, out of the |
| 617 | * buffer's bound or if the window is invalid. |
| 618 | */ |
| 619 | static inline int native_window_set_crop( |
| 620 | struct ANativeWindow* window, |
| 621 | android_native_rect_t const * crop) |
| 622 | { |
| 623 | return window->perform(window, NATIVE_WINDOW_SET_CROP, crop); |
| 624 | } |
| 625 | |
| 626 | /* |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 627 | * native_window_set_buffer_count(..., count) |
| 628 | * Sets the number of buffers associated with this native window. |
| 629 | */ |
| 630 | static inline int native_window_set_buffer_count( |
| 631 | struct ANativeWindow* window, |
| 632 | size_t bufferCount) |
| 633 | { |
| 634 | return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount); |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * native_window_set_buffers_geometry(..., int w, int h, int format) |
| 639 | * All buffers dequeued after this call will have the dimensions and format |
| 640 | * specified. A successful call to this function has the same effect as calling |
| 641 | * native_window_set_buffers_size and native_window_set_buffers_format. |
| 642 | * |
| 643 | * XXX: This function is deprecated. The native_window_set_buffers_dimensions |
| 644 | * and native_window_set_buffers_format functions should be used instead. |
| 645 | */ |
| 646 | static inline int native_window_set_buffers_geometry( |
| 647 | struct ANativeWindow* window, |
| 648 | int w, int h, int format) __deprecated; |
| 649 | |
| 650 | static inline int native_window_set_buffers_geometry( |
| 651 | struct ANativeWindow* window, |
| 652 | int w, int h, int format) |
| 653 | { |
| 654 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, |
| 655 | w, h, format); |
| 656 | } |
| 657 | |
| 658 | /* |
| 659 | * native_window_set_buffers_dimensions(..., int w, int h) |
| 660 | * All buffers dequeued after this call will have the dimensions specified. |
| 661 | * In particular, all buffers will have a fixed-size, independent from the |
| 662 | * native-window size. They will be scaled according to the scaling mode |
| 663 | * (see native_window_set_scaling_mode) upon window composition. |
| 664 | * |
| 665 | * If w and h are 0, the normal behavior is restored. That is, dequeued buffers |
| 666 | * following this call will be sized to match the window's size. |
| 667 | * |
| 668 | * Calling this function will reset the window crop to a NULL value, which |
| 669 | * disables cropping of the buffers. |
| 670 | */ |
| 671 | static inline int native_window_set_buffers_dimensions( |
| 672 | struct ANativeWindow* window, |
| 673 | int w, int h) |
| 674 | { |
| 675 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS, |
| 676 | w, h); |
| 677 | } |
| 678 | |
| 679 | /* |
| 680 | * native_window_set_buffers_user_dimensions(..., int w, int h) |
| 681 | * |
| 682 | * Sets the user buffer size for the window, which overrides the |
| 683 | * window's size. All buffers dequeued after this call will have the |
| 684 | * dimensions specified unless overridden by |
| 685 | * native_window_set_buffers_dimensions. All buffers will have a |
| 686 | * fixed-size, independent from the native-window size. They will be |
| 687 | * scaled according to the scaling mode (see |
| 688 | * native_window_set_scaling_mode) upon window composition. |
| 689 | * |
| 690 | * If w and h are 0, the normal behavior is restored. That is, the |
| 691 | * default buffer size will match the windows's size. |
| 692 | * |
| 693 | * Calling this function will reset the window crop to a NULL value, which |
| 694 | * disables cropping of the buffers. |
| 695 | */ |
| 696 | static inline int native_window_set_buffers_user_dimensions( |
| 697 | struct ANativeWindow* window, |
| 698 | int w, int h) |
| 699 | { |
| 700 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS, |
| 701 | w, h); |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | * native_window_set_buffers_format(..., int format) |
| 706 | * All buffers dequeued after this call will have the format specified. |
| 707 | * |
| 708 | * If the specified format is 0, the default buffer format will be used. |
| 709 | */ |
| 710 | static inline int native_window_set_buffers_format( |
| 711 | struct ANativeWindow* window, |
| 712 | int format) |
| 713 | { |
| 714 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format); |
| 715 | } |
| 716 | |
| 717 | /* |
| 718 | * native_window_set_buffers_data_space(..., int dataSpace) |
| 719 | * All buffers queued after this call will be associated with the dataSpace |
| 720 | * parameter specified. |
| 721 | * |
| 722 | * dataSpace specifies additional information about the buffer that's dependent |
| 723 | * on the buffer format and the endpoints. For example, it can be used to convey |
| 724 | * the color space of the image data in the buffer, or it can be used to |
| 725 | * indicate that the buffers contain depth measurement data instead of color |
| 726 | * images. The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been |
| 727 | * overridden by the consumer. |
| 728 | */ |
| 729 | static inline int native_window_set_buffers_data_space( |
| 730 | struct ANativeWindow* window, |
| 731 | android_dataspace_t dataSpace) |
| 732 | { |
| 733 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE, |
| 734 | dataSpace); |
| 735 | } |
| 736 | |
| 737 | /* |
Courtney Goeltzenleuchter | 9bad0d7 | 2017-12-19 12:34:34 -0700 | [diff] [blame] | 738 | * native_window_set_buffers_smpte2086_metadata(..., metadata) |
| 739 | * All buffers queued after this call will be associated with the SMPTE |
| 740 | * ST.2086 metadata specified. |
| 741 | * |
| 742 | * metadata specifies additional information about the contents of the buffer |
| 743 | * that may affect how it's displayed. When it is nullptr, it means no such |
| 744 | * information is available. No SMPTE ST.2086 metadata is associated with the |
| 745 | * buffers by default. |
| 746 | */ |
| 747 | static inline int native_window_set_buffers_smpte2086_metadata( |
| 748 | struct ANativeWindow* window, |
| 749 | const struct android_smpte2086_metadata* metadata) |
| 750 | { |
| 751 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA, |
| 752 | metadata); |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | * native_window_set_buffers_cta861_3_metadata(..., metadata) |
| 757 | * All buffers queued after this call will be associated with the CTA-861.3 |
| 758 | * metadata specified. |
| 759 | * |
| 760 | * metadata specifies additional information about the contents of the buffer |
| 761 | * that may affect how it's displayed. When it is nullptr, it means no such |
| 762 | * information is available. No CTA-861.3 metadata is associated with the |
| 763 | * buffers by default. |
| 764 | */ |
| 765 | static inline int native_window_set_buffers_cta861_3_metadata( |
| 766 | struct ANativeWindow* window, |
| 767 | const struct android_cta861_3_metadata* metadata) |
| 768 | { |
| 769 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA, |
| 770 | metadata); |
| 771 | } |
| 772 | |
| 773 | /* |
Valerie Hau | a82679d | 2018-11-21 09:31:43 -0800 | [diff] [blame] | 774 | * native_window_set_buffers_hdr10_plus_metadata(..., metadata) |
| 775 | * All buffers queued after this call will be associated with the |
| 776 | * HDR10+ dynamic metadata specified. |
| 777 | * |
| 778 | * metadata specifies additional dynamic information about the |
| 779 | * contents of the buffer that may affect how it is displayed. When |
| 780 | * it is nullptr, it means no such information is available. No |
| 781 | * HDR10+ dynamic emtadata is associated with the buffers by default. |
| 782 | * |
| 783 | * Parameter "size" refers to the length of the metadata blob pointed to |
| 784 | * by parameter "data". The metadata blob will adhere to the HDR10+ SEI |
| 785 | * message standard. |
| 786 | */ |
| 787 | static inline int native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow* window, |
| 788 | const size_t size, |
| 789 | const uint8_t* metadata) { |
| 790 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA, size, |
| 791 | metadata); |
| 792 | } |
| 793 | |
| 794 | /* |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 795 | * native_window_set_buffers_transform(..., int transform) |
| 796 | * All buffers queued after this call will be displayed transformed according |
| 797 | * to the transform parameter specified. |
| 798 | */ |
| 799 | static inline int native_window_set_buffers_transform( |
| 800 | struct ANativeWindow* window, |
| 801 | int transform) |
| 802 | { |
| 803 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM, |
| 804 | transform); |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * native_window_set_buffers_sticky_transform(..., int transform) |
| 809 | * All buffers queued after this call will be displayed transformed according |
| 810 | * to the transform parameter specified applied on top of the regular buffer |
| 811 | * transform. Setting this transform will disable the transform hint. |
| 812 | * |
| 813 | * Temporary - This is only intended to be used by the LEGACY camera mode, do |
| 814 | * not use this for anything else. |
| 815 | */ |
| 816 | static inline int native_window_set_buffers_sticky_transform( |
| 817 | struct ANativeWindow* window, |
| 818 | int transform) |
| 819 | { |
| 820 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM, |
| 821 | transform); |
| 822 | } |
| 823 | |
| 824 | /* |
| 825 | * native_window_set_buffers_timestamp(..., int64_t timestamp) |
| 826 | * All buffers queued after this call will be associated with the timestamp |
| 827 | * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO |
| 828 | * (the default), timestamps will be generated automatically when queueBuffer is |
| 829 | * called. The timestamp is measured in nanoseconds, and is normally monotonically |
| 830 | * increasing. The timestamp should be unaffected by time-of-day adjustments, |
| 831 | * and for a camera should be strictly monotonic but for a media player may be |
| 832 | * reset when the position is set. |
| 833 | */ |
| 834 | static inline int native_window_set_buffers_timestamp( |
| 835 | struct ANativeWindow* window, |
| 836 | int64_t timestamp) |
| 837 | { |
| 838 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP, |
| 839 | timestamp); |
| 840 | } |
| 841 | |
| 842 | /* |
| 843 | * native_window_set_scaling_mode(..., int mode) |
| 844 | * All buffers queued after this call will be associated with the scaling mode |
| 845 | * specified. |
| 846 | */ |
| 847 | static inline int native_window_set_scaling_mode( |
| 848 | struct ANativeWindow* window, |
| 849 | int mode) |
| 850 | { |
| 851 | return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE, |
| 852 | mode); |
| 853 | } |
| 854 | |
| 855 | /* |
| 856 | * native_window_api_connect(..., int api) |
| 857 | * connects an API to this window. only one API can be connected at a time. |
| 858 | * Returns -EINVAL if for some reason the window cannot be connected, which |
| 859 | * can happen if it's connected to some other API. |
| 860 | */ |
| 861 | static inline int native_window_api_connect( |
| 862 | struct ANativeWindow* window, int api) |
| 863 | { |
| 864 | return window->perform(window, NATIVE_WINDOW_API_CONNECT, api); |
| 865 | } |
| 866 | |
| 867 | /* |
| 868 | * native_window_api_disconnect(..., int api) |
| 869 | * disconnect the API from this window. |
| 870 | * An error is returned if for instance the window wasn't connected in the |
| 871 | * first place. |
| 872 | */ |
| 873 | static inline int native_window_api_disconnect( |
| 874 | struct ANativeWindow* window, int api) |
| 875 | { |
| 876 | return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api); |
| 877 | } |
| 878 | |
| 879 | /* |
| 880 | * native_window_dequeue_buffer_and_wait(...) |
| 881 | * Dequeue a buffer and wait on the fence associated with that buffer. The |
| 882 | * buffer may safely be accessed immediately upon this function returning. An |
| 883 | * error is returned if either of the dequeue or the wait operations fail. |
| 884 | */ |
| 885 | static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw, |
| 886 | struct ANativeWindowBuffer** anb) { |
| 887 | return anw->dequeueBuffer_DEPRECATED(anw, anb); |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | * native_window_set_sideband_stream(..., native_handle_t*) |
| 892 | * Attach a sideband buffer stream to a native window. |
| 893 | */ |
| 894 | static inline int native_window_set_sideband_stream( |
| 895 | struct ANativeWindow* window, |
| 896 | native_handle_t* sidebandHandle) |
| 897 | { |
| 898 | return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM, |
| 899 | sidebandHandle); |
| 900 | } |
| 901 | |
| 902 | /* |
| 903 | * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects) |
| 904 | * Set the surface damage (i.e., the region of the surface that has changed |
| 905 | * since the previous frame). The damage set by this call will be reset (to the |
| 906 | * default of full-surface damage) after calling queue, so this must be called |
| 907 | * prior to every frame with damage that does not cover the whole surface if the |
| 908 | * caller desires downstream consumers to use this optimization. |
| 909 | * |
| 910 | * The damage region is specified as an array of rectangles, with the important |
| 911 | * caveat that the origin of the surface is considered to be the bottom-left |
| 912 | * corner, as in OpenGL ES. |
| 913 | * |
| 914 | * If numRects is set to 0, rects may be NULL, and the surface damage will be |
| 915 | * set to the full surface (the same as if this function had not been called for |
| 916 | * this frame). |
| 917 | */ |
| 918 | static inline int native_window_set_surface_damage( |
| 919 | struct ANativeWindow* window, |
| 920 | const android_native_rect_t* rects, size_t numRects) |
| 921 | { |
| 922 | return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE, |
| 923 | rects, numRects); |
| 924 | } |
| 925 | |
| 926 | /* |
| 927 | * native_window_set_shared_buffer_mode(..., bool sharedBufferMode) |
| 928 | * Enable/disable shared buffer mode |
| 929 | */ |
| 930 | static inline int native_window_set_shared_buffer_mode( |
| 931 | struct ANativeWindow* window, |
| 932 | bool sharedBufferMode) |
| 933 | { |
| 934 | return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE, |
| 935 | sharedBufferMode); |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | * native_window_set_auto_refresh(..., autoRefresh) |
| 940 | * Enable/disable auto refresh when in shared buffer mode |
| 941 | */ |
| 942 | static inline int native_window_set_auto_refresh( |
| 943 | struct ANativeWindow* window, |
| 944 | bool autoRefresh) |
| 945 | { |
| 946 | return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh); |
| 947 | } |
| 948 | |
| 949 | static inline int native_window_get_refresh_cycle_duration( |
| 950 | struct ANativeWindow* window, |
| 951 | int64_t* outRefreshDuration) |
| 952 | { |
| 953 | return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION, |
| 954 | outRefreshDuration); |
| 955 | } |
| 956 | |
| 957 | static inline int native_window_get_next_frame_id( |
| 958 | struct ANativeWindow* window, uint64_t* frameId) |
| 959 | { |
| 960 | return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId); |
| 961 | } |
| 962 | |
| 963 | static inline int native_window_enable_frame_timestamps( |
| 964 | struct ANativeWindow* window, bool enable) |
| 965 | { |
| 966 | return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS, |
| 967 | enable); |
| 968 | } |
| 969 | |
| 970 | static inline int native_window_get_compositor_timing( |
| 971 | struct ANativeWindow* window, |
| 972 | int64_t* compositeDeadline, int64_t* compositeInterval, |
| 973 | int64_t* compositeToPresentLatency) |
| 974 | { |
| 975 | return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING, |
| 976 | compositeDeadline, compositeInterval, compositeToPresentLatency); |
| 977 | } |
| 978 | |
| 979 | static inline int native_window_get_frame_timestamps( |
| 980 | struct ANativeWindow* window, uint64_t frameId, |
| 981 | int64_t* outRequestedPresentTime, int64_t* outAcquireTime, |
| 982 | int64_t* outLatchTime, int64_t* outFirstRefreshStartTime, |
| 983 | int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime, |
| 984 | int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime, |
| 985 | int64_t* outReleaseTime) |
| 986 | { |
| 987 | return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS, |
| 988 | frameId, outRequestedPresentTime, outAcquireTime, outLatchTime, |
| 989 | outFirstRefreshStartTime, outLastRefreshStartTime, |
| 990 | outGpuCompositionDoneTime, outDisplayPresentTime, |
| 991 | outDequeueReadyTime, outReleaseTime); |
| 992 | } |
| 993 | |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 994 | /* deprecated. Always returns 0 and outSupport holds true. Don't call. */ |
| 995 | static inline int native_window_get_wide_color_support ( |
| 996 | struct ANativeWindow* window __UNUSED, bool* outSupport) __deprecated; |
| 997 | |
| 998 | /* |
| 999 | Deprecated(b/242763577): to be removed, this method should not be used |
| 1000 | Surface support should not be tied to the display |
| 1001 | Return true since most displays should have this support |
| 1002 | */ |
| 1003 | static inline int native_window_get_wide_color_support ( |
| 1004 | struct ANativeWindow* window __UNUSED, bool* outSupport) { |
| 1005 | *outSupport = true; |
| 1006 | return 0; |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 1009 | /* deprecated. Always returns 0 and outSupport holds true. Don't call. */ |
| 1010 | static inline int native_window_get_hdr_support(struct ANativeWindow* window __UNUSED, |
| 1011 | bool* outSupport) __deprecated; |
| 1012 | |
| 1013 | /* |
| 1014 | Deprecated(b/242763577): to be removed, this method should not be used |
| 1015 | Surface support should not be tied to the display |
| 1016 | Return true since most displays should have this support |
| 1017 | */ |
| 1018 | static inline int native_window_get_hdr_support(struct ANativeWindow* window __UNUSED, |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 1019 | bool* outSupport) { |
Huihong Luo | 31b5ac2 | 2022-08-15 20:38:10 -0700 | [diff] [blame] | 1020 | *outSupport = true; |
| 1021 | return 0; |
Chia-I Wu | e2786ea | 2017-08-07 10:36:08 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | static inline int native_window_get_consumer_usage(struct ANativeWindow* window, |
| 1025 | uint64_t* outUsage) { |
| 1026 | return window->perform(window, NATIVE_WINDOW_GET_CONSUMER_USAGE64, outUsage); |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Yiwei Zhang | 538cedc | 2019-06-24 19:35:03 -0700 | [diff] [blame] | 1029 | /* |
| 1030 | * native_window_set_auto_prerotation(..., autoPrerotation) |
| 1031 | * Enable/disable the auto prerotation at buffer allocation when the buffer size |
| 1032 | * is driven by the consumer. |
| 1033 | * |
| 1034 | * When buffer size is driven by the consumer and the transform hint specifies |
| 1035 | * a 90 or 270 degree rotation, if auto prerotation is enabled, the width and |
| 1036 | * height used for dequeueBuffer will be additionally swapped. |
| 1037 | */ |
| 1038 | static inline int native_window_set_auto_prerotation(struct ANativeWindow* window, |
| 1039 | bool autoPrerotation) { |
| 1040 | return window->perform(window, NATIVE_WINDOW_SET_AUTO_PREROTATION, autoPrerotation); |
| 1041 | } |
| 1042 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 1043 | /* |
| 1044 | * Internal extension of ANativeWindow_FrameRateCompatibility. |
| 1045 | */ |
| 1046 | enum { |
| 1047 | /** |
| 1048 | * This surface belongs to an app on the High Refresh Rate Deny list, and needs the display |
| 1049 | * to operate at the exact frame rate. |
| 1050 | * |
| 1051 | * Keep in sync with Surface.java constant. |
| 1052 | */ |
| 1053 | ANATIVEWINDOW_FRAME_RATE_EXACT = 100, |
| 1054 | |
| 1055 | /** |
| 1056 | * This surface is ignored while choosing the refresh rate. |
| 1057 | */ |
| 1058 | ANATIVEWINDOW_FRAME_RATE_NO_VOTE, |
Andy Labrada | 096227e | 2022-06-15 16:58:11 +0000 | [diff] [blame] | 1059 | |
| 1060 | /** |
| 1061 | * This surface will vote for the minimum refresh rate. |
| 1062 | */ |
Rachel Lee | 227aef2 | 2024-11-26 11:31:08 -0800 | [diff] [blame] | 1063 | ANATIVEWINDOW_FRAME_RATE_MIN |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 1064 | }; |
| 1065 | |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 1066 | /* |
| 1067 | * Frame rate category values that can be used in Transaction::setFrameRateCategory. |
| 1068 | */ |
| 1069 | enum { |
| 1070 | /** |
| 1071 | * Default value. This value can also be set to return to default behavior, such as layers |
| 1072 | * without animations. |
| 1073 | */ |
| 1074 | ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT = 0, |
| 1075 | |
| 1076 | /** |
| 1077 | * The layer will explicitly not influence the frame rate. |
| 1078 | * This may indicate a frame rate suitable for no animation updates (such as a cursor blinking |
| 1079 | * or a sporadic update). |
| 1080 | */ |
| 1081 | ANATIVEWINDOW_FRAME_RATE_CATEGORY_NO_PREFERENCE = 1, |
| 1082 | |
| 1083 | /** |
| 1084 | * Indicates a frame rate suitable for animations that looks fine even if played at a low frame |
| 1085 | * rate. |
| 1086 | */ |
| 1087 | ANATIVEWINDOW_FRAME_RATE_CATEGORY_LOW = 2, |
| 1088 | |
| 1089 | /** |
| 1090 | * Indicates a middle frame rate suitable for animations that do not require higher frame |
| 1091 | * rates, or do not benefit from high smoothness. This is normally 60 Hz or close to it. |
| 1092 | */ |
| 1093 | ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL = 3, |
| 1094 | |
| 1095 | /** |
Rachel Lee | 9580ff1 | 2023-12-26 17:33:41 -0800 | [diff] [blame] | 1096 | * Indicates that, as a result of a user interaction, an animation is likely to start. |
| 1097 | * This category is a signal that a user interaction heuristic determined the need of a |
| 1098 | * high refresh rate, and is not an explicit request from the app. |
| 1099 | * As opposed to FRAME_RATE_CATEGORY_HIGH, this vote may be ignored in favor of |
| 1100 | * more explicit votes. |
| 1101 | */ |
| 1102 | ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH_HINT = 4, |
| 1103 | |
| 1104 | /** |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 1105 | * Indicates a frame rate suitable for animations that require a high frame rate, which may |
| 1106 | * increase smoothness but may also increase power usage. |
| 1107 | */ |
Rachel Lee | 9580ff1 | 2023-12-26 17:33:41 -0800 | [diff] [blame] | 1108 | ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH = 5 |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 1109 | }; |
| 1110 | |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 1111 | /* |
| 1112 | * Frame rate selection strategy values that can be used in |
| 1113 | * Transaction::setFrameRateSelectionStrategy. |
| 1114 | */ |
| 1115 | enum { |
| 1116 | /** |
| 1117 | * Default value. The layer uses its own frame rate specifications, assuming it has any |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1118 | * specifications, instead of its parent's. If it does not have its own frame rate |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1119 | * specifications, it will try to use its parent's. It will propagate its specifications to any |
| 1120 | * descendants that do not have their own. |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1121 | * |
| 1122 | * However, FRAME_RATE_SELECTION_STRATEGY_OVERRIDE_CHILDREN on an ancestor layer |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1123 | * supersedes this behavior, meaning that this layer will inherit frame rate specifications |
| 1124 | * regardless of whether it has its own. |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 1125 | */ |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1126 | ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_PROPAGATE = 0, |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 1127 | |
| 1128 | /** |
| 1129 | * The layer's frame rate specifications will propagate to and override those of its descendant |
| 1130 | * layers. |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1131 | * |
| 1132 | * The layer itself has the FRAME_RATE_SELECTION_STRATEGY_PROPAGATE behavior. |
| 1133 | * Thus, ancestor layer that also has the strategy |
| 1134 | * FRAME_RATE_SELECTION_STRATEGY_OVERRIDE_CHILDREN will override this layer's |
| 1135 | * frame rate specifications. |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 1136 | */ |
| 1137 | ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_OVERRIDE_CHILDREN = 1, |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1138 | |
| 1139 | /** |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1140 | * The layer's frame rate specifications will not propagate to its descendant |
| 1141 | * layers, even if the descendant layer has no frame rate specifications. |
| 1142 | * However, FRAME_RATE_SELECTION_STRATEGY_OVERRIDE_CHILDREN on an ancestor |
| 1143 | * layer supersedes this behavior. |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 1144 | */ |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 1145 | ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_SELF = 2, |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 1146 | }; |
| 1147 | |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 1148 | static inline int native_window_set_frame_rate(struct ANativeWindow* window, float frameRate, |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 1149 | int8_t compatibility, int8_t changeFrameRateStrategy) { |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 1150 | return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate, |
Marin Shalamanov | c598677 | 2021-03-16 16:09:49 +0100 | [diff] [blame] | 1151 | (int)compatibility, (int)changeFrameRateStrategy); |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 1152 | } |
| 1153 | |
Ady Abraham | 88930f9 | 2023-06-07 10:32:08 -0700 | [diff] [blame] | 1154 | struct ANativeWindowFrameTimelineInfo { |
| 1155 | // Frame Id received from ANativeWindow_getNextFrameId. |
| 1156 | uint64_t frameNumber; |
| 1157 | |
| 1158 | // VsyncId received from the Choreographer callback that started this frame. |
| 1159 | int64_t frameTimelineVsyncId; |
| 1160 | |
| 1161 | // Input Event ID received from the input event that started this frame. |
| 1162 | int32_t inputEventId; |
| 1163 | |
| 1164 | // The time which this frame rendering started (i.e. when Choreographer callback actually run) |
| 1165 | int64_t startTimeNanos; |
| 1166 | |
| 1167 | // Whether or not to use the vsyncId to determine the refresh rate. Used for TextureView only. |
| 1168 | int32_t useForRefreshRateSelection; |
| 1169 | |
| 1170 | // The VsyncId of a frame that was not drawn and squashed into this frame. |
| 1171 | // Used for UI thread updates that were not picked up by RenderThread on time. |
| 1172 | int64_t skippedFrameVsyncId; |
| 1173 | |
| 1174 | // The start time of a frame that was not drawn and squashed into this frame. |
| 1175 | int64_t skippedFrameStartTimeNanos; |
| 1176 | }; |
| 1177 | |
Ady Abraham | 5526916 | 2023-05-09 11:26:06 -0700 | [diff] [blame] | 1178 | static inline int native_window_set_frame_timeline_info( |
Ady Abraham | 88930f9 | 2023-06-07 10:32:08 -0700 | [diff] [blame] | 1179 | struct ANativeWindow* window, struct ANativeWindowFrameTimelineInfo frameTimelineInfo) { |
| 1180 | return window->perform(window, NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO, frameTimelineInfo); |
Ady Abraham | 74e1756 | 2020-08-24 18:18:19 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
John Reck | db164ff | 2024-04-03 16:59:28 -0400 | [diff] [blame] | 1183 | /** |
| 1184 | * native_window_set_buffers_additional_options(..., ExtendableType* additionalOptions, size_t size) |
| 1185 | * All buffers dequeued after this call will have the additionalOptions specified. |
| 1186 | * |
| 1187 | * This must only be called after api_connect, otherwise NO_INIT is returned. The options are |
| 1188 | * cleared in api_disconnect & api_connect |
| 1189 | * |
| 1190 | * If IAllocator is not v2 or newer this method returns INVALID_OPERATION |
| 1191 | * |
| 1192 | * \return NO_ERROR on success. |
| 1193 | * \return NO_INIT if no api is connected |
| 1194 | * \return INVALID_OPERATION if additional option support is not available |
| 1195 | */ |
| 1196 | static inline int native_window_set_buffers_additional_options( |
| 1197 | struct ANativeWindow* window, const AHardwareBufferLongOptions* additionalOptions, |
| 1198 | size_t additionalOptionsSize) { |
| 1199 | return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_ADDITIONAL_OPTIONS, additionalOptions, |
| 1200 | additionalOptionsSize); |
| 1201 | } |
| 1202 | |
Alec Mouri | ef0b153 | 2019-12-17 09:39:07 -0800 | [diff] [blame] | 1203 | // ------------------------------------------------------------------------------------------------ |
| 1204 | // Candidates for APEX visibility |
| 1205 | // These functions are planned to be made stable for APEX modules, but have not |
| 1206 | // yet been stabilized to a specific api version. |
| 1207 | // ------------------------------------------------------------------------------------------------ |
| 1208 | |
| 1209 | /** |
| 1210 | * Retrieves the last queued buffer for this window, along with the fence that |
| 1211 | * fires when the buffer is ready to be read, and the 4x4 coordinate |
| 1212 | * transform matrix that should be applied to the buffer's content. The |
| 1213 | * transform matrix is represented in column-major order. |
| 1214 | * |
| 1215 | * If there was no buffer previously queued, then outBuffer will be NULL and |
| 1216 | * the value of outFence will be -1. |
| 1217 | * |
| 1218 | * Note that if outBuffer is not NULL, then the caller will hold a reference |
| 1219 | * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release |
| 1220 | * when the buffer is no longer needed so that the system may reclaim the |
| 1221 | * buffer. |
| 1222 | * |
| 1223 | * \return NO_ERROR on success. |
| 1224 | * \return NO_MEMORY if there was insufficient memory. |
| 1225 | */ |
| 1226 | static inline int ANativeWindow_getLastQueuedBuffer(ANativeWindow* window, |
| 1227 | AHardwareBuffer** outBuffer, int* outFence, |
| 1228 | float outTransformMatrix[16]) { |
| 1229 | return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER, outBuffer, outFence, |
| 1230 | outTransformMatrix); |
| 1231 | } |
| 1232 | |
Alec Mouri | d41a1be | 2020-02-14 15:18:11 -0800 | [diff] [blame] | 1233 | /** |
John Reck | aa5a0b2 | 2021-05-18 00:42:56 -0400 | [diff] [blame] | 1234 | * Retrieves the last queued buffer for this window, along with the fence that |
| 1235 | * fires when the buffer is ready to be read. The cropRect & transform should be applied to the |
| 1236 | * buffer's content. |
| 1237 | * |
| 1238 | * If there was no buffer previously queued, then outBuffer will be NULL and |
| 1239 | * the value of outFence will be -1. |
| 1240 | * |
| 1241 | * Note that if outBuffer is not NULL, then the caller will hold a reference |
| 1242 | * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release |
| 1243 | * when the buffer is no longer needed so that the system may reclaim the |
| 1244 | * buffer. |
| 1245 | * |
| 1246 | * \return NO_ERROR on success. |
| 1247 | * \return NO_MEMORY if there was insufficient memory. |
| 1248 | * \return STATUS_UNKNOWN_TRANSACTION if this ANativeWindow doesn't support this method, callers |
| 1249 | * should fall back to ANativeWindow_getLastQueuedBuffer instead. |
| 1250 | */ |
| 1251 | static inline int ANativeWindow_getLastQueuedBuffer2(ANativeWindow* window, |
| 1252 | AHardwareBuffer** outBuffer, int* outFence, |
| 1253 | ARect* outCropRect, uint32_t* outTransform) { |
| 1254 | return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2, outBuffer, outFence, |
| 1255 | outCropRect, outTransform); |
| 1256 | } |
| 1257 | |
| 1258 | /** |
Alec Mouri | d41a1be | 2020-02-14 15:18:11 -0800 | [diff] [blame] | 1259 | * Retrieves an identifier for the next frame to be queued by this window. |
| 1260 | * |
Pablo Gamito | 1a467c2 | 2021-09-06 17:43:06 +0000 | [diff] [blame] | 1261 | * Frame ids start at 1 and are incremented on each new frame until the underlying surface changes, |
| 1262 | * in which case the frame id is reset to 1. |
| 1263 | * |
| 1264 | * \return the next frame id (0 being uninitialized). |
Alec Mouri | d41a1be | 2020-02-14 15:18:11 -0800 | [diff] [blame] | 1265 | */ |
Pablo Gamito | 004c412 | 2021-08-24 11:04:27 +0200 | [diff] [blame] | 1266 | static inline uint64_t ANativeWindow_getNextFrameId(ANativeWindow* window) { |
| 1267 | uint64_t value; |
Alec Mouri | d41a1be | 2020-02-14 15:18:11 -0800 | [diff] [blame] | 1268 | window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, &value); |
| 1269 | return value; |
| 1270 | } |
| 1271 | |
John Reck | 401cda6 | 2020-05-07 16:04:41 -0700 | [diff] [blame] | 1272 | /** |
| 1273 | * Prototype of the function that an ANativeWindow implementation would call |
| 1274 | * when ANativeWindow_query is called. |
| 1275 | */ |
| 1276 | typedef int (*ANativeWindow_queryFn)(const ANativeWindow* window, int what, int* value); |
| 1277 | |
| 1278 | /** |
| 1279 | * Prototype of the function that intercepts an invocation of |
| 1280 | * ANativeWindow_queryFn, along with a data pointer that's passed by the |
| 1281 | * caller who set the interceptor, as well as arguments that would be |
| 1282 | * passed to ANativeWindow_queryFn if it were to be called. |
| 1283 | */ |
| 1284 | typedef int (*ANativeWindow_queryInterceptor)(const ANativeWindow* window, |
| 1285 | ANativeWindow_queryFn perform, void* data, |
| 1286 | int what, int* value); |
| 1287 | |
| 1288 | /** |
| 1289 | * Registers an interceptor for ANativeWindow_query. Instead of calling |
| 1290 | * the underlying query function, instead the provided interceptor is |
| 1291 | * called, which may optionally call the underlying query function. An |
| 1292 | * optional data pointer is also provided to side-channel additional arguments. |
| 1293 | * |
| 1294 | * Note that usage of this should only be used for specialized use-cases by |
| 1295 | * either the system partition or to Mainline modules. This should never be |
| 1296 | * exposed to NDK or LL-NDK. |
| 1297 | * |
| 1298 | * Returns NO_ERROR on success, -errno if registration failed. |
| 1299 | */ |
| 1300 | static inline int ANativeWindow_setQueryInterceptor(ANativeWindow* window, |
| 1301 | ANativeWindow_queryInterceptor interceptor, |
| 1302 | void* data) { |
| 1303 | return window->perform(window, NATIVE_WINDOW_SET_QUERY_INTERCEPTOR, interceptor, data); |
| 1304 | } |
| 1305 | |
Mathias Agopian | a6c0e20 | 2017-03-20 15:48:44 -0700 | [diff] [blame] | 1306 | __END_DECLS |