~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/xaa/xaaStipple.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/xaa/xaaStipple.c,v 1.11 2001/10/28 03:34:04 tsi Exp $ */
 
2
 
 
3
#include "xaa.h"
 
4
#include "xaalocal.h"
 
5
#include "xaacexp.h"
 
6
#include "xf86.h"
 
7
#include "xf86_ansic.h"
 
8
 
 
9
static CARD32* StipplePowerOfTwo(CARD32*, CARD32*, int, int, int);
 
10
static CARD32* StipplePowerOfTwo_Inverted(CARD32*, CARD32*, int, int, int);
 
11
static CARD32* StippleUpTo32(CARD32*, CARD32*, int, int, int);
 
12
static CARD32* StippleUpTo32_Inverted(CARD32*, CARD32*, int, int, int);
 
13
static CARD32* StippleOver32(CARD32*, CARD32*, int, int, int);
 
14
static CARD32* StippleOver32_Inverted(CARD32*, CARD32*, int, int, int);
 
15
 
 
16
#ifdef TRIPLE_BITS
 
17
#define stipple_scanline_func EXPNAME(XAAStippleScanlineFunc3)
 
18
#else
 
19
#define stipple_scanline_func EXPNAME(XAAStippleScanlineFunc)
 
20
#endif
 
21
 
 
22
StippleScanlineProcPtr stipple_scanline_func[6] = {
 
23
   StipplePowerOfTwo,
 
24
   StippleUpTo32,
 
25
   StippleOver32,
 
26
   StipplePowerOfTwo_Inverted,
 
27
   StippleUpTo32_Inverted,
 
28
   StippleOver32_Inverted
 
29
};
 
30
 
 
31
 
 
32
#ifdef FIXEDBASE
 
33
# define DEST(i)        *dest
 
34
# define RETURN(i)      return(dest)
 
35
#else
 
36
# define DEST(i)        dest[i]
 
37
# define RETURN(i)      return(dest + i)
 
38
#endif
 
39
 
 
40
 
 
41
/* TRIPLE_BITS pattern expansion */
 
42
#ifdef TRIPLE_BITS
 
43
#define EXPAND_PAT \
 
44
        CARD32 pat1 = byte_expand3[pat & 0xFF], \
 
45
               pat2 = byte_expand3[(pat & 0xFF00) >> 8], \
 
46
               pat3 = byte_expand3[(pat & 0xFF0000) >> 16], \
 
47
               pat4 = byte_expand3[(pat & 0xFF000000) >> 24], \
 
48
               patA = pat1 | (pat2 << 24), \
 
49
               patB = (pat2 >> 8) | (pat3 << 16), \
 
50
               patC = (pat3 >> 16) | (pat4 << 8)
 
51
#ifdef FIXED_BASE
 
52
#define WRITE_PAT1 { \
 
53
        *dest = patA; }
 
54
#define WRITE_PAT2 { \
 
55
        *dest = patA; \
 
56
        *dest = patB; }
 
57
#define WRITE_PAT3 { \
 
58
        *dest = patA; \
 
59
        *dest = patB; \
 
60
        *dest = patC; }
 
61
#else
 
62
#define WRITE_PAT1 { \
 
63
        *(dest++) = patA; }
 
64
#define WRITE_PAT2 { \
 
65
        *(dest) = patA; \
 
66
        *(dest + 1) = patB; \
 
67
        dest += 2; }
 
68
#define WRITE_PAT3 { \
 
69
        *(dest) = patA; \
 
70
        *(dest + 1) = patB; \
 
71
        *(dest + 2) = patC; \
 
72
        dest += 3; }
 
73
#endif
 
74
#endif
 
75
 
 
76
 
 
77
#if !defined(FIXEDBASE) && !defined(MSBFIRST) && !defined(TRIPLE_BITS)
 
