1 /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
2 /***********************************************************
4 Copyright 1987, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
48 #ifdef HAVE_DIX_CONFIG_H
49 #include <dix-config.h>
53 #include <X11/Xprotostr.h>
57 #include "regionstr.h"
59 #include "windowstr.h"
60 #include "pixmapstr.h"
61 #include "scrnintstr.h"
69 /* CopyArea and CopyPlane for a monchrome frame buffer
72 clip the source rectangle to the source's available bits. (this
73 avoids copying unnecessary pieces that will just get exposed anyway.)
74 this becomes the new shape of the destination.
75 clip the destination region to the composite clip in the
76 GC. this requires translating the destination region to (dstx, dsty).
77 build a list of source points, one for each rectangle in the
78 destination. this is a simple translation.
79 go do the multiple rectangle copies
82 /** Optimized for drawing pixmaps into windows, especially when drawing into
83 ** unobscured windows. Calls to the general-purpose region code were
84 ** replaced with rectangle-to-rectangle clipping comparisions. This is
85 ** possible, since the pixmap is a single rectangle. In an unobscured
86 ** window, the destination clip is also a single rectangle, and region
87 ** code can be avoided entirely. This is a big savings, since the region
88 ** code uses XAlloc() and makes many function calls.
90 ** In addition, if source is a pixmap, there is no need to call the
91 ** expensive miHandleExposures() routine. Instead, we simply return NULL.
93 ** Previously, drawing a pixmap into an unobscured window executed at least
94 ** 8 XAlloc()'s, 30 function calls, and hundreds of lines of code.
96 ** Now, the same operation requires no XAlloc()'s, no region function calls,
97 ** and much less overhead. Nice for drawing lots of small pixmaps.
102 mfbDoBitblt (pSrc
, pDst
, alu
, prgnDst
, pptSrc
)
103 DrawablePtr pSrc
, pDst
;
111 mfbDoBitbltCopy (pSrc
, pDst
, alu
, prgnDst
, pptSrc
);
114 mfbDoBitbltXor (pSrc
, pDst
, alu
, prgnDst
, pptSrc
);
117 mfbDoBitbltCopyInverted (pSrc
, pDst
, alu
, prgnDst
, pptSrc
);
120 mfbDoBitbltOr (pSrc
, pDst
, alu
, prgnDst
, pptSrc
);
123 mfbDoBitbltGeneral (pSrc
, pDst
, alu
, prgnDst
, pptSrc
);
129 mfbCopyArea(pSrcDrawable
, pDstDrawable
,
130 pGC
, srcx
, srcy
, width
, height
, dstx
, dsty
)
131 register DrawablePtr pSrcDrawable
;
132 register DrawablePtr pDstDrawable
;
138 RegionPtr prgnSrcClip
= NULL
; /* may be a new region, or just a copy */
139 Bool freeSrcClip
= FALSE
;
141 RegionPtr prgnExposed
;
144 register DDXPointPtr ppt
;
145 register BoxPtr pbox
;
149 xRectangle origSource
;
150 DDXPointRec origDest
;
153 int fastClip
= 0; /* for fast clipping with pixmap source */
154 int fastExpose
= 0; /* for fast exposures with pixmap source */
155 void (*localDoBitBlt
)(
156 DrawablePtr
/*pSrc*/,
157 DrawablePtr
/*pDst*/,
159 RegionPtr
/*prgnDst*/,
160 DDXPointPtr
/*pptSrc*/);
164 origSource
.width
= width
;
165 origSource
.height
= height
;
169 if ((pSrcDrawable
!= pDstDrawable
) &&
170 pSrcDrawable
->pScreen
->SourceValidate
)
172 (*pSrcDrawable
->pScreen
->SourceValidate
) (pSrcDrawable
, srcx
, srcy
, width
, height
);
177 localDoBitBlt
= mfbDoBitbltCopy
;
180 localDoBitBlt
= mfbDoBitbltCopyInverted
;
183 localDoBitBlt
= mfbDoBitbltXor
;
186 localDoBitBlt
= mfbDoBitbltOr
;
189 localDoBitBlt
= mfbDoBitbltGeneral
;
193 srcx
+= pSrcDrawable
->x
;
194 srcy
+= pSrcDrawable
->y
;
196 /* clip the source */
198 if (pSrcDrawable
->type
== DRAWABLE_PIXMAP
)
200 if ((pSrcDrawable
== pDstDrawable
) &&
201 (pGC
->clientClipType
== CT_NONE
))
203 prgnSrcClip
= pGC
->pCompositeClip
;
212 if (pGC
->subWindowMode
== IncludeInferiors
)
214 if (!((WindowPtr
) pSrcDrawable
)->parent
)
217 * special case bitblt from root window in
218 * IncludeInferiors mode; just like from a pixmap
222 else if ((pSrcDrawable
== pDstDrawable
) &&
223 (pGC
->clientClipType
== CT_NONE
))
225 prgnSrcClip
= pGC
->pCompositeClip
;
229 prgnSrcClip
= NotClippedByChildren((WindowPtr
)pSrcDrawable
);
235 prgnSrcClip
= &((WindowPtr
)pSrcDrawable
)->clipList
;
241 fastBox
.x2
= srcx
+ width
;
242 fastBox
.y2
= srcy
+ height
;
244 /* Don't create a source region if we are doing a fast clip */
249 * clip the source; if regions extend beyond the source size,
250 * make sure exposure events get sent
252 if (fastBox
.x1
< pSrcDrawable
->x
)
254 fastBox
.x1
= pSrcDrawable
->x
;
257 if (fastBox
.y1
< pSrcDrawable
->y
)
259 fastBox
.y1
= pSrcDrawable
->y
;
262 if (fastBox
.x2
> pSrcDrawable
->x
+ (int) pSrcDrawable
->width
)
264 fastBox
.x2
= pSrcDrawable
->x
+ (int) pSrcDrawable
->width
;
267 if (fastBox
.y2
> pSrcDrawable
->y
+ (int) pSrcDrawable
->height
)
269 fastBox
.y2
= pSrcDrawable
->y
+ (int) pSrcDrawable
->height
;
275 REGION_INIT(pGC
->pScreen
, &rgnDst
, &fastBox
, 1);
276 REGION_INTERSECT(pGC
->pScreen
, &rgnDst
, &rgnDst
, prgnSrcClip
);
279 dstx
+= pDstDrawable
->x
;
280 dsty
+= pDstDrawable
->y
;
282 if (pDstDrawable
->type
== DRAWABLE_WINDOW
)
284 if (!((WindowPtr
)pDstDrawable
)->realized
)
287 REGION_UNINIT(pGC
->pScreen
, &rgnDst
);
289 REGION_DESTROY(pGC
->pScreen
, prgnSrcClip
);
297 /* Translate and clip the dst to the destination composite clip */
302 /* Translate the region directly */
308 /* If the destination composite clip is one rectangle we can
309 do the clip directly. Otherwise we have to create a full
310 blown region and call intersect */
311 cclip
= pGC
->pCompositeClip
;
312 if (REGION_NUM_RECTS(cclip
) == 1)
314 BoxPtr pBox
= REGION_RECTS(cclip
);
316 if (fastBox
.x1
< pBox
->x1
) fastBox
.x1
= pBox
->x1
;
317 if (fastBox
.x2
> pBox
->x2
) fastBox
.x2
= pBox
->x2
;
318 if (fastBox
.y1
< pBox
->y1
) fastBox
.y1
= pBox
->y1
;
319 if (fastBox
.y2
> pBox
->y2
) fastBox
.y2
= pBox
->y2
;
321 /* Check to see if the region is empty */
322 if (fastBox
.x1
>= fastBox
.x2
|| fastBox
.y1
>= fastBox
.y2
)
324 REGION_NULL(pGC
->pScreen
, &rgnDst
);
328 REGION_INIT(pGC
->pScreen
, &rgnDst
, &fastBox
, 1);
333 /* We must turn off fastClip now, since we must create
334 a full blown region. It is intersected with the
335 composite clip below. */
337 REGION_INIT(pGC
->pScreen
, &rgnDst
, &fastBox
, 1);
342 REGION_TRANSLATE(pGC
->pScreen
, &rgnDst
, -dx
, -dy
);
347 REGION_INTERSECT(pGC
->pScreen
, &rgnDst
, &rgnDst
, pGC
->pCompositeClip
);
350 /* Do bit blitting */
351 numRects
= REGION_NUM_RECTS(&rgnDst
);
352 if (numRects
&& width
&& height
)
354 if(!(pptSrc
= (DDXPointPtr
)ALLOCATE_LOCAL(numRects
*
355 sizeof(DDXPointRec
))))
357 REGION_UNINIT(pGC
->pScreen
, &rgnDst
);
359 REGION_DESTROY(pGC
->pScreen
, prgnSrcClip
);
362 pbox
= REGION_RECTS(&rgnDst
);
364 for (i
= numRects
; --i
>= 0; pbox
++, ppt
++)
366 ppt
->x
= pbox
->x1
+ dx
;
367 ppt
->y
= pbox
->y1
+ dy
;
370 if (pGC
->planemask
& 1)
371 (*localDoBitBlt
) (pSrcDrawable
, pDstDrawable
, pGC
->alu
, &rgnDst
, pptSrc
);
373 DEALLOCATE_LOCAL(pptSrc
);
379 /* Pixmap sources generate a NoExposed (we return NULL to do this) */
382 miHandleExposures(pSrcDrawable
, pDstDrawable
, pGC
,
383 origSource
.x
, origSource
.y
,
384 (int)origSource
.width
,
385 (int)origSource
.height
,
386 origDest
.x
, origDest
.y
, (unsigned long)0);
388 REGION_UNINIT(pGC
->pScreen
, &rgnDst
);
390 REGION_DESTROY(pGC
->pScreen
, prgnSrcClip
);
396 * Devices which use mfb for 1-bit pixmap support
397 * must register a function for n-to-1 copy operations
400 static unsigned long copyPlaneGeneration
;
401 static int copyPlaneScreenIndex
= -1;
404 mfbRegisterCopyPlaneProc (pScreen
, proc
)
407 DrawablePtr
/* pSrcDrawable */,
408 DrawablePtr
/* pDstDrawable */,
416 unsigned long /* bitPlane */);
418 if (copyPlaneGeneration
!= serverGeneration
)
420 copyPlaneScreenIndex
= AllocateScreenPrivateIndex();
421 if (copyPlaneScreenIndex
< 0)
423 copyPlaneGeneration
= serverGeneration
;
425 pScreen
->devPrivates
[copyPlaneScreenIndex
].fptr
= proc
;
430 if fg == 1 and bg ==0, we can do an ordinary CopyArea.
431 if fg == bg, we can do a CopyArea with alu = mfbReduceRop(alu, fg)
432 if fg == 0 and bg == 1, we use the same rasterop, with
433 source operand inverted.
435 CopyArea deals with all of the graphics exposure events.
436 This code depends on knowing that we can change the
437 alu in the GC without having to call ValidateGC() before calling
444 mfbCopyPlane(pSrcDrawable
, pDstDrawable
,
445 pGC
, srcx
, srcy
, width
, height
, dstx
, dsty
, plane
)
446 DrawablePtr pSrcDrawable
, pDstDrawable
;
454 RegionPtr prgnExposed
;
455 RegionPtr (*copyPlane
)(
456 DrawablePtr
/* pSrcDrawable */,
457 DrawablePtr
/* pDstDrawable */,
465 unsigned long /* bitPlane */);
468 if (pSrcDrawable
->depth
!= 1)
470 if (copyPlaneScreenIndex
>= 0 &&
472 pSrcDrawable
->pScreen
->devPrivates
[copyPlaneScreenIndex
].fptr
)
475 return (*copyPlane
) (pSrcDrawable
, pDstDrawable
,
476 pGC
, srcx
, srcy
, width
, height
, dstx
, dsty
, plane
);
480 FatalError ("No copyPlane proc registered for depth %d\n",
481 pSrcDrawable
->depth
);
487 if ((pGC
->fgPixel
& 1) == 1 && (pGC
->bgPixel
& 1) == 0)
489 prgnExposed
= (*pGC
->ops
->CopyArea
)(pSrcDrawable
, pDstDrawable
,
490 pGC
, srcx
, srcy
, width
, height
, dstx
, dsty
);
492 else if ((pGC
->fgPixel
& 1) == (pGC
->bgPixel
& 1))
495 pGC
->alu
= mfbReduceRop(pGC
->alu
, pGC
->fgPixel
);
496 prgnExposed
= (*pGC
->ops
->CopyArea
)(pSrcDrawable
, pDstDrawable
,
497 pGC
, srcx
, srcy
, width
, height
, dstx
, dsty
);
500 else /* need to invert the src */
503 pGC
->alu
= InverseAlu
[alu
];
504 prgnExposed
= (*pGC
->ops
->CopyArea
)(pSrcDrawable
, pDstDrawable
,
505 pGC
, srcx
, srcy
, width
, height
, dstx
, dsty
);