#[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.