s3v_shadow.c revision ba85709e
1
2/*
3Copyright (C) 1994-2000 The XFree86 Project, Inc.  All Rights Reserved.
4
5Permission is hereby granted, free of charge, to any person obtaining a copy of
6this software and associated documentation files (the "Software"), to deal in
7the Software without restriction, including without limitation the rights to
8use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9of the Software, and to permit persons to whom the Software is furnished to do
10so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all
13copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
17NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of the XFree86 Project shall not
23be used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from the XFree86 Project.
25*/
26
27/*
28Copyright (C) 1994-2000 The XFree86 Project, Inc.  All Rights Reserved.
29
30Permission is hereby granted, free of charge, to any person obtaining a copy of
31this software and associated documentation files (the "Software"), to deal in
32the Software without restriction, including without limitation the rights to
33use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
34of the Software, and to permit persons to whom the Software is furnished to do
35so, subject to the following conditions:
36
37The above copyright notice and this permission notice shall be included in all
38copies or substantial portions of the Software.
39
40THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
42NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
43XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
44AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
45WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46
47Except as contained in this notice, the name of the XFree86 Project shall not
48be used in advertising or otherwise to promote the sale, use or other dealings
49in this Software without prior written authorization from the XFree86 Project.
50*/
51
52/*
53   Copyright (c) 1999,2000  The XFree86 Project Inc.
54   based on code written by Mark Vojkovich <markv@valinux.com>
55*/
56
57#ifdef HAVE_CONFIG_H
58#include "config.h"
59#endif
60
61#include "xf86.h"
62#include "xf86_OSproc.h"
63#include "xf86Resources.h"
64#include "xf86PciInfo.h"
65#include "xf86Pci.h"
66#include "shadowfb.h"
67#include "servermd.h"
68#include "s3v.h"
69
70
71void
72s3vRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
73{
74    S3VPtr ps3v = S3VPTR(pScrn);
75    int width, height, Bpp, FBPitch;
76    unsigned char *src, *dst;
77
78    Bpp = pScrn->bitsPerPixel >> 3;
79    FBPitch = BitmapBytePad(pScrn->displayWidth * pScrn->bitsPerPixel);
80
81    while(num--) {
82	width = (pbox->x2 - pbox->x1) * Bpp;
83	height = pbox->y2 - pbox->y1;
84	src = ps3v->ShadowPtr + (pbox->y1 * ps3v->ShadowPitch) +
85						(pbox->x1 * Bpp);
86	dst = ps3v->FBStart + (pbox->y1 * FBPitch) + (pbox->x1 * Bpp);
87
88	while(height--) {
89	    memcpy(dst, src, width);
90	    dst += FBPitch;
91	    src += ps3v->ShadowPitch;
92	}
93
94	pbox++;
95    }
96}
97
98void
99s3vPointerMoved(int index, int x, int y)
100{
101    ScrnInfoPtr pScrn = xf86Screens[index];
102    S3VPtr ps3v = S3VPTR(pScrn);
103    int newX, newY;
104
105    if(ps3v->rotate == 1) {
106	newX = pScrn->pScreen->height - y - 1;
107	newY = x;
108    } else {
109	newX = y;
110	newY = pScrn->pScreen->width - x - 1;
111    }
112
113    (*ps3v->PointerMoved)(index, newX, newY);
114}
115
116void
117s3vRefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
118{
119    S3VPtr ps3v = S3VPTR(pScrn);
120    int count, width, height, y1, y2, dstPitch, srcPitch;
121    CARD8 *dstPtr, *srcPtr, *src;
122    CARD32 *dst;
123
124    dstPitch = pScrn->displayWidth;
125    srcPitch = -ps3v->rotate * ps3v->ShadowPitch;
126
127    while(num--) {
128	width = pbox->x2 - pbox->x1;
129	y1 = pbox->y1 & ~3;
130	y2 = (pbox->y2 + 3) & ~3;
131	height = (y2 - y1) >> 2;  /* in dwords */
132
133	if(ps3v->rotate == 1) {
134	    dstPtr = ps3v->FBStart +
135			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
136	    srcPtr = ps3v->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1;
137	} else {
138	    dstPtr = ps3v->FBStart +
139			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
140	    srcPtr = ps3v->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1;
141	}
142
143	while(width--) {
144	    src = srcPtr;
145	    dst = (CARD32*)dstPtr;
146	    count = height;
147	    while(count--) {
148		*(dst++) = src[0] | (src[srcPitch] << 8) |
149					(src[srcPitch * 2] << 16) |
150					(src[srcPitch * 3] << 24);
151		src += srcPitch * 4;
152	    }
153	    srcPtr += ps3v->rotate;
154	    dstPtr += dstPitch;
155	}
156
157	pbox++;
158    }
159}
160
161
162void
163s3vRefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
164{
165    S3VPtr ps3v = S3VPTR(pScrn);
166    int count, width, height, y1, y2, dstPitch, srcPitch;
167    CARD16 *dstPtr, *srcPtr, *src;
168    CARD32 *dst;
169
170    dstPitch = pScrn->displayWidth;
171    srcPitch = -ps3v->rotate * ps3v->ShadowPitch >> 1;
172
173    while(num--) {
174	width = pbox->x2 - pbox->x1;
175	y1 = pbox->y1 & ~1;
176	y2 = (pbox->y2 + 1) & ~1;
177	height = (y2 - y1) >> 1;  /* in dwords */
178
179	if(ps3v->rotate == 1) {
180	    dstPtr = (CARD16*)ps3v->FBStart +
181			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
182	    srcPtr = (CARD16*)ps3v->ShadowPtr +
183			((1 - y2) * srcPitch) + pbox->x1;
184	} else {
185	    dstPtr = (CARD16*)ps3v->FBStart +
186			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
187	    srcPtr = (CARD16*)ps3v->ShadowPtr +
188			(y1 * srcPitch) + pbox->x2 - 1;
189	}
190
191	while(width--) {
192	    src = srcPtr;
193	    dst = (CARD32*)dstPtr;
194	    count = height;
195	    while(count--) {
196		*(dst++) = src[0] | (src[srcPitch] << 16);
197		src += srcPitch * 2;
198	    }
199	    srcPtr += ps3v->rotate;
200	    dstPtr += dstPitch;
201	}
202
203	pbox++;
204    }
205}
206
207
208/* this one could be faster */
209void
210s3vRefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
211{
212    S3VPtr ps3v = S3VPTR(pScrn);
213    int count, width, height, y1, y2, dstPitch, srcPitch;
214    CARD8 *dstPtr, *srcPtr, *src;
215    CARD32 *dst;
216
217    dstPitch = BitmapBytePad(pScrn->displayWidth * 24);
218    srcPitch = -ps3v->rotate * ps3v->ShadowPitch;
219
220    while(num--) {
221        width = pbox->x2 - pbox->x1;
222        y1 = pbox->y1 & ~3;
223        y2 = (pbox->y2 + 3) & ~3;
224        height = (y2 - y1) >> 2;  /* blocks of 3 dwords */
225
226	if(ps3v->rotate == 1) {
227	    dstPtr = ps3v->FBStart +
228			(pbox->x1 * dstPitch) + ((pScrn->virtualX - y2) * 3);
229	    srcPtr = ps3v->ShadowPtr + ((1 - y2) * srcPitch) + (pbox->x1 * 3);
230	} else {
231	    dstPtr = ps3v->FBStart +
232			((pScrn->virtualY - pbox->x2) * dstPitch) + (y1 * 3);
233	    srcPtr = ps3v->ShadowPtr + (y1 * srcPitch) + (pbox->x2 * 3) - 3;
234	}
235
236	while(width--) {
237	    src = srcPtr;
238	    dst = (CARD32*)dstPtr;
239	    count = height;
240	    while(count--) {
241		dst[0] = src[0] | (src[1] << 8) | (src[2] << 16) |
242				(src[srcPitch] << 24);
243		dst[1] = src[srcPitch + 1] | (src[srcPitch + 2] << 8) |
244				(src[srcPitch * 2] << 16) |
245				(src[(srcPitch * 2) + 1] << 24);
246		dst[2] = src[(srcPitch * 2) + 2] | (src[srcPitch * 3] << 8) |
247				(src[(srcPitch * 3) + 1] << 16) |
248				(src[(srcPitch * 3) + 2] << 24);
249		dst += 3;
250		src += srcPitch * 4;
251	    }
252	    srcPtr += ps3v->rotate * 3;
253	    dstPtr += dstPitch;
254	}
255
256	pbox++;
257    }
258}
259
260void
261s3vRefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
262{
263    S3VPtr ps3v = S3VPTR(pScrn);
264    int count, width, height, dstPitch, srcPitch;
265    CARD32 *dstPtr, *srcPtr, *src, *dst;
266
267    dstPitch = pScrn->displayWidth;
268    srcPitch = -ps3v->rotate * ps3v->ShadowPitch >> 2;
269
270    while(num--) {
271	width = pbox->x2 - pbox->x1;
272	height = pbox->y2 - pbox->y1;
273
274	if(ps3v->rotate == 1) {
275	    dstPtr = (CARD32*)ps3v->FBStart +
276			(pbox->x1 * dstPitch) + pScrn->virtualX - pbox->y2;
277	    srcPtr = (CARD32*)ps3v->ShadowPtr +
278			((1 - pbox->y2) * srcPitch) + pbox->x1;
279	} else {
280	    dstPtr = (CARD32*)ps3v->FBStart +
281			((pScrn->virtualY - pbox->x2) * dstPitch) + pbox->y1;
282	    srcPtr = (CARD32*)ps3v->ShadowPtr +
283			(pbox->y1 * srcPitch) + pbox->x2 - 1;
284	}
285
286	while(width--) {
287	    src = srcPtr;
288	    dst = dstPtr;
289	    count = height;
290	    while(count--) {
291		*(dst++) = *src;
292		src += srcPitch;
293	    }
294	    srcPtr += ps3v->rotate;
295	    dstPtr += dstPitch;
296	}
297
298	pbox++;
299    }
300}
301
302
303
304