procsvisualizer: port to GTK 4

This is a minimal port. We'll definitely want to cache the rendered cairo
surface going forward instead of redrawing every frame.
This commit is contained in:
Christian Hergert
2021-09-28 15:39:56 -07:00
parent 234d37ea12
commit 226a1f147b

View File

@ -183,24 +183,24 @@ sysprof_procs_visualizer_set_reader (SysprofVisualizer *visualizer,
g_task_run_in_thread (task, discovery_worker); g_task_run_in_thread (task, discovery_worker);
} }
static gboolean static void
sysprof_procs_visualizer_draw (GtkWidget *widget, sysprof_procs_visualizer_snapshot (GtkWidget *widget,
cairo_t *cr) GtkSnapshot *snapshot)
{ {
SysprofProcsVisualizer *self = (SysprofProcsVisualizer *)widget; SysprofProcsVisualizer *self = (SysprofProcsVisualizer *)widget;
g_autofree SysprofVisualizerAbsolutePoint *points = NULL; g_autofree SysprofVisualizerAbsolutePoint *points = NULL;
gboolean ret = GDK_EVENT_PROPAGATE;
GtkAllocation alloc; GtkAllocation alloc;
GdkRGBA background; GdkRGBA background;
GdkRGBA foreground; GdkRGBA foreground;
const Point *fpoints; const Point *fpoints;
guint n_fpoints = 0; guint n_fpoints = 0;
Discovery *d; Discovery *d;
cairo_t *cr;
gdouble last_x = 0; gdouble last_x = 0;
gdouble last_y = 0; gdouble last_y = 0;
g_assert (SYSPROF_IS_PROCS_VISUALIZER (self)); g_assert (SYSPROF_IS_PROCS_VISUALIZER (self));
g_assert (cr != NULL); g_assert (snapshot != NULL);
gtk_widget_get_allocation (widget, &alloc); gtk_widget_get_allocation (widget, &alloc);
@ -208,14 +208,17 @@ sysprof_procs_visualizer_draw (GtkWidget *widget,
background = foreground; background = foreground;
background.alpha *= .5; background.alpha *= .5;
ret = GTK_WIDGET_CLASS (sysprof_procs_visualizer_parent_class)->draw (widget, cr); GTK_WIDGET_CLASS (sysprof_procs_visualizer_parent_class)->snapshot (widget, snapshot);
if (!(d = self->discovery) || d->cache == NULL) if (!(d = self->discovery) || d->cache == NULL)
return ret; return;
if (!(fpoints = point_cache_get_points (d->cache, 1, &n_fpoints))) if (!(fpoints = point_cache_get_points (d->cache, 1, &n_fpoints)))
return ret; return;
/* This is all going to need offscreen drawing instead of new cairo every frame */
cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, alloc.width, alloc.height));
points = g_new0 (SysprofVisualizerAbsolutePoint, n_fpoints); points = g_new0 (SysprofVisualizerAbsolutePoint, n_fpoints);
sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (self), sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (self),
@ -254,7 +257,7 @@ sysprof_procs_visualizer_draw (GtkWidget *widget,
gdk_cairo_set_source_rgba (cr, &foreground); gdk_cairo_set_source_rgba (cr, &foreground);
cairo_stroke (cr); cairo_stroke (cr);
return ret; cairo_destroy (cr);
} }
static void static void
@ -276,7 +279,7 @@ sysprof_procs_visualizer_class_init (SysprofProcsVisualizerClass *klass)
object_class->finalize = sysprof_procs_visualizer_finalize; object_class->finalize = sysprof_procs_visualizer_finalize;
widget_class->draw = sysprof_procs_visualizer_draw; widget_class->snapshot = sysprof_procs_visualizer_snapshot;
visualizer_class->set_reader = sysprof_procs_visualizer_set_reader; visualizer_class->set_reader = sysprof_procs_visualizer_set_reader;
} }