Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00032
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
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 }