From a36b11a9340784ab38dd218bf96b75a3dafb9335 Mon Sep 17 00:00:00 2001 From: David Johnson Date: Sat, 15 Jan 2022 08:33:24 -0600 Subject: [PATCH] X11 implementation no longer has an extraneous copy to deal with xlib's lifetime requirements --- examples/winit.rs | 4 ---- src/x11.rs | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/examples/winit.rs b/examples/winit.rs index 52c18a9..1fa128a 100644 --- a/examples/winit.rs +++ b/examples/winit.rs @@ -1,4 +1,3 @@ -use std::time::Instant; use winit::event::{Event, WindowEvent}; use winit::event_loop::{ControlFlow, EventLoop}; use winit::window::WindowBuilder; @@ -20,10 +19,7 @@ fn main() { }; let buffer = vec![0x00FF00FF; (width * height) as usize]; - let start = Instant::now(); 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::CloseRequested, diff --git a/src/x11.rs b/src/x11.rs index 3fd3786..855cbf1 100644 --- a/src/x11.rs +++ b/src/x11.rs @@ -34,9 +34,6 @@ impl X11Impl { impl GraphicsContextImpl for X11Impl { 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 let image = (self.lib.XCreateImage)( self.handle.display as *mut Display, @@ -44,7 +41,7 @@ impl GraphicsContextImpl for X11Impl { self.depth as u32, ZPixmap, 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, height as u32, 32, @@ -69,6 +66,7 @@ impl GraphicsContextImpl for X11Impl { height as c_uint ); + (*image).data = std::ptr::null_mut(); (self.lib.XDestroyImage)(image); }