1 /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
2 /***********************************************************
4 Copyright (c) 1987 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
28 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
32 Permission to use, copy, modify, and distribute this software and its
33 documentation for any purpose and without fee is hereby granted,
34 provided that the above copyright notice appear in all copies and that
35 both that copyright notice and this permission notice appear in
36 supporting documentation, and that the name of Digital not be
37 used in advertising or publicity pertaining to distribution of the
38 software without specific, written prior permission.
40 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48 ******************************************************************/
50 #ifdef HAVE_DIX_CONFIG_H
51 #include <dix-config.h>
57 #include <X11/Xprotostr.h>
59 #include "regionstr.h"
61 #include "windowstr.h"
62 #include "pixmapstr.h"
63 #include "scrnintstr.h"
70 /* CopyArea and CopyPlane for a monchrome frame buffer
73 clip the source rectangle to the source's available bits. (this
74 avoids copying unnecessary pieces that will just get exposed anyway.)
75 this becomes the new shape of the destination.
76 clip the destination region to the composite clip in the
77 GC. this requires translating the destination region to (dstx, dsty).
78 build a list of source points, one for each rectangle in the
79 destination. this is a simple translation.
80 go do the multiple rectangle copies
83 /** Optimized for drawing pixmaps into windows, especially when drawing into
84 ** unobscured windows. Calls to the general-purpose region code were
85 ** replaced with rectangle-to-rectangle clipping comparisions. This is
86 ** possible, since the pixmap is a single rectangle. In an unobscured
87 ** window, the destination clip is also a single rectangle, and region
88 ** code can be avoided entirely. This is a big savings, since the region
89 ** code uses XAlloc() and makes many function calls.
91 ** In addition, if source is a pixmap, there is no need to call the
92 ** expensive miHandleExposures() routine. Instead, we simply return NULL.
94 ** Previously, drawing a pixmap into an unobscured window executed at least
95 ** 8 XAlloc()'s, 30 function calls, and hundreds of lines of code.
97 ** Now, the same operation requires no XAlloc()'s, no region function calls,
98 ** and much less overhead. Nice for drawing lots of small pixmaps.
102 afbDoBitblt(DrawablePtr pSrc
, DrawablePtr pDst
, int alu
, RegionPtr prgnDst
, DDXPointPtr pptSrc
, long unsigned int planemask
)
106 afbDoBitbltCopy(pSrc
, pDst
, alu
, prgnDst
, pptSrc
, planemask
);
109 afbDoBitbltXor(pSrc
, pDst
, alu
, prgnDst
, pptSrc
, planemask
);
112 afbDoBitbltCopyInverted(pSrc
, pDst
, alu
, prgnDst
, pptSrc
, planemask
);
115 afbDoBitbltOr(pSrc
, pDst
, alu
, prgnDst
, pptSrc
, planemask
);
118 afbDoBitbltGeneral(pSrc
, pDst
, alu
, prgnDst
, pptSrc
, planemask
);
123 typedef void (*afb_blit_func
)
124 (DrawablePtr
, DrawablePtr
, int, RegionPtr
, DDXPointPtr
, unsigned long);
127 afbBitBlt(register DrawablePtr pSrcDrawable
, register DrawablePtr pDstDrawable
, register GC
*pGC
, int srcx
, int srcy
, int width
, int height
, int dstx
, int dsty
, afb_blit_func doBitBlt
, long unsigned int planemask
)
129 RegionPtr prgnSrcClip
= NULL
; /* may be a new region, or just a copy */
130 Bool freeSrcClip
= FALSE
;
132 RegionPtr prgnExposed
;
135 register DDXPointPtr ppt
;
136 register BoxPtr pbox
;
140 xRectangle origSource
;
141 DDXPointRec origDest
;
144 int fastClip
= 0; /* for fast clipping with pixmap source */
145 int fastExpose
= 0; /* for fast exposures with pixmap source */
149 origSource
.width
= width
;
150 origSource
.height
= height
;
154 if ((pSrcDrawable
!= pDstDrawable
) && pSrcDrawable
->pScreen
->SourceValidate
)
155 (*pSrcDrawable
->pScreen
->SourceValidate
)(pSrcDrawable
, srcx
, srcy
, width
,
158 srcx
+= pSrcDrawable
->x
;
159 srcy
+= pSrcDrawable
->y
;
161 /* clip the source */
163 if (pSrcDrawable
->type
== DRAWABLE_PIXMAP
)
164 if ((pSrcDrawable
== pDstDrawable
) && (pGC
->clientClipType
== CT_NONE
))
165 prgnSrcClip
= pGC
->pCompositeClip
;
168 else if (pGC
->subWindowMode
== IncludeInferiors
)
169 if (!((WindowPtr
)pSrcDrawable
)->parent
)
171 * special case bitblt from root window in
172 * IncludeInferiors mode; just like from a pixmap
175 else if ((pSrcDrawable
== pDstDrawable
) && (pGC
->clientClipType
== CT_NONE
))
176 prgnSrcClip
= pGC
->pCompositeClip
;
178 prgnSrcClip
= NotClippedByChildren((WindowPtr
)pSrcDrawable
);
182 prgnSrcClip
= &((WindowPtr
)pSrcDrawable
)->clipList
;
186 fastBox
.x2
= srcx
+ width
;
187 fastBox
.y2
= srcy
+ height
;
189 /* Don't create a source region if we are doing a fast clip */
193 * clip the source; if regions extend beyond the source size,
194 * make sure exposure events get sent
196 if (fastBox
.x1
< pSrcDrawable
->x
) {
197 fastBox
.x1
= pSrcDrawable
->x
;
200 if (fastBox
.y1
< pSrcDrawable
->y
) {
201 fastBox
.y1
= pSrcDrawable
->y
;
204 if (fastBox
.x2
> pSrcDrawable
->x
+ (int)pSrcDrawable
->width
) {
205 fastBox
.x2
= pSrcDrawable
->x
+ (int)pSrcDrawable
->width
;
208 if (fastBox
.y2
> pSrcDrawable
->y
+ (int)pSrcDrawable
->height
) {
209 fastBox
.y2
= pSrcDrawable
->y
+ (int)pSrcDrawable
->height
;
213 REGION_INIT(pGC
->pScreen
, &rgnDst
, &fastBox
, 1);
214 REGION_INTERSECT(pGC
->pScreen
, &rgnDst
, &rgnDst
, prgnSrcClip
);
217 dstx
+= pDstDrawable
->x
;
218 dsty
+= pDstDrawable
->y
;
220 if (pDstDrawable
->type
== DRAWABLE_WINDOW
)
221 if (!((WindowPtr
)pDstDrawable
)->realized
) {
223 REGION_UNINIT(pGC
->pScreen
, &rgnDst
);
225 REGION_DESTROY(pGC
->pScreen
, prgnSrcClip
);
232 /* Translate and clip the dst to the destination composite clip */
236 /* Translate the region directly */
242 /* If the destination composite clip is one rectangle we can
243 do the clip directly. Otherwise we have to create a full
244 blown region and call intersect */
245 cclip
= pGC
->pCompositeClip
;
246 if (REGION_NUM_RECTS(cclip
) == 1) {
247 BoxPtr pBox
= REGION_RECTS(cclip
);
249 if (fastBox
.x1
< pBox
->x1
)
250 fastBox
.x1
= pBox
->x1
;
251 if (fastBox
.x2
> pBox
->x2
)
252 fastBox
.x2
= pBox
->x2
;
253 if (fastBox
.y1
< pBox
->y1
)
254 fastBox
.y1
= pBox
->y1
;
255 if (fastBox
.y2
> pBox
->y2
)
256 fastBox
.y2
= pBox
->y2
;
258 /* Check to see if the region is empty */
259 if (fastBox
.x1
>= fastBox
.x2
|| fastBox
.y1
>= fastBox
.y2
) {
260 REGION_NULL(pGC
->pScreen
, &rgnDst
);
262 REGION_INIT(pGC
->pScreen
, &rgnDst
, &fastBox
, 1);
265 /* We must turn off fastClip now, since we must create
266 a full blown region. It is intersected with the
267 composite clip below. */
269 REGION_INIT(pGC
->pScreen
, &rgnDst
, &fastBox
,1);
272 REGION_TRANSLATE(pGC
->pScreen
, &rgnDst
, -dx
, -dy
);
275 REGION_INTERSECT(pGC
->pScreen
, &rgnDst
, &rgnDst
,
276 pGC
->pCompositeClip
);
279 /* Do bit blitting */
280 numRects
= REGION_NUM_RECTS(&rgnDst
);
281 if (numRects
&& width
&& height
) {
282 if(!(pptSrc
= (DDXPointPtr
)ALLOCATE_LOCAL(numRects
*
283 sizeof(DDXPointRec
)))) {
284 REGION_UNINIT(pGC
->pScreen
, &rgnDst
);
286 REGION_DESTROY(pGC
->pScreen
, prgnSrcClip
);
289 pbox
= REGION_RECTS(&rgnDst
);
291 for (i
= numRects
; --i
>= 0; pbox
++, ppt
++) {
292 ppt
->x
= pbox
->x1
+ dx
;
293 ppt
->y
= pbox
->y1
+ dy
;
296 (*doBitBlt
)(pSrcDrawable
, pDstDrawable
, pGC
->alu
, &rgnDst
, pptSrc
,
299 DEALLOCATE_LOCAL(pptSrc
);
304 /* Pixmap sources generate a NoExposed (we return NULL to do this) */
306 prgnExposed
= miHandleExposures(pSrcDrawable
, pDstDrawable
, pGC
,
307 origSource
.x
, origSource
.y
,
308 (int)origSource
.width
,
309 (int)origSource
.height
, origDest
.x
,
310 origDest
.y
, (unsigned long)0);
312 REGION_UNINIT(pGC
->pScreen
, &rgnDst
);
314 REGION_DESTROY(pGC
->pScreen
, prgnSrcClip
);
319 afbCopyArea(DrawablePtr pSrcDrawable
, DrawablePtr pDstDrawable
, GC
*pGC
, int srcx
, int srcy
, int width
, int height
, int dstx
, int dsty
)
321 afb_blit_func doBitBlt
;
325 doBitBlt
= afbDoBitbltCopy
;
328 doBitBlt
= afbDoBitbltXor
;
331 doBitBlt
= afbDoBitbltCopyInverted
;
334 doBitBlt
= afbDoBitbltOr
;
337 doBitBlt
= afbDoBitbltGeneral
;
341 return(afbBitBlt(pSrcDrawable
, pDstDrawable
, pGC
, srcx
, srcy
,
342 width
, height
, dstx
, dsty
, doBitBlt
, pGC
->planemask
));