]> Pileus Git - ~andy/gtk/commitdiff
API: Change offscreen windows to use a cairo_surface_t
authorBenjamin Otte <otte@redhat.com>
Thu, 26 Aug 2010 11:46:34 +0000 (13:46 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 26 Sep 2010 13:11:29 +0000 (15:11 +0200)
This requires changes to all the offscreen surface getters that used to
return a GdkPixmap before.

13 files changed:
demos/gtk-demo/offscreen_window.c
demos/gtk-demo/offscreen_window2.c
docs/reference/gdk/gdk3-sections.txt
docs/reference/gtk/gtk3-sections.txt
gdk/gdk.symbols
gdk/gdkoffscreenwindow.c
gdk/gdkwindow.c
gdk/gdkwindow.h
gtk/gtk.symbols
gtk/gtkoffscreenwindow.c
gtk/gtkoffscreenwindow.h
tests/gtkoffscreenbox.c
tests/testoffscreenwindow.c

index 0e0d067206852067b7bc38bdbf19a9864af2131c..b1d766e5a0aad3bce4c9d3de76faabbf2453402a 100644 (file)
@@ -485,13 +485,13 @@ gtk_rotated_bin_expose (GtkWidget      *widget,
       window = gtk_widget_get_window (widget);
       if (event->window == window)
         {
-          GdkPixmap *pixmap;
+          cairo_surface_t *surface;
           GtkAllocation child_area;
           cairo_t *cr;
 
           if (bin->child && gtk_widget_get_visible (bin->child))
             {
-              pixmap = gdk_offscreen_window_get_pixmap (bin->offscreen_window);
+              surface = gdk_offscreen_window_get_surface (bin->offscreen_window);
               gtk_widget_get_allocation (bin->child, &child_area);
 
               cr = gdk_cairo_create (window);
@@ -508,11 +508,11 @@ gtk_rotated_bin_expose (GtkWidget      *widget,
               cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
 
               /* clip */
-              gdk_drawable_get_size (pixmap, &width, &height);
+              gdk_drawable_get_size (bin->offscreen_window, &width, &height);
               cairo_rectangle (cr, 0, 0, width, height);
               cairo_clip (cr);
               /* paint */
-              gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+              cairo_set_source_surface (cr, surface, 0, 0);
               cairo_paint (cr);
 
               cairo_destroy (cr);
index d162a360e78e91d8bf4b83c3cc1585dd3edbc3d2..fcc32140751290e4dedf9f7b82eeeac31c3098c5 100644 (file)
@@ -389,15 +389,15 @@ gtk_mirror_bin_expose (GtkWidget      *widget,
       window = gtk_widget_get_window (widget);
       if (event->window == window)
         {
-          GdkPixmap *pixmap;
+          cairo_surface_t *surface;
           cairo_t *cr;
           cairo_matrix_t matrix;
           cairo_pattern_t *mask;
 
           if (bin->child && gtk_widget_get_visible (bin->child))
             {
-              pixmap = gdk_offscreen_window_get_pixmap (bin->offscreen_window);
-              gdk_drawable_get_size (pixmap, &width, &height);
+              surface = gdk_offscreen_window_get_surface (bin->offscreen_window);
+              gdk_drawable_get_size (bin->offscreen_window, &width, &height);
 
               cr = gdk_cairo_create (window);
 
@@ -407,7 +407,7 @@ gtk_mirror_bin_expose (GtkWidget      *widget,
               cairo_clip (cr);
 
               /* paint the offscreen child */
-              gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+              cairo_set_source_surface (cr, surface, 0, 0);
               cairo_paint (cr);
 
               cairo_restore (cr);
@@ -420,7 +420,7 @@ gtk_mirror_bin_expose (GtkWidget      *widget,
               cairo_rectangle (cr, 0, height, width, height);
               cairo_clip (cr);
 
-              gdk_cairo_set_source_pixmap (cr, pixmap, 0, height);
+              cairo_set_source_surface (cr, surface, 0, height);
 
               /* create linear gradient as mask-pattern to fade out the source */
               mask = cairo_pattern_create_linear (0.0, height, 0.0, 2*height);
index 85b1015a9d4c764b8f132951c725feb89ba47c7b..cfb8b00c6b8d793b2bb49462be595808eb17019b 100644 (file)
@@ -530,7 +530,7 @@ GdkPointerHooks
 gdk_set_pointer_hooks
 
 <SUBSECTION>
-gdk_offscreen_window_get_pixmap
+gdk_offscreen_window_get_surface
 gdk_offscreen_window_set_embedder
 gdk_offscreen_window_get_embedder
 gdk_window_geometry_changed
index c9e13f5d907c8ddd2175838bb1e0b80cf35400ec..62e4835277a5f4f1563923f0442e38f72e0e3bd8 100644 (file)
@@ -2266,7 +2266,7 @@ GTK_OBJECT_UNSET_FLAGS
 <TITLE>GtkOffscreenWindow</TITLE>
 GtkOffscreenWindow
 gtk_offscreen_window_new
-gtk_offscreen_window_get_pixmap
+gtk_offscreen_window_get_surface
 gtk_offscreen_window_get_pixbuf
 <SUBSECTION Standard>
 GTK_OFFSCREEN_WINDOW
index 4d2526eb3b1f58d846a8c845841f9d6022f7382f..8891e0f5e50ee9b3c33b59b2923f3069e88432f8 100644 (file)
@@ -668,7 +668,7 @@ gdk_window_get_device_position
 
 #if IN_HEADER(__GDK_WINDOW_H__)
 #if IN_FILE(__GDK_OFFSCREEN_WINDOW_C__)
-gdk_offscreen_window_get_pixmap
+gdk_offscreen_window_get_surface
 gdk_offscreen_window_set_embedder
 gdk_offscreen_window_get_embedder
 #endif
index 30df772522ab1310ac4cdb5ad9e60506128b94ef..3e7e9bbc63f2ee4b5afc88b112a31977b69d50a4 100644 (file)
@@ -30,7 +30,6 @@
 #include "gdkwindow.h"
 #include "gdkinternals.h"
 #include "gdkwindowimpl.h"
-#include "gdkpixmap.h"
 #include "gdkdrawable.h"
 #include "gdktypes.h"
 #include "gdkscreen.h"
@@ -55,7 +54,7 @@ struct _GdkOffscreenWindow
   GdkColormap *colormap;
   GdkScreen *screen;
 
-  GdkPixmap *pixmap;
+  cairo_surface_t *surface;
   GdkWindow *embedder;
 };
 
@@ -86,7 +85,7 @@ gdk_offscreen_window_finalize (GObject *object)
 {
   GdkOffscreenWindow *offscreen = GDK_OFFSCREEN_WINDOW (object);
 
-  g_object_unref (offscreen->pixmap);
+  cairo_surface_destroy (offscreen->surface);
 
   G_OBJECT_CLASS (gdk_offscreen_window_parent_class)->finalize (object);
 }
@@ -138,7 +137,7 @@ gdk_offscreen_window_ref_cairo_surface (GdkDrawable *drawable)
 {
   GdkOffscreenWindow *offscreen = GDK_OFFSCREEN_WINDOW (drawable);
 
-  return _gdk_drawable_ref_cairo_surface (offscreen->pixmap);
+  return cairo_surface_reference (offscreen->surface);
 }
 
 static GdkColormap*
@@ -241,11 +240,10 @@ _gdk_offscreen_window_new (GdkWindow     *window,
        offscreen->colormap = gdk_colormap_new (visual, FALSE);
     }
 
-  offscreen->pixmap = gdk_pixmap_new ((GdkDrawable *)private->parent,
-                                     private->width,
-                                     private->height,
-                                     private->depth);
-  gdk_drawable_set_colormap (offscreen->pixmap, offscreen->colormap);
+  offscreen->surface = gdk_window_create_similar_surface ((GdkWindow *)private->parent,
+                                                          CAIRO_CONTENT_COLOR,
+                                                          private->width,
+                                                          private->height);
 }
 
 static gboolean
@@ -399,19 +397,17 @@ gdk_offscreen_window_get_device_state (GdkWindow       *window,
 }
 
 /**
- * gdk_offscreen_window_get_pixmap:
+ * gdk_offscreen_window_get_surface:
  * @window: a #GdkWindow
  *
- * Gets the offscreen pixmap that an offscreen window renders into.
+ * Gets the offscreen surface that an offscreen window renders into.
  * If you need to keep this around over window resizes, you need to
  * add a reference to it.
  *
- * Returns: The offscreen pixmap, or %NULL if not offscreen
- *
- * Since: 2.18
+ * Returns: The offscreen surface, or %NULL if not offscreen
  */
-GdkPixmap *
-gdk_offscreen_window_get_pixmap (GdkWindow *window)
+cairo_surface_t *
+gdk_offscreen_window_get_surface (GdkWindow *window)
 {
   GdkWindowObject *private = (GdkWindowObject *)window;
   GdkOffscreenWindow *offscreen;
@@ -422,7 +418,7 @@ gdk_offscreen_window_get_pixmap (GdkWindow *window)
     return NULL;
 
   offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
-  return offscreen->pixmap;
+  return offscreen->surface;
 }
 
 static void
@@ -450,7 +446,7 @@ gdk_offscreen_window_move_resize_internal (GdkWindow *window,
   GdkWindowObject *private = (GdkWindowObject *)window;
   GdkOffscreenWindow *offscreen;
   gint dx, dy, dw, dh;
-  GdkPixmap *old_pixmap;
+  cairo_surface_t *old_surface;
 
   offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
 
@@ -478,16 +474,18 @@ gdk_offscreen_window_move_resize_internal (GdkWindow *window,
       private->width = width;
       private->height = height;
 
-      old_pixmap = offscreen->pixmap;
-      offscreen->pixmap = gdk_pixmap_new (GDK_DRAWABLE (old_pixmap),
-                                         width,
-                                         height,
-                                         private->depth);
+      old_surface = offscreen->surface;
+      offscreen->surface = cairo_surface_create_similar (old_surface,
+                                                         cairo_surface_get_content (old_surface),
+                                                         width,
+                                                         height);
 
-      cr = gdk_cairo_create (offscreen->pixmap);
-      gdk_cairo_set_source_pixmap (cr, old_pixmap, 0, 0);
+      cr = cairo_create (offscreen->surface);
+      cairo_set_source_surface (cr, old_surface, 0, 0);
       cairo_paint (cr);
       cairo_destroy (cr);
+
+      cairo_surface_destroy (old_surface);
     }
 
   if (GDK_WINDOW_IS_MAPPED (private))
@@ -661,13 +659,10 @@ gdk_offscreen_window_translate (GdkWindow      *window,
                                 gint            dx,
                                 gint            dy)
 {
-  cairo_surface_t *surface;
+  GdkOffscreenWindow *offscreen = GDK_OFFSCREEN_WINDOW (((GdkWindowObject *) window)->impl);
   cairo_t *cr;
 
-  /* Can't use gdk_cairo_create here due to clipping */
-  surface = _gdk_drawable_ref_cairo_surface (window);
-  cr = cairo_create (surface);
-  cairo_surface_destroy (surface);
+  cr = cairo_create (offscreen->surface);
 
   area = cairo_region_copy (area);
 
@@ -679,7 +674,7 @@ gdk_offscreen_window_translate (GdkWindow      *window,
    */
   cairo_push_group (cr);
 
-  gdk_cairo_set_source_pixmap (cr, window, dx, dy);
+  cairo_set_source_surface (cr, offscreen->surface, dx, dy);
   cairo_paint (cr);
 
   cairo_pop_group_to_source (cr);
index 4078f660912d6dc2349d86c82866f834511370ff..875de931ee5fd23f8aac6cb9160bc106abe301a1 100644 (file)
@@ -3004,7 +3004,7 @@ gdk_window_end_paint (GdkWindow *window)
       full_clip = cairo_region_copy (private->clip_region_with_children);
       cairo_region_intersect (full_clip, paint->region);
 
-      cr = gdk_cairo_create (private->impl);
+      cr = gdk_cairo_create (window);
       cairo_set_source_surface (cr, paint->surface, 0, 0);
       gdk_cairo_region (cr, full_clip);
       cairo_fill (cr);
index 4c02cc28498c18d734ac39f8036cf2165cd7d177..3ce4abdafe4679225f69fac9a488550a4b5c284a 100644 (file)
@@ -846,7 +846,8 @@ GdkPointerHooks *gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks);
 GdkWindow *gdk_get_default_root_window (void);
 
 /* Offscreen redirection */
-GdkPixmap *gdk_offscreen_window_get_pixmap     (GdkWindow     *window);
+cairo_surface_t *
+           gdk_offscreen_window_get_surface    (GdkWindow     *window);
 void       gdk_offscreen_window_set_embedder   (GdkWindow     *window,
                                                GdkWindow     *embedder);
 GdkWindow *gdk_offscreen_window_get_embedder   (GdkWindow     *window);
index fb895eafe09d7a3af39130a026aeeb2716c2a397..fc80fc671642b0875a72ff674ca945019b144575 100644 (file)
@@ -2085,7 +2085,7 @@ gtk_object_get_type G_GNUC_CONST
 #if IN_FILE(__GTK_OFFSCREEN_WINDOW_C__)
 gtk_offscreen_window_get_type G_GNUC_CONST
 gtk_offscreen_window_new
-gtk_offscreen_window_get_pixmap
+gtk_offscreen_window_get_surface
 gtk_offscreen_window_get_pixbuf
 #endif
 #endif
index a2ea06c7092ae46e82fc8d170705be71211efedb..443a4c5ca81a3a18718c42755ae2550786fedeca 100644 (file)
@@ -37,7 +37,7 @@
  *
  * The idea is to take a widget and manually set the state of it,
  * add it to a GtkOffscreenWindow and then retrieve the snapshot
- * as a #GdkPixmap or #GdkPixbuf.
+ * as a #cairo_surface_t or #GdkPixbuf.
  *
  * GtkOffscreenWindow derives from #GtkWindow only as an implementation
  * detail.  Applications should not use any API specific to #GtkWindow
@@ -270,24 +270,24 @@ gtk_offscreen_window_new (void)
 }
 
 /**
- * gtk_offscreen_window_get_pixmap:
+ * gtk_offscreen_window_get_surface:
  * @offscreen: the #GtkOffscreenWindow contained widget.
  *
  * Retrieves a snapshot of the contained widget in the form of
- * a #GdkPixmap.  If you need to keep this around over window
+ * a #cairo_surface_t.  If you need to keep this around over window
  * resizes then you should add a reference to it.
  *
- * Returns: (transfer none): A #GdkPixmap pointer to the offscreen pixmap,
- *     or %NULL.
+ * Returns: (transfer none): A #cairo_surface_t pointer to the offscreen
+ *     surface, or %NULL.
  *
  * Since: 2.20
  */
-GdkPixmap *
-gtk_offscreen_window_get_pixmap (GtkOffscreenWindow *offscreen)
+cairo_surface_t *
+gtk_offscreen_window_get_surface (GtkOffscreenWindow *offscreen)
 {
   g_return_val_if_fail (GTK_IS_OFFSCREEN_WINDOW (offscreen), NULL);
 
-  return gdk_offscreen_window_get_pixmap (gtk_widget_get_window (GTK_WIDGET (offscreen)));
+  return gdk_offscreen_window_get_surface (gtk_widget_get_window (GTK_WIDGET (offscreen)));
 }
 
 /**
@@ -306,22 +306,24 @@ gtk_offscreen_window_get_pixmap (GtkOffscreenWindow *offscreen)
 GdkPixbuf *
 gtk_offscreen_window_get_pixbuf (GtkOffscreenWindow *offscreen)
 {
-  GdkPixmap *pixmap = NULL;
+  cairo_surface_t *surface;
   GdkPixbuf *pixbuf = NULL;
+  GdkWindow *window;
 
   g_return_val_if_fail (GTK_IS_OFFSCREEN_WINDOW (offscreen), NULL);
 
-  pixmap = gdk_offscreen_window_get_pixmap (gtk_widget_get_window (GTK_WIDGET (offscreen)));
+  window = gtk_widget_get_window (GTK_WIDGET (offscreen));
+  surface = gdk_offscreen_window_get_surface (window);
 
-  if (pixmap != NULL)
+  if (surface != NULL)
     {
       gint width, height;
 
-      gdk_drawable_get_size (pixmap, &width, &height);
+      gdk_drawable_get_size (window, &width, &height);
 
-      pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, NULL,
-                                             0, 0, 0, 0,
-                                             width, height);
+      pixbuf = gdk_pixbuf_get_from_surface (NULL, surface,
+                                            0, 0, 0, 0,
+                                            width, height);
     }
 
   return pixbuf;
index a706e6704c4fb85803dd175282139e86fb69f687..7ecb71262fb2c706113852c09b8e9b23298f6933 100644 (file)
@@ -49,11 +49,11 @@ struct _GtkOffscreenWindowClass
   GtkWindowClass parent_class;
 };
 
-GType      gtk_offscreen_window_get_type   (void) G_GNUC_CONST;
+GType            gtk_offscreen_window_get_type    (void) G_GNUC_CONST;
 
-GtkWidget *gtk_offscreen_window_new        (void);
-GdkPixmap *gtk_offscreen_window_get_pixmap (GtkOffscreenWindow *offscreen);
-GdkPixbuf *gtk_offscreen_window_get_pixbuf (GtkOffscreenWindow *offscreen);
+GtkWidget       *gtk_offscreen_window_new         (void);
+cairo_surface_t *gtk_offscreen_window_get_surface (GtkOffscreenWindow *offscreen);
+GdkPixbuf       *gtk_offscreen_window_get_pixbuf  (GtkOffscreenWindow *offscreen);
 
 G_END_DECLS
 
index eee514b7483f267c7cf98eefe3152d12cae7ccf6..cd70c3e4aa038444112317a54a784f6f9f6d186d 100644 (file)
@@ -598,19 +598,19 @@ gtk_offscreen_box_expose (GtkWidget      *widget,
       window = gtk_widget_get_window (widget);
       if (event->window == window)
        {
-          GdkPixmap *pixmap;
+          cairo_surface_t *surface;
           GtkAllocation child_area;
           cairo_t *cr;
          int start_y = 0;
 
          if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1))
            {
-             pixmap = gdk_offscreen_window_get_pixmap (offscreen_box->offscreen_window1);
+             surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window1);
               gtk_widget_get_allocation (offscreen_box->child1, &child_area);
 
              cr = gdk_cairo_create (window);
 
-              gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+              cairo_set_source_surface (cr, surface, 0, 0);
               cairo_paint (cr);
 
               cairo_destroy (cr);
@@ -622,7 +622,7 @@ gtk_offscreen_box_expose (GtkWidget      *widget,
            {
               gint w, h;
 
-             pixmap = gdk_offscreen_window_get_pixmap (offscreen_box->offscreen_window2);
+             surface = gdk_offscreen_window_get_surface (offscreen_box->offscreen_window2);
               gtk_widget_get_allocation (offscreen_box->child2, &child_area);
 
              cr = gdk_cairo_create (window);
@@ -634,12 +634,12 @@ gtk_offscreen_box_expose (GtkWidget      *widget,
              cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
 
               /* clip */
-              gdk_drawable_get_size (pixmap, &w, &h);
+              gdk_drawable_get_size (offscreen_box->offscreen_window2, &w, &h);
               cairo_rectangle (cr, 0, 0, w, h);
               cairo_clip (cr);
 
               /* paint */
-             gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0);
+             cairo_set_source_surface (cr, surface, 0, 0);
              cairo_paint (cr);
 
               cairo_destroy (cr);
index bf6a321f133bc4d45565496b52a55691a6c1c2ac..ded2762bbec829a255e05d4b5bf1b2cc2c0bc990 100644 (file)
@@ -6,15 +6,15 @@ da_expose (GtkWidget *widget,
            gpointer user_data)
 {
   GtkOffscreenWindow *offscreen = (GtkOffscreenWindow *)user_data;
-  GdkPixmap *pixmap;
+  cairo_surface_t *surface;
   cairo_t *cr;
 
   if (gtk_widget_is_drawable (widget))
     {
-      pixmap = gtk_offscreen_window_get_pixmap (offscreen);
+      surface = gtk_offscreen_window_get_surface (offscreen);
 
       cr = gdk_cairo_create (gtk_widget_get_window (widget));
-      gdk_cairo_set_source_pixmap (cr, pixmap, 50, 50);
+      cairo_set_source_surface (cr, surface, 50, 50);
       cairo_paint (cr);
       cairo_destroy (cr);
     }