Added EvasGL support for software backend finally.
[framework/uifw/evas.git] / src / modules / engines / software_generic / evas_engine.c
1 #include "evas_common.h" /* Also includes international specific stuff */
2 #include "evas_private.h"
3
4
5 #define EVAS_GL_NO_GL_H_CHECK 1
6 #include "Evas_GL.h"
7
8 #ifdef HAVE_DLSYM
9 # include <dlfcn.h>      /* dlopen,dlclose,etc */
10 #else
11 # error software_generic should not get compiled if dlsym is not found on the system!
12 #endif
13
14 //----------------------------------//
15 // OSMesa... 
16
17 #define OSMESA_MAJOR_VERSION 6
18 #define OSMESA_MINOR_VERSION 5
19 #define OSMESA_PATCH_VERSION 0
20
21 /*
22  * Values for the format parameter of OSMesaCreateContext()
23  * New in version 2.0.
24  */
25 #define OSMESA_COLOR_INDEX      GL_COLOR_INDEX
26 #define OSMESA_RGBA             GL_RGBA
27 #define OSMESA_BGRA             0x1
28 #define OSMESA_ARGB             0x2
29 #define OSMESA_RGB              GL_RGB
30 #define OSMESA_BGR              0x4
31 #define OSMESA_RGB_565          0x5
32
33
34 /*
35  * OSMesaPixelStore() parameters:
36  * New in version 2.0.
37  */
38 #define OSMESA_ROW_LENGTH       0x10
39 #define OSMESA_Y_UP             0x11
40
41
42 /*
43  * Accepted by OSMesaGetIntegerv:
44  */
45 #define OSMESA_WIDTH            0x20
46 #define OSMESA_HEIGHT           0x21
47 #define OSMESA_FORMAT           0x22
48 #define OSMESA_TYPE             0x23
49 #define OSMESA_MAX_WIDTH        0x24  /* new in 4.0 */
50 #define OSMESA_MAX_HEIGHT       0x25  /* new in 4.0 */
51
52
53 typedef void (*OSMESAproc)();
54 typedef struct osmesa_context *OSMesaContext;
55
56 typedef struct _Render_Engine_GL_Surface    Render_Engine_GL_Surface;
57 typedef struct _Render_Engine_GL_Context    Render_Engine_GL_Context;
58
59 struct _Render_Engine_GL_Surface
60 {
61    int     initialized;
62    int     w, h;
63
64    GLenum  internal_fmt;
65    int     internal_cpp;   // Component per pixel.  ie. RGB = 3
66
67    int     depth_bits;
68    int     stencil_bits;
69
70    // Data 
71    void   *buffer;
72
73    Render_Engine_GL_Context   *current_ctx;
74 };
75
76 struct _Render_Engine_GL_Context
77 {
78    int            initialized;
79
80    OSMesaContext  context;
81
82    Render_Engine_GL_Context   *share_ctx;
83
84    Render_Engine_GL_Surface   *current_sfc;
85 };
86
87
88 //------------------------------------------------------//
89 typedef void                   (*_eng_fn) (void );       
90 typedef _eng_fn                (*glsym_func_eng_fn) ();
91 typedef void                   (*glsym_func_void) ();
92 typedef unsigned int           (*glsym_func_uint) ();
93 typedef int                    (*glsym_func_int) ();
94 typedef unsigned char          (*glsym_func_uchar) ();
95 typedef unsigned char         *(*glsym_func_uchar_ptr) ();
96 typedef const unsigned char   *(*glsym_func_const_uchar_ptr) ();
97 typedef char const            *(*glsym_func_char_const_ptr) ();
98 typedef GLboolean              (*glsym_func_bool) ();
99 typedef OSMesaContext          (*glsym_func_osm_ctx) ();
100 //------------------------------------------------------//
101
102 /* Function table for GL APIs */
103 static Evas_GL_API gl_funcs;
104 static void *gl_lib_handle;
105 static int gl_lib_is_gles = 0;
106 static Evas_GL_API gl_funcs;
107
108 //------------------------------------------------------//
109 // OSMesa APIS...
110 static OSMesaContext (*_sym_OSMesaCreateContextExt)             (GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, OSMesaContext sharelist) = NULL;
111 static void          (*_sym_OSMesaDestroyContext)               (OSMesaContext ctx) = NULL;
112 static GLboolean     (*_sym_OSMesaMakeCurrent)                  (OSMesaContext ctx, void *buffer, GLenum type, GLsizei width, GLsizei height) = NULL;
113 static void          (*_sym_OSMesaPixelStore)                   (GLint pname, GLint value) = NULL;
114 static OSMESAproc    (*_sym_OSMesaGetProcAddress)               (const char *funcName);
115
116
117 //------------------------------------------------------//
118 // GLES 2.0 APIs...
119 static void       (*_sym_glActiveTexture)                       (GLenum texture) = NULL;
120 static void       (*_sym_glAttachShader)                        (GLuint program, GLuint shader) = NULL;
121 static void       (*_sym_glBindAttribLocation)                  (GLuint program, GLuint index, const char* name) = NULL;
122 static void       (*_sym_glBindBuffer)                          (GLenum target, GLuint buffer) = NULL;
123 static void       (*_sym_glBindFramebuffer)                     (GLenum target, GLuint framebuffer) = NULL;
124 static void       (*_sym_glBindRenderbuffer)                    (GLenum target, GLuint renderbuffer) = NULL;
125 static void       (*_sym_glBindTexture)                         (GLenum target, GLuint texture) = NULL;
126 static void       (*_sym_glBlendColor)                          (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) = NULL;
127 static void       (*_sym_glBlendEquation)                       (GLenum mode) = NULL;
128 static void       (*_sym_glBlendEquationSeparate)               (GLenum modeRGB, GLenum modeAlpha) = NULL;
129 static void       (*_sym_glBlendFunc)                           (GLenum sfactor, GLenum dfactor) = NULL;
130 static void       (*_sym_glBlendFuncSeparate)                   (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) = NULL;
131 static void       (*_sym_glBufferData)                          (GLenum target, GLsizeiptr size, const void* data, GLenum usage) = NULL;
132 static void       (*_sym_glBufferSubData)                       (GLenum target, GLintptr offset, GLsizeiptr size, const void* data) = NULL;
133 static GLenum     (*_sym_glCheckFramebufferStatus)              (GLenum target) = NULL;
134 static void       (*_sym_glClear)                               (GLbitfield mask) = NULL;
135 static void       (*_sym_glClearColor)                          (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) = NULL;
136 static void       (*_sym_glClearDepthf)                         (GLclampf depth) = NULL;
137 static void       (*_sym_glClearStencil)                        (GLint s) = NULL;
138 static void       (*_sym_glColorMask)                           (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) = NULL;
139 static void       (*_sym_glCompileShader)                       (GLuint shader) = NULL;
140 static void       (*_sym_glCompressedTexImage2D)                (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data) = NULL;
141 static void       (*_sym_glCompressedTexSubImage2D)             (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* data) = NULL;
142 static void       (*_sym_glCopyTexImage2D)                      (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) = NULL;
143 static void       (*_sym_glCopyTexSubImage2D)                   (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) = NULL;
144 static GLuint     (*_sym_glCreateProgram)                       (void) = NULL;
145 static GLuint     (*_sym_glCreateShader)                        (GLenum type) = NULL;
146 static void       (*_sym_glCullFace)                            (GLenum mode) = NULL;
147 static void       (*_sym_glDeleteBuffers)                       (GLsizei n, const GLuint* buffers) = NULL;
148 static void       (*_sym_glDeleteFramebuffers)                  (GLsizei n, const GLuint* framebuffers) = NULL;
149 static void       (*_sym_glDeleteProgram)                       (GLuint program) = NULL;
150 static void       (*_sym_glDeleteRenderbuffers)                 (GLsizei n, const GLuint* renderbuffers) = NULL;
151 static void       (*_sym_glDeleteShader)                        (GLuint shader) = NULL;
152 static void       (*_sym_glDeleteTextures)                      (GLsizei n, const GLuint* textures) = NULL;
153 static void       (*_sym_glDepthFunc)                           (GLenum func) = NULL;
154 static void       (*_sym_glDepthMask)                           (GLboolean flag) = NULL;
155 static void       (*_sym_glDepthRangef)                         (GLclampf zNear, GLclampf zFar) = NULL;
156 static void       (*_sym_glDetachShader)                        (GLuint program, GLuint shader) = NULL;
157 static void       (*_sym_glDisable)                             (GLenum cap) = NULL;
158 static void       (*_sym_glDisableVertexAttribArray)            (GLuint index) = NULL;
159 static void       (*_sym_glDrawArrays)                          (GLenum mode, GLint first, GLsizei count) = NULL;
160 static void       (*_sym_glDrawElements)                        (GLenum mode, GLsizei count, GLenum type, const void* indices) = NULL;
161 static void       (*_sym_glEnable)                              (GLenum cap) = NULL;
162 static void       (*_sym_glEnableVertexAttribArray)             (GLuint index) = NULL;
163 static void       (*_sym_glFinish)                              (void) = NULL;
164 static void       (*_sym_glFlush)                               (void) = NULL;
165 static void       (*_sym_glFramebufferRenderbuffer)             (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) = NULL;
166 static void       (*_sym_glFramebufferTexture2D)                (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) = NULL;
167 static void       (*_sym_glFrontFace)                           (GLenum mode) = NULL;
168 static void       (*_sym_glGenBuffers)                          (GLsizei n, GLuint* buffers) = NULL;
169 static void       (*_sym_glGenerateMipmap)                      (GLenum target) = NULL;
170 static void       (*_sym_glGenFramebuffers)                     (GLsizei n, GLuint* framebuffers) = NULL;
171 static void       (*_sym_glGenRenderbuffers)                    (GLsizei n, GLuint* renderbuffers) = NULL;
172 static void       (*_sym_glGenTextures)                         (GLsizei n, GLuint* textures) = NULL;
173 static void       (*_sym_glGetActiveAttrib)                     (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) = NULL;
174 static void       (*_sym_glGetActiveUniform)                    (GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name) = NULL;
175 static void       (*_sym_glGetAttachedShaders)                  (GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders) = NULL;
176 static int        (*_sym_glGetAttribLocation)                   (GLuint program, const char* name) = NULL;
177 static void       (*_sym_glGetBooleanv)                         (GLenum pname, GLboolean* params) = NULL;
178 static void       (*_sym_glGetBufferParameteriv)                (GLenum target, GLenum pname, GLint* params) = NULL;
179 static GLenum     (*_sym_glGetError)                            (void) = NULL;
180 static void       (*_sym_glGetFloatv)                           (GLenum pname, GLfloat* params) = NULL;
181 static void       (*_sym_glGetFramebufferAttachmentParameteriv) (GLenum target, GLenum attachment, GLenum pname, GLint* params) = NULL;
182 static void       (*_sym_glGetIntegerv)                         (GLenum pname, GLint* params) = NULL;
183 static void       (*_sym_glGetProgramiv)                        (GLuint program, GLenum pname, GLint* params) = NULL;
184 static void       (*_sym_glGetProgramInfoLog)                   (GLuint program, GLsizei bufsize, GLsizei* length, char* infolog) = NULL;
185 static void       (*_sym_glGetRenderbufferParameteriv)          (GLenum target, GLenum pname, GLint* params) = NULL;
186 static void       (*_sym_glGetShaderiv)                         (GLuint shader, GLenum pname, GLint* params) = NULL;
187 static void       (*_sym_glGetShaderInfoLog)                    (GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog) = NULL;
188 static void       (*_sym_glGetShaderPrecisionFormat)            (GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision) = NULL;
189 static void       (*_sym_glGetShaderSource)                     (GLuint shader, GLsizei bufsize, GLsizei* length, char* source) = NULL;
190 static const GLubyte *(*_sym_glGetString)                           (GLenum name) = NULL;
191 static void       (*_sym_glGetTexParameterfv)                   (GLenum target, GLenum pname, GLfloat* params) = NULL;
192 static void       (*_sym_glGetTexParameteriv)                   (GLenum target, GLenum pname, GLint* params) = NULL;
193 static void       (*_sym_glGetUniformfv)                        (GLuint program, GLint location, GLfloat* params) = NULL;
194 static void       (*_sym_glGetUniformiv)                        (GLuint program, GLint location, GLint* params) = NULL;
195 static int        (*_sym_glGetUniformLocation)                  (GLuint program, const char* name) = NULL;
196 static void       (*_sym_glGetVertexAttribfv)                   (GLuint index, GLenum pname, GLfloat* params) = NULL;
197 static void       (*_sym_glGetVertexAttribiv)                   (GLuint index, GLenum pname, GLint* params) = NULL;
198 static void       (*_sym_glGetVertexAttribPointerv)             (GLuint index, GLenum pname, void** pointer) = NULL;
199 static void       (*_sym_glHint)                                (GLenum target, GLenum mode) = NULL;
200 static GLboolean  (*_sym_glIsBuffer)                            (GLuint buffer) = NULL;
201 static GLboolean  (*_sym_glIsEnabled)                           (GLenum cap) = NULL;
202 static GLboolean  (*_sym_glIsFramebuffer)                       (GLuint framebuffer) = NULL;
203 static GLboolean  (*_sym_glIsProgram)                           (GLuint program) = NULL;
204 static GLboolean  (*_sym_glIsRenderbuffer)                      (GLuint renderbuffer) = NULL;
205 static GLboolean  (*_sym_glIsShader)                            (GLuint shader) = NULL;
206 static GLboolean  (*_sym_glIsTexture)                           (GLuint texture) = NULL;
207 static void       (*_sym_glLineWidth)                           (GLfloat width) = NULL;
208 static void       (*_sym_glLinkProgram)                         (GLuint program) = NULL;
209 static void       (*_sym_glPixelStorei)                         (GLenum pname, GLint param) = NULL;
210 static void       (*_sym_glPolygonOffset)                       (GLfloat factor, GLfloat units) = NULL;
211 static void       (*_sym_glReadPixels)                          (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels) = NULL;
212 static void       (*_sym_glReleaseShaderCompiler)               (void) = NULL;
213 static void       (*_sym_glRenderbufferStorage)                 (GLenum target, GLenum internalformat, GLsizei width, GLsizei height) = NULL;
214 static void       (*_sym_glSampleCoverage)                      (GLclampf value, GLboolean invert) = NULL;
215 static void       (*_sym_glScissor)                             (GLint x, GLint y, GLsizei width, GLsizei height) = NULL;
216 static void       (*_sym_glShaderBinary)                        (GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length) = NULL;
217 static void       (*_sym_glShaderSource)                        (GLuint shader, GLsizei count, const char** string, const GLint* length) = NULL;
218 static void       (*_sym_glStencilFunc)                         (GLenum func, GLint ref, GLuint mask) = NULL;
219 static void       (*_sym_glStencilFuncSeparate)                 (GLenum face, GLenum func, GLint ref, GLuint mask) = NULL;
220 static void       (*_sym_glStencilMask)                         (GLuint mask) = NULL;
221 static void       (*_sym_glStencilMaskSeparate)                 (GLenum face, GLuint mask) = NULL;
222 static void       (*_sym_glStencilOp)                           (GLenum fail, GLenum zfail, GLenum zpass) = NULL;
223 static void       (*_sym_glStencilOpSeparate)                   (GLenum face, GLenum fail, GLenum zfail, GLenum zpass) = NULL;
224 static void       (*_sym_glTexImage2D)                          (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels) = NULL;
225 static void       (*_sym_glTexParameterf)                       (GLenum target, GLenum pname, GLfloat param) = NULL;
226 static void       (*_sym_glTexParameterfv)                      (GLenum target, GLenum pname, const GLfloat* params) = NULL;
227 static void       (*_sym_glTexParameteri)                       (GLenum target, GLenum pname, GLint param) = NULL;
228 static void       (*_sym_glTexParameteriv)                      (GLenum target, GLenum pname, const GLint* params) = NULL;
229 static void       (*_sym_glTexSubImage2D)                       (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels) = NULL;
230 static void       (*_sym_glUniform1f)                           (GLint location, GLfloat x) = NULL;
231 static void       (*_sym_glUniform1fv)                          (GLint location, GLsizei count, const GLfloat* v) = NULL;
232 static void       (*_sym_glUniform1i)                           (GLint location, GLint x) = NULL;
233 static void       (*_sym_glUniform1iv)                          (GLint location, GLsizei count, const GLint* v) = NULL;
234 static void       (*_sym_glUniform2f)                           (GLint location, GLfloat x, GLfloat y) = NULL;
235 static void       (*_sym_glUniform2fv)                          (GLint location, GLsizei count, const GLfloat* v) = NULL;
236 static void       (*_sym_glUniform2i)                           (GLint location, GLint x, GLint y) = NULL;
237 static void       (*_sym_glUniform2iv)                          (GLint location, GLsizei count, const GLint* v) = NULL;
238 static void       (*_sym_glUniform3f)                           (GLint location, GLfloat x, GLfloat y, GLfloat z) = NULL;
239 static void       (*_sym_glUniform3fv)                          (GLint location, GLsizei count, const GLfloat* v) = NULL;
240 static void       (*_sym_glUniform3i)                           (GLint location, GLint x, GLint y, GLint z) = NULL;
241 static void       (*_sym_glUniform3iv)                          (GLint location, GLsizei count, const GLint* v) = NULL;
242 static void       (*_sym_glUniform4f)                           (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) = NULL;
243 static void       (*_sym_glUniform4fv)                          (GLint location, GLsizei count, const GLfloat* v) = NULL;
244 static void       (*_sym_glUniform4i)                           (GLint location, GLint x, GLint y, GLint z, GLint w) = NULL;
245 static void       (*_sym_glUniform4iv)                          (GLint location, GLsizei count, const GLint* v) = NULL;
246 static void       (*_sym_glUniformMatrix2fv)                    (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) = NULL;
247 static void       (*_sym_glUniformMatrix3fv)                    (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) = NULL;
248 static void       (*_sym_glUniformMatrix4fv)                    (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) = NULL;
249 static void       (*_sym_glUseProgram)                          (GLuint program) = NULL;
250 static void       (*_sym_glValidateProgram)                     (GLuint program) = NULL;
251 static void       (*_sym_glVertexAttrib1f)                      (GLuint indx, GLfloat x) = NULL;
252 static void       (*_sym_glVertexAttrib1fv)                     (GLuint indx, const GLfloat* values) = NULL;
253 static void       (*_sym_glVertexAttrib2f)                      (GLuint indx, GLfloat x, GLfloat y) = NULL;
254 static void       (*_sym_glVertexAttrib2fv)                     (GLuint indx, const GLfloat* values) = NULL;
255 static void       (*_sym_glVertexAttrib3f)                      (GLuint indx, GLfloat x, GLfloat y, GLfloat z) = NULL;
256 static void       (*_sym_glVertexAttrib3fv)                     (GLuint indx, const GLfloat* values) = NULL;
257 static void       (*_sym_glVertexAttrib4f)                      (GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w) = NULL;
258 static void       (*_sym_glVertexAttrib4fv)                     (GLuint indx, const GLfloat* values) = NULL;
259 static void       (*_sym_glVertexAttribPointer)                 (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr) = NULL;
260 static void       (*_sym_glViewport)                            (GLint x, GLint y, GLsizei width, GLsizei height) = NULL;
261
262 // GLES Extensions...
263 static void       (*_sym_glGetProgramBinary)                    (GLuint a, GLsizei b, GLsizei* c, GLenum* d, void* e) = NULL;
264 static void       (*_sym_glProgramBinary)                       (GLuint a, GLenum b, const void* c, GLint d) = NULL;
265 static void       (*_sym_glProgramParameteri)                   (GLuint a, GLuint b, GLint d) = NULL;
266
267 /*
268  *****
269  **
270  ** ENGINE ROUTINES
271  **
272  *****
273  */
274 static int cpunum = 0;
275 static int _evas_soft_gen_log_dom = -1;
276
277 static void
278 eng_output_dump(void *data __UNUSED__)
279 {
280    evas_common_image_image_all_unload();
281    evas_common_font_font_all_unload();
282 }
283
284 static void *
285 eng_context_new(void *data __UNUSED__)
286 {
287    return evas_common_draw_context_new();
288 }
289
290 static void
291 eng_context_free(void *data __UNUSED__, void *context)
292 {
293    evas_common_draw_context_free(context);
294 }
295
296 static void
297 eng_context_clip_set(void *data __UNUSED__, void *context, int x, int y, int w, int h)
298 {
299    evas_common_draw_context_set_clip(context, x, y, w, h);
300 }
301
302 static void
303 eng_context_clip_clip(void *data __UNUSED__, void *context, int x, int y, int w, int h)
304 {
305    evas_common_draw_context_clip_clip(context, x, y, w, h);
306 }
307
308 static void
309 eng_context_clip_unset(void *data __UNUSED__, void *context)
310 {
311    evas_common_draw_context_unset_clip(context);
312 }
313
314 static int
315 eng_context_clip_get(void *data __UNUSED__, void *context, int *x, int *y, int *w, int *h)
316 {
317    *x = ((RGBA_Draw_Context *)context)->clip.x;
318    *y = ((RGBA_Draw_Context *)context)->clip.y;
319    *w = ((RGBA_Draw_Context *)context)->clip.w;
320    *h = ((RGBA_Draw_Context *)context)->clip.h;
321    return ((RGBA_Draw_Context *)context)->clip.use;
322 }
323
324 static void
325 eng_context_color_set(void *data __UNUSED__, void *context, int r, int g, int b, int a)
326 {
327    evas_common_draw_context_set_color(context, r, g, b, a);
328 }
329
330 static int
331 eng_context_color_get(void *data __UNUSED__, void *context, int *r, int *g, int *b, int *a)
332 {
333    *r = (int)(R_VAL(&((RGBA_Draw_Context *)context)->col.col));
334    *g = (int)(G_VAL(&((RGBA_Draw_Context *)context)->col.col));
335    *b = (int)(B_VAL(&((RGBA_Draw_Context *)context)->col.col));
336    *a = (int)(A_VAL(&((RGBA_Draw_Context *)context)->col.col));
337    return 1;
338 }
339
340 static void
341 eng_context_multiplier_set(void *data __UNUSED__, void *context, int r, int g, int b, int a)
342 {
343    evas_common_draw_context_set_multiplier(context, r, g, b, a);
344 }
345
346 static void
347 eng_context_multiplier_unset(void *data __UNUSED__, void *context)
348 {
349    evas_common_draw_context_unset_multiplier(context);
350 }
351
352 static int
353 eng_context_multiplier_get(void *data __UNUSED__, void *context, int *r, int *g, int *b, int *a)
354 {
355    *r = (int)(R_VAL(&((RGBA_Draw_Context *)context)->mul.col));
356    *g = (int)(G_VAL(&((RGBA_Draw_Context *)context)->mul.col));
357    *b = (int)(B_VAL(&((RGBA_Draw_Context *)context)->mul.col));
358    *a = (int)(A_VAL(&((RGBA_Draw_Context *)context)->mul.col));
359    return ((RGBA_Draw_Context *)context)->mul.use;
360 }
361
362 static void
363 eng_context_mask_set(void *data __UNUSED__, void *context, void *mask, int x, int y, int w, int h)
364 {
365    evas_common_draw_context_set_mask(context, mask, x, y, w, h);
366 }
367
368 static void
369 eng_context_mask_unset(void *data __UNUSED__, void *context)
370 {
371    evas_common_draw_context_unset_mask(context);
372 }
373 /*
374 static void *
375 eng_context_mask_get(void *data __UNUSED__, void *context)
376 {
377    return ((RGBA_Draw_Context *)context)->mask.mask;
378 }
379 */
380
381 static void
382 eng_context_cutout_add(void *data __UNUSED__, void *context, int x, int y, int w, int h)
383 {
384    evas_common_draw_context_add_cutout(context, x, y, w, h);
385 }
386
387 static void
388 eng_context_cutout_clear(void *data __UNUSED__, void *context)
389 {
390    evas_common_draw_context_clear_cutouts(context);
391 }
392
393 static void
394 eng_context_anti_alias_set(void *data __UNUSED__, void *context, unsigned char aa)
395 {
396    evas_common_draw_context_set_anti_alias(context, aa);
397 }
398
399 static unsigned char
400 eng_context_anti_alias_get(void *data __UNUSED__, void *context)
401 {
402    return ((RGBA_Draw_Context *)context)->anti_alias;
403 }
404
405 static void
406 eng_context_color_interpolation_set(void *data __UNUSED__, void *context, int color_space)
407 {
408    evas_common_draw_context_set_color_interpolation(context, color_space);
409 }
410
411 static int
412 eng_context_color_interpolation_get(void *data __UNUSED__, void *context)
413 {
414    return ((RGBA_Draw_Context *)context)->interpolation.color_space;
415 }
416
417 static void
418 eng_context_render_op_set(void *data __UNUSED__, void *context, int op)
419 {
420    evas_common_draw_context_set_render_op(context, op);
421 }
422
423 static int
424 eng_context_render_op_get(void *data __UNUSED__, void *context)
425 {
426    return ((RGBA_Draw_Context *)context)->render_op;
427 }
428
429
430
431 static void
432 eng_rectangle_draw(void *data __UNUSED__, void *context, void *surface, int x, int y, int w, int h)
433 {
434 #ifdef BUILD_PIPE_RENDER
435    if ((cpunum > 1)
436 #ifdef EVAS_FRAME_QUEUING
437         && evas_common_frameq_enabled()
438 #endif
439         )
440      evas_common_pipe_rectangle_draw(surface, context, x, y, w, h);
441    else
442 #endif
443      {
444         evas_common_rectangle_draw(surface, context, x, y, w, h);
445         evas_common_cpu_end_opt();
446      }
447 }
448
449 static void
450 eng_line_draw(void *data __UNUSED__, void *context, void *surface, int x1, int y1, int x2, int y2)
451 {
452 #ifdef BUILD_PIPE_RENDER
453    if ((cpunum > 1)
454  #ifdef EVAS_FRAME_QUEUING
455         && evas_common_frameq_enabled()
456 #endif
457         )
458     evas_common_pipe_line_draw(surface, context, x1, y1, x2, y2);
459    else
460 #endif   
461      {
462         evas_common_line_draw(surface, context, x1, y1, x2, y2);
463         evas_common_cpu_end_opt();
464      }
465 }
466
467 static void *
468 eng_polygon_point_add(void *data __UNUSED__, void *context __UNUSED__, void *polygon, int x, int y)
469 {
470    return evas_common_polygon_point_add(polygon, x, y);
471 }
472
473 static void *
474 eng_polygon_points_clear(void *data __UNUSED__, void *context __UNUSED__, void *polygon)
475 {
476    return evas_common_polygon_points_clear(polygon);
477 }
478
479 static void
480 eng_polygon_draw(void *data __UNUSED__, void *context, void *surface, void *polygon, int x, int y)
481 {
482 #ifdef BUILD_PIPE_RENDER
483    if ((cpunum > 1)
484 #ifdef EVAS_FRAME_QUEUING
485         && evas_common_frameq_enabled()
486 #endif
487         )
488      evas_common_pipe_poly_draw(surface, context, polygon, x, y);
489    else
490 #endif
491      {
492         evas_common_polygon_draw(surface, context, polygon, x, y);
493         evas_common_cpu_end_opt();
494      }
495 }
496
497 static int
498 eng_image_alpha_get(void *data __UNUSED__, void *image)
499 {
500    Image_Entry *im;
501
502    if (!image) return 1;
503    im = image;
504    switch (im->space)
505      {
506       case EVAS_COLORSPACE_ARGB8888:
507         if (im->flags.alpha) return 1;
508       default:
509         break;
510      }
511    return 0;
512 }
513
514 static int
515 eng_image_colorspace_get(void *data __UNUSED__, void *image)
516 {
517    Image_Entry *im;
518
519    if (!image) return EVAS_COLORSPACE_ARGB8888;
520    im = image;
521    return im->space;
522 }
523
524 static Eina_Bool
525 eng_image_can_region_get(void *data __UNUSED__, void *image)
526 {
527    Image_Entry *im;
528    if (!image) return EINA_FALSE;
529    im = image;
530    return ((Evas_Image_Load_Func*) im->info.loader)->do_region;
531 }
532
533 static void
534 eng_image_mask_create(void *data __UNUSED__, void *image)
535 {
536    RGBA_Image *im;
537    int sz;
538    uint8_t *dst,*end;
539    uint32_t *src;
540
541    if (!image) return;
542    im = image;
543    if (im->mask.mask && !im->mask.dirty) return;
544
545    if (im->mask.mask) free(im->mask.mask);
546    sz = im->cache_entry.w * im->cache_entry.h;
547    im->mask.mask = malloc(sz);
548    dst = im->mask.mask;
549    if (!im->image.data)
550       evas_cache_image_load_data(&im->cache_entry);
551    src = (void*) im->image.data;
552    if (!src) return;
553    for (end = dst + sz ; dst < end ; dst ++, src ++)
554       *dst = *src >> 24;
555    im->mask.dirty = 0;
556 }
557
558
559 static void *
560 eng_image_alpha_set(void *data __UNUSED__, void *image, int has_alpha)
561 {
562    RGBA_Image *im;
563
564    if (!image) return NULL;
565    im = image;
566    if (im->cache_entry.space != EVAS_COLORSPACE_ARGB8888)
567      {
568         im->cache_entry.flags.alpha = 0;
569         return im;
570      }
571    im = (RGBA_Image *) evas_cache_image_alone(&im->cache_entry);
572    evas_common_image_colorspace_dirty(im);
573
574    im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
575    return im;
576 }
577
578 static void *
579 eng_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
580 {
581    RGBA_Image *im;
582
583    im = image;
584    return im;
585 }
586
587 static void
588 eng_image_border_get(void *data __UNUSED__, void *image, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
589 {
590    RGBA_Image *im;
591
592    im = image;
593 }
594
595 static char *
596 eng_image_comment_get(void *data __UNUSED__, void *image, char *key __UNUSED__)
597 {
598    RGBA_Image *im;
599
600    if (!image) return NULL;
601    im = image;
602    return im->info.comment;
603 }
604
605 static char *
606 eng_image_format_get(void *data __UNUSED__, void *image __UNUSED__)
607 {
608    return NULL;
609 }
610
611 static void
612 eng_image_colorspace_set(void *data __UNUSED__, void *image, int cspace)
613 {
614    Image_Entry *im;
615
616    if (!image) return;
617    im = image;
618    evas_cache_image_colorspace(im, cspace);
619 }
620
621 static void *
622 eng_image_native_set(void *data __UNUSED__, void *image, void *native __UNUSED__)
623 {
624    //return image;
625    Evas_Native_Surface *ns = native;
626    Image_Entry *im = image, *im2 = NULL;
627
628    if (!im)
629      {
630         if ((!ns) && (ns->data.x11.visual))
631           {
632              im = evas_cache_image_data(evas_common_image_cache_get(),
633                                         im->w, im->h,
634                                         ns->data.x11.visual, 1,
635                                         EVAS_COLORSPACE_ARGB8888);
636              return im;
637           }
638         else
639            return NULL;
640      }
641
642    if ((!ns) && (!im)) return im;
643
644    if (!ns) return im;
645
646    im2 = evas_cache_image_data(evas_common_image_cache_get(), 
647                                im->w, im->h, 
648                                ns->data.x11.visual, 1,
649                                EVAS_COLORSPACE_ARGB8888);
650    evas_cache_image_drop(im);
651    im = im2;
652
653    return im;
654
655 }
656
657 static void *
658 eng_image_native_get(void *data __UNUSED__, void *image __UNUSED__)
659 {
660    return NULL;
661 }
662
663 static void *
664 eng_image_load(void *data __UNUSED__, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
665 {
666    *error = EVAS_LOAD_ERROR_NONE;
667    return evas_common_load_image_from_file(file, key, lo, error);
668 }
669
670 static void *
671 eng_image_new_from_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
672 {
673    return evas_cache_image_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
674 }
675
676 static void *
677 eng_image_new_from_copied_data(void *data __UNUSED__, int w, int h, DATA32 *image_data, int alpha, int cspace)
678 {
679    return evas_cache_image_copied_data(evas_common_image_cache_get(), w, h, image_data, alpha, cspace);
680 }
681
682 static void
683 eng_image_free(void *data __UNUSED__, void *image)
684 {
685    evas_cache_image_drop(image);
686 }
687
688 static void
689 eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
690 {
691    Image_Entry *im;
692
693    im = image;
694    if (w) *w = im->w;
695    if (h) *h = im->h;
696 }
697
698 static void *
699 eng_image_size_set(void *data __UNUSED__, void *image, int w, int h)
700 {
701    Image_Entry *im;
702
703    im = image;
704    return evas_cache_image_size_set(image, w, h);
705 }
706
707 static void *
708 eng_image_dirty_region(void *data __UNUSED__, void *image, int x, int y, int w, int h)
709 {
710    Image_Entry *im = image;
711
712    if (!image) return NULL;
713    return evas_cache_image_dirty(im, x, y, w, h);
714 }
715
716 static void *
717 eng_image_data_get(void *data __UNUSED__, void *image, int to_write, DATA32 **image_data, int *err)
718 {
719    RGBA_Image *im;
720    int error;
721
722    if (!image)
723      {
724         *image_data = NULL;
725         return NULL;
726      }
727    im = image;
728    error = evas_cache_image_load_data(&im->cache_entry);
729    switch (im->cache_entry.space)
730      {
731       case EVAS_COLORSPACE_ARGB8888:
732         if (to_write)
733           im = (RGBA_Image *)evas_cache_image_alone(&im->cache_entry);
734         *image_data = im->image.data;
735         break;
736       case EVAS_COLORSPACE_YCBCR422P601_PL:
737       case EVAS_COLORSPACE_YCBCR422P709_PL:
738       case EVAS_COLORSPACE_YCBCR422601_PL:
739       case EVAS_COLORSPACE_YCBCR420NV12601_PL:
740       case EVAS_COLORSPACE_YCBCR420TM12601_PL:
741         *image_data = im->cs.data;
742         break;
743       default:
744         abort();
745         break;
746      }
747    if (err) *err = error;
748    return im;
749 }
750
751 static void *
752 eng_image_data_put(void *data, void *image, DATA32 *image_data)
753 {
754    RGBA_Image *im, *im2;
755
756    if (!image) return NULL;
757    im = image;
758    switch (im->cache_entry.space)
759      {
760       case EVAS_COLORSPACE_ARGB8888:
761         if (image_data != im->image.data)
762           {
763              int w, h;
764
765              w = im->cache_entry.w;
766              h = im->cache_entry.h;
767              im2 = eng_image_new_from_data(data, w, h, image_data,
768                                            eng_image_alpha_get(data, image),
769                                            eng_image_colorspace_get(data, image));
770              evas_cache_image_drop(&im->cache_entry);
771              im = im2;
772           }
773         break;
774       case EVAS_COLORSPACE_YCBCR422P601_PL:
775       case EVAS_COLORSPACE_YCBCR422P709_PL:
776       case EVAS_COLORSPACE_YCBCR422601_PL:
777       case EVAS_COLORSPACE_YCBCR420NV12601_PL:
778       case EVAS_COLORSPACE_YCBCR420TM12601_PL:
779         if (image_data != im->cs.data)
780           {
781              if (im->cs.data)
782                {
783                   if (!im->cs.no_free) free(im->cs.data);
784                }
785              im->cs.data = image_data;
786           }
787         evas_common_image_colorspace_dirty(im);
788         break;
789       default:
790         abort();
791         break;
792      }
793    return im;
794 }
795
796 static void
797 eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
798 {
799    RGBA_Image *im = image;
800
801    if (!im) return ;
802    evas_cache_image_preload_data(&im->cache_entry, target);
803 }
804
805 static void
806 eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
807 {
808    RGBA_Image *im = image;
809
810    if (!im) return ;
811    evas_cache_image_preload_cancel(&im->cache_entry, target);
812 }
813
814 static void
815 eng_image_draw(void *data __UNUSED__, void *context, void *surface, void *image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int smooth)
816 {
817    RGBA_Image *im;
818
819    if (!image) return;
820    im = image;
821 #ifdef BUILD_PIPE_RENDER
822    if ((cpunum > 1)
823 #ifdef EVAS_FRAME_QUEUING
824         && evas_common_frameq_enabled()
825 #endif
826         )
827      {
828         evas_common_rgba_image_scalecache_prepare((Image_Entry *)(im), 
829                                                   surface, context, smooth,
830                                                   src_x, src_y, src_w, src_h,
831                                                   dst_x, dst_y, dst_w, dst_h);
832         
833         evas_common_pipe_image_draw(im, surface, context, smooth,
834                                     src_x, src_y, src_w, src_h,
835                                     dst_x, dst_y, dst_w, dst_h);
836      }
837    else
838 #endif
839      {
840 //        if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
841 //          evas_cache_image_load_data(&im->cache_entry);
842 //        evas_common_image_colorspace_normalize(im);
843         evas_common_rgba_image_scalecache_prepare(&im->cache_entry, surface, context, smooth,
844                                                   src_x, src_y, src_w, src_h,
845                                                   dst_x, dst_y, dst_w, dst_h);
846         evas_common_rgba_image_scalecache_do(&im->cache_entry, surface, context, smooth,
847                                              src_x, src_y, src_w, src_h,
848                                              dst_x, dst_y, dst_w, dst_h);
849 /*        
850         if (smooth)
851           evas_common_scale_rgba_in_to_out_clip_smooth(im, surface, context,
852                                                        src_x, src_y, src_w, src_h,
853                                                        dst_x, dst_y, dst_w, dst_h);
854         else
855           evas_common_scale_rgba_in_to_out_clip_sample(im, surface, context,
856                                                        src_x, src_y, src_w, src_h,
857                                                        dst_x, dst_y, dst_w, dst_h);
858  */
859         evas_common_cpu_end_opt();
860      }
861 }
862
863 static void
864 eng_image_map_draw(void *data __UNUSED__, void *context, void *surface, void *image, int npoints, RGBA_Map_Point *p, int smooth, int level)
865 {
866    RGBA_Image *im;
867
868    if (!image) return;
869    if (npoints < 3) return;
870    im = image;
871
872    if ((p[0].x == p[3].x) &&
873        (p[1].x == p[2].x) &&
874        (p[0].y == p[1].y) &&
875        (p[3].y == p[2].y) &&
876        (p[0].x <= p[1].x) &&
877        (p[0].y <= p[2].y) &&
878        (p[0].u == 0) &&
879        (p[0].v == 0) &&
880        (p[1].u == (int)(im->cache_entry.w << FP)) &&
881        (p[1].v == 0) &&
882        (p[2].u == (int)(im->cache_entry.w << FP)) &&
883        (p[2].v == (int)(im->cache_entry.h << FP)) &&
884        (p[3].u == 0) &&
885        (p[3].v == (int)(im->cache_entry.h << FP)) &&
886        (p[0].col == 0xffffffff) &&
887        (p[1].col == 0xffffffff) &&
888        (p[2].col == 0xffffffff) &&
889        (p[3].col == 0xffffffff))
890      {
891         int dx, dy, dw, dh;
892
893         dx = p[0].x >> FP;
894         dy = p[0].y >> FP;
895         dw = (p[2].x >> FP) - dx;
896         dh = (p[2].y >> FP) - dy;
897         eng_image_draw
898           (data, context, surface, image,
899            0, 0, im->cache_entry.w, im->cache_entry.h,
900            dx, dy, dw, dh, smooth);
901      }
902    else
903      {
904 #ifdef BUILD_PIPE_RENDER
905         if ((cpunum > 1)
906 # ifdef EVAS_FRAME_QUEUING
907        && evas_common_frameq_enabled()
908 # endif
909         )
910           evas_common_pipe_map_draw(im, surface, context, npoints, p, smooth, level);
911         else
912 #endif
913           evas_common_map_rgba(im, surface, context, npoints, p, smooth, level);
914      }
915    evas_common_cpu_end_opt();
916
917    if (npoints > 4)
918      {
919         eng_image_map_draw(data, context, surface, image, npoints - 2, p + 2,
920                            smooth, level);
921      }
922 }
923
924 static void *
925 eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
926 {
927    void *surface;
928    DATA32 *pixels;
929    surface = evas_cache_image_copied_data(evas_common_image_cache_get(), 
930                                           w, h, NULL, alpha, 
931                                           EVAS_COLORSPACE_ARGB8888);
932    pixels = evas_cache_image_pixels(surface);
933    return surface;
934 }
935
936 static void
937 eng_image_map_surface_free(void *data __UNUSED__, void *surface)
938 {
939    evas_cache_image_drop(surface);
940 }
941
942 static void
943 eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
944 {
945    Image_Entry *im;
946
947    if (!image) return;
948    im = image;
949    im->scale_hint = hint;
950 }
951
952 static int
953 eng_image_scale_hint_get(void *data __UNUSED__, void *image)
954 {
955    Image_Entry *im;
956
957    if (!image) return EVAS_IMAGE_SCALE_HINT_NONE;
958    im = image;
959    return im->scale_hint;
960 }
961
962 static Eina_Bool
963 eng_image_animated_get(void *data __UNUSED__, void *image)
964 {
965    Image_Entry *im;
966
967    if (!image) return EINA_FALSE;
968    im = image;
969    return im->flags.animated;
970 }
971
972 static int
973 eng_image_animated_frame_count_get(void *data __UNUSED__, void *image)
974 {
975    Image_Entry *im;
976
977    if (!image) return -1;
978    im = image;
979    if (!im->flags.animated) return -1;
980    return im->frame_count;
981 }
982
983 static Evas_Image_Animated_Loop_Hint
984 eng_image_animated_loop_type_get(void *data __UNUSED__, void *image)
985 {
986    Image_Entry *im;
987
988    if (!image) return EVAS_IMAGE_ANIMATED_HINT_NONE;
989    im = image;
990    if (!im->flags.animated) return EVAS_IMAGE_ANIMATED_HINT_NONE;
991    return im->loop_hint;
992 }
993
994 static int
995 eng_image_animated_loop_count_get(void *data __UNUSED__, void *image)
996 {
997    Image_Entry *im;
998
999    if (!image) return -1;
1000    im = image;
1001    if (!im->flags.animated) return -1;
1002    return im->loop_count;
1003 }
1004
1005 static double
1006 eng_image_animated_frame_duration_get(void *data __UNUSED__, void *image, int start_frame, int frame_num)
1007 {
1008    Image_Entry *im;
1009
1010    if (!image) return -1;
1011    im = image;
1012    if (!im->flags.animated) return -1;
1013    return evas_common_load_rgba_image_frame_duration_from_file(im, start_frame, frame_num);
1014 }
1015
1016 static Eina_Bool
1017 eng_image_animated_frame_set(void *data __UNUSED__, void *image, int frame_index)
1018 {
1019    Image_Entry *im;
1020
1021    if (!image) return EINA_FALSE;
1022    im = image;
1023    if (!im->flags.animated) return EINA_FALSE;
1024    if (im->cur_frame == frame_index) return EINA_FALSE;
1025    im->cur_frame = frame_index;
1026    return EINA_TRUE;
1027 }
1028
1029 static void
1030 eng_image_cache_flush(void *data __UNUSED__)
1031 {
1032    int tmp_size;
1033
1034    tmp_size = evas_common_image_get_cache();
1035    evas_common_image_set_cache(0);
1036    evas_common_rgba_image_scalecache_flush();
1037    evas_common_image_set_cache(tmp_size);
1038 }
1039
1040 static void
1041 eng_image_cache_set(void *data __UNUSED__, int bytes)
1042 {
1043    evas_common_image_set_cache(bytes);
1044    evas_common_rgba_image_scalecache_size_set(bytes);
1045 }
1046
1047 static int
1048 eng_image_cache_get(void *data __UNUSED__)
1049 {
1050    return evas_common_image_get_cache();
1051 }
1052
1053 static Evas_Font_Set *
1054 eng_font_load(void *data __UNUSED__, const char *name, int size,
1055       Font_Rend_Flags wanted_rend)
1056 {
1057    return (Evas_Font_Set *) evas_common_font_load(name, size, wanted_rend);
1058 }
1059
1060 static Evas_Font_Set *
1061 eng_font_memory_load(void *data __UNUSED__, char *name, int size, const void *fdata, int fdata_size, Font_Rend_Flags wanted_rend)
1062 {
1063    return (Evas_Font_Set *) evas_common_font_memory_load(name, size, fdata,
1064          fdata_size, wanted_rend);
1065 }
1066
1067 static Evas_Font_Set *
1068 eng_font_add(void *data __UNUSED__, Evas_Font_Set *font, const char *name, int size, Font_Rend_Flags wanted_rend)
1069 {
1070    return (Evas_Font_Set *) evas_common_font_add((RGBA_Font *) font, name,
1071          size, wanted_rend);
1072 }
1073
1074 static Evas_Font_Set *
1075 eng_font_memory_add(void *data __UNUSED__, Evas_Font_Set *font, char *name, int size, const void *fdata, int fdata_size, Font_Rend_Flags wanted_rend)
1076 {
1077    return (Evas_Font_Set *) evas_common_font_memory_add((RGBA_Font *) font,
1078          name, size, fdata, fdata_size, wanted_rend);
1079 }
1080
1081 static void
1082 eng_font_free(void *data __UNUSED__, Evas_Font_Set *font)
1083 {
1084    evas_common_font_free((RGBA_Font *) font);
1085 }
1086
1087 static int
1088 eng_font_ascent_get(void *data __UNUSED__, Evas_Font_Set *font)
1089 {
1090    return evas_common_font_ascent_get((RGBA_Font *) font);
1091 }
1092
1093 static int
1094 eng_font_descent_get(void *data __UNUSED__, Evas_Font_Set *font)
1095 {
1096    return evas_common_font_descent_get((RGBA_Font *) font);
1097 }
1098
1099 static int
1100 eng_font_max_ascent_get(void *data __UNUSED__, Evas_Font_Set *font)
1101 {
1102    return evas_common_font_max_ascent_get((RGBA_Font *) font);
1103 }
1104
1105 static int
1106 eng_font_max_descent_get(void *data __UNUSED__, Evas_Font_Set *font)
1107 {
1108    return evas_common_font_max_descent_get((RGBA_Font *) font);
1109 }
1110
1111 static void
1112 eng_font_string_size_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int *w, int *h)
1113 {
1114    evas_common_font_query_size((RGBA_Font *) font, text_props, w, h);
1115 }
1116
1117 static int
1118 eng_font_inset_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
1119 {
1120    return evas_common_font_query_inset((RGBA_Font *) font, text_props);
1121 }
1122
1123 static int
1124 eng_font_right_inset_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
1125 {
1126    return evas_common_font_query_right_inset((RGBA_Font *) font, text_props);
1127 }
1128
1129 static int
1130 eng_font_h_advance_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
1131 {
1132    int h, v;
1133
1134    evas_common_font_query_advance((RGBA_Font *) font, text_props, &h, &v);
1135    return h;
1136 }
1137
1138 static int
1139 eng_font_v_advance_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props)
1140 {
1141    int h, v;
1142
1143    evas_common_font_query_advance((RGBA_Font *) font, text_props, &h, &v);
1144    return v;
1145 }
1146
1147 static int
1148 eng_font_pen_coords_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int pos, int *cpen_x, int *cy, int *cadv, int *ch)
1149 {
1150    return evas_common_font_query_pen_coords((RGBA_Font *) font, text_props, pos, cpen_x, cy, cadv, ch);
1151 }
1152
1153 static Eina_Bool
1154 eng_font_text_props_info_create(void *data __UNUSED__, Evas_Font_Instance *fi, const Eina_Unicode *text, Evas_Text_Props *text_props, const Evas_BiDi_Paragraph_Props *par_props, size_t par_pos, size_t len)
1155 {
1156    return evas_common_text_props_content_create((RGBA_Font_Int *) fi, text,
1157          text_props, par_props, par_pos, len);
1158 }
1159
1160 static int
1161 eng_font_char_coords_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int pos, int *cx, int *cy, int *cw, int *ch)
1162 {
1163    return evas_common_font_query_char_coords((RGBA_Font *) font, text_props, pos, cx, cy, cw, ch);
1164 }
1165
1166 static int
1167 eng_font_char_at_coords_get(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int x, int y, int *cx, int *cy, int *cw, int *ch)
1168 {
1169    return evas_common_font_query_char_at_coords((RGBA_Font *) font, text_props, x, y, cx, cy, cw, ch);
1170 }
1171
1172 static int
1173 eng_font_last_up_to_pos(void *data __UNUSED__, Evas_Font_Set *font, const Evas_Text_Props *text_props, int x, int y)
1174 {
1175    return evas_common_font_query_last_up_to_pos((RGBA_Font *) font, text_props, x, y);
1176 }
1177
1178 static int
1179 eng_font_run_font_end_get(void *data __UNUSED__, Evas_Font_Set *font, Evas_Font_Instance **script_fi, Evas_Font_Instance **cur_fi, Evas_Script_Type script, const Eina_Unicode *text, int run_len)
1180 {
1181    return evas_common_font_query_run_font_end_get((RGBA_Font *) font,
1182          (RGBA_Font_Int **) script_fi, (RGBA_Font_Int **) cur_fi,
1183          script, text, run_len);
1184 }
1185
1186 static void
1187 eng_font_draw(void *data __UNUSED__, void *context, void *surface, Evas_Font_Set *font, int x, int y, int w __UNUSED__, int h __UNUSED__, int ow __UNUSED__, int oh __UNUSED__, const Evas_Text_Props *text_props)
1188 {
1189 #ifdef BUILD_PIPE_RENDER
1190    if ((cpunum > 1)
1191 #ifdef EVAS_FRAME_QUEUING
1192         && evas_common_frameq_enabled()
1193 #endif
1194         )
1195      evas_common_pipe_text_draw(surface, context, (RGBA_Font *) font, x, y,
1196            text_props);
1197    else
1198 #endif   
1199      {
1200         evas_common_font_draw(surface, context, (RGBA_Font *) font, x, y,
1201               text_props);
1202         evas_common_cpu_end_opt();
1203      }
1204 }
1205
1206 static void
1207 eng_font_cache_flush(void *data __UNUSED__)
1208 {
1209    int tmp_size;
1210
1211    tmp_size = evas_common_font_cache_get();
1212    evas_common_font_cache_set(0);
1213    evas_common_font_flush();
1214    evas_common_font_cache_set(tmp_size);
1215 }
1216
1217 static void
1218 eng_font_cache_set(void *data __UNUSED__, int bytes)
1219 {
1220    evas_common_font_cache_set(bytes);
1221 }
1222
1223 static int
1224 eng_font_cache_get(void *data __UNUSED__)
1225 {
1226    return evas_common_font_cache_get();
1227 }
1228
1229 static void
1230 eng_font_hinting_set(void *data __UNUSED__, Evas_Font_Set *font, int hinting)
1231 {
1232    evas_common_font_hinting_set((RGBA_Font *) font, hinting);
1233 }
1234
1235 static int
1236 eng_font_hinting_can_hint(void *data __UNUSED__, int hinting)
1237 {
1238    return evas_common_hinting_available(hinting);
1239 }
1240
1241 static Eina_Bool
1242 eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
1243 {
1244    return EINA_TRUE;
1245 }
1246
1247
1248 /* Filter API */
1249 #if 0 // filtering disabled
1250 static void
1251 eng_image_draw_filtered(void *data __UNUSED__, void *context __UNUSED__,
1252                         void *surface, void *image, Evas_Filter_Info *filter)
1253 {
1254    Evas_Software_Filter_Fn fn;
1255    RGBA_Image *im = image;
1256
1257    fn = evas_filter_software_get(filter);
1258    if (!fn) return;
1259    if (im->cache_entry.cache) evas_cache_image_load_data(&im->cache_entry);
1260    fn(filter, image, surface);
1261    return;
1262 }
1263
1264 static Filtered_Image *
1265 eng_image_filtered_get(void *image, uint8_t *key, size_t keylen)
1266 {
1267    RGBA_Image *im = image;
1268    Filtered_Image *fi;
1269    Eina_List *l;
1270
1271    for (l = im->filtered ; l ; l = l->next)
1272      {
1273          fi = l->data;
1274          if (fi->keylen != keylen) continue;
1275          if (memcmp(key, fi->key, keylen) != 0) continue;
1276          fi->ref ++;
1277          return fi;
1278      }
1279
1280    return NULL;
1281 }
1282
1283 static Filtered_Image *
1284 eng_image_filtered_save(void *image, void *fimage, uint8_t *key, size_t keylen)
1285 {
1286    RGBA_Image *im = image;
1287    Filtered_Image *fi;
1288    Eina_List *l;
1289
1290    for (l = im->filtered ; l ; l = l->next)
1291      {
1292         fi = l->data;
1293         if (fi->keylen != keylen) continue;
1294         if (memcmp(key, fi->key, keylen) == 0) continue;
1295         evas_cache_image_drop((void *)fi->image);
1296         fi->image = fimage;
1297         return fi;
1298      }
1299
1300    fi = calloc(1,sizeof(Filtered_Image));
1301    if (!fi) return NULL;
1302
1303    fi->keylen = keylen;
1304    fi->key = malloc(keylen);
1305    memcpy(fi->key, key, keylen);
1306    fi->image = fimage;
1307    fi->ref = 1;
1308
1309    im->filtered = eina_list_prepend(im->filtered, fi);
1310
1311    return fi;
1312 }
1313
1314 static void
1315 eng_image_filtered_free(void *image, Filtered_Image *fi)
1316 {
1317    RGBA_Image *im = image;
1318
1319    fi->ref --;
1320    if (fi->ref) return;
1321
1322    free(fi->key);
1323    evas_cache_image_drop(&fi->image->cache_entry);
1324    fi->image = NULL;
1325
1326    im->filtered = eina_list_remove(im->filtered, fi);
1327 }
1328 #endif
1329
1330 static int
1331 eng_image_load_error_get(void *data __UNUSED__, void *image)
1332 {
1333    RGBA_Image *im;
1334    
1335    if (!image) return EVAS_LOAD_ERROR_NONE;
1336    im = image;
1337    return im->cache_entry.load_error;
1338 }
1339
1340 //------------ Evas GL engine code ---------------//
1341 static void *
1342 eng_gl_surface_create(void *data __UNUSED__, void *config, int w, int h)
1343 {
1344    Render_Engine_GL_Surface *sfc;
1345    Evas_GL_Config *cfg;
1346
1347    sfc = calloc(1, sizeof(Render_Engine_GL_Surface));
1348    if (!sfc) return NULL;
1349
1350    cfg = (Evas_GL_Config *)config;
1351
1352    sfc->initialized  = 0;
1353    sfc->w            = w;
1354    sfc->h            = h;
1355
1356    // Color Format
1357    switch (cfg->color_format)
1358      {
1359
1360       case EVAS_GL_RGB_888:
1361          sfc->internal_fmt = OSMESA_RGB;
1362          sfc->internal_cpp = 3;
1363          break;
1364       case EVAS_GL_RGBA_8888:
1365          sfc->internal_fmt = OSMESA_BGRA;
1366          sfc->internal_cpp = 4;
1367          break;
1368       default:
1369          sfc->internal_fmt = OSMESA_RGBA;
1370          sfc->internal_cpp = 4;
1371          break;
1372      }
1373
1374    // Depth Bits
1375    switch (cfg->depth_bits)
1376      {
1377       case EVAS_GL_DEPTH_BIT_8:
1378          sfc->depth_bits = 8;
1379          break;
1380       case EVAS_GL_DEPTH_BIT_16:
1381          sfc->depth_bits = 16;
1382          break;
1383       case EVAS_GL_DEPTH_BIT_24:
1384          sfc->depth_bits = 24;
1385          break;
1386       case EVAS_GL_DEPTH_BIT_32:
1387          sfc->depth_bits = 32;
1388          break;
1389       case EVAS_GL_DEPTH_NONE:
1390       default:
1391          sfc->depth_bits = 0;
1392          break;
1393      }
1394    
1395    // Stencil Bits
1396    switch (cfg->stencil_bits)
1397      {
1398       case EVAS_GL_STENCIL_BIT_1:
1399          sfc->stencil_bits = 1;
1400          break;
1401       case EVAS_GL_STENCIL_BIT_2:
1402          sfc->stencil_bits = 2;
1403          break;
1404       case EVAS_GL_STENCIL_BIT_4:
1405          sfc->stencil_bits = 4;
1406          break;
1407       case EVAS_GL_STENCIL_BIT_8:
1408          sfc->stencil_bits = 8;
1409          break;
1410       case EVAS_GL_STENCIL_BIT_16:
1411          sfc->stencil_bits = 16;
1412          break;
1413       case EVAS_GL_STENCIL_NONE:
1414       default:
1415          sfc->stencil_bits = 0;
1416          break;
1417      }
1418
1419    sfc->buffer = malloc(sizeof(unsigned char)*sfc->internal_cpp*w*h);
1420
1421    if (!sfc->buffer)
1422      {
1423         free(sfc);
1424         return NULL;
1425      }
1426
1427    return sfc;
1428 }
1429
1430 static int
1431 eng_gl_surface_destroy(void *data __UNUSED__, void *surface)
1432 {
1433    Render_Engine_GL_Surface *sfc;
1434
1435    sfc = (Render_Engine_GL_Surface*)surface;
1436
1437    if (!sfc) return 0;
1438
1439    if (sfc->buffer) free(sfc->buffer);
1440
1441    free(sfc);
1442
1443    surface = NULL;
1444
1445    return 1;
1446 }
1447
1448 static void *
1449 eng_gl_context_create(void *data __UNUSED__, void *share_context)
1450 {
1451    Render_Engine_GL_Context *ctx;
1452    Render_Engine_GL_Context *share_ctx;
1453
1454    ctx = calloc(1, sizeof(Render_Engine_GL_Context));
1455
1456    if (!ctx) return NULL;
1457
1458    share_ctx = (Render_Engine_GL_Context *)share_context;
1459
1460    ctx->share_ctx = share_ctx;
1461
1462    /*
1463    if (share_ctx)
1464       ctx->context = OSMesaCreateContextExt( OSMESA_RGBA, 8, 0, 0, share_ctx->context );
1465    else
1466       ctx->context = OSMesaCreateContextExt( OSMESA_RGBA, 8, 0, 0, NULL );
1467
1468
1469    if (!ctx->context)
1470      {
1471         ERR("Error creating OSMesa Context.");
1472         free(ctx);
1473         return NULL;
1474      }
1475      */
1476
1477    ctx->initialized = 0;
1478
1479    return ctx;
1480 }
1481
1482 static int
1483 eng_gl_context_destroy(void *data __UNUSED__, void *context)
1484 {
1485    Render_Engine_GL_Context *ctx;
1486
1487    ctx = (Render_Engine_GL_Context*)context;
1488
1489    if (!ctx) return 0;
1490
1491    _sym_OSMesaDestroyContext(ctx->context);
1492
1493    free(ctx);
1494    context = NULL;
1495
1496    return 1;
1497 }
1498
1499 static int
1500 eng_gl_make_current(void *data __UNUSED__, void *surface, void *context)
1501 {
1502    Render_Engine_GL_Surface *sfc;
1503    Render_Engine_GL_Context *ctx;
1504    OSMesaContext share_ctx;
1505    GLboolean ret;
1506
1507    sfc = (Render_Engine_GL_Surface*)surface;
1508    ctx = (Render_Engine_GL_Context*)context;
1509
1510    // Unset surface/context
1511    if ((!sfc) || (!ctx))
1512      {
1513         if (ctx) ctx->current_sfc = NULL;
1514         if (sfc) sfc->current_ctx = NULL;
1515         return 1;
1516      }
1517
1518    // Initialize Context if it hasn't been.
1519    if (!ctx->initialized)
1520      {
1521         if (ctx->share_ctx)
1522            share_ctx = ctx->share_ctx->context;
1523         else
1524            share_ctx = NULL;
1525
1526         ctx->context =  _sym_OSMesaCreateContextExt(sfc->internal_fmt, 
1527                                                sfc->depth_bits,
1528                                                sfc->stencil_bits, 
1529                                                0,
1530                                                share_ctx);
1531         if (!ctx->context)
1532           {
1533              ERR("Error initializing context.");
1534              return 0;
1535           }
1536
1537         ctx->initialized = 1;
1538      }
1539
1540
1541    // Call MakeCurrent
1542    ret = _sym_OSMesaMakeCurrent(ctx->context, sfc->buffer, GL_UNSIGNED_BYTE, 
1543                            sfc->w, sfc->h);
1544
1545    if (ret == GL_FALSE)
1546      {
1547         ERR("Error doing MakeCurrent.");
1548         return 0;
1549      }
1550
1551    _sym_OSMesaPixelStore(OSMESA_Y_UP, 0);
1552
1553    // Set the current surface/context
1554    ctx->current_sfc = sfc;
1555    sfc->current_ctx = ctx;
1556
1557    return 1;
1558 }
1559
1560 // FIXME!!! Implement later
1561 static void *
1562 eng_gl_string_query(void *data, int name)
1563 {
1564    return NULL;
1565 }
1566
1567 static void *
1568 eng_gl_proc_address_get(void *data __UNUSED__, const char *name)
1569 {
1570    if (_sym_OSMesaGetProcAddress) return _sym_OSMesaGetProcAddress(name);
1571    return dlsym(RTLD_DEFAULT, name);
1572 }
1573
1574 static int
1575 eng_gl_native_surface_get(void *data __UNUSED__, void *surface, void *native_surface)
1576 {
1577    Render_Engine_GL_Surface *sfc;
1578    Evas_Native_Surface *ns;
1579
1580    sfc = (Render_Engine_GL_Surface*)surface;
1581    ns  = (Evas_Native_Surface*)native_surface;
1582
1583    if (!sfc) return 0;
1584
1585    ns->type = EVAS_NATIVE_SURFACE_OPENGL;
1586    ns->version = EVAS_NATIVE_SURFACE_VERSION;
1587    ns->data.x11.visual = sfc->buffer;
1588
1589    return 1;
1590 }
1591
1592
1593 static void *
1594 eng_gl_api_get(void *data __UNUSED__)
1595 {
1596    return &gl_funcs;
1597 }
1598
1599 //------------------------------------------------//
1600
1601
1602 /*
1603  *****
1604  **
1605  ** ENGINE API
1606  **
1607  *****
1608  */
1609
1610 static Evas_Func func =
1611 {
1612    NULL,
1613      NULL,
1614      NULL,
1615      NULL,
1616      NULL,
1617      NULL,
1618      NULL,
1619      NULL,
1620      NULL,
1621      NULL,
1622      NULL,
1623      NULL,
1624      NULL,
1625      eng_output_dump,
1626      /* draw context virtual methods */
1627      eng_context_new,
1628      eng_canvas_alpha_get,
1629      eng_context_free,
1630      eng_context_clip_set,
1631      eng_context_clip_clip,
1632      eng_context_clip_unset,
1633      eng_context_clip_get,
1634      eng_context_mask_set,
1635      eng_context_mask_unset,
1636      eng_context_color_set,
1637      eng_context_color_get,
1638      eng_context_multiplier_set,
1639      eng_context_multiplier_unset,
1640      eng_context_multiplier_get,
1641      eng_context_cutout_add,
1642      eng_context_cutout_clear,
1643      eng_context_anti_alias_set,
1644      eng_context_anti_alias_get,
1645      eng_context_color_interpolation_set,
1646      eng_context_color_interpolation_get,
1647      eng_context_render_op_set,
1648      eng_context_render_op_get,
1649      /* rect draw funcs */
1650      eng_rectangle_draw,
1651      /* line draw funcs */
1652      eng_line_draw,
1653      /* polygon draw funcs */
1654      eng_polygon_point_add,
1655      eng_polygon_points_clear,
1656      eng_polygon_draw,
1657      /* image draw funcs */
1658      eng_image_load,
1659      eng_image_new_from_data,
1660      eng_image_new_from_copied_data,
1661      eng_image_free,
1662      eng_image_size_get,
1663      eng_image_size_set,
1664      NULL,
1665      eng_image_dirty_region,
1666      eng_image_data_get,
1667      eng_image_data_put,
1668      eng_image_data_preload_request,
1669      eng_image_data_preload_cancel,
1670      eng_image_alpha_set,
1671      eng_image_alpha_get,
1672      eng_image_border_set,
1673      eng_image_border_get,
1674      eng_image_draw,
1675      eng_image_comment_get,
1676      eng_image_format_get,
1677      eng_image_colorspace_set,
1678      eng_image_colorspace_get,
1679      eng_image_can_region_get,
1680      eng_image_mask_create,
1681      eng_image_native_set,
1682      eng_image_native_get,
1683      /* image cache funcs */
1684      eng_image_cache_flush,
1685      eng_image_cache_set,
1686      eng_image_cache_get,
1687      /* font draw functions */
1688      eng_font_load,
1689      eng_font_memory_load,
1690      eng_font_add,
1691      eng_font_memory_add,
1692      eng_font_free,
1693      eng_font_ascent_get,
1694      eng_font_descent_get,
1695      eng_font_max_ascent_get,
1696      eng_font_max_descent_get,
1697      eng_font_string_size_get,
1698      eng_font_inset_get,
1699      eng_font_h_advance_get,
1700      eng_font_v_advance_get,
1701      eng_font_char_coords_get,
1702      eng_font_char_at_coords_get,
1703      eng_font_draw,
1704      /* font cache functions */
1705      eng_font_cache_flush,
1706      eng_font_cache_set,
1707      eng_font_cache_get,
1708      /* font hinting functions */
1709      eng_font_hinting_set,
1710      eng_font_hinting_can_hint,
1711      eng_image_scale_hint_set,
1712      eng_image_scale_hint_get,
1713      /* more font draw functions */
1714      eng_font_last_up_to_pos,
1715      eng_image_map_draw,
1716      eng_image_map_surface_new,
1717      eng_image_map_surface_free,
1718      NULL, // eng_image_content_hint_set - software doesn't use it
1719      NULL, // eng_image_content_hint_get - software doesn't use it
1720      eng_font_pen_coords_get,
1721      eng_font_text_props_info_create,
1722      eng_font_right_inset_get,
1723 #if 0 // filtering disabled
1724      eng_image_draw_filtered,
1725      eng_image_filtered_get,
1726      eng_image_filtered_save,
1727      eng_image_filtered_free,
1728 #endif   
1729      NULL, // need software mesa for gl rendering <- gl_surface_create
1730      NULL, // need software mesa for gl rendering <- gl_surface_destroy
1731      NULL, // need software mesa for gl rendering <- gl_context_create
1732      NULL, // need software mesa for gl rendering <- gl_context_destroy
1733      NULL, // need software mesa for gl rendering <- gl_make_current
1734      NULL, // need software mesa for gl rendering <- gl_string_query
1735      NULL, // need software mesa for gl rendering <- gl_proc_address_get
1736      NULL, // need software mesa for gl rendering <- gl_native_surface_get
1737      NULL, // need software mesa for gl rendering <- gl_api_get
1738      eng_image_load_error_get,
1739      eng_font_run_font_end_get,
1740      eng_image_animated_get,
1741      eng_image_animated_frame_count_get,
1742      eng_image_animated_loop_type_get,
1743      eng_image_animated_loop_count_get,
1744      eng_image_animated_frame_duration_get,
1745      eng_image_animated_frame_set,
1746      NULL
1747    /* FUTURE software generic calls go here */
1748 };
1749
1750
1751 //----------------------------------------------------------------//
1752 //                                                                //
1753 //                      Load Symbols                              //
1754 //                                                                //
1755 //----------------------------------------------------------------//
1756 static void
1757 sym_missing(void)
1758 {
1759    ERR("GL symbols missing!\n");
1760 }
1761
1762
1763 static int 
1764 glue_sym_init(void)
1765 {
1766    //------------------------------------------------//
1767    // Use eglGetProcAddress
1768 #define FINDSYM(dst, sym, typ) \
1769    if (!dst) dst = (typeof(dst))dlsym(gl_lib_handle, sym); \
1770    if (!dst)  \
1771      { \
1772         ERR("Symbol not found %s\n", sym); \
1773         return 0; \
1774      }
1775 #define FALLBAK(dst, typ) if (!dst) dst = (typeof(dst))sym_missing;
1776
1777     //------------------------------------------------------//
1778    // OSMesa APIs...
1779    FINDSYM(_sym_OSMesaCreateContextExt, "OSMesaCreateContextExt", glsym_func_osm_ctx);
1780    FALLBAK(_sym_OSMesaCreateContextExt, glsym_func_void);
1781
1782    FINDSYM(_sym_OSMesaDestroyContext, "OSMesaDestroyContext", glsym_func_void);
1783    FALLBAK(_sym_OSMesaDestroyContext, glsym_func_void);
1784
1785    FINDSYM(_sym_OSMesaMakeCurrent, "OSMesaMakeCurrent", glsym_func_bool);
1786    FALLBAK(_sym_OSMesaMakeCurrent, glsym_func_void);
1787
1788    FINDSYM(_sym_OSMesaPixelStore, "OSMesaPixelStore", glsym_func_void);
1789    FALLBAK(_sym_OSMesaPixelStore, glsym_func_void);
1790
1791    FINDSYM(_sym_OSMesaGetProcAddress, "OSMesaGetProcAddress", glsym_func_eng_fn);
1792    FALLBAK(_sym_OSMesaGetProcAddress, glsym_func_void);
1793
1794 #undef FINDSYM
1795 #undef FALLBAK
1796
1797    return 1;
1798 }
1799
1800 static int 
1801 gl_sym_init(void)
1802 {
1803    //------------------------------------------------//
1804 #define FINDSYM(dst, sym, typ) \
1805    if (!dst) dst = (typeof(dst))dlsym(gl_lib_handle, sym); \
1806    if (!dst) DBG("Symbol not found %s\n", sym);
1807 #define FALLBAK(dst, typ) if (!dst) dst = (typeof(dst))sym_missing;
1808
1809
1810    //------------------------------------------------------//
1811    // GLES 2.0 APIs...
1812    FINDSYM(_sym_glActiveTexture, "glActiveTexture", glsym_func_void);
1813    FALLBAK(_sym_glActiveTexture, glsym_func_void);
1814
1815    FINDSYM(_sym_glAttachShader, "glAttachShader", glsym_func_void);
1816    FALLBAK(_sym_glAttachShader, glsym_func_void);
1817
1818    FINDSYM(_sym_glBindAttribLocation, "glBindAttribLocation", glsym_func_void);
1819    FALLBAK(_sym_glBindAttribLocation, glsym_func_void);
1820
1821    FINDSYM(_sym_glBindBuffer, "glBindBuffer", glsym_func_void);
1822    FALLBAK(_sym_glBindBuffer, glsym_func_void);
1823
1824    FINDSYM(_sym_glBindFramebuffer, "glBindFramebuffer", glsym_func_void);
1825    FALLBAK(_sym_glBindFramebuffer, glsym_func_void);
1826
1827    FINDSYM(_sym_glBindRenderbuffer, "glBindRenderbuffer", glsym_func_void);
1828    FALLBAK(_sym_glBindRenderbuffer, glsym_func_void);
1829
1830    FINDSYM(_sym_glBindTexture, "glBindTexture", glsym_func_void);
1831    FALLBAK(_sym_glBindTexture, glsym_func_void);
1832
1833    FINDSYM(_sym_glBlendColor, "glBlendColor", glsym_func_void);
1834    FALLBAK(_sym_glBlendColor, glsym_func_void);
1835
1836    FINDSYM(_sym_glBlendEquation, "glBlendEquation", glsym_func_void);
1837    FALLBAK(_sym_glBlendEquation, glsym_func_void);
1838
1839    FINDSYM(_sym_glBlendEquationSeparate, "glBlendEquationSeparate", glsym_func_void);
1840    FALLBAK(_sym_glBlendEquationSeparate, glsym_func_void);
1841
1842    FINDSYM(_sym_glBlendFunc, "glBlendFunc", glsym_func_void);
1843    FALLBAK(_sym_glBlendFunc, glsym_func_void);
1844
1845    FINDSYM(_sym_glBlendFuncSeparate, "glBlendFuncSeparate", glsym_func_void);
1846    FALLBAK(_sym_glBlendFuncSeparate, glsym_func_void);
1847
1848    FINDSYM(_sym_glBufferData, "glBufferData", glsym_func_void);
1849    FALLBAK(_sym_glBufferData, glsym_func_void);
1850
1851    FINDSYM(_sym_glBufferSubData, "glBufferSubData", glsym_func_void);
1852    FALLBAK(_sym_glBufferSubData, glsym_func_void);
1853
1854    FINDSYM(_sym_glCheckFramebufferStatus, "glCheckFramebufferStatus", glsym_func_uint);
1855    FALLBAK(_sym_glCheckFramebufferStatus, glsym_func_uint);
1856
1857    FINDSYM(_sym_glClear, "glClear", glsym_func_void);
1858    FALLBAK(_sym_glClear, glsym_func_void);
1859
1860    FINDSYM(_sym_glClearColor, "glClearColor", glsym_func_void);
1861    FALLBAK(_sym_glClearColor, glsym_func_void);
1862
1863    FINDSYM(_sym_glClearDepthf, "glClearDepthf", glsym_func_void);
1864    FINDSYM(_sym_glClearDepthf, "glClearDepth", glsym_func_void);
1865    FALLBAK(_sym_glClearDepthf, glsym_func_void);
1866
1867    FINDSYM(_sym_glClearStencil, "glClearStencil", glsym_func_void);
1868    FALLBAK(_sym_glClearStencil, glsym_func_void);
1869
1870    FINDSYM(_sym_glColorMask, "glColorMask", glsym_func_void);
1871    FALLBAK(_sym_glColorMask, glsym_func_void);
1872
1873    FINDSYM(_sym_glCompileShader, "glCompileShader", glsym_func_void);
1874    FALLBAK(_sym_glCompileShader, glsym_func_void);
1875
1876    FINDSYM(_sym_glCompressedTexImage2D, "glCompressedTexImage2D", glsym_func_void);
1877    FALLBAK(_sym_glCompressedTexImage2D, glsym_func_void);
1878
1879    FINDSYM(_sym_glCompressedTexSubImage2D, "glCompressedTexSubImage2D", glsym_func_void);
1880    FALLBAK(_sym_glCompressedTexSubImage2D, glsym_func_void);
1881
1882    FINDSYM(_sym_glCopyTexImage2D, "glCopyTexImage2D", glsym_func_void);
1883    FALLBAK(_sym_glCopyTexImage2D, glsym_func_void);
1884
1885    FINDSYM(_sym_glCopyTexSubImage2D, "glCopyTexSubImage2D", glsym_func_void);
1886    FALLBAK(_sym_glCopyTexSubImage2D, glsym_func_void);
1887
1888    FINDSYM(_sym_glCreateProgram, "glCreateProgram", glsym_func_uint);
1889    FALLBAK(_sym_glCreateProgram, glsym_func_uint);
1890
1891    FINDSYM(_sym_glCreateShader, "glCreateShader", glsym_func_uint);
1892    FALLBAK(_sym_glCreateShader, glsym_func_uint);
1893
1894    FINDSYM(_sym_glCullFace, "glCullFace", glsym_func_void);
1895    FALLBAK(_sym_glCullFace, glsym_func_void);
1896
1897    FINDSYM(_sym_glDeleteBuffers, "glDeleteBuffers", glsym_func_void);
1898    FALLBAK(_sym_glDeleteBuffers, glsym_func_void);
1899
1900    FINDSYM(_sym_glDeleteFramebuffers, "glDeleteFramebuffers", glsym_func_void);
1901    FALLBAK(_sym_glDeleteFramebuffers, glsym_func_void);
1902
1903    FINDSYM(_sym_glDeleteProgram, "glDeleteProgram", glsym_func_void);
1904    FALLBAK(_sym_glDeleteProgram, glsym_func_void);
1905
1906    FINDSYM(_sym_glDeleteRenderbuffers, "glDeleteRenderbuffers", glsym_func_void);
1907    FALLBAK(_sym_glDeleteRenderbuffers, glsym_func_void);
1908
1909    FINDSYM(_sym_glDeleteShader, "glDeleteShader", glsym_func_void);
1910    FALLBAK(_sym_glDeleteShader, glsym_func_void);
1911
1912    FINDSYM(_sym_glDeleteTextures, "glDeleteTextures", glsym_func_void);
1913    FALLBAK(_sym_glDeleteTextures, glsym_func_void);
1914
1915    FINDSYM(_sym_glDepthFunc, "glDepthFunc", glsym_func_void);
1916    FALLBAK(_sym_glDepthFunc, glsym_func_void);
1917
1918    FINDSYM(_sym_glDepthMask, "glDepthMask", glsym_func_void);
1919    FALLBAK(_sym_glDepthMask, glsym_func_void);
1920
1921    FINDSYM(_sym_glDepthRangef, "glDepthRangef", glsym_func_void);
1922    FINDSYM(_sym_glDepthRangef, "glDepthRange", glsym_func_void);
1923    FALLBAK(_sym_glDepthRangef, glsym_func_void);
1924
1925    FINDSYM(_sym_glDetachShader, "glDetachShader", glsym_func_void);
1926    FALLBAK(_sym_glDetachShader, glsym_func_void);
1927
1928    FINDSYM(_sym_glDisable, "glDisable", glsym_func_void);
1929    FALLBAK(_sym_glDisable, glsym_func_void);
1930
1931    FINDSYM(_sym_glDisableVertexAttribArray, "glDisableVertexAttribArray", glsym_func_void);
1932    FALLBAK(_sym_glDisableVertexAttribArray, glsym_func_void);
1933
1934    FINDSYM(_sym_glDrawArrays, "glDrawArrays", glsym_func_void);
1935    FALLBAK(_sym_glDrawArrays, glsym_func_void);
1936
1937    FINDSYM(_sym_glDrawElements, "glDrawElements", glsym_func_void);
1938    FALLBAK(_sym_glDrawElements, glsym_func_void);
1939
1940    FINDSYM(_sym_glEnable, "glEnable", glsym_func_void);
1941    FALLBAK(_sym_glEnable, glsym_func_void);
1942
1943    FINDSYM(_sym_glEnableVertexAttribArray, "glEnableVertexAttribArray", glsym_func_void);
1944    FALLBAK(_sym_glEnableVertexAttribArray, glsym_func_void);
1945
1946    FINDSYM(_sym_glFinish, "glFinish", glsym_func_void);
1947    FALLBAK(_sym_glFinish, glsym_func_void);
1948
1949    FINDSYM(_sym_glFlush, "glFlush", glsym_func_void);
1950    FALLBAK(_sym_glFlush, glsym_func_void);
1951
1952    FINDSYM(_sym_glFramebufferRenderbuffer, "glFramebufferRenderbuffer", glsym_func_void);
1953    FALLBAK(_sym_glFramebufferRenderbuffer, glsym_func_void);
1954
1955    FINDSYM(_sym_glFramebufferTexture2D, "glFramebufferTexture2D", glsym_func_void);
1956    FALLBAK(_sym_glFramebufferTexture2D, glsym_func_void);
1957
1958    FINDSYM(_sym_glFrontFace, "glFrontFace", glsym_func_void);
1959    FALLBAK(_sym_glFrontFace, glsym_func_void);
1960
1961    FINDSYM(_sym_glGenBuffers, "glGenBuffers", glsym_func_void);
1962    FALLBAK(_sym_glGenBuffers, glsym_func_void);
1963
1964    FINDSYM(_sym_glGenerateMipmap, "glGenerateMipmap", glsym_func_void);
1965    FALLBAK(_sym_glGenerateMipmap, glsym_func_void);
1966
1967    FINDSYM(_sym_glGenFramebuffers, "glGenFramebuffers", glsym_func_void);
1968    FALLBAK(_sym_glGenFramebuffers, glsym_func_void);
1969
1970    FINDSYM(_sym_glGenRenderbuffers, "glGenRenderbuffers", glsym_func_void);
1971    FALLBAK(_sym_glGenRenderbuffers, glsym_func_void);
1972
1973    FINDSYM(_sym_glGenTextures, "glGenTextures", glsym_func_void);
1974    FALLBAK(_sym_glGenTextures, glsym_func_void);
1975
1976    FINDSYM(_sym_glGetActiveAttrib, "glGetActiveAttrib", glsym_func_void);
1977    FALLBAK(_sym_glGetActiveAttrib, glsym_func_void);
1978
1979    FINDSYM(_sym_glGetActiveUniform, "glGetActiveUniform", glsym_func_void);
1980    FALLBAK(_sym_glGetActiveUniform, glsym_func_void);
1981
1982    FINDSYM(_sym_glGetAttachedShaders, "glGetAttachedShaders", glsym_func_void);
1983    FALLBAK(_sym_glGetAttachedShaders, glsym_func_void);
1984
1985    FINDSYM(_sym_glGetAttribLocation, "glGetAttribLocation", glsym_func_int);
1986    FALLBAK(_sym_glGetAttribLocation, glsym_func_int);
1987
1988    FINDSYM(_sym_glGetBooleanv, "glGetBooleanv", glsym_func_void);
1989    FALLBAK(_sym_glGetBooleanv, glsym_func_void);
1990
1991    FINDSYM(_sym_glGetBufferParameteriv, "glGetBufferParameteriv", glsym_func_void);
1992    FALLBAK(_sym_glGetBufferParameteriv, glsym_func_void);
1993
1994    FINDSYM(_sym_glGetError, "glGetError", glsym_func_uint);
1995    FALLBAK(_sym_glGetError, glsym_func_uint);
1996
1997    FINDSYM(_sym_glGetFloatv, "glGetFloatv", glsym_func_void);
1998    FALLBAK(_sym_glGetFloatv, glsym_func_void);
1999
2000    FINDSYM(_sym_glGetFramebufferAttachmentParameteriv, "glGetFramebufferAttachmentParameteriv", glsym_func_void);
2001    FALLBAK(_sym_glGetFramebufferAttachmentParameteriv, glsym_func_void);
2002
2003    FINDSYM(_sym_glGetIntegerv, "glGetIntegerv", glsym_func_void);
2004    FALLBAK(_sym_glGetIntegerv, glsym_func_void);
2005
2006    FINDSYM(_sym_glGetProgramiv, "glGetProgramiv", glsym_func_void);
2007    FALLBAK(_sym_glGetProgramiv, glsym_func_void);
2008
2009    FINDSYM(_sym_glGetProgramInfoLog, "glGetProgramInfoLog", glsym_func_void);
2010    FALLBAK(_sym_glGetProgramInfoLog, glsym_func_void);
2011
2012    FINDSYM(_sym_glGetRenderbufferParameteriv, "glGetRenderbufferParameteriv", glsym_func_void);
2013    FALLBAK(_sym_glGetRenderbufferParameteriv, glsym_func_void);
2014
2015    FINDSYM(_sym_glGetShaderiv, "glGetShaderiv", glsym_func_void);
2016    FALLBAK(_sym_glGetShaderiv, glsym_func_void);
2017
2018    FINDSYM(_sym_glGetShaderInfoLog, "glGetShaderInfoLog", glsym_func_void);
2019    FALLBAK(_sym_glGetShaderInfoLog, glsym_func_void);
2020
2021    FINDSYM(_sym_glGetShaderPrecisionFormat, "glGetShaderPrecisionFormat", glsym_func_void);
2022    FALLBAK(_sym_glGetShaderPrecisionFormat, glsym_func_void);
2023
2024    FINDSYM(_sym_glGetShaderSource, "glGetShaderSource", glsym_func_void);
2025    FALLBAK(_sym_glGetShaderSource, glsym_func_void);
2026
2027    FINDSYM(_sym_glGetString, "glGetString", glsym_func_uchar_ptr);
2028    FALLBAK(_sym_glGetString, glsym_func_const_uchar_ptr);
2029
2030    FINDSYM(_sym_glGetTexParameterfv, "glGetTexParameterfv", glsym_func_void);
2031    FALLBAK(_sym_glGetTexParameterfv, glsym_func_void);
2032
2033    FINDSYM(_sym_glGetTexParameteriv, "glGetTexParameteriv", glsym_func_void);
2034    FALLBAK(_sym_glGetTexParameteriv, glsym_func_void);
2035
2036    FINDSYM(_sym_glGetUniformfv, "glGetUniformfv", glsym_func_void);
2037    FALLBAK(_sym_glGetUniformfv, glsym_func_void);
2038
2039    FINDSYM(_sym_glGetUniformiv, "glGetUniformiv", glsym_func_void);
2040    FALLBAK(_sym_glGetUniformiv, glsym_func_void);
2041
2042    FINDSYM(_sym_glGetUniformLocation, "glGetUniformLocation", glsym_func_int);
2043    FALLBAK(_sym_glGetUniformLocation, glsym_func_int);
2044
2045    FINDSYM(_sym_glGetVertexAttribfv, "glGetVertexAttribfv", glsym_func_void);
2046    FALLBAK(_sym_glGetVertexAttribfv, glsym_func_void);
2047
2048    FINDSYM(_sym_glGetVertexAttribiv, "glGetVertexAttribiv", glsym_func_void);
2049    FALLBAK(_sym_glGetVertexAttribiv, glsym_func_void);
2050
2051    FINDSYM(_sym_glGetVertexAttribPointerv, "glGetVertexAttribPointerv", glsym_func_void);
2052    FALLBAK(_sym_glGetVertexAttribPointerv, glsym_func_void);
2053
2054    FINDSYM(_sym_glHint, "glHint", glsym_func_void);
2055    FALLBAK(_sym_glHint, glsym_func_void);
2056
2057    FINDSYM(_sym_glIsBuffer, "glIsBuffer", glsym_func_uchar);
2058    FALLBAK(_sym_glIsBuffer, glsym_func_uchar);
2059
2060    FINDSYM(_sym_glIsEnabled, "glIsEnabled", glsym_func_uchar);
2061    FALLBAK(_sym_glIsEnabled, glsym_func_uchar);
2062
2063    FINDSYM(_sym_glIsFramebuffer, "glIsFramebuffer", glsym_func_uchar);
2064    FALLBAK(_sym_glIsFramebuffer, glsym_func_uchar);
2065
2066    FINDSYM(_sym_glIsProgram, "glIsProgram", glsym_func_uchar);
2067    FALLBAK(_sym_glIsProgram, glsym_func_uchar);
2068
2069    FINDSYM(_sym_glIsRenderbuffer, "glIsRenderbuffer", glsym_func_uchar);
2070    FALLBAK(_sym_glIsRenderbuffer, glsym_func_uchar);
2071
2072    FINDSYM(_sym_glIsShader, "glIsShader", glsym_func_uchar);
2073    FALLBAK(_sym_glIsShader, glsym_func_uchar);
2074
2075    FINDSYM(_sym_glIsTexture, "glIsTexture", glsym_func_uchar);
2076    FALLBAK(_sym_glIsTexture, glsym_func_uchar);
2077
2078    FINDSYM(_sym_glLineWidth, "glLineWidth", glsym_func_void);
2079    FALLBAK(_sym_glLineWidth, glsym_func_void);
2080
2081    FINDSYM(_sym_glLinkProgram, "glLinkProgram", glsym_func_void);
2082    FALLBAK(_sym_glLinkProgram, glsym_func_void);
2083
2084    FINDSYM(_sym_glPixelStorei, "glPixelStorei", glsym_func_void);
2085    FALLBAK(_sym_glPixelStorei, glsym_func_void);
2086
2087    FINDSYM(_sym_glPolygonOffset, "glPolygonOffset", glsym_func_void);
2088    FALLBAK(_sym_glPolygonOffset, glsym_func_void);
2089
2090    FINDSYM(_sym_glReadPixels, "glReadPixels", glsym_func_void);
2091    FALLBAK(_sym_glReadPixels, glsym_func_void);
2092
2093    FINDSYM(_sym_glReleaseShaderCompiler, "glReleaseShaderCompiler", glsym_func_void);
2094    FALLBAK(_sym_glReleaseShaderCompiler, glsym_func_void);
2095
2096    FINDSYM(_sym_glRenderbufferStorage, "glRenderbufferStorage", glsym_func_void);
2097    FALLBAK(_sym_glRenderbufferStorage, glsym_func_void);
2098
2099    FINDSYM(_sym_glSampleCoverage, "glSampleCoverage", glsym_func_void);
2100    FALLBAK(_sym_glSampleCoverage, glsym_func_void);
2101
2102    FINDSYM(_sym_glScissor, "glScissor", glsym_func_void);
2103    FALLBAK(_sym_glScissor, glsym_func_void);
2104
2105    FINDSYM(_sym_glShaderBinary, "glShaderBinary", glsym_func_void);
2106    FALLBAK(_sym_glShaderBinary, glsym_func_void);
2107
2108    FINDSYM(_sym_glShaderSource, "glShaderSource", glsym_func_void);
2109    FALLBAK(_sym_glShaderSource, glsym_func_void);
2110
2111    FINDSYM(_sym_glStencilFunc, "glStencilFunc", glsym_func_void);
2112    FALLBAK(_sym_glStencilFunc, glsym_func_void);
2113
2114    FINDSYM(_sym_glStencilFuncSeparate, "glStencilFuncSeparate", glsym_func_void);
2115    FALLBAK(_sym_glStencilFuncSeparate, glsym_func_void);
2116
2117    FINDSYM(_sym_glStencilMask, "glStencilMask", glsym_func_void);
2118    FALLBAK(_sym_glStencilMask, glsym_func_void);
2119
2120    FINDSYM(_sym_glStencilMaskSeparate, "glStencilMaskSeparate", glsym_func_void);
2121    FALLBAK(_sym_glStencilMaskSeparate, glsym_func_void);
2122
2123    FINDSYM(_sym_glStencilOp, "glStencilOp", glsym_func_void);
2124    FALLBAK(_sym_glStencilOp, glsym_func_void);
2125
2126    FINDSYM(_sym_glStencilOpSeparate, "glStencilOpSeparate", glsym_func_void);
2127    FALLBAK(_sym_glStencilOpSeparate, glsym_func_void);
2128
2129    FINDSYM(_sym_glTexImage2D, "glTexImage2D", glsym_func_void);
2130    FALLBAK(_sym_glTexImage2D, glsym_func_void);
2131
2132    FINDSYM(_sym_glTexParameterf, "glTexParameterf", glsym_func_void);
2133    FALLBAK(_sym_glTexParameterf, glsym_func_void);
2134
2135    FINDSYM(_sym_glTexParameterfv, "glTexParameterfv", glsym_func_void);
2136    FALLBAK(_sym_glTexParameterfv, glsym_func_void);
2137
2138    FINDSYM(_sym_glTexParameteri, "glTexParameteri", glsym_func_void);
2139    FALLBAK(_sym_glTexParameteri, glsym_func_void);
2140
2141    FINDSYM(_sym_glTexParameteriv, "glTexParameteriv", glsym_func_void);
2142    FALLBAK(_sym_glTexParameteriv, glsym_func_void);
2143
2144    FINDSYM(_sym_glTexSubImage2D, "glTexSubImage2D", glsym_func_void);
2145    FALLBAK(_sym_glTexSubImage2D, glsym_func_void);
2146
2147    FINDSYM(_sym_glUniform1f, "glUniform1f", glsym_func_void);
2148    FALLBAK(_sym_glUniform1f, glsym_func_void);
2149
2150    FINDSYM(_sym_glUniform1fv, "glUniform1fv", glsym_func_void);
2151    FALLBAK(_sym_glUniform1fv, glsym_func_void);
2152
2153    FINDSYM(_sym_glUniform1i, "glUniform1i", glsym_func_void);
2154    FALLBAK(_sym_glUniform1i, glsym_func_void);
2155
2156    FINDSYM(_sym_glUniform1iv, "glUniform1iv", glsym_func_void);
2157    FALLBAK(_sym_glUniform1iv, glsym_func_void);
2158
2159    FINDSYM(_sym_glUniform2f, "glUniform2f", glsym_func_void);
2160    FALLBAK(_sym_glUniform2f, glsym_func_void);
2161
2162    FINDSYM(_sym_glUniform2fv, "glUniform2fv", glsym_func_void);
2163    FALLBAK(_sym_glUniform2fv, glsym_func_void);
2164
2165    FINDSYM(_sym_glUniform2i, "glUniform2i", glsym_func_void);
2166    FALLBAK(_sym_glUniform2i, glsym_func_void);
2167
2168    FINDSYM(_sym_glUniform2iv, "glUniform2iv", glsym_func_void);
2169    FALLBAK(_sym_glUniform2iv, glsym_func_void);
2170
2171    FINDSYM(_sym_glUniform3f, "glUniform3f", glsym_func_void);
2172    FALLBAK(_sym_glUniform3f, glsym_func_void);
2173
2174    FINDSYM(_sym_glUniform3fv, "glUniform3fv", glsym_func_void);
2175    FALLBAK(_sym_glUniform3fv, glsym_func_void);
2176
2177    FINDSYM(_sym_glUniform3i, "glUniform3i", glsym_func_void);
2178    FALLBAK(_sym_glUniform3i, glsym_func_void);
2179
2180    FINDSYM(_sym_glUniform3iv, "glUniform3iv", glsym_func_void);
2181    FALLBAK(_sym_glUniform3iv, glsym_func_void);
2182
2183    FINDSYM(_sym_glUniform4f, "glUniform4f", glsym_func_void);
2184    FALLBAK(_sym_glUniform4f, glsym_func_void);
2185
2186    FINDSYM(_sym_glUniform4fv, "glUniform4fv", glsym_func_void);
2187    FALLBAK(_sym_glUniform4fv, glsym_func_void);
2188
2189    FINDSYM(_sym_glUniform4i, "glUniform4i", glsym_func_void);
2190    FALLBAK(_sym_glUniform4i, glsym_func_void);
2191
2192    FINDSYM(_sym_glUniform4iv, "glUniform4iv", glsym_func_void);
2193    FALLBAK(_sym_glUniform4iv, glsym_func_void);
2194
2195    FINDSYM(_sym_glUniformMatrix2fv, "glUniformMatrix2fv", glsym_func_void);
2196    FALLBAK(_sym_glUniformMatrix2fv, glsym_func_void);
2197
2198    FINDSYM(_sym_glUniformMatrix3fv, "glUniformMatrix3fv", glsym_func_void);
2199    FALLBAK(_sym_glUniformMatrix3fv, glsym_func_void);
2200
2201    FINDSYM(_sym_glUniformMatrix4fv, "glUniformMatrix4fv", glsym_func_void);
2202    FALLBAK(_sym_glUniformMatrix4fv, glsym_func_void);
2203
2204    FINDSYM(_sym_glUseProgram, "glUseProgram", glsym_func_void);
2205    FALLBAK(_sym_glUseProgram, glsym_func_void);
2206
2207    FINDSYM(_sym_glValidateProgram, "glValidateProgram", glsym_func_void);
2208    FALLBAK(_sym_glValidateProgram, glsym_func_void);
2209
2210    FINDSYM(_sym_glVertexAttrib1f, "glVertexAttrib1f", glsym_func_void);
2211    FALLBAK(_sym_glVertexAttrib1f, glsym_func_void);
2212
2213    FINDSYM(_sym_glVertexAttrib1fv, "glVertexAttrib1fv", glsym_func_void);
2214    FALLBAK(_sym_glVertexAttrib1fv, glsym_func_void);
2215
2216    FINDSYM(_sym_glVertexAttrib2f, "glVertexAttrib2f", glsym_func_void);
2217    FALLBAK(_sym_glVertexAttrib2f, glsym_func_void);
2218
2219    FINDSYM(_sym_glVertexAttrib2fv, "glVertexAttrib2fv", glsym_func_void);
2220    FALLBAK(_sym_glVertexAttrib2fv, glsym_func_void);
2221
2222    FINDSYM(_sym_glVertexAttrib3f, "glVertexAttrib3f", glsym_func_void);
2223    FALLBAK(_sym_glVertexAttrib3f, glsym_func_void);
2224
2225    FINDSYM(_sym_glVertexAttrib3fv, "glVertexAttrib3fv", glsym_func_void);
2226    FALLBAK(_sym_glVertexAttrib3fv, glsym_func_void);
2227
2228    FINDSYM(_sym_glVertexAttrib4f, "glVertexAttrib4f", glsym_func_void);
2229    FALLBAK(_sym_glVertexAttrib4f, glsym_func_void);
2230
2231    FINDSYM(_sym_glVertexAttrib4fv, "glVertexAttrib4fv", glsym_func_void);
2232    FALLBAK(_sym_glVertexAttrib4fv, glsym_func_void);
2233
2234    FINDSYM(_sym_glVertexAttribPointer, "glVertexAttribPointer", glsym_func_void);
2235    FALLBAK(_sym_glVertexAttribPointer, glsym_func_void);
2236
2237    FINDSYM(_sym_glViewport, "glViewport", glsym_func_void);
2238    FALLBAK(_sym_glViewport, glsym_func_void);
2239
2240 #undef FINDSYM
2241 #undef FALLBAK
2242
2243    // Checking to see if this function exists is a poor but reasonable way to 
2244    // check if it's gles but it works for now
2245    if (_sym_glGetShaderPrecisionFormat != (typeof(_sym_glGetShaderPrecisionFormat))sym_missing ) 
2246      {
2247         DBG("GL Library is GLES.");
2248         gl_lib_is_gles = 1;
2249      }
2250    
2251    return 1;
2252 }
2253
2254 //--------------------------------------------------------------//
2255 // Wrapped GL APIs to handle desktop compatibility
2256
2257 // Stripping precision code from GLES shader for desktop compatibility
2258 // Code adopted from Meego GL code. Temporary Fix.  
2259 static const char *
2260 opengl_strtok(const char *s, int *n, char **saveptr, char *prevbuf)
2261 {
2262    char *start;
2263    char *ret;
2264    char *p;
2265    int retlen;
2266    static const char *delim = " \t\n\r/";
2267
2268    if (prevbuf) free(prevbuf);
2269
2270    if (s) 
2271       *saveptr = (char *)s;
2272    else 
2273      {
2274         if (!(*saveptr) || !(*n))
2275            return NULL;
2276         s = *saveptr;
2277      }
2278
2279    for (; *n && strchr(delim, *s); s++, (*n)--) 
2280      {
2281         if (*s == '/' && *n > 1) 
2282           {
2283              if (s[1] == '/') 
2284                {
2285                   do 
2286                     {
2287                        s++, (*n)--;
2288                     } 
2289                   while (*n > 1 && s[1] != '\n' && s[1] != '\r');
2290                } 
2291              else if (s[1] == '*') 
2292                {
2293                   do 
2294                     {
2295                        s++, (*n)--;
2296                     } 
2297                   while (*n > 2 && (s[1] != '*' || s[2] != '/'));
2298                   s++, (*n)--;
2299                }
2300           }
2301      }
2302
2303    start = (char *)s;
2304    for (; *n && *s && !strchr(delim, *s); s++, (*n)--);
2305    if (*n > 0) s++, (*n)--;
2306
2307    *saveptr = (char *)s;
2308
2309    retlen = s - start;
2310    ret = malloc(retlen + 1);
2311    p = ret;
2312
2313    while (retlen > 0) 
2314      {
2315         if (*start == '/' && retlen > 1) 
2316           {
2317              if (start[1] == '/') 
2318                {
2319                   do 
2320                     {
2321                        start++, retlen--;
2322                     } 
2323                   while (retlen > 1 && start[1] != '\n' && start[1] != '\r');
2324                   start++, retlen--;
2325                   continue;
2326                } 
2327              else if (start[1] == '*') 
2328                {
2329                   do 
2330                     {
2331                        start++, retlen--;
2332                     } 
2333                   while (retlen > 2 && (start[1] != '*' || start[2] != '/'));
2334                   start += 3, retlen -= 3;
2335                   continue;
2336                }
2337           }
2338         *(p++) = *(start++), retlen--;
2339      }
2340
2341    *p = 0;
2342    return ret;
2343 }       
2344
2345 static char *
2346 patch_gles_shader(const char *source, int length, int *patched_len)
2347 {
2348    char *saveptr = NULL;
2349    char *sp;
2350    char *p = NULL;
2351
2352    if (!length) length = strlen(source);
2353
2354    *patched_len = 0;
2355    int patched_size = length;
2356    char *patched = malloc(patched_size + 1);
2357
2358    if (!patched) return NULL;
2359
2360    p = (char *)opengl_strtok(source, &length, &saveptr, NULL);
2361    for (; p; p = (char *)opengl_strtok(0, &length, &saveptr, p)) 
2362      {
2363         if (!strncmp(p, "lowp", 4) || !strncmp(p, "mediump", 7) || !strncmp(p, "highp", 5)) 
2364           {
2365              continue;
2366           } 
2367         else if (!strncmp(p, "precision", 9)) 
2368           {
2369              while ((p = (char *)opengl_strtok(0, &length, &saveptr, p)) && !strchr(p, ';'));
2370           } 
2371         else 
2372           {
2373              if (!strncmp(p, "gl_MaxVertexUniformVectors", 26)) 
2374                {
2375                   p = "(gl_MaxVertexUniformComponents / 4)";
2376                } 
2377              else if (!strncmp(p, "gl_MaxFragmentUniformVectors", 28)) 
2378                {
2379                   p = "(gl_MaxFragmentUniformComponents / 4)";
2380                } 
2381              else if (!strncmp(p, "gl_MaxVaryingVectors", 20)) 
2382                {
2383                   p = "(gl_MaxVaryingFloats / 4)";
2384                }
2385
2386              int new_len = strlen(p);
2387              if (*patched_len + new_len > patched_size) 
2388                {
2389                   patched_size *= 2;
2390                   patched = realloc(patched, patched_size + 1);
2391
2392                   if (!patched) 
2393                      return NULL;
2394                }
2395
2396              memcpy(patched + *patched_len, p, new_len);
2397              *patched_len += new_len;
2398           }     
2399      }
2400
2401    patched[*patched_len] = 0;
2402    /* check that we don't leave dummy preprocessor lines */
2403    for (sp = patched; *sp;) 
2404      {
2405         for (; *sp == ' ' || *sp == '\t'; sp++);
2406         if (!strncmp(sp, "#define", 7)) 
2407           {
2408              for (p = sp + 7; *p == ' ' || *p == '\t'; p++);
2409              if (*p == '\n' || *p == '\r' || *p == '/') 
2410                {
2411                   memset(sp, 0x20, 7);
2412                }
2413           }
2414         for (; *sp && *sp != '\n' && *sp != '\r'; sp++);
2415         for (; *sp == '\n' || *sp == '\r'; sp++);
2416      }
2417    return patched;
2418 }
2419
2420 static void
2421 evgl_glShaderSource(GLuint shader, GLsizei count, const char** string, const GLint* length)
2422 {
2423    char *newstr;
2424    char *srcbk;
2425    char *token = NULL;
2426    char *saveptr;
2427    int i = 0;
2428    int len = 0;
2429    int token_len = 0;
2430
2431    char **s = malloc(count * sizeof(char*));
2432    GLint *l = malloc(count * sizeof(GLint));
2433
2434    memset(s, 0, count * sizeof(char*));
2435    memset(l, 0, count * sizeof(GLint));
2436
2437    for (i = 0; i < count; ++i) 
2438      {
2439         if (length) 
2440           {
2441              len = length[i];
2442              if (len < 0) 
2443                 len = string[i] ? strlen(string[i]) : 0;
2444           }
2445         else
2446            len = string[i] ? strlen(string[i]) : 0;
2447
2448         if (string[i]) 
2449           {
2450              s[i] = patch_gles_shader(string[i], len, &l[i]);
2451              if (!s[i]) 
2452                {
2453                   while(i)
2454                      free(s[--i]);
2455                   free(l);
2456                   free(s);
2457
2458                   DBG("Patching Shader Failed.");
2459                   return;
2460                }
2461           } 
2462         else 
2463           {
2464              s[i] = NULL;
2465              l[i] = 0;
2466           }
2467      }
2468
2469    _sym_glShaderSource(shader, count, (const char **)s, l);
2470
2471    while(i)
2472       free(s[--i]);
2473    free(l);
2474    free(s);
2475 }
2476
2477
2478 static void
2479 evgl_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2480 {
2481    if (range)
2482      {
2483         range[0] = -126; // floor(log2(FLT_MIN))
2484         range[1] = 127; // floor(log2(FLT_MAX))
2485      }
2486    if (precision)
2487      {
2488         precision[0] = 24; // floor(-log2((1.0/16777218.0)));
2489      }
2490    return;
2491    shadertype = precisiontype = 0;
2492 }
2493
2494 static void
2495 evgl_glReleaseShaderCompiler(void)
2496 {
2497    DBG("Not supported in Desktop GL");
2498    return;
2499 }
2500
2501 static void
2502 evgl_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
2503 {
2504    // FIXME: need to dlsym/getprocaddress for this
2505    DBG("Not supported in Desktop GL");
2506    return;
2507    //n = binaryformat = length = 0;
2508    //shaders = binary = 0;
2509 }
2510 //--------------------------------------------------------------//
2511
2512
2513 static void
2514 override_gl_apis(Evas_GL_API *api)
2515 {
2516
2517    api->version = EVAS_GL_API_VERSION;
2518
2519 #define ORD(f) EVAS_API_OVERRIDE(f, api, _sym_)
2520    // GLES 2.0
2521    ORD(glActiveTexture);
2522    ORD(glAttachShader);
2523    ORD(glBindAttribLocation);
2524    ORD(glBindBuffer);
2525    ORD(glBindTexture);
2526    ORD(glBlendColor);
2527    ORD(glBlendEquation);
2528    ORD(glBlendEquationSeparate);
2529    ORD(glBlendFunc);
2530    ORD(glBlendFuncSeparate);
2531    ORD(glBufferData);
2532    ORD(glBufferSubData);
2533    ORD(glCheckFramebufferStatus);
2534    ORD(glClear);
2535    ORD(glClearColor);
2536    ORD(glClearDepthf);     
2537    ORD(glClearStencil);
2538    ORD(glColorMask);
2539    ORD(glCompileShader);
2540    ORD(glCompressedTexImage2D);
2541    ORD(glCompressedTexSubImage2D);
2542    ORD(glCopyTexImage2D);
2543    ORD(glCopyTexSubImage2D);
2544    ORD(glCreateProgram);
2545    ORD(glCreateShader);
2546    ORD(glCullFace);
2547    ORD(glDeleteBuffers);
2548    ORD(glDeleteFramebuffers);
2549    ORD(glDeleteProgram);
2550    ORD(glDeleteRenderbuffers);
2551    ORD(glDeleteShader);
2552    ORD(glDeleteTextures);
2553    ORD(glDepthFunc);
2554    ORD(glDepthMask);
2555    ORD(glDepthRangef);     
2556    ORD(glDetachShader);
2557    ORD(glDisable);
2558    ORD(glDisableVertexAttribArray);
2559    ORD(glDrawArrays);
2560    ORD(glDrawElements);
2561    ORD(glEnable);
2562    ORD(glEnableVertexAttribArray);
2563    ORD(glFinish);
2564    ORD(glFlush);
2565    ORD(glFramebufferRenderbuffer);
2566    ORD(glFramebufferTexture2D);
2567    ORD(glFrontFace);
2568    ORD(glGenBuffers);
2569    ORD(glGenerateMipmap);
2570    ORD(glGenFramebuffers);
2571    ORD(glGenRenderbuffers);
2572    ORD(glGenTextures);
2573    ORD(glGetActiveAttrib);
2574    ORD(glGetActiveUniform);
2575    ORD(glGetAttachedShaders);
2576    ORD(glGetAttribLocation);
2577    ORD(glGetBooleanv);
2578    ORD(glGetBufferParameteriv);
2579    ORD(glGetError);
2580    ORD(glGetFloatv);
2581    ORD(glGetFramebufferAttachmentParameteriv);
2582    ORD(glGetIntegerv);
2583    ORD(glGetProgramiv);
2584    ORD(glGetProgramInfoLog);
2585    ORD(glGetRenderbufferParameteriv);
2586    ORD(glGetShaderiv);
2587    ORD(glGetShaderInfoLog);
2588    ORD(glGetShaderPrecisionFormat);  
2589    ORD(glGetShaderSource);
2590    ORD(glGetString);             // FIXME
2591    ORD(glGetTexParameterfv);
2592    ORD(glGetTexParameteriv);
2593    ORD(glGetUniformfv);
2594    ORD(glGetUniformiv);
2595    ORD(glGetUniformLocation);
2596    ORD(glGetVertexAttribfv);
2597    ORD(glGetVertexAttribiv);
2598    ORD(glGetVertexAttribPointerv);
2599    ORD(glHint);
2600    ORD(glIsBuffer);
2601    ORD(glIsEnabled);
2602    ORD(glIsFramebuffer);
2603    ORD(glIsProgram);
2604    ORD(glIsRenderbuffer);
2605    ORD(glIsShader);
2606    ORD(glIsTexture);
2607    ORD(glLineWidth);
2608    ORD(glLinkProgram);
2609    ORD(glPixelStorei);
2610    ORD(glPolygonOffset);
2611    ORD(glReadPixels);
2612    ORD(glReleaseShaderCompiler); 
2613    ORD(glRenderbufferStorage);
2614    ORD(glSampleCoverage);
2615    ORD(glScissor);
2616    ORD(glShaderBinary); 
2617    ORD(glShaderSource);
2618    ORD(glStencilFunc);
2619    ORD(glStencilFuncSeparate);
2620    ORD(glStencilMask);
2621    ORD(glStencilMaskSeparate);
2622    ORD(glStencilOp);
2623    ORD(glStencilOpSeparate);
2624    ORD(glTexImage2D);
2625    ORD(glTexParameterf);
2626    ORD(glTexParameterfv);
2627    ORD(glTexParameteri);
2628    ORD(glTexParameteriv);
2629    ORD(glTexSubImage2D);
2630    ORD(glUniform1f);
2631    ORD(glUniform1fv);
2632    ORD(glUniform1i);
2633    ORD(glUniform1iv);
2634    ORD(glUniform2f);
2635    ORD(glUniform2fv);
2636    ORD(glUniform2i);
2637    ORD(glUniform2iv);
2638    ORD(glUniform3f);
2639    ORD(glUniform3fv);
2640    ORD(glUniform3i);
2641    ORD(glUniform3iv);
2642    ORD(glUniform4f);
2643    ORD(glUniform4fv);
2644    ORD(glUniform4i);
2645    ORD(glUniform4iv);
2646    ORD(glUniformMatrix2fv);
2647    ORD(glUniformMatrix3fv);
2648    ORD(glUniformMatrix4fv);
2649    ORD(glUseProgram);
2650    ORD(glValidateProgram);
2651    ORD(glVertexAttrib1f);
2652    ORD(glVertexAttrib1fv);
2653    ORD(glVertexAttrib2f);
2654    ORD(glVertexAttrib2fv);
2655    ORD(glVertexAttrib3f);
2656    ORD(glVertexAttrib3fv);
2657    ORD(glVertexAttrib4f);
2658    ORD(glVertexAttrib4fv);
2659    ORD(glVertexAttribPointer);
2660    ORD(glViewport);
2661 #undef ORD
2662
2663 #define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, evgl_)
2664    if (!gl_lib_is_gles)
2665      {
2666         // Override functions wrapped by Evas_GL
2667         // GLES2.0 API compat on top of desktop gl
2668         ORD(glGetShaderPrecisionFormat);
2669         ORD(glReleaseShaderCompiler);
2670         ORD(glShaderBinary);
2671      }
2672
2673    ORD(glShaderSource);    // Do precision stripping in both cases
2674 #undef ORD
2675 }
2676
2677 //-------------------------------------------//
2678 static int
2679 gl_lib_init(void)
2680 {
2681    // dlopen OSMesa 
2682    gl_lib_handle = dlopen("libOSMesa.so.1", RTLD_NOW);
2683    if (!gl_lib_handle) gl_lib_handle = dlopen("libOSMesa.so", RTLD_NOW);
2684    if (!gl_lib_handle)
2685      {
2686         DBG("Unable to open libOSMesa:  %s", dlerror());
2687         return 0;
2688      }
2689
2690    //------------------------------------------------//
2691    if (!glue_sym_init()) return 0;
2692    if (!gl_sym_init()) return 0;
2693
2694    override_gl_apis(&gl_funcs);
2695   
2696    return 1;
2697 }
2698
2699
2700 static void 
2701 init_gl()
2702 {
2703    DBG("Initializing Software OpenGL APIs...\n");
2704
2705    if (!gl_lib_init())
2706       DBG("Unable to support EvasGL in this engine module. Install OSMesa to get it running");
2707    else
2708      {
2709 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
2710         ORD(gl_surface_create);
2711         ORD(gl_surface_destroy);
2712         ORD(gl_context_create);
2713         ORD(gl_context_destroy);
2714         ORD(gl_make_current);
2715         ORD(gl_string_query);           // FIXME: Need to implement
2716         ORD(gl_proc_address_get);       // FIXME: Need to implement
2717         ORD(gl_native_surface_get);
2718         ORD(gl_api_get);
2719 #undef ORD
2720      }
2721 }
2722
2723
2724 /*
2725  *****
2726  **
2727  ** MODULE ACCESSIBLE API API
2728  **
2729  *****
2730  */
2731
2732 static int
2733 module_open(Evas_Module *em)
2734 {
2735    if (!em) return 0;
2736    _evas_soft_gen_log_dom = eina_log_domain_register
2737      ("evas-software_generic", EVAS_DEFAULT_LOG_COLOR);
2738    if(_evas_soft_gen_log_dom<0)
2739      {
2740         EINA_LOG_ERR("Can not create a module log domain.");
2741         return 0;
2742      }
2743
2744    init_gl();
2745
2746    em->functions = (void *)(&func);
2747    cpunum = eina_cpu_count();
2748    return 1;
2749 }
2750
2751 static void
2752 module_close(Evas_Module *em __UNUSED__)
2753 {
2754   eina_log_domain_unregister(_evas_soft_gen_log_dom);
2755 }
2756
2757 static Evas_Module_Api evas_modapi =
2758 {
2759    EVAS_MODULE_API_VERSION,
2760    "software_generic",
2761    "none",
2762    {
2763      module_open,
2764      module_close
2765    }
2766 };
2767
2768 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_generic);
2769
2770 #ifndef EVAS_STATIC_BUILD_SOFTWARE_GENERIC
2771 EVAS_EINA_MODULE_DEFINE(engine, software_generic);
2772 #endif