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    // Append new opcodes so existing byte values remain stable.
26    PushCompositingLayer,
27}
28
29impl RenderDataOpcode {
30    const ALL: [RenderDataOpcode; 18] = [
31        Self::Invalid,
32        Self::DrawLine,
33        Self::DrawRectangle,
34        Self::DrawEllipse,
35        Self::DrawGeometry,
36        Self::DrawGlyphRun,
37        Self::DrawBitmap,
38        Self::DrawCustom,
39        Self::PushClip,
40        Self::PushGeometryClip,
41        Self::PushOpacity,
42        Self::PushOpacityMask,
43        Self::PushTransform,
44        Self::PushRenderOptions,
45        Self::PushTextOptions,
46        Self::PushEffect,
47        Self::Pop,
48        Self::PushCompositingLayer,
49    ];
50}
51
52/// One byte, as the `byte`-backed enumeration of upstream. A byte that
53/// names no opcode reads as [`RenderDataOpcode::Invalid`].
54impl BatchValue for RenderDataOpcode {
55    #[inline]
56    fn write_to(&self, out: &mut Vec<u8>) {
57        out.push(*self as u8);
58    }
59
60    #[inline]
61    fn read_from(input: &mut BatchValueReader<'_>) -> Self {
62        let value = input.take::<1>()[0];
63        Self::ALL.get(value as usize).copied().unwrap_or(Self::Invalid)
64    }
65}