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.
This commit is contained in:
Benjamin Otte 2010-08-26 13:46:34 +02:00
parent ebdf26e1d8
commit 332652f702
13 changed files with 72 additions and 74 deletions

View File

@ -485,13 +485,13 @@ gtk_rotated_bin_expose (GtkWidget *widget,
window = gtk_widget_get_window (widget); window = gtk_widget_get_window (widget);
if (event->window == window) if (event->window == window)
{ {
GdkPixmap *pixmap; cairo_surface_t *surface;
GtkAllocation child_area; GtkAllocation child_area;
cairo_t *cr; cairo_t *cr;
if (bin->child && gtk_widget_get_visible (bin->child)) 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); gtk_widget_get_allocation (bin->child, &child_area);
cr = gdk_cairo_create (window); 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); cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
/* clip */ /* 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_rectangle (cr, 0, 0, width, height);
cairo_clip (cr); cairo_clip (cr);
/* paint */ /* paint */
gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0); cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr); cairo_paint (cr);
cairo_destroy (cr); cairo_destroy (cr);

View File

@ -389,15 +389,15 @@ gtk_mirror_bin_expose (GtkWidget *widget,
window = gtk_widget_get_window (widget); window = gtk_widget_get_window (widget);
if (event->window == window) if (event->window == window)
{ {
GdkPixmap *pixmap; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
cairo_matrix_t matrix; cairo_matrix_t matrix;
cairo_pattern_t *mask; cairo_pattern_t *mask;
if (bin->child && gtk_widget_get_visible (bin->child)) 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);
gdk_drawable_get_size (pixmap, &width, &height); gdk_drawable_get_size (bin->offscreen_window, &width, &height);
cr = gdk_cairo_create (window); cr = gdk_cairo_create (window);
@ -407,7 +407,7 @@ gtk_mirror_bin_expose (GtkWidget *widget,
cairo_clip (cr); cairo_clip (cr);
/* paint the offscreen child */ /* 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_paint (cr);
cairo_restore (cr); cairo_restore (cr);
@ -420,7 +420,7 @@ gtk_mirror_bin_expose (GtkWidget *widget,
cairo_rectangle (cr, 0, height, width, height); cairo_rectangle (cr, 0, height, width, height);
cairo_clip (cr); 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 */ /* create linear gradient as mask-pattern to fade out the source */
mask = cairo_pattern_create_linear (0.0, height, 0.0, 2*height); mask = cairo_pattern_create_linear (0.0, height, 0.0, 2*height);

View File

@ -530,7 +530,7 @@ GdkPointerHooks
gdk_set_pointer_hooks gdk_set_pointer_hooks
<SUBSECTION> <SUBSECTION>
gdk_offscreen_window_get_pixmap gdk_offscreen_window_get_surface
gdk_offscreen_window_set_embedder gdk_offscreen_window_set_embedder
gdk_offscreen_window_get_embedder gdk_offscreen_window_get_embedder
gdk_window_geometry_changed gdk_window_geometry_changed

View File

@ -2266,7 +2266,7 @@ GTK_OBJECT_UNSET_FLAGS
<TITLE>GtkOffscreenWindow</TITLE> <TITLE>GtkOffscreenWindow</TITLE>
GtkOffscreenWindow GtkOffscreenWindow
gtk_offscreen_window_new gtk_offscreen_window_new
gtk_offscreen_window_get_pixmap gtk_offscreen_window_get_surface
gtk_offscreen_window_get_pixbuf gtk_offscreen_window_get_pixbuf
<SUBSECTION Standard> <SUBSECTION Standard>
GTK_OFFSCREEN_WINDOW GTK_OFFSCREEN_WINDOW

View File

@ -668,7 +668,7 @@ gdk_window_get_device_position
#if IN_HEADER(__GDK_WINDOW_H__) #if IN_HEADER(__GDK_WINDOW_H__)
#if IN_FILE(__GDK_OFFSCREEN_WINDOW_C__) #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_set_embedder
gdk_offscreen_window_get_embedder gdk_offscreen_window_get_embedder
#endif #endif

View File

@ -30,7 +30,6 @@
#include "gdkwindow.h" #include "gdkwindow.h"
#include "gdkinternals.h" #include "gdkinternals.h"
#include "gdkwindowimpl.h" #include "gdkwindowimpl.h"
#include "gdkpixmap.h"
#include "gdkdrawable.h" #include "gdkdrawable.h"
#include "gdktypes.h" #include "gdktypes.h"
#include "gdkscreen.h" #include "gdkscreen.h"
@ -55,7 +54,7 @@ struct _GdkOffscreenWindow
GdkColormap *colormap; GdkColormap *colormap;
GdkScreen *screen; GdkScreen *screen;
GdkPixmap *pixmap; cairo_surface_t *surface;
GdkWindow *embedder; GdkWindow *embedder;
}; };
@ -86,7 +85,7 @@ gdk_offscreen_window_finalize (GObject *object)
{ {
GdkOffscreenWindow *offscreen = GDK_OFFSCREEN_WINDOW (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); 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); GdkOffscreenWindow *offscreen = GDK_OFFSCREEN_WINDOW (drawable);
return _gdk_drawable_ref_cairo_surface (offscreen->pixmap); return cairo_surface_reference (offscreen->surface);
} }
static GdkColormap* static GdkColormap*
@ -241,11 +240,10 @@ _gdk_offscreen_window_new (GdkWindow *window,
offscreen->colormap = gdk_colormap_new (visual, FALSE); offscreen->colormap = gdk_colormap_new (visual, FALSE);
} }
offscreen->pixmap = gdk_pixmap_new ((GdkDrawable *)private->parent, offscreen->surface = gdk_window_create_similar_surface ((GdkWindow *)private->parent,
private->width, CAIRO_CONTENT_COLOR,
private->height, private->width,
private->depth); private->height);
gdk_drawable_set_colormap (offscreen->pixmap, offscreen->colormap);
} }
static gboolean 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 * @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 * If you need to keep this around over window resizes, you need to
* add a reference to it. * add a reference to it.
* *
* Returns: The offscreen pixmap, or %NULL if not offscreen * Returns: The offscreen surface, or %NULL if not offscreen
*
* Since: 2.18
*/ */
GdkPixmap * cairo_surface_t *
gdk_offscreen_window_get_pixmap (GdkWindow *window) gdk_offscreen_window_get_surface (GdkWindow *window)
{ {
GdkWindowObject *private = (GdkWindowObject *)window; GdkWindowObject *private = (GdkWindowObject *)window;
GdkOffscreenWindow *offscreen; GdkOffscreenWindow *offscreen;
@ -422,7 +418,7 @@ gdk_offscreen_window_get_pixmap (GdkWindow *window)
return NULL; return NULL;
offscreen = GDK_OFFSCREEN_WINDOW (private->impl); offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
return offscreen->pixmap; return offscreen->surface;
} }
static void static void
@ -450,7 +446,7 @@ gdk_offscreen_window_move_resize_internal (GdkWindow *window,
GdkWindowObject *private = (GdkWindowObject *)window; GdkWindowObject *private = (GdkWindowObject *)window;
GdkOffscreenWindow *offscreen; GdkOffscreenWindow *offscreen;
gint dx, dy, dw, dh; gint dx, dy, dw, dh;
GdkPixmap *old_pixmap; cairo_surface_t *old_surface;
offscreen = GDK_OFFSCREEN_WINDOW (private->impl); offscreen = GDK_OFFSCREEN_WINDOW (private->impl);
@ -478,16 +474,18 @@ gdk_offscreen_window_move_resize_internal (GdkWindow *window,
private->width = width; private->width = width;
private->height = height; private->height = height;
old_pixmap = offscreen->pixmap; old_surface = offscreen->surface;
offscreen->pixmap = gdk_pixmap_new (GDK_DRAWABLE (old_pixmap), offscreen->surface = cairo_surface_create_similar (old_surface,
width, cairo_surface_get_content (old_surface),
height, width,
private->depth); height);
cr = gdk_cairo_create (offscreen->pixmap); cr = cairo_create (offscreen->surface);
gdk_cairo_set_source_pixmap (cr, old_pixmap, 0, 0); cairo_set_source_surface (cr, old_surface, 0, 0);
cairo_paint (cr); cairo_paint (cr);
cairo_destroy (cr); cairo_destroy (cr);
cairo_surface_destroy (old_surface);
} }
if (GDK_WINDOW_IS_MAPPED (private)) if (GDK_WINDOW_IS_MAPPED (private))
@ -661,13 +659,10 @@ gdk_offscreen_window_translate (GdkWindow *window,
gint dx, gint dx,
gint dy) gint dy)
{ {
cairo_surface_t *surface; GdkOffscreenWindow *offscreen = GDK_OFFSCREEN_WINDOW (((GdkWindowObject *) window)->impl);
cairo_t *cr; cairo_t *cr;
/* Can't use gdk_cairo_create here due to clipping */ cr = cairo_create (offscreen->surface);
surface = _gdk_drawable_ref_cairo_surface (window);
cr = cairo_create (surface);
cairo_surface_destroy (surface);
area = cairo_region_copy (area); area = cairo_region_copy (area);
@ -679,7 +674,7 @@ gdk_offscreen_window_translate (GdkWindow *window,
*/ */
cairo_push_group (cr); 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_paint (cr);
cairo_pop_group_to_source (cr); cairo_pop_group_to_source (cr);

View File

@ -3004,7 +3004,7 @@ gdk_window_end_paint (GdkWindow *window)
full_clip = cairo_region_copy (private->clip_region_with_children); full_clip = cairo_region_copy (private->clip_region_with_children);
cairo_region_intersect (full_clip, paint->region); 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); cairo_set_source_surface (cr, paint->surface, 0, 0);
gdk_cairo_region (cr, full_clip); gdk_cairo_region (cr, full_clip);
cairo_fill (cr); cairo_fill (cr);

View File

@ -846,7 +846,8 @@ GdkPointerHooks *gdk_set_pointer_hooks (const GdkPointerHooks *new_hooks);
GdkWindow *gdk_get_default_root_window (void); GdkWindow *gdk_get_default_root_window (void);
/* Offscreen redirection */ /* 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, void gdk_offscreen_window_set_embedder (GdkWindow *window,
GdkWindow *embedder); GdkWindow *embedder);
GdkWindow *gdk_offscreen_window_get_embedder (GdkWindow *window); GdkWindow *gdk_offscreen_window_get_embedder (GdkWindow *window);

View File

@ -2085,7 +2085,7 @@ gtk_object_get_type G_GNUC_CONST
#if IN_FILE(__GTK_OFFSCREEN_WINDOW_C__) #if IN_FILE(__GTK_OFFSCREEN_WINDOW_C__)
gtk_offscreen_window_get_type G_GNUC_CONST gtk_offscreen_window_get_type G_GNUC_CONST
gtk_offscreen_window_new gtk_offscreen_window_new
gtk_offscreen_window_get_pixmap gtk_offscreen_window_get_surface
gtk_offscreen_window_get_pixbuf gtk_offscreen_window_get_pixbuf
#endif #endif
#endif #endif

View File

@ -37,7 +37,7 @@
* *
* The idea is to take a widget and manually set the state of it, * The idea is to take a widget and manually set the state of it,
* add it to a GtkOffscreenWindow and then retrieve the snapshot * 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 * GtkOffscreenWindow derives from #GtkWindow only as an implementation
* detail. Applications should not use any API specific to #GtkWindow * 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. * @offscreen: the #GtkOffscreenWindow contained widget.
* *
* Retrieves a snapshot of the contained widget in the form of * 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. * resizes then you should add a reference to it.
* *
* Returns: (transfer none): A #GdkPixmap pointer to the offscreen pixmap, * Returns: (transfer none): A #cairo_surface_t pointer to the offscreen
* or %NULL. * surface, or %NULL.
* *
* Since: 2.20 * Since: 2.20
*/ */
GdkPixmap * cairo_surface_t *
gtk_offscreen_window_get_pixmap (GtkOffscreenWindow *offscreen) gtk_offscreen_window_get_surface (GtkOffscreenWindow *offscreen)
{ {
g_return_val_if_fail (GTK_IS_OFFSCREEN_WINDOW (offscreen), NULL); 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 * GdkPixbuf *
gtk_offscreen_window_get_pixbuf (GtkOffscreenWindow *offscreen) gtk_offscreen_window_get_pixbuf (GtkOffscreenWindow *offscreen)
{ {
GdkPixmap *pixmap = NULL; cairo_surface_t *surface;
GdkPixbuf *pixbuf = NULL; GdkPixbuf *pixbuf = NULL;
GdkWindow *window;
g_return_val_if_fail (GTK_IS_OFFSCREEN_WINDOW (offscreen), NULL); 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; 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, pixbuf = gdk_pixbuf_get_from_surface (NULL, surface,
0, 0, 0, 0, 0, 0, 0, 0,
width, height); width, height);
} }
return pixbuf; return pixbuf;

View File

@ -49,11 +49,11 @@ struct _GtkOffscreenWindowClass
GtkWindowClass parent_class; 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); GtkWidget *gtk_offscreen_window_new (void);
GdkPixmap *gtk_offscreen_window_get_pixmap (GtkOffscreenWindow *offscreen); cairo_surface_t *gtk_offscreen_window_get_surface (GtkOffscreenWindow *offscreen);
GdkPixbuf *gtk_offscreen_window_get_pixbuf (GtkOffscreenWindow *offscreen); GdkPixbuf *gtk_offscreen_window_get_pixbuf (GtkOffscreenWindow *offscreen);
G_END_DECLS G_END_DECLS

View File

@ -598,19 +598,19 @@ gtk_offscreen_box_expose (GtkWidget *widget,
window = gtk_widget_get_window (widget); window = gtk_widget_get_window (widget);
if (event->window == window) if (event->window == window)
{ {
GdkPixmap *pixmap; cairo_surface_t *surface;
GtkAllocation child_area; GtkAllocation child_area;
cairo_t *cr; cairo_t *cr;
int start_y = 0; int start_y = 0;
if (offscreen_box->child1 && gtk_widget_get_visible (offscreen_box->child1)) 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); gtk_widget_get_allocation (offscreen_box->child1, &child_area);
cr = gdk_cairo_create (window); 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_paint (cr);
cairo_destroy (cr); cairo_destroy (cr);
@ -622,7 +622,7 @@ gtk_offscreen_box_expose (GtkWidget *widget,
{ {
gint w, h; 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); gtk_widget_get_allocation (offscreen_box->child2, &child_area);
cr = gdk_cairo_create (window); 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); cairo_translate (cr, -child_area.width / 2, -child_area.height / 2);
/* clip */ /* 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_rectangle (cr, 0, 0, w, h);
cairo_clip (cr); cairo_clip (cr);
/* paint */ /* paint */
gdk_cairo_set_source_pixmap (cr, pixmap, 0, 0); cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr); cairo_paint (cr);
cairo_destroy (cr); cairo_destroy (cr);

View File

@ -6,15 +6,15 @@ da_expose (GtkWidget *widget,
gpointer user_data) gpointer user_data)
{ {
GtkOffscreenWindow *offscreen = (GtkOffscreenWindow *)user_data; GtkOffscreenWindow *offscreen = (GtkOffscreenWindow *)user_data;
GdkPixmap *pixmap; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
if (gtk_widget_is_drawable (widget)) 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)); 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_paint (cr);
cairo_destroy (cr); cairo_destroy (cr);
} }