cedric pushed a commit to branch master.

commit e60baa006101c323193d694b34beeacff82e45ba
Author: Cedric Bail <[email protected]>
Date:   Fri Aug 2 10:25:26 2013 +0900

    evas: change mapping policy to be less agressive into loading file in 
memory.
    
    Should fix T271.
---
 ChangeLog                                          |  7 ++++-
 NEWS                                               |  1 +
 src/modules/evas/loaders/bmp/evas_image_load_bmp.c |  2 +-
 src/modules/evas/loaders/gif/evas_image_load_gif.c |  8 ++---
 src/modules/evas/loaders/ico/evas_image_load_ico.c |  4 +--
 .../evas/loaders/jpeg/evas_image_load_jpeg.c       |  2 +-
 .../evas/loaders/pmaps/evas_image_load_pmaps.c     | 10 +++----
 src/modules/evas/loaders/png/evas_image_load_png.c |  2 +-
 src/modules/evas/loaders/psd/evas_image_load_psd.c |  2 +-
 src/modules/evas/loaders/tga/evas_image_load_tga.c |  2 +-
 .../evas/loaders/tiff/evas_image_load_tiff.c       | 35 ++++++++++++++--------
 .../evas/loaders/wbmp/evas_image_load_wbmp.c       |  2 +-
 .../evas/loaders/webp/evas_image_load_webp.c       |  2 +-
 src/modules/evas/loaders/xpm/evas_image_load_xpm.c |  4 +--
 14 files changed, 50 insertions(+), 33 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0c2c627..4cd2a4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
+2013-08-02  Cedric Bail
+
+        * Evas: change mapping policy for image loader (RANDOM during header,
+        SEQUENTIAL or WILLNEED during pixels reading).
+
 2013-08-01  Cedric Bail
 
-       * Edje: faster load time for Edje_Object using Evas_Object_Textblocks 
and many styles.
+        * Edje: faster load time for Edje_Object using Evas_Object_Textblocks 
and many styles.
 
 2013-07-31  Carsten Haitzler (The Rasterman)
 
diff --git a/NEWS b/NEWS
index a1dfab0..bbbdc06 100644
--- a/NEWS
+++ b/NEWS
@@ -57,6 +57,7 @@ Additions:
      - Add Cserve2 scalecache support
      - Add evas_object_image_source_clip_set()/get()
      - Use eina_file_virtualize() for evas_object_image_memfile_set().
+     - Change mapping policy for image loader.
     * Ecore_X:
      - Add window profile support.
        ECORE_X_ATOM_E_WINDOW_PROFILE_SUPPORTED
diff --git a/src/modules/evas/loaders/bmp/evas_image_load_bmp.c 
b/src/modules/evas/loaders/bmp/evas_image_load_bmp.c
index ed2037b..d54cfdc 100644
--- a/src/modules/evas/loaders/bmp/evas_image_load_bmp.c
+++ b/src/modules/evas/loaders/bmp/evas_image_load_bmp.c
@@ -344,7 +344,7 @@ evas_image_load_file_head_bmp(void *loader_data,
    fsize = eina_file_size_get(f);
    if (fsize < 2) goto close_file;
 
-   map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!map) goto close_file;
 
    memset(&header, 0, sizeof (header));
