Revert "Upstream merge"
[framework/uifw/evas.git] / src / modules / engines / software_generic / evas_engine.c
index cd3fb33..5540b3e 100644 (file)
@@ -1,18 +1,20 @@
 #include "evas_common.h" /* Also includes international specific stuff */
 #include "evas_private.h"
 
-
-#define EVAS_GL_NO_GL_H_CHECK 1
-#include "Evas_GL.h"
-
 #ifdef HAVE_DLSYM
 # include <dlfcn.h>      /* dlopen,dlclose,etc */
+
+# define EVAS_GL 1
+# define EVAS_GL_NO_GL_H_CHECK 1
+# include "Evas_GL.h"
+
 #else
-# error software_generic should not get compiled if dlsym is not found on the system!
+# warning software_generic will not be able to have Evas_GL API.
 #endif
 
+#ifdef EVAS_GL
 //----------------------------------//
-// OSMesa... 
+// OSMesa...
 
 #define OSMESA_MAJOR_VERSION 6
 #define OSMESA_MINOR_VERSION 5
@@ -52,6 +54,7 @@
 
 typedef void (*OSMESAproc)();
 typedef struct osmesa_context *OSMesaContext;
+#endif
 
 typedef struct _Render_Engine_GL_Surface    Render_Engine_GL_Surface;
 typedef struct _Render_Engine_GL_Context    Render_Engine_GL_Context;
@@ -61,18 +64,21 @@ struct _Render_Engine_GL_Surface
    int     initialized;
    int     w, h;
 
+#ifdef EVAS_GL
    GLenum  internal_fmt;
+#endif
    int     internal_cpp;   // Component per pixel.  ie. RGB = 3
 
    int     depth_bits;
    int     stencil_bits;
 
-   // Data 
+   // Data
    void   *buffer;
 
    Render_Engine_GL_Context   *current_ctx;
 };
 
+#ifdef EVAS_GL
 struct _Render_Engine_GL_Context
 {
    int            initialized;
@@ -84,9 +90,8 @@ struct _Render_Engine_GL_Context
    Render_Engine_GL_Surface   *current_sfc;
 };
 
-
 //------------------------------------------------------//
-typedef void                   (*_eng_fn) (void );       
+typedef void                   (*_eng_fn) (void );
 typedef _eng_fn                (*glsym_func_eng_fn) ();
 typedef void                   (*glsym_func_void) ();
 typedef unsigned int           (*glsym_func_uint) ();
