Gnash  0.8.11dev
gtk_cairo_create.h
Go to the documentation of this file.
1 /* GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 #include <gdk/gdkdrawable.h>
21 
22 #include <cairo-xlib.h>
23 #include <gtk/gtk.h>
24 #ifndef _WIN32
25 #include <gdk/gdkx.h>
26 #else
27 #include <gdk/gdk.h>
28 #endif
29 
30 
31 /* copied from gtk+/gdk/gdkcairo.c and gtk+/gdk/x11/gdkdrawable-x11.c
32  * gdk_cairo_create() is be available in gtk 2.8
33  */
34 static cairo_t *
35 gdk_cairo_create (GdkDrawable *target)
36 {
37  int width, height;
38  int x_off=0, y_off=0;
39  cairo_t *cr;
40  cairo_surface_t *surface;
41  GdkDrawable *drawable = target;
42  GdkVisual *visual;
43 
44  if (GDK_IS_WINDOW(target)) {
45  /* query the window's backbuffer if it has one */
46  GdkWindow *window = GDK_WINDOW(target);
47  gdk_window_get_internal_paint_info (window,
48  &drawable, &x_off, &y_off);
49  }
50  visual = gdk_drawable_get_visual (drawable);
51  gdk_drawable_get_size (drawable, &width, &height);
52 
53  if (visual) {
54  surface = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY (drawable),
55  GDK_DRAWABLE_XID (drawable),
56  GDK_VISUAL_XVISUAL (visual),
57  width, height);
58  } else if (gdk_drawable_get_depth (drawable) == 1) {
59  surface = cairo_xlib_surface_create_for_bitmap
60  (GDK_PIXMAP_XDISPLAY (drawable),
61  GDK_PIXMAP_XID (drawable),
62  GDK_SCREEN_XSCREEN (gdk_drawable_get_screen (drawable)),
63  width, height);
64  } else {
65  g_warning ("Using Cairo rendering requires the drawable argument to\n"
66  "have a specified colormap. All windows have a colormap,\n"
67  "however, pixmaps only have colormap by default if they\n"
68  "were created with a non-NULL window argument. Otherwise\n"
69  "a colormap must be set on them with "
70  "gdk_drawable_set_colormap");
71  return NULL;
72  }
73  cairo_surface_set_device_offset (surface, -x_off, -y_off);
74  cr = cairo_create (surface);
75  cairo_surface_destroy (surface);
76  return cr;
77 }
Definition: klash_part.cpp:329
Definition: klash_part.cpp:329