1a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian/*
2a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian * Copyright (C) 2017 The Android Open Source Project
3a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian *
4a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian * you may not use this file except in compliance with the License.
6a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian * You may obtain a copy of the License at
7a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian *
8a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian *
10a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian * Unless required by applicable law or agreed to in writing, software
11a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian * See the License for the specific language governing permissions and
14a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian * limitations under the License.
15a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian */
16a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian
17a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian#ifndef ANDROID_VNDK_NATIVEWINDOW_ANATIVEWINDOW_H
18a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian#define ANDROID_VNDK_NATIVEWINDOW_ANATIVEWINDOW_H
19a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian
20000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#include <stdint.h>
21000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#include <stdbool.h>
22a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian#include <sys/cdefs.h>
23000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#include <system/graphics-base.h>
24000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#include <cutils/native_handle.h>
25a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian
26a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian// vndk is a superset of the NDK
27a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian#include <android/native_window.h>
28a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian
29a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian__BEGIN_DECLS
30a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian
31000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*****************************************************************************/
32a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian
33000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#ifdef __cplusplus
34000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#define ANDROID_NATIVE_UNSIGNED_CAST(x) static_cast<unsigned int>(x)
35000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#else
36000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#define ANDROID_NATIVE_UNSIGNED_CAST(x) ((unsigned int)(x))
37000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#endif
38a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian
39000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d)  \
40000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ((ANDROID_NATIVE_UNSIGNED_CAST(a) << 24) | \
41000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     (ANDROID_NATIVE_UNSIGNED_CAST(b) << 16) | \
42000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     (ANDROID_NATIVE_UNSIGNED_CAST(c) <<  8) | \
43000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     (ANDROID_NATIVE_UNSIGNED_CAST(d)))
44000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
45000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#define ANDROID_NATIVE_BUFFER_MAGIC     ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
46000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
47000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
48000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*****************************************************************************/
49000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
50000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopiantypedef struct android_native_base_t
51000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian{
52000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /* a magic value defined by the actual EGL native type */
53000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    int magic;
54000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
55000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /* the sizeof() of the actual EGL native type */
56000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    int version;
57000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
58000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    void* reserved[4];
59000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
60000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /* reference-counting interface */
61000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    void (*incRef)(struct android_native_base_t* base);
62000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    void (*decRef)(struct android_native_base_t* base);
63000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian} android_native_base_t;
64000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
65000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopiantypedef struct ANativeWindowBuffer
66000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian{
67000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#ifdef __cplusplus
68000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANativeWindowBuffer() {
69000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian        common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
70000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian        common.version = sizeof(ANativeWindowBuffer);
71000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian        memset(common.reserved, 0, sizeof(common.reserved));
72000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    }
73000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
74000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    // Implement the methods that sp<ANativeWindowBuffer> expects so that it
75000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    // can be used to automatically refcount ANativeWindowBuffer's.
76000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    void incStrong(const void* /*id*/) const {
77000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian        common.incRef(const_cast<android_native_base_t*>(&common));
78000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    }
79000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    void decStrong(const void* /*id*/) const {
80000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian        common.decRef(const_cast<android_native_base_t*>(&common));
81000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    }
82000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian#endif
83000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
84000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    struct android_native_base_t common;
85000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
86000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    int width;
87000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    int height;
88000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    int stride;
89000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    int format;
90000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    int usage;
91000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    uintptr_t layerCount;
92000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
93000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    void* reserved[1];
94000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
95000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    const native_handle_t* handle;
96000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
97000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    void* reserved_proc[8];
98000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian} ANativeWindowBuffer_t;
99000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
100000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopiantypedef struct ANativeWindowBuffer ANativeWindowBuffer;
101000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
102453effd1f144fb5a6ae89a7c377d20a845c49080Mathias Agopian/*
103453effd1f144fb5a6ae89a7c377d20a845c49080Mathias Agopian * Convert this ANativeWindowBuffer into a AHardwareBuffer
104453effd1f144fb5a6ae89a7c377d20a845c49080Mathias Agopian */
105453effd1f144fb5a6ae89a7c377d20a845c49080Mathias AgopianAHardwareBuffer* ANativeWindowBuffer_getHardwareBuffer(ANativeWindowBuffer* anwb);
106000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
107453effd1f144fb5a6ae89a7c377d20a845c49080Mathias Agopian/*****************************************************************************/
108000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
109000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
110000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Stores a value into one of the 4 available slots
111000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Retrieve the value with ANativeWindow_OemStorageGet()
112000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
113000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * slot: 0 to 3
114000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
115000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Returns 0 on success or -errno on error.
116000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
117000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_OemStorageSet(ANativeWindow* window, uint32_t slot, intptr_t value);
118000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
119000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
120000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
121000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Retrieves a value from one of the 4 available slots
122000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * By default the returned value is 0 if it wasn't set by ANativeWindow_OemStorageSet()
123000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
124000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * slot: 0 to 3
125000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
126000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Returns 0 on success or -errno on error.
127000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
128000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_OemStorageGet(ANativeWindow* window, uint32_t slot, intptr_t* value);
129000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
130000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
131000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
132000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Set the swap interval for this surface.
133000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
134000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Returns 0 on success or -errno on error.
135000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
136000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_setSwapInterval(ANativeWindow* window, int interval);
137000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
138000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
139000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
140000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * queries that can be used with ANativeWindow_query() and ANativeWindow_queryf()
141000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
142000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianenum ANativeWindowQuery {
143000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /* The minimum number of buffers that must remain un-dequeued after a buffer
144000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * has been queued.  This value applies only if set_buffer_count was used to
145000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * override the number of buffers and if a buffer has since been queued.
146000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * Users of the set_buffer_count ANativeWindow method should query this
147000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * value before calling set_buffer_count.  If it is necessary to have N
148000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * buffers simultaneously dequeued as part of the steady-state operation,
149000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * and this query returns M then N+M buffers should be requested via
150000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * native_window_set_buffer_count.
151000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
152000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * Note that this value does NOT apply until a single buffer has been
153000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * queued.  In particular this means that it is possible to:
154000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
155000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 1. Query M = min undequeued buffers
156000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 2. Set the buffer count to N + M
157000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 3. Dequeue all N + M buffers
158000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 4. Cancel M buffers
159000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 5. Queue, dequeue, queue, dequeue, ad infinitum
160000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     */
161000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS = 3,
162000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
163000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /*
164000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * Default width of ANativeWindow buffers, these are the
165000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * dimensions of the window buffers irrespective of the
166000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * ANativeWindow_setBuffersDimensions() call and match the native window
167000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * size.
168000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     */
169000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANATIVEWINDOW_QUERY_DEFAULT_WIDTH = 6,
170000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT = 7,
171000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
172000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /*
173000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * transformation that will most-likely be applied to buffers. This is only
174000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * a hint, the actual transformation applied might be different.
175000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
176000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * INTENDED USE:
177000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
178000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * The transform hint can be used by a producer, for instance the GLES
179000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * driver, to pre-rotate the rendering such that the final transformation
180000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * in the composer is identity. This can be very useful when used in
181000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * conjunction with the h/w composer HAL, in situations where it
182000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * cannot handle arbitrary rotations.
183000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
184000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 1. Before dequeuing a buffer, the GL driver (or any other ANW client)
185000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    queries the ANW for NATIVE_WINDOW_TRANSFORM_HINT.
186000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
187000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 2. The GL driver overrides the width and height of the ANW to
188000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    account for NATIVE_WINDOW_TRANSFORM_HINT. This is done by querying
189000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    NATIVE_WINDOW_DEFAULT_{WIDTH | HEIGHT}, swapping the dimensions
190000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    according to NATIVE_WINDOW_TRANSFORM_HINT and calling
191000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    native_window_set_buffers_dimensions().
192000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
193000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 3. The GL driver dequeues a buffer of the new pre-rotated size.
194000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
195000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 4. The GL driver renders to the buffer such that the image is
196000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    already transformed, that is applying NATIVE_WINDOW_TRANSFORM_HINT
197000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    to the rendering.
198000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
199000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 5. The GL driver calls native_window_set_transform to apply
200000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    inverse transformation to the buffer it just rendered.
201000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    In order to do this, the GL driver needs
202000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    to calculate the inverse of NATIVE_WINDOW_TRANSFORM_HINT, this is
203000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    done easily:
204000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
205000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *        int hintTransform, inverseTransform;
206000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *        query(..., NATIVE_WINDOW_TRANSFORM_HINT, &hintTransform);
207000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *        inverseTransform = hintTransform;
208000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *        if (hintTransform & HAL_TRANSFORM_ROT_90)
209000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *            inverseTransform ^= HAL_TRANSFORM_ROT_180;
210000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
211000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
212000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 6. The GL driver queues the pre-transformed buffer.
213000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
214000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * 7. The composer combines the buffer transform with the display
215000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    transform.  If the buffer transform happens to cancel out the
216000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *    display transform then no rotation is needed.
217000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     *
218000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     */
219000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANATIVEWINDOW_QUERY_TRANSFORM_HINT = 8,
220000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
221000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /*
222000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * Returns the age of the contents of the most recently dequeued buffer as
223000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * the number of frames that have elapsed since it was last queued. For
224000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * example, if the window is double-buffered, the age of any given buffer in
225000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * steady state will be 2. If the dequeued buffer has never been queued, its
226000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     * age will be 0.
227000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian     */
228000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANATIVEWINDOW_QUERY_BUFFER_AGE = 13,
229000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
230000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /* min swap interval supported by this compositor */
231000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANATIVEWINDOW_QUERY_MIN_SWAP_INTERVAL = 0x10000,
232000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
233000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /* max swap interval supported by this compositor */
234000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANATIVEWINDOW_QUERY_MAX_SWAP_INTERVAL = 0x10001,
235000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
236000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /* horizontal resolution in DPI. value is float, use queryf() */
237000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANATIVEWINDOW_QUERY_XDPI = 0x10002,
238000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
239000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    /* vertical resolution in DPI. value is float, use queryf() */
240000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian    ANATIVEWINDOW_QUERY_YDPI = 0x10003,
241000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian};
242000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
2430e95cad418cff706743f98c1ac649d3378ab0b34Mathias Agopiantypedef enum ANativeWindowQuery ANativeWindowQuery;
2440e95cad418cff706743f98c1ac649d3378ab0b34Mathias Agopian
245000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
246000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * hook used to retrieve information about the native window.
247000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
248000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Returns 0 on success or -errno on error.
249000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
250000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_query(const ANativeWindow* window, ANativeWindowQuery query, int* value);
251000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_queryf(const ANativeWindow* window, ANativeWindowQuery query, float* value);
252000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
253000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
254000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
255000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Hook called by EGL to acquire a buffer. This call may block if no
256000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * buffers are available.
257000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
258000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * The window holds a reference to the buffer between dequeueBuffer and
259000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * either queueBuffer or cancelBuffer, so clients only need their own
260000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * reference if they might use the buffer after queueing or canceling it.
261000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Holding a reference to a buffer after queueing or canceling it is only
262000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * allowed if a specific buffer count has been set.
263000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
264000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * The libsync fence file descriptor returned in the int pointed to by the
265000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * fenceFd argument will refer to the fence that must signal before the
266000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * dequeued buffer may be written to.  A value of -1 indicates that the
267000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * caller may access the buffer immediately without waiting on a fence.  If
268000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * a valid file descriptor is returned (i.e. any value except -1) then the
269000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * caller is responsible for closing the file descriptor.
270000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
271000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Returns 0 on success or -errno on error.
272000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
273000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd);
274000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
275000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
276000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
277000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Hook called by EGL when modifications to the render buffer are done.
278000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * This unlocks and post the buffer.
279000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
280000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * The window holds a reference to the buffer between dequeueBuffer and
281000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * either queueBuffer or cancelBuffer, so clients only need their own
282000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * reference if they might use the buffer after queueing or canceling it.
283000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Holding a reference to a buffer after queueing or canceling it is only
284000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * allowed if a specific buffer count has been set.
285000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
286000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * The fenceFd argument specifies a libsync fence file descriptor for a
287000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * fence that must signal before the buffer can be accessed.  If the buffer
288000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * can be accessed immediately then a value of -1 should be used.  The
289000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * caller must not use the file descriptor after it is passed to
290000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * queueBuffer, and the ANativeWindow implementation is responsible for
291000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * closing it.
292000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
293000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Returns 0 on success or -errno on error.
294000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
295000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd);
296000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
297000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
298000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
299000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Hook used to cancel a buffer that has been dequeued.
300000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * No synchronization is performed between dequeue() and cancel(), so
301000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * either external synchronization is needed, or these functions must be
302000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * called from the same thread.
303000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
304000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * The window holds a reference to the buffer between dequeueBuffer and
305000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * either queueBuffer or cancelBuffer, so clients only need their own
306000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * reference if they might use the buffer after queueing or canceling it.
307000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Holding a reference to a buffer after queueing or canceling it is only
308000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * allowed if a specific buffer count has been set.
309000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
310000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * The fenceFd argument specifies a libsync fence file decsriptor for a
311000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * fence that must signal before the buffer can be accessed.  If the buffer
312000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * can be accessed immediately then a value of -1 should be used.
313000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
314000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Note that if the client has not waited on the fence that was returned
315000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * from dequeueBuffer, that same fence should be passed to cancelBuffer to
316000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * ensure that future uses of the buffer are preceded by a wait on that
317000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * fence.  The caller must not use the file descriptor after it is passed
318000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * to cancelBuffer, and the ANativeWindow implementation is responsible for
319000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * closing it.
320000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
321000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Returns 0 on success or -errno on error.
322000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
323000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd);
324000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
325000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
326000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *  Sets the intended usage flags for the next buffers.
327000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
3282c38b56d19f464142e32030b99ac56afd47ab7cdMathias Agopian *  usage: one of AHARDWAREBUFFER_USAGE_* constant
329000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
330000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *  By default (if this function is never called), a usage of
3312c38b56d19f464142e32030b99ac56afd47ab7cdMathias Agopian *      AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT
332000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *  is assumed.
333000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
334000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *  Calling this function will usually cause following buffers to be
335000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *  reallocated.
336000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
3372c38b56d19f464142e32030b99ac56afd47ab7cdMathias Agopianint ANativeWindow_setUsage(ANativeWindow* window, uint64_t usage);
338000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
339000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
340000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
341000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Sets the number of buffers associated with this native window.
342000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
343000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_setBufferCount(ANativeWindow* window, size_t bufferCount);
344000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
345000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
346000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
347000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * All buffers dequeued after this call will have the dimensions specified.
348000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * In particular, all buffers will have a fixed-size, independent from the
349000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * native-window size. They will be scaled according to the scaling mode
350000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * (see native_window_set_scaling_mode) upon window composition.
351000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
352000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
353000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * following this call will be sized to match the window's size.
354000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
355000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Calling this function will reset the window crop to a NULL value, which
356000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * disables cropping of the buffers.
357000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
358000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_setBuffersDimensions(ANativeWindow* window, uint32_t w, uint32_t h);
359000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
360000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
361000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
362000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * All buffers dequeued after this call will have the format specified.
363000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * format: one of AHARDWAREBUFFER_FORMAT_* constant
364000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
365000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * If the specified format is 0, the default buffer format will be used.
366000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
367000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_setBuffersFormat(ANativeWindow* window, int format);
368000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
369000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
370000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
371000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * All buffers queued after this call will be associated with the timestamp in nanosecond
372000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
373000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * (the default), timestamps will be generated automatically when queueBuffer is
374000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * called. The timestamp is measured in nanoseconds, and is normally monotonically
375000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * increasing. The timestamp should be unaffected by time-of-day adjustments,
376000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * and for a camera should be strictly monotonic but for a media player may be
377000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * reset when the position is set.
378000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
379000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_setBuffersTimestamp(ANativeWindow* window, int64_t timestamp);
380000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
381000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
382000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
383000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * All buffers queued after this call will be associated with the dataSpace
384000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * parameter specified.
385000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian *
386000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * dataSpace specifies additional information about the buffer that's dependent
387000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * on the buffer format and the endpoints. For example, it can be used to convey
388000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * the color space of the image data in the buffer, or it can be used to
389000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * indicate that the buffers contain depth measurement data instead of color
390000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * images.  The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
391000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * overridden by the consumer.
392000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
393000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_setBufferDataSpace(ANativeWindow* window, android_dataspace_t dataSpace);
394000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
395000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
396000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
397000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Enable/disable shared buffer mode
398000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
399000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_setSharedBufferMode(ANativeWindow* window, bool sharedBufferMode);
400000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
401000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
402000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*
403000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian * Enable/disable auto refresh when in shared buffer mode
404000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian */
405000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopianint ANativeWindow_setAutoRefresh(ANativeWindow* window, bool autoRefresh);
406000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
407000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian
408000879a0eb2156727a2221e42d04b6f3e150aa79Mathias Agopian/*****************************************************************************/
409a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian
410a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian__END_DECLS
411a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian
412a6c0e20ac89b1be29901a7200590bf7cb8b99f78Mathias Agopian#endif /* ANDROID_VNDK_NATIVEWINDOW_ANATIVEWINDOW_H */
413