1e41f4b71Sopenharmony_ci# NativeVsync 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciThe **NativeVsync** module provides the capabilities of native virtual synchronization (VSync). 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci\@syscap SystemCapability.Graphic.Graphic2D.NativeVsync 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci**Since** 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci9 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Summary 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci### Files 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci| Name| Description| 21e41f4b71Sopenharmony_ci| -------- | -------- | 22e41f4b71Sopenharmony_ci| [native_vsync.h](native__vsync_8h.md) | Declares the functions for obtaining and using native VSync.<br>**File to include**: <native_vsync/native_vsync.h><br>**Library**: libnative_vsync.so| 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci### Types 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci| Name| Description| 28e41f4b71Sopenharmony_ci| -------- | -------- | 29e41f4b71Sopenharmony_ci| typedef enum [OHNativeErrorCode](#ohnativeerrorcode) [OHNativeErrorCode](#ohnativeerrorcode) | Defines an enum for the error codes. | 30e41f4b71Sopenharmony_ci| typedef struct [OH_NativeVSync](#oh_nativevsync) [OH_NativeVSync](#oh_nativevsync) | Provides the declaration of an **OH_NativeVSync** struct. | 31e41f4b71Sopenharmony_ci| typedef void(\* [OH_NativeVSync_FrameCallback](#oh_nativevsync_framecallback)) (long long timestamp, void \*data) | Defines the pointer to a VSync callback function. | 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci### Enums 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Name| Description| 37e41f4b71Sopenharmony_ci| -------- | -------- | 38e41f4b71Sopenharmony_ci| [OHNativeErrorCode](#ohnativeerrorcode-1) {<br>NATIVE_ERROR_OK = 0, NATIVE_ERROR_INVALID_ARGUMENTS = 40001000, NATIVE_ERROR_NO_PERMISSION = 40301000, NATIVE_ERROR_NO_BUFFER = 40601000,<br>NATIVE_ERROR_NO_CONSUMER = 41202000, NATIVE_ERROR_NOT_INIT = 41203000, NATIVE_ERROR_CONSUMER_CONNECTED = 41206000, NATIVE_ERROR_BUFFER_STATE_INVALID = 41207000,<br>NATIVE_ERROR_BUFFER_IN_CACHE = 41208000, NATIVE_ERROR_BUFFER_QUEUE_FULL = 41209000, NATIVE_ERROR_BUFFER_NOT_IN_CACHE = 41210000,NATIVE_ERROR_CONSUMER_DISCONNECTED = 41211000,NATIVE_ERROR_CONSUMER_NO_LISTENER_REGISTERED = 41212000, NATIVE_ERROR_UNSUPPORTED = 50102000,<br>NATIVE_ERROR_UNKNOWN = 50002000,NATIVE_ERROR_HDI_ERROR = 50007000,NATIVE_ERROR_BINDER_ERROR = 50401000,<br>NATIVE_ERROR_EGL_STATE_UNKNOWN = 60001000, NATIVE_ERROR_EGL_API_FAILED = 60002000<br>} | Enumerates the error codes. | 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci### Functions 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci| Name| Description| 44e41f4b71Sopenharmony_ci| -------- | -------- | 45e41f4b71Sopenharmony_ci| [OH_NativeVSync_Create](#oh_nativevsync_create) (const char \*name, unsigned int length) | Creates an **OH_NativeVSync** instance. A new **OH_NativeVSync** instance is created each time this function is called.| 46e41f4b71Sopenharmony_ci| [OH_NativeVSync_Destroy](#oh_nativevsync_destroy) ([OH_NativeVSync](#oh_nativevsync) \*nativeVsync) | Destroys an **OH_NativeVSync** instance.| 47e41f4b71Sopenharmony_ci| int [OH_NativeVSync_RequestFrame](#oh_nativevsync_requestframe) ([OH_NativeVSync](#oh_nativevsync) \*nativeVsync, [OH_NativeVSync_FrameCallback](#oh_nativevsync_framecallback) callback, void \*data) | Requests the next VSync signal. When the signal arrives, a callback function is invoked. If this function is called for multiple times in the same frame, only the last callback function is invoked.| 48e41f4b71Sopenharmony_ci| int [OH_NativeVSync_RequestFrameWithMultiCallback](#oh_nativevsync_requestframewithmulticallback) ([OH_NativeVSync](#oh_nativevsync) \*nativeVsync, [OH_NativeVSync_FrameCallback](#oh_nativevsync_framecallback) callback, void \*data) | Requests the next VSync signal. When the signal arrives, a callback function is invoked. If this function is called for multiple times in the same frame, every callback function is invoked.| 49e41f4b71Sopenharmony_ci| [OH_NativeVSync_GetPeriod](#oh_nativevsync_getperiod) ([OH_NativeVSync](#oh_nativevsync) \*nativeVsync, long long \*period) |Obtains the VSync period.| 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci## Type Description 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci### OH_NativeVSync 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci``` 58e41f4b71Sopenharmony_citypedef struct OH_NativeVSync OH_NativeVSync 59e41f4b71Sopenharmony_ci``` 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**Description** 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ciProvides the declaration of an **OH_NativeVSync** struct. 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci### OH_NativeVSync_FrameCallback 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci``` 70e41f4b71Sopenharmony_citypedef void(* OH_NativeVSync_FrameCallback) (long long timestamp, void *data) 71e41f4b71Sopenharmony_ci``` 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci**Description** 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ciDefines the pointer to a VSync callback function. 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci\@syscap SystemCapability.Graphic.Graphic2D.NativeVsync 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**Parameters** 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci| Name| Description| 82e41f4b71Sopenharmony_ci| -------- | -------- | 83e41f4b71Sopenharmony_ci| timestamp | VSync timestamp.| 84e41f4b71Sopenharmony_ci| data | User-defined data.| 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci### OHNativeErrorCode 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci``` 90e41f4b71Sopenharmony_citypedef enum OHNativeErrorCode OHNativeErrorCode 91e41f4b71Sopenharmony_ci``` 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**Description** 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ciDefines an enum for the error codes. 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci**Since**: 12 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci## Enum Description 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci### OHNativeErrorCode 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci``` 106e41f4b71Sopenharmony_cienum OHNativeErrorCode 107e41f4b71Sopenharmony_ci``` 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**Description** 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ciEnumerates the error codes. 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**Since**: 12 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci| Value| Description| 116e41f4b71Sopenharmony_ci| -------- | -------- | 117e41f4b71Sopenharmony_ci| NATIVE_ERROR_OK | The operation is successful. | 118e41f4b71Sopenharmony_ci| NATIVE_ERROR_INVALID_ARGUMENTS | An input parameter is invalid. | 119e41f4b71Sopenharmony_ci| NATIVE_ERROR_NO_PERMISSION | You do not have the permission to perform the operation. | 120e41f4b71Sopenharmony_ci| NATIVE_ERROR_NO_BUFFER | No buffer is available. | 121e41f4b71Sopenharmony_ci| NATIVE_ERROR_NO_CONSUMER | The consumer does not exist. | 122e41f4b71Sopenharmony_ci| NATIVE_ERROR_NOT_INIT | Not initialized. | 123e41f4b71Sopenharmony_ci| NATIVE_ERROR_CONSUMER_CONNECTED | The consumer is connected. | 124e41f4b71Sopenharmony_ci| NATIVE_ERROR_BUFFER_STATE_INVALID | The buffer status does not meet the expectation. | 125e41f4b71Sopenharmony_ci| NATIVE_ERROR_BUFFER_IN_CACHE | The buffer is already in the buffer queue. | 126e41f4b71Sopenharmony_ci| NATIVE_ERROR_BUFFER_QUEUE_FULL | The queue is full. | 127e41f4b71Sopenharmony_ci| NATIVE_ERROR_BUFFER_NOT_IN_CACHE | The buffer is not in the buffer queue. | 128e41f4b71Sopenharmony_ci| NATIVE_ERROR_CONSUMER_DISCONNECTED | The consumer is disconnected.| 129e41f4b71Sopenharmony_ci| NATIVE_ERROR_CONSUMER_NO_LISTENER_REGISTERED | No listener is registered on the consumer side.| 130e41f4b71Sopenharmony_ci| NATIVE_ERROR_UNSUPPORTED | The device or platform does not support the operation. | 131e41f4b71Sopenharmony_ci| NATIVE_ERROR_UNKNOWN | Unknown error. Check the log. | 132e41f4b71Sopenharmony_ci| NATIVE_ERROR_HDI_ERROR | Failed to call the HDI. | 133e41f4b71Sopenharmony_ci| NATIVE_ERROR_BINDER_ERROR | Cross-process communication failed. | 134e41f4b71Sopenharmony_ci| NATIVE_ERROR_EGL_STATE_UNKNOWN | The EGL environment is abnormal. | 135e41f4b71Sopenharmony_ci| NATIVE_ERROR_EGL_API_FAILED | Failed to call the EGL APIs. | 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci## Function Description 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci### OH_NativeVSync_GetPeriod() 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci``` 143e41f4b71Sopenharmony_ciint OH_NativeVSync_GetPeriod (OH_NativeVSync * nativeVsync, long long * period ) 144e41f4b71Sopenharmony_ci``` 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci**Description** 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ciObtains the VSync period. 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci\@syscap SystemCapability.Graphic.Graphic2D.NativeVsync 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**Parameters** 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci| Name| Description| 155e41f4b71Sopenharmony_ci| -------- | -------- | 156e41f4b71Sopenharmony_ci| nativeVsync | Pointer to an **OH_NativeVSync** instance.| 157e41f4b71Sopenharmony_ci| period | Pointer to the VSync period.| 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci**Returns** 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ciReturns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**Since** 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci10 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci### OH_NativeVSync_Create() 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci``` 172e41f4b71Sopenharmony_ciOH_NativeVSync* OH_NativeVSync_Create (const char * name, unsigned int length ) 173e41f4b71Sopenharmony_ci``` 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**Description** 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ciCreates an **OH_NativeVSync** instance. A new **OH_NativeVSync** instance is created each time this function is called. 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci\@syscap SystemCapability.Graphic.Graphic2D.NativeVsync 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci**Parameters** 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci| Name| Description| 184e41f4b71Sopenharmony_ci| -------- | -------- | 185e41f4b71Sopenharmony_ci| name | Pointer to the name that associates with an **OH_NativeVSync** instance.| 186e41f4b71Sopenharmony_ci| length | Length of the name.| 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci**Returns** 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ciReturns the pointer to an **OH_NativeVSync** instance. 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci### OH_NativeVSync_Destroy() 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci``` 197e41f4b71Sopenharmony_civoid OH_NativeVSync_Destroy (OH_NativeVSync * nativeVsync) 198e41f4b71Sopenharmony_ci``` 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci**Description** 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ciDestroys an **OH_NativeVSync** instance. 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci\@syscap SystemCapability.Graphic.Graphic2D.NativeVsync 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci**Parameters** 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci| Name| Description| 209e41f4b71Sopenharmony_ci| -------- | -------- | 210e41f4b71Sopenharmony_ci| nativeVsync | Pointer to an **OH_NativeVSync** instance.| 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci### OH_NativeVSync_RequestFrame() 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci``` 217e41f4b71Sopenharmony_ciint OH_NativeVSync_RequestFrame (OH_NativeVSync * nativeVsync, OH_NativeVSync_FrameCallback callback, void * data ) 218e41f4b71Sopenharmony_ci``` 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci**Description** 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ciRequests the next VSync signal. When the signal arrives, a callback function is invoked. If this function is called for multiple times in the same frame, only the last callback function is invoked. 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci\@syscap SystemCapability.Graphic.Graphic2D.NativeVsync 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci**Parameters** 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci| Name| Description| 229e41f4b71Sopenharmony_ci| -------- | -------- | 230e41f4b71Sopenharmony_ci| nativeVsync | Pointer to an **OH_NativeVSync** instance.| 231e41f4b71Sopenharmony_ci| callback | Function pointer of the **OH_NativeVSync_FrameCallback** type. This function pointer will be called when the next VSync signal arrives.| 232e41f4b71Sopenharmony_ci| data | Pointer to the user-defined data struct. The type is void\*.| 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**Returns** 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ciReturns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci### OH_NativeVSync_RequestFrameWithMultiCallback() 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci``` 242e41f4b71Sopenharmony_ciint OH_NativeVSync_RequestFrameWithMultiCallback (OH_NativeVSync* nativeVsync, OH_NativeVSync_FrameCallback callback, void* data ) 243e41f4b71Sopenharmony_ci``` 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci**Description** 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ciRequests the next VSync signal. When the signal arrives, a callback function is invoked. If this function is called for multiple times in the same frame, every callback function is invoked. 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphic.Graphic2D.NativeVsync 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci**Since**: 12 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci**Parameters** 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci| Name| Description| 256e41f4b71Sopenharmony_ci| -------- | -------- | 257e41f4b71Sopenharmony_ci| nativeVsync | Pointer to an **OH_NativeVSync** instance.| 258e41f4b71Sopenharmony_ci| callback | Function pointer of the **OH_NativeVSync_FrameCallback** type. This function pointer will be called when the next VSync signal arrives.| 259e41f4b71Sopenharmony_ci| data | Pointer to the user-defined data struct. The type is void\*.| 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**Returns** 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ciReturns **0** if the operation is successful; returns an error code defined in [OHNativeErrorCode](#ohnativeerrorcode) otherwise. 264