]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfbtegblt.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfbtegblt.c
1 /* $XConsortium: cfbtegblt.c,v 5.9 94/04/17 20:29:03 dpw Exp $ */
2 /* $XFree86: xc/programs/Xserver/cfb/cfbtegblt.c,v 3.0 1996/06/29 09:05:52 dawes Exp $ */
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 #include        "X.h"
51 #include        "Xmd.h"
52 #include        "Xproto.h"
53 #include        "cfb.h"
54 #include        "fontstruct.h"
55 #include        "dixfontstr.h"
56 #include        "gcstruct.h"
57 #include        "windowstr.h"
58 #include        "scrnintstr.h"
59 #include        "pixmapstr.h"
60 #include        "regionstr.h"
61 #include        "cfbmskbits.h"
62 #include        "mi.h"
63 #define MFB_CONSTS_ONLY
64 #include        "maskbits.h"
65
66 /*
67     this works for fonts with glyphs <= 32 bits wide, on an
68     arbitrarily deep display.  Use cfbTEGlyphBlt8 for 8 bit displays.
69
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.
73
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.
78
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.
82
83 */
84
85 void
86 cfbTEGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
87     DrawablePtr pDrawable;
88     GC          *pGC;
89     int         x, y;
90     unsigned int nglyph;
91     CharInfoPtr *ppci;          /* array of character info */
92     pointer     pglyphBase;     /* start of array of glyphs */
93 {
94     FontPtr     pfont = pGC->font;
95     int widthDst;
96     unsigned long *pdstBase;    /* pointer to longword with top row 
97                                    of current glyph */
98
99     int w;                      /* width of glyph and char */
100     int h;                      /* height of glyph and char */
101     register int xpos=x;        /* current x%32  */
102     int ypos=y;                 /* current y%32 */
103     register unsigned char *pglyph;
104     int widthGlyph;
105
106     register unsigned long *pdst;/* pointer to current longword in dst */
107     int hTmp;                   /* counter for height */
108     BoxRec bbox;                /* for clipping */
109
110     register int wtmp,xtemp,width;
111     unsigned long bgfill,fgfill,*ptemp,tmpDst1,tmpDst2,*pdtmp;
112     int tmpx;
113 #if PSZ == 24
114     int xIndex;
115 #endif
116
117     xpos += pDrawable->x;
118     ypos += pDrawable->y;
119
120     cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase)
121
122     wtmp = FONTMAXBOUNDS(pfont,characterWidth);
123     h = FONTASCENT(pfont) + FONTDESCENT(pfont);
124     widthGlyph = GLYPHWIDTHBYTESPADDED(*ppci);
125
126     xpos += FONTMAXBOUNDS(pfont,leftSideBearing);
127     ypos -= FONTASCENT(pfont);
128
129     bbox.x1 = xpos;
130     bbox.x2 = xpos + (wtmp * nglyph);
131     bbox.y1 = ypos;
132     bbox.y2 = ypos + h;
133
134     fgfill = PFILL(pGC->fgPixel);
135     bgfill = PFILL(pGC->bgPixel);
136
137     switch (RECT_IN_REGION(pGC->pScreen,  cfbGetCompositeClip(pGC), &bbox))
138     {
139       case rgnOUT:
140         break;
141       case rgnPART:
142         /* this is the WRONG thing to do, but it works.
143            calling the non-terminal text is easy, but slow, given
144            what we know about the font.
145
146            the right thing to do is something like:
147             for each clip rectangle
148                 compute at which row the glyph starts to be in it,
149                    and at which row the glyph ceases to be in it
150                 compute which is the first glyph inside the left
151                     edge, and the last one inside the right edge
152                 draw a fractional first glyph, using only
153                     the rows we know are in
154                 draw all the whole glyphs, using the appropriate rows
155                 draw any pieces of the last glyph, using the right rows
156
157            this way, the code would take advantage of knowing that
158            all glyphs are the same height and don't overlap.
159
160            one day...
161         */
162         miImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
163         break;
164       case rgnIN:
165
166         pdtmp = pdstBase + (widthDst * ypos);
167         while(nglyph--)
168         {
169
170             pglyph = FONTGLYPHBITS(pglyphBase, *ppci++);
171             pdst = pdtmp;
172             hTmp = h;
173
174             while (hTmp--)
175             {
176                 x = xpos;
177                 width = wtmp;
178                 xtemp = 0;
179
180                 while (width > 0)
181                 {
182 #if PSZ == 24
183                     tmpx = x & 3;
184                     w = 1;
185 #else
186                     tmpx = x & PIM;
187                     w = min(width, PPW - tmpx);
188                     w = min(w, (PGSZ - xtemp));
189 #endif
190
191 #if PSZ == 24
192                     ptemp = (unsigned long *)(pglyph + ((xtemp *3)>> 2));
193 #else
194                     ptemp = (unsigned long *)(pglyph + (xtemp >> MFB_PWSH));
195 #endif
196 #if PSZ == 24
197                     getstipplepixels24(ptemp,xtemp,0,&bgfill,&tmpDst1, xtemp);
198                     getstipplepixels24(ptemp,xtemp,1,&fgfill,&tmpDst2, xtemp);
199 #else
200                     getstipplepixels(ptemp,xtemp,w,0,&bgfill,&tmpDst1);
201                     getstipplepixels(ptemp,xtemp,w,1,&fgfill,&tmpDst2);
202 #endif
203
204                     {
205                         unsigned long tmpDst = tmpDst1 | tmpDst2;
206 #if PSZ == 24
207                         unsigned long *pdsttmp = pdst + ((x*3) >> 2);
208                         putbits24(tmpDst,tmpx,w,pdsttmp,pGC->planemask,x);
209 #else
210                         unsigned long *pdsttmp = pdst + (x >> PWSH);
211                         putbits(tmpDst,tmpx,w,pdsttmp,pGC->planemask);
212 #endif
213                     }
214                     x += w;
215                     xtemp += w;
216                     width -= w;
217                 }
218                 pglyph += widthGlyph;
219                 pdst += widthDst;
220             }
221             xpos += wtmp;
222         }     
223         break;
224     }
225 }