1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::{GlyphRenderMode, RasterStyleRequest, Rgba8};
use std::hash::{Hash, Hasher};
/// Describes which foreground channels can change rasterized color artwork.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum ForegroundDependency {
/// The artwork or its fallback may use the complete foreground color.
Full,
/// Fixed RGB artwork uses only the foreground alpha.
AlphaOnly,
}
/// The cache-relevant raster settings chosen by a platform rasterizer.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct PreparedRasterStyle {
/// The normalized render mode.
pub mode: GlyphRenderMode,
/// Any normalized color effect baked into coverage or color pixels.
pub color_effect: RasterColorEffect,
/// Which foreground channels can alter this raster or its fallback.
pub foreground_dependency: ForegroundDependency,
}
impl PreparedRasterStyle {
/// Creates a color-independent raster style.
pub const fn independent(mode: GlyphRenderMode) -> Self {
Self {
mode,
color_effect: RasterColorEffect::Independent,
foreground_dependency: ForegroundDependency::Full,
}
}
/// Creates a native preblended style from the request's relevant color channels.
pub fn preblend(request: RasterStyleRequest) -> Self {
Self {
mode: request.requested_mode,
color_effect: RasterColorEffect::Preblend(request.normalized_color()),
foreground_dependency: request.foreground_dependency,
}
}
}
/// The part of the requested color, if any, which changes rasterized pixels.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum RasterColorEffect {
/// Coverage and color pixels do not depend on the scene color.
Independent,
/// CoreGraphics' five-level font-smoothing dilation.
Dilation(u8),
/// A quantized color consumed by a native preblending or `currentColor` path.
Preblend(Rgba8),
}
impl Hash for RasterColorEffect {
fn hash<H: Hasher>(&self, state: &mut H) {
core::mem::discriminant(self).hash(state);
match self {
Self::Independent => {}
Self::Dilation(dilation) => dilation.hash(state),
Self::Preblend(color) => <[u8; 4]>::from(*color).hash(state),
}
}
}