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/.
28
#include "gdkvisual.h"
29
#include "gdkprivate-fb.h"
30
#include "gdkinternals.h"
31
#include <sys/ioctl.h>
33
static GdkVisual *system_visual = NULL;
36
gdk_visual_finalize (GObject *object)
38
g_error ("A GdkVisual object was finalized. This should not happen");
42
gdk_visual_class_init (GObjectClass *class)
44
class->finalize = gdk_visual_finalize;
49
gdk_visual_get_type (void)
51
static GType object_type = 0;
55
static const GTypeInfo object_info =
57
sizeof (GdkVisualClass),
59
(GBaseFinalizeFunc) NULL,
60
(GClassInitFunc) gdk_visual_class_init,
61
NULL, /* class_finalize */
62
NULL, /* class_data */
65
(GInstanceInitFunc) NULL,
68
object_type = g_type_register_static (G_TYPE_OBJECT,
77
_gdk_visual_init (void)
79
system_visual = g_object_new (GDK_TYPE_VISUAL, NULL);
81
system_visual->depth = system_visual->bits_per_rgb = gdk_display->modeinfo.bits_per_pixel;
82
system_visual->byte_order = GDK_LSB_FIRST;
83
system_visual->colormap_size = 0;
85
switch (gdk_display->sinfo.visual)
87
case FB_VISUAL_PSEUDOCOLOR:
88
system_visual->colormap_size = 1 << gdk_display->modeinfo.bits_per_pixel;
89
system_visual->type = GDK_VISUAL_PSEUDO_COLOR;
91
case FB_VISUAL_DIRECTCOLOR:
92
case FB_VISUAL_TRUECOLOR:
93
system_visual->type = GDK_VISUAL_TRUE_COLOR;
95
system_visual->red_prec = gdk_display->modeinfo.red.length;
96
system_visual->red_shift = gdk_display->modeinfo.red.offset;
97
system_visual->red_mask = ((1 << (system_visual->red_prec)) - 1) << system_visual->red_shift;
99
system_visual->green_prec = gdk_display->modeinfo.green.length;
100
system_visual->green_shift = gdk_display->modeinfo.green.offset;
101
system_visual->green_mask = ((1 << (system_visual->green_prec)) - 1) << system_visual->green_shift;
103
system_visual->blue_prec = gdk_display->modeinfo.blue.length;
104
system_visual->blue_shift = gdk_display->modeinfo.blue.offset;
105
system_visual->blue_mask = ((1 << (system_visual->blue_prec)) - 1) << system_visual->blue_shift;
107
if (gdk_display->sinfo.visual == FB_VISUAL_DIRECTCOLOR)
109
guint16 red[256], green[256], blue[256];
110
struct fb_cmap fbc = {0,0};
112
/* Load the colormap to ramps here, as they might be initialized to
113
some other garbage */
115
g_warning ("Directcolor visual, not very well tested\n");
120
size = 1 << system_visual->red_prec;
121
for (i = 0; i < size; i++)
122
red[i] = i * 65535 / (size - 1);
124
size = 1 << system_visual->green_prec;
126
for (i = 0; i < size; i++)
127
green[i] = i * 65535 / (size - 1);
129
size = 1 << system_visual->blue_prec;
130
for (i = 0; i < size; i++)
131
blue[i] = i * 65535 / (size - 1);
133
ioctl (gdk_display->fb_fd, FBIOPUTCMAP, &fbc);
136
case FB_VISUAL_STATIC_PSEUDOCOLOR:
137
system_visual->type = GDK_VISUAL_STATIC_COLOR;
138
system_visual->colormap_size = 1 << gdk_display->modeinfo.bits_per_pixel;
141
g_assert_not_reached ();
147
gdk_visual_get_best_depth (void)
149
return system_visual->depth;
153
gdk_visual_get_best_type (void)
155
return system_visual->type;
159
gdk_screen_get_system_visual (GdkScreen *screen)
161
return system_visual;
165
gdk_visual_get_best (void)
167
return system_visual;
171
gdk_visual_get_best_with_depth (gint depth)
173
if (system_visual->depth != depth)
176
return system_visual;
180
gdk_visual_get_best_with_type (GdkVisualType visual_type)
182
if (system_visual->type != visual_type)
185
return system_visual;
189
gdk_visual_get_best_with_both (gint depth,
190
GdkVisualType visual_type)
192
if (system_visual->depth != depth)
195
if (system_visual->type != visual_type)
198
return system_visual;
202
gdk_query_depths (gint **depths,
206
*depths = &system_visual->depth;
210
gdk_query_visual_types (GdkVisualType **visual_types,
214
*visual_types = &system_visual->type;
218
gdk_screen_list_visuals (GdkScreen *screen)
220
return g_list_append (NULL, gdk_visual_get_system ());
224
gdk_visual_get_screen (GdkVisual *visual)
226
g_return_val_if_fail (GDK_IS_VISUAL (visual), NULL);
228
return gdk_screen_get_default ();