Struct webrender::resource_cache::ResourceCache
source · pub struct ResourceCache {Show 19 fields
cached_glyphs: GlyphCache,
cached_images: ResourceClassCache<ImageKey, ImageResult, ()>,
cached_render_tasks: RenderTaskCache,
resources: Resources,
state: State,
current_frame_id: FrameId,
capture_dirty: bool,
pub texture_cache: TextureCache,
pub picture_textures: PictureTextures,
cached_glyph_dimensions: FastHashMap<(FontInstanceKey, GlyphIndex), Option<GlyphDimensions>>,
glyph_rasterizer: GlyphRasterizer,
pending_image_requests: HashSet<ImageRequest, BuildHasherDefault<FxHasher>>,
rasterized_blob_images: FastHashMap<BlobImageKey, FastHashMap<TileOffset, RasterizedBlobImage>>,
deleted_blob_keys: VecDeque<Vec<BlobImageKey>>,
blob_image_handler: Option<Box<dyn BlobImageHandler>>,
pending_native_surface_updates: Vec<NativeSurfaceOperation>,
image_templates_memory: usize,
font_templates_memory: usize,
render_target_pool: Vec<RenderTarget>,
}
Expand description
High-level container for resources managed by the RenderBackend
.
This includes a variety of things, including images, fonts, and glyphs, which may be stored as memory buffers, GPU textures, or handles to resources managed by the OS or other parts of WebRender.
Fields§
§cached_glyphs: GlyphCache
§cached_images: ResourceClassCache<ImageKey, ImageResult, ()>
§cached_render_tasks: RenderTaskCache
§resources: Resources
§state: State
§current_frame_id: FrameId
§capture_dirty: bool
Used for capture sequences. If the resource cache is updated, then we mark it as dirty. When the next frame is captured in the sequence, we dump the state of the resource cache.
texture_cache: TextureCache
§picture_textures: PictureTextures
§cached_glyph_dimensions: FastHashMap<(FontInstanceKey, GlyphIndex), Option<GlyphDimensions>>
TODO(gw): We should expire (parts of) this cache semi-regularly!
glyph_rasterizer: GlyphRasterizer
§pending_image_requests: HashSet<ImageRequest, BuildHasherDefault<FxHasher>>
The set of images that aren’t present or valid in the texture cache, and need to be rasterized and/or uploaded this frame. This includes both blobs and regular images.
rasterized_blob_images: FastHashMap<BlobImageKey, FastHashMap<TileOffset, RasterizedBlobImage>>
§deleted_blob_keys: VecDeque<Vec<BlobImageKey>>
A log of the last three frames worth of deleted image keys kept for debugging purposes.
blob_image_handler: Option<Box<dyn BlobImageHandler>>
We keep one around to be able to call clear_namespace after the api object is deleted. For most purposes the api object’s blob handler should be used instead.
pending_native_surface_updates: Vec<NativeSurfaceOperation>
A list of queued compositor surface updates to apply next frame.
image_templates_memory: usize
§font_templates_memory: usize
§render_target_pool: Vec<RenderTarget>
A pool of render targets for use by the render task graph
Implementations§
source§impl ResourceCache
impl ResourceCache
pub fn new( texture_cache: TextureCache, picture_textures: PictureTextures, glyph_rasterizer: GlyphRasterizer, cached_glyphs: GlyphCache, fonts: SharedFontResources, blob_image_handler: Option<Box<dyn BlobImageHandler>>, ) -> Self
pub fn max_texture_size(&self) -> i32
sourcepub fn tiling_threshold(&self) -> i32
pub fn tiling_threshold(&self) -> i32
Maximum texture size before we consider it preferrable to break the texture into tiles.
pub fn enable_multithreading(&mut self, enable: bool)
fn should_tile( limit: i32, descriptor: &ImageDescriptor, data: &CachedImageData, ) -> bool
pub fn request_render_task<F>(
&mut self,
key: RenderTaskCacheKey,
gpu_cache: &mut GpuCache,
gpu_buffer_builder: &mut GpuBufferBuilderImpl<GpuBufferBlockF>,
rg_builder: &mut RenderTaskGraphBuilder,
user_data: Option<[f32; 4]>,
is_opaque: bool,
parent: RenderTaskParent,
surface_builder: &mut SurfaceBuilder,
f: F,
) -> RenderTaskIdwhere
F: FnOnce(&mut RenderTaskGraphBuilder, &mut GpuBufferBuilderImpl<GpuBufferBlockF>) -> RenderTaskId,
pub fn post_scene_building_update( &mut self, updates: Vec<ResourceUpdate>, profile: &mut TransactionProfile, )
pub fn add_rasterized_blob_images( &mut self, images: Vec<(BlobImageRequest, BlobImageResult)>, profile: &mut TransactionProfile, )
pub fn add_font_template(&mut self, font_key: FontKey, template: FontTemplate)
pub fn delete_font_template(&mut self, font_key: FontKey)
pub fn delete_font_instance(&mut self, instance_key: FontInstanceKey)
pub fn get_font_instance( &self, instance_key: FontInstanceKey, ) -> Option<Arc<BaseFontInstance>>
pub fn get_fonts(&self) -> SharedFontResources
pub fn add_image_template( &mut self, image_key: ImageKey, descriptor: ImageDescriptor, data: CachedImageData, visible_rect: &DeviceIntRect, tiling: Option<TileSize>, )
pub fn update_image_template( &mut self, image_key: ImageKey, descriptor: ImageDescriptor, data: CachedImageData, dirty_rect: &ImageDirtyRect, )
pub fn delete_image_template(&mut self, image_key: ImageKey)
sourcepub fn get_image_generation(&self, key: ImageKey) -> ImageGeneration
pub fn get_image_generation(&self, key: ImageKey) -> ImageGeneration
Return the current generation of an image template
sourcepub fn request_image(
&mut self,
request: ImageRequest,
gpu_cache: &mut GpuCache,
) -> DeviceIntSize
pub fn request_image( &mut self, request: ImageRequest, gpu_cache: &mut GpuCache, ) -> DeviceIntSize
Requests an image to ensure that it will be in the texture cache this frame.
returns the size in device pixel of the image or tile.
fn discard_tiles_outside_visible_area( &mut self, key: BlobImageKey, area: &DeviceIntRect, )
fn set_image_visible_rect(&mut self, key: ImageKey, rect: &DeviceIntRect)
pub fn request_glyphs( &mut self, font: FontInstance, glyph_keys: &[GlyphKey], gpu_cache: &mut GpuCache, )
pub fn pending_updates(&mut self) -> ResourceUpdateList
pub fn fetch_glyphs<F>( &self, font: FontInstance, glyph_keys: &[GlyphKey], fetch_buffer: &mut Vec<GlyphFetchResult>, gpu_cache: &mut GpuCache, f: F, )
pub fn map_font_key(&self, key: FontKey) -> FontKey
pub fn map_font_instance_key(&self, key: FontInstanceKey) -> FontInstanceKey
pub fn get_glyph_dimensions( &mut self, font: &FontInstance, glyph_index: GlyphIndex, ) -> Option<GlyphDimensions>
pub fn get_glyph_index(&mut self, font_key: FontKey, ch: char) -> Option<u32>
pub fn get_cached_image(&self, request: ImageRequest) -> Result<CacheItem, ()>
pub fn get_cached_render_task( &self, handle: &WeakFreeListHandle<RenderTaskCacheMarker>, ) -> &RenderTaskCacheEntry
fn get_image_info(&self, request: ImageRequest) -> Result<&CachedImageInfo, ()>
pub fn get_texture_cache_item(&self, handle: &TextureCacheHandle) -> CacheItem
pub fn get_image_properties( &self, image_key: ImageKey, ) -> Option<ImageProperties>
pub fn begin_frame( &mut self, stamp: FrameStamp, gpu_cache: &mut GpuCache, profile: &mut TransactionProfile, )
pub fn block_until_all_resources_added( &mut self, gpu_cache: &mut GpuCache, profile: &mut TransactionProfile, )
fn update_texture_cache(&mut self, gpu_cache: &mut GpuCache)
pub fn create_compositor_backdrop_surface( &mut self, color: ColorF, ) -> NativeSurfaceId
sourcepub fn create_compositor_surface(
&mut self,
virtual_offset: DeviceIntPoint,
tile_size: DeviceIntSize,
is_opaque: bool,
) -> NativeSurfaceId
pub fn create_compositor_surface( &mut self, virtual_offset: DeviceIntPoint, tile_size: DeviceIntSize, is_opaque: bool, ) -> NativeSurfaceId
Queue up allocation of a new OS native compositor surface with the specified tile size.
pub fn create_compositor_external_surface( &mut self, is_opaque: bool, ) -> NativeSurfaceId
sourcepub fn destroy_compositor_surface(&mut self, id: NativeSurfaceId)
pub fn destroy_compositor_surface(&mut self, id: NativeSurfaceId)
Queue up destruction of an existing native OS surface. This is used when a picture cache surface is dropped or resized.
sourcepub fn create_compositor_tile(&mut self, id: NativeTileId)
pub fn create_compositor_tile(&mut self, id: NativeTileId)
Queue construction of a native compositor tile on a given surface.
sourcepub fn destroy_compositor_tile(&mut self, id: NativeTileId)
pub fn destroy_compositor_tile(&mut self, id: NativeTileId)
Queue destruction of a native compositor tile.
pub fn attach_compositor_external_image( &mut self, id: NativeSurfaceId, external_image: ExternalImageId, )
pub fn end_frame(&mut self, profile: &mut TransactionProfile)
pub fn set_debug_flags(&mut self, flags: DebugFlags)
pub fn clear(&mut self, what: ClearCache)
pub fn clear_namespace(&mut self, namespace: IdNamespace)
sourcepub fn report_memory(&self, op: VoidPtrToSizeFn) -> MemoryReport
pub fn report_memory(&self, op: VoidPtrToSizeFn) -> MemoryReport
Reports the CPU heap usage of this ResourceCache.
NB: It would be much better to use the derive(MallocSizeOf) machinery here, but the Arcs complicate things. The two ways to handle that would be to either (a) Implement MallocSizeOf manually for the things that own them and manually avoid double-counting, or (b) Use the “seen this pointer yet” machinery from the proper malloc_size_of crate. We can do this if/when more accurate memory reporting on these resources becomes a priority.
sourcefn clear_images<F: Fn(&ImageKey) -> bool>(&mut self, f: F)
fn clear_images<F: Fn(&ImageKey) -> bool>(&mut self, f: F)
Properly deletes all images matching the predicate.
sourcepub fn get_or_create_render_target_from_pool(
&mut self,
size: DeviceIntSize,
format: ImageFormat,
) -> CacheTextureId
pub fn get_or_create_render_target_from_pool( &mut self, size: DeviceIntSize, format: ImageFormat, ) -> CacheTextureId
Get a render target from the pool, or allocate a new one if none are currently available that match the requested parameters.
sourcepub fn return_render_target_to_pool(&mut self, id: CacheTextureId)
pub fn return_render_target_to_pool(&mut self, id: CacheTextureId)
Return a render target to the pool.
sourcefn clear_render_target_pool(&mut self)
fn clear_render_target_pool(&mut self)
Clear all current render targets (e.g. on memory pressure)
sourcefn gc_render_targets(
&mut self,
total_bytes_threshold: usize,
total_bytes_red_line_threshold: usize,
frames_threshold: u64,
)
fn gc_render_targets( &mut self, total_bytes_threshold: usize, total_bytes_red_line_threshold: usize, frames_threshold: u64, )
Garbage collect and remove old render targets from the pool that haven’t been used for some time.
source§impl ResourceCache
impl ResourceCache
pub fn save_capture( &mut self, root: &PathBuf, ) -> (PlainResources, Vec<ExternalCaptureImage>)
pub fn save_caches(&self, _root: &PathBuf) -> PlainCacheRef<'_>
pub fn save_capture_sequence( &mut self, config: &mut CaptureConfig, ) -> Vec<ExternalCaptureImage>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ResourceCache
impl !RefUnwindSafe for ResourceCache
impl !Send for ResourceCache
impl !Sync for ResourceCache
impl Unpin for ResourceCache
impl !UnwindSafe for ResourceCache
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more