From 282f81b866372ba9aeb2010f9d10b9a55f87dabe Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 11 Dec 2024 21:36:50 -0500 Subject: [PATCH 1/3] fix(iced): use internal_ref size --- src/utils/iced.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/iced.rs b/src/utils/iced.rs index 18513644..55552034 100644 --- a/src/utils/iced.rs +++ b/src/utils/iced.rs @@ -915,7 +915,7 @@ where .to_logical(1., Transform::Normal) .to_i32_round(), )), - Some(size.to_logical(1, Transform::Normal)), + Some(internal_ref.size), Kind::Unspecified, ) { return vec![C::from(buffer)]; From 2cfa7ff0f6fe486d220d6c81412237a7479350aa Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 12 Dec 2024 01:31:33 -0500 Subject: [PATCH 2/3] fix: improve damage tracking --- src/utils/iced.rs | 67 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/src/utils/iced.rs b/src/utils/iced.rs index 55552034..b5d930a4 100644 --- a/src/utils/iced.rs +++ b/src/utils/iced.rs @@ -25,7 +25,10 @@ use cosmic::{ }, Theme, }; -use iced_tiny_skia::{graphics::Viewport, Primitive}; +use iced_tiny_skia::{ + graphics::{damage, Viewport}, + Layer, +}; use once_cell::sync::Lazy; use ordered_float::OrderedFloat; @@ -143,7 +146,7 @@ impl IcedProgram for ProgramWrapper

{ pub(crate) struct IcedElementInternal { // draw buffer outputs: HashSet, - buffers: HashMap, (MemoryRenderBuffer, Option<(Vec, Color)>)>, + buffers: HashMap, (MemoryRenderBuffer, Option<(Vec, Color)>)>, pending_update: Option, // state @@ -850,7 +853,9 @@ where internal_ref.pending_update = None; } let _ = internal_ref.update(force); - if let Some((buffer, _)) = internal_ref.buffers.get_mut(&OrderedFloat(scale.x)) { + if let Some((buffer, ref mut old_layers)) = + internal_ref.buffers.get_mut(&OrderedFloat(scale.x)) + { let size: Size = internal_ref .size .to_f64() @@ -871,20 +876,52 @@ where let bounds = IcedSize::new(size.w as u32, size.h as u32); let viewport = Viewport::with_physical_size(bounds, scale.x); - let damage = vec![cosmic::iced::Rectangle::new( - cosmic::iced::Point::default(), - viewport.logical_size(), - )]; - - internal_ref.renderer.draw( - &mut pixels, - &mut clip_mask, - &viewport, - &damage, - background_color, - &overlay, + let current_layers = internal_ref.renderer.layers(); + let mut damage: Vec<_> = old_layers + .as_ref() + .and_then(|(last_primitives, last_color)| { + (last_color == &background_color).then(|| { + damage::diff( + &last_primitives, + current_layers, + |_| { + vec![cosmic::iced::Rectangle::new( + cosmic::iced::Point::default(), + viewport.logical_size(), + )] + }, + Layer::damage, + ) + .into_iter() + .filter(|d| { + let width = d.width as u32; + let height = d.height as u32; + + width > 1 && height > 1 + }) + .collect() + }) + }) + .unwrap_or_else(|| { + vec![cosmic::iced::Rectangle::with_size(viewport.logical_size())] + }); + damage = damage::group( + damage, + cosmic::iced::Rectangle::with_size(viewport.logical_size()), ); + if !damage.is_empty() { + *old_layers = Some((current_layers.to_vec(), background_color)); + + internal_ref.renderer.draw( + &mut pixels, + &mut clip_mask, + &viewport, + &damage, + background_color, + &overlay, + ); + } let damage = damage .into_iter() .filter_map(|x| x.snap()) From 6a556188bf852b6182d230588705dfd51c7584eb Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 12 Dec 2024 01:48:38 -0500 Subject: [PATCH 3/3] fix: manually scale the damage --- src/utils/iced.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/iced.rs b/src/utils/iced.rs index b5d930a4..90f5bab9 100644 --- a/src/utils/iced.rs +++ b/src/utils/iced.rs @@ -875,7 +875,7 @@ where let background_color = state_ref.program().0.background_color(theme); let bounds = IcedSize::new(size.w as u32, size.h as u32); let viewport = Viewport::with_physical_size(bounds, scale.x); - + let scale_x = scale.x as f32; let current_layers = internal_ref.renderer.layers(); let mut damage: Vec<_> = old_layers .as_ref() @@ -922,8 +922,10 @@ where &overlay, ); } + let damage = damage .into_iter() + .map(|d| d * scale_x) .filter_map(|x| x.snap()) .map(|damage_rect| { Rectangle::from_loc_and_size(