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