Skip to main content

Scene

Struct Scene 

Source
pub struct Scene { /* private fields */ }
Expand description

A render context for GPU rendering.

This context maintains the state for path rendering and manages the rendering pipeline from paths to strips that can be rendered by the GPU.

Implementations§

Source§

impl Scene

Source

pub fn new(width: u16, height: u16) -> Self

Create a new render context with the given width and height in pixels.

Source

pub fn new_with(width: u16, height: u16, level: Level) -> Self

Create a new render context with a specific SIMD level.

Source

pub fn fill_path(&mut self, path: &BezPath)

Fill a path with the current paint and fill rule.

Source

pub fn push_clip_path(&mut self, path: &BezPath)

Push a new clip path to the clip stack.

See the explanation in the clipping example for how this method differs from push_clip_layer.

Source

pub fn push_clip_rect(&mut self, rect: &Rect)

Push a rectangular clip path.

Source

pub fn pop_clip(&mut self)

Pop the most recently pushed clip path or clip rectangle from the clip stack.

Note that unlike push_clip_layer, it is permissible to have pending pushed clips before finishing the rendering operation.

Source

pub fn stroke_path(&mut self, path: &BezPath)

Stroke a path with the current paint and stroke settings.

Source

pub fn set_aliasing_threshold(&mut self, aliasing_threshold: Option<u8>)

Set the aliasing threshold.

If set to None (which is the recommended option in nearly all cases), anti-aliasing will be applied.

If instead set to some value, then a pixel will be fully painted if the coverage is bigger than the threshold (between 0 and 255), otherwise it will not be painted at all.

Note that there is no performance benefit to disabling anti-aliasing and this functionality is simply provided for compatibility.

Source

pub fn fill_rect(&mut self, rect: &Rect)

Fill a rectangle with the current paint and fill rule.

Source

pub fn stroke_rect(&mut self, rect: &Rect)

Stroke a rectangle with the current paint and stroke settings.

Source

pub fn fill_blurred_rounded_rect( &mut self, rect: &Rect, radius: f32, std_dev: f32, invert: bool, )

Fill a blurred rectangle with the given corner radius and standard deviation.

When invert is true, the inverse (1 - alpha) of the blur coverage is painted: the paint is fully opaque outside the blurred rectangle and fades to transparent inside it. This can be used to implement inset box shadows.

This operation uses the current transform and paint transform. Like Vello CPU, it only uses solid paints; non-solid paints fall back to black.

Source

pub fn glyph_run<'a>( &'a mut self, resources: &'a mut Resources, font: &FontData, ) -> GlyphRunBuilder<'a>

Creates a builder for drawing a run of glyphs that have the same attributes.

Source

pub fn push_layer( &mut self, clip_path: Option<&BezPath>, blend_mode: Option<BlendMode>, opacity: Option<f32>, mask: Option<Mask>, filter: Option<Filter>, )

Push a new layer with the given properties.

§Panics

Panics if mask is provided because mask layers are not yet supported.

Source

pub fn push_clip_layer(&mut self, path: &BezPath)

Push a new clip layer.

See the explanation in the clipping example for how this method differs from push_clip_path.

Source

pub fn push_blend_layer(&mut self, blend_mode: BlendMode)

Push a new blend layer.

Source

pub fn push_opacity_layer(&mut self, opacity: f32)

Push a new opacity layer.

Source

pub fn push_mask_layer(&mut self, mask: Mask)

Push a new mask layer.

§Panics

This method currently always panics since masks are not supported yet.

Source

pub fn push_filter_layer(&mut self, filter: Filter)

Push a new filter layer.

Source

pub fn pop_layer(&mut self)

Pop the last pushed layer.

Source

pub fn set_blend_mode(&mut self, blend_mode: BlendMode)

Set the blend mode for subsequent rendering operations.

§Panics

Panics if blend_mode is destructive, which is currently not supported for non-isolated blends. You need to use clip layers instead if you need that behavior.

Source

pub fn set_stroke(&mut self, stroke: Stroke)

Set the stroke settings for subsequent stroke operations.

Source

pub fn stroke(&self) -> &Stroke

Get the current stroke.

Source

pub fn set_paint(&mut self, paint: impl Into<PaintType>)

Set the paint for subsequent rendering operations.

Source

pub fn set_tint(&mut self, tint: Option<Tint>)

Set the tint for subsequent image paint operations.

Source

pub fn reset_tint(&mut self)

Clear the tint, so subsequent image paints are drawn without tinting.

Source

pub fn paint(&self) -> &PaintType

Get the current paint.

Source

pub fn set_paint_transform(&mut self, paint_transform: Affine)

Set the current paint transform.

