pub struct Bitmap { /* private fields */ }Expand description
A shared premultiplied-RGBA buffer, texture, and optional offscreen surface.
Clones share one resource. The final clone releases the texture and offscreen surface on browser and native hosts.
use fui::prelude::*;
let bitmap = Bitmap::new(32, 32);
{
let mut pixels = bitmap.pixels();
pixels[0..4].copy_from_slice(&[255, 96, 32, 255]);
}
bitmap.clear_dirty_rects().dirty_rect(0, 0, 1, 1).commit();Implementations§
Source§impl Bitmap
impl Bitmap
Sourcepub fn new(width: u32, height: u32) -> Self
pub fn new(width: u32, height: u32) -> Self
Allocates a non-empty bitmap and its host texture/offscreen resources.
Sourcepub fn texture_id(&self) -> u32
pub fn texture_id(&self) -> u32
Returns the texture ID accepted by DrawContext::draw_image.
Sourcepub fn pixels(&self) -> RefMut<'_, Vec<u8>>
pub fn pixels(&self) -> RefMut<'_, Vec<u8>>
Mutably borrows premultiplied RGBA bytes.
Drop the returned borrow before invoking any other bitmap method.
Sourcepub fn pixel_ptr(&self) -> usize
pub fn pixel_ptr(&self) -> usize
Returns the current pixel-buffer address for low-level host interop.
Sourcepub fn canvas(&self) -> DrawContext
pub fn canvas(&self) -> DrawContext
Returns the persistent offscreen drawing context.
Once used, each commit flushes and reads this surface
over the pixel buffer before texture upload. Do not subsequently mix
direct pixel ownership into the same bitmap.
Sourcepub fn render<T: Node>(&self, node: &T, x: f32, y: f32, scale: f32) -> bool
pub fn render<T: Node>(&self, node: &T, x: f32, y: f32, scale: f32) -> bool
Rasterizes a built, laid-out retained node into the pixel buffer.
Call this after layout, then call commit. scale
maps logical node coordinates to physical bitmap pixels.
Sourcepub fn render_text_layout(
&self,
layout: &TextLayout,
x: f32,
y: f32,
scale: f32,
) -> bool
pub fn render_text_layout( &self, layout: &TextLayout, x: f32, y: f32, scale: f32, ) -> bool
Rasterizes a ready retained text layout into the pixel buffer.
Sourcepub fn prepare_text<T: Node>(node: &T)
pub fn prepare_text<T: Node>(node: &T)
Builds and prepares a retained text node for bitmap rasterization.
Sourcepub fn on_text_ready<T: Node + Clone + 'static>(
&self,
node: &T,
callback: impl FnOnce(BitmapTextReadyEventArgs) + 'static,
) -> &Self
pub fn on_text_ready<T: Node + Clone + 'static>( &self, node: &T, callback: impl FnOnce(BitmapTextReadyEventArgs) + 'static, ) -> &Self
Invokes callback once required fonts and initial app load are ready.
Sourcepub fn dirty_rect(&self, x: u32, y: u32, w: u32, h: u32) -> &Self
pub fn dirty_rect(&self, x: u32, y: u32, w: u32, h: u32) -> &Self
Adds a clipped dirty upload region for the next commit.
Empty/outside regions are ignored and at most 16 regions are retained.
Sourcepub fn clear_dirty_rects(&self) -> &Self
pub fn clear_dirty_rects(&self) -> &Self
Clears pending dirty regions so the next commit is a full upload unless new regions are added.
Sourcepub fn has_dirty_rects(&self) -> bool
pub fn has_dirty_rects(&self) -> bool
Reports whether the next commit contains partial upload regions.