evas: Add gl_cocoa engine
authorcaptainigloo <captainigloo@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 2 Nov 2011 18:23:54 +0000 (18:23 +0000)
committercaptainigloo <captainigloo@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 2 Nov 2011 18:23:54 +0000 (18:23 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@64653 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

Makefile.am
configure.ac
m4/evas_check_engine.m4
src/modules/engines/Makefile.am
src/modules/engines/gl_cocoa/Evas_Engine_GL_Cocoa.h [new file with mode: 0644]
src/modules/engines/gl_cocoa/Makefile.am [new file with mode: 0644]
src/modules/engines/gl_cocoa/evas_engine.c [new file with mode: 0644]
src/modules/engines/gl_cocoa/evas_engine.h [new file with mode: 0644]
src/modules/engines/gl_cocoa/evas_gl_cocoa_main.m [new file with mode: 0644]

index 5f40421..7b28d3e 100644 (file)
@@ -96,6 +96,10 @@ if BUILD_ENGINE_GL_SDL
 pkgconfig_DATA += evas-opengl-sdl.pc
 endif
 
+if BUILD_ENGINE_GL_COCOA
+pkgconfig_DATA += evas-opengl-cocoa.pc
+endif
+
 if BUILD_ENGINE_SOFTWARE_GDI
 pkgconfig_DATA += evas-software-gdi.pc
 endif
index 6b8b9b7..05afa08 100644 (file)
@@ -107,6 +107,7 @@ want_evas_engine_software_16_sdl="no"
 want_evas_engine_gl_xlib="no"
 want_evas_engine_gl_xcb="no"
 want_evas_engine_gl_sdl="no"
+want_evas_engine_gl_cocoa="yes"
 want_evas_engine_direct3d="no"
 want_evas_engine_fb="no"
 want_evas_engine_directfb="no"
@@ -148,6 +149,7 @@ case "$host_os" in
       ;;
    darwin*)
       want_evas_engine_software_xlib="auto"
+      want_evas_engine_gl_cocoa="auto"
       ;;
    *)
       want_evas_engine_software_xlib="auto"
@@ -677,6 +679,8 @@ EVAS_CHECK_ENGINE([software-sdl], [${want_evas_engine_software_sdl}], [no], [Sof
 
 EVAS_CHECK_ENGINE([gl-sdl], [${want_evas_engine_gl_sdl}], [no], [OpenGL SDL])
 
+EVAS_CHECK_ENGINE([gl-cocoa], [${want_evas_engine_gl_cocoa}], [no], [OpenGL Cocoa])
+
 EVAS_CHECK_ENGINE([fb], [${want_evas_engine_fb}], [no], [Framebuffer])
 
 EVAS_CHECK_ENGINE([directfb], [${want_evas_engine_directfb}], [no], [DirectFB])
@@ -842,12 +846,14 @@ have_evas_engine_gl_common="no"
 have_static_evas_engine_gl_common="no"
 if test "x$have_evas_engine_gl_xlib" = "xyes" \
    || test "x$have_evas_engine_gl_xcb" = "xyes" \
-   || test "x$have_evas_engine_gl_sdl" = "xyes"; then
+   || test "x$have_evas_engine_gl_sdl" = "xyes" \
+   || test "x$have_evas_engine_gl_cocoa" = "xyes"; then
    have_evas_engine_gl_common="yes"
 fi
 if test "x$have_evas_engine_gl_xlib" = "xstatic" \
    || test "x$have_evas_engine_gl_xcb" = "xstatic" \
-   || test "x$have_evas_engine_gl_sdl" = "xstatic"; then
+   || test "x$have_evas_engine_gl_sdl" = "xstatic" \
+   || test "x$have_evas_engine_gl_cocoa" = "xstatic"; then
    have_evas_engine_gl_common="yes"
    have_static_evas_engine_gl_common="yes"
 fi
@@ -1768,6 +1774,7 @@ evas-directfb.pc
 evas-fb.pc
 evas-opengl-x11.pc
 evas-opengl-sdl.pc
+evas-opengl-cocoa.pc
 evas-software-buffer.pc
 evas-software-x11.pc
 evas-software-8-x11.pc
@@ -1813,6 +1820,7 @@ src/modules/engines/directfb/Makefile
 src/modules/engines/gl_common/Makefile
 src/modules/engines/gl_x11/Makefile
 src/modules/engines/gl_sdl/Makefile
+src/modules/engines/gl_cocoa/Makefile
 src/modules/engines/software_sdl/Makefile
 src/modules/engines/software_8/Makefile
 src/modules/engines/software_8_x11/Makefile
@@ -1906,6 +1914,7 @@ if test "x$have_evas_engine_gl_sdl" = "xyes"; then
 else
   echo
 fi
+echo "  OpenGL Cocoa...............: $have_evas_engine_gl_cocoa"
 echo "  Software Framebuffer.......: $have_evas_engine_fb"
 echo "  DirectFB...................: $have_evas_engine_directfb"
 echo "  Software 8bit grayscale....: $have_evas_engine_software_8"
index 5d3c450..7330a3f 100644 (file)
@@ -328,8 +328,6 @@ fi
 ])
 
 
-
-
 dnl use: EVAS_CHECK_ENGINE_DEP_SOFTWARE_GDI(engine, simple, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
 
 AC_DEFUN([EVAS_CHECK_ENGINE_DEP_SOFTWARE_GDI],
@@ -411,6 +409,59 @@ fi
 
 ])
 
