From bdca20fc4a3e8f6bd8ffb59de75e6ca0f8a94b6a Mon Sep 17 00:00:00 2001 From: Vladyslav Nikonov Date: Thu, 21 Oct 2021 22:42:14 +0300 Subject: Experimental wgpu WebGL backend support - Added missing `draw_cache_align_4x4` call for `brush_glyph` on wasm32 target - Added WebGL support to `integratio_wgpu` example - Fixed test.yml CI workflow - Removed spir-v shader in `integration_wgpu`; Fixed formatting - Removed redundant `BoxStream` typedef --- winit/src/application.rs | 106 +++++++++++++++++++++++++++++++++-------------- winit/src/clipboard.rs | 25 +++++++++++ 2 files changed, 100 insertions(+), 31 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index e9212b5e..a3715b04 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -115,12 +115,16 @@ where use futures::task; use futures::Future; use winit::event_loop::EventLoop; + #[cfg(not(target_arch = "wasm32"))] use winit::platform::run_return::EventLoopExtRunReturn; let mut debug = Debug::new(); debug.startup_started(); + #[cfg(not(target_arch = "wasm32"))] let mut event_loop = EventLoop::with_user_event(); + #[cfg(target_arch = "wasm32")] + let event_loop = EventLoop::with_user_event(); let mut proxy = event_loop.create_proxy(); let mut runtime = { @@ -179,41 +183,81 @@ where let mut context = task::Context::from_waker(task::noop_waker_ref()); - event_loop.run_return(move |event, _, control_flow| { - use winit::event_loop::ControlFlow; + #[cfg(not(target_arch = "wasm32"))] + { + event_loop.run_return(move |event, _, control_flow| { + use winit::event_loop::ControlFlow; - if let ControlFlow::Exit = control_flow { - return; - } + if let ControlFlow::Exit = control_flow { + return; + } - let event = match event { - winit::event::Event::WindowEvent { - event: - winit::event::WindowEvent::ScaleFactorChanged { - new_inner_size, - .. - }, - window_id, - } => Some(winit::event::Event::WindowEvent { - event: winit::event::WindowEvent::Resized(*new_inner_size), - window_id, - }), - _ => event.to_static(), - }; - - if let Some(event) = event { - sender.start_send(event).expect("Send event"); - - let poll = instance.as_mut().poll(&mut context); - - *control_flow = match poll { - task::Poll::Pending => ControlFlow::Wait, - task::Poll::Ready(_) => ControlFlow::Exit, + let event = match event { + winit::event::Event::WindowEvent { + event: + winit::event::WindowEvent::ScaleFactorChanged { + new_inner_size, + .. + }, + window_id, + } => Some(winit::event::Event::WindowEvent { + event: winit::event::WindowEvent::Resized(*new_inner_size), + window_id, + }), + _ => event.to_static(), }; - } - }); - Ok(()) + if let Some(event) = event { + sender.start_send(event).expect("Send event"); + + let poll = instance.as_mut().poll(&mut context); + + *control_flow = match poll { + task::Poll::Pending => ControlFlow::Wait, + task::Poll::Ready(_) => ControlFlow::Exit, + }; + } + }); + + Ok(()) + } + + #[cfg(target_arch = "wasm32")] + { + event_loop.run(move |event, _, control_flow| { + use winit::event_loop::ControlFlow; + + if let ControlFlow::Exit = control_flow { + return; + } + + let event = match event { + winit::event::Event::WindowEvent { + event: + winit::event::WindowEvent::ScaleFactorChanged { + new_inner_size, + .. + }, + window_id, + } => Some(winit::event::Event::WindowEvent { + event: winit::event::WindowEvent::Resized(*new_inner_size), + window_id, + }), + _ => event.to_static(), + }; + + if let Some(event) = event { + sender.start_send(event).expect("Send event"); + + let poll = instance.as_mut().poll(&mut context); + + *control_flow = match poll { + task::Poll::Pending => ControlFlow::Wait, + task::Poll::Ready(_) => ControlFlow::Exit, + }; + } + }); + } } async fn run_instance( diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index 1b92b28d..197d32b3 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -6,15 +6,40 @@ use crate::command::{self, Command}; /// A buffer for short-term storage and transfer within and between /// applications. #[allow(missing_debug_implementations)] +#[cfg(target_arch = "wasm32")] +pub struct Clipboard; + +#[cfg(target_arch = "wasm32")] +impl Clipboard { + /// Creates a new [`Clipboard`] for the given window. + pub fn connect(_window: &winit::window::Window) -> Clipboard { + Clipboard + } + + /// Reads the current content of the [`Clipboard`] as text. + pub fn read(&self) -> Option { + None + } + + /// Writes the given text contents to the [`Clipboard`]. + pub fn write(&mut self, _contents: String) {} +} + +/// A buffer for short-term storage and transfer within and between +/// applications. +#[allow(missing_debug_implementations)] +#[cfg(not(target_arch = "wasm32"))] pub struct Clipboard { state: State, } +#[cfg(not(target_arch = "wasm32"))] enum State { Connected(window_clipboard::Clipboard), Unavailable, } +#[cfg(not(target_arch = "wasm32"))] impl Clipboard { /// Creates a new [`Clipboard`] for the given window. pub fn connect(window: &winit::window::Window) -> Clipboard { -- cgit From 908259663de60ae62723a73c3e93159c4bd22586 Mon Sep 17 00:00:00 2001 From: Kai Mast Date: Thu, 27 Jan 2022 11:27:12 -0600 Subject: Remove wasm-specific clipboard --- winit/src/clipboard.rs | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) (limited to 'winit/src') diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index 197d32b3..559b3521 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -3,43 +3,17 @@ pub use iced_native::clipboard::Action; use crate::command::{self, Command}; -/// A buffer for short-term storage and transfer within and between -/// applications. +#[allow(missing_docs)] #[allow(missing_debug_implementations)] -#[cfg(target_arch = "wasm32")] -pub struct Clipboard; - -#[cfg(target_arch = "wasm32")] -impl Clipboard { - /// Creates a new [`Clipboard`] for the given window. - pub fn connect(_window: &winit::window::Window) -> Clipboard { - Clipboard - } - - /// Reads the current content of the [`Clipboard`] as text. - pub fn read(&self) -> Option { - None - } - - /// Writes the given text contents to the [`Clipboard`]. - pub fn write(&mut self, _contents: String) {} -} - -/// A buffer for short-term storage and transfer within and between -/// applications. -#[allow(missing_debug_implementations)] -#[cfg(not(target_arch = "wasm32"))] pub struct Clipboard { state: State, } -#[cfg(not(target_arch = "wasm32"))] enum State { Connected(window_clipboard::Clipboard), Unavailable, } -#[cfg(not(target_arch = "wasm32"))] impl Clipboard { /// Creates a new [`Clipboard`] for the given window. pub fn connect(window: &winit::window::Window) -> Clipboard { -- cgit From beebf25c5f2fe2a2e6bc860cebfa7e8d2c862cdc Mon Sep 17 00:00:00 2001 From: Kai Mast Date: Thu, 27 Jan 2022 11:28:55 -0600 Subject: Re-add docs for clipboard --- winit/src/clipboard.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'winit/src') diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index 559b3521..1b92b28d 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -3,7 +3,8 @@ pub use iced_native::clipboard::Action; use crate::command::{self, Command}; -#[allow(missing_docs)] +/// A buffer for short-term storage and transfer within and between +/// applications. #[allow(missing_debug_implementations)] pub struct Clipboard { state: State, -- cgit From f39147d3822037955dc27c38cea873bb65c594e3 Mon Sep 17 00:00:00 2001 From: Kai Mast Date: Thu, 27 Jan 2022 14:52:53 -0600 Subject: Always use event_loop.run --- winit/src/application.rs | 107 +++++++++++++---------------------------------- 1 file changed, 30 insertions(+), 77 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index a3715b04..53b7a6c7 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -115,15 +115,10 @@ where use futures::task; use futures::Future; use winit::event_loop::EventLoop; - #[cfg(not(target_arch = "wasm32"))] - use winit::platform::run_return::EventLoopExtRunReturn; let mut debug = Debug::new(); debug.startup_started(); - #[cfg(not(target_arch = "wasm32"))] - let mut event_loop = EventLoop::with_user_event(); - #[cfg(target_arch = "wasm32")] let event_loop = EventLoop::with_user_event(); let mut proxy = event_loop.create_proxy(); @@ -183,81 +178,39 @@ where let mut context = task::Context::from_waker(task::noop_waker_ref()); - #[cfg(not(target_arch = "wasm32"))] - { - event_loop.run_return(move |event, _, control_flow| { - use winit::event_loop::ControlFlow; + event_loop.run(move |event, _, control_flow| { + use winit::event_loop::ControlFlow; - if let ControlFlow::Exit = control_flow { - return; - } - - let event = match event { - winit::event::Event::WindowEvent { - event: - winit::event::WindowEvent::ScaleFactorChanged { - new_inner_size, - .. - }, - window_id, - } => Some(winit::event::Event::WindowEvent { - event: winit::event::WindowEvent::Resized(*new_inner_size), - window_id, - }), - _ => event.to_static(), - }; - - if let Some(event) = event { - sender.start_send(event).expect("Send event"); - - let poll = instance.as_mut().poll(&mut context); - - *control_flow = match poll { - task::Poll::Pending => ControlFlow::Wait, - task::Poll::Ready(_) => ControlFlow::Exit, - }; - } - }); - - Ok(()) - } - - #[cfg(target_arch = "wasm32")] - { - event_loop.run(move |event, _, control_flow| { - use winit::event_loop::ControlFlow; - - if let ControlFlow::Exit = control_flow { - return; - } + if let ControlFlow::Exit = control_flow { + return; + } - let event = match event { - winit::event::Event::WindowEvent { - event: - winit::event::WindowEvent::ScaleFactorChanged { - new_inner_size, - .. - }, - window_id, - } => Some(winit::event::Event::WindowEvent { - event: winit::event::WindowEvent::Resized(*new_inner_size), - window_id, - }), - _ => event.to_static(), + let event = match event { + winit::event::Event::WindowEvent { + event: + winit::event::WindowEvent::ScaleFactorChanged { + new_inner_size, + .. + }, + window_id, + } => Some(winit::event::Event::WindowEvent { + event: winit::event::WindowEvent::Resized(*new_inner_size), + window_id, + }), + _ => event.to_static(), + }; + + if let Some(event) = event { + sender.start_send(event).expect("Send event"); + + let poll = instance.as_mut().poll(&mut context); + + *control_flow = match poll { + task::Poll::Pending => ControlFlow::Wait, + task::Poll::Ready(_) => ControlFlow::Exit, }; - - if let Some(event) = event { - sender.start_send(event).expect("Send event"); - - let poll = instance.as_mut().poll(&mut context); - - *control_flow = match poll { - task::Poll::Pending => ControlFlow::Wait, - task::Poll::Ready(_) => ControlFlow::Exit, - }; - } - }); - } + } + }); } async fn run_instance( -- cgit From 26d95fdc4b7b6a66431d45f49edd0cc3ef19823f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 28 Jan 2022 16:55:16 +0700 Subject: Append `Canvas` to `` when targetting Wasm in `iced_winit` --- winit/src/application.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 53b7a6c7..7ddb9947 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -148,6 +148,21 @@ where .build(&event_loop) .map_err(Error::WindowCreationFailed)?; + #[cfg(target_arch = "wasm32")] + { + use winit::platform::web::WindowExtWebSys; + + let canvas = window.canvas(); + + let window = web_sys::window().unwrap(); + let document = window.document().unwrap(); + let body = document.body().unwrap(); + + let _ = body + .append_child(&canvas) + .expect("Append canvas to HTML body"); + } + let mut clipboard = Clipboard::connect(&window); run_command( -- cgit From 6f604ab3995cb345aacf183a569589988aa3ad1f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 31 Jan 2022 16:39:46 +0700 Subject: Allow `Application::run` to return on native platforms --- winit/src/application.rs | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 7ddb9947..ed077507 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -193,7 +193,7 @@ where let mut context = task::Context::from_waker(task::noop_waker_ref()); - event_loop.run(move |event, _, control_flow| { + platform::run(event_loop, move |event, _, control_flow| { use winit::event_loop::ControlFlow; if let ControlFlow::Exit = control_flow { @@ -225,7 +225,7 @@ where task::Poll::Ready(_) => ControlFlow::Exit, }; } - }); + }) } async fn run_instance( @@ -574,3 +574,43 @@ pub fn run_command( } } } + +#[cfg(not(target_arch = "wasm32"))] +mod platform { + pub fn run( + mut event_loop: winit::event_loop::EventLoop, + event_handler: F, + ) -> Result<(), super::Error> + where + F: 'static + + FnMut( + winit::event::Event<'_, T>, + &winit::event_loop::EventLoopWindowTarget, + &mut winit::event_loop::ControlFlow, + ), + { + use winit::platform::run_return::EventLoopExtRunReturn; + + let _ = event_loop.run_return(event_handler); + + Ok(()) + } +} + +#[cfg(target_arch = "wasm32")] +mod platform { + pub fn run( + event_loop: winit::event_loop::EventLoop, + event_handler: F, + ) -> ! + where + F: 'static + + FnMut( + winit::event::Event<'_, T>, + &winit::event_loop::EventLoopWindowTarget, + &mut winit::event_loop::ControlFlow, + ), + { + event_loop.run(event_handler) + } +} -- cgit