From: Enlightenment S. <no-...@en...> - 2009-04-16 21:04:02
|
Log: create the thumbnails in a different thread Author: urandom Date: 2009-04-16 14:03:53 -0700 (Thu, 16 Apr 2009) New Revision: 40118 Modified: trunk/PROTO/image-viewer/configure.in trunk/PROTO/image-viewer/data/theme/default.edc trunk/PROTO/image-viewer/src/bin/main.c Modified: trunk/PROTO/image-viewer/configure.in =================================================================== --- trunk/PROTO/image-viewer/configure.in 2009-04-16 21:03:43 UTC (rev 40117) +++ trunk/PROTO/image-viewer/configure.in 2009-04-16 21:03:53 UTC (rev 40118) @@ -47,9 +47,91 @@ AM_CONDITIONAL(BUILD_E, test $have_enlightenment = yes) +AC_DEFUN([EFL_CHECK_PTHREAD], +[ + +dnl configure option + +AC_ARG_ENABLE([pthread], + [AC_HELP_STRING([--disable-pthread], [enable POSIX threads code @<:@default=no@:>@])], + [ + if test "x${enableval}" = "xyes" ; then + _efl_enable_pthread="yes" + else + _efl_enable_pthread="no" + fi + ], + [_efl_enable_pthread="yes"] +) +AC_MSG_CHECKING([whether to build POSIX threads code]) +AC_MSG_RESULT([${_efl_enable_pthread}]) + +dnl check if the compiler supports pthreads + +_efl_have_pthread="no" + +if test "x${_efl_enable_pthread}" = "xyes" ; then + + SAVE_CFLAGS=${CFLAGS} + CFLAGS="-pthread" + AC_LANG_PUSH([C]) + + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ +#include <pthread.h> + ]], + [[]]) + ], + [ + _efl_have_pthread="yes" + EFL_PTHREAD_CFLAGS="-pthread" + EFL_PTHREAD_LIBS="-pthread" + ] + ) + + AC_LANG_POP([C]) + CFLAGS=${SAVE_CFLAGS} +fi + +AC_MSG_CHECKING([whether compiler need -pthread POSIX for threads support]) +AC_MSG_RESULT([${_efl_have_pthread}]) + +if test "x${_efl_have_pthread}" = "xno" -a "x${_efl_enable_pthread}" = "xyes" ; then + AC_CHECK_HEADER(pthread.h, + [ + _efl_have_pthread="yes" + EFL_PTHREAD_LIBS="-lpthread" + ], + [ + _efl_have_pthread="no" + ]) + + AC_MSG_CHECKING([whether system support POSIX threads]) + AC_MSG_RESULT([${_efl_enable_pthread}]) +fi + +AC_SUBST(EFL_PTHREAD_CFLAGS) +AC_SUBST(EFL_PTHREAD_LIBS) + +if test "x${_efl_have_pthread}" = "xyes" ; then + AC_DEFINE(EFL_HAVE_PTHREAD, 1, [Define to mention that POSIX threads are supported]) +fi + +if test "x${_efl_have_pthread}" = "xyes" ; then + ifelse([$1], , :, [$1]) +else + ifelse([$2], , :, [$2]) +fi +]) +EFL_CHECK_PTHREAD([have_pthread="yes"], [have_pthread="no"]) + PKG_CHECK_MODULES(ETHUMB, ethumb, [ - have_ethumb="yes" - AC_DEFINE(HAVE_ETHUMB, 1, [have ethumb support]) + if test $have_pthread = yes ; then + have_ethumb="yes" + AC_DEFINE(HAVE_ETHUMB, 1, [have ethumb support]) + else + have_ethumb="no" + fi ], [ have_ethumb="no" ]) Modified: trunk/PROTO/image-viewer/data/theme/default.edc =================================================================== --- trunk/PROTO/image-viewer/data/theme/default.edc 2009-04-16 21:03:43 UTC (rev 40117) +++ trunk/PROTO/image-viewer/data/theme/default.edc 2009-04-16 21:03:53 UTC (rev 40118) @@ -21,18 +21,16 @@ state: "default" 0.0; visible: 0; fixed: 1 1; - rel2 { - relative: 1 0; - offset: 0 0; - } + min: 0 80; + rel1.relative: 0 -0.1; + rel2.relative: 1 0; } description { state: "active" 0.0; + inherit: "default" 0.0; visible: 1; - rel2 { - relative: 1 0; - offset: 0 60; - } + rel1.relative: 0 0; + rel2.relative: 1 0.1; } } part { name: "iv.swallow.controls"; @@ -40,18 +38,28 @@ description { state: "default" 0.0; visible: 0; + fixed: 1 1; rel1 { relative: 0 1; offset: 0 0; } + rel2 { + relative: 1 1; + offset: 0 -40; + } } description { state: "active" 0.0; + inherit: "default" 0.0; visible: 1; rel1 { relative: 0 1; offset: 0 -40; } + rel2 { + relative: 1 1; + offset: 0 0; + } } } part { name: "upper_edge"; Modified: trunk/PROTO/image-viewer/src/bin/main.c =================================================================== --- trunk/PROTO/image-viewer/src/bin/main.c 2009-04-16 21:03:43 UTC (rev 40117) +++ trunk/PROTO/image-viewer/src/bin/main.c 2009-04-16 21:03:53 UTC (rev 40118) @@ -18,6 +18,7 @@ #ifdef HAVE_ETHUMB #include <Ethumb.h> + #include <pthread.h> #endif #ifdef HAVE_LIBEXIF @@ -25,6 +26,7 @@ #endif #define DBG(...) EINA_ERROR_PDBG(__VA_ARGS__) +#define ERR(...) EINA_ERROR_PERR(__VA_ARGS__) typedef enum _IV_Image_Fit { PAN, @@ -46,6 +48,7 @@ typedef struct _IV IV; typedef struct _IV_Config IV_Config; +typedef struct _IV_Thumb_Info IV_Thumb_Info; struct _IV { @@ -84,6 +87,7 @@ Eina_Bool ignore_preview_change : 1; Eina_Bool hide_previews : 1; Eina_Bool previews_visible : 1; + Eina_Bool first_preview : 1; #endif } flags; @@ -93,11 +97,12 @@ Ecore_Timer *config_save; #ifdef HAVE_ETHUMB + Eina_List *thumb_path; Eina_List *preview_files; - Eina_List *preview_items; + Eina_Hash *preview_items; Ethumb *ethumb; - int preview_startup_count; + pthread_t thumb_thread; #endif }; @@ -111,6 +116,12 @@ IV_Image_Bg image_bg; }; +struct _IV_Thumb_Info +{ + const char *thumb_path; + const char *file; +}; + static Eina_List * rewind_list(Eina_List *list) { @@ -533,7 +544,6 @@ { Evas_Object *thumb = data; IV *iv = evas_object_data_get(thumb, "iv"); - Eina_List *l = evas_object_data_get(thumb, "iv_preview_list"); const char *file = evas_object_data_get(thumb, "iv_file"); if (iv->flags.ignore_preview_change) @@ -543,16 +553,50 @@ } iv->files = eina_list_data_find_list(rewind_list(iv->files), file); - iv->preview_items = l; iv->flags.current = EINA_TRUE; if (iv->config->auto_hide_previews) iv->flags.hide_previews = EINA_TRUE; } +static void * +on_thumb_thread_create(void *data) +{ + IV *iv = data; + Eina_List *l; + const char *file; + + EINA_LIST_FOREACH(iv->preview_files, l, file) + { + Ethumb_File *ef = ethumb_file_new(iv->ethumb, file); + + if (ef) + { + if (ethumb_file_generate(ef)) + { + IV_Thumb_Info *info = calloc(1, sizeof(IV_Thumb_Info)); + + info->thumb_path = eina_stringshare_add(ef->thumb_path); + info->file = file; + + iv->thumb_path = eina_list_append(iv->thumb_path, info); + } + ethumb_file_free(ef); + } + + iv->preview_files = l; + } + + iv->thumb_thread = 0; + return NULL; +} + static int on_idler(void *data) { IV *iv = data; +#ifdef HAVE_ETHUMB + Elm_Toolbar_Item *item; +#endif if (iv->dirs) { @@ -614,66 +658,55 @@ } #ifdef HAVE_ETHUMB - if (iv->flags.add_previews && !iv->preview_startup_count) + if (!iv->thumb_thread && iv->thumb_path) { - Eina_List *l; - const char *file; - int count = 0; - Eina_Bool new = EINA_FALSE; + Evas_Object *thumb; + IV_Thumb_Info *info; - if (!iv->preview_files) + EINA_LIST_FREE(iv->thumb_path, info) { - iv->preview_files = rewind_list(iv->files); - new = EINA_TRUE; - } + Elm_Toolbar_Item *item; - EINA_LIST_FOREACH(iv->preview_files, l, file) - { - Ethumb_File *ef = ethumb_file_new(iv->ethumb, file); + thumb = elm_icon_add(iv->gui.toolbar); + elm_icon_file_set(thumb, info->thumb_path, NULL); + evas_object_data_set(thumb, "iv", iv); + evas_object_data_set(thumb, "iv_file", info->file); + evas_object_show(thumb); + item = elm_toolbar_item_add(iv->gui.toolbar, thumb, NULL, on_toolbar_change, thumb); + eina_hash_add(iv->preview_items, info->file, item); - if (ef) + if (iv->flags.first_preview) { - Evas_Object *thumb; + iv->flags.ignore_preview_change = EINA_TRUE; + elm_toolbar_item_select(item); + iv->flags.first_preview = EINA_FALSE; + } - if (ethumb_file_generate(ef)) - { - thumb = elm_icon_add(iv->gui.toolbar); - elm_icon_file_set(thumb, ef->thumb_path, NULL); - evas_object_data_set(thumb, "iv", iv); - evas_object_data_set(thumb, "iv_file", file); - evas_object_show(thumb); - iv->preview_items = eina_list_append( - iv->preview_items, - elm_toolbar_item_add(iv->gui.toolbar, thumb, NULL, on_toolbar_change, thumb)); - evas_object_data_set(thumb, "iv_preview_list", eina_list_last(iv->preview_items)); + eina_stringshare_del(info->thumb_path); + free(info); + } - if (new) - { - iv->flags.ignore_preview_change = EINA_TRUE; - elm_toolbar_item_select(iv->preview_items->data); - new = EINA_FALSE; - } - } - ethumb_file_free(ef); - } + } - iv->preview_files = l; - if (++count > 10) - { - if (l->next) - iv->preview_files = l->next; - break; - } + if (iv->flags.add_previews) + { + int rc; + + if (!iv->preview_files) + { + iv->preview_files = rewind_list(iv->files); + iv->flags.first_preview = EINA_TRUE; } - if (iv->preview_files->next) - iv->flags.add_previews = EINA_TRUE; - else - iv->flags.add_previews = EINA_FALSE; + if (!iv->thumb_thread) + { + rc = pthread_create(&(iv->thumb_thread), NULL, on_thumb_thread_create, iv); + if (rc) + ERR("Error starting the thumbnail thread: %d\n", rc); + + iv->flags.add_previews = EINA_FALSE; + } } - - if (iv->preview_startup_count) - iv->preview_startup_count--; #endif } @@ -684,19 +717,9 @@ iv->flags.next = EINA_FALSE; if (iv->files->next) - { - iv->files = iv->files->next; -#ifdef HAVE_ETHUMB - iv->preview_items = iv->preview_items->next; -#endif - } + iv->files = iv->files->next; else - { - iv->files = rewind_list(iv->files); -#ifdef HAVE_ETHUMB - iv->preview_items = rewind_list(iv->preview_items); -#endif - } + iv->files = rewind_list(iv->files); /* XXX: this is necessary for some reason, bug in elm? */ elm_scroller_content_set(iv->gui.scroller, NULL); @@ -720,7 +743,9 @@ #ifdef HAVE_ETHUMB iv->flags.ignore_preview_change = EINA_TRUE; - elm_toolbar_item_select(iv->preview_items->data); + item = eina_hash_find(iv->preview_items, iv->files->data); + if (item) + elm_toolbar_item_select(item); #endif } } @@ -731,19 +756,9 @@ iv->flags.prev = EINA_FALSE; if (iv->files->prev) - { - iv->files = iv->files->prev; -#ifdef HAVE_ETHUMB - iv->preview_items = iv->preview_items->prev; -#endif - } + iv->files = iv->files->prev; else - { - iv->files = eina_list_last(iv->files); -#ifdef HAVE_ETHUMB - iv->preview_items = eina_list_last(iv->preview_items); -#endif - } + iv->files = eina_list_last(iv->files); /* XXX: this is necessary for some reason, bug in elm? */ elm_scroller_content_set(iv->gui.scroller, NULL); @@ -767,7 +782,9 @@ #ifdef HAVE_ETHUMB iv->flags.ignore_preview_change = EINA_TRUE; - elm_toolbar_item_select(iv->preview_items->data); + item = eina_hash_find(iv->preview_items, iv->files->data); + if (item) + elm_toolbar_item_select(item); #endif } } @@ -1351,10 +1368,9 @@ #ifdef HAVE_ETHUMB ethumb_init(); iv->ethumb = ethumb_new(); + iv->preview_items = eina_hash_string_superfast_new(NULL); if (iv->files) iv->flags.add_previews = EINA_TRUE; - - iv->preview_startup_count = 3; #endif iv->flags.fit_changed = EINA_TRUE; @@ -1364,6 +1380,7 @@ #ifdef HAVE_ETHUMB ethumb_free(iv->ethumb); + eina_hash_free(iv->preview_items); ethumb_shutdown(); #endif iv_free(iv); |