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 09:42:26 +0000
committerCarsten Haitzler <raster@rasterman.com>2010-01-21 09:42:26 +0000
commitdbf33fc10a6c6b94f3bdddf9b0c6eec6396b3eac (patch)
tree14b4ff3898956db26c031f9999e9d1399e76f6c5 /legacy/evas/src/modules/engines/gl_x11/evas_engine.c
parentad2b33c0bbf07cc3fdda85b744f998d0ac028c52 (diff)
some protection against playing with native surfaces (setting image size
doent re-alloc for example) SVN revision: 45385
Diffstat (limited to '')
-rw-r--r--legacy/evas/src/modules/engines/gl_x11/evas_engine.c198
1 files changed, 121 insertions, 77 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 4610c75999..e03b9be4e4 100644
--- a/legacy/evas/src/modules/engines/gl_x11/evas_engine.c
+++ b/legacy/evas/src/modules/engines/gl_x11/evas_engine.c
@@ -12,9 +12,8 @@
12#endif 12#endif
13 13
14#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) 14#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
15# if defined(GLES_VARIETY_S3C6410) 15void (*glsym_eglBindTexImage) (EGLDisplay a, EGLSurface b, int c) = NULL;
16# elif defined(GLES_VARIETY_SGX) 16void (*glsym_eglReleaseTexImage) (EGLDisplay a, EGLSurface b, int c) = NULL;
17# endif
18#else 17#else
19typedef void (*_eng_fn) (void); 18typedef void (*_eng_fn) (void);
20 19
@@ -28,17 +27,23 @@ _sym_init(void)
28{ 27{
29 static int done = 0; 28 static int done = 0;
30 29
31#define FINDSYM(dst, sym) \
32 if ((!dst) && (glsym_glXGetProcAddress)) dst = glsym_glXGetProcAddress(sym); \
33 if (!dst) dst = dlsym(RTLD_DEFAULT, sym)
34 30
35 if (done) return; 31 if (done) return;
36 32
37#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) 33#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
38# if defined(GLES_VARIETY_S3C6410) 34#define FINDSYM(dst, sym) if (!dst) dst = dlsym(RTLD_DEFAULT, sym)
39# elif defined(GLES_VARIETY_SGX) 35 FINDSYM(glsym_eglBindTexImage, "eglBindTexImage");
40# endif 36 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageEXT");
37 FINDSYM(glsym_eglBindTexImage, "eglBindTexImageARB");
38
39 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImage");
40 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageEXT");
41 FINDSYM(glsym_eglReleaseTexImage, "eglReleaseTexImageARB");
41#else 42#else
43#define FINDSYM(dst, sym) \
44 if ((!dst) && (glsym_glXGetProcAddress)) dst = glsym_glXGetProcAddress(sym); \
45 if (!dst) dst = dlsym(RTLD_DEFAULT, sym)
46
42 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddress"); 47 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddress");
43 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressEXT"); 48 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressEXT");
44 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressARB"); 49 FINDSYM(glsym_glXGetProcAddress, "glXGetProcAddressARB");
@@ -896,6 +901,11 @@ eng_image_alpha_set(void *data, void *image, int has_alpha)
896 if (!image) return NULL; 901 if (!image) return NULL;
897 eng_window_use(re->win); 902 eng_window_use(re->win);
898 im = image; 903 im = image;
904 if (im->native.data)
905 {
906 im->alpha = has_alpha;
907 return image;
908 }
899 /* FIXME: can move to gl_common */ 909 /* FIXME: can move to gl_common */
900 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im; 910 if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im;
901 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image; 911 if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image;
@@ -966,6 +976,7 @@ eng_image_colorspace_set(void *data, void *image, int cspace)
966 re = (Render_Engine *)data; 976 re = (Render_Engine *)data;
967 if (!image) return; 977 if (!image) return;
968 im = image; 978 im = image;
979 if (im->native.data) return;
969 /* FIXME: can move to gl_common */ 980 /* FIXME: can move to gl_common */
970 if (im->cs.space == cspace) return; 981 if (im->cs.space == cspace) return;
971 eng_window_use(re->win); 982 eng_window_use(re->win);
@@ -1010,6 +1021,8 @@ struct _Native
1010 Visual *visual; 1021 Visual *visual;
1011 1022
1012#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) 1023#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1024 EGLSurface egl_surface;
1025 EGLContext egl_context;
1013#else 1026#else
1014# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT 1027# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1015 GLXFBConfig fbc; 1028 GLXFBConfig fbc;
@@ -1026,7 +1039,10 @@ _native_bind_cb(void *data, void *image)
1026 Native *n = im->native.data; 1039 Native *n = im->native.data;
1027 1040
1028#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) 1041#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1029// eglBindTexImage(egl->dpy, egl->pixmap_surface, EGL_SINGLE_BUFFER); 1042 if (glsym_eglBindTexImage)
1043 {
1044 glsym_eglBindTexImage(re->win->egl_disp, n->egl_surface, EGL_SINGLE_BUFFER);
1045 }
1030#else 1046#else
1031# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT 1047# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1032 if (glsym_glXBindTexImage) 1048 if (glsym_glXBindTexImage)
@@ -1042,7 +1058,6 @@ _native_bind_cb(void *data, void *image)
1042 1058
1043 n->glx_pixmap = glXCreatePixmap(re->win->disp, n->fbc, 1059 n->glx_pixmap = glXCreatePixmap(re->win->disp, n->fbc,
1044 n->pixmap, pixmap_att); 1060 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, 1061 glsym_glXBindTexImage(re->win->disp, n->glx_pixmap,
1047 GLX_FRONT_LEFT_EXT, NULL); 1062 GLX_FRONT_LEFT_EXT, NULL);
1048 } 1063 }
@@ -1058,12 +1073,14 @@ _native_unbind_cb(void *data, void *image)
1058 Native *n = im->native.data; 1073 Native *n = im->native.data;
1059 1074
1060#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) 1075#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1061// eglReleaseTexImage(egl->dpy, egl->pixmap_surface, EGL_SINGLE_BUFFER); 1076 if (glsym_eglReleaseTexImage)
1077 {
1078 glsym_eglReleaseTexImage(re->win->egl_disp, n->egl_surface, EGL_SINGLE_BUFFER);
1079 }
1062#else 1080#else
1063# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT 1081# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1064 if (glsym_glXReleaseTexImage) 1082 if (glsym_glXReleaseTexImage)
1065 { 1083 {
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, 1084 glsym_glXReleaseTexImage(re->win->disp, n->glx_pixmap,
1068 GLX_FRONT_LEFT_EXT); 1085 GLX_FRONT_LEFT_EXT);
1069 glXDestroyPixmap(re->win->disp, n->glx_pixmap); 1086 glXDestroyPixmap(re->win->disp, n->glx_pixmap);
@@ -1081,17 +1098,16 @@ _native_free_cb(void *data, void *image)
1081 Native *n = im->native.data; 1098 Native *n = im->native.data;
1082 1099
1083#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) 1100#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1084/* if (egl->pixmap_ctx != EGL_NO_CONTEXT) 1101 if (n->egl_context)
1085 { 1102 {
1086 eglDestroyContext(egl->dpy, egl->pixmap_ctx); 1103 eglDestroyContext(re->win->egl_disp, n->egl_context);
1087 egl->pixmap_ctx = EGL_NO_CONTEXT; 1104 n->egl_context = 0;
1088 } 1105 }
1089 if (egl->pixmap_surface != EGL_NO_SURFACE) 1106 if (n->egl_surface)
1090 { 1107 {
1091 eglDestroySurface(egl->dpy, egl->pixmap_surface); 1108 eglDestroySurface(re->win->egl_disp, n->egl_surface);
1092 egl->pixmap_surface = EGL_NO_SURFACE; 1109 n->egl_surface = 0;
1093 } 1110 }
1094 res = true; */
1095#else 1111#else
1096# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT 1112# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT
1097 if (n->glx_pixmap) 1113 if (n->glx_pixmap)
@@ -1120,7 +1136,6 @@ eng_image_native_set(void *data, void *image, void *native)
1120 Visual *vis = NULL; 1136 Visual *vis = NULL;
1121 Pixmap pm = 0; 1137 Pixmap pm = 0;
1122 1138
1123 printf("eng_image_native_set\n");
1124 if (ns) 1139 if (ns)
1125 { 1140 {
1126 vis = ns->data.x11.visual; 1141 vis = ns->data.x11.visual;
@@ -1130,55 +1145,73 @@ eng_image_native_set(void *data, void *image, void *native)
1130 Evas_Native_Surface *n = im->native.data; 1145 Evas_Native_Surface *n = im->native.data;
1131 if ((n->data.x11.visual == vis) && (n->data.x11.pixmap == pm)) 1146 if ((n->data.x11.visual == vis) && (n->data.x11.pixmap == pm))
1132 { 1147 {
1133 printf(" same\n");
1134 return; 1148 return;
1135 } 1149 }
1136 } 1150 }
1137 } 1151 }
1138 printf(" .1\n");
1139 if ((!ns) && (!im->native.data)) return; 1152 if ((!ns) && (!im->native.data)) return;
1140 printf(" ..2\n");
1141 if (!im) return; 1153 if (!im) return;
1142 printf(" ...3\n");
1143#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX) 1154#if defined (GLES_VARIETY_S3C6410) || defined (GLES_VARIETY_SGX)
1144/* EGLConfig cfg; 1155 if (im->native.data)
1145 EGLint num;
1146 EGLint attbs[30] = { NULL, };
1147
1148 EGLint ctx_attbs[] =
1149 { 1156 {
1150 EGL_CONTEXT_CLIENT_VERSION, 2, 1157 if (im->native.func.free)
1151 EGL_NONE 1158 im->native.func.free(im->native.func.data, im);
1152 }; 1159 evas_gl_common_image_native_disable(im);
1153 1160 }
1154 int i = 0; 1161 if (native)
1155 1162 {
1156 attbs[i++] = EGL_RED_SIZE; 1163 Native *n;
1157 attbs[i++] = egl->cfg_r; 1164
1158 attbs[i++] = EGL_GREEN_SIZE; 1165 n = calloc(1, sizeof(Native));
1159 attbs[i++] = egl->cfg_g; 1166 if (n)
1160 attbs[i++] = EGL_BLUE_SIZE; 1167 {
1161 attbs[i++] = egl->cfg_b; 1168 EGLConfig egl_config;
1162 attbs[i++] = EGL_ALPHA_SIZE; 1169 int context_attrs[3];
1163 attbs[i++] = egl->cfg_a; 1170 int config_attrs[20];
1164 attbs[i++] = EGL_DEPTH_SIZE; 1171 int num_config, i;
1165 attbs[i++] = egl->cfg_d; 1172
1166 attbs[i++] = EGL_STENCIL_SIZE; 1173 context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
1167 attbs[i++] = egl->cfg_s; 1174 context_attrs[1] = 2;
1168 attbs[i++] = EGL_RENDERABLE_TYPE; 1175 context_attrs[2] = EGL_NONE;
1169 attbs[i++] = EGL_OPENGL_ES2_BIT; 1176
1170 attbs[i++] = EGL_SURFACE_TYPE; 1177 i = 0;
1171 attbs[i++] = EGL_PIXMAP_BIT; // for pixmap surface 1178 config_attrs[i++] = EGL_RED_SIZE;
1172 attbs[i++] = EGL_NONE; 1179 config_attrs[i++] = 8;
1173 1180 config_attrs[i++] = EGL_GREEN_SIZE;
1174 eglChooseConfig(egl->dpy, attbs, &cfg, 1, &num); 1181 config_attrs[i++] = 8;
1175 egl->pixmap_surface = eglCreatePixmapSurface(egl->dpy, cfg, pixmap, NULL); 1182 config_attrs[i++] = EGL_BLUE_SIZE;
1176 eglBindAPI(EGL_OPENGL_ES_API); 1183 config_attrs[i++] = 8;
1177 egl->pixmap_ctx = eglCreateContext(egl->dpy, cfg, EGL_NO_CONTEXT, ctx_attbs); */ 1184 config_attrs[i++] = EGL_ALPHA_SIZE;
1185 config_attrs[i++] = 8;
1186 config_attrs[i++] = EGL_DEPTH_SIZE;
1187 config_attrs[i++] = 32;
1188 config_attrs[i++] = EGL_RENDERABLE_TYPE;
1189 config_attrs[i++] = EGL_OPENGL_ES2_BIT;
1190 config_attrs[i++] = EGL_SURFACE_TYPE;
1191 config_attrs[i++] = EGL_PIXMAP_BIT;
1192 config_attrs[i++] = EGL_NONE;
1193
1194 eglChooseConfig(re->win->egl_disp, config_attrs,
1195 &egl_config, 1, &num_config);
1196 n->egl_surface = eglCreatePixmapSurface(re->win->egl_disp,
1197 egl_config, pixmap,
1198 NULL);
1199 eglBindAPI(EGL_OPENGL_ES_API);
1200 n->egl_context = eglCreateContext(re->win->egl_disp, egl_config,
1201 NULL, context_attrs);
1202 evas_gl_common_image_native_enable(im);
1203 n->pixmap = pm;
1204 n->visual = vis;
1205 im->native.yinvert = 1;
1206 im->native.data = n;
1207 im->native.func.data = re;
1208 im->native.func.bind = _native_bind_cb;
1209 im->native.func.unbind = _native_unbind_cb;
1210 im->native.func.free = _native_free_cb;
1211 }
1212 }
1178#else 1213#else
1179# ifdef GLX_BIND_TO_TEXTURE_TARGETS_EXT 1214# 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) 1215 if (im->native.data)
1183 { 1216 {
1184 if (im->native.func.free) 1217 if (im->native.func.free)
@@ -1196,10 +1229,8 @@ eng_image_native_set(void *data, void *image, void *native)
1196 fbc = glXGetFBConfigs(re->win->disp, 1229 fbc = glXGetFBConfigs(re->win->disp,
1197 0 /* FIXME: screen 0 assumption */, 1230 0 /* FIXME: screen 0 assumption */,
1198 &num); 1231 &num);
1199 printf(" .....5\n");
1200 if (fbc) 1232 if (fbc)
1201 { 1233 {
1202 printf(" ......6\n");
1203 for (i = 0; i < num; i++) 1234 for (i = 0; i < num; i++)
1204 { 1235 {
1205 XVisualInfo *vi; 1236 XVisualInfo *vi;
@@ -1240,12 +1271,9 @@ eng_image_native_set(void *data, void *image, void *native)
1240 { 1271 {
1241 Native *n; 1272 Native *n;
1242 1273
1243 printf(" .......7\n");
1244 n = calloc(1, sizeof(Native)); 1274 n = calloc(1, sizeof(Native));
1245 if (n) 1275 if (n)
1246 { 1276 {
1247
1248 printf(" .......8\n");
1249 evas_gl_common_image_native_enable(im); 1277 evas_gl_common_image_native_enable(im);
1250 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface)); 1278 memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
1251 n->pixmap = pm; 1279 n->pixmap = pm;
@@ -1258,7 +1286,6 @@ eng_image_native_set(void *data, void *image, void *native)
1258 im->native.func.bind = _native_bind_cb; 1286 im->native.func.bind = _native_bind_cb;
1259 im->native.func.unbind = _native_unbind_cb; 1287 im->native.func.unbind = _native_unbind_cb;
1260 im->native.func.free = _native_free_cb; 1288 im->native.func.free = _native_free_cb;
1261 printf(" yinvert = %i\n", yinvert);
1262 } 1289 }
1263 } 1290 }
1264 } 1291 }
@@ -1337,18 +1364,25 @@ eng_image_size_get(void *data, void *image, int *w, int *h)
1337 *h = 0; 1364 *h = 0;
1338 return; 1365 return;
1339 } 1366 }
1340 if (w) *w = ((Evas_GL_Image *)image)->im->cache_entry.w; 1367 if (w) *w = ((Evas_GL_Image *)image)->w;
1341 if (h) *h = ((Evas_GL_Image *)image)->im->cache_entry.h; 1368 if (h) *h = ((Evas_GL_Image *)image)->h;
1342} 1369}
1343 1370
1344static void * 1371static void *
1345eng_image_size_set(void *data, void *image, int w, int h) 1372eng_image_size_set(void *data, void *image, int w, int h)
1346{ 1373{
1347 Render_Engine *re; 1374 Render_Engine *re;
1348 Evas_GL_Image *im, *im_old; 1375 Evas_GL_Image *im = image;
1349 1376 Evas_GL_Image *im_old;
1377
1350 re = (Render_Engine *)data; 1378 re = (Render_Engine *)data;
1351 if (!image) return NULL; 1379 if (!im) return NULL;
1380 if (im->native.data)
1381 {
1382 im->w = w;
1383 im->h = h;
1384 return image;
1385 }
1352 eng_window_use(re->win); 1386 eng_window_use(re->win);
1353 im_old = image; 1387 im_old = image;
1354 if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) || 1388 if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) ||
@@ -1380,10 +1414,12 @@ static void *
1380eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h) 1414eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
1381{ 1415{
1382 Render_Engine *re; 1416 Render_Engine *re;
1417 Evas_GL_Image *im = image;
1383 1418
1384 re = (Render_Engine *)data; 1419 re = (Render_Engine *)data;
1385 if (!image) return NULL; 1420 if (!image) return NULL;
1386 eng_window_use(re->win); 1421 eng_window_use(re->win);
1422 if (im->native.data) return image;
1387 evas_gl_common_image_dirty(image, x, y, w, h); 1423 evas_gl_common_image_dirty(image, x, y, w, h);
1388 return image; 1424 return image;
1389} 1425}
@@ -1401,6 +1437,11 @@ eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data)
1401 return NULL; 1437 return NULL;
1402 } 1438 }
1403 im = image; 1439 im = image;
1440 if (im->native.data)
1441 {
1442 *image_data = NULL;
1443 return im;
1444 }
1404 eng_window_use(re->win); 1445 eng_window_use(re->win);
1405 evas_cache_image_load_data(&im->im->cache_entry); 1446 evas_cache_image_load_data(&im->im->cache_entry);
1406 switch (im->cs.space) 1447 switch (im->cs.space)
@@ -1448,6 +1489,7 @@ eng_image_data_put(void *data, void *image, DATA32 *image_data)
1448 re = (Render_Engine *)data; 1489 re = (Render_Engine *)data;
1449 if (!image) return NULL; 1490 if (!image) return NULL;
1450 im = image; 1491 im = image;
1492 if (im->native.data) return image;
1451 eng_window_use(re->win); 1493 eng_window_use(re->win);
1452 switch (im->cs.space) 1494 switch (im->cs.space)
1453 { 1495 {
@@ -1492,9 +1534,10 @@ eng_image_data_preload_request(void *data __UNUSED__, void *image, const void *t
1492 Evas_GL_Image *gim = image; 1534 Evas_GL_Image *gim = image;
1493 RGBA_Image *im; 1535 RGBA_Image *im;
1494 1536
1495 if (!gim) return ; 1537 if (!gim) return;
1496 im = (RGBA_Image*) gim->im; 1538 if (gim->native.data) return;
1497 if (!im) return ; 1539 im = (RGBA_Image *)gim->im;
1540 if (!im) return;
1498 evas_cache_image_preload_data(&im->cache_entry, target); 1541 evas_cache_image_preload_data(&im->cache_entry, target);
1499} 1542}
1500 1543
@@ -1504,9 +1547,10 @@ eng_image_data_preload_cancel(void *data __UNUSED__, void *image, const void *ta
1504 Evas_GL_Image *gim = image; 1547 Evas_GL_Image *gim = image;
1505 RGBA_Image *im; 1548 RGBA_Image *im;
1506 1549
1507 if (!gim) return ; 1550 if (!gim) return;
1508 im = (RGBA_Image*) gim->im; 1551 if (gim->native.data) return;
1509 if (!im) return ; 1552 im = (RGBA_Image *)gim->im;
1553 if (!im) return;
1510 evas_cache_image_preload_cancel(&im->cache_entry, target); 1554 evas_cache_image_preload_cancel(&im->cache_entry, target);
1511} 1555}
1512 1556