evas - gl - dont allocate image and/or texture until needed on native unset
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Wed, 16 Oct 2013 08:20:14 +0000 (17:20 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Wed, 16 Oct 2013 13:56:38 +0000 (22:56 +0900)
src/modules/evas/engines/gl_cocoa/evas_engine.c
src/modules/evas/engines/gl_common/evas_gl_common.h
src/modules/evas/engines/gl_common/evas_gl_image.c
src/modules/evas/engines/gl_sdl/evas_engine.c
src/modules/evas/engines/gl_x11/evas_engine.c
src/modules/evas/engines/wayland_egl/evas_engine.c

index 83c2968..702e751 100644 (file)
@@ -453,6 +453,7 @@ eng_image_alpha_set(void *data, void *image, int has_alpha)
         
         if (!im->im->image.data)
           evas_cache_image_load_data(&im->im->cache_entry);
+        evas_gl_common_image_alloc_ensure(im);
         im_new = evas_gl_common_image_new_from_copied_data
            (im->gc, im->im->cache_entry.w, im->im->cache_entry.h, 
                im->im->image.data,
@@ -523,6 +524,7 @@ eng_image_colorspace_set(void *data, void *image, int cspace)
    /* FIXME: can move to gl_common */
    if (im->cs.space == cspace) return;
    eng_window_use(re->win);
+   evas_gl_common_image_alloc_ensure(im);
    evas_cache_image_colorspace(&im->im->cache_entry, cspace);
    switch (cspace)
      {
@@ -676,7 +678,8 @@ eng_image_size_set(void *data, void *image, int w, int h)
         w &= ~0x1;
         break;
      }
-   
+
+   evas_gl_common_image_alloc_ensure(im_old);
    if ((im_old->im) &&
        ((int)im_old->im->cache_entry.w == w) &&
        ((int)im_old->im->cache_entry.h == h))
@@ -744,6 +747,7 @@ eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data, i
      }
    eng_window_use(re->win);
    error = evas_cache_image_load_data(&im->im->cache_entry);
+   evas_gl_common_image_alloc_ensure(im);
    switch (im->cs.space)
      {
       case EVAS_COLORSPACE_ARGB8888:
@@ -795,6 +799,7 @@ eng_image_data_put(void *data, void *image, DATA32 *image_data)
    im = image;
    if (im->native.data) return image;
    eng_window_use(re->win);
+   evas_gl_common_image_alloc_ensure(im);
    if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.data))
      {
         if (im->tex->pt->dyn.data == image_data)
index def6425..df01664 100644 (file)
@@ -715,6 +715,7 @@ void              evas_gl_common_texture_nv12_update(Evas_GL_Texture *tex, DATA8
 Evas_GL_Texture  *evas_gl_common_texture_nv12tiled_new(Evas_Engine_GL_Context *gc, DATA8 **rows, unsigned int w, unsigned int h);
 void              evas_gl_common_texture_nv12tiled_update(Evas_GL_Texture *tex, DATA8 **row, unsigned int w, unsigned int h);
 
+void              evas_gl_common_image_alloc_ensure(Evas_GL_Image *im);
 void              evas_gl_common_image_all_unload(Evas_Engine_GL_Context *gc);
 
 void              evas_gl_common_image_ref(Evas_GL_Image *im);
index 769b65a..2317790 100644 (file)
@@ -1,6 +1,14 @@
 #include "evas_gl_private.h"
 
 void
+evas_gl_common_image_alloc_ensure(Evas_GL_Image *im)
+{
+   if (!im->im) return;
+   im->im = (RGBA_Image *)evas_cache_image_size_set(&im->im->cache_entry,
+                                                    im->w, im->h);
+}
+
+void
 evas_gl_common_image_all_unload(Evas_Engine_GL_Context *gc)
 {
    Eina_List *l;
@@ -332,6 +340,7 @@ evas_gl_common_image_alpha_set(Evas_GL_Image *im, int alpha)
    if (im->alpha == alpha) return im;
    im->alpha = alpha;
    if (!im->im) return im;
+   evas_gl_common_image_alloc_ensure(im);
    evas_cache_image_load_data(&im->im->cache_entry);
    im->im->cache_entry.flags.alpha = alpha ? 1 : 0;
 
@@ -395,14 +404,15 @@ evas_gl_common_image_native_disable(Evas_GL_Image *im)
         im->tex = NULL;
      }
    im->tex_only = 0;
-
    im->im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
    im->im->cache_entry.flags.alpha = im->alpha;
    im->cs.space = EVAS_COLORSPACE_ARGB8888;
    evas_cache_image_colorspace(&im->im->cache_entry, im->cs.space);
+/*
    im->im = (RGBA_Image *)evas_cache_image_size_set(&im->im->cache_entry, im->w, im->h);
    if (!im->tex)
      im->tex = evas_gl_common_texture_new(im->gc, im->im);
+ */
 }
 
 void
@@ -538,6 +548,7 @@ evas_gl_common_image_dirty(Evas_GL_Image *im, unsigned int x, unsigned int y, un
      }
    if (im->im)
      {
+        evas_gl_common_image_alloc_ensure(im);
         im->im = (RGBA_Image *)evas_cache_image_dirty(&im->im->cache_entry, x, y, w, h);
      }
    im->dirty = 1;
@@ -549,6 +560,7 @@ evas_gl_common_image_update(Evas_Engine_GL_Context *gc, Evas_GL_Image *im)
    Image_Entry *ie;
    if (!im->im) return;
    ie = (Image_Entry *)(im->im);
+   evas_gl_common_image_alloc_ensure(im);
 /*
    if ((im->cs.space == EVAS_COLORSPACE_YCBCR422P601_PL) ||
        (im->cs.space == EVAS_COLORSPACE_YCBCR422P709_PL))
@@ -716,6 +728,7 @@ evas_gl_common_image_push(Evas_Engine_GL_Context *gc, Evas_GL_Image *im,
    RECTS_CLIP_TO_RECT(nx, ny, nw, nh,
                       cx, cy, cw, ch);
    if ((nw < 1) || (nh < 1)) return;
+   if (!im->tex) return;
    if ((nx == dx) && (ny == dy) && (nw == dw) && (nh == dh))
      {
         if (yuv)
index 5c5df60..6e89f21 100644 (file)
@@ -365,6 +365,7 @@ eng_image_alpha_set(void *data EINA_UNUSED, void *image, int has_alpha)
         
         if (!im->im->image.data)
           evas_cache_image_load_data(&im->im->cache_entry);
+        evas_gl_common_image_alloc_ensure(im);
         im_new = evas_gl_common_image_new_from_copied_data(im->gc, im->im->cache_entry.w, im->im->cache_entry.h, im->im->image.data,
                                                            eng_image_alpha_get(data, image),
                                                            eng_image_colorspace_get(data, image));
@@ -414,6 +415,7 @@ eng_image_colorspace_set(void *data EINA_UNUSED, void *image, int cspace)
    if (im->native.data) return;
    /* FIXME: can move to gl_common */
    if (im->cs.space == cspace) return;
+   evas_gl_common_image_alloc_ensure(im);
    evas_cache_image_colorspace(&im->im->cache_entry, cspace);
    switch (cspace)
      {
@@ -566,6 +568,7 @@ eng_image_size_set(void *data, void *image, int w, int h)
          break;
      }
 
+   evas_gl_common_image_alloc_ensure(im_old);
    if ((im_old->im) &&
        ((int)im_old->im->cache_entry.w == w) &&
        ((int)im_old->im->cache_entry.h == h))
@@ -621,6 +624,7 @@ eng_image_data_get(void *data EINA_UNUSED, void *image, int to_write, DATA32 **i
         return im;
      }
    error = evas_cache_image_load_data(&im->im->cache_entry);
+   evas_gl_common_image_alloc_ensure(im);
    switch (im->cs.space)
      {
       case EVAS_COLORSPACE_ARGB8888:
@@ -670,6 +674,7 @@ eng_image_data_put(void *data EINA_UNUSED, void *image, DATA32 *image_data)
    if (!image) return NULL;
    im = image;
    if (im->native.data) return image;
+   evas_gl_common_image_alloc_ensure(im);
    switch (im->cs.space)
      {
       case EVAS_COLORSPACE_ARGB8888:
index cda7fe7..f1a41e5 100644 (file)
@@ -1817,6 +1817,7 @@ eng_image_alpha_set(void *data, void *image, int has_alpha)
 
         if (!im->im->image.data)
           evas_cache_image_load_data(&im->im->cache_entry);
+        evas_gl_common_image_alloc_ensure(im);
         im_new = evas_gl_common_image_new_from_copied_data
            (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
                im->im->image.data,
@@ -1888,6 +1889,7 @@ eng_image_colorspace_set(void *data, void *image, int cspace)
    /* FIXME: can move to gl_common */
    if (im->cs.space == cspace) return;
    eng_window_use(re->win);
+   evas_gl_common_image_alloc_ensure(im);
    evas_cache_image_colorspace(&im->im->cache_entry, cspace);
    switch (cspace)
      {
@@ -2633,6 +2635,7 @@ eng_image_size_set(void *data, void *image, int w, int h)
          break;
      }
 
+   evas_gl_common_image_alloc_ensure(im_old);
    if ((im_old->im) &&
        ((int)im_old->im->cache_entry.w == w) &&
        ((int)im_old->im->cache_entry.h == h))
@@ -2743,6 +2746,7 @@ eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data, i
     }
 
    error = evas_cache_image_load_data(&im->im->cache_entry);
+   evas_gl_common_image_alloc_ensure(im);
    switch (im->cs.space)
      {
       case EVAS_COLORSPACE_ARGB8888:
@@ -2797,6 +2801,7 @@ eng_image_data_put(void *data, void *image, DATA32 *image_data)
    im = image;
    if (im->native.data) return image;
    eng_window_use(re->win);
+   evas_gl_common_image_alloc_ensure(im);
    if ((im->tex) && (im->tex->pt)
        && (im->tex->pt->dyn.data)
        && (im->cs.space == EVAS_COLORSPACE_ARGB8888))
@@ -3357,6 +3362,7 @@ eng_pixel_alpha_get(void *image, int x, int y, DATA8 *alpha, int src_region_x, i
         return EINA_FALSE;
      }
 
+   evas_gl_common_image_alloc_ensure(im);
    src_w = im->im->cache_entry.w;
    src_h = im->im->cache_entry.h;
    if ((src_w == 0) || (src_h == 0))
index 28f72b0..a370825 100644 (file)
@@ -1681,6 +1681,7 @@ eng_image_size_set(void *data, void *image, int w, int h)
          break;
      }
 
+   evas_gl_common_image_alloc_ensure(im);
    if ((im_old->im) &&
        ((int)im_old->im->cache_entry.w == w) &&
        ((int)im_old->im->cache_entry.h == h))
@@ -1778,6 +1779,7 @@ eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data, i
      }
 
    error = evas_cache_image_load_data(&im->im->cache_entry);
+   evas_gl_common_image_alloc_ensure(im);
    switch (im->cs.space)
      {
       case EVAS_COLORSPACE_ARGB8888:
@@ -1832,6 +1834,7 @@ eng_image_data_put(void *data, void *image, DATA32 *image_data)
    if (!(im = image)) return NULL;
    if (im->native.data) return image;
    eng_window_use(re->win);
+   evas_gl_common_image_alloc_ensure(im);
    if ((im->tex) && (im->tex->pt)
        && (im->tex->pt->dyn.data)
        && (im->cs.space == EVAS_COLORSPACE_ARGB8888))
@@ -1959,6 +1962,7 @@ eng_image_alpha_set(void *data, void *image, int has_alpha)
 
         if (!im->im->image.data)
           evas_cache_image_load_data(&im->im->cache_entry);
+        evas_gl_common_image_alloc_ensure(im);
         im_new = evas_gl_common_image_new_from_copied_data
           (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
               im->im->image.data,
@@ -2071,6 +2075,7 @@ eng_image_colorspace_set(void *data, void *image, int cspace)
    /* FIXME: can move to gl_common */
    if (im->cs.space == cspace) return;
    eng_window_use(re->win);
+   evas_gl_common_image_alloc_ensure(im);
    evas_cache_image_colorspace(&im->im->cache_entry, cspace);
    switch (cspace)
      {
@@ -2516,6 +2521,7 @@ eng_pixel_alpha_get(void *image, int x, int y, DATA8 *alpha, int src_region_x, i
         return EINA_FALSE;
      }
 
+   evas_gl_common_image_alloc_ensure(im);
    src_w = im->im->cache_entry.w;
    src_h = im->im->cache_entry.h;
    if ((src_w == 0) || (src_h == 0))