Scaffold iced_tiny_skia and connect it to iced_renderer
This commit is contained in:
parent
a01bc865a0
commit
8c373cd497
10 changed files with 318 additions and 12 deletions
|
|
@ -7,12 +7,14 @@ use std::borrow::Cow;
|
|||
|
||||
pub enum Backend {
|
||||
Wgpu(iced_wgpu::Backend),
|
||||
TinySkia(iced_tiny_skia::Backend),
|
||||
}
|
||||
|
||||
impl iced_graphics::Backend for Backend {
|
||||
fn trim_measurements(&mut self) {
|
||||
match self {
|
||||
Self::Wgpu(backend) => backend.trim_measurements(),
|
||||
Self::TinySkia(backend) => backend.trim_measurements(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -25,12 +27,14 @@ impl backend::Text for Backend {
|
|||
fn default_font(&self) -> Font {
|
||||
match self {
|
||||
Self::Wgpu(backend) => backend.default_font(),
|
||||
Self::TinySkia(backend) => backend.default_font(),
|
||||
}
|
||||
}
|
||||
|
||||
fn default_size(&self) -> f32 {
|
||||
match self {
|
||||
Self::Wgpu(backend) => backend.default_size(),
|
||||
Self::TinySkia(backend) => backend.default_size(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,6 +49,9 @@ impl backend::Text for Backend {
|
|||
Self::Wgpu(backend) => {
|
||||
backend.measure(contents, size, font, bounds)
|
||||
}
|
||||
Self::TinySkia(backend) => {
|
||||
backend.measure(contents, size, font, bounds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -66,6 +73,14 @@ impl backend::Text for Backend {
|
|||
position,
|
||||
nearest_only,
|
||||
),
|
||||
Self::TinySkia(backend) => backend.hit_test(
|
||||
contents,
|
||||
size,
|
||||
font,
|
||||
bounds,
|
||||
position,
|
||||
nearest_only,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,6 +89,9 @@ impl backend::Text for Backend {
|
|||
Self::Wgpu(backend) => {
|
||||
backend.load_font(font);
|
||||
}
|
||||
Self::TinySkia(backend) => {
|
||||
backend.load_font(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -83,6 +101,7 @@ impl backend::Image for Backend {
|
|||
fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
|
||||
match self {
|
||||
Self::Wgpu(backend) => backend.dimensions(handle),
|
||||
Self::TinySkia(backend) => backend.dimensions(handle),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -95,6 +114,7 @@ impl backend::Svg for Backend {
|
|||
) -> Size<u32> {
|
||||
match self {
|
||||
Self::Wgpu(backend) => backend.viewport_dimensions(handle),
|
||||
Self::TinySkia(backend) => backend.viewport_dimensions(handle),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,12 @@ pub use iced_graphics::window::compositor::{Information, SurfaceError};
|
|||
|
||||
pub enum Compositor<Theme> {
|
||||
Wgpu(iced_wgpu::window::Compositor<Theme>),
|
||||
TinySkia(iced_tiny_skia::window::Compositor<Theme>),
|
||||
}
|
||||
|
||||
pub enum Surface {
|
||||
Wgpu(iced_wgpu::window::Surface),
|
||||
TinySkia(iced_tiny_skia::window::Surface),
|
||||
}
|
||||
|
||||
impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
|
||||
|
|
@ -19,21 +21,31 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
|
|||
|
||||
fn new<W: HasRawWindowHandle + HasRawDisplayHandle>(
|
||||
settings: Self::Settings,
|
||||
compatible_window: Option<&W>,
|
||||
_compatible_window: Option<&W>,
|
||||
) -> Result<(Self, Self::Renderer), Error> {
|
||||
let (compositor, backend) = iced_wgpu::window::compositor::new(
|
||||
iced_wgpu::Settings {
|
||||
//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,
|
||||
antialiasing: settings.antialiasing,
|
||||
..iced_wgpu::Settings::from_env()
|
||||
},
|
||||
compatible_window,
|
||||
)?;
|
||||
});
|
||||
|
||||
Ok((
|
||||
Self::Wgpu(compositor),
|
||||
Renderer::new(Backend::Wgpu(backend)),
|
||||
Self::TinySkia(compositor),
|
||||
Renderer::new(Backend::TinySkia(backend)),
|
||||
))
|
||||
}
|
||||
|
||||
|
|
@ -45,6 +57,9 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
|
|||
Self::Wgpu(compositor) => {
|
||||
Surface::Wgpu(compositor.create_surface(window))
|
||||
}
|
||||
Self::TinySkia(compositor) => {
|
||||
Surface::TinySkia(compositor.create_surface(window))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,12 +73,17 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
|
|||
(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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,6 +110,20 @@ impl<Theme> iced_graphics::window::Compositor for Compositor<Theme> {
|
|||
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!(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue