riva_shadow.c revision fc5a983d
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 "riva_local.h"
11#include "riva_include.h"
12#include "riva_type.h"
13#include "shadowfb.h"
14#include "servermd.h"
15
16
17void
18RivaRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
19{
20    RivaPtr pRiva = RivaPTR(pScrn);
21    int width, height, Bpp, FBPitch;
22    unsigned char *src, *dst;
23
24    Bpp = pScrn->bitsPerPixel >> 3;
25    FBPitch = BitmapBytePad(pScrn->displayWidth * pScrn->bitsPerPixel);
26
27    while(num--) {
28	width = (pbox->x2 - pbox->x1) * Bpp;
29	height = pbox->y2 - pbox->y1;
30	src = pRiva->ShadowPtr + (pbox->y1 * pRiva->ShadowPitch) +
31						(pbox->x1 * Bpp);
32	dst = pRiva->FbStart + (pbox->y1 * FBPitch) + (pbox->x1 * Bpp);
33
34	while(height--) {
35	    memcpy(dst, src, width);
36	    dst += FBPitch;
37	    src += pRiva->ShadowPitch;
38	}
39
40	pbox++;
41    }
42}
43
44void
45RivaPointerMoved(int index, int x, int y)
46{
47    ScrnInfoPtr pScrn = xf86Screens[index];
48    RivaPtr pRiva = RivaPTR(pScrn);
49    int newX, newY;
50
51    if(pRiva->Rotate == 1) {
52	newX = pScrn->pScreen->height - y - 1;
53	newY = x;
54    } else {
55	newX = y;
56	newY = pScrn->pScreen->width - x - 1;
57    }
58
59    (*pRiva->PointerMoved)(index, newX, newY);
60}
61
62void
63RivaRefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
64{
65    RivaPtr pRiva = RivaPTR(pScrn);
66    int count, width, height, y1, y2, dstPitch, srcPitch;
67    CARD8 *dstPtr, *srcPtr, *src;
68    CARD32 *dst;
69
70    dstPitch = pScrn->displayWidth;
71    srcPitch = -pRiva->Rotate * pRiva->ShadowPitch;
72
73    while(num--) {
74	width = pbox->x2 - pbox->x1;
75	y1 = pbox->y1 & ~3;
76	y2 = (pbox->y2 + 3) & ~3;
77	height = (y2 - y1) >> 2;  /* in dwords */
78
79	if(pRiva->Rotate == 1) {
80	    dstPtr = pRiva->FbStart +
81			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
82	    srcPtr = pRiva->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1;
83	} else {
84	    dstPtr = pRiva->FbStart +
85			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
86	    srcPtr = pRiva->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1;
87	}
88
89	while(width--) {
90	    src = srcPtr;
91	    dst = (CARD32*)dstPtr;
92	    count = height;
93	    while(count--) {
94		*(dst++) = src[0] | (src[srcPitch] << 8) |
95					(src[srcPitch * 2] << 16) |
96					(src[srcPitch * 3] << 24);
97		src += srcPitch * 4;
98	    }
99	    srcPtr += pRiva->Rotate;
100	    dstPtr += dstPitch;
101	}
102
103	pbox++;
104    }
105}
106
107
108void
109RivaRefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
110{
111    RivaPtr pRiva = RivaPTR(pScrn);
112    int count, width, height, y1, y2, dstPitch, srcPitch;
113    CARD16 *dstPtr, *srcPtr, *src;
114    CARD32 *dst;
115
116    dstPitch = pScrn->displayWidth;
117    srcPitch = -pRiva->Rotate * pRiva->ShadowPitch >> 1;
118
119    while(num--) {
120	width = pbox->x2 - pbox->x1;
121	y1 = pbox->y1 & ~1;
122	y2 = (pbox->y2 + 1) & ~1;
123	height = (y2 - y1) >> 1;  /* in dwords */
124
125	if(pRiva->Rotate == 1) {
126	    dstPtr = (CARD16*)pRiva->FbStart +
127			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
128	    srcPtr = (CARD16*)pRiva->ShadowPtr +
129			((1 - y2) * srcPitch) + pbox->x1;
130	} else {
131	    dstPtr = (CARD16*)pRiva->FbStart +
132			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
133	    srcPtr = (CARD16*)pRiva->ShadowPtr +
134			(y1 * srcPitch) + pbox->x2 - 1;
135	}
136
137	while(width--) {
138	    src = srcPtr;
139	    dst = (CARD32*)dstPtr;
140	    count = height;
141	    while(count--) {
142		*(dst++) = src[0] | (src[srcPitch] << 16);
143		src += srcPitch * 2;
144	    }
145	    srcPtr += pRiva->Rotate;
146	    dstPtr += dstPitch;
147	}
148
149	pbox++;
150    }
151}
152
153
154void
155RivaRefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
156{
157    RivaPtr pRiva = RivaPTR(pScrn);
158    int count, width, height, dstPitch, srcPitch;
159    CARD32 *dstPtr, *srcPtr, *src, *dst;
160
161    dstPitch = pScrn->displayWidth;
162    srcPitch = -pRiva->Rotate * pRiva->ShadowPitch >> 2;
163
164    while(num--) {
165	width = pbox->x2 - pbox->x1;
166	height = pbox->y2 - pbox->y1;
167
168	if(pRiva->Rotate == 1) {
169	    dstPtr = (CARD32*)pRiva->FbStart +
170			(pbox->x1 * dstPitch) + pScrn->virtualX - pbox->y2;
171	    srcPtr = (CARD32*)pRiva->ShadowPtr +
172			((1 - pbox->y2) * srcPitch) + pbox->x1;
173	} else {
174	    dstPtr = (CARD32*)pRiva->FbStart +
175			((pScrn->virtualY - pbox->x2) * dstPitch) + pbox->y1;
176	    srcPtr = (CARD32*)pRiva->ShadowPtr +
177			(pbox->y1 * srcPitch) + pbox->x2 - 1;
178	}
179
180	while(width--) {
181	    src = srcPtr;
182	    dst = dstPtr;
183	    count = height;
184	    while(count--) {
185		*(dst++) = *src;
186		src += srcPitch;
187	    }
188	    srcPtr += pRiva->Rotate;
189	    dstPtr += dstPitch;
190	}
191
192	pbox++;
193    }
194}
195