Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / xaa / xaaLineMisc.c
blob537b08b9753fc25b1496b8d6d648530609bcbb58
2 #ifdef HAVE_XORG_CONFIG_H
3 #include <xorg-config.h>
4 #endif
6 #include "misc.h"
7 #include "xf86.h"
8 #include "xf86_OSproc.h"
10 #include <X11/X.h>
11 #include "scrnintstr.h"
12 #include "miline.h"
13 #include "xf86str.h"
14 #include "xaa.h"
15 #include "xaalocal.h"
18 void
19 XAASolidHorVertLineAsRects(
20 ScrnInfoPtr pScrn,
21 int x, int y, int len, int dir
23 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
25 if(dir == DEGREES_0)
26 (*infoRec->SubsequentSolidFillRect)(pScrn, x, y, len, 1);
27 else
28 (*infoRec->SubsequentSolidFillRect)(pScrn, x, y, 1, len);
32 void
33 XAASolidHorVertLineAsTwoPoint(
34 ScrnInfoPtr pScrn,
35 int x, int y, int len, int dir
37 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
39 len--;
41 if(dir == DEGREES_0)
42 (*infoRec->SubsequentSolidTwoPointLine)(pScrn, x, y, x + len, y, 0);
43 else
44 (*infoRec->SubsequentSolidTwoPointLine)(pScrn, x, y, x, y + len, 0);
47 void
48 XAASolidHorVertLineAsBresenham(
49 ScrnInfoPtr pScrn,
50 int x, int y, int len, int dir
52 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
54 if(dir == DEGREES_0)
55 (*infoRec->SubsequentSolidBresenhamLine)(
56 pScrn, x, y, len << 1, 0, -len, len, 0);
57 else
58 (*infoRec->SubsequentSolidBresenhamLine)(
59 pScrn, x, y, len << 1, 0, -len, len, YMAJOR);
63 void
64 XAAComputeDash(GCPtr pGC)
66 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
67 XAAGCPtr pGCPriv = (XAAGCPtr) (pGC)->devPrivates[XAAGetGCIndex()].ptr;
68 Bool EvenDash = (pGC->numInDashList & 0x01) ? FALSE : TRUE;
69 int PatternLength = 0;
70 unsigned char* DashPtr = (unsigned char*)pGC->dash;
71 CARD32 *ptr;
72 int count = pGC->numInDashList;
73 int shift, value, direction;
74 Bool set;
76 if(pGCPriv->DashPattern)
77 xfree(pGCPriv->DashPattern);
79 pGCPriv->DashPattern = NULL;
80 pGCPriv->DashLength = 0;
82 while(count--)
83 PatternLength += *(DashPtr++);
85 if(!EvenDash)
86 PatternLength <<= 1;
88 if(PatternLength > infoRec->DashPatternMaxLength)
89 return;
91 if((infoRec->DashedLineFlags & LINE_PATTERN_POWER_OF_2_ONLY) &&
92 (PatternLength & (PatternLength - 1)))
93 return;
95 pGCPriv->DashPattern = xcalloc((PatternLength + 31) >> 5, 4);
96 if(!pGCPriv->DashPattern) return;
97 pGCPriv->DashLength = PatternLength;
99 if(infoRec->DashedLineFlags & (LINE_PATTERN_LSBFIRST_MSBJUSTIFIED |
100 LINE_PATTERN_LSBFIRST_LSBJUSTIFIED)) {
101 direction = 1;
102 set = TRUE;
103 DashPtr = (unsigned char*)pGC->dash;
104 } else {
105 direction = -1;
106 set = FALSE;
107 DashPtr = (unsigned char*)pGC->dash + pGC->numInDashList - 1;
110 if(infoRec->DashedLineFlags & (LINE_PATTERN_LSBFIRST_MSBJUSTIFIED |
111 LINE_PATTERN_MSBFIRST_MSBJUSTIFIED))
112 shift = 32 - (PatternLength & 31);
113 else
114 shift = 0;
116 ptr = (CARD32*)(pGCPriv->DashPattern);
118 CONCATENATE:
120 count = pGC->numInDashList;
122 while(count--) {
123 value = *DashPtr;
124 DashPtr += direction;
125 while(value) {
126 if(value < (32 - shift)) {
127 if(set) *ptr |= XAAShiftMasks[value] << shift;
128 shift += value;
129 break;
130 } else {
131 if(set) *ptr |= ~0L << shift;
132 value -= (32 - shift);
133 shift = 0;
134 ptr++;
137 if(set) set = FALSE;
138 else set = TRUE;
141 if(!EvenDash) {
142 EvenDash = TRUE;
143 if(infoRec->DashedLineFlags & (LINE_PATTERN_LSBFIRST_MSBJUSTIFIED |
144 LINE_PATTERN_LSBFIRST_LSBJUSTIFIED))
145 DashPtr = (unsigned char*)pGC->dash;
146 else
147 DashPtr = (unsigned char*)pGC->dash + pGC->numInDashList;
148 goto CONCATENATE;