| // Copyright 2026 the Vello Authors | |
| // SPDX-License-Identifier: Apache-2.0 OR MIT | |
| //! Persistent renderer resources shared across frames. | |
| #[cfg(feature = "text")] | |
| use crate::text::GlyphAtlasResources; | |
| #[cfg(feature = "text")] | |
| use glifo::{GlyphPrepCache, HintCacheConfig}; | |
| use vello_common::image_cache::ImageCache; | |
| use vello_common::multi_atlas::AtlasConfig; | |
| /// Persistent resources required by Vello GPU for rendering. | |
| /// | |
| /// A set of resources must only be used with the renderer instance associated with it. | |
| #[derive(Debug)] | |
| pub struct Resources { | |
| pub(crate) image_cache: ImageCache, | |
| #[cfg(feature = "text")] | |
| pub(crate) glyph_prep_cache: GlyphPrepCache, | |
| #[cfg(feature = "text")] | |
| pub(crate) glyph_resources: Option<GlyphAtlasResources>, | |
| } | |
| impl Resources { | |
| pub(crate) fn new( | |
| glyph_atlas_config: AtlasConfig, | |
| #[cfg(feature = "text")] hint_cache_config: HintCacheConfig, | |
| ) -> Self { | |
| Self { | |
| image_cache: ImageCache::new_with_config(glyph_atlas_config), | |
| #[cfg(feature = "text")] | |
| glyph_prep_cache: GlyphPrepCache::with_hint_cache_config(hint_cache_config), | |
| // Will be initialized lazily. | |
| #[cfg(feature = "text")] | |
| glyph_resources: None, | |
| } | |
| } | |
| /// Drop all cached glyphs and their atlas allocations, keeping the cache configuration. | |
| pub(crate) fn clear(&mut self) { | |
| *self = Self::new( | |
| *self.image_cache.atlas_manager().config(), | |
| #[cfg(feature = "text")] | |
| *self.glyph_prep_cache.hint_cache_config(), | |
| ); | |
| } | |
| } |