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
impl FrameBuffer
Sourcepub fn new(width: usize, height: usize) -> Self
pub fn new(width: usize, height: usize) -> Self
Creates a new frame buffer initialized to transparent black.
Sourcepub fn clear_rect(&mut self, rect: Rect, color: Color)
pub fn clear_rect(&mut self, rect: Rect, color: Color)
Clears an axis-aligned rectangular region with a solid color.
Sourcepub fn as_raw_bytes(&self) -> &[u8] ⓘ
pub fn as_raw_bytes(&self) -> &[u8] ⓘ
Safe zero-copy byte slice view of raw RGBA pixel data.
Sourcepub fn set_pixel(&mut self, x: usize, y: usize, src: Color)
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).
Sourcepub fn blend_glyph_coverage(
&mut self,
x: usize,
y: usize,
color: Color,
coverage: f32,
)
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.
Sourcepub fn draw_rect(&mut self, bounds: Rect, color: Color, clip: Option<Rect>)
pub fn draw_rect(&mut self, bounds: Rect, color: Color, clip: Option<Rect>)
Renders an axis-aligned solid rectangle.
Sourcepub fn draw_rounded_rect(
&mut self,
bounds: Rect,
color: Color,
radius: f32,
border_width: f32,
border_color: Option<Color>,
clip: Option<Rect>,
)
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.
Sourcepub fn draw_shadow(
&mut self,
bounds: Rect,
shadow: &BoxShadow,
clip: Option<Rect>,
)
pub fn draw_shadow( &mut self, bounds: Rect, shadow: &BoxShadow, clip: Option<Rect>, )
Renders a CSS box-shadow using smoothed SDF drop shadow approximation.
Sourcepub fn draw_text(
&mut self,
origin: (f32, f32),
text: &str,
font_size: f32,
color: Color,
clip: Option<Rect>,
)
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.
Sourcepub fn apply_filter(&mut self, bounds: Rect, filter: &BackdropFilter)
pub fn apply_filter(&mut self, bounds: Rect, filter: &BackdropFilter)
Applies CSS filter operations to the specified rectangle in the FrameBuffer.
Sourcepub fn draw_circle(
&mut self,
cx: f32,
cy: f32,
radius: f32,
color: Color,
clip: Option<Rect>,
)
pub fn draw_circle( &mut self, cx: f32, cy: f32, radius: f32, color: Color, clip: Option<Rect>, )
Renders an anti-aliased circle.
Sourcepub fn draw_linear_gradient(
&mut self,
bounds: Rect,
angle_deg: f32,
stops: &[ColorStop],
radius: f32,
clip: Option<Rect>,
)
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.
Sourcepub fn draw_radial_gradient(
&mut self,
bounds: Rect,
center: (f32, f32),
stops: &[ColorStop],
radius: f32,
clip: Option<Rect>,
)
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.
Sourcepub fn draw_image(
&mut self,
bounds: Rect,
image: &ImageResource,
clip: Option<Rect>,
)
pub fn draw_image( &mut self, bounds: Rect, image: &ImageResource, clip: Option<Rect>, )
Renders an image with bilinear scaling and alpha blending.
Sourcepub 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>,
)
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.
Sourcepub 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>,
)
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.
Sourcepub fn push_clip_path(&mut self, bounds: Rect, clip_path: &ClipPath)
pub fn push_clip_path(&mut self, bounds: Rect, clip_path: &ClipPath)
Pushes an arbitrary geometric clip mask.
Sourcepub fn pop_clip_path(&mut self)
pub fn pop_clip_path(&mut self)
Pops the active geometric clip mask.
Sourcepub fn render_display_list(&mut self, list: &DisplayList)
pub fn render_display_list(&mut self, list: &DisplayList)
Convenience alias for execute_display_list.
Sourcepub fn execute_display_list(&mut self, list: &DisplayList)
pub fn execute_display_list(&mut self, list: &DisplayList)
Executes an entire DisplayList onto this FrameBuffer.
Sourcepub fn rasterize_damaged(&mut self, list: &DisplayList, damage: &DamageTracker)
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.
Sourcepub fn execute_display_list_damaged(&mut self, list: &DisplayList, damage: Rect)
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).
Sourcepub fn to_png_bytes(&self) -> Result<Vec<u8>, String>
pub fn to_png_bytes(&self) -> Result<Vec<u8>, String>
Encodes the current RGBA framebuffer into a standard, spec-compliant PNG byte buffer.
Sourcepub fn export_png<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn export_png<P: AsRef<Path>>(&self, path: P) -> Result<()>
Exports the current framebuffer to a PNG image file at the specified path.
Sourcepub fn compute_phash(&self) -> u64
pub fn compute_phash(&self) -> u64
Computes a 64-bit difference hash (dHash) for visual regression testing and perceptual diffing.
Sourcepub fn phash_distance(hash_a: u64, hash_b: u64) -> u32
pub fn phash_distance(hash_a: u64, hash_b: u64) -> u32
Computes the Hamming distance (number of differing bits) between two perceptual hashes.