RenderContext

Struct RenderContext 

Source
pub struct RenderContext {
Show 13 fields pub(crate) width: u16, pub(crate) height: u16, pub(crate) paint: PaintType, pub(crate) paint_transform: Affine, pub(crate) stroke: Stroke, pub(crate) transform: Affine, pub(crate) fill_rule: Fill, pub(crate) temp_path: BezPath, pub(crate) aliasing_threshold: Option<u8>, pub(crate) encoded_paints: Vec<EncodedPaint>, pub(crate) render_settings: RenderSettings, dispatcher: Box<dyn Dispatcher>, pub(crate) glyph_caches: Option<GlyphCaches>,
}
Expand description

A render context.

Fields§

§width: u16§height: u16§paint: PaintType§paint_transform: Affine§stroke: Stroke§transform: Affine§fill_rule: Fill§temp_path: BezPath§aliasing_threshold: Option<u8>§encoded_paints: Vec<EncodedPaint>§render_settings: RenderSettings§dispatcher: Box<dyn Dispatcher>§glyph_caches: Option<GlyphCaches>

Implementations§

Source§

impl RenderContext

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, settings: RenderSettings) -> Self

Create a new render context with specific settings.

Source

fn encode_current_paint(&mut self) -> Paint

Source

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

Fill a path.

Source

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

Stroke a path.

Source

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

Fill a rectangle.

Source

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

Source

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

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

Note that this only works properly if the current paint is set to a solid color. If not, it will fall back to using black as the fill color.

Source

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

Stroke a rectangle.

Source

pub fn glyph_run(&mut self, font: &FontData) -> GlyphRunBuilder<'_, Self>

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>, )

Push a new layer with the given properties.

Note that the mask, if provided, needs to have the same size as the render context. Otherwise, it will be ignored. In addition to that, the mask will not be affected by the current transformation matrix in place.

Source

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

Push a new clip layer.

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 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 push_mask_layer(&mut self, mask: Mask)

Push a new mask layer.

Note that the mask, if provided, needs to have the same size as the render context. Otherwise, it will be ignored. In addition to that, the mask will not be affected by the current transformation matrix in place.

Source

pub fn pop_layer(&mut self)

Pop the last-pushed layer.

Source

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

Set the current stroke.

Source

pub fn stroke(&self) -> &Stroke

Get the current stroke

Source

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

Set the current paint.

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 paint_transform(&self) -> &Affine

Get the current paint transform.

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 current fill rule.

Source

pub fn fill_rule(&self) -> &Fill

Get the current fill rule.

Source

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

Set the current transform.

Source

pub fn transform(&self) -> &Affine

Get the current transform.

Source

pub fn reset_transform(&mut self)

Reset the current transform.

Source

pub fn reset(&mut self)

Reset the render context.

Source

pub fn flush(&mut self)

Flush any pending operations.

This is a no-op when using the single-threaded render mode, and can be ignored. For multi-threaded rendering, you have to call this before rasterizing, otherwise the program will panic.

Source

pub fn render_to_buffer( &self, buffer: &mut [u8], width: u16, height: u16, render_mode: RenderMode, )

Render the current context into a buffer. The buffer is expected to be in premultiplied RGBA8 format with length width * height * 4

Source

pub fn render_to_pixmap(&self, pixmap: &mut Pixmap)

Render the current context into a pixmap.

Source

pub fn width(&self) -> u16

Return the width of the pixmap.

Source

pub fn height(&self) -> u16

Return the height of the pixmap.

Source

pub fn render_settings(&self) -> &RenderSettings

Return the render settings used by the RenderContext.

Source§

impl RenderContext

Recording management implementation.

Source

fn generate_strips_from_commands( &mut self, commands: &[RenderCommand], buffers: (StripStorage, Vec<usize>), ) -> (StripStorage, Vec<usize>)

Generate strips from strip commands and capture ranges.

Returns:

  • collected_strips: The generated strips.
  • collected_alphas: The generated alphas.
  • strip_start_indices: The start indices of strips for each geometry command.
Source§

impl RenderContext

Recording management implementation.

Source

fn process_geometry_command( &mut self, strip_start_indices: &[usize], range_index: usize, adjusted_strips: &[Strip], )

Source

fn prepare_cached_strips( &mut self, cached_strips: &[Strip], cached_alphas: &[u8], ) -> Vec<Strip>

Prepare cached strips for rendering by adjusting indices.

Source

fn take_current_state(&mut self) -> RenderState

Save the current rendering state.

Source

fn restore_state(&mut self, state: RenderState)

Restore the saved rendering state.

Trait Implementations§

Source§

impl ColrRenderer for RenderContext

Source§

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

Push a new clip layer.
Source§

fn push_blend_layer(&mut self, blend_mode: BlendMode)

Push a new blend layer.
Source§

fn fill_solid(&mut self, color: AlphaColor<Srgb>)

Fill the current area with the given solid color.
Source§

fn fill_gradient(&mut self, gradient: Gradient)

Fill the current area with the given gradient color.
Source§

fn set_paint_transform(&mut self, affine: Affine)

Set the transform for paints.
Source§

fn pop_layer(&mut self)

Pop the last clip/blend layer.
Source§

impl Debug for RenderContext

Source§

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

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

impl GlyphRenderer for RenderContext

Source§

fn fill_glyph(&mut self, prepared_glyph: PreparedGlyph<'_>)

Fill glyphs with the current paint and fill rule.
Source§

fn stroke_glyph(&mut self, prepared_glyph: PreparedGlyph<'_>)

Stroke glyphs with the current paint and stroke settings.
Source§

fn take_glyph_caches(&mut self) -> GlyphCaches

Takes the glyph caches from the renderer for use in a glyph run. Read more
Source§

fn restore_glyph_caches(&mut self, cache: GlyphCaches)

Restores the glyph caches after a glyph run. Read more
Source§

impl Recordable for RenderContext

Source§

fn record<F>(&mut self, recording: &mut Recording, f: F)
where F: FnOnce(&mut Recorder<'_>),

Record rendering commands into a recording. Read more
Source§

fn prepare_recording(&mut self, recording: &mut Recording)

Generate sparse strips for a recording. Read more
Source§

fn execute_recording(&mut self, recording: &Recording)

Execute a recording directly without preparation. Read more

Auto Trait Implementations§

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> 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(value: T, _simd: S) -> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.