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