CopyGC.c revision 1ab64890
1/* $Xorg: CopyGC.c,v 1.4 2001/02/09 02:03:32 xorgcvs Exp $ */
2/*
3
4Copyright 1986, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from The Open Group.
25
26*/
27/* $XFree86: xc/lib/X11/CopyGC.c,v 1.3 2001/01/17 19:41:33 dawes Exp $ */
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32#include "Xlibint.h"
33
34int
35XCopyGC (
36     register Display *dpy,
37     GC srcGC,
38     unsigned long mask,		/* which ones to set initially */
39     GC destGC)
40{
41    register XGCValues *destgv = &destGC->values,
42    		       *srcgv = &srcGC->values;
43    register xCopyGCReq *req;
44    register _XExtension *ext;
45
46    LockDisplay(dpy);
47
48    mask &= (1L << (GCLastBit + 1)) - 1;
49    /* if some of the source values to be copied are "dirty", flush them
50       out before sending the CopyGC request. */
51    if (srcGC->dirty & mask)
52         _XFlushGCCache(dpy, srcGC);
53
54    /* mark the copied values "not dirty" in the destination. */
55    destGC->dirty &= ~mask;
56
57    GetReq(CopyGC, req);
58    req->srcGC = srcGC->gid;
59    req->dstGC = destGC->gid;
60    req->mask = mask;
61
62    if (mask & GCFunction)
63    	destgv->function = srcgv->function;
64
65    if (mask & GCPlaneMask)
66        destgv->plane_mask = srcgv->plane_mask;
67
68    if (mask & GCForeground)
69        destgv->foreground = srcgv->foreground;
70
71    if (mask & GCBackground)
72        destgv->background = srcgv->background;
73
74    if (mask & GCLineWidth)
75        destgv->line_width = srcgv->line_width;
76
77    if (mask & GCLineStyle)
78        destgv->line_style = srcgv->line_style;
79
80    if (mask & GCCapStyle)
81        destgv->cap_style = srcgv->cap_style;
82
83    if (mask & GCJoinStyle)
84        destgv->join_style = srcgv->join_style;
85
86    if (mask & GCFillStyle)
87    	destgv->fill_style = srcgv->fill_style;
88
89    if (mask & GCFillRule)
90        destgv->fill_rule = srcgv->fill_rule;
91
92    if (mask & GCArcMode)
93        destgv->arc_mode = srcgv->arc_mode;
94
95    if (mask & GCTile)
96        destgv->tile = srcgv->tile;
97
98    if (mask & GCStipple)
99        destgv->stipple = srcgv->stipple;
100
101    if (mask & GCTileStipXOrigin)
102        destgv->ts_x_origin = srcgv->ts_x_origin;
103
104    if (mask & GCTileStipYOrigin)
105        destgv->ts_y_origin = srcgv->ts_y_origin;
106
107    if (mask & GCFont)
108        destgv->font = srcgv->font;
109
110    if (mask & GCSubwindowMode)
111        destgv->subwindow_mode = srcgv->subwindow_mode;
112
113    if (mask & GCGraphicsExposures)
114        destgv->graphics_exposures = srcgv->graphics_exposures;
115
116    if (mask & GCClipXOrigin)
117        destgv->clip_x_origin = srcgv->clip_x_origin;
118
119    if (mask & GCClipYOrigin)
120        destgv->clip_y_origin = srcgv->clip_y_origin;
121
122    if (mask & GCClipMask) {
123	destGC->rects = srcGC->rects;
124        destgv->clip_mask = srcgv->clip_mask;
125	}
126
127    if (mask & GCDashOffset)
128        destgv->dash_offset = srcgv->dash_offset;
129
130    if (mask & GCDashList) {
131	destGC->dashes = srcGC->dashes;
132        destgv->dashes = srcgv->dashes;
133	}
134    /* call out to any extensions interested */
135    for (ext = dpy->ext_procs; ext; ext = ext->next)
136	if (ext->copy_GC) (*ext->copy_GC)(dpy, destGC, &ext->codes);
137    UnlockDisplay(dpy);
138    SyncHandle();
139    return 1;
140    }
141