~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to base/gxpageq.h

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
 
2
   All Rights Reserved.
 
3
  
 
4
   This software is provided AS-IS with no warranty, either express or
 
5
   implied.
 
6
 
 
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.
 
12
*/
 
13
 
 
14
/* $Id: gxpageq.h 8022 2007-06-05 22:23:38Z giles $ */
 
15
/* Page queue implementation */
 
16
 
 
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 */
 
24
 
 
25
#ifndef gxpageq_INCLUDED
 
26
# define gxpageq_INCLUDED
 
27
 
 
28
#include "gsmemory.h"
 
29
#include "gxband.h"
 
30
#include "gxsync.h"
 
31
 
 
32
/* --------------- Data type definitions --------------------- */
 
33
 
 
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.
 
42
 
 
43
 
 
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.
 
50
 
 
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.
 
54
 
 
55
        Partial pages are never imaged.
 
56
 
 
57
 
 
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).
 
64
 
 
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
 
73
        not be imaged.
 
74
 
 
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.
 
80
 
 
81
 
 
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"
 
86
        semantics.
 
87
 
 
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.
 
92
 
 
93
 
 
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.
 
99
 */
 
100
typedef enum {
 
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;
 
106
 
 
107
/*
 
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.
 
111
 */
 
112
#ifndef gx_page_queue_DEFINED
 
113
# define gx_page_queue_DEFINED
 
114
typedef struct gx_page_queue_s gx_page_queue_t;
 
115
#endif
 
116
 
 
117
/*
 
118
 * Define a page queue entry object.
 
119
 */
 
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 */
 
128
};
 
129
 
 
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,\
 
134
    next, queue)
 
135
 
 
136
/* -------------- Public Procedure Declaraions --------------------- */
 
137
 
 
138
/* Allocate a page queue. */
 
139
gx_page_queue_t *gx_page_queue_alloc(gs_memory_t *mem);
 
140
 
 
141
/*
 
142
 * Allocate and initialize a page queue entry.
 
143
 * All page queue entries must be allocated by this routine.
 
144
 */
 
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 */
 
149
    );
 
150
 
 
151
/*
 
152
 * Free a page queue entry.
 
153
 * All page queue entries must be destroyed by this routine.
 
154
 */
 
155
void gx_page_queue_entry_free(
 
156
    gx_page_queue_entry_t * entry       /* entry to free up */
 
157
    );
 
158
 
 
159
/*
 
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
 
166
 * memory (lots).
 
167
 */
 
168
void gx_page_queue_entry_free_page_info(
 
169
    gx_page_queue_entry_t * entry       /* entry to free up */
 
170
    );
 
171
 
 
172
/*
 
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.
 
176
 */
 
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 */
 
181
    );
 
182
 
 
183
/*
 
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.
 
187
 */
 
188
void gx_page_queue_dnit(
 
189
    gx_page_queue_t * queue     /* page queue to dnit */
 
190
    );
 
191
 
 
192
/*
 
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.
 
196
 */
 
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 */
 
200
    );
 
201
 
 
202
/*
 
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
 
205
 * continuing.
 
206
 */
 
207
void gx_page_queue_wait_until_empty(
 
208
    gx_page_queue_t * queue             /* page queue to wait on */
 
209
    );
 
210
 
 
211
/*
 
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.
 
214
 */
 
215
void gx_page_queue_enqueue(
 
216
    gx_page_queue_entry_t * entry       /* entry to add */
 
217
    );
 
218
 
 
219
/*
 
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.
 
227
 */
 
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 */
 
236
    );
 
237
 
 
238
/*
 
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
 
242
 * same pageq entry.
 
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:
 
249
    do {
 
250
        gx_page_queue_start_deqeueue(...);
 
251
        render_retrieved_entry(...);
 
252
        gx_page_queue_finish_dequeue(...);
 
253
    } while (some condition);
 
254
 */
 
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 */
 
258
    );
 
259
 
 
260
/*
 
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).
 
266
 */
 
267
void gx_page_queue_finish_dequeue(
 
268
    gx_page_queue_entry_t * entry  /* entry that was retrieved to delete */
 
269
    );
 
270
 
 
271
#endif /*!defined(gxpageq_INCLUDED) */