Skip to content

Commit

Permalink
Add vsync bindings
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Schwender <[email protected]>
  • Loading branch information
jschwe committed Aug 16, 2024
1 parent 4c4c37f commit 7d246a0
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions scripts/generate_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 7 additions & 0 deletions src/vsync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Bindings to the native vsync APIs
#[link(name = "native_vsync")]
extern "C" {}

mod vsync_api10;
pub use vsync_api10::*;
62 changes: 62 additions & 0 deletions src/vsync/vsync_api10.rs
Original file line number Diff line number Diff line change
@@ -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 <b>NativeVsync</b> instance.\n
A new <b>NativeVsync</b> 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 <b>NativeVsync</b> 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 <b>NativeVsync</b> 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;
}
62 changes: 62 additions & 0 deletions src/vsync/vsync_api11.rs
Original file line number Diff line number Diff line change
@@ -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 <b>NativeVsync</b> instance.\n
A new <b>NativeVsync</b> 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 <b>NativeVsync</b> 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 <b>NativeVsync</b> 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;
}
62 changes: 62 additions & 0 deletions src/vsync/vsync_api12.rs
Original file line number Diff line number Diff line change
@@ -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 <b>NativeVsync</b> instance.\n
A new <b>NativeVsync</b> 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 <b>NativeVsync</b> 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 <b>NativeVsync</b> 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;
}

0 comments on commit 7d246a0

Please sign in to comment.