1 /* GDK - The GIMP Drawing Kit
4 * Copyright 2001 Sun Microsystems Inc.
6 * Erwann Chenede <erwann.chenede@sun.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 #include "gdkvisualprivate.h"
25 #include "gdkscreenprivate.h"
30 * @Short_description: Low-level display hardware information
33 * A #GdkVisual describes a particular video hardware display format.
34 * It includes information about the number of bits used for each color,
35 * the way the bits are translated into an RGB value for display, and
36 * the way the bits are stored in memory. For example, a piece of display
37 * hardware might support 24-bit color, 16-bit color, or 8-bit color;
38 * meaning 24/16/8-bit pixel sizes. For a given pixel size, pixels can
39 * be in different formats; for example the "red" element of an RGB pixel
40 * may be in the top 8 bits of the pixel, or may be in the lower 4 bits.
42 * There are several standard visuals. The visual returned by
43 * gdk_screen_get_system_visual() is the system's default visual.
45 * A number of functions are provided for determining the "best" available
46 * visual. For the purposes of making this determination, higher bit depths
47 * are considered better, and for visuals of the same bit depth,
48 * %GDK_VISUAL_PSEUDO_COLOR is preferred at 8bpp, otherwise, the visual
49 * types are ranked in the order of(highest to lowest)
50 * %GDK_VISUAL_DIRECT_COLOR, %GDK_VISUAL_TRUE_COLOR,
51 * %GDK_VISUAL_PSEUDO_COLOR, %GDK_VISUAL_STATIC_COLOR,
52 * %GDK_VISUAL_GRAYSCALE, then %GDK_VISUAL_STATIC_GRAY.
55 G_DEFINE_TYPE (GdkVisual, gdk_visual, G_TYPE_OBJECT)
58 gdk_visual_init (GdkVisual *visual)
63 gdk_visual_finalize (GObject *object)
65 G_OBJECT_CLASS (gdk_visual_parent_class)->finalize (object);
69 gdk_visual_class_init (GdkVisualClass *visual_class)
71 GObjectClass *object_class = G_OBJECT_CLASS (visual_class);
73 object_class->finalize = gdk_visual_finalize;
79 * Lists the available visuals for the default screen.
80 * (See gdk_screen_list_visuals())
81 * A visual describes a hardware image data format.
82 * For example, a visual might support 24-bit color, or 8-bit color,
83 * and might expect pixels to be in a certain format.
85 * Call g_list_free() on the return value when you're finished with it.
87 * Return value: (transfer container) (element-type GdkVisual):
88 * a list of visuals; the list must be freed, but not its contents
91 gdk_list_visuals (void)
93 return gdk_screen_list_visuals (gdk_screen_get_default ());
97 * gdk_visual_get_system:
99 * Get the system's default visual for the default GDK screen.
100 * This is the visual for the root window of the display.
101 * The return value should not be freed.
103 * Return value: (transfer none): system visual
106 gdk_visual_get_system (void)
108 return gdk_screen_get_system_visual (gdk_screen_get_default());
112 * gdk_visual_get_best_depth:
114 * Get the best available depth for the default GDK screen. "Best"
115 * means "largest," i.e. 32 preferred over 24 preferred over 8 bits
118 * Return value: best available depth
121 gdk_visual_get_best_depth (void)
123 GdkScreen *screen = gdk_screen_get_default();
125 return GDK_SCREEN_GET_CLASS(screen)->visual_get_best_depth (screen);
129 * gdk_visual_get_best_type:
131 * Return the best available visual type for the default GDK screen.
133 * Return value: best visual type
136 gdk_visual_get_best_type (void)
138 GdkScreen *screen = gdk_screen_get_default();
140 return GDK_SCREEN_GET_CLASS(screen)->visual_get_best_type (screen);
144 * gdk_visual_get_best:
146 * Get the visual with the most available colors for the default
147 * GDK screen. The return value should not be freed.
149 * Return value: (transfer none): best visual
152 gdk_visual_get_best (void)
154 GdkScreen *screen = gdk_screen_get_default();
156 return GDK_SCREEN_GET_CLASS(screen)->visual_get_best (screen);
160 * gdk_visual_get_best_with_depth:
161 * @depth: a bit depth
163 * Get the best visual with depth @depth for the default GDK screen.
164 * Color visuals and visuals with mutable colormaps are preferred
165 * over grayscale or fixed-colormap visuals. The return value should
166 * not be freed. %NULL may be returned if no visual supports @depth.
168 * Return value: (transfer none): best visual for the given depth
171 gdk_visual_get_best_with_depth (gint depth)
173 GdkScreen *screen = gdk_screen_get_default();
175 return GDK_SCREEN_GET_CLASS(screen)->visual_get_best_with_depth (screen, depth);
179 * gdk_visual_get_best_with_type:
180 * @visual_type: a visual type
182 * Get the best visual of the given @visual_type for the default GDK screen.
183 * Visuals with higher color depths are considered better. The return value
184 * should not be freed. %NULL may be returned if no visual has type
187 * Return value: (transfer none): best visual of the given type
190 gdk_visual_get_best_with_type (GdkVisualType visual_type)
192 GdkScreen *screen = gdk_screen_get_default();
194 return GDK_SCREEN_GET_CLASS(screen)->visual_get_best_with_type (screen,
199 * gdk_visual_get_best_with_both:
200 * @depth: a bit depth
201 * @visual_type: a visual type
203 * Combines gdk_visual_get_best_with_depth() and
204 * gdk_visual_get_best_with_type().
206 * Return value: (transfer none): best visual with both @depth and
207 * @visual_type, or %NULL if none
210 gdk_visual_get_best_with_both (gint depth,
211 GdkVisualType visual_type)
213 GdkScreen *screen = gdk_screen_get_default();
215 return GDK_SCREEN_GET_CLASS(screen)->visual_get_best_with_both (screen, depth, visual_type);
220 * @depths: (out) (array length=count) (transfer none): return
221 * location for available depths
222 * @count: return location for number of available depths
224 * This function returns the available bit depths for the default
225 * screen. It's equivalent to listing the visuals
226 * (gdk_list_visuals()) and then looking at the depth field in each
227 * visual, removing duplicates.
229 * The array returned by this function should not be freed.
232 gdk_query_depths (gint **depths,
235 GdkScreen *screen = gdk_screen_get_default();
237 GDK_SCREEN_GET_CLASS(screen)->query_depths (screen, depths, count);
241 * gdk_query_visual_types:
242 * @visual_types: (out) (array length=count) (transfer none): return
243 * location for the available visual types
244 * @count: return location for the number of available visual types
246 * This function returns the available visual types for the default
247 * screen. It's equivalent to listing the visuals
248 * (gdk_list_visuals()) and then looking at the type field in each
249 * visual, removing duplicates.
251 * The array returned by this function should not be freed.
254 gdk_query_visual_types (GdkVisualType **visual_types,
257 GdkScreen *screen = gdk_screen_get_default();
259 GDK_SCREEN_GET_CLASS(screen)->query_visual_types (screen, visual_types, count);
263 * gdk_visual_get_visual_type:
264 * @visual: A #GdkVisual.
266 * Returns the type of visual this is (PseudoColor, TrueColor, etc).
268 * Return value: A #GdkVisualType stating the type of @visual.
273 gdk_visual_get_visual_type (GdkVisual *visual)
275 g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
281 * gdk_visual_get_depth:
282 * @visual: A #GdkVisual.
284 * Returns the bit depth of this visual.
286 * Return value: The bit depth of this visual.
291 gdk_visual_get_depth (GdkVisual *visual)
293 g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
295 return visual->depth;
299 * gdk_visual_get_byte_order:
300 * @visual: A #GdkVisual.
302 * Returns the byte order of this visual.
304 * Return value: A #GdkByteOrder stating the byte order of @visual.
309 gdk_visual_get_byte_order (GdkVisual *visual)
311 g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
313 return visual->byte_order;
317 * gdk_visual_get_colormap_size:
318 * @visual: A #GdkVisual.
320 * Returns the size of a colormap for this visual.
322 * Return value: The size of a colormap that is suitable for @visual.
327 gdk_visual_get_colormap_size (GdkVisual *visual)
329 g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
331 return visual->colormap_size;
335 * gdk_visual_get_bits_per_rgb:
336 * @visual: a #GdkVisual
338 * Returns the number of significant bits per red, green and blue value.
340 * Return value: The number of significant bits per color value for @visual.
345 gdk_visual_get_bits_per_rgb (GdkVisual *visual)
347 g_return_val_if_fail (GDK_IS_VISUAL (visual), 0);
349 return visual->bits_per_rgb;
353 * gdk_visual_get_red_pixel_details:
354 * @visual: A #GdkVisual
355 * @mask: (out) (allow-none): A pointer to a #guint32 to be filled in, or %NULL
356 * @shift: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL
357 * @precision: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL
359 * Obtains values that are needed to calculate red pixel values in TrueColor
360 * and DirectColor. The "mask" is the significant bits within the pixel.
361 * The "shift" is the number of bits left we must shift a primary for it
362 * to be in position (according to the "mask"). Finally, "precision" refers
363 * to how much precision the pixel value contains for a particular primary.
368 gdk_visual_get_red_pixel_details (GdkVisual *visual,
373 g_return_if_fail (GDK_IS_VISUAL (visual));
376 *mask = visual->red_mask;
379 *shift = visual->red_shift;
382 *precision = visual->red_prec;
386 * gdk_visual_get_green_pixel_details:
387 * @visual: a #GdkVisual
388 * @mask: (out) (allow-none): A pointer to a #guint32 to be filled in, or %NULL
389 * @shift: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL
390 * @precision: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL
392 * Obtains values that are needed to calculate green pixel values in TrueColor
393 * and DirectColor. The "mask" is the significant bits within the pixel.
394 * The "shift" is the number of bits left we must shift a primary for it
395 * to be in position (according to the "mask"). Finally, "precision" refers
396 * to how much precision the pixel value contains for a particular primary.
401 gdk_visual_get_green_pixel_details (GdkVisual *visual,
406 g_return_if_fail (GDK_IS_VISUAL (visual));
409 *mask = visual->green_mask;
412 *shift = visual->green_shift;
415 *precision = visual->green_prec;
419 * gdk_visual_get_blue_pixel_details:
420 * @visual: a #GdkVisual
421 * @mask: (out) (allow-none): A pointer to a #guint32 to be filled in, or %NULL
422 * @shift: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL
423 * @precision: (out) (allow-none): A pointer to a #gint to be filled in, or %NULL
425 * Obtains values that are needed to calculate blue pixel values in TrueColor
426 * and DirectColor. The "mask" is the significant bits within the pixel.
427 * The "shift" is the number of bits left we must shift a primary for it
428 * to be in position (according to the "mask"). Finally, "precision" refers
429 * to how much precision the pixel value contains for a particular primary.
434 gdk_visual_get_blue_pixel_details (GdkVisual *visual,
439 g_return_if_fail (GDK_IS_VISUAL (visual));
442 *mask = visual->blue_mask;
445 *shift = visual->blue_shift;
448 *precision = visual->blue_prec;
452 * gdk_visual_get_screen:
453 * @visual: a #GdkVisual
455 * Gets the screen to which this visual belongs
457 * Return value: (transfer none): the screen to which this visual belongs.
462 gdk_visual_get_screen (GdkVisual *visual)
464 g_return_val_if_fail (GDK_IS_VISUAL (visual), NULL);
466 return visual->screen;