Skip to main content

Module canvas

Module canvas 

Source
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::intersect and 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 ๐Ÿ”’