78
 
 
79
unsigned int XAAShiftMasks[32] = {
 
80
  /* gcc is rather pedantic about SHIFT_R(0xFFFFFFFF,32) */
 
81
          0x00000000    , SHIFT_R(0xFFFFFFFF,31),
 
82
  SHIFT_R(0xFFFFFFFF,30), SHIFT_R(0xFFFFFFFF,29),
 
83
  SHIFT_R(0xFFFFFFFF,28), SHIFT_R(0xFFFFFFFF,27),
 
84
  SHIFT_R(0xFFFFFFFF,26), SHIFT_R(0xFFFFFFFF,25),
 
85
  SHIFT_R(0xFFFFFFFF,24), SHIFT_R(0xFFFFFFFF,23),
 
86
  SHIFT_R(0xFFFFFFFF,22), SHIFT_R(0xFFFFFFFF,21),
 
87
  SHIFT_R(0xFFFFFFFF,20), SHIFT_R(0xFFFFFFFF,19),
 
88
  SHIFT_R(0xFFFFFFFF,18), SHIFT_R(0xFFFFFFFF,17),
 
89
  SHIFT_R(0xFFFFFFFF,16), SHIFT_R(0xFFFFFFFF,15),
 
90
  SHIFT_R(0xFFFFFFFF,14), SHIFT_R(0xFFFFFFFF,13),
 
91
  SHIFT_R(0xFFFFFFFF,12), SHIFT_R(0xFFFFFFFF,11),
 
92
  SHIFT_R(0xFFFFFFFF,10), SHIFT_R(0xFFFFFFFF,9),
 
93
  SHIFT_R(0xFFFFFFFF,8),  SHIFT_R(0xFFFFFFFF,7),
 
94
  SHIFT_R(0xFFFFFFFF,6),  SHIFT_R(0xFFFFFFFF,5),
 
95
  SHIFT_R(0xFFFFFFFF,4),  SHIFT_R(0xFFFFFFFF,3),
 
96
  SHIFT_R(0xFFFFFFFF,2),  SHIFT_R(0xFFFFFFFF,1)
 
97
};
 
98
 
 
99
#endif
 
100
 
 
101
void 
 
102
#ifdef TRIPLE_BITS
 
