Move damage tracking logic to compositor in iced_tiny_skia
This commit is contained in:
parent
d953d12c38
commit
af0303f95e
5 changed files with 183 additions and 182 deletions
|
|
@ -208,96 +208,6 @@ impl Primitive {
|
|||
Self::Cache { content } => content.bounds(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn damage(&self, other: &Self) -> Vec<Rectangle> {
|
||||
match (self, other) {
|
||||
(
|
||||
Primitive::Group {
|
||||
primitives: primitives_a,
|
||||
},
|
||||
Primitive::Group {
|
||||
primitives: primitives_b,
|
||||
},
|
||||
) => return Self::damage_list(primitives_a, primitives_b),
|
||||
(
|
||||
Primitive::Clip {
|
||||
bounds: bounds_a,
|
||||
content: content_a,
|
||||
},
|
||||
Primitive::Clip {
|
||||
bounds: bounds_b,
|
||||
content: content_b,
|
||||
},
|
||||
) => {
|
||||
if bounds_a == bounds_b {
|
||||
return content_a
|
||||
.damage(content_b)
|
||||
.into_iter()
|
||||
.filter_map(|r| r.intersection(bounds_a))
|
||||
.collect();
|
||||
} else {
|
||||
return vec![*bounds_a, *bounds_b];
|
||||
}
|
||||
}
|
||||
(
|
||||
Primitive::Translate {
|
||||
translation: translation_a,
|
||||
content: content_a,
|
||||
},
|
||||
Primitive::Translate {
|
||||
translation: translation_b,
|
||||
content: content_b,
|
||||
},
|
||||
) => {
|
||||
if translation_a == translation_b {
|
||||
return content_a
|
||||
.damage(content_b)
|
||||
.into_iter()
|
||||
.map(|r| r + *translation_a)
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
(
|
||||
Primitive::Cache { content: content_a },
|
||||
Primitive::Cache { content: content_b },
|
||||
) => {
|
||||
if Arc::ptr_eq(content_a, content_b) {
|
||||
return vec![];
|
||||
}
|
||||
}
|
||||
_ if self == other => return vec![],
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let bounds_a = self.bounds();
|
||||
let bounds_b = other.bounds();
|
||||
|
||||
if bounds_a == bounds_b {
|
||||
vec![bounds_a]
|
||||
} else {
|
||||
vec![bounds_a, bounds_b]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn damage_list(previous: &[Self], current: &[Self]) -> Vec<Rectangle> {
|
||||
let damage =
|
||||
previous.iter().zip(current).flat_map(|(a, b)| a.damage(b));
|
||||
|
||||
if previous.len() == current.len() {
|
||||
damage.collect()
|
||||
} else {
|
||||
let (smaller, bigger) = if previous.len() < current.len() {
|
||||
(previous, current)
|
||||
} else {
|
||||
(current, previous)
|
||||
};
|
||||
|
||||
// Extend damage by the added/removed primitives
|
||||
damage
|
||||
.chain(bigger[smaller.len()..].iter().map(Primitive::bounds))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A set of [`Vertex2D`] and indices representing a list of triangles.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue