/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use api::{FontKey, FontInstanceKey, IdNamespace}; use glyph_rasterizer::{FontInstance, GlyphFormat, GlyphCacheKey, GlyphRasterizer}; usecrate::internal_types::{FrameId, FrameStamp, FastHashMap}; usecrate::resource_cache::ResourceClassCache; use std::sync::Arc; usecrate::texture_cache::{EvictionNotice, TextureCache}; usecrate::texture_cache::TextureCacheHandle;
#[cfg_attr(feature = "capture", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] pubenum GlyphCacheEntry { // A glyph that has been successfully rasterized.
Cached(CachedGlyphInfo), // A glyph that should not be rasterized (i.e. a space).
Blank, // A glyph that has been submitted to the font backend for rasterization, // but is still pending a result. #[allow(dead_code)]
Pending,
}
fn clear_evicted(&mutself, texture_cache: &TextureCache) { ifself.eviction_notice().check() { // If there are evictions, filter out any glyphs evicted from the // texture cache from the glyph key cache. self.retain(|_, entry| !entry.has_been_evicted(texture_cache));
}
}
}
pubfn clear(&mutself) { for (_, glyph_key_cache) in &mutself.glyph_key_caches {
glyph_key_cache.clear()
} // We use this in on_memory_pressure where retaining memory allocations // isn't desirable, so we completely remove the hash map instead of clearing it. self.glyph_key_caches = FastHashMap::default();
}
/// Clear out evicted entries from glyph key caches. fn clear_evicted(&mutself, texture_cache: &TextureCache) { for cache inself.glyph_key_caches.values_mut() { // Scan for any glyph key caches that have evictions.
cache.clear_evicted(texture_cache);
}
}
/// If possible, remove entirely any empty glyph key caches. fn clear_empty_caches(&mutself, glyph_rasterizer: &'color:red'>mut GlyphRasterizer) { self.glyph_key_caches.retain(|key, cache| { // Discard the glyph key cache if it has no valid glyphs. if cache.is_empty() {
glyph_rasterizer.delete_font_instance(key); false
} else { true
}
});
}
pubfn begin_frame(
&mutself,
stamp: FrameStamp,
texture_cache: &mut TextureCache,
glyph_rasterizer: &mut GlyphRasterizer,
) {
profile_scope!("begin_frame"); self.current_frame = stamp.frame_id(); self.clear_evicted(texture_cache); // Clearing evicted glyphs and pruning excess usage might have produced empty caches, // so get rid of them if possible. self.clear_empty_caches(glyph_rasterizer);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.