1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998-2002 Tor Lillqvist
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
21 * file for a list of people on the GTK+ Team. See the ChangeLog
22 * files for a list of changes. These files are distributed with
23 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gdkvisual.h"
30 #include "gdkscreen.h" /* gdk_screen_get_default() */
31 #include "gdkprivate-win32.h"
32 #include "gdkvisualprivate.h"
34 static void gdk_visual_decompose_mask (gulong mask,
38 static GdkVisual *system_visual = NULL;
40 static gint available_depths[1];
42 static GdkVisualType available_types[1];
45 _gdk_visual_init (void)
58 const gint rastercaps = GetDeviceCaps (_gdk_display_hdc, RASTERCAPS);
59 const int numcolors = GetDeviceCaps (_gdk_display_hdc, NUMCOLORS);
60 gint bitspixel = GetDeviceCaps (_gdk_display_hdc, BITSPIXEL);
63 system_visual = g_object_new (GDK_TYPE_VISUAL, NULL);
64 system_visual->screen = gdk_screen_get_default();
66 if (rastercaps & RC_PALETTE)
68 const int sizepalette = GetDeviceCaps (_gdk_display_hdc, SIZEPALETTE);
69 gchar *max_colors = getenv ("GDK_WIN32_MAX_COLORS");
70 system_visual->type = GDK_VISUAL_PSEUDO_COLOR;
72 g_assert (sizepalette == 256);
74 if (max_colors != NULL)
75 _gdk_max_colors = atoi (max_colors);
77 map_entries = _gdk_max_colors;
79 if (map_entries >= 16 && map_entries < sizepalette)
84 system_visual->type = GDK_VISUAL_STATIC_COLOR;
87 else if (map_entries < 64)
92 else if (map_entries < 128)
97 else if (map_entries < 256)
103 g_assert_not_reached ();
106 map_entries = sizepalette;
108 else if (bitspixel == 1 && numcolors == 16)
111 system_visual->type = GDK_VISUAL_STATIC_COLOR;
114 else if (bitspixel == 1)
116 system_visual->type = GDK_VISUAL_STATIC_GRAY;
119 else if (bitspixel == 4)
121 system_visual->type = GDK_VISUAL_STATIC_COLOR;
124 else if (bitspixel == 8)
126 system_visual->type = GDK_VISUAL_STATIC_COLOR;
129 else if (bitspixel == 16)
131 system_visual->type = GDK_VISUAL_TRUE_COLOR;
133 /* This code by Mike Enright,
134 * see http://www.users.cts.com/sd/m/menright/display.html
136 memset (&bmi, 0, sizeof (bmi));
137 bmi.bi.biSize = sizeof (bmi.bi);
139 hbm = CreateCompatibleBitmap (_gdk_display_hdc, 1, 1);
140 GetDIBits (_gdk_display_hdc, hbm, 0, 1, NULL,
141 (BITMAPINFO *) &bmi, DIB_RGB_COLORS);
142 GetDIBits (_gdk_display_hdc, hbm, 0, 1, NULL,
143 (BITMAPINFO *) &bmi, DIB_RGB_COLORS);
146 if (bmi.bi.biCompression != BI_BITFIELDS)
148 /* Either BI_RGB or BI_RLE_something
149 * .... or perhaps (!!) something else.
150 * Theoretically biCompression might be
151 * mmioFourCC('c','v','i','d') but I doubt it.
153 if (bmi.bi.biCompression == BI_RGB)
157 system_visual->red_mask = 0x00007C00;
158 system_visual->green_mask = 0x000003E0;
159 system_visual->blue_mask = 0x0000001F;
163 g_assert_not_reached ();
169 bmi.u.fields[0] | bmi.u.fields[1] | bmi.u.fields[2];
178 system_visual->red_mask = bmi.u.fields[0];
179 system_visual->green_mask = bmi.u.fields[1];
180 system_visual->blue_mask = bmi.u.fields[2];
183 /* Old, incorrect (but still working) code. */
185 system_visual->red_mask = 0x0000F800;
186 system_visual->green_mask = 0x000007E0;
187 system_visual->blue_mask = 0x0000001F;
189 system_visual->red_mask = 0x00007C00;
190 system_visual->green_mask = 0x000003E0;
191 system_visual->blue_mask = 0x0000001F;
195 else if (bitspixel == 24 || bitspixel == 32)
198 system_visual->type = GDK_VISUAL_TRUE_COLOR;
199 system_visual->red_mask = 0x00FF0000;
200 system_visual->green_mask = 0x0000FF00;
201 system_visual->blue_mask = 0x000000FF;
204 g_error ("_gdk_visual_init: unsupported BITSPIXEL: %d\n", bitspixel);
206 system_visual->depth = bitspixel;
207 system_visual->byte_order = GDK_LSB_FIRST;
208 system_visual->bits_per_rgb = 42; /* Not used? */
210 if ((system_visual->type == GDK_VISUAL_TRUE_COLOR) ||
211 (system_visual->type == GDK_VISUAL_DIRECT_COLOR))
213 gdk_visual_decompose_mask (system_visual->red_mask,
214 &system_visual->red_shift,
215 &system_visual->red_prec);
217 gdk_visual_decompose_mask (system_visual->green_mask,
218 &system_visual->green_shift,
219 &system_visual->green_prec);
221 gdk_visual_decompose_mask (system_visual->blue_mask,
222 &system_visual->blue_shift,
223 &system_visual->blue_prec);
224 map_entries = 1 << (MAX (system_visual->red_prec,
225 MAX (system_visual->green_prec,
226 system_visual->blue_prec)));
230 system_visual->red_mask = 0;
231 system_visual->red_shift = 0;
232 system_visual->red_prec = 0;
234 system_visual->green_mask = 0;
235 system_visual->green_shift = 0;
236 system_visual->green_prec = 0;
238 system_visual->blue_mask = 0;
239 system_visual->blue_shift = 0;
240 system_visual->blue_prec = 0;
242 system_visual->colormap_size = map_entries;
244 available_depths[0] = system_visual->depth;
245 available_types[0] = system_visual->type;
249 _gdk_win32_screen_visual_get_best_depth (GdkScreen *screen)
251 return available_depths[0];
255 _gdk_win32_screen_visual_get_best_type (GdkScreen *screen)
257 return available_types[0];
261 _gdk_win32_screen_get_system_visual (GdkScreen *screen)
263 return system_visual;
267 _gdk_win32_screen_visual_get_best (GdkScreen *screen)
269 return ((GdkVisual*) system_visual);
273 _gdk_win32_screen_visual_get_best_with_depth (GdkScreen *screen, gint depth)
275 if (depth == system_visual->depth)
276 return (GdkVisual*) system_visual;
282 _gdk_win32_screen_visual_get_best_with_type (GdkScreen *screen, GdkVisualType visual_type)
284 if (visual_type == system_visual->type)
285 return system_visual;
291 _gdk_win32_screen_visual_get_best_with_both (GdkScreen *screen,
293 GdkVisualType visual_type)
295 if ((depth == system_visual->depth) && (visual_type == system_visual->type))
296 return system_visual;
302 _gdk_win32_screen_query_depths (GdkScreen *screen,
307 *depths = available_depths;
311 _gdk_win32_screen_query_visual_types (GdkScreen *screen,
312 GdkVisualType **visual_types,
316 *visual_types = available_types;
320 _gdk_win32_screen_list_visuals (GdkScreen *screen)
322 return g_list_append (NULL, (gpointer) system_visual);
326 gdk_visual_decompose_mask (gulong mask,
333 while (!(mask & 0x1))