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

View File

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

View File

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

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_auto(GValue) value = G_VALUE_INIT;
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);
@ -186,12 +186,12 @@ sysprof_normalized_series_items_changed (SysprofSeries *series,
}
else
{
static const float empty[32] = {0};
const float *vals = empty;
float *alloc = NULL;
static const double empty[32] = {0};
const double *vals = empty;
double *alloc = NULL;
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);
@ -234,7 +234,7 @@ sysprof_normalized_series_get_series_item (SysprofSeries *series,
ret = g_object_new (SYSPROF_TYPE_NORMALIZED_SERIES_ITEM,
"item", item,
"value", g_array_index (self->values, float, position),
"value", g_array_index (self->values, double, position),
NULL);
g_object_unref (item);
@ -365,7 +365,7 @@ sysprof_normalized_series_class_init (SysprofNormalizedSeriesClass *klass)
static void
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 ();
}
@ -404,7 +404,7 @@ sysprof_normalized_series_new (SysprofSeries *series,
return SYSPROF_SERIES (normalized);
}
float
double
sysprof_normalized_series_get_value_at (SysprofNormalizedSeries *self,
guint position)
{
@ -416,7 +416,7 @@ sysprof_normalized_series_get_value_at (SysprofNormalizedSeries *self,
if (position >= self->values->len)
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,
guint *n_values)
{
@ -545,7 +545,7 @@ sysprof_normalized_series_get_values (SysprofNormalizedSeries *self,
*n_values = self->values->len;
return &g_array_index (self->values, float, 0);
return &g_array_index (self->values, double, 0);
}
void

View File

@ -62,10 +62,10 @@ SYSPROF_AVAILABLE_IN_ALL
void sysprof_normalized_series_set_series (SysprofNormalizedSeries *self,
SysprofSeries *series);
SYSPROF_AVAILABLE_IN_ALL
float sysprof_normalized_series_value_at (SysprofNormalizedSeries *self,
double sysprof_normalized_series_value_at (SysprofNormalizedSeries *self,
guint position);
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);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofNormalizedSeries, g_object_unref)

View File

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

View File

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

View File

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