diff options
author | 2023-06-27 20:37:19 +0200 | |
---|---|---|
committer | 2023-06-27 20:37:19 +0200 | |
commit | f6966268bb6d58b4b03ba61fc5732e1bf016e2a1 (patch) | |
tree | c8e79670b59fdd19103cb1a3a6d18783136e2294 /winit | |
parent | ef18ecf4ef0fe654578380059b467fe2fb34aa0a (diff) | |
parent | 5b6e205e998cbb20b3c8aaff8b515d78315d6703 (diff) | |
download | iced-f6966268bb6d58b4b03ba61fc5732e1bf016e2a1.tar.gz iced-f6966268bb6d58b4b03ba61fc5732e1bf016e2a1.tar.bz2 iced-f6966268bb6d58b4b03ba61fc5732e1bf016e2a1.zip |
Merge pull request #1845 from bungoboingo/feat/offscreen-rendering
Feat: Offscreen Rendering & Screenshots
Diffstat (limited to 'winit')
-rw-r--r-- | winit/src/application.rs | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs index be416ac8..6e7b94ef 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -308,6 +308,8 @@ async fn run_instance<A, E, C>( run_command( &application, + &mut compositor, + &mut surface, &mut cache, &state, &mut renderer, @@ -318,7 +320,6 @@ async fn run_instance<A, E, C>( &mut proxy, &mut debug, &window, - || compositor.fetch_information(), ); runtime.track(application.subscription().into_recipes()); @@ -382,6 +383,8 @@ async fn run_instance<A, E, C>( // Update application update( &mut application, + &mut compositor, + &mut surface, &mut cache, &state, &mut renderer, @@ -392,7 +395,6 @@ async fn run_instance<A, E, C>( &mut debug, &mut messages, &window, - || compositor.fetch_information(), ); // Update window @@ -645,8 +647,10 @@ where /// Updates an [`Application`] by feeding it the provided messages, spawning any /// resulting [`Command`], and tracking its [`Subscription`]. -pub fn update<A: Application, E: Executor>( +pub fn update<A: Application, C, E: Executor>( application: &mut A, + compositor: &mut C, + surface: &mut C::Surface, cache: &mut user_interface::Cache, state: &State<A>, renderer: &mut A::Renderer, @@ -657,8 +661,8 @@ pub fn update<A: Application, E: Executor>( debug: &mut Debug, messages: &mut Vec<A::Message>, window: &winit::window::Window, - graphics_info: impl FnOnce() -> compositor::Information + Copy, ) where + C: Compositor<Renderer = A::Renderer> + 'static, <A::Renderer as core::Renderer>::Theme: StyleSheet, { for message in messages.drain(..) { @@ -676,6 +680,8 @@ pub fn update<A: Application, E: Executor>( run_command( application, + compositor, + surface, cache, state, renderer, @@ -686,7 +692,6 @@ pub fn update<A: Application, E: Executor>( proxy, debug, window, - graphics_info, ); } @@ -695,8 +700,10 @@ pub fn update<A: Application, E: Executor>( } /// Runs the actions of a [`Command`]. -pub fn run_command<A, E>( +pub fn run_command<A, C, E>( application: &A, + compositor: &mut C, + surface: &mut C::Surface, cache: &mut user_interface::Cache, state: &State<A>, renderer: &mut A::Renderer, @@ -707,10 +714,10 @@ pub fn run_command<A, E>( proxy: &mut winit::event_loop::EventLoopProxy<A::Message>, debug: &mut Debug, window: &winit::window::Window, - _graphics_info: impl FnOnce() -> compositor::Information + Copy, ) where A: Application, E: Executor, + C: Compositor<Renderer = A::Renderer> + 'static, <A::Renderer as core::Renderer>::Theme: StyleSheet, { use crate::runtime::command; @@ -802,12 +809,28 @@ pub fn run_command<A, E>( .send_event(tag(window.id().into())) .expect("Send message to event loop"); } + window::Action::Screenshot(tag) => { + let bytes = compositor.screenshot( + renderer, + surface, + state.viewport(), + state.background_color(), + &debug.overlay(), + ); + + proxy + .send_event(tag(window::Screenshot::new( + bytes, + state.physical_size(), + ))) + .expect("Send message to event loop.") + } }, command::Action::System(action) => match action { system::Action::QueryInformation(_tag) => { #[cfg(feature = "system")] { - let graphics_info = _graphics_info(); + let graphics_info = compositor.fetch_information(); let proxy = proxy.clone(); let _ = std::thread::spawn(move || { |