diff options
author | Alexander Larsson <alexl@redhat.com> | 2020-09-29 09:36:10 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2020-09-29 09:51:16 +0200 |
commit | e76cb3e1e44b1bdc86864ab0a6992055d4bf1b9e (patch) | |
tree | 9067af998fc87e3f77ec1212bd64c8c35c64490f | |
parent | 8bcb031418a2676a2f64080ae74c51cd9e9fbf30 (diff) | |
download | gtk+-e76cb3e1e44b1bdc86864ab0a6992055d4bf1b9e.tar.gz |
gtk-demo: Add a shader paintable to the fishbowl
This gets around 500 instances at 60fps on my system.
-rw-r--r-- | demos/gtk-demo/fishbowl.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/demos/gtk-demo/fishbowl.c b/demos/gtk-demo/fishbowl.c index 40c8203726..659318b7cd 100644 --- a/demos/gtk-demo/fishbowl.c +++ b/demos/gtk-demo/fishbowl.c @@ -9,6 +9,7 @@ #include "gtkfishbowl.h" #include "gtkgears.h" +#include "gskshaderpaintable.h" const char *const css = ".blurred-button {" @@ -149,6 +150,38 @@ create_switch (void) return w; } +static gboolean +update_paintable (GtkWidget *widget, + GdkFrameClock *frame_clock, + gpointer user_data) +{ + GskShaderPaintable *paintable; + gint64 frame_time; + + paintable = GSK_SHADER_PAINTABLE (gtk_picture_get_paintable (GTK_PICTURE (widget))); + frame_time = gdk_frame_clock_get_frame_time (frame_clock); + gsk_shader_paintable_update_time (paintable, 0, frame_time); + + return G_SOURCE_CONTINUE; +} + +static GtkWidget * +create_cogs (void) +{ + GtkWidget *picture; + static GskGLShader *cog_shader = NULL; + GdkPaintable *paintable; + + if (cog_shader == NULL) + cog_shader = gsk_gl_shader_new_from_resource ("/gltransition/cogs2.glsl"); + paintable = gsk_shader_paintable_new (g_object_ref (cog_shader), NULL); + picture = gtk_picture_new_for_paintable (paintable); + gtk_widget_set_size_request (picture, 150, 75); + gtk_widget_add_tick_callback (picture, update_paintable, NULL, NULL); + + return picture; +} + static void mapped (GtkWidget *w) { @@ -185,6 +218,7 @@ static const struct { { "Gears", create_gears }, { "Switch", create_switch }, { "Menubutton", create_menu_button }, + { "Shader", create_cogs }, }; static int selected_widget_type = -1; |