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

source

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

source

pub fn max_texture_size(&self) -> i32

source

pub fn tiling_threshold(&self) -> i32

Maximum texture size before we consider it preferrable to break the texture into tiles.

source

pub fn enable_multithreading(&mut self, enable: bool)

source

fn should_tile( limit: i32, descriptor: &ImageDescriptor, data: &CachedImageData ) -> bool

source

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,

source

pub fn post_scene_building_update( &mut self, updates: Vec<ResourceUpdate>, profile: &mut TransactionProfile )

source

pub fn add_rasterized_blob_images( &mut self, images: Vec<(BlobImageRequest, BlobImageResult)>, profile: &mut TransactionProfile )

source

pub fn add_font_template(&mut self, font_key: FontKey, template: FontTemplate)

source

pub fn delete_font_template(&mut self, font_key: FontKey)

source

pub fn delete_font_instance(&mut self, instance_key: FontInstanceKey)

source

pub fn get_font_instance( &self, instance_key: FontInstanceKey ) -> Option<Arc<BaseFontInstance>>

source

pub fn get_fonts(&self) -> SharedFontResources

source

pub fn add_image_template( &mut self, image_key: ImageKey, descriptor: ImageDescriptor, data: CachedImageData, visible_rect: &DeviceIntRect, tiling: Option<TileSize> )

source

pub fn update_image_template( &mut self, image_key: ImageKey, descriptor: ImageDescriptor, data: CachedImageData, dirty_rect: &ImageDirtyRect )

source

pub fn delete_image_template(&mut self, image_key: ImageKey)

source

pub fn get_image_generation(&self, key: ImageKey) -> ImageGeneration

Return the current generation of an image template

source

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.

source

fn discard_tiles_outside_visible_area( &mut self, key: BlobImageKey, area: &DeviceIntRect )

source

fn set_image_visible_rect(&mut self, key: ImageKey, rect: &DeviceIntRect)

source

pub fn request_glyphs( &mut self, font: FontInstance, glyph_keys: &[GlyphKey], gpu_cache: &mut GpuCache )

source

pub fn pending_updates(&mut self) -> ResourceUpdateList

source

pub fn fetch_glyphs<F>( &self, font: FontInstance, glyph_keys: &[GlyphKey], fetch_buffer: &mut Vec<GlyphFetchResult>, gpu_cache: &mut GpuCache, f: F )where F: FnMut(TextureSource, GlyphFormat, &[GlyphFetchResult]),

source

pub fn map_font_key(&self, key: FontKey) -> FontKey

source

pub fn map_font_instance_key(&self, key: FontInstanceKey) -> FontInstanceKey

source

pub fn get_glyph_dimensions( &mut self, font: &FontInstance, glyph_index: GlyphIndex ) -> Option<GlyphDimensions>

source

pub fn get_glyph_index(&mut self, font_key: FontKey, ch: char) -> Option<u32>

source

pub fn get_cached_image(&self, request: ImageRequest) -> Result<CacheItem, ()>

source

pub fn get_cached_render_task( &self, handle: &WeakFreeListHandle<RenderTaskCacheMarker> ) -> &RenderTaskCacheEntry

source

fn get_image_info(&self, request: ImageRequest) -> Result<&CachedImageInfo, ()>

source

pub fn get_texture_cache_item(&self, handle: &TextureCacheHandle) -> CacheItem

source

pub fn get_image_properties( &self, image_key: ImageKey ) -> Option<ImageProperties>

source

pub fn begin_frame( &mut self, stamp: FrameStamp, gpu_cache: &mut GpuCache, profile: &mut TransactionProfile )

source

pub fn block_until_all_resources_added( &mut self, gpu_cache: &mut GpuCache, profile: &mut TransactionProfile )

source

fn update_texture_cache(&mut self, gpu_cache: &mut GpuCache)

source

pub fn create_compositor_backdrop_surface( &mut self, color: ColorF ) -> NativeSurfaceId

source

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.

source

pub fn create_compositor_external_surface( &mut self, is_opaque: bool ) -> NativeSurfaceId

source

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.

source

pub fn create_compositor_tile(&mut self, id: NativeTileId)

Queue construction of a native compositor tile on a given surface.

source

pub fn destroy_compositor_tile(&mut self, id: NativeTileId)

Queue destruction of a native compositor tile.

source

pub fn attach_compositor_external_image( &mut self, id: NativeSurfaceId, external_image: ExternalImageId )

source

pub fn end_frame(&mut self, profile: &mut TransactionProfile)

source

pub fn set_debug_flags(&mut self, flags: DebugFlags)

source

pub fn clear(&mut self, what: ClearCache)

source

pub fn clear_namespace(&mut self, namespace: IdNamespace)

source

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.

source

fn clear_images<F: Fn(&ImageKey) -> bool>(&mut self, f: F)

Properly deletes all images matching the predicate.

source

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.

source

pub fn return_render_target_to_pool(&mut self, id: CacheTextureId)

Return a render target to the pool.

source

fn clear_render_target_pool(&mut self)

Clear all current render targets (e.g. on memory pressure)

source

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

source

pub fn save_capture( &mut self, root: &PathBuf ) -> (PlainResources, Vec<ExternalCaptureImage>)

source

pub fn save_caches(&self, _root: &PathBuf) -> PlainCacheRef<'_>

source

pub fn save_capture_sequence( &mut self, config: &mut CaptureConfig ) -> Vec<ExternalCaptureImage>

Trait Implementations§

source§

impl Drop for ResourceCache

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.