1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gdkvisual.h"
30 #include "gdkprivate-win32.h"
32 static void gdk_visual_decompose_mask (gulong mask,
36 static GdkVisualPrivate *system_visual;
38 static gint available_depths[1];
40 static GdkVisualType available_types[1];
44 static const gchar* visual_names[] =
54 #endif /* G_ENABLE_DEBUG */
57 gdk_visual_init (void)
70 int rastercaps, numcolors, sizepalette, bitspixel;
72 system_visual = g_new (GdkVisualPrivate, 1);
74 bitspixel = GetDeviceCaps (gdk_DC, BITSPIXEL);
75 rastercaps = GetDeviceCaps (gdk_DC, RASTERCAPS);
76 system_visual->xvisual = g_new (Visual, 1);
77 system_visual->xvisual->visualid = 0;
78 system_visual->xvisual->bitspixel = bitspixel;
80 if (rastercaps & RC_PALETTE)
82 system_visual->visual.type = GDK_VISUAL_PSEUDO_COLOR;
83 numcolors = GetDeviceCaps (gdk_DC, NUMCOLORS);
84 sizepalette = GetDeviceCaps (gdk_DC, SIZEPALETTE);
85 system_visual->xvisual->map_entries = sizepalette;
87 else if (bitspixel == 1)
89 system_visual->visual.type = GDK_VISUAL_STATIC_GRAY;
90 system_visual->xvisual->map_entries = 2;
92 else if (bitspixel == 4)
94 system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
95 system_visual->xvisual->map_entries = 16;
97 else if (bitspixel == 8)
99 system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
100 system_visual->xvisual->map_entries = 256;
102 else if (bitspixel == 16)
104 system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
106 /* This code by Mike Enright,
107 * see http://www.users.cts.com/sd/m/menright/display.html
109 memset (&bmi, 0, sizeof (bmi));
110 bmi.bi.biSize = sizeof (bmi.bi);
112 hbm = CreateCompatibleBitmap (gdk_DC, 1, 1);
113 GetDIBits (gdk_DC, hbm, 0, 1, NULL,
114 (BITMAPINFO *) &bmi, DIB_RGB_COLORS);
115 GetDIBits (gdk_DC, hbm, 0, 1, NULL,
116 (BITMAPINFO *) &bmi, DIB_RGB_COLORS);
119 if (bmi.bi.biCompression != BI_BITFIELDS)
121 /* Either BI_RGB or BI_RLE_something
122 * .... or perhaps (!!) something else.
123 * Theoretically biCompression might be
124 * mmioFourCC('c','v','i','d') but I doubt it.
126 if (bmi.bi.biCompression == BI_RGB)
130 system_visual->visual.red_mask = 0x00007C00;
131 system_visual->visual.green_mask = 0x000003E0;
132 system_visual->visual.blue_mask = 0x0000001F;
136 g_assert_not_reached ();
142 bmi.u.fields[0] | bmi.u.fields[1] | bmi.u.fields[2];
151 system_visual->visual.red_mask = bmi.u.fields[0];
152 system_visual->visual.green_mask = bmi.u.fields[1];
153 system_visual->visual.blue_mask = bmi.u.fields[2];
156 /* Old, incorrect (but still working) code. */
158 system_visual->visual.red_mask = 0x0000F800;
159 system_visual->visual.green_mask = 0x000007E0;
160 system_visual->visual.blue_mask = 0x0000001F;
162 system_visual->visual.red_mask = 0x00007C00;
163 system_visual->visual.green_mask = 0x000003E0;
164 system_visual->visual.blue_mask = 0x0000001F;
168 else if (bitspixel == 24 || bitspixel == 32)
171 system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
172 system_visual->visual.red_mask = 0x00FF0000;
173 system_visual->visual.green_mask = 0x0000FF00;
174 system_visual->visual.blue_mask = 0x000000FF;
177 g_error ("gdk_visual_init: unsupported BITSPIXEL: %d\n", bitspixel);
179 system_visual->visual.depth = bitspixel;
180 system_visual->visual.byte_order = GDK_LSB_FIRST;
181 system_visual->visual.bits_per_rgb = 42; /* Not used? */
183 if ((system_visual->visual.type == GDK_VISUAL_TRUE_COLOR) ||
184 (system_visual->visual.type == GDK_VISUAL_DIRECT_COLOR))
186 gdk_visual_decompose_mask (system_visual->visual.red_mask,
187 &system_visual->visual.red_shift,
188 &system_visual->visual.red_prec);
190 gdk_visual_decompose_mask (system_visual->visual.green_mask,
191 &system_visual->visual.green_shift,
192 &system_visual->visual.green_prec);
194 gdk_visual_decompose_mask (system_visual->visual.blue_mask,
195 &system_visual->visual.blue_shift,
196 &system_visual->visual.blue_prec);
197 system_visual->xvisual->map_entries =
198 1 << (MAX (system_visual->visual.red_prec,
199 MAX (system_visual->visual.green_prec,
200 system_visual->visual.blue_prec)));
204 system_visual->visual.red_mask = 0;
205 system_visual->visual.red_shift = 0;
206 system_visual->visual.red_prec = 0;
208 system_visual->visual.green_mask = 0;
209 system_visual->visual.green_shift = 0;
210 system_visual->visual.green_prec = 0;
212 system_visual->visual.blue_mask = 0;
213 system_visual->visual.blue_shift = 0;
214 system_visual->visual.blue_prec = 0;
216 system_visual->visual.colormap_size = system_visual->xvisual->map_entries;
218 available_depths[0] = system_visual->visual.depth;
219 available_types[0] = system_visual->visual.type;
223 gdk_visual_ref (GdkVisual *visual)
229 gdk_visual_unref (GdkVisual *visual)
235 gdk_visual_get_best_depth (void)
237 return available_depths[0];
241 gdk_visual_get_best_type (void)
243 return available_types[0];
247 gdk_visual_get_system (void)
249 return ((GdkVisual*) system_visual);
253 gdk_visual_get_best (void)
255 return ((GdkVisual*) system_visual);
259 gdk_visual_get_best_with_depth (gint depth)
261 if (depth == system_visual->visual.depth)
262 return (GdkVisual*) system_visual;
268 gdk_visual_get_best_with_type (GdkVisualType visual_type)
270 if (visual_type == system_visual->visual.type)
271 return (GdkVisual*) system_visual;
277 gdk_visual_get_best_with_both (gint depth,
278 GdkVisualType visual_type)
280 if ((depth == system_visual->visual.depth) &&
281 (visual_type == system_visual->visual.type))
282 return (GdkVisual*) system_visual;
288 gdk_query_depths (gint **depths,
292 *depths = available_depths;
296 gdk_query_visual_types (GdkVisualType **visual_types,
300 *visual_types = available_types;
304 gdk_list_visuals (void)
306 return g_list_append (NULL, (gpointer) system_visual);
310 gdk_visual_lookup (Visual *xvisual)
312 if (system_visual->xvisual == xvisual)
313 return (GdkVisual *) system_visual;
319 gdk_visual_decompose_mask (gulong mask,
326 while (!(mask & 0x1))