Expand description
The surface type: a validated, contiguous rectangle of pixels.
One type replaces CanvasBuffer, the drawing half of HeapScreen,
SimpleDisplayAdapterโs raw pointer and the framebuffer wrapper. The
invariants that used to be comments are enforced here:
- the pitch covers the width and the backing store covers the pitch;
- the format is one the pixel backends can actually drive;
- a bulk blit only happens between identical formats; conversion is a separate, explicit call;
- clipping is
Rect::intersectand nothing else; - dirty rectangles come from
RectSet, not three overlapping models.
ยงStorage
A Canvas borrows its pixels or points at MMIO; it never allocates.
Canvas::new / Canvas::with_ops take a &mut [u8], Canvas::direct
takes a validated NonNull<u8> for a physical framebuffer. Paged
(HeapScreen-style) storage is deliberately out of scope: it is the
thing R12 removes from the kernel.
ยงExample
use fbsurface::{Canvas, Dims, Format, Rect};
// Back the surface with `u32` so the 32 bpp alignment rule holds.
let mut words = [0u32; 16];
let bytes = unsafe {
core::slice::from_raw_parts_mut(words.as_mut_ptr() as *mut u8, words.len() * 4)
};
let mut canvas = Canvas::new(bytes, Dims::new(4, 4), 16, Format::XRGB8888).unwrap();
canvas.fill_rect(Rect::new(1, 1, 2, 2), Format::XRGB8888.white());
assert_eq!(canvas.read_pixel(1, 1), Some(Format::XRGB8888.white()));Re-exportsยง
use core::marker::PhantomData;๐use core::ptr::NonNull;๐use crate::format::Format;๐use crate::format::Packed;๐use crate::geom::Dims;๐use crate::geom::Rect;๐use crate::geom::RectSet;๐use crate::geom::DEFAULT_SET_CAPACITY;๐use crate::ops::blend_word;๐use crate::ops::PixelOps;๐use crate::ops::ScalarOps;๐use crate::view::Source;๐
Structsยง
- Canvas
- A contiguous pixel surface with a validated geometry and format.
Enumsยง
- Error
- Why a canvas could not be created or a copy refused to run.
Functionsยง
- required_
len ๐ - validate ๐
- validate_
alignment ๐