summaryrefslogtreecommitdiff
path: root/pdf/pdf_interpret.c
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/pdf_interpret.c
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/pdf_interpret.c')
-rw-r--r--pdf/pdf_interpret.c48
1 files changed, 24 insertions, 24 deletions
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");