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