Skip to main content

PixelOps

Trait PixelOps 

Source
pub trait PixelOps {
    type Guard: PixelGuard;

    // Required methods
    fn guard(&self) -> Self::Guard;
    unsafe fn fill(&self, dst: *mut u32, color: u32, count: usize);
    unsafe fn blit(&self, dst: *mut u32, src: *const u32, count: usize);
    unsafe fn blend(
        &self,
        dst: *mut u32,
        src: *const u32,
        alpha: u8,
        count: usize,
    );
    unsafe fn fill_nt(&self, dst: *mut u32, color: u32, count: usize);
    unsafe fn blit_nt(&self, dst: *mut u32, src: *const u32, count: usize);
}
Expand description

Raw 32-bit pixel operations.

§Safety contract

Implementations may assume, for every method, that:

  • dst points to count writable u32 values;
  • src points to count readable u32 values;
  • the two ranges do not overlap.

The methods stay unsafe fn even though the trait is safe: constructing a bad implementation is harmless as long as every call site upholds the contract, and Canvas is the only caller.

Required Associated Types§

Source

type Guard: PixelGuard

RAII state saved around a drawing call (FPU/SSE registers in the kernel, nothing on the host).

Required Methods§

Source

fn guard(&self) -> Self::Guard

Acquire the guard. Kept separate from the operations so the compiler can drop it at the end of the drawing call.

Source

unsafe fn fill(&self, dst: *mut u32, color: u32, count: usize)

Fill count pixels with color.

§Safety

See the trait-level contract.

Source

unsafe fn blit(&self, dst: *mut u32, src: *const u32, count: usize)

Copy count pixels from src to dst.

§Safety

See the trait-level contract.

Source

unsafe fn blend(&self, dst: *mut u32, src: *const u32, alpha: u8, count: usize)

Blend src over dst with a constant alpha (0 = keep dst, 255 = take src), channel by channel including the top byte.

§Safety

See the trait-level contract.

Source

unsafe fn fill_nt(&self, dst: *mut u32, color: u32, count: usize)

Non-temporal variant of Self::fill, for write-combining memory.

§Safety

See the trait-level contract, plus: dst must be write-combining memory, and the caller must issue a fence before the result is read.

Source

unsafe fn blit_nt(&self, dst: *mut u32, src: *const u32, count: usize)

Non-temporal variant of Self::blit.

§Safety

See Self::fill_nt.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§