fix cloning
This commit is contained in:
parent
f02d45f563
commit
48785ffb7a
2 changed files with 18 additions and 19 deletions
|
@ -23,17 +23,17 @@ use winit_input_helper::WinitInputHelper;
|
|||
|
||||
pub struct WindowInfo {
|
||||
id: WindowId,
|
||||
data: Arc<Mutex<WindowData>>,
|
||||
data: Arc<WindowData>,
|
||||
}
|
||||
|
||||
pub struct WindowData {
|
||||
scaled_buf: Vec<[u8; 4]>,
|
||||
pixels: Pixels,
|
||||
scaled_buf: Mutex<Vec<[u8; 4]>>,
|
||||
pixels: Mutex<Pixels>,
|
||||
}
|
||||
|
||||
pub struct WindowManager {
|
||||
event_loop: EventLoop<()>,
|
||||
windows: HashMap<WindowId, Arc<Mutex<WindowData>>>,
|
||||
windows: HashMap<WindowId, Arc<WindowData>>,
|
||||
input: Arc<Mutex<WinitInputHelper>>,
|
||||
}
|
||||
|
||||
|
@ -76,14 +76,13 @@ impl WindowManager {
|
|||
}
|
||||
Event::RedrawRequested(window_id) => {
|
||||
if let Some(w) = self.windows.get(&window_id) {
|
||||
if let Ok(mut w) = w.lock() {
|
||||
let scaled = w.scaled_buf.clone();
|
||||
if let Ok(scaled_buf) = w.scaled_buf.lock() && let Ok(mut pixels) = w.pixels.lock() {
|
||||
for (pixel, source) in
|
||||
w.pixels.frame_mut().chunks_exact_mut(4).zip(&scaled)
|
||||
pixels.frame_mut().chunks_exact_mut(4).zip(scaled_buf.iter())
|
||||
{
|
||||
pixel.copy_from_slice(source);
|
||||
}
|
||||
w.pixels.render().unwrap();
|
||||
pixels.render().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +95,7 @@ impl WindowManager {
|
|||
pub struct WindowRenderer {
|
||||
window: Window,
|
||||
input: Arc<Mutex<WinitInputHelper>>,
|
||||
data: Arc<Mutex<WindowData>>,
|
||||
data: Arc<WindowData>,
|
||||
width: usize,
|
||||
height: usize,
|
||||
factor: usize,
|
||||
|
@ -133,10 +132,10 @@ impl WindowRenderer {
|
|||
.unwrap()
|
||||
};
|
||||
|
||||
let data = Arc::new(Mutex::new(WindowData {
|
||||
scaled_buf: Vec::new(),
|
||||
pixels,
|
||||
}));
|
||||
let data = Arc::new(WindowData {
|
||||
scaled_buf: Mutex::new(Vec::new()),
|
||||
pixels: Mutex::new(pixels),
|
||||
});
|
||||
let info = WindowInfo {
|
||||
id: window.id(),
|
||||
data: data.clone(),
|
||||
|
@ -170,24 +169,24 @@ impl Renderer<[u8; 4]> for WindowRenderer {
|
|||
let h = (height * self.real_factor) as u32;
|
||||
|
||||
self.window.set_inner_size(PhysicalSize::new(w, h));
|
||||
if let Ok(mut data) = self.data.lock() {
|
||||
data.pixels = {
|
||||
if let Ok(mut scaled_buf) = self.data.scaled_buf.lock() && let Ok(mut pixels) = self.data.pixels.lock() {
|
||||
*pixels = {
|
||||
let window_size = self.window.inner_size();
|
||||
let surface_texture =
|
||||
SurfaceTexture::new(window_size.width, window_size.height, &self.window);
|
||||
Pixels::new(window_size.width, window_size.height, surface_texture).unwrap()
|
||||
};
|
||||
|
||||
data.scaled_buf.resize((w * h) as usize, [0; 4]);
|
||||
scaled_buf.resize((w * h) as usize, [0; 4]);
|
||||
}
|
||||
self.window.request_redraw();
|
||||
}
|
||||
|
||||
fn display(&mut self, buffer: &[[u8; 4]]) {
|
||||
if let Ok(mut data) = self.data.lock() {
|
||||
if let Ok(mut scaled_buf) = self.data.scaled_buf.lock() {
|
||||
scale_buffer_in_place(
|
||||
buffer,
|
||||
&mut data.scaled_buf,
|
||||
&mut scaled_buf,
|
||||
self.width,
|
||||
self.height,
|
||||
self.real_factor,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#![feature(exclusive_range_pattern, let_chains, bigint_helper_methods, step_trait)]
|
||||
#![feature(exclusive_range_pattern, let_chains, bigint_helper_methods)]
|
||||
|
||||
use crate::{
|
||||
processor::{memory::Memory, Flags},
|
||||
|
|
Loading…
Add table
Reference in a new issue