blob: 1037a9cbb01d2b3172d309d8a7c74a3e2a25493b [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>
Pablo Ceballos923d27f2015-10-19 10:24:42 -070028#include <stdbool.h>
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070029
Ian Rogersde8b9832014-06-27 16:38:01 -070030#ifndef __UNUSED
31#define __UNUSED __attribute__((__unused__))
Mark Salyzyn48878422014-05-22 16:08:52 -070032#endif
Mark Salyzyn289e1112014-05-23 12:31:42 -070033#ifndef __deprecated
34#define __deprecated __attribute__((__deprecated__))
35#endif
Mark Salyzyn48878422014-05-22 16:08:52 -070036
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070037__BEGIN_DECLS
38
39/*****************************************************************************/
40
Colin Cross7c7990e2016-09-15 18:04:04 -070041#ifdef __cplusplus
42#define ANDROID_NATIVE_UNSIGNED_CAST(x) static_cast<unsigned int>(x)
43#else
44#define ANDROID_NATIVE_UNSIGNED_CAST(x) ((unsigned int)(x))
45#endif
46
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070047#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \
Colin Cross7c7990e2016-09-15 18:04:04 -070048 ((ANDROID_NATIVE_UNSIGNED_CAST(a) << 24) | \
49 (ANDROID_NATIVE_UNSIGNED_CAST(b) << 16) | \
50 (ANDROID_NATIVE_UNSIGNED_CAST(c) << 8) | \
51 (ANDROID_NATIVE_UNSIGNED_CAST(d)))
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070052
53#define ANDROID_NATIVE_WINDOW_MAGIC \
54 ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
55
56#define ANDROID_NATIVE_BUFFER_MAGIC \
57 ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r')
58
59// ---------------------------------------------------------------------------
60
Jamie Gennis22aec572012-06-13 16:43:06 -070061// This #define may be used to conditionally compile device-specific code to
62// support either the prior ANativeWindow interface, which did not pass libsync
63// fences around, or the new interface that does. This #define is only present
64// when the ANativeWindow interface does include libsync support.
65#define ANDROID_NATIVE_WINDOW_HAS_SYNC 1
66
67// ---------------------------------------------------------------------------
68
Iliyan Malchev0ab886b2011-05-01 14:07:43 -070069typedef const native_handle_t* buffer_handle_t;
70
71// ---------------------------------------------------------------------------
72
73typedef struct android_native_rect_t
74{
75 int32_t left;
76 int32_t top;
77 int32_t right;
78 int32_t bottom;
79} android_native_rect_t;
80
81// ---------------------------------------------------------------------------
82
83typedef struct android_native_base_t
84{
85 /* a magic value defined by the actual EGL native type */
86 int magic;
87
88 /* the sizeof() of the actual EGL native type */
89 int version;
90
91 void* reserved[4];
92
93 /* reference-counting interface */
94 void (*incRef)(struct android_native_base_t* base);
95 void (*decRef)(struct android_native_base_t* base);
96} android_native_base_t;
97
98typedef struct ANativeWindowBuffer
99{
100#ifdef __cplusplus
101 ANativeWindowBuffer() {
102 common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
103 common.version = sizeof(ANativeWindowBuffer);
104 memset(common.reserved, 0, sizeof(common.reserved));
105 }
106
107 // Implement the methods that sp<ANativeWindowBuffer> expects so that it
108 // can be used to automatically refcount ANativeWindowBuffer's.
Mark Salyzyn48878422014-05-22 16:08:52 -0700109 void incStrong(const void* /*id*/) const {
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700110 common.incRef(const_cast<android_native_base_t*>(&common));
111 }
Mark Salyzyn48878422014-05-22 16:08:52 -0700112 void decStrong(const void* /*id*/) const {
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700113 common.decRef(const_cast<android_native_base_t*>(&common));
114 }
115#endif
116
117 struct android_native_base_t common;
118
119 int width;
120 int height;
121 int stride;
122 int format;
123 int usage;
Craig Donnerce54b4d2016-10-19 18:07:17 -0700124 uintptr_t layerCount;
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700125
Craig Donnerce54b4d2016-10-19 18:07:17 -0700126 void* reserved[1];
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700127
128 buffer_handle_t handle;
129
130 void* reserved_proc[8];
131} ANativeWindowBuffer_t;
132
133// Old typedef for backwards compatibility.
134typedef ANativeWindowBuffer_t android_native_buffer_t;
135
136// ---------------------------------------------------------------------------
137
138/* attributes queriable with query() */
139enum {
140 NATIVE_WINDOW_WIDTH = 0,
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700141 NATIVE_WINDOW_HEIGHT = 1,
142 NATIVE_WINDOW_FORMAT = 2,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700143
144 /* The minimum number of buffers that must remain un-dequeued after a buffer
145 * has been queued. This value applies only if set_buffer_count was used to
146 * override the number of buffers and if a buffer has since been queued.
147 * Users of the set_buffer_count ANativeWindow method should query this
148 * value before calling set_buffer_count. If it is necessary to have N
149 * buffers simultaneously dequeued as part of the steady-state operation,
150 * and this query returns M then N+M buffers should be requested via
151 * native_window_set_buffer_count.
152 *
153 * Note that this value does NOT apply until a single buffer has been
154 * queued. In particular this means that it is possible to:
155 *
156 * 1. Query M = min undequeued buffers
157 * 2. Set the buffer count to N + M
158 * 3. Dequeue all N + M buffers
159 * 4. Cancel M buffers
160 * 5. Queue, dequeue, queue, dequeue, ad infinitum
161 */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700162 NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = 3,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700163
164 /* Check whether queueBuffer operations on the ANativeWindow send the buffer
165 * to the window compositor. The query sets the returned 'value' argument
166 * to 1 if the ANativeWindow DOES send queued buffers directly to the window
167 * compositor and 0 if the buffers do not go directly to the window
168 * compositor.
169 *
170 * This can be used to determine whether protected buffer content should be
171 * sent to the ANativeWindow. Note, however, that a result of 1 does NOT
172 * indicate that queued buffers will be protected from applications or users
173 * capturing their contents. If that behavior is desired then some other
174 * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
175 * conjunction with this query.
176 */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700177 NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700178
179 /* Get the concrete type of a ANativeWindow. See below for the list of
180 * possible return values.
181 *
182 * This query should not be used outside the Android framework and will
183 * likely be removed in the near future.
184 */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700185 NATIVE_WINDOW_CONCRETE_TYPE = 5,
Mathias Agopian51009162011-07-19 15:59:15 -0700186
187
188 /*
Michael I. Goldafcdef62012-04-09 18:21:13 -0700189 * Default width and height of ANativeWindow buffers, these are the
190 * dimensions of the window buffers irrespective of the
191 * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window
Jamie Gennisaa3f4c32012-04-17 19:37:48 -0700192 * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
Mathias Agopian51009162011-07-19 15:59:15 -0700193 */
194 NATIVE_WINDOW_DEFAULT_WIDTH = 6,
195 NATIVE_WINDOW_DEFAULT_HEIGHT = 7,
196
197 /*
198 * transformation that will most-likely be applied to buffers. This is only
199 * a hint, the actual transformation applied might be different.
200 *
201 * INTENDED USE:
202 *
203 * The transform hint can be used by a producer, for instance the GLES
204 * driver, to pre-rotate the rendering such that the final transformation
205 * in the composer is identity. This can be very useful when used in
206 * conjunction with the h/w composer HAL, in situations where it
207 * cannot handle arbitrary rotations.
208 *
209 * 1. Before dequeuing a buffer, the GL driver (or any other ANW client)
210 * queries the ANW for NATIVE_WINDOW_TRANSFORM_HINT.
211 *
212 * 2. The GL driver overrides the width and height of the ANW to
213 * account for NATIVE_WINDOW_TRANSFORM_HINT. This is done by querying
214 * NATIVE_WINDOW_DEFAULT_{WIDTH | HEIGHT}, swapping the dimensions
215 * according to NATIVE_WINDOW_TRANSFORM_HINT and calling
216 * native_window_set_buffers_dimensions().
217 *
218 * 3. The GL driver dequeues a buffer of the new pre-rotated size.
219 *
220 * 4. The GL driver renders to the buffer such that the image is
221 * already transformed, that is applying NATIVE_WINDOW_TRANSFORM_HINT
222 * to the rendering.
223 *
224 * 5. The GL driver calls native_window_set_transform to apply
225 * inverse transformation to the buffer it just rendered.
226 * In order to do this, the GL driver needs
227 * to calculate the inverse of NATIVE_WINDOW_TRANSFORM_HINT, this is
228 * done easily:
229 *
230 * int hintTransform, inverseTransform;
231 * query(..., NATIVE_WINDOW_TRANSFORM_HINT, &hintTransform);
232 * inverseTransform = hintTransform;
233 * if (hintTransform & HAL_TRANSFORM_ROT_90)
234 * inverseTransform ^= HAL_TRANSFORM_ROT_180;
235 *
236 *
237 * 6. The GL driver queues the pre-transformed buffer.
238 *
239 * 7. The composer combines the buffer transform with the display
240 * transform. If the buffer transform happens to cancel out the
241 * display transform then no rotation is needed.
242 *
243 */
244 NATIVE_WINDOW_TRANSFORM_HINT = 8,
Jamie Gennisaa3f4c32012-04-17 19:37:48 -0700245
246 /*
247 * Boolean that indicates whether the consumer is running more than
248 * one buffer behind the producer.
249 */
Eino-Ville Talvalaf88a5b42013-07-30 14:07:08 -0700250 NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9,
251
252 /*
253 * The consumer gralloc usage bits currently set by the consumer.
254 * The values are defined in hardware/libhardware/include/gralloc.h.
255 */
Ruben Brunka5e65d82014-06-27 16:15:18 -0700256 NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10,
257
258 /**
259 * Transformation that will by applied to buffers by the hwcomposer.
260 * This must not be set or checked by producer endpoints, and will
261 * disable the transform hint set in SurfaceFlinger (see
262 * NATIVE_WINDOW_TRANSFORM_HINT).
263 *
264 * INTENDED USE:
265 * Temporary - Please do not use this. This is intended only to be used
266 * by the camera's LEGACY mode.
267 *
268 * In situations where a SurfaceFlinger client wishes to set a transform
269 * that is not visible to the producer, and will always be applied in the
270 * hardware composer, the client can set this flag with
271 * native_window_set_buffers_sticky_transform. This can be used to rotate
272 * and flip buffers consumed by hardware composer without actually changing
273 * the aspect ratio of the buffers produced.
274 */
275 NATIVE_WINDOW_STICKY_TRANSFORM = 11,
Eino-Ville Talvalab93343d2015-02-17 15:34:44 -0800276
277 /**
278 * The default data space for the buffers as set by the consumer.
279 * The values are defined in graphics.h.
280 */
Dan Stoza0a866ea2015-02-25 16:45:08 -0800281 NATIVE_WINDOW_DEFAULT_DATASPACE = 12,
282
283 /*
284 * Returns the age of the contents of the most recently dequeued buffer as
285 * the number of frames that have elapsed since it was last queued. For
286 * example, if the window is double-buffered, the age of any given buffer in
287 * steady state will be 2. If the dequeued buffer has never been queued, its
288 * age will be 0.
289 */
290 NATIVE_WINDOW_BUFFER_AGE = 13,
Dan Stoza94ededa2016-07-01 14:02:08 -0700291
292 /*
293 * Returns the duration of the last dequeueBuffer call in microseconds
294 */
295 NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
296
297 /*
298 * Returns the duration of the last queueBuffer call in microseconds
299 */
300 NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
Craig Donnerce54b4d2016-10-19 18:07:17 -0700301
302 /*
303 * Returns the number of image layers that the ANativeWindow buffer
304 * contains. By default this is 1, unless a buffer is explicitly allocated
305 * to contain multiple layers.
306 */
307 NATIVE_WINDOW_LAYER_COUNT = 16,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700308};
309
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700310/* Valid operations for the (*perform)() hook.
311 *
312 * Values marked as 'deprecated' are supported, but have been superceded by
313 * other functionality.
314 *
315 * Values marked as 'private' should be considered private to the framework.
316 * HAL implementation code with access to an ANativeWindow should not use these,
317 * as it may not interact properly with the framework's use of the
318 * ANativeWindow.
319 */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700320enum {
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700321 NATIVE_WINDOW_SET_USAGE = 0,
Mathias Agopian8ad54522011-07-29 17:52:36 -0700322 NATIVE_WINDOW_CONNECT = 1, /* deprecated */
323 NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700324 NATIVE_WINDOW_SET_CROP = 3, /* private */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700325 NATIVE_WINDOW_SET_BUFFER_COUNT = 4,
326 NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */
327 NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6,
328 NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7,
329 NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8,
330 NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9,
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700331 NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */
Mathias Agopianae3736a2011-07-13 18:40:38 -0700332 NATIVE_WINDOW_LOCK = 11, /* private */
333 NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */
Mathias Agopian8ad54522011-07-29 17:52:36 -0700334 NATIVE_WINDOW_API_CONNECT = 13, /* private */
335 NATIVE_WINDOW_API_DISCONNECT = 14, /* private */
Michael I. Goldafcdef62012-04-09 18:21:13 -0700336 NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
Jamie Gennisd21113a2012-05-03 14:21:24 -0700337 NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* private */
Ruben Brunka5e65d82014-06-27 16:15:18 -0700338 NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17,/* private */
Rachadd6d4c612014-07-29 18:03:21 -0700339 NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18,
Dan Stoza238ec982015-03-23 10:43:14 -0700340 NATIVE_WINDOW_SET_BUFFERS_DATASPACE = 19,
341 NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */
Pablo Ceballos248e7712016-03-17 15:42:21 -0700342 NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21,
Pablo Ceballos3daa5742016-01-15 13:31:14 -0800343 NATIVE_WINDOW_SET_AUTO_REFRESH = 22,
Pablo Ceballosc2efc322016-05-31 11:06:03 -0700344 NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 23,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700345};
346
Mathias Agopian8ad54522011-07-29 17:52:36 -0700347/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700348enum {
Jamie Gennis5423e9e2011-07-12 13:53:42 -0700349 /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
350 * OpenGL ES.
351 */
352 NATIVE_WINDOW_API_EGL = 1,
353
354 /* Buffers will be queued after being filled using the CPU
355 */
356 NATIVE_WINDOW_API_CPU = 2,
357
358 /* Buffers will be queued by Stagefright after being filled by a video
359 * decoder. The video decoder can either be a software or hardware decoder.
360 */
361 NATIVE_WINDOW_API_MEDIA = 3,
362
363 /* Buffers will be queued by the the camera HAL.
364 */
365 NATIVE_WINDOW_API_CAMERA = 4,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700366};
367
368/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
369enum {
370 /* flip source image horizontally */
371 NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
372 /* flip source image vertically */
373 NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Mathias Agopian96675ed2013-09-17 23:48:54 -0700374 /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700375 NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
376 /* rotate source image 180 degrees */
377 NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
378 /* rotate source image 270 degrees clock-wise */
379 NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Mathias Agopian96675ed2013-09-17 23:48:54 -0700380 /* transforms source by the inverse transform of the screen it is displayed onto. This
381 * transform is applied last */
382 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700383};
384
Robert Carrf3954fb2015-12-17 11:31:11 -0800385/* parameter for NATIVE_WINDOW_SET_SCALING_MODE
386 * keep in sync with Surface.java in frameworks/base */
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700387enum {
388 /* the window content is not updated (frozen) until a buffer of
389 * the window size is received (enqueued)
390 */
391 NATIVE_WINDOW_SCALING_MODE_FREEZE = 0,
392 /* the buffer is scaled in both dimensions to match the window size */
393 NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1,
Daniel Lam29392a42012-04-11 18:19:46 -0700394 /* the buffer is scaled uniformly such that the smaller dimension
395 * of the buffer matches the window size (cropping in the process)
396 */
397 NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2,
Jamie Gennisd21113a2012-05-03 14:21:24 -0700398 /* the window is clipped to the size of the buffer's crop rectangle; pixels
399 * outside the crop rectangle are treated as if they are completely
400 * transparent.
401 */
402 NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3,
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700403};
404
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700405/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
406enum {
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700407 NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
408 NATIVE_WINDOW_SURFACE = 1, /* Surface */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700409};
410
411/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
412 *
413 * Special timestamp value to indicate that timestamps should be auto-generated
414 * by the native window when queueBuffer is called. This is equal to INT64_MIN,
415 * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
416 */
417static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
418
419struct ANativeWindow
420{
421#ifdef __cplusplus
422 ANativeWindow()
423 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
424 {
425 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
426 common.version = sizeof(ANativeWindow);
427 memset(common.reserved, 0, sizeof(common.reserved));
428 }
429
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700430 /* Implement the methods that sp<ANativeWindow> expects so that it
431 can be used to automatically refcount ANativeWindow's. */
Mark Salyzyn48878422014-05-22 16:08:52 -0700432 void incStrong(const void* /*id*/) const {
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700433 common.incRef(const_cast<android_native_base_t*>(&common));
434 }
Mark Salyzyn48878422014-05-22 16:08:52 -0700435 void decStrong(const void* /*id*/) const {
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700436 common.decRef(const_cast<android_native_base_t*>(&common));
437 }
438#endif
439
440 struct android_native_base_t common;
441
442 /* flags describing some attributes of this surface or its updater */
443 const uint32_t flags;
444
445 /* min swap interval supported by this updated */
446 const int minSwapInterval;
447
448 /* max swap interval supported by this updated */
449 const int maxSwapInterval;
450
451 /* horizontal and vertical resolution in DPI */
452 const float xdpi;
453 const float ydpi;
454
455 /* Some storage reserved for the OEM's driver. */
456 intptr_t oem[4];
457
458 /*
459 * Set the swap interval for this surface.
460 *
461 * Returns 0 on success or -errno on error.
462 */
463 int (*setSwapInterval)(struct ANativeWindow* window,
464 int interval);
465
466 /*
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800467 * Hook called by EGL to acquire a buffer. After this call, the buffer
468 * is not locked, so its content cannot be modified. This call may block if
469 * no buffers are available.
470 *
471 * The window holds a reference to the buffer between dequeueBuffer and
472 * either queueBuffer or cancelBuffer, so clients only need their own
473 * reference if they might use the buffer after queueing or canceling it.
474 * Holding a reference to a buffer after queueing or canceling it is only
475 * allowed if a specific buffer count has been set.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700476 *
477 * Returns 0 on success or -errno on error.
Jamie Gennis22aec572012-06-13 16:43:06 -0700478 *
479 * XXX: This function is deprecated. It will continue to work for some
480 * time for binary compatibility, but the new dequeueBuffer function that
481 * outputs a fence file descriptor should be used in its place.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700482 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700483 int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700484 struct ANativeWindowBuffer** buffer);
485
486 /*
487 * hook called by EGL to lock a buffer. This MUST be called before modifying
488 * the content of a buffer. The buffer must have been acquired with
489 * dequeueBuffer first.
490 *
491 * Returns 0 on success or -errno on error.
Jamie Gennis22aec572012-06-13 16:43:06 -0700492 *
493 * XXX: This function is deprecated. It will continue to work for some
494 * time for binary compatibility, but it is essentially a no-op, and calls
495 * to it should be removed.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700496 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700497 int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700498 struct ANativeWindowBuffer* buffer);
Jamie Gennis22aec572012-06-13 16:43:06 -0700499
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800500 /*
501 * Hook called by EGL when modifications to the render buffer are done.
502 * This unlocks and post the buffer.
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 * Buffers MUST be queued in the same order than they were dequeued.
511 *
512 * Returns 0 on success or -errno on error.
Jamie Gennis22aec572012-06-13 16:43:06 -0700513 *
514 * XXX: This function is deprecated. It will continue to work for some
515 * time for binary compatibility, but the new queueBuffer function that
516 * takes a fence file descriptor should be used in its place (pass a value
517 * of -1 for the fence file descriptor if there is no valid one to pass).
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800518 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700519 int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700520 struct ANativeWindowBuffer* buffer);
521
522 /*
523 * hook used to retrieve information about the native window.
524 *
525 * Returns 0 on success or -errno on error.
526 */
527 int (*query)(const struct ANativeWindow* window,
528 int what, int* value);
529
530 /*
531 * hook used to perform various operations on the surface.
532 * (*perform)() is a generic mechanism to add functionality to
533 * ANativeWindow while keeping backward binary compatibility.
534 *
535 * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
536 * defined below.
537 *
Dan Stoza238ec982015-03-23 10:43:14 -0700538 * (*perform)() returns -ENOENT if the 'what' parameter is not supported
539 * by the surface's implementation.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700540 *
Dan Stoza238ec982015-03-23 10:43:14 -0700541 * See above for a list of valid operations, such as
542 * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700543 */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700544 int (*perform)(struct ANativeWindow* window,
545 int operation, ... );
546
547 /*
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800548 * Hook used to cancel a buffer that has been dequeued.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700549 * No synchronization is performed between dequeue() and cancel(), so
550 * either external synchronization is needed, or these functions must be
551 * called from the same thread.
Jesse Hall7cd3e0a2011-12-12 10:32:55 -0800552 *
553 * The window holds a reference to the buffer between dequeueBuffer and
554 * either queueBuffer or cancelBuffer, so clients only need their own
555 * reference if they might use the buffer after queueing or canceling it.
556 * Holding a reference to a buffer after queueing or canceling it is only
557 * allowed if a specific buffer count has been set.
Jamie Gennis22aec572012-06-13 16:43:06 -0700558 *
559 * XXX: This function is deprecated. It will continue to work for some
560 * time for binary compatibility, but the new cancelBuffer function that
561 * takes a fence file descriptor should be used in its place (pass a value
562 * of -1 for the fence file descriptor if there is no valid one to pass).
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700563 */
Jamie Gennis22aec572012-06-13 16:43:06 -0700564 int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700565 struct ANativeWindowBuffer* buffer);
566
Jamie Gennis22aec572012-06-13 16:43:06 -0700567 /*
568 * Hook called by EGL to acquire a buffer. This call may block if no
569 * buffers are available.
570 *
571 * The window holds a reference to the buffer between dequeueBuffer and
572 * either queueBuffer or cancelBuffer, so clients only need their own
573 * reference if they might use the buffer after queueing or canceling it.
574 * Holding a reference to a buffer after queueing or canceling it is only
575 * allowed if a specific buffer count has been set.
576 *
577 * The libsync fence file descriptor returned in the int pointed to by the
578 * fenceFd argument will refer to the fence that must signal before the
579 * dequeued buffer may be written to. A value of -1 indicates that the
580 * caller may access the buffer immediately without waiting on a fence. If
581 * a valid file descriptor is returned (i.e. any value except -1) then the
582 * caller is responsible for closing the file descriptor.
583 *
584 * Returns 0 on success or -errno on error.
585 */
586 int (*dequeueBuffer)(struct ANativeWindow* window,
587 struct ANativeWindowBuffer** buffer, int* fenceFd);
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700588
Jamie Gennis22aec572012-06-13 16:43:06 -0700589 /*
590 * Hook called by EGL when modifications to the render buffer are done.
591 * This unlocks and post the buffer.
592 *
593 * The window holds a reference to the buffer between dequeueBuffer and
594 * either queueBuffer or cancelBuffer, so clients only need their own
595 * reference if they might use the buffer after queueing or canceling it.
596 * Holding a reference to a buffer after queueing or canceling it is only
597 * allowed if a specific buffer count has been set.
598 *
599 * The fenceFd argument specifies a libsync fence file descriptor for a
600 * fence that must signal before the buffer can be accessed. If the buffer
601 * can be accessed immediately then a value of -1 should be used. The
602 * caller must not use the file descriptor after it is passed to
603 * queueBuffer, and the ANativeWindow implementation is responsible for
604 * closing it.
605 *
606 * Returns 0 on success or -errno on error.
607 */
608 int (*queueBuffer)(struct ANativeWindow* window,
609 struct ANativeWindowBuffer* buffer, int fenceFd);
610
611 /*
612 * Hook used to cancel a buffer that has been dequeued.
613 * No synchronization is performed between dequeue() and cancel(), so
614 * either external synchronization is needed, or these functions must be
615 * called from the same thread.
616 *
617 * The window holds a reference to the buffer between dequeueBuffer and
618 * either queueBuffer or cancelBuffer, so clients only need their own
619 * reference if they might use the buffer after queueing or canceling it.
620 * Holding a reference to a buffer after queueing or canceling it is only
621 * allowed if a specific buffer count has been set.
622 *
623 * The fenceFd argument specifies a libsync fence file decsriptor for a
624 * fence that must signal before the buffer can be accessed. If the buffer
625 * can be accessed immediately then a value of -1 should be used.
626 *
627 * Note that if the client has not waited on the fence that was returned
628 * from dequeueBuffer, that same fence should be passed to cancelBuffer to
629 * ensure that future uses of the buffer are preceded by a wait on that
630 * fence. The caller must not use the file descriptor after it is passed
631 * to cancelBuffer, and the ANativeWindow implementation is responsible for
632 * closing it.
633 *
634 * Returns 0 on success or -errno on error.
635 */
636 int (*cancelBuffer)(struct ANativeWindow* window,
637 struct ANativeWindowBuffer* buffer, int fenceFd);
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700638};
639
640 /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
641 * android_native_window_t is deprecated.
642 */
643typedef struct ANativeWindow ANativeWindow;
Mark Salyzyn289e1112014-05-23 12:31:42 -0700644typedef struct ANativeWindow android_native_window_t __deprecated;
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700645
646/*
647 * native_window_set_usage(..., usage)
648 * Sets the intended usage flags for the next buffers
649 * acquired with (*lockBuffer)() and on.
650 * By default (if this function is never called), a usage of
651 * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE
652 * is assumed.
653 * Calling this function will usually cause following buffers to be
654 * reallocated.
655 */
656
657static inline int native_window_set_usage(
658 struct ANativeWindow* window, int usage)
659{
660 return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage);
661}
662
Mathias Agopian8ad54522011-07-29 17:52:36 -0700663/* deprecated. Always returns 0. Don't call. */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700664static inline int native_window_connect(
Ian Rogersde8b9832014-06-27 16:38:01 -0700665 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
Mark Salyzyn289e1112014-05-23 12:31:42 -0700666
667static inline int native_window_connect(
Ian Rogersde8b9832014-06-27 16:38:01 -0700668 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
Mathias Agopian319f4e22011-08-03 11:26:38 -0700669 return 0;
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700670}
671
Mathias Agopian8ad54522011-07-29 17:52:36 -0700672/* deprecated. Always returns 0. Don't call. */
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700673static inline int native_window_disconnect(
Ian Rogersde8b9832014-06-27 16:38:01 -0700674 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
Mark Salyzyn289e1112014-05-23 12:31:42 -0700675
676static inline int native_window_disconnect(
Ian Rogersde8b9832014-06-27 16:38:01 -0700677 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
Mathias Agopian319f4e22011-08-03 11:26:38 -0700678 return 0;
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700679}
680
681/*
682 * native_window_set_crop(..., crop)
683 * Sets which region of the next queued buffers needs to be considered.
Jamie Gennisd21113a2012-05-03 14:21:24 -0700684 * Depending on the scaling mode, a buffer's crop region is scaled and/or
685 * cropped to match the surface's size. This function sets the crop in
686 * pre-transformed buffer pixel coordinates.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700687 *
688 * The specified crop region applies to all buffers queued after it is called.
689 *
Jamie Gennisd21113a2012-05-03 14:21:24 -0700690 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700691 *
Jamie Gennisd21113a2012-05-03 14:21:24 -0700692 * An error is returned if for instance the crop region is invalid, out of the
693 * buffer's bound or if the window is invalid.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700694 */
695static inline int native_window_set_crop(
696 struct ANativeWindow* window,
697 android_native_rect_t const * crop)
698{
699 return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
700}
701
702/*
Jamie Gennisd21113a2012-05-03 14:21:24 -0700703 * native_window_set_post_transform_crop(..., crop)
704 * Sets which region of the next queued buffers needs to be considered.
705 * Depending on the scaling mode, a buffer's crop region is scaled and/or
706 * cropped to match the surface's size. This function sets the crop in
707 * post-transformed pixel coordinates.
708 *
709 * The specified crop region applies to all buffers queued after it is called.
710 *
711 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
712 *
713 * An error is returned if for instance the crop region is invalid, out of the
714 * buffer's bound or if the window is invalid.
715 */
716static inline int native_window_set_post_transform_crop(
717 struct ANativeWindow* window,
718 android_native_rect_t const * crop)
719{
720 return window->perform(window, NATIVE_WINDOW_SET_POST_TRANSFORM_CROP, crop);
721}
722
723/*
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700724 * native_window_set_active_rect(..., active_rect)
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700725 *
Jamie Gennis22aec572012-06-13 16:43:06 -0700726 * This function is deprecated and will be removed soon. For now it simply
Jamie Gennisd21113a2012-05-03 14:21:24 -0700727 * sets the post-transform crop for compatibility while multi-project commits
728 * get checked.
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700729 */
730static inline int native_window_set_active_rect(
731 struct ANativeWindow* window,
Mark Salyzyn289e1112014-05-23 12:31:42 -0700732 android_native_rect_t const * active_rect) __deprecated;
733
734static inline int native_window_set_active_rect(
735 struct ANativeWindow* window,
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700736 android_native_rect_t const * active_rect)
737{
Jamie Gennisd21113a2012-05-03 14:21:24 -0700738 return native_window_set_post_transform_crop(window, active_rect);
Jamie Gennisfb1ee572012-04-17 19:37:48 -0700739}
740
741/*
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700742 * native_window_set_buffer_count(..., count)
743 * Sets the number of buffers associated with this native window.
744 */
745static inline int native_window_set_buffer_count(
746 struct ANativeWindow* window,
747 size_t bufferCount)
748{
749 return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
750}
751
752/*
753 * native_window_set_buffers_geometry(..., int w, int h, int format)
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700754 * All buffers dequeued after this call will have the dimensions and format
755 * specified. A successful call to this function has the same effect as calling
756 * native_window_set_buffers_size and native_window_set_buffers_format.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700757 *
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700758 * XXX: This function is deprecated. The native_window_set_buffers_dimensions
759 * and native_window_set_buffers_format functions should be used instead.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700760 */
761static inline int native_window_set_buffers_geometry(
762 struct ANativeWindow* window,
Mark Salyzyn289e1112014-05-23 12:31:42 -0700763 int w, int h, int format) __deprecated;
764
765static inline int native_window_set_buffers_geometry(
766 struct ANativeWindow* window,
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700767 int w, int h, int format)
768{
769 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
770 w, h, format);
771}
772
773/*
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700774 * native_window_set_buffers_dimensions(..., int w, int h)
775 * All buffers dequeued after this call will have the dimensions specified.
Michael I. Goldafcdef62012-04-09 18:21:13 -0700776 * In particular, all buffers will have a fixed-size, independent from the
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700777 * native-window size. They will be scaled according to the scaling mode
778 * (see native_window_set_scaling_mode) upon window composition.
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700779 *
780 * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
781 * following this call will be sized to match the window's size.
782 *
783 * Calling this function will reset the window crop to a NULL value, which
784 * disables cropping of the buffers.
785 */
786static inline int native_window_set_buffers_dimensions(
787 struct ANativeWindow* window,
788 int w, int h)
789{
790 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
791 w, h);
792}
793
794/*
Michael I. Goldafcdef62012-04-09 18:21:13 -0700795 * native_window_set_buffers_user_dimensions(..., int w, int h)
796 *
797 * Sets the user buffer size for the window, which overrides the
798 * window's size. All buffers dequeued after this call will have the
799 * dimensions specified unless overridden by
800 * native_window_set_buffers_dimensions. All buffers will have a
801 * fixed-size, independent from the native-window size. They will be
802 * scaled according to the scaling mode (see
803 * native_window_set_scaling_mode) upon window composition.
804 *
805 * If w and h are 0, the normal behavior is restored. That is, the
806 * default buffer size will match the windows's size.
807 *
808 * Calling this function will reset the window crop to a NULL value, which
809 * disables cropping of the buffers.
810 */
811static inline int native_window_set_buffers_user_dimensions(
812 struct ANativeWindow* window,
813 int w, int h)
814{
815 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
816 w, h);
817}
818
819/*
Jamie Gennis208ec5e2011-07-07 11:51:48 -0700820 * native_window_set_buffers_format(..., int format)
821 * All buffers dequeued after this call will have the format specified.
822 *
823 * If the specified format is 0, the default buffer format will be used.
824 */
825static inline int native_window_set_buffers_format(
826 struct ANativeWindow* window,
827 int format)
828{
829 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
830}
831
832/*
Eino-Ville Talvalab93343d2015-02-17 15:34:44 -0800833 * native_window_set_buffers_data_space(..., int dataSpace)
834 * All buffers queued after this call will be associated with the dataSpace
835 * parameter specified.
836 *
837 * dataSpace specifies additional information about the buffer that's dependent
838 * on the buffer format and the endpoints. For example, it can be used to convey
839 * the color space of the image data in the buffer, or it can be used to
840 * indicate that the buffers contain depth measurement data instead of color
841 * images. The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
842 * overridden by the consumer.
843 */
844static inline int native_window_set_buffers_data_space(
845 struct ANativeWindow* window,
846 android_dataspace_t dataSpace)
847{
848 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
849 dataSpace);
850}
851
852/*
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700853 * native_window_set_buffers_transform(..., int transform)
854 * All buffers queued after this call will be displayed transformed according
855 * to the transform parameter specified.
856 */
857static inline int native_window_set_buffers_transform(
858 struct ANativeWindow* window,
859 int transform)
860{
861 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
862 transform);
863}
864
865/*
Ruben Brunka5e65d82014-06-27 16:15:18 -0700866 * native_window_set_buffers_sticky_transform(..., int transform)
867 * All buffers queued after this call will be displayed transformed according
868 * to the transform parameter specified applied on top of the regular buffer
869 * transform. Setting this transform will disable the transform hint.
870 *
871 * Temporary - This is only intended to be used by the LEGACY camera mode, do
872 * not use this for anything else.
873 */
874static inline int native_window_set_buffers_sticky_transform(
875 struct ANativeWindow* window,
876 int transform)
877{
878 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
879 transform);
880}
881
882/*
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700883 * native_window_set_buffers_timestamp(..., int64_t timestamp)
884 * All buffers queued after this call will be associated with the timestamp
885 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
886 * (the default), timestamps will be generated automatically when queueBuffer is
Glenn Kastenc322f672011-06-27 10:42:39 -0700887 * called. The timestamp is measured in nanoseconds, and is normally monotonically
888 * increasing. The timestamp should be unaffected by time-of-day adjustments,
889 * and for a camera should be strictly monotonic but for a media player may be
890 * reset when the position is set.
Iliyan Malchev0ab886b2011-05-01 14:07:43 -0700891 */
892static inline int native_window_set_buffers_timestamp(
893 struct ANativeWindow* window,
894 int64_t timestamp)
895{
896 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
897 timestamp);
898}
899
Mathias Agopian42cc1ed2011-07-13 15:49:58 -0700900/*
901 * native_window_set_scaling_mode(..., int mode)
902 * All buffers queued after this call will be associated with the scaling mode
903 * specified.
904 */
905static inline int native_window_set_scaling_mode(
906 struct ANativeWindow* window,
907 int mode)
908{
909 return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
910 mode);
911}
912
Mathias Agopian8ad54522011-07-29 17:52:36 -0700913/*
914 * native_window_api_connect(..., int api)
915 * connects an API to this window. only one API can be connected at a time.
916 * Returns -EINVAL if for some reason the window cannot be connected, which
917 * can happen if it's connected to some other API.
918 */
919static inline int native_window_api_connect(
920 struct ANativeWindow* window, int api)
921{
Mathias Agopian319f4e22011-08-03 11:26:38 -0700922 return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
Mathias Agopian8ad54522011-07-29 17:52:36 -0700923}
924
925/*
926 * native_window_api_disconnect(..., int api)
927 * disconnect the API from this window.
928 * An error is returned if for instance the window wasn't connected in the
929 * first place.
930 */
931static inline int native_window_api_disconnect(
932 struct ANativeWindow* window, int api)
933{
Mathias Agopian319f4e22011-08-03 11:26:38 -0700934 return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
Mathias Agopian8ad54522011-07-29 17:52:36 -0700935}
936
Jamie Gennis22aec572012-06-13 16:43:06 -0700937/*
938 * native_window_dequeue_buffer_and_wait(...)
939 * Dequeue a buffer and wait on the fence associated with that buffer. The
940 * buffer may safely be accessed immediately upon this function returning. An
941 * error is returned if either of the dequeue or the wait operations fail.
942 */
943static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
944 struct ANativeWindowBuffer** anb) {
Jesse Hallbc930ed2012-10-01 13:48:36 -0700945 return anw->dequeueBuffer_DEPRECATED(anw, anb);
Jamie Gennis22aec572012-06-13 16:43:06 -0700946}
947
Rachadd6d4c612014-07-29 18:03:21 -0700948/*
949 * native_window_set_sideband_stream(..., native_handle_t*)
950 * Attach a sideband buffer stream to a native window.
951 */
952static inline int native_window_set_sideband_stream(
953 struct ANativeWindow* window,
954 native_handle_t* sidebandHandle)
955{
956 return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
957 sidebandHandle);
958}
Mathias Agopian8ad54522011-07-29 17:52:36 -0700959
Dan Stoza238ec982015-03-23 10:43:14 -0700960/*
961 * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
962 * Set the surface damage (i.e., the region of the surface that has changed
963 * since the previous frame). The damage set by this call will be reset (to the
964 * default of full-surface damage) after calling queue, so this must be called
965 * prior to every frame with damage that does not cover the whole surface if the
966 * caller desires downstream consumers to use this optimization.
967 *
968 * The damage region is specified as an array of rectangles, with the important
969 * caveat that the origin of the surface is considered to be the bottom-left
970 * corner, as in OpenGL ES.
971 *
972 * If numRects is set to 0, rects may be NULL, and the surface damage will be
973 * set to the full surface (the same as if this function had not been called for
974 * this frame).
975 */
976static inline int native_window_set_surface_damage(
977 struct ANativeWindow* window,
978 const android_native_rect_t* rects, size_t numRects)
979{
980 return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
981 rects, numRects);
982}
983
Pablo Ceballos923d27f2015-10-19 10:24:42 -0700984/*
Pablo Ceballos248e7712016-03-17 15:42:21 -0700985 * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
986 * Enable/disable shared buffer mode
Pablo Ceballos923d27f2015-10-19 10:24:42 -0700987 */
Pablo Ceballos248e7712016-03-17 15:42:21 -0700988static inline int native_window_set_shared_buffer_mode(
Pablo Ceballos923d27f2015-10-19 10:24:42 -0700989 struct ANativeWindow* window,
Pablo Ceballos248e7712016-03-17 15:42:21 -0700990 bool sharedBufferMode)
Pablo Ceballos923d27f2015-10-19 10:24:42 -0700991{
Pablo Ceballos248e7712016-03-17 15:42:21 -0700992 return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
993 sharedBufferMode);
Pablo Ceballos923d27f2015-10-19 10:24:42 -0700994}
995
Pablo Ceballos3daa5742016-01-15 13:31:14 -0800996/*
997 * native_window_set_auto_refresh(..., autoRefresh)
Pablo Ceballos248e7712016-03-17 15:42:21 -0700998 * Enable/disable auto refresh when in shared buffer mode
Pablo Ceballos3daa5742016-01-15 13:31:14 -0800999 */
1000static inline int native_window_set_auto_refresh(
1001 struct ANativeWindow* window,
1002 bool autoRefresh)
1003{
1004 return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
1005}
1006
Pablo Ceballosc2efc322016-05-31 11:06:03 -07001007static inline int native_window_get_frame_timestamps(
1008 struct ANativeWindow* window, uint32_t framesAgo,
Brian Anderson18f29032016-07-22 10:38:53 -07001009 int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
Pablo Ceballosc2efc322016-05-31 11:06:03 -07001010 int64_t* outRefreshStartTime, int64_t* outGlCompositionDoneTime,
1011 int64_t* outDisplayRetireTime, int64_t* outReleaseTime)
1012{
1013 return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
Brian Anderson18f29032016-07-22 10:38:53 -07001014 framesAgo, outRequestedPresentTime, outAcquireTime,
1015 outRefreshStartTime, outGlCompositionDoneTime, outDisplayRetireTime,
1016 outReleaseTime);
Pablo Ceballosc2efc322016-05-31 11:06:03 -07001017}
1018
1019
Iliyan Malchev0ab886b2011-05-01 14:07:43 -07001020__END_DECLS
1021
tedbo1ffdb382011-05-24 00:55:33 -07001022#endif /* SYSTEM_CORE_INCLUDE_ANDROID_WINDOW_H */