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