103b705cfSriastradh/*
203b705cfSriastradh * Copyright © 1998 Keith Packard
303b705cfSriastradh * Copyright © 2012 Intel Corporation
403b705cfSriastradh *
503b705cfSriastradh * Permission to use, copy, modify, distribute, and sell this software and its
603b705cfSriastradh * documentation for any purpose is hereby granted without fee, provided that
703b705cfSriastradh * the above copyright notice appear in all copies and that both that
803b705cfSriastradh * copyright notice and this permission notice appear in supporting
903b705cfSriastradh * documentation, and that the name of Keith Packard not be used in
1003b705cfSriastradh * advertising or publicity pertaining to distribution of the software without
1103b705cfSriastradh * specific, written prior permission.  Keith Packard makes no
1203b705cfSriastradh * representations about the suitability of this software for any purpose.  It
1303b705cfSriastradh * is provided "as is" without express or implied warranty.
1403b705cfSriastradh *
1503b705cfSriastradh * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1603b705cfSriastradh * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1703b705cfSriastradh * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1803b705cfSriastradh * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1903b705cfSriastradh * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
2003b705cfSriastradh * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2103b705cfSriastradh * PERFORMANCE OF THIS SOFTWARE.
2203b705cfSriastradh */
2303b705cfSriastradh
2403b705cfSriastradh#ifndef FB_H
2503b705cfSriastradh#define FB_H
2603b705cfSriastradh
2703b705cfSriastradh#include <xorg-server.h>
2803b705cfSriastradh#include <servermd.h>
2903b705cfSriastradh#include <gcstruct.h>
3003b705cfSriastradh#include <colormap.h>
3103b705cfSriastradh#include <windowstr.h>
3203b705cfSriastradh#include <regionstr.h>
3303b705cfSriastradh
3403b705cfSriastradh#include <stdbool.h>
3503b705cfSriastradh#include <pixman.h>
3603b705cfSriastradh
3703b705cfSriastradh#include "sfb.h"
3803b705cfSriastradh
3903b705cfSriastradh#include "../../compat-api.h"
4013496ba1Ssnj#include "../debug.h"
4103b705cfSriastradh
4203b705cfSriastradh#define WRITE(ptr, val) (*(ptr) = (val))
4303b705cfSriastradh#define READ(ptr) (*(ptr))
4403b705cfSriastradh
4503b705cfSriastradh/*
4603b705cfSriastradh * This single define controls the basic size of data manipulated
4703b705cfSriastradh * by this software; it must be log2(sizeof (FbBits) * 8)
4803b705cfSriastradh */
4903b705cfSriastradh#define FB_SHIFT    LOG2_BITMAP_PAD
5003b705cfSriastradh
5103b705cfSriastradh#define FB_UNIT	    (1 << FB_SHIFT)
5203b705cfSriastradh#define FB_HALFUNIT (1 << (FB_SHIFT-1))
5303b705cfSriastradh#define FB_MASK	    (FB_UNIT - 1)
5403b705cfSriastradh#define FB_ALLONES  ((FbBits) -1)
5503b705cfSriastradh
5603b705cfSriastradh#if IMAGE_BYTE_ORDER != LSBFirst
5703b705cfSriastradh#error "IMAGE_BYTE_ORDER must be LSBFirst"
5803b705cfSriastradh#endif
5903b705cfSriastradh
6003b705cfSriastradh#if GLYPHPADBYTES != 4
6103b705cfSriastradh#error "GLYPHPADBYTES must be 4"
6203b705cfSriastradh#endif
6303b705cfSriastradh
6403b705cfSriastradh#if FB_SHIFT != 5
6503b705cfSriastradh#error "FB_SHIFT ala LOG2_BITMAP_PAD must be 5"
6603b705cfSriastradh#endif
6703b705cfSriastradh
6803b705cfSriastradh#define FB_STIP_SHIFT	LOG2_BITMAP_PAD
6903b705cfSriastradh#define FB_STIP_UNIT	(1 << FB_STIP_SHIFT)
7003b705cfSriastradh#define FB_STIP_MASK	(FB_STIP_UNIT - 1)
7103b705cfSriastradh#define FB_STIP_ALLONES	((FbStip) -1)
7203b705cfSriastradh#define FbFullMask(n)   ((n) == FB_UNIT ? FB_ALLONES : ((((FbBits) 1) << n) - 1))
7303b705cfSriastradh
7403b705cfSriastradhtypedef uint32_t FbBits;
7503b705cfSriastradhtypedef FbBits FbStip;
7603b705cfSriastradhtypedef int FbStride;
7703b705cfSriastradh
7803b705cfSriastradh#include "fbrop.h"
7903b705cfSriastradh
8003b705cfSriastradh#define FbScrLeft(x,n)	((x) >> (n))
8103b705cfSriastradh#define FbScrRight(x,n)	((x) << (n))
8203b705cfSriastradh/* #define FbLeftBits(x,n)	((x) & ((((FbBits) 1) << (n)) - 1)) */
8303b705cfSriastradh#define FbLeftStipBits(x,n) ((x) & ((((FbStip) 1) << (n)) - 1))
8403b705cfSriastradh#define FbStipMoveLsb(x,s,n)	(FbStipRight (x,(s)-(n)))
8503b705cfSriastradh#define FbPatternOffsetBits	0
8603b705cfSriastradh
8703b705cfSriastradh#define FbStipLeft(x,n)	FbScrLeft(x,n)
8803b705cfSriastradh#define FbStipRight(x,n) FbScrRight(x,n)
8903b705cfSriastradh
9003b705cfSriastradh#define FbRotLeft(x,n)	FbScrLeft(x,n) | (n ? FbScrRight(x,FB_UNIT-n) : 0)
9103b705cfSriastradh#define FbRotRight(x,n)	FbScrRight(x,n) | (n ? FbScrLeft(x,FB_UNIT-n) : 0)
9203b705cfSriastradh
9303b705cfSriastradh#define FbRotStipLeft(x,n)  FbStipLeft(x,n) | (n ? FbStipRight(x,FB_STIP_UNIT-n) : 0)
9403b705cfSriastradh#define FbRotStipRight(x,n)  FbStipRight(x,n) | (n ? FbStipLeft(x,FB_STIP_UNIT-n) : 0)
9503b705cfSriastradh
9603b705cfSriastradh#define FbLeftMask(x)	    ( ((x) & FB_MASK) ? \
9703b705cfSriastradh			     FbScrRight(FB_ALLONES,(x) & FB_MASK) : 0)
9803b705cfSriastradh#define FbRightMask(x)	    ( ((FB_UNIT - (x)) & FB_MASK) ? \
9903b705cfSriastradh			     FbScrLeft(FB_ALLONES,(FB_UNIT - (x)) & FB_MASK) : 0)
10003b705cfSriastradh
10103b705cfSriastradh#define FbLeftStipMask(x)   ( ((x) & FB_STIP_MASK) ? \
10203b705cfSriastradh			     FbStipRight(FB_STIP_ALLONES,(x) & FB_STIP_MASK) : 0)
10303b705cfSriastradh#define FbRightStipMask(x)  ( ((FB_STIP_UNIT - (x)) & FB_STIP_MASK) ? \
10403b705cfSriastradh			     FbScrLeft(FB_STIP_ALLONES,(FB_STIP_UNIT - (x)) & FB_STIP_MASK) : 0)
10503b705cfSriastradh
10603b705cfSriastradh#define FbBitsMask(x,w)	(FbScrRight(FB_ALLONES,(x) & FB_MASK) & \
10703b705cfSriastradh			 FbScrLeft(FB_ALLONES,(FB_UNIT - ((x) + (w))) & FB_MASK))
10803b705cfSriastradh
10903b705cfSriastradh#define FbStipMask(x,w)	(FbStipRight(FB_STIP_ALLONES,(x) & FB_STIP_MASK) & \
11003b705cfSriastradh			 FbStipLeft(FB_STIP_ALLONES,(FB_STIP_UNIT - ((x)+(w))) & FB_STIP_MASK))
11103b705cfSriastradh
11203b705cfSriastradh#define FbMaskBits(x,w,l,n,r) { \
11303b705cfSriastradh    n = (w); \
11403b705cfSriastradh    r = FbRightMask((x)+n); \
11503b705cfSriastradh    l = FbLeftMask(x); \
11603b705cfSriastradh    if (l) { \
11703b705cfSriastradh	n -= FB_UNIT - ((x) & FB_MASK); \
11803b705cfSriastradh	if (n < 0) { \
11903b705cfSriastradh	    n = 0; \
12003b705cfSriastradh	    l &= r; \
12103b705cfSriastradh	    r = 0; \
12203b705cfSriastradh	} \
12303b705cfSriastradh    } \
12403b705cfSriastradh    n >>= FB_SHIFT; \
12503b705cfSriastradh}
12603b705cfSriastradh
12703b705cfSriastradh#define FbByteMaskInvalid   0x10
12803b705cfSriastradh
12903b705cfSriastradh#define FbPatternOffset(o,t)  ((o) ^ (FbPatternOffsetBits & ~(sizeof (t) - 1)))
13003b705cfSriastradh
13103b705cfSriastradh#define FbPtrOffset(p,o,t)		((t *) ((CARD8 *) (p) + (o)))
13203b705cfSriastradh#define FbSelectPatternPart(xor,o,t)	((xor) >> (FbPatternOffset (o,t) << 3))
13303b705cfSriastradh#define FbStorePart(dst,off,t,xor)	(WRITE(FbPtrOffset(dst,off,t), \
13403b705cfSriastradh					 FbSelectPart(xor,off,t)))
13503b705cfSriastradh#ifndef FbSelectPart
13603b705cfSriastradh#define FbSelectPart(x,o,t) FbSelectPatternPart(x,o,t)
13703b705cfSriastradh#endif
13803b705cfSriastradh
13903b705cfSriastradh#define FbMaskBitsBytes(x,w,copy,l,lb,n,r,rb) { \
14003b705cfSriastradh    n = (w); \
14103b705cfSriastradh    lb = 0; \
14203b705cfSriastradh    rb = 0; \
14303b705cfSriastradh    r = FbRightMask((x)+n); \
14403b705cfSriastradh    if (r) { \
14503b705cfSriastradh	/* compute right byte length */ \
14603b705cfSriastradh	if ((copy) && (((x) + n) & 7) == 0) { \
14703b705cfSriastradh	    rb = (((x) + n) & FB_MASK) >> 3; \
14803b705cfSriastradh	} else { \
14903b705cfSriastradh	    rb = FbByteMaskInvalid; \
15003b705cfSriastradh	} \
15103b705cfSriastradh    } \
15203b705cfSriastradh    l = FbLeftMask(x); \
15303b705cfSriastradh    if (l) { \
15403b705cfSriastradh	/* compute left byte length */ \
15503b705cfSriastradh	if ((copy) && ((x) & 7) == 0) { \
15603b705cfSriastradh	    lb = ((x) & FB_MASK) >> 3; \
15703b705cfSriastradh	} else { \
15803b705cfSriastradh	    lb = FbByteMaskInvalid; \
15903b705cfSriastradh	} \
16003b705cfSriastradh	/* subtract out the portion painted by leftMask */ \
16103b705cfSriastradh	n -= FB_UNIT - ((x) & FB_MASK); \
16203b705cfSriastradh	if (n < 0) { \
16303b705cfSriastradh	    if (lb != FbByteMaskInvalid) { \
16403b705cfSriastradh		if (rb == FbByteMaskInvalid) { \
16503b705cfSriastradh		    lb = FbByteMaskInvalid; \
16603b705cfSriastradh		} else if (rb) { \
16703b705cfSriastradh		    lb |= (rb - lb) << (FB_SHIFT - 3); \
16803b705cfSriastradh		    rb = 0; \
16903b705cfSriastradh		} \
17003b705cfSriastradh	    } \
17103b705cfSriastradh	    n = 0; \
17203b705cfSriastradh	    l &= r; \
17303b705cfSriastradh	    r = 0; \
17403b705cfSriastradh	}\
17503b705cfSriastradh    } \
17603b705cfSriastradh    n >>= FB_SHIFT; \
17703b705cfSriastradh}
17803b705cfSriastradh
17903b705cfSriastradh#define FbDoLeftMaskByteRRop(dst,lb,l,and,xor) { \
18003b705cfSriastradh    switch (lb) { \
18103b705cfSriastradh    case (sizeof (FbBits) - 3) | (1 << (FB_SHIFT - 3)): \
18203b705cfSriastradh	FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
18303b705cfSriastradh	break; \
18403b705cfSriastradh    case (sizeof (FbBits) - 3) | (2 << (FB_SHIFT - 3)): \
18503b705cfSriastradh	FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
18603b705cfSriastradh	FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
18703b705cfSriastradh	break; \
18803b705cfSriastradh    case (sizeof (FbBits) - 2) | (1 << (FB_SHIFT - 3)): \
18903b705cfSriastradh	FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
19003b705cfSriastradh	break; \
19103b705cfSriastradh    case sizeof (FbBits) - 3: \
19203b705cfSriastradh	FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
19303b705cfSriastradh    case sizeof (FbBits) - 2: \
19403b705cfSriastradh	FbStorePart(dst,sizeof (FbBits) - 2,CARD16,xor); \
19503b705cfSriastradh	break; \
19603b705cfSriastradh    case sizeof (FbBits) - 1: \
19703b705cfSriastradh	FbStorePart(dst,sizeof (FbBits) - 1,CARD8,xor); \
19803b705cfSriastradh	break; \
19903b705cfSriastradh    default: \
20003b705cfSriastradh	WRITE(dst, FbDoMaskRRop(READ(dst), and, xor, l)); \
20103b705cfSriastradh	break; \
20203b705cfSriastradh    } \
20303b705cfSriastradh}
20403b705cfSriastradh
20503b705cfSriastradh#define FbDoRightMaskByteRRop(dst,rb,r,and,xor) { \
20603b705cfSriastradh    switch (rb) { \
20703b705cfSriastradh    case 1: \
20803b705cfSriastradh	FbStorePart(dst,0,CARD8,xor); \
20903b705cfSriastradh	break; \
21003b705cfSriastradh    case 2: \
21103b705cfSriastradh	FbStorePart(dst,0,CARD16,xor); \
21203b705cfSriastradh	break; \
21303b705cfSriastradh    case 3: \
21403b705cfSriastradh	FbStorePart(dst,0,CARD16,xor); \
21503b705cfSriastradh	FbStorePart(dst,2,CARD8,xor); \
21603b705cfSriastradh	break; \
21703b705cfSriastradh    default: \
21803b705cfSriastradh	WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, r)); \
21903b705cfSriastradh    } \
22003b705cfSriastradh}
22103b705cfSriastradh
22203b705cfSriastradh#define FbMaskStip(x,w,l,n,r) { \
22303b705cfSriastradh    n = (w); \
22403b705cfSriastradh    r = FbRightStipMask((x)+n); \
22503b705cfSriastradh    l = FbLeftStipMask(x); \
22603b705cfSriastradh    if (l) { \
22703b705cfSriastradh	n -= FB_STIP_UNIT - ((x) & FB_STIP_MASK); \
22803b705cfSriastradh	if (n < 0) { \
22903b705cfSriastradh	    n = 0; \
23003b705cfSriastradh	    l &= r; \
23103b705cfSriastradh	    r = 0; \
23203b705cfSriastradh	} \
23303b705cfSriastradh    } \
23403b705cfSriastradh    n >>= FB_STIP_SHIFT; \
23503b705cfSriastradh}
23603b705cfSriastradh
23703b705cfSriastradh/*
23803b705cfSriastradh * These macros are used to transparently stipple
23903b705cfSriastradh * in copy mode; the expected usage is with 'n' constant
24003b705cfSriastradh * so all of the conditional parts collapse into a minimal
24103b705cfSriastradh * sequence of partial word writes
24203b705cfSriastradh *
24303b705cfSriastradh * 'n' is the bytemask of which bytes to store, 'a' is the address
24403b705cfSriastradh * of the FbBits base unit, 'o' is the offset within that unit
24503b705cfSriastradh *
24603b705cfSriastradh * The term "lane" comes from the hardware term "byte-lane" which
24703b705cfSriastradh */
24803b705cfSriastradh
24903b705cfSriastradh#define FbLaneCase1(n,a,o)						\
25003b705cfSriastradh    if ((n) == 0x01) {							\
25103b705cfSriastradh	WRITE((CARD8 *) ((a)+FbPatternOffset(o,CARD8)), fgxor);		\
25203b705cfSriastradh    }
25303b705cfSriastradh
25403b705cfSriastradh#define FbLaneCase2(n,a,o)						\
25503b705cfSriastradh    if ((n) == 0x03) {							\
25603b705cfSriastradh	WRITE((CARD16 *) ((a)+FbPatternOffset(o,CARD16)), fgxor);	\
25703b705cfSriastradh    } else {								\
25803b705cfSriastradh	FbLaneCase1((n)&1,a,o)						\
25903b705cfSriastradh	FbLaneCase1((n)>>1,a,(o)+1)					\
26003b705cfSriastradh    }
26103b705cfSriastradh
26203b705cfSriastradh#define FbLaneCase4(n,a,o)						\
26303b705cfSriastradh    if ((n) == 0x0f) {							\
26403b705cfSriastradh	WRITE((CARD32 *) ((a)+FbPatternOffset(o,CARD32)), fgxor);	\
26503b705cfSriastradh    } else {								\
26603b705cfSriastradh	FbLaneCase2((n)&3,a,o)						\
26703b705cfSriastradh	FbLaneCase2((n)>>2,a,(o)+2)					\
26803b705cfSriastradh    }
26903b705cfSriastradh
27003b705cfSriastradh#define FbLaneCase(n,a)   FbLaneCase4(n,(CARD8 *) (a),0)
27103b705cfSriastradh
27203b705cfSriastradhtypedef struct {
27303b705cfSriastradh	long changes;
27403b705cfSriastradh	long serial;
27503b705cfSriastradh	GCFuncs *old_funcs;
27603b705cfSriastradh	void *priv;
27703b705cfSriastradh
27803b705cfSriastradh	FbBits and, xor;            /* reduced rop values */
27903b705cfSriastradh	FbBits bgand, bgxor;        /* for stipples */
28003b705cfSriastradh	FbBits fg, bg, pm;          /* expanded and filled */
28103b705cfSriastradh	unsigned int dashLength;    /* total of all dash elements */
28203b705cfSriastradh	unsigned char evenStipple;  /* stipple is even */
28303b705cfSriastradh	unsigned char bpp;          /* current drawable bpp */
28403b705cfSriastradh} FbGCPrivate, *FbGCPrivPtr;
28503b705cfSriastradh
28603b705cfSriastradhextern DevPrivateKeyRec sna_gc_key;
28703b705cfSriastradhextern DevPrivateKeyRec sna_window_key;
28803b705cfSriastradh
28903b705cfSriastradhstatic inline FbGCPrivate *fb_gc(GCPtr gc)
29003b705cfSriastradh{
29103b705cfSriastradh	return (FbGCPrivate *)__get_private(gc, sna_gc_key);
29203b705cfSriastradh}
29303b705cfSriastradh
29403b705cfSriastradhstatic inline PixmapPtr fbGetWindowPixmap(WindowPtr window)
29503b705cfSriastradh{
29603b705cfSriastradh	return *(PixmapPtr *)__get_private(window, sna_window_key);
29703b705cfSriastradh}
29803b705cfSriastradh
29903b705cfSriastradh#ifdef ROOTLESS
30003b705cfSriastradh#define __fbPixDrawableX(p)	((p)->drawable.x)
30103b705cfSriastradh#define __fbPixDrawableY(p)	((p)->drawable.y)
30203b705cfSriastradh#else
30303b705cfSriastradh#define __fbPixDrawableX(p)	0
30403b705cfSriastradh#define __fbPixDrawableY(p)	0
30503b705cfSriastradh#endif
30603b705cfSriastradh
30703b705cfSriastradh#ifdef COMPOSITE
30803b705cfSriastradh#define __fbPixOffXWin(p)	(__fbPixDrawableX(p) - (p)->screen_x)
30903b705cfSriastradh#define __fbPixOffYWin(p)	(__fbPixDrawableY(p) - (p)->screen_y)
31003b705cfSriastradh#else
31103b705cfSriastradh#define __fbPixOffXWin(p)	(__fbPixDrawableX(p))
31203b705cfSriastradh#define __fbPixOffYWin(p)	(__fbPixDrawableY(p))
31303b705cfSriastradh#endif
31403b705cfSriastradh#define __fbPixOffXPix(p)	(__fbPixDrawableX(p))
31503b705cfSriastradh#define __fbPixOffYPix(p)	(__fbPixDrawableY(p))
31603b705cfSriastradh
31703b705cfSriastradh#define fbGetDrawablePixmap(drawable, pixmap, xoff, yoff) {		\
31803b705cfSriastradh    if ((drawable)->type != DRAWABLE_PIXMAP) {				\
31903b705cfSriastradh	(pixmap) = fbGetWindowPixmap((WindowPtr)drawable);		\
32003b705cfSriastradh	(xoff) = __fbPixOffXWin(pixmap);				\
32103b705cfSriastradh	(yoff) = __fbPixOffYWin(pixmap);				\
32203b705cfSriastradh    } else {								\
32303b705cfSriastradh	(pixmap) = (PixmapPtr) (drawable);				\
32403b705cfSriastradh	(xoff) = __fbPixOffXPix(pixmap);				\
32503b705cfSriastradh	(yoff) = __fbPixOffYPix(pixmap);				\
32603b705cfSriastradh    }									\
32703b705cfSriastradh}
32803b705cfSriastradh
32903b705cfSriastradh#define fbGetPixmapBitsData(pixmap, pointer, stride, bpp) {		\
33003b705cfSriastradh    (pointer) = (FbBits *) (pixmap)->devPrivate.ptr;			\
33103b705cfSriastradh    (stride) = ((int) (pixmap)->devKind) / sizeof (FbBits); (void)(stride);\
33203b705cfSriastradh    (bpp) = (pixmap)->drawable.bitsPerPixel;  (void)(bpp);		\
33303b705cfSriastradh}
33403b705cfSriastradh
33503b705cfSriastradh#define fbGetPixmapStipData(pixmap, pointer, stride, bpp) {		\
33603b705cfSriastradh    (pointer) = (FbStip *) (pixmap)->devPrivate.ptr;			\
33703b705cfSriastradh    (stride) = ((int) (pixmap)->devKind) / sizeof (FbStip); (void)(stride);\
33803b705cfSriastradh    (bpp) = (pixmap)->drawable.bitsPerPixel;  (void)(bpp);		\
33903b705cfSriastradh}
34003b705cfSriastradh
34103b705cfSriastradh#define fbGetDrawable(drawable, pointer, stride, bpp, xoff, yoff) {	\
34203b705cfSriastradh    PixmapPtr   _pPix;							\
34303b705cfSriastradh    fbGetDrawablePixmap(drawable, _pPix, xoff, yoff);			\
34403b705cfSriastradh    fbGetPixmapBitsData(_pPix, pointer, stride, bpp);			\
34503b705cfSriastradh}
34603b705cfSriastradh
34703b705cfSriastradh#define fbGetStipDrawable(drawable, pointer, stride, bpp, xoff, yoff) {	\
34803b705cfSriastradh    PixmapPtr   _pPix;							\
34903b705cfSriastradh    fbGetDrawablePixmap(drawable, _pPix, xoff, yoff);			\
35003b705cfSriastradh    fbGetPixmapStipData(_pPix, pointer, stride, bpp);			\
35103b705cfSriastradh}
35203b705cfSriastradh
35303b705cfSriastradh/*
35403b705cfSriastradh * XFree86 empties the root BorderClip when the VT is inactive,
35503b705cfSriastradh * here's a macro which uses that to disable GetImage and GetSpans
35603b705cfSriastradh */
35703b705cfSriastradh
35803b705cfSriastradh#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,10,0,0,0)
35903b705cfSriastradh#define fbWindowEnabled(pWin) \
36003b705cfSriastradh	RegionNotEmpty(&(pWin)->drawable.pScreen->root->borderClip)
36103b705cfSriastradh#else
36203b705cfSriastradh#define fbWindowEnabled(pWin) \
36303b705cfSriastradh	RegionNotEmpty(&WindowTable[(pWin)->drawable.pScreen->myNum]->borderClip)
36403b705cfSriastradh#endif
36503b705cfSriastradh#define fbDrawableEnabled(drawable) \
36603b705cfSriastradh    ((drawable)->type == DRAWABLE_PIXMAP ? \
36703b705cfSriastradh     TRUE : fbWindowEnabled((WindowPtr) drawable))
36803b705cfSriastradh
36903b705cfSriastradh#define FbPowerOfTwo(w)	    (((w) & ((w) - 1)) == 0)
37003b705cfSriastradh/*
37103b705cfSriastradh * Accelerated tiles are power of 2 width <= FB_UNIT
37203b705cfSriastradh */
37303b705cfSriastradh#define FbEvenTile(w)	    ((w) <= FB_UNIT && FbPowerOfTwo(w))
37403b705cfSriastradh/*
37503b705cfSriastradh * Accelerated stipples are power of 2 width and <= FB_UNIT/dstBpp
37603b705cfSriastradh * with dstBpp a power of 2 as well
37703b705cfSriastradh */
37803b705cfSriastradh#define FbEvenStip(w,bpp)   ((w) * (bpp) <= FB_UNIT && FbPowerOfTwo(w) && FbPowerOfTwo(bpp))
37903b705cfSriastradh
38003b705cfSriastradhinline static int16_t fbBound(int16_t a, uint16_t b)
38103b705cfSriastradh{
38203b705cfSriastradh	int v = (int)a + (int)b;
38303b705cfSriastradh	if (v > MAXSHORT)
38403b705cfSriastradh		return MAXSHORT;
38503b705cfSriastradh	return v;
38603b705cfSriastradh}
38703b705cfSriastradh
38803b705cfSriastradhextern void
38903b705cfSriastradhfbPolyArc(DrawablePtr drawable, GCPtr gc, int narcs, xArc * parcs);
39003b705cfSriastradh
39103b705cfSriastradhextern void
39203b705cfSriastradhfbBlt(FbBits *src, FbStride srcStride, int srcX,
39303b705cfSriastradh      FbBits *dst, FbStride dstStride, int dstX,
39403b705cfSriastradh      int width, int height,
39503b705cfSriastradh      int alu, FbBits pm, int bpp,
39603b705cfSriastradh      Bool reverse, Bool upsidedown);
39703b705cfSriastradh
39803b705cfSriastradh#if FB_STIP_SHIFT == FB_SHIFT
39903b705cfSriastradhstatic inline void
40003b705cfSriastradhfbBltStip(FbStip *src, FbStride srcStride, int srcX,
40103b705cfSriastradh	  FbStip *dst, FbStride dstStride, int dstX,
40203b705cfSriastradh	  int width, int height, int alu, FbBits pm, int bpp)
40303b705cfSriastradh{
40403b705cfSriastradh	fbBlt((FbBits *)src, srcStride, srcX,
40503b705cfSriastradh	      (FbBits *)dst, dstStride, dstX,
40603b705cfSriastradh	      width, height, alu, pm, bpp,
40703b705cfSriastradh	      FALSE, FALSE);
40803b705cfSriastradh}
40903b705cfSriastradh#else
41003b705cfSriastradh#error FB_STIP_SHIFT must equal FB_SHIFT
41103b705cfSriastradh#endif
41203b705cfSriastradh
41303b705cfSriastradhextern void
41403b705cfSriastradhfbBltOne(FbStip *src, FbStride srcStride, int srcX,
41503b705cfSriastradh         FbBits *dst, FbStride dstStride, int dstX,
41603b705cfSriastradh         int dstBpp, int width, int height,
41703b705cfSriastradh	 FbBits fgand, FbBits fbxor, FbBits bgand, FbBits bgxor);
41803b705cfSriastradh
41903b705cfSriastradhextern void
42003b705cfSriastradhfbBltPlane(FbBits *src, FbStride srcStride, int srcX, int srcBpp,
42103b705cfSriastradh           FbStip *dst, FbStride dstStride, int dstX,
42203b705cfSriastradh           int width, int height,
42303b705cfSriastradh           FbStip fgand, FbStip fgxor, FbStip bgand, FbStip bgxor,
42403b705cfSriastradh	   Pixel planeMask);
42503b705cfSriastradh
42603b705cfSriastradhextern void
42703b705cfSriastradhfbCopyNtoN(DrawablePtr src, DrawablePtr dst, GCPtr gc,
42803b705cfSriastradh           BoxPtr pbox, int nbox,
42903b705cfSriastradh           int dx, int dy,
43003b705cfSriastradh           Bool reverse, Bool upsidedown, Pixel bitplane, void *closure);
43103b705cfSriastradh
43203b705cfSriastradhextern void
43303b705cfSriastradhfbCopy1toN(DrawablePtr src, DrawablePtr dst, GCPtr gc,
43403b705cfSriastradh           BoxPtr pbox, int nbox,
43503b705cfSriastradh           int dx, int dy,
43603b705cfSriastradh           Bool reverse, Bool upsidedown, Pixel bitplane, void *closure);
43703b705cfSriastradh
43803b705cfSriastradhextern void
43903b705cfSriastradhfbCopyNto1(DrawablePtr src, DrawablePtr dst, GCPtr gc,
44003b705cfSriastradh           BoxPtr pbox, int nbox,
44103b705cfSriastradh           int dx, int dy,
44203b705cfSriastradh           Bool reverse, Bool upsidedown, Pixel bitplane, void *closure);
44303b705cfSriastradh
44403b705cfSriastradhextern RegionPtr
44503b705cfSriastradhfbCopyArea(DrawablePtr src, DrawablePtr dst, GCPtr gc,
44603b705cfSriastradh	   int sx, int sy,
44703b705cfSriastradh	   int width, int height,
44803b705cfSriastradh	   int dx, int dy);
44903b705cfSriastradh
45003b705cfSriastradhextern RegionPtr
45103b705cfSriastradhfbCopyPlane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
45203b705cfSriastradh	    int sx, int sy,
45303b705cfSriastradh	    int width, int height,
45403b705cfSriastradh	    int dx, int dy,
45503b705cfSriastradh	    unsigned long bitplane);
45603b705cfSriastradh
45703b705cfSriastradhextern void
45803b705cfSriastradhfbFill(DrawablePtr drawable, GCPtr gc, int x, int y, int width, int height);
45903b705cfSriastradh
46003b705cfSriastradhextern void
46103b705cfSriastradhfbSolidBoxClipped(DrawablePtr drawable, GCPtr gc,
46203b705cfSriastradh                  int x1, int y1, int x2, int y2);
46303b705cfSriastradh
46403b705cfSriastradhextern void
46503b705cfSriastradhfbPolyFillRect(DrawablePtr drawable, GCPtr gc, int n, xRectangle *rec);
46603b705cfSriastradh
46703b705cfSriastradhextern void
46803b705cfSriastradhfbFillSpans(DrawablePtr drawable, GCPtr gc,
46903b705cfSriastradh            int n, DDXPointPtr pt, int *width, int fSorted);
47003b705cfSriastradh
47103b705cfSriastradhextern void
47203b705cfSriastradhfbPadPixmap(PixmapPtr pPixmap);
47303b705cfSriastradh
47403b705cfSriastradhextern void
47503b705cfSriastradhfbValidateGC(GCPtr gc, unsigned long changes, DrawablePtr drawable);
47603b705cfSriastradh
47703b705cfSriastradhextern void
47803b705cfSriastradhfbGetSpans(DrawablePtr drawable, int wMax,
47903b705cfSriastradh           DDXPointPtr pt, int *width, int n, char *dst);
48003b705cfSriastradh
48103b705cfSriastradhextern void
48203b705cfSriastradhfbPolyGlyphBlt(DrawablePtr drawable, GCPtr gc, int x, int y,
48303b705cfSriastradh               unsigned int n, CharInfoPtr *info, pointer glyphs);
48403b705cfSriastradh
48503b705cfSriastradhextern void
48603b705cfSriastradhfbImageGlyphBlt(DrawablePtr drawable, GCPtr gc, int x, int y,
48703b705cfSriastradh                unsigned int n, CharInfoPtr *info, pointer glyphs);
48803b705cfSriastradh
48903b705cfSriastradhextern void
49003b705cfSriastradhfbPutImage(DrawablePtr drawable, GCPtr gc, int depth,
49103b705cfSriastradh           int x, int y, int w, int h,
49203b705cfSriastradh	   int leftPad, int format, char *image);
49303b705cfSriastradh
49403b705cfSriastradhextern void
49503b705cfSriastradhfbPutXYImage(DrawablePtr drawable, GCPtr gc,
49603b705cfSriastradh             FbBits fg, FbBits bg, FbBits pm,
49703b705cfSriastradh             int alu, Bool opaque,
49803b705cfSriastradh             int x, int y, int width, int height,
49903b705cfSriastradh	     FbStip * src, FbStride srcStride, int srcX);
50003b705cfSriastradh
50103b705cfSriastradhextern void
50203b705cfSriastradhfbGetImage(DrawablePtr drawable,
50303b705cfSriastradh           int x, int y, int w, int h,
50403b705cfSriastradh	   unsigned int format, unsigned long planeMask, char *d);
50503b705cfSriastradh
50603b705cfSriastradhextern void
50703b705cfSriastradhfbPolyLine(DrawablePtr drawable, GCPtr gc, int mode, int n, DDXPointPtr pt);
50803b705cfSriastradh
50903b705cfSriastradhextern void
51003b705cfSriastradhfbFixCoordModePrevious(int n, DDXPointPtr pt);
51103b705cfSriastradh
51203b705cfSriastradhextern void
51303b705cfSriastradhfbPolySegment(DrawablePtr drawable, GCPtr gc, int n, xSegment *seg);
51403b705cfSriastradh
51503b705cfSriastradhextern RegionPtr
51603b705cfSriastradhfbBitmapToRegion(PixmapPtr pixmap);
51703b705cfSriastradh
51803b705cfSriastradhextern void
51903b705cfSriastradhfbPolyPoint(DrawablePtr drawable, GCPtr gc,
52003b705cfSriastradh	    int mode, int n, xPoint *pt,
52103b705cfSriastradh	    unsigned flags);
52203b705cfSriastradh
52303b705cfSriastradhextern void
52403b705cfSriastradhfbPushImage(DrawablePtr drawable, GCPtr gc,
52503b705cfSriastradh            FbStip *src, FbStride srcStride, int srcX,
52603b705cfSriastradh	    int x, int y, int width, int height);
52703b705cfSriastradh
52803b705cfSriastradhextern void
52903b705cfSriastradhfbPushPixels(GCPtr gc, PixmapPtr pBitmap, DrawablePtr drawable,
53003b705cfSriastradh	     int dx, int dy, int xOrg, int yOrg);
53103b705cfSriastradh
53203b705cfSriastradhextern void
53303b705cfSriastradhfbSetSpans(DrawablePtr drawable, GCPtr gc,
53403b705cfSriastradh           char *src, DDXPointPtr pt, int *width, int n, int fSorted);
53503b705cfSriastradh
53603b705cfSriastradhextern void
53703b705cfSriastradhfbSegment(DrawablePtr drawable, GCPtr gc,
53803b705cfSriastradh          int xa, int ya, int xb, int yb,
53903b705cfSriastradh	  bool drawLast, int *dashOffset);
54003b705cfSriastradh
54103b705cfSriastradhextern void
54203b705cfSriastradhfbSegment1(DrawablePtr drawable, GCPtr gc, const BoxRec *clip,
54303b705cfSriastradh          int xa, int ya, int xb, int yb,
54403b705cfSriastradh	  bool drawLast, int *dashOffset);
54503b705cfSriastradh
54603b705cfSriastradhextern void
54703b705cfSriastradhfbTransparentSpan(FbBits * dst, FbBits stip, FbBits fgxor, int n);
54803b705cfSriastradh
54903b705cfSriastradhextern void
55003b705cfSriastradhfbStipple(FbBits *dst, FbStride dstStride, int dstX, int dstBpp,
55103b705cfSriastradh          int width, int height,
55203b705cfSriastradh          FbStip *stip, FbStride stipStride,
55303b705cfSriastradh          int stipWidth, int stipHeight,
55403b705cfSriastradh          Bool even,
55503b705cfSriastradh          FbBits fgand, FbBits fgxor, FbBits bgand, FbBits bgxor,
55603b705cfSriastradh	  int xRot, int yRot);
55703b705cfSriastradh
55803b705cfSriastradhextern void
55903b705cfSriastradhfbTile(FbBits *dst, FbStride dstStride, int dstX, int width, int height,
56003b705cfSriastradh       FbBits *tile, FbStride tileStride, int tileWidth, int tileHeight,
56103b705cfSriastradh       int alu, FbBits pm, int bpp,
56203b705cfSriastradh       int xRot, int yRot);
56303b705cfSriastradh
56403b705cfSriastradhextern FbBits fbReplicatePixel(Pixel p, int bpp);
56503b705cfSriastradh
56603b705cfSriastradh#endif  /* FB_H */
567