Skip to main content

Crate emblema

Crate emblema 

Source
Expand description

emblema: a 2D vector renderer that tessellates paths on the CPU and needs no compute shaders.

Frosted glass panels with a progress ring, a line chart, bars, a donut chart and toggles, drawn by emblema

Draw into a Canvas with a Paint, finish it into a Recording, and hand that to a Context, which owns the device and the backend it picked. The showcase example draws the frame above; the repository’s README has the rest.

FeatureDefaultWhat it adds
vulkanyesThe Vulkan 1.1 backend.
present-wsiyesPresenting into a Vulkan swapchain. Implies vulkan.
glesThe GLES 3.0 backend.
present-eglPresenting into an EGL window surface. Implies gles.
drmDirect scanout to a KMS plane. Vulkan draws into it today; GLES does not yet.
gbmScanout from buffers GBM allocates on the display’s side, for a display that cannot take what the renderer allocates. Implies drm; needs Rust 1.94.1.

The whole of it, from a device to pixels in memory:

use emblema::{BackendPreference, Canvas, Color, Context, Extent2D, Paint, PixelFormat, Rect};

// The backend is chosen at run time, so one binary serves a board with a
// working Vulkan driver and one where only GLES is usable.
let mut ctx = Context::new(BackendPreference::Auto)?;

let size = Extent2D::new(256, 256);
let mut surface = ctx.create_surface(size, PixelFormat::Rgba8Unorm)?;

let mut canvas = Canvas::new(size);
canvas.clear(Color::WHITE);
canvas.draw_rect(
    Rect::new(32.0, 32.0, 224.0, 224.0),
    &Paint::fill(Color::rgba8(0, 120, 220, 255)),
)?;

// Recording is separate from submitting, so a whole frame is described
// before any of it reaches the GPU and every shape shares one pass.
ctx.draw(&mut surface, &canvas.finish())?;
let pixels = ctx.read(&mut surface)?;

// Destroyed explicitly, because nothing here frees a GPU object on drop. A
// surface still alive when its context goes is a child outliving its device,
// which the validation layer reports as an error rather than a leak.
ctx.destroy_surface(surface);

Which backend runs is decided when the context is created, not when the binary is built, so one image can boot on a board with a working Vulkan driver and on one where only GLES is usable.

Code above the backend branches on Context::capabilities rather than on which backend it got. A device that cannot export a fence is the same problem whichever API it speaks, and asking which backend it is gets both cases wrong.

Re-exports§

pub use backend::Backend;
pub use backend::BackendPreference;
pub use context::Context;
pub use context::Image;
pub use context::Surface;
pub use emblema_present_drm as drm;drm
pub use emblema_hal_vulkan as vulkan;vulkan
pub use emblema_hal_gles as gles;gles
pub use emblema_present_vk as wsi;present-wsi
pub use emblema_present_egl as egl;present-egl
pub use emblema_present as present;

Modules§

backend
Choosing a rendering backend at runtime.
context
A rendering context, over whichever backend is available.
execute
Draw a recording into a texture this crate did not create.

Structs§

Affine2
Two-dimensional vector and affine types, from glam. A 2D affine transform, which can represent translation, rotation, scaling and shear.
Atlas
A square atlas of glyph coverage, and where each glyph landed.
AtlasRect
Where a glyph sits in the atlas, in texels.
Canvas
Records drawing commands for one frame.
Capabilities
Everything the layers above the HAL are allowed to branch on.
Color
A linear, straight-alpha color.
Coverage
A rasterized glyph, as a caller supplies it.
Dash
A dash pattern: alternating drawn and skipped lengths, and where to start.
DmaBufPlaneUnix
One plane of a dma-buf image.
Extent2D
A 2D extent in pixels.
ExternalImageDescUnix
An image that already exists, to be imported rather than allocated.
Float32Support
What a device can do with one of the 32-bit float formats, past sampling it texel by texel, which every device here can.
Fourcc
What Context::import_image takes: a dma-buf’s planes, its DRM format and its layout. A DRM fourcc format code.
GlyphKey
What identifies a glyph in the atlas.
GradientStop
A color stop in a gradient.
Layer
How a layer is composited back onto what was underneath it.
MemoryBlocks
The sizes of the blocks a backend takes device memory in, in bytes.
MemoryUse
Memory allocated from a backend’s blocks, in bytes, by the two kinds MemoryBlocks has: what only the device reads, and what the host writes or reads through.
Modifier
What Context::import_image takes: a dma-buf’s planes, its DRM format and its layout. A DRM format modifier describing the memory layout of a buffer.
Morphology
Spreading or shrinking a finished layer, one axis at a time.
Paint
Everything about how a shape is painted.
Path
A path: a verb stream plus the points those verbs consume.
PathBuilder
Accumulates verbs and points into a Path.
PositionedGlyph
One glyph, placed.
Recording
A finished recording, ready to submit.
Rect
A rectangle in user coordinates.
RuntimeProgram
A caller’s fragment program, in the forms each backend can take one.
ShaderVariant
The parts of the built-in shader one draw needs: its material’s arm, and whether it filters its color and blends its tint by a mode other than Modulate.
SourceRect
A rectangle in texels, as a sprite’s source.
Sprite
One piece of a sprite sheet, and where it goes.
StrokeStyle
A stroke’s geometric parameters.
TextureDescriptor
What to allocate, or what to import.
TextureUsage
How a texture will be used, which backends need up front to choose a layout.
Transform2D
A transform of the plane that may carry perspective.
Vec2
Two-dimensional vector and affine types, from glam. A 2-dimensional vector.
Vertices
A mesh of triangles in user space, with optional texture coordinates.

Enums§

AtlasError
Why a glyph could not be added.
BlendFactor
A factor a blend equation multiplies one side by.
BlendMode
How a draw combines with what a target already holds.
ColorFilter
A function applied to a material’s color, after the material and before the blend.
ColorForm
What space a color filter’s matrix expects its input in.
ColorSpace
The primaries a color’s components are stated against.
Error
FillRule
How overlapping subpaths combine when filling.
Gamma
Which way through the sRGB transfer function a ColorFilter::Gamma goes.
ImageFilter
A function applied to what a paint drew, rather than to the color it computed.
LineCap
How a stroke terminates at an open end.
LineJoin
How a stroke turns a corner.
MaskBlurStyle
Which part of a blurred shape survives.
MaterialVariant
Which arm of the built-in shader a material is drawn by.
PixelFormat
Pixel formats the renderer can target.
PointMode
How a run of points is joined up.
Sampling
How a texture is read between its texels.
Shader
What fills a shape.
Style
Fill the shape, or trace its outline.
TileMode
What happens outside an image’s own bounds.
VertexMode
How positions are grouped into triangles.

Constants§

EFFECT_BYTES
Bytes of the effect block a draw binds: RUNTIME_FLOATS of them.
MAX_STOPS
The most stops a gradient carries in the material itself.
MORPHOLOGY_TAPS
How far one morphology pass reaches, in texels each way.
RUNTIME_FLOATS
How many floats a runtime effect may take: 6,208 bytes, the most Flutter’s shader compiler (impellerc) lets a fragment program declare.

Traits§

Hal
A rendering backend, as a family of associated types.

Functions§

execute
Draw a recording into a texture this crate did not create.
execute_deferred
Draw a recording into a texture this crate did not create.
execute_layers
Draw a recording into a texture this crate did not create.
mip_levels_for
How many mip levels an image of this size has, counting the image itself.
render_offscreen
Draw a recording into a texture this crate did not create.

Type Aliases§

Result
Result alias used throughout the HAL.
RoundingRadii
A rounded rectangle’s four corners, each with an x and a y radius.