blob: 588f9c67499576554dbbdcc71d23e4655adba3e4 [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>
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070025#include <sys/cdefs.h>
26#include <system/graphics.h>
Jamie Gennis22aec572012-06-13 16:43:06 -070027#include <unistd.h>
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070028
29__BEGIN_DECLS
30
31/*****************************************************************************/
32
33#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \
34 (((unsigned)(a)<<24)|((unsigned)(b)<<16)|((unsigned)(c)<<8)|(unsigned)(d))
35
36#define ANDROID_NATIVE_WINDOW_MAGIC \
37 ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
38
39#define ANDROID_NATIVE_BUFFER_MAGIC \
40 ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
41
42// ---------------------------------------------------------------------------
43
Jamie Gennis22aec572012-06-13 16:43:06 -070044// This #define may be used to conditionally compile device-specific code to
45// support either the prior ANativeWindow interface, which did not pass libsync
46// fences around, or the new interface that does. This #define is only present
47// when the ANativeWindow interface does include libsync support.
48#define ANDROID_NATIVE_WINDOW_HAS_SYNC 1
49
50// ---------------------------------------------------------------------------
51
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070052typedef const native_handle_t* buffer_handle_t;
53
54// ---------------------------------------------------------------------------
55
56typedef struct android_native_rect_t
57{
58 int32_t left;
59 int32_t top;
60 int32_t right;
61 int32_t bottom;
62} android_native_rect_t;
63
64// ---------------------------------------------------------------------------
65
66typedef struct android_native_base_t
67{
68 /* a magic value defined by the actual EGL native type */
69 int magic;
70
71 /* the sizeof() of the actual EGL native type */
72 int version;
73
74 void* reserved[4];
75
76 /* reference-counting interface */
77 void (*incRef)(struct android_native_base_t* base);
78 void (*decRef)(struct android_native_base_t* base);
79} android_native_base_t;
80
81typedef struct ANativeWindowBuffer
82{
83#ifdef __cplusplus
84 ANativeWindowBuffer() {
85 common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
86 common.version = sizeof(ANativeWindowBuffer);
87 memset(common.reserved, 0, sizeof(common.reserved));
88 }
89
90 // Implement the methods that sp<ANativeWindowBuffer> expects so that it
91 // can be used to automatically refcount ANativeWindowBuffer's.
92 void incStrong(const void* id) const {
93 common.incRef(const_cast<android_native_base_t*>(&common));
94 }
95 void decStrong(const void* id) const {
96 common.decRef(const_cast<android_native_base_t*>(&common));
97 }
98#endif
99
100 struct android_native_base_t common;
101
102 int width;
103 int height;
104 int stride;
105 int format;
106 int usage;
107
108 void* reserved[2];
109
110 buffer_handle_t handle;
111
112 void* reserved_proc[8];
113} ANativeWindowBuffer_t;
114
115// Old typedef for backwards compatibility.
116typedef ANativeWindowBuffer_t android_native_buffer_t;
117
118// ---------------------------------------------------------------------------
119
120/* attributes queriable with query() */
121enum {
122 NATIVE_WINDOW_WIDTH = 0,
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700123 NATIVE_WINDOW_HEIGHT = 1,
124 NATIVE_WINDOW_FORMAT = 2,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700125
126 /* The minimum number of buffers that must remain un-dequeued after a buffer
127 * has been queued. This value applies only if set_buffer_count was used to
128 * override the number of buffers and if a buffer has since been queued.
129 * Users of the set_buffer_count ANativeWindow method should query this
130 * value before calling set_buffer_count. If it is necessary to have N
131 * buffers simultaneously dequeued as part of the steady-state operation,
132 * and this query returns M then N+M buffers should be requested via
133 * native_window_set_buffer_count.
134 *
135 * Note that this value does NOT apply until a single buffer has been
136 * queued. In particular this means that it is possible to:
137 *
138 * 1. Query M = min undequeued buffers
139 * 2. Set the buffer count to N + M
140 * 3. Dequeue all N + M buffers
141 * 4. Cancel M buffers
142 * 5. Queue, dequeue, queue, dequeue, ad infinitum
143 */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700144 NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = 3,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700145
146 /* Check whether queueBuffer operations on the ANativeWindow send the buffer
147 * to the window compositor. The query sets the returned 'value' argument
148 * to 1 if the ANativeWindow DOES send queued buffers directly to the window
149 * compositor and 0 if the buffers do not go directly to the window
150 * compositor.
151 *
152 * This can be used to determine whether protected buffer content should be
153 * sent to the ANativeWindow. Note, however, that a result of 1 does NOT
154 * indicate that queued buffers will be protected from applications or users
155 * capturing their contents. If that behavior is desired then some other
156 * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
157 * conjunction with this query.
158 */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700159 NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700160
161 /* Get the concrete type of a ANativeWindow. See below for the list of
162 * possible return values.
163 *
164 * This query should not be used outside the Android framework and will
165 * likely be removed in the near future.
166 */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700167 NATIVE_WINDOW_CONCRETE_TYPE = 5,
Mathias Agopian51009162011-07-19 15:59:15 -0700168
169
170 /*
Michael I. Goldafcdef62012-04-09 18:21:13 -0700171 * Default width and height of ANativeWindow buffers, these are the
172 * dimensions of the window buffers irrespective of the
173 * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window
Jamie Gennisaa3f4c32012-04-17 19:37:48 -0700174 * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
Mathias Agopian51009162011-07-19 15:59:15 -0700175 */
176 NATIVE_WINDOW_DEFAULT_WIDTH = 6,
177 NATIVE_WINDOW_DEFAULT_HEIGHT = 7,
178
179 /*
180 * transformation that will most-likely be applied to buffers. This is only
181 * a hint, the actual transformation applied might be different.
182 *
183 * INTENDED USE:
184 *
185 * The transform hint can be used by a producer, for instance the GLES
186 * driver, to pre-rotate the rendering such that the final transformation
187 * in the composer is identity. This can be very useful when used in
188 * conjunction with the h/w composer HAL, in situations where it
189 * cannot handle arbitrary rotations.
190 *
191 * 1. Before dequeuing a buffer, the GL driver (or any other ANW client)
192 * queries the ANW for NATIVE_WINDOW_TRANSFORM_HINT.
193 *
194 * 2. The GL driver overrides the width and height of the ANW to
195 * account for NATIVE_WINDOW_TRANSFORM_HINT. This is done by querying
196 * NATIVE_WINDOW_DEFAULT_{WIDTH | HEIGHT}, swapping the dimensions
197 * according to NATIVE_WINDOW_TRANSFORM_HINT and calling
198 * native_window_set_buffers_dimensions().
199 *
200 * 3. The GL driver dequeues a buffer of the new pre-rotated size.
201 *
202 * 4. The GL driver renders to the buffer such that the image is
203 * already transformed, that is applying NATIVE_WINDOW_TRANSFORM_HINT
204 * to the rendering.
205 *
206 * 5. The GL driver calls native_window_set_transform to apply
207 * inverse transformation to the buffer it just rendered.
208 * In order to do this, the GL driver needs
209 * to calculate the inverse of NATIVE_WINDOW_TRANSFORM_HINT, this is
210 * done easily:
211 *
212 * int hintTransform, inverseTransform;
213 * query(..., NATIVE_WINDOW_TRANSFORM_HINT, &hintTransform);
214 * inverseTransform = hintTransform;
215 * if (hintTransform & HAL_TRANSFORM_ROT_90)
216 * inverseTransform ^= HAL_TRANSFORM_ROT_180;
217 *
218 *
219 * 6. The GL driver queues the pre-transformed buffer.
220 *
221 * 7. The composer combines the buffer transform with the display
222 * transform. If the buffer transform happens to cancel out the
223 * display transform then no rotation is needed.
224 *
225 */
226 NATIVE_WINDOW_TRANSFORM_HINT = 8,
Jamie Gennisaa3f4c32012-04-17 19:37:48 -0700227
228 /*
229 * Boolean that indicates whether the consumer is running more than
230 * one buffer behind the producer.
231 */
Eino-Ville Talvalaf88a5b42013-07-30 14:07:08 -0700232 NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9,
233
234 /*
235 * The consumer gralloc usage bits currently set by the consumer.
236 * The values are defined in hardware/libhardware/include/gralloc.h.
237 */
238 NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700239};
240
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700241/* Valid operations for the (*perform)() hook.
242 *
243 * Values marked as 'deprecated' are supported, but have been superceded by
244 * other functionality.
245 *
246 * Values marked as 'private' should be considered private to the framework.
247 * HAL implementation code with access to an ANativeWindow should not use these,
248 * as it may not interact properly with the framework's use of the
249 * ANativeWindow.
250 */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700251enum {
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700252 NATIVE_WINDOW_SET_USAGE = 0,
Mathias Agopian8ad54522011-07-29 17:52:36 -0700253 NATIVE_WINDOW_CONNECT = 1, /* deprecated */
254 NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700255 NATIVE_WINDOW_SET_CROP = 3, /* private */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700256 NATIVE_WINDOW_SET_BUFFER_COUNT = 4,
257 NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */
258 NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6,
259 NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7,
260 NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8,
261 NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9,
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700262 NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */
Mathias Agopianae3736a2011-07-13 18:40:38 -0700263 NATIVE_WINDOW_LOCK = 11, /* private */
264 NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */
Mathias Agopian8ad54522011-07-29 17:52:36 -0700265 NATIVE_WINDOW_API_CONNECT = 13, /* private */
266 NATIVE_WINDOW_API_DISCONNECT = 14, /* private */
Michael I. Goldafcdef62012-04-09 18:21:13 -0700267 NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
Jamie Gennisd21113a2012-05-03 14:21:24 -0700268 NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* private */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700269};
270
Mathias Agopian8ad54522011-07-29 17:52:36 -0700271/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700272enum {
Jamie Gennis5423e9e2011-07-12 13:53:42 -0700273 /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
274 * OpenGL ES.
275 */
276 NATIVE_WINDOW_API_EGL = 1,
277
278 /* Buffers will be queued after being filled using the CPU
279 */
280 NATIVE_WINDOW_API_CPU = 2,
281
282 /* Buffers will be queued by Stagefright after being filled by a video
283 * decoder. The video decoder can either be a software or hardware decoder.
284 */
285 NATIVE_WINDOW_API_MEDIA = 3,
286
287 /* Buffers will be queued by the the camera HAL.
288 */
289 NATIVE_WINDOW_API_CAMERA = 4,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700290};
291
292/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
293enum {
294 /* flip source image horizontally */
295 NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
296 /* flip source image vertically */
297 NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Mathias Agopian96675ed2013-09-17 23:48:54 -0700298 /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700299 NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
300 /* rotate source image 180 degrees */
301 NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
302 /* rotate source image 270 degrees clock-wise */
303 NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Mathias Agopian96675ed2013-09-17 23:48:54 -0700304 /* transforms source by the inverse transform of the screen it is displayed onto. This
305 * transform is applied last */
306 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700307};
308
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700309/* parameter for NATIVE_WINDOW_SET_SCALING_MODE */
310enum {
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,
Daniel Lam29392a42012-04-11 18:19:46 -0700317 /* 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,
Jamie Gennisd21113a2012-05-03 14:21:24 -0700321 /* 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,
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700326};
327
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700328/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
329enum {
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700330 NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
331 NATIVE_WINDOW_SURFACE = 1, /* Surface */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700332};
333
334/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
335 *
336 * Special timestamp value to indicate that timestamps should be auto-generated
337 * by the native window when queueBuffer is called. This is equal to INT64_MIN,
338 * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
339 */
340static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
341
342struct ANativeWindow
343{
344#ifdef __cplusplus
345 ANativeWindow()
346 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
347 {
348 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
349 common.version = sizeof(ANativeWindow);
350 memset(common.reserved, 0, sizeof(common.reserved));
351 }
352
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700353 /* Implement the methods that sp<ANativeWindow> expects so that it
354 can be used to automatically refcount ANativeWindow's. */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700355 void incStrong(const void* id) const {
356 common.incRef(const_cast<android_native_base_t*>(&common));
357 }
358 void decStrong(const void* id) const {
359 common.decRef(const_cast<android_native_base_t*>(&common));
360 }
361#endif
362
363 struct android_native_base_t common;
364
365 /* flags describing some attributes of this surface or its updater */
366 const uint32_t flags;
367
368 /* min swap interval supported by this updated */
369 const int minSwapInterval;
370
371 /* max swap interval supported by this updated */
372 const int maxSwapInterval;
373
374 /* horizontal and vertical resolution in DPI */
375 const float xdpi;
376 const float ydpi;
377
378 /* Some storage reserved for the OEM's driver. */
379 intptr_t oem[4];
380
381 /*
382 * Set the swap interval for this surface.
383 *
384 * Returns 0 on success or -errno on error.
385 */
386 int (*setSwapInterval)(struct ANativeWindow* window,
387 int interval);
388
389 /*
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800390 * Hook called by EGL to acquire a buffer. After this call, the buffer
391 * is not locked, so its content cannot be modified. This call may block if
392 * no buffers are available.
393 *
394 * The window holds a reference to the buffer between dequeueBuffer and
395 * either queueBuffer or cancelBuffer, so clients only need their own
396 * reference if they might use the buffer after queueing or canceling it.
397 * Holding a reference to a buffer after queueing or canceling it is only
398 * allowed if a specific buffer count has been set.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700399 *
400 * Returns 0 on success or -errno on error.
Jamie Gennis22aec572012-06-13 16:43:06 -0700401 *
402 * XXX: This function is deprecated. It will continue to work for some
403 * time for binary compatibility, but the new dequeueBuffer function that
404 * outputs a fence file descriptor should be used in its place.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700405 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700406 int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700407 struct ANativeWindowBuffer** buffer);
408
409 /*
410 * hook called by EGL to lock a buffer. This MUST be called before modifying
411 * the content of a buffer. The buffer must have been acquired with
412 * dequeueBuffer first.
413 *
414 * Returns 0 on success or -errno on error.
Jamie Gennis22aec572012-06-13 16:43:06 -0700415 *
416 * XXX: This function is deprecated. It will continue to work for some
417 * time for binary compatibility, but it is essentially a no-op, and calls
418 * to it should be removed.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700419 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700420 int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700421 struct ANativeWindowBuffer* buffer);
Jamie Gennis22aec572012-06-13 16:43:06 -0700422
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800423 /*
424 * Hook called by EGL when modifications to the render buffer are done.
425 * This unlocks and post the buffer.
426 *
427 * The window holds a reference to the buffer between dequeueBuffer and
428 * either queueBuffer or cancelBuffer, so clients only need their own
429 * reference if they might use the buffer after queueing or canceling it.
430 * Holding a reference to a buffer after queueing or canceling it is only
431 * allowed if a specific buffer count has been set.
432 *
433 * Buffers MUST be queued in the same order than they were dequeued.
434 *
435 * Returns 0 on success or -errno on error.
Jamie Gennis22aec572012-06-13 16:43:06 -0700436 *
437 * XXX: This function is deprecated. It will continue to work for some
438 * time for binary compatibility, but the new queueBuffer function that
439 * takes a fence file descriptor should be used in its place (pass a value
440 * of -1 for the fence file descriptor if there is no valid one to pass).
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800441 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700442 int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700443 struct ANativeWindowBuffer* buffer);
444
445 /*
446 * hook used to retrieve information about the native window.
447 *
448 * Returns 0 on success or -errno on error.
449 */
450 int (*query)(const struct ANativeWindow* window,
451 int what, int* value);
452
453 /*
454 * hook used to perform various operations on the surface.
455 * (*perform)() is a generic mechanism to add functionality to
456 * ANativeWindow while keeping backward binary compatibility.
457 *
458 * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
459 * defined below.
460 *
461 * (*perform)() returns -ENOENT if the 'what' parameter is not supported
462 * by the surface's implementation.
463 *
464 * The valid operations are:
465 * NATIVE_WINDOW_SET_USAGE
Mathias Agopian8ad54522011-07-29 17:52:36 -0700466 * NATIVE_WINDOW_CONNECT (deprecated)
467 * NATIVE_WINDOW_DISCONNECT (deprecated)
Jamie Gennis190b6e22012-04-30 16:32:06 -0700468 * NATIVE_WINDOW_SET_CROP (private)
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700469 * NATIVE_WINDOW_SET_BUFFER_COUNT
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700470 * NATIVE_WINDOW_SET_BUFFERS_GEOMETRY (deprecated)
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700471 * NATIVE_WINDOW_SET_BUFFERS_TRANSFORM
472 * NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700473 * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS
474 * NATIVE_WINDOW_SET_BUFFERS_FORMAT
Jamie Gennis190b6e22012-04-30 16:32:06 -0700475 * NATIVE_WINDOW_SET_SCALING_MODE (private)
Mathias Agopianae3736a2011-07-13 18:40:38 -0700476 * NATIVE_WINDOW_LOCK (private)
477 * NATIVE_WINDOW_UNLOCK_AND_POST (private)
Mathias Agopian8ad54522011-07-29 17:52:36 -0700478 * NATIVE_WINDOW_API_CONNECT (private)
479 * NATIVE_WINDOW_API_DISCONNECT (private)
Michael I. Goldafcdef62012-04-09 18:21:13 -0700480 * NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS (private)
Jamie Gennisd21113a2012-05-03 14:21:24 -0700481 * NATIVE_WINDOW_SET_POST_TRANSFORM_CROP (private)
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700482 *
483 */
484
485 int (*perform)(struct ANativeWindow* window,
486 int operation, ... );
487
488 /*
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800489 * Hook used to cancel a buffer that has been dequeued.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700490 * No synchronization is performed between dequeue() and cancel(), so
491 * either external synchronization is needed, or these functions must be
492 * called from the same thread.
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800493 *
494 * The window holds a reference to the buffer between dequeueBuffer and
495 * either queueBuffer or cancelBuffer, so clients only need their own
496 * reference if they might use the buffer after queueing or canceling it.
497 * Holding a reference to a buffer after queueing or canceling it is only
498 * allowed if a specific buffer count has been set.
Jamie Gennis22aec572012-06-13 16:43:06 -0700499 *
500 * XXX: This function is deprecated. It will continue to work for some
501 * time for binary compatibility, but the new cancelBuffer function that
502 * takes a fence file descriptor should be used in its place (pass a value
503 * of -1 for the fence file descriptor if there is no valid one to pass).
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700504 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700505 int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700506 struct ANativeWindowBuffer* buffer);
507
Jamie Gennis22aec572012-06-13 16:43:06 -0700508 /*
509 * Hook called by EGL to acquire a buffer. This call may block if no
510 * buffers are available.
511 *
512 * The window holds a reference to the buffer between dequeueBuffer and
513 * either queueBuffer or cancelBuffer, so clients only need their own
514 * reference if they might use the buffer after queueing or canceling it.
515 * Holding a reference to a buffer after queueing or canceling it is only
516 * allowed if a specific buffer count has been set.
517 *
518 * The libsync fence file descriptor returned in the int pointed to by the
519 * fenceFd argument will refer to the fence that must signal before the
520 * dequeued buffer may be written to. A value of -1 indicates that the
521 * caller may access the buffer immediately without waiting on a fence. If
522 * a valid file descriptor is returned (i.e. any value except -1) then the
523 * caller is responsible for closing the file descriptor.
524 *
525 * Returns 0 on success or -errno on error.
526 */
527 int (*dequeueBuffer)(struct ANativeWindow* window,
528 struct ANativeWindowBuffer** buffer, int* fenceFd);
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700529
Jamie Gennis22aec572012-06-13 16:43:06 -0700530 /*
531 * Hook called by EGL when modifications to the render buffer are done.
532 * This unlocks and post the buffer.
533 *
534 * The window holds a reference to the buffer between dequeueBuffer and
535 * either queueBuffer or cancelBuffer, so clients only need their own
536 * reference if they might use the buffer after queueing or canceling it.
537 * Holding a reference to a buffer after queueing or canceling it is only
538 * allowed if a specific buffer count has been set.
539 *
540 * The fenceFd argument specifies a libsync fence file descriptor for a
541 * fence that must signal before the buffer can be accessed. If the buffer
542 * can be accessed immediately then a value of -1 should be used. The
543 * caller must not use the file descriptor after it is passed to
544 * queueBuffer, and the ANativeWindow implementation is responsible for
545 * closing it.
546 *
547 * Returns 0 on success or -errno on error.
548 */
549 int (*queueBuffer)(struct ANativeWindow* window,
550 struct ANativeWindowBuffer* buffer, int fenceFd);
551
552 /*
553 * Hook used to cancel a buffer that has been dequeued.
554 * No synchronization is performed between dequeue() and cancel(), so
555 * either external synchronization is needed, or these functions must be
556 * called from the same thread.
557 *
558 * The window holds a reference to the buffer between dequeueBuffer and
559 * either queueBuffer or cancelBuffer, so clients only need their own
560 * reference if they might use the buffer after queueing or canceling it.
561 * Holding a reference to a buffer after queueing or canceling it is only
562 * allowed if a specific buffer count has been set.
563 *
564 * The fenceFd argument specifies a libsync fence file decsriptor for a
565 * fence that must signal before the buffer can be accessed. If the buffer
566 * can be accessed immediately then a value of -1 should be used.
567 *
568 * Note that if the client has not waited on the fence that was returned
569 * from dequeueBuffer, that same fence should be passed to cancelBuffer to
570 * ensure that future uses of the buffer are preceded by a wait on that
571 * fence. The caller must not use the file descriptor after it is passed
572 * to cancelBuffer, and the ANativeWindow implementation is responsible for
573 * closing it.
574 *
575 * Returns 0 on success or -errno on error.
576 */
577 int (*cancelBuffer)(struct ANativeWindow* window,
578 struct ANativeWindowBuffer* buffer, int fenceFd);
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700579};
580
581 /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
582 * android_native_window_t is deprecated.
583 */
584typedef struct ANativeWindow ANativeWindow;
585typedef struct ANativeWindow android_native_window_t;
586
587/*
588 * native_window_set_usage(..., usage)
589 * Sets the intended usage flags for the next buffers
590 * acquired with (*lockBuffer)() and on.
591 * By default (if this function is never called), a usage of
592 * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE
593 * is assumed.
594 * Calling this function will usually cause following buffers to be
595 * reallocated.
596 */
597
598static inline int native_window_set_usage(
599 struct ANativeWindow* window, int usage)
600{
601 return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage);
602}
603
Mathias Agopian8ad54522011-07-29 17:52:36 -0700604/* deprecated. Always returns 0. Don't call. */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700605static inline int native_window_connect(
Mathias Agopian8ad54522011-07-29 17:52:36 -0700606 struct ANativeWindow* window, int api) {
Mathias Agopian319f4e22011-08-03 11:26:38 -0700607 return 0;
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700608}
609
Mathias Agopian8ad54522011-07-29 17:52:36 -0700610/* deprecated. Always returns 0. Don't call. */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700611static inline int native_window_disconnect(
Mathias Agopian8ad54522011-07-29 17:52:36 -0700612 struct ANativeWindow* window, int api) {
Mathias Agopian319f4e22011-08-03 11:26:38 -0700613 return 0;
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700614}
615
616/*
617 * native_window_set_crop(..., crop)
618 * Sets which region of the next queued buffers needs to be considered.
Jamie Gennisd21113a2012-05-03 14:21:24 -0700619 * Depending on the scaling mode, a buffer's crop region is scaled and/or
620 * cropped to match the surface's size. This function sets the crop in
621 * pre-transformed buffer pixel coordinates.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700622 *
623 * The specified crop region applies to all buffers queued after it is called.
624 *
Jamie Gennisd21113a2012-05-03 14:21:24 -0700625 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700626 *
Jamie Gennisd21113a2012-05-03 14:21:24 -0700627 * An error is returned if for instance the crop region is invalid, out of the
628 * buffer's bound or if the window is invalid.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700629 */
630static inline int native_window_set_crop(
631 struct ANativeWindow* window,
632 android_native_rect_t const * crop)
633{
634 return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
635}
636
637/*
Jamie Gennisd21113a2012-05-03 14:21:24 -0700638 * native_window_set_post_transform_crop(..., crop)
639 * Sets which region of the next queued buffers needs to be considered.
640 * Depending on the scaling mode, a buffer's crop region is scaled and/or
641 * cropped to match the surface's size. This function sets the crop in
642 * post-transformed pixel coordinates.
643 *
644 * The specified crop region applies to all buffers queued after it is called.
645 *
646 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
647 *
648 * An error is returned if for instance the crop region is invalid, out of the
649 * buffer's bound or if the window is invalid.
650 */
651static inline int native_window_set_post_transform_crop(
652 struct ANativeWindow* window,
653 android_native_rect_t const * crop)
654{
655 return window->perform(window, NATIVE_WINDOW_SET_POST_TRANSFORM_CROP, crop);
656}
657
658/*
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700659 * native_window_set_active_rect(..., active_rect)
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700660 *
Jamie Gennis22aec572012-06-13 16:43:06 -0700661 * This function is deprecated and will be removed soon. For now it simply
Jamie Gennisd21113a2012-05-03 14:21:24 -0700662 * sets the post-transform crop for compatibility while multi-project commits
663 * get checked.
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700664 */
665static inline int native_window_set_active_rect(
666 struct ANativeWindow* window,
667 android_native_rect_t const * active_rect)
668{
Jamie Gennisd21113a2012-05-03 14:21:24 -0700669 return native_window_set_post_transform_crop(window, active_rect);
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700670}
671
672/*
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700673 * native_window_set_buffer_count(..., count)
674 * Sets the number of buffers associated with this native window.
675 */
676static inline int native_window_set_buffer_count(
677 struct ANativeWindow* window,
678 size_t bufferCount)
679{
680 return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
681}
682
683/*
684 * native_window_set_buffers_geometry(..., int w, int h, int format)
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700685 * All buffers dequeued after this call will have the dimensions and format
686 * specified. A successful call to this function has the same effect as calling
687 * native_window_set_buffers_size and native_window_set_buffers_format.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700688 *
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700689 * XXX: This function is deprecated. The native_window_set_buffers_dimensions
690 * and native_window_set_buffers_format functions should be used instead.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700691 */
692static inline int native_window_set_buffers_geometry(
693 struct ANativeWindow* window,
694 int w, int h, int format)
695{
696 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
697 w, h, format);
698}
699
700/*
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700701 * native_window_set_buffers_dimensions(..., int w, int h)
702 * All buffers dequeued after this call will have the dimensions specified.
Michael I. Goldafcdef62012-04-09 18:21:13 -0700703 * In particular, all buffers will have a fixed-size, independent from the
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700704 * native-window size. They will be scaled according to the scaling mode
705 * (see native_window_set_scaling_mode) upon window composition.
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700706 *
707 * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
708 * following this call will be sized to match the window's size.
709 *
710 * Calling this function will reset the window crop to a NULL value, which
711 * disables cropping of the buffers.
712 */
713static inline int native_window_set_buffers_dimensions(
714 struct ANativeWindow* window,
715 int w, int h)
716{
717 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
718 w, h);
719}
720
721/*
Michael I. Goldafcdef62012-04-09 18:21:13 -0700722 * native_window_set_buffers_user_dimensions(..., int w, int h)
723 *
724 * Sets the user buffer size for the window, which overrides the
725 * window's size. All buffers dequeued after this call will have the
726 * dimensions specified unless overridden by
727 * native_window_set_buffers_dimensions. All buffers will have a
728 * fixed-size, independent from the native-window size. They will be
729 * scaled according to the scaling mode (see
730 * native_window_set_scaling_mode) upon window composition.
731 *
732 * If w and h are 0, the normal behavior is restored. That is, the
733 * default buffer size will match the windows's size.
734 *
735 * Calling this function will reset the window crop to a NULL value, which
736 * disables cropping of the buffers.
737 */
738static inline int native_window_set_buffers_user_dimensions(
739 struct ANativeWindow* window,
740 int w, int h)
741{
742 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
743 w, h);
744}
745
746/*
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700747 * native_window_set_buffers_format(..., int format)
748 * All buffers dequeued after this call will have the format specified.
749 *
750 * If the specified format is 0, the default buffer format will be used.
751 */
752static inline int native_window_set_buffers_format(
753 struct ANativeWindow* window,
754 int format)
755{
756 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
757}
758
759/*
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700760 * native_window_set_buffers_transform(..., int transform)
761 * All buffers queued after this call will be displayed transformed according
762 * to the transform parameter specified.
763 */
764static inline int native_window_set_buffers_transform(
765 struct ANativeWindow* window,
766 int transform)
767{
768 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
769 transform);
770}
771
772/*
773 * native_window_set_buffers_timestamp(..., int64_t timestamp)
774 * All buffers queued after this call will be associated with the timestamp
775 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
776 * (the default), timestamps will be generated automatically when queueBuffer is
Glenn Kastenc322f672011-06-27 10:42:39 -0700777 * called. The timestamp is measured in nanoseconds, and is normally monotonically
778 * increasing. The timestamp should be unaffected by time-of-day adjustments,
779 * and for a camera should be strictly monotonic but for a media player may be
780 * reset when the position is set.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700781 */
782static inline int native_window_set_buffers_timestamp(
783 struct ANativeWindow* window,
784 int64_t timestamp)
785{
786 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
787 timestamp);
788}
789
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700790/*
791 * native_window_set_scaling_mode(..., int mode)
792 * All buffers queued after this call will be associated with the scaling mode
793 * specified.
794 */
795static inline int native_window_set_scaling_mode(
796 struct ANativeWindow* window,
797 int mode)
798{
799 return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
800 mode);
801}
802
Mathias Agopian8ad54522011-07-29 17:52:36 -0700803/*
804 * native_window_api_connect(..., int api)
805 * connects an API to this window. only one API can be connected at a time.
806 * Returns -EINVAL if for some reason the window cannot be connected, which
807 * can happen if it's connected to some other API.
808 */
809static inline int native_window_api_connect(
810 struct ANativeWindow* window, int api)
811{
Mathias Agopian319f4e22011-08-03 11:26:38 -0700812 return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
Mathias Agopian8ad54522011-07-29 17:52:36 -0700813}
814
815/*
816 * native_window_api_disconnect(..., int api)
817 * disconnect the API from this window.
818 * An error is returned if for instance the window wasn't connected in the
819 * first place.
820 */
821static inline int native_window_api_disconnect(
822 struct ANativeWindow* window, int api)
823{
Mathias Agopian319f4e22011-08-03 11:26:38 -0700824 return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
Mathias Agopian8ad54522011-07-29 17:52:36 -0700825}
826
Jamie Gennis22aec572012-06-13 16:43:06 -0700827/*
828 * native_window_dequeue_buffer_and_wait(...)
829 * Dequeue a buffer and wait on the fence associated with that buffer. The
830 * buffer may safely be accessed immediately upon this function returning. An
831 * error is returned if either of the dequeue or the wait operations fail.
832 */
833static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
834 struct ANativeWindowBuffer** anb) {
Jesse Hallbc930ed2012-10-01 13:48:36 -0700835 return anw->dequeueBuffer_DEPRECATED(anw, anb);
Jamie Gennis22aec572012-06-13 16:43:06 -0700836}
837
Mathias Agopian8ad54522011-07-29 17:52:36 -0700838
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700839__END_DECLS
840
tedbo1ffdb382011-05-24 00:55:33 -0700841#endif /* SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H */