evas/gl_x11, gl_cocoa: remove static variable in eng_font_draw
authorDongyeon Kim <dy5.kim@samsung.com>
Mon, 15 Jun 2015 08:48:10 +0000 (17:48 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Mon, 15 Jun 2015 08:48:11 +0000 (17:48 +0900)
Summary:
When evas is recreated, this static variable value remains,
so it references already freed memory.

Test Plan: Local tests

Reviewers: cedric, jpeg

Reviewed By: jpeg

Subscribers: wonsik, mer.kim, cedric

Differential Revision: https://phab.enlightenment.org/D2678

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_context.c
src/modules/evas/engines/gl_generic/evas_engine.c

index 4acca80..5aab2c2 100644 (file)
@@ -1035,27 +1035,25 @@ eng_font_draw(void *data, void *context, void *surface, Evas_Font_Set *font EINA
    evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
    re->win->gl_context->dc = context;
      {
-        // FIXME: put im into context so we can free it
-           static RGBA_Image *im = NULL;
-        
-        if (!im)
-          im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
-        im->cache_entry.w = re->win->gl_context->shared->w;
-        im->cache_entry.h = re->win->gl_context->shared->h;
+        if (!re->win->gl_context->font_surface)
+          re->win->gl_context->font_surface = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
+        re->win->gl_context->font_surface->cache_entry.w = re->win->gl_context->shared->w;
+        re->win->gl_context->font_surface->cache_entry.h = re->win->gl_context->shared->h;
+
         evas_common_draw_context_font_ext_set(context,
-                                             re->win->gl_context,
-                                             evas_gl_font_texture_new,
-                                             evas_gl_font_texture_free,
-                                             evas_gl_font_texture_draw,
+                                              re->win->gl_context,
+                                              evas_gl_font_texture_new,
+                                              evas_gl_font_texture_free,
+                                              evas_gl_font_texture_draw,
                                               NULL,
                                               NULL,
                                               NULL);
-           evas_common_font_draw_prepare(intl_props);
-           evas_common_font_draw(im, context, x, y, intl_props->glyphs);
-           evas_common_draw_context_font_ext_set(context,
-                                             NULL,
-                                             NULL,
-                                             NULL,
+            evas_common_font_draw_prepare(intl_props);
+            evas_common_font_draw(re->win->gl_context->font_surface, context, x, y, intl_props->glyphs);
+            evas_common_draw_context_font_ext_set(context,
+                                              NULL,
+                                              NULL,
+                                              NULL,
                                               NULL,
                                               NULL,
                                               NULL,
index 3ee8c5b..6dc673f 100644 (file)
@@ -579,6 +579,8 @@ struct _Evas_Engine_GL_Context
 
    GLuint preserve_bit;
    int gles_version;
+
+   RGBA_Image *font_surface;
 };
 
 struct _Evas_GL_Texture_Pool
index 9a1ef99..f79967a 100644 (file)
@@ -973,6 +973,9 @@ evas_gl_common_context_free(Evas_Engine_GL_Context *gc)
 
    if (gc->def_surface) evas_gl_common_image_free(gc->def_surface);
 
+   if (gc->font_surface)
+     evas_cache_image_drop(&gc->font_surface->cache_entry);
+
    if (glsym_glMapBuffer && glsym_glUnmapBuffer)
      {
         for (i = 0; i < MAX_PIPES; i++)
index 68dd9b4..ddcab2c 100644 (file)
@@ -1335,13 +1335,10 @@ eng_font_draw(void *data, void *context, void *surface, Evas_Font_Set *font EINA
    evas_gl_common_context_target_surface_set(gl_context, surface);
    gl_context->dc = context;
      {
-        // FIXME: put im into context so we can free it
-        static RGBA_Image *im = NULL;
-
-        if (!im)
-          im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
-        im->cache_entry.w = gl_context->shared->w;
-        im->cache_entry.h = gl_context->shared->h;
+        if (!gl_context->font_surface)
+          gl_context->font_surface = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
+        gl_context->font_surface->cache_entry.w = gl_context->shared->w;
+        gl_context->font_surface->cache_entry.h = gl_context->shared->h;
 
         evas_common_draw_context_font_ext_set(context,
                                               gl_context,
@@ -1352,7 +1349,7 @@ eng_font_draw(void *data, void *context, void *surface, Evas_Font_Set *font EINA
                                               evas_gl_image_free,
                                               evas_gl_image_draw);
         evas_common_font_draw_prepare(intl_props);
-        evas_common_font_draw(im, context, x, y, intl_props->glyphs);
+        evas_common_font_draw(gl_context->font_surface, context, x, y, intl_props->glyphs);
         evas_common_draw_context_font_ext_set(context,
                                               NULL,
                                               NULL,