Skip to main content

ferroui_base/rendering/composition/drawing/
render_data_opcode.rs

1use crate::rendering::composition::transport::{BatchValue, BatchValueReader};
2
3/// The opcode that starts every operation of a render data stream.
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
5#[repr(u8)]
6pub enum RenderDataOpcode {
7    #[default]
8    Invalid = 0,
9    DrawLine,
10    DrawRectangle,
11    DrawEllipse,
12    DrawGeometry,
13    DrawGlyphRun,
14    DrawBitmap,
15    DrawCustom,
16    PushClip,
17    PushGeometryClip,
18    PushOpacity,
19    PushOpacityMask,
20    PushTransform,
21    PushRenderOptions,
22    PushTextOptions,
23    PushEffect,
24    Pop,
25}
26
27impl RenderDataOpcode {
28    const ALL: [RenderDataOpcode; 17] = [
29        Self::Invalid,
30        Self::DrawLine,
31        Self::DrawRectangle,
32        Self::DrawEllipse,
33        Self::DrawGeometry,
34        Self::DrawGlyphRun,
35        Self::DrawBitmap,
36        Self::DrawCustom,
37        Self::PushClip,
38        Self::PushGeometryClip,
39        Self::PushOpacity,
40        Self::PushOpacityMask,
41        Self::PushTransform,
42        Self::PushRenderOptions,
43        Self::PushTextOptions,
44        Self::PushEffect,
45        Self::Pop,
46    ];
47}
48
49/// One byte, as the `byte`-backed enumeration of upstream. A byte that
50/// names no opcode reads as [`RenderDataOpcode::Invalid`].
51impl BatchValue for RenderDataOpcode {
52    #[inline]
53    fn write_to(&self, out: &mut Vec<u8>) {
54        out.push(*self as u8);
55    }
56
57    #[inline]
58    fn read_from(input: &mut BatchValueReader<'_>) -> Self {
59        let value = input.take::<1>()[0];
60        Self::ALL.get(value as usize).copied().unwrap_or(Self::Invalid)
61    }
62}