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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
/*
*
* Copyright © 1998 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "fb.h"
#include <X11/fonts/fontstruct.h>
#include "dixfontstr.h"
#define dummyScreen screenInfo.screens[0]
_X_EXPORT Bool
fbGlyphIn (RegionPtr pRegion,
int x,
int y,
int width,
int height)
{
BoxRec box;
BoxPtr pExtents = REGION_EXTENTS (dummyScreen, pRegion);
/*
* Check extents by hand to avoid 16 bit overflows
*/
if (x < (int) pExtents->x1)
return FALSE;
if ((int) pExtents->x2 < x + width)
return FALSE;
if (y < (int) pExtents->y1)
return FALSE;
if ((int) pExtents->y2 < y + height)
return FALSE;
box.x1 = x;
box.x2 = x + width;
box.y1 = y;
box.y2 = y + height;
return RECT_IN_REGION (dummyScreen, pRegion, &box) == rgnIN;
}
#ifdef FB_24BIT
#ifndef FBNOPIXADDR
#define WRITE1(d,n,fg) WRITE((d) + (n), (CARD8) fg)
#define WRITE2(d,n,fg) WRITE((CARD16 *) &(d[n]), (CARD16) fg)
#define WRITE4(d,n,fg) WRITE((CARD32 *) &(d[n]), (CARD32) fg)
#if FB_UNIT == 6 && IMAGE_BYTE_ORDER == LSBFirst
#define WRITE8(d) WRITE((FbBits *) &(d[0]), fg)
#else
#define WRITE8(d) WRITE4(d,0,_ABCA), WRITE4(d,4,_BCAB)
#endif
/*
* This is a bit tricky, but it's brief. Write 12 bytes worth
* of dest, which is four pixels, at a time. This gives constant
* code for each pattern as they're always aligned the same
*
* a b c d a b c d a b c d bytes
* A B C A B C A B C A B C pixels
*
* f0 f1 f2
* A B C A B C A B C A B C pixels LSB
* C A B C A B C A B C A B pixels MSB
*
* LSB MSB
* A f0 f1
* B f1 f2
* C f2 f0
* A B f0 f2
* B C f1 f0
* C A f2 f1
* A B C A f0 f1
* B C A B f1 f2
* C A B C f2 f0
*/
#undef _A
#undef _B
#undef _C
#undef _AB
#undef _BC
#undef _CA
#undef _ABCA
#undef _BCAB
#undef _CABC
#if IMAGE_BYTE_ORDER == MSBFirst
#define _A f1
#define _B f2
#define _C f0
#define _AB f2
#define _BC f0
#define _CA f1
#define _ABCA f1
#define _BCAB f2
#define _CABC f0
#define CASE(a,b,c,d) ((a << 3) | (b << 2) | (c << 1) | d)
#else
#define _A f0
#define _B f1
#define _C f2
#define _AB f0
#define _BC f1
#define _CA f2
#define _ABCA f0
#define _BCAB f1
#define _CABC f2
#define CASE(a,b,c,d) (a | (b << 1) | (c << 2) | (d << 3))
#endif
_X_EXPORT void
fbGlyph24 (FbBits *dstBits,
FbStride dstStride,
int dstBpp,
FbStip *stipple,
FbBits fg,
int x,
int height)
{
int lshift;
FbStip bits;
CARD8 *dstLine;
CARD8 *dst;
FbStip f0, f1, f2;
int n;
int shift;
f0 = fg;
f1 = FbRot24(f0,16);
f2 = FbRot24(f0,8);
dstLine = (CARD8 *) dstBits;
dstLine += (x & ~3) * 3;
dstStride *= (sizeof (FbBits) / sizeof (CARD8));
shift = x & 3;
lshift = 4 - shift;
while (height--)
{
bits = READ(stipple++);
n = lshift;
dst = dstLine;
while (bits)
{
switch (FbStipMoveLsb (FbLeftStipBits (bits, n), 4, n)) {
case CASE(0,0,0,0):
break;
case CASE(1,0,0,0):
WRITE2(dst,0,_AB);
WRITE1(dst,2,_C);
break;
case CASE(0,1,0,0):
WRITE1(dst,3,_A);
WRITE2(dst,4,_BC);
break;
case CASE(1,1,0,0):
WRITE4(dst,0,_ABCA);
WRITE2(dst,4,_BC);
break;
case CASE(0,0,1,0):
WRITE2(dst,6,_AB);
WRITE1(dst,8,_C);
break;
case CASE(1,0,1,0):
WRITE2(dst,0,_AB);
WRITE1(dst,2,_C);
WRITE2(dst,6,_AB);
WRITE1(dst,8,_C);
break;
case CASE(0,1,1,0):
WRITE1(dst,3,_A);
WRITE4(dst,4,_BCAB);
WRITE1(dst,8,_C);
break;
case CASE(1,1,1,0):
WRITE8(dst);
WRITE1(dst,8,_C);
break;
case CASE(0,0,0,1):
WRITE1(dst,9,_A);
WRITE2(dst,10,_BC);
break;
case CASE(1,0,0,1):
WRITE2(dst,0,_AB);
WRITE1(dst,2,_C);
WRITE1(dst,9,_A);
WRITE2(dst,10,_BC);
break;
case CASE(0,1,0,1):
WRITE1(dst,3,_A);
WRITE2(dst,4,_BC);
WRITE1(dst,9,_A);
WRITE2(dst,10,_BC);
break;
case CASE(1,1,0,1):
WRITE4(dst,0,_ABCA);
WRITE2(dst,4,_BC);
WRITE1(dst,9,_A);
WRITE2(dst,10,_BC);
break;
case CASE(0,0,1,1):
WRITE2(dst,6,_AB);
WRITE4(dst,8,_CABC);
break;
case CASE(1,0,1,1):
WRITE2(dst,0,_AB);
WRITE1(dst,2,_C);
WRITE2(dst,6,_AB);
WRITE4(dst,8,_CABC);
break;
case CASE(0,1,1,1):
WRITE1(dst,3,_A);
WRITE4(dst,4,_BCAB);
WRITE4(dst,8,_CABC);
break;
case CASE(1,1,1,1):
WRITE8(dst);
WRITE4(dst,8,_CABC);
break;
}
bits = FbStipLeft (bits, n);
n = 4;
dst += 12;
}
dstLine += dstStride;
}
}
#endif
#endif
_X_EXPORT void
fbPolyGlyphBlt (DrawablePtr pDrawable,
GCPtr pGC,
int x,
int y,
unsigned int nglyph,
CharInfoPtr *ppci,
pointer pglyphBase)
{
FbGCPrivPtr pPriv = fbGetGCPrivate (pGC);
CharInfoPtr pci;
unsigned char *pglyph; /* pointer bits in glyph */
int gx, gy;
int gWidth, gHeight; /* width and height of glyph */
FbStride gStride; /* stride of glyph */
#ifndef FBNOPIXADDR
void (*glyph) (FbBits *,
FbStride,
int,
FbStip *,
FbBits,
int,
int);
FbBits *dst = 0;
FbStride dstStride = 0;
int dstBpp = 0;
int dstXoff = 0, dstYoff = 0;
glyph = 0;
if (pGC->fillStyle == FillSolid && pPriv->and == 0)
{
dstBpp = pDrawable->bitsPerPixel;
switch (dstBpp) {
case 8: glyph = fbGlyph8; break;
case 16: glyph = fbGlyph16; break;
#ifdef FB_24BIT
case 24: glyph = fbGlyph24; break;
#endif
case 32: glyph = fbGlyph32; break;
}
}
#endif
x += pDrawable->x;
y += pDrawable->y;
while (nglyph--)
{
pci = *ppci++;
pglyph = FONTGLYPHBITS(pglyphBase, pci);
gWidth = GLYPHWIDTHPIXELS(pci);
gHeight = GLYPHHEIGHTPIXELS(pci);
if (gWidth && gHeight)
{
gx = x + pci->metrics.leftSideBearing;
gy = y - pci->metrics.ascent;
#ifndef FBNOPIXADDR
if (glyph && gWidth <= sizeof (FbStip) * 8 &&
fbGlyphIn (fbGetCompositeClip(pGC), gx, gy, gWidth, gHeight))
{
fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
(*glyph) (dst + (gy + dstYoff) * dstStride,
dstStride,
dstBpp,
(FbStip *) pglyph,
pPriv->xor,
gx + dstXoff,
gHeight);
fbFinishAccess (pDrawable);
}
else
#endif
{
gStride = GLYPHWIDTHBYTESPADDED(pci) / sizeof (FbStip);
fbPushImage (pDrawable,
pGC,
(FbStip *) pglyph,
gStride,
0,
gx,
gy,
gWidth, gHeight);
}
}
x += pci->metrics.characterWidth;
}
}
_X_EXPORT void
fbImageGlyphBlt (DrawablePtr pDrawable,
GCPtr pGC,
int x,
int y,
unsigned int nglyph,
CharInfoPtr *ppciInit,
pointer pglyphBase)
{
FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
CharInfoPtr *ppci;
CharInfoPtr pci;
unsigned char *pglyph; /* pointer bits in glyph */
int gWidth, gHeight; /* width and height of glyph */
FbStride gStride; /* stride of glyph */
Bool opaque;
int n;
int gx, gy;
#ifndef FBNOPIXADDR
void (*glyph) (FbBits *,
FbStride,
int,
FbStip *,
FbBits,
int,
int);
FbBits *dst = 0;
FbStride dstStride = 0;
int dstBpp = 0;
int dstXoff = 0, dstYoff = 0;
glyph = 0;
if (pPriv->and == 0)
{
dstBpp = pDrawable->bitsPerPixel;
switch (dstBpp) {
case 8: glyph = fbGlyph8; break;
case 16: glyph = fbGlyph16; break;
#ifdef FB_24BIT
case 24: glyph = fbGlyph24; break;
#endif
case 32: glyph = fbGlyph32; break;
}
}
#endif
x += pDrawable->x;
y += pDrawable->y;
if (TERMINALFONT (pGC->font)
#ifndef FBNOPIXADDR
&& !glyph
#endif
)
{
opaque = TRUE;
}
else
{
int xBack, widthBack;
int yBack, heightBack;
ppci = ppciInit;
n = nglyph;
widthBack = 0;
while (n--)
widthBack += (*ppci++)->metrics.characterWidth;
xBack = x;
if (widthBack < 0)
{
xBack += widthBack;
widthBack = -widthBack;
}
yBack = y - FONTASCENT(pGC->font);
heightBack = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
fbSolidBoxClipped (pDrawable,
fbGetCompositeClip(pGC),
xBack,
yBack,
xBack + widthBack,
yBack + heightBack,
fbAnd(GXcopy,pPriv->bg,pPriv->pm),
fbXor(GXcopy,pPriv->bg,pPriv->pm));
opaque = FALSE;
}
ppci = ppciInit;
while (nglyph--)
{
pci = *ppci++;
pglyph = FONTGLYPHBITS(pglyphBase, pci);
gWidth = GLYPHWIDTHPIXELS(pci);
gHeight = GLYPHHEIGHTPIXELS(pci);
if (gWidth && gHeight)
{
gx = x + pci->metrics.leftSideBearing;
gy = y - pci->metrics.ascent;
#ifndef FBNOPIXADDR
if (glyph && gWidth <= sizeof (FbStip) * 8 &&
fbGlyphIn (fbGetCompositeClip(pGC), gx, gy, gWidth, gHeight))
{
fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
(*glyph) (dst + (gy + dstYoff) * dstStride,
dstStride,
dstBpp,
(FbStip *) pglyph,
pPriv->fg,
gx + dstXoff,
gHeight);
fbFinishAccess (pDrawable);
}
else
#endif
{
gStride = GLYPHWIDTHBYTESPADDED(pci) / sizeof (FbStip);
fbPutXYImage (pDrawable,
fbGetCompositeClip(pGC),
pPriv->fg,
pPriv->bg,
pPriv->pm,
GXcopy,
opaque,
gx,
gy,
gWidth, gHeight,
(FbStip *) pglyph,
gStride,
0);
}
}
x += pci->metrics.characterWidth;
}
}
|