summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-07-31 11:53:39 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-07-31 11:53:39 +0900
commite0b8e3f5e75306a37ee131f999f975dee39e8329 (patch)
treef3faef4a76638cb56c774d6ff3690bbfef2a39de
parentf2de8970a137a6291ff35e42cfbf556120337ce5 (diff)
evas: use eina_file_virtualize() in evas_object_memfile_set().
NOTE: I am tempted to mark evas_object_memfile_set() as deprecated due to the forced memcpy it introduced and the fact that it is now a 3 lines of code to do the same in a more efficient way.
Diffstat (limited to '')
-rw-r--r--ChangeLog1
-rw-r--r--NEWS1
-rw-r--r--src/lib/evas/Evas_Eo.h16
-rw-r--r--src/lib/evas/canvas/evas_object_image.c147
4 files changed, 10 insertions, 155 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e2d23460f..e072762aea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
12013-07-31 Cedric Bail 12013-07-31 Cedric Bail
2 2
3 * Eina: add eina_file_virtualize() and eina_file_virtual(). 3 * Eina: add eina_file_virtualize() and eina_file_virtual().
4 * Evas: use eina_file_virtualize() for evas_object_image_memfile_set().
4 5
52013-07-25 ChunEon Park (Hermet) 62013-07-25 ChunEon Park (Hermet)
6 7
diff --git a/NEWS b/NEWS
index 0bacd4e705..c0834591f0 100644
--- a/NEWS
+++ b/NEWS
@@ -55,6 +55,7 @@ Additions:
55 - Add multiple font draws support to engines 55 - Add multiple font draws support to engines
56 - Add Cserve2 scalecache support 56 - Add Cserve2 scalecache support
57 - Add evas_object_image_source_clip_set()/get() 57 - Add evas_object_image_source_clip_set()/get()
58 - Use eina_file_virtualize() for evas_object_image_memfile_set().
58 * Ecore_X: 59 * Ecore_X:
59 - Add window profile support. 60 - Add window profile support.
60 ECORE_X_ATOM_E_WINDOW_PROFILE_SUPPORTED 61 ECORE_X_ATOM_E_WINDOW_PROFILE_SUPPORTED
diff --git a/src/lib/evas/Evas_Eo.h b/src/lib/evas/Evas_Eo.h
index 4a6c08de54..e4b83e8034 100644
--- a/src/lib/evas/Evas_Eo.h
+++ b/src/lib/evas/Evas_Eo.h
@@ -5524,7 +5524,6 @@ extern EAPI Eo_Op EVAS_OBJ_IMAGE_BASE_ID;
5524 5524
5525enum 5525enum
5526{ 5526{
5527 EVAS_OBJ_IMAGE_SUB_ID_MEMFILE_SET,
5528 EVAS_OBJ_IMAGE_SUB_ID_FILE_SET, 5527 EVAS_OBJ_IMAGE_SUB_ID_FILE_SET,
5529 EVAS_OBJ_IMAGE_SUB_ID_MMAP_SET, 5528 EVAS_OBJ_IMAGE_SUB_ID_MMAP_SET,
5530 EVAS_OBJ_IMAGE_SUB_ID_FILE_GET, 5529 EVAS_OBJ_IMAGE_SUB_ID_FILE_GET,
@@ -5608,21 +5607,6 @@ enum
5608 */ 5607 */
5609 5608
5610/** 5609/**
5611 * @def evas_obj_image_memfile_set
5612 * @since 1.8
5613 *
5614 * Sets the data for an image from memory to be loaded
5615 *
5616 * @param[in] data in
5617 * @param[in] size in
5618 * @param[in] format in
5619 * @param[in] key in
5620 *
5621 * @see evas_object_image_memfile_set
5622 */
5623#define evas_obj_image_memfile_set(data, size, format, key) EVAS_OBJ_IMAGE_ID(EVAS_OBJ_IMAGE_SUB_ID_MEMFILE_SET), EO_TYPECHECK(void *, data), EO_TYPECHECK(int, size), EO_TYPECHECK(char *, format), EO_TYPECHECK(char *, key)
5624
5625/**
5626 * @def evas_obj_image_file_set 5610 * @def evas_obj_image_file_set
5627 * @since 1.8 5611 * @since 1.8
5628 * 5612 *
diff --git a/src/lib/evas/canvas/evas_object_image.c b/src/lib/evas/canvas/evas_object_image.c
index 41cdc93ec3..4af6bf91e4 100644
--- a/src/lib/evas/canvas/evas_object_image.c
+++ b/src/lib/evas/canvas/evas_object_image.c
@@ -64,9 +64,6 @@ struct _Evas_Object_Image_Pixels
64 } func; 64 } func;
65 65
66 Evas_Video_Surface video; 66 Evas_Video_Surface video;
67
68 const char *tmpf;
69 int tmpf_fd;
70}; 67};
71 68
72struct _Evas_Object_Image_State 69struct _Evas_Object_Image_State
@@ -181,8 +178,6 @@ static void _proxy_unset(Evas_Object *proxy, Evas_Object_Protected_Data *obj, Ev
181static void _proxy_set(Evas_Object *proxy, Evas_Object *src); 178static void _proxy_set(Evas_Object *proxy, Evas_Object *src);
182static void _proxy_error(Evas_Object *proxy, void *context, void *output, void *surface, int x, int y, Eina_Bool do_async); 179static void _proxy_error(Evas_Object *proxy, void *context, void *output, void *surface, int x, int y, Eina_Bool do_async);
183 180
184static void _cleanup_tmpf(Evas_Object *eo_obj);
185
186static const Evas_Object_Func object_func = 181static const Evas_Object_Func object_func =
187{ 182{
188 /* methods (compulsory) */ 183 /* methods (compulsory) */
@@ -214,7 +209,7 @@ static const Evas_Object_Image_Load_Opts default_load_opts = {
214}; 209};
215 210
216static const Evas_Object_Image_Pixels default_pixels = { 211static const Evas_Object_Image_Pixels default_pixels = {
217 NULL, { NULL, NULL }, { 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, NULL, -1 212 NULL, { NULL, NULL }, { 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
218}; 213};
219 214
220static const Evas_Object_Image_State default_state = { 215static const Evas_Object_Image_State default_state = {
@@ -281,7 +276,6 @@ _evas_object_image_cleanup(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj,
281 o->engine_data, 276 o->engine_data,
282 eo_obj); 277 eo_obj);
283 } 278 }
284 if (o->pixels->tmpf) _cleanup_tmpf(eo_obj);
285 if (o->cur->source) _proxy_unset(eo_obj, obj, o); 279 if (o->cur->source) _proxy_unset(eo_obj, obj, o);
286} 280}
287 281
@@ -374,139 +368,19 @@ evas_object_image_filled_add(Evas *eo_e)
374 return eo_obj; 368 return eo_obj;
375} 369}
376 370
377static void
378_cleanup_tmpf(Evas_Object *eo_obj)
379{
380#ifdef HAVE_SYS_MMAN_H
381 Evas_Object_Image *o;
382
383 o = eo_data_scope_get(eo_obj, MY_CLASS);
384 if (!o->pixels->tmpf) return;
385#ifdef __linux__
386#else
387 unlink(o->pixels->tmpf);
388#endif
389 EINA_COW_PIXEL_WRITE_BEGIN(o, pixels)
390 {
391 if (pixels->tmpf_fd >= 0) close(pixels->tmpf_fd);
392 eina_stringshare_del(pixels->tmpf);
393 pixels->tmpf_fd = -1;
394 pixels->tmpf = NULL;
395 }
396 EINA_COW_PIXEL_WRITE_END(o, pixels);
397#else
398 (void) eo_obj;
399#endif
400}
401
402static void
403_create_tmpf(Evas_Object *eo_obj, void *data, int size, char *format EINA_UNUSED)
404{
405#ifdef HAVE_SYS_MMAN_H
406 Evas_Object_Image *o;
407 char buf[PATH_MAX];
408 void *dst;
409 int fd = -1;
410
411 o = eo_data_scope_get(eo_obj, MY_CLASS);
412#ifdef __linux__
413 snprintf(buf, sizeof(buf), "/dev/shm/.evas-tmpf-%i-%p-%i-XXXXXX",
414 (int)getpid(), data, (int)size);
415 fd = mkstemp(buf);
416#endif
417 if (fd < 0)
418 {
419 const char *tmpdir = getenv("TMPDIR");
420
421 if (!tmpdir)
422 {
423 tmpdir = getenv("TMP");
424 if (!tmpdir)
425 {
426 tmpdir = getenv("TEMP");
427 if (!tmpdir) tmpdir = "/tmp";
428 }
429 }
430 snprintf(buf, sizeof(buf), "%s/.evas-tmpf-%i-%p-%i-XXXXXX",
431 tmpdir, (int)getpid(), data, (int)size);
432 fd = mkstemp(buf);
433 if (fd < 0) return;
434 }
435 if (ftruncate(fd, size) < 0)
436 {
437 unlink(buf);
438 close(fd);
439 return;
440 }
441#ifdef __linux__
442 unlink(buf);
443#endif
444
445 eina_mmap_safety_enabled_set(EINA_TRUE);
446
447 dst = mmap(NULL, size,
448 PROT_READ | PROT_WRITE,
449 MAP_SHARED,
450 fd, 0);
451 if (dst == MAP_FAILED)
452 {
453 close(fd);
454 return;
455 }
456 EINA_COW_PIXEL_WRITE_BEGIN(o, pixels)
457 pixels->tmpf_fd = fd;
458 EINA_COW_PIXEL_WRITE_END(o, pixels);
459#ifdef __linux__
460 snprintf(buf, sizeof(buf), "/proc/%li/fd/%i", (long)getpid(), fd);
461#endif
462 EINA_COW_PIXEL_WRITE_BEGIN(o, pixels)
463 pixels->tmpf = eina_stringshare_add(buf);
464 EINA_COW_PIXEL_WRITE_END(o, pixels);
465 memcpy(dst, data, size);
466 munmap(dst, size);
467#else
468 (void) eo_obj;
469 (void) data;
470 (void) size;
471 (void) format;
472#endif
473}
474
475EAPI void 371EAPI void
476evas_object_image_memfile_set(Evas_Object *eo_obj, void *data, int size, char *format, char *key) 372evas_object_image_memfile_set(Evas_Object *eo_obj, void *data, int size, char *format EINA_UNUSED, char *key)
477{ 373{
374 Eina_File *f;
375
478 MAGIC_CHECK(eo_obj, Evas_Object, MAGIC_OBJ); 376 MAGIC_CHECK(eo_obj, Evas_Object, MAGIC_OBJ);
479 return; 377 return;
480 MAGIC_CHECK_END(); 378 MAGIC_CHECK_END();
481 eo_do(eo_obj, evas_obj_image_memfile_set(data, size, format, key));
482}
483 379
484static void 380 f = eina_file_virtualize(data, size, EINA_TRUE);
485_image_memfile_set(Eo *eo_obj, void *_pd, va_list *list) 381 if (!f) return ;
486{ 382 eo_do(eo_obj, evas_obj_image_mmap_set(f, key));
487 Evas_Object_Image *o = _pd; 383 eina_file_close(f);
488
489 void *data = va_arg(*list, void *);
490 int size = va_arg(*list, int);
491 char *format = va_arg(*list, char*);
492 char *key = va_arg(*list, char*);
493
494 _cleanup_tmpf(eo_obj);
495 evas_object_image_file_set(eo_obj, NULL, NULL);
496 // invalidate the cache effectively
497 evas_object_image_alpha_set(eo_obj, !o->cur->has_alpha);
498 evas_object_image_alpha_set(eo_obj, o->cur->has_alpha);
499
500 if ((size < 1) || (!data)) return;
501
502 _create_tmpf(eo_obj, data, size, format);
503 evas_object_image_file_set(eo_obj, o->pixels->tmpf, key);
504 if (!o->engine_data)
505 {
506 ERR("unable to load '%s' from memory", o->pixels->tmpf);
507 _cleanup_tmpf(eo_obj);
508 return;
509 }
510} 384}
511 385
512static void 386static void
@@ -635,7 +509,6 @@ _image_mmap_set(Eo *eo_obj, void *_pd, va_list *list)
635 Eina_File *f = va_arg(*list, Eina_File *); 509 Eina_File *f = va_arg(*list, Eina_File *);
636 const char *key = va_arg(*list, const char*); 510 const char *key = va_arg(*list, const char*);
637 511
638 if (o->pixels->tmpf) _cleanup_tmpf(eo_obj);
639 if (o->cur->u.f == f) 512 if (o->cur->u.f == f)
640 { 513 {
641 if ((!o->cur->key) && (!key)) 514 if ((!o->cur->key) && (!key))
@@ -672,7 +545,6 @@ _image_file_set(Eo *eo_obj, void *_pd, va_list *list)
672 const char *file = va_arg(*list, const char*); 545 const char *file = va_arg(*list, const char*);
673 const char *key = va_arg(*list, const char*); 546 const char *key = va_arg(*list, const char*);
674 547
675 if ((o->pixels->tmpf) && (file != o->pixels->tmpf)) _cleanup_tmpf(eo_obj);
676 if ((o->cur->u.file) && (file) && (!strcmp(o->cur->u.file, file))) 548 if ((o->cur->u.file) && (file) && (!strcmp(o->cur->u.file, file)))
677 { 549 {
678 if ((!o->cur->key) && (!key)) 550 if ((!o->cur->key) && (!key))
@@ -3676,7 +3548,6 @@ evas_object_image_free(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj)
3676 Eina_Rectangle *r; 3548 Eina_Rectangle *r;
3677 3549
3678 /* free obj */ 3550 /* free obj */
3679 _cleanup_tmpf(eo_obj);
3680 if (o->cur->u.file && !o->cur->mmaped_source) eina_stringshare_del(o->cur->u.file); 3551 if (o->cur->u.file && !o->cur->mmaped_source) eina_stringshare_del(o->cur->u.file);
3681 if (o->cur->key) eina_stringshare_del(o->cur->key); 3552 if (o->cur->key) eina_stringshare_del(o->cur->key);
3682 if (o->cur->source) _proxy_unset(eo_obj, obj, o); 3553 if (o->cur->source) _proxy_unset(eo_obj, obj, o);
@@ -5327,7 +5198,6 @@ _class_constructor(Eo_Class *klass)
5327 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor), 5198 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
5328 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor), 5199 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
5329 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DBG_INFO_GET), _dbg_info_get), 5200 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DBG_INFO_GET), _dbg_info_get),
5330 EO_OP_FUNC(EVAS_OBJ_IMAGE_ID(EVAS_OBJ_IMAGE_SUB_ID_MEMFILE_SET), _image_memfile_set),
5331 EO_OP_FUNC(EVAS_OBJ_IMAGE_ID(EVAS_OBJ_IMAGE_SUB_ID_FILE_SET), _image_file_set), 5201 EO_OP_FUNC(EVAS_OBJ_IMAGE_ID(EVAS_OBJ_IMAGE_SUB_ID_FILE_SET), _image_file_set),
5332 EO_OP_FUNC(EVAS_OBJ_IMAGE_ID(EVAS_OBJ_IMAGE_SUB_ID_MMAP_SET), _image_mmap_set), 5202 EO_OP_FUNC(EVAS_OBJ_IMAGE_ID(EVAS_OBJ_IMAGE_SUB_ID_MMAP_SET), _image_mmap_set),
5333 EO_OP_FUNC(EVAS_OBJ_IMAGE_ID(EVAS_OBJ_IMAGE_SUB_ID_FILE_GET), _image_file_get), 5203 EO_OP_FUNC(EVAS_OBJ_IMAGE_ID(EVAS_OBJ_IMAGE_SUB_ID_FILE_GET), _image_file_get),
@@ -5406,7 +5276,6 @@ _class_constructor(Eo_Class *klass)
5406} 5276}
5407 5277
5408static const Eo_Op_Description op_desc[] = { 5278static const Eo_Op_Description op_desc[] = {
5409 EO_OP_DESCRIPTION(EVAS_OBJ_IMAGE_SUB_ID_MEMFILE_SET, "Sets the data for an image from memory to be loaded"),
5410 EO_OP_DESCRIPTION(EVAS_OBJ_IMAGE_SUB_ID_FILE_SET, "Set the source file from where an image object must fetch the real"), 5279 EO_OP_DESCRIPTION(EVAS_OBJ_IMAGE_SUB_ID_FILE_SET, "Set the source file from where an image object must fetch the real"),
5411 EO_OP_DESCRIPTION(EVAS_OBJ_IMAGE_SUB_ID_MMAP_SET, "Set the source mmaped file from where an image object must fetch the real"), 5280 EO_OP_DESCRIPTION(EVAS_OBJ_IMAGE_SUB_ID_MMAP_SET, "Set the source mmaped file from where an image object must fetch the real"),
5412 EO_OP_DESCRIPTION(EVAS_OBJ_IMAGE_SUB_ID_FILE_GET, "Retrieve the source file from where an image object is to fetch the"), 5281 EO_OP_DESCRIPTION(EVAS_OBJ_IMAGE_SUB_ID_FILE_GET, "Retrieve the source file from where an image object is to fetch the"),