Merge pull request #1845 from bungoboingo/feat/offscreen-rendering

Feat: Offscreen Rendering & Screenshots
This commit is contained in:
Héctor Ramón 2023-06-27 20:37:19 +02:00 committed by GitHub
commit f6966268bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 921 additions and 24 deletions

View file

@ -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 || {