libsysprof-gtk: use doubles for normalized values

These need more precision so that we can convert them to our final position
by widget width/height which may have implications with zoom.
This commit is contained in:
Christian Hergert
2023-07-05 15:47:52 -07:00
parent 98998eb868
commit d91e57b10d
9 changed files with 61 additions and 70 deletions

View File

@ -53,8 +53,8 @@ sysprof_column_layer_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot) GtkSnapshot *snapshot)
{ {
SysprofColumnLayer *self = (SysprofColumnLayer *)widget; SysprofColumnLayer *self = (SysprofColumnLayer *)widget;
const float *x_values; const double *x_values;
const float *y_values; const double *y_values;
const GdkRGBA *color; const GdkRGBA *color;
guint n_values; guint n_values;
int width; int width;
@ -102,7 +102,7 @@ sysprof_column_layer_snapshot (GtkWidget *widget,
&GRAPHENE_RECT_INIT (x_values[i] * width, &GRAPHENE_RECT_INIT (x_values[i] * width,
0, 0,
1, 1,
ceilf (y_values[i] * height))); ceil (y_values[i] * height)));
} }
gtk_snapshot_restore (snapshot); gtk_snapshot_restore (snapshot);
@ -115,8 +115,8 @@ sysprof_column_layer_get_index_at_coord (SysprofColumnLayer *self,
graphene_rect_t *area) graphene_rect_t *area)
{ {
graphene_point_t point; graphene_point_t point;
const float *x_values; const double *x_values;
const float *y_values; const double *y_values;
gboolean flip_y; gboolean flip_y;
guint best = GTK_INVALID_LIST_POSITION; guint best = GTK_INVALID_LIST_POSITION;
guint n_values; guint n_values;

View File

@ -72,14 +72,14 @@ sysprof_line_layer_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot) GtkSnapshot *snapshot)
{ {
SysprofLineLayer *self = (SysprofLineLayer *)widget; SysprofLineLayer *self = (SysprofLineLayer *)widget;
const float *x_values; const double *x_values;
const float *y_values; const double *y_values;
const GdkRGBA *color; const GdkRGBA *color;
cairo_t *cr; cairo_t *cr;
float first_x; double first_x;
float first_y; double first_y;
float last_x; double last_x;
float last_y; double last_y;
guint n_values; guint n_values;
int width; int width;
int height; int height;
@ -120,8 +120,8 @@ sysprof_line_layer_snapshot (GtkWidget *widget,
{ {
for (guint i = 1; i < n_values; i++) for (guint i = 1; i < n_values; i++)
{ {
float x = floor (x_values[i] * width); double x = floor (x_values[i] * width);
float y = floor (y_values[i] * height) + .5; double y = floor (y_values[i] * height) + .5;
/* Skip if we are getting data incorrectly on the X axis. /* Skip if we are getting data incorrectly on the X axis.
* It should have been sorted by this point. * It should have been sorted by this point.
@ -145,8 +145,8 @@ sysprof_line_layer_snapshot (GtkWidget *widget,
{ {
for (guint i = 1; i < n_values; i++) for (guint i = 1; i < n_values; i++)
{ {
float x = floor (x_values[i] * width); double x = floor (x_values[i] * width);
float y = floor (y_values[i] * height) + .5; double y = floor (y_values[i] * height) + .5;
/* Skip if we are getting data incorrectly on the X axis. /* Skip if we are getting data incorrectly on the X axis.
* It should have been sorted by this point. * It should have been sorted by this point.
@ -190,12 +190,12 @@ sysprof_line_layer_snapshot_motion (SysprofChartLayer *layer,
{ {
SysprofLineLayer *self = (SysprofLineLayer *)layer; SysprofLineLayer *self = (SysprofLineLayer *)layer;
const GdkRGBA *color; const GdkRGBA *color;
const float *x_values; const double *x_values;
const float *y_values; const double *y_values;
float best_distance = G_MAXFLOAT; double best_distance = G_MAXFLOAT;
guint best_index = GTK_INVALID_LIST_POSITION; guint best_index = GTK_INVALID_LIST_POSITION;
float best_x = 0; double best_x = 0;
float best_y = 0; double best_y = 0;
guint n_values; guint n_values;
int width; int width;
int height; int height;
@ -221,9 +221,9 @@ sysprof_line_layer_snapshot_motion (SysprofChartLayer *layer,
for (guint i = 0; i < n_values; i++) for (guint i = 0; i < n_values; i++)
{ {
float x2 = floor (x_values[i] * width); double x2 = floor (x_values[i] * width);
float y2 = height - floor (y_values[i] * height); double y2 = height - floor (y_values[i] * height);
float distance; double distance;
if (x2 + NEAR_DISTANCE < x) if (x2 + NEAR_DISTANCE < x)
continue; continue;

View File

@ -26,7 +26,7 @@ struct _SysprofNormalizedSeriesItem
{ {
GObject parent_instance; GObject parent_instance;
GObject *item; GObject *item;
float value; double value;
}; };
enum { enum {
@ -65,7 +65,7 @@ sysprof_normalized_series_item_get_property (GObject *object,
break; break;
case PROP_VALUE: case PROP_VALUE:
g_value_set_float (value, self->value); g_value_set_double (value, self->value);
break; break;
default: default:
@ -88,7 +88,7 @@ sysprof_normalized_series_item_set_property (GObject *object,
break; break;
case PROP_VALUE: case PROP_VALUE:
self->value = g_value_get_float (value); self->value = g_value_get_double (value);
break; break;
default: default:
@ -111,9 +111,9 @@ sysprof_normalized_series_item_class_init (SysprofNormalizedSeriesItemClass *kla
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
properties [PROP_VALUE] = properties [PROP_VALUE] =
g_param_spec_float ("value", NULL, NULL, g_param_spec_double ("value", NULL, NULL,
0, 1, 0, 0, 1, 0,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties); g_object_class_install_properties (object_class, N_PROPS, properties);
} }
@ -123,7 +123,7 @@ sysprof_normalized_series_item_init (SysprofNormalizedSeriesItem *self)
{ {
} }
float double
sysprof_normalized_series_item_get_value (SysprofNormalizedSeriesItem *self) sysprof_normalized_series_item_get_value (SysprofNormalizedSeriesItem *self)
{ {
g_return_val_if_fail (SYSPROF_IS_NORMALIZED_SERIES_ITEM (self), 0); g_return_val_if_fail (SYSPROF_IS_NORMALIZED_SERIES_ITEM (self), 0);

View File

@ -34,6 +34,6 @@ G_DECLARE_FINAL_TYPE (SysprofNormalizedSeriesItem, sysprof_normalized_series_ite
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
gpointer sysprof_normalized_series_item_get_item (SysprofNormalizedSeriesItem *self); gpointer sysprof_normalized_series_item_get_item (SysprofNormalizedSeriesItem *self);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
float sysprof_normalized_series_item_get_value (SysprofNormalizedSeriesItem *self); double sysprof_normalized_series_item_get_value (SysprofNormalizedSeriesItem *self);
G_END_DECLS G_END_DECLS

View File

@ -96,7 +96,7 @@ sysprof_normalized_series_update_missing (gpointer user_data)
g_autoptr(GObject) item = g_list_model_get_item (model, position); g_autoptr(GObject) item = g_list_model_get_item (model, position);
g_auto(GValue) value = G_VALUE_INIT; g_auto(GValue) value = G_VALUE_INIT;
guint next = GTK_INVALID_LIST_POSITION; guint next = GTK_INVALID_LIST_POSITION;
float *fval = &g_array_index (self->values, float, position); double *fval = &g_array_index (self->values, double, position);
gtk_expression_evaluate (expression, item, &value); gtk_expression_evaluate (expression, item, &value);
@ -186,12 +186,12 @@ sysprof_normalized_series_items_changed (SysprofSeries *series,
} }
else else
{ {
static const float empty[32] = {0}; static const double empty[32] = {0};
const float *vals = empty; const double *vals = empty;
float *alloc = NULL; double *alloc = NULL;
if (added > G_N_ELEMENTS (empty)) if (added > G_N_ELEMENTS (empty))
vals = alloc = g_new0 (float, added); vals = alloc = g_new0 (double, added);
g_array_insert_vals (self->values, position, vals, added); g_array_insert_vals (self->values, position, vals, added);
@ -234,7 +234,7 @@ sysprof_normalized_series_get_series_item (SysprofSeries *series,
ret = g_object_new (SYSPROF_TYPE_NORMALIZED_SERIES_ITEM, ret = g_object_new (SYSPROF_TYPE_NORMALIZED_SERIES_ITEM,
"item", item, "item", item,
"value", g_array_index (self->values, float, position), "value", g_array_index (self->values, double, position),
NULL); NULL);
g_object_unref (item); g_object_unref (item);
@ -365,7 +365,7 @@ sysprof_normalized_series_class_init (SysprofNormalizedSeriesClass *klass)
static void static void
sysprof_normalized_series_init (SysprofNormalizedSeries *self) sysprof_normalized_series_init (SysprofNormalizedSeries *self)
{ {
self->values = g_array_new (FALSE, TRUE, sizeof (float)); self->values = g_array_new (FALSE, TRUE, sizeof (double));
self->missing = egg_bitset_new_empty (); self->missing = egg_bitset_new_empty ();
} }
@ -404,7 +404,7 @@ sysprof_normalized_series_new (SysprofSeries *series,
return SYSPROF_SERIES (normalized); return SYSPROF_SERIES (normalized);
} }
float double
sysprof_normalized_series_get_value_at (SysprofNormalizedSeries *self, sysprof_normalized_series_get_value_at (SysprofNormalizedSeries *self,
guint position) guint position)
{ {
@ -416,7 +416,7 @@ sysprof_normalized_series_get_value_at (SysprofNormalizedSeries *self,
if (position >= self->values->len) if (position >= self->values->len)
return .0; return .0;
return g_array_index (self->values, float, position); return g_array_index (self->values, double, position);
} }
/** /**
@ -534,7 +534,7 @@ sysprof_normalized_series_set_series (SysprofNormalizedSeries *self,
} }
} }
const float * const double *
sysprof_normalized_series_get_values (SysprofNormalizedSeries *self, sysprof_normalized_series_get_values (SysprofNormalizedSeries *self,
guint *n_values) guint *n_values)
{ {
@ -545,7 +545,7 @@ sysprof_normalized_series_get_values (SysprofNormalizedSeries *self,
*n_values = self->values->len; *n_values = self->values->len;
return &g_array_index (self->values, float, 0); return &g_array_index (self->values, double, 0);
} }
void void

View File

@ -62,10 +62,10 @@ SYSPROF_AVAILABLE_IN_ALL
void sysprof_normalized_series_set_series (SysprofNormalizedSeries *self, void sysprof_normalized_series_set_series (SysprofNormalizedSeries *self,
SysprofSeries *series); SysprofSeries *series);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
float sysprof_normalized_series_value_at (SysprofNormalizedSeries *self, double sysprof_normalized_series_value_at (SysprofNormalizedSeries *self,
guint position); guint position);
SYSPROF_AVAILABLE_IN_ALL SYSPROF_AVAILABLE_IN_ALL
const float *sysprof_normalized_series_get_values (SysprofNormalizedSeries *self, const double *sysprof_normalized_series_get_values (SysprofNormalizedSeries *self,
guint *n_values); guint *n_values);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofNormalizedSeries, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofNormalizedSeries, g_object_unref)

View File

@ -93,13 +93,12 @@ sysprof_time_span_layer_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot) GtkSnapshot *snapshot)
{ {
SysprofTimeSpanLayer *self = (SysprofTimeSpanLayer *)widget; SysprofTimeSpanLayer *self = (SysprofTimeSpanLayer *)widget;
const float *x_values; const double *x_values;
const float *x2_values; const double *x2_values;
const GdkRGBA *color; const GdkRGBA *color;
const GdkRGBA *event_color; const GdkRGBA *event_color;
GdkRGBA mixed; GdkRGBA mixed;
graphene_rect_t box_rect; graphene_rect_t box_rect;
float last_end_x = 0;
guint n_x_values = 0; guint n_x_values = 0;
guint n_x2_values = 0; guint n_x2_values = 0;
guint n_values; guint n_values;
@ -156,8 +155,8 @@ sysprof_time_span_layer_snapshot (GtkWidget *widget,
*/ */
for (guint i = 0; i < n_values; i++) for (guint i = 0; i < n_values; i++)
{ {
float begin = x_values[i]; double begin = x_values[i];
float end = x2_values[i]; double end = x2_values[i];
if (end < .0) if (end < .0)
continue; continue;
@ -168,24 +167,16 @@ sysprof_time_span_layer_snapshot (GtkWidget *widget,
if (begin != end) if (begin != end)
{ {
graphene_rect_t rect; graphene_rect_t rect;
float end_x;
rect = GRAPHENE_RECT_INIT (floorf (begin * width), rect = GRAPHENE_RECT_INIT (floor (begin * width),
0, 0,
ceilf ((end - begin) * width), ceil ((end - begin) * width),
height); height);
/* Ignore empty draws */ /* Ignore empty draws */
if (rect.size.width == 0) if (rect.size.width == 0)
continue; continue;
/* Cull draw unless it will extend past last rect */
end_x = rect.origin.x + rect.size.width;
if (end_x <= last_end_x)
continue;
else
last_end_x = end_x;
gtk_snapshot_append_color (snapshot, color, &rect); gtk_snapshot_append_color (snapshot, color, &rect);
if (rect.size.width > 20) if (rect.size.width > 20)
@ -211,7 +202,7 @@ sysprof_time_span_layer_snapshot (GtkWidget *widget,
if (event_color->alpha > 0) if (event_color->alpha > 0)
{ {
float last_x = -1; double last_x = -1;
box_rect = GRAPHENE_RECT_INIT (-ceil (height / 6.), box_rect = GRAPHENE_RECT_INIT (-ceil (height / 6.),
-ceil (height / 6.), -ceil (height / 6.),
@ -220,8 +211,8 @@ sysprof_time_span_layer_snapshot (GtkWidget *widget,
for (guint i = 0; i < n_values; i++) for (guint i = 0; i < n_values; i++)
{ {
float begin = x_values[i]; double begin = x_values[i];
float end = x2_values[i]; double end = x2_values[i];
if (begin != end) if (begin != end)
continue; continue;
@ -247,8 +238,8 @@ sysprof_time_span_layer_lookup_item (SysprofChartLayer *layer,
double y) double y)
{ {
SysprofTimeSpanLayer *self = (SysprofTimeSpanLayer *)layer; SysprofTimeSpanLayer *self = (SysprofTimeSpanLayer *)layer;
const float *x_values; const double *x_values;
const float *x2_values; const double *x2_values;
GListModel *model; GListModel *model;
guint n_x_values = 0; guint n_x_values = 0;
guint n_x2_values = 0; guint n_x2_values = 0;
@ -288,8 +279,8 @@ sysprof_time_span_layer_lookup_item (SysprofChartLayer *layer,
/* Then match regular duration events */ /* Then match regular duration events */
for (guint i = 0; i < n_values; i++) for (guint i = 0; i < n_values; i++)
{ {
float begin = x_values[i] * width; double begin = x_values[i] * width;
float end = x2_values[i] * width; double end = x2_values[i] * width;
if (x_values[i] == x2_values[i]) if (x_values[i] == x2_values[i])
continue; continue;

View File

@ -47,8 +47,8 @@ struct _SysprofXYLayerClass
}; };
void _sysprof_xy_layer_get_xy (SysprofXYLayer *self, void _sysprof_xy_layer_get_xy (SysprofXYLayer *self,
const float **x_values, const double **x_values,
const float **y_values, const double **y_values,
guint *n_values); guint *n_values);
G_END_DECLS G_END_DECLS

View File

@ -195,8 +195,8 @@ sysprof_xy_layer_init (SysprofXYLayer *self)
void void
_sysprof_xy_layer_get_xy (SysprofXYLayer *self, _sysprof_xy_layer_get_xy (SysprofXYLayer *self,
const float **x_values, const double **x_values,
const float **y_values, const double **y_values,
guint *n_values) guint *n_values)
{ {
guint n_x_values = 0; guint n_x_values = 0;