pub struct RenderContext {
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) anti_alias: bool,
pub(crate) encoded_paints: Vec<EncodedPaint>,
pub(crate) render_settings: RenderSettings,
dispatcher: Box<dyn Dispatcher>,
}
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
§anti_alias: bool
§encoded_paints: Vec<EncodedPaint>
§render_settings: RenderSettings
§dispatcher: Box<dyn Dispatcher>
Implementations§
Source§impl RenderContext
impl RenderContext
Sourcepub fn new(width: u16, height: u16) -> Self
pub fn new(width: u16, height: u16) -> Self
Create a new render context with the given width and height in pixels.
Sourcepub fn new_with(width: u16, height: u16, settings: RenderSettings) -> Self
pub fn new_with(width: u16, height: u16, settings: RenderSettings) -> Self
Create a new render context with specific settings.
fn encode_current_paint(&mut self) -> Paint
Sourcepub fn stroke_path(&mut self, path: &BezPath)
pub fn stroke_path(&mut self, path: &BezPath)
Stroke a path.
Sourcepub fn fill_blurred_rounded_rect(
&mut self,
rect: &Rect,
radius: f32,
std_dev: f32,
)
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.
Sourcepub fn stroke_rect(&mut self, rect: &Rect)
pub fn stroke_rect(&mut self, rect: &Rect)
Stroke a rectangle.
Sourcepub fn glyph_run(&mut self, font: &Font) -> GlyphRunBuilder<'_, Self>
pub fn glyph_run(&mut self, font: &Font) -> GlyphRunBuilder<'_, Self>
Creates a builder for drawing a run of glyphs that have the same attributes.
Sourcepub fn push_layer(
&mut self,
clip_path: Option<&BezPath>,
blend_mode: Option<BlendMode>,
opacity: Option<f32>,
mask: Option<Mask>,
)
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.
Sourcepub fn push_clip_layer(&mut self, path: &BezPath)
pub fn push_clip_layer(&mut self, path: &BezPath)
Push a new clip layer.
Sourcepub fn push_blend_layer(&mut self, blend_mode: BlendMode)
pub fn push_blend_layer(&mut self, blend_mode: BlendMode)
Push a new blend layer.
Sourcepub fn push_opacity_layer(&mut self, opacity: f32)
pub fn push_opacity_layer(&mut self, opacity: f32)
Push a new opacity layer.
Sourcepub fn set_anti_aliasing(&mut self, value: bool)
pub fn set_anti_aliasing(&mut self, value: bool)
Set whether to enable anti-aliasing.
Sourcepub fn push_mask_layer(&mut self, mask: Mask)
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.
Sourcepub fn set_stroke(&mut self, stroke: Stroke)
pub fn set_stroke(&mut self, stroke: Stroke)
Set the current stroke.
Sourcepub fn set_paint_transform(&mut self, paint_transform: Affine)
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.
Sourcepub fn paint_transform(&self) -> &Affine
pub fn paint_transform(&self) -> &Affine
Get the current paint transform.
Sourcepub fn reset_paint_transform(&mut self)
pub fn reset_paint_transform(&mut self)
Reset the current paint transform.
Sourcepub fn set_fill_rule(&mut self, fill_rule: Fill)
pub fn set_fill_rule(&mut self, fill_rule: Fill)
Set the current fill rule.
Sourcepub fn set_transform(&mut self, transform: Affine)
pub fn set_transform(&mut self, transform: Affine)
Set the current transform.
Sourcepub fn reset_transform(&mut self)
pub fn reset_transform(&mut self)
Reset the current transform.
Sourcepub fn flush(&mut self)
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.
Sourcepub fn render_to_buffer(
&self,
buffer: &mut [u8],
width: u16,
height: u16,
render_mode: RenderMode,
)
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
Sourcepub fn render_to_pixmap(&self, pixmap: &mut Pixmap)
pub fn render_to_pixmap(&self, pixmap: &mut Pixmap)
Render the current context into a pixmap.
Sourcepub fn render_settings(&self) -> &RenderSettings
pub fn render_settings(&self) -> &RenderSettings
Return the render settings used by the RenderContext
.
Source§impl RenderContext
Recording management implementation.
impl RenderContext
Recording management implementation.
Sourcefn generate_strips_from_commands(
&mut self,
commands: &[RenderCommand],
buffers: (Vec<Strip>, Vec<u8>, Vec<usize>),
) -> (Vec<Strip>, Vec<u8>, Vec<usize>)
fn generate_strips_from_commands( &mut self, commands: &[RenderCommand], buffers: (Vec<Strip>, Vec<u8>, Vec<usize>), ) -> (Vec<Strip>, Vec<u8>, 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.
impl RenderContext
Recording management implementation.
fn process_geometry_command( &mut self, command: &RenderCommand, strip_start_indices: &[usize], range_index: usize, adjusted_strips: &[Strip], )
Sourcefn prepare_cached_strips(
&mut self,
cached_strips: &[Strip],
cached_alphas: &[u8],
) -> Vec<Strip>
fn prepare_cached_strips( &mut self, cached_strips: &[Strip], cached_alphas: &[u8], ) -> Vec<Strip>
Prepare cached strips for rendering by adjusting indices.
Sourcefn generate_fill_strips(
&mut self,
path: &BezPath,
strips: &mut Vec<Strip>,
transform: Affine,
strip_generator: &mut StripGenerator,
)
fn generate_fill_strips( &mut self, path: &BezPath, strips: &mut Vec<Strip>, transform: Affine, strip_generator: &mut StripGenerator, )
Generate strips for a filled path.
Sourcefn generate_stroke_strips(
&mut self,
path: &BezPath,
strips: &mut Vec<Strip>,
transform: Affine,
strip_generator: &mut StripGenerator,
)
fn generate_stroke_strips( &mut self, path: &BezPath, strips: &mut Vec<Strip>, transform: Affine, strip_generator: &mut StripGenerator, )
Generate strips for a stroked path.
Sourcefn take_current_state(&mut self, alphas: Vec<u8>) -> RenderState
fn take_current_state(&mut self, alphas: Vec<u8>) -> RenderState
Save the current rendering state.
Sourcefn restore_state(&mut self, state: RenderState)
fn restore_state(&mut self, state: RenderState)
Restore the saved rendering state.