pub struct FrameBuffer {
pub data: Vec<u8>,
pub width: u32,
pub height: u32,
pub dirty_region: DirtyRegion,
}Expand description
A pixel RGBA framebuffer with configurable dimensions.
The internal buffer is a flat array of RGBA bytes in row-major order.
Pixel (x, y) starts at byte offset (y * width + x) * 4.
Fields§
§data: Vec<u8>Raw RGBA pixel data, width * height * 4 bytes.
width: u32Screen width in pixels.
height: u32Screen height in pixels.
dirty_region: DirtyRegionAccumulated dirty region for incremental rendering. Callers mark areas that need redrawing; render functions may skip pixels outside this region.
Implementations§
Source§impl FrameBuffer
impl FrameBuffer
Sourcepub fn new(config: RenderConfig, clear_color: Rgba) -> FrameBuffer
pub fn new(config: RenderConfig, clear_color: Rgba) -> FrameBuffer
Create a new framebuffer with the given render config, cleared to the given color.
Sourcepub fn mark_all_dirty(&mut self)
pub fn mark_all_dirty(&mut self)
Mark the entire framebuffer as dirty (force full redraw).
Sourcepub fn mark_dirty_rect(&mut self, x: i32, y: i32, w: u32, h: u32)
pub fn mark_dirty_rect(&mut self, x: i32, y: i32, w: u32, h: u32)
Mark a rectangular region as dirty.
Sourcepub fn mark_dirty_tile(&mut self, tx: i32, ty: i32)
pub fn mark_dirty_tile(&mut self, tx: i32, ty: i32)
Mark a tile as dirty given its tile coordinates (tx, ty).
Sourcepub fn clear_dirty(&mut self)
pub fn clear_dirty(&mut self)
Clear all dirty regions (nothing to redraw).
Sourcepub fn is_dirty_pixel(&self, x: u32, y: u32) -> bool
pub fn is_dirty_pixel(&self, x: u32, y: u32) -> bool
Check whether a pixel is in a dirty region (needs redrawing). If no dirty region is present, all pixels are considered dirty.
Sourcepub fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
pub fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
Set a single pixel. Returns false if out of bounds.
Sourcepub fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
pub fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
Get the color of a single pixel. Returns None if out of bounds.
Sourcepub fn fill_rect(
&mut self,
x: u32,
y: u32,
rect_width: u32,
rect_height: u32,
color: Rgba,
)
pub fn fill_rect( &mut self, x: u32, y: u32, rect_width: u32, rect_height: u32, color: Rgba, )
Fill a rectangular region with a color. Coordinates are clamped to screen bounds.
Sourcepub fn row_slice(&self, y: u32) -> Option<&[u8]>
pub fn row_slice(&self, y: u32) -> Option<&[u8]>
Get a slice of one pixel row’s RGBA data. Returns None if y is out of bounds.
Sourcepub fn row_slice_mut(&mut self, y: u32) -> Option<&mut [u8]>
pub fn row_slice_mut(&mut self, y: u32) -> Option<&mut [u8]>
Get a mutable slice of one pixel row’s RGBA data. Returns None if y is out of bounds.
Trait Implementations§
Source§impl Clone for FrameBuffer
impl Clone for FrameBuffer
Source§fn clone(&self) -> FrameBuffer
fn clone(&self) -> FrameBuffer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FrameBuffer
impl Debug for FrameBuffer
Source§impl FbSurface for FrameBuffer
impl FbSurface for FrameBuffer
Source§fn new_screen(width: u32, height: u32) -> Self
fn new_screen(width: u32, height: u32) -> Self
width × height surface, cleared to black.Source§fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
Source§fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
Source§fn fill_rect(
&mut self,
x: u32,
y: u32,
rect_width: u32,
rect_height: u32,
color: Rgba,
)
fn fill_rect( &mut self, x: u32, y: u32, rect_width: u32, rect_height: u32, color: Rgba, )
Source§fn present_into(&self, out: &mut [u8])
fn present_into(&self, out: &mut [u8])
out, which must hold
at least width * height * 4 bytes.Source§impl TransitionFb for FrameBuffer
impl TransitionFb for FrameBuffer
Source§fn tile_black(&mut self, tx: usize, ty: usize)
fn tile_black(&mut self, tx: usize, ty: usize)
tx, ty) with black.
Out-of-bounds tiles are clamped to the visible area.Auto Trait Implementations§
impl Freeze for FrameBuffer
impl RefUnwindSafe for FrameBuffer
impl Send for FrameBuffer
impl Sync for FrameBuffer
impl Unpin for FrameBuffer
impl UnsafeUnpin for FrameBuffer
impl UnwindSafe for FrameBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.