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
//! Dirty-region tracking and platform rendering capabilities.
use alloc::{vec, vec::Vec};
use embedded_graphics::primitives::Rectangle;
/// Dirty regions to redraw on the next frame.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum DirtyRegion {
/// Nothing changed; drawing can be skipped.
None,
/// The whole surface should be redrawn.
Full,
/// Redraw the listed rectangles.
Rects(Vec<Rectangle>),
}
impl DirtyRegion {
/// Nothing is dirty.
#[must_use]
pub const fn none() -> Self {
Self::None
}
/// The whole surface is dirty.
#[must_use]
pub const fn full() -> Self {
Self::Full
}
/// A single dirty rectangle.
#[must_use]
pub fn rect(rect: Rectangle) -> Self {
Self::Rects(vec![rect])
}
/// True if no redraw is needed.
#[must_use]
pub const fn is_none(&self) -> bool {
matches!(self, Self::None)
}
/// Borrow the dirty rectangles when the region is rectangular.
#[must_use]
pub fn rects(&self) -> Option<&[Rectangle]> {
match self {
Self::Rects(rects) => Some(rects.as_slice()),
_ => None,
}
}
/// Add a rectangle to the dirty set.
pub fn add_rect(&mut self, rect: Rectangle) {
match self {
Self::None => *self = Self::Rects(vec![rect]),
Self::Full => {}
Self::Rects(rects) => rects.push(rect),
}
}
}
/// Renderer/backend capabilities relevant to the runtime.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct PlatformCapabilities {
/// The renderer can clip draw calls to a sub-rectangle.
pub supports_clip: bool,
/// The backend can flush only dirty rectangles efficiently.
pub supports_partial_flush: bool,
/// The backend accepts semantic input actions directly.
pub supports_semantic_input: bool,
/// The backend is happier redrawing the whole frame.
pub prefers_full_redraw: bool,
}