1/* 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 **** **** 20 **** DEPRECATED **** 21 **** **** 22 **** THIS FILE EXISTS ONLY FOR BACKWARD SOURCE COMPATIBILITY. **** 23 **** **** 24 **** DO NOT ADD TO THIS FILE. **** 25 **** **** 26 **** Driver implementors (vendors) should use vndk/window.h **** 27 **** (frameworks/native/libs/nativewindow/include/vndk/window.h) **** 28 **** **** 29 **** Internal definition can be found here: **** 30 **** frameworks/native/libs/nativewindow/include/system/window.h **** 31 **** **** 32 ************************************************************************************************** 33 **************************************************************************************************/ 34 35#pragma once 36 37#include <cutils/native_handle.h> 38#include <errno.h> 39#include <limits.h> 40#include <stdint.h> 41#include <string.h> 42#include <sys/cdefs.h> 43#include <system/graphics.h> 44#include <unistd.h> 45#include <stdbool.h> 46 47#ifndef __UNUSED 48#define __UNUSED __attribute__((__unused__)) 49#endif 50#ifndef __deprecated 51#define __deprecated __attribute__((__deprecated__)) 52#endif 53 54__BEGIN_DECLS 55 56/*****************************************************************************/ 57 58#ifdef __cplusplus 59#define ANDROID_NATIVE_UNSIGNED_CAST(x) static_cast<unsigned int>(x) 60#else 61#define ANDROID_NATIVE_UNSIGNED_CAST(x) ((unsigned int)(x)) 62#endif 63 64#define ANDROID_NATIVE_MAKE_CONSTANT(a,b,c,d) \ 65 ((ANDROID_NATIVE_UNSIGNED_CAST(a) << 24) | \ 66 (ANDROID_NATIVE_UNSIGNED_CAST(b) << 16) | \ 67 (ANDROID_NATIVE_UNSIGNED_CAST(c) << 8) | \ 68 (ANDROID_NATIVE_UNSIGNED_CAST(d))) 69 70#define ANDROID_NATIVE_WINDOW_MAGIC \ 71 ANDROID_NATIVE_MAKE_CONSTANT('_','w','n','d') 72 73#define ANDROID_NATIVE_BUFFER_MAGIC \ 74 ANDROID_NATIVE_MAKE_CONSTANT('_','b','f','r') 75 76// --------------------------------------------------------------------------- 77 78// This #define may be used to conditionally compile device-specific code to 79// support either the prior ANativeWindow interface, which did not pass libsync 80// fences around, or the new interface that does. This #define is only present 81// when the ANativeWindow interface does include libsync support. 82#define ANDROID_NATIVE_WINDOW_HAS_SYNC 1 83 84// --------------------------------------------------------------------------- 85 86typedef const native_handle_t* buffer_handle_t; 87 88// --------------------------------------------------------------------------- 89 90typedef struct android_native_rect_t 91{ 92 int32_t left; 93 int32_t top; 94 int32_t right; 95 int32_t bottom; 96} android_native_rect_t; 97 98// --------------------------------------------------------------------------- 99 100typedef struct android_native_base_t 101{ 102 /* a magic value defined by the actual EGL native type */ 103 int magic; 104 105 /* the sizeof() of the actual EGL native type */ 106 int version; 107 108 void* reserved[4]; 109 110 /* reference-counting interface */ 111 void (*incRef)(struct android_native_base_t* base); 112 void (*decRef)(struct android_native_base_t* base); 113} android_native_base_t; 114 115typedef struct ANativeWindowBuffer 116{ 117#ifdef __cplusplus 118 ANativeWindowBuffer() { 119 common.magic = ANDROID_NATIVE_BUFFER_MAGIC; 120 common.version = sizeof(ANativeWindowBuffer); 121 memset(common.reserved, 0, sizeof(common.reserved)); 122 } 123 124 // Implement the methods that sp<ANativeWindowBuffer> expects so that it 125 // can be used to automatically refcount ANativeWindowBuffer's. 126 void incStrong(const void* /*id*/) const { 127 common.incRef(const_cast<android_native_base_t*>(&common)); 128 } 129 void decStrong(const void* /*id*/) const { 130 common.decRef(const_cast<android_native_base_t*>(&common)); 131 } 132#endif 133 134 struct android_native_base_t common; 135 136 int width; 137 int height; 138 int stride; 139 int format; 140 int usage; 141 uintptr_t layerCount; 142 143 void* reserved[1]; 144 145 buffer_handle_t handle; 146 147 void* reserved_proc[8]; 148} ANativeWindowBuffer_t; 149 150// Old typedef for backwards compatibility. 151typedef ANativeWindowBuffer_t android_native_buffer_t; 152 153// --------------------------------------------------------------------------- 154 155/* attributes queriable with query() */ 156enum { 157 NATIVE_WINDOW_WIDTH = 0, 158 NATIVE_WINDOW_HEIGHT = 1, 159 NATIVE_WINDOW_FORMAT = 2, 160 161 /* The minimum number of buffers that must remain un-dequeued after a buffer 162 * has been queued. This value applies only if set_buffer_count was used to 163 * override the number of buffers and if a buffer has since been queued. 164 * Users of the set_buffer_count ANativeWindow method should query this 165 * value before calling set_buffer_count. If it is necessary to have N 166 * buffers simultaneously dequeued as part of the steady-state operation, 167 * and this query returns M then N+M buffers should be requested via 168 * native_window_set_buffer_count. 169 * 170 * Note that this value does NOT apply until a single buffer has been 171 * queued. In particular this means that it is possible to: 172 * 173 * 1. Query M = min undequeued buffers 174 * 2. Set the buffer count to N + M 175 * 3. Dequeue all N + M buffers 176 * 4. Cancel M buffers 177 * 5. Queue, dequeue, queue, dequeue, ad infinitum 178 */ 179 NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS = 3, 180 181 /* Check whether queueBuffer operations on the ANativeWindow send the buffer 182 * to the window compositor. The query sets the returned 'value' argument 183 * to 1 if the ANativeWindow DOES send queued buffers directly to the window 184 * compositor and 0 if the buffers do not go directly to the window 185 * compositor. 186 * 187 * This can be used to determine whether protected buffer content should be 188 * sent to the ANativeWindow. Note, however, that a result of 1 does NOT 189 * indicate that queued buffers will be protected from applications or users 190 * capturing their contents. If that behavior is desired then some other 191 * mechanism (e.g. the GRALLOC_USAGE_PROTECTED flag) should be used in 192 * conjunction with this query. 193 */ 194 NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER = 4, 195 196 /* Get the concrete type of a ANativeWindow. See below for the list of 197 * possible return values. 198 * 199 * This query should not be used outside the Android framework and will 200 * likely be removed in the near future. 201 */ 202 NATIVE_WINDOW_CONCRETE_TYPE = 5, 203 204 205 /* 206 * Default width and height of ANativeWindow buffers, these are the 207 * dimensions of the window buffers irrespective of the 208 * NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS call and match the native window 209 * size unless overridden by NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS. 210 */ 211 NATIVE_WINDOW_DEFAULT_WIDTH = 6, 212 NATIVE_WINDOW_DEFAULT_HEIGHT = 7, 213 214 /* 215 * transformation that will most-likely be applied to buffers. This is only 216 * a hint, the actual transformation applied might be different. 217 * 218 * INTENDED USE: 219 * 220 * The transform hint can be used by a producer, for instance the GLES 221 * driver, to pre-rotate the rendering such that the final transformation 222 * in the composer is identity. This can be very useful when used in 223 * conjunction with the h/w composer HAL, in situations where it 224 * cannot handle arbitrary rotations. 225 * 226 * 1. Before dequeuing a buffer, the GL driver (or any other ANW client) 227 * queries the ANW for NATIVE_WINDOW_TRANSFORM_HINT. 228 * 229 * 2. The GL driver overrides the width and height of the ANW to 230 * account for NATIVE_WINDOW_TRANSFORM_HINT. This is done by querying 231 * NATIVE_WINDOW_DEFAULT_{WIDTH | HEIGHT}, swapping the dimensions 232 * according to NATIVE_WINDOW_TRANSFORM_HINT and calling 233 * native_window_set_buffers_dimensions(). 234 * 235 * 3. The GL driver dequeues a buffer of the new pre-rotated size. 236 * 237 * 4. The GL driver renders to the buffer such that the image is 238 * already transformed, that is applying NATIVE_WINDOW_TRANSFORM_HINT 239 * to the rendering. 240 * 241 * 5. The GL driver calls native_window_set_transform to apply 242 * inverse transformation to the buffer it just rendered. 243 * In order to do this, the GL driver needs 244 * to calculate the inverse of NATIVE_WINDOW_TRANSFORM_HINT, this is 245 * done easily: 246 * 247 * int hintTransform, inverseTransform; 248 * query(..., NATIVE_WINDOW_TRANSFORM_HINT, &hintTransform); 249 * inverseTransform = hintTransform; 250 * if (hintTransform & HAL_TRANSFORM_ROT_90) 251 * inverseTransform ^= HAL_TRANSFORM_ROT_180; 252 * 253 * 254 * 6. The GL driver queues the pre-transformed buffer. 255 * 256 * 7. The composer combines the buffer transform with the display 257 * transform. If the buffer transform happens to cancel out the 258 * display transform then no rotation is needed. 259 * 260 */ 261 NATIVE_WINDOW_TRANSFORM_HINT = 8, 262 263 /* 264 * Boolean that indicates whether the consumer is running more than 265 * one buffer behind the producer. 266 */ 267 NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND = 9, 268 269 /* 270 * The consumer gralloc usage bits currently set by the consumer. 271 * The values are defined in hardware/libhardware/include/gralloc.h. 272 */ 273 NATIVE_WINDOW_CONSUMER_USAGE_BITS = 10, 274 275 /** 276 * Transformation that will by applied to buffers by the hwcomposer. 277 * This must not be set or checked by producer endpoints, and will 278 * disable the transform hint set in SurfaceFlinger (see 279 * NATIVE_WINDOW_TRANSFORM_HINT). 280 * 281 * INTENDED USE: 282 * Temporary - Please do not use this. This is intended only to be used 283 * by the camera's LEGACY mode. 284 * 285 * In situations where a SurfaceFlinger client wishes to set a transform 286 * that is not visible to the producer, and will always be applied in the 287 * hardware composer, the client can set this flag with 288 * native_window_set_buffers_sticky_transform. This can be used to rotate 289 * and flip buffers consumed by hardware composer without actually changing 290 * the aspect ratio of the buffers produced. 291 */ 292 NATIVE_WINDOW_STICKY_TRANSFORM = 11, 293 294 /** 295 * The default data space for the buffers as set by the consumer. 296 * The values are defined in graphics.h. 297 */ 298 NATIVE_WINDOW_DEFAULT_DATASPACE = 12, 299 300 /* 301 * Returns the age of the contents of the most recently dequeued buffer as 302 * the number of frames that have elapsed since it was last queued. For 303 * example, if the window is double-buffered, the age of any given buffer in 304 * steady state will be 2. If the dequeued buffer has never been queued, its 305 * age will be 0. 306 */ 307 NATIVE_WINDOW_BUFFER_AGE = 13, 308 309 /* 310 * Returns the duration of the last dequeueBuffer call in microseconds 311 */ 312 NATIVE_WINDOW_LAST_DEQUEUE_DURATION = 14, 313 314 /* 315 * Returns the duration of the last queueBuffer call in microseconds 316 */ 317 NATIVE_WINDOW_LAST_QUEUE_DURATION = 15, 318 319 /* 320 * Returns the number of image layers that the ANativeWindow buffer 321 * contains. By default this is 1, unless a buffer is explicitly allocated 322 * to contain multiple layers. 323 */ 324 NATIVE_WINDOW_LAYER_COUNT = 16, 325 326 /* 327 * Returns 1 if the native window is valid, 0 otherwise. native window is valid 328 * if it is safe (i.e. no crash will occur) to call any method on it. 329 */ 330 NATIVE_WINDOW_IS_VALID = 17, 331 332 /* 333 * Returns 1 if NATIVE_WINDOW_GET_FRAME_TIMESTAMPS will return display 334 * present info, 0 if it won't. 335 */ 336 NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT = 18, 337 338 /* 339 * The consumer end is capable of handling protected buffers, i.e. buffer 340 * with GRALLOC_USAGE_PROTECTED usage bits on. 341 */ 342 NATIVE_WINDOW_CONSUMER_IS_PROTECTED = 19, 343}; 344 345/* Valid operations for the (*perform)() hook. 346 * 347 * Values marked as 'deprecated' are supported, but have been superceded by 348 * other functionality. 349 * 350 * Values marked as 'private' should be considered private to the framework. 351 * HAL implementation code with access to an ANativeWindow should not use these, 352 * as it may not interact properly with the framework's use of the 353 * ANativeWindow. 354 */ 355enum { 356// clang-format off 357 NATIVE_WINDOW_SET_USAGE = 0, 358 NATIVE_WINDOW_CONNECT = 1, /* deprecated */ 359 NATIVE_WINDOW_DISCONNECT = 2, /* deprecated */ 360 NATIVE_WINDOW_SET_CROP = 3, /* private */ 361 NATIVE_WINDOW_SET_BUFFER_COUNT = 4, 362 NATIVE_WINDOW_SET_BUFFERS_GEOMETRY = 5, /* deprecated */ 363 NATIVE_WINDOW_SET_BUFFERS_TRANSFORM = 6, 364 NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP = 7, 365 NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS = 8, 366 NATIVE_WINDOW_SET_BUFFERS_FORMAT = 9, 367 NATIVE_WINDOW_SET_SCALING_MODE = 10, /* private */ 368 NATIVE_WINDOW_LOCK = 11, /* private */ 369 NATIVE_WINDOW_UNLOCK_AND_POST = 12, /* private */ 370 NATIVE_WINDOW_API_CONNECT = 13, /* private */ 371 NATIVE_WINDOW_API_DISCONNECT = 14, /* private */ 372 NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS = 15, /* private */ 373 NATIVE_WINDOW_SET_POST_TRANSFORM_CROP = 16, /* private */ 374 NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM = 17,/* private */ 375 NATIVE_WINDOW_SET_SIDEBAND_STREAM = 18, 376 NATIVE_WINDOW_SET_BUFFERS_DATASPACE = 19, 377 NATIVE_WINDOW_SET_SURFACE_DAMAGE = 20, /* private */ 378 NATIVE_WINDOW_SET_SHARED_BUFFER_MODE = 21, 379 NATIVE_WINDOW_SET_AUTO_REFRESH = 22, 380 NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION= 23, 381 NATIVE_WINDOW_GET_NEXT_FRAME_ID = 24, 382 NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS = 25, 383 NATIVE_WINDOW_GET_COMPOSITOR_TIMING = 26, 384 NATIVE_WINDOW_GET_FRAME_TIMESTAMPS = 27, 385 NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT = 28, 386 NATIVE_WINDOW_GET_HDR_SUPPORT = 29, 387// clang-format on 388}; 389 390/* parameter for NATIVE_WINDOW_[API_][DIS]CONNECT */ 391enum { 392 /* Buffers will be queued by EGL via eglSwapBuffers after being filled using 393 * OpenGL ES. 394 */ 395 NATIVE_WINDOW_API_EGL = 1, 396 397 /* Buffers will be queued after being filled using the CPU 398 */ 399 NATIVE_WINDOW_API_CPU = 2, 400 401 /* Buffers will be queued by Stagefright after being filled by a video 402 * decoder. The video decoder can either be a software or hardware decoder. 403 */ 404 NATIVE_WINDOW_API_MEDIA = 3, 405 406 /* Buffers will be queued by the the camera HAL. 407 */ 408 NATIVE_WINDOW_API_CAMERA = 4, 409}; 410 411/* parameter for NATIVE_WINDOW_SET_BUFFERS_TRANSFORM */ 412enum { 413 /* flip source image horizontally */ 414 NATIVE_WINDOW_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H , 415 /* flip source image vertically */ 416 NATIVE_WINDOW_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, 417 /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */ 418 NATIVE_WINDOW_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, 419 /* rotate source image 180 degrees */ 420 NATIVE_WINDOW_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, 421 /* rotate source image 270 degrees clock-wise */ 422 NATIVE_WINDOW_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, 423 /* transforms source by the inverse transform of the screen it is displayed onto. This 424 * transform is applied last */ 425 NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY = 0x08 426}; 427 428/* parameter for NATIVE_WINDOW_SET_SCALING_MODE 429 * keep in sync with Surface.java in frameworks/base */ 430enum { 431 /* the window content is not updated (frozen) until a buffer of 432 * the window size is received (enqueued) 433 */ 434 NATIVE_WINDOW_SCALING_MODE_FREEZE = 0, 435 /* the buffer is scaled in both dimensions to match the window size */ 436 NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW = 1, 437 /* the buffer is scaled uniformly such that the smaller dimension 438 * of the buffer matches the window size (cropping in the process) 439 */ 440 NATIVE_WINDOW_SCALING_MODE_SCALE_CROP = 2, 441 /* the window is clipped to the size of the buffer's crop rectangle; pixels 442 * outside the crop rectangle are treated as if they are completely 443 * transparent. 444 */ 445 NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP = 3, 446}; 447 448/* values returned by the NATIVE_WINDOW_CONCRETE_TYPE query */ 449enum { 450 NATIVE_WINDOW_FRAMEBUFFER = 0, /* FramebufferNativeWindow */ 451 NATIVE_WINDOW_SURFACE = 1, /* Surface */ 452}; 453 454/* parameter for NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP 455 * 456 * Special timestamp value to indicate that timestamps should be auto-generated 457 * by the native window when queueBuffer is called. This is equal to INT64_MIN, 458 * defined directly to avoid problems with C99/C++ inclusion of stdint.h. 459 */ 460static const int64_t NATIVE_WINDOW_TIMESTAMP_AUTO = (-9223372036854775807LL-1); 461 462/* parameter for NATIVE_WINDOW_GET_FRAME_TIMESTAMPS 463 * 464 * Special timestamp value to indicate the timestamps aren't yet known or 465 * that they are invalid. 466 */ 467static const int64_t NATIVE_WINDOW_TIMESTAMP_PENDING = -2; 468static const int64_t NATIVE_WINDOW_TIMESTAMP_INVALID = -1; 469 470struct ANativeWindow 471{ 472#ifdef __cplusplus 473 ANativeWindow() 474 : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) 475 { 476 common.magic = ANDROID_NATIVE_WINDOW_MAGIC; 477 common.version = sizeof(ANativeWindow); 478 memset(common.reserved, 0, sizeof(common.reserved)); 479 } 480 481 /* Implement the methods that sp<ANativeWindow> expects so that it 482 can be used to automatically refcount ANativeWindow's. */ 483 void incStrong(const void* /*id*/) const { 484 common.incRef(const_cast<android_native_base_t*>(&common)); 485 } 486 void decStrong(const void* /*id*/) const { 487 common.decRef(const_cast<android_native_base_t*>(&common)); 488 } 489#endif 490 491 struct android_native_base_t common; 492 493 /* flags describing some attributes of this surface or its updater */ 494 const uint32_t flags; 495 496 /* min swap interval supported by this updated */ 497 const int minSwapInterval; 498 499 /* max swap interval supported by this updated */ 500 const int maxSwapInterval; 501 502 /* horizontal and vertical resolution in DPI */ 503 const float xdpi; 504 const float ydpi; 505 506 /* Some storage reserved for the OEM's driver. */ 507 intptr_t oem[4]; 508 509 /* 510 * Set the swap interval for this surface. 511 * 512 * Returns 0 on success or -errno on error. 513 */ 514 int (*setSwapInterval)(struct ANativeWindow* window, 515 int interval); 516 517 /* 518 * Hook called by EGL to acquire a buffer. After this call, the buffer 519 * is not locked, so its content cannot be modified. This call may block if 520 * no buffers are available. 521 * 522 * The window holds a reference to the buffer between dequeueBuffer and 523 * either queueBuffer or cancelBuffer, so clients only need their own 524 * reference if they might use the buffer after queueing or canceling it. 525 * Holding a reference to a buffer after queueing or canceling it is only 526 * allowed if a specific buffer count has been set. 527 * 528 * Returns 0 on success or -errno on error. 529 * 530 * XXX: This function is deprecated. It will continue to work for some 531 * time for binary compatibility, but the new dequeueBuffer function that 532 * outputs a fence file descriptor should be used in its place. 533 */ 534 int (*dequeueBuffer_DEPRECATED)(struct ANativeWindow* window, 535 struct ANativeWindowBuffer** buffer); 536 537 /* 538 * hook called by EGL to lock a buffer. This MUST be called before modifying 539 * the content of a buffer. The buffer must have been acquired with 540 * dequeueBuffer first. 541 * 542 * Returns 0 on success or -errno on error. 543 * 544 * XXX: This function is deprecated. It will continue to work for some 545 * time for binary compatibility, but it is essentially a no-op, and calls 546 * to it should be removed. 547 */ 548 int (*lockBuffer_DEPRECATED)(struct ANativeWindow* window, 549 struct ANativeWindowBuffer* buffer); 550 551 /* 552 * Hook called by EGL when modifications to the render buffer are done. 553 * This unlocks and post the buffer. 554 * 555 * The window holds a reference to the buffer between dequeueBuffer and 556 * either queueBuffer or cancelBuffer, so clients only need their own 557 * reference if they might use the buffer after queueing or canceling it. 558 * Holding a reference to a buffer after queueing or canceling it is only 559 * allowed if a specific buffer count has been set. 560 * 561 * Buffers MUST be queued in the same order than they were dequeued. 562 * 563 * Returns 0 on success or -errno on error. 564 * 565 * XXX: This function is deprecated. It will continue to work for some 566 * time for binary compatibility, but the new queueBuffer function that 567 * takes a fence file descriptor should be used in its place (pass a value 568 * of -1 for the fence file descriptor if there is no valid one to pass). 569 */ 570 int (*queueBuffer_DEPRECATED)(struct ANativeWindow* window, 571 struct ANativeWindowBuffer* buffer); 572 573 /* 574 * hook used to retrieve information about the native window. 575 * 576 * Returns 0 on success or -errno on error. 577 */ 578 int (*query)(const struct ANativeWindow* window, 579 int what, int* value); 580 581 /* 582 * hook used to perform various operations on the surface. 583 * (*perform)() is a generic mechanism to add functionality to 584 * ANativeWindow while keeping backward binary compatibility. 585 * 586 * DO NOT CALL THIS HOOK DIRECTLY. Instead, use the helper functions 587 * defined below. 588 * 589 * (*perform)() returns -ENOENT if the 'what' parameter is not supported 590 * by the surface's implementation. 591 * 592 * See above for a list of valid operations, such as 593 * NATIVE_WINDOW_SET_USAGE or NATIVE_WINDOW_CONNECT 594 */ 595 int (*perform)(struct ANativeWindow* window, 596 int operation, ... ); 597 598 /* 599 * Hook used to cancel a buffer that has been dequeued. 600 * No synchronization is performed between dequeue() and cancel(), so 601 * either external synchronization is needed, or these functions must be 602 * called from the same thread. 603 * 604 * The window holds a reference to the buffer between dequeueBuffer and 605 * either queueBuffer or cancelBuffer, so clients only need their own 606 * reference if they might use the buffer after queueing or canceling it. 607 * Holding a reference to a buffer after queueing or canceling it is only 608 * allowed if a specific buffer count has been set. 609 * 610 * XXX: This function is deprecated. It will continue to work for some 611 * time for binary compatibility, but the new cancelBuffer function that 612 * takes a fence file descriptor should be used in its place (pass a value 613 * of -1 for the fence file descriptor if there is no valid one to pass). 614 */ 615 int (*cancelBuffer_DEPRECATED)(struct ANativeWindow* window, 616 struct ANativeWindowBuffer* buffer); 617 618 /* 619 * Hook called by EGL to acquire a buffer. This call may block if no 620 * buffers are available. 621 * 622 * The window holds a reference to the buffer between dequeueBuffer and 623 * either queueBuffer or cancelBuffer, so clients only need their own 624 * reference if they might use the buffer after queueing or canceling it. 625 * Holding a reference to a buffer after queueing or canceling it is only 626 * allowed if a specific buffer count has been set. 627 * 628 * The libsync fence file descriptor returned in the int pointed to by the 629 * fenceFd argument will refer to the fence that must signal before the 630 * dequeued buffer may be written to. A value of -1 indicates that the 631 * caller may access the buffer immediately without waiting on a fence. If 632 * a valid file descriptor is returned (i.e. any value except -1) then the 633 * caller is responsible for closing the file descriptor. 634 * 635 * Returns 0 on success or -errno on error. 636 */ 637 int (*dequeueBuffer)(struct ANativeWindow* window, 638 struct ANativeWindowBuffer** buffer, int* fenceFd); 639 640 /* 641 * Hook called by EGL when modifications to the render buffer are done. 642 * This unlocks and post the buffer. 643 * 644 * The window holds a reference to the buffer between dequeueBuffer and 645 * either queueBuffer or cancelBuffer, so clients only need their own 646 * reference if they might use the buffer after queueing or canceling it. 647 * Holding a reference to a buffer after queueing or canceling it is only 648 * allowed if a specific buffer count has been set. 649 * 650 * The fenceFd argument specifies a libsync fence file descriptor for a 651 * fence that must signal before the buffer can be accessed. If the buffer 652 * can be accessed immediately then a value of -1 should be used. The 653 * caller must not use the file descriptor after it is passed to 654 * queueBuffer, and the ANativeWindow implementation is responsible for 655 * closing it. 656 * 657 * Returns 0 on success or -errno on error. 658 */ 659 int (*queueBuffer)(struct ANativeWindow* window, 660 struct ANativeWindowBuffer* buffer, int fenceFd); 661 662 /* 663 * Hook used to cancel a buffer that has been dequeued. 664 * No synchronization is performed between dequeue() and cancel(), so 665 * either external synchronization is needed, or these functions must be 666 * called from the same thread. 667 * 668 * The window holds a reference to the buffer between dequeueBuffer and 669 * either queueBuffer or cancelBuffer, so clients only need their own 670 * reference if they might use the buffer after queueing or canceling it. 671 * Holding a reference to a buffer after queueing or canceling it is only 672 * allowed if a specific buffer count has been set. 673 * 674 * The fenceFd argument specifies a libsync fence file decsriptor for a 675 * fence that must signal before the buffer can be accessed. If the buffer 676 * can be accessed immediately then a value of -1 should be used. 677 * 678 * Note that if the client has not waited on the fence that was returned 679 * from dequeueBuffer, that same fence should be passed to cancelBuffer to 680 * ensure that future uses of the buffer are preceded by a wait on that 681 * fence. The caller must not use the file descriptor after it is passed 682 * to cancelBuffer, and the ANativeWindow implementation is responsible for 683 * closing it. 684 * 685 * Returns 0 on success or -errno on error. 686 */ 687 int (*cancelBuffer)(struct ANativeWindow* window, 688 struct ANativeWindowBuffer* buffer, int fenceFd); 689}; 690 691 /* Backwards compatibility: use ANativeWindow (struct ANativeWindow in C). 692 * android_native_window_t is deprecated. 693 */ 694typedef struct ANativeWindow ANativeWindow; 695typedef struct ANativeWindow android_native_window_t __deprecated; 696 697/* 698 * native_window_set_usage(..., usage) 699 * Sets the intended usage flags for the next buffers 700 * acquired with (*lockBuffer)() and on. 701 * By default (if this function is never called), a usage of 702 * GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE 703 * is assumed. 704 * Calling this function will usually cause following buffers to be 705 * reallocated. 706 */ 707 708static inline int native_window_set_usage( 709 struct ANativeWindow* window, int usage) 710{ 711 return window->perform(window, NATIVE_WINDOW_SET_USAGE, usage); 712} 713 714/* deprecated. Always returns 0. Don't call. */ 715static inline int native_window_connect( 716 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated; 717 718static inline int native_window_connect( 719 struct ANativeWindow* window __UNUSED, int api __UNUSED) { 720 return 0; 721} 722 723/* deprecated. Always returns 0. Don't call. */ 724static inline int native_window_disconnect( 725 struct ANativeWindow* window __UNUSED, int api __UNUSED) __deprecated; 726 727static inline int native_window_disconnect( 728 struct ANativeWindow* window __UNUSED, int api __UNUSED) { 729 return 0; 730} 731 732/* 733 * native_window_set_crop(..., crop) 734 * Sets which region of the next queued buffers needs to be considered. 735 * Depending on the scaling mode, a buffer's crop region is scaled and/or 736 * cropped to match the surface's size. This function sets the crop in 737 * pre-transformed buffer pixel coordinates. 738 * 739 * The specified crop region applies to all buffers queued after it is called. 740 * 741 * If 'crop' is NULL, subsequently queued buffers won't be cropped. 742 * 743 * An error is returned if for instance the crop region is invalid, out of the 744 * buffer's bound or if the window is invalid. 745 */ 746static inline int native_window_set_crop( 747 struct ANativeWindow* window, 748 android_native_rect_t const * crop) 749{ 750 return window->perform(window, NATIVE_WINDOW_SET_CROP, crop); 751} 752 753/* 754 * native_window_set_post_transform_crop(..., crop) 755 * Sets which region of the next queued buffers needs to be considered. 756 * Depending on the scaling mode, a buffer's crop region is scaled and/or 757 * cropped to match the surface's size. This function sets the crop in 758 * post-transformed pixel coordinates. 759 * 760 * The specified crop region applies to all buffers queued after it is called. 761 * 762 * If 'crop' is NULL, subsequently queued buffers won't be cropped. 763 * 764 * An error is returned if for instance the crop region is invalid, out of the 765 * buffer's bound or if the window is invalid. 766 */ 767static inline int native_window_set_post_transform_crop( 768 struct ANativeWindow* window, 769 android_native_rect_t const * crop) 770{ 771 return window->perform(window, NATIVE_WINDOW_SET_POST_TRANSFORM_CROP, crop); 772} 773 774/* 775 * native_window_set_active_rect(..., active_rect) 776 * 777 * This function is deprecated and will be removed soon. For now it simply 778 * sets the post-transform crop for compatibility while multi-project commits 779 * get checked. 780 */ 781static inline int native_window_set_active_rect( 782 struct ANativeWindow* window, 783 android_native_rect_t const * active_rect) __deprecated; 784 785static inline int native_window_set_active_rect( 786 struct ANativeWindow* window, 787 android_native_rect_t const * active_rect) 788{ 789 return native_window_set_post_transform_crop(window, active_rect); 790} 791 792/* 793 * native_window_set_buffer_count(..., count) 794 * Sets the number of buffers associated with this native window. 795 */ 796static inline int native_window_set_buffer_count( 797 struct ANativeWindow* window, 798 size_t bufferCount) 799{ 800 return window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, bufferCount); 801} 802 803/* 804 * native_window_set_buffers_geometry(..., int w, int h, int format) 805 * All buffers dequeued after this call will have the dimensions and format 806 * specified. A successful call to this function has the same effect as calling 807 * native_window_set_buffers_size and native_window_set_buffers_format. 808 * 809 * XXX: This function is deprecated. The native_window_set_buffers_dimensions 810 * and native_window_set_buffers_format functions should be used instead. 811 */ 812static inline int native_window_set_buffers_geometry( 813 struct ANativeWindow* window, 814 int w, int h, int format) __deprecated; 815 816static inline int native_window_set_buffers_geometry( 817 struct ANativeWindow* window, 818 int w, int h, int format) 819{ 820 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_GEOMETRY, 821 w, h, format); 822} 823 824/* 825 * native_window_set_buffers_dimensions(..., int w, int h) 826 * All buffers dequeued after this call will have the dimensions specified. 827 * In particular, all buffers will have a fixed-size, independent from the 828 * native-window size. They will be scaled according to the scaling mode 829 * (see native_window_set_scaling_mode) upon window composition. 830 * 831 * If w and h are 0, the normal behavior is restored. That is, dequeued buffers 832 * following this call will be sized to match the window's size. 833 * 834 * Calling this function will reset the window crop to a NULL value, which 835 * disables cropping of the buffers. 836 */ 837static inline int native_window_set_buffers_dimensions( 838 struct ANativeWindow* window, 839 int w, int h) 840{ 841 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS, 842 w, h); 843} 844 845/* 846 * native_window_set_buffers_user_dimensions(..., int w, int h) 847 * 848 * Sets the user buffer size for the window, which overrides the 849 * window's size. All buffers dequeued after this call will have the 850 * dimensions specified unless overridden by 851 * native_window_set_buffers_dimensions. All buffers will have a 852 * fixed-size, independent from the native-window size. They will be 853 * scaled according to the scaling mode (see 854 * native_window_set_scaling_mode) upon window composition. 855 * 856 * If w and h are 0, the normal behavior is restored. That is, the 857 * default buffer size will match the windows's size. 858 * 859 * Calling this function will reset the window crop to a NULL value, which 860 * disables cropping of the buffers. 861 */ 862static inline int native_window_set_buffers_user_dimensions( 863 struct ANativeWindow* window, 864 int w, int h) 865{ 866 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS, 867 w, h); 868} 869 870/* 871 * native_window_set_buffers_format(..., int format) 872 * All buffers dequeued after this call will have the format specified. 873 * 874 * If the specified format is 0, the default buffer format will be used. 875 */ 876static inline int native_window_set_buffers_format( 877 struct ANativeWindow* window, 878 int format) 879{ 880 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_FORMAT, format); 881} 882 883/* 884 * native_window_set_buffers_data_space(..., int dataSpace) 885 * All buffers queued after this call will be associated with the dataSpace 886 * parameter specified. 887 * 888 * dataSpace specifies additional information about the buffer that's dependent 889 * on the buffer format and the endpoints. For example, it can be used to convey 890 * the color space of the image data in the buffer, or it can be used to 891 * indicate that the buffers contain depth measurement data instead of color 892 * images. The default dataSpace is 0, HAL_DATASPACE_UNKNOWN, unless it has been 893 * overridden by the consumer. 894 */ 895static inline int native_window_set_buffers_data_space( 896 struct ANativeWindow* window, 897 android_dataspace_t dataSpace) 898{ 899 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_DATASPACE, 900 dataSpace); 901} 902 903/* 904 * native_window_set_buffers_transform(..., int transform) 905 * All buffers queued after this call will be displayed transformed according 906 * to the transform parameter specified. 907 */ 908static inline int native_window_set_buffers_transform( 909 struct ANativeWindow* window, 910 int transform) 911{ 912 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TRANSFORM, 913 transform); 914} 915 916/* 917 * native_window_set_buffers_sticky_transform(..., int transform) 918 * All buffers queued after this call will be displayed transformed according 919 * to the transform parameter specified applied on top of the regular buffer 920 * transform. Setting this transform will disable the transform hint. 921 * 922 * Temporary - This is only intended to be used by the LEGACY camera mode, do 923 * not use this for anything else. 924 */ 925static inline int native_window_set_buffers_sticky_transform( 926 struct ANativeWindow* window, 927 int transform) 928{ 929 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM, 930 transform); 931} 932 933/* 934 * native_window_set_buffers_timestamp(..., int64_t timestamp) 935 * All buffers queued after this call will be associated with the timestamp 936 * parameter specified. If the timestamp is set to NATIVE_WINDOW_TIMESTAMP_AUTO 937 * (the default), timestamps will be generated automatically when queueBuffer is 938 * called. The timestamp is measured in nanoseconds, and is normally monotonically 939 * increasing. The timestamp should be unaffected by time-of-day adjustments, 940 * and for a camera should be strictly monotonic but for a media player may be 941 * reset when the position is set. 942 */ 943static inline int native_window_set_buffers_timestamp( 944 struct ANativeWindow* window, 945 int64_t timestamp) 946{ 947 return window->perform(window, NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP, 948 timestamp); 949} 950 951/* 952 * native_window_set_scaling_mode(..., int mode) 953 * All buffers queued after this call will be associated with the scaling mode 954 * specified. 955 */ 956static inline int native_window_set_scaling_mode( 957 struct ANativeWindow* window, 958 int mode) 959{ 960 return window->perform(window, NATIVE_WINDOW_SET_SCALING_MODE, 961 mode); 962} 963 964/* 965 * native_window_api_connect(..., int api) 966 * connects an API to this window. only one API can be connected at a time. 967 * Returns -EINVAL if for some reason the window cannot be connected, which 968 * can happen if it's connected to some other API. 969 */ 970static inline int native_window_api_connect( 971 struct ANativeWindow* window, int api) 972{ 973 return window->perform(window, NATIVE_WINDOW_API_CONNECT, api); 974} 975 976/* 977 * native_window_api_disconnect(..., int api) 978 * disconnect the API from this window. 979 * An error is returned if for instance the window wasn't connected in the 980 * first place. 981 */ 982static inline int native_window_api_disconnect( 983 struct ANativeWindow* window, int api) 984{ 985 return window->perform(window, NATIVE_WINDOW_API_DISCONNECT, api); 986} 987 988/* 989 * native_window_dequeue_buffer_and_wait(...) 990 * Dequeue a buffer and wait on the fence associated with that buffer. The 991 * buffer may safely be accessed immediately upon this function returning. An 992 * error is returned if either of the dequeue or the wait operations fail. 993 */ 994static inline int native_window_dequeue_buffer_and_wait(ANativeWindow *anw, 995 struct ANativeWindowBuffer** anb) { 996 return anw->dequeueBuffer_DEPRECATED(anw, anb); 997} 998 999/* 1000 * native_window_set_sideband_stream(..., native_handle_t*) 1001 * Attach a sideband buffer stream to a native window. 1002 */ 1003static inline int native_window_set_sideband_stream( 1004 struct ANativeWindow* window, 1005 native_handle_t* sidebandHandle) 1006{ 1007 return window->perform(window, NATIVE_WINDOW_SET_SIDEBAND_STREAM, 1008 sidebandHandle); 1009} 1010 1011/* 1012 * native_window_set_surface_damage(..., android_native_rect_t* rects, int numRects) 1013 * Set the surface damage (i.e., the region of the surface that has changed 1014 * since the previous frame). The damage set by this call will be reset (to the 1015 * default of full-surface damage) after calling queue, so this must be called 1016 * prior to every frame with damage that does not cover the whole surface if the 1017 * caller desires downstream consumers to use this optimization. 1018 * 1019 * The damage region is specified as an array of rectangles, with the important 1020 * caveat that the origin of the surface is considered to be the bottom-left 1021 * corner, as in OpenGL ES. 1022 * 1023 * If numRects is set to 0, rects may be NULL, and the surface damage will be 1024 * set to the full surface (the same as if this function had not been called for 1025 * this frame). 1026 */ 1027static inline int native_window_set_surface_damage( 1028 struct ANativeWindow* window, 1029 const android_native_rect_t* rects, size_t numRects) 1030{ 1031 return window->perform(window, NATIVE_WINDOW_SET_SURFACE_DAMAGE, 1032 rects, numRects); 1033} 1034 1035/* 1036 * native_window_set_shared_buffer_mode(..., bool sharedBufferMode) 1037 * Enable/disable shared buffer mode 1038 */ 1039static inline int native_window_set_shared_buffer_mode( 1040 struct ANativeWindow* window, 1041 bool sharedBufferMode) 1042{ 1043 return window->perform(window, NATIVE_WINDOW_SET_SHARED_BUFFER_MODE, 1044 sharedBufferMode); 1045} 1046 1047/* 1048 * native_window_set_auto_refresh(..., autoRefresh) 1049 * Enable/disable auto refresh when in shared buffer mode 1050 */ 1051static inline int native_window_set_auto_refresh( 1052 struct ANativeWindow* window, 1053 bool autoRefresh) 1054{ 1055 return window->perform(window, NATIVE_WINDOW_SET_AUTO_REFRESH, autoRefresh); 1056} 1057 1058static inline int native_window_get_refresh_cycle_duration( 1059 struct ANativeWindow* window, 1060 int64_t* outRefreshDuration) 1061{ 1062 return window->perform(window, NATIVE_WINDOW_GET_REFRESH_CYCLE_DURATION, 1063 outRefreshDuration); 1064} 1065 1066static inline int native_window_get_next_frame_id( 1067 struct ANativeWindow* window, uint64_t* frameId) 1068{ 1069 return window->perform(window, NATIVE_WINDOW_GET_NEXT_FRAME_ID, frameId); 1070} 1071 1072static inline int native_window_enable_frame_timestamps( 1073 struct ANativeWindow* window, bool enable) 1074{ 1075 return window->perform(window, NATIVE_WINDOW_ENABLE_FRAME_TIMESTAMPS, 1076 enable); 1077} 1078 1079static inline int native_window_get_compositor_timing( 1080 struct ANativeWindow* window, 1081 int64_t* compositeDeadline, int64_t* compositeInterval, 1082 int64_t* compositeToPresentLatency) 1083{ 1084 return window->perform(window, NATIVE_WINDOW_GET_COMPOSITOR_TIMING, 1085 compositeDeadline, compositeInterval, compositeToPresentLatency); 1086} 1087 1088static inline int native_window_get_frame_timestamps( 1089 struct ANativeWindow* window, uint64_t frameId, 1090 int64_t* outRequestedPresentTime, int64_t* outAcquireTime, 1091 int64_t* outLatchTime, int64_t* outFirstRefreshStartTime, 1092 int64_t* outLastRefreshStartTime, int64_t* outGpuCompositionDoneTime, 1093 int64_t* outDisplayPresentTime, int64_t* outDequeueReadyTime, 1094 int64_t* outReleaseTime) 1095{ 1096 return window->perform(window, NATIVE_WINDOW_GET_FRAME_TIMESTAMPS, 1097 frameId, outRequestedPresentTime, outAcquireTime, outLatchTime, 1098 outFirstRefreshStartTime, outLastRefreshStartTime, 1099 outGpuCompositionDoneTime, outDisplayPresentTime, 1100 outDequeueReadyTime, outReleaseTime); 1101} 1102 1103static inline int native_window_get_wide_color_support( 1104 struct ANativeWindow* window, bool* outSupport) { 1105 return window->perform(window, NATIVE_WINDOW_GET_WIDE_COLOR_SUPPORT, 1106 outSupport); 1107} 1108 1109static inline int native_window_get_hdr_support(struct ANativeWindow* window, 1110 bool* outSupport) { 1111 return window->perform(window, NATIVE_WINDOW_GET_HDR_SUPPORT, outSupport); 1112} 1113 1114__END_DECLS 1115