The paint transform is applied to the paint after the transform of the geometry the paint is drawn in, i.e., the paint transform is applied after the global transform. This allows transforming the paint independently from the drawn geometry.

Source

pub fn reset_paint_transform(&mut self)

Reset the current paint transform.

Source

pub fn set_fill_rule(&mut self, fill_rule: Fill)

Set the fill rule for subsequent fill operations.

Source

pub fn set_transform(&mut self, transform: Affine)

Set the transform for subsequent rendering operations.

Source

pub fn reset_transform(&mut self)

Reset the transform to identity.

Source

pub fn set_filter_effect(&mut self, filter: Filter)

Apply filter to the current paint (affects next drawn element).

Source

pub fn reset_filter_effect(&mut self)

Reset the current filter effect.

Source

pub fn reset_and_resize(&mut self, width: u16, height: u16)

Reset the scene and update its size.

Source

pub fn reset(&mut self)

Reset scene to default values.

Source

pub fn width(&self) -> u16

Get the width of the render context.

Source

pub fn height(&self) -> u16

Get the height of the render context.

Source

pub fn take_current_state(&mut self) -> RenderState

Take current rendering state and reset the existing state to its default.

Source

pub fn save_current_state(&mut self) -> RenderState

Save a copy of the current rendering state.

Source

pub fn restore_state(&mut self, state: RenderState)

Restore rendering state.

Trait Implementations§

Source§

impl Debug for Scene

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DrawSink for Scene

DrawSink for the GPU Scene.

Source§

fn set_transform(&mut self, t: Affine)

Set the current transform.
Source§

fn set_paint(&mut self, paint: AtlasPaint)

Set the current paint.
Source§

fn set_paint_transform(&mut self, t: Affine)

Set the paint transform.
Source§

fn fill_path(&mut self, path: &BezPath)

Fill a path with the current paint and transform.
Source§

fn fill_rect(&mut self, rect: &Rect)

Fill a rectangle with the current paint and transform.
Source§

fn push_clip_layer(&mut self, clip: &BezPath)

Push a clip layer defined by a path.
Source§

fn push_clip_path(&mut self, clip: &BezPath)

Push a clip path. Read more
Source§

fn push_clip_rect(&mut self, clip: &Rect)

Push a rectangular clip path.
Source§

fn push_blend_layer(&mut self, blend_mode: BlendMode)

Push a blend/compositing layer.
Source§

fn pop_layer(&mut self)

Pop the most recent clip or blend layer.
Source§

fn pop_clip_path(&mut self)

Pop the most recent clip path. Read more
Source§

fn width(&self) -> u16

Width of the surface.
Source§

fn height(&self) -> u16

Height of the surface.
Source§

impl GlyphRenderer for Scene

Source§

type SavedState = RenderState

The type of state used by the renderer.
Source§

fn save_state(&mut self) -> Self::SavedState

Save the current state.
Source§

fn restore_state(&mut self, state: Self::SavedState)

Restore the current state.
Source§

fn stroke_path(&mut self, path: &BezPath)

Stroke a path with the current paint and stroke settings.
Source§

fn set_paint_image(&mut self, image: Image)

Set the current paint to an image.
Source§

fn set_tint(&mut self, tint: Option<Tint>)

Set the tint for subsequent image draws.
Source§

fn get_context_color(&self) -> AlphaColor<Srgb>

Get the context color from the renderer’s current paint, used for resolving the context-dependent colors of COLR glyphs.
Source§

fn current_paint(&self) -> &PaintType

Get the currently active paint.
Source§

fn atlas_image_source(&self, atlas_slot: &AtlasSlot) -> ImageSource

Construct the ImageSource for sampling a cached glyph from the atlas.
Source§

fn atlas_paint_transform(&self, _atlas_slot: &AtlasSlot) -> Affine

Compute the paint transform for sampling a cached glyph from the atlas.
Source§

impl ProbeRenderer for Scene

Source§

fn set_transform(&mut self, transform: Affine)

Source§

fn set_paint(&mut self, paint: PaintType)

Source§

fn fill_path(&mut self, path: &BezPath)

Source§

fn fill_rect(&mut self, rect: &Rect)

Source§

fn push_layer(&mut self, blend_mode: Option<BlendMode>, opacity: Option<f32>)

Source§

fn push_filter_layer(&mut self, filter: Filter)

Source§

fn pop_layer(&mut self)

Source§

fn set_paint_transform(&mut self, paint_transform: Affine)

Source§

fn reset_paint_transform(&mut self)

Auto Trait Implementations§

§

impl !Freeze for Scene

§

impl !RefUnwindSafe for Scene

§

impl !Sync for Scene

§

impl Send for Scene

§

impl Unpin for Scene

§

impl UnsafeUnpin for Scene

§

impl UnwindSafe for Scene

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,