1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gxpageq.h 8022 2007-06-05 22:23:38Z giles $ */
15
/* Page queue implementation */
17
/* Initial version 2/1/98 by John Desrosiers (soho@crl.com) */
18
/* 7/17/98 L. Peter Deutsch (ghost@aladdin.com) edited to conform to
19
Ghostscript coding standards */
20
/* 8/7/98 ghost@aladdin.com fixed bugs in #define st_... statements */
21
/* 11/3/98 ghost@aladdin.com further updates for coding standards,
22
moves definition of page queue structure to gxpageq.c */
23
/* 12/1/98 soho@crl.com - Upgraded gx_page_queue_action_t comments */
25
#ifndef gxpageq_INCLUDED
26
# define gxpageq_INCLUDED
32
/* --------------- Data type definitions --------------------- */
34
/* Action codes for each page queue entry. Each page that the interpreter
35
emits to the page queue can actually be broken down into a sequence of
36
one or more page queue entries. The general form for a given page's
37
sequence of page queue entries can be expressed as:
38
[PARTIAL_PAGE]... [COPY_PAGE [PARTIAL_PAGE]...]... FULL_PAGE
39
where elements in square brackets are optional, and ellipses show
40
repetition. NOTE that a single ACTION_TERMINATE (followed by nothing) can
41
also show up at any point in the page queue in lieu of page descriptions.
44
PARTIAL_PAGE: The interpreter emits a partial page when the bandlist is
45
too small to contain a page's full representation. Partial pages will
46
be emitted in out-of-memory situations *only* after the interpreter
47
has determined that no further page queue entries are in the page
48
queue, indicating that no further memory can be reclaimed by merely
49
waiting for queued pages to render and free their associated bandlist.
51
Note that num_copies is undefined for partial pages: the actual
52
number of pages to render will only be known when ...COPY_PAGE
53
or FULL_PAGE is emitted.
55
Partial pages are never imaged.
58
FULL_PAGE: The interpreter emits a full page when a page description
59
is complete (e.g. showpage), or trashed (e.g. setpagedevice). The
60
page's complete description consists of the FULL_PAGE plus all
61
PARTIAL_PAGEs that immediately precede it in the page queue (and
62
possibly preceding COPY_PAGEs) all the way back to the previous
63
FULL_PAGE (or up to the beginning of queue entries).
65
In the case of a trashed page, the page count will be 0. The page
66
queue may choose to not render the 0-count FULL_PAGE queue entry
67
for efficiency. If they have not been rendered, the page queue
68
may choose to also discard (and/or not render) any PARTIAL_PAGEs
69
leading up to the trashed page. The page queue must however take
70
care to not discard any entries leading up to a COPY_PAGE with
71
a non-0 page count that may precede the FULL_PAGE, since COPY_PAGE
72
must be rendered in that case. In any event, a 0-count page will
75
In the case of a complete page, the page count will be 0 or greater.
76
The 0-count page is equivalent to a trashed page -- see above. The
77
renderer must ensure that all PARTIAL_PAGEs and COPY_PAGEs leading
78
up to the FULL_PAGE are rendered sequentially before rendering
79
and imaging the FULL_PAGE.
82
COPY_PAGE: is similar to FULL_PAGE above, except that COPY_PAGE must
83
keep the rendered results, instead of clearing them. COPY_PAGE
84
differs from a partial page in that the page must be imaged, as well
85
as rasterized. This is to support PostScript language "copypage"
88
Note that a 0 page count here does not absolve the renderer from
89
rendering the page queue entries (unless all subsequent COPY_PAGEs
90
the the FULL_PAGE for this page also have a 0 page count), since
91
the results of COPY_PAGE must be available for subsequent pages.
94
TERMINATE: This entry can appear at any time in the page queue. It
95
will be the last entry to ever appear in the queue. The semantics
96
of this entry require all prior non-zero-count COPY_PAGEs and
97
FULL_PAGEs to be imaged. Any trailing PARTIAL_PAGEs may optionally
98
be rendered, but should not be imaged.
101
GX_PAGE_QUEUE_ACTION_PARTIAL_PAGE,
102
GX_PAGE_QUEUE_ACTION_FULL_PAGE,
103
GX_PAGE_QUEUE_ACTION_COPY_PAGE,
104
GX_PAGE_QUEUE_ACTION_TERMINATE
105
} gx_page_queue_action_t;
108
* Define the structure used to manage a page queue.
109
* A page queue is a monitor-locked FIFO which holds completed command
110
* list files ready for rendering.
112
#ifndef gx_page_queue_DEFINED
113
# define gx_page_queue_DEFINED
114
typedef struct gx_page_queue_s gx_page_queue_t;
118
* Define a page queue entry object.
120
typedef struct gx_page_queue_entry_s gx_page_queue_entry_t;
121
struct gx_page_queue_entry_s {
122
gx_band_page_info_t page_info;
123
gx_page_queue_action_t action; /* action code */
124
int num_copies; /* number of copies to render, only defined */
125
/* if action == ...FULL_PAGE or ...COPY_PAGE */
126
gx_page_queue_entry_t *next; /* link to next in queue */
127
gx_page_queue_t *queue; /* link to queue the entry is in */
130
#define private_st_gx_page_queue_entry()\
131
gs_private_st_ptrs2(st_gx_page_queue_entry, gx_page_queue_entry_t,\
132
"gx_page_queue_entry",\
133
gx_page_queue_entry_enum_ptrs, gx_page_queue_entry_reloc_ptrs,\
136
/* -------------- Public Procedure Declaraions --------------------- */
138
/* Allocate a page queue. */
139
gx_page_queue_t *gx_page_queue_alloc(gs_memory_t *mem);
142
* Allocate and initialize a page queue entry.
143
* All page queue entries must be allocated by this routine.
145
/* rets ptr to allocated object, 0 if VM error */
146
gx_page_queue_entry_t *
147
gx_page_queue_entry_alloc(
148
gx_page_queue_t * queue /* queue that entry is being alloc'd for */
152
* Free a page queue entry.
153
* All page queue entries must be destroyed by this routine.
155
void gx_page_queue_entry_free(
156
gx_page_queue_entry_t * entry /* entry to free up */
160
* Free the page_info resources held by the pageq entry. Used to free
161
* pages' clist, typically after rendering. Note that this routine is NOT
162
* called implicitly by gx_page_queue_entry_free, since page clist may be
163
* managed separately from page queue entries. However, unless you are
164
* managing clist separately, you must call this routine before freeing the
165
* pageq entry itself (via gx_page_queue_entry_free), or you will leak
168
void gx_page_queue_entry_free_page_info(
169
gx_page_queue_entry_t * entry /* entry to free up */
173
* Initialize a page queue; this must be done before it can be used.
174
* This routine allocates & inits various necessary structures and will
175
* fail if insufficient memory is available.
177
/* -ve error code, or 0 */
178
int gx_page_queue_init(
179
gx_page_queue_t * queue, /* page queue to init */
180
gs_memory_t * memory /* allocator for dynamic memory */
184
* Destroy a page queue which was initialized by gx_page_queue_init.
185
* Any page queue entries in the queue are released and destroyed;
186
* dynamic allocations are released.
188
void gx_page_queue_dnit(
189
gx_page_queue_t * queue /* page queue to dnit */
193
* If there are any pages in queue, wait until one of them finishes
194
* rendering. Typically called by writer's out-of-memory error handlers
195
* that want to wait until some memory has been freed.
197
/* rets 0 if no pages were waiting for rendering, 1 if actually waited */
198
int gx_page_queue_wait_one_page(
199
gx_page_queue_t * queue /* queue to wait on */
203
* Wait until all (if any) pages in queue have finished rendering. Typically
204
* called by writer operations which need to drain the page queue before
207
void gx_page_queue_wait_until_empty(
208
gx_page_queue_t * queue /* page queue to wait on */
212
* Add a pageq queue entry to the end of the page queue. If an unsatisfied
213
* reader thread has an outstanding gx_page_queue_start_deque(), wake it up.
215
void gx_page_queue_enqueue(
216
gx_page_queue_entry_t * entry /* entry to add */
220
* Allocate & construct a pageq entry, then add to the end of the pageq as
221
* in gx_page_queue_enqueue. If unable to allocate a new pageq entry, uses
222
* the pre-allocated reserve entry held in the pageq. When using the reserve
223
* pageq entry, wait until enough pages have been rendered to allocate a new
224
* reserve for next time -- this should always succeed & returns eFatal if not.
225
* Unless the reserve was used, does not wait for any rendering to complete.
226
* Typically called by writer when it has a (partial) page ready for rendering.
228
/* rets 0 ok, gs_error_Fatal if error */
229
int gx_page_queue_add_page(
230
gx_device_clist_writer *const pcwdev,
231
gx_page_queue_t * queue, /* page queue to add to */
232
gx_page_queue_action_t action, /* action code to queue */
233
const gx_band_page_info_t * page_info, /* bandinfo incl. bandlist */
234
int page_count /* # of copies to print if final "print," */
235
/* 0 if partial page, -1 if cancel */
239
* Retrieve the least-recently added queue entry from the pageq. If no
240
* entry is available, waits on a signal from gx_page_queue_enqueue. Must
241
* eventually be followed by a call to gx_page_queue_finish_dequeue for the
243
* Even though the pageq is actually removed from the pageq, a mark is made in
244
* the pageq to indicate that the pageq is not "empty" until the
245
* gx_page_queue_finish_dequeue; this is for the benefit of
246
* gx_page_queue_wait_???, since the completing the current page's rendering
247
* may free more memory.
248
* Typically called by renderer thread loop, which looks like:
250
gx_page_queue_start_deqeueue(...);
251
render_retrieved_entry(...);
252
gx_page_queue_finish_dequeue(...);
253
} while (some condition);
255
gx_page_queue_entry_t * /* removed entry */
256
gx_page_queue_start_dequeue(
257
gx_page_queue_t * queue /* page queue to retrieve from */
261
* Free the pageq entry and its associated band list data, then signal any
262
* waiting threads. Typically used to indicate completion of rendering the
263
* pageq entry. Note that this is different from gx_page_queue_entry_free,
264
* which does not free the band list data (a separate call of
265
* gx_page_queue_entry_free_page_info is required).
267
void gx_page_queue_finish_dequeue(
268
gx_page_queue_entry_t * entry /* entry that was retrieved to delete */
271
#endif /*!defined(gxpageq_INCLUDED) */