Rename window::Backend to Compositor

This commit is contained in:
Héctor Ramón Jiménez 2020-05-19 20:01:55 +02:00
parent a0ac09122a
commit 4aed0fa4b6
9 changed files with 39 additions and 31 deletions

View file

@ -26,7 +26,7 @@ pub struct Tour {
} }
impl Application for Tour { impl Application for Tour {
type Backend = window::Backend; type Compositor = window::Compositor;
type Executor = executor::Null; type Executor = executor::Null;
type Message = Message; type Message = Message;
type Flags = (); type Flags = ();

View file

@ -1,4 +1,4 @@
//! Display rendering results on windows. //! Display rendering results on windows.
mod backend; mod compositor;
pub use backend::Backend; pub use compositor::Compositor;

View file

@ -6,20 +6,20 @@ use raw_window_handle::HasRawWindowHandle;
/// A window graphics backend for iced powered by `glow`. /// A window graphics backend for iced powered by `glow`.
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct Backend { pub struct Compositor {
connection: surfman::Connection, connection: surfman::Connection,
device: surfman::Device, device: surfman::Device,
gl_context: surfman::Context, gl_context: surfman::Context,
gl: Option<glow::Context>, gl: Option<glow::Context>,
} }
impl iced_native::window::Backend for Backend { impl iced_native::window::Compositor for Compositor {
type Settings = Settings; type Settings = Settings;
type Renderer = Renderer; type Renderer = Renderer;
type Surface = (); type Surface = ();
type SwapChain = Viewport; type SwapChain = Viewport;
fn new(settings: Self::Settings) -> Backend { fn new(_settings: Self::Settings) -> Self {
let connection = surfman::Connection::new().expect("Create connection"); let connection = surfman::Connection::new().expect("Create connection");
let adapter = connection let adapter = connection
@ -40,7 +40,7 @@ impl iced_native::window::Backend for Backend {
.create_context(&context_descriptor) .create_context(&context_descriptor)
.expect("Create context"); .expect("Create context");
Backend { Self {
connection, connection,
device, device,
gl_context, gl_context,
@ -179,7 +179,7 @@ impl iced_native::window::Backend for Backend {
} }
} }
impl Drop for Backend { impl Drop for Compositor {
fn drop(&mut self) { fn drop(&mut self) {
self.device self.device
.destroy_context(&mut self.gl_context) .destroy_context(&mut self.gl_context)

View file

@ -1,6 +1,6 @@
//! Build window-based GUI applications. //! Build window-based GUI applications.
mod backend; mod compositor;
mod event; mod event;
pub use backend::Backend; pub use compositor::Compositor;
pub use event::Event; pub use event::Event;

View file

@ -2,8 +2,8 @@ use crate::mouse;
use raw_window_handle::HasRawWindowHandle; use raw_window_handle::HasRawWindowHandle;
/// A graphics backend that can render to windows. /// A graphics compositor that can draw to windows.
pub trait Backend: Sized { pub trait Compositor: Sized {
/// The settings of the backend. /// The settings of the backend.
type Settings: Default + Clone; type Settings: Default + Clone;

View file

@ -216,7 +216,7 @@ impl<A> iced_winit::Application for Instance<A>
where where
A: Application, A: Application,
{ {
type Backend = iced_wgpu::window::Backend; type Compositor = iced_wgpu::window::Compositor;
type Executor = A::Executor; type Executor = A::Executor;
type Flags = A::Flags; type Flags = A::Flags;
type Message = A::Message; type Message = A::Message;

View file

@ -1,6 +1,6 @@
//! Display rendering results on windows. //! Display rendering results on windows.
mod backend; mod compositor;
mod swap_chain; mod swap_chain;
pub use backend::Backend; pub use compositor::Compositor;
pub use swap_chain::SwapChain; pub use swap_chain::SwapChain;

View file

@ -5,19 +5,19 @@ use raw_window_handle::HasRawWindowHandle;
/// A window graphics backend for iced powered by `wgpu`. /// A window graphics backend for iced powered by `wgpu`.
#[derive(Debug)] #[derive(Debug)]
pub struct Backend { pub struct Compositor {
device: wgpu::Device, device: wgpu::Device,
queue: wgpu::Queue, queue: wgpu::Queue,
format: wgpu::TextureFormat, format: wgpu::TextureFormat,
} }
impl iced_native::window::Backend for Backend { impl iced_native::window::Compositor for Compositor {
type Settings = Settings; type Settings = Settings;
type Renderer = Renderer; type Renderer = Renderer;
type Surface = wgpu::Surface; type Surface = wgpu::Surface;
type SwapChain = SwapChain; type SwapChain = SwapChain;
fn new(settings: Self::Settings) -> Backend { fn new(settings: Self::Settings) -> Self {
let (device, queue) = futures::executor::block_on(async { let (device, queue) = futures::executor::block_on(async {
let adapter = wgpu::Adapter::request( let adapter = wgpu::Adapter::request(
&wgpu::RequestAdapterOptions { &wgpu::RequestAdapterOptions {
@ -43,7 +43,7 @@ impl iced_native::window::Backend for Backend {
.await .await
}); });
Backend { Self {
device, device,
queue, queue,
format: settings.format, format: settings.format,

View file

@ -19,7 +19,7 @@ pub trait Application: Sized {
/// The graphics backend to use to draw the [`Application`]. /// The graphics backend to use to draw the [`Application`].
/// ///
/// [`Application`]: trait.Application.html /// [`Application`]: trait.Application.html
type Backend: window::Backend; type Compositor: window::Compositor;
/// The [`Executor`] that will run commands and subscriptions. /// The [`Executor`] that will run commands and subscriptions.
/// ///
@ -91,7 +91,11 @@ pub trait Application: Sized {
/// [`Application`]: trait.Application.html /// [`Application`]: trait.Application.html
fn view( fn view(
&mut self, &mut self,
) -> Element<'_, Self::Message, <Self::Backend as window::Backend>::Renderer>; ) -> Element<
'_,
Self::Message,
<Self::Compositor as window::Compositor>::Renderer,
>;
/// Returns the current [`Application`] mode. /// Returns the current [`Application`] mode.
/// ///
@ -116,11 +120,11 @@ pub trait Application: Sized {
/// [`Settings`]: struct.Settings.html /// [`Settings`]: struct.Settings.html
fn run( fn run(
settings: Settings<Self::Flags>, settings: Settings<Self::Flags>,
backend_settings: <Self::Backend as window::Backend>::Settings, backend_settings: <Self::Compositor as window::Compositor>::Settings,
) where ) where
Self: 'static, Self: 'static,
{ {
use window::Backend as _; use window::Compositor as _;
use winit::{ use winit::{
event::{self, WindowEvent}, event::{self, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
@ -181,15 +185,15 @@ pub trait Application: Sized {
let mut resized = false; let mut resized = false;
let clipboard = Clipboard::new(&window); let clipboard = Clipboard::new(&window);
let mut backend = Self::Backend::new(backend_settings.clone()); let mut compositor = Self::Compositor::new(backend_settings.clone());
let surface = backend.create_surface(&window); let surface = compositor.create_surface(&window);
let mut renderer = backend.create_renderer(backend_settings); let mut renderer = compositor.create_renderer(backend_settings);
let mut swap_chain = { let mut swap_chain = {
let physical_size = size.physical(); let physical_size = size.physical();
backend.create_swap_chain( compositor.create_swap_chain(
&surface, &surface,
physical_size.width, physical_size.width,
physical_size.height, physical_size.height,
@ -324,7 +328,7 @@ pub trait Application: Sized {
if resized { if resized {
let physical_size = size.physical(); let physical_size = size.physical();
swap_chain = backend.create_swap_chain( swap_chain = compositor.create_swap_chain(
&surface, &surface,
physical_size.width, physical_size.width,
physical_size.height, physical_size.height,
@ -333,7 +337,7 @@ pub trait Application: Sized {
resized = false; resized = false;
} }
let new_mouse_interaction = backend.draw( let new_mouse_interaction = compositor.draw(
&mut renderer, &mut renderer,
&mut swap_chain, &mut swap_chain,
&primitive, &primitive,
@ -414,10 +418,14 @@ pub trait Application: Sized {
fn build_user_interface<'a, A: Application>( fn build_user_interface<'a, A: Application>(
application: &'a mut A, application: &'a mut A,
cache: Cache, cache: Cache,
renderer: &mut <A::Backend as window::Backend>::Renderer, renderer: &mut <A::Compositor as window::Compositor>::Renderer,
size: winit::dpi::LogicalSize<f64>, size: winit::dpi::LogicalSize<f64>,
debug: &mut Debug, debug: &mut Debug,
) -> UserInterface<'a, A::Message, <A::Backend as window::Backend>::Renderer> { ) -> UserInterface<
'a,
A::Message,
<A::Compositor as window::Compositor>::Renderer,
> {
debug.view_started(); debug.view_started();
let view = application.view(); let view = application.view();
debug.view_finished(); debug.view_finished();