pub struct ShadowCache { /* private fields */ }Expand description
Rendered shadows, most recently used last.
Implementations§
Source§impl ShadowCache
impl ShadowCache
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
A cache holding capacity shadows.
Zero is treated as DEFAULT_CAPACITY: a cache that held nothing
would re-blur every shadow every frame, which is the cost this type
exists to remove.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Forget everything.
For a theme change that invalidates every shadow at once, where evicting one at a time would blur each of them again on the way out.
Sourcepub fn blit_into(
&mut self,
key: ShadowKey,
theme: &Theme,
dst: &mut ShadowDest<'_>,
) -> bool
pub fn blit_into( &mut self, key: ShadowKey, theme: &Theme, dst: &mut ShadowDest<'_>, ) -> bool
Composite this shadow onto dst, rendering it first if it is not
cached.
Source-over, in premultiplied alpha, as the reference composites it:
what is already in dst shows through where the shadow is not opaque.
On a cleared buffer that is the same as a copy.
Returns false, writing nothing, for a zero-sized key or destination,
and true otherwise — rather than failing: a window being resized
passes through zero, and a decoration that errored on the way would
flicker.
A destination smaller than the patch is clipped, not refused — the
alternative is writing past the caller’s buffer. Rows that do not fit
in pixels at stride are skipped too, and the call still returns
true.
Sourcepub fn blit_cross_fade(
&mut self,
a: ShadowKey,
b: ShadowKey,
theme: &Theme,
dst: &mut ShadowDest<'_>,
t: f32,
) -> bool
pub fn blit_cross_fade( &mut self, a: ShadowKey, b: ShadowKey, theme: &Theme, dst: &mut ShadowDest<'_>, t: f32, ) -> bool
Composite a blend of two shadows, t of the way from a to b, onto
dst.
What a focus change animates through. Both patches are cached, so the
transition costs a per-pixel lerp rather than a blur per frame — given
a capacity of at least two. With a capacity of
one, rendering b evicts a, and a mid-transition blend draws
nothing and returns false. The blend is composited source-over, as
blit_into is, and the endpoints are exactly
blit_into of one patch.
t is clamped to 0..=1: an animation that overshoots is a caller
bug, and extrapolating a color past its endpoints produces values
that are not a shadow at all.
The two keys must be the same size, as the reference requires; keys
that differ write nothing and return false. Otherwise the return is
as for blit_into: false, writing nothing, for a zero-sized key or
destination, and true once the blend is composited.