blob: 3df97a1b4a7a09fbbe385efc24327e1349e0c115 [file] [log] [blame]
Mathias Agopiana6c0e202017-03-20 15:48:44 -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/*************************************************************************************************
18 *
19 * IMPORTANT:
20 *
21 * There is an old copy of this file in system/core/include/system/window.h, which exists only
22 * for backward source compatibility.
23 * But there are binaries out there as well, so this version of window.h must stay binary
24 * backward compatible with the one found in system/core.
25 *
26 *
27 * Source compatibility is also required for now, because this is how we're handling the
28 * transition from system/core/include (global include path) to nativewindow/include.
29 *
30 *************************************************************************************************/
31
32#pragma once
33
34#include <cutils/native_handle.h>
35#include <errno.h>
36#include <limits.h>
37#include <stdint.h>
38#include <string.h>
39#include <sys/cdefs.h>
40#include <system/graphics.h>
41#include <unistd.h>
42#include <stdbool.h>
43
44// system/window.h is a superset of the vndk
45#include <vndk/window.h>
46
47
48#ifndef __UNUSED
49#define __UNUSED __attribute__((__unused__))
50#endif
51#ifndef __deprecated
52#define __deprecated __attribute__((__deprecated__))
53#endif
54
55__BEGIN_DECLS
56
57/*****************************************************************************/
58
Mathias Agopian000879a2017-03-20 18:07:26 -070059#define ANDROID_NATIVE_WINDOW_MAGIC ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
Mathias Agopiana6c0e202017-03-20 15:48:44 -070060
61// ---------------------------------------------------------------------------
62
Mathias Agopiana6c0e202017-03-20 15:48:44 -070063/* attributes queriable with query() */
64enum {
65 NATIVE_WINDOW_WIDTH = 0,
66 NATIVE_WINDOW_HEIGHT = 1,
67 NATIVE_WINDOW_FORMAT = 2,
68
Mathias Agopian000879a2017-03-20 18:07:26 -070069 /* see ANativeWindowQuery in vndk/window.h */
70 NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS,
Mathias Agopiana6c0e202017-03-20 15:48:44 -070071
72 /* Check whether queueBuffer operations on the ANativeWindow send the buffer
73 * to the window compositor. The query sets the returned 'value' argument
74 * to 1 if the ANativeWindow DOES send queued buffers directly to the window
75 * compositor and 0 if the buffers do not go directly to the window
76 * compositor.
77 *
78 * This can be used to determine whether protected buffer content should be
79 * sent to the ANativeWindow. Note, however, that a result of 1 does NOT
80 * indicate that queued buffers will be protected from applications or users
81 * capturing their contents. If that behavior is desired then some other
82 * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
83 * conjunction with this query.
84 */
85 NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
86
87 /* Get the concrete type of a ANativeWindow. See below for the list of
88 * possible return values.
89 *
90 * This query should not be used outside the Android framework and will
91 * likely be removed in the near future.
92 */
93 NATIVE_WINDOW_CONCRETE_TYPE = 5,
94
95
96 /*
97 * Default width and height of ANativeWindow buffers, these are the
98 * dimensions of the window buffers irrespective of the
99 * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window
100 * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS.
101 */
Mathias Agopian000879a2017-03-20 18:07:26 -0700102 NATIVE_WINDOW_DEFAULT_WIDTH = ANATIVEWINDOW_QUERY_DEFAULT_WIDTH,
103 NATIVE_WINDOW_DEFAULT_HEIGHT = ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700104
Mathias Agopian000879a2017-03-20 18:07:26 -0700105 /* see ANativeWindowQuery in vndk/window.h */
106 NATIVE_WINDOW_TRANSFORM_HINT = ANATIVEWINDOW_QUERY_TRANSFORM_HINT,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700107
108 /*
109 * Boolean that indicates whether the consumer is running more than
110 * one buffer behind the producer.
111 */
112 NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9,
113
114 /*
115 * The consumer gralloc usage bits currently set by the consumer.
116 * The values are defined in hardware/libhardware/include/gralloc.h.
117 */
118 NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10,
119
120 /**
121 * Transformation that will by applied to buffers by the hwcomposer.
122 * This must not be set or checked by producer endpoints, and will
123 * disable the transform hint set in SurfaceFlinger (see
124 * NATIVE_WINDOW_TRANSFORM_HINT).
125 *
126 * INTENDED USE:
127 * Temporary - Please do not use this. This is intended only to be used
128 * by the camera's LEGACY mode.
129 *
130 * In situations where a SurfaceFlinger client wishes to set a transform
131 * that is not visible to the producer, and will always be applied in the
132 * hardware composer, the client can set this flag with
133 * native_window_set_buffers_sticky_transform. This can be used to rotate
134 * and flip buffers consumed by hardware composer without actually changing
135 * the aspect ratio of the buffers produced.
136 */
137 NATIVE_WINDOW_STICKY_TRANSFORM = 11,
138
139 /**
140 * The default data space for the buffers as set by the consumer.
141 * The values are defined in graphics.h.
142 */
143 NATIVE_WINDOW_DEFAULT_DATASPACE = 12,
144
Mathias Agopian000879a2017-03-20 18:07:26 -0700145 /* see ANativeWindowQuery in vndk/window.h */
146 NATIVE_WINDOW_BUFFER_AGE = ANATIVEWINDOW_QUERY_BUFFER_AGE,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700147
148 /*
149 * Returns the duration of the last dequeueBuffer call in microseconds
150 */
151 NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
152
153 /*
154 * Returns the duration of the last queueBuffer call in microseconds
155 */
156 NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
157
158 /*
159 * Returns the number of image layers that the ANativeWindow buffer
160 * contains. By default this is 1, unless a buffer is explicitly allocated
161 * to contain multiple layers.
162 */
163 NATIVE_WINDOW_LAYER_COUNT = 16,
164
165 /*
166 * Returns 1 if the native window is valid, 0 otherwise. native window is valid
167 * if it is safe (i.e. no crash will occur) to call any method on it.
168 */
169 NATIVE_WINDOW_IS_VALID = 17,
Brian Anderson6b376712017-04-04 10:51:39 -0700170
171 /*
172 * Returns 1 if NATIVE_WINDOW_GET_FRAME_TIMESTAMPS will return display
173 * present info, 0 if it won't.
174 */
175 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18,
Jiwen 'Steve' Cai20419132017-04-21 18:49:53 -0700176
177 /*
178 * The consumer end is capable of handling protected buffers, i.e. buffer
179 * with GRALLOC_USAGE_PROTECTED usage bits on.
180 */
181 NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700182};
183
184/* Valid operations for the (*perform)() hook.
185 *
186 * Values marked as 'deprecated' are supported, but have been superceded by
187 * other functionality.
188 *
189 * Values marked as 'private' should be considered private to the framework.
190 * HAL implementation code with access to an ANativeWindow should not use these,
191 * as it may not interact properly with the framework's use of the
192 * ANativeWindow.
193 */
194enum {
195// clang-format off
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700196 NATIVE_WINDOW_SET_USAGE = 0, /* deprecated */
197 NATIVE_WINDOW_CONNECT = 1, /* deprecated */
198 NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */
199 NATIVE_WINDOW_SET_CROP = 3, /* private */
200 NATIVE_WINDOW_SET_BUFFER_COUNT = 4,
201 NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */
202 NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6,
203 NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7,
204 NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8,
205 NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9,
206 NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */
207 NATIVE_WINDOW_LOCK = 11, /* private */
208 NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */
209 NATIVE_WINDOW_API_CONNECT = 13, /* private */
210 NATIVE_WINDOW_API_DISCONNECT = 14, /* private */
211 NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
212 NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* deprecated, unimplemented */
213 NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17, /* private */
214 NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18,
215 NATIVE_WINDOW_SET_BUFFERS_DATASPACE = 19,
216 NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */
217 NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21,
218 NATIVE_WINDOW_SET_AUTO_REFRESH = 22,
219 NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION = 23,
220 NATIVE_WINDOW_GET_NEXT_FRAME_ID = 24,
221 NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS = 25,
222 NATIVE_WINDOW_GET_COMPOSITOR_TIMING = 26,
223 NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 27,
224 NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT = 28,
225 NATIVE_WINDOW_GET_HDR_SUPPORT = 29,
226 NATIVE_WINDOW_SET_USAGE64 = 30,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700227// clang-format on
228};
229
230/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
231enum {
232 /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
233 * OpenGL ES.
234 */
235 NATIVE_WINDOW_API_EGL = 1,
236
237 /* Buffers will be queued after being filled using the CPU
238 */
239 NATIVE_WINDOW_API_CPU = 2,
240
241 /* Buffers will be queued by Stagefright after being filled by a video
242 * decoder. The video decoder can either be a software or hardware decoder.
243 */
244 NATIVE_WINDOW_API_MEDIA = 3,
245
246 /* Buffers will be queued by the the camera HAL.
247 */
248 NATIVE_WINDOW_API_CAMERA = 4,
249};
250
251/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
252enum {
253 /* flip source image horizontally */
254 NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
255 /* flip source image vertically */
256 NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
257 /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
258 NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
259 /* rotate source image 180 degrees */
260 NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
261 /* rotate source image 270 degrees clock-wise */
262 NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
263 /* transforms source by the inverse transform of the screen it is displayed onto. This
264 * transform is applied last */
265 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
266};
267
268/* parameter for NATIVE_WINDOW_SET_SCALING_MODE
269 * keep in sync with Surface.java in frameworks/base */
270enum {
271 /* the window content is not updated (frozen) until a buffer of
272 * the window size is received (enqueued)
273 */
274 NATIVE_WINDOW_SCALING_MODE_FREEZE = 0,
275 /* the buffer is scaled in both dimensions to match the window size */
276 NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1,
277 /* the buffer is scaled uniformly such that the smaller dimension
278 * of the buffer matches the window size (cropping in the process)
279 */
280 NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2,
281 /* the window is clipped to the size of the buffer's crop rectangle; pixels
282 * outside the crop rectangle are treated as if they are completely
283 * transparent.
284 */
285 NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3,
286};
287
288/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
289enum {
290 NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
291 NATIVE_WINDOW_SURFACE = 1, /* Surface */
292};
293
294/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
295 *
296 * Special timestamp value to indicate that timestamps should be auto-generated
297 * by the native window when queueBuffer is called. This is equal to INT64_MIN,
298 * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
299 */
300static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
301
Brian Andersondc96fdf2017-03-20 16:54:25 -0700302/* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS
303 *
304 * Special timestamp value to indicate the timestamps aren't yet known or
305 * that they are invalid.
306 */
307static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2;
308static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1;
309
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700310struct ANativeWindow
311{
312#ifdef __cplusplus
313 ANativeWindow()
314 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
315 {
316 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
317 common.version = sizeof(ANativeWindow);
318 memset(common.reserved, 0, sizeof(common.reserved));
319 }
320
321 /* Implement the methods that sp<ANativeWindow> expects so that it
322 can be used to automatically refcount ANativeWindow's. */
323 void incStrong(const void* /*id*/) const {
324 common.incRef(const_cast<android_native_base_t*>(&common));
325 }
326 void decStrong(const void* /*id*/) const {
327 common.decRef(const_cast<android_native_base_t*>(&common));
328 }
329#endif
330
331 struct android_native_base_t common;
332
333 /* flags describing some attributes of this surface or its updater */
334 const uint32_t flags;
335
336 /* min swap interval supported by this updated */
337 const int minSwapInterval;
338
339 /* max swap interval supported by this updated */
340 const int maxSwapInterval;
341
342 /* horizontal and vertical resolution in DPI */
343 const float xdpi;
344 const float ydpi;
345
346 /* Some storage reserved for the OEM's driver. */
347 intptr_t oem[4];
348
349 /*
350 * Set the swap interval for this surface.
351 *
352 * Returns 0 on success or -errno on error.
353 */
354 int (*setSwapInterval)(struct ANativeWindow* window,
355 int interval);
356
357 /*
358 * Hook called by EGL to acquire a buffer. After this call, the buffer
359 * is not locked, so its content cannot be modified. This call may block if
360 * no buffers are available.
361 *
362 * The window holds a reference to the buffer between dequeueBuffer and
363 * either queueBuffer or cancelBuffer, so clients only need their own
364 * reference if they might use the buffer after queueing or canceling it.
365 * Holding a reference to a buffer after queueing or canceling it is only
366 * allowed if a specific buffer count has been set.
367 *
368 * Returns 0 on success or -errno on error.
369 *
370 * XXX: This function is deprecated. It will continue to work for some
371 * time for binary compatibility, but the new dequeueBuffer function that
372 * outputs a fence file descriptor should be used in its place.
373 */
374 int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
375 struct ANativeWindowBuffer** buffer);
376
377 /*
378 * hook called by EGL to lock a buffer. This MUST be called before modifying
379 * the content of a buffer. The buffer must have been acquired with
380 * dequeueBuffer first.
381 *
382 * Returns 0 on success or -errno on error.
383 *
384 * XXX: This function is deprecated. It will continue to work for some
385 * time for binary compatibility, but it is essentially a no-op, and calls
386 * to it should be removed.
387 */
388 int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
389 struct ANativeWindowBuffer* buffer);
390
391 /*
392 * Hook called by EGL when modifications to the render buffer are done.
393 * This unlocks and post the buffer.
394 *
395 * The window holds a reference to the buffer between dequeueBuffer and
396 * either queueBuffer or cancelBuffer, so clients only need their own
397 * reference if they might use the buffer after queueing or canceling it.
398 * Holding a reference to a buffer after queueing or canceling it is only
399 * allowed if a specific buffer count has been set.
400 *
401 * Buffers MUST be queued in the same order than they were dequeued.
402 *
403 * Returns 0 on success or -errno on error.
404 *
405 * XXX: This function is deprecated. It will continue to work for some
406 * time for binary compatibility, but the new queueBuffer function that
407 * takes a fence file descriptor should be used in its place (pass a value
408 * of -1 for the fence file descriptor if there is no valid one to pass).
409 */
410 int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
411 struct ANativeWindowBuffer* buffer);
412
413 /*
414 * hook used to retrieve information about the native window.
415 *
416 * Returns 0 on success or -errno on error.
417 */
418 int (*query)(const struct ANativeWindow* window,
419 int what, int* value);
420
421 /*
422 * hook used to perform various operations on the surface.
423 * (*perform)() is a generic mechanism to add functionality to
424 * ANativeWindow while keeping backward binary compatibility.
425 *
426 * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
427 * defined below.
428 *
429 * (*perform)() returns -ENOENT if the 'what' parameter is not supported
430 * by the surface's implementation.
431 *
432 * See above for a list of valid operations, such as
433 * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
434 */
435 int (*perform)(struct ANativeWindow* window,
436 int operation, ... );
437
438 /*
439 * Hook used to cancel a buffer that has been dequeued.
440 * No synchronization is performed between dequeue() and cancel(), so
441 * either external synchronization is needed, or these functions must be
442 * called from the same thread.
443 *
444 * The window holds a reference to the buffer between dequeueBuffer and
445 * either queueBuffer or cancelBuffer, so clients only need their own
446 * reference if they might use the buffer after queueing or canceling it.
447 * Holding a reference to a buffer after queueing or canceling it is only
448 * allowed if a specific buffer count has been set.
449 *
450 * XXX: This function is deprecated. It will continue to work for some
451 * time for binary compatibility, but the new cancelBuffer function that
452 * takes a fence file descriptor should be used in its place (pass a value
453 * of -1 for the fence file descriptor if there is no valid one to pass).
454 */
455 int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
456 struct ANativeWindowBuffer* buffer);
457
458 /*
459 * Hook called by EGL to acquire a buffer. This call may block if no
460 * buffers are available.
461 *
462 * The window holds a reference to the buffer between dequeueBuffer and
463 * either queueBuffer or cancelBuffer, so clients only need their own
464 * reference if they might use the buffer after queueing or canceling it.
465 * Holding a reference to a buffer after queueing or canceling it is only
466 * allowed if a specific buffer count has been set.
467 *
468 * The libsync fence file descriptor returned in the int pointed to by the
469 * fenceFd argument will refer to the fence that must signal before the
470 * dequeued buffer may be written to. A value of -1 indicates that the
471 * caller may access the buffer immediately without waiting on a fence. If
472 * a valid file descriptor is returned (i.e. any value except -1) then the
473 * caller is responsible for closing the file descriptor.
474 *
475 * Returns 0 on success or -errno on error.
476 */
477 int (*dequeueBuffer)(struct ANativeWindow* window,
478 struct ANativeWindowBuffer** buffer, int* fenceFd);
479
480 /*
481 * Hook called by EGL when modifications to the render buffer are done.
482 * This unlocks and post the buffer.
483 *
484 * The window holds a reference to the buffer between dequeueBuffer and
485 * either queueBuffer or cancelBuffer, so clients only need their own
486 * reference if they might use the buffer after queueing or canceling it.
487 * Holding a reference to a buffer after queueing or canceling it is only
488 * allowed if a specific buffer count has been set.
489 *
490 * The fenceFd argument specifies a libsync fence file descriptor for a
491 * fence that must signal before the buffer can be accessed. If the buffer
492 * can be accessed immediately then a value of -1 should be used. The
493 * caller must not use the file descriptor after it is passed to
494 * queueBuffer, and the ANativeWindow implementation is responsible for
495 * closing it.
496 *
497 * Returns 0 on success or -errno on error.
498 */
499 int (*queueBuffer)(struct ANativeWindow* window,
500 struct ANativeWindowBuffer* buffer, int fenceFd);
501
502 /*
503 * Hook used to cancel a buffer that has been dequeued.
504 * No synchronization is performed between dequeue() and cancel(), so
505 * either external synchronization is needed, or these functions must be
506 * called from the same thread.
507 *
508 * The window holds a reference to the buffer between dequeueBuffer and
509 * either queueBuffer or cancelBuffer, so clients only need their own
510 * reference if they might use the buffer after queueing or canceling it.
511 * Holding a reference to a buffer after queueing or canceling it is only
512 * allowed if a specific buffer count has been set.
513 *
514 * The fenceFd argument specifies a libsync fence file decsriptor for a
515 * fence that must signal before the buffer can be accessed. If the buffer
516 * can be accessed immediately then a value of -1 should be used.
517 *
518 * Note that if the client has not waited on the fence that was returned
519 * from dequeueBuffer, that same fence should be passed to cancelBuffer to
520 * ensure that future uses of the buffer are preceded by a wait on that
521 * fence. The caller must not use the file descriptor after it is passed
522 * to cancelBuffer, and the ANativeWindow implementation is responsible for
523 * closing it.
524 *
525 * Returns 0 on success or -errno on error.
526 */
527 int (*cancelBuffer)(struct ANativeWindow* window,
528 struct ANativeWindowBuffer* buffer, int fenceFd);
529};
530
531 /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
532 * android_native_window_t is deprecated.
533 */
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700534typedef struct ANativeWindow android_native_window_t __deprecated;
535
536/*
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700537 * native_window_set_usage64(..., usage)
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700538 * Sets the intended usage flags for the next buffers
539 * acquired with (*lockBuffer)() and on.
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700540 *
541 * Valid usage flags are defined in android/hardware_buffer.h
542 * All AHARDWAREBUFFER_USAGE_* flags can be specified as needed.
543 *
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700544 * Calling this function will usually cause following buffers to be
545 * reallocated.
546 */
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700547static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) {
548 return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700549}
550
551/* deprecated. Always returns 0. Don't call. */
552static inline int native_window_connect(
553 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
554
555static inline int native_window_connect(
556 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
557 return 0;
558}
559
560/* deprecated. Always returns 0. Don't call. */
561static inline int native_window_disconnect(
562 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
563
564static inline int native_window_disconnect(
565 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
566 return 0;
567}
568
569/*
570 * native_window_set_crop(..., crop)
571 * Sets which region of the next queued buffers needs to be considered.
572 * Depending on the scaling mode, a buffer's crop region is scaled and/or
573 * cropped to match the surface's size. This function sets the crop in
574 * pre-transformed buffer pixel coordinates.
575 *
576 * The specified crop region applies to all buffers queued after it is called.
577 *
578 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
579 *
580 * An error is returned if for instance the crop region is invalid, out of the
581 * buffer's bound or if the window is invalid.
582 */
583static inline int native_window_set_crop(
584 struct ANativeWindow* window,
585 android_native_rect_t const * crop)
586{
587 return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
588}
589
590/*
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700591 * native_window_set_buffer_count(..., count)
592 * Sets the number of buffers associated with this native window.
593 */
594static inline int native_window_set_buffer_count(
595 struct ANativeWindow* window,
596 size_t bufferCount)
597{
598 return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
599}
600
601/*
602 * native_window_set_buffers_geometry(..., int w, int h, int format)
603 * All buffers dequeued after this call will have the dimensions and format
604 * specified. A successful call to this function has the same effect as calling
605 * native_window_set_buffers_size and native_window_set_buffers_format.
606 *
607 * XXX: This function is deprecated. The native_window_set_buffers_dimensions
608 * and native_window_set_buffers_format functions should be used instead.
609 */
610static inline int native_window_set_buffers_geometry(
611 struct ANativeWindow* window,
612 int w, int h, int format) __deprecated;
613
614static inline int native_window_set_buffers_geometry(
615 struct ANativeWindow* window,
616 int w, int h, int format)
617{
618 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
619 w, h, format);
620}
621
622/*
623 * native_window_set_buffers_dimensions(..., int w, int h)
624 * All buffers dequeued after this call will have the dimensions specified.
625 * In particular, all buffers will have a fixed-size, independent from the
626 * native-window size. They will be scaled according to the scaling mode
627 * (see native_window_set_scaling_mode) upon window composition.
628 *
629 * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
630 * following this call will be sized to match the window's size.
631 *
632 * Calling this function will reset the window crop to a NULL value, which
633 * disables cropping of the buffers.
634 */
635static inline int native_window_set_buffers_dimensions(
636 struct ANativeWindow* window,
637 int w, int h)
638{
639 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
640 w, h);
641}
642
643/*
644 * native_window_set_buffers_user_dimensions(..., int w, int h)
645 *
646 * Sets the user buffer size for the window, which overrides the
647 * window's size. All buffers dequeued after this call will have the
648 * dimensions specified unless overridden by
649 * native_window_set_buffers_dimensions. All buffers will have a
650 * fixed-size, independent from the native-window size. They will be
651 * scaled according to the scaling mode (see
652 * native_window_set_scaling_mode) upon window composition.
653 *
654 * If w and h are 0, the normal behavior is restored. That is, the
655 * default buffer size will match the windows's size.
656 *
657 * Calling this function will reset the window crop to a NULL value, which
658 * disables cropping of the buffers.
659 */
660static inline int native_window_set_buffers_user_dimensions(
661 struct ANativeWindow* window,
662 int w, int h)
663{
664 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
665 w, h);
666}
667
668/*
669 * native_window_set_buffers_format(..., int format)
670 * All buffers dequeued after this call will have the format specified.
671 *
672 * If the specified format is 0, the default buffer format will be used.
673 */
674static inline int native_window_set_buffers_format(
675 struct ANativeWindow* window,
676 int format)
677{
678 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
679}
680
681/*
682 * native_window_set_buffers_data_space(..., int dataSpace)
683 * All buffers queued after this call will be associated with the dataSpace
684 * parameter specified.
685 *
686 * dataSpace specifies additional information about the buffer that's dependent
687 * on the buffer format and the endpoints. For example, it can be used to convey
688 * the color space of the image data in the buffer, or it can be used to
689 * indicate that the buffers contain depth measurement data instead of color
690 * images. The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
691 * overridden by the consumer.
692 */
693static inline int native_window_set_buffers_data_space(
694 struct ANativeWindow* window,
695 android_dataspace_t dataSpace)
696{
697 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
698 dataSpace);
699}
700
701/*
702 * native_window_set_buffers_transform(..., int transform)
703 * All buffers queued after this call will be displayed transformed according
704 * to the transform parameter specified.
705 */
706static inline int native_window_set_buffers_transform(
707 struct ANativeWindow* window,
708 int transform)
709{
710 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
711 transform);
712}
713
714/*
715 * native_window_set_buffers_sticky_transform(..., int transform)
716 * All buffers queued after this call will be displayed transformed according
717 * to the transform parameter specified applied on top of the regular buffer
718 * transform. Setting this transform will disable the transform hint.
719 *
720 * Temporary - This is only intended to be used by the LEGACY camera mode, do
721 * not use this for anything else.
722 */
723static inline int native_window_set_buffers_sticky_transform(
724 struct ANativeWindow* window,
725 int transform)
726{
727 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
728 transform);
729}
730
731/*
732 * native_window_set_buffers_timestamp(..., int64_t timestamp)
733 * All buffers queued after this call will be associated with the timestamp
734 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
735 * (the default), timestamps will be generated automatically when queueBuffer is
736 * called. The timestamp is measured in nanoseconds, and is normally monotonically
737 * increasing. The timestamp should be unaffected by time-of-day adjustments,
738 * and for a camera should be strictly monotonic but for a media player may be
739 * reset when the position is set.
740 */
741static inline int native_window_set_buffers_timestamp(
742 struct ANativeWindow* window,
743 int64_t timestamp)
744{
745 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
746 timestamp);
747}
748
749/*
750 * native_window_set_scaling_mode(..., int mode)
751 * All buffers queued after this call will be associated with the scaling mode
752 * specified.
753 */
754static inline int native_window_set_scaling_mode(
755 struct ANativeWindow* window,
756 int mode)
757{
758 return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
759 mode);
760}
761
762/*
763 * native_window_api_connect(..., int api)
764 * connects an API to this window. only one API can be connected at a time.
765 * Returns -EINVAL if for some reason the window cannot be connected, which
766 * can happen if it's connected to some other API.
767 */
768static inline int native_window_api_connect(
769 struct ANativeWindow* window, int api)
770{
771 return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
772}
773
774/*
775 * native_window_api_disconnect(..., int api)
776 * disconnect the API from this window.
777 * An error is returned if for instance the window wasn't connected in the
778 * first place.
779 */
780static inline int native_window_api_disconnect(
781 struct ANativeWindow* window, int api)
782{
783 return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
784}
785
786/*
787 * native_window_dequeue_buffer_and_wait(...)
788 * Dequeue a buffer and wait on the fence associated with that buffer. The
789 * buffer may safely be accessed immediately upon this function returning. An
790 * error is returned if either of the dequeue or the wait operations fail.
791 */
792static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
793 struct ANativeWindowBuffer** anb) {
794 return anw->dequeueBuffer_DEPRECATED(anw, anb);
795}
796
797/*
798 * native_window_set_sideband_stream(..., native_handle_t*)
799 * Attach a sideband buffer stream to a native window.
800 */
801static inline int native_window_set_sideband_stream(
802 struct ANativeWindow* window,
803 native_handle_t* sidebandHandle)
804{
805 return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
806 sidebandHandle);
807}
808
809/*
810 * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
811 * Set the surface damage (i.e., the region of the surface that has changed
812 * since the previous frame). The damage set by this call will be reset (to the
813 * default of full-surface damage) after calling queue, so this must be called
814 * prior to every frame with damage that does not cover the whole surface if the
815 * caller desires downstream consumers to use this optimization.
816 *
817 * The damage region is specified as an array of rectangles, with the important
818 * caveat that the origin of the surface is considered to be the bottom-left
819 * corner, as in OpenGL ES.
820 *
821 * If numRects is set to 0, rects may be NULL, and the surface damage will be
822 * set to the full surface (the same as if this function had not been called for
823 * this frame).
824 */
825static inline int native_window_set_surface_damage(
826 struct ANativeWindow* window,
827 const android_native_rect_t* rects, size_t numRects)
828{
829 return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
830 rects, numRects);
831}
832
833/*
834 * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
835 * Enable/disable shared buffer mode
836 */
837static inline int native_window_set_shared_buffer_mode(
838 struct ANativeWindow* window,
839 bool sharedBufferMode)
840{
841 return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
842 sharedBufferMode);
843}
844
845/*
846 * native_window_set_auto_refresh(..., autoRefresh)
847 * Enable/disable auto refresh when in shared buffer mode
848 */
849static inline int native_window_set_auto_refresh(
850 struct ANativeWindow* window,
851 bool autoRefresh)
852{
853 return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
854}
855
856static inline int native_window_get_refresh_cycle_duration(
857 struct ANativeWindow* window,
858 int64_t* outRefreshDuration)
859{
860 return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION,
861 outRefreshDuration);
862}
863
864static inline int native_window_get_next_frame_id(
865 struct ANativeWindow* window, uint64_t* frameId)
866{
867 return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId);
868}
869
870static inline int native_window_enable_frame_timestamps(
871 struct ANativeWindow* window, bool enable)
872{
873 return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS,
874 enable);
875}
876
877static inline int native_window_get_compositor_timing(
878 struct ANativeWindow* window,
879 int64_t* compositeDeadline, int64_t* compositeInterval,
880 int64_t* compositeToPresentLatency)
881{
882 return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING,
883 compositeDeadline, compositeInterval, compositeToPresentLatency);
884}
885
886static inline int native_window_get_frame_timestamps(
887 struct ANativeWindow* window, uint64_t frameId,
888 int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
889 int64_t* outLatchTime, int64_t* outFirstRefreshStartTime,
890 int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime,
891 int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime,
892 int64_t* outReleaseTime)
893{
894 return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
895 frameId, outRequestedPresentTime, outAcquireTime, outLatchTime,
896 outFirstRefreshStartTime, outLastRefreshStartTime,
897 outGpuCompositionDoneTime, outDisplayPresentTime,
898 outDequeueReadyTime, outReleaseTime);
899}
900
901static inline int native_window_get_wide_color_support(
902 struct ANativeWindow* window, bool* outSupport) {
903 return window->perform(window, NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT,
904 outSupport);
905}
906
907static inline int native_window_get_hdr_support(struct ANativeWindow* window,
908 bool* outSupport) {
909 return window->perform(window, NATIVE_WINDOW_GET_HDR_SUPPORT, outSupport);
910}
911
912__END_DECLS