Skip to main content

Crate skia_canvas

Crate skia_canvas 

Source
Expand description

GPU-accelerated, multi-threaded HTML Canvas-compatible 2D rendering for Rust and Node, powered by Skia.

§Rust consumers: use the prelude

The crate-root modules are the stable, supported Rust API; the prelude re-exports them all. Public signatures never expose skia_safe or neon types – a compile-time pin verifies this. The Node/Neon binding lives under the internal node module.

use skia_canvas::prelude::*;

let backend = Backend::new();
let mut surface = backend.create_surface(
    1920,
    1080,
    SurfaceOptions {
        color_space: LinearColorSpace::DisplayP3,
        ..SurfaceOptions::default()
    },
)?;

surface.with_canvas(|canvas| {
    canvas.clear(RgbaLinear::new_premultiplied(0.0, 0.0, 0.0, 0.0));
    canvas.draw_rect(
        Rect::from_xywh(100.0, 100.0, 200.0, 100.0),
        &Paint::fill(RgbaLinear::opaque(1.0, 0.0, 0.0)),
    );
});

let frame = surface.read_pixels()?;

See docs/api/native-rust.md in the repository for a longer reference (color spaces, alpha semantics, surfaces, paint, paths, shaders, filters, images, text, fonts).

§Cargo features

  • vulkan – enable the Vulkan backend (Linux / Windows).
  • metal – enable the Metal backend (macOS).
  • window – enable the winit-backed GUI window/event loop.
  • freetype – bundle FreeType + WOFF2 support for font registration on Linux containers / minimal images.
  • node-addon – register the #[neon::main] entry point so the resulting cdylib loads as a Node.js addon. Pure-Rust consumers should leave this off.

Pure-Rust consumers typically depend with default-features = false and pick the backend they need:

[dependencies]
skia-canvas = { version = "0.2", default-features = false, features = ["vulkan", "freetype"] }

Modules§

backend
color
error
filter
font
geometry
image
paint
path
pixels
prelude
Glob-importable re-export of the whole public API: use skia_canvas::prelude::*;.
recorder
shader
surface
text