📄 cfbcmap.c
字号:
for (red = 0; red <= maxred; red += stepred) { for (green = 0; green <= maxgreen; green += stepgreen) { AddElement (DoBlue) } } } } return nresult;}BoolcfbCreateDefColormap(pScreen) ScreenPtr pScreen;{ unsigned short zero = 0, ones = 0xFFFF; VisualPtr pVisual; ColormapPtr cmap; Pixel wp, bp; for (pVisual = pScreen->visuals; pVisual->vid != pScreen->rootVisual; pVisual++) ; if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &cmap, (pVisual->class & DynamicClass) ? AllocNone : AllocAll, 0) != Success) return FALSE; wp = pScreen->whitePixel; bp = pScreen->blackPixel; if ((AllocColor(cmap, &ones, &ones, &ones, &wp, 0) != Success) || (AllocColor(cmap, &zero, &zero, &zero, &bp, 0) != Success)) return FALSE; pScreen->whitePixel = wp; pScreen->blackPixel = bp; (*pScreen->InstallColormap)(cmap); return TRUE;}extern int defaultColorVisualClass;#define _BZ(d) (d / 3)#define _BS(d) 0#define _BM(d) ((1 << _BZ(d)) - 1)#define _GZ(d) ((d - _BZ(d) + 1) / 2)#define _GS(d) _BZ(d)#define _GM(d) (((1 << _GZ(d)) - 1) << _GS(d))#define _RZ(d) (d - _BZ(d) - _GZ(d))#define _RS(d) (_BZ(d) + _GZ(d))#define _RM(d) (((1 << _RZ(d)) - 1) << _RS(d))#define _CE(d) (1 << _GZ(d))#define MAX_PSEUDO_DEPTH 10 /* largest DAC size I know */#define StaticGrayMask (1 << StaticGray)#define GrayScaleMask (1 << GrayScale)#define StaticColorMask (1 << StaticColor)#define PseudoColorMask (1 << PseudoColor)#define TrueColorMask (1 << TrueColor)#define DirectColorMask (1 << DirectColor)#define ALL_VISUALS (StaticGrayMask|\ GrayScaleMask|\ StaticColorMask|\ PseudoColorMask|\ TrueColorMask|\ DirectColorMask)#define LARGE_VISUALS (TrueColorMask|\ DirectColorMask)typedef struct _cfbVisuals { struct _cfbVisuals *next; int depth; int bitsPerRGB; int visuals; int count;} cfbVisualsRec, *cfbVisualsPtr;static int cfbVisualPriority[] = { PseudoColor, DirectColor, GrayScale, StaticColor, TrueColor, StaticGray};#define NUM_PRIORITY 6static cfbVisualsPtr cfbVisuals;BoolcfbSetVisualTypes (depth, visuals, bitsPerRGB) int depth; int visuals;{ cfbVisualsPtr new, *prev, v; int count; new = (cfbVisualsPtr) xalloc (sizeof *new); if (!new) return FALSE; new->next = 0; new->depth = depth; new->visuals = visuals; new->bitsPerRGB = bitsPerRGB; count = (visuals >> 1) & 033333333333; count = visuals - count - ((count >> 1) & 033333333333); count = (((count + (count >> 3)) & 030707070707) % 077); /* HAKMEM 169 */ new->count = count; for (prev = &cfbVisuals; v = *prev; prev = &v->next); *prev = new; return TRUE;}/* * Given a list of formats for a screen, create a list * of visuals and depths for the screen which coorespond to * the set which can be used with this version of cfb. */BoolcfbInitVisuals (visualp, depthp, nvisualp, ndepthp, rootDepthp, defaultVisp, sizes, bitsPerRGB) VisualPtr *visualp; DepthPtr *depthp; int *nvisualp, *ndepthp; int *rootDepthp; VisualID *defaultVisp; unsigned long sizes; int bitsPerRGB;{ int i, j, k; VisualPtr visual; DepthPtr depth; VisualID *vid; int d, b; int f; int ndepth, nvisual; int nvtype; int vtype; VisualID defaultVisual; cfbVisualsPtr visuals, nextVisuals; /* none specified, we'll guess from pixmap formats */ if (!cfbVisuals) { for (f = 0; f < screenInfo.numPixmapFormats; f++) { d = screenInfo.formats[f].depth; b = screenInfo.formats[f].bitsPerPixel; if (sizes & (1 << (b - 1))) { if (d > MAX_PSEUDO_DEPTH) vtype = LARGE_VISUALS; else if (d == 1) vtype = StaticGrayMask; else vtype = ALL_VISUALS; } else vtype = 0; if (!cfbSetVisualTypes (d, vtype, bitsPerRGB)) return FALSE; } } nvisual = 0; ndepth = 0; for (visuals = cfbVisuals; visuals; visuals = nextVisuals) { nextVisuals = visuals->next; ndepth++; nvisual += visuals->count; } depth = (DepthPtr) xalloc (ndepth * sizeof (DepthRec)); visual = (VisualPtr) xalloc (nvisual * sizeof (VisualRec)); if (!depth || !visual) { xfree (depth); xfree (visual); return FALSE; } *depthp = depth; *visualp = visual; *ndepthp = ndepth; *nvisualp = nvisual; for (visuals = cfbVisuals; visuals; visuals = nextVisuals) { nextVisuals = visuals->next; d = visuals->depth; vtype = visuals->visuals; nvtype = visuals->count; vid = NULL; if (nvtype) { vid = (VisualID *) xalloc (nvtype * sizeof (VisualID)); if (!vid) return FALSE; } depth->depth = d; depth->numVids = nvtype; depth->vids = vid; depth++; for (i = 0; i < NUM_PRIORITY; i++) { if (! (vtype & (1 << cfbVisualPriority[i]))) continue; visual->class = cfbVisualPriority[i]; visual->bitsPerRGBValue = visuals->bitsPerRGB; visual->ColormapEntries = 1 << d; visual->nplanes = d; visual->vid = *vid = FakeClientID (0); switch (visual->class) { case PseudoColor: case GrayScale: case StaticGray: visual->redMask = 0; visual->greenMask = 0; visual->blueMask = 0; visual->offsetRed = 0; visual->offsetGreen = 0; visual->offsetBlue = 0; break; case DirectColor: case TrueColor: visual->ColormapEntries = _CE(d); /* fall through */ case StaticColor: if (d == 8) { visual->redMask = 0x07; visual->greenMask = 0x38; visual->blueMask = 0xC0; visual->offsetRed = 0; visual->offsetGreen = 3; visual->offsetBlue = 6; } else { visual->redMask = _RM(d); visual->greenMask = _GM(d); visual->blueMask = _BM(d); visual->offsetRed = _RS(d); visual->offsetGreen = _GS(d); visual->offsetBlue = _BS(d); } } vid++; visual++; } xfree (visuals); } cfbVisuals = NULL; visual = *visualp; depth = *depthp; for (i = 0; i < ndepth; i++) { if (*rootDepthp && *rootDepthp != depth[i].depth) continue; for (j = 0; j < depth[i].numVids; j++) { for (k = 0; k < nvisual; k++) if (visual[k].vid == depth[i].vids[j]) break; if (k == nvisual) continue; if (defaultColorVisualClass < 0 || visual[k].class == defaultColorVisualClass) break; } if (j != depth[i].numVids) break; } if (i == ndepth) { i = 0; j = 0; } *rootDepthp = depth[i].depth; *defaultVisp = depth[i].vids[j];#ifdef GLXEXT#ifdef GLX_MODULE if( GlxInitVisualsPtr != NULL ) return (*GlxInitVisualsPtr)#else return GlxInitVisuals#endif ( visualp, depthp, nvisualp, ndepthp, rootDepthp, defaultVisp, sizes, bitsPerRGB );#else return TRUE;#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -