mirror of
https://github.com/Stichting-MINIX-Research-Foundation/xsrc.git
synced 2025-09-19 09:35:04 -04:00
267 lines
6.9 KiB
C
267 lines
6.9 KiB
C
/* $NetBSD: sfbblt.c,v 1.1 2004/01/18 05:21:41 rtr Exp $ */
|
|
|
|
/*
|
|
* sfb copy area
|
|
*/
|
|
|
|
/*
|
|
|
|
Copyright (c) 1989 X Consortium
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
Except as contained in this notice, the name of the X Consortium shall not be
|
|
used in advertising or otherwise to promote the sale, use or other dealings
|
|
in this Software without prior written authorization from the X Consortium.
|
|
|
|
Author: Keith Packard
|
|
|
|
*/
|
|
/* $XConsortium: cfbblt.c,v 1.13 94/04/17 20:28:44 dpw Exp $ */
|
|
/* $XFree86: xc/programs/Xserver/cfb/cfbblt.c,v 3.1.2.1 1998/12/13 14:12:03 dawes Exp $ */
|
|
|
|
/* 24-bit bug fixes: Peter Wainwright, 1998/11/28 */
|
|
|
|
#define MROP Mcopy
|
|
|
|
#ifndef PSZ
|
|
#define PSZ 8
|
|
#endif
|
|
|
|
#include "X.h"
|
|
#include "Xmd.h"
|
|
#include "Xproto.h"
|
|
#include "gcstruct.h"
|
|
#include "windowstr.h"
|
|
#include "scrnintstr.h"
|
|
#include "pixmapstr.h"
|
|
#include "regionstr.h"
|
|
#include "cfb.h"
|
|
#include "cfbmskbits.h"
|
|
#include "cfb8bit.h"
|
|
#include "fastblt.h"
|
|
#include "mergerop.h"
|
|
|
|
#include <stdio.h>
|
|
/* #include "clstuff.h" */ /* defines for blitting */
|
|
/*static unsigned char *clregs,*clfb;*/
|
|
|
|
#include "dec.h"
|
|
#include "sfb.h"
|
|
#include "sfbmap.h"
|
|
|
|
void
|
|
MROP_NAME(decSfbDoBitblt)(pSrc, pDst, alu, prgnDst, pptSrc, planemask)
|
|
DrawablePtr pSrc, pDst;
|
|
int alu;
|
|
RegionPtr prgnDst;
|
|
DDXPointPtr pptSrc;
|
|
unsigned long planemask;
|
|
{
|
|
unsigned int *psrcBase, *pdstBase;
|
|
/* start of src and dst bitmaps */
|
|
int widthSrc, widthDst; /* add to get to same position in next line */
|
|
|
|
BoxPtr pbox;
|
|
int nbox;
|
|
|
|
BoxPtr pboxTmp, pboxNext, pboxBase, pboxNew1, pboxNew2;
|
|
/* temporaries for shuffling rectangles */
|
|
DDXPointPtr pptTmp, pptNew1, pptNew2;
|
|
/* shuffling boxes entails shuffling the
|
|
source points too */
|
|
int w, h;
|
|
int xdir; /* 1 = left right, -1 = right left/ */
|
|
int ydir; /* 1 = top down, -1 = bottom up */
|
|
|
|
unsigned int psrcLine, pdstLine;
|
|
/* current src and dst (add to psrcBase, etc) */
|
|
|
|
MROP_DECLARE_REG()
|
|
|
|
/* following used for looping through a line */
|
|
unsigned int startmask, endmask; /* masks for writing ends of dst */
|
|
int nlMiddle; /* whole longwords in dst */
|
|
int xoffSrc, xoffDst;
|
|
register int leftShift, rightShift;
|
|
register unsigned int bits;
|
|
register unsigned int bits1;
|
|
register int nl; /* temp copy of nlMiddle */
|
|
|
|
/* place to store full source word */
|
|
int nstart; /* number of ragged bits at start of dst */
|
|
int nend; /* number of ragged bits at end of dst */
|
|
int srcStartOver; /* pulling nstart bits from src
|
|
overflows into the next word? */
|
|
int careful;
|
|
int tmpSrc;
|
|
|
|
fbFd *inf = &decFbs[pSrc->pScreen->myNum];
|
|
unsigned char *fb = inf->fb;
|
|
sfb_reg_t **regs = inf->regs.sfbregs;
|
|
int creg = 0;
|
|
|
|
if (pSrc != pDst)
|
|
return cfbDoBitbltCopy(pSrc, pDst, alu, prgnDst, pptSrc, planemask);
|
|
|
|
MROP_INITIALIZE(alu,planemask);
|
|
|
|
cfbGetTypedWidthAndPointer (pSrc, widthSrc, psrcBase, unsigned, unsigned)
|
|
cfbGetTypedWidthAndPointer (pDst, widthDst, pdstBase, unsigned, unsigned)
|
|
|
|
/* XXX we have to err on the side of safety when both are windows,
|
|
* because we don't know if IncludeInferiors is being used.
|
|
*/
|
|
careful = ((pSrc == pDst) ||
|
|
((pSrc->type == DRAWABLE_WINDOW) &&
|
|
(pDst->type == DRAWABLE_WINDOW)));
|
|
|
|
pbox = REGION_RECTS(prgnDst);
|
|
nbox = REGION_NUM_RECTS(prgnDst);
|
|
|
|
pboxNew1 = NULL;
|
|
pptNew1 = NULL;
|
|
pboxNew2 = NULL;
|
|
pptNew2 = NULL;
|
|
if (careful && (pptSrc->y < pbox->y1))
|
|
{
|
|
/* walk source botttom to top */
|
|
ydir = -1;
|
|
widthSrc = -widthSrc;
|
|
widthDst = -widthDst;
|
|
|
|
if (nbox > 1)
|
|
{
|
|
/* keep ordering in each band, reverse order of bands */
|
|
pboxNew1 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
|
|
if(!pboxNew1)
|
|
return;
|
|
pptNew1 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
|
|
if(!pptNew1)
|
|
{
|
|
DEALLOCATE_LOCAL(pboxNew1);
|
|
return;
|
|
}
|
|
pboxBase = pboxNext = pbox+nbox-1;
|
|
while (pboxBase >= pbox)
|
|
{
|
|
while ((pboxNext >= pbox) &&
|
|
(pboxBase->y1 == pboxNext->y1))
|
|
pboxNext--;
|
|
pboxTmp = pboxNext+1;
|
|
pptTmp = pptSrc + (pboxTmp - pbox);
|
|
while (pboxTmp <= pboxBase)
|
|
{
|
|
*pboxNew1++ = *pboxTmp++;
|
|
*pptNew1++ = *pptTmp++;
|
|
}
|
|
pboxBase = pboxNext;
|
|
}
|
|
pboxNew1 -= nbox;
|
|
pbox = pboxNew1;
|
|
pptNew1 -= nbox;
|
|
pptSrc = pptNew1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* walk source top to bottom */
|
|
ydir = 1;
|
|
}
|
|
|
|
if (careful && (pptSrc->x < pbox->x1))
|
|
{
|
|
/* walk source right to left */
|
|
xdir = -1;
|
|
|
|
if (nbox > 1)
|
|
{
|
|
/* reverse order of rects in each band */
|
|
pboxNew2 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
|
|
pptNew2 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
|
|
if(!pboxNew2 || !pptNew2)
|
|
{
|
|
if (pptNew2) DEALLOCATE_LOCAL(pptNew2);
|
|
if (pboxNew2) DEALLOCATE_LOCAL(pboxNew2);
|
|
if (pboxNew1)
|
|
{
|
|
DEALLOCATE_LOCAL(pptNew1);
|
|
DEALLOCATE_LOCAL(pboxNew1);
|
|
}
|
|
return;
|
|
}
|
|
pboxBase = pboxNext = pbox;
|
|
while (pboxBase < pbox+nbox)
|
|
{
|
|
while ((pboxNext < pbox+nbox) &&
|
|
(pboxNext->y1 == pboxBase->y1))
|
|
pboxNext++;
|
|
pboxTmp = pboxNext;
|
|
pptTmp = pptSrc + (pboxTmp - pbox);
|
|
while (pboxTmp != pboxBase)
|
|
{
|
|
*pboxNew2++ = *--pboxTmp;
|
|
*pptNew2++ = *--pptTmp;
|
|
}
|
|
pboxBase = pboxNext;
|
|
}
|
|
pboxNew2 -= nbox;
|
|
pbox = pboxNew2;
|
|
pptNew2 -= nbox;
|
|
pptSrc = pptNew2;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* walk source left to right */
|
|
xdir = 1;
|
|
}
|
|
|
|
while (nbox--) {
|
|
decSfbDoBitbltSimple(
|
|
psrcBase,
|
|
pdstBase,
|
|
widthSrc,
|
|
widthDst,
|
|
regs,
|
|
alu,
|
|
pptSrc->x,
|
|
pptSrc->y,
|
|
pbox->x1,
|
|
pbox->y1,
|
|
pbox->y2 - pbox->y1,
|
|
pbox->x2 - pbox->x1,
|
|
xdir,
|
|
ydir);
|
|
|
|
pbox++;
|
|
pptSrc++;
|
|
}
|
|
done:
|
|
if (pboxNew2)
|
|
{
|
|
DEALLOCATE_LOCAL(pptNew2);
|
|
DEALLOCATE_LOCAL(pboxNew2);
|
|
}
|
|
if (pboxNew1)
|
|
{
|
|
DEALLOCATE_LOCAL(pptNew1);
|
|
DEALLOCATE_LOCAL(pboxNew1);
|
|
}
|
|
}
|