10ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev/*
20ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * Copyright (C) 2011 The Android Open Source Project
30ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev *
40ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * Licensed under the Apache License, Version 2.0 (the "License");
50ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * you may not use this file except in compliance with the License.
60ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * You may obtain a copy of the License at
70ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev *
80ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev *      http://www.apache.org/licenses/LICENSE-2.0
90ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev *
100ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * Unless required by applicable law or agreed to in writing, software
110ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * distributed under the License is distributed on an "AS IS" BASIS,
120ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * See the License for the specific language governing permissions and
140ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * limitations under the License.
150ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev */
160ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
170ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#ifndef SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H
180ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#define SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H
190ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
2022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis#include <cutils/native_handle.h>
21bc930eda3985cf50bb568aeb098cd0585d0c0ce0Jesse Hall#include <errno.h>
2222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis#include <limits.h>
230ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#include <stdint.h>
24c958a7f4988f3dd98135b23619cdf55ec55bd1f6Mathias Agopian#include <string.h>
2522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis#include <sync/sync.h>
260ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#include <sys/cdefs.h>
270ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#include <system/graphics.h>
2822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis#include <unistd.h>
290ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
300ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev__BEGIN_DECLS
310ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
320ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev/*****************************************************************************/
330ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
340ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \
350ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d))
360ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
370ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#define ANDROID_NATIVE_WINDOW_MAGIC \
380ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
390ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
400ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#define ANDROID_NATIVE_BUFFER_MAGIC \
410ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
420ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
430ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev// ---------------------------------------------------------------------------
440ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
4522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis// This #define may be used to conditionally compile device-specific code to
4622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis// support either the prior ANativeWindow interface, which did not pass libsync
4722aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis// fences around, or the new interface that does.  This #define is only present
4822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis// when the ANativeWindow interface does include libsync support.
4922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis#define ANDROID_NATIVE_WINDOW_HAS_SYNC 1
5022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis
5122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis// ---------------------------------------------------------------------------
5222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis
530ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevtypedef const native_handle_t* buffer_handle_t;
540ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
550ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev// ---------------------------------------------------------------------------
560ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
570ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevtypedef struct android_native_rect_t
580ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev{
590ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int32_t left;
600ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int32_t top;
610ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int32_t right;
620ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int32_t bottom;
630ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev} android_native_rect_t;
640ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
650ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev// ---------------------------------------------------------------------------
660ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
670ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevtypedef struct android_native_base_t
680ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev{
690ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* a magic value defined by the actual EGL native type */
700ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int magic;
710ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
720ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* the sizeof() of the actual EGL native type */
730ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int version;
740ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
750ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    void* reserved[4];
760ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
770ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* reference-counting interface */
780ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    void (*incRef)(struct android_native_base_t* base);
790ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    void (*decRef)(struct android_native_base_t* base);
800ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev} android_native_base_t;
810ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
820ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevtypedef struct ANativeWindowBuffer
830ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev{
840ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#ifdef __cplusplus
850ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    ANativeWindowBuffer() {
860ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
870ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        common.version = sizeof(ANativeWindowBuffer);
880ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        memset(common.reserved, 0, sizeof(common.reserved));
890ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    }
900ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
910ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    // Implement the methods that sp<ANativeWindowBuffer> expects so that it
920ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    // can be used to automatically refcount ANativeWindowBuffer's.
930ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    void incStrong(const void* id) const {
940ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        common.incRef(const_cast<android_native_base_t*>(&common));
950ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    }
960ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    void decStrong(const void* id) const {
970ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        common.decRef(const_cast<android_native_base_t*>(&common));
980ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    }
990ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#endif
1000ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1010ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    struct android_native_base_t common;
1020ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1030ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int width;
1040ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int height;
1050ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int stride;
1060ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int format;
1070ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int usage;
1080ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1090ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    void* reserved[2];
1100ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1110ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    buffer_handle_t handle;
1120ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1130ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    void* reserved_proc[8];
1140ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev} ANativeWindowBuffer_t;
1150ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1160ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev// Old typedef for backwards compatibility.
1170ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevtypedef ANativeWindowBuffer_t android_native_buffer_t;
1180ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1190ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev// ---------------------------------------------------------------------------
1200ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1210ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev/* attributes queriable with query() */
1220ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevenum {
1230ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    NATIVE_WINDOW_WIDTH     = 0,
12442cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_HEIGHT    = 1,
12542cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_FORMAT    = 2,
1260ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1270ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* The minimum number of buffers that must remain un-dequeued after a buffer
1280ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * has been queued.  This value applies only if set_buffer_count was used to
1290ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * override the number of buffers and if a buffer has since been queued.
1300ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * Users of the set_buffer_count ANativeWindow method should query this
1310ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * value before calling set_buffer_count.  If it is necessary to have N
1320ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * buffers simultaneously dequeued as part of the steady-state operation,
1330ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * and this query returns M then N+M buffers should be requested via
1340ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * native_window_set_buffer_count.
1350ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
1360ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * Note that this value does NOT apply until a single buffer has been
1370ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * queued.  In particular this means that it is possible to:
1380ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
1390ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * 1. Query M = min undequeued buffers
1400ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * 2. Set the buffer count to N + M
1410ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * 3. Dequeue all N + M buffers
1420ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * 4. Cancel M buffers
1430ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * 5. Queue, dequeue, queue, dequeue, ad infinitum
1440ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     */
14542cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = 3,
1460ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1470ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* Check whether queueBuffer operations on the ANativeWindow send the buffer
1480ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * to the window compositor.  The query sets the returned 'value' argument
1490ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * to 1 if the ANativeWindow DOES send queued buffers directly to the window
1500ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * compositor and 0 if the buffers do not go directly to the window
1510ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * compositor.
1520ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
1530ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * This can be used to determine whether protected buffer content should be
1540ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * sent to the ANativeWindow.  Note, however, that a result of 1 does NOT
1550ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * indicate that queued buffers will be protected from applications or users
1560ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * capturing their contents.  If that behavior is desired then some other
1570ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
1580ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * conjunction with this query.
1590ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     */
16042cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
1610ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
1620ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* Get the concrete type of a ANativeWindow.  See below for the list of
1630ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * possible return values.
1640ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
1650ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * This query should not be used outside the Android framework and will
1660ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * likely be removed in the near future.
1670ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     */
16842cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_CONCRETE_TYPE = 5,
1695100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian
1705100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian
1715100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian    /*
172afcdef635718985aae26e5f94c21ae4f3248a0b9Michael I. Gold     * Default width and height of ANativeWindow buffers, these are the
173afcdef635718985aae26e5f94c21ae4f3248a0b9Michael I. Gold     * dimensions of the window buffers irrespective of the
174afcdef635718985aae26e5f94c21ae4f3248a0b9Michael I. Gold     * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window
175aa3f4c3591d83728adec17bf0004f8dd5e46a3bbJamie Gennis     * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
1765100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     */
1775100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian    NATIVE_WINDOW_DEFAULT_WIDTH = 6,
1785100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian    NATIVE_WINDOW_DEFAULT_HEIGHT = 7,
1795100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian
1805100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian    /*
1815100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * transformation that will most-likely be applied to buffers. This is only
1825100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * a hint, the actual transformation applied might be different.
1835100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
1845100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * INTENDED USE:
1855100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
1865100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * The transform hint can be used by a producer, for instance the GLES
1875100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * driver, to pre-rotate the rendering such that the final transformation
1885100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * in the composer is identity. This can be very useful when used in
1895100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * conjunction with the h/w composer HAL, in situations where it
1905100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * cannot handle arbitrary rotations.
1915100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
1925100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * 1. Before dequeuing a buffer, the GL driver (or any other ANW client)
1935100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    queries the ANW for NATIVE_WINDOW_TRANSFORM_HINT.
1945100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
1955100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * 2. The GL driver overrides the width and height of the ANW to
1965100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    account for NATIVE_WINDOW_TRANSFORM_HINT. This is done by querying
1975100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    NATIVE_WINDOW_DEFAULT_{WIDTH | HEIGHT}, swapping the dimensions
1985100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    according to NATIVE_WINDOW_TRANSFORM_HINT and calling
1995100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    native_window_set_buffers_dimensions().
2005100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
2015100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * 3. The GL driver dequeues a buffer of the new pre-rotated size.
2025100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
2035100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * 4. The GL driver renders to the buffer such that the image is
2045100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    already transformed, that is applying NATIVE_WINDOW_TRANSFORM_HINT
2055100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    to the rendering.
2065100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
2075100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * 5. The GL driver calls native_window_set_transform to apply
2085100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    inverse transformation to the buffer it just rendered.
2095100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    In order to do this, the GL driver needs
2105100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    to calculate the inverse of NATIVE_WINDOW_TRANSFORM_HINT, this is
2115100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    done easily:
2125100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
2135100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *        int hintTransform, inverseTransform;
2145100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *        query(..., NATIVE_WINDOW_TRANSFORM_HINT, &hintTransform);
2155100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *        inverseTransform = hintTransform;
2165100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *        if (hintTransform & HAL_TRANSFORM_ROT_90)
2175100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *            inverseTransform ^= HAL_TRANSFORM_ROT_180;
2185100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
2195100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
2205100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * 6. The GL driver queues the pre-transformed buffer.
2215100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
2225100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     * 7. The composer combines the buffer transform with the display
2235100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    transform.  If the buffer transform happens to cancel out the
2245100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *    display transform then no rotation is needed.
2255100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     *
2265100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian     */
2275100916182b05971975f8d8fe65a1255e2c5ac96Mathias Agopian    NATIVE_WINDOW_TRANSFORM_HINT = 8,
228aa3f4c3591d83728adec17bf0004f8dd5e46a3bbJamie Gennis
229aa3f4c3591d83728adec17bf0004f8dd5e46a3bbJamie Gennis    /*
230aa3f4c3591d83728adec17bf0004f8dd5e46a3bbJamie Gennis     * Boolean that indicates whether the consumer is running more than
231aa3f4c3591d83728adec17bf0004f8dd5e46a3bbJamie Gennis     * one buffer behind the producer.
232aa3f4c3591d83728adec17bf0004f8dd5e46a3bbJamie Gennis     */
233aa3f4c3591d83728adec17bf0004f8dd5e46a3bbJamie Gennis    NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9
2340ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev};
2350ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
236fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis/* Valid operations for the (*perform)() hook.
237fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis *
238fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis * Values marked as 'deprecated' are supported, but have been superceded by
239fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis * other functionality.
240fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis *
241fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis * Values marked as 'private' should be considered private to the framework.
242fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis * HAL implementation code with access to an ANativeWindow should not use these,
243fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis * as it may not interact properly with the framework's use of the
244fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis * ANativeWindow.
245fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis */
2460ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevenum {
24742cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SET_USAGE                 =  0,
2488ad545297cdb180893c4f957682857953c0d3c5fMathias Agopian    NATIVE_WINDOW_CONNECT                   =  1,   /* deprecated */
2498ad545297cdb180893c4f957682857953c0d3c5fMathias Agopian    NATIVE_WINDOW_DISCONNECT                =  2,   /* deprecated */
250fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis    NATIVE_WINDOW_SET_CROP                  =  3,   /* private */
25142cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SET_BUFFER_COUNT          =  4,
25242cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SET_BUFFERS_GEOMETRY      =  5,   /* deprecated */
25342cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SET_BUFFERS_TRANSFORM     =  6,
25442cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP     =  7,
25542cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS    =  8,
25642cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SET_BUFFERS_FORMAT        =  9,
257fb1ee571446c13ad698e91f13fd4e0274a37d4d7Jamie Gennis    NATIVE_WINDOW_SET_SCALING_MODE          = 10,   /* private */
258ae3736a3d1418eb1a1e57895ce410256d7106aa3Mathias Agopian    NATIVE_WINDOW_LOCK                      = 11,   /* private */
259ae3736a3d1418eb1a1e57895ce410256d7106aa3Mathias Agopian    NATIVE_WINDOW_UNLOCK_AND_POST           = 12,   /* private */
2608ad545297cdb180893c4f957682857953c0d3c5fMathias Agopian    NATIVE_WINDOW_API_CONNECT               = 13,   /* private */
2618ad545297cdb180893c4f957682857953c0d3c5fMathias Agopian    NATIVE_WINDOW_API_DISCONNECT            = 14,   /* private */
262afcdef635718985aae26e5f94c21ae4f3248a0b9Michael I. Gold    NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
263d21113ac460a2a663396bc6ecd79e5a85e2efc1bJamie Gennis    NATIVE_WINDOW_SET_POST_TRANSFORM_CROP   = 16,   /* private */
2640ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev};
2650ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
2668ad545297cdb180893c4f957682857953c0d3c5fMathias Agopian/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
2670ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevenum {
2685423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis    /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
2695423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis     * OpenGL ES.
2705423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis     */
2715423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis    NATIVE_WINDOW_API_EGL = 1,
2725423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis
2735423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis    /* Buffers will be queued after being filled using the CPU
2745423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis     */
2755423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis    NATIVE_WINDOW_API_CPU = 2,
2765423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis
2775423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis    /* Buffers will be queued by Stagefright after being filled by a video
2785423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis     * decoder.  The video decoder can either be a software or hardware decoder.
2795423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis     */
2805423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis    NATIVE_WINDOW_API_MEDIA = 3,
2815423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis
2825423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis    /* Buffers will be queued by the the camera HAL.
2835423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis     */
2845423e9e4ce52a45ac42419f1467e79ba9e62298fJamie Gennis    NATIVE_WINDOW_API_CAMERA = 4,
2850ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev};
2860ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
2870ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
2880ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevenum {
2890ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* flip source image horizontally */
2900ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
2910ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* flip source image vertically */
2920ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
2930ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* rotate source image 90 degrees clock-wise */
2940ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
2950ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* rotate source image 180 degrees */
2960ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
2970ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* rotate source image 270 degrees clock-wise */
2980ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
2990ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev};
3000ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
30142cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian/* parameter for NATIVE_WINDOW_SET_SCALING_MODE */
30242cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopianenum {
30342cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    /* the window content is not updated (frozen) until a buffer of
30442cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian     * the window size is received (enqueued)
30542cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian     */
30642cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SCALING_MODE_FREEZE           = 0,
30742cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    /* the buffer is scaled in both dimensions to match the window size */
30842cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW  = 1,
30929392a4e5bedcff53a1d1f6674c73de00e0e5055Daniel Lam    /* the buffer is scaled uniformly such that the smaller dimension
31029392a4e5bedcff53a1d1f6674c73de00e0e5055Daniel Lam     * of the buffer matches the window size (cropping in the process)
31129392a4e5bedcff53a1d1f6674c73de00e0e5055Daniel Lam     */
31229392a4e5bedcff53a1d1f6674c73de00e0e5055Daniel Lam    NATIVE_WINDOW_SCALING_MODE_SCALE_CROP       = 2,
313d21113ac460a2a663396bc6ecd79e5a85e2efc1bJamie Gennis    /* the window is clipped to the size of the buffer's crop rectangle; pixels
314d21113ac460a2a663396bc6ecd79e5a85e2efc1bJamie Gennis     * outside the crop rectangle are treated as if they are completely
315d21113ac460a2a663396bc6ecd79e5a85e2efc1bJamie Gennis     * transparent.
316d21113ac460a2a663396bc6ecd79e5a85e2efc1bJamie Gennis     */
317d21113ac460a2a663396bc6ecd79e5a85e2efc1bJamie Gennis    NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP    = 3,
31842cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian};
31942cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian
3200ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
3210ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevenum {
32242cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_FRAMEBUFFER               = 0, /* FramebufferNativeWindow */
32342cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SURFACE                   = 1, /* Surface */
32442cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT    = 2, /* SurfaceTextureClient */
3250ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev};
3260ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3270ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
3280ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev *
3290ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * Special timestamp value to indicate that timestamps should be auto-generated
3300ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * by the native window when queueBuffer is called.  This is equal to INT64_MIN,
3310ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
3320ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev */
3330ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevstatic const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
3340ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3350ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchevstruct ANativeWindow
3360ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev{
3370ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#ifdef __cplusplus
3380ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    ANativeWindow()
3390ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
3400ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    {
3410ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
3420ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        common.version = sizeof(ANativeWindow);
3430ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        memset(common.reserved, 0, sizeof(common.reserved));
3440ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    }
3450ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
34642cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian    /* Implement the methods that sp<ANativeWindow> expects so that it
34742cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian       can be used to automatically refcount ANativeWindow's. */
3480ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    void incStrong(const void* id) const {
3490ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        common.incRef(const_cast<android_native_base_t*>(&common));
3500ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    }
3510ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    void decStrong(const void* id) const {
3520ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev        common.decRef(const_cast<android_native_base_t*>(&common));
3530ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    }
3540ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev#endif
3550ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3560ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    struct android_native_base_t common;
3570ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3580ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* flags describing some attributes of this surface or its updater */
3590ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    const uint32_t flags;
3600ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3610ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* min swap interval supported by this updated */
3620ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    const int   minSwapInterval;
3630ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3640ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* max swap interval supported by this updated */
3650ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    const int   maxSwapInterval;
3660ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3670ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* horizontal and vertical resolution in DPI */
3680ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    const float xdpi;
3690ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    const float ydpi;
3700ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3710ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /* Some storage reserved for the OEM's driver. */
3720ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    intptr_t    oem[4];
3730ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3740ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /*
3750ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * Set the swap interval for this surface.
3760ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
3770ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * Returns 0 on success or -errno on error.
3780ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     */
3790ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int     (*setSwapInterval)(struct ANativeWindow* window,
3800ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev                int interval);
3810ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
3820ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /*
3837cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * Hook called by EGL to acquire a buffer. After this call, the buffer
3847cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * is not locked, so its content cannot be modified. This call may block if
3857cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * no buffers are available.
3867cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     *
3877cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * The window holds a reference to the buffer between dequeueBuffer and
3887cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * either queueBuffer or cancelBuffer, so clients only need their own
3897cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * reference if they might use the buffer after queueing or canceling it.
3907cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * Holding a reference to a buffer after queueing or canceling it is only
3917cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * allowed if a specific buffer count has been set.
3920ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
3930ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * Returns 0 on success or -errno on error.
39422aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
39522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * XXX: This function is deprecated.  It will continue to work for some
39622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * time for binary compatibility, but the new dequeueBuffer function that
39722aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * outputs a fence file descriptor should be used in its place.
3980ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     */
39922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    int     (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
4000ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev                struct ANativeWindowBuffer** buffer);
4010ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
4020ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /*
4030ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * hook called by EGL to lock a buffer. This MUST be called before modifying
4040ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * the content of a buffer. The buffer must have been acquired with
4050ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * dequeueBuffer first.
4060ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
4070ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * Returns 0 on success or -errno on error.
40822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
40922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * XXX: This function is deprecated.  It will continue to work for some
41022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * time for binary compatibility, but it is essentially a no-op, and calls
41122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * to it should be removed.
4120ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     */
41322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    int     (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
4140ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev                struct ANativeWindowBuffer* buffer);
41522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis
4167cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall    /*
4177cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * Hook called by EGL when modifications to the render buffer are done.
4187cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * This unlocks and post the buffer.
4197cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     *
4207cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * The window holds a reference to the buffer between dequeueBuffer and
4217cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * either queueBuffer or cancelBuffer, so clients only need their own
4227cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * reference if they might use the buffer after queueing or canceling it.
4237cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * Holding a reference to a buffer after queueing or canceling it is only
4247cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * allowed if a specific buffer count has been set.
4257cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     *
4267cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * Buffers MUST be queued in the same order than they were dequeued.
4277cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     *
4287cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * Returns 0 on success or -errno on error.
42922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
43022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * XXX: This function is deprecated.  It will continue to work for some
43122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * time for binary compatibility, but the new queueBuffer function that
43222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * takes a fence file descriptor should be used in its place (pass a value
43322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * of -1 for the fence file descriptor if there is no valid one to pass).
4347cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     */
43522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    int     (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
4360ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev                struct ANativeWindowBuffer* buffer);
4370ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
4380ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /*
4390ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * hook used to retrieve information about the native window.
4400ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
4410ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * Returns 0 on success or -errno on error.
4420ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     */
4430ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int     (*query)(const struct ANativeWindow* window,
4440ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev                int what, int* value);
4450ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
4460ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /*
4470ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * hook used to perform various operations on the surface.
4480ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * (*perform)() is a generic mechanism to add functionality to
4490ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * ANativeWindow while keeping backward binary compatibility.
4500ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
4510ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * DO NOT CALL THIS HOOK DIRECTLY.  Instead, use the helper functions
4520ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * defined below.
4530ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
4540ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *  (*perform)() returns -ENOENT if the 'what' parameter is not supported
4550ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *  by the surface's implementation.
4560ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
4570ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * The valid operations are:
4580ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *     NATIVE_WINDOW_SET_USAGE
4598ad545297cdb180893c4f957682857953c0d3c5fMathias Agopian     *     NATIVE_WINDOW_CONNECT               (deprecated)
4608ad545297cdb180893c4f957682857953c0d3c5fMathias Agopian     *     NATIVE_WINDOW_DISCONNECT            (deprecated)
461190b6e2698dc47ddb4888b9c51abb23f69fcf064Jamie Gennis     *     NATIVE_WINDOW_SET_CROP              (private)
4620ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *     NATIVE_WINDOW_SET_BUFFER_COUNT
46342cc1edfe7edf613e17bff97f30ff124ada05136Mathias Agopian     *     NATIVE_WINDOW_SET_BUFFERS_GEOMETRY  (deprecated)
4640ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *     NATIVE_WINDOW_SET_BUFFERS_TRANSFORM
4650ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *     NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
466208ec5ec564597bdf8b478a424cc9ccc09547bacJamie Gennis     *     NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS
467208ec5ec564597bdf8b478a424cc9ccc09547bacJamie Gennis     *     NATIVE_WINDOW_SET_BUFFERS_FORMAT
468190b6e2698dc47ddb4888b9c51abb23f69fcf064Jamie Gennis     *     NATIVE_WINDOW_SET_SCALING_MODE       (private)
469ae3736a3d1418eb1a1e57895ce410256d7106aa3Mathias Agopian     *     NATIVE_WINDOW_LOCK                   (private)
470ae3736a3d1418eb1a1e57895ce410256d7106aa3Mathias Agopian     *     NATIVE_WINDOW_UNLOCK_AND_POST        (private)
4718ad545297cdb180893c4f957682857953c0d3c5fMathias Agopian     *     NATIVE_WINDOW_API_CONNECT            (private)
4728ad545297cdb180893c4f957682857953c0d3c5fMathias Agopian     *     NATIVE_WINDOW_API_DISCONNECT         (private)
473afcdef635718985aae26e5f94c21ae4f3248a0b9Michael I. Gold     *     NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS (private)
474d21113ac460a2a663396bc6ecd79e5a85e2efc1bJamie Gennis     *     NATIVE_WINDOW_SET_POST_TRANSFORM_CROP (private)
4750ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     *
4760ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     */
4770ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
4780ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    int     (*perform)(struct ANativeWindow* window,
4790ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev                int operation, ... );
4800ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
4810ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev    /*
4827cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * Hook used to cancel a buffer that has been dequeued.
4830ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * No synchronization is performed between dequeue() and cancel(), so
4840ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * either external synchronization is needed, or these functions must be
4850ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     * called from the same thread.
4867cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     *
4877cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * The window holds a reference to the buffer between dequeueBuffer and
4887cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * either queueBuffer or cancelBuffer, so clients only need their own
4897cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * reference if they might use the buffer after queueing or canceling it.
4907cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * Holding a reference to a buffer after queueing or canceling it is only
4917cd3e0a3a2f9b104cd6c04f699ae62c4577787e2Jesse Hall     * allowed if a specific buffer count has been set.
49222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
49322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * XXX: This function is deprecated.  It will continue to work for some
49422aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * time for binary compatibility, but the new cancelBuffer function that
49522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * takes a fence file descriptor should be used in its place (pass a value
49622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * of -1 for the fence file descriptor if there is no valid one to pass).
4970ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev     */
49822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    int     (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
4990ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev                struct ANativeWindowBuffer* buffer);
5000ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
50122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    /*
50222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Hook called by EGL to acquire a buffer. This call may block if no
50322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * buffers are available.
50422aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
50522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * The window holds a reference to the buffer between dequeueBuffer and
50622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * either queueBuffer or cancelBuffer, so clients only need their own
50722aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * reference if they might use the buffer after queueing or canceling it.
50822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Holding a reference to a buffer after queueing or canceling it is only
50922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * allowed if a specific buffer count has been set.
51022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
51122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * The libsync fence file descriptor returned in the int pointed to by the
51222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * fenceFd argument will refer to the fence that must signal before the
51322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * dequeued buffer may be written to.  A value of -1 indicates that the
51422aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * caller may access the buffer immediately without waiting on a fence.  If
51522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * a valid file descriptor is returned (i.e. any value except -1) then the
51622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * caller is responsible for closing the file descriptor.
51722aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
51822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Returns 0 on success or -errno on error.
51922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     */
52022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    int     (*dequeueBuffer)(struct ANativeWindow* window,
52122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis                struct ANativeWindowBuffer** buffer, int* fenceFd);
52222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis
52322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    /*
52422aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Hook called by EGL when modifications to the render buffer are done.
52522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * This unlocks and post the buffer.
52622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
52722aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * The window holds a reference to the buffer between dequeueBuffer and
52822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * either queueBuffer or cancelBuffer, so clients only need their own
52922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * reference if they might use the buffer after queueing or canceling it.
53022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Holding a reference to a buffer after queueing or canceling it is only
53122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * allowed if a specific buffer count has been set.
53222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
53322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * The fenceFd argument specifies a libsync fence file descriptor for a
53422aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * fence that must signal before the buffer can be accessed.  If the buffer
53522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * can be accessed immediately then a value of -1 should be used.  The
53622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * caller must not use the file descriptor after it is passed to
53722aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * queueBuffer, and the ANativeWindow implementation is responsible for
53822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * closing it.
53922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
54022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Returns 0 on success or -errno on error.
54122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     */
54222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    int     (*queueBuffer)(struct ANativeWindow* window,
54322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis                struct ANativeWindowBuffer* buffer, int fenceFd);
5440ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
54522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    /*
54622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Hook used to cancel a buffer that has been dequeued.
54722aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * No synchronization is performed between dequeue() and cancel(), so
54822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * either external synchronization is needed, or these functions must be
54922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * called from the same thread.
55022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
55122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * The window holds a reference to the buffer between dequeueBuffer and
55222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * either queueBuffer or cancelBuffer, so clients only need their own
55322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * reference if they might use the buffer after queueing or canceling it.
55422aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Holding a reference to a buffer after queueing or canceling it is only
55522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * allowed if a specific buffer count has been set.
55622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
55722aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * The fenceFd argument specifies a libsync fence file decsriptor for a
55822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * fence that must signal before the buffer can be accessed.  If the buffer
55922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * can be accessed immediately then a value of -1 should be used.
56022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
56122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Note that if the client has not waited on the fence that was returned
56222aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * from dequeueBuffer, that same fence should be passed to cancelBuffer to
56322aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * ensure that future uses of the buffer are preceded by a wait on that
56422aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * fence.  The caller must not use the file descriptor after it is passed
56522aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * to cancelBuffer, and the ANativeWindow implementation is responsible for
56622aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * closing it.
56722aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     *
56822aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     * Returns 0 on success or -errno on error.
56922aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis     */
57022aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis    int     (*cancelBuffer)(struct ANativeWindow* window,
57122aec573b718c57aea2b9bd91607631a6d521911Jamie Gennis                struct ANativeWindowBuffer* buffer, int fenceFd);
5720ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev};
5730ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev
5740ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
5750ab886bdabd167b32aad90ce5d4e00ce8392858cIliyan Malchev  * android_native_window_t is deprecated.
576