From 806ee4d1e210a097e3e0feb846663853df868b5b Mon Sep 17 00:00:00 2001 From: Long0x0 <51022287+Long0x0@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:29:26 +0800 Subject: [PATCH] Render one frame before showing the window to avoid flashing (#777) Fixes #590. Demo: ![capture](https://github.com/user-attachments/assets/cc62d644-aefa-4f72-9688-a7f921be0036) --- masonry/src/event_loop_runner.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/masonry/src/event_loop_runner.rs b/masonry/src/event_loop_runner.rs index c30efb576..dda6a5636 100644 --- a/masonry/src/event_loop_runner.rs +++ b/masonry/src/event_loop_runner.rs @@ -264,7 +264,6 @@ impl MasonryState<'_> { let window = event_loop.create_window(attributes).unwrap(); let adapter = Adapter::with_event_loop_proxy(&window, self.proxy.clone()); - window.set_visible(visible); let window = Arc::new(window); // https://github.com/rust-windowing/winit/issues/2308 #[cfg(target_os = "ios")] @@ -286,6 +285,20 @@ impl MasonryState<'_> { }; self.render_root .handle_window_event(WindowEvent::Rescale(scale_factor)); + // Render one frame before showing the window to avoid flashing + if visible { + let (scene, tree_update) = self.render_root.redraw(); + self.render(scene); + if let WindowState::Rendering { + window, + accesskit_adapter, + .. + } = &mut self.window + { + accesskit_adapter.update_if_active(|| tree_update); + window.set_visible(true); + }; + } } WindowState::Suspended { window,