+
+dnl use: EVAS_CHECK_ENGINE_DEP_GL_COCOA(engine, simple, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+
+AC_DEFUN([EVAS_CHECK_ENGINE_DEP_GL_COCOA],
+[
+
+evas_engine_[]$1[]_cflags=""
+evas_engine_[]$1[]_libs=""
+
+AC_LANG_PUSH([Objective C])
+
+LIBS_save="$LIBS"
+LIBS="$LIBS -framework Cocoa"
+AC_LINK_IFELSE(
+   [AC_LANG_PROGRAM(
+       [[
+#include <Cocoa/Cocoa.h>
+       ]],
+       [[
+NSWindow *window;
+window = [[NSWindow alloc]
+           initWithContentRect:NSMakeRect(0, 0, 1, 1)
+           styleMask:(NSTitledWindowMask)
+           backing:NSBackingStoreBuffered
+           defer:NO
+           screen:nil
+         ];
+       ]])],
+   [
+    have_dep="yes"
+    evas_engine_[]$1[]_libs="-framework Cocoa"
+   ],
+   [have_dep="no"])
+LIBS="$LIBS_save"
+
+AC_LANG_POP([Objective C])
+
+if test "x${have_dep}" = "xyes" ; then
+   PKG_CHECK_MODULES([GL_EET], [eet >= 1.4.0], [have_dep="yes"], [have_dep="no"])
+fi
+
+AC_SUBST([evas_engine_$1_cflags])
+AC_SUBST([evas_engine_$1_libs])
+
+if test "x${have_dep}" = "xyes" ; then
+  m4_default([$4], [:])
+else
+  m4_default([$5], [:])
+fi
+
+])
+
+
 dnl use: EVAS_CHECK_ENGINE_DEP_SOFTWARE_SDL(engine, simple, want_static[, ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
 
 AC_DEFUN([EVAS_CHECK_ENGINE_DEP_SOFTWARE_SDL],
index 041e3ad..b307fb9 100644 (file)
@@ -27,6 +27,9 @@ endif
 if !EVAS_STATIC_BUILD_GL_SDL
 SUBDIRS += gl_sdl
 endif
+if !EVAS_STATIC_BUILD_GL_COCOA
+SUBDIRS += gl_cocoa
+endif
 
 if !EVAS_STATIC_BUILD_SOFTWARE_8
 SUBDIRS += software_8
diff --git a/src/modules/engines/gl_cocoa/Evas_Engine_GL_Cocoa.h b/src/modules/engines/gl_cocoa/Evas_Engine_GL_Cocoa.h
new file mode 100644 (file)
index 0000000..eb04d28
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef __EVAS_ENGINE_GL_COCOA_H__
+#define __EVAS_ENGINE_GL_COCOA_H__
+
+typedef struct _Evas_Engine_Info_GL_Cocoa Evas_Engine_Info_GL_Cocoa;
+
+struct _Evas_Engine_Info_GL_Cocoa
+{
+   /* PRIVATE - don't mess with this baby or evas will poke its tongue out */
+   /* at you and make nasty noises */
+   Evas_Engine_Info magic;
+
+   /* engine specific data & parameters it needs to set up */
+   void   *window;
+   void   *view;
+   int   depth;
+
+};
+
+
+#endif /* __EVAS_ENGINE_GL_COCOA_H__ */
diff --git a/src/modules/engines/gl_cocoa/Makefile.am b/src/modules/engines/gl_cocoa/Makefile.am
new file mode 100644 (file)
index 0000000..6d424d7
--- /dev/null
@@ -0,0 +1,46 @@
+
+MAINTAINERCLEANFILES = Makefile.in
+
+AM_CPPFLAGS = \
+-I. \
+-I$(top_srcdir)/src/lib \
+-I$(top_srcdir)/src/lib/include \
+-I$(top_srcdir)/src/modules/engines/gl_common \
+@EINA_CFLAGS@ \
+@GL_EET_CFLAGS@ \
+@FREETYPE_CFLAGS@ \
+@evas_engine_gl_cocoa_cflags@
+
+if BUILD_ENGINE_GL_COCOA
+
+GL_COCOA_SOURCES = evas_engine.c\
+evas_gl_cocoa_main.m
+
+
+GL_COCOA_LIBADD = @evas_engine_gl_cocoa_libs@ $(top_builddir)/src/modules/engines/gl_common/libevas_engine_gl_common.la
+
+
+include_HEADERS = Evas_Engine_GL_Cocoa.h
+includesdir = $(includedir)/evas-@VMAJ@
+
+if !EVAS_STATIC_BUILD_GL_COCOA
+
+pkgdir = $(libdir)/evas/modules/engines/gl_cocoa/$(MODULE_ARCH)
+pkg_LTLIBRARIES = module.la
+
+module_la_SOURCES = $(GL_COCOA_SOURCES)
+module_la_LIBADD = @EINA_LIBS@ @GL_EET_LIBS@ $(GL_COCOA_LIBADD) $(top_builddir)/src/lib/libevas.la @dlopen_libs@
+module_la_LDFLAGS = -module -avoid-version
+module_la_LIBTOOLFLAGS = --tag=disable-static
+
+else
+
+noinst_LTLIBRARIES = libevas_engine_gl_cocoa.la
+
+libevas_engine_gl_cocoa_la_SOURCES = $(GL_COCOA_SOURCES)
+libevas_engine_gl_cocoa_la_LIBADD = $(GL_COCOA_LIBADD)
+
+endif
+endif
+
+EXTRA_DIST = evas_engine.h
diff --git a/src/modules/engines/gl_cocoa/evas_engine.c b/src/modules/engines/gl_cocoa/evas_engine.c
new file mode 100644 (file)
index 0000000..fd95688
--- /dev/null
@@ -0,0 +1,1462 @@
+#include "evas_common.h" /* Also includes international specific stuff */
+#include "evas_engine.h"
+
+#include "evas_private.h"
+
+#include <dlfcn.h>      /* dlopen,dlclose,etc */
+#define EVAS_GL_NO_GL_H_CHECK 1
+#include "Evas_GL.h"
+
+
+
+typedef struct _Render_Engine Render_Engine;
+typedef struct _Render_Engine_GL_Surface    Render_Engine_GL_Surface;
+typedef struct _Render_Engine_GL_Context    Render_Engine_GL_Context;
+
+struct _Render_Engine
+{
+   Evas_GL_Cocoa_Window *win;
+   int                  end;
+};
+
+
+struct _Render_Engine_GL_Surface
+{
+   int     initialized;
+   int     fbo_attached;
+   int     w, h;
+   int     depth_bits;
+   int     stencil_bits;
+
+   // Render target texture/buffers
+   GLuint  rt_tex;
+   GLint   rt_internal_fmt;
+   GLenum  rt_fmt; 
+   GLuint  rb_depth;
+   GLenum  rb_depth_fmt;
+   GLuint  rb_stencil;
+   GLenum  rb_stencil_fmt;
+
+   Render_Engine_GL_Context   *current_ctx;
+};
+
+struct _Render_Engine_GL_Context
+{
+   int         initialized;
+  //   EGLContext  context;
+
+   GLuint      fbo;     
+   
+   Render_Engine_GL_Surface   *current_sfc;
+};
+
+
+int _evas_engine_gl_cocoa_log_dom = -1;
+/* function tables - filled in later (func and parent func) */
+static Evas_Func func, pfunc;
+
+/* Function table for GL APIs */
+static Evas_GL_API gl_funcs;
+
+
+
+static void *
+eng_info(Evas *e __UNUSED__)
+{
+   Evas_Engine_Info_GL_Cocoa *info;
+   info = calloc(1, sizeof(Evas_Engine_Info_GL_Cocoa));
+   DBG("Info %p", info);
+   if (!info) return NULL;
+   info->magic.magic = rand();
+   return info;
+}
+
+static void
+eng_info_free(Evas *e __UNUSED__, void *info)
+{
+   Evas_Engine_Info_GL_Cocoa *in;
+
+   DBG("Info %p", info);
+   eina_log_domain_unregister(_evas_engine_gl_cocoa_log_dom);
+   in = (Evas_Engine_Info_GL_Cocoa *)info;
+   free(in);
+}
+
+static int
+eng_setup(Evas *e, void *in)
+{
+   Render_Engine            *re;
+   Evas_Engine_Info_GL_Cocoa *info;
+
+   DBG("Engine Setup");
+
+   info = (Evas_Engine_Info_GL_Cocoa *)in;
+   if (!e->engine.data.output)
+     {
+       re = calloc(1, sizeof(Render_Engine));
+       if (!re) return 0;
+
+       e->engine.data.output = re;
+       re->win = eng_window_new(info->window,
+                                   e->output.w,
+                                    e->output.h);
+       info->view = re->win->view;
+       if (!re->win)
+         {
+            free(re);
+            e->engine.data.output = NULL;
+            return 0;
+         }
+
+       evas_common_cpu_init();
+
+       evas_common_blend_init();
+       evas_common_image_init();
+       evas_common_convert_init();
+       evas_common_scale_init();
+       evas_common_rectangle_init();
+       evas_common_polygon_init();
+       evas_common_line_init();
+       evas_common_font_init();
+       evas_common_draw_init();
+       evas_common_tilebuf_init();
+     }
+   else
+     {
+       re = e->engine.data.output;
+       eng_window_free(re->win);
+       re->win = eng_window_new(info->window,
+                                   e->output.w,
+                                    e->output.h);
+       info->view = re->win->view;
+     }
+   if (!e->engine.data.output) return 0;
+
+   if (!e->engine.data.context)
+     e->engine.data.context =
+       e->engine.func->context_new(e->engine.data.output);
+   eng_window_use(re->win);
+
+   return 1;
+}
+
+static void
+eng_output_free(void *data)
+{
+   Render_Engine *re;
+
+   DBG("Output free");
+   re = (Render_Engine *)data;
+   eng_window_free(re->win);
+   free(re);
+
+   evas_common_font_shutdown();
+   evas_common_image_shutdown();
+}
+
+static void
+eng_output_resize(void *data, int w, int h)
+{
+   Render_Engine *re;
+
+   DBG("Output Resize %d %d", w, h);
+
+   re = (Render_Engine *)data;
+   re->win->width = w;
+   re->win->height = h;
+   
+   eng_window_resize(re->win, w, h);
+   evas_gl_common_context_resize(re->win->gl_context, w, h, 0);
+}
+
+static void
+eng_output_tile_size_set(void *data __UNUSED__, int w __UNUSED__, int h __UNUSED__)
+{
+  DBG("tile size set");
+}
+
+static void
+eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
+{
+   Render_Engine *re;
+
+   DBG("Redraw rect %d %d %d %d", x, y, w, h);
+   re = (Render_Engine *)data;
+   evas_gl_common_context_resize(re->win->gl_context, re->win->width, re->win->height, 0);
+   /* simple bounding box */
+   RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, re->win->width, re->win->height);
+   if ((w <= 0) || (h <= 0)) return;
+   if (!re->win->draw.redraw)
+     {
+#if 0
+       re->win->draw.x1 = x;
+       re->win->draw.y1 = y;
+       re->win->draw.x2 = x + w - 1;
+       re->win->draw.y2 = y + h - 1;
+#else
+       re->win->draw.x1 = 0;
+       re->win->draw.y1 = 0;
+       re->win->draw.x2 = re->win->width - 1;
+       re->win->draw.y2 = re->win->height - 1;
+#endif
+     }
+   else
+     {
+       if (x < re->win->draw.x1) re->win->draw.x1 = x;
+       if (y < re->win->draw.y1) re->win->draw.y1 = y;
+       if ((x + w - 1) > re->win->draw.x2) re->win->draw.x2 = x + w - 1;
+       if ((y + h - 1) > re->win->draw.y2) re->win->draw.y2 = y + h - 1;
+     }
+   re->win->draw.redraw = 1;
+}
+
+static void
+eng_output_redraws_rect_del(void *data __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
+{
+}
+
+static void
+eng_output_redraws_clear(void *data)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   re->win->draw.redraw = 0;
+}
+
+//#define SLOW_GL_COPY_RECT 1
+/* vsync games - not for now though */
+#define VSYNC_TO_SCREEN 1
+
+static void *
+eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   evas_gl_common_context_flush(re->win->gl_context);
+   /* get the upate rect surface - return engine data as dummy */
+   if (!re->win->draw.redraw)
+     {
+//     printf("GL: NO updates!\n");
+       return NULL;
+     }
+//   printf("GL: update....!\n");
+#ifdef SLOW_GL_COPY_RECT
+   /* if any update - just return the whole canvas - works with swap
+    * buffers then */
+   if (x) *x = 0;
+   if (y) *y = 0;
+   if (w) *w = re->win->width;
+   if (h) *h = re->win->height;
+   if (cx) *cx = 0;
+   if (cy) *cy = 0;
+   if (cw) *cw = re->win->width;
+   if (ch) *ch = re->win->height;
+#else
+   /* 1 update - INCREDIBLY SLOW if combined with swap_rect in flush. a gl
+    * problem where there just is no hardware path for somethnig that
+    * obviously SHOULD be there */
+   /* only 1 update to minimise gl context games and rendering multiple update
+    * regions as evas does with other engines
+    */
+   if (x) *x = re->win->draw.x1;
+   if (y) *y = re->win->draw.y1;
+   if (w) *w = re->win->draw.x2 - re->win->draw.x1 + 1;
+   if (h) *h = re->win->draw.y2 - re->win->draw.y1 + 1;
+   if (cx) *cx = re->win->draw.x1;
+   if (cy) *cy = re->win->draw.y1;
+   if (cw) *cw = re->win->draw.x2 - re->win->draw.x1 + 1;
+   if (ch) *ch = re->win->draw.y2 - re->win->draw.y1 + 1;
+#endif
+// clear buffer. only needed for dest alpha
+//   glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+//   glClear(GL_COLOR_BUFFER_BIT);
+//x//   printf("frame -> new\n");
+   return re->win->gl_context->def_surface;
+}
+
+static void
+eng_output_redraws_next_update_push(void *data, void *surface __UNUSED__, int x __UNUSED__, int y __UNUSED__, int w __UNUSED__, int h __UNUSED__)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   /* put back update surface.. in this case just unflag redraw */
+   re->win->draw.redraw = 0;
+   re->win->draw.drew = 1;
+   evas_gl_common_context_flush(re->win->gl_context);
+}
+
+static void
+eng_output_flush(void *data)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   if (!re->win->draw.drew) return;
+
+   re->win->draw.drew = 0;
+   eng_window_use(re->win);
+
+#ifdef VSYNC_TO_SCREEN
+   eng_window_vsync_set(1);
+#endif
+
+   eng_window_swap_buffers(re->win);
+
+}
+
+static void
+eng_output_idle_flush(void *data __UNUSED__)
+{
+}
+
+static void
+eng_context_cutout_add(void *data __UNUSED__, void *context, int x, int y, int w, int h)
+{
+   evas_common_draw_context_add_cutout(context, x, y, w, h);
+}
+
+static void
+eng_context_cutout_clear(void *data __UNUSED__, void *context)
+{
+   evas_common_draw_context_clear_cutouts(context);
+}
+
+static void
+eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   eng_window_use(re->win);
+   evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
+   re->win->gl_context->dc = context;
+   evas_gl_common_rect_draw(re->win->gl_context, x, y, w, h);
+}
+
+static void
+eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   eng_window_use(re->win);
+   evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
+   re->win->gl_context->dc = context;
+   evas_gl_common_line_draw(re->win->gl_context, x1, y1, x2, y2);
+}
+
+static void *
+eng_polygon_point_add(void *data, void *context __UNUSED__, void *polygon, int x, int y)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   return evas_gl_common_poly_point_add(polygon, x, y);
+}
+
+static void *
+eng_polygon_points_clear(void *data, void *context __UNUSED__, void *polygon)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   return evas_gl_common_poly_points_clear(polygon);
+}
+
+static void
+eng_polygon_draw(void *data, void *context, void *surface __UNUSED__, void *polygon, int x, int y)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   eng_window_use(re->win);
+   evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
+   re->win->gl_context->dc = context;
+   evas_gl_common_poly_draw(re->win->gl_context, polygon, x, y);
+}
+
+static int
+eng_image_alpha_get(void *data __UNUSED__, void *image)
+{
+//   Render_Engine *re;
+   Evas_GL_Image *im;
+
+//   re = (Render_Engine *)data;
+   if (!image) return 1;
+   im = image;
+   return im->alpha;
+}
+
+static int
+eng_image_colorspace_get(void *data __UNUSED__, void *image)
+{
+//   Render_Engine *re;
+   Evas_GL_Image *im;
+
+//   re = (Render_Engine *)data;
+   if (!image) return EVAS_COLORSPACE_ARGB8888;
+   im = image;
+   return im->cs.space;
+}
+
+static void
+eng_image_mask_create(void *data __UNUSED__, void *image)
+{
+   Evas_GL_Image *im;
+
+   if (!image) return;
+   im = image;
+   if (!im->im->image.data)
+      evas_cache_image_load_data(&im->im->cache_entry);
+   if (!im->tex)
+      im->tex = evas_gl_common_texture_new(im->gc, im->im);
+}
+
+
+static void *
+eng_image_alpha_set(void *data, void *image, int has_alpha)
+{
+   Render_Engine *re;
+   Evas_GL_Image *im;
+
+   re = (Render_Engine *)data;
+   if (!image) return NULL;
+   im = image;
+   if (im->alpha == has_alpha) return image;
+   if (im->native.data)
+     {
+        im->alpha = has_alpha;
+        return image;
+     }
+   eng_window_use(re->win);
+   if ((im->tex) && (im->tex->pt->dyn.img))
+     {
+        im->alpha = has_alpha;
+        im->tex->alpha = im->alpha;
+        return image;
+     }
+   /* FIXME: can move to gl_common */
+   if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
+   if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
+   else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image;
+   if (im->references > 1)
+     {
+        Evas_GL_Image *im_new;
+        
+        im_new = evas_gl_common_image_new_from_copied_data
+           (im->gc, im->im->cache_entry.w, im->im->cache_entry.h, 
+               im->im->image.data,
+               eng_image_alpha_get(data, image),
+               eng_image_colorspace_get(data, image));
+        if (!im_new) return im;
+        evas_gl_common_image_free(im);
+        im = im_new;
+     }
+   else
+     evas_gl_common_image_dirty(im, 0, 0, 0, 0);
+   return evas_gl_common_image_alpha_set(im, has_alpha ? 1 : 0);
+//   im->im->cache_entry.flags.alpha = has_alpha ? 1 : 0;
+//   return image;
+}
+
+static void *
+eng_image_border_set(void *data __UNUSED__, void *image, int l __UNUSED__, int r __UNUSED__, int t __UNUSED__, int b __UNUSED__)
+{
+//   Render_Engine *re;
+//
+//   re = (Render_Engine *)data;
+   return image;
+}
+
+static void
+eng_image_border_get(void *data __UNUSED__, void *image __UNUSED__, int *l __UNUSED__, int *r __UNUSED__, int *t __UNUSED__, int *b __UNUSED__)
+{
+//   Render_Engine *re;
+//
+//   re = (Render_Engine *)data;
+}
+
+static char *
+eng_image_comment_get(void *data __UNUSED__, void *image, char *key __UNUSED__)
+{
+//   Render_Engine *re;
+   Evas_GL_Image *im;
+
+//   re = (Render_Engine *)data;
+   if (!image) return NULL;
+   im = image;
+   if (!im->im) return NULL;
+   return im->im->info.comment;
+}
+
+static char *
+eng_image_format_get(void *data __UNUSED__, void *image)
+{
+//   Render_Engine *re;
+   Evas_GL_Image *im;
+
+//   re = (Render_Engine *)data;
+   im = image;
+   return NULL;
+}
+
+static void
+eng_image_colorspace_set(void *data, void *image, int cspace)
+{
+   Render_Engine *re;
+   Evas_GL_Image *im;
+
+   re = (Render_Engine *)data;
+   if (!image) return;
+   im = image;
+   if (im->native.data) return;
+   /* FIXME: can move to gl_common */
+   if (im->cs.space == cspace) return;
+   eng_window_use(re->win);
+   evas_cache_image_colorspace(&im->im->cache_entry, cspace);
+   switch (cspace)
+     {
+      case EVAS_COLORSPACE_ARGB8888:
+       if (im->cs.data)
+         {
+            if (!im->cs.no_free) free(im->cs.data);
+            im->cs.data = NULL;
+            im->cs.no_free = 0;
+         }
+       break;
+      case EVAS_COLORSPACE_YCBCR422P601_PL:
+      case EVAS_COLORSPACE_YCBCR422P709_PL:
+        if (im->tex) evas_gl_common_texture_free(im->tex);
+        im->tex = NULL;
+       if (im->cs.data)
+         {
+            if (!im->cs.no_free) free(im->cs.data);
+         }
+        if (im->im->cache_entry.h > 0)
+          im->cs.data = 
+          calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2);
+        else
+          im->cs.data = NULL;
+       im->cs.no_free = 0;
+       break;
+      default:
+       abort();
+       break;
+     }
+   im->cs.space = cspace;
+}
+
+/////////////////////////////////////////////////////////////////////////
+//
+//
+
+// FIXME: this is enabled so updates happen - but its SLOOOOOOOOOOOOOOOW
+// (i am sure this is the reason)  not to mention seemingly superfluous. but
+// i need to enable it for it to work on fglrx at least. havent tried nvidia.
+// 
+// why is this the case? does anyone know? has anyone tried it on other gfx
+// drivers?
+// 
+//#define GLX_TEX_PIXMAP_RECREATE 1
+#if 0
+static void
+eng_image_draw_filtered(void *data, void *context, void *surface,
+                        void *image, Evas_Filter_Info *filter)
+{
+   Render_Engine *re = data;
+
+   if (!image) return;
+   eng_window_use(re->win);
+   evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
+   re->win->gl_context->dc = context;
+
+   evas_gl_common_filter_draw(re->win->gl_context, image, filter);
+}
+
+static Filtered_Image *
+eng_image_filtered_get(void *im, uint8_t *key, size_t keylen)
+{
+   return evas_gl_common_image_filtered_get(im, key, keylen);
+}
+
+static Filtered_Image *
+eng_image_filtered_save(void *im, void *fim, uint8_t *key, size_t keylen)
+{
+   return evas_gl_common_image_filtered_save(im, fim, key, keylen);
+}
+
+static void
+eng_image_filtered_free(void *im, Filtered_Image *fim)
+{
+   evas_gl_common_image_filtered_free(im, fim);
+}
+
+#endif
+
+//
+//
+/////////////////////////////////////////////////////////////////////////
+
+static void *
+eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   *error = EVAS_LOAD_ERROR_NONE;
+   eng_window_use(re->win);
+   return evas_gl_common_image_load(re->win->gl_context, file, key, lo, error);
+}
+
+static void *
+eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   eng_window_use(re->win);
+   return evas_gl_common_image_new_from_data(re->win->gl_context, w, h, image_data, alpha, cspace);
+}
+
+static void *
+eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   eng_window_use(re->win);
+   return evas_gl_common_image_new_from_copied_data(re->win->gl_context, w, h, image_data, alpha, cspace);
+}
+
+static void
+eng_image_free(void *data, void *image)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   if (!image) return;
+   eng_window_use(re->win);
+   evas_gl_common_image_free(image);
+}
+
+static void
+eng_image_size_get(void *data __UNUSED__, void *image, int *w, int *h)
+{
+   if (!image)
+     {
+       *w = 0;
+       *h = 0;
+       return;
+     }
+   if (w) *w = ((Evas_GL_Image *)image)->w;
+   if (h) *h = ((Evas_GL_Image *)image)->h;
+}
+
+static void *
+eng_image_size_set(void *data, void *image, int w, int h)
+{
+   Render_Engine *re;
+   Evas_GL_Image *im = image;
+   Evas_GL_Image *im_old;
+   
+   re = (Render_Engine *)data;
+   if (!im) return NULL;
+   if (im->native.data)
+     {
+        im->w = w;
+        im->h = h;
+        return image;
+     }
+   eng_window_use(re->win);
+   if ((im->tex) && (im->tex->pt->dyn.img))
+     {
+        evas_gl_common_texture_free(im->tex);
+        im->tex = NULL;
+        im->w = w;
+        im->h = h;
+        im->tex = evas_gl_common_texture_dynamic_new(im->gc, im);
+        return image;
+     }
+   im_old = image;
+   if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) ||
+       (eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P709_PL))
+     w &= ~0x1;
+   if ((im_old) &&
+       ((int)im_old->im->cache_entry.w == w) &&
+       ((int)im_old->im->cache_entry.h == h))
+     return image;
+   if (im_old)
+     {
+       im = evas_gl_common_image_new(re->win->gl_context, w, h,
+                                     eng_image_alpha_get(data, image),
+                                     eng_image_colorspace_get(data, image));
+/*
+       evas_common_load_image_data_from_file(im_old->im);
+       if (im_old->im->image->data)
+         {
+            evas_common_blit_rectangle(im_old->im, im->im, 0, 0, w, h, 0, 0);
+            evas_common_cpu_end_opt();
+         }
+ */
+        evas_gl_common_image_free(im_old);
+     }
+   else
+     im = evas_gl_common_image_new(re->win->gl_context, w, h, 1, EVAS_COLORSPACE_ARGB8888);
+   return im;
+}
+
+static void *
+eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
+{
+   Render_Engine *re;
+   Evas_GL_Image *im = image;
+
+   re = (Render_Engine *)data;
+   if (!image) return NULL;
+   if (im->native.data) return image;
+   eng_window_use(re->win);
+   evas_gl_common_image_dirty(image, x, y, w, h);
+   return image;
+}
+
+static void *
+eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data, int *err)
+{
+   Render_Engine *re;
+   Evas_GL_Image *im;
+   int error;
+
+   re = (Render_Engine *)data;
+   if (!image)
+     {
+       *image_data = NULL;
+        if (err) *err = EVAS_LOAD_ERROR_GENERIC;
+       return NULL;
+     }
+   im = image;
+   if (im->native.data)
+     {
+        *image_data = NULL;
+        if (err) *err = EVAS_LOAD_ERROR_NONE;
+        return im;
+     }
+   if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.data))
+     {
+        *image_data = im->tex->pt->dyn.data;
+        if (err) *err = EVAS_LOAD_ERROR_NONE;
+        return im;
+     }
+   eng_window_use(re->win);
+   error = evas_cache_image_load_data(&im->im->cache_entry);
+   switch (im->cs.space)
+     {
+      case EVAS_COLORSPACE_ARGB8888:
+       if (to_write)
+         {
+            if (im->references > 1)
+              {
+                 Evas_GL_Image *im_new;
+
+                 im_new = evas_gl_common_image_new_from_copied_data
+                     (im->gc, im->im->cache_entry.w, im->im->cache_entry.h,
+                         im->im->image.data,
+                         eng_image_alpha_get(data, image),
+                         eng_image_colorspace_get(data, image));
+                 if (!im_new)
+                   {
+                      *image_data = NULL;
+                       if (err) *err = EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
+                      return im;
+                   }
+                 evas_gl_common_image_free(im);
+                 im = im_new;
+              }
+            else
+              evas_gl_common_image_dirty(im, 0, 0, 0, 0);
+         }
+       *image_data = im->im->image.data;
+       break;
+      case EVAS_COLORSPACE_YCBCR422P601_PL:
+      case EVAS_COLORSPACE_YCBCR422P709_PL:
+       *image_data = im->cs.data;
+       break;
+      default:
+       abort();
+       break;
+     }
+   if (err) *err = error;
+   return im;
+}
+
+static void *
+eng_image_data_put(void *data, void *image, DATA32 *image_data)
+{
+   Render_Engine *re;
+   Evas_GL_Image *im, *im2;
+
+   re = (Render_Engine *)data;
+   if (!image) return NULL;
+   im = image;
+   if (im->native.data) return image;
+   eng_window_use(re->win);
+   if ((im->tex) && (im->tex->pt) && (im->tex->pt->dyn.data))
+     {
+        if (im->tex->pt->dyn.data == image_data)
+          {
+             return image;
+          }
+        else
+          {
+            int w, h;
+
+            w = im->im->cache_entry.w;
+            h = im->im->cache_entry.h;
+            im2 = eng_image_new_from_data(data, w, h, image_data,
+                                          eng_image_alpha_get(data, image),
+                                          eng_image_colorspace_get(data, image));
+            if (!im2) return im;
+            evas_gl_common_image_free(im);
+            im = im2;
+             evas_gl_common_image_dirty(im, 0, 0, 0, 0);
+             return im;
+          }
+     }
+   switch (im->cs.space)
+     {
+      case EVAS_COLORSPACE_ARGB8888:
+       if (image_data != im->im->image.data)
+         {
+            int w, h;
+
+            w = im->im->cache_entry.w;
+            h = im->im->cache_entry.h;
+            im2 = eng_image_new_from_data(data, w, h, image_data,
+                                          eng_image_alpha_get(data, image),
+                                          eng_image_colorspace_get(data, image));
+            if (!im2) return im;
+            evas_gl_common_image_free(im);
+            im = im2;
+         }
+        break;
+      case EVAS_COLORSPACE_YCBCR422P601_PL:
+      case EVAS_COLORSPACE_YCBCR422P709_PL:
+        if (image_data != im->cs.data)
+         {
+            if (im->cs.data)
+              {
+                 if (!im->cs.no_free) free(im->cs.data);
+              }
+            im->cs.data = image_data;
+         }
+       break;
+      default:
+       abort();
+       break;
+     }
+   /* hmmm - but if we wrote... why bother? */
+   evas_gl_common_image_dirty(im, 0, 0, 0, 0);
+   return im;
+}
+
+static void
+eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *target)
+{
+   Evas_GL_Image *gim = image;
+   RGBA_Image *im;
+
+   if (!gim) return;
+   if (gim->native.data) return;
+   im = (RGBA_Image *)gim->im;
+   if (!im) return;
+   evas_cache_image_preload_data(&im->cache_entry, target);
+}
+
+static void
+eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *target)
+{
+   Evas_GL_Image *gim = image;
+   RGBA_Image *im;
+
+   if (!gim) return;
+   if (gim->native.data) return;
+   im = (RGBA_Image *)gim->im;
+   if (!im) return;
+   evas_cache_image_preload_cancel(&im->cache_entry, target);
+}
+
+static void
+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)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   if (!image) return;
+   eng_window_use(re->win);
+   evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
+   re->win->gl_context->dc = context;
+   evas_gl_common_image_draw(re->win->gl_context, image,
+                             src_x, src_y, src_w, src_h,
+                             dst_x, dst_y, dst_w, dst_h,
+                             smooth);
+}
+
+static void
+eng_image_scale_hint_set(void *data __UNUSED__, void *image, int hint)
+{
+   if (image) evas_gl_common_image_scale_hint_set(image, hint);
+}
+
+static int
+eng_image_scale_hint_get(void *data __UNUSED__, void *image)
+{
+   Evas_GL_Image *gim = image;
+   if (!gim) return EVAS_IMAGE_SCALE_HINT_NONE;
+   return gim->scale_hint;
+}
+
+static void
+eng_image_map_draw(void *data __UNUSED__, void *context, void *surface, void *image, int npoints, RGBA_Map_Point *p, int smooth, int level)
+{
+   Evas_GL_Image *gim = image;
+   Render_Engine *re;
+   
+   re = (Render_Engine *)data;
+   if (!image) return;
+   eng_window_use(re->win);
+   evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
+   re->win->gl_context->dc = context;
+   if (npoints != 4)
+     {
+        // FIXME: nash - you didnt fix this
+        abort();
+     }
+   if ((p[0].x == p[3].x) &&
+       (p[1].x == p[2].x) &&
+       (p[0].y == p[1].y) &&
+       (p[3].y == p[2].y) &&
+       (p[0].x <= p[1].x) &&
+       (p[0].y <= p[2].y) &&
+       (p[0].u == 0) &&
+       (p[0].v == 0) &&
+       (p[1].u == (gim->w << FP)) &&
+       (p[1].v == 0) &&
+       (p[2].u == (gim->w << FP)) &&
+       (p[2].v == (gim->h << FP)) &&
+       (p[3].u == 0) &&
+       (p[3].v == (gim->h << FP)) &&
+       (p[0].col == 0xffffffff) &&
+       (p[1].col == 0xffffffff) &&
+       (p[2].col == 0xffffffff) &&
+       (p[3].col == 0xffffffff))
+     {
+        int dx, dy, dw, dh;
+        
+        dx = p[0].x >> FP;
+        dy = p[0].y >> FP;
+        dw = (p[2].x >> FP) - dx;
+        dh = (p[2].y >> FP) - dy;
+        eng_image_draw(data, context, surface, image,
+                       0, 0, gim->w, gim->h, dx, dy, dw, dh, smooth);
+     }
+   else
+     {
+        evas_gl_common_image_map_draw(re->win->gl_context, image, npoints, p,
+                                      smooth, level);
+     }
+}
+
+static void *
+eng_image_map_surface_new(void *data __UNUSED__, int w, int h, int alpha)
+{
+   Render_Engine *re;
+   
+   re = (Render_Engine *)data;
+   return evas_gl_common_image_surface_new(re->win->gl_context, w, h, alpha);
+}
+
+static void
+eng_image_map_surface_free(void *data __UNUSED__, void *surface)
+{
+   evas_gl_common_image_free(surface);
+}
+
+static void
+eng_image_content_hint_set(void *data __UNUSED__, void *image, int hint)
+{
+   if (image) evas_gl_common_image_content_hint_set(image, hint);
+}
+
+static int
+eng_image_content_hint_get(void *data __UNUSED__, void *image)
+{
+   Evas_GL_Image *gim = image;
+   if (!gim) return EVAS_IMAGE_CONTENT_HINT_NONE;
+   return gim->content_hint;
+}
+
+static void
+eng_image_cache_flush(void *data __UNUSED__)
+{
+   Render_Engine *re;
+   int tmp_size;
+   
+   re = (Render_Engine *)data;
+   
+   tmp_size = evas_common_image_get_cache();
+   evas_common_image_set_cache(0);
+   evas_common_rgba_image_scalecache_flush();
+   evas_gl_common_image_cache_flush(re->win->gl_context);
+   evas_common_image_set_cache(tmp_size);
+}
+
+static void
+eng_image_cache_set(void *data __UNUSED__, int bytes)
+{
+   Render_Engine *re;
+   
+   re = (Render_Engine *)data;
+   evas_common_image_set_cache(bytes);
+   evas_common_rgba_image_scalecache_size_set(bytes);
+   evas_gl_common_image_cache_flush(re->win->gl_context);
+}
+
+static int
+eng_image_cache_get(void *data __UNUSED__)
+{
+   Render_Engine *re;
+   
+   re = (Render_Engine *)data;
+   return evas_common_image_get_cache();
+}
+
+
+static void
+eng_image_stride_get(void *data __UNUSED__, void *image, int *stride)
+{
+   Evas_GL_Image *im = image;
+   *stride = im->w * 4;
+   if ((im->tex) && (im->tex->pt->dyn.img))
+     {
+        *stride = im->tex->pt->dyn.w * 4;
+        // FIXME: for other image formats (yuv etc.) different stride needed
+     }
+}
+
+static void
+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)
+{
+   Render_Engine *re;
+
+   re = (Render_Engine *)data;
+   eng_window_use(re->win);
+   evas_gl_common_context_target_surface_set(re->win->gl_context, surface);
+   re->win->gl_context->dc = context;
+     {
+        // FIXME: put im into context so we can free it
+       static RGBA_Image *im = NULL;
+        
+        if (!im)
+          im = (RGBA_Image *)evas_cache_image_empty(evas_common_image_cache_get());
+        im->cache_entry.w = re->win->width;
+        im->cache_entry.h = re->win->height;
+        evas_common_draw_context_font_ext_set(context,
+                                             re->win->gl_context,
+                                             evas_gl_font_texture_new,
+                                             evas_gl_font_texture_free,
+                                             evas_gl_font_texture_draw);
+       evas_common_font_draw(im, context, (RGBA_Font *) font, x, y,
+                              intl_props);
+       evas_common_draw_context_font_ext_set(context,
+                                             NULL,
+                                             NULL,
+                                             NULL,
+                                             NULL);
+     }
+}
+
+
+static Eina_Bool
+eng_canvas_alpha_get(void *data __UNUSED__, void *info __UNUSED__)
+{
+   // FIXME: support ARGB gl targets!!!
+   return EINA_FALSE;
+}
+
+
+#if 1
+static void
+evgl_glBindFramebuffer(GLenum target, GLuint framebuffer)
+{
+   // Add logic to take care when framebuffer=0
+   glBindFramebuffer(target, framebuffer);
+}
+
+static void
+evgl_glBindRenderbuffer(GLenum target, GLuint renderbuffer)
+{
+   // Add logic to take care when renderbuffer=0
+   glBindRenderbuffer(target, renderbuffer);
+}
+
+static void
+evgl_glClearDepthf(GLclampf depth)
+{
+#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
+   glClearDepthf(depth);
+#else
+   glClearDepth(depth);
+#endif
+}
+
+static void
+evgl_glDepthRangef(GLclampf zNear, GLclampf zFar)
+{
+#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
+   glDepthRangef(zNear, zFar);
+#else
+   glDepthRange(zNear, zFar);
+#endif
+}
+
+static void
+evgl_glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
+{
+#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
+   glGetShaderPrecisionFormat(shadertype, precisiontype, range, precision);
+#else
+   if (range)
+     {
+        range[0] = -126; // floor(log2(FLT_MIN))
+        range[1] = 127; // floor(log2(FLT_MAX))
+     }
+   if (precision)
+     {
+        precision[0] = 24; // floor(-log2((1.0/16777218.0)));
+     }
+   return;
+   shadertype = precisiontype = 0;
+#endif
+}
+
+static void
+evgl_glReleaseShaderCompiler(void)
+{
+#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
+   glReleaseShaderCompiler();
+#else
+#endif
+}
+
+static void
+evgl_glShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
+{
+#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
+   glShaderBinary(n, shaders, binaryformat, binary, length);
+#else
+// FIXME: need to dlsym/getprocaddress for this
+   return;
+   n = binaryformat = length = 0;
+   shaders = binary = 0;
+#endif
+}
+
+#endif 
+
+static void *
+eng_gl_api_get(void *data)
+{
+   Render_Engine *re;
+
+   re  = (Render_Engine *)data;
+
+   gl_funcs.version = EVAS_GL_API_VERSION;
+#if 1
+#define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, )
+   ORD(glActiveTexture);
+   ORD(glAttachShader);
+   ORD(glBindAttribLocation);
+   ORD(glBindBuffer);
+   ORD(glBindTexture);
+   ORD(glBlendColor);
+   ORD(glBlendEquation);
+   ORD(glBlendEquationSeparate);
+   ORD(glBlendFunc);
+   ORD(glBlendFuncSeparate);
+   ORD(glBufferData);
+   ORD(glBufferSubData);
+   ORD(glCheckFramebufferStatus);
+   ORD(glClear);
+   ORD(glClearColor);
+//   ORD(glClearDepthf);
+   ORD(glClearStencil);
+   ORD(glColorMask);
+   ORD(glCompileShader);
+   ORD(glCompressedTexImage2D);
+   ORD(glCompressedTexSubImage2D);
+   ORD(glCopyTexImage2D);
+   ORD(glCopyTexSubImage2D);
+   ORD(glCreateProgram);
+   ORD(glCreateShader);
+   ORD(glCullFace);
+   ORD(glDeleteBuffers);
+   ORD(glDeleteFramebuffers);
+   ORD(glDeleteProgram);
+   ORD(glDeleteRenderbuffers);
+   ORD(glDeleteShader);
+   ORD(glDeleteTextures);
+   ORD(glDepthFunc);
+   ORD(glDepthMask);
+//   ORD(glDepthRangef);
+   ORD(glDetachShader);
+   ORD(glDisable);
+   ORD(glDisableVertexAttribArray);
+   ORD(glDrawArrays);
+   ORD(glDrawElements);
+   ORD(glEnable);
+   ORD(glEnableVertexAttribArray);
+   ORD(glFinish);
+   ORD(glFlush);
+   ORD(glFramebufferRenderbuffer);
+   ORD(glFramebufferTexture2D);
+   ORD(glFrontFace);
+   ORD(glGenBuffers);
+   ORD(glGenerateMipmap);
+   ORD(glGenFramebuffers);
+   ORD(glGenRenderbuffers);
+   ORD(glGenTextures);
+   ORD(glGetActiveAttrib);
+   ORD(glGetActiveUniform);
+   ORD(glGetAttachedShaders);
+   ORD(glGetAttribLocation);
+   ORD(glGetBooleanv);
+   ORD(glGetBufferParameteriv);
+   ORD(glGetError);
+   ORD(glGetFloatv);
+   ORD(glGetFramebufferAttachmentParameteriv);
+   ORD(glGetIntegerv);
+   ORD(glGetProgramiv);
+   ORD(glGetProgramInfoLog);
+   ORD(glGetRenderbufferParameteriv);
+   ORD(glGetShaderiv);
+   ORD(glGetShaderInfoLog);
+//   ORD(glGetShaderPrecisionFormat);
+   ORD(glGetShaderSource);
+   ORD(glGetString);
+   ORD(glGetTexParameterfv);
+   ORD(glGetTexParameteriv);
+   ORD(glGetUniformfv);
+   ORD(glGetUniformiv);
+   ORD(glGetUniformLocation);
+   ORD(glGetVertexAttribfv);
+   ORD(glGetVertexAttribiv);
+   ORD(glGetVertexAttribPointerv);
+   ORD(glHint);
+   ORD(glIsBuffer);
+   ORD(glIsEnabled);
+   ORD(glIsFramebuffer);
+   ORD(glIsProgram);
+   ORD(glIsRenderbuffer);
+   ORD(glIsShader);
+   ORD(glIsTexture);
+   ORD(glLineWidth);
+   ORD(glLinkProgram);
+   ORD(glPixelStorei);
+   ORD(glPolygonOffset);
+   ORD(glReadPixels);
+//   ORD(glReleaseShaderCompiler);
+   ORD(glRenderbufferStorage);
+   ORD(glSampleCoverage);
+   ORD(glScissor);
+//   ORD(glShaderBinary);
+   ORD(glShaderSource);
+   ORD(glStencilFunc);
+   ORD(glStencilFuncSeparate);
+   ORD(glStencilMask);
+   ORD(glStencilMaskSeparate);
+   ORD(glStencilOp);
+   ORD(glStencilOpSeparate);
+   ORD(glTexImage2D);
+   ORD(glTexParameterf);
+   ORD(glTexParameterfv);
+   ORD(glTexParameteri);
+   ORD(glTexParameteriv);
+   ORD(glTexSubImage2D);
+   ORD(glUniform1f);
+   ORD(glUniform1fv);
+   ORD(glUniform1i);
+   ORD(glUniform1iv);
+   ORD(glUniform2f);
+   ORD(glUniform2fv);
+   ORD(glUniform2i);
+   ORD(glUniform2iv);
+   ORD(glUniform3f);
+   ORD(glUniform3fv);
+   ORD(glUniform3i);
+   ORD(glUniform3iv);
+   ORD(glUniform4f);
+   ORD(glUniform4fv);
+   ORD(glUniform4i);
+   ORD(glUniform4iv);
+   ORD(glUniformMatrix2fv);
+   ORD(glUniformMatrix3fv);
+   ORD(glUniformMatrix4fv);
+   ORD(glUseProgram);
+   ORD(glValidateProgram);
+   ORD(glVertexAttrib1f);
+   ORD(glVertexAttrib1fv);
+   ORD(glVertexAttrib2f);
+   ORD(glVertexAttrib2fv);
+   ORD(glVertexAttrib3f);
+   ORD(glVertexAttrib3fv);
+   ORD(glVertexAttrib4f);
+   ORD(glVertexAttrib4fv);
+   ORD(glVertexAttribPointer);
+   ORD(glViewport);
+#undef ORD
+
+// Override functions wrapped by Evas_GL
+#define ORD(f) EVAS_API_OVERRIDE(f, &gl_funcs, evgl_)
+   ORD(glBindFramebuffer);         
+   ORD(glBindRenderbuffer);        
+   
+// GLES2.0 API compat on top of desktop gl
+   ORD(glClearDepthf);
+   ORD(glDepthRangef);
+   ORD(glGetShaderPrecisionFormat);
+   ORD(glReleaseShaderCompiler);
+   ORD(glShaderBinary);
+#undef ORD
+
+#endif 
+
+   return &gl_funcs;
+}
+
+static int
+eng_image_load_error_get(void *data __UNUSED__, void *image)
+{
+   Evas_GL_Image *im;
+   
+   if (!image) return EVAS_LOAD_ERROR_NONE;
+   im = image;
+   return im->im->cache_entry.load_error;
+}
+
+static int
+module_open(Evas_Module *em)
+{
+   if (!em) return 0;
+   /* get whatever engine module we inherit from */
+   if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
+   _evas_engine_gl_cocoa_log_dom = eina_log_domain_register("EvasGLCocoa", EVAS_DEFAULT_LOG_COLOR);
+   if(_evas_engine_gl_cocoa_log_dom < 0)
+     {
+       EINA_LOG_ERR("Impossible to create a log domain for GL (Cocoa) engine.");
+       return 0;
+     }
+   /* store it for later use */
+   func = pfunc;
+   /* now to override methods */
+   #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
+   ORD(info);
+   ORD(info_free);
+   ORD(setup);
+   ORD(canvas_alpha_get);
+   ORD(output_free);
+   ORD(output_resize);
+   ORD(output_tile_size_set);
+   ORD(output_redraws_rect_add);
+   ORD(output_redraws_rect_del);
+   ORD(output_redraws_clear);
+   ORD(output_redraws_next_update_get);
+   ORD(output_redraws_next_update_push);
+   ORD(context_cutout_add);
+   ORD(context_cutout_clear);
+   ORD(output_flush);
+   ORD(output_idle_flush);
+   //   ORD(output_dump);
+   ORD(rectangle_draw);
+   ORD(line_draw);
+   ORD(polygon_point_add);
+   ORD(polygon_points_clear);
+   ORD(polygon_draw);
+
+   ORD(image_load);
+   ORD(image_new_from_data);
+   ORD(image_new_from_copied_data);
+   ORD(image_free);
+   ORD(image_size_get);
+   ORD(image_size_set);
+   ORD(image_dirty_region);
+   ORD(image_data_get);
+   ORD(image_data_put);
+   ORD(image_data_preload_request);
+   ORD(image_data_preload_cancel);
+   ORD(image_alpha_set);
+   ORD(image_alpha_get);
+   ORD(image_border_set);
+   ORD(image_border_get);
+   ORD(image_draw);
+   ORD(image_comment_get);
+   ORD(image_format_get);
+   ORD(image_colorspace_set);
+   ORD(image_colorspace_get);
+   ORD(image_mask_create);
+   //   ORD(image_native_set);
+   //   ORD(image_native_get);
+   //   ORD(image_draw_filtered);
+   //   ORD(image_filtered_get);
+   //   ORD(image_filtered_save);
+   //   ORD(image_filtered_free);
+   
+   ORD(font_draw);
+   
+   ORD(image_scale_hint_set);
+   ORD(image_scale_hint_get);
+   ORD(image_stride_get);
+   
+   ORD(image_map_draw);
+   ORD(image_map_surface_new);
+   ORD(image_map_surface_free);
+   
+   ORD(image_content_hint_set);
+   ORD(image_content_hint_get);
+
+   ORD(image_cache_flush);
+   ORD(image_cache_set);
+   ORD(image_cache_get);
+
+   ORD(gl_api_get); 
+
+   ORD(image_load_error_get);    
+
+   /* now advertise out own api */
+   em->functions = (void *)(&func);
+   return 1;
+}
+
+static void
+module_close(Evas_Module *em)
+{
+  eina_log_domain_unregister(_evas_engine_gl_cocoa_log_dom);
+}
+
+static Evas_Module_Api evas_modapi =
+{
+   EVAS_MODULE_API_VERSION,
+   "gl_cocoa",
+   "none",
+   {
+     module_open,
+     module_close
+   }
+};
+
+EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, gl_cocoa);
+
+#ifndef EVAS_STATIC_BUILD_GL_COCOA
+EVAS_EINA_MODULE_DEFINE(engine, gl_cocoa);
+#endif
diff --git a/src/modules/engines/gl_cocoa/evas_engine.h b/src/modules/engines/gl_cocoa/evas_engine.h
new file mode 100644 (file)
index 0000000..a066d3e
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef __EVAS_ENGINE_H__
+#define __EVAS_ENGINE_H__
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <OpenGL/gl.h>
+
+#include "evas_gl_common.h"
+#include "Evas_Engine_GL_Cocoa.h"
+
+extern int _evas_engine_gl_cocoa_log_dom;
+
+#ifdef ERR
+# undef ERR
+#endif
+#define ERR(...) EINA_LOG_DOM_ERR(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
+
+#ifdef DBG
+# undef DBG
+#endif
+#define DBG(...) EINA_LOG_DOM_DBG(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
+
+#ifdef INF
+# undef INF
+#endif
+#define INF(...) EINA_LOG_DOM_INFO(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
+
+#ifdef WRN
+# undef WRN
+#endif
+#define WRN(...) EINA_LOG_DOM_WARN(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
+
+#ifdef CRIT
+# undef CRIT
+#endif
+#define CRIT(...) EINA_LOG_DOM_CRIT(_evas_engine_gl_cocoa_log_dom, __VA_ARGS__)
+
+typedef struct _Evas_GL_Cocoa_Window Evas_GL_Cocoa_Window;
+
+struct _Evas_GL_Cocoa_Window
+{
+   void*            window;
+   void*            view;
+   int              width;
+   int              height;
+   int              depth;
+   Evas_Engine_GL_Context *gl_context;
+   struct {
+      int           x1;
+      int           y1;
+      int           x2;
+      int           y2;
+      int           redraw : 1;
+      int           drew : 1;
+   } draw;
+};
+
+Evas_GL_Cocoa_Window *eng_window_new(void *window,
+                                    int  width,
+                                    int  height);
+void eng_window_free(Evas_GL_Cocoa_Window *gw);
+void eng_window_use(Evas_GL_Cocoa_Window *gw);
+void eng_window_swap_buffers(Evas_GL_Cocoa_Window *gw);
+void eng_window_vsync_set(int on);
+void ng_window_resize(Evas_GL_Cocoa_Window *gw, int width, int height);
+
+#endif /* __EVAS_ENGINE_H__ */
diff --git a/src/modules/engines/gl_cocoa/evas_gl_cocoa_main.m b/src/modules/engines/gl_cocoa/evas_gl_cocoa_main.m
new file mode 100644 (file)
index 0000000..aa6b895
--- /dev/null
@@ -0,0 +1,134 @@
+
+#include <Cocoa/Cocoa.h>
+
+#include "evas_engine.h"
+
+static Evas_GL_Cocoa_Window *_evas_gl_cocoa_window = NULL;
+
+@interface EvasGLView : NSOpenGLView
+{
+}
+
++ (NSOpenGLPixelFormat*) basicPixelFormat;
+- (id) initWithFrame: (NSRect) frameRect;
+
+@end
+
+
+@implementation EvasGLView
+
+- (id) init
+{
+   self = [super init];
+   return self;
+}
+
++ (NSOpenGLPixelFormat*) basicPixelFormat
+{
+   NSOpenGLPixelFormatAttribute attributes [] = {
+            NSOpenGLPFAWindow,
+            NSOpenGLPFAAccelerated,
+            NSOpenGLPFADoubleBuffer,
+            /*NSOpenGLPFAColorSize, 24,
+            NSOpenGLPFAAlphaSize, 8,
+            NSOpenGLPFADepthSize, 24,*/
+            0
+   };
+   return [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
+}
+
+// ---------------------------------
+
+-(id) initWithFrame: (NSRect) frameRect
+{
+   NSOpenGLPixelFormat * pf = [EvasGLView basicPixelFormat];
+   self = [super initWithFrame: frameRect pixelFormat: pf];
+   return self;
+}
+
+@end
+
+
+Evas_GL_Cocoa_Window *
+eng_window_new(void *window,
+              int      w,
+              int      h)
+{
+   Evas_GL_Cocoa_Window *gw;
+   int context_attrs[3];
+   int config_attrs[20];
+   int major_version, minor_version;
+   int num_config;
+
+   gw = calloc(1, sizeof(Evas_GL_Cocoa_Window));
+   if (!gw) return NULL;
+   _evas_gl_cocoa_window = gw;
+   gw->window = window;
+   gw->view = [[EvasGLView alloc] initWithFrame:NSMakeRect(0,0,w,h)];
+   NSOpenGLContext *ctx = [(NSOpenGLView*)gw->view openGLContext];
+   [ctx makeCurrentContext];
+   gw->gl_context = evas_gl_common_context_new();
+
+   if (!gw->gl_context)
+     {
+       free(gw);
+       return NULL;
+     }
+   evas_gl_common_context_use(gw->gl_context);
+   evas_gl_common_context_resize(gw->gl_context, w, h, 0);
+
+   return gw;
+}
+
+void
+eng_window_free(Evas_GL_Cocoa_Window *gw)
+{
+   if (gw == _evas_gl_cocoa_window) _evas_gl_cocoa_window = NULL;
+   evas_gl_common_context_free(gw->gl_context);
+   free(gw);
+}
+
+void
+eng_window_use(Evas_GL_Cocoa_Window *gw)
+{
+   if (_evas_gl_cocoa_window != gw)
+     {
+       [[(NSOpenGLView*)gw->view openGLContext] makeCurrentContext];
+        if (_evas_gl_cocoa_window)
+          evas_gl_common_context_flush(_evas_gl_cocoa_window->gl_context);
+       _evas_gl_cocoa_window = gw;
+
+     }
+   evas_gl_common_context_use(gw->gl_context);
+}
+
+void
+eng_window_swap_buffers(Evas_GL_Cocoa_Window *gw)
+{
+   [[(NSOpenGLView*)gw->view openGLContext] flushBuffer];
+}
+
+void
+eng_window_vsync_set(int on)
+{
+
+}
+
+
+void
+eng_window_resize(Evas_GL_Cocoa_Window *gw, int width, int height)
+{
+  NSRect view_frame;
+
+  INF("Resize %d %d\n", width, height);
+
+  view_frame = [(EvasGLView*)gw->view frame];
+  printf("view_frame : %3.3f %3.3f\n", view_frame.size.height, view_frame.size.width);
+  view_frame.size.height = height;
+  view_frame.size.width = width;
+  printf("view_frame : %3.3f %3.3f\n", view_frame.size.height, view_frame.size.width);
+  [(EvasGLView*)gw->view setFrame:view_frame];
+  [[(NSOpenGLView*)gw->view openGLContext] flushBuffer];
+}
+