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