aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/modules/engines/gl_x11/evas_engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/evas/src/modules/engines/gl_x11/evas_engine.c')
-rw-r--r--libraries/evas/src/modules/engines/gl_x11/evas_engine.c3993
1 files changed, 3993 insertions, 0 deletions
diff --git a/libraries/evas/src/modules/engines/gl_x11/evas_engine.c b/libraries/evas/src/modules/engines/gl_x11/evas_engine.c
new file mode 100644
index 0000000..38e0c13
--- /dev/null
+++ b/libraries/evas/src/modules/engines/gl_x11/evas_engine.c
@@ -0,0 +1,3993 @@
1#include "evas_common.h" /* Also includes international specific stuff */
2#include "evas_engine.h"
3
4#ifdef HAVE_DLSYM
5# include <dlfcn.h> /* dlopen,dlclose,etc */
6#else
7# error gl_x11 should not get compiled if dlsym is not found on the system!
8#endif
9
10#define EVAS_GL_NO_GL_H_CHECK 1
11#include "Evas_GL.h"
12
13#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
14// EGL / GLES
15# if defined(GLES_VARIETY_S3C6410)
16# elif defined(GLES_VARIETY_SGX)
17# endif
18#else
19// GLX
20#endif
21
22typedef struct _Render_Engine Render_Engine;
23typedef struct _Render_Engine_GL_Surface Render_Engine_GL_Surface;
24typedef struct _Render_Engine_GL_Context Render_Engine_GL_Context;
25typedef struct _Render_Engine_GL_Resource Render_Engine_GL_Resource;
26typedef struct _Extension_Entry Extension_Entry;
27
28struct _Render_Engine
29{
30 Evas_GL_X11_Window *win;
31 Evas_Engine_Info_GL_X11 *info;
32 Evas *evas;
33 Tilebuf *tb;
34 int end;
35/*
36 XrmDatabase xrdb; // xres - dpi
37 struct { // xres - dpi
38 int dpi; // xres - dpi
39 } xr; // xres - dpi
40 */
41 int w, h;
42 int vsync;
43
44};
45
46struct _Render_Engine_GL_Surface
47{
48 int initialized;
49 int fbo_attached;
50 int w, h;
51 int depth_bits;
52 int stencil_bits;
53
54 // Render target texture/buffers
55 GLuint rt_tex;
56 GLint rt_internal_fmt;
57 GLenum rt_fmt;
58 GLuint rb_depth;
59 GLenum rb_depth_fmt;
60 GLuint rb_stencil;
61 GLenum rb_stencil_fmt;
62
63 Render_Engine_GL_Context *current_ctx;
64};
65
66struct _Render_Engine_GL_Context
67{
68 int initialized;
69#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
70 EGLContext context;
71#else
72 GLXContext context;
73#endif
74 GLuint context_fbo;
75 GLuint current_fbo;
76
77 Render_Engine_GL_Surface *current_sfc;
78};
79
80// Resources used per thread
81struct _Render_Engine_GL_Resource
82{
83 // Resource context/surface per Thread in TLS for evasgl use
84#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
85 EGLContext context;
86 EGLSurface surface;
87#else
88 GLXContext context;
89#endif
90};
91
92// Extension Handling
93struct _Extension_Entry
94{
95 const char *name;
96 const char *real_name;
97 int supported;
98};
99
100static int initted = 0;
101static int gl_wins = 0;
102static Render_Engine_GL_Context *current_evgl_ctx;
103static Render_Engine *current_engine;
104
105static char _gl_ext_string[1024];
106static char _evasgl_ext_string[1024];
107
108// Resource context/surface per Thread in TLS for evasgl use
109static Eina_TLS resource_key;
110static Eina_List *resource_list;
111LK(resource_lock);
112
113typedef void (*_eng_fn) (void);
114typedef _eng_fn (*glsym_func_eng_fn) ();
115typedef void (*glsym_func_void) ();
116typedef void *(*glsym_func_void_ptr) ();
117typedef int (*glsym_func_int) ();
118typedef unsigned int (*glsym_func_uint) ();
119typedef unsigned char (*glsym_func_uchar) ();
120typedef unsigned char *(*glsym_func_uchar_ptr) ();
121typedef const char *(*glsym_func_const_char_ptr) ();
122
123#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
124
125#ifndef EGL_NATIVE_PIXMAP_KHR
126# define EGL_NATIVE_PIXMAP_KHR 0x30b0
127#endif
128_eng_fn (*glsym_eglGetProcAddress) (const char *a) = NULL;
129void (*glsym_eglBindTexImage) (EGLDisplay a, EGLSurface b, int c) = NULL;
130void (*glsym_eglReleaseTexImage) (EGLDisplay a, EGLSurface b, int c) = NULL;
131void *(*glsym_eglCreateImage) (EGLDisplay a, EGLContext b, EGLenum c, EGLClientBuffer d, const int *e) = NULL;
132void (*glsym_eglDestroyImage) (EGLDisplay a, void *b) = NULL;
133void (*glsym_glEGLImageTargetTexture2DOES) (int a, void *b) = NULL;
134void (*glsym_glEGLImageTargetRenderbufferStorageOES) (int a, void *b) = NULL;
135void *(*glsym_eglMapImageSEC) (void *a, void *b) = NULL;
136unsigned int (*glsym_eglUnmapImageSEC) (void *a, void *b) = NULL;
137const char *(*glsym_eglQueryString) (EGLDisplay a, int name) = NULL;
138
139unsigned int (*glsym_eglLockSurface) (EGLDisplay a, EGLSurface b, const int *attrib_list) = NULL;
140unsigned int (*glsym_eglUnlockSurface) (EGLDisplay a, EGLSurface b) = NULL;
141
142#else
143typedef XID (*glsym_func_xid) ();
144
145_eng_fn (*glsym_glXGetProcAddress) (const char *a) = NULL;
146void (*glsym_glXBindTexImage) (Display *a, GLXDrawable b, int c, int *d) = NULL;
147void (*glsym_glXReleaseTexImage) (Display *a, GLXDrawable b, int c) = NULL;
148int (*glsym_glXGetVideoSync) (unsigned int *a) = NULL;
149int (*glsym_glXWaitVideoSync) (int a, int b, unsigned int *c) = NULL;
150XID (*glsym_glXCreatePixmap) (Display *a, void *b, Pixmap c, const int *d) = NULL;
151void (*glsym_glXDestroyPixmap) (Display *a, XID b) = NULL;
152void (*glsym_glXQueryDrawable) (Display *a, XID b, int c, unsigned int *d) = NULL;
153int (*glsym_glXSwapIntervalSGI) (int a) = NULL;
154void (*glsym_glXSwapIntervalEXT) (Display *s, GLXDrawable b, int c) = NULL;
155
156const char *(*glsym_glXQueryExtensionsString) (Display *a, int screen) = NULL;
157#endif
158
159// GLES2 Extensions
160void (*glsym_glGetProgramBinaryOES) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary) = NULL;
161void (*glsym_glProgramBinaryOES) (GLuint program, GLenum binaryFormat, const void *binary, GLint length) = NULL;
162void* (*glsym_glMapBufferOES) (GLenum target, GLenum access) = NULL;
163unsigned char (*glsym_glUnmapBufferOES) (GLenum target) = NULL;
164void (*glsym_glGetBufferPointervOES) (GLenum target, GLenum pname, void** params) = NULL;
165void (*glsym_glTexImage3DOES) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void* pixels) = NULL;
166void (*glsym_glTexSubImage3DOES) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void* pixels) = NULL;
167void (*glsym_glCopyTexSubImage3DOES) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) = NULL;
168void (*glsym_glCompressedTexImage3DOES) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void* data) = NULL;
169void (*glsym_glCompressedTexSubImage3DOES) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void* data) = NULL;
170void (*glsym_glFramebufferTexture3DOES) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset) = NULL;
171void (*glsym_glGetPerfMonitorGroupsAMD) (GLint* numGroups, GLsizei groupsSize, GLuint* groups) = NULL;
172void (*glsym_glGetPerfMonitorCountersAMD) (GLuint group, GLint* numCounters, GLint* maxActiveCounters, GLsizei counterSize, GLuint* counters) = NULL;
173void (*glsym_glGetPerfMonitorGroupStringAMD) (GLuint group, GLsizei bufSize, GLsizei* length, char* groupString) = NULL;
174void (*glsym_glGetPerfMonitorCounterStringAMD) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei* length, char* counterString) = NULL;
175void (*glsym_glGetPerfMonitorCounterInfoAMD) (GLuint group, GLuint counter, GLenum pname, void* data) = NULL;
176void (*glsym_glGenPerfMonitorsAMD) (GLsizei n, GLuint* monitors) = NULL;
177void (*glsym_glDeletePerfMonitorsAMD) (GLsizei n, GLuint* monitors) = NULL;
178void (*glsym_glSelectPerfMonitorCountersAMD) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint* countersList) = NULL;
179void (*glsym_glBeginPerfMonitorAMD) (GLuint monitor) = NULL;
180void (*glsym_glEndPerfMonitorAMD) (GLuint monitor) = NULL;
181void (*glsym_glGetPerfMonitorCounterDataAMD) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint* data, GLint* bytesWritten) = NULL;
182void (*glsym_glDiscardFramebufferEXT) (GLenum target, GLsizei numAttachments, const GLenum* attachments) = NULL;
183void (*glsym_glMultiDrawArraysEXT) (GLenum mode, GLint* first, GLsizei* count, GLsizei primcount) = NULL;
184void (*glsym_glMultiDrawElementsEXT) (GLenum mode, const GLsizei* count, GLenum type, const GLvoid** indices, GLsizei primcount) = NULL;
185void (*glsym_glDeleteFencesNV) (GLsizei n, const GLuint* fences) = NULL;
186void (*glsym_glGenFencesNV) (GLsizei n, GLuint* fences) = NULL;
187unsigned char (*glsym_glIsFenceNV) (GLuint fence) = NULL;
188unsigned char (*glsym_glTestFenceNV) (GLuint fence) = NULL;
189void (*glsym_glGetFenceivNV) (GLuint fence, GLenum pname, GLint* params) = NULL;
190void (*glsym_glFinishFenceNV) (GLuint fence) = NULL;
191void (*glsym_glSetFenceNV) (GLuint, GLenum) = NULL;
192void (*glsym_glGetDriverControlsQCOM) (GLint* num, GLsizei size, GLuint* driverControls) = NULL;
193void (*glsym_glGetDriverControlStringQCOM) (GLuint driverControl, GLsizei bufSize, GLsizei* length, char* driverControlString) = NULL;
194void (*glsym_glEnableDriverControlQCOM) (GLuint driverControl) = NULL;
195void (*glsym_glDisableDriverControlQCOM) (GLuint driverControl) = NULL;
196void (*glsym_glExtGetTexturesQCOM) (GLuint* textures, GLint maxTextures, GLint* numTextures) = NULL;
197void (*glsym_glExtGetBuffersQCOM) (GLuint* buffers, GLint maxBuffers, GLint* numBuffers) = NULL;
198void (*glsym_glExtGetRenderbuffersQCOM) (GLuint* renderbuffers, GLint maxRenderbuffers, GLint* numRenderbuffers) = NULL;
199void (*glsym_glExtGetFramebuffersQCOM) (GLuint* framebuffers, GLint maxFramebuffers, GLint* numFramebuffers) = NULL;
200void (*glsym_glExtGetTexLevelParameterivQCOM) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint* params) = NULL;
201void (*glsym_glExtTexObjectStateOverrideiQCOM) (GLenum target, GLenum pname, GLint param) = NULL;
202void (*glsym_glExtGetTexSubImageQCOM) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, void* texels) = NULL;
203void (*glsym_glExtGetBufferPointervQCOM) (GLenum target, void** params) = NULL;
204void (*glsym_glExtGetShadersQCOM) (GLuint* shaders, GLint maxShaders, GLint* numShaders) = NULL;
205void (*glsym_glExtGetProgramsQCOM) (GLuint* programs, GLint maxPrograms, GLint* numPrograms) = NULL;
206unsigned char (*glsym_glExtIsProgramBinaryQCOM) (GLuint program) = NULL;
207void (*glsym_glExtGetProgramBinarySourceQCOM) (GLuint program, GLenum shadertype, char* source, GLint* length) = NULL;
208
209
210//------ GLES 2.0 Extensions supported in EvasGL -----//
211static Extension_Entry _gl_ext_entries[] = {
212#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
213 //--- Function Extensions ---//
214 { "GL_OES_get_program_binary", "get_program_binary", 0 },
215 { "GL_OES_mapbuffer", "mapbuffer", 0 },
216 { "GL_OES_texture_3D", "texture_3D", 0 },
217 { "AMD_performance_monitor", "AMD_performance_monitor", 0 },
218 { "GL_EXT_discard_framebuffer", "discard_framebuffer", 0 },
219 { "GL_EXT_multi_draw_arrays", "multi_draw_arrays", 0 },
220 { "GL_NV_fence", "NV_fence", 0 },
221 { "GL_QCOM_driver_control", "QCOM_driver_control", 0 },
222 { "GL_QCOM_extended_get", "QCOM_extended_get", 0 },
223 { "GL_QCOM_extended_get2", "QCOM_extended_get2", 0 },
224
225 //--- Define Extensions ---//
226 { "GL_OES_compressed_ETC1_RGB8_texture", "compressed_ETC1_RGB8_texture", 0 },
227 { "GL_OES_compressed_paletted_texture", "compressed_paletted_texture", 0 },
228 { "GL_OES_depth24", "depth24", 0 },
229 { "GL_OES_depth32", "depth32", 0 },
230 { "GL_OES_EvasGL_image", "EGL_image", 0 },
231 { "GL_OES_packed_depth_stencil", "packed_depth_stencil", 0 },
232 { "GL_OES_rgb8_rgba8", "rgb8_rgba8", 0 },
233 { "GL_OES_standard_derivatives", "standard_derivatives", 0 },
234 { "GL_OES_stencil1", "stencil1", 0 },
235 { "GL_OES_stencil4", "stencil4", 0 },
236 { "GL_OES_texture_float", "texture_float", 0 },
237 { "GL_OES_texture_half_float", "texture_half_float", 0 },
238 { "GL_OES_texture_half_float_linear", "texture_half_float_linear", 0 },
239 { "GL_OES_texture_npot", "texture_npot", 0 },
240 { "GL_OES_vertex_half_float", "vertex_half_float", 0 },
241 { "GL_OES_vertex_type_10_10_10_2", "vertex_type_10_10_10_2", 0 },
242 { "GL_AMD_compressed_3DC_texture", "compressed_3DC_texture", 0 },
243 { "GL_AMD_compressed_ATC_texture", "compressed_ATC_texture", 0 },
244 { "GL_AMD_program_binary_Z400", "program_binary_Z400", 0 },
245 { "GL_EXT_blend_minmax", "blend_minmax", 0 },
246 { "GL_EXT_read_format_bgra", "read_format_bgra", 0 },
247 { "GL_EXT_texture_filter_anisotropic", "texture_filter_anisotrophic", 0 },
248 { "GL_EXT_texture_format_BGRA8888", "texture_format_BGRA8888", 0 },
249 { "GL_EXT_texture_type_2_10_10_10_REV", "texture_type_2_10_10_10_rev", 0 },
250 { "GL_IMG_program_binary", "IMG_program_binary", 0 },
251 { "GL_IMG_read_format", "IMG_read_format", 0 },
252 { "GL_IMG_shader_binary", "IMG_shader_binary", 0 },
253 { "GL_IMG_texture_compression_pvrtc", "IMG_texture_compression_pvrtc", 0 },
254 { "GL_QCOM_perfmon_global_mode", "QCOM_perfmon_global_mode", 0 },
255 { "GL_QCOM_writeonly_rendering", "QCOM_writeonly_rendering", 0 },
256#else
257 //--- Function Extensions ---//
258 { "GL_OES_get_program_binary", "get_program_binary", 0 },
259 { "GL_OES_mapbuffer", "mapbuffer", 0 },
260 { "GL_OES_texture_3D", "texture_3D", 0 },
261 { "AMD_performance_monitor", "AMD_performance_monitor", 0 },
262 { "GL_EXT_discard_framebuffer", "discard_framebuffer", 0 },
263 { "GL_EXT_multi_draw_arrays", "multi_draw_arrays", 0 },
264 { "GL_NV_fence", "NV_fence", 0 },
265 { "GL_QCOM_driver_control", "QCOM_driver_control", 0 },
266 { "GL_QCOM_extended_get", "QCOM_extended_get", 0 },
267 { "GL_QCOM_extended_get2", "QCOM_extended_get2", 0 },
268
269 //--- Define Extensions ---//
270 { "GL_OES_compressed_ETC1_RGB8_texture", "compressed_ETC1_RGB8_texture", 0 },
271 { "GL_OES_compressed_paletted_texture", "compressed_paletted_texture", 0 },
272 { "GL_OES_depth24", "depth24", 0 },
273 { "GL_OES_depth32", "depth32", 0 },
274 { "GL_OES_EvasGL_image", "EGL_image", 0 },
275 { "GL_OES_packed_depth_stencil", "packed_depth_stencil", 0 },
276 { "GL_OES_rgb8_rgba8", "rgb8_rgba8", 0 },
277 { "GL_OES_standard_derivatives", "standard_derivatives", 0 },
278 { "GL_OES_stencil1", "stencil1", 0 },
279 { "GL_OES_stencil4", "stencil4", 0 },
280 { "GL_OES_texture_float", "texture_float", 0 },
281 { "GL_OES_texture_half_float", "texture_half_float", 0 },
282 { "GL_OES_texture_half_float_linear", "texture_half_float_linear", 0 },
283 { "GL_OES_texture_npot", "texture_non_power_of_two", 0 }, // Desktop differs
284 { "GL_OES_vertex_half_float", "half_float_vertex", 0 }, // Desktop differs
285 { "GL_OES_vertex_type_10_10_10_2", "vertex_type_10_10_10_2", 0 },
286 { "GL_AMD_compressed_3DC_texture", "compressed_3DC_texture", 0 },
287 { "GL_AMD_compressed_ATC_texture", "compressed_ATC_texture", 0 },
288 { "GL_AMD_program_binary_Z400", "program_binary_Z400", 0 },
289 { "GL_EXT_blend_minmax", "blend_minmax", 0 },
290 { "GL_EXT_read_format_bgra", "bgra", 0 }, // Desktop differs
291 { "GL_EXT_texture_filter_anisotropic", "texture_filter_anisotrophic", 0 },
292 { "GL_EXT_texture_format_BGRA8888", "bgra", 0 }, // Desktop differs
293 { "GL_EXT_texture_type_2_10_10_10_REV", "vertex_type_2_10_10_10_rev", 0 }, // Desktop differs ???
294 { "GL_IMG_program_binary", "IMG_program_binary", 0 },
295 { "GL_IMG_read_format", "IMG_read_format", 0 },
296 { "GL_IMG_shader_binary", "IMG_shader_binary", 0 },
297 { "GL_IMG_texture_compression_pvrtc", "IMG_texture_compression_pvrtc", 0 },
298 { "GL_QCOM_perfmon_global_mode", "QCOM_perfmon_global_mode", 0 },
299 { "GL_QCOM_writeonly_rendering", "QCOM_writeonly_rendering", 0 },
300
301#endif
302 { NULL, NULL, 0}
303};
304
305//------ Extensions supported in EvasGL -----//
306static Extension_Entry _evasgl_ext_entries[] = {
307#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
308 { "EvasGL_KHR_image", "EGL_KHR_image", 0 },
309 { "EvasGL_KHR_vg_parent_image", "EGL_KHR_vg_parent_image", 0 },
310 { "EvasGL_KHR_gl_texture_2D_image", "EGL_KHR_gl_texture_2D_image", 0 },
311 { "EvasGL_KHR_gl_texture_cubemap_image", "EGL_KHR_gl_texture_cubemap_image", 0 },
312 { "EvasGL_KHR_gl_texture_3D_image", "EGL_KHR_gl_texture_3D_image", 0 },
313 { "EvasGL_KHR_gl_renderbuffer_image", "EGL_KHR_gl_renderbuffer_image", 0 },
314#else
315#endif
316 { NULL, NULL, 0 }
317};
318
319static void
320_sym_init(void)
321{
322 static int done = 0;
323
324 if (done) return;
325
326#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
327#define FINDSYM(dst, sym, typ) \
328 if ((!dst) && (glsym_eglGetProcAddress)) dst = (typ)glsym_eglGetProcAddress(sym); \
329 if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
330
331 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddress", glsym_func_eng_fn);
332 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddressEXT", glsym_func_eng_fn);
333 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddressARB", glsym_func_eng_fn);
334 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddressKHR", glsym_func_eng_fn);
335
336 FINDSYM(glsym_eglBindTexImage, "eglBindTexImage", glsym_func_void);
337 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageEXT", glsym_func_void);
338 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageARB", glsym_func_void);
339 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageKHR", glsym_func_void);
340
341 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImage", glsym_func_void);
342 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageEXT", glsym_func_void);
343 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageARB", glsym_func_void);
344 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageKHR", glsym_func_void);
345
346 FINDSYM(glsym_eglCreateImage, "eglCreateImage", glsym_func_void_ptr);
347 FINDSYM(glsym_eglCreateImage, "eglCreateImageEXT", glsym_func_void_ptr);
348 FINDSYM(glsym_eglCreateImage, "eglCreateImageARB", glsym_func_void_ptr);
349 FINDSYM(glsym_eglCreateImage, "eglCreateImageKHR", glsym_func_void_ptr);
350
351 FINDSYM(glsym_eglDestroyImage, "eglDestroyImage", glsym_func_void);
352 FINDSYM(glsym_eglDestroyImage, "eglDestroyImageEXT", glsym_func_void);
353 FINDSYM(glsym_eglDestroyImage, "eglDestroyImageARB", glsym_func_void);
354 FINDSYM(glsym_eglDestroyImage, "eglDestroyImageKHR", glsym_func_void);
355
356 FINDSYM(glsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", glsym_func_void);
357
358 FINDSYM(glsym_glEGLImageTargetRenderbufferStorageOES, "glEGLImageTargetRenderbufferStorageOES", glsym_func_void);
359
360 FINDSYM(glsym_eglMapImageSEC, "eglMapImageSEC", glsym_func_void_ptr);
361 FINDSYM(glsym_eglUnmapImageSEC, "eglUnmapImageSEC", glsym_func_uint);
362
363 FINDSYM(glsym_eglQueryString, "eglQueryString", glsym_func_const_char_ptr);
364
365 FINDSYM(glsym_eglLockSurface, "eglLockSurface", glsym_func_uint);
366 FINDSYM(glsym_eglLockSurface, "eglLockSurfaceEXT", glsym_func_uint);
367 FINDSYM(glsym_eglLockSurface, "eglLockSurfaceARB", glsym_func_uint);
368 FINDSYM(glsym_eglLockSurface, "eglLockSurfaceKHR", glsym_func_uint);
369
370 FINDSYM(glsym_eglUnlockSurface, "eglUnlockSurface", glsym_func_uint);
371 FINDSYM(glsym_eglUnlockSurface, "eglUnlockSurfaceEXT", glsym_func_uint);
372 FINDSYM(glsym_eglUnlockSurface, "eglUnlockSurfaceARB", glsym_func_uint);
373 FINDSYM(glsym_eglUnlockSurface, "eglUnlockSurfaceKHR", glsym_func_uint);
374
375#else
376#define FINDSYM(dst, sym, typ) \
377 if ((!dst) && (glsym_glXGetProcAddress)) dst = (typ)glsym_glXGetProcAddress(sym); \
378 if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
379
380 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddress", glsym_func_eng_fn);
381 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressEXT", glsym_func_eng_fn);
382 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressARB", glsym_func_eng_fn);
383
384 FINDSYM(glsym_glXBindTexImage, "glXBindTexImage", glsym_func_void);
385 FINDSYM(glsym_glXBindTexImage, "glXBindTexImageEXT", glsym_func_void);
386 FINDSYM(glsym_glXBindTexImage, "glXBindTexImageARB", glsym_func_void);
387
388 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImage", glsym_func_void);
389 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImageEXT", glsym_func_void);
390 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImageARB", glsym_func_void);
391
392 FINDSYM(glsym_glXGetVideoSync, "glXGetVideoSyncSGI", glsym_func_int);
393
394 FINDSYM(glsym_glXWaitVideoSync, "glXWaitVideoSyncSGI", glsym_func_int);
395
396 FINDSYM(glsym_glXCreatePixmap, "glXCreatePixmap", glsym_func_xid);
397 FINDSYM(glsym_glXCreatePixmap, "glXCreatePixmapEXT", glsym_func_xid);
398 FINDSYM(glsym_glXCreatePixmap, "glXCreatePixmapARB", glsym_func_xid);
399
400 FINDSYM(glsym_glXDestroyPixmap, "glXDestroyPixmap", glsym_func_void);
401 FINDSYM(glsym_glXDestroyPixmap, "glXDestroyPixmapEXT", glsym_func_void);
402 FINDSYM(glsym_glXDestroyPixmap, "glXDestroyPixmapARB", glsym_func_void);
403
404 FINDSYM(glsym_glXQueryDrawable, "glXQueryDrawable", glsym_func_void);
405 FINDSYM(glsym_glXQueryDrawable, "glXQueryDrawableEXT", glsym_func_void);
406 FINDSYM(glsym_glXQueryDrawable, "glXQueryDrawableARB", glsym_func_void);
407
408 FINDSYM(glsym_glXSwapIntervalSGI, "glXSwapIntervalMESA", glsym_func_int);
409 FINDSYM(glsym_glXSwapIntervalSGI, "glXSwapIntervalSGI", glsym_func_int);
410
411 FINDSYM(glsym_glXSwapIntervalEXT, "glXSwapIntervalEXT", glsym_func_void);
412
413 FINDSYM(glsym_glXQueryExtensionsString, "glXQueryExtensionsString", glsym_func_const_char_ptr);
414#endif
415
416 //----------- GLES 2.0 Extensions ------------//
417 // If the symbol's not found, they get set to NULL
418 // If one of the functions in the extension exists, the extension in supported
419 /* GL_OES_get_program_binary */
420 FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinary", glsym_func_void);
421 FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinaryEXT", glsym_func_void);
422 FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinaryARB", glsym_func_void);
423 FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinaryOES", glsym_func_void);
424
425 FINDSYM(glsym_glProgramBinaryOES, "glProgramBinary", glsym_func_void);
426 FINDSYM(glsym_glProgramBinaryOES, "glProgramBinaryEXT", glsym_func_void);
427 FINDSYM(glsym_glProgramBinaryOES, "glProgramBinaryARB", glsym_func_void);
428 FINDSYM(glsym_glProgramBinaryOES, "glProgramBinaryOES", glsym_func_void);
429
430 // Check the first function to see if the extension is supported...
431 if (glsym_glGetProgramBinaryOES) _gl_ext_entries[0].supported = 1;
432
433
434 /* GL_OES_mapbuffer */
435 FINDSYM(glsym_glMapBufferOES, "glMapBuffer", glsym_func_void_ptr);
436 FINDSYM(glsym_glMapBufferOES, "glMapBufferEXT", glsym_func_void_ptr);
437 FINDSYM(glsym_glMapBufferOES, "glMapBufferARB", glsym_func_void_ptr);
438 FINDSYM(glsym_glMapBufferOES, "glMapBufferOES", glsym_func_void_ptr);
439
440 FINDSYM(glsym_glUnmapBufferOES, "glUnmapBuffer", glsym_func_uchar);
441 FINDSYM(glsym_glUnmapBufferOES, "glUnmapBufferEXT", glsym_func_uchar);
442 FINDSYM(glsym_glUnmapBufferOES, "glUnmapBufferARB", glsym_func_uchar);
443 FINDSYM(glsym_glUnmapBufferOES, "glUnmapBufferOES", glsym_func_uchar);
444
445 FINDSYM(glsym_glGetBufferPointervOES, "glGetBufferPointerv", glsym_func_void);
446 FINDSYM(glsym_glGetBufferPointervOES, "glGetBufferPointervEXT", glsym_func_void);
447 FINDSYM(glsym_glGetBufferPointervOES, "glGetBufferPointervARB", glsym_func_void);
448 FINDSYM(glsym_glGetBufferPointervOES, "glGetBufferPointervOES", glsym_func_void);
449
450 if (glsym_glMapBufferOES) _gl_ext_entries[1].supported = 1;
451
452 /* GL_OES_texture_3D */
453 FINDSYM(glsym_glTexImage3DOES, "glTexImage3D", glsym_func_void);
454 FINDSYM(glsym_glTexImage3DOES, "glTexImage3DEXT", glsym_func_void);
455 FINDSYM(glsym_glTexImage3DOES, "glTexImage3DARB", glsym_func_void);
456 FINDSYM(glsym_glTexImage3DOES, "glTexImage3DOES", glsym_func_void);
457
458 FINDSYM(glsym_glTexSubImage3DOES, "glTexSubImage3D", glsym_func_void);
459 FINDSYM(glsym_glTexSubImage3DOES, "glTexSubImage3DEXT", glsym_func_void);
460 FINDSYM(glsym_glTexSubImage3DOES, "glTexSubImage3DARB", glsym_func_void);
461 FINDSYM(glsym_glTexSubImage3DOES, "glTexSubImage3DOES", glsym_func_void);
462
463 FINDSYM(glsym_glCopyTexSubImage3DOES, "glCopyTexSubImage3D", glsym_func_void);
464 FINDSYM(glsym_glCopyTexSubImage3DOES, "glCopyTexSubImage3DARB", glsym_func_void);
465 FINDSYM(glsym_glCopyTexSubImage3DOES, "glCopyTexSubImage3DEXT", glsym_func_void);
466 FINDSYM(glsym_glCopyTexSubImage3DOES, "glCopyTexSubImage3DOES", glsym_func_void);
467
468 FINDSYM(glsym_glCompressedTexImage3DOES, "glCompressedTexImage3D", glsym_func_void);
469 FINDSYM(glsym_glCompressedTexImage3DOES, "glCompressedTexImage3DARB", glsym_func_void);
470 FINDSYM(glsym_glCompressedTexImage3DOES, "glCompressedTexImage3DEXT", glsym_func_void);
471 FINDSYM(glsym_glCompressedTexImage3DOES, "glCompressedTexImage3DOES", glsym_func_void);
472
473 FINDSYM(glsym_glCompressedTexSubImage3DOES, "glCompressedTexSubImage3D", glsym_func_void);
474 FINDSYM(glsym_glCompressedTexSubImage3DOES, "glCompressedTexSubImage3DARB", glsym_func_void);
475 FINDSYM(glsym_glCompressedTexSubImage3DOES, "glCompressedTexSubImage3DEXT", glsym_func_void);
476 FINDSYM(glsym_glCompressedTexSubImage3DOES, "glCompressedTexSubImage3DOES", glsym_func_void);
477
478 FINDSYM(glsym_glFramebufferTexture3DOES, "glFramebufferTexture3D", glsym_func_void);
479 FINDSYM(glsym_glFramebufferTexture3DOES, "glFramebufferTexture3DARB", glsym_func_void);
480 FINDSYM(glsym_glFramebufferTexture3DOES, "glFramebufferTexture3DEXT", glsym_func_void);
481 FINDSYM(glsym_glFramebufferTexture3DOES, "glFramebufferTexture3DOES", glsym_func_void);
482
483 if (glsym_glTexSubImage3DOES) _gl_ext_entries[2].supported = 1;
484
485 /* AMD_performance_monitor */
486 FINDSYM(glsym_glGetPerfMonitorGroupsAMD, "glGetPerfMonitorGroupsAMD", glsym_func_void);
487 FINDSYM(glsym_glGetPerfMonitorCountersAMD, "glGetPerfMonitorCountersAMD", glsym_func_void);
488 FINDSYM(glsym_glGetPerfMonitorGroupStringAMD, "glGetPerfMonitorGroupStringAMD", glsym_func_void);
489 FINDSYM(glsym_glGetPerfMonitorCounterStringAMD, "glGetPerfMonitorCounterStringAMD", glsym_func_void);
490 FINDSYM(glsym_glGetPerfMonitorCounterInfoAMD, "glGetPerfMonitorCounterInfoAMD", glsym_func_void);
491 FINDSYM(glsym_glGenPerfMonitorsAMD, "glGenPerfMonitorsAMD", glsym_func_void);
492 FINDSYM(glsym_glDeletePerfMonitorsAMD, "glDeletePerfMonitorsAMD", glsym_func_void);
493 FINDSYM(glsym_glSelectPerfMonitorCountersAMD, "glSelectPerfMonitorCountersAMD", glsym_func_void);
494 FINDSYM(glsym_glBeginPerfMonitorAMD, "glBeginPerfMonitorAMD", glsym_func_void);
495 FINDSYM(glsym_glEndPerfMonitorAMD, "glEndPerfMonitorAMD", glsym_func_void);
496 FINDSYM(glsym_glGetPerfMonitorCounterDataAMD, "glGetPerfMonitorCounterDataAMD", glsym_func_void);
497
498 if (glsym_glGetPerfMonitorGroupsAMD) _gl_ext_entries[3].supported = 1;
499
500 /* GL_EXT_discard_framebuffer */
501 FINDSYM(glsym_glDiscardFramebufferEXT, "glDiscardFramebuffer", glsym_func_void);
502 FINDSYM(glsym_glDiscardFramebufferEXT, "glDiscardFramebufferARB", glsym_func_void);
503 FINDSYM(glsym_glDiscardFramebufferEXT, "glDiscardFramebufferEXT", glsym_func_void);
504
505 if (glsym_glDiscardFramebufferEXT) _gl_ext_entries[4].supported = 1;
506
507 /* GL_EXT_multi_draw_arrays */
508 FINDSYM(glsym_glMultiDrawArraysEXT, "glMultiDrawArrays", glsym_func_void);
509 FINDSYM(glsym_glMultiDrawArraysEXT, "glMultiDrawArraysARB", glsym_func_void);
510 FINDSYM(glsym_glMultiDrawArraysEXT, "glMultiDrawArraysEXT", glsym_func_void);
511
512 FINDSYM(glsym_glMultiDrawElementsEXT, "glMultiDrawElements", glsym_func_void);
513 FINDSYM(glsym_glMultiDrawElementsEXT, "glMultiDrawElementsARB", glsym_func_void);
514 FINDSYM(glsym_glMultiDrawElementsEXT, "glMultiDrawElementsEXT", glsym_func_void);
515
516 if (glsym_glMultiDrawArraysEXT) _gl_ext_entries[5].supported = 1;
517
518 /* GL_NV_fence */
519 FINDSYM(glsym_glDeleteFencesNV, "glDeleteFencesNV", glsym_func_void);
520 FINDSYM(glsym_glGenFencesNV, "glGenFencesNV", glsym_func_void);
521 FINDSYM(glsym_glIsFenceNV, "glIsFenceNV", glsym_func_uchar);
522 FINDSYM(glsym_glTestFenceNV, "glTestFenceNV", glsym_func_uchar);
523 FINDSYM(glsym_glGetFenceivNV, "glGetFenceivNV", glsym_func_void);
524 FINDSYM(glsym_glFinishFenceNV, "glFinishFenceNV", glsym_func_void);
525 FINDSYM(glsym_glSetFenceNV, "glSetFenceNV", glsym_func_void);
526
527 if (glsym_glDeleteFencesNV) _gl_ext_entries[6].supported = 1;
528
529 /* GL_QCOM_driver_control */
530 FINDSYM(glsym_glGetDriverControlsQCOM, "glGetDriverControlsQCOM", glsym_func_void);
531 FINDSYM(glsym_glGetDriverControlStringQCOM, "glGetDriverControlStringQCOM", glsym_func_void);
532 FINDSYM(glsym_glEnableDriverControlQCOM, "glEnableDriverControlQCOM", glsym_func_void);
533 FINDSYM(glsym_glDisableDriverControlQCOM, "glDisableDriverControlQCOM", glsym_func_void);
534
535 if (glsym_glGetDriverControlsQCOM) _gl_ext_entries[7].supported = 1;
536
537 /* GL_QCOM_extended_get */
538 FINDSYM(glsym_glExtGetTexturesQCOM, "glExtGetTexturesQCOM", glsym_func_void);
539 FINDSYM(glsym_glExtGetBuffersQCOM, "glExtGetBuffersQCOM", glsym_func_void);
540 FINDSYM(glsym_glExtGetRenderbuffersQCOM, "glExtGetRenderbuffersQCOM", glsym_func_void);
541 FINDSYM(glsym_glExtGetFramebuffersQCOM, "glExtGetFramebuffersQCOM", glsym_func_void);
542 FINDSYM(glsym_glExtGetTexLevelParameterivQCOM, "glExtGetTexLevelParameterivQCOM", glsym_func_void);
543 FINDSYM(glsym_glExtTexObjectStateOverrideiQCOM, "glExtTexObjectStateOverrideiQCOM", glsym_func_void);
544 FINDSYM(glsym_glExtGetTexSubImageQCOM, "glExtGetTexSubImageQCOM", glsym_func_void);
545 FINDSYM(glsym_glExtGetBufferPointervQCOM, "glExtGetBufferPointervQCOM", glsym_func_void);
546
547 if (glsym_glExtGetTexturesQCOM) _gl_ext_entries[8].supported = 1;
548
549 /* GL_QCOM_extended_get2 */
550 FINDSYM(glsym_glExtGetShadersQCOM, "glExtGetShadersQCOM", glsym_func_void);
551 FINDSYM(glsym_glExtGetProgramsQCOM, "glExtGetProgramsQCOM", glsym_func_void);
552 FINDSYM(glsym_glExtIsProgramBinaryQCOM, "glExtIsProgramBinaryQCOM", glsym_func_uchar);
553 FINDSYM(glsym_glExtGetProgramBinarySourceQCOM, "glExtGetProgramBinarySourceQCOM", glsym_func_void);
554
555 if (glsym_glExtGetShadersQCOM) _gl_ext_entries[9].supported = 1;
556}
557
558static void
559_extensions_init(Render_Engine *re)
560{
561 int i;
562 const char *glexts, *evasglexts;
563
564 memset(_gl_ext_string, 0, 1024);
565 memset(_evasgl_ext_string, 0, 1024);
566
567 // GLES 2.0 Extensions
568 glexts = (const char*)glGetString(GL_EXTENSIONS);
569
570 DBG("--------GLES 2.0 Extensions--------");
571 for (i = 0; _gl_ext_entries[i].name != NULL; i++)
572 {
573 if ( (strstr(glexts, _gl_ext_entries[i].name) != NULL) ||
574 (strstr(glexts, _gl_ext_entries[i].real_name) != NULL) )
575 {
576 _gl_ext_entries[i].supported = 1;
577 strcat(_gl_ext_string, _gl_ext_entries[i].name);
578 strcat(_gl_ext_string, " ");
579 DBG("\t%s", _gl_ext_entries[i].name);
580 }
581
582 }
583 DBG(" ");
584
585#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
586 // EGL Extensions
587 evasglexts = glsym_eglQueryString(re->win->egl_disp, EGL_EXTENSIONS);
588#else
589 evasglexts = glXQueryExtensionsString(re->info->info.display,
590 re->info->info.screen);
591#endif
592
593 DBG("--------EvasGL Extensions----------");
594 for (i = 0; _evasgl_ext_entries[i].name != NULL; i++)
595 {
596 if ( (strstr(evasglexts, _evasgl_ext_entries[i].name) != NULL) ||
597 (strstr(evasglexts, _evasgl_ext_entries[i].real_name) != NULL) )
598 {
599 _evasgl_ext_entries[i].supported = 1;
600 strcat(_evasgl_ext_string, _evasgl_ext_entries[i].name);
601 strcat(_evasgl_ext_string, " ");
602 DBG("\t%s", _evasgl_ext_entries[i].name);
603 }
604 }
605 DBG(" ");
606}
607
608int _evas_engine_GL_X11_log_dom = -1;
609/* function tables - filled in later (func and parent func) */
610static Evas_Func func, pfunc;
611
612/* Function table for GL APIs */
613static Evas_GL_API gl_funcs;
614/*
615struct xrdb_user
616{
617 time_t last_stat;
618 time_t last_mtime;
619 XrmDatabase db;
620};
621static struct xrdb_user xrdb_user = {0, 0, NULL};
622
623static Eina_Bool
624xrdb_user_query(const char *name, const char *cls, char **type, XrmValue *val)
625{
626 time_t last = xrdb_user.last_stat, now = time(NULL);
627
628 xrdb_user.last_stat = now;
629 if (last != now) // don't stat() more than once every second
630 {
631 struct stat st;
632 const char *home = getenv("HOME");
633 char tmp[PATH_MAX];
634
635 if (!home) goto failed;
636 snprintf(tmp, sizeof(tmp), "%s/.Xdefaults", home);
637 if (stat(tmp, &st) != 0) goto failed;
638 if (xrdb_user.last_mtime != st.st_mtime)
639 {
640 if (xrdb_user.db) XrmDestroyDatabase(xrdb_user.db);
641 xrdb_user.db = XrmGetFileDatabase(tmp);
642 if (!xrdb_user.db) goto failed;
643 xrdb_user.last_mtime = st.st_mtime;
644 }
645 }
646
647 if (!xrdb_user.db) return EINA_FALSE;
648 return XrmGetResource(xrdb_user.db, name, cls, type, val);
649
650 failed:
651 if (xrdb_user.db)
652 {
653 XrmDestroyDatabase(xrdb_user.db);
654 xrdb_user.db = NULL;
655 }
656 xrdb_user.last_mtime = 0;
657 return EINA_FALSE;
658}
659*/
660
661static void *
662eng_info(Evas *e)
663{
664 Evas_Engine_Info_GL_X11 *info;
665
666 info = calloc(1, sizeof(Evas_Engine_Info_GL_X11));
667 info->magic.magic = rand();
668 info->func.best_visual_get = eng_best_visual_get;
669 info->func.best_colormap_get = eng_best_colormap_get;
670 info->func.best_depth_get = eng_best_depth_get;
671 info->render_mode = EVAS_RENDER_MODE_BLOCKING;
672 return info;
673 e = NULL;
674}
675
676static void
677eng_info_free(Evas *e __UNUSED__, void *info)
678{
679 Evas_Engine_Info_GL_X11 *in;
680// dont free! why bother? its not worth it
681// eina_log_domain_unregister(_evas_engine_GL_X11_log_dom);
682 in = (Evas_Engine_Info_GL_X11 *)info;
683 free(in);
684}
685
686static int
687_re_wincheck(Render_Engine *re)
688{
689 if (re->win->surf) return 1;
690 eng_window_resurf(re->win);
691 if (!re->win->surf)
692 {
693 ERR("GL engine can't re-create window surface!");
694 }
695 return 0;
696}
697
698static void
699_re_winfree(Render_Engine *re)
700{
701 if (!re->win->surf) return;
702 eng_window_unsurf(re->win);
703}
704
705static Render_Engine_GL_Resource *
706_create_internal_glue_resources(void *data)
707{
708 Render_Engine *re = (Render_Engine *)data;
709 Render_Engine_GL_Resource *rsc;
710
711 rsc = calloc(1, sizeof(Render_Engine_GL_Resource));
712
713 if (!rsc) return NULL;
714
715#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
716 // EGL
717 int context_attrs[3];
718 context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
719 context_attrs[1] = 2;
720 context_attrs[2] = EGL_NONE;
721
722 // Create resource surface for EGL
723 rsc->surface = eglCreateWindowSurface(re->win->egl_disp,
724 re->win->egl_config,
725 (EGLNativeWindowType)DefaultRootWindow(re->info->info.display),
726 NULL);
727 if (!rsc->surface)
728 {
729 ERR("Creating internal resource surface failed.");
730 free(rsc);
731 return NULL;
732 }
733
734 // Create a resource context for EGL
735 rsc->context = eglCreateContext(re->win->egl_disp,
736 re->win->egl_config,
737 re->win->egl_context[0], // Evas' GL Context
738 context_attrs);
739 if (!rsc->context)
740 {
741 ERR("Internal Resource Context Creations Failed.");
742 free(rsc);
743 return NULL;
744 }
745
746 // Add to the resource resource list for cleanup
747 LKL(resource_lock);
748 resource_list = eina_list_prepend(resource_list, rsc);
749 LKU(resource_lock);
750
751 // Set the resource in TLS
752 if (eina_tls_set(resource_key, (void*)rsc) == EINA_FALSE)
753 {
754 ERR("Failed setting TLS Resource");
755 free(rsc);
756 return NULL;
757 }
758
759#else
760 // GLX
761 rsc->context = glXCreateContext(re->info->info.display,
762 re->win->visualinfo,
763 re->win->context, // Evas' GL Context
764 1);
765 if (!rsc->context)
766 {
767 ERR("Internal Resource Context Creations Failed.");
768 free(rsc);
769 return NULL;
770 }
771
772 // Add to the resource resource list for cleanup
773 LKL(resource_lock);
774 resource_list = eina_list_prepend(resource_list, rsc);
775 LKU(resource_lock);
776
777 // Set the resource in TLS
778 if (eina_tls_set(resource_key, (void*)rsc) == EINA_FALSE)
779 {
780 ERR("Failed setting TLS Resource");
781 free(rsc);
782 return NULL;
783 }
784
785#endif
786
787
788 return rsc;
789}
790
791static int
792_destroy_internal_glue_resources(void *data)
793{
794 Render_Engine *re = (Render_Engine *)data;
795 Eina_List *l;
796 Render_Engine_GL_Resource *rsc;
797
798#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
799 // EGL
800 // Delete the Resources
801 LKL(resource_lock);
802 EINA_LIST_FOREACH(resource_list, l, rsc)
803 {
804 if (rsc->surface) eglDestroySurface(re->win->egl_disp, rsc->surface);
805 if (rsc->context) eglDestroyContext(re->win->egl_disp, rsc->context);
806 free(rsc);
807 }
808 eina_list_free(resource_list);
809 LKU(resource_lock);
810
811 // Destroy TLS
812 eina_tls_free(resource_key);
813#else
814 // GLX
815 // Delete the Resources
816 LKL(resource_lock);
817 EINA_LIST_FOREACH(resource_list, l, rsc)
818 {
819 if (rsc)
820 {
821 glXDestroyContext(re->info->info.display, rsc->context);
822 free(rsc);
823 }
824 }
825 eina_list_free(resource_list);
826 LKU(resource_lock);
827
828 // Destroy TLS
829 eina_tls_free(resource_key);
830#endif
831
832 return 1;
833}
834
835
836
837static int
838eng_setup(Evas *e, void *in)
839{
840 Render_Engine *re;
841 Evas_Engine_Info_GL_X11 *info;
842
843 info = (Evas_Engine_Info_GL_X11 *)in;
844 if (!e->engine.data.output)
845 {
846#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
847#else
848 int eb, evb;
849
850 if (!glXQueryExtension(info->info.display, &eb, &evb)) return 0;
851#endif
852 re = calloc(1, sizeof(Render_Engine));
853 if (!re) return 0;
854 re->info = info;
855 re->evas = e;
856 e->engine.data.output = re;
857 re->w = e->output.w;
858 re->h = e->output.h;
859 re->win = eng_window_new(re->info->info.display,
860 re->info->info.drawable,
861 re->info->info.screen,
862 re->info->info.visual,
863 re->info->info.colormap,
864 re->info->info.depth,
865 re->w,
866 re->h,
867 re->info->indirect,
868 re->info->info.destination_alpha,
869 re->info->info.rotation);
870 if (!re->win)
871 {
872 free(re);
873 e->engine.data.output = NULL;
874 return 0;
875 }
876
877 gl_wins++;
878/*
879 {
880 int status;
881 char *type = NULL;
882 XrmValue val;
883
884 re->xr.dpi = 75000; // dpy * 1000
885
886 status = xrdb_user_query("Xft.dpi", "Xft.Dpi", &type, &val);
887 if ((!status) || (!type))
888 {
889 if (!re->xrdb) re->xrdb = XrmGetDatabase(re->info->info.display);
890 if (re->xrdb)
891 status = XrmGetResource(re->xrdb,
892 "Xft.dpi", "Xft.Dpi", &type, &val);
893 }
894
895 if ((status) && (type))
896 {
897 if (!strcmp(type, "String"))
898 {
899 const char *str, *dp;
900
901 str = val.addr;
902 dp = strchr(str, '.');
903 if (!dp) dp = strchr(str, ',');
904
905 if (dp)
906 {
907 int subdpi, len, i;
908 char *buf;
909
910 buf = alloca(dp - str + 1);
911 strncpy(buf, str, dp - str);
912 buf[dp - str] = 0;
913 len = strlen(dp + 1);
914 subdpi = atoi(dp + 1);
915
916 if (len < 3)
917 {
918 for (i = len; i < 3; i++) subdpi *= 10;
919 }
920 else if (len > 3)
921 {
922 for (i = len; i > 3; i--) subdpi /= 10;
923 }
924 re->xr.dpi = atoi(buf) * 1000;
925 }
926 else
927 re->xr.dpi = atoi(str) * 1000;
928 evas_common_font_dpi_set(re->xr.dpi / 1000);
929 }
930 }
931 }
932 */
933 if (!initted)
934 {
935 evas_common_cpu_init();
936
937 evas_common_blend_init();
938 evas_common_image_init();
939 evas_common_convert_init();
940 evas_common_scale_init();
941 evas_common_rectangle_init();
942 evas_common_polygon_init();
943 evas_common_line_init();
944 evas_common_font_init();
945 evas_common_draw_init();
946 evas_common_tilebuf_init();
947
948 // Initialize TLS
949 if (eina_tls_new(&resource_key) == EINA_FALSE)
950 ERR("Error creating tls key");
951 DBG("TLS KEY create... %d", resource_key);
952
953 initted = 1;
954 }
955 }
956 else
957 {
958 re = e->engine.data.output;
959 if (_re_wincheck(re))
960 {
961 if ((re->info->info.display != re->win->disp) ||
962 (re->info->info.drawable != re->win->win) ||
963 (re->info->info.screen != re->win->screen) ||
964 (re->info->info.visual != re->win->visual) ||
965 (re->info->info.colormap != re->win->colormap) ||
966 (re->info->info.depth != re->win->depth) ||
967 (re->info->info.destination_alpha != re->win->alpha) ||
968 (re->info->info.rotation != re->win->rot))
969 {
970 int inc = 0;
971
972 if (re->win)
973 {
974 re->win->gl_context->references++;
975 eng_window_free(re->win);
976 inc = 1;
977 gl_wins--;
978 }
979 re->w = e->output.w;
980 re->h = e->output.h;
981 re->win = eng_window_new(re->info->info.display,
982 re->info->info.drawable,
983 re->info->info.screen,
984 re->info->info.visual,
985 re->info->info.colormap,
986 re->info->info.depth,
987 re->w,
988 re->h,
989 re->info->indirect,
990 re->info->info.destination_alpha,
991 re->info->info.rotation);
992 eng_window_use(re->win);
993 if (re->win) gl_wins++;
994 if ((re->win) && (inc))
995 re->win->gl_context->references--;
996 }
997 else if ((re->win->w != e->output.w) ||
998 (re->win->h != e->output.h))
999 {
1000 re->w = e->output.w;
1001 re->h = e->output.h;
1002 re->win->w = e->output.w;
1003 re->win->h = e->output.h;
1004 eng_window_use(re->win);
1005 evas_gl_common_context_resize(re->win->gl_context, re->win->w, re->win->h, re->win->rot);
1006 }
1007 }
1008 }
1009 if (!re->win)
1010 {
1011 free(re);
1012 return 0;
1013 }
1014
1015 if (!e->engine.data.output)
1016 {
1017 if (re->win)
1018 {
1019 eng_window_free(re->win);
1020 gl_wins--;
1021 }
1022 free(re);
1023 return 0;
1024 }
1025 re->tb = evas_common_tilebuf_new(re->win->w, re->win->h);
1026 if (!re->tb)
1027 {
1028 if (re->win)
1029 {
1030 eng_window_free(re->win);
1031 gl_wins--;
1032 }
1033 free(re);
1034 return 0;
1035 }
1036 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
1037
1038 if (!e->engine.data.context)
1039 e->engine.data.context =
1040 e->engine.func->context_new(e->engine.data.output);
1041 eng_window_use(re->win);
1042
1043 re->vsync = 0;
1044 _sym_init();
1045 _extensions_init(re);
1046
1047 // This is used in extensions. Not pretty but can't get display otherwise.
1048 current_engine = re;
1049
1050 return 1;
1051}
1052
1053static void
1054eng_output_free(void *data)
1055{
1056 Render_Engine *re;
1057
1058 re = (Render_Engine *)data;
1059
1060 if (re)
1061 {
1062// NOTE: XrmGetDatabase() result is shared per connection, do not free it.
1063// if (re->xrdb) XrmDestroyDatabase(re->xrdb);
1064
1065#if 0
1066#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1067 // Destroy the resource surface
1068 // Only required for EGL case
1069 if (re->surface)
1070 eglDestroySurface(re->win->egl_disp, re->surface);
1071#endif
1072
1073 // Destroy the resource context
1074 _destroy_internal_context(re, context);
1075#endif
1076 if (re->win)
1077 {
1078 if ((initted == 1) && (gl_wins == 1))
1079 _destroy_internal_glue_resources(re);
1080 eng_window_free(re->win);
1081 gl_wins--;
1082 }
1083 evas_common_tilebuf_free(re->tb);
1084 free(re);
1085 }
1086 if ((initted == 1) && (gl_wins == 0))
1087 {
1088 evas_common_image_shutdown();
1089 evas_common_font_shutdown();
1090 initted = 0;
1091 }
1092}
1093
1094static void
1095eng_output_resize(void *data, int w, int h)
1096{
1097 Render_Engine *re;
1098
1099 re = (Render_Engine *)data;
1100 re->win->w = w;
1101 re->win->h = h;
1102 eng_window_use(re->win);
1103 evas_gl_common_context_resize(re->win->gl_context, w, h, re->win->rot);
1104 evas_common_tilebuf_free(re->tb);
1105 re->tb = evas_common_tilebuf_new(w, h);
1106 if (re->tb)
1107 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
1108}
1109
1110static void
1111eng_output_tile_size_set(void *data, int w, int h)
1112{
1113 Render_Engine *re;
1114
1115 re = (Render_Engine *)data;
1116 evas_common_tilebuf_set_tile_size(re->tb, w, h);
1117}
1118
1119static void
1120eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
1121{
1122 Render_Engine *re;
1123
1124 re = (Render_Engine *)data;
1125 eng_window_use(re->win);
1126 evas_gl_common_context_resize(re->win->gl_context, re->win->w, re->win->h, re->win->rot);
1127 evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
1128/*
1129 RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, re->win->w, re->win->h);
1130 if ((w <= 0) || (h <= 0)) return;
1131 if (!re->win->draw.redraw)
1132 {
1133#if 0
1134 re->win->draw.x1 = x;
1135 re->win->draw.y1 = y;
1136 re->win->draw.x2 = x + w - 1;
1137 re->win->draw.y2 = y + h - 1;
1138#else
1139 re->win->draw.x1 = 0;
1140 re->win->draw.y1 = 0;
1141 re->win->draw.x2 = re->win->w - 1;
1142 re->win->draw.y2 = re->win->h - 1;
1143#endif
1144 }
1145 else
1146 {
1147 if (x < re->win->draw.x1) re->win->draw.x1 = x;
1148 if (y < re->win->draw.y1) re->win->draw.y1 = y;
1149 if ((x + w - 1) > re->win->draw.x2) re->win->draw.x2 = x + w - 1;
1150 if ((y + h - 1) > re->win->draw.y2) re->win->draw.y2 = y + h - 1;
1151 }
1152 re->win->draw.redraw = 1;
1153 */
1154}
1155
1156static void
1157eng_output_redraws_rect_del(void *data __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
1158{
1159 Render_Engine *re;
1160
1161 re = (Render_Engine *)data;
1162 evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
1163}
1164
1165static void
1166eng_output_redraws_clear(void *data)
1167{
1168 Render_Engine *re;
1169
1170 re = (Render_Engine *)data;
1171 evas_common_tilebuf_clear(re->tb);
1172/* re->win->draw.redraw = 0;*/
1173// INF("GL: finish update cycle!");
1174}
1175
1176/* vsync games - not for now though */
1177#define VSYNC_TO_SCREEN 1
1178
1179static void *
1180eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
1181{
1182 Render_Engine *re;
1183 Tilebuf_Rect *rects;
1184
1185 re = (Render_Engine *)data;
1186 /* get the upate rect surface - return engine data as dummy */
1187 rects = evas_common_tilebuf_get_render_rects(re->tb);
1188 if (rects)
1189 {
1190/*
1191 Tilebuf_Rect *r;
1192
1193 printf("REAAAAACCTS\n");
1194 EINA_INLIST_FOREACH(EINA_INLIST_GET(rects), r)
1195 {
1196 printf(" %i %i %ix%i\n", r->x, r->y, r->w, r->h);
1197 }
1198 */
1199 evas_common_tilebuf_free_render_rects(rects);
1200 evas_common_tilebuf_clear(re->tb);
1201#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1202 // dont need to for egl - eng_window_use() can check for other ctxt's
1203#else
1204 eng_window_use(NULL);
1205#endif
1206 eng_window_use(re->win);
1207 if (!_re_wincheck(re)) return NULL;
1208 evas_gl_common_context_flush(re->win->gl_context);
1209 evas_gl_common_context_newframe(re->win->gl_context);
1210 if (x) *x = 0;
1211 if (y) *y = 0;
1212 if (w) *w = re->win->w;
1213 if (h) *h = re->win->h;
1214 if (cx) *cx = 0;
1215 if (cy) *cy = 0;
1216 if (cw) *cw = re->win->w;
1217 if (ch) *ch = re->win->h;
1218 return re->win->gl_context->def_surface;
1219 }
1220 return NULL;
1221/*
1222 if (!re->win->draw.redraw) return NULL;
1223#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1224 // dont need to for egl - eng_window_use() can check for other ctxt's
1225#else
1226 eng_window_use(NULL);
1227#endif
1228 eng_window_use(re->win);
1229 if (!_re_wincheck(re)) return NULL;
1230 evas_gl_common_context_flush(re->win->gl_context);
1231 evas_gl_common_context_newframe(re->win->gl_context);
1232 if (x) *x = re->win->draw.x1;
1233 if (y) *y = re->win->draw.y1;
1234 if (w) *w = re->win->draw.x2 - re->win->draw.x1 + 1;
1235 if (h) *h = re->win->draw.y2 - re->win->draw.y1 + 1;
1236 if (cx) *cx = re->win->draw.x1;
1237 if (cy) *cy = re->win->draw.y1;
1238 if (cw) *cw = re->win->draw.x2 - re->win->draw.x1 + 1;
1239 if (ch) *ch = re->win->draw.y2 - re->win->draw.y1 + 1;
1240 return re->win->gl_context->def_surface;
1241 */
1242}
1243
1244//#define FRAMECOUNT 1
1245
1246#ifdef FRAMECOUNT
1247double
1248get_time(void)
1249{
1250 struct timeval timev;
1251
1252 gettimeofday(&timev, NULL);
1253 return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
1254}
1255#endif
1256
1257static int safe_native = -1;
1258
1259static void
1260eng_output_redraws_next_update_push(void *data, void *surface __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
1261{
1262 Render_Engine *re;
1263#ifdef FRAMECOUNT
1264 static double pt = 0.0;
1265 double ta, tb;
1266#endif
1267
1268 re = (Render_Engine *)data;
1269 /* put back update surface.. in this case just unflag redraw */
1270 if (!_re_wincheck(re)) return;
1271 re->win->draw.redraw = 0;
1272 re->win->draw.drew = 1;
1273 evas_gl_common_context_flush(re->win->gl_context);
1274 if (safe_native == -1)
1275 {
1276 const char *s = getenv("EVAS_GL_SAFE_NATIVE");
1277 safe_native = 0;
1278 if (s) safe_native = atoi(s);
1279 else
1280 {
1281 s = (const char *)glGetString(GL_RENDERER);
1282 if (s)
1283 {
1284 if (strstr(s, "PowerVR SGX 540") ||
1285 strstr(s, "Mali-400 MP"))
1286 safe_native = 1;
1287 }
1288 }
1289 }
1290#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1291 // this is needed to make sure all previous rendering is flushed to
1292 // buffers/surfaces
1293#ifdef FRAMECOUNT
1294 double t0 = get_time();
1295 ta = t0 - pt;
1296 pt = t0;
1297#endif
1298 // previous rendering should be done and swapped
1299 if (!safe_native) eglWaitNative(EGL_CORE_NATIVE_ENGINE);
1300#ifdef FRAMECOUNT
1301 double t1 = get_time();
1302 tb = t1 - t0;
1303 printf("... %1.5f -> %1.5f | ", ta, tb);
1304#endif
1305// if (eglGetError() != EGL_SUCCESS)
1306// {
1307// printf("Error: eglWaitNative(EGL_CORE_NATIVE_ENGINE) fail.\n");
1308// }
1309#else
1310 // previous rendering should be done and swapped
1311 if (!safe_native) glXWaitX();
1312#endif
1313//x// printf("frame -> push\n");
1314}
1315
1316static void
1317eng_output_flush(void *data)
1318{
1319 Render_Engine *re;
1320
1321 re = (Render_Engine *)data;
1322 if (!_re_wincheck(re)) return;
1323 if (!re->win->draw.drew) return;
1324//x// printf("frame -> flush\n");
1325 re->win->draw.drew = 0;
1326 eng_window_use(re->win);
1327
1328#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1329#ifdef FRAMECOUNT
1330 double t0 = get_time();
1331#endif
1332 if (!re->vsync)
1333 {
1334 if (re->info->vsync) eglSwapInterval(re->win->egl_disp, 1);
1335 else eglSwapInterval(re->win->egl_disp, 0);
1336 re->vsync = 1;
1337 }
1338 if (re->info->callback.pre_swap)
1339 {
1340 re->info->callback.pre_swap(re->info->callback.data, re->evas);
1341 }
1342 eglSwapBuffers(re->win->egl_disp, re->win->egl_surface[0]);
1343 if (!safe_native) eglWaitGL();
1344 if (re->info->callback.post_swap)
1345 {
1346 re->info->callback.post_swap(re->info->callback.data, re->evas);
1347 }
1348#ifdef FRAMECOUNT
1349 double t1 = get_time();
1350 printf("%1.5f\n", t1 - t0);
1351#endif
1352// if (eglGetError() != EGL_SUCCESS)
1353// {
1354// printf("Error: eglSwapBuffers() fail.\n");
1355// }
1356#else
1357#ifdef VSYNC_TO_SCREEN
1358 if ((re->info->vsync)/* || (1)*/)
1359 {
1360 if (glsym_glXSwapIntervalEXT)
1361 {
1362 if (!re->vsync)
1363 {
1364 if (re->info->vsync) glsym_glXSwapIntervalEXT(re->win->disp, re->win->win, 1);
1365 else glsym_glXSwapIntervalEXT(re->win->disp, re->win->win, 0);
1366 re->vsync = 1;
1367 }
1368 }
1369 if (glsym_glXSwapIntervalSGI)
1370 {
1371 if (!re->vsync)
1372 {
1373 if (re->info->vsync) glsym_glXSwapIntervalSGI(1);
1374 else glsym_glXSwapIntervalSGI(0);
1375 re->vsync = 1;
1376 }
1377 }
1378 else
1379 {
1380 if ((glsym_glXGetVideoSync) && (glsym_glXWaitVideoSync))
1381 {
1382 unsigned int rc;
1383
1384 glsym_glXGetVideoSync(&rc);
1385 glsym_glXWaitVideoSync(1, 0, &rc);
1386 }
1387 }
1388 }
1389# endif
1390 if (re->info->callback.pre_swap)
1391 {
1392 re->info->callback.pre_swap(re->info->callback.data, re->evas);
1393 }
1394/*
1395 if ((1)
1396// (re->win->draw.x1 == 0) &&
1397// (re->win->draw.y1 == 0) &&
1398// (re->win->draw.x2 == (re->win->w - 1)) &&
1399// (re->win->draw.y2 == (re->win->h - 1))
1400 )
1401 */
1402 {
1403 glXSwapBuffers(re->win->disp, re->win->win);
1404 if (!safe_native) glXWaitGL();
1405 }
1406/*
1407 else
1408 {
1409// FIXME: this doesn't work.. why oh why?
1410 int sx, sy, sw, sh;
1411
1412 // fimxe - reset when done
1413// glEnable(GL_SCISSOR_TEST);
1414 glDrawBuffer(GL_FRONT);
1415
1416 sx = re->win->draw.x1;
1417 sy = re->win->draw.y1;
1418 sw = (re->win->draw.x2 - re->win->draw.x1) + 1;
1419 sh = (re->win->draw.y2 - re->win->draw.y1) + 1;
1420 sy = re->win->h - sy - sh;
1421
1422// glScissor(sx, sy, sw, sh);
1423 glRasterPos2i(sx, re->win->h - sy);
1424 glCopyPixels(sx, sy, sw, sh, GL_COLOR);
1425 glRasterPos2i(0, 0);
1426
1427// glDisable(GL_SCISSOR_TEST);
1428 glDrawBuffer(GL_BACK);
1429 glFlush();
1430 }
1431 */
1432 if (re->info->callback.post_swap)
1433 {
1434 re->info->callback.post_swap(re->info->callback.data, re->evas);
1435 }
1436#endif
1437}
1438
1439static void
1440eng_output_idle_flush(void *data)
1441{
1442 Render_Engine *re;
1443
1444 re = (Render_Engine *)data;
1445}
1446
1447static void
1448eng_output_dump(void *data)
1449{
1450 Render_Engine *re;
1451
1452 re = (Render_Engine *)data;
1453 evas_common_image_image_all_unload();
1454 evas_common_font_font_all_unload();
1455 evas_gl_common_image_all_unload(re->win->gl_context);
1456 _re_winfree(re);
1457}
1458
1459static void
1460eng_context_cutout_add(void *data __UNUSED__, void *context, int x, int y, int w, int h)
1461{
1462// Render_Engine *re;
1463//
1464// re = (Render_Engine *)data;
1465// re->win->gl_context->dc = context;
1466 evas_common_draw_context_add_cutout(context, x, y, w, h);
1467}
1468
1469static void
1470eng_context_cutout_clear(void *data __UNUSED__, void *context)
1471{
1472// Render_Engine *re;
1473//
1474// re = (Render_Engine *)data;
1475// re->win->gl_context->dc = context;
1476 evas_common_draw_context_clear_cutouts(context);
1477}
1478
1479static void
1480eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
1481{
1482 Render_Engine *re;
1483
1484 re = (Render_Engine *)data;
1485 eng_window_use(re->win);
1486 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
1487 re->win->gl_context->dc = context;
1488 evas_gl_common_rect_draw(re->win->gl_context, x, y, w, h);
1489}
1490
1491static void
1492eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
1493{
1494 Render_Engine *re;
1495
1496 re = (Render_Engine *)data;
1497 eng_window_use(re->win);
1498 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
1499 re->win->gl_context->dc = context;
1500 evas_gl_common_line_draw(re->win->gl_context, x1, y1, x2, y2);
1501}
1502
1503static void *
1504eng_polygon_point_add(void *data, void *context __UNUSED__, void *polygon, int x, int y)
1505{
1506 Render_Engine *re;
1507
1508 re = (Render_Engine *)data;
1509 return evas_gl_common_poly_point_add(polygon, x, y);
1510}
1511
1512static void *
1513eng_polygon_points_clear(void *data, void *context __UNUSED__, void *polygon)
1514{
1515 Render_Engine *re;
1516
1517 re = (Render_Engine *)data;
1518 return evas_gl_common_poly_points_clear(polygon);
1519}
1520
1521static void
1522eng_polygon_draw(void *data, void *context, void *surface __UNUSED__, void *polygon, int x, int y)
1523{
1524 Render_Engine *re;
1525
1526 re = (Render_Engine *)data;
1527 eng_window_use(re->win);
1528 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
1529 re->win->gl_context->dc = context;
1530 evas_gl_common_poly_draw(re->win->gl_context, polygon, x, y);
1531}
1532
1533static int
1534eng_image_alpha_get(void *data __UNUSED__, void *image)
1535{
1536// Render_Engine *re;
1537 Evas_GL_Image *im;
1538
1539// re = (Render_Engine *)data;
1540 if (!image) return 1;
1541 im = image;
1542 return im->alpha;
1543}
1544
1545static int
1546eng_image_colorspace_get(void *data __UNUSED__, void *image)
1547{
1548// Render_Engine *re;
1549 Evas_GL_Image *im;
1550
1551// re = (Render_Engine *)data;
1552 if (!image) return EVAS_COLORSPACE_ARGB8888;
1553 im = image;
1554 return im->cs.space;
1555}
1556
1557static void
1558eng_image_mask_create(void *data __UNUSED__, void *image)
1559{
1560 Evas_GL_Image *im;
1561
1562 if (!image) return;
1563 im = image;
1564 if (!im->im->image.data)
1565 evas_cache_image_load_data(&im->im->cache_entry);
1566 if (!im->tex)
1567 im->tex = evas_gl_common_texture_new(im->gc, im->im);
1568}
1569
1570
1571static void *
1572eng_image_alpha_set(void *data, void *image, int has_alpha)
1573{
1574 Render_Engine *re;
1575 Evas_GL_Image *im;
1576
1577 re = (Render_Engine *)data;
1578 if (!image) return NULL;
1579 im = image;
1580 if (im->alpha == has_alpha) return image;
1581 if (im->native.data)
1582 {
1583 im->alpha = has_alpha;
1584 return image;
1585 }
1586 eng_window_use(re->win);
1587 if ((im->tex) && (im->tex->pt->dyn.img))
1588 {
1589 im->alpha = has_alpha;
1590 im->tex->alpha = im->alpha;
1591 return image;
1592 }
1593 /* FIXME: can move to gl_common */
1594 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
1595 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
1596 else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
1597 if (im->references > 1)
1598 {
1599 Evas_GL_Image *im_new;
1600
1601 im_new = evas_gl_common_image_new_from_copied_data
1602 (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
1603 im->im->image.data,
1604 eng_image_alpha_get(data, image),
1605 eng_image_colorspace_get(data, image));
1606 if (!im_new) return im;
1607 evas_gl_common_image_free(im);
1608 im = im_new;
1609 }
1610 else
1611 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1612 return evas_gl_common_image_alpha_set(im, has_alpha ? 1 : 0);
1613// im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
1614// return image;
1615}
1616
1617static void *
1618eng_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
1619{
1620// Render_Engine *re;
1621//
1622// re = (Render_Engine *)data;
1623 return image;
1624}
1625
1626static void
1627eng_image_border_get(void *data __UNUSED__, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
1628{
1629// Render_Engine *re;
1630//
1631// re = (Render_Engine *)data;
1632}
1633
1634static char *
1635eng_image_comment_get(void *data __UNUSED__, void *image, char *key __UNUSED__)
1636{
1637// Render_Engine *re;
1638 Evas_GL_Image *im;
1639
1640// re = (Render_Engine *)data;
1641 if (!image) return NULL;
1642 im = image;
1643 if (!im->im) return NULL;
1644 return im->im->info.comment;
1645}
1646
1647static char *
1648eng_image_format_get(void *data __UNUSED__, void *image)
1649{
1650// Render_Engine *re;
1651 Evas_GL_Image *im;
1652
1653// re = (Render_Engine *)data;
1654 im = image;
1655 return NULL;
1656}
1657
1658static void
1659eng_image_colorspace_set(void *data, void *image, int cspace)
1660{
1661 Render_Engine *re;
1662 Evas_GL_Image *im;
1663
1664 re = (Render_Engine *)data;
1665 if (!image) return;
1666 im = image;
1667 if (im->native.data) return;
1668 /* FIXME: can move to gl_common */
1669 if (im->cs.space == cspace) return;
1670 eng_window_use(re->win);
1671 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
1672 switch (cspace)
1673 {
1674 case EVAS_COLORSPACE_ARGB8888:
1675 if (im->cs.data)
1676 {
1677 if (!im->cs.no_free) free(im->cs.data);
1678 im->cs.data = NULL;
1679 im->cs.no_free = 0;
1680 }
1681 break;
1682 case EVAS_COLORSPACE_YCBCR422P601_PL:
1683 case EVAS_COLORSPACE_YCBCR422P709_PL:
1684 case EVAS_COLORSPACE_YCBCR422601_PL:
1685 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
1686 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
1687 if (im->tex) evas_gl_common_texture_free(im->tex);
1688 im->tex = NULL;
1689 if (im->cs.data)
1690 {
1691 if (!im->cs.no_free) free(im->cs.data);
1692 }
1693 if (im->im->cache_entry.h > 0)
1694 im->cs.data =
1695 calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
1696 else
1697 im->cs.data = NULL;
1698 im->cs.no_free = 0;
1699 break;
1700 default:
1701 abort();
1702 break;
1703 }
1704 im->cs.space = cspace;
1705}
1706
1707/////////////////////////////////////////////////////////////////////////
1708//
1709//
1710typedef struct _Native Native;
1711
1712struct _Native
1713{
1714 Evas_Native_Surface ns;
1715 Pixmap pixmap;
1716 Visual *visual;
1717
1718#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1719 void *egl_surface;
1720#else
1721 void *fbc;
1722 XID glx_pixmap;
1723#endif
1724};
1725
1726// FIXME: this is enabled so updates happen - but its SLOOOOOOOOOOOOOOOW
1727// (i am sure this is the reason) not to mention seemingly superfluous. but
1728// i need to enable it for it to work on fglrx at least. havent tried nvidia.
1729//
1730// why is this the case? does anyone know? has anyone tried it on other gfx
1731// drivers?
1732//
1733//#define GLX_TEX_PIXMAP_RECREATE 1
1734
1735static void
1736_native_bind_cb(void *data, void *image)
1737{
1738 Evas_GL_Image *im = image;
1739 Native *n = im->native.data;
1740
1741 if (n->ns.type == EVAS_NATIVE_SURFACE_X11)
1742 {
1743#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1744 if (n->egl_surface)
1745 {
1746 if (glsym_glEGLImageTargetTexture2DOES)
1747 {
1748 glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, n->egl_surface);
1749 if (eglGetError() != EGL_SUCCESS)
1750 ERR("glEGLImageTargetTexture2DOES() failed.");
1751 }
1752 else
1753 ERR("Try glEGLImageTargetTexture2DOES on EGL with no support");
1754 }
1755#else
1756# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1757 Render_Engine *re = data;
1758
1759 if (glsym_glXBindTexImage)
1760 {
1761 glsym_glXBindTexImage(re->win->disp, n->glx_pixmap,
1762 GLX_FRONT_LEFT_EXT, NULL);
1763 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1764 }
1765 else
1766 ERR("Try glXBindTexImage on GLX with no support");
1767# endif
1768#endif
1769 }
1770 else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
1771 {
1772 glBindTexture(GL_TEXTURE_2D, n->ns.data.opengl.texture_id);
1773 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1774 }
1775 return;
1776 data = NULL;
1777}
1778
1779static void
1780_native_unbind_cb(void *data, void *image)
1781{
1782 Evas_GL_Image *im = image;
1783 Native *n = im->native.data;
1784
1785 if (n->ns.type == EVAS_NATIVE_SURFACE_X11)
1786 {
1787#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1788 // nothing
1789#else
1790# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1791 Render_Engine *re = data;
1792
1793 if (glsym_glXReleaseTexImage)
1794 {
1795 glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap,
1796 GLX_FRONT_LEFT_EXT);
1797 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1798 }
1799 else
1800 ERR("Try glXReleaseTexImage on GLX with no support");
1801# endif
1802#endif
1803 }
1804 else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
1805 {
1806 glBindTexture(GL_TEXTURE_2D, 0);
1807 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1808 }
1809 return;
1810 data = NULL;
1811}
1812
1813static void
1814_native_free_cb(void *data, void *image)
1815{
1816 Render_Engine *re = data;
1817 Evas_GL_Image *im = image;
1818 Native *n = im->native.data;
1819 uint32_t pmid, texid;
1820
1821 if (n->ns.type == EVAS_NATIVE_SURFACE_X11)
1822 {
1823 pmid = n->pixmap;
1824 eina_hash_del(re->win->gl_context->shared->native_pm_hash, &pmid, im);
1825#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1826 if (n->egl_surface)
1827 {
1828 if (glsym_eglDestroyImage)
1829 {
1830 glsym_eglDestroyImage(re->win->egl_disp,
1831 n->egl_surface);
1832 if (eglGetError() != EGL_SUCCESS)
1833 ERR("eglDestroyImage() failed.");
1834 }
1835 else
1836 ERR("Try eglDestroyImage on EGL with no support");
1837 }
1838#else
1839# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1840 if (n->glx_pixmap)
1841 {
1842 if (im->native.loose)
1843 {
1844 if (glsym_glXReleaseTexImage)
1845 {
1846 glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap,
1847 GLX_FRONT_LEFT_EXT);
1848 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1849 }
1850 else
1851 ERR("Try glXReleaseTexImage on GLX with no support");
1852 }
1853 if (glsym_glXDestroyPixmap)
1854 {
1855 glsym_glXDestroyPixmap(re->win->disp, n->glx_pixmap);
1856 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1857 }
1858 else
1859 ERR("Try glXDestroyPixmap on GLX with no support");
1860 n->glx_pixmap = 0;
1861 }
1862# endif
1863#endif
1864 }
1865 else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
1866 {
1867 texid = n->ns.data.opengl.texture_id;
1868 eina_hash_del(re->win->gl_context->shared->native_tex_hash, &texid, im);
1869 }
1870 im->native.data = NULL;
1871 im->native.func.data = NULL;
1872 im->native.func.bind = NULL;
1873 im->native.func.unbind = NULL;
1874 im->native.func.free = NULL;
1875 free(n);
1876}
1877
1878static void *
1879eng_image_native_set(void *data, void *image, void *native)
1880{
1881 Render_Engine *re = (Render_Engine *)data;
1882 Evas_Native_Surface *ns = native;
1883 Evas_GL_Image *im = image, *im2 = NULL;
1884 Visual *vis = NULL;
1885 Pixmap pm = 0;
1886 Native *n = NULL;
1887 uint32_t pmid, texid;
1888 unsigned int tex = 0;
1889 unsigned int fbo = 0;
1890
1891 if (!im)
1892 {
1893 if ((!ns) && (ns->type == EVAS_NATIVE_SURFACE_OPENGL))
1894 {
1895 im = evas_gl_common_image_new_from_data(re->win->gl_context,
1896 ns->data.opengl.w,
1897 ns->data.opengl.h,
1898 NULL, 1,
1899 EVAS_COLORSPACE_ARGB8888);
1900 }
1901 else
1902 return NULL;
1903 }
1904
1905 if (ns)
1906 {
1907 if (ns->type == EVAS_NATIVE_SURFACE_X11)
1908 {
1909 vis = ns->data.x11.visual;
1910 pm = ns->data.x11.pixmap;
1911 if (im->native.data)
1912 {
1913 Evas_Native_Surface *ens = im->native.data;
1914 if ((ens->data.x11.visual == vis) &&
1915 (ens->data.x11.pixmap == pm))
1916 return im;
1917 }
1918 }
1919 else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
1920 {
1921 tex = ns->data.opengl.texture_id;
1922 fbo = ns->data.opengl.framebuffer_id;
1923 if (im->native.data)
1924 {
1925 Evas_Native_Surface *ens = im->native.data;
1926 if ((ens->data.opengl.texture_id == tex) &&
1927 (ens->data.opengl.framebuffer_id == fbo))
1928 return im;
1929 }
1930 }
1931 }
1932 if ((!ns) && (!im->native.data)) return im;
1933
1934 eng_window_use(re->win);
1935
1936 if (im->native.data)
1937 {
1938 if (im->native.func.free)
1939 im->native.func.free(im->native.func.data, im);
1940 evas_gl_common_image_native_disable(im);
1941 }
1942
1943 if (!ns) return im;
1944
1945 if (ns->type == EVAS_NATIVE_SURFACE_X11)
1946 {
1947 pmid = pm;
1948 im2 = eina_hash_find(re->win->gl_context->shared->native_pm_hash, &pmid);
1949 if (im2 == im) return im;
1950 if (im2)
1951 {
1952 n = im2->native.data;
1953 if (n)
1954 {
1955 evas_gl_common_image_ref(im2);
1956 evas_gl_common_image_free(im);
1957 return im2;
1958 }
1959 }
1960 }
1961 else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
1962 {
1963 texid = tex;
1964 im2 = eina_hash_find(re->win->gl_context->shared->native_tex_hash, &texid);
1965 if (im2 == im) return im;
1966 if (im2)
1967 {
1968 n = im2->native.data;
1969 if (n)
1970 {
1971 evas_gl_common_image_ref(im2);
1972 evas_gl_common_image_free(im);
1973 return im2;
1974 }
1975 }
1976
1977 }
1978 im2 = evas_gl_common_image_new_from_data(re->win->gl_context,
1979 im->w, im->h, NULL, im->alpha,
1980 EVAS_COLORSPACE_ARGB8888);
1981 evas_gl_common_image_free(im);
1982 im = im2;
1983 if (ns->type == EVAS_NATIVE_SURFACE_X11)
1984 {
1985#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1986 if (native)
1987 {
1988 n = calloc(1, sizeof(Native));
1989 if (n)
1990 {
1991 EGLConfig egl_config;
1992 int config_attrs[20];
1993 int num_config, i = 0;
1994
1995 eina_hash_add(re->win->gl_context->shared->native_pm_hash, &pmid, im);
1996
1997 config_attrs[i++] = EGL_RED_SIZE;
1998 config_attrs[i++] = 8;
1999 config_attrs[i++] = EGL_GREEN_SIZE;
2000 config_attrs[i++] = 8;
2001 config_attrs[i++] = EGL_BLUE_SIZE;
2002 config_attrs[i++] = 8;
2003 config_attrs[i++] = EGL_ALPHA_SIZE;
2004 config_attrs[i++] = 8;
2005 config_attrs[i++] = EGL_DEPTH_SIZE;
2006 config_attrs[i++] = 0;
2007 config_attrs[i++] = EGL_STENCIL_SIZE;
2008 config_attrs[i++] = 0;
2009 config_attrs[i++] = EGL_RENDERABLE_TYPE;
2010 config_attrs[i++] = EGL_OPENGL_ES2_BIT;
2011 config_attrs[i++] = EGL_SURFACE_TYPE;
2012 config_attrs[i++] = EGL_PIXMAP_BIT;
2013 config_attrs[i++] = EGL_NONE;
2014
2015 if (!eglChooseConfig(re->win->egl_disp, config_attrs,
2016 &egl_config, 1, &num_config))
2017 ERR("eglChooseConfig() failed for pixmap 0x%x, num_config = %i", (unsigned int)pm, num_config);
2018 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
2019 n->pixmap = pm;
2020 n->visual = vis;
2021 if (glsym_eglCreateImage)
2022 n->egl_surface = glsym_eglCreateImage(re->win->egl_disp,
2023 EGL_NO_CONTEXT,
2024 EGL_NATIVE_PIXMAP_KHR,
2025 (void *)pm,
2026 NULL);
2027 else
2028 ERR("Try eglCreateImage on EGL with no support");
2029 if (!n->egl_surface)
2030 ERR("eglCreatePixmapSurface() for 0x%x failed", (unsigned int)pm);
2031 im->native.yinvert = 1;
2032 im->native.loose = 0;
2033 im->native.data = n;
2034 im->native.func.data = re;
2035 im->native.func.bind = _native_bind_cb;
2036 im->native.func.unbind = _native_unbind_cb;
2037 im->native.func.free = _native_free_cb;
2038 im->native.target = GL_TEXTURE_2D;
2039 im->native.mipmap = 0;
2040 evas_gl_common_image_native_enable(im);
2041 }
2042 }
2043#else
2044# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
2045 if (native)
2046 {
2047 int dummy;
2048 unsigned int w, h, depth = 32, border;
2049 Window wdummy;
2050
2051 // fixme: round trip :(
2052 XGetGeometry(re->win->disp, pm, &wdummy, &dummy, &dummy,
2053 &w, &h, &border, &depth);
2054 n = calloc(1, sizeof(Native));
2055 if (n)
2056 {
2057 int pixmap_att[20];
2058 unsigned int target = 0;
2059 unsigned int i = 0;
2060
2061 eina_hash_add(re->win->gl_context->shared->native_pm_hash, &pmid, im);
2062 if ((re->win->depth_cfg[depth].tex_target &
2063 GLX_TEXTURE_2D_BIT_EXT)
2064 // && (1) // we assume npo2 for now
2065 // size is pow2 || mnpo2 supported
2066 )
2067 target = GLX_TEXTURE_2D_EXT;
2068 else if ((re->win->depth_cfg[depth].tex_target &
2069 GLX_TEXTURE_RECTANGLE_BIT_EXT))
2070 {
2071 ERR("rect!!! (not handled)");
2072 target = GLX_TEXTURE_RECTANGLE_EXT;
2073 }
2074 if (!target)
2075 {
2076 ERR("broken text-from-pixmap");
2077 if (!(re->win->depth_cfg[depth].tex_target &
2078 GLX_TEXTURE_2D_BIT_EXT))
2079 target = GLX_TEXTURE_RECTANGLE_EXT;
2080 else if (!(re->win->depth_cfg[depth].tex_target &
2081 GLX_TEXTURE_RECTANGLE_BIT_EXT))
2082 target = GLX_TEXTURE_2D_EXT;
2083 }
2084
2085
2086 pixmap_att[i++] = GLX_TEXTURE_FORMAT_EXT;
2087 pixmap_att[i++] = re->win->depth_cfg[depth].tex_format;
2088 pixmap_att[i++] = GLX_MIPMAP_TEXTURE_EXT;
2089 pixmap_att[i++] = re->win->depth_cfg[depth].mipmap;
2090
2091 if (target)
2092 {
2093 pixmap_att[i++] = GLX_TEXTURE_TARGET_EXT;
2094 pixmap_att[i++] = target;
2095 }
2096
2097 pixmap_att[i++] = 0;
2098
2099 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
2100 n->pixmap = pm;
2101 n->visual = vis;
2102 n->fbc = re->win->depth_cfg[depth].fbc;
2103 if (glsym_glXCreatePixmap)
2104 n->glx_pixmap = glsym_glXCreatePixmap(re->win->disp,
2105 n->fbc,
2106 n->pixmap,
2107 pixmap_att);
2108 else
2109 ERR("Try glXCreatePixmap on GLX with no support");
2110 if (n->glx_pixmap)
2111 {
2112// printf("%p: new native texture for %x | %4i x %4i @ %2i = %p\n",
2113// n, pm, w, h, depth, n->glx_pixmap);
2114 if (!target)
2115 {
2116 ERR("no target :(");
2117 if (glsym_glXQueryDrawable)
2118 glsym_glXQueryDrawable(re->win->disp,
2119 n->pixmap,
2120 GLX_TEXTURE_TARGET_EXT,
2121 &target);
2122 }
2123 if (target == GLX_TEXTURE_2D_EXT)
2124 {
2125 im->native.target = GL_TEXTURE_2D;
2126 im->native.mipmap = re->win->depth_cfg[depth].mipmap;
2127 }
2128# ifdef GL_TEXTURE_RECTANGLE_ARB
2129 else if (target == GLX_TEXTURE_RECTANGLE_EXT)
2130 {
2131 im->native.target = GL_TEXTURE_RECTANGLE_ARB;
2132 im->native.mipmap = 0;
2133 }
2134# endif
2135 else
2136 {
2137 im->native.target = GL_TEXTURE_2D;
2138 im->native.mipmap = 0;
2139 ERR("still unknown target");
2140 }
2141 }
2142 else
2143 ERR("GLX Pixmap create fail");
2144 im->native.yinvert = re->win->depth_cfg[depth].yinvert;
2145 im->native.loose = re->win->detected.loose_binding;
2146 im->native.data = n;
2147 im->native.func.data = re;
2148 im->native.func.bind = _native_bind_cb;
2149 im->native.func.unbind = _native_unbind_cb;
2150 im->native.func.free = _native_free_cb;
2151
2152 evas_gl_common_image_native_enable(im);
2153 }
2154 }
2155# endif
2156#endif
2157 }
2158 else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
2159 {
2160 if (native)
2161 {
2162 n = calloc(1, sizeof(Native));
2163 if (n)
2164 {
2165 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
2166
2167 eina_hash_add(re->win->gl_context->shared->native_tex_hash, &texid, im);
2168
2169 n->pixmap = 0;
2170 n->visual = 0;
2171#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2172 n->egl_surface = 0;
2173#else
2174 n->fbc = 0;
2175 n->glx_pixmap = 0;
2176#endif
2177
2178 im->native.yinvert = 0;
2179 im->native.loose = 0;
2180 im->native.data = n;
2181 im->native.func.data = re;
2182 im->native.func.bind = _native_bind_cb;
2183 im->native.func.unbind = _native_unbind_cb;
2184 im->native.func.free = _native_free_cb;
2185 im->native.target = GL_TEXTURE_2D;
2186 im->native.mipmap = 0;
2187
2188 // FIXME: need to implement mapping sub texture regions
2189 // x, y, w, h for possible texture atlasing
2190
2191 evas_gl_common_image_native_enable(im);
2192 }
2193 }
2194
2195 }
2196 return im;
2197}
2198
2199static void *
2200eng_image_native_get(void *data __UNUSED__, void *image)
2201{
2202 Evas_GL_Image *im = image;
2203 Native *n;
2204 if (!im) return NULL;
2205 n = im->native.data;
2206 if (!n) return NULL;
2207 return &(n->ns);
2208}
2209
2210#if 0 // filtering disabled
2211static void
2212eng_image_draw_filtered(void *data, void *context, void *surface,
2213 void *image, Evas_Filter_Info *filter)
2214{
2215 Render_Engine *re = data;
2216
2217 if (!image) return;
2218 eng_window_use(re->win);
2219 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
2220 re->win->gl_context->dc = context;
2221
2222 evas_gl_common_filter_draw(re->win->gl_context, image, filter);
2223}
2224
2225static Filtered_Image *
2226eng_image_filtered_get(void *im, uint8_t *key, size_t keylen)
2227{
2228 return evas_gl_common_image_filtered_get(im, key, keylen);
2229}
2230
2231static Filtered_Image *
2232eng_image_filtered_save(void *im, void *fim, uint8_t *key, size_t keylen)
2233{
2234 return evas_gl_common_image_filtered_save(im, fim, key, keylen);
2235}
2236
2237static void
2238eng_image_filtered_free(void *im, Filtered_Image *fim)
2239{
2240 evas_gl_common_image_filtered_free(im, fim);
2241}
2242#endif
2243
2244
2245//
2246//
2247/////////////////////////////////////////////////////////////////////////
2248
2249static void *
2250eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
2251{
2252 Render_Engine *re;
2253
2254 re = (Render_Engine *)data;
2255 *error = EVAS_LOAD_ERROR_NONE;
2256 eng_window_use(re->win);
2257 return evas_gl_common_image_load(re->win->gl_context, file, key, lo, error);
2258}
2259
2260static void *
2261eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
2262{
2263 Render_Engine *re;
2264
2265 re = (Render_Engine *)data;
2266 eng_window_use(re->win);
2267 return evas_gl_common_image_new_from_data(re->win->gl_context, w, h, image_data, alpha, cspace);
2268}
2269
2270static void *
2271eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
2272{
2273 Render_Engine *re;
2274
2275 re = (Render_Engine *)data;
2276 eng_window_use(re->win);
2277 return evas_gl_common_image_new_from_copied_data(re->win->gl_context, w, h, image_data, alpha, cspace);
2278}
2279
2280static void
2281eng_image_free(void *data, void *image)
2282{
2283 Render_Engine *re;
2284
2285 re = (Render_Engine *)data;
2286 if (!image) return;
2287 eng_window_use(re->win);
2288 evas_gl_common_image_free(image);
2289}
2290
2291static void
2292eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
2293{
2294 if (!image)
2295 {
2296 *w = 0;
2297 *h = 0;
2298 return;
2299 }
2300 if (w) *w = ((Evas_GL_Image *)image)->w;
2301 if (h) *h = ((Evas_GL_Image *)image)->h;
2302}
2303
2304static void *
2305eng_image_size_set(void *data, void *image, int w, int h)
2306{
2307 Render_Engine *re;
2308 Evas_GL_Image *im = image;
2309 Evas_GL_Image *im_old;
2310
2311 re = (Render_Engine *)data;
2312 if (!im) return NULL;
2313 if (im->native.data)
2314 {
2315 im->w = w;
2316 im->h = h;
2317 return image;
2318 }
2319 eng_window_use(re->win);
2320 if ((im->tex) && (im->tex->pt->dyn.img))
2321 {
2322 evas_gl_common_texture_free(im->tex);
2323 im->tex = NULL;
2324 im->w = w;
2325 im->h = h;
2326 im->tex = evas_gl_common_texture_dynamic_new(im->gc, im);
2327 return image;
2328 }
2329 im_old = image;
2330
2331 switch (eng_image_colorspace_get(data, image))
2332 {
2333 case EVAS_COLORSPACE_YCBCR422P601_PL:
2334 case EVAS_COLORSPACE_YCBCR422P709_PL:
2335 case EVAS_COLORSPACE_YCBCR422601_PL:
2336 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
2337 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
2338 w &= ~0x1;
2339 break;
2340 }
2341
2342 if ((im_old) &&
2343 ((int)im_old->im->cache_entry.w == w) &&
2344 ((int)im_old->im->cache_entry.h == h))
2345 return image;
2346 if (im_old)
2347 {
2348 im = evas_gl_common_image_new(re->win->gl_context, w, h,
2349 eng_image_alpha_get(data, image),
2350 eng_image_colorspace_get(data, image));
2351 /*
2352 evas_common_load_image_data_from_file(im_old->im);
2353 if (im_old->im->image->data)
2354 {
2355 evas_common_blit_rectangle(im_old->im, im->im, 0, 0, w, h, 0, 0);
2356 evas_common_cpu_end_opt();
2357 }
2358 */
2359 evas_gl_common_image_free(im_old);
2360 }
2361 else
2362 im = evas_gl_common_image_new(re->win->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
2363 return im;
2364}
2365
2366static void *
2367eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
2368{
2369 Render_Engine *re;
2370 Evas_GL_Image *im = image;
2371
2372 re = (Render_Engine *)data;
2373 if (!image) return NULL;
2374 if (im->native.data) return image;
2375 eng_window_use(re->win);
2376 evas_gl_common_image_dirty(image, x, y, w, h);
2377 return image;
2378}
2379
2380static void *
2381eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data, int *err)
2382{
2383 Render_Engine *re;
2384 Evas_GL_Image *im;
2385 int error;
2386
2387 re = (Render_Engine *)data;
2388 if (!image)
2389 {
2390 *image_data = NULL;
2391 if (err) *err = EVAS_LOAD_ERROR_GENERIC;
2392 return NULL;
2393 }
2394 im = image;
2395 if (im->native.data)
2396 {
2397 *image_data = NULL;
2398 if (err) *err = EVAS_LOAD_ERROR_NONE;
2399 return im;
2400 }
2401
2402#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2403 eng_window_use(re->win);
2404
2405 if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.img) && (im->cs.space == EVAS_COLORSPACE_ARGB8888))
2406 {
2407 if (im->tex->pt->dyn.checked_out > 0)
2408 {
2409 im->tex->pt->dyn.checked_out++;
2410 *image_data = im->tex->pt->dyn.data;
2411 if (err) *err = EVAS_LOAD_ERROR_NONE;
2412 return im;
2413 }
2414 *image_data = im->tex->pt->dyn.data = glsym_eglMapImageSEC(re->win->egl_disp, im->tex->pt->dyn.img);
2415
2416 if (!im->tex->pt->dyn.data)
2417 {
2418 if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
2419 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2420 return im;
2421 }
2422 im->tex->pt->dyn.checked_out++;
2423
2424 if (err) *err = EVAS_LOAD_ERROR_NONE;
2425 return im;
2426 }
2427#else
2428 if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.data))
2429 {
2430 *image_data = im->tex->pt->dyn.data;
2431 if (err) *err = EVAS_LOAD_ERROR_NONE;
2432 return im;
2433 }
2434
2435 eng_window_use(re->win);
2436#endif
2437
2438 /* Engine can be fail to create texture after cache drop like eng_image_content_hint_set function,
2439 so it is need to add code which check im->im's NULL value*/
2440
2441 if (!im->im)
2442 {
2443 *image_data = NULL;
2444 if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
2445 return NULL;
2446 }
2447
2448 error = evas_cache_image_load_data(&im->im->cache_entry);
2449 switch (im->cs.space)
2450 {
2451 case EVAS_COLORSPACE_ARGB8888:
2452 if (to_write)
2453 {
2454 if (im->references > 1)
2455 {
2456 Evas_GL_Image *im_new;
2457
2458 im_new = evas_gl_common_image_new_from_copied_data
2459 (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
2460 im->im->image.data,
2461 eng_image_alpha_get(data, image),
2462 eng_image_colorspace_get(data, image));
2463 if (!im_new)
2464 {
2465 *image_data = NULL;
2466 if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
2467 return NULL;
2468 }
2469 evas_gl_common_image_free(im);
2470 im = im_new;
2471 }
2472 else
2473 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
2474 }
2475 *image_data = im->im->image.data;
2476 break;
2477 case EVAS_COLORSPACE_YCBCR422P601_PL:
2478 case EVAS_COLORSPACE_YCBCR422P709_PL:
2479 case EVAS_COLORSPACE_YCBCR422601_PL:
2480 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
2481 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
2482 *image_data = im->cs.data;
2483 break;
2484 default:
2485 abort();
2486 break;
2487 }
2488 if (err) *err = error;
2489 return im;
2490}
2491
2492static void *
2493eng_image_data_put(void *data, void *image, DATA32 *image_data)
2494{
2495 Render_Engine *re;
2496 Evas_GL_Image *im, *im2;
2497
2498 re = (Render_Engine *)data;
2499 if (!image) return NULL;
2500 im = image;
2501 if (im->native.data) return image;
2502 eng_window_use(re->win);
2503 if ((im->tex) && (im->tex->pt)
2504 && (im->tex->pt->dyn.data)
2505 && (im->cs.space == EVAS_COLORSPACE_ARGB8888))
2506 {
2507 int w, h;
2508
2509 if (im->tex->pt->dyn.data == image_data)
2510 {
2511 im->tex->pt->dyn.checked_out--;
2512#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2513 if (im->tex->pt->dyn.checked_out == 0)
2514 glsym_eglUnmapImageSEC(re->win->egl_disp, im->tex->pt->dyn.img);
2515#endif
2516 return image;
2517 }
2518
2519 w = im->im->cache_entry.w;
2520 h = im->im->cache_entry.h;
2521 im2 = eng_image_new_from_data(data, w, h, image_data,
2522 eng_image_alpha_get(data, image),
2523 eng_image_colorspace_get(data, image));
2524 if (!im2) return im;
2525 evas_gl_common_image_free(im);
2526 im = im2;
2527 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
2528 return im;
2529 }
2530 switch (im->cs.space)
2531 {
2532 case EVAS_COLORSPACE_ARGB8888:
2533 if (image_data != im->im->image.data)
2534 {
2535 int w, h;
2536
2537 w = im->im->cache_entry.w;
2538 h = im->im->cache_entry.h;
2539 im2 = eng_image_new_from_data(data, w, h, image_data,
2540 eng_image_alpha_get(data, image),
2541 eng_image_colorspace_get(data, image));
2542 if (!im2) return im;
2543 evas_gl_common_image_free(im);
2544 im = im2;
2545 }
2546 break;
2547 case EVAS_COLORSPACE_YCBCR422P601_PL:
2548 case EVAS_COLORSPACE_YCBCR422P709_PL:
2549 case EVAS_COLORSPACE_YCBCR422601_PL:
2550 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
2551 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
2552 if (image_data != im->cs.data)
2553 {
2554 if (im->cs.data)
2555 {
2556 if (!im->cs.no_free) free(im->cs.data);
2557 }
2558 im->cs.data = image_data;
2559 }
2560 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
2561 break;
2562 default:
2563 abort();
2564 break;
2565 }
2566 return im;
2567}
2568
2569static void
2570eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
2571{
2572 Evas_GL_Image *gim = image;
2573 RGBA_Image *im;
2574
2575 if (!gim) return;
2576 if (gim->native.data) return;
2577 im = (RGBA_Image *)gim->im;
2578 if (!im) return;
2579 evas_cache_image_preload_data(&im->cache_entry, target);
2580}
2581
2582static void
2583eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
2584{
2585 Evas_GL_Image *gim = image;
2586 RGBA_Image *im;
2587
2588 if (!gim) return;
2589 if (gim->native.data) return;
2590 im = (RGBA_Image *)gim->im;
2591 if (!im) return;
2592 evas_cache_image_preload_cancel(&im->cache_entry, target);
2593}
2594
2595static void
2596eng_image_draw(void *data, 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)
2597{
2598 Render_Engine *re;
2599
2600 re = (Render_Engine *)data;
2601 if (!image) return;
2602 eng_window_use(re->win);
2603 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
2604 re->win->gl_context->dc = context;
2605 evas_gl_common_image_draw(re->win->gl_context, image,
2606 src_x, src_y, src_w, src_h,
2607 dst_x, dst_y, dst_w, dst_h,
2608 smooth);
2609}
2610
2611static void
2612eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
2613{
2614 if (image) evas_gl_common_image_scale_hint_set(image, hint);
2615}
2616
2617static int
2618eng_image_scale_hint_get(void *data __UNUSED__, void *image)
2619{
2620 Evas_GL_Image *gim = image;
2621 if (!gim) return EVAS_IMAGE_SCALE_HINT_NONE;
2622 return gim->scale_hint;
2623}
2624
2625static void
2626eng_image_map_draw(void *data, void *context, void *surface, void *image, int npoints, RGBA_Map_Point *p, int smooth, int level)
2627{
2628 Evas_GL_Image *gim = image;
2629 Render_Engine *re;
2630
2631 re = (Render_Engine *)data;
2632 if (!image) return;
2633 eng_window_use(re->win);
2634 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
2635 re->win->gl_context->dc = context;
2636 if (npoints != 4)
2637 {
2638 // FIXME: nash - you didn't fix this
2639 abort();
2640 }
2641 if ((p[0].x == p[3].x) &&
2642 (p[1].x == p[2].x) &&
2643 (p[0].y == p[1].y) &&
2644 (p[3].y == p[2].y) &&
2645 (p[0].x <= p[1].x) &&
2646 (p[0].y <= p[2].y) &&
2647 (p[0].u == 0) &&
2648 (p[0].v == 0) &&
2649 (p[1].u == (gim->w << FP)) &&
2650 (p[1].v == 0) &&
2651 (p[2].u == (gim->w << FP)) &&
2652 (p[2].v == (gim->h << FP)) &&
2653 (p[3].u == 0) &&
2654 (p[3].v == (gim->h << FP)) &&
2655 (p[0].col == 0xffffffff) &&
2656 (p[1].col == 0xffffffff) &&
2657 (p[2].col == 0xffffffff) &&
2658 (p[3].col == 0xffffffff))
2659 {
2660 int dx, dy, dw, dh;
2661
2662 dx = p[0].x >> FP;
2663 dy = p[0].y >> FP;
2664 dw = (p[2].x >> FP) - dx;
2665 dh = (p[2].y >> FP) - dy;
2666 eng_image_draw(data, context, surface, image,
2667 0, 0, gim->w, gim->h, dx, dy, dw, dh, smooth);
2668 }
2669 else
2670 {
2671 evas_gl_common_image_map_draw(re->win->gl_context, image, npoints, p,
2672 smooth, level);
2673 }
2674}
2675
2676static void *
2677eng_image_map_surface_new(void *data, int w, int h, int alpha)
2678{
2679 Render_Engine *re;
2680
2681 re = (Render_Engine *)data;
2682 return evas_gl_common_image_surface_new(re->win->gl_context, w, h, alpha);
2683}
2684
2685static void
2686eng_image_map_surface_free(void *data __UNUSED__, void *surface)
2687{
2688 evas_gl_common_image_free(surface);
2689}
2690
2691static void
2692eng_image_content_hint_set(void *data __UNUSED__, void *image, int hint)
2693{
2694 if (image) evas_gl_common_image_content_hint_set(image, hint);
2695}
2696
2697static int
2698eng_image_content_hint_get(void *data __UNUSED__, void *image)
2699{
2700 Evas_GL_Image *gim = image;
2701 if (!gim) return EVAS_IMAGE_CONTENT_HINT_NONE;
2702 return gim->content_hint;
2703}
2704
2705static void
2706eng_image_cache_flush(void *data)
2707{
2708 Render_Engine *re;
2709 int tmp_size;
2710
2711 re = (Render_Engine *)data;
2712
2713 tmp_size = evas_common_image_get_cache();
2714 evas_common_image_set_cache(0);
2715 evas_common_rgba_image_scalecache_flush();
2716 evas_gl_common_image_cache_flush(re->win->gl_context);
2717 evas_common_image_set_cache(tmp_size);
2718}
2719
2720static void
2721eng_image_cache_set(void *data, int bytes)
2722{
2723 Render_Engine *re;
2724
2725 re = (Render_Engine *)data;
2726 evas_common_image_set_cache(bytes);
2727 evas_common_rgba_image_scalecache_size_set(bytes);
2728 evas_gl_common_image_cache_flush(re->win->gl_context);
2729}
2730
2731static int
2732eng_image_cache_get(void *data __UNUSED__)
2733{
2734 return evas_common_image_get_cache();
2735}
2736
2737static void
2738eng_image_stride_get(void *data __UNUSED__, void *image, int *stride)
2739{
2740 Evas_GL_Image *im = image;
2741
2742 if ((im->tex) && (im->tex->pt->dyn.img))
2743 *stride = im->tex->pt->dyn.stride;
2744 else
2745 *stride = im->w * 4;
2746}
2747
2748static void
2749eng_font_draw(void *data, 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 *intl_props)
2750{
2751 Render_Engine *re;
2752
2753 re = (Render_Engine *)data;
2754 eng_window_use(re->win);
2755 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
2756 re->win->gl_context->dc = context;
2757 {
2758 // FIXME: put im into context so we can free it
2759 static RGBA_Image *im = NULL;
2760
2761 if (!im)
2762 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
2763 im->cache_entry.w = re->win->w;
2764 im->cache_entry.h = re->win->h;
2765 evas_common_draw_context_font_ext_set(context,
2766 re->win->gl_context,
2767 evas_gl_font_texture_new,
2768 evas_gl_font_texture_free,
2769 evas_gl_font_texture_draw);
2770 evas_common_font_draw(im, context, (RGBA_Font *) font, x, y,
2771 intl_props);
2772 evas_common_draw_context_font_ext_set(context,
2773 NULL,
2774 NULL,
2775 NULL,
2776 NULL);
2777 }
2778}
2779
2780static Eina_Bool
2781eng_canvas_alpha_get(void *data, void *info __UNUSED__)
2782{
2783 Render_Engine *re = (Render_Engine *)data;
2784 return re->win->alpha;
2785}
2786
2787static int
2788_set_internal_config(Render_Engine_GL_Surface *sfc, Evas_GL_Config *cfg)
2789{
2790 // Also initialize pixel format here as well...
2791 switch(cfg->color_format)
2792 {
2793 case EVAS_GL_RGB_888:
2794 sfc->rt_fmt = GL_RGB;
2795 sfc->rt_internal_fmt = GL_RGB;
2796 break;
2797 case EVAS_GL_RGBA_8888:
2798 sfc->rt_fmt = GL_RGBA;
2799 sfc->rt_internal_fmt = GL_RGBA;
2800 break;
2801 default:
2802 ERR("Invalid Color Format!");
2803 return 0;
2804 }
2805
2806 switch(cfg->depth_bits)
2807 {
2808 case EVAS_GL_DEPTH_NONE:
2809 break;
2810 case EVAS_GL_DEPTH_BIT_8:
2811 case EVAS_GL_DEPTH_BIT_16:
2812 case EVAS_GL_DEPTH_BIT_24:
2813#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2814 // 24 bit doesn't work... just cover it with 16 for now..
2815 sfc->rb_depth_fmt = GL_DEPTH_COMPONENT16;
2816#else
2817 sfc->rb_depth_fmt = GL_DEPTH_COMPONENT;
2818#endif
2819 break;
2820 case EVAS_GL_DEPTH_BIT_32:
2821 default:
2822 ERR("Unsupported Depth Bits Format!");
2823 return 0;
2824 }
2825
2826 switch(cfg->stencil_bits)
2827 {
2828 case EVAS_GL_STENCIL_NONE:
2829 break;
2830 case EVAS_GL_STENCIL_BIT_1:
2831 case EVAS_GL_STENCIL_BIT_2:
2832 case EVAS_GL_STENCIL_BIT_4:
2833 case EVAS_GL_STENCIL_BIT_8:
2834#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2835 sfc->rb_stencil_fmt = GL_STENCIL_INDEX8;
2836#else
2837 sfc->rb_stencil_fmt = GL_STENCIL_INDEX;
2838#endif
2839 break;
2840 case EVAS_GL_STENCIL_BIT_16:
2841 default:
2842 ERR("Unsupported Stencil Bits Format!");
2843 return 0;
2844 }
2845
2846 // Do Packed Depth24_Stencil8 Later...
2847
2848 return 1;
2849}
2850
2851static int
2852_create_rt_buffers(Render_Engine *data __UNUSED__,
2853 Render_Engine_GL_Surface *sfc)
2854{
2855 // Render Target texture
2856 glGenTextures(1, &sfc->rt_tex );
2857
2858 // Depth RenderBuffer - Create storage here...
2859 if (sfc->depth_bits != EVAS_GL_DEPTH_NONE)
2860 glGenRenderbuffers(1, &sfc->rb_depth);
2861
2862 // Stencil RenderBuffer - Create Storage here...
2863 if (sfc->stencil_bits != EVAS_GL_STENCIL_NONE)
2864 glGenRenderbuffers(1, &sfc->rb_stencil);
2865
2866 return 1;
2867}
2868
2869static int
2870_attach_fbo_surface(Render_Engine *data __UNUSED__,
2871 Render_Engine_GL_Surface *sfc,
2872 Render_Engine_GL_Context *ctx)
2873{
2874 int fb_status;
2875
2876 // Initialize Texture
2877 glBindTexture(GL_TEXTURE_2D, sfc->rt_tex );
2878 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2879 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2880 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2881 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2882 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sfc->w, sfc->h, 0,
2883 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
2884 glBindTexture(GL_TEXTURE_2D, 0);
2885
2886
2887 // Attach texture to FBO
2888 glBindFramebuffer(GL_FRAMEBUFFER, ctx->context_fbo);
2889 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2890 GL_TEXTURE_2D, sfc->rt_tex, 0);
2891
2892 // Depth RenderBuffer - Attach it to FBO
2893 if (sfc->depth_bits != EVAS_GL_DEPTH_NONE)
2894 {
2895 glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth);
2896 glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_depth_fmt,
2897 sfc->w, sfc->h);
2898 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
2899 GL_RENDERBUFFER, sfc->rb_depth);
2900 glBindRenderbuffer(GL_RENDERBUFFER, 0);
2901 }
2902
2903 // Stencil RenderBuffer - Attach it to FBO
2904 if (sfc->stencil_bits != EVAS_GL_STENCIL_NONE)
2905 {
2906 glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_stencil);
2907 glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_stencil_fmt,
2908 sfc->w, sfc->h);
2909 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
2910 GL_RENDERBUFFER, sfc->rb_stencil);
2911 glBindRenderbuffer(GL_RENDERBUFFER, 0);
2912 }
2913
2914 // Check FBO for completeness
2915 fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
2916 if (fb_status != GL_FRAMEBUFFER_COMPLETE)
2917 {
2918 ERR("FBO not complete!");
2919 return 0;
2920 }
2921
2922 return 1;
2923}
2924
2925
2926static void *
2927eng_gl_surface_create(void *data, void *config, int w, int h)
2928{
2929 Render_Engine *re;
2930 Render_Engine_GL_Surface *sfc;
2931 Render_Engine_GL_Resource *rsc;
2932 Evas_GL_Config *cfg;
2933 int ret;
2934
2935 sfc = calloc(1, sizeof(Render_Engine_GL_Surface));
2936 if (!sfc) return NULL;
2937
2938 re = (Render_Engine *)data;
2939 cfg = (Evas_GL_Config *)config;
2940
2941 sfc->initialized = 0;
2942 sfc->fbo_attached = 0;
2943 sfc->w = w;
2944 sfc->h = h;
2945 sfc->depth_bits = cfg->depth_bits;
2946 sfc->stencil_bits = cfg->stencil_bits;
2947 sfc->rt_tex = 0;
2948 sfc->rb_depth = 0;
2949 sfc->rb_stencil = 0;
2950
2951 // Set the internal format based on the config
2952 if (!_set_internal_config(sfc, cfg))
2953 {
2954 ERR("Unsupported Format!");
2955 free(sfc);
2956 return NULL;
2957 }
2958
2959 // Create internal resource context if it hasn't been created already
2960 if ((rsc = eina_tls_get(resource_key)) == NULL)
2961 {
2962 if ((rsc = _create_internal_glue_resources(re)) == NULL)
2963 {
2964 ERR("Error creating internal resources.");
2965 free(sfc);
2966 return NULL;
2967 }
2968 }
2969
2970 // I'm using evas's original context to create the render target texture
2971 // This is to prevent awkwardness in using native_surface_get() function
2972 // If the rt texture creation is deferred till the context is created and
2973 // make_current called, the user can't call native_surface_get() right
2974 // after the surface is created. hence this is done here using evas' context.
2975#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2976 ret = eglMakeCurrent(re->win->egl_disp, rsc->surface, rsc->surface, rsc->context);
2977#else
2978 ret = glXMakeCurrent(re->info->info.display, re->win->win, rsc->context);
2979#endif
2980 if (!ret)
2981 {
2982 ERR("xxxMakeCurrent() failed!");
2983 free(sfc);
2984 return NULL;
2985 }
2986
2987 // Create Render texture
2988 if (!_create_rt_buffers(re, sfc))
2989 {
2990 ERR("_create_rt_buffers() failed.");
2991 free(sfc);
2992 return NULL;
2993 }
2994
2995#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2996 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
2997#else
2998 ret = glXMakeCurrent(re->info->info.display, None, NULL);
2999#endif
3000 if (!ret)
3001 {
3002 ERR("xxxMakeCurrent() failed!");
3003 free(sfc);
3004 return NULL;
3005 }
3006
3007 return sfc;
3008}
3009
3010static int
3011eng_gl_surface_destroy(void *data, void *surface)
3012{
3013 Render_Engine *re;
3014 Render_Engine_GL_Surface *sfc;
3015 Render_Engine_GL_Resource *rsc;
3016 int ret;
3017
3018 re = (Render_Engine *)data;
3019 sfc = (Render_Engine_GL_Surface*)surface;
3020
3021 if (!sfc) return 0;
3022
3023 if ((rsc = eina_tls_get(resource_key)) == EINA_FALSE) return 0;
3024
3025#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3026 ret = eglMakeCurrent(re->win->egl_disp, rsc->surface, rsc->surface, rsc->context);
3027#else
3028 ret = glXMakeCurrent(re->info->info.display, re->win->win, rsc->context);
3029#endif
3030 if (!ret)
3031 {
3032 ERR("xxxMakeCurrent() failed!");
3033 return 0;
3034 }
3035
3036 // Delete FBO/RBO and Texture here
3037 if (sfc->rt_tex)
3038 glDeleteTextures(1, &sfc->rt_tex);
3039
3040 if (sfc->rb_depth)
3041 glDeleteRenderbuffers(1, &sfc->rb_depth);
3042
3043 if (sfc->rb_stencil)
3044 glDeleteRenderbuffers(1, &sfc->rb_stencil);
3045
3046#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3047 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
3048#else
3049 ret = glXMakeCurrent(re->info->info.display, None, NULL);
3050#endif
3051 if (!ret)
3052 {
3053 ERR("xxxMakeCurrent() failed!");
3054 free(sfc);
3055 return 0;
3056 }
3057
3058 free(sfc);
3059 surface = NULL;
3060
3061 return 1;
3062}
3063
3064static void *
3065eng_gl_context_create(void *data, void *share_context)
3066{
3067 Render_Engine *re;
3068 Render_Engine_GL_Context *ctx;
3069 Render_Engine_GL_Context *share_ctx;
3070#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3071 int context_attrs[3];
3072#endif
3073
3074 ctx = calloc(1, sizeof(Render_Engine_GL_Context));
3075
3076 if (!ctx) return NULL;
3077
3078 re = (Render_Engine *)data;
3079 share_ctx = (Render_Engine_GL_Context *)share_context;
3080
3081 // Set the share context to Evas' GL context if share_context is NULL.
3082 // Otherwise set it to the given share_context.
3083#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3084 // EGL
3085 context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
3086 context_attrs[1] = 2;
3087 context_attrs[2] = EGL_NONE;
3088
3089 if (share_ctx)
3090 {
3091 ctx->context = eglCreateContext(re->win->egl_disp,
3092 re->win->egl_config,
3093 share_ctx->context, // Share Context
3094 context_attrs);
3095 }
3096 else
3097 {
3098 ctx->context = eglCreateContext(re->win->egl_disp,
3099 re->win->egl_config,
3100 re->win->egl_context[0], // Evas' GL Context
3101 context_attrs);
3102 }
3103
3104 if (!ctx->context)
3105 {
3106 ERR("eglCreateContext() fail. code=%#x", eglGetError());
3107 return NULL;
3108 }
3109#else
3110 // GLX
3111 if (share_context)
3112 {
3113 ctx->context = glXCreateContext(re->info->info.display,
3114 re->win->visualinfo,
3115 share_ctx->context, // Share Context
3116 1);
3117 }
3118 else
3119 {
3120 ctx->context = glXCreateContext(re->info->info.display,
3121 re->win->visualinfo,
3122 re->win->context, // Evas' GL Context
3123 1);
3124 }
3125
3126 if (!ctx->context)
3127 {
3128 ERR("glXCreateContext() fail.");
3129 return NULL;
3130 }
3131#endif
3132
3133 ctx->initialized = 0;
3134 ctx->context_fbo = 0;
3135 ctx->current_sfc = NULL;
3136
3137 return ctx;
3138}
3139
3140static int
3141eng_gl_context_destroy(void *data, void *context)
3142{
3143 Render_Engine *re;
3144 Render_Engine_GL_Context *ctx;
3145 Render_Engine_GL_Resource *rsc;
3146 int ret;
3147
3148 re = (Render_Engine *)data;
3149 ctx = (Render_Engine_GL_Context*)context;
3150
3151 if (!ctx) return 0;
3152
3153 if ((rsc = eina_tls_get(resource_key)) == EINA_FALSE) return 0;
3154
3155 // 1. Do a make current with the given context
3156#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3157 ret = eglMakeCurrent(re->win->egl_disp, rsc->surface,
3158 rsc->surface, ctx->context);
3159#else
3160 ret = glXMakeCurrent(re->info->info.display, re->win->win,
3161 ctx->context);
3162#endif
3163 if (!ret)
3164 {
3165 ERR("xxxMakeCurrent() failed!");
3166 return 0;
3167 }
3168
3169 // 2. Delete the FBO
3170 if (ctx->context_fbo)
3171 glDeleteFramebuffers(1, &ctx->context_fbo);
3172
3173 // 3. Destroy the Context
3174#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3175 eglDestroyContext(re->win->egl_disp, ctx->context);
3176
3177 ctx->context = EGL_NO_CONTEXT;
3178
3179 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE,
3180 EGL_NO_SURFACE, EGL_NO_CONTEXT);
3181#else
3182 glXDestroyContext(re->info->info.display, ctx->context);
3183
3184 ctx->context = 0;
3185
3186 ret = glXMakeCurrent(re->info->info.display, None, NULL);
3187#endif
3188 if (!ret)
3189 {
3190 ERR("xxxMakeCurrent() failed!");
3191 return 0;
3192 }
3193
3194 free(ctx);
3195 context = NULL;
3196
3197 return 1;
3198}
3199
3200static int
3201eng_gl_make_current(void *data __UNUSED__, void *surface, void *context)
3202{
3203 Render_Engine *re;
3204 Render_Engine_GL_Surface *sfc;
3205 Render_Engine_GL_Context *ctx;
3206 int ret = 0;
3207#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3208 Render_Engine_GL_Resource *rsc;
3209#endif
3210
3211 re = (Render_Engine *)data;
3212 sfc = (Render_Engine_GL_Surface*)surface;
3213 ctx = (Render_Engine_GL_Context*)context;
3214
3215 // Unset surface/context
3216 if ((!sfc) || (!ctx))
3217 {
3218#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3219 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE,
3220 EGL_NO_SURFACE, EGL_NO_CONTEXT);
3221#else
3222 ret = glXMakeCurrent(re->info->info.display, None, NULL);
3223#endif
3224 if (!ret)
3225 {
3226 ERR("xxxMakeCurrent() failed!");
3227 return 0;
3228 }
3229
3230 if (ctx) ctx->current_sfc = NULL;
3231 if (sfc) sfc->current_ctx = NULL;
3232 current_evgl_ctx = NULL;
3233 return 1;
3234 }
3235
3236 // Do a make current only if it's not already current
3237#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3238 if ((rsc = eina_tls_get(resource_key)) == EINA_FALSE) return 0;
3239
3240 if ((eglGetCurrentContext() != ctx->context) ||
3241 (eglGetCurrentSurface(EGL_READ) != rsc->surface) ||
3242 (eglGetCurrentSurface(EGL_DRAW) != rsc->surface) )
3243 {
3244 // Flush remainder of what's in Evas' pipeline
3245 if (re->win) eng_window_use(NULL);
3246
3247 // Do a make current
3248 ret = eglMakeCurrent(re->win->egl_disp, rsc->surface,
3249 rsc->surface, ctx->context);
3250 if (!ret)
3251 {
3252 ERR("xxxMakeCurrent() failed!");
3253 return 0;
3254 }
3255 }
3256#else
3257 if ((glXGetCurrentContext() != ctx->context) ||
3258 (glXGetCurrentDrawable() != re->win->win) )
3259 {
3260 // Flush remainder of what's in Evas' pipeline
3261 if (re->win) eng_window_use(NULL);
3262
3263 // Do a make current
3264 ret = glXMakeCurrent(re->info->info.display, re->win->win, ctx->context);
3265 if (!ret)
3266 {
3267 ERR("xxxMakeCurrent() failed!");
3268 return 0;
3269 }
3270 }
3271#endif
3272
3273 // Create FBO if not already created
3274 if (!ctx->initialized)
3275 {
3276 glGenFramebuffers(1, &ctx->context_fbo);
3277 ctx->initialized = 1;
3278 }
3279
3280 // Attach FBO if it hasn't been attached or if surface changed
3281 if ((!sfc->fbo_attached) || (ctx->current_sfc != sfc))
3282 {
3283 if (!_attach_fbo_surface(re, sfc, ctx))
3284 {
3285 ERR("_attach_fbo_surface() failed.");
3286 return 0;
3287 }
3288
3289 if (ctx->current_fbo)
3290 // Bind to the previously bound buffer
3291 glBindFramebuffer(GL_FRAMEBUFFER, ctx->current_fbo);
3292 else
3293 // Bind FBO
3294 glBindFramebuffer(GL_FRAMEBUFFER, ctx->context_fbo);
3295
3296 sfc->fbo_attached = 1;
3297 }
3298
3299 // Set the current surface/context
3300 ctx->current_sfc = sfc;
3301 sfc->current_ctx = ctx;
3302 current_evgl_ctx = ctx;
3303
3304 return 1;
3305}
3306
3307static void *
3308eng_gl_string_query(void *data __UNUSED__, int name)
3309{
3310 switch(name)
3311 {
3312 case EVAS_GL_EXTENSIONS:
3313 return (void*)_evasgl_ext_string;
3314 default:
3315 return NULL;
3316 };
3317}
3318
3319static void *
3320eng_gl_proc_address_get(void *data __UNUSED__, const char *name)
3321{
3322#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3323 if (glsym_eglGetProcAddress) return glsym_eglGetProcAddress(name);
3324 return dlsym(RTLD_DEFAULT, name);
3325#else
3326 if (glsym_glXGetProcAddress) return glsym_glXGetProcAddress(name);
3327 return dlsym(RTLD_DEFAULT, name);
3328#endif
3329}
3330
3331static int
3332eng_gl_native_surface_get(void *data, void *surface, void *native_surface)
3333{
3334 Render_Engine *re;
3335 Render_Engine_GL_Surface *sfc;
3336 Evas_Native_Surface *ns;
3337
3338 re = (Render_Engine *)data;
3339 sfc = (Render_Engine_GL_Surface*)surface;
3340 ns = (Evas_Native_Surface*)native_surface;
3341
3342 ns->type = EVAS_NATIVE_SURFACE_OPENGL;
3343 ns->version = EVAS_NATIVE_SURFACE_VERSION;
3344 ns->data.opengl.texture_id = sfc->rt_tex;
3345 ns->data.opengl.x = 0;
3346 ns->data.opengl.y = 0;
3347 ns->data.opengl.w = sfc->w;
3348 ns->data.opengl.h = sfc->h;
3349
3350 return 1;
3351}
3352
3353
3354static const GLubyte *
3355evgl_glGetString(GLenum name)
3356{
3357 if (name == GL_EXTENSIONS)
3358 return (GLubyte *)_gl_ext_string; //glGetString(GL_EXTENSIONS);
3359 else
3360 return glGetString(name);
3361}
3362
3363static void
3364evgl_glBindFramebuffer(GLenum target, GLuint framebuffer)
3365{
3366 Render_Engine_GL_Context *ctx = current_evgl_ctx;
3367
3368 // Take care of BindFramebuffer 0 issue
3369 if (framebuffer==0)
3370 {
3371 if (ctx)
3372 {
3373 glBindFramebuffer(target, ctx->context_fbo);
3374 ctx->current_fbo = 0;
3375 }
3376 }
3377 else
3378 {
3379 glBindFramebuffer(target, framebuffer);
3380
3381 // Save this for restore when doing make current
3382 if (ctx)
3383 ctx->current_fbo = framebuffer;
3384 }
3385}
3386
3387static void
3388evgl_glBindRenderbuffer(GLenum target, GLuint renderbuffer)
3389{
3390 // Add logic to take care when renderbuffer=0
3391 // On a second thought we don't need this
3392 glBindRenderbuffer(target, renderbuffer);
3393}
3394
3395static void
3396evgl_glClearDepthf(GLclampf depth)
3397{
3398#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3399 glClearDepthf(depth);
3400#else
3401 glClearDepth(depth);
3402#endif
3403}
3404
3405static void
3406evgl_glDepthRangef(GLclampf zNear, GLclampf zFar)
3407{
3408#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3409 glDepthRangef(zNear, zFar);
3410#else
3411 glDepthRange(zNear, zFar);
3412#endif
3413}
3414
3415static void
3416evgl_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
3417{
3418#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3419 glGetShaderPrecisionFormat(shadertype, precisiontype, range, precision);
3420#else
3421 if (range)
3422 {
3423 range[0] = -126; // floor(log2(FLT_MIN))
3424 range[1] = 127; // floor(log2(FLT_MAX))
3425 }
3426 if (precision)
3427 {
3428 precision[0] = 24; // floor(-log2((1.0/16777218.0)));
3429 }
3430 return;
3431 shadertype = precisiontype = 0;
3432#endif
3433}
3434
3435static void
3436evgl_glReleaseShaderCompiler(void)
3437{
3438#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3439 glReleaseShaderCompiler();
3440#else
3441#endif
3442}
3443
3444static void
3445evgl_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
3446{
3447#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3448 glShaderBinary(n, shaders, binaryformat, binary, length);
3449#else
3450// FIXME: need to dlsym/getprocaddress for this
3451 return;
3452 n = binaryformat = length = 0;
3453 shaders = binary = 0;
3454#endif
3455}
3456
3457//--------------------------------//
3458#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3459// EGL Extensions
3460static void *
3461evgl_evasglCreateImage(int target, void* buffer, int *attrib_list)
3462{
3463 if (current_engine)
3464 {
3465 return glsym_eglCreateImage(current_engine->win->egl_disp,
3466 EGL_NO_CONTEXT,
3467 target,
3468 buffer,
3469 attrib_list);
3470 }
3471 else
3472 ERR("Invalid Engine... (Can't acccess EGL Display)\n");
3473}
3474
3475static void
3476evgl_evasglDestroyImage(EvasGLImage image)
3477{
3478 if (current_engine)
3479 glsym_eglDestroyImage(current_engine->win->egl_disp, image);
3480 else
3481 ERR("Invalid Engine... (Can't acccess EGL Display)\n");
3482}
3483
3484static void
3485evgl_glEvasGLImageTargetTexture2DOES(GLenum target, EvasGLImage image)
3486{
3487 glsym_glEGLImageTargetTexture2DOES(target, image);
3488}
3489
3490static void
3491evgl_glEvasGLImageTargetRenderbufferStorageOES(GLenum target, EvasGLImage image)
3492{
3493 glsym_glEGLImageTargetTexture2DOES(target, image);
3494}
3495#else
3496#endif
3497
3498//--------------------------------//
3499
3500
3501static void *
3502eng_gl_api_get(void *data)
3503{
3504 Render_Engine *re;
3505
3506 re = (Render_Engine *)data;
3507
3508 gl_funcs.version = EVAS_GL_API_VERSION;
3509
3510#define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, )
3511 // GLES 2.0
3512 ORD(glActiveTexture);
3513 ORD(glAttachShader);
3514 ORD(glBindAttribLocation);
3515 ORD(glBindBuffer);
3516 ORD(glBindTexture);
3517 ORD(glBlendColor);
3518 ORD(glBlendEquation);
3519 ORD(glBlendEquationSeparate);
3520 ORD(glBlendFunc);
3521 ORD(glBlendFuncSeparate);
3522 ORD(glBufferData);
3523 ORD(glBufferSubData);
3524 ORD(glCheckFramebufferStatus);
3525 ORD(glClear);
3526 ORD(glClearColor);
3527// ORD(glClearDepthf);
3528 ORD(glClearStencil);
3529 ORD(glColorMask);
3530 ORD(glCompileShader);
3531 ORD(glCompressedTexImage2D);
3532 ORD(glCompressedTexSubImage2D);
3533 ORD(glCopyTexImage2D);
3534 ORD(glCopyTexSubImage2D);
3535 ORD(glCreateProgram);
3536 ORD(glCreateShader);
3537 ORD(glCullFace);
3538 ORD(glDeleteBuffers);
3539 ORD(glDeleteFramebuffers);
3540 ORD(glDeleteProgram);
3541 ORD(glDeleteRenderbuffers);
3542 ORD(glDeleteShader);
3543 ORD(glDeleteTextures);
3544 ORD(glDepthFunc);
3545 ORD(glDepthMask);
3546// ORD(glDepthRangef);
3547 ORD(glDetachShader);
3548 ORD(glDisable);
3549 ORD(glDisableVertexAttribArray);
3550 ORD(glDrawArrays);
3551 ORD(glDrawElements);
3552 ORD(glEnable);
3553 ORD(glEnableVertexAttribArray);
3554 ORD(glFinish);
3555 ORD(glFlush);
3556 ORD(glFramebufferRenderbuffer);
3557 ORD(glFramebufferTexture2D);
3558 ORD(glFrontFace);
3559 ORD(glGenBuffers);
3560 ORD(glGenerateMipmap);
3561 ORD(glGenFramebuffers);
3562 ORD(glGenRenderbuffers);
3563 ORD(glGenTextures);
3564 ORD(glGetActiveAttrib);
3565 ORD(glGetActiveUniform);
3566 ORD(glGetAttachedShaders);
3567 ORD(glGetAttribLocation);
3568 ORD(glGetBooleanv);
3569 ORD(glGetBufferParameteriv);
3570 ORD(glGetError);
3571 ORD(glGetFloatv);
3572 ORD(glGetFramebufferAttachmentParameteriv);
3573 ORD(glGetIntegerv);
3574 ORD(glGetProgramiv);
3575 ORD(glGetProgramInfoLog);
3576 ORD(glGetRenderbufferParameteriv);
3577 ORD(glGetShaderiv);
3578 ORD(glGetShaderInfoLog);
3579// ORD(glGetShaderPrecisionFormat);
3580 ORD(glGetShaderSource);
3581// ORD(glGetString);
3582 ORD(glGetTexParameterfv);
3583 ORD(glGetTexParameteriv);
3584 ORD(glGetUniformfv);
3585 ORD(glGetUniformiv);
3586 ORD(glGetUniformLocation);
3587 ORD(glGetVertexAttribfv);
3588 ORD(glGetVertexAttribiv);
3589 ORD(glGetVertexAttribPointerv);
3590 ORD(glHint);
3591 ORD(glIsBuffer);
3592 ORD(glIsEnabled);
3593 ORD(glIsFramebuffer);
3594 ORD(glIsProgram);
3595 ORD(glIsRenderbuffer);
3596 ORD(glIsShader);
3597 ORD(glIsTexture);
3598 ORD(glLineWidth);
3599 ORD(glLinkProgram);
3600 ORD(glPixelStorei);
3601 ORD(glPolygonOffset);
3602 ORD(glReadPixels);
3603// ORD(glReleaseShaderCompiler);
3604 ORD(glRenderbufferStorage);
3605 ORD(glSampleCoverage);
3606 ORD(glScissor);
3607// ORD(glShaderBinary);
3608 ORD(glShaderSource);
3609 ORD(glStencilFunc);
3610 ORD(glStencilFuncSeparate);
3611 ORD(glStencilMask);
3612 ORD(glStencilMaskSeparate);
3613 ORD(glStencilOp);
3614 ORD(glStencilOpSeparate);
3615 ORD(glTexImage2D);
3616 ORD(glTexParameterf);
3617 ORD(glTexParameterfv);
3618 ORD(glTexParameteri);
3619 ORD(glTexParameteriv);
3620 ORD(glTexSubImage2D);
3621 ORD(glUniform1f);
3622 ORD(glUniform1fv);
3623 ORD(glUniform1i);
3624 ORD(glUniform1iv);
3625 ORD(glUniform2f);
3626 ORD(glUniform2fv);
3627 ORD(glUniform2i);
3628 ORD(glUniform2iv);
3629 ORD(glUniform3f);
3630 ORD(glUniform3fv);
3631 ORD(glUniform3i);
3632 ORD(glUniform3iv);
3633 ORD(glUniform4f);
3634 ORD(glUniform4fv);
3635 ORD(glUniform4i);
3636 ORD(glUniform4iv);
3637 ORD(glUniformMatrix2fv);
3638 ORD(glUniformMatrix3fv);
3639 ORD(glUniformMatrix4fv);
3640 ORD(glUseProgram);
3641 ORD(glValidateProgram);
3642 ORD(glVertexAttrib1f);
3643 ORD(glVertexAttrib1fv);
3644 ORD(glVertexAttrib2f);
3645 ORD(glVertexAttrib2fv);
3646 ORD(glVertexAttrib3f);
3647 ORD(glVertexAttrib3fv);
3648 ORD(glVertexAttrib4f);
3649 ORD(glVertexAttrib4fv);
3650 ORD(glVertexAttribPointer);
3651 ORD(glViewport);
3652#undef ORD
3653
3654#define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, glsym_)
3655 // Extensions
3656 ORD(glGetProgramBinaryOES);
3657 ORD(glProgramBinaryOES);
3658 ORD(glMapBufferOES);
3659 ORD(glUnmapBufferOES);
3660 ORD(glGetBufferPointervOES);
3661 ORD(glTexImage3DOES);
3662 ORD(glTexSubImage3DOES);
3663 ORD(glCopyTexSubImage3DOES);
3664 ORD(glCompressedTexImage3DOES);
3665 ORD(glCompressedTexSubImage3DOES);
3666 ORD(glFramebufferTexture3DOES);
3667 ORD(glGetPerfMonitorGroupsAMD);
3668 ORD(glGetPerfMonitorCountersAMD);
3669 ORD(glGetPerfMonitorGroupStringAMD);
3670 ORD(glGetPerfMonitorCounterStringAMD);
3671 ORD(glGetPerfMonitorCounterInfoAMD);
3672 ORD(glGenPerfMonitorsAMD);
3673 ORD(glDeletePerfMonitorsAMD);
3674 ORD(glSelectPerfMonitorCountersAMD);
3675 ORD(glBeginPerfMonitorAMD);
3676 ORD(glEndPerfMonitorAMD);
3677 ORD(glGetPerfMonitorCounterDataAMD);
3678 ORD(glDiscardFramebufferEXT);
3679 ORD(glMultiDrawArraysEXT);
3680 ORD(glMultiDrawElementsEXT);
3681 ORD(glDeleteFencesNV);
3682 ORD(glGenFencesNV);
3683 ORD(glIsFenceNV);
3684 ORD(glTestFenceNV);
3685 ORD(glGetFenceivNV);
3686 ORD(glFinishFenceNV);
3687 ORD(glSetFenceNV);
3688 ORD(glGetDriverControlsQCOM);
3689 ORD(glGetDriverControlStringQCOM);
3690 ORD(glEnableDriverControlQCOM);
3691 ORD(glDisableDriverControlQCOM);
3692 ORD(glExtGetTexturesQCOM);
3693 ORD(glExtGetBuffersQCOM);
3694 ORD(glExtGetRenderbuffersQCOM);
3695 ORD(glExtGetFramebuffersQCOM);
3696 ORD(glExtGetTexLevelParameterivQCOM);
3697 ORD(glExtTexObjectStateOverrideiQCOM);
3698 ORD(glExtGetTexSubImageQCOM);
3699 ORD(glExtGetBufferPointervQCOM);
3700 ORD(glExtGetShadersQCOM);
3701 ORD(glExtGetProgramsQCOM);
3702 ORD(glExtIsProgramBinaryQCOM);
3703 ORD(glExtGetProgramBinarySourceQCOM);
3704#undef ORD
3705
3706// Override functions wrapped by Evas_GL
3707#define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, evgl_)
3708 ORD(glBindFramebuffer);
3709 ORD(glBindRenderbuffer);
3710
3711 // GLES2.0 API compat on top of desktop gl
3712 ORD(glClearDepthf);
3713 ORD(glDepthRangef);
3714 ORD(glGetShaderPrecisionFormat);
3715 ORD(glReleaseShaderCompiler);
3716 ORD(glShaderBinary);
3717
3718 ORD(glGetString);
3719
3720#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3721 // GLES 2.0 Extensions that needs wrapping
3722 ORD(evasglCreateImage);
3723 ORD(evasglDestroyImage);
3724 ORD(glEvasGLImageTargetTexture2DOES);
3725 ORD(glEvasGLImageTargetRenderbufferStorageOES);
3726#endif
3727
3728#undef ORD
3729
3730 return &gl_funcs;
3731}
3732
3733static int
3734eng_image_load_error_get(void *data __UNUSED__, void *image)
3735{
3736 Evas_GL_Image *im;
3737
3738 if (!image) return EVAS_LOAD_ERROR_NONE;
3739 im = image;
3740 return im->im->cache_entry.load_error;
3741}
3742
3743static Eina_Bool
3744eng_image_animated_get(void *data __UNUSED__, void *image)
3745{
3746 Evas_GL_Image *gim = image;
3747 Image_Entry *im;
3748
3749 if (!gim) return EINA_FALSE;
3750 im = (Image_Entry *)gim->im;
3751 if (!im) return EINA_FALSE;
3752
3753 return im->flags.animated;
3754}
3755
3756static int
3757eng_image_animated_frame_count_get(void *data __UNUSED__, void *image)
3758{
3759 Evas_GL_Image *gim = image;
3760 Image_Entry *im;
3761
3762 if (!gim) return -1;
3763 im = (Image_Entry *)gim->im;
3764 if (!im) return -1;
3765
3766 if (!im->flags.animated) return -1;
3767 return im->frame_count;
3768}
3769
3770static Evas_Image_Animated_Loop_Hint
3771eng_image_animated_loop_type_get(void *data __UNUSED__, void *image)
3772{
3773 Evas_GL_Image *gim = image;
3774 Image_Entry *im;
3775
3776 if (!gim) return EVAS_IMAGE_ANIMATED_HINT_NONE;
3777 im = (Image_Entry *)gim->im;
3778 if (!im) return EVAS_IMAGE_ANIMATED_HINT_NONE;
3779
3780 if (!im->flags.animated) return EVAS_IMAGE_ANIMATED_HINT_NONE;
3781 return im->loop_hint;
3782}
3783
3784static int
3785eng_image_animated_loop_count_get(void *data __UNUSED__, void *image)
3786{
3787 Evas_GL_Image *gim = image;
3788 Image_Entry *im;
3789
3790 if (!gim) return -1;
3791 im = (Image_Entry *)gim->im;
3792 if (!im) return -1;
3793
3794 if (!im->flags.animated) return -1;
3795 return im->loop_count;
3796}
3797
3798static double
3799eng_image_animated_frame_duration_get(void *data __UNUSED__, void *image, int start_frame, int frame_num)
3800{
3801 Evas_GL_Image *gim = image;
3802 Image_Entry *im;
3803
3804 if (!gim) return -1;
3805 im = (Image_Entry *)gim->im;
3806 if (!im) return -1;
3807
3808 if (!im->flags.animated) return -1;
3809 return evas_common_load_rgba_image_frame_duration_from_file(im, start_frame, frame_num);
3810}
3811
3812static Eina_Bool
3813eng_image_animated_frame_set(void *data __UNUSED__, void *image, int frame_index)
3814{
3815 Evas_GL_Image *gim = image;
3816 Image_Entry *im;
3817
3818 if (!gim) return EINA_FALSE;
3819 im = (Image_Entry *)gim->im;
3820 if (!im) return EINA_FALSE;
3821
3822 if (!im->flags.animated) return EINA_FALSE;
3823 if (im->cur_frame == frame_index) return EINA_FALSE;
3824
3825 im->cur_frame = frame_index;
3826 return EINA_TRUE;
3827}
3828
3829static void
3830eng_image_max_size_get(void *data, int *maxw, int *maxh)
3831{
3832 Render_Engine *re = (Render_Engine *)data;
3833 if (maxw) *maxw = re->win->gl_context->shared->info.max_texture_size;
3834 if (maxh) *maxh = re->win->gl_context->shared->info.max_texture_size;
3835}
3836
3837static int
3838module_open(Evas_Module *em)
3839{
3840 static Eina_Bool xrm_inited = EINA_FALSE;
3841 if (!xrm_inited)
3842 {
3843 xrm_inited = EINA_TRUE;
3844 XrmInitialize();
3845 }
3846
3847 if (!em) return 0;
3848 if (!evas_gl_common_module_open()) return 0;
3849 /* get whatever engine module we inherit from */
3850 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
3851 if (_evas_engine_GL_X11_log_dom < 0)
3852 _evas_engine_GL_X11_log_dom = eina_log_domain_register
3853 ("evas-gl_x11", EVAS_DEFAULT_LOG_COLOR);
3854 if (_evas_engine_GL_X11_log_dom < 0)
3855 {
3856 EINA_LOG_ERR("Can not create a module log domain.");
3857 return 0;
3858 }
3859 /* store it for later use */
3860 func = pfunc;
3861 /* now to override methods */
3862 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
3863 ORD(info);
3864 ORD(info_free);
3865 ORD(setup);
3866 ORD(canvas_alpha_get);
3867 ORD(output_free);
3868 ORD(output_resize);
3869 ORD(output_tile_size_set);
3870 ORD(output_redraws_rect_add);
3871 ORD(output_redraws_rect_del);
3872 ORD(output_redraws_clear);
3873 ORD(output_redraws_next_update_get);
3874 ORD(output_redraws_next_update_push);
3875 ORD(context_cutout_add);
3876 ORD(context_cutout_clear);
3877 ORD(output_flush);
3878 ORD(output_idle_flush);
3879 ORD(output_dump);
3880 ORD(rectangle_draw);
3881 ORD(line_draw);
3882 ORD(polygon_point_add);
3883 ORD(polygon_points_clear);
3884 ORD(polygon_draw);
3885
3886 ORD(image_load);
3887 ORD(image_new_from_data);
3888 ORD(image_new_from_copied_data);
3889 ORD(image_free);
3890 ORD(image_size_get);
3891 ORD(image_size_set);
3892 ORD(image_dirty_region);
3893 ORD(image_data_get);
3894 ORD(image_data_put);
3895 ORD(image_data_preload_request);
3896 ORD(image_data_preload_cancel);
3897 ORD(image_alpha_set);
3898 ORD(image_alpha_get);
3899 ORD(image_border_set);
3900 ORD(image_border_get);
3901 ORD(image_draw);
3902 ORD(image_comment_get);
3903 ORD(image_format_get);
3904 ORD(image_colorspace_set);
3905 ORD(image_colorspace_get);
3906 ORD(image_mask_create);
3907 ORD(image_native_set);
3908 ORD(image_native_get);
3909#if 0 // filtering disabled
3910 ORD(image_draw_filtered);
3911 ORD(image_filtered_get);
3912 ORD(image_filtered_save);
3913 ORD(image_filtered_free);
3914#endif
3915
3916 ORD(font_draw);
3917
3918 ORD(image_scale_hint_set);
3919 ORD(image_scale_hint_get);
3920 ORD(image_stride_get);
3921
3922 ORD(image_map_draw);
3923 ORD(image_map_surface_new);
3924 ORD(image_map_surface_free);
3925
3926 ORD(image_content_hint_set);
3927 ORD(image_content_hint_get);
3928
3929 ORD(image_cache_flush);
3930 ORD(image_cache_set);
3931 ORD(image_cache_get);
3932
3933 ORD(gl_surface_create);
3934 ORD(gl_surface_destroy);
3935 ORD(gl_context_create);
3936 ORD(gl_context_destroy);
3937 ORD(gl_make_current);
3938 ORD(gl_string_query);
3939 ORD(gl_proc_address_get);
3940 ORD(gl_native_surface_get);
3941 ORD(gl_api_get);
3942
3943 ORD(image_load_error_get);
3944
3945 /* now advertise out own api */
3946 ORD(image_animated_get);
3947 ORD(image_animated_frame_count_get);
3948 ORD(image_animated_loop_type_get);
3949 ORD(image_animated_loop_count_get);
3950 ORD(image_animated_frame_duration_get);
3951 ORD(image_animated_frame_set);
3952
3953 ORD(image_max_size_get);
3954
3955 /* now advertise out own api */
3956 em->functions = (void *)(&func);
3957 return 1;
3958}
3959
3960static void
3961module_close(Evas_Module *em __UNUSED__)
3962{
3963 eina_log_domain_unregister(_evas_engine_GL_X11_log_dom);
3964/*
3965 if (xrdb_user.db)
3966 {
3967 XrmDestroyDatabase(xrdb_user.db);
3968 xrdb_user.last_stat = 0;
3969 xrdb_user.last_mtime = 0;
3970 xrdb_user.db = NULL;
3971 }
3972 */
3973 evas_gl_common_module_close();
3974}
3975
3976static Evas_Module_Api evas_modapi =
3977{
3978 EVAS_MODULE_API_VERSION,
3979 "gl_x11",
3980 "none",
3981 {
3982 module_open,
3983 module_close
3984 }
3985};
3986
3987EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, gl_x11);
3988
3989#ifndef EVAS_STATIC_BUILD_GL_XLIB
3990EVAS_EINA_MODULE_DEFINE(engine, gl_x11);
3991#endif
3992
3993/* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/