mga_shadow.c revision fe5e51b7
1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_shadow.c,v 1.1 1999/08/14 10:49:48 dawes Exp $ */ 2 3/* 4 Copyright (c) 1999, The XFree86 Project Inc. 5 Written by Mark Vojkovich <markv@valinux.com> 6*/ 7 8#ifdef HAVE_CONFIG_H 9#include "config.h" 10#endif 11 12#include "xf86.h" 13#include "xf86_OSproc.h" 14#include "xf86Resources.h" 15#include "xf86PciInfo.h" 16#include "xf86Pci.h" 17#include "mga_reg.h" 18#include "mga.h" 19#include "shadowfb.h" 20#include "servermd.h" 21 22 23 24void 25MGARefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox) 26{ 27 MGAPtr pMga = MGAPTR(pScrn); 28 int width, height, Bpp, FBPitch; 29 unsigned char *src, *dst; 30 31 Bpp = pScrn->bitsPerPixel >> 3; 32 FBPitch = BitmapBytePad(pScrn->displayWidth * pScrn->bitsPerPixel); 33 34 while(num--) { 35 width = (pbox->x2 - pbox->x1) * Bpp; 36 height = pbox->y2 - pbox->y1; 37 src = pMga->ShadowPtr + (pbox->y1 * pMga->ShadowPitch) + 38 (pbox->x1 * Bpp); 39 dst = pMga->FbStart + (pbox->y1 * FBPitch) + (pbox->x1 * Bpp); 40 41 while(height--) { 42 memcpy(dst, src, width); 43 dst += FBPitch; 44 src += pMga->ShadowPitch; 45 } 46 47 pbox++; 48 } 49} 50 51void 52MGAPointerMoved(int index, int x, int y) 53{ 54 ScrnInfoPtr pScrn = xf86Screens[index]; 55 MGAPtr pMga = MGAPTR(pScrn); 56 int newX, newY; 57 58 if(pMga->Rotate == 1) { 59 newX = pScrn->pScreen->height - y - 1; 60 newY = x; 61 } else { 62 newX = y; 63 newY = pScrn->pScreen->width - x - 1; 64 } 65 66 (*pMga->PointerMoved)(index, newX, newY); 67} 68 69void 70MGARefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox) 71{ 72 MGAPtr pMga = MGAPTR(pScrn); 73 int count, width, height, y1, y2, dstPitch, srcPitch; 74 CARD8 *dstPtr, *srcPtr, *src; 75 CARD32 *dst; 76 77 dstPitch = pScrn->displayWidth; 78 srcPitch = -pMga->Rotate * pMga->ShadowPitch; 79 80 while(num--) { 81 width = pbox->x2 - pbox->x1; 82 y1 = pbox->y1 & ~3; 83 y2 = (pbox->y2 + 3) & ~3; 84 height = (y2 - y1) >> 2; /* in dwords */ 85 86 if(pMga->Rotate == 1) { 87 dstPtr = pMga->FbStart + 88 (pbox->x1 * dstPitch) + pScrn->virtualX - y2; 89 srcPtr = pMga->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1; 90 } else { 91 dstPtr = pMga->FbStart + 92 ((pScrn->virtualY - pbox->x2) * dstPitch) + y1; 93 srcPtr = pMga->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1; 94 } 95 96 while(width--) { 97 src = srcPtr; 98 dst = (CARD32*)dstPtr; 99 count = height; 100 while(count--) { 101 *(dst++) = src[0] | (src[srcPitch] << 8) | 102 (src[srcPitch * 2] << 16) | 103 (src[srcPitch * 3] << 24); 104 src += srcPitch * 4; 105 } 106 srcPtr += pMga->Rotate; 107 dstPtr += dstPitch; 108 } 109 110 pbox++; 111 } 112} 113 114 115void 116MGARefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox) 117{ 118 MGAPtr pMga = MGAPTR(pScrn); 119 int count, width, height, y1, y2, dstPitch, srcPitch; 120 CARD16 *dstPtr, *srcPtr, *src; 121 CARD32 *dst; 122 123 dstPitch = pScrn->displayWidth; 124 srcPitch = -pMga->Rotate * pMga->ShadowPitch >> 1; 125 126 while(num--) { 127 width = pbox->x2 - pbox->x1; 128 y1 = pbox->y1 & ~1; 129 y2 = (pbox->y2 + 1) & ~1; 130 height = (y2 - y1) >> 1; /* in dwords */ 131 132 if(pMga->Rotate == 1) { 133 dstPtr = (CARD16*)pMga->FbStart + 134 (pbox->x1 * dstPitch) + pScrn->virtualX - y2; 135 srcPtr = (CARD16*)pMga->ShadowPtr + 136 ((1 - y2) * srcPitch) + pbox->x1; 137 } else { 138 dstPtr = (CARD16*)pMga->FbStart + 139 ((pScrn->virtualY - pbox->x2) * dstPitch) + y1; 140 srcPtr = (CARD16*)pMga->ShadowPtr + 141 (y1 * srcPitch) + pbox->x2 - 1; 142 } 143 144 while(width--) { 145 src = srcPtr; 146 dst = (CARD32*)dstPtr; 147 count = height; 148 while(count--) { 149 *(dst++) = src[0] | (src[srcPitch] << 16); 150 src += srcPitch * 2; 151 } 152 srcPtr += pMga->Rotate; 153 dstPtr += dstPitch; 154 } 155 156 pbox++; 157 } 158} 159 160 161/* this one could be faster */ 162void 163MGARefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox) 164{ 165 MGAPtr pMga = MGAPTR(pScrn); 166 int count, width, height, y1, y2, dstPitch, srcPitch; 167 CARD8 *dstPtr, *srcPtr, *src; 168 CARD32 *dst; 169 170 dstPitch = BitmapBytePad(pScrn->displayWidth * 24); 171 srcPitch = -pMga->Rotate * pMga->ShadowPitch; 172 173 while(num--) { 174 width = pbox->x2 - pbox->x1; 175 y1 = pbox->y1 & ~3; 176 y2 = (pbox->y2 + 3) & ~3; 177 height = (y2 - y1) >> 2; /* blocks of 3 dwords */ 178 179 if(pMga->Rotate == 1) { 180 dstPtr = pMga->FbStart + 181 (pbox->x1 * dstPitch) + ((pScrn->virtualX - y2) * 3); 182 srcPtr = pMga->ShadowPtr + ((1 - y2) * srcPitch) + (pbox->x1 * 3); 183 } else { 184 dstPtr = pMga->FbStart + 185 ((pScrn->virtualY - pbox->x2) * dstPitch) + (y1 * 3); 186 srcPtr = pMga->ShadowPtr + (y1 * srcPitch) + (pbox->x2 * 3) - 3; 187 } 188 189 while(width--) { 190 src = srcPtr; 191 dst = (CARD32*)dstPtr; 192 count = height; 193 while(count--) { 194 dst[0] = src[0] | (src[1] << 8) | (src[2] << 16) | 195 (src[srcPitch] << 24); 196 dst[1] = src[srcPitch + 1] | (src[srcPitch + 2] << 8) | 197 (src[srcPitch * 2] << 16) | 198 (src[(srcPitch * 2) + 1] << 24); 199 dst[2] = src[(srcPitch * 2) + 2] | (src[srcPitch * 3] << 8) | 200 (src[(srcPitch * 3) + 1] << 16) | 201 (src[(srcPitch * 3) + 2] << 24); 202 dst += 3; 203 src += srcPitch * 4; 204 } 205 srcPtr += pMga->Rotate * 3; 206 dstPtr += dstPitch; 207 } 208 209 pbox++; 210 } 211} 212 213void 214MGARefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox) 215{ 216 MGAPtr pMga = MGAPTR(pScrn); 217 int count, width, height, dstPitch, srcPitch; 218 CARD32 *dstPtr, *srcPtr, *src, *dst; 219 220 dstPitch = pScrn->displayWidth; 221 srcPitch = -pMga->Rotate * pMga->ShadowPitch >> 2; 222 223 while(num--) { 224 width = pbox->x2 - pbox->x1; 225 height = pbox->y2 - pbox->y1; 226 227 if(pMga->Rotate == 1) { 228 dstPtr = (CARD32*)pMga->FbStart + 229 (pbox->x1 * dstPitch) + pScrn->virtualX - pbox->y2; 230 srcPtr = (CARD32*)pMga->ShadowPtr + 231 ((1 - pbox->y2) * srcPitch) + pbox->x1; 232 } else { 233 dstPtr = (CARD32*)pMga->FbStart + 234 ((pScrn->virtualY - pbox->x2) * dstPitch) + pbox->y1; 235 srcPtr = (CARD32*)pMga->ShadowPtr + 236 (pbox->y1 * srcPitch) + pbox->x2 - 1; 237 } 238 239 while(width--) { 240 src = srcPtr; 241 dst = dstPtr; 242 count = height; 243 while(count--) { 244 *(dst++) = *src; 245 src += srcPitch; 246 } 247 srcPtr += pMga->Rotate; 248 dstPtr += dstPitch; 249 } 250 251 pbox++; 252 } 253} 254 255 256 257