this repo has no description
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

:recycle: Remove unused pixmap cache leftovers

+27 -73
-38
src/graphics/canvas.rs
··· 251 251 ((resolution as f32 * aspect_ratio) as u32, resolution) 252 252 } 253 253 } 254 - 255 - // previous_frame_at gives path to the previously rendered frame, which allows to copy on cache hits instead of having to re-write bytes again 256 - pub fn render_to_png( 257 - &mut self, 258 - at: &str, 259 - resolution: u32, 260 - previous_frame_at: Option<&str>, 261 - ) -> anyhow::Result<()> { 262 - debug_time!("render_to_png"); 263 - let (width, height) = self.resolution_to_size(resolution); 264 - if let Some(previous_frame_at) = previous_frame_at { 265 - match self.render_to_pixmap(width, height)? { 266 - None => { 267 - std::fs::copy(previous_frame_at, at)?; 268 - } 269 - Some(pixmap) => pixmap_to_png_data(pixmap) 270 - .and_then(|data| write_png_data(data, at))?, 271 - } 272 - return Ok(()); 273 - } 274 - 275 - self.render_to_pixmap_no_cache(width, height) 276 - .and_then(|pixmap| { 277 - pixmap_to_png_data(pixmap) 278 - .and_then(|data| write_png_data(data, at)) 279 - }) 280 - } 281 - } 282 - 283 - fn pixmap_to_png_data(pixmap: tiny_skia::Pixmap) -> anyhow::Result<Vec<u8>> { 284 - debug_time!("\tpixmap_to_png_data"); 285 - Ok(pixmap.encode_png()?) 286 - } 287 - 288 - fn write_png_data(data: Vec<u8>, at: &str) -> anyhow::Result<()> { 289 - debug_time!("\twrite_png_data"); 290 - std::fs::write(at, data)?; 291 - Ok(()) 292 254 } 293 255 294 256 impl Canvas {
-1
src/main.rs
··· 51 51 match canvas.render_to_png( 52 52 &args.arg_file, 53 53 args.flag_resolution.unwrap_or(1000), 54 - None, 55 54 ) { 56 55 Ok(_) => println!("Image saved to {}", args.arg_file), 57 56 Err(e) => println!("Error saving image: {}", e),
+26 -33
src/rendering/canvas.rs
··· 84 84 Ok(pixmap) 85 85 } 86 86 87 - pub fn render_to_pixmap_no_cache( 87 + pub fn render_to_pixmap( 88 88 &mut self, 89 89 width: u32, 90 90 height: u32, ··· 100 100 self.svg_to_pixmap(width, height, &svg_contents) 101 101 } 102 102 103 - // Returns None if we had a render cache hit -- pixmap is in self.png_render_cache in that case 104 - pub fn render_to_pixmap( 105 - &mut self, 106 - width: u32, 107 - height: u32, 108 - ) -> anyhow::Result<Option<tiny_skia::Pixmap>> { 109 - debug_time!("render_to_pixmap"); 110 - 111 - self.load_fonts()?; 112 - 113 - let new_svg_contents = self 114 - .render_to_svg( 115 - self.colormap.clone(), 116 - self.cell_size, 117 - self.object_sizes, 118 - "", 119 - )? 120 - .to_string(); 121 - if let Some(cached_svg) = &self.png_render_cache { 122 - if *cached_svg == new_svg_contents { 123 - // TODO find a way to avoid .cloneing the pixmap 124 - return Ok(None); 125 - } 126 - } 127 - 128 - let pixmap = self.svg_to_pixmap(width, height, &new_svg_contents)?; 129 - 130 - self.png_render_cache = Some(new_svg_contents); 131 - 132 - Ok(Some(pixmap)) 133 - } 134 - 135 103 fn usvg_tree_to_pixmap( 136 104 &self, 137 105 width: u32, ··· 154 122 debug_time!("create_pixmap"); 155 123 tiny_skia::Pixmap::new(width, height).expect("Failed to create pixmap") 156 124 } 125 + 126 + // previous_frame_at gives path to the previously rendered frame, which allows to copy on cache hits instead of having to re-write bytes again 127 + pub fn render_to_png( 128 + &mut self, 129 + at: &str, 130 + resolution: u32, 131 + ) -> anyhow::Result<()> { 132 + debug_time!("render_to_png"); 133 + let (width, height) = self.resolution_to_size(resolution); 134 + 135 + self.render_to_pixmap(width, height).and_then(|pixmap| { 136 + pixmap_to_png_data(pixmap).and_then(|data| write_png_data(data, at)) 137 + }) 138 + } 157 139 } 158 140 159 141 fn svg_to_usvg_tree( ··· 172 154 }, 173 155 )?) 174 156 } 157 + 158 + fn pixmap_to_png_data(pixmap: tiny_skia::Pixmap) -> anyhow::Result<Vec<u8>> { 159 + debug_time!("pixmap_to_png_data"); 160 + Ok(pixmap.encode_png()?) 161 + } 162 + 163 + fn write_png_data(data: Vec<u8>, at: &str) -> anyhow::Result<()> { 164 + debug_time!("write_png_data"); 165 + std::fs::write(at, data)?; 166 + Ok(()) 167 + }
+1 -1
src/video/encoding.rs
··· 22 22 resolution: u32, 23 23 ) -> anyhow::Result<video_rs::Frame> { 24 24 let (width, height) = self.resolution_to_size(resolution); 25 - let pixmap = self.render_to_pixmap_no_cache(width, height)?; 25 + let pixmap = self.render_to_pixmap(width, height)?; 26 26 self.pixmap_to_hwc_frame(resolution, &pixmap) 27 27 } 28 28