diff options
author | Matthias Clasen <mclasen@redhat.com> | 2023-05-16 16:05:47 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2023-05-16 16:25:59 -0400 |
commit | 6b2c088a29e4a8193ccbc8d654f24dee8fb35227 (patch) | |
tree | ff3d9c90aca3f654fd139aaa48d5545662e27619 /demos | |
parent | 4efc736a6ee9fdff0132b0f9b66a72c2989751cf (diff) | |
download | gtk+-6b2c088a29e4a8193ccbc8d654f24dee8fb35227.tar.gz |
demos: Stop using deprecated api
Use texture apis instead of pixbuf ones.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/gtk-demo/fontrendering.c | 32 | ||||
-rw-r--r-- | demos/gtk-demo/images.c | 21 | ||||
-rw-r--r-- | demos/widget-factory/widget-factory.c | 29 |
3 files changed, 58 insertions, 24 deletions
diff --git a/demos/gtk-demo/fontrendering.c b/demos/gtk-demo/fontrendering.c index 69a654d506..9684c5b517 100644 --- a/demos/gtk-demo/fontrendering.c +++ b/demos/gtk-demo/fontrendering.c @@ -43,6 +43,7 @@ update_image (void) cairo_t *cr; GdkPixbuf *pixbuf; GdkPixbuf *pixbuf2; + GdkTexture *texture; cairo_font_options_t *fopt; cairo_hint_style_t hintstyle; cairo_hint_metrics_t hintmetrics; @@ -120,8 +121,17 @@ update_image (void) cairo_destroy (cr); g_object_unref (layout); - pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface)); - pixbuf2 = gdk_pixbuf_scale_simple (pixbuf, gdk_pixbuf_get_width (pixbuf) * scale, gdk_pixbuf_get_height (pixbuf) * scale, GDK_INTERP_NEAREST); + pixbuf = gdk_pixbuf_new_from_data (cairo_image_surface_get_data (surface), + GDK_COLORSPACE_RGB, TRUE, 8, + cairo_image_surface_get_width (surface), + cairo_image_surface_get_height (surface), + cairo_image_surface_get_stride (surface), + NULL, NULL); + + pixbuf2 = gdk_pixbuf_scale_simple (pixbuf, + gdk_pixbuf_get_width (pixbuf) * scale, + gdk_pixbuf_get_height (pixbuf) * scale, + GDK_INTERP_NEAREST); g_object_unref (pixbuf); cairo_surface_destroy (surface); @@ -278,14 +288,24 @@ retry: pango_layout_iter_free (iter); g_object_unref (layout); - pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface)); - pixbuf2 = gdk_pixbuf_scale_simple (pixbuf, gdk_pixbuf_get_width (pixbuf) * scale, gdk_pixbuf_get_height (pixbuf) * scale, GDK_INTERP_NEAREST); + pixbuf = gdk_pixbuf_new_from_data (cairo_image_surface_get_data (surface), + GDK_COLORSPACE_RGB, TRUE, 8, + cairo_image_surface_get_width (surface), + cairo_image_surface_get_height (surface), + cairo_image_surface_get_stride (surface), + NULL, NULL); + + pixbuf2 = gdk_pixbuf_scale_simple (pixbuf, + gdk_pixbuf_get_width (pixbuf) * scale, + gdk_pixbuf_get_height (pixbuf) * scale, + GDK_INTERP_NEAREST); g_object_unref (pixbuf); cairo_surface_destroy (surface); } - gtk_picture_set_pixbuf (GTK_PICTURE (image), pixbuf2); - + texture = gdk_texture_new_for_pixbuf (pixbuf2); + gtk_picture_set_paintable (GTK_PICTURE (image), GDK_PAINTABLE (texture)); + g_object_unref (pixbuf2); g_object_unref (pixbuf2); } diff --git a/demos/gtk-demo/images.c b/demos/gtk-demo/images.c index af2ceb269c..24056db33d 100644 --- a/demos/gtk-demo/images.c +++ b/demos/gtk-demo/images.c @@ -30,6 +30,7 @@ progressive_prepared_callback (GdkPixbufLoader *loader, { GdkPixbuf *pixbuf; GtkWidget *picture; + GdkTexture *texture; picture = GTK_WIDGET (data); @@ -40,7 +41,9 @@ progressive_prepared_callback (GdkPixbufLoader *loader, */ gdk_pixbuf_fill (pixbuf, 0xaaaaaaff); - gtk_picture_set_pixbuf (GTK_PICTURE (picture), pixbuf); + texture = gdk_texture_new_for_pixbuf (pixbuf); + gtk_picture_set_paintable (GTK_PICTURE (picture), GDK_PAINTABLE (texture)); + g_object_unref (texture); } static void @@ -51,22 +54,18 @@ progressive_updated_callback (GdkPixbufLoader *loader, int height, gpointer data) { - GtkWidget *picture; - GdkPixbuf *pixbuf; - - picture = GTK_WIDGET (data); + GtkWidget *picture = GTK_WIDGET (data); + GdkTexture *texture; - pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); - gtk_picture_set_pixbuf (GTK_PICTURE (picture), NULL); - gtk_picture_set_pixbuf (GTK_PICTURE (picture), pixbuf); + texture = gdk_texture_new_for_pixbuf (gdk_pixbuf_loader_get_pixbuf (loader)); + gtk_picture_set_paintable (GTK_PICTURE (picture), GDK_PAINTABLE (texture)); + g_object_unref (texture); } static int progressive_timeout (gpointer data) { - GtkWidget *picture; - - picture = GTK_WIDGET (data); + GtkWidget *picture = GTK_WIDGET (data); /* This shows off fully-paranoid error handling, so looks scary. * You could factor out the error handling code into a nice separate diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c index 45406086b2..f0cfa2e62f 100644 --- a/demos/widget-factory/widget-factory.c +++ b/demos/widget-factory/widget-factory.c @@ -1210,12 +1210,12 @@ typedef struct { static void add_background (GtkWidget *flowbox, const char *filename, - GdkPixbuf *pixbuf, + GdkTexture *texture, gboolean is_resource) { GtkWidget *child; - child = gtk_picture_new_for_pixbuf (pixbuf); + child = gtk_picture_new_for_paintable (GDK_PAINTABLE (texture)); gtk_widget_set_size_request (child, 110, 70); gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), child, -1); child = gtk_widget_get_parent (child); @@ -1231,6 +1231,7 @@ background_loaded_cb (GObject *source, { BackgroundData *bd = data; GdkPixbuf *pixbuf; + GdkTexture *texture; GError *error = NULL; pixbuf = gdk_pixbuf_new_from_stream_finish (res, &error); @@ -1241,8 +1242,11 @@ background_loaded_cb (GObject *source, return; } - add_background (bd->flowbox, bd->filename, pixbuf, FALSE); + texture = gdk_texture_new_for_pixbuf (pixbuf); + add_background (bd->flowbox, bd->filename, texture, FALSE); + g_object_unref (texture); + g_object_unref (pixbuf); g_free (bd->filename); g_free (bd); } @@ -1259,7 +1263,10 @@ populate_flowbox (GtkWidget *flowbox) GInputStream *stream; BackgroundData *bd; GdkPixbuf *pixbuf; + GdkTexture *texture; GtkWidget *child; + guchar *data; + GBytes *bytes; int i; const char *resources[] = { "sunset.jpg", "portland-rose.jpg", "beach.jpg", "nyc.jpg" @@ -1270,9 +1277,14 @@ populate_flowbox (GtkWidget *flowbox) g_object_set_data (G_OBJECT (flowbox), "populated", GUINT_TO_POINTER (1)); - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 110, 70); - gdk_pixbuf_fill (pixbuf, 0xffffffff); - child = gtk_picture_new_for_pixbuf (pixbuf); + data = g_malloc (4 * 110 * 70); + memset (data, 0xff, 4 * 110 * 70); + bytes = g_bytes_new_take (data, 4 * 110 * 70); + texture = gdk_memory_texture_new (110, 70, GDK_MEMORY_DEFAULT, bytes, 4 * 110); + child = gtk_picture_new_for_paintable (GDK_PAINTABLE (texture)); + g_object_unref (texture); + g_bytes_unref (bytes); + gtk_widget_add_css_class (child, "frame"); gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), child, -1); @@ -1280,7 +1292,10 @@ populate_flowbox (GtkWidget *flowbox) { filename = g_strconcat ("/org/gtk/WidgetFactory4/", resources[i], NULL); pixbuf = gdk_pixbuf_new_from_resource_at_scale (filename, 110, 110, TRUE, NULL); - add_background (flowbox, filename, pixbuf, TRUE); + texture = gdk_texture_new_for_pixbuf (pixbuf); + add_background (flowbox, filename, texture, TRUE); + g_object_unref (texture); + g_object_unref (pixbuf); } location = "/usr/share/backgrounds/gnome"; |