@@ -5,13 +5,22 @@ mod win32;
5
5
6
6
use raw_window_handle:: { HasRawWindowHandle , RawWindowHandle } ;
7
7
8
+ /// An instance of this struct contains the platform-specific data that must be managed in order to
9
+ /// write to a window on that platform. This struct owns the window that this data corresponds to
10
+ /// to ensure safety, as that data must be destroyed before the window itself is destroyed. You may
11
+ /// access the underlying window via [`window`](Self::window) and [`window_mut`](Self::window_mut).
8
12
pub struct GraphicsContext < W : HasRawWindowHandle > {
9
13
window : W ,
10
14
graphics_context_impl : Box < dyn GraphicsContextImpl >
11
15
}
12
16
13
17
impl < W : HasRawWindowHandle > GraphicsContext < W > {
14
18
19
+ /// Creates a new instance of this struct, consuming the given window.
20
+ ///
21
+ /// # Safety
22
+ ///
23
+ /// - Ensure that the passed object is valid to draw a 2D buffer to
15
24
pub unsafe fn new ( window : W ) -> Self {
16
25
let raw_handle = window. raw_window_handle ( ) ;
17
26
let imple = match raw_handle{
@@ -28,16 +37,41 @@ impl<W: HasRawWindowHandle> GraphicsContext<W> {
28
37
}
29
38
}
30
39
40
+ /// Gets shared access to the underlying window
31
41
#[ inline]
32
42
pub fn window ( & self ) -> & W {
33
43
& self . window
34
44
}
35
45
46
+ /// Gets mut/exclusive access to the underlying window
36
47
#[ inline]
37
48
pub fn window_mut ( & mut self ) -> & mut W {
38
49
& mut self . window
39
50
}
40
51
52
+ /// Shows the given buffer with the given width and height on the window corresponding to this
53
+ /// graphics context. Panics if buffer.len() ≠ width*height. If the size of the buffer does
54
+ /// not match the size of the window, the buffer is drawn in the upper-left corner of the window.
55
+ /// It is recommended in most production use cases to have the buffer fill the entire window.
56
+ /// Use your windowing library to find the size of the window.
57
+ ///
58
+ /// The format of the buffer is as follows. There is one u32 in the buffer for each pixel in
59
+ /// the area to draw. The first entry is the upper-left most pixel. The second is one to the right
60
+ /// etc. (Row-major top to bottom left to right one u32 per pixel). Within each u32 the highest
61
+ /// order 8 bits are to be set to 0. The next highest order 8 bits are the red channel, then the
62
+ /// green channel, and then the blue channel in the lowest-order 8 bits. See the examples for
63
+ /// one way to build this format using bitwise operations.
64
+ ///
65
+ /// --------
66
+ ///
67
+ /// Pixel format (u32):
68
+ ///
69
+ /// 00000000RRRRRRRRGGGGGGGGBBBBBBBB
70
+ ///
71
+ /// 0: Bit is 0
72
+ /// R: Red channel
73
+ /// G: Green channel
74
+ /// B: Blue channel
41
75
#[ inline]
42
76
pub fn set_buffer ( & mut self , buffer : & [ u32 ] , width : u16 , height : u16 ) {
43
77
if ( width as usize ) * ( height as usize ) != buffer. len ( ) {
0 commit comments