summaryrefslogtreecommitdiff
path: root/fitz/fitz.h
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-12-14 19:08:56 +0000
committerRobin Watts <robin.watts@artifex.com>2011-12-15 00:43:24 +0000
commit313e8f82816c839b3de47e1137a91414bb95a327 (patch)
treef680cd6ebc26e51dab5cd0b9a5337ce49197f6ac /fitz/fitz.h
parent09c8ebeea83f11ccac07bad76e516460e2c8e0f7 (diff)
downloadmupdf-313e8f82816c839b3de47e1137a91414bb95a327.tar.xz
Rework pdf_store to fz_store, a part of fz_context.
Firstly, we rename pdf_store to fz_store, reflecting the fact that there are no pdf specific dependencies on it. Next, we rework it so that all the objects that can be stored in the store start with an fz_storable structure. This consists of a reference count, and a function used to free the object when the reference count reaches zero. All the keep/drop functions are then reimplemented by calling fz_keep_sharable/fz_drop_sharable. The 'drop' functions as supplied by the callers are thus now 'free' functions, only called if the reference count drops to 0. The store changes to keep all the items in the store in the linked list (which becomes a doubly linked one). We still make use of the hashtable to index into this list quickly, but we now have the objects in an LRU ordering within the list. Every object is put into the store, with a size record; this is an estimate of how much memory would be freed by freeing that object. The store is moved into the context and given a maximum size; when new things are inserted into the store, care is taken to ensure that we do not expand beyond this size. We evict any stored items (that are not in use) starting from the least recently used. Finding an object in the store now takes a reference to it already. LOCK and UNLOCK comments are used to indicate where locks need to be taken and released to ensure thread safety.
Diffstat (limited to 'fitz/fitz.h')
-rw-r--r--fitz/fitz.h51
1 files changed, 47 insertions, 4 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 8d523e3f..ebbd176c 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -100,6 +100,7 @@ typedef struct fz_error_context_s fz_error_context;
typedef struct fz_warn_context_s fz_warn_context;
typedef struct fz_font_context_s fz_font_context;
typedef struct fz_aa_context_s fz_aa_context;
+typedef struct fz_store_s fz_store;
typedef struct fz_context_s fz_context;
struct fz_alloc_context_s
@@ -156,9 +157,10 @@ struct fz_context_s
fz_warn_context *warn;
fz_font_context *font;
fz_aa_context *aa;
+ fz_store *store;
};
-fz_context *fz_new_context(fz_alloc_context *alloc);
+fz_context *fz_new_context(fz_alloc_context *alloc, unsigned int max_store);
fz_context *fz_clone_context(fz_context *ctx);
void fz_free_context(fz_context *ctx);
@@ -490,6 +492,42 @@ void fz_resize_buffer(fz_context *ctx, fz_buffer *buf, int size);
void fz_grow_buffer(fz_context *ctx, fz_buffer *buf);
/*
+ * Resource store
+ */
+
+typedef struct fz_storable_s fz_storable;
+
+typedef struct fz_item_s fz_item;
+
+typedef void (fz_store_free_fn)(fz_context *, void *);
+
+struct fz_storable_s {
+ int refs;
+ fz_store_free_fn *free;
+};
+
+#define FZ_INIT_STORABLE(S_,RC,FREE) \
+ do { fz_storable *S = &(S_)->storable; S->refs = (RC); \
+ S->free = (FREE); \
+ } while (0)
+
+enum {
+ FZ_STORE_UNLIMITED = 0
+};
+
+void fz_new_store_context(fz_context *ctx, unsigned int max);
+void fz_free_store_context(fz_context *ctx);
+void fz_debug_store(fz_context *ctx);
+
+void *fz_keep_storable(fz_storable *);
+void fz_drop_storable(fz_context *, fz_storable *);
+
+void fz_store_item(fz_context *ctx, fz_obj *key, void *val, unsigned int itemsize);
+void *fz_find_item(fz_context *ctx, fz_store_free_fn *freefn, fz_obj *key);
+void fz_remove_item(fz_context *ctx, fz_store_free_fn *freefn, fz_obj *key);
+void fz_age_store(fz_context *ctx, int maxage);
+
+/*
* Buffered reader.
* Only the data between rp and wp is valid data.
*/
@@ -648,7 +686,7 @@ typedef struct fz_colorspace_s fz_colorspace;
struct fz_pixmap_s
{
- int refs;
+ fz_storable storable;
int x, y, w, h, n;
fz_pixmap *mask; /* explicit soft/image mask */
int interpolate;
@@ -667,6 +705,7 @@ fz_pixmap *fz_new_pixmap_with_rect_and_data(fz_context *ctx, fz_colorspace *, fz
fz_pixmap *fz_new_pixmap(fz_context *ctx, fz_colorspace *, int w, int h);
fz_pixmap *fz_keep_pixmap(fz_pixmap *pix);
void fz_drop_pixmap(fz_context *ctx, fz_pixmap *pix);
+void fz_free_pixmap_imp(fz_context *ctx, void *pix);
void fz_clear_pixmap(fz_pixmap *pix);
void fz_clear_pixmap_with_color(fz_pixmap *pix, int value);
void fz_clear_pixmap_rect_with_color(fz_pixmap *pix, int value, fz_bbox r);
@@ -677,6 +716,7 @@ fz_pixmap *fz_alpha_from_gray(fz_context *ctx, fz_pixmap *gray, int luminosity);
fz_bbox fz_bound_pixmap(fz_pixmap *pix);
void fz_invert_pixmap(fz_pixmap *pix);
void fz_gamma_pixmap(fz_pixmap *pix, float gamma);
+unsigned int fz_pixmap_size(fz_pixmap *pix);
fz_pixmap *fz_scale_pixmap(fz_context *ctx, fz_pixmap *src, float x, float y, float w, float h);
@@ -740,7 +780,8 @@ extern fz_colorspace *fz_device_cmyk;
struct fz_colorspace_s
{
- int refs;
+ fz_storable storable;
+ unsigned int size;
char name[16];
int n;
void (*to_rgb)(fz_context *ctx, fz_colorspace *, float *src, float *rgb);
@@ -752,6 +793,7 @@ struct fz_colorspace_s
fz_colorspace *fz_new_colorspace(fz_context *ctx, char *name, int n);
fz_colorspace *fz_keep_colorspace(fz_colorspace *colorspace);
void fz_drop_colorspace(fz_context *ctx, fz_colorspace *colorspace);
+void fz_free_colorspace_imp(fz_context *ctx, void *colorspace);
void fz_convert_color(fz_context *ctx, fz_colorspace *srcs, float *srcv, fz_colorspace *dsts, float *dstv);
void fz_convert_pixmap(fz_context *ctx, fz_pixmap *src, fz_pixmap *dst);
@@ -928,7 +970,7 @@ typedef struct fz_shade_s fz_shade;
struct fz_shade_s
{
- int refs;
+ fz_storable storable;
fz_rect bbox; /* can be fz_infinite_rect */
fz_colorspace *colorspace;
@@ -950,6 +992,7 @@ struct fz_shade_s
fz_shade *fz_keep_shade(fz_shade *shade);
void fz_drop_shade(fz_context *ctx, fz_shade *shade);
+void fz_free_shade_imp(fz_context *ctx, void *shade);
void fz_debug_shade(fz_shade *shade);
fz_rect fz_bound_shade(fz_shade *shade, fz_matrix ctm);