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.
- Atlas
Rect - 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.
- Glyph
Key - What identifies a glyph in the atlas.
- Gradient
Stop - 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.
- Path
Builder - Accumulates verbs and points into a
Path. - Positioned
Glyph - One glyph, placed.
- Recording
- A finished recording, ready to submit.
- Rect
- A rectangle in user coordinates.
- Runtime
Program - A caller’s fragment program, in the forms each backend can take one.
- Source
Rect - A rectangle in texels, as a sprite’s source.
- Sprite
- One piece of a sprite sheet, and where it goes.
- Stroke
Style - A stroke’s geometric parameters.
- Texture
Descriptor - What to allocate, or what to import.
- Texture
Usage - 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§
- Atlas
Error - Why a glyph could not be added.
- Blend
Factor - A factor a blend equation multiplies one side by.
- Blend
Mode - How a draw combines with what a target already holds.
- Color
Filter - A function applied to a material’s color, after the material and before the blend.
- Color
Form - What space a color filter’s matrix expects its input in.
- Color
Space - The primaries a color’s components are stated against.
- Error
- Fill
Rule - How overlapping subpaths combine when filling.
- Gamma
- Which way through the sRGB transfer function a
ColorFilter::Gammagoes. - Image
Filter - A function applied to what a paint drew, rather than to the color it computed.
- LineCap
- How a stroke terminates at an open end.
- Line
Join - How a stroke turns a corner.
- Mask
Blur Style - Which part of a blurred shape survives.
- Pixel
Format - Pixel formats the renderer can target.
- Point
Mode - 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.
- Tile
Mode - What happens outside an image’s own bounds.
- Vertex
Mode - 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.
- Rounding
Radii - A rounded rectangle’s four corners, each with an x and a y radius.