pub struct Canvas<'a, O: PixelOps = ScalarOps> {
base: *mut u8,
pitch: usize,
dims: Dims,
format: Format,
wc: bool,
track_dirty: bool,
dirty: RectSet<DEFAULT_SET_CAPACITY>,
ops: O,
_borrow: PhantomData<&'a mut [u8]>,
}Expand description
A contiguous pixel surface with a validated geometry and format.
The default ops backend is ScalarOps, which keeps the type usable
from a host test. The kernel instantiates Canvas<'_, KernelOps> so the
SSE2 paths are inlined with no dispatch.
Fields§
§base: *mut u8§pitch: usize§dims: Dims§format: Format§wc: bool§track_dirty: bool§dirty: RectSet<DEFAULT_SET_CAPACITY>§ops: O§_borrow: PhantomData<&'a mut [u8]>Implementations§
Source§impl<'a, O: PixelOps> Canvas<'a, O>
impl<'a, O: PixelOps> Canvas<'a, O>
Sourcepub fn with_ops(
buf: &'a mut [u8],
dims: Dims,
pitch: usize,
format: Format,
ops: O,
) -> Result<Self, Error>
pub fn with_ops( buf: &'a mut [u8], dims: Dims, pitch: usize, format: Format, ops: O, ) -> Result<Self, Error>
Build a canvas over a borrowed buffer with an explicit ops backend.
Sourcepub unsafe fn direct(
base: NonNull<u8>,
dims: Dims,
pitch: usize,
format: Format,
write_combining: bool,
ops: O,
) -> Result<Self, Error>
pub unsafe fn direct( base: NonNull<u8>, dims: Dims, pitch: usize, format: Format, write_combining: bool, ops: O, ) -> Result<Self, Error>
Build a canvas over physical framebuffer memory.
base is the HHDM-mapped virtual address, already validated by the
caller (page-aligned and mapped for pitch * height bytes).
§Safety
base must stay mapped and exclusively owned by this canvas for the
whole lifetime of the value, and pitch * height must not wrap.
unsafe fn from_raw( base: *mut u8, dims: Dims, pitch: usize, format: Format, wc: bool, ops: O, ) -> Self
pub fn dims(&self) -> Dims
pub fn format(&self) -> Format
Sourcepub fn bytes_per_pixel(&self) -> usize
pub fn bytes_per_pixel(&self) -> usize
Bytes from the start of one row to the start of the same column in the next row.
pub fn is_write_combining(&self) -> bool
Sourcepub fn set_write_combining(&mut self, wc: bool)
pub fn set_write_combining(&mut self, wc: bool)
Mark the surface as write-combining (MMIO framebuffer). Drawing then uses the non-temporal stores and fences once per call.
pub fn ops(&self) -> &O
pub fn ops_mut(&mut self) -> &mut O
Sourcepub fn clip(&self, rect: Rect) -> Option<Rect>
pub fn clip(&self, rect: Rect) -> Option<Rect>
Clip a rectangle to this surface. None means nothing to draw.
This is the only clipping rule in the crate.
Sourcepub fn set_tracking(&mut self, on: bool)
pub fn set_tracking(&mut self, on: bool)
Enable or disable dirty-rectangle tracking. Enabled by default: the cost is one bounded insertion per drawing call.
pub fn is_tracking(&self) -> bool
pub fn dirty(&self) -> &RectSet<DEFAULT_SET_CAPACITY>
Sourcepub fn take_dirty(&mut self) -> RectSet<DEFAULT_SET_CAPACITY>
pub fn take_dirty(&mut self) -> RectSet<DEFAULT_SET_CAPACITY>
Take the accumulated damage, leaving the set empty.
pub fn clear_dirty(&mut self)
fn mark(&mut self, rect: Rect)
Sourcepub fn fence(&self)
pub fn fence(&self)
Fence the stores of a write-combining surface.
Called once per public drawing call; callers that emit their own stores must call it before the pixels are read.
pub(crate) fn row_ptr(&self, y: u32) -> *mut u8
Sourcefn read_raw(&self, x: u32, y: u32) -> u32
fn read_raw(&self, x: u32, y: u32) -> u32
Read a pixel. Coordinates must be inside the surface.
Volatile on a write-combining (MMIO) surface: the value may have been changed by the device since the last cached load.
Sourcefn write_raw(&mut self, x: u32, y: u32, value: u32)
fn write_raw(&mut self, x: u32, y: u32, value: u32)
Write a pixel. Coordinates must be inside the surface. Volatile on a write-combining (MMIO) surface.
Sourcepub fn read_pixel(&self, x: u32, y: u32) -> Option<Packed>
pub fn read_pixel(&self, x: u32, y: u32) -> Option<Packed>
Read one pixel. Volatile, because the surface may be MMIO.
Sourcepub fn write_pixel(&mut self, x: u32, y: u32, pixel: Packed) -> bool
pub fn write_pixel(&mut self, x: u32, y: u32, pixel: Packed) -> bool
Write one pixel. Volatile, because the surface may be MMIO.
Sourcepub fn fill_rect(&mut self, rect: Rect, color: Packed) -> Option<Rect>
pub fn fill_rect(&mut self, rect: Rect, color: Packed) -> Option<Rect>
Fill rect (clipped) with a packed colour. Returns the rectangle
actually written, or None when entirely outside.
Sourcepub fn fill(&mut self, color: Packed) -> Rect
pub fn fill(&mut self, color: Packed) -> Rect
Fill the whole surface. Convenience over Self::fill_rect.
Sourcepub fn blit<S: Source + ?Sized>(
&mut self,
dst: Rect,
src: &S,
src_rect: Rect,
) -> Result<Option<Rect>, Error>
pub fn blit<S: Source + ?Sized>( &mut self, dst: Rect, src: &S, src_rect: Rect, ) -> Result<Option<Rect>, Error>
Copy src_rect from src into dst on this surface.
Both formats must be identical: a bulk copy must not silently
reinterpret channels. Clipping is applied to the destination and to
the source, and src_rect’s origin is shifted accordingly.
Returns the destination rectangle written, or None when nothing was
visible.
Sourcepub fn blend_rect<S: Source + ?Sized>(
&mut self,
dst: Rect,
src: &S,
src_rect: Rect,
alpha: u8,
) -> Result<Option<Rect>, Error>
pub fn blend_rect<S: Source + ?Sized>( &mut self, dst: Rect, src: &S, src_rect: Rect, alpha: u8, ) -> Result<Option<Rect>, Error>
Blend an optional constant alpha.
With alpha == 255 this is a plain copy; with alpha == 0 the
destination is unchanged, so the call returns None without touching
the surface or recording damage. The blend is per byte of the native
word, matching the kernel’s FramebufferOps::blend.
Sourcepub fn convert_from<S: Source + ?Sized>(
&mut self,
dst: Rect,
src: &S,
src_rect: Rect,
) -> Result<Option<Rect>, Error>
pub fn convert_from<S: Source + ?Sized>( &mut self, dst: Rect, src: &S, src_rect: Rect, ) -> Result<Option<Rect>, Error>
Copy from a surface that may have a different format.
This is the crate’s only per-pixel conversion path: each source
pixel is decoded with Format::unpack and re-encoded with
Format::pack. Prefer Self::blit when the formats match.
Sourcepub fn copy_to<O2: PixelOps>(
&self,
dst: &mut Canvas<'_, O2>,
origin: (u32, u32),
) -> Result<Option<Rect>, Error>
pub fn copy_to<O2: PixelOps>( &self, dst: &mut Canvas<'_, O2>, origin: (u32, u32), ) -> Result<Option<Rect>, Error>
Copy the whole surface into dst at origin, with the same format
rules as Self::blit.
Sourcefn is_contiguous<S: Source + ?Sized>(&self, d: Rect, sx: u32, src: &S) -> bool
fn is_contiguous<S: Source + ?Sized>(&self, d: Rect, sx: u32, src: &S) -> bool
True when d spans a full row of both surfaces and both pitches have
no padding, so the whole block is contiguous in memory.
Sourcefn map_rect(
&self,
dst: Rect,
src_dims: Dims,
src_rect: Rect,
) -> Option<(Rect, u32, u32)>
fn map_rect( &self, dst: Rect, src_dims: Dims, src_rect: Rect, ) -> Option<(Rect, u32, u32)>
Map a requested copy onto the destination and source surfaces.
Returns the clipped destination rectangle plus the source origin to start from. This is what keeps a partially off-screen blit correct: clipping the destination shifts the source window by the same amount, it never stretches or re-anchors the image.