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