Revert "EvasGL: Fixed a few minor bugs."
authorWooHyun Jung <wh0705.jung@samsung.com>
Fri, 27 Jul 2012 02:32:01 +0000 (11:32 +0900)
committerWooHyun Jung <wh0705.jung@samsung.com>
Fri, 27 Jul 2012 02:32:01 +0000 (11:32 +0900)
This reverts commit e65f349eb8809068b2ff8e5bcb4dc81b3724d727.

src/lib/canvas/evas_gl.c
src/modules/engines/gl_x11/evas_engine.c

index 60255a2..bccab2d 100644 (file)
@@ -100,12 +100,6 @@ evas_gl_surface_create(Evas_GL *evas_gl, Evas_GL_Config *config, int width, int
         return NULL;
      }
 
-   if ( (width <= 0) || (height <= 0))
-     {
-        ERR("Invalid surface dimensions: %d, %d", width, height);
-        return NULL;
-     }
-
    surf = calloc(1, sizeof(Evas_GL_Surface));
 
    if (!surf) return NULL;
@@ -227,15 +221,10 @@ evas_gl_make_current(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_GL_Context *c
    return EINA_FALSE;
    MAGIC_CHECK_END();
 
-   if ((surf) && (ctx))
-     ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, surf->data, ctx->data);
-   else if ((!surf) && (!ctx))
+   if ((!surf) || (!ctx))
      ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, NULL, NULL);
    else
-     {
-        ERR("Bad match between surface: %p and context: %p", surf, ctx);
-        return EINA_FALSE;
-     }
+     ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, surf->data, ctx->data);
 
    return ret;
 }
index 93347ee..4739730 100755 (executable)
@@ -77,10 +77,10 @@ struct _Render_Engine_GL_Surface
    int      stencil_bits;
 
    int      direct_fb_opt;
-   int      multisample_bits;
+   int         multiample_bits;
 
    // Render target Texture/Buffers
-   GLint    rt_msaa_samples;
+   GLint       rt_msaa_samples;
 
    GLuint   rt_tex;
    GLint    rt_internal_fmt;
@@ -146,9 +146,8 @@ static Render_Engine_GL_Context *current_evgl_ctx = NULL;
 static Render_Engine *current_engine = NULL;
 static Evas_Object *gl_direct_img_obj = NULL;
 
-static int  _ext_initted = 0;
-static char *_gl_ext_string = NULL;
-static char *_evasgl_ext_string = NULL;
+static char _gl_ext_string[1024];
+static char _evasgl_ext_string[1024];
 
 // Resource context/surface per Thread in TLS for evasgl use
 static Eina_TLS   resource_key;
@@ -465,6 +464,7 @@ _gl_ext_sym_init(void)
    //----------- GLES 2.0 Extensions ------------//
    // If the symbol's not found, they get set to NULL
    // If one of the functions in the extension exists, the extension in supported
+
    /* GL_OES_get_program_binary */
    FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinary", glsym_func_void);
    FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinaryEXT", glsym_func_void);
