diff options
author | Robin Watts <robin.watts@artifex.com> | 2014-01-03 16:51:31 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2014-03-04 13:43:01 +0000 |
commit | 67cdce34a5aeaeae15cbb7228184eecf89ddbe27 (patch) | |
tree | 6e92827161eba8556f737a594753254e12e558ed /source/pdf/pdf-run.c | |
parent | 67aba4046c0d54b03b5f97e0952316eff98c1c2f (diff) | |
download | mupdf-67cdce34a5aeaeae15cbb7228184eecf89ddbe27.tar.xz |
Bug 691691: Add way of clearing cached objects out of the xref.
We add various facilities here, intended to allow us to efficiently
minimise the memory we use for holding cached pdf objects.
Firstly, we add the ability to 'mark' all the currently loaded objects.
Next we add the ability to 'clear the xref' - to drop all the currently
loaded objects that have no other references except the ones held by the
xref table itself.
Finally, we add the ability to 'clear the xref to the last mark' - to
drop all the currently loaded objects that have been created since the
last 'mark' operation and have no other references except the ones held
by the xref table.
We expose this to the user by adding a new device hint 'FZ_NO_CACHE'.
If set on the device, then the PDF interpreter will pdf_mark_xref before
starting and pdf_clear_xref_to_mark afterwards. Thus no additional
objects will be retained in memory after a given page is run, unless
someone else picks them up and takes a reference to them as part of
the run.
We amend our simple example app to set this device hint when loading
pages as part of a search.
Diffstat (limited to 'source/pdf/pdf-run.c')
-rw-r--r-- | source/pdf/pdf-run.c | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/source/pdf/pdf-run.c b/source/pdf/pdf-run.c index 4ac92bb0..a77dd50e 100644 --- a/source/pdf/pdf-run.c +++ b/source/pdf/pdf-run.c @@ -36,7 +36,24 @@ static void pdf_run_page_contents_with_usage(pdf_document *doc, pdf_page *page, void pdf_run_page_contents(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) { - pdf_run_page_contents_with_usage(doc, page, dev, ctm, "View", cookie); + fz_context *ctx = doc->ctx; + int nocache = !!(dev->hints & FZ_NO_CACHE); + + if (nocache) + pdf_mark_xref(doc); + fz_try(ctx) + { + pdf_run_page_contents_with_usage(doc, page, dev, ctm, "View", cookie); + } + fz_always(ctx) + { + if (nocache) + pdf_clear_xref_to_mark(doc); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } if (page->incomplete & PDF_PAGE_INCOMPLETE_CONTENTS) fz_throw(doc->ctx, FZ_ERROR_TRYLATER, "incomplete rendering"); } @@ -44,7 +61,24 @@ void pdf_run_page_contents(pdf_document *doc, pdf_page *page, fz_device *dev, co void pdf_run_annot(pdf_document *doc, pdf_page *page, pdf_annot *annot, fz_device *dev, const fz_matrix *ctm, fz_cookie *cookie) { - pdf_run_annot_with_usage(doc, page, annot, dev, ctm, "View", cookie); + fz_context *ctx = doc->ctx; + int nocache = !!(dev->hints & FZ_NO_CACHE); + + if (nocache) + pdf_mark_xref(doc); + fz_try(ctx) + { + pdf_run_annot_with_usage(doc, page, annot, dev, ctm, "View", cookie); + } + fz_always(ctx) + { + if (nocache) + pdf_clear_xref_to_mark(doc); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } if (page->incomplete & PDF_PAGE_INCOMPLETE_ANNOTS) fz_throw(doc->ctx, FZ_ERROR_TRYLATER, "incomplete rendering"); } @@ -78,8 +112,25 @@ static void pdf_run_page_annots_with_usage(pdf_document *doc, pdf_page *page, fz void pdf_run_page_with_usage(pdf_document *doc, pdf_page *page, fz_device *dev, const fz_matrix *ctm, char *event, fz_cookie *cookie) { - pdf_run_page_contents_with_usage(doc, page, dev, ctm, event, cookie); - pdf_run_page_annots_with_usage(doc, page, dev, ctm, event, cookie); + fz_context *ctx = doc->ctx; + int nocache = !!(dev->hints & FZ_NO_CACHE); + + if (nocache) + pdf_mark_xref(doc); + fz_try(ctx) + { + pdf_run_page_contents_with_usage(doc, page, dev, ctm, event, cookie); + pdf_run_page_annots_with_usage(doc, page, dev, ctm, event, cookie); + } + fz_always(ctx) + { + if (nocache) + pdf_clear_xref_to_mark(doc); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } if (page->incomplete) fz_throw(doc->ctx, FZ_ERROR_TRYLATER, "incomplete rendering"); } |