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