Checkpoint

This commit is contained in:
Antonio Scandurra
2023-10-10 13:07:53 +02:00
parent a4afb72535
commit 678235023f
2 changed files with 29 additions and 2 deletions
+28 -2
View File
@@ -27,7 +27,6 @@ impl MetalAtlas {
self.0.lock().texture(id).metal_texture.clone()
}
#[allow(dead_code)]
pub(crate) fn allocate(
&self,
size: Size<DevicePixels>,
@@ -35,6 +34,18 @@ impl MetalAtlas {
) -> AtlasTile {
self.0.lock().allocate(size, texture_kind)
}
pub(crate) fn clear_textures(&self, texture_kind: AtlasTextureKind) {
let mut lock = self.0.lock();
let textures = match texture_kind {
AtlasTextureKind::Monochrome => &mut lock.monochrome_textures,
AtlasTextureKind::Polychrome => &mut lock.polychrome_textures,
AtlasTextureKind::Path => &mut lock.path_textures,
};
for texture in textures {
texture.clear();
}
}
}
struct MetalAtlasState {
@@ -59,12 +70,23 @@ impl PlatformAtlas for MetalAtlas {
let tile = lock.allocate(size, key.texture_kind());
let texture = lock.texture(tile.texture_id);
texture.upload(tile.bounds, &bytes);
lock.tiles_by_key.insert(key.clone(), tile.clone());
Ok(tile)
}
}
fn clear(&self) {
self.0.lock().tiles_by_key.clear();
let mut lock = self.0.lock();
lock.tiles_by_key.clear();
for texture in &mut lock.monochrome_textures {
texture.clear();
}
for texture in &mut lock.polychrome_textures {
texture.clear();
}
for texture in &mut lock.path_textures {
texture.clear();
}
}
}
@@ -153,6 +175,10 @@ struct MetalAtlasTexture {
}
impl MetalAtlasTexture {
fn clear(&mut self) {
self.allocator.clear();
}
fn allocate(&mut self, size: Size<DevicePixels>) -> Option<AtlasTile> {
let allocation = self.allocator.allocate(size.into())?;
let tile = AtlasTile {
@@ -281,6 +281,7 @@ impl MetalRenderer {
command_buffer.commit();
command_buffer.wait_until_completed();
drawable.present();
self.sprite_atlas.clear_textures(AtlasTextureKind::Path);
}
fn rasterize_paths(