blob: 8f850070b6c7dd692defa35e7a49aa7de944255b [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>
37#include <stdint.h>
38#include <string.h>
39#include <sys/cdefs.h>
40#include <system/graphics.h>
41#include <unistd.h>
42#include <stdbool.h>
43
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 {
66 NATIVE_WINDOW_WIDTH = 0,
67 NATIVE_WINDOW_HEIGHT = 1,
68 NATIVE_WINDOW_FORMAT = 2,
69
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
150 */
151 NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
152
153 /*
154 * Returns the duration of the last queueBuffer call in microseconds
155 */
156 NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
157
158 /*
159 * Returns the number of image layers that the ANativeWindow buffer
160 * contains. By default this is 1, unless a buffer is explicitly allocated
161 * to contain multiple layers.
162 */
163 NATIVE_WINDOW_LAYER_COUNT = 16,
164
165 /*
166 * Returns 1 if the native window is valid, 0 otherwise. native window is valid
167 * if it is safe (i.e. no crash will occur) to call any method on it.
168 */
169 NATIVE_WINDOW_IS_VALID = 17,
Brian Anderson6b376712017-04-04 10:51:39 -0700170
171 /*
172 * Returns 1 if NATIVE_WINDOW_GET_FRAME_TIMESTAMPS will return display
173 * present info, 0 if it won't.
174 */
175 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18,
Jiwen 'Steve' Cai20419132017-04-21 18:49:53 -0700176
177 /*
178 * The consumer end is capable of handling protected buffers, i.e. buffer
179 * with GRALLOC_USAGE_PROTECTED usage bits on.
180 */
181 NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19,
Peiyong Lin654f87b2018-01-30 14:21:33 -0800182
183 /*
184 * Returns data space for the buffers.
185 */
186 NATIVE_WINDOW_DATASPACE = 20,
Yiwei Zhangdbd96152018-02-08 14:22:53 -0800187
188 /*
189 * Returns maxBufferCount set by BufferQueueConsumer
190 */
191 NATIVE_WINDOW_MAX_BUFFER_COUNT = 21,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700192};
193
194/* Valid operations for the (*perform)() hook.
195 *
196 * Values marked as 'deprecated' are supported, but have been superceded by
197 * other functionality.
198 *
199 * Values marked as 'private' should be considered private to the framework.
200 * HAL implementation code with access to an ANativeWindow should not use these,
201 * as it may not interact properly with the framework's use of the
202 * ANativeWindow.
203 */
204enum {
Valerie Haua82679d2018-11-21 09:31:43 -0800205 // clang-format off
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700206 NATIVE_WINDOW_SET_USAGE = 0, /* deprecated */
207 NATIVE_WINDOW_CONNECT = 1, /* deprecated */
208 NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */
209 NATIVE_WINDOW_SET_CROP = 3, /* private */
210 NATIVE_WINDOW_SET_BUFFER_COUNT = 4,
211 NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */
212 NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6,
213 NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7,
214 NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8,
215 NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9,
216 NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */
217 NATIVE_WINDOW_LOCK = 11, /* private */
218 NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */
219 NATIVE_WINDOW_API_CONNECT = 13, /* private */
220 NATIVE_WINDOW_API_DISCONNECT = 14, /* private */
221 NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
222 NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* deprecated, unimplemented */
223 NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17, /* private */
224 NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18,
225 NATIVE_WINDOW_SET_BUFFERS_DATASPACE = 19,
226 NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */
227 NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21,
228 NATIVE_WINDOW_SET_AUTO_REFRESH = 22,
229 NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION = 23,
230 NATIVE_WINDOW_GET_NEXT_FRAME_ID = 24,
231 NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS = 25,
232 NATIVE_WINDOW_GET_COMPOSITOR_TIMING = 26,
233 NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 27,
234 NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT = 28,
235 NATIVE_WINDOW_GET_HDR_SUPPORT = 29,
236 NATIVE_WINDOW_SET_USAGE64 = 30,
237 NATIVE_WINDOW_GET_CONSUMER_USAGE64 = 31,
238 NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA = 32,
239 NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA = 33,
Valerie Haua82679d2018-11-21 09:31:43 -0800240 NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA = 34,
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700241 NATIVE_WINDOW_SET_AUTO_PREROTATION = 35,
Alec Mouria1619662019-08-21 19:30:48 -0700242 NATIVE_WINDOW_GET_LAST_DEQUEUE_START = 36, /* private */
Alec Mouri04fdb602019-08-23 19:41:43 -0700243 NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT = 37, /* private */
Valerie Haua82679d2018-11-21 09:31:43 -0800244 // clang-format on
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700245};
246
247/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
248enum {
249 /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
250 * OpenGL ES.
251 */
252 NATIVE_WINDOW_API_EGL = 1,
253
254 /* Buffers will be queued after being filled using the CPU
255 */
256 NATIVE_WINDOW_API_CPU = 2,
257
258 /* Buffers will be queued by Stagefright after being filled by a video
259 * decoder. The video decoder can either be a software or hardware decoder.
260 */
261 NATIVE_WINDOW_API_MEDIA = 3,
262
263 /* Buffers will be queued by the the camera HAL.
264 */
265 NATIVE_WINDOW_API_CAMERA = 4,
266};
267
268/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
269enum {
270 /* flip source image horizontally */
271 NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
272 /* flip source image vertically */
273 NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
274 /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
275 NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
276 /* rotate source image 180 degrees */
277 NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
278 /* rotate source image 270 degrees clock-wise */
279 NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
280 /* transforms source by the inverse transform of the screen it is displayed onto. This
281 * transform is applied last */
282 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
283};
284
285/* parameter for NATIVE_WINDOW_SET_SCALING_MODE
286 * keep in sync with Surface.java in frameworks/base */
287enum {
288 /* the window content is not updated (frozen) until a buffer of
289 * the window size is received (enqueued)
290 */
291 NATIVE_WINDOW_SCALING_MODE_FREEZE = 0,
292 /* the buffer is scaled in both dimensions to match the window size */
293 NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1,
294 /* the buffer is scaled uniformly such that the smaller dimension
295 * of the buffer matches the window size (cropping in the process)
296 */
297 NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2,
298 /* the window is clipped to the size of the buffer's crop rectangle; pixels
299 * outside the crop rectangle are treated as if they are completely
300 * transparent.
301 */
302 NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3,
303};
304
305/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
306enum {
307 NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
308 NATIVE_WINDOW_SURFACE = 1, /* Surface */
309};
310
311/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
312 *
313 * Special timestamp value to indicate that timestamps should be auto-generated
314 * by the native window when queueBuffer is called. This is equal to INT64_MIN,
315 * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
316 */
317static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
318
Brian Andersondc96fdf2017-03-20 16:54:25 -0700319/* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS
320 *
321 * Special timestamp value to indicate the timestamps aren't yet known or
322 * that they are invalid.
323 */
324static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2;
325static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1;
326
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700327struct ANativeWindow
328{
329#ifdef __cplusplus
330 ANativeWindow()
331 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
332 {
333 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
334 common.version = sizeof(ANativeWindow);
335 memset(common.reserved, 0, sizeof(common.reserved));
336 }
337
338 /* Implement the methods that sp<ANativeWindow> expects so that it
339 can be used to automatically refcount ANativeWindow's. */
340 void incStrong(const void* /*id*/) const {
341 common.incRef(const_cast<android_native_base_t*>(&common));
342 }
343 void decStrong(const void* /*id*/) const {
344 common.decRef(const_cast<android_native_base_t*>(&common));
345 }
346#endif
347
348 struct android_native_base_t common;
349
350 /* flags describing some attributes of this surface or its updater */
351 const uint32_t flags;
352
353 /* min swap interval supported by this updated */
354 const int minSwapInterval;
355
356 /* max swap interval supported by this updated */
357 const int maxSwapInterval;
358
359 /* horizontal and vertical resolution in DPI */
360 const float xdpi;
361 const float ydpi;
362
363 /* Some storage reserved for the OEM's driver. */
364 intptr_t oem[4];
365
366 /*
367 * Set the swap interval for this surface.
368 *
369 * Returns 0 on success or -errno on error.
370 */
371 int (*setSwapInterval)(struct ANativeWindow* window,
372 int interval);
373
374 /*
375 * Hook called by EGL to acquire a buffer. After this call, the buffer
376 * is not locked, so its content cannot be modified. This call may block if
377 * no buffers are available.
378 *
379 * The window holds a reference to the buffer between dequeueBuffer and
380 * either queueBuffer or cancelBuffer, so clients only need their own
381 * reference if they might use the buffer after queueing or canceling it.
382 * Holding a reference to a buffer after queueing or canceling it is only
383 * allowed if a specific buffer count has been set.
384 *
385 * Returns 0 on success or -errno on error.
386 *
387 * XXX: This function is deprecated. It will continue to work for some
388 * time for binary compatibility, but the new dequeueBuffer function that
389 * outputs a fence file descriptor should be used in its place.
390 */
391 int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
392 struct ANativeWindowBuffer** buffer);
393
394 /*
395 * hook called by EGL to lock a buffer. This MUST be called before modifying
396 * the content of a buffer. The buffer must have been acquired with
397 * dequeueBuffer first.
398 *
399 * Returns 0 on success or -errno on error.
400 *
401 * XXX: This function is deprecated. It will continue to work for some
402 * time for binary compatibility, but it is essentially a no-op, and calls
403 * to it should be removed.
404 */
405 int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
406 struct ANativeWindowBuffer* buffer);
407
408 /*
409 * Hook called by EGL when modifications to the render buffer are done.
410 * This unlocks and post the buffer.
411 *
412 * The window holds a reference to the buffer between dequeueBuffer and
413 * either queueBuffer or cancelBuffer, so clients only need their own
414 * reference if they might use the buffer after queueing or canceling it.
415 * Holding a reference to a buffer after queueing or canceling it is only
416 * allowed if a specific buffer count has been set.
417 *
418 * Buffers MUST be queued in the same order than they were dequeued.
419 *
420 * Returns 0 on success or -errno on error.
421 *
422 * XXX: This function is deprecated. It will continue to work for some
423 * time for binary compatibility, but the new queueBuffer function that
424 * takes a fence file descriptor should be used in its place (pass a value
425 * of -1 for the fence file descriptor if there is no valid one to pass).
426 */
427 int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
428 struct ANativeWindowBuffer* buffer);
429
430 /*
431 * hook used to retrieve information about the native window.
432 *
433 * Returns 0 on success or -errno on error.
434 */
435 int (*query)(const struct ANativeWindow* window,
436 int what, int* value);
437
438 /*
439 * hook used to perform various operations on the surface.
440 * (*perform)() is a generic mechanism to add functionality to
441 * ANativeWindow while keeping backward binary compatibility.
442 *
443 * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
444 * defined below.
445 *
446 * (*perform)() returns -ENOENT if the 'what' parameter is not supported
447 * by the surface's implementation.
448 *
449 * See above for a list of valid operations, such as
450 * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
451 */
452 int (*perform)(struct ANativeWindow* window,
453 int operation, ... );
454
455 /*
456 * Hook used to cancel a buffer that has been dequeued.
457 * No synchronization is performed between dequeue() and cancel(), so
458 * either external synchronization is needed, or these functions must be
459 * called from the same thread.
460 *
461 * The window holds a reference to the buffer between dequeueBuffer and
462 * either queueBuffer or cancelBuffer, so clients only need their own
463 * reference if they might use the buffer after queueing or canceling it.
464 * Holding a reference to a buffer after queueing or canceling it is only
465 * allowed if a specific buffer count has been set.
466 *
467 * XXX: This function is deprecated. It will continue to work for some
468 * time for binary compatibility, but the new cancelBuffer function that
469 * takes a fence file descriptor should be used in its place (pass a value
470 * of -1 for the fence file descriptor if there is no valid one to pass).
471 */
472 int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
473 struct ANativeWindowBuffer* buffer);
474
475 /*
476 * Hook called by EGL to acquire a buffer. This call may block if no
477 * buffers are available.
478 *
479 * The window holds a reference to the buffer between dequeueBuffer and
480 * either queueBuffer or cancelBuffer, so clients only need their own
481 * reference if they might use the buffer after queueing or canceling it.
482 * Holding a reference to a buffer after queueing or canceling it is only
483 * allowed if a specific buffer count has been set.
484 *
485 * The libsync fence file descriptor returned in the int pointed to by the
486 * fenceFd argument will refer to the fence that must signal before the
487 * dequeued buffer may be written to. A value of -1 indicates that the
488 * caller may access the buffer immediately without waiting on a fence. If
489 * a valid file descriptor is returned (i.e. any value except -1) then the
490 * caller is responsible for closing the file descriptor.
491 *
492 * Returns 0 on success or -errno on error.
493 */
494 int (*dequeueBuffer)(struct ANativeWindow* window,
495 struct ANativeWindowBuffer** buffer, int* fenceFd);
496
497 /*
498 * Hook called by EGL when modifications to the render buffer are done.
499 * This unlocks and post the buffer.
500 *
501 * The window holds a reference to the buffer between dequeueBuffer and
502 * either queueBuffer or cancelBuffer, so clients only need their own
503 * reference if they might use the buffer after queueing or canceling it.
504 * Holding a reference to a buffer after queueing or canceling it is only
505 * allowed if a specific buffer count has been set.
506 *
507 * The fenceFd argument specifies a libsync fence file descriptor for a
508 * fence that must signal before the buffer can be accessed. If the buffer
509 * can be accessed immediately then a value of -1 should be used. The
510 * caller must not use the file descriptor after it is passed to
511 * queueBuffer, and the ANativeWindow implementation is responsible for
512 * closing it.
513 *
514 * Returns 0 on success or -errno on error.
515 */
516 int (*queueBuffer)(struct ANativeWindow* window,
517 struct ANativeWindowBuffer* buffer, int fenceFd);
518
519 /*
520 * Hook used to cancel a buffer that has been dequeued.
521 * No synchronization is performed between dequeue() and cancel(), so
522 * either external synchronization is needed, or these functions must be
523 * called from the same thread.
524 *
525 * The window holds a reference to the buffer between dequeueBuffer and
526 * either queueBuffer or cancelBuffer, so clients only need their own
527 * reference if they might use the buffer after queueing or canceling it.
528 * Holding a reference to a buffer after queueing or canceling it is only
529 * allowed if a specific buffer count has been set.
530 *
531 * The fenceFd argument specifies a libsync fence file decsriptor for a
532 * fence that must signal before the buffer can be accessed. If the buffer
533 * can be accessed immediately then a value of -1 should be used.
534 *
535 * Note that if the client has not waited on the fence that was returned
536 * from dequeueBuffer, that same fence should be passed to cancelBuffer to
537 * ensure that future uses of the buffer are preceded by a wait on that
538 * fence. The caller must not use the file descriptor after it is passed
539 * to cancelBuffer, and the ANativeWindow implementation is responsible for
540 * closing it.
541 *
542 * Returns 0 on success or -errno on error.
543 */
544 int (*cancelBuffer)(struct ANativeWindow* window,
545 struct ANativeWindowBuffer* buffer, int fenceFd);
546};
547
548 /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
549 * android_native_window_t is deprecated.
550 */
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700551typedef struct ANativeWindow android_native_window_t __deprecated;
552
553/*
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700554 * native_window_set_usage64(..., usage)
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700555 * Sets the intended usage flags for the next buffers
556 * acquired with (*lockBuffer)() and on.
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700557 *
558 * Valid usage flags are defined in android/hardware_buffer.h
559 * All AHARDWAREBUFFER_USAGE_* flags can be specified as needed.
560 *
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700561 * Calling this function will usually cause following buffers to be
562 * reallocated.
563 */
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700564static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) {
565 return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700566}
567
568/* deprecated. Always returns 0. Don't call. */
569static inline int native_window_connect(
570 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
571
572static inline int native_window_connect(
573 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
574 return 0;
575}
576
577/* deprecated. Always returns 0. Don't call. */
578static inline int native_window_disconnect(
579 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
580
581static inline int native_window_disconnect(
582 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
583 return 0;
584}
585
586/*
587 * native_window_set_crop(..., crop)
588 * Sets which region of the next queued buffers needs to be considered.
589 * Depending on the scaling mode, a buffer's crop region is scaled and/or
590 * cropped to match the surface's size. This function sets the crop in
591 * pre-transformed buffer pixel coordinates.
592 *
593 * The specified crop region applies to all buffers queued after it is called.
594 *
595 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
596 *
597 * An error is returned if for instance the crop region is invalid, out of the
598 * buffer's bound or if the window is invalid.
599 */
600static inline int native_window_set_crop(
601 struct ANativeWindow* window,
602 android_native_rect_t const * crop)
603{
604 return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
605}
606
607/*
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700608 * native_window_set_buffer_count(..., count)
609 * Sets the number of buffers associated with this native window.
610 */
611static inline int native_window_set_buffer_count(
612 struct ANativeWindow* window,
613 size_t bufferCount)
614{
615 return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
616}
617
618/*
619 * native_window_set_buffers_geometry(..., int w, int h, int format)
620 * All buffers dequeued after this call will have the dimensions and format
621 * specified. A successful call to this function has the same effect as calling
622 * native_window_set_buffers_size and native_window_set_buffers_format.
623 *
624 * XXX: This function is deprecated. The native_window_set_buffers_dimensions
625 * and native_window_set_buffers_format functions should be used instead.
626 */
627static inline int native_window_set_buffers_geometry(
628 struct ANativeWindow* window,
629 int w, int h, int format) __deprecated;
630
631static inline int native_window_set_buffers_geometry(
632 struct ANativeWindow* window,
633 int w, int h, int format)
634{
635 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
636 w, h, format);
637}
638
639/*
640 * native_window_set_buffers_dimensions(..., int w, int h)
641 * All buffers dequeued after this call will have the dimensions specified.
642 * In particular, all buffers will have a fixed-size, independent from the
643 * native-window size. They will be scaled according to the scaling mode
644 * (see native_window_set_scaling_mode) upon window composition.
645 *
646 * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
647 * following this call will be sized to match the window's size.
648 *
649 * Calling this function will reset the window crop to a NULL value, which
650 * disables cropping of the buffers.
651 */
652static inline int native_window_set_buffers_dimensions(
653 struct ANativeWindow* window,
654 int w, int h)
655{
656 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
657 w, h);
658}
659
660/*
661 * native_window_set_buffers_user_dimensions(..., int w, int h)
662 *
663 * Sets the user buffer size for the window, which overrides the
664 * window's size. All buffers dequeued after this call will have the
665 * dimensions specified unless overridden by
666 * native_window_set_buffers_dimensions. All buffers will have a
667 * fixed-size, independent from the native-window size. They will be
668 * scaled according to the scaling mode (see
669 * native_window_set_scaling_mode) upon window composition.
670 *
671 * If w and h are 0, the normal behavior is restored. That is, the
672 * default buffer size will match the windows's size.
673 *
674 * Calling this function will reset the window crop to a NULL value, which
675 * disables cropping of the buffers.
676 */
677static inline int native_window_set_buffers_user_dimensions(
678 struct ANativeWindow* window,
679 int w, int h)
680{
681 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
682 w, h);
683}
684
685/*
686 * native_window_set_buffers_format(..., int format)
687 * All buffers dequeued after this call will have the format specified.
688 *
689 * If the specified format is 0, the default buffer format will be used.
690 */
691static inline int native_window_set_buffers_format(
692 struct ANativeWindow* window,
693 int format)
694{
695 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
696}
697
698/*
699 * native_window_set_buffers_data_space(..., int dataSpace)
700 * All buffers queued after this call will be associated with the dataSpace
701 * parameter specified.
702 *
703 * dataSpace specifies additional information about the buffer that's dependent
704 * on the buffer format and the endpoints. For example, it can be used to convey
705 * the color space of the image data in the buffer, or it can be used to
706 * indicate that the buffers contain depth measurement data instead of color
707 * images. The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
708 * overridden by the consumer.
709 */
710static inline int native_window_set_buffers_data_space(
711 struct ANativeWindow* window,
712 android_dataspace_t dataSpace)
713{
714 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
715 dataSpace);
716}
717
718/*
Courtney Goeltzenleuchter9bad0d72017-12-19 12:34:34 -0700719 * native_window_set_buffers_smpte2086_metadata(..., metadata)
720 * All buffers queued after this call will be associated with the SMPTE
721 * ST.2086 metadata specified.
722 *
723 * metadata specifies additional information about the contents of the buffer
724 * that may affect how it's displayed. When it is nullptr, it means no such
725 * information is available. No SMPTE ST.2086 metadata is associated with the
726 * buffers by default.
727 */
728static inline int native_window_set_buffers_smpte2086_metadata(
729 struct ANativeWindow* window,
730 const struct android_smpte2086_metadata* metadata)
731{
732 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA,
733 metadata);
734}
735
736/*
737 * native_window_set_buffers_cta861_3_metadata(..., metadata)
738 * All buffers queued after this call will be associated with the CTA-861.3
739 * metadata specified.
740 *
741 * metadata specifies additional information about the contents of the buffer
742 * that may affect how it's displayed. When it is nullptr, it means no such
743 * information is available. No CTA-861.3 metadata is associated with the
744 * buffers by default.
745 */
746static inline int native_window_set_buffers_cta861_3_metadata(
747 struct ANativeWindow* window,
748 const struct android_cta861_3_metadata* metadata)
749{
750 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA,
751 metadata);
752}
753
754/*
Valerie Haua82679d2018-11-21 09:31:43 -0800755 * native_window_set_buffers_hdr10_plus_metadata(..., metadata)
756 * All buffers queued after this call will be associated with the
757 * HDR10+ dynamic metadata specified.
758 *
759 * metadata specifies additional dynamic information about the
760 * contents of the buffer that may affect how it is displayed. When
761 * it is nullptr, it means no such information is available. No
762 * HDR10+ dynamic emtadata is associated with the buffers by default.
763 *
764 * Parameter "size" refers to the length of the metadata blob pointed to
765 * by parameter "data". The metadata blob will adhere to the HDR10+ SEI
766 * message standard.
767 */
768static inline int native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow* window,
769 const size_t size,
770 const uint8_t* metadata) {
771 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA, size,
772 metadata);
773}
774
775/*
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700776 * native_window_set_buffers_transform(..., int transform)
777 * All buffers queued after this call will be displayed transformed according
778 * to the transform parameter specified.
779 */
780static inline int native_window_set_buffers_transform(
781 struct ANativeWindow* window,
782 int transform)
783{
784 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
785 transform);
786}
787
788/*
789 * native_window_set_buffers_sticky_transform(..., int transform)
790 * All buffers queued after this call will be displayed transformed according
791 * to the transform parameter specified applied on top of the regular buffer
792 * transform. Setting this transform will disable the transform hint.
793 *
794 * Temporary - This is only intended to be used by the LEGACY camera mode, do
795 * not use this for anything else.
796 */
797static inline int native_window_set_buffers_sticky_transform(
798 struct ANativeWindow* window,
799 int transform)
800{
801 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
802 transform);
803}
804
805/*
806 * native_window_set_buffers_timestamp(..., int64_t timestamp)
807 * All buffers queued after this call will be associated with the timestamp
808 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
809 * (the default), timestamps will be generated automatically when queueBuffer is
810 * called. The timestamp is measured in nanoseconds, and is normally monotonically
811 * increasing. The timestamp should be unaffected by time-of-day adjustments,
812 * and for a camera should be strictly monotonic but for a media player may be
813 * reset when the position is set.
814 */
815static inline int native_window_set_buffers_timestamp(
816 struct ANativeWindow* window,
817 int64_t timestamp)
818{
819 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
820 timestamp);
821}
822
823/*
824 * native_window_set_scaling_mode(..., int mode)
825 * All buffers queued after this call will be associated with the scaling mode
826 * specified.
827 */
828static inline int native_window_set_scaling_mode(
829 struct ANativeWindow* window,
830 int mode)
831{
832 return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
833 mode);
834}
835
836/*
837 * native_window_api_connect(..., int api)
838 * connects an API to this window. only one API can be connected at a time.
839 * Returns -EINVAL if for some reason the window cannot be connected, which
840 * can happen if it's connected to some other API.
841 */
842static inline int native_window_api_connect(
843 struct ANativeWindow* window, int api)
844{
845 return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
846}
847
848/*
849 * native_window_api_disconnect(..., int api)
850 * disconnect the API from this window.
851 * An error is returned if for instance the window wasn't connected in the
852 * first place.
853 */
854static inline int native_window_api_disconnect(
855 struct ANativeWindow* window, int api)
856{
857 return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
858}
859
860/*
861 * native_window_dequeue_buffer_and_wait(...)
862 * Dequeue a buffer and wait on the fence associated with that buffer. The
863 * buffer may safely be accessed immediately upon this function returning. An
864 * error is returned if either of the dequeue or the wait operations fail.
865 */
866static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
867 struct ANativeWindowBuffer** anb) {
868 return anw->dequeueBuffer_DEPRECATED(anw, anb);
869}
870
871/*
872 * native_window_set_sideband_stream(..., native_handle_t*)
873 * Attach a sideband buffer stream to a native window.
874 */
875static inline int native_window_set_sideband_stream(
876 struct ANativeWindow* window,
877 native_handle_t* sidebandHandle)
878{
879 return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
880 sidebandHandle);
881}
882
883/*
884 * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
885 * Set the surface damage (i.e., the region of the surface that has changed
886 * since the previous frame). The damage set by this call will be reset (to the
887 * default of full-surface damage) after calling queue, so this must be called
888 * prior to every frame with damage that does not cover the whole surface if the
889 * caller desires downstream consumers to use this optimization.
890 *
891 * The damage region is specified as an array of rectangles, with the important
892 * caveat that the origin of the surface is considered to be the bottom-left
893 * corner, as in OpenGL ES.
894 *
895 * If numRects is set to 0, rects may be NULL, and the surface damage will be
896 * set to the full surface (the same as if this function had not been called for
897 * this frame).
898 */
899static inline int native_window_set_surface_damage(
900 struct ANativeWindow* window,
901 const android_native_rect_t* rects, size_t numRects)
902{
903 return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
904 rects, numRects);
905}
906
907/*
908 * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
909 * Enable/disable shared buffer mode
910 */
911static inline int native_window_set_shared_buffer_mode(
912 struct ANativeWindow* window,
913 bool sharedBufferMode)
914{
915 return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
916 sharedBufferMode);
917}
918
919/*
920 * native_window_set_auto_refresh(..., autoRefresh)
921 * Enable/disable auto refresh when in shared buffer mode
922 */
923static inline int native_window_set_auto_refresh(
924 struct ANativeWindow* window,
925 bool autoRefresh)
926{
927 return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
928}
929
930static inline int native_window_get_refresh_cycle_duration(
931 struct ANativeWindow* window,
932 int64_t* outRefreshDuration)
933{
934 return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION,
935 outRefreshDuration);
936}
937
938static inline int native_window_get_next_frame_id(
939 struct ANativeWindow* window, uint64_t* frameId)
940{
941 return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId);
942}
943
944static inline int native_window_enable_frame_timestamps(
945 struct ANativeWindow* window, bool enable)
946{
947 return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS,
948 enable);
949}
950
951static inline int native_window_get_compositor_timing(
952 struct ANativeWindow* window,
953 int64_t* compositeDeadline, int64_t* compositeInterval,
954 int64_t* compositeToPresentLatency)
955{
956 return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING,
957 compositeDeadline, compositeInterval, compositeToPresentLatency);
958}
959
960static inline int native_window_get_frame_timestamps(
961 struct ANativeWindow* window, uint64_t frameId,
962 int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
963 int64_t* outLatchTime, int64_t* outFirstRefreshStartTime,
964 int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime,
965 int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime,
966 int64_t* outReleaseTime)
967{
968 return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
969 frameId, outRequestedPresentTime, outAcquireTime, outLatchTime,
970 outFirstRefreshStartTime, outLastRefreshStartTime,
971 outGpuCompositionDoneTime, outDisplayPresentTime,
972 outDequeueReadyTime, outReleaseTime);
973}
974
975static inline int native_window_get_wide_color_support(
976 struct ANativeWindow* window, bool* outSupport) {
Chia-I Wue2786ea2017-08-07 10:36:08 -0700977 return window->perform(window, NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT,
978 outSupport);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700979}
980
981static inline int native_window_get_hdr_support(struct ANativeWindow* window,
982 bool* outSupport) {
Chia-I Wue2786ea2017-08-07 10:36:08 -0700983 return window->perform(window, NATIVE_WINDOW_GET_HDR_SUPPORT, outSupport);
984}
985
986static inline int native_window_get_consumer_usage(struct ANativeWindow* window,
987 uint64_t* outUsage) {
988 return window->perform(window, NATIVE_WINDOW_GET_CONSUMER_USAGE64, outUsage);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700989}
990
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700991/*
992 * native_window_set_auto_prerotation(..., autoPrerotation)
993 * Enable/disable the auto prerotation at buffer allocation when the buffer size
994 * is driven by the consumer.
995 *
996 * When buffer size is driven by the consumer and the transform hint specifies
997 * a 90 or 270 degree rotation, if auto prerotation is enabled, the width and
998 * height used for dequeueBuffer will be additionally swapped.
999 */
1000static inline int native_window_set_auto_prerotation(struct ANativeWindow* window,
1001 bool autoPrerotation) {
1002 return window->perform(window, NATIVE_WINDOW_SET_AUTO_PREROTATION, autoPrerotation);
1003}
1004
Mathias Agopiana6c0e202017-03-20 15:48:44 -07001005__END_DECLS