From 80324284282f173e4d26e1f297daaf71a93f51a6 Mon Sep 17 00:00:00 2001 From: Malte Veerman Date: Fri, 6 Dec 2019 16:47:40 +0100 Subject: Implemented SVG support in iced_wgpu. --- wgpu/src/renderer.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'wgpu/src/renderer.rs') diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index fa52bd96..9895e1c4 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -1,4 +1,4 @@ -use crate::{quad, text, Image, Primitive, Quad, Transformation}; +use crate::{quad, text, Image, Primitive, Quad, Svg, Transformation}; use iced_native::{ renderer::{Debugger, Windowed}, Background, Color, Layout, MouseCursor, Point, Rectangle, Vector, Widget, @@ -23,6 +23,7 @@ pub struct Renderer { queue: Queue, quad_pipeline: quad::Pipeline, image_pipeline: crate::image::Pipeline, + svg_pipeline: crate::svg::Pipeline, text_pipeline: text::Pipeline, } @@ -31,6 +32,7 @@ struct Layer<'a> { offset: Vector, quads: Vec, images: Vec, + svgs: Vec, text: Vec>, } @@ -41,6 +43,7 @@ impl<'a> Layer<'a> { offset, quads: Vec::new(), images: Vec::new(), + svgs: Vec::new(), text: Vec::new(), } } @@ -64,12 +67,14 @@ impl Renderer { let text_pipeline = text::Pipeline::new(&mut device); let quad_pipeline = quad::Pipeline::new(&mut device); let image_pipeline = crate::image::Pipeline::new(&mut device); + let svg_pipeline = crate::svg::Pipeline::new(&mut device); Self { device, queue, quad_pipeline, image_pipeline, + svg_pipeline, text_pipeline, } } @@ -128,6 +133,7 @@ impl Renderer { self.queue.submit(&[encoder.finish()]); self.image_pipeline.trim_cache(); + self.svg_pipeline.trim_cache(); *mouse_cursor } @@ -237,6 +243,13 @@ impl Renderer { scale: [bounds.width, bounds.height], }); } + Primitive::Svg { handle, bounds } => { + layer.svgs.push(Svg { + handle: handle.clone(), + position: [bounds.x, bounds.y], + scale: [bounds.width, bounds.height], + }) + }, Primitive::Clip { bounds, offset, @@ -345,6 +358,25 @@ impl Renderer { ); } + if layer.svgs.len() > 0 { + let translated = transformation + * Transformation::translate( + -(layer.offset.x as f32), + -(layer.offset.y as f32), + ); + + self.svg_pipeline.draw( + &mut self.device, + encoder, + &layer.svgs, + translated, + bounds, + target, + (dpi * 96.0) as u16, + (dpi * 20.0) as u16, + ); + } + if layer.text.len() > 0 { for text in layer.text.iter() { // Target physical coordinates directly to avoid blurry text -- cgit From 5696afcadd5b3b89a532f4205efac30d8a24d558 Mon Sep 17 00:00:00 2001 From: Malte Veerman Date: Wed, 11 Dec 2019 22:13:29 +0100 Subject: Ran cargo_fmt over changed files. --- wgpu/src/renderer.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'wgpu/src/renderer.rs') diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index 9895e1c4..92e24933 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -243,13 +243,11 @@ impl Renderer { scale: [bounds.width, bounds.height], }); } - Primitive::Svg { handle, bounds } => { - layer.svgs.push(Svg { - handle: handle.clone(), - position: [bounds.x, bounds.y], - scale: [bounds.width, bounds.height], - }) - }, + Primitive::Svg { handle, bounds } => layer.svgs.push(Svg { + handle: handle.clone(), + position: [bounds.x, bounds.y], + scale: [bounds.width, bounds.height], + }), Primitive::Clip { bounds, offset, -- cgit From f737c6da24d5c75e3efa92c0fd9d0d11fbd715c1 Mon Sep 17 00:00:00 2001 From: Malte Veerman Date: Thu, 12 Dec 2019 00:20:06 +0100 Subject: Improved dpi handling --- wgpu/src/renderer.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'wgpu/src/renderer.rs') diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index 92e24933..3eb8c5ca 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -370,8 +370,7 @@ impl Renderer { translated, bounds, target, - (dpi * 96.0) as u16, - (dpi * 20.0) as u16, + dpi, ); } -- cgit From 895eaef99b52c24e6f3d804897ad850c1f1de960 Mon Sep 17 00:00:00 2001 From: Malte Veerman Date: Thu, 12 Dec 2019 01:14:54 +0100 Subject: Merged svg pipeline into image --- wgpu/src/renderer.rs | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'wgpu/src/renderer.rs') diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index 3eb8c5ca..d1d4de14 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -1,4 +1,4 @@ -use crate::{quad, text, Image, Primitive, Quad, Svg, Transformation}; +use crate::{quad, text, Image, Primitive, Quad, Transformation}; use iced_native::{ renderer::{Debugger, Windowed}, Background, Color, Layout, MouseCursor, Point, Rectangle, Vector, Widget, @@ -23,7 +23,6 @@ pub struct Renderer { queue: Queue, quad_pipeline: quad::Pipeline, image_pipeline: crate::image::Pipeline, - svg_pipeline: crate::svg::Pipeline, text_pipeline: text::Pipeline, } @@ -32,7 +31,6 @@ struct Layer<'a> { offset: Vector, quads: Vec, images: Vec, - svgs: Vec, text: Vec>, } @@ -43,7 +41,6 @@ impl<'a> Layer<'a> { offset, quads: Vec::new(), images: Vec::new(), - svgs: Vec::new(), text: Vec::new(), } } @@ -67,14 +64,12 @@ impl Renderer { let text_pipeline = text::Pipeline::new(&mut device); let quad_pipeline = quad::Pipeline::new(&mut device); let image_pipeline = crate::image::Pipeline::new(&mut device); - let svg_pipeline = crate::svg::Pipeline::new(&mut device); Self { device, queue, quad_pipeline, image_pipeline, - svg_pipeline, text_pipeline, } } @@ -133,7 +128,6 @@ impl Renderer { self.queue.submit(&[encoder.finish()]); self.image_pipeline.trim_cache(); - self.svg_pipeline.trim_cache(); *mouse_cursor } @@ -243,11 +237,6 @@ impl Renderer { scale: [bounds.width, bounds.height], }); } - Primitive::Svg { handle, bounds } => layer.svgs.push(Svg { - handle: handle.clone(), - position: [bounds.x, bounds.y], - scale: [bounds.width, bounds.height], - }), Primitive::Clip { bounds, offset, @@ -353,23 +342,6 @@ impl Renderer { translated_and_scaled, bounds, target, - ); - } - - if layer.svgs.len() > 0 { - let translated = transformation - * Transformation::translate( - -(layer.offset.x as f32), - -(layer.offset.y as f32), - ); - - self.svg_pipeline.draw( - &mut self.device, - encoder, - &layer.svgs, - translated, - bounds, - target, dpi, ); } -- cgit From 09707f29fcf7fbd71570a43db214921043427c3f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 15 Dec 2019 06:19:07 +0100 Subject: Rerasterize SVGs when resized and refactor a bit --- wgpu/src/renderer.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'wgpu/src/renderer.rs') diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs index d1d4de14..365ef1ef 100644 --- a/wgpu/src/renderer.rs +++ b/wgpu/src/renderer.rs @@ -1,4 +1,4 @@ -use crate::{quad, text, Image, Primitive, Quad, Transformation}; +use crate::{image, quad, text, Image, Primitive, Quad, Transformation}; use iced_native::{ renderer::{Debugger, Windowed}, Background, Color, Layout, MouseCursor, Point, Rectangle, Vector, Widget, @@ -232,7 +232,14 @@ impl Renderer { } Primitive::Image { handle, bounds } => { layer.images.push(Image { - handle: handle.clone(), + handle: image::Handle::Raster(handle.clone()), + position: [bounds.x, bounds.y], + scale: [bounds.width, bounds.height], + }); + } + Primitive::Svg { handle, bounds } => { + layer.images.push(Image { + handle: image::Handle::Vector(handle.clone()), position: [bounds.x, bounds.y], scale: [bounds.width, bounds.height], }); -- cgit