sis_shadow.c 10.7 KB
Newer Older
1
/*
2 3
 * Copyright (C) 1999-2004 by The XFree86 Project, Inc.
 * based on code written by Mark Vojkovich
Thomas Winischhofer's avatar
Thomas Winischhofer committed
4
 * Copyright (C) 2003-2005 Thomas Winischhofer
5 6
 *
 * Licensed under the following terms:
7 8 9
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
10 11 12 13 14
 * the above copyright notice appears in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * and that the name of the copyright holder not be used in advertising
 * or publicity pertaining to distribution of the software without specific,
 * written prior permission. The copyright holder makes no representations
15
 * about the suitability of this software for any purpose.  It is provided
16
 * "as is" without expressed or implied warranty.
17 18
 *
 * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
20 21 22 23 24
 * EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
25
 *
26 27
 * This module doesn't use CurrentLayout, because it is never
 * active when DGA is active and vice versa.
28 29
 */

30 31 32 33
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

34 35
#include "sis.h"
#include "servermd.h"
Thomas Winischhofer's avatar
Thomas Winischhofer committed
36

37 38
void SISPointerMoved(SCRN_ARG_TYPE arg, int x, int y);
void SISPointerMovedReflect(SCRN_ARG_TYPE arg, int x, int y);
Thomas Winischhofer's avatar
Thomas Winischhofer committed
39
void SISRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
Thomas Winischhofer's avatar
Thomas Winischhofer committed
40
void SISRefreshAreaReflect(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
Thomas Winischhofer's avatar
Thomas Winischhofer committed
41 42 43 44
void SISRefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
void SISRefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
void SISRefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
void SISRefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
45

46
void
47
SISPointerMoved(SCRN_ARG_TYPE arg, int x, int y)
48
{
49
    SCRN_INFO_PTR(arg);
50 51 52
    SISPtr pSiS = SISPTR(pScrn);

    if(pSiS->Rotate == 1) {
53
       (*pSiS->PointerMoved)(arg, pScrn->pScreen->height - y - 1, x);
54
    } else {
55
       (*pSiS->PointerMoved)(arg, y, pScrn->pScreen->width - x - 1);
56 57 58
    }
}

Thomas Winischhofer's avatar
Thomas Winischhofer committed
59
void
60
SISPointerMovedReflect(SCRN_ARG_TYPE arg, int x, int y)
Thomas Winischhofer's avatar
Thomas Winischhofer committed
61
{
62
    SCRN_INFO_PTR(arg);
Thomas Winischhofer's avatar
Thomas Winischhofer committed
63 64 65 66
    SISPtr pSiS = SISPTR(pScrn);

    switch(pSiS->Reflect) {
    case 1: /* x */
67
       (*pSiS->PointerMoved)(arg, pScrn->pScreen->width - x - 1, y);
Thomas Winischhofer's avatar
Thomas Winischhofer committed
68 69
       break;
    case 2: /* y */
70
       (*pSiS->PointerMoved)(arg, x, pScrn->pScreen->height - y - 1);
Thomas Winischhofer's avatar
Thomas Winischhofer committed
71 72
       break;
    case 3: /* x + y */
73
       (*pSiS->PointerMoved)(arg, pScrn->pScreen->width - x - 1, pScrn->pScreen->height - y - 1);
Thomas Winischhofer's avatar
Thomas Winischhofer committed
74 75 76
    }
}

77
/* Refresh area (unreflected, unrotated) */
Thomas Winischhofer's avatar
Thomas Winischhofer committed
78

79 80 81 82
void
SISRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
{
    SISPtr pSiS = SISPTR(pScrn);
83 84
    int    width, height, Bpp, FBPitch;
    CARD8  *src, *dst;
Thomas Winischhofer's avatar
Thomas Winischhofer committed
85

86 87
    Bpp = pScrn->bitsPerPixel >> 3;
    FBPitch = BitmapBytePad(pScrn->displayWidth * pScrn->bitsPerPixel);
Thomas Winischhofer's avatar
Thomas Winischhofer committed
88

89
    while(num--) {
Thomas Winischhofer's avatar
Thomas Winischhofer committed
90

91 92 93 94 95 96
       width = (pbox->x2 - pbox->x1) * Bpp;
       height = pbox->y2 - pbox->y1;
       src = pSiS->ShadowPtr + (pbox->y1 * pSiS->ShadowPitch) +  (pbox->x1 * Bpp);
       dst = pSiS->FbBase + (pbox->y1 * FBPitch) + (pbox->x1 * Bpp);

       while(height--) {
Thomas Winischhofer's avatar
Thomas Winischhofer committed
97
          SiSMemCopyToVideoRam(pSiS, dst, src, width);
98 99 100
	  dst += FBPitch;
	  src += pSiS->ShadowPitch;
       }
Thomas Winischhofer's avatar
Thomas Winischhofer committed
101

102
       pbox++;
103
    }
Thomas Winischhofer's avatar
Thomas Winischhofer committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
}

/* RefreshArea for reflection */

void
SISRefreshAreaReflect(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
{
    SISPtr pSiS = SISPTR(pScrn);
    int    width, height, Bpp, FBPitch, twidth;
    CARD8  *src, *dst, *tdst, *tsrc;
    CARD16 *tdst16, *tsrc16;
    CARD32 *tdst32, *tsrc32;

    Bpp = pScrn->bitsPerPixel >> 3;
    FBPitch = BitmapBytePad(pScrn->displayWidth * pScrn->bitsPerPixel);

    while(num--) {
       width = (pbox->x2 - pbox->x1) * Bpp;
       height = pbox->y2 - pbox->y1;
       src = pSiS->ShadowPtr + (pbox->y1 * pSiS->ShadowPitch) +  (pbox->x1 * Bpp);
       dst = pSiS->FbBase;
       switch(pSiS->Reflect) {
       case 1:	/* x */
	  dst += (pbox->y1 * FBPitch) + ((pScrn->displayWidth - pbox->x1 - 1) * Bpp);
	  switch(Bpp) {
	     case 1:
		while(height--) {
		   tdst = dst;
		   tsrc = src;
		   twidth = width;
		   while(twidth--) *tdst-- = *tsrc++;
		   dst += FBPitch;
		   src += pSiS->ShadowPitch;
		}
		break;
	     case 2:
		width >>= 1;
		while(height--) {
		   tdst16 = (CARD16 *)dst;
		   tsrc16 = (CARD16 *)src;
		   twidth = width;
		   while(twidth--) *tdst16-- = *tsrc16++;
		   dst += FBPitch;
		   src += pSiS->ShadowPitch;
		}
		break;
	     case 4:
		width >>= 2;
		while(height--) {
		   tdst32 = (CARD32 *)dst;
		   tsrc32 = (CARD32 *)src;
		   twidth = width;
		   while(twidth--) *tdst32-- = *tsrc32++;
		   dst += FBPitch;
		   src += pSiS->ShadowPitch;
		}
	  }
	  break;
       case 2:	/* y */
	  dst += ((pScrn->virtualY - pbox->y1 - 1) * FBPitch) + (pbox->x1 * Bpp);
	  while(height--) {
	     SiSMemCopyToVideoRam(pSiS, dst, src, width);
	     dst -= FBPitch;
	     src += pSiS->ShadowPitch;
	  }
	  break;
       case 3:	/* x + y */
	  dst += ((pScrn->virtualY - pbox->y1 - 1) * FBPitch) + ((pScrn->displayWidth - pbox->x1 - 1) * Bpp);
	  switch(Bpp) {
	     case 1:
		while(height--) {
		   tdst = dst;
		   tsrc = src;
		   twidth = width;
		   while(twidth--) *tdst-- = *tsrc++;
		   dst -= FBPitch;
		   src += pSiS->ShadowPitch;
		}
		break;
	     case 2:
	        width >>= 1;
		while(height--) {
		   tdst16 = (CARD16 *)dst;
		   tsrc16 = (CARD16 *)src;
		   twidth = width;
		   while(twidth--) *tdst16-- = *tsrc16++;
		   dst -= FBPitch;
		   src += pSiS->ShadowPitch;
		}
		break;
	     case 4:
		width >>= 2;
		while(height--) {
		   tdst32 = (CARD32 *)dst;
		   tsrc32 = (CARD32 *)src;
		   twidth = width;
		   while(twidth--) *tdst32-- = *tsrc32++;
		   dst -= FBPitch;
		   src += pSiS->ShadowPitch;
		}
		break;
	  }
       }
       pbox++;
    }
}

/* RefreshArea()s for rotation */
212 213 214 215 216

void
SISRefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
{
    SISPtr pSiS = SISPTR(pScrn);
217 218
    int    count, width, height, y1, y2, dstPitch, srcPitch;
    CARD8  *dstPtr, *srcPtr, *src;
219 220 221 222 223 224
    CARD32 *dst;

    dstPitch = pScrn->displayWidth;
    srcPitch = -pSiS->Rotate * pSiS->ShadowPitch;

    while(num--) {
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
       width = pbox->x2 - pbox->x1;
       y1 = pbox->y1 & ~3;
       y2 = (pbox->y2 + 3) & ~3;
       height = (y2 - y1) >> 2;  /* in dwords */

       if(pSiS->Rotate == 1) {
	  dstPtr = pSiS->FbBase + (pbox->x1 * dstPitch) + pScrn->virtualX - y2;
	  srcPtr = pSiS->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1;
       } else {
	  dstPtr = pSiS->FbBase +  ((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
	  srcPtr = pSiS->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1;
       }

       while(width--) {
	  src = srcPtr;
	  dst = (CARD32 *)dstPtr;
	  count = height;
	  while(count--) {
Thomas Winischhofer's avatar
Thomas Winischhofer committed
243 244 245
	     *(dst++) = src[0]                    |
		        (src[srcPitch]     <<  8) |
		        (src[srcPitch * 2] << 16) |
246 247 248 249 250 251 252 253
			(src[srcPitch * 3] << 24);
	     src += (srcPitch * 4);
	  }
	  srcPtr += pSiS->Rotate;
	  dstPtr += dstPitch;
       }

       pbox++;
254
    }
Thomas Winischhofer's avatar
Thomas Winischhofer committed
255
}
256 257 258 259 260 261 262 263 264 265 266 267 268

void
SISRefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
{
    SISPtr pSiS = SISPTR(pScrn);
    int count, width, height, y1, y2, dstPitch, srcPitch;
    CARD16 *dstPtr, *srcPtr, *src;
    CARD32 *dst;

    dstPitch = pScrn->displayWidth;
    srcPitch = -pSiS->Rotate * pSiS->ShadowPitch >> 1;

    while(num--) {
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
       width = pbox->x2 - pbox->x1;
       y1 = pbox->y1 & ~1;
       y2 = (pbox->y2 + 1) & ~1;
       height = (y2 - y1) >> 1;  /* in dwords */

       if(pSiS->Rotate == 1) {
	  dstPtr = (CARD16 *)pSiS->FbBase + (pbox->x1 * dstPitch) + pScrn->virtualX - y2;
	  srcPtr = (CARD16 *)pSiS->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1;
       } else {
	  dstPtr = (CARD16 *)pSiS->FbBase + ((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
	  srcPtr = (CARD16 *)pSiS->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1;
       }

       while(width--) {
	  src = srcPtr;
	  dst = (CARD32 *)dstPtr;
	  count = height;
	  while(count--) {
	     *(dst++) = src[0] | (src[srcPitch] << 16);
	     src += (srcPitch * 2);
	  }
	  srcPtr += pSiS->Rotate;
	  dstPtr += dstPitch;
       }

       pbox++;
295 296 297 298 299 300 301 302
    }
}

/* this one could be faster */
void
SISRefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
{
    SISPtr pSiS = SISPTR(pScrn);
303 304
    int    count, width, height, y1, y2, dstPitch, srcPitch;
    CARD8  *dstPtr, *srcPtr, *src;
305 306 307 308 309 310
    CARD32 *dst;

    dstPitch = BitmapBytePad(pScrn->displayWidth * 24);
    srcPitch = -pSiS->Rotate * pSiS->ShadowPitch;

    while(num--) {
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
       width = pbox->x2 - pbox->x1;
       y1 = pbox->y1 & ~3;
       y2 = (pbox->y2 + 3) & ~3;
       height = (y2 - y1) >> 2;  /* blocks of 3 dwords */

       if(pSiS->Rotate == 1) {
	  dstPtr = pSiS->FbBase + (pbox->x1 * dstPitch) + ((pScrn->virtualX - y2) * 3);
	  srcPtr = pSiS->ShadowPtr + ((1 - y2) * srcPitch) + (pbox->x1 * 3);
       } else {
	  dstPtr = pSiS->FbBase + ((pScrn->virtualY - pbox->x2) * dstPitch) + (y1 * 3);
	  srcPtr = pSiS->ShadowPtr + (y1 * srcPitch) + (pbox->x2 * 3) - 3;
       }

       while(width--) {
	  src = srcPtr;
	  dst = (CARD32 *)dstPtr;
	  count = height;
	  while(count--) {
Thomas Winischhofer's avatar
Thomas Winischhofer committed
329 330
	     dst[0] = src[0]         |
		      (src[1] << 8)  |
331
		      (src[2] << 16) |
Thomas Winischhofer's avatar
Thomas Winischhofer committed
332 333
		      (src[srcPitch] << 24);
	     dst[1] = src[srcPitch + 1]         |
334 335
		      (src[srcPitch + 2] << 8)  |
		      (src[srcPitch * 2] << 16) |
Thomas Winischhofer's avatar
Thomas Winischhofer committed
336 337
		      (src[(srcPitch * 2) + 1] << 24);
	     dst[2] = src[(srcPitch * 2) + 2]         |
338 339
		      (src[srcPitch * 3] << 8)        |
		      (src[(srcPitch * 3) + 1] << 16) |
Thomas Winischhofer's avatar
Thomas Winischhofer committed
340
		      (src[(srcPitch * 3) + 2] << 24);
341 342 343 344
	     dst += 3;
	     src += (srcPitch << 2);
	  }
	  srcPtr += pSiS->Rotate * 3;
Thomas Winischhofer's avatar
Thomas Winischhofer committed
345
	  dstPtr += dstPitch;
346 347 348
       }

       pbox++;
349 350 351 352 353 354 355
    }
}

void
SISRefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
{
    SISPtr pSiS = SISPTR(pScrn);
356
    int    count, width, height, dstPitch, srcPitch;
357 358 359 360 361 362
    CARD32 *dstPtr, *srcPtr, *src, *dst;

    dstPitch = pScrn->displayWidth;
    srcPitch = -pSiS->Rotate * pSiS->ShadowPitch >> 2;

    while(num--) {
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
       width = pbox->x2 - pbox->x1;
       height = pbox->y2 - pbox->y1;

       if(pSiS->Rotate == 1) {
	  dstPtr = (CARD32 *)pSiS->FbBase + (pbox->x1 * dstPitch) + pScrn->virtualX - pbox->y2;
	  srcPtr = (CARD32 *)pSiS->ShadowPtr + ((1 - pbox->y2) * srcPitch) + pbox->x1;
       } else {
	  dstPtr = (CARD32 *)pSiS->FbBase + ((pScrn->virtualY - pbox->x2) * dstPitch) + pbox->y1;
	  srcPtr = (CARD32 *)pSiS->ShadowPtr + (pbox->y1 * srcPitch) + pbox->x2 - 1;
       }

       while(width--) {
	  src = srcPtr;
	  dst = dstPtr;
	  count = height;
	  while(count--) {
	     *(dst++) = *src;
	     src += srcPitch;
	  }
	  srcPtr += pSiS->Rotate;
	  dstPtr += dstPitch;
       }

       pbox++;
387 388
    }
}