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