]> Pileus Git - ~andy/gtk/blob - gdk/linux-fb/gdkvisual-fb.c
Don't mangle sequences of consecutive \n or \r.
[~andy/gtk] / gdk / linux-fb / gdkvisual-fb.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "gdkvisual.h"
28 #include "gdkprivate-fb.h"
29 #include "gdkinternals.h"
30 #include <sys/ioctl.h>
31
32 static GdkVisual *system_visual = NULL;
33
34 static void
35 gdk_visual_finalize (GObject *object)
36 {
37   g_error ("A GdkVisual object was finalized. This should not happen");
38 }
39
40 static void
41 gdk_visual_class_init (GObjectClass *class)
42 {
43   class->finalize = gdk_visual_finalize;
44 }
45
46
47 GType
48 gdk_visual_get_type (void)
49 {
50   static GType object_type = 0;
51
52   if (!object_type)
53     {
54       static const GTypeInfo object_info =
55       {
56         sizeof (GdkVisualClass),
57         (GBaseInitFunc) NULL,
58         (GBaseFinalizeFunc) NULL,
59         (GClassInitFunc) gdk_visual_class_init,
60         NULL,           /* class_finalize */
61         NULL,           /* class_data */
62         sizeof (GdkVisual),
63         0,              /* n_preallocs */
64         (GInstanceInitFunc) NULL,
65       };
66       
67       object_type = g_type_register_static (G_TYPE_OBJECT,
68                                             "GdkVisual",
69                                             &object_info, 0);
70     }
71   
72   return object_type;
73 }
74
75 void
76 _gdk_visual_init (void)
77 {
78   system_visual = g_object_new (GDK_TYPE_VISUAL, NULL);
79
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;
83
84   switch (gdk_display->sinfo.visual)
85     {
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;
89       break;
90     case FB_VISUAL_DIRECTCOLOR:
91     case FB_VISUAL_TRUECOLOR:
92       system_visual->type = GDK_VISUAL_TRUE_COLOR;
93
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;
97
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;
101
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;
105
106       if (gdk_display->sinfo.visual == FB_VISUAL_DIRECTCOLOR) 
107         {
108           guint16 red[256], green[256], blue[256];
109           struct fb_cmap fbc = {0,0};
110           int size, i;
111           /* Load the colormap to ramps here, as they might be initialized to
112              some other garbage */
113           
114           g_warning ("Directcolor visual, not very well tested\n");
115           fbc.red = red;
116           fbc.green = green;
117           fbc.blue = blue;
118           
119           size = 1 << system_visual->red_prec;
120           for (i = 0; i < size; i++)
121             red[i] = i * 65535 / (size - 1);
122           
123           size = 1 << system_visual->green_prec;
124           fbc.len = size;
125           for (i = 0; i < size; i++)
126             green[i] = i * 65535 / (size - 1);
127           
128           size = 1 << system_visual->blue_prec;
129           for (i = 0; i < size; i++)
130             blue[i] = i * 65535 / (size - 1);
131           
132           ioctl (gdk_display->fb_fd, FBIOPUTCMAP, &fbc);
133         }
134       break;
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;
138       break;
139     default:
140       g_assert_not_reached ();
141       break;
142     }
143 }
144
145 gint
146 gdk_visual_get_best_depth (void)
147 {
148   return system_visual->depth;
149 }
150
151 GdkVisualType
152 gdk_visual_get_best_type (void)
153 {
154   return system_visual->type;
155 }
156
157 GdkVisual*
158 gdk_visual_get_system (void)
159 {
160   return system_visual;
161 }
162
163 GdkVisual*
164 gdk_visual_get_best (void)
165 {
166   return system_visual;
167 }
168
169 GdkVisual*
170 gdk_visual_get_best_with_depth (gint depth)
171 {
172   if (system_visual->depth != depth)
173     return NULL;
174
175   return system_visual;
176 }
177
178 GdkVisual*
179 gdk_visual_get_best_with_type (GdkVisualType visual_type)
180 {
181   if (system_visual->type != visual_type)
182     return NULL;
183
184   return system_visual;
185 }
186
187 GdkVisual*
188 gdk_visual_get_best_with_both (gint          depth,
189                                GdkVisualType visual_type)
190 {
191   if (system_visual->depth != depth)
192     return NULL;
193
194   if (system_visual->type != visual_type)
195     return NULL;
196
197   return system_visual;
198 }
199
200 void
201 gdk_query_depths  (gint **depths,
202                    gint  *count)
203 {
204   *count = 1;
205   *depths = &system_visual->depth;
206 }
207
208 void
209 gdk_query_visual_types (GdkVisualType **visual_types,
210                         gint           *count)
211 {
212   *count = 1;
213   *visual_types = &system_visual->type;
214 }
215
216 GList*
217 gdk_list_visuals (void)
218 {
219   return g_list_append (NULL, gdk_visual_get_system ());
220 }