NetSurf
|
Cache implementation for bitmap images decoded into frontend format. More...
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include "netsurf/inttypes.h"
#include "utils/utils.h"
#include "utils/log.h"
#include "netsurf/misc.h"
#include "netsurf/bitmap.h"
#include "content/llcache.h"
#include "content/content_protected.h"
#include "desktop/gui_internal.h"
#include "image/image_cache.h"
#include "image/image.h"
Go to the source code of this file.
Data Structures | |
struct | image_cache_entry_s |
Image cache entry. More... | |
struct | image_cache_s |
Current state of the cache. More... | |
Macros | |
#define | FMTCHR(chr, fmt, var) |
#define | FMTPCHR(chr, fmt, var, div) |
Typedefs | |
typedef unsigned int | cache_age |
Age of an entry within the cache. More... | |
Functions | |
static struct image_cache_entry_s * | image_cache__findn (int entryn) |
Find a cache entry by index. More... | |
static struct image_cache_entry_s * | image_cache__find (const struct content *c) |
Find the cache entry for a content. More... | |
static void | image_cache_stats_bitmap_add (struct image_cache_entry_s *centry) |
Update the image cache statistics with an entry. More... | |
static void | image_cache__link (struct image_cache_entry_s *centry) |
static void | image_cache__unlink (struct image_cache_entry_s *centry) |
static void | image_cache__free_bitmap (struct image_cache_entry_s *centry) |
free bitmap from an image cache entry More... | |
static void | image_cache__free_entry (struct image_cache_entry_s *centry) |
free image cache entry More... | |
static void | image_cache__clean (struct image_cache_s *icache) |
Image cache cleaner. More... | |
static void | image_cache__background_update (void *p) |
Cache background scheduled callback. More... | |
struct bitmap * | image_cache_get_bitmap (const struct content *c) |
Obtain a bitmap from a content converting from source if neccessary. More... | |
bool | image_cache_speculate (struct content *c) |
Decide if a content should be speculatively converted. More... | |
struct bitmap * | image_cache_find_bitmap (struct content *c) |
Obtain a bitmap from a content with no conversion. More... | |
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) |
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... | |
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... | |
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 *content) |
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) |
Variables | |
static struct image_cache_s * | image_cache = NULL |
image cache state More... | |
Cache implementation for bitmap images decoded into frontend format.
Definition in file image_cache.c.
#define FMTCHR | ( | chr, | |
fmt, | |||
var | |||
) |
#define FMTPCHR | ( | chr, | |
fmt, | |||
var, | |||
div | |||
) |
typedef unsigned int cache_age |
Age of an entry within the cache.
type deffed away so it can be readily changed later perhaps to a wallclock time structure.
Definition at line 48 of file image_cache.c.
|
static |
Cache background scheduled callback.
p | The image cache context. |
Definition at line 327 of file image_cache.c.
References image_cache_parameters::bg_clean_time, image_cache_s::current_age, guit, image_cache__background_update(), image_cache__clean(), netsurf_table::misc, NSLOG, image_cache_s::params, and gui_misc_table::schedule.
Referenced by image_cache__background_update(), image_cache_fini(), and image_cache_init().
|
static |
Image cache cleaner.
icache | The image cache context. |
Definition at line 304 of file image_cache.c.
References image_cache_parameters::bg_clean_time, image_cache_s::current_age, image_cache_s::entries, image_cache_parameters::hysteresis, image_cache__free_bitmap(), image_cache_parameters::limit, image_cache_entry_s::next, image_cache_s::params, image_cache_entry_s::redraw_age, and image_cache_s::total_bitmap_size.
Referenced by image_cache__background_update().
|
static |
Find the cache entry for a content.
c | The content to get an entry for |
Definition at line 168 of file image_cache.c.
References image_cache_entry_s::content, image_cache_s::entries, image_cache, and image_cache_entry_s::next.
Referenced by image_cache_add(), image_cache_destroy(), image_cache_find_bitmap(), image_cache_get_bitmap(), image_cache_redraw(), and image_cache_remove().
|
static |
Find a cache entry by index.
entryn | index of cache entry |
Definition at line 149 of file image_cache.c.
References image_cache_s::entries, image_cache, and image_cache_entry_s::next.
Referenced by image_cache_snentryf().
|
static |
free bitmap from an image cache entry
centry | The image cache entry to free bitmap from. |
Definition at line 255 of file image_cache.c.
References image_cache_entry_s::bitmap, netsurf_table::bitmap, image_cache_entry_s::bitmap_age, image_cache_s::bitmap_count, image_cache_entry_s::bitmap_size, image_cache_s::current_age, gui_bitmap_table::destroy, guit, image_cache, NSLOG, image_cache_entry_s::redraw_count, image_cache_s::specultive_miss_count, and image_cache_s::total_bitmap_size.
Referenced by image_cache__clean(), and image_cache__free_entry().
|
static |
free image cache entry
centry | The image cache entry to free. |
Definition at line 282 of file image_cache.c.
References image_cache, image_cache__free_bitmap(), image_cache__unlink(), NSLOG, image_cache_entry_s::redraw_count, and image_cache_s::total_unrendered.
Referenced by image_cache_destroy(), image_cache_fini(), and image_cache_remove().
|
static |
Definition at line 219 of file image_cache.c.
References image_cache_s::entries, image_cache, image_cache_entry_s::next, and image_cache_entry_s::prev.
Referenced by image_cache_add().
|
static |
Definition at line 229 of file image_cache.c.
References image_cache_s::entries, image_cache, image_cache_entry_s::next, and image_cache_entry_s::prev.
Referenced by image_cache__free_entry().
nserror image_cache_add | ( | struct content * | content, |
struct bitmap * | bitmap, | ||
image_cache_convert_fn * | convert | ||
) |
adds an image content to be cached.
content | The content handle used as a key |
bitmap | A bitmap representing the already converted content or NULL. |
convert | A function pointer to convert the content into a bitmap or NULL. |
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().
content_type image_cache_content_type | ( | void | ) |
Definition at line 873 of file image_cache.c.
References CONTENT_IMAGE.
void image_cache_destroy | ( | struct content * | content | ) |
Definition at line 841 of file image_cache.c.
References image_cache__find(), image_cache__free_entry(), and NSLOG.
Referenced by rsvg_destroy().
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().
nserror image_cache_fini | ( | void | ) |
Definition at line 438 of file image_cache.c.
References image_cache_s::bitmap_count, image_cache_s::current_age, image_cache_s::entries, image_cache_s::fail_count, image_cache_s::fail_size, guit, image_cache_s::hit_count, image_cache_s::hit_size, image_cache, image_cache__background_update(), image_cache__free_entry(), image_cache_s::max_bitmap_count, image_cache_s::max_bitmap_count_size, image_cache_s::max_bitmap_size, image_cache_s::max_bitmap_size_count, netsurf_table::misc, image_cache_s::miss_count, image_cache_s::miss_size, NSERROR_OK, NSLOG, image_cache_s::peak_conversions, image_cache_s::peak_conversions_size, PRId64, PRIsizet, PRIu64, gui_misc_table::schedule, image_cache_s::specultive_miss_count, image_cache_s::total_bitmap_size, image_cache_s::total_extra_conversions, image_cache_s::total_extra_conversions_count, and image_cache_s::total_unrendered.
Referenced by netsurf_exit().
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().
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().
nserror image_cache_init | ( | const struct image_cache_parameters * | image_cache_parameters | ) |
Initialise the image cache.
image_cache_parameters | The 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().
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().
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.
Definition at line 567 of file image_cache.c.
References image_cache__find(), image_cache__free_entry(), NSERROR_NOT_FOUND, NSERROR_OK, and NSLOG.
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
string | The buffer in which to place the results. |
size | The size of the string buffer. |
entryn | The opaque entry number. |
fmt | The format string. |
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.
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.
string | The buffer in which to place the results. |
size | The size of the string buffer. |
fmt | The format string. |
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.
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.
c | The content to be considered. |
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().
|
static |
Update the image cache statistics with an entry.
centry | The image cache entry to update the stats with. |
Definition at line 184 of file image_cache.c.
References image_cache_entry_s::bitmap_age, image_cache_s::bitmap_count, image_cache_entry_s::bitmap_size, image_cache_entry_s::conversion_count, image_cache_s::current_age, image_cache, image_cache_s::max_bitmap_count, image_cache_s::max_bitmap_count_size, image_cache_s::max_bitmap_size, image_cache_s::max_bitmap_size_count, image_cache_s::peak_conversions, image_cache_s::peak_conversions_size, image_cache_s::total_bitmap_size, image_cache_s::total_extra_conversions, and image_cache_s::total_extra_conversions_count.
Referenced by image_cache_add(), image_cache_get_bitmap(), and image_cache_redraw().
|
static |
image cache state
Definition at line 140 of file image_cache.c.
Referenced by image_cache__find(), image_cache__findn(), image_cache__free_bitmap(), image_cache__free_entry(), image_cache__link(), image_cache__unlink(), image_cache_add(), image_cache_fini(), image_cache_get_bitmap(), image_cache_init(), image_cache_redraw(), image_cache_snentryf(), image_cache_snsummaryf(), image_cache_speculate(), and image_cache_stats_bitmap_add().