summaryrefslogtreecommitdiff
path: root/hw/xfree86/xaa/xaaNonTEGlyph.c
blob: 514a8cf42821ba2d39e1a4619b61e7337e7e844e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* $XFree86: xc/programs/Xserver/hw/xfree86/xaa/xaaNonTEGlyph.c,v 1.4 1998/09/13 05:23:55 dawes Exp $ */


#include "xaa.h"
#include "xaalocal.h"
#include "xaacexp.h"
#include "xf86.h"
#include "xf86_ansic.h"

/* Not used anymore because the algorithm isn't correct. It doesn't
   handle overlapping characters properly */

#ifdef TRIPLE_BITS
#define NonTEGlyphFunc EXPNAME(XAANonTEGlyphScanlineFunc3)
#else
#define NonTEGlyphFunc EXPNAME(XAANonTEGlyphScanlineFunc)
#endif

/********************************************************************

   Here we have NonTEGlyphRenders for a bunch of different color
   expansion types.  The driver may provide its own renderer, but
   this is the default one which renders using lower-level primitives
   exported by the chipset driver.

********************************************************************/

/* Since the dimensions of the text string and the backing rectangle
	do not always coincide, it is possible that wBack or wText
	may be 0!  The NonTEGlyphRender must always check for this. */

/* This gets built for MSBFIRST or LSBFIRST with FIXEDBASE or not,
	with TRIPLE_BITS or not. A total of 8 versions */

/* if the backing rectangle and text are of the same dimensions
	then we can draw in one pass */

void 
#ifdef TRIPLE_BITS
EXPNAME(XAANonTEGlyphRenderer3)(
#else
EXPNAME(XAANonTEGlyphRenderer)(
#endif
    ScrnInfoPtr pScrn,
    int xText, int wText, 
    int y, int h, int skipleft, int startline, 
    NonTEGlyphInfo *glyphp,
    int fg, int rop,
    unsigned int planemask )
{
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
    CARD32* base = (CARD32*)infoRec->ColorExpandBase;
#ifdef TRIPLE_BITS
    int dwords = ((3 * wText + 31) >> 5) * h;
#else
    int dwords = ((wText + 31) >> 5) * h;
#endif

    (*infoRec->SetupForCPUToScreenColorExpandFill)(
					pScrn, fg, -1, rop, planemask);
    (*infoRec->SubsequentCPUToScreenColorExpandFill)(
					pScrn, xText, y, wText, h, 0);

#ifndef FIXEDBASE
#ifdef TRIPLE_BITS
    if((((3 * wText + 31) >> 5) * h) <= infoRec->ColorExpandRange)
#else
    if((((wText + 31) >> 5) * h) <= infoRec->ColorExpandRange)
#endif
	while(h--) 
	    base = NonTEGlyphFunc(base, glyphp, startline++, wText, skipleft);
    else
#endif
	while(h--)
	    NonTEGlyphFunc(base, glyphp, startline++, wText, skipleft);

    if((infoRec->CPUToScreenColorExpandFillFlags & CPU_TRANSFER_PAD_QWORD) &&
			(dwords & 1)) {
	base = (CARD32*)infoRec->ColorExpandBase;
	base[0] = 0x00000000;
    }

    if(infoRec->CPUToScreenColorExpandFillFlags & SYNC_AFTER_COLOR_EXPAND) 
	(*infoRec->Sync)(pScrn);
    else SET_SYNC_FLAG(infoRec);
}

#ifndef FIXEDBASE
/*  Scanline version of above gets built for LSBFIRST and MSBFIRST */

void 
#ifdef TRIPLE_BITS
EXPNAME(XAANonTEGlyphRendererScanline3)(
#else
EXPNAME(XAANonTEGlyphRendererScanline)(
#endif
    ScrnInfoPtr pScrn,
    int xText, int wText, 
    int y, int h, int skipleft, int startline, 
    NonTEGlyphInfo *glyphp,
    int fg, int rop,
    unsigned int planemask )
{
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
    int bufferNo = 0;
    CARD32* base;

    (*infoRec->SetupForScanlineCPUToScreenColorExpandFill)(
				pScrn, fg, -1, rop, planemask);
    (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill)(
				pScrn, xText, y, wText, h, 0);

    while(h--) {
	base = (CARD32*)infoRec->ScanlineColorExpandBuffers[bufferNo];
	NonTEGlyphFunc(base, glyphp, startline++, wText, skipleft);
	(*infoRec->SubsequentColorExpandScanline)(pScrn, bufferNo++);
	if(bufferNo >= infoRec->NumScanlineColorExpandBuffers)
	    bufferNo = 0;
    }

    SET_SYNC_FLAG(infoRec);
}

#endif

/********************************************************************

   Generic NonTE scanline rendering code.

********************************************************************/


CARD32* 
NonTEGlyphFunc(
    CARD32 *base,
    NonTEGlyphInfo *glyphp,
    int line, int TotalWidth, int skipleft )
{
    CARD32 bits = 0;
    int shift = glyphp->width; 

    if(skipleft) {
	if((line >= glyphp->firstline) && (line <= glyphp->lastline))
            bits = SHIFT_R(glyphp->bitsp[line], skipleft);
	shift -= skipleft;
    } else if((line >= glyphp->firstline) && (line <= glyphp->lastline))
            bits =  glyphp->bitsp[line];
 

    while(TotalWidth > 32) {
	while(shift < 32) {
	    glyphp++;
	    if((line >= glyphp->firstline) && (line <= glyphp->lastline)) 
		bits |= SHIFT_L(glyphp->bitsp[line],shift);
	    shift += glyphp->width;	
	}
#ifdef TRIPLE_BITS
	WRITE_BITS3(bits);
#else
	WRITE_BITS(bits);
#endif
	shift &= 31;
	if(shift && 
	 (line >= glyphp->firstline) && (line <= glyphp->lastline)) 
           bits = SHIFT_R(glyphp->bitsp[line], glyphp->width - shift);
	else bits = 0;
	TotalWidth -= 32;
    }

    if(TotalWidth) {
	TotalWidth -= shift;
	while(TotalWidth > 0) {
	     glyphp++;
	     if((line >= glyphp->firstline) && (line <= glyphp->lastline)) 
		bits |= SHIFT_L(glyphp->bitsp[line], shift);
	     shift += glyphp->width;
	     TotalWidth -= glyphp->width;
	}
#ifdef TRIPLE_BITS
	if (shift >= 22) {
	    WRITE_BITS3(bits);
	} else if (shift >= 11) {
	    WRITE_BITS2(bits);
	} else {
	    WRITE_BITS1(bits);
	}
#else
	WRITE_BITS(bits);
#endif
    }

  
    return base;
}