From 3a0d34c0240f4421737a6a08761f99d6f8140d02 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Mar 2023 05:37:11 +0100 Subject: Create `iced_widget` subcrate and re-organize the whole codebase --- renderer/src/window/compositor.rs | 132 -------------------------------------- 1 file changed, 132 deletions(-) delete mode 100644 renderer/src/window/compositor.rs (limited to 'renderer/src/window') diff --git a/renderer/src/window/compositor.rs b/renderer/src/window/compositor.rs deleted file mode 100644 index a11374ed..00000000 --- a/renderer/src/window/compositor.rs +++ /dev/null @@ -1,132 +0,0 @@ -use crate::{Backend, Color, Error, Renderer, Settings, Viewport}; - -use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; - -pub use iced_graphics::window::compositor::{Information, SurfaceError}; - -pub enum Compositor { - Wgpu(iced_wgpu::window::Compositor), - TinySkia(iced_tiny_skia::window::Compositor), -} - -pub enum Surface { - Wgpu(iced_wgpu::window::Surface), - TinySkia(iced_tiny_skia::window::Surface), -} - -impl iced_graphics::window::Compositor for Compositor { - type Settings = Settings; - type Renderer = Renderer; - type Surface = Surface; - - fn new( - settings: Self::Settings, - _compatible_window: Option<&W>, - ) -> Result<(Self, Self::Renderer), Error> { - //let (compositor, backend) = iced_wgpu::window::compositor::new( - // iced_wgpu::Settings { - // default_font: settings.default_font, - // default_text_size: settings.default_text_size, - // antialiasing: settings.antialiasing, - // ..iced_wgpu::Settings::from_env() - // }, - // compatible_window, - //)?; - - //Ok(( - // Self::Wgpu(compositor), - // Renderer::new(Backend::Wgpu(backend)), - //)) - let (compositor, backend) = - iced_tiny_skia::window::compositor::new(iced_tiny_skia::Settings { - default_font: settings.default_font, - default_text_size: settings.default_text_size, - }); - - Ok(( - Self::TinySkia(compositor), - Renderer::new(Backend::TinySkia(backend)), - )) - } - - fn create_surface( - &mut self, - window: &W, - width: u32, - height: u32, - ) -> Surface { - match self { - Self::Wgpu(compositor) => { - Surface::Wgpu(compositor.create_surface(window, width, height)) - } - Self::TinySkia(compositor) => Surface::TinySkia( - compositor.create_surface(window, width, height), - ), - } - } - - fn configure_surface( - &mut self, - surface: &mut Surface, - width: u32, - height: u32, - ) { - match (self, surface) { - (Self::Wgpu(compositor), Surface::Wgpu(surface)) => { - compositor.configure_surface(surface, width, height); - } - (Self::TinySkia(compositor), Surface::TinySkia(surface)) => { - compositor.configure_surface(surface, width, height); - } - _ => unreachable!(), - } - } - - fn fetch_information(&self) -> Information { - match self { - Self::Wgpu(compositor) => compositor.fetch_information(), - Self::TinySkia(compositor) => compositor.fetch_information(), - } - } - - fn present>( - &mut self, - renderer: &mut Self::Renderer, - surface: &mut Self::Surface, - viewport: &Viewport, - background_color: Color, - overlay: &[T], - ) -> Result<(), SurfaceError> { - renderer.with_primitives(|backend, primitives| { - match (self, backend, surface) { - ( - Self::Wgpu(compositor), - Backend::Wgpu(backend), - Surface::Wgpu(surface), - ) => iced_wgpu::window::compositor::present( - compositor, - backend, - surface, - primitives, - viewport, - background_color, - overlay, - ), - ( - Self::TinySkia(compositor), - Backend::TinySkia(backend), - Surface::TinySkia(surface), - ) => iced_tiny_skia::window::compositor::present( - compositor, - backend, - surface, - primitives, - viewport, - background_color, - overlay, - ), - _ => unreachable!(), - } - }) - } -} -- cgit