Skip to content

Commit e781cd8

Browse files
committed
Add from_raw function for direct use of raw handles
1 parent 99d6306 commit e781cd8

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,23 @@ pub struct GraphicsContext {
3333
}
3434

3535
impl GraphicsContext {
36-
/// Creates a new instance of this struct, consuming the given window.
36+
/// Creates a new instance of this struct, using the provided window.
3737
///
3838
/// # Safety
3939
///
40-
/// - Ensure that the passed object is valid to draw a 2D buffer to, and is valid for the
40+
/// - Ensure that the provided window is valid to draw a 2D buffer to, and is valid for the
4141
/// lifetime of the GraphicsContext
4242
pub unsafe fn new<W: HasRawWindowHandle + HasRawDisplayHandle>(window: &W) -> Result<Self, SwBufError> {
43-
let raw_window_handle = window.raw_window_handle();
44-
let raw_display_handle = window.raw_display_handle();
43+
Self::from_raw(window.raw_window_handle(), window.raw_display_handle())
44+
}
4545

46+
/// Creates a new instance of this struct, using the provided raw handles
47+
///
48+
/// # Safety
49+
///
50+
/// - Ensure that the provided handles are valid to draw a 2D buffer to, and are valid for the
51+
/// lifetime of the GraphicsContext
52+
pub unsafe fn from_raw(raw_window_handle: RawWindowHandle, raw_display_handle: RawDisplayHandle) -> Result<Self, SwBufError> {
4653
let imple: Box<dyn GraphicsContextImpl> = match (raw_window_handle, raw_display_handle) {
4754
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
4855
(RawWindowHandle::Xlib(xlib_window_handle), RawDisplayHandle::Xlib(xlib_display_handle)) => Box::new(x11::X11Impl::new(xlib_window_handle, xlib_display_handle)?),

0 commit comments

Comments
 (0)