3 Copyright 1986, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
34 * This procedure returns a list of visual information structures
35 * that match the specified attributes given in the visual information
38 * If no visuals exist that match the specified attributes, a NULL is
41 * The choices for visual_info_mask are:
51 * VisualColormapSizeMask
52 * VisualBitsPerRGBMask
56 XVisualInfo *XGetVisualInfo(
58 register long visual_info_mask,
59 register XVisualInfo *visual_info_template,
60 int *nitems) /* RETURN */
66 int ii,screen_s,screen_e,total,count;
67 register XVisualInfo *vip,*vip_base;
69 /* NOTE: NO HIGH PERFORMING CODE TO BE FOUND HERE */
73 /* ALLOCATE THE ORIGINAL BUFFER; REALLOCED LATER IF OVERFLOW OCCURS;
74 FREED AT END IF NO VISUALS ARE FOUND */
78 if (! (vip_base = vip = (XVisualInfo *)
79 Xmalloc((unsigned) (sizeof(XVisualInfo) * total)))) {
81 return (XVisualInfo *) NULL;
84 /* DETERMINE IF WE DO ALL SCREENS OR ONLY ONE */
87 screen_e = dpy->nscreens;
88 if (visual_info_mask & VisualScreenMask)
90 screen_s = visual_info_template->screen;
91 if (screen_s < 0 || screen_s >= screen_e)
94 screen_e = screen_s + 1;
97 /* LOOP THROUGH SCREENS */
99 for (ii=screen_s; ii<screen_e; ii++)
101 sp = (Screen *)(&dpy->screens[ii]);
103 /* LOOP THROUGH DEPTHS */
105 for (dp=sp->depths; dp < (sp->depths + sp->ndepths); dp++)
107 if ((visual_info_mask & VisualDepthMask) &&
108 (dp->depth != visual_info_template->depth)) continue;
110 /* LOOP THROUGH VISUALS */
113 for (vp=dp->visuals; vp<(dp->visuals + dp->nvisuals); vp++) {
114 if ((visual_info_mask & VisualIDMask) &&
115 (vp->visualid != visual_info_template->visualid)) continue;
116 if ((visual_info_mask & VisualClassMask) &&
117 (vp->class != visual_info_template->class)) continue;
118 if ((visual_info_mask & VisualRedMaskMask) &&
119 (vp->red_mask != visual_info_template->red_mask)) continue;
120 if ((visual_info_mask & VisualGreenMaskMask) &&
121 (vp->green_mask != visual_info_template->green_mask)) continue;
122 if ((visual_info_mask & VisualBlueMaskMask) &&
123 (vp->blue_mask != visual_info_template->blue_mask)) continue;
124 if ((visual_info_mask & VisualColormapSizeMask) &&
125 (vp->map_entries != visual_info_template->colormap_size)) continue;
126 if ((visual_info_mask & VisualBitsPerRGBMask) &&
127 (vp->bits_per_rgb != visual_info_template->bits_per_rgb)) continue;
129 /* YEA!!! WE FOUND A GOOD ONE */
133 XVisualInfo *old_vip_base = vip_base;
135 if (! (vip_base = (XVisualInfo *)
136 Xrealloc((char *) vip_base,
137 (unsigned) (sizeof(XVisualInfo) * total)))) {
138 Xfree((char *) old_vip_base);
140 return (XVisualInfo *) NULL;
142 vip = &vip_base[count];
147 vip->visual = _XVIDtoVisual(dpy, vp->visualid);
148 vip->visualid = vp->visualid;
150 vip->depth = dp->depth;
151 vip->class = vp->class;
152 vip->red_mask = vp->red_mask;
153 vip->green_mask = vp->green_mask;
154 vip->blue_mask = vp->blue_mask;
155 vip->colormap_size = vp->map_entries;
156 vip->bits_per_rgb = vp->bits_per_rgb;
160 } /* END OF LOOP ON VISUALS */
161 } /* END OF IF THERE ARE ANY VISUALS AT THIS DEPTH */
163 } /* END OF LOOP ON DEPTHS */
165 } /* END OF LOOP ON SCREENS */
175 Xfree((char *) vip_base);
182 * This procedure will return the visual information for a visual
183 * that matches the specified depth and class for a screen. Since
184 * multiple visuals may exist that match the specified depth and
185 * class, which visual chosen is undefined.
187 * If a visual is found, True is returned as the function value,
188 * otherwise False is returned.
191 Status XMatchVisualInfo(
196 XVisualInfo *visual_info) /* RETURNED */
204 if (screen < 0 || screen >= dpy->nscreens)
209 sp = (Screen *)(&dpy->screens[screen]);
213 for (ii=0; ii < sp->ndepths; ii++)
216 /* LOOK THROUGH DEPTHS FOR THE WANTED DEPTH */
218 if (dp->depth == depth)
222 /* LOOK THROUGH VISUALS FOR THE WANTED CLASS */
224 /* if nvisuals == 0 then vp will be NULL */
225 for (jj=0; jj<dp->nvisuals; jj++)
227 if (vp->class == class)
229 visual_info->visual = _XVIDtoVisual(dpy, vp->visualid);
230 visual_info->visualid = vp->visualid;
231 visual_info->screen = screen;
232 visual_info->depth = depth;
233 visual_info->class = vp->class;
234 visual_info->red_mask = vp->red_mask;
235 visual_info->green_mask = vp->green_mask;
236 visual_info->blue_mask = vp->blue_mask;
237 visual_info->colormap_size = vp->map_entries;
238 visual_info->bits_per_rgb = vp->bits_per_rgb;