|
|
1.1 root 1: #include "copyright.h"
2:
3: /* $Header: XVisUtil.c,v 11.8 87/09/11 08:15:44 toddb Exp $ */
4: /* Copyright Massachusetts Institute of Technology 1986 */
5:
6: #include <stdio.h>
7: #include "Xlibint.h"
8: #include "Xutil.h"
9: /*
10: * This procedure returns a list of visual information structures
11: * that match the specified attributes given in the visual information
12: * template.
13: *
14: * If no visuals exist that match the specified attributes, a NULL is
15: * returned.
16: *
17: * The choices for visual_info_mask are:
18: *
19: * VisualNoMask
20: * VisualIDMask
21: * VisualScreenMask
22: * VisualDepthMask
23: * VisualClassMask
24: * VisualRedMaskMask
25: * VisualGreenMaskMask
26: * VisualBlueMaskMask
27: * VisualColormapSizeMask
28: * VisualBitsPerRGBMask
29: * VisualAllMask
30: */
31:
32: XVisualInfo *XGetVisualInfo( dpy, visual_info_mask,
33: visual_info_template, nitems)
34: Display *dpy;
35: register long visual_info_mask;
36: register XVisualInfo *visual_info_template;
37: int *nitems; /* RETURN */
38: {
39:
40: register Visual *vp;
41: register Depth *dp;
42: Screen *sp;
43: int ii,screen_s,screen_e,total,count;
44: register XVisualInfo *vip,*vip_base;
45:
46: /* NOTE: NO HIGH PERFORMING CODE TO BE FOUND HERE */
47:
48: LockDisplay(dpy);
49:
50: /* ALLOCATE THE ORIGINAL BUFFER; REALLOCED LATER OF OVERFLOW OCCURS;
51: FREED AT END IF NO VISUALS ARE FOUND */
52:
53: count = 0;
54: total = 10;
55: vip_base = vip = (XVisualInfo *)Xmalloc(sizeof(XVisualInfo)*total);
56:
57: /* DETERMINE IF WE DO ALL SCREENS OR ONLY ONE */
58:
59: screen_s = 0;
60: screen_e = dpy->nscreens;
61: if (visual_info_mask & VisualScreenMask)
62: {
63: screen_s = visual_info_template->screen;
64: screen_e = screen_s + 1;
65: }
66:
67: /* LOOP THROUGH SCREENS */
68:
69: for (ii=screen_s; ii<screen_e; ii++)
70: {
71: sp = (Screen *)(&dpy->screens[ii]);
72:
73: /* LOOP THROUGH DEPTHS */
74:
75: for (dp=sp->depths; dp < (sp->depths + sp->ndepths); dp++)
76: {
77: if ((visual_info_mask & VisualDepthMask) &&
78: (dp->depth != visual_info_template->depth)) continue;
79:
80: /* LOOP THROUGH VISUALS */
81:
82: for (vp=dp->visuals; vp<(dp->visuals + dp->nvisuals); vp++)
83: {
84: if ((visual_info_mask & VisualIDMask) &&
85: (vp->visualid != visual_info_template->visualid)) continue;
86: if ((visual_info_mask & VisualClassMask) &&
87: (vp->class != visual_info_template->class)) continue;
88: if ((visual_info_mask & VisualRedMaskMask) &&
89: (vp->red_mask != visual_info_template->red_mask)) continue;
90: if ((visual_info_mask & VisualGreenMaskMask) &&
91: (vp->green_mask != visual_info_template->green_mask)) continue;
92: if ((visual_info_mask & VisualBlueMaskMask) &&
93: (vp->blue_mask != visual_info_template->blue_mask)) continue;
94: if ((visual_info_mask & VisualColormapSizeMask) &&
95: (vp->map_entries != visual_info_template->colormap_size)) continue;
96: if ((visual_info_mask & VisualBitsPerRGBMask) &&
97: (vp->bits_per_rgb != visual_info_template->bits_per_rgb)) continue;
98:
99: /* YEA!!! WE FOUND A GOOD ONE */
100:
101: if (count+1 > total)
102: {
103: total += 10;
104: vip_base = (XVisualInfo *)Xrealloc(vip_base,sizeof(XVisualInfo)*total);
105: vip = &vip_base[count];
106: }
107:
108: count++;
109:
110: vip->visual = vp;
111: vip->visualid = vp->visualid;
112: vip->screen = ii;
113: vip->depth = dp->depth;
114: vip->class = vp->class;
115: vip->red_mask = vp->red_mask;
116: vip->green_mask = vp->green_mask;
117: vip->blue_mask = vp->blue_mask;
118: vip->colormap_size = vp->map_entries;
119: vip->bits_per_rgb = vp->bits_per_rgb;
120:
121: vip++;
122:
123: } /* END OF LOOP ON VISUALS */
124:
125: } /* END OF LOOP ON DEPTHS */
126:
127: } /* END OF LOOP ON SCREENS */
128:
129: UnlockDisplay(dpy);
130:
131: if (count)
132: {
133: *nitems = count;
134: return vip_base;
135: }
136:
137:
138: Xfree(vip_base);
139:
140: *nitems = 0;
141:
142: return NULL;
143:
144: }
145:
146:
147: /*
148: * This procedure will return the visual information for a visual
149: * that matches the specified depth and class for a screen. Since
150: * multiple visuals may exist that match the specified depth and
151: * class, which visual chosen is undefined.
152: *
153: * If a visual is found, True is returned as the function value,
154: * otherwise False is returned.
155: */
156:
157: Status XMatchVisualInfo( dpy, screen, depth, class, visual_info)
158: Display *dpy;
159: int screen;
160: int depth;
161: int class;
162: XVisualInfo *visual_info; /* RETURNED */
163: {
164:
165: Visual *vp;
166: Depth *dp;
167: Screen *sp;
168: int ii,jj;
169:
170: LockDisplay(dpy);
171:
172: sp = (Screen *)(&dpy->screens[screen]);
173:
174: dp = sp->depths;
175:
176: for (ii=0; ii < sp->ndepths; ii++)
177: {
178:
179: /* LOOK THROUGH DEPTHS FOR THE WANTED DEPTH */
180:
181: if (dp->depth == depth)
182: {
183: vp = dp->visuals;
184:
185: /* LOOK THROUGH VISUALS FOR THE WANTED CLASS */
186:
187: for (jj=0; jj<dp->nvisuals; jj++)
188: {
189: if (vp->class == class)
190: {
191: visual_info->visual = vp;
192: visual_info->visualid = vp->visualid;
193: visual_info->screen = screen;
194: visual_info->depth = depth;
195: visual_info->class = vp->class;
196: visual_info->red_mask = vp->red_mask;
197: visual_info->green_mask = vp->green_mask;
198: visual_info->blue_mask = vp->blue_mask;
199: visual_info->colormap_size = vp->map_entries;
200: visual_info->bits_per_rgb = vp->bits_per_rgb;
201: UnlockDisplay(dpy);
202: return True;
203: }
204: vp++;
205: }
206: }
207:
208: dp++;
209:
210: }
211:
212: UnlockDisplay(dpy);
213:
214: return False;
215:
216: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.