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