@@ -33,16 +33,23 @@ pub struct GraphicsContext {
33
33
}
34
34
35
35
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.
37
37
///
38
38
/// # Safety
39
39
///
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
41
41
/// lifetime of the GraphicsContext
42
42
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
+ }
45
45
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 > {
46
53
let imple: Box < dyn GraphicsContextImpl > = match ( raw_window_handle, raw_display_handle) {
47
54
#[ cfg( any( target_os = "linux" , target_os = "freebsd" ) ) ]
48
55
( RawWindowHandle :: Xlib ( xlib_window_handle) , RawDisplayHandle :: Xlib ( xlib_display_handle) ) => Box :: new ( x11:: X11Impl :: new ( xlib_window_handle, xlib_display_handle) ?) ,
0 commit comments