Make canvas minimal render on first loop
@@ -82,14 +82,20 @@ fn main() {
let mut renderer = Renderer::new(pathfinder_device, &resource_loader, mode, options);
let font_context = CanvasFontContext::from_system_source();
+ let mut is_first_render = true;
// Wait for a keypress.
event_loop.run_forever(|event| {
+ let mut should_render = is_first_render;
match event {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } |
- Event::WindowEvent { event: WindowEvent::KeyboardInput { .. }, .. } => {
- ControlFlow::Break
- }
+ Event::WindowEvent { event: WindowEvent::KeyboardInput { .. }, .. } => return ControlFlow::Break,
Event::WindowEvent { event: WindowEvent::Refresh, .. } => {
+ should_render = true;
+ }
+ _ => {},
+ }
+
+ if should_render {
// 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());
@@ -120,11 +126,10 @@ fn main() {
let mut surface = device.unbind_surface_from_context(&mut context).unwrap().unwrap();
device.present_surface(&mut context, &mut surface).unwrap();
device.bind_surface_to_context(&mut context, surface).unwrap();
+ }
+ is_first_render = false;
ControlFlow::Continue
- }
- _ => ControlFlow::Continue,
- }
});
// Clean up.
