pub struct Surface { /* private fields */ }
Expand description
Offscreen pixel buffer surface. (Premultiplied BGRA 32-bit format)
When using the CPU renderer, each View is painted to its own Surface.
NOTE: Custom Surface is currently not support in this Rust wrapper
Implementations§
source§impl Surface
impl Surface
sourcepub fn row_bytes(&self) -> u32
pub fn row_bytes(&self) -> u32
Get the number of bytes between each row of pixels.
usually width * 4
sourcepub fn bytes_size(&self) -> usize
pub fn bytes_size(&self) -> usize
Get the size in bytes of the pixel buffer.
bytes_size is calculated as row_bytes() * height()
.
sourcepub fn lock_pixels(&mut self) -> Option<PixelsGuard<'_>>
pub fn lock_pixels(&mut self) -> Option<PixelsGuard<'_>>
Lock the pixel buffer for reading/writing.
An RAII guard is returned that will unlock the buffer when dropped.
sourcepub fn resize(&self, width: u32, height: u32)
pub fn resize(&self, width: u32, height: u32)
Resize the pixel buffer to a certain width and height (both in pixels).
sourcepub fn set_dirty_bounds(&self, bounds: Rect<i32>)
pub fn set_dirty_bounds(&self, bounds: Rect<i32>)
Set the dirty bounds to a certain value.
This is called after the Renderer paints to an area of the pixel buffer. (The new value will be joined with the existing dirty_bounds())
sourcepub fn dirty_bounds(&self) -> Rect<i32>
pub fn dirty_bounds(&self) -> Rect<i32>
Get the dirty bounds.
This value can be used to determine which portion of the pixel buffer has been updated since
the last call to clear_dirty_bounds
.
The general algorithm to determine if a Surface needs display is:
if !surface.dirty_bounds().is_empty() {
// Surface pixels are dirty and needs display.
// Cast Surface to native Surface and use it here (pseudo code)
display_surface(surface);
// Once you're done, clear the dirty bounds:
surface.clear_dirty_bounds();
}
sourcepub fn clear_dirty_bounds(&self)
pub fn clear_dirty_bounds(&self)
Clear the dirty bounds.
You should call this after you’re done displaying the Surface.