module pkg::alloy::drawsource
A retained 2D renderer over pkg::alloy::gpu (PLAN.md, stage F3): a canvas holds a tree of nodes, each with a transform, a clip for its children and a paint, the primitives it draws in its own coordinates. A frame redraws only what changed since the last one, into a texture the canvas keeps, then copies that to the frame. Coordinates are physical pixels, y down; colors are sRGB with straight alpha, blended as browsers blend them.
var canvas = Canvas::create(&var device, surface.format);
const card = canvas.add(canvas.root());
canvas.set_transform(card, Transform::translate(40.0, 40.0));
var paint = Paint::empty();
paint.rounded_rect(Rect::sized(300.0, 200.0), Radii::all(12.0), Fill::Color(Color::white()));
canvas.paint(card, move paint);
// on Redraw
if (canvas.damaged()) {
if (device.acquire(surface, window.size()) is ::Some |frame|) {
var encoder = Encoder::empty();
canvas.render(&var device, &var encoder, frame);
device.submit(move encoder);
device.present(surface, &var window);
}
}
## How it was built
Notes kept from each stage as it was finished, the sizes and numbers of their day; what changed since is in REVIEW.md and the history.
**F3 as built** (2026-10-12):
draw:draw.alloythe API (geometry,Paint,Canvas),encoding.alloyprimitives asdraw.wgsl's instances,damage.alloy,atlas.alloy,frame.alloythe resources and a frame. The API is the design's, with: fills asFill::Color(c),Fill::linear,Fill::radial(and_stopsforms, at most 8 stops); a node's clip applies to its children, not its own paint, so a card's shadow stays outside the clip that rounds its contents; shadows take one radius, the top left one, and a blur of 0 is a plain rounded rectangle;Pictureis a texture's region:canvas.pictureandcanvas.maskpack RGBA images and coverage masks of up to 256 pixels a side into 1024x1024 shelf-packed pages (a border of one pixel, an image's edge repeated), larger ones getting a texture, andPicture::wholetakes a texture of the program's;paint.image(area, picture, Filter);canvas.damage_all()after a resize or anything outside the canvas;canvas.stats()what the last frame drew, for tests and benchmarks;canvas.release(&var device).- Each node keeps its encoded instances, 48 floats each, its texture groups and device boxes, encoded again when its paint changes or, with its descendants, its transform or clip; a node changed marks its ancestors so a frame visits only changed subtrees. Its old and new bounds are damaged, kept as at most 16 rectangles as they come, then snapped to pixels and merged until none overlap and at most 4 remain; past 60% of the frame, the whole frame is drawn. Each rectangle gets a clearing instance (a second pipeline, replacing) and the instances touching it in painter's order, in runs of one texture; untextured ones join any run. The kept texture is copied to the frame, which copies must be able to write.
gpugainedTextureFormat::R8Unorm,Encoder::copy_texture,write_texture_regionandColor::rgba,white,transparent; stdVector::append(a push a byte took a third of the encoding) andread_filereading past a size of 0 (/proc); the compiler no longer lets a free function specialize a method of the same name.- Tests:
alloyc test draw/tests.alloy(geometry, damage, batching, on the CPU device), andtests/canvas.alloy's seven golden scenes (tests/golden/draw/), the last drawn in two frames and compared with the same scene drawn whole: the same on the CPU device, lavapipe and WebGPU through Dawn here, on biscuit's GTX 1660 and on the Windows desktop's RTX 4070 Ti.samples/cards.alloyfloats three of twelve cards by their transforms (run under a headless weston here; not yet seen by a person;cards.exeis in.alloy\window-testson the Windows desktop). - Benchmarks (
bench/,scripts/bench.sh, run byscripts/test.shagainstbench/budgets.txt), the best of five, in milliseconds:
| | lavapipe | GTX 1660 | RTX 4070 Ti | |---|---|---|---| | encoding 10,000 primitives on 1000 nodes | 3.8 | 3.2 | 2.1 | | encoding one node changed among them | 0.07 | 0.06 | 0.03 | | a whole 1920x1080 frame of them, to its fence | 38.5 | 3.0 | 1.3 | | a frame redrawing one node | 1.7 | 0.35 | 0.14 |
(Encoding is CPU time, on each machine's CPU.) The startup program (12 cards in a window) presents its first
frame 64 ms after main under headless weston on lavapipe, which
compiling its pipelines dominates, peaking at 85 MB resident
(lavapipe's LLVM); it is 0.77 MB natively and 0.55 MB of wasm. The
plan's 50 ms and 20 MB targets are for a hello world on a GPU driver,
to measure with F5.
- Left for later: atlas pages are never reclaimed (F4's glyph cache will need eviction), nor are the bind groups of program textures released; images are not snapped to pixels.
**F10d as built** (2026-10-15; decisions/F10.md, "Color emoji"):
glyphs.alloyaskstextforglyph_imageand packs a color glyph into RGBA atlas pages beside the coverage pages (each kind with its own pages and its own eviction, a page's borders clear rather than an edge repeated); a cached glyph says which it is. A color glyph is rasterized once per size, at the quarter-pixel position 0, the other three positions naming its entry, and drawn on whole pixels; one showing the text's color (COLR's 0xFFFF) is kept per color, tints of one glyph listed under its key.encoding.alloy:Kind::Colored, an instancedraw.wgsldraws as its texel times its alpha (COLORED), in white, so that the text's color tints only what the glyph says, as browsers draw emoji; MSL's goldendraw.metalfollows.- Tests:
tests/canvas.alloy'semojiscene, Noto Color Emoji (COLR version 1), Twemoji Mozilla (version 0) and Twemoji (CBDT) subsets oftests/fontsbeside text, the same on the CPU device, lavapipe and WebGPU through Dawn. - Benchmarks (
bench/canvas.alloy): a 1920x1080 page of 1914 emoji of 100 kinds at 26 pixels, 23.7 ms its first frame on lavapipe, which rasterizing and packing them dominates, 13.2 ms drawn again.
**F11c as built** (2026-10-15; decisions/F11.md, "What
window and draw gain"): canvas.set_hidden(node, hidden) and
is_hidden: a hidden node covers nothing (its reach empty, so frames
gather nothing under it) and is skipped with its descendants, which
keep their paint; hiding damages where the subtree drew, showing marks
it moved, so it is measured and drawn again. ui hides the views a
switch or a navigator keeps.
**F11e as built** (2026-10-15; decisions/F11.md, question
12A): canvas.set_opacity(node, opacity) and opacity: the alpha of
every primitive under the node multiplied by the opacities above it as
a frame encodes it (gradient stops' too, as they go into the frame's),
so overlapping parts show through while fading; a node at 0 is skipped
with all under it; a change damages where the subtree reaches.
Color::mix(a, b, t).
**Rounded clips nested** (2026-10-17; decisions/showcase.md,
question 3A, ui's clip_radii): a rectangle clipping inside a
rounded clip, both upright, no longer drops the rounded one for the
scissor: when their intersection is one rounded rectangle (each corner
the rounded clip's own or clear of its curve, as a picture across a
card's top) that is tested per pixel, else the rounded clip is and the
rectangle cuts by the scissor (child_state in encoding.alloy).
A rounded clip inside another still keeps only the inner one's corners.
Golden clips.png gained a band across a rounded card's top.
**F14c as built** (2026-10-20; decisions/F14.md, "Glyph memory", questions 9B and 10A):
glyphs.alloy: a glyph page is cut into 4 by 4 plots, each packed in shelves (Shelvesinatlas.alloy, the pictures' pages' too), stamped with the frame it last gave a glyph and listing the keys of the glyphs (and tints) placed in it; a cached glyph names its page and plot. A glyph goes into the most recently used plot of the budget's pages with room, else an empty one, else a new page while the budget has room (large glyphs the frame has not drawn cleared for it), else the least recently used plot the frame has not drawn from, cleared; only when the frame drew from every plot of the budget does it get a page past it. Clearing forgets just that plot's keys, and never damages.canvas.set_glyph_budget(&var device, GlyphBudget):coverage4 andcolor2 pages, andpage, the side, 1024 (smaller in tests; a change of it empties the cache).canvas.glyph_stats(): pages, those past the budget, plots holding glyphs, the textures' bytes, entries, and the last frame's glyphs rasterized and plots cleared.- At a frame's start (
evict): a page past the budget is kept where the budget has room again; else its plots are cleared once a frame has not drawn from them, or while the budget's pages have plots the last frame did not use, which its glyphs then move into as they are drawn; a page past the budget holding nothing, and a large glyph's texture cleared, are released with their bind groups (Resources::forget). Within the budget pages are kept, so a steady app makes no textures. - A glyph larger than a plot (over 254 pixels a side at 1024) has a texture of its own as a page of one plot, counted in the budget as the plots it covers, past it when no room is made; larger than a page, it is not drawn, as before.
- Entries of glyphs with no pixels, and tinted ones whose tints went,
are forgotten together once 8,192 more were made (
MAX_MARKS). - Pictures: a page emptied by
release_pictureis released at the next frame, but a format's last;release_pictureof aPicture::wholereleases the bind groups made for the program's texture. - Tests:
draw/tests.alloy(least recently used plots first, a frame's overflow released two frames on with its bind group, glyphs moving back into the budget, a lowered budget, large glyphs, empty glyphs forgotten, picture pages and bind groups released);tests/canvas.alloy'sbudgetscene, six lines drawn a frame each under one page of 64 pixels each format, clearing 5 to 9 plots a frame, then the band behind the first line redrawn, compared with the scene drawn at once under the default budget (within one level, question 12);tests/glyph_memory.alloy, the long run. - Every glyph moved, so glyphs sampled at a texel's center round
differently at a few pixels: 26 goldens were written again (
tests/golden/draw/text.png, 13 oftests/golden/ui, 12 oftests/golden/tickets), each differing by one level in one channel at 1 to 7 pixels (question 12). - The long run (
tests/glyph_memory.alloy, 2,000 frames of 640x480 on the CPU device, run byscripts/test.shnatively and for 220 frames for ARM64 under qemu): at most 5 pages (4 of coverage, one of color, 8 MiB), none past the budget, at most 9,571 entries; 48.6 MB resident after its first cycle and 48.2 MB at its end, against 77.8 and 77.1 MB before F14c, of which the fallback faces read whole were about 25 MB (text's "F14c as built"). - Benchmarks (
bench/canvas.alloyon lavapipe):glyph_churn, the 1920x1080 page at a size not cached over a full cache, 20.6 ms (text_frame20.9);glyph_bookkeeping, a frame drawing nothing over that cache, 0.003 ms of CPU;glyph_resident_kb, the long run's growth, 0. The counter grew by 14 KB natively and 13 KB of wasm, hello world by 10 KB and 9 KB.
RectRect::atRect::sizedRect::emptyrightbottomis_emptyintersectionunionintersectsinflatedareaRadiiRadii::allRadii::noneTransformTransform::identityTransform::translateTransform::scaleTransform::rotatethenapplyinversemap_rectStopGradientFillMAX_STOPSFill::linearFill::linear_stopsFill::radialFill::radial_stopsColor::mixShadowShadow::softFilterPicturePicture::wholePaintPaint::emptytextshrinklengthrectrounded_rectbordershadowimageimagemaskNodeIdClipClip::rectClip::roundedFrameStatsCanvasCanvas::createfontsadd_fontadd_font_toreleaserootaddremovecontainsset_transformtransformset_clipset_hiddenset_opacityopacityis_hiddenpaintset_backgrounddamageddamage_allrenderrender_overtexturestatsGlyphBudgetGlyphStatsset_glyph_budgetglyph_statspicturerelease_picturemask
type Rectsource
exp type Rect = struct
A rectangle from its top left corner.
Fields
exp x: f32exp y: f32exp width: f32exp height: f32
Functions
exp fn Rect::at(x: f32, y: f32, width: f32, height: f32) -> Rectexp fn Rect::sized(width: f32, height: f32) -> Rectexp fn Rect::empty() -> Rectexp fn right(self r: &Rect) -> f32exp fn bottom(self r: &Rect) -> f32exp fn is_empty(self r: &Rect) -> boolexp fn intersection(self r: &Rect, other: &Rect) -> Rectexp fn union(self r: &Rect, other: &Rect) -> Rectexp fn intersects(self r: &Rect, other: &Rect) -> boolexp fn inflated(self r: &Rect, by: f32) -> Rectexp fn area(self r: &Rect) -> f32
fn Rect::atsource
exp fn Rect::at(x: f32, y: f32, width: f32, height: f32) -> Rect
fn Rect::sizedsource
exp fn Rect::sized(width: f32, height: f32) -> Rect
A rectangle at the origin.
fn Rect::emptysource
exp fn Rect::empty() -> Rect
fn rightsource
exp fn right(self r: &Rect) -> f32
fn bottomsource
exp fn bottom(self r: &Rect) -> f32
fn is_emptysource
exp fn is_empty(self r: &Rect) -> bool
fn intersectionsource
exp fn intersection(self r: &Rect, other: &Rect) -> Rect
What both cover, empty when they do not meet.
fn unionsource
exp fn union(self r: &Rect, other: &Rect) -> Rect
The smallest rectangle holding both, an empty one counting for nothing.
fn intersectssource
exp fn intersects(self r: &Rect, other: &Rect) -> bool
fn inflatedsource
exp fn inflated(self r: &Rect, by: f32) -> Rect
The rectangle grown by by on every side.
fn areasource
exp fn area(self r: &Rect) -> f32
type Radiisource
exp type Radii = struct
A rounded rectangle's corner radii.
Fields
exp top_left: f32exp top_right: f32exp bottom_right: f32exp bottom_left: f32
Functions
fn Radii::allsource
exp fn Radii::all(radius: f32) -> Radii
fn Radii::nonesource
exp fn Radii::none() -> Radii
type Transformsource
exp type Transform = struct
A 2D affine transform: the point (x, y) goes to (a x + c y + tx, b x + d y + ty).
Fields
exp a: f32exp b: f32exp c: f32exp d: f32exp tx: f32exp ty: f32
Functions
exp fn Transform::identity() -> Transformexp fn Transform::translate(x: f32, y: f32) -> Transformexp fn Transform::scale(x: f32, y: f32) -> Transformexp fn Transform::rotate(radians: f32) -> Transformexp fn then(self t: &Transform, next: &Transform) -> Transformexp fn apply(self t: &Transform, p: Point) -> Pointexp fn inverse(self t: &Transform) -> Transformexp fn map_rect(self t: &Transform, r: &Rect) -> Rect
fn Transform::identitysource
exp fn Transform::identity() -> Transform
fn Transform::translatesource
exp fn Transform::translate(x: f32, y: f32) -> Transform
fn Transform::scalesource
exp fn Transform::scale(x: f32, y: f32) -> Transform
fn Transform::rotatesource
exp fn Transform::rotate(radians: f32) -> Transform
Turns by the angle, clockwise on the screen, about the origin.
fn thensource
exp fn then(self t: &Transform, next: &Transform) -> Transform
This transform, then the next.
fn applysource
exp fn apply(self t: &Transform, p: Point) -> Point
fn inversesource
exp fn inverse(self t: &Transform) -> Transform
The transform undoing this one; a flat one has none, and gives the identity.
fn map_rectsource
exp fn map_rect(self t: &Transform, r: &Rect) -> Rect
The bounds of the rectangle once transformed.
type Stopsource
exp type Stop = struct
A gradient's color at an offset from 0 to 1 along it.
Fields
exp offset: f32exp color: Color
type Gradientsource
exp type Gradient = struct
Two points: a linear gradient's start and end, or a radial one's center and a point on its circle.
Fields
exp start: Pointexp end: Pointexp stops: Vector<Stop>
type Fillsource
exp type Fill = enum
Variants
Color: ColorLinear: GradientRadial: Gradient
Functions
const MAX_STOPSsource
exp const MAX_STOPS: u64 = 8;
At most this many stops a gradient.
fn Fill::linearsource
exp fn Fill::linear(start: Point, end: Point, colors: &[Color]) -> Fill
A linear gradient through the colors, evenly spaced.
fn Fill::linear_stopssource
exp fn Fill::linear_stops(start: Point, end: Point, stops: &[Stop]) -> Fill
fn Fill::radialsource
exp fn Fill::radial(center: Point, radius: f32, colors: &[Color]) -> Fill
A radial gradient through the colors, evenly spaced, from the center out to the radius.
fn Fill::radial_stopssource
exp fn Fill::radial_stops(center: Point, radius: f32, stops: &[Stop]) -> Fill
fn Color::mixsource
exp fn Color::mix(a: Color, b: Color, t: f32) -> Color
The color a fraction t of the way from a to b, each component
and the alpha mixed straight: 0 gives a, 1 gives b.
type Shadowsource
exp type Shadow = struct
A box shadow, as CSS's: the shape moved by the offset, grown by the spread and blurred over the blur radius (twice the Gaussian's sigma).
Fields
exp offset: Pointexp blur: f32exp spread: f32exp color: Color
Functions
fn Shadow::softsource
exp fn Shadow::soft(x: f32, y: f32, blur: f32, color: Color) -> Shadow
type Filtersource
exp type Filter = enum
How an image is sampled between its pixels.
Variants
LinearNearest
type Picturesource
exp type Picture = struct
A region of a texture to draw images or masks from: one the canvas
packed (Canvas::picture, Canvas::mask) or one of the program's.
Fields
exp texture: Textureexp region: Rectin the texture's pixels
Functions
fn Picture::wholesource
exp fn Picture::whole(texture: Texture) -> Picture
A whole texture of the program's, which it keeps alive while drawn.
type Paintsource
exp type Paint = struct
What a node draws: primitives in order, in its own coordinates.
Functions
exp fn Paint::empty() -> Paintexp fn text(self paint: &var Paint, layout: &Layout, origin: Point, color: Color)exp fn shrink(self paint: &var Paint)exp fn length(self paint: &Paint) -> u64exp fn rect(self paint: &var Paint, area: Rect, fill: Fill)exp fn rounded_rect(self paint: &var Paint, area: Rect, radii: Radii, fill: Fill)exp fn border(self paint: &var Paint, area: Rect, radii: Radii, width: f32, color: Color)exp fn shadow(self paint: &var Paint, area: Rect, radii: Radii, shadow: Shadow)exp fn image(self paint: &var Paint, area: Rect, picture: Picture)exp fn image(self paint: &var Paint, area: Rect, picture: Picture, filter: Filter)exp fn mask(self paint: &var Paint, area: Rect, picture: Picture, color: Color)
fn Paint::emptysource
exp fn Paint::empty() -> Paint
fn textsource
exp fn text(self paint: &var Paint, layout: &Layout, origin: Point, color: Color)
The layout's text with its pen at origin, its top left, in the
color, but where a span gives its own; underlines and strikethroughs
under it. The layout's fonts are the canvas's (canvas.fonts()).
fn shrinksource
exp fn shrink(self paint: &var Paint)
Gives back the room past what the paint holds, for a paint kept.
fn lengthsource
exp fn length(self paint: &Paint) -> u64
How many primitives it holds.
fn rectsource
exp fn rect(self paint: &var Paint, area: Rect, fill: Fill)
fn rounded_rectsource
exp fn rounded_rect(self paint: &var Paint, area: Rect, radii: Radii, fill: Fill)
fn bordersource
exp fn border(self paint: &var Paint, area: Rect, radii: Radii, width: f32, color: Color)
A border of the width inside the rounded rectangle's edge.
fn shadowsource
exp fn shadow(self paint: &var Paint, area: Rect, radii: Radii, shadow: Shadow)
The rounded rectangle's shadow, drawn under what follows. One radius shapes it, the top left one.
fn imagesource
exp fn image(self paint: &var Paint, area: Rect, picture: Picture)
The picture stretched over the area, filtered linearly.
fn imagesource
exp fn image(self paint: &var Paint, area: Rect, picture: Picture, filter: Filter)
fn masksource
exp fn mask(self paint: &var Paint, area: Rect, picture: Picture, color: Color)
The color where the picture, a coverage mask, covers the area.
type NodeIdsource
exp type NodeId = struct
A node of a canvas, valid until it is removed.
type Clipsource
exp type Clip = struct
A clip: its children draw only inside the rounded rectangle, in the node's coordinates.
Fields
exp area: Rectexp radii: Radii
Functions
fn Clip::rectsource
exp fn Clip::rect(area: Rect) -> Clip
fn Clip::roundedsource
exp fn Clip::rounded(area: Rect, radius: f32) -> Clip
type FrameStatssource
exp type FrameStats = struct
What the last frame drew, for tests and benchmarks.
Fields
exp rects: Vector<Rect>the damaged rectangles redrawn, whole pixels
exp full: boolthe whole frame redrawn
exp instances: u32the primitives drawn, a clear for each rectangle included
exp draws: u32
type Canvassource
exp type Canvas = struct
Functions
exp fn Canvas::create(device: &var Device, format: TextureFormat) -> Canvasexp fn fonts(self canvas: &var Canvas) -> &var Fontsexp fn add_font(self canvas: &var Canvas, bytes: Vector<u8>) -> Option<Family>exp fn add_font_to(self canvas: &var Canvas, family: Family, bytes: Vector<u8>) -> boolexp fn release(self canvas: &var Canvas, device: &var Device)exp fn root(self canvas: &Canvas) -> NodeIdexp fn add(self canvas: &var Canvas, parent: NodeId) -> NodeIdexp fn remove(self canvas: &var Canvas, node: NodeId)exp fn contains(self canvas: &Canvas, node: NodeId) -> boolexp fn set_transform(self canvas: &var Canvas, node: NodeId, transform: Transform)exp fn transform(self canvas: &Canvas, node: NodeId) -> Transformexp fn set_clip(self canvas: &var Canvas, node: NodeId, clip: Option<Clip>)exp fn set_hidden(self canvas: &var Canvas, node: NodeId, hidden: bool)exp fn set_opacity(self canvas: &var Canvas, node: NodeId, opacity: f32)exp fn opacity(self canvas: &Canvas, node: NodeId) -> f32exp fn is_hidden(self canvas: &Canvas, node: NodeId) -> boolexp fn paint(self canvas: &var Canvas, node: NodeId, paint: Paint)exp fn set_background(self canvas: &var Canvas, color: Color)exp fn damaged(self canvas: &Canvas) -> boolexp fn damage_all(self canvas: &var Canvas)exp fn render( self canvas: &var Canvas, device: &var Device, encoder: &var Encoder, frame: Texture )exp fn render_over( self canvas: &var Canvas, device: &var Device, encoder: &var Encoder, frame: Texture )exp fn texture(self canvas: &Canvas) -> Option<Texture>exp fn stats(self canvas: &Canvas) -> &FrameStatsexp fn set_glyph_budget(self canvas: &var Canvas, device: &var Device, budget: GlyphBudget)exp fn glyph_stats(self canvas: &Canvas) -> GlyphStatsexp fn picture( self canvas: &var Canvas, device: &var Device, width: u32, height: u32, pixels: &[u8] ) -> Pictureexp fn release_picture(self canvas: &var Canvas, device: &var Device, picture: Picture)exp fn mask( self canvas: &var Canvas, device: &var Device, width: u32, height: u32, coverage: &[u8] ) -> Picture
fn Canvas::createsource
exp fn Canvas::create(device: &var Device, format: TextureFormat) -> Canvas
A canvas drawing into textures of the format: a surface's, or one the program reads back.
fn fontssource
exp fn fonts(self canvas: &var Canvas) -> &var Fonts
The fonts the canvas draws text in, the bundled family first, for the layouts it draws.
fn add_fontsource
exp fn add_font(self canvas: &var Canvas, bytes: Vector<u8>) -> Option<Family>
A TrueType face as a family of its own (pkg::alloy::text's
Fonts::add).
fn add_font_tosource
exp fn add_font_to(self canvas: &var Canvas, family: Family, bytes: Vector<u8>) -> bool
fn releasesource
exp fn release(self canvas: &var Canvas, device: &var Device)
Releases what the canvas made on the device: its pictures' textures among them.
fn rootsource
exp fn root(self canvas: &Canvas) -> NodeId
The node every other descends from, which the canvas never removes.
fn addsource
exp fn add(self canvas: &var Canvas, parent: NodeId) -> NodeId
A new node, the parent's last child: it draws after the parent's other children, over them.
fn removesource
exp fn remove(self canvas: &var Canvas, node: NodeId)
Removes the node and its descendants; what they drew is damaged.
fn containssource
exp fn contains(self canvas: &Canvas, node: NodeId) -> bool
Whether the node is still there: neither it nor an ancestor removed.
fn set_transformsource
exp fn set_transform(self canvas: &var Canvas, node: NodeId, transform: Transform)
Moves the node and its descendants: the transform takes its coordinates into its parent's.
fn transformsource
exp fn transform(self canvas: &Canvas, node: NodeId) -> Transform
fn set_clipsource
exp fn set_clip(self canvas: &var Canvas, node: NodeId, clip: Option<Clip>)
Clips the node's children, not its own paint, to the rounded rectangle; None draws them whole.
fn set_opacitysource
exp fn set_opacity(self canvas: &var Canvas, node: NodeId, opacity: f32)
Fades the node and its descendants: the alpha of all they draw multiplied by the opacity, from 0 (nothing drawn) to 1, as each primitive is drawn, so where they overlap the lower shows through the upper. Where they draw is damaged.
fn opacitysource
exp fn opacity(self canvas: &Canvas, node: NodeId) -> f32
fn paintsource
exp fn paint(self canvas: &var Canvas, node: NodeId, paint: Paint)
Replaces what the node draws.
fn set_backgroundsource
exp fn set_background(self canvas: &var Canvas, color: Color)
The color under everything, white at first.
fn damagedsource
exp fn damaged(self canvas: &Canvas) -> bool
Whether a frame would change anything: false, the last one stands.
fn damage_allsource
exp fn damage_all(self canvas: &var Canvas)
Redraws the whole next frame, as after the window's size changed.
fn rendersource
exp fn render(
self canvas: &var Canvas,
device: &var Device,
encoder: &var Encoder,
frame: Texture
)
Records the frame's drawing into the encoder: what changed since the last frame redrawn into the texture the canvas keeps, which is then copied to the frame, a texture of the canvas's format that copies may write. A frame of another size than the last redraws everything.
fn render_oversource
exp fn render_over(
self canvas: &var Canvas,
device: &var Device,
encoder: &var Encoder,
frame: Texture
)
The same, but blending the kept texture over what the frame holds
instead of copying it, its premultiplied alpha letting the frame show
where the canvas draws nothing: a canvas whose background is
transparent over another's drawing, as an engine's (pkg::alloy::ui's
Hud). Every frame blends, whether anything changed or not.
fn texturesource
exp fn texture(self canvas: &Canvas) -> Option<Texture>
The texture the canvas keeps its drawing in, of the last frame's size, for a program placing it itself; None before the first frame.
fn statssource
exp fn stats(self canvas: &Canvas) -> &FrameStats
What the last frame drew.
type GlyphBudgetsource
exp type GlyphBudget = struct
How many pages of glyphs the canvas keeps of each format, each cut into 4 by 4 plots, which it clears the least recently used of when it needs room. A frame needing more than these gets pages past them, given back in the frames after it.
Fields
exp coverage: u32 = 4pages of one-byte pixels: 4 MiB
exp color: u32 = 2pages of RGBA: 8 MiB
exp page: u32 = 1024a page's width and height in pixels, a multiple of 4
type GlyphStatssource
exp type GlyphStats = struct
What the glyph cache holds, and what its last frame did.
Fields
exp pages: u32the glyphs' textures, a large glyph's own among them
exp past: u32of them past the budget
exp plots: u32holding glyphs
exp bytes: u64the textures'
exp entries: u64the glyphs the cache knows
exp rasterized: u32by the last frame
exp cleared: u32plots, by the last frame
fn set_glyph_budgetsource
exp fn set_glyph_budget(self canvas: &var Canvas, device: &var Device, budget: GlyphBudget)
Sets the glyph cache's budget, which pages past it follow from the next frame on; a change of the page's size empties the cache.
fn glyph_statssource
exp fn glyph_stats(self canvas: &Canvas) -> GlyphStats
fn picturesource
exp fn picture(
self canvas: &var Canvas,
device: &var Device,
width: u32,
height: u32,
pixels: &[u8]
) -> Picture
Packs the image, RGBA rows with straight alpha, into a texture the canvas keeps: small ones share pages of an atlas.
fn release_picturesource
exp fn release_picture(self canvas: &var Canvas, device: &var Device, picture: Picture)
Gives back what a picture picture packed holds, for the next one;
nothing may draw it afterwards.
fn masksource
exp fn mask(
self canvas: &var Canvas,
device: &var Device,
width: u32,
height: u32,
coverage: &[u8]
) -> Picture
Packs a coverage mask, a byte a pixel, as glyphs are.