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