pub struct AppResources {
pub css_ids_to_image_ids: FastHashMap<CssImageId, ImageId>,
pub css_ids_to_font_ids: FastHashMap<CssFontId, FontId>,
pub image_sources: FastHashMap<ImageId, ImageSource>,
pub font_sources: FastHashMap<FontId, FontSource>,
pub currently_registered_images: FastHashMap<PipelineId, FastHashMap<ImageId, ImageInfo>>,
pub currently_registered_fonts: FastHashMap<PipelineId, FastHashMap<ImmediateFontId, LoadedFont>>,
pub last_frame_image_keys: FastHashMap<PipelineId, FastHashSet<ImageId>>,
pub last_frame_font_keys: FastHashMap<PipelineId, FastHashMap<ImmediateFontId, FastHashSet<Au>>>,
pub text_cache: TextCache,
}
Expand description
Stores the resources for the application, souch as fonts, images and cached texts, also clipboard strings
Images and fonts can be references across window contexts (not yet tested, but should work).
Fields§
§css_ids_to_image_ids: FastHashMap<CssImageId, ImageId>
The CssImageId is the string used in the CSS, i.e. “my_image” -> ImageId(4)
css_ids_to_font_ids: FastHashMap<CssFontId, FontId>
Same as CssImageId -> ImageId, but for fonts, i.e. “Roboto” -> FontId(9)
image_sources: FastHashMap<ImageId, ImageSource>
Stores where the images were loaded from
font_sources: FastHashMap<FontId, FontSource>
Stores where the fonts were loaded from
currently_registered_images: FastHashMap<PipelineId, FastHashMap<ImageId, ImageInfo>>
All image keys currently active in the RenderApi
currently_registered_fonts: FastHashMap<PipelineId, FastHashMap<ImmediateFontId, LoadedFont>>
All font keys currently active in the RenderApi
last_frame_image_keys: FastHashMap<PipelineId, FastHashSet<ImageId>>
If an image isn’t displayed, it is deleted from memory, only
the ImageSource
(i.e. the path / source where the image was loaded from) remains.
This way the image can be re-loaded if necessary but doesn’t have to reside in memory at all times.
last_frame_font_keys: FastHashMap<PipelineId, FastHashMap<ImmediateFontId, FastHashSet<Au>>>
If a font does not get used for one frame, the corresponding instance key gets deleted. If a FontId has no FontInstanceKeys anymore, the font key gets deleted.
The only thing remaining in memory permanently is the FontSource (which is only the string of the file path where the font was loaded from, so no huge memory pressure). The reason for this agressive strategy is that the
text_cache: TextCache
Stores long texts across frames
Implementations§
Source§impl AppResources
impl AppResources
Sourcepub fn add_pipeline(&mut self, pipeline_id: PipelineId)
pub fn add_pipeline(&mut self, pipeline_id: PipelineId)
Add a new pipeline to the app resources
Sourcepub fn delete_pipeline<T: FontImageApi>(
&mut self,
pipeline_id: &PipelineId,
render_api: &mut T,
)
pub fn delete_pipeline<T: FontImageApi>( &mut self, pipeline_id: &PipelineId, render_api: &mut T, )
Delete and remove all fonts & font instance keys from a given pipeline
Source§impl AppResources
impl AppResources
pub fn new() -> Self
Sourcepub fn get_loaded_font_ids(&self) -> Vec<FontId>
pub fn get_loaded_font_ids(&self) -> Vec<FontId>
Returns the IDs of all currently loaded fonts in self.font_data
pub fn get_loaded_image_ids(&self) -> Vec<ImageId>
pub fn get_loaded_css_image_ids(&self) -> Vec<CssImageId>
pub fn get_loaded_css_font_ids(&self) -> Vec<CssFontId>
pub fn get_loaded_text_ids(&self) -> Vec<TextId>
Sourcepub fn add_image_source(&mut self, image_id: ImageId, image_source: ImageSource)
pub fn add_image_source(&mut self, image_id: ImageId, image_source: ImageSource)
Add an image from a PNG, JPEG or other source.
Note: For specialized image formats, you’ll have to enable them as features in the Cargo.toml file.
Sourcepub fn has_image_source(&self, image_id: &ImageId) -> bool
pub fn has_image_source(&self, image_id: &ImageId) -> bool
Returns whether the AppResources has currently a certain image ID registered
Sourcepub fn get_image_source(&self, image_id: &ImageId) -> Option<&ImageSource>
pub fn get_image_source(&self, image_id: &ImageId) -> Option<&ImageSource>
Given an ImageId
, returns the decoded bytes of that image or None
, if the ImageId
is invalid.
Returns an error on IO failure / image decoding failure or image
pub fn delete_image_source(&mut self, image_id: &ImageId)
pub fn add_css_image_id<S: Into<String>>(&mut self, css_id: S) -> ImageId
pub fn has_css_image_id(&self, css_id: &str) -> bool
pub fn get_css_image_id(&self, css_id: &str) -> Option<&ImageId>
pub fn delete_css_image_id(&mut self, css_id: &str) -> Option<ImageId>
pub fn get_image_info( &self, pipeline_id: &PipelineId, image_key: &ImageId, ) -> Option<&ImageInfo>
pub fn add_css_font_id<S: Into<String>>(&mut self, css_id: S) -> FontId
pub fn has_css_font_id(&self, css_id: &str) -> bool
pub fn get_css_font_id(&self, css_id: &str) -> Option<&FontId>
pub fn delete_css_font_id(&mut self, css_id: &str) -> Option<FontId>
pub fn add_font_source(&mut self, font_id: FontId, font_source: FontSource)
Sourcepub fn get_font_source(&self, font_id: &FontId) -> Option<&FontSource>
pub fn get_font_source(&self, font_id: &FontId) -> Option<&FontSource>
Given a FontId
, returns the bytes for that font or None
, if the FontId
is invalid.
Sourcepub fn has_font_source(&self, id: &FontId) -> bool
pub fn has_font_source(&self, id: &FontId) -> bool
Checks if a FontId
is valid, i.e. if a font is currently ready-to-use
pub fn delete_font_source(&mut self, id: &FontId)
pub fn get_loaded_font( &self, pipeline_id: &PipelineId, font_id: &ImmediateFontId, ) -> Option<&LoadedFont>
Sourcepub fn add_text(&mut self, words: Words) -> TextId
pub fn add_text(&mut self, words: Words) -> TextId
Adds a string to the internal text cache, but only store it as a string, without caching the layout of the string.
pub fn get_text(&self, id: &TextId) -> Option<&Words>
Sourcepub fn delete_text(&mut self, id: TextId)
pub fn delete_text(&mut self, id: TextId)
Removes a string from both the string cache and the layouted text cache
Sourcepub fn clear_all_texts(&mut self)
pub fn clear_all_texts(&mut self)
Empties the entire internal text cache, invalidating all TextId
s. Use with care.