@@ -614,26 +614,15 @@ _gl_ext_sym_init(void)
 static void
 _gl_ext_init(Render_Engine *re)
 {
-   int i, ext_len = 0;
+   int i;
    const char *glexts, *evasglexts;
 
+   memset(_gl_ext_string, 0, 1024);
+   memset(_evasgl_ext_string, 0, 1024);
+
    // GLES 2.0 Extensions
    glexts = (const char*)glGetString(GL_EXTENSIONS);
 
-   ext_len = strlen(glexts);
-   if (!ext_len)
-     {
-        DBG("GL Get Extension string NULL: No extensions supported");
-        return;
-     }
-
-   _gl_ext_string = calloc(1, sizeof(char) * ext_len * 2);
-   if (!_gl_ext_string)
-     {
-        ERR("Error allocating _gl_ext_string.");
-        return;
-     }
-
    DBG("--------GLES 2.0 Extensions--------");
    for (i = 0; _gl_ext_entries[i].name != NULL; i++)
      {
@@ -660,20 +649,6 @@ _gl_ext_init(Render_Engine *re)
         evasglexts = glXQueryExtensionsString(re->info->info.display,
                                               re->info->info.screen);
 #endif
-        ext_len = strlen(evasglexts);
-
-        if (!ext_len)
-          {
-             DBG("GL Get Extension string NULL: No extensions supported");
-             return;
-          }
-
-        _evasgl_ext_string = calloc(1, sizeof(char) * ext_len * 2);
-        if (!_evasgl_ext_string)
-          {
-             ERR("Error allocating _evasgl_ext_string.");
-             return;
-          }
 
         DBG("--------EvasGL Supported Extensions----------");
         for (i = 0; _evasgl_ext_entries[i].name != NULL; i++)
@@ -924,19 +899,6 @@ _destroy_internal_glue_resources(void *data)
    eina_tls_free(resource_key);
 #endif
 
-   // Free the extension strings
-   if (_ext_initted)
-     {
-        if (_gl_ext_string)
-           free(_gl_ext_string);
-        if (_evasgl_ext_string)
-           free(_evasgl_ext_string);
-
-        _gl_ext_string = NULL;
-        _evasgl_ext_string = NULL;
-        _ext_initted = 0;
-     }
-
    return 1;
 }
 
@@ -1149,13 +1111,8 @@ eng_setup(Evas *e, void *in)
    eng_window_use(re->win);
 
    re->vsync = 0;
-
-   if (!_ext_initted)
-     {
-        _gl_ext_sym_init();
-        _gl_ext_init(re);
-        _ext_initted = 1 ;
-     }
+   _gl_ext_sym_init();
+   _gl_ext_init(re);
 
    return 1;
 }
