nv_shadow.c revision bd304fc0
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 "nv_local.h"
11#include "nv_include.h"
12#include "nv_type.h"
13#include "shadowfb.h"
14#include "servermd.h"
15
16
17void
18NVRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
19{
20    NVPtr pNv = NVPTR(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 = pNv->ShadowPtr + (pbox->y1 * pNv->ShadowPitch) +
31						(pbox->x1 * Bpp);
32	dst = pNv->FbStart + (pbox->y1 * FBPitch) + (pbox->x1 * Bpp);
33
34	while(height--) {
35	    memcpy(dst, src, width);
36	    dst += FBPitch;
37	    src += pNv->ShadowPitch;
38	}
39
40	pbox++;
41    }
42}
43
44void
45NVPointerMoved(SCRN_ARG_TYPE arg, int x, int y)
46{
47    SCRN_INFO_PTR(arg);
48    NVPtr pNv = NVPTR(pScrn);
49    int newX, newY;
50
51    if(pNv->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    (*pNv->PointerMoved)(arg, newX, newY);
60}
61
62void
63NVRefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
64{
65    NVPtr pNv = NVPTR(pScrn);
66    int count, width, height, y1, y2, dstPitch, srcPitch;
67    CARD8 *dstPtr, *srcPtr, *src;
68    CARD32 *dst;
69
70    if(!pNv->Rotate) {
71       NVRefreshArea(pScrn, num, pbox);
72       return;
73    }
74
75    dstPitch = pScrn->displayWidth;
76    srcPitch = -pNv->Rotate * pNv->ShadowPitch;
77
78    while(num--) {
79	width = pbox->x2 - pbox->x1;
80	y1 = pbox->y1 & ~3;
81	y2 = (pbox->y2 + 3) & ~3;
82	height = (y2 - y1) >> 2;  /* in dwords */
83
84	if(pNv->Rotate == 1) {
85	    dstPtr = pNv->FbStart +
86			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
87	    srcPtr = pNv->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1;
88	} else {
89	    dstPtr = pNv->FbStart +
90			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
91	    srcPtr = pNv->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1;
92	}
93
94	while(width--) {
95	    src = srcPtr;
96	    dst = (CARD32*)dstPtr;
97	    count = height;
98	    while(count--) {
99		*(dst++) = src[0] | (src[srcPitch] << 8) |
100					(src[srcPitch * 2] << 16) |
101					(src[srcPitch * 3] << 24);
102		src += srcPitch * 4;
103	    }
104	    srcPtr += pNv->Rotate;
105	    dstPtr += dstPitch;
106	}
107
108	pbox++;
109    }
110}
111
112
113void
114NVRefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
115{
116    NVPtr pNv = NVPTR(pScrn);
117    int count, width, height, y1, y2, dstPitch, srcPitch;
118    CARD16 *dstPtr, *srcPtr, *src;
119    CARD32 *dst;
120
121    if(!pNv->Rotate) {
122       NVRefreshArea(pScrn, num, pbox);
123       return;
124    }
125
126    dstPitch = pScrn->displayWidth;
127    srcPitch = -pNv->Rotate * pNv->ShadowPitch >> 1;
128
129    while(num--) {
130	width = pbox->x2 - pbox->x1;
131	y1 = pbox->y1 & ~1;
132	y2 = (pbox->y2 + 1) & ~1;
133	height = (y2 - y1) >> 1;  /* in dwords */
134
135	if(pNv->Rotate == 1) {
136	    dstPtr = (CARD16*)pNv->FbStart +
137			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
138	    srcPtr = (CARD16*)pNv->ShadowPtr +
139			((1 - y2) * srcPitch) + pbox->x1;
140	} else {
141	    dstPtr = (CARD16*)pNv->FbStart +
142			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
143	    srcPtr = (CARD16*)pNv->ShadowPtr +
144			(y1 * srcPitch) + pbox->x2 - 1;
145	}
146
147	while(width--) {
148	    src = srcPtr;
149	    dst = (CARD32*)dstPtr;
150	    count = height;
151	    while(count--) {
152		*(dst++) = src[0] | (src[srcPitch] << 16);
153		src += srcPitch * 2;
154	    }
155	    srcPtr += pNv->Rotate;
156	    dstPtr += dstPitch;
157	}
158
159	pbox++;
160    }
161}
162
163
164void
165NVRefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
166{
167    NVPtr pNv = NVPTR(pScrn);
168    int count, width, height, dstPitch, srcPitch;
169    CARD32 *dstPtr, *srcPtr, *src, *dst;
170
171    if(!pNv->Rotate) {
172       NVRefreshArea(pScrn, num, pbox);
173       return;
174    }
175
176    dstPitch = pScrn->displayWidth;
177    srcPitch = -pNv->Rotate * pNv->ShadowPitch >> 2;
178
179    while(num--) {
180	width = pbox->x2 - pbox->x1;
181	height = pbox->y2 - pbox->y1;
182
183	if(pNv->Rotate == 1) {
184	    dstPtr = (CARD32*)pNv->FbStart +
185			(pbox->x1 * dstPitch) + pScrn->virtualX - pbox->y2;
186	    srcPtr = (CARD32*)pNv->ShadowPtr +
187			((1 - pbox->y2) * srcPitch) + pbox->x1;
188	} else {
189	    dstPtr = (CARD32*)pNv->FbStart +
190			((pScrn->virtualY - pbox->x2) * dstPitch) + pbox->y1;
191	    srcPtr = (CARD32*)pNv->ShadowPtr +
192			(pbox->y1 * srcPitch) + pbox->x2 - 1;
193	}
194
195	while(width--) {
196	    src = srcPtr;
197	    dst = dstPtr;
198	    count = height;
199	    while(count--) {
200		*(dst++) = *src;
201		src += srcPitch;
202	    }
203	    srcPtr += pNv->Rotate;
204	    dstPtr += dstPitch;
205	}
206
207	pbox++;
208    }
209}
210