blob: a4e5afd38d6f2871653efc3111d6b2436fe5e3ee [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>
Steven Thomas3172e202020-01-06 19:25:30 -080037#include <stdbool.h>
Mathias Agopiana6c0e202017-03-20 15:48:44 -070038#include <stdint.h>
39#include <string.h>
40#include <sys/cdefs.h>
41#include <system/graphics.h>
42#include <unistd.h>
Mathias Agopiana6c0e202017-03-20 15:48:44 -070043
Alec Mouri9fa2cb62019-07-15 17:36:26 -070044// system/window.h is a superset of the vndk and apex apis
45#include <apex/window.h>
Mathias Agopiana6c0e202017-03-20 15:48:44 -070046#include <vndk/window.h>
47
48
49#ifndef __UNUSED
50#define __UNUSED __attribute__((__unused__))
51#endif
52#ifndef __deprecated
53#define __deprecated __attribute__((__deprecated__))
54#endif
55
56__BEGIN_DECLS
57
58/*****************************************************************************/
59
Mathias Agopian000879a2017-03-20 18:07:26 -070060#define ANDROID_NATIVE_WINDOW_MAGIC ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d')
Mathias Agopiana6c0e202017-03-20 15:48:44 -070061
62// ---------------------------------------------------------------------------
63
Mathias Agopiana6c0e202017-03-20 15:48:44 -070064/* attributes queriable with query() */
65enum {
Alec Mouri72670c52019-08-31 01:54:33 -070066 NATIVE_WINDOW_WIDTH = 0,
67 NATIVE_WINDOW_HEIGHT = 1,
68 NATIVE_WINDOW_FORMAT = 2,
Mathias Agopiana6c0e202017-03-20 15:48:44 -070069
Mathias Agopian000879a2017-03-20 18:07:26 -070070 /* see ANativeWindowQuery in vndk/window.h */
71 NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = ANATIVEWINDOW_QUERY_MIN_UNDEQUEUED_BUFFERS,
Mathias Agopiana6c0e202017-03-20 15:48:44 -070072
73 /* Check whether queueBuffer operations on the ANativeWindow send the buffer
74 * to the window compositor. The query sets the returned 'value' argument
75 * to 1 if the ANativeWindow DOES send queued buffers directly to the window
76 * compositor and 0 if the buffers do not go directly to the window
77 * compositor.
78 *
79 * This can be used to determine whether protected buffer content should be
80 * sent to the ANativeWindow. Note, however, that a result of 1 does NOT
81 * indicate that queued buffers will be protected from applications or users
82 * capturing their contents. If that behavior is desired then some other
83 * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in
84 * conjunction with this query.
85 */
86 NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4,
87
88 /* Get the concrete type of a ANativeWindow. See below for the list of
89 * possible return values.
90 *
91 * This query should not be used outside the Android framework and will
92 * likely be removed in the near future.
93 */
94 NATIVE_WINDOW_CONCRETE_TYPE = 5,
95
Mathias Agopiana6c0e202017-03-20 15:48:44 -070096 /*
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 */
Chia-I Wue2786ea2017-08-07 10:36:08 -0700118 NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10, /* deprecated */
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700119
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
Alec Mouri72670c52019-08-31 01:54:33 -0700150 * Deprecated: please use NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION in
151 * perform() instead, which supports nanosecond precision.
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700152 */
153 NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14,
154
155 /*
156 * Returns the duration of the last queueBuffer call in microseconds
Alec Mouri72670c52019-08-31 01:54:33 -0700157 * Deprecated: please use NATIVE_WINDOW_GET_LAST_QUEUE_DURATION in
158 * perform() instead, which supports nanosecond precision.
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700159 */
160 NATIVE_WINDOW_LAST_QUEUE_DURATION = 15,
161
162 /*
163 * Returns the number of image layers that the ANativeWindow buffer
164 * contains. By default this is 1, unless a buffer is explicitly allocated
165 * to contain multiple layers.
166 */
167 NATIVE_WINDOW_LAYER_COUNT = 16,
168
169 /*
170 * Returns 1 if the native window is valid, 0 otherwise. native window is valid
171 * if it is safe (i.e. no crash will occur) to call any method on it.
172 */
173 NATIVE_WINDOW_IS_VALID = 17,
Brian Anderson6b376712017-04-04 10:51:39 -0700174
175 /*
176 * Returns 1 if NATIVE_WINDOW_GET_FRAME_TIMESTAMPS will return display
177 * present info, 0 if it won't.
178 */
179 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18,
Jiwen 'Steve' Cai20419132017-04-21 18:49:53 -0700180
181 /*
182 * The consumer end is capable of handling protected buffers, i.e. buffer
183 * with GRALLOC_USAGE_PROTECTED usage bits on.
184 */
185 NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19,
Peiyong Lin654f87b2018-01-30 14:21:33 -0800186
187 /*
188 * Returns data space for the buffers.
189 */
190 NATIVE_WINDOW_DATASPACE = 20,
Yiwei Zhangdbd96152018-02-08 14:22:53 -0800191
192 /*
193 * Returns maxBufferCount set by BufferQueueConsumer
194 */
195 NATIVE_WINDOW_MAX_BUFFER_COUNT = 21,
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700196};
197
198/* Valid operations for the (*perform)() hook.
199 *
200 * Values marked as 'deprecated' are supported, but have been superceded by
201 * other functionality.
202 *
203 * Values marked as 'private' should be considered private to the framework.
204 * HAL implementation code with access to an ANativeWindow should not use these,
205 * as it may not interact properly with the framework's use of the
206 * ANativeWindow.
207 */
208enum {
Valerie Haua82679d2018-11-21 09:31:43 -0800209 // clang-format off
Alec Mouri09d122a2019-11-25 10:00:53 -0800210 NATIVE_WINDOW_SET_USAGE = ANATIVEWINDOW_PERFORM_SET_USAGE, /* deprecated */
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700211 NATIVE_WINDOW_CONNECT = 1, /* deprecated */
212 NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */
213 NATIVE_WINDOW_SET_CROP = 3, /* private */
214 NATIVE_WINDOW_SET_BUFFER_COUNT = 4,
Alec Mouri09d122a2019-11-25 10:00:53 -0800215 NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = ANATIVEWINDOW_PERFORM_SET_BUFFERS_GEOMETRY, /* deprecated */
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700216 NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6,
217 NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7,
218 NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8,
Alec Mouri09d122a2019-11-25 10:00:53 -0800219 NATIVE_WINDOW_SET_BUFFERS_FORMAT = ANATIVEWINDOW_PERFORM_SET_BUFFERS_FORMAT,
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700220 NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */
221 NATIVE_WINDOW_LOCK = 11, /* private */
222 NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */
223 NATIVE_WINDOW_API_CONNECT = 13, /* private */
224 NATIVE_WINDOW_API_DISCONNECT = 14, /* private */
225 NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */
226 NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* deprecated, unimplemented */
227 NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17, /* private */
228 NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18,
229 NATIVE_WINDOW_SET_BUFFERS_DATASPACE = 19,
230 NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */
231 NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21,
232 NATIVE_WINDOW_SET_AUTO_REFRESH = 22,
233 NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION = 23,
234 NATIVE_WINDOW_GET_NEXT_FRAME_ID = 24,
235 NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS = 25,
236 NATIVE_WINDOW_GET_COMPOSITOR_TIMING = 26,
237 NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 27,
238 NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT = 28,
239 NATIVE_WINDOW_GET_HDR_SUPPORT = 29,
Alec Mouri09d122a2019-11-25 10:00:53 -0800240 NATIVE_WINDOW_SET_USAGE64 = ANATIVEWINDOW_PERFORM_SET_USAGE64,
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700241 NATIVE_WINDOW_GET_CONSUMER_USAGE64 = 31,
242 NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA = 32,
243 NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA = 33,
Valerie Haua82679d2018-11-21 09:31:43 -0800244 NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA = 34,
Yiwei Zhang538cedc2019-06-24 19:35:03 -0700245 NATIVE_WINDOW_SET_AUTO_PREROTATION = 35,
Alec Mouria1619662019-08-21 19:30:48 -0700246 NATIVE_WINDOW_GET_LAST_DEQUEUE_START = 36, /* private */
Alec Mouri04fdb602019-08-23 19:41:43 -0700247 NATIVE_WINDOW_SET_DEQUEUE_TIMEOUT = 37, /* private */
Alec Mouri72670c52019-08-31 01:54:33 -0700248 NATIVE_WINDOW_GET_LAST_DEQUEUE_DURATION = 38, /* private */
249 NATIVE_WINDOW_GET_LAST_QUEUE_DURATION = 39, /* private */
Steven Thomas3172e202020-01-06 19:25:30 -0800250 NATIVE_WINDOW_SET_FRAME_RATE = 40,
Alec Mouri09d122a2019-11-25 10:00:53 -0800251 NATIVE_WINDOW_SET_CANCEL_INTERCEPTOR = 41, /* private */
252 NATIVE_WINDOW_SET_DEQUEUE_INTERCEPTOR = 42, /* private */
253 NATIVE_WINDOW_SET_PERFORM_INTERCEPTOR = 43, /* private */
254 NATIVE_WINDOW_SET_QUEUE_INTERCEPTOR = 44, /* private */
Valerie Haua82679d2018-11-21 09:31:43 -0800255 // clang-format on
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700256};
257
258/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
259enum {
260 /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
261 * OpenGL ES.
262 */
263 NATIVE_WINDOW_API_EGL = 1,
264
265 /* Buffers will be queued after being filled using the CPU
266 */
267 NATIVE_WINDOW_API_CPU = 2,
268
269 /* Buffers will be queued by Stagefright after being filled by a video
270 * decoder. The video decoder can either be a software or hardware decoder.
271 */
272 NATIVE_WINDOW_API_MEDIA = 3,
273
274 /* Buffers will be queued by the the camera HAL.
275 */
276 NATIVE_WINDOW_API_CAMERA = 4,
277};
278
279/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
280enum {
281 /* flip source image horizontally */
282 NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
283 /* flip source image vertically */
284 NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
285 /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
286 NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
287 /* rotate source image 180 degrees */
288 NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
289 /* rotate source image 270 degrees clock-wise */
290 NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
291 /* transforms source by the inverse transform of the screen it is displayed onto. This
292 * transform is applied last */
293 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
294};
295
296/* parameter for NATIVE_WINDOW_SET_SCALING_MODE
297 * keep in sync with Surface.java in frameworks/base */
298enum {
299 /* the window content is not updated (frozen) until a buffer of
300 * the window size is received (enqueued)
301 */
302 NATIVE_WINDOW_SCALING_MODE_FREEZE = 0,
303 /* the buffer is scaled in both dimensions to match the window size */
304 NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1,
305 /* the buffer is scaled uniformly such that the smaller dimension
306 * of the buffer matches the window size (cropping in the process)
307 */
308 NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2,
309 /* the window is clipped to the size of the buffer's crop rectangle; pixels
310 * outside the crop rectangle are treated as if they are completely
311 * transparent.
312 */
313 NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3,
314};
315
316/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
317enum {
318 NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
319 NATIVE_WINDOW_SURFACE = 1, /* Surface */
320};
321
322/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
323 *
324 * Special timestamp value to indicate that timestamps should be auto-generated
325 * by the native window when queueBuffer is called. This is equal to INT64_MIN,
326 * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
327 */
328static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
329
Brian Andersondc96fdf2017-03-20 16:54:25 -0700330/* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS
331 *
332 * Special timestamp value to indicate the timestamps aren't yet known or
333 * that they are invalid.
334 */
335static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2;
336static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1;
337
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700338struct ANativeWindow
339{
340#ifdef __cplusplus
341 ANativeWindow()
342 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
343 {
344 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
345 common.version = sizeof(ANativeWindow);
346 memset(common.reserved, 0, sizeof(common.reserved));
347 }
348
349 /* Implement the methods that sp<ANativeWindow> expects so that it
350 can be used to automatically refcount ANativeWindow's. */
351 void incStrong(const void* /*id*/) const {
352 common.incRef(const_cast<android_native_base_t*>(&common));
353 }
354 void decStrong(const void* /*id*/) const {
355 common.decRef(const_cast<android_native_base_t*>(&common));
356 }
357#endif
358
359 struct android_native_base_t common;
360
361 /* flags describing some attributes of this surface or its updater */
362 const uint32_t flags;
363
364 /* min swap interval supported by this updated */
365 const int minSwapInterval;
366
367 /* max swap interval supported by this updated */
368 const int maxSwapInterval;
369
370 /* horizontal and vertical resolution in DPI */
371 const float xdpi;
372 const float ydpi;
373
374 /* Some storage reserved for the OEM's driver. */
375 intptr_t oem[4];
376
377 /*
378 * Set the swap interval for this surface.
379 *
380 * Returns 0 on success or -errno on error.
381 */
382 int (*setSwapInterval)(struct ANativeWindow* window,
383 int interval);
384
385 /*
386 * Hook called by EGL to acquire a buffer. After this call, the buffer
387 * is not locked, so its content cannot be modified. This call may block if
388 * no buffers are available.
389 *
390 * The window holds a reference to the buffer between dequeueBuffer and
391 * either queueBuffer or cancelBuffer, so clients only need their own
392 * reference if they might use the buffer after queueing or canceling it.
393 * Holding a reference to a buffer after queueing or canceling it is only
394 * allowed if a specific buffer count has been set.
395 *
396 * Returns 0 on success or -errno on error.
397 *
398 * XXX: This function is deprecated. It will continue to work for some
399 * time for binary compatibility, but the new dequeueBuffer function that
400 * outputs a fence file descriptor should be used in its place.
401 */
402 int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
403 struct ANativeWindowBuffer** buffer);
404
405 /*
406 * hook called by EGL to lock a buffer. This MUST be called before modifying
407 * the content of a buffer. The buffer must have been acquired with
408 * dequeueBuffer first.
409 *
410 * Returns 0 on success or -errno on error.
411 *
412 * XXX: This function is deprecated. It will continue to work for some
413 * time for binary compatibility, but it is essentially a no-op, and calls
414 * to it should be removed.
415 */
416 int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
417 struct ANativeWindowBuffer* buffer);
418
419 /*
420 * Hook called by EGL when modifications to the render buffer are done.
421 * This unlocks and post the buffer.
422 *
423 * The window holds a reference to the buffer between dequeueBuffer and
424 * either queueBuffer or cancelBuffer, so clients only need their own
425 * reference if they might use the buffer after queueing or canceling it.
426 * Holding a reference to a buffer after queueing or canceling it is only
427 * allowed if a specific buffer count has been set.
428 *
429 * Buffers MUST be queued in the same order than they were dequeued.
430 *
431 * Returns 0 on success or -errno on error.
432 *
433 * XXX: This function is deprecated. It will continue to work for some
434 * time for binary compatibility, but the new queueBuffer function that
435 * takes a fence file descriptor should be used in its place (pass a value
436 * of -1 for the fence file descriptor if there is no valid one to pass).
437 */
438 int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
439 struct ANativeWindowBuffer* buffer);
440
441 /*
442 * hook used to retrieve information about the native window.
443 *
444 * Returns 0 on success or -errno on error.
445 */
446 int (*query)(const struct ANativeWindow* window,
447 int what, int* value);
448
449 /*
450 * hook used to perform various operations on the surface.
451 * (*perform)() is a generic mechanism to add functionality to
452 * ANativeWindow while keeping backward binary compatibility.
453 *
454 * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
455 * defined below.
456 *
457 * (*perform)() returns -ENOENT if the 'what' parameter is not supported
458 * by the surface's implementation.
459 *
460 * See above for a list of valid operations, such as
461 * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
462 */
463 int (*perform)(struct ANativeWindow* window,
464 int operation, ... );
465
466 /*
467 * Hook used to cancel a buffer that has been dequeued.
468 * No synchronization is performed between dequeue() and cancel(), so
469 * either external synchronization is needed, or these functions must be
470 * called from the same thread.
471 *
472 * The window holds a reference to the buffer between dequeueBuffer and
473 * either queueBuffer or cancelBuffer, so clients only need their own
474 * reference if they might use the buffer after queueing or canceling it.
475 * Holding a reference to a buffer after queueing or canceling it is only
476 * allowed if a specific buffer count has been set.
477 *
478 * XXX: This function is deprecated. It will continue to work for some
479 * time for binary compatibility, but the new cancelBuffer function that
480 * takes a fence file descriptor should be used in its place (pass a value
481 * of -1 for the fence file descriptor if there is no valid one to pass).
482 */
483 int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
484 struct ANativeWindowBuffer* buffer);
485
486 /*
487 * Hook called by EGL to acquire a buffer. This call may block if no
488 * buffers are available.
489 *
490 * The window holds a reference to the buffer between dequeueBuffer and
491 * either queueBuffer or cancelBuffer, so clients only need their own
492 * reference if they might use the buffer after queueing or canceling it.
493 * Holding a reference to a buffer after queueing or canceling it is only
494 * allowed if a specific buffer count has been set.
495 *
496 * The libsync fence file descriptor returned in the int pointed to by the
497 * fenceFd argument will refer to the fence that must signal before the
498 * dequeued buffer may be written to. A value of -1 indicates that the
499 * caller may access the buffer immediately without waiting on a fence. If
500 * a valid file descriptor is returned (i.e. any value except -1) then the
501 * caller is responsible for closing the file descriptor.
502 *
503 * Returns 0 on success or -errno on error.
504 */
505 int (*dequeueBuffer)(struct ANativeWindow* window,
506 struct ANativeWindowBuffer** buffer, int* fenceFd);
507
508 /*
509 * Hook called by EGL when modifications to the render buffer are done.
510 * This unlocks and post the buffer.
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 fenceFd argument specifies a libsync fence file descriptor for a
519 * fence that must signal before the buffer can be accessed. If the buffer
520 * can be accessed immediately then a value of -1 should be used. The
521 * caller must not use the file descriptor after it is passed to
522 * queueBuffer, and the ANativeWindow implementation is responsible for
523 * closing it.
524 *
525 * Returns 0 on success or -errno on error.
526 */
527 int (*queueBuffer)(struct ANativeWindow* window,
528 struct ANativeWindowBuffer* buffer, int fenceFd);
529
530 /*
531 * Hook used to cancel a buffer that has been dequeued.
532 * No synchronization is performed between dequeue() and cancel(), so
533 * either external synchronization is needed, or these functions must be
534 * called from the same thread.
535 *
536 * The window holds a reference to the buffer between dequeueBuffer and
537 * either queueBuffer or cancelBuffer, so clients only need their own
538 * reference if they might use the buffer after queueing or canceling it.
539 * Holding a reference to a buffer after queueing or canceling it is only
540 * allowed if a specific buffer count has been set.
541 *
542 * The fenceFd argument specifies a libsync fence file decsriptor for a
543 * fence that must signal before the buffer can be accessed. If the buffer
544 * can be accessed immediately then a value of -1 should be used.
545 *
546 * Note that if the client has not waited on the fence that was returned
547 * from dequeueBuffer, that same fence should be passed to cancelBuffer to
548 * ensure that future uses of the buffer are preceded by a wait on that
549 * fence. The caller must not use the file descriptor after it is passed
550 * to cancelBuffer, and the ANativeWindow implementation is responsible for
551 * closing it.
552 *
553 * Returns 0 on success or -errno on error.
554 */
555 int (*cancelBuffer)(struct ANativeWindow* window,
556 struct ANativeWindowBuffer* buffer, int fenceFd);
557};
558
559 /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
560 * android_native_window_t is deprecated.
561 */
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700562typedef struct ANativeWindow android_native_window_t __deprecated;
563
564/*
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700565 * native_window_set_usage64(..., usage)
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700566 * Sets the intended usage flags for the next buffers
567 * acquired with (*lockBuffer)() and on.
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700568 *
569 * Valid usage flags are defined in android/hardware_buffer.h
570 * All AHARDWAREBUFFER_USAGE_* flags can be specified as needed.
571 *
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700572 * Calling this function will usually cause following buffers to be
573 * reallocated.
574 */
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700575static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) {
576 return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700577}
578
579/* deprecated. Always returns 0. Don't call. */
580static inline int native_window_connect(
581 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
582
583static inline int native_window_connect(
584 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
585 return 0;
586}
587
588/* deprecated. Always returns 0. Don't call. */
589static inline int native_window_disconnect(
590 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
591
592static inline int native_window_disconnect(
593 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
594 return 0;
595}
596
597/*
598 * native_window_set_crop(..., crop)
599 * Sets which region of the next queued buffers needs to be considered.
600 * Depending on the scaling mode, a buffer's crop region is scaled and/or
601 * cropped to match the surface's size. This function sets the crop in
602 * pre-transformed buffer pixel coordinates.
603 *
604 * The specified crop region applies to all buffers queued after it is called.
605 *
606 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
607 *
608 * An error is returned if for instance the crop region is invalid, out of the
609 * buffer's bound or if the window is invalid.
610 */
611static inline int native_window_set_crop(
612 struct ANativeWindow* window,
613 android_native_rect_t const * crop)
614{
615 return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
616}
617
618/*
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700619 * native_window_set_buffer_count(..., count)
620 * Sets the number of buffers associated with this native window.
621 */
622static inline int native_window_set_buffer_count(
623 struct ANativeWindow* window,
624 size_t bufferCount)
625{
626 return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
627}
628
629/*
630 * native_window_set_buffers_geometry(..., int w, int h, int format)
631 * All buffers dequeued after this call will have the dimensions and format
632 * specified. A successful call to this function has the same effect as calling
633 * native_window_set_buffers_size and native_window_set_buffers_format.
634 *
635 * XXX: This function is deprecated. The native_window_set_buffers_dimensions
636 * and native_window_set_buffers_format functions should be used instead.
637 */
638static inline int native_window_set_buffers_geometry(
639 struct ANativeWindow* window,
640 int w, int h, int format) __deprecated;
641
642static inline int native_window_set_buffers_geometry(
643 struct ANativeWindow* window,
644 int w, int h, int format)
645{
646 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
647 w, h, format);
648}
649
650/*
651 * native_window_set_buffers_dimensions(..., int w, int h)
652 * All buffers dequeued after this call will have the dimensions specified.
653 * In particular, all buffers will have a fixed-size, independent from the
654 * native-window size. They will be scaled according to the scaling mode
655 * (see native_window_set_scaling_mode) upon window composition.
656 *
657 * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
658 * following this call will be sized to match the window's size.
659 *
660 * Calling this function will reset the window crop to a NULL value, which
661 * disables cropping of the buffers.
662 */
663static inline int native_window_set_buffers_dimensions(
664 struct ANativeWindow* window,
665 int w, int h)
666{
667 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
668 w, h);
669}
670
671/*
672 * native_window_set_buffers_user_dimensions(..., int w, int h)
673 *
674 * Sets the user buffer size for the window, which overrides the
675 * window's size. All buffers dequeued after this call will have the
676 * dimensions specified unless overridden by
677 * native_window_set_buffers_dimensions. All buffers will have a
678 * fixed-size, independent from the native-window size. They will be
679 * scaled according to the scaling mode (see
680 * native_window_set_scaling_mode) upon window composition.
681 *
682 * If w and h are 0, the normal behavior is restored. That is, the
683 * default buffer size will match the windows's size.
684 *
685 * Calling this function will reset the window crop to a NULL value, which
686 * disables cropping of the buffers.
687 */
688static inline int native_window_set_buffers_user_dimensions(
689 struct ANativeWindow* window,
690 int w, int h)
691{
692 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
693 w, h);
694}
695
696/*
697 * native_window_set_buffers_format(..., int format)
698 * All buffers dequeued after this call will have the format specified.
699 *
700 * If the specified format is 0, the default buffer format will be used.
701 */
702static inline int native_window_set_buffers_format(
703 struct ANativeWindow* window,
704 int format)
705{
706 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
707}
708
709/*
710 * native_window_set_buffers_data_space(..., int dataSpace)
711 * All buffers queued after this call will be associated with the dataSpace
712 * parameter specified.
713 *
714 * dataSpace specifies additional information about the buffer that's dependent
715 * on the buffer format and the endpoints. For example, it can be used to convey
716 * the color space of the image data in the buffer, or it can be used to
717 * indicate that the buffers contain depth measurement data instead of color
718 * images. The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
719 * overridden by the consumer.
720 */
721static inline int native_window_set_buffers_data_space(
722 struct ANativeWindow* window,
723 android_dataspace_t dataSpace)
724{
725 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
726 dataSpace);
727}
728
729/*
Courtney Goeltzenleuchter9bad0d72017-12-19 12:34:34 -0700730 * native_window_set_buffers_smpte2086_metadata(..., metadata)
731 * All buffers queued after this call will be associated with the SMPTE
732 * ST.2086 metadata specified.
733 *
734 * metadata specifies additional information about the contents of the buffer
735 * that may affect how it's displayed. When it is nullptr, it means no such
736 * information is available. No SMPTE ST.2086 metadata is associated with the
737 * buffers by default.
738 */
739static inline int native_window_set_buffers_smpte2086_metadata(
740 struct ANativeWindow* window,
741 const struct android_smpte2086_metadata* metadata)
742{
743 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA,
744 metadata);
745}
746
747/*
748 * native_window_set_buffers_cta861_3_metadata(..., metadata)
749 * All buffers queued after this call will be associated with the CTA-861.3
750 * metadata specified.
751 *
752 * metadata specifies additional information about the contents of the buffer
753 * that may affect how it's displayed. When it is nullptr, it means no such
754 * information is available. No CTA-861.3 metadata is associated with the
755 * buffers by default.
756 */
757static inline int native_window_set_buffers_cta861_3_metadata(
758 struct ANativeWindow* window,
759 const struct android_cta861_3_metadata* metadata)
760{
761 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA,
762 metadata);
763}
764
765/*
Valerie Haua82679d2018-11-21 09:31:43 -0800766 * native_window_set_buffers_hdr10_plus_metadata(..., metadata)
767 * All buffers queued after this call will be associated with the
768 * HDR10+ dynamic metadata specified.
769 *
770 * metadata specifies additional dynamic information about the
771 * contents of the buffer that may affect how it is displayed. When
772 * it is nullptr, it means no such information is available. No
773 * HDR10+ dynamic emtadata is associated with the buffers by default.
774 *
775 * Parameter "size" refers to the length of the metadata blob pointed to
776 * by parameter "data". The metadata blob will adhere to the HDR10+ SEI
777 * message standard.
778 */
779static inline int native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow* window,
780 const size_t size,
781 const uint8_t* metadata) {
782 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA, size,
783 metadata);
784}
785
786/*
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700787 * native_window_set_buffers_transform(..., int transform)
788 * All buffers queued after this call will be displayed transformed according
789 * to the transform parameter specified.
790 */
791static inline int native_window_set_buffers_transform(
792 struct ANativeWindow* window,
793 int transform)
794{
795 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
796 transform);
797}
798
799/*
800 * native_window_set_buffers_sticky_transform(..., int transform)
801 * All buffers queued after this call will be displayed transformed according
802 * to the transform parameter specified applied on top of the regular buffer
803 * transform. Setting this transform will disable the transform hint.
804 *
805 * Temporary - This is only intended to be used by the LEGACY camera mode, do
806 * not use this for anything else.
807 */
808static inline int native_window_set_buffers_sticky_transform(
809 struct ANativeWindow* window,
810 int transform)
811{
812 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
813 transform);
814}
815
816/*
817 * native_window_set_buffers_timestamp(..., int64_t timestamp)
818 * All buffers queued after this call will be associated with the timestamp
819 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
820 * (the default), timestamps will be generated automatically when queueBuffer is
821 * called. The timestamp is measured in nanoseconds, and is normally monotonically
822 * increasing. The timestamp should be unaffected by time-of-day adjustments,
823 * and for a camera should be strictly monotonic but for a media player may be
824 * reset when the position is set.
825 */
826static inline int native_window_set_buffers_timestamp(
827 struct ANativeWindow* window,
828 int64_t timestamp)
829{
830 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
831 timestamp);
832}
833
834/*
835 * native_window_set_scaling_mode(..., int mode)
836 * All buffers queued after this call will be associated with the scaling mode
837 * specified.
838 */
839static inline int native_window_set_scaling_mode(
840 struct ANativeWindow* window,
841 int mode)
842{
843 return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
844 mode);
845}
846
847/*
848 * native_window_api_connect(..., int api)
849 * connects an API to this window. only one API can be connected at a time.
850 * Returns -EINVAL if for some reason the window cannot be connected, which
851 * can happen if it's connected to some other API.
852 */
853static inline int native_window_api_connect(
854 struct ANativeWindow* window, int api)
855{
856 return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
857}
858
859/*
860 * native_window_api_disconnect(..., int api)
861 * disconnect the API from this window.
862 * An error is returned if for instance the window wasn't connected in the
863 * first place.
864 */
865static inline int native_window_api_disconnect(
866 struct ANativeWindow* window, int api)
867{
868 return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
869}
870
871/*
872 * native_window_dequeue_buffer_and_wait(...)
873 * Dequeue a buffer and wait on the fence associated with that buffer. The
874 * buffer may safely be accessed immediately upon this function returning. An
875 * error is returned if either of the dequeue or the wait operations fail.
876 */
877static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
878 struct ANativeWindowBuffer** anb) {
879 return anw->dequeueBuffer_DEPRECATED(anw, anb);
880}
881
882/*
883 * native_window_set_sideband_stream(..., native_handle_t*)
884 * Attach a sideband buffer stream to a native window.
885 */
886static inline int native_window_set_sideband_stream(
887 struct ANativeWindow* window,
888 native_handle_t* sidebandHandle)
889{
890 return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
891 sidebandHandle);
892}
893
894/*
895 * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
896 * Set the surface damage (i.e., the region of the surface that has changed
897 * since the previous frame). The damage set by this call will be reset (to the
898 * default of full-surface damage) after calling queue, so this must be called
899 * prior to every frame with damage that does not cover the whole surface if the
900 * caller desires downstream consumers to use this optimization.
901 *
902 * The damage region is specified as an array of rectangles, with the important
903 * caveat that the origin of the surface is considered to be the bottom-left
904 * corner, as in OpenGL ES.
905 *
906 * If numRects is set to 0, rects may be NULL, and the surface damage will be
907 * set to the full surface (the same as if this function had not been called for
908 * this frame).
909 */
910static inline int native_window_set_surface_damage(
911 struct ANativeWindow* window,
912 const android_native_rect_t* rects, size_t numRects)
913{
914 return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
915 rects, numRects);
916}
917
918/*
919 * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
920 * Enable/disable shared buffer mode
921 */
922static inline int native_window_set_shared_buffer_mode(
923 struct ANativeWindow* window,
924 bool sharedBufferMode)
925{
926 return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
927 sharedBufferMode);
928}
929
930/*
931 * native_window_set_auto_refresh(..., autoRefresh)
932 * Enable/disable auto refresh when in shared buffer mode
933 */
934static inline int native_window_set_auto_refresh(
935 struct ANativeWindow* window,
936 bool autoRefresh)
937{
938 return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
939}
940
941static inline int native_window_get_refresh_cycle_duration(
942 struct ANativeWindow* window,
943 int64_t* outRefreshDuration)
944{
945 return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION,
946 outRefreshDuration);
947}
948
949static inline int native_window_get_next_frame_id(
950 struct ANativeWindow* window, uint64_t* frameId)
951{
952 return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId);
953}
954
955static inline int native_window_enable_frame_timestamps(
956 struct ANativeWindow* window, bool enable)
957{
958 return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS,
959 enable);
960}
961
962static inline int native_window_get_compositor_timing(
963 struct ANativeWindow* window,
964 int64_t* compositeDeadline, int64_t* compositeInterval,
965 int64_t* compositeToPresentLatency)
966{
967 return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING,
968 compositeDeadline, compositeInterval, compositeToPresentLatency);
969}
970
971static inline int native_window_get_frame_timestamps(
972 struct ANativeWindow* window, uint64_t frameId,
973 int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
974 int64_t* outLatchTime, int64_t* outFirstRefreshStartTime,
975 int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime,
976 int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime,
977 int64_t* outReleaseTime)
978{
979 return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
980 frameId, outRequestedPresentTime, outAcquireTime, outLatchTime,
981 outFirstRefreshStartTime, outLastRefreshStartTime,
982 outGpuCompositionDoneTime, outDisplayPresentTime,
983 outDequeueReadyTime, outReleaseTime);
984}
985
986static inline int native_window_get_wide_color_support(
987 struct ANativeWindow* window, bool* outSupport) {
Chia-I Wue2786ea2017-08-07 10:36:08 -0700988 return window->perform(window, NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT,
989 outSupport);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700990}
991
992static inline int native_window_get_hdr_support(struct ANativeWindow* window,
993 bool* outSupport) {
Chia-I Wue2786ea2017-08-07 10:36:08 -0700994 return window->perform(window, NATIVE_WINDOW_GET_HDR_SUPPORT, outSupport);
995}
996
997static inline int native_window_get_consumer_usage(struct ANativeWindow* window,
998 uint64_t* outUsage) {
999 return window->perform(window, NATIVE_WINDOW_GET_CONSUMER_USAGE64, outUsage);
Mathias Agopiana6c0e202017-03-20 15:48:44 -07001000}
1001
Yiwei Zhang538cedc2019-06-24 19:35:03 -07001002/*
1003 * native_window_set_auto_prerotation(..., autoPrerotation)
1004 * Enable/disable the auto prerotation at buffer allocation when the buffer size
1005 * is driven by the consumer.
1006 *
1007 * When buffer size is driven by the consumer and the transform hint specifies
1008 * a 90 or 270 degree rotation, if auto prerotation is enabled, the width and
1009 * height used for dequeueBuffer will be additionally swapped.
1010 */
1011static inline int native_window_set_auto_prerotation(struct ANativeWindow* window,
1012 bool autoPrerotation) {
1013 return window->perform(window, NATIVE_WINDOW_SET_AUTO_PREROTATION, autoPrerotation);
1014}
1015
Steven Thomas3172e202020-01-06 19:25:30 -08001016static inline int native_window_set_frame_rate(struct ANativeWindow* window, float frameRate) {
1017 return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate);
1018}
1019
Mathias Agopiana6c0e202017-03-20 15:48:44 -07001020__END_DECLS