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
= calloc(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
);
353 .u
.noExposure
.drawable
= drawable
,
354 .u
.noExposure
.majorEvent
= major
,
355 .u
.noExposure
.minorEvent
= minor
357 event
.u
.u
.type
= NoExpose
;
358 WriteEventsToClient(client
, 1, &event
);
363 miSendExposures(WindowPtr pWin
, RegionPtr pRgn
, int dx
, int dy
)
370 pBox
= RegionRects(pRgn
);
371 numRects
= RegionNumRects(pRgn
);
372 if (!(pEvent
= calloc(1, numRects
* sizeof(xEvent
))))
375 for (i
= numRects
, pe
= pEvent
; --i
>= 0; pe
++, pBox
++) {
376 pe
->u
.u
.type
= Expose
;
377 pe
->u
.expose
.window
= pWin
->drawable
.id
;
378 pe
->u
.expose
.x
= pBox
->x1
- dx
;
379 pe
->u
.expose
.y
= pBox
->y1
- dy
;
380 pe
->u
.expose
.width
= pBox
->x2
- pBox
->x1
;
381 pe
->u
.expose
.height
= pBox
->y2
- pBox
->y1
;
382 pe
->u
.expose
.count
= i
;
386 if (!noPanoramiXExtension
) {
387 int scrnum
= pWin
->drawable
.pScreen
->myNum
;
392 x
= screenInfo
.screens
[scrnum
]->x
;
393 y
= screenInfo
.screens
[scrnum
]->y
;
394 pWin
= screenInfo
.screens
[0]->root
;
395 realWin
= pWin
->drawable
.id
;
400 win
= PanoramiXFindIDByScrnum(XRT_WINDOW
,
401 pWin
->drawable
.id
, scrnum
);
406 realWin
= win
->info
[0].id
;
407 dixLookupWindow(&pWin
, realWin
, serverClient
, DixSendAccess
);
409 if (x
|| y
|| scrnum
)
410 for (i
= 0; i
< numRects
; i
++) {
411 pEvent
[i
].u
.expose
.window
= realWin
;
412 pEvent
[i
].u
.expose
.x
+= x
;
413 pEvent
[i
].u
.expose
.y
+= y
;
418 DeliverEvents(pWin
, pEvent
, numRects
, NullWindow
);
424 miWindowExposures(WindowPtr pWin
, RegionPtr prgn
, RegionPtr other_exposed
)
426 RegionPtr exposures
= prgn
;
428 if ((prgn
&& !RegionNil(prgn
)) ||
429 (exposures
&& !RegionNil(exposures
)) || other_exposed
) {
431 int clientInterested
;
434 * Restore from backing-store FIRST.
437 (pWin
->eventMask
| wOtherEventMasks(pWin
)) & ExposureMask
;
440 RegionUnion(other_exposed
, exposures
, other_exposed
);
441 if (exposures
!= prgn
)
442 RegionDestroy(exposures
);
444 exposures
= other_exposed
;
446 if (clientInterested
&& exposures
&&
447 (RegionNumRects(exposures
) > RECTLIMIT
)) {
449 * If we have LOTS of rectangles, we decide to take the extents
450 * and force an exposure on that. This should require much less
451 * work overall, on both client and server. This is cheating, but
452 * isn't prohibited by the protocol ("spontaneous combustion" :-).
456 box
= *RegionExtents(exposures
);
457 if (exposures
== prgn
) {
459 RegionInit(exposures
, &box
, 1);
460 RegionReset(prgn
, &box
);
463 RegionReset(exposures
, &box
);
464 RegionUnion(prgn
, prgn
, exposures
);
466 /* miPaintWindow doesn't clip, so we have to */
467 RegionIntersect(prgn
, prgn
, &pWin
->clipList
);
469 if (prgn
&& !RegionNil(prgn
))
470 miPaintWindow(pWin
, prgn
, PW_BACKGROUND
);
471 if (clientInterested
&& exposures
&& !RegionNil(exposures
))
472 miSendExposures(pWin
, exposures
,
473 pWin
->drawable
.x
, pWin
->drawable
.y
);
474 if (exposures
== &expRec
) {
475 RegionUninit(exposures
);
477 else if (exposures
&& exposures
!= prgn
&& exposures
!= other_exposed
)
478 RegionDestroy(exposures
);
482 else if (exposures
&& exposures
!= prgn
)
483 RegionDestroy(exposures
);
487 /* Ugly, ugly, but we lost our hooks into miPaintWindow... =/ */
488 void RootlessSetPixmapOfAncestors(WindowPtr pWin
);
489 void RootlessStartDrawing(WindowPtr pWin
);
490 void RootlessDamageRegion(WindowPtr pWin
, RegionPtr prgn
);
491 Bool
IsFramedWindow(WindowPtr pWin
);
495 miPaintWindow(WindowPtr pWin
, RegionPtr prgn
, int what
)
497 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
498 ChangeGCVal gcval
[6];
507 * Distance from screen to destination drawable, use this
508 * to adjust rendering coordinates which come in in screen space
510 int draw_x_off
, draw_y_off
;
513 * Tile offset for drawing; these need to align the tile
514 * to the appropriate window origin
516 int tile_x_off
, tile_y_off
;
519 DrawablePtr drawable
= &pWin
->drawable
;
522 if (!drawable
|| drawable
->type
== UNDRAWABLE_WINDOW
)
525 if (IsFramedWindow(pWin
)) {
526 RootlessStartDrawing(pWin
);
527 RootlessDamageRegion(pWin
, prgn
);
529 if (pWin
->backgroundState
== ParentRelative
) {
530 if ((what
== PW_BACKGROUND
) ||
531 (what
== PW_BORDER
&& !pWin
->borderIsPixel
))
532 RootlessSetPixmapOfAncestors(pWin
);
537 if (what
== PW_BACKGROUND
) {
538 while (pWin
->backgroundState
== ParentRelative
)
541 draw_x_off
= drawable
->x
;
542 draw_y_off
= drawable
->y
;
544 tile_x_off
= pWin
->drawable
.x
- draw_x_off
;
545 tile_y_off
= pWin
->drawable
.y
- draw_y_off
;
546 fill
= pWin
->background
;
548 if (pWin
->inhibitBGPaint
)
551 switch (pWin
->backgroundState
) {
554 case BackgroundPixmap
:
562 tile_x_off
= drawable
->x
;
563 tile_y_off
= drawable
->y
;
565 /* servers without pixmaps draw their own borders */
566 if (!pScreen
->GetWindowPixmap
)
568 pixmap
= (*pScreen
->GetWindowPixmap
) ((WindowPtr
) drawable
);
569 drawable
= &pixmap
->drawable
;
571 draw_x_off
= pixmap
->screen_x
;
572 draw_y_off
= pixmap
->screen_y
;
573 tile_x_off
-= draw_x_off
;
574 tile_y_off
-= draw_y_off
;
580 solid
= pWin
->borderIsPixel
;
583 gcval
[0].val
= GXcopy
;
586 #ifdef ROOTLESS_SAFEALPHA
587 /* Bit mask for alpha channel with a particular number of bits per
588 * pixel. Note that we only care for 32bpp data. Mac OS X uses planar
591 #define RootlessAlphaMask(bpp) ((bpp) == 32 ? 0xFF000000 : 0)
595 #ifdef ROOTLESS_SAFEALPHA
597 fill
.pixel
| RootlessAlphaMask(pWin
->drawable
.bitsPerPixel
);
599 gcval
[1].val
= fill
.pixel
;
601 gcval
[2].val
= FillSolid
;
602 gcmask
|= GCForeground
| GCFillStyle
;
607 #ifdef ROOTLESS_SAFEALPHA
609 ((CARD32
) -1) & ~RootlessAlphaMask(pWin
->drawable
.bitsPerPixel
);
610 gcmask
|= GCPlaneMask
;
612 gcval
[c
++].val
= FillTiled
;
613 gcval
[c
++].ptr
= (pointer
) fill
.pixmap
;
614 gcval
[c
++].val
= tile_x_off
;
615 gcval
[c
++].val
= tile_y_off
;
616 gcmask
|= GCFillStyle
| GCTile
| GCTileStipXOrigin
| GCTileStipYOrigin
;
619 prect
= malloc(RegionNumRects(prgn
) * sizeof(xRectangle
));
623 pGC
= GetScratchGC(drawable
->depth
, drawable
->pScreen
);
629 ChangeGC(NullClient
, pGC
, gcmask
, gcval
);
630 ValidateGC(drawable
, pGC
);
632 numRects
= RegionNumRects(prgn
);
633 pbox
= RegionRects(prgn
);
634 for (i
= numRects
; --i
>= 0; pbox
++, prect
++) {
635 prect
->x
= pbox
->x1
- draw_x_off
;
636 prect
->y
= pbox
->y1
- draw_y_off
;
637 prect
->width
= pbox
->x2
- pbox
->x1
;
638 prect
->height
= pbox
->y2
- pbox
->y1
;
641 (*pGC
->ops
->PolyFillRect
) (drawable
, pGC
, numRects
, prect
);
647 /* MICLEARDRAWABLE -- sets the entire drawable to the background color of
648 * the GC. Useful when we have a scratch drawable and need to initialize
651 miClearDrawable(DrawablePtr pDraw
, GCPtr pGC
)
656 fg
.val
= pGC
->fgPixel
;
657 bg
.val
= pGC
->bgPixel
;
660 rect
.width
= pDraw
->width
;
661 rect
.height
= pDraw
->height
;
662 ChangeGC(NullClient
, pGC
, GCForeground
, &bg
);
663 ValidateGC(pDraw
, pGC
);
664 (*pGC
->ops
->PolyFillRect
) (pDraw
, pGC
, 1, &rect
);
665 ChangeGC(NullClient
, pGC
, GCForeground
, &fg
);
666 ValidateGC(pDraw
, pGC
);