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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) 2023 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
// Use of this source is governed by Lesser General Public License that can be found
// in the LICENSE file.
use bitflags::bitflags;
/// Description of how the LCD strips are arranged for each pixel.
///
/// If this is unknown, or the pixels are meant to be "portable" and/or transformed
/// before showing (e.g. rotated, scaled) then use `Unknown`.
#[repr(u8)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
pub enum PixelGeometry {
Unknown,
RgbH,
BgrH,
RgbV,
BgrV,
}
impl Default for PixelGeometry {
fn default() -> Self {
Self::Unknown
}
}
impl PixelGeometry {
/// Returns true iff geo is a known geometry and is RGB.
#[must_use]
pub const fn is_rgb(self) -> bool {
matches!(self, Self::RgbH | Self::RgbV)
}
/// Returns true iff geo is a known geometry and is BGR.
#[must_use]
pub const fn is_bgr(self) -> bool {
matches!(self, Self::BgrH | Self::BgrV)
}
/// Returns true iff geo is a known geometry and is horizontal.
#[must_use]
pub const fn is_h(self) -> bool {
matches!(self, Self::RgbH | Self::BgrH)
}
/// Returns true iff geo is a known geometry and is vertical.
#[must_use]
pub const fn is_v(self) -> bool {
matches!(self, Self::RgbV | Self::BgrV)
}
}
bitflags! {
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
pub struct Flags: u8 {
const UseDeviceIndependentFonts = 1 << 0;
/// Use internal MSAA to render to non-MSAA GPU surfaces.
const DynamicMSAA = 1 << 1;
/// If set, all rendering will have dithering enabled.
/// Currently this only impacts GPU backends
const AlwaysDither = 1 << 2;
}
}
/// `SurfaceProps` describes properties and constraints of a given Surface.
///
/// The rendering engine can parse these during drawing, and can sometimes
/// optimize its performance (e.g. disabling an expensive feature).
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct SurfaceProps {
flags: Flags,
pixel_geometry: PixelGeometry,
}
impl Default for SurfaceProps {
fn default() -> Self {
Self::new()
}
}
impl SurfaceProps {
/// No flags, unknown pixel geometry.
#[must_use]
pub const fn new() -> Self {
Self {
flags: Flags::empty(),
pixel_geometry: PixelGeometry::Unknown,
}
}
#[must_use]
pub const fn with_geometry(flags: Flags, pixel_geometry: PixelGeometry) -> Self {
Self {
flags,
pixel_geometry,
}
}
#[must_use]
pub const fn flags(&self) -> Flags {
self.flags
}
#[must_use]
pub const fn pixel_geometry(&self) -> PixelGeometry {
self.pixel_geometry
}
#[must_use]
pub const fn is_use_device_independent_fonts(&self) -> bool {
self.flags.contains(Flags::UseDeviceIndependentFonts)
}
#[must_use]
pub const fn is_always_dither(&self) -> bool {
self.flags.contains(Flags::AlwaysDither)
}
}