From 2ae2a7b68381f0fc5940e983ccdec5b4cc08d188 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 4 Jan 2012 18:33:33 +0000 Subject: 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'. --- fitz/dev_list.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'fitz/dev_list.c') 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) -- cgit v1.2.3