pub struct NativeVsync { /* private fields */ }Implementations§
Source§impl NativeVsync
impl NativeVsync
Sourcepub fn new(name: &str) -> Result<Self, NativeVsyncError>
pub fn new(name: &str) -> Result<Self, NativeVsyncError>
Creates a new NativeVsync instance with the given name.
Sourcepub unsafe fn from_raw(native_vsync: *mut OH_NativeVSync) -> Self
pub unsafe fn from_raw(native_vsync: *mut OH_NativeVSync) -> Self
Create from a raw pointer to a valid OH_NativeVSync instance.
§Safety
native_vsync must be a valid, live OH_NativeVSync instance.
The ownership of native_vsync must be exclusive and is transferred to the new object.
Sourcepub fn into_raw(self) -> *mut OH_NativeVSync
pub fn into_raw(self) -> *mut OH_NativeVSync
Returns the reference to the raw OH_NativeVSync and consumes self
NativeVsync::from_raw can be used to reconstruct Self later.
This can be used to pass the owned NativeVsync object to the callback function.
Sourcepub unsafe fn request_raw_callback(
&self,
callback: OH_NativeVSync_FrameCallback,
data: *mut c_void,
) -> Result<(), NativeVsyncError>
pub unsafe fn request_raw_callback( &self, callback: OH_NativeVSync_FrameCallback, data: *mut c_void, ) -> Result<(), NativeVsyncError>
Request a Callback to callback on the next Vsync frame
data will be passed to the callback.
§Safety
If data is used in the callback then data must live long enough and be ThreadSafe to use. Todo: Define the requirements more clearly.
Sourcepub unsafe fn request_raw_callback_with_self(
self,
callback: OH_NativeVSync_FrameCallback,
) -> Result<(), NativeVsyncError>
pub unsafe fn request_raw_callback_with_self( self, callback: OH_NativeVSync_FrameCallback, ) -> Result<(), NativeVsyncError>
Request a Callback to callback on the next Vsync frame passing self to the callback
The Callback receives a raw pointer to the native vsync instance, that can be used with
NativeVsync::from_raw() to pass Self to the callback.
§Safety
Probably this function is safe to use. The only open question is if it’s sound for the callback to reconstruct the NativeVsync object and then drop the object, since that would also destroy the thread the callback is running on. It’s unclear if the thread would be destroyed immediately, or after the callback returns.
§Note
The callback function should be aware that data points to the native vsync instance.
Failure to reconstruct NativeVsync would lead to a memory leak.
Sourcepub fn get_period(&self) -> Result<u64, NativeVsyncError>
pub fn get_period(&self) -> Result<u64, NativeVsyncError>
Returns the vsync period in nanoseconds.