diff --git a/src/modules/evas/loaders/gif/evas_image_load_gif.c 
b/src/modules/evas/loaders/gif/evas_image_load_gif.c
index fb186ef..6c2c634 100644
--- a/src/modules/evas/loaders/gif/evas_image_load_gif.c
+++ b/src/modules/evas/loaders/gif/evas_image_load_gif.c
@@ -615,7 +615,7 @@ evas_image_load_file_head_gif(void *loader_data,
    prop->h = 0;
    a = 0;
 
-   egi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   egi.map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!egi.map)
      {
         *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
@@ -762,7 +762,7 @@ evas_image_load_specific_frame(Eina_File *f,
    Evas_GIF_Info      egi;
    Eina_Bool          r = EINA_FALSE;
 
-   egi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   egi.map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!egi.map)
      {
         *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
@@ -869,7 +869,7 @@ evas_image_load_file_data_gif(void *loader_data,
              GifFileType  *gif = NULL;
              Eina_Bool     r = EINA_FALSE;
 
-             egi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+             egi.map = eina_file_map_all(f, EINA_FILE_RANDOM);
              if (!egi.map)
                {
                   *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
@@ -951,7 +951,7 @@ evas_image_load_frame_duration_gif(void *loader_data,
    if ((start_frame + frame_num) > frame_count) return -1;
    if (frame_num < 0) return -1;
 
-   egi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   egi.map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!egi.map) goto on_error;
    egi.length = eina_file_size_get(f);
    egi.position = 0;        
diff --git a/src/modules/evas/loaders/ico/evas_image_load_ico.c 
b/src/modules/evas/loaders/ico/evas_image_load_ico.c
index 5e54dbe..a90d3e2 100644
--- a/src/modules/evas/loaders/ico/evas_image_load_ico.c
+++ b/src/modules/evas/loaders/ico/evas_image_load_ico.c
@@ -151,7 +151,7 @@ evas_image_load_file_head_ico(void *loader_data,
    fsize = eina_file_size_get(f);
    if (fsize < (6 + 16 + 40)) goto close_file;
 
-   map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!map) goto close_file;
 
    // key:
@@ -381,7 +381,7 @@ evas_image_load_file_data_ico(void *loader_data,
    fsize = eina_file_size_get(f);
    if (fsize < (6 + 16 + 40)) goto close_file;
 
-   map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!map) goto close_file;
 
    // key:
diff --git a/src/modules/evas/loaders/jpeg/evas_image_load_jpeg.c 
b/src/modules/evas/loaders/jpeg/evas_image_load_jpeg.c
index 60de55a..11df6e7 100644
--- a/src/modules/evas/loaders/jpeg/evas_image_load_jpeg.c
+++ b/src/modules/evas/loaders/jpeg/evas_image_load_jpeg.c
@@ -1306,7 +1306,7 @@ evas_image_load_file_head_jpeg(void *loader_data,
    opts = loader->opts;
    f = loader->f;
 
-   map = eina_file_map_all(f, EINA_FILE_WILLNEED);
+   map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!map)
      {
        *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
diff --git a/src/modules/evas/loaders/pmaps/evas_image_load_pmaps.c 
b/src/modules/evas/loaders/pmaps/evas_image_load_pmaps.c
index 62551e5..50d1226 100644
--- a/src/modules/evas/loaders/pmaps/evas_image_load_pmaps.c
+++ b/src/modules/evas/loaders/pmaps/evas_image_load_pmaps.c
@@ -41,7 +41,7 @@ struct Pmaps_Buffer
 };
 
 /* internal used functions */
-static Eina_Bool pmaps_buffer_open(Pmaps_Buffer *b, Eina_File *f, int *error);
+static Eina_Bool pmaps_buffer_open(Pmaps_Buffer *b, Eina_File *f, Eina_Bool 
header, int *error);
 static void pmaps_buffer_close(Pmaps_Buffer *b);
 static Eina_Bool pmaps_buffer_header_parse(Pmaps_Buffer *b, int *error);
 static int pmaps_buffer_plain_int_get(Pmaps_Buffer *b, int *val);
@@ -77,7 +77,7 @@ evas_image_load_file_head_pmaps(void *loader_data,
    Eina_File *f = loader_data;
    Pmaps_Buffer b;
 
-   if (!pmaps_buffer_open(&b, f, error))
+   if (!pmaps_buffer_open(&b, f, EINA_TRUE, error))
      {
        pmaps_buffer_close(&b);
        return EINA_FALSE;
@@ -109,7 +109,7 @@ evas_image_load_file_data_pmaps(void *loader_data,
    DATA32 *ptr;
    Eina_Bool r = EINA_FALSE;
 
-   if (!pmaps_buffer_open(&b, f, error))
+   if (!pmaps_buffer_open(&b, f, EINA_FALSE, error))
      goto on_error;
 
    if (!pmaps_buffer_header_parse(&b, error))
@@ -161,12 +161,12 @@ evas_image_load_file_data_pmaps(void *loader_data,
 
 /* internal used functions */
 static Eina_Bool
-pmaps_buffer_open(Pmaps_Buffer *b, Eina_File *f, int *error)
+pmaps_buffer_open(Pmaps_Buffer *b, Eina_File *f, Eina_Bool header, int *error)
 {
    size_t len;
 
    b->file = f;
-   b->map = eina_file_map_all(b->file, EINA_FILE_SEQUENTIAL);
+   b->map = eina_file_map_all(b->file, header ? EINA_FILE_RANDOM : 
EINA_FILE_SEQUENTIAL);
    if (!b->map)
      {
         *error = EVAS_LOAD_ERROR_DOES_NOT_EXIST;
diff --git a/src/modules/evas/loaders/png/evas_image_load_png.c 
b/src/modules/evas/loaders/png/evas_image_load_png.c
index eef8385..fb19ac2 100644
--- a/src/modules/evas/loaders/png/evas_image_load_png.c
+++ b/src/modules/evas/loaders/png/evas_image_load_png.c
@@ -90,7 +90,7 @@ evas_image_load_file_head_png(void *loader_data,
    f = loader->f;
 
    hasa = 0;
-   epi.map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   epi.map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!epi.map)
      {
         *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
diff --git a/src/modules/evas/loaders/psd/evas_image_load_psd.c 
b/src/modules/evas/loaders/psd/evas_image_load_psd.c
index e553196..c183b52 100644
--- a/src/modules/evas/loaders/psd/evas_image_load_psd.c
+++ b/src/modules/evas/loaders/psd/evas_image_load_psd.c
@@ -175,7 +175,7 @@ evas_image_load_file_head_psd(void *loader_data,
 
    *error = EVAS_LOAD_ERROR_NONE;
 
-   map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   map = eina_file_map_all(f, EINA_FILE_RANDOM);
    length = eina_file_size_get(f);
    position = 0;
    if (!map || length < 1)
diff --git a/src/modules/evas/loaders/tga/evas_image_load_tga.c 
b/src/modules/evas/loaders/tga/evas_image_load_tga.c
index 6c022dc..08e639a 100644
--- a/src/modules/evas/loaders/tga/evas_image_load_tga.c
+++ b/src/modules/evas/loaders/tga/evas_image_load_tga.c
@@ -87,7 +87,7 @@ evas_image_load_file_head_tga(void *loader_data,
    *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
    if (eina_file_size_get(f) < (off_t)(sizeof(tga_header) + 
sizeof(tga_footer)))
       goto close_file;
-   seg = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   seg = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (seg == NULL) goto close_file;
    filedata = seg;
 
diff --git a/src/modules/evas/loaders/tiff/evas_image_load_tiff.c 
b/src/modules/evas/loaders/tiff/evas_image_load_tiff.c
index b170fe6..943c3e7 100644
--- a/src/modules/evas/loaders/tiff/evas_image_load_tiff.c
+++ b/src/modules/evas/loaders/tiff/evas_image_load_tiff.c
@@ -27,6 +27,7 @@ static int _evas_loader_tiff_log_dom = -1;
 #define INF(...) EINA_LOG_DOM_INFO(_evas_loader_tiff_log_dom, __VA_ARGS__)
 
 typedef struct TIFFRGBAImage_Extra TIFFRGBAImage_Extra;
+typedef struct TIFFRGBAMap TIFFRGBAMap;
 
 struct TIFFRGBAImage_Extra {
    TIFFRGBAImage       rgba;
@@ -35,6 +36,11 @@ struct TIFFRGBAImage_Extra {
    uint32              py;
 };
 
+struct TIFFRGBAMap {
+   tdata_t mem;
+   toff_t size;
+};
+
 static tsize_t
 _evas_tiff_RWProc(thandle_t handle EINA_UNUSED,
                   tdata_t data EINA_UNUSED,
@@ -60,28 +66,25 @@ _evas_tiff_CloseProc(thandle_t handle EINA_UNUSED)
 static toff_t
 _evas_tiff_SizeProc(thandle_t handle)
 {
-   Eina_File *f = (Eina_File *) handle;
+   TIFFRGBAMap *map = (TIFFRGBAMap*) handle;
 
-   return eina_file_size_get(f);
+   return map->size;
 }
 
 static int
 _evas_tiff_MapProc(thandle_t handle, tdata_t *mem, toff_t *size)
 {
-   Eina_File *f = (Eina_File *) handle;
+   TIFFRGBAMap *map = (TIFFRGBAMap*) handle;
 
-   *mem = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
-   *size = eina_file_size_get(f);
+   *mem = map->mem;
+   *size = map->size;
 
    return 1;
 }
 
 static void
-_evas_tiff_UnmapProc(thandle_t handle, tdata_t data, toff_t size EINA_UNUSED)
+_evas_tiff_UnmapProc(thandle_t handle EINA_UNUSED, tdata_t data EINA_UNUSED, 
toff_t size EINA_UNUSED)
 {
-   Eina_File *f = (Eina_File *) handle;
-
-   eina_file_map_free(f, data);
 }
 
 static void *
@@ -106,12 +109,13 @@ evas_image_load_file_head_tiff(void *loader_data,
    Eina_File *f = loader_data;
    char           txt[1024];
    TIFFRGBAImage  tiff_image;
+   TIFFRGBAMap    tiff_map;
    TIFF          *tif = NULL;
    unsigned char *map;
    uint16         magic_number;
    Eina_Bool      r = EINA_FALSE;
 
-   map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!map || eina_file_size_get(f) < 3)
      {
         *error = EVAS_LOAD_ERROR_UNKNOWN_FORMAT;
@@ -127,7 +131,10 @@ evas_image_load_file_head_tiff(void *loader_data,
         goto on_error;
      }
 
-   tif = TIFFClientOpen("evas", "rM", f,
+   tiff_map.mem = map;
+   tiff_map.size = eina_file_size_get(f);
+
+   tif = TIFFClientOpen("evas", "rM", &tiff_map,
                         _evas_tiff_RWProc, _evas_tiff_RWProc,
                         _evas_tiff_SeekProc, _evas_tiff_CloseProc,
                         _evas_tiff_SizeProc,
@@ -186,6 +193,7 @@ evas_image_load_file_data_tiff(void *loader_data,
    Eina_File          *f = loader_data;
    char                txt[1024];
    TIFFRGBAImage_Extra rgba_image;
+   TIFFRGBAMap         rgba_map;
    TIFF               *tif = NULL;
    unsigned char      *map;
    uint32             *rast = NULL;
@@ -210,7 +218,10 @@ evas_image_load_file_data_tiff(void *loader_data,
         goto on_error;
      }
 
-   tif = TIFFClientOpen("evas", "rM", f,
+   rgba_map.mem = map;
+   rgba_map.size = eina_file_size_get(f);
+
+   tif = TIFFClientOpen("evas", "rM", &rgba_map,
                         _evas_tiff_RWProc, _evas_tiff_RWProc,
                         _evas_tiff_SeekProc, _evas_tiff_CloseProc,
                         _evas_tiff_SizeProc,
diff --git a/src/modules/evas/loaders/wbmp/evas_image_load_wbmp.c 
b/src/modules/evas/loaders/wbmp/evas_image_load_wbmp.c
index 1bfc5ae..70c5078 100644
--- a/src/modules/evas/loaders/wbmp/evas_image_load_wbmp.c
+++ b/src/modules/evas/loaders/wbmp/evas_image_load_wbmp.c
@@ -59,7 +59,7 @@ evas_image_load_file_head_wbmp(void *loader_data,
    length = eina_file_size_get(f);
    if (length <= 4) goto bail;
 
-   map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   map = eina_file_map_all(f, EINA_FILE_RANDOM);
    if (!map) goto bail;
 
    if (read_mb(&type, map, length, &position) < 0) goto bail;
diff --git a/src/modules/evas/loaders/webp/evas_image_load_webp.c 
b/src/modules/evas/loaders/webp/evas_image_load_webp.c
index 36a6aa3..50f52d0 100644
--- a/src/modules/evas/loaders/webp/evas_image_load_webp.c
+++ b/src/modules/evas/loaders/webp/evas_image_load_webp.c
@@ -65,7 +65,7 @@ evas_image_load_file_head_webp(void *loader_data,
 
    *error = EVAS_LOAD_ERROR_NONE;
 
-   data = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   data = eina_file_map_all(f, EINA_FILE_RANDOM);
 
    r = evas_image_load_file_check(f, data,
                                  &prop->w, &prop->h, &prop->alpha,
diff --git a/src/modules/evas/loaders/xpm/evas_image_load_xpm.c 
b/src/modules/evas/loaders/xpm/evas_image_load_xpm.c
index b340191..2c8ec96 100644
--- a/src/modules/evas/loaders/xpm/evas_image_load_xpm.c
+++ b/src/modules/evas/loaders/xpm/evas_image_load_xpm.c
@@ -172,7 +172,7 @@ evas_image_load_file_xpm(Eina_File *f, Evas_Image_Property 
*prop, void *pixels,
         goto on_error;
      }
 
-   map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   map = eina_file_map_all(f, load_data ? EINA_FILE_WILLNEED : 
EINA_FILE_RANDOM);
    if (!map)
      {
         ERR("XPM ERROR: file failed to mmap");
@@ -712,7 +712,7 @@ module_open(Evas_Module *em)
    if (!rgb_txt) rgb_txt = eina_file_open("/usr/X11R6/lib/X11/rgb.txt", 0);
    if (!rgb_txt) rgb_txt = eina_file_open("/usr/openwin/lib/X11/rgb.txt", 0);
    if (rgb_txt)
-     rgb_txt_map = eina_file_map_all(rgb_txt, EINA_FILE_SEQUENTIAL);
+     rgb_txt_map = eina_file_map_all(rgb_txt, EINA_FILE_WILLNEED);
    em->functions = (void *)(&evas_image_load_xpm_func);
    return 1;
 }

-- 

------------------------------------------------------------------------------
Get your SQL database under version control now!
Version control is standard for application code, but databases havent 
caught up. So what steps can you take to put your SQL databases under 
version control? Why should you start doing it? Read more to find out.
http://pubads.g.doubleclick.net/gampad/clk?id=49501711&iu=/4140/ostg.clktrk

Reply via email to