@@ -2921,7 +2878,7 @@ _check_gl_surface_format(GLint int_fmt, GLenum fmt, GLenum attachment, GLenum at
    int w, h, fb_status;
 
    // Initialize Variables
-   fbo = tex = rb = ds_tex = 0;
+   tex = rb = ds_tex = 0;
 
    // Width/Heith for test purposes
    w = h = 2;
@@ -3000,7 +2957,7 @@ _check_gl_surface_format(GLint int_fmt, GLenum fmt, GLenum attachment, GLenum at
 
    // Delete Created Resources
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
-   if (fbo) glDeleteFramebuffers(1, &fbo);
+   glDeleteFramebuffers(1, &fbo);
    if (tex) glDeleteTextures(1, &tex);
    if (ds_tex) glDeleteTextures(1, &ds_tex);
    if (rb) glDeleteRenderbuffers(1, &rb);
@@ -3017,42 +2974,6 @@ _check_gl_surface_format(GLint int_fmt, GLenum fmt, GLenum attachment, GLenum at
 }
 
 static void
-_print_gl_surface_info(Render_Engine_GL_Surface *sfc, int error)
-{
-#define PRINT_LOG(...) \
-   if (error) \
-      ERR(__VA_ARGS__); \
-   else \
-      DBG(__VA_ARGS__);
-
-   PRINT_LOG("----------Surface Info------------");
-   PRINT_LOG("     [Surface] %x", (unsigned int)sfc);
-   PRINT_LOG("         Width:  %d", sfc->w);
-   PRINT_LOG("         Height: %d", sfc->h);
-   PRINT_LOG("         Direct Surface: %x", (unsigned int)sfc->direct_sfc);
-   PRINT_LOG("         Current Context: %x", (unsigned int)sfc->current_ctx);
-   PRINT_LOG("         [-------Config-------]");
-   PRINT_LOG("            Depth Bits      : %d", sfc->depth_bits);
-   PRINT_LOG("            Stencil Bits    : %d", sfc->stencil_bits);
-   PRINT_LOG("            Direct FB Opt   : %d", sfc->direct_fb_opt);
-   PRINT_LOG("            Multisample Bits: %d", sfc->multisample_bits);
-   PRINT_LOG("            MSAA Samples    : %d", sfc->rt_msaa_samples);
-   PRINT_LOG("         [-------Internal-----]");
-   PRINT_LOG("            RenderTarget Texture             : %d", sfc->rt_tex);
-   PRINT_LOG("            RenderTarget Internal Format     : %x", sfc->rt_internal_fmt);
-   PRINT_LOG("            RenderTaret Format               : %x", sfc->rt_fmt);
-   PRINT_LOG("            RenderBuffer Depth               : %x", sfc->rb_depth);
-   PRINT_LOG("            RenderBuffer Depth Format        : %x", sfc->rb_depth_fmt);
-   PRINT_LOG("            RenderBuffer Stencil             : %d", sfc->rb_stencil);
-   PRINT_LOG("            RenderBuffer Stencil Format      : %x", sfc->rb_stencil_fmt);
-   PRINT_LOG("            RenderBuffer Depth Stencil       : %x", sfc->rb_depth_stencil);
-   PRINT_LOG("            RenderBuffer Depth Stencil Format: %x", sfc->rb_depth_stencil_fmt);
-   PRINT_LOG("--------------------------------------");
-
-#undef PRINT_LOG
-}
-
-static void
 _print_gl_surface_cap(Render_Engine *re, int error)
 {
 #define PRINT_LOG(...) \
@@ -3061,8 +2982,8 @@ _print_gl_surface_cap(Render_Engine *re, int error)
    else \
       DBG(__VA_ARGS__);
 
-   PRINT_LOG("----------------------------------------------------");
-   PRINT_LOG("           EvasGL Supported Surface Format          ");
+   PRINT_LOG("---------------------------------------------------");
+   PRINT_LOG("           EvasGL Supported Surface Format         ");
    PRINT_LOG("                                                    ");
    PRINT_LOG(" [Max Renderbuffer Size]  : %d", re->gl_cap.max_rb_size);
    PRINT_LOG(" [Multisample Support  ]  : %d", re->gl_cap.msaa_support);
@@ -3093,7 +3014,7 @@ _set_gl_surface_cap(Render_Engine *re)
    GLuint fbo, tex, depth, stencil;
    int w, h;
 
-   int i, count;
+   int i, ret, count;
 
    if (!re) return;
    if (re->gl_cap_initted) return;
@@ -3107,7 +3028,7 @@ _set_gl_surface_cap(Render_Engine *re)
    glGetIntegerv(GL_MAX_SAMPLES_IMG, &max_samples);
 
    // Check if msaa_support is supported
-   if ((max_samples) &&
+   if (max_samples &&
        (glsym_glFramebufferTexture2DMultisample) &&
        (glsym_glRenderbufferStorageMultisample))
      {
@@ -3150,7 +3071,7 @@ _set_gl_surface_cap(Render_Engine *re)
         re->gl_cap.depth_24_stencil_8[i]  = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_STENCIL_OES, GL_DEPTH_STENCIL_OES, re->gl_cap.msaa_samples[i]);
      }
 
-#else
+  #else
    count = (re->gl_cap.msaa_support) ? 4 : 1;
 
    for (i = 0; i < count; i++)
@@ -3275,7 +3196,6 @@ _set_internal_config(Render_Engine *re, Render_Engine_GL_Surface *sfc, Evas_GL_C
            }
       case EVAS_GL_STENCIL_BIT_8:
          if ((sfc->rb_depth_fmt == re->gl_cap.depth_24_stencil_8[0]) ||
-             (sfc->rb_depth_fmt == re->gl_cap.depth_24[0]) ||
              (!(re->gl_cap.stencil_8[0]) && (re->gl_cap.depth_24_stencil_8[0])))
            {
               sfc->rb_depth_stencil_fmt = re->gl_cap.depth_24_stencil_8[0];
@@ -3333,32 +3253,48 @@ _set_internal_config(Render_Engine *re, Render_Engine_GL_Surface *sfc, Evas_GL_C
    return 1;
 }
 
-static int
-_attach_fbo_surface(Render_Engine *data __UNUSED__,
-                    Render_Engine_GL_Surface *sfc,
-                    int fbo)
+static void
+_create_rt_buffers(Render_Engine *data __UNUSED__,
+                   Render_Engine_GL_Surface *sfc)
 {
-   int fb_status, curr_tex, curr_rb;
-
-   glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+   // Render Target texture
+   if (sfc->rt_fmt)
+     {
+        glGenTextures(1, &sfc->rt_tex);
+     }
 
-   // Detach any previously attached buffers
-   glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
-   glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
-   glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
+   // First check if packed buffer is to be used.
+   if (sfc->rb_depth_stencil_fmt)
+     {
 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
-   glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
-   glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
+        glGenTextures(1, &sfc->rb_depth_stencil);
 #else
-   glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
+        glGenRenderbuffers(1, &sfc->rb_depth_stencil);
 #endif
+        return;
+     }
 
+   // Depth RenderBuffer - Create storage here...
+   if (sfc->rb_depth_fmt)
+      glGenRenderbuffers(1, &sfc->rb_depth);
+
+   // Stencil RenderBuffer - Create Storage here...
+   if (sfc->rb_stencil_fmt)
+      glGenRenderbuffers(1, &sfc->rb_stencil);
+}
+
+static int
+_attach_fbo_surface(Render_Engine *data __UNUSED__,
+                    Render_Engine_GL_Surface *sfc,
+                    Render_Engine_GL_Context *ctx)
+{
+   int fb_status;
+
+   glBindFramebuffer(GL_FRAMEBUFFER, ctx->context_fbo);
 
    // Render Target Texture
    if (sfc->rt_tex)
      {
-        curr_tex = 0;
-        glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_tex);
         glBindTexture(GL_TEXTURE_2D, sfc->rt_tex );
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -3366,9 +3302,8 @@ _attach_fbo_surface(Render_Engine *data __UNUSED__,
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sfc->w, sfc->h, 0,
                      GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-        glBindTexture(GL_TEXTURE_2D, curr_tex);
+        glBindTexture(GL_TEXTURE_2D, 0);
 
-        // Attach texture to FBO
         if (sfc->rt_msaa_samples)
            glsym_glFramebufferTexture2DMultisample(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sfc->rt_tex, 0, sfc->rt_msaa_samples);
         else
@@ -3377,12 +3312,12 @@ _attach_fbo_surface(Render_Engine *data __UNUSED__,
      }
 
 
+
+
    // Depth Stencil RenderBuffer - Attach it to FBO
    if (sfc->rb_depth_stencil)
      {
 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
-        curr_tex = 0;
-        glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_tex);
         glBindTexture(GL_TEXTURE_2D, sfc->rb_depth_stencil);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -3394,26 +3329,21 @@ _attach_fbo_surface(Render_Engine *data __UNUSED__,
                                GL_TEXTURE_2D, sfc->rb_depth_stencil, 0);
         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
                                GL_TEXTURE_2D, sfc->rb_depth_stencil, 0);
-        glBindTexture(GL_TEXTURE_2D, curr_tex);
+        glBindTexture(GL_TEXTURE_2D, 0);
 
 #else
-        curr_rb = 0;
-        glGetIntegerv(GL_RENDERBUFFER_BINDING, &curr_rb);
         glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth_stencil);
         glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_depth_stencil_fmt,
                               sfc->w, sfc->h);
         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
                                   GL_RENDERBUFFER, sfc->rb_depth_stencil);
-        glBindRenderbuffer(GL_RENDERBUFFER, curr_rb);
+        glBindRenderbuffer(GL_RENDERBUFFER, 0);
 #endif
      }
 
    // Depth RenderBuffer - Attach it to FBO
    if (sfc->rb_depth)
      {
-        curr_rb = 0;
-        glGetIntegerv(GL_RENDERBUFFER_BINDING, &curr_rb);
-
         glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth);
 
         if (sfc->rt_msaa_samples)
@@ -3426,15 +3356,12 @@ _attach_fbo_surface(Render_Engine *data __UNUSED__,
                                  sfc->w, sfc->h);
         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                                   GL_RENDERBUFFER, sfc->rb_depth);
