blob: b8a19c80f341875e9cb7ef58bf334f3fb277d872 [file] [log] [blame]
Iliyan Malchev0ab886b2011-05-01 14:07:43 -07001/*
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
Jamie Gennis22aec572012-06-13 16:43:06 -070020#include <cutils/native_handle.h>
Jesse Hallbc930ed2012-10-01 13:48:36 -070021#include <errno.h>
Jamie Gennis22aec572012-06-13 16:43:06 -070022#include <limits.h>
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070023#include <stdint.h>
Mathias Agopianc958a7f2012-02-25 21:13:36 -080024#include <string.h>
Jamie Gennis22aec572012-06-13 16:43:06 -070025#include <sync/sync.h>
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070026#include <sys/cdefs.h>
27#include <system/graphics.h>
Jamie Gennis22aec572012-06-13 16:43:06 -070028#include <unistd.h>
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070029
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
Jamie Gennis22aec572012-06-13 16:43:06 -070045// 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
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070053typedef 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,
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700124 NATIVE_WINDOW_HEIGHT = 1,
125 NATIVE_WINDOW_FORMAT = 2,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700126
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 */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700145 NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = 3,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700146
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 */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700160 NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700161
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 */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700168 NATIVE_WINDOW_CONCRETE_TYPE = 5,
Mathias Agopian51009162011-07-19 15:59:15 -0700169
170
171 /*
Michael I. Goldafcdef62012-04-09 18:21:13 -0700172 * 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
Jamie Gennisaa3f4c32012-04-17 19:37:48 -0700175 * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
Mathias Agopian51009162011-07-19 15:59:15 -0700176 */
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,
Jamie Gennisaa3f4c32012-04-17 19:37:48 -0700228
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
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700234};
235
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700236/* Valid operations for the (*perform)() hook.
237 *
238 * Values marked as 'deprecated' are supported, but have been superceded by
239 * other functionality.
240 *
241 * Values marked as 'private' should be considered private to the framework.
242 * HAL implementation code with access to an ANativeWindow should not use these,
243 * as it may not interact properly with the framework's use of the
244 * ANativeWindow.
245 */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700246enum {
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700247 NATIVE_WINDOW_SET_USAGE = 0,
Mathias Agopian8ad54522011-07-29 17:52:36 -0700248 NATIVE_WINDOW_CONNECT = 1, /* deprecated */
249 NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700250 NATIVE_WINDOW_SET_CROP = 3, /* private */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700251 NATIVE_WINDOW_SET_BUFFER_COUNT = 4,
252 NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */
253 NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6,
254 NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7,
255 NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8,
256 NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9,
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700257 NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */
Mathias Agopianae3736a2011-07-13 18:40:38 -0700258 NATIVE_WINDOW_LOCK = 11, /* private */
259 NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */
Mathias Agopian8ad54522011-07-29 17:52:36 -0700260 NATIVE_WINDOW_API_CONNECT = 13, /* private */
261 NATIVE_WINDOW_API_DISCONNECT = 14, /* private */
Michael I. Goldafcdef62012-04-09 18:21:13 -0700262 NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
Jamie Gennisd21113a2012-05-03 14:21:24 -0700263 NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* private */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700264};
265
Mathias Agopian8ad54522011-07-29 17:52:36 -0700266/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700267enum {
Jamie Gennis5423e9e2011-07-12 13:53:42 -0700268 /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
269 * OpenGL ES.
270 */
271 NATIVE_WINDOW_API_EGL = 1,
272
273 /* Buffers will be queued after being filled using the CPU
274 */
275 NATIVE_WINDOW_API_CPU = 2,
276
277 /* Buffers will be queued by Stagefright after being filled by a video
278 * decoder. The video decoder can either be a software or hardware decoder.
279 */
280 NATIVE_WINDOW_API_MEDIA = 3,
281
282 /* Buffers will be queued by the the camera HAL.
283 */
284 NATIVE_WINDOW_API_CAMERA = 4,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700285};
286
287/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
288enum {
289 /* flip source image horizontally */
290 NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
291 /* flip source image vertically */
292 NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
293 /* rotate source image 90 degrees clock-wise */
294 NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
295 /* rotate source image 180 degrees */
296 NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
297 /* rotate source image 270 degrees clock-wise */
298 NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
299};
300
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700301/* parameter for NATIVE_WINDOW_SET_SCALING_MODE */
302enum {
303 /* the window content is not updated (frozen) until a buffer of
304 * the window size is received (enqueued)
305 */
306 NATIVE_WINDOW_SCALING_MODE_FREEZE = 0,
307 /* the buffer is scaled in both dimensions to match the window size */
308 NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1,
Daniel Lam29392a42012-04-11 18:19:46 -0700309 /* the buffer is scaled uniformly such that the smaller dimension
310 * of the buffer matches the window size (cropping in the process)
311 */
312 NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2,
Jamie Gennisd21113a2012-05-03 14:21:24 -0700313 /* the window is clipped to the size of the buffer's crop rectangle; pixels
314 * outside the crop rectangle are treated as if they are completely
315 * transparent.
316 */
317 NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3,
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700318};
319
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700320/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
321enum {
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700322 NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
323 NATIVE_WINDOW_SURFACE = 1, /* Surface */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700324};
325
326/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
327 *
328 * Special timestamp value to indicate that timestamps should be auto-generated
329 * by the native window when queueBuffer is called. This is equal to INT64_MIN,
330 * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
331 */
332static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
333
334struct ANativeWindow
335{
336#ifdef __cplusplus
337 ANativeWindow()
338 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
339 {
340 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
341 common.version = sizeof(ANativeWindow);
342 memset(common.reserved, 0, sizeof(common.reserved));
343 }
344
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700345 /* Implement the methods that sp<ANativeWindow> expects so that it
346 can be used to automatically refcount ANativeWindow's. */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700347 void incStrong(const void* id) const {
348 common.incRef(const_cast<android_native_base_t*>(&common));
349 }
350 void decStrong(const void* id) const {
351 common.decRef(const_cast<android_native_base_t*>(&common));
352 }
353#endif
354
355 struct android_native_base_t common;
356
357 /* flags describing some attributes of this surface or its updater */
358 const uint32_t flags;
359
360 /* min swap interval supported by this updated */
361 const int minSwapInterval;
362
363 /* max swap interval supported by this updated */
364 const int maxSwapInterval;
365
366 /* horizontal and vertical resolution in DPI */
367 const float xdpi;
368 const float ydpi;
369
370 /* Some storage reserved for the OEM's driver. */
371 intptr_t oem[4];
372
373 /*
374 * Set the swap interval for this surface.
375 *
376 * Returns 0 on success or -errno on error.
377 */
378 int (*setSwapInterval)(struct ANativeWindow* window,
379 int interval);
380
381 /*
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800382 * Hook called by EGL to acquire a buffer. After this call, the buffer
383 * is not locked, so its content cannot be modified. This call may block if
384 * no buffers are available.
385 *
386 * The window holds a reference to the buffer between dequeueBuffer and
387 * either queueBuffer or cancelBuffer, so clients only need their own
388 * reference if they might use the buffer after queueing or canceling it.
389 * Holding a reference to a buffer after queueing or canceling it is only
390 * allowed if a specific buffer count has been set.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700391 *
392 * Returns 0 on success or -errno on error.
Jamie Gennis22aec572012-06-13 16:43:06 -0700393 *
394 * XXX: This function is deprecated. It will continue to work for some
395 * time for binary compatibility, but the new dequeueBuffer function that
396 * outputs a fence file descriptor should be used in its place.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700397 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700398 int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700399 struct ANativeWindowBuffer** buffer);
400
401 /*
402 * hook called by EGL to lock a buffer. This MUST be called before modifying
403 * the content of a buffer. The buffer must have been acquired with
404 * dequeueBuffer first.
405 *
406 * Returns 0 on success or -errno on error.
Jamie Gennis22aec572012-06-13 16:43:06 -0700407 *
408 * XXX: This function is deprecated. It will continue to work for some
409 * time for binary compatibility, but it is essentially a no-op, and calls
410 * to it should be removed.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700411 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700412 int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700413 struct ANativeWindowBuffer* buffer);
Jamie Gennis22aec572012-06-13 16:43:06 -0700414
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800415 /*
416 * Hook called by EGL when modifications to the render buffer are done.
417 * This unlocks and post the buffer.
418 *
419 * The window holds a reference to the buffer between dequeueBuffer and
420 * either queueBuffer or cancelBuffer, so clients only need their own
421 * reference if they might use the buffer after queueing or canceling it.
422 * Holding a reference to a buffer after queueing or canceling it is only
423 * allowed if a specific buffer count has been set.
424 *
425 * Buffers MUST be queued in the same order than they were dequeued.
426 *
427 * Returns 0 on success or -errno on error.
Jamie Gennis22aec572012-06-13 16:43:06 -0700428 *
429 * XXX: This function is deprecated. It will continue to work for some
430 * time for binary compatibility, but the new queueBuffer function that
431 * takes a fence file descriptor should be used in its place (pass a value
432 * of -1 for the fence file descriptor if there is no valid one to pass).
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800433 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700434 int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700435 struct ANativeWindowBuffer* buffer);
436
437 /*
438 * hook used to retrieve information about the native window.
439 *
440 * Returns 0 on success or -errno on error.
441 */
442 int (*query)(const struct ANativeWindow* window,
443 int what, int* value);
444
445 /*
446 * hook used to perform various operations on the surface.
447 * (*perform)() is a generic mechanism to add functionality to
448 * ANativeWindow while keeping backward binary compatibility.
449 *
450 * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
451 * defined below.
452 *
453 * (*perform)() returns -ENOENT if the 'what' parameter is not supported
454 * by the surface's implementation.
455 *
456 * The valid operations are:
457 * NATIVE_WINDOW_SET_USAGE
Mathias Agopian8ad54522011-07-29 17:52:36 -0700458 * NATIVE_WINDOW_CONNECT (deprecated)
459 * NATIVE_WINDOW_DISCONNECT (deprecated)
Jamie Gennis190b6e22012-04-30 16:32:06 -0700460 * NATIVE_WINDOW_SET_CROP (private)
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700461 * NATIVE_WINDOW_SET_BUFFER_COUNT
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700462 * NATIVE_WINDOW_SET_BUFFERS_GEOMETRY (deprecated)
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700463 * NATIVE_WINDOW_SET_BUFFERS_TRANSFORM
464 * NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700465 * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS
466 * NATIVE_WINDOW_SET_BUFFERS_FORMAT
Jamie Gennis190b6e22012-04-30 16:32:06 -0700467 * NATIVE_WINDOW_SET_SCALING_MODE (private)
Mathias Agopianae3736a2011-07-13 18:40:38 -0700468 * NATIVE_WINDOW_LOCK (private)
469 * NATIVE_WINDOW_UNLOCK_AND_POST (private)
Mathias Agopian8ad54522011-07-29 17:52:36 -0700470 * NATIVE_WINDOW_API_CONNECT (private)
471 * NATIVE_WINDOW_API_DISCONNECT (private)
Michael I. Goldafcdef62012-04-09 18:21:13 -0700472 * NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS (private)
Jamie Gennisd21113a2012-05-03 14:21:24 -0700473 * NATIVE_WINDOW_SET_POST_TRANSFORM_CROP (private)
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700474 *
475 */
476
477 int (*perform)(struct ANativeWindow* window,
478 int operation, ... );
479
480 /*
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800481 * Hook used to cancel a buffer that has been dequeued.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700482 * No synchronization is performed between dequeue() and cancel(), so
483 * either external synchronization is needed, or these functions must be
484 * called from the same thread.
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800485 *
486 * The window holds a reference to the buffer between dequeueBuffer and
487 * either queueBuffer or cancelBuffer, so clients only need their own
488 * reference if they might use the buffer after queueing or canceling it.
489 * Holding a reference to a buffer after queueing or canceling it is only
490 * allowed if a specific buffer count has been set.
Jamie Gennis22aec572012-06-13 16:43:06 -0700491 *
492 * XXX: This function is deprecated. It will continue to work for some
493 * time for binary compatibility, but the new cancelBuffer function that
494 * takes a fence file descriptor should be used in its place (pass a value
495 * of -1 for the fence file descriptor if there is no valid one to pass).
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700496 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700497 int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700498 struct ANativeWindowBuffer* buffer);
499
Jamie Gennis22aec572012-06-13 16:43:06 -0700500 /*
501 * Hook called by EGL to acquire a buffer. This call may block if no
502 * buffers are available.
503 *
504 * The window holds a reference to the buffer between dequeueBuffer and
505 * either queueBuffer or cancelBuffer, so clients only need their own
506 * reference if they might use the buffer after queueing or canceling it.
507 * Holding a reference to a buffer after queueing or canceling it is only
508 * allowed if a specific buffer count has been set.
509 *
510 * The libsync fence file descriptor returned in the int pointed to by the
511 * fenceFd argument will refer to the fence that must signal before the
512 * dequeued buffer may be written to. A value of -1 indicates that the
513 * caller may access the buffer immediately without waiting on a fence. If
514 * a valid file descriptor is returned (i.e. any value except -1) then the
515 * caller is responsible for closing the file descriptor.
516 *
517 * Returns 0 on success or -errno on error.
518 */
519 int (*dequeueBuffer)(struct ANativeWindow* window,
520 struct ANativeWindowBuffer** buffer, int* fenceFd);
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700521
Jamie Gennis22aec572012-06-13 16:43:06 -0700522 /*
523 * Hook called by EGL when modifications to the render buffer are done.
524 * This unlocks and post the buffer.
525 *
526 * The window holds a reference to the buffer between dequeueBuffer and
527 * either queueBuffer or cancelBuffer, so clients only need their own
528 * reference if they might use the buffer after queueing or canceling it.
529 * Holding a reference to a buffer after queueing or canceling it is only
530 * allowed if a specific buffer count has been set.
531 *
532 * The fenceFd argument specifies a libsync fence file descriptor for a
533 * fence that must signal before the buffer can be accessed. If the buffer
534 * can be accessed immediately then a value of -1 should be used. The
535 * caller must not use the file descriptor after it is passed to
536 * queueBuffer, and the ANativeWindow implementation is responsible for
537 * closing it.
538 *
539 * Returns 0 on success or -errno on error.
540 */
541 int (*queueBuffer)(struct ANativeWindow* window,
542 struct ANativeWindowBuffer* buffer, int fenceFd);
543
544 /*
545 * Hook used to cancel a buffer that has been dequeued.
546 * No synchronization is performed between dequeue() and cancel(), so
547 * either external synchronization is needed, or these functions must be
548 * called from the same thread.
549 *
550 * The window holds a reference to the buffer between dequeueBuffer and
551 * either queueBuffer or cancelBuffer, so clients only need their own
552 * reference if they might use the buffer after queueing or canceling it.
553 * Holding a reference to a buffer after queueing or canceling it is only
554 * allowed if a specific buffer count has been set.
555 *
556 * The fenceFd argument specifies a libsync fence file decsriptor for a
557 * fence that must signal before the buffer can be accessed. If the buffer
558 * can be accessed immediately then a value of -1 should be used.
559 *
560 * Note that if the client has not waited on the fence that was returned
561 * from dequeueBuffer, that same fence should be passed to cancelBuffer to
562 * ensure that future uses of the buffer are preceded by a wait on that
563 * fence. The caller must not use the file descriptor after it is passed
564 * to cancelBuffer, and the ANativeWindow implementation is responsible for
565 * closing it.
566 *
567 * Returns 0 on success or -errno on error.
568 */
569 int (*cancelBuffer)(struct ANativeWindow* window,
570 struct ANativeWindowBuffer* buffer, int fenceFd);
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700571};
572
573 /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
574 * android_native_window_t is deprecated.
575 */
576typedef struct ANativeWindow ANativeWindow;
577typedef struct ANativeWindow android_native_window_t;
578
579/*
580 * native_window_set_usage(..., usage)
581 * Sets the intended usage flags for the next buffers
582 * acquired with (*lockBuffer)() and on.
583 * By default (if this function is never called), a usage of
584 * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE
585 * is assumed.
586 * Calling this function will usually cause following buffers to be
587 * reallocated.
588 */
589
590static inline int native_window_set_usage(
591 struct ANativeWindow* window, int usage)
592{
593 return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage);
594}
595
Mathias Agopian8ad54522011-07-29 17:52:36 -0700596/* deprecated. Always returns 0. Don't call. */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700597static inline int native_window_connect(
Mathias Agopian8ad54522011-07-29 17:52:36 -0700598 struct ANativeWindow* window, int api) {
Mathias Agopian319f4e22011-08-03 11:26:38 -0700599 return 0;
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700600}
601
Mathias Agopian8ad54522011-07-29 17:52:36 -0700602/* deprecated. Always returns 0. Don't call. */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700603static inline int native_window_disconnect(
Mathias Agopian8ad54522011-07-29 17:52:36 -0700604 struct ANativeWindow* window, int api) {
Mathias Agopian319f4e22011-08-03 11:26:38 -0700605 return 0;
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700606}
607
608/*
609 * native_window_set_crop(..., crop)
610 * Sets which region of the next queued buffers needs to be considered.
Jamie Gennisd21113a2012-05-03 14:21:24 -0700611 * Depending on the scaling mode, a buffer's crop region is scaled and/or
612 * cropped to match the surface's size. This function sets the crop in
613 * pre-transformed buffer pixel coordinates.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700614 *
615 * The specified crop region applies to all buffers queued after it is called.
616 *
Jamie Gennisd21113a2012-05-03 14:21:24 -0700617 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700618 *
Jamie Gennisd21113a2012-05-03 14:21:24 -0700619 * An error is returned if for instance the crop region is invalid, out of the
620 * buffer's bound or if the window is invalid.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700621 */
622static inline int native_window_set_crop(
623 struct ANativeWindow* window,
624 android_native_rect_t const * crop)
625{
626 return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
627}
628
629/*
Jamie Gennisd21113a2012-05-03 14:21:24 -0700630 * native_window_set_post_transform_crop(..., crop)
631 * Sets which region of the next queued buffers needs to be considered.
632 * Depending on the scaling mode, a buffer's crop region is scaled and/or
633 * cropped to match the surface's size. This function sets the crop in
634 * post-transformed pixel coordinates.
635 *
636 * The specified crop region applies to all buffers queued after it is called.
637 *
638 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
639 *
640 * An error is returned if for instance the crop region is invalid, out of the
641 * buffer's bound or if the window is invalid.
642 */
643static inline int native_window_set_post_transform_crop(
644 struct ANativeWindow* window,
645 android_native_rect_t const * crop)
646{
647 return window->perform(window, NATIVE_WINDOW_SET_POST_TRANSFORM_CROP, crop);
648}
649
650/*
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700651 * native_window_set_active_rect(..., active_rect)
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700652 *
Jamie Gennis22aec572012-06-13 16:43:06 -0700653 * This function is deprecated and will be removed soon. For now it simply
Jamie Gennisd21113a2012-05-03 14:21:24 -0700654 * sets the post-transform crop for compatibility while multi-project commits
655 * get checked.
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700656 */
657static inline int native_window_set_active_rect(
658 struct ANativeWindow* window,
659 android_native_rect_t const * active_rect)
660{
Jamie Gennisd21113a2012-05-03 14:21:24 -0700661 return native_window_set_post_transform_crop(window, active_rect);
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700662}
663
664/*
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700665 * native_window_set_buffer_count(..., count)
666 * Sets the number of buffers associated with this native window.
667 */
668static inline int native_window_set_buffer_count(
669 struct ANativeWindow* window,
670 size_t bufferCount)
671{
672 return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
673}
674
675/*
676 * native_window_set_buffers_geometry(..., int w, int h, int format)
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700677 * All buffers dequeued after this call will have the dimensions and format
678 * specified. A successful call to this function has the same effect as calling
679 * native_window_set_buffers_size and native_window_set_buffers_format.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700680 *
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700681 * XXX: This function is deprecated. The native_window_set_buffers_dimensions
682 * and native_window_set_buffers_format functions should be used instead.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700683 */
684static inline int native_window_set_buffers_geometry(
685 struct ANativeWindow* window,
686 int w, int h, int format)
687{
688 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
689 w, h, format);
690}
691
692/*
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700693 * native_window_set_buffers_dimensions(..., int w, int h)
694 * All buffers dequeued after this call will have the dimensions specified.
Michael I. Goldafcdef62012-04-09 18:21:13 -0700695 * In particular, all buffers will have a fixed-size, independent from the
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700696 * native-window size. They will be scaled according to the scaling mode
697 * (see native_window_set_scaling_mode) upon window composition.
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700698 *
699 * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
700 * following this call will be sized to match the window's size.
701 *
702 * Calling this function will reset the window crop to a NULL value, which
703 * disables cropping of the buffers.
704 */
705static inline int native_window_set_buffers_dimensions(
706 struct ANativeWindow* window,
707 int w, int h)
708{
709 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
710 w, h);
711}
712
713/*
Michael I. Goldafcdef62012-04-09 18:21:13 -0700714 * native_window_set_buffers_user_dimensions(..., int w, int h)
715 *
716 * Sets the user buffer size for the window, which overrides the
717 * window's size. All buffers dequeued after this call will have the
718 * dimensions specified unless overridden by
719 * native_window_set_buffers_dimensions. All buffers will have a
720 * fixed-size, independent from the native-window size. They will be
721 * scaled according to the scaling mode (see
722 * native_window_set_scaling_mode) upon window composition.
723 *
724 * If w and h are 0, the normal behavior is restored. That is, the
725 * default buffer size will match the windows's size.
726 *
727 * Calling this function will reset the window crop to a NULL value, which
728 * disables cropping of the buffers.
729 */
730static inline int native_window_set_buffers_user_dimensions(
731 struct ANativeWindow* window,
732 int w, int h)
733{
734 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
735 w, h);
736}
737
738/*
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700739 * native_window_set_buffers_format(..., int format)
740 * All buffers dequeued after this call will have the format specified.
741 *
742 * If the specified format is 0, the default buffer format will be used.
743 */
744static inline int native_window_set_buffers_format(
745 struct ANativeWindow* window,
746 int format)
747{
748 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
749}
750
751/*
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700752 * native_window_set_buffers_transform(..., int transform)
753 * All buffers queued after this call will be displayed transformed according
754 * to the transform parameter specified.
755 */
756static inline int native_window_set_buffers_transform(
757 struct ANativeWindow* window,
758 int transform)
759{
760 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
761 transform);
762}
763
764/*
765 * native_window_set_buffers_timestamp(..., int64_t timestamp)
766 * All buffers queued after this call will be associated with the timestamp
767 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
768 * (the default), timestamps will be generated automatically when queueBuffer is
Glenn Kastenc322f672011-06-27 10:42:39 -0700769 * called. The timestamp is measured in nanoseconds, and is normally monotonically
770 * increasing. The timestamp should be unaffected by time-of-day adjustments,
771 * and for a camera should be strictly monotonic but for a media player may be
772 * reset when the position is set.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700773 */
774static inline int native_window_set_buffers_timestamp(
775 struct ANativeWindow* window,
776 int64_t timestamp)
777{
778 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
779 timestamp);
780}
781
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700782/*
783 * native_window_set_scaling_mode(..., int mode)
784 * All buffers queued after this call will be associated with the scaling mode
785 * specified.
786 */
787static inline int native_window_set_scaling_mode(
788 struct ANativeWindow* window,
789 int mode)
790{
791 return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
792 mode);
793}
794
Mathias Agopian8ad54522011-07-29 17:52:36 -0700795/*
796 * native_window_api_connect(..., int api)
797 * connects an API to this window. only one API can be connected at a time.
798 * Returns -EINVAL if for some reason the window cannot be connected, which
799 * can happen if it's connected to some other API.
800 */
801static inline int native_window_api_connect(
802 struct ANativeWindow* window, int api)
803{
Mathias Agopian319f4e22011-08-03 11:26:38 -0700804 return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
Mathias Agopian8ad54522011-07-29 17:52:36 -0700805}
806
807/*
808 * native_window_api_disconnect(..., int api)
809 * disconnect the API from this window.
810 * An error is returned if for instance the window wasn't connected in the
811 * first place.
812 */
813static inline int native_window_api_disconnect(
814 struct ANativeWindow* window, int api)
815{
Mathias Agopian319f4e22011-08-03 11:26:38 -0700816 return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
Mathias Agopian8ad54522011-07-29 17:52:36 -0700817}
818
Jamie Gennis22aec572012-06-13 16:43:06 -0700819/*
820 * native_window_dequeue_buffer_and_wait(...)
821 * Dequeue a buffer and wait on the fence associated with that buffer. The
822 * buffer may safely be accessed immediately upon this function returning. An
823 * error is returned if either of the dequeue or the wait operations fail.
824 */
825static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
826 struct ANativeWindowBuffer** anb) {
Jesse Hallbc930ed2012-10-01 13:48:36 -0700827 return anw->dequeueBuffer_DEPRECATED(anw, anb);
Jamie Gennis22aec572012-06-13 16:43:06 -0700828}
829
Mathias Agopian8ad54522011-07-29 17:52:36 -0700830
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700831__END_DECLS
832
tedbo1ffdb382011-05-24 00:55:33 -0700833#endif /* SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H */