Skip to main content

FrameBuffer

Struct FrameBuffer 

Source
pub struct FrameBuffer {
    pub width: usize,
    pub height: usize,
    pub pixels: Vec<u8>,
    pub clip_mask_stack: Vec<Vec<u8>>,
}
Expand description

Headless in-memory RGBA pixel canvas for software rasterization and automated testing.

Fields§

§width: usize§height: usize§pixels: Vec<u8>§clip_mask_stack: Vec<Vec<u8>>

Implementations§

Source§

impl FrameBuffer

Source

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

Creates a new frame buffer initialized to transparent black.

Source

pub fn clear(&mut self, color: Color)

Clears the entire buffer with a solid color.

Source

pub fn clear_rect(&mut self, rect: Rect, color: Color)

Clears an axis-aligned rectangular region with a solid color.

Source

pub fn get_pixel(&self, x: usize, y: usize) -> Color

Reads a pixel at (x, y).

Source

pub fn as_raw_bytes(&self) -> &[u8] ⓘ

Safe zero-copy byte slice view of raw RGBA pixel data.

Source

pub fn set_pixel(&mut self, x: usize, y: usize, src: Color)

Writes a pixel at (x, y) with standard alpha blending (Porter-Duff Over).

Source

pub fn blend_glyph_coverage( &mut self, x: usize, y: usize, color: Color, coverage: f32, )

Blends glyph coverage into the framebuffer at (x, y) with non-linear sRGB gamma compensation (gamma = 2.2).

Prevents optical thinning and dark halos when rendering light text on dark backgrounds by performing alpha compositing in physically linear luminance space.

Source

pub fn draw_rect(&mut self, bounds: Rect, color: Color, clip: Option<Rect>)

Renders an axis-aligned solid rectangle.

Source

pub fn draw_rounded_rect( &mut self, bounds: Rect, color: Color, radius: f32, border_width: f32, border_color: Option<Color>, clip: Option<Rect>, )

Renders an anti-aliased rounded rectangle via Signed Distance Fields.

Source

pub fn draw_shadow( &mut self, bounds: Rect, shadow: &BoxShadow, clip: Option<Rect>, )

Renders a CSS box-shadow using smoothed SDF drop shadow approximation.

Source

pub fn draw_text( &mut self, origin: (f32, f32), text: &str, font_size: f32, color: Color, clip: Option<Rect>, )

Renders text using the embedded 8x16 bitmap font.

Source

pub fn apply_filter(&mut self, bounds: Rect, filter: &BackdropFilter)

Applies CSS filter operations to the specified rectangle in the FrameBuffer.

Source

pub fn draw_circle( &mut self, cx: f32, cy: f32, radius: f32, color: Color, clip: Option<Rect>, )

Renders an anti-aliased circle.

Source

pub fn draw_linear_gradient( &mut self, bounds: Rect, angle_deg: f32, stops: &[ColorStop], radius: f32, clip: Option<Rect>, )

Renders a multi-stop linear gradient with analytical corner clipping.

Source

pub fn draw_radial_gradient( &mut self, bounds: Rect, center: (f32, f32), stops: &[ColorStop], radius: f32, clip: Option<Rect>, )

Renders a multi-stop radial gradient with analytical corner clipping.

Source

pub fn draw_image( &mut self, bounds: Rect, image: &ImageResource, clip: Option<Rect>, )

Renders an image with bilinear scaling and alpha blending.

Source

pub fn draw_svg_path( &mut self, bounds: Rect, path_data: &str, stroke_color: Option<Color>, fill_color: Option<Color>, stroke_width: f32, stroke_linecap: StrokeLineCap, stroke_linejoin: StrokeLineJoin, stroke_dasharray: &[f32], fill_rule: FillRule, view_box: (f32, f32), clip: Option<Rect>, )

Renders an SVG vector path with fill and stroke.

Source

pub fn draw_gpu_path( &mut self, bounds: Rect, path: &Path, stroke: Option<StrokeOptions>, fill_color: Option<Color>, stroke_color: Option<Color>, transform: Option<Matrix4x4>, clip: Option<Rect>, )

Renders a GPU vector path with fill and stroke.

Source

pub fn push_clip_path(&mut self, bounds: Rect, clip_path: &ClipPath)

Pushes an arbitrary geometric clip mask.

Source

pub fn pop_clip_path(&mut self)

Pops the active geometric clip mask.

Source

pub fn render_display_list(&mut self, list: &DisplayList)

Convenience alias for execute_display_list.

Source

pub fn execute_display_list(&mut self, list: &DisplayList)

Executes an entire DisplayList onto this FrameBuffer.

Source

pub fn rasterize_damaged(&mut self, list: &DisplayList, damage: &DamageTracker)

Executes a display list scissored strictly to the clustered damage regions tracked by the DamageTracker.

Source

pub fn execute_display_list_damaged(&mut self, list: &DisplayList, damage: Rect)

Executes drawing commands strictly scissored to the specified damage rectangle. Commands that do not intersect damage are skipped in O(1).

Source

pub fn to_png_bytes(&self) -> Result<Vec<u8>, String>

Encodes the current RGBA framebuffer into a standard, spec-compliant PNG byte buffer.

Source

pub fn export_png<P: AsRef<Path>>(&self, path: P) -> Result<()>

Exports the current framebuffer to a PNG image file at the specified path.

Source

pub fn compute_phash(&self) -> u64

Computes a 64-bit difference hash (dHash) for visual regression testing and perceptual diffing.

Source

pub fn phash_distance(hash_a: u64, hash_b: u64) -> u32

Computes the Hamming distance (number of differing bits) between two perceptual hashes.

Trait Implementations§

Source§

impl Clone for FrameBuffer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FrameBuffer

Source§

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

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

impl PartialEq for FrameBuffer

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FrameBuffer

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoInitialState<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> Upcast<T> for T

Source§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,