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