comparison src/video/Xext/XmuStdCmap/AllCmap.c @ 2185:2032348afed1

This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is available and to keep people form having to install yet another library I have added the essential parts of Xmu in src/video/extensions/XmuStdCmap and an include file in src/video/extensions. The support makes use of standard X11 mechanisms to create color maps and make sure that an application uses the same color map for each window/visual combination. This should make it possible for gamma support to be implemented based on a single color map per application. Hurm... it looks like "make indent" modified a few extra files. Those are getting committed too.
author Bob Pendleton <bob@pendleton.com>
date Thu, 12 Jul 2007 20:00:50 +0000
parents
children
comparison
equal deleted inserted replaced
2184:8f8516e79a13 2185:2032348afed1
1 /* $Xorg: AllCmap.c,v 1.4 2001/02/09 02:03:51 xorgcvs Exp $ */
2
3 /*
4
5 Copyright 1989, 1998 The Open Group
6
7 Permission to use, copy, modify, distribute, and sell this software and its
8 documentation for any purpose is hereby granted without fee, provided that
9 the above copyright notice appear in all copies and that both that
10 copyright notice and this permission notice appear in supporting
11 documentation.
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23 Except as contained in this notice, the name of The Open Group shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from The Open Group.
26
27 */
28 /* $XFree86: xc/lib/Xmu/AllCmap.c,v 1.7 2001/01/17 19:42:53 dawes Exp $ */
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 #include <stdio.h>
34 #include <X11/Xlib.h>
35 #include <X11/Xatom.h>
36 #include <X11/Xutil.h>
37 #include "../extensions/StdCmap.h"
38
39 static XVisualInfo *getDeepestVisual(int, XVisualInfo *, int);
40
41 /*
42 * To create all of the appropriate standard colormaps for every visual of
43 * every screen on a given display, use XmuAllStandardColormaps.
44 *
45 * Define and retain as permanent resources all standard colormaps which are
46 * meaningful for the visuals of each screen of the display. Return 0 on
47 * failure, non-zero on success. If the property of any standard colormap
48 * is already defined, redefine it.
49 *
50 * This interface is intended to be used by window managers or a client
51 * upon start-up of a session.
52 *
53 * The standard colormaps of a screen are defined by properties associated
54 * with the screen's root window. Each screen has exactly one root window.
55 * The property names of standard colormaps are predefined, and each property
56 * name may describe at most one colormap.
57 *
58 * The standard colormaps are
59 * RGB_BEST_MAP
60 * RGB_RED_MAP
61 * RGB_GREEN_MAP
62 * RGB_BLUE_MAP
63 * RGB_DEFAULT_MAP
64 * RGB_GRAY_MAP
65 *
66 * Therefore a screen may have at most 6 standard colormap properties defined.
67 *
68 * A standard colormap is associated with a particular visual of the screen.
69 * A screen may have multiple visuals defined, including visuals of the same
70 * class at different depths. Note that a visual id might be repeated for
71 * more than one depth, so the visual id and the depth of a visual identify
72 * the visual. The characteristics of the visual will determine which
73 * standard colormaps are meaningful under that visual, and will determine
74 * how the standard colormap is defined. Because a standard colormap is
75 * associated with a specific visual, there must be a method of determining
76 * which visuals take precedence in defining standard colormaps.
77 *
78 * The method used here is: for the visual of greatest depth, define all
79 * standard colormaps meaningful to that visual class, according to this
80 * order of (descending) precedence:
81 * 1. DirectColor
82 * 2. PseudoColor
83 * 3. TrueColor and GrayScale
84 * 4. StaticColor and StaticGray
85 *
86 * Allows partial success by screenful. For example, if a map on screen 1
87 * fails, the maps on screen 0, created earlier, will remain. However,
88 * none on screen 1 will remain. If a map on 0 fails, none will remain.
89 *
90 * See the comments under XmuVisualStandardColormaps() for notes on which
91 * standard colormaps are meaningful under these classes of visuals.
92 */
93
94 Status
95 XmuAllStandardColormaps(Display * dpy)
96 {
97 int nvisuals, scr;
98 Status status;
99 long vinfo_mask;
100 XVisualInfo template, *vinfo, *v1, *v2;
101
102 status = 0;
103 /* for each screen, determine all visuals of this server */
104 for (scr = 0; scr < ScreenCount(dpy); scr++) {
105 template.screen = scr;
106 vinfo_mask = VisualScreenMask;
107 vinfo = XGetVisualInfo(dpy, vinfo_mask, &template, &nvisuals);
108 if (vinfo == NULL) /* unexpected: a screen with no visuals */
109 continue;
110
111 v1 = getDeepestVisual(DirectColor, vinfo, nvisuals);
112 v2 = getDeepestVisual(PseudoColor, vinfo, nvisuals);
113
114 if (v2 &&
115 (!v1 || (v2->colormap_size >=
116 ((v1->red_mask | v1->green_mask | v1->blue_mask) + 1))))
117 status = XmuVisualStandardColormaps(dpy, scr, v2->visualid,
118 (unsigned) v2->depth, 1, 1);
119 else if (v1)
120 status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
121 (unsigned) v1->depth, 1, 1);
122
123 else {
124 if (((v1 = getDeepestVisual(TrueColor, vinfo, nvisuals)) != NULL)
125 || ((v1 = getDeepestVisual(StaticColor, vinfo, nvisuals)) !=
126 NULL))
127 status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
128 (unsigned) v1->depth, 1,
129 1);
130 if (status
131 &&
132 (((v1 = getDeepestVisual(GrayScale, vinfo, nvisuals)) != NULL)
133 || ((v1 = getDeepestVisual(StaticGray, vinfo, nvisuals)) !=
134 NULL)))
135 status =
136 XmuVisualStandardColormaps(dpy, scr, v1->visualid,
137 (unsigned) v1->depth, 1, 1);
138 }
139 XFree((char *) vinfo);
140 if (!status)
141 break;
142 }
143 return status;
144 }
145
146 static XVisualInfo *
147 getDeepestVisual(int visual_class, XVisualInfo * vinfo, int nvisuals)
148 {
149 register int i;
150 register int maxdepth = 0;
151 XVisualInfo *v = NULL;
152
153 for (i = 0; i < nvisuals; i++, vinfo++)
154 if (vinfo->class == visual_class && vinfo->depth > maxdepth) {
155 maxdepth = vinfo->depth;
156 v = vinfo;
157 }
158 return (v);
159 }