Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3584 sourcerer 1
/*
2
 * Copyright 2011 John-Mark Bell 
3
 *
4
 * This file is part of NetSurf, http://www.netsurf-browser.org/
5
 *
6
 * NetSurf is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; version 2 of the License.
9
 *
10
 * NetSurf is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see .
17
 */
18
 
19
/** \file
20
 * The image content handler intermediate image cache.
21
 *
22
 * This cache allows netsurf to use a generic intermediate bitmap
23
 * format without keeping the
24
 * intermediate representation in memory.
25
 *
26
 * The bitmap structure is opaque to the rest of netsurf and is
27
 * controlled by the platform-specific code (see image/bitmap.h for
28
 * detials). All image content handlers convert into this format and
29
 * pass it to the plot functions for display,
30
 *
31
 * This cache maintains a link between the underlying original content
32
 * and the intermediate representation. It is intended to be flexable
33
 * and either manage the bitmap plotting completely or give the image
34
 * content handler complete control.
35
 */
36
 
37
#ifndef NETSURF_IMAGE_IMAGE_CACHE_H_
38
#define NETSURF_IMAGE_IMAGE_CACHE_H_
39
 
40
#include "utils/errors.h"
41
#include "desktop/plotters.h"
42
#include "image/bitmap.h"
43
 
44
typedef struct bitmap * (image_cache_convert_fn) (struct content *content);
45
 
46
struct image_cache_parameters {
47
	/** How frequently the background cache clean process is run (ms) */
48
	unsigned int bg_clean_time;
49
 
50
	/** The target upper bound for the image cache size */
51
	size_t limit;
52
 
53
	/** The hysteresis allowed round the target size */
54
	size_t hysteresis;
55
 
56
	/** The speculative conversion "small" size */
57
	size_t speculative_small;
58
};
59
 
60
/** Initialise the image cache
61
 *
62
 * @param image_cache_parameters The control parameters for the image cache
63
 */
64
nserror image_cache_init(const struct image_cache_parameters *image_cache_parameters);
65
nserror image_cache_fini(void);
66
 
67
/** adds an image content to be cached.
68
 *
69
 * @param content The content handle used as a key
70
 * @param bitmap A bitmap representing the already converted content or NULL.
71
 * @param convert A function pointer to convert the content into a bitmap or NULL.
72
 * @return A netsurf error code.
73
 */
74
nserror image_cache_add(struct content *content,
75
			struct bitmap *bitmap,
76
			image_cache_convert_fn *convert);
77
 
78
nserror image_cache_remove(struct content *content);
79
 
80
 
81
/** Obtain a bitmap from a content converting from source if neccessary. */
82
struct bitmap *image_cache_get_bitmap(const struct content *c);
83
 
84
/** Obtain a bitmap from a content with no conversion */
85
struct bitmap *image_cache_find_bitmap(struct content *c);
86
 
87
/** Decide if a content should be speculatively converted.
88
 *
89
 * This allows for image content handlers to ask the cache if a bitmap
90
 * should be generated before it is added to the cache. This is the
91
 * same decision logic used to decide to perform an immediate
92
 * conversion when a content is initially added to the cache.
93
 *
94
 * @param c The content to be considered.
95
 * @return true if a speculative conversion is desired false otehrwise.
96
 */
97
bool image_cache_speculate(struct content *c);
98
 
99
/**
100
 * Fill a buffer with information about a cache entry using a format.
101
 *
102
 * The format string is copied into the output buffer with the
103
 * following replaced:
104
 * %e - The entry number
105
 * %k - The content key
106
 * %r - The number of redraws of this bitmap
107
 * %c - The number of times this bitmap has been converted
108
 * %s - The size of the current bitmap allocation
109
 *
110
 * \param string  The buffer in which to place the results.
111
 * \param size    The size of the string buffer.
112
 * \param entryn  The opaque entry number.
113
 * \param fmt     The format string.
114
 * \return The number of bytes written to \a string or -1 on error
115
 */
116
int image_cache_snentryf(char *string, size_t size, unsigned int entryn,
117
			 const char *fmt);
118
 
119
/**
120
 * Fill a buffer with information about the image cache using a format.
121
 *
122
 * The format string is copied into the output buffer with the
123
 * following replaced:
124
 *
125
 * a Configured cache limit size
126
 * b Configured cache hysteresis size
127
 * c Current caches total consumed size
128
 * d Number of images currently in the cache
129
 * e The age of the cache
130
 * f The largest amount of space the cache has occupied since initialisation
131
 * g The number of objetcs when the cache was at its largest
132
 * h The largest number of images in the cache since initialisation
133
 * i The size of the cache when the largest number of objects occoured
134
 * j The total number of read operations performed on the cache
135
 * k The total number of read operations satisfied from the cache without
136
 *     conversion.
137
 * l The total number of read operations satisfied from the cache which
138
 *     required a conversion.
139
 * m The total number of read operations which could not be sucessfully
140
 *     returned. ie. not available in cache and conversion failed.
141
 * n The total size  of read operations performed on the cache
142
 * o The total size of read operations satisfied from the cache without
143
 *     conversion.
144
 * q The total size of read operations satisfied from the cache which
145
 *     required a conversion.
146
 * r The total size of read operations which could not be sucessfully
147
 *     returned. ie. not available in cache and conversion failed.
148
 * s The number of images which were placed in the cache but never read.
149
 * t The number of images that were converted on insertion into teh cache which were subsequently never used.
150
 * u The number of times an image was converted after the first
151
 * v The number of images that had extra conversions performed.
152
 * w Size of the image that was converted (read missed cache) highest number
153
 *     of times.
154
 * x The number of times the image that was converted (read missed cache)
155
 *     highest number of times.
156
 *
157
 * format modifiers:
158
 * A p before the value modifies the replacement to be a percentage.
159
 *
160
 *
161
 * \param string  The buffer in which to place the results.
162
 * \param size    The size of the string buffer.
163
 * \param fmt     The format string.
164
 * \return The number of bytes written to \a string or -1 on error
165
 */
166
 
167
int image_cache_snsummaryf(char *string, size_t size, const char *fmt);
168
 
169
/********* Image content handler generic cache callbacks ************/
170
 
171
/** Generic content redraw callback
172
 *
173
 * May be used by image content handlers as their redraw
174
 * callback. Performs all neccissary cache lookups and conversions and
175
 * calls the bitmap plot function in the redraw context.
176
 */
177
bool image_cache_redraw(struct content *c,
178
			struct content_redraw_data *data,
179
			const struct rect *clip,
180
			const struct redraw_context *ctx);
181
 
182
void image_cache_destroy(struct content *c);
183
 
184
void *image_cache_get_internal(const struct content *c, void *context);
185
 
186
content_type image_cache_content_type(void);
187
 
188
#endif