Mercurial > geeqie
changeset 1331:a5c15bf32cdb
compute histmap in idle callback and only if the histogram is expanded
author | nadvornik |
---|---|
date | Fri, 27 Feb 2009 21:30:28 +0000 |
parents | 8b6e2a47adc7 |
children | 4286f08079b6 |
files | src/bar_histogram.c |
diffstat | 1 files changed, 38 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bar_histogram.c Thu Feb 26 21:46:27 2009 +0000 +++ b/src/bar_histogram.c Fri Feb 27 21:30:28 2009 +0000 @@ -42,22 +42,46 @@ gint histogram_height; GdkPixbuf *pixbuf; FileData *fd; + gboolean need_update; + gint idle_id; }; +static gboolean bar_pane_histogram_update_cb(gpointer data); + static void bar_pane_histogram_update(PaneHistogramData *phd) { - const HistMap *histmap; if (phd->pixbuf) g_object_unref(phd->pixbuf); phd->pixbuf = NULL; if (!phd->histogram_width || !phd->histogram_height || !phd->fd) return; + /* histmap_get is relatively expensive, run it only when we really need it + and with lower priority than pixbuf_renderer + FIXME: this does not work for fullscreen*/ + if (GTK_WIDGET_DRAWABLE(phd->drawing_area)) + { + if (phd->idle_id == -1) phd->idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, bar_pane_histogram_update_cb, phd, NULL); + } + else + { + phd->need_update = TRUE; + } +} + +static gboolean bar_pane_histogram_update_cb(gpointer data) +{ + const HistMap *histmap; + PaneHistogramData *phd = data; + + phd->idle_id = -1; + phd->need_update = FALSE; + gtk_widget_queue_draw_area(GTK_WIDGET(phd->drawing_area), 0, 0, phd->histogram_width, phd->histogram_height); histmap = histmap_get(phd->fd); - if (!histmap) return; + if (!histmap) return FALSE; phd->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, phd->histogram_width, phd->histogram_height); gdk_pixbuf_fill(phd->pixbuf, 0xffffffff); @@ -66,6 +90,7 @@ #if GTK_CHECK_VERSION(2,12,0) gtk_widget_set_tooltip_text(phd->drawing_area, histogram_label(phd->histogram)); #endif + return FALSE; } @@ -109,7 +134,14 @@ static gboolean bar_pane_histogram_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) { PaneHistogramData *phd = data; - if (!phd || !phd->pixbuf) return TRUE; + if (!phd) return TRUE; + + if (phd->need_update) + { + bar_pane_histogram_update(phd); + } + + if (!phd->pixbuf) return TRUE; gdk_draw_pixbuf(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], @@ -143,7 +175,8 @@ static void bar_pane_histogram_destroy(GtkWidget *widget, gpointer data) { PaneHistogramData *phd = data; - + + g_source_remove(phd->idle_id); file_data_unregister_notify_func(bar_pane_histogram_notify_cb, phd); file_data_unref(phd->fd); @@ -304,6 +337,7 @@ phd->pane.pane_write_config = bar_pane_histogram_write_config; phd->pane.title = g_strdup(title); phd->pane.expanded = expanded; + phd->idle_id = -1; phd->histogram = histogram_new();