Skip to main content

OpCode

Enum OpCode 

Source
#[repr(i32)]
pub enum OpCode {
Show 23 variants FillRect = 0, StrokeRect = 1, FillRrect = 2, FillEllipse = 3, StrokeEllipse = 4, StrokeArc = 5, Line = 6, Text = 7, Save = 8, Restore = 9, Concat = 10, FillPolygon = 11, StrokePolygon = 12, StrokeRrect = 13, SetGradient = 14, FillPath = 15, StrokePath = 16, Clip = 17, StrokeStyle = 18, SetFont = 19, Stamp = 20, StampPoints = 21, Image = 22,
}
Expand description

The canvas wire op codes (§11, §15.3): slot 0 of every 9-number record in encode_ops’s output. The numeric values are the frozen wire contract: the JNI, C++, and JS decoders each hand-write these as constants, so a value here may never be reused or renumbered; new ops append. ALL drives the density test that keeps this enum and the encoder in step.

Variants§

§

FillRect = 0

Fill a rect (a,b=origin, c,d=size).

§

StrokeRect = 1

Stroke a rect (g=width).

§

FillRrect = 2

Fill a rounded rect (e=radius).

§

FillEllipse = 3

Fill an ellipse in a rect.

§

StrokeEllipse = 4

Stroke an ellipse (g=width).

§

StrokeArc = 5

Stroke an arc (e=start°, f=sweep°, g=width). Fill(Shape::Arc) also encodes as this with width 0, the known asymmetry; see encode_ops.

§

Line = 6

Line a,b → c,d (g=width).

§

Text = 7

Text at a,b (e=size, f=anchor: 0 leading / 1 centered); the string rides the texts channel.

§

Save = 8

Save the graphics state.

§

Restore = 9

Restore the graphics state.

§

Concat = 10

Concat an affine transform (a..f).

§

FillPolygon = 11

Fill a polygon; points ride the texts channel as “x,y x,y …” (closed automatically). a = the geometry_key of those points, or 0 for none.

§

StrokePolygon = 12

Stroke a polygon (g=width); points and key as OpCode::FillPolygon.

§

StrokeRrect = 13

Stroke a rounded rect (e=radius, g=width).

§

SetGradient = 14

Set a gradient for the next shape record (f=type: 0 linear with a,b=start / c,d=end unit points; 1 radial with a,b=center unit point, c=unit radius; e=stop count). Stops ride the texts channel as “offset,aarrggbb offset,aarrggbb …”. Unit geometry resolves against the shape’s bounding box.

§

FillPath = 15

Fill a path (f=fill rule: 0 non-zero / 1 even-odd); segments ride the texts channel (see encode_path). a = the geometry_key of those segments, or 0 for none.

The key is a cache handle, not a payload: a decoder that recognizes it may keep the native geometry it built last time and skip re-parsing the segments, but it must still consume the texts entry either way, because that channel is positional and a skipped entry desynchronizes every record after it.

§

StrokePath = 16

Stroke a path (g=width); segments and key as OpCode::FillPath.

§

Clip = 17

Clip to a shape (f=shape kind: 0 rect / 1 rrect(e=radius) / 2 ellipse / 3 path (e=fill rule) / 4 polygon; a..d=geometry; path/polygon payloads ride the texts channel).

For the two payload-bearing kinds (3 and 4) there is no geometry in the slots, so a carries the geometry_key instead and b..d stay 0. The other three kinds put real geometry in a..d and have nothing to cache.

§

StrokeStyle = 18

Stroke style for the next stroke record (a=cap, b=join, c=miter limit, d=dash phase, e=dash count; the dash array rides the texts channel).

§

SetFont = 19

Font for the next text record (a=CSS weight 100 … 900, 0 = default; b=italic 0/1); the family name rides the texts channel, "" = the platform’s default face. Like OpCode::SetGradient and OpCode::StrokeStyle it is consumed by the record that follows and then cleared; a default CanvasFont emits no record at all, so a drawing without fonts encodes exactly as it did before this op existed.

§

Stamp = 20

The next shape record is a template, drawn once per stamped position rather than once (docs/canvas.md “Stamping”). a = how many positions follow. Like OpCode::SetGradient, OpCode::StrokeStyle and OpCode::SetFont it is a prefix, consumed by the record it applies to and then cleared.

Between this and that template record come ceil(a / 4) OpCode::StampPoints records carrying the coordinates. A drawing with no stamps encodes exactly as it did before.

§

StampPoints = 21

Four stamped positions, filling the record edge to edge: [op, x0, y0, x1, y1, x2, y2, x3, y3], the one record that uses its last slot for geometry instead of a color, because it carries no color of its own. The final record of a run is padded; the count in the OpCode::Stamp header says how many of the pairs are real.

§

Image = 22

Draw a decoded image: a,b = origin, c,d = size, e = the BitmapId, f = opacity in 0.0..=1.0 (docs/images.md).

The id rides the numeric channel because it is a number, and an f64 carries a u64 id exactly up to 2^53; ids are minted from 1 per process, so that ceiling is unreachable. Nothing rides the texts channel for this op.

Implementations§

Source§

impl OpCode

Source

pub const ALL: [OpCode; 23]

Every code, in wire order. The density test iterates this so a new variant that forgets to join fails loudly.

Source

pub fn from_wire(n: f64) -> Option<OpCode>

The code back from a wire number (a decoder-side aid and the round-trip test’s reference); None for anything outside the table.

Trait Implementations§

Source§

impl Clone for OpCode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for OpCode

Source§

impl Debug for OpCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for OpCode

Source§

impl PartialEq for OpCode

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for OpCode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.