anvil: Fix winit resizing

This commit is contained in:
Victor Brekenfeld 2022-01-10 19:31:07 +01:00
parent fefb287fa8
commit 51ece28120
1 changed files with 62 additions and 54 deletions

View File

@ -168,24 +168,57 @@ pub fn run_winit(log: Logger) {
.and_then(|_| { .and_then(|_| {
backend backend
.renderer() .renderer()
.render(size, Transform::Flipped180, |renderer, frame| { .render(
render_layers_and_windows( output_geometry
renderer, .size
frame, .to_f64()
&*state.window_map.borrow(), .to_physical(output_scale as f64)
output_geometry, .to_i32_round(),
output_scale, Transform::Flipped180,
&log, |renderer, frame| {
)?; render_layers_and_windows(
renderer,
frame,
&*state.window_map.borrow(),
output_geometry,
output_scale,
&log,
)?;
let (x, y) = state.pointer_location.into(); let (x, y) = state.pointer_location.into();
// draw the dnd icon if any // draw the dnd icon if any
{ {
let guard = state.dnd_icon.lock().unwrap(); let guard = state.dnd_icon.lock().unwrap();
if let Some(ref surface) = *guard { if let Some(ref surface) = *guard {
if surface.as_ref().is_alive() { if surface.as_ref().is_alive() {
draw_dnd_icon( draw_dnd_icon(
renderer,
frame,
surface,
(x as i32, y as i32).into(),
output_scale,
&log,
)?;
}
}
}
// draw the cursor as relevant
{
let mut guard = state.cursor_status.lock().unwrap();
// reset the cursor if the surface is no longer alive
let mut reset = false;
if let CursorImageStatus::Image(ref surface) = *guard {
reset = !surface.as_ref().is_alive();
}
if reset {
*guard = CursorImageStatus::Default;
}
// draw as relevant
if let CursorImageStatus::Image(ref surface) = *guard {
cursor_visible = false;
draw_cursor(
renderer, renderer,
frame, frame,
surface, surface,
@ -193,52 +226,27 @@ pub fn run_winit(log: Logger) {
output_scale, output_scale,
&log, &log,
)?; )?;
} else {
cursor_visible = true;
} }
} }
}
// draw the cursor as relevant
{
let mut guard = state.cursor_status.lock().unwrap();
// reset the cursor if the surface is no longer alive
let mut reset = false;
if let CursorImageStatus::Image(ref surface) = *guard {
reset = !surface.as_ref().is_alive();
}
if reset {
*guard = CursorImageStatus::Default;
}
// draw as relevant #[cfg(feature = "debug")]
if let CursorImageStatus::Image(ref surface) = *guard { {
cursor_visible = false; let fps = state.backend_data.fps.avg().round() as u32;
draw_cursor(
draw_fps(
renderer, renderer,
frame, frame,
surface, &state.backend_data.fps_texture,
(x as i32, y as i32).into(), output_scale as f64,
output_scale, fps,
&log,
)?; )?;
} else {
cursor_visible = true;
} }
}
#[cfg(feature = "debug")] Ok(())
{ },
let fps = state.backend_data.fps.avg().round() as u32; )
draw_fps(
renderer,
frame,
&state.backend_data.fps_texture,
output_scale as f64,
fps,
)?;
}
Ok(())
})
.map_err(Into::<SwapBuffersError>::into) .map_err(Into::<SwapBuffersError>::into)
.and_then(|x| x) .and_then(|x| x)
}) })