First import
[xorg_rtime.git] / xorg-server-1.4 / hw / dmx / dmxvisual.c
blob7b8771f9ebba385e4788d9ac8d9ca584ad2a5a29
1 /*
2 * Copyright 2002-2004 Red Hat Inc., Durham, North Carolina.
4 * All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation on the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
29 * Authors:
30 * Kevin E. Martin <kem@redhat.com>
34 /** \file
35 * This file provides support for visuals. */
37 #ifdef HAVE_DMX_CONFIG_H
38 #include <dmx-config.h>
39 #endif
41 #include "dmx.h"
42 #include "dmxvisual.h"
44 #include "scrnintstr.h"
46 #ifdef GLXEXT
48 #include <GL/glxint.h>
50 extern VisualID glxMatchVisualInConfigList(ScreenPtr pScreen,
51 VisualPtr pVisual,
52 __GLXvisualConfig *configs,
53 int nconfigs);
55 static Visual *dmxLookupGLXVisual(ScreenPtr pScreen, VisualPtr pVisual)
57 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
58 int j;
59 VisualID vid;
61 vid = glxMatchVisualInConfigList(pScreen, pVisual,
62 dmxScreen->glxVisuals,
63 dmxScreen->numGlxVisuals);
64 if (vid) {
65 /* Find the X visual of the matching GLX visual */
66 for (j = 0; j < dmxScreen->beNumVisuals; j++)
67 if (vid == dmxScreen->beVisuals[j].visualid)
68 return dmxScreen->beVisuals[j].visual;
71 /* No matching visual found */
72 return NULL;
74 #endif
76 /** Return the visual that matched \a pVisual. */
77 Visual *dmxLookupVisual(ScreenPtr pScreen, VisualPtr pVisual)
79 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
80 int i;
81 #ifdef GLXEXT
82 Visual *retval;
83 #endif
85 if (!dmxScreen->beDisplay)
86 return NULL;
88 #ifdef GLXEXT
89 if ((retval = dmxLookupGLXVisual(pScreen, pVisual)))
90 return retval;
91 #endif
93 for (i = 0; i < dmxScreen->beNumVisuals; i++) {
94 if (pVisual->class == dmxScreen->beVisuals[i].class &&
95 pVisual->bitsPerRGBValue == dmxScreen->beVisuals[i].bits_per_rgb &&
96 pVisual->ColormapEntries == dmxScreen->beVisuals[i].colormap_size &&
97 pVisual->nplanes == dmxScreen->beVisuals[i].depth &&
98 pVisual->redMask == dmxScreen->beVisuals[i].red_mask &&
99 pVisual->greenMask == dmxScreen->beVisuals[i].green_mask &&
100 pVisual->blueMask == dmxScreen->beVisuals[i].blue_mask) {
101 return dmxScreen->beVisuals[i].visual;
105 return NULL;
108 /** Return the visual that matched the \a vid. */
109 Visual *dmxLookupVisualFromID(ScreenPtr pScreen, VisualID vid)
111 Visual *visual;
112 int i;
114 if (!dmxScreens[pScreen->myNum].beDisplay)
115 return NULL;
117 for (i = 0; i < pScreen->numVisuals; i++) {
118 if (pScreen->visuals[i].vid == vid) {
119 visual = dmxLookupVisual(pScreen, &pScreen->visuals[i]);
120 if (visual) return visual;
124 return NULL;
127 /** Return the colormap for the \a visual. */
128 Colormap dmxColormapFromDefaultVisual(ScreenPtr pScreen, Visual *visual)
130 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
131 int i;
133 if (dmxScreen->beDisplay) {
134 for (i = 0; i < dmxScreen->beNumDefColormaps; i++)
135 if (visual == dmxScreen->beVisuals[i].visual)
136 return dmxScreen->beDefColormaps[i];
139 return None;