1 #include "evas_common.h" /* Also includes international specific stuff */
2 #include "evas_engine.h"
5 # include <dlfcn.h> /* dlopen,dlclose,etc */
7 # error gl_x11 should not get compiled if dlsym is not found on the system!
10 #define EVAS_GL_NO_GL_H_CHECK 1
13 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
15 # if defined(GLES_VARIETY_S3C6410)
16 # elif defined(GLES_VARIETY_SGX)
22 typedef struct _Render_Engine Render_Engine;
23 typedef struct _Render_Engine_GL_Surface Render_Engine_GL_Surface;
24 typedef struct _Render_Engine_GL_Context Render_Engine_GL_Context;
25 typedef struct _Render_Engine_GL_Resource Render_Engine_GL_Resource;
26 typedef struct _Extension_Entry Extension_Entry;
30 Evas_GL_X11_Window *win;
31 Evas_Engine_Info_GL_X11 *info;
36 XrmDatabase xrdb; // xres - dpi
37 struct { // xres - dpi
38 int dpi; // xres - dpi
44 // GL Surface Capability
65 int depth_24_stencil_8[4];
71 struct _Render_Engine_GL_Surface
82 // Render target Texture/Buffers
83 GLint rt_msaa_samples;
86 GLint rt_internal_fmt;
91 GLenum rb_stencil_fmt;
92 GLuint rb_depth_stencil;
93 GLenum rb_depth_stencil_fmt;
95 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
96 EGLSurface direct_sfc;
101 Render_Engine_GL_Context *current_ctx;
104 struct _Render_Engine_GL_Context
107 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
118 Render_Engine_GL_Surface *current_sfc;
121 // Resources used per thread
122 struct _Render_Engine_GL_Resource
124 // Resource context/surface per Thread in TLS for evasgl use
125 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
133 // Extension Handling
134 struct _Extension_Entry
137 const char *real_name;
141 static int initted = 0;
142 static int gl_wins = 0;
143 static int gl_direct_override = 0;
144 static int gl_direct_enabled = 0;
145 static Render_Engine_GL_Context *current_evgl_ctx = NULL;
146 static Render_Engine *current_engine = NULL;
147 static Evas_Object *gl_direct_img_obj = NULL;
149 static int _ext_initted = 0;
150 static char *_gl_ext_string = NULL;
151 static char *_evasgl_ext_string = NULL;
153 // Resource context/surface per Thread in TLS for evasgl use
154 static Eina_TLS resource_key;
155 static Eina_List *resource_list;
158 typedef void (*_eng_fn) (void);
159 typedef _eng_fn (*glsym_func_eng_fn) ();
160 typedef void (*glsym_func_void) ();
161 typedef void *(*glsym_func_void_ptr) ();
162 typedef int (*glsym_func_int) ();
163 typedef unsigned int (*glsym_func_uint) ();
164 typedef unsigned char (*glsym_func_uchar) ();
165 typedef unsigned char *(*glsym_func_uchar_ptr) ();
166 typedef const char *(*glsym_func_const_char_ptr) ();
168 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
170 #ifndef EGL_NATIVE_PIXMAP_KHR
171 # define EGL_NATIVE_PIXMAP_KHR 0x30b0
173 _eng_fn (*glsym_eglGetProcAddress) (const char *a) = NULL;
174 void (*glsym_eglBindTexImage) (EGLDisplay a, EGLSurface b, int c) = NULL;
175 void (*glsym_eglReleaseTexImage) (EGLDisplay a, EGLSurface b, int c) = NULL;
176 void *(*glsym_eglCreateImage) (EGLDisplay a, EGLContext b, EGLenum c, EGLClientBuffer d, const int *e) = NULL;
177 void (*glsym_eglDestroyImage) (EGLDisplay a, void *b) = NULL;
178 void (*glsym_glEGLImageTargetTexture2DOES) (int a, void *b) = NULL;
179 void (*glsym_glEGLImageTargetRenderbufferStorageOES) (int a, void *b) = NULL;
180 void *(*glsym_eglMapImageSEC) (void *a, void *b) = NULL;
181 unsigned int (*glsym_eglUnmapImageSEC) (void *a, void *b) = NULL;
182 const char *(*glsym_eglQueryString) (EGLDisplay a, int name) = NULL;
184 unsigned int (*glsym_eglLockSurface) (EGLDisplay a, EGLSurface b, const int *attrib_list) = NULL;
185 unsigned int (*glsym_eglUnlockSurface) (EGLDisplay a, EGLSurface b) = NULL;
188 typedef XID (*glsym_func_xid) ();
190 _eng_fn (*glsym_glXGetProcAddress) (const char *a) = NULL;
191 void (*glsym_glXBindTexImage) (Display *a, GLXDrawable b, int c, int *d) = NULL;
192 void (*glsym_glXReleaseTexImage) (Display *a, GLXDrawable b, int c) = NULL;
193 int (*glsym_glXGetVideoSync) (unsigned int *a) = NULL;
194 int (*glsym_glXWaitVideoSync) (int a, int b, unsigned int *c) = NULL;
195 XID (*glsym_glXCreatePixmap) (Display *a, void *b, Pixmap c, const int *d) = NULL;
196 void (*glsym_glXDestroyPixmap) (Display *a, XID b) = NULL;
197 void (*glsym_glXQueryDrawable) (Display *a, XID b, int c, unsigned int *d) = NULL;
198 int (*glsym_glXSwapIntervalSGI) (int a) = NULL;
199 void (*glsym_glXSwapIntervalEXT) (Display *s, GLXDrawable b, int c) = NULL;
201 const char *(*glsym_glXQueryExtensionsString) (Display *a, int screen) = NULL;
205 void (*glsym_glGetProgramBinaryOES) (GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, void *binary) = NULL;
206 void (*glsym_glProgramBinaryOES) (GLuint program, GLenum binaryFormat, const void *binary, GLint length) = NULL;
207 void* (*glsym_glMapBufferOES) (GLenum target, GLenum access) = NULL;
208 unsigned char (*glsym_glUnmapBufferOES) (GLenum target) = NULL;
209 void (*glsym_glGetBufferPointervOES) (GLenum target, GLenum pname, void** params) = NULL;
210 void (*glsym_glTexImage3DOES) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void* pixels) = NULL;
211 void (*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;
212 void (*glsym_glCopyTexSubImage3DOES) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height) = NULL;
213 void (*glsym_glCompressedTexImage3DOES) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const void* data) = NULL;
214 void (*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;
215 void (*glsym_glFramebufferTexture3DOES) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset) = NULL;
216 void (*glsym_glGetPerfMonitorGroupsAMD) (GLint* numGroups, GLsizei groupsSize, GLuint* groups) = NULL;
217 void (*glsym_glGetPerfMonitorCountersAMD) (GLuint group, GLint* numCounters, GLint* maxActiveCounters, GLsizei counterSize, GLuint* counters) = NULL;
218 void (*glsym_glGetPerfMonitorGroupStringAMD) (GLuint group, GLsizei bufSize, GLsizei* length, char* groupString) = NULL;
219 void (*glsym_glGetPerfMonitorCounterStringAMD) (GLuint group, GLuint counter, GLsizei bufSize, GLsizei* length, char* counterString) = NULL;
220 void (*glsym_glGetPerfMonitorCounterInfoAMD) (GLuint group, GLuint counter, GLenum pname, void* data) = NULL;
221 void (*glsym_glGenPerfMonitorsAMD) (GLsizei n, GLuint* monitors) = NULL;
222 void (*glsym_glDeletePerfMonitorsAMD) (GLsizei n, GLuint* monitors) = NULL;
223 void (*glsym_glSelectPerfMonitorCountersAMD) (GLuint monitor, GLboolean enable, GLuint group, GLint numCounters, GLuint* countersList) = NULL;
224 void (*glsym_glBeginPerfMonitorAMD) (GLuint monitor) = NULL;
225 void (*glsym_glEndPerfMonitorAMD) (GLuint monitor) = NULL;
226 void (*glsym_glGetPerfMonitorCounterDataAMD) (GLuint monitor, GLenum pname, GLsizei dataSize, GLuint* data, GLint* bytesWritten) = NULL;
227 void (*glsym_glDiscardFramebufferEXT) (GLenum target, GLsizei numAttachments, const GLenum* attachments) = NULL;
228 void (*glsym_glMultiDrawArraysEXT) (GLenum mode, GLint* first, GLsizei* count, GLsizei primcount) = NULL;
229 void (*glsym_glMultiDrawElementsEXT) (GLenum mode, const GLsizei* count, GLenum type, const GLvoid** indices, GLsizei primcount) = NULL;
230 void (*glsym_glDeleteFencesNV) (GLsizei n, const GLuint* fences) = NULL;
231 void (*glsym_glGenFencesNV) (GLsizei n, GLuint* fences) = NULL;
232 unsigned char (*glsym_glIsFenceNV) (GLuint fence) = NULL;
233 unsigned char (*glsym_glTestFenceNV) (GLuint fence) = NULL;
234 void (*glsym_glGetFenceivNV) (GLuint fence, GLenum pname, GLint* params) = NULL;
235 void (*glsym_glFinishFenceNV) (GLuint fence) = NULL;
236 void (*glsym_glSetFenceNV) (GLuint, GLenum) = NULL;
237 void (*glsym_glRenderbufferStorageMultisample) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height) = NULL;
238 void (*glsym_glFramebufferTexture2DMultisample) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples) = NULL;
239 void (*glsym_glGetDriverControlsQCOM) (GLint* num, GLsizei size, GLuint* driverControls) = NULL;
240 void (*glsym_glGetDriverControlStringQCOM) (GLuint driverControl, GLsizei bufSize, GLsizei* length, char* driverControlString) = NULL;
241 void (*glsym_glEnableDriverControlQCOM) (GLuint driverControl) = NULL;
242 void (*glsym_glDisableDriverControlQCOM) (GLuint driverControl) = NULL;
243 void (*glsym_glExtGetTexturesQCOM) (GLuint* textures, GLint maxTextures, GLint* numTextures) = NULL;
244 void (*glsym_glExtGetBuffersQCOM) (GLuint* buffers, GLint maxBuffers, GLint* numBuffers) = NULL;
245 void (*glsym_glExtGetRenderbuffersQCOM) (GLuint* renderbuffers, GLint maxRenderbuffers, GLint* numRenderbuffers) = NULL;
246 void (*glsym_glExtGetFramebuffersQCOM) (GLuint* framebuffers, GLint maxFramebuffers, GLint* numFramebuffers) = NULL;
247 void (*glsym_glExtGetTexLevelParameterivQCOM) (GLuint texture, GLenum face, GLint level, GLenum pname, GLint* params) = NULL;
248 void (*glsym_glExtTexObjectStateOverrideiQCOM) (GLenum target, GLenum pname, GLint param) = NULL;
249 void (*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;
250 void (*glsym_glExtGetBufferPointervQCOM) (GLenum target, void** params) = NULL;
251 void (*glsym_glExtGetShadersQCOM) (GLuint* shaders, GLint maxShaders, GLint* numShaders) = NULL;
252 void (*glsym_glExtGetProgramsQCOM) (GLuint* programs, GLint maxPrograms, GLint* numPrograms) = NULL;
253 unsigned char (*glsym_glExtIsProgramBinaryQCOM) (GLuint program) = NULL;
254 void (*glsym_glExtGetProgramBinarySourceQCOM) (GLuint program, GLenum shadertype, char* source, GLint* length) = NULL;
257 //------ GLES 2.0 Extensions supported in EvasGL -----//
258 static Extension_Entry _gl_ext_entries[] = {
259 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
260 //--- Function Extensions ---//
261 { "GL_OES_get_program_binary", "get_program_binary", 0 },
262 { "GL_OES_mapbuffer", "mapbuffer", 0 },
263 { "GL_OES_texture_3D", "texture_3D", 0 },
264 { "AMD_performance_monitor", "AMD_performance_monitor", 0 },
265 { "GL_EXT_discard_framebuffer", "discard_framebuffer", 0 },
266 { "GL_EXT_multi_draw_arrays", "multi_draw_arrays", 0 },
267 { "GL_NV_fence", "NV_fence", 0 },
268 { "GL_QCOM_driver_control", "QCOM_driver_control", 0 },
269 { "GL_QCOM_extended_get", "QCOM_extended_get", 0 },
270 { "GL_QCOM_extended_get2", "QCOM_extended_get2", 0 },
271 { "GL_IMG_multlisampled_render_to_texture", "multisampled_render_to_texture", 0 },
273 //--- Define Extensions ---//
274 { "GL_OES_compressed_ETC1_RGB8_texture", "compressed_ETC1_RGB8_texture", 0 },
275 { "GL_OES_compressed_paletted_texture", "compressed_paletted_texture", 0 },
276 { "GL_OES_depth24", "depth24", 0 },
277 { "GL_OES_depth32", "depth32", 0 },
278 { "GL_OES_EvasGL_image", "EGL_image", 0 },
279 { "GL_OES_packed_depth_stencil", "packed_depth_stencil", 0 },
280 { "GL_OES_rgb8_rgba8", "rgb8_rgba8", 0 },
281 { "GL_OES_standard_derivatives", "standard_derivatives", 0 },
282 { "GL_OES_stencil1", "stencil1", 0 },
283 { "GL_OES_stencil4", "stencil4", 0 },
284 { "GL_OES_texture_float", "texture_float", 0 },
285 { "GL_OES_texture_half_float", "texture_half_float", 0 },
286 { "GL_OES_texture_half_float_linear", "texture_half_float_linear", 0 },
287 { "GL_OES_texture_npot", "texture_npot", 0 },
288 { "GL_OES_vertex_half_float", "vertex_half_float", 0 },
289 { "GL_OES_vertex_type_10_10_10_2", "vertex_type_10_10_10_2", 0 },
290 { "GL_AMD_compressed_3DC_texture", "compressed_3DC_texture", 0 },
291 { "GL_AMD_compressed_ATC_texture", "compressed_ATC_texture", 0 },
292 { "GL_AMD_program_binary_Z400", "program_binary_Z400", 0 },
293 { "GL_EXT_blend_minmax", "blend_minmax", 0 },
294 { "GL_EXT_read_format_bgra", "read_format_bgra", 0 },
295 { "GL_EXT_texture_filter_anisotropic", "texture_filter_anisotrophic", 0 },
296 { "GL_EXT_texture_format_BGRA8888", "texture_format_BGRA8888", 0 },
297 { "GL_EXT_texture_type_2_10_10_10_REV", "texture_type_2_10_10_10_rev", 0 },
298 { "GL_IMG_program_binary", "IMG_program_binary", 0 },
299 { "GL_IMG_read_format", "IMG_read_format", 0 },
300 { "GL_IMG_shader_binary", "IMG_shader_binary", 0 },
301 { "GL_IMG_texture_compression_pvrtc", "IMG_texture_compression_pvrtc", 0 },
302 { "GL_QCOM_perfmon_global_mode", "QCOM_perfmon_global_mode", 0 },
303 { "GL_QCOM_writeonly_rendering", "QCOM_writeonly_rendering", 0 },
305 //--- Function Extensions ---//
306 { "GL_OES_get_program_binary", "get_program_binary", 0 },
307 { "GL_OES_mapbuffer", "mapbuffer", 0 },
308 { "GL_OES_texture_3D", "texture_3D", 0 },
309 { "AMD_performance_monitor", "AMD_performance_monitor", 0 },
310 { "GL_EXT_discard_framebuffer", "discard_framebuffer", 0 },
311 { "GL_EXT_multi_draw_arrays", "multi_draw_arrays", 0 },
312 { "GL_NV_fence", "NV_fence", 0 },
313 { "GL_QCOM_driver_control", "QCOM_driver_control", 0 },
314 { "GL_QCOM_extended_get", "QCOM_extended_get", 0 },
315 { "GL_QCOM_extended_get2", "QCOM_extended_get2", 0 },
316 { "GL_IMG_multlisampled_render_to_texture", "multisampled_render_to_texture", 0 },
318 //--- Define Extensions ---//
319 { "GL_OES_compressed_ETC1_RGB8_texture", "compressed_ETC1_RGB8_texture", 0 },
320 { "GL_OES_compressed_paletted_texture", "compressed_paletted_texture", 0 },
321 { "GL_OES_depth24", "depth24", 0 },
322 { "GL_OES_depth32", "depth32", 0 },
323 { "GL_OES_EvasGL_image", "EGL_image", 0 },
324 { "GL_OES_packed_depth_stencil", "packed_depth_stencil", 0 },
325 { "GL_OES_rgb8_rgba8", "rgb8_rgba8", 0 },
326 { "GL_OES_standard_derivatives", "standard_derivatives", 0 },
327 { "GL_OES_stencil1", "stencil1", 0 },
328 { "GL_OES_stencil4", "stencil4", 0 },
329 { "GL_OES_texture_float", "texture_float", 0 },
330 { "GL_OES_texture_half_float", "texture_half_float", 0 },
331 { "GL_OES_texture_half_float_linear", "texture_half_float_linear", 0 },
332 { "GL_OES_texture_npot", "texture_non_power_of_two", 0 }, // Desktop differs
333 { "GL_OES_vertex_half_float", "half_float_vertex", 0 }, // Desktop differs
334 { "GL_OES_vertex_type_10_10_10_2", "vertex_type_10_10_10_2", 0 },
335 { "GL_AMD_compressed_3DC_texture", "compressed_3DC_texture", 0 },
336 { "GL_AMD_compressed_ATC_texture", "compressed_ATC_texture", 0 },
337 { "GL_AMD_program_binary_Z400", "program_binary_Z400", 0 },
338 { "GL_EXT_blend_minmax", "blend_minmax", 0 },
339 { "GL_EXT_read_format_bgra", "bgra", 0 }, // Desktop differs
340 { "GL_EXT_texture_filter_anisotropic", "texture_filter_anisotrophic", 0 },
341 { "GL_EXT_texture_format_BGRA8888", "bgra", 0 }, // Desktop differs
342 { "GL_EXT_texture_type_2_10_10_10_REV", "vertex_type_2_10_10_10_rev", 0 }, // Desktop differs ???
343 { "GL_IMG_program_binary", "IMG_program_binary", 0 },
344 { "GL_IMG_read_format", "IMG_read_format", 0 },
345 { "GL_IMG_shader_binary", "IMG_shader_binary", 0 },
346 { "GL_IMG_texture_compression_pvrtc", "IMG_texture_compression_pvrtc", 0 },
347 { "GL_QCOM_perfmon_global_mode", "QCOM_perfmon_global_mode", 0 },
348 { "GL_QCOM_writeonly_rendering", "QCOM_writeonly_rendering", 0 },
354 //------ Extensions supported in EvasGL -----//
355 static Extension_Entry _evasgl_ext_entries[] = {
356 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
357 { "EvasGL_KHR_image", "EGL_KHR_image", 0 },
358 { "EvasGL_KHR_vg_parent_image", "EGL_KHR_vg_parent_image", 0 },
359 { "EvasGL_KHR_gl_texture_2D_image", "EGL_KHR_gl_texture_2D_image", 0 },
360 { "EvasGL_KHR_gl_texture_cubemap_image", "EGL_KHR_gl_texture_cubemap_image", 0 },
361 { "EvasGL_KHR_gl_texture_3D_image", "EGL_KHR_gl_texture_3D_image", 0 },
362 { "EvasGL_KHR_gl_renderbuffer_image", "EGL_KHR_gl_renderbuffer_image", 0 },
369 _gl_ext_sym_init(void)
375 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
376 #define FINDSYM(dst, sym, typ) \
377 if ((!dst) && (glsym_eglGetProcAddress)) dst = (typ)glsym_eglGetProcAddress(sym); \
378 if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
380 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddress", glsym_func_eng_fn);
381 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddressEXT", glsym_func_eng_fn);
382 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddressARB", glsym_func_eng_fn);
383 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddressKHR", glsym_func_eng_fn);
385 FINDSYM(glsym_eglBindTexImage, "eglBindTexImage", glsym_func_void);
386 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageEXT", glsym_func_void);
387 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageARB", glsym_func_void);
388 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageKHR", glsym_func_void);
390 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImage", glsym_func_void);
391 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageEXT", glsym_func_void);
392 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageARB", glsym_func_void);
393 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageKHR", glsym_func_void);
395 FINDSYM(glsym_eglCreateImage, "eglCreateImage", glsym_func_void_ptr);
396 FINDSYM(glsym_eglCreateImage, "eglCreateImageEXT", glsym_func_void_ptr);
397 FINDSYM(glsym_eglCreateImage, "eglCreateImageARB", glsym_func_void_ptr);
398 FINDSYM(glsym_eglCreateImage, "eglCreateImageKHR", glsym_func_void_ptr);
400 FINDSYM(glsym_eglDestroyImage, "eglDestroyImage", glsym_func_void);
401 FINDSYM(glsym_eglDestroyImage, "eglDestroyImageEXT", glsym_func_void);
402 FINDSYM(glsym_eglDestroyImage, "eglDestroyImageARB", glsym_func_void);
403 FINDSYM(glsym_eglDestroyImage, "eglDestroyImageKHR", glsym_func_void);
405 FINDSYM(glsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", glsym_func_void);
407 FINDSYM(glsym_glEGLImageTargetRenderbufferStorageOES, "glEGLImageTargetRenderbufferStorageOES", glsym_func_void);
409 FINDSYM(glsym_eglMapImageSEC, "eglMapImageSEC", glsym_func_void_ptr);
410 FINDSYM(glsym_eglUnmapImageSEC, "eglUnmapImageSEC", glsym_func_uint);
412 FINDSYM(glsym_eglQueryString, "eglQueryString", glsym_func_const_char_ptr);
414 FINDSYM(glsym_eglLockSurface, "eglLockSurface", glsym_func_uint);
415 FINDSYM(glsym_eglLockSurface, "eglLockSurfaceEXT", glsym_func_uint);
416 FINDSYM(glsym_eglLockSurface, "eglLockSurfaceARB", glsym_func_uint);
417 FINDSYM(glsym_eglLockSurface, "eglLockSurfaceKHR", glsym_func_uint);
419 FINDSYM(glsym_eglUnlockSurface, "eglUnlockSurface", glsym_func_uint);
420 FINDSYM(glsym_eglUnlockSurface, "eglUnlockSurfaceEXT", glsym_func_uint);
421 FINDSYM(glsym_eglUnlockSurface, "eglUnlockSurfaceARB", glsym_func_uint);
422 FINDSYM(glsym_eglUnlockSurface, "eglUnlockSurfaceKHR", glsym_func_uint);
425 #define FINDSYM(dst, sym, typ) \
426 if ((!dst) && (glsym_glXGetProcAddress)) dst = (typ)glsym_glXGetProcAddress(sym); \
427 if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
429 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddress", glsym_func_eng_fn);
430 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressEXT", glsym_func_eng_fn);
431 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressARB", glsym_func_eng_fn);
433 FINDSYM(glsym_glXBindTexImage, "glXBindTexImage", glsym_func_void);
434 FINDSYM(glsym_glXBindTexImage, "glXBindTexImageEXT", glsym_func_void);
435 FINDSYM(glsym_glXBindTexImage, "glXBindTexImageARB", glsym_func_void);
437 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImage", glsym_func_void);
438 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImageEXT", glsym_func_void);
439 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImageARB", glsym_func_void);
441 FINDSYM(glsym_glXGetVideoSync, "glXGetVideoSyncSGI", glsym_func_int);
443 FINDSYM(glsym_glXWaitVideoSync, "glXWaitVideoSyncSGI", glsym_func_int);
445 FINDSYM(glsym_glXCreatePixmap, "glXCreatePixmap", glsym_func_xid);
446 FINDSYM(glsym_glXCreatePixmap, "glXCreatePixmapEXT", glsym_func_xid);
447 FINDSYM(glsym_glXCreatePixmap, "glXCreatePixmapARB", glsym_func_xid);
449 FINDSYM(glsym_glXDestroyPixmap, "glXDestroyPixmap", glsym_func_void);
450 FINDSYM(glsym_glXDestroyPixmap, "glXDestroyPixmapEXT", glsym_func_void);
451 FINDSYM(glsym_glXDestroyPixmap, "glXDestroyPixmapARB", glsym_func_void);
453 FINDSYM(glsym_glXQueryDrawable, "glXQueryDrawable", glsym_func_void);
454 FINDSYM(glsym_glXQueryDrawable, "glXQueryDrawableEXT", glsym_func_void);
455 FINDSYM(glsym_glXQueryDrawable, "glXQueryDrawableARB", glsym_func_void);
457 FINDSYM(glsym_glXSwapIntervalSGI, "glXSwapIntervalMESA", glsym_func_int);
458 FINDSYM(glsym_glXSwapIntervalSGI, "glXSwapIntervalSGI", glsym_func_int);
460 FINDSYM(glsym_glXSwapIntervalEXT, "glXSwapIntervalEXT", glsym_func_void);
462 FINDSYM(glsym_glXQueryExtensionsString, "glXQueryExtensionsString", glsym_func_const_char_ptr);
465 //----------- GLES 2.0 Extensions ------------//
466 // If the symbol's not found, they get set to NULL
467 // If one of the functions in the extension exists, the extension in supported
468 /* GL_OES_get_program_binary */
469 FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinary", glsym_func_void);
470 FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinaryEXT", glsym_func_void);
471 FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinaryARB", glsym_func_void);
472 FINDSYM(glsym_glGetProgramBinaryOES, "glGetProgramBinaryOES", glsym_func_void);
474 FINDSYM(glsym_glProgramBinaryOES, "glProgramBinary", glsym_func_void);
475 FINDSYM(glsym_glProgramBinaryOES, "glProgramBinaryEXT", glsym_func_void);
476 FINDSYM(glsym_glProgramBinaryOES, "glProgramBinaryARB", glsym_func_void);
477 FINDSYM(glsym_glProgramBinaryOES, "glProgramBinaryOES", glsym_func_void);
479 // Check the first function to see if the extension is supported...
480 if (glsym_glGetProgramBinaryOES) _gl_ext_entries[0].supported = 1;
483 /* GL_OES_mapbuffer */
484 FINDSYM(glsym_glMapBufferOES, "glMapBuffer", glsym_func_void_ptr);
485 FINDSYM(glsym_glMapBufferOES, "glMapBufferEXT", glsym_func_void_ptr);
486 FINDSYM(glsym_glMapBufferOES, "glMapBufferARB", glsym_func_void_ptr);
487 FINDSYM(glsym_glMapBufferOES, "glMapBufferOES", glsym_func_void_ptr);
489 FINDSYM(glsym_glUnmapBufferOES, "glUnmapBuffer", glsym_func_uchar);
490 FINDSYM(glsym_glUnmapBufferOES, "glUnmapBufferEXT", glsym_func_uchar);
491 FINDSYM(glsym_glUnmapBufferOES, "glUnmapBufferARB", glsym_func_uchar);
492 FINDSYM(glsym_glUnmapBufferOES, "glUnmapBufferOES", glsym_func_uchar);
494 FINDSYM(glsym_glGetBufferPointervOES, "glGetBufferPointerv", glsym_func_void);
495 FINDSYM(glsym_glGetBufferPointervOES, "glGetBufferPointervEXT", glsym_func_void);
496 FINDSYM(glsym_glGetBufferPointervOES, "glGetBufferPointervARB", glsym_func_void);
497 FINDSYM(glsym_glGetBufferPointervOES, "glGetBufferPointervOES", glsym_func_void);
499 if (glsym_glMapBufferOES) _gl_ext_entries[1].supported = 1;
501 /* GL_OES_texture_3D */
502 FINDSYM(glsym_glTexImage3DOES, "glTexImage3D", glsym_func_void);
503 FINDSYM(glsym_glTexImage3DOES, "glTexImage3DEXT", glsym_func_void);
504 FINDSYM(glsym_glTexImage3DOES, "glTexImage3DARB", glsym_func_void);
505 FINDSYM(glsym_glTexImage3DOES, "glTexImage3DOES", glsym_func_void);
507 FINDSYM(glsym_glTexSubImage3DOES, "glTexSubImage3D", glsym_func_void);
508 FINDSYM(glsym_glTexSubImage3DOES, "glTexSubImage3DEXT", glsym_func_void);
509 FINDSYM(glsym_glTexSubImage3DOES, "glTexSubImage3DARB", glsym_func_void);
510 FINDSYM(glsym_glTexSubImage3DOES, "glTexSubImage3DOES", glsym_func_void);
512 FINDSYM(glsym_glCopyTexSubImage3DOES, "glCopyTexSubImage3D", glsym_func_void);
513 FINDSYM(glsym_glCopyTexSubImage3DOES, "glCopyTexSubImage3DARB", glsym_func_void);
514 FINDSYM(glsym_glCopyTexSubImage3DOES, "glCopyTexSubImage3DEXT", glsym_func_void);
515 FINDSYM(glsym_glCopyTexSubImage3DOES, "glCopyTexSubImage3DOES", glsym_func_void);
517 FINDSYM(glsym_glCompressedTexImage3DOES, "glCompressedTexImage3D", glsym_func_void);
518 FINDSYM(glsym_glCompressedTexImage3DOES, "glCompressedTexImage3DARB", glsym_func_void);
519 FINDSYM(glsym_glCompressedTexImage3DOES, "glCompressedTexImage3DEXT", glsym_func_void);
520 FINDSYM(glsym_glCompressedTexImage3DOES, "glCompressedTexImage3DOES", glsym_func_void);
522 FINDSYM(glsym_glCompressedTexSubImage3DOES, "glCompressedTexSubImage3D", glsym_func_void);
523 FINDSYM(glsym_glCompressedTexSubImage3DOES, "glCompressedTexSubImage3DARB", glsym_func_void);
524 FINDSYM(glsym_glCompressedTexSubImage3DOES, "glCompressedTexSubImage3DEXT", glsym_func_void);
525 FINDSYM(glsym_glCompressedTexSubImage3DOES, "glCompressedTexSubImage3DOES", glsym_func_void);
527 FINDSYM(glsym_glFramebufferTexture3DOES, "glFramebufferTexture3D", glsym_func_void);
528 FINDSYM(glsym_glFramebufferTexture3DOES, "glFramebufferTexture3DARB", glsym_func_void);
529 FINDSYM(glsym_glFramebufferTexture3DOES, "glFramebufferTexture3DEXT", glsym_func_void);
530 FINDSYM(glsym_glFramebufferTexture3DOES, "glFramebufferTexture3DOES", glsym_func_void);
532 if (glsym_glTexSubImage3DOES) _gl_ext_entries[2].supported = 1;
534 /* AMD_performance_monitor */
535 FINDSYM(glsym_glGetPerfMonitorGroupsAMD, "glGetPerfMonitorGroupsAMD", glsym_func_void);
536 FINDSYM(glsym_glGetPerfMonitorCountersAMD, "glGetPerfMonitorCountersAMD", glsym_func_void);
537 FINDSYM(glsym_glGetPerfMonitorGroupStringAMD, "glGetPerfMonitorGroupStringAMD", glsym_func_void);
538 FINDSYM(glsym_glGetPerfMonitorCounterStringAMD, "glGetPerfMonitorCounterStringAMD", glsym_func_void);
539 FINDSYM(glsym_glGetPerfMonitorCounterInfoAMD, "glGetPerfMonitorCounterInfoAMD", glsym_func_void);
540 FINDSYM(glsym_glGenPerfMonitorsAMD, "glGenPerfMonitorsAMD", glsym_func_void);
541 FINDSYM(glsym_glDeletePerfMonitorsAMD, "glDeletePerfMonitorsAMD", glsym_func_void);
542 FINDSYM(glsym_glSelectPerfMonitorCountersAMD, "glSelectPerfMonitorCountersAMD", glsym_func_void);
543 FINDSYM(glsym_glBeginPerfMonitorAMD, "glBeginPerfMonitorAMD", glsym_func_void);
544 FINDSYM(glsym_glEndPerfMonitorAMD, "glEndPerfMonitorAMD", glsym_func_void);
545 FINDSYM(glsym_glGetPerfMonitorCounterDataAMD, "glGetPerfMonitorCounterDataAMD", glsym_func_void);
547 if (glsym_glGetPerfMonitorGroupsAMD) _gl_ext_entries[3].supported = 1;
549 /* GL_EXT_discard_framebuffer */
550 FINDSYM(glsym_glDiscardFramebufferEXT, "glDiscardFramebuffer", glsym_func_void);
551 FINDSYM(glsym_glDiscardFramebufferEXT, "glDiscardFramebufferARB", glsym_func_void);
552 FINDSYM(glsym_glDiscardFramebufferEXT, "glDiscardFramebufferEXT", glsym_func_void);
554 if (glsym_glDiscardFramebufferEXT) _gl_ext_entries[4].supported = 1;
556 /* GL_EXT_multi_draw_arrays */
557 FINDSYM(glsym_glMultiDrawArraysEXT, "glMultiDrawArrays", glsym_func_void);
558 FINDSYM(glsym_glMultiDrawArraysEXT, "glMultiDrawArraysARB", glsym_func_void);
559 FINDSYM(glsym_glMultiDrawArraysEXT, "glMultiDrawArraysEXT", glsym_func_void);
561 FINDSYM(glsym_glMultiDrawElementsEXT, "glMultiDrawElements", glsym_func_void);
562 FINDSYM(glsym_glMultiDrawElementsEXT, "glMultiDrawElementsARB", glsym_func_void);
563 FINDSYM(glsym_glMultiDrawElementsEXT, "glMultiDrawElementsEXT", glsym_func_void);
565 if (glsym_glMultiDrawArraysEXT) _gl_ext_entries[5].supported = 1;
568 FINDSYM(glsym_glDeleteFencesNV, "glDeleteFencesNV", glsym_func_void);
569 FINDSYM(glsym_glGenFencesNV, "glGenFencesNV", glsym_func_void);
570 FINDSYM(glsym_glIsFenceNV, "glIsFenceNV", glsym_func_uchar);
571 FINDSYM(glsym_glTestFenceNV, "glTestFenceNV", glsym_func_uchar);
572 FINDSYM(glsym_glGetFenceivNV, "glGetFenceivNV", glsym_func_void);
573 FINDSYM(glsym_glFinishFenceNV, "glFinishFenceNV", glsym_func_void);
574 FINDSYM(glsym_glSetFenceNV, "glSetFenceNV", glsym_func_void);
576 if (glsym_glDeleteFencesNV) _gl_ext_entries[6].supported = 1;
578 /* GL_QCOM_driver_control */
579 FINDSYM(glsym_glGetDriverControlsQCOM, "glGetDriverControlsQCOM", glsym_func_void);
580 FINDSYM(glsym_glGetDriverControlStringQCOM, "glGetDriverControlStringQCOM", glsym_func_void);
581 FINDSYM(glsym_glEnableDriverControlQCOM, "glEnableDriverControlQCOM", glsym_func_void);
582 FINDSYM(glsym_glDisableDriverControlQCOM, "glDisableDriverControlQCOM", glsym_func_void);
584 if (glsym_glGetDriverControlsQCOM) _gl_ext_entries[7].supported = 1;
586 /* GL_QCOM_extended_get */
587 FINDSYM(glsym_glExtGetTexturesQCOM, "glExtGetTexturesQCOM", glsym_func_void);
588 FINDSYM(glsym_glExtGetBuffersQCOM, "glExtGetBuffersQCOM", glsym_func_void);
589 FINDSYM(glsym_glExtGetRenderbuffersQCOM, "glExtGetRenderbuffersQCOM", glsym_func_void);
590 FINDSYM(glsym_glExtGetFramebuffersQCOM, "glExtGetFramebuffersQCOM", glsym_func_void);
591 FINDSYM(glsym_glExtGetTexLevelParameterivQCOM, "glExtGetTexLevelParameterivQCOM", glsym_func_void);
592 FINDSYM(glsym_glExtTexObjectStateOverrideiQCOM, "glExtTexObjectStateOverrideiQCOM", glsym_func_void);
593 FINDSYM(glsym_glExtGetTexSubImageQCOM, "glExtGetTexSubImageQCOM", glsym_func_void);
594 FINDSYM(glsym_glExtGetBufferPointervQCOM, "glExtGetBufferPointervQCOM", glsym_func_void);
596 if (glsym_glExtGetTexturesQCOM) _gl_ext_entries[8].supported = 1;
598 /* GL_QCOM_extended_get2 */
599 FINDSYM(glsym_glExtGetShadersQCOM, "glExtGetShadersQCOM", glsym_func_void);
600 FINDSYM(glsym_glExtGetProgramsQCOM, "glExtGetProgramsQCOM", glsym_func_void);
601 FINDSYM(glsym_glExtIsProgramBinaryQCOM, "glExtIsProgramBinaryQCOM", glsym_func_uchar);
602 FINDSYM(glsym_glExtGetProgramBinarySourceQCOM, "glExtGetProgramBinarySourceQCOM", glsym_func_void);
604 if (glsym_glExtGetShadersQCOM) _gl_ext_entries[9].supported = 1;
606 /* GL_IMG_multisampled_render_to_texture */
607 FINDSYM(glsym_glRenderbufferStorageMultisample, "glRenderbufferStorageMultisampleIMG", glsym_func_void);
608 FINDSYM(glsym_glRenderbufferStorageMultisample, "glRenderbufferStorageMultisampleEXT", glsym_func_void);
609 FINDSYM(glsym_glFramebufferTexture2DMultisample, "glFramebufferTexture2DMultisampleIMG", glsym_func_void);
610 FINDSYM(glsym_glFramebufferTexture2DMultisample, "glFramebufferTexture2DMultisampleEXT", glsym_func_void);
615 _gl_ext_init(Render_Engine *re)
618 const char *glexts, *evasglexts;
620 // GLES 2.0 Extensions
621 glexts = (const char*)glGetString(GL_EXTENSIONS);
623 ext_len = strlen(glexts);
626 DBG("GL Get Extension string NULL: No extensions supported");
630 _gl_ext_string = calloc(1, sizeof(char) * ext_len * 2);
633 ERR("Error allocating _gl_ext_string.");
637 DBG("--------GLES 2.0 Extensions--------");
638 for (i = 0; _gl_ext_entries[i].name != NULL; i++)
640 if ( (strstr(glexts, _gl_ext_entries[i].name) != NULL) ||
641 (strstr(glexts, _gl_ext_entries[i].real_name) != NULL) )
643 _gl_ext_entries[i].supported = 1;
644 strcat(_gl_ext_string, _gl_ext_entries[i].name);
645 strcat(_gl_ext_string, " ");
646 DBG("\t%s", _gl_ext_entries[i].name);
652 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
654 if (glsym_eglQueryString)
656 evasglexts = glsym_eglQueryString(re->win->egl_disp, EGL_EXTENSIONS);
658 if (glsym_glXQueryExtensionsString)
660 evasglexts = glXQueryExtensionsString(re->info->info.display,
661 re->info->info.screen);
663 ext_len = strlen(evasglexts);
667 DBG("GL Get Extension string NULL: No extensions supported");
671 _evasgl_ext_string = calloc(1, sizeof(char) * ext_len * 2);
672 if (!_evasgl_ext_string)
674 ERR("Error allocating _evasgl_ext_string.");
678 DBG("--------EvasGL Supported Extensions----------");
679 for (i = 0; _evasgl_ext_entries[i].name != NULL; i++)
681 if ( (strstr(evasglexts, _evasgl_ext_entries[i].name) != NULL) ||
682 (strstr(evasglexts, _evasgl_ext_entries[i].real_name) != NULL) )
684 _evasgl_ext_entries[i].supported = 1;
685 strcat(_evasgl_ext_string, _evasgl_ext_entries[i].name);
686 strcat(_evasgl_ext_string, " ");
687 DBG("\t%s", _evasgl_ext_entries[i].name);
694 int _evas_engine_GL_X11_log_dom = -1;
695 /* function tables - filled in later (func and parent func) */
696 static Evas_Func func, pfunc;
698 /* Function table for GL APIs */
699 static Evas_GL_API gl_funcs;
707 static struct xrdb_user xrdb_user = {0, 0, NULL};
710 xrdb_user_query(const char *name, const char *cls, char **type, XrmValue *val)
712 time_t last = xrdb_user.last_stat, now = time(NULL);
714 xrdb_user.last_stat = now;
715 if (last != now) // don't stat() more than once every second
718 const char *home = getenv("HOME");
721 if (!home) goto failed;
722 snprintf(tmp, sizeof(tmp), "%s/.Xdefaults", home);
723 if (stat(tmp, &st) != 0) goto failed;
724 if (xrdb_user.last_mtime != st.st_mtime)
726 if (xrdb_user.db) XrmDestroyDatabase(xrdb_user.db);
727 xrdb_user.db = XrmGetFileDatabase(tmp);
728 if (!xrdb_user.db) goto failed;
729 xrdb_user.last_mtime = st.st_mtime;
733 if (!xrdb_user.db) return EINA_FALSE;
734 return XrmGetResource(xrdb_user.db, name, cls, type, val);
739 XrmDestroyDatabase(xrdb_user.db);
742 xrdb_user.last_mtime = 0;
750 Evas_Engine_Info_GL_X11 *info;
752 info = calloc(1, sizeof(Evas_Engine_Info_GL_X11));
753 info->magic.magic = rand();
754 info->func.best_visual_get = eng_best_visual_get;
755 info->func.best_colormap_get = eng_best_colormap_get;
756 info->func.best_depth_get = eng_best_depth_get;
757 info->render_mode = EVAS_RENDER_MODE_BLOCKING;
763 eng_info_free(Evas *e __UNUSED__, void *info)
765 Evas_Engine_Info_GL_X11 *in;
766 // dont free! why bother? its not worth it
767 // eina_log_domain_unregister(_evas_engine_GL_X11_log_dom);
768 in = (Evas_Engine_Info_GL_X11 *)info;
773 _re_wincheck(Render_Engine *re)
775 if (re->win->surf) return 1;
776 eng_window_resurf(re->win);
779 ERR("GL engine can't re-create window surface!");
785 _re_winfree(Render_Engine *re)
787 if (!re->win->surf) return;
788 eng_window_unsurf(re->win);
791 static Render_Engine_GL_Resource *
792 _create_internal_glue_resources(void *data)
794 Render_Engine *re = (Render_Engine *)data;
795 Render_Engine_GL_Resource *rsc;
797 rsc = calloc(1, sizeof(Render_Engine_GL_Resource));
799 if (!rsc) return NULL;
801 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
803 int context_attrs[3];
804 context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
805 context_attrs[1] = 2;
806 context_attrs[2] = EGL_NONE;
808 if (eina_main_loop_is())
810 rsc->surface = re->win->egl_surface[0];
814 // Create resource surface for EGL
815 rsc->surface = eglCreateWindowSurface(re->win->egl_disp,
817 (EGLNativeWindowType)DefaultRootWindow(re->info->info.display),
821 ERR("Creating internal resource surface failed.");
827 // Create a resource context for EGL
828 rsc->context = eglCreateContext(re->win->egl_disp,
830 re->win->egl_context[0], // Evas' GL Context
834 ERR("Internal Resource Context Creations Failed.");
839 // Add to the resource resource list for cleanup
841 resource_list = eina_list_prepend(resource_list, rsc);
844 // Set the resource in TLS
845 if (eina_tls_set(resource_key, (void*)rsc) == EINA_FALSE)
847 ERR("Failed setting TLS Resource");
854 rsc->context = glXCreateContext(re->info->info.display,
856 re->win->context, // Evas' GL Context
860 ERR("Internal Resource Context Creations Failed.");
865 // Add to the resource resource list for cleanup
867 resource_list = eina_list_prepend(resource_list, rsc);
870 // Set the resource in TLS
871 if (eina_tls_set(resource_key, (void*)rsc) == EINA_FALSE)
873 ERR("Failed setting TLS Resource");
885 _destroy_internal_glue_resources(void *data)
887 Render_Engine *re = (Render_Engine *)data;
889 Render_Engine_GL_Resource *rsc;
891 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
892 // Create internal resource context if it hasn't been created already
893 if ((rsc = eina_tls_get(resource_key)) == NULL)
895 ERR("Error retrieving the TLS resources.");
899 if (eina_main_loop_is()) rsc->surface = re->win->egl_surface[0];
902 // Delete the Resources
904 EINA_LIST_FOREACH(resource_list, l, rsc)
906 if ((rsc->surface) && (rsc->surface != re->win->egl_surface[0]))
907 eglDestroySurface(re->win->egl_disp, rsc->surface);
909 eglDestroyContext(re->win->egl_disp, rsc->context);
914 // Delete the Resources
916 EINA_LIST_FOREACH(resource_list, l, rsc)
920 glXDestroyContext(re->info->info.display, rsc->context);
925 eina_list_free(resource_list);
926 resource_list = NULL;
930 eina_tls_free(resource_key);
932 // Free the extension strings
936 free(_gl_ext_string);
937 if (_evasgl_ext_string)
938 free(_evasgl_ext_string);
940 _gl_ext_string = NULL;
941 _evasgl_ext_string = NULL;
950 _internal_resources_make_current(void *data)
952 Render_Engine *re = (Render_Engine *)data;
953 Render_Engine_GL_Resource *rsc;
956 // Create internal resource context if it hasn't been created already
957 if ((rsc = eina_tls_get(resource_key)) == NULL)
959 if ((rsc = _create_internal_glue_resources(re)) == NULL)
961 ERR("Error creating internal resources.");
966 // Use resource surface/context to create surface resrouces
967 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
968 // Update the evas' window surface
969 if (eina_main_loop_is()) rsc->surface = re->win->egl_surface[0];
971 ret = eglMakeCurrent(re->win->egl_disp, rsc->surface, rsc->surface, rsc->context);
975 ERR("eglMakeCurrent() failed. Error Code: %#x", eglGetError());
979 ret = glXMakeCurrent(re->info->info.display, re->win->win, rsc->context);
982 ERR("glXMakeCurrent()!");
990 eng_setup(Evas *e, void *in)
993 Evas_Engine_Info_GL_X11 *info;
995 info = (Evas_Engine_Info_GL_X11 *)in;
996 if (!e->engine.data.output)
998 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1002 if (!glXQueryExtension(info->info.display, &eb, &evb)) return 0;
1004 re = calloc(1, sizeof(Render_Engine));
1008 e->engine.data.output = re;
1009 re->w = e->output.w;
1010 re->h = e->output.h;
1011 re->win = eng_window_new(re->info->info.display,
1012 re->info->info.drawable,
1013 re->info->info.screen,
1014 re->info->info.visual,
1015 re->info->info.colormap,
1016 re->info->info.depth,
1020 re->info->info.destination_alpha,
1021 re->info->info.rotation);
1025 e->engine.data.output = NULL;
1036 re->xr.dpi = 75000; // dpy * 1000
1038 status = xrdb_user_query("Xft.dpi", "Xft.Dpi", &type, &val);
1039 if ((!status) || (!type))
1041 if (!re->xrdb) re->xrdb = XrmGetDatabase(re->info->info.display);
1043 status = XrmGetResource(re->xrdb,
1044 "Xft.dpi", "Xft.Dpi", &type, &val);
1047 if ((status) && (type))
1049 if (!strcmp(type, "String"))
1051 const char *str, *dp;
1054 dp = strchr(str, '.');
1055 if (!dp) dp = strchr(str, ',');
1062 buf = alloca(dp - str + 1);
1063 strncpy(buf, str, dp - str);
1065 len = strlen(dp + 1);
1066 subdpi = atoi(dp + 1);
1070 for (i = len; i < 3; i++) subdpi *= 10;
1074 for (i = len; i > 3; i--) subdpi /= 10;
1076 re->xr.dpi = atoi(buf) * 1000;
1079 re->xr.dpi = atoi(str) * 1000;
1080 evas_common_font_dpi_set(re->xr.dpi / 1000);
1087 evas_common_cpu_init();
1089 evas_common_blend_init();
1090 evas_common_image_init();
1091 evas_common_convert_init();
1092 evas_common_scale_init();
1093 evas_common_rectangle_init();
1094 evas_common_polygon_init();
1095 evas_common_line_init();
1096 evas_common_font_init();
1097 evas_common_draw_init();
1098 evas_common_tilebuf_init();
1101 if (eina_tls_new(&resource_key) == EINA_FALSE)
1102 ERR("Error creating tls key");
1103 DBG("TLS KEY create... %d", resource_key);
1110 re = e->engine.data.output;
1111 if (_re_wincheck(re))
1113 if ((re->info->info.display != re->win->disp) ||
1114 (re->info->info.drawable != re->win->win) ||
1115 (re->info->info.screen != re->win->screen) ||
1116 (re->info->info.visual != re->win->visual) ||
1117 (re->info->info.colormap != re->win->colormap) ||
1118 (re->info->info.depth != re->win->depth) ||
1119 (re->info->info.destination_alpha != re->win->alpha) ||
1120 (re->info->info.rotation != re->win->rot))
1126 re->win->gl_context->references++;
1127 eng_window_free(re->win);
1131 re->w = e->output.w;
1132 re->h = e->output.h;
1133 re->win = eng_window_new(re->info->info.display,
1134 re->info->info.drawable,
1135 re->info->info.screen,
1136 re->info->info.visual,
1137 re->info->info.colormap,
1138 re->info->info.depth,
1142 re->info->info.destination_alpha,
1143 re->info->info.rotation);
1144 eng_window_use(re->win);
1145 if (re->win) gl_wins++;
1146 if ((re->win) && (inc))
1147 re->win->gl_context->references--;
1149 else if ((re->win->w != e->output.w) ||
1150 (re->win->h != e->output.h))
1152 re->w = e->output.w;
1153 re->h = e->output.h;
1154 re->win->w = e->output.w;
1155 re->win->h = e->output.h;
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);
1167 if (!e->engine.data.output)
1171 eng_window_free(re->win);
1177 re->tb = evas_common_tilebuf_new(re->win->w, re->win->h);
1182 eng_window_free(re->win);
1188 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
1190 if (!e->engine.data.context)
1191 e->engine.data.context =
1192 e->engine.func->context_new(e->engine.data.output);
1193 eng_window_use(re->win);
1208 eng_output_free(void *data)
1212 re = (Render_Engine *)data;
1216 // NOTE: XrmGetDatabase() result is shared per connection, do not free it.
1217 // if (re->xrdb) XrmDestroyDatabase(re->xrdb);
1220 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1221 // Destroy the resource surface
1222 // Only required for EGL case
1224 eglDestroySurface(re->win->egl_disp, re->surface);
1227 // Destroy the resource context
1228 _destroy_internal_context(re, context);
1232 if ((initted == 1) && (gl_wins == 1))
1233 _destroy_internal_glue_resources(re);
1234 eng_window_free(re->win);
1237 evas_common_tilebuf_free(re->tb);
1240 if ((initted == 1) && (gl_wins == 0))
1242 evas_common_image_shutdown();
1243 evas_common_font_shutdown();
1249 eng_output_resize(void *data, int w, int h)
1253 re = (Render_Engine *)data;
1256 eng_window_use(re->win);
1257 evas_gl_common_context_resize(re->win->gl_context, w, h, re->win->rot);
1258 evas_common_tilebuf_free(re->tb);
1259 re->tb = evas_common_tilebuf_new(w, h);
1261 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
1265 eng_output_tile_size_set(void *data, int w, int h)
1269 re = (Render_Engine *)data;
1270 evas_common_tilebuf_set_tile_size(re->tb, w, h);
1274 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
1278 re = (Render_Engine *)data;
1279 eng_window_use(re->win);
1280 evas_gl_common_context_resize(re->win->gl_context, re->win->w, re->win->h, re->win->rot);
1281 evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
1283 RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, re->win->w, re->win->h);
1284 if ((w <= 0) || (h <= 0)) return;
1285 if (!re->win->draw.redraw)
1288 re->win->draw.x1 = x;
1289 re->win->draw.y1 = y;
1290 re->win->draw.x2 = x + w - 1;
1291 re->win->draw.y2 = y + h - 1;
1293 re->win->draw.x1 = 0;
1294 re->win->draw.y1 = 0;
1295 re->win->draw.x2 = re->win->w - 1;
1296 re->win->draw.y2 = re->win->h - 1;
1301 if (x < re->win->draw.x1) re->win->draw.x1 = x;
1302 if (y < re->win->draw.y1) re->win->draw.y1 = y;
1303 if ((x + w - 1) > re->win->draw.x2) re->win->draw.x2 = x + w - 1;
1304 if ((y + h - 1) > re->win->draw.y2) re->win->draw.y2 = y + h - 1;
1306 re->win->draw.redraw = 1;
1310 eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
1314 re = (Render_Engine *)data;
1315 evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
1319 eng_output_redraws_clear(void *data)
1323 re = (Render_Engine *)data;
1324 evas_common_tilebuf_clear(re->tb);
1325 /* re->win->draw.redraw = 0;*/
1326 // INF("GL: finish update cycle!");
1329 /* vsync games - not for now though */
1330 #define VSYNC_TO_SCREEN 1
1333 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
1336 Tilebuf_Rect *rects;
1338 re = (Render_Engine *)data;
1339 /* get the upate rect surface - return engine data as dummy */
1340 rects = evas_common_tilebuf_get_render_rects(re->tb);
1346 printf("REAAAAACCTS\n");
1347 EINA_INLIST_FOREACH(EINA_INLIST_GET(rects), r)
1349 printf(" %i %i %ix%i\n", r->x, r->y, r->w, r->h);
1352 evas_common_tilebuf_free_render_rects(rects);
1353 evas_common_tilebuf_clear(re->tb);
1354 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1355 // dont need to for egl - eng_window_use() can check for other ctxt's
1357 eng_window_use(NULL);
1359 eng_window_use(re->win);
1360 if (!_re_wincheck(re)) return NULL;
1361 evas_gl_common_context_flush(re->win->gl_context);
1362 evas_gl_common_context_newframe(re->win->gl_context);
1365 if (w) *w = re->win->w;
1366 if (h) *h = re->win->h;
1369 if (cw) *cw = re->win->w;
1370 if (ch) *ch = re->win->h;
1371 return re->win->gl_context->def_surface;
1375 if (!re->win->draw.redraw) return NULL;
1376 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1377 // dont need to for egl - eng_window_use() can check for other ctxt's
1379 eng_window_use(NULL);
1381 eng_window_use(re->win);
1382 if (!_re_wincheck(re)) return NULL;
1383 evas_gl_common_context_flush(re->win->gl_context);
1384 evas_gl_common_context_newframe(re->win->gl_context);
1385 if (x) *x = re->win->draw.x1;
1386 if (y) *y = re->win->draw.y1;
1387 if (w) *w = re->win->draw.x2 - re->win->draw.x1 + 1;
1388 if (h) *h = re->win->draw.y2 - re->win->draw.y1 + 1;
1389 if (cx) *cx = re->win->draw.x1;
1390 if (cy) *cy = re->win->draw.y1;
1391 if (cw) *cw = re->win->draw.x2 - re->win->draw.x1 + 1;
1392 if (ch) *ch = re->win->draw.y2 - re->win->draw.y1 + 1;
1393 return re->win->gl_context->def_surface;
1397 //#define FRAMECOUNT 1
1403 struct timeval timev;
1405 gettimeofday(&timev, NULL);
1406 return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
1410 static int safe_native = -1;
1413 eng_output_redraws_next_update_push(void *data, void *surface __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
1417 static double pt = 0.0;
1421 re = (Render_Engine *)data;
1422 /* put back update surface.. in this case just unflag redraw */
1423 if (!_re_wincheck(re)) return;
1424 re->win->draw.redraw = 0;
1425 re->win->draw.drew = 1;
1426 evas_gl_common_context_flush(re->win->gl_context);
1427 if (safe_native == -1)
1429 const char *s = getenv("EVAS_GL_SAFE_NATIVE");
1431 if (s) safe_native = atoi(s);
1434 s = (const char *)glGetString(GL_RENDERER);
1437 if (strstr(s, "PowerVR SGX 540") ||
1438 strstr(s, "Mali-400 MP"))
1443 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1444 // this is needed to make sure all previous rendering is flushed to
1447 double t0 = get_time();
1451 // previous rendering should be done and swapped
1452 if (!safe_native) eglWaitNative(EGL_CORE_NATIVE_ENGINE);
1454 double t1 = get_time();
1456 printf("... %1.5f -> %1.5f | ", ta, tb);
1458 // if (eglGetError() != EGL_SUCCESS)
1460 // printf("Error: eglWaitNative(EGL_CORE_NATIVE_ENGINE) fail.\n");
1463 // previous rendering should be done and swapped
1464 if (!safe_native) glXWaitX();
1466 //x// printf("frame -> push\n");
1470 eng_output_flush(void *data)
1474 re = (Render_Engine *)data;
1475 if (!_re_wincheck(re)) return;
1476 if (!re->win->draw.drew) return;
1477 //x// printf("frame -> flush\n");
1478 re->win->draw.drew = 0;
1479 eng_window_use(re->win);
1481 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1483 double t0 = get_time();
1487 if (re->info->vsync) eglSwapInterval(re->win->egl_disp, 1);
1488 else eglSwapInterval(re->win->egl_disp, 0);
1491 if (re->info->callback.pre_swap)
1493 re->info->callback.pre_swap(re->info->callback.data, re->evas);
1495 eglSwapBuffers(re->win->egl_disp, re->win->egl_surface[0]);
1496 if (!safe_native) eglWaitGL();
1497 if (re->info->callback.post_swap)
1499 re->info->callback.post_swap(re->info->callback.data, re->evas);
1502 double t1 = get_time();
1503 printf("%1.5f\n", t1 - t0);
1505 // if (eglGetError() != EGL_SUCCESS)
1507 // printf("Error: eglSwapBuffers() fail.\n");
1510 #ifdef VSYNC_TO_SCREEN
1511 if ((re->info->vsync)/* || (1)*/)
1513 if (glsym_glXSwapIntervalEXT)
1517 if (re->info->vsync) glsym_glXSwapIntervalEXT(re->win->disp, re->win->win, 1);
1518 else glsym_glXSwapIntervalEXT(re->win->disp, re->win->win, 0);
1522 if (glsym_glXSwapIntervalSGI)
1526 if (re->info->vsync) glsym_glXSwapIntervalSGI(1);
1527 else glsym_glXSwapIntervalSGI(0);
1533 if ((glsym_glXGetVideoSync) && (glsym_glXWaitVideoSync))
1537 glsym_glXGetVideoSync(&rc);
1538 glsym_glXWaitVideoSync(1, 0, &rc);
1543 if (re->info->callback.pre_swap)
1545 re->info->callback.pre_swap(re->info->callback.data, re->evas);
1550 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)))
1553 // double t, t2 = 0.0;
1555 glXSwapBuffers(re->win->disp, re->win->win);
1556 // t = get_time() - t;
1557 // if (!safe_native)
1561 // t2 = get_time() - t2;
1563 // printf("swap: %3.5f (%3.5fms), x wait gl: %3.5f (%3.5fms)\n",
1564 // t, t * 1000.0, t2, t2 * 1000.0);
1568 // FIXME: this doesn't work.. why oh why?
1571 sx = re->win->draw.x1;
1572 sy = re->win->draw.y1;
1573 sw = (re->win->draw.x2 - re->win->draw.x1) + 1;
1574 sh = (re->win->draw.y2 - re->win->draw.y1) + 1;
1575 sy = re->win->h - sy - sh;
1577 glBitmap(0, 0, 0, 0, sx, re->win->h - sy, NULL);
1578 glEnable(GL_SCISSOR_TEST);
1579 glScissor(sx, sy, sw, sh);
1580 glDrawBuffer(GL_FRONT);
1581 glCopyPixels(sx, sy, sw, sh, GL_COLOR);
1582 glDrawBuffer(GL_BACK);
1583 glDisable(GL_SCISSOR_TEST);
1584 glBitmap(0, 0, 0, 0, 0, 0, NULL);
1587 if (re->info->callback.post_swap)
1589 re->info->callback.post_swap(re->info->callback.data, re->evas);
1595 eng_output_idle_flush(void *data)
1599 re = (Render_Engine *)data;
1603 eng_output_dump(void *data)
1607 re = (Render_Engine *)data;
1608 evas_common_image_image_all_unload();
1609 evas_common_font_font_all_unload();
1610 evas_gl_common_image_all_unload(re->win->gl_context);
1615 eng_context_cutout_add(void *data __UNUSED__, void *context, int x, int y, int w, int h)
1617 // Render_Engine *re;
1619 // re = (Render_Engine *)data;
1620 // re->win->gl_context->dc = context;
1621 evas_common_draw_context_add_cutout(context, x, y, w, h);
1625 eng_context_cutout_clear(void *data __UNUSED__, void *context)
1627 // Render_Engine *re;
1629 // re = (Render_Engine *)data;
1630 // re->win->gl_context->dc = context;
1631 evas_common_draw_context_clear_cutouts(context);
1635 eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
1639 re = (Render_Engine *)data;
1640 eng_window_use(re->win);
1641 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
1642 re->win->gl_context->dc = context;
1643 evas_gl_common_rect_draw(re->win->gl_context, x, y, w, h);
1647 eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
1651 re = (Render_Engine *)data;
1652 eng_window_use(re->win);
1653 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
1654 re->win->gl_context->dc = context;
1655 evas_gl_common_line_draw(re->win->gl_context, x1, y1, x2, y2);
1659 eng_polygon_point_add(void *data, void *context __UNUSED__, void *polygon, int x, int y)
1663 re = (Render_Engine *)data;
1664 return evas_gl_common_poly_point_add(polygon, x, y);
1668 eng_polygon_points_clear(void *data, void *context __UNUSED__, void *polygon)
1672 re = (Render_Engine *)data;
1673 return evas_gl_common_poly_points_clear(polygon);
1677 eng_polygon_draw(void *data, void *context, void *surface __UNUSED__, void *polygon, int x, int y)
1681 re = (Render_Engine *)data;
1682 eng_window_use(re->win);
1683 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
1684 re->win->gl_context->dc = context;
1685 evas_gl_common_poly_draw(re->win->gl_context, polygon, x, y);
1689 eng_image_alpha_get(void *data __UNUSED__, void *image)
1691 // Render_Engine *re;
1694 // re = (Render_Engine *)data;
1695 if (!image) return 1;
1701 eng_image_colorspace_get(void *data __UNUSED__, void *image)
1703 // Render_Engine *re;
1706 // re = (Render_Engine *)data;
1707 if (!image) return EVAS_COLORSPACE_ARGB8888;
1709 return im->cs.space;
1713 eng_image_mask_create(void *data __UNUSED__, void *image)
1719 if (!im->im->image.data)
1720 evas_cache_image_load_data(&im->im->cache_entry);
1722 im->tex = evas_gl_common_texture_new(im->gc, im->im);
1727 eng_image_alpha_set(void *data, void *image, int has_alpha)
1732 re = (Render_Engine *)data;
1733 if (!image) return NULL;
1735 if (im->alpha == has_alpha) return image;
1736 if (im->native.data)
1738 im->alpha = has_alpha;
1741 eng_window_use(re->win);
1742 if ((im->tex) && (im->tex->pt->dyn.img))
1744 im->alpha = has_alpha;
1745 im->tex->alpha = im->alpha;
1748 /* FIXME: can move to gl_common */
1749 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
1750 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
1751 else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
1752 if (im->references > 1)
1754 Evas_GL_Image *im_new;
1756 im_new = evas_gl_common_image_new_from_copied_data
1757 (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
1759 eng_image_alpha_get(data, image),
1760 eng_image_colorspace_get(data, image));
1761 if (!im_new) return im;
1762 evas_gl_common_image_free(im);
1766 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1767 return evas_gl_common_image_alpha_set(im, has_alpha ? 1 : 0);
1768 // im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
1773 eng_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
1775 // Render_Engine *re;
1777 // re = (Render_Engine *)data;
1782 eng_image_border_get(void *data __UNUSED__, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
1784 // Render_Engine *re;
1786 // re = (Render_Engine *)data;
1790 eng_image_comment_get(void *data __UNUSED__, void *image, char *key __UNUSED__)
1792 // Render_Engine *re;
1795 // re = (Render_Engine *)data;
1796 if (!image) return NULL;
1798 if (!im->im) return NULL;
1799 return im->im->info.comment;
1803 eng_image_format_get(void *data __UNUSED__, void *image)
1805 // Render_Engine *re;
1808 // re = (Render_Engine *)data;
1814 eng_image_colorspace_set(void *data, void *image, int cspace)
1819 re = (Render_Engine *)data;
1822 if (im->native.data) return;
1823 /* FIXME: can move to gl_common */
1824 if (im->cs.space == cspace) return;
1825 eng_window_use(re->win);
1826 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
1829 case EVAS_COLORSPACE_ARGB8888:
1832 if (!im->cs.no_free) free(im->cs.data);
1837 case EVAS_COLORSPACE_YCBCR422P601_PL:
1838 case EVAS_COLORSPACE_YCBCR422P709_PL:
1839 case EVAS_COLORSPACE_YCBCR422601_PL:
1840 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
1841 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
1842 if (im->tex) evas_gl_common_texture_free(im->tex);
1846 if (!im->cs.no_free) free(im->cs.data);
1848 if (im->im->cache_entry.h > 0)
1850 calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
1859 im->cs.space = cspace;
1862 /////////////////////////////////////////////////////////////////////////
1865 typedef struct _Native Native;
1869 Evas_Native_Surface ns;
1873 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1881 // FIXME: this is enabled so updates happen - but its SLOOOOOOOOOOOOOOOW
1882 // (i am sure this is the reason) not to mention seemingly superfluous. but
1883 // i need to enable it for it to work on fglrx at least. havent tried nvidia.
1885 // why is this the case? does anyone know? has anyone tried it on other gfx
1888 //#define GLX_TEX_PIXMAP_RECREATE 1
1891 _native_bind_cb(void *data, void *image)
1893 Evas_GL_Image *im = image;
1894 Native *n = im->native.data;
1896 if (n->ns.type == EVAS_NATIVE_SURFACE_X11)
1898 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1901 if (glsym_glEGLImageTargetTexture2DOES)
1903 glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, n->egl_surface);
1904 if (eglGetError() != EGL_SUCCESS)
1905 ERR("glEGLImageTargetTexture2DOES() failed.");
1908 ERR("Try glEGLImageTargetTexture2DOES on EGL with no support");
1911 # ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1912 Render_Engine *re = data;
1914 if (glsym_glXBindTexImage)
1916 glsym_glXBindTexImage(re->win->disp, n->glx_pixmap,
1917 GLX_FRONT_LEFT_EXT, NULL);
1918 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1921 ERR("Try glXBindTexImage on GLX with no support");
1925 else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
1927 glBindTexture(GL_TEXTURE_2D, n->ns.data.opengl.texture_id);
1928 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1935 _native_unbind_cb(void *data, void *image)
1937 Evas_GL_Image *im = image;
1938 Native *n = im->native.data;
1940 if (n->ns.type == EVAS_NATIVE_SURFACE_X11)
1942 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1945 # ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1946 Render_Engine *re = data;
1948 if (glsym_glXReleaseTexImage)
1950 glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap,
1951 GLX_FRONT_LEFT_EXT);
1952 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1955 ERR("Try glXReleaseTexImage on GLX with no support");
1959 else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
1961 glBindTexture(GL_TEXTURE_2D, 0);
1962 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1969 _native_free_cb(void *data, void *image)
1971 Render_Engine *re = data;
1972 Evas_GL_Image *im = image;
1973 Native *n = im->native.data;
1974 uint32_t pmid, texid;
1976 if (n->ns.type == EVAS_NATIVE_SURFACE_X11)
1979 eina_hash_del(re->win->gl_context->shared->native_pm_hash, &pmid, im);
1980 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1983 if (glsym_eglDestroyImage)
1985 glsym_eglDestroyImage(re->win->egl_disp,
1987 if (eglGetError() != EGL_SUCCESS)
1988 ERR("eglDestroyImage() failed.");
1991 ERR("Try eglDestroyImage on EGL with no support");
1994 # ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1997 if (im->native.loose)
1999 if (glsym_glXReleaseTexImage)
2001 glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap,
2002 GLX_FRONT_LEFT_EXT);
2003 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2006 ERR("Try glXReleaseTexImage on GLX with no support");
2008 if (glsym_glXDestroyPixmap)
2010 glsym_glXDestroyPixmap(re->win->disp, n->glx_pixmap);
2011 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2014 ERR("Try glXDestroyPixmap on GLX with no support");
2020 else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
2022 texid = n->ns.data.opengl.texture_id;
2023 eina_hash_del(re->win->gl_context->shared->native_tex_hash, &texid, im);
2025 im->native.data = NULL;
2026 im->native.func.data = NULL;
2027 im->native.func.bind = NULL;
2028 im->native.func.unbind = NULL;
2029 im->native.func.free = NULL;
2034 eng_image_native_set(void *data, void *image, void *native)
2036 Render_Engine *re = (Render_Engine *)data;
2037 Evas_Native_Surface *ns = native;
2038 Evas_GL_Image *im = image, *im2 = NULL;
2042 uint32_t pmid, texid;
2043 unsigned int tex = 0;
2044 unsigned int fbo = 0;
2048 if ((!ns) && (ns->type == EVAS_NATIVE_SURFACE_OPENGL))
2050 im = evas_gl_common_image_new_from_data(re->win->gl_context,
2054 EVAS_COLORSPACE_ARGB8888);
2062 if (ns->type == EVAS_NATIVE_SURFACE_X11)
2064 vis = ns->data.x11.visual;
2065 pm = ns->data.x11.pixmap;
2066 if (im->native.data)
2068 Evas_Native_Surface *ens = im->native.data;
2069 if ((ens->data.x11.visual == vis) &&
2070 (ens->data.x11.pixmap == pm))
2074 else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
2076 tex = ns->data.opengl.texture_id;
2077 fbo = ns->data.opengl.framebuffer_id;
2078 if (im->native.data)
2080 Evas_Native_Surface *ens = im->native.data;
2081 if ((ens->data.opengl.texture_id == tex) &&
2082 (ens->data.opengl.framebuffer_id == fbo))
2087 if ((!ns) && (!im->native.data)) return im;
2089 eng_window_use(re->win);
2091 if (im->native.data)
2093 if (im->native.func.free)
2094 im->native.func.free(im->native.func.data, im);
2095 evas_gl_common_image_native_disable(im);
2100 if (ns->type == EVAS_NATIVE_SURFACE_X11)
2103 im2 = eina_hash_find(re->win->gl_context->shared->native_pm_hash, &pmid);
2104 if (im2 == im) return im;
2107 n = im2->native.data;
2110 evas_gl_common_image_ref(im2);
2111 evas_gl_common_image_free(im);
2116 else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
2119 im2 = eina_hash_find(re->win->gl_context->shared->native_tex_hash, &texid);
2120 if (im2 == im) return im;
2123 n = im2->native.data;
2126 evas_gl_common_image_ref(im2);
2127 evas_gl_common_image_free(im);
2133 im2 = evas_gl_common_image_new_from_data(re->win->gl_context,
2134 im->w, im->h, NULL, im->alpha,
2135 EVAS_COLORSPACE_ARGB8888);
2136 evas_gl_common_image_free(im);
2138 if (ns->type == EVAS_NATIVE_SURFACE_X11)
2140 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2143 n = calloc(1, sizeof(Native));
2146 EGLConfig egl_config;
2147 int config_attrs[20];
2148 int num_config, i = 0;
2150 eina_hash_add(re->win->gl_context->shared->native_pm_hash, &pmid, im);
2152 config_attrs[i++] = EGL_RED_SIZE;
2153 config_attrs[i++] = 8;
2154 config_attrs[i++] = EGL_GREEN_SIZE;
2155 config_attrs[i++] = 8;
2156 config_attrs[i++] = EGL_BLUE_SIZE;
2157 config_attrs[i++] = 8;
2158 config_attrs[i++] = EGL_ALPHA_SIZE;
2159 config_attrs[i++] = 8;
2160 config_attrs[i++] = EGL_DEPTH_SIZE;
2161 config_attrs[i++] = 0;
2162 config_attrs[i++] = EGL_STENCIL_SIZE;
2163 config_attrs[i++] = 0;
2164 config_attrs[i++] = EGL_RENDERABLE_TYPE;
2165 config_attrs[i++] = EGL_OPENGL_ES2_BIT;
2166 config_attrs[i++] = EGL_SURFACE_TYPE;
2167 config_attrs[i++] = EGL_PIXMAP_BIT;
2168 config_attrs[i++] = EGL_NONE;
2170 if (!eglChooseConfig(re->win->egl_disp, config_attrs,
2171 &egl_config, 1, &num_config))
2172 ERR("eglChooseConfig() failed for pixmap 0x%x, num_config = %i", (unsigned int)pm, num_config);
2173 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
2176 if (glsym_eglCreateImage)
2177 n->egl_surface = glsym_eglCreateImage(re->win->egl_disp,
2179 EGL_NATIVE_PIXMAP_KHR,
2183 ERR("Try eglCreateImage on EGL with no support");
2184 if (!n->egl_surface)
2185 ERR("eglCreatePixmapSurface() for 0x%x failed", (unsigned int)pm);
2186 im->native.yinvert = 1;
2187 im->native.loose = 0;
2188 im->native.data = n;
2189 im->native.func.data = re;
2190 im->native.func.bind = _native_bind_cb;
2191 im->native.func.unbind = _native_unbind_cb;
2192 im->native.func.free = _native_free_cb;
2193 im->native.target = GL_TEXTURE_2D;
2194 im->native.mipmap = 0;
2195 evas_gl_common_image_native_enable(im);
2199 # ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
2203 unsigned int w, h, depth = 32, border;
2206 // fixme: round trip :(
2207 XGetGeometry(re->win->disp, pm, &wdummy, &dummy, &dummy,
2208 &w, &h, &border, &depth);
2209 n = calloc(1, sizeof(Native));
2213 unsigned int target = 0;
2216 eina_hash_add(re->win->gl_context->shared->native_pm_hash, &pmid, im);
2217 if ((re->win->depth_cfg[depth].tex_target &
2218 GLX_TEXTURE_2D_BIT_EXT)
2219 // && (1) // we assume npo2 for now
2220 // size is pow2 || mnpo2 supported
2222 target = GLX_TEXTURE_2D_EXT;
2223 else if ((re->win->depth_cfg[depth].tex_target &
2224 GLX_TEXTURE_RECTANGLE_BIT_EXT))
2226 ERR("rect!!! (not handled)");
2227 target = GLX_TEXTURE_RECTANGLE_EXT;
2231 ERR("broken text-from-pixmap");
2232 if (!(re->win->depth_cfg[depth].tex_target &
2233 GLX_TEXTURE_2D_BIT_EXT))
2234 target = GLX_TEXTURE_RECTANGLE_EXT;
2235 else if (!(re->win->depth_cfg[depth].tex_target &
2236 GLX_TEXTURE_RECTANGLE_BIT_EXT))
2237 target = GLX_TEXTURE_2D_EXT;
2241 pixmap_att[i++] = GLX_TEXTURE_FORMAT_EXT;
2242 pixmap_att[i++] = re->win->depth_cfg[depth].tex_format;
2243 pixmap_att[i++] = GLX_MIPMAP_TEXTURE_EXT;
2244 pixmap_att[i++] = re->win->depth_cfg[depth].mipmap;
2248 pixmap_att[i++] = GLX_TEXTURE_TARGET_EXT;
2249 pixmap_att[i++] = target;
2252 pixmap_att[i++] = 0;
2254 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
2257 n->fbc = re->win->depth_cfg[depth].fbc;
2258 if (glsym_glXCreatePixmap)
2259 n->glx_pixmap = glsym_glXCreatePixmap(re->win->disp,
2264 ERR("Try glXCreatePixmap on GLX with no support");
2267 // printf("%p: new native texture for %x | %4i x %4i @ %2i = %p\n",
2268 // n, pm, w, h, depth, n->glx_pixmap);
2271 ERR("no target :(");
2272 if (glsym_glXQueryDrawable)
2273 glsym_glXQueryDrawable(re->win->disp,
2275 GLX_TEXTURE_TARGET_EXT,
2278 if (target == GLX_TEXTURE_2D_EXT)
2280 im->native.target = GL_TEXTURE_2D;
2281 im->native.mipmap = re->win->depth_cfg[depth].mipmap;
2283 # ifdef GL_TEXTURE_RECTANGLE_ARB
2284 else if (target == GLX_TEXTURE_RECTANGLE_EXT)
2286 im->native.target = GL_TEXTURE_RECTANGLE_ARB;
2287 im->native.mipmap = 0;
2292 im->native.target = GL_TEXTURE_2D;
2293 im->native.mipmap = 0;
2294 ERR("still unknown target");
2298 ERR("GLX Pixmap create fail");
2299 im->native.yinvert = re->win->depth_cfg[depth].yinvert;
2300 im->native.loose = re->win->detected.loose_binding;
2301 im->native.data = n;
2302 im->native.func.data = re;
2303 im->native.func.bind = _native_bind_cb;
2304 im->native.func.unbind = _native_unbind_cb;
2305 im->native.func.free = _native_free_cb;
2307 evas_gl_common_image_native_enable(im);
2313 else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
2317 n = calloc(1, sizeof(Native));
2320 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
2322 eina_hash_add(re->win->gl_context->shared->native_tex_hash, &texid, im);
2326 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2333 im->native.yinvert = 0;
2334 im->native.loose = 0;
2335 im->native.data = n;
2336 im->native.func.data = re;
2337 im->native.func.bind = _native_bind_cb;
2338 im->native.func.unbind = _native_unbind_cb;
2339 im->native.func.free = _native_free_cb;
2340 im->native.target = GL_TEXTURE_2D;
2341 im->native.mipmap = 0;
2343 // FIXME: need to implement mapping sub texture regions
2344 // x, y, w, h for possible texture atlasing
2346 evas_gl_common_image_native_enable(im);
2355 eng_image_native_get(void *data __UNUSED__, void *image)
2357 Evas_GL_Image *im = image;
2359 if (!im) return NULL;
2360 n = im->native.data;
2361 if (!n) return NULL;
2365 #if 0 // filtering disabled
2367 eng_image_draw_filtered(void *data, void *context, void *surface,
2368 void *image, Evas_Filter_Info *filter)
2370 Render_Engine *re = data;
2373 eng_window_use(re->win);
2374 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
2375 re->win->gl_context->dc = context;
2377 evas_gl_common_filter_draw(re->win->gl_context, image, filter);
2380 static Filtered_Image *
2381 eng_image_filtered_get(void *im, uint8_t *key, size_t keylen)
2383 return evas_gl_common_image_filtered_get(im, key, keylen);
2386 static Filtered_Image *
2387 eng_image_filtered_save(void *im, void *fim, uint8_t *key, size_t keylen)
2389 return evas_gl_common_image_filtered_save(im, fim, key, keylen);
2393 eng_image_filtered_free(void *im, Filtered_Image *fim)
2395 evas_gl_common_image_filtered_free(im, fim);
2402 /////////////////////////////////////////////////////////////////////////
2405 eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
2409 re = (Render_Engine *)data;
2410 *error = EVAS_LOAD_ERROR_NONE;
2411 eng_window_use(re->win);
2412 return evas_gl_common_image_load(re->win->gl_context, file, key, lo, error);
2416 eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
2420 re = (Render_Engine *)data;
2421 eng_window_use(re->win);
2422 return evas_gl_common_image_new_from_data(re->win->gl_context, w, h, image_data, alpha, cspace);
2426 eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
2430 re = (Render_Engine *)data;
2431 eng_window_use(re->win);
2432 return evas_gl_common_image_new_from_copied_data(re->win->gl_context, w, h, image_data, alpha, cspace);
2436 eng_image_free(void *data, void *image)
2440 re = (Render_Engine *)data;
2442 eng_window_use(re->win);
2443 evas_gl_common_image_free(image);
2447 eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
2455 if (w) *w = ((Evas_GL_Image *)image)->w;
2456 if (h) *h = ((Evas_GL_Image *)image)->h;
2460 eng_image_size_set(void *data, void *image, int w, int h)
2463 Evas_GL_Image *im = image;
2464 Evas_GL_Image *im_old;
2466 re = (Render_Engine *)data;
2467 if (!im) return NULL;
2468 if (im->native.data)
2474 eng_window_use(re->win);
2475 if ((im->tex) && (im->tex->pt->dyn.img))
2477 evas_gl_common_texture_free(im->tex);
2481 im->tex = evas_gl_common_texture_dynamic_new(im->gc, im);
2486 switch (eng_image_colorspace_get(data, image))
2488 case EVAS_COLORSPACE_YCBCR422P601_PL:
2489 case EVAS_COLORSPACE_YCBCR422P709_PL:
2490 case EVAS_COLORSPACE_YCBCR422601_PL:
2491 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
2492 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
2498 ((int)im_old->im->cache_entry.w == w) &&
2499 ((int)im_old->im->cache_entry.h == h))
2503 im = evas_gl_common_image_new(re->win->gl_context, w, h,
2504 eng_image_alpha_get(data, image),
2505 eng_image_colorspace_get(data, image));
2507 evas_common_load_image_data_from_file(im_old->im);
2508 if (im_old->im->image->data)
2510 evas_common_blit_rectangle(im_old->im, im->im, 0, 0, w, h, 0, 0);
2511 evas_common_cpu_end_opt();
2514 evas_gl_common_image_free(im_old);
2517 im = evas_gl_common_image_new(re->win->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
2522 eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
2525 Evas_GL_Image *im = image;
2527 re = (Render_Engine *)data;
2528 if (!image) return NULL;
2529 if (im->native.data) return image;
2530 eng_window_use(re->win);
2531 evas_gl_common_image_dirty(image, x, y, w, h);
2536 eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data, int *err)
2542 re = (Render_Engine *)data;
2546 if (err) *err = EVAS_LOAD_ERROR_GENERIC;
2550 if (im->native.data)
2553 if (err) *err = EVAS_LOAD_ERROR_NONE;
2557 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2558 eng_window_use(re->win);
2560 if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.img) && (im->cs.space == EVAS_COLORSPACE_ARGB8888))
2562 if (im->tex->pt->dyn.checked_out > 0)
2564 im->tex->pt->dyn.checked_out++;
2565 *image_data = im->tex->pt->dyn.data;
2566 if (err) *err = EVAS_LOAD_ERROR_NONE;
2569 *image_data = im->tex->pt->dyn.data = glsym_eglMapImageSEC(re->win->egl_disp, im->tex->pt->dyn.img);
2571 if (!im->tex->pt->dyn.data)
2573 if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
2574 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
2577 im->tex->pt->dyn.checked_out++;
2579 if (err) *err = EVAS_LOAD_ERROR_NONE;
2583 if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.data))
2585 *image_data = im->tex->pt->dyn.data;
2586 if (err) *err = EVAS_LOAD_ERROR_NONE;
2590 eng_window_use(re->win);
2593 /* Engine can be fail to create texture after cache drop like eng_image_content_hint_set function,
2594 so it is need to add code which check im->im's NULL value*/
2599 if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
2603 error = evas_cache_image_load_data(&im->im->cache_entry);
2604 switch (im->cs.space)
2606 case EVAS_COLORSPACE_ARGB8888:
2609 if (im->references > 1)
2611 Evas_GL_Image *im_new;
2613 im_new = evas_gl_common_image_new_from_copied_data
2614 (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
2616 eng_image_alpha_get(data, image),
2617 eng_image_colorspace_get(data, image));
2621 if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
2624 evas_gl_common_image_free(im);
2628 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
2630 *image_data = im->im->image.data;
2632 case EVAS_COLORSPACE_YCBCR422P601_PL:
2633 case EVAS_COLORSPACE_YCBCR422P709_PL:
2634 case EVAS_COLORSPACE_YCBCR422601_PL:
2635 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
2636 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
2637 *image_data = im->cs.data;
2643 if (err) *err = error;
2648 eng_image_data_put(void *data, void *image, DATA32 *image_data)
2651 Evas_GL_Image *im, *im2;
2653 re = (Render_Engine *)data;
2654 if (!image) return NULL;
2656 if (im->native.data) return image;
2657 eng_window_use(re->win);
2658 if ((im->tex) && (im->tex->pt)
2659 && (im->tex->pt->dyn.data)
2660 && (im->cs.space == EVAS_COLORSPACE_ARGB8888))
2662 if (im->tex->pt->dyn.data == image_data)
2664 if (im->tex->pt->dyn.checked_out > 0)
2666 im->tex->pt->dyn.checked_out--;
2667 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2668 if (im->tex->pt->dyn.checked_out == 0)
2669 glsym_eglUnmapImageSEC(re->win->egl_disp, im->tex->pt->dyn.img);
2675 im2 = eng_image_new_from_data(data, im->w, im->h, image_data,
2676 eng_image_alpha_get(data, image),
2677 eng_image_colorspace_get(data, image));
2678 if (!im2) return im;
2679 evas_gl_common_image_free(im);
2681 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
2684 switch (im->cs.space)
2686 case EVAS_COLORSPACE_ARGB8888:
2687 if ((!im->im) || (image_data != im->im->image.data))
2689 im2 = eng_image_new_from_data(data, im->w, im->h, image_data,
2690 eng_image_alpha_get(data, image),
2691 eng_image_colorspace_get(data, image));
2692 if (!im2) return im;
2693 evas_gl_common_image_free(im);
2697 case EVAS_COLORSPACE_YCBCR422P601_PL:
2698 case EVAS_COLORSPACE_YCBCR422P709_PL:
2699 case EVAS_COLORSPACE_YCBCR422601_PL:
2700 case EVAS_COLORSPACE_YCBCR420NV12601_PL:
2701 case EVAS_COLORSPACE_YCBCR420TM12601_PL:
2702 if (image_data != im->cs.data)
2706 if (!im->cs.no_free) free(im->cs.data);
2708 im->cs.data = image_data;
2710 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
2720 eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
2722 Evas_GL_Image *gim = image;
2726 if (gim->native.data) return;
2727 im = (RGBA_Image *)gim->im;
2729 evas_cache_image_preload_data(&im->cache_entry, target);
2733 eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
2735 Evas_GL_Image *gim = image;
2739 if (gim->native.data) return;
2740 im = (RGBA_Image *)gim->im;
2742 evas_cache_image_preload_cancel(&im->cache_entry, target);
2746 eng_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)
2749 re = (Render_Engine *)data;
2752 if ((gl_direct_img_obj) && (gl_direct_enabled))
2754 DBG("Rendering Directly to the window");
2755 evas_object_image_pixels_dirty_set(gl_direct_img_obj, EINA_TRUE);
2759 eng_window_use(re->win);
2760 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
2761 re->win->gl_context->dc = context;
2762 evas_gl_common_image_draw(re->win->gl_context, image,
2763 src_x, src_y, src_w, src_h,
2764 dst_x, dst_y, dst_w, dst_h,
2770 eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
2772 if (image) evas_gl_common_image_scale_hint_set(image, hint);
2776 eng_image_scale_hint_get(void *data __UNUSED__, void *image)
2778 Evas_GL_Image *gim = image;
2779 if (!gim) return EVAS_IMAGE_SCALE_HINT_NONE;
2780 return gim->scale_hint;
2784 eng_image_map_draw(void *data, void *context, void *surface, void *image, RGBA_Map *m, int smooth, int level)
2786 Evas_GL_Image *gim = image;
2789 re = (Render_Engine *)data;
2791 eng_window_use(re->win);
2792 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
2793 re->win->gl_context->dc = context;
2796 // FIXME: nash - you didn't fix this
2799 if ((m->pts[0].x == m->pts[3].x) &&
2800 (m->pts[1].x == m->pts[2].x) &&
2801 (m->pts[0].y == m->pts[1].y) &&
2802 (m->pts[3].y == m->pts[2].y) &&
2803 (m->pts[0].x <= m->pts[1].x) &&
2804 (m->pts[0].y <= m->pts[2].y) &&
2805 (m->pts[0].u == 0) &&
2806 (m->pts[0].v == 0) &&
2807 (m->pts[1].u == (gim->w << FP)) &&
2808 (m->pts[1].v == 0) &&
2809 (m->pts[2].u == (gim->w << FP)) &&
2810 (m->pts[2].v == (gim->h << FP)) &&
2811 (m->pts[3].u == 0) &&
2812 (m->pts[3].v == (gim->h << FP)) &&
2813 (m->pts[0].col == 0xffffffff) &&
2814 (m->pts[1].col == 0xffffffff) &&
2815 (m->pts[2].col == 0xffffffff) &&
2816 (m->pts[3].col == 0xffffffff))
2820 dx = m->pts[0].x >> FP;
2821 dy = m->pts[0].y >> FP;
2822 dw = (m->pts[2].x >> FP) - dx;
2823 dh = (m->pts[2].y >> FP) - dy;
2824 eng_image_draw(data, context, surface, image,
2825 0, 0, gim->w, gim->h, dx, dy, dw, dh, smooth);
2829 evas_gl_common_image_map_draw(re->win->gl_context, image, m->count, &m->pts[0],
2835 eng_image_map_clean(void *data, RGBA_Map *m)
2840 eng_image_map_surface_new(void *data, int w, int h, int alpha)
2844 re = (Render_Engine *)data;
2845 return evas_gl_common_image_surface_new(re->win->gl_context, w, h, alpha);
2849 eng_image_map_surface_free(void *data __UNUSED__, void *surface)
2851 evas_gl_common_image_free(surface);
2855 eng_image_content_hint_set(void *data __UNUSED__, void *image, int hint)
2857 if (image) evas_gl_common_image_content_hint_set(image, hint);
2861 eng_image_content_hint_get(void *data __UNUSED__, void *image)
2863 Evas_GL_Image *gim = image;
2864 if (!gim) return EVAS_IMAGE_CONTENT_HINT_NONE;
2865 return gim->content_hint;
2869 eng_image_cache_flush(void *data)
2874 re = (Render_Engine *)data;
2876 tmp_size = evas_common_image_get_cache();
2877 evas_common_image_set_cache(0);
2878 evas_common_rgba_image_scalecache_flush();
2879 evas_gl_common_image_cache_flush(re->win->gl_context);
2880 evas_common_image_set_cache(tmp_size);
2884 eng_image_cache_set(void *data, int bytes)
2888 re = (Render_Engine *)data;
2889 evas_common_image_set_cache(bytes);
2890 evas_common_rgba_image_scalecache_size_set(bytes);
2891 evas_gl_common_image_cache_flush(re->win->gl_context);
2895 eng_image_cache_get(void *data __UNUSED__)
2897 return evas_common_image_get_cache();
2901 eng_image_stride_get(void *data __UNUSED__, void *image, int *stride)
2903 Evas_GL_Image *im = image;
2905 if ((im->tex) && (im->tex->pt->dyn.img))
2906 *stride = im->tex->pt->dyn.stride;
2908 *stride = im->w * 4;
2912 eng_font_draw(void *data, void *context, void *surface, Evas_Font_Set *font __UNUSED__, int x, int y, int w __UNUSED__, int h __UNUSED__, int ow __UNUSED__, int oh __UNUSED__, Evas_Text_Props *intl_props)
2916 re = (Render_Engine *)data;
2917 eng_window_use(re->win);
2918 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
2919 re->win->gl_context->dc = context;
2921 // FIXME: put im into context so we can free it
2922 static RGBA_Image *im = NULL;
2925 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
2926 im->cache_entry.w = re->win->gl_context->shared->w;
2927 im->cache_entry.h = re->win->gl_context->shared->h;
2929 evas_common_draw_context_font_ext_set(context,
2930 re->win->gl_context,
2931 evas_gl_font_texture_new,
2932 evas_gl_font_texture_free,
2933 evas_gl_font_texture_draw);
2934 evas_common_font_draw_prepare(intl_props);
2935 evas_common_font_draw(im, context, x, y, intl_props);
2936 evas_common_draw_context_font_ext_set(context,
2945 eng_canvas_alpha_get(void *data, void *info __UNUSED__)
2947 Render_Engine *re = (Render_Engine *)data;
2948 return re->win->alpha;
2952 // Unfortunately, there is no query function to figure out which surface formats work.
2953 // So, this is one way to test for surface config capability.
2955 _check_gl_surface_format(GLint int_fmt, GLenum fmt, GLenum attachment, GLenum attach_fmt, int mult_samples)
2957 GLuint fbo, tex, rb, ds_tex;
2958 int w, h, fb_status;
2960 // Initialize Variables
2961 fbo = tex = rb = ds_tex = 0;
2963 // Width/Heith for test purposes
2967 glGenFramebuffers(1, &fbo);
2968 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2970 // Render Target Texture
2973 glGenTextures(1, &tex);
2974 glBindTexture(GL_TEXTURE_2D, tex );
2975 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2976 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2977 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2978 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2979 glTexImage2D(GL_TEXTURE_2D, 0, int_fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE, NULL);
2980 glBindTexture(GL_TEXTURE_2D, 0);
2983 glsym_glFramebufferTexture2DMultisample(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0, mult_samples);
2985 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
2988 // Render Target Attachment (Stencil or Depth)
2991 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2992 // This is a little hacky but this is how we'll have to do for now.
2993 if (attach_fmt == GL_DEPTH_STENCIL_OES)
2995 glGenTextures(1, &ds_tex);
2996 glBindTexture(GL_TEXTURE_2D, ds_tex);
2997 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2998 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2999 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3000 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3001 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, w, h,
3002 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, NULL);
3005 glsym_glFramebufferTexture2DMultisample(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3006 GL_TEXTURE_2D, ds_tex, 0, mult_samples);
3007 glsym_glFramebufferTexture2DMultisample(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
3008 GL_TEXTURE_2D, ds_tex, 0, mult_samples);
3012 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3013 GL_TEXTURE_2D, ds_tex, 0);
3014 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
3015 GL_TEXTURE_2D, ds_tex, 0);
3017 glBindTexture(GL_TEXTURE_2D, 0);
3022 glGenRenderbuffers(1, &rb);
3023 glBindRenderbuffer(GL_RENDERBUFFER, rb);
3025 glsym_glRenderbufferStorageMultisample(GL_RENDERBUFFER, mult_samples, attach_fmt, w, h);
3027 glRenderbufferStorage(GL_RENDERBUFFER, attach_fmt, w, h);
3028 glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, rb);
3029 glBindRenderbuffer(GL_RENDERBUFFER, 0);
3034 // Check FBO for completeness
3035 fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
3038 // Delete Created Resources
3039 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3040 if (fbo) glDeleteFramebuffers(1, &fbo);
3041 if (tex) glDeleteTextures(1, &tex);
3042 if (ds_tex) glDeleteTextures(1, &ds_tex);
3043 if (rb) glDeleteRenderbuffers(1, &rb);
3045 if (fb_status != GL_FRAMEBUFFER_COMPLETE)
3049 if ((attachment) && (!mult_samples))
3057 _print_gl_surface_info(Render_Engine_GL_Surface *sfc, int error)
3059 #define PRINT_LOG(...) \
3065 PRINT_LOG("----------Surface Info------------");
3066 PRINT_LOG(" [Surface] %x", (unsigned int)sfc);
3067 PRINT_LOG(" Width: %d", sfc->w);
3068 PRINT_LOG(" Height: %d", sfc->h);
3069 PRINT_LOG(" Direct Surface: %x", (unsigned int)sfc->direct_sfc);
3070 PRINT_LOG(" Current Context: %x", (unsigned int)sfc->current_ctx);
3071 PRINT_LOG(" [-------Config-------]");
3072 PRINT_LOG(" Depth Bits : %d", sfc->depth_bits);
3073 PRINT_LOG(" Stencil Bits : %d", sfc->stencil_bits);
3074 PRINT_LOG(" Direct FB Opt : %d", sfc->direct_fb_opt);
3075 PRINT_LOG(" Multisample Bits: %d", sfc->multisample_bits);
3076 PRINT_LOG(" MSAA Samples : %d", sfc->rt_msaa_samples);
3077 PRINT_LOG(" [-------Internal-----]");
3078 PRINT_LOG(" RenderTarget Texture : %d", sfc->rt_tex);
3079 PRINT_LOG(" RenderTarget Internal Format : %x", sfc->rt_internal_fmt);
3080 PRINT_LOG(" RenderTaret Format : %x", sfc->rt_fmt);
3081 PRINT_LOG(" RenderBuffer Depth : %x", sfc->rb_depth);
3082 PRINT_LOG(" RenderBuffer Depth Format : %x", sfc->rb_depth_fmt);
3083 PRINT_LOG(" RenderBuffer Stencil : %d", sfc->rb_stencil);
3084 PRINT_LOG(" RenderBuffer Stencil Format : %x", sfc->rb_stencil_fmt);
3085 PRINT_LOG(" RenderBuffer Depth Stencil : %x", sfc->rb_depth_stencil);
3086 PRINT_LOG(" RenderBuffer Depth Stencil Format: %x", sfc->rb_depth_stencil_fmt);
3087 PRINT_LOG("--------------------------------------");
3093 _print_gl_surface_cap(Render_Engine *re, int error)
3095 #define PRINT_LOG(...) \
3101 PRINT_LOG("----------------------------------------------------");
3102 PRINT_LOG(" EvasGL Supported Surface Format ");
3104 PRINT_LOG(" [Max Renderbuffer Size] : %d", re->gl_cap.max_rb_size);
3105 PRINT_LOG(" [Multisample Support ] : %d", re->gl_cap.msaa_support);
3106 PRINT_LOG(" [Low Samples] : %d", re->gl_cap.msaa_samples[1]);
3107 PRINT_LOG(" [Med Samples] : %d", re->gl_cap.msaa_samples[2]);
3108 PRINT_LOG(" [High Samples] : %d", re->gl_cap.msaa_samples[3]);
3109 PRINT_LOG(" [--Multisamples--] ");
3110 PRINT_LOG(" [Norm] [Low] [Med] [High]");
3111 PRINT_LOG(" [RGB Format] : %4x %d %d %d", re->gl_cap.rgb_888[0], re->gl_cap.rgb_888[1], re->gl_cap.rgb_888[2], re->gl_cap.rgb_888[3]);
3112 PRINT_LOG(" [RGBA Format] : %4x %d %d %d", re->gl_cap.rgba_8888[0], re->gl_cap.rgba_8888[1], re->gl_cap.rgba_8888[2], re->gl_cap.rgba_8888[3]);
3113 PRINT_LOG(" [Depth 8 Bits] : %4x %d %d %d", re->gl_cap.depth_8[0], re->gl_cap.depth_8[1], re->gl_cap.depth_8[2], re->gl_cap.depth_8[3]);
3114 PRINT_LOG(" [Depth 16 Bits] : %4x %d %d %d", re->gl_cap.depth_16[0], re->gl_cap.depth_16[1], re->gl_cap.depth_16[2], re->gl_cap.depth_16[3]);
3115 PRINT_LOG(" [Depth 24 Bits] : %4x %d %d %d", re->gl_cap.depth_24[0], re->gl_cap.depth_24[1], re->gl_cap.depth_24[2], re->gl_cap.depth_24[3]);
3116 PRINT_LOG(" [Depth 32 Bits] : %4x %d %d %d", re->gl_cap.depth_32[0], re->gl_cap.depth_32[1], re->gl_cap.depth_32[2], re->gl_cap.depth_32[3]);
3117 PRINT_LOG(" [Stencil 1 Bits] : %4x %d %d %d", re->gl_cap.stencil_1[0], re->gl_cap.stencil_1[1], re->gl_cap.stencil_1[2], re->gl_cap.stencil_1[3]);
3118 PRINT_LOG(" [Stencil 2 Bits] : %4x %d %d %d", re->gl_cap.stencil_2[0], re->gl_cap.stencil_2[1], re->gl_cap.stencil_2[2], re->gl_cap.stencil_2[3]);
3119 PRINT_LOG(" [Stencil 4 Bits] : %4x %d %d %d", re->gl_cap.stencil_4[0], re->gl_cap.stencil_4[1], re->gl_cap.stencil_4[2], re->gl_cap.stencil_4[3]);
3120 PRINT_LOG(" [Stencil 8 Bits] : %4x %d %d %d", re->gl_cap.stencil_8[0], re->gl_cap.stencil_8[1], re->gl_cap.stencil_8[2], re->gl_cap.stencil_8[3]);
3121 PRINT_LOG(" [Stencil 16 Bits] : %4x %d %d %d", re->gl_cap.stencil_16[0], re->gl_cap.stencil_16[1], re->gl_cap.stencil_16[2], re->gl_cap.stencil_16[3]);
3122 PRINT_LOG(" [Depth 24 Stencil 8 Bits]: %4x %d %d %d", re->gl_cap.depth_24_stencil_8[0], re->gl_cap.depth_24_stencil_8[1], re->gl_cap.depth_24_stencil_8[2], re->gl_cap.depth_24_stencil_8[3]);
3123 PRINT_LOG("----------------------------------------------------");
3128 _set_gl_surface_cap(Render_Engine *re)
3130 GLuint fbo, tex, depth, stencil;
3136 if (re->gl_cap_initted) return;
3138 // Width/Heith for test purposes
3141 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3142 int max_samples = 0;
3144 glGetIntegerv(GL_MAX_SAMPLES_IMG, &max_samples);
3146 // Check if msaa_support is supported
3147 if ((max_samples) &&
3148 (glsym_glFramebufferTexture2DMultisample) &&
3149 (glsym_glRenderbufferStorageMultisample))
3151 re->gl_cap.msaa_support = 1;
3153 re->gl_cap.msaa_samples[3] = max_samples;
3154 re->gl_cap.msaa_samples[2] = max_samples/2;
3155 re->gl_cap.msaa_samples[1] = max_samples/4;
3156 re->gl_cap.msaa_samples[0] = 0;
3158 if (!re->gl_cap.msaa_samples[2]) re->gl_cap.msaa_samples[3];
3159 if (!re->gl_cap.msaa_samples[1]) re->gl_cap.msaa_samples[2];
3163 re->gl_cap.msaa_support = 0;
3168 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &re->gl_cap.max_rb_size);
3170 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3171 count = (re->gl_cap.msaa_support) ? 4 : 1;
3173 for (i = 0; i < count; i++)
3175 re->gl_cap.rgb_888[i] = _check_gl_surface_format(GL_RGB, GL_RGB, 0, 0, re->gl_cap.msaa_samples[i]);
3176 re->gl_cap.rgba_8888[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, 0, 0, re->gl_cap.msaa_samples[i]);
3178 re->gl_cap.depth_8[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT, re->gl_cap.msaa_samples[i]);
3179 re->gl_cap.depth_16[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16, re->gl_cap.msaa_samples[i]);
3180 re->gl_cap.depth_24[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT24_OES, re->gl_cap.msaa_samples[i]);
3181 re->gl_cap.depth_32[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT32_OES, re->gl_cap.msaa_samples[i]);
3183 re->gl_cap.stencil_1[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX1_OES, re->gl_cap.msaa_samples[i]);
3184 re->gl_cap.stencil_4[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX4_OES, re->gl_cap.msaa_samples[i]);
3185 re->gl_cap.stencil_8[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8, re->gl_cap.msaa_samples[i]);
3187 re->gl_cap.depth_24_stencil_8[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_STENCIL_OES, GL_DEPTH_STENCIL_OES, re->gl_cap.msaa_samples[i]);
3191 count = (re->gl_cap.msaa_support) ? 4 : 1;
3193 for (i = 0; i < count; i++)
3195 re->gl_cap.rgb_888[i] = _check_gl_surface_format(GL_RGB, GL_RGB, 0, 0, re->gl_cap.msaa_samples[i]);
3196 re->gl_cap.rgba_8888[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, 0, 0, re->gl_cap.msaa_samples[i]);
3198 re->gl_cap.depth_8[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT, re->gl_cap.msaa_samples[i]);
3199 re->gl_cap.depth_16[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT16, re->gl_cap.msaa_samples[i]);
3200 re->gl_cap.depth_24[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT24, re->gl_cap.msaa_samples[i]);
3201 re->gl_cap.depth_32[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT32, re->gl_cap.msaa_samples[i]);
3203 re->gl_cap.stencil_1[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX1, re->gl_cap.msaa_samples[i]);
3204 re->gl_cap.stencil_4[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX4, re->gl_cap.msaa_samples[i]);
3205 re->gl_cap.stencil_8[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8, re->gl_cap.msaa_samples[i]);
3207 re->gl_cap.depth_24_stencil_8[i] = _check_gl_surface_format(GL_RGBA, GL_RGBA, GL_DEPTH_STENCIL_ATTACHMENT, GL_DEPTH24_STENCIL8, re->gl_cap.msaa_samples[i]);
3211 _print_gl_surface_cap(re, 0);
3213 re->gl_cap_initted = 1;
3217 _set_internal_config(Render_Engine *re, Render_Engine_GL_Surface *sfc, Evas_GL_Config *cfg)
3219 // Check if color formats are supported
3220 switch((int)cfg->color_format)
3222 case EVAS_GL_RGB_888:
3223 if (re->gl_cap.rgb_888[0])
3225 sfc->rt_fmt = GL_RGB;
3226 sfc->rt_internal_fmt = GL_RGB;
3229 case EVAS_GL_RGBA_8888:
3230 if (re->gl_cap.rgba_8888[0])
3232 sfc->rt_fmt = GL_RGBA;
3233 sfc->rt_internal_fmt = GL_RGBA;
3234 cfg->color_format = EVAS_GL_RGBA_8888;
3238 ERR("Color Format Not Supported: %d", cfg->color_format);
3239 _print_gl_surface_cap(re, 1);
3243 switch((int)cfg->depth_bits)
3245 case EVAS_GL_DEPTH_NONE:
3247 case EVAS_GL_DEPTH_BIT_8:
3248 if (re->gl_cap.depth_8[0])
3250 sfc->rb_depth_fmt = re->gl_cap.depth_8[0];
3251 cfg->depth_bits = EVAS_GL_DEPTH_BIT_8;
3254 case EVAS_GL_DEPTH_BIT_16:
3255 if (re->gl_cap.depth_16[0])
3257 sfc->rb_depth_fmt = re->gl_cap.depth_16[0];
3258 cfg->depth_bits = EVAS_GL_DEPTH_BIT_16;
3261 case EVAS_GL_DEPTH_BIT_24:
3262 if (re->gl_cap.depth_24[0])
3264 sfc->rb_depth_fmt = re->gl_cap.depth_24[0];
3265 cfg->depth_bits = EVAS_GL_DEPTH_BIT_24;
3268 else if (re->gl_cap.depth_24_stencil_8[0])
3270 sfc->rb_depth_stencil_fmt = re->gl_cap.depth_24_stencil_8[0];
3271 sfc->rb_depth_fmt = re->gl_cap.depth_24_stencil_8[0];
3272 cfg->depth_bits = EVAS_GL_DEPTH_BIT_24;
3275 case EVAS_GL_DEPTH_BIT_32:
3276 if (re->gl_cap.depth_32[0])
3278 sfc->rb_depth_fmt = re->gl_cap.depth_32[0];
3279 cfg->depth_bits = EVAS_GL_DEPTH_BIT_32;
3283 ERR("Unsupported Depth Bits Format: %d", cfg->depth_bits);
3284 _print_gl_surface_cap(re, 1);
3288 switch((int)cfg->stencil_bits)
3290 case EVAS_GL_STENCIL_NONE:
3292 case EVAS_GL_STENCIL_BIT_1:
3293 if (re->gl_cap.stencil_1[0])
3295 sfc->rb_stencil_fmt = re->gl_cap.stencil_1[0];
3296 cfg->stencil_bits = EVAS_GL_STENCIL_BIT_1;
3299 case EVAS_GL_STENCIL_BIT_2:
3300 if (re->gl_cap.stencil_2[0])
3302 sfc->rb_stencil_fmt = re->gl_cap.stencil_2[0];
3303 cfg->stencil_bits = EVAS_GL_STENCIL_BIT_2;
3306 case EVAS_GL_STENCIL_BIT_4:
3307 if (re->gl_cap.stencil_4[0])
3309 sfc->rb_stencil_fmt = re->gl_cap.stencil_4[0];
3310 cfg->stencil_bits = EVAS_GL_STENCIL_BIT_4;
3313 case EVAS_GL_STENCIL_BIT_8:
3314 if ((sfc->rb_depth_fmt == re->gl_cap.depth_24_stencil_8[0]) ||
3315 (sfc->rb_depth_fmt == re->gl_cap.depth_24[0]) ||
3316 (!(re->gl_cap.stencil_8[0]) && (re->gl_cap.depth_24_stencil_8[0])))
3318 sfc->rb_depth_stencil_fmt = re->gl_cap.depth_24_stencil_8[0];
3319 sfc->rb_stencil_fmt = re->gl_cap.depth_24_stencil_8[0];
3320 cfg->stencil_bits = EVAS_GL_STENCIL_BIT_8;
3323 else if (re->gl_cap.stencil_8[0])
3325 sfc->rb_stencil_fmt = re->gl_cap.stencil_8[0];
3326 cfg->stencil_bits = EVAS_GL_STENCIL_BIT_8;
3329 case EVAS_GL_STENCIL_BIT_16:
3330 if (re->gl_cap.stencil_16[0])
3332 sfc->rb_stencil_fmt = re->gl_cap.stencil_16[0];
3333 cfg->stencil_bits = EVAS_GL_STENCIL_BIT_16;
3337 ERR("Unsupported Stencil Bits Format: %d", cfg->stencil_bits);
3338 _print_gl_surface_cap(re, 1);
3342 if (cfg->options_bits)
3344 if (cfg->options_bits & EVAS_GL_OPTIONS_DIRECT)
3346 sfc->direct_fb_opt = 1;
3347 DBG("########################################################");
3348 DBG("######### [Evas] Direct option bit is enabled ##########");
3349 DBG("########################################################");
3351 // Add other options here...
3355 if (re->gl_cap.msaa_support)
3357 if ( ((int)(cfg->multisample_bits) > (int)EVAS_GL_MULTISAMPLE_HIGH) ||
3358 ((int)(cfg->multisample_bits) < 0) )
3360 ERR("Unsupported Multisample Bits Format!");
3361 _print_gl_surface_cap(re, 1);
3366 sfc->rt_msaa_samples = re->gl_cap.msaa_samples[(int)cfg->multisample_bits];
3374 _attach_fbo_surface(Render_Engine *data __UNUSED__,
3375 Render_Engine_GL_Surface *sfc,
3378 int fb_status, curr_tex, curr_rb;
3380 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3382 // Detach any previously attached buffers
3383 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
3384 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
3385 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
3386 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3387 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
3388 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
3390 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
3394 // Render Target Texture
3398 glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_tex);
3399 glBindTexture(GL_TEXTURE_2D, sfc->rt_tex );
3400 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3401 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3403 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3404 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sfc->w, sfc->h, 0,
3405 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
3406 glBindTexture(GL_TEXTURE_2D, curr_tex);
3408 // Attach texture to FBO
3409 if (sfc->rt_msaa_samples)
3410 glsym_glFramebufferTexture2DMultisample(GL_FRAMEBUFFER,
3411 GL_COLOR_ATTACHMENT0,
3412 GL_TEXTURE_2D, sfc->rt_tex,
3413 0, sfc->rt_msaa_samples);
3415 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
3416 GL_TEXTURE_2D, sfc->rt_tex, 0);
3420 // Depth Stencil RenderBuffer - Attach it to FBO
3421 if (sfc->rb_depth_stencil)
3423 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3425 glGetIntegerv(GL_TEXTURE_BINDING_2D, &curr_tex);
3426 glBindTexture(GL_TEXTURE_2D, sfc->rb_depth_stencil);
3427 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3428 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3429 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3430 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3431 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_STENCIL_OES, sfc->w, sfc->h,
3432 0, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, NULL);
3433 if (sfc->rt_msaa_samples)
3435 glsym_glFramebufferTexture2DMultisample(GL_FRAMEBUFFER,
3436 GL_DEPTH_ATTACHMENT,
3438 sfc->rb_depth_stencil,
3439 0, sfc->rt_msaa_samples);
3440 glsym_glFramebufferTexture2DMultisample(GL_FRAMEBUFFER,
3441 GL_STENCIL_ATTACHMENT,
3443 sfc->rb_depth_stencil,
3444 0, sfc->rt_msaa_samples);
3448 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3449 GL_TEXTURE_2D, sfc->rb_depth_stencil, 0);
3450 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
3451 GL_TEXTURE_2D, sfc->rb_depth_stencil, 0);
3453 glBindTexture(GL_TEXTURE_2D, curr_tex);
3457 glGetIntegerv(GL_RENDERBUFFER_BINDING, &curr_rb);
3458 glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth_stencil);
3459 glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_depth_stencil_fmt,
3461 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
3462 GL_RENDERBUFFER, sfc->rb_depth_stencil);
3463 glBindRenderbuffer(GL_RENDERBUFFER, curr_rb);
3467 // Depth RenderBuffer - Attach it to FBO
3471 glGetIntegerv(GL_RENDERBUFFER_BINDING, &curr_rb);
3473 glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth);
3475 if (sfc->rt_msaa_samples)
3476 glsym_glRenderbufferStorageMultisample(GL_RENDERBUFFER,
3477 sfc->rt_msaa_samples,
3481 glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_depth_fmt,
3483 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3484 GL_RENDERBUFFER, sfc->rb_depth);
3485 glBindRenderbuffer(GL_RENDERBUFFER, curr_rb);
3488 // Stencil RenderBuffer - Attach it to FBO
3489 if (sfc->rb_stencil)
3492 glGetIntegerv(GL_RENDERBUFFER_BINDING, &curr_rb);
3494 glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_stencil);
3496 if (sfc->rt_msaa_samples)
3497 glsym_glRenderbufferStorageMultisample(GL_RENDERBUFFER,
3498 sfc->rt_msaa_samples,
3499 sfc->rb_stencil_fmt,
3502 glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_stencil_fmt,
3504 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
3505 GL_RENDERBUFFER, sfc->rb_stencil);
3506 glBindRenderbuffer(GL_RENDERBUFFER, curr_rb);
3509 // Check FBO for completeness
3510 fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
3511 if (fb_status != GL_FRAMEBUFFER_COMPLETE)
3513 ERR("FBO not complete. Error Code: %x!", fb_status);
3514 _print_gl_surface_info(sfc, 1);
3522 _create_rt_buffers(Render_Engine *data __UNUSED__,
3523 Render_Engine_GL_Surface *sfc)
3526 GLuint fbo = 0, curr_fbo = 0;
3528 //------------------------------------//
3529 // Render Target texture
3532 glGenTextures(1, &sfc->rt_tex);
3535 // First check if packed buffer is to be used.
3536 if (sfc->rb_depth_stencil_fmt)
3538 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3539 glGenTextures(1, &sfc->rb_depth_stencil);
3541 glGenRenderbuffers(1, &sfc->rb_depth_stencil);
3546 // Depth RenderBuffer - Create storage here...
3547 if (sfc->rb_depth_fmt)
3548 glGenRenderbuffers(1, &sfc->rb_depth);
3550 // Stencil RenderBuffer - Create Storage here...
3551 if (sfc->rb_stencil_fmt)
3552 glGenRenderbuffers(1, &sfc->rb_stencil);
3554 //------------------------------------//
3555 // Try attaching the given configuration
3556 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &curr_fbo);
3557 glGenFramebuffers(1 ,&fbo);
3559 ret = _attach_fbo_surface(NULL, sfc, fbo);
3561 if (fbo) glDeleteFramebuffers(1, &fbo);
3562 glBindFramebuffer(GL_FRAMEBUFFER, curr_fbo);
3566 if (sfc->rt_tex) glDeleteTextures(1, &sfc->rt_tex);
3567 if (sfc->rb_depth) glDeleteRenderbuffers(1, &sfc->rb_depth);
3568 if (sfc->rb_stencil) glDeleteRenderbuffers(1, &sfc->rb_stencil);
3569 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3570 if (sfc->rb_depth_stencil) glDeleteTextures(1, &sfc->rb_depth_stencil);
3572 if (sfc->rb_depth_stencil) glDeleteRenderbuffers(1, &sfc->rb_depth_stencil);
3574 ERR("_attach_fbo_surface() failed.");
3583 eng_gl_surface_create(void *data, void *config, int w, int h)
3586 Render_Engine_GL_Surface *sfc;
3587 Render_Engine_GL_Resource *rsc;
3588 Evas_GL_Config *cfg;
3592 re = (Render_Engine *)data;
3593 cfg = (Evas_GL_Config *)config;
3595 // Allocate surface and fill in values
3596 sfc = calloc(1, sizeof(Render_Engine_GL_Surface));
3599 ERR("Surface allocation failed.");
3605 sfc->depth_bits = cfg->depth_bits;
3606 sfc->stencil_bits = cfg->stencil_bits;
3608 // Allow alpha for evas gl direct rendering override
3609 // FIXME!!!: A little out of place but for now...
3610 if (!gl_direct_override)
3611 if (getenv("EVAS_GL_DIRECT_OVERRIDE")) gl_direct_override = 1;
3613 // Set the internal format based on the config
3614 if (cfg->options_bits & EVAS_GL_OPTIONS_DIRECT)
3616 DBG("Enabling Direct rendering to the Evas' window.");
3617 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3618 sfc->direct_sfc = re->win->egl_surface[0];
3620 sfc->direct_sfc = re->win->win;
3624 // Use resource surface/context to do a make current
3625 if (!_internal_resources_make_current(re))
3627 ERR("Error doing a make current with the internal resources.");
3631 // Set the engine surface capability first if it hasn't been set
3632 if (!re->gl_cap_initted) _set_gl_surface_cap(re);
3634 // Check the size of the surface
3635 if ( (w > re->gl_cap.max_rb_size) || (h > re->gl_cap.max_rb_size) )
3637 ERR("Surface size greater than the supported size. Max Surface Size: %d", re->gl_cap.max_rb_size);
3641 // Set the internal config value
3642 if (!_set_internal_config(re, sfc, cfg))
3644 ERR("Unsupported Format!");
3648 // Create Render texture
3649 if (!_create_rt_buffers(re, sfc))
3651 ERR("Unable Create Specificed Surfaces. Unsupported format!");
3659 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3660 res = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
3662 res = glXMakeCurrent(re->info->info.display, None, NULL);
3666 ERR("xxxMakeCurrent() (NULL, NULL) Error!");
3677 eng_gl_surface_destroy(void *data, void *surface)
3680 Render_Engine_GL_Surface *sfc;
3681 Render_Engine_GL_Resource *rsc;
3684 re = (Render_Engine *)data;
3685 sfc = (Render_Engine_GL_Surface*)surface;
3689 // Use resource surface/context to create surface resrouces
3690 if (!_internal_resources_make_current(re))
3692 ERR("Error doing a make current with the internal resources.");
3696 // Reset the Framebuffer binding point
3697 if ((current_evgl_ctx) && (current_evgl_ctx->current_fbo == current_evgl_ctx->context_fbo))
3699 //glBindFramebuffer(GL_FRAMEBUFFER, 0);
3700 current_evgl_ctx->current_fbo = 0;
3701 current_evgl_ctx->current_sfc = NULL;
3704 // Clear direct rendering flag
3705 gl_direct_enabled = 0;
3707 // Delete FBO/RBO and Texture here
3709 glDeleteTextures(1, &sfc->rt_tex);
3712 glDeleteRenderbuffers(1, &sfc->rb_depth);
3714 if (sfc->rb_stencil)
3715 glDeleteRenderbuffers(1, &sfc->rb_stencil);
3717 if (sfc->rb_depth_stencil)
3719 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3720 glDeleteTextures(1, &sfc->rb_depth_stencil);
3722 glDeleteRenderbuffers(1, &sfc->rb_depth_stencil);
3727 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3728 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
3730 ret = glXMakeCurrent(re->info->info.display, None, NULL);
3734 ERR("xxxMakeCurrent() failed!");
3746 eng_gl_context_create(void *data, void *share_context)
3749 Render_Engine_GL_Context *ctx;
3750 Render_Engine_GL_Context *share_ctx;
3751 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3752 int context_attrs[3];
3755 ctx = calloc(1, sizeof(Render_Engine_GL_Context));
3757 if (!ctx) return NULL;
3759 re = (Render_Engine *)data;
3760 share_ctx = (Render_Engine_GL_Context *)share_context;
3762 // Set the share context to Evas' GL context if share_context is NULL.
3763 // Otherwise set it to the given share_context.
3764 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3766 context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
3767 context_attrs[1] = 2;
3768 context_attrs[2] = EGL_NONE;
3772 ctx->context = eglCreateContext(re->win->egl_disp,
3773 re->win->egl_config,
3774 share_ctx->context, // Share Context
3779 ctx->context = eglCreateContext(re->win->egl_disp,
3780 re->win->egl_config,
3781 re->win->egl_context[0], // Evas' GL Context
3787 ERR("eglCreateContext() fail. code=%#x", eglGetError());
3794 ctx->context = glXCreateContext(re->info->info.display,
3795 re->win->visualinfo,
3796 share_ctx->context, // Share Context
3801 ctx->context = glXCreateContext(re->info->info.display,
3802 re->win->visualinfo,
3803 re->win->context, // Evas' GL Context
3809 ERR("glXCreateContext() fail.");
3814 ctx->initialized = 0;
3815 ctx->context_fbo = 0;
3816 ctx->current_sfc = NULL;
3822 eng_gl_context_destroy(void *data, void *context)
3825 Render_Engine_GL_Context *ctx;
3826 Render_Engine_GL_Resource *rsc;
3829 re = (Render_Engine *)data;
3830 ctx = (Render_Engine_GL_Context*)context;
3834 // Use resource surface/context to create surface resrouces
3835 if (!_internal_resources_make_current(re))
3837 ERR("Error doing a make current with the internal resources.");
3842 if (ctx->context_fbo)
3843 glDeleteFramebuffers(1, &ctx->context_fbo);
3845 // Destroy the Context
3846 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3847 eglDestroyContext(re->win->egl_disp, ctx->context);
3849 ctx->context = EGL_NO_CONTEXT;
3851 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE,
3852 EGL_NO_SURFACE, EGL_NO_CONTEXT);
3854 glXDestroyContext(re->info->info.display, ctx->context);
3858 ret = glXMakeCurrent(re->info->info.display, None, NULL);
3862 ERR("xxxMakeCurrent() failed!");
3873 eng_gl_make_current(void *data __UNUSED__, void *surface, void *context)
3876 Render_Engine_GL_Surface *sfc;
3877 Render_Engine_GL_Context *ctx;
3879 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3880 Render_Engine_GL_Resource *rsc;
3883 re = (Render_Engine *)data;
3884 sfc = (Render_Engine_GL_Surface*)surface;
3885 ctx = (Render_Engine_GL_Context*)context;
3887 current_engine = re;
3889 // Unset surface/context
3890 if ((!sfc) || (!ctx))
3892 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3893 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE,
3894 EGL_NO_SURFACE, EGL_NO_CONTEXT);
3896 ret = glXMakeCurrent(re->info->info.display, None, NULL);
3900 ERR("xxxMakeCurrent() failed!");
3904 if (ctx) ctx->current_sfc = NULL;
3905 if (sfc) sfc->current_ctx = NULL;
3906 current_evgl_ctx = NULL;
3910 // Check if direct rendering is possible:
3911 // It's possible when direct_fb_opt is on and either current image
3912 // object is valid or gl_direct_override is on. Override allows
3913 // rendering outside of pixel getter but it doesn't guarantee
3914 // correct rendering.
3915 if ((sfc->direct_fb_opt) && (gl_direct_img_obj || gl_direct_override))
3917 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3918 sfc->direct_sfc = re->win->egl_surface[0];
3920 sfc->direct_sfc = re->win->win;
3922 gl_direct_enabled = 1;
3925 gl_direct_enabled = 0;
3927 if (gl_direct_enabled)
3931 // Do a make current only if it's not already current
3932 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3933 if ((eglGetCurrentContext() != ctx->context) ||
3934 (eglGetCurrentSurface(EGL_READ) != sfc->direct_sfc) ||
3935 (eglGetCurrentSurface(EGL_DRAW) != sfc->direct_sfc) )
3937 DBG("Rendering Directly to the window\n");
3939 // Flush remainder of what's in Evas' pipeline
3940 eng_window_use(NULL);
3942 // Do a make current
3943 ret = eglMakeCurrent(re->win->egl_disp, sfc->direct_sfc,
3944 sfc->direct_sfc, ctx->context);
3947 ERR("xxxMakeCurrent() failed! code=%#x", eglGetError());
3948 //ERR("xxxMakeCurrent() failed!");
3953 if ((glXGetCurrentContext() != ctx->context))
3955 // Flush remainder of what's in Evas' pipeline
3956 eng_window_use(NULL);
3958 // Do a make current
3959 ret = glXMakeCurrent(re->info->info.display, sfc->direct_sfc, ctx->context);
3962 ERR("xxxMakeCurrent() failed!");
3967 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &curr_fbo);
3968 if (ctx->context_fbo == curr_fbo)
3970 ctx->current_fbo = 0;
3971 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3977 // Do a make current only if it's not already current
3978 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
3979 if (eina_main_loop_is())
3981 if ((eglGetCurrentContext() != ctx->context) ||
3982 (eglGetCurrentSurface(EGL_READ) != re->win->egl_surface[0]) ||
3983 (eglGetCurrentSurface(EGL_DRAW) != re->win->egl_surface[0]) )
3986 // Flush remainder of what's in Evas' pipeline
3987 eng_window_use(NULL);
3989 // Do a make current
3990 ret = eglMakeCurrent(re->win->egl_disp, re->win->egl_surface[0],
3991 re->win->egl_surface[0], ctx->context);
3994 ERR("xxxMakeCurrent() failed! code=%#x", eglGetError());
4001 if ((rsc = eina_tls_get(resource_key)) == EINA_FALSE) return 0;
4003 if ((eglGetCurrentContext() != ctx->context) ||
4004 (eglGetCurrentSurface(EGL_READ) != rsc->surface) ||
4005 (eglGetCurrentSurface(EGL_DRAW) != rsc->surface) )
4007 // Flush remainder of what's in Evas' pipeline
4008 eng_window_use(NULL);
4010 // Do a make current
4011 ret = eglMakeCurrent(re->win->egl_disp, rsc->surface,
4012 rsc->surface, ctx->context);
4015 ERR("xxxMakeCurrent() failed!");
4021 if ((glXGetCurrentContext() != ctx->context) ||
4022 (glXGetCurrentDrawable() != re->win->win) )
4024 // Flush remainder of what's in Evas' pipeline
4025 eng_window_use(NULL);
4027 // Do a make current
4028 ret = glXMakeCurrent(re->info->info.display, re->win->win, ctx->context);
4031 ERR("xxxMakeCurrent() failed!");
4037 // Create FBO if not already created
4038 if (!ctx->initialized)
4040 glGenFramebuffers(1, &ctx->context_fbo);
4041 ctx->initialized = 1;
4044 // Attach FBO if it hasn't been attached or if surface changed
4045 if ((!sfc->fbo_attached) || (ctx->current_sfc != sfc))
4047 if (!_attach_fbo_surface(re, sfc, ctx->context_fbo))
4049 ERR("_attach_fbo_surface() failed.");
4050 _print_gl_surface_info(sfc, 1);
4054 if (ctx->current_fbo)
4055 // Bind to the previously bound buffer
4056 glBindFramebuffer(GL_FRAMEBUFFER, ctx->current_fbo);
4059 glBindFramebuffer(GL_FRAMEBUFFER, ctx->context_fbo);
4061 sfc->fbo_attached = 1;
4065 // Set the current surface/context
4066 ctx->current_sfc = sfc;
4067 sfc->current_ctx = ctx;
4068 current_evgl_ctx = ctx;
4069 current_engine = re;
4075 eng_gl_string_query(void *data __UNUSED__, int name)
4079 case EVAS_GL_EXTENSIONS:
4080 return (void*)_evasgl_ext_string;
4087 eng_gl_proc_address_get(void *data __UNUSED__, const char *name)
4089 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
4090 if (glsym_eglGetProcAddress) return glsym_eglGetProcAddress(name);
4091 return dlsym(RTLD_DEFAULT, name);
4093 if (glsym_glXGetProcAddress) return glsym_glXGetProcAddress(name);
4094 return dlsym(RTLD_DEFAULT, name);
4099 eng_gl_native_surface_get(void *data __UNUSED__, void *surface, void *native_surface)
4101 Render_Engine_GL_Surface *sfc;
4102 Evas_Native_Surface *ns;
4104 sfc = (Render_Engine_GL_Surface*)surface;
4105 ns = (Evas_Native_Surface*)native_surface;
4107 if (sfc->direct_fb_opt)
4109 ns->type = EVAS_NATIVE_SURFACE_OPENGL;
4110 ns->version = EVAS_NATIVE_SURFACE_VERSION;
4111 ns->data.opengl.texture_id = sfc->rt_tex;
4112 ns->data.opengl.framebuffer_id = 0;
4113 ns->data.opengl.x = 0;
4114 ns->data.opengl.y = 0;
4115 ns->data.opengl.w = sfc->w;
4116 ns->data.opengl.h = sfc->h;
4120 ns->type = EVAS_NATIVE_SURFACE_OPENGL;
4121 ns->version = EVAS_NATIVE_SURFACE_VERSION;
4122 ns->data.opengl.texture_id = sfc->rt_tex;
4123 ns->data.opengl.framebuffer_id = sfc->rt_tex;
4124 ns->data.opengl.x = 0;
4125 ns->data.opengl.y = 0;
4126 ns->data.opengl.w = sfc->w;
4127 ns->data.opengl.h = sfc->h;
4134 static const GLubyte *
4135 evgl_glGetString(GLenum name)
4137 if (name == GL_EXTENSIONS)
4138 return (GLubyte *)_gl_ext_string; //glGetString(GL_EXTENSIONS);
4140 return glGetString(name);
4144 evgl_glBindFramebuffer(GLenum target, GLuint framebuffer)
4146 Render_Engine_GL_Context *ctx = current_evgl_ctx;
4150 ERR("No current context set.");
4154 // Take care of BindFramebuffer 0 issue
4157 if (gl_direct_enabled)
4158 glBindFramebuffer(target, 0);
4160 glBindFramebuffer(target, ctx->context_fbo);
4161 ctx->current_fbo = 0;
4165 glBindFramebuffer(target, framebuffer);
4167 // Save this for restore when doing make current
4168 ctx->current_fbo = framebuffer;
4173 evgl_glBindRenderbuffer(GLenum target, GLuint renderbuffer)
4175 // Add logic to take care when renderbuffer=0
4176 // On a second thought we don't need this
4177 glBindRenderbuffer(target, renderbuffer);
4180 // Transform from Evas Coordinat to GL Coordinate
4181 // returns: oc[4] original image object dimension in gl coord
4182 // returns: nc[4] tranformed (x, y, width, heigth) in gl coord
4184 compute_gl_coordinates(Evas_Object *obj, int rot, int clip,
4185 int x, int y, int width, int height,
4186 int imgc[4], int objc[4])
4190 // oringinal image object coordinate in gl coordinate
4191 imgc[0] = obj->cur.geometry.x;
4192 imgc[1] = obj->layer->evas->output.h - obj->cur.geometry.y - obj->cur.geometry.h;
4193 imgc[2] = imgc[0] + obj->cur.geometry.w;
4194 imgc[3] = imgc[1] + obj->cur.geometry.h;
4196 // transformed (x,y,width,height) in gl coordinate
4197 objc[0] = imgc[0] + x;
4198 objc[1] = imgc[1] + y;
4199 objc[2] = objc[0] + width;
4200 objc[3] = objc[1] + height;
4202 else if (rot == 180)
4204 // oringinal image object coordinate in gl coordinate
4205 imgc[0] = obj->layer->evas->output.w - obj->cur.geometry.x - obj->cur.geometry.w;
4206 imgc[1] = obj->cur.geometry.y;
4207 imgc[2] = imgc[0] + obj->cur.geometry.w;
4208 imgc[3] = imgc[1] + obj->cur.geometry.h;
4210 // transformed (x,y,width,height) in gl coordinate
4211 objc[0] = imgc[0] + obj->cur.geometry.w - x - width;
4212 objc[1] = imgc[1] + obj->cur.geometry.h - y - height;
4213 objc[2] = objc[0] + width;
4214 objc[3] = objc[1] + height;
4219 // oringinal image object coordinate in gl coordinate
4220 imgc[0] = obj->cur.geometry.y;
4221 imgc[1] = obj->cur.geometry.x;
4222 imgc[2] = imgc[0] + obj->cur.geometry.h;
4223 imgc[3] = imgc[1] + obj->cur.geometry.w;
4225 // transformed (x,y,width,height) in gl coordinate
4226 objc[0] = imgc[0] + obj->cur.geometry.h - y - height;
4227 objc[1] = imgc[1] + x;
4228 objc[2] = objc[0] + height;
4229 objc[3] = objc[1] + width;
4231 else if (rot == 270)
4233 // oringinal image object coordinate in gl coordinate
4234 imgc[0] = obj->layer->evas->output.h - obj->cur.geometry.y - obj->cur.geometry.h;
4235 imgc[1] = obj->layer->evas->output.w - obj->cur.geometry.x - obj->cur.geometry.w;
4236 imgc[2] = imgc[0] + obj->cur.geometry.h;
4237 imgc[3] = imgc[1] + obj->cur.geometry.w;
4239 // transformed (x,y,width,height) in gl coordinate
4240 objc[0] = imgc[0] + y;
4241 objc[1] = imgc[1] + obj->cur.geometry.w - x - width;
4242 objc[2] = objc[0] + height;
4243 objc[3] = objc[1] + width;
4247 ERR("Invalid rotation angle %d.", rot);
4253 // Clip against original image object
4254 if (objc[0] < imgc[0]) objc[0] = imgc[0];
4255 if (objc[0] > imgc[2]) objc[0] = 0;
4257 if (objc[1] < imgc[1]) objc[1] = imgc[1];
4258 if (objc[1] > imgc[3]) objc[1] = 0;
4260 if (objc[2] < imgc[0]) objc[0] = 0;
4261 if (objc[2] > imgc[2]) objc[2] = imgc[2];
4263 if (objc[3] < imgc[1]) objc[1] = 0;
4264 if (objc[3] > imgc[3]) objc[3] = imgc[3];
4267 imgc[2] = imgc[2]-imgc[0]; // width
4268 imgc[3] = imgc[3]-imgc[1]; // height
4270 objc[2] = objc[2]-objc[0]; // width
4271 objc[3] = objc[3]-objc[1]; // height
4275 evgl_glClear(GLbitfield mask)
4277 Render_Engine_GL_Context *ctx = current_evgl_ctx;
4281 if ((gl_direct_img_obj) && (gl_direct_enabled) && (ctx) && (!ctx->current_fbo))
4283 if ((current_engine) && (current_engine->win) && (current_engine->win->gl_context))
4284 rot = current_engine->win->gl_context->rot;
4286 ERR("Unable to retrieve rotation angle: %d", rot);
4288 compute_gl_coordinates(gl_direct_img_obj, rot, 0, 0, 0, 0, 0, oc, nc);
4289 glScissor(oc[0], oc[1], oc[2], oc[3]);
4297 evgl_glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
4299 glClearColor(red, green, blue, alpha);
4303 evgl_glEnable(GLenum cap)
4305 Render_Engine_GL_Context *ctx = current_evgl_ctx;
4307 if (cap == GL_SCISSOR_TEST)
4308 if (ctx) ctx->scissor_enabled = 1;
4313 evgl_glDisable(GLenum cap)
4315 Render_Engine_GL_Context *ctx = current_evgl_ctx;
4317 if (cap == GL_SCISSOR_TEST)
4318 if (ctx) ctx->scissor_enabled = 0;
4324 evgl_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
4326 Render_Engine_GL_Context *ctx = current_evgl_ctx;
4330 if ((gl_direct_img_obj) && (gl_direct_enabled) && (ctx) && (!ctx->current_fbo))
4332 if ((current_engine) && (current_engine->win) && (current_engine->win->gl_context))
4333 rot = current_engine->win->gl_context->rot;
4335 ERR("Unable to retrieve rotation angle: %d", rot);
4337 compute_gl_coordinates(gl_direct_img_obj, rot, 1, x, y, width, height, oc, nc);
4338 glReadPixels(nc[0], nc[1], nc[2], nc[3], format, type, pixels);
4341 glReadPixels(x, y, width, height, format, type, pixels);
4345 evgl_glScissor(GLint x, GLint y, GLsizei width, GLsizei height)
4347 Render_Engine_GL_Context *ctx = current_evgl_ctx;
4351 if ((gl_direct_img_obj) && (gl_direct_enabled) && (ctx) && (!ctx->current_fbo))
4353 if ((current_engine) && (current_engine->win) && (current_engine->win->gl_context))
4354 rot = current_engine->win->gl_context->rot;
4356 ERR("Unable to retrieve rotation angle: %d", rot);
4358 compute_gl_coordinates(gl_direct_img_obj, rot, 1, x, y, width, height, oc, nc);
4359 glScissor(nc[0], nc[1], nc[2], nc[3]);
4360 ctx->scissor_upated = 1;
4363 glScissor(x, y, width, height);
4367 evgl_glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
4369 Render_Engine_GL_Context *ctx = current_evgl_ctx;
4373 if ((gl_direct_img_obj) && (gl_direct_enabled) && (ctx) && (!ctx->current_fbo))
4375 if ((current_engine) && (current_engine->win) && (current_engine->win->gl_context))
4376 rot = current_engine->win->gl_context->rot;
4378 ERR("Unable to retrieve rotation angle: %d", rot);
4380 compute_gl_coordinates(gl_direct_img_obj, rot, 0, x, y, width, height, oc, nc);
4381 glEnable(GL_SCISSOR_TEST);
4382 glScissor(oc[0], oc[1], oc[2], oc[3]);
4383 glViewport(nc[0], nc[1], nc[2], nc[3]);
4386 glViewport(x, y, width, height);
4391 //----------------------------------------------//
4394 evgl_glClearDepthf(GLclampf depth)
4396 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
4397 glClearDepthf(depth);
4399 glClearDepth(depth);
4404 evgl_glDepthRangef(GLclampf zNear, GLclampf zFar)
4406 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
4407 glDepthRangef(zNear, zFar);
4409 glDepthRange(zNear, zFar);
4414 evgl_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
4416 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
4417 glGetShaderPrecisionFormat(shadertype, precisiontype, range, precision);
4421 range[0] = -126; // floor(log2(FLT_MIN))
4422 range[1] = 127; // floor(log2(FLT_MAX))
4426 precision[0] = 24; // floor(-log2((1.0/16777218.0)));
4433 evgl_glReleaseShaderCompiler(void)
4435 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
4436 glReleaseShaderCompiler();
4442 evgl_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
4444 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
4445 glShaderBinary(n, shaders, binaryformat, binary, length);
4447 // FIXME: need to dlsym/getprocaddress for this
4449 n = binaryformat = length = 0;
4450 shaders = binary = 0;
4454 //--------------------------------//
4455 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
4458 evgl_evasglCreateImage(int target, void* buffer, int *attrib_list)
4462 return glsym_eglCreateImage(current_engine->win->egl_disp,
4470 ERR("Invalid Engine... (Can't acccess EGL Display)\n");
4476 evgl_evasglDestroyImage(EvasGLImage image)
4479 glsym_eglDestroyImage(current_engine->win->egl_disp, image);
4481 ERR("Invalid Engine... (Can't acccess EGL Display)\n");
4485 evgl_glEvasGLImageTargetTexture2DOES(GLenum target, EvasGLImage image)
4487 glsym_glEGLImageTargetTexture2DOES(target, image);
4491 evgl_glEvasGLImageTargetRenderbufferStorageOES(GLenum target, EvasGLImage image)
4493 glsym_glEGLImageTargetTexture2DOES(target, image);
4498 //--------------------------------//
4502 eng_gl_api_get(void *data)
4506 re = (Render_Engine *)data;
4508 gl_funcs.version = EVAS_GL_API_VERSION;
4510 #define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, )
4512 ORD(glActiveTexture);
4513 ORD(glAttachShader);
4514 ORD(glBindAttribLocation);
4518 ORD(glBlendEquation);
4519 ORD(glBlendEquationSeparate);
4521 ORD(glBlendFuncSeparate);
4523 ORD(glBufferSubData);
4524 ORD(glCheckFramebufferStatus);
4526 // ORD(glClearColor);
4527 // ORD(glClearDepthf);
4528 ORD(glClearStencil);
4530 ORD(glCompileShader);
4531 ORD(glCompressedTexImage2D);
4532 ORD(glCompressedTexSubImage2D);
4533 ORD(glCopyTexImage2D);
4534 ORD(glCopyTexSubImage2D);
4535 ORD(glCreateProgram);
4536 ORD(glCreateShader);
4538 ORD(glDeleteBuffers);
4539 ORD(glDeleteFramebuffers);
4540 ORD(glDeleteProgram);
4541 ORD(glDeleteRenderbuffers);
4542 ORD(glDeleteShader);
4543 ORD(glDeleteTextures);
4546 // ORD(glDepthRangef);
4547 ORD(glDetachShader);
4549 ORD(glDisableVertexAttribArray);
4551 ORD(glDrawElements);
4553 ORD(glEnableVertexAttribArray);
4556 ORD(glFramebufferRenderbuffer);
4557 ORD(glFramebufferTexture2D);
4560 ORD(glGenerateMipmap);
4561 ORD(glGenFramebuffers);
4562 ORD(glGenRenderbuffers);
4564 ORD(glGetActiveAttrib);
4565 ORD(glGetActiveUniform);
4566 ORD(glGetAttachedShaders);
4567 ORD(glGetAttribLocation);
4569 ORD(glGetBufferParameteriv);
4572 ORD(glGetFramebufferAttachmentParameteriv);
4574 ORD(glGetProgramiv);
4575 ORD(glGetProgramInfoLog);
4576 ORD(glGetRenderbufferParameteriv);
4578 ORD(glGetShaderInfoLog);
4579 // ORD(glGetShaderPrecisionFormat);
4580 ORD(glGetShaderSource);
4581 // ORD(glGetString);
4582 ORD(glGetTexParameterfv);
4583 ORD(glGetTexParameteriv);
4584 ORD(glGetUniformfv);
4585 ORD(glGetUniformiv);
4586 ORD(glGetUniformLocation);
4587 ORD(glGetVertexAttribfv);
4588 ORD(glGetVertexAttribiv);
4589 ORD(glGetVertexAttribPointerv);
4593 ORD(glIsFramebuffer);
4595 ORD(glIsRenderbuffer);
4601 ORD(glPolygonOffset);
4603 // ORD(glReleaseShaderCompiler);
4604 ORD(glRenderbufferStorage);
4605 ORD(glSampleCoverage);
4607 // ORD(glShaderBinary);
4608 ORD(glShaderSource);
4610 ORD(glStencilFuncSeparate);
4612 ORD(glStencilMaskSeparate);
4614 ORD(glStencilOpSeparate);
4616 ORD(glTexParameterf);
4617 ORD(glTexParameterfv);
4618 ORD(glTexParameteri);
4619 ORD(glTexParameteriv);
4620 ORD(glTexSubImage2D);
4637 ORD(glUniformMatrix2fv);
4638 ORD(glUniformMatrix3fv);
4639 ORD(glUniformMatrix4fv);
4641 ORD(glValidateProgram);
4642 ORD(glVertexAttrib1f);
4643 ORD(glVertexAttrib1fv);
4644 ORD(glVertexAttrib2f);
4645 ORD(glVertexAttrib2fv);
4646 ORD(glVertexAttrib3f);
4647 ORD(glVertexAttrib3fv);
4648 ORD(glVertexAttrib4f);
4649 ORD(glVertexAttrib4fv);
4650 ORD(glVertexAttribPointer);
4654 #define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, glsym_)
4656 ORD(glGetProgramBinaryOES);
4657 ORD(glProgramBinaryOES);
4658 ORD(glMapBufferOES);
4659 ORD(glUnmapBufferOES);
4660 ORD(glGetBufferPointervOES);
4661 ORD(glTexImage3DOES);
4662 ORD(glTexSubImage3DOES);
4663 ORD(glCopyTexSubImage3DOES);
4664 ORD(glCompressedTexImage3DOES);
4665 ORD(glCompressedTexSubImage3DOES);
4666 ORD(glFramebufferTexture3DOES);
4667 ORD(glGetPerfMonitorGroupsAMD);
4668 ORD(glGetPerfMonitorCountersAMD);
4669 ORD(glGetPerfMonitorGroupStringAMD);
4670 ORD(glGetPerfMonitorCounterStringAMD);
4671 ORD(glGetPerfMonitorCounterInfoAMD);
4672 ORD(glGenPerfMonitorsAMD);
4673 ORD(glDeletePerfMonitorsAMD);
4674 ORD(glSelectPerfMonitorCountersAMD);
4675 ORD(glBeginPerfMonitorAMD);
4676 ORD(glEndPerfMonitorAMD);
4677 ORD(glGetPerfMonitorCounterDataAMD);
4678 ORD(glDiscardFramebufferEXT);
4679 ORD(glMultiDrawArraysEXT);
4680 ORD(glMultiDrawElementsEXT);
4681 ORD(glDeleteFencesNV);
4685 ORD(glGetFenceivNV);
4686 ORD(glFinishFenceNV);
4688 ORD(glGetDriverControlsQCOM);
4689 ORD(glGetDriverControlStringQCOM);
4690 ORD(glEnableDriverControlQCOM);
4691 ORD(glDisableDriverControlQCOM);
4692 ORD(glExtGetTexturesQCOM);
4693 ORD(glExtGetBuffersQCOM);
4694 ORD(glExtGetRenderbuffersQCOM);
4695 ORD(glExtGetFramebuffersQCOM);
4696 ORD(glExtGetTexLevelParameterivQCOM);
4697 ORD(glExtTexObjectStateOverrideiQCOM);
4698 ORD(glExtGetTexSubImageQCOM);
4699 ORD(glExtGetBufferPointervQCOM);
4700 ORD(glExtGetShadersQCOM);
4701 ORD(glExtGetProgramsQCOM);
4702 ORD(glExtIsProgramBinaryQCOM);
4703 ORD(glExtGetProgramBinarySourceQCOM);
4706 // Override functions wrapped by Evas_GL
4707 #define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, evgl_)
4708 ORD(glBindFramebuffer);
4709 ORD(glBindRenderbuffer);
4719 // GLES2.0 API compat on top of desktop gl
4722 ORD(glGetShaderPrecisionFormat);
4723 ORD(glReleaseShaderCompiler);
4724 ORD(glShaderBinary);
4728 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
4729 // GLES 2.0 Extensions that needs wrapping
4730 ORD(evasglCreateImage);
4731 ORD(evasglDestroyImage);
4732 ORD(glEvasGLImageTargetTexture2DOES);
4733 ORD(glEvasGLImageTargetRenderbufferStorageOES);
4742 eng_gl_img_obj_set(void *data, void *image, int has_alpha)
4744 Render_Engine *re = (Render_Engine *)data;
4746 gl_direct_img_obj = NULL;
4748 // Normally direct rendering isn't allowed if alpha is on and
4749 // rotation is not 0. BUT, if override is on, allow it.
4750 if ((has_alpha) || (re->win->gl_context->rot!=0))
4752 if (gl_direct_override)
4753 gl_direct_img_obj = image;
4756 gl_direct_img_obj = image;
4760 eng_image_load_error_get(void *data __UNUSED__, void *image)
4764 if (!image) return EVAS_LOAD_ERROR_NONE;
4766 return im->im->cache_entry.load_error;
4770 eng_image_animated_get(void *data __UNUSED__, void *image)
4772 Evas_GL_Image *gim = image;
4775 if (!gim) return EINA_FALSE;
4776 im = (Image_Entry *)gim->im;
4777 if (!im) return EINA_FALSE;
4779 return im->flags.animated;
4783 eng_image_animated_frame_count_get(void *data __UNUSED__, void *image)
4785 Evas_GL_Image *gim = image;
4788 if (!gim) return -1;
4789 im = (Image_Entry *)gim->im;
4792 if (!im->flags.animated) return -1;
4793 return im->frame_count;
4796 static Evas_Image_Animated_Loop_Hint
4797 eng_image_animated_loop_type_get(void *data __UNUSED__, void *image)
4799 Evas_GL_Image *gim = image;
4802 if (!gim) return EVAS_IMAGE_ANIMATED_HINT_NONE;
4803 im = (Image_Entry *)gim->im;
4804 if (!im) return EVAS_IMAGE_ANIMATED_HINT_NONE;
4806 if (!im->flags.animated) return EVAS_IMAGE_ANIMATED_HINT_NONE;
4807 return im->loop_hint;
4811 eng_image_animated_loop_count_get(void *data __UNUSED__, void *image)
4813 Evas_GL_Image *gim = image;
4816 if (!gim) return -1;
4817 im = (Image_Entry *)gim->im;
4820 if (!im->flags.animated) return -1;
4821 return im->loop_count;
4825 eng_image_animated_frame_duration_get(void *data __UNUSED__, void *image, int start_frame, int frame_num)
4827 Evas_GL_Image *gim = image;
4830 if (!gim) return -1;
4831 im = (Image_Entry *)gim->im;
4834 if (!im->flags.animated) return -1;
4835 return evas_common_load_rgba_image_frame_duration_from_file(im, start_frame, frame_num);
4839 eng_image_animated_frame_set(void *data __UNUSED__, void *image, int frame_index)
4841 Evas_GL_Image *gim = image;
4844 if (!gim) return EINA_FALSE;
4845 im = (Image_Entry *)gim->im;
4846 if (!im) return EINA_FALSE;
4848 if (!im->flags.animated) return EINA_FALSE;
4849 if (im->cur_frame == frame_index) return EINA_FALSE;
4851 im->cur_frame = frame_index;
4856 eng_image_can_region_get(void *data __UNUSED__, void *image)
4858 Evas_GL_Image *gim = image;
4860 if (!gim) return EINA_FALSE;
4861 im = (Image_Entry *)gim->im;
4862 if (!im) return EINA_FALSE;
4863 return ((Evas_Image_Load_Func*) im->info.loader)->do_region;
4868 eng_image_max_size_get(void *data, int *maxw, int *maxh)
4870 Render_Engine *re = (Render_Engine *)data;
4871 if (maxw) *maxw = re->win->gl_context->shared->info.max_texture_size;
4872 if (maxh) *maxh = re->win->gl_context->shared->info.max_texture_size;
4876 module_open(Evas_Module *em)
4878 static Eina_Bool xrm_inited = EINA_FALSE;
4881 xrm_inited = EINA_TRUE;
4886 if (!evas_gl_common_module_open()) return 0;
4887 /* get whatever engine module we inherit from */
4888 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
4889 if (_evas_engine_GL_X11_log_dom < 0)
4890 _evas_engine_GL_X11_log_dom = eina_log_domain_register
4891 ("evas-gl_x11", EVAS_DEFAULT_LOG_COLOR);
4892 if (_evas_engine_GL_X11_log_dom < 0)
4894 EINA_LOG_ERR("Can not create a module log domain.");
4899 /* Allow alpha for evas gl direct rendering */
4900 if (getenv("EVAS_GL_DIRECT_OVERRIDE"))
4902 gl_direct_override = 1;
4903 DBG("########################################################");
4904 DBG("######### [Evas] Direct overriding is enabled ##########");
4905 DBG("########################################################");
4908 /* store it for later use */
4910 /* now to override methods */
4911 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
4915 ORD(canvas_alpha_get);
4918 ORD(output_tile_size_set);
4919 ORD(output_redraws_rect_add);
4920 ORD(output_redraws_rect_del);
4921 ORD(output_redraws_clear);
4922 ORD(output_redraws_next_update_get);
4923 ORD(output_redraws_next_update_push);
4924 ORD(context_cutout_add);
4925 ORD(context_cutout_clear);
4927 ORD(output_idle_flush);
4929 ORD(rectangle_draw);
4931 ORD(polygon_point_add);
4932 ORD(polygon_points_clear);
4936 ORD(image_new_from_data);
4937 ORD(image_new_from_copied_data);
4939 ORD(image_size_get);
4940 ORD(image_size_set);
4941 ORD(image_dirty_region);
4942 ORD(image_data_get);
4943 ORD(image_data_put);
4944 ORD(image_data_preload_request);
4945 ORD(image_data_preload_cancel);
4946 ORD(image_alpha_set);
4947 ORD(image_alpha_get);
4948 ORD(image_border_set);
4949 ORD(image_border_get);
4951 ORD(image_comment_get);
4952 ORD(image_format_get);
4953 ORD(image_colorspace_set);
4954 ORD(image_colorspace_get);
4955 ORD(image_can_region_get);
4956 ORD(image_mask_create);
4957 ORD(image_native_set);
4958 ORD(image_native_get);
4959 #if 0 // filtering disabled
4960 ORD(image_draw_filtered);
4961 ORD(image_filtered_get);
4962 ORD(image_filtered_save);
4963 ORD(image_filtered_free);
4968 ORD(image_scale_hint_set);
4969 ORD(image_scale_hint_get);
4970 ORD(image_stride_get);
4972 ORD(image_map_draw);
4973 ORD(image_map_surface_new);
4974 ORD(image_map_surface_free);
4975 ORD(image_map_clean);
4977 ORD(image_content_hint_set);
4978 ORD(image_content_hint_get);
4980 ORD(image_cache_flush);
4981 ORD(image_cache_set);
4982 ORD(image_cache_get);
4984 ORD(gl_surface_create);
4985 ORD(gl_surface_destroy);
4986 ORD(gl_context_create);
4987 ORD(gl_context_destroy);
4988 ORD(gl_make_current);
4989 ORD(gl_string_query);
4990 ORD(gl_proc_address_get);
4991 ORD(gl_native_surface_get);
4993 ORD(gl_img_obj_set);
4995 ORD(image_load_error_get);
4997 /* now advertise out own api */
4998 ORD(image_animated_get);
4999 ORD(image_animated_frame_count_get);
5000 ORD(image_animated_loop_type_get);
5001 ORD(image_animated_loop_count_get);
5002 ORD(image_animated_frame_duration_get);
5003 ORD(image_animated_frame_set);
5005 ORD(image_max_size_get);
5007 /* now advertise out own api */
5008 em->functions = (void *)(&func);
5013 module_close(Evas_Module *em __UNUSED__)
5015 eina_log_domain_unregister(_evas_engine_GL_X11_log_dom);
5019 XrmDestroyDatabase(xrdb_user.db);
5020 xrdb_user.last_stat = 0;
5021 xrdb_user.last_mtime = 0;
5022 xrdb_user.db = NULL;
5025 evas_gl_common_module_close();
5028 static Evas_Module_Api evas_modapi =
5030 EVAS_MODULE_API_VERSION,
5039 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, gl_x11);
5041 #ifndef EVAS_STATIC_BUILD_GL_XLIB
5042 EVAS_EINA_MODULE_DEFINE(engine, gl_x11);
5045 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/