#[repr(u8)]pub enum BlendMode {
Show 29 variants
Clear = 0,
Src = 1,
Dst = 2,
SrcOver = 3,
DstOver = 4,
SrcIn = 5,
DstIn = 6,
SrcOut = 7,
DstOut = 8,
SrcATop = 9,
DstATop = 10,
Xor = 11,
Plus = 12,
Modulate = 13,
Screen = 14,
Overlay = 15,
Darken = 16,
Lighten = 17,
ColorDodge = 18,
ColorBurn = 19,
HardLight = 20,
SoftLight = 21,
Difference = 22,
Exclusion = 23,
Multiply = 24,
Hue = 25,
Saturation = 26,
Color = 27,
Luminosity = 28,
}Expand description
How a draw combines with what a target already holds.
Three families: the Porter-Duff set, which decides which of the source and destination survive and where; the separable modes, which mix the two arithmetically channel by channel; and the non-separable modes, which exchange whole attributes of a color. Only the first works everywhere.
Numbered as upstream numbers them: the discriminants are Impeller’s
BlendMode and dart:ui’s BlendMode.index, which agree with each other
and with Skia’s SkBlendMode. A caller holding one of those numbers –
an embedder decoding a Paint, a port reading a serialized display list
– converts with a table it can check against this one rather than a
match it has to keep in step by hand, and as u8 gives the number back.
The number a shader reads is Self::code, not this. The two are kept
apart on purpose; see there.
Variants§
Clear = 0
Leave nothing behind. Neither source nor destination survives.
Src = 1
Replace the destination outright, alpha included.
Not the same as Self::SrcOver with an opaque source: this overwrites
destination alpha too, which decides whether a layer composites
correctly when it is itself drawn onto something else.
Dst = 2
Keep the destination and discard the source.
SrcOver = 3
Source over destination: the default for drawing one thing on another.
DstOver = 4
Destination over source, as though the source were drawn underneath.
SrcIn = 5
Source, clipped to where the destination is.
DstIn = 6
Destination, clipped to where the source is.
SrcOut = 7
Source, clipped to where the destination is not.
DstOut = 8
Destination, clipped to where the source is not.
SrcATop = 9
Source drawn on top, but only within the destination’s shape.
DstATop = 10
Destination drawn on top, but only within the source’s shape.
Xor = 11
Whichever of the two is not overlapped by the other.
Plus = 12
The two added together, saturating.
Used for light accumulation, where overlapping contributions should brighten rather than replace.
Modulate = 13
The two multiplied together.
Screen = 14
The inverse of multiplying the inverses, which always lightens.
Overlay = 15
Multiply or screen depending on the destination, so the destination decides the contrast.
Darken = 16
The darker of the two, per channel.
Lighten = 17
The lighter of the two, per channel.
ColorDodge = 18
Brighten the destination in proportion to the source.
ColorBurn = 19
Darken the destination in proportion to the inverse of the source.
HardLight = 20
Overlay with the roles reversed, so the source decides the contrast.
SoftLight = 21
A gentler hard-light, without the hard transition at the midpoint.
Difference = 22
The absolute difference, which inverts where the two agree.
Exclusion = 23
Like difference, but with a softer response near the midpoint.
Multiply = 24
Multiply the two, which always darkens.
Last of the separable modes rather than first, because that is where
upstream numbers it (impeller/geometry/color.h).
Hue = 25
The source’s hue, with the backdrop’s saturation and luminosity.
Saturation = 26
The source’s saturation, with the backdrop’s hue and luminosity.
Color = 27
The source’s hue and saturation, with the backdrop’s luminosity.
Luminosity = 28
The source’s luminosity, with the backdrop’s hue and saturation.
Implementations§
Source§impl BlendMode
impl BlendMode
Sourcepub const PORTER_DUFF: &'static [BlendMode]
pub const PORTER_DUFF: &'static [BlendMode]
The modes every device can do, with no extension.
Sourcepub const ALL: &'static [BlendMode]
pub const ALL: &'static [BlendMode]
Every mode, for exhaustive tests and reporting.
Deliberately not what a backend iterates to decide what it supports —
that is what Self::is_advanced and the capability flag are for.
Sourcepub fn is_destructive(self) -> bool
pub fn is_destructive(self) -> bool
Whether this mode changes the destination where the source is absent.
The modes for which “the source drew nothing here” is not the same as
“leave this pixel alone”: DstIn zeroes what the source did not cover,
Clear zeroes everything, Src replaces it. A layer composited with
one of these has to cover everything it might affect rather than only
what it drew, so it is the test for whether a layer’s target may be
narrowed to its content.
The same nine upstream lists in Entity::IsBlendModeDestructive, and
the reason to match it exactly is that this decides a target’s size:
a mode missing here is a layer that silently stops masking what it
used to.
Sourcepub const fn code(self) -> f32
pub const fn code(self) -> f32
The number a shader reads to identify this mode.
Spelled out rather than cast from the discriminant, because this number
is written into a uniform buffer that a shader decodes, and the two
must agree where only one of them is visible from the shader. It is
emblema’s own numbering and predates the upstream discriminants: it
still counts Multiply as 14, which moving the variant did not change
and does not need to.
Sourcepub const fn is_advanced(self) -> bool
pub const fn is_advanced(self) -> bool
Whether this mode needs advanced blending.
Callers check crate::Capabilities::advanced_blend before using one, and a
backend without it refuses rather than substituting something that looks
close: a silently wrong blend mode is a picture nobody can debug from.
Sourcepub const fn factors(self) -> Option<BlendFactors>
pub const fn factors(self) -> Option<BlendFactors>
The factors this mode blends with, assuming premultiplied color.
None for an advanced mode: those are not expressible as factors at
all, which is exactly why they need an extension. Returning an
option rather than a plausible pair keeps a backend from silently
rendering the wrong thing.
Sourcepub const fn reads_destination(self) -> bool
pub const fn reads_destination(self) -> bool
Whether the destination contributes to the result.
A mode that ignores it can skip loading the target on a tiler, which is a bandwidth saving rather than a correctness one.
Sourcepub const fn respects_coverage(self) -> bool
pub const fn respects_coverage(self) -> bool
Whether a source scaled by coverage composites as though the shape were partly there.
This is what decides whether a shape may be antialiased by computing coverage in the fragment stage rather than by multisampling. Such a shape is drawn on a quad larger than itself and emits a fragment everywhere on it, including where coverage is nothing — so the mode has to leave the destination alone for a fully transparent source, or the quad erases what is behind it in the gap between the two.
Which is exactly the destination factor being One or
OneMinusSrcAlpha: the source term vanishes with the alpha whatever its
own factor is, so only the destination’s own weight is left. Every
advanced mode qualifies as well — their equations carry a
(1 - source alpha) on the destination by construction, and reduce to
it when the source contributes nothing.
The same condition happens to be what makes the partly covered edge correct rather than merely harmless. Weighting a premultiplied source by coverage and compositing gives the same answer as mixing the unweighted result into the destination by coverage, which is what multisampling would have produced.
Sourcepub const fn is_plain_write(self) -> bool
pub const fn is_plain_write(self) -> bool
Whether this simply writes the source, so blending can be switched off.
pub const fn name(self) -> &'static str
Trait Implementations§
impl Copy for BlendMode
impl Eq for BlendMode
impl StructuralPartialEq for BlendMode
Auto Trait Implementations§
impl Forget for BlendMode
impl Freeze for BlendMode
impl Move for BlendMode
impl RefUnwindSafe for BlendMode
impl Send for BlendMode
impl Sync for BlendMode
impl Unpin for BlendMode
impl UnsafeUnpin for BlendMode
impl UnwindSafe for BlendMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more