• 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  * IMPORTANT:
19  *
20  * There is an old copy of this file in system/core/include/system/window.h, which exists only
21  * for backward source compatibility.
22  * But there are binaries out there as well, so this version of window.h must stay binary
23  * backward compatible with the one found in system/core.
24  *
25  *
26  * Source compatibility is also required for now, because this is how we're handling the
27  * transition from system/core/include (global include path) to nativewindow/include.
28  *
29  *************************************************************************************************/
30 #pragma once
31 #include <cutils/native_handle.h>
32 #include <errno.h>
33 #include <limits.h>
34 #include <stdint.h>
35 #include <string.h>
36 #include <sys/cdefs.h>
37 #include <system/graphics.h>
38 #include <unistd.h>
39 #include <stdbool.h>
40 // system/window.h is a superset of the vndk
41 #include <vndk/window.h>
42 #ifndef __UNUSED
43 #define __UNUSED __attribute__((__unused__))
44 #endif
45 #ifndef __deprecated
46 #define __deprecated __attribute__((__deprecated__))
47 #endif
48 __BEGIN_DECLS
49 /*****************************************************************************/
50 #define ANDROID_NATIVE_WINDOW_MAGIC     ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
51 // ---------------------------------------------------------------------------
52 /* attributes queriable with query() */
53 enum {
54     NATIVE_WINDOW_WIDTH     = 0,
55     NATIVE_WINDOW_HEIGHT    = 1,
56     NATIVE_WINDOW_FORMAT    = 2,
57     /* see ANativeWindowQuery in vndk/window.h */
58     NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS,
59     /* Check whether queueBuffer operations on the ANativeWindow send the buffer
60      * to the window compositor.  The query sets the returned 'value' argument
61      * to 1 if the ANativeWindow DOES send queued buffers directly to the window
62      * compositor and 0 if the buffers do not go directly to the window
63      * compositor.
64      *
65      * This can be used to determine whether protected buffer content should be
66      * sent to the ANativeWindow.  Note, however, that a result of 1 does NOT
67      * indicate that queued buffers will be protected from applications or users
68      * capturing their contents.  If that behavior is desired then some other
69      * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
70      * conjunction with this query.
71      */
72     NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
73     /* Get the concrete type of a ANativeWindow.  See below for the list of
74      * possible return values.
75      *
76      * This query should not be used outside the Android framework and will
77      * likely be removed in the near future.
78      */
79     NATIVE_WINDOW_CONCRETE_TYPE = 5,
80     /*
81      * Default width and height of ANativeWindow buffers, these are the
82      * dimensions of the window buffers irrespective of the
83      * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window
84      * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
85      */
86     NATIVE_WINDOW_DEFAULT_WIDTH = ANATIVEWINDOW_QUERY_DEFAULT_WIDTH,
87     NATIVE_WINDOW_DEFAULT_HEIGHT = ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT,
88     /* see ANativeWindowQuery in vndk/window.h */
89     NATIVE_WINDOW_TRANSFORM_HINT = ANATIVEWINDOW_QUERY_TRANSFORM_HINT,
90     /*
91      * Boolean that indicates whether the consumer is running more than
92      * one buffer behind the producer.
93      */
94     NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9,
95     /*
96      * The consumer gralloc usage bits currently set by the consumer.
97      * The values are defined in hardware/libhardware/include/gralloc.h.
98      */
99     NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10, /* deprecated */
100     /**
101      * Transformation that will by applied to buffers by the hwcomposer.
102      * This must not be set or checked by producer endpoints, and will
103      * disable the transform hint set in SurfaceFlinger (see
104      * NATIVE_WINDOW_TRANSFORM_HINT).
105      *
106      * INTENDED USE:
107      * Temporary - Please do not use this.  This is intended only to be used
108      * by the camera's LEGACY mode.
109      *
110      * In situations where a SurfaceFlinger client wishes to set a transform
111      * that is not visible to the producer, and will always be applied in the
112      * hardware composer, the client can set this flag with
113      * native_window_set_buffers_sticky_transform.  This can be used to rotate
114      * and flip buffers consumed by hardware composer without actually changing
115      * the aspect ratio of the buffers produced.
116      */
117     NATIVE_WINDOW_STICKY_TRANSFORM = 11,
118     /**
119      * The default data space for the buffers as set by the consumer.
120      * The values are defined in graphics.h.
121      */
122     NATIVE_WINDOW_DEFAULT_DATASPACE = 12,
123     /* see ANativeWindowQuery in vndk/window.h */
124     NATIVE_WINDOW_BUFFER_AGE = ANATIVEWINDOW_QUERY_BUFFER_AGE,
125     /*
126      * Returns the duration of the last dequeueBuffer call in microseconds
127      */
128     NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
129     /*
130      * Returns the duration of the last queueBuffer call in microseconds
131      */
132     NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
133     /*
134      * Returns the number of image layers that the ANativeWindow buffer
135      * contains. By default this is 1, unless a buffer is explicitly allocated
136      * to contain multiple layers.
137      */
138     NATIVE_WINDOW_LAYER_COUNT = 16,
139     /*
140      * Returns 1 if the native window is valid, 0 otherwise. native window is valid
141      * if it is safe (i.e. no crash will occur) to call any method on it.
142      */
143     NATIVE_WINDOW_IS_VALID = 17,
144     /*
145      * Returns 1 if NATIVE_WINDOW_GET_FRAME_TIMESTAMPS will return display
146      * present info, 0 if it won't.
147      */
148     NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18,
149     /*
150      * The consumer end is capable of handling protected buffers, i.e. buffer
151      * with GRALLOC_USAGE_PROTECTED usage bits on.
152      */
153     NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19,
154     /*
155      * Returns data space for the buffers.
156      */
157     NATIVE_WINDOW_DATASPACE = 20,
158     /*
159      * Returns maxBufferCount set by BufferQueueConsumer
160      */
161     NATIVE_WINDOW_MAX_BUFFER_COUNT = 21,
162 };
163 /* Valid operations for the (*perform)() hook.
164  *
165  * Values marked as 'deprecated' are supported, but have been superceded by
166  * other functionality.
167  *
168  * Values marked as 'private' should be considered private to the framework.
169  * HAL implementation code with access to an ANativeWindow should not use these,
170  * as it may not interact properly with the framework's use of the
171  * ANativeWindow.
172  */
173 enum {
174 // clang-format off
175     NATIVE_WINDOW_SET_USAGE                     =  0,   /* deprecated */
176     NATIVE_WINDOW_CONNECT                       =  1,   /* deprecated */
177     NATIVE_WINDOW_DISCONNECT                    =  2,   /* deprecated */
178     NATIVE_WINDOW_SET_CROP                      =  3,   /* private */
179     NATIVE_WINDOW_SET_BUFFER_COUNT              =  4,
180     NATIVE_WINDOW_SET_BUFFERS_GEOMETRY          =  5,   /* deprecated */
181     NATIVE_WINDOW_SET_BUFFERS_TRANSFORM         =  6,
182     NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP         =  7,
183     NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS        =  8,
184     NATIVE_WINDOW_SET_BUFFERS_FORMAT            =  9,
185     NATIVE_WINDOW_SET_SCALING_MODE              = 10,   /* private */
186     NATIVE_WINDOW_LOCK                          = 11,   /* private */
187     NATIVE_WINDOW_UNLOCK_AND_POST               = 12,   /* private */
188     NATIVE_WINDOW_API_CONNECT                   = 13,   /* private */
189     NATIVE_WINDOW_API_DISCONNECT                = 14,   /* private */
190     NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS   = 15,   /* private */
191     NATIVE_WINDOW_SET_POST_TRANSFORM_CROP       = 16,   /* deprecated, unimplemented */
192     NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM  = 17,   /* private */
193     NATIVE_WINDOW_SET_SIDEBAND_STREAM           = 18,
194     NATIVE_WINDOW_SET_BUFFERS_DATASPACE         = 19,
195     NATIVE_WINDOW_SET_SURFACE_DAMAGE            = 20,   /* private */
196     NATIVE_WINDOW_SET_SHARED_BUFFER_MODE        = 21,
197     NATIVE_WINDOW_SET_AUTO_REFRESH              = 22,
198     NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION    = 23,
199     NATIVE_WINDOW_GET_NEXT_FRAME_ID             = 24,
200     NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS       = 25,
201     NATIVE_WINDOW_GET_COMPOSITOR_TIMING         = 26,
202     NATIVE_WINDOW_GET_FRAME_TIMESTAMPS          = 27,
203     NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT        = 28,
204     NATIVE_WINDOW_GET_HDR_SUPPORT               = 29,
205     NATIVE_WINDOW_SET_USAGE64                   = 30,
206     NATIVE_WINDOW_GET_CONSUMER_USAGE64          = 31,
207     NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA = 32,
208     NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA = 33,
209 // clang-format on
210 };
211 /* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
212 enum {
213     /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
214      * OpenGL ES.
215      */
216     NATIVE_WINDOW_API_EGL = 1,
217     /* Buffers will be queued after being filled using the CPU
218      */
219     NATIVE_WINDOW_API_CPU = 2,
220     /* Buffers will be queued by Stagefright after being filled by a video
221      * decoder.  The video decoder can either be a software or hardware decoder.
222      */
223     NATIVE_WINDOW_API_MEDIA = 3,
224     /* Buffers will be queued by the the camera HAL.
225      */
226     NATIVE_WINDOW_API_CAMERA = 4,
227 };
228 /* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
229 enum {
230     /* flip source image horizontally */
231     NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
232     /* flip source image vertically */
233     NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
234     /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
235     NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
236     /* rotate source image 180 degrees */
237     NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
238     /* rotate source image 270 degrees clock-wise */
239     NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
240     /* transforms source by the inverse transform of the screen it is displayed onto. This
241      * transform is applied last */
242     NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
243 };
244 /* parameter for NATIVE_WINDOW_SET_SCALING_MODE
245  * keep in sync with Surface.java in frameworks/base */
246 enum {
247     /* the window content is not updated (frozen) until a buffer of
248      * the window size is received (enqueued)
249      */
250     NATIVE_WINDOW_SCALING_MODE_FREEZE           = 0,
251     /* the buffer is scaled in both dimensions to match the window size */
252     NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW  = 1,
253     /* the buffer is scaled uniformly such that the smaller dimension
254      * of the buffer matches the window size (cropping in the process)
255      */
256     NATIVE_WINDOW_SCALING_MODE_SCALE_CROP       = 2,
257     /* the window is clipped to the size of the buffer's crop rectangle; pixels
258      * outside the crop rectangle are treated as if they are completely
259      * transparent.
260      */
261     NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP    = 3,
262 };
263 /* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
264 enum {
265     NATIVE_WINDOW_FRAMEBUFFER               = 0, /* FramebufferNativeWindow */
266     NATIVE_WINDOW_SURFACE                   = 1, /* Surface */
267 };
268 /* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
269  *
270  * Special timestamp value to indicate that timestamps should be auto-generated
271  * by the native window when queueBuffer is called.  This is equal to INT64_MIN,
272  * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
273  */
274 static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
275 /* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS
276  *
277  * Special timestamp value to indicate the timestamps aren't yet known or
278  * that they are invalid.
279  */
280 static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2;
281 static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1;
282 struct ANativeWindow
283 {
284 #ifdef __cplusplus
ANativeWindowANativeWindow285     ANativeWindow()
286         : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
287     {
288         common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
289         common.version = sizeof(ANativeWindow);
290         memset(common.reserved, 0, sizeof(common.reserved));
291     }
292     /* Implement the methods that sp<ANativeWindow> expects so that it
293        can be used to automatically refcount ANativeWindow's. */
incStrongANativeWindow294     void incStrong(const void* /*id*/) const {
295         common.incRef(const_cast<android_native_base_t*>(&common));
296     }
decStrongANativeWindow297     void decStrong(const void* /*id*/) const {
298         common.decRef(const_cast<android_native_base_t*>(&common));
299     }
300 #endif
301     struct android_native_base_t common;
302     /* flags describing some attributes of this surface or its updater */
303     const uint32_t flags;
304     /* min swap interval supported by this updated */
305     const int   minSwapInterval;
306     /* max swap interval supported by this updated */
307     const int   maxSwapInterval;
308     /* horizontal and vertical resolution in DPI */
309     const float xdpi;
310     const float ydpi;
311     /* Some storage reserved for the OEM's driver. */
312     intptr_t    oem[4];
313     /*
314      * Set the swap interval for this surface.
315      *
316      * Returns 0 on success or -errno on error.
317      */
318     int     (*setSwapInterval)(struct ANativeWindow* window,
319                 int interval);
320     /*
321      * Hook called by EGL to acquire a buffer. After this call, the buffer
322      * is not locked, so its content cannot be modified. This call may block if
323      * no buffers are available.
324      *
325      * The window holds a reference to the buffer between dequeueBuffer and
326      * either queueBuffer or cancelBuffer, so clients only need their own
327      * reference if they might use the buffer after queueing or canceling it.
328      * Holding a reference to a buffer after queueing or canceling it is only
329      * allowed if a specific buffer count has been set.
330      *
331      * Returns 0 on success or -errno on error.
332      *
333      * XXX: This function is deprecated.  It will continue to work for some
334      * time for binary compatibility, but the new dequeueBuffer function that
335      * outputs a fence file descriptor should be used in its place.
336      */
337     int     (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
338                 struct ANativeWindowBuffer** buffer);
339     /*
340      * hook called by EGL to lock a buffer. This MUST be called before modifying
341      * the content of a buffer. The buffer must have been acquired with
342      * dequeueBuffer first.
343      *
344      * Returns 0 on success or -errno on error.
345      *
346      * XXX: This function is deprecated.  It will continue to work for some
347      * time for binary compatibility, but it is essentially a no-op, and calls
348      * to it should be removed.
349      */
350     int     (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
351                 struct ANativeWindowBuffer* buffer);
352     /*
353      * Hook called by EGL when modifications to the render buffer are done.
354      * This unlocks and post the buffer.
355      *
356      * The window holds a reference to the buffer between dequeueBuffer and
357      * either queueBuffer or cancelBuffer, so clients only need their own
358      * reference if they might use the buffer after queueing or canceling it.
359      * Holding a reference to a buffer after queueing or canceling it is only
360      * allowed if a specific buffer count has been set.
361      *
362      * Buffers MUST be queued in the same order than they were dequeued.
363      *
364      * Returns 0 on success or -errno on error.
365      *
366      * XXX: This function is deprecated.  It will continue to work for some
367      * time for binary compatibility, but the new queueBuffer function that
368      * takes a fence file descriptor should be used in its place (pass a value
369      * of -1 for the fence file descriptor if there is no valid one to pass).
370      */
371     int     (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
372                 struct ANativeWindowBuffer* buffer);
373     /*
374      * hook used to retrieve information about the native window.
375      *
376      * Returns 0 on success or -errno on error.
377      */
378     int     (*query)(const struct ANativeWindow* window,
379                 int what, int* value);
380     /*
381      * hook used to perform various operations on the surface.
382      * (*perform)() is a generic mechanism to add functionality to
383      * ANativeWindow while keeping backward binary compatibility.
384      *
385      * DO NOT CALL THIS HOOK DIRECTLY.  Instead, use the helper functions
386      * defined below.
387      *
388      * (*perform)() returns -ENOENT if the 'what' parameter is not supported
389      * by the surface's implementation.
390      *
391      * See above for a list of valid operations, such as
392      * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
393      */
394     int     (*perform)(struct ANativeWindow* window,
395                 int operation, ... );
396     /*
397      * Hook used to cancel a buffer that has been dequeued.
398      * No synchronization is performed between dequeue() and cancel(), so
399      * either external synchronization is needed, or these functions must be
400      * called from the same thread.
401      *
402      * The window holds a reference to the buffer between dequeueBuffer and
403      * either queueBuffer or cancelBuffer, so clients only need their own
404      * reference if they might use the buffer after queueing or canceling it.
405      * Holding a reference to a buffer after queueing or canceling it is only
406      * allowed if a specific buffer count has been set.
407      *
408      * XXX: This function is deprecated.  It will continue to work for some
409      * time for binary compatibility, but the new cancelBuffer function that
410      * takes a fence file descriptor should be used in its place (pass a value
411      * of -1 for the fence file descriptor if there is no valid one to pass).
412      */
413     int     (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
414                 struct ANativeWindowBuffer* buffer);
415     /*
416      * Hook called by EGL to acquire a buffer. This call may block if no
417      * buffers are available.
418      *
419      * The window holds a reference to the buffer between dequeueBuffer and
420      * either queueBuffer or cancelBuffer, so clients only need their own
421      * reference if they might use the buffer after queueing or canceling it.
422      * Holding a reference to a buffer after queueing or canceling it is only
423      * allowed if a specific buffer count has been set.
424      *
425      * The libsync fence file descriptor returned in the int pointed to by the
426      * fenceFd argument will refer to the fence that must signal before the
427      * dequeued buffer may be written to.  A value of -1 indicates that the
428      * caller may access the buffer immediately without waiting on a fence.  If
429      * a valid file descriptor is returned (i.e. any value except -1) then the
430      * caller is responsible for closing the file descriptor.
431      *
432      * Returns 0 on success or -errno on error.
433      */
434     int     (*dequeueBuffer)(struct ANativeWindow* window,
435                 struct ANativeWindowBuffer** buffer, int* fenceFd);
436     /*
437      * Hook called by EGL when modifications to the render buffer are done.
438      * This unlocks and post the buffer.
439      *
440      * The window holds a reference to the buffer between dequeueBuffer and
441      * either queueBuffer or cancelBuffer, so clients only need their own
442      * reference if they might use the buffer after queueing or canceling it.
443      * Holding a reference to a buffer after queueing or canceling it is only
444      * allowed if a specific buffer count has been set.
445      *
446      * The fenceFd argument specifies a libsync fence file descriptor for a
447      * fence that must signal before the buffer can be accessed.  If the buffer
448      * can be accessed immediately then a value of -1 should be used.  The
449      * caller must not use the file descriptor after it is passed to
450      * queueBuffer, and the ANativeWindow implementation is responsible for
451      * closing it.
452      *
453      * Returns 0 on success or -errno on error.
454      */
455     int     (*queueBuffer)(struct ANativeWindow* window,
456                 struct ANativeWindowBuffer* buffer, int fenceFd);
457     /*
458      * Hook used to cancel a buffer that has been dequeued.
459      * No synchronization is performed between dequeue() and cancel(), so
460      * either external synchronization is needed, or these functions must be
461      * called from the same thread.
462      *
463      * The window holds a reference to the buffer between dequeueBuffer and
464      * either queueBuffer or cancelBuffer, so clients only need their own
465      * reference if they might use the buffer after queueing or canceling it.
466      * Holding a reference to a buffer after queueing or canceling it is only
467      * allowed if a specific buffer count has been set.
468      *
469      * The fenceFd argument specifies a libsync fence file decsriptor for a
470      * fence that must signal before the buffer can be accessed.  If the buffer
471      * can be accessed immediately then a value of -1 should be used.
472      *
473      * Note that if the client has not waited on the fence that was returned
474      * from dequeueBuffer, that same fence should be passed to cancelBuffer to
475      * ensure that future uses of the buffer are preceded by a wait on that
476      * fence.  The caller must not use the file descriptor after it is passed
477      * to cancelBuffer, and the ANativeWindow implementation is responsible for
478      * closing it.
479      *
480      * Returns 0 on success or -errno on error.
481      */
482     int     (*cancelBuffer)(struct ANativeWindow* window,
483                 struct ANativeWindowBuffer* buffer, int fenceFd);
484 };
485  /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
486   * android_native_window_t is deprecated.
487   */
488 typedef struct ANativeWindow android_native_window_t __deprecated;
489 /*
490  *  native_window_set_usage64(..., usage)
491  *  Sets the intended usage flags for the next buffers
492  *  acquired with (*lockBuffer)() and on.
493  *
494  *  Valid usage flags are defined in android/hardware_buffer.h
495  *  All AHARDWAREBUFFER_USAGE_* flags can be specified as needed.
496  *
497  *  Calling this function will usually cause following buffers to be
498  *  reallocated.
499  */
native_window_set_usage(struct ANativeWindow * window,uint64_t usage)500 static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) {
501     return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage);
502 }
503 /* deprecated. Always returns 0. Don't call. */
504 static inline int native_window_connect(
505         struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
native_window_connect(struct ANativeWindow * window __UNUSED,int api __UNUSED)506 static inline int native_window_connect(
507         struct ANativeWindow* window __UNUSED, int api __UNUSED) {
508     return 0;
509 }
510 /* deprecated. Always returns 0. Don't call. */
511 static inline int native_window_disconnect(
512         struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
native_window_disconnect(struct ANativeWindow * window __UNUSED,int api __UNUSED)513 static inline int native_window_disconnect(
514         struct ANativeWindow* window __UNUSED, int api __UNUSED) {
515     return 0;
516 }
517 /*
518  * native_window_set_crop(..., crop)
519  * Sets which region of the next queued buffers needs to be considered.
520  * Depending on the scaling mode, a buffer's crop region is scaled and/or
521  * cropped to match the surface's size.  This function sets the crop in
522  * pre-transformed buffer pixel coordinates.
523  *
524  * The specified crop region applies to all buffers queued after it is called.
525  *
526  * If 'crop' is NULL, subsequently queued buffers won't be cropped.
527  *
528  * An error is returned if for instance the crop region is invalid, out of the
529  * buffer's bound or if the window is invalid.
530  */
native_window_set_crop(struct ANativeWindow * window,android_native_rect_t const * crop)531 static inline int native_window_set_crop(
532         struct ANativeWindow* window,
533         android_native_rect_t const * crop)
534 {
535     return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
536 }
537 /*
538  * native_window_set_buffer_count(..., count)
539  * Sets the number of buffers associated with this native window.
540  */
native_window_set_buffer_count(struct ANativeWindow * window,size_t bufferCount)541 static inline int native_window_set_buffer_count(
542         struct ANativeWindow* window,
543         size_t bufferCount)
544 {
545     return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
546 }
547 /*
548  * native_window_set_buffers_geometry(..., int w, int h, int format)
549  * All buffers dequeued after this call will have the dimensions and format
550  * specified.  A successful call to this function has the same effect as calling
551  * native_window_set_buffers_size and native_window_set_buffers_format.
552  *
553  * XXX: This function is deprecated.  The native_window_set_buffers_dimensions
554  * and native_window_set_buffers_format functions should be used instead.
555  */
556 static inline int native_window_set_buffers_geometry(
557         struct ANativeWindow* window,
558         int w, int h, int format) __deprecated;
native_window_set_buffers_geometry(struct ANativeWindow * window,int w,int h,int format)559 static inline int native_window_set_buffers_geometry(
560         struct ANativeWindow* window,
561         int w, int h, int format)
562 {
563     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
564             w, h, format);
565 }
566 /*
567  * native_window_set_buffers_dimensions(..., int w, int h)
568  * All buffers dequeued after this call will have the dimensions specified.
569  * In particular, all buffers will have a fixed-size, independent from the
570  * native-window size. They will be scaled according to the scaling mode
571  * (see native_window_set_scaling_mode) upon window composition.
572  *
573  * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
574  * following this call will be sized to match the window's size.
575  *
576  * Calling this function will reset the window crop to a NULL value, which
577  * disables cropping of the buffers.
578  */
native_window_set_buffers_dimensions(struct ANativeWindow * window,int w,int h)579 static inline int native_window_set_buffers_dimensions(
580         struct ANativeWindow* window,
581         int w, int h)
582 {
583     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
584             w, h);
585 }
586 /*
587  * native_window_set_buffers_user_dimensions(..., int w, int h)
588  *
589  * Sets the user buffer size for the window, which overrides the
590  * window's size.  All buffers dequeued after this call will have the
591  * dimensions specified unless overridden by
592  * native_window_set_buffers_dimensions.  All buffers will have a
593  * fixed-size, independent from the native-window size. They will be
594  * scaled according to the scaling mode (see
595  * native_window_set_scaling_mode) upon window composition.
596  *
597  * If w and h are 0, the normal behavior is restored. That is, the
598  * default buffer size will match the windows's size.
599  *
600  * Calling this function will reset the window crop to a NULL value, which
601  * disables cropping of the buffers.
602  */
native_window_set_buffers_user_dimensions(struct ANativeWindow * window,int w,int h)603 static inline int native_window_set_buffers_user_dimensions(
604         struct ANativeWindow* window,
605         int w, int h)
606 {
607     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
608             w, h);
609 }
610 /*
611  * native_window_set_buffers_format(..., int format)
612  * All buffers dequeued after this call will have the format specified.
613  *
614  * If the specified format is 0, the default buffer format will be used.
615  */
native_window_set_buffers_format(struct ANativeWindow * window,int format)616 static inline int native_window_set_buffers_format(
617         struct ANativeWindow* window,
618         int format)
619 {
620     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
621 }
622 /*
623  * native_window_set_buffers_data_space(..., int dataSpace)
624  * All buffers queued after this call will be associated with the dataSpace
625  * parameter specified.
626  *
627  * dataSpace specifies additional information about the buffer that's dependent
628  * on the buffer format and the endpoints. For example, it can be used to convey
629  * the color space of the image data in the buffer, or it can be used to
630  * indicate that the buffers contain depth measurement data instead of color
631  * images.  The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
632  * overridden by the consumer.
633  */
native_window_set_buffers_data_space(struct ANativeWindow * window,android_dataspace_t dataSpace)634 static inline int native_window_set_buffers_data_space(
635         struct ANativeWindow* window,
636         android_dataspace_t dataSpace)
637 {
638     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
639             dataSpace);
640 }
641 /*
642  * native_window_set_buffers_smpte2086_metadata(..., metadata)
643  * All buffers queued after this call will be associated with the SMPTE
644  * ST.2086 metadata specified.
645  *
646  * metadata specifies additional information about the contents of the buffer
647  * that may affect how it's displayed.  When it is nullptr, it means no such
648  * information is available.  No SMPTE ST.2086 metadata is associated with the
649  * buffers by default.
650  */
native_window_set_buffers_smpte2086_metadata(struct ANativeWindow * window,const struct android_smpte2086_metadata * metadata)651 static inline int native_window_set_buffers_smpte2086_metadata(
652         struct ANativeWindow* window,
653         const struct android_smpte2086_metadata* metadata)
654 {
655     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA,
656             metadata);
657 }
658 /*
659  * native_window_set_buffers_cta861_3_metadata(..., metadata)
660  * All buffers queued after this call will be associated with the CTA-861.3
661  * metadata specified.
662  *
663  * metadata specifies additional information about the contents of the buffer
664  * that may affect how it's displayed.  When it is nullptr, it means no such
665  * information is available.  No CTA-861.3 metadata is associated with the
666  * buffers by default.
667  */
native_window_set_buffers_cta861_3_metadata(struct ANativeWindow * window,const struct android_cta861_3_metadata * metadata)668 static inline int native_window_set_buffers_cta861_3_metadata(
669         struct ANativeWindow* window,
670         const struct android_cta861_3_metadata* metadata)
671 {
672     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA,
673             metadata);
674 }
675 /*
676  * native_window_set_buffers_transform(..., int transform)
677  * All buffers queued after this call will be displayed transformed according
678  * to the transform parameter specified.
679  */
native_window_set_buffers_transform(struct ANativeWindow * window,int transform)680 static inline int native_window_set_buffers_transform(
681         struct ANativeWindow* window,
682         int transform)
683 {
684     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
685             transform);
686 }
687 /*
688  * native_window_set_buffers_sticky_transform(..., int transform)
689  * All buffers queued after this call will be displayed transformed according
690  * to the transform parameter specified applied on top of the regular buffer
691  * transform.  Setting this transform will disable the transform hint.
692  *
693  * Temporary - This is only intended to be used by the LEGACY camera mode, do
694  *   not use this for anything else.
695  */
native_window_set_buffers_sticky_transform(struct ANativeWindow * window,int transform)696 static inline int native_window_set_buffers_sticky_transform(
697         struct ANativeWindow* window,
698         int transform)
699 {
700     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
701             transform);
702 }
703 /*
704  * native_window_set_buffers_timestamp(..., int64_t timestamp)
705  * All buffers queued after this call will be associated with the timestamp
706  * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
707  * (the default), timestamps will be generated automatically when queueBuffer is
708  * called. The timestamp is measured in nanoseconds, and is normally monotonically
709  * increasing. The timestamp should be unaffected by time-of-day adjustments,
710  * and for a camera should be strictly monotonic but for a media player may be
711  * reset when the position is set.
712  */
native_window_set_buffers_timestamp(struct ANativeWindow * window,int64_t timestamp)713 static inline int native_window_set_buffers_timestamp(
714         struct ANativeWindow* window,
715         int64_t timestamp)
716 {
717     return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
718             timestamp);
719 }
720 /*
721  * native_window_set_scaling_mode(..., int mode)
722  * All buffers queued after this call will be associated with the scaling mode
723  * specified.
724  */
native_window_set_scaling_mode(struct ANativeWindow * window,int mode)725 static inline int native_window_set_scaling_mode(
726         struct ANativeWindow* window,
727         int mode)
728 {
729     return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
730             mode);
731 }
732 /*
733  * native_window_api_connect(..., int api)
734  * connects an API to this window. only one API can be connected at a time.
735  * Returns -EINVAL if for some reason the window cannot be connected, which
736  * can happen if it's connected to some other API.
737  */
native_window_api_connect(struct ANativeWindow * window,int api)738 static inline int native_window_api_connect(
739         struct ANativeWindow* window, int api)
740 {
741     return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
742 }
743 /*
744  * native_window_api_disconnect(..., int api)
745  * disconnect the API from this window.
746  * An error is returned if for instance the window wasn't connected in the
747  * first place.
748  */
native_window_api_disconnect(struct ANativeWindow * window,int api)749 static inline int native_window_api_disconnect(
750         struct ANativeWindow* window, int api)
751 {
752     return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
753 }
754 /*
755  * native_window_dequeue_buffer_and_wait(...)
756  * Dequeue a buffer and wait on the fence associated with that buffer.  The
757  * buffer may safely be accessed immediately upon this function returning.  An
758  * error is returned if either of the dequeue or the wait operations fail.
759  */
native_window_dequeue_buffer_and_wait(ANativeWindow * anw,struct ANativeWindowBuffer ** anb)760 static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
761         struct ANativeWindowBuffer** anb) {
762     return anw->dequeueBuffer_DEPRECATED(anw, anb);
763 }
764 /*
765  * native_window_set_sideband_stream(..., native_handle_t*)
766  * Attach a sideband buffer stream to a native window.
767  */
native_window_set_sideband_stream(struct ANativeWindow * window,native_handle_t * sidebandHandle)768 static inline int native_window_set_sideband_stream(
769         struct ANativeWindow* window,
770         native_handle_t* sidebandHandle)
771 {
772     return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
773             sidebandHandle);
774 }
775 /*
776  * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
777  * Set the surface damage (i.e., the region of the surface that has changed
778  * since the previous frame). The damage set by this call will be reset (to the
779  * default of full-surface damage) after calling queue, so this must be called
780  * prior to every frame with damage that does not cover the whole surface if the
781  * caller desires downstream consumers to use this optimization.
782  *
783  * The damage region is specified as an array of rectangles, with the important
784  * caveat that the origin of the surface is considered to be the bottom-left
785  * corner, as in OpenGL ES.
786  *
787  * If numRects is set to 0, rects may be NULL, and the surface damage will be
788  * set to the full surface (the same as if this function had not been called for
789  * this frame).
790  */
native_window_set_surface_damage(struct ANativeWindow * window,const android_native_rect_t * rects,size_t numRects)791 static inline int native_window_set_surface_damage(
792         struct ANativeWindow* window,
793         const android_native_rect_t* rects, size_t numRects)
794 {
795     return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
796             rects, numRects);
797 }
798 /*
799  * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
800  * Enable/disable shared buffer mode
801  */
native_window_set_shared_buffer_mode(struct ANativeWindow * window,bool sharedBufferMode)802 static inline int native_window_set_shared_buffer_mode(
803         struct ANativeWindow* window,
804         bool sharedBufferMode)
805 {
806     return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
807             sharedBufferMode);
808 }
809 /*
810  * native_window_set_auto_refresh(..., autoRefresh)
811  * Enable/disable auto refresh when in shared buffer mode
812  */
native_window_set_auto_refresh(struct ANativeWindow * window,bool autoRefresh)813 static inline int native_window_set_auto_refresh(
814         struct ANativeWindow* window,
815         bool autoRefresh)
816 {
817     return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
818 }
native_window_get_refresh_cycle_duration(struct ANativeWindow * window,int64_t * outRefreshDuration)819 static inline int native_window_get_refresh_cycle_duration(
820         struct ANativeWindow* window,
821         int64_t* outRefreshDuration)
822 {
823     return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION,
824             outRefreshDuration);
825 }
native_window_get_next_frame_id(struct ANativeWindow * window,uint64_t * frameId)826 static inline int native_window_get_next_frame_id(
827         struct ANativeWindow* window, uint64_t* frameId)
828 {
829     return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId);
830 }
native_window_enable_frame_timestamps(struct ANativeWindow * window,bool enable)831 static inline int native_window_enable_frame_timestamps(
832         struct ANativeWindow* window, bool enable)
833 {
834     return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS,
835             enable);
836 }
native_window_get_compositor_timing(struct ANativeWindow * window,int64_t * compositeDeadline,int64_t * compositeInterval,int64_t * compositeToPresentLatency)837 static inline int native_window_get_compositor_timing(
838         struct ANativeWindow* window,
839         int64_t* compositeDeadline, int64_t* compositeInterval,
840         int64_t* compositeToPresentLatency)
841 {
842     return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING,
843             compositeDeadline, compositeInterval, compositeToPresentLatency);
844 }
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)845 static inline int native_window_get_frame_timestamps(
846         struct ANativeWindow* window, uint64_t frameId,
847         int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
848         int64_t* outLatchTime, int64_t* outFirstRefreshStartTime,
849         int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime,
850         int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime,
851         int64_t* outReleaseTime)
852 {
853     return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
854             frameId, outRequestedPresentTime, outAcquireTime, outLatchTime,
855             outFirstRefreshStartTime, outLastRefreshStartTime,
856             outGpuCompositionDoneTime, outDisplayPresentTime,
857             outDequeueReadyTime, outReleaseTime);
858 }
native_window_get_wide_color_support(struct ANativeWindow * window,bool * outSupport)859 static inline int native_window_get_wide_color_support(
860     struct ANativeWindow* window, bool* outSupport) {
861     return window->perform(window, NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT,
862             outSupport);
863 }
native_window_get_hdr_support(struct ANativeWindow * window,bool * outSupport)864 static inline int native_window_get_hdr_support(struct ANativeWindow* window,
865                                                 bool* outSupport) {
866     return window->perform(window, NATIVE_WINDOW_GET_HDR_SUPPORT, outSupport);
867 }
native_window_get_consumer_usage(struct ANativeWindow * window,uint64_t * outUsage)868 static inline int native_window_get_consumer_usage(struct ANativeWindow* window,
869                                                    uint64_t* outUsage) {
870     return window->perform(window, NATIVE_WINDOW_GET_CONSUMER_USAGE64, outUsage);
871 }
872 __END_DECLS