@@ -260,9 +265,10 @@ static void       (*_sym_glVertexAttribPointer)                 (GLuint indx, GL
 static void       (*_sym_glViewport)                            (GLint x, GLint y, GLsizei width, GLsizei height) = NULL;
 
 // GLES Extensions...
-static void       (*_sym_glGetProgramBinary)                    (GLuint a, GLsizei b, GLsizei* c, GLenum* d, void* e) = NULL;
-static void       (*_sym_glProgramBinary)                       (GLuint a, GLenum b, const void* c, GLint d) = NULL;
-static void       (*_sym_glProgramParameteri)                   (GLuint a, GLuint b, GLint d) = NULL;
+/* static void       (*_sym_glGetProgramBinary)                    (GLuint a, GLsizei b, GLsizei* c, GLenum* d, void* e) = NULL; */
+/* static void       (*_sym_glProgramBinary)                       (GLuint a, GLenum b, const void* c, GLint d) = NULL; */
+/* static void       (*_sym_glProgramParameteri)                   (GLuint a, GLuint b, GLint d) = NULL; */
+#endif
 
 /*
  *****
@@ -585,11 +591,8 @@ eng_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r
 }
 
 static void
-eng_image_border_get(void *data __UNUSED__, void *image, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
+eng_image_border_get(void *data __UNUSED__, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
 {
-   RGBA_Image *im;
-
-   im = image;
 }
 
 static char *
@@ -643,8 +646,8 @@ eng_image_native_set(void *data __UNUSED__, void *image, void *native __UNUSED__
 
    if (!ns) return im;
 
-   im2 = evas_cache_image_data(evas_common_image_cache_get(), 
-                               im->w, im->h, 
+   im2 = evas_cache_image_data(evas_common_image_cache_get(),
+                               im->w, im->h,
                                ns->data.x11.visual, 1,
                                EVAS_COLORSPACE_ARGB8888);
    evas_cache_image_drop(im);
@@ -698,18 +701,16 @@ eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
 static void *
 eng_image_size_set(void *data __UNUSED__, void *image, int w, int h)
 {
-   Image_Entry *im;
-
-   im = image;
-   return evas_cache_image_size_set(image, w, h);
+   Image_Entry *im = image;
+   if (!im) return NULL;
+   return evas_cache_image_size_set(im, w, h);
 }
 
 static void *
 eng_image_dirty_region(void *data __UNUSED__, void *image, int x, int y, int w, int h)
 {
    Image_Entry *im = image;
-
-   if (!image) return NULL;
+   if (!im) return NULL;
    return evas_cache_image_dirty(im, x, y, w, h);
 }
 
@@ -925,11 +926,10 @@ static void *
 eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
 {
    void *surface;
-   DATA32 *pixels;
    surface = evas_cache_image_copied_data(evas_common_image_cache_get(), 
                                           w, h, NULL, alpha, 
                                           EVAS_COLORSPACE_ARGB8888);
-   pixels = evas_cache_image_pixels(surface);
+   evas_cache_image_pixels(surface);
    return surface;
 }
 
@@ -1341,6 +1341,7 @@ eng_image_load_error_get(void *data __UNUSED__, void *image)
 static void *
 eng_gl_surface_create(void *data __UNUSED__, void *config, int w, int h)
 {
+#ifdef EVAS_GL
    Render_Engine_GL_Surface *sfc;
    Evas_GL_Config *cfg;
 
@@ -1391,7 +1392,7 @@ eng_gl_surface_create(void *data __UNUSED__, void *config, int w, int h)
          sfc->depth_bits = 0;
          break;
      }
-   
+
    // Stencil Bits
    switch (cfg->stencil_bits)
      {
@@ -1425,11 +1426,18 @@ eng_gl_surface_create(void *data __UNUSED__, void *config, int w, int h)
      }
 
    return sfc;
+#else
+   (void) config;
+   (void) w;
+   (void) h;
+   return NULL;
+#endif
 }
 
 static int
 eng_gl_surface_destroy(void *data __UNUSED__, void *surface)
 {
+#ifdef EVAS_GL
    Render_Engine_GL_Surface *sfc;
 
    sfc = (Render_Engine_GL_Surface*)surface;
@@ -1443,11 +1451,16 @@ eng_gl_surface_destroy(void *data __UNUSED__, void *surface)
    surface = NULL;
 
    return 1;
+#else
+   (void) surface;
+   return 1;
+#endif
 }
 
 static void *
 eng_gl_context_create(void *data __UNUSED__, void *share_context)
 {
+#ifdef EVAS_GL
    Render_Engine_GL_Context *ctx;
    Render_Engine_GL_Context *share_ctx;
 
@@ -1477,11 +1490,16 @@ eng_gl_context_create(void *data __UNUSED__, void *share_context)
    ctx->initialized = 0;
 
    return ctx;
+#else
+   (void) share_context;
+   return NULL;
+#endif
 }
 
 static int
 eng_gl_context_destroy(void *data __UNUSED__, void *context)
 {
+#ifdef EVAS_GL
    Render_Engine_GL_Context *ctx;
 
    ctx = (Render_Engine_GL_Context*)context;
@@ -1494,11 +1512,16 @@ eng_gl_context_destroy(void *data __UNUSED__, void *context)
    context = NULL;
 
    return 1;
+#else
+   (void) context;
+   return 0;
+#endif
 }
 
 static int
 eng_gl_make_current(void *data __UNUSED__, void *surface, void *context)
 {
+#ifdef EVAS_GL
    Render_Engine_GL_Surface *sfc;
    Render_Engine_GL_Context *ctx;
    OSMesaContext share_ctx;
@@ -1523,9 +1546,9 @@ eng_gl_make_current(void *data __UNUSED__, void *surface, void *context)
         else
            share_ctx = NULL;
 
-        ctx->context =  _sym_OSMesaCreateContextExt(sfc->internal_fmt, 
+        ctx->context =  _sym_OSMesaCreateContextExt(sfc->internal_fmt,
                                                sfc->depth_bits,
-                                               sfc->stencil_bits, 
+                                               sfc->stencil_bits,
                                                0,
                                                share_ctx);
         if (!ctx->context)
@@ -1539,7 +1562,7 @@ eng_gl_make_current(void *data __UNUSED__, void *surface, void *context)
 
 
    // Call MakeCurrent
-   ret = _sym_OSMesaMakeCurrent(ctx->context, sfc->buffer, GL_UNSIGNED_BYTE, 
+   ret = _sym_OSMesaMakeCurrent(ctx->context, sfc->buffer, GL_UNSIGNED_BYTE,
                            sfc->w, sfc->h);
 
    if (ret == GL_FALSE)
@@ -1555,11 +1578,16 @@ eng_gl_make_current(void *data __UNUSED__, void *surface, void *context)
    sfc->current_ctx = ctx;
 
    return 1;
+#else
+   (void) surface;
+   (void) context;
+   return 1;
+#endif
 }
 
 // FIXME!!! Implement later
 static void *
-eng_gl_string_query(void *data, int name)
+eng_gl_string_query(void *data __UNUSED__, int name __UNUSED__)
 {
    return NULL;
 }
@@ -1567,13 +1595,19 @@ eng_gl_string_query(void *data, int name)
 static void *
 eng_gl_proc_address_get(void *data __UNUSED__, const char *name)
 {
+#ifdef EVAS_GL
    if (_sym_OSMesaGetProcAddress) return _sym_OSMesaGetProcAddress(name);
    return dlsym(RTLD_DEFAULT, name);
+#else
+   (void) name;
+   return NULL;
+#endif
 }
 
 static int
 eng_gl_native_surface_get(void *data __UNUSED__, void *surface, void *native_surface)
 {
+#ifdef EVAS_GL
    Render_Engine_GL_Surface *sfc;
    Evas_Native_Surface *ns;
 
@@ -1587,13 +1621,22 @@ eng_gl_native_surface_get(void *data __UNUSED__, void *surface, void *native_sur
    ns->data.x11.visual = sfc->buffer;
 
    return 1;
+#else
+   (void) surface;
+   (void) native_surface;
+   return 1;
+#endif
 }
 
 
 static void *
 eng_gl_api_get(void *data __UNUSED__)
 {
+#ifdef EVAS_GL
    return &gl_funcs;
+#else
+   return NULL;
+#endif
 }
 
 //------------------------------------------------//
@@ -1735,6 +1778,7 @@ static Evas_Func func =
      NULL, // need software mesa for gl rendering <- gl_proc_address_get
      NULL, // need software mesa for gl rendering <- gl_native_surface_get
      NULL, // need software mesa for gl rendering <- gl_api_get
+     NULL, // need software mesa for gl rendering <- gl_img_obj_set
      eng_image_load_error_get,
      eng_font_run_font_end_get,
      eng_image_animated_get,
@@ -1753,14 +1797,14 @@ static Evas_Func func =
 //                      Load Symbols                              //
 //                                                                //
 //----------------------------------------------------------------//
+#ifdef EVAS_GL
 static void
 sym_missing(void)
 {
    ERR("GL symbols missing!\n");
 }
 
-
-static int 
+static int
 glue_sym_init(void)
 {
    //------------------------------------------------//
@@ -1797,7 +1841,7 @@ glue_sym_init(void)
    return 1;
 }
 
-static int 
+static int
 gl_sym_init(void)
 {
    //------------------------------------------------//
@@ -2240,14 +2284,14 @@ gl_sym_init(void)
 #undef FINDSYM
 #undef FALLBAK
 
-   // Checking to see if this function exists is a poor but reasonable way to 
+   // Checking to see if this function exists is a poor but reasonable way to
    // check if it's gles but it works for now
-   if (_sym_glGetShaderPrecisionFormat != (typeof(_sym_glGetShaderPrecisionFormat))sym_missing ) 
+   if (_sym_glGetShaderPrecisionFormat != (typeof(_sym_glGetShaderPrecisionFormat))sym_missing )
      {
         DBG("GL Library is GLES.");
         gl_lib_is_gles = 1;
      }
-   
+
    return 1;
 }
 
@@ -2255,7 +2299,7 @@ gl_sym_init(void)
 // Wrapped GL APIs to handle desktop compatibility
 
 // Stripping precision code from GLES shader for desktop compatibility
-// Code adopted from Meego GL code. Temporary Fix.  
+// Code adopted from Meego GL code. Temporary Fix.
 static const char *
 opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
 {
@@ -2267,33 +2311,33 @@ opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
 
    if (prevbuf) free(prevbuf);
 
-   if (s) 
+   if (s)
       *saveptr = (char *)s;
-   else 
+   else
      {
         if (!(*saveptr) || !(*n))
            return NULL;
         s = *saveptr;
      }
 
-   for (; *n && strchr(delim, *s); s++, (*n)--) 
+   for (; *n && strchr(delim, *s); s++, (*n)--)
      {
-        if (*s == '/' && *n > 1) 
+        if (*s == '/' && *n > 1)
           {
-             if (s[1] == '/') 
+             if (s[1] == '/')
                {
-                  do 
+                  do
                     {
                        s++, (*n)--;
-                    } 
+                    }
                   while (*n > 1 && s[1] != '\n' && s[1] != '\r');
-               } 
-             else if (s[1] == '*') 
+               }
+             else if (s[1] == '*')
                {
-                  do 
+                  do
                     {
                        s++, (*n)--;
-                    } 
+                    }
                   while (*n > 2 && (s[1] != '*' || s[2] != '/'));
                   s++, (*n)--;
                }
@@ -2310,26 +2354,26 @@ opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
    ret = malloc(retlen + 1);
    p = ret;
 
-   while (retlen > 0) 
+   while (retlen > 0)
      {
-        if (*start == '/' && retlen > 1) 
+        if (*start == '/' && retlen > 1)
           {
-             if (start[1] == '/') 
+             if (start[1] == '/')
                {
-                  do 
+                  do
                     {
                        start++, retlen--;
-                    } 
+                    }
                   while (retlen > 1 && start[1] != '\n' && start[1] != '\r');
                   start++, retlen--;
                   continue;
-               } 
-             else if (start[1] == '*') 
+               }
+             else if (start[1] == '*')
                {
-                  do 
+                  do
                     {
                        start++, retlen--;
-                    } 
+                    }
                   while (retlen > 2 && (start[1] != '*' || start[2] != '/'));
                   start += 3, retlen -= 3;
                   continue;
@@ -2340,7 +2384,7 @@ opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
 
    *p = 0;
    return ret;
-}      
+}
 
 static char *
 patch_gles_shader(const char *source, int length, int *patched_len)
@@ -2358,55 +2402,55 @@ patch_gles_shader(const char *source, int length, int *patched_len)
    if (!patched) return NULL;
 
    p = (char *)opengl_strtok(source, &length, &saveptr, NULL);
-   for (; p; p = (char *)opengl_strtok(0, &length, &saveptr, p)) 
+   for (; p; p = (char *)opengl_strtok(0, &length, &saveptr, p))
      {
-        if (!strncmp(p, "lowp", 4) || !strncmp(p, "mediump", 7) || !strncmp(p, "highp", 5)) 
+        if (!strncmp(p, "lowp", 4) || !strncmp(p, "mediump", 7) || !strncmp(p, "highp", 5))
           {
              continue;
-          } 
-        else if (!strncmp(p, "precision", 9)) 
+          }
+        else if (!strncmp(p, "precision", 9))
           {
              while ((p = (char *)opengl_strtok(0, &length, &saveptr, p)) && !strchr(p, ';'));
-          } 
-        else 
+          }
+        else
           {
-             if (!strncmp(p, "gl_MaxVertexUniformVectors", 26)) 
+             if (!strncmp(p, "gl_MaxVertexUniformVectors", 26))
                {
                   p = "(gl_MaxVertexUniformComponents / 4)";
-               } 
-             else if (!strncmp(p, "gl_MaxFragmentUniformVectors", 28)) 
+               }
+             else if (!strncmp(p, "gl_MaxFragmentUniformVectors", 28))
                {
                   p = "(gl_MaxFragmentUniformComponents / 4)";
-               } 
-             else if (!strncmp(p, "gl_MaxVaryingVectors", 20)) 
+               }
+             else if (!strncmp(p, "gl_MaxVaryingVectors", 20))
                {
                   p = "(gl_MaxVaryingFloats / 4)";
                }
 
              int new_len = strlen(p);
-             if (*patched_len + new_len > patched_size) 
+             if (*patched_len + new_len > patched_size)
                {
                   patched_size *= 2;
                   patched = realloc(patched, patched_size + 1);
 
-                  if (!patched) 
+                  if (!patched)
                      return NULL;
                }
 
              memcpy(patched + *patched_len, p, new_len);
              *patched_len += new_len;
-          }     
+          }
      }
 
    patched[*patched_len] = 0;
    /* check that we don't leave dummy preprocessor lines */
-   for (sp = patched; *sp;) 
+   for (sp = patched; *sp;)
      {
         for (; *sp == ' ' || *sp == '\t'; sp++);
-        if (!strncmp(sp, "#define", 7)) 
+        if (!strncmp(sp, "#define", 7))
           {
              for (p = sp + 7; *p == ' ' || *p == '\t'; p++);
-             if (*p == '\n' || *p == '\r' || *p == '/') 
+             if (*p == '\n' || *p == '\r' || *p == '/')
                {
                   memset(sp, 0x20, 7);
                }
@@ -2420,13 +2464,7 @@ patch_gles_shader(const char *source, int length, int *patched_len)
 static void
 evgl_glShaderSource(GLuint shader, GLsizei count, const char** string, const GLint* length)
 {
-   char *newstr;
-   char *srcbk;
-   char *token = NULL;
-   char *saveptr;
-   int i = 0;
-   int len = 0;
-   int token_len = 0;
+   int i = 0, len = 0;
 
    char **s = malloc(count * sizeof(char*));
    GLint *l = malloc(count * sizeof(GLint));
@@ -2434,21 +2472,21 @@ evgl_glShaderSource(GLuint shader, GLsizei count, const char** string, const GLi
    memset(s, 0, count * sizeof(char*));
    memset(l, 0, count * sizeof(GLint));
 
-   for (i = 0; i < count; ++i) 
+   for (i = 0; i < count; ++i)
      {
-        if (length) 
+        if (length)
           {
              len = length[i];
-             if (len < 0) 
+             if (len < 0)
                 len = string[i] ? strlen(string[i]) : 0;
           }
         else
            len = string[i] ? strlen(string[i]) : 0;
 
-        if (string[i]) 
+        if (string[i])
           {
              s[i] = patch_gles_shader(string[i], len, &l[i]);
-             if (!s[i]) 
+             if (!s[i])
                {
                   while(i)
                      free(s[--i]);
@@ -2458,8 +2496,8 @@ evgl_glShaderSource(GLuint shader, GLsizei count, const char** string, const GLi
                   DBG("Patching Shader Failed.");
                   return;
                }
-          } 
-        else 
+          }
+        else
           {
              s[i] = NULL;
              l[i] = 0;
@@ -2476,7 +2514,7 @@ evgl_glShaderSource(GLuint shader, GLsizei count, const char** string, const GLi
 
 
 static void
-evgl_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
+evgl_glGetShaderPrecisionFormat(GLenum shadertype __UNUSED__, GLenum precisiontype __UNUSED__, GLint* range, GLint* precision)
 {
    if (range)
      {
@@ -2488,7 +2526,6 @@ evgl_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint*
         precision[0] = 24; // floor(-log2((1.0/16777218.0)));
      }
    return;
-   shadertype = precisiontype = 0;
 }
 
 static void
@@ -2499,7 +2536,7 @@ evgl_glReleaseShaderCompiler(void)
 }
 
 static void
-evgl_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
+evgl_glShaderBinary(GLsizei n __UNUSED__, const GLuint* shaders __UNUSED__, GLenum binaryformat __UNUSED__, const void* binary __UNUSED__, GLsizei length __UNUSED__)
 {
    // FIXME: need to dlsym/getprocaddress for this
    DBG("Not supported in Desktop GL");
@@ -2507,9 +2544,11 @@ evgl_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const
    //n = binaryformat = length = 0;
    //shaders = binary = 0;
 }
+#endif
 //--------------------------------------------------------------//
 
 
+#ifdef EVAS_GL
 static void
 override_gl_apis(Evas_GL_API *api)
 {
@@ -2522,6 +2561,8 @@ override_gl_apis(Evas_GL_API *api)
    ORD(glAttachShader);
    ORD(glBindAttribLocation);
    ORD(glBindBuffer);
+   ORD(glBindFramebuffer);
+   ORD(glBindRenderbuffer);
    ORD(glBindTexture);
    ORD(glBlendColor);
    ORD(glBlendEquation);
@@ -2533,7 +2574,7 @@ override_gl_apis(Evas_GL_API *api)
    ORD(glCheckFramebufferStatus);
    ORD(glClear);
    ORD(glClearColor);
-   ORD(glClearDepthf);     
+   ORD(glClearDepthf);
    ORD(glClearStencil);
    ORD(glColorMask);
    ORD(glCompileShader);
@@ -2552,7 +2593,7 @@ override_gl_apis(Evas_GL_API *api)
    ORD(glDeleteTextures);
    ORD(glDepthFunc);
    ORD(glDepthMask);
-   ORD(glDepthRangef);     
+   ORD(glDepthRangef);
    ORD(glDetachShader);
    ORD(glDisable);
    ORD(glDisableVertexAttribArray);
@@ -2585,7 +2626,7 @@ override_gl_apis(Evas_GL_API *api)
    ORD(glGetRenderbufferParameteriv);
    ORD(glGetShaderiv);
    ORD(glGetShaderInfoLog);
-   ORD(glGetShaderPrecisionFormat);  
+   ORD(glGetShaderPrecisionFormat);
    ORD(glGetShaderSource);
    ORD(glGetString);             // FIXME
    ORD(glGetTexParameterfv);
@@ -2609,11 +2650,11 @@ override_gl_apis(Evas_GL_API *api)
    ORD(glPixelStorei);
    ORD(glPolygonOffset);
    ORD(glReadPixels);
-   ORD(glReleaseShaderCompiler); 
+   ORD(glReleaseShaderCompiler);
    ORD(glRenderbufferStorage);
    ORD(glSampleCoverage);
    ORD(glScissor);
-   ORD(glShaderBinary); 
+   ORD(glShaderBinary);
    ORD(glShaderSource);
    ORD(glStencilFunc);
    ORD(glStencilFuncSeparate);
@@ -2673,12 +2714,14 @@ override_gl_apis(Evas_GL_API *api)
    ORD(glShaderSource);    // Do precision stripping in both cases
 #undef ORD
 }
+#endif
 
 //-------------------------------------------//
 static int
 gl_lib_init(void)
 {
-   // dlopen OSMesa 
+#ifdef EVAS_GL
+   // dlopen OSMesa
    gl_lib_handle = dlopen("libOSMesa.so.1", RTLD_NOW);
    if (!gl_lib_handle) gl_lib_handle = dlopen("libOSMesa.so", RTLD_NOW);
    if (!gl_lib_handle)
@@ -2692,13 +2735,16 @@ gl_lib_init(void)
    if (!gl_sym_init()) return 0;
 
    override_gl_apis(&gl_funcs);
-  
+
    return 1;
+#else
+   return 0;
+#endif
 }
 
 
-static void 
-init_gl()
+static void
+init_gl(void)
 {
    DBG("Initializing Software OpenGL APIs...\n");