harmony 鸿蒙NativeVSync Development
NativeVSync Development
When to Use
The NativeVSync module is used to obtain virtual synchronization (VSync) signals from the system. It provides APIs for creating and destroying an OH_NativeVSync instance and setting the VSync callback function, which is triggered when a VSync signal arrives.
Available APIs
API | Description |
---|---|
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. |
OH_NativeVSync_Destroy (OH_NativeVSync *nativeVsync) | Destroys an OH_NativeVSync instance. |
OH_NativeVSync_FrameCallback (long long timestamp, void *data) | Sets a callback function. timestamp indicates the timestamp, and data indicates the input parameter of the callback function. |
OH_NativeVSync_RequestFrame (OH_NativeVSync *nativeVsync, OH_NativeVSync_FrameCallback callback, void *data) | Requests the next VSync signal. When the signal arrives, a callback function is invoked. |
For details about the APIs, see native_vsync.
How to Develop
The following steps describe how to use the native APIs provided by NativeVSync to create and destroy an OH_NativeVSync instance and set the VSync callback function.
Adding Dynamic Link Libraries
Add the following library to CMakeLists.txt:
libnative_vsync.so
Header File
#include <native_vsync/native_vsync.h>
Prepare a VSync callback function.
#include <iostream> static bool flag = false; static void OnVSync(long long timestamp, void* data) { flag = true; std::cout << "OnVSync: " << timestamp << std::endl; } OH_NativeVSync_FrameCallback callback = OnVSync; // The callback function must be of the OH_NativeVSync_FrameCallback type.
Create an OH_NativeVSync instance.
char name[] = "hello_vsync"; OH_NativeVSync* nativeVSync = OH_NativeVSync_Create(name, strlen(name));
Set the VSync callback function through the OH_NativeVSync instance.
#include <unistd.h> #include <iostream> OH_NativeVSync_RequestFrame(nativeVSync, callback, nullptr); while (!flag) { // Check the flag value. The while loop exits only after the VSync callback function is executed, indicating that a VSync signal is received. std::cout << "wait for vsync!\n"; sleep(1); } std::cout << "vsync come, end this thread\n";
Destroy the OH_NativeVSync instance.
OH_NativeVSync_Destroy(nativeVSync); // Destroy the OH_NativeVSync instance when the application does not need to receive VSync signals.
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Drawing and Display Sample
harmony 鸿蒙Hardware Compatibility
harmony 鸿蒙Using MindSpore Lite for Model Inference
harmony 鸿蒙Using MindSpore Lite for Offline Model Conversion and Inference
harmony 鸿蒙Using Native APIs in Application Projects
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