diff --git a/gb-emu/src/renderer/pixels.rs b/gb-emu/src/renderer/pixels.rs index 1eda6c9..0c0b813 100644 --- a/gb-emu/src/renderer/pixels.rs +++ b/gb-emu/src/renderer/pixels.rs @@ -18,6 +18,16 @@ impl WindowData { pub fn resize(&mut self, width: u32, height: u32, factor: u32, window: &Window) { self.pixels = new_pixels(width, height, factor, window); } + + pub fn new_frame(&mut self, buffer: &[[u8; 4]]) { + self.pixels + .frame_mut() + .copy_from_slice(bytemuck::cast_slice(buffer)); + } + + pub fn render(&mut self) { + self.pixels.render().unwrap(); + } } fn new_pixels(width: u32, height: u32, scaling: u32, window: &Window) -> Pixels { diff --git a/gb-emu/src/window.rs b/gb-emu/src/window.rs index 13a778d..63866ff 100644 --- a/gb-emu/src/window.rs +++ b/gb-emu/src/window.rs @@ -75,8 +75,8 @@ impl WindowManager { } Event::RedrawRequested(window_id) => { if let Some(w) = self.windows.get(&window_id) { - if let Ok(data) = w.lock() { - data.pixels.render().unwrap(); + if let Ok(mut data) = w.lock() { + data.render(); } } } @@ -162,9 +162,7 @@ impl Renderer<[u8; 4]> for WindowRenderer { fn display(&mut self, buffer: &[[u8; 4]]) { if let Ok(mut data) = self.data.lock() { - data.pixels - .frame_mut() - .copy_from_slice(bytemuck::cast_slice(buffer)); + data.new_frame(buffer); } self.window.request_redraw(); }