diff options
author | 2019-12-06 16:47:40 +0100 | |
---|---|---|
committer | 2019-12-11 20:02:43 +0100 | |
commit | 80324284282f173e4d26e1f297daaf71a93f51a6 (patch) | |
tree | afaf4816e7a9ae4f57616afc2386ff8695f3b3c4 /wgpu/src/renderer.rs | |
parent | c1b9f6652517dcbf5ffd83b5db4a624f9a5b0da4 (diff) | |
download | iced-80324284282f173e4d26e1f297daaf71a93f51a6.tar.gz iced-80324284282f173e4d26e1f297daaf71a93f51a6.tar.bz2 iced-80324284282f173e4d26e1f297daaf71a93f51a6.zip |
Implemented SVG support in iced_wgpu.
Diffstat (limited to 'wgpu/src/renderer.rs')
-rw-r--r-- | wgpu/src/renderer.rs | 34 |
1 files changed, 33 insertions, 1 deletions
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<u32>, quads: Vec<Quad>, images: Vec<Image>, + svgs: Vec<Svg>, text: Vec<wgpu_glyph::Section<'a>>, } @@ -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 |