1
2#ifdef HAVE_XORG_CONFIG_H
3#include <xorg-config.h>
4#endif
5
6#include "misc.h"
7#include "xf86.h"
8#include "xf86_OSproc.h"
9
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"
16
17
18void
19XAASolidHorVertLineAsRects(
20   ScrnInfoPtr pScrn,
21   int x, int y, int len, int dir
22){
23    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
24
25    if(dir == DEGREES_0)
26	(*infoRec->SubsequentSolidFillRect)(pScrn, x, y, len, 1);
27    else
28	(*infoRec->SubsequentSolidFillRect)(pScrn, x, y, 1, len);
29}
30
31
32void
33XAASolidHorVertLineAsTwoPoint(
34   ScrnInfoPtr pScrn,
35   int x, int y, int len, int dir
36){
37    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
38
39    len--;
40
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);
45}
46
47void
48XAASolidHorVertLineAsBresenham(
49   ScrnInfoPtr pScrn,
50   int x, int y, int len, int dir
51){
52    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
53
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);
60}
61
62
63void
64XAAComputeDash(GCPtr pGC)
65{
66    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
67    XAAGCPtr   pGCPriv = (XAAGCPtr)dixLookupPrivate(&pGC->devPrivates,
68						    XAAGetGCKey());
69    Bool EvenDash = (pGC->numInDashList & 0x01) ? FALSE : TRUE;
70    int PatternLength = 0;
71    unsigned char* DashPtr = (unsigned char*)pGC->dash;
72    CARD32 *ptr;
73    int count = pGC->numInDashList;
74    int shift, value, direction;
75    Bool set;
76
77    free(pGCPriv->DashPattern);
78
79    pGCPriv->DashPattern = NULL;
80    pGCPriv->DashLength = 0;
81
82    while(count--)
83	PatternLength += *(DashPtr++);
84
85    if(!EvenDash)
86	PatternLength <<= 1;
87
88    if(PatternLength > infoRec->DashPatternMaxLength)
89	return;
90
91    if((infoRec->DashedLineFlags & LINE_PATTERN_POWER_OF_2_ONLY) &&
92				(PatternLength & (PatternLength - 1)))
93	return;
94
95    pGCPriv->DashPattern = calloc((PatternLength + 31) >> 5, 4);
96    if(!pGCPriv->DashPattern) return;
97    pGCPriv->DashLength = PatternLength;
98
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;
108    }
109
110    if(infoRec->DashedLineFlags & (LINE_PATTERN_LSBFIRST_MSBJUSTIFIED |
111 	 	 		   LINE_PATTERN_MSBFIRST_MSBJUSTIFIED))
112	shift = 32 - (PatternLength & 31);
113    else
114	shift = 0;
115
116    ptr = (CARD32*)(pGCPriv->DashPattern);
117
118CONCATENATE:
119
120    count = pGC->numInDashList;
121
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++;
135	     }
136	}
137	if(set) set = FALSE;
138	else set = TRUE;
139    }
140
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;
149    }
150}
151