summaryrefslogtreecommitdiff
path: root/src/lib/evas/common
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-08-28 17:16:48 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-08-28 17:17:35 +0900
commitebdc7a99523af6c6ef3362ab258e2fd7d7602807 (patch)
tree87775772f7ee2793363cca3f5012ef8bde47df4a /src/lib/evas/common
parent175335ae085b2c0a6dffe05a56baeb6d159bb593 (diff)
evas: use mmap/munmap on system that have it for image data.
Diffstat (limited to 'src/lib/evas/common')
-rw-r--r--src/lib/evas/common/evas_image_main.c91
1 files changed, 82 insertions, 9 deletions
diff --git a/src/lib/evas/common/evas_image_main.c b/src/lib/evas/common/evas_image_main.c
index 56b8c373c3..48a895fd53 100644
--- a/src/lib/evas/common/evas_image_main.c
+++ b/src/lib/evas/common/evas_image_main.c
@@ -2,6 +2,10 @@
2# include "config.h" /* so that EAPI in Eet.h is correctly defined */ 2# include "config.h" /* so that EAPI in Eet.h is correctly defined */
3#endif 3#endif
4 4
5#ifdef HAVE_SYS_MMAN_H
6# include <sys/mman.h>
7#endif
8
5#ifdef BUILD_LOADER_EET 9#ifdef BUILD_LOADER_EET
6# include <Eet.h> 10# include <Eet.h>
7#endif 11#endif
@@ -105,6 +109,69 @@ static const Evas_Cache2_Image_Func _evas_common_image_func2 =
105}; 109};
106#endif 110#endif
107 111
112static inline size_t
113_evas_common_rgba_image_surface_size(unsigned int w, unsigned int h, Eina_Bool alpha_only)
114{
115#define PAGE_SIZE (4 * 1024)
116#ifdef HAVE_SYS_MMAN_H
117# define ALIGN_TO_PAGE(Siz) (((Siz / PAGE_SIZE) + (Siz % PAGE_SIZE ? 1 : 0)) * PAGE_SIZE)
118#else
119# define ALIGN_TO_PAGE(Siz) Siz
120#endif
121 size_t siz;
122
123 if (alpha_only)
124 siz = w * h * sizeof(DATA8);
125 else
126 siz = w * h * sizeof(DATA32);
127
128 if (siz < PAGE_SIZE) return siz;
129
130 return ALIGN_TO_PAGE(siz);
131
132#undef ALIGN_TO_PAGE
133}
134
135static void *
136_evas_common_rgba_image_surface_mmap(unsigned int w, unsigned int h, Eina_Bool alpha_only)
137{
138 size_t siz;
139 void *r;
140
141 siz = _evas_common_rgba_image_surface_size(w, h, alpha_only);
142
143#ifdef HAVE_SYS_MMAN_H
144 if (siz < PAGE_SIZE)
145 return malloc(siz);
146
147 r = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
148 if (r == MAP_FAILED)
149 r = mmap(NULL, siz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
150 if (r == MAP_FAILED)
151 r = NULL;
152
153 return r;
154#else
155 return malloc(siz);
156#endif
157}
158
159static void
160_evas_common_rgba_image_surface_munmap(void *data, unsigned int w, unsigned int h, Eina_Bool alpha_only)
161{
162#ifdef HAVE_SYS_MMAN_H
163 size_t siz;
164
165 siz = _evas_common_rgba_image_surface_size(w, h, alpha_only);
166 if (siz < PAGE_SIZE)
167 free(data);
168 else
169 munmap(data, siz);
170#else
171 free(data);
172#endif
173}
174
108EAPI void 175EAPI void
109evas_common_image_init(void) 176evas_common_image_init(void)
110{ 177{
@@ -305,7 +372,9 @@ evas_common_rgba_image_unload(Image_Entry *ie)
305 372
306 if (im->image.data && !im->image.no_free) 373 if (im->image.data && !im->image.no_free)
307 { 374 {
308 free(im->image.data); 375 _evas_common_rgba_image_surface_munmap(im->image.data,
376 ie->allocated.w, ie->allocated.h,
377 (im->flags & RGBA_IMAGE_ALPHA_ONLY));
309#ifdef SURFDBG 378#ifdef SURFDBG
310 surfs = eina_list_remove(surfs, ie); 379 surfs = eina_list_remove(surfs, ie);
311#endif 380#endif
@@ -373,19 +442,18 @@ _evas_common_rgba_image_surface_alloc(Image_Entry *ie, unsigned int w, unsigned
373#endif 442#endif
374 if (im->image.no_free) return 0; 443 if (im->image.no_free) return 0;
375 444
376 if (im->flags & RGBA_IMAGE_ALPHA_ONLY) 445 siz = _evas_common_rgba_image_surface_size(w, h, (im->flags & RGBA_IMAGE_ALPHA_ONLY));
377 siz = w * h * sizeof(DATA8);
378 else
379 siz = w * h * sizeof(DATA32);
380 446
381 if (im->image.data) 447 if (im->image.data)
382 { 448 {
383 free(im->image.data); 449 _evas_common_rgba_image_surface_munmap(im->image.data,
450 ie->allocated.w, ie->allocated.h,
451 (im->flags & RGBA_IMAGE_ALPHA_ONLY));
384#ifdef SURFDBG 452#ifdef SURFDBG
385 surfs = eina_list_remove(surfs, ie); 453 surfs = eina_list_remove(surfs, ie);
386#endif 454#endif
387 } 455 }
388 im->image.data = malloc(siz); 456 im->image.data = _evas_common_rgba_image_surface_mmap(w, h, (im->flags & RGBA_IMAGE_ALPHA_ONLY));
389 if (!im->image.data) return -1; 457 if (!im->image.data) return -1;
390 ie->allocated.w = w; 458 ie->allocated.w = w;
391 ie->allocated.h = h; 459 ie->allocated.h = h;
@@ -439,7 +507,9 @@ _evas_common_rgba_image_surface_delete(Image_Entry *ie)
439 507
440 if (im->image.data && !im->image.no_free) 508 if (im->image.data && !im->image.no_free)
441 { 509 {
442 free(im->image.data); 510 _evas_common_rgba_image_surface_munmap(im->image.data,
511 ie->allocated.w, ie->allocated.h,
512 (im->flags & RGBA_IMAGE_ALPHA_ONLY));
443#ifdef SURFDBG 513#ifdef SURFDBG
444 surfs = eina_list_remove(surfs, ie); 514 surfs = eina_list_remove(surfs, ie);
445#endif 515#endif
@@ -682,7 +752,10 @@ evas_common_image_colorspace_normalize(RGBA_Image *im)
682#endif 752#endif
683 if (!im->image.no_free) 753 if (!im->image.no_free)
684 { 754 {
685 free(im->image.data); 755 _evas_common_rgba_image_surface_munmap(im->image.data,
756 im->cache_entry.allocated.w,
757 im->cache_entry.allocated.h,
758 (im->flags & RGBA_IMAGE_ALPHA_ONLY));
686#ifdef SURFDBG 759#ifdef SURFDBG
687 surfs = eina_list_remove(surfs, im); 760 surfs = eina_list_remove(surfs, im);
688#endif 761#endif