fix spelling and doxygen comments in image cache

This commit is contained in:
Vincent Sanders 2016-11-20 23:52:45 +00:00
parent d436992eb2
commit f679a9b1d6

View File

@ -16,6 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/**
* \file
* Cache implementation for bitmap images decoded into frontend format.
*/
#include <assert.h> #include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h> #include <stdint.h>
@ -34,22 +39,26 @@
#include "image/image_cache.h" #include "image/image_cache.h"
#include "image/image.h" #include "image/image.h"
/** Age of an entry within the cache /**
* Age of an entry within the cache
* *
* type deffed away so it can be readily changed later perhaps to a * type deffed away so it can be readily changed later perhaps to a
* wallclock time structure. * wallclock time structure.
*/ */
typedef unsigned int cache_age; typedef unsigned int cache_age;
/** Image cache entry /**
* Image cache entry
*/ */
struct image_cache_entry_s { struct image_cache_entry_s {
struct image_cache_entry_s *next; /* next cache entry in list */ struct image_cache_entry_s *next; /**< next cache entry in list */
struct image_cache_entry_s *prev; /* previous cache entry in list */ struct image_cache_entry_s *prev; /**< previous cache entry in list */
struct content *content; /** content is used as a key */ /** content is used as a key */
struct bitmap *bitmap; /** associated bitmap entry */ struct content *content;
/** Conversion routine */ /** associated bitmap entry */
struct bitmap *bitmap;
/** routine to convert content into bitmap */
image_cache_convert_fn *convert; image_cache_convert_fn *convert;
/* Statistics for replacement algorithm */ /* Statistics for replacement algorithm */
@ -62,7 +71,8 @@ struct image_cache_entry_s {
int conversion_count; /**< Number of times image has been converted */ int conversion_count; /**< Number of times image has been converted */
}; };
/** Current state of the cache. /**
* Current state of the cache.
* *
* Global state of the cache. entries "age" is determined based on a * Global state of the cache. entries "age" is determined based on a
* monotonically incrementing operation count. This avoids issues with * monotonically incrementing operation count. This avoids issues with
@ -90,12 +100,12 @@ struct image_cache_s {
/** Maximum size of bitmaps allocated at any one time */ /** Maximum size of bitmaps allocated at any one time */
size_t max_bitmap_size; size_t max_bitmap_size;
/** The number of objects when maximum bitmap usage occoured */ /** The number of objects when maximum bitmap usage occurred */
int max_bitmap_size_count; int max_bitmap_size_count;
/** Maximum count of bitmaps allocated at any one time */ /** Maximum count of bitmaps allocated at any one time */
int max_bitmap_count; int max_bitmap_count;
/** The size of the bitmaps when the max count occoured */ /** The size of the bitmaps when the max count occurred */
size_t max_bitmap_count_size; size_t max_bitmap_count_size;
/** Bitmap was not available at plot time required conversion */ /** Bitmap was not available at plot time required conversion */
@ -130,7 +140,11 @@ struct image_cache_s {
static struct image_cache_s *image_cache = NULL; static struct image_cache_s *image_cache = NULL;
/** Find the nth cache entry /**
* Find a cache entry by index.
*
* \param entryn index of cache entry
* \return cache entry at index or NULL if not found.
*/ */
static struct image_cache_entry_s *image_cache__findn(int entryn) static struct image_cache_entry_s *image_cache__findn(int entryn)
{ {
@ -144,7 +158,12 @@ static struct image_cache_entry_s *image_cache__findn(int entryn)
return found; return found;
} }
/** Find the cache entry for a content
/**
* Find the cache entry for a content
*
* \param c The content to get an entry for
* \return The image cache entry or NULL if not found.
*/ */
static struct image_cache_entry_s *image_cache__find(const struct content *c) static struct image_cache_entry_s *image_cache__find(const struct content *c)
{ {
@ -157,6 +176,11 @@ static struct image_cache_entry_s *image_cache__find(const struct content *c)
return found; return found;
} }
/**
* Update the image cache statistics with an entry.
*
* \param centry The image cache entry to update the stats with.
*/
static void image_cache_stats_bitmap_add(struct image_cache_entry_s *centry) static void image_cache_stats_bitmap_add(struct image_cache_entry_s *centry)
{ {
centry->bitmap_age = image_cache->current_age; centry->bitmap_age = image_cache->current_age;
@ -223,11 +247,20 @@ static void image_cache__unlink(struct image_cache_entry_s *centry)
} }
} }
/**
* free bitmap from an image cache entry
*
* \param centry The image cache entry to free bitmap from.
*/
static void image_cache__free_bitmap(struct image_cache_entry_s *centry) static void image_cache__free_bitmap(struct image_cache_entry_s *centry)
{ {
if (centry->bitmap != NULL) { if (centry->bitmap != NULL) {
#ifdef IMAGE_CACHE_VERBOSE #ifdef IMAGE_CACHE_VERBOSE
LOG("Freeing bitmap %p size %d age %d redraw count %d", centry->bitmap, centry->bitmap_size, image_cache->current_age - centry->bitmap_age, centry->redraw_count); LOG("Freeing bitmap %p size %d age %d redraw count %d",
centry->bitmap,
centry->bitmap_size,
image_cache->current_age - centry->bitmap_age,
centry->redraw_count);
#endif #endif
guit->bitmap->destroy(centry->bitmap); guit->bitmap->destroy(centry->bitmap);
centry->bitmap = NULL; centry->bitmap = NULL;
@ -240,7 +273,11 @@ static void image_cache__free_bitmap(struct image_cache_entry_s *centry)
} }
/* free cache entry */ /**
* free image cache entry
*
* \param centry The image cache entry to free.
*/
static void image_cache__free_entry(struct image_cache_entry_s *centry) static void image_cache__free_entry(struct image_cache_entry_s *centry)
{ {
#ifdef IMAGE_CACHE_VERBOSE #ifdef IMAGE_CACHE_VERBOSE
@ -258,7 +295,11 @@ static void image_cache__free_entry(struct image_cache_entry_s *centry)
free(centry); free(centry);
} }
/** Cache cleaner */ /**
* Image cache cleaner
*
* \param icache The image cache context.
*/
static void image_cache__clean(struct image_cache_s *icache) static void image_cache__clean(struct image_cache_s *icache)
{ {
struct image_cache_entry_s *centry = icache->entries; struct image_cache_entry_s *centry = icache->entries;
@ -277,7 +318,11 @@ static void image_cache__clean(struct image_cache_s *icache)
} }
} }
/** Cache background scheduled callback. */ /**
* Cache background scheduled callback.
*
* \param p The image cache context.
*/
static void image_cache__background_update(void *p) static void image_cache__background_update(void *p)
{ {
struct image_cache_s *icache = p; struct image_cache_s *icache = p;
@ -377,7 +422,7 @@ image_cache_init(const struct image_cache_parameters *image_cache_parameters)
image_cache__background_update, image_cache__background_update,
image_cache); image_cache);
LOG("Image cache initilised with a limit of %" PRIsizet " hysteresis of %"PRIsizet, LOG("Image cache initialised with a limit of %" PRIsizet " hysteresis of %"PRIsizet,
image_cache->params.limit, image_cache->params.hysteresis); image_cache->params.limit, image_cache->params.hysteresis);
return NSERROR_OK; return NSERROR_OK;
@ -678,7 +723,7 @@ int image_cache_snentryf(char *string, size_t size, unsigned int entryn,
case 'U': case 'U':
slen += snprintf(string + slen, size - slen, slen += snprintf(string + slen, size - slen,
"%s", nsurl_access(llcache_handle_get_url(centry->content->llcache))); "%s", nsurl_access(llcache_handle_get_url(centry->content->llcache)));
break; break;
case 'o': case 'o':
@ -690,20 +735,20 @@ int image_cache_snentryf(char *string, size_t size, unsigned int entryn,
centry->content-> centry->content->
llcache), llcache),
NSURL_HOST); NSURL_HOST);
slen += snprintf(string + slen, slen += snprintf(string + slen,
size - slen, "%s", size - slen, "%s",
lwc_string_data( lwc_string_data(
origin)); origin));
lwc_string_unref(origin); lwc_string_unref(origin);
} else { } else {
slen += snprintf(string + slen, slen += snprintf(string + slen,
size - slen, "%s", size - slen, "%s",
"localhost"); "localhost");
} }
break; break;
case 's': case 's':
if (centry->bitmap != NULL) { if (centry->bitmap != NULL) {
slen += snprintf(string + slen, slen += snprintf(string + slen,
@ -774,6 +819,7 @@ bool image_cache_redraw(struct content *c,
return image_bitmap_plot(centry->bitmap, data, clip, ctx); return image_bitmap_plot(centry->bitmap, data, clip, ctx);
} }
/* exported interface documented in image_cache.h */
void image_cache_destroy(struct content *content) void image_cache_destroy(struct content *content)
{ {
struct image_cache_entry_s *centry; struct image_cache_entry_s *centry;
@ -787,11 +833,13 @@ void image_cache_destroy(struct content *content)
} }
} }
/* exported interface documented in image_cache.h */
void *image_cache_get_internal(const struct content *c, void *context) void *image_cache_get_internal(const struct content *c, void *context)
{ {
return image_cache_get_bitmap(c); return image_cache_get_bitmap(c);
} }
/* exported interface documented in image_cache.h */
content_type image_cache_content_type(void) content_type image_cache_content_type(void)
{ {
return CONTENT_IMAGE; return CONTENT_IMAGE;