~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xnest/GC.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: GC.c,v 1.3 2000/08/17 19:53:28 cpqbld Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1993 by Davor Matic
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software
 
7
and its documentation for any purpose is hereby granted without fee,
 
8
provided that the above copyright notice appear in all copies and that
 
9
both that copyright notice and this permission notice appear in
 
10
supporting documentation.  Davor Matic makes no representations about
 
11
the suitability of this software for any purpose.  It is provided "as
 
12
is" without express or implied warranty.
 
13
 
 
14
*/
 
15
/* $XFree86: xc/programs/Xserver/hw/xnest/GC.c,v 3.6 2001/10/28 03:34:11 tsi Exp $ */
 
16
 
 
17
#ifdef HAVE_XNEST_CONFIG_H
 
18
#include <xnest-config.h>
 
19
#endif
 
20
 
 
21
#include <X11/X.h>
 
22
#include <X11/Xproto.h>
 
23
#include "gcstruct.h"
 
24
#include "windowstr.h"
 
25
#include "pixmapstr.h"
 
26
#include "scrnintstr.h"
 
27
#include <X11/fonts/fontstruct.h>
 
28
#include "mistruct.h"
 
29
#include "region.h"
 
30
 
 
31
#include "Xnest.h"
 
32
 
 
33
#include "Display.h"
 
34
#include "XNGC.h" 
 
35
#include "GCOps.h"
 
36
#include "Drawable.h"
 
37
#include "XNFont.h"
 
38
#include "Color.h"
 
39
 
 
40
int xnestGCPrivateIndex;
 
41
 
 
42
static GCFuncs xnestFuncs = {
 
43
  xnestValidateGC,
 
44
  xnestChangeGC,
 
45
  xnestCopyGC,
 
46
  xnestDestroyGC,
 
47
  xnestChangeClip,
 
48
  xnestDestroyClip,
 
49
  xnestCopyClip,
 
50
};
 
51
 
 
52
static GCOps xnestOps = {
 
53
  xnestFillSpans,
 
54
  xnestSetSpans,
 
55
  xnestPutImage,
 
56
  xnestCopyArea, 
 
57
  xnestCopyPlane,
 
58
  xnestPolyPoint,
 
59
  xnestPolylines,
 
60
  xnestPolySegment,
 
61
  xnestPolyRectangle,
 
62
  xnestPolyArc,
 
63
  xnestFillPolygon,
 
64
  xnestPolyFillRect,
 
65
  xnestPolyFillArc,
 
66
  xnestPolyText8, 
 
67
  xnestPolyText16,
 
68
  xnestImageText8,
 
69
  xnestImageText16,
 
70
  xnestImageGlyphBlt,
 
71
  xnestPolyGlyphBlt,
 
72
  xnestPushPixels
 
73
};
 
74
 
 
75
Bool
 
76
xnestCreateGC(GCPtr pGC)
 
77
{
 
78
  pGC->clientClipType = CT_NONE;
 
79
  pGC->clientClip = NULL;
 
80
  
 
81
  pGC->funcs = &xnestFuncs;
 
82
  pGC->ops = &xnestOps;
 
83
  
 
84
  pGC->miTranslate = 1;
 
85
   
 
86
  xnestGCPriv(pGC)->gc = XCreateGC(xnestDisplay, 
 
87
                                   xnestDefaultDrawables[pGC->depth], 
 
88
                                   0L, NULL);
 
89
  xnestGCPriv(pGC)->nClipRects = 0;
 
90
 
 
91
  return True;
 
92
}
 
93
 
 
94
void
 
95
xnestValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
 
96
{
 
97
  pGC->lastWinOrg.x = pDrawable->x;
 
98
  pGC->lastWinOrg.y = pDrawable->y;
 
99
}
 
100
 
 
101
void
 
102
xnestChangeGC(GCPtr pGC, unsigned long mask)
 
