diff --git a/crates/gpui3/src/platform/mac/metal_atlas.rs b/crates/gpui3/src/platform/mac/metal_atlas.rs index 4c9938e0ece8af9d1e4d6ba34eade5f55f3dcb75..777d97b37f0c85d588b09ee635603e6864faa2a2 100644 --- a/crates/gpui3/src/platform/mac/metal_atlas.rs +++ b/crates/gpui3/src/platform/mac/metal_atlas.rs @@ -27,7 +27,6 @@ impl MetalAtlas { self.0.lock().texture(id).metal_texture.clone() } - #[allow(dead_code)] pub(crate) fn allocate( &self, size: Size, @@ -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) -> Option { let allocation = self.allocator.allocate(size.into())?; let tile = AtlasTile { diff --git a/crates/gpui3/src/platform/mac/metal_renderer.rs b/crates/gpui3/src/platform/mac/metal_renderer.rs index 18d8410738fcd434cbc85014cece40305c2f57b4..c1626849f4f483ac46d0de62ca78c8dfafec6e81 100644 --- a/crates/gpui3/src/platform/mac/metal_renderer.rs +++ b/crates/gpui3/src/platform/mac/metal_renderer.rs @@ -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(