mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
source tree cleanup
The lib/ directory was getting a bit out of hand, so this tries to organize things a bit so it is easier going forward to locate the code people want to patch.
This commit is contained in:
170
lib/visualizers/sp-cpu-visualizer-row.c
Normal file
170
lib/visualizers/sp-cpu-visualizer-row.c
Normal file
@ -0,0 +1,170 @@
|
||||
/* sp-cpu-visualizer-row.c
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "sp-cpu-visualizer-row"
|
||||
|
||||
#include "capture/sp-capture-condition.h"
|
||||
#include "capture/sp-capture-cursor.h"
|
||||
#include "util/sp-color-cycle.h"
|
||||
#include "visualizers/sp-cpu-visualizer-row.h"
|
||||
|
||||
struct _SpCpuVisualizerRow
|
||||
{
|
||||
SpLineVisualizerRow parent_instance;
|
||||
SpColorCycle *colors;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (SpCpuVisualizerRow, sp_cpu_visualizer_row, SP_TYPE_LINE_VISUALIZER_ROW)
|
||||
|
||||
static gboolean
|
||||
sp_cpu_visualizer_counter_found (const SpCaptureFrame *frame,
|
||||
gpointer user_data)
|
||||
{
|
||||
const SpCaptureFrameCounterDefine *def = (SpCaptureFrameCounterDefine *)frame;
|
||||
GArray *counters = user_data;
|
||||
gboolean found = FALSE;
|
||||
|
||||
g_assert (frame->type == SP_CAPTURE_FRAME_CTRDEF);
|
||||
|
||||
/*
|
||||
* In practice, all the CPU counters are defined at once, so we can avoid
|
||||
* walking the rest of the capture by returning after we find our CTRDEF.
|
||||
*/
|
||||
|
||||
for (guint i = 0; i < def->n_counters; i++)
|
||||
{
|
||||
if (g_str_equal (def->counters[i].category, "CPU Percent"))
|
||||
{
|
||||
guint id = def->counters[i].id;
|
||||
g_array_append_val (counters, id);
|
||||
found = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return !found;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_cpu_visualizer_row_discover_counters (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *canellable)
|
||||
{
|
||||
const SpCaptureFrameType types[] = { SP_CAPTURE_FRAME_CTRDEF };
|
||||
SpCaptureReader *reader = task_data;
|
||||
g_autoptr(SpCaptureCursor) cursor = NULL;
|
||||
SpCpuVisualizerRow *self = source_object;
|
||||
g_autoptr(GArray) counters = NULL;
|
||||
|
||||
g_assert (G_IS_TASK (task));
|
||||
g_assert (SP_IS_CPU_VISUALIZER_ROW (self));
|
||||
g_assert (reader != NULL);
|
||||
|
||||
counters = g_array_new (FALSE, FALSE, sizeof (guint));
|
||||
cursor = sp_capture_cursor_new (reader);
|
||||
sp_capture_cursor_add_condition (cursor, sp_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types));
|
||||
sp_capture_cursor_foreach (cursor, sp_cpu_visualizer_counter_found, counters);
|
||||
g_task_return_pointer (task, g_steal_pointer (&counters), (GDestroyNotify)g_array_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
complete_counters (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
SpCpuVisualizerRow *self = (SpCpuVisualizerRow *)object;
|
||||
g_autoptr(GArray) counters = NULL;
|
||||
|
||||
g_assert (SP_IS_CPU_VISUALIZER_ROW (self));
|
||||
g_assert (G_IS_TASK (result));
|
||||
|
||||
counters = g_task_propagate_pointer (G_TASK (result), NULL);
|
||||
|
||||
if (counters != NULL)
|
||||
{
|
||||
for (guint i = 0; i < counters->len; i++)
|
||||
{
|
||||
guint counter_id = g_array_index (counters, guint, i);
|
||||
GdkRGBA color;
|
||||
|
||||
sp_color_cycle_next (self->colors, &color);
|
||||
sp_line_visualizer_row_add_counter (SP_LINE_VISUALIZER_ROW (self), counter_id, &color);
|
||||
}
|
||||
}
|
||||
|
||||
/* Hide ourself if we failed to locate counters */
|
||||
gtk_widget_set_visible (GTK_WIDGET (self), counters != NULL && counters->len > 0);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_cpu_visualizer_row_set_reader (SpVisualizerRow *row,
|
||||
SpCaptureReader *reader)
|
||||
{
|
||||
SpCpuVisualizerRow *self = (SpCpuVisualizerRow *)row;
|
||||
g_autoptr(GTask) task = NULL;
|
||||
|
||||
g_assert (SP_IS_CPU_VISUALIZER_ROW (row));
|
||||
|
||||
sp_color_cycle_reset (self->colors);
|
||||
|
||||
sp_line_visualizer_row_clear (SP_LINE_VISUALIZER_ROW (row));
|
||||
|
||||
SP_VISUALIZER_ROW_CLASS (sp_cpu_visualizer_row_parent_class)->set_reader (row, reader);
|
||||
|
||||
if (reader != NULL)
|
||||
{
|
||||
task = g_task_new (self, NULL, complete_counters, NULL);
|
||||
g_task_set_source_tag (task, sp_cpu_visualizer_row_set_reader);
|
||||
g_task_set_task_data (task, sp_capture_reader_copy (reader),
|
||||
(GDestroyNotify)sp_capture_reader_unref);
|
||||
g_task_run_in_thread (task, sp_cpu_visualizer_row_discover_counters);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_cpu_visualizer_row_finalize (GObject *object)
|
||||
{
|
||||
SpCpuVisualizerRow *self = (SpCpuVisualizerRow *)object;
|
||||
|
||||
g_clear_pointer (&self->colors, sp_color_cycle_unref);
|
||||
|
||||
G_OBJECT_CLASS (sp_cpu_visualizer_row_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_cpu_visualizer_row_class_init (SpCpuVisualizerRowClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
SpVisualizerRowClass *row_class = SP_VISUALIZER_ROW_CLASS (klass);
|
||||
|
||||
object_class->finalize = sp_cpu_visualizer_row_finalize;
|
||||
|
||||
row_class->set_reader = sp_cpu_visualizer_row_set_reader;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_cpu_visualizer_row_init (SpCpuVisualizerRow *self)
|
||||
{
|
||||
self->colors = sp_color_cycle_new ();
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
sp_cpu_visualizer_row_new (void)
|
||||
{
|
||||
return g_object_new (SP_TYPE_CPU_VISUALIZER_ROW, NULL);
|
||||
}
|
||||
34
lib/visualizers/sp-cpu-visualizer-row.h
Normal file
34
lib/visualizers/sp-cpu-visualizer-row.h
Normal file
@ -0,0 +1,34 @@
|
||||
/* sp-cpu-visualizer-row.h
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SP_CPU_VISUALIZER_ROW_H
|
||||
#define SP_CPU_VISUALIZER_ROW_H
|
||||
|
||||
#include "visualizers/sp-line-visualizer-row.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SP_TYPE_CPU_VISUALIZER_ROW (sp_cpu_visualizer_row_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (SpCpuVisualizerRow, sp_cpu_visualizer_row, SP, CPU_VISUALIZER_ROW, SpLineVisualizerRow)
|
||||
|
||||
GtkWidget *sp_cpu_visualizer_row_new (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* SP_CPU_VISUALIZER_ROW_H */
|
||||
684
lib/visualizers/sp-line-visualizer-row.c
Normal file
684
lib/visualizers/sp-line-visualizer-row.c
Normal file
@ -0,0 +1,684 @@
|
||||
/* sp-line-visualizer-row.c
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "sp-line-visualizer-row"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "util/pointcache.h"
|
||||
#include "capture/sp-capture-condition.h"
|
||||
#include "capture/sp-capture-cursor.h"
|
||||
#include "visualizers/sp-line-visualizer-row.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/*
|
||||
* Our reader as assigned by the visualizer system.
|
||||
*/
|
||||
SpCaptureReader *reader;
|
||||
|
||||
/*
|
||||
* An array of LineInfo which contains information about the counters
|
||||
* we need to render.
|
||||
*/
|
||||
GArray *lines;
|
||||
|
||||
/*
|
||||
* This is our set of cached points to render. Once it is assigned here,
|
||||
* it is immutable (and therefore may be shared with worker processes
|
||||
* that are rendering the points).
|
||||
*/
|
||||
PointCache *cache;
|
||||
|
||||
/*
|
||||
* Child widget to display the label in the upper corner.
|
||||
*/
|
||||
GtkLabel *label;
|
||||
|
||||
/*
|
||||
* Range of the scale for lower and upper.
|
||||
*/
|
||||
gdouble y_lower;
|
||||
gdouble y_upper;
|
||||
|
||||
/*
|
||||
* If we have a new counter discovered or the reader is set, we might
|
||||
* want to delay loading until we return to the main loop. This can
|
||||
* help us avoid doing duplicate work.
|
||||
*/
|
||||
guint queued_load;
|
||||
} SpLineVisualizerRowPrivate;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
guint id;
|
||||
gdouble line_width;
|
||||
GdkRGBA background;
|
||||
GdkRGBA foreground;
|
||||
guint use_default_style : 1;
|
||||
guint fill : 1;
|
||||
} LineInfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SpCaptureCursor *cursor;
|
||||
GArray *lines;
|
||||
PointCache *cache;
|
||||
gint64 begin_time;
|
||||
gint64 end_time;
|
||||
gdouble y_lower;
|
||||
gdouble y_upper;
|
||||
} LoadData;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (SpLineVisualizerRow, sp_line_visualizer_row, SP_TYPE_VISUALIZER_ROW)
|
||||
|
||||
static void sp_line_visualizer_row_load_data_async (SpLineVisualizerRow *self,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
static PointCache *sp_line_visualizer_row_load_data_finish (SpLineVisualizerRow *self,
|
||||
GAsyncResult *result,
|
||||
GError **error);
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_TITLE,
|
||||
PROP_Y_LOWER,
|
||||
PROP_Y_UPPER,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
static void
|
||||
load_data_free (gpointer data)
|
||||
{
|
||||
LoadData *load = data;
|
||||
|
||||
if (load != NULL)
|
||||
{
|
||||
g_clear_pointer (&load->lines, g_array_unref);
|
||||
g_clear_object (&load->cursor);
|
||||
g_clear_pointer (&load->cache, point_cache_unref);
|
||||
g_slice_free (LoadData, load);
|
||||
}
|
||||
}
|
||||
|
||||
static GArray *
|
||||
copy_array (GArray *ar)
|
||||
{
|
||||
GArray *ret;
|
||||
|
||||
ret = g_array_sized_new (FALSE, FALSE, g_array_get_element_size (ar), ar->len);
|
||||
g_array_set_size (ret, ar->len);
|
||||
memcpy (ret->data, ar->data, ar->len * g_array_get_element_size (ret));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sp_line_visualizer_row_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
{
|
||||
SpLineVisualizerRow *self = (SpLineVisualizerRow *)widget;
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
GtkStyleContext *style_context;
|
||||
GtkStateFlags flags;
|
||||
GtkAllocation alloc;
|
||||
GdkRGBA foreground;
|
||||
gboolean ret;
|
||||
|
||||
g_assert (SP_IS_LINE_VISUALIZER_ROW (widget));
|
||||
g_assert (cr != NULL);
|
||||
|
||||
gtk_widget_get_allocation (widget, &alloc);
|
||||
|
||||
ret = GTK_WIDGET_CLASS (sp_line_visualizer_row_parent_class)->draw (widget, cr);
|
||||
|
||||
if (priv->cache == NULL)
|
||||
return ret;
|
||||
|
||||
style_context = gtk_widget_get_style_context (widget);
|
||||
flags = gtk_widget_get_state_flags (widget);
|
||||
gtk_style_context_get_color (style_context, flags, &foreground);
|
||||
|
||||
for (guint line = 0; line < priv->lines->len; line++)
|
||||
{
|
||||
g_autofree SpVisualizerRowAbsolutePoint *points = NULL;
|
||||
const LineInfo *line_info = &g_array_index (priv->lines, LineInfo, line);
|
||||
const Point *fpoints;
|
||||
guint n_fpoints = 0;
|
||||
GdkRGBA color;
|
||||
|
||||
fpoints = point_cache_get_points (priv->cache, line_info->id, &n_fpoints);
|
||||
|
||||
if (n_fpoints > 0)
|
||||
{
|
||||
gfloat last_x;
|
||||
gfloat last_y;
|
||||
|
||||
points = g_new0 (SpVisualizerRowAbsolutePoint, n_fpoints);
|
||||
|
||||
sp_visualizer_row_translate_points (SP_VISUALIZER_ROW (self),
|
||||
(const SpVisualizerRowRelativePoint *)fpoints,
|
||||
n_fpoints,
|
||||
points,
|
||||
n_fpoints);
|
||||
|
||||
last_x = points[0].x;
|
||||
last_y = points[0].y;
|
||||
|
||||
if (line_info->fill)
|
||||
{
|
||||
cairo_move_to (cr, last_x, alloc.height);
|
||||
cairo_line_to (cr, last_x, last_y);
|
||||
}
|
||||
else
|
||||
{
|
||||
cairo_move_to (cr, last_x, last_y);
|
||||
}
|
||||
|
||||
for (guint i = 1; i < n_fpoints; i++)
|
||||
{
|
||||
cairo_curve_to (cr,
|
||||
last_x + ((points[i].x - last_x) / 2),
|
||||
last_y,
|
||||
last_x + ((points[i].x - last_x) / 2),
|
||||
points[i].y,
|
||||
points[i].x,
|
||||
points[i].y);
|
||||
last_x = points[i].x;
|
||||
last_y = points[i].y;
|
||||
}
|
||||
|
||||
if (line_info->fill)
|
||||
{
|
||||
cairo_line_to (cr, last_x, alloc.height);
|
||||
cairo_close_path (cr);
|
||||
}
|
||||
|
||||
cairo_set_line_width (cr, line_info->line_width);
|
||||
|
||||
if (line_info->use_default_style)
|
||||
color = foreground;
|
||||
else
|
||||
color = line_info->foreground;
|
||||
|
||||
gdk_cairo_set_source_rgba (cr, &color);
|
||||
|
||||
if (line_info->fill)
|
||||
cairo_fill (cr);
|
||||
else
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_load_data_cb (GObject *object,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
SpLineVisualizerRow *self = (SpLineVisualizerRow *)object;
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(PointCache) cache = NULL;
|
||||
|
||||
g_assert (SP_IS_LINE_VISUALIZER_ROW (self));
|
||||
|
||||
cache = sp_line_visualizer_row_load_data_finish (self, result, &error);
|
||||
|
||||
if (cache == NULL)
|
||||
{
|
||||
g_warning ("%s", error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
g_clear_pointer (&priv->cache, point_cache_unref);
|
||||
priv->cache = g_steal_pointer (&cache);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sp_line_visualizer_row_do_reload (gpointer data)
|
||||
{
|
||||
SpLineVisualizerRow *self = data;
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
|
||||
g_assert (SP_IS_LINE_VISUALIZER_ROW (self));
|
||||
|
||||
priv->queued_load = 0;
|
||||
|
||||
if (priv->reader != NULL)
|
||||
{
|
||||
sp_line_visualizer_row_load_data_async (self,
|
||||
NULL,
|
||||
sp_line_visualizer_row_load_data_cb,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_queue_reload (SpLineVisualizerRow *self)
|
||||
{
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
|
||||
g_assert (SP_IS_LINE_VISUALIZER_ROW (self));
|
||||
|
||||
if (priv->queued_load == 0)
|
||||
{
|
||||
priv->queued_load = gdk_threads_add_idle_full (G_PRIORITY_LOW,
|
||||
sp_line_visualizer_row_do_reload,
|
||||
self,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_set_reader (SpVisualizerRow *row,
|
||||
SpCaptureReader *reader)
|
||||
{
|
||||
SpLineVisualizerRow *self = (SpLineVisualizerRow *)row;
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
|
||||
g_assert (SP_IS_LINE_VISUALIZER_ROW (self));
|
||||
|
||||
if (priv->reader != reader)
|
||||
{
|
||||
if (priv->reader != NULL)
|
||||
{
|
||||
sp_capture_reader_unref (priv->reader);
|
||||
priv->reader = NULL;
|
||||
}
|
||||
|
||||
if (reader != NULL)
|
||||
priv->reader = sp_capture_reader_ref (reader);
|
||||
|
||||
sp_line_visualizer_row_queue_reload (self);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_finalize (GObject *object)
|
||||
{
|
||||
SpLineVisualizerRow *self = (SpLineVisualizerRow *)object;
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
|
||||
g_clear_pointer (&priv->lines, g_array_unref);
|
||||
g_clear_pointer (&priv->cache, point_cache_unref);
|
||||
g_clear_pointer (&priv->reader, sp_capture_reader_unref);
|
||||
|
||||
if (priv->queued_load != 0)
|
||||
{
|
||||
g_source_remove (priv->queued_load);
|
||||
priv->queued_load = 0;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (sp_line_visualizer_row_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SpLineVisualizerRow *self = SP_LINE_VISUALIZER_ROW (object);
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_TITLE:
|
||||
g_object_get_property (G_OBJECT (priv->label), "label", value);
|
||||
break;
|
||||
|
||||
case PROP_Y_LOWER:
|
||||
g_value_set_double (value, priv->y_lower);
|
||||
break;
|
||||
|
||||
case PROP_Y_UPPER:
|
||||
g_value_set_double (value, priv->y_upper);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SpLineVisualizerRow *self = SP_LINE_VISUALIZER_ROW (object);
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_TITLE:
|
||||
g_object_set_property (G_OBJECT (priv->label), "label", value);
|
||||
break;
|
||||
|
||||
case PROP_Y_LOWER:
|
||||
priv->y_lower = g_value_get_double (value);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_Y_UPPER:
|
||||
priv->y_upper = g_value_get_double (value);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_class_init (SpLineVisualizerRowClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
SpVisualizerRowClass *visualizer_class = SP_VISUALIZER_ROW_CLASS (klass);
|
||||
|
||||
object_class->finalize = sp_line_visualizer_row_finalize;
|
||||
object_class->get_property = sp_line_visualizer_row_get_property;
|
||||
object_class->set_property = sp_line_visualizer_row_set_property;
|
||||
|
||||
widget_class->draw = sp_line_visualizer_row_draw;
|
||||
|
||||
visualizer_class->set_reader = sp_line_visualizer_row_set_reader;
|
||||
|
||||
properties [PROP_TITLE] =
|
||||
g_param_spec_string ("title",
|
||||
"Title",
|
||||
"The title of the row",
|
||||
NULL,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_Y_LOWER] =
|
||||
g_param_spec_double ("y-lower",
|
||||
"Y Lower",
|
||||
"The lowest Y value for the visualizer",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
0.0,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_Y_UPPER] =
|
||||
g_param_spec_double ("y-upper",
|
||||
"Y Upper",
|
||||
"The highest Y value for the visualizer",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
100.0,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_init (SpLineVisualizerRow *self)
|
||||
{
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
PangoAttrList *attrs = pango_attr_list_new ();
|
||||
|
||||
priv->lines = g_array_new (FALSE, FALSE, sizeof (LineInfo));
|
||||
|
||||
pango_attr_list_insert (attrs, pango_attr_scale_new (PANGO_SCALE_SMALL * PANGO_SCALE_SMALL));
|
||||
|
||||
priv->label = g_object_new (GTK_TYPE_LABEL,
|
||||
"attributes", attrs,
|
||||
"visible", TRUE,
|
||||
"xalign", 0.0f,
|
||||
"yalign", 0.0f,
|
||||
NULL);
|
||||
gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (priv->label));
|
||||
|
||||
pango_attr_list_unref (attrs);
|
||||
}
|
||||
|
||||
void
|
||||
sp_line_visualizer_row_add_counter (SpLineVisualizerRow *self,
|
||||
guint counter_id,
|
||||
const GdkRGBA *color)
|
||||
{
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
LineInfo line_info = { 0 };
|
||||
|
||||
g_assert (SP_IS_LINE_VISUALIZER_ROW (self));
|
||||
g_assert (priv->lines != NULL);
|
||||
|
||||
line_info.id = counter_id;
|
||||
line_info.line_width = 1.0;
|
||||
|
||||
if (color != NULL)
|
||||
{
|
||||
line_info.foreground = *color;
|
||||
line_info.use_default_style = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
line_info.use_default_style = TRUE;
|
||||
}
|
||||
|
||||
g_array_append_val (priv->lines, line_info);
|
||||
|
||||
if (SP_LINE_VISUALIZER_ROW_GET_CLASS (self)->counter_added)
|
||||
SP_LINE_VISUALIZER_ROW_GET_CLASS (self)->counter_added (self, counter_id);
|
||||
|
||||
sp_line_visualizer_row_queue_reload (self);
|
||||
}
|
||||
|
||||
void
|
||||
sp_line_visualizer_row_clear (SpLineVisualizerRow *self)
|
||||
{
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (SP_IS_LINE_VISUALIZER_ROW (self));
|
||||
|
||||
if (priv->lines->len > 0)
|
||||
g_array_remove_range (priv->lines, 0, priv->lines->len);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
contains_id (GArray *ar,
|
||||
guint id)
|
||||
{
|
||||
for (guint i = 0; i < ar->len; i++)
|
||||
{
|
||||
const LineInfo *info = &g_array_index (ar, LineInfo, i);
|
||||
if (info->id == id)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline guint8
|
||||
counter_type (LoadData *load,
|
||||
guint counter_id)
|
||||
{
|
||||
/* TODO: Support other counter types
|
||||
*
|
||||
* We need to keep some information on the counter (by id) so that we
|
||||
* can track the counters type (which is a 1-byte type id).
|
||||
*/
|
||||
return SP_CAPTURE_COUNTER_DOUBLE;
|
||||
}
|
||||
|
||||
static inline gfloat
|
||||
calc_x (gint64 lower,
|
||||
gint64 upper,
|
||||
gint64 value)
|
||||
{
|
||||
return (gdouble)(value - lower) / (gdouble)(upper - lower);
|
||||
}
|
||||
|
||||
static inline gfloat
|
||||
calc_y_double (gdouble lower,
|
||||
gdouble upper,
|
||||
gdouble value)
|
||||
{
|
||||
return (value - lower) / (upper - lower);
|
||||
}
|
||||
|
||||
static inline gfloat
|
||||
calc_y_int64 (gint64 lower,
|
||||
gint64 upper,
|
||||
gint64 value)
|
||||
{
|
||||
return (gdouble)(value - lower) / (gdouble)(upper - lower);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sp_line_visualizer_row_load_data_frame_cb (const SpCaptureFrame *frame,
|
||||
gpointer user_data)
|
||||
{
|
||||
LoadData *load = user_data;
|
||||
|
||||
g_assert (frame != NULL);
|
||||
g_assert (frame->type == SP_CAPTURE_FRAME_CTRSET ||
|
||||
frame->type == SP_CAPTURE_FRAME_CTRDEF);
|
||||
g_assert (load != NULL);
|
||||
|
||||
if (frame->type == SP_CAPTURE_FRAME_CTRSET)
|
||||
{
|
||||
const SpCaptureFrameCounterSet *set = (SpCaptureFrameCounterSet *)frame;
|
||||
gfloat x = calc_x (load->begin_time, load->end_time, frame->time);
|
||||
|
||||
for (guint i = 0; i < set->n_values; i++)
|
||||
{
|
||||
const SpCaptureCounterValues *group = &set->values[i];
|
||||
|
||||
for (guint j = 0; j < G_N_ELEMENTS (group->ids); j++)
|
||||
{
|
||||
guint counter_id = group->ids[j];
|
||||
|
||||
if (counter_id != 0 && contains_id (load->lines, counter_id))
|
||||
{
|
||||
gfloat y;
|
||||
|
||||
if (counter_type (load, counter_id) == SP_CAPTURE_COUNTER_DOUBLE)
|
||||
y = calc_y_double (load->y_lower, load->y_upper, group->values[j].vdbl);
|
||||
else
|
||||
y = calc_y_int64 (load->y_lower, load->y_upper, group->values[j].v64);
|
||||
|
||||
point_cache_add_point_to_set (load->cache, counter_id, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_load_data_worker (GTask *task,
|
||||
gpointer source_object,
|
||||
gpointer task_data,
|
||||
GCancellable *cancellable)
|
||||
{
|
||||
LoadData *load = task_data;
|
||||
g_autoptr(GArray) counter_ids = NULL;
|
||||
|
||||
g_assert (G_IS_TASK (task));
|
||||
g_assert (SP_IS_LINE_VISUALIZER_ROW (source_object));
|
||||
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
|
||||
|
||||
counter_ids = g_array_new (FALSE, FALSE, sizeof (guint));
|
||||
|
||||
for (guint i = 0; i < load->lines->len; i++)
|
||||
{
|
||||
const LineInfo *line_info = &g_array_index (load->lines, LineInfo, i);
|
||||
g_array_append_val (counter_ids, line_info->id);
|
||||
}
|
||||
|
||||
sp_capture_cursor_add_condition (
|
||||
load->cursor,
|
||||
sp_capture_condition_new_where_counter_in (counter_ids->len,
|
||||
(guint *)(gpointer)counter_ids->data));
|
||||
sp_capture_cursor_foreach (load->cursor, sp_line_visualizer_row_load_data_frame_cb, load);
|
||||
g_task_return_pointer (task, g_steal_pointer (&load->cache), (GDestroyNotify)point_cache_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_line_visualizer_row_load_data_async (SpLineVisualizerRow *self,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
SpLineVisualizerRowPrivate *priv = sp_line_visualizer_row_get_instance_private (self);
|
||||
g_autoptr(GTask) task = NULL;
|
||||
LoadData *load;
|
||||
|
||||
g_assert (SP_IS_LINE_VISUALIZER_ROW (self));
|
||||
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
|
||||
|
||||
task = g_task_new (self, cancellable, callback, user_data);
|
||||
g_task_set_priority (task, G_PRIORITY_LOW);
|
||||
g_task_set_source_tag (task, sp_line_visualizer_row_load_data_async);
|
||||
|
||||
if (priv->reader == NULL)
|
||||
{
|
||||
g_task_return_new_error (task,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"No data loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
load = g_slice_new0 (LoadData);
|
||||
load->cache = point_cache_new ();
|
||||
load->y_lower = priv->y_lower;
|
||||
load->y_upper = priv->y_upper;
|
||||
load->begin_time = sp_capture_reader_get_start_time (priv->reader);
|
||||
load->end_time = sp_capture_reader_get_end_time (priv->reader);
|
||||
load->cursor = sp_capture_cursor_new (priv->reader);
|
||||
load->lines = copy_array (priv->lines);
|
||||
|
||||
for (guint i = 0; i < load->lines->len; i++)
|
||||
{
|
||||
const LineInfo *line_info = &g_array_index (load->lines, LineInfo, i);
|
||||
|
||||
point_cache_add_set (load->cache, line_info->id);
|
||||
}
|
||||
|
||||
g_task_set_task_data (task, load, load_data_free);
|
||||
g_task_run_in_thread (task, sp_line_visualizer_row_load_data_worker);
|
||||
}
|
||||
|
||||
static PointCache *
|
||||
sp_line_visualizer_row_load_data_finish (SpLineVisualizerRow *self,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_assert (SP_IS_LINE_VISUALIZER_ROW (self));
|
||||
g_assert (G_IS_TASK (result));
|
||||
|
||||
return g_task_propagate_pointer (G_TASK (result), error);
|
||||
}
|
||||
63
lib/visualizers/sp-line-visualizer-row.h
Normal file
63
lib/visualizers/sp-line-visualizer-row.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* sp-line-visualizer-row.h
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SP_LINE_VISUALIZER_ROW_H
|
||||
#define SP_LINE_VISUALIZER_ROW_H
|
||||
|
||||
#include "visualizers/sp-visualizer-row.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SP_TYPE_LINE_VISUALIZER_ROW (sp_line_visualizer_row_get_type())
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE (SpLineVisualizerRow, sp_line_visualizer_row, SP, LINE_VISUALIZER_ROW, SpVisualizerRow)
|
||||
|
||||
struct _SpLineVisualizerRowClass
|
||||
{
|
||||
SpVisualizerRowClass parent_class;
|
||||
|
||||
void (*counter_added) (SpLineVisualizerRow *self,
|
||||
guint counter_id);
|
||||
|
||||
gpointer _reserved1;
|
||||
gpointer _reserved2;
|
||||
gpointer _reserved3;
|
||||
gpointer _reserved4;
|
||||
gpointer _reserved5;
|
||||
gpointer _reserved6;
|
||||
gpointer _reserved7;
|
||||
gpointer _reserved8;
|
||||
gpointer _reserved9;
|
||||
gpointer _reserved10;
|
||||
gpointer _reserved11;
|
||||
gpointer _reserved12;
|
||||
gpointer _reserved13;
|
||||
gpointer _reserved14;
|
||||
gpointer _reserved15;
|
||||
gpointer _reserved16;
|
||||
};
|
||||
|
||||
GtkWidget *sp_line_visualizer_row_new (void);
|
||||
void sp_line_visualizer_row_clear (SpLineVisualizerRow *self);
|
||||
void sp_line_visualizer_row_add_counter (SpLineVisualizerRow *self,
|
||||
guint counter_id,
|
||||
const GdkRGBA *color);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* SP_LINE_VISUALIZER_ROW_H */
|
||||
233
lib/visualizers/sp-visualizer-list.c
Normal file
233
lib/visualizers/sp-visualizer-list.c
Normal file
@ -0,0 +1,233 @@
|
||||
/* sp-visualizer-list.c
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "sp-visualizer-list"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "visualizers/sp-visualizer-list.h"
|
||||
#include "visualizers/sp-visualizer-row.h"
|
||||
#include "util/sp-zoom-manager.h"
|
||||
|
||||
#define NSEC_PER_SEC G_GUINT64_CONSTANT(1000000000)
|
||||
#define DEFAULT_PIXELS_PER_SECOND 20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SpCaptureReader *reader;
|
||||
SpZoomManager *zoom_manager;
|
||||
gint64 begin_time;
|
||||
gint64 end_time;
|
||||
} SpVisualizerListPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_READER,
|
||||
PROP_ZOOM_MANAGER,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (SpVisualizerList, sp_visualizer_list, GTK_TYPE_LIST_BOX)
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
static void
|
||||
sp_visualizer_list_add (GtkContainer *container,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
SpVisualizerList *self = (SpVisualizerList *)container;
|
||||
SpVisualizerListPrivate *priv = sp_visualizer_list_get_instance_private (self);
|
||||
|
||||
GTK_CONTAINER_CLASS (sp_visualizer_list_parent_class)->add (container, widget);
|
||||
|
||||
if (SP_IS_VISUALIZER_ROW (widget))
|
||||
{
|
||||
sp_visualizer_row_set_reader (SP_VISUALIZER_ROW (widget), priv->reader);
|
||||
sp_visualizer_row_set_zoom_manager (SP_VISUALIZER_ROW (widget), priv->zoom_manager);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_list_finalize (GObject *object)
|
||||
{
|
||||
SpVisualizerList *self = (SpVisualizerList *)object;
|
||||
SpVisualizerListPrivate *priv = sp_visualizer_list_get_instance_private (self);
|
||||
|
||||
g_clear_pointer (&priv->reader, sp_capture_reader_unref);
|
||||
|
||||
G_OBJECT_CLASS (sp_visualizer_list_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_list_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SpVisualizerList *self = SP_VISUALIZER_LIST (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_READER:
|
||||
g_value_set_boxed (value, sp_visualizer_list_get_reader (self));
|
||||
break;
|
||||
|
||||
case PROP_ZOOM_MANAGER:
|
||||
g_value_set_object (value, sp_visualizer_list_get_zoom_manager (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_list_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SpVisualizerList *self = SP_VISUALIZER_LIST (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_READER:
|
||||
sp_visualizer_list_set_reader (self, g_value_get_boxed (value));
|
||||
break;
|
||||
|
||||
case PROP_ZOOM_MANAGER:
|
||||
sp_visualizer_list_set_zoom_manager (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_list_class_init (SpVisualizerListClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
|
||||
|
||||
object_class->finalize = sp_visualizer_list_finalize;
|
||||
object_class->get_property = sp_visualizer_list_get_property;
|
||||
object_class->set_property = sp_visualizer_list_set_property;
|
||||
|
||||
container_class->add = sp_visualizer_list_add;
|
||||
|
||||
properties [PROP_READER] =
|
||||
g_param_spec_boxed ("reader",
|
||||
"Reader",
|
||||
"The capture reader",
|
||||
SP_TYPE_CAPTURE_READER,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_ZOOM_MANAGER] =
|
||||
g_param_spec_object ("zoom-manager",
|
||||
"Zoom Manager",
|
||||
"The zoom manager",
|
||||
SP_TYPE_ZOOM_MANAGER,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_list_init (SpVisualizerList *self)
|
||||
{
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
sp_visualizer_list_new (void)
|
||||
{
|
||||
return g_object_new (SP_TYPE_VISUALIZER_ROW, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* sp_visualizer_list_get_reader:
|
||||
*
|
||||
* Gets the reader that is being used for the #SpVisualizerList.
|
||||
*
|
||||
* Returns: (transfer none): An #SpCaptureReader
|
||||
*/
|
||||
SpCaptureReader *
|
||||
sp_visualizer_list_get_reader (SpVisualizerList *self)
|
||||
{
|
||||
SpVisualizerListPrivate *priv = sp_visualizer_list_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (SP_IS_VISUALIZER_LIST (self), NULL);
|
||||
|
||||
return priv->reader;
|
||||
}
|
||||
|
||||
void
|
||||
sp_visualizer_list_set_reader (SpVisualizerList *self,
|
||||
SpCaptureReader *reader)
|
||||
{
|
||||
SpVisualizerListPrivate *priv = sp_visualizer_list_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (SP_IS_VISUALIZER_LIST (self));
|
||||
|
||||
if (reader != priv->reader)
|
||||
{
|
||||
g_clear_pointer (&priv->reader, sp_capture_reader_unref);
|
||||
|
||||
if (reader != NULL)
|
||||
priv->reader = sp_capture_reader_ref (reader);
|
||||
|
||||
gtk_container_foreach (GTK_CONTAINER (self),
|
||||
(GtkCallback)sp_visualizer_row_set_reader,
|
||||
reader);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_READER]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sp_visualizer_list_set_zoom_manager (SpVisualizerList *self,
|
||||
SpZoomManager *zoom_manager)
|
||||
{
|
||||
SpVisualizerListPrivate *priv = sp_visualizer_list_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (SP_IS_VISUALIZER_LIST (self));
|
||||
g_return_if_fail (SP_IS_ZOOM_MANAGER (zoom_manager));
|
||||
|
||||
if (g_set_object (&priv->zoom_manager, zoom_manager))
|
||||
{
|
||||
gtk_container_foreach (GTK_CONTAINER (self),
|
||||
(GtkCallback)sp_visualizer_row_set_zoom_manager,
|
||||
zoom_manager);
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM_MANAGER]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sp_visualizer_list_get_zoom_manager:
|
||||
*
|
||||
* Returns: (nullable) (transfer): A #SpZoomManager or %NULL.
|
||||
*/
|
||||
SpZoomManager *
|
||||
sp_visualizer_list_get_zoom_manager (SpVisualizerList *self)
|
||||
{
|
||||
SpVisualizerListPrivate *priv = sp_visualizer_list_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (SP_IS_VISUALIZER_LIST (self), NULL);
|
||||
|
||||
return priv->zoom_manager;
|
||||
}
|
||||
57
lib/visualizers/sp-visualizer-list.h
Normal file
57
lib/visualizers/sp-visualizer-list.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* sp-visualizer-list.h
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SP_VISUALIZER_LIST_H
|
||||
#define SP_VISUALIZER_LIST_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "capture/sp-capture-reader.h"
|
||||
#include "util/sp-zoom-manager.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SP_TYPE_VISUALIZER_LIST (sp_visualizer_list_get_type())
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE (SpVisualizerList, sp_visualizer_list, SP, VISUALIZER_LIST, GtkListBox)
|
||||
|
||||
struct _SpVisualizerListClass
|
||||
{
|
||||
GtkListBoxClass parent_class;
|
||||
|
||||
gpointer _reserved1;
|
||||
gpointer _reserved2;
|
||||
gpointer _reserved3;
|
||||
gpointer _reserved4;
|
||||
gpointer _reserved5;
|
||||
gpointer _reserved6;
|
||||
gpointer _reserved7;
|
||||
gpointer _reserved8;
|
||||
};
|
||||
|
||||
GtkWidget *sp_visualizer_list_new (void);
|
||||
void sp_visualizer_list_set_reader (SpVisualizerList *self,
|
||||
SpCaptureReader *reader);
|
||||
SpCaptureReader *sp_visualizer_list_get_reader (SpVisualizerList *self);
|
||||
SpZoomManager *sp_visualizer_list_get_zoom_manager (SpVisualizerList *self);
|
||||
void sp_visualizer_list_set_zoom_manager (SpVisualizerList *self,
|
||||
SpZoomManager *zoom_manager);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* SP_VISUALIZER_LIST_H */
|
||||
30
lib/visualizers/sp-visualizer-row-private.h
Normal file
30
lib/visualizers/sp-visualizer-row-private.h
Normal file
@ -0,0 +1,30 @@
|
||||
/* sp-visualizer-row-private.h
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SP_VISUALIZER_ROW_PRIVATE_H
|
||||
#define SP_VISUALIZER_ROW_PRIVATE_H
|
||||
|
||||
#include "visualizers/sp-visualizer-row.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gint _sp_visualizer_row_get_graph_width (SpVisualizerRow *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* SP_VISUALIZER_ROW_PRIVATE_H */
|
||||
306
lib/visualizers/sp-visualizer-row.c
Normal file
306
lib/visualizers/sp-visualizer-row.c
Normal file
@ -0,0 +1,306 @@
|
||||
/* sp-visualizer-row.c
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "sp-visualizer-row"
|
||||
|
||||
#include "visualizers/sp-visualizer-row.h"
|
||||
#include "visualizers/sp-visualizer-row-private.h"
|
||||
|
||||
#define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
|
||||
#define DEFAULT_PIXELS_PER_SECOND 20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SpCaptureReader *reader;
|
||||
SpZoomManager *zoom_manager;
|
||||
} SpVisualizerRowPrivate;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ZOOM_MANAGER,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (SpVisualizerRow, sp_visualizer_row, GTK_TYPE_LIST_BOX_ROW)
|
||||
|
||||
gint
|
||||
_sp_visualizer_row_get_graph_width (SpVisualizerRow *self)
|
||||
{
|
||||
SpVisualizerRowPrivate *priv = sp_visualizer_row_get_instance_private (self);
|
||||
gdouble zoom_level = 1.0;
|
||||
gint64 begin_time;
|
||||
gint64 end_time;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_ROW (self));
|
||||
|
||||
if (priv->reader == NULL)
|
||||
return 0;
|
||||
|
||||
if (priv->zoom_manager != NULL)
|
||||
zoom_level = sp_zoom_manager_get_zoom (priv->zoom_manager);
|
||||
|
||||
begin_time = sp_capture_reader_get_start_time (priv->reader);
|
||||
end_time = sp_capture_reader_get_end_time (priv->reader);
|
||||
|
||||
return (end_time - begin_time)
|
||||
/ (gdouble)NSEC_PER_SEC
|
||||
* zoom_level
|
||||
* DEFAULT_PIXELS_PER_SECOND;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_row_get_preferred_width (GtkWidget *widget,
|
||||
gint *min_width,
|
||||
gint *nat_width)
|
||||
{
|
||||
SpVisualizerRow *self = (SpVisualizerRow *)widget;
|
||||
gint graph_width;
|
||||
gint real_min_width = 0;
|
||||
gint real_nat_width = 0;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_ROW (self));
|
||||
|
||||
GTK_WIDGET_CLASS (sp_visualizer_row_parent_class)->get_preferred_width (widget, &real_min_width, &real_nat_width);
|
||||
|
||||
graph_width = _sp_visualizer_row_get_graph_width (self);
|
||||
|
||||
*min_width = *nat_width = real_min_width + graph_width;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_row_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SpVisualizerRow *self = SP_VISUALIZER_ROW (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ZOOM_MANAGER:
|
||||
g_value_set_object (value, sp_visualizer_row_get_zoom_manager (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_row_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SpVisualizerRow *self = SP_VISUALIZER_ROW (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ZOOM_MANAGER:
|
||||
sp_visualizer_row_set_zoom_manager (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_row_finalize (GObject *object)
|
||||
{
|
||||
SpVisualizerRow *self = (SpVisualizerRow *)object;
|
||||
SpVisualizerRowPrivate *priv = sp_visualizer_row_get_instance_private (self);
|
||||
|
||||
g_clear_pointer (&priv->reader, sp_capture_reader_unref);
|
||||
g_clear_object (&priv->zoom_manager);
|
||||
|
||||
G_OBJECT_CLASS (sp_visualizer_row_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_row_class_init (SpVisualizerRowClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
object_class->finalize = sp_visualizer_row_finalize;
|
||||
object_class->get_property = sp_visualizer_row_get_property;
|
||||
object_class->set_property = sp_visualizer_row_set_property;
|
||||
|
||||
widget_class->get_preferred_width = sp_visualizer_row_get_preferred_width;
|
||||
|
||||
properties [PROP_ZOOM_MANAGER] =
|
||||
g_param_spec_object ("zoom-manager",
|
||||
"Zoom Manager",
|
||||
"Zoom Manager",
|
||||
SP_TYPE_ZOOM_MANAGER,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_row_init (SpVisualizerRow *self)
|
||||
{
|
||||
gtk_list_box_row_set_activatable (GTK_LIST_BOX_ROW (self), FALSE);
|
||||
gtk_list_box_row_set_selectable (GTK_LIST_BOX_ROW (self), FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_row_zoom_manager_notify_zoom (SpVisualizerRow *self,
|
||||
GParamSpec *pspec,
|
||||
SpZoomManager *zoom_manager)
|
||||
{
|
||||
g_assert (SP_IS_VISUALIZER_ROW (self));
|
||||
g_assert (SP_IS_ZOOM_MANAGER (zoom_manager));
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
/**
|
||||
* sp_visualizer_row_get_zoom_manager:
|
||||
*
|
||||
* Returns: (transfer none) (nullable): A #SpZoomManager or %NULL.
|
||||
*/
|
||||
SpZoomManager *
|
||||
sp_visualizer_row_get_zoom_manager (SpVisualizerRow *self)
|
||||
{
|
||||
SpVisualizerRowPrivate *priv = sp_visualizer_row_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (SP_IS_VISUALIZER_ROW (self), NULL);
|
||||
|
||||
return priv->zoom_manager;
|
||||
}
|
||||
|
||||
void
|
||||
sp_visualizer_row_set_zoom_manager (SpVisualizerRow *self,
|
||||
SpZoomManager *zoom_manager)
|
||||
{
|
||||
SpVisualizerRowPrivate *priv = sp_visualizer_row_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (SP_IS_VISUALIZER_ROW (self));
|
||||
g_return_if_fail (!zoom_manager || SP_IS_ZOOM_MANAGER (zoom_manager));
|
||||
|
||||
if (priv->zoom_manager != zoom_manager)
|
||||
{
|
||||
if (priv->zoom_manager != NULL)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (priv->zoom_manager,
|
||||
G_CALLBACK (sp_visualizer_row_zoom_manager_notify_zoom),
|
||||
self);
|
||||
g_clear_object (&priv->zoom_manager);
|
||||
}
|
||||
|
||||
if (zoom_manager != NULL)
|
||||
{
|
||||
priv->zoom_manager = g_object_ref (zoom_manager);
|
||||
g_signal_connect_object (priv->zoom_manager,
|
||||
"notify::zoom",
|
||||
G_CALLBACK (sp_visualizer_row_zoom_manager_notify_zoom),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
}
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM_MANAGER]);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sp_visualizer_row_set_reader (SpVisualizerRow *self,
|
||||
SpCaptureReader *reader)
|
||||
{
|
||||
SpVisualizerRowPrivate *priv = sp_visualizer_row_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (SP_IS_VISUALIZER_ROW (self));
|
||||
|
||||
if (priv->reader != reader)
|
||||
{
|
||||
g_clear_pointer (&priv->reader, sp_capture_reader_unref);
|
||||
|
||||
if (reader != NULL)
|
||||
priv->reader = sp_capture_reader_ref (reader);
|
||||
|
||||
if (SP_VISUALIZER_ROW_GET_CLASS (self)->set_reader)
|
||||
SP_VISUALIZER_ROW_GET_CLASS (self)->set_reader (self, reader);
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
subtract_border (GtkAllocation *alloc,
|
||||
GtkBorder *border)
|
||||
{
|
||||
#if 0
|
||||
g_print ("Border; %d %d %d %d\n", border->top, border->left, border->bottom, border->right);
|
||||
#endif
|
||||
|
||||
alloc->x += border->left;
|
||||
alloc->y += border->top;
|
||||
alloc->width -= border->left + border->right;
|
||||
alloc->height -= border->top + border->bottom;
|
||||
}
|
||||
|
||||
static void
|
||||
adjust_alloc_for_borders (SpVisualizerRow *self,
|
||||
GtkAllocation *alloc)
|
||||
{
|
||||
GtkStyleContext *style_context;
|
||||
GtkBorder border;
|
||||
GtkStateFlags state;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_ROW (self));
|
||||
g_assert (alloc != NULL);
|
||||
|
||||
state = gtk_widget_get_state_flags (GTK_WIDGET (self));
|
||||
style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
|
||||
gtk_style_context_get_border (style_context, state, &border);
|
||||
|
||||
subtract_border (alloc, &border);
|
||||
}
|
||||
|
||||
void
|
||||
sp_visualizer_row_translate_points (SpVisualizerRow *self,
|
||||
const SpVisualizerRowRelativePoint *in_points,
|
||||
guint n_in_points,
|
||||
SpVisualizerRowAbsolutePoint *out_points,
|
||||
guint n_out_points)
|
||||
{
|
||||
GtkAllocation alloc;
|
||||
gint graph_width;
|
||||
|
||||
g_return_if_fail (SP_IS_VISUALIZER_ROW (self));
|
||||
g_return_if_fail (in_points != NULL);
|
||||
g_return_if_fail (out_points != NULL);
|
||||
g_return_if_fail (n_in_points == n_out_points);
|
||||
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
|
||||
adjust_alloc_for_borders (self, &alloc);
|
||||
|
||||
graph_width = _sp_visualizer_row_get_graph_width (self);
|
||||
|
||||
for (guint i = 0; i < n_in_points; i++)
|
||||
{
|
||||
out_points[i].x = alloc.x + (in_points[i].x * graph_width);
|
||||
out_points[i].y = alloc.y + alloc.height - (in_points[i].y * alloc.height);
|
||||
}
|
||||
}
|
||||
|
||||
90
lib/visualizers/sp-visualizer-row.h
Normal file
90
lib/visualizers/sp-visualizer-row.h
Normal file
@ -0,0 +1,90 @@
|
||||
/* sp-visualizer-row.h
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <christian@hergert.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SP_VISUALIZER_ROW_H
|
||||
#define SP_VISUALIZER_ROW_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "capture/sp-capture-reader.h"
|
||||
#include "util/sp-zoom-manager.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SP_TYPE_VISUALIZER_ROW (sp_visualizer_row_get_type())
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE (SpVisualizerRow, sp_visualizer_row, SP, VISUALIZER_ROW, GtkListBoxRow)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gfloat x;
|
||||
gfloat y;
|
||||
} SpVisualizerRowRelativePoint;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gint x;
|
||||
gint y;
|
||||
} SpVisualizerRowAbsolutePoint;
|
||||
|
||||
struct _SpVisualizerRowClass
|
||||
{
|
||||
GtkListBoxRowClass parent_class;
|
||||
|
||||
/**
|
||||
* SpVisualizerRow::set_reader:
|
||||
*
|
||||
* Sets the reader that the row should use to extract counters.
|
||||
* This reader is private to the row and should be freed when
|
||||
* no longer in use with sp_capture_reader_unref().
|
||||
*/
|
||||
void (*set_reader) (SpVisualizerRow *self,
|
||||
SpCaptureReader *reader);
|
||||
|
||||
gpointer _reserved1;
|
||||
gpointer _reserved2;
|
||||
gpointer _reserved3;
|
||||
gpointer _reserved4;
|
||||
gpointer _reserved5;
|
||||
gpointer _reserved6;
|
||||
gpointer _reserved7;
|
||||
gpointer _reserved8;
|
||||
gpointer _reserved9;
|
||||
gpointer _reserved10;
|
||||
gpointer _reserved11;
|
||||
gpointer _reserved12;
|
||||
gpointer _reserved13;
|
||||
gpointer _reserved14;
|
||||
gpointer _reserved15;
|
||||
gpointer _reserved16;
|
||||
};
|
||||
|
||||
void sp_visualizer_row_set_reader (SpVisualizerRow *self,
|
||||
SpCaptureReader *reader);
|
||||
SpZoomManager *sp_visualizer_row_get_zoom_manager (SpVisualizerRow *self);
|
||||
void sp_visualizer_row_set_zoom_manager (SpVisualizerRow *self,
|
||||
SpZoomManager *zoom_manager);
|
||||
void sp_visualizer_row_translate_points (SpVisualizerRow *self,
|
||||
const SpVisualizerRowRelativePoint *in_points,
|
||||
guint n_in_points,
|
||||
SpVisualizerRowAbsolutePoint *out_points,
|
||||
guint n_out_points);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* SP_VISUALIZER_ROW_H */
|
||||
388
lib/visualizers/sp-visualizer-ticks.c
Normal file
388
lib/visualizers/sp-visualizer-ticks.c
Normal file
@ -0,0 +1,388 @@
|
||||
/* sp-visualizer-ticks.c
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "visualizers/sp-visualizer-ticks.h"
|
||||
|
||||
#define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
|
||||
#define NSEC_PER_HOUR (NSEC_PER_SEC * 60 * 60)
|
||||
#define NSEC_PER_MIN (NSEC_PER_SEC * 60)
|
||||
#define NSEC_PER_MSEC (NSEC_PER_SEC/G_GINT64_CONSTANT(1000))
|
||||
#define MIN_TICK_DISTANCE 20
|
||||
#define LABEL_HEIGHT_PX 8
|
||||
|
||||
struct _SpVisualizerTicks
|
||||
{
|
||||
GtkDrawingArea parent_instance;
|
||||
|
||||
gint64 epoch;
|
||||
gint64 begin_time;
|
||||
gint64 end_time;
|
||||
} __attribute__((aligned(8)));
|
||||
|
||||
enum {
|
||||
TICK_MINUTES,
|
||||
TICK_HALF_MINUTES,
|
||||
TICK_FIVE_SECONDS,
|
||||
TICK_SECONDS,
|
||||
TICK_HALF_SECONDS,
|
||||
TICK_QUARTER_SECONDS,
|
||||
TICK_TENTHS,
|
||||
TICK_HUNDREDTHS,
|
||||
TICK_THOUSANDTHS,
|
||||
N_TICKS
|
||||
};
|
||||
|
||||
struct {
|
||||
gint width;
|
||||
gint height;
|
||||
gint64 span;
|
||||
} tick_sizing[N_TICKS] = {
|
||||
{ 1, 12, NSEC_PER_SEC * 60 },
|
||||
{ 1, 11, NSEC_PER_SEC * 30 },
|
||||
{ 1, 10, NSEC_PER_SEC * 5 },
|
||||
{ 1, 9, NSEC_PER_SEC },
|
||||
{ 1, 8, NSEC_PER_SEC / 2 },
|
||||
{ 1, 6, NSEC_PER_SEC / 4 },
|
||||
{ 1, 5, NSEC_PER_SEC / 10 },
|
||||
{ 1, 4, NSEC_PER_SEC / 100 },
|
||||
{ 1, 3, NSEC_PER_SEC / 1000 },
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (SpVisualizerTicks, sp_visualizer_ticks, GTK_TYPE_DRAWING_AREA)
|
||||
|
||||
static void
|
||||
update_label_text (PangoLayout *layout,
|
||||
gint64 time,
|
||||
gboolean want_msec)
|
||||
{
|
||||
g_autofree gchar *str = NULL;
|
||||
gint64 tmp;
|
||||
gint msec = 0;
|
||||
gint hours = 0;
|
||||
gint min = 0;
|
||||
gint sec = 0;
|
||||
|
||||
g_assert (PANGO_IS_LAYOUT (layout));
|
||||
|
||||
tmp = time % NSEC_PER_SEC;
|
||||
time -= tmp;
|
||||
msec = tmp / 100000L;
|
||||
|
||||
if (time >= NSEC_PER_HOUR)
|
||||
{
|
||||
hours = time / NSEC_PER_HOUR;
|
||||
time %= NSEC_PER_HOUR;
|
||||
}
|
||||
|
||||
if (time >= NSEC_PER_MIN)
|
||||
{
|
||||
min = time / NSEC_PER_MIN;
|
||||
time %= NSEC_PER_MIN;
|
||||
}
|
||||
|
||||
if (time >= NSEC_PER_SEC)
|
||||
{
|
||||
sec = time / NSEC_PER_SEC;
|
||||
time %= NSEC_PER_SEC;
|
||||
}
|
||||
|
||||
if (want_msec || (!hours && !min && !sec && msec))
|
||||
{
|
||||
if (hours > 0)
|
||||
str = g_strdup_printf ("%02u:%02u:%02u.%04u", hours, min, sec, msec);
|
||||
else
|
||||
str = g_strdup_printf ("%02u:%02u.%04u", min, sec, msec);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hours > 0)
|
||||
str = g_strdup_printf ("%02u:%02u:%02u", hours, min, sec);
|
||||
else
|
||||
str = g_strdup_printf ("%02u:%02u", min, sec);
|
||||
}
|
||||
|
||||
pango_layout_set_text (layout, str, -1);
|
||||
}
|
||||
|
||||
static inline gdouble
|
||||
get_x_for_time (SpVisualizerTicks *self,
|
||||
const GtkAllocation *alloc,
|
||||
gint64 t)
|
||||
{
|
||||
gint64 timespan = self->end_time - self->begin_time;
|
||||
gdouble x_ratio = (gdouble)(t - self->begin_time) / (gdouble)timespan;
|
||||
return alloc->width * x_ratio;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static inline gint64
|
||||
get_time_at_x (SpVisualizerTicks *self,
|
||||
const GtkAllocation *alloc,
|
||||
gdouble x)
|
||||
{
|
||||
return self->begin_time
|
||||
- self->epoch
|
||||
+ ((self->end_time - self->begin_time) / (gdouble)alloc->width * x);
|
||||
}
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
draw_ticks (SpVisualizerTicks *self,
|
||||
cairo_t *cr,
|
||||
GtkAllocation *area,
|
||||
gint ticks,
|
||||
gboolean label_mode)
|
||||
{
|
||||
GtkAllocation alloc;
|
||||
gdouble half;
|
||||
gint64 x_offset;
|
||||
gint count = 0;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_TICKS (self));
|
||||
g_assert (cr != NULL);
|
||||
g_assert (area != NULL);
|
||||
g_assert (ticks >= 0);
|
||||
g_assert (ticks < N_TICKS);
|
||||
|
||||
/*
|
||||
* If we are in label_model, we don't draw the ticks but only the labels.
|
||||
* That way we can determine which tick level managed to draw a tick in
|
||||
* the visible region so we only show labels for the largest tick level.
|
||||
* (Returning true from this method indicates we successfully drew a tick).
|
||||
*/
|
||||
|
||||
half = tick_sizing[ticks].width / 2.0;
|
||||
|
||||
/* Take our epoch into account to calculate the offset of the
|
||||
* first tick, which might not align perfectly when the beginning
|
||||
* of the visible area.
|
||||
*/
|
||||
x_offset = (self->begin_time - self->epoch) % tick_sizing[ticks].span;
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
|
||||
|
||||
if G_UNLIKELY (label_mode)
|
||||
{
|
||||
PangoLayout *layout;
|
||||
PangoFontDescription *font_desc;
|
||||
gboolean want_msec;
|
||||
|
||||
layout = gtk_widget_create_pango_layout (GTK_WIDGET (self), "00:10:00");
|
||||
|
||||
font_desc = pango_font_description_new ();
|
||||
pango_font_description_set_family_static (font_desc, "Monospace");
|
||||
pango_font_description_set_absolute_size (font_desc, LABEL_HEIGHT_PX * PANGO_SCALE);
|
||||
pango_layout_set_font_description (layout, font_desc);
|
||||
pango_font_description_free (font_desc);
|
||||
|
||||
/* If we are operating on smaller than seconds here, then we want
|
||||
* to ensure we include msec with the timestamps.
|
||||
*/
|
||||
want_msec = tick_sizing[ticks].span < NSEC_PER_SEC;
|
||||
|
||||
for (gint64 t = self->begin_time - x_offset;
|
||||
t <= self->end_time;
|
||||
t += tick_sizing[ticks].span)
|
||||
{
|
||||
gdouble x = get_x_for_time (self, &alloc, t);
|
||||
|
||||
cairo_move_to (cr, (gint)x + .5 - (gint)half, alloc.height - LABEL_HEIGHT_PX);
|
||||
update_label_text (layout, t - self->epoch, want_msec);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
}
|
||||
|
||||
g_clear_object (&layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (gint64 t = self->begin_time - x_offset;
|
||||
t <= self->end_time;
|
||||
t += tick_sizing[ticks].span)
|
||||
{
|
||||
gdouble x = get_x_for_time (self, &alloc, t);
|
||||
|
||||
cairo_move_to (cr, (gint)x - .5 - (gint)half, 0);
|
||||
cairo_line_to (cr, (gint)x - .5 - (gint)half, tick_sizing[ticks].height);
|
||||
count++;
|
||||
}
|
||||
|
||||
cairo_set_line_width (cr, tick_sizing[ticks].width);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
return count > 2;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sp_visualizer_ticks_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
{
|
||||
SpVisualizerTicks *self = SP_VISUALIZER_TICKS (widget);
|
||||
GtkStyleContext *style;
|
||||
GtkAllocation alloc;
|
||||
GtkStateFlags state;
|
||||
gint64 timespan;
|
||||
GdkRGBA color;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_TICKS (self));
|
||||
g_assert (cr != NULL);
|
||||
|
||||
if (0 == (timespan = self->end_time - self->begin_time))
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
|
||||
|
||||
style = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
gtk_style_context_get_color (style, state, &color);
|
||||
|
||||
gdk_cairo_set_source_rgba (cr, &color);
|
||||
|
||||
/*
|
||||
* We need to discover up to what level we will draw tick marks.
|
||||
* This is based on the width of the widget and the number of ticks
|
||||
* to draw (which is determined from our timespan). We will skip a
|
||||
* mark if they will end up less than MIN_TICK_DISTANCE px apart.
|
||||
*/
|
||||
|
||||
for (guint i = G_N_ELEMENTS (tick_sizing); i > 0; i--)
|
||||
{
|
||||
gint64 n_ticks = timespan / tick_sizing[i - 1].span;
|
||||
gint largest_match = -1;
|
||||
|
||||
if (n_ticks == 0 || (alloc.width / n_ticks) < MIN_TICK_DISTANCE)
|
||||
continue;
|
||||
|
||||
for (guint j = i; j > 0; j--)
|
||||
{
|
||||
if (draw_ticks (self, cr, &alloc, j - 1, FALSE))
|
||||
largest_match = j - 1;
|
||||
}
|
||||
|
||||
if (largest_match != -1)
|
||||
draw_ticks (self, cr, &alloc, largest_match, TRUE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_ticks_get_preferred_height (GtkWidget *widget,
|
||||
gint *min_height,
|
||||
gint *nat_height)
|
||||
{
|
||||
g_assert (SP_IS_VISUALIZER_TICKS (widget));
|
||||
|
||||
*min_height = *nat_height = tick_sizing[0].height + LABEL_HEIGHT_PX;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_ticks_class_init (SpVisualizerTicksClass *klass)
|
||||
{
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
widget_class->draw = sp_visualizer_ticks_draw;
|
||||
widget_class->get_preferred_height = sp_visualizer_ticks_get_preferred_height;
|
||||
|
||||
gtk_widget_class_set_css_name (widget_class, "ticks");
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_ticks_init (SpVisualizerTicks *self)
|
||||
{
|
||||
self->end_time = G_GINT64_CONSTANT (1000000000) * 60;
|
||||
|
||||
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
sp_visualizer_ticks_new (void)
|
||||
{
|
||||
return g_object_new (SP_TYPE_VISUALIZER_TICKS, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
sp_visualizer_ticks_get_time_range (SpVisualizerTicks *self,
|
||||
gint64 *begin_time,
|
||||
gint64 *end_time)
|
||||
{
|
||||
g_return_if_fail (SP_IS_VISUALIZER_TICKS (self));
|
||||
g_return_if_fail (begin_time != NULL || end_time != NULL);
|
||||
|
||||
if (begin_time != NULL)
|
||||
*begin_time = self->begin_time;
|
||||
|
||||
if (end_time != NULL)
|
||||
*end_time = self->end_time;
|
||||
}
|
||||
|
||||
void
|
||||
sp_visualizer_ticks_set_time_range (SpVisualizerTicks *self,
|
||||
gint64 begin_time,
|
||||
gint64 end_time)
|
||||
{
|
||||
g_return_if_fail (SP_IS_VISUALIZER_TICKS (self));
|
||||
|
||||
if (begin_time > end_time)
|
||||
{
|
||||
gint64 tmp = begin_time;
|
||||
begin_time = end_time;
|
||||
end_time = tmp;
|
||||
}
|
||||
|
||||
self->begin_time = begin_time;
|
||||
self->end_time = end_time;
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
gint64
|
||||
sp_visualizer_ticks_get_epoch (SpVisualizerTicks *self)
|
||||
{
|
||||
g_return_val_if_fail (SP_IS_VISUALIZER_TICKS (self), 0);
|
||||
|
||||
return self->epoch;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the epoch for the visualizer ticks.
|
||||
*
|
||||
* The epoch is the "real" starting time of the capture, where as the
|
||||
* sp_visualizer_ticks_set_time_range() function sets the visible range
|
||||
* of the capture.
|
||||
*
|
||||
* This is used to calculate the offset of the beginning of the capture
|
||||
* from begin_time so that the ticks appear in the proper location.
|
||||
*
|
||||
* This function should only need to be called when the reader is changed.
|
||||
*/
|
||||
void
|
||||
sp_visualizer_ticks_set_epoch (SpVisualizerTicks *self,
|
||||
gint64 epoch)
|
||||
{
|
||||
g_return_if_fail (SP_IS_VISUALIZER_TICKS (self));
|
||||
|
||||
if (self->epoch != epoch)
|
||||
{
|
||||
self->epoch = epoch;
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
}
|
||||
43
lib/visualizers/sp-visualizer-ticks.h
Normal file
43
lib/visualizers/sp-visualizer-ticks.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* sp-visualizer-ticks.h
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SP_VISUALIZER_TICKS_H
|
||||
#define SP_VISUALIZER_TICKS_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SP_TYPE_VISUALIZER_TICKS (sp_visualizer_ticks_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (SpVisualizerTicks, sp_visualizer_ticks, SP, VISUALIZER_TICKS, GtkDrawingArea)
|
||||
|
||||
GtkWidget *sp_visualizer_ticks_new (void);
|
||||
void sp_visualizer_ticks_set_epoch (SpVisualizerTicks *self,
|
||||
gint64 epoch);
|
||||
gint64 sp_visualizer_ticks_get_epoch (SpVisualizerTicks *self);
|
||||
void sp_visualizer_ticks_get_time_range (SpVisualizerTicks *self,
|
||||
gint64 *begin_time,
|
||||
gint64 *end_time);
|
||||
void sp_visualizer_ticks_set_time_range (SpVisualizerTicks *self,
|
||||
gint64 begin_time,
|
||||
gint64 end_time);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* SP_VISUALIZER_TICKS_H */
|
||||
754
lib/visualizers/sp-visualizer-view.c
Normal file
754
lib/visualizers/sp-visualizer-view.c
Normal file
@ -0,0 +1,754 @@
|
||||
/* sp-visualizer-view.c
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define G_LOG_DOMAIN "sp-visualizer-view"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "util/sp-theme-manager.h"
|
||||
#include "visualizers/sp-visualizer-list.h"
|
||||
#include "visualizers/sp-visualizer-row.h"
|
||||
#include "visualizers/sp-visualizer-row-private.h"
|
||||
#include "util/sp-selection.h"
|
||||
#include "visualizers/sp-visualizer-ticks.h"
|
||||
#include "visualizers/sp-visualizer-view.h"
|
||||
|
||||
#define NSEC_PER_SEC G_GINT64_CONSTANT(1000000000)
|
||||
#define DEFAULT_PIXELS_PER_SECOND 20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SpCaptureReader *reader;
|
||||
SpZoomManager *zoom_manager;
|
||||
SpSelection *selection;
|
||||
|
||||
SpVisualizerList *list;
|
||||
GtkScrolledWindow *scroller;
|
||||
SpVisualizerTicks *ticks;
|
||||
|
||||
gint64 drag_begin_at;
|
||||
gint64 drag_selection_at;
|
||||
|
||||
guint button_pressed : 1;
|
||||
} SpVisualizerViewPrivate;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SpVisualizerView *self;
|
||||
GtkStyleContext *style_context;
|
||||
cairo_t *cr;
|
||||
GtkAllocation alloc;
|
||||
} SelectionDraw;
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_READER,
|
||||
PROP_ZOOM_MANAGER,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
enum {
|
||||
VISUALIZER_ADDED,
|
||||
VISUALIZER_REMOVED,
|
||||
N_SIGNALS
|
||||
};
|
||||
|
||||
static void buildable_iface_init (GtkBuildableIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (SpVisualizerView, sp_visualizer_view, GTK_TYPE_BIN, 0,
|
||||
G_ADD_PRIVATE (SpVisualizerView)
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init))
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
static guint signals [N_SIGNALS];
|
||||
static GtkBuildableIface *parent_buildable;
|
||||
|
||||
static void
|
||||
find_row1 (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
GtkWidget **row1 = data;
|
||||
|
||||
if (*row1 == NULL && SP_IS_VISUALIZER_ROW (widget))
|
||||
*row1 = widget;
|
||||
}
|
||||
|
||||
static gint64
|
||||
get_time_from_coordinates (SpVisualizerView *self,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
SpVisualizerRow *row1 = NULL;
|
||||
GtkAllocation alloc;
|
||||
gint64 begin_time;
|
||||
gint64 end_time;
|
||||
gint graph_width;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
|
||||
if (priv->reader == NULL)
|
||||
return 0;
|
||||
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
|
||||
|
||||
x -= alloc.x;
|
||||
y -= alloc.y;
|
||||
|
||||
/*
|
||||
* Find the first row so we can get an idea of how wide the graph is
|
||||
* (ignoring spacing caused by the widget being wider than the data points.
|
||||
*/
|
||||
gtk_container_foreach (GTK_CONTAINER (priv->list), find_row1, &row1);
|
||||
if (!SP_IS_VISUALIZER_ROW (row1))
|
||||
return 0;
|
||||
|
||||
begin_time = sp_capture_reader_get_start_time (priv->reader);
|
||||
end_time = sp_capture_reader_get_end_time (priv->reader);
|
||||
graph_width = _sp_visualizer_row_get_graph_width (row1);
|
||||
|
||||
return begin_time + ((end_time - begin_time) * (x / (gdouble)graph_width));
|
||||
}
|
||||
|
||||
static gint
|
||||
get_x_for_time_at (SpVisualizerView *self,
|
||||
const GtkAllocation *alloc,
|
||||
gint64 time_at)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
SpVisualizerRow *row1 = NULL;
|
||||
GtkAdjustment *hadjustment;
|
||||
gdouble nsec_per_pixel;
|
||||
gdouble value;
|
||||
gint64 begin_time;
|
||||
gint64 end_time;
|
||||
gint graph_width;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (alloc != NULL);
|
||||
|
||||
/*
|
||||
* Find the first row so we can get an idea of how wide the graph is
|
||||
* (ignoring spacing caused by the widget being wider than the data points.
|
||||
*/
|
||||
gtk_container_foreach (GTK_CONTAINER (priv->list), find_row1, &row1);
|
||||
if (!SP_IS_VISUALIZER_ROW (row1))
|
||||
return 0;
|
||||
|
||||
hadjustment = gtk_scrolled_window_get_hadjustment (priv->scroller);
|
||||
value = gtk_adjustment_get_value (hadjustment);
|
||||
|
||||
begin_time = sp_capture_reader_get_start_time (priv->reader);
|
||||
end_time = sp_capture_reader_get_end_time (priv->reader);
|
||||
|
||||
graph_width = _sp_visualizer_row_get_graph_width (row1);
|
||||
nsec_per_pixel = (end_time - begin_time) / (gdouble)graph_width;
|
||||
begin_time += value * nsec_per_pixel;
|
||||
|
||||
return ((time_at - begin_time) / nsec_per_pixel);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_row_added (SpVisualizerView *self,
|
||||
GtkWidget *widget,
|
||||
SpVisualizerList *list)
|
||||
{
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (GTK_IS_WIDGET (widget));
|
||||
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||
|
||||
if (SP_IS_VISUALIZER_ROW (widget))
|
||||
g_signal_emit (self, signals [VISUALIZER_ADDED], 0, widget);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_row_removed (SpVisualizerView *self,
|
||||
GtkWidget *widget,
|
||||
SpVisualizerList *list)
|
||||
{
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (GTK_IS_WIDGET (widget));
|
||||
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||
|
||||
if (SP_IS_VISUALIZER_ROW (widget))
|
||||
g_signal_emit (self, signals [VISUALIZER_REMOVED], 0, widget);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_update_ticks (SpVisualizerView *self)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
GtkAdjustment *hadjustment;
|
||||
GtkAllocation alloc;
|
||||
gdouble value;
|
||||
gint64 begin_time;
|
||||
gint64 end_time;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
|
||||
hadjustment = gtk_scrolled_window_get_hadjustment (priv->scroller);
|
||||
value = gtk_adjustment_get_value (hadjustment);
|
||||
|
||||
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
|
||||
|
||||
begin_time = get_time_from_coordinates (self, alloc.x + value, alloc.y);
|
||||
end_time = get_time_from_coordinates (self, alloc.x + value + alloc.width, alloc.y);
|
||||
|
||||
sp_visualizer_ticks_set_time_range (priv->ticks, begin_time, end_time);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_hadjustment_value_changed (SpVisualizerView *self,
|
||||
GtkAdjustment *adjustment)
|
||||
{
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (GTK_IS_ADJUSTMENT (adjustment));
|
||||
|
||||
sp_visualizer_view_update_ticks (self);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
SpVisualizerView *self = (SpVisualizerView *)widget;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (allocation != NULL);
|
||||
|
||||
GTK_WIDGET_CLASS (sp_visualizer_view_parent_class)->size_allocate (widget, allocation);
|
||||
|
||||
sp_visualizer_view_update_ticks (self);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_selection_cb (SpSelection *selection,
|
||||
gint64 range_begin,
|
||||
gint64 range_end,
|
||||
gpointer user_data)
|
||||
{
|
||||
SelectionDraw *draw = user_data;
|
||||
GdkRectangle area;
|
||||
|
||||
g_assert (SP_IS_SELECTION (selection));
|
||||
g_assert (draw != NULL);
|
||||
g_assert (draw->cr != NULL);
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (draw->self));
|
||||
|
||||
area.x = get_x_for_time_at (draw->self, &draw->alloc, range_begin);
|
||||
area.width = get_x_for_time_at (draw->self, &draw->alloc, range_end) - area.x;
|
||||
area.y = 0;
|
||||
area.height = draw->alloc.height;
|
||||
|
||||
if (area.width < 0)
|
||||
{
|
||||
area.width = ABS (area.width);
|
||||
area.x -= area.width;
|
||||
}
|
||||
|
||||
gtk_render_background (draw->style_context, draw->cr, area.x, area.y, area.width, area.height);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sp_visualizer_view_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
{
|
||||
SpVisualizerView *self = (SpVisualizerView *)widget;
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
SelectionDraw draw = { 0 };
|
||||
gboolean ret;
|
||||
|
||||
g_assert (GTK_IS_WIDGET (widget));
|
||||
g_assert (cr != NULL);
|
||||
|
||||
draw.style_context = gtk_widget_get_style_context (widget);
|
||||
draw.self = self;
|
||||
draw.cr = cr;
|
||||
|
||||
gtk_widget_get_allocation (widget, &draw.alloc);
|
||||
|
||||
ret = GTK_WIDGET_CLASS (sp_visualizer_view_parent_class)->draw (widget, cr);
|
||||
|
||||
if (sp_selection_get_has_selection (priv->selection) || priv->button_pressed)
|
||||
{
|
||||
gtk_style_context_add_class (draw.style_context, "selection");
|
||||
sp_selection_foreach (priv->selection, draw_selection_cb, &draw);
|
||||
if (priv->button_pressed)
|
||||
draw_selection_cb (priv->selection, priv->drag_begin_at, priv->drag_selection_at, &draw);
|
||||
gtk_style_context_remove_class (draw.style_context, "selection");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sp_visualizer_view_list_button_press_event (SpVisualizerView *self,
|
||||
GdkEventButton *ev,
|
||||
SpVisualizerList *list)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (ev != NULL);
|
||||
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||
|
||||
if (priv->reader == NULL)
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
|
||||
if (ev->button != GDK_BUTTON_PRIMARY)
|
||||
{
|
||||
if (sp_selection_get_has_selection (priv->selection))
|
||||
{
|
||||
sp_selection_unselect_all (priv->selection);
|
||||
return GDK_EVENT_STOP;
|
||||
}
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
if ((ev->state & GDK_SHIFT_MASK) == 0)
|
||||
sp_selection_unselect_all (priv->selection);
|
||||
|
||||
priv->button_pressed = TRUE;
|
||||
|
||||
priv->drag_begin_at = get_time_from_coordinates (self, ev->x, ev->y);
|
||||
priv->drag_selection_at = priv->drag_begin_at;
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sp_visualizer_view_list_button_release_event (SpVisualizerView *self,
|
||||
GdkEventButton *ev,
|
||||
SpVisualizerList *list)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (ev != NULL);
|
||||
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||
|
||||
if (!priv->button_pressed || ev->button != GDK_BUTTON_PRIMARY)
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
|
||||
priv->button_pressed = FALSE;
|
||||
|
||||
if (priv->drag_begin_at != priv->drag_selection_at)
|
||||
{
|
||||
sp_selection_select_range (priv->selection,
|
||||
priv->drag_begin_at,
|
||||
priv->drag_selection_at);
|
||||
priv->drag_begin_at = -1;
|
||||
priv->drag_selection_at = -1;
|
||||
}
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
|
||||
return GDK_EVENT_STOP;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
sp_visualizer_view_list_motion_notify_event (SpVisualizerView *self,
|
||||
GdkEventMotion *ev,
|
||||
SpVisualizerList *list)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (ev != NULL);
|
||||
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||
|
||||
if (!priv->button_pressed)
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
|
||||
priv->drag_selection_at = get_time_from_coordinates (self, ev->x, ev->y);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_list_realize_after (SpVisualizerView *self,
|
||||
SpVisualizerList *list)
|
||||
{
|
||||
GdkDisplay *display;
|
||||
GdkWindow *window;
|
||||
GdkCursor *cursor;
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (SP_IS_VISUALIZER_LIST (list));
|
||||
|
||||
window = gtk_widget_get_window (GTK_WIDGET (list));
|
||||
display = gdk_window_get_display (window);
|
||||
cursor = gdk_cursor_new_from_name (display, "text");
|
||||
gdk_window_set_cursor (window, cursor);
|
||||
g_clear_object (&cursor);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_selection_changed (SpVisualizerView *self,
|
||||
SpSelection *selection)
|
||||
{
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (SP_IS_SELECTION (selection));
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_finalize (GObject *object)
|
||||
{
|
||||
SpVisualizerView *self = (SpVisualizerView *)object;
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_clear_pointer (&priv->reader, sp_capture_reader_unref);
|
||||
g_clear_object (&priv->zoom_manager);
|
||||
g_clear_object (&priv->selection);
|
||||
|
||||
G_OBJECT_CLASS (sp_visualizer_view_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SpVisualizerView *self = SP_VISUALIZER_VIEW (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_READER:
|
||||
g_value_set_boxed (value, sp_visualizer_view_get_reader (self));
|
||||
break;
|
||||
|
||||
case PROP_ZOOM_MANAGER:
|
||||
g_value_set_object (value, sp_visualizer_view_get_zoom_manager (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
SpVisualizerView *self = SP_VISUALIZER_VIEW (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_READER:
|
||||
sp_visualizer_view_set_reader (self, g_value_get_boxed (value));
|
||||
break;
|
||||
|
||||
case PROP_ZOOM_MANAGER:
|
||||
sp_visualizer_view_set_zoom_manager (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_class_init (SpVisualizerViewClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
SpThemeManager *theme_manager = sp_theme_manager_get_default ();
|
||||
|
||||
object_class->finalize = sp_visualizer_view_finalize;
|
||||
object_class->get_property = sp_visualizer_view_get_property;
|
||||
object_class->set_property = sp_visualizer_view_set_property;
|
||||
|
||||
widget_class->draw = sp_visualizer_view_draw;
|
||||
widget_class->size_allocate = sp_visualizer_view_size_allocate;
|
||||
|
||||
properties [PROP_READER] =
|
||||
g_param_spec_boxed ("reader",
|
||||
"Reader",
|
||||
"The reader for the visualizers",
|
||||
SP_TYPE_CAPTURE_READER,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
properties [PROP_ZOOM_MANAGER] =
|
||||
g_param_spec_object ("zoom-manager",
|
||||
"Zoom Manager",
|
||||
"The zoom manager for the view",
|
||||
SP_TYPE_ZOOM_MANAGER,
|
||||
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
|
||||
signals [VISUALIZER_ADDED] =
|
||||
g_signal_new ("visualizer-added",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (SpVisualizerViewClass, visualizer_added),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1, SP_TYPE_VISUALIZER_ROW);
|
||||
|
||||
signals [VISUALIZER_REMOVED] =
|
||||
g_signal_new ("visualizer-removed",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (SpVisualizerViewClass, visualizer_removed),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1, SP_TYPE_VISUALIZER_ROW);
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sp-visualizer-view.ui");
|
||||
gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, list);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, scroller);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, ticks);
|
||||
|
||||
gtk_widget_class_set_css_name (widget_class, "visualizers");
|
||||
|
||||
sp_theme_manager_register_resource (theme_manager, NULL, NULL, "/org/gnome/sysprof/css/SpVisualizerView-shared.css");
|
||||
sp_theme_manager_register_resource (theme_manager, "Adwaita", NULL, "/org/gnome/sysprof/css/SpVisualizerView-Adwaita.css");
|
||||
sp_theme_manager_register_resource (theme_manager, "Adwaita", "dark", "/org/gnome/sysprof/css/SpVisualizerView-Adwaita-dark.css");
|
||||
|
||||
g_type_ensure (SP_TYPE_VISUALIZER_LIST);
|
||||
g_type_ensure (SP_TYPE_VISUALIZER_TICKS);
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_init (SpVisualizerView *self)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
GtkAdjustment *hadjustment;
|
||||
|
||||
priv->drag_begin_at = -1;
|
||||
priv->drag_selection_at = -1;
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
|
||||
priv->selection = g_object_new (SP_TYPE_SELECTION, NULL);
|
||||
|
||||
g_signal_connect_object (priv->selection,
|
||||
"changed",
|
||||
G_CALLBACK (sp_visualizer_view_selection_changed),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
g_signal_connect_object (priv->list,
|
||||
"button-press-event",
|
||||
G_CALLBACK (sp_visualizer_view_list_button_press_event),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
g_signal_connect_object (priv->list,
|
||||
"button-release-event",
|
||||
G_CALLBACK (sp_visualizer_view_list_button_release_event),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
g_signal_connect_object (priv->list,
|
||||
"motion-notify-event",
|
||||
G_CALLBACK (sp_visualizer_view_list_motion_notify_event),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
g_signal_connect_object (priv->list,
|
||||
"realize",
|
||||
G_CALLBACK (sp_visualizer_view_list_realize_after),
|
||||
self,
|
||||
G_CONNECT_SWAPPED | G_CONNECT_AFTER);
|
||||
|
||||
g_signal_connect_object (priv->list,
|
||||
"add",
|
||||
G_CALLBACK (sp_visualizer_view_row_added),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
g_signal_connect_object (priv->list,
|
||||
"remove",
|
||||
G_CALLBACK (sp_visualizer_view_row_removed),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
hadjustment = gtk_scrolled_window_get_hadjustment (priv->scroller);
|
||||
|
||||
g_signal_connect_object (hadjustment,
|
||||
"value-changed",
|
||||
G_CALLBACK (sp_visualizer_view_hadjustment_value_changed),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
}
|
||||
|
||||
/**
|
||||
* sp_visualizer_view_get_reader:
|
||||
*
|
||||
* Returns: (transfer none): An #SpCaptureReader
|
||||
*/
|
||||
SpCaptureReader *
|
||||
sp_visualizer_view_get_reader (SpVisualizerView *self)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (SP_IS_VISUALIZER_VIEW (self), NULL);
|
||||
|
||||
return priv->reader;
|
||||
}
|
||||
|
||||
void
|
||||
sp_visualizer_view_set_reader (SpVisualizerView *self,
|
||||
SpCaptureReader *reader)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (SP_IS_VISUALIZER_VIEW (self));
|
||||
|
||||
if (priv->reader != reader)
|
||||
{
|
||||
g_clear_pointer (&priv->reader, sp_capture_reader_unref);
|
||||
|
||||
if (reader != NULL)
|
||||
{
|
||||
gint64 begin_time;
|
||||
|
||||
priv->reader = sp_capture_reader_ref (reader);
|
||||
|
||||
begin_time = sp_capture_reader_get_start_time (priv->reader);
|
||||
|
||||
sp_visualizer_ticks_set_epoch (priv->ticks, begin_time);
|
||||
sp_visualizer_ticks_set_time_range (priv->ticks, begin_time, begin_time);
|
||||
|
||||
sp_selection_unselect_all (priv->selection);
|
||||
}
|
||||
|
||||
sp_visualizer_list_set_reader (priv->list, reader);
|
||||
sp_visualizer_view_update_ticks (self);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_READER]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_add_child (GtkBuildable *buildable,
|
||||
GtkBuilder *builder,
|
||||
GObject *child,
|
||||
const gchar *type)
|
||||
{
|
||||
SpVisualizerView *self = (SpVisualizerView *)buildable;
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (GTK_IS_BUILDER (builder));
|
||||
g_assert (G_IS_OBJECT (child));
|
||||
|
||||
if (g_strcmp0 (type, "visualizer") == 0 && GTK_IS_WIDGET (child))
|
||||
{
|
||||
gtk_container_add (GTK_CONTAINER (priv->list), GTK_WIDGET (child));
|
||||
return;
|
||||
}
|
||||
|
||||
parent_buildable->add_child (buildable, builder, child, type);
|
||||
}
|
||||
|
||||
static void
|
||||
buildable_iface_init (GtkBuildableIface *iface)
|
||||
{
|
||||
parent_buildable = g_type_interface_peek_parent (iface);
|
||||
iface->add_child = sp_visualizer_view_add_child;
|
||||
}
|
||||
|
||||
static void
|
||||
sp_visualizer_view_zoom_manager_notify_zoom (SpVisualizerView *self,
|
||||
GParamSpec *pspec,
|
||||
SpZoomManager *zoom_manager)
|
||||
{
|
||||
g_assert (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_assert (SP_IS_ZOOM_MANAGER (zoom_manager));
|
||||
|
||||
sp_visualizer_view_update_ticks (self);
|
||||
}
|
||||
|
||||
/**
|
||||
* sp_visualizer_view_get_zoom_manager:
|
||||
*
|
||||
* Returns: (transfer none) (nullable): An #SpZoomManager or %NULL
|
||||
*/
|
||||
SpZoomManager *
|
||||
sp_visualizer_view_get_zoom_manager (SpVisualizerView *self)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (SP_IS_VISUALIZER_VIEW (self), NULL);
|
||||
|
||||
return priv->zoom_manager;
|
||||
}
|
||||
|
||||
void
|
||||
sp_visualizer_view_set_zoom_manager (SpVisualizerView *self,
|
||||
SpZoomManager *zoom_manager)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (SP_IS_VISUALIZER_VIEW (self));
|
||||
g_return_if_fail (!zoom_manager || SP_IS_ZOOM_MANAGER (zoom_manager));
|
||||
|
||||
if (priv->zoom_manager != zoom_manager)
|
||||
{
|
||||
if (priv->zoom_manager != NULL)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (priv->zoom_manager,
|
||||
G_CALLBACK (sp_visualizer_view_zoom_manager_notify_zoom),
|
||||
self);
|
||||
g_clear_object (&priv->zoom_manager);
|
||||
}
|
||||
|
||||
if (zoom_manager != NULL)
|
||||
{
|
||||
priv->zoom_manager = g_object_ref (zoom_manager);
|
||||
g_signal_connect_object (priv->zoom_manager,
|
||||
"notify::zoom",
|
||||
G_CALLBACK (sp_visualizer_view_zoom_manager_notify_zoom),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
}
|
||||
|
||||
sp_visualizer_list_set_zoom_manager (priv->list, zoom_manager);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM_MANAGER]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sp_visualizer_view_get_selection:
|
||||
*
|
||||
* Gets the #SpSelection instance for the visualizer view.
|
||||
* This can be used to alter the selection or selections of the visualizers.
|
||||
*
|
||||
* Returns: (transfer none): An #SpSelection.
|
||||
*/
|
||||
SpSelection *
|
||||
sp_visualizer_view_get_selection (SpVisualizerView *self)
|
||||
{
|
||||
SpVisualizerViewPrivate *priv = sp_visualizer_view_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (SP_IS_VISUALIZER_VIEW (self), NULL);
|
||||
|
||||
return priv->selection;
|
||||
}
|
||||
72
lib/visualizers/sp-visualizer-view.h
Normal file
72
lib/visualizers/sp-visualizer-view.h
Normal file
@ -0,0 +1,72 @@
|
||||
/* sp-visualizer-view.h
|
||||
*
|
||||
* Copyright (C) 2016 Christian Hergert <chergert@redhat.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SP_VISUALIZER_VIEW_H
|
||||
#define SP_VISUALIZER_VIEW_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "visualizers/sp-visualizer-row.h"
|
||||
#include "util/sp-selection.h"
|
||||
#include "util/sp-zoom-manager.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define SP_TYPE_VISUALIZER_VIEW (sp_visualizer_view_get_type())
|
||||
|
||||
G_DECLARE_DERIVABLE_TYPE (SpVisualizerView, sp_visualizer_view, SP, VISUALIZER_VIEW, GtkBin)
|
||||
|
||||
struct _SpVisualizerViewClass
|
||||
{
|
||||
GtkBinClass parent_class;
|
||||
|
||||
void (*visualizer_added) (SpVisualizerView *self,
|
||||
SpVisualizerRow *visualizer);
|
||||
void (*visualizer_removed) (SpVisualizerView *self,
|
||||
SpVisualizerRow *visualizer);
|
||||
|
||||
gpointer _reserved1;
|
||||
gpointer _reserved2;
|
||||
gpointer _reserved3;
|
||||
gpointer _reserved4;
|
||||
gpointer _reserved5;
|
||||
gpointer _reserved6;
|
||||
gpointer _reserved7;
|
||||
gpointer _reserved8;
|
||||
gpointer _reserved9;
|
||||
gpointer _reserved10;
|
||||
gpointer _reserved11;
|
||||
gpointer _reserved12;
|
||||
gpointer _reserved13;
|
||||
gpointer _reserved14;
|
||||
gpointer _reserved15;
|
||||
gpointer _reserved16;
|
||||
};
|
||||
|
||||
GtkWidget *sp_visualizer_view_new (void);
|
||||
SpCaptureReader *sp_visualizer_view_get_reader (SpVisualizerView *self);
|
||||
void sp_visualizer_view_set_reader (SpVisualizerView *self,
|
||||
SpCaptureReader *reader);
|
||||
SpZoomManager *sp_visualizer_view_get_zoom_manager (SpVisualizerView *self);
|
||||
void sp_visualizer_view_set_zoom_manager (SpVisualizerView *self,
|
||||
SpZoomManager *zoom_manager);
|
||||
SpSelection *sp_visualizer_view_get_selection (SpVisualizerView *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* SP_VISUALIZER_VIEW_H */
|
||||
Reference in New Issue
Block a user