From 59d45a5440aaa46c7dc8f3dc70c8518167c10418 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 26 Feb 2020 12:34:34 +0100 Subject: Refactor texture atlas - Split into multiple modules - Rename some concepts - Change API details --- wgpu/src/image/vector.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'wgpu/src/image/vector.rs') diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs index 98588e5c..0dabc9ca 100644 --- a/wgpu/src/image/vector.rs +++ b/wgpu/src/image/vector.rs @@ -1,8 +1,6 @@ -use crate::image::{TextureArray, ImageAllocation}; +use crate::texture::atlas::{self, Atlas}; use iced_native::svg; -use std::{ - collections::{HashMap, HashSet}, -}; +use std::collections::{HashMap, HashSet}; pub enum Svg { Loaded(resvg::usvg::Tree), @@ -33,7 +31,7 @@ impl std::fmt::Debug for Svg { pub struct Cache { svgs: HashMap, - rasterized: HashMap<(u64, u32, u32), ImageAllocation>, + rasterized: HashMap<(u64, u32, u32), atlas::Entry>, svg_hits: HashSet, rasterized_hits: HashSet<(u64, u32, u32)>, } @@ -71,8 +69,8 @@ impl Cache { scale: f32, device: &wgpu::Device, encoder: &mut wgpu::CommandEncoder, - texture_array: &mut TextureArray, - ) -> Option<&ImageAllocation> { + texture_atlas: &mut Atlas, + ) -> Option<&atlas::Entry> { let id = handle.id(); let (width, height) = ( @@ -104,10 +102,8 @@ impl Cache { let screen_size = resvg::ScreenSize::new(width, height).unwrap(); - let mut canvas = resvg::raqote::DrawTarget::new( - width as i32, - height as i32, - ); + let mut canvas = + resvg::raqote::DrawTarget::new(width as i32, height as i32); resvg::backend_raqote::render_to_canvas( tree, @@ -116,17 +112,21 @@ impl Cache { &mut canvas, ); - let allocation = texture_array.upload(&canvas, device, encoder); + let allocation = texture_atlas.upload( + width, + height, + canvas.get_data(), + device, + encoder, + )?; let _ = self.svg_hits.insert(id); let _ = self.rasterized_hits.insert((id, width, height)); - let _ = self - .rasterized - .insert((id, width, height), allocation); + let _ = self.rasterized.insert((id, width, height), allocation); self.rasterized.get(&(id, width, height)) } - Svg::NotFound => None + Svg::NotFound => None, } } @@ -145,4 +145,4 @@ impl std::fmt::Debug for Cache { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "vector::Cache") } -} \ No newline at end of file +} -- cgit