diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-15 00:43:54 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-15 00:43:54 +0000 |
commit | ba4cca2c65677aeffb088117169abbc12ebec3fc (patch) | |
tree | 08379a140cd14f2164114d43a722fabf111a0fff | |
parent | 313e8f82816c839b3de47e1137a91414bb95a327 (diff) | |
download | mupdf-ba4cca2c65677aeffb088117169abbc12ebec3fc.tar.xz |
Remove 'soft limit' on pixmaps in favour of fz_store.
Change the fz_store to be limited to 256 Megs. Remove the soft limit
for pixmaps; the store will automatically throw old resources away
to stay below the limit.
-rw-r--r-- | apps/pdfclean.c | 2 | ||||
-rw-r--r-- | apps/pdfdraw.c | 2 | ||||
-rw-r--r-- | apps/pdfextract.c | 2 | ||||
-rw-r--r-- | apps/pdfshow.c | 2 | ||||
-rw-r--r-- | apps/win_main.c | 2 | ||||
-rw-r--r-- | apps/xpsdraw.c | 2 | ||||
-rw-r--r-- | fitz/base_context.c | 3 | ||||
-rw-r--r-- | fitz/filt_jpxd.c | 7 | ||||
-rw-r--r-- | fitz/fitz.h | 3 | ||||
-rw-r--r-- | fitz/res_pixmap.c | 21 | ||||
-rw-r--r-- | pdf/pdf_image.c | 7 | ||||
-rw-r--r-- | xps/xps_jpeg.c | 7 | ||||
-rw-r--r-- | xps/xps_png.c | 7 | ||||
-rw-r--r-- | xps/xps_tiff.c | 7 |
14 files changed, 34 insertions, 40 deletions
diff --git a/apps/pdfclean.c b/apps/pdfclean.c index e8c27359..37381306 100644 --- a/apps/pdfclean.c +++ b/apps/pdfclean.c @@ -767,7 +767,7 @@ int main(int argc, char **argv) if (argc - fz_optind > 0) subset = 1; - ctx = fz_new_context(&fz_alloc_default, FZ_STORE_UNLIMITED); + ctx = fz_new_context(&fz_alloc_default, 256<<20); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index af1d5ad7..f7867bf0 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -362,7 +362,7 @@ int main(int argc, char **argv) if (accelerate) fz_accelerate(); - ctx = fz_new_context(&fz_alloc_default, FZ_STORE_UNLIMITED); + ctx = fz_new_context(&fz_alloc_default, 256<<20); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); diff --git a/apps/pdfextract.c b/apps/pdfextract.c index 590bf13f..5b1fca0b 100644 --- a/apps/pdfextract.c +++ b/apps/pdfextract.c @@ -178,7 +178,7 @@ int main(int argc, char **argv) infile = argv[fz_optind++]; - ctx = fz_new_context(&fz_alloc_default, FZ_STORE_UNLIMITED); + ctx = fz_new_context(&fz_alloc_default, 256<<20); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); diff --git a/apps/pdfshow.c b/apps/pdfshow.c index 0c3feaf2..3f142264 100644 --- a/apps/pdfshow.c +++ b/apps/pdfshow.c @@ -189,7 +189,7 @@ int main(int argc, char **argv) filename = argv[fz_optind++]; - ctx = fz_new_context(&fz_alloc_default, FZ_STORE_UNLIMITED); + ctx = fz_new_context(&fz_alloc_default, 256<<20); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); diff --git a/apps/win_main.c b/apps/win_main.c index 0af83aec..7223f4e6 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -831,7 +831,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow fz_accelerate(); - ctx = fz_new_context(&fz_alloc_default, FZ_STORE_UNLIMITED); + ctx = fz_new_context(&fz_alloc_default, 256<<20); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c index f583057e..f8828f7e 100644 --- a/apps/xpsdraw.c +++ b/apps/xpsdraw.c @@ -314,7 +314,7 @@ int main(int argc, char **argv) if (accelerate) fz_accelerate(); - ctx = fz_new_context(&fz_alloc_default, FZ_STORE_UNLIMITED); + ctx = fz_new_context(&fz_alloc_default, 256<<20); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); diff --git a/fitz/base_context.c b/fitz/base_context.c index e722aa1d..ee92904b 100644 --- a/fitz/base_context.c +++ b/fitz/base_context.c @@ -76,5 +76,6 @@ cleanup: fz_context * fz_clone_context(fz_context *ctx) { - return fz_new_context(ctx->alloc, FZ_STORE_UNLIMITED); + /* FIXME: Should be sharing store */ + return fz_new_context(ctx->alloc, 256<<20); } diff --git a/fitz/filt_jpxd.c b/fitz/filt_jpxd.c index 64197a08..3075847b 100644 --- a/fitz/filt_jpxd.c +++ b/fitz/filt_jpxd.c @@ -111,8 +111,11 @@ fz_load_jpx_image(fz_context *ctx, unsigned char *data, int size, fz_colorspace } } - img = fz_new_pixmap_with_limit(ctx, colorspace, w, h); - if (!img) + fz_try(ctx) + { + img = fz_new_pixmap(ctx, colorspace, w, h); + } + fz_catch(ctx) { opj_image_destroy(jpx); fz_throw(ctx, "out of memory"); diff --git a/fitz/fitz.h b/fitz/fitz.h index ebbd176c..94a3eea2 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -696,9 +696,6 @@ struct fz_pixmap_s int free_samples; }; -/* will return NULL if soft limit is exceeded */ -fz_pixmap *fz_new_pixmap_with_limit(fz_context *ctx, fz_colorspace *colorspace, int w, int h); - fz_pixmap *fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h, unsigned char *samples); fz_pixmap *fz_new_pixmap_with_rect(fz_context *ctx, fz_colorspace *, fz_bbox bbox); fz_pixmap *fz_new_pixmap_with_rect_and_data(fz_context *ctx, fz_colorspace *, fz_bbox bbox, unsigned char *samples); diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index c8ae7540..0f6e192d 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -1,8 +1,5 @@ #include "fitz.h" -static int fz_memory_limit = 256 << 20; -static int fz_memory_used = 0; - fz_pixmap * fz_keep_pixmap(fz_pixmap *pix) { @@ -18,7 +15,6 @@ fz_drop_pixmap(fz_context *ctx, fz_pixmap *pix) void fz_free_pixmap_imp(fz_context *ctx, fz_pixmap *pix) { - fz_memory_used -= pix->w * pix->h * pix->n; if (pix->mask) fz_drop_pixmap(ctx, pix->mask); if (pix->colorspace) @@ -59,7 +55,6 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h } else { - fz_memory_used += pix->w * pix->h * pix->n; pix->samples = fz_malloc_array(ctx, pix->h, pix->w * pix->n); pix->free_samples = 1; } @@ -68,20 +63,6 @@ fz_new_pixmap_with_data(fz_context *ctx, fz_colorspace *colorspace, int w, int h } fz_pixmap * -fz_new_pixmap_with_limit(fz_context *ctx, fz_colorspace *colorspace, int w, int h) -{ - int n = colorspace ? colorspace->n + 1 : 1; - int size = w * h * n; - if (fz_memory_used + size > fz_memory_limit) - { - fz_warn(ctx, "pixmap memory exceeds soft limit %dM + %dM > %dM", - fz_memory_used/(1<<20), size/(1<<20), fz_memory_limit/(1<<20)); - return NULL; - } - return fz_new_pixmap_with_data(ctx, colorspace, w, h, NULL); -} - -fz_pixmap * fz_new_pixmap(fz_context *ctx, fz_colorspace *colorspace, int w, int h) { return fz_new_pixmap_with_data(ctx, colorspace, w, h, NULL); @@ -541,5 +522,5 @@ fz_pixmap_size(fz_pixmap * pix) { if (pix == NULL) return 0; - return sizeof(*pix) + pix->n * pix->x * pix->y; + return sizeof(*pix) + pix->n * pix->w * pix->h; } diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index 4266ded3..ead5c365 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -160,8 +160,11 @@ pdf_load_image_imp(pdf_xref *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cstm, i } /* Allocate now, to fail early if we run out of memory */ - tile = fz_new_pixmap_with_limit(ctx, colorspace, w, h); - if (!tile) + fz_try(ctx) + { + tile = fz_new_pixmap(ctx, colorspace, w, h); + } + fz_catch(ctx) { fz_throw(ctx, "out of memory"); } diff --git a/xps/xps_jpeg.c b/xps/xps_jpeg.c index 381baffd..4e937a31 100644 --- a/xps/xps_jpeg.c +++ b/xps/xps_jpeg.c @@ -94,8 +94,11 @@ xps_decode_jpeg(fz_context *ctx, byte *rbuf, int rlen) else fz_throw(ctx, "bad number of components in jpeg: %d", cinfo.output_components); - image = fz_new_pixmap_with_limit(ctx, colorspace, cinfo.output_width, cinfo.output_height); - if (!image) + fz_try(ctx) + { + image = fz_new_pixmap(ctx, colorspace, cinfo.output_width, cinfo.output_height); + } + fz_catch(ctx) { jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); diff --git a/xps/xps_png.c b/xps/xps_png.c index a396b433..719e522f 100644 --- a/xps/xps_png.c +++ b/xps/xps_png.c @@ -516,8 +516,11 @@ xps_decode_png(fz_context *ctx, byte *p, int total) stride = (png.width * png.n * png.depth + 7) / 8; - image = fz_new_pixmap_with_limit(ctx, colorspace, png.width, png.height); - if (!image) + fz_try(ctx) + { + image = fz_new_pixmap(ctx, colorspace, png.width, png.height); + } + fz_catch(ctx) { fz_free(png.ctx, png.samples); fz_throw(ctx, "out of memory"); diff --git a/xps/xps_tiff.c b/xps/xps_tiff.c index 38430710..01e5be9b 100644 --- a/xps/xps_tiff.c +++ b/xps/xps_tiff.c @@ -782,8 +782,11 @@ xps_decode_tiff(fz_context *ctx, byte *buf, int len) /* Expand into fz_pixmap struct */ - image = fz_new_pixmap_with_limit(tiff.ctx, tiff.colorspace, tiff.imagewidth, tiff.imagelength); - if (!image) + fz_try(ctx) + { + image = fz_new_pixmap(tiff.ctx, tiff.colorspace, tiff.imagewidth, tiff.imagelength); + } + fz_catch(ctx) { if (tiff.colormap) fz_free(ctx, tiff.colormap); if (tiff.stripoffsets) fz_free(ctx, tiff.stripoffsets); |