2 /********************************************************************
4 In this file we have GC level replacements for PolyText8/16,
5 ImageText8/16, ImageGlyphBlt and PolyGlyphBlt for TE (fixed) fonts.
6 The idea is that everything in this file is device independent.
7 The mentioned GCOps are merely wrappers for XAAGlyphBltTEColorExpansion
8 which calculates the boxes containing arbitrarily clipped text
9 and passes them to the TEGlyphRenderer which will usually be a lower
10 level XAA function which renders these clipped glyphs using
11 the basic color expansion functions exported by the chipset driver.
12 The TEGlyphRenderer itself may optionally be driver supplied to
13 facilitate work-arounds/optimizations at a higher level than usual.
15 v1.0 - Mark Vojkovich (mvojkovi@ucsd.edu)
18 ********************************************************************/
20 #ifdef HAVE_XORG_CONFIG_H
21 #include <xorg-config.h>
26 #include "xf86_OSproc.h"
29 #include <X11/fonts/font.h>
30 #include "scrnintstr.h"
31 #include "dixfontstr.h"
36 #include "pixmapstr.h"
39 static void XAAGlyphBltTEColorExpansion(ScrnInfoPtr pScrn, int xInit,
40 int yInit, FontPtr font, int fg, int bg, int rop,
41 unsigned int planemask, RegionPtr cclip, int nglyph,
42 unsigned char* gBase, CharInfoPtr *ppci);
45 /********************************************************************
47 GC level replacements for PolyText8/16 and ImageText8/16
48 for TE fonts when using color expansion.
50 ********************************************************************/
54 XAAPolyText8TEColorExpansion(
61 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
64 (*pGC->font->get_glyphs)(pGC->font, (unsigned long)count,
65 (unsigned char *)chars, Linear8Bit, &n, infoRec->CharInfo);
67 /* we have divorced XAAGlyphBltTEColorExpansion from the drawable */
68 if(n) XAAGlyphBltTEColorExpansion(
69 infoRec->pScrn, x + pDraw->x, y + pDraw->y,
70 pGC->font, pGC->fgPixel, -1, pGC->alu, pGC->planemask,
71 pGC->pCompositeClip, n, FONTGLYPHS(pGC->font), infoRec->CharInfo);
73 return (x + (n * FONTMAXBOUNDS(pGC->font, characterWidth)));
78 XAAPolyText16TEColorExpansion(
83 unsigned short *chars )
85 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
88 (*pGC->font->get_glyphs)(
89 pGC->font, (unsigned long)count, (unsigned char *)chars,
90 (FONTLASTROW(pGC->font) == 0) ? Linear16Bit : TwoD16Bit,
91 &n, infoRec->CharInfo);
93 if(n) XAAGlyphBltTEColorExpansion(
94 infoRec->pScrn, x + pDraw->x, y + pDraw->y,
95 pGC->font, pGC->fgPixel, -1, pGC->alu, pGC->planemask,
96 pGC->pCompositeClip, n, FONTGLYPHS(pGC->font), infoRec->CharInfo);
98 return (x + (n * FONTMAXBOUNDS(pGC->font, characterWidth)));
103 XAAImageText8TEColorExpansion(
110 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
113 if(!RegionNumRects(pGC->pCompositeClip))
116 (*pGC->font->get_glyphs)(pGC->font, (unsigned long)count,
117 (unsigned char *)chars, Linear8Bit, &n, infoRec->CharInfo);
119 if(n) XAAGlyphBltTEColorExpansion(
120 infoRec->pScrn, x + pDraw->x, y + pDraw->y,
121 pGC->font, pGC->fgPixel, pGC->bgPixel, GXcopy, pGC->planemask,
122 pGC->pCompositeClip, n, FONTGLYPHS(pGC->font), infoRec->CharInfo);
127 XAAImageText16TEColorExpansion(
132 unsigned short *chars )
134 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
137 if(!RegionNumRects(pGC->pCompositeClip))
140 (*pGC->font->get_glyphs)(
141 pGC->font, (unsigned long)count, (unsigned char *)chars,
142 (FONTLASTROW(pGC->font) == 0) ? Linear16Bit : TwoD16Bit,
143 &n, infoRec->CharInfo);
145 if(n) XAAGlyphBltTEColorExpansion(
146 infoRec->pScrn, x + pDraw->x, y + pDraw->y,
147 pGC->font, pGC->fgPixel, pGC->bgPixel, GXcopy, pGC->planemask,
148 pGC->pCompositeClip, n, FONTGLYPHS(pGC->font), infoRec->CharInfo);
153 /********************************************************************
155 GC level replacements for ImageGlyphBlt and PolyGlyphBlt for
156 TE fonts when using color expansion.
158 ********************************************************************/
162 XAAImageGlyphBltTEColorExpansion(
163 DrawablePtr pDrawable,
165 int xInit, int yInit,
170 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
172 if(!RegionNumRects(pGC->pCompositeClip))
175 XAAGlyphBltTEColorExpansion(
176 infoRec->pScrn, xInit + pDrawable->x, yInit + pDrawable->y,
177 pGC->font, pGC->fgPixel, pGC->bgPixel, GXcopy, pGC->planemask,
178 pGC->pCompositeClip, nglyph, (unsigned char*)pglyphBase, ppci);
182 XAAPolyGlyphBltTEColorExpansion(
183 DrawablePtr pDrawable,
185 int xInit, int yInit,
190 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
192 if(!RegionNumRects(pGC->pCompositeClip))
195 XAAGlyphBltTEColorExpansion(
196 infoRec->pScrn, xInit + pDrawable->x, yInit + pDrawable->y,
197 pGC->font, pGC->fgPixel, -1, pGC->alu, pGC->planemask,
198 pGC->pCompositeClip, nglyph, (unsigned char*)pglyphBase, ppci);
204 /********************************************************************
206 XAAGlyphBltTEColorExpansion -
208 This guy computes the clipped pieces of text and sends it to
209 the lower-level function which will handle acceleration of
210 arbitrarily clipped text.
212 ********************************************************************/
216 XAAGlyphBltTEColorExpansion(
218 int xInit, int yInit,
222 unsigned int planemask,
225 unsigned char* gBase,
228 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
229 int skippix, skipglyphs;
230 int Left, Right, Top, Bottom;
231 int LeftEdge, RightEdge, ytop, ybot;
232 int nbox = RegionNumRects(cclip);
233 BoxPtr pbox = RegionRects(cclip);
234 unsigned int **glyphs = NULL;
235 int glyphWidth = FONTMAXBOUNDS(font, characterWidth);
237 /* find the size of the box */
239 Right = Left + (glyphWidth * nglyph);
240 Top = yInit - FONTASCENT(font);
241 Bottom = yInit + FONTDESCENT(font);
243 /* get into the first band that may contain part of our string */
244 while(nbox && (Top >= pbox->y2)) {
248 /* stop when the lower edge of the box is beyond our string */
249 while(nbox && (Bottom > pbox->y1)) {
250 LeftEdge = max(Left, pbox->x1);
251 RightEdge = min(Right, pbox->x2);
253 if(RightEdge > LeftEdge) { /* we have something to draw */
254 unsigned int *fallbackBits = NULL;
255 ytop = max(Top, pbox->y1);
256 ybot = min(Bottom, pbox->y2);
258 if((skippix = LeftEdge - Left)) {
259 skipglyphs = skippix/glyphWidth;
260 skippix %= glyphWidth;
261 } else skipglyphs = 0;
265 glyphs = (unsigned int**)(infoRec->PreAllocMem);
267 for(count = 0; count < nglyph; count++) {
268 glyphs[count] = (unsigned int*)
269 FONTGLYPHBITS(gBase,*ppci++);
270 if (!glyphs[count]) {
271 /* Glyphs with NULL bits do exist in the wild.
272 Replace with blank bits in that case */
275 int fontHeight = Bottom - Top + 1;
276 fallbackBits = calloc(glyphWidth * fontHeight, 1);
280 glyphs[count] = fallbackBits;
284 /* our new unrolled TE code only writes DWORDS at a time
285 so it can read up to 6 characters past the last one
287 glyphs[count + 0] = glyphs[0];
288 glyphs[count + 1] = glyphs[0];
289 glyphs[count + 2] = glyphs[0];
290 glyphs[count + 3] = glyphs[0];
291 glyphs[count + 4] = glyphs[0];
292 glyphs[count + 5] = glyphs[0];
295 /* x, y, w, h, skipleft, skiptop, glyphp, glyphWidth, fg, bg, rop, pm */
297 (*infoRec->TEGlyphRenderer)( pScrn,
298 LeftEdge, ytop, RightEdge - LeftEdge, ybot - ytop,
299 skippix, ytop - Top, glyphs + skipglyphs, glyphWidth,
300 fg, bg, rop, planemask);