3 This is a lighter version of cfbBitBlt. We calculate the boxes
4 when accelerating pixmap->screen and screen->screen copies.
5 We also pass the GC to the doBitBlt function so that it has access
6 to the fg and bg so CopyPlane can use this.
9 #ifdef HAVE_XORG_CONFIG_H
10 #include <xorg-config.h>
15 #include "xf86_OSproc.h"
19 #include "pixmapstr.h"
21 #include "windowstr.h"
27 DrawablePtr pSrcDrawable
,
28 DrawablePtr pDstDrawable
,
31 int width
, int height
,
33 void (*doBitBlt
)(DrawablePtr
, DrawablePtr
, GCPtr
, RegionPtr
, DDXPointPtr
),
34 unsigned long bitPlane
)
37 RegionPtr prgnSrcClip
= NULL
; /* may be a new region, or just a copy */
38 RegionPtr prgnExposed
;
39 Bool freeSrcClip
= FALSE
;
41 DDXPointPtr pptSrc
, ppt
;
45 int i
, dx
, dy
, numRects
;
46 xRectangle origSource
;
47 int fastClip
= 0; /* for fast clipping with pixmap source */
48 int fastExpose
= 0; /* for fast exposures with pixmap source */
52 origSource
.width
= width
;
53 origSource
.height
= height
;
57 if((pSrcDrawable
!= pDstDrawable
) &&
58 pSrcDrawable
->pScreen
->SourceValidate
) {
59 (*pSrcDrawable
->pScreen
->SourceValidate
) (
60 pSrcDrawable
, srcx
, srcy
, width
, height
);
63 srcx
+= pSrcDrawable
->x
;
64 srcy
+= pSrcDrawable
->y
;
67 if (pSrcDrawable
->type
== DRAWABLE_PIXMAP
) {
68 if ((pSrcDrawable
== pDstDrawable
) && (pGC
->clientClipType
== CT_NONE
))
69 prgnSrcClip
= pGC
->pCompositeClip
;
73 if (pGC
->subWindowMode
== IncludeInferiors
) {
74 if (!((WindowPtr
) pSrcDrawable
)->parent
) {
76 * special case bitblt from root window in
77 * IncludeInferiors mode; just like from a pixmap
80 } else if ((pSrcDrawable
== pDstDrawable
) &&
81 (pGC
->clientClipType
== CT_NONE
)) {
82 prgnSrcClip
= pGC
->pCompositeClip
;
84 prgnSrcClip
= NotClippedByChildren((WindowPtr
)pSrcDrawable
);
88 prgnSrcClip
= &((WindowPtr
)pSrcDrawable
)->clipList
;
94 fastBox
.x2
= srcx
+ width
;
95 fastBox
.y2
= srcy
+ height
;
97 /* Don't create a source region if we are doing a fast clip */
101 * clip the source; if regions extend beyond the source size,
102 * make sure exposure events get sent
104 if (fastBox
.x1
< pSrcDrawable
->x
) {
105 fastBox
.x1
= pSrcDrawable
->x
;
108 if (fastBox
.y1
< pSrcDrawable
->y
) {
109 fastBox
.y1
= pSrcDrawable
->y
;
112 if (fastBox
.x2
> pSrcDrawable
->x
+ (int) pSrcDrawable
->width
) {
113 fastBox
.x2
= pSrcDrawable
->x
+ (int) pSrcDrawable
->width
;
116 if (fastBox
.y2
> pSrcDrawable
->y
+ (int) pSrcDrawable
->height
) {
117 fastBox
.y2
= pSrcDrawable
->y
+ (int) pSrcDrawable
->height
;
121 REGION_INIT(pGC
->pScreen
, &rgnDst
, &fastBox
, 1);
122 REGION_INTERSECT(pGC
->pScreen
, &rgnDst
, &rgnDst
, prgnSrcClip
);
125 dstx
+= pDstDrawable
->x
;
126 dsty
+= pDstDrawable
->y
;
128 if (pDstDrawable
->type
== DRAWABLE_WINDOW
) {
129 if (!((WindowPtr
)pDstDrawable
)->realized
) {
131 REGION_UNINIT(pGC
->pScreen
, &rgnDst
);
133 REGION_DESTROY(pGC
->pScreen
, prgnSrcClip
);
141 /* Translate and clip the dst to the destination composite clip */
145 /* Translate the region directly */
151 /* If the destination composite clip is one rectangle we can
152 do the clip directly. Otherwise we have to create a full
153 blown region and call intersect */
155 cclip
= pGC
->pCompositeClip
;
156 if (REGION_NUM_RECTS(cclip
) == 1) {
157 BoxPtr pBox
= REGION_RECTS(cclip
);
159 if (fastBox
.x1
< pBox
->x1
) fastBox
.x1
= pBox
->x1
;
160 if (fastBox
.x2
> pBox
->x2
) fastBox
.x2
= pBox
->x2
;
161 if (fastBox
.y1
< pBox
->y1
) fastBox
.y1
= pBox
->y1
;
162 if (fastBox
.y2
> pBox
->y2
) fastBox
.y2
= pBox
->y2
;
164 /* Check to see if the region is empty */
165 if (fastBox
.x1
>= fastBox
.x2
|| fastBox
.y1
>= fastBox
.y2
) {
166 REGION_NULL(pGC
->pScreen
, &rgnDst
);
168 REGION_INIT(pGC
->pScreen
, &rgnDst
, &fastBox
, 1);
171 /* We must turn off fastClip now, since we must create
172 a full blown region. It is intersected with the
173 composite clip below. */
175 REGION_INIT(pGC
->pScreen
, &rgnDst
, &fastBox
,1);
178 REGION_TRANSLATE(pGC
->pScreen
, &rgnDst
, -dx
, -dy
);
182 REGION_INTERSECT(pGC
->pScreen
, &rgnDst
, &rgnDst
,
183 pGC
->pCompositeClip
);
186 /* Do bit blitting */
187 numRects
= REGION_NUM_RECTS(&rgnDst
);
188 if (numRects
&& width
&& height
) {
189 if(!(pptSrc
= (DDXPointPtr
)ALLOCATE_LOCAL(numRects
*
190 sizeof(DDXPointRec
)))) {
191 REGION_UNINIT(pGC
->pScreen
, &rgnDst
);
193 REGION_DESTROY(pGC
->pScreen
, prgnSrcClip
);
196 pbox
= REGION_RECTS(&rgnDst
);
198 for (i
= numRects
; --i
>= 0; pbox
++, ppt
++) {
199 ppt
->x
= pbox
->x1
+ dx
;
200 ppt
->y
= pbox
->y1
+ dy
;
203 (*doBitBlt
) (pSrcDrawable
, pDstDrawable
, pGC
, &rgnDst
, pptSrc
);
204 DEALLOCATE_LOCAL(pptSrc
);
209 /* Pixmap sources generate a NoExposed (we return NULL to do this) */
211 prgnExposed
= miHandleExposures(pSrcDrawable
, pDstDrawable
, pGC
,
212 origSource
.x
, origSource
.y
,
213 (int)origSource
.width
,
214 (int)origSource
.height
,
215 origDest
.x
, origDest
.y
, bitPlane
);
217 REGION_UNINIT(pGC
->pScreen
, &rgnDst
);
219 REGION_DESTROY(pGC
->pScreen
, prgnSrcClip
);