Add EVAS_GL_DIRECT_MEM_OPT to enable on-demand fallback memory
authorSung Park <sungwoo@gmail.com>
Thu, 24 Jan 2013 04:51:51 +0000 (04:51 +0000)
committerSung Park <sungwoo@gmail.com>
Thu, 24 Jan 2013 04:51:51 +0000 (04:51 +0000)
allocation policy for EvasGL direct rendering.

Also made some variable name changes and some other minor fixes.

SVN revision: 83199

ChangeLog
NEWS
src/modules/evas/engines/gl_common/evas_gl_core.c
src/modules/evas/engines/gl_common/evas_gl_core_private.h

index 4a83dae..a1c77ad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-01-24  Sung W. Park (sung_)
+
+       * Add EVAS_GL_DIRECT_MEM_OPT to enable on-demand fallback memory
+        allocation policy for EvasGL direct rendering.
+
 2013-01-24  Cedric Bail
 
        * Don't over align data if they are already aligned.
diff --git a/NEWS b/NEWS
index 9d3dbb4..9699a5d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,7 @@ Additions:
     * evas:
      - Add ellipsis support in Evas_Object_Text.
      - Add EVAS_GL_LINE_OFFSET_HACK_DISABLE to turn off line shift correction by evas.
+     - Add EVAS_GL_DIRECT_MEM_OPT to enable on-demand fallback memory allocation policy for EvasGL direct rendering.
     * Add ecore_audio API
     * Added eina_xattr_fd_get(), eina_xattr_fd_set(),
       eina_xattr_del(), eina_xattr_fd_del(), eina_xattr_copy() and
index 6b40a96..180d4d4 100755 (executable)
@@ -1049,15 +1049,8 @@ _surface_buffers_fbo_set(EVGL_Surface *sfc, GLuint fbo)
 }
 
 static int
-_surface_buffers_create(EVGL_Engine *ee, EVGL_Surface *sfc)
+_surface_buffers_create(EVGL_Surface *sfc)
 {
-   // Set the context current with resource context/surface
-   if (!_internal_resource_make_current(ee, NULL))
-     {
-        ERR("Error doing an internal resource make current");
-        return 0;
-     }
-
    // Create buffers
    if (sfc->color_fmt)
      {
@@ -1086,26 +1079,21 @@ _surface_buffers_create(EVGL_Engine *ee, EVGL_Surface *sfc)
           }
      }
 
-   if (!ee->funcs->make_current(ee->engine_data, NULL, NULL, 0))
-     {
-        ERR("Error doing make_current(NULL, NULL).");
-        return 0;
-     }
-
    return 1; //ret;
 }
 
 
 static int
-_surface_buffers_allocate(EVGL_Engine *ee, EVGL_Surface *sfc, int w, int h)
+_surface_buffers_allocate(EVGL_Engine *ee, EVGL_Surface *sfc, int w, int h, int mc)
 {
    // Set the context current with resource context/surface
-   if (!_internal_resource_make_current(ee, NULL))
-     {
-        ERR("Error doing an internal resource make current");
-        return 0;
-     }
+   if (mc)
+      if (!_internal_resource_make_current(ee, NULL))
+        {
+           ERR("Error doing an internal resource make current");
+           return 0;
+        }
+
    // Create buffers
    if (sfc->color_fmt)
      {
@@ -1147,15 +1135,8 @@ _surface_buffers_allocate(EVGL_Engine *ee, EVGL_Surface *sfc, int w, int h)
 }
 
 static int
-_surface_buffers_destroy(EVGL_Engine *ee, EVGL_Surface *sfc)
+_surface_buffers_destroy(EVGL_Surface *sfc)
 {
-   // Set the context current with resource context/surface
-   if (!_internal_resource_make_current(ee, NULL))
-     {
-        ERR("Error doing an internal resource make current");
-        return 0;
-     }
-
    if (sfc->color_buf)
       _texture_destroy(&sfc->color_buf);
    if (sfc->depth_buf)
@@ -1171,12 +1152,6 @@ _surface_buffers_destroy(EVGL_Engine *ee, EVGL_Surface *sfc)
 #endif
      }
 
-   if (!ee->funcs->make_current(ee->engine_data, NULL, NULL, 0))
-     {
-        ERR("Error doing make_current(NULL, NULL).");
-        return 0;
-     }
-
    return 1;
 }
 
