Initial commit
[xorg_rtime.git] / xorg-server-1.4 / cfb / cfbtegblt.c
blobf04ee3fafdb0d57ddffd4d85464cde6671e6aabe
1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28 All Rights Reserved
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
46 ******************************************************************/
48 #ifdef HAVE_DIX_CONFIG_H
49 #include <dix-config.h>
50 #endif
52 #include <X11/X.h>
53 #include <X11/Xmd.h>
54 #include <X11/Xproto.h>
55 #include "cfb.h"
56 #include <X11/fonts/fontstruct.h>
57 #include "dixfontstr.h"
58 #include "gcstruct.h"
59 #include "windowstr.h"
60 #include "scrnintstr.h"
61 #include "pixmapstr.h"
62 #include "regionstr.h"
63 #include "cfbmskbits.h"
64 #include "mi.h"
65 #define MFB_CONSTS_ONLY
66 #include "maskbits.h"
69 this works for fonts with glyphs <= 32 bits wide, on an
70 arbitrarily deep display. Use cfbTEGlyphBlt8 for 8 bit displays.
72 This should be called only with a terminal-emulator font;
73 this means that the FIXED_METRICS flag is set, and that
74 glyphbounds == charbounds.
76 in theory, this goes faster; even if it doesn't, it reduces the
77 flicker caused by writing a string over itself with image text (since
78 the background gets repainted per character instead of per string.)
79 this seems to be important for some converted X10 applications.
81 Image text looks at the bits in the glyph and the fg and bg in the
82 GC. it paints a rectangle, as defined in the protocol dcoument,
83 and the paints the characters.
87 void
88 cfbTEGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
89 DrawablePtr pDrawable;
90 GC *pGC;
91 int x, y;
92 unsigned int nglyph;
93 CharInfoPtr *ppci; /* array of character info */
94 pointer pglyphBase; /* start of array of glyphs */
96 FontPtr pfont = pGC->font;
97 int widthDst;
98 CfbBits *pdstBase; /* pointer to longword with top row
99 of current glyph */
101 int w; /* width of glyph and char */
102 int h; /* height of glyph and char */
103 register int xpos=x; /* current x%32 */
104 int ypos=y; /* current y%32 */
105 register unsigned char *pglyph;
106 int widthGlyph;
108 register CfbBits *pdst;/* pointer to current longword in dst */
109 int hTmp; /* counter for height */
110 BoxRec bbox; /* for clipping */
112 register int wtmp,xtemp,width;
113 CfbBits bgfill,fgfill,*ptemp,tmpDst1,tmpDst2,*pdtmp;
114 #if PSZ != 24
115 int tmpx;
116 #endif
118 xpos += pDrawable->x;
119 ypos += pDrawable->y;
121 cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase)
123 wtmp = FONTMAXBOUNDS(pfont,characterWidth);
124 h = FONTASCENT(pfont) + FONTDESCENT(pfont);
125 widthGlyph = GLYPHWIDTHBYTESPADDED(*ppci);
127 xpos += FONTMAXBOUNDS(pfont,leftSideBearing);
128 ypos -= FONTASCENT(pfont);
130 bbox.x1 = xpos;
131 bbox.x2 = xpos + (wtmp * nglyph);
132 bbox.y1 = ypos;
133 bbox.y2 = ypos + h;
135 fgfill = PFILL(pGC->fgPixel);
136 bgfill = PFILL(pGC->bgPixel);
138 switch (RECT_IN_REGION(pGC->pScreen, cfbGetCompositeClip(pGC), &bbox))
140 case rgnOUT:
141 break;
142 case rgnPART:
143 /* this is the WRONG thing to do, but it works.
144 calling the non-terminal text is easy, but slow, given
145 what we know about the font.
147 the right thing to do is something like:
148 for each clip rectangle
149 compute at which row the glyph starts to be in it,
150 and at which row the glyph ceases to be in it
151 compute which is the first glyph inside the left
152 edge, and the last one inside the right edge
153 draw a fractional first glyph, using only
154 the rows we know are in
155 draw all the whole glyphs, using the appropriate rows
156 draw any pieces of the last glyph, using the right rows
158 this way, the code would take advantage of knowing that
159 all glyphs are the same height and don't overlap.
161 one day...
163 cfbImageGlyphBlt8(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
164 break;
165 case rgnIN:
167 pdtmp = pdstBase + (widthDst * ypos);
168 while(nglyph--)
171 pglyph = FONTGLYPHBITS(pglyphBase, *ppci++);
172 pdst = pdtmp;
173 hTmp = h;
175 while (hTmp--)
177 x = xpos;
178 width = wtmp;
179 xtemp = 0;
181 while (width > 0)
183 #if PSZ == 24
184 w = 1;
185 ptemp = (CfbBits *)(pglyph + ((xtemp *3)>> 2));
186 getstipplepixels24(ptemp,xtemp,0,&bgfill,&tmpDst1, xtemp);
187 getstipplepixels24(ptemp,xtemp,1,&fgfill,&tmpDst2, xtemp);
188 #else
189 tmpx = x & PIM;
190 w = min(width, PPW - tmpx);
191 w = min(w, (PGSZ - xtemp));
192 ptemp = (CfbBits *)(pglyph + (xtemp >> MFB_PWSH));
193 getstipplepixels(ptemp,xtemp,w,0,&bgfill,&tmpDst1);
194 getstipplepixels(ptemp,xtemp,w,1,&fgfill,&tmpDst2);
195 #endif
198 CfbBits tmpDst = tmpDst1 | tmpDst2;
199 #if PSZ == 24
200 CfbBits *pdsttmp = pdst + ((x*3) >> 2);
201 putbits24(tmpDst,w,pdsttmp,pGC->planemask,x);
202 #else
203 CfbBits *pdsttmp = pdst + (x >> PWSH);
204 putbits(tmpDst,tmpx,w,pdsttmp,pGC->planemask);
205 #endif
207 x += w;
208 xtemp += w;
209 width -= w;
211 pglyph += widthGlyph;
212 pdst += widthDst;
214 xpos += wtmp;
216 break;