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