-        glBindRenderbuffer(GL_RENDERBUFFER, curr_rb);
+        glBindRenderbuffer(GL_RENDERBUFFER, 0);
      }
 
    // Stencil RenderBuffer - Attach it to FBO
    if (sfc->rb_stencil)
      {
-        curr_rb = 0;
-        glGetIntegerv(GL_RENDERBUFFER_BINDING, &curr_rb);
-
         glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_stencil);
 
         if (sfc->rt_msaa_samples)
@@ -3447,81 +3374,20 @@ _attach_fbo_surface(Render_Engine *data __UNUSED__,
                                  sfc->w, sfc->h);
         glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
                                   GL_RENDERBUFFER, sfc->rb_stencil);
-        glBindRenderbuffer(GL_RENDERBUFFER, curr_rb);
+        glBindRenderbuffer(GL_RENDERBUFFER, 0);
      }
 
    // Check FBO for completeness
    fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (fb_status != GL_FRAMEBUFFER_COMPLETE)
      {
-        ERR("FBO not complete. Error Code: %x!", fb_status);
-        _print_gl_surface_info(sfc, 1);
+        ERR("FBO not complete!");
         return 0;
      }
 
    return 1;
 }
 
-static int
-_create_rt_buffers(Render_Engine *data __UNUSED__,
-                   Render_Engine_GL_Surface *sfc)
-{
-   int ret = 0;
-   GLuint fbo = 0, curr_fbo = 0;
-
-   //------------------------------------//
-   // Render Target texture
-   if (sfc->rt_fmt)
-     {
-        glGenTextures(1, &sfc->rt_tex);
-     }
-
-   // First check if packed buffer is to be used.
-   if (sfc->rb_depth_stencil_fmt)
-     {
-#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
-        glGenTextures(1, &sfc->rb_depth_stencil);
-#else
-        glGenRenderbuffers(1, &sfc->rb_depth_stencil);
-#endif
-     }
-   else
-     {
-        // Depth RenderBuffer - Create storage here...
-        if (sfc->rb_depth_fmt)
-           glGenRenderbuffers(1, &sfc->rb_depth);
-
-        // Stencil RenderBuffer - Create Storage here...
-        if (sfc->rb_stencil_fmt)
-           glGenRenderbuffers(1, &sfc->rb_stencil);
-     }
-   //------------------------------------//
-   // Try attaching the given configuration
-   glGetIntegerv(GL_FRAMEBUFFER_BINDING, &curr_fbo);
-   glGenFramebuffers(1 ,&fbo);
-
-   ret = _attach_fbo_surface(NULL, sfc, fbo);
-
-   if (fbo) glDeleteFramebuffers(1, &fbo);
-   glBindFramebuffer(GL_FRAMEBUFFER, curr_fbo);
-
-   if (!ret)
-     {
-        if (sfc->rt_tex) glDeleteTextures(1, &sfc->rt_tex);
-        if (sfc->rb_depth) glDeleteRenderbuffers(1, &sfc->rb_depth);
-        if (sfc->rb_stencil) glDeleteRenderbuffers(1, &sfc->rb_stencil);
-#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
-        if (sfc->rb_depth_stencil) glDeleteTextures(1, &sfc->rb_depth_stencil);
-#else
-        if (sfc->rb_depth_stencil) glDeleteRenderbuffers(1, &sfc->rb_depth_stencil);
-#endif
-        ERR("_attach_fbo_surface() failed.");
-        return 0;
-     }
-   else
-      return 1;
-}
-
 
 static void *
 eng_gl_surface_create(void *data, void *config, int w, int h)
