From 1083a4c0b74dd9d9ab44d577672a353b8955b304 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 23 Sep 2010 18:56:46 +0200 Subject: [PATCH] Introduce MetaPixmap compatibility wrapper Similar to the region compatibility shim, we will soon need a compatibility shim around GdkPixmap/cairo_surface_t. For now, the patch just introduces the compatibility layer. This patch also does not include the function meta_gdk_pixbuf_get_from_pixmap() as that function will need special treatment in GTK3 anyway. https://bugzilla.gnome.org/show_bug.cgi?id=630203 --- src/gdk2-drawing-utils.h | 7 +++++++ src/ui/frames.c | 18 +++++++++--------- src/ui/theme-viewer.c | 13 ++++++------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/gdk2-drawing-utils.h b/src/gdk2-drawing-utils.h index d3ce3026a..69f45d4b1 100644 --- a/src/gdk2-drawing-utils.h +++ b/src/gdk2-drawing-utils.h @@ -24,6 +24,13 @@ #include +#define MetaPixmap GdkPixmap + +#define meta_pixmap_new(window, w, h) gdk_pixmap_new (window, w, h, -1) +#define meta_pixmap_free(pixmap) g_object_unref (pixmap) +#define meta_pixmap_cairo_create(pixmap) meta_cairo_create (pixmap) +#define meta_cairo_set_source_pixmap(cr, pixmap, x, y) gdk_cairo_set_source_pixmap (cr, pixmap, x, y) + /* This function only exists for GTK2 code. */ cairo_t * meta_cairo_create (GdkDrawable *drawable); diff --git a/src/ui/frames.c b/src/ui/frames.c index ee90541e9..97677034c 100644 --- a/src/ui/frames.c +++ b/src/ui/frames.c @@ -276,7 +276,7 @@ meta_frames_finalize (GObject *object) typedef struct { GdkRectangle rect; - GdkPixmap *pixmap; + MetaPixmap *pixmap; } CachedFramePiece; typedef struct @@ -313,7 +313,7 @@ invalidate_cache (MetaFrames *frames, for (i = 0; i < 4; i++) if (pixels->piece[i].pixmap) - g_object_unref (pixels->piece[i].pixmap); + meta_pixmap_free (pixels->piece[i].pixmap); g_free (pixels); g_hash_table_remove (frames->cache, frame); @@ -2084,22 +2084,22 @@ setup_bg_cr (cairo_t *cr, GdkWindow *window, int x_offset, int y_offset) /* Returns a pixmap with a piece of the windows frame painted on it. */ -static GdkPixmap * +static MetaPixmap * generate_pixmap (MetaFrames *frames, MetaUIFrame *frame, GdkRectangle *rect) { - GdkPixmap *result; + MetaPixmap *result; cairo_t *cr; /* do not create a pixmap for nonexisting areas */ if (rect->width <= 0 || rect->height <= 0) return NULL; - result = gdk_pixmap_new (frame->window, - rect->width, rect->height, -1); + result = meta_pixmap_new (frame->window, + rect->width, rect->height); - cr = meta_cairo_create (result); + cr = meta_pixmap_cairo_create (result); setup_bg_cr (cr, frame->window, rect->x, rect->y); cairo_paint (cr); @@ -2270,8 +2270,8 @@ cached_pixels_draw (CachedPixels *pixels, if (piece->pixmap) { - gdk_cairo_set_source_pixmap (cr, piece->pixmap, - piece->rect.x, piece->rect.y); + meta_cairo_set_source_pixmap (cr, piece->pixmap, + piece->rect.x, piece->rect.y); cairo_paint (cr); region_piece = meta_region_new_from_rectangle (&piece->rect); diff --git a/src/ui/theme-viewer.c b/src/ui/theme-viewer.c index 7c0d3b1b4..e7cd29c64 100644 --- a/src/ui/theme-viewer.c +++ b/src/ui/theme-viewer.c @@ -943,7 +943,7 @@ static void run_theme_benchmark (void) { GtkWidget* widget; - GdkPixmap *pixmap; + MetaPixmap *pixmap; int top_height, bottom_height, left_width, right_width; MetaButtonState button_states[META_BUTTON_TYPE_LAST] = { @@ -1007,12 +1007,11 @@ run_theme_benchmark (void) /* Creating the pixmap in the loop is right, since * GDK does the same with its double buffering. */ - pixmap = gdk_pixmap_new (gtk_widget_get_window (widget), - client_width + left_width + right_width, - client_height + top_height + bottom_height, - -1); + pixmap = meta_pixmap_new (gtk_widget_get_window (widget), + client_width + left_width + right_width, + client_height + top_height + bottom_height); - cr = meta_cairo_create (pixmap); + cr = meta_pixmap_cairo_create (pixmap); meta_theme_draw_frame (global_theme, widget, @@ -1029,7 +1028,7 @@ run_theme_benchmark (void) meta_preview_get_icon ()); cairo_destroy (cr); - g_object_unref (G_OBJECT (pixmap)); + meta_pixmap_free (pixmap); ++i; client_width += inc;