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