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