/*
* Geeqie
* (C) 2004 John Ellis
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
*
* Author: John Ellis
*
GType image_loader_get_type(void)
{
static GType type = 0;
- if (type == 0)
+ if (type == 0)
{
static const GTypeInfo info = {
sizeof(ImageLoaderClass),
il->idle_done_id = 0;
}
- while (g_source_remove_by_user_data(il))
+ while (g_source_remove_by_user_data(il))
{
DEBUG_2("pending signals detected");
}
- while (il->area_param_list)
+ while (il->area_param_list)
{
DEBUG_1("pending area_ready signals detected");
while (g_source_remove_by_user_data(il->area_param_list->data)) {}
il->area_param_list = g_list_delete_link(il->area_param_list, il->area_param_list);
}
- while (il->area_param_delayed_list)
+ while (il->area_param_delayed_list)
{
g_free(il->area_param_delayed_list->data);
il->area_param_delayed_list = g_list_delete_link(il->area_param_delayed_list, il->area_param_delayed_list);
{
ImageLoaderAreaParam *par = data;
ImageLoader *il = par->il;
- g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h);
+ guint x, y, w, h;
g_mutex_lock(il->data_mutex);
il->area_param_list = g_list_remove(il->area_param_list, par);
+ x = par->x;
+ y = par->y;
+ w = par->w;
+ h = par->h;
g_free(par);
g_mutex_unlock(il->data_mutex);
+
+ g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, x, y, w, h);
return FALSE;
}
g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_size_cb, il, NULL);
}
-/* this function expects that il->data_mutex is locked by caller */
-static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
+static ImageLoaderAreaParam *image_loader_queue_area_ready(ImageLoader *il, GList **list, guint x, guint y, guint w, guint h)
{
+ if (*list)
+ {
+ ImageLoaderAreaParam *prev_par = (*list)->data;
+ if (prev_par->x == x && prev_par->w == w &&
+ prev_par->y + prev_par->h == y)
+ {
+ /* we can merge the notifications */
+ prev_par->h += h;
+ return NULL;
+ }
+ if (prev_par->x == x && prev_par->w == w &&
+ y + h == prev_par->y)
+ {
+ /* we can merge the notifications */
+ prev_par->h += h;
+ prev_par->y = y;
+ return NULL;
+ }
+ if (prev_par->y == y && prev_par->h == h &&
+ prev_par->x + prev_par->w == x)
+ {
+ /* we can merge the notifications */
+ prev_par->w += w;
+ return NULL;
+ }
+ if (prev_par->y == y && prev_par->h == h &&
+ x + w == prev_par->x)
+ {
+ /* we can merge the notifications */
+ prev_par->w += w;
+ prev_par->x = x;
+ return NULL;
+ }
+ }
+
ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
par->il = il;
par->x = x;
par->w = w;
par->h = h;
- il->area_param_list = g_list_prepend(il->area_param_list, par);
+ *list = g_list_prepend(*list, par);
+ return par;
+}
+
+/* this function expects that il->data_mutex is locked by caller */
+static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
+{
+ ImageLoaderAreaParam *par = image_loader_queue_area_ready(il, &il->area_param_list, x, y, w, h);
- g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
+ if (par)
+ {
+ g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
+ }
}
/**************************************************************************************/
/* this function expects that il->data_mutex is locked by caller */
static void image_loader_queue_delayed_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
{
- ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
- par->il = il;
- par->x = x;
- par->y = y;
- par->w = w;
- par->h = h;
-
- il->area_param_delayed_list = g_list_prepend(il->area_param_delayed_list, par);
+ image_loader_queue_area_ready(il, &il->area_param_delayed_list, x, y, w, h);
}
g_mutex_lock(il->data_mutex);
- if (!il->loader)
+ if (!il->loader)
{
g_mutex_unlock(il->data_mutex);
return;
guchar *pix;
size_t h, rs;
- /* a workaround for
- http://bugzilla.gnome.org/show_bug.cgi?id=547669
+ /* a workaround for
+ http://bugzilla.gnome.org/show_bug.cgi?id=547669
http://bugzilla.gnome.org/show_bug.cgi?id=589334
*/
gchar *format = il->backend.get_format_name(loader);
g_mutex_lock(il->data_mutex);
il->actual_width = width;
il->actual_height = height;
- if (il->requested_width < 1 || il->requested_height < 1)
+ if (il->requested_width < 1 || il->requested_height < 1)
{
g_mutex_unlock(il->data_mutex);
image_loader_emit_size(il);
static void image_loader_thread_wait_high(void)
{
g_mutex_lock(image_loader_prio_mutex);
- while (image_loader_prio_num)
+ while (image_loader_prio_num)
{
g_cond_wait(image_loader_prio_cond, image_loader_prio_mutex);
}
gboolean cont;
gboolean err;
- if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
+ if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
{
/* low prio, wait untill high prio tasks finishes */
image_loader_thread_wait_high();
if (err)
{
- /*
- loader failed, we have to send signal
+ /*
+ loader failed, we have to send signal
(idle mode returns the image_loader_begin return value directly)
(success is always reported indirectly from image_loader_begin)
*/
while (cont && !image_loader_get_is_done(il) && !image_loader_get_stopping(il))
{
- if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
+ if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE)
{
/* low prio, wait untill high prio tasks finishes */
image_loader_thread_wait_high();
}
image_loader_stop_loader(il);
- if (il->idle_priority <= G_PRIORITY_DEFAULT_IDLE)
+ if (il->idle_priority <= G_PRIORITY_DEFAULT_IDLE)
{
/* high prio */
image_loader_thread_leave_high();
if (!image_loader_setup_source(il)) return FALSE;
- if (!image_loader_thread_pool)
+ if (!image_loader_thread_pool)
{
image_loader_thread_pool = g_thread_pool_new(image_loader_thread_run, NULL, -1, FALSE, NULL);
image_loader_prio_cond = g_cond_new();
if (!il) return 0.0;
g_mutex_lock(il->data_mutex);
- if (il->bytes_total == 0)
+ if (il->bytes_total == 0)
{
ret = 0.0;
}