Annotation of researchv9/X11/src/X.V11R1/lib/X/XCrGC.c, revision 1.1.1.1

1.1       root        1: #include "copyright.h"
                      2: 
                      3: /* $Header: XCrGC.c,v 11.21 87/09/09 15:58:25 newman Exp $ */
                      4: /* Copyright    Massachusetts Institute of Technology    1986  */
                      5: 
                      6: #include "Xlibint.h"
                      7: 
                      8: static XGCValues initial_GC = {
                      9:     GXcopy,    /* function */
                     10:     AllPlanes, /* plane_mask */
                     11:     0L,                /* foreground */
                     12:     1L,                /* background */
                     13:     0,         /* line_width */
                     14:     LineSolid, /* line_style */
                     15:     CapButt,   /* cap_style */
                     16:     JoinMiter, /* join_style */
                     17:     FillSolid, /* fill_style */
                     18:     EvenOddRule,/* fill_rule */
                     19:     ArcPieSlice,/* arc_mode */
                     20:     ~0,                /* tile, impossible (unknown) resource */
                     21:     ~0,                /* stipple, impossible (unknown) resource */
                     22:     0,         /* ts_x_origin */
                     23:     0,         /* ts_y_origin */
                     24:     ~0,                /* font, impossible (unknown) resource */
                     25:     ClipByChildren, /* subwindow_mode */
                     26:     True,      /* graphics_exposures */
                     27:     0,         /* clip_x_origin */
                     28:     0,         /* clip_y_origin */
                     29:     None,      /* clip_mask */
                     30:     0,         /* dash_offset */
                     31:     4          /* dashes (list [4,4]) */
                     32: };
                     33: 
                     34: GC XCreateGC (dpy, d, valuemask, values)
                     35:      register Display *dpy;
                     36:      Drawable d;               /* Window or Pixmap for which depth matches */
                     37:      unsigned long valuemask;  /* which ones to set initially */
                     38:      XGCValues *values;                /* the values themselves */
                     39: {
                     40:     register GC gc;
                     41:     register xCreateGCReq *req;
                     42:     register _XExtension *ext;
                     43: 
                     44:     LockDisplay(dpy);
                     45:     if ((gc = (GC)Xmalloc (sizeof(struct _XGC))) == NULL) {
                     46:         errno = ENOMEM;
                     47:        (*_XIOErrorFunction)(dpy);
                     48:        UnlockDisplay(dpy);
                     49:        return (NULL);
                     50:     }
                     51:     gc->rects = 0;
                     52:     gc->dashes = 0;
                     53:     gc->ext_data = NULL;
                     54:     gc->values = initial_GC;
                     55:     gc->dirty = 0L;
                     56: 
                     57:     if (valuemask) _XUpdateGCCache (gc, valuemask, values);
                     58: 
                     59:     GetReq(CreateGC, req);
                     60:     req->drawable = d;
                     61:     req->gc = gc->gid = XAllocID(dpy);
                     62: 
                     63:     if (req->mask = gc->dirty)
                     64:         _XGenerateGCList (dpy, gc, (xReq *) req);
                     65:     ext = dpy->ext_procs;
                     66:     while (ext) {              /* call out to any extensions interested */
                     67:        if (ext->create_GC != NULL) (*ext->create_GC)(dpy, gc, &ext->codes);
                     68:        ext = ext->next;
                     69:        }    
                     70:     UnlockDisplay(dpy);
                     71:     SyncHandle();
                     72:     return (gc);
                     73:     }
                     74: 
                     75: /*
                     76:  * GenerateGCList looks at the GC dirty bits, and appends all the required
                     77:  * long words to the request being generated.  Clears the dirty bits in
                     78:  * the GC.
                     79:  */
                     80: 
                     81: _XGenerateGCList (dpy, gc, req)
                     82:     register Display *dpy;
                     83:     xReq *req;
                     84:     GC gc;
                     85:     {
                     86:     /* Warning!  This code assumes that "unsigned long" is 32-bits wide */
                     87: 
                     88:     unsigned long values[32];
                     89:     register unsigned long *value = values;
                     90:     long nvalues;
                     91:     register XGCValues *gv = &gc->values;
                     92:     register unsigned long dirty = gc->dirty;
                     93: 
                     94:     /*
                     95:      * Note: The order of these tests are critical; the order must be the
                     96:      * same as the GC mask bits in the word.
                     97:      */
                     98:     if (dirty & GCFunction)          *value++ = gv->function;
                     99:     if (dirty & GCPlaneMask)         *value++ = gv->plane_mask;
                    100:     if (dirty & GCForeground)        *value++ = gv->foreground;
                    101:     if (dirty & GCBackground)        *value++ = gv->background;
                    102:     if (dirty & GCLineWidth)         *value++ = gv->line_width;
                    103:     if (dirty & GCLineStyle)         *value++ = gv->line_style;
                    104:     if (dirty & GCCapStyle)          *value++ = gv->cap_style;
                    105:     if (dirty & GCJoinStyle)         *value++ = gv->join_style;
                    106:     if (dirty & GCFillStyle)         *value++ = gv->fill_style;
                    107:     if (dirty & GCFillRule)          *value++ = gv->fill_rule;
                    108:     if (dirty & GCTile)              *value++ = gv->tile;
                    109:     if (dirty & GCStipple)           *value++ = gv->stipple;
                    110:     if (dirty & GCTileStipXOrigin)   *value++ = gv->ts_x_origin;
                    111:     if (dirty & GCTileStipYOrigin)   *value++ = gv->ts_y_origin;
                    112:     if (dirty & GCFont)              *value++ = gv->font;
                    113:     if (dirty & GCSubwindowMode)     *value++ = gv->subwindow_mode;
                    114:     if (dirty & GCGraphicsExposures) *value++ = gv->graphics_exposures;
                    115:     if (dirty & GCClipXOrigin)       *value++ = gv->clip_x_origin;
                    116:     if (dirty & GCClipYOrigin)       *value++ = gv->clip_y_origin;
                    117:     if (dirty & GCClipMask)          *value++ = gv->clip_mask;
                    118:     if (dirty & GCDashOffset)        *value++ = gv->dash_offset;
                    119:     if (dirty & GCDashList)          *value++ = gv->dashes;
                    120:     if (dirty & GCArcMode)           *value++ = gv->arc_mode;
                    121: 
                    122:     req->length += (nvalues = value - values);
                    123: 
                    124:     /* 
                    125:      * note: Data is a macro that uses its arguments multiple
                    126:      * times, so "nvalues" is changed in a separate assignment
                    127:      * statement 
                    128:      */
                    129: 
                    130:     nvalues <<= 2;
                    131:     Data (dpy, (char *) values, nvalues);
                    132:     gc->dirty = 0L;
                    133: 
                    134:     }
                    135: 
                    136: 
                    137: _XUpdateGCCache (gc, mask, att)
                    138:     register long mask;
                    139:     register XGCValues *att;
                    140:     register GC gc;
                    141:     {
                    142:     register XGCValues *gv = &gc->values;
                    143: 
                    144:     if (mask & GCFunction)
                    145:         if (gv->function != att->function) {
                    146:          gv->function = att->function;
                    147:          gc->dirty |= GCFunction;
                    148:        }
                    149:        
                    150:     if (mask & GCPlaneMask)
                    151:         if (gv->plane_mask != att->plane_mask) {
                    152:             gv->plane_mask = att->plane_mask;
                    153:            gc->dirty |= GCPlaneMask;
                    154:          }
                    155: 
                    156:     if (mask & GCForeground)
                    157:         if (gv->foreground != att->foreground) {
                    158:             gv->foreground = att->foreground;
                    159:            gc->dirty |= GCForeground;
                    160:          }
                    161: 
                    162:     if (mask & GCBackground)
                    163:         if (gv->background != att->background) {
                    164:             gv->background = att->background;
                    165:            gc->dirty |= GCBackground;
                    166:          }
                    167: 
                    168:     if (mask & GCLineWidth)
                    169:         if (gv->line_width != att->line_width) {
                    170:             gv->line_width = att->line_width;
                    171:            gc->dirty |= GCLineWidth;
                    172:          }
                    173: 
                    174:     if (mask & GCLineStyle)
                    175:         if (gv->line_style != att->line_style) {
                    176:             gv->line_style = att->line_style;
                    177:            gc->dirty |= GCLineStyle;
                    178:          }
                    179: 
                    180:     if (mask & GCCapStyle)
                    181:         if (gv->cap_style != att->cap_style) {
                    182:             gv->cap_style = att->cap_style;
                    183:            gc->dirty |= GCCapStyle;
                    184:          }
                    185:     
                    186:     if (mask & GCJoinStyle)
                    187:         if (gv->join_style != att->join_style) {
                    188:             gv->join_style = att->join_style;
                    189:            gc->dirty |= GCJoinStyle;
                    190:          }
                    191: 
                    192:     if (mask & GCFillStyle)
                    193:         if (gv->fill_style != att->fill_style) {
                    194:             gv->fill_style = att->fill_style;
                    195:            gc->dirty |= GCFillStyle;
                    196:          }
                    197: 
                    198:     if (mask & GCFillRule)
                    199:         if (gv->fill_rule != att->fill_rule) {
                    200:            gv->fill_rule = att->fill_rule;
                    201:            gc->dirty |= GCFillRule;
                    202:          }
                    203: 
                    204:     if (mask & GCArcMode)
                    205:         if (gv->arc_mode != att->arc_mode) {
                    206:            gv->arc_mode = att->arc_mode;
                    207:            gc->dirty |= GCArcMode;
                    208:          }
                    209: 
                    210:     /* always write through resource ID changes */
                    211:     if (mask & GCTile) {
                    212:            gv->tile = att->tile;
                    213:            gc->dirty |= GCTile;
                    214:          }
                    215: 
                    216:     /* always write through resource ID changes */
                    217:     if (mask & GCStipple) {
                    218:            gv->stipple = att->stipple;
                    219:            gc->dirty |= GCStipple;
                    220:          }
                    221: 
                    222:     if (mask & GCTileStipXOrigin)
                    223:         if (gv->ts_x_origin != att->ts_x_origin) {
                    224:            gv->ts_x_origin = att->ts_x_origin;
                    225:            gc->dirty |= GCTileStipXOrigin;
                    226:          }
                    227: 
                    228:     if (mask & GCTileStipYOrigin)
                    229:         if (gv->ts_y_origin != att->ts_y_origin) {
                    230:            gv->ts_y_origin = att->ts_y_origin;
                    231:            gc->dirty |= GCTileStipYOrigin;
                    232:          }
                    233: 
                    234:     /* always write through resource ID changes */
                    235:     if (mask & GCFont) {
                    236:            gv->font = att->font;
                    237:            gc->dirty |= GCFont;
                    238:          }
                    239: 
                    240:     if (mask & GCSubwindowMode)
                    241:         if (gv->subwindow_mode != att->subwindow_mode) {
                    242:            gv->subwindow_mode = att->subwindow_mode;
                    243:            gc->dirty |= GCSubwindowMode;
                    244:          }
                    245: 
                    246:     if (mask & GCGraphicsExposures)
                    247:         if (gv->graphics_exposures != att->graphics_exposures) {
                    248:            gv->graphics_exposures = att->graphics_exposures;
                    249:            gc->dirty |= GCGraphicsExposures;
                    250:          }
                    251: 
                    252:     if (mask & GCClipXOrigin)
                    253:         if (gv->clip_x_origin != att->clip_x_origin) {
                    254:            gv->clip_x_origin = att->clip_x_origin;
                    255:            gc->dirty |= GCClipXOrigin;
                    256:          }
                    257: 
                    258:     if (mask & GCClipYOrigin)
                    259:         if (gv->clip_y_origin != att->clip_y_origin) {
                    260:            gv->clip_y_origin = att->clip_y_origin;
                    261:            gc->dirty |= GCClipYOrigin;
                    262:          }
                    263: 
                    264:     if (mask & GCClipMask) 
                    265:         if ((gv->clip_mask != att->clip_mask) || (gc->rects == True)) {
                    266:            gv->clip_mask = att->clip_mask;
                    267:           gc->dirty |= GCClipMask;
                    268:           gc->rects = 0;
                    269:           }
                    270: 
                    271:     if (mask & GCDashOffset)
                    272:         if (gv->dash_offset != att->dash_offset) {
                    273:            gv->dash_offset = att->dash_offset;
                    274:            gc->dirty |= GCDashOffset;
                    275:          }
                    276: 
                    277:     if (mask & GCDashList)
                    278:         if ((gv->dashes != att->dashes) || (gc->dashes == True)) {
                    279:             gv->dashes = att->dashes;
                    280:            gc->dirty |= GCDashList;
                    281:            gc->dashes = 0;
                    282:            }
                    283:     return;
                    284:     }
                    285: 
                    286: /* can only call when display is already locked. */
                    287: 
                    288: _XFlushGCCache(dpy, gc)
                    289:      Display *dpy;
                    290:      GC gc;
                    291: {
                    292:     register xChangeGCReq *req;
                    293:     register _XExtension *ext;
                    294: 
                    295:     if (gc->dirty) {
                    296:         GetReq(ChangeGC, req);
                    297:         req->gc = gc->gid;
                    298:        req->mask = gc->dirty;
                    299:         _XGenerateGCList (dpy, gc, (xReq *) req);
                    300:        ext = dpy->ext_procs;
                    301:        while (ext) {           /* call out to any extensions interested */
                    302:                if (ext->flush_GC != NULL) (*ext->flush_GC)(dpy, gc, &ext->codes);
                    303:                ext = ext->next;
                    304:        }    
                    305:     }
                    306: }
                    307: 
                    308: GContext XGContextFromGC(gc)
                    309:     GC gc;
                    310:     { return (gc->gid); }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.