| 1 |
/* gdkvisual-quartz.c |
| 2 |
* |
| 3 |
* Copyright (C) 2005 Imendio AB |
| 4 |
* |
| 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. |
| 9 |
* |
| 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. |
| 14 |
* |
| 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. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include "gdkvisual.h" |
| 24 |
#include "gdkprivate-quartz.h" |
| 25 |
|
| 26 |
static GdkVisual *system_visual; |
| 27 |
static GdkVisual *rgba_visual; |
| 28 |
static GdkVisual *gray_visual; |
| 29 |
|
| 30 |
static void |
| 31 |
gdk_visual_finalize (GObject *object) |
| 32 |
{ |
| 33 |
g_error ("A GdkVisual object was finalized. This should not happen"); |
| 34 |
} |
| 35 |
|
| 36 |
static void |
| 37 |
gdk_visual_class_init (GObjectClass *class) |
| 38 |
{ |
| 39 |
class->finalize = gdk_visual_finalize; |
| 40 |
} |
| 41 |
|
| 42 |
GType |
| 43 |
gdk_visual_get_type (void) |
| 44 |
{ |
| 45 |
static GType object_type = 0; |
| 46 |
|
| 47 |
if (!object_type) |
| 48 |
{ |
| 49 |
const GTypeInfo object_info = |
| 50 |
{ |
| 51 |
sizeof (GdkVisualClass), |
| 52 |
(GBaseInitFunc) NULL, |
| 53 |
(GBaseFinalizeFunc) NULL, |
| 54 |
(GClassInitFunc) gdk_visual_class_init, |
| 55 |
NULL, /* class_finalize */ |
| 56 |
NULL, /* class_data */ |
| 57 |
sizeof (GdkVisual), |
| 58 |
0, /* n_preallocs */ |
| 59 |
(GInstanceInitFunc) NULL, |
| 60 |
}; |
| 61 |
|
| 62 |
object_type = g_type_register_static (G_TYPE_OBJECT, |
| 63 |
"GdkVisual", |
| 64 |
&object_info, 0); |
| 65 |
} |
| 66 |
|
| 67 |
return object_type; |
| 68 |
} |
| 69 |
|
| 70 |
static void |
| 71 |
gdk_visual_decompose_mask (gulong mask, |
| 72 |
gint *shift, |
| 73 |
gint *prec) |
| 74 |
{ |
| 75 |
*shift = 0; |
| 76 |
*prec = 0; |
| 77 |
|
| 78 |
while (!(mask & 0x1)) |
| 79 |
{ |
| 80 |
(*shift)++; |
| 81 |
mask >>= 1; |
| 82 |
} |
| 83 |
|
| 84 |
while (mask & 0x1) |
| 85 |
{ |
| 86 |
(*prec)++; |
| 87 |
mask >>= 1; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
static GdkVisual * |
| 92 |
create_standard_visual (gint depth) |
| 93 |
{ |
| 94 |
GdkVisual *visual = g_object_new (GDK_TYPE_VISUAL, NULL); |
| 95 |
|
| 96 |
visual->depth = depth; |
| 97 |
visual->byte_order = GDK_MSB_FIRST; /* FIXME: Should this be different on intel macs? */ |
| 98 |
visual->colormap_size = 0; |
| 99 |
|
| 100 |
visual->type = GDK_VISUAL_TRUE_COLOR; |
| 101 |
|
| 102 |
visual->red_mask = 0xff0000; |
| 103 |
visual->green_mask = 0xff00; |
| 104 |
visual->blue_mask = 0xff; |
| 105 |
|
| 106 |
gdk_visual_decompose_mask (visual->red_mask, |
| 107 |
&visual->red_shift, |
| 108 |
&visual->red_prec); |
| 109 |
gdk_visual_decompose_mask (visual->green_mask, |
| 110 |
&visual->green_shift, |
| 111 |
&visual->green_prec); |
| 112 |
gdk_visual_decompose_mask (visual->blue_mask, |
| 113 |
&visual->blue_shift, |
| 114 |
&visual->blue_prec); |
| 115 |
|
| 116 |
return visual; |
| 117 |
} |
| 118 |
|
| 119 |
static GdkVisual * |
| 120 |
create_gray_visual (void) |
| 121 |
{ |
| 122 |
GdkVisual *visual = g_object_new (GDK_TYPE_VISUAL, NULL); |
| 123 |
|
| 124 |
visual->depth = 1; |
| 125 |
visual->byte_order = GDK_MSB_FIRST; |
| 126 |
visual->colormap_size = 0; |
| 127 |
|
| 128 |
visual->type = GDK_VISUAL_STATIC_GRAY; |
| 129 |
|
| 130 |
return visual; |
| 131 |
} |
| 132 |
|
| 133 |
void |
| 134 |
_gdk_visual_init (void) |
| 135 |
{ |
| 136 |
system_visual = create_standard_visual (24); |
| 137 |
rgba_visual = create_standard_visual (32); |
| 138 |
gray_visual = create_gray_visual (); |
| 139 |
} |
| 140 |
|
| 141 |
/* We prefer the system visual for now ... */ |
| 142 |
gint |
| 143 |
gdk_visual_get_best_depth (void) |
| 144 |
{ |
| 145 |
return system_visual->depth; |
| 146 |
} |
| 147 |
|
| 148 |
GdkVisualType |
| 149 |
gdk_visual_get_best_type (void) |
| 150 |
{ |
| 151 |
return system_visual->type; |
| 152 |
} |
| 153 |
|
| 154 |
GdkVisual * |
| 155 |
gdk_screen_get_rgba_visual (GdkScreen *screen) |
| 156 |
{ |
| 157 |
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); |
| 158 |
|
| 159 |
return rgba_visual; |
| 160 |
} |
| 161 |
|
| 162 |
GdkVisual* |
| 163 |
gdk_screen_get_system_visual (GdkScreen *screen) |
| 164 |
{ |
| 165 |
return system_visual; |
| 166 |
} |
| 167 |
|
| 168 |
GdkVisual* |
| 169 |
gdk_visual_get_best (void) |
| 170 |
{ |
| 171 |
return system_visual; |
| 172 |
} |
| 173 |
|
| 174 |
GdkVisual* |
| 175 |
gdk_visual_get_best_with_depth (gint depth) |
| 176 |
{ |
| 177 |
GdkVisual *visual = NULL; |
| 178 |
|
| 179 |
switch (depth) |
| 180 |
{ |
| 181 |
case 32: |
| 182 |
visual = rgba_visual; |
| 183 |
break; |
| 184 |
|
| 185 |
case 24: |
| 186 |
visual = system_visual; |
| 187 |
break; |
| 188 |
|
| 189 |
case 1: |
| 190 |
visual = gray_visual; |
| 191 |
break; |
| 192 |
|
| 193 |
default: |
| 194 |
visual = NULL; |
| 195 |
} |
| 196 |
|
| 197 |
return visual; |
| 198 |
} |
| 199 |
|
| 200 |
GdkVisual* |
| 201 |
gdk_visual_get_best_with_type (GdkVisualType visual_type) |
| 202 |
{ |
| 203 |
if (system_visual->type == visual_type) |
| 204 |
return system_visual; |
| 205 |
else if (gray_visual->type == visual_type) |
| 206 |
return gray_visual; |
| 207 |
|
| 208 |
return NULL; |
| 209 |
} |
| 210 |
|
| 211 |
GdkVisual* |
| 212 |
gdk_visual_get_best_with_both (gint depth, |
| 213 |
GdkVisualType visual_type) |
| 214 |
{ |
| 215 |
if (system_visual->depth == depth |
| 216 |
&& system_visual->type == visual_type) |
| 217 |
return system_visual; |
| 218 |
else if (rgba_visual->depth == depth |
| 219 |
&& rgba_visual->type == visual_type) |
| 220 |
return rgba_visual; |
| 221 |
else if (gray_visual->depth == depth |
| 222 |
&& gray_visual->type == visual_type) |
| 223 |
return gray_visual; |
| 224 |
|
| 225 |
return NULL; |
| 226 |
} |
| 227 |
|
| 228 |
/* For these, we also prefer the system visual */ |
| 229 |
void |
| 230 |
gdk_query_depths (gint **depths, |
| 231 |
gint *count) |
| 232 |
{ |
| 233 |
*count = 1; |
| 234 |
*depths = &system_visual->depth; |
| 235 |
} |
| 236 |
|
| 237 |
void |
| 238 |
gdk_query_visual_types (GdkVisualType **visual_types, |
| 239 |
gint *count) |
| 240 |
{ |
| 241 |
*count = 1; |
| 242 |
*visual_types = &system_visual->type; |
| 243 |
} |
| 244 |
|
| 245 |
GList* |
| 246 |
gdk_screen_list_visuals (GdkScreen *screen) |
| 247 |
{ |
| 248 |
GList *visuals = NULL; |
| 249 |
|
| 250 |
visuals = g_list_append (visuals, system_visual); |
| 251 |
visuals = g_list_append (visuals, rgba_visual); |
| 252 |
visuals = g_list_append (visuals, gray_visual); |
| 253 |
|
| 254 |
return visuals; |
| 255 |
} |
| 256 |
|
| 257 |
GdkScreen * |
| 258 |
gdk_visual_get_screen (GdkVisual *visual) |
| 259 |
{ |
| 260 |
g_return_val_if_fail (GDK_IS_VISUAL (visual), NULL); |
| 261 |
|
| 262 |
return gdk_screen_get_default (); |
| 263 |
} |
| 264 |
|