clamp the damage rect to the destination rect
this fixes issues when the damage rect is greater than the destination rect, like providing i32::Max as the damage size
This commit is contained in:
parent
75929919ba
commit
9f5bf25b6b
|
@ -1286,11 +1286,18 @@ impl Frame for Gles2Frame {
|
|||
let damage = damage
|
||||
.iter()
|
||||
.map(|rect| {
|
||||
let rect = rect.to_f64();
|
||||
|
||||
let rect_constrained_loc = rect
|
||||
.loc
|
||||
.constrain(Rectangle::from_extemities((0f64, 0f64), dest.size.to_point()));
|
||||
let rect_clamped_size = rect.size.clamp((0f64, 0f64), dest.size);
|
||||
|
||||
[
|
||||
rect.loc.x as f32 / dest.size.w as f32,
|
||||
rect.loc.y as f32 / dest.size.h as f32,
|
||||
rect.size.w as f32 / dest.size.w as f32,
|
||||
rect.size.h as f32 / dest.size.h as f32,
|
||||
(rect_constrained_loc.x / dest.size.w) as f32,
|
||||
(rect_constrained_loc.y / dest.size.h) as f32,
|
||||
(rect_clamped_size.w / dest.size.w) as f32,
|
||||
(rect_clamped_size.h / dest.size.h) as f32,
|
||||
]
|
||||
})
|
||||
.flatten()
|
||||
|
|
|
@ -296,6 +296,23 @@ impl<N: Coordinate, Kind> Point<N, Kind> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: Coordinate, Kind> Point<N, Kind> {
|
||||
/// Constrain this [`Point`] within a [`Rectangle`] with the same coordinates
|
||||
///
|
||||
/// The [`Point`] returned is guaranteed to be not smaller than the [`Rectangle`]
|
||||
/// location and not greater than the [`Rectangle`] size.
|
||||
#[inline]
|
||||
pub fn constrain(self, rect: impl Into<Rectangle<N, Kind>>) -> Point<N, Kind> {
|
||||
let rect = rect.into();
|
||||
|
||||
Point {
|
||||
x: self.x.max(rect.loc.x).min(rect.size.w),
|
||||
y: self.y.max(rect.loc.y).min(rect.size.h),
|
||||
_kind: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Coordinate, Kind> Point<N, Kind> {
|
||||
/// Convert the underlying numerical type to f64 for floating point manipulations
|
||||
#[inline]
|
||||
|
@ -543,6 +560,20 @@ impl<N: Coordinate, Kind> Size<N, Kind> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: Coordinate, Kind> Size<N, Kind> {
|
||||
/// Restrict this [`Size`] to min and max [`Size`] with the same coordinates
|
||||
pub fn clamp(self, min: impl Into<Size<N, Kind>>, max: impl Into<Size<N, Kind>>) -> Size<N, Kind> {
|
||||
let min = min.into();
|
||||
let max = max.into();
|
||||
|
||||
Size {
|
||||
w: self.w.max(min.w).min(max.w),
|
||||
h: self.h.max(min.h).min(max.h),
|
||||
_kind: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Coordinate, Kind> Size<N, Kind> {
|
||||
/// Convert the underlying numerical type to f64 for floating point manipulations
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue