Skip to main content

vello_common/
lib.rs

1// Copyright 2025 the Vello Authors
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4// After you edit the crate's doc comment, run this command, then check README.md for any missing links
5// cargo rdme --workspace-project=vello_common
6
7//! This crate includes common geometry representations, tiling logic, and other fundamental components used by both [Vello CPU][vello_cpu] and Vello Hybrid.
8//!
9//! # Usage
10//!
11//! This crate should not be used on its own, and you should instead use one of the renderers which use it.
12//! At the moment, only [Vello CPU][vello_cpu] is published, and you probably want to use that.
13//!
14//! We also develop [Vello](https://crates.io/crates/vello), which makes use of the GPU for 2D rendering and has higher performance than Vello CPU.
15//! Vello CPU is being developed as part of work to address shortcomings in Vello.
16//! Vello does not use this crate.
17//!
18//! # Features
19//!
20//! - `std` (enabled by default): Get floating point functions from the standard library
21//!   (likely using your target's libc).
22//! - `libm`: Use floating point implementations from [libm][].
23//! - `png` (enabled by default): Allow loading [`Pixmap`][crate::pixmap::Pixmap]s from PNG images.
24//!   Also required for rendering glyphs with an embedded PNG.
25//!   Implies `std`.
26//!
27//! At least one of `std` and `libm` is required; `std` overrides `libm`.
28//!
29//! # Contents
30//!
31//! - Shared data structures for paths, tiles, and strips
32//! - Geometry processing utilities
33//! - Common logic for rendering stages
34//!
35//! This crate acts as a foundation for `vello_cpu` and `vello_hybrid`, providing essential components to minimize duplication.
36//!
37//! [vello_cpu]: https://crates.io/crates/vello_cpu
38#![cfg_attr(feature = "libm", doc = "[libm]: libm")]
39#![cfg_attr(not(feature = "libm"), doc = "[libm]: https://crates.io/crates/libm")]
40// LINEBENDER LINT SET - lib.rs - v3
41// See https://linebender.org/wiki/canonical-lints/
42// These lints shouldn't apply to examples or tests.
43#![cfg_attr(not(test), warn(unused_crate_dependencies))]
44// These lints shouldn't apply to examples.
45#![warn(clippy::print_stdout, clippy::print_stderr)]
46// Targeting e.g. 32-bit means structs containing usize can give false positives for 64-bit.
47#![cfg_attr(target_pointer_width = "64", warn(clippy::trivially_copy_pass_by_ref))]
48// END LINEBENDER LINT SET
49#![cfg_attr(docsrs, feature(doc_cfg))]
50#![forbid(unsafe_code)]
51#![expect(
52    clippy::cast_possible_truncation,
53    reason = "We temporarily ignore those because the casts\
54only break in edge cases, and some of them are also only related to conversions from f64 to f32."
55)]
56#![no_std]
57
58// Suppress the unused_crate_dependencies lint when both std and libm are specified.
59#[cfg(all(feature = "std", feature = "libm"))]
60use libm as _;
61
62extern crate alloc;
63#[cfg(feature = "std")]
64extern crate std;
65
66pub mod blurred_rounded_rect;
67pub mod clip;
68pub mod encode;
69pub mod filter;
70pub mod filter_effects;
71pub mod flatten;
72pub(crate) mod flatten_simd;
73pub mod geometry;
74pub mod image_cache;
75pub mod mask;
76pub mod math;
77pub mod multi_atlas;
78pub mod paint;
79#[doc(hidden)]
80#[cfg(feature = "pico_svg")]
81pub mod pico_svg;
82pub mod pixmap;
83#[doc(hidden)]
84#[cfg(feature = "probe")]
85pub mod probe;
86pub mod record;
87pub mod rect;
88pub mod render_state;
89pub mod simd;
90pub mod strip;
91pub mod strip_generator;
92pub mod tile;
93pub mod transforms;
94pub mod util;
95pub mod viewport;
96
97pub use fearless_simd;
98pub use peniko;
99pub use peniko::color;
100pub use peniko::kurbo;
101
102/// A handle to an external, user-provided texture.
103///
104/// This is resolved at render time by passing in a mapping of handles to textures, but is
105/// otherwise opaque to the renderer.
106#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
107pub struct TextureId(pub u64);