Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native vsync bindings #12

Merged
merged 3 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Please also check the following:
- Be sure to guard the new component behind a cargo feature and document the feature in Cargo.toml.
- If you did not generate the bindings with API-level 10, specify which API-level you generated the bindings with
and guard the generated module behind the corresponding api-level feature flag.
- Installing `bindgen`: We use a version of bindgen that has not been released yet to crates.io.
You can install the latest version by running `cargo install --git https://github.com/rust-lang/rust-bindgen.git bindgen-cli --branch main --features prettyplease`

## License

Expand Down
18 changes: 17 additions & 1 deletion scripts/generate_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ ROOT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd )

if ! command -v bindgen
then
echo "Error: bindgen not found"
echo "Error: bindgen not found. Please install it."
exit 1
fi

if ! command -v jq
then
echo "Error: jq not found. Please install it."
exit 1
fi

Expand Down Expand Up @@ -117,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;
}