103
{
 
104
  XGCValues values;
 
105
  
 
106
  if (mask & GCFunction)
 
107
    values.function = pGC->alu;
 
108
  
 
109
  if (mask & GCPlaneMask)
 
110
    values.plane_mask = pGC->planemask;
 
111
  
 
112
  if (mask & GCForeground)
 
113
    values.foreground = xnestPixel(pGC->fgPixel);
 
114
  
 
115
  if (mask & GCBackground)
 
116
    values.background = xnestPixel(pGC->bgPixel);
 
117
 
 
118
  if (mask & GCLineWidth)
 
119
    values.line_width = pGC->lineWidth;
 
120
    
 
121
  if (mask & GCLineStyle)
 
122
    values.line_style = pGC->lineStyle;
 
123
 
 
124
  if (mask & GCCapStyle)
 
125
    values.cap_style = pGC->capStyle;
 
126
 
 
127
  if (mask & GCJoinStyle)
 
128
    values.join_style = pGC->joinStyle;
 
129
 
 
130
  if (mask & GCFillStyle)
 
131
    values.fill_style = pGC->fillStyle;
 
132
 
 
133
  if (mask & GCFillRule)
 
134
    values.fill_rule = pGC->fillRule;
 
135
  
 
136
  if (mask & GCTile) {
 
137
    if (pGC->tileIsPixel)
 
138
      mask &= ~GCTile;
 
139
    else
 
140
      values.tile = xnestPixmap(pGC->tile.pixmap);
 
141
  }
 
142
 
 
143
  if (mask & GCStipple)
 
144
    values.stipple = xnestPixmap(pGC->stipple);
 
145
 
 
146
  if (mask & GCTileStipXOrigin)
 
147
    values.ts_x_origin = pGC->patOrg.x;
 
148
 
 
149
  if (mask & GCTileStipYOrigin)
 
150
    values.ts_y_origin = pGC->patOrg.y;
 
151
 
 
152
  if (mask & GCFont)
 
153
    values.font = xnestFont(pGC->font);
 
154
 
 
155
  if (mask & GCSubwindowMode)
 
156
    values.subwindow_mode = pGC->subWindowMode;
 
157
 
 
158
  if (mask & GCGraphicsExposures)
 
159
    values.graphics_exposures = pGC->graphicsExposures;
 
160
 
 
161
  if (mask & GCClipXOrigin)
 
162
    values.clip_x_origin = pGC->clipOrg.x;
 
163
 
 
164
  if (mask & GCClipYOrigin)
 
165
    values.clip_y_origin = pGC->clipOrg.y;
 
166
 
 
167
  if (mask & GCClipMask) /* this is handled in change clip */
 
168
    mask &= ~GCClipMask;
 
169
 
 
170
  if (mask & GCDashOffset)
 
171
    values.dash_offset = pGC->dashOffset;
 
172
 
 
173
  if (mask & GCDashList) {
 
174
    mask &= ~GCDashList;
 
175
    XSetDashes(xnestDisplay, xnestGC(pGC), 
 
176
               pGC->dashOffset, (char *)pGC->dash, pGC->numInDashList);
 
177
  }
 
178
 
 
179
  if (mask & GCArcMode)
 
180
    values.arc_mode = pGC->arcMode;
 
181
 
 
182
  if (mask)
 
183
    XChangeGC(xnestDisplay, xnestGC(pGC), mask, &values);
 
184
}
 
185
 
 
186
void
 
187
xnestCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst)
 
188
{
 
189
  XCopyGC(xnestDisplay, xnestGC(pGCSrc), mask, xnestGC(pGCDst));
 
190
}
 
191
 
 
192
void
 
193
xnestDestroyGC(GCPtr pGC)
 
194
{
 
195
  XFreeGC(xnestDisplay, xnestGC(pGC));
 
196
}
 
197
 
 
198
void
 
199
xnestChangeClip(GCPtr pGC, int type, pointer pValue, int nRects)
 
