Skip to content

Commit

Permalink
[tiny-skia]: Avoid physical mask for shadows, stricted clip mask.
Browse files Browse the repository at this point in the history
  • Loading branch information
T-256 committed Jan 7, 2025
1 parent cf29084 commit 2e52724
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
70 changes: 36 additions & 34 deletions tiny_skia/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Engine {
background: &Background,
transformation: Transformation,
pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: &mut tiny_skia::Mask,
clip_mask: &tiny_skia::Mask,
clip_bounds: Rectangle,
) {
debug_assert!(
Expand All @@ -51,8 +51,8 @@ impl Engine {
return;
}

let clip_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask as &_);
let physical_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask);

let transform = into_transform(transformation);

Expand Down Expand Up @@ -143,7 +143,9 @@ impl Engine {
pixmap.as_ref(),
&tiny_skia::PixmapPaint::default(),
tiny_skia::Transform::default(),
clip_mask,
// Shadows physically could be larger than clip bounds.
// To avoid out of bound draws, always pass original clip mask.
Some(clip_mask),
);
}
}
Expand Down Expand Up @@ -202,7 +204,7 @@ impl Engine {
},
tiny_skia::FillRule::EvenOdd,
transform,
clip_mask,
physical_mask,
);

if border_width > 0.0 {
Expand Down Expand Up @@ -251,7 +253,7 @@ impl Engine {
..tiny_skia::Stroke::default()
},
transform,
clip_mask,
physical_mask,
);
} else {
// Draw corners that have too small border radii as having no border radius,
Expand Down Expand Up @@ -315,7 +317,7 @@ impl Engine {
temp_pixmap.as_ref(),
&tiny_skia::PixmapPaint::default(),
transform,
clip_mask,
physical_mask,
);
}
}
Expand All @@ -326,7 +328,7 @@ impl Engine {
text: &Text,
transformation: Transformation,
pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: &mut tiny_skia::Mask,
clip_mask: &tiny_skia::Mask,
clip_bounds: Rectangle,
) {
match text {
Expand All @@ -347,15 +349,15 @@ impl Engine {
return;
}

let clip_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask as &_);
let physical_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask);

self.text_pipeline.draw_paragraph(
paragraph,
*position,
*color,
pixels,
clip_mask,
physical_mask,
transformation,
);
}
Expand All @@ -375,15 +377,15 @@ impl Engine {
return;
}

let clip_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask as &_);
let physical_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask);

self.text_pipeline.draw_editor(
editor,
*position,
*color,
pixels,
clip_mask,
physical_mask,
transformation,
);
}
Expand All @@ -405,8 +407,8 @@ impl Engine {
return;
}

let clip_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask as &_);
let physical_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask);

self.text_pipeline.draw_cached(
content,
Expand All @@ -419,7 +421,7 @@ impl Engine {
*vertical_alignment,
*shaping,
pixels,
clip_mask,
physical_mask,
transformation,
);
}
Expand All @@ -446,15 +448,15 @@ impl Engine {
return;
}

let clip_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask as &_);
let physical_mask = (!physical_bounds.is_within(&clip_bounds))
.then_some(clip_mask);

self.text_pipeline.draw_raw(
&buffer,
raw.position,
raw.color,
pixels,
clip_mask,
physical_mask,
transformation,
);
}
Expand All @@ -466,7 +468,7 @@ impl Engine {
primitive: &Primitive,
transformation: Transformation,
pixels: &mut tiny_skia::PixmapMut<'_>,
clip_mask: &mut tiny_skia::Mask,
clip_mask: &tiny_skia::Mask,
layer_bounds: Rectangle,
) {
match primitive {
Expand All @@ -488,15 +490,15 @@ impl Engine {
return;
};

let clip_mask =
(physical_bounds != clip_bounds).then_some(clip_mask as &_);
let physical_mask =
(physical_bounds != clip_bounds).then_some(clip_mask);

pixels.fill_path(
path,
paint,
*rule,
into_transform(transformation),
clip_mask,
physical_mask,
);
}
Primitive::Stroke {
Expand All @@ -521,15 +523,15 @@ impl Engine {
return;
};

let clip_mask =
(physical_bounds != clip_bounds).then_some(clip_mask as &_);
let physical_mask =
(physical_bounds != clip_bounds).then_some(clip_mask);

pixels.stroke_path(
path,
paint,
stroke,
into_transform(transformation),
clip_mask,
physical_mask,
);
}
}
Expand All @@ -540,7 +542,7 @@ impl Engine {
image: &Image,
_transformation: Transformation,
_pixels: &mut tiny_skia::PixmapMut<'_>,
_clip_mask: &mut tiny_skia::Mask,
_clip_mask: &tiny_skia::Mask,
_clip_bounds: Rectangle,
) {
match image {
Expand All @@ -552,8 +554,8 @@ impl Engine {
return;
}

let clip_mask = (!physical_bounds.is_within(&_clip_bounds))
.then_some(_clip_mask as &_);
let physical_mask = (!physical_bounds.is_within(&_clip_bounds))
.then_some(_clip_mask);

let center = physical_bounds.center();
let radians = f32::from(raster.rotation);
Expand All @@ -571,7 +573,7 @@ impl Engine {
raster.opacity,
_pixels,
transform,
clip_mask,
physical_mask,
);
}
#[cfg(feature = "svg")]
Expand All @@ -582,8 +584,8 @@ impl Engine {
return;
}

let clip_mask = (!physical_bounds.is_within(&_clip_bounds))
.then_some(_clip_mask as &_);
let physical_mask = (!physical_bounds.is_within(&_clip_bounds))
.then_some(_clip_mask);

let center = physical_bounds.center();
let radians = f32::from(svg.rotation);
Expand All @@ -601,7 +603,7 @@ impl Engine {
svg.opacity,
_pixels,
transform,
clip_mask,
physical_mask,
);
}
#[cfg(not(feature = "image"))]
Expand Down
8 changes: 4 additions & 4 deletions tiny_skia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Renderer {
background,
Transformation::scale(scale_factor),
pixels,
clip_mask,
clip_mask as &_,
clip_bounds,
);
}
Expand All @@ -170,7 +170,7 @@ impl Renderer {
group.transformation()
* Transformation::scale(scale_factor),
pixels,
clip_mask,
clip_mask as &_,
clip_bounds,
);
}
Expand All @@ -183,7 +183,7 @@ impl Renderer {
image,
Transformation::scale(scale_factor),
pixels,
clip_mask,
clip_mask as &_,
clip_bounds,
);
}
Expand All @@ -195,7 +195,7 @@ impl Renderer {
group.transformation()
* Transformation::scale(scale_factor),
pixels,
clip_mask,
clip_mask as &_,
clip_bounds,
);
}
Expand Down

0 comments on commit 2e52724

Please sign in to comment.