changeset 2078:41ea2592dde6

try to merge pending area_ready notifications
author Vladimir Nadvornik <nadvornik@suse.cz>
date Tue, 14 Aug 2012 22:52:03 +0200
parents 034e50486d27
children 429a86e76026
files src/image-load.c
diffstat 1 files changed, 56 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/image-load.c	Sun Aug 12 21:07:49 2012 +0200
+++ b/src/image-load.c	Tue Aug 14 22:52:03 2012 +0200
@@ -252,11 +252,17 @@
 {
 	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;
 }
@@ -319,9 +325,43 @@
 	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;
@@ -329,9 +369,19 @@
 	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);
+		}
 }
 
 /**************************************************************************************/
@@ -340,14 +390,7 @@
 /* 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);
 }