• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO         = 48,    /* private */
259     NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2         = 49,    /* private */
260     // clang-format on
261 };
262 
263 /* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
264 enum {
265     /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
266      * OpenGL ES.
267      */
268     NATIVE_WINDOW_API_EGL = 1,
269 
270     /* Buffers will be queued after being filled using the CPU
271      */
272     NATIVE_WINDOW_API_CPU = 2,
273 
274     /* Buffers will be queued by Stagefright after being filled by a video
275      * decoder.  The video decoder can either be a software or hardware decoder.
276      */
277     NATIVE_WINDOW_API_MEDIA = 3,
278 
279     /* Buffers will be queued by the the camera HAL.
280      */
281     NATIVE_WINDOW_API_CAMERA = 4,
282 };
283 
284 /* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
285 enum {
286     /* flip source image horizontally */
287     NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
288     /* flip source image vertically */
289     NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
290     /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
291     NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
292     /* rotate source image 180 degrees */
293     NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
294     /* rotate source image 270 degrees clock-wise */
295     NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
296     /* transforms source by the inverse transform of the screen it is displayed onto. This
297      * transform is applied last */
298     NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
299 };
300 
301 /* parameter for NATIVE_WINDOW_SET_SCALING_MODE
302  * keep in sync with Surface.java in frameworks/base */
303 enum {
304     /* the window content is not updated (frozen) until a buffer of
305      * the window size is received (enqueued)
306      */
307     NATIVE_WINDOW_SCALING_MODE_FREEZE           = 0,
308     /* the buffer is scaled in both dimensions to match the window size */
309     NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW  = 1,
310     /* the buffer is scaled uniformly such that the smaller dimension
311      * of the buffer matches the window size (cropping in the process)
312      */
313     NATIVE_WINDOW_SCALING_MODE_SCALE_CROP       = 2,
314     /* the window is clipped to the size of the buffer's crop rectangle; pixels
315      * outside the crop rectangle are treated as if they are completely
316      * transparent.
317      */
318     NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP    = 3,
319 };
320 
321 /* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
322 enum {
323     NATIVE_WINDOW_FRAMEBUFFER               = 0, /* FramebufferNativeWindow */
324     NATIVE_WINDOW_SURFACE                   = 1, /* Surface */
325 };
326 
327 /* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
328  *
329  * Special timestamp value to indicate that timestamps should be auto-generated
330  * by the native window when queueBuffer is called.  This is equal to INT64_MIN,
331  * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
332  */
333 static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
334 
335 /* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS
336  *
337  * Special timestamp value to indicate the timestamps aren't yet known or
338  * that they are invalid.
339  */
340 static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2;
341 static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1;
342 
343 struct ANativeWindow
344 {
345 #ifdef __cplusplus
ANativeWindowANativeWindow346     ANativeWindow()
347         : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
348     {
349         common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
350         common.version = sizeof(ANativeWindow);
351         memset(common.reserved, 0, sizeof(common.reserved));
352     }
353 
354     /* Implement the methods that sp<ANativeWindow> expects so that it
355        can be used to automatically refcount ANativeWindow's. */
incStrongANativeWindow356     void incStrong(const void* /*id*/) const {
357         common.incRef(const_cast<android_native_base_t*>(&common));
358     }
decStrongANativeWindow359     void decStrong(const void* /*id*/) const {
360         common.decRef(const_cast<android_native_base_t*>(&common));
361     }
362 #endif
363 
364     struct android_native_base_t common;
365 
366     /* flags describing some attributes of this surface or its updater */
367     const uint32_t flags;
368 
369     /* min swap interval supported by this updated */
370     const int   minSwapInterval;
371 
372     /* max swap interval supported by this updated */
373     const int   maxSwapInterval;
374 
375     /* horizontal and vertical resolution in DPI */
376     const float xdpi;
377     const float ydpi;
378 
379     /* Some storage reserved for the OEM's driver. */
380     intptr_t    oem[4];
381 
382     /*
383      * Set the swap interval for this surface.
384      *
385      * Returns 0 on success or -errno on error.
386      */
387     int     (*setSwapInterval)(struct ANativeWindow* window,
388                 int interval);
389 
390     /*
391      * Hook called by EGL to acquire a buffer. After this call, the buffer
392      * is not locked, so its content cannot be modified. This call may block if
393      * no buffers are available.
394      *
395      * The window holds a reference to the buffer between dequeueBuffer and
396      * either queueBuffer or cancelBuffer, so clients only need their own
397      * reference if they might use the buffer after queueing or canceling it.
398      * Holding a reference to a buffer after queueing or canceling it is only
399      * allowed if a specific buffer count has been set.
400      *
401      * Returns 0 on success or -errno on error.
402      *
403      * XXX: This function is deprecated.  It will continue to work for some
404      * time for binary compatibility, but the new dequeueBuffer function that
405      * outputs a fence file descriptor should be used in its place.
406      */
407     int     (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
408                 struct ANativeWindowBuffer** buffer);
409 
410     /*
411      * hook called by EGL to lock a buffer. This MUST be called before modifying
412      * the content of a buffer. The buffer must have been acquired with
413      * dequeueBuffer first.
414      *
415      * Returns 0 on success or -errno on error.
416      *
417      * XXX: This function is deprecated.  It will continue to work for some
418      * time for binary compatibility, but it is essentially a no-op, and calls
419      * to it should be removed.
420      */
421     int     (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
422                 struct ANativeWindowBuffer* buffer);
423 
424     /*
425      * Hook called by EGL when modifications to the render buffer are done.
426      * This unlocks and post the buffer.
427      *
428      * The window holds a reference to the buffer between dequeueBuffer and
429      * either queueBuffer or cancelBuffer, so clients only need their own
430      * reference if they might use the buffer after queueing or canceling it.
431      * Holding a reference to a buffer after queueing or canceling it is only
432      * allowed if a specific buffer count has been set.
433      *
434      * Buffers MUST be queued in the same order than they were dequeued.
435      *
436      * Returns 0 on success or -errno on error.
437      *
438      * XXX: This function is deprecated.  It will continue to work for some
439      * time for binary compatibility, but the new queueBuffer function that
440      * takes a fence file descriptor should be used in its place (pass a value
441      * of -1 for the fence file descriptor if there is no valid one to pass).
442      */
443     int     (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
444                 struct ANativeWindowBuffer* buffer);
445 
446     /*
447      * hook used to retrieve information about the native window.
448      *
449      * Returns 0 on success or -errno on error.
450      */
451     int     (*query)(const struct ANativeWindow* window,
452                 int what, int* value);
453 
454     /*
455      * hook used to perform various operations on the surface.
456      * (*perform)() is a generic mechanism to add functionality to
457      * ANativeWindow while keeping backward binary compatibility.
458      *
459      * DO NOT CALL THIS HOOK DIRECTLY.  Instead, use the helper functions
460      * defined below.
461      *
462      * (*perform)() returns -ENOENT if the 'what' parameter is not supported
463      * by the surface's implementation.
464      *
465      * See above for a list of valid operations, such as
466      * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
467      */
468     int     (*perform)(struct ANativeWindow* window,
469                 int operation, ... );
470 
471     /*
472      * Hook used to cancel a buffer that has been dequeued.
473      * No synchronization is performed between dequeue() and cancel(), so
474      * either external synchronization is needed, or these functions must be
475      * called from the same thread.
476      *
477      * The window holds a reference to the buffer between dequeueBuffer and
478      * either queueBuffer or cancelBuffer, so clients only need their own
479      * reference if they might use the buffer after queueing or canceling it.
480      * Holding a reference to a buffer after queueing or canceling it is only
481      * allowed if a specific buffer count has been set.
482      *
483      * XXX: This function is deprecated.  It will continue to work for some
484      * time for binary compatibility, but the new cancelBuffer function that
485      * takes a fence file descriptor should be used in its place (pass a value
486      * of -1 for the fence file descriptor if there is no valid one to pass).
487      */
488     int     (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
489                 struct ANativeWindowBuffer* buffer);
490 
491     /*
492      * Hook called by EGL to acquire a buffer. This call may block if no
493      * buffers are available.
494      *
495      * The window holds a reference to the buffer between dequeueBuffer and
496      * either queueBuffer or cancelBuffer, so clients only need their own
497      * reference if they might use the buffer after queueing or canceling it.
498      * Holding a reference to a buffer after queueing or canceling it is only
499      * allowed if a specific buffer count has been set.
500      *
501      * The libsync fence file descriptor returned in the int pointed to by the
502      * fenceFd argument will refer to the fence that must signal before the
503      * dequeued buffer may be written to.  A value of -1 indicates that the
504      * caller may access the buffer immediately without waiting on a fence.  If
505      * a valid file descriptor is returned (i.e. any value except -1) then the
506      * caller is responsible for closing the file descriptor.
507      *
508      * Returns 0 on success or -errno on error.
509      */
510     int     (*dequeueBuffer)(struct ANativeWindow* window,
511                 struct ANativeWindowBuffer** buffer, int* fenceFd);
512 
513     /*
514      * Hook called by EGL when modifications to the render buffer are done.
515      * This unlocks and post the buffer.
516      *
517      * The window holds a reference to the buffer between dequeueBuffer and
518      * either queueBuffer or cancelBuffer, so clients only need their own
519      * reference if they might use the buffer after queueing or canceling it.
520      * Holding a reference to a buffer after queueing or canceling it is only
521      * allowed if a specific buffer count has been set.
522      *
523      * The fenceFd argument specifies a libsync fence file descriptor for a
524      * fence that must signal before the buffer can be accessed.  If the buffer
525      * can be accessed immediately then a value of -1 should be used.  The
526      * caller must not use the file descriptor after it is passed to
527      * queueBuffer, and the ANativeWindow implementation is responsible for
528      * closing it.
529      *
530      * Returns 0 on success or -errno on error.
531      */
532     int     (*queueBuffer)(struct ANativeWindow* window,
533                 struct ANativeWindowBuffer* buffer, int fenceFd);
534 
535     /*
536      * Hook used to cancel a buffer that has been dequeued.
537      * No synchronization is performed between dequeue() and cancel(), so
538      * either external synchronization is needed, or these functions must be
539      * called from the same thread.
540      *
541      * The window holds a reference to the buffer between dequeueBuffer and
542      * either queueBuffer or cancelBuffer, so clients only need their own
543      * reference if they might use the buffer after queueing or canceling it.
544      * Holding a reference to a buffer after queueing or canceling it is only
545      * allowed if a specific buffer count has been set.
546      *
547      * The fenceFd argument specifies a libsync fence file decsriptor for a
548      * fence that must signal before the buffer can be accessed.  If the buffer
549      * can be accessed immediately then a value of -1 should be used.
550      *
551      * Note that if the client has not waited on the fence that was returned
552      * from dequeueBuffer, that same fence should be passed to cancelBuffer to
553      * ensure that future uses of the buffer are preceded by a wait on that
554      * fence.  The caller must not use the file descriptor after it is passed
555      * to cancelBuffer, and the ANativeWindow implementation is responsible for
556      * closing it.
557      *
558      * Returns 0 on success or -errno on error.
559      */
560     int     (*cancelBuffer)(struct ANativeWindow* window,
561                 struct ANativeWindowBuffer* buffer, int fenceFd);
562 };
563 
564  /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
565   * android_native_window_t is deprecated.
566   */
567 typedef struct ANativeWindow android_native_window_t __deprecated;
568 
569 /*
570  *  native_window_set_usage64(..., usage)
571  *  Sets the intended usage flags for the next buffers
572  *  acquired with (*lockBuffer)() and on.
573  *
574  *  Valid usage flags are defined in android/hardware_buffer.h
575  *  All AHARDWAREBUFFER_USAGE_* flags can be specified as needed.
576  *
577  *  Calling this function will usually cause following buffers to be
578  *  reallocated.
579  */
native_window_set_usage(struct ANativeWindow * window,uint64_t usage)580 static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) {
581     return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage);
582 }
583 
584 /* deprecated. Always returns 0. Don't call. */
585 static inline int native_window_connect(
586         struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
587 
native_window_connect(struct ANativeWindow * window __UNUSED,int api __UNUSED)588 static inline int native_window_connect(
589         struct ANativeWindow* window __UNUSED, int api __UNUSED) {
590     return 0;
591 }
592 
593 /* deprecated. Always returns 0. Don't call. */
594 static inline int native_window_disconnect(
595         struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
596 
native_window_disconnect(struct ANativeWindow * window __UNUSED,int api __UNUSED)597 static inline int native_window_disconnect(
598         struct ANativeWindow* window __UNUSED, int api __UNUSED) {
599     return 0;
600 }
601 
602 /*
603  * native_window_set_crop(..., crop)
604  * Sets which region of the next queued buffers needs to be considered.
605  * Depending on the scaling mode, a buffer's crop region is scaled and/or
606  * cropped to match the surface's size.  This function sets the crop in
607  * pre-transformed buffer pixel coordinates.
608  *
609  * The specified crop region applies to all buffers queued after it is called.
610  *
611  * If 'crop' is NULL, subsequently queued buffers won't be cropped.
612  *
613  * An error is returned if for instance the crop region is invalid, out of the
614  * buffer's bound or if the window is invalid.
615  */
native_window_set_crop(struct ANativeWindow * window,android_native_rect_t const * crop)616 static inline int native_window_set_crop(
617         struct ANativeWindow* window,
618         android_native_rect_t const * crop)
619 {
620     return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
621 }
622 
623 /*
624  * native_window_set_buffer_count(..., count)
625  * Sets the number of buffers associated with this native window.
626  */
native_window_set_buffer_count(struct ANativeWindow * window,size_t bufferCount)627 static inline int native_window_set_buffer_count(
628         struct ANativeWindow* window,
629         size_t bufferCount)
630 {
631     return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
632 }
633 
634 /*
635  * native_window_set_buffers_geometry(..., int w, int h, int format)
636  * All buffers dequeued after this call will have the dimensions and format
637  * specified.  A successful call to this function has the same effect as calling
638  * native_window_set_buffers_size and native_window_set_buffers_format.
639  *
640  * XXX: This function is deprecated.  The native_window_set_buffers_dimensions
641  * and native_window_set_buffers_format functions should be used instead.
642  */
643 static inline int native_window_set_buffers_geometry(
644         struct ANativeWindow* window,
645         int w, int h, int format) __deprecated;
646 
native_window_set_buffers_geometry(struct ANativeWindow * window,int w,int h,int format)647 static inline int native_window_set_buffers_geometry(
648         struct ANativeWindow* window,
649         int w, int h, int format)
650 {
651     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
652             w, h, format);
653 }
654 
655 /*
656  * native_window_set_buffers_dimensions(..., int w, int h)
657  * All buffers dequeued after this call will have the dimensions specified.
658  * In particular, all buffers will have a fixed-size, independent from the
659  * native-window size. They will be scaled according to the scaling mode
660  * (see native_window_set_scaling_mode) upon window composition.
661  *
662  * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
663  * following this call will be sized to match the window's size.
664  *
665  * Calling this function will reset the window crop to a NULL value, which
666  * disables cropping of the buffers.
667  */
native_window_set_buffers_dimensions(struct ANativeWindow * window,int w,int h)668 static inline int native_window_set_buffers_dimensions(
669         struct ANativeWindow* window,
670         int w, int h)
671 {
672     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
673             w, h);
674 }
675 
676 /*
677  * native_window_set_buffers_user_dimensions(..., int w, int h)
678  *
679  * Sets the user buffer size for the window, which overrides the
680  * window's size.  All buffers dequeued after this call will have the
681  * dimensions specified unless overridden by
682  * native_window_set_buffers_dimensions.  All buffers will have a
683  * fixed-size, independent from the native-window size. They will be
684  * scaled according to the scaling mode (see
685  * native_window_set_scaling_mode) upon window composition.
686  *
687  * If w and h are 0, the normal behavior is restored. That is, the
688  * default buffer size will match the windows's size.
689  *
690  * Calling this function will reset the window crop to a NULL value, which
691  * disables cropping of the buffers.
692  */
native_window_set_buffers_user_dimensions(struct ANativeWindow * window,int w,int h)693 static inline int native_window_set_buffers_user_dimensions(
694         struct ANativeWindow* window,
695         int w, int h)
696 {
697     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
698             w, h);
699 }
700 
701 /*
702  * native_window_set_buffers_format(..., int format)
703  * All buffers dequeued after this call will have the format specified.
704  *
705  * If the specified format is 0, the default buffer format will be used.
706  */
native_window_set_buffers_format(struct ANativeWindow * window,int format)707 static inline int native_window_set_buffers_format(
708         struct ANativeWindow* window,
709         int format)
710 {
711     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
712 }
713 
714 /*
715  * native_window_set_buffers_data_space(..., int dataSpace)
716  * All buffers queued after this call will be associated with the dataSpace
717  * parameter specified.
718  *
719  * dataSpace specifies additional information about the buffer that's dependent
720  * on the buffer format and the endpoints. For example, it can be used to convey
721  * the color space of the image data in the buffer, or it can be used to
722  * indicate that the buffers contain depth measurement data instead of color
723  * images.  The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
724  * overridden by the consumer.
725  */
native_window_set_buffers_data_space(struct ANativeWindow * window,android_dataspace_t dataSpace)726 static inline int native_window_set_buffers_data_space(
727         struct ANativeWindow* window,
728         android_dataspace_t dataSpace)
729 {
730     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
731             dataSpace);
732 }
733 
734 /*
735  * native_window_set_buffers_smpte2086_metadata(..., metadata)
736  * All buffers queued after this call will be associated with the SMPTE
737  * ST.2086 metadata specified.
738  *
739  * metadata specifies additional information about the contents of the buffer
740  * that may affect how it's displayed.  When it is nullptr, it means no such
741  * information is available.  No SMPTE ST.2086 metadata is associated with the
742  * buffers by default.
743  */
native_window_set_buffers_smpte2086_metadata(struct ANativeWindow * window,const struct android_smpte2086_metadata * metadata)744 static inline int native_window_set_buffers_smpte2086_metadata(
745         struct ANativeWindow* window,
746         const struct android_smpte2086_metadata* metadata)
747 {
748     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA,
749             metadata);
750 }
751 
752 /*
753  * native_window_set_buffers_cta861_3_metadata(..., metadata)
754  * All buffers queued after this call will be associated with the CTA-861.3
755  * metadata specified.
756  *
757  * metadata specifies additional information about the contents of the buffer
758  * that may affect how it's displayed.  When it is nullptr, it means no such
759  * information is available.  No CTA-861.3 metadata is associated with the
760  * buffers by default.
761  */
native_window_set_buffers_cta861_3_metadata(struct ANativeWindow * window,const struct android_cta861_3_metadata * metadata)762 static inline int native_window_set_buffers_cta861_3_metadata(
763         struct ANativeWindow* window,
764         const struct android_cta861_3_metadata* metadata)
765 {
766     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA,
767             metadata);
768 }
769 
770 /*
771  * native_window_set_buffers_hdr10_plus_metadata(..., metadata)
772  * All buffers queued after this call will be associated with the
773  * HDR10+ dynamic metadata specified.
774  *
775  * metadata specifies additional dynamic information about the
776  * contents of the buffer that may affect how it is displayed.  When
777  * it is nullptr, it means no such information is available.  No
778  * HDR10+ dynamic emtadata is associated with the buffers by default.
779  *
780  * Parameter "size" refers to the length of the metadata blob pointed to
781  * by parameter "data".  The metadata blob will adhere to the HDR10+ SEI
782  * message standard.
783  */
native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow * window,const size_t size,const uint8_t * metadata)784 static inline int native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow* window,
785                                                            const size_t size,
786                                                            const uint8_t* metadata) {
787     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA, size,
788                            metadata);
789 }
790 
791 /*
792  * native_window_set_buffers_transform(..., int transform)
793  * All buffers queued after this call will be displayed transformed according
794  * to the transform parameter specified.
795  */
native_window_set_buffers_transform(struct ANativeWindow * window,int transform)796 static inline int native_window_set_buffers_transform(
797         struct ANativeWindow* window,
798         int transform)
799 {
800     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
801             transform);
802 }
803 
804 /*
805  * native_window_set_buffers_sticky_transform(..., int transform)
806  * All buffers queued after this call will be displayed transformed according
807  * to the transform parameter specified applied on top of the regular buffer
808  * transform.  Setting this transform will disable the transform hint.
809  *
810  * Temporary - This is only intended to be used by the LEGACY camera mode, do
811  *   not use this for anything else.
812  */
native_window_set_buffers_sticky_transform(struct ANativeWindow * window,int transform)813 static inline int native_window_set_buffers_sticky_transform(
814         struct ANativeWindow* window,
815         int transform)
816 {
817     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
818             transform);
819 }
820 
821 /*
822  * native_window_set_buffers_timestamp(..., int64_t timestamp)
823  * All buffers queued after this call will be associated with the timestamp
824  * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
825  * (the default), timestamps will be generated automatically when queueBuffer is
826  * called. The timestamp is measured in nanoseconds, and is normally monotonically
827  * increasing. The timestamp should be unaffected by time-of-day adjustments,
828  * and for a camera should be strictly monotonic but for a media player may be
829  * reset when the position is set.
830  */
native_window_set_buffers_timestamp(struct ANativeWindow * window,int64_t timestamp)831 static inline int native_window_set_buffers_timestamp(
832         struct ANativeWindow* window,
833         int64_t timestamp)
834 {
835     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
836             timestamp);
837 }
838 
839 /*
840  * native_window_set_scaling_mode(..., int mode)
841  * All buffers queued after this call will be associated with the scaling mode
842  * specified.
843  */
native_window_set_scaling_mode(struct ANativeWindow * window,int mode)844 static inline int native_window_set_scaling_mode(
845         struct ANativeWindow* window,
846         int mode)
847 {
848     return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
849             mode);
850 }
851 
852 /*
853  * native_window_api_connect(..., int api)
854  * connects an API to this window. only one API can be connected at a time.
855  * Returns -EINVAL if for some reason the window cannot be connected, which
856  * can happen if it's connected to some other API.
857  */
native_window_api_connect(struct ANativeWindow * window,int api)858 static inline int native_window_api_connect(
859         struct ANativeWindow* window, int api)
860 {
861     return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
862 }
863 
864 /*
865  * native_window_api_disconnect(..., int api)
866  * disconnect the API from this window.
867  * An error is returned if for instance the window wasn't connected in the
868  * first place.
869  */
native_window_api_disconnect(struct ANativeWindow * window,int api)870 static inline int native_window_api_disconnect(
871         struct ANativeWindow* window, int api)
872 {
873     return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
874 }
875 
876 /*
877  * native_window_dequeue_buffer_and_wait(...)
878  * Dequeue a buffer and wait on the fence associated with that buffer.  The
879  * buffer may safely be accessed immediately upon this function returning.  An
880  * error is returned if either of the dequeue or the wait operations fail.
881  */
native_window_dequeue_buffer_and_wait(ANativeWindow * anw,struct ANativeWindowBuffer ** anb)882 static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
883         struct ANativeWindowBuffer** anb) {
884     return anw->dequeueBuffer_DEPRECATED(anw, anb);
885 }
886 
887 /*
888  * native_window_set_sideband_stream(..., native_handle_t*)
889  * Attach a sideband buffer stream to a native window.
890  */
native_window_set_sideband_stream(struct ANativeWindow * window,native_handle_t * sidebandHandle)891 static inline int native_window_set_sideband_stream(
892         struct ANativeWindow* window,
893         native_handle_t* sidebandHandle)
894 {
895     return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
896             sidebandHandle);
897 }
898 
899 /*
900  * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
901  * Set the surface damage (i.e., the region of the surface that has changed
902  * since the previous frame). The damage set by this call will be reset (to the
903  * default of full-surface damage) after calling queue, so this must be called
904  * prior to every frame with damage that does not cover the whole surface if the
905  * caller desires downstream consumers to use this optimization.
906  *
907  * The damage region is specified as an array of rectangles, with the important
908  * caveat that the origin of the surface is considered to be the bottom-left
909  * corner, as in OpenGL ES.
910  *
911  * If numRects is set to 0, rects may be NULL, and the surface damage will be
912  * set to the full surface (the same as if this function had not been called for
913  * this frame).
914  */
native_window_set_surface_damage(struct ANativeWindow * window,const android_native_rect_t * rects,size_t numRects)915 static inline int native_window_set_surface_damage(
916         struct ANativeWindow* window,
917         const android_native_rect_t* rects, size_t numRects)
918 {
919     return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
920             rects, numRects);
921 }
922 
923 /*
924  * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
925  * Enable/disable shared buffer mode
926  */
native_window_set_shared_buffer_mode(struct ANativeWindow * window,bool sharedBufferMode)927 static inline int native_window_set_shared_buffer_mode(
928         struct ANativeWindow* window,
929         bool sharedBufferMode)
930 {
931     return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
932             sharedBufferMode);
933 }
934 
935 /*
936  * native_window_set_auto_refresh(..., autoRefresh)
937  * Enable/disable auto refresh when in shared buffer mode
938  */
native_window_set_auto_refresh(struct ANativeWindow * window,bool autoRefresh)939 static inline int native_window_set_auto_refresh(
940         struct ANativeWindow* window,
941         bool autoRefresh)
942 {
943     return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
944 }
945 
native_window_get_refresh_cycle_duration(struct ANativeWindow * window,int64_t * outRefreshDuration)946 static inline int native_window_get_refresh_cycle_duration(
947         struct ANativeWindow* window,
948         int64_t* outRefreshDuration)
949 {
950     return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION,
951             outRefreshDuration);
952 }
953 
native_window_get_next_frame_id(struct ANativeWindow * window,uint64_t * frameId)954 static inline int native_window_get_next_frame_id(
955         struct ANativeWindow* window, uint64_t* frameId)
956 {
957     return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId);
958 }
959 
native_window_enable_frame_timestamps(struct ANativeWindow * window,bool enable)960 static inline int native_window_enable_frame_timestamps(
961         struct ANativeWindow* window, bool enable)
962 {
963     return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS,
964             enable);
965 }
966 
native_window_get_compositor_timing(struct ANativeWindow * window,int64_t * compositeDeadline,int64_t * compositeInterval,int64_t * compositeToPresentLatency)967 static inline int native_window_get_compositor_timing(
968         struct ANativeWindow* window,
969         int64_t* compositeDeadline, int64_t* compositeInterval,
970         int64_t* compositeToPresentLatency)
971 {
972     return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING,
973             compositeDeadline, compositeInterval, compositeToPresentLatency);
974 }
975 
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)976 static inline int native_window_get_frame_timestamps(
977         struct ANativeWindow* window, uint64_t frameId,
978         int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
979         int64_t* outLatchTime, int64_t* outFirstRefreshStartTime,
980         int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime,
981         int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime,
982         int64_t* outReleaseTime)
983 {
984     return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
985             frameId, outRequestedPresentTime, outAcquireTime, outLatchTime,
986             outFirstRefreshStartTime, outLastRefreshStartTime,
987             outGpuCompositionDoneTime, outDisplayPresentTime,
988             outDequeueReadyTime, outReleaseTime);
989 }
990 
native_window_get_wide_color_support(struct ANativeWindow * window,bool * outSupport)991 static inline int native_window_get_wide_color_support(
992     struct ANativeWindow* window, bool* outSupport) {
993     return window->perform(window, NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT,
994             outSupport);
995 }
996 
native_window_get_hdr_support(struct ANativeWindow * window,bool * outSupport)997 static inline int native_window_get_hdr_support(struct ANativeWindow* window,
998                                                 bool* outSupport) {
999     return window->perform(window, NATIVE_WINDOW_GET_HDR_SUPPORT, outSupport);
1000 }
1001 
native_window_get_consumer_usage(struct ANativeWindow * window,uint64_t * outUsage)1002 static inline int native_window_get_consumer_usage(struct ANativeWindow* window,
1003                                                    uint64_t* outUsage) {
1004     return window->perform(window, NATIVE_WINDOW_GET_CONSUMER_USAGE64, outUsage);
1005 }
1006 
1007 /*
1008  * native_window_set_auto_prerotation(..., autoPrerotation)
1009  * Enable/disable the auto prerotation at buffer allocation when the buffer size
1010  * is driven by the consumer.
1011  *
1012  * When buffer size is driven by the consumer and the transform hint specifies
1013  * a 90 or 270 degree rotation, if auto prerotation is enabled, the width and
1014  * height used for dequeueBuffer will be additionally swapped.
1015  */
native_window_set_auto_prerotation(struct ANativeWindow * window,bool autoPrerotation)1016 static inline int native_window_set_auto_prerotation(struct ANativeWindow* window,
1017                                                      bool autoPrerotation) {
1018     return window->perform(window, NATIVE_WINDOW_SET_AUTO_PREROTATION, autoPrerotation);
1019 }
1020 
1021 /*
1022  * Internal extension of ANativeWindow_FrameRateCompatibility.
1023  */
1024 enum {
1025     /**
1026      * This surface belongs to an app on the High Refresh Rate Deny list, and needs the display
1027      * to operate at the exact frame rate.
1028      *
1029      * Keep in sync with Surface.java constant.
1030      */
1031     ANATIVEWINDOW_FRAME_RATE_EXACT = 100,
1032 
1033     /**
1034      * This surface is ignored while choosing the refresh rate.
1035      */
1036     ANATIVEWINDOW_FRAME_RATE_NO_VOTE,
1037 };
1038 
native_window_set_frame_rate(struct ANativeWindow * window,float frameRate,int8_t compatibility,int8_t changeFrameRateStrategy)1039 static inline int native_window_set_frame_rate(struct ANativeWindow* window, float frameRate,
1040                                         int8_t compatibility, int8_t changeFrameRateStrategy) {
1041     return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate,
1042                            (int)compatibility, (int)changeFrameRateStrategy);
1043 }
1044 
native_window_set_frame_timeline_info(struct ANativeWindow * window,uint64_t frameNumber,int64_t frameTimelineVsyncId,int32_t inputEventId,int64_t startTimeNanos)1045 static inline int native_window_set_frame_timeline_info(struct ANativeWindow* window,
1046                                                         uint64_t frameNumber,
1047                                                         int64_t frameTimelineVsyncId,
1048                                                         int32_t inputEventId,
1049                                                         int64_t startTimeNanos) {
1050     return window->perform(window, NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO, frameNumber,
1051                            frameTimelineVsyncId, inputEventId, startTimeNanos);
1052 }
1053 
1054 // ------------------------------------------------------------------------------------------------
1055 // Candidates for APEX visibility
1056 // These functions are planned to be made stable for APEX modules, but have not
1057 // yet been stabilized to a specific api version.
1058 // ------------------------------------------------------------------------------------------------
1059 
1060 /**
1061  * Retrieves the last queued buffer for this window, along with the fence that
1062  * fires when the buffer is ready to be read, and the 4x4 coordinate
1063  * transform matrix that should be applied to the buffer's content. The
1064  * transform matrix is represented in column-major order.
1065  *
1066  * If there was no buffer previously queued, then outBuffer will be NULL and
1067  * the value of outFence will be -1.
1068  *
1069  * Note that if outBuffer is not NULL, then the caller will hold a reference
1070  * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release
1071  * when the buffer is no longer needed so that the system may reclaim the
1072  * buffer.
1073  *
1074  * \return NO_ERROR on success.
1075  * \return NO_MEMORY if there was insufficient memory.
1076  */
ANativeWindow_getLastQueuedBuffer(ANativeWindow * window,AHardwareBuffer ** outBuffer,int * outFence,float outTransformMatrix[16])1077 static inline int ANativeWindow_getLastQueuedBuffer(ANativeWindow* window,
1078                                                     AHardwareBuffer** outBuffer, int* outFence,
1079                                                     float outTransformMatrix[16]) {
1080     return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER, outBuffer, outFence,
1081                            outTransformMatrix);
1082 }
1083 
1084 /**
1085  * Retrieves the last queued buffer for this window, along with the fence that
1086  * fires when the buffer is ready to be read. The cropRect & transform should be applied to the
1087  * buffer's content.
1088  *
1089  * If there was no buffer previously queued, then outBuffer will be NULL and
1090  * the value of outFence will be -1.
1091  *
1092  * Note that if outBuffer is not NULL, then the caller will hold a reference
1093  * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release
1094  * when the buffer is no longer needed so that the system may reclaim the
1095  * buffer.
1096  *
1097  * \return NO_ERROR on success.
1098  * \return NO_MEMORY if there was insufficient memory.
1099  * \return STATUS_UNKNOWN_TRANSACTION if this ANativeWindow doesn't support this method, callers
1100  *         should fall back to ANativeWindow_getLastQueuedBuffer instead.
1101  */
ANativeWindow_getLastQueuedBuffer2(ANativeWindow * window,AHardwareBuffer ** outBuffer,int * outFence,ARect * outCropRect,uint32_t * outTransform)1102 static inline int ANativeWindow_getLastQueuedBuffer2(ANativeWindow* window,
1103                                                      AHardwareBuffer** outBuffer, int* outFence,
1104                                                      ARect* outCropRect, uint32_t* outTransform) {
1105     return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2, outBuffer, outFence,
1106                            outCropRect, outTransform);
1107 }
1108 
1109 /**
1110  * Retrieves an identifier for the next frame to be queued by this window.
1111  *
1112  * Frame ids start at 1 and are incremented on each new frame until the underlying surface changes,
1113  * in which case the frame id is reset to 1.
1114  *
1115  * \return the next frame id (0 being uninitialized).
1116  */
ANativeWindow_getNextFrameId(ANativeWindow * window)1117 static inline uint64_t ANativeWindow_getNextFrameId(ANativeWindow* window) {
1118     uint64_t value;
1119     window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, &value);
1120     return value;
1121 }
1122 
1123 /**
1124  * Prototype of the function that an ANativeWindow implementation would call
1125  * when ANativeWindow_query is called.
1126  */
1127 typedef int (*ANativeWindow_queryFn)(const ANativeWindow* window, int what, int* value);
1128 
1129 /**
1130  * Prototype of the function that intercepts an invocation of
1131  * ANativeWindow_queryFn, along with a data pointer that's passed by the
1132  * caller who set the interceptor, as well as arguments that would be
1133  * passed to ANativeWindow_queryFn if it were to be called.
1134  */
1135 typedef int (*ANativeWindow_queryInterceptor)(const ANativeWindow* window,
1136                                                 ANativeWindow_queryFn perform, void* data,
1137                                                 int what, int* value);
1138 
1139 /**
1140  * Registers an interceptor for ANativeWindow_query. Instead of calling
1141  * the underlying query function, instead the provided interceptor is
1142  * called, which may optionally call the underlying query function. An
1143  * optional data pointer is also provided to side-channel additional arguments.
1144  *
1145  * Note that usage of this should only be used for specialized use-cases by
1146  * either the system partition or to Mainline modules. This should never be
1147  * exposed to NDK or LL-NDK.
1148  *
1149  * Returns NO_ERROR on success, -errno if registration failed.
1150  */
ANativeWindow_setQueryInterceptor(ANativeWindow * window,ANativeWindow_queryInterceptor interceptor,void * data)1151 static inline int ANativeWindow_setQueryInterceptor(ANativeWindow* window,
1152                                             ANativeWindow_queryInterceptor interceptor,
1153                                             void* data) {
1154     return window->perform(window, NATIVE_WINDOW_SET_QUERY_INTERCEPTOR, interceptor, data);
1155 }
1156 
1157 __END_DECLS
1158