]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkdrawable-x11.c
Add gdk_drawable_set_cairo_target().
[~andy/gtk] / gdk / x11 / gdkdrawable-x11.c
index c6f3142072a2774932286e53afe91ecf23fea691..19c7b9264a0b2d905f36c5ac9ae3a17f7b0233ba 100644 (file)
@@ -147,6 +147,9 @@ static void gdk_x11_draw_trapezoids (GdkDrawable     *drawable,
                                     GdkTrapezoid    *trapezoids,
                                     gint             n_trapezoids);
 
+static void gdk_x11_set_cairo_target (GdkDrawable *drawable,
+                                     cairo_t     *cr);
+     
 static void gdk_x11_set_colormap   (GdkDrawable    *drawable,
                                     GdkColormap    *colormap);
 
@@ -215,6 +218,8 @@ gdk_drawable_impl_x11_class_init (GdkDrawableImplX11Class *klass)
   drawable_class->draw_pixbuf = gdk_x11_draw_pixbuf;
   drawable_class->draw_trapezoids = gdk_x11_draw_trapezoids;
   
+  drawable_class->set_cairo_target = gdk_x11_set_cairo_target;
+
   drawable_class->set_colormap = gdk_x11_set_colormap;
   drawable_class->get_colormap = gdk_x11_get_colormap;
 
@@ -1558,6 +1563,51 @@ gdk_x11_draw_trapezoids (GdkDrawable  *drawable,
   g_free (xtrapezoids);
 }
 
+static cairo_surface_t *
+gdk_x11_drawable_get_cairo_surface (GdkDrawable *drawable)
+{
+  GdkDrawableImplX11 *impl = GDK_DRAWABLE_IMPL_X11 (drawable);
+  GdkColormap *colormap;
+  GdkVisual *visual;
+
+  if (GDK_IS_WINDOW_IMPL_X11 (drawable) &&
+      GDK_WINDOW_DESTROYED (impl->wrapper))
+    return NULL;
+
+  colormap = gdk_drawable_get_colormap (drawable);
+  if (!colormap)
+    {
+      g_warning ("Using Cairo rendering requires the drawable argument to\n"
+                "have a specified colormap. All windows have a colormap,\n"
+                "however, pixmaps only have colormap by default if they\n"
+                "were created with a non-NULL window argument. Otherwise\n"
+                "a colormap must be set on them with gdk_drawable_set_colormap");
+      return NULL;
+    }
+
+  visual = gdk_colormap_get_visual (colormap);
+
+  if (!impl->cairo_surface)
+    {
+      impl->cairo_surface = cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (impl->screen),
+                                                      impl->xid,
+                                                      GDK_VISUAL_XVISUAL (visual),
+                                                      CAIRO_FORMAT_RGB24,
+                                                      GDK_COLORMAP_XCOLORMAP (colormap));
+    }
+
+  return impl->cairo_surface;
+}
+
+static void
+gdk_x11_set_cairo_target (GdkDrawable *drawable,
+                         cairo_t     *cr)
+{
+  cairo_surface_t *surface = gdk_x11_drawable_get_cairo_surface (drawable);
+  if (surface)
+    cairo_set_target_surface (cr, surface);
+}
+
 /**
  * gdk_draw_rectangle_alpha_libgtk_only:
  * @drawable: The #GdkDrawable to draw on