@@ -1257,7 +1232,7 @@ _internal_config_set(EVGL_Engine *ee, EVGL_Surface *sfc, Evas_GL_Config *cfg)
 static int
 _evgl_direct_renderable(EVGL_Engine *ee, EVGL_Resource *rsc, EVGL_Surface *sfc)
 {
-   if (ee->force_direct_off) return 0;
+   if (ee->direct_force_off) return 0;
    if (rsc->id != ee->main_tid) return 0;
    if (!sfc->direct_fb_opt) return 0;
    if (!rsc->direct_img_obj) return 0;
@@ -1318,7 +1293,7 @@ _evgl_not_in_pixel_get(EVGL_Engine *ee)
 
    EVGL_Context *ctx = rsc->current_ctx;
 
-   if ((!ee->force_direct_off) && (rsc->id == ee->main_tid) &&
+   if ((!ee->direct_force_off) && (rsc->id == ee->main_tid) &&
        (ctx) && (ctx->current_sfc) && (ctx->current_sfc->direct_fb_opt) &&
        (!rsc->direct_img_obj))
       return 1;
@@ -1353,7 +1328,7 @@ _evgl_direct_enabled(EVGL_Engine *ee)
 EVGL_Engine *
 evgl_engine_create(EVGL_Interface *efunc, void *engine_data)
 {
-   int direct_off = 0, debug_mode = 0;
+   int direct_mem_opt = 0, direct_off = 0, debug_mode = 0;
    char *s = NULL;
 
 
@@ -1424,11 +1399,18 @@ evgl_engine_create(EVGL_Interface *efunc, void *engine_data)
         goto error;
      }
 
+   // Check if Direct Rendering Memory Optimzation flag is on
+   // Creates resources on demand when it fallsback to fbo rendering
+   s = getenv("EVAS_GL_DIRECT_MEM_OPT");
+   if (s) direct_mem_opt = atoi(s);
+   if (direct_mem_opt == 1)
+      evgl_engine->direct_mem_opt = 1;
+
    // Check if Direct Rendering Override Force Off flag is on
    s = getenv("EVAS_GL_DIRECT_OVERRIDE_FORCE_OFF");
    if (s) direct_off = atoi(s);
    if (direct_off == 1)
-      evgl_engine->force_direct_off = 1;
+      evgl_engine->direct_force_off = 1;
 
    // Check if API Debug mode is on
    s = getenv("EVAS_GL_API_DEBUG");
@@ -1543,13 +1525,36 @@ evgl_surface_create(EVGL_Engine *ee, Evas_GL_Config *cfg, int w, int h)
         goto error;
      }
 
+   // Set the context current with resource context/surface
+   if (!_internal_resource_make_current(ee, NULL))
+     {
+        ERR("Error doing an internal resource make current");
+        return 0;
+     }
+
    // Create internal buffers
-   if (!_surface_buffers_create(ee, sfc))
+   if (!_surface_buffers_create(sfc))
      {
         ERR("Unable Create Specificed Surfaces.");
         goto error;
      };
 
+   // Allocate resources for fallback unless the flag is on
+   if (!ee->direct_mem_opt)
+     {
+        if (!_surface_buffers_allocate(ee, sfc, sfc->w, sfc->h, 0))
+          {
+             ERR("Unable Create Allocate Memory for Surface.");
+             goto error;
+          }
+     }
+
+   if (!ee->funcs->make_current(ee->engine_data, NULL, NULL, 0))
+     {
+        ERR("Error doing make_current(NULL, NULL).");
+        return 0;
+     }
+
    // Keep track of all the created surfaces
    ee->surfaces = eina_list_prepend(ee->surfaces, sfc);
 
@@ -1595,13 +1600,26 @@ evgl_surface_destroy(EVGL_Engine *ee, EVGL_Surface *sfc)
         evgl_make_current(ee, NULL, NULL);
      }
 
+   // Set the context current with resource context/surface
+   if (!_internal_resource_make_current(ee, NULL))
+     {
+        ERR("Error doing an internal resource make current");
+        return 0;
+     }
+
    // Destroy created buffers
-   if (!_surface_buffers_destroy(ee, sfc))
+   if (!_surface_buffers_destroy(sfc))
      {
         ERR("Error deleting surface resources.");
         return 0;
      }
 
+   if (!ee->funcs->make_current(ee->engine_data, NULL, NULL, 0))
+     {
+        ERR("Error doing make_current(NULL, NULL).");
+        return 0;
+     }
+
    // Remove it from the list
    ee->surfaces = eina_list_remove(ee->surfaces, sfc);
 
@@ -1734,31 +1752,35 @@ evgl_make_current(EVGL_Engine *ee, EVGL_Surface *sfc, EVGL_Context *ctx)
      }
 
 
-   // Allocate or free resources depending on what mode it's running.
-   if (_evgl_direct_renderable(ee, rsc, sfc))
+   // Allocate or free resources depending on what mode (direct of fbo) it's
+   // running only if the env var EVAS_GL_DIRECT_MEM_OPT is set.
+   if (ee->direct_mem_opt)
      {
-        // Destroy created resources
-        if (sfc->buffers_allocated)
+        if (_evgl_direct_renderable(ee, rsc, sfc))
           {
-             if (!_surface_buffers_allocate(ee, sfc, 0, 0))
+             // Destroy created resources
+             if (sfc->buffers_allocated)
                {
-                  ERR("Unable to destroy surface buffers!");
-                  return 0;
-               };
-             sfc->buffers_allocated = 0;
+                  if (!_surface_buffers_allocate(ee, sfc, 0, 0, 1))
+                    {
+                       ERR("Unable to destroy surface buffers!");
+                       return 0;
+                    };
+                  sfc->buffers_allocated = 0;
+               }
           }
-     }
-   else
-     {
-        // Create internal buffers if not yet created
-        if (!sfc->buffers_allocated)
+        else
           {
-             if (!_surface_buffers_allocate(ee, sfc, sfc->w, sfc->h))
+             // Create internal buffers if not yet created
+             if (!sfc->buffers_allocated)
                {
-                  ERR("Unable Create Specificed Surfaces.  Unsupported format!");
-                  return 0;
-               };
-             sfc->buffers_allocated = 1;
+                  if (!_surface_buffers_allocate(ee, sfc, sfc->w, sfc->h, 1))
+                    {
+                       ERR("Unable Create Specificed Surfaces.  Unsupported format!");
+                       return 0;
+                    };
+                  sfc->buffers_allocated = 1;
+               }
           }
      }
 
index 77d4d07..62c1da4 100755 (executable)
@@ -240,10 +240,11 @@ struct _EVGL_Engine
 
 
    int                direct_override;
+   int                direct_mem_opt;
    int                api_debug_mode;
 
    // Force Off fo Debug purposes
-   int                force_direct_off;
+   int                direct_force_off;
 
    // Keep track of all the current surfaces/contexts
    Eina_List         *surfaces;