Skip to main content

ferroui_base/rendering/composition/drawing/
render_data_payloads.rs

1use super::RenderDataOpcode;
2use crate::media::{RenderOptions, TextOptions};
3use crate::rendering::composition::transport::{BatchValue, BatchValueReader};
4use crate::{Matrix, Point, Rect, RoundedRect};
5
6/// The fixed-size part of an operation of a render data stream, written
7/// after its opcode.
8pub trait IRenderDataPayload: BatchValue + Copy {
9    /// The opcode written before the payload.
10    const OPCODE: RenderDataOpcode;
11}
12
13/// Implements a payload: its opcode, and its encoding (the fields in
14/// declaration order, as upstream blits the struct).
15macro_rules! render_data_payload {
16    ($name:ident => $opcode:ident { $($field:ident : $fty:ty),* $(,)? }) => {
17        impl IRenderDataPayload for $name {
18            const OPCODE: RenderDataOpcode = RenderDataOpcode::$opcode;
19        }
20
21        impl BatchValue for $name {
22            #[inline]
23            fn write_to(&self, out: &mut Vec<u8>) {
24                $(self.$field.write_to(out);)*
25            }
26
27            #[inline]
28            fn read_from(input: &mut BatchValueReader<'_>) -> Self {
29                $(let $field = <$fty>::read_from(input);)*
30                Self { $($field,)* }
31            }
32        }
33    };
34}
35
36#[derive(Clone, Copy, Debug, Default, PartialEq)]
37pub struct DrawLinePayload {
38    pub server_pen: i32,
39    pub client_pen: i32,
40    pub p1: Point,
41    pub p2: Point,
42}
43
44render_data_payload!(DrawLinePayload => DrawLine { server_pen: i32, client_pen: i32, p1: Point, p2: Point });
45
46/// Followed by `box_shadow_count` box shadows.
47#[derive(Clone, Copy, Debug, Default, PartialEq)]
48pub struct DrawRectanglePayload {
49    pub server_brush: i32,
50    pub server_pen: i32,
51    pub client_pen: i32,
52    pub rect: RoundedRect,
53    pub box_shadow_count: i32,
54}
55
56render_data_payload!(DrawRectanglePayload => DrawRectangle {
57    server_brush: i32,
58    server_pen: i32,
59    client_pen: i32,
60    rect: RoundedRect,
61    box_shadow_count: i32,
62});
63
64#[derive(Clone, Copy, Debug, Default, PartialEq)]
65pub struct DrawEllipsePayload {
66    pub server_brush: i32,
67    pub server_pen: i32,
68    pub client_pen: i32,
69    pub rect: Rect,
70}
71
72render_data_payload!(DrawEllipsePayload => DrawEllipse {
73    server_brush: i32,
74    server_pen: i32,
75    client_pen: i32,
76    rect: Rect,
77});
78
79#[derive(Clone, Copy, Debug, Default, PartialEq)]
80pub struct DrawGeometryPayload {
81    pub server_brush: i32,
82    pub server_pen: i32,
83    pub client_pen: i32,
84    pub geometry: i32,
85}
86
87render_data_payload!(DrawGeometryPayload => DrawGeometry {
88    server_brush: i32,
89    server_pen: i32,
90    client_pen: i32,
91    geometry: i32,
92});
93
94#[derive(Clone, Copy, Debug, Default, PartialEq)]
95pub struct DrawGlyphRunPayload {
96    pub server_brush: i32,
97    pub glyph_run: i32,
98}
99
100render_data_payload!(DrawGlyphRunPayload => DrawGlyphRun { server_brush: i32, glyph_run: i32 });
101
102#[derive(Clone, Copy, Debug, Default, PartialEq)]
103pub struct DrawBitmapPayload {
104    pub bitmap: i32,
105    pub opacity: f64,
106    pub source_rect: Rect,
107    pub dest_rect: Rect,
108}
109
110render_data_payload!(DrawBitmapPayload => DrawBitmap { bitmap: i32, opacity: f64, source_rect: Rect, dest_rect: Rect });
111
112#[derive(Clone, Copy, Debug, Default, PartialEq)]
113pub struct DrawCustomPayload {
114    pub operation: i32,
115}
116
117render_data_payload!(DrawCustomPayload => DrawCustom { operation: i32 });
118
119#[derive(Clone, Copy, Debug, Default, PartialEq)]
120pub struct PushClipPayload {
121    pub clip: RoundedRect,
122}
123
124render_data_payload!(PushClipPayload => PushClip { clip: RoundedRect });
125
126#[derive(Clone, Copy, Debug, Default, PartialEq)]
127pub struct PushGeometryClipPayload {
128    pub geometry: i32,
129}
130
131render_data_payload!(PushGeometryClipPayload => PushGeometryClip { geometry: i32 });
132
133#[derive(Clone, Copy, Debug, Default, PartialEq)]
134pub struct PushOpacityPayload {
135    pub opacity: f64,
136}
137
138render_data_payload!(PushOpacityPayload => PushOpacity { opacity: f64 });
139
140#[derive(Clone, Copy, Debug, Default, PartialEq)]
141pub struct PushOpacityMaskPayload {
142    pub brush: i32,
143    pub bounds: Rect,
144}
145
146render_data_payload!(PushOpacityMaskPayload => PushOpacityMask { brush: i32, bounds: Rect });
147
148#[derive(Clone, Copy, Debug, Default, PartialEq)]
149pub struct PushTransformPayload {
150    pub matrix: Matrix,
151}
152
153render_data_payload!(PushTransformPayload => PushTransform { matrix: Matrix });
154
155#[derive(Clone, Copy, Debug, Default, PartialEq)]
156pub struct PushRenderOptionsPayload {
157    pub options: RenderOptions,
158}
159
160render_data_payload!(PushRenderOptionsPayload => PushRenderOptions { options: RenderOptions });
161
162#[derive(Clone, Copy, Debug, Default, PartialEq)]
163pub struct PushTextOptionsPayload {
164    pub options: TextOptions,
165}
166
167render_data_payload!(PushTextOptionsPayload => PushTextOptions { options: TextOptions });
168
169#[derive(Clone, Copy, Debug, Default, PartialEq)]
170pub struct PushEffectPayload {
171    pub effect: i32,
172    pub bounds: Rect,
173}
174
175render_data_payload!(PushEffectPayload => PushEffect { effect: i32, bounds: Rect });