@@ -3605,15 +3471,7 @@ eng_gl_surface_create(void *data, void *config, int w, int h)
      }
 
    // Create Render texture
-   if (!_create_rt_buffers(re, sfc))
-     {
-        ERR("Unable Create Specificed Surfaces.  Unsupported format!");
-        goto finish;
-     };
-
-   ret = sfc;
-
-finish:
+   _create_rt_buffers(re, sfc);
 
 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
    res = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
@@ -3622,9 +3480,14 @@ finish:
 #endif
    if (!res)
      {
-        ERR("xxxMakeCurrent() (NULL, NULL) Error!");
+        ERR("xxxMakeCurrent() finish!");
+        goto finish;
      }
 
+   ret = sfc;
+
+finish:
+
    if (!ret)
      {
         if (sfc) free(sfc);
@@ -4011,10 +3874,9 @@ eng_gl_make_current(void *data __UNUSED__, void *surface, void *context)
         // Attach FBO if it hasn't been attached or if surface changed
         if ((!sfc->fbo_attached) || (ctx->current_sfc != sfc))
           {
-             if (!_attach_fbo_surface(re, sfc, ctx->context_fbo))
+             if (!_attach_fbo_surface(re, sfc, ctx))
                {
                   ERR("_attach_fbo_surface() failed.");
-                  _print_gl_surface_info(sfc, 1);
                   return 0;
                }