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