[gtk+/rendering-cleanup: 76/92] API: Change offscreen windows to use a cairo_surface_t



commit bc51963553131036fabf40c5c9b8d43cc7b9c4e9
Author: Benjamin Otte <otte redhat com>
Date:   Thu Aug 26 13:46:34 2010 +0200

    API: Change offscreen windows to use a cairo_surface_t
    
    This requires changes to all the offscreen surface getters that used to
    return a GdkPixmap before.

 demos/gtk-demo/offscreen_window.c    |    8 ++--
 demos/gtk-demo/offscreen_window2.c   |   10 +++---
 docs/reference/gdk/gdk3-sections.txt |    2 +-
 docs/reference/gtk/gtk3-sections.txt |    2 +-
 gdk/gdk.symbols                      |    2 +-
 gdk/gdkoffscreenwindow.c             |   57 +++++++++++++++------------------
 gdk/gdkwindow.c                      |    2 +-
 gdk/gdkwindow.h                      |    3 +-
 gtk/gtk.symbols                      |    2 +-
 gtk/gtkoffscreenwindow.c             |   30 +++++++++--------
 gtk/gtkoffscreenwindow.h             |    8 ++--
 tests/gtkoffscreenbox.c              |   12 +++---
 tests/testoffscreenwindow.c          |    6 ++--
 13 files changed, 71 insertions(+), 73 deletions(-)
---
diff --git a/demos/gtk-demo/offscreen_window.c b/demos/gtk-demo/offscreen_window.c
index e4b454d..31a8a40 100644
--- a/demos/gtk-demo/offscreen_window.c
+++ b/demos/gtk-demo/offscreen_window.c
@@ -483,13 +483,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);
@@ -506,11 +506,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);
diff --git a/demos/gtk-demo/offscreen_window2.c b/demos/gtk-demo/offscreen_window2.c
index 642fc46..a8a2e19 100644
--- a/demos/gtk-demo/offscreen_window2.c
+++ b/demos/gtk-demo/offscreen_window2.c
@@ -387,15 +387,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);
 
@@ -405,7 +405,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);
@@ -418,7 +418,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);
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index fa87e3e..14a25ae 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -529,7 +529,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
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 5164d3f..ff0be70 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -2289,7 +2289,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
diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols
index dfb397e..2ee8678 100644
--- a/gdk/gdk.symbols
+++ b/gdk/gdk.symbols
@@ -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
diff --git a/gdk/gdkoffscreenwindow.c b/gdk/gdkoffscreenwindow.c
index cc356ed..7ebdd40 100644
--- a/gdk/gdkoffscreenwindow.c
+++ b/gdk/gdkoffscreenwindow.c
@@ -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
@@ -434,19 +432,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;
@@ -457,7 +453,7 @@ gdk_offscreen_window_get_pixmap (GdkWindow *window)
     return NULL;
 
   offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
-  return offscreen->pixmap;
+  return offscreen->surface;
 }
 
 static void
@@ -485,7 +481,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);
 
@@ -513,16 +509,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))
@@ -696,13 +694,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);
 
@@ -714,7 +709,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);
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 2fc1385..1f24060 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -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);
diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h
index 48e47fd..d1cb301 100644
--- a/gdk/gdkwindow.h
+++ b/gdk/gdkwindow.h
@@ -855,7 +855,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);
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index ccb520c..2dd1012 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2205,7 +2205,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
diff --git a/gtk/gtkoffscreenwindow.c b/gtk/gtkoffscreenwindow.c
index ca2461d..923d912 100644
--- a/gtk/gtkoffscreenwindow.c
+++ b/gtk/gtkoffscreenwindow.c
@@ -34,7 +34,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
@@ -265,23 +265,23 @@ 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: A #GdkPixmap pointer to the offscreen pixmap, or %NULL.
+ * Returns: 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)));
 }
 
 /**
@@ -300,22 +300,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;
diff --git a/gtk/gtkoffscreenwindow.h b/gtk/gtkoffscreenwindow.h
index a706e67..7ecb712 100644
--- a/gtk/gtkoffscreenwindow.h
+++ b/gtk/gtkoffscreenwindow.h
@@ -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
 
diff --git a/tests/gtkoffscreenbox.c b/tests/gtkoffscreenbox.c
index 6a46469..831e56a 100644
--- a/tests/gtkoffscreenbox.c
+++ b/tests/gtkoffscreenbox.c
@@ -594,19 +594,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);
@@ -618,7 +618,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);
@@ -630,12 +630,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);
diff --git a/tests/testoffscreenwindow.c b/tests/testoffscreenwindow.c
index bf6a321..ded2762 100644
--- a/tests/testoffscreenwindow.c
+++ b/tests/testoffscreenwindow.c
@@ -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);
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]