103
EXPNAME(XAAFillColorExpandRects3)(
 
104
#else
 
105
EXPNAME(XAAFillColorExpandRects)(
 
106
#endif
 
107
   ScrnInfoPtr pScrn,
 
108
   int fg, int bg, int rop,
 
109
   unsigned int planemask,
 
110
   int nBox,
 
111
   BoxPtr pBox,
 
112
   int xorg, int yorg,
 
113
   PixmapPtr pPix
 
114
){
 
115
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
 
116
    CARD32 *base;
 
117
    Bool TwoPass = FALSE, FirstPass = TRUE;
 
118
    StippleScanlineProcPtr StippleFunc, FirstFunc, SecondFunc;
 
119
    int stipplewidth = pPix->drawable.width;
 
120
    int stippleheight = pPix->drawable.height;
 
121
    int srcwidth = pPix->devKind;
 
122
    int dwords, srcy, srcx, funcNo = 2, h;
 
123
    unsigned char *src = (unsigned char*)pPix->devPrivate.ptr;
 
124
    unsigned char *srcp;
 
125
    int flag;
 
126
 
 
127
    if(stipplewidth <= 32) {
 
128
        if(stipplewidth & (stipplewidth - 1))   
 
129
          funcNo = 1;
 
130
        else    
 
131
          funcNo = 0;
 
132
    } 
 
133
    StippleFunc = stipple_scanline_func[funcNo];
 
134
    SecondFunc = stipple_scanline_func[funcNo];
 
135
    FirstFunc = stipple_scanline_func[funcNo + 3];
 
136
 
 
137
#ifdef TRIPLE_BITS
 
138
    if((bg == -1) || 
 
139
        (!(infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY) &&
 
140
        (!(infoRec->CPUToScreenColorExpandFillFlags & RGB_EQUAL) ||
 
141
        (CHECK_RGB_EQUAL(bg))))) {
 
142
#else
 
143
    if((bg == -1) || 
 
144
        !(infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
 
145
#endif
 
146
        /* one pass */
 
147
    } else if((rop == GXcopy) && infoRec->FillSolidRects) {
 
148
        /* one pass but we fill background rects first */
 
149
        (*infoRec->FillSolidRects)(pScrn, bg, rop, planemask, nBox, pBox);
 
150
        bg = -1;
 
151
    } else {
 
152
        /* gotta do two passes */
 
153
        TwoPass = TRUE;
 
154
    }
 
155
 
 
156
    if(!TwoPass)
 
157
        (*infoRec->SetupForCPUToScreenColorExpandFill)(
 
158
                                        pScrn, fg, bg, rop, planemask);
 
159
 
 
160
    while(nBox--) {
 
161
#ifdef TRIPLE_BITS
 
162
        dwords = (3 * (pBox->x2 - pBox->x1) + 31) >> 5;
 
163
#else
 
164
        dwords = (pBox->x2 - pBox->x1 + 31) >> 5;
 
165
#endif
 
166
 
 
167
SECOND_PASS:
 
168
        if(TwoPass) {
 
169
            (*infoRec->SetupForCPUToScreenColorExpandFill)(pScrn, 
 
170
                        (FirstPass) ? bg : fg, -1, rop, planemask);
 
171
            StippleFunc = (FirstPass) ? FirstFunc : SecondFunc;
 
172
        }
 
173
 
 
174
        h = pBox->y2 - pBox->y1;
 
175
        flag = (infoRec->CPUToScreenColorExpandFillFlags 
 
176
                & CPU_TRANSFER_PAD_QWORD) && ((dwords * h) & 0x01);
 
177
 
 
178
        (*infoRec->SubsequentCPUToScreenColorExpandFill)(
 
179
                        pScrn, pBox->x1, pBox->y1,
 
180
                        pBox->x2 - pBox->x1, h, 0);
 
181
 
 
182
        base = (CARD32*)infoRec->ColorExpandBase;
 
183
 
 
184
        srcy = (pBox->y1 - yorg) % stippleheight;
 
185
        if(srcy < 0) srcy += stippleheight;
 
186
        srcx = (pBox->x1 - xorg) % stipplewidth;
 
187
        if(srcx < 0) srcx += stipplewidth;
 
188
 
 
189
        srcp = (srcwidth * srcy) + src;
 
190
        
 
191
#ifndef FIXEDBASE
 
192
        if((dwords * h) <= infoRec->ColorExpandRange) {
 
193
           while(h--) {
 
194
                base = (*StippleFunc)(
 
195
                        base, (CARD32*)srcp, srcx, stipplewidth, dwords);
 
196
                srcy++;
 
197
                srcp += srcwidth;
 
198
                if (srcy >= stippleheight) {
 
199
                   srcy = 0;
 
200
                   srcp = src;
 
201
                }
 
202
           }
 
203
        } else
 
204
#endif
 
205
           while(h--) {
 
206
                (*StippleFunc)(base, (CARD32*)srcp, srcx, stipplewidth, dwords);
 
207
                srcy++;
 
208
                srcp += srcwidth;
 
209
                if (srcy >= stippleheight) {
 
210
                   srcy = 0;
 
211
                   srcp = src;
 
212
                }
 
213
           }
 
214
    
 
215
          if (flag) {
 
216
              base = (CARD32*)infoRec->ColorExpandBase;
 
217
              base[0] = 0x00000000;
 
218
          }
 
219
 
 
220
        if(TwoPass) {
 
221
           if(FirstPass) {
 
222
                FirstPass = FALSE;
 
223
                goto SECOND_PASS;
 
224
           } else FirstPass = TRUE;
 
225
        }
 
226
 
 
227
        pBox++;
 
228
     }
 
229
 
 
230
    if(infoRec->CPUToScreenColorExpandFillFlags & SYNC_AFTER_COLOR_EXPAND) 
 
231
        (*infoRec->Sync)(pScrn);
 
232
    else SET_SYNC_FLAG(infoRec);
 
233
}
 
234
 
 
235
 
 
236
 
 
237
void 
 
238
#ifdef TRIPLE_BITS
 
239
EXPNAME(XAAFillColorExpandSpans3)(
 
240
#else
 
241
EXPNAME(XAAFillColorExpandSpans)(
 
242
#endif
 
243
   ScrnInfoPtr pScrn,
 
244
   int fg, int bg, int rop,
 
245
   unsigned int planemask,
 
246
   int n,
 
247
   DDXPointPtr ppt,
 
248
   int *pwidth,
 
249
   int fSorted,
 
250
   int xorg, int yorg,
 
251
   PixmapPtr pPix
 
252
){
 
253
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
 
254
    CARD32 *base;
 
255
    Bool TwoPass = FALSE, FirstPass = TRUE;
 
256
    StippleScanlineProcPtr StippleFunc, FirstFunc, SecondFunc;
 
257
    int stipplewidth = pPix->drawable.width;
 
258
    int stippleheight = pPix->drawable.height;
 
259
    int dwords, srcy, srcx, funcNo = 2;
 
260
    unsigned char *srcp;
 
261
 
 
262
    if(stipplewidth <= 32) {
 
263
        if(stipplewidth & (stipplewidth - 1))   
 
264
          funcNo = 1;
 
265
        else    
 
266
          funcNo = 0;
 
267
    } 
 
268
    StippleFunc = stipple_scanline_func[funcNo];
 
269
    SecondFunc = stipple_scanline_func[funcNo];
 
270
    FirstFunc = stipple_scanline_func[funcNo + 3];
 
271
 
 
272
#ifdef TRIPLE_BITS
 
273
    if((bg == -1) || 
 
274
        (!(infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY) &&
 
275
        (!(infoRec->CPUToScreenColorExpandFillFlags & RGB_EQUAL) ||
 
276
        (CHECK_RGB_EQUAL(bg))))) {
 
277
#else
 
278
    if((bg == -1) || 
 
279
        !(infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
 
280
#endif
 
281
        /* one pass */
 
282
    } else if((rop == GXcopy) && infoRec->FillSolidSpans) {
 
283
        /* one pass but we fill background rects first */
 
284
        (*infoRec->FillSolidSpans)(
 
285
                pScrn, bg, rop, planemask, n, ppt, pwidth, fSorted);
 
286
        bg = -1;
 
287
    } else {
 
288
        /* gotta do two passes */
 
289
        TwoPass = TRUE;
 
290
    }
 
291
 
 
292
    if(!TwoPass)
 
293
        (*infoRec->SetupForCPUToScreenColorExpandFill)(
 
294
                                pScrn, fg, bg, rop, planemask);
 
295
 
 
296
    while(n--) {
 
297
#ifdef TRIPLE_BITS
 
298
        dwords = (3 * *pwidth + 31) >> 5;
 
299
#else
 
300
        dwords = (*pwidth + 31) >> 5;
 
301
#endif
 
302
 
 
303
        srcy = (ppt->y - yorg) % stippleheight;
 
304
        if(srcy < 0) srcy += stippleheight;
 
305
        srcx = (ppt->x - xorg) % stipplewidth;
 
306
        if(srcx < 0) srcx += stipplewidth;
 
307
 
 
308
        srcp = (pPix->devKind * srcy) + (unsigned char*)pPix->devPrivate.ptr;
 
309
 
 
310
SECOND_PASS:
 
311
        if(TwoPass) {
 
312
            (*infoRec->SetupForCPUToScreenColorExpandFill)(pScrn, 
 
313
                        (FirstPass) ? bg : fg, -1, rop, planemask);
 
314
            StippleFunc = (FirstPass) ? FirstFunc : SecondFunc;
 
315
        }
 
316
 
 
317
        (*infoRec->SubsequentCPUToScreenColorExpandFill)(pScrn, ppt->x, ppt->y,
 
318
                        *pwidth, 1, 0);
 
319
 
 
320
        base = (CARD32*)infoRec->ColorExpandBase;
 
321
 
 
322
        (*StippleFunc)(base, (CARD32*)srcp, srcx, stipplewidth, dwords);
 
323
    
 
324
        if((infoRec->CPUToScreenColorExpandFillFlags & CPU_TRANSFER_PAD_QWORD) 
 
325
                        && (dwords & 0x01)) {
 
326
            base = (CARD32*)infoRec->ColorExpandBase;
 
327
            base[0] = 0x00000000;
 
328
        }
 
329
 
 
330
        if(TwoPass) {
 
331
           if(FirstPass) {
 
332
                FirstPass = FALSE;
 
333
                goto SECOND_PASS;
 
334
           } else FirstPass = TRUE;
 
335
        }
 
336
 
 
337
        ppt++; pwidth++;
 
338
     }
 
339
 
 
340
    if(infoRec->CPUToScreenColorExpandFillFlags & SYNC_AFTER_COLOR_EXPAND) 
 
341
        (*infoRec->Sync)(pScrn);
 
342
    else SET_SYNC_FLAG(infoRec);
 
343
}
 
344
 
 
345
 
 
346
#ifndef FIXEDBASE
 
347
 
 
348
void 
 
349
#ifdef TRIPLE_BITS
 
350
EXPNAME(XAAFillScanlineColorExpandRects3)(
 
351
#else
 
352
EXPNAME(XAAFillScanlineColorExpandRects)(
 
353
#endif
 
354
   ScrnInfoPtr pScrn,
 
355
   int fg, int bg, int rop,
 
356
   unsigned int planemask,
 
357
   int nBox,
 
358
   BoxPtr pBox,
 
359
   int xorg, int yorg,
 
360
   PixmapPtr pPix
 
361
){
 
362
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
 
363
    CARD32 *base;
 
364
    Bool TwoPass = FALSE, FirstPass = TRUE;
 
365
    StippleScanlineProcPtr StippleFunc, FirstFunc, SecondFunc;
 
366
    int stipplewidth = pPix->drawable.width;
 
367
    int stippleheight = pPix->drawable.height;
 
368
    int srcwidth = pPix->devKind;
 
369
    int dwords, srcy, srcx, funcNo = 2, bufferNo, h;
 
370
    unsigned char *src = pPix->devPrivate.ptr;
 
371
    unsigned char *srcp;
 
372
 
 
373
    if(stipplewidth <= 32) {
 
374
        if(stipplewidth & (stipplewidth - 1))   
 
375
          funcNo = 1;
 
376
        else    
 
377
          funcNo = 0;
 
378
    } 
 
379
    StippleFunc = stipple_scanline_func[funcNo];
 
380
    SecondFunc = stipple_scanline_func[funcNo];
 
381
    FirstFunc = stipple_scanline_func[funcNo + 3];
 
382
 
 
383
#ifdef TRIPLE_BITS
 
384
    if((bg == -1) || 
 
385
      (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY) &&
 
386
      (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags & RGB_EQUAL) ||
 
387
      (CHECK_RGB_EQUAL(bg))))) {
 
388
#else
 
389
    if((bg == -1) || 
 
390
      !(infoRec->ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
 
391
#endif
 
392
        /* one pass */
 
393
    } else if((rop == GXcopy) && infoRec->FillSolidRects) {
 
394
        /* one pass but we fill background rects first */
 
395
        (*infoRec->FillSolidRects)(pScrn, bg, rop, planemask, nBox, pBox);
 
396
        bg = -1;
 
397
    } else {
 
398
        /* gotta do two passes */
 
399
        TwoPass = TRUE;
 
400
    }
 
401
 
 
402
    if(!TwoPass)
 
403
        (*infoRec->SetupForScanlineCPUToScreenColorExpandFill)(
 
404
                                pScrn, fg, bg, rop, planemask);
 
405
 
 
406
    while(nBox--) {
 
407
#ifdef TRIPLE_BITS
 
408
        dwords = (3 * (pBox->x2 - pBox->x1) + 31) >> 5;
 
409
#else
 
410
        dwords = (pBox->x2 - pBox->x1 + 31) >> 5;
 
411
#endif
 
412
 
 
413
SECOND_PASS:
 
414
        if(TwoPass) {
 
415
            (*infoRec->SetupForScanlineCPUToScreenColorExpandFill)(pScrn, 
 
416
                        (FirstPass) ? bg : fg, -1, rop, planemask);
 
417
            StippleFunc = (FirstPass) ? FirstFunc : SecondFunc;
 
418
        }
 
419
 
 
420
        h = pBox->y2 - pBox->y1;
 
421
 
 
422
        (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill)(
 
423
                pScrn, pBox->x1, pBox->y1, pBox->x2 - pBox->x1, h, 0);
 
424
 
 
425
        bufferNo = 0;
 
426
 
 
427
        srcy = (pBox->y1 - yorg) % stippleheight;
 
428
        if(srcy < 0) srcy += stippleheight;
 
429
        srcx = (pBox->x1 - xorg) % stipplewidth;
 
430
        if(srcx < 0) srcx += stipplewidth;
 
431
 
 
432
        srcp = (srcwidth * srcy) + src;
 
433
 
 
434
        while(h--) {
 
435
            base = (CARD32*)infoRec->ScanlineColorExpandBuffers[bufferNo];
 
436
            (*StippleFunc)(base, (CARD32*)srcp, srcx, stipplewidth, dwords);
 
437
            (*infoRec->SubsequentColorExpandScanline)(pScrn, bufferNo++);
 
438
            if(bufferNo >= infoRec->NumScanlineColorExpandBuffers)
 
439
                bufferNo = 0;
 
440
            srcy++;
 
441
            srcp += srcwidth;
 
442
            if (srcy >= stippleheight) {
 
443
                srcy = 0;
 
444
                srcp = src;
 
445
            }
 
446
        }
 
447
    
 
448
        if(TwoPass) {
 
449
           if(FirstPass) {
 
450
                FirstPass = FALSE;
 
451
                goto SECOND_PASS;
 
452
           } else FirstPass = TRUE;
 
453
        }
 
454
 
 
455
        pBox++;
 
456
     }
 
457
 
 
458
     SET_SYNC_FLAG(infoRec);
 
459
}
 
460
 
 
461
void 
 
462
#ifdef TRIPLE_BITS
 
463
EXPNAME(XAAFillScanlineColorExpandSpans3)(
 
464
#else
 
465
EXPNAME(XAAFillScanlineColorExpandSpans)(
 
466
#endif
 
467
   ScrnInfoPtr pScrn,
 
468
   int fg, int bg, int rop,
 
469
   unsigned int planemask,
 
470
   int n,
 
471
   DDXPointPtr ppt,
 
472
   int *pwidth,
 
473
   int fSorted,
 
474
   int xorg, int yorg,
 
475
   PixmapPtr pPix
 
476
){
 
477
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
 
478
    CARD32 *base;
 
479
    Bool TwoPass = FALSE, FirstPass = TRUE;
 
480
    StippleScanlineProcPtr StippleFunc, FirstFunc, SecondFunc;
 
481
    int stipplewidth = pPix->drawable.width;
 
482
    int stippleheight = pPix->drawable.height;
 
483
    int dwords, srcy, srcx, funcNo = 2;
 
484
    unsigned char *srcp;
 
485
 
 
486
    if(stipplewidth <= 32) {
 
487
        if(stipplewidth & (stipplewidth - 1))   
 
488
          funcNo = 1;
 
489
        else    
 
490
          funcNo = 0;
 
491
    } 
 
492
    StippleFunc = stipple_scanline_func[funcNo];
 
493
    SecondFunc = stipple_scanline_func[funcNo];
 
494
    FirstFunc = stipple_scanline_func[funcNo + 3];
 
495
 
 
496
#ifdef TRIPLE_BITS
 
497
    if((bg == -1) || 
 
498
      (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY) &&
 
499
      (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags & RGB_EQUAL) ||
 
500
      (CHECK_RGB_EQUAL(bg))))) {
 
501
#else
 
502
    if((bg == -1) || 
 
503
      !(infoRec->ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
 
504
#endif
 
505
        /* one pass */
 
506
    } else if((rop == GXcopy) && infoRec->FillSolidSpans) {
 
507
        /* one pass but we fill background rects first */
 
508
        (*infoRec->FillSolidSpans)(
 
509
                pScrn, bg, rop, planemask, n, ppt, pwidth, fSorted);
 
510
        bg = -1;
 
511
    } else {
 
512
        /* gotta do two passes */
 
513
        TwoPass = TRUE;
 
514
    }
 
515
 
 
516
    if(!TwoPass)
 
517
        (*infoRec->SetupForScanlineCPUToScreenColorExpandFill)(
 
518
                                pScrn, fg, bg, rop, planemask);
 
519
 
 
520
 
 
521
    while(n--) {
 
522
#ifdef TRIPLE_BITS
 
523
        dwords = (3 * *pwidth + 31) >> 5;
 
524
#else
 
525
        dwords = (*pwidth + 31) >> 5;
 
526
#endif
 
527
 
 
528
        srcy = (ppt->y - yorg) % stippleheight;
 
529
        if(srcy < 0) srcy += stippleheight;
 
530
        srcx = (ppt->x - xorg) % stipplewidth;
 
531
        if(srcx < 0) srcx += stipplewidth;
 
532
 
 
533
        srcp = (pPix->devKind * srcy) + (unsigned char*)pPix->devPrivate.ptr;
 
534
 
 
535
SECOND_PASS:
 
536
        if(TwoPass) {
 
537
            (*infoRec->SetupForScanlineCPUToScreenColorExpandFill)(pScrn, 
 
538
                        (FirstPass) ? bg : fg, -1, rop, planemask);
 
539
            StippleFunc = (FirstPass) ? FirstFunc : SecondFunc;
 
540
        }
 
541
 
 
542
        (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill)(
 
543
                                pScrn, ppt->x, ppt->y, *pwidth, 1, 0);
 
544
 
 
545
        base = (CARD32*)infoRec->ScanlineColorExpandBuffers[0];
 
546
 
 
547
        (*StippleFunc)(base, (CARD32*)srcp, srcx, stipplewidth, dwords);
 
548
        (*infoRec->SubsequentColorExpandScanline)(pScrn, 0);
 
549
    
 
550
        if(TwoPass) {
 
551
           if(FirstPass) {
 
552
                FirstPass = FALSE;
 
553
                goto SECOND_PASS;
 
554
           } else FirstPass = TRUE;
 
555
        }
 
556
 
 
557
        ppt++; pwidth++;
 
558
     }
 
559
 
 
560
     SET_SYNC_FLAG(infoRec);
 
561
}
 
562
 
 
563
#endif
 
564
 
 
565
static CARD32 *
 
566
StipplePowerOfTwo(
 
567
   CARD32* dest, CARD32* src, 
 
568
   int shift, int width, int dwords
 
569
){
 
570
    CARD32 pat = *src;
 
571
    if(width < 32) {
 
572
        pat &= XAAShiftMasks[width];
 
573
        while(width < 32) {
 
574
            pat |= SHIFT_L(pat,width);
 
575
            width <<= 1;
 
576
        }
 
577
    }
 
578
   
 
579
    if(shift)
 
580
        pat = SHIFT_R(pat,shift) | SHIFT_L(pat,32 - shift);
 
581
 
 
582
#ifdef MSBFIRST
 
583
    pat = SWAP_BITS_IN_BYTES(pat);    
 
584
#endif
 
585
 
 
586
#ifdef TRIPLE_BITS
 
587
    {
 
588
        EXPAND_PAT;
 
589
 
 
590
        while(dwords >= 3) {
 
591
            WRITE_PAT3;
 
592
            dwords -= 3;
 
593
        }
 
594
        if (dwords == 2) {
 
595
            WRITE_PAT2;
 
596
        } else if (dwords == 1) {
 
597
            WRITE_PAT1;
 
598
        }
 
599
 
 
600
        return dest;
 
601
    }
 
602
#else /* TRIPLE_BITS */
 
603
   while(dwords >= 4) {
 
604
        DEST(0) = pat;
 
605
        DEST(1) = pat;
 
606
        DEST(2) = pat;
 
607
        DEST(3) = pat;
 
608
        dwords -= 4;
 
609
#ifndef FIXEDBASE
 
610
        dest += 4;
 
611
#endif
 
612
   }
 
613
   
 
614
   if(!dwords) return dest;
 
615
   DEST(0) = pat;
 
616
   if(dwords == 1) RETURN(1);
 
617
   DEST(1) = pat;
 
618
   if(dwords == 2) RETURN(2);
 
619
   DEST(2) = pat;
 
620
   RETURN(3);
 
621
#endif /* TRIPLE_BITS */
 
622
}
 
623
 
 
624
static CARD32 *
 
625
StipplePowerOfTwo_Inverted(
 
626
   CARD32* dest, CARD32* src, 
 
627
   int shift, int width, int dwords
 
628
){
 
629
    CARD32 pat = *src;
 
630
    if(width < 32) {
 
631
        pat &= XAAShiftMasks[width];
 
632
        while(width < 32) {
 
633
            pat |= SHIFT_L(pat,width);
 
634
            width <<= 1;
 
635
        }
 
636
    }
 
637
   
 
638
    if(shift)
 
639
        pat = SHIFT_R(pat,shift) | SHIFT_L(pat,32 - shift);
 
640
 
 
641
#ifdef MSBFIRST
 
642
    pat = SWAP_BITS_IN_BYTES(pat);    
 
643
#endif
 
644
 
 
645
   pat = ~pat;
 
646
 
 
647
#ifdef TRIPLE_BITS
 
648
    {
 
649
        EXPAND_PAT;
 
650
 
 
651
        while(dwords >= 3) {
 
652
            WRITE_PAT3;
 
653
            dwords -= 3;
 
654
        }
 
655
        if (dwords == 2) {
 
656
            WRITE_PAT2;
 
657
        } else if (dwords == 1) {
 
658
            WRITE_PAT1;
 
659
        }
 
660
 
 
661
        return dest;
 
662
    }
 
663
#else /* TRIPLE_BITS */
 
664
   while(dwords >= 4) {
 
665
        DEST(0) = pat;
 
666
        DEST(1) = pat;
 
667
        DEST(2) = pat;
 
668
        DEST(3) = pat;
 
669
        dwords -= 4;
 
670
#ifndef FIXEDBASE
 
671
        dest += 4;
 
672
#endif
 
673
   }
 
674
   
 
675
   if(!dwords) return dest;
 
676
   DEST(0) = pat;
 
677
   if(dwords == 1) RETURN(1);
 
678
   DEST(1) = pat;
 
679
   if(dwords == 2) RETURN(2);
 
680
   DEST(2) = pat;
 
681
   RETURN(3);
 
682
#endif /* TRIPLE_BITS */
 
683
}
 
684
 
 
685
 
 
686
static CARD32 *
 
687
StippleUpTo32(
 
688
   CARD32* base, CARD32* src, 
 
689
   int shift, int width, int dwords
 
690
){
 
691
    CARD32 pat = *src & XAAShiftMasks[width];
 
692
 
 
693
    while(width <= 15) {
 
694
        pat |= SHIFT_L(pat,width);
 
695
        width <<= 1;
 
696
    }
 
697
    pat |= SHIFT_L(pat,width);
 
698
 
 
699
    while(dwords--) {
 
700
        CARD32 bits = SHIFT_R(pat,shift) | SHIFT_L(pat,width-shift);
 
701
#ifdef TRIPLE_BITS
 
702
        if(dwords >= 2) {
 
703
            WRITE_BITS3(bits);
 
704
            dwords -= 2;
 
705
        } else if(dwords > 0) {
 
706
            WRITE_BITS2(bits);
 
707
            dwords--;
 
708
        } else {
 
709
            WRITE_BITS1(bits);
 
710
        }
 
711
#else
 
712
        WRITE_BITS(bits);
 
713
#endif
 
714
 
 
715
        shift += 32;
 
716
        shift %= width;
 
717
    }
 
718
    return base;
 
719
}
 
720
 
 
721
 
 
722
static CARD32 *
 
723
StippleUpTo32_Inverted(
 
724
   CARD32* base, CARD32* src, 
 
725
   int shift, int width, int dwords
 
726
){
 
727
    CARD32 pat = *src & XAAShiftMasks[width];
 
728
 
 
729
    while(width <= 15) {
 
730
        pat |= SHIFT_L(pat,width);
 
731
        width <<= 1;
 
732
    }
 
733
    pat |= SHIFT_L(pat,width);
 
734
 
 
735
    while(dwords--) {
 
736
        CARD32 bits = ~(SHIFT_R(pat,shift) | SHIFT_L(pat,width-shift));
 
737
#ifdef TRIPLE_BITS
 
738
        if(dwords >= 2) {
 
739
            WRITE_BITS3(bits);
 
740
            dwords -= 2;
 
741
        } else if(dwords > 0) {
 
742
            WRITE_BITS2(bits);
 
743
            dwords--;
 
744
        } else {
 
745
            WRITE_BITS1(bits);
 
746
        }
 
747
#else
 
748
        WRITE_BITS(bits);
 
749
#endif
 
750
 
 
751
        shift += 32;
 
752
        shift %= width;
 
753
    }
 
754
    return base;
 
755
}
 
756
 
 
757
 
 
758
static CARD32 *
 
759
StippleOver32(
 
760
   CARD32* base, CARD32* src, 
 
761
   int offset, int width, int dwords
 
762
){
 
763
   CARD32* srcp;
 
764
   CARD32 bits;
 
765
   int bitsleft, shift;   
 
766
 
 
767
   while(dwords--) {
 
768
        bitsleft = width - offset;
 
769
        srcp = src + (offset >> 5);
 
770
        shift = offset & 31;
 
771
 
 
772
        if(bitsleft < 32)
 
773
            bits = SHIFT_L(*src,bitsleft) | 
 
774
                      (SHIFT_R(*srcp,shift) & XAAShiftMasks[bitsleft]);
 
775
        else if(shift)
 
776
            bits = SHIFT_R(*srcp,shift) | SHIFT_L(srcp[1],32-shift);
 
777
        else
 
778
            bits = *srcp;
 
779
 
 
780
#ifdef TRIPLE_BITS
 
781
        if(dwords >= 2) {
 
782
            WRITE_BITS3(bits);
 
783
            dwords -= 2;
 
784
        } else if(dwords > 0) {
 
785
            WRITE_BITS2(bits);
 
786
            dwords--;
 
787
        } else {
 
788
            WRITE_BITS1(bits);
 
789
        }
 
790
#else
 
791
        WRITE_BITS(bits);
 
792
#endif
 
793
 
 
794
        offset += 32;
 
795
        offset %= width;
 
796
   }
 
797
   return base;
 
798
}
 
799
 
 
800
 
 
801
static CARD32 *
 
802
StippleOver32_Inverted(
 
803
   CARD32* base, CARD32* src, 
 
804
   int offset, int width, int dwords
 
805
){
 
806
   CARD32* srcp;
 
807
   CARD32 bits;
 
808
   int bitsleft, shift;   
 
809
 
 
810
   while(dwords--) {
 
811
        bitsleft = width - offset;
 
812
        srcp = src + (offset >> 5);
 
813
        shift = offset & 31;
 
814
 
 
815
        if(bitsleft < 32)
 
816
            bits = SHIFT_L(*src,bitsleft) | 
 
817
                      (SHIFT_R(*srcp,shift) & XAAShiftMasks[bitsleft]);
 
818
        else if(shift)
 
819
            bits = SHIFT_R(*srcp,shift) | SHIFT_L(srcp[1],32-shift);
 
820
        else
 
821
            bits = *srcp;
 
822
 
 
823
        bits = ~bits;
 
824
 
 
825
#ifdef TRIPLE_BITS
 
826
        if(dwords >= 2) {
 
827
            WRITE_BITS3(bits);
 
828
            dwords -= 2;
 
829
        } else if(dwords > 0) {
 
830
            WRITE_BITS2(bits);
 
831
            dwords--;
 
832
        } else {
 
833
            WRITE_BITS1(bits);
 
834
        }
 
835
#else
 
836
        WRITE_BITS(bits);
 
837
#endif
 
838
 
 
839
        offset += 32;
 
840
        offset %= width;
 
841
   }
 
842
   return base;
 
843
}