gpui/text_system/
raster.rs1use crate::{GlyphRenderMode, RasterStyleRequest, Rgba8};
2use std::hash::{Hash, Hasher};
3
4#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
6pub enum ForegroundDependency {
7 Full,
9 AlphaOnly,
11}
12
13#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
15pub struct PreparedRasterStyle {
16 pub mode: GlyphRenderMode,
18 pub color_effect: RasterColorEffect,
20 pub foreground_dependency: ForegroundDependency,
22}
23
24impl PreparedRasterStyle {
25 pub const fn independent(mode: GlyphRenderMode) -> Self {
27 Self {
28 mode,
29 color_effect: RasterColorEffect::Independent,
30 foreground_dependency: ForegroundDependency::Full,
31 }
32 }
33
34 pub fn preblend(request: RasterStyleRequest) -> Self {
36 Self {
37 mode: request.requested_mode,
38 color_effect: RasterColorEffect::Preblend(request.normalized_color()),
39 foreground_dependency: request.foreground_dependency,
40 }
41 }
42}
43
44#[derive(Clone, Copy, Debug, Eq, PartialEq)]
46pub enum RasterColorEffect {
47 Independent,
49 Dilation(u8),
51 Preblend(Rgba8),
53}
54
55impl Hash for RasterColorEffect {
56 fn hash<H: Hasher>(&self, state: &mut H) {
57 core::mem::discriminant(self).hash(state);
58
59 match self {
60 Self::Independent => {}
61 Self::Dilation(dilation) => dilation.hash(state),
62 Self::Preblend(color) => <[u8; 4]>::from(*color).hash(state),
63 }
64 }
65}