1 #include "evas_common.h" /* Also includes international specific stuff */
2 #include "evas_engine.h"
4 #include <dlfcn.h> /* dlopen,dlclose,etc */
5 #define EVAS_GL_NO_GL_H_CHECK 1
8 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
10 # if defined(GLES_VARIETY_S3C6410)
11 # elif defined(GLES_VARIETY_SGX)
17 typedef struct _Render_Engine Render_Engine;
18 typedef struct _Render_Engine_GL_Surface Render_Engine_GL_Surface;
19 typedef struct _Render_Engine_GL_Context Render_Engine_GL_Context;
23 Evas_GL_X11_Window *win;
24 Evas_Engine_Info_GL_X11 *info;
28 XrmDatabase xrdb; // xres - dpi
29 struct { // xres - dpi
30 int dpi; // xres - dpi
37 struct _Render_Engine_GL_Surface
45 // Render target texture/buffers
47 GLint rt_internal_fmt;
52 GLenum rb_stencil_fmt;
54 Render_Engine_GL_Context *current_ctx;
57 struct _Render_Engine_GL_Context
60 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
67 Render_Engine_GL_Surface *current_sfc;
70 static int initted = 0;
71 static int gl_wins = 0;
73 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
75 #ifndef EGL_NATIVE_PIXMAP_KHR
76 # define EGL_NATIVE_PIXMAP_KHR 0x30b0
78 typedef void (*_eng_fn) (void);
80 typedef _eng_fn (*glsym_func_eng_fn) ();
81 typedef void (*glsym_func_void) ();
82 typedef void *(*glsym_func_void_ptr) ();
84 _eng_fn (*glsym_eglGetProcAddress) (const char *a) = NULL;
85 void (*glsym_eglBindTexImage) (EGLDisplay a, EGLSurface b, int c) = NULL;
86 void (*glsym_eglReleaseTexImage) (EGLDisplay a, EGLSurface b, int c) = NULL;
87 void *(*glsym_eglCreateImage) (EGLDisplay a, EGLContext b, EGLenum c, EGLClientBuffer d, const int *e) = NULL;
88 void (*glsym_eglDestroyImage) (EGLDisplay a, void *b) = NULL;
89 void (*glsym_glEGLImageTargetTexture2DOES) (int a, void *b) = NULL;
91 typedef void (*_eng_fn) (void);
93 typedef _eng_fn (*glsym_func_eng_fn) ();
94 typedef void (*glsym_func_void) ();
95 typedef int (*glsym_func_int) ();
96 typedef XID (*glsym_func_xid) ();
97 typedef unsigned int (*glsym_func_uint) ();
98 typedef unsigned char (*glsym_func_uchar) ();
99 typedef unsigned char *(*glsym_func_uchar_ptr) ();
101 _eng_fn (*glsym_glXGetProcAddress) (const char *a) = NULL;
102 void (*glsym_glXBindTexImage) (Display *a, GLXDrawable b, int c, int *d) = NULL;
103 void (*glsym_glXReleaseTexImage) (Display *a, GLXDrawable b, int c) = NULL;
104 int (*glsym_glXGetVideoSync) (unsigned int *a) = NULL;
105 int (*glsym_glXWaitVideoSync) (int a, int b, unsigned int *c) = NULL;
106 XID (*glsym_glXCreatePixmap) (Display *a, void *b, Pixmap c, const int *d) = NULL;
107 void (*glsym_glXDestroyPixmap) (Display *a, XID b) = NULL;
108 void (*glsym_glXQueryDrawable) (Display *a, XID b, int c, unsigned int *d) = NULL;
109 int (*glsym_glxSwapIntervalSGI) (int a) = NULL;
110 void (*glsym_glxSwapIntervalEXT) (Display *s, GLXDrawable b, int c) = NULL;
120 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
121 #define FINDSYM(dst, sym, typ) \
122 if ((!dst) && (glsym_eglGetProcAddress)) dst = (typ)glsym_eglGetProcAddress(sym); \
123 if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
125 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddress", glsym_func_eng_fn);
126 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddressEXT", glsym_func_eng_fn);
127 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddressARB", glsym_func_eng_fn);
128 FINDSYM(glsym_eglGetProcAddress, "eglGetProcAddressKHR", glsym_func_eng_fn);
130 FINDSYM(glsym_eglBindTexImage, "eglBindTexImage", glsym_func_void);
131 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageEXT", glsym_func_void);
132 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageARB", glsym_func_void);
133 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageKHR", glsym_func_void);
135 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImage", glsym_func_void);
136 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageEXT", glsym_func_void);
137 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageARB", glsym_func_void);
138 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageKHR", glsym_func_void);
140 FINDSYM(glsym_eglCreateImage, "eglCreateImage", glsym_func_void_ptr);
141 FINDSYM(glsym_eglCreateImage, "eglCreateImageEXT", glsym_func_void_ptr);
142 FINDSYM(glsym_eglCreateImage, "eglCreateImageARB", glsym_func_void_ptr);
143 FINDSYM(glsym_eglCreateImage, "eglCreateImageKHR", glsym_func_void_ptr);
145 FINDSYM(glsym_eglDestroyImage, "eglDestroyImage", glsym_func_void);
146 FINDSYM(glsym_eglDestroyImage, "eglDestroyImageEXT", glsym_func_void);
147 FINDSYM(glsym_eglDestroyImage, "eglDestroyImageARB", glsym_func_void);
148 FINDSYM(glsym_eglDestroyImage, "eglDestroyImageKHR", glsym_func_void);
150 FINDSYM(glsym_glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", glsym_func_void);
152 #define FINDSYM(dst, sym, typ) \
153 if ((!dst) && (glsym_glXGetProcAddress)) dst = (typ)glsym_glXGetProcAddress(sym); \
154 if (!dst) dst = (typ)dlsym(RTLD_DEFAULT, sym)
156 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddress", glsym_func_eng_fn);
157 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressEXT", glsym_func_eng_fn);
158 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressARB", glsym_func_eng_fn);
160 FINDSYM(glsym_glXBindTexImage, "glXBindTexImage", glsym_func_void);
161 FINDSYM(glsym_glXBindTexImage, "glXBindTexImageEXT", glsym_func_void);
162 FINDSYM(glsym_glXBindTexImage, "glXBindTexImageARB", glsym_func_void);
164 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImage", glsym_func_void);
165 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImageEXT", glsym_func_void);
166 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImageARB", glsym_func_void);
168 FINDSYM(glsym_glXGetVideoSync, "glXGetVideoSyncSGI", glsym_func_int);
170 FINDSYM(glsym_glXWaitVideoSync, "glXWaitVideoSyncSGI", glsym_func_int);
172 FINDSYM(glsym_glXCreatePixmap, "glXCreatePixmap", glsym_func_xid);
173 FINDSYM(glsym_glXCreatePixmap, "glXCreatePixmapEXT", glsym_func_xid);
174 FINDSYM(glsym_glXCreatePixmap, "glXCreatePixmapARB", glsym_func_xid);
176 FINDSYM(glsym_glXDestroyPixmap, "glXDestroyPixmap", glsym_func_void);
177 FINDSYM(glsym_glXDestroyPixmap, "glXDestroyPixmapEXT", glsym_func_void);
178 FINDSYM(glsym_glXDestroyPixmap, "glXDestroyPixmapARB", glsym_func_void);
180 FINDSYM(glsym_glXQueryDrawable, "glXQueryDrawable", glsym_func_void);
181 FINDSYM(glsym_glXQueryDrawable, "glXQueryDrawableEXT", glsym_func_void);
182 FINDSYM(glsym_glXQueryDrawable, "glXQueryDrawableARB", glsym_func_void);
184 FINDSYM(glsym_glxSwapIntervalSGI, "glXSwapIntervalMESA", glsym_func_int);
185 FINDSYM(glsym_glxSwapIntervalSGI, "glXSwapIntervalSGI", glsym_func_int);
187 FINDSYM(glsym_glxSwapIntervalEXT, "glXSwapIntervalEXT", glsym_func_void);
191 int _evas_engine_GL_X11_log_dom = -1;
192 /* function tables - filled in later (func and parent func) */
193 static Evas_Func func, pfunc;
195 /* Function table for GL APIs */
196 static Evas_GL_API gl_funcs;
204 static struct xrdb_user xrdb_user = {0, 0, NULL};
207 xrdb_user_query(const char *name, const char *cls, char **type, XrmValue *val)
209 time_t last = xrdb_user.last_stat, now = time(NULL);
211 xrdb_user.last_stat = now;
212 if (last != now) /* don't stat() more than once every second */
215 const char *home = getenv("HOME");
218 if (!home) goto failed;
219 snprintf(tmp, sizeof(tmp), "%s/.Xdefaults", home);
220 if (stat(tmp, &st) != 0) goto failed;
221 if (xrdb_user.last_mtime != st.st_mtime)
223 if (xrdb_user.db) XrmDestroyDatabase(xrdb_user.db);
224 xrdb_user.db = XrmGetFileDatabase(tmp);
225 if (!xrdb_user.db) goto failed;
226 xrdb_user.last_mtime = st.st_mtime;
230 if (!xrdb_user.db) return EINA_FALSE;
231 return XrmGetResource(xrdb_user.db, name, cls, type, val);
236 XrmDestroyDatabase(xrdb_user.db);
239 xrdb_user.last_mtime = 0;
246 Evas_Engine_Info_GL_X11 *info;
248 info = calloc(1, sizeof(Evas_Engine_Info_GL_X11));
249 info->magic.magic = rand();
250 info->func.best_visual_get = eng_best_visual_get;
251 info->func.best_colormap_get = eng_best_colormap_get;
252 info->func.best_depth_get = eng_best_depth_get;
253 info->render_mode = EVAS_RENDER_MODE_BLOCKING;
259 eng_info_free(Evas *e __UNUSED__, void *info)
261 Evas_Engine_Info_GL_X11 *in;
262 // dont free! why bother? its not worth it
263 // eina_log_domain_unregister(_evas_engine_GL_X11_log_dom);
264 in = (Evas_Engine_Info_GL_X11 *)info;
269 _re_wincheck(Render_Engine *re)
271 if (re->win->surf) return 1;
272 eng_window_resurf(re->win);
275 ERR("GL engine can't re-create window surface!");
281 _re_winfree(Render_Engine *re)
283 if (!re->win->surf) return;
284 eng_window_unsurf(re->win);
288 eng_setup(Evas *e, void *in)
291 Evas_Engine_Info_GL_X11 *info;
293 info = (Evas_Engine_Info_GL_X11 *)in;
294 if (!e->engine.data.output)
296 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
300 if (!glXQueryExtension(info->info.display, &eb, &evb)) return 0;
302 re = calloc(1, sizeof(Render_Engine));
306 e->engine.data.output = re;
309 re->win = eng_window_new(re->info->info.display,
310 re->info->info.drawable,
311 re->info->info.screen,
312 re->info->info.visual,
313 re->info->info.colormap,
314 re->info->info.depth,
318 re->info->info.destination_alpha,
319 re->info->info.rotation);
323 e->engine.data.output = NULL;
333 re->xr.dpi = 75000; // dpy * 1000
335 status = xrdb_user_query("Xft.dpi", "Xft.Dpi", &type, &val);
336 if ((!status) || (!type))
338 if (!re->xrdb) re->xrdb = XrmGetDatabase(re->info->info.display);
340 status = XrmGetResource(re->xrdb,
341 "Xft.dpi", "Xft.Dpi", &type, &val);
344 if ((status) && (type))
346 if (!strcmp(type, "String"))
348 const char *str, *dp;
351 dp = strchr(str, '.');
352 if (!dp) dp = strchr(str, ',');
359 buf = alloca(dp - str + 1);
360 strncpy(buf, str, dp - str);
362 len = strlen(dp + 1);
363 subdpi = atoi(dp + 1);
367 for (i = len; i < 3; i++) subdpi *= 10;
371 for (i = len; i > 3; i--) subdpi /= 10;
373 re->xr.dpi = atoi(buf) * 1000;
376 re->xr.dpi = atoi(str) * 1000;
377 evas_common_font_dpi_set(re->xr.dpi / 1000);
384 evas_common_cpu_init();
386 evas_common_blend_init();
387 evas_common_image_init();
388 evas_common_convert_init();
389 evas_common_scale_init();
390 evas_common_rectangle_init();
391 evas_common_polygon_init();
392 evas_common_line_init();
393 evas_common_font_init();
394 evas_common_draw_init();
395 evas_common_tilebuf_init();
401 re = e->engine.data.output;
402 if (_re_wincheck(re))
404 if ((re->info->info.display != re->win->disp) ||
405 (re->info->info.drawable != re->win->win) ||
406 (re->info->info.screen != re->win->screen) ||
407 (re->info->info.visual != re->win->visual) ||
408 (re->info->info.colormap != re->win->colormap) ||
409 (re->info->info.depth != re->win->depth) ||
410 (re->info->info.destination_alpha != re->win->alpha) ||
411 (re->info->info.rotation != re->win->rot))
417 re->win->gl_context->references++;
418 eng_window_free(re->win);
424 re->win = eng_window_new(re->info->info.display,
425 re->info->info.drawable,
426 re->info->info.screen,
427 re->info->info.visual,
428 re->info->info.colormap,
429 re->info->info.depth,
433 re->info->info.destination_alpha,
434 re->info->info.rotation);
435 eng_window_use(re->win);
436 if (re->win) gl_wins++;
437 if ((re->win) && (inc))
438 re->win->gl_context->references--;
440 else if ((re->win->w != e->output.w) ||
441 (re->win->h != e->output.h))
445 re->win->w = e->output.w;
446 re->win->h = e->output.h;
447 eng_window_use(re->win);
448 evas_gl_common_context_resize(re->win->gl_context, re->win->w, re->win->h, re->win->rot);
458 if (!e->engine.data.output)
462 eng_window_free(re->win);
468 if (!e->engine.data.context)
469 e->engine.data.context =
470 e->engine.func->context_new(e->engine.data.output);
471 eng_window_use(re->win);
476 glClearColor(0.0, 0.0, 0.0, 0.0);
477 glClear(GL_COLOR_BUFFER_BIT);
486 eng_output_free(void *data)
490 re = (Render_Engine *)data;
494 // NOTE: XrmGetDatabase() result is shared per connection, do not free it.
495 // if (re->xrdb) XrmDestroyDatabase(re->xrdb);
499 eng_window_free(re->win);
504 if ((initted == 1) && (gl_wins == 0))
506 evas_common_image_shutdown();
507 evas_common_font_shutdown();
513 eng_output_resize(void *data, int w, int h)
517 re = (Render_Engine *)data;
520 eng_window_use(re->win);
521 evas_gl_common_context_resize(re->win->gl_context, w, h, re->win->rot);
525 eng_output_tile_size_set(void *data __UNUSED__, int w __UNUSED__, int h __UNUSED__)
530 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
534 re = (Render_Engine *)data;
535 evas_gl_common_context_resize(re->win->gl_context, re->win->w, re->win->h, re->win->rot);
536 /* smple bounding box */
537 RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, re->win->w, re->win->h);
538 if ((w <= 0) || (h <= 0)) return;
539 if (!re->win->draw.redraw)
542 re->win->draw.x1 = x;
543 re->win->draw.y1 = y;
544 re->win->draw.x2 = x + w - 1;
545 re->win->draw.y2 = y + h - 1;
547 re->win->draw.x1 = 0;
548 re->win->draw.y1 = 0;
549 re->win->draw.x2 = re->win->w - 1;
550 re->win->draw.y2 = re->win->h - 1;
555 if (x < re->win->draw.x1) re->win->draw.x1 = x;
556 if (y < re->win->draw.y1) re->win->draw.y1 = y;
557 if ((x + w - 1) > re->win->draw.x2) re->win->draw.x2 = x + w - 1;
558 if ((y + h - 1) > re->win->draw.y2) re->win->draw.y2 = y + h - 1;
560 re->win->draw.redraw = 1;
564 eng_output_redraws_rect_del(void *data __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
569 eng_output_redraws_clear(void *data)
573 re = (Render_Engine *)data;
574 re->win->draw.redraw = 0;
575 // INF("GL: finish update cycle!");
578 /* vsync games - not for now though */
579 #define VSYNC_TO_SCREEN 1
582 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
586 re = (Render_Engine *)data;
587 /* get the upate rect surface - return engine data as dummy */
588 if (!re->win->draw.redraw) return NULL;
589 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
590 // dont need to for egl - eng_window_use() can check for other ctxt's
592 eng_window_use(NULL);
594 eng_window_use(re->win);
595 if (!_re_wincheck(re)) return NULL;
596 evas_gl_common_context_flush(re->win->gl_context);
597 evas_gl_common_context_newframe(re->win->gl_context);
598 if (x) *x = re->win->draw.x1;
599 if (y) *y = re->win->draw.y1;
600 if (w) *w = re->win->draw.x2 - re->win->draw.x1 + 1;
601 if (h) *h = re->win->draw.y2 - re->win->draw.y1 + 1;
602 if (cx) *cx = re->win->draw.x1;
603 if (cy) *cy = re->win->draw.y1;
604 if (cw) *cw = re->win->draw.x2 - re->win->draw.x1 + 1;
605 if (ch) *ch = re->win->draw.y2 - re->win->draw.y1 + 1;
606 return re->win->gl_context->def_surface;
609 //#define FRAMECOUNT 1
615 struct timeval timev;
617 gettimeofday(&timev, NULL);
618 return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
622 static int safe_native = -1;
625 eng_output_redraws_next_update_push(void *data, void *surface __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
629 static double pt = 0.0;
633 re = (Render_Engine *)data;
634 /* put back update surface.. in this case just unflag redraw */
635 if (!_re_wincheck(re)) return;
636 re->win->draw.redraw = 0;
637 re->win->draw.drew = 1;
638 evas_gl_common_context_flush(re->win->gl_context);
639 if (safe_native == -1)
641 const char *s = getenv("EVAS_GL_SAFE_NATIVE");
643 if (s) safe_native = atoi(s);
646 s = (const char *)glGetString(GL_RENDERER);
649 if (strstr(s, "PowerVR SGX 540"))
654 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
655 // this is needed to make sure all previous rendering is flushed to
658 double t0 = get_time();
662 // previous rendering should be done and swapped
663 if (!safe_native) eglWaitNative(EGL_CORE_NATIVE_ENGINE);
665 double t1 = get_time();
667 printf("... %1.5f -> %1.5f | ", ta, tb);
669 // if (eglGetError() != EGL_SUCCESS)
671 // printf("Error: eglWaitNative(EGL_CORE_NATIVE_ENGINE) fail.\n");
674 // previous rendering should be done and swapped
675 if (!safe_native) glXWaitX();
677 //x// printf("frame -> push\n");
681 eng_output_flush(void *data)
685 re = (Render_Engine *)data;
686 if (!_re_wincheck(re)) return;
687 if (!re->win->draw.drew) return;
688 //x// printf("frame -> flush\n");
689 re->win->draw.drew = 0;
690 eng_window_use(re->win);
692 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
694 double t0 = get_time();
698 if (re->info->vsync) eglSwapInterval(re->win->egl_disp, 1);
699 else eglSwapInterval(re->win->egl_disp, 0);
702 if (re->info->callback.pre_swap)
704 re->info->callback.pre_swap(re->info->callback.data, re->evas);
706 eglSwapBuffers(re->win->egl_disp, re->win->egl_surface[0]);
707 if (!safe_native) eglWaitGL();
708 if (re->info->callback.post_swap)
710 re->info->callback.post_swap(re->info->callback.data, re->evas);
713 double t1 = get_time();
714 printf("%1.5f\n", t1 - t0);
716 // if (eglGetError() != EGL_SUCCESS)
718 // printf("Error: eglSwapBuffers() fail.\n");
721 #ifdef VSYNC_TO_SCREEN
722 if ((re->info->vsync)/* || (1)*/)
724 if (glsym_glxSwapIntervalEXT)
728 if (re->info->vsync) glsym_glxSwapIntervalEXT(re->win->disp, re->win->win, 1);
729 else glsym_glxSwapIntervalEXT(re->win->disp, re->win->win, 0);
733 if (glsym_glxSwapIntervalSGI)
737 if (re->info->vsync) glsym_glxSwapIntervalSGI(1);
738 else glsym_glxSwapIntervalSGI(0);
744 if ((glsym_glXGetVideoSync) && (glsym_glXWaitVideoSync))
748 glsym_glXGetVideoSync(&rc);
749 glsym_glXWaitVideoSync(1, 0, &rc);
754 if (re->info->callback.pre_swap)
756 re->info->callback.pre_swap(re->info->callback.data, re->evas);
760 // (re->win->draw.x1 == 0) &&
761 // (re->win->draw.y1 == 0) &&
762 // (re->win->draw.x2 == (re->win->w - 1)) &&
763 // (re->win->draw.y2 == (re->win->h - 1))
767 glXSwapBuffers(re->win->disp, re->win->win);
768 if (!safe_native) glXWaitGL();
773 // FIXME: this doesn't work.. why oh why?
776 // fimxe - reset when done
777 // glEnable(GL_SCISSOR_TEST);
778 glDrawBuffer(GL_FRONT);
780 sx = re->win->draw.x1;
781 sy = re->win->draw.y1;
782 sw = (re->win->draw.x2 - re->win->draw.x1) + 1;
783 sh = (re->win->draw.y2 - re->win->draw.y1) + 1;
784 sy = re->win->h - sy - sh;
786 // glScissor(sx, sy, sw, sh);
787 glRasterPos2i(sx, re->win->h - sy);
788 glCopyPixels(sx, sy, sw, sh, GL_COLOR);
791 // glDisable(GL_SCISSOR_TEST);
792 glDrawBuffer(GL_BACK);
796 if (re->info->callback.post_swap)
798 re->info->callback.post_swap(re->info->callback.data, re->evas);
804 glClearColor(0.0, 0.0, 0.0, 0.0);
805 glClear(GL_COLOR_BUFFER_BIT);
810 eng_output_idle_flush(void *data)
814 re = (Render_Engine *)data;
818 eng_output_dump(void *data)
822 re = (Render_Engine *)data;
823 evas_common_image_image_all_unload();
824 evas_common_font_font_all_unload();
825 evas_gl_common_image_all_unload(re->win->gl_context);
830 eng_context_cutout_add(void *data __UNUSED__, void *context, int x, int y, int w, int h)
832 // Render_Engine *re;
834 // re = (Render_Engine *)data;
835 // re->win->gl_context->dc = context;
836 evas_common_draw_context_add_cutout(context, x, y, w, h);
840 eng_context_cutout_clear(void *data __UNUSED__, void *context)
842 // Render_Engine *re;
844 // re = (Render_Engine *)data;
845 // re->win->gl_context->dc = context;
846 evas_common_draw_context_clear_cutouts(context);
850 eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
854 re = (Render_Engine *)data;
855 eng_window_use(re->win);
856 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
857 re->win->gl_context->dc = context;
858 evas_gl_common_rect_draw(re->win->gl_context, x, y, w, h);
862 eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
866 re = (Render_Engine *)data;
867 eng_window_use(re->win);
868 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
869 re->win->gl_context->dc = context;
870 evas_gl_common_line_draw(re->win->gl_context, x1, y1, x2, y2);
874 eng_polygon_point_add(void *data, void *context __UNUSED__, void *polygon, int x, int y)
878 re = (Render_Engine *)data;
879 return evas_gl_common_poly_point_add(polygon, x, y);
883 eng_polygon_points_clear(void *data, void *context __UNUSED__, void *polygon)
887 re = (Render_Engine *)data;
888 return evas_gl_common_poly_points_clear(polygon);
892 eng_polygon_draw(void *data, void *context, void *surface __UNUSED__, void *polygon, int x, int y)
896 re = (Render_Engine *)data;
897 eng_window_use(re->win);
898 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
899 re->win->gl_context->dc = context;
900 evas_gl_common_poly_draw(re->win->gl_context, polygon, x, y);
904 eng_image_alpha_get(void *data __UNUSED__, void *image)
906 // Render_Engine *re;
909 // re = (Render_Engine *)data;
910 if (!image) return 1;
916 eng_image_colorspace_get(void *data __UNUSED__, void *image)
918 // Render_Engine *re;
921 // re = (Render_Engine *)data;
922 if (!image) return EVAS_COLORSPACE_ARGB8888;
928 eng_image_mask_create(void *data __UNUSED__, void *image)
934 if (!im->im->image.data)
935 evas_cache_image_load_data(&im->im->cache_entry);
937 im->tex = evas_gl_common_texture_new(im->gc, im->im);
942 eng_image_alpha_set(void *data, void *image, int has_alpha)
947 re = (Render_Engine *)data;
948 if (!image) return NULL;
950 if (im->alpha == has_alpha) return image;
953 im->alpha = has_alpha;
956 eng_window_use(re->win);
957 if ((im->tex) && (im->tex->pt->dyn.img))
959 im->alpha = has_alpha;
960 im->tex->alpha = im->alpha;
963 /* FIXME: can move to gl_common */
964 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
965 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
966 else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
967 if (im->references > 1)
969 Evas_GL_Image *im_new;
971 im_new = evas_gl_common_image_new_from_copied_data
972 (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
974 eng_image_alpha_get(data, image),
975 eng_image_colorspace_get(data, image));
976 if (!im_new) return im;
977 evas_gl_common_image_free(im);
981 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
982 return evas_gl_common_image_alpha_set(im, has_alpha ? 1 : 0);
983 // im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
988 eng_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
990 // Render_Engine *re;
992 // re = (Render_Engine *)data;
997 eng_image_border_get(void *data __UNUSED__, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
999 // Render_Engine *re;
1001 // re = (Render_Engine *)data;
1005 eng_image_comment_get(void *data __UNUSED__, void *image, char *key __UNUSED__)
1007 // Render_Engine *re;
1010 // re = (Render_Engine *)data;
1011 if (!image) return NULL;
1013 if (!im->im) return NULL;
1014 return im->im->info.comment;
1018 eng_image_format_get(void *data __UNUSED__, void *image)
1020 // Render_Engine *re;
1023 // re = (Render_Engine *)data;
1029 eng_image_colorspace_set(void *data, void *image, int cspace)
1034 re = (Render_Engine *)data;
1037 if (im->native.data) return;
1038 /* FIXME: can move to gl_common */
1039 if (im->cs.space == cspace) return;
1040 eng_window_use(re->win);
1041 evas_cache_image_colorspace(&im->im->cache_entry, cspace);
1044 case EVAS_COLORSPACE_ARGB8888:
1047 if (!im->cs.no_free) free(im->cs.data);
1052 case EVAS_COLORSPACE_YCBCR422P601_PL:
1053 case EVAS_COLORSPACE_YCBCR422P709_PL:
1054 if (im->tex) evas_gl_common_texture_free(im->tex);
1058 if (!im->cs.no_free) free(im->cs.data);
1060 if (im->im->cache_entry.h > 0)
1062 calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
1071 im->cs.space = cspace;
1074 /////////////////////////////////////////////////////////////////////////
1077 typedef struct _Native Native;
1081 Evas_Native_Surface ns;
1085 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1093 // FIXME: this is enabled so updates happen - but its SLOOOOOOOOOOOOOOOW
1094 // (i am sure this is the reason) not to mention seemingly superfluous. but
1095 // i need to enable it for it to work on fglrx at least. havent tried nvidia.
1097 // why is this the case? does anyone know? has anyone tried it on other gfx
1100 //#define GLX_TEX_PIXMAP_RECREATE 1
1103 _native_bind_cb(void *data, void *image)
1105 Evas_GL_Image *im = image;
1106 Native *n = im->native.data;
1108 if (n->ns.type == EVAS_NATIVE_SURFACE_X11)
1110 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1113 if (glsym_glEGLImageTargetTexture2DOES)
1115 glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, n->egl_surface);
1116 if (eglGetError() != EGL_SUCCESS)
1117 ERR("glEGLImageTargetTexture2DOES() failed.");
1120 ERR("Try glEGLImageTargetTexture2DOES on EGL with no support");
1123 # ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1124 Render_Engine *re = data;
1126 if (glsym_glXBindTexImage)
1128 glsym_glXBindTexImage(re->win->disp, n->glx_pixmap,
1129 GLX_FRONT_LEFT_EXT, NULL);
1130 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1133 ERR("Try glXBindTexImage on GLX with no support");
1137 else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
1139 glBindTexture(GL_TEXTURE_2D, n->ns.data.opengl.texture_id);
1140 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1147 _native_unbind_cb(void *data, void *image)
1149 Evas_GL_Image *im = image;
1150 Native *n = im->native.data;
1152 if (n->ns.type == EVAS_NATIVE_SURFACE_X11)
1154 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1157 # ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1158 Render_Engine *re = data;
1160 if (glsym_glXReleaseTexImage)
1162 glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap,
1163 GLX_FRONT_LEFT_EXT);
1164 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1167 ERR("Try glXReleaseTexImage on GLX with no support");
1171 else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
1173 glBindTexture(GL_TEXTURE_2D, 0);
1174 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1181 _native_free_cb(void *data, void *image)
1183 Render_Engine *re = data;
1184 Evas_GL_Image *im = image;
1185 Native *n = im->native.data;
1186 uint32_t pmid, texid;
1188 if (n->ns.type == EVAS_NATIVE_SURFACE_X11)
1191 eina_hash_del(re->win->gl_context->shared->native_pm_hash, &pmid, im);
1192 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1195 if (glsym_eglDestroyImage)
1197 glsym_eglDestroyImage(re->win->egl_disp,
1199 if (eglGetError() != EGL_SUCCESS)
1200 ERR("eglDestroyImage() failed.");
1203 ERR("Try eglDestroyImage on EGL with no support");
1206 # ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1209 if (im->native.loose)
1211 if (glsym_glXReleaseTexImage)
1213 glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap,
1214 GLX_FRONT_LEFT_EXT);
1215 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1218 ERR("Try glXReleaseTexImage on GLX with no support");
1220 if (glsym_glXDestroyPixmap)
1222 glsym_glXDestroyPixmap(re->win->disp, n->glx_pixmap);
1223 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
1226 ERR("Try glXDestroyPixmap on GLX with no support");
1232 else if (n->ns.type == EVAS_NATIVE_SURFACE_OPENGL)
1234 texid = n->ns.data.opengl.texture_id;
1235 eina_hash_del(re->win->gl_context->shared->native_tex_hash, &texid, im);
1237 im->native.data = NULL;
1238 im->native.func.data = NULL;
1239 im->native.func.bind = NULL;
1240 im->native.func.unbind = NULL;
1241 im->native.func.free = NULL;
1246 eng_image_native_set(void *data, void *image, void *native)
1248 Render_Engine *re = (Render_Engine *)data;
1249 Evas_Native_Surface *ns = native;
1250 Evas_GL_Image *im = image, *im2 = NULL;
1254 uint32_t pmid, texid;
1255 unsigned int tex = 0;
1256 unsigned int fbo = 0;
1260 if ((!ns) && (ns->type == EVAS_NATIVE_SURFACE_OPENGL))
1262 im = evas_gl_common_image_new_from_data(re->win->gl_context,
1266 EVAS_COLORSPACE_ARGB8888);
1274 if (ns->type == EVAS_NATIVE_SURFACE_X11)
1276 vis = ns->data.x11.visual;
1277 pm = ns->data.x11.pixmap;
1278 if (im->native.data)
1280 Evas_Native_Surface *ens = im->native.data;
1281 if ((ens->data.x11.visual == vis) &&
1282 (ens->data.x11.pixmap == pm))
1286 else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
1288 tex = ns->data.opengl.texture_id;
1289 fbo = ns->data.opengl.framebuffer_id;
1290 if (im->native.data)
1292 Evas_Native_Surface *ens = im->native.data;
1293 if ((ens->data.opengl.texture_id == tex) &&
1294 (ens->data.opengl.framebuffer_id == fbo))
1299 if ((!ns) && (!im->native.data)) return im;
1301 eng_window_use(re->win);
1303 if (im->native.data)
1305 if (im->native.func.free)
1306 im->native.func.free(im->native.func.data, im);
1307 evas_gl_common_image_native_disable(im);
1312 if (ns->type == EVAS_NATIVE_SURFACE_X11)
1315 im2 = eina_hash_find(re->win->gl_context->shared->native_pm_hash, &pmid);
1316 if (im2 == im) return im;
1319 n = im2->native.data;
1322 evas_gl_common_image_ref(im2);
1323 evas_gl_common_image_free(im);
1328 else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
1331 im2 = eina_hash_find(re->win->gl_context->shared->native_tex_hash, &texid);
1332 if (im2 == im) return im;
1335 n = im2->native.data;
1338 evas_gl_common_image_ref(im2);
1339 evas_gl_common_image_free(im);
1345 im2 = evas_gl_common_image_new_from_data(re->win->gl_context,
1346 im->w, im->h, NULL, im->alpha,
1347 EVAS_COLORSPACE_ARGB8888);
1348 evas_gl_common_image_free(im);
1350 if (ns->type == EVAS_NATIVE_SURFACE_X11)
1352 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1355 n = calloc(1, sizeof(Native));
1358 EGLConfig egl_config;
1359 int config_attrs[20];
1360 int num_config, i = 0;
1362 eina_hash_add(re->win->gl_context->shared->native_pm_hash, &pmid, im);
1364 config_attrs[i++] = EGL_RED_SIZE;
1365 config_attrs[i++] = 8;
1366 config_attrs[i++] = EGL_GREEN_SIZE;
1367 config_attrs[i++] = 8;
1368 config_attrs[i++] = EGL_BLUE_SIZE;
1369 config_attrs[i++] = 8;
1370 config_attrs[i++] = EGL_ALPHA_SIZE;
1371 config_attrs[i++] = 8;
1372 config_attrs[i++] = EGL_DEPTH_SIZE;
1373 config_attrs[i++] = 0;
1374 config_attrs[i++] = EGL_STENCIL_SIZE;
1375 config_attrs[i++] = 0;
1376 config_attrs[i++] = EGL_RENDERABLE_TYPE;
1377 config_attrs[i++] = EGL_OPENGL_ES2_BIT;
1378 config_attrs[i++] = EGL_SURFACE_TYPE;
1379 config_attrs[i++] = EGL_PIXMAP_BIT;
1380 config_attrs[i++] = EGL_NONE;
1382 if (!eglChooseConfig(re->win->egl_disp, config_attrs,
1383 &egl_config, 1, &num_config))
1384 ERR("eglChooseConfig() failed for pixmap 0x%x, num_config = %i", (unsigned int)pm, num_config);
1385 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
1388 if (glsym_eglCreateImage)
1389 n->egl_surface = glsym_eglCreateImage(re->win->egl_disp,
1391 EGL_NATIVE_PIXMAP_KHR,
1395 ERR("Try eglCreateImage on EGL with no support");
1396 if (!n->egl_surface)
1397 ERR("eglCreatePixmapSurface() for 0x%x failed", (unsigned int)pm);
1398 im->native.yinvert = 1;
1399 im->native.loose = 0;
1400 im->native.data = n;
1401 im->native.func.data = re;
1402 im->native.func.bind = _native_bind_cb;
1403 im->native.func.unbind = _native_unbind_cb;
1404 im->native.func.free = _native_free_cb;
1405 im->native.target = GL_TEXTURE_2D;
1406 im->native.mipmap = 0;
1407 evas_gl_common_image_native_enable(im);
1411 # ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1415 unsigned int w, h, depth = 32, border;
1418 // fixme: round trip :(
1419 XGetGeometry(re->win->disp, pm, &wdummy, &dummy, &dummy,
1420 &w, &h, &border, &depth);
1421 n = calloc(1, sizeof(Native));
1425 unsigned int target = 0;
1428 eina_hash_add(re->win->gl_context->shared->native_pm_hash, &pmid, im);
1429 if ((re->win->depth_cfg[depth].tex_target &
1430 GLX_TEXTURE_2D_BIT_EXT)
1431 // && (1) // we assume npo2 for now
1432 // size is pow2 || mnpo2 supported
1434 target = GLX_TEXTURE_2D_EXT;
1435 else if ((re->win->depth_cfg[depth].tex_target &
1436 GLX_TEXTURE_RECTANGLE_BIT_EXT))
1438 ERR("rect!!! (not handled)");
1439 target = GLX_TEXTURE_RECTANGLE_EXT;
1443 ERR("broken text-from-pixmap");
1444 if (!(re->win->depth_cfg[depth].tex_target &
1445 GLX_TEXTURE_2D_BIT_EXT))
1446 target = GLX_TEXTURE_RECTANGLE_EXT;
1447 else if (!(re->win->depth_cfg[depth].tex_target &
1448 GLX_TEXTURE_RECTANGLE_BIT_EXT))
1449 target = GLX_TEXTURE_2D_EXT;
1453 pixmap_att[i++] = GLX_TEXTURE_FORMAT_EXT;
1454 pixmap_att[i++] = re->win->depth_cfg[depth].tex_format;
1455 pixmap_att[i++] = GLX_MIPMAP_TEXTURE_EXT;
1456 pixmap_att[i++] = re->win->depth_cfg[depth].mipmap;
1460 pixmap_att[i++] = GLX_TEXTURE_TARGET_EXT;
1461 pixmap_att[i++] = target;
1464 pixmap_att[i++] = 0;
1466 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
1469 n->fbc = re->win->depth_cfg[depth].fbc;
1470 if (glsym_glXCreatePixmap)
1471 n->glx_pixmap = glsym_glXCreatePixmap(re->win->disp,
1476 ERR("Try glXCreatePixmap on GLX with no support");
1479 // printf("%p: new native texture for %x | %4i x %4i @ %2i = %p\n",
1480 // n, pm, w, h, depth, n->glx_pixmap);
1483 ERR("no target :(");
1484 if (glsym_glXQueryDrawable)
1485 glsym_glXQueryDrawable(re->win->disp,
1487 GLX_TEXTURE_TARGET_EXT,
1490 if (target == GLX_TEXTURE_2D_EXT)
1492 im->native.target = GL_TEXTURE_2D;
1493 im->native.mipmap = re->win->depth_cfg[depth].mipmap;
1495 # ifdef GL_TEXTURE_RECTANGLE_ARB
1496 else if (target == GLX_TEXTURE_RECTANGLE_EXT)
1498 im->native.target = GL_TEXTURE_RECTANGLE_ARB;
1499 im->native.mipmap = 0;
1504 im->native.target = GL_TEXTURE_2D;
1505 im->native.mipmap = 0;
1506 ERR("still unknown target");
1510 ERR("GLX Pixmap create fail");
1511 im->native.yinvert = re->win->depth_cfg[depth].yinvert;
1512 im->native.loose = re->win->detected.loose_binding;
1513 im->native.data = n;
1514 im->native.func.data = re;
1515 im->native.func.bind = _native_bind_cb;
1516 im->native.func.unbind = _native_unbind_cb;
1517 im->native.func.free = _native_free_cb;
1519 evas_gl_common_image_native_enable(im);
1525 else if (ns->type == EVAS_NATIVE_SURFACE_OPENGL)
1529 n = calloc(1, sizeof(Native));
1532 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
1534 eina_hash_add(re->win->gl_context->shared->native_tex_hash, &texid, im);
1538 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1545 im->native.yinvert = 0;
1546 im->native.loose = 0;
1547 im->native.data = n;
1548 im->native.func.data = re;
1549 im->native.func.bind = _native_bind_cb;
1550 im->native.func.unbind = _native_unbind_cb;
1551 im->native.func.free = _native_free_cb;
1552 im->native.target = GL_TEXTURE_2D;
1553 im->native.mipmap = 0;
1555 // FIXME: need to implement mapping sub texture regions
1556 // x, y, w, h for possible texture atlasing
1558 evas_gl_common_image_native_enable(im);
1567 eng_image_native_get(void *data __UNUSED__, void *image)
1569 Evas_GL_Image *im = image;
1571 if (!im) return NULL;
1572 n = im->native.data;
1573 if (!n) return NULL;
1577 #if 0 // filtering disabled
1579 eng_image_draw_filtered(void *data, void *context, void *surface,
1580 void *image, Evas_Filter_Info *filter)
1582 Render_Engine *re = data;
1585 eng_window_use(re->win);
1586 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
1587 re->win->gl_context->dc = context;
1589 evas_gl_common_filter_draw(re->win->gl_context, image, filter);
1592 static Filtered_Image *
1593 eng_image_filtered_get(void *im, uint8_t *key, size_t keylen)
1595 return evas_gl_common_image_filtered_get(im, key, keylen);
1598 static Filtered_Image *
1599 eng_image_filtered_save(void *im, void *fim, uint8_t *key, size_t keylen)
1601 return evas_gl_common_image_filtered_save(im, fim, key, keylen);
1605 eng_image_filtered_free(void *im, Filtered_Image *fim)
1607 evas_gl_common_image_filtered_free(im, fim);
1614 /////////////////////////////////////////////////////////////////////////
1617 eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
1621 re = (Render_Engine *)data;
1622 *error = EVAS_LOAD_ERROR_NONE;
1623 eng_window_use(re->win);
1624 return evas_gl_common_image_load(re->win->gl_context, file, key, lo, error);
1628 eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
1632 re = (Render_Engine *)data;
1633 eng_window_use(re->win);
1634 return evas_gl_common_image_new_from_data(re->win->gl_context, w, h, image_data, alpha, cspace);
1638 eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
1642 re = (Render_Engine *)data;
1643 eng_window_use(re->win);
1644 return evas_gl_common_image_new_from_copied_data(re->win->gl_context, w, h, image_data, alpha, cspace);
1648 eng_image_free(void *data, void *image)
1652 re = (Render_Engine *)data;
1654 eng_window_use(re->win);
1655 evas_gl_common_image_free(image);
1659 eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
1667 if (w) *w = ((Evas_GL_Image *)image)->w;
1668 if (h) *h = ((Evas_GL_Image *)image)->h;
1672 eng_image_size_set(void *data, void *image, int w, int h)
1675 Evas_GL_Image *im = image;
1676 Evas_GL_Image *im_old;
1678 re = (Render_Engine *)data;
1679 if (!im) return NULL;
1680 if (im->native.data)
1686 eng_window_use(re->win);
1687 if ((im->tex) && (im->tex->pt->dyn.img))
1689 evas_gl_common_texture_free(im->tex);
1693 im->tex = evas_gl_common_texture_dynamic_new(im->gc, im);
1697 if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) ||
1698 (eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P709_PL))
1701 ((int)im_old->im->cache_entry.w == w) &&
1702 ((int)im_old->im->cache_entry.h == h))
1706 im = evas_gl_common_image_new(re->win->gl_context, w, h,
1707 eng_image_alpha_get(data, image),
1708 eng_image_colorspace_get(data, image));
1710 evas_common_load_image_data_from_file(im_old->im);
1711 if (im_old->im->image->data)
1713 evas_common_blit_rectangle(im_old->im, im->im, 0, 0, w, h, 0, 0);
1714 evas_common_cpu_end_opt();
1717 evas_gl_common_image_free(im_old);
1720 im = evas_gl_common_image_new(re->win->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
1725 eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
1728 Evas_GL_Image *im = image;
1730 re = (Render_Engine *)data;
1731 if (!image) return NULL;
1732 if (im->native.data) return image;
1733 eng_window_use(re->win);
1734 evas_gl_common_image_dirty(image, x, y, w, h);
1739 eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data, int *err)
1745 re = (Render_Engine *)data;
1749 if (err) *err = EVAS_LOAD_ERROR_GENERIC;
1753 if (im->native.data)
1756 if (err) *err = EVAS_LOAD_ERROR_NONE;
1759 if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.data))
1761 *image_data = im->tex->pt->dyn.data;
1762 if (err) *err = EVAS_LOAD_ERROR_NONE;
1765 eng_window_use(re->win);
1766 error = evas_cache_image_load_data(&im->im->cache_entry);
1767 switch (im->cs.space)
1769 case EVAS_COLORSPACE_ARGB8888:
1772 if (im->references > 1)
1774 Evas_GL_Image *im_new;
1776 im_new = evas_gl_common_image_new_from_copied_data
1777 (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
1779 eng_image_alpha_get(data, image),
1780 eng_image_colorspace_get(data, image));
1784 if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
1787 evas_gl_common_image_free(im);
1791 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1793 *image_data = im->im->image.data;
1795 case EVAS_COLORSPACE_YCBCR422P601_PL:
1796 case EVAS_COLORSPACE_YCBCR422P709_PL:
1797 *image_data = im->cs.data;
1803 if (err) *err = error;
1808 eng_image_data_put(void *data, void *image, DATA32 *image_data)
1811 Evas_GL_Image *im, *im2;
1813 re = (Render_Engine *)data;
1814 if (!image) return NULL;
1816 if (im->native.data) return image;
1817 eng_window_use(re->win);
1818 if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.data))
1820 if (im->tex->pt->dyn.data == image_data)
1828 w = im->im->cache_entry.w;
1829 h = im->im->cache_entry.h;
1830 im2 = eng_image_new_from_data(data, w, h, image_data,
1831 eng_image_alpha_get(data, image),
1832 eng_image_colorspace_get(data, image));
1833 if (!im2) return im;
1834 evas_gl_common_image_free(im);
1836 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1840 switch (im->cs.space)
1842 case EVAS_COLORSPACE_ARGB8888:
1843 if (image_data != im->im->image.data)
1847 w = im->im->cache_entry.w;
1848 h = im->im->cache_entry.h;
1849 im2 = eng_image_new_from_data(data, w, h, image_data,
1850 eng_image_alpha_get(data, image),
1851 eng_image_colorspace_get(data, image));
1852 if (!im2) return im;
1853 evas_gl_common_image_free(im);
1857 case EVAS_COLORSPACE_YCBCR422P601_PL:
1858 case EVAS_COLORSPACE_YCBCR422P709_PL:
1859 if (image_data != im->cs.data)
1863 if (!im->cs.no_free) free(im->cs.data);
1865 im->cs.data = image_data;
1872 /* hmmm - but if we wrote... why bother? */
1873 evas_gl_common_image_dirty(im, 0, 0, 0, 0);
1878 eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
1880 Evas_GL_Image *gim = image;
1884 if (gim->native.data) return;
1885 im = (RGBA_Image *)gim->im;
1887 evas_cache_image_preload_data(&im->cache_entry, target);
1891 eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
1893 Evas_GL_Image *gim = image;
1897 if (gim->native.data) return;
1898 im = (RGBA_Image *)gim->im;
1900 evas_cache_image_preload_cancel(&im->cache_entry, target);
1904 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)
1908 re = (Render_Engine *)data;
1910 eng_window_use(re->win);
1911 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
1912 re->win->gl_context->dc = context;
1913 evas_gl_common_image_draw(re->win->gl_context, image,
1914 src_x, src_y, src_w, src_h,
1915 dst_x, dst_y, dst_w, dst_h,
1920 eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
1922 if (image) evas_gl_common_image_scale_hint_set(image, hint);
1926 eng_image_scale_hint_get(void *data __UNUSED__, void *image)
1928 Evas_GL_Image *gim = image;
1929 if (!gim) return EVAS_IMAGE_SCALE_HINT_NONE;
1930 return gim->scale_hint;
1934 eng_image_map_draw(void *data, void *context, void *surface, void *image, int npoints, RGBA_Map_Point *p, int smooth, int level)
1936 Evas_GL_Image *gim = image;
1939 re = (Render_Engine *)data;
1941 eng_window_use(re->win);
1942 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
1943 re->win->gl_context->dc = context;
1946 // FIXME: nash - you didn't fix this
1949 if ((p[0].x == p[3].x) &&
1950 (p[1].x == p[2].x) &&
1951 (p[0].y == p[1].y) &&
1952 (p[3].y == p[2].y) &&
1953 (p[0].x <= p[1].x) &&
1954 (p[0].y <= p[2].y) &&
1957 (p[1].u == (gim->w << FP)) &&
1959 (p[2].u == (gim->w << FP)) &&
1960 (p[2].v == (gim->h << FP)) &&
1962 (p[3].v == (gim->h << FP)) &&
1963 (p[0].col == 0xffffffff) &&
1964 (p[1].col == 0xffffffff) &&
1965 (p[2].col == 0xffffffff) &&
1966 (p[3].col == 0xffffffff))
1972 dw = (p[2].x >> FP) - dx;
1973 dh = (p[2].y >> FP) - dy;
1974 eng_image_draw(data, context, surface, image,
1975 0, 0, gim->w, gim->h, dx, dy, dw, dh, smooth);
1979 evas_gl_common_image_map_draw(re->win->gl_context, image, npoints, p,
1985 eng_image_map_surface_new(void *data, int w, int h, int alpha)
1989 re = (Render_Engine *)data;
1990 return evas_gl_common_image_surface_new(re->win->gl_context, w, h, alpha);
1994 eng_image_map_surface_free(void *data __UNUSED__, void *surface)
1996 evas_gl_common_image_free(surface);
2000 eng_image_content_hint_set(void *data __UNUSED__, void *image, int hint)
2002 if (image) evas_gl_common_image_content_hint_set(image, hint);
2006 eng_image_content_hint_get(void *data __UNUSED__, void *image)
2008 Evas_GL_Image *gim = image;
2009 if (!gim) return EVAS_IMAGE_CONTENT_HINT_NONE;
2010 return gim->content_hint;
2014 eng_image_cache_flush(void *data)
2019 re = (Render_Engine *)data;
2021 tmp_size = evas_common_image_get_cache();
2022 evas_common_image_set_cache(0);
2023 evas_common_rgba_image_scalecache_flush();
2024 evas_gl_common_image_cache_flush(re->win->gl_context);
2025 evas_common_image_set_cache(tmp_size);
2029 eng_image_cache_set(void *data, int bytes)
2033 re = (Render_Engine *)data;
2034 evas_common_image_set_cache(bytes);
2035 evas_common_rgba_image_scalecache_size_set(bytes);
2036 evas_gl_common_image_cache_flush(re->win->gl_context);
2040 eng_image_cache_get(void *data __UNUSED__)
2042 return evas_common_image_get_cache();
2046 eng_image_stride_get(void *data __UNUSED__, void *image, int *stride)
2048 Evas_GL_Image *im = image;
2050 *stride = im->w * 4;
2051 if ((im->tex) && (im->tex->pt->dyn.img))
2053 *stride = im->tex->pt->dyn.w * 4;
2054 // FIXME: for other image formats (yuv etc.) different stride needed
2059 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)
2063 re = (Render_Engine *)data;
2064 eng_window_use(re->win);
2065 evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
2066 re->win->gl_context->dc = context;
2068 // FIXME: put im into context so we can free it
2069 static RGBA_Image *im = NULL;
2072 im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
2073 im->cache_entry.w = re->win->w;
2074 im->cache_entry.h = re->win->h;
2075 evas_common_draw_context_font_ext_set(context,
2076 re->win->gl_context,
2077 evas_gl_font_texture_new,
2078 evas_gl_font_texture_free,
2079 evas_gl_font_texture_draw);
2080 evas_common_font_draw(im, context, (RGBA_Font *) font, x, y,
2082 evas_common_draw_context_font_ext_set(context,
2091 eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
2093 // FIXME: support ARGB gl targets!!!
2098 _set_internal_config(Render_Engine_GL_Surface *sfc, Evas_GL_Config *cfg)
2100 // Also initialize pixel format here as well...
2101 switch(cfg->color_format)
2104 sfc->rt_fmt = GL_RGB;
2105 sfc->rt_internal_fmt = GL_RGB;
2107 case EVAS_GL_RGBA_8:
2108 sfc->rt_fmt = GL_RGBA;
2109 sfc->rt_internal_fmt = GL_RGBA;
2111 case EVAS_GL_RGB_32:
2112 // Only supported on some hw
2113 // Fill it in later...
2114 case EVAS_GL_RGBA_32:
2115 // Only supported on some hw
2116 // Fill it in later...
2118 ERR("Invalid Color Format!");
2122 switch(cfg->depth_bits)
2124 case EVAS_GL_DEPTH_NONE:
2126 case EVAS_GL_DEPTH_BIT_8:
2127 case EVAS_GL_DEPTH_BIT_16:
2128 case EVAS_GL_DEPTH_BIT_24:
2129 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2130 // 24 bit doesn't work... just cover it with 16 for now..
2131 sfc->rb_depth_fmt = GL_DEPTH_COMPONENT16;
2133 sfc->rb_depth_fmt = GL_DEPTH_COMPONENT;
2136 case EVAS_GL_DEPTH_BIT_32:
2138 ERR("Unsupported Depth Bits Format!");
2142 switch(cfg->stencil_bits)
2144 case EVAS_GL_STENCIL_NONE:
2146 case EVAS_GL_STENCIL_BIT_1:
2147 case EVAS_GL_STENCIL_BIT_2:
2148 case EVAS_GL_STENCIL_BIT_4:
2149 case EVAS_GL_STENCIL_BIT_8:
2150 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2151 sfc->rb_stencil_fmt = GL_STENCIL_INDEX8;
2153 sfc->rb_stencil_fmt = GL_STENCIL_INDEX;
2156 case EVAS_GL_STENCIL_BIT_16:
2158 ERR("Unsupported Stencil Bits Format!");
2162 // Do Packed Depth24_Stencil8 Later...
2168 _create_rt_buffers(Render_Engine *data __UNUSED__,
2169 Render_Engine_GL_Surface *sfc)
2171 // Render Target texture
2172 glGenTextures(1, &sfc->rt_tex );
2173 glBindTexture(GL_TEXTURE_2D, sfc->rt_tex );
2174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2175 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2176 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2177 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2178 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sfc->w, sfc->h, 0,
2179 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
2180 glBindTexture(GL_TEXTURE_2D, 0);
2182 // Depth RenderBuffer - Create storage here...
2183 if (sfc->depth_bits != EVAS_GL_DEPTH_NONE)
2185 glGenRenderbuffers(1, &sfc->rb_depth);
2186 glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth);
2187 glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_depth_fmt,
2189 glBindRenderbuffer(GL_RENDERBUFFER, 0);
2192 // Stencil RenderBuffer - Create Storage here...
2193 if (sfc->stencil_bits != EVAS_GL_STENCIL_NONE)
2195 glGenRenderbuffers(1, &sfc->rb_stencil);
2196 glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_stencil);
2197 glRenderbufferStorage(GL_RENDERBUFFER, sfc->rb_stencil_fmt,
2199 glBindRenderbuffer(GL_RENDERBUFFER, 0);
2206 _attach_fbo_surface(Render_Engine *data __UNUSED__,
2207 Render_Engine_GL_Surface *sfc,
2208 Render_Engine_GL_Context *ctx)
2213 glBindFramebuffer(GL_FRAMEBUFFER, ctx->fbo);
2214 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2215 GL_TEXTURE_2D, sfc->rt_tex, 0);
2217 // Depth RenderBuffer - Attach it to FBO
2218 if (sfc->depth_bits != EVAS_GL_DEPTH_NONE)
2220 glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_depth);
2221 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
2222 GL_RENDERBUFFER, sfc->rb_depth);
2223 glBindRenderbuffer(GL_RENDERBUFFER, 0);
2226 // Stencil RenderBuffer - Attach it to FBO
2227 if (sfc->stencil_bits != EVAS_GL_STENCIL_NONE)
2229 glBindRenderbuffer(GL_RENDERBUFFER, sfc->rb_stencil);
2230 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
2231 GL_RENDERBUFFER, sfc->rb_stencil);
2232 glBindRenderbuffer(GL_RENDERBUFFER, 0);
2235 // Check FBO for completeness
2236 fb_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
2237 if (fb_status != GL_FRAMEBUFFER_COMPLETE)
2239 ERR("FBO not complete!");
2247 eng_gl_surface_create(void *data, void *config, int w, int h)
2250 Render_Engine_GL_Surface *sfc;
2251 Evas_GL_Config *cfg;
2254 sfc = calloc(1, sizeof(Render_Engine_GL_Surface));
2256 if (!sfc) return NULL;
2258 re = (Render_Engine *)data;
2259 cfg = (Evas_GL_Config *)config;
2261 sfc->initialized = 0;
2262 sfc->fbo_attached = 0;
2265 sfc->depth_bits = cfg->depth_bits;
2266 sfc->stencil_bits = cfg->stencil_bits;
2269 sfc->rb_stencil = 0;
2271 // Set the internal format based on the config
2272 if (!_set_internal_config(sfc, cfg))
2274 ERR("Unsupported Format!");
2279 // Create Render Target Texture/Buffers if not initialized
2280 if (!sfc->initialized)
2282 // I'm using evas's original context to create the render target texture
2283 // This is to prevent awkwardness in using native_surface_get() function
2284 // If the rt texture creation is deferred till the context is created and
2285 // make_current called, the user can't call native_surface_get() right
2286 // after the surface is created. hence this is done here using evas' context.
2287 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2288 ret = eglMakeCurrent(re->win->egl_disp, re->win->egl_surface[0], re->win->egl_surface[0], re->win->egl_context[0]);
2290 ret = glXMakeCurrent(re->info->info.display, re->win->win, re->win->context);
2294 ERR("xxxMakeCurrent() failed!");
2299 // Create Render texture
2300 if (!_create_rt_buffers(re, sfc))
2302 ERR("_create_rt_buffers() failed.");
2307 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2308 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE,
2309 EGL_NO_SURFACE, EGL_NO_CONTEXT);
2311 ret = glXMakeCurrent(re->info->info.display, None, NULL);
2315 ERR("xxxMakeCurrent() failed!");
2319 sfc->initialized = 1;
2326 eng_gl_surface_destroy(void *data, void *surface)
2329 Render_Engine_GL_Surface *sfc;
2332 re = (Render_Engine *)data;
2333 sfc = (Render_Engine_GL_Surface*)surface;
2335 // I'm using evas's original context to delete the created fbo and texture
2336 // This is because the fbo/texture was created in the user created context
2337 // but the context can be destroyed already...
2338 // I don't think this is the best way but at least for now this is A WAY.
2339 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2340 ret = eglMakeCurrent(re->win->egl_disp, re->win->egl_surface[0], re->win->egl_surface[0], re->win->egl_context[0]);
2342 ret = glXMakeCurrent(re->info->info.display, re->win->win, re->win->context);
2346 ERR("xxxMakeCurrent() failed!");
2350 // Delete FBO/RBO and Texture here
2351 if (glIsTexture(sfc->rt_tex))
2352 glDeleteTextures(1, &sfc->rt_tex);
2354 if (glIsBuffer(sfc->rb_depth))
2355 glDeleteRenderbuffers(1, &sfc->rb_depth);
2357 if (glIsBuffer(sfc->rb_stencil))
2358 glDeleteRenderbuffers(1, &sfc->rb_stencil);
2361 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2362 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
2364 ret = glXMakeCurrent(re->info->info.display, None, NULL);
2368 ERR("xxxMakeCurrent() failed!");
2379 eng_gl_context_create(void *data, void *share_context)
2382 Render_Engine_GL_Context *ctx;
2383 Render_Engine_GL_Context *share_ctx;
2384 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2385 int context_attrs[3];
2388 ctx = calloc(1, sizeof(Render_Engine_GL_Context));
2390 if (!ctx) return NULL;
2392 re = (Render_Engine *)data;
2393 share_ctx = (Render_Engine_GL_Context *)share_context;
2395 // Set the share context to Evas' GL context if share_context is NULL.
2396 // Otherwise set it to the given share_context.
2397 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2399 context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
2400 context_attrs[1] = 2;
2401 context_attrs[2] = EGL_NONE;
2405 ctx->context = eglCreateContext(re->win->egl_disp,
2406 re->win->egl_config,
2407 share_ctx->context, // Share Context
2412 ctx->context = eglCreateContext(re->win->egl_disp,
2413 re->win->egl_config,
2414 re->win->egl_context[0], // Evas' GL Context
2420 ERR("eglCreateContext() fail. code=%#x", eglGetError());
2427 ctx->context = glXCreateContext(re->info->info.display,
2428 re->win->visualinfo,
2429 share_ctx->context, // Share Context
2434 ctx->context = glXCreateContext(re->info->info.display,
2435 re->win->visualinfo,
2436 re->win->context, // Evas' GL Context
2442 ERR("glXCreateContext() fail.");
2447 ctx->initialized = 0;
2449 ctx->current_sfc = NULL;
2455 eng_gl_context_destroy(void *data, void *context)
2458 Render_Engine_GL_Context *ctx;
2461 re = (Render_Engine *)data;
2462 ctx = (Render_Engine_GL_Context*)context;
2464 // 1. Do a make current with the given context
2465 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2466 ret = eglMakeCurrent(re->win->egl_disp, re->win->egl_surface[0],
2467 re->win->egl_surface[0], ctx->context);
2469 ret = glXMakeCurrent(re->info->info.display, re->win->win,
2474 ERR("xxxMakeCurrent() failed!");
2478 // 2. Delete the FBO
2479 if (glIsBuffer(ctx->fbo))
2480 glDeleteBuffers(1, &ctx->fbo);
2482 // 3. Destroy the Context
2483 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2484 eglDestroyContext(re->win->egl_disp, ctx->context);
2486 ctx->context = EGL_NO_CONTEXT;
2488 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE,
2489 EGL_NO_SURFACE, EGL_NO_CONTEXT);
2491 glXDestroyContext(re->info->info.display, ctx->context);
2495 ret = glXMakeCurrent(re->info->info.display, None, NULL);
2499 ERR("xxxMakeCurrent() failed!");
2510 eng_gl_make_current(void *data, void *surface, void *context)
2513 Render_Engine_GL_Surface *sfc;
2514 Render_Engine_GL_Context *ctx;
2517 re = (Render_Engine *)data;
2518 sfc = (Render_Engine_GL_Surface*)surface;
2519 ctx = (Render_Engine_GL_Context*)context;
2521 // Flush remainder of what's in Evas' pipeline
2524 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2525 if ((eglGetCurrentContext() == re->win->egl_context[0]) ||
2526 (eglGetCurrentSurface(EGL_READ) == re->win->egl_surface[0]) ||
2527 (eglGetCurrentSurface(EGL_DRAW) == re->win->egl_surface[0]))
2529 evas_gl_common_context_use(re->win->gl_context);
2530 evas_gl_common_context_flush(re->win->gl_context);
2533 if (glXGetCurrentContext() == re->win->context)
2535 evas_gl_common_context_use(re->win->gl_context);
2536 evas_gl_common_context_flush(re->win->gl_context);
2541 // Unset surface/context
2542 if ((!sfc) || (!ctx))
2544 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2545 ret = eglMakeCurrent(re->win->egl_disp, EGL_NO_SURFACE,
2546 EGL_NO_SURFACE, EGL_NO_CONTEXT);
2548 ret = glXMakeCurrent(re->info->info.display, None, NULL);
2552 ERR("xxxMakeCurrent() failed!");
2558 // Don't do a make current if it's already current
2560 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2561 if ((eglGetCurrentContext() != ctx->context))
2562 ret = eglMakeCurrent(re->win->egl_disp, re->win->egl_surface[0],
2563 re->win->egl_surface[0], ctx->context);
2565 if (glXGetCurrentContext() != ctx->context)
2566 ret = glXMakeCurrent(re->info->info.display, re->win->win, ctx->context);
2570 ERR("xxxMakeCurrent() failed!");
2574 // Create FBO if not already created
2575 if (!ctx->initialized)
2577 glGenFramebuffers(1, &ctx->fbo);
2578 ctx->initialized = 1;
2581 // Attach FBO if it hasn't been attached or if surface changed
2582 if ((!sfc->fbo_attached) || (ctx != sfc->current_ctx))
2584 if (!_attach_fbo_surface(re, sfc, ctx))
2586 ERR("_attach_fbo_surface() failed.");
2589 sfc->fbo_attached = 1;
2592 // Set the current surface/context
2593 ctx->current_sfc = sfc;
2594 sfc->current_ctx = ctx;
2597 glBindFramebuffer(GL_FRAMEBUFFER, ctx->fbo);
2598 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2600 //glDrawBuffer(GL_COLOR_ATTACHMENT0);
2607 eng_gl_proc_address_get(void *data __UNUSED__, const char *name)
2609 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2610 if (glsym_eglGetProcAddress) return glsym_eglGetProcAddress(name);
2611 return dlsym(RTLD_DEFAULT, name);
2613 if (glsym_glXGetProcAddress) return glsym_glXGetProcAddress(name);
2614 return dlsym(RTLD_DEFAULT, name);
2619 eng_gl_native_surface_get(void *data, void *surface, void *native_surface)
2622 Render_Engine_GL_Surface *sfc;
2623 Evas_Native_Surface *ns;
2625 re = (Render_Engine *)data;
2626 sfc = (Render_Engine_GL_Surface*)surface;
2627 ns = (Evas_Native_Surface*)native_surface;
2629 ns->type = EVAS_NATIVE_SURFACE_OPENGL;
2630 ns->version = EVAS_NATIVE_SURFACE_VERSION;
2631 ns->data.opengl.texture_id = sfc->rt_tex;
2632 //ns->data.opengl.framebuffer_id = sfc->fbo;
2633 //ns->data.opengl.framebuffer_id = ctx->fbo;
2634 ns->data.opengl.x = 0;
2635 ns->data.opengl.y = 0;
2636 ns->data.opengl.w = sfc->w;
2637 ns->data.opengl.h = sfc->h;
2644 evgl_glBindFramebuffer(GLenum target, GLuint framebuffer)
2646 // Add logic to take care when framebuffer=0
2647 glBindFramebuffer(target, framebuffer);
2651 evgl_glBindRenderbuffer(GLenum target, GLuint renderbuffer)
2653 // Add logic to take care when renderbuffer=0
2654 glBindRenderbuffer(target, renderbuffer);
2658 evgl_glClearDepthf(GLclampf depth)
2660 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2661 glClearDepthf(depth);
2663 glClearDepth(depth);
2668 evgl_glDepthRangef(GLclampf zNear, GLclampf zFar)
2670 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2671 glDepthRangef(zNear, zFar);
2673 glDepthRange(zNear, zFar);
2678 evgl_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
2680 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2681 glGetShaderPrecisionFormat(shadertype, precisiontype, range, precision);
2685 range[0] = -126; // floor(log2(FLT_MIN))
2686 range[1] = 127; // floor(log2(FLT_MAX))
2690 precision[0] = 24; // floor(-log2((1.0/16777218.0)));
2693 shadertype = precisiontype = 0;
2698 evgl_glReleaseShaderCompiler(void)
2700 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2701 glReleaseShaderCompiler();
2707 evgl_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
2709 #if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
2710 glShaderBinary(n, shaders, binaryformat, binary, length);
2712 // FIXME: need to dlsym/getprocaddress for this
2714 n = binaryformat = length = 0;
2715 shaders = binary = 0;
2722 eng_gl_api_get(void *data)
2726 re = (Render_Engine *)data;
2728 gl_funcs.version = EVAS_GL_API_VERSION;
2730 #define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, )
2731 ORD(glActiveTexture);
2732 ORD(glAttachShader);
2733 ORD(glBindAttribLocation);
2737 ORD(glBlendEquation);
2738 ORD(glBlendEquationSeparate);
2740 ORD(glBlendFuncSeparate);
2742 ORD(glBufferSubData);
2743 ORD(glCheckFramebufferStatus);
2746 // ORD(glClearDepthf);
2747 ORD(glClearStencil);
2749 ORD(glCompileShader);
2750 ORD(glCompressedTexImage2D);
2751 ORD(glCompressedTexSubImage2D);
2752 ORD(glCopyTexImage2D);
2753 ORD(glCopyTexSubImage2D);
2754 ORD(glCreateProgram);
2755 ORD(glCreateShader);
2757 ORD(glDeleteBuffers);
2758 ORD(glDeleteFramebuffers);
2759 ORD(glDeleteProgram);
2760 ORD(glDeleteRenderbuffers);
2761 ORD(glDeleteShader);
2762 ORD(glDeleteTextures);
2765 // ORD(glDepthRangef);
2766 ORD(glDetachShader);
2768 ORD(glDisableVertexAttribArray);
2770 ORD(glDrawElements);
2772 ORD(glEnableVertexAttribArray);
2775 ORD(glFramebufferRenderbuffer);
2776 ORD(glFramebufferTexture2D);
2779 ORD(glGenerateMipmap);
2780 ORD(glGenFramebuffers);
2781 ORD(glGenRenderbuffers);
2783 ORD(glGetActiveAttrib);
2784 ORD(glGetActiveUniform);
2785 ORD(glGetAttachedShaders);
2786 ORD(glGetAttribLocation);
2788 ORD(glGetBufferParameteriv);
2791 ORD(glGetFramebufferAttachmentParameteriv);
2793 ORD(glGetProgramiv);
2794 ORD(glGetProgramInfoLog);
2795 ORD(glGetRenderbufferParameteriv);
2797 ORD(glGetShaderInfoLog);
2798 // ORD(glGetShaderPrecisionFormat);
2799 ORD(glGetShaderSource);
2801 ORD(glGetTexParameterfv);
2802 ORD(glGetTexParameteriv);
2803 ORD(glGetUniformfv);
2804 ORD(glGetUniformiv);
2805 ORD(glGetUniformLocation);
2806 ORD(glGetVertexAttribfv);
2807 ORD(glGetVertexAttribiv);
2808 ORD(glGetVertexAttribPointerv);
2812 ORD(glIsFramebuffer);
2814 ORD(glIsRenderbuffer);
2820 ORD(glPolygonOffset);
2822 // ORD(glReleaseShaderCompiler);
2823 ORD(glRenderbufferStorage);
2824 ORD(glSampleCoverage);
2826 // ORD(glShaderBinary);
2827 ORD(glShaderSource);
2829 ORD(glStencilFuncSeparate);
2831 ORD(glStencilMaskSeparate);
2833 ORD(glStencilOpSeparate);
2835 ORD(glTexParameterf);
2836 ORD(glTexParameterfv);
2837 ORD(glTexParameteri);
2838 ORD(glTexParameteriv);
2839 ORD(glTexSubImage2D);
2856 ORD(glUniformMatrix2fv);
2857 ORD(glUniformMatrix3fv);
2858 ORD(glUniformMatrix4fv);
2860 ORD(glValidateProgram);
2861 ORD(glVertexAttrib1f);
2862 ORD(glVertexAttrib1fv);
2863 ORD(glVertexAttrib2f);
2864 ORD(glVertexAttrib2fv);
2865 ORD(glVertexAttrib3f);
2866 ORD(glVertexAttrib3fv);
2867 ORD(glVertexAttrib4f);
2868 ORD(glVertexAttrib4fv);
2869 ORD(glVertexAttribPointer);
2873 // Override functions wrapped by Evas_GL
2874 #define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, evgl_)
2875 ORD(glBindFramebuffer);
2876 ORD(glBindRenderbuffer);
2878 // GLES2.0 API compat on top of desktop gl
2881 ORD(glGetShaderPrecisionFormat);
2882 ORD(glReleaseShaderCompiler);
2883 ORD(glShaderBinary);
2892 eng_image_load_error_get(void *data __UNUSED__, void *image)
2896 if (!image) return EVAS_LOAD_ERROR_NONE;
2898 return im->im->cache_entry.load_error;
2902 module_open(Evas_Module *em)
2904 static Eina_Bool xrm_inited = EINA_FALSE;
2907 xrm_inited = EINA_TRUE;
2912 if (!evas_gl_common_module_open()) return 0;
2913 /* get whatever engine module we inherit from */
2914 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
2915 if (_evas_engine_GL_X11_log_dom < 0)
2916 _evas_engine_GL_X11_log_dom = eina_log_domain_register
2917 ("evas-gl_x11", EVAS_DEFAULT_LOG_COLOR);
2918 if (_evas_engine_GL_X11_log_dom < 0)
2920 EINA_LOG_ERR("Can not create a module log domain.");
2923 /* store it for later use */
2925 /* now to override methods */
2926 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
2930 ORD(canvas_alpha_get);
2933 ORD(output_tile_size_set);
2934 ORD(output_redraws_rect_add);
2935 ORD(output_redraws_rect_del);
2936 ORD(output_redraws_clear);
2937 ORD(output_redraws_next_update_get);
2938 ORD(output_redraws_next_update_push);
2939 ORD(context_cutout_add);
2940 ORD(context_cutout_clear);
2942 ORD(output_idle_flush);
2944 ORD(rectangle_draw);
2946 ORD(polygon_point_add);
2947 ORD(polygon_points_clear);
2951 ORD(image_new_from_data);
2952 ORD(image_new_from_copied_data);
2954 ORD(image_size_get);
2955 ORD(image_size_set);
2956 ORD(image_dirty_region);
2957 ORD(image_data_get);
2958 ORD(image_data_put);
2959 ORD(image_data_preload_request);
2960 ORD(image_data_preload_cancel);
2961 ORD(image_alpha_set);
2962 ORD(image_alpha_get);
2963 ORD(image_border_set);
2964 ORD(image_border_get);
2966 ORD(image_comment_get);
2967 ORD(image_format_get);
2968 ORD(image_colorspace_set);
2969 ORD(image_colorspace_get);
2970 ORD(image_mask_create);
2971 ORD(image_native_set);
2972 ORD(image_native_get);
2973 #if 0 // filtering disabled
2974 ORD(image_draw_filtered);
2975 ORD(image_filtered_get);
2976 ORD(image_filtered_save);
2977 ORD(image_filtered_free);
2982 ORD(image_scale_hint_set);
2983 ORD(image_scale_hint_get);
2984 ORD(image_stride_get);
2986 ORD(image_map_draw);
2987 ORD(image_map_surface_new);
2988 ORD(image_map_surface_free);
2990 ORD(image_content_hint_set);
2991 ORD(image_content_hint_get);
2993 ORD(image_cache_flush);
2994 ORD(image_cache_set);
2995 ORD(image_cache_get);
2997 ORD(gl_surface_create);
2998 ORD(gl_surface_destroy);
2999 ORD(gl_context_create);
3000 ORD(gl_context_destroy);
3001 ORD(gl_make_current);
3002 ORD(gl_proc_address_get);
3003 ORD(gl_native_surface_get);
3007 ORD(image_load_error_get);
3009 /* now advertise out own api */
3010 em->functions = (void *)(&func);
3015 module_close(Evas_Module *em __UNUSED__)
3017 eina_log_domain_unregister(_evas_engine_GL_X11_log_dom);
3020 XrmDestroyDatabase(xrdb_user.db);
3021 xrdb_user.last_stat = 0;
3022 xrdb_user.last_mtime = 0;
3023 xrdb_user.db = NULL;
3025 evas_gl_common_module_close();
3028 static Evas_Module_Api evas_modapi =
3030 EVAS_MODULE_API_VERSION,
3039 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, gl_x11);
3041 #ifndef EVAS_STATIC_BUILD_GL_X11
3042 EVAS_EINA_MODULE_DEFINE(engine, gl_x11);
3045 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/