summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2014-01-03 16:51:31 +0000
committerRobin Watts <robin.watts@artifex.com>2014-03-04 13:43:01 +0000
commit67cdce34a5aeaeae15cbb7228184eecf89ddbe27 (patch)
tree6e92827161eba8556f737a594753254e12e558ed /include
parent67aba4046c0d54b03b5f97e0952316eff98c1c2f (diff)
downloadmupdf-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 'include')
-rw-r--r--include/mupdf/fitz/device.h1
-rw-r--r--include/mupdf/pdf/object.h2
-rw-r--r--include/mupdf/pdf/xref.h12
3 files changed, 14 insertions, 1 deletions
diff --git a/include/mupdf/fitz/device.h b/include/mupdf/fitz/device.h
index a95a5ab1..25959424 100644
--- a/include/mupdf/fitz/device.h
+++ b/include/mupdf/fitz/device.h
@@ -206,6 +206,7 @@ enum
FZ_IGNORE_SHADE = 2,
FZ_DONT_INTERPOLATE_IMAGES = 4,
FZ_MAINTAIN_CONTAINER_STACK = 8,
+ FZ_NO_CACHE = 16,
};
/*
diff --git a/include/mupdf/pdf/object.h b/include/mupdf/pdf/object.h
index 0f0a48d2..2c9600a2 100644
--- a/include/mupdf/pdf/object.h
+++ b/include/mupdf/pdf/object.h
@@ -106,6 +106,8 @@ void pdf_sort_dict(pdf_obj *dict);
*/
void pdf_set_obj_parent(pdf_obj *obj, int num);
+int pdf_obj_refs(pdf_obj *ref);
+
int pdf_obj_parent_num(pdf_obj *obj);
int pdf_sprint_obj(char *s, int n, pdf_obj *obj, int tight);
diff --git a/include/mupdf/pdf/xref.h b/include/mupdf/pdf/xref.h
index f9e1657f..5f1a49d1 100644
--- a/include/mupdf/pdf/xref.h
+++ b/include/mupdf/pdf/xref.h
@@ -35,13 +35,19 @@ typedef struct pdf_xref_entry_s pdf_xref_entry;
struct pdf_xref_entry_s
{
char type; /* 0=unset (f)ree i(n)use (o)bjstm */
+ unsigned char flags; /* bit 0 = marked */
+ unsigned short gen; /* generation / objstm index */
int ofs; /* file offset / objstm object number */
- int gen; /* generation / objstm index */
int stm_ofs; /* on-disk stream */
fz_buffer *stm_buf; /* in-memory stream (for updated objects) */
pdf_obj *obj; /* stored/cached object */
};
+enum
+{
+ PDF_OBJ_FLAG_MARK = 1,
+};
+
struct pdf_xref_s
{
int len;
@@ -83,6 +89,10 @@ void pdf_repair_xref(pdf_document *doc, pdf_lexbuf *buf);
void pdf_repair_obj_stms(pdf_document *doc);
pdf_obj *pdf_new_ref(pdf_document *doc, pdf_obj *obj);
+void pdf_mark_xref(pdf_document *doc);
+void pdf_clear_xref(pdf_document *doc);
+void pdf_clear_xref_to_mark(pdf_document *doc);
+
int pdf_repair_obj(pdf_document *doc, pdf_lexbuf *buf, int *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, int *tmpofs);
pdf_obj *pdf_progressive_advance(pdf_document *doc, int pagenum);