comparison src/image-load.c @ 1045:0ab0deb0cfcc

added possibility to redraw only the parts of image that are already loaded
author nadvornik
date Mon, 08 Sep 2008 19:57:51 +0000
parents 5fc64d6252e7
children 1646720364cf
comparison
equal deleted inserted replaced
1044:ea4e0c2df854 1045:0ab0deb0cfcc
170 while (g_source_remove_by_user_data(il->area_param_list->data)) {} 170 while (g_source_remove_by_user_data(il->area_param_list->data)) {}
171 g_free(il->area_param_list->data); 171 g_free(il->area_param_list->data);
172 il->area_param_list = g_list_delete_link(il->area_param_list, il->area_param_list); 172 il->area_param_list = g_list_delete_link(il->area_param_list, il->area_param_list);
173 } 173 }
174 174
175 while (il->area_param_delayed_list)
176 {
177 g_free(il->area_param_delayed_list->data);
178 il->area_param_delayed_list = g_list_delete_link(il->area_param_delayed_list, il->area_param_delayed_list);
179 }
180
175 if (il->pixbuf) g_object_unref(il->pixbuf); 181 if (il->pixbuf) g_object_unref(il->pixbuf);
176 182
177 file_data_unref(il->fd); 183 file_data_unref(il->fd);
178 #ifdef HAVE_GTHREAD 184 #ifdef HAVE_GTHREAD
179 g_mutex_free(il->data_mutex); 185 g_mutex_free(il->data_mutex);
265 static void image_loader_emit_percent(ImageLoader *il) 271 static void image_loader_emit_percent(ImageLoader *il)
266 { 272 {
267 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL); 273 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL);
268 } 274 }
269 275
276 /* this function expects that il->data_mutex is locked by caller */
270 static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h) 277 static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
271 { 278 {
272 ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1); 279 ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
273 par->il = il; 280 par->il = il;
274 par->x = x; 281 par->x = x;
275 par->y = y; 282 par->y = y;
276 par->w = w; 283 par->w = w;
277 par->h = h; 284 par->h = h;
278 285
279 g_mutex_lock(il->data_mutex);
280 il->area_param_list = g_list_prepend(il->area_param_list, par); 286 il->area_param_list = g_list_prepend(il->area_param_list, par);
281 g_mutex_unlock(il->data_mutex);
282 287
283 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL); 288 g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
284 } 289 }
285 290
286 /**************************************************************************************/ 291 /**************************************************************************************/
287 /* the following functions may be executed in separate thread */ 292 /* the following functions may be executed in separate thread */
288 293
294 /* this function expects that il->data_mutex is locked by caller */
295 static void image_loader_queue_delayed_erea_ready(ImageLoader *il, guint x, guint y, guint w, guint h)
296 {
297 ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
298 par->il = il;
299 par->x = x;
300 par->y = y;
301 par->w = w;
302 par->h = h;
303
304 il->area_param_delayed_list = g_list_prepend(il->area_param_delayed_list, par);
305 }
306
307
308
289 static gint image_loader_get_stopping(ImageLoader *il) 309 static gint image_loader_get_stopping(ImageLoader *il)
290 { 310 {
291 gint ret; 311 gint ret;
292 if (!il) return FALSE; 312 if (!il) return FALSE;
293 313
295 ret = il->stopping; 315 ret = il->stopping;
296 g_mutex_unlock(il->data_mutex); 316 g_mutex_unlock(il->data_mutex);
297 317
298 return ret; 318 return ret;
299 } 319 }
320
300 321
301 static void image_loader_sync_pixbuf(ImageLoader *il) 322 static void image_loader_sync_pixbuf(ImageLoader *il)
302 { 323 {
303 GdkPixbuf *pb; 324 GdkPixbuf *pb;
304 325
338 if (!image_loader_get_pixbuf(il)) 359 if (!image_loader_get_pixbuf(il))
339 { 360 {
340 log_printf("critical: area_ready signal with NULL pixbuf (out of mem?)\n"); 361 log_printf("critical: area_ready signal with NULL pixbuf (out of mem?)\n");
341 } 362 }
342 } 363 }
343 image_loader_emit_area_ready(il, x, y, w, h); 364
365 g_mutex_lock(il->data_mutex);
366 if (il->delay_area_ready)
367 image_loader_queue_delayed_erea_ready(il, x, y, w, h);
368 else
369 image_loader_emit_area_ready(il, x, y, w, h);
370 g_mutex_unlock(il->data_mutex);
344 } 371 }
345 372
346 static void image_loader_area_prepared_cb(GdkPixbufLoader *loader, gpointer data) 373 static void image_loader_area_prepared_cb(GdkPixbufLoader *loader, gpointer data)
347 { 374 {
348 GdkPixbuf *pb; 375 GdkPixbuf *pb;
664 image_loader_stop_loader(il); 691 image_loader_stop_loader(il);
665 image_loader_stop_source(il); 692 image_loader_stop_source(il);
666 693
667 } 694 }
668 695
696 void image_loader_delay_area_ready(ImageLoader *il, gint enable)
697 {
698 g_mutex_lock(il->data_mutex);
699 il->delay_area_ready = enable;
700 if (!enable)
701 {
702 /* send delayed */
703 GList *list, *work;
704 list = g_list_reverse(il->area_param_delayed_list);
705 il->area_param_delayed_list = NULL;
706 g_mutex_unlock(il->data_mutex);
707
708 work = list;
709
710 while (work)
711 {
712 ImageLoaderAreaParam *par = work->data;
713 work = work->next;
714
715 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h);
716 g_free(par);
717 }
718 g_list_free(list);
719 }
720 else
721 {
722 /* just unlock */
723 g_mutex_unlock(il->data_mutex);
724 }
725 }
726
727
669 /**************************************************************************************/ 728 /**************************************************************************************/
670 /* execution via idle calls */ 729 /* execution via idle calls */
671 730
672 static gint image_loader_idle_cb(gpointer data) 731 static gint image_loader_idle_cb(gpointer data)
673 { 732 {