]> Pileus Git - ~andy/gtk/blob - gdk/linux-fb/gdkvisual-fb.c
Better error messages.
[~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
31 static GdkVisual *system_visual = NULL;
32
33 void
34 gdk_visual_init (void)
35 {
36   system_visual = g_new0 (GdkVisual, 1);
37
38   system_visual->depth = system_visual->bits_per_rgb = gdk_display->modeinfo.bits_per_pixel;
39   system_visual->byte_order = GDK_LSB_FIRST;
40   system_visual->colormap_size = 0;
41
42   switch (gdk_display->sinfo.visual)
43     {
44     case FB_VISUAL_PSEUDOCOLOR:
45       system_visual->colormap_size = 1 << gdk_display->modeinfo.bits_per_pixel;
46       system_visual->type = GDK_VISUAL_PSEUDO_COLOR;
47       break;
48     case FB_VISUAL_DIRECTCOLOR:
49       /* TODO: Should load the colormap to ramps here, as they might be initialized to
50          some other garbage */
51       
52       /* Fall through */
53     case FB_VISUAL_TRUECOLOR:
54       system_visual->type = GDK_VISUAL_TRUE_COLOR;
55
56       system_visual->red_prec = gdk_display->modeinfo.red.length;
57       system_visual->red_shift = gdk_display->modeinfo.red.offset;
58       system_visual->red_mask = ((1 << (system_visual->red_prec)) - 1) << system_visual->red_shift;
59
60       system_visual->green_prec = gdk_display->modeinfo.green.length;
61       system_visual->green_shift = gdk_display->modeinfo.green.offset;
62       system_visual->green_mask = ((1 << (system_visual->green_prec)) - 1) << system_visual->green_shift;
63
64       system_visual->blue_prec = gdk_display->modeinfo.blue.length;
65       system_visual->blue_shift = gdk_display->modeinfo.blue.offset;
66       system_visual->blue_mask = ((1 << (system_visual->blue_prec)) - 1) << system_visual->blue_shift;
67       break;
68     case FB_VISUAL_STATIC_PSEUDOCOLOR:
69       system_visual->type = GDK_VISUAL_STATIC_COLOR;
70       system_visual->colormap_size = 1 << gdk_display->modeinfo.bits_per_pixel;
71       break;
72     default:
73       g_assert_not_reached ();
74       break;
75     }
76 }
77
78 GdkVisual*
79 gdk_visual_ref (GdkVisual *visual)
80 {
81   return visual;
82 }
83
84 void
85 gdk_visual_unref (GdkVisual *visual)
86 {
87 }
88
89 gint
90 gdk_visual_get_best_depth (void)
91 {
92   return system_visual->depth;
93 }
94
95 GdkVisualType
96 gdk_visual_get_best_type (void)
97 {
98   return system_visual->type;
99 }
100
101 GdkVisual*
102 gdk_visual_get_system (void)
103 {
104   return system_visual;
105 }
106
107 GdkVisual*
108 gdk_visual_get_best (void)
109 {
110   return system_visual;
111 }
112
113 GdkVisual*
114 gdk_visual_get_best_with_depth (gint depth)
115 {
116   if (system_visual->depth != depth)
117     return NULL;
118
119   return system_visual;
120 }
121
122 GdkVisual*
123 gdk_visual_get_best_with_type (GdkVisualType visual_type)
124 {
125   if (system_visual->type != visual_type)
126     return NULL;
127
128   return system_visual;
129 }
130
131 GdkVisual*
132 gdk_visual_get_best_with_both (gint          depth,
133                                GdkVisualType visual_type)
134 {
135   if (system_visual->depth != depth)
136     return NULL;
137
138   if (system_visual->type != visual_type)
139     return NULL;
140
141   return system_visual;
142 }
143
144 void
145 gdk_query_depths  (gint **depths,
146                    gint  *count)
147 {
148   *count = 1;
149   *depths = &system_visual->depth;
150 }
151
152 void
153 gdk_query_visual_types (GdkVisualType **visual_types,
154                         gint           *count)
155 {
156   *count = 1;
157   *visual_types = &system_visual->type;
158 }
159
160 GList*
161 gdk_list_visuals (void)
162 {
163   return g_list_append (NULL, gdk_visual_get_system ());
164 }