Struct webrender::texture_pack::BucketedShelfAllocator
source · pub struct BucketedShelfAllocator {
shelves: Vec<Shelf>,
buckets: Vec<Bucket>,
available_height: u16,
width: u16,
height: u16,
first_unallocated_bucket: BucketIndex,
flip_xy: bool,
alignment: Size2D<i32, UnknownUnit>,
current_column: u16,
column_width: u16,
num_columns: u16,
allocated_space: i32,
}
Expand description
A faster but less precise Shelf-packing dynamic texture atlas allocator, inspired by https://github.com/mapbox/shelf-pack/
Items are accumulated into buckets which are laid out in rows (shelves) of variable height. When allocating we first look for a suitable bucket. If none is found, a new shelf of the desired height is pushed.
Lifetime isn’t tracked at item granularity. Instead, items are grouped into buckets and deallocation happens per bucket when all items of the buckets are removed. When the top-most shelf is empty, it is removed, potentially cascading into garbage-collecting the next shelf, etc.
This allocator works well when there are a lot of small items with similar sizes (typically, glyph atlases).
Fields§
§shelves: Vec<Shelf>
§buckets: Vec<Bucket>
§available_height: u16
§width: u16
§height: u16
§first_unallocated_bucket: BucketIndex
§flip_xy: bool
§alignment: Size2D<i32, UnknownUnit>
§current_column: u16
§column_width: u16
§num_columns: u16
§allocated_space: i32
Implementations§
source§impl BucketedAtlasAllocator
impl BucketedAtlasAllocator
sourcepub fn with_options(
size: Size2D<i32, UnknownUnit>,
options: &AllocatorOptions,
) -> BucketedAtlasAllocator
pub fn with_options( size: Size2D<i32, UnknownUnit>, options: &AllocatorOptions, ) -> BucketedAtlasAllocator
Create an atlas allocator with provided options.
sourcepub fn new(size: Size2D<i32, UnknownUnit>) -> BucketedAtlasAllocator
pub fn new(size: Size2D<i32, UnknownUnit>) -> BucketedAtlasAllocator
Create an atlas allocator with default options.
pub fn clear(&mut self)
pub fn size(&self) -> Size2D<i32, UnknownUnit>
pub fn grow(&mut self, new_size: Size2D<i32, UnknownUnit>)
pub fn is_empty(&self) -> bool
sourcepub fn allocate(
&mut self,
requested_size: Size2D<i32, UnknownUnit>,
) -> Option<Allocation>
pub fn allocate( &mut self, requested_size: Size2D<i32, UnknownUnit>, ) -> Option<Allocation>
Allocate a rectangle in the atlas.
sourcepub fn deallocate(&mut self, id: AllocId)
pub fn deallocate(&mut self, id: AllocId)
Deallocate a rectangle in the atlas.
Space is only reclaimed when all items of the same bucket are deallocated.
sourcepub fn allocated_space(&self) -> i32
pub fn allocated_space(&self) -> i32
Amount of occupied space in the atlas.
sourcepub fn free_space(&self) -> i32
pub fn free_space(&self) -> i32
How much space is available for future allocations.
sourcepub fn dump_svg(&self, output: &mut dyn Write) -> Result<(), Error>
pub fn dump_svg(&self, output: &mut dyn Write) -> Result<(), Error>
Dump a visual representation of the atlas in SVG format.
sourcepub fn dump_into_svg(
&self,
rect: Option<&Box2D<i32, UnknownUnit>>,
output: &mut dyn Write,
) -> Result<(), Error>
pub fn dump_into_svg( &self, rect: Option<&Box2D<i32, UnknownUnit>>, output: &mut dyn Write, ) -> Result<(), Error>
Dump a visual representation of the atlas in SVG, omitting the beginning and end of the SVG document, so that it can be included in a larger document.
If a rectangle is provided, translate and scale the output to fit it.
Trait Implementations§
source§impl AtlasAllocator for BucketedShelfAllocator
impl AtlasAllocator for BucketedShelfAllocator
§type Parameters = AllocatorOptions
type Parameters = AllocatorOptions
source§fn new(size: i32, options: &Self::Parameters) -> Self
fn new(size: i32, options: &Self::Parameters) -> Self
source§fn allocate(&mut self, size: DeviceIntSize) -> Option<(AllocId, DeviceIntRect)>
fn allocate(&mut self, size: DeviceIntSize) -> Option<(AllocId, DeviceIntRect)>
source§fn deallocate(&mut self, id: AllocId)
fn deallocate(&mut self, id: AllocId)
source§fn allocated_space(&self) -> i32
fn allocated_space(&self) -> i32
source§impl Clone for BucketedAtlasAllocator
impl Clone for BucketedAtlasAllocator
source§fn clone(&self) -> BucketedAtlasAllocator
fn clone(&self) -> BucketedAtlasAllocator
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'de> Deserialize<'de> for BucketedAtlasAllocator
impl<'de> Deserialize<'de> for BucketedAtlasAllocator
source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<BucketedAtlasAllocator, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<BucketedAtlasAllocator, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl Serialize for BucketedAtlasAllocator
impl Serialize for BucketedAtlasAllocator
source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for BucketedAtlasAllocator
impl RefUnwindSafe for BucketedAtlasAllocator
impl Send for BucketedAtlasAllocator
impl Sync for BucketedAtlasAllocator
impl Unpin for BucketedAtlasAllocator
impl UnwindSafe for BucketedAtlasAllocator
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more