Skip to main content

CpuBackend

Struct CpuBackend 

Source
pub struct CpuBackend { /* private fields */ }
Expand description

CPU-based rendering backend.

Wraps a tiny-skia Pixmap and implements RenderBackend using software rasterization. Zero GPU dependencies.

Implementations§

Source§

impl CpuBackend

Source

pub fn new(logical_w: u32, logical_h: u32, scale: f32) -> Option<CpuBackend>

Create a new CPU backend.

logical_w / logical_h are in logical points; scale is the display scale factor (2.0 on Retina, 1.0 otherwise). The internal pixmap is sized at logical × scale physical pixels.

Source

pub fn resize(&mut self, logical_w: u32, logical_h: u32, scale: f32) -> bool

Reallocate the internal pixmap for a new logical size and/or scale factor. Call from a host-reported resize / DPI-change handler; a no-op if the resulting physical dimensions match the current pixmap.

Source

pub fn data(&self) -> &[u8]

Raw pixel data (RGBA premultiplied, row-major, physical pixels).

Source

pub fn width(&self) -> u32

Pixel buffer width (physical pixels).

Source

pub fn height(&self) -> u32

Pixel buffer height (physical pixels).

Source

pub fn scale(&self) -> f32

Display scale factor baked at construction.

Trait Implementations§

Source§

impl RenderBackend for CpuBackend

All RenderBackend methods accept coordinates in logical points. The backend multiplies by self.scale before handing off to tiny-skia, so the pixmap is rasterized at physical-pixel density.

Source§

fn clear(&mut self, color: Color)

Clear the entire surface with a solid color.
Source§

fn fill_rect(&mut self, x: f32, y: f32, w: f32, h: f32, color: Color)

Fill a rectangle.
Source§

fn fill_circle(&mut self, cx: f32, cy: f32, radius: f32, color: Color)

Fill a circle.
Source§

fn stroke_circle( &mut self, cx: f32, cy: f32, radius: f32, color: Color, width: f32, )

Stroke a circle outline.
Source§

fn stroke_arc( &mut self, cx: f32, cy: f32, radius: f32, start_angle: f32, end_angle: f32, color: Color, width: f32, )

Stroke an arc (portion of a circle).
Source§

fn draw_line( &mut self, x1: f32, y1: f32, x2: f32, y2: f32, color: Color, width: f32, )

Draw a line between two points.
Source§

fn draw_text(&mut self, text: &str, x: f32, y: f32, size: f32, color: Color)

Draw text using the embedded TrueType font (fontdue).
Source§

fn text_width(&self, text: &str, size: f32) -> f32

Measure the width of a text string in logical points, at the given logical-point font size.
Source§

fn register_image(&mut self, rgba: &[u8], width: u32, height: u32) -> ImageId

Register an RGBA8 image (premultiplied alpha, row-major, tightly packed). Read more
Source§

fn unregister_image(&mut self, id: ImageId)

Remove a previously-registered image. No-op if the id is invalid or already unregistered.
Source§

fn draw_image(&mut self, id: ImageId, x: f32, y: f32, w: f32, h: f32)

Draw a previously-registered image at (x, y) sized w × h. Read more
Source§

fn present(&mut self)

Flush rendering to the display surface. 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> 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, 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.
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,