Pull XORG-6_8_0 to CYGWIN branch
[xf86-video-sis/mirage.git] / src / sis_shadow.c
blob3869f6eac70a7a703abb86ea659023fc39b7f902
1 /* $XFree86$ */
2 /* $XdotOrg: xc/programs/Xserver/hw/xfree86/drivers/sis/sis_shadow.c,v 1.3 2004/06/17 13:20:14 twini Exp $ */
3 /*
4 * Copyright (C) 1999-2004 by The XFree86 Project, Inc.
5 * based on code written by Mark Vojkovich
7 * Licensed under the following terms:
9 * Permission to use, copy, modify, distribute, and sell this software and its
10 * documentation for any purpose is hereby granted without fee, provided that
11 * the above copyright notice appears in all copies and that both that copyright
12 * notice and this permission notice appear in supporting documentation, and
13 * and that the name of the copyright holder not be used in advertising
14 * or publicity pertaining to distribution of the software without specific,
15 * written prior permission. The copyright holder makes no representations
16 * about the suitability of this software for any purpose. It is provided
17 * "as is" without expressed or implied warranty.
19 * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
20 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
21 * EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
22 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
23 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
24 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
25 * PERFORMANCE OF THIS SOFTWARE.
27 * TW: This module doesn't use CurrentLayout, because it is never
28 * active when DGA is active and vice versa.
31 #include "xf86.h"
32 #include "xf86_OSproc.h"
33 #include "xf86Resources.h"
34 #include "xf86_ansic.h"
35 #include "xf86PciInfo.h"
36 #include "xf86Pci.h"
37 #include "sis.h"
38 #include "servermd.h"
40 #include "sis_shadow.h"
42 void
43 SISPointerMoved(int index, int x, int y)
45 ScrnInfoPtr pScrn = xf86Screens[index];
46 SISPtr pSiS = SISPTR(pScrn);
48 if(pSiS->Rotate == 1) {
49 (*pSiS->PointerMoved)(index, pScrn->pScreen->height - y - 1, x);
50 } else {
51 (*pSiS->PointerMoved)(index, y, pScrn->pScreen->width - x - 1);
55 void
56 SISRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
58 SISPtr pSiS = SISPTR(pScrn);
59 int width, height, Bpp, FBPitch;
60 CARD8 *src, *dst;
62 Bpp = pScrn->bitsPerPixel >> 3;
63 FBPitch = BitmapBytePad(pScrn->displayWidth * pScrn->bitsPerPixel);
65 while(num--) {
66 width = (pbox->x2 - pbox->x1) * Bpp;
67 height = pbox->y2 - pbox->y1;
68 src = pSiS->ShadowPtr + (pbox->y1 * pSiS->ShadowPitch) + (pbox->x1 * Bpp);
69 dst = pSiS->FbBase + (pbox->y1 * FBPitch) + (pbox->x1 * Bpp);
71 while(height--) {
72 memcpy(dst, src, width);
73 dst += FBPitch;
74 src += pSiS->ShadowPitch;
77 pbox++;
81 void
82 SISRefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
84 SISPtr pSiS = SISPTR(pScrn);
85 int count, width, height, y1, y2, dstPitch, srcPitch;
86 CARD8 *dstPtr, *srcPtr, *src;
87 CARD32 *dst;
89 dstPitch = pScrn->displayWidth;
90 srcPitch = -pSiS->Rotate * pSiS->ShadowPitch;
92 while(num--) {
93 width = pbox->x2 - pbox->x1;
94 y1 = pbox->y1 & ~3;
95 y2 = (pbox->y2 + 3) & ~3;
96 height = (y2 - y1) >> 2; /* in dwords */
98 if(pSiS->Rotate == 1) {
99 dstPtr = pSiS->FbBase + (pbox->x1 * dstPitch) + pScrn->virtualX - y2;
100 srcPtr = pSiS->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1;
101 } else {
102 dstPtr = pSiS->FbBase + ((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
103 srcPtr = pSiS->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1;
106 while(width--) {
107 src = srcPtr;
108 dst = (CARD32 *)dstPtr;
109 count = height;
110 while(count--) {
111 *(dst++) = src[0] |
112 (src[srcPitch] << 8) |
113 (src[srcPitch * 2] << 16) |
114 (src[srcPitch * 3] << 24);
115 src += (srcPitch * 4);
117 srcPtr += pSiS->Rotate;
118 dstPtr += dstPitch;
121 pbox++;
125 void
126 SISRefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
128 SISPtr pSiS = SISPTR(pScrn);
129 int count, width, height, y1, y2, dstPitch, srcPitch;
130 CARD16 *dstPtr, *srcPtr, *src;
131 CARD32 *dst;
133 dstPitch = pScrn->displayWidth;
134 srcPitch = -pSiS->Rotate * pSiS->ShadowPitch >> 1;
136 while(num--) {
137 width = pbox->x2 - pbox->x1;
138 y1 = pbox->y1 & ~1;
139 y2 = (pbox->y2 + 1) & ~1;
140 height = (y2 - y1) >> 1; /* in dwords */
142 if(pSiS->Rotate == 1) {
143 dstPtr = (CARD16 *)pSiS->FbBase + (pbox->x1 * dstPitch) + pScrn->virtualX - y2;
144 srcPtr = (CARD16 *)pSiS->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1;
145 } else {
146 dstPtr = (CARD16 *)pSiS->FbBase + ((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
147 srcPtr = (CARD16 *)pSiS->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1;
150 while(width--) {
151 src = srcPtr;
152 dst = (CARD32 *)dstPtr;
153 count = height;
154 while(count--) {
155 *(dst++) = src[0] | (src[srcPitch] << 16);
156 src += (srcPitch * 2);
158 srcPtr += pSiS->Rotate;
159 dstPtr += dstPitch;
162 pbox++;
166 /* this one could be faster */
167 void
168 SISRefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
170 SISPtr pSiS = SISPTR(pScrn);
171 int count, width, height, y1, y2, dstPitch, srcPitch;
172 CARD8 *dstPtr, *srcPtr, *src;
173 CARD32 *dst;
175 dstPitch = BitmapBytePad(pScrn->displayWidth * 24);
176 srcPitch = -pSiS->Rotate * pSiS->ShadowPitch;
178 while(num--) {
179 width = pbox->x2 - pbox->x1;
180 y1 = pbox->y1 & ~3;
181 y2 = (pbox->y2 + 3) & ~3;
182 height = (y2 - y1) >> 2; /* blocks of 3 dwords */
184 if(pSiS->Rotate == 1) {
185 dstPtr = pSiS->FbBase + (pbox->x1 * dstPitch) + ((pScrn->virtualX - y2) * 3);
186 srcPtr = pSiS->ShadowPtr + ((1 - y2) * srcPitch) + (pbox->x1 * 3);
187 } else {
188 dstPtr = pSiS->FbBase + ((pScrn->virtualY - pbox->x2) * dstPitch) + (y1 * 3);
189 srcPtr = pSiS->ShadowPtr + (y1 * srcPitch) + (pbox->x2 * 3) - 3;
192 while(width--) {
193 src = srcPtr;
194 dst = (CARD32 *)dstPtr;
195 count = height;
196 while(count--) {
197 dst[0] = src[0] |
198 (src[1] << 8) |
199 (src[2] << 16) |
200 (src[srcPitch] << 24);
201 dst[1] = src[srcPitch + 1] |
202 (src[srcPitch + 2] << 8) |
203 (src[srcPitch * 2] << 16) |
204 (src[(srcPitch * 2) + 1] << 24);
205 dst[2] = src[(srcPitch * 2) + 2] |
206 (src[srcPitch * 3] << 8) |
207 (src[(srcPitch * 3) + 1] << 16) |
208 (src[(srcPitch * 3) + 2] << 24);
209 dst += 3;
210 src += (srcPitch << 2);
212 srcPtr += pSiS->Rotate * 3;
213 dstPtr += dstPitch;
216 pbox++;
220 void
221 SISRefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
223 SISPtr pSiS = SISPTR(pScrn);
224 int count, width, height, dstPitch, srcPitch;
225 CARD32 *dstPtr, *srcPtr, *src, *dst;
227 dstPitch = pScrn->displayWidth;
228 srcPitch = -pSiS->Rotate * pSiS->ShadowPitch >> 2;
230 while(num--) {
231 width = pbox->x2 - pbox->x1;
232 height = pbox->y2 - pbox->y1;
234 if(pSiS->Rotate == 1) {
235 dstPtr = (CARD32 *)pSiS->FbBase + (pbox->x1 * dstPitch) + pScrn->virtualX - pbox->y2;
236 srcPtr = (CARD32 *)pSiS->ShadowPtr + ((1 - pbox->y2) * srcPitch) + pbox->x1;
237 } else {
238 dstPtr = (CARD32 *)pSiS->FbBase + ((pScrn->virtualY - pbox->x2) * dstPitch) + pbox->y1;
239 srcPtr = (CARD32 *)pSiS->ShadowPtr + (pbox->y1 * srcPitch) + pbox->x2 - 1;
242 while(width--) {
243 src = srcPtr;
244 dst = dstPtr;
245 count = height;
246 while(count--) {
247 *(dst++) = *src;
248 src += srcPitch;
250 srcPtr += pSiS->Rotate;
251 dstPtr += dstPitch;
254 pbox++;