1
0
Fork 0
forked from wry/wry

render: make damage visualizer slightly less inefficient

This commit is contained in:
Julian Orth 2025-07-27 15:00:09 +02:00
parent 225dda8e5b
commit e12ececca4
9 changed files with 30 additions and 19 deletions

View file

@ -49,7 +49,7 @@ impl Region {
return Self::default();
}
if rects.len() == 1 {
return Self::new2(rects[0]);
return Self::new(rects[0]);
}
let rects = rects_to_bands(unsafe { mem::transmute::<&[Rect], &[RectRaw]>(rects) });
Self {
@ -74,6 +74,20 @@ impl Region {
})
}
pub fn union_cow<'a>(self: &'a Self, other: &'a Self) -> Cow<'a, Region> {
if self.extents.is_empty() {
return Cow::Borrowed(other);
}
if other.extents.is_empty() {
return Cow::Borrowed(self);
}
let rects = union(&self.rects, &other.rects);
Cow::Owned(Self {
rects,
extents: self.extents.union(other.extents),
})
}
pub fn subtract(self: &Rc<Self>, other: &Rc<Self>) -> Rc<Self> {
if self.extents.is_empty() || other.extents.is_empty() {
return self.clone();
@ -122,7 +136,7 @@ impl Region<u32> {
if rects.len() == 1 {
let mut rect = rects[0];
rect.raw.tag = rect.raw.tag.constrain();
return Self::new2(rect);
return Self::new(rect);
}
let rects = rects_to_bands_tagged(unsafe {
mem::transmute::<&[Rect<u32>], &[RectRaw<u32>]>(rects)
@ -153,11 +167,7 @@ impl<T> Region<T>
where
T: Tag,
{
pub fn new(rect: Rect<T>) -> Rc<Self> {
Rc::new(Self::new2(rect))
}
pub fn new2(rect: Rect<T>) -> Self {
pub fn new(rect: Rect<T>) -> Self {
let mut rects = SmallVec::new();
rects.push(rect.raw);
Self {

View file

@ -8,7 +8,8 @@ fn union1() {
let r1 = Region::new(Rect::new(0, 0, 10, 10).unwrap());
let r2_ = Region::new(Rect::new(5, 5, 15, 15).unwrap());
let r2 = Region::new(Rect::new(10, 10, 20, 20).unwrap());
let r3 = r1.union(&r2).union(&r2_);
let r3 = r1.union_cow(&r2);
let r3 = r3.union_cow(&r2_);
assert_eq!(r3.extents, Rect::new(0, 0, 20, 20).unwrap());
assert_eq!(
&r3.rects[..],
@ -25,7 +26,7 @@ fn union1() {
fn union2() {
let r1 = Region::new(Rect::new(0, 0, 10, 10).unwrap());
let r2 = Region::new(Rect::new(0, 10, 10, 20).unwrap());
let r3 = r1.union(&r2);
let r3 = r1.union_cow(&r2);
assert_eq!(r3.extents, Rect::new(0, 0, 10, 20).unwrap());
assert_eq!(&r3.rects[..], &[Rect::new(0, 0, 10, 20).unwrap().raw,]);
}
@ -34,7 +35,7 @@ fn union2() {
fn subtract1() {
let r1 = Region::new(Rect::new(0, 0, 20, 20).unwrap());
let r2 = Region::new(Rect::new(5, 5, 15, 15).unwrap());
let r3 = r1.subtract(&r2);
let r3 = r1.subtract_cow(&r2);
assert_eq!(r3.extents, Rect::new(0, 0, 20, 20).unwrap());
assert_eq!(
&r3.rects[..],