Skip to content

plutovg, plutosvg and their ucode bindings - #163

Merged
dangowrt merged 4 commits into
openwrt:masterfrom
dangowrt:ucode-plutovg
Sep 25, 2026
Merged

dangowrt merged 4 commits into
openwrt:masterfrom
dangowrt:ucode-plutovg

Conversation

@dangowrt

Copy link
Copy Markdown
Member

Four packages: the plutovg rasteriser, the plutosvg renderer built on it, and a ucode binding for each.

plutovg is a software rasteriser for 2D vector graphics, MIT licensed, with no dependency beyond libc. It draws onto a 32-bit premultiplied ARGB surface that can wrap memory the caller already owns, which is what makes it usable against a buffer something else has mapped. plutosvg parses SVG documents and renders them through plutovg, built without the optional freetype support, which only serves OpenType SVG glyphs. Both are small: 89 KB and 17 KB packaged for aarch64.

Both carry --wrap-mode=nofallback. plutosvg ships a subprojects/plutovg.wrap, and without that argument meson downloads and builds a second private copy rather than using the packaged one, which also breaks a buildbot where the network is available only during the download phase.

The two ucode modules expose those APIs to scripts. ucode-mod-plutovg covers surfaces, canvases, paths, matrices, solid, gradient and texture paints, stroking with dash patterns, clipping, compositing and text rendering, with colours, points, rectangles, matrices and gradient stops passed as plain ucode objects or arrays. ucode-mod-plutosvg covers loading a document from memory or from a file, querying its intrinsic size and element extents, and rendering a document or a single element onto a plutovg canvas or into a fresh surface, with CSS currentColor and colour variables resolved from a ucode object or callback.

Together they let a ucode program draw vector graphics into a buffer it does not own, which is what a scripted boot splash needs: SVG stays SVG in the source tree, and nothing has to ship rendered bitmaps or pull in a rendering toolchain at build time.

Build tested for rockchip/armv8 (aarch64, musl) and run tested on a Radxa ROCK 5B.

Software rasteriser for paths, strokes, gradients and transforms onto a
32-bit premultiplied ARGB surface, which it can create over memory the
caller already owns. Needed to draw a boot splash procedurally rather
than from a baked frame sequence.

Links against nothing but libc, and comes to 172 KiB on aarch64. The
font face cache is disabled along with the examples and tests, since
nothing here renders text.

Signed-off-by: Daniel Golle <[email protected]>
Parses SVG and draws it through plutovg, which lets a theme ship its
artwork as text rather than as rendered bitmaps. 33 KiB on aarch64, and
it needs nothing beyond plutovg and libc.

freetype is disabled: it only serves OpenType SVG glyphs, and pulling it
in for that would outweigh the library several times over. The bundled
plutovg wrap is refused so a failed dependency check cannot stage a
second copy over the packaged one.

Signed-off-by: Daniel Golle <[email protected]>
@openwrt openwrt Bot added add package Introduces a new package Makefile build script not following guidelines Pull request does not follow formatting guidelines labels Sep 25, 2026
Make the plutovg drawing API usable from ucode. Surfaces, canvases,
paths, paints and font faces become ucode resource types with method
tables, while colours, points, rectangles, matrices and gradient stops
cross the boundary as plain ucode objects or arrays, so a whole scene
can be built and mutated from script. Enumerations are spelled as
strings rather than opaque integers.

Each resource holds one plutovg reference and drops it from the type
destructor; getters that return a borrowed pointer take a reference
before wrapping it, so a canvas keeps its surface alive and nothing is
released twice at collection time.

The value conversion helpers live in a separate header installed into
the staging directory because the plutosvg binding needs the same
colour and rectangle marshalling.

Signed-off-by: Daniel Golle <[email protected]>
Make SVG documents loadable and renderable from ucode. A document is a
resource type that reports its intrinsic size, computes the extents of
the whole drawing or of one element by id, and renders either onto a
plutovg canvas or into a fresh surface. CSS currentColor is passed as
an ordinary colour value and colour variables resolve through a ucode
object or callback invoked during rendering.

Script data handed to the loader is copied because the parser keeps
pointers into it for the lifetime of the document; the copy is released
through the destroy callback. An element id is dereferenced in the
frame that owns the argument, as a short ucode string lives inside the
variable holding the value.

Surfaces returned by the renderer are plutovg resources, so the plutovg
module is loaded on demand when it is not already present.

Signed-off-by: Daniel Golle <[email protected]>
@openwrt openwrt Bot removed the not following guidelines Pull request does not follow formatting guidelines label Sep 25, 2026
@dangowrt
dangowrt merged commit e54dc4e into openwrt:master Sep 25, 2026
14 checks passed
@dangowrt
dangowrt deleted the ucode-plutovg branch September 25, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add package Introduces a new package Makefile build script

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant