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