blob: 935eded983818898694efe7d28497a428d313eca [file] [log] [blame]
Mathias Agopiana6c0e202017-03-20 15:48:44 -07001/*
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 Thomas3172e202020-01-06 19:25:30 -080037#include <stdbool.h>
Mathias Agopiana6c0e202017-03-20 15:48:44 -070038#include <stdint.h>
39#include <string.h>
40#include <sys/cdefs.h>
41#include <system/graphics.h>
42#include <unistd.h>
Mathias Agopiana6c0e202017-03-20 15:48:44 -070043
Alec Mouri9fa2cb62019-07-15 17:36:26 -070044// system/window.h is a superset of the vndk and apex apis
45#include <apex/window.h>
Mathias Agopiana6c0e202017-03-20 15:48:44 -070046#include <vndk/window.h>
47
48
49#ifndef __UNUSED
50#define __UNUSED __attribute__((__unused__))
51#endif
52#ifndef __deprecated
53#define __deprecated __attribute__((__deprecated__))
54#endif
55
56__BEGIN_DECLS
57
58/*****************************************************************************/
59
Mathias Agopian000879a2017-03-20 18:07:26 -070060#define ANDROID_NATIVE_WINDOW_MAGIC ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
Mathias Agopiana6c0e202017-03-20 15:48:44 -070061
62// ---------------------------------------------------------------------------
63
Mathias Agopiana6c0e202017-03-20 15:48:44 -070064/* attributes queriable with query() */
65enum {
Alec Mouri72670c52019-08-31 01:54:33 -070066 NATIVE_WINDOW_WIDTH = 0,
67 NATIVE_WINDOW_HEIGHT = 1,
68 NATIVE_WINDOW_FORMAT = 2,
Mathias Agopiana6c0e202017-03-20 15:48:44 -070069
Mathias Agopian000879a2017-03-20 18:07:26 -070070 /* see ANativeWindowQuery in vndk/window.h */
71 NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS,
Mathias Agopiana6c0e202017-03-20 15:48:44 -070072
73 /* Check whether queueBuffer operations on the ANativeWindow send the buffer
74 * to the window compositor. The query sets the returned 'value' argument
75 * to 1 if the ANativeWindow DOES send queued buffers directly to the window
76 * compositor and 0 if the buffers do not go directly to the window
77 * compositor.
78 *
79 * This can be used to determine whether protected buffer content should be
80 * sent to the ANativeWindow. Note, however, that a result of 1 does NOT
81 * indicate that queued buffers will be protected from applications or users
82 * capturing their contents. If that behavior is desired then some other
83 * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
84 * conjunction with this query.
85 */
86 NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
87
88 /* Get the concrete type of a ANativeWindow. See below for the list of
89 * possible return values.
90 *
91 * This query should not be used outside the Android framework and will
92 * likely be removed in the near future.
93 */
94 NATIVE_WINDOW_CONCRETE_TYPE = 5,
95
Mathias Agopiana6c0e202017-03-20 15:48:44 -070096 /*
97 * Default width and height of ANativeWindow buffers, these are the
98 * dimensions of the window buffers irrespective of the
99 * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window
100 * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
101 */
Mathias Agopian000879a2017-03-20 18:07:26 -0700102 NATIVE_WINDOW_DEFAULT_WIDTH = ANATIVEWINDOW_QUERY_DEFAULT_WIDTH,
103 NATIVE_WINDOW_DEFAULT_HEIGHT = ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700104
Mathias Agopian000879a2017-03-20 18:07:26 -0700105 /* see ANativeWindowQuery in vndk/window.h */
106 NATIVE_WINDOW_TRANSFORM_HINT = ANATIVEWINDOW_QUERY_TRANSFORM_HINT,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700107
108 /*
109 * Boolean that indicates whether the consumer is running more than
110 * one buffer behind the producer.
111 */
112 NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9,
113
114 /*
115 * The consumer gralloc usage bits currently set by the consumer.
116 * The values are defined in hardware/libhardware/include/gralloc.h.
117 */
Chia-I Wue2786ea2017-08-07 10:36:08 -0700118 NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10, /* deprecated */
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700119
120 /**
121 * Transformation that will by applied to buffers by the hwcomposer.
122 * This must not be set or checked by producer endpoints, and will
123 * disable the transform hint set in SurfaceFlinger (see
124 * NATIVE_WINDOW_TRANSFORM_HINT).
125 *
126 * INTENDED USE:
127 * Temporary - Please do not use this. This is intended only to be used
128 * by the camera's LEGACY mode.
129 *
130 * In situations where a SurfaceFlinger client wishes to set a transform
131 * that is not visible to the producer, and will always be applied in the
132 * hardware composer, the client can set this flag with
133 * native_window_set_buffers_sticky_transform. This can be used to rotate
134 * and flip buffers consumed by hardware composer without actually changing
135 * the aspect ratio of the buffers produced.
136 */
137 NATIVE_WINDOW_STICKY_TRANSFORM = 11,
138
139 /**
140 * The default data space for the buffers as set by the consumer.
141 * The values are defined in graphics.h.
142 */
143 NATIVE_WINDOW_DEFAULT_DATASPACE = 12,
144
Mathias Agopian000879a2017-03-20 18:07:26 -0700145 /* see ANativeWindowQuery in vndk/window.h */
146 NATIVE_WINDOW_BUFFER_AGE = ANATIVEWINDOW_QUERY_BUFFER_AGE,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700147
148 /*
149 * Returns the duration of the last dequeueBuffer call in microseconds
Alec Mouri72670c52019-08-31 01:54:33 -0700150 * Deprecated: please use NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION in
151 * perform() instead, which supports nanosecond precision.
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700152 */
153 NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
154
155 /*
156 * Returns the duration of the last queueBuffer call in microseconds
Alec Mouri72670c52019-08-31 01:54:33 -0700157 * Deprecated: please use NATIVE_WINDOW_GET_LAST_QUEUE_DURATION in
158 * perform() instead, which supports nanosecond precision.
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700159 */
160 NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
161
162 /*
163 * Returns the number of image layers that the ANativeWindow buffer
164 * contains. By default this is 1, unless a buffer is explicitly allocated
165 * to contain multiple layers.
166 */
167 NATIVE_WINDOW_LAYER_COUNT = 16,
168
169 /*
170 * Returns 1 if the native window is valid, 0 otherwise. native window is valid
171 * if it is safe (i.e. no crash will occur) to call any method on it.
172 */
173 NATIVE_WINDOW_IS_VALID = 17,
Brian Anderson6b376712017-04-04 10:51:39 -0700174
175 /*
176 * Returns 1 if NATIVE_WINDOW_GET_FRAME_TIMESTAMPS will return display
177 * present info, 0 if it won't.
178 */
179 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18,
Jiwen 'Steve' Cai20419132017-04-21 18:49:53 -0700180
181 /*
182 * The consumer end is capable of handling protected buffers, i.e. buffer
183 * with GRALLOC_USAGE_PROTECTED usage bits on.
184 */
185 NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19,
Peiyong Lin654f87b2018-01-30 14:21:33 -0800186
187 /*
188 * Returns data space for the buffers.
189 */
190 NATIVE_WINDOW_DATASPACE = 20,
Yiwei Zhangdbd96152018-02-08 14:22:53 -0800191
192 /*
193 * Returns maxBufferCount set by BufferQueueConsumer
194 */
195 NATIVE_WINDOW_MAX_BUFFER_COUNT = 21,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700196};
197
198/* Valid operations for the (*perform)() hook.
199 *
200 * Values marked as 'deprecated' are supported, but have been superceded by
201 * other functionality.
202 *
203 * Values marked as 'private' should be considered private to the framework.
204 * HAL implementation code with access to an ANativeWindow should not use these,
205 * as it may not interact properly with the framework's use of the
206 * ANativeWindow.
207 */
208enum {
Valerie Haua82679d2018-11-21 09:31:43 -0800209 // clang-format off
Alec Mouri09d122a2019-11-25 10:00:53 -0800210 NATIVE_WINDOW_SET_USAGE = ANATIVEWINDOW_PERFORM_SET_USAGE, /* deprecated */
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700211 NATIVE_WINDOW_CONNECT = 1, /* deprecated */
212 NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */
213 NATIVE_WINDOW_SET_CROP = 3, /* private */
214 NATIVE_WINDOW_SET_BUFFER_COUNT = 4,
Alec Mouri09d122a2019-11-25 10:00:53 -0800215 NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = ANATIVEWINDOW_PERFORM_SET_BUFFERS_GEOMETRY, /* deprecated */
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700216 NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6,
217 NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7,
218 NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8,
Alec Mouri09d122a2019-11-25 10:00:53 -0800219 NATIVE_WINDOW_SET_BUFFERS_FORMAT = ANATIVEWINDOW_PERFORM_SET_BUFFERS_FORMAT,
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700220 NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */
221 NATIVE_WINDOW_LOCK = 11, /* private */
222 NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */
223 NATIVE_WINDOW_API_CONNECT = 13, /* private */
224 NATIVE_WINDOW_API_DISCONNECT = 14, /* private */
225 NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
226 NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* deprecated, unimplemented */
227 NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17, /* private */
228 NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18,
229 NATIVE_WINDOW_SET_BUFFERS_DATASPACE = 19,
230 NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */
231 NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21,
232 NATIVE_WINDOW_SET_AUTO_REFRESH = 22,
233 NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION = 23,
234 NATIVE_WINDOW_GET_NEXT_FRAME_ID = 24,
235 NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS = 25,
236 NATIVE_WINDOW_GET_COMPOSITOR_TIMING = 26,
237 NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 27,
238 NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT = 28,
239 NATIVE_WINDOW_GET_HDR_SUPPORT = 29,
Alec Mouri09d122a2019-11-25 10:00:53 -0800240 NATIVE_WINDOW_SET_USAGE64 = ANATIVEWINDOW_PERFORM_SET_USAGE64,
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700241 NATIVE_WINDOW_GET_CONSUMER_USAGE64 = 31,
242 NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA = 32,
243 NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA = 33,
Valerie Haua82679d2018-11-21 09:31:43 -0800244 NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA = 34,
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700245 NATIVE_WINDOW_SET_AUTO_PREROTATION = 35,
Alec Mouria1619662019-08-21 19:30:48 -0700246 NATIVE_WINDOW_GET_LAST_DEQUEUE_START = 36, /* private */
Alec Mouri04fdb602019-08-23 19:41:43 -0700247 NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT = 37, /* private */
Alec Mouri72670c52019-08-31 01:54:33 -0700248 NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION = 38, /* private */
249 NATIVE_WINDOW_GET_LAST_QUEUE_DURATION = 39, /* private */
Steven Thomas3172e202020-01-06 19:25:30 -0800250 NATIVE_WINDOW_SET_FRAME_RATE = 40,
Alec Mouri09d122a2019-11-25 10:00:53 -0800251 NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR = 41, /* private */
252 NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR = 42, /* private */
253 NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR = 43, /* private */
254 NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR = 44, /* private */
Alec Mouri74aef6d2019-12-09 17:10:24 -0800255 NATIVE_WINDOW_ALLOCATE_BUFFERS = 45, /* private */
Alec Mourief0b1532019-12-17 09:39:07 -0800256 NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER = 46, /* private */
John Reck401cda62020-05-07 16:04:41 -0700257 NATIVE_WINDOW_SET_QUERY_INTERCEPTOR = 47, /* private */
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000258 NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO = 48, /* private */
Ady Abraham564f9de2021-02-03 18:34:33 -0800259 NATIVE_WINDOW_GET_EXTRA_BUFFER_COUNT = 49, /* private */
John Reckaa5a0b22021-05-18 00:42:56 -0400260 NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2 = 50, /* private */
Valerie Haua82679d2018-11-21 09:31:43 -0800261 // clang-format on
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700262};
263
264/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
265enum {
266 /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
267 * OpenGL ES.
268 */
269 NATIVE_WINDOW_API_EGL = 1,
270
271 /* Buffers will be queued after being filled using the CPU
272 */
273 NATIVE_WINDOW_API_CPU = 2,
274
275 /* Buffers will be queued by Stagefright after being filled by a video
276 * decoder. The video decoder can either be a software or hardware decoder.
277 */
278 NATIVE_WINDOW_API_MEDIA = 3,
279
280 /* Buffers will be queued by the the camera HAL.
281 */
282 NATIVE_WINDOW_API_CAMERA = 4,
283};
284
285/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
286enum {
287 /* flip source image horizontally */
288 NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
289 /* flip source image vertically */
290 NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
291 /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
292 NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
293 /* rotate source image 180 degrees */
294 NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
295 /* rotate source image 270 degrees clock-wise */
296 NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
297 /* transforms source by the inverse transform of the screen it is displayed onto. This
298 * transform is applied last */
299 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
300};
301
302/* parameter for NATIVE_WINDOW_SET_SCALING_MODE
303 * keep in sync with Surface.java in frameworks/base */
304enum {
305 /* the window content is not updated (frozen) until a buffer of
306 * the window size is received (enqueued)
307 */
308 NATIVE_WINDOW_SCALING_MODE_FREEZE = 0,
309 /* the buffer is scaled in both dimensions to match the window size */
310 NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1,
311 /* the buffer is scaled uniformly such that the smaller dimension
312 * of the buffer matches the window size (cropping in the process)
313 */
314 NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2,
315 /* the window is clipped to the size of the buffer's crop rectangle; pixels
316 * outside the crop rectangle are treated as if they are completely
317 * transparent.
318 */
319 NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3,
320};
321
322/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
323enum {
324 NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
325 NATIVE_WINDOW_SURFACE = 1, /* Surface */
326};
327
328/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
329 *
330 * Special timestamp value to indicate that timestamps should be auto-generated
331 * by the native window when queueBuffer is called. This is equal to INT64_MIN,
332 * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
333 */
334static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
335
Brian Andersondc96fdf2017-03-20 16:54:25 -0700336/* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS
337 *
338 * Special timestamp value to indicate the timestamps aren't yet known or
339 * that they are invalid.
340 */
341static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2;
342static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1;
343
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700344struct ANativeWindow
345{
346#ifdef __cplusplus
347 ANativeWindow()
348 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
349 {
350 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
351 common.version = sizeof(ANativeWindow);
352 memset(common.reserved, 0, sizeof(common.reserved));
353 }
354
355 /* Implement the methods that sp<ANativeWindow> expects so that it
356 can be used to automatically refcount ANativeWindow's. */
357 void incStrong(const void* /*id*/) const {
358 common.incRef(const_cast<android_native_base_t*>(&common));
359 }
360 void decStrong(const void* /*id*/) const {
361 common.decRef(const_cast<android_native_base_t*>(&common));
362 }
363#endif
364
365 struct android_native_base_t common;
366
367 /* flags describing some attributes of this surface or its updater */
368 const uint32_t flags;
369
370 /* min swap interval supported by this updated */
371 const int minSwapInterval;
372
373 /* max swap interval supported by this updated */
374 const int maxSwapInterval;
375
376 /* horizontal and vertical resolution in DPI */
377 const float xdpi;
378 const float ydpi;
379
380 /* Some storage reserved for the OEM's driver. */
381 intptr_t oem[4];
382
383 /*
384 * Set the swap interval for this surface.
385 *
386 * Returns 0 on success or -errno on error.
387 */
388 int (*setSwapInterval)(struct ANativeWindow* window,
389 int interval);
390
391 /*
392 * Hook called by EGL to acquire a buffer. After this call, the buffer
393 * is not locked, so its content cannot be modified. This call may block if
394 * no buffers are available.
395 *
396 * The window holds a reference to the buffer between dequeueBuffer and
397 * either queueBuffer or cancelBuffer, so clients only need their own
398 * reference if they might use the buffer after queueing or canceling it.
399 * Holding a reference to a buffer after queueing or canceling it is only
400 * allowed if a specific buffer count has been set.
401 *
402 * Returns 0 on success or -errno on error.
403 *
404 * XXX: This function is deprecated. It will continue to work for some
405 * time for binary compatibility, but the new dequeueBuffer function that
406 * outputs a fence file descriptor should be used in its place.
407 */
408 int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
409 struct ANativeWindowBuffer** buffer);
410
411 /*
412 * hook called by EGL to lock a buffer. This MUST be called before modifying
413 * the content of a buffer. The buffer must have been acquired with
414 * dequeueBuffer first.
415 *
416 * Returns 0 on success or -errno on error.
417 *
418 * XXX: This function is deprecated. It will continue to work for some
419 * time for binary compatibility, but it is essentially a no-op, and calls
420 * to it should be removed.
421 */
422 int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
423 struct ANativeWindowBuffer* buffer);
424
425 /*
426 * Hook called by EGL when modifications to the render buffer are done.
427 * This unlocks and post the buffer.
428 *
429 * The window holds a reference to the buffer between dequeueBuffer and
430 * either queueBuffer or cancelBuffer, so clients only need their own
431 * reference if they might use the buffer after queueing or canceling it.
432 * Holding a reference to a buffer after queueing or canceling it is only
433 * allowed if a specific buffer count has been set.
434 *
435 * Buffers MUST be queued in the same order than they were dequeued.
436 *
437 * Returns 0 on success or -errno on error.
438 *
439 * XXX: This function is deprecated. It will continue to work for some
440 * time for binary compatibility, but the new queueBuffer function that
441 * takes a fence file descriptor should be used in its place (pass a value
442 * of -1 for the fence file descriptor if there is no valid one to pass).
443 */
444 int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
445 struct ANativeWindowBuffer* buffer);
446
447 /*
448 * hook used to retrieve information about the native window.
449 *
450 * Returns 0 on success or -errno on error.
451 */
452 int (*query)(const struct ANativeWindow* window,
453 int what, int* value);
454
455 /*
456 * hook used to perform various operations on the surface.
457 * (*perform)() is a generic mechanism to add functionality to
458 * ANativeWindow while keeping backward binary compatibility.
459 *
460 * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
461 * defined below.
462 *
463 * (*perform)() returns -ENOENT if the 'what' parameter is not supported
464 * by the surface's implementation.
465 *
466 * See above for a list of valid operations, such as
467 * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
468 */
469 int (*perform)(struct ANativeWindow* window,
470 int operation, ... );
471
472 /*
473 * Hook used to cancel a buffer that has been dequeued.
474 * No synchronization is performed between dequeue() and cancel(), so
475 * either external synchronization is needed, or these functions must be
476 * called from the same thread.
477 *
478 * The window holds a reference to the buffer between dequeueBuffer and
479 * either queueBuffer or cancelBuffer, so clients only need their own
480 * reference if they might use the buffer after queueing or canceling it.
481 * Holding a reference to a buffer after queueing or canceling it is only
482 * allowed if a specific buffer count has been set.
483 *
484 * XXX: This function is deprecated. It will continue to work for some
485 * time for binary compatibility, but the new cancelBuffer function that
486 * takes a fence file descriptor should be used in its place (pass a value
487 * of -1 for the fence file descriptor if there is no valid one to pass).
488 */
489 int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
490 struct ANativeWindowBuffer* buffer);
491
492 /*
493 * Hook called by EGL to acquire a buffer. This call may block if no
494 * buffers are available.
495 *
496 * The window holds a reference to the buffer between dequeueBuffer and
497 * either queueBuffer or cancelBuffer, so clients only need their own
498 * reference if they might use the buffer after queueing or canceling it.
499 * Holding a reference to a buffer after queueing or canceling it is only
500 * allowed if a specific buffer count has been set.
501 *
502 * The libsync fence file descriptor returned in the int pointed to by the
503 * fenceFd argument will refer to the fence that must signal before the
504 * dequeued buffer may be written to. A value of -1 indicates that the
505 * caller may access the buffer immediately without waiting on a fence. If
506 * a valid file descriptor is returned (i.e. any value except -1) then the
507 * caller is responsible for closing the file descriptor.
508 *
509 * Returns 0 on success or -errno on error.
510 */
511 int (*dequeueBuffer)(struct ANativeWindow* window,
512 struct ANativeWindowBuffer** buffer, int* fenceFd);
513
514 /*
515 * Hook called by EGL when modifications to the render buffer are done.
516 * This unlocks and post the buffer.
517 *
518 * The window holds a reference to the buffer between dequeueBuffer and
519 * either queueBuffer or cancelBuffer, so clients only need their own
520 * reference if they might use the buffer after queueing or canceling it.
521 * Holding a reference to a buffer after queueing or canceling it is only
522 * allowed if a specific buffer count has been set.
523 *
524 * The fenceFd argument specifies a libsync fence file descriptor for a
525 * fence that must signal before the buffer can be accessed. If the buffer
526 * can be accessed immediately then a value of -1 should be used. The
527 * caller must not use the file descriptor after it is passed to
528 * queueBuffer, and the ANativeWindow implementation is responsible for
529 * closing it.
530 *
531 * Returns 0 on success or -errno on error.
532 */
533 int (*queueBuffer)(struct ANativeWindow* window,
534 struct ANativeWindowBuffer* buffer, int fenceFd);
535
536 /*
537 * Hook used to cancel a buffer that has been dequeued.
538 * No synchronization is performed between dequeue() and cancel(), so
539 * either external synchronization is needed, or these functions must be
540 * called from the same thread.
541 *
542 * The window holds a reference to the buffer between dequeueBuffer and
543 * either queueBuffer or cancelBuffer, so clients only need their own
544 * reference if they might use the buffer after queueing or canceling it.
545 * Holding a reference to a buffer after queueing or canceling it is only
546 * allowed if a specific buffer count has been set.
547 *
548 * The fenceFd argument specifies a libsync fence file decsriptor for a
549 * fence that must signal before the buffer can be accessed. If the buffer
550 * can be accessed immediately then a value of -1 should be used.
551 *
552 * Note that if the client has not waited on the fence that was returned
553 * from dequeueBuffer, that same fence should be passed to cancelBuffer to
554 * ensure that future uses of the buffer are preceded by a wait on that
555 * fence. The caller must not use the file descriptor after it is passed
556 * to cancelBuffer, and the ANativeWindow implementation is responsible for
557 * closing it.
558 *
559 * Returns 0 on success or -errno on error.
560 */
561 int (*cancelBuffer)(struct ANativeWindow* window,
562 struct ANativeWindowBuffer* buffer, int fenceFd);
563};
564
565 /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
566 * android_native_window_t is deprecated.
567 */
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700568typedef struct ANativeWindow android_native_window_t __deprecated;
569
570/*
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700571 * native_window_set_usage64(..., usage)
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700572 * Sets the intended usage flags for the next buffers
573 * acquired with (*lockBuffer)() and on.
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700574 *
575 * Valid usage flags are defined in android/hardware_buffer.h
576 * All AHARDWAREBUFFER_USAGE_* flags can be specified as needed.
577 *
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700578 * Calling this function will usually cause following buffers to be
579 * reallocated.
580 */
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700581static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) {
582 return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700583}
584
585/* deprecated. Always returns 0. Don't call. */
586static inline int native_window_connect(
587 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
588
589static inline int native_window_connect(
590 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
591 return 0;
592}
593
594/* deprecated. Always returns 0. Don't call. */
595static inline int native_window_disconnect(
596 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
597
598static inline int native_window_disconnect(
599 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
600 return 0;
601}
602
603/*
604 * native_window_set_crop(..., crop)
605 * Sets which region of the next queued buffers needs to be considered.
606 * Depending on the scaling mode, a buffer's crop region is scaled and/or
607 * cropped to match the surface's size. This function sets the crop in
608 * pre-transformed buffer pixel coordinates.
609 *
610 * The specified crop region applies to all buffers queued after it is called.
611 *
612 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
613 *
614 * An error is returned if for instance the crop region is invalid, out of the
615 * buffer's bound or if the window is invalid.
616 */
617static inline int native_window_set_crop(
618 struct ANativeWindow* window,
619 android_native_rect_t const * crop)
620{
621 return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
622}
623
624/*
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700625 * native_window_set_buffer_count(..., count)
626 * Sets the number of buffers associated with this native window.
627 */
628static inline int native_window_set_buffer_count(
629 struct ANativeWindow* window,
630 size_t bufferCount)
631{
632 return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
633}
634
635/*
636 * native_window_set_buffers_geometry(..., int w, int h, int format)
637 * All buffers dequeued after this call will have the dimensions and format
638 * specified. A successful call to this function has the same effect as calling
639 * native_window_set_buffers_size and native_window_set_buffers_format.
640 *
641 * XXX: This function is deprecated. The native_window_set_buffers_dimensions
642 * and native_window_set_buffers_format functions should be used instead.
643 */
644static inline int native_window_set_buffers_geometry(
645 struct ANativeWindow* window,
646 int w, int h, int format) __deprecated;
647
648static inline int native_window_set_buffers_geometry(
649 struct ANativeWindow* window,
650 int w, int h, int format)
651{
652 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
653 w, h, format);
654}
655
656/*
657 * native_window_set_buffers_dimensions(..., int w, int h)
658 * All buffers dequeued after this call will have the dimensions specified.
659 * In particular, all buffers will have a fixed-size, independent from the
660 * native-window size. They will be scaled according to the scaling mode
661 * (see native_window_set_scaling_mode) upon window composition.
662 *
663 * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
664 * following this call will be sized to match the window's size.
665 *
666 * Calling this function will reset the window crop to a NULL value, which
667 * disables cropping of the buffers.
668 */
669static inline int native_window_set_buffers_dimensions(
670 struct ANativeWindow* window,
671 int w, int h)
672{
673 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
674 w, h);
675}
676
677/*
678 * native_window_set_buffers_user_dimensions(..., int w, int h)
679 *
680 * Sets the user buffer size for the window, which overrides the
681 * window's size. All buffers dequeued after this call will have the
682 * dimensions specified unless overridden by
683 * native_window_set_buffers_dimensions. All buffers will have a
684 * fixed-size, independent from the native-window size. They will be
685 * scaled according to the scaling mode (see
686 * native_window_set_scaling_mode) upon window composition.
687 *
688 * If w and h are 0, the normal behavior is restored. That is, the
689 * default buffer size will match the windows's size.
690 *
691 * Calling this function will reset the window crop to a NULL value, which
692 * disables cropping of the buffers.
693 */
694static inline int native_window_set_buffers_user_dimensions(
695 struct ANativeWindow* window,
696 int w, int h)
697{
698 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
699 w, h);
700}
701
702/*
703 * native_window_set_buffers_format(..., int format)
704 * All buffers dequeued after this call will have the format specified.
705 *
706 * If the specified format is 0, the default buffer format will be used.
707 */
708static inline int native_window_set_buffers_format(
709 struct ANativeWindow* window,
710 int format)
711{
712 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
713}
714
715/*
716 * native_window_set_buffers_data_space(..., int dataSpace)
717 * All buffers queued after this call will be associated with the dataSpace
718 * parameter specified.
719 *
720 * dataSpace specifies additional information about the buffer that's dependent
721 * on the buffer format and the endpoints. For example, it can be used to convey
722 * the color space of the image data in the buffer, or it can be used to
723 * indicate that the buffers contain depth measurement data instead of color
724 * images. The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
725 * overridden by the consumer.
726 */
727static inline int native_window_set_buffers_data_space(
728 struct ANativeWindow* window,
729 android_dataspace_t dataSpace)
730{
731 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
732 dataSpace);
733}
734
735/*
Courtney Goeltzenleuchter9bad0d72017-12-19 12:34:34 -0700736 * native_window_set_buffers_smpte2086_metadata(..., metadata)
737 * All buffers queued after this call will be associated with the SMPTE
738 * ST.2086 metadata specified.
739 *
740 * metadata specifies additional information about the contents of the buffer
741 * that may affect how it's displayed. When it is nullptr, it means no such
742 * information is available. No SMPTE ST.2086 metadata is associated with the
743 * buffers by default.
744 */
745static inline int native_window_set_buffers_smpte2086_metadata(
746 struct ANativeWindow* window,
747 const struct android_smpte2086_metadata* metadata)
748{
749 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA,
750 metadata);
751}
752
753/*
754 * native_window_set_buffers_cta861_3_metadata(..., metadata)
755 * All buffers queued after this call will be associated with the CTA-861.3
756 * metadata specified.
757 *
758 * metadata specifies additional information about the contents of the buffer
759 * that may affect how it's displayed. When it is nullptr, it means no such
760 * information is available. No CTA-861.3 metadata is associated with the
761 * buffers by default.
762 */
763static inline int native_window_set_buffers_cta861_3_metadata(
764 struct ANativeWindow* window,
765 const struct android_cta861_3_metadata* metadata)
766{
767 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA,
768 metadata);
769}
770
771/*
Valerie Haua82679d2018-11-21 09:31:43 -0800772 * native_window_set_buffers_hdr10_plus_metadata(..., metadata)
773 * All buffers queued after this call will be associated with the
774 * HDR10+ dynamic metadata specified.
775 *
776 * metadata specifies additional dynamic information about the
777 * contents of the buffer that may affect how it is displayed. When
778 * it is nullptr, it means no such information is available. No
779 * HDR10+ dynamic emtadata is associated with the buffers by default.
780 *
781 * Parameter "size" refers to the length of the metadata blob pointed to
782 * by parameter "data". The metadata blob will adhere to the HDR10+ SEI
783 * message standard.
784 */
785static inline int native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow* window,
786 const size_t size,
787 const uint8_t* metadata) {
788 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA, size,
789 metadata);
790}
791
792/*
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700793 * native_window_set_buffers_transform(..., int transform)
794 * All buffers queued after this call will be displayed transformed according
795 * to the transform parameter specified.
796 */
797static inline int native_window_set_buffers_transform(
798 struct ANativeWindow* window,
799 int transform)
800{
801 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
802 transform);
803}
804
805/*
806 * native_window_set_buffers_sticky_transform(..., int transform)
807 * All buffers queued after this call will be displayed transformed according
808 * to the transform parameter specified applied on top of the regular buffer
809 * transform. Setting this transform will disable the transform hint.
810 *
811 * Temporary - This is only intended to be used by the LEGACY camera mode, do
812 * not use this for anything else.
813 */
814static inline int native_window_set_buffers_sticky_transform(
815 struct ANativeWindow* window,
816 int transform)
817{
818 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
819 transform);
820}
821
822/*
823 * native_window_set_buffers_timestamp(..., int64_t timestamp)
824 * All buffers queued after this call will be associated with the timestamp
825 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
826 * (the default), timestamps will be generated automatically when queueBuffer is
827 * called. The timestamp is measured in nanoseconds, and is normally monotonically
828 * increasing. The timestamp should be unaffected by time-of-day adjustments,
829 * and for a camera should be strictly monotonic but for a media player may be
830 * reset when the position is set.
831 */
832static inline int native_window_set_buffers_timestamp(
833 struct ANativeWindow* window,
834 int64_t timestamp)
835{
836 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
837 timestamp);
838}
839
840/*
841 * native_window_set_scaling_mode(..., int mode)
842 * All buffers queued after this call will be associated with the scaling mode
843 * specified.
844 */
845static inline int native_window_set_scaling_mode(
846 struct ANativeWindow* window,
847 int mode)
848{
849 return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
850 mode);
851}
852
853/*
854 * native_window_api_connect(..., int api)
855 * connects an API to this window. only one API can be connected at a time.
856 * Returns -EINVAL if for some reason the window cannot be connected, which
857 * can happen if it's connected to some other API.
858 */
859static inline int native_window_api_connect(
860 struct ANativeWindow* window, int api)
861{
862 return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
863}
864
865/*
866 * native_window_api_disconnect(..., int api)
867 * disconnect the API from this window.
868 * An error is returned if for instance the window wasn't connected in the
869 * first place.
870 */
871static inline int native_window_api_disconnect(
872 struct ANativeWindow* window, int api)
873{
874 return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
875}
876
877/*
878 * native_window_dequeue_buffer_and_wait(...)
879 * Dequeue a buffer and wait on the fence associated with that buffer. The
880 * buffer may safely be accessed immediately upon this function returning. An
881 * error is returned if either of the dequeue or the wait operations fail.
882 */
883static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
884 struct ANativeWindowBuffer** anb) {
885 return anw->dequeueBuffer_DEPRECATED(anw, anb);
886}
887
888/*
889 * native_window_set_sideband_stream(..., native_handle_t*)
890 * Attach a sideband buffer stream to a native window.
891 */
892static inline int native_window_set_sideband_stream(
893 struct ANativeWindow* window,
894 native_handle_t* sidebandHandle)
895{
896 return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
897 sidebandHandle);
898}
899
900/*
901 * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
902 * Set the surface damage (i.e., the region of the surface that has changed
903 * since the previous frame). The damage set by this call will be reset (to the
904 * default of full-surface damage) after calling queue, so this must be called
905 * prior to every frame with damage that does not cover the whole surface if the
906 * caller desires downstream consumers to use this optimization.
907 *
908 * The damage region is specified as an array of rectangles, with the important
909 * caveat that the origin of the surface is considered to be the bottom-left
910 * corner, as in OpenGL ES.
911 *
912 * If numRects is set to 0, rects may be NULL, and the surface damage will be
913 * set to the full surface (the same as if this function had not been called for
914 * this frame).
915 */
916static inline int native_window_set_surface_damage(
917 struct ANativeWindow* window,
918 const android_native_rect_t* rects, size_t numRects)
919{
920 return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
921 rects, numRects);
922}
923
924/*
925 * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
926 * Enable/disable shared buffer mode
927 */
928static inline int native_window_set_shared_buffer_mode(
929 struct ANativeWindow* window,
930 bool sharedBufferMode)
931{
932 return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
933 sharedBufferMode);
934}
935
936/*
937 * native_window_set_auto_refresh(..., autoRefresh)
938 * Enable/disable auto refresh when in shared buffer mode
939 */
940static inline int native_window_set_auto_refresh(
941 struct ANativeWindow* window,
942 bool autoRefresh)
943{
944 return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
945}
946
947static inline int native_window_get_refresh_cycle_duration(
948 struct ANativeWindow* window,
949 int64_t* outRefreshDuration)
950{
951 return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION,
952 outRefreshDuration);
953}
954
955static inline int native_window_get_next_frame_id(
956 struct ANativeWindow* window, uint64_t* frameId)
957{
958 return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId);
959}
960
961static inline int native_window_enable_frame_timestamps(
962 struct ANativeWindow* window, bool enable)
963{
964 return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS,
965 enable);
966}
967
968static inline int native_window_get_compositor_timing(
969 struct ANativeWindow* window,
970 int64_t* compositeDeadline, int64_t* compositeInterval,
971 int64_t* compositeToPresentLatency)
972{
973 return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING,
974 compositeDeadline, compositeInterval, compositeToPresentLatency);
975}
976
977static inline int native_window_get_frame_timestamps(
978 struct ANativeWindow* window, uint64_t frameId,
979 int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
980 int64_t* outLatchTime, int64_t* outFirstRefreshStartTime,
981 int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime,
982 int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime,
983 int64_t* outReleaseTime)
984{
985 return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
986 frameId, outRequestedPresentTime, outAcquireTime, outLatchTime,
987 outFirstRefreshStartTime, outLastRefreshStartTime,
988 outGpuCompositionDoneTime, outDisplayPresentTime,
989 outDequeueReadyTime, outReleaseTime);
990}
991
992static inline int native_window_get_wide_color_support(
993 struct ANativeWindow* window, bool* outSupport) {
Chia-I Wue2786ea2017-08-07 10:36:08 -0700994 return window->perform(window, NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT,
995 outSupport);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700996}
997
998static inline int native_window_get_hdr_support(struct ANativeWindow* window,
999 bool* outSupport) {
Chia-I Wue2786ea2017-08-07 10:36:08 -07001000 return window->perform(window, NATIVE_WINDOW_GET_HDR_SUPPORT, outSupport);
1001}
1002
1003static inline int native_window_get_consumer_usage(struct ANativeWindow* window,
1004 uint64_t* outUsage) {
1005 return window->perform(window, NATIVE_WINDOW_GET_CONSUMER_USAGE64, outUsage);
Mathias Agopiana6c0e202017-03-20 15:48:44 -07001006}
1007
Yiwei Zhang538cedc2019-06-24 19:35:03 -07001008/*
1009 * native_window_set_auto_prerotation(..., autoPrerotation)
1010 * Enable/disable the auto prerotation at buffer allocation when the buffer size
1011 * is driven by the consumer.
1012 *
1013 * When buffer size is driven by the consumer and the transform hint specifies
1014 * a 90 or 270 degree rotation, if auto prerotation is enabled, the width and
1015 * height used for dequeueBuffer will be additionally swapped.
1016 */
1017static inline int native_window_set_auto_prerotation(struct ANativeWindow* window,
1018 bool autoPrerotation) {
1019 return window->perform(window, NATIVE_WINDOW_SET_AUTO_PREROTATION, autoPrerotation);
1020}
1021
Steven Thomas62a4cf82020-01-31 12:04:03 -08001022static inline int native_window_set_frame_rate(struct ANativeWindow* window, float frameRate,
Marin Shalamanovc5986772021-03-16 16:09:49 +01001023 int8_t compatibility, int8_t changeFrameRateStrategy) {
Steven Thomas62a4cf82020-01-31 12:04:03 -08001024 return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate,
Marin Shalamanovc5986772021-03-16 16:09:49 +01001025 (int)compatibility, (int)changeFrameRateStrategy);
Steven Thomas3172e202020-01-06 19:25:30 -08001026}
1027
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -10001028static inline int native_window_set_frame_timeline_info(struct ANativeWindow* window,
1029 int64_t frameTimelineVsyncId,
1030 int32_t inputEventId) {
1031 return window->perform(window, NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO,
1032 frameTimelineVsyncId, inputEventId);
Ady Abraham74e17562020-08-24 18:18:19 -07001033}
1034
Ady Abraham564f9de2021-02-03 18:34:33 -08001035static inline int native_window_get_extra_buffer_count(
1036 struct ANativeWindow* window, int* extraBuffers) {
1037 return window->perform(window, NATIVE_WINDOW_GET_EXTRA_BUFFER_COUNT, extraBuffers);
1038}
1039
Alec Mourief0b1532019-12-17 09:39:07 -08001040// ------------------------------------------------------------------------------------------------
1041// Candidates for APEX visibility
1042// These functions are planned to be made stable for APEX modules, but have not
1043// yet been stabilized to a specific api version.
1044// ------------------------------------------------------------------------------------------------
1045
1046/**
1047 * Retrieves the last queued buffer for this window, along with the fence that
1048 * fires when the buffer is ready to be read, and the 4x4 coordinate
1049 * transform matrix that should be applied to the buffer's content. The
1050 * transform matrix is represented in column-major order.
1051 *
1052 * If there was no buffer previously queued, then outBuffer will be NULL and
1053 * the value of outFence will be -1.
1054 *
1055 * Note that if outBuffer is not NULL, then the caller will hold a reference
1056 * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release
1057 * when the buffer is no longer needed so that the system may reclaim the
1058 * buffer.
1059 *
1060 * \return NO_ERROR on success.
1061 * \return NO_MEMORY if there was insufficient memory.
1062 */
1063static inline int ANativeWindow_getLastQueuedBuffer(ANativeWindow* window,
1064 AHardwareBuffer** outBuffer, int* outFence,
1065 float outTransformMatrix[16]) {
1066 return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER, outBuffer, outFence,
1067 outTransformMatrix);
1068}
1069
Alec Mourid41a1be2020-02-14 15:18:11 -08001070/**
John Reckaa5a0b22021-05-18 00:42:56 -04001071 * Retrieves the last queued buffer for this window, along with the fence that
1072 * fires when the buffer is ready to be read. The cropRect & transform should be applied to the
1073 * buffer's content.
1074 *
1075 * If there was no buffer previously queued, then outBuffer will be NULL and
1076 * the value of outFence will be -1.
1077 *
1078 * Note that if outBuffer is not NULL, then the caller will hold a reference
1079 * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release
1080 * when the buffer is no longer needed so that the system may reclaim the
1081 * buffer.
1082 *
1083 * \return NO_ERROR on success.
1084 * \return NO_MEMORY if there was insufficient memory.
1085 * \return STATUS_UNKNOWN_TRANSACTION if this ANativeWindow doesn't support this method, callers
1086 * should fall back to ANativeWindow_getLastQueuedBuffer instead.
1087 */
1088static inline int ANativeWindow_getLastQueuedBuffer2(ANativeWindow* window,
1089 AHardwareBuffer** outBuffer, int* outFence,
1090 ARect* outCropRect, uint32_t* outTransform) {
1091 return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2, outBuffer, outFence,
1092 outCropRect, outTransform);
1093}
1094
1095/**
Alec Mourid41a1be2020-02-14 15:18:11 -08001096 * Retrieves an identifier for the next frame to be queued by this window.
1097 *
1098 * \return the next frame id.
1099 */
1100static inline int64_t ANativeWindow_getNextFrameId(ANativeWindow* window) {
1101 int64_t value;
1102 window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, &value);
1103 return value;
1104}
1105
John Reck401cda62020-05-07 16:04:41 -07001106/**
1107 * Prototype of the function that an ANativeWindow implementation would call
1108 * when ANativeWindow_query is called.
1109 */
1110typedef int (*ANativeWindow_queryFn)(const ANativeWindow* window, int what, int* value);
1111
1112/**
1113 * Prototype of the function that intercepts an invocation of
1114 * ANativeWindow_queryFn, along with a data pointer that's passed by the
1115 * caller who set the interceptor, as well as arguments that would be
1116 * passed to ANativeWindow_queryFn if it were to be called.
1117 */
1118typedef int (*ANativeWindow_queryInterceptor)(const ANativeWindow* window,
1119 ANativeWindow_queryFn perform, void* data,
1120 int what, int* value);
1121
1122/**
1123 * Registers an interceptor for ANativeWindow_query. Instead of calling
1124 * the underlying query function, instead the provided interceptor is
1125 * called, which may optionally call the underlying query function. An
1126 * optional data pointer is also provided to side-channel additional arguments.
1127 *
1128 * Note that usage of this should only be used for specialized use-cases by
1129 * either the system partition or to Mainline modules. This should never be
1130 * exposed to NDK or LL-NDK.
1131 *
1132 * Returns NO_ERROR on success, -errno if registration failed.
1133 */
1134static inline int ANativeWindow_setQueryInterceptor(ANativeWindow* window,
1135 ANativeWindow_queryInterceptor interceptor,
1136 void* data) {
1137 return window->perform(window, NATIVE_WINDOW_SET_QUERY_INTERCEPTOR, interceptor, data);
1138}
1139
Mathias Agopiana6c0e202017-03-20 15:48:44 -07001140__END_DECLS