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