widget-factory: Use a pixbuf instead of a surface
authorBenjamin Otte <otte@redhat.com>
Wed, 11 Apr 2018 23:40:38 +0000 (01:40 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 12 Apr 2018 12:03:58 +0000 (14:03 +0200)
This gets rid of the last user of
gdk_cairo_surface_create_from_pixbuf().

demos/widget-factory/widget-factory.c

index 60dbd07ceb45ef60dd7355abe0fe2835fc43686a..8627c1d5a5f6068e0a51bcbf9f59cf0f6fd8144f 100644 (file)
@@ -1082,7 +1082,7 @@ set_accel (GtkApplication *app, GtkWidget *widget)
 typedef struct
 {
   GtkTextView tv;
-  cairo_surface_t *surface;
+  GdkPixbuf *pixbuf;
 } MyTextView;
 
 typedef GtkTextViewClass MyTextViewClass;
@@ -1101,10 +1101,10 @@ my_tv_draw_layer (GtkTextView      *widget,
 {
   MyTextView *tv = (MyTextView *)widget;
 
-  if (layer == GTK_TEXT_VIEW_LAYER_BELOW_TEXT && tv->surface)
+  if (layer == GTK_TEXT_VIEW_LAYER_BELOW_TEXT && tv->pixbuf)
     {
       cairo_save (cr);
-      cairo_set_source_surface (cr, tv->surface, 0.0, 0.0);
+      gdk_cairo_set_source_pixbuf (cr, tv->pixbuf, 0.0, 0.0);
       cairo_paint_with_alpha (cr, 0.333);
       cairo_restore (cr);
     }
@@ -1115,8 +1115,7 @@ my_tv_finalize (GObject *object)
 {
   MyTextView *tv = (MyTextView *)object;
 
-  if (tv->surface)
-    cairo_surface_destroy (tv->surface);
+  g_clear_object (&tv->pixbuf);
 
   G_OBJECT_CLASS (my_text_view_parent_class)->finalize (object);
 }
@@ -1134,18 +1133,14 @@ my_text_view_class_init (MyTextViewClass *class)
 static void
 my_text_view_set_background (MyTextView *tv, const gchar *filename)
 {
-  GdkPixbuf *pixbuf;
   GError *error = NULL;
 
-  if (tv->surface)
-    cairo_surface_destroy (tv->surface);
-
-  tv->surface = NULL;
+  g_clear_object (&tv->pixbuf);
 
   if (filename == NULL)
     return;
 
-  pixbuf = gdk_pixbuf_new_from_file (filename, &error);
+  tv->pixbuf = gdk_pixbuf_new_from_file (filename, &error);
   if (error)
     {
       g_warning ("%s", error->message);
@@ -1153,10 +1148,6 @@ my_text_view_set_background (MyTextView *tv, const gchar *filename)
       return;
     }
 
-  tv->surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
-
-  g_object_unref (pixbuf);
-
   gtk_widget_queue_draw (GTK_WIDGET (tv));
 }