mga_shadow.c revision 4a32b415
1/*
2   Copyright (c) 1999,  The XFree86 Project Inc.
3   Written by Mark Vojkovich <markv@valinux.com>
4*/
5
6#ifdef HAVE_CONFIG_H
7#include "config.h"
8#endif
9
10#include "xorg-server.h"
11#include "xf86.h"
12#include "xf86_OSproc.h"
13#include "xf86Pci.h"
14#include "mga_reg.h"
15#include "mga.h"
16#include "shadowfb.h"
17#include "servermd.h"
18
19
20
21void
22MGARefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
23{
24    MGAPtr pMga = MGAPTR(pScrn);
25    int width, height, Bpp, FBPitch;
26    unsigned char *src, *dst;
27
28    Bpp = pScrn->bitsPerPixel >> 3;
29    FBPitch = BitmapBytePad(pScrn->displayWidth * pScrn->bitsPerPixel);
30
31    while(num--) {
32	width = (pbox->x2 - pbox->x1) * Bpp;
33	height = pbox->y2 - pbox->y1;
34	src = pMga->ShadowPtr + (pbox->y1 * pMga->ShadowPitch) +
35						(pbox->x1 * Bpp);
36	dst = pMga->FbStart + (pbox->y1 * FBPitch) + (pbox->x1 * Bpp);
37
38	while(height--) {
39	    memcpy(dst, src, width);
40	    dst += FBPitch;
41	    src += pMga->ShadowPitch;
42	}
43
44	pbox++;
45    }
46}
47
48void
49MGAPointerMoved(SCRN_ARG_TYPE arg, int x, int y)
50{
51    SCRN_INFO_PTR(arg);
52    MGAPtr pMga = MGAPTR(pScrn);
53    int newX, newY;
54
55    if(pMga->Rotate == 1) {
56	newX = pScrn->pScreen->height - y - 1;
57	newY = x;
58    } else {
59	newX = y;
60	newY = pScrn->pScreen->width - x - 1;
61    }
62
63    (*pMga->PointerMoved)(arg, newX, newY);
64}
65
66void
67MGARefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
68{
69    MGAPtr pMga = MGAPTR(pScrn);
70    int count, width, height, y1, y2, dstPitch, srcPitch;
71    CARD8 *dstPtr, *srcPtr, *src;
72    CARD32 *dst;
73
74    dstPitch = pScrn->displayWidth;
75    srcPitch = -pMga->Rotate * pMga->ShadowPitch;
76
77    while(num--) {
78	width = pbox->x2 - pbox->x1;
79	y1 = pbox->y1 & ~3;
80	y2 = (pbox->y2 + 3) & ~3;
81	height = (y2 - y1) >> 2;  /* in dwords */
82
83	if(pMga->Rotate == 1) {
84	    dstPtr = pMga->FbStart +
85			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
86	    srcPtr = pMga->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1;
87	} else {
88	    dstPtr = pMga->FbStart +
89			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
90	    srcPtr = pMga->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1;
91	}
92
93	while(width--) {
94	    src = srcPtr;
95	    dst = (CARD32*)dstPtr;
96	    count = height;
97	    while(count--) {
98		*(dst++) = src[0] | (src[srcPitch] << 8) |
99					(src[srcPitch * 2] << 16) |
100					(src[srcPitch * 3] << 24);
101		src += srcPitch * 4;
102	    }
103	    srcPtr += pMga->Rotate;
104	    dstPtr += dstPitch;
105	}
106
107	pbox++;
108    }
109}
110
111
112void
113MGARefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
114{
115    MGAPtr pMga = MGAPTR(pScrn);
116    int count, width, height, y1, y2, dstPitch, srcPitch;
117    CARD16 *dstPtr, *srcPtr, *src;
118    CARD32 *dst;
119
120    dstPitch = pScrn->displayWidth;
121    srcPitch = -pMga->Rotate * pMga->ShadowPitch >> 1;
122
123    while(num--) {
124	width = pbox->x2 - pbox->x1;
125	y1 = pbox->y1 & ~1;
126	y2 = (pbox->y2 + 1) & ~1;
127	height = (y2 - y1) >> 1;  /* in dwords */
128
129	if(pMga->Rotate == 1) {
130	    dstPtr = (CARD16*)pMga->FbStart +
131			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
132	    srcPtr = (CARD16*)pMga->ShadowPtr +
133			((1 - y2) * srcPitch) + pbox->x1;
134	} else {
135	    dstPtr = (CARD16*)pMga->FbStart +
136			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
137	    srcPtr = (CARD16*)pMga->ShadowPtr +
138			(y1 * srcPitch) + pbox->x2 - 1;
139	}
140
141	while(width--) {
142	    src = srcPtr;
143	    dst = (CARD32*)dstPtr;
144	    count = height;
145	    while(count--) {
146		*(dst++) = src[0] | (src[srcPitch] << 16);
147		src += srcPitch * 2;
148	    }
149	    srcPtr += pMga->Rotate;
150	    dstPtr += dstPitch;
151	}
152
153	pbox++;
154    }
155}
156
157
158/* this one could be faster */
159void
160MGARefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
161{
162    MGAPtr pMga = MGAPTR(pScrn);
163    int count, width, height, y1, y2, dstPitch, srcPitch;
164    CARD8 *dstPtr, *srcPtr, *src;
165    CARD32 *dst;
166
167    dstPitch = BitmapBytePad(pScrn->displayWidth * 24);
168    srcPitch = -pMga->Rotate * pMga->ShadowPitch;
169
170    while(num--) {
171        width = pbox->x2 - pbox->x1;
172        y1 = pbox->y1 & ~3;
173        y2 = (pbox->y2 + 3) & ~3;
174        height = (y2 - y1) >> 2;  /* blocks of 3 dwords */
175
176	if(pMga->Rotate == 1) {
177	    dstPtr = pMga->FbStart +
178			(pbox->x1 * dstPitch) + ((pScrn->virtualX - y2) * 3);
179	    srcPtr = pMga->ShadowPtr + ((1 - y2) * srcPitch) + (pbox->x1 * 3);
180	} else {
181	    dstPtr = pMga->FbStart +
182			((pScrn->virtualY - pbox->x2) * dstPitch) + (y1 * 3);
183	    srcPtr = pMga->ShadowPtr + (y1 * srcPitch) + (pbox->x2 * 3) - 3;
184	}
185
186	while(width--) {
187	    src = srcPtr;
188	    dst = (CARD32*)dstPtr;
189	    count = height;
190	    while(count--) {
191		dst[0] = src[0] | (src[1] << 8) | (src[2] << 16) |
192				(src[srcPitch] << 24);
193		dst[1] = src[srcPitch + 1] | (src[srcPitch + 2] << 8) |
194				(src[srcPitch * 2] << 16) |
195				(src[(srcPitch * 2) + 1] << 24);
196		dst[2] = src[(srcPitch * 2) + 2] | (src[srcPitch * 3] << 8) |
197				(src[(srcPitch * 3) + 1] << 16) |
198				(src[(srcPitch * 3) + 2] << 24);
199		dst += 3;
200		src += srcPitch * 4;
201	    }
202	    srcPtr += pMga->Rotate * 3;
203	    dstPtr += dstPitch;
204	}
205
206	pbox++;
207    }
208}
209
210void
211MGARefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
212{
213    MGAPtr pMga = MGAPTR(pScrn);
214    int count, width, height, dstPitch, srcPitch;
215    CARD32 *dstPtr, *srcPtr, *src, *dst;
216
217    dstPitch = pScrn->displayWidth;
218    srcPitch = -pMga->Rotate * pMga->ShadowPitch >> 2;
219
220    while(num--) {
221	width = pbox->x2 - pbox->x1;
222	height = pbox->y2 - pbox->y1;
223
224	if(pMga->Rotate == 1) {
225	    dstPtr = (CARD32*)pMga->FbStart +
226			(pbox->x1 * dstPitch) + pScrn->virtualX - pbox->y2;
227	    srcPtr = (CARD32*)pMga->ShadowPtr +
228			((1 - pbox->y2) * srcPitch) + pbox->x1;
229	} else {
230	    dstPtr = (CARD32*)pMga->FbStart +
231			((pScrn->virtualY - pbox->x2) * dstPitch) + pbox->y1;
232	    srcPtr = (CARD32*)pMga->ShadowPtr +
233			(pbox->y1 * srcPitch) + pbox->x2 - 1;
234	}
235
236	while(width--) {
237	    src = srcPtr;
238	    dst = dstPtr;
239	    count = height;
240	    while(count--) {
241		*(dst++) = *src;
242		src += srcPitch;
243	    }
244	    srcPtr += pMga->Rotate;
245	    dstPtr += dstPitch;
246	}
247
248	pbox++;
249    }
250}
251
252
253
254