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