blob: 121374b1d5191723c6d22fc3f25da228e85385f7 [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 */
Alec Mouri74aef6d2019-12-09 17:10:24 -0800255 NATIVE_WINDOW_ALLOCATE_BUFFERS = 45, /* private */
Valerie Haua82679d2018-11-21 09:31:43 -0800256 // clang-format on
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700257};
258
259/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */
260enum {
261 /* Buffers will be queued by EGL via eglSwapBuffers after being filled using
262 * OpenGL ES.
263 */
264 NATIVE_WINDOW_API_EGL = 1,
265
266 /* Buffers will be queued after being filled using the CPU
267 */
268 NATIVE_WINDOW_API_CPU = 2,
269
270 /* Buffers will be queued by Stagefright after being filled by a video
271 * decoder. The video decoder can either be a software or hardware decoder.
272 */
273 NATIVE_WINDOW_API_MEDIA = 3,
274
275 /* Buffers will be queued by the the camera HAL.
276 */
277 NATIVE_WINDOW_API_CAMERA = 4,
278};
279
280/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */
281enum {
282 /* flip source image horizontally */
283 NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H ,
284 /* flip source image vertically */
285 NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
286 /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
287 NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
288 /* rotate source image 180 degrees */
289 NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
290 /* rotate source image 270 degrees clock-wise */
291 NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
292 /* transforms source by the inverse transform of the screen it is displayed onto. This
293 * transform is applied last */
294 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08
295};
296
297/* parameter for NATIVE_WINDOW_SET_SCALING_MODE
298 * keep in sync with Surface.java in frameworks/base */
299enum {
300 /* the window content is not updated (frozen) until a buffer of
301 * the window size is received (enqueued)
302 */
303 NATIVE_WINDOW_SCALING_MODE_FREEZE = 0,
304 /* the buffer is scaled in both dimensions to match the window size */
305 NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1,
306 /* the buffer is scaled uniformly such that the smaller dimension
307 * of the buffer matches the window size (cropping in the process)
308 */
309 NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2,
310 /* the window is clipped to the size of the buffer's crop rectangle; pixels
311 * outside the crop rectangle are treated as if they are completely
312 * transparent.
313 */
314 NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3,
315};
316
317/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */
318enum {
319 NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */
320 NATIVE_WINDOW_SURFACE = 1, /* Surface */
321};
322
323/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP
324 *
325 * Special timestamp value to indicate that timestamps should be auto-generated
326 * by the native window when queueBuffer is called. This is equal to INT64_MIN,
327 * defined directly to avoid problems with C99/C++ inclusion of stdint.h.
328 */
329static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1);
330
Brian Andersondc96fdf2017-03-20 16:54:25 -0700331/* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS
332 *
333 * Special timestamp value to indicate the timestamps aren't yet known or
334 * that they are invalid.
335 */
336static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2;
337static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1;
338
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700339struct ANativeWindow
340{
341#ifdef __cplusplus
342 ANativeWindow()
343 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0)
344 {
345 common.magic = ANDROID_NATIVE_WINDOW_MAGIC;
346 common.version = sizeof(ANativeWindow);
347 memset(common.reserved, 0, sizeof(common.reserved));
348 }
349
350 /* Implement the methods that sp<ANativeWindow> expects so that it
351 can be used to automatically refcount ANativeWindow's. */
352 void incStrong(const void* /*id*/) const {
353 common.incRef(const_cast<android_native_base_t*>(&common));
354 }
355 void decStrong(const void* /*id*/) const {
356 common.decRef(const_cast<android_native_base_t*>(&common));
357 }
358#endif
359
360 struct android_native_base_t common;
361
362 /* flags describing some attributes of this surface or its updater */
363 const uint32_t flags;
364
365 /* min swap interval supported by this updated */
366 const int minSwapInterval;
367
368 /* max swap interval supported by this updated */
369 const int maxSwapInterval;
370
371 /* horizontal and vertical resolution in DPI */
372 const float xdpi;
373 const float ydpi;
374
375 /* Some storage reserved for the OEM's driver. */
376 intptr_t oem[4];
377
378 /*
379 * Set the swap interval for this surface.
380 *
381 * Returns 0 on success or -errno on error.
382 */
383 int (*setSwapInterval)(struct ANativeWindow* window,
384 int interval);
385
386 /*
387 * Hook called by EGL to acquire a buffer. After this call, the buffer
388 * is not locked, so its content cannot be modified. This call may block if
389 * no buffers are available.
390 *
391 * The window holds a reference to the buffer between dequeueBuffer and
392 * either queueBuffer or cancelBuffer, so clients only need their own
393 * reference if they might use the buffer after queueing or canceling it.
394 * Holding a reference to a buffer after queueing or canceling it is only
395 * allowed if a specific buffer count has been set.
396 *
397 * Returns 0 on success or -errno on error.
398 *
399 * XXX: This function is deprecated. It will continue to work for some
400 * time for binary compatibility, but the new dequeueBuffer function that
401 * outputs a fence file descriptor should be used in its place.
402 */
403 int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window,
404 struct ANativeWindowBuffer** buffer);
405
406 /*
407 * hook called by EGL to lock a buffer. This MUST be called before modifying
408 * the content of a buffer. The buffer must have been acquired with
409 * dequeueBuffer first.
410 *
411 * Returns 0 on success or -errno on error.
412 *
413 * XXX: This function is deprecated. It will continue to work for some
414 * time for binary compatibility, but it is essentially a no-op, and calls
415 * to it should be removed.
416 */
417 int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window,
418 struct ANativeWindowBuffer* buffer);
419
420 /*
421 * Hook called by EGL when modifications to the render buffer are done.
422 * This unlocks and post the buffer.
423 *
424 * The window holds a reference to the buffer between dequeueBuffer and
425 * either queueBuffer or cancelBuffer, so clients only need their own
426 * reference if they might use the buffer after queueing or canceling it.
427 * Holding a reference to a buffer after queueing or canceling it is only
428 * allowed if a specific buffer count has been set.
429 *
430 * Buffers MUST be queued in the same order than they were dequeued.
431 *
432 * Returns 0 on success or -errno on error.
433 *
434 * XXX: This function is deprecated. It will continue to work for some
435 * time for binary compatibility, but the new queueBuffer function that
436 * takes a fence file descriptor should be used in its place (pass a value
437 * of -1 for the fence file descriptor if there is no valid one to pass).
438 */
439 int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window,
440 struct ANativeWindowBuffer* buffer);
441
442 /*
443 * hook used to retrieve information about the native window.
444 *
445 * Returns 0 on success or -errno on error.
446 */
447 int (*query)(const struct ANativeWindow* window,
448 int what, int* value);
449
450 /*
451 * hook used to perform various operations on the surface.
452 * (*perform)() is a generic mechanism to add functionality to
453 * ANativeWindow while keeping backward binary compatibility.
454 *
455 * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions
456 * defined below.
457 *
458 * (*perform)() returns -ENOENT if the 'what' parameter is not supported
459 * by the surface's implementation.
460 *
461 * See above for a list of valid operations, such as
462 * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT
463 */
464 int (*perform)(struct ANativeWindow* window,
465 int operation, ... );
466
467 /*
468 * Hook used to cancel a buffer that has been dequeued.
469 * No synchronization is performed between dequeue() and cancel(), so
470 * either external synchronization is needed, or these functions must be
471 * called from the same thread.
472 *
473 * The window holds a reference to the buffer between dequeueBuffer and
474 * either queueBuffer or cancelBuffer, so clients only need their own
475 * reference if they might use the buffer after queueing or canceling it.
476 * Holding a reference to a buffer after queueing or canceling it is only
477 * allowed if a specific buffer count has been set.
478 *
479 * XXX: This function is deprecated. It will continue to work for some
480 * time for binary compatibility, but the new cancelBuffer function that
481 * takes a fence file descriptor should be used in its place (pass a value
482 * of -1 for the fence file descriptor if there is no valid one to pass).
483 */
484 int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window,
485 struct ANativeWindowBuffer* buffer);
486
487 /*
488 * Hook called by EGL to acquire a buffer. This call may block if no
489 * buffers are available.
490 *
491 * The window holds a reference to the buffer between dequeueBuffer and
492 * either queueBuffer or cancelBuffer, so clients only need their own
493 * reference if they might use the buffer after queueing or canceling it.
494 * Holding a reference to a buffer after queueing or canceling it is only
495 * allowed if a specific buffer count has been set.
496 *
497 * The libsync fence file descriptor returned in the int pointed to by the
498 * fenceFd argument will refer to the fence that must signal before the
499 * dequeued buffer may be written to. A value of -1 indicates that the
500 * caller may access the buffer immediately without waiting on a fence. If
501 * a valid file descriptor is returned (i.e. any value except -1) then the
502 * caller is responsible for closing the file descriptor.
503 *
504 * Returns 0 on success or -errno on error.
505 */
506 int (*dequeueBuffer)(struct ANativeWindow* window,
507 struct ANativeWindowBuffer** buffer, int* fenceFd);
508
509 /*
510 * Hook called by EGL when modifications to the render buffer are done.
511 * This unlocks and post the buffer.
512 *
513 * The window holds a reference to the buffer between dequeueBuffer and
514 * either queueBuffer or cancelBuffer, so clients only need their own
515 * reference if they might use the buffer after queueing or canceling it.
516 * Holding a reference to a buffer after queueing or canceling it is only
517 * allowed if a specific buffer count has been set.
518 *
519 * The fenceFd argument specifies a libsync fence file descriptor for a
520 * fence that must signal before the buffer can be accessed. If the buffer
521 * can be accessed immediately then a value of -1 should be used. The
522 * caller must not use the file descriptor after it is passed to
523 * queueBuffer, and the ANativeWindow implementation is responsible for
524 * closing it.
525 *
526 * Returns 0 on success or -errno on error.
527 */
528 int (*queueBuffer)(struct ANativeWindow* window,
529 struct ANativeWindowBuffer* buffer, int fenceFd);
530
531 /*
532 * Hook used to cancel a buffer that has been dequeued.
533 * No synchronization is performed between dequeue() and cancel(), so
534 * either external synchronization is needed, or these functions must be
535 * called from the same thread.
536 *
537 * The window holds a reference to the buffer between dequeueBuffer and
538 * either queueBuffer or cancelBuffer, so clients only need their own
539 * reference if they might use the buffer after queueing or canceling it.
540 * Holding a reference to a buffer after queueing or canceling it is only
541 * allowed if a specific buffer count has been set.
542 *
543 * The fenceFd argument specifies a libsync fence file decsriptor for a
544 * fence that must signal before the buffer can be accessed. If the buffer
545 * can be accessed immediately then a value of -1 should be used.
546 *
547 * Note that if the client has not waited on the fence that was returned
548 * from dequeueBuffer, that same fence should be passed to cancelBuffer to
549 * ensure that future uses of the buffer are preceded by a wait on that
550 * fence. The caller must not use the file descriptor after it is passed
551 * to cancelBuffer, and the ANativeWindow implementation is responsible for
552 * closing it.
553 *
554 * Returns 0 on success or -errno on error.
555 */
556 int (*cancelBuffer)(struct ANativeWindow* window,
557 struct ANativeWindowBuffer* buffer, int fenceFd);
558};
559
560 /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C).
561 * android_native_window_t is deprecated.
562 */
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700563typedef struct ANativeWindow android_native_window_t __deprecated;
564
565/*
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700566 * native_window_set_usage64(..., usage)
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700567 * Sets the intended usage flags for the next buffers
568 * acquired with (*lockBuffer)() and on.
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700569 *
570 * Valid usage flags are defined in android/hardware_buffer.h
571 * All AHARDWAREBUFFER_USAGE_* flags can be specified as needed.
572 *
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700573 * Calling this function will usually cause following buffers to be
574 * reallocated.
575 */
Mathias Agopiancb496ac2017-05-22 14:21:00 -0700576static inline int native_window_set_usage(struct ANativeWindow* window, uint64_t usage) {
577 return window->perform(window, NATIVE_WINDOW_SET_USAGE64, usage);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700578}
579
580/* deprecated. Always returns 0. Don't call. */
581static inline int native_window_connect(
582 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
583
584static inline int native_window_connect(
585 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
586 return 0;
587}
588
589/* deprecated. Always returns 0. Don't call. */
590static inline int native_window_disconnect(
591 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated;
592
593static inline int native_window_disconnect(
594 struct ANativeWindow* window __UNUSED, int api __UNUSED) {
595 return 0;
596}
597
598/*
599 * native_window_set_crop(..., crop)
600 * Sets which region of the next queued buffers needs to be considered.
601 * Depending on the scaling mode, a buffer's crop region is scaled and/or
602 * cropped to match the surface's size. This function sets the crop in
603 * pre-transformed buffer pixel coordinates.
604 *
605 * The specified crop region applies to all buffers queued after it is called.
606 *
607 * If 'crop' is NULL, subsequently queued buffers won't be cropped.
608 *
609 * An error is returned if for instance the crop region is invalid, out of the
610 * buffer's bound or if the window is invalid.
611 */
612static inline int native_window_set_crop(
613 struct ANativeWindow* window,
614 android_native_rect_t const * crop)
615{
616 return window->perform(window, NATIVE_WINDOW_SET_CROP, crop);
617}
618
619/*
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700620 * native_window_set_buffer_count(..., count)
621 * Sets the number of buffers associated with this native window.
622 */
623static inline int native_window_set_buffer_count(
624 struct ANativeWindow* window,
625 size_t bufferCount)
626{
627 return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount);
628}
629
630/*
631 * native_window_set_buffers_geometry(..., int w, int h, int format)
632 * All buffers dequeued after this call will have the dimensions and format
633 * specified. A successful call to this function has the same effect as calling
634 * native_window_set_buffers_size and native_window_set_buffers_format.
635 *
636 * XXX: This function is deprecated. The native_window_set_buffers_dimensions
637 * and native_window_set_buffers_format functions should be used instead.
638 */
639static inline int native_window_set_buffers_geometry(
640 struct ANativeWindow* window,
641 int w, int h, int format) __deprecated;
642
643static inline int native_window_set_buffers_geometry(
644 struct ANativeWindow* window,
645 int w, int h, int format)
646{
647 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY,
648 w, h, format);
649}
650
651/*
652 * native_window_set_buffers_dimensions(..., int w, int h)
653 * All buffers dequeued after this call will have the dimensions specified.
654 * In particular, all buffers will have a fixed-size, independent from the
655 * native-window size. They will be scaled according to the scaling mode
656 * (see native_window_set_scaling_mode) upon window composition.
657 *
658 * If w and h are 0, the normal behavior is restored. That is, dequeued buffers
659 * following this call will be sized to match the window's size.
660 *
661 * Calling this function will reset the window crop to a NULL value, which
662 * disables cropping of the buffers.
663 */
664static inline int native_window_set_buffers_dimensions(
665 struct ANativeWindow* window,
666 int w, int h)
667{
668 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS,
669 w, h);
670}
671
672/*
673 * native_window_set_buffers_user_dimensions(..., int w, int h)
674 *
675 * Sets the user buffer size for the window, which overrides the
676 * window's size. All buffers dequeued after this call will have the
677 * dimensions specified unless overridden by
678 * native_window_set_buffers_dimensions. All buffers will have a
679 * fixed-size, independent from the native-window size. They will be
680 * scaled according to the scaling mode (see
681 * native_window_set_scaling_mode) upon window composition.
682 *
683 * If w and h are 0, the normal behavior is restored. That is, the
684 * default buffer size will match the windows's size.
685 *
686 * Calling this function will reset the window crop to a NULL value, which
687 * disables cropping of the buffers.
688 */
689static inline int native_window_set_buffers_user_dimensions(
690 struct ANativeWindow* window,
691 int w, int h)
692{
693 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS,
694 w, h);
695}
696
697/*
698 * native_window_set_buffers_format(..., int format)
699 * All buffers dequeued after this call will have the format specified.
700 *
701 * If the specified format is 0, the default buffer format will be used.
702 */
703static inline int native_window_set_buffers_format(
704 struct ANativeWindow* window,
705 int format)
706{
707 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format);
708}
709
710/*
711 * native_window_set_buffers_data_space(..., int dataSpace)
712 * All buffers queued after this call will be associated with the dataSpace
713 * parameter specified.
714 *
715 * dataSpace specifies additional information about the buffer that's dependent
716 * on the buffer format and the endpoints. For example, it can be used to convey
717 * the color space of the image data in the buffer, or it can be used to
718 * indicate that the buffers contain depth measurement data instead of color
719 * images. The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been
720 * overridden by the consumer.
721 */
722static inline int native_window_set_buffers_data_space(
723 struct ANativeWindow* window,
724 android_dataspace_t dataSpace)
725{
726 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE,
727 dataSpace);
728}
729
730/*
Courtney Goeltzenleuchter9bad0d72017-12-19 12:34:34 -0700731 * native_window_set_buffers_smpte2086_metadata(..., metadata)
732 * All buffers queued after this call will be associated with the SMPTE
733 * ST.2086 metadata specified.
734 *
735 * metadata specifies additional information about the contents of the buffer
736 * that may affect how it's displayed. When it is nullptr, it means no such
737 * information is available. No SMPTE ST.2086 metadata is associated with the
738 * buffers by default.
739 */
740static inline int native_window_set_buffers_smpte2086_metadata(
741 struct ANativeWindow* window,
742 const struct android_smpte2086_metadata* metadata)
743{
744 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_SMPTE2086_METADATA,
745 metadata);
746}
747
748/*
749 * native_window_set_buffers_cta861_3_metadata(..., metadata)
750 * All buffers queued after this call will be associated with the CTA-861.3
751 * metadata specified.
752 *
753 * metadata specifies additional information about the contents of the buffer
754 * that may affect how it's displayed. When it is nullptr, it means no such
755 * information is available. No CTA-861.3 metadata is associated with the
756 * buffers by default.
757 */
758static inline int native_window_set_buffers_cta861_3_metadata(
759 struct ANativeWindow* window,
760 const struct android_cta861_3_metadata* metadata)
761{
762 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_CTA861_3_METADATA,
763 metadata);
764}
765
766/*
Valerie Haua82679d2018-11-21 09:31:43 -0800767 * native_window_set_buffers_hdr10_plus_metadata(..., metadata)
768 * All buffers queued after this call will be associated with the
769 * HDR10+ dynamic metadata specified.
770 *
771 * metadata specifies additional dynamic information about the
772 * contents of the buffer that may affect how it is displayed. When
773 * it is nullptr, it means no such information is available. No
774 * HDR10+ dynamic emtadata is associated with the buffers by default.
775 *
776 * Parameter "size" refers to the length of the metadata blob pointed to
777 * by parameter "data". The metadata blob will adhere to the HDR10+ SEI
778 * message standard.
779 */
780static inline int native_window_set_buffers_hdr10_plus_metadata(struct ANativeWindow* window,
781 const size_t size,
782 const uint8_t* metadata) {
783 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_HDR10_PLUS_METADATA, size,
784 metadata);
785}
786
787/*
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700788 * native_window_set_buffers_transform(..., int transform)
789 * All buffers queued after this call will be displayed transformed according
790 * to the transform parameter specified.
791 */
792static inline int native_window_set_buffers_transform(
793 struct ANativeWindow* window,
794 int transform)
795{
796 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM,
797 transform);
798}
799
800/*
801 * native_window_set_buffers_sticky_transform(..., int transform)
802 * All buffers queued after this call will be displayed transformed according
803 * to the transform parameter specified applied on top of the regular buffer
804 * transform. Setting this transform will disable the transform hint.
805 *
806 * Temporary - This is only intended to be used by the LEGACY camera mode, do
807 * not use this for anything else.
808 */
809static inline int native_window_set_buffers_sticky_transform(
810 struct ANativeWindow* window,
811 int transform)
812{
813 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM,
814 transform);
815}
816
817/*
818 * native_window_set_buffers_timestamp(..., int64_t timestamp)
819 * All buffers queued after this call will be associated with the timestamp
820 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO
821 * (the default), timestamps will be generated automatically when queueBuffer is
822 * called. The timestamp is measured in nanoseconds, and is normally monotonically
823 * increasing. The timestamp should be unaffected by time-of-day adjustments,
824 * and for a camera should be strictly monotonic but for a media player may be
825 * reset when the position is set.
826 */
827static inline int native_window_set_buffers_timestamp(
828 struct ANativeWindow* window,
829 int64_t timestamp)
830{
831 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP,
832 timestamp);
833}
834
835/*
836 * native_window_set_scaling_mode(..., int mode)
837 * All buffers queued after this call will be associated with the scaling mode
838 * specified.
839 */
840static inline int native_window_set_scaling_mode(
841 struct ANativeWindow* window,
842 int mode)
843{
844 return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE,
845 mode);
846}
847
848/*
849 * native_window_api_connect(..., int api)
850 * connects an API to this window. only one API can be connected at a time.
851 * Returns -EINVAL if for some reason the window cannot be connected, which
852 * can happen if it's connected to some other API.
853 */
854static inline int native_window_api_connect(
855 struct ANativeWindow* window, int api)
856{
857 return window->perform(window, NATIVE_WINDOW_API_CONNECT, api);
858}
859
860/*
861 * native_window_api_disconnect(..., int api)
862 * disconnect the API from this window.
863 * An error is returned if for instance the window wasn't connected in the
864 * first place.
865 */
866static inline int native_window_api_disconnect(
867 struct ANativeWindow* window, int api)
868{
869 return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api);
870}
871
872/*
873 * native_window_dequeue_buffer_and_wait(...)
874 * Dequeue a buffer and wait on the fence associated with that buffer. The
875 * buffer may safely be accessed immediately upon this function returning. An
876 * error is returned if either of the dequeue or the wait operations fail.
877 */
878static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw,
879 struct ANativeWindowBuffer** anb) {
880 return anw->dequeueBuffer_DEPRECATED(anw, anb);
881}
882
883/*
884 * native_window_set_sideband_stream(..., native_handle_t*)
885 * Attach a sideband buffer stream to a native window.
886 */
887static inline int native_window_set_sideband_stream(
888 struct ANativeWindow* window,
889 native_handle_t* sidebandHandle)
890{
891 return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM,
892 sidebandHandle);
893}
894
895/*
896 * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects)
897 * Set the surface damage (i.e., the region of the surface that has changed
898 * since the previous frame). The damage set by this call will be reset (to the
899 * default of full-surface damage) after calling queue, so this must be called
900 * prior to every frame with damage that does not cover the whole surface if the
901 * caller desires downstream consumers to use this optimization.
902 *
903 * The damage region is specified as an array of rectangles, with the important
904 * caveat that the origin of the surface is considered to be the bottom-left
905 * corner, as in OpenGL ES.
906 *
907 * If numRects is set to 0, rects may be NULL, and the surface damage will be
908 * set to the full surface (the same as if this function had not been called for
909 * this frame).
910 */
911static inline int native_window_set_surface_damage(
912 struct ANativeWindow* window,
913 const android_native_rect_t* rects, size_t numRects)
914{
915 return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE,
916 rects, numRects);
917}
918
919/*
920 * native_window_set_shared_buffer_mode(..., bool sharedBufferMode)
921 * Enable/disable shared buffer mode
922 */
923static inline int native_window_set_shared_buffer_mode(
924 struct ANativeWindow* window,
925 bool sharedBufferMode)
926{
927 return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE,
928 sharedBufferMode);
929}
930
931/*
932 * native_window_set_auto_refresh(..., autoRefresh)
933 * Enable/disable auto refresh when in shared buffer mode
934 */
935static inline int native_window_set_auto_refresh(
936 struct ANativeWindow* window,
937 bool autoRefresh)
938{
939 return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh);
940}
941
942static inline int native_window_get_refresh_cycle_duration(
943 struct ANativeWindow* window,
944 int64_t* outRefreshDuration)
945{
946 return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION,
947 outRefreshDuration);
948}
949
950static inline int native_window_get_next_frame_id(
951 struct ANativeWindow* window, uint64_t* frameId)
952{
953 return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId);
954}
955
956static inline int native_window_enable_frame_timestamps(
957 struct ANativeWindow* window, bool enable)
958{
959 return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS,
960 enable);
961}
962
963static inline int native_window_get_compositor_timing(
964 struct ANativeWindow* window,
965 int64_t* compositeDeadline, int64_t* compositeInterval,
966 int64_t* compositeToPresentLatency)
967{
968 return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING,
969 compositeDeadline, compositeInterval, compositeToPresentLatency);
970}
971
972static inline int native_window_get_frame_timestamps(
973 struct ANativeWindow* window, uint64_t frameId,
974 int64_t* outRequestedPresentTime, int64_t* outAcquireTime,
975 int64_t* outLatchTime, int64_t* outFirstRefreshStartTime,
976 int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime,
977 int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime,
978 int64_t* outReleaseTime)
979{
980 return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS,
981 frameId, outRequestedPresentTime, outAcquireTime, outLatchTime,
982 outFirstRefreshStartTime, outLastRefreshStartTime,
983 outGpuCompositionDoneTime, outDisplayPresentTime,
984 outDequeueReadyTime, outReleaseTime);
985}
986
987static inline int native_window_get_wide_color_support(
988 struct ANativeWindow* window, bool* outSupport) {
Chia-I Wue2786ea2017-08-07 10:36:08 -0700989 return window->perform(window, NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT,
990 outSupport);
Mathias Agopiana6c0e202017-03-20 15:48:44 -0700991}
992
993static inline int native_window_get_hdr_support(struct ANativeWindow* window,
994 bool* outSupport) {
Chia-I Wue2786ea2017-08-07 10:36:08 -0700995 return window->perform(window, NATIVE_WINDOW_GET_HDR_SUPPORT, outSupport);
996}
997
998static inline int native_window_get_consumer_usage(struct ANativeWindow* window,
999 uint64_t* outUsage) {
1000 return window->perform(window, NATIVE_WINDOW_GET_CONSUMER_USAGE64, outUsage);
Mathias Agopiana6c0e202017-03-20 15:48:44 -07001001}
1002
Yiwei Zhang538cedc2019-06-24 19:35:03 -07001003/*
1004 * native_window_set_auto_prerotation(..., autoPrerotation)
1005 * Enable/disable the auto prerotation at buffer allocation when the buffer size
1006 * is driven by the consumer.
1007 *
1008 * When buffer size is driven by the consumer and the transform hint specifies
1009 * a 90 or 270 degree rotation, if auto prerotation is enabled, the width and
1010 * height used for dequeueBuffer will be additionally swapped.
1011 */
1012static inline int native_window_set_auto_prerotation(struct ANativeWindow* window,
1013 bool autoPrerotation) {
1014 return window->perform(window, NATIVE_WINDOW_SET_AUTO_PREROTATION, autoPrerotation);
1015}
1016
Steven Thomas3172e202020-01-06 19:25:30 -08001017static inline int native_window_set_frame_rate(struct ANativeWindow* window, float frameRate) {
1018 return window->perform(window, NATIVE_WINDOW_SET_FRAME_RATE, (double)frameRate);
1019}
1020
Mathias Agopiana6c0e202017-03-20 15:48:44 -07001021__END_DECLS