xserver-multidpi/hw/xfree86/xaa/xaaFillRect.c

1102 lines
35 KiB
C
Raw Normal View History

2003-11-14 17:48:57 +01:00
#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif
#include "misc.h"
2003-11-14 17:48:57 +01:00
#include "xf86.h"
#include "xf86_OSproc.h"
#include <X11/X.h>
2003-11-14 17:48:57 +01:00
#include "scrnintstr.h"
#include "pixmapstr.h"
#include "xf86str.h"
#include "xaa.h"
#include "xaalocal.h"
static void XAARenderSolidRects(GCPtr, int, BoxPtr, int, int);
static void XAARenderColor8x8Rects(GCPtr, int, BoxPtr, int, int);
static void XAARenderMono8x8Rects(GCPtr, int, BoxPtr, int, int);
static void XAARenderColorExpandRects(GCPtr, int, BoxPtr, int, int);
static void XAARenderCacheExpandRects(GCPtr, int, BoxPtr, int, int);
static void XAARenderCacheBltRects(GCPtr, int, BoxPtr, int, int);
static void XAARenderImageWriteRects(GCPtr, int, BoxPtr, int, int);
static void XAARenderPixmapCopyRects(GCPtr, int, BoxPtr, int, int);
void
XAAPolyFillRect(DrawablePtr pDraw, GCPtr pGC, int nrectFill, /* number of rectangles to fill */
xRectangle *prectInit /* Pointer to first rectangle to fill */
)
{
2003-11-14 17:48:57 +01:00
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
int xorg = pDraw->x;
int yorg = pDraw->y;
int type = 0;
2003-11-14 17:48:57 +01:00
ClipAndRenderRectsFunc function;
if ((nrectFill <= 0) || !pGC->planemask)
2003-11-14 17:48:57 +01:00
return;
if (!RegionNumRects(pGC->pCompositeClip))
return;
2003-11-14 17:48:57 +01:00
switch (pGC->fillStyle) {
2003-11-14 17:48:57 +01:00
case FillSolid:
type = DO_SOLID;
break;
2003-11-14 17:48:57 +01:00
case FillStippled:
type = (*infoRec->StippledFillChooser) (pGC);
break;
2003-11-14 17:48:57 +01:00
case FillOpaqueStippled:
if ((pGC->fgPixel == pGC->bgPixel) && infoRec->FillSolidRects &&
CHECK_PLANEMASK(pGC, infoRec->FillSolidRectsFlags) &&
CHECK_ROP(pGC, infoRec->FillSolidRectsFlags) &&
CHECK_ROPSRC(pGC, infoRec->FillSolidRectsFlags) &&
CHECK_FG(pGC, infoRec->FillSolidRectsFlags))
type = DO_SOLID;
else
type = (*infoRec->OpaqueStippledFillChooser) (pGC);
break;
2003-11-14 17:48:57 +01:00
case FillTiled:
type = (*infoRec->TiledFillChooser) (pGC);
break;
2003-11-14 17:48:57 +01:00
}
switch (type) {
2003-11-14 17:48:57 +01:00
case DO_SOLID:
function = XAARenderSolidRects;
break;
2003-11-14 17:48:57 +01:00
case DO_COLOR_8x8:
function = XAARenderColor8x8Rects;
break;
2003-11-14 17:48:57 +01:00
case DO_MONO_8x8:
function = XAARenderMono8x8Rects;
break;
2003-11-14 17:48:57 +01:00
case DO_CACHE_BLT:
function = XAARenderCacheBltRects;
break;
2003-11-14 17:48:57 +01:00
case DO_COLOR_EXPAND:
function = XAARenderColorExpandRects;
break;
2003-11-14 17:48:57 +01:00
case DO_CACHE_EXPAND:
function = XAARenderCacheExpandRects;
break;
2003-11-14 17:48:57 +01:00
case DO_IMAGE_WRITE:
function = XAARenderImageWriteRects;
break;
2003-11-14 17:48:57 +01:00
case DO_PIXMAP_COPY:
function = XAARenderPixmapCopyRects;
break;
2003-11-14 17:48:57 +01:00
default:
(*XAAFallbackOps.PolyFillRect) (pDraw, pGC, nrectFill, prectInit);
return;
2003-11-14 17:48:57 +01:00
}
if (xorg | yorg) {
int n = nrectFill;
xRectangle *prect = prectInit;
2003-11-14 17:48:57 +01:00
while (n--) {
prect->x += xorg;
prect->y += yorg;
prect++;
}
2003-11-14 17:48:57 +01:00
}
XAAClipAndRenderRects(pGC, function, nrectFill, prectInit, xorg, yorg);
}
/*********************\
2003-11-14 17:48:57 +01:00
| Solid Rects |
\*********************/
static void
XAARenderSolidRects(GCPtr pGC,
int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
2003-11-14 17:48:57 +01:00
(*infoRec->FillSolidRects) (infoRec->pScrn,
pGC->fgPixel, pGC->alu, pGC->planemask, nboxes,
pClipBoxes);
}
2003-11-14 17:48:57 +01:00
/************************\
2003-11-14 17:48:57 +01:00
| Mono 8x8 Rects |
\************************/
static void
XAARenderMono8x8Rects(GCPtr pGC,
int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
XAAPixmapPtr pPriv;
int fg, bg;
switch (pGC->fillStyle) {
case FillStippled:
pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
fg = pGC->fgPixel;
bg = -1;
break;
case FillOpaqueStippled:
pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
fg = pGC->fgPixel;
bg = pGC->bgPixel;
break;
case FillTiled:
pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
fg = pPriv->fg;
bg = pPriv->bg;
break;
default: /* Muffle compiler */
pPriv = NULL; /* Kaboom */
fg = -1;
bg = -1;
break;
}
(*infoRec->FillMono8x8PatternRects) (infoRec->pScrn,
fg, bg, pGC->alu, pGC->planemask,
nboxes, pClipBoxes, pPriv->pattern0,
pPriv->pattern1,
(xorg + pGC->patOrg.x),
(yorg + pGC->patOrg.y));
2003-11-14 17:48:57 +01:00
}
/*************************\
2003-11-14 17:48:57 +01:00
| Color 8x8 Rects |
\*************************/
static void
XAARenderColor8x8Rects(GCPtr pGC,
int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
XAACacheInfoPtr pCache;
PixmapPtr pPix;
int fg, bg;
switch (pGC->fillStyle) {
case FillStippled:
pPix = pGC->stipple;
fg = pGC->fgPixel;
bg = -1;
break;
case FillOpaqueStippled:
pPix = pGC->stipple;
fg = pGC->fgPixel;
bg = pGC->bgPixel;
break;
case FillTiled:
pPix = pGC->tile.pixmap;
fg = -1;
bg = -1;
break;
default: /* Muffle compiler */
pPix = NULL;
fg = -1;
bg = -1;
break;
}
2003-11-14 17:48:57 +01:00
pCache = (*infoRec->CacheColor8x8Pattern) (infoRec->pScrn, pPix, fg, bg);
(*infoRec->FillColor8x8PatternRects) (infoRec->pScrn,
pGC->alu, pGC->planemask, nboxes,
pClipBoxes, (xorg + pGC->patOrg.x),
(yorg + pGC->patOrg.y), pCache);
}
2003-11-14 17:48:57 +01:00
/****************************\
2003-11-14 17:48:57 +01:00
| Color Expand Rects |
\****************************/
static void
XAARenderColorExpandRects(GCPtr pGC,
int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
int fg, bg;
2003-11-14 17:48:57 +01:00
switch (pGC->fillStyle) {
case FillStippled:
fg = pGC->fgPixel;
bg = -1;
break;
case FillOpaqueStippled:
fg = pGC->fgPixel;
bg = pGC->bgPixel;
break;
default: /* Muffle compiler */
fg = -1;
bg = -1;
break;
}
2003-11-14 17:48:57 +01:00
(*infoRec->FillColorExpandRects) (infoRec->pScrn, fg, bg,
pGC->alu, pGC->planemask, nboxes,
pClipBoxes, (xorg + pGC->patOrg.x),
(yorg + pGC->patOrg.y), pGC->stipple);
}
/*************************\
2003-11-14 17:48:57 +01:00
| Cache Blt Rects |
\*************************/
static void
XAARenderCacheBltRects(GCPtr pGC,
int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
XAACacheInfoPtr pCache;
switch (pGC->fillStyle) {
case FillStippled:
pCache = (*infoRec->CacheStipple) (infoRec->pScrn, pGC->stipple,
pGC->fgPixel, -1);
break;
case FillOpaqueStippled:
pCache = (*infoRec->CacheStipple) (infoRec->pScrn, pGC->stipple,
pGC->fgPixel, pGC->bgPixel);
break;
case FillTiled:
pCache = (*infoRec->CacheTile) (infoRec->pScrn, pGC->tile.pixmap);
break;
default: /* Muffle compiler */
pCache = NULL;
break;
}
2003-11-14 17:48:57 +01:00
(*infoRec->FillCacheBltRects) (infoRec->pScrn, pGC->alu,
pGC->planemask, nboxes, pClipBoxes,
(xorg + pGC->patOrg.x),
(yorg + pGC->patOrg.y), pCache);
}
2003-11-14 17:48:57 +01:00
/****************************\
2003-11-14 17:48:57 +01:00
| Cache Expand Rects |
\****************************/
static void
XAARenderCacheExpandRects(GCPtr pGC,
int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
int fg, bg;
2003-11-14 17:48:57 +01:00
switch (pGC->fillStyle) {
case FillStippled:
fg = pGC->fgPixel;
bg = -1;
break;
case FillOpaqueStippled:
fg = pGC->fgPixel;
bg = pGC->bgPixel;
break;
default: /* Muffle compiler */
fg = -1;
bg = -1;
break;
}
2003-11-14 17:48:57 +01:00
(*infoRec->FillCacheExpandRects) (infoRec->pScrn, fg, bg,
pGC->alu, pGC->planemask, nboxes,
pClipBoxes, (xorg + pGC->patOrg.x),
(yorg + pGC->patOrg.y), pGC->stipple);
}
2003-11-14 17:48:57 +01:00
/***************************\
2003-11-14 17:48:57 +01:00
| Image Write Rects |
\***************************/
static void
XAARenderImageWriteRects(GCPtr pGC,
int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
2003-11-14 17:48:57 +01:00
(*infoRec->FillImageWriteRects) (infoRec->pScrn, pGC->alu,
pGC->planemask, nboxes, pClipBoxes,
(xorg + pGC->patOrg.x),
(yorg + pGC->patOrg.y), pGC->tile.pixmap);
}
2003-11-14 17:48:57 +01:00
/***************************\
2003-11-14 17:48:57 +01:00
| Pixmap Copy Rects |
\***************************/
static void
XAARenderPixmapCopyRects(GCPtr pGC,
int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
XAACacheInfoPtr pCache = &(infoRec->ScratchCacheInfoRec);
XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
pCache->x = pPriv->offscreenArea->box.x1;
pCache->y = pPriv->offscreenArea->box.y1;
pCache->w = pCache->orig_w = pPriv->offscreenArea->box.x2 - pCache->x;
pCache->h = pCache->orig_h = pPriv->offscreenArea->box.y2 - pCache->y;
pCache->trans_color = -1;
(*infoRec->FillCacheBltRects) (infoRec->pScrn, pGC->alu,
pGC->planemask, nboxes, pClipBoxes,
(xorg + pGC->patOrg.x),
(yorg + pGC->patOrg.y), pCache);
2003-11-14 17:48:57 +01:00
}
/************\
2003-11-14 17:48:57 +01:00
| Solid |
\************/
void
XAAFillSolidRects(ScrnInfoPtr pScrn, int fg, int rop, unsigned int planemask, int nBox, /* number of rectangles to fill */
BoxPtr pBox /* Pointer to first rectangle to fill */
)
{
2003-11-14 17:48:57 +01:00
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
(*infoRec->SetupForSolidFill) (pScrn, fg, rop, planemask);
while (nBox--) {
(*infoRec->SubsequentSolidFillRect) (pScrn, pBox->x1, pBox->y1,
pBox->x2 - pBox->x1,
pBox->y2 - pBox->y1);
pBox++;
}
SET_SYNC_FLAG(infoRec);
2003-11-14 17:48:57 +01:00
}
/*********************\
2003-11-14 17:48:57 +01:00
| 8x8 Mono Patterns |
\*********************/
void
XAAFillMono8x8PatternRectsScreenOrigin(ScrnInfoPtr pScrn,
int fg, int bg, int rop,
unsigned int planemask,
int nBox,
BoxPtr pBox,
int pattern0, int pattern1,
int xorigin, int yorigin)
2003-11-14 17:48:57 +01:00
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
int patx = pattern0, paty = pattern1;
int xorg = (-xorigin) & 0x07;
int yorg = (-yorigin) & 0x07;
if (infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS) {
if (!(infoRec->Mono8x8PatternFillFlags &
HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
XAARotateMonoPattern(&patx, &paty, xorg, yorg,
(infoRec->Mono8x8PatternFillFlags &
BIT_ORDER_IN_BYTE_MSBFIRST));
xorg = patx;
yorg = paty;
}
}
else {
XAACacheInfoPtr pCache =
(*infoRec->CacheMono8x8Pattern) (pScrn, pattern0, pattern1);
patx = pCache->x;
paty = pCache->y;
if (!(infoRec->Mono8x8PatternFillFlags &
HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
int slot = (yorg << 3) + xorg;
patx += pCache->offsets[slot].x;
paty += pCache->offsets[slot].y;
xorg = patx;
yorg = paty;
2003-11-14 17:48:57 +01:00
}
}
(*infoRec->SetupForMono8x8PatternFill) (pScrn, patx, paty,
fg, bg, rop, planemask);
2003-11-14 17:48:57 +01:00
while (nBox--) {
(*infoRec->SubsequentMono8x8PatternFillRect) (pScrn,
xorg, yorg, pBox->x1,
pBox->y1,
pBox->x2 - pBox->x1,
pBox->y2 - pBox->y1);
pBox++;
}
SET_SYNC_FLAG(infoRec);
2003-11-14 17:48:57 +01:00
}
void
XAAFillMono8x8PatternRects(ScrnInfoPtr pScrn,
int fg, int bg, int rop,
unsigned int planemask,
int nBox,
BoxPtr pBox,
int pattern0, int pattern1, int xorigin, int yorigin)
2003-11-14 17:48:57 +01:00
{
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
int patx = pattern0, paty = pattern1;
int xorg, yorg;
XAACacheInfoPtr pCache = NULL;
if (!(infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS)) {
pCache = (*infoRec->CacheMono8x8Pattern) (pScrn, pattern0, pattern1);
patx = pCache->x;
paty = pCache->y;
2003-11-14 17:48:57 +01:00
}
(*infoRec->SetupForMono8x8PatternFill) (pScrn, patx, paty,
fg, bg, rop, planemask);
while (nBox--) {
xorg = (pBox->x1 - xorigin) & 0x07;
yorg = (pBox->y1 - yorigin) & 0x07;
if (!(infoRec->Mono8x8PatternFillFlags &
HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
if (infoRec->Mono8x8PatternFillFlags &
HARDWARE_PATTERN_PROGRAMMED_BITS) {
patx = pattern0;
paty = pattern1;
XAARotateMonoPattern(&patx, &paty, xorg, yorg,
(infoRec->Mono8x8PatternFillFlags &
BIT_ORDER_IN_BYTE_MSBFIRST));
xorg = patx;
yorg = paty;
}
else {
int slot = (yorg << 3) + xorg;
2003-11-14 17:48:57 +01:00
xorg = patx + pCache->offsets[slot].x;
yorg = paty + pCache->offsets[slot].y;
}
2003-11-14 17:48:57 +01:00
}
(*infoRec->SubsequentMono8x8PatternFillRect) (pScrn,
xorg, yorg, pBox->x1,
pBox->y1,
pBox->x2 - pBox->x1,
pBox->y2 - pBox->y1);
pBox++;
}
2003-11-14 17:48:57 +01:00
SET_SYNC_FLAG(infoRec);
2003-11-14 17:48:57 +01:00
}
/**********************\
2003-11-14 17:48:57 +01:00
| 8x8 Color Patterns |
\**********************/
void
XAAFillColor8x8PatternRectsScreenOrigin(ScrnInfoPtr pScrn,
int rop,
unsigned int planemask,
int nBox,
BoxPtr pBox,
int xorigin, int yorigin,
XAACacheInfoPtr pCache)
{
2003-11-14 17:48:57 +01:00
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
int patx = pCache->x, paty = pCache->y;
int xorg = (-xorigin) & 0x07;
int yorg = (-yorigin) & 0x07;
if (!(infoRec->Color8x8PatternFillFlags &
HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
int slot = (yorg << 3) + xorg;
paty += pCache->offsets[slot].y;
patx += pCache->offsets[slot].x;
xorg = patx;
yorg = paty;
}
(*infoRec->SetupForColor8x8PatternFill) (pScrn, patx, paty,
rop, planemask,
pCache->trans_color);
while (nBox--) {
(*infoRec->SubsequentColor8x8PatternFillRect) (pScrn,
xorg, yorg, pBox->x1,
pBox->y1,
pBox->x2 - pBox->x1,
pBox->y2 - pBox->y1);
pBox++;
2003-11-14 17:48:57 +01:00
}
SET_SYNC_FLAG(infoRec);
}
void
XAAFillColor8x8PatternRects(ScrnInfoPtr pScrn,
int rop,
unsigned int planemask,
int nBox,
BoxPtr pBox,
int xorigin, int yorigin, XAACacheInfoPtr pCache)
{
2003-11-14 17:48:57 +01:00
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
int xorg, yorg;
(*infoRec->SetupForColor8x8PatternFill) (pScrn, pCache->x, pCache->y,
rop, planemask,
pCache->trans_color);
while (nBox--) {
xorg = (pBox->x1 - xorigin) & 0x07;
yorg = (pBox->y1 - yorigin) & 0x07;
2003-11-14 17:48:57 +01:00
if (!(infoRec->Color8x8PatternFillFlags &
HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
int slot = (yorg << 3) + xorg;
2003-11-14 17:48:57 +01:00
yorg = pCache->y + pCache->offsets[slot].y;
xorg = pCache->x + pCache->offsets[slot].x;
2003-11-14 17:48:57 +01:00
}
(*infoRec->SubsequentColor8x8PatternFillRect) (pScrn,
xorg, yorg, pBox->x1,
pBox->y1,
pBox->x2 - pBox->x1,
pBox->y2 - pBox->y1);
pBox++;
}
2003-11-14 17:48:57 +01:00
SET_SYNC_FLAG(infoRec);
2003-11-14 17:48:57 +01:00
}
/***************\
2003-11-14 17:48:57 +01:00
| Cache Blits |
\***************/
void
XAAFillCacheBltRects(ScrnInfoPtr pScrn,
int rop,
unsigned int planemask,
int nBox,
BoxPtr pBox, int xorg, int yorg, XAACacheInfoPtr pCache)
{
2003-11-14 17:48:57 +01:00
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
int x, y, phaseY, phaseX, skipleft, height, width, w, blit_w, blit_h;
(*infoRec->SetupForScreenToScreenCopy) (pScrn, 1, 1, rop, planemask,
pCache->trans_color);
while (nBox--) {
y = pBox->y1;
phaseY = (y - yorg) % pCache->orig_h;
if (phaseY < 0)
phaseY += pCache->orig_h;
phaseX = (pBox->x1 - xorg) % pCache->orig_w;
if (phaseX < 0)
phaseX += pCache->orig_w;
height = pBox->y2 - y;
width = pBox->x2 - pBox->x1;
2003-11-14 17:48:57 +01:00
#if 0
if (rop == GXcopy) {
while (1) {
w = width;
skipleft = phaseX;
x = pBox->x1;
blit_h = pCache->h - phaseY;
if (blit_h > height)
blit_h = height;
while (1) {
blit_w = pCache->w - skipleft;
if (blit_w > w)
blit_w = w;
(*infoRec->SubsequentScreenToScreenCopy) (pScrn,
pCache->x +
skipleft,
pCache->y +
phaseY, x, y,
blit_w, blit_h);
w -= blit_w;
if (!w)
break;
x += blit_w;
skipleft = (skipleft + blit_w) % pCache->orig_w;
if (blit_w >= pCache->orig_w)
break;
}
/* Expand horizontally */
if (w) {
skipleft -= phaseX;
if (skipleft < 0)
skipleft += pCache->orig_w;
blit_w = x - pBox->x1 - skipleft;
while (w) {
if (blit_w > w)
blit_w = w;
(*infoRec->SubsequentScreenToScreenCopy) (pScrn,
pBox->x1 +
skipleft, y,
x, y, blit_w,
blit_h);
w -= blit_w;
x += blit_w;
blit_w <<= 1;
}
}
height -= blit_h;
if (!height)
break;
y += blit_h;
phaseY = (phaseY + blit_h) % pCache->orig_h;
if (blit_h >= pCache->orig_h)
break;
}
/* Expand vertically */
if (height) {
blit_w = pBox->x2 - pBox->x1;
phaseY -= (pBox->y1 - yorg) % pCache->orig_h;
if (phaseY < 0)
phaseY += pCache->orig_h;
blit_h = y - pBox->y1 - phaseY;
while (height) {
if (blit_h > height)
blit_h = height;
(*infoRec->SubsequentScreenToScreenCopy) (pScrn, pBox->x1,
pBox->y1 + phaseY,
pBox->x1, y,
blit_w, blit_h);
height -= blit_h;
y += blit_h;
blit_h <<= 1;
}
}
}
else
2003-11-14 17:48:57 +01:00
#endif
{
while (1) {
w = width;
skipleft = phaseX;
x = pBox->x1;
blit_h = pCache->h - phaseY;
if (blit_h > height)
blit_h = height;
while (1) {
blit_w = pCache->w - skipleft;
if (blit_w > w)
blit_w = w;
(*infoRec->SubsequentScreenToScreenCopy) (pScrn,
pCache->x +
skipleft,
pCache->y +
phaseY, x, y,
blit_w, blit_h);
w -= blit_w;
if (!w)
break;
x += blit_w;
skipleft = (skipleft + blit_w) % pCache->orig_w;
}
height -= blit_h;
if (!height)
break;
y += blit_h;
phaseY = (phaseY + blit_h) % pCache->orig_h;
}
}
pBox++;
2003-11-14 17:48:57 +01:00
}
2003-11-14 17:48:57 +01:00
SET_SYNC_FLAG(infoRec);
}
/*******************\
2003-11-14 17:48:57 +01:00
| Cache Expansion |
\*******************/
void
XAAFillCacheExpandRects(ScrnInfoPtr pScrn,
int fg, int bg, int rop,
unsigned int planemask,
int nBox,
BoxPtr pBox, int xorg, int yorg, PixmapPtr pPix)
{
2003-11-14 17:48:57 +01:00
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
int x, y, phaseY, phaseX, skipleft, height, width, w, blit_w, blit_h;
int cacheWidth;
XAACacheInfoPtr pCache;
pCache = (*infoRec->CacheMonoStipple) (pScrn, pPix);
cacheWidth = (pCache->w * pScrn->bitsPerPixel) /
infoRec->CacheColorExpandDensity;
(*infoRec->SetupForScreenToScreenColorExpandFill) (pScrn, fg, bg, rop,
planemask);
while (nBox--) {
y = pBox->y1;
phaseY = (y - yorg) % pCache->orig_h;
if (phaseY < 0)
phaseY += pCache->orig_h;
phaseX = (pBox->x1 - xorg) % pCache->orig_w;
if (phaseX < 0)
phaseX += pCache->orig_w;
height = pBox->y2 - y;
width = pBox->x2 - pBox->x1;
while (1) {
w = width;
skipleft = phaseX;
x = pBox->x1;
blit_h = pCache->h - phaseY;
if (blit_h > height)
blit_h = height;
while (1) {
blit_w = cacheWidth - skipleft;
if (blit_w > w)
blit_w = w;
(*infoRec->SubsequentScreenToScreenColorExpandFill) (pScrn, x,
y, blit_w,
blit_h,
pCache->x,
pCache->y +
phaseY,
skipleft);
w -= blit_w;
if (!w)
break;
x += blit_w;
skipleft = (skipleft + blit_w) % pCache->orig_w;
}
height -= blit_h;
if (!height)
break;
y += blit_h;
phaseY = (phaseY + blit_h) % pCache->orig_h;
}
pBox++;
2003-11-14 17:48:57 +01:00
}
2003-11-14 17:48:57 +01:00
SET_SYNC_FLAG(infoRec);
}
/******************\
2003-11-14 17:48:57 +01:00
| Image Writes |
\******************/
/* This requires all LEFT_EDGE clipping. You get too many problems
with reading past the edge of the pattern otherwise */
static void
WriteColumn(ScrnInfoPtr pScrn,
unsigned char *pSrc,
int x, int y, int w, int h,
int xoff, int yoff, int pHeight, int srcwidth, int Bpp)
{
2003-11-14 17:48:57 +01:00
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
unsigned char *src;
Bool PlusOne = FALSE;
int skipleft, dwords;
pSrc += (Bpp * xoff);
if ((skipleft = (long) pSrc & 0x03L)) {
if (Bpp == 3)
skipleft = 4 - skipleft;
2003-11-14 17:48:57 +01:00
else
skipleft /= Bpp;
2003-11-14 17:48:57 +01:00
x -= skipleft;
2003-11-14 17:48:57 +01:00
w += skipleft;
if (Bpp == 3)
pSrc -= 3 * skipleft;
else /* is this Alpha friendly ? */
pSrc = (unsigned char *) ((long) pSrc & ~0x03L);
2003-11-14 17:48:57 +01:00
}
src = pSrc + (yoff * srcwidth);
dwords = bytes_to_int32(w * Bpp);
2003-11-14 17:48:57 +01:00
if ((infoRec->ImageWriteFlags & CPU_TRANSFER_PAD_QWORD) &&
((dwords * h) & 0x01)) {
2003-11-14 17:48:57 +01:00
PlusOne = TRUE;
}
2003-11-14 17:48:57 +01:00
(*infoRec->SubsequentImageWriteRect) (pScrn, x, y, w, h, skipleft);
2003-11-14 17:48:57 +01:00
if (dwords > infoRec->ImageWriteRange) {
while (h--) {
XAAMoveDWORDS_FixedBase((CARD32 *) infoRec->ImageWriteBase,
(CARD32 *) src, dwords);
2003-11-14 17:48:57 +01:00
src += srcwidth;
yoff++;
if (yoff >= pHeight) {
yoff = 0;
src = pSrc;
}
2003-11-14 17:48:57 +01:00
}
}
else {
if (srcwidth == (dwords << 2)) {
int maxLines = infoRec->ImageWriteRange / dwords;
int step;
2003-11-14 17:48:57 +01:00
while (h) {
step = pHeight - yoff;
if (step > maxLines)
step = maxLines;
if (step > h)
step = h;
2003-11-14 17:48:57 +01:00
XAAMoveDWORDS((CARD32 *) infoRec->ImageWriteBase,
(CARD32 *) src, dwords * step);
2003-11-14 17:48:57 +01:00
src += (srcwidth * step);
yoff += step;
if (yoff >= pHeight) {
yoff = 0;
src = pSrc;
}
h -= step;
}
}
else {
while (h--) {
XAAMoveDWORDS((CARD32 *) infoRec->ImageWriteBase,
(CARD32 *) src, dwords);
2003-11-14 17:48:57 +01:00
src += srcwidth;
yoff++;
if (yoff >= pHeight) {
yoff = 0;
src = pSrc;
}
2003-11-14 17:48:57 +01:00
}
}
}
if (PlusOne) {
CARD32 *base = (CARD32 *) infoRec->ImageWriteBase;
2003-11-14 17:48:57 +01:00
*base = 0x00000000;
}
}
void
XAAFillImageWriteRects(ScrnInfoPtr pScrn,
int rop,
unsigned int planemask,
int nBox,
BoxPtr pBox, int xorg, int yorg, PixmapPtr pPix)
{
2003-11-14 17:48:57 +01:00
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
int x, phaseY, phaseX, height, width, blit_w;
int pHeight = pPix->drawable.height;
int pWidth = pPix->drawable.width;
int Bpp = pPix->drawable.bitsPerPixel >> 3;
int srcwidth = pPix->devKind;
(*infoRec->SetupForImageWrite) (pScrn, rop, planemask, -1,
pPix->drawable.bitsPerPixel,
pPix->drawable.depth);
while (nBox--) {
x = pBox->x1;
phaseY = (pBox->y1 - yorg) % pHeight;
if (phaseY < 0)
phaseY += pHeight;
phaseX = (x - xorg) % pWidth;
if (phaseX < 0)
phaseX += pWidth;
height = pBox->y2 - pBox->y1;
width = pBox->x2 - x;
while (1) {
blit_w = pWidth - phaseX;
if (blit_w > width)
blit_w = width;
WriteColumn(pScrn, pPix->devPrivate.ptr, x, pBox->y1,
blit_w, height, phaseX, phaseY, pHeight, srcwidth, Bpp);
width -= blit_w;
if (!width)
break;
x += blit_w;
phaseX = (phaseX + blit_w) % pWidth;
}
pBox++;
2003-11-14 17:48:57 +01:00
}
if (infoRec->ImageWriteFlags & SYNC_AFTER_IMAGE_WRITE)
(*infoRec->Sync) (pScrn);
else
SET_SYNC_FLAG(infoRec);
2003-11-14 17:48:57 +01:00
}
/*************\
2003-11-14 17:48:57 +01:00
| Utilities |
\*************/
void
XAAClipAndRenderRects(GCPtr pGC,
ClipAndRenderRectsFunc BoxFunc,
int nrectFill, xRectangle *prect, int xorg, int yorg)
{
2003-11-14 17:48:57 +01:00
XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
int Right, Bottom, MaxBoxes;
BoxPtr pextent, pboxClipped, pboxClippedBase;
2003-11-14 17:48:57 +01:00
MaxBoxes = infoRec->PreAllocSize / sizeof(BoxRec);
pboxClippedBase = (BoxPtr) infoRec->PreAllocMem;
2003-11-14 17:48:57 +01:00
pboxClipped = pboxClippedBase;
if (RegionNumRects(pGC->pCompositeClip) == 1) {
pextent = RegionRects(pGC->pCompositeClip);
while (nrectFill--) {
pboxClipped->x1 = max(pextent->x1, prect->x);
pboxClipped->y1 = max(pextent->y1, prect->y);
Right = (int) prect->x + (int) prect->width;
pboxClipped->x2 = min(pextent->x2, Right);
Bottom = (int) prect->y + (int) prect->height;
pboxClipped->y2 = min(pextent->y2, Bottom);
prect++;
if ((pboxClipped->x1 < pboxClipped->x2) &&
(pboxClipped->y1 < pboxClipped->y2)) {
pboxClipped++;
if (pboxClipped >= (pboxClippedBase + MaxBoxes)) {
(*BoxFunc) (pGC, MaxBoxes, pboxClippedBase, xorg, yorg);
pboxClipped = pboxClippedBase;
}
}
}
}
else {
pextent = RegionExtents(pGC->pCompositeClip);
while (nrectFill--) {
int n;
BoxRec box, *pbox;
box.x1 = max(pextent->x1, prect->x);
box.y1 = max(pextent->y1, prect->y);
Right = (int) prect->x + (int) prect->width;
box.x2 = min(pextent->x2, Right);
Bottom = (int) prect->y + (int) prect->height;
box.y2 = min(pextent->y2, Bottom);
prect++;
if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
continue;
n = RegionNumRects(pGC->pCompositeClip);
pbox = RegionRects(pGC->pCompositeClip);
/* clip the rectangle to each box in the clip region
this is logically equivalent to calling Intersect()
*/
while (n--) {
pboxClipped->x1 = max(box.x1, pbox->x1);
pboxClipped->y1 = max(box.y1, pbox->y1);
pboxClipped->x2 = min(box.x2, pbox->x2);
pboxClipped->y2 = min(box.y2, pbox->y2);
pbox++;
/* see if clipping left anything */
if (pboxClipped->x1 < pboxClipped->x2 &&
pboxClipped->y1 < pboxClipped->y2) {
pboxClipped++;
if (pboxClipped >= (pboxClippedBase + MaxBoxes)) {
(*BoxFunc) (pGC, MaxBoxes, pboxClippedBase, xorg, yorg);
pboxClipped = pboxClippedBase;
}
}
}
}
2003-11-14 17:48:57 +01:00
}
if (pboxClipped != pboxClippedBase)
(*BoxFunc) (pGC, pboxClipped - pboxClippedBase, pboxClippedBase,
xorg, yorg);
2003-11-14 17:48:57 +01:00
}
int
XAAGetRectClipBoxes(GCPtr pGC,
BoxPtr pboxClippedBase,
int nrectFill, xRectangle *prectInit)
{
int Right, Bottom;
BoxPtr pextent, pboxClipped = pboxClippedBase;
xRectangle *prect = prectInit;
RegionPtr prgnClip = pGC->pCompositeClip;
2003-11-14 17:48:57 +01:00
if (RegionNumRects(prgnClip) == 1) {
pextent = RegionRects(prgnClip);
while (nrectFill--) {
pboxClipped->x1 = max(pextent->x1, prect->x);
pboxClipped->y1 = max(pextent->y1, prect->y);
Right = (int) prect->x + (int) prect->width;
pboxClipped->x2 = min(pextent->x2, Right);
Bottom = (int) prect->y + (int) prect->height;
pboxClipped->y2 = min(pextent->y2, Bottom);
prect++;
if ((pboxClipped->x1 < pboxClipped->x2) &&
(pboxClipped->y1 < pboxClipped->y2)) {
pboxClipped++;
}
}
}
else {
pextent = RegionExtents(prgnClip);
while (nrectFill--) {
int n;
BoxRec box, *pbox;
box.x1 = max(pextent->x1, prect->x);
box.y1 = max(pextent->y1, prect->y);
Right = (int) prect->x + (int) prect->width;
box.x2 = min(pextent->x2, Right);
Bottom = (int) prect->y + (int) prect->height;
box.y2 = min(pextent->y2, Bottom);
prect++;
if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
continue;
n = RegionNumRects(prgnClip);
pbox = RegionRects(prgnClip);
/* clip the rectangle to each box in the clip region
this is logically equivalent to calling Intersect()
*/
while (n--) {
pboxClipped->x1 = max(box.x1, pbox->x1);
pboxClipped->y1 = max(box.y1, pbox->y1);
pboxClipped->x2 = min(box.x2, pbox->x2);
pboxClipped->y2 = min(box.y2, pbox->y2);
pbox++;
/* see if clipping left anything */
if (pboxClipped->x1 < pboxClipped->x2 &&
pboxClipped->y1 < pboxClipped->y2) {
pboxClipped++;
}
}
}
2003-11-14 17:48:57 +01:00
}
return pboxClipped - pboxClippedBase;
2003-11-14 17:48:57 +01:00
}