Struct webrender::texture_pack::ShelfAllocator
source · pub struct ShelfAllocator {
shelves: Vec<Shelf>,
items: Vec<Item>,
alignment: Size2D<i32, UnknownUnit>,
flip_xy: bool,
size: Size2D<i32, UnknownUnit>,
first_shelf: ShelfIndex,
free_items: ItemIndex,
free_shelves: ShelfIndex,
shelf_width: u16,
allocated_space: i32,
}
Expand description
A shelf-packing dynamic texture atlas allocator tracking each allocation individually and with support for coalescing empty shelves.
Fields§
§shelves: Vec<Shelf>
§items: Vec<Item>
§alignment: Size2D<i32, UnknownUnit>
§flip_xy: bool
§size: Size2D<i32, UnknownUnit>
§first_shelf: ShelfIndex
§free_items: ItemIndex
§free_shelves: ShelfIndex
§shelf_width: u16
§allocated_space: i32
Implementations§
source§impl AtlasAllocator
impl AtlasAllocator
sourcepub fn with_options(
size: Size2D<i32, UnknownUnit>,
options: &AllocatorOptions,
) -> AtlasAllocator
pub fn with_options( size: Size2D<i32, UnknownUnit>, options: &AllocatorOptions, ) -> AtlasAllocator
Create an atlas allocator with provided options.
sourcepub fn new(size: Size2D<i32, UnknownUnit>) -> AtlasAllocator
pub fn new(size: Size2D<i32, UnknownUnit>) -> AtlasAllocator
Create an atlas allocator with default options.
pub fn clear(&mut self)
pub fn size(&self) -> Size2D<i32, UnknownUnit>
sourcepub fn allocate(&mut self, size: Size2D<i32, UnknownUnit>) -> Option<Allocation>
pub fn allocate(&mut self, 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.
pub fn is_empty(&self) -> bool
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.
pub fn iter(&self) -> Iter<'_>
sourcepub fn get_index(&self, id: AllocId) -> u32
pub fn get_index(&self, id: AllocId) -> u32
Turn a valid AllocId into an index that can be used as a key for external storage.
The allocator internally stores all items in a single vector. In addition allocations stay at the same index in the vector until they are deallocated. As a result the index of an item can be used as a key for external storage using vectors. Note that:
- The provided ID must correspond to an item that is currently allocated in the atlas.
- After an item is deallocated, its index may be reused by a future allocation, so the returned index should only be considered valid during the lifetime of the its associated item.
- indices are expected to be “reasonable” with respect to the number of allocated items, in other words it is never larger than the maximum number of allocated items in the atlas (making it a good fit for indexing within a sparsely populated vector).
sourcepub fn get(&self, id: AllocId) -> Box2D<i32, UnknownUnit>
pub fn get(&self, id: AllocId) -> Box2D<i32, UnknownUnit>
Returns the allocation info associated to the allocation ID.
The id must correspond to an existing allocation in the atlas.
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 ShelfAllocator
impl AtlasAllocator for ShelfAllocator
§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 AtlasAllocator
impl Clone for AtlasAllocator
source§fn clone(&self) -> AtlasAllocator
fn clone(&self) -> AtlasAllocator
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 AtlasAllocator
impl<'de> Deserialize<'de> for AtlasAllocator
source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<AtlasAllocator, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<AtlasAllocator, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl<'l> IntoIterator for &'l AtlasAllocator
impl<'l> IntoIterator for &'l AtlasAllocator
source§impl Serialize for AtlasAllocator
impl Serialize for AtlasAllocator
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 AtlasAllocator
impl RefUnwindSafe for AtlasAllocator
impl Send for AtlasAllocator
impl Sync for AtlasAllocator
impl Unpin for AtlasAllocator
impl UnwindSafe for AtlasAllocator
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