~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to afb/afbplygblt.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/afb/afbplygblt.c,v 3.2tsi Exp $ */
 
2
/* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
 
3
/***********************************************************
 
4
 
 
5
Copyright (c) 1987  X Consortium
 
6
 
 
7
Permission is hereby granted, free of charge, to any person obtaining a copy
 
8
of this software and associated documentation files (the "Software"), to deal
 
9
in the Software without restriction, including without limitation the rights
 
10
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
11
copies of the Software, and to permit persons to whom the Software is
 
12
furnished to do so, subject to the following conditions:
 
13
 
 
14
The above copyright notice and this permission notice shall be included in
 
15
all copies or substantial portions of the Software.
 
16
 
 
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
19
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
20
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
21
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
22
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
23
 
 
24
Except as contained in this notice, the name of the X Consortium shall not be
 
25
used in advertising or otherwise to promote the sale, use or other dealings
 
26
in this Software without prior written authorization from the X Consortium.
 
27
 
 
28
 
 
29
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
 
30
 
 
31
                        All Rights Reserved
 
32
 
 
33
Permission to use, copy, modify, and distribute this software and its
 
34
documentation for any purpose and without fee is hereby granted,
 
35
provided that the above copyright notice appear in all copies and that
 
36
both that copyright notice and this permission notice appear in
 
37
supporting documentation, and that the name of Digital not be
 
38
used in advertising or publicity pertaining to distribution of the
 
39
software without specific, written prior permission.
 
40
 
 
41
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
42
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
43
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
44
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
45
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
46
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
47
SOFTWARE.
 
48
 
 
49
******************************************************************/
 
50
/* $XConsortium: afbimggblt.c,v 5.17 94/04/17 20:28:25 dpw Exp $ */
 
51
 
 
52
#ifdef HAVE_DIX_CONFIG_H
 
53
#include <dix-config.h>
 
54
#endif
 
55
 
 
56
#include                <X11/X.h>
 
57
#include                <X11/Xmd.h>
 
58
#include                <X11/Xproto.h>
 
59
#include                "afb.h"
 
60
#include                <X11/fonts/fontstruct.h>
 
61
#include                "dixfontstr.h"
 
62
#include                "gcstruct.h"
 
63
#include                "windowstr.h"
 
64
#include                "scrnintstr.h"
 
65
#include                "pixmapstr.h"
 
66
#include                "regionstr.h"
 
67
#include                "maskbits.h"
 
68
 
 
69
/*
 
70
        this works for fonts with glyphs <= 32 bits wide.
 
71
 
 
72
        the clipping calculations are done for worst-case fonts.
 
73
we make no assumptions about the heights, widths, or bearings
 
74
of the glyphs.  if we knew that the glyphs are all the same height,
 
75
we could clip the tops and bottoms per clipping box, rather
 
76
than per character per clipping box.  if we knew that the glyphs'
 
77
left and right bearings were wlle-behaved, we could clip a single
 
78
character at the start, output until the last unclipped
 
79
character, and then clip the last one.  this is all straightforward
 
80
to determine based on max-bounds and min-bounds from the font.
 
81
        there is some inefficiency introduced in the per-character
 
82
clipping to make what's going on clearer.
 
83
 
 
84
        (it is possible, for example, for a font to be defined in which the
 
85
next-to-last character in a font would be clipped out, but the last
 
86
one wouldn't.  the code below deals with this.)
 
87
 
 
88
*/
 
89
 
 
90
void
 
91
afbPolyGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
 
92
        DrawablePtr pDrawable;
 
93
        GC                              *pGC;
 
94
        int             x, y;
 
95
        unsigned int nglyph;
 
96
        CharInfoPtr *ppci;                      /* array of character info */
 
97
        pointer         pglyphBase;             /* start of array of glyphs */
 
