summaryrefslogtreecommitdiffstats
path: root/winit/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-09 03:25:13 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-09 03:25:13 +0100
commitf1e20a61f16388ed4d2dac734bab30d67bbd84b3 (patch)
treee4112411df1b0493ecb34aa75ecd04e92e9a82af /winit/src
parent95880ca74bddb6a23774621ef766b91956d40a61 (diff)
downloadiced-f1e20a61f16388ed4d2dac734bab30d67bbd84b3.tar.gz
iced-f1e20a61f16388ed4d2dac734bab30d67bbd84b3.tar.bz2
iced-f1e20a61f16388ed4d2dac734bab30d67bbd84b3.zip
Allow `iced_wgpu` to render to any `TextureView`
Diffstat (limited to 'winit/src')
-rw-r--r--winit/src/application.rs39
1 files changed, 23 insertions, 16 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 3c0332ed..0d90525a 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -14,10 +14,10 @@ use crate::{
/// An [`Application`](trait.Application.html) can execute asynchronous actions
/// by returning a [`Command`](struct.Command.html) in some of its methods.
pub trait Application: Sized {
- /// The renderer to use to draw the [`Application`].
+ /// The graphics backend to use to draw the [`Application`].
///
/// [`Application`]: trait.Application.html
- type Renderer: window::Renderer;
+ type Backend: window::Backend;
/// The [`Executor`] that will run commands and subscriptions.
///
@@ -75,7 +75,9 @@ pub trait Application: Sized {
/// These widgets can produce __messages__ based on user interaction.
///
/// [`Application`]: trait.Application.html
- fn view(&mut self) -> Element<'_, Self::Message, Self::Renderer>;
+ fn view(
+ &mut self,
+ ) -> Element<'_, Self::Message, <Self::Backend as window::Backend>::Renderer>;
/// Returns the current [`Application`] mode.
///
@@ -99,11 +101,11 @@ pub trait Application: Sized {
/// [`Application`]: trait.Application.html
fn run(
settings: Settings,
- renderer_settings: <Self::Renderer as window::Renderer>::Settings,
+ backend_settings: <Self::Backend as window::Backend>::Settings,
) where
Self: 'static,
{
- use window::{Renderer as _, Target as _};
+ use window::Backend as _;
use winit::{
event::{self, WindowEvent},
event_loop::{ControlFlow, EventLoop},
@@ -162,17 +164,18 @@ pub trait Application: Sized {
let mut resized = false;
let clipboard = Clipboard::new(&window);
- let mut renderer = Self::Renderer::new(renderer_settings);
+ let (mut backend, mut renderer) = Self::Backend::new(backend_settings);
- let mut target = {
+ let surface = backend.create_surface(&window);
+
+ let mut swap_chain = {
let physical_size = size.physical();
- <Self::Renderer as window::Renderer>::Target::new(
- &window,
+ backend.create_swap_chain(
+ &surface,
physical_size.width,
physical_size.height,
size.scale_factor(),
- &renderer,
)
};
@@ -306,18 +309,22 @@ pub trait Application: Sized {
if resized {
let physical_size = size.physical();
- target.resize(
+ swap_chain = backend.create_swap_chain(
+ &surface,
physical_size.width,
physical_size.height,
size.scale_factor(),
- &renderer,
);
resized = false;
}
- let new_mouse_cursor =
- renderer.draw(&primitive, &debug.overlay(), &mut target);
+ let new_mouse_cursor = backend.draw(
+ &mut renderer,
+ &mut swap_chain,
+ &primitive,
+ &debug.overlay(),
+ );
debug.render_finished();
@@ -451,10 +458,10 @@ pub trait Application: Sized {
fn build_user_interface<'a, A: Application>(
application: &'a mut A,
cache: Cache,
- renderer: &mut A::Renderer,
+ renderer: &mut <A::Backend as window::Backend>::Renderer,
size: winit::dpi::LogicalSize<f64>,
debug: &mut Debug,
-) -> UserInterface<'a, A::Message, A::Renderer> {
+) -> UserInterface<'a, A::Message, <A::Backend as window::Backend>::Renderer> {
debug.view_started();
let view = application.view();
debug.view_finished();