diff options
Diffstat (limited to '')
| -rw-r--r-- | wgpu/src/window.rs | 2 | ||||
| -rw-r--r-- | wgpu/src/window/compositor.rs | 33 | ||||
| -rw-r--r-- | wgpu/src/window/swap_chain.rs | 61 | 
3 files changed, 20 insertions, 76 deletions
| diff --git a/wgpu/src/window.rs b/wgpu/src/window.rs index 391d3e36..aac5fb9e 100644 --- a/wgpu/src/window.rs +++ b/wgpu/src/window.rs @@ -1,6 +1,4 @@  //! Display rendering results on windows.  mod compositor; -mod swap_chain;  pub use compositor::Compositor; -pub use swap_chain::SwapChain; diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 8950ffd4..7eba8924 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -1,5 +1,6 @@ -use crate::{window::SwapChain, Renderer, Settings, Target}; +use crate::{Renderer, Settings}; +use iced_graphics::Viewport;  use iced_native::{futures, mouse};  use raw_window_handle::HasRawWindowHandle; @@ -11,11 +12,11 @@ pub struct Compositor {      format: wgpu::TextureFormat,  } -impl iced_native::window::Compositor for Compositor { +impl iced_graphics::window::Compositor for Compositor {      type Settings = Settings;      type Renderer = Renderer;      type Surface = wgpu::Surface; -    type SwapChain = SwapChain; +    type SwapChain = wgpu::SwapChain;      fn new(settings: Self::Settings) -> Self {          let (device, queue) = futures::executor::block_on(async { @@ -66,19 +67,28 @@ impl iced_native::window::Compositor for Compositor {          surface: &Self::Surface,          width: u32,          height: u32, -    ) -> SwapChain { -        SwapChain::new(&self.device, surface, self.format, width, height) +    ) -> Self::SwapChain { +        self.device.create_swap_chain( +            surface, +            &wgpu::SwapChainDescriptor { +                usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, +                format: self.format, +                width, +                height, +                present_mode: wgpu::PresentMode::Mailbox, +            }, +        )      }      fn draw<T: AsRef<str>>(          &mut self,          renderer: &mut Self::Renderer, -        swap_chain: &mut SwapChain, +        swap_chain: &mut Self::SwapChain, +        viewport: &Viewport,          output: &<Self::Renderer as iced_native::Renderer>::Output, -        scale_factor: f64,          overlay: &[T],      ) -> mouse::Interaction { -        let (frame, viewport) = swap_chain.next_frame().expect("Next frame"); +        let frame = swap_chain.get_next_texture().expect("Next frame");          let mut encoder = self.device.create_command_encoder(              &wgpu::CommandEncoderDescriptor { label: None }, @@ -103,12 +113,9 @@ impl iced_native::window::Compositor for Compositor {          let mouse_interaction = renderer.backend_mut().draw(              &mut self.device,              &mut encoder, -            Target { -                texture: &frame.view, -                viewport, -            }, +            &frame.view, +            viewport,              output, -            scale_factor,              overlay,          ); diff --git a/wgpu/src/window/swap_chain.rs b/wgpu/src/window/swap_chain.rs deleted file mode 100644 index 72e58a50..00000000 --- a/wgpu/src/window/swap_chain.rs +++ /dev/null @@ -1,61 +0,0 @@ -use crate::Viewport; - -/// The rendering target of a window. -/// -/// It represents a series of virtual framebuffers with a scale factor. -#[derive(Debug)] -pub struct SwapChain { -    raw: wgpu::SwapChain, -    viewport: Viewport, -} - -impl SwapChain {} - -impl SwapChain { -    /// Creates a new [`SwapChain`] for the given surface. -    /// -    /// [`SwapChain`]: struct.SwapChain.html -    pub fn new( -        device: &wgpu::Device, -        surface: &wgpu::Surface, -        format: wgpu::TextureFormat, -        width: u32, -        height: u32, -    ) -> SwapChain { -        SwapChain { -            raw: new_swap_chain(surface, format, width, height, device), -            viewport: Viewport::new(width, height), -        } -    } - -    /// Returns the next frame of the [`SwapChain`] alongside its [`Viewport`]. -    /// -    /// [`SwapChain`]: struct.SwapChain.html -    /// [`Viewport`]: ../struct.Viewport.html -    pub fn next_frame( -        &mut self, -    ) -> Result<(wgpu::SwapChainOutput, &Viewport), wgpu::TimeOut> { -        let viewport = &self.viewport; - -        self.raw.get_next_texture().map(|output| (output, viewport)) -    } -} - -fn new_swap_chain( -    surface: &wgpu::Surface, -    format: wgpu::TextureFormat, -    width: u32, -    height: u32, -    device: &wgpu::Device, -) -> wgpu::SwapChain { -    device.create_swap_chain( -        &surface, -        &wgpu::SwapChainDescriptor { -            usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, -            format, -            width, -            height, -            present_mode: wgpu::PresentMode::Mailbox, -        }, -    ) -} | 
