r16448 - gnucash/trunk/src - Optimize some dense-cal (re-)drawing and updating. Add some timer-debuggings.
Josh Sled
jsled at cvs.gnucash.org
Sat Aug 18 11:48:14 EDT 2007
Author: jsled
Date: 2007-08-18 11:48:13 -0400 (Sat, 18 Aug 2007)
New Revision: 16448
Trac: http://svn.gnucash.org/trac/changeset/16448
Modified:
gnucash/trunk/src/gnome-utils/gnc-dense-cal-store.c
gnucash/trunk/src/gnome-utils/gnc-dense-cal.c
gnucash/trunk/src/gnome/dialog-sx-editor.c
Log:
Optimize some dense-cal (re-)drawing and updating. Add some timer-debuggings.
Modified: gnucash/trunk/src/gnome/dialog-sx-editor.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-sx-editor.c 2007-08-18 15:28:18 UTC (rev 16447)
+++ gnucash/trunk/src/gnome/dialog-sx-editor.c 2007-08-18 15:48:13 UTC (rev 16448)
@@ -1553,8 +1553,8 @@
g_free(schedule_desc);
}
- gnc_dense_cal_set_month(sxed->example_cal, g_date_get_month(&first_date));
- gnc_dense_cal_set_year(sxed->example_cal, g_date_get_year(&first_date));
+ //gnc_dense_cal_set_month(sxed->example_cal, g_date_get_month(&first_date));
+ //gnc_dense_cal_set_year(sxed->example_cal, g_date_get_year(&first_date));
/* figure out the end restriction */
if (gtk_toggle_button_get_active(sxed->optEndDate))
Modified: gnucash/trunk/src/gnome-utils/gnc-dense-cal-store.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-dense-cal-store.c 2007-08-18 15:28:18 UTC (rev 16447)
+++ gnucash/trunk/src/gnome-utils/gnc-dense-cal-store.c 2007-08-18 15:48:13 UTC (rev 16448)
@@ -159,7 +159,7 @@
g_free(model->name);
}
model->name = g_strdup(name);
- g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
+ //g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
}
void
@@ -170,7 +170,7 @@
g_free(model->info);
}
model->info = g_strdup(info);
- g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
+ //g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
}
static void
Modified: gnucash/trunk/src/gnome-utils/gnc-dense-cal.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-dense-cal.c 2007-08-18 15:28:18 UTC (rev 16447)
+++ gnucash/trunk/src/gnome-utils/gnc-dense-cal.c 2007-08-18 15:48:13 UTC (rev 16448)
@@ -112,6 +112,11 @@
static inline int col_height(GncDenseCal *dcal);
static inline int num_cols(GncDenseCal *dcal);
+
+static void _gnc_dense_cal_set_month(GncDenseCal *dcal, GDateMonth mon, gboolean redraw);
+static void _gnc_dense_cal_set_year(GncDenseCal *dcal, guint year, gboolean redraw);
+
+
/**
* Returns the total number of weeks to display in the calendar [irrespective
* of columns/weeks-per-col].
@@ -136,7 +141,7 @@
int *x1, int *y1, int *x2, int *y2);
static void gdc_mark_add(GncDenseCal *dcal, guint tag, gchar *name, gchar *info, guint size, GDate **dateArray);
-static void gdc_mark_remove(GncDenseCal *dcal, guint mark_to_remove);
+static void gdc_mark_remove(GncDenseCal *dcal, guint mark_to_remove, gboolean redraw);
static void gdc_add_tag_markings(GncDenseCal *cal, guint tag);
static void gdc_add_markings(GncDenseCal *cal);
@@ -282,7 +287,6 @@
gtk_box_pack_start(GTK_BOX(dcal), GTK_WIDGET(hbox), FALSE, FALSE, 0);
}
-
dcal->cal_drawing_area = GTK_DRAWING_AREA(gtk_drawing_area_new());
gtk_widget_add_events(GTK_WIDGET(dcal->cal_drawing_area), (GDK_EXPOSURE_MASK
| GDK_BUTTON_PRESS_MASK
@@ -395,8 +399,8 @@
{
GDate *now = g_date_new();
g_date_set_time_t(now, time(NULL));
- gnc_dense_cal_set_month(dcal, g_date_get_month(now));
- gnc_dense_cal_set_year(dcal, g_date_get_year(now));
+ _gnc_dense_cal_set_month(dcal, g_date_get_month(now), FALSE);
+ _gnc_dense_cal_set_year(dcal, g_date_get_year(now), FALSE);
g_date_free(now);
}
@@ -491,24 +495,53 @@
void
gnc_dense_cal_set_month(GncDenseCal *dcal, GDateMonth mon)
{
+ _gnc_dense_cal_set_month(dcal, mon, TRUE);
+}
+
+static void
+_gnc_dense_cal_set_month(GncDenseCal *dcal, GDateMonth mon, gboolean redraw)
+{
+ GTimer *t = g_timer_new();
+ if (dcal->month == mon)
+ return;
dcal->month = mon;
+ g_timer_start(t);
recompute_first_of_month_offset(dcal);
+ g_debug("recompute_first_of_month_offset: %f", g_timer_elapsed(t, NULL) * 1000.);
+ g_timer_start(t);
recompute_extents(dcal);
- if (GTK_WIDGET_REALIZED(dcal))
+ g_debug("recompute_extents: %f", g_timer_elapsed(t, NULL) * 1000.);
+ if (redraw && GTK_WIDGET_REALIZED(dcal))
{
+ g_timer_start(t);
recompute_x_y_scales(dcal);
+ g_debug("recompute_x_y_scales: %f", g_timer_elapsed(t, NULL) * 1000.);
+ g_timer_start(t);
gnc_dense_cal_draw_to_buffer(dcal);
+ g_debug("draw_to_buffer: %f", g_timer_elapsed(t, NULL) * 1000.);
+ g_timer_start(t);
gtk_widget_queue_draw(GTK_WIDGET(dcal->cal_drawing_area));
+ g_debug("queue_draw: %f", g_timer_elapsed(t, NULL) * 1000.);
}
+ g_timer_stop(t);
+ g_timer_destroy(t);
}
void
gnc_dense_cal_set_year(GncDenseCal *dcal, guint year)
{
+ return _gnc_dense_cal_set_year(dcal, year, TRUE);
+}
+
+static void
+_gnc_dense_cal_set_year(GncDenseCal *dcal, guint year, gboolean redraw)
+{
+ if (dcal->year == year)
+ return;
dcal->year = year;
recompute_first_of_month_offset(dcal);
recompute_extents(dcal);
- if (GTK_WIDGET_REALIZED(dcal))
+ if (redraw && GTK_WIDGET_REALIZED(dcal))
{
recompute_x_y_scales(dcal);
gnc_dense_cal_draw_to_buffer(dcal);
@@ -833,6 +866,8 @@
return TRUE;
}
+#define LOG_AND_RESET(timer, msg) do { g_debug("%s: %f", msg, g_timer_elapsed(timer, NULL) * 1000.); g_timer_reset(timer); } while (0);
+
static void
gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
{
@@ -840,13 +875,18 @@
gint i;
int maxWidth;
PangoLayout *layout;
+ GTimer *timer;
+ timer = g_timer_new();
+ g_debug("drawing");
widget = GTK_WIDGET(dcal);
if (!dcal->drawbuf)
return;
+ g_timer_start(timer);
layout = gtk_widget_create_pango_layout(GTK_WIDGET(dcal), NULL);
+ LOG_AND_RESET(timer, "create_pango_layout");
gdk_draw_rectangle(dcal->drawbuf,
widget->style->white_gc,
@@ -895,6 +935,7 @@
g_object_unref(gc);
}
+ LOG_AND_RESET(timer, "alternating month colors");
/* Hilight the marked days. */
{
@@ -944,6 +985,7 @@
// reset to the previous foreground color.
gdk_gc_set_foreground(widget->style->fg_gc[widget->state], ¤t_values.foreground);
}
+ LOG_AND_RESET(timer, "marked days");
for (i=0; i < num_cols(dcal); i++)
{
@@ -1013,6 +1055,7 @@
}
}
}
+ LOG_AND_RESET(timer, "lines and labels");
/* Month labels. */
{
@@ -1041,6 +1084,7 @@
pango_matrix_rotate(&matrix, -90.);
pango_context_set_matrix(gtk_widget_get_pango_context(GTK_WIDGET(dcal)), &matrix);
}
+ LOG_AND_RESET(timer, "month labels");
/* Try the per-day strings [dates] */
{
@@ -1069,6 +1113,7 @@
layout);
}
}
+ LOG_AND_RESET(timer, "dates");
gtk_widget_queue_draw_area(GTK_WIDGET(dcal),
widget->allocation.x,
@@ -1076,7 +1121,11 @@
widget->allocation.width,
widget->allocation.height);
+ LOG_AND_RESET(timer, "queue draw");
+
g_object_unref(layout);
+
+ g_timer_destroy(timer);
}
static void
@@ -1676,6 +1725,9 @@
gnc_dense_cal_model_get_instance(cal->model, tag, idx, dates[idx]);
}
+ _gnc_dense_cal_set_month(cal, g_date_get_month(dates[0]), FALSE);
+ _gnc_dense_cal_set_year(cal, g_date_get_year(dates[0]), FALSE);
+
gdc_mark_add(cal, tag, name, info, num_marks, dates);
for (idx = 0; idx < num_marks; idx++)
@@ -1709,7 +1761,7 @@
for (; tags != NULL; tags = tags->next)
{
guint tag = GPOINTER_TO_UINT(tags->data);
- gdc_mark_remove(cal, tag);
+ gdc_mark_remove(cal, tag, FALSE);
}
g_list_free(tags);
}
@@ -1727,8 +1779,9 @@
{
GncDenseCal *cal = GNC_DENSE_CAL(user_data);
g_debug("gdc_model_update_cb update for tag [%d]\n", update_tag);
- gdc_mark_remove(cal, update_tag);
+ gdc_mark_remove(cal, update_tag, FALSE);
gdc_add_tag_markings(cal, update_tag);
+
}
static void
@@ -1736,7 +1789,7 @@
{
GncDenseCal *cal = GNC_DENSE_CAL(user_data);
g_debug("gdc_model_removing_cb update [%d]\n", remove_tag);
- gdc_mark_remove(cal, remove_tag);
+ gdc_mark_remove(cal, remove_tag, TRUE);
}
void
@@ -1812,7 +1865,7 @@
}
static void
-gdc_mark_remove(GncDenseCal *dcal, guint mark_to_remove)
+gdc_mark_remove(GncDenseCal *dcal, guint mark_to_remove, gboolean redraw)
{
GList *iter, *calendar_marks;
gint day_of_cal;
@@ -1851,6 +1904,10 @@
g_list_free(mark_data->ourMarks);
dcal->markData = g_list_remove(dcal->markData, mark_data);
g_free(mark_data);
- gnc_dense_cal_draw_to_buffer(dcal);
- gtk_widget_queue_draw(GTK_WIDGET(dcal->cal_drawing_area));
+
+ if (redraw)
+ {
+ gnc_dense_cal_draw_to_buffer(dcal);
+ gtk_widget_queue_draw(GTK_WIDGET(dcal->cal_drawing_area));
+ }
}
More information about the gnucash-changes
mailing list