jovian / venusian-blend2d
Blend2D for Venusian Topside: the blend2d drawing engine, through ext-blend2d.
Requires
- php: ~8.4.27||^8.5.12
- ext-blend2d: ^0.11.0
- venusian/topside: ^0.11.5
Requires (Dev)
- pestphp/pest: ^4
- venusian/framework: ^0.11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-03 14:58:14 UTC
README
Blend2D for Venusian Topside, through ext-blend2d: the blend2d drawing engine. It reads a draw list and draws it on the CPU, with Blend2D's own calls, into memory Blend2D allocates.
Requirements
- Linux or macOS, PHP 8.4+.
- ext-blend2d 0.11, which builds the Blend2D it ships with, with its
blphp_path_append_segments(). - venusian/topside 0.11.
Install
composer require jovian/venusian-blend2d
The provider registers blend2d on topside's engine manager. Name it in config to make it the default:
// config/engines.php return ['default' => 'blend2d'];
Its own settings are Blend2D's rendering threads and its JIT, in config/blend2d.php:
php computer vendor:publish --tag=blend2d-config
Usage
use Surface\Contracts\Graphics\Painter; use Surface\Engines\FrameRequest; use Surface\Engines\OffscreenSurface; use Surface\Engines\PixelMemory; use Surface\NutsAndBolts\Color; $recorder = app('graphics.recorders')->driver(); $root = $recorder->group()->add($recorder->record( fn (Painter $painter) => $painter->fill( $painter->path()->moveTo(10, 10)->lineTo(90, 10)->lineTo(50, 90)->close(), new Color(1.0, 0.0, 0.0), ), )); $engine = app('engines')->driver('blend2d'); $frame = $engine->frame(new OffscreenSurface(100, 100)); $response = $engine->execute(new FrameRequest($frame, [$recorder->list($root)])); $response->missed; // [] when all of it was drawn $memory = $frame->give(PixelMemory::class); // address, width, height, stride, FormatSpec::bgra8Premultiplied()
Behavior
- Frames. One
BL_FORMAT_PRGB32image a frame: rows of premultiplied B, G, R, A bytes at one address for the frame's life. On a surface that lendsPixelMemoryinFormatSpec::bgra8Premultiplied(), at the surface's size, Blend2D draws into that memory at its stride; on any other, one that lends nothing or only forms the engine does not take, Blend2D allocates the memory at the surface's size. A frame of its own is in the first of the surface'sformats()thatmakes()names, else in the first ofmakes(), so no surface is refused for a format; on lent memoryformats()is not read. Lent memory in another format (both are named withdescribe()), of another size, or with a stride less than a row (a negative one included) is refused; a stride that is not a multiple of four is taken. A frame's width and height are pixels; the surface's scale is how many pixels one drawing unit covers and applies to the whole request.draws()answersFormatSpec::bgra8Premultiplied();makes()answers it and thenFormatSpec::rgba8Straight(). A frame of its own inFormatSpec::rgba8Straight()keeps its premultiplied image as it is and a copy beside it, rows of exactly width × 4 bytes of R, G, B, A, straight alpha, in a byte array Blend2D allocates (bl_array_resize, its address frombl_array_make_mutable), filled whole by Blend2D's pixel converter (bl_pixel_converter_convert) at the end of each draw: itsPixelMemoryis the copy, unwritten until the next draw, and its owner,Blend2DConverted, holds the array and the converter, so the copy outlivesrelease()while thatPixelMemoryis held. A frame givesPixelMemory; no pixel is ever a PHP value. - Requests.
execute()draws a request's lists in order in one rendering context, over what the frame holds when the request says it holds a backdrop and on a cleared frame otherwise (a frame said to hold its last draw is drawn whole), and answers with the frame, the whole of it changed, and what was missed. It draws only into a blend2d frame. - Drawing. Paths, fill rules, solid colors, linear and radial gradients with every spread, caps, joins, miter limits, save, restore and transforms are Blend2D's own. Gradient stops are interpolated by Blend2D, a gradient holds any number of them, and two stops at one offset are a hard edge between their colors.
- Redraws. A picture never changes, so the engine reads it once and keeps the
BLPaths, colors, gradients and matrices it made, for as long as the picture lives. A new picture's paths go from their own memory intoBLPaths in one call each, whatever their length. - What Blend2D lacks is left out with all that is inside it, and the rest is drawn:
| Capability | Left out |
|---|---|
CLIP_TO_PATH |
what a picture draws under clip() until its restore; a group with a clip |
GROUP_OPACITY |
a group with an opacity below 1 |
STROKE_DASHES |
a dashed stroke |
The response's missed names the capabilities it missed, supports() answers beforehand, and one CapabilityMissing mail (engine.capability.missing.blend2d) goes out the first time each is missed, through topside's RenderingEngineAdapter.
Testing
See .okf/runbooks/testing.md. The tests need ext-blend2d.
License
MIT. See LICENSE.