summaryrefslogtreecommitdiff
path: root/hw/xfree86/xaa/xaaCpyPlane.c
blob: d8ad1447367d95c056ae8d5d95622bacab867bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208

/*
   A CopyPlane function that handles bitmap->screen copies and
   sends anything else to the Fallback.

   Also, a PushPixels for solid fill styles.

   Written by Mark Vojkovich (markv@valinux.com)

*/

#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif

#include <string.h>

#include "misc.h"
#include "xf86.h"
#include "xf86_OSproc.h"
#include "servermd.h"

#include <X11/X.h>
#include "scrnintstr.h"
#include "mi.h"
#include "pixmapstr.h"
#include "xf86str.h"
#include "xaa.h"
#include "xaalocal.h"
#include "xaawrap.h"

static void XAACopyPlane1toNColorExpand(DrawablePtr pSrc, DrawablePtr pDst,
					GCPtr pGC, RegionPtr rgnDst,
					DDXPointPtr pptSrc);
static void XAACopyPlaneNtoNColorExpand(DrawablePtr pSrc, DrawablePtr pDst,
					GCPtr pGC, RegionPtr rgnDst,
					DDXPointPtr pptSrc);


static unsigned long TmpBitPlane; 

_X_EXPORT RegionPtr
XAACopyPlaneColorExpansion(
    DrawablePtr	pSrc,
    DrawablePtr	pDst,
    GCPtr pGC,
    int	srcx, int srcy,
    int	width, int height,
    int	dstx, int dsty,
    unsigned long bitPlane 
){
    if((pSrc->type == DRAWABLE_PIXMAP) && !XAA_DEPTH_BUG(pGC)) {
	if(pSrc->bitsPerPixel == 1) {
	   return(XAABitBlt(pSrc, pDst, pGC, srcx, srcy,
			width, height, dstx, dsty, 
			XAACopyPlane1toNColorExpand, bitPlane));
	} else if(bitPlane < (1 << pDst->depth)){
	   TmpBitPlane = bitPlane;
	   return(XAABitBlt(pSrc, pDst, pGC, srcx, srcy,
			width, height, dstx, dsty, 
			XAACopyPlaneNtoNColorExpand, bitPlane));
	}
    }

    return (XAAFallbackOps.CopyPlane(pSrc, pDst, pGC, srcx, srcy, 
			width, height, dstx, dsty, bitPlane));
}


static void 
XAACopyPlane1toNColorExpand(
    DrawablePtr   pSrc, 
    DrawablePtr	  pDst,
    GCPtr	  pGC,
    RegionPtr     rgnDst,
    DDXPointPtr   pptSrc )
{
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
    BoxPtr pbox = REGION_RECTS(rgnDst);
    int numrects = REGION_NUM_RECTS(rgnDst);
    unsigned char *src = ((PixmapPtr)pSrc)->devPrivate.ptr;
    int srcwidth = ((PixmapPtr)pSrc)->devKind; 
    
    while(numrects--) {	
	(*infoRec->WriteBitmap)(infoRec->pScrn, pbox->x1, pbox->y1, 
		pbox->x2 - pbox->x1, pbox->y2 - pbox->y1, 
		src + (srcwidth * pptSrc->y) + ((pptSrc->x >> 5) << 2), 
		srcwidth, pptSrc->x & 31, 
		pGC->fgPixel, pGC->bgPixel, pGC->alu, pGC->planemask);
	pbox++; pptSrc++;
    }
}


static void 
XAACopyPlaneNtoNColorExpand(
    DrawablePtr   pSrc, 
    DrawablePtr	  pDst,
    GCPtr	  pGC,
    RegionPtr     rgnDst,
    DDXPointPtr   pptSrc 
){
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
    BoxPtr pbox = REGION_RECTS(rgnDst);
    int numrects = REGION_NUM_RECTS(rgnDst);
    unsigned char *src = ((PixmapPtr)pSrc)->devPrivate.ptr;
    unsigned char *data, *srcPtr, *dataPtr;
    int srcwidth = ((PixmapPtr)pSrc)->devKind; 
    int pitch, width, height, h, i, index, offset;
    int Bpp = pSrc->bitsPerPixel >> 3;
    unsigned long mask = TmpBitPlane;

    if(TmpBitPlane < (1 << 8)) {
	offset = 0;
    } else if(TmpBitPlane < (1 << 16)) {
	offset = 1;
	mask >>= 8;
    } else if(TmpBitPlane < (1 << 24)) {
	offset = 2;
	mask >>= 16;
    } else {
	offset = 3;
	mask >>= 24;
    }

    if(IS_OFFSCREEN_PIXMAP(pSrc))
	SYNC_CHECK(pSrc);
    
    while(numrects--) {	
	width = pbox->x2 - pbox->x1;
	h = height = pbox->y2 - pbox->y1;
	pitch = BitmapBytePad(width);

	if(!(data = xcalloc(height, pitch)))
	   goto ALLOC_FAILED;

	dataPtr = data;
        srcPtr = ((pptSrc->y) * srcwidth) + src + 
                        ((pptSrc->x) * Bpp) + offset;

	while(h--) {
	    for(i = index = 0; i < width; i++, index += Bpp) {
	       if(mask & srcPtr[index])
		  dataPtr[i >> 3] |= (1 << (i & 7));
	    }
	    dataPtr += pitch;
	    srcPtr += srcwidth;
	}

	(*infoRec->WriteBitmap)(infoRec->pScrn, 
		pbox->x1, pbox->y1, width, height, data, pitch, 0, 
		pGC->fgPixel, pGC->bgPixel, pGC->alu, pGC->planemask);
	
	xfree(data);

ALLOC_FAILED:

	pbox++; pptSrc++;
    }
}

_X_EXPORT void
XAAPushPixelsSolidColorExpansion(
    GCPtr	pGC,
    PixmapPtr	pBitMap,
    DrawablePtr pDraw,
    int	dx, int dy, 
    int xOrg, int yOrg )
{
   XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
   int MaxBoxes = REGION_NUM_RECTS(pGC->pCompositeClip);
   BoxPtr	pbox, pClipBoxes;
   int		nboxes, srcx, srcy;
   xRectangle TheRect;
   unsigned char *src = pBitMap->devPrivate.ptr;
   int srcwidth = pBitMap->devKind;

   if(!REGION_NUM_RECTS(pGC->pCompositeClip))
	return;

   TheRect.x = xOrg;
   TheRect.y = yOrg;
   TheRect.width = dx;
   TheRect.height = dy; 

   if(MaxBoxes > (infoRec->PreAllocSize/sizeof(BoxRec))) {
	pClipBoxes = xalloc(MaxBoxes * sizeof(BoxRec));
	if(!pClipBoxes) return;	
   } else pClipBoxes = (BoxPtr)infoRec->PreAllocMem;

   nboxes = XAAGetRectClipBoxes(pGC, pClipBoxes, 1, &TheRect);
   pbox = pClipBoxes;

   while(nboxes--) {
	srcx = pbox->x1 - xOrg;
	srcy = pbox->y1 - yOrg;
 	(*infoRec->WriteBitmap)(infoRec->pScrn, pbox->x1, pbox->y1, 
		pbox->x2 - pbox->x1, pbox->y2 - pbox->y1, 
		src + (srcwidth * srcy) + ((srcx >> 5) << 2), 
		srcwidth, srcx & 31, 
		pGC->fgPixel, -1, pGC->alu, pGC->planemask);
	pbox++;
   }

    if(pClipBoxes != (BoxPtr)infoRec->PreAllocMem)
	xfree(pClipBoxes);
}