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, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gdkvisual.h"
32 #include "gdkscreen.h" /* gdk_screen_get_default() */
33 #include "gdkprivate-win32.h"
34 #include "gdkvisualprivate.h"
36 static void gdk_visual_decompose_mask (gulong mask,
40 static GdkVisual *system_visual = NULL;
42 static gint available_depths[1];
44 static GdkVisualType available_types[1];
47 _gdk_visual_init (void)
60 const gint rastercaps = GetDeviceCaps (_gdk_display_hdc, RASTERCAPS);
61 const int numcolors = GetDeviceCaps (_gdk_display_hdc, NUMCOLORS);
62 gint bitspixel = GetDeviceCaps (_gdk_display_hdc, BITSPIXEL);
65 system_visual = g_object_new (GDK_TYPE_VISUAL, NULL);
66 system_visual->screen = gdk_screen_get_default();
68 GDK_NOTE (COLORMAP, g_print ("BITSPIXEL=%d NUMCOLORS=%d\n",
69 bitspixel, numcolors));
71 if (rastercaps & RC_PALETTE)
73 const int sizepalette = GetDeviceCaps (_gdk_display_hdc, SIZEPALETTE);
74 gchar *max_colors = getenv ("GDK_WIN32_MAX_COLORS");
75 system_visual->type = GDK_VISUAL_PSEUDO_COLOR;
77 GDK_NOTE (COLORMAP, g_print ("SIZEPALETTE=%d\n", sizepalette));
78 g_assert (sizepalette == 256);
80 if (max_colors != NULL)
81 _gdk_max_colors = atoi (max_colors);
83 map_entries = _gdk_max_colors;
85 if (map_entries >= 16 && map_entries < sizepalette)
90 system_visual->type = GDK_VISUAL_STATIC_COLOR;
93 else if (map_entries < 64)
98 else if (map_entries < 128)
103 else if (map_entries < 256)
109 g_assert_not_reached ();
112 map_entries = sizepalette;
114 else if (bitspixel == 1 && numcolors == 16)
117 system_visual->type = GDK_VISUAL_STATIC_COLOR;
120 else if (bitspixel == 1)
122 system_visual->type = GDK_VISUAL_STATIC_GRAY;
125 else if (bitspixel == 4)
127 system_visual->type = GDK_VISUAL_STATIC_COLOR;
130 else if (bitspixel == 8)
132 system_visual->type = GDK_VISUAL_STATIC_COLOR;
135 else if (bitspixel == 16)
137 system_visual->type = GDK_VISUAL_TRUE_COLOR;
139 /* This code by Mike Enright,
140 * see http://www.users.cts.com/sd/m/menright/display.html
142 memset (&bmi, 0, sizeof (bmi));
143 bmi.bi.biSize = sizeof (bmi.bi);
145 hbm = CreateCompatibleBitmap (_gdk_display_hdc, 1, 1);
146 GetDIBits (_gdk_display_hdc, hbm, 0, 1, NULL,
147 (BITMAPINFO *) &bmi, DIB_RGB_COLORS);
148 GetDIBits (_gdk_display_hdc, hbm, 0, 1, NULL,
149 (BITMAPINFO *) &bmi, DIB_RGB_COLORS);
152 if (bmi.bi.biCompression != BI_BITFIELDS)
154 /* Either BI_RGB or BI_RLE_something
155 * .... or perhaps (!!) something else.
156 * Theoretically biCompression might be
157 * mmioFourCC('c','v','i','d') but I doubt it.
159 if (bmi.bi.biCompression == BI_RGB)
163 system_visual->red_mask = 0x00007C00;
164 system_visual->green_mask = 0x000003E0;
165 system_visual->blue_mask = 0x0000001F;
169 g_assert_not_reached ();
175 bmi.u.fields[0] | bmi.u.fields[1] | bmi.u.fields[2];
184 system_visual->red_mask = bmi.u.fields[0];
185 system_visual->green_mask = bmi.u.fields[1];
186 system_visual->blue_mask = bmi.u.fields[2];
189 /* Old, incorrect (but still working) code. */
191 system_visual->red_mask = 0x0000F800;
192 system_visual->green_mask = 0x000007E0;
193 system_visual->blue_mask = 0x0000001F;
195 system_visual->red_mask = 0x00007C00;
196 system_visual->green_mask = 0x000003E0;
197 system_visual->blue_mask = 0x0000001F;
201 else if (bitspixel == 24 || bitspixel == 32)
204 system_visual->type = GDK_VISUAL_TRUE_COLOR;
205 system_visual->red_mask = 0x00FF0000;
206 system_visual->green_mask = 0x0000FF00;
207 system_visual->blue_mask = 0x000000FF;
210 g_error ("_gdk_visual_init: unsupported BITSPIXEL: %d\n", bitspixel);
212 system_visual->depth = bitspixel;
213 system_visual->byte_order = GDK_LSB_FIRST;
214 system_visual->bits_per_rgb = 42; /* Not used? */
216 if ((system_visual->type == GDK_VISUAL_TRUE_COLOR) ||
217 (system_visual->type == GDK_VISUAL_DIRECT_COLOR))
219 gdk_visual_decompose_mask (system_visual->red_mask,
220 &system_visual->red_shift,
221 &system_visual->red_prec);
223 gdk_visual_decompose_mask (system_visual->green_mask,
224 &system_visual->green_shift,
225 &system_visual->green_prec);
227 gdk_visual_decompose_mask (system_visual->blue_mask,
228 &system_visual->blue_shift,
229 &system_visual->blue_prec);
230 map_entries = 1 << (MAX (system_visual->red_prec,
231 MAX (system_visual->green_prec,
232 system_visual->blue_prec)));
236 system_visual->red_mask = 0;
237 system_visual->red_shift = 0;
238 system_visual->red_prec = 0;
240 system_visual->green_mask = 0;
241 system_visual->green_shift = 0;
242 system_visual->green_prec = 0;
244 system_visual->blue_mask = 0;
245 system_visual->blue_shift = 0;
246 system_visual->blue_prec = 0;
248 system_visual->colormap_size = map_entries;
250 available_depths[0] = system_visual->depth;
251 available_types[0] = system_visual->type;
255 _gdk_win32_screen_visual_get_best_depth (GdkScreen *screen)
257 return available_depths[0];
261 _gdk_win32_screen_visual_get_best_type (GdkScreen *screen)
263 return available_types[0];
267 _gdk_win32_screen_get_system_visual (GdkScreen *screen)
269 return system_visual;
273 _gdk_win32_screen_visual_get_best (GdkScreen *screen)
275 return ((GdkVisual*) system_visual);
279 _gdk_win32_screen_visual_get_best_with_depth (GdkScreen *screen, gint depth)
281 if (depth == system_visual->depth)
282 return (GdkVisual*) system_visual;
288 _gdk_win32_screen_visual_get_best_with_type (GdkScreen *screen, GdkVisualType visual_type)
290 if (visual_type == system_visual->type)
291 return system_visual;
297 _gdk_win32_screen_visual_get_best_with_both (GdkScreen *screen,
299 GdkVisualType visual_type)
301 if ((depth == system_visual->depth) && (visual_type == system_visual->type))
302 return system_visual;
308 _gdk_win32_screen_query_depths (GdkScreen *screen,
313 *depths = available_depths;
317 _gdk_win32_screen_query_visual_types (GdkScreen *screen,
318 GdkVisualType **visual_types,
322 *visual_types = available_types;
326 _gdk_win32_screen_list_visuals (GdkScreen *screen)
328 return g_list_append (NULL, (gpointer) system_visual);
332 gdk_visual_decompose_mask (gulong mask,
339 while (!(mask & 0x1))