98
{
 
99
        ExtentInfoRec info;                     /* used by QueryGlyphExtents() */
 
100
        BoxRec bbox;                                    /* string's bounding box */
 
101
 
 
102
        CharInfoPtr pci;
 
103
        int xorg, yorg;                         /* origin of drawable in bitmap */
 
104
        int widthDst;                                   /* width of dst in longwords */
 
105
 
 
106
                                                                                /* these keep track of the character origin */
 
107
        PixelType *pdstBase;
 
108
                                                                                /* points to longword with character origin */
 
109
        int xchar;                                              /* xorigin of char (mod 32) */
 
110
 
 
111
                                                                                /* these are used for placing the glyph */
 
112
        register int xoff;                      /* x offset of left edge of glyph (mod 32) */
 
113
        register PixelType *pdst;       /* pointer to current longword in dst */
 
114
 
 
115
        register int d;
 
116
        int depthDst;
 
117
        int sizeDst;
 
118
        int hSave;
 
119
        int w;                                                  /* width of glyph in bits */
 
120
        int h;                                                  /* height of glyph */
 
121
        int widthGlyph;                         /* width of glyph, in bytes */
 
122
        unsigned char *rrops;
 
123
        register unsigned char *pglyph;
 
124
                                                                                /* pointer to current row of glyph */
 
125
        unsigned char *pglyphSave;
 
126
 
 
127
                                                                                /* used for putting down glyph */
 
128
        register PixelType tmpSrc;
 
129
                                                                                /* for getting bits from glyph */
 
130
        register PixelType startmask;
 
131
        register PixelType endmask;
 
132
 
 
133
        register int nFirst;                    /* bits of glyph in current longword */
 
134
        PixelType *pdstSave;
 
135
 
 
136
        xorg = pDrawable->x;
 
137
        yorg = pDrawable->y;
 
138
        afbGetPixelWidthSizeDepthAndPointer(pDrawable, widthDst, sizeDst, depthDst,
 
139
                                                                                                         pdstBase);
 
140
 
 
141
        QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
 
142
 
 
143
        x += xorg;
 
144
        y += yorg;
 
145
 
 
146
        bbox.x1 = x + info.overallLeft;
 
147
        bbox.x2 = x + info.overallRight;
 
148
        bbox.y1 = y - info.overallAscent;
 
149
        bbox.y2 = y + info.overallDescent;
 
150
 
 
151
        rrops = ((afbPrivGCPtr) pGC->devPrivates[afbGCPrivateIndex].ptr)->rrops;
 
152
 
 
153
        switch (RECT_IN_REGION(pGC->pScreen, pGC->pCompositeClip, &bbox)) {
 
154
                case rgnOUT:
 
155
                        break;
 
156
                case rgnIN:
 
157
                        pdstBase = afbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
 
158
                        xchar = x & PIM;
 
159
 
 
160
                        while(nglyph--) {
 
161
                                pci = *ppci;
 
162
                                pglyphSave = FONTGLYPHBITS(pglyphBase, pci);
 
163
                                w = pci->metrics.rightSideBearing - pci->metrics.leftSideBearing;
 
164
                                hSave = pci->metrics.ascent + pci->metrics.descent;
 
165
                                widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
 
166
                                /* start at top scanline of glyph */
 
167
                                pdstSave = afbScanlineDelta(pdstBase, -pci->metrics.ascent,
 
168
                                                                                        widthDst);
 
169
 
 
170
                                /* find correct word in scanline and x offset within it
 
171
                                   for left edge of glyph
 
172
                                */
 
173
                                xoff = xchar + pci->metrics.leftSideBearing;
 
174
                                if (xoff > PLST) {
 
175
                                        pdstSave++;
 
176
                                        xoff &= PIM;
 
177
                                } else if (xoff < 0) {
 
178
                                        xoff += PPW;
 
179
                                        pdstSave--;
 
180
                                }
 
181
 
 
182
                                for (d = 0; d < depthDst; d++) {
 
183
                                        h = hSave;
 
184
                                        pdst = pdstSave;
 
185
                                        pdstSave += sizeDst;    /* @@@ NEXT PLANE @@@ */
 
186
                                        pglyph = pglyphSave;
 
187
 
 
188
                                        if ((xoff + w) <= PPW) {
 
189
                                                /* glyph all in one longword */
 
190
                                                maskpartialbits(xoff, w, startmask);
 
191
                                                switch (rrops[d]) {
 
192
                                                        case RROP_WHITE:
 
193
                                                                while (h--) {
 
194
                                                                        getleftbits(pglyph, w, tmpSrc);
 
195
                                                                        *pdst |= (SCRRIGHT(tmpSrc, xoff) & startmask);
 
196
                                                                        pglyph += widthGlyph;
 
197
                                                                        afbScanlineInc(pdst, widthDst);
 
198
                                                                }
 
199
                                                                break;
 
200
                                                        case RROP_BLACK:
 
201
                                                                while (h--) {
 
202
                                                                        getleftbits(pglyph, w, tmpSrc);
 
203
                                                                        *pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
 
204
                                                                        pglyph += widthGlyph;
 
205
                                                                        afbScanlineInc(pdst, widthDst);
 
206
                                                                }
 
207
                                                                break;
 
208
                                                        case RROP_INVERT:
 
209
                                                                while (h--) {
 
210
                                                                        getleftbits(pglyph, w, tmpSrc);
 
211
                                                                        *pdst ^= (SCRRIGHT(tmpSrc, xoff) & startmask);
 
212
                                                                        pglyph += widthGlyph;
 
213
                                                                        afbScanlineInc(pdst, widthDst);
 
214
                                                                }
 
215
                                                                break;
 
216
                                                }
 
217
                                        } else {
 
218
                                                /* glyph crosses longword boundary */
 
219
                                                maskPPWbits(xoff, w, startmask, endmask);
 
220
                                                nFirst = PPW - xoff;
 
221
                                                switch (rrops[d]) {
 
222
                                                        case RROP_WHITE:
 
223
                                                                while (h--) {
 
224
                                                                        getleftbits(pglyph, w, tmpSrc);
 
225
                                                                        *pdst |= (SCRRIGHT(tmpSrc, xoff) & startmask);
 
226
                                                                        *(pdst+1) |= (SCRLEFT(tmpSrc, nFirst) & endmask);
 
227
                                                                        pglyph += widthGlyph;
 
228
                                                                        afbScanlineInc(pdst, widthDst);
 
229
                                                                }
 
230
                                                                break;
 
231
                                                        case RROP_BLACK:
 
232
                                                                while (h--) {
 
233
                                                                        getleftbits(pglyph, w, tmpSrc);
 
234
                                                                        *pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
 
235
                                                                        *(pdst+1) &= ~(SCRLEFT(tmpSrc, nFirst) & endmask);
 
236
                                                                        pglyph += widthGlyph;
 
237
                                                                        afbScanlineInc(pdst, widthDst);
 
238
                                                                }
 
239
                                                                break;
 
240
                                                        case RROP_INVERT:
 
241
                                                                while (h--) {
 
242
                                                                        getleftbits(pglyph, w, tmpSrc);
 
243
                                                                        *pdst ^= (SCRRIGHT(tmpSrc, xoff) & startmask);
 
244
                                                                        *(pdst+1) ^= (SCRLEFT(tmpSrc, nFirst) & endmask);
 
245
                                                                        pglyph += widthGlyph;
 
246
                                                                        afbScanlineInc(pdst, widthDst);
 
247
                                                                }
 
248
                                                                break;
 
249
                                                }
 
250
                                        } /* glyph crosses longwords boundary */
 
251
                                } /* depth loop */
 
252
                                /* update character origin */
 
253
                                x += pci->metrics.characterWidth;
 
254
                                xchar += pci->metrics.characterWidth;
 
255
                                if (xchar > PLST) {
 
256
                                        xchar -= PPW;
 
257
                                        pdstBase++;
 
258
                                } else if (xchar < 0) {
 
259
                                        xchar += PPW;
 
260
                                        pdstBase--;
 
261
                                }
 
262
                                ppci++;
 
263
                        } /* while nglyph-- */
 
264
                        break;
 
265
                case rgnPART:
 
266
                        {
 
267
                                afbTEXTPOS *ppos;
 
268
                                int nbox;
 
269
                                BoxPtr pbox;
 
270
                                RegionPtr cclip;
 
271
                                int xpos;                               /* x position of char origin */
 
272
                                int i;
 
273
                                BoxRec clip;
 
274
                                int leftEdge, rightEdge;
 
275
                                int topEdge, bottomEdge;
 
276
                                int glyphRow;                           /* first row of glyph not wholly
 
277
                                                                                   clipped out */
 
278
                                int glyphCol;                           /* leftmost visible column of glyph */
 
279
#if GETLEFTBITS_ALIGNMENT > 1
 
280
                                int getWidth;                           /* bits to get from glyph */
 
281
#endif
 
282
 
 
283
                                if(!(ppos = (afbTEXTPOS *)ALLOCATE_LOCAL(nglyph * sizeof(afbTEXTPOS))))
 
284
                                        return;
 
285
 
 
286
                                pdstBase = afbScanlineNoBankSwitch(pdstBase, x, y, widthDst);
 
287
                                xpos = x;
 
288
                                xchar = xpos & PIM;
 
289
 
 
290
                                for (i = 0; i < nglyph; i++) {
 
291
                                        pci = ppci[i];
 
292
 
 
293
                                        ppos[i].xpos = xpos;
 
294
                                        ppos[i].xchar = xchar;
 
295
                                        ppos[i].leftEdge = xpos + pci->metrics.leftSideBearing;
 
296
                                        ppos[i].rightEdge = xpos + pci->metrics.rightSideBearing;
 
297
                                        ppos[i].topEdge = y - pci->metrics.ascent;
 
298
                                        ppos[i].bottomEdge = y + pci->metrics.descent;
 
299
                                        ppos[i].pdstBase = pdstBase;
 
300
                                        ppos[i].widthGlyph = GLYPHWIDTHBYTESPADDED(pci);
 
301
 
 
302
                                        xpos += pci->metrics.characterWidth;
 
303
                                        xchar += pci->metrics.characterWidth;
 
304
                                        if (xchar > PLST) {
 
305
                                                xchar &= PIM;
 
306
                                                pdstBase++;
 
307
                                        } else if (xchar < 0) {
 
308
                                                xchar += PPW;
 
309
                                                pdstBase--;
 
310
                                        }
 
311
                                }
 
312
 
 
313
                                cclip = pGC->pCompositeClip;
 
314
                                pbox = REGION_RECTS(cclip);
 
315
                                nbox = REGION_NUM_RECTS(cclip);
 
316
 
 
317
                                /* HACK ALERT
 
318
                                   since we continue out of the loop below so often, it
 
319
                                   is easier to increment pbox at the  top than at the end.
 
320
                                   don't try this at home.
 
321
                                */
 
322
                                pbox--;
 
323
                                while(nbox--) {
 
324
                                        pbox++;
 
325
                                        clip.x1 = max(bbox.x1, pbox->x1);
 
326
                                        clip.y1 = max(bbox.y1, pbox->y1);
 
327
                                        clip.x2 = min(bbox.x2, pbox->x2);
 
328
                                        clip.y2 = min(bbox.y2, pbox->y2);
 
329
                                        if ((clip.x2<=clip.x1) || (clip.y2<=clip.y1))
 
330
                                                continue;
 
331
 
 
332
                                        for(i=0; i<nglyph; i++) {
 
333
                                                pci = ppci[i];
 
334
                                                xchar = ppos[i].xchar;
 
335
 
 
336
                                                /* clip the left and right edges */
 
337
                                                if (ppos[i].leftEdge < clip.x1)
 
338
                                                        leftEdge = clip.x1;
 
339
                                                else
 
340
                                                        leftEdge = ppos[i].leftEdge;
 
341
 
 
342
                                                if (ppos[i].rightEdge > clip.x2)
 
343
                                                        rightEdge = clip.x2;
 
344
                                                else
 
345
                                                        rightEdge = ppos[i].rightEdge;
 
346
 
 
347
                                                w = rightEdge - leftEdge;
 
348
                                                if (w <= 0)
 
349
                                                        continue;
 
350
 
 
351
                                                /* clip the top and bottom edges */
 
352
                                                if (ppos[i].topEdge < clip.y1)
 
353
                                                        topEdge = clip.y1;
 
354
                                                else
 
355
                                                        topEdge = ppos[i].topEdge;
 
356
 
 
357
                                                if (ppos[i].bottomEdge > clip.y2)
 
358
                                                        bottomEdge = clip.y2;
 
359
                                                else
 
360
                                                        bottomEdge = ppos[i].bottomEdge;
 
361
 
 
362
                                                hSave = bottomEdge - topEdge;
 
363
                                                if (hSave <= 0)
 
364
                                                        continue;
 
365
 
 
366
                                                glyphRow = (topEdge - y) + pci->metrics.ascent;
 
367
                                                widthGlyph = ppos[i].widthGlyph;
 
368
                                                pglyphSave = FONTGLYPHBITS(pglyphBase, pci);
 
369
                                                pglyphSave += (glyphRow * widthGlyph);
 
370
 
 
371
                                                glyphCol = (leftEdge - ppos[i].xpos) -
 
372
                                                                   (pci->metrics.leftSideBearing);
 
373
#if GETLEFTBITS_ALIGNMENT > 1
 
374
                                                getWidth = w + glyphCol;
 
375
#endif
 
376
 
 
377
                                                pdstSave = afbScanlineDelta(ppos[i].pdstBase, -(y-topEdge),
 
378
                                                                                                        widthDst);
 
379
                                                xoff = xchar + (leftEdge - ppos[i].xpos);
 
380
                                                if (xoff > PLST) {
 
381
                                                        xoff &= PIM;
 
382
                                                        pdstSave++;
 
383
                                                } else if (xoff < 0) {
 
384
                                                        xoff += PPW;
 
385
                                                        pdstSave--;
 
386
                                                }
 
387
 
 
388
                                                for (d = 0; d < depthDst; d++) {
 
389
                                                        h = hSave;
 
390
                                                        pdst = pdstSave;
 
391
                                                        pdstSave += sizeDst;    /* @@@ NEXT PLANE @@@ */
 
392
                                                        pglyph = pglyphSave;
 
393
 
 
394
                                                        if ((xoff + w) <= PPW) {
 
395
                                                                maskpartialbits(xoff, w, startmask);
 
396
                                                                switch (rrops[d]) {
 
397
                                                                        case RROP_WHITE:
 
398
                                                                                while (h--) {
 
399
                                                                                        getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
 
400
                                                                                        *pdst |= (SCRRIGHT(tmpSrc, xoff) & startmask);
 
401
                                                                                        pglyph += widthGlyph;
 
402
                                                                                        afbScanlineInc(pdst, widthDst);
 
403
                                                                                }
 
404
                                                                                break;
 
405
                                                                        case RROP_BLACK:
 
406
                                                                                while (h--) {
 
407
                                                                                        getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
 
408
                                                                                        *pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
 
409
                                                                                        pglyph += widthGlyph;
 
410
                                                                                        afbScanlineInc(pdst, widthDst);
 
411
                                                                                }
 
412
                                                                                break;
 
413
                                                                        case RROP_INVERT:
 
414
                                                                                while (h--) {
 
415
                                                                                        getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
 
416
                                                                                        *pdst ^= (SCRRIGHT(tmpSrc, xoff) & startmask);
 
417
                                                                                        pglyph += widthGlyph;
 
418
                                                                                        afbScanlineInc(pdst, widthDst);
 
419
                                                                                }
 
420
                                                                                break;
 
421
                                                                }
 
422
                                                        } else {
 
423
                                                                maskPPWbits(xoff, w, startmask, endmask);
 
424
                                                                nFirst = PPW - xoff;
 
425
                                                                switch (rrops[d]) {
 
426
                                                                        case RROP_WHITE:
 
427
                                                                                while (h--) {
 
428
                                                                                        getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
 
429
                                                                                        *pdst |= (SCRRIGHT(tmpSrc, xoff) & startmask);
 
430
                                                                                        *(pdst+1) |= (SCRLEFT(tmpSrc, nFirst) & endmask);
 
431
                                                                                        pglyph += widthGlyph;
 
432
                                                                                        afbScanlineInc(pdst, widthDst);
 
433
                                                                                }
 
434
                                                                                break;
 
435
                                                                        case RROP_BLACK:
 
436
                                                                                while (h--) {
 
437
                                                                                        getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
 
438
                                                                                        *pdst &= ~(SCRRIGHT(tmpSrc, xoff) & startmask);
 
439
                                                                                        *(pdst+1) &= ~(SCRLEFT(tmpSrc, nFirst) & endmask);
 
440
                                                                                        pglyph += widthGlyph;
 
441
                                                                                        afbScanlineInc(pdst, widthDst);
 
442
                                                                                }
 
443
                                                                                break;
 
444
                                                                        case RROP_INVERT:
 
445
                                                                                while (h--) {
 
446
                                                                                        getshiftedleftbits(pglyph, glyphCol, getWidth, tmpSrc);
 
447
                                                                                        *pdst ^= (SCRRIGHT(tmpSrc, xoff) & startmask);
 
448
                                                                                        *(pdst+1) ^= (SCRLEFT(tmpSrc, nFirst) & endmask);
 
449
                                                                                        pglyph += widthGlyph;
 
450
                                                                                        afbScanlineInc(pdst, widthDst);
 
451
                                                                                }
 
452
                                                                                break;
 
453
                                                                }
 
454
                                                        }
 
455
                                                } /* depth */
 
456
                                        } /* for each glyph */
 
457
                                } /* while nbox-- */
 
458
                                DEALLOCATE_LOCAL(ppos);
 
459
                                break;
 
460
                        }
 
461
 
 
462
                default:
 
463
                        break;
 
464
        }
 
465
}