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