1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ******************************************************************/
46 /*****************************************************************
48 Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
50 Permission is hereby granted, free of charge, to any person obtaining a copy
51 of this software and associated documentation files (the "Software"), to deal
52 in the Software without restriction, including without limitation the rights
53 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
54 copies of the Software.
56 The above copyright notice and this permission notice shall be included in
57 all copies or substantial portions of the Software.
59 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
62 DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
63 BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
64 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
65 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67 Except as contained in this notice, the name of Digital Equipment Corporation
68 shall not be used in advertising or otherwise to promote the sale, use or other
69 dealings in this Software without prior written authorization from Digital
70 Equipment Corporation.
72 ******************************************************************/
74 #ifdef HAVE_DIX_CONFIG_H
75 #include <dix-config.h>
79 #include <X11/Xproto.h>
80 #include <X11/Xprotostr.h>
83 #include "regionstr.h"
84 #include "scrnintstr.h"
86 #include "windowstr.h"
90 #include "dixstruct.h"
97 #include "panoramiX.h"
98 #include "panoramiXsrv.h"
102 machine-independent graphics exposure code. any device that uses
103 the region package can call this.
107 #define RECTLIMIT 25 /* pick a number, any number > 8 */
111 generate a region for exposures for areas that were copied from obscured or
112 non-existent areas to non-obscured areas of the destination. Paint the
113 background for the region, if the destination is a window.
116 this should generally be called, even if graphicsExposures is false,
117 because this is where bits get recovered from backing store.
120 added argument 'plane' is used to indicate how exposures from backing
121 store should be accomplished. If plane is 0 (i.e. no bit plane), CopyArea
122 should be used, else a CopyPlane of the indicated plane will be used. The
123 exposing is done by the backing store's GraphicsExpose function, of course.
128 miHandleExposures(DrawablePtr pSrcDrawable
, DrawablePtr pDstDrawable
,
129 GCPtr pGC
, int srcx
, int srcy
, int width
, int height
,
130 int dstx
, int dsty
, unsigned long plane
)
132 RegionPtr prgnSrcClip
; /* drawable-relative source clip */
134 RegionPtr prgnDstClip
; /* drawable-relative dest clip */
136 BoxRec srcBox
; /* unclipped source */
137 RegionRec rgnExposed
; /* exposed region, calculated source-
138 relative, made dst relative to
139 intersect with visible parts of
140 dest and send events to client,
141 and then screen relative to paint
142 the window background
148 /* avoid work if we can */
149 if (!pGC
->graphicsExposures
&&
150 (pDstDrawable
->type
== DRAWABLE_PIXMAP
) &&
151 ((pSrcDrawable
->type
== DRAWABLE_PIXMAP
) ||
152 (((WindowPtr
) pSrcDrawable
)->backStorage
== NULL
)))
157 srcBox
.x2
= srcx
+ width
;
158 srcBox
.y2
= srcy
+ height
;
160 if (pSrcDrawable
->type
!= DRAWABLE_PIXMAP
) {
163 TsrcBox
.x1
= srcx
+ pSrcDrawable
->x
;
164 TsrcBox
.y1
= srcy
+ pSrcDrawable
->y
;
165 TsrcBox
.x2
= TsrcBox
.x1
+ width
;
166 TsrcBox
.y2
= TsrcBox
.y1
+ height
;
167 pSrcWin
= (WindowPtr
) pSrcDrawable
;
168 if (pGC
->subWindowMode
== IncludeInferiors
) {
169 prgnSrcClip
= NotClippedByChildren(pSrcWin
);
170 if ((RegionContainsRect(prgnSrcClip
, &TsrcBox
)) == rgnIN
) {
171 RegionDestroy(prgnSrcClip
);
176 if ((RegionContainsRect(&pSrcWin
->clipList
, &TsrcBox
)) == rgnIN
)
178 prgnSrcClip
= &rgnSrcRec
;
179 RegionNull(prgnSrcClip
);
180 RegionCopy(prgnSrcClip
, &pSrcWin
->clipList
);
182 RegionTranslate(prgnSrcClip
, -pSrcDrawable
->x
, -pSrcDrawable
->y
);
187 if ((srcBox
.x1
>= 0) && (srcBox
.y1
>= 0) &&
188 (srcBox
.x2
<= pSrcDrawable
->width
) &&
189 (srcBox
.y2
<= pSrcDrawable
->height
))
194 box
.x2
= pSrcDrawable
->width
;
195 box
.y2
= pSrcDrawable
->height
;
196 prgnSrcClip
= &rgnSrcRec
;
197 RegionInit(prgnSrcClip
, &box
, 1);
201 if (pDstDrawable
== pSrcDrawable
) {
202 prgnDstClip
= prgnSrcClip
;
204 else if (pDstDrawable
->type
!= DRAWABLE_PIXMAP
) {
205 if (pGC
->subWindowMode
== IncludeInferiors
) {
206 prgnDstClip
= NotClippedByChildren((WindowPtr
) pDstDrawable
);
209 prgnDstClip
= &rgnDstRec
;
210 RegionNull(prgnDstClip
);
211 RegionCopy(prgnDstClip
, &((WindowPtr
) pDstDrawable
)->clipList
);
213 RegionTranslate(prgnDstClip
, -pDstDrawable
->x
, -pDstDrawable
->y
);
220 box
.x2
= pDstDrawable
->width
;
221 box
.y2
= pDstDrawable
->height
;
222 prgnDstClip
= &rgnDstRec
;
223 RegionInit(prgnDstClip
, &box
, 1);
226 /* drawable-relative source region */
227 RegionInit(&rgnExposed
, &srcBox
, 1);
229 /* now get the hidden parts of the source box */
230 RegionSubtract(&rgnExposed
, &rgnExposed
, prgnSrcClip
);
232 /* move them over the destination */
233 RegionTranslate(&rgnExposed
, dstx
- srcx
, dsty
- srcy
);
235 /* intersect with visible areas of dest */
236 RegionIntersect(&rgnExposed
, &rgnExposed
, prgnDstClip
);
238 /* intersect with client clip region. */
239 if (pGC
->clientClipType
== CT_REGION
)
240 RegionIntersect(&rgnExposed
, &rgnExposed
, pGC
->clientClip
);
243 * If we have LOTS of rectangles, we decide to take the extents
244 * and force an exposure on that. This should require much less
245 * work overall, on both client and server. This is cheating, but
246 * isn't prohibited by the protocol ("spontaneous combustion" :-)
249 extents
= pGC
->graphicsExposures
&&
250 (RegionNumRects(&rgnExposed
) > RECTLIMIT
) &&
251 (pDstDrawable
->type
!= DRAWABLE_PIXMAP
);
255 if (!(region
= wClipShape(pSrcWin
)))
256 region
= wBoundingShape(pSrcWin
);
258 * If you try to CopyArea the extents of a shaped window, compacting the
259 * exposed region will undo all our work!
261 if (extents
&& pSrcWin
&& region
&&
262 (RegionContainsRect(region
, &srcBox
) != rgnIN
))
266 expBox
= *RegionExtents(&rgnExposed
);
267 RegionReset(&rgnExposed
, &expBox
);
269 if ((pDstDrawable
->type
!= DRAWABLE_PIXMAP
) &&
270 (((WindowPtr
) pDstDrawable
)->backgroundState
!= None
)) {
271 WindowPtr pWin
= (WindowPtr
) pDstDrawable
;
273 /* make the exposed area screen-relative */
274 RegionTranslate(&rgnExposed
, pDstDrawable
->x
, pDstDrawable
->y
);
277 /* miPaintWindow doesn't clip, so we have to */
278 RegionIntersect(&rgnExposed
, &rgnExposed
, &pWin
->clipList
);
280 miPaintWindow((WindowPtr
) pDstDrawable
, &rgnExposed
, PW_BACKGROUND
);
283 RegionReset(&rgnExposed
, &expBox
);
286 RegionTranslate(&rgnExposed
, -pDstDrawable
->x
, -pDstDrawable
->y
);
288 if (prgnDstClip
== &rgnDstRec
) {
289 RegionUninit(prgnDstClip
);
291 else if (prgnDstClip
!= prgnSrcClip
) {
292 RegionDestroy(prgnDstClip
);
295 if (prgnSrcClip
== &rgnSrcRec
) {
296 RegionUninit(prgnSrcClip
);
299 RegionDestroy(prgnSrcClip
);
302 if (pGC
->graphicsExposures
) {
304 RegionPtr exposed
= RegionCreate(NullBox
, 0);
306 *exposed
= rgnExposed
;
310 RegionUninit(&rgnExposed
);
315 /* send GraphicsExpose events, or a NoExpose event, based on the region */
318 miSendGraphicsExpose(ClientPtr client
, RegionPtr pRgn
, XID drawable
,
319 int major
, int minor
)
321 if (pRgn
&& !RegionNil(pRgn
)) {
328 numRects
= RegionNumRects(pRgn
);
329 pBox
= RegionRects(pRgn
);
330 if (!(pEvent
= malloc(numRects
* sizeof(xEvent
))))
334 for (i
= 1; i
<= numRects
; i
++, pe
++, pBox
++) {
335 pe
->u
.u
.type
= GraphicsExpose
;
336 pe
->u
.graphicsExposure
.drawable
= drawable
;
337 pe
->u
.graphicsExposure
.x
= pBox
->x1
;
338 pe
->u
.graphicsExposure
.y
= pBox
->y1
;
339 pe
->u
.graphicsExposure
.width
= pBox
->x2
- pBox
->x1
;
340 pe
->u
.graphicsExposure
.height
= pBox
->y2
- pBox
->y1
;
341 pe
->u
.graphicsExposure
.count
= numRects
- i
;
342 pe
->u
.graphicsExposure
.majorEvent
= major
;
343 pe
->u
.graphicsExposure
.minorEvent
= minor
;
345 /* GraphicsExpose is a "critical event", which TryClientEvents
346 * handles specially. */
347 TryClientEvents(client
, NULL
, pEvent
, numRects
,
348 (Mask
) 0, NoEventMask
, NullGrab
);
354 memset(&event
, 0, sizeof(xEvent
));
355 event
.u
.u
.type
= NoExpose
;
356 event
.u
.noExposure
.drawable
= drawable
;
357 event
.u
.noExposure
.majorEvent
= major
;
358 event
.u
.noExposure
.minorEvent
= minor
;
359 WriteEventsToClient(client
, 1, &event
);
364 miSendExposures(WindowPtr pWin
, RegionPtr pRgn
, int dx
, int dy
)
371 pBox
= RegionRects(pRgn
);
372 numRects
= RegionNumRects(pRgn
);
373 if (!(pEvent
= calloc(1, numRects
* sizeof(xEvent
))))
376 for (i
= numRects
, pe
= pEvent
; --i
>= 0; pe
++, pBox
++) {
377 pe
->u
.u
.type
= Expose
;
378 pe
->u
.expose
.window
= pWin
->drawable
.id
;
379 pe
->u
.expose
.x
= pBox
->x1
- dx
;
380 pe
->u
.expose
.y
= pBox
->y1
- dy
;
381 pe
->u
.expose
.width
= pBox
->x2
- pBox
->x1
;
382 pe
->u
.expose
.height
= pBox
->y2
- pBox
->y1
;
383 pe
->u
.expose
.count
= i
;
387 if (!noPanoramiXExtension
) {
388 int scrnum
= pWin
->drawable
.pScreen
->myNum
;
393 x
= screenInfo
.screens
[scrnum
]->x
;
394 y
= screenInfo
.screens
[scrnum
]->y
;
395 pWin
= screenInfo
.screens
[0]->root
;
396 realWin
= pWin
->drawable
.id
;
401 win
= PanoramiXFindIDByScrnum(XRT_WINDOW
,
402 pWin
->drawable
.id
, scrnum
);
407 realWin
= win
->info
[0].id
;
408 dixLookupWindow(&pWin
, realWin
, serverClient
, DixSendAccess
);
410 if (x
|| y
|| scrnum
)
411 for (i
= 0; i
< numRects
; i
++) {
412 pEvent
[i
].u
.expose
.window
= realWin
;
413 pEvent
[i
].u
.expose
.x
+= x
;
414 pEvent
[i
].u
.expose
.y
+= y
;
419 DeliverEvents(pWin
, pEvent
, numRects
, NullWindow
);
425 miWindowExposures(WindowPtr pWin
, RegionPtr prgn
, RegionPtr other_exposed
)
427 RegionPtr exposures
= prgn
;
429 if ((prgn
&& !RegionNil(prgn
)) ||
430 (exposures
&& !RegionNil(exposures
)) || other_exposed
) {
432 int clientInterested
;
435 * Restore from backing-store FIRST.
438 (pWin
->eventMask
| wOtherEventMasks(pWin
)) & ExposureMask
;
441 RegionUnion(other_exposed
, exposures
, other_exposed
);
442 if (exposures
!= prgn
)
443 RegionDestroy(exposures
);
445 exposures
= other_exposed
;
447 if (clientInterested
&& exposures
&&
448 (RegionNumRects(exposures
) > RECTLIMIT
)) {
450 * If we have LOTS of rectangles, we decide to take the extents
451 * and force an exposure on that. This should require much less
452 * work overall, on both client and server. This is cheating, but
453 * isn't prohibited by the protocol ("spontaneous combustion" :-).
457 box
= *RegionExtents(exposures
);
458 if (exposures
== prgn
) {
460 RegionInit(exposures
, &box
, 1);
461 RegionReset(prgn
, &box
);
464 RegionReset(exposures
, &box
);
465 RegionUnion(prgn
, prgn
, exposures
);
467 /* miPaintWindow doesn't clip, so we have to */
468 RegionIntersect(prgn
, prgn
, &pWin
->clipList
);
470 if (prgn
&& !RegionNil(prgn
))
471 miPaintWindow(pWin
, prgn
, PW_BACKGROUND
);
472 if (clientInterested
&& exposures
&& !RegionNil(exposures
))
473 miSendExposures(pWin
, exposures
,
474 pWin
->drawable
.x
, pWin
->drawable
.y
);
475 if (exposures
== &expRec
) {
476 RegionUninit(exposures
);
478 else if (exposures
&& exposures
!= prgn
&& exposures
!= other_exposed
)
479 RegionDestroy(exposures
);
483 else if (exposures
&& exposures
!= prgn
)
484 RegionDestroy(exposures
);
488 /* Ugly, ugly, but we lost our hooks into miPaintWindow... =/ */
489 void RootlessSetPixmapOfAncestors(WindowPtr pWin
);
490 void RootlessStartDrawing(WindowPtr pWin
);
491 void RootlessDamageRegion(WindowPtr pWin
, RegionPtr prgn
);
492 Bool
IsFramedWindow(WindowPtr pWin
);
496 miPaintWindow(WindowPtr pWin
, RegionPtr prgn
, int what
)
498 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
499 ChangeGCVal gcval
[6];
508 * Distance from screen to destination drawable, use this
509 * to adjust rendering coordinates which come in in screen space
511 int draw_x_off
, draw_y_off
;
514 * Tile offset for drawing; these need to align the tile
515 * to the appropriate window origin
517 int tile_x_off
, tile_y_off
;
520 DrawablePtr drawable
= &pWin
->drawable
;
523 if (!drawable
|| drawable
->type
== UNDRAWABLE_WINDOW
)
526 if (IsFramedWindow(pWin
)) {
527 RootlessStartDrawing(pWin
);
528 RootlessDamageRegion(pWin
, prgn
);
530 if (pWin
->backgroundState
== ParentRelative
) {
531 if ((what
== PW_BACKGROUND
) ||
532 (what
== PW_BORDER
&& !pWin
->borderIsPixel
))
533 RootlessSetPixmapOfAncestors(pWin
);
538 if (what
== PW_BACKGROUND
) {
539 while (pWin
->backgroundState
== ParentRelative
)
542 draw_x_off
= drawable
->x
;
543 draw_y_off
= drawable
->y
;
545 tile_x_off
= pWin
->drawable
.x
- draw_x_off
;
546 tile_y_off
= pWin
->drawable
.y
- draw_y_off
;
547 fill
= pWin
->background
;
549 if (pWin
->inhibitBGPaint
)
552 switch (pWin
->backgroundState
) {
555 case BackgroundPixmap
:
563 tile_x_off
= drawable
->x
;
564 tile_y_off
= drawable
->y
;
566 /* servers without pixmaps draw their own borders */
567 if (!pScreen
->GetWindowPixmap
)
569 pixmap
= (*pScreen
->GetWindowPixmap
) ((WindowPtr
) drawable
);
570 drawable
= &pixmap
->drawable
;
572 draw_x_off
= pixmap
->screen_x
;
573 draw_y_off
= pixmap
->screen_y
;
574 tile_x_off
-= draw_x_off
;
575 tile_y_off
-= draw_y_off
;
581 solid
= pWin
->borderIsPixel
;
584 gcval
[0].val
= GXcopy
;
587 #ifdef ROOTLESS_SAFEALPHA
588 /* Bit mask for alpha channel with a particular number of bits per
589 * pixel. Note that we only care for 32bpp data. Mac OS X uses planar
592 #define RootlessAlphaMask(bpp) ((bpp) == 32 ? 0xFF000000 : 0)
596 #ifdef ROOTLESS_SAFEALPHA
598 fill
.pixel
| RootlessAlphaMask(pWin
->drawable
.bitsPerPixel
);
600 gcval
[1].val
= fill
.pixel
;
602 gcval
[2].val
= FillSolid
;
603 gcmask
|= GCForeground
| GCFillStyle
;
608 #ifdef ROOTLESS_SAFEALPHA
610 ((CARD32
) -1) & ~RootlessAlphaMask(pWin
->drawable
.bitsPerPixel
);
611 gcmask
|= GCPlaneMask
;
613 gcval
[c
++].val
= FillTiled
;
614 gcval
[c
++].ptr
= (pointer
) fill
.pixmap
;
615 gcval
[c
++].val
= tile_x_off
;
616 gcval
[c
++].val
= tile_y_off
;
617 gcmask
|= GCFillStyle
| GCTile
| GCTileStipXOrigin
| GCTileStipYOrigin
;
620 prect
= malloc(RegionNumRects(prgn
) * sizeof(xRectangle
));
624 pGC
= GetScratchGC(drawable
->depth
, drawable
->pScreen
);
630 ChangeGC(NullClient
, pGC
, gcmask
, gcval
);
631 ValidateGC(drawable
, pGC
);
633 numRects
= RegionNumRects(prgn
);
634 pbox
= RegionRects(prgn
);
635 for (i
= numRects
; --i
>= 0; pbox
++, prect
++) {
636 prect
->x
= pbox
->x1
- draw_x_off
;
637 prect
->y
= pbox
->y1
- draw_y_off
;
638 prect
->width
= pbox
->x2
- pbox
->x1
;
639 prect
->height
= pbox
->y2
- pbox
->y1
;
642 (*pGC
->ops
->PolyFillRect
) (drawable
, pGC
, numRects
, prect
);
648 /* MICLEARDRAWABLE -- sets the entire drawable to the background color of
649 * the GC. Useful when we have a scratch drawable and need to initialize
652 miClearDrawable(DrawablePtr pDraw
, GCPtr pGC
)
657 fg
.val
= pGC
->fgPixel
;
658 bg
.val
= pGC
->bgPixel
;
661 rect
.width
= pDraw
->width
;
662 rect
.height
= pDraw
->height
;
663 ChangeGC(NullClient
, pGC
, GCForeground
, &bg
);
664 ValidateGC(pDraw
, pGC
);
665 (*pGC
->ops
->PolyFillRect
) (pDraw
, pGC
, 1, &rect
);
666 ChangeGC(NullClient
, pGC
, GCForeground
, &fg
);
667 ValidateGC(pDraw
, pGC
);