10529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
20529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Copyright (C) 2011 The Android Open Source Project
30529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
40529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Licensed under the Apache License, Version 2.0 (the "License");
50529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * you may not use this file except in compliance with the License.
60529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * You may obtain a copy of the License at
70529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
80529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *      http://www.apache.org/licenses/LICENSE-2.0
90529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Unless required by applicable law or agreed to in writing, software
110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * distributed under the License is distributed on an "AS IS" BASIS,
120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * See the License for the specific language governing permissions and
140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * limitations under the License.
150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#ifndef SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H
180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H
190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include <cutils/native_handle.h>
210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include <errno.h>
220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include <limits.h>
230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include <stdint.h>
240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include <string.h>
250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include <sys/cdefs.h>
260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include <system/graphics.h>
270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include <unistd.h>
280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch__BEGIN_DECLS
300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*****************************************************************************/
320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \
340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d))
350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define ANDROID_NATIVE_WINDOW_MAGIC \
370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define ANDROID_NATIVE_BUFFER_MAGIC \
400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// ---------------------------------------------------------------------------
430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// This #define may be used to conditionally compile device-specific code to
450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// support either the prior ANativeWindow interface, which did not pass libsync
460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// fences around, or the new interface that does.  This #define is only present
470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// when the ANativeWindow interface does include libsync support.
480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#define ANDROID_NATIVE_WINDOW_HAS_SYNC 1
490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// ---------------------------------------------------------------------------
510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochtypedef const native_handle_t* buffer_handle_t;
530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// ---------------------------------------------------------------------------
550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochtypedef struct android_native_rect_t
570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int32_t left;
590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int32_t top;
600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int32_t right;
610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int32_t bottom;
620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} android_native_rect_t;
630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// ---------------------------------------------------------------------------
650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochtypedef struct android_native_base_t
670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* a magic value defined by the actual EGL native type */
690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int magic;
700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* the sizeof() of the actual EGL native type */
720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int version;
730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    void* reserved[4];
750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* reference-counting interface */
770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    void (*incRef)(struct android_native_base_t* base);
780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    void (*decRef)(struct android_native_base_t* base);
790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} android_native_base_t;
800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochtypedef struct ANativeWindowBuffer
820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#ifdef __cplusplus
840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    ANativeWindowBuffer() {
850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        common.version = sizeof(ANativeWindowBuffer);
870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        memset(common.reserved, 0, sizeof(common.reserved));
880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    }
890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    // Implement the methods that sp<ANativeWindowBuffer> expects so that it
910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    // can be used to automatically refcount ANativeWindowBuffer's.
920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    void incStrong(const void* id) const {
930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        common.incRef(const_cast<android_native_base_t*>(&common));
940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    }
950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    void decStrong(const void* id) const {
960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        common.decRef(const_cast<android_native_base_t*>(&common));
970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    }
980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#endif
990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    struct android_native_base_t common;
1010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int width;
1030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int height;
1040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int stride;
1050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int format;
1060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int usage;
1070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    void* reserved[2];
1090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    buffer_handle_t handle;
1110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    void* reserved_proc[8];
1130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} ANativeWindowBuffer_t;
1140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Old typedef for backwards compatibility.
1160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochtypedef ANativeWindowBuffer_t android_native_buffer_t;
1170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// ---------------------------------------------------------------------------
1190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/* attributes queriable with query() */
1210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochenum {
1220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_WIDTH     = 0,
1230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_HEIGHT    = 1,
1240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_FORMAT    = 2,
1250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* The minimum number of buffers that must remain un-dequeued after a buffer
1270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * has been queued.  This value applies only if set_buffer_count was used to
1280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * override the number of buffers and if a buffer has since been queued.
1290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Users of the set_buffer_count ANativeWindow method should query this
1300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * value before calling set_buffer_count.  If it is necessary to have N
1310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * buffers simultaneously dequeued as part of the steady-state operation,
1320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * and this query returns M then N+M buffers should be requested via
1330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * native_window_set_buffer_count.
1340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
1350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Note that this value does NOT apply until a single buffer has been
1360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * queued.  In particular this means that it is possible to:
1370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
1380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 1. Query M = min undequeued buffers
1390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 2. Set the buffer count to N + M
1400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 3. Dequeue all N + M buffers
1410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 4. Cancel M buffers
1420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 5. Queue, dequeue, queue, dequeue, ad infinitum
1430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
1440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = 3,
1450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* Check whether queueBuffer operations on the ANativeWindow send the buffer
1470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * to the window compositor.  The query sets the returned 'value' argument
1480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * to 1 if the ANativeWindow DOES send queued buffers directly to the window
1490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * compositor and 0 if the buffers do not go directly to the window
1500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * compositor.
1510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
1520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * This can be used to determine whether protected buffer content should be
1530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * sent to the ANativeWindow.  Note, however, that a result of 1 does NOT
1540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * indicate that queued buffers will be protected from applications or users
1550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * capturing their contents.  If that behavior is desired then some other
1560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
1570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * conjunction with this query.
1580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
1590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
1600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* Get the concrete type of a ANativeWindow.  See below for the list of
1620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * possible return values.
1630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
1640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * This query should not be used outside the Android framework and will
1650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * likely be removed in the near future.
1660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
1670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_CONCRETE_TYPE = 5,
1680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
1710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Default width and height of ANativeWindow buffers, these are the
1720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * dimensions of the window buffers irrespective of the
1730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window
1740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
1750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
1760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_DEFAULT_WIDTH = 6,
1770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_DEFAULT_HEIGHT = 7,
1780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
1800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * transformation that will most-likely be applied to buffers. This is only
1810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * a hint, the actual transformation applied might be different.
1820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
1830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * INTENDED USE:
1840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
1850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The transform hint can be used by a producer, for instance the GLES
1860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * driver, to pre-rotate the rendering such that the final transformation
1870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * in the composer is identity. This can be very useful when used in
1880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * conjunction with the h/w composer HAL, in situations where it
1890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * cannot handle arbitrary rotations.
1900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
1910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 1. Before dequeuing a buffer, the GL driver (or any other ANW client)
1920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    queries the ANW for NATIVE_WINDOW_TRANSFORM_HINT.
1930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
1940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 2. The GL driver overrides the width and height of the ANW to
1950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    account for NATIVE_WINDOW_TRANSFORM_HINT. This is done by querying
1960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    NATIVE_WINDOW_DEFAULT_{WIDTH | HEIGHT}, swapping the dimensions
1970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    according to NATIVE_WINDOW_TRANSFORM_HINT and calling
1980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    native_window_set_buffers_dimensions().
1990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
2000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 3. The GL driver dequeues a buffer of the new pre-rotated size.
2010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
2020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 4. The GL driver renders to the buffer such that the image is
2030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    already transformed, that is applying NATIVE_WINDOW_TRANSFORM_HINT
2040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    to the rendering.
2050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
2060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 5. The GL driver calls native_window_set_transform to apply
2070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    inverse transformation to the buffer it just rendered.
2080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    In order to do this, the GL driver needs
2090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    to calculate the inverse of NATIVE_WINDOW_TRANSFORM_HINT, this is
2100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    done easily:
2110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
2120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *        int hintTransform, inverseTransform;
2130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *        query(..., NATIVE_WINDOW_TRANSFORM_HINT, &hintTransform);
2140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *        inverseTransform = hintTransform;
2150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *        if (hintTransform & HAL_TRANSFORM_ROT_90)
2160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *            inverseTransform ^= HAL_TRANSFORM_ROT_180;
2170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
2180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
2190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 6. The GL driver queues the pre-transformed buffer.
2200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
2210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * 7. The composer combines the buffer transform with the display
2220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    transform.  If the buffer transform happens to cancel out the
2230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *    display transform then no rotation is needed.
2240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
2250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
2260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_TRANSFORM_HINT = 8,
2270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
2280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
2290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Boolean that indicates whether the consumer is running more than
2300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * one buffer behind the producer.
2310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
2320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9,
2330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
2340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
2350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The consumer gralloc usage bits currently set by the consumer.
2360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The values are defined in hardware/libhardware/include/gralloc.h.
2370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
2380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10
2390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
2400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
2410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/* Valid operations for the (*perform)() hook.
2420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
2430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Values marked as 'deprecated' are supported, but have been superceded by
2440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * other functionality.
2450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
2460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Values marked as 'private' should be considered private to the framework.
2470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * HAL implementation code with access to an ANativeWindow should not use these,
2480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * as it may not interact properly with the framework's use of the
2490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * ANativeWindow.
2500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
2510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochenum {
2520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_USAGE                 =  0,
2530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_CONNECT                   =  1,   /* deprecated */
2540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_DISCONNECT                =  2,   /* deprecated */
2550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_CROP                  =  3,   /* private */
2560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_BUFFER_COUNT          =  4,
2570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_BUFFERS_GEOMETRY      =  5,   /* deprecated */
2580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_BUFFERS_TRANSFORM     =  6,
2590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP     =  7,
2600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS    =  8,
2610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_BUFFERS_FORMAT        =  9,
2620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_SCALING_MODE          = 10,   /* private */
2630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_LOCK                      = 11,   /* private */
2640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_UNLOCK_AND_POST           = 12,   /* private */
2650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_API_CONNECT               = 13,   /* private */
2660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_API_DISCONNECT            = 14,   /* private */
2670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
2680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SET_POST_TRANSFORM_CROP   = 16,   /* private */
2690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
2700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
2710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
2720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochenum {
2730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
2740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * OpenGL ES.
2750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
2760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_API_EGL = 1,
2770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
2780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* Buffers will be queued after being filled using the CPU
2790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
2800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_API_CPU = 2,
2810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
2820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* Buffers will be queued by Stagefright after being filled by a video
2830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * decoder.  The video decoder can either be a software or hardware decoder.
2840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
2850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_API_MEDIA = 3,
2860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
2870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* Buffers will be queued by the the camera HAL.
2880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
2890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_API_CAMERA = 4,
2900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
2910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
2920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
2930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochenum {
2940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* flip source image horizontally */
2950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
2960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* flip source image vertically */
2970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
2980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
2990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
3000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* rotate source image 180 degrees */
3010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
3020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* rotate source image 270 degrees clock-wise */
3030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
3040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* transforms source by the inverse transform of the screen it is displayed onto. This
3050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * transform is applied last */
3060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
3070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
3080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/* parameter for NATIVE_WINDOW_SET_SCALING_MODE */
3100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochenum {
3110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* the window content is not updated (frozen) until a buffer of
3120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * the window size is received (enqueued)
3130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
3140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SCALING_MODE_FREEZE           = 0,
3150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* the buffer is scaled in both dimensions to match the window size */
3160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW  = 1,
3170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* the buffer is scaled uniformly such that the smaller dimension
3180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * of the buffer matches the window size (cropping in the process)
3190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
3200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SCALING_MODE_SCALE_CROP       = 2,
3210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* the window is clipped to the size of the buffer's crop rectangle; pixels
3220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * outside the crop rectangle are treated as if they are completely
3230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * transparent.
3240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
3250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP    = 3,
3260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
3270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
3290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochenum {
3300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_FRAMEBUFFER               = 0, /* FramebufferNativeWindow */
3310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NATIVE_WINDOW_SURFACE                   = 1, /* Surface */
3320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
3330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
3350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
3360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Special timestamp value to indicate that timestamps should be auto-generated
3370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * by the native window when queueBuffer is called.  This is equal to INT64_MIN,
3380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
3390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
3400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
3410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstruct ANativeWindow
3430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
3440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#ifdef __cplusplus
3450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    ANativeWindow()
3460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
3470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    {
3480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
3490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        common.version = sizeof(ANativeWindow);
3500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        memset(common.reserved, 0, sizeof(common.reserved));
3510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    }
3520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* Implement the methods that sp<ANativeWindow> expects so that it
3540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch       can be used to automatically refcount ANativeWindow's. */
3550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    void incStrong(const void* id) const {
3560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        common.incRef(const_cast<android_native_base_t*>(&common));
3570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    }
3580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    void decStrong(const void* id) const {
3590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        common.decRef(const_cast<android_native_base_t*>(&common));
3600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    }
3610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#endif
3620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    struct android_native_base_t common;
3640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* flags describing some attributes of this surface or its updater */
3660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    const uint32_t flags;
3670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* min swap interval supported by this updated */
3690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    const int   minSwapInterval;
3700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* max swap interval supported by this updated */
3720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    const int   maxSwapInterval;
3730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* horizontal and vertical resolution in DPI */
3750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    const float xdpi;
3760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    const float ydpi;
3770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /* Some storage reserved for the OEM's driver. */
3790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    intptr_t    oem[4];
3800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
3820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Set the swap interval for this surface.
3830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
3840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Returns 0 on success or -errno on error.
3850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
3860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*setSwapInterval)(struct ANativeWindow* window,
3870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                int interval);
3880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
3890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
3900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Hook called by EGL to acquire a buffer. After this call, the buffer
3910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * is not locked, so its content cannot be modified. This call may block if
3920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * no buffers are available.
3930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
3940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The window holds a reference to the buffer between dequeueBuffer and
3950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * either queueBuffer or cancelBuffer, so clients only need their own
3960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * reference if they might use the buffer after queueing or canceling it.
3970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Holding a reference to a buffer after queueing or canceling it is only
3980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * allowed if a specific buffer count has been set.
3990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Returns 0 on success or -errno on error.
4010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * XXX: This function is deprecated.  It will continue to work for some
4030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * time for binary compatibility, but the new dequeueBuffer function that
4040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * outputs a fence file descriptor should be used in its place.
4050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
4060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
4070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                struct ANativeWindowBuffer** buffer);
4080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
4090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
4100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * hook called by EGL to lock a buffer. This MUST be called before modifying
4110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * the content of a buffer. The buffer must have been acquired with
4120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * dequeueBuffer first.
4130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Returns 0 on success or -errno on error.
4150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * XXX: This function is deprecated.  It will continue to work for some
4170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * time for binary compatibility, but it is essentially a no-op, and calls
4180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * to it should be removed.
4190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
4200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
4210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                struct ANativeWindowBuffer* buffer);
4220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
4230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
4240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Hook called by EGL when modifications to the render buffer are done.
4250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * This unlocks and post the buffer.
4260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The window holds a reference to the buffer between dequeueBuffer and
4280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * either queueBuffer or cancelBuffer, so clients only need their own
4290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * reference if they might use the buffer after queueing or canceling it.
4300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Holding a reference to a buffer after queueing or canceling it is only
4310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * allowed if a specific buffer count has been set.
4320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Buffers MUST be queued in the same order than they were dequeued.
4340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Returns 0 on success or -errno on error.
4360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * XXX: This function is deprecated.  It will continue to work for some
4380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * time for binary compatibility, but the new queueBuffer function that
4390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * takes a fence file descriptor should be used in its place (pass a value
4400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * of -1 for the fence file descriptor if there is no valid one to pass).
4410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
4420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
4430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                struct ANativeWindowBuffer* buffer);
4440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
4450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
4460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * hook used to retrieve information about the native window.
4470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Returns 0 on success or -errno on error.
4490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
4500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*query)(const struct ANativeWindow* window,
4510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                int what, int* value);
4520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
4530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
4540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * hook used to perform various operations on the surface.
4550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * (*perform)() is a generic mechanism to add functionality to
4560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * ANativeWindow while keeping backward binary compatibility.
4570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * DO NOT CALL THIS HOOK DIRECTLY.  Instead, use the helper functions
4590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * defined below.
4600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *  (*perform)() returns -ENOENT if the 'what' parameter is not supported
4620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *  by the surface's implementation.
4630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The valid operations are:
4650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_USAGE
4660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_CONNECT               (deprecated)
4670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_DISCONNECT            (deprecated)
4680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_CROP              (private)
4690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_BUFFER_COUNT
4700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_BUFFERS_GEOMETRY  (deprecated)
4710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_BUFFERS_TRANSFORM
4720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
4730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS
4740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_BUFFERS_FORMAT
4750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_SCALING_MODE       (private)
4760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_LOCK                   (private)
4770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_UNLOCK_AND_POST        (private)
4780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_API_CONNECT            (private)
4790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_API_DISCONNECT         (private)
4800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS (private)
4810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *     NATIVE_WINDOW_SET_POST_TRANSFORM_CROP (private)
4820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
4840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
4850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*perform)(struct ANativeWindow* window,
4860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                int operation, ... );
4870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
4880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
4890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Hook used to cancel a buffer that has been dequeued.
4900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * No synchronization is performed between dequeue() and cancel(), so
4910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * either external synchronization is needed, or these functions must be
4920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * called from the same thread.
4930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
4940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The window holds a reference to the buffer between dequeueBuffer and
4950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * either queueBuffer or cancelBuffer, so clients only need their own
4960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * reference if they might use the buffer after queueing or canceling it.
4970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Holding a reference to a buffer after queueing or canceling it is only
4980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * allowed if a specific buffer count has been set.
4990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * XXX: This function is deprecated.  It will continue to work for some
5010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * time for binary compatibility, but the new cancelBuffer function that
5020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * takes a fence file descriptor should be used in its place (pass a value
5030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * of -1 for the fence file descriptor if there is no valid one to pass).
5040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
5050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
5060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                struct ANativeWindowBuffer* buffer);
5070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
5080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
5090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Hook called by EGL to acquire a buffer. This call may block if no
5100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * buffers are available.
5110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The window holds a reference to the buffer between dequeueBuffer and
5130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * either queueBuffer or cancelBuffer, so clients only need their own
5140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * reference if they might use the buffer after queueing or canceling it.
5150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Holding a reference to a buffer after queueing or canceling it is only
5160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * allowed if a specific buffer count has been set.
5170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The libsync fence file descriptor returned in the int pointed to by the
5190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * fenceFd argument will refer to the fence that must signal before the
5200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * dequeued buffer may be written to.  A value of -1 indicates that the
5210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * caller may access the buffer immediately without waiting on a fence.  If
5220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * a valid file descriptor is returned (i.e. any value except -1) then the
5230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * caller is responsible for closing the file descriptor.
5240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Returns 0 on success or -errno on error.
5260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
5270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*dequeueBuffer)(struct ANativeWindow* window,
5280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                struct ANativeWindowBuffer** buffer, int* fenceFd);
5290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
5300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
5310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Hook called by EGL when modifications to the render buffer are done.
5320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * This unlocks and post the buffer.
5330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The window holds a reference to the buffer between dequeueBuffer and
5350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * either queueBuffer or cancelBuffer, so clients only need their own
5360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * reference if they might use the buffer after queueing or canceling it.
5370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Holding a reference to a buffer after queueing or canceling it is only
5380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * allowed if a specific buffer count has been set.
5390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The fenceFd argument specifies a libsync fence file descriptor for a
5410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * fence that must signal before the buffer can be accessed.  If the buffer
5420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * can be accessed immediately then a value of -1 should be used.  The
5430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * caller must not use the file descriptor after it is passed to
5440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * queueBuffer, and the ANativeWindow implementation is responsible for
5450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * closing it.
5460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Returns 0 on success or -errno on error.
5480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
5490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*queueBuffer)(struct ANativeWindow* window,
5500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                struct ANativeWindowBuffer* buffer, int fenceFd);
5510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
5520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /*
5530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Hook used to cancel a buffer that has been dequeued.
5540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * No synchronization is performed between dequeue() and cancel(), so
5550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * either external synchronization is needed, or these functions must be
5560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * called from the same thread.
5570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The window holds a reference to the buffer between dequeueBuffer and
5590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * either queueBuffer or cancelBuffer, so clients only need their own
5600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * reference if they might use the buffer after queueing or canceling it.
5610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Holding a reference to a buffer after queueing or canceling it is only
5620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * allowed if a specific buffer count has been set.
5630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * The fenceFd argument specifies a libsync fence file decsriptor for a
5650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * fence that must signal before the buffer can be accessed.  If the buffer
5660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * can be accessed immediately then a value of -1 should be used.
5670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Note that if the client has not waited on the fence that was returned
5690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * from dequeueBuffer, that same fence should be passed to cancelBuffer to
5700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * ensure that future uses of the buffer are preceded by a wait on that
5710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * fence.  The caller must not use the file descriptor after it is passed
5720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * to cancelBuffer, and the ANativeWindow implementation is responsible for
5730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * closing it.
5740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *
5750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Returns 0 on success or -errno on error.
5760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
5770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int     (*cancelBuffer)(struct ANativeWindow* window,
5780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                struct ANativeWindowBuffer* buffer, int fenceFd);
5790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
5800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
5810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
5820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  * android_native_window_t is deprecated.
5830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  */
5840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochtypedef struct ANativeWindow ANativeWindow;
5850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochtypedef struct ANativeWindow android_native_window_t;
5860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
5870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
5880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *  native_window_set_usage(..., usage)
5890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *  Sets the intended usage flags for the next buffers
5900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *  acquired with (*lockBuffer)() and on.
5910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *  By default (if this function is never called), a usage of
5920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *      GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE
5930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *  is assumed.
5940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *  Calling this function will usually cause following buffers to be
5950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *  reallocated.
5960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
5970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
5980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_usage(
5990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window, int usage)
6000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
6010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage);
6020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
6030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
6040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/* deprecated. Always returns 0. Don't call. */
6050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_connect(
6060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window, int api) {
6070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return 0;
6080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
6090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
6100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/* deprecated. Always returns 0. Don't call. */
6110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_disconnect(
6120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window, int api) {
6130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return 0;
6140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
6150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
6160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
6170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_crop(..., crop)
6180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Sets which region of the next queued buffers needs to be considered.
6190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Depending on the scaling mode, a buffer's crop region is scaled and/or
6200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * cropped to match the surface's size.  This function sets the crop in
6210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * pre-transformed buffer pixel coordinates.
6220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
6230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * The specified crop region applies to all buffers queued after it is called.
6240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
6250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * If 'crop' is NULL, subsequently queued buffers won't be cropped.
6260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
6270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * An error is returned if for instance the crop region is invalid, out of the
6280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * buffer's bound or if the window is invalid.
6290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
6300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_crop(
6310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
6320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        android_native_rect_t const * crop)
6330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
6340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
6350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
6360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
6370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
6380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_post_transform_crop(..., crop)
6390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Sets which region of the next queued buffers needs to be considered.
6400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Depending on the scaling mode, a buffer's crop region is scaled and/or
6410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * cropped to match the surface's size.  This function sets the crop in
6420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * post-transformed pixel coordinates.
6430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
6440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * The specified crop region applies to all buffers queued after it is called.
6450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
6460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * If 'crop' is NULL, subsequently queued buffers won't be cropped.
6470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
6480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * An error is returned if for instance the crop region is invalid, out of the
6490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * buffer's bound or if the window is invalid.
6500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
6510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_post_transform_crop(
6520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
6530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        android_native_rect_t const * crop)
6540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
6550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_POST_TRANSFORM_CROP, crop);
6560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
6570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
6580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
6590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_active_rect(..., active_rect)
6600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
6610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * This function is deprecated and will be removed soon.  For now it simply
6620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * sets the post-transform crop for compatibility while multi-project commits
6630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * get checked.
6640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
6650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_active_rect(
6660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
6670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        android_native_rect_t const * active_rect)
6680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
6690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return native_window_set_post_transform_crop(window, active_rect);
6700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
6710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
6720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
6730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_buffer_count(..., count)
6740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Sets the number of buffers associated with this native window.
6750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
6760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_buffer_count(
6770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
6780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        size_t bufferCount)
6790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
6800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
6810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
6820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
6830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
6840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_buffers_geometry(..., int w, int h, int format)
6850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * All buffers dequeued after this call will have the dimensions and format
6860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * specified.  A successful call to this function has the same effect as calling
6870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_buffers_size and native_window_set_buffers_format.
6880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
6890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * XXX: This function is deprecated.  The native_window_set_buffers_dimensions
6900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * and native_window_set_buffers_format functions should be used instead.
6910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
6920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_buffers_geometry(
6930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
6940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        int w, int h, int format)
6950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
6960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
6970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch            w, h, format);
6980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
6990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
7000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
7010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_buffers_dimensions(..., int w, int h)
7020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * All buffers dequeued after this call will have the dimensions specified.
7030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * In particular, all buffers will have a fixed-size, independent from the
7040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native-window size. They will be scaled according to the scaling mode
7050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * (see native_window_set_scaling_mode) upon window composition.
7060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
7070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
7080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * following this call will be sized to match the window's size.
7090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
7100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Calling this function will reset the window crop to a NULL value, which
7110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * disables cropping of the buffers.
7120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
7130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_buffers_dimensions(
7140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
7150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        int w, int h)
7160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
7170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
7180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch            w, h);
7190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
7200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
7210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
7220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_buffers_user_dimensions(..., int w, int h)
7230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
7240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Sets the user buffer size for the window, which overrides the
7250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * window's size.  All buffers dequeued after this call will have the
7260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * dimensions specified unless overridden by
7270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_buffers_dimensions.  All buffers will have a
7280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * fixed-size, independent from the native-window size. They will be
7290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * scaled according to the scaling mode (see
7300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_scaling_mode) upon window composition.
7310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
7320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * If w and h are 0, the normal behavior is restored. That is, the
7330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * default buffer size will match the windows's size.
7340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
7350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Calling this function will reset the window crop to a NULL value, which
7360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * disables cropping of the buffers.
7370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
7380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_buffers_user_dimensions(
7390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
7400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        int w, int h)
7410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
7420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
7430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch            w, h);
7440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
7450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
7460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
7470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_buffers_format(..., int format)
7480529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * All buffers dequeued after this call will have the format specified.
7490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch *
7500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * If the specified format is 0, the default buffer format will be used.
7510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
7520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_buffers_format(
7530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
7540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        int format)
7550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
7560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
7570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
7580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
7590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
7600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_buffers_transform(..., int transform)
7610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * All buffers queued after this call will be displayed transformed according
7620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * to the transform parameter specified.
7630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
7640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_buffers_transform(
7650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
7660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        int transform)
7670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
7680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
7690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch            transform);
7700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
7710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
7720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
7730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_buffers_timestamp(..., int64_t timestamp)
7740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * All buffers queued after this call will be associated with the timestamp
7750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
7760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * (the default), timestamps will be generated automatically when queueBuffer is
7770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * called. The timestamp is measured in nanoseconds, and is normally monotonically
7780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * increasing. The timestamp should be unaffected by time-of-day adjustments,
7790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * and for a camera should be strictly monotonic but for a media player may be
7800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * reset when the position is set.
7810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
7820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_buffers_timestamp(
7830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
7840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        int64_t timestamp)
7850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
7860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
7870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch            timestamp);
7880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
7890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
7900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
7910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_set_scaling_mode(..., int mode)
7920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * All buffers queued after this call will be associated with the scaling mode
7930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * specified.
7940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
7950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_set_scaling_mode(
7960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window,
7970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        int mode)
7980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
7990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
8000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch            mode);
8010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
8020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
8030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
8040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_api_connect(..., int api)
8050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * connects an API to this window. only one API can be connected at a time.
8060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Returns -EINVAL if for some reason the window cannot be connected, which
8070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * can happen if it's connected to some other API.
8080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
8090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_api_connect(
8100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window, int api)
8110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
8120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
8130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
8140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
8150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
8160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_api_disconnect(..., int api)
8170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * disconnect the API from this window.
8180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * An error is returned if for instance the window wasn't connected in the
8190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * first place.
8200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
8210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_api_disconnect(
8220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindow* window, int api)
8230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch{
8240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
8250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
8260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
8270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/*
8280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * native_window_dequeue_buffer_and_wait(...)
8290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * Dequeue a buffer and wait on the fence associated with that buffer.  The
8300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * buffer may safely be accessed immediately upon this function returning.  An
8310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * error is returned if either of the dequeue or the wait operations fail.
8320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
8330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstatic inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
8340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        struct ANativeWindowBuffer** anb) {
8350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return anw->dequeueBuffer_DEPRECATED(anw, anb);
8360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
8370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
8380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
8390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch__END_DECLS
8400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
8410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#endif /* SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H */
842