X11 implementation no longer has an extraneous copy to deal with xlib's lifetime requirements
This commit is contained in:
parent
384f2dc9a3
commit
a36b11a934
2 changed files with 2 additions and 8 deletions
|
|
@ -1,4 +1,3 @@
|
||||||
use std::time::Instant;
|
|
||||||
use winit::event::{Event, WindowEvent};
|
use winit::event::{Event, WindowEvent};
|
||||||
use winit::event_loop::{ControlFlow, EventLoop};
|
use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
use winit::window::WindowBuilder;
|
use winit::window::WindowBuilder;
|
||||||
|
|
@ -20,10 +19,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
let buffer = vec![0x00FF00FF; (width * height) as usize];
|
let buffer = vec![0x00FF00FF; (width * height) as usize];
|
||||||
|
|
||||||
let start = Instant::now();
|
|
||||||
graphics_context.set_buffer(&buffer, width as u16, height as u16);
|
graphics_context.set_buffer(&buffer, width as u16, height as u16);
|
||||||
let elapsed = Instant::now()-start;
|
|
||||||
println!("Set in: {}ms", elapsed.as_millis());
|
|
||||||
}
|
}
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
event: WindowEvent::CloseRequested,
|
event: WindowEvent::CloseRequested,
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,6 @@ impl X11Impl {
|
||||||
impl GraphicsContextImpl for X11Impl {
|
impl GraphicsContextImpl for X11Impl {
|
||||||
|
|
||||||
unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) {
|
unsafe fn set_buffer(&mut self, buffer: &[u32], width: u16, height: u16) {
|
||||||
let mut owned_buffer = vec![0; (width as usize)*(height as usize)];
|
|
||||||
owned_buffer.copy_from_slice(buffer);
|
|
||||||
|
|
||||||
//create image
|
//create image
|
||||||
let image = (self.lib.XCreateImage)(
|
let image = (self.lib.XCreateImage)(
|
||||||
self.handle.display as *mut Display,
|
self.handle.display as *mut Display,
|
||||||
|
|
@ -44,7 +41,7 @@ impl GraphicsContextImpl for X11Impl {
|
||||||
self.depth as u32,
|
self.depth as u32,
|
||||||
ZPixmap,
|
ZPixmap,
|
||||||
0,
|
0,
|
||||||
Box::leak(owned_buffer.into_boxed_slice()).as_mut_ptr() as *mut c_char,
|
(buffer.as_ptr()) as *mut c_char,
|
||||||
width as u32,
|
width as u32,
|
||||||
height as u32,
|
height as u32,
|
||||||
32,
|
32,
|
||||||
|
|
@ -69,6 +66,7 @@ impl GraphicsContextImpl for X11Impl {
|
||||||
height as c_uint
|
height as c_uint
|
||||||
);
|
);
|
||||||
|
|
||||||
|
(*image).data = std::ptr::null_mut();
|
||||||
(self.lib.XDestroyImage)(image);
|
(self.lib.XDestroyImage)(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue