Skip to main content

vello_common/
render_state.rs

1// Copyright 2025 the Vello Authors
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4//! Shared render state.
5
6use crate::kurbo::{Cap, Join, Stroke};
7use crate::paint::{PaintType, Tint};
8use crate::peniko::color::palette::css::BLACK;
9use crate::peniko::{BlendMode, Compose, Fill, Mix};
10use crate::transforms::Transforms;
11
12/// A render state which contains the style properties for path rendering.
13#[derive(Debug, Clone)]
14pub struct RenderState {
15    /// The paint type (solid color, gradient, or image).
16    pub paint: PaintType,
17    /// Stroke style for path stroking operations.
18    pub stroke: Stroke,
19    /// Fill rule for path filling operations.
20    pub fill_rule: Fill,
21    /// Blend mode for compositing.
22    pub blend_mode: BlendMode,
23    /// The tint for image painting.
24    pub tint: Option<Tint>,
25    /// State of active transforms.
26    pub transforms: Transforms,
27}
28
29impl Default for RenderState {
30    fn default() -> Self {
31        Self {
32            paint: BLACK.into(),
33            stroke: Stroke {
34                width: 1.0,
35                join: Join::Bevel,
36                start_cap: Cap::Butt,
37                end_cap: Cap::Butt,
38                ..Default::default()
39            },
40            fill_rule: Fill::NonZero,
41            blend_mode: BlendMode::new(Mix::Normal, Compose::SrcOver),
42            tint: None,
43            transforms: Transforms::default(),
44        }
45    }
46}
47
48impl RenderState {
49    /// Reset to default state.
50    pub fn reset(&mut self) {
51        *self = Self::default();
52    }
53}