summaryrefslogtreecommitdiff
path: root/legacy/evas/src/modules/engines/gl_x11/evas_engine.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2010-01-21 08:44:11 +0000
committerCarsten Haitzler <raster@rasterman.com>2010-01-21 08:44:11 +0000
commitad2b33c0bbf07cc3fdda85b744f998d0ac028c52 (patch)
tree0610c503008bff3e98c19f62718a268f3ad31b9b /legacy/evas/src/modules/engines/gl_x11/evas_engine.c
parent7c3f53b36450b0a21b9701aabc1607c76b237d61 (diff)
native surface support lives - for GL (GLX) only. it works - or seemingly
does in my test casses. doesn't work for compositing though! don't know why. SVN revision: 45383
Diffstat (limited to '')
-rw-r--r--legacy/evas/src/modules/engines/gl_x11/evas_engine.c357
1 files changed, 342 insertions, 15 deletions
diff --git a/legacy/evas/src/modules/engines/gl_x11/evas_engine.c b/legacy/evas/src/modules/engines/gl_x11/evas_engine.c
index 2156f28358..4610c75999 100644
--- a/legacy/evas/src/modules/engines/gl_x11/evas_engine.c
+++ b/legacy/evas/src/modules/engines/gl_x11/evas_engine.c
@@ -1,13 +1,63 @@
1#include "evas_engine.h" 1#include "evas_engine.h"
2 2
3// EGL / GLES 3#include <dlfcn.h> /* dlopen,dlclose,etc */
4
4#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) 5#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
6// EGL / GLES
5# if defined(GLES_VARIETY_S3C6410) 7# if defined(GLES_VARIETY_S3C6410)
6# elif defined(GLES_VARIETY_SGX) 8# elif defined(GLES_VARIETY_SGX)
7# endif 9# endif
10#else
8// GLX 11// GLX
12#endif
13
14#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
15# if defined(GLES_VARIETY_S3C6410)
16# elif defined(GLES_VARIETY_SGX)
17# endif
18#else
19typedef void (*_eng_fn) (void);
20
21_eng_fn (*glsym_glXGetProcAddress) (const char *a) = NULL;
22void (*glsym_glXBindTexImage) (Display *a, GLXDrawable b, int c, int *d) = NULL;
23void (*glsym_glXReleaseTexImage) (Display *a, GLXDrawable b, int c) = NULL;
24#endif
25
26static void
27_sym_init(void)
28{
29 static int done = 0;
30
31#define FINDSYM(dst, sym) \
32 if ((!dst) && (glsym_glXGetProcAddress)) dst = glsym_glXGetProcAddress(sym); \
33 if (!dst) dst = dlsym(RTLD_DEFAULT, sym)
34
35 if (done) return;
36
37#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
38# if defined(GLES_VARIETY_S3C6410)
39# elif defined(GLES_VARIETY_SGX)
40# endif
9#else 41#else
42 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddress");
43 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressEXT");
44 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressARB");
45
46 FINDSYM(glsym_glXBindTexImage, "glXBindTexImage");
47 FINDSYM(glsym_glXBindTexImage, "glXBindTexImageEXT");
48 FINDSYM(glsym_glXBindTexImage, "glXBindTexImageARB");
49
50 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImage");
51 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImageEXT");
52 FINDSYM(glsym_glXReleaseTexImage, "glXReleaseTexImageARB");
53
54 printf("glXGetProcAddress: %p\n"
55 "glXBindTexImage: %p\n"
56 "glXReleaseTexImage: %p\n",
57 glsym_glXGetProcAddress,
58 glsym_glXBindTexImage, glsym_glXReleaseTexImage);
10#endif 59#endif
60}
11 61
12int _evas_engine_GL_X11_log_dom = -1; 62int _evas_engine_GL_X11_log_dom = -1;
13/* function tables - filled in later (func and parent func) */ 63/* function tables - filled in later (func and parent func) */
@@ -30,6 +80,7 @@ static void *
30eng_info(Evas *e) 80eng_info(Evas *e)
31{ 81{
32 Evas_Engine_Info_GL_X11 *info; 82 Evas_Engine_Info_GL_X11 *info;
83
33 info = calloc(1, sizeof(Evas_Engine_Info_GL_X11)); 84 info = calloc(1, sizeof(Evas_Engine_Info_GL_X11));
34 info->magic.magic = rand(); 85 info->magic.magic = rand();
35 info->func.best_visual_get = eng_best_visual_get; 86 info->func.best_visual_get = eng_best_visual_get;
@@ -161,6 +212,8 @@ eng_setup(Evas *e, void *in)
161 e->engine.func->context_new(e->engine.data.output); 212 e->engine.func->context_new(e->engine.data.output);
162 eng_window_use(re->win); 213 eng_window_use(re->win);
163 214
215 _sym_init();
216
164 return 1; 217 return 1;
165} 218}
166 219
@@ -337,21 +390,21 @@ eng_output_flush(void *data)
337 eglSwapBuffers(re->win->egl_disp, re->win->egl_surface[0]); 390 eglSwapBuffers(re->win->egl_disp, re->win->egl_surface[0]);
338#else 391#else
339# ifdef VSYNC_TO_SCREEN 392# ifdef VSYNC_TO_SCREEN
340 { 393// {
341 unsigned int rc; 394// unsigned int rc;
342 395//
343 glXGetVideoSyncSGI(&rc); 396// glXGetVideoSyncSGI(&rc);
344 glXWaitVideoSyncSGI(2, (rc + 1) % 2, &rc); 397// glXWaitVideoSyncSGI(2, (rc + 1) % 2, &rc);
345 } 398// }
346# endif 399# endif
347# ifdef SLOW_GL_COPY_RECT 400# ifdef SLOW_GL_COPY_RECT
348 glXSwapBuffers(re->win->disp, re->win->win); 401 glXSwapBuffers(re->win->disp, re->win->win);
349# else 402# else
350 /* SLOW AS ALL HELL! */ 403// /* SLOW AS ALL HELL! */
351 evas_gl_common_swap_rect(re->win->gl_context, 404// evas_gl_common_swap_rect(re->win->gl_context,
352 re->win->draw.x1, re->win->draw.y1, 405// re->win->draw.x1, re->win->draw.y1,
353 re->win->draw.x2 - re->win->draw.x1 + 1, 406// re->win->draw.x2 - re->win->draw.x1 + 1,
354 re->win->draw.y2 - re->win->draw.y1 + 1); 407// re->win->draw.y2 - re->win->draw.y1 + 1);
355# endif 408# endif
356// glFlush(); 409// glFlush();
357// glXWaitGL(); 410// glXWaitGL();
@@ -945,17 +998,291 @@ eng_image_colorspace_set(void *data, void *image, int cspace)
945 im->cs.space = cspace; 998 im->cs.space = cspace;
946} 999}
947 1000
1001/////////////////////////////////////////////////////////////////////////
1002//
1003//
1004typedef struct _Native Native;
1005
1006struct _Native
1007{
1008 Evas_Native_Surface ns;
1009 Pixmap pixmap;
1010 Visual *visual;
1011
1012#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1013#else
1014# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1015 GLXFBConfig fbc;
1016 GLXPixmap glx_pixmap;
1017# endif
1018#endif
1019};
1020
1021static void
1022_native_bind_cb(void *data, void *image)
1023{
1024 Render_Engine *re = data;
1025 Evas_GL_Image *im = image;
1026 Native *n = im->native.data;
1027
1028#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1029// eglBindTexImage(egl->dpy, egl->pixmap_surface, EGL_SINGLE_BUFFER);
1030#else
1031# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1032 if (glsym_glXBindTexImage)
1033 {
1034 const int pixmap_att[] =
1035 {
1036 GLX_TEXTURE_TARGET_EXT,
1037 GLX_TEXTURE_2D_EXT,
1038 GLX_TEXTURE_FORMAT_EXT,
1039 GLX_TEXTURE_FORMAT_RGBA_EXT,
1040 0
1041 };
1042
1043 n->glx_pixmap = glXCreatePixmap(re->win->disp, n->fbc,
1044 n->pixmap, pixmap_att);
1045 printf("bind: %p %i %i %p\n", re->win->disp, n->glx_pixmap, GLX_FRONT_LEFT_EXT, NULL);
1046 glsym_glXBindTexImage(re->win->disp, n->glx_pixmap,
1047 GLX_FRONT_LEFT_EXT, NULL);
1048 }
1049# endif
1050#endif
1051}
1052
1053static void
1054_native_unbind_cb(void *data, void *image)
1055{
1056 Render_Engine *re = data;
1057 Evas_GL_Image *im = image;
1058 Native *n = im->native.data;
1059
1060#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1061// eglReleaseTexImage(egl->dpy, egl->pixmap_surface, EGL_SINGLE_BUFFER);
1062#else
1063# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1064 if (glsym_glXReleaseTexImage)
1065 {
1066 printf("unbind: %p %i %i\n", re->win->disp, n->glx_pixmap, GLX_FRONT_LEFT_EXT);
1067 glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap,
1068 GLX_FRONT_LEFT_EXT);
1069 glXDestroyPixmap(re->win->disp, n->glx_pixmap);
1070 n->glx_pixmap = 0;
1071 }
1072# endif
1073#endif
1074}
1075
948static void 1076static void
949eng_image_native_set(void *data __UNUSED__, void *image __UNUSED__, void *native __UNUSED__) 1077_native_free_cb(void *data, void *image)
950{ 1078{
1079 Render_Engine *re = data;
1080 Evas_GL_Image *im = image;
1081 Native *n = im->native.data;
1082
1083#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1084/* if (egl->pixmap_ctx != EGL_NO_CONTEXT)
1085 {
1086 eglDestroyContext(egl->dpy, egl->pixmap_ctx);
1087 egl->pixmap_ctx = EGL_NO_CONTEXT;
1088 }
1089 if (egl->pixmap_surface != EGL_NO_SURFACE)
1090 {
1091 eglDestroySurface(egl->dpy, egl->pixmap_surface);
1092 egl->pixmap_surface = EGL_NO_SURFACE;
1093 }
1094 res = true; */
1095#else
1096# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1097 if (n->glx_pixmap)
1098 {
1099 glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap,
1100 GLX_FRONT_LEFT_EXT);
1101 glXDestroyPixmap(re->win->disp, n->glx_pixmap);
1102 n->glx_pixmap = 0;
1103 }
1104# endif
1105#endif
1106 im->native.data = NULL;
1107 im->native.func.data = NULL;
1108 im->native.func.bind = NULL;
1109 im->native.func.unbind = NULL;
1110 im->native.func.free = NULL;
1111 free(n);
1112}
1113
1114static void
1115eng_image_native_set(void *data, void *image, void *native)
1116{
1117 Render_Engine *re = (Render_Engine *)data;
1118 Evas_Native_Surface *ns = native;
1119 Evas_GL_Image *im = image;
1120 Visual *vis = NULL;
1121 Pixmap pm = 0;
1122
1123 printf("eng_image_native_set\n");
1124 if (ns)
1125 {
1126 vis = ns->data.x11.visual;
1127 pm = ns->data.x11.pixmap;
1128 if (im->native.data)
1129 {
1130 Evas_Native_Surface *n = im->native.data;
1131 if ((n->data.x11.visual == vis) && (n->data.x11.pixmap == pm))
1132 {
1133 printf(" same\n");
1134 return;
1135 }
1136 }
1137 }
1138 printf(" .1\n");
1139 if ((!ns) && (!im->native.data)) return;
1140 printf(" ..2\n");
1141 if (!im) return;
1142 printf(" ...3\n");
1143#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1144/* EGLConfig cfg;
1145 EGLint num;
1146 EGLint attbs[30] = { NULL, };
1147
1148 EGLint ctx_attbs[] =
1149 {
1150 EGL_CONTEXT_CLIENT_VERSION, 2,
1151 EGL_NONE
1152 };
1153
1154 int i = 0;
1155
1156 attbs[i++] = EGL_RED_SIZE;
1157 attbs[i++] = egl->cfg_r;
1158 attbs[i++] = EGL_GREEN_SIZE;
1159 attbs[i++] = egl->cfg_g;
1160 attbs[i++] = EGL_BLUE_SIZE;
1161 attbs[i++] = egl->cfg_b;
1162 attbs[i++] = EGL_ALPHA_SIZE;
1163 attbs[i++] = egl->cfg_a;
1164 attbs[i++] = EGL_DEPTH_SIZE;
1165 attbs[i++] = egl->cfg_d;
1166 attbs[i++] = EGL_STENCIL_SIZE;
1167 attbs[i++] = egl->cfg_s;
1168 attbs[i++] = EGL_RENDERABLE_TYPE;
1169 attbs[i++] = EGL_OPENGL_ES2_BIT;
1170 attbs[i++] = EGL_SURFACE_TYPE;
1171 attbs[i++] = EGL_PIXMAP_BIT; // for pixmap surface
1172 attbs[i++] = EGL_NONE;
1173
1174 eglChooseConfig(egl->dpy, attbs, &cfg, 1, &num);
1175 egl->pixmap_surface = eglCreatePixmapSurface(egl->dpy, cfg, pixmap, NULL);
1176 eglBindAPI(EGL_OPENGL_ES_API);
1177 egl->pixmap_ctx = eglCreateContext(egl->dpy, cfg, EGL_NO_CONTEXT, ctx_attbs); */
1178#else
1179# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1180 printf(" ....4\n");
1181 // FIXME: if there is already a natiive surface - free it
1182 if (im->native.data)
1183 {
1184 if (im->native.func.free)
1185 im->native.func.free(im->native.func.data, im);
1186 evas_gl_common_image_native_disable(im);
1187 }
1188 if (native)
1189 {
1190 VisualID vid;
1191 GLXFBConfig *fbc;
1192 int i, num;
1193 int yinvert = 0;
1194
1195 vid = XVisualIDFromVisual(vis);
1196 fbc = glXGetFBConfigs(re->win->disp,
1197 0 /* FIXME: screen 0 assumption */,
1198 &num);
1199 printf(" .....5\n");
1200 if (fbc)
1201 {
1202 printf(" ......6\n");
1203 for (i = 0; i < num; i++)
1204 {
1205 XVisualInfo *vi;
1206 int val;
1207
1208 vi = glXGetVisualFromFBConfig(re->win->disp, fbc[i]);
1209 if ((!vi) || (vi->visualid != vid))
1210 continue;
1211
1212 glXGetFBConfigAttrib(re->win->disp, fbc[i],
1213 GLX_DRAWABLE_TYPE, &val);
1214 if (!(val & GLX_PIXMAP_BIT)) continue;
1215
1216 glXGetFBConfigAttrib(re->win->disp, fbc[i],
1217 GLX_BIND_TO_TEXTURE_TARGETS_EXT, &val);
1218 if (!(val & GLX_TEXTURE_2D_BIT_EXT)) continue;
1219
1220 glXGetFBConfigAttrib(re->win->disp, fbc[i],
1221 GLX_BIND_TO_TEXTURE_RGBA_EXT, &val);
1222 if (!val)
1223 {
1224 glXGetFBConfigAttrib(re->win->disp, fbc[i],
1225 GLX_BIND_TO_TEXTURE_RGB_EXT, &val);
1226 if (!val) continue;
1227 }
1228
1229 glXGetFBConfigAttrib(re->win->disp, fbc[i],
1230 GLX_Y_INVERTED_EXT, &val);
1231 if (val) yinvert = 1;
1232 break;
1233 }
1234 if (i == num)
1235 {
1236 printf(" err \n");
1237 // error
1238 }
1239 else
1240 {
1241 Native *n;
1242
1243 printf(" .......7\n");
1244 n = calloc(1, sizeof(Native));
1245 if (n)
1246 {
1247
1248 printf(" .......8\n");
1249 evas_gl_common_image_native_enable(im);
1250 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
1251 n->pixmap = pm;
1252 n->visual = vis;
1253 memcpy(&(n->fbc), fbc, sizeof(GLXFBConfig));
1254 n->fbc = *fbc;
1255 im->native.yinvert = yinvert;
1256 im->native.data = n;
1257 im->native.func.data = re;
1258 im->native.func.bind = _native_bind_cb;
1259 im->native.func.unbind = _native_unbind_cb;
1260 im->native.func.free = _native_free_cb;
1261 printf(" yinvert = %i\n", yinvert);
1262 }
1263 }
1264 }
1265 }
1266# endif
1267#endif
951} 1268}
952 1269
953static void * 1270static void *
954eng_image_native_get(void *data __UNUSED__, void *image __UNUSED__) 1271eng_image_native_get(void *data, void *image)
955{ 1272{
956 return NULL; 1273 Render_Engine *re = (Render_Engine *)data;
1274 Evas_GL_Image *im = image;
1275 Native *n;
1276 if (!im) return NULL;
1277 n = im->native.data;
1278 if (!n) return NULL;
1279 return &(n->ns);
957} 1280}
958 1281
1282//
1283//
1284/////////////////////////////////////////////////////////////////////////
1285
959static void * 1286static void *
960eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo) 1287eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
961{ 1288{