#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <X11/X.h>
#include <X11/Xmd.h>
#include "servermd.h"
#ifndef PixelType
#define PixelType CARD32
#endif
#ifndef MfbBits
#define MfbBits CARD32
#endif
#define MFB_PGSZB 4
#define MFB_PPW (MFB_PGSZB<<3)
#define MFB_PGSZ MFB_PPW
#define MFB_PLST (MFB_PPW-1)
#define MFB_PIM MFB_PLST
#if MFB_PPW == 32
#define MFB_PWSH 5
#endif
extern PixelType starttab[];
extern PixelType endtab[];
extern PixelType partmasks[MFB_PPW][MFB_PPW];
extern PixelType rmask[];
extern PixelType mask[];
extern PixelType mfbGetstarttab(int);
extern PixelType mfbGetendtab(int);
extern PixelType mfbGetpartmasks(int, int);
extern PixelType mfbGetrmask(int);
extern PixelType mfbGetmask(int);
#ifndef MFB_CONSTS_ONLY
#define PGSZB MFB_PGSZB
#define PPW MFB_PPW
#define PGSZ MFB_PGSZ
#define PLST MFB_PLST
#define PIM MFB_PIM
#define PWSH MFB_PWSH
#define BitLeft(b,s) SCRLEFT(b,s)
#define BitRight(b,s) SCRRIGHT(b,s)
#if 1
#define LONG2CHARSSAMEORDER(x) ((MfbBits)(x))
#define LONG2CHARSDIFFORDER( x ) ( ( ( ( x ) & (MfbBits)0x000000FF ) << 0x18 ) \
| ( ( ( x ) & (MfbBits)0x0000FF00 ) << 0x08 ) \
| ( ( ( x ) & (MfbBits)0x00FF0000 ) >> 0x08 ) \
| ( ( ( x ) & (MfbBits)0xFF000000 ) >> 0x18 ) )
#endif
#if (BITMAP_BIT_ORDER == IMAGE_BYTE_ORDER)
#define LONG2CHARS(x) ((MfbBits)(x))
#else
#define LONG2CHARS( x ) ( ( ( ( x ) & (MfbBits)0x000000FF ) << 0x18 ) \
| ( ( ( x ) & (MfbBits)0x0000FF00 ) << 0x08 ) \
| ( ( ( x ) & (MfbBits)0x00FF0000 ) >> 0x08 ) \
| ( ( ( x ) & (MfbBits)0xFF000000 ) >> 0x18 ) )
#endif
#ifdef STRICT_ANSI_SHIFT
#define SHL(x,y) ((y) >= PPW ? 0 : LONG2CHARS(LONG2CHARS(x) << (y)))
#define SHR(x,y) ((y) >= PPW ? 0 : LONG2CHARS(LONG2CHARS(x) >> (y)))
#else
#define SHL(x,y) LONG2CHARS(LONG2CHARS(x) << (y))
#define SHR(x,y) LONG2CHARS(LONG2CHARS(x) >> (y))
#endif
#if (BITMAP_BIT_ORDER == MSBFirst)
#define SCRLEFT(lw, n) SHL((PixelType)(lw),(n))
#define SCRRIGHT(lw, n) SHR((PixelType)(lw),(n))
#else
#define SCRLEFT(lw, n) SHR((PixelType)(lw),(n))
#define SCRRIGHT(lw, n) SHL((PixelType)(lw),(n))
#endif
#define DoRRop(alu, src, dst) \
(((alu) == RROP_BLACK) ? ((dst) & ~(src)) : \
((alu) == RROP_WHITE) ? ((dst) | (src)) : \
((alu) == RROP_INVERT) ? ((dst) ^ (src)) : \
(dst))
#define Duff(counter, block) { \
while (counter >= 4) {\
{ block; } \
{ block; } \
{ block; } \
{ block; } \
counter -= 4; \
} \
switch (counter & 3) { \
case 3: { block; } \
case 2: { block; } \
case 1: { block; } \
case 0: \
counter = 0; \
} \
}
#define maskbits(x, w, startmask, endmask, nlw) \
startmask = mfbGetstarttab((x) & PIM); \
endmask = mfbGetendtab(((x)+(w)) & PIM); \
if (startmask) \
nlw = (((w) - (PPW - ((x) & PIM))) >> PWSH); \
else \
nlw = (w) >> PWSH;
#define maskpartialbits(x, w, mask) \
mask = mfbGetpartmasks((x) & PIM, (w) & PIM);
#define maskPPWbits(x, w, startmask, endmask) \
startmask = mfbGetstarttab((x) & PIM); \
endmask = mfbGetendtab(((x)+(w)) & PIM);
#ifdef __GNUC__
#ifdef vax
#define FASTGETBITS(psrc,x,w,dst) \
__asm ("extzv %1,%2,%3,%0" \
: "=g" (dst) \
: "g" (x), "g" (w), "m" (*(char *)(psrc)))
#define getbits(psrc,x,w,dst) FASTGETBITS(psrc,x,w,dst)
#define FASTPUTBITS(src, x, w, pdst) \
__asm ("insv %3,%1,%2,%0" \
: "=m" (*(char *)(pdst)) \
: "g" (x), "g" (w), "g" (src))
#define putbits(src, x, w, pdst) FASTPUTBITS(src, x, w, pdst)
#endif
#ifdef mc68020
#define FASTGETBITS(psrc, x, w, dst) \
__asm ("bfextu %3{%1:%2},%0" \
: "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
#define getbits(psrc,x,w,dst) \
{ \
FASTGETBITS(psrc, x, w, dst);\
dst = SHL(dst,(32-(w))); \
}
#define FASTPUTBITS(src, x, w, pdst) \
__asm ("bfins %3,%0{%1:%2}" \
: "=o" (*(char *)(pdst)) \
: "di" (x), "di" (w), "d" (src), "0" (*(char *) (pdst)))
#define putbits(src, x, w, pdst) FASTPUTBITS(SHR((src),32-(w)), x, w, pdst)
#endif
#endif
#if !defined(mc68020) || !defined(sun)
#define NO_3_60_CG4
#endif
#define slo_putbits(src, x, w, pdst) \
{ \
register int n = (x)+(w)-PPW; \
\
if (n <= 0) \
{ \
register PixelType tmpmask; \
maskpartialbits((x), (w), tmpmask); \
*(pdst) = (*(pdst) & ~tmpmask) | \
(SCRRIGHT(src, x) & tmpmask); \
} \
else \
{ \
register int d = PPW-(x); \
*(pdst) = (*(pdst) & mfbGetendtab(x)) | (SCRRIGHT((src), x)); \
(pdst)[1] = ((pdst)[1] & mfbGetstarttab(n)) | \
(SCRLEFT(src, d) & mfbGetendtab(n)); \
} \
}
#if defined(putbits) && !defined(NO_3_60_CG4)
#define u_putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
#else
#define u_putbits(src, x, w, pdst) putbits(src, x, w, pdst)
#endif
#if !defined(putbits)
#define putbits(src, x, w, pdst) slo_putbits(src, x, w, pdst)
#endif
#ifndef getbits
#define getbits(psrc, x, w, dst) \
{ \
dst = SCRLEFT(*(psrc), (x)); \
if ( ((x) + (w)) > PPW) \
dst |= (SCRRIGHT(*((psrc)+1), PPW-(x))); \
}
#endif
#define u_putbitsrop(src, x, w, pdst, rop) \
{\
register PixelType t1, t2; \
register int n = (x)+(w)-PPW; \
\
t1 = SCRRIGHT((src), (x)); \
DoRop(t2, rop, t1, *(pdst)); \
\
if (n <= 0) \
{ \
register PixelType tmpmask; \
\
maskpartialbits((x), (w), tmpmask); \
*(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
} \
else \
{ \
int m = PPW-(x); \
*(pdst) = (*(pdst) & mfbGetendtab(x)) | (t2 & mfbGetstarttab(x)); \
t1 = SCRLEFT((src), m); \
DoRop(t2, rop, t1, (pdst)[1]); \
(pdst)[1] = ((pdst)[1] & mfbGetstarttab(n)) | (t2 & mfbGetendtab(n)); \
} \
}
#if defined(FASTPUTBITS) && defined(FASTGETBITS) && defined(NO_3_60_CG4)
#if (BITMAP_BIT_ORDER == MSBFirst)
#define putbitsrop(src, x, w, pdst, rop) \
{ \
register PixelType _tmp, _tmp2; \
FASTGETBITS(pdst, x, w, _tmp); \
_tmp2 = SCRRIGHT(src, PPW-(w)); \
DoRop(_tmp, rop, _tmp2, _tmp) \
FASTPUTBITS(_tmp, x, w, pdst); \
}
#define putbitsrrop(src, x, w, pdst, rop) \
{ \
register PixelType _tmp, _tmp2; \
\
FASTGETBITS(pdst, x, w, _tmp); \
_tmp2 = SCRRIGHT(src, PPW-(w)); \
_tmp= DoRRop(rop, _tmp2, _tmp); \
FASTPUTBITS(_tmp, x, w, pdst); \
}
#undef u_putbitsrop
#else
#define putbitsrop(src, x, w, pdst, rop) \
{ \
register PixelType _tmp; \
FASTGETBITS(pdst, x, w, _tmp); \
DoRop(_tmp, rop, src, _tmp) \
FASTPUTBITS(_tmp, x, w, pdst); \
}
#define putbitsrrop(src, x, w, pdst, rop) \
{ \
register PixelType _tmp; \
\
FASTGETBITS(pdst, x, w, _tmp); \
_tmp= DoRRop(rop, src, _tmp); \
FASTPUTBITS(_tmp, x, w, pdst); \
}
#undef u_putbitsrop
#endif
#endif
#ifndef putbitsrop
#define putbitsrop(src, x, w, pdst, rop) u_putbitsrop(src, x, w, pdst, rop)
#endif
#ifndef putbitsrrop
#define putbitsrrop(src, x, w, pdst, rop) \
{\
register PixelType t1, t2; \
register int n = (x)+(w)-PPW; \
\
t1 = SCRRIGHT((src), (x)); \
t2 = DoRRop(rop, t1, *(pdst)); \
\
if (n <= 0) \
{ \
register PixelType tmpmask; \
\
maskpartialbits((x), (w), tmpmask); \
*(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
} \
else \
{ \
int m = PPW-(x); \
*(pdst) = (*(pdst) & mfbGetendtab(x)) | (t2 & mfbGetstarttab(x)); \
t1 = SCRLEFT((src), m); \
t2 = DoRRop(rop, t1, (pdst)[1]); \
(pdst)[1] = ((pdst)[1] & mfbGetstarttab(n)) | (t2 & mfbGetendtab(n)); \
} \
}
#endif
#if GETLEFTBITS_ALIGNMENT == 1
#define getleftbits(psrc, w, dst) dst = *((CARD32 *)(pointer) psrc)
#endif
#if GETLEFTBITS_ALIGNMENT == 2
#define getleftbits(psrc, w, dst) \
{ \
if ( ((int)(psrc)) & 0x01 ) \
getbits( ((CARD32 *)(((char *)(psrc))-1)), 8, (w), (dst) ); \
else \
getbits(psrc, 0, w, dst); \
}
#endif
#if GETLEFTBITS_ALIGNMENT == 4
#define getleftbits(psrc, w, dst) \
{ \
int off, off_b; \
off_b = (off = ( ((int)(psrc)) & 0x03)) << 3; \
getbits( \
(CARD32 *)( ((char *)(psrc)) - off), \
(off_b), (w), (dst) \
); \
}
#endif
#define getshiftedleftbits(psrc, offset, w, dst) \
getleftbits((psrc), (w), (dst)); \
dst = SCRLEFT((dst), (offset));
#if defined(FASTGETBITS) && defined(FASTPUTBITS)
#ifdef NO_3_60_CG4
#define u_FASTPUT(aa, bb, cc, dd) FASTPUTBITS(aa, bb, cc, dd)
#else
#define u_FASTPUT(aa, bb, cc, dd) u_putbits(SCRLEFT(aa, PPW-(cc)), bb, cc, dd)
#endif
#define getandputbits(psrc, srcbit, dstbit, width, pdst) \
{ \
register PixelType _tmpbits; \
FASTGETBITS(psrc, srcbit, width, _tmpbits); \
u_FASTPUT(_tmpbits, dstbit, width, pdst); \
}
#define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
{ \
register PixelType _tmpsrc, _tmpdst; \
FASTGETBITS(pdst, dstbit, width, _tmpdst); \
FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
DoRop(_tmpdst, rop, _tmpsrc, _tmpdst); \
u_FASTPUT(_tmpdst, dstbit, width, pdst); \
}
#define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
{ \
register PixelType _tmpsrc, _tmpdst; \
FASTGETBITS(pdst, dstbit, width, _tmpdst); \
FASTGETBITS(psrc, srcbit, width, _tmpsrc); \
_tmpdst = DoRRop(rop, _tmpsrc, _tmpdst); \
u_FASTPUT(_tmpdst, dstbit, width, pdst); \
}
#define getandputbits0(psrc, srcbit, width, pdst) \
getandputbits(psrc, srcbit, 0, width, pdst)
#define getandputrop0(psrc, srcbit, width, pdst, rop) \
getandputrop(psrc, srcbit, 0, width, pdst, rop)
#define getandputrrop0(psrc, srcbit, width, pdst, rop) \
getandputrrop(psrc, srcbit, 0, width, pdst, rop)
#else
#define getandputbits(psrc, srcbit, dstbit, width, pdst) \
{ \
register PixelType _tmpbits; \
getbits(psrc, srcbit, width, _tmpbits); \
putbits(_tmpbits, dstbit, width, pdst); \
}
#define getandputrop(psrc, srcbit, dstbit, width, pdst, rop) \
{ \
register PixelType _tmpbits; \
getbits(psrc, srcbit, width, _tmpbits) \
putbitsrop(_tmpbits, dstbit, width, pdst, rop) \
}
#define getandputrrop(psrc, srcbit, dstbit, width, pdst, rop) \
{ \
register PixelType _tmpbits; \
getbits(psrc, srcbit, width, _tmpbits) \
putbitsrrop(_tmpbits, dstbit, width, pdst, rop) \
}
#define getandputbits0(psrc, sbindex, width, pdst) \
{ \
register int _flag = PPW - (sbindex); \
register PixelType _src; \
\
_src = SCRLEFT (*(psrc), (sbindex)); \
if ((width) > _flag) \
_src |= SCRRIGHT (*((psrc) + 1), _flag); \
\
*(pdst) = (*(pdst) & mfbGetstarttab((width))) | (_src & mfbGetendtab((width))); \
}
#define getandputrop0(psrc, sbindex, width, pdst, rop) \
{ \
register int _flag = PPW - (sbindex); \
register PixelType _src; \
\
_src = SCRLEFT (*(psrc), (sbindex)); \
if ((width) > _flag) \
_src |= SCRRIGHT (*((psrc) + 1), _flag); \
DoRop(_src, rop, _src, *(pdst)); \
\
*(pdst) = (*(pdst) & mfbGetstarttab((width))) | (_src & mfbGetendtab((width))); \
}
#define getandputrrop0(psrc, sbindex, width, pdst, rop) \
{ \
int _flag = PPW - (sbindex); \
register PixelType _src; \
\
_src = SCRLEFT (*(psrc), (sbindex)); \
if ((width) > _flag) \
_src |= SCRRIGHT (*((psrc) + 1), _flag); \
_src = DoRRop(rop, _src, *(pdst)); \
\
*(pdst) = (*(pdst) & mfbGetstarttab((width))) | (_src & mfbGetendtab((width))); \
}
#endif
#endif