Skip to main content

RenderBackend

Trait RenderBackend 

Source
pub trait RenderBackend: Send {
    type Surface;

Show 16 methods // Required methods fn create_surface( &self, width: u32, height: u32, bg: &RgbaColor, ) -> Self::Surface; fn fill_path( &mut self, surface: &mut Self::Surface, ops: &[PathOp], fill_rule: FillRule, color: &RgbaColor, transform: &Matrix, ); fn stroke_path( &mut self, surface: &mut Self::Surface, ops: &[PathOp], style: &StrokeStyle, color: &RgbaColor, transform: &Matrix, ); fn draw_image( &mut self, surface: &mut Self::Surface, image: &DecodedImage, transform: &Matrix, interpolate: bool, ); fn push_clip( &mut self, surface: &mut Self::Surface, clip: &ClipPath, transform: &Matrix, ); fn pop_clip(&mut self, surface: &mut Self::Surface); fn push_group( &mut self, surface: &mut Self::Surface, blend_mode: BlendMode, opacity: f32, isolated: bool, knockout: bool, ); fn pop_group(&mut self, surface: &mut Self::Surface); fn surface_dimensions(&self, surface: &Self::Surface) -> (u32, u32); fn composite_over(&mut self, dst: &mut Self::Surface, src: &Self::Surface); fn surface_pixels(&self, surface: &Self::Surface) -> Vec<u8> ; fn finish(self, surface: Self::Surface) -> Bitmap; // Provided methods fn fill_path_no_aa( &mut self, surface: &mut Self::Surface, ops: &[PathOp], fill_rule: FillRule, color: &RgbaColor, transform: &Matrix, ) { ... } fn set_group_mask( &mut self, _alpha_data: Vec<u8>, _width: u32, _height: u32, ) { ... } fn draw_alpha_bitmap( &mut self, _surface: &mut Self::Surface, _alpha: &[u8], _width: u32, _height: u32, _bearing_x: i32, _bearing_y: i32, _color: &RgbaColor, _transform: &Matrix, ) { ... } fn set_antialiasing(&mut self, _enabled: bool) { ... }
}
Expand description

Trait for a 2D rendering backend.

Implementations provide the actual drawing operations (fill, stroke, clip, compositing) using a concrete rendering library (e.g., tiny-skia).

Required Associated Types§

Source

type Surface

The surface type used by this backend.

Required Methods§

Source

fn create_surface( &self, width: u32, height: u32, bg: &RgbaColor, ) -> Self::Surface

Create a new rendering surface with the given dimensions and background.

Source

fn fill_path( &mut self, surface: &mut Self::Surface, ops: &[PathOp], fill_rule: FillRule, color: &RgbaColor, transform: &Matrix, )

Fill a path with the given color and transform.

Source

fn stroke_path( &mut self, surface: &mut Self::Surface, ops: &[PathOp], style: &StrokeStyle, color: &RgbaColor, transform: &Matrix, )

Stroke a path with the given style, color, and transform.

Source

fn draw_image( &mut self, surface: &mut Self::Surface, image: &DecodedImage, transform: &Matrix, interpolate: bool, )

Draw a decoded image with the given transform.

When interpolate is true, the backend should use bilinear (or higher) filtering instead of nearest-neighbor. This matches PDFium’s auto-bilinear heuristic for upscaled images (see CStretchEngine::UseInterpolateBilinear).

Source

fn push_clip( &mut self, surface: &mut Self::Surface, clip: &ClipPath, transform: &Matrix, )

Push a clipping region onto the clip stack.

Source

fn pop_clip(&mut self, surface: &mut Self::Surface)

Pop the most recent clipping region.

Source

fn push_group( &mut self, surface: &mut Self::Surface, blend_mode: BlendMode, opacity: f32, isolated: bool, knockout: bool, )

Begin a transparency group with the given blend mode, opacity, and transparency group attributes.

Source

fn pop_group(&mut self, surface: &mut Self::Surface)

End the current transparency group, compositing it onto the surface below.

Source

fn surface_dimensions(&self, surface: &Self::Surface) -> (u32, u32)

Return the dimensions (width, height) of the given surface.

Source

fn composite_over(&mut self, dst: &mut Self::Surface, src: &Self::Surface)

Draw the content of src over dst using normal (SourceOver) blending.

This is used to composite rendered content (on a transparent backdrop) onto a background-color surface.

Source

fn surface_pixels(&self, surface: &Self::Surface) -> Vec<u8>

Return the raw pixel data of the surface as premultiplied RGBA bytes.

Source

fn finish(self, surface: Self::Surface) -> Bitmap

Finish rendering and return the final bitmap.

Provided Methods§

Source

fn fill_path_no_aa( &mut self, surface: &mut Self::Surface, ops: &[PathOp], fill_rule: FillRule, color: &RgbaColor, transform: &Matrix, )

Fill a path with anti-aliasing forced off.

Used by shading subdivision where upstream PDFium uses full_cover = true to avoid visible seams between adjacent sub-patches.

Source

fn set_group_mask(&mut self, _alpha_data: Vec<u8>, _width: u32, _height: u32)

Set a soft mask on the topmost group entry.

The mask is provided as a single-channel alpha buffer (one byte per pixel, row-major, same dimensions as the surface). Implementations store it so that pop_group can apply the mask during compositing.

Source

fn draw_alpha_bitmap( &mut self, _surface: &mut Self::Surface, _alpha: &[u8], _width: u32, _height: u32, _bearing_x: i32, _bearing_y: i32, _color: &RgbaColor, _transform: &Matrix, )

Draw a pre-rasterized alpha bitmap at the given position with the given color.

The alpha data is a row-major single-channel bitmap. Each pixel in the output should be colored with color modulated by the alpha value.

Source

fn set_antialiasing(&mut self, _enabled: bool)

Set whether anti-aliasing is enabled for subsequent fill/stroke operations.

Backends may ignore this hint. The default implementation is a no-op.

Implementors§