NetSurf
Data Structures | Typedefs | Functions
image_cache.h File Reference

The image content handler intermediate image cache. More...

#include "utils/errors.h"
#include "netsurf/content_type.h"
Include dependency graph for image_cache.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  image_cache_parameters
 

Typedefs

typedef struct bitmap *() image_cache_convert_fn(struct content *content)
 

Functions

nserror image_cache_init (const struct image_cache_parameters *image_cache_parameters)
 Initialise the image cache. More...
 
nserror image_cache_fini (void)
 
nserror image_cache_add (struct content *content, struct bitmap *bitmap, image_cache_convert_fn *convert)
 adds an image content to be cached. More...
 
nserror image_cache_remove (struct content *content)
 
struct bitmapimage_cache_get_bitmap (const struct content *c)
 Obtain a bitmap from a content converting from source if neccessary. More...
 
struct bitmapimage_cache_find_bitmap (struct content *c)
 Obtain a bitmap from a content with no conversion. More...
 
bool image_cache_speculate (struct content *c)
 Decide if a content should be speculatively converted. More...
 
int image_cache_snentryf (char *string, size_t size, unsigned int entryn, const char *fmt)
 Fill a buffer with information about a cache entry using a format. More...
 
int image_cache_snsummaryf (char *string, size_t size, const char *fmt)
 Fill a buffer with information about the image cache using a format. More...
 
