Skip to main content

Crate impeller

Crate impeller 

Source
Expand description

impeller-rs: a tessellation-based 2D vector renderer.

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

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)))?;

ctx.draw(&mut surface, &canvas.finish())?;
let pixels = ctx.read(&mut surface)?;
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 impeller_present_drm as drm;
pub use impeller_hal_vulkan as vulkan;
pub use impeller_hal_gles as gles;
pub use impeller_present_vk as wsi;
pub use impeller_present_egl as egl;
pub use impeller_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.
Extent2D
A 2D extent in pixels.
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.
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.
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.
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§

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.

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.