1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup NativeWindow 18 * @{ 19 * 20 * @brief Provides the native window capability for connection to the EGL. 21 * 22 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 23 * @since 8 24 * @version 1.0 25 */ 26 27 /** 28 * @file external_window.h 29 * 30 * @brief Defines the functions for obtaining and using a native window. 31 * 32 * @kit ArkGraphics2D 33 * @library libnative_window.so 34 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 35 * @since 8 36 * @version 1.0 37 */ 38 39 #ifndef NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_ 40 #define NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_ 41 42 #include <stdint.h> 43 #include "buffer_handle.h" 44 #include "../native_buffer/buffer_common.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 typedef struct OH_NativeBuffer OH_NativeBuffer; 50 51 /** 52 * @brief Defines the ipc parcel. 53 * 54 * @since 12 55 * @version 1.0 56 */ 57 typedef struct OHIPCParcel OHIPCParcel; 58 59 /** 60 * @brief native window. 61 * @since 8 62 */ 63 struct NativeWindow; 64 65 /** 66 * @brief native window buffer. 67 * @since 8 68 */ 69 struct NativeWindowBuffer; 70 71 /** 72 * @brief define the new type name OHNativeWindow for struct NativeWindow. 73 * @since 8 74 */ 75 typedef struct NativeWindow OHNativeWindow; 76 77 /** 78 * @brief define the new type name OHNativeWindowBuffer for struct NativeWindowBuffer. 79 * @since 8 80 */ 81 typedef struct NativeWindowBuffer OHNativeWindowBuffer; 82 83 /** 84 * @brief indicates a dirty region where content is updated. 85 * @since 8 86 */ 87 typedef struct Region { 88 /** if rects is nullptr, fill the Buffer dirty size by default */ 89 struct Rect { 90 int32_t x; 91 int32_t y; 92 uint32_t w; 93 uint32_t h; 94 } *rects; 95 /** if rectNumber is 0, fill the Buffer dirty size by default */ 96 int32_t rectNumber; 97 }Region; 98 99 100 /** 101 * @brief Indicates the operation code in the function OH_NativeWindow_NativeWindowHandleOpt. 102 * @since 8 103 */ 104 typedef enum NativeWindowOperation { 105 /** 106 * set native window buffer geometry, 107 * variable parameter in function is 108 * [in] int32_t width, [in] int32_t height 109 */ 110 SET_BUFFER_GEOMETRY, 111 /** 112 * get native window buffer geometry, 113 * variable parameter in function is 114 * [out] int32_t *height, [out] int32_t *width 115 */ 116 GET_BUFFER_GEOMETRY, 117 /** 118 * get native window buffer format, 119 * variable parameter in function is 120 * [out] int32_t *format, the enumeration value refers to {@link OH_NativeBuffer_Format}. 121 */ 122 GET_FORMAT, 123 /** 124 * set native window buffer format, 125 * variable parameter in function is 126 * [in] int32_t format, the enumeration value refers to {@link OH_NativeBuffer_Format}. 127 */ 128 SET_FORMAT, 129 /** 130 * get native window buffer usage, 131 * variable parameter in function is 132 * [out] uint64_t *usage, the enumeration value refers to {@link OH_NativeBuffer_Usage}. 133 */ 134 GET_USAGE, 135 /** 136 * set native window buffer usage, 137 * variable parameter in function is 138 * [in] uint64_t usage, the enumeration value refers to {@link OH_NativeBuffer_Usage}. 139 */ 140 SET_USAGE, 141 /** 142 * set native window buffer stride, 143 * variable parameter in function is 144 * [in] int32_t stride. 145 * @deprecated since 16 146 */ 147 SET_STRIDE, 148 /** 149 * get native window buffer stride, 150 * variable parameter in function is 151 * [out] int32_t *stride. 152 * @deprecated since 16 153 * @useinstead Use {@link OH_NativeWindow_GetBufferHandleFromNative} to get a {@link BufferHandleand} from a buffer 154 * and then retrieve the stride from the {@link BufferHandle}. 155 */ 156 GET_STRIDE, 157 /** 158 * set native window buffer swap interval, 159 * variable parameter in function is 160 * [in] int32_t interval. 161 */ 162 SET_SWAP_INTERVAL, 163 /** 164 * get native window buffer swap interval, 165 * variable parameter in function is 166 * [out] int32_t *interval. 167 */ 168 GET_SWAP_INTERVAL, 169 /** 170 * set the timeout in milliseconds when the native window requests a buffer, 171 * the default value is 3000 milliseconds when not set, 172 * variable parameter in function is 173 * [in] int32_t timeout, in milliseconds. 174 */ 175 SET_TIMEOUT, 176 /** 177 * get the timeout in milliseconds when the native window requests a buffer, 178 * the default value is 3000 milliseconds when not set, 179 * variable parameter in function is 180 * [out] int32_t *timeout, in milliseconds. 181 */ 182 GET_TIMEOUT, 183 /** 184 * set native window buffer colorGamut, 185 * variable parameter in function is 186 * [in] int32_t colorGamut, the enumeration value refers to {@link OH_NativeBuffer_ColorGamut}. 187 */ 188 SET_COLOR_GAMUT, 189 /** 190 * get native window buffer colorGamut, 191 * variable parameter in function is 192 * [out] int32_t *colorGamut, the enumeration value refers to {@link OH_NativeBuffer_ColorGamut}. 193 */ 194 GET_COLOR_GAMUT, 195 /** 196 * set native window buffer transform, 197 * variable parameter in function is 198 * [in] int32_t transform, the enumeration value refers to {@link OH_NativeBuffer_TransformType}. 199 */ 200 SET_TRANSFORM, 201 /** 202 * get native window buffer transform, 203 * variable parameter in function is 204 * [out] int32_t *transform, the enumeration value refers to {@link OH_NativeBuffer_TransformType}. 205 */ 206 GET_TRANSFORM, 207 /** 208 * set native window buffer uiTimestamp, 209 * variable parameter in function is 210 * [in] uint64_t uiTimestamp. 211 */ 212 SET_UI_TIMESTAMP, 213 /** 214 * get native window bufferqueue size, 215 * variable parameter in function is 216 * [out] int32_t *size. 217 * @since 12 218 */ 219 GET_BUFFERQUEUE_SIZE, 220 /** 221 * set surface source type, 222 * variable parameter in function is 223 * [in] int32_t sourceType, the enumeration value refers to {@link OHSurfaceSource}. 224 * @since 12 225 */ 226 SET_SOURCE_TYPE, 227 /** 228 * get surface source type, 229 * variable parameter in function is 230 * [out] int32_t *sourceType, the enumeration value refers to {@link OHSurfaceSource}. 231 * @since 12 232 */ 233 GET_SOURCE_TYPE, 234 /** 235 * set app framework type, 236 * variable parameter in function is 237 * [in] char* frameworkType. maximum length is 64 bytes, otherwise the setting fails. 238 * @since 12 239 */ 240 SET_APP_FRAMEWORK_TYPE, 241 /** 242 * get app framework type, 243 * variable parameter in function is 244 * [out] char** frameworkType. 245 * @since 12 246 */ 247 GET_APP_FRAMEWORK_TYPE, 248 /** 249 * set hdr white point brightness, 250 * variable parameter in function is 251 * [in] float brightness. the value range is 0.0f to 1.0f. 252 * @since 12 253 */ 254 SET_HDR_WHITE_POINT_BRIGHTNESS, 255 /** 256 * set sdr white point brightness, 257 * variable parameter in function is 258 * [in] float brightness. the value range is 0.0f to 1.0f. 259 * @since 12 260 */ 261 SET_SDR_WHITE_POINT_BRIGHTNESS, 262 /** 263 * Set native window buffer desiredPresentTimestamp, indicates the desired time to present the buffer.\n 264 * Which should be generated by std::chrono::steady_clock in nanoseconds.\n 265 * It is only effective when RenderService is the consumer.\n 266 * The buffer will wait until desiredPresentTimestamp is reached before being consumed and displayed.\n 267 * If multiple buffers reach desiredPresentTimestamp, the earlier buffer will be dropped.\n 268 * This Operation should be called before calling <b>OH_NativeWindow_NativeWindowFlushBuffer</b>.\n 269 * If desiredPresentTimestamp is greater than 1 second of the consumer-provided timestamp, 270 * the desiredPresentTimestamp will be ignored.\n 271 * Variable parameter in function is 272 * [in] int64_t desiredPresentTimestamp. 273 * @since 13 274 */ 275 SET_DESIRED_PRESENT_TIMESTAMP = 24, 276 } NativeWindowOperation; 277 278 /** 279 * @brief Indicates Scaling Mode. 280 * @since 9 281 * @deprecated(since = "10") 282 * @useinstead OHScalingModeV2 283 */ 284 typedef enum { 285 /** 286 * the window content is not updated until a buffer of 287 * the window size is received 288 */ 289 OH_SCALING_MODE_FREEZE = 0, 290 /** 291 * the buffer is scaled in two dimensions to match the window size 292 */ 293 OH_SCALING_MODE_SCALE_TO_WINDOW, 294 /** 295 * the buffer is uniformly scaled so that the smaller size of 296 * the buffer matches the window size 297 */ 298 OH_SCALING_MODE_SCALE_CROP, 299 /** 300 * the window is clipped to the size of the buffer's clipping rectangle 301 * pixels outside the clipping rectangle are considered fully transparent. 302 */ 303 OH_SCALING_MODE_NO_SCALE_CROP, 304 } OHScalingMode; 305 306 /** 307 * @brief Indicates Scaling Mode. 308 * @since 12 309 */ 310 typedef enum { 311 /** 312 * the window content is not updated until a buffer of 313 * the window size is received 314 */ 315 OH_SCALING_MODE_FREEZE_V2 = 0, 316 /** 317 * the buffer is scaled in two dimensions to match the window size 318 */ 319 OH_SCALING_MODE_SCALE_TO_WINDOW_V2, 320 /** 321 * the buffer is uniformly scaled so that the smaller size of 322 * the buffer matches the window size 323 */ 324 OH_SCALING_MODE_SCALE_CROP_V2, 325 /** 326 * the window is clipped to the size of the buffer's clipping rectangle 327 * pixels outside the clipping rectangle are considered fully transparent. 328 */ 329 OH_SCALING_MODE_NO_SCALE_CROP_V2, 330 /** 331 * Adapt to the buffer and scale proportionally to the buffer size. Prioritize displaying all buffer content. 332 * If the size is not the same as the window size, fill the unfilled area of the window with a background color. 333 */ 334 OH_SCALING_MODE_SCALE_FIT_V2, 335 } OHScalingModeV2; 336 337 /** 338 * @brief Enumerates the HDR metadata keys. 339 * @since 9 340 * @deprecated(since = "10") 341 */ 342 typedef enum { 343 OH_METAKEY_RED_PRIMARY_X = 0, 344 OH_METAKEY_RED_PRIMARY_Y = 1, 345 OH_METAKEY_GREEN_PRIMARY_X = 2, 346 OH_METAKEY_GREEN_PRIMARY_Y = 3, 347 OH_METAKEY_BLUE_PRIMARY_X = 4, 348 OH_METAKEY_BLUE_PRIMARY_Y = 5, 349 OH_METAKEY_WHITE_PRIMARY_X = 6, 350 OH_METAKEY_WHITE_PRIMARY_Y = 7, 351 OH_METAKEY_MAX_LUMINANCE = 8, 352 OH_METAKEY_MIN_LUMINANCE = 9, 353 OH_METAKEY_MAX_CONTENT_LIGHT_LEVEL = 10, 354 OH_METAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11, 355 OH_METAKEY_HDR10_PLUS = 12, 356 OH_METAKEY_HDR_VIVID = 13, 357 } OHHDRMetadataKey; 358 359 /** 360 * @brief Defines the HDR metadata. 361 * @since 9 362 * @deprecated(since = "10") 363 */ 364 typedef struct { 365 OHHDRMetadataKey key; 366 float value; 367 } OHHDRMetaData; 368 369 /** 370 * @brief Defines the ExtData Handle 371 * @since 9 372 * @deprecated(since = "10") 373 */ 374 typedef struct OHExtDataHandle { 375 /**< Handle fd, -1 if not supported */ 376 int32_t fd; 377 /**< the number of reserved integer value */ 378 uint32_t reserveInts; 379 /**< the reserved data */ 380 int32_t reserve[0]; 381 } OHExtDataHandle; 382 383 /** 384 * @brief Indicates the source type of surface. 385 * @since 12 386 */ 387 typedef enum { 388 /* 389 * the default source type of surface. 390 */ 391 OH_SURFACE_SOURCE_DEFAULT = 0, 392 /* 393 * the surface is created by ui. 394 */ 395 OH_SURFACE_SOURCE_UI, 396 /* 397 * the surface is created by game. 398 */ 399 OH_SURFACE_SOURCE_GAME, 400 /* 401 * the surface is created by camera. 402 */ 403 OH_SURFACE_SOURCE_CAMERA, 404 /* 405 * the surface is created by video. 406 */ 407 OH_SURFACE_SOURCE_VIDEO, 408 } OHSurfaceSource; 409 410 /** 411 * @brief Creates a <b>OHNativeWindow</b> instance. A new <b>OHNativeWindow</b> instance is created each time this function is called. 412 * 413 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 414 * @param pSurface Indicates the pointer to a <b>ProduceSurface</b>. The type is a pointer to <b>sptr<OHOS::Surface></b>. 415 * @return Returns the pointer to the <b>OHNativeWindow</b> instance created. 416 * @since 8 417 * @version 1.0 418 * @deprecated since 12 419 */ 420 OHNativeWindow* OH_NativeWindow_CreateNativeWindow(void* pSurface); 421 422 /** 423 * @brief Decreases the reference count of a <b>OHNativeWindow</b> instance by 1, 424 * and when the reference count reaches 0, destroys the instance.\n 425 * This interface is a non-thread-safe type interface.\n 426 * 427 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 428 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 429 * @since 8 430 * @version 1.0 431 */ 432 void OH_NativeWindow_DestroyNativeWindow(OHNativeWindow* window); 433 434 /** 435 * @brief Creates a <b>OHNativeWindowBuffer</b> instance. A new <b>OHNativeWindowBuffer</b> instance is created each time this function is called. 436 * 437 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 438 * @param pSurfaceBuffer Indicates the pointer to a produce buffer. The type is <b>sptr<OHOS::SurfaceBuffer></b>. 439 * @return Returns the pointer to the <b>OHNativeWindowBuffer</b> instance created. 440 * @since 8 441 * @version 1.0 442 * @deprecated since 12 443 * @useinstead OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer 444 */ 445 OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer); 446 447 /** 448 * @brief Creates a <b>OHNativeWindowBuffer</b> instance.\n 449 * A new <b>OHNativeWindowBuffer</b> instance is created each time this function is called.\n 450 * This interface needs to be used in conjunction with <b>OH_NativeWindow_DestroyNativeWindowBuffer</b>, 451 * otherwise memory leaks will occur.\n 452 * This interface is a non-thread-safe type interface.\n 453 * 454 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 455 * @param nativeBuffer Indicates the pointer to a native buffer. The type is <b>OH_NativeBuffer*</b>. 456 * @return Returns the pointer to the <b>OHNativeWindowBuffer</b> instance created. 457 * @since 11 458 * @version 1.0 459 */ 460 OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromNativeBuffer(OH_NativeBuffer* nativeBuffer); 461 462 /** 463 * @brief Decreases the reference count of a <b>OHNativeWindowBuffer</b> instance by 1 and, 464 * when the reference count reaches 0, destroys the instance.\n 465 * This interface is a non-thread-safe type interface.\n 466 * 467 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 468 * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance. 469 * @since 8 470 * @version 1.0 471 */ 472 void OH_NativeWindow_DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer); 473 474 /** 475 * @brief Requests a <b>OHNativeWindowBuffer</b> through a <b>OHNativeWindow</b> instance for content production.\n 476 * Before calling this interface, you need to set the width and height of 477 * <b>OHNativeWindow</b> through <b>SET_BUFFER_GEOMETRY</b>.\n 478 * This interface needs to be used in conjunction with <b>OH_NativeWindow_NativeWindowFlushBuffer</b>, 479 * otherwise buffer will be exhausted.\n 480 * When the fenceFd is used up, you need to close it.\n 481 * This interface is a non-thread-safe type interface.\n 482 * 483 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 484 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 485 * @param buffer Indicates the double pointer to a <b>OHNativeWindowBuffer</b> instance. 486 * @param fenceFd Indicates the pointer to a file descriptor handle. 487 * @return Returns an error code, 0 is success, otherwise, failed. 488 * @since 8 489 * @version 1.0 490 */ 491 int32_t OH_NativeWindow_NativeWindowRequestBuffer(OHNativeWindow *window, 492 OHNativeWindowBuffer **buffer, int *fenceFd); 493 494 /** 495 * @brief Flushes the <b>OHNativeWindowBuffer</b> filled with the content to the buffer queue 496 * through a <b>OHNativeWindow</b> instance for content consumption.\n 497 * The fenceFd will be close by system.\n 498 * This interface is a non-thread-safe type interface.\n 499 * 500 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 501 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 502 * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance. 503 * @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization. 504 * @param region Indicates a dirty region where content is updated. 505 * @return Returns an error code, 0 is success, otherwise, failed. 506 * @since 8 507 * @version 1.0 508 */ 509 int32_t OH_NativeWindow_NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer, 510 int fenceFd, Region region); 511 512 /** 513 * @brief Get the last flushed <b>OHNativeWindowBuffer</b> from a <b>OHNativeWindow</b> instance. 514 * 515 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 516 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 517 * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> pointer. 518 * @param fenceFd Indicates the pointer to a file descriptor handle. 519 * @param matrix Indicates the retrieved 4*4 transform matrix. 520 * @return Returns an error code, 0 is success, otherwise, failed. 521 * @since 11 522 * @version 1.0 523 * @deprecated since 12 524 * @useinstead OH_NativeWindow_GetLastFlushedBufferV2 525 */ 526 int32_t OH_NativeWindow_GetLastFlushedBuffer(OHNativeWindow *window, OHNativeWindowBuffer **buffer, 527 int *fenceFd, float matrix[16]); 528 529 /** 530 * @brief Returns the <b>OHNativeWindowBuffer</b> to the buffer queue through a <b>OHNativeWindow</b> instance, 531 * without filling in any content. The <b>OHNativeWindowBuffer</b> can be used for another request.\n 532 * This interface is a non-thread-safe type interface.\n 533 * 534 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 535 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 536 * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance. 537 * @return Returns an error code, 0 is success, otherwise, failed. 538 * @since 8 539 * @version 1.0 540 */ 541 int32_t OH_NativeWindow_NativeWindowAbortBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer); 542 543 /** 544 * @brief Sets or obtains the attributes of a native window, including the width, height, and content format.\n 545 * This interface is a non-thread-safe type interface.\n 546 * 547 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 548 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 549 * @param code Indicates the operation code, pointer to <b>NativeWindowOperation</b>. 550 * @param ... variable parameter, must correspond to code one-to-one. 551 * @return Returns an error code, 0 is success, otherwise, failed. 552 * @since 8 553 * @version 1.0 554 */ 555 int32_t OH_NativeWindow_NativeWindowHandleOpt(OHNativeWindow *window, int code, ...); 556 557 /** 558 * @brief Obtains the pointer to a <b>BufferHandle</b> of a <b>OHNativeWindowBuffer</b> instance.\n 559 * This interface is a non-thread-safe type interface.\n 560 * 561 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 562 * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance. 563 * @return Returns the pointer to the <b>BufferHandle</b> instance obtained. 564 * @since 8 565 * @version 1.0 566 */ 567 BufferHandle *OH_NativeWindow_GetBufferHandleFromNative(OHNativeWindowBuffer *buffer); 568 569 /** 570 * @brief Adds the reference count of a native object.\n 571 * This interface needs to be used in conjunction with <b>OH_NativeWindow_NativeObjectUnreference</b>, 572 * otherwise memory leaks will occur.\n 573 * This interface is a non-thread-safe type interface.\n 574 * 575 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 576 * @param obj Indicates the pointer to a <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance. 577 * @return Returns an error code, 0 is success, otherwise, failed. 578 * @since 8 579 * @version 1.0 580 */ 581 int32_t OH_NativeWindow_NativeObjectReference(void *obj); 582 583 /** 584 * @brief Decreases the reference count of a native object and, 585 * when the reference count reaches 0, destroys this object.\n 586 * This interface is a non-thread-safe type interface.\n 587 * 588 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 589 * @param obj Indicates the pointer to a <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance. 590 * @return Returns an error code, 0 is success, otherwise, failed. 591 * @since 8 592 * @version 1.0 593 */ 594 int32_t OH_NativeWindow_NativeObjectUnreference(void *obj); 595 596 /** 597 * @brief Obtains the magic ID of a native object.\n 598 * This interface is a non-thread-safe type interface.\n 599 * 600 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 601 * @param obj Indicates the pointer to a <b>OHNativeWindow</b> or <b>OHNativeWindowBuffer</b> instance. 602 * @return Returns the magic ID, which is unique for each native object. 603 * @since 8 604 * @version 1.0 605 */ 606 int32_t OH_NativeWindow_GetNativeObjectMagic(void *obj); 607 608 /** 609 * @brief Sets scalingMode of a native window. 610 * 611 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 612 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 613 * @param sequence Indicates the sequence to a produce buffer. 614 * @param scalingMode Indicates the enum value to <b>OHScalingMode</b> 615 * @return Returns an error code, 0 is success, otherwise, failed. 616 * @since 9 617 * @version 1.0 618 * @deprecated(since = "10") 619 * @useinstead OH_NativeWindow_NativeWindowSetScalingModeV2 620 */ 621 int32_t OH_NativeWindow_NativeWindowSetScalingMode(OHNativeWindow *window, uint32_t sequence, 622 OHScalingMode scalingMode); 623 624 /** 625 * @brief Sets metaData of a native window. 626 * 627 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 628 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 629 * @param sequence Indicates the sequence to a produce buffer. 630 * @param size Indicates the size of a <b>OHHDRMetaData</b> vector. 631 * @param metaDate Indicates the pointer to a <b>OHHDRMetaData</b> vector. 632 * @return Returns an error code, 0 is success, otherwise, failed. 633 * @since 9 634 * @version 1.0 635 * @deprecated(since = "10") 636 */ 637 int32_t OH_NativeWindow_NativeWindowSetMetaData(OHNativeWindow *window, uint32_t sequence, int32_t size, 638 const OHHDRMetaData *metaData); 639 640 /** 641 * @brief Sets metaDataSet of a native window. 642 * 643 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 644 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 645 * @param sequence Indicates the sequence to a produce buffer. 646 * @param key Indicates the enum value to <b>OHHDRMetadataKey</b> 647 * @param size Indicates the size of a uint8_t vector. 648 * @param metaDate Indicates the pointer to a uint8_t vector. 649 * @return Returns an error code, 0 is success, otherwise, failed. 650 * @since 9 651 * @version 1.0 652 * @deprecated(since = "10") 653 */ 654 int32_t OH_NativeWindow_NativeWindowSetMetaDataSet(OHNativeWindow *window, uint32_t sequence, OHHDRMetadataKey key, 655 int32_t size, const uint8_t *metaData); 656 657 /** 658 * @brief Sets tunnel handle of a native window. 659 * 660 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 661 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 662 * @param handle Indicates the pointer to a <b>OHExtDataHandle</b>. 663 * @return Returns an error code, 0 is success, otherwise, failed. 664 * @since 9 665 * @version 1.0 666 * @deprecated(since = "10") 667 */ 668 int32_t OH_NativeWindow_NativeWindowSetTunnelHandle(OHNativeWindow *window, const OHExtDataHandle *handle); 669 670 /** 671 * @brief Attach a buffer to an <b>OHNativeWindow</b> instance.\n 672 * This interface needs to be used in conjunction with <b>OH_NativeWindow_NativeWindowDetachBuffer</b>, 673 * otherwise buffer management will be chaotic.\n 674 * This interface is a non-thread-safe type interface.\n 675 * 676 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 677 * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance. 678 * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance. 679 * @return Returns an error code, 0 is success, otherwise, failed. 680 * @since 12 681 * @version 1.0 682 */ 683 int32_t OH_NativeWindow_NativeWindowAttachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer); 684 685 /** 686 * @brief Detach a buffer from an <b>OHNativeWindow</b> instance.\n 687 * This interface is a non-thread-safe type interface.\n 688 * 689 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 690 * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance. 691 * @param buffer Indicates the pointer to a <b>OHNativeWindowBuffer</b> instance. 692 * @return Returns an error code, 0 is success, otherwise, failed. 693 * @since 12 694 * @version 1.0 695 */ 696 int32_t OH_NativeWindow_NativeWindowDetachBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer); 697 698 /** 699 * @brief Get surfaceId from native window.\n 700 * This interface is a non-thread-safe type interface.\n 701 * 702 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 703 * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance. 704 * @param surfaceId Indicates the pointer to a surfaceId. 705 * @return Returns an error code, 0 is success, otherwise, failed. 706 * @since 12 707 * @version 1.0 708 */ 709 int32_t OH_NativeWindow_GetSurfaceId(OHNativeWindow *window, uint64_t *surfaceId); 710 711 /** 712 * @brief Creates an <b>OHNativeWindow</b> instance.\n 713 * This interface needs to be used in conjunction with <b>OH_NativeWindow_DestroyNativeWindow</b>, 714 * otherwise memory leaks will occur.\n 715 * If there is a concurrent destroy OHNativeWindow, you need to add once and decrement once to the 716 * OHNativeWindow reference count through <b>OH_NativeWindow_NativeObjectReference</b> and 717 * <b>OH_NativeWindow_NativeObjectUnreference</b>.\n 718 * If the surface obtained through surfaceId is created in this process, the surface cannot be obtained 719 * across processes.\n 720 * This interface is a non-thread-safe type interface.\n 721 * 722 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 723 * @param surfaceId Indicates the surfaceId to a surface. 724 * @param window indicates the pointer to an <b>OHNativeWindow</b> instance. 725 * @return Returns an error code, 0 is Success, otherwise, failed. 726 * @since 12 727 * @version 1.0 728 */ 729 int32_t OH_NativeWindow_CreateNativeWindowFromSurfaceId(uint64_t surfaceId, OHNativeWindow **window); 730 731 /** 732 * @brief Sets scalingMode of a native window.\n 733 * This interface is a non-thread-safe type interface.\n 734 * 735 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 736 * @param window indicates the pointer to an <b>OHNativeWindow</b> instance. 737 * @param scalingMode Indicates the enum value to <b>OHScalingModeV2</b> 738 * @return Returns an error code, 0 is Success, otherwise, failed. 739 * @since 12 740 * @version 1.0 741 */ 742 int32_t OH_NativeWindow_NativeWindowSetScalingModeV2(OHNativeWindow *window, OHScalingModeV2 scalingMode); 743 744 /** 745 * @brief Set native window buffer hold.\n 746 * This interface is a non-thread-safe type interface.\n 747 * 748 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 749 * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance. 750 * @since 12 751 * @version 1.0 752 */ 753 void OH_NativeWindow_SetBufferHold(OHNativeWindow *window); 754 755 /** 756 * @brief Write an OHNativeWindow to an OHIPCParcel.\n 757 * This interface is a non-thread-safe type interface.\n 758 * 759 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 760 * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance. 761 * @param parcel Indicates the pointer to an <b>OHIPCParcel</b> instance. 762 * @return {@link NATIVE_ERROR_OK} 0 - Success. 763 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - parcel is NULL or window is NULL. 764 * @since 12 765 * @version 1.0 766 */ 767 int32_t OH_NativeWindow_WriteToParcel(OHNativeWindow *window, OHIPCParcel *parcel); 768 769 /** 770 * @brief Read an OHNativeWindow from an OHIPCParcel.\n 771 * This interface is a non-thread-safe type interface.\n 772 * 773 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 774 * @param parcel Indicates the pointer to an <b>OHIPCParcel</b> instance. 775 * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance. 776 * @return {@link NATIVE_ERROR_OK} 0 - Success. 777 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - parcel is NULL or parcel does not contain the window. 778 * @since 12 779 * @version 1.0 780 */ 781 int32_t OH_NativeWindow_ReadFromParcel(OHIPCParcel *parcel, OHNativeWindow **window); 782 783 /** 784 * @brief Get the last flushed <b>OHNativeWindowBuffer</b> from an <b>OHNativeWindow</b> instance.\n 785 * When the fenceFd is used up, you need to close it.\n 786 * This interface needs to be used in conjunction with <b>OH_NativeWindow_NativeObjectUnreference</b>, 787 * otherwise memory leaks will occur.\n 788 * This interface is a non-thread-safe type interface.\n 789 * 790 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 791 * @param window Indicates the pointer to an <b>OHNativeWindow</b> instance. 792 * @param buffer Indicates the pointer to an <b>OHNativeWindowBuffer</b> pointer. 793 * @param fenceFd Indicates the pointer to a file descriptor handle. 794 * @param matrix Indicates the retrieved 4*4 transform matrix. 795 * @return {@link NATIVE_ERROR_OK} 0 - Success. 796 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window is NULL or buffer is NULL or fenceFd is NULL. 797 * {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - buffer state is wrong. 798 * @since 12 799 * @version 1.0 800 */ 801 802 int32_t OH_NativeWindow_GetLastFlushedBufferV2(OHNativeWindow *window, OHNativeWindowBuffer **buffer, 803 int *fenceFd, float matrix[16]); 804 /** 805 * @brief Set the color space of the native window.\n 806 * This interface is a non-thread-safe type interface.\n 807 * 808 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 809 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 810 * @param colorSpace Indicates the color space of native window, see <b>OH_NativeBuffer_ColorSpace</b>. 811 * @return {@link NATIVE_ERROR_OK} 0 - Success. 812 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window is NULL. 813 * {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect colorSpace state. 814 * @since 12 815 * @version 1.0 816 */ 817 int32_t OH_NativeWindow_SetColorSpace(OHNativeWindow *window, OH_NativeBuffer_ColorSpace colorSpace); 818 819 /** 820 * @brief Get the color space of the native window.\n 821 * This interface is a non-thread-safe type interface.\n 822 * 823 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 824 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 825 * @param colorSpace Indicates the color space of native window, see <b>OH_NativeBuffer_ColorSpace</b>. 826 * @return {@link NATIVE_ERROR_OK} 0 - Success. 827 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window is NULL. 828 * {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect colorSpace state. 829 * @since 12 830 * @version 1.0 831 */ 832 int32_t OH_NativeWindow_GetColorSpace(OHNativeWindow *window, OH_NativeBuffer_ColorSpace *colorSpace); 833 834 /** 835 * @brief Set the metadata type of the native window.\n 836 * This interface is a non-thread-safe type interface.\n 837 * 838 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 839 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 840 * @param metadataKey Indicates the metadata type of native window, see <b>OH_NativeBuffer_MetadataKey</b>. 841 * @param size Indicates the size of a uint8_t vector. 842 * @param metadata Indicates the pointer to a uint8_t vector. 843 * @return {@link NATIVE_ERROR_OK} 0 - Success. 844 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window or metadata is NULL. 845 * {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect metadata state. 846 * {@link NATIVE_ERROR_UNSUPPORTED} 50102000 - Unsupported metadata key. 847 * @since 12 848 * @version 1.0 849 */ 850 int32_t OH_NativeWindow_SetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey, 851 int32_t size, uint8_t *metadata); 852 853 /** 854 * @brief Set the metadata type of the native window.\n 855 * This interface is a non-thread-safe type interface.\n 856 * 857 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 858 * @param window Indicates the pointer to a <b>OHNativeWindow</b> instance. 859 * @param metadataKey Indicates the metadata type of native window, see <b>OH_NativeBuffer_MetadataKey</b>. 860 * @param size Indicates the size of a uint8_t vector. 861 * @param metadata Indicates the pointer to a uint8_t vector. 862 * @return {@link NATIVE_ERROR_OK} 0 - Success. 863 * {@link NATIVE_ERROR_INVALID_ARGUMENTS} 40001000 - window, metadata, or size is NULL. 864 * {@link NATIVE_ERROR_BUFFER_STATE_INVALID} 41207000 - Incorrect metadata state. 865 * {@link NATIVE_ERROR_UNSUPPORTED} 50102000 - Unsupported metadata key. 866 * @since 12 867 * @version 1.0 868 */ 869 int32_t OH_NativeWindow_GetMetadataValue(OHNativeWindow *window, OH_NativeBuffer_MetadataKey metadataKey, 870 int32_t *size, uint8_t **metadata); 871 #ifdef __cplusplus 872 } 873 #endif 874 875 /** @} */ 876 #endif