bool image_cache_redraw (struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
 Generic content redraw callback. More...
 
void image_cache_destroy (struct content *c)
 
void * image_cache_get_internal (const struct content *c, void *context)
 
bool image_cache_is_opaque (struct content *c)
 
content_type image_cache_content_type (void)
 

Detailed Description

The image content handler intermediate image cache.

This cache allows netsurf to use a generic intermediate bitmap format without keeping the intermediate representation in memory.

The bitmap structure is opaque to the rest of netsurf and is controlled by the platform-specific code (see image/bitmap.h for detials). All image content handlers convert into this format and pass it to the plot functions for display,

This cache maintains a link between the underlying original content and the intermediate representation. It is intended to be flexable and either manage the bitmap plotting completely or give the image content handler complete control.

Definition in file image_cache.h.

Typedef Documentation

◆ image_cache_convert_fn

typedef struct bitmap *() image_cache_convert_fn(struct content *content)

Definition at line 1 of file image_cache.h.

Function Documentation

◆ image_cache_add()

nserror image_cache_add ( struct content content,
struct bitmap bitmap,
image_cache_convert_fn convert 
)

adds an image content to be cached.

Parameters
contentThe content handle used as a key
bitmapA bitmap representing the already converted content or NULL.
convertA function pointer to convert the content into a bitmap or NULL.
Returns
A netsurf error code.

Definition at line 510 of file image_cache.c.

References image_cache_entry_s::bitmap, netsurf_table::bitmap, bitmap(), image_cache_entry_s::bitmap_size, image_cache_entry_s::content, image_cache_entry_s::convert, image_cache_s::current_age, gui_bitmap_table::destroy, image_cache_s::fail_count, guit, content::height, image_cache, image_cache__find(), image_cache__link(), image_cache_speculate(), image_cache_stats_bitmap_add(), NSERROR_NOMEM, NSERROR_OK, NSLOG, and content::width.

Referenced by nsjpeg_convert(), nsjpegxl_convert(), nspng_convert(), rsvg_convert(), and webp_convert().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ image_cache_content_type()

content_type image_cache_content_type ( void  )

Definition at line 873 of file image_cache.c.

References CONTENT_IMAGE.

◆ image_cache_destroy()

void image_cache_destroy ( struct content c)

Definition at line 841 of file image_cache.c.

References image_cache__find(), image_cache__free_entry(), and NSLOG.

Referenced by rsvg_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ image_cache_find_bitmap()

struct bitmap * image_cache_find_bitmap ( struct content c)

Obtain a bitmap from a content with no conversion.

Definition at line 402 of file image_cache.c.

References image_cache_entry_s::bitmap, and image_cache__find().

Here is the call graph for this function:

◆ image_cache_fini()

nserror image_cache_fini ( void  )

◆ image_cache_get_bitmap()

struct bitmap * image_cache_get_bitmap ( const struct content c)

Obtain a bitmap from a content converting from source if neccessary.

Definition at line 346 of file image_cache.c.

References image_cache_entry_s::bitmap, image_cache_entry_s::bitmap_size, image_cache_entry_s::content, image_cache_entry_s::convert, image_cache_s::fail_count, image_cache_s::fail_size, image_cache_s::hit_count, image_cache_s::hit_size, image_cache, image_cache__find(), image_cache_stats_bitmap_add(), image_cache_s::miss_count, and image_cache_s::miss_size.

Referenced by image_cache_get_internal(), and image_cache_is_opaque().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ image_cache_get_internal()

void * image_cache_get_internal ( const struct content c,
void *  context 
)

Definition at line 856 of file image_cache.c.

References image_cache_get_bitmap().

Here is the call graph for this function:

◆ image_cache_init()

nserror image_cache_init ( const struct image_cache_parameters image_cache_parameters)

Initialise the image cache.

Parameters
image_cache_parametersThe control parameters for the image cache

Definition at line 416 of file image_cache.c.

References image_cache_parameters::bg_clean_time, guit, image_cache_parameters::hysteresis, image_cache, image_cache__background_update(), image_cache_parameters::limit, netsurf_table::misc, NSERROR_NOMEM, NSERROR_OK, NSLOG, image_cache_s::params, PRIsizet, and gui_misc_table::schedule.

Referenced by netsurf_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ image_cache_is_opaque()

bool image_cache_is_opaque ( struct content c)

Definition at line 862 of file image_cache.c.

References netsurf_table::bitmap, gui_bitmap_table::get_opaque, guit, and image_cache_get_bitmap().

Here is the call graph for this function:

◆ image_cache_redraw()

bool image_cache_redraw ( struct content c,
struct content_redraw_data data,
const struct rect clip,
const struct redraw_context ctx 
)

Generic content redraw callback.

May be used by image content handlers as their redraw callback. Performs all neccissary cache lookups and conversions and calls the bitmap plot function in the redraw context.

Definition at line 798 of file image_cache.c.

References image_cache_entry_s::bitmap, image_cache_entry_s::bitmap_size, clip(), image_cache_entry_s::content, image_cache_entry_s::convert, image_cache_s::current_age, image_cache_s::fail_count, image_cache_s::fail_size, image_cache_s::hit_count, image_cache_s::hit_size, image_bitmap_plot(), image_cache, image_cache__find(), image_cache_stats_bitmap_add(), image_cache_s::miss_count, image_cache_s::miss_size, NSLOG, image_cache_entry_s::redraw_age, and image_cache_entry_s::redraw_count.

Here is the call graph for this function:

◆ image_cache_remove()

nserror image_cache_remove ( struct content content)

Definition at line 567 of file image_cache.c.

References image_cache__find(), image_cache__free_entry(), NSERROR_NOT_FOUND, NSERROR_OK, and NSLOG.

Here is the call graph for this function:

◆ image_cache_snentryf()

int image_cache_snentryf ( char *  string,
size_t  size,
unsigned int  entryn,
const char *  fmt 
)

Fill a buffer with information about a cache entry using a format.

The format string is copied into the output buffer with the following replaced: e - The entry number k - The content key r - The number of redraws of this bitmap c - The number of times this bitmap has been converted s - The size of the current bitmap allocation

Parameters
stringThe buffer in which to place the results.
sizeThe size of the string buffer.
entrynThe opaque entry number.
fmtThe format string.
Returns
The number of bytes written to string or -1 on error

Definition at line 692 of file image_cache.c.

References image_cache_entry_s::bitmap, image_cache_entry_s::bitmap_age, image_cache_entry_s::bitmap_size, image_cache_entry_s::content, image_cache_entry_s::conversion_count, image_cache_s::current_age, image_cache, image_cache__findn(), content::llcache, llcache, llcache_handle_get_url(), min, nsurl_access(), nsurl_get_component(), nsurl_has_component(), NSURL_HOST, PRIsizet, image_cache_entry_s::redraw_age, and image_cache_entry_s::redraw_count.

Here is the call graph for this function:

◆ image_cache_snsummaryf()

int image_cache_snsummaryf ( char *  string,
size_t  size,
const char *  fmt 
)

Fill a buffer with information about the image cache using a format.

The format string is copied into the output buffer with the following replaced:

a Configured cache limit size b Configured cache hysteresis size c Current caches total consumed size d Number of images currently in the cache e The age of the cache f The largest amount of space the cache has occupied since initialisation g The number of objetcs when the cache was at its largest h The largest number of images in the cache since initialisation i The size of the cache when the largest number of objects occoured j The total number of read operations performed on the cache k The total number of read operations satisfied from the cache without conversion. l The total number of read operations satisfied from the cache which required a conversion. m The total number of read operations which could not be sucessfully returned. ie. not available in cache and conversion failed. n The total size of read operations performed on the cache o The total size of read operations satisfied from the cache without conversion. q The total size of read operations satisfied from the cache which required a conversion. r The total size of read operations which could not be sucessfully returned. ie. not available in cache and conversion failed. s The number of images which were placed in the cache but never read. t The number of images that were converted on insertion into the cache which were subsequently never used. u The number of times an image was converted after the first v The number of images that had extra conversions performed. w Size of the image that was converted (read missed cache) highest number of times. x The number of times the image that was converted (read missed cache) highest number of times.

format modifiers: A p before the value modifies the replacement to be a percentage.

Parameters
stringThe buffer in which to place the results.
sizeThe size of the string buffer.
fmtThe format string.
Returns
The number of bytes written to string or -1 on error

Definition at line 585 of file image_cache.c.

References image_cache_s::fail_count, image_cache_s::fail_size, FMTCHR, FMTPCHR, image_cache_s::hit_count, image_cache_s::hit_size, image_cache, min, image_cache_s::miss_count, image_cache_s::miss_size, PRId64, and PRIsizet.

◆ image_cache_speculate()

bool image_cache_speculate ( struct content c)

Decide if a content should be speculatively converted.

This allows for image content handlers to ask the cache if a bitmap should be generated before it is added to the cache. This is the same decision logic used to decide to perform an immediate conversion when a content is initially added to the cache.

Parameters
cThe content to be considered.
Returns
true if a speculative conversion is desired false otherwise.

Definition at line 377 of file image_cache.c.

References image_cache, image_cache_parameters::limit, NSLOG, image_cache_s::params, content::size, SPECULATE_SMALL, image_cache_parameters::speculative_small, and image_cache_s::total_bitmap_size.

Referenced by image_cache_add(), and info_callback().

Here is the caller graph for this function: