summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-01-18 15:49:09 +0000
committerRobin Watts <robin.watts@artifex.com>2012-01-19 12:40:24 +0000
commit40f4ed22806b88ba0e26c458915d4695f1f7c201 (patch)
treebacdebee1932d294f8233a8fb14cb86383e5f107 /pdf
parent2c836b57d5295b47655988cf8deaffda731e1c3c (diff)
downloadmupdf-40f4ed22806b88ba0e26c458915d4695f1f7c201.tar.xz
Multi-threading support for MuPDF
When we moved over to a context based system, we laid the foundation for a thread-safe mupdf. This commit should complete that process. Firstly, fz_clone_context is properly implemented so that it makes a new context, but shares certain sections (currently just the allocator, and the store). Secondly, we add locking (to parts of the code that have previously just had placeholder LOCK/UNLOCK comments). Functions to lock and unlock a mutex are added to the allocator structure; omit these (as is the case today) and no multithreading is (safely) possible. The context will refuse to clone if these are not provided. Finally we flesh out the LOCK/UNLOCK comments to be real calls of the functions - unfortunately this requires us to plumb fz_context into the fz_keep_storable function (and all the fz_keep_xxx functions that call it). This is the largest section of the patch. No changes expected to any test files.
Diffstat (limited to 'pdf')
-rw-r--r--pdf/mupdf.h10
-rw-r--r--pdf/pdf_cmap.c6
-rw-r--r--pdf/pdf_colorspace.c2
-rw-r--r--pdf/pdf_font.c4
-rw-r--r--pdf/pdf_function.c4
-rw-r--r--pdf/pdf_interpret.c48
-rw-r--r--pdf/pdf_pattern.c4
-rw-r--r--pdf/pdf_xobject.c4
8 files changed, 41 insertions, 41 deletions
diff --git a/pdf/mupdf.h b/pdf/mupdf.h
index 0e21f930..b1b2a7e1 100644
--- a/pdf/mupdf.h
+++ b/pdf/mupdf.h
@@ -159,7 +159,7 @@ typedef struct pdf_function_s pdf_function;
pdf_function *pdf_load_function(pdf_xref *xref, fz_obj *ref);
void pdf_eval_function(fz_context *ctx, pdf_function *func, float *in, int inlen, float *out, int outlen);
-pdf_function *pdf_keep_function(pdf_function *func);
+pdf_function *pdf_keep_function(fz_context *ctx, pdf_function *func);
void pdf_drop_function(fz_context *ctx, pdf_function *func);
unsigned int pdf_function_size(pdf_function *func);
@@ -191,7 +191,7 @@ struct pdf_pattern_s
};
pdf_pattern *pdf_load_pattern(pdf_xref *xref, fz_obj *obj);
-pdf_pattern *pdf_keep_pattern(pdf_pattern *pat);
+pdf_pattern *pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat);
void pdf_drop_pattern(fz_context *ctx, pdf_pattern *pat);
/*
@@ -215,7 +215,7 @@ struct pdf_xobject_s
};
pdf_xobject *pdf_load_xobject(pdf_xref *xref, fz_obj *obj);
-pdf_xobject *pdf_keep_xobject(pdf_xobject *xobj);
+pdf_xobject *pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj);
void pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj);
/*
@@ -263,7 +263,7 @@ struct pdf_cmap_s
};
pdf_cmap *pdf_new_cmap(fz_context *ctx);
-pdf_cmap *pdf_keep_cmap(pdf_cmap *cmap);
+pdf_cmap *pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap);
void pdf_drop_cmap(fz_context *ctx, pdf_cmap *cmap);
void pdf_free_cmap_imp(fz_context *ctx, fz_storable *cmap);
unsigned int pdf_cmap_size(pdf_cmap *cmap);
@@ -401,7 +401,7 @@ pdf_font_desc *pdf_load_type3_font(pdf_xref *xref, fz_obj *rdb, fz_obj *obj);
pdf_font_desc *pdf_load_font(pdf_xref *xref, fz_obj *rdb, fz_obj *obj);
pdf_font_desc *pdf_new_font_desc(fz_context *ctx);
-pdf_font_desc *pdf_keep_font(pdf_font_desc *fontdesc);
+pdf_font_desc *pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc);
void pdf_drop_font(fz_context *ctx, pdf_font_desc *font);
void pdf_debug_font(pdf_font_desc *fontdesc);
diff --git a/pdf/pdf_cmap.c b/pdf/pdf_cmap.c
index bb1c1ea0..4430979c 100644
--- a/pdf/pdf_cmap.c
+++ b/pdf/pdf_cmap.c
@@ -68,9 +68,9 @@ pdf_new_cmap(fz_context *ctx)
/* Could be a macro for speed */
pdf_cmap *
-pdf_keep_cmap(pdf_cmap *cmap)
+pdf_keep_cmap(fz_context *ctx, pdf_cmap *cmap)
{
- return (pdf_cmap *)fz_keep_storable(&cmap->storable);
+ return (pdf_cmap *)fz_keep_storable(ctx, &cmap->storable);
}
/* Could be a macro for speed */
@@ -87,7 +87,7 @@ pdf_set_usecmap(fz_context *ctx, pdf_cmap *cmap, pdf_cmap *usecmap)
if (cmap->usecmap)
pdf_drop_cmap(ctx, cmap->usecmap);
- cmap->usecmap = pdf_keep_cmap(usecmap);
+ cmap->usecmap = pdf_keep_cmap(ctx, usecmap);
if (cmap->codespace_len == 0)
{
diff --git a/pdf/pdf_colorspace.c b/pdf/pdf_colorspace.c
index b2f42b8f..b7f9f131 100644
--- a/pdf/pdf_colorspace.c
+++ b/pdf/pdf_colorspace.c
@@ -211,7 +211,7 @@ pdf_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src)
}
if (src->mask)
- dst->mask = fz_keep_pixmap(src->mask);
+ dst->mask = fz_keep_pixmap(ctx, src->mask);
dst->interpolate = src->interpolate;
return dst;
diff --git a/pdf/pdf_font.c b/pdf/pdf_font.c
index d0a7241d..b6c59153 100644
--- a/pdf/pdf_font.c
+++ b/pdf/pdf_font.c
@@ -304,9 +304,9 @@ pdf_load_embedded_font(pdf_font_desc *fontdesc, pdf_xref *xref, fz_obj *stmref)
*/
pdf_font_desc *
-pdf_keep_font(pdf_font_desc *fontdesc)
+pdf_keep_font(fz_context *ctx, pdf_font_desc *fontdesc)
{
- return (pdf_font_desc *)fz_keep_storable(&fontdesc->storable);
+ return (pdf_font_desc *)fz_keep_storable(ctx, &fontdesc->storable);
}
void
diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c
index 5cc4524e..61682ac2 100644
--- a/pdf/pdf_function.c
+++ b/pdf/pdf_function.c
@@ -1295,9 +1295,9 @@ eval_stitching_func(fz_context *ctx, pdf_function *func, float in, float *out)
*/
pdf_function *
-pdf_keep_function(pdf_function *func)
+pdf_keep_function(fz_context *ctx, pdf_function *func)
{
- return (pdf_function *)fz_keep_storable(&func->storable);
+ return (pdf_function *)fz_keep_storable(ctx, &func->storable);
}
void
diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c
index 7bb2da9c..d42684c0 100644
--- a/pdf/pdf_interpret.c
+++ b/pdf/pdf_interpret.c
@@ -867,14 +867,14 @@ pdf_init_gstate(pdf_gstate *gs, fz_matrix ctm)
memset(gs->stroke_state.dash_list, 0, sizeof(gs->stroke_state.dash_list));
gs->stroke.kind = PDF_MAT_COLOR;
- gs->stroke.colorspace = fz_keep_colorspace(fz_device_gray);
+ gs->stroke.colorspace = fz_device_gray; /* No fz_keep_colorspace as static */
gs->stroke.v[0] = 0;
gs->stroke.pattern = NULL;
gs->stroke.shade = NULL;
gs->stroke.alpha = 1;
gs->fill.kind = PDF_MAT_COLOR;
- gs->fill.colorspace = fz_keep_colorspace(fz_device_gray);
+ gs->fill.colorspace = fz_device_gray; /* No fz_keep_colorspace as static */
gs->fill.v[0] = 0;
gs->fill.pattern = NULL;
gs->fill.shade = NULL;
@@ -896,14 +896,14 @@ pdf_init_gstate(pdf_gstate *gs, fz_matrix ctm)
}
static pdf_material *
-pdf_keep_material(pdf_material *mat)
+pdf_keep_material(fz_context *ctx, pdf_material *mat)
{
if (mat->colorspace)
- fz_keep_colorspace(mat->colorspace);
+ fz_keep_colorspace(ctx, mat->colorspace);
if (mat->pattern)
- pdf_keep_pattern(mat->pattern);
+ pdf_keep_pattern(ctx, mat->pattern);
if (mat->shade)
- fz_keep_shade(mat->shade);
+ fz_keep_shade(ctx, mat->shade);
return mat;
}
@@ -920,19 +920,19 @@ pdf_drop_material(fz_context *ctx, pdf_material *mat)
}
static void
-copy_state(pdf_gstate *gs, pdf_gstate *old)
+copy_state(fz_context *ctx, pdf_gstate *gs, pdf_gstate *old)
{
gs->stroke = old->stroke;
gs->fill = old->fill;
gs->font = old->font;
gs->softmask = old->softmask;
- pdf_keep_material(&gs->stroke);
- pdf_keep_material(&gs->fill);
+ pdf_keep_material(ctx, &gs->stroke);
+ pdf_keep_material(ctx, &gs->fill);
if (gs->font)
- pdf_keep_font(gs->font);
+ pdf_keep_font(ctx, gs->font);
if (gs->softmask)
- pdf_keep_xobject(gs->softmask);
+ pdf_keep_xobject(ctx, gs->softmask);
}
@@ -975,7 +975,7 @@ pdf_new_csi(pdf_xref *xref, fz_device *dev, fz_matrix ctm, char *event, fz_cooki
csi->top_ctm = ctm;
pdf_init_gstate(&csi->gstate[0], ctm);
if (gstate)
- copy_state(&csi->gstate[0], gstate);
+ copy_state(ctx, &csi->gstate[0], gstate);
csi->gtop = 0;
csi->cookie = cookie;
@@ -1023,12 +1023,12 @@ pdf_gsave(pdf_csi *csi)
csi->gtop++;
gs = &csi->gstate[csi->gtop];
- pdf_keep_material(&gs->stroke);
- pdf_keep_material(&gs->fill);
+ pdf_keep_material(ctx, &gs->stroke);
+ pdf_keep_material(ctx, &gs->fill);
if (gs->font)
- pdf_keep_font(gs->font);
+ pdf_keep_font(ctx, gs->font);
if (gs->softmask)
- pdf_keep_xobject(gs->softmask);
+ pdf_keep_xobject(ctx, gs->softmask);
}
static void
@@ -1114,7 +1114,7 @@ pdf_set_colorspace(pdf_csi *csi, int what, fz_colorspace *colorspace)
fz_drop_colorspace(ctx, mat->colorspace);
mat->kind = PDF_MAT_COLOR;
- mat->colorspace = fz_keep_colorspace(colorspace);
+ mat->colorspace = fz_keep_colorspace(ctx, colorspace);
mat->v[0] = 0;
mat->v[1] = 0;
@@ -1167,7 +1167,7 @@ pdf_set_shade(pdf_csi *csi, int what, fz_shade *shade)
fz_drop_shade(ctx, mat->shade);
mat->kind = PDF_MAT_SHADE;
- mat->shade = fz_keep_shade(shade);
+ mat->shade = fz_keep_shade(ctx, shade);
}
static void
@@ -1186,7 +1186,7 @@ pdf_set_pattern(pdf_csi *csi, int what, pdf_pattern *pat, float *v)
mat->kind = PDF_MAT_PATTERN;
if (pat)
- mat->pattern = pdf_keep_pattern(pat);
+ mat->pattern = pdf_keep_pattern(ctx, pat);
else
mat->pattern = NULL;
@@ -1234,13 +1234,13 @@ pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, fz_rect area, int what)
if (what == PDF_FILL)
{
pdf_drop_material(ctx, &gstate->stroke);
- pdf_keep_material(&gstate->fill);
+ pdf_keep_material(ctx, &gstate->fill);
gstate->stroke = gstate->fill;
}
if (what == PDF_STROKE)
{
pdf_drop_material(ctx, &gstate->fill);
- pdf_keep_material(&gstate->stroke);
+ pdf_keep_material(ctx, &gstate->stroke);
gstate->fill = gstate->stroke;
}
}
@@ -1695,11 +1695,11 @@ static void pdf_run_cs_imp(pdf_csi *csi, fz_obj *rdb, int what)
else
{
if (!strcmp(csi->name, "DeviceGray"))
- colorspace = fz_keep_colorspace(fz_device_gray);
+ colorspace = fz_device_gray; /* No fz_keep_colorspace as static */
else if (!strcmp(csi->name, "DeviceRGB"))
- colorspace = fz_keep_colorspace(fz_device_rgb);
+ colorspace = fz_device_rgb; /* No fz_keep_colorspace as static */
else if (!strcmp(csi->name, "DeviceCMYK"))
- colorspace = fz_keep_colorspace(fz_device_cmyk);
+ colorspace = fz_device_cmyk; /* No fz_keep_colorspace as static */
else
{
dict = fz_dict_gets(rdb, "ColorSpace");
diff --git a/pdf/pdf_pattern.c b/pdf/pdf_pattern.c
index 1fc356c7..2b4d32a2 100644
--- a/pdf/pdf_pattern.c
+++ b/pdf/pdf_pattern.c
@@ -2,9 +2,9 @@
#include "mupdf.h"
pdf_pattern *
-pdf_keep_pattern(pdf_pattern *pat)
+pdf_keep_pattern(fz_context *ctx, pdf_pattern *pat)
{
- return (pdf_pattern *)fz_keep_storable(&pat->storable);
+ return (pdf_pattern *)fz_keep_storable(ctx, &pat->storable);
}
void
diff --git a/pdf/pdf_xobject.c b/pdf/pdf_xobject.c
index 61daf9a4..e33ac858 100644
--- a/pdf/pdf_xobject.c
+++ b/pdf/pdf_xobject.c
@@ -2,9 +2,9 @@
#include "mupdf.h"
pdf_xobject *
-pdf_keep_xobject(pdf_xobject *xobj)
+pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj)
{
- return (pdf_xobject *)fz_keep_storable(&xobj->storable);
+ return (pdf_xobject *)fz_keep_storable(ctx, &xobj->storable);
}
void