~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to include/android_stub/system/window.h

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

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