forked from enlightenment/efl
elm_image: Fix file_set when preload is disabled
If we disable preload, then the second file set on an elm_image object would not trigger a deletion of the first image. As a consequence, both images would be visible... really bad if there's alpha or different dimensions! Thanks Anand Kumar for the report! @fix Also merges master commit: elm_image: Improve test case from previous patch
This commit is contained in:
parent
819b5e33b7
commit
4eda12b5e1
|
@ -347,7 +347,7 @@ _img_load_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info E
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_create_image(Evas_Object *data, Eina_Bool async, Eina_Bool preload)
|
_create_image(Evas_Object *data, Eina_Bool async, Eina_Bool preload, Eina_Bool logo)
|
||||||
{
|
{
|
||||||
Evas_Object *win = data;
|
Evas_Object *win = data;
|
||||||
Evas_Object *im, *status_text;
|
Evas_Object *im, *status_text;
|
||||||
|
@ -381,12 +381,15 @@ _create_image(Evas_Object *data, Eina_Bool async, Eina_Bool preload)
|
||||||
evas_object_smart_callback_add(im, "load,cancel", _img_load_cancel_cb, status_text);
|
evas_object_smart_callback_add(im, "load,cancel", _img_load_cancel_cb, status_text);
|
||||||
|
|
||||||
STATUS_SET(status_text, "Loading image...");
|
STATUS_SET(status_text, "Loading image...");
|
||||||
snprintf(buf, sizeof(buf) - 1, "%s/images/insanely_huge_test_image.jpg", elm_app_data_dir_get());
|
if (!logo)
|
||||||
|
snprintf(buf, sizeof(buf) - 1, "%s/images/insanely_huge_test_image.jpg", elm_app_data_dir_get());
|
||||||
|
else
|
||||||
|
snprintf(buf, sizeof(buf) - 1, "%s/images/logo.png", elm_app_data_dir_get());
|
||||||
elm_image_file_set(im, buf, NULL);
|
elm_image_file_set(im, buf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_bt_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
_reload_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
{
|
{
|
||||||
Evas_Object *win = data;
|
Evas_Object *win = data;
|
||||||
Evas_Object *im = evas_object_data_get(win, "im");
|
Evas_Object *im = evas_object_data_get(win, "im");
|
||||||
|
@ -394,9 +397,44 @@ _bt_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUS
|
||||||
Evas_Object *chk2 = evas_object_data_get(win, "chk2");
|
Evas_Object *chk2 = evas_object_data_get(win, "chk2");
|
||||||
Eina_Bool async = elm_check_state_get(chk1);
|
Eina_Bool async = elm_check_state_get(chk1);
|
||||||
Eina_Bool preload = elm_check_state_get(chk2);
|
Eina_Bool preload = elm_check_state_get(chk2);
|
||||||
|
Eina_Bool logo = EINA_FALSE;
|
||||||
|
const char *file = NULL;
|
||||||
|
|
||||||
|
elm_image_file_get(im, &file, NULL);
|
||||||
|
logo = (file && strstr(file, "logo"));
|
||||||
|
|
||||||
evas_object_del(im);
|
evas_object_del(im);
|
||||||
_create_image(win, async, preload);
|
_create_image(win, async, preload, logo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_switch_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||||
|
{
|
||||||
|
Evas_Object *win = data;
|
||||||
|
Evas_Object *im = evas_object_data_get(win, "im");
|
||||||
|
Evas_Object *chk1 = evas_object_data_get(win, "chk1");
|
||||||
|
Evas_Object *chk2 = evas_object_data_get(win, "chk2");
|
||||||
|
Eina_Bool async = elm_check_state_get(chk1);
|
||||||
|
Eina_Bool preload = elm_check_state_get(chk2);
|
||||||
|
char buf[PATH_MAX] = {0};
|
||||||
|
Eina_Bool logo = EINA_FALSE;
|
||||||
|
const char *file = NULL;
|
||||||
|
|
||||||
|
elm_image_file_get(im, &file, NULL);
|
||||||
|
logo = (file && strstr(file, "logo"));
|
||||||
|
|
||||||
|
if (logo)
|
||||||
|
{
|
||||||
|
snprintf(buf, sizeof(buf) - 1, "%s/images/insanely_huge_test_image.jpg", elm_app_data_dir_get());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(buf, sizeof(buf) - 1, "%s/images/logo.png", elm_app_data_dir_get());
|
||||||
|
}
|
||||||
|
|
||||||
|
elm_image_async_open_set(im, async);
|
||||||
|
elm_image_preload_disabled_set(im, preload);
|
||||||
|
elm_image_file_set(im, buf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -414,7 +452,7 @@ test_load_image(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
|
||||||
evas_object_show(box);
|
evas_object_show(box);
|
||||||
evas_object_data_set(win, "box", box);
|
evas_object_data_set(win, "box", box);
|
||||||
|
|
||||||
_create_image(win, EINA_FALSE, EINA_FALSE);
|
_create_image(win, EINA_FALSE, EINA_FALSE, EINA_FALSE);
|
||||||
|
|
||||||
hbox = elm_box_add(win);
|
hbox = elm_box_add(win);
|
||||||
elm_box_horizontal_set(hbox, EINA_TRUE);
|
elm_box_horizontal_set(hbox, EINA_TRUE);
|
||||||
|
@ -448,12 +486,26 @@ test_load_image(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
|
||||||
evas_object_show(hbox);
|
evas_object_show(hbox);
|
||||||
elm_box_pack_end(box, hbox);
|
elm_box_pack_end(box, hbox);
|
||||||
|
|
||||||
bt = elm_button_add(win);
|
hbox = elm_box_add(win);
|
||||||
evas_object_size_hint_align_set(bt, 0.5, 0.0);
|
elm_box_horizontal_set(hbox, EINA_TRUE);
|
||||||
elm_object_text_set(bt, "Image Reload");
|
elm_box_align_set(hbox, 0.5, 0.5);
|
||||||
evas_object_smart_callback_add(bt, "clicked", _bt_clicked, win);
|
evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, 0.0);
|
||||||
elm_box_pack_end(box, bt);
|
evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, 0.0);
|
||||||
evas_object_show(bt);
|
{
|
||||||
|
bt = elm_button_add(win);
|
||||||
|
elm_object_text_set(bt, "Image Reload");
|
||||||
|
evas_object_smart_callback_add(bt, "clicked", _reload_clicked, win);
|
||||||
|
elm_box_pack_end(hbox, bt);
|
||||||
|
evas_object_show(bt);
|
||||||
|
|
||||||
|
bt = elm_button_add(win);
|
||||||
|
elm_object_text_set(bt, "Image Switch");
|
||||||
|
evas_object_smart_callback_add(bt, "clicked", _switch_clicked, win);
|
||||||
|
elm_box_pack_end(hbox, bt);
|
||||||
|
evas_object_show(bt);
|
||||||
|
}
|
||||||
|
evas_object_show(hbox);
|
||||||
|
elm_box_pack_end(box, hbox);
|
||||||
|
|
||||||
evas_object_resize(win, 320, 480);
|
evas_object_resize(win, 320, 480);
|
||||||
evas_object_show(win);
|
evas_object_show(win);
|
||||||
|
|
|
@ -382,7 +382,10 @@ _efl_ui_image_async_open_done(void *data, Ecore_Thread *thread)
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
if (sd->edje)
|
if (sd->edje)
|
||||||
ok = edje_object_mmap_set(sd->img, f, key);
|
{
|
||||||
|
_prev_img_del(sd);
|
||||||
|
ok = edje_object_mmap_set(sd->img, f, key);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ok = _efl_ui_image_smart_internal_file_set
|
ok = _efl_ui_image_smart_internal_file_set
|
||||||
(sd->self, sd, file, f, key);
|
(sd->self, sd, file, f, key);
|
||||||
|
@ -904,7 +907,9 @@ _efl_ui_image_smart_internal_file_set(Eo *obj, Efl_Ui_Image_Data *sd,
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sd->preload_status != EFL_UI_IMAGE_PRELOAD_DISABLED)
|
if (sd->preload_status == EFL_UI_IMAGE_PRELOAD_DISABLED)
|
||||||
|
_prev_img_del(sd);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
evas_object_hide(sd->img);
|
evas_object_hide(sd->img);
|
||||||
sd->preload_status = EFL_UI_IMAGE_PRELOADING;
|
sd->preload_status = EFL_UI_IMAGE_PRELOADING;
|
||||||
|
@ -1989,8 +1994,13 @@ elm_image_memfile_set(Evas_Object *obj, const void *img, size_t size, const char
|
||||||
evas_object_image_memfile_set
|
evas_object_image_memfile_set
|
||||||
(sd->img, (void *)img, size, (char *)format, (char *)key);
|
(sd->img, (void *)img, size, (char *)format, (char *)key);
|
||||||
|
|
||||||
sd->preload_status = EFL_UI_IMAGE_PRELOADING;
|
if (sd->preload_status == EFL_UI_IMAGE_PRELOAD_DISABLED)
|
||||||
evas_object_image_preload(sd->img, EINA_FALSE);
|
_prev_img_del(sd);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sd->preload_status = EFL_UI_IMAGE_PRELOADING;
|
||||||
|
evas_object_image_preload(sd->img, EINA_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
err = evas_object_image_load_error_get(sd->img);
|
err = evas_object_image_load_error_get(sd->img);
|
||||||
if (err != EVAS_LOAD_ERROR_NONE)
|
if (err != EVAS_LOAD_ERROR_NONE)
|
||||||
|
|
Loading…
Reference in New Issue