diff options
author | Robin Watts <robin.watts@artifex.com> | 2012-01-04 18:33:33 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-01-04 19:13:41 +0000 |
commit | 2ae2a7b68381f0fc5940e983ccdec5b4cc08d188 (patch) | |
tree | a0ff2e359868cf6d4bcc6de7fabc06d9ade9774a /fitz | |
parent | 94439d77f23763d59457b9946ba35bd354ea4841 (diff) | |
download | mupdf-2ae2a7b68381f0fc5940e983ccdec5b4cc08d188.tar.xz |
Bug 692739: Add ability to abort time consuming actions
A new 'cookie' parameter is added to page rendering/interpretation
functions. Supply this as NULL to get existing behaviour.
If you supply a non-NULL cookie, then this is taken as a pointer to
a struct that can be used for simple, non-thread locked communication
between caller and library.
The entire struct should be memset to zero before entry, except for
specific flags (thus coping with future extensions to this struct).
The abort flag should be zero on entry. It will be checked periodically
by the library - if the caller sets it non-zero (via another thread)
then the current operation will be aborted. No guarantees are given as
to how often this will be checked, or how fast it will be responded to.
The progress_max field will be set to an integer (-1 for unknown)
representing the number of 'things' to do. The progress field will
count up from 0 to this number as time goes by. No guarantees are
made as to the accuracy of this information, but it should be
useful for offering some sort of progress bar etc. Note that
progress_max may increase during the job.
In general, callers should be careful to accept out of range or
invalid data in this structure as this is deliberately
accessed 'unlocked'.
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/dev_list.c | 17 | ||||
-rw-r--r-- | fitz/fitz.h | 15 |
2 files changed, 30 insertions, 2 deletions
diff --git a/fitz/dev_list.c b/fitz/dev_list.c index 376cdac8..c6a71ec9 100644 --- a/fitz/dev_list.c +++ b/fitz/dev_list.c @@ -591,7 +591,7 @@ fz_free_display_list(fz_context *ctx, fz_display_list *list) } void -fz_execute_display_list(fz_display_list *list, fz_device *dev, fz_matrix top_ctm, fz_bbox scissor) +fz_execute_display_list(fz_display_list *list, fz_device *dev, fz_matrix top_ctm, fz_bbox scissor, fz_cookie *cookie) { fz_display_node *node; fz_matrix ctm; @@ -600,6 +600,7 @@ fz_execute_display_list(fz_display_list *list, fz_device *dev, fz_matrix top_ctm int clipped = 0; int tiled = 0; int empty; + int progress = 0; if (!fz_is_infinite_bbox(scissor)) { @@ -609,8 +610,22 @@ fz_execute_display_list(fz_display_list *list, fz_device *dev, fz_matrix top_ctm scissor.x1 += 20; scissor.y1 += 20; } + if (cookie) + { + cookie->progress_max = list->last - list->first; + cookie->progress = 0; + } + for (node = list->first; node; node = node->next) { + /* Check the cookie for aborting */ + if (cookie) + { + if (cookie->abort) + break; + cookie->progress = progress++; + } + /* cull objects to draw using a quick visibility test */ if (tiled || node->cmd == FZ_CMD_BEGIN_TILE || node->cmd == FZ_CMD_END_TILE) diff --git a/fitz/fitz.h b/fitz/fitz.h index d79d39f2..becd5df9 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -1150,6 +1150,19 @@ void fz_debug_text_span_xml(fz_text_span *span); fz_device *fz_new_text_device(fz_context *ctx, fz_text_span *text); /* + * Cookie support - simple communication channel between app/library. + */ + +typedef struct fz_cookie_s fz_cookie; + +struct fz_cookie_s +{ + int abort; + int progress; + int progress_max; /* -1 for unknown */ +}; + +/* * Display list device -- record and play back device commands. */ @@ -1158,7 +1171,7 @@ typedef struct fz_display_list_s fz_display_list; fz_display_list *fz_new_display_list(fz_context *ctx); void fz_free_display_list(fz_context *ctx, fz_display_list *list); fz_device *fz_new_list_device(fz_context *ctx, fz_display_list *list); -void fz_execute_display_list(fz_display_list *list, fz_device *dev, fz_matrix ctm, fz_bbox area); +void fz_execute_display_list(fz_display_list *list, fz_device *dev, fz_matrix ctm, fz_bbox area, fz_cookie *cookie); /* |