200
{
 
201
  int i, size;
 
202
  BoxPtr pBox;
 
203
  XRectangle *pRects;
 
204
 
 
205
  xnestDestroyClipHelper(pGC);
 
206
 
 
207
  switch(type) 
 
208
    {
 
209
    case CT_NONE:
 
210
      XSetClipMask(xnestDisplay, xnestGC(pGC), None);
 
211
      break;
 
212
      
 
213
    case CT_REGION:
 
214
      nRects = REGION_NUM_RECTS((RegionPtr)pValue);
 
215
      size = nRects * sizeof(*pRects);
 
216
      pRects = (XRectangle *) xalloc(size);
 
217
      pBox = REGION_RECTS((RegionPtr)pValue);
 
218
      for (i = nRects; i-- > 0; ) {
 
219
        pRects[i].x = pBox[i].x1;
 
220
        pRects[i].y = pBox[i].y1;
 
221
        pRects[i].width = pBox[i].x2 - pBox[i].x1;
 
222
        pRects[i].height = pBox[i].y2 - pBox[i].y1;
 
223
      }
 
224
      XSetClipRectangles(xnestDisplay, xnestGC(pGC), 0, 0,
 
225
                         pRects, nRects, Unsorted);
 
226
      xfree((char *) pRects);
 
227
      break;
 
228
 
 
229
    case CT_PIXMAP:
 
230
      XSetClipMask(xnestDisplay, xnestGC(pGC), 
 
231
                   xnestPixmap((PixmapPtr)pValue));
 
232
      /*
 
233
       * Need to change into region, so subsequent uses are with
 
234
       * current pixmap contents.
 
235
       */
 
236
      pGC->clientClip = (pointer) (*pGC->pScreen->BitmapToRegion)((PixmapPtr)pValue);
 
237
      (*pGC->pScreen->DestroyPixmap)((PixmapPtr)pValue);
 
238
      pValue = pGC->clientClip;
 
239
      type = CT_REGION;
 
240
      break;
 
241
 
 
242
    case CT_UNSORTED:
 
243
      XSetClipRectangles(xnestDisplay, xnestGC(pGC), 
 
244
                         pGC->clipOrg.x, pGC->clipOrg.y,
 
245
                         (XRectangle *)pValue, nRects, Unsorted);
 
246
      break;
 
247
 
 
248
    case CT_YSORTED:
 
249
      XSetClipRectangles(xnestDisplay, xnestGC(pGC), 
 
250
                         pGC->clipOrg.x, pGC->clipOrg.y,
 
251
                         (XRectangle *)pValue, nRects, YSorted);
 
252
      break;
 
253
 
 
254
    case CT_YXSORTED:
 
255
      XSetClipRectangles(xnestDisplay, xnestGC(pGC), 
 
256
                         pGC->clipOrg.x, pGC->clipOrg.y,
 
257
                         (XRectangle *)pValue, nRects, YXSorted);
 
258
      break;
 
259
 
 
260
    case CT_YXBANDED:
 
261
      XSetClipRectangles(xnestDisplay, xnestGC(pGC), 
 
262
                         pGC->clipOrg.x, pGC->clipOrg.y,
 
263
                         (XRectangle *)pValue, nRects, YXBanded);
 
264
      break;
 
265
    }
 
266
 
 
267
  switch(type) 
 
268
    {
 
269
    default:
 
270
      break;
 
271
 
 
272
    case CT_UNSORTED:
 
273
    case CT_YSORTED:
 
274
    case CT_YXSORTED:
 
275
    case CT_YXBANDED:
 
276
      
 
277
      /*
 
278
       * other parts of server can only deal with CT_NONE,
 
279
       * CT_PIXMAP and CT_REGION client clips.
 
280
       */
 
281
      pGC->clientClip = (pointer) RECTS_TO_REGION(pGC->pScreen, nRects,
 
282
                                                  (xRectangle *)pValue, type);
 
283
      xfree(pValue);
 
284
      pValue = pGC->clientClip;
 
285
      type = CT_REGION;
 
286
 
 
287
      break;
 
288
    }
 
289
 
 
290
  pGC->clientClipType = type;
 
291
  pGC->clientClip = pValue;
 
292
  xnestGCPriv(pGC)->nClipRects = nRects;
 
293
}
 
294
 
 
295
void
 
296
xnestDestroyClip(GCPtr pGC)
 
297
{
 
298
  xnestDestroyClipHelper(pGC);
 
299
 
 
300
  XSetClipMask(xnestDisplay, xnestGC(pGC), None);
 
301
 
 
302
  pGC->clientClipType = CT_NONE;
 
303
  pGC->clientClip = NULL;
 
304
  xnestGCPriv(pGC)->nClipRects = 0;
 
305
}
 
306
 
 
307
void
 
308
xnestDestroyClipHelper(GCPtr pGC)
 
309
{
 
310
  switch (pGC->clientClipType)
 
311
    {
 
312
    default:
 
313
    case CT_NONE:
 
314
      break;
 
315
      
 
316
    case CT_REGION:
 
317
      REGION_DESTROY(pGC->pScreen, pGC->clientClip); 
 
318
      break;
 
319
    }
 
320
}
 
321
 
 
322
void
 
323
xnestCopyClip(GCPtr pGCDst, GCPtr pGCSrc)
 
324
{
 
325
  RegionPtr pRgn;
 
326
 
 
327
  switch (pGCSrc->clientClipType)
 
328
    {
 
329
    default:
 
330
    case CT_NONE:
 
331
      xnestDestroyClip(pGCDst);
 
332
      break;
 
333
 
 
334
    case CT_REGION:
 
335
      pRgn = REGION_CREATE(pGCDst->pScreen, NULL, 1);
 
336
      REGION_COPY(pGCDst->pScreen, pRgn, pGCSrc->clientClip);
 
337
      xnestChangeClip(pGCDst, CT_REGION, pRgn, 0);
 
338
      break;
 
339
    }
 
340
}