NativeVsync

Struct NativeVsync 

Source
pub struct NativeVsync { /* private fields */ }

Implementations§

Source§

impl NativeVsync

Source

pub fn new(name: &str) -> Result<Self, NativeVsyncError>

Creates a new NativeVsync instance with the given name.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_period(&self) -> Result<u64, NativeVsyncError>

Returns the vsync period in nanoseconds.

Trait Implementations§

Source§

impl Drop for NativeVsync

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.