summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-22 05:27:31 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-22 05:27:31 +0100
commit1f13a91361258a1607c71f4840a26a6437f88612 (patch)
tree972fd3bd7afbab9958d16b8475d42ff3e41df484 /graphics
parentbbafeed13d20f2cbd6fc18b949b34596aa0c6c2e (diff)
downloadiced-1f13a91361258a1607c71f4840a26a6437f88612.tar.gz
iced-1f13a91361258a1607c71f4840a26a6437f88612.tar.bz2
iced-1f13a91361258a1607c71f4840a26a6437f88612.zip
Make `iced_tiny_skia` optional with a `tiny-skia` feature
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/backend.rs3
-rw-r--r--graphics/src/compositor.rs62
-rw-r--r--graphics/src/geometry.rs4
-rw-r--r--graphics/src/geometry/frame.rs3
-rw-r--r--graphics/src/mesh.rs4
5 files changed, 69 insertions, 7 deletions
diff --git a/graphics/src/backend.rs b/graphics/src/backend.rs
index e394c956..e982b54a 100644
--- a/graphics/src/backend.rs
+++ b/graphics/src/backend.rs
@@ -10,6 +10,9 @@ use std::borrow::Cow;
///
/// [`Renderer`]: crate::Renderer
pub trait Backend {
+ /// The compositor of this [`Backend`].
+ type Compositor;
+
/// The custom kind of primitives this [`Backend`] supports.
type Primitive: TryFrom<Mesh, Error = &'static str>;
}
diff --git a/graphics/src/compositor.rs b/graphics/src/compositor.rs
index 91951a8e..32cea46a 100644
--- a/graphics/src/compositor.rs
+++ b/graphics/src/compositor.rs
@@ -15,7 +15,7 @@ pub trait Compositor: Sized {
type Settings: Default;
/// The iced renderer of the backend.
- type Renderer: iced_core::Renderer;
+ type Renderer;
/// The surface of the backend.
type Surface;
@@ -122,3 +122,63 @@ pub struct Information {
/// Contains the graphics backend.
pub backend: String,
}
+
+impl Compositor for () {
+ type Settings = ();
+ type Renderer = ();
+ type Surface = ();
+
+ async fn new<W: Window + Clone>(
+ _settings: Self::Settings,
+ _compatible_window: W,
+ ) -> Result<Self, Error> {
+ Ok(())
+ }
+
+ fn create_renderer(&self) -> Self::Renderer {}
+
+ fn create_surface<W: Window + Clone>(
+ &mut self,
+ _window: W,
+ _width: u32,
+ _height: u32,
+ ) -> Self::Surface {
+ }
+
+ fn configure_surface(
+ &mut self,
+ _surface: &mut Self::Surface,
+ _width: u32,
+ _height: u32,
+ ) {
+ }
+
+ fn fetch_information(&self) -> Information {
+ Information {
+ adapter: String::from("Null Renderer"),
+ backend: String::from("Null"),
+ }
+ }
+
+ fn present<T: AsRef<str>>(
+ &mut self,
+ _renderer: &mut Self::Renderer,
+ _surface: &mut Self::Surface,
+ _viewport: &Viewport,
+ _background_color: Color,
+ _overlay: &[T],
+ ) -> Result<(), SurfaceError> {
+ Ok(())
+ }
+
+ fn screenshot<T: AsRef<str>>(
+ &mut self,
+ _renderer: &mut Self::Renderer,
+ _surface: &mut Self::Surface,
+ _viewport: &Viewport,
+ _background_color: Color,
+ _overlay: &[T],
+ ) -> Vec<u8> {
+ vec![]
+ }
+}
diff --git a/graphics/src/geometry.rs b/graphics/src/geometry.rs
index cc2359b6..194f37b2 100644
--- a/graphics/src/geometry.rs
+++ b/graphics/src/geometry.rs
@@ -18,11 +18,11 @@ pub use text::Text;
pub use crate::gradient::{self, Gradient};
-use crate::core::Size;
+use crate::core::{self, Size};
use crate::Cached;
/// A renderer capable of drawing some [`Self::Geometry`].
-pub trait Renderer: crate::core::Renderer {
+pub trait Renderer: core::Renderer {
/// The kind of geometry this renderer can draw.
type Geometry: Cached;
diff --git a/graphics/src/geometry/frame.rs b/graphics/src/geometry/frame.rs
index b54fca5d..635012d0 100644
--- a/graphics/src/geometry/frame.rs
+++ b/graphics/src/geometry/frame.rs
@@ -1,7 +1,6 @@
//! Draw and generate geometry.
use crate::core::{Point, Radians, Rectangle, Size, Vector};
use crate::geometry::{self, Fill, Path, Stroke, Text};
-use crate::Cached;
/// The region of a surface that can be used to draw geometry.
#[allow(missing_debug_implementations)]
@@ -173,7 +172,7 @@ where
/// of each method.
#[allow(missing_docs)]
pub trait Backend: Sized {
- type Geometry: Cached;
+ type Geometry;
fn width(&self) -> f32;
fn height(&self) -> f32;
diff --git a/graphics/src/mesh.rs b/graphics/src/mesh.rs
index d671f494..20692b07 100644
--- a/graphics/src/mesh.rs
+++ b/graphics/src/mesh.rs
@@ -1,6 +1,6 @@
//! Draw triangles!
use crate::color;
-use crate::core::{self, Rectangle, Size};
+use crate::core::{Rectangle, Size};
use crate::gradient;
use crate::Damage;
@@ -76,7 +76,7 @@ pub struct GradientVertex2D {
}
/// A renderer capable of drawing a [`Mesh`].
-pub trait Renderer: core::Renderer {
+pub trait Renderer {
/// Draws the given [`Mesh`].
fn draw_mesh(&mut self, mesh: Mesh);
}