gdkvisual-win32.c

Go to the documentation of this file.
00001 /* GDK - The GIMP Drawing Kit
00002  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 /*
00021  * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
00022  * file for a list of people on the GTK+ Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
00025  */
00026 
00027 #include "config.h"
00028 
00029 #include "gdkvisual.h"
00030 #include "gdkprivate-win32.h"
00031 
00032 static void gdk_visual_decompose_mask(gulong mask,
00033                                       gint * shift, gint * prec);
00034 
00035 static GdkVisualPrivate *system_visual;
00036 
00037 static gint available_depths[1];
00038 
00039 static GdkVisualType available_types[1];
00040 
00041 #ifdef G_ENABLE_DEBUG
00042 
00043 static const gchar *visual_names[] = {
00044    "static gray",
00045    "grayscale",
00046    "static color",
00047    "pseudo color",
00048    "true color",
00049    "direct color",
00050 };
00051 
00052 #endif                          /* G_ENABLE_DEBUG */
00053 
00054 void gdk_visual_init(void)
00055 {
00056    struct {
00057       BITMAPINFOHEADER bi;
00058       union {
00059          RGBQUAD colors[256];
00060          DWORD fields[256];
00061       } u;
00062    } bmi;
00063    HBITMAP hbm;
00064 
00065    int rastercaps, numcolors, sizepalette, bitspixel;
00066 
00067    system_visual = g_new(GdkVisualPrivate, 1);
00068 
00069    bitspixel = GetDeviceCaps(gdk_DC, BITSPIXEL);
00070    rastercaps = GetDeviceCaps(gdk_DC, RASTERCAPS);
00071    system_visual->xvisual = g_new(Visual, 1);
00072    system_visual->xvisual->visualid = 0;
00073    system_visual->xvisual->bitspixel = bitspixel;
00074 
00075    // temporary solves a strange bug in root in 16 bit mode:
00076    // axis labels background is not the same color than the 
00077    // pad background...
00078    if (bitspixel == 16) bitspixel = 24; 
00079 
00080    if (rastercaps & RC_PALETTE) {
00081       g_error
00082           ("Palettized display (%d-colour) mode not supported on Windows.",
00083            GetDeviceCaps(gdk_DC, SIZEPALETTE));
00084       system_visual->visual.type = GDK_VISUAL_PSEUDO_COLOR;
00085       numcolors = GetDeviceCaps(gdk_DC, NUMCOLORS);
00086       sizepalette = GetDeviceCaps(gdk_DC, SIZEPALETTE);
00087       system_visual->xvisual->map_entries = sizepalette;
00088    } else if (bitspixel == 1) {
00089       system_visual->visual.type = GDK_VISUAL_STATIC_GRAY;
00090       system_visual->xvisual->map_entries = 2;
00091    } else if (bitspixel == 4) {
00092       system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
00093       system_visual->xvisual->map_entries = 16;
00094    } else if (bitspixel == 8) {
00095       system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
00096       system_visual->xvisual->map_entries = 256;
00097    } else if (bitspixel == 16) {
00098       system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
00099 #if 1
00100       /* This code by Mike Enright,
00101        * see http://www.users.cts.com/sd/m/menright/display.html
00102        */
00103       memset(&bmi, 0, sizeof(bmi));
00104       bmi.bi.biSize = sizeof(bmi.bi);
00105 
00106       hbm = CreateCompatibleBitmap(gdk_DC, 1, 1);
00107       GetDIBits(gdk_DC, hbm, 0, 1, NULL,
00108                 (BITMAPINFO *) & bmi, DIB_RGB_COLORS);
00109       GetDIBits(gdk_DC, hbm, 0, 1, NULL,
00110                 (BITMAPINFO *) & bmi, DIB_RGB_COLORS);
00111       DeleteObject(hbm);
00112 
00113       if (bmi.bi.biCompression != BI_BITFIELDS) {
00114          /* Either BI_RGB or BI_RLE_something
00115           * .... or perhaps (!!) something else.
00116           * Theoretically biCompression might be
00117           * mmioFourCC('c','v','i','d') but I doubt it.
00118           */
00119          if (bmi.bi.biCompression == BI_RGB) {
00120             /* It's 555 */
00121             bitspixel = 15;
00122             system_visual->visual.red_mask = 0x00007C00;
00123             system_visual->visual.green_mask = 0x000003E0;
00124             system_visual->visual.blue_mask = 0x0000001F;
00125          } else {
00126             g_assert_not_reached();
00127          }
00128       } else {
00129          DWORD allmasks =
00130              bmi.u.fields[0] | bmi.u.fields[1] | bmi.u.fields[2];
00131          int k = 0;
00132          while (allmasks) {
00133             if (allmasks & 1)
00134                k++;
00135             allmasks /= 2;
00136          }
00137          bitspixel = k;
00138          system_visual->visual.red_mask = bmi.u.fields[0];
00139          system_visual->visual.green_mask = bmi.u.fields[1];
00140          system_visual->visual.blue_mask = bmi.u.fields[2];
00141       }
00142 #else
00143       /* Old, incorrect (but still working) code. */
00144 #if 0
00145       system_visual->visual.red_mask = 0x0000F800;
00146       system_visual->visual.green_mask = 0x000007E0;
00147       system_visual->visual.blue_mask = 0x0000001F;
00148 #else
00149       system_visual->visual.red_mask = 0x00007C00;
00150       system_visual->visual.green_mask = 0x000003E0;
00151       system_visual->visual.blue_mask = 0x0000001F;
00152 #endif
00153 #endif
00154    } else if (bitspixel == 24 || bitspixel == 32) {
00155 //      bitspixel = 24;
00156       system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
00157       system_visual->visual.red_mask = 0x00FF0000;
00158       system_visual->visual.green_mask = 0x0000FF00;
00159       system_visual->visual.blue_mask = 0x000000FF;
00160    } else
00161       g_error("gdk_visual_init: unsupported BITSPIXEL: %d\n", bitspixel);
00162 
00163    system_visual->visual.depth = bitspixel;
00164    system_visual->visual.byte_order = GDK_LSB_FIRST;
00165    system_visual->visual.bits_per_rgb = 42;     /* Not used? */
00166 
00167    if ((system_visual->visual.type == GDK_VISUAL_TRUE_COLOR) ||
00168        (system_visual->visual.type == GDK_VISUAL_DIRECT_COLOR)) {
00169       gdk_visual_decompose_mask(system_visual->visual.red_mask,
00170                                 &system_visual->visual.red_shift,
00171                                 &system_visual->visual.red_prec);
00172 
00173       gdk_visual_decompose_mask(system_visual->visual.green_mask,
00174                                 &system_visual->visual.green_shift,
00175                                 &system_visual->visual.green_prec);
00176 
00177       gdk_visual_decompose_mask(system_visual->visual.blue_mask,
00178                                 &system_visual->visual.blue_shift,
00179                                 &system_visual->visual.blue_prec);
00180       system_visual->xvisual->map_entries =
00181           1 << (MAX(system_visual->visual.red_prec,
00182                     MAX(system_visual->visual.green_prec,
00183                         system_visual->visual.blue_prec)));
00184    } else {
00185       system_visual->visual.red_mask = 0;
00186       system_visual->visual.red_shift = 0;
00187       system_visual->visual.red_prec = 0;
00188 
00189       system_visual->visual.green_mask = 0;
00190       system_visual->visual.green_shift = 0;
00191       system_visual->visual.green_prec = 0;
00192 
00193       system_visual->visual.blue_mask = 0;
00194       system_visual->visual.blue_shift = 0;
00195       system_visual->visual.blue_prec = 0;
00196    }
00197    system_visual->visual.colormap_size =
00198        system_visual->xvisual->map_entries;
00199 
00200    available_depths[0] = system_visual->visual.depth;
00201    available_types[0] = system_visual->visual.type;
00202 }
00203 
00204 GdkVisual *gdk_visual_ref(GdkVisual * visual)
00205 {
00206    return visual;
00207 }
00208 
00209 void gdk_visual_unref(GdkVisual * visual)
00210 {
00211    return;
00212 }
00213 
00214 gint gdk_visual_get_best_depth(void)
00215 {
00216    return available_depths[0];
00217 }
00218 
00219 GdkVisualType gdk_visual_get_best_type(void)
00220 {
00221    return available_types[0];
00222 }
00223 
00224 GdkVisual *gdk_visual_get_system(void)
00225 {
00226    return ((GdkVisual *) system_visual);
00227 }
00228 
00229 GdkVisual *gdk_visual_get_best(void)
00230 {
00231    return ((GdkVisual *) system_visual);
00232 }
00233 
00234 GdkVisual *gdk_visual_get_best_with_depth(gint depth)
00235 {
00236    if (depth == system_visual->visual.depth)
00237       return (GdkVisual *) system_visual;
00238    else
00239       return NULL;
00240 }
00241 
00242 GdkVisual *gdk_visual_get_best_with_type(GdkVisualType visual_type)
00243 {
00244    if (visual_type == system_visual->visual.type)
00245       return (GdkVisual *) system_visual;
00246    else
00247       return NULL;
00248 }
00249 
00250 GdkVisual *gdk_visual_get_best_with_both(gint depth,
00251                                          GdkVisualType visual_type)
00252 {
00253    if ((depth == system_visual->visual.depth) &&
00254        (visual_type == system_visual->visual.type))
00255       return (GdkVisual *) system_visual;
00256    else
00257       return NULL;
00258 }
00259 
00260 void gdk_query_depths(gint ** depths, gint * count)
00261 {
00262    *count = 1;
00263    *depths = available_depths;
00264 }
00265 
00266 void gdk_query_visual_types(GdkVisualType ** visual_types, gint * count)
00267 {
00268    *count = 1;
00269    *visual_types = available_types;
00270 }
00271 
00272 GList *gdk_list_visuals(void)
00273 {
00274    return g_list_append(NULL, (gpointer) system_visual);
00275 }
00276 
00277 static void
00278 gdk_visual_decompose_mask(gulong mask, gint * shift, gint * prec)
00279 {
00280    *shift = 0;
00281    *prec = 0;
00282 
00283    while (!(mask & 0x1)) {
00284       (*shift)++;
00285       mask >>= 1;
00286    }
00287 
00288    while (mask & 0x1) {
00289       (*prec)++;
00290       mask >>= 1;
00291    }
00292 }

Generated on Tue Jul 5 14:14:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1