diff --git a/Cargo.toml b/Cargo.toml
index bd26079..ddabfae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,6 +28,8 @@ napi = []
native_buffer = []
## Enables bindings to `native_window`
native_window = []
+## Enables bindings to `native_vsync`
+vsync = []
## Enables bindings to `native_xcomponent`
xcomponent = []
## Enables all components listed above. Orthogonal to `api-XX` features.
@@ -37,7 +39,8 @@ all-components = [
"napi",
"native_buffer",
"native_window",
- "xcomponent"]
+ "xcomponent",
+ "vsync"]
#! ### OpenHarmony API level
#! This crate by default exposes bindings for API-level 10.
diff --git a/scripts/generate_bindings.sh b/scripts/generate_bindings.sh
index 80a5da5..6cf2396 100755
--- a/scripts/generate_bindings.sh
+++ b/scripts/generate_bindings.sh
@@ -123,6 +123,16 @@ bindgen "${BASE_BINDGEN_ARGS[@]}" \
-- \
"${BASE_CLANG_ARGS[@]}"
+bindgen "${BASE_BINDGEN_ARGS[@]}" \
+ --default-enum-style=newtype \
+ --no-derive-copy \
+ --no-derive-debug \
+ --allowlist-file ".*/native_vsync\.h" \
+ --output "${ROOT_DIR}/src/vsync/vsync_api${OHOS_API_VERSION}.rs" \
+ "${OHOS_SYSROOT_DIR}/usr/include/native_vsync/native_vsync.h" \
+ -- \
+ "${BASE_CLANG_ARGS[@]}"
+
# API-10
DRAWING_NOCOPY_STRUCTS=(OH_Drawing_Canvas OH_Drawing_Pen OH_Drawing_Brush OH_Drawing_Path OH_Drawing_Bitmap)
DRAWING_NOCOPY_STRUCTS+=(OH_Drawing_FontCollection OH_Drawing_Typography OH_Drawing_TextStyle OH_Drawing_TypographyStyle)
diff --git a/src/lib.rs b/src/lib.rs
index 938c12d..1f0c534 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -26,12 +26,19 @@ pub mod hilog;
#[cfg(feature = "napi")]
#[cfg_attr(docsrs, doc(cfg(feature = "napi")))]
pub mod napi;
+
#[cfg(feature = "native_buffer")]
#[cfg_attr(docsrs, doc(cfg(feature = "native_buffer")))]
pub mod native_buffer;
+
#[cfg(feature = "native_window")]
#[cfg_attr(docsrs, doc(cfg(feature = "native_window")))]
pub mod native_window;
+
+#[cfg(feature = "vsync")]
+#[cfg_attr(docsrs, doc(cfg(feature = "vsync")))]
+pub mod vsync;
+
#[cfg(feature = "xcomponent")]
#[cfg_attr(docsrs, doc(cfg(feature = "xcomponent")))]
pub mod xcomponent;
diff --git a/src/vsync.rs b/src/vsync.rs
new file mode 100644
index 0000000..5909683
--- /dev/null
+++ b/src/vsync.rs
@@ -0,0 +1,7 @@
+//! Bindings to the native vsync APIs
+
+#[link(name = "native_vsync")]
+extern "C" {}
+
+mod vsync_api10;
+pub use vsync_api10::*;
diff --git a/src/vsync/vsync_api10.rs b/src/vsync/vsync_api10.rs
new file mode 100644
index 0000000..890e46f
--- /dev/null
+++ b/src/vsync/vsync_api10.rs
@@ -0,0 +1,62 @@
+/* automatically generated by rust-bindgen 0.69.4 */
+
+#![allow(non_upper_case_globals)]
+#![allow(non_camel_case_types)]
+#![allow(non_snake_case)]
+
+#[repr(C)]
+pub struct OH_NativeVSync {
+ _unused: [u8; 0],
+}
+pub type OH_NativeVSync_FrameCallback = ::core::option::Option<
+ unsafe extern "C" fn(timestamp: ::core::ffi::c_longlong, data: *mut ::core::ffi::c_void),
+>;
+extern "C" {
+ /** @brief Creates a NativeVsync instance.\n
+ A new NativeVsync instance is created each time this function is called.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param name Indicates the vsync connection name.
+ @param length Indicates the name's length.
+ @return Returns the pointer to the NativeVsync instance created.
+ @since 9
+ @version 1.0*/
+ pub fn OH_NativeVSync_Create(
+ name: *const ::core::ffi::c_char,
+ length: ::core::ffi::c_uint,
+ ) -> *mut OH_NativeVSync;
+ /** @brief Delete the NativeVsync instance.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param window Indicates the pointer to a NativeVsync instance.
+ @return Returns int32_t, return value == 0, success, otherwise, failed.
+ @since 9
+ @version 1.0*/
+ pub fn OH_NativeVSync_Destroy(nativeVsync: *mut OH_NativeVSync);
+ /** @brief Request next vsync with callback.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param nativeVsync Indicates the pointer to a NativeVsync.
+ @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
+ @param data Indicates data whick will be used in callback.
+ @return Returns int32_t, return value == 0, success, otherwise, failed.
+ @since 9
+ @version 1.0*/
+ pub fn OH_NativeVSync_RequestFrame(
+ nativeVsync: *mut OH_NativeVSync,
+ callback: OH_NativeVSync_FrameCallback,
+ data: *mut ::core::ffi::c_void,
+ ) -> ::core::ffi::c_int;
+ /** @brief Get vsync period.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param nativeVsync Indicates the pointer to a NativeVsync.
+ @param period Indicates the vsync period.
+ @return Returns int32_t, return value == 0, success, otherwise, failed.
+ @since 10
+ @version 1.0*/
+ pub fn OH_NativeVSync_GetPeriod(
+ nativeVsync: *mut OH_NativeVSync,
+ period: *mut ::core::ffi::c_longlong,
+ ) -> ::core::ffi::c_int;
+}
diff --git a/src/vsync/vsync_api11.rs b/src/vsync/vsync_api11.rs
new file mode 100644
index 0000000..890e46f
--- /dev/null
+++ b/src/vsync/vsync_api11.rs
@@ -0,0 +1,62 @@
+/* automatically generated by rust-bindgen 0.69.4 */
+
+#![allow(non_upper_case_globals)]
+#![allow(non_camel_case_types)]
+#![allow(non_snake_case)]
+
+#[repr(C)]
+pub struct OH_NativeVSync {
+ _unused: [u8; 0],
+}
+pub type OH_NativeVSync_FrameCallback = ::core::option::Option<
+ unsafe extern "C" fn(timestamp: ::core::ffi::c_longlong, data: *mut ::core::ffi::c_void),
+>;
+extern "C" {
+ /** @brief Creates a NativeVsync instance.\n
+ A new NativeVsync instance is created each time this function is called.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param name Indicates the vsync connection name.
+ @param length Indicates the name's length.
+ @return Returns the pointer to the NativeVsync instance created.
+ @since 9
+ @version 1.0*/
+ pub fn OH_NativeVSync_Create(
+ name: *const ::core::ffi::c_char,
+ length: ::core::ffi::c_uint,
+ ) -> *mut OH_NativeVSync;
+ /** @brief Delete the NativeVsync instance.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param window Indicates the pointer to a NativeVsync instance.
+ @return Returns int32_t, return value == 0, success, otherwise, failed.
+ @since 9
+ @version 1.0*/
+ pub fn OH_NativeVSync_Destroy(nativeVsync: *mut OH_NativeVSync);
+ /** @brief Request next vsync with callback.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param nativeVsync Indicates the pointer to a NativeVsync.
+ @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
+ @param data Indicates data whick will be used in callback.
+ @return Returns int32_t, return value == 0, success, otherwise, failed.
+ @since 9
+ @version 1.0*/
+ pub fn OH_NativeVSync_RequestFrame(
+ nativeVsync: *mut OH_NativeVSync,
+ callback: OH_NativeVSync_FrameCallback,
+ data: *mut ::core::ffi::c_void,
+ ) -> ::core::ffi::c_int;
+ /** @brief Get vsync period.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param nativeVsync Indicates the pointer to a NativeVsync.
+ @param period Indicates the vsync period.
+ @return Returns int32_t, return value == 0, success, otherwise, failed.
+ @since 10
+ @version 1.0*/
+ pub fn OH_NativeVSync_GetPeriod(
+ nativeVsync: *mut OH_NativeVSync,
+ period: *mut ::core::ffi::c_longlong,
+ ) -> ::core::ffi::c_int;
+}
diff --git a/src/vsync/vsync_api12.rs b/src/vsync/vsync_api12.rs
new file mode 100644
index 0000000..890e46f
--- /dev/null
+++ b/src/vsync/vsync_api12.rs
@@ -0,0 +1,62 @@
+/* automatically generated by rust-bindgen 0.69.4 */
+
+#![allow(non_upper_case_globals)]
+#![allow(non_camel_case_types)]
+#![allow(non_snake_case)]
+
+#[repr(C)]
+pub struct OH_NativeVSync {
+ _unused: [u8; 0],
+}
+pub type OH_NativeVSync_FrameCallback = ::core::option::Option<
+ unsafe extern "C" fn(timestamp: ::core::ffi::c_longlong, data: *mut ::core::ffi::c_void),
+>;
+extern "C" {
+ /** @brief Creates a NativeVsync instance.\n
+ A new NativeVsync instance is created each time this function is called.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param name Indicates the vsync connection name.
+ @param length Indicates the name's length.
+ @return Returns the pointer to the NativeVsync instance created.
+ @since 9
+ @version 1.0*/
+ pub fn OH_NativeVSync_Create(
+ name: *const ::core::ffi::c_char,
+ length: ::core::ffi::c_uint,
+ ) -> *mut OH_NativeVSync;
+ /** @brief Delete the NativeVsync instance.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param window Indicates the pointer to a NativeVsync instance.
+ @return Returns int32_t, return value == 0, success, otherwise, failed.
+ @since 9
+ @version 1.0*/
+ pub fn OH_NativeVSync_Destroy(nativeVsync: *mut OH_NativeVSync);
+ /** @brief Request next vsync with callback.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param nativeVsync Indicates the pointer to a NativeVsync.
+ @param callback Indicates the OH_NativeVSync_FrameCallback which will be called when next vsync coming.
+ @param data Indicates data whick will be used in callback.
+ @return Returns int32_t, return value == 0, success, otherwise, failed.
+ @since 9
+ @version 1.0*/
+ pub fn OH_NativeVSync_RequestFrame(
+ nativeVsync: *mut OH_NativeVSync,
+ callback: OH_NativeVSync_FrameCallback,
+ data: *mut ::core::ffi::c_void,
+ ) -> ::core::ffi::c_int;
+ /** @brief Get vsync period.
+
+ @syscap SystemCapability.Graphic.Graphic2D.NativeVsync
+ @param nativeVsync Indicates the pointer to a NativeVsync.
+ @param period Indicates the vsync period.
+ @return Returns int32_t, return value == 0, success, otherwise, failed.
+ @since 10
+ @version 1.0*/
+ pub fn OH_NativeVSync_GetPeriod(
+ nativeVsync: *mut OH_NativeVSync,
+ period: *mut ::core::ffi::c_longlong,
+ ) -> ::core::ffi::c_int;
+}