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 <stdbool.h>
38 #include <stdint.h>
39 #include <string.h>
40 #include <sys/cdefs.h>
41 #include <system/graphics.h>
42 #include <unistd.h>
43 
44 // system/window.h is a superset of the vndk and apex apis
45 #include <apex/window.h>
46 #include <vndk/window.h>
47 
48 
49 #ifndef __UNUSED
50 #define __UNUSED __attribute__((__unused__))
51 #endif
52 #ifndef __deprecated
53 #define __deprecated __attribute__((__deprecated__))
54 #endif
55 
56 __BEGIN_DECLS
57 
58 /*****************************************************************************/
59 
60 #define ANDROID_NATIVE_WINDOW_MAGIC     ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
61 
62 // ---------------------------------------------------------------------------
63 
64 /* attributes queriable with query() */
65 enum {
66     NATIVE_WINDOW_WIDTH = 0,
67     NATIVE_WINDOW_HEIGHT = 1,
68     NATIVE_WINDOW_FORMAT = 2,
69 
70     /* see ANativeWindowQuery in vndk/window.h */
71     NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS,
72 
73     /* Check whether queueBuffer operations on the ANativeWindow send the buffer
74      * to the window compositor.  The query sets the returned 'value' argument
75      * to 1 if the ANativeWindow DOES send queued buffers directly to the window
76      * compositor and 0 if the buffers do not go directly to the window
77      * compositor.
78      *
79      * This can be used to determine whether protected buffer content should be
80      * sent to the ANativeWindow.  Note, however, that a result of 1 does NOT
81      * indicate that queued buffers will be protected from applications or users
82      * capturing their contents.  If that behavior is desired then some other
83      * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
84      * conjunction with this query.
85      */
86     NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
87 
88     /* Get the concrete type of a ANativeWindow.  See below for the list of
89      * possible return values.
90      *
91      * This query should not be used outside the Android framework and will
92      * likely be removed in the near future.
93      */
94     NATIVE_WINDOW_CONCRETE_TYPE = 5,
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      * Deprecated: please use NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION in
151      * perform() instead, which supports nanosecond precision.
152      */
153     NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
154 
155     /*
156      * Returns the duration of the last queueBuffer call in microseconds
157      * Deprecated: please use NATIVE_WINDOW_GET_LAST_QUEUE_DURATION in
158      * perform() instead, which supports nanosecond precision.
159      */
160     NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
161 
162     /*
163      * Returns the number of image layers that the ANativeWindow buffer
164      * contains. By default this is 1, unless a buffer is explicitly allocated
165      * to contain multiple layers.
166      */
167     NATIVE_WINDOW_LAYER_COUNT = 16,
168 
169     /*
170      * Returns 1 if the native window is valid, 0 otherwise. native window is valid
171      * if it is safe (i.e. no crash will occur) to call any method on it.
172      */
173     NATIVE_WINDOW_IS_VALID = 17,
174 
175     /*
176      * Returns 1 if NATIVE_WINDOW_GET_FRAME_TIMESTAMPS will return display
177      * present info, 0 if it won't.
178      */
179     NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18,
180 
181     /*
182      * The consumer end is capable of handling protected buffers, i.e. buffer
183      * with GRALLOC_USAGE_PROTECTED usage bits on.
184      */
185     NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19,
186 
187     /*
188      * Returns data space for the buffers.
189      */
190     NATIVE_WINDOW_DATASPACE = 20,
191 
192     /*
193      * Returns maxBufferCount set by BufferQueueConsumer
194      */
195     NATIVE_WINDOW_MAX_BUFFER_COUNT = 21,
196 };
197 
198 /* Valid operations for the (*perform)() hook.
199  *
200  * Values marked as 'deprecated' are supported, but have been superceded by
201  * other functionality.
202  *
203  * Values marked as 'private' should be considered private to the framework.
204  * HAL implementation code with access to an ANativeWindow should not use these,
205  * as it may not interact properly with the framework's use of the
206  * ANativeWindow.
207  */
208 enum {
209     // clang-format off
210     NATIVE_WINDOW_SET_USAGE                       =  ANATIVEWINDOW_PERFORM_SET_USAGE,   /* deprecated */
211     NATIVE_WINDOW_CONNECT                         =  1,   /* deprecated */
212     NATIVE_WINDOW_DISCONNECT                      =  2,   /* deprecated */
213     NATIVE_WINDOW_SET_CROP                        =  3,   /* private */
214     NATIVE_WINDOW_SET_BUFFER_COUNT                =  4,
215     NATIVE_WINDOW_SET_BUFFERS_GEOMETRY            =  ANATIVEWINDOW_PERFORM_SET_BUFFERS_GEOMETRY,   /* deprecated */
216     NATIVE_WINDOW_SET_BUFFERS_TRANSFORM           =  6,
217     NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP           =  7,
218     NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS          =  8,
219     NATIVE_WINDOW_SET_BUFFERS_FORMAT              =  ANATIVEWINDOW_PERFORM_SET_BUFFERS_FORMAT,
220     NATIVE_WINDOW_SET_SCALING_MODE                = 10,   /* private */
221     NATIVE_WINDOW_LOCK                            = 11,   /* private */
222     NATIVE_WINDOW_UNLOCK_AND_POST                 = 12,   /* private */
223     NATIVE_WINDOW_API_CONNECT                     = 13,   /* private */
224     NATIVE_WINDOW_API_DISCONNECT                  = 14,   /* private */
225     NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS     = 15,   /* private */
226     NATIVE_WINDOW_SET_POST_TRANSFORM_CROP         = 16,   /* deprecated, unimplemented */
227     NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM    = 17,   /* private */
228     NATIVE_WINDOW_SET_SIDEBAND_STREAM             = 18,
229     NATIVE_WINDOW_SET_BUFFERS_DATASPACE           = 19,
230     NATIVE_WINDOW_SET_SURFACE_DAMAGE              = 20,   /* private */
231     NATIVE_WINDOW_SET_SHARED_BUFFER_MODE          = 21,
232     NATIVE_WINDOW_SET_AUTO_REFRESH                = 22,
233     NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION      = 23,
234     NATIVE_WINDOW_GET_NEXT_FRAME_ID               = 24,
235     NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS         = 25,
236     NATIVE_WINDOW_GET_COMPOSITOR_TIMING           = 26,
237     NATIVE_WINDOW_GET_FRAME_TIMESTAMPS            = 27,
238     NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT          = 28,
239     NATIVE_WINDOW_GET_HDR_SUPPORT                 = 29,
240     NATIVE_WINDOW_SET_USAGE64                     = ANATIVEWINDOW_PERFORM_SET_USAGE64,
241     NATIVE_WINDOW_GET_CONSUMER_USAGE64            = 31,
242     NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA  = 32,
243     NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA   = 33,
244     NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA = 34,
245     NATIVE_WINDOW_SET_AUTO_PREROTATION            = 35,
246     NATIVE_WINDOW_GET_LAST_DEQUEUE_START          = 36,    /* private */
247     NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT             = 37,    /* private */
248     NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION       = 38,    /* private */
249     NATIVE_WINDOW_GET_LAST_QUEUE_DURATION         = 39,    /* private */
250     NATIVE_WINDOW_SET_FRAME_RATE                  = 40,
251     NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR          = 41,    /* private */
252     NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR         = 42,    /* private */
253     NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR         = 43,    /* private */
254     NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR           = 44,    /* private */
255     NATIVE_WINDOW_ALLOCATE_BUFFERS                = 45,    /* private */
256     NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER          = 46,    /* private */
257     NATIVE_WINDOW_SET_QUERY_INTERCEPTOR           = 47,    /* private */
258     // clang-format on
259 };
260 
261 /* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
262 enum {
263     /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
264      * OpenGL ES.
265      */
266     NATIVE_WINDOW_API_EGL = 1,
267 
268     /* Buffers will be queued after being filled using the CPU
269      */
270     NATIVE_WINDOW_API_CPU = 2,
271 
272     /* Buffers will be queued by Stagefright after being filled by a video
273      * decoder.  The video decoder can either be a software or hardware decoder.
274      */
275     NATIVE_WINDOW_API_MEDIA = 3,
276 
277     /* Buffers will be queued by the the camera HAL.
278      */
279     NATIVE_WINDOW_API_CAMERA = 4,
280 };
281 
282 /* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
283 enum {
284     /* flip source image horizontally */
285     NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
286     /* flip source image vertically */
287     NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
288     /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
289     NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
290     /* rotate source image 180 degrees */
291     NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
292     /* rotate source image 270 degrees clock-wise */
293     NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
294     /* transforms source by the inverse transform of the screen it is displayed onto. This
295      * transform is applied last */
296     NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
297 };
298 
299 /* parameter for NATIVE_WINDOW_SET_SCALING_MODE
300  * keep in sync with Surface.java in frameworks/base */
301 enum {
302     /* the window content is not updated (frozen) until a buffer of
303      * the window size is received (enqueued)
304      */
305     NATIVE_WINDOW_SCALING_MODE_FREEZE           = 0,
306     /* the buffer is scaled in both dimensions to match the window size */
307     NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW  = 1,
308     /* the buffer is scaled uniformly such that the smaller dimension
309      * of the buffer matches the window size (cropping in the process)
310      */
311     NATIVE_WINDOW_SCALING_MODE_SCALE_CROP       = 2,
312     /* the window is clipped to the size of the buffer's crop rectangle; pixels
313      * outside the crop rectangle are treated as if they are completely
314      * transparent.
315      */
316     NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP    = 3,
317 };
318 
319 /* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
320 enum {
321     NATIVE_WINDOW_FRAMEBUFFER               = 0, /* FramebufferNativeWindow */
322     NATIVE_WINDOW_SURFACE                   = 1, /* Surface */
323 };
324 
325 /* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
326  *
327  * Special timestamp value to indicate that timestamps should be auto-generated
328  * by the native window when queueBuffer is called.  This is equal to INT64_MIN,
329  * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
330  */
331 static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
332 
333 /* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS
334  *
335  * Special timestamp value to indicate the timestamps aren't yet known or
336  * that they are invalid.
337  */
338 static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2;
339 static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1;
340 
341 struct ANativeWindow
342 {
343 #ifdef __cplusplus
ANativeWindowANativeWindow344     ANativeWindow()
345         : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
346     {
347         common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
348         common.version = sizeof(ANativeWindow);
349         memset(common.reserved, 0, sizeof(common.reserved));
350     }
351 
352     /* Implement the methods that sp<ANativeWindow> expects so that it
353        can be used to automatically refcount ANativeWindow's. */
incStrongANativeWindow354     void incStrong(const void* /*id*/) const {
355         common.incRef(const_cast<android_native_base_t*>(&common));
356     }
decStrongANativeWindow357     void decStrong(const void* /*id*/) const {
358         common.decRef(const_cast<android_native_base_t*>(&common));
359     }
360 #endif
361 
362     struct android_native_base_t common;
363 
364     /* flags describing some attributes of this surface or its updater */
365     const uint32_t flags;
366 
367     /* min swap interval supported by this updated */
368     const int   minSwapInterval;
369 
370     /* max swap interval supported by this updated */
371     const int   maxSwapInterval;
372 
373     /* horizontal and vertical resolution in DPI */
374     const float xdpi;
375     const float ydpi;
376 
377     /* Some storage reserved for the OEM's driver. */
378     intptr_t    oem[4];
379 
380     /*
381      * Set the swap interval for this surface.
382      *
383      * Returns 0 on success or -errno on error.
384      */
385     int     (*setSwapInterval)(struct ANativeWindow* window,
386                 int interval);
387 
388     /*
389      * Hook called by EGL to acquire a buffer. After this call, the buffer
390      * is not locked, so its content cannot be modified. This call may block if
391      * no buffers are available.
392      *
393      * The window holds a reference to the buffer between dequeueBuffer and
394      * either queueBuffer or cancelBuffer, so clients only need their own
395      * reference if they might use the buffer after queueing or canceling it.
396      * Holding a reference to a buffer after queueing or canceling it is only
397      * allowed if a specific buffer count has been set.
398      *
399      * Returns 0 on success or -errno on error.
400      *
401      * XXX: This function is deprecated.  It will continue to work for some
402      * time for binary compatibility, but the new dequeueBuffer function that
403      * outputs a fence file descriptor should be used in its place.
404      */
405     int     (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
406                 struct ANativeWindowBuffer** buffer);
407 
408     /*
409      * hook called by EGL to lock a buffer. This MUST be called before modifying
410      * the content of a buffer. The buffer must have been acquired with
411      * dequeueBuffer first.
412      *
413      * Returns 0 on success or -errno on error.
414      *
415      * XXX: This function is deprecated.  It will continue to work for some
416      * time for binary compatibility, but it is essentially a no-op, and calls
417      * to it should be removed.
418      */
419     int     (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
420                 struct ANativeWindowBuffer* buffer);
421 
422     /*
423      * Hook called by EGL when modifications to the render buffer are done.
424      * This unlocks and post the buffer.
425      *
426      * The window holds a reference to the buffer between dequeueBuffer and
427      * either queueBuffer or cancelBuffer, so clients only need their own
428      * reference if they might use the buffer after queueing or canceling it.
429      * Holding a reference to a buffer after queueing or canceling it is only
430      * allowed if a specific buffer count has been set.
431      *
432      * Buffers MUST be queued in the same order than they were dequeued.
433      *
434      * Returns 0 on success or -errno on error.
435      *
436      * XXX: This function is deprecated.  It will continue to work for some
437      * time for binary compatibility, but the new queueBuffer function that
438      * takes a fence file descriptor should be used in its place (pass a value
439      * of -1 for the fence file descriptor if there is no valid one to pass).
440      */
441     int     (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
442                 struct ANativeWindowBuffer* buffer);
443 
444     /*
445      * hook used to retrieve information about the native window.
446      *
447      * Returns 0 on success or -errno on error.
448      */
449     int     (*query)(const struct ANativeWindow* window,
450                 int what, int* value);
451 
452     /*
453      * hook used to perform various operations on the surface.
454      * (*perform)() is a generic mechanism to add functionality to
455      * ANativeWindow while keeping backward binary compatibility.
456      *
457      * DO NOT CALL THIS HOOK DIRECTLY.  Instead, use the helper functions
458      * defined below.
459      *
460      * (*perform)() returns -ENOENT if the 'what' parameter is not supported
461      * by the surface's implementation.
462      *
463      * See above for a list of valid operations, such as
464      * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
465      */
466     int     (*perform)(struct ANativeWindow* window,
467                 int operation, ... );
468 
469     /*
470      * Hook used to cancel a buffer that has been dequeued.
471      * No synchronization is performed between dequeue() and cancel(), so
472      * either external synchronization is needed, or these functions must be
473      * called from the same thread.
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      * XXX: This function is deprecated.  It will continue to work for some
482      * time for binary compatibility, but the new cancelBuffer function that
483      * takes a fence file descriptor should be used in its place (pass a value
484      * of -1 for the fence file descriptor if there is no valid one to pass).
485      */
486     int     (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
487                 struct ANativeWindowBuffer* buffer);
488 
489     /*
490      * Hook called by EGL to acquire a buffer. This call may block if no
491      * buffers are available.
492      *
493      * The window holds a reference to the buffer between dequeueBuffer and
494      * either queueBuffer or cancelBuffer, so clients only need their own
495      * reference if they might use the buffer after queueing or canceling it.
496      * Holding a reference to a buffer after queueing or canceling it is only
497      * allowed if a specific buffer count has been set.
498      *
499      * The libsync fence file descriptor returned in the int pointed to by the
500      * fenceFd argument will refer to the fence that must signal before the
501      * dequeued buffer may be written to.  A value of -1 indicates that the
502      * caller may access the buffer immediately without waiting on a fence.  If
503      * a valid file descriptor is returned (i.e. any value except -1) then the
504      * caller is responsible for closing the file descriptor.
505      *
506      * Returns 0 on success or -errno on error.
507      */
508     int     (*dequeueBuffer)(struct ANativeWindow* window,
509                 struct ANativeWindowBuffer** buffer, int* fenceFd);
510 
511     /*
512      * Hook called by EGL when modifications to the render buffer are done.
513      * This unlocks and post the buffer.
514      *
515      * The window holds a reference to the buffer between dequeueBuffer and
516      * either queueBuffer or cancelBuffer, so clients only need their own
517      * reference if they might use the buffer after queueing or canceling it.
518      * Holding a reference to a buffer after queueing or canceling it is only
519      * allowed if a specific buffer count has been set.
520      *
521      * The fenceFd argument specifies a libsync fence file descriptor for a
522      * fence that must signal before the buffer can be accessed.  If the buffer
523      * can be accessed immediately then a value of -1 should be used.  The
524      * caller must not use the file descriptor after it is passed to
525      * queueBuffer, and the ANativeWindow implementation is responsible for
526      * closing it.
527      *
528      * Returns 0 on success or -errno on error.
529      */
530     int     (*queueBuffer)(struct ANativeWindow* window,
531                 struct ANativeWindowBuffer* buffer, int fenceFd);
532 
533     /*
534      * Hook used to cancel a buffer that has been dequeued.
535      * No synchronization is performed between dequeue() and cancel(), so
536      * either external synchronization is needed, or these functions must be
537      * called from the same thread.
538      *
539      * The window holds a reference to the buffer between dequeueBuffer and
540      * either queueBuffer or cancelBuffer, so clients only need their own
541      * reference if they might use the buffer after queueing or canceling it.
542      * Holding a reference to a buffer after queueing or canceling it is only
543      * allowed if a specific buffer count has been set.
544      *
545      * The fenceFd argument specifies a libsync fence file decsriptor for a
546      * fence that must signal before the buffer can be accessed.  If the buffer
547      * can be accessed immediately then a value of -1 should be used.
548      *
549      * Note that if the client has not waited on the fence that was returned
550      * from dequeueBuffer, that same fence should be passed to cancelBuffer to
551      * ensure that future uses of the buffer are preceded by a wait on that
552      * fence.  The caller must not use the file descriptor after it is passed
553      * to cancelBuffer, and the ANativeWindow implementation is responsible for
554      * closing it.
555      *
556      * Returns 0 on success or -errno on error.
557      */
558     int     (*cancelBuffer)(struct ANativeWindow* window,
559                 struct ANativeWindowBuffer* buffer, int fenceFd);
560 };
561 
562  /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
563   * android_native_window_t is deprecated.
564   */
565 typedef struct ANativeWindow android_native_window_t __deprecated;
566 
567 /*
568  *  native_window_set_usage64(..., usage)
569  *  Sets the intended usage flags for the next buffers
570  *  acquired with (*lockBuffer)() and on.
571  *
572  *  Valid usage flags are defined in android/hardware_buffer.h
573  *  All AHARDWAREBUFFER_USAGE_* flags can be specified as needed.
574  *
575  *  Calling this function will usually cause following buffers to be
576  *  reallocated.
577  */
native_window_set_usage(struct ANativeWindow * window,uint64_t usage)578 static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) {
579     return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage);
580 }
581 
582 /* deprecated. Always returns 0. Don't call. */
583 static inline int native_window_connect(
584         struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
585 
native_window_connect(struct ANativeWindow * window __UNUSED,int api __UNUSED)586 static inline int native_window_connect(
587         struct ANativeWindow* window __UNUSED, int api __UNUSED) {
588     return 0;
589 }
590 
591 /* deprecated. Always returns 0. Don't call. */
592 static inline int native_window_disconnect(
593         struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
594 
native_window_disconnect(struct ANativeWindow * window __UNUSED,int api __UNUSED)595 static inline int native_window_disconnect(
596         struct ANativeWindow* window __UNUSED, int api __UNUSED) {
597     return 0;
598 }
599 
600 /*
601  * native_window_set_crop(..., crop)
602  * Sets which region of the next queued buffers needs to be considered.
603  * Depending on the scaling mode, a buffer's crop region is scaled and/or
604  * cropped to match the surface's size.  This function sets the crop in
605  * pre-transformed buffer pixel coordinates.
606  *
607  * The specified crop region applies to all buffers queued after it is called.
608  *
609  * If 'crop' is NULL, subsequently queued buffers won't be cropped.
610  *
611  * An error is returned if for instance the crop region is invalid, out of the
612  * buffer's bound or if the window is invalid.
613  */
native_window_set_crop(struct ANativeWindow * window,android_native_rect_t const * crop)614 static inline int native_window_set_crop(
615         struct ANativeWindow* window,
616         android_native_rect_t const * crop)
617 {
618     return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
619 }
620 
621 /*
622  * native_window_set_buffer_count(..., count)
623  * Sets the number of buffers associated with this native window.
624  */
native_window_set_buffer_count(struct ANativeWindow * window,size_t bufferCount)625 static inline int native_window_set_buffer_count(
626         struct ANativeWindow* window,
627         size_t bufferCount)
628 {
629     return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
630 }
631 
632 /*
633  * native_window_set_buffers_geometry(..., int w, int h, int format)
634  * All buffers dequeued after this call will have the dimensions and format
635  * specified.  A successful call to this function has the same effect as calling
636  * native_window_set_buffers_size and native_window_set_buffers_format.
637  *
638  * XXX: This function is deprecated.  The native_window_set_buffers_dimensions
639  * and native_window_set_buffers_format functions should be used instead.
640  */
641 static inline int native_window_set_buffers_geometry(
642         struct ANativeWindow* window,
643         int w, int h, int format) __deprecated;
644 
native_window_set_buffers_geometry(struct ANativeWindow * window,int w,int h,int format)645 static inline int native_window_set_buffers_geometry(
646         struct ANativeWindow* window,
647         int w, int h, int format)
648 {
649     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
650             w, h, format);
651 }
652 
653 /*
654  * native_window_set_buffers_dimensions(..., int w, int h)
655  * All buffers dequeued after this call will have the dimensions specified.
656  * In particular, all buffers will have a fixed-size, independent from the
657  * native-window size. They will be scaled according to the scaling mode
658  * (see native_window_set_scaling_mode) upon window composition.
659  *
660  * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
661  * following this call will be sized to match the window's size.
662  *
663  * Calling this function will reset the window crop to a NULL value, which
664  * disables cropping of the buffers.
665  */
native_window_set_buffers_dimensions(struct ANativeWindow * window,int w,int h)666 static inline int native_window_set_buffers_dimensions(
667         struct ANativeWindow* window,
668         int w, int h)
669 {
670     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
671             w, h);
672 }
673 
674 /*
675  * native_window_set_buffers_user_dimensions(..., int w, int h)
676  *
677  * Sets the user buffer size for the window, which overrides the
678  * window's size.  All buffers dequeued after this call will have the
679  * dimensions specified unless overridden by
680  * native_window_set_buffers_dimensions.  All buffers will have a
681  * fixed-size, independent from the native-window size. They will be
682  * scaled according to the scaling mode (see
683  * native_window_set_scaling_mode) upon window composition.
684  *
685  * If w and h are 0, the normal behavior is restored. That is, the
686  * default buffer size will match the windows's size.
687  *
688  * Calling this function will reset the window crop to a NULL value, which
689  * disables cropping of the buffers.
690  */
native_window_set_buffers_user_dimensions(struct ANativeWindow * window,int w,int h)691 static inline int native_window_set_buffers_user_dimensions(
692         struct ANativeWindow* window,
693         int w, int h)
694 {
695     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
696             w, h);
697 }
698 
699 /*
700  * native_window_set_buffers_format(..., int format)
701  * All buffers dequeued after this call will have the format specified.
702  *
703  * If the specified format is 0, the default buffer format will be used.
704  */
native_window_set_buffers_format(struct ANativeWindow * window,int format)705 static inline int native_window_set_buffers_format(
706         struct ANativeWindow* window,
707         int format)
708 {
709     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
710 }
711 
712 /*
713  * native_window_set_buffers_data_space(..., int dataSpace)
714  * All buffers queued after this call will be associated with the dataSpace
715  * parameter specified.
716  *
717  * dataSpace specifies additional information about the buffer that's dependent
718  * on the buffer format and the endpoints. For example, it can be used to convey
719  * the color space of the image data in the buffer, or it can be used to
720  * indicate that the buffers contain depth measurement data instead of color
721  * images.  The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
722  * overridden by the consumer.
723  */
native_window_set_buffers_data_space(struct ANativeWindow * window,android_dataspace_t dataSpace)724 static inline int native_window_set_buffers_data_space(
725         struct ANativeWindow* window,
726         android_dataspace_t dataSpace)
727 {
728     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
729             dataSpace);
730 }
731 
732 /*
733  * native_window_set_buffers_smpte2086_metadata(..., metadata)
734  * All buffers queued after this call will be associated with the SMPTE
735  * ST.2086 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 SMPTE ST.2086 metadata is associated with the
740  * buffers by default.
741  */
native_window_set_buffers_smpte2086_metadata(struct ANativeWindow * window,const struct android_smpte2086_metadata * metadata)742 static inline int native_window_set_buffers_smpte2086_metadata(
743         struct ANativeWindow* window,
744         const struct android_smpte2086_metadata* metadata)
745 {
746     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA,
747             metadata);
748 }
749 
750 /*
751  * native_window_set_buffers_cta861_3_metadata(..., metadata)
752  * All buffers queued after this call will be associated with the CTA-861.3
753  * metadata specified.
754  *
755  * metadata specifies additional information about the contents of the buffer
756  * that may affect how it's displayed.  When it is nullptr, it means no such
757  * information is available.  No CTA-861.3 metadata is associated with the
758  * buffers by default.
759  */
native_window_set_buffers_cta861_3_metadata(struct ANativeWindow * window,const struct android_cta861_3_metadata * metadata)760 static inline int native_window_set_buffers_cta861_3_metadata(
761         struct ANativeWindow* window,
762         const struct android_cta861_3_metadata* metadata)
763 {
764     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA,
765             metadata);
766 }
767 
768 /*
769  * native_window_set_buffers_hdr10_plus_metadata(..., metadata)
770  * All buffers queued after this call will be associated with the
771  * HDR10+ dynamic metadata specified.
772  *
773  * metadata specifies additional dynamic information about the
774  * contents of the buffer that may affect how it is displayed.  When
775  * it is nullptr, it means no such information is available.  No
776  * HDR10+ dynamic emtadata is associated with the buffers by default.
777  *
778  * Parameter "size" refers to the length of the metadata blob pointed to
779  * by parameter "data".  The metadata blob will adhere to the HDR10+ SEI
780  * message standard.
781  */
native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow * window,const size_t size,const uint8_t * metadata)782 static inline int native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow* window,
783                                                            const size_t size,
784                                                            const uint8_t* metadata) {
785     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA, size,
786                            metadata);
787 }
788 
789 /*
790  * native_window_set_buffers_transform(..., int transform)
791  * All buffers queued after this call will be displayed transformed according
792  * to the transform parameter specified.
793  */
native_window_set_buffers_transform(struct ANativeWindow * window,int transform)794 static inline int native_window_set_buffers_transform(
795         struct ANativeWindow* window,
796         int transform)
797 {
798     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
799             transform);
800 }
801 
802 /*
803  * native_window_set_buffers_sticky_transform(..., int transform)
804  * All buffers queued after this call will be displayed transformed according
805  * to the transform parameter specified applied on top of the regular buffer
806  * transform.  Setting this transform will disable the transform hint.
807  *
808  * Temporary - This is only intended to be used by the LEGACY camera mode, do
809  *   not use this for anything else.
810  */
native_window_set_buffers_sticky_transform(struct ANativeWindow * window,int transform)811 static inline int native_window_set_buffers_sticky_transform(
812         struct ANativeWindow* window,
813         int transform)
814 {
815     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
816             transform);
817 }
818 
819 /*
820  * native_window_set_buffers_timestamp(..., int64_t timestamp)
821  * All buffers queued after this call will be associated with the timestamp
822  * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
823  * (the default), timestamps will be generated automatically when queueBuffer is
824  * called. The timestamp is measured in nanoseconds, and is normally monotonically
825  * increasing. The timestamp should be unaffected by time-of-day adjustments,
826  * and for a camera should be strictly monotonic but for a media player may be
827  * reset when the position is set.
828  */
native_window_set_buffers_timestamp(struct ANativeWindow * window,int64_t timestamp)829 static inline int native_window_set_buffers_timestamp(
830         struct ANativeWindow* window,
831         int64_t timestamp)
832 {
833     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
834             timestamp);
835 }
836 
837 /*
838  * native_window_set_scaling_mode(..., int mode)
839  * All buffers queued after this call will be associated with the scaling mode
840  * specified.
841  */
native_window_set_scaling_mode(struct ANativeWindow * window,int mode)842 static inline int native_window_set_scaling_mode(
843         struct ANativeWindow* window,
844         int mode)
845 {
846     return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
847             mode);
848 }
849 
850 /*
851  * native_window_api_connect(..., int api)
852  * connects an API to this window. only one API can be connected at a time.
853  * Returns -EINVAL if for some reason the window cannot be connected, which
854  * can happen if it's connected to some other API.
855  */
native_window_api_connect(struct ANativeWindow * window,int api)856 static inline int native_window_api_connect(
857         struct ANativeWindow* window, int api)
858 {
859     return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
860 }
861 
862 /*
863  * native_window_api_disconnect(..., int api)
864  * disconnect the API from this window.
865  * An error is returned if for instance the window wasn't connected in the
866  * first place.
867  */
native_window_api_disconnect(struct ANativeWindow * window,int api)868 static inline int native_window_api_disconnect(
869         struct ANativeWindow* window, int api)
870 {
871     return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
872 }
873 
874 /*
875  * native_window_dequeue_buffer_and_wait(...)
876  * Dequeue a buffer and wait on the fence associated with that buffer.  The
877  * buffer may safely be accessed immediately upon this function returning.  An
878  * error is returned if either of the dequeue or the wait operations fail.
879  */
native_window_dequeue_buffer_and_wait(ANativeWindow * anw,struct ANativeWindowBuffer ** anb)880 static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
881         struct ANativeWindowBuffer** anb) {
882     return anw->dequeueBuffer_DEPRECATED(anw, anb);
883 }
884 
885 /*
886  * native_window_set_sideband_stream(..., native_handle_t*)
887  * Attach a sideband buffer stream to a native window.
888  */
native_window_set_sideband_stream(struct ANativeWindow * window,native_handle_t * sidebandHandle)889 static inline int native_window_set_sideband_stream(
890         struct ANativeWindow* window,
891         native_handle_t* sidebandHandle)
892 {
893     return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
894             sidebandHandle);
895 }
896 
897 /*
898  * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
899  * Set the surface damage (i.e., the region of the surface that has changed
900  * since the previous frame). The damage set by this call will be reset (to the
901  * default of full-surface damage) after calling queue, so this must be called
902  * prior to every frame with damage that does not cover the whole surface if the
903  * caller desires downstream consumers to use this optimization.
904  *
905  * The damage region is specified as an array of rectangles, with the important
906  * caveat that the origin of the surface is considered to be the bottom-left
907  * corner, as in OpenGL ES.
908  *
909  * If numRects is set to 0, rects may be NULL, and the surface damage will be
910  * set to the full surface (the same as if this function had not been called for
911  * this frame).
912  */
native_window_set_surface_damage(struct ANativeWindow * window,const android_native_rect_t * rects,size_t numRects)913 static inline int native_window_set_surface_damage(
914         struct ANativeWindow* window,
915         const android_native_rect_t* rects, size_t numRects)
916 {
917     return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
918             rects, numRects);
919 }
920 
921 /*
922  * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
923  * Enable/disable shared buffer mode
924  */
native_window_set_shared_buffer_mode(struct ANativeWindow * window,bool sharedBufferMode)925 static inline int native_window_set_shared_buffer_mode(
926         struct ANativeWindow* window,
927         bool sharedBufferMode)
928 {
929     return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
930             sharedBufferMode);
931 }
932 
933 /*
934  * native_window_set_auto_refresh(..., autoRefresh)
935  * Enable/disable auto refresh when in shared buffer mode
936  */
native_window_set_auto_refresh(struct ANativeWindow * window,bool autoRefresh)937 static inline int native_window_set_auto_refresh(
938         struct ANativeWindow* window,
939         bool autoRefresh)
940 {
941     return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
942 }
943 
native_window_get_refresh_cycle_duration(struct ANativeWindow * window,int64_t * outRefreshDuration)944 static inline int native_window_get_refresh_cycle_duration(
945         struct ANativeWindow* window,
946         int64_t* outRefreshDuration)
947 {
948     return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION,
949             outRefreshDuration);
950 }
951 
native_window_get_next_frame_id(struct ANativeWindow * window,uint64_t * frameId)952 static inline int native_window_get_next_frame_id(
953         struct ANativeWindow* window, uint64_t* frameId)
954 {
955     return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId);
956 }
957 
native_window_enable_frame_timestamps(struct ANativeWindow * window,bool enable)958 static inline int native_window_enable_frame_timestamps(
959         struct ANativeWindow* window, bool enable)
960 {
961     return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS,
962             enable);
963 }
964 
native_window_get_compositor_timing(struct ANativeWindow * window,int64_t * compositeDeadline,int64_t * compositeInterval,int64_t * compositeToPresentLatency)965 static inline int native_window_get_compositor_timing(
966         struct ANativeWindow* window,
967         int64_t* compositeDeadline, int64_t* compositeInterval,
968         int64_t* compositeToPresentLatency)
969 {
970     return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING,
971             compositeDeadline, compositeInterval, compositeToPresentLatency);
972 }
973 
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)974 static inline int native_window_get_frame_timestamps(
975         struct ANativeWindow* window, uint64_t frameId,
976         int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
977         int64_t* outLatchTime, int64_t* outFirstRefreshStartTime,
978         int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime,
979         int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime,
980         int64_t* outReleaseTime)
981 {
982     return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
983             frameId, outRequestedPresentTime, outAcquireTime, outLatchTime,
984             outFirstRefreshStartTime, outLastRefreshStartTime,
985             outGpuCompositionDoneTime, outDisplayPresentTime,
986             outDequeueReadyTime, outReleaseTime);
987 }
988 
native_window_get_wide_color_support(struct ANativeWindow * window,bool * outSupport)989 static inline int native_window_get_wide_color_support(
990     struct ANativeWindow* window, bool* outSupport) {
991     return window->perform(window, NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT,
992             outSupport);
993 }
994 
native_window_get_hdr_support(struct ANativeWindow * window,bool * outSupport)995 static inline int native_window_get_hdr_support(struct ANativeWindow* window,
996                                                 bool* outSupport) {
997     return window->perform(window, NATIVE_WINDOW_GET_HDR_SUPPORT, outSupport);
998 }
999 
native_window_get_consumer_usage(struct ANativeWindow * window,uint64_t * outUsage)1000 static inline int native_window_get_consumer_usage(struct ANativeWindow* window,
1001                                                    uint64_t* outUsage) {
1002     return window->perform(window, NATIVE_WINDOW_GET_CONSUMER_USAGE64, outUsage);
1003 }
1004 
1005 /*
1006  * native_window_set_auto_prerotation(..., autoPrerotation)
1007  * Enable/disable the auto prerotation at buffer allocation when the buffer size
1008  * is driven by the consumer.
1009  *
1010  * When buffer size is driven by the consumer and the transform hint specifies
1011  * a 90 or 270 degree rotation, if auto prerotation is enabled, the width and
1012  * height used for dequeueBuffer will be additionally swapped.
1013  */
native_window_set_auto_prerotation(struct ANativeWindow * window,bool autoPrerotation)1014 static inline int native_window_set_auto_prerotation(struct ANativeWindow* window,
1015                                                      bool autoPrerotation) {
1016     return window->perform(window, NATIVE_WINDOW_SET_AUTO_PREROTATION, autoPrerotation);
1017 }
1018 
native_window_set_frame_rate(struct ANativeWindow * window,float frameRate,int8_t compatibility)1019 static inline int native_window_set_frame_rate(struct ANativeWindow* window, float frameRate,
1020                                                int8_t compatibility) {
1021     return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate,
1022                            (int)compatibility);
1023 }
1024 
1025 // ------------------------------------------------------------------------------------------------
1026 // Candidates for APEX visibility
1027 // These functions are planned to be made stable for APEX modules, but have not
1028 // yet been stabilized to a specific api version.
1029 // ------------------------------------------------------------------------------------------------
1030 
1031 /**
1032  * Retrieves the last queued buffer for this window, along with the fence that
1033  * fires when the buffer is ready to be read, and the 4x4 coordinate
1034  * transform matrix that should be applied to the buffer's content. The
1035  * transform matrix is represented in column-major order.
1036  *
1037  * If there was no buffer previously queued, then outBuffer will be NULL and
1038  * the value of outFence will be -1.
1039  *
1040  * Note that if outBuffer is not NULL, then the caller will hold a reference
1041  * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release
1042  * when the buffer is no longer needed so that the system may reclaim the
1043  * buffer.
1044  *
1045  * \return NO_ERROR on success.
1046  * \return NO_MEMORY if there was insufficient memory.
1047  */
ANativeWindow_getLastQueuedBuffer(ANativeWindow * window,AHardwareBuffer ** outBuffer,int * outFence,float outTransformMatrix[16])1048 static inline int ANativeWindow_getLastQueuedBuffer(ANativeWindow* window,
1049                                                     AHardwareBuffer** outBuffer, int* outFence,
1050                                                     float outTransformMatrix[16]) {
1051     return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER, outBuffer, outFence,
1052                            outTransformMatrix);
1053 }
1054 
1055 /**
1056  * Retrieves an identifier for the next frame to be queued by this window.
1057  *
1058  * \return the next frame id.
1059  */
ANativeWindow_getNextFrameId(ANativeWindow * window)1060 static inline int64_t ANativeWindow_getNextFrameId(ANativeWindow* window) {
1061     int64_t value;
1062     window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, &value);
1063     return value;
1064 }
1065 
1066 /**
1067  * Prototype of the function that an ANativeWindow implementation would call
1068  * when ANativeWindow_query is called.
1069  */
1070 typedef int (*ANativeWindow_queryFn)(const ANativeWindow* window, int what, int* value);
1071 
1072 /**
1073  * Prototype of the function that intercepts an invocation of
1074  * ANativeWindow_queryFn, along with a data pointer that's passed by the
1075  * caller who set the interceptor, as well as arguments that would be
1076  * passed to ANativeWindow_queryFn if it were to be called.
1077  */
1078 typedef int (*ANativeWindow_queryInterceptor)(const ANativeWindow* window,
1079                                                 ANativeWindow_queryFn perform, void* data,
1080                                                 int what, int* value);
1081 
1082 /**
1083  * Registers an interceptor for ANativeWindow_query. Instead of calling
1084  * the underlying query function, instead the provided interceptor is
1085  * called, which may optionally call the underlying query function. An
1086  * optional data pointer is also provided to side-channel additional arguments.
1087  *
1088  * Note that usage of this should only be used for specialized use-cases by
1089  * either the system partition or to Mainline modules. This should never be
1090  * exposed to NDK or LL-NDK.
1091  *
1092  * Returns NO_ERROR on success, -errno if registration failed.
1093  */
ANativeWindow_setQueryInterceptor(ANativeWindow * window,ANativeWindow_queryInterceptor interceptor,void * data)1094 static inline int ANativeWindow_setQueryInterceptor(ANativeWindow* window,
1095                                             ANativeWindow_queryInterceptor interceptor,
1096                                             void* data) {
1097     return window->perform(window, NATIVE_WINDOW_SET_QUERY_INTERCEPTOR, interceptor, data);
1098 }
1099 
1100 __END_DECLS
1101