-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//! Bindings for [`ASurfaceControl`], [`ASurfaceTransaction`] | ||
use std::{ffi::CStr, ptr::NonNull}; | ||
|
||
use crate::native_window::NativeWindow; | ||
|
||
#[doc(alias = "ASurfaceControl")] | ||
pub struct SurfaceControl { | ||
ptr: NonNull<ffi::ASurfaceControl>, | ||
} | ||
|
||
impl SurfaceControl { | ||
/// Assumes ownership of `ptr` | ||
/// | ||
/// # Safety | ||
/// `ptr` must be a valid pointer to an Android [`ffi::ASurfaceControl`]. | ||
pub unsafe fn from_ptr(ptr: NonNull<ffi::ASurfaceControl>) -> Self { | ||
Self { ptr } | ||
} | ||
|
||
/// Acquires ownership of `ptr` | ||
/// | ||
/// # Safety | ||
/// `ptr` must be a valid pointer to an Android [`ffi::ASurfaceControl`]. | ||
pub unsafe fn clone_from_ptr(ptr: NonNull<ffi::ASurfaceControl>) -> Self { | ||
ffi::ASurfaceControl_acquire(ptr.as_ptr()); | ||
Self::from_ptr(ptr) | ||
} | ||
|
||
/// BORROW | ||
#[doc(alias = "ASurfaceControl_createFromWindow")] | ||
pub fn create_from_window(parent: NativeWindow, debug_name: &CStr) -> Option<Self> { | ||
let ptr = unsafe { | ||
ffi::ASurfaceControl_createFromWindow(parent.ptr().as_ptr(), debug_name.as_ptr()) | ||
}; | ||
let s = NonNull::new(ptr)?; | ||
Some(unsafe { Self::from_ptr(s) }) | ||
} | ||
|
||
#[doc(alias = "ASurfaceControl_create")] | ||
pub fn create(parent: &Self, debug_name: &CStr) -> Option<Self> { | ||
let ptr = unsafe { ffi::ASurfaceControl_create(parent.ptr.as_ptr(), debug_name.as_ptr()) }; | ||
// NonNull::new(ptr).map(|ptr| Self { ptr }) | ||
let s = NonNull::new(ptr)?; | ||
Some(unsafe { Self::from_ptr(s) }) | ||
} | ||
|
||
pub fn ptr(&self) -> NonNull<ffi::ASurfaceControl> { | ||
self.ptr | ||
} | ||
} | ||
|
||
impl Drop for SurfaceControl { | ||
#[doc(alias = "ASurfaceControl_release")] | ||
fn drop(&mut self) { | ||
unsafe { ffi::ASurfaceControl_release(self.ptr.as_ptr()) } | ||
} | ||
} | ||
|
||
impl Clone for SurfaceControl { | ||
#[doc(alias = "ASurfaceControl_acquire")] | ||
fn clone(&self) -> Self { | ||
unsafe { ffi::ASurfaceControl_acquire(self.ptr.as_ptr()) } | ||
Self { ptr: self.ptr } | ||
} | ||
} |