• 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 #include <vndk/hardware_buffer.h>
45 
46 // system/window.h is a superset of the vndk and apex apis
47 #include <apex/window.h>
48 #include <vndk/window.h>
49 
50 
51 #ifndef __UNUSED
52 #define __UNUSED __attribute__((__unused__))
53 #endif
54 #ifndef __deprecated
55 #define __deprecated __attribute__((__deprecated__))
56 #endif
57 
58 __BEGIN_DECLS
59 
60 /*****************************************************************************/
61 
62 #define ANDROID_NATIVE_WINDOW_MAGIC     ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
63 
64 // ---------------------------------------------------------------------------
65 
66 /* attributes queriable with query() */
67 enum {
68     NATIVE_WINDOW_WIDTH = 0,
69     NATIVE_WINDOW_HEIGHT = 1,
70     NATIVE_WINDOW_FORMAT = 2,
71 
72     /* see ANativeWindowQuery in vndk/window.h */
73     NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS,
74 
75     /* Check whether queueBuffer operations on the ANativeWindow send the buffer
76      * to the window compositor.  The query sets the returned 'value' argument
77      * to 1 if the ANativeWindow DOES send queued buffers directly to the window
78      * compositor and 0 if the buffers do not go directly to the window
79      * compositor.
80      *
81      * This can be used to determine whether protected buffer content should be
82      * sent to the ANativeWindow.  Note, however, that a result of 1 does NOT
83      * indicate that queued buffers will be protected from applications or users
84      * capturing their contents.  If that behavior is desired then some other
85      * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
86      * conjunction with this query.
87      */
88     NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
89 
90     /* Get the concrete type of a ANativeWindow.  See below for the list of
91      * possible return values.
92      *
93      * This query should not be used outside the Android framework and will
94      * likely be removed in the near future.
95      */
96     NATIVE_WINDOW_CONCRETE_TYPE = 5,
97 
98     /*
99      * Default width and height of ANativeWindow buffers, these are the
100      * dimensions of the window buffers irrespective of the
101      * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window
102      * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
103      */
104     NATIVE_WINDOW_DEFAULT_WIDTH = ANATIVEWINDOW_QUERY_DEFAULT_WIDTH,
105     NATIVE_WINDOW_DEFAULT_HEIGHT = ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT,
106 
107     /* see ANativeWindowQuery in vndk/window.h */
108     NATIVE_WINDOW_TRANSFORM_HINT = ANATIVEWINDOW_QUERY_TRANSFORM_HINT,
109 
110     /*
111      * Boolean that indicates whether the consumer is running more than
112      * one buffer behind the producer.
113      */
114     NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9,
115 
116     /*
117      * The consumer gralloc usage bits currently set by the consumer.
118      * The values are defined in hardware/libhardware/include/gralloc.h.
119      */
120     NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10, /* deprecated */
121 
122     /**
123      * Transformation that will by applied to buffers by the hwcomposer.
124      * This must not be set or checked by producer endpoints, and will
125      * disable the transform hint set in SurfaceFlinger (see
126      * NATIVE_WINDOW_TRANSFORM_HINT).
127      *
128      * INTENDED USE:
129      * Temporary - Please do not use this.  This is intended only to be used
130      * by the camera's LEGACY mode.
131      *
132      * In situations where a SurfaceFlinger client wishes to set a transform
133      * that is not visible to the producer, and will always be applied in the
134      * hardware composer, the client can set this flag with
135      * native_window_set_buffers_sticky_transform.  This can be used to rotate
136      * and flip buffers consumed by hardware composer without actually changing
137      * the aspect ratio of the buffers produced.
138      */
139     NATIVE_WINDOW_STICKY_TRANSFORM = 11,
140 
141     /**
142      * The default data space for the buffers as set by the consumer.
143      * The values are defined in graphics.h.
144      */
145     NATIVE_WINDOW_DEFAULT_DATASPACE = 12,
146 
147     /* see ANativeWindowQuery in vndk/window.h */
148     NATIVE_WINDOW_BUFFER_AGE = ANATIVEWINDOW_QUERY_BUFFER_AGE,
149 
150     /*
151      * Returns the duration of the last dequeueBuffer call in microseconds
152      * Deprecated: please use NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION in
153      * perform() instead, which supports nanosecond precision.
154      */
155     NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
156 
157     /*
158      * Returns the duration of the last queueBuffer call in microseconds
159      * Deprecated: please use NATIVE_WINDOW_GET_LAST_QUEUE_DURATION in
160      * perform() instead, which supports nanosecond precision.
161      */
162     NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
163 
164     /*
165      * Returns the number of image layers that the ANativeWindow buffer
166      * contains. By default this is 1, unless a buffer is explicitly allocated
167      * to contain multiple layers.
168      */
169     NATIVE_WINDOW_LAYER_COUNT = 16,
170 
171     /*
172      * Returns 1 if the native window is valid, 0 otherwise. native window is valid
173      * if it is safe (i.e. no crash will occur) to call any method on it.
174      */
175     NATIVE_WINDOW_IS_VALID = 17,
176 
177     /*
178      * Returns 1 if NATIVE_WINDOW_GET_FRAME_TIMESTAMPS will return display
179      * present info, 0 if it won't.
180      */
181     NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18,
182 
183     /*
184      * The consumer end is capable of handling protected buffers, i.e. buffer
185      * with GRALLOC_USAGE_PROTECTED usage bits on.
186      */
187     NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19,
188 
189     /*
190      * Returns data space for the buffers.
191      */
192     NATIVE_WINDOW_DATASPACE = 20,
193 
194     /*
195      * Returns maxBufferCount set by BufferQueueConsumer
196      */
197     NATIVE_WINDOW_MAX_BUFFER_COUNT = 21,
198 };
199 
200 /* Valid operations for the (*perform)() hook.
201  *
202  * Values marked as 'deprecated' are supported, but have been superceded by
203  * other functionality.
204  *
205  * Values marked as 'private' should be considered private to the framework.
206  * HAL implementation code with access to an ANativeWindow should not use these,
207  * as it may not interact properly with the framework's use of the
208  * ANativeWindow.
209  */
210 enum {
211     // clang-format off
212     NATIVE_WINDOW_SET_USAGE                       =  ANATIVEWINDOW_PERFORM_SET_USAGE,   /* deprecated */
213     NATIVE_WINDOW_CONNECT                         =  1,   /* deprecated */
214     NATIVE_WINDOW_DISCONNECT                      =  2,   /* deprecated */
215     NATIVE_WINDOW_SET_CROP                        =  3,   /* private */
216     NATIVE_WINDOW_SET_BUFFER_COUNT                =  4,
217     NATIVE_WINDOW_SET_BUFFERS_GEOMETRY            =  ANATIVEWINDOW_PERFORM_SET_BUFFERS_GEOMETRY,   /* deprecated */
218     NATIVE_WINDOW_SET_BUFFERS_TRANSFORM           =  6,
219     NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP           =  7,
220     NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS          =  8,
221     NATIVE_WINDOW_SET_BUFFERS_FORMAT              =  ANATIVEWINDOW_PERFORM_SET_BUFFERS_FORMAT,
222     NATIVE_WINDOW_SET_SCALING_MODE                = 10,   /* private */
223     NATIVE_WINDOW_LOCK                            = 11,   /* private */
224     NATIVE_WINDOW_UNLOCK_AND_POST                 = 12,   /* private */
225     NATIVE_WINDOW_API_CONNECT                     = 13,   /* private */
226     NATIVE_WINDOW_API_DISCONNECT                  = 14,   /* private */
227     NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS     = 15,   /* private */
228     NATIVE_WINDOW_SET_POST_TRANSFORM_CROP         = 16,   /* deprecated, unimplemented */
229     NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM    = 17,   /* private */
230     NATIVE_WINDOW_SET_SIDEBAND_STREAM             = 18,
231     NATIVE_WINDOW_SET_BUFFERS_DATASPACE           = 19,
232     NATIVE_WINDOW_SET_SURFACE_DAMAGE              = 20,   /* private */
233     NATIVE_WINDOW_SET_SHARED_BUFFER_MODE          = 21,
234     NATIVE_WINDOW_SET_AUTO_REFRESH                = 22,
235     NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION      = 23,
236     NATIVE_WINDOW_GET_NEXT_FRAME_ID               = 24,
237     NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS         = 25,
238     NATIVE_WINDOW_GET_COMPOSITOR_TIMING           = 26,
239     NATIVE_WINDOW_GET_FRAME_TIMESTAMPS            = 27,
240     /* 28, removed: NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT */
241     /* 29, removed: NATIVE_WINDOW_GET_HDR_SUPPORT */
242     NATIVE_WINDOW_SET_USAGE64                     = ANATIVEWINDOW_PERFORM_SET_USAGE64,
243     NATIVE_WINDOW_GET_CONSUMER_USAGE64            = 31,
244     NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA  = 32,
245     NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA   = 33,
246     NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA = 34,
247     NATIVE_WINDOW_SET_AUTO_PREROTATION            = 35,
248     NATIVE_WINDOW_GET_LAST_DEQUEUE_START          = 36,    /* private */
249     NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT             = 37,    /* private */
250     NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION       = 38,    /* private */
251     NATIVE_WINDOW_GET_LAST_QUEUE_DURATION         = 39,    /* private */
252     NATIVE_WINDOW_SET_FRAME_RATE                  = 40,
253     NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR          = 41,    /* private */
254     NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR         = 42,    /* private */
255     NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR         = 43,    /* private */
256     NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR           = 44,    /* private */
257     NATIVE_WINDOW_ALLOCATE_BUFFERS                = 45,    /* private */
258     NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER          = 46,    /* private */
259     NATIVE_WINDOW_SET_QUERY_INTERCEPTOR           = 47,    /* private */
260     NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO         = 48,    /* private */
261     NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2         = 49,    /* private */
262     NATIVE_WINDOW_SET_BUFFERS_ADDITIONAL_OPTIONS  = 50,
263     // clang-format on
264 };
265 
266 /* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
267 enum {
268     /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
269      * OpenGL ES.
270      */
271     NATIVE_WINDOW_API_EGL = 1,
272 
273     /* Buffers will be queued after being filled using the CPU
274      */
275     NATIVE_WINDOW_API_CPU = 2,
276 
277     /* Buffers will be queued by Stagefright after being filled by a video
278      * decoder.  The video decoder can either be a software or hardware decoder.
279      */
280     NATIVE_WINDOW_API_MEDIA = 3,
281 
282     /* Buffers will be queued by the the camera HAL.
283      */
284     NATIVE_WINDOW_API_CAMERA = 4,
285 };
286 
287 /* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
288 enum {
289     /* flip source image horizontally */
290     NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
291     /* flip source image vertically */
292     NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
293     /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
294     NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
295     /* rotate source image 180 degrees */
296     NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
297     /* rotate source image 270 degrees clock-wise */
298     NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
299     /* transforms source by the inverse transform of the screen it is displayed onto. This
300      * transform is applied last */
301     NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
302 };
303 
304 /* parameter for NATIVE_WINDOW_SET_SCALING_MODE
305  * keep in sync with Surface.java in frameworks/base */
306 enum {
307     /* the window content is not updated (frozen) until a buffer of
308      * the window size is received (enqueued)
309      */
310     NATIVE_WINDOW_SCALING_MODE_FREEZE           = 0,
311     /* the buffer is scaled in both dimensions to match the window size */
312     NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW  = 1,
313     /* the buffer is scaled uniformly such that the smaller dimension
314      * of the buffer matches the window size (cropping in the process)
315      */
316     NATIVE_WINDOW_SCALING_MODE_SCALE_CROP       = 2,
317     /* the window is clipped to the size of the buffer's crop rectangle; pixels
318      * outside the crop rectangle are treated as if they are completely
319      * transparent.
320      */
321     NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP    = 3,
322 };
323 
324 /* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
325 enum {
326     NATIVE_WINDOW_FRAMEBUFFER               = 0, /* FramebufferNativeWindow */
327     NATIVE_WINDOW_SURFACE                   = 1, /* Surface */
328 };
329 
330 /* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
331  *
332  * Special timestamp value to indicate that timestamps should be auto-generated
333  * by the native window when queueBuffer is called.  This is equal to INT64_MIN,
334  * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
335  */
336 static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
337 
338 /* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS
339  *
340  * Special timestamp value to indicate the timestamps aren't yet known or
341  * that they are invalid.
342  */
343 static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2;
344 static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1;
345 
346 struct ANativeWindow
347 {
348 #ifdef __cplusplus
ANativeWindowANativeWindow349     ANativeWindow()
350         : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
351     {
352         common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
353         common.version = sizeof(ANativeWindow);
354         memset(common.reserved, 0, sizeof(common.reserved));
355     }
356 
357     /* Implement the methods that sp<ANativeWindow> expects so that it
358        can be used to automatically refcount ANativeWindow's. */
incStrongANativeWindow359     void incStrong(const void* /*id*/) const {
360         common.incRef(const_cast<android_native_base_t*>(&common));
361     }
decStrongANativeWindow362     void decStrong(const void* /*id*/) const {
363         common.decRef(const_cast<android_native_base_t*>(&common));
364     }
365 #endif
366 
367     struct android_native_base_t common;
368 
369     /* flags describing some attributes of this surface or its updater */
370     const uint32_t flags;
371 
372     /* min swap interval supported by this updated */
373     const int   minSwapInterval;
374 
375     /* max swap interval supported by this updated */
376     const int   maxSwapInterval;
377 
378     /* horizontal and vertical resolution in DPI */
379     const float xdpi;
380     const float ydpi;
381 
382     /* Some storage reserved for the OEM's driver. */
383     intptr_t    oem[4];
384 
385     /*
386      * Set the swap interval for this surface.
387      *
388      * Returns 0 on success or -errno on error.
389      */
390     int     (*setSwapInterval)(struct ANativeWindow* window,
391                 int interval);
392 
393     /*
394      * Hook called by EGL to acquire a buffer. After this call, the buffer
395      * is not locked, so its content cannot be modified. This call may block if
396      * no buffers are available.
397      *
398      * The window holds a reference to the buffer between dequeueBuffer and
399      * either queueBuffer or cancelBuffer, so clients only need their own
400      * reference if they might use the buffer after queueing or canceling it.
401      * Holding a reference to a buffer after queueing or canceling it is only
402      * allowed if a specific buffer count has been set.
403      *
404      * Returns 0 on success or -errno on error.
405      *
406      * XXX: This function is deprecated.  It will continue to work for some
407      * time for binary compatibility, but the new dequeueBuffer function that
408      * outputs a fence file descriptor should be used in its place.
409      */
410     int     (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
411                 struct ANativeWindowBuffer** buffer);
412 
413     /*
414      * hook called by EGL to lock a buffer. This MUST be called before modifying
415      * the content of a buffer. The buffer must have been acquired with
416      * dequeueBuffer first.
417      *
418      * Returns 0 on success or -errno on error.
419      *
420      * XXX: This function is deprecated.  It will continue to work for some
421      * time for binary compatibility, but it is essentially a no-op, and calls
422      * to it should be removed.
423      */
424     int     (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
425                 struct ANativeWindowBuffer* buffer);
426 
427     /*
428      * Hook called by EGL when modifications to the render buffer are done.
429      * This unlocks and post the buffer.
430      *
431      * The window holds a reference to the buffer between dequeueBuffer and
432      * either queueBuffer or cancelBuffer, so clients only need their own
433      * reference if they might use the buffer after queueing or canceling it.
434      * Holding a reference to a buffer after queueing or canceling it is only
435      * allowed if a specific buffer count has been set.
436      *
437      * Buffers MUST be queued in the same order than they were dequeued.
438      *
439      * Returns 0 on success or -errno on error.
440      *
441      * XXX: This function is deprecated.  It will continue to work for some
442      * time for binary compatibility, but the new queueBuffer function that
443      * takes a fence file descriptor should be used in its place (pass a value
444      * of -1 for the fence file descriptor if there is no valid one to pass).
445      */
446     int     (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
447                 struct ANativeWindowBuffer* buffer);
448 
449     /*
450      * hook used to retrieve information about the native window.
451      *
452      * Returns 0 on success or -errno on error.
453      */
454     int     (*query)(const struct ANativeWindow* window,
455                 int what, int* value);
456 
457     /*
458      * hook used to perform various operations on the surface.
459      * (*perform)() is a generic mechanism to add functionality to
460      * ANativeWindow while keeping backward binary compatibility.
461      *
462      * DO NOT CALL THIS HOOK DIRECTLY.  Instead, use the helper functions
463      * defined below.
464      *
465      * (*perform)() returns -ENOENT if the 'what' parameter is not supported
466      * by the surface's implementation.
467      *
468      * See above for a list of valid operations, such as
469      * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
470      */
471     int     (*perform)(struct ANativeWindow* window,
472                 int operation, ... );
473 
474     /*
475      * Hook used to cancel a buffer that has been dequeued.
476      * No synchronization is performed between dequeue() and cancel(), so
477      * either external synchronization is needed, or these functions must be
478      * called from the same thread.
479      *
480      * The window holds a reference to the buffer between dequeueBuffer and
481      * either queueBuffer or cancelBuffer, so clients only need their own
482      * reference if they might use the buffer after queueing or canceling it.
483      * Holding a reference to a buffer after queueing or canceling it is only
484      * allowed if a specific buffer count has been set.
485      *
486      * XXX: This function is deprecated.  It will continue to work for some
487      * time for binary compatibility, but the new cancelBuffer function that
488      * takes a fence file descriptor should be used in its place (pass a value
489      * of -1 for the fence file descriptor if there is no valid one to pass).
490      */
491     int     (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
492                 struct ANativeWindowBuffer* buffer);
493 
494     /*
495      * Hook called by EGL to acquire a buffer. This call may block if no
496      * buffers are available.
497      *
498      * The window holds a reference to the buffer between dequeueBuffer and
499      * either queueBuffer or cancelBuffer, so clients only need their own
500      * reference if they might use the buffer after queueing or canceling it.
501      * Holding a reference to a buffer after queueing or canceling it is only
502      * allowed if a specific buffer count has been set.
503      *
504      * The libsync fence file descriptor returned in the int pointed to by the
505      * fenceFd argument will refer to the fence that must signal before the
506      * dequeued buffer may be written to.  A value of -1 indicates that the
507      * caller may access the buffer immediately without waiting on a fence.  If
508      * a valid file descriptor is returned (i.e. any value except -1) then the
509      * caller is responsible for closing the file descriptor.
510      *
511      * Returns 0 on success or -errno on error.
512      */
513     int     (*dequeueBuffer)(struct ANativeWindow* window,
514                 struct ANativeWindowBuffer** buffer, int* fenceFd);
515 
516     /*
517      * Hook called by EGL when modifications to the render buffer are done.
518      * This unlocks and post the buffer.
519      *
520      * The window holds a reference to the buffer between dequeueBuffer and
521      * either queueBuffer or cancelBuffer, so clients only need their own
522      * reference if they might use the buffer after queueing or canceling it.
523      * Holding a reference to a buffer after queueing or canceling it is only
524      * allowed if a specific buffer count has been set.
525      *
526      * The fenceFd argument specifies a libsync fence file descriptor for a
527      * fence that must signal before the buffer can be accessed.  If the buffer
528      * can be accessed immediately then a value of -1 should be used.  The
529      * caller must not use the file descriptor after it is passed to
530      * queueBuffer, and the ANativeWindow implementation is responsible for
531      * closing it.
532      *
533      * Returns 0 on success or -errno on error.
534      */
535     int     (*queueBuffer)(struct ANativeWindow* window,
536                 struct ANativeWindowBuffer* buffer, int fenceFd);
537 
538     /*
539      * Hook used to cancel a buffer that has been dequeued.
540      * No synchronization is performed between dequeue() and cancel(), so
541      * either external synchronization is needed, or these functions must be
542      * called from the same thread.
543      *
544      * The window holds a reference to the buffer between dequeueBuffer and
545      * either queueBuffer or cancelBuffer, so clients only need their own
546      * reference if they might use the buffer after queueing or canceling it.
547      * Holding a reference to a buffer after queueing or canceling it is only
548      * allowed if a specific buffer count has been set.
549      *
550      * The fenceFd argument specifies a libsync fence file decsriptor for a
551      * fence that must signal before the buffer can be accessed.  If the buffer
552      * can be accessed immediately then a value of -1 should be used.
553      *
554      * Note that if the client has not waited on the fence that was returned
555      * from dequeueBuffer, that same fence should be passed to cancelBuffer to
556      * ensure that future uses of the buffer are preceded by a wait on that
557      * fence.  The caller must not use the file descriptor after it is passed
558      * to cancelBuffer, and the ANativeWindow implementation is responsible for
559      * closing it.
560      *
561      * Returns 0 on success or -errno on error.
562      */
563     int     (*cancelBuffer)(struct ANativeWindow* window,
564                 struct ANativeWindowBuffer* buffer, int fenceFd);
565 };
566 
567  /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
568   * android_native_window_t is deprecated.
569   */
570 typedef struct ANativeWindow android_native_window_t __deprecated;
571 
572 /*
573  *  native_window_set_usage64(..., usage)
574  *  Sets the intended usage flags for the next buffers
575  *  acquired with (*lockBuffer)() and on.
576  *
577  *  Valid usage flags are defined in android/hardware_buffer.h
578  *  All AHARDWAREBUFFER_USAGE_* flags can be specified as needed.
579  *
580  *  Calling this function will usually cause following buffers to be
581  *  reallocated.
582  */
native_window_set_usage(struct ANativeWindow * window,uint64_t usage)583 static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) {
584     return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage);
585 }
586 
587 /* deprecated. Always returns 0. Don't call. */
588 static inline int native_window_connect(
589         struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
590 
native_window_connect(struct ANativeWindow * window __UNUSED,int api __UNUSED)591 static inline int native_window_connect(
592         struct ANativeWindow* window __UNUSED, int api __UNUSED) {
593     return 0;
594 }
595 
596 /* deprecated. Always returns 0. Don't call. */
597 static inline int native_window_disconnect(
598         struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
599 
native_window_disconnect(struct ANativeWindow * window __UNUSED,int api __UNUSED)600 static inline int native_window_disconnect(
601         struct ANativeWindow* window __UNUSED, int api __UNUSED) {
602     return 0;
603 }
604 
605 /*
606  * native_window_set_crop(..., crop)
607  * Sets which region of the next queued buffers needs to be considered.
608  * Depending on the scaling mode, a buffer's crop region is scaled and/or
609  * cropped to match the surface's size.  This function sets the crop in
610  * pre-transformed buffer pixel coordinates.
611  *
612  * The specified crop region applies to all buffers queued after it is called.
613  *
614  * If 'crop' is NULL, subsequently queued buffers won't be cropped.
615  *
616  * An error is returned if for instance the crop region is invalid, out of the
617  * buffer's bound or if the window is invalid.
618  */
native_window_set_crop(struct ANativeWindow * window,android_native_rect_t const * crop)619 static inline int native_window_set_crop(
620         struct ANativeWindow* window,
621         android_native_rect_t const * crop)
622 {
623     return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
624 }
625 
626 /*
627  * native_window_set_buffer_count(..., count)
628  * Sets the number of buffers associated with this native window.
629  */
native_window_set_buffer_count(struct ANativeWindow * window,size_t bufferCount)630 static inline int native_window_set_buffer_count(
631         struct ANativeWindow* window,
632         size_t bufferCount)
633 {
634     return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
635 }
636 
637 /*
638  * native_window_set_buffers_geometry(..., int w, int h, int format)
639  * All buffers dequeued after this call will have the dimensions and format
640  * specified.  A successful call to this function has the same effect as calling
641  * native_window_set_buffers_size and native_window_set_buffers_format.
642  *
643  * XXX: This function is deprecated.  The native_window_set_buffers_dimensions
644  * and native_window_set_buffers_format functions should be used instead.
645  */
646 static inline int native_window_set_buffers_geometry(
647         struct ANativeWindow* window,
648         int w, int h, int format) __deprecated;
649 
native_window_set_buffers_geometry(struct ANativeWindow * window,int w,int h,int format)650 static inline int native_window_set_buffers_geometry(
651         struct ANativeWindow* window,
652         int w, int h, int format)
653 {
654     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
655             w, h, format);
656 }
657 
658 /*
659  * native_window_set_buffers_dimensions(..., int w, int h)
660  * All buffers dequeued after this call will have the dimensions specified.
661  * In particular, all buffers will have a fixed-size, independent from the
662  * native-window size. They will be scaled according to the scaling mode
663  * (see native_window_set_scaling_mode) upon window composition.
664  *
665  * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
666  * following this call will be sized to match the window's size.
667  *
668  * Calling this function will reset the window crop to a NULL value, which
669  * disables cropping of the buffers.
670  */
native_window_set_buffers_dimensions(struct ANativeWindow * window,int w,int h)671 static inline int native_window_set_buffers_dimensions(
672         struct ANativeWindow* window,
673         int w, int h)
674 {
675     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
676             w, h);
677 }
678 
679 /*
680  * native_window_set_buffers_user_dimensions(..., int w, int h)
681  *
682  * Sets the user buffer size for the window, which overrides the
683  * window's size.  All buffers dequeued after this call will have the
684  * dimensions specified unless overridden by
685  * native_window_set_buffers_dimensions.  All buffers will have a
686  * fixed-size, independent from the native-window size. They will be
687  * scaled according to the scaling mode (see
688  * native_window_set_scaling_mode) upon window composition.
689  *
690  * If w and h are 0, the normal behavior is restored. That is, the
691  * default buffer size will match the windows's size.
692  *
693  * Calling this function will reset the window crop to a NULL value, which
694  * disables cropping of the buffers.
695  */
native_window_set_buffers_user_dimensions(struct ANativeWindow * window,int w,int h)696 static inline int native_window_set_buffers_user_dimensions(
697         struct ANativeWindow* window,
698         int w, int h)
699 {
700     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
701             w, h);
702 }
703 
704 /*
705  * native_window_set_buffers_format(..., int format)
706  * All buffers dequeued after this call will have the format specified.
707  *
708  * If the specified format is 0, the default buffer format will be used.
709  */
native_window_set_buffers_format(struct ANativeWindow * window,int format)710 static inline int native_window_set_buffers_format(
711         struct ANativeWindow* window,
712         int format)
713 {
714     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
715 }
716 
717 /*
718  * native_window_set_buffers_data_space(..., int dataSpace)
719  * All buffers queued after this call will be associated with the dataSpace
720  * parameter specified.
721  *
722  * dataSpace specifies additional information about the buffer that's dependent
723  * on the buffer format and the endpoints. For example, it can be used to convey
724  * the color space of the image data in the buffer, or it can be used to
725  * indicate that the buffers contain depth measurement data instead of color
726  * images.  The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
727  * overridden by the consumer.
728  */
native_window_set_buffers_data_space(struct ANativeWindow * window,android_dataspace_t dataSpace)729 static inline int native_window_set_buffers_data_space(
730         struct ANativeWindow* window,
731         android_dataspace_t dataSpace)
732 {
733     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
734             dataSpace);
735 }
736 
737 /*
738  * native_window_set_buffers_smpte2086_metadata(..., metadata)
739  * All buffers queued after this call will be associated with the SMPTE
740  * ST.2086 metadata specified.
741  *
742  * metadata specifies additional information about the contents of the buffer
743  * that may affect how it's displayed.  When it is nullptr, it means no such
744  * information is available.  No SMPTE ST.2086 metadata is associated with the
745  * buffers by default.
746  */
native_window_set_buffers_smpte2086_metadata(struct ANativeWindow * window,const struct android_smpte2086_metadata * metadata)747 static inline int native_window_set_buffers_smpte2086_metadata(
748         struct ANativeWindow* window,
749         const struct android_smpte2086_metadata* metadata)
750 {
751     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA,
752             metadata);
753 }
754 
755 /*
756  * native_window_set_buffers_cta861_3_metadata(..., metadata)
757  * All buffers queued after this call will be associated with the CTA-861.3
758  * metadata specified.
759  *
760  * metadata specifies additional information about the contents of the buffer
761  * that may affect how it's displayed.  When it is nullptr, it means no such
762  * information is available.  No CTA-861.3 metadata is associated with the
763  * buffers by default.
764  */
native_window_set_buffers_cta861_3_metadata(struct ANativeWindow * window,const struct android_cta861_3_metadata * metadata)765 static inline int native_window_set_buffers_cta861_3_metadata(
766         struct ANativeWindow* window,
767         const struct android_cta861_3_metadata* metadata)
768 {
769     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA,
770             metadata);
771 }
772 
773 /*
774  * native_window_set_buffers_hdr10_plus_metadata(..., metadata)
775  * All buffers queued after this call will be associated with the
776  * HDR10+ dynamic metadata specified.
777  *
778  * metadata specifies additional dynamic information about the
779  * contents of the buffer that may affect how it is displayed.  When
780  * it is nullptr, it means no such information is available.  No
781  * HDR10+ dynamic emtadata is associated with the buffers by default.
782  *
783  * Parameter "size" refers to the length of the metadata blob pointed to
784  * by parameter "data".  The metadata blob will adhere to the HDR10+ SEI
785  * message standard.
786  */
native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow * window,const size_t size,const uint8_t * metadata)787 static inline int native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow* window,
788                                                            const size_t size,
789                                                            const uint8_t* metadata) {
790     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA, size,
791                            metadata);
792 }
793 
794 /*
795  * native_window_set_buffers_transform(..., int transform)
796  * All buffers queued after this call will be displayed transformed according
797  * to the transform parameter specified.
798  */
native_window_set_buffers_transform(struct ANativeWindow * window,int transform)799 static inline int native_window_set_buffers_transform(
800         struct ANativeWindow* window,
801         int transform)
802 {
803     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
804             transform);
805 }
806 
807 /*
808  * native_window_set_buffers_sticky_transform(..., int transform)
809  * All buffers queued after this call will be displayed transformed according
810  * to the transform parameter specified applied on top of the regular buffer
811  * transform.  Setting this transform will disable the transform hint.
812  *
813  * Temporary - This is only intended to be used by the LEGACY camera mode, do
814  *   not use this for anything else.
815  */
native_window_set_buffers_sticky_transform(struct ANativeWindow * window,int transform)816 static inline int native_window_set_buffers_sticky_transform(
817         struct ANativeWindow* window,
818         int transform)
819 {
820     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
821             transform);
822 }
823 
824 /*
825  * native_window_set_buffers_timestamp(..., int64_t timestamp)
826  * All buffers queued after this call will be associated with the timestamp
827  * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
828  * (the default), timestamps will be generated automatically when queueBuffer is
829  * called. The timestamp is measured in nanoseconds, and is normally monotonically
830  * increasing. The timestamp should be unaffected by time-of-day adjustments,
831  * and for a camera should be strictly monotonic but for a media player may be
832  * reset when the position is set.
833  */
native_window_set_buffers_timestamp(struct ANativeWindow * window,int64_t timestamp)834 static inline int native_window_set_buffers_timestamp(
835         struct ANativeWindow* window,
836         int64_t timestamp)
837 {
838     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
839             timestamp);
840 }
841 
842 /*
843  * native_window_set_scaling_mode(..., int mode)
844  * All buffers queued after this call will be associated with the scaling mode
845  * specified.
846  */
native_window_set_scaling_mode(struct ANativeWindow * window,int mode)847 static inline int native_window_set_scaling_mode(
848         struct ANativeWindow* window,
849         int mode)
850 {
851     return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
852             mode);
853 }
854 
855 /*
856  * native_window_api_connect(..., int api)
857  * connects an API to this window. only one API can be connected at a time.
858  * Returns -EINVAL if for some reason the window cannot be connected, which
859  * can happen if it's connected to some other API.
860  */
native_window_api_connect(struct ANativeWindow * window,int api)861 static inline int native_window_api_connect(
862         struct ANativeWindow* window, int api)
863 {
864     return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
865 }
866 
867 /*
868  * native_window_api_disconnect(..., int api)
869  * disconnect the API from this window.
870  * An error is returned if for instance the window wasn't connected in the
871  * first place.
872  */
native_window_api_disconnect(struct ANativeWindow * window,int api)873 static inline int native_window_api_disconnect(
874         struct ANativeWindow* window, int api)
875 {
876     return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
877 }
878 
879 /*
880  * native_window_dequeue_buffer_and_wait(...)
881  * Dequeue a buffer and wait on the fence associated with that buffer.  The
882  * buffer may safely be accessed immediately upon this function returning.  An
883  * error is returned if either of the dequeue or the wait operations fail.
884  */
native_window_dequeue_buffer_and_wait(ANativeWindow * anw,struct ANativeWindowBuffer ** anb)885 static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
886         struct ANativeWindowBuffer** anb) {
887     return anw->dequeueBuffer_DEPRECATED(anw, anb);
888 }
889 
890 /*
891  * native_window_set_sideband_stream(..., native_handle_t*)
892  * Attach a sideband buffer stream to a native window.
893  */
native_window_set_sideband_stream(struct ANativeWindow * window,native_handle_t * sidebandHandle)894 static inline int native_window_set_sideband_stream(
895         struct ANativeWindow* window,
896         native_handle_t* sidebandHandle)
897 {
898     return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
899             sidebandHandle);
900 }
901 
902 /*
903  * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
904  * Set the surface damage (i.e., the region of the surface that has changed
905  * since the previous frame). The damage set by this call will be reset (to the
906  * default of full-surface damage) after calling queue, so this must be called
907  * prior to every frame with damage that does not cover the whole surface if the
908  * caller desires downstream consumers to use this optimization.
909  *
910  * The damage region is specified as an array of rectangles, with the important
911  * caveat that the origin of the surface is considered to be the bottom-left
912  * corner, as in OpenGL ES.
913  *
914  * If numRects is set to 0, rects may be NULL, and the surface damage will be
915  * set to the full surface (the same as if this function had not been called for
916  * this frame).
917  */
native_window_set_surface_damage(struct ANativeWindow * window,const android_native_rect_t * rects,size_t numRects)918 static inline int native_window_set_surface_damage(
919         struct ANativeWindow* window,
920         const android_native_rect_t* rects, size_t numRects)
921 {
922     return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
923             rects, numRects);
924 }
925 
926 /*
927  * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
928  * Enable/disable shared buffer mode
929  */
native_window_set_shared_buffer_mode(struct ANativeWindow * window,bool sharedBufferMode)930 static inline int native_window_set_shared_buffer_mode(
931         struct ANativeWindow* window,
932         bool sharedBufferMode)
933 {
934     return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
935             sharedBufferMode);
936 }
937 
938 /*
939  * native_window_set_auto_refresh(..., autoRefresh)
940  * Enable/disable auto refresh when in shared buffer mode
941  */
native_window_set_auto_refresh(struct ANativeWindow * window,bool autoRefresh)942 static inline int native_window_set_auto_refresh(
943         struct ANativeWindow* window,
944         bool autoRefresh)
945 {
946     return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
947 }
948 
native_window_get_refresh_cycle_duration(struct ANativeWindow * window,int64_t * outRefreshDuration)949 static inline int native_window_get_refresh_cycle_duration(
950         struct ANativeWindow* window,
951         int64_t* outRefreshDuration)
952 {
953     return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION,
954             outRefreshDuration);
955 }
956 
native_window_get_next_frame_id(struct ANativeWindow * window,uint64_t * frameId)957 static inline int native_window_get_next_frame_id(
958         struct ANativeWindow* window, uint64_t* frameId)
959 {
960     return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId);
961 }
962 
native_window_enable_frame_timestamps(struct ANativeWindow * window,bool enable)963 static inline int native_window_enable_frame_timestamps(
964         struct ANativeWindow* window, bool enable)
965 {
966     return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS,
967             enable);
968 }
969 
native_window_get_compositor_timing(struct ANativeWindow * window,int64_t * compositeDeadline,int64_t * compositeInterval,int64_t * compositeToPresentLatency)970 static inline int native_window_get_compositor_timing(
971         struct ANativeWindow* window,
972         int64_t* compositeDeadline, int64_t* compositeInterval,
973         int64_t* compositeToPresentLatency)
974 {
975     return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING,
976             compositeDeadline, compositeInterval, compositeToPresentLatency);
977 }
978 
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)979 static inline int native_window_get_frame_timestamps(
980         struct ANativeWindow* window, uint64_t frameId,
981         int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
982         int64_t* outLatchTime, int64_t* outFirstRefreshStartTime,
983         int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime,
984         int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime,
985         int64_t* outReleaseTime)
986 {
987     return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
988             frameId, outRequestedPresentTime, outAcquireTime, outLatchTime,
989             outFirstRefreshStartTime, outLastRefreshStartTime,
990             outGpuCompositionDoneTime, outDisplayPresentTime,
991             outDequeueReadyTime, outReleaseTime);
992 }
993 
994 /* deprecated. Always returns 0 and outSupport holds true. Don't call. */
995 static inline int native_window_get_wide_color_support (
996     struct ANativeWindow* window __UNUSED, bool* outSupport) __deprecated;
997 
998 /*
999    Deprecated(b/242763577): to be removed, this method should not be used
1000    Surface support should not be tied to the display
1001    Return true since most displays should have this support
1002 */
native_window_get_wide_color_support(struct ANativeWindow * window __UNUSED,bool * outSupport)1003 static inline int native_window_get_wide_color_support (
1004     struct ANativeWindow* window __UNUSED, bool* outSupport) {
1005     *outSupport = true;
1006     return 0;
1007 }
1008 
1009 /* deprecated. Always returns 0 and outSupport holds true. Don't call. */
1010 static inline int native_window_get_hdr_support(struct ANativeWindow* window __UNUSED,
1011                                                 bool* outSupport) __deprecated;
1012 
1013 /*
1014    Deprecated(b/242763577): to be removed, this method should not be used
1015    Surface support should not be tied to the display
1016    Return true since most displays should have this support
1017 */
native_window_get_hdr_support(struct ANativeWindow * window __UNUSED,bool * outSupport)1018 static inline int native_window_get_hdr_support(struct ANativeWindow* window __UNUSED,
1019                                                 bool* outSupport) {
1020     *outSupport = true;
1021     return 0;
1022 }
1023 
native_window_get_consumer_usage(struct ANativeWindow * window,uint64_t * outUsage)1024 static inline int native_window_get_consumer_usage(struct ANativeWindow* window,
1025                                                    uint64_t* outUsage) {
1026     return window->perform(window, NATIVE_WINDOW_GET_CONSUMER_USAGE64, outUsage);
1027 }
1028 
1029 /*
1030  * native_window_set_auto_prerotation(..., autoPrerotation)
1031  * Enable/disable the auto prerotation at buffer allocation when the buffer size
1032  * is driven by the consumer.
1033  *
1034  * When buffer size is driven by the consumer and the transform hint specifies
1035  * a 90 or 270 degree rotation, if auto prerotation is enabled, the width and
1036  * height used for dequeueBuffer will be additionally swapped.
1037  */
native_window_set_auto_prerotation(struct ANativeWindow * window,bool autoPrerotation)1038 static inline int native_window_set_auto_prerotation(struct ANativeWindow* window,
1039                                                      bool autoPrerotation) {
1040     return window->perform(window, NATIVE_WINDOW_SET_AUTO_PREROTATION, autoPrerotation);
1041 }
1042 
1043 /*
1044  * Internal extension of ANativeWindow_FrameRateCompatibility.
1045  */
1046 enum {
1047     /**
1048      * This surface belongs to an app on the High Refresh Rate Deny list, and needs the display
1049      * to operate at the exact frame rate.
1050      *
1051      * Keep in sync with Surface.java constant.
1052      */
1053     ANATIVEWINDOW_FRAME_RATE_EXACT = 100,
1054 
1055     /**
1056      * This surface is ignored while choosing the refresh rate.
1057      */
1058     ANATIVEWINDOW_FRAME_RATE_NO_VOTE,
1059 
1060     /**
1061      * This surface will vote for the minimum refresh rate.
1062      */
1063     ANATIVEWINDOW_FRAME_RATE_MIN,
1064 
1065     /**
1066      * The surface requests a frame rate that is greater than or equal to `frameRate`.
1067      */
1068     ANATIVEWINDOW_FRAME_RATE_GTE
1069 };
1070 
1071 /*
1072  * Frame rate category values that can be used in Transaction::setFrameRateCategory.
1073  */
1074 enum {
1075     /**
1076      * Default value. This value can also be set to return to default behavior, such as layers
1077      * without animations.
1078      */
1079     ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT = 0,
1080 
1081     /**
1082      * The layer will explicitly not influence the frame rate.
1083      * This may indicate a frame rate suitable for no animation updates (such as a cursor blinking
1084      * or a sporadic update).
1085      */
1086     ANATIVEWINDOW_FRAME_RATE_CATEGORY_NO_PREFERENCE = 1,
1087 
1088     /**
1089      * Indicates a frame rate suitable for animations that looks fine even if played at a low frame
1090      * rate.
1091      */
1092     ANATIVEWINDOW_FRAME_RATE_CATEGORY_LOW = 2,
1093 
1094     /**
1095      * Indicates a middle frame rate suitable for animations that do not require higher frame
1096      * rates, or do not benefit from high smoothness. This is normally 60 Hz or close to it.
1097      */
1098     ANATIVEWINDOW_FRAME_RATE_CATEGORY_NORMAL = 3,
1099 
1100     /**
1101      * Indicates that, as a result of a user interaction, an animation is likely to start.
1102      * This category is a signal that a user interaction heuristic determined the need of a
1103      * high refresh rate, and is not an explicit request from the app.
1104      * As opposed to FRAME_RATE_CATEGORY_HIGH, this vote may be ignored in favor of
1105      * more explicit votes.
1106      */
1107     ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH_HINT = 4,
1108 
1109     /**
1110      * Indicates a frame rate suitable for animations that require a high frame rate, which may
1111      * increase smoothness but may also increase power usage.
1112      */
1113     ANATIVEWINDOW_FRAME_RATE_CATEGORY_HIGH = 5
1114 };
1115 
1116 /*
1117  * Frame rate selection strategy values that can be used in
1118  * Transaction::setFrameRateSelectionStrategy.
1119  */
1120 enum {
1121     /**
1122      * Default value. The layer uses its own frame rate specifications, assuming it has any
1123      * specifications, instead of its parent's. If it does not have its own frame rate
1124      * specifications, it will try to use its parent's. It will propagate its specifications to any
1125      * descendants that do not have their own.
1126      *
1127      * However, FRAME_RATE_SELECTION_STRATEGY_OVERRIDE_CHILDREN on an ancestor layer
1128      * supersedes this behavior, meaning that this layer will inherit frame rate specifications
1129      * regardless of whether it has its own.
1130      */
1131     ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_PROPAGATE = 0,
1132 
1133     /**
1134      * The layer's frame rate specifications will propagate to and override those of its descendant
1135      * layers.
1136      *
1137      * The layer itself has the FRAME_RATE_SELECTION_STRATEGY_PROPAGATE behavior.
1138      * Thus, ancestor layer that also has the strategy
1139      * FRAME_RATE_SELECTION_STRATEGY_OVERRIDE_CHILDREN will override this layer's
1140      * frame rate specifications.
1141      */
1142     ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_OVERRIDE_CHILDREN = 1,
1143 
1144     /**
1145      * The layer's frame rate specifications will not propagate to its descendant
1146      * layers, even if the descendant layer has no frame rate specifications.
1147      * However, FRAME_RATE_SELECTION_STRATEGY_OVERRIDE_CHILDREN on an ancestor
1148      * layer supersedes this behavior.
1149      */
1150     ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_SELF = 2,
1151 };
1152 
native_window_set_frame_rate(struct ANativeWindow * window,float frameRate,int8_t compatibility,int8_t changeFrameRateStrategy)1153 static inline int native_window_set_frame_rate(struct ANativeWindow* window, float frameRate,
1154                                         int8_t compatibility, int8_t changeFrameRateStrategy) {
1155     return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate,
1156                            (int)compatibility, (int)changeFrameRateStrategy);
1157 }
1158 
1159 struct ANativeWindowFrameTimelineInfo {
1160     // Frame Id received from ANativeWindow_getNextFrameId.
1161     uint64_t frameNumber;
1162 
1163     // VsyncId received from the Choreographer callback that started this frame.
1164     int64_t frameTimelineVsyncId;
1165 
1166     // Input Event ID received from the input event that started this frame.
1167     int32_t inputEventId;
1168 
1169     // The time which this frame rendering started (i.e. when Choreographer callback actually run)
1170     int64_t startTimeNanos;
1171 
1172     // Whether or not to use the vsyncId to determine the refresh rate. Used for TextureView only.
1173     int32_t useForRefreshRateSelection;
1174 
1175     // The VsyncId of a frame that was not drawn and squashed into this frame.
1176     // Used for UI thread updates that were not picked up by RenderThread on time.
1177     int64_t skippedFrameVsyncId;
1178 
1179     // The start time of a frame that was not drawn and squashed into this frame.
1180     int64_t skippedFrameStartTimeNanos;
1181 };
1182 
native_window_set_frame_timeline_info(struct ANativeWindow * window,struct ANativeWindowFrameTimelineInfo frameTimelineInfo)1183 static inline int native_window_set_frame_timeline_info(
1184         struct ANativeWindow* window, struct ANativeWindowFrameTimelineInfo frameTimelineInfo) {
1185     return window->perform(window, NATIVE_WINDOW_SET_FRAME_TIMELINE_INFO, frameTimelineInfo);
1186 }
1187 
1188 /**
1189  * native_window_set_buffers_additional_options(..., ExtendableType* additionalOptions, size_t size)
1190  * All buffers dequeued after this call will have the additionalOptions specified.
1191  *
1192  * This must only be called after api_connect, otherwise NO_INIT is returned. The options are
1193  * cleared in api_disconnect & api_connect
1194  *
1195  * If IAllocator is not v2 or newer this method returns INVALID_OPERATION
1196  *
1197  * \return NO_ERROR on success.
1198  * \return NO_INIT if no api is connected
1199  * \return INVALID_OPERATION if additional option support is not available
1200  */
native_window_set_buffers_additional_options(struct ANativeWindow * window,const AHardwareBufferLongOptions * additionalOptions,size_t additionalOptionsSize)1201 static inline int native_window_set_buffers_additional_options(
1202         struct ANativeWindow* window, const AHardwareBufferLongOptions* additionalOptions,
1203         size_t additionalOptionsSize) {
1204     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_ADDITIONAL_OPTIONS, additionalOptions,
1205                            additionalOptionsSize);
1206 }
1207 
1208 // ------------------------------------------------------------------------------------------------
1209 // Candidates for APEX visibility
1210 // These functions are planned to be made stable for APEX modules, but have not
1211 // yet been stabilized to a specific api version.
1212 // ------------------------------------------------------------------------------------------------
1213 
1214 /**
1215  * Retrieves the last queued buffer for this window, along with the fence that
1216  * fires when the buffer is ready to be read, and the 4x4 coordinate
1217  * transform matrix that should be applied to the buffer's content. The
1218  * transform matrix is represented in column-major order.
1219  *
1220  * If there was no buffer previously queued, then outBuffer will be NULL and
1221  * the value of outFence will be -1.
1222  *
1223  * Note that if outBuffer is not NULL, then the caller will hold a reference
1224  * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release
1225  * when the buffer is no longer needed so that the system may reclaim the
1226  * buffer.
1227  *
1228  * \return NO_ERROR on success.
1229  * \return NO_MEMORY if there was insufficient memory.
1230  */
ANativeWindow_getLastQueuedBuffer(ANativeWindow * window,AHardwareBuffer ** outBuffer,int * outFence,float outTransformMatrix[16])1231 static inline int ANativeWindow_getLastQueuedBuffer(ANativeWindow* window,
1232                                                     AHardwareBuffer** outBuffer, int* outFence,
1233                                                     float outTransformMatrix[16]) {
1234     return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER, outBuffer, outFence,
1235                            outTransformMatrix);
1236 }
1237 
1238 /**
1239  * Retrieves the last queued buffer for this window, along with the fence that
1240  * fires when the buffer is ready to be read. The cropRect & transform should be applied to the
1241  * buffer's content.
1242  *
1243  * If there was no buffer previously queued, then outBuffer will be NULL and
1244  * the value of outFence will be -1.
1245  *
1246  * Note that if outBuffer is not NULL, then the caller will hold a reference
1247  * onto the buffer. Accordingly, the caller must call AHardwareBuffer_release
1248  * when the buffer is no longer needed so that the system may reclaim the
1249  * buffer.
1250  *
1251  * \return NO_ERROR on success.
1252  * \return NO_MEMORY if there was insufficient memory.
1253  * \return STATUS_UNKNOWN_TRANSACTION if this ANativeWindow doesn't support this method, callers
1254  *         should fall back to ANativeWindow_getLastQueuedBuffer instead.
1255  */
ANativeWindow_getLastQueuedBuffer2(ANativeWindow * window,AHardwareBuffer ** outBuffer,int * outFence,ARect * outCropRect,uint32_t * outTransform)1256 static inline int ANativeWindow_getLastQueuedBuffer2(ANativeWindow* window,
1257                                                      AHardwareBuffer** outBuffer, int* outFence,
1258                                                      ARect* outCropRect, uint32_t* outTransform) {
1259     return window->perform(window, NATIVE_WINDOW_GET_LAST_QUEUED_BUFFER2, outBuffer, outFence,
1260                            outCropRect, outTransform);
1261 }
1262 
1263 /**
1264  * Retrieves an identifier for the next frame to be queued by this window.
1265  *
1266  * Frame ids start at 1 and are incremented on each new frame until the underlying surface changes,
1267  * in which case the frame id is reset to 1.
1268  *
1269  * \return the next frame id (0 being uninitialized).
1270  */
ANativeWindow_getNextFrameId(ANativeWindow * window)1271 static inline uint64_t ANativeWindow_getNextFrameId(ANativeWindow* window) {
1272     uint64_t value;
1273     window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, &value);
1274     return value;
1275 }
1276 
1277 /**
1278  * Prototype of the function that an ANativeWindow implementation would call
1279  * when ANativeWindow_query is called.
1280  */
1281 typedef int (*ANativeWindow_queryFn)(const ANativeWindow* window, int what, int* value);
1282 
1283 /**
1284  * Prototype of the function that intercepts an invocation of
1285  * ANativeWindow_queryFn, along with a data pointer that's passed by the
1286  * caller who set the interceptor, as well as arguments that would be
1287  * passed to ANativeWindow_queryFn if it were to be called.
1288  */
1289 typedef int (*ANativeWindow_queryInterceptor)(const ANativeWindow* window,
1290                                                 ANativeWindow_queryFn perform, void* data,
1291                                                 int what, int* value);
1292 
1293 /**
1294  * Registers an interceptor for ANativeWindow_query. Instead of calling
1295  * the underlying query function, instead the provided interceptor is
1296  * called, which may optionally call the underlying query function. An
1297  * optional data pointer is also provided to side-channel additional arguments.
1298  *
1299  * Note that usage of this should only be used for specialized use-cases by
1300  * either the system partition or to Mainline modules. This should never be
1301  * exposed to NDK or LL-NDK.
1302  *
1303  * Returns NO_ERROR on success, -errno if registration failed.
1304  */
ANativeWindow_setQueryInterceptor(ANativeWindow * window,ANativeWindow_queryInterceptor interceptor,void * data)1305 static inline int ANativeWindow_setQueryInterceptor(ANativeWindow* window,
1306                                             ANativeWindow_queryInterceptor interceptor,
1307                                             void* data) {
1308     return window->perform(window, NATIVE_WINDOW_SET_QUERY_INTERCEPTOR, interceptor, data);
1309 }
1310 
1311 __END_DECLS
1312