Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright 2002-2004 Red Hat Inc., Durham, North Carolina. | |
3 | * | |
4 | * All Rights Reserved. | |
5 | * | |
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: | |
13 | * | |
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. | |
17 | * | |
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. | |
26 | */ | |
27 | ||
28 | /* | |
29 | * Authors: | |
30 | * Kevin E. Martin <kem@redhat.com> | |
31 | * | |
32 | */ | |
33 | ||
34 | /** \file | |
35 | * This file provides support for visuals. */ | |
36 | ||
37 | #ifdef HAVE_DMX_CONFIG_H | |
38 | #include <dmx-config.h> | |
39 | #endif | |
40 | ||
41 | #include "dmx.h" | |
42 | #include "dmxvisual.h" | |
43 | ||
44 | #include "scrnintstr.h" | |
45 | ||
46 | #ifdef GLXEXT | |
47 | ||
48 | #include <GL/glxint.h> | |
49 | ||
50 | extern VisualID glxMatchVisualInConfigList(ScreenPtr pScreen, | |
51 | VisualPtr pVisual, | |
52 | __GLXvisualConfig * configs, | |
53 | int nconfigs); | |
54 | ||
55 | static Visual * | |
56 | dmxLookupGLXVisual(ScreenPtr pScreen, VisualPtr pVisual) | |
57 | { | |
58 | DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum]; | |
59 | int j; | |
60 | VisualID vid; | |
61 | ||
62 | vid = glxMatchVisualInConfigList(pScreen, pVisual, | |
63 | dmxScreen->glxVisuals, | |
64 | dmxScreen->numGlxVisuals); | |
65 | if (vid) { | |
66 | /* Find the X visual of the matching GLX visual */ | |
67 | for (j = 0; j < dmxScreen->beNumVisuals; j++) | |
68 | if (vid == dmxScreen->beVisuals[j].visualid) | |
69 | return dmxScreen->beVisuals[j].visual; | |
70 | } | |
71 | ||
72 | /* No matching visual found */ | |
73 | return NULL; | |
74 | } | |
75 | #endif | |
76 | ||
77 | /** Return the visual that matched \a pVisual. */ | |
78 | Visual * | |
79 | dmxLookupVisual(ScreenPtr pScreen, VisualPtr pVisual) | |
80 | { | |
81 | DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum]; | |
82 | int i; | |
83 | ||
84 | #ifdef GLXEXT | |
85 | Visual *retval; | |
86 | #endif | |
87 | ||
88 | if (!dmxScreen->beDisplay) | |
89 | return NULL; | |
90 | ||
91 | #ifdef GLXEXT | |
92 | if ((retval = dmxLookupGLXVisual(pScreen, pVisual))) | |
93 | return retval; | |
94 | #endif | |
95 | ||
96 | for (i = 0; i < dmxScreen->beNumVisuals; i++) { | |
97 | if (pVisual->class == dmxScreen->beVisuals[i].class && | |
98 | pVisual->bitsPerRGBValue == dmxScreen->beVisuals[i].bits_per_rgb && | |
99 | pVisual->ColormapEntries == dmxScreen->beVisuals[i].colormap_size && | |
100 | pVisual->nplanes == dmxScreen->beVisuals[i].depth && | |
101 | pVisual->redMask == dmxScreen->beVisuals[i].red_mask && | |
102 | pVisual->greenMask == dmxScreen->beVisuals[i].green_mask && | |
103 | pVisual->blueMask == dmxScreen->beVisuals[i].blue_mask) { | |
104 | return dmxScreen->beVisuals[i].visual; | |
105 | } | |
106 | } | |
107 | ||
108 | return NULL; | |
109 | } | |
110 | ||
111 | /** Return the visual that matched the \a vid. */ | |
112 | Visual * | |
113 | dmxLookupVisualFromID(ScreenPtr pScreen, VisualID vid) | |
114 | { | |
115 | Visual *visual; | |
116 | int i; | |
117 | ||
118 | if (!dmxScreens[pScreen->myNum].beDisplay) | |
119 | return NULL; | |
120 | ||
121 | for (i = 0; i < pScreen->numVisuals; i++) { | |
122 | if (pScreen->visuals[i].vid == vid) { | |
123 | visual = dmxLookupVisual(pScreen, &pScreen->visuals[i]); | |
124 | if (visual) | |
125 | return visual; | |
126 | } | |
127 | } | |
128 | ||
129 | return NULL; | |
130 | } | |
131 | ||
132 | /** Return the colormap for the \a visual. */ | |
133 | Colormap | |
134 | dmxColormapFromDefaultVisual(ScreenPtr pScreen, Visual * visual) | |
135 | { | |
136 | DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum]; | |
137 | int i; | |
138 | ||
139 | if (dmxScreen->beDisplay) { | |
140 | for (i = 0; i < dmxScreen->beNumDefColormaps; i++) | |
141 | if (visual == dmxScreen->beVisuals[i].visual) | |
142 | return dmxScreen->beDefColormaps[i]; | |
143 | } | |
144 | ||
145 | return None; | |
146 | } |