Skip to content

Commit a36b11a

Browse files
committed
X11 implementation no longer has an extraneous copy to deal with xlib's lifetime requirements
1 parent 384f2dc commit a36b11a

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

examples/winit.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::time::Instant;
21
use winit::event::{Event, WindowEvent};
32
use winit::event_loop::{ControlFlow, EventLoop};
43
use winit::window::WindowBuilder;
@@ -20,10 +19,7 @@ fn main() {
2019
};
2120
let buffer = vec![0x00FF00FF; (width * height) as usize];
2221

23-
let start = Instant::now();
2422
graphics_context.set_buffer(&buffer, width as u16, height as u16);
25-
let elapsed = Instant::now()-start;
26-
println!("Set in: {}ms", elapsed.as_millis());
2723
}
2824
Event::WindowEvent {
2925
event: WindowEvent::CloseRequested,

src/x11.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ impl X11Impl {
3434
impl GraphicsContextImpl for X11Impl {
3535

3636
unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) {
37-
let mut owned_buffer = vec![0; (width as usize)*(height as usize)];
38-
owned_buffer.copy_from_slice(buffer);
39-
4037
//create image
4138
let image = (self.lib.XCreateImage)(
4239
self.handle.display as *mut Display,
4340
self.visual,
4441
self.depth as u32,
4542
ZPixmap,
4643
0,
47-
Box::leak(owned_buffer.into_boxed_slice()).as_mut_ptr() as *mut c_char,
44+
(buffer.as_ptr()) as *mut c_char,
4845
width as u32,
4946
height as u32,
5047
32,
@@ -69,6 +66,7 @@ impl GraphicsContextImpl for X11Impl {
6966
height as c_uint
7067
);
7168

69+
(*image).data = std::ptr::null_mut();
7270
(self.lib.XDestroyImage)(image);
7371
}
7472

0 commit comments

Comments
 (0)