1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
/*
* Copyright 2001-2004 Red Hat Inc., Durham, North Carolina.
*
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation on the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* Authors:
* Kevin E. Martin <kem@redhat.com>
*
*/
/** \file
* This file provides support for GCs. */
#ifdef HAVE_DMX_CONFIG_H
#include <dmx-config.h>
#endif
#include "dmx.h"
#include "dmxsync.h"
#include "dmxgc.h"
#include "dmxgcops.h"
#include "dmxpixmap.h"
#include "dmxfont.h"
#include "gcstruct.h"
#include "pixmapstr.h"
#include "migc.h"
static GCFuncs dmxGCFuncs = {
dmxValidateGC,
dmxChangeGC,
dmxCopyGC,
dmxDestroyGC,
dmxChangeClip,
dmxDestroyClip,
dmxCopyClip,
};
static GCOps dmxGCOps = {
dmxFillSpans,
dmxSetSpans,
dmxPutImage,
dmxCopyArea,
dmxCopyPlane,
dmxPolyPoint,
dmxPolylines,
dmxPolySegment,
dmxPolyRectangle,
dmxPolyArc,
dmxFillPolygon,
dmxPolyFillRect,
dmxPolyFillArc,
dmxPolyText8,
dmxPolyText16,
dmxImageText8,
dmxImageText16,
dmxImageGlyphBlt,
dmxPolyGlyphBlt,
dmxPushPixels
};
/** Initialize the GC on \a pScreen */
Bool dmxInitGC(ScreenPtr pScreen)
{
if (!dixRequestPrivate(dmxGCPrivateKey, sizeof(dmxGCPrivRec)))
return FALSE;
return TRUE;
}
/** Create the GC on the back-end server. */
void dmxBECreateGC(ScreenPtr pScreen, GCPtr pGC)
{
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
int i;
for (i = 0; i < dmxScreen->beNumPixmapFormats; i++) {
if (pGC->depth == dmxScreen->bePixmapFormats[i].depth) {
unsigned long mask;
XGCValues gcvals;
mask = GCGraphicsExposures;
gcvals.graphics_exposures = FALSE;
/* Create GC in the back-end servers */
pGCPriv->gc = XCreateGC(dmxScreen->beDisplay,
dmxScreen->scrnDefDrawables[i],
mask, &gcvals);
break;
}
}
}
/** Create a graphics context on the back-end server associated /a pGC's
* screen. */
Bool dmxCreateGC(GCPtr pGC)
{
ScreenPtr pScreen = pGC->pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
Bool ret;
DMX_UNWRAP(CreateGC, dmxScreen, pScreen);
if ((ret = pScreen->CreateGC(pGC))) {
/* Save the old funcs */
pGCPriv->funcs = pGC->funcs;
pGCPriv->ops = NULL;
pGC->funcs = &dmxGCFuncs;
if (dmxScreen->beDisplay) {
dmxBECreateGC(pScreen, pGC);
} else {
pGCPriv->gc = NULL;
}
/* Check for "magic special case"
* 1. see CreateGC in dix/gc.c for more info
* 2. see dmxChangeGC for more info
*/
pGCPriv->msc = (!pGC->tileIsPixel && !pGC->tile.pixmap);
}
DMX_WRAP(CreateGC, dmxCreateGC, dmxScreen, pScreen);
return ret;
}
/** Validate a graphics context, \a pGC, locally in the DMX server and
* recompute the composite clip, if necessary. */
void dmxValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
{
dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
DMX_GC_FUNC_PROLOGUE(pGC);
#if 0
pGC->funcs->ValidateGC(pGC, changes, pDrawable);
#endif
if (pDrawable->type == DRAWABLE_WINDOW ||
pDrawable->type == DRAWABLE_PIXMAP) {
/* Save the old ops, since we're about to change the ops in the
* epilogue.
*/
pGCPriv->ops = pGC->ops;
} else {
pGCPriv->ops = NULL;
}
/* If the client clip is different or moved OR the subwindowMode has
* changed OR the window's clip has changed since the last
* validation, then we need to recompute the composite clip.
*/
if ((changes & (GCClipXOrigin |
GCClipYOrigin |
GCClipMask |
GCSubwindowMode)) ||
(pDrawable->serialNumber !=
(pGC->serialNumber & DRAWABLE_SERIAL_BITS))) {
miComputeCompositeClip(pGC, pDrawable);
}
DMX_GC_FUNC_EPILOGUE(pGC);
}
/** Set the values in the graphics context on the back-end server
* associated with \a pGC's screen. */
void dmxChangeGC(GCPtr pGC, unsigned long mask)
{
ScreenPtr pScreen = pGC->pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
XGCValues v;
DMX_GC_FUNC_PROLOGUE(pGC);
#if 0
pGC->funcs->ChangeGC(pGC, mask);
#endif
/* Handle "magic special case" from CreateGC */
if (pGCPriv->msc) {
/* The "magic special case" is used to handle the case where a
* foreground pixel is set when the GC is created so that a
* "pseudo default-tile" can be created and used in case the
* fillstyle was set to FillTiled. This specific case is tested
* in xtest (XCreateGC test #3). What has happened in dix by
* the time it reaches here is (1) the pGC->tile.pixel has been
* set to pGC->fgPixel and pGC->tileIsPixel is set, (2) if a
* tile has also been set, then pGC->tileIsPixel is unset and
* pGC->tile.pixmap is initialized; else, the default tile is
* created and pGC->tileIsPixel is unset and pGC->tile.pixmap is
* initialized to the "pseudo default-tile". In either case,
* pGC->tile.pixmap is set; however, in the "magic special case"
* the mask is not updated to allow us to detect that we should
* initialize the GCTile in the back-end server. Thus, we catch
* this case in dmxCreateGC and add GCTile to the mask here.
* Are there any cases that I've missed?
*/
/* Make sure that the tile.pixmap is set, just in case the user
* set GCTile in the mask but forgot to set vals.pixmap
*/
if (pGC->tile.pixmap) mask |= GCTile;
/* This only happens once when the GC is created */
pGCPriv->msc = FALSE;
}
/* Update back-end server's gc */
if (mask & GCFunction) v.function = pGC->alu;
if (mask & GCPlaneMask) v.plane_mask = pGC->planemask;
if (mask & GCForeground) v.foreground = pGC->fgPixel;
if (mask & GCBackground) v.background = pGC->bgPixel;
if (mask & GCLineWidth) v.line_width = pGC->lineWidth;
if (mask & GCLineStyle) v.line_style = pGC->lineStyle;
if (mask & GCCapStyle) v.cap_style = pGC->capStyle;
if (mask & GCJoinStyle) v.join_style = pGC->joinStyle;
if (mask & GCFillStyle) v.fill_style = pGC->fillStyle;
if (mask & GCFillRule) v.fill_rule = pGC->fillRule;
if (mask & GCTile) {
if (pGC->tileIsPixel) {
mask &= ~GCTile;
} else {
dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pGC->tile.pixmap);
v.tile = (Drawable)pPixPriv->pixmap;
}
}
if (mask & GCStipple) {
dmxPixPrivPtr pPixPriv = DMX_GET_PIXMAP_PRIV(pGC->stipple);
v.stipple = (Drawable)pPixPriv->pixmap;
}
if (mask & GCTileStipXOrigin) v.ts_x_origin = pGC->patOrg.x;
if (mask & GCTileStipYOrigin) v.ts_y_origin = pGC->patOrg.y;
if (mask & GCFont) {
if (dmxScreen->beDisplay) {
dmxFontPrivPtr pFontPriv;
pFontPriv = FontGetPrivate(pGC->font, dmxFontPrivateIndex);
v.font = pFontPriv->font[pScreen->myNum]->fid;
} else {
mask &= ~GCFont;
}
}
if (mask & GCSubwindowMode) v.subwindow_mode = pGC->subWindowMode;
/* Graphics exposures are not needed on the back-ends since they can
be generated on the front-end thereby saving bandwidth. */
if (mask & GCGraphicsExposures) mask &= ~GCGraphicsExposures;
if (mask & GCClipXOrigin) v.clip_x_origin = pGC->clipOrg.x;
if (mask & GCClipYOrigin) v.clip_y_origin = pGC->clipOrg.y;
if (mask & GCClipMask) mask &= ~GCClipMask; /* See ChangeClip */
if (mask & GCDashOffset) v.dash_offset = pGC->dashOffset;
if (mask & GCDashList) {
mask &= ~GCDashList;
if (dmxScreen->beDisplay)
XSetDashes(dmxScreen->beDisplay, pGCPriv->gc,
pGC->dashOffset, (char *)pGC->dash,
pGC->numInDashList);
}
if (mask & GCArcMode) v.arc_mode = pGC->arcMode;
if (mask && dmxScreen->beDisplay) {
XChangeGC(dmxScreen->beDisplay, pGCPriv->gc, mask, &v);
dmxSync(dmxScreen, FALSE);
}
DMX_GC_FUNC_EPILOGUE(pGC);
}
/** Copy \a pGCSrc to \a pGCDst on the back-end server associated with
* \a pGCSrc's screen. */
void dmxCopyGC(GCPtr pGCSrc, unsigned long changes, GCPtr pGCDst)
{
ScreenPtr pScreen = pGCSrc->pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxGCPrivPtr pGCSrcPriv = DMX_GET_GC_PRIV(pGCSrc);
dmxGCPrivPtr pGCDstPriv = DMX_GET_GC_PRIV(pGCDst);
DMX_GC_FUNC_PROLOGUE(pGCDst);
pGCDst->funcs->CopyGC(pGCSrc, changes, pGCDst);
/* Copy the GC on the back-end server */
if (dmxScreen->beDisplay)
XCopyGC(dmxScreen->beDisplay, pGCSrcPriv->gc, changes, pGCDstPriv->gc);
DMX_GC_FUNC_EPILOGUE(pGCDst);
}
/** Free the \a pGC on the back-end server. */
Bool dmxBEFreeGC(GCPtr pGC)
{
ScreenPtr pScreen = pGC->pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
if (pGCPriv->gc) {
XFreeGC(dmxScreen->beDisplay, pGCPriv->gc);
pGCPriv->gc = NULL;
return TRUE;
}
return FALSE;
}
/** Destroy the graphics context, \a pGC and free the corresponding GC
* on the back-end server. */
void dmxDestroyGC(GCPtr pGC)
{
ScreenPtr pScreen = pGC->pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
DMX_GC_FUNC_PROLOGUE(pGC);
/* Free the GC on the back-end server */
if (dmxScreen->beDisplay)
dmxBEFreeGC(pGC);
pGC->funcs->DestroyGC(pGC);
DMX_GC_FUNC_EPILOGUE(pGC);
}
/** Change the clip rects for a GC. */
void dmxChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects)
{
ScreenPtr pScreen = pGC->pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
XRectangle *pRects;
BoxPtr pBox;
int i, nRects;
DMX_GC_FUNC_PROLOGUE(pGC);
pGC->funcs->ChangeClip(pGC, type, pvalue, nrects);
/* Set the client clip on the back-end server */
switch (pGC->clientClipType) {
case CT_NONE:
if (dmxScreen->beDisplay)
XSetClipMask(dmxScreen->beDisplay, pGCPriv->gc, None);
break;
case CT_REGION:
if (dmxScreen->beDisplay) {
nRects = REGION_NUM_RECTS((RegionPtr)pGC->clientClip);
pRects = xalloc(nRects * sizeof(*pRects));
pBox = REGION_RECTS((RegionPtr)pGC->clientClip);
for (i = 0; i < nRects; i++) {
pRects[i].x = pBox[i].x1;
pRects[i].y = pBox[i].y1;
pRects[i].width = pBox[i].x2 - pBox[i].x1;
pRects[i].height = pBox[i].y2 - pBox[i].y1;
}
XSetClipRectangles(dmxScreen->beDisplay, pGCPriv->gc,
pGC->clipOrg.x, pGC->clipOrg.y,
pRects, nRects, Unsorted);
xfree(pRects);
}
break;
case CT_PIXMAP:
case CT_UNSORTED:
case CT_YSORTED:
case CT_YXSORTED:
case CT_YXBANDED:
/* These clip types are condensed down to either NONE or REGION
in the mi code */
break;
}
DMX_GC_FUNC_EPILOGUE(pGC);
}
/** Destroy a GC's clip rects. */
void dmxDestroyClip(GCPtr pGC)
{
ScreenPtr pScreen = pGC->pScreen;
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC);
DMX_GC_FUNC_PROLOGUE(pGC);
pGC->funcs->DestroyClip(pGC);
/* Set the client clip on the back-end server to None */
if (dmxScreen->beDisplay)
XSetClipMask(dmxScreen->beDisplay, pGCPriv->gc, None);
DMX_GC_FUNC_EPILOGUE(pGC);
}
/** Copy a GC's clip rects. */
void dmxCopyClip(GCPtr pGCDst, GCPtr pGCSrc)
{
DMX_GC_FUNC_PROLOGUE(pGCDst);
pGCDst->funcs->CopyClip(pGCDst, pGCSrc);
DMX_GC_FUNC_EPILOGUE(pGCDst);
}
|