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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
use super::*;
/// Backend-agnostic vector/UI drawing primitive emitted by `PaintPass` and consumed by all renderers.
#[derive(Clone, Debug, PartialEq)]
pub enum DrawCommand {
/// Clears the target surface to `Color`.
Clear(Color),
/// Draws a rounded or sharp filled rectangle with optional border stroke.
FillRoundedRect {
/// Bounds in logical pixels.
rect: Rect,
/// Fill color.
color: Color,
/// Corner radii.
radius: CornerRadius,
/// Optional border stroke.
border: Border,
},
/// Draws a two-stop linear gradient inside a rounded rectangle.
LinearGradientRect {
/// Bounds in logical pixels.
rect: Rect,
/// Gradient specification.
gradient: LinearGradient,
/// Corner radii.
radius: CornerRadius,
},
/// Draws a soft drop shadow under a rounded rectangle.
BoxShadow {
/// Casting box bounds.
rect: Rect,
/// Corner radii.
radius: CornerRadius,
/// Shadow parameters.
shadow: Shadow,
},
/// Applies a backdrop blur sampling the previously rendered pixels beneath `rect`.
BackdropBlur {
/// Output bounds in logical pixels.
rect: Rect,
/// Corner radii mask in logical pixels.
radius: CornerRadius,
/// Gaussian blur radius in logical pixels.
blur_radius: f32,
},
/// Draws a laid-out text run using the shared deterministic glyph atlas.
TextRun {
/// Bounding rectangle in logical pixels.
rect: Rect,
/// UTF-8 text string.
text: String,
/// Typography style.
style: TextStyle,
},
/// Draws a blinking text-input caret aligned to exact rasterized glyph advances.
TextCaret {
/// Text layout bounding rectangle in logical pixels.
text_rect: Rect,
/// Input inner content clip rectangle in logical pixels.
content_rect: Rect,
/// Active input text preceding the caret.
text: String,
/// Typography style matching the input's `TextRun`.
style: TextStyle,
/// Caret height in logical pixels.
caret_height: f32,
/// Caret fill color.
color: Color,
/// Whether the input wraps across multiple lines.
multiline: bool,
},
/// Blits a decoded RGBA8 image buffer into `rect`.
Image {
/// Destination bounds.
rect: Rect,
/// Image pixel buffer.
buffer: ImageBuffer,
/// Corner radii mask.
radius: CornerRadius,
},
/// Blits a reference-counted pooled RGBA8 pixel buffer into `rect` with zero per-frame copy.
SharedImage {
/// Destination bounds.
rect: Rect,
/// Image width in pixels.
width: u32,
/// Image height in pixels.
height: u32,
/// Shared RGBA8 pixel bytes (`width * height * 4`).
pixels: Arc<Vec<u8>>,
/// Corner radii mask.
radius: CornerRadius,
},
/// Draws a straight anti-aliased line segment (used by custom canvases and dividers).
Line {
/// Start point.
from: Point,
/// End point.
to: Point,
/// Line color.
color: Color,
/// Stroke width.
width: f32,
},
/// Draws a filled anti-aliased circle (used by badges, avatars, spinners, and custom canvases).
Circle {
/// Center point.
center: Point,
/// Circle radius.
radius: f32,
/// Fill color.
color: Color,
},
/// Draws a filled triangle primitive (used by 2D game meshes, spaceships, lasers, and polygons).
Triangle {
/// First vertex in logical pixels.
p0: Point,
/// Second vertex in logical pixels.
p1: Point,
/// Third vertex in logical pixels.
p2: Point,
/// Fill color.
color: Color,
},
/// Blits a cropped sub-region of an `ImageBuffer` sprite sheet with optional tint color.
SpriteRegion {
/// Destination bounds in logical pixels.
rect: Rect,
/// Source sprite-sheet RGBA8 buffer.
buffer: ImageBuffer,
/// Source pixel sub-rectangle `(x, y, w, h)`.
src_rect: Rect,
/// Multiplicative tint color (`COLOR_WHITE` for untinted).
tint: Color,
},
/// Composites the hardware GPU offscreen scene render target (`external_tex`) directly into `rect`.
ExternalSurface {
/// Destination bounds in logical pixels.
rect: Rect,
/// Corner radii mask in logical pixels.
radius: CornerRadius,
},
/// Pushes an axis-aligned clip rectangle onto the clip stack.
PushClip(Rect),
/// Pushes a rounded-rectangle clip mask onto the clip stack, balanced by `PopClip`.
PushRoundedClip {
/// Clip rectangle bounds in logical pixels.
rect: Rect,
/// Corner radii in logical pixels.
radius: CornerRadius,
},
/// Pops the top clip rectangle from the clip stack.
PopClip,
}
/// Slab-backed zero-String-allocation representation of `DrawCommand` stored inside `PaintFragmentCache`.
#[derive(Clone, Debug)]
pub(crate) enum CachedDrawCommand {
/// Clears the target surface to `Color`.
Clear(Color),
/// Draws a rounded or sharp filled rectangle with optional border stroke.
FillRoundedRect {
/// Bounds in logical pixels.
rect: Rect,
/// Fill color.
color: Color,
/// Corner radii.
radius: CornerRadius,
/// Optional border stroke.
border: Border,
},
/// Draws a two-stop linear gradient inside a rounded rectangle.
LinearGradientRect {
/// Bounds in logical pixels.
rect: Rect,
/// Gradient specification.
gradient: LinearGradient,
/// Corner radii.
radius: CornerRadius,
},
/// Draws a soft drop shadow under a rounded rectangle.
BoxShadow {
/// Casting box bounds.
rect: Rect,
/// Corner radii.
radius: CornerRadius,
/// Shadow parameters.
shadow: Shadow,
},
/// Applies a backdrop blur sampling the previously rendered pixels beneath `rect`.
BackdropBlur {
/// Output bounds in logical pixels.
rect: Rect,
/// Corner radii mask in logical pixels.
radius: CornerRadius,
/// Gaussian blur radius in logical pixels.
blur_radius: f32,
},
/// Draws a laid-out text run backed by byte slice `[text_start..text_start + text_len]` in `PaintFragmentCache::text_slab`.
TextRun {
/// Bounding rectangle in logical pixels.
rect: Rect,
/// Start UTF-8 byte offset inside `text_slab`.
text_start: u32,
/// UTF-8 byte length inside `text_slab`.
text_len: u32,
/// Typography style.
style: TextStyle,
},
/// Draws a blinking text-input caret backed by byte slice `[text_start..text_start + text_len]` in `PaintFragmentCache::text_slab`.
TextCaret {
/// Text layout bounding rectangle in logical pixels.
text_rect: Rect,
/// Input inner content clip rectangle in logical pixels.
content_rect: Rect,
/// Start UTF-8 byte offset inside `text_slab`.
text_start: u32,
/// UTF-8 byte length inside `text_slab`.
text_len: u32,
/// Typography style matching the input's `TextRun`.
style: TextStyle,
/// Caret height in logical pixels.
caret_height: f32,
/// Caret fill color.
color: Color,
/// Whether the input wraps across multiple lines.
multiline: bool,
},
/// Blits a decoded RGBA8 image buffer into `rect`.
Image {
/// Destination bounds.
rect: Rect,
/// Image pixel buffer.
buffer: ImageBuffer,
/// Corner radii mask.
radius: CornerRadius,
},
/// Blits a reference-counted pooled RGBA8 pixel buffer into `rect` with zero per-frame copy.
SharedImage {
/// Destination bounds.
rect: Rect,
/// Image width in pixels.
width: u32,
/// Image height in pixels.
height: u32,
/// Shared RGBA8 pixel bytes (`width * height * 4`).
pixels: Arc<Vec<u8>>,
/// Corner radii mask.
radius: CornerRadius,
},
/// Draws a straight anti-aliased line segment.
Line {
/// Start point.
from: Point,
/// End point.
to: Point,
/// Line color.
color: Color,
/// Stroke width.
width: f32,
},
/// Draws a filled anti-aliased circle.
Circle {
/// Center point.
center: Point,
/// Circle radius.
radius: f32,
/// Fill color.
color: Color,
},
/// Draws a filled triangle primitive.
Triangle {
/// First vertex in logical pixels.
p0: Point,
/// Second vertex in logical pixels.
p1: Point,
/// Third vertex in logical pixels.
p2: Point,
/// Fill color.
color: Color,
},
/// Blits a cropped sub-region of an `ImageBuffer` sprite sheet with optional tint color.
SpriteRegion {
/// Destination bounds in logical pixels.
rect: Rect,
/// Source sprite-sheet RGBA8 buffer.
buffer: ImageBuffer,
/// Source pixel sub-rectangle `(x, y, w, h)`.
src_rect: Rect,
/// Multiplicative tint color.
tint: Color,
},
/// Composites the hardware GPU offscreen scene render target (`external_tex`) directly into `rect`.
ExternalSurface {
/// Destination bounds in logical pixels.
rect: Rect,
/// Corner radii mask in logical pixels.
radius: CornerRadius,
},
/// Pushes an axis-aligned clip rectangle onto the clip stack.
PushClip(Rect),
/// Pushes a rounded-rectangle clip mask onto the clip stack, balanced by `PopClip`.
PushRoundedClip {
/// Clip rectangle bounds in logical pixels.
rect: Rect,
/// Corner radii in logical pixels.
radius: CornerRadius,
},
/// Pops the top clip rectangle from the clip stack.
PopClip,
}