Skip to main content

CanvasBuffer

Struct CanvasBuffer 

Source
pub struct CanvasBuffer {
    pub addr: *mut u8,
    pub width: usize,
    pub height: usize,
    pub pitch: usize,
    pub bpp: u16,
    pub back_buffer: Option<Vec<u32>>,
    pub draw_to_back: bool,
    pub dirty: DirtyRectSet,
    pub track_dirty: bool,
    pub present_pending: bool,
    pub last_present_tick: u64,
    pub ops: FramebufferOps,
}
Expand description

A raw framebuffer canvas with optional double buffering.

Encapsulates the HW framebuffer pointer, optional back-buffer (always 32bpp), dirty-region tracking, SIMD-accelerated pixel ops, and a present() that flushes dirty regions to the real hardware.

Used by both the VGA text-mode writer (VgaWriter) and the raw hardware video driver (hardware::video::Framebuffer), eliminating the duplicated present() / dirty-tracking logic between them.

Fields§

§addr: *mut u8

Pointer to the start of the HW framebuffer (HHDM-mapped virtual).

§width: usize

Width in pixels.

§height: usize

Height in pixels.

§pitch: usize

Bytes per row (stride / pitch).

§bpp: u16

Bits per pixel (24 or 32).

§back_buffer: Option<Vec<u32>>

Optional back-buffer (always 32bpp / u32 per pixel).

§draw_to_back: bool

If true, draw operations write to back_buffer instead of HW.

§dirty: DirtyRectSet

Set of dirty rectangles pending a present().

§track_dirty: bool

If true, dirty rectangles are tracked.

§present_pending: bool

Whether a present() has been requested.

§last_present_tick: u64

Tick of the last present() (for rate-limiting).

§ops: FramebufferOps

SIMD-accelerated pixel ops (fill, blit, blend, convert).

Implementations§

Source§

impl CanvasBuffer

Source

pub fn enable_back_buffer(&mut self) -> bool

Enable double-buffering by allocating and syncing a back-buffer.

Source

pub fn disable_back_buffer(&mut self, do_present: bool)

Disable double-buffering, optionally presenting first.

Source

pub fn pixel_offset(&self, x: usize, y: usize) -> Option<usize>

Byte offset in HW memory for pixel (x, y).

Source

pub fn read_hw_pixel(&self, x: usize, y: usize) -> u32

Read a packed pixel directly from HW memory.

Source

pub fn write_hw_pixel(&mut self, x: usize, y: usize, color: u32)

Write a packed pixel to HW memory.

Source

pub fn read_pixel(&self, x: usize, y: usize) -> u32

Read pixel (x, y) : from back-buffer if available, else HW.

Source

pub fn write_pixel(&mut self, x: usize, y: usize, color: u32)

Write pixel (x, y) : to back-buffer if available, else HW.

Source

pub fn fill_rect(&mut self, x: usize, y: usize, w: usize, h: usize, color: u32)

Fill a rectangle with a packed colour.

Source

pub fn present(&mut self)

Flush dirty back-buffer regions to the hardware framebuffer.

Uses SIMD-accelerated ops.blit when the back-buffer’s row stride matches the frame-buffer’s stride, falling back to row-by-row copies.

Source

pub fn request_present(&mut self)

Request a present (throttled).

Source

pub fn present_if_due(&mut self, force: bool, now: u64)

Present if a request is pending and the throttle delay has elapsed.

Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.