Gnash
0.8.10
|
00001 /* 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 Lesser 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 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser 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 #include <gdk/gdkdrawable.h> 00021 00022 #include <cairo-xlib.h> 00023 #include <gtk/gtk.h> 00024 #ifndef _WIN32 00025 #include <gdk/gdkx.h> 00026 #else 00027 #include <gdk/gdk.h> 00028 #endif 00029 00030 00031 /* copied from gtk+/gdk/gdkcairo.c and gtk+/gdk/x11/gdkdrawable-x11.c 00032 * gdk_cairo_create() is be available in gtk 2.8 00033 */ 00034 static cairo_t * 00035 gdk_cairo_create (GdkDrawable *target) 00036 { 00037 int width, height; 00038 int x_off=0, y_off=0; 00039 cairo_t *cr; 00040 cairo_surface_t *surface; 00041 GdkDrawable *drawable = target; 00042 GdkVisual *visual; 00043 00044 if (GDK_IS_WINDOW(target)) { 00045 /* query the window's backbuffer if it has one */ 00046 GdkWindow *window = GDK_WINDOW(target); 00047 gdk_window_get_internal_paint_info (window, 00048 &drawable, &x_off, &y_off); 00049 } 00050 visual = gdk_drawable_get_visual (drawable); 00051 gdk_drawable_get_size (drawable, &width, &height); 00052 00053 if (visual) { 00054 surface = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY (drawable), 00055 GDK_DRAWABLE_XID (drawable), 00056 GDK_VISUAL_XVISUAL (visual), 00057 width, height); 00058 } else if (gdk_drawable_get_depth (drawable) == 1) { 00059 surface = cairo_xlib_surface_create_for_bitmap 00060 (GDK_PIXMAP_XDISPLAY (drawable), 00061 GDK_PIXMAP_XID (drawable), 00062 GDK_SCREEN_XSCREEN (gdk_drawable_get_screen (drawable)), 00063 width, height); 00064 } else { 00065 g_warning ("Using Cairo rendering requires the drawable argument to\n" 00066 "have a specified colormap. All windows have a colormap,\n" 00067 "however, pixmaps only have colormap by default if they\n" 00068 "were created with a non-NULL window argument. Otherwise\n" 00069 "a colormap must be set on them with " 00070 "gdk_drawable_set_colormap"); 00071 return NULL; 00072 } 00073 cairo_surface_set_device_offset (surface, -x_off, -y_off); 00074 cr = cairo_create (surface); 00075 cairo_surface_destroy (surface); 00076 return cr; 00077 }