dmxvisual.c revision 706f2543
1706f2543Smrg/*
2706f2543Smrg * Copyright 2002-2004 Red Hat Inc., Durham, North Carolina.
3706f2543Smrg *
4706f2543Smrg * All Rights Reserved.
5706f2543Smrg *
6706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining
7706f2543Smrg * a copy of this software and associated documentation files (the
8706f2543Smrg * "Software"), to deal in the Software without restriction, including
9706f2543Smrg * without limitation on the rights to use, copy, modify, merge,
10706f2543Smrg * publish, distribute, sublicense, and/or sell copies of the Software,
11706f2543Smrg * and to permit persons to whom the Software is furnished to do so,
12706f2543Smrg * subject to the following conditions:
13706f2543Smrg *
14706f2543Smrg * The above copyright notice and this permission notice (including the
15706f2543Smrg * next paragraph) shall be included in all copies or substantial
16706f2543Smrg * portions of the Software.
17706f2543Smrg *
18706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19706f2543Smrg * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20706f2543Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21706f2543Smrg * NON-INFRINGEMENT.  IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22706f2543Smrg * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23706f2543Smrg * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24706f2543Smrg * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25706f2543Smrg * SOFTWARE.
26706f2543Smrg */
27706f2543Smrg
28706f2543Smrg/*
29706f2543Smrg * Authors:
30706f2543Smrg *   Kevin E. Martin <kem@redhat.com>
31706f2543Smrg *
32706f2543Smrg */
33706f2543Smrg
34706f2543Smrg/** \file
35706f2543Smrg * This file provides support for visuals. */
36706f2543Smrg
37706f2543Smrg#ifdef HAVE_DMX_CONFIG_H
38706f2543Smrg#include <dmx-config.h>
39706f2543Smrg#endif
40706f2543Smrg
41706f2543Smrg#include "dmx.h"
42706f2543Smrg#include "dmxvisual.h"
43706f2543Smrg
44706f2543Smrg#include "scrnintstr.h"
45706f2543Smrg
46706f2543Smrg#ifdef GLXEXT
47706f2543Smrg
48706f2543Smrg#include <GL/glxint.h>
49706f2543Smrg
50706f2543Smrgextern VisualID glxMatchVisualInConfigList(ScreenPtr pScreen,
51706f2543Smrg					   VisualPtr pVisual,
52706f2543Smrg					   __GLXvisualConfig *configs,
53706f2543Smrg					   int nconfigs);
54706f2543Smrg
55706f2543Smrgstatic Visual *dmxLookupGLXVisual(ScreenPtr pScreen, VisualPtr pVisual)
56706f2543Smrg{
57706f2543Smrg    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
58706f2543Smrg    int            j;
59706f2543Smrg    VisualID       vid;
60706f2543Smrg
61706f2543Smrg    vid = glxMatchVisualInConfigList(pScreen, pVisual,
62706f2543Smrg				     dmxScreen->glxVisuals,
63706f2543Smrg				     dmxScreen->numGlxVisuals);
64706f2543Smrg    if (vid) {
65706f2543Smrg	/* Find the X visual of the matching GLX visual */
66706f2543Smrg	for (j = 0; j < dmxScreen->beNumVisuals; j++)
67706f2543Smrg	    if (vid == dmxScreen->beVisuals[j].visualid)
68706f2543Smrg		return dmxScreen->beVisuals[j].visual;
69706f2543Smrg    }
70706f2543Smrg
71706f2543Smrg    /* No matching visual found */
72706f2543Smrg    return NULL;
73706f2543Smrg}
74706f2543Smrg#endif
75706f2543Smrg
76706f2543Smrg/** Return the visual that matched \a pVisual. */
77706f2543SmrgVisual *dmxLookupVisual(ScreenPtr pScreen, VisualPtr pVisual)
78706f2543Smrg{
79706f2543Smrg    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
80706f2543Smrg    int            i;
81706f2543Smrg#ifdef GLXEXT
82706f2543Smrg    Visual        *retval;
83706f2543Smrg#endif
84706f2543Smrg
85706f2543Smrg    if (!dmxScreen->beDisplay)
86706f2543Smrg	return NULL;
87706f2543Smrg
88706f2543Smrg#ifdef GLXEXT
89706f2543Smrg    if ((retval = dmxLookupGLXVisual(pScreen, pVisual)))
90706f2543Smrg	return retval;
91706f2543Smrg#endif
92706f2543Smrg
93706f2543Smrg    for (i = 0; i < dmxScreen->beNumVisuals; i++) {
94706f2543Smrg	if (pVisual->class == dmxScreen->beVisuals[i].class &&
95706f2543Smrg	    pVisual->bitsPerRGBValue == dmxScreen->beVisuals[i].bits_per_rgb &&
96706f2543Smrg	    pVisual->ColormapEntries == dmxScreen->beVisuals[i].colormap_size &&
97706f2543Smrg	    pVisual->nplanes == dmxScreen->beVisuals[i].depth &&
98706f2543Smrg	    pVisual->redMask == dmxScreen->beVisuals[i].red_mask &&
99706f2543Smrg	    pVisual->greenMask == dmxScreen->beVisuals[i].green_mask &&
100706f2543Smrg	    pVisual->blueMask == dmxScreen->beVisuals[i].blue_mask) {
101706f2543Smrg	    return dmxScreen->beVisuals[i].visual;
102706f2543Smrg	}
103706f2543Smrg    }
104706f2543Smrg
105706f2543Smrg    return NULL;
106706f2543Smrg}
107706f2543Smrg
108706f2543Smrg/** Return the visual that matched the \a vid. */
109706f2543SmrgVisual *dmxLookupVisualFromID(ScreenPtr pScreen, VisualID vid)
110706f2543Smrg{
111706f2543Smrg    Visual *visual;
112706f2543Smrg    int     i;
113706f2543Smrg
114706f2543Smrg    if (!dmxScreens[pScreen->myNum].beDisplay)
115706f2543Smrg	return NULL;
116706f2543Smrg
117706f2543Smrg    for (i = 0; i < pScreen->numVisuals; i++) {
118706f2543Smrg	if (pScreen->visuals[i].vid == vid) {
119706f2543Smrg	    visual = dmxLookupVisual(pScreen, &pScreen->visuals[i]);
120706f2543Smrg	    if (visual) return visual;
121706f2543Smrg	}
122706f2543Smrg    }
123706f2543Smrg
124706f2543Smrg    return NULL;
125706f2543Smrg}
126706f2543Smrg
127706f2543Smrg/** Return the colormap for the \a visual. */
128706f2543SmrgColormap dmxColormapFromDefaultVisual(ScreenPtr pScreen, Visual *visual)
129706f2543Smrg{
130706f2543Smrg    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
131706f2543Smrg    int            i;
132706f2543Smrg
133706f2543Smrg    if (dmxScreen->beDisplay) {
134706f2543Smrg	for (i = 0; i < dmxScreen->beNumDefColormaps; i++)
135706f2543Smrg	    if (visual == dmxScreen->beVisuals[i].visual)
136706f2543Smrg		return dmxScreen->beDefColormaps[i];
137706f2543Smrg    }
138706f2543Smrg
139706f2543Smrg    return None;
140706f2543Smrg}
141