First import
[xorg_rtime.git] / xorg-server-1.4 / afb / afbtegblt.c
blobba889cb80c91c30b012a9f91179a0514ac266a07
1 /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
2 /***********************************************************
4 Copyright (c) 1987 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
28 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
30 All Rights Reserved
32 Permission to use, copy, modify, and distribute this software and its
33 documentation for any purpose and without fee is hereby granted,
34 provided that the above copyright notice appear in all copies and that
35 both that copyright notice and this permission notice appear in
36 supporting documentation, and that the name of Digital not be
37 used in advertising or publicity pertaining to distribution of the
38 software without specific, written prior permission.
40 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 SOFTWARE.
48 ******************************************************************/
50 #ifdef HAVE_DIX_CONFIG_H
51 #include <dix-config.h>
52 #endif
54 #include <X11/X.h>
55 #include <X11/Xmd.h>
56 #include <X11/Xproto.h>
57 #include "afb.h"
58 #include <X11/fonts/fontstruct.h>
59 #include "dixfontstr.h"
60 #include "gcstruct.h"
61 #include "windowstr.h"
62 #include "scrnintstr.h"
63 #include "pixmapstr.h"
64 #include "regionstr.h"
65 #include "maskbits.h"
68 this works for fonts with glyphs <= PPW bits wide.
70 This should be called only with a terminal-emulator font;
71 this means that the FIXED_METRICS flag is set, and that
72 glyphbounds == charbounds.
74 in theory, this goes faster; even if it doesn't, it reduces the
75 flicker caused by writing a string over itself with image text (since
76 the background gets repainted per character instead of per string.)
77 this seems to be important for some converted X10 applications.
79 Image text looks at the bits in the glyph and the fg and bg in the
80 GC. it paints a rectangle, as defined in the protocol dcoument,
81 and the paints the characters.
85 #if defined(NO_3_60_CG4) && defined(FASTPUTBITS) && defined(FASTGETBITS)
86 #define FASTCHARS
87 #endif
90 * this macro "knows" that only characters <= 8 bits wide will
91 * fit this case (which is why it is independent of GLYPHPADBYTES)
94 #if (BITMAP_BIT_ORDER == MSBFirst) && (GLYPHPADBYTES != 4)
95 #if GLYPHPADBYTES == 1
96 #define ShiftAmnt 24
97 #else
98 #define ShiftAmnt 16
99 #endif
102 * Note: for BITMAP_BIT_ORDER != IMAGE_BYTE_ORDER, SCRRIGHT() evaluates its
103 * first argument more than once. Thus the imbedded char++ have to be moved.
104 * (DHD)
106 #if BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER
107 #if PPW == 32
108 #define GetBits4 c = (*char1++ << ShiftAmnt) | \
109 SCRRIGHT (*char2++ << ShiftAmnt, xoff2) | \
110 SCRRIGHT (*char3++ << ShiftAmnt, xoff3) | \
111 SCRRIGHT (*char4++ << ShiftAmnt, xoff4);
112 #else /* PPW */
113 #define GetBits4 c = ((unsigned long)(*char1++ << ShiftAmnt) << 32 ) | \
114 (SCRRIGHT (*char2++ << ShiftAmnt, xoff2) << 32 ) | \
115 (SCRRIGHT (*char3++ << ShiftAmnt, xoff3) << 32 ) | \
116 (SCRRIGHT (*char4++ << ShiftAmnt, xoff4) << 32 ) | \
117 (*char5++ << ShiftAmnt) | \
118 SCRRIGHT (*char6++ << ShiftAmnt, xoff6) | \
119 SCRRIGHT (*char7++ << ShiftAmnt, xoff7) | \
120 SCRRIGHT (*char8++ << ShiftAmnt, xoff8);
121 #endif /* PPW */
122 #else /* BITMAP_BIT_ORDER != IMAGE_BYTE_ORDER */
123 #if PPW == 32
124 #define GetBits4 c = (*char1++ << ShiftAmnt) | \
125 SCRRIGHT (*char2 << ShiftAmnt, xoff2) | \
126 SCRRIGHT (*char3 << ShiftAmnt, xoff3) | \
127 SCRRIGHT (*char4 << ShiftAmnt, xoff4); \
128 char2++; char3++; char4++;
129 #else /* PPW == 64 */
130 #define GetBits4 c = ((unsigned long)(*char1++ << ShiftAmnt) << 32 ) | \
131 (SCRRIGHT (*char2 << ShiftAmnt, xoff2) << 32 ) | \
132 (SCRRIGHT (*char3 << ShiftAmnt, xoff3) << 32 ) | \
133 (SCRRIGHT (*char4 << ShiftAmnt, xoff4) << 32 ) | \
134 (*char5++ << ShiftAmnt) | \
135 SCRRIGHT (*char6 << ShiftAmnt, xoff6) | \
136 SCRRIGHT (*char7 << ShiftAmnt, xoff7) | \
137 SCRRIGHT (*char8 << ShiftAmnt, xoff8); \
138 char2++; char3++; char4++; char6++; char7++; char8++;
139 #endif /* PPW */
140 #endif /* BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER */
142 #else /* (BITMAP_BIT_ORDER != MSBFirst) || (GLYPHPADBYTES == 4) */
144 #if BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER
145 #if PPW == 32
146 #define GetBits4 c = *char1++ | \
147 SCRRIGHT (*char2++, xoff2) | \
148 SCRRIGHT (*char3++, xoff3) | \
149 SCRRIGHT (*char4++, xoff4);
150 #else /* PPW == 64 */
151 #define GetBits4 c = (unsigned long)(((*char1++) << 64 ) | \
152 (SCRRIGHT (*char2++, xoff2) << 64 ) | \
153 (SCRRIGHT (*char3++, xoff3) << 64 ) | \
154 (SCRRIGHT (*char4++, xoff4) << 64 ) | \
155 SCRRIGHT (*char5++, xoff5) | \
156 SCRRIGHT (*char6++, xoff6) | \
157 SCRRIGHT (*char7++, xoff7) | \
158 SCRRIGHT (*char8++, xoff8));
159 #endif /* PPW */
160 #else /* BITMAP_BIT_ORDER != IMAGE_BYTE_ORDER */
161 #if PPW == 32
162 #define GetBits4 c = *char1++ | \
163 SCRRIGHT (*char2, xoff2) | \
164 SCRRIGHT (*char3, xoff3) | \
165 SCRRIGHT (*char4, xoff4); \
166 char2++; char3++; char4++;
167 #else /* PPW == 64 */
168 #define GetBits4 c = (unsigned long)(((*char1++) << 64 ) | \
169 (SCRRIGHT (*char2, xoff2) << 64 ) | \
170 (SCRRIGHT (*char3, xoff3) << 64 ) | \
171 (SCRRIGHT (*char4, xoff4) << 64 ) | \
172 SCRRIGHT (*char5, xoff5) | \
173 SCRRIGHT (*char6, xoff6) | \
174 SCRRIGHT (*char7, xoff7) | \
175 SCRRIGHT (*char8, xoff8)); \
176 char2++; char3++; char4++; \
177 char5++; char6++; char7++; char8++;
178 #endif /* PPW */
179 #endif /* BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER */
181 #endif /* BITMAP_BIT_ORDER && GLYPHPADBYTES */
184 #if GLYPHPADBYTES == 1
185 typedef unsigned char *glyphPointer;
186 #define USE_LEFTBITS
187 #endif
189 #if GLYPHPADBYTES == 2
190 typedef unsigned short *glyphPointer;
191 #define USE_LEFTBITS
192 #endif
194 #if GLYPHPADBYTES == 4
195 typedef unsigned int *glyphPointer;
196 #endif
198 #ifdef USE_LEFTBITS
199 #define GetBits1 getleftbits (char1, widthGlyph, c); \
200 c &= glyphMask; \
201 char1 = (glyphPointer) (((char *) char1) + glyphBytes);
202 #else
203 #define GetBits1 c = *char1++;
204 #endif
206 void
207 afbTEGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
208 DrawablePtr pDrawable;
209 GC *pGC;
210 int x, y;
211 unsigned int nglyph;
212 CharInfoPtr *ppci; /* array of character info */
213 pointer pglyphBase; /* start of array of glyphs */
215 FontPtr pfont = pGC->font;
216 int widthDst;
217 PixelType *pdstBase; /* pointer to longword with top row
218 of current glyph */
220 int h; /* height of glyph and char */
221 register int xpos; /* current x */
222 int ypos; /* current y */
223 int widthGlyph;
225 int hTmp; /* counter for height */
226 register PixelType startmask, endmask;
227 int nfirst; /* used if glyphs spans a longword boundary */
228 BoxRec bbox; /* for clipping */
229 int widthGlyphs;
230 int sizeDst;
231 int depthDst;
232 PixelType *saveDst;
233 register PixelType *dst;
234 register PixelType c;
235 register int d;
236 register int xoff1, xoff2, xoff3, xoff4;
237 register glyphPointer char1, char2, char3, char4;
238 glyphPointer schar1, schar2, schar3, schar4;
239 #if PPW == 64
240 register int xoff5, xoff6, xoff7, xoff8;
241 register glyphPointer char5, char6, char7, char8;
242 glyphPointer schar5, schar6, schar7, schar8;
243 #endif /* PPW */
245 unsigned char *rrops;
246 #ifdef USE_LEFTBITS
247 register PixelType glyphMask;
248 register PixelType tmpSrc;
249 register int glyphBytes;
250 #endif
252 afbGetPixelWidthSizeDepthAndPointer(pDrawable, widthDst, sizeDst, depthDst,
253 pdstBase);
255 xpos = x + pDrawable->x;
256 ypos = y + pDrawable->y;
258 widthGlyph = FONTMAXBOUNDS(pfont,characterWidth);
259 h = FONTASCENT(pfont) + FONTDESCENT(pfont);
261 xpos += FONTMAXBOUNDS(pfont,leftSideBearing);
262 ypos -= FONTASCENT(pfont);
264 rrops = ((afbPrivGCPtr) pGC->devPrivates[afbGCPrivateIndex].ptr)->rropOS;
266 bbox.x1 = xpos;
267 bbox.x2 = xpos + (widthGlyph * nglyph);
268 bbox.y1 = ypos;
269 bbox.y2 = ypos + h;
271 switch (RECT_IN_REGION(pGC->pScreen, pGC->pCompositeClip, &bbox)) {
272 case rgnPART:
273 /* this is the WRONG thing to do, but it works.
274 calling the non-terminal text is easy, but slow, given
275 what we know about the font.
277 the right thing to do is something like:
278 for each clip rectangle
279 compute at which row the glyph starts to be in it,
280 and at which row the glyph ceases to be in it
281 compute which is the first glyph inside the left
282 edge, and the last one inside the right edge
283 draw a fractional first glyph, using only
284 the rows we know are in
285 draw all the whole glyphs, using the appropriate rows
286 draw any pieces of the last glyph, using the right rows
288 this way, the code would take advantage of knowing that
289 all glyphs are the same height and don't overlap.
291 one day...
293 afbImageGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
294 case rgnOUT:
295 return;
297 pdstBase = afbScanlineDeltaNoBankSwitch(pdstBase, ypos, widthDst);
298 widthGlyphs = widthGlyph * PGSZB;
300 #ifdef USE_LEFTBITS
301 glyphMask = mfbGetendtab(widthGlyph);
302 glyphBytes = GLYPHWIDTHBYTESPADDED(*ppci);
303 #endif
305 if (nglyph >= PGSZB && widthGlyphs <= PPW) {
306 while (nglyph >= PGSZB) {
307 nglyph -= PGSZB;
308 xoff1 = xpos & PIM;
309 xoff2 = widthGlyph;
310 xoff3 = xoff2 + widthGlyph;
311 xoff4 = xoff3 + widthGlyph;
312 #if PPW == 64
313 xoff5 = xoff4 + widthGlyph;
314 xoff6 = xoff5 + widthGlyph;
315 xoff7 = xoff6 + widthGlyph;
316 xoff8 = xoff7 + widthGlyph;
317 #endif /* PPW */
318 schar1 = (glyphPointer)FONTGLYPHBITS(pglyphBase,(*ppci++));
319 schar2 = (glyphPointer)FONTGLYPHBITS(pglyphBase,(*ppci++));
320 schar3 = (glyphPointer)FONTGLYPHBITS(pglyphBase,(*ppci++));
321 schar4 = (glyphPointer)FONTGLYPHBITS(pglyphBase,(*ppci++));
322 #if PPW == 64
323 schar5 = (glyphPointer)FONTGLYPHBITS(pglyphBase,(*ppci++));
324 schar6 = (glyphPointer)FONTGLYPHBITS(pglyphBase,(*ppci++));
325 schar7 = (glyphPointer)FONTGLYPHBITS(pglyphBase,(*ppci++));
326 schar8 = (glyphPointer)FONTGLYPHBITS(pglyphBase,(*ppci++));
327 #endif /* PPW */
329 hTmp = h;
330 saveDst = afbScanlineOffset(pdstBase, (xpos >> PWSH)); /* switch now */
332 #ifndef FASTCHARS
333 if (xoff1 + widthGlyphs <= PPW) {
334 maskpartialbits (xoff1, widthGlyphs, startmask);
335 #endif
336 for (d = 0; d < depthDst; d++) {
337 hTmp = h;
338 dst = saveDst;
339 saveDst += sizeDst; /* @@@ NEXT PLANE @@@ */
341 switch (rrops[d]) {
342 case RROP_BLACK:
343 while (hTmp--) {
344 #ifdef FASTCHARS
345 FASTPUTBITS(0, xoff1, widthGlyphs, dst);
346 #else
347 *(dst) &= ~startmask;
348 #endif
349 afbScanlineInc(dst, widthDst);
351 break;
352 case RROP_WHITE:
353 while (hTmp--) {
354 #ifdef FASTCHARS
355 FASTPUTBITS(~0, xoff1, widthGlyphs, dst);
356 #else
357 *(dst) |= startmask;
358 #endif
359 afbScanlineInc(dst, widthDst);
361 break;
362 case RROP_INVERT:
363 char1 = schar1;
364 char2 = schar2;
365 char3 = schar3;
366 char4 = schar4;
367 /* XXX */
368 while (hTmp--) {
369 GetBits4
370 #ifdef FASTCHARS
371 # if BITMAP_BIT_ORDER == MSBFirst
372 c >>= PPW - widthGlyphs;
373 # endif
374 FASTPUTBITS(~c, xoff1, widthGlyphs, dst);
375 #else
376 *(dst) = ((*dst) & ~startmask) | (~SCRRIGHT(c, xoff1) & startmask);
377 #endif
378 afbScanlineInc(dst, widthDst);
380 break;
381 case RROP_COPY:
382 char1 = schar1;
383 char2 = schar2;
384 char3 = schar3;
385 char4 = schar4;
387 while (hTmp--) {
388 GetBits4
389 #ifdef FASTCHARS
390 # if BITMAP_BIT_ORDER == MSBFirst
391 c >>= PPW - widthGlyphs;
392 #endif
393 FASTPUTBITS(c, xoff1, widthGlyphs, dst);
394 #else
395 *(dst) = ((*dst) & ~startmask) | (SCRRIGHT(c, xoff1) & startmask);
396 #endif
397 afbScanlineInc(dst, widthDst);
399 break;
400 case RROP_NOP:
401 break;
402 } /* switch (rrops[d]) */
403 } /* for (d = ... ) */
404 #ifndef FASTCHARS
405 } else {
406 maskPPWbits (xoff1, widthGlyphs, startmask, endmask);
407 nfirst = PPW - xoff1;
408 for (d = 0; d < depthDst; d++) {
409 hTmp = h;
410 dst = saveDst;
411 saveDst += sizeDst; /* @@@ NEXT PLANE @@@ */
413 switch (rrops[d]) {
414 case RROP_BLACK:
415 while (hTmp--) {
416 dst[0] &= ~startmask;
417 dst[1] &= ~endmask;
418 afbScanlineInc(dst, widthDst);
420 break;
421 case RROP_WHITE:
422 while (hTmp--) {
423 dst[0] |= startmask;
424 dst[1] |= endmask;
425 afbScanlineInc(dst, widthDst);
427 break;
428 case RROP_INVERT:
429 char1 = schar1;
430 char2 = schar2;
431 char3 = schar3;
432 char4 = schar4;
434 while (hTmp--) {
435 GetBits4
436 dst[0] = (dst[0] & ~startmask) | (~SCRRIGHT(c,xoff1) & startmask);
437 dst[1] = (dst[1] & ~endmask) | (~SCRLEFT(c,nfirst) & endmask);
438 afbScanlineInc(dst, widthDst);
440 break;
441 case RROP_COPY:
442 char1 = schar1;
443 char2 = schar2;
444 char3 = schar3;
445 char4 = schar4;
447 while (hTmp--) {
448 GetBits4
449 dst[0] = (dst[0] & ~startmask) | (SCRRIGHT(c,xoff1) & startmask);
450 dst[1] = (dst[1] & ~endmask) | (SCRLEFT(c,nfirst) & endmask);
451 afbScanlineInc(dst, widthDst);
453 break;
455 case RROP_NOP:
456 break;
457 } /* switch */
458 } /* for (d = ... ) */
460 #endif
461 xpos += widthGlyphs;
465 while(nglyph--) {
466 xoff1 = xpos & PIM;
467 schar1 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
468 hTmp = h;
469 saveDst = afbScanlineOffset(pdstBase, (xpos >> PWSH));
471 if (xoff1 + widthGlyph <= PPW) {
472 maskpartialbits (xoff1, widthGlyph, startmask);
474 for (d = 0; d < depthDst; d++) {
475 hTmp = h;
476 dst = saveDst;
477 saveDst += sizeDst; /* @@@ NEXT PLANE @@@ */
478 char1 = schar1;
480 switch (rrops[d]) {
481 case RROP_BLACK:
482 while (hTmp--) {
483 (*dst) &= ~startmask;
484 afbScanlineInc(dst, widthDst);
486 break;
487 case RROP_WHITE:
488 while (hTmp--) {
489 (*dst) |= startmask;
490 afbScanlineInc(dst, widthDst);
492 break;
493 case RROP_INVERT:
494 while (hTmp--) {
495 #ifdef FASTCHARS
496 #ifdef USE_LEFTBITS
497 FASTGETBITS (char1,0,widthGlyph,c);
498 char1 = (glyphPointer) (((char *) char1) + glyphBytes);
499 #else
500 c = *char1++;
501 #if BITMAP_BIT_ORDER == MSBFirst
502 c >>= PPW - widthGlyph;
503 #endif
504 #endif
505 FASTPUTBITS (~c,xoff1,widthGlyph,dst);
506 #else
507 GetBits1
508 (*dst) = ((*dst) & ~startmask) | (~SCRRIGHT(c, xoff1) & startmask);
509 #endif
510 afbScanlineInc(dst, widthDst);
512 break;
513 case RROP_COPY:
514 while (hTmp--) {
515 #ifdef FASTCHARS
516 #ifdef USE_LEFTBITS
517 FASTGETBITS (char1,0,widthGlyph,c);
518 char1 = (glyphPointer) (((char *) char1) + glyphBytes);
519 #else
520 c = *char1++;
521 #if BITMAP_BIT_ORDER == MSBFirst
522 c >>= PPW - widthGlyph;
523 #endif
524 #endif
525 FASTPUTBITS (c,xoff1,widthGlyph,dst);
526 #else
527 GetBits1
528 (*dst) = ((*dst) & ~startmask) | (SCRRIGHT(c, xoff1) & startmask);
529 #endif
530 afbScanlineInc(dst, widthDst);
532 break;
533 case RROP_NOP:
534 break;
535 } /* switch */
536 } /* for (d = ...) */
537 } else {
538 maskPPWbits (xoff1, widthGlyph, startmask, endmask);
539 nfirst = PPW - xoff1;
541 for (d = 0; d < depthDst; d++) {
542 hTmp = h;
543 dst = saveDst;
544 saveDst += sizeDst; /* @@@ NEXT PLANE @@@ */
545 char1 = schar1;
547 switch (rrops[d]) {
548 case RROP_BLACK:
549 while (hTmp--) {
550 dst[0] &= ~startmask;
551 dst[1] &= ~endmask;
552 afbScanlineInc(dst, widthDst);
554 break;
555 case RROP_WHITE:
556 while (hTmp--) {
557 dst[0] |= startmask;
558 dst[1] |= endmask;
559 afbScanlineInc(dst, widthDst);
561 break;
562 case RROP_INVERT:
563 while (hTmp--) {
564 GetBits1
565 dst[0] = (dst[0] & ~startmask) | (~SCRRIGHT(c,xoff1) & startmask);
566 dst[1] = (dst[1] & ~endmask) | (~SCRLEFT(c,nfirst) & endmask);
567 afbScanlineInc(dst, widthDst);
569 break;
570 case RROP_COPY:
571 while (hTmp--) {
572 GetBits1
573 dst[0] = (dst[0] & ~startmask) | (SCRRIGHT(c,xoff1) & startmask);
574 dst[1] = (dst[1] & ~endmask) | (SCRLEFT(c,nfirst) & endmask);
575 afbScanlineInc(dst, widthDst);
577 break;
578 case RROP_NOP:
579 break;
580 } /* switch */
581 } /* for (d = ...) */
584 xpos += widthGlyph;