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 Lesser 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser 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-2000. 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/.
27 #include "gdkvisual.h"
28 #include "gdkprivate-fb.h"
29 #include "gdkinternals.h"
30 #include <sys/ioctl.h>
32 static GdkVisual *system_visual = NULL;
35 gdk_visual_finalize (GObject *object)
37 g_error ("A GdkVisual object was finalized. This should not happen");
41 gdk_visual_class_init (GObjectClass *class)
43 class->finalize = gdk_visual_finalize;
48 gdk_visual_get_type (void)
50 static GType object_type = 0;
54 static const GTypeInfo object_info =
56 sizeof (GdkVisualClass),
58 (GBaseFinalizeFunc) NULL,
59 (GClassInitFunc) gdk_visual_class_init,
60 NULL, /* class_finalize */
61 NULL, /* class_data */
64 (GInstanceInitFunc) NULL,
67 object_type = g_type_register_static (G_TYPE_OBJECT,
76 _gdk_visual_init (void)
78 system_visual = g_object_new (GDK_TYPE_VISUAL, NULL);
80 system_visual->depth = system_visual->bits_per_rgb = gdk_display->modeinfo.bits_per_pixel;
81 system_visual->byte_order = GDK_LSB_FIRST;
82 system_visual->colormap_size = 0;
84 switch (gdk_display->sinfo.visual)
86 case FB_VISUAL_PSEUDOCOLOR:
87 system_visual->colormap_size = 1 << gdk_display->modeinfo.bits_per_pixel;
88 system_visual->type = GDK_VISUAL_PSEUDO_COLOR;
90 case FB_VISUAL_DIRECTCOLOR:
91 case FB_VISUAL_TRUECOLOR:
92 system_visual->type = GDK_VISUAL_TRUE_COLOR;
94 system_visual->red_prec = gdk_display->modeinfo.red.length;
95 system_visual->red_shift = gdk_display->modeinfo.red.offset;
96 system_visual->red_mask = ((1 << (system_visual->red_prec)) - 1) << system_visual->red_shift;
98 system_visual->green_prec = gdk_display->modeinfo.green.length;
99 system_visual->green_shift = gdk_display->modeinfo.green.offset;
100 system_visual->green_mask = ((1 << (system_visual->green_prec)) - 1) << system_visual->green_shift;
102 system_visual->blue_prec = gdk_display->modeinfo.blue.length;
103 system_visual->blue_shift = gdk_display->modeinfo.blue.offset;
104 system_visual->blue_mask = ((1 << (system_visual->blue_prec)) - 1) << system_visual->blue_shift;
106 if (gdk_display->sinfo.visual == FB_VISUAL_DIRECTCOLOR)
108 guint16 red[256], green[256], blue[256];
109 struct fb_cmap fbc = {0,0};
111 /* Load the colormap to ramps here, as they might be initialized to
112 some other garbage */
114 g_warning ("Directcolor visual, not very well tested\n");
119 size = 1 << system_visual->red_prec;
120 for (i = 0; i < size; i++)
121 red[i] = i * 65535 / (size - 1);
123 size = 1 << system_visual->green_prec;
125 for (i = 0; i < size; i++)
126 green[i] = i * 65535 / (size - 1);
128 size = 1 << system_visual->blue_prec;
129 for (i = 0; i < size; i++)
130 blue[i] = i * 65535 / (size - 1);
132 ioctl (gdk_display->fb_fd, FBIOPUTCMAP, &fbc);
135 case FB_VISUAL_STATIC_PSEUDOCOLOR:
136 system_visual->type = GDK_VISUAL_STATIC_COLOR;
137 system_visual->colormap_size = 1 << gdk_display->modeinfo.bits_per_pixel;
140 g_assert_not_reached ();
146 gdk_visual_get_best_depth (void)
148 return system_visual->depth;
152 gdk_visual_get_best_type (void)
154 return system_visual->type;
158 gdk_visual_get_system (void)
160 return system_visual;
164 gdk_visual_get_best (void)
166 return system_visual;
170 gdk_visual_get_best_with_depth (gint depth)
172 if (system_visual->depth != depth)
175 return system_visual;
179 gdk_visual_get_best_with_type (GdkVisualType visual_type)
181 if (system_visual->type != visual_type)
184 return system_visual;
188 gdk_visual_get_best_with_both (gint depth,
189 GdkVisualType visual_type)
191 if (system_visual->depth != depth)
194 if (system_visual->type != visual_type)
197 return system_visual;
201 gdk_query_depths (gint **depths,
205 *depths = &system_visual->depth;
209 gdk_query_visual_types (GdkVisualType **visual_types,
213 *visual_types = &system_visual->type;
217 gdk_list_visuals (void)
219 return g_list_append (NULL, gdk_visual_get_system ());