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