Make canvas minimal render on first loop

This commit is contained in:
LeRoyce Pearson 2020-07-22 12:28:36 -06:00
parent 5951b32ede
commit 263dc0ab15
1 changed files with 41 additions and 36 deletions

View File

@ -82,14 +82,20 @@ fn main() {
let mut renderer = Renderer::new(pathfinder_device, &resource_loader, mode, options); let mut renderer = Renderer::new(pathfinder_device, &resource_loader, mode, options);
let font_context = CanvasFontContext::from_system_source(); let font_context = CanvasFontContext::from_system_source();
let mut is_first_render = true;
// Wait for a keypress. // Wait for a keypress.
event_loop.run_forever(|event| { event_loop.run_forever(|event| {
let mut should_render = is_first_render;
match event { match event {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } | Event::WindowEvent { event: WindowEvent::CloseRequested, .. } |
Event::WindowEvent { event: WindowEvent::KeyboardInput { .. }, .. } => { Event::WindowEvent { event: WindowEvent::KeyboardInput { .. }, .. } => return ControlFlow::Break,
ControlFlow::Break
}
Event::WindowEvent { event: WindowEvent::Refresh, .. } => { Event::WindowEvent { event: WindowEvent::Refresh, .. } => {
should_render = true;
}
_ => {},
}
if should_render {
// Make a canvas. We're going to draw a house. // Make a canvas. We're going to draw a house.
let mut canvas = Canvas::new(framebuffer_size.to_f32()).get_context_2d(font_context.clone()); let mut canvas = Canvas::new(framebuffer_size.to_f32()).get_context_2d(font_context.clone());
@ -120,11 +126,10 @@ fn main() {
let mut surface = device.unbind_surface_from_context(&mut context).unwrap().unwrap(); let mut surface = device.unbind_surface_from_context(&mut context).unwrap().unwrap();
device.present_surface(&mut context, &mut surface).unwrap(); device.present_surface(&mut context, &mut surface).unwrap();
device.bind_surface_to_context(&mut context, surface).unwrap(); device.bind_surface_to_context(&mut context, surface).unwrap();
}
is_first_render = false;
ControlFlow::Continue ControlFlow::Continue
}
_ => ControlFlow::Continue,
}
}); });
// Clean up. // Clean up.