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 #ifndef NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_ 17 #define NDK_INCLUDE_EXTERNAL_NATIVE_WINDOW_H_ 18 19 /** 20 * @addtogroup NativeWindow 21 * @{ 22 * 23 * @brief Provides the native window capability for connection to the EGL. 24 * 25 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 26 * @since 8 27 * @version 1.0 28 */ 29 30 /** 31 * @file external_window.h 32 * 33 * @brief Defines the functions for obtaining and using a native window. 34 * 35 * @since 8 36 * @version 1.0 37 */ 38 39 #include <stdint.h> 40 #include "buffer_handle.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /** 47 * @brief native window. 48 */ 49 struct NativeWindow; 50 51 /** 52 * @brief native window buffer. 53 */ 54 struct NativeWindowBuffer; 55 56 /** 57 * @brief define the new type name OHNativeWindow for struct NativeWindow. 58 */ 59 typedef struct NativeWindow OHNativeWindow; 60 61 /** 62 * @brief define the new type name OHNativeWindowBuffer for struct NativeWindowBuffer. 63 */ 64 typedef struct NativeWindowBuffer OHNativeWindowBuffer; 65 66 /** 67 * @brief indicates a dirty region where content is updated. 68 */ 69 typedef struct Region { 70 /** if rects is nullptr, fill the Buffer dirty size by default */ 71 struct Rect { 72 int32_t x; 73 int32_t y; 74 uint32_t w; 75 uint32_t h; 76 } *rects; 77 /** if rectNumber is 0, fill the Buffer dirty size by default */ 78 int32_t rectNumber; 79 }Region; 80 81 82 /** 83 * @brief Indicates the operation code in the function OH_NativeWindow_NativeWindowHandleOpt. 84 */ 85 enum NativeWindowOperation { 86 /** 87 * set native window buffer geometry, 88 * variable parameter in function is 89 * [in] int32_t height, [in] int32_t width 90 */ 91 SET_BUFFER_GEOMETRY, 92 /** 93 * get native window buffer geometry, 94 * variable parameter in function is 95 * [out] int32_t *height, [out] int32_t *width 96 */ 97 GET_BUFFER_GEOMETRY, 98 /** 99 * get native window buffer format, 100 * variable parameter in function is 101 * [out] int32_t *format 102 */ 103 GET_FORMAT, 104 /** 105 * set native window buffer format, 106 * variable parameter in function is 107 * [in] int32_t format 108 */ 109 SET_FORMAT, 110 /** 111 * get native window buffer usage, 112 * variable parameter in function is 113 * [out] int32_t *usage. 114 */ 115 GET_USAGE, 116 /** 117 * set native window buffer usage, 118 * variable parameter in function is 119 * [in] int32_t usage. 120 */ 121 SET_USAGE, 122 /** 123 * set native window buffer stride, 124 * variable parameter in function is 125 * [in] int32_t stride. 126 */ 127 SET_STRIDE, 128 /** 129 * get native window buffer stride, 130 * variable parameter in function is 131 * [out] int32_t *stride. 132 */ 133 GET_STRIDE, 134 /** 135 * set native window buffer swap interval, 136 * variable parameter in function is 137 * [in] int32_t interval. 138 */ 139 SET_SWAP_INTERVAL, 140 /** 141 * get native window buffer swap interval, 142 * variable parameter in function is 143 * [out] int32_t *interval. 144 */ 145 GET_SWAP_INTERVAL, 146 /** 147 * set native window buffer timeout, 148 * variable parameter in function is 149 * [in] int32_t timeout. 150 */ 151 SET_TIMEOUT, 152 /** 153 * get native window buffer timeout, 154 * variable parameter in function is 155 * [out] int32_t *timeout. 156 */ 157 GET_TIMEOUT, 158 /** 159 * set native window buffer colorGamut, 160 * variable parameter in function is 161 * [in] int32_t colorGamut. 162 */ 163 SET_COLOR_GAMUT, 164 /** 165 * get native window buffer colorGamut, 166 * variable parameter in function is 167 * [out int32_t *colorGamut]. 168 */ 169 GET_COLOR_GAMUT, 170 /** 171 * set native window buffer transform, 172 * variable parameter in function is 173 * [in] int32_t transform. 174 */ 175 SET_TRANSFORM, 176 /** 177 * get native window buffer transform, 178 * variable parameter in function is 179 * [out] int32_t *transform. 180 */ 181 GET_TRANSFORM, 182 /** 183 * set native window buffer uiTimestamp, 184 * variable parameter in function is 185 * [in] uint64_t uiTimestamp. 186 */ 187 SET_UI_TIMESTAMP, 188 }; 189 190 /** 191 * @brief Indicates Scaling Mode. 192 */ 193 typedef enum { 194 /** 195 * the window content is not updated until a buffer of 196 * the window size is received 197 */ 198 OH_SCALING_MODE_FREEZE = 0, 199 /** 200 * the buffer is scaled in two dimensions to match the window size 201 */ 202 OH_SCALING_MODE_SCALE_TO_WINDOW, 203 /** 204 * the buffer is uniformly scaled so that the smaller size of 205 * the buffer matches the window size 206 */ 207 OH_SCALING_MODE_SCALE_CROP, 208 /** 209 * the window is clipped to the size of the buffer's clipping rectangle 210 * pixels outside the clipping rectangle are considered fully transparent. 211 */ 212 OH_SCALING_MODE_NO_SCALE_CROP, 213 } OHScalingMode; 214 215 /** 216 * @brief Enumerates the HDR metadata keys. 217 */ 218 typedef enum { 219 OH_METAKEY_RED_PRIMARY_X = 0, 220 OH_METAKEY_RED_PRIMARY_Y = 1, 221 OH_METAKEY_GREEN_PRIMARY_X = 2, 222 OH_METAKEY_GREEN_PRIMARY_Y = 3, 223 OH_METAKEY_BLUE_PRIMARY_X = 4, 224 OH_METAKEY_BLUE_PRIMARY_Y = 5, 225 OH_METAKEY_WHITE_PRIMARY_X = 6, 226 OH_METAKEY_WHITE_PRIMARY_Y = 7, 227 OH_METAKEY_MAX_LUMINANCE = 8, 228 OH_METAKEY_MIN_LUMINANCE = 9, 229 OH_METAKEY_MAX_CONTENT_LIGHT_LEVEL = 10, 230 OH_METAKEY_MAX_FRAME_AVERAGE_LIGHT_LEVEL = 11, 231 OH_METAKEY_HDR10_PLUS = 12, 232 OH_METAKEY_HDR_VIVID = 13, 233 } OHHDRMetadataKey; 234 235 /** 236 * @brief Defines the HDR metadata. 237 */ 238 typedef struct { 239 OHHDRMetadataKey key; 240 float value; 241 } OHHDRMetaData; 242 243 /** 244 * @brief Defines the ExtData Handle 245 */ 246 typedef struct { 247 /**< Handle fd, -1 if not supported */ 248 int32_t fd; 249 /**< the number of reserved integer value */ 250 uint32_t reserveInts; 251 /**< the reserved data */ 252 int32_t reserve[0]; 253 } OHExtDataHandle; 254 255 /** 256 * @brief Creates a <b>NativeWindow</b> instance. A new <b>NativeWindow</b> instance is created each time this function is called. 257 * 258 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 259 * @param pSurface Indicates the pointer to a <b>ProduceSurface</b>. The type is a pointer to <b>sptr<OHOS::Surface></b>. 260 * @return Returns the pointer to the <b>NativeWindow</b> instance created. 261 * @since 8 262 * @version 1.0 263 */ 264 OHNativeWindow* OH_NativeWindow_CreateNativeWindow(void* pSurface); 265 266 /** 267 * @brief Decreases the reference count of a <b>NativeWindow</b> instance by 1, and when the reference count reaches 0, destroys the instance. 268 * 269 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 270 * @param window Indicates the pointer to a <b>NativeWindow</b> instance. 271 * @since 8 272 * @version 1.0 273 */ 274 void OH_NativeWindow_DestroyNativeWindow(OHNativeWindow* window); 275 276 /** 277 * @brief Creates a <b>NativeWindowBuffer</b> instance. A new <b>NativeWindowBuffer</b> instance is created each time this function is called. 278 * 279 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 280 * @param pSurfaceBuffer Indicates the pointer to a produce buffer. The type is <b>sptr<OHOS::SurfaceBuffer></b>. 281 * @return Returns the pointer to the <b>NativeWindowBuffer</b> instance created. 282 * @since 8 283 * @version 1.0 284 */ 285 OHNativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer(void* pSurfaceBuffer); 286 287 /** 288 * @brief Decreases the reference count of a <b>NativeWindowBuffer</b> instance by 1 and, when the reference count reaches 0, destroys the instance. 289 * 290 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 291 * @param buffer Indicates the pointer to a <b>NativeWindowBuffer</b> instance. 292 * @since 8 293 * @version 1.0 294 */ 295 void OH_NativeWindow_DestroyNativeWindowBuffer(OHNativeWindowBuffer* buffer); 296 297 /** 298 * @brief Requests a <b>NativeWindowBuffer</b> through a <b>NativeWindow</b> instance for content production. 299 * 300 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 301 * @param window Indicates the pointer to a <b>NativeWindow</b> instance. 302 * @param buffer Indicates the double pointer to a <b>NativeWindowBuffer</b> instance. 303 * @param fenceFd Indicates the pointer to a file descriptor handle. 304 * @return Returns an error code defined in <b>GSError</b>. 305 * @since 8 306 * @version 1.0 307 */ 308 int32_t OH_NativeWindow_NativeWindowRequestBuffer(OHNativeWindow *window, 309 OHNativeWindowBuffer **buffer, int *fenceFd); 310 311 /** 312 * @brief Flushes the <b>NativeWindowBuffer</b> filled with the content to the buffer queue through a <b>NativeWindow</b> instance for content consumption. 313 * 314 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 315 * @param window Indicates the pointer to a <b>NativeWindow</b> instance. 316 * @param buffer Indicates the pointer to a <b>NativeWindowBuffer</b> instance. 317 * @param fenceFd Indicates a file descriptor handle, which is used for timing synchronization. 318 * @param region Indicates a dirty region where content is updated. 319 * @return Returns an error code defined in <b>GSError</b>. 320 * @since 8 321 * @version 1.0 322 */ 323 int32_t OH_NativeWindow_NativeWindowFlushBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer, 324 int fenceFd, Region region); 325 326 /** 327 * @brief Returns the <b>NativeWindowBuffer</b> to the buffer queue through a <b>NativeWindow</b> instance, without filling in any content. The <b>NativeWindowBuffer</b> can be used for another request. 328 * 329 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 330 * @param window Indicates the pointer to a <b>NativeWindow</b> instance. 331 * @param buffer Indicates the pointer to a <b>NativeWindowBuffer</b> instance. 332 * @return Returns an error code defined in <b>GSError</b>. 333 * @since 8 334 * @version 1.0 335 */ 336 int32_t OH_NativeWindow_NativeWindowAbortBuffer(OHNativeWindow *window, OHNativeWindowBuffer *buffer); 337 338 /** 339 * @brief Sets or obtains the attributes of a native window, including the width, height, and content format. 340 * 341 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 342 * @param window Indicates the pointer to a <b>NativeWindow</b> instance. 343 * @param code Indicates the operation code, pointer to <b>NativeWindowOperation</b>. 344 * @param ... variable parameter, must correspond to code one-to-one. 345 * @return Returns an error code defined in <b>GSError</b>. 346 * @since 8 347 * @version 1.0 348 */ 349 int32_t OH_NativeWindow_NativeWindowHandleOpt(OHNativeWindow *window, int code, ...); 350 351 /** 352 * @brief Obtains the pointer to a <b>BufferHandle</b> of a <b>NativeWindowBuffer</b> instance. 353 * 354 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 355 * @param buffer Indicates the pointer to a <b>NativeWindowBuffer</b> instance. 356 * @return Returns the pointer to the <b>BufferHandle</b> instance obtained. 357 * @since 8 358 * @version 1.0 359 */ 360 BufferHandle *OH_NativeWindow_GetBufferHandleFromNative(OHNativeWindowBuffer *buffer); 361 362 /** 363 * @brief Adds the reference count of a native object. 364 * 365 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 366 * @param obj Indicates the pointer to a <b>NativeWindow</b> or <b>NativeWindowBuffer</b> instance. 367 * @return Returns an error code defined in <b>GSError</b>. 368 * @since 8 369 * @version 1.0 370 */ 371 int32_t OH_NativeWindow_NativeObjectReference(void *obj); 372 373 /** 374 * @brief Decreases the reference count of a native object and, when the reference count reaches 0, destroys this object. 375 * 376 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 377 * @param obj Indicates the pointer to a <b>NativeWindow</b> or <b>NativeWindowBuffer</b> instance. 378 * @return Returns an error code defined in <b>GSError</b>. 379 * @since 8 380 * @version 1.0 381 */ 382 int32_t OH_NativeWindow_NativeObjectUnreference(void *obj); 383 384 /** 385 * @brief Obtains the magic ID of a native object. 386 * 387 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 388 * @param obj Indicates the pointer to a <b>NativeWindow</b> or <b>NativeWindowBuffer</b> instance. 389 * @return Returns the magic ID, which is unique for each native object. 390 * @since 8 391 * @version 1.0 392 */ 393 int32_t OH_NativeWindow_GetNativeObjectMagic(void *obj); 394 395 /** 396 * @brief Sets scalingMode of a native window. 397 * 398 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 399 * @param window Indicates the pointer to a <b>NativeWindow</b> instance. 400 * @param sequence Indicates the sequence to a produce buffer. 401 * @param scalingMode Indicates the enum value to <b>OHScalingMode</b> 402 * @return Returns an error code defined in <b>GSError</b>. 403 * @since 9 404 * @version 1.0 405 */ 406 int32_t OH_NativeWindow_NativeWindowSetScalingMode(OHNativeWindow *window, uint32_t sequence, 407 OHScalingMode scalingMode); 408 409 /** 410 * @brief Sets metaData of a native window. 411 * 412 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 413 * @param window Indicates the pointer to a <b>NativeWindow</b> instance. 414 * @param sequence Indicates the sequence to a produce buffer. 415 * @param size Indicates the size of a <b>OHHDRMetaData</b> vector. 416 * @param metaDate Indicates the pointer to a <b>OHHDRMetaData</b> vector. 417 * @return Returns an error code defined in <b>GSError</b>. 418 * @since 9 419 * @version 1.0 420 */ 421 int32_t OH_NativeWindow_NativeWindowSetMetaData(OHNativeWindow *window, uint32_t sequence, int32_t size, 422 const OHHDRMetaData *metaData); 423 424 /** 425 * @brief Sets metaDataSet of a native window. 426 * 427 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 428 * @param window Indicates the pointer to a <b>NativeWindow</b> instance. 429 * @param sequence Indicates the sequence to a produce buffer. 430 * @param key Indicates the enum value to <b>OHHDRMetadataKey</b> 431 * @param size Indicates the size of a uint8_t vector. 432 * @param metaDate Indicates the pointer to a uint8_t vector. 433 * @return Returns an error code defined in <b>GSError</b>. 434 * @since 9 435 * @version 1.0 436 */ 437 int32_t OH_NativeWindow_NativeWindowSetMetaDataSet(OHNativeWindow *window, uint32_t sequence, OHHDRMetadataKey key, 438 int32_t size, const uint8_t *metaData); 439 440 /** 441 * @brief Sets tunnel handle of a native window. 442 * 443 * @syscap SystemCapability.Graphic.Graphic2D.NativeWindow 444 * @param window Indicates the pointer to a <b>NativeWindow</b> instance. 445 * @param handle Indicates the pointer to a <b>OHExtDataHandle</b>. 446 * @return Returns an error code defined in <b>GSError</b>. 447 * @since 9 448 * @version 1.0 449 */ 450 int32_t OH_NativeWindow_NativeWindowSetTunnelHandle(OHNativeWindow *window, const OHExtDataHandle *handle); 451 452 #ifdef __cplusplus 453 } 454 #endif 455 456 /** @} */ 457 #endif