summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDongyeon Kim <dy5.kim@samsung.com>2015-07-30 09:14:08 +0900
committerDongyeon Kim <dy5.kim@samsung.com>2015-10-19 17:10:01 +0900
commit1f88f93453a4cef9c7d811bb5568fa75f6140788 (patch)
treea5410b3493a12c06d400452c090e5dcb6a91305a
parent2eaf33d9cf05662d504166aad1bdcd9d9ccf5491 (diff)
Evas GL: Minimize internal resource creationdevs/spacegrapher/evasgl
Summary: Evas GL maintains internal resource (XWindow, EGL Window Surface, EGL Context) per thread to be used for make current when indirect rendering is used. Currently this internal resource is created regardless of current rendering mode, and always created when a new Evas GL thread is created by the application. Internal resource created in a new thread is not freed until evas shuts down in the main thread, so this causes memory/fd leak. This can be fixed by creating internal resource only in necessary cases (ie. indirect rendering), and adding tls resource destructor to be called when thread exits.
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_api.c5
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_api_ext.c2
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_core.c440
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_core.h2
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_core_private.h5
-rw-r--r--src/modules/evas/engines/gl_generic/evas_engine.c15
6 files changed, 274 insertions, 195 deletions
diff --git a/src/modules/evas/engines/gl_common/evas_gl_api.c b/src/modules/evas/engines/gl_common/evas_gl_api.c
index a97204e087..f384fc2854 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_api.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_api.c
@@ -971,6 +971,11 @@ _evgl_glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
971 glViewport(nc[0], nc[1], nc[2], nc[3]); 971 glViewport(nc[0], nc[1], nc[2], nc[3]);
972 } 972 }
973 973
974 ctx->viewport_direct[0] = nc[0];
975 ctx->viewport_direct[1] = nc[1];
976 ctx->viewport_direct[2] = nc[2];
977 ctx->viewport_direct[3] = nc[3];
978
974 // Keep a copy of the original coordinates 979 // Keep a copy of the original coordinates
975 ctx->viewport_coord[0] = x; 980 ctx->viewport_coord[0] = x;
976 ctx->viewport_coord[1] = y; 981 ctx->viewport_coord[1] = y;
diff --git a/src/modules/evas/engines/gl_common/evas_gl_api_ext.c b/src/modules/evas/engines/gl_common/evas_gl_api_ext.c
index eb6f1564e7..1960ec56b1 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_api_ext.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_api_ext.c
@@ -502,7 +502,7 @@ evgl_api_egl_ext_init(void *getproc, const char *glueexts)
502 Eina_Strbuf *sb = NULL; 502 Eina_Strbuf *sb = NULL;
503 503
504 if (_evgl_api_ext_status & EVASGL_API_EGL_EXT_INITIALIZED) 504 if (_evgl_api_ext_status & EVASGL_API_EGL_EXT_INITIALIZED)
505 return EINA_TRUE; 505 return EINA_TRUE;
506 506
507 sb = eina_strbuf_new(); 507 sb = eina_strbuf_new();
508 508
diff --git a/src/modules/evas/engines/gl_common/evas_gl_core.c b/src/modules/evas/engines/gl_common/evas_gl_core.c
index f59d34e1b0..09f1568cbc 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_core.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_core.c
@@ -25,6 +25,9 @@ glsym_func_void_ptr glsym_evas_gl_engine_data_get = NULL;
25static void _surface_cap_print(int error); 25static void _surface_cap_print(int error);
26static void _surface_context_list_print(); 26static void _surface_context_list_print();
27static void _internal_resources_destroy(void *eng_data, EVGL_Resource *rsc); 27static void _internal_resources_destroy(void *eng_data, EVGL_Resource *rsc);
28static void *_egl_image_create(EVGL_Context *context, int target, void *buffer);
29static void _egl_image_destroy(void *image);
30static int _evgl_direct_renderable(EVGL_Resource *rsc, EVGL_Surface *sfc);
28 31
29// NOTE: These constants are "hidden", kinda non public API. They should not 32// NOTE: These constants are "hidden", kinda non public API. They should not
30// be used unless you know exactly what you are doing. 33// be used unless you know exactly what you are doing.
@@ -37,6 +40,7 @@ extern void (*EXT_FUNC_GLES1(glBindFramebufferOES)) (GLenum target, GLuint frame
37extern void (*EXT_FUNC_GLES1(glFramebufferTexture2DOES)) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); 40extern void (*EXT_FUNC_GLES1(glFramebufferTexture2DOES)) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
38extern void (*EXT_FUNC_GLES1(glFramebufferRenderbufferOES)) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); 41extern void (*EXT_FUNC_GLES1(glFramebufferRenderbufferOES)) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
39extern GLenum (*EXT_FUNC_GLES1(glCheckFramebufferStatusOES)) (GLenum target); 42extern GLenum (*EXT_FUNC_GLES1(glCheckFramebufferStatusOES)) (GLenum target);
43
40//---------------------------------------------------------------// 44//---------------------------------------------------------------//
41// Internal Resources: 45// Internal Resources:
42// - Surface and Context used for internal buffer creation 46// - Surface and Context used for internal buffer creation
@@ -60,6 +64,8 @@ _internal_resources_create(void *eng_data)
60 ERR("Error allocating EVGL_Resource"); 64 ERR("Error allocating EVGL_Resource");
61 return NULL; 65 return NULL;
62 } 66 }
67 rsc->id = eina_thread_self();
68 rsc->error_state = EVAS_GL_SUCCESS;
63 69
64 // Get display 70 // Get display
65 rsc->display = evgl_engine->funcs->display_get(eng_data); 71 rsc->display = evgl_engine->funcs->display_get(eng_data);
@@ -69,31 +75,6 @@ _internal_resources_create(void *eng_data)
69 goto error; 75 goto error;
70 } 76 }
71 77
72 // Create resource surface
73 rsc->window = evgl_engine->funcs->native_window_create(eng_data);
74 if (!rsc->window)
75 {
76 ERR("Error creating native window");
77 goto error;
78 }
79
80 rsc->surface = evgl_engine->funcs->surface_create(eng_data, rsc->window);
81 if (!rsc->surface)
82 {
83 ERR("Error creating native surface");
84 goto error;
85 }
86
87 // Create a resource context
88 rsc->context = evgl_engine->funcs->context_create(eng_data, NULL, EVAS_GL_GLES_2_X);
89 if (!rsc->context)
90 {
91 ERR("Internal resource context creation failed.");
92 goto error;
93 }
94
95 rsc->error_state = EVAS_GL_SUCCESS;
96
97 return rsc; 78 return rsc;
98 79
99error: 80error:
@@ -107,17 +88,17 @@ _internal_resources_destroy(void *eng_data, EVGL_Resource *rsc)
107 if ((!eng_data) || (!rsc)) return; 88 if ((!eng_data) || (!rsc)) return;
108 89
109 if (rsc->context) 90 if (rsc->context)
110 evgl_engine->funcs->context_destroy(eng_data, rsc->context); 91 evgl_engine->funcs->context_destroy(eng_data, rsc->context);
111 if (rsc->surface) 92 if (rsc->surface)
112 evgl_engine->funcs->surface_destroy(eng_data, rsc->surface); 93 evgl_engine->funcs->surface_destroy(eng_data, rsc->surface);
113 if (rsc->window) 94 if (rsc->window)
114 evgl_engine->funcs->native_window_destroy(eng_data, rsc->window); 95 evgl_engine->funcs->native_window_destroy(eng_data, rsc->window);
115 96
116 free(rsc); 97 free(rsc);
117} 98}
118 99
119static int 100static int
120_internal_resource_make_current(void *eng_data, EVGL_Context *ctx) 101_internal_resource_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
121{ 102{
122 EVGL_Resource *rsc = NULL; 103 EVGL_Resource *rsc = NULL;
123 void *surface = NULL; 104 void *surface = NULL;
@@ -129,25 +110,94 @@ _internal_resource_make_current(void *eng_data, EVGL_Context *ctx)
129 { 110 {
130 if (!(rsc = _evgl_tls_resource_create(eng_data))) 111 if (!(rsc = _evgl_tls_resource_create(eng_data)))
131 { 112 {
132 ERR("Error creting resources in tls."); 113 ERR("Error creating resources in tls.");
133 return 0; 114 return 0;
134 } 115 }
135 } 116 }
136 117
137 // Set context from input or from resource 118 // Set context from input or from resource
138 if (ctx) 119 if (ctx)
139 context = ctx->context; 120 context = ctx->context;
140 else 121 else
141 context = (void*)rsc->context; 122 {
123 if (!rsc->context)
124 {
125 // Create a resource context
126 rsc->context = evgl_engine->funcs->context_create(eng_data, NULL, EVAS_GL_GLES_2_X);
127 if (!rsc->context)
128 {
129 ERR("Internal resource context creation failed.");
130 return 0;
131 }
132 }
142 133
143 // Set the surface to evas surface if it's there 134 context = (void*)rsc->context;
144 if (rsc->id == evgl_engine->main_tid) 135 }
145 rsc->direct.surface = evgl_engine->funcs->evas_surface_get(eng_data);
146 136
147 if (rsc->direct.surface) 137 if (sfc)
148 surface = (void*)rsc->direct.surface; 138 {
149 else 139 if (_evgl_direct_renderable(rsc, sfc)) // Direct rendering
150 surface = (void*)rsc->surface; 140 {
141 // Do Nothing
142 }
143 else if (ctx->pixmap_image_supported) // Pixmap surface
144 {
145 if (!sfc->indirect_sfc)
146 {
147 evgl_engine->funcs->indirect_surface_create(evgl_engine, eng_data, sfc, sfc->cfg, sfc->w, sfc->h);
148 if (sfc->egl_image) _egl_image_destroy(sfc->egl_image);
149 sfc->egl_image = _egl_image_create(NULL, EVAS_GL_NATIVE_PIXMAP, sfc->indirect_sfc_native);
150 }
151 surface = (void*)sfc->indirect_sfc;
152
153 if (!ctx->indirect_context)
154 ctx->indirect_context = evgl_engine->funcs->gles_context_create(eng_data, ctx, sfc);
155 context = (void*)ctx->indirect_context;
156 }
157 else if (sfc->pbuffer.native_surface) // Pbuffer surface
158 {
159 surface = (void*)sfc->pbuffer.native_surface;
160 }
161 else // FBO
162 {
163 // Do Nothing
164 }
165 }
166
167 if (!surface)
168 {
169 // Set the surface to evas surface if it's there
170 if (rsc->id == evgl_engine->main_tid)
171 rsc->direct.surface = evgl_engine->funcs->evas_surface_get(eng_data);
172
173 if (rsc->direct.surface)
174 surface = (void*)rsc->direct.surface;
175 else
176 {
177 if (!rsc->window)
178 {
179 // Create resource surface
180 rsc->window = evgl_engine->funcs->native_window_create(eng_data);
181 if (!rsc->window)
182 {
183 ERR("Error creating native window");
184 return 0;
185 }
186 }
187
188 if (!rsc->surface)
189 {
190 rsc->surface = evgl_engine->funcs->surface_create(eng_data, rsc->window);
191 if (!rsc->surface)
192 {
193 ERR("Error creating native surface");
194 return 0;
195 }
196 }
197
198 surface = (void*)rsc->surface;
199 }
200 }
151 201
152 // Do the make current 202 // Do the make current
153 if (evgl_engine->api_debug_mode) 203 if (evgl_engine->api_debug_mode)
@@ -798,13 +848,14 @@ error:
798static int 848static int
799_surface_cap_init(void *eng_data) 849_surface_cap_init(void *eng_data)
800{ 850{
851 int ret = 0;
801 int max_size = 0; 852 int max_size = 0;
802 853
803 // Do internal make current 854 // Do internal make current
804 if (!_internal_resource_make_current(eng_data, NULL)) 855 if (!_internal_resource_make_current(eng_data, NULL, NULL))
805 { 856 {
806 ERR("Error doing an internal resource make current"); 857 ERR("Error doing an internal resource make current");
807 return 0; 858 return ret;
808 } 859 }
809 860
810 // Query the max width and height of the surface 861 // Query the max width and height of the surface
@@ -853,13 +904,17 @@ _surface_cap_init(void *eng_data)
853 { 904 {
854 _surface_cap_print(0); 905 _surface_cap_print(0);
855 DBG("Number of supported surface formats: %d", evgl_engine->caps.num_fbo_fmts); 906 DBG("Number of supported surface formats: %d", evgl_engine->caps.num_fbo_fmts);
856 return 1; 907 ret = 1;
857 } 908 }
858 else 909 else
859 { 910 {
860 ERR("There are no available surface formats. Error!"); 911 ERR("There are no available surface formats. Error!");
861 return 0;
862 } 912 }
913
914 // Destroy internal resources
915 _evgl_tls_resource_destroy(eng_data);
916
917 return ret;
863} 918}
864 919
865static int 920static int
@@ -1173,16 +1228,8 @@ _surface_buffers_create(EVGL_Surface *sfc)
1173 1228
1174 1229
1175static int 1230static int
1176_surface_buffers_allocate(void *eng_data, EVGL_Surface *sfc, int w, int h, int mc) 1231_surface_buffers_allocate(void *eng_data EINA_UNUSED, EVGL_Surface *sfc, int w, int h)
1177{ 1232{
1178 // Set the context current with resource context/surface
1179 if (mc)
1180 if (!_internal_resource_make_current(eng_data, NULL))
1181 {
1182 ERR("Error doing an internal resource make current");
1183 return 0;
1184 }
1185
1186 // Create buffers 1233 // Create buffers
1187 if (sfc->color_fmt) 1234 if (sfc->color_fmt)
1188 { 1235 {
@@ -1438,12 +1485,22 @@ _evgl_tls_resource_get(void)
1438 return NULL; 1485 return NULL;
1439 } 1486 }
1440 1487
1441 rsc = eina_tls_get(evgl_engine->resource_key); 1488 if (evgl_engine->resource_key)
1489 rsc = eina_tls_get(evgl_engine->resource_key);
1442 1490
1443 if (!rsc) 1491 return rsc;
1444 return NULL; 1492}
1445 else 1493
1446 return rsc; 1494static void
1495_evgl_tls_resource_destroy_cb(void *data)
1496{
1497 EVGL_Resource *rsc = data;
1498
1499 LKL(evgl_engine->resource_lock);
1500 evgl_engine->resource_list = eina_list_remove(evgl_engine->resource_list, rsc);
1501 LKU(evgl_engine->resource_lock);
1502
1503 _internal_resources_destroy(rsc->current_eng, rsc);
1447} 1504}
1448 1505
1449EVGL_Resource * 1506EVGL_Resource *
@@ -1458,6 +1515,14 @@ _evgl_tls_resource_create(void *eng_data)
1458 return NULL; 1515 return NULL;
1459 } 1516 }
1460 1517
1518 // Initialize Resource TLS
1519 if (!evgl_engine->resource_key && eina_tls_cb_new(&evgl_engine->resource_key, _evgl_tls_resource_destroy_cb) == EINA_FALSE)
1520 {
1521 ERR("Error creating tls key");
1522 return NULL;
1523 }
1524 DBG("TLS KEY created: %d", evgl_engine->resource_key);
1525
1461 // Create internal resources if it hasn't been created already 1526 // Create internal resources if it hasn't been created already
1462 if (!(rsc = _internal_resources_create(eng_data))) 1527 if (!(rsc = _internal_resources_create(eng_data)))
1463 { 1528 {
@@ -1470,7 +1535,6 @@ _evgl_tls_resource_create(void *eng_data)
1470 { 1535 {
1471 // Add to the resource resource list for cleanup 1536 // Add to the resource resource list for cleanup
1472 LKL(evgl_engine->resource_lock); 1537 LKL(evgl_engine->resource_lock);
1473 rsc->id = evgl_engine->resource_count++;
1474 evgl_engine->resource_list = eina_list_prepend(evgl_engine->resource_list, rsc); 1538 evgl_engine->resource_list = eina_list_prepend(evgl_engine->resource_list, rsc);
1475 LKU(evgl_engine->resource_lock); 1539 LKU(evgl_engine->resource_lock);
1476 return rsc; 1540 return rsc;
@@ -1488,6 +1552,8 @@ _evgl_tls_resource_destroy(void *eng_data)
1488{ 1552{
1489 Eina_List *l; 1553 Eina_List *l;
1490 EVGL_Resource *rsc; 1554 EVGL_Resource *rsc;
1555 EVGL_Surface *sfc;
1556 EVGL_Context *ctx;
1491 1557
1492 // Check if engine is valid 1558 // Check if engine is valid
1493 if (!evgl_engine) 1559 if (!evgl_engine)
@@ -1496,18 +1562,30 @@ _evgl_tls_resource_destroy(void *eng_data)
1496 return; 1562 return;
1497 } 1563 }
1498 1564
1499 if (!_evgl_tls_resource_get()) 1565 EINA_LIST_FOREACH(evgl_engine->surfaces, l, sfc)
1500 { 1566 {
1501 ERR("Error retrieving resource from TLS"); 1567 evgl_surface_destroy(eng_data, sfc);
1502 return; 1568 }
1569 EINA_LIST_FOREACH(evgl_engine->contexts, l, ctx)
1570 {
1571 evgl_context_destroy(eng_data, ctx);
1503 } 1572 }
1504 1573
1505 LKL(evgl_engine->resource_lock); 1574 LKL(evgl_engine->resource_lock);
1575
1576 eina_list_free(evgl_engine->surfaces);
1577 evgl_engine->surfaces = NULL;
1578
1579 eina_list_free(evgl_engine->contexts);
1580 evgl_engine->contexts = NULL;
1581
1506 EINA_LIST_FOREACH(evgl_engine->resource_list, l, rsc) 1582 EINA_LIST_FOREACH(evgl_engine->resource_list, l, rsc)
1507 { 1583 {
1508 _internal_resources_destroy(eng_data, rsc); 1584 _internal_resources_destroy(eng_data, rsc);
1509 } 1585 }
1510 eina_list_free(evgl_engine->resource_list); 1586 eina_list_free(evgl_engine->resource_list);
1587 evgl_engine->resource_list = NULL;
1588
1511 LKU(evgl_engine->resource_lock); 1589 LKU(evgl_engine->resource_lock);
1512 1590
1513 // Destroy TLS 1591 // Destroy TLS
@@ -1691,17 +1769,11 @@ evgl_engine_init(void *eng_data, const EVGL_Interface *efunc)
1691 1769
1692 // Assign functions 1770 // Assign functions
1693 evgl_engine->funcs = efunc; 1771 evgl_engine->funcs = efunc;
1694
1695 // Initialize Resource TLS
1696 if (eina_tls_new(&evgl_engine->resource_key) == EINA_FALSE)
1697 {
1698 ERR("Error creating tls key");
1699 goto error;
1700 }
1701 DBG("TLS KEY created: %d", evgl_engine->resource_key);
1702
1703 evgl_engine->safe_extensions = eina_hash_string_small_new(NULL); 1772 evgl_engine->safe_extensions = eina_hash_string_small_new(NULL);
1704 1773
1774 // Main Thread ID
1775 evgl_engine->main_tid = eina_thread_self();
1776
1705 // Surface Caps 1777 // Surface Caps
1706 if (!_surface_cap_init(eng_data)) 1778 if (!_surface_cap_init(eng_data))
1707 { 1779 {
@@ -1747,9 +1819,6 @@ evgl_engine_init(void *eng_data, const EVGL_Interface *efunc)
1747 if (debug_mode == 1) 1819 if (debug_mode == 1)
1748 evgl_engine->api_debug_mode = 1; 1820 evgl_engine->api_debug_mode = 1;
1749 1821
1750 // Maint Thread ID (get tid not available in eina thread yet)
1751 evgl_engine->main_tid = 0;
1752
1753 return evgl_engine; 1822 return evgl_engine;
1754 1823
1755error: 1824error:
@@ -1783,15 +1852,19 @@ evgl_engine_shutdown(void *eng_data)
1783 eina_hash_free(evgl_engine->safe_extensions); 1852 eina_hash_free(evgl_engine->safe_extensions);
1784 evgl_engine->safe_extensions = NULL; 1853 evgl_engine->safe_extensions = NULL;
1785 1854
1786 // Log 1855 if (gles1_funcs) free(gles1_funcs);
1787 eina_log_domain_unregister(_evas_gl_log_dom); 1856 if (gles2_funcs) free(gles2_funcs);
1788 _evas_gl_log_dom = -1; 1857 if (gles3_funcs) free(gles3_funcs);
1789 1858
1790 // Destroy internal resources 1859 // Destroy internal resources
1791 _evgl_tls_resource_destroy(eng_data); 1860 _evgl_tls_resource_destroy(eng_data);
1792 1861
1793 LKD(evgl_engine->resource_lock); 1862 LKD(evgl_engine->resource_lock);
1794 1863
1864 // Log
1865 eina_log_domain_unregister(_evas_gl_log_dom);
1866 _evas_gl_log_dom = -1;
1867
1795 // Free engine 1868 // Free engine
1796 free(evgl_engine); 1869 free(evgl_engine);
1797 evgl_engine = NULL; 1870 evgl_engine = NULL;
@@ -1982,43 +2055,41 @@ evgl_surface_destroy(void *eng_data, EVGL_Surface *sfc)
1982 return 0; 2055 return 0;
1983 } 2056 }
1984 2057
1985 // Retrieve the resource object
1986 if (!(rsc = _evgl_tls_resource_get()))
1987 {
1988 ERR("Error retrieving resource from TLS");
1989 return 0;
1990 }
1991
1992 if ((dbg = evgl_engine->api_debug_mode)) 2058 if ((dbg = evgl_engine->api_debug_mode))
1993 DBG("Destroying surface sfc %p (eng %p)", sfc, eng_data); 2059 DBG("Destroying surface sfc %p (eng %p)", sfc, eng_data);
1994 2060
1995 if ((rsc->current_ctx) && (rsc->current_ctx->current_sfc == sfc) ) 2061 // Retrieve the resource object
2062 rsc = _evgl_tls_resource_get();
2063 if (rsc && rsc->current_ctx)
1996 { 2064 {
1997 if (evgl_engine->api_debug_mode) 2065 // Make current to current context to destroy surface buffers
2066 if (!_internal_resource_make_current(eng_data, sfc, rsc->current_ctx))
1998 { 2067 {
1999 ERR("The context is still current before it's being destroyed. " 2068 ERR("Error doing an internal resource make current");
2000 "Calling make_current(NULL, NULL)"); 2069 return 0;
2001 } 2070 }
2002 else 2071
2072 // Destroy created buffers
2073 if (!_surface_buffers_destroy(sfc))
2003 { 2074 {
2004 WRN("The context is still current before it's being destroyed. " 2075 ERR("Error deleting surface resources.");
2005 "Calling make_current(NULL, NULL)"); 2076 return 0;
2006 } 2077 }
2007 evgl_make_current(eng_data, NULL, NULL);
2008 }
2009 2078
2010 // Make current to current context to destroy surface buffers 2079 if (rsc->current_ctx->current_sfc == sfc)
2011 if (!_internal_resource_make_current(eng_data, rsc->current_ctx)) 2080 {
2012 { 2081 if (evgl_engine->api_debug_mode)
2013 ERR("Error doing an internal resource make current"); 2082 {
2014 return 0; 2083 ERR("The surface is still current before it's being destroyed.");
2015 } 2084 ERR("Doing make_current(NULL, NULL)");
2016 2085 }
2017 // Destroy created buffers 2086 else
2018 if (!_surface_buffers_destroy(sfc)) 2087 {
2019 { 2088 WRN("The surface is still current before it's being destroyed.");
2020 ERR("Error deleting surface resources."); 2089 WRN("Doing make_current(NULL, NULL)");
2021 return 0; 2090 }
2091 evgl_make_current(eng_data, NULL, NULL);
2092 }
2022 } 2093 }
2023 2094
2024 // Destroy indirect surface 2095 // Destroy indirect surface
@@ -2065,8 +2136,12 @@ evgl_surface_destroy(void *eng_data, EVGL_Surface *sfc)
2065 } 2136 }
2066 } 2137 }
2067 2138
2068 if (sfc->current_ctx && sfc->current_ctx->current_sfc == sfc) 2139 if (dbg) DBG("Calling make_current(NULL, NULL)");
2069 sfc->current_ctx->current_sfc = NULL; 2140 if (!evgl_engine->funcs->make_current(eng_data, NULL, NULL, 0))
2141 {
2142 ERR("Error doing make_current(NULL, NULL).");
2143 return 0;
2144 }
2070 2145
2071 // Remove it from the list 2146 // Remove it from the list
2072 LKL(evgl_engine->resource_lock); 2147 LKL(evgl_engine->resource_lock);
@@ -2088,7 +2163,6 @@ evgl_context_create(void *eng_data, EVGL_Context *share_ctx,
2088 void *(*engine_data_get)(void *)) 2163 void *(*engine_data_get)(void *))
2089{ 2164{
2090 EVGL_Context *ctx = NULL; 2165 EVGL_Context *ctx = NULL;
2091 EVGL_Resource *rsc = NULL;
2092 2166
2093 // A little bit ugly. But it works even when dlsym(DEFAULT) doesn't work. 2167 // A little bit ugly. But it works even when dlsym(DEFAULT) doesn't work.
2094 glsym_evas_gl_native_context_get = native_context_get; 2168 glsym_evas_gl_native_context_get = native_context_get;
@@ -2112,12 +2186,6 @@ evgl_context_create(void *eng_data, EVGL_Context *share_ctx,
2112 if (evgl_engine->api_debug_mode) 2186 if (evgl_engine->api_debug_mode)
2113 DBG("Creating context GLESv%d (eng = %p, shctx = %p)", version, eng_data, share_ctx); 2187 DBG("Creating context GLESv%d (eng = %p, shctx = %p)", version, eng_data, share_ctx);
2114 2188
2115 if (!(rsc = _evgl_tls_resource_get()))
2116 {
2117 ERR("Error creating resources in tls.");
2118 return NULL;
2119 }
2120
2121 // Allocate context object 2189 // Allocate context object
2122 ctx = calloc(1, sizeof(EVGL_Context)); 2190 ctx = calloc(1, sizeof(EVGL_Context));
2123 if (!ctx) 2191 if (!ctx)
@@ -2200,16 +2268,31 @@ evgl_context_destroy(void *eng_data, EVGL_Context *ctx)
2200 if (ctx->current_sfc && (ctx->current_sfc->current_ctx == ctx)) 2268 if (ctx->current_sfc && (ctx->current_sfc->current_ctx == ctx))
2201 ctx->current_sfc->current_ctx = NULL; 2269 ctx->current_sfc->current_ctx = NULL;
2202 2270
2203 // Set the context current with resource context/surface 2271 // Delete the FBO
2204 if (!_internal_resource_make_current(eng_data, rsc->current_ctx)) 2272 if (ctx->surface_fbo)
2205 { 2273 {
2206 ERR("Error doing an internal resource make current"); 2274 // Set the context current with resource context/surface
2207 return 0; 2275 if (!_internal_resource_make_current(eng_data, ctx->current_sfc, ctx))
2276 {
2277 ERR("Error doing an internal resource make current");
2278 return 0;
2279 }
2280 glDeleteFramebuffers(1, &ctx->surface_fbo);
2208 } 2281 }
2209 2282
2210 // Delete the FBO 2283 // Retrieve the resource object
2211 if (ctx->surface_fbo) 2284 rsc = _evgl_tls_resource_get();
2212 glDeleteFramebuffers(1, &ctx->surface_fbo); 2285 if (rsc && rsc->current_ctx == ctx)
2286 {
2287 // Unset the currrent context
2288 if (dbg) DBG("Calling make_current(NULL, NULL)");
2289 if (!evgl_engine->funcs->make_current(eng_data, NULL, NULL, 0))
2290 {
2291 ERR("Error doing make_current(NULL, NULL).");
2292 return 0;
2293 }
2294 rsc->current_ctx = NULL;
2295 }
2213 2296
2214 // Destroy indirect rendering context 2297 // Destroy indirect rendering context
2215 if (ctx->indirect_context && 2298 if (ctx->indirect_context &&
@@ -2245,23 +2328,18 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2245 EVGL_Resource *rsc; 2328 EVGL_Resource *rsc;
2246 int curr_fbo = 0; 2329 int curr_fbo = 0;
2247 2330
2248 // Check the input validity. If either sfc or ctx is NULL, it's also error. 2331 // Check the input validity. If either sfc is valid but ctx is NULL, it's also error.
2249 if ( (!evgl_engine) || 2332 // sfc can be NULL as evas gl supports surfaceless make current
2250 (sfc && (!ctx)) ) 2333 if ( (!evgl_engine) || ((sfc) && (!ctx)) )
2251 { 2334 {
2252 ERR("Invalid Inputs. Engine: %p Surface: %p Context: %p!", evgl_engine, sfc, ctx); 2335 ERR("Invalid Input: Engine: %p, Surface: %p, Context: %p", evgl_engine, sfc, ctx);
2253 if(!sfc) evas_gl_common_error_set(eng_data, EVAS_GL_BAD_SURFACE); 2336 if (!evgl_engine) evas_gl_common_error_set(eng_data, EVAS_GL_NOT_INITIALIZED);
2254 if(!ctx) evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONTEXT); 2337 if (!ctx) evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONTEXT);
2255 return 0; 2338 return 0;
2256 } 2339 }
2257 2340
2258 // Get TLS Resources 2341 // Get TLS Resources
2259 rsc = _evgl_tls_resource_get(); 2342 rsc = _evgl_tls_resource_get();
2260
2261 // Abuse debug mode - extra tracing for make_current and friends
2262 dbg = evgl_engine->api_debug_mode;
2263 if (dbg) DBG("(eng = %p, sfc = %p, ctx = %p), rsc = %p", eng_data, sfc, ctx, rsc);
2264
2265 if (!rsc) 2343 if (!rsc)
2266 { 2344 {
2267 DBG("Creating new TLS for this thread: %lu", (unsigned long)eina_thread_self()); 2345 DBG("Creating new TLS for this thread: %lu", (unsigned long)eina_thread_self());
@@ -2269,13 +2347,17 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2269 if (!rsc) return 0; 2347 if (!rsc) return 0;
2270 } 2348 }
2271 2349
2350 // Abuse debug mode - extra tracing for make_current and friends
2351 dbg = evgl_engine->api_debug_mode;
2352 if (dbg) DBG("(eng = %p, sfc = %p, ctx = %p), rsc = %p", eng_data, sfc, ctx, rsc);
2353
2272 // Unset 2354 // Unset
2273 if ((!sfc) && (!ctx)) 2355 if ((!sfc) && (!ctx))
2274 { 2356 {
2275 if (rsc->current_ctx) 2357 if (rsc->current_ctx)
2276 { 2358 {
2277 if (rsc->direct.partial.enabled) 2359 if (rsc->direct.partial.enabled)
2278 evgl_direct_partial_render_end(); 2360 evgl_direct_partial_render_end();
2279 2361
2280 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &curr_fbo); 2362 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &curr_fbo);
2281 if ((rsc->current_ctx->surface_fbo == (GLuint) curr_fbo) || 2363 if ((rsc->current_ctx->surface_fbo == (GLuint) curr_fbo) ||
@@ -2313,7 +2395,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2313 } 2395 }
2314 2396
2315 // Do a make current 2397 // Do a make current
2316 if (!_internal_resource_make_current(eng_data, ctx)) 2398 if (!_internal_resource_make_current(eng_data, sfc, ctx))
2317 { 2399 {
2318 ERR("Error doing a make current with internal surface. Context: %p", ctx); 2400 ERR("Error doing a make current with internal surface. Context: %p", ctx);
2319 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONTEXT); 2401 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONTEXT);
@@ -2326,7 +2408,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2326 // to use fbo & egl image passing to evas 2408 // to use fbo & egl image passing to evas
2327 if (!ctx->extension_checked) 2409 if (!ctx->extension_checked)
2328 { 2410 {
2329 if (!evgl_api_get(eng_data, ctx->version)) 2411 if (!evgl_api_get(eng_data, ctx->version, EINA_FALSE))
2330 { 2412 {
2331 ERR("Unable to get the list of GL APIs for version %d", ctx->version); 2413 ERR("Unable to get the list of GL APIs for version %d", ctx->version);
2332 evas_gl_common_error_set(eng_data, EVAS_GL_NOT_INITIALIZED); 2414 evas_gl_common_error_set(eng_data, EVAS_GL_NOT_INITIALIZED);
@@ -2371,7 +2453,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2371 // Destroy created resources 2453 // Destroy created resources
2372 if (sfc->buffers_allocated) 2454 if (sfc->buffers_allocated)
2373 { 2455 {
2374 if (!_surface_buffers_allocate(eng_data, sfc, 0, 0, 0)) 2456 if (!_surface_buffers_allocate(eng_data, sfc, 0, 0))
2375 { 2457 {
2376 ERR("Unable to destroy surface buffers!"); 2458 ERR("Unable to destroy surface buffers!");
2377 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC); 2459 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC);
@@ -2392,7 +2474,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2392 if (!sfc->buffers_allocated) 2474 if (!sfc->buffers_allocated)
2393 { 2475 {
2394 if (dbg) DBG("Allocating buffers for sfc %p", sfc); 2476 if (dbg) DBG("Allocating buffers for sfc %p", sfc);
2395 if (!_surface_buffers_allocate(eng_data, sfc, sfc->w, sfc->h, 0)) 2477 if (!_surface_buffers_allocate(eng_data, sfc, sfc->w, sfc->h))
2396 { 2478 {
2397 ERR("Unable Create Specificed Surfaces. Unsupported format!"); 2479 ERR("Unable Create Specificed Surfaces. Unsupported format!");
2398 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC); 2480 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC);
@@ -2407,7 +2489,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2407 { 2489 {
2408 if (!sfc->buffers_allocated) 2490 if (!sfc->buffers_allocated)
2409 { 2491 {
2410 if (!_surface_buffers_allocate(eng_data, sfc, sfc->w, sfc->h, 0)) 2492 if (!_surface_buffers_allocate(eng_data, sfc, sfc->w, sfc->h))
2411 { 2493 {
2412 ERR("Unable Create Allocate Memory for Surface."); 2494 ERR("Unable Create Allocate Memory for Surface.");
2413 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC); 2495 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC);
@@ -2436,24 +2518,6 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2436 } 2518 }
2437 else 2519 else
2438 { 2520 {
2439 if (!sfc->indirect_sfc)
2440 {
2441 evgl_engine->funcs->indirect_surface_create(evgl_engine, eng_data, sfc, sfc->cfg, sfc->w, sfc->h);
2442 sfc->egl_image = _egl_image_create(NULL, EVAS_GL_NATIVE_PIXMAP, sfc->indirect_sfc_native);
2443 }
2444 if (!ctx->indirect_context)
2445 {
2446 ctx->indirect_context =
2447 evgl_engine->funcs->gles_context_create(eng_data, ctx, sfc);
2448 }
2449 if (dbg) DBG("Calling make_current(%p, %p)", sfc->indirect_sfc, ctx->indirect_context);
2450 if (!evgl_engine->funcs->make_current(eng_data, sfc->indirect_sfc,
2451 ctx->indirect_context, EINA_TRUE))
2452 {
2453 ERR("Failed to make current with indirect surface.");
2454 return 0;
2455 }
2456
2457 // Transition from direct rendering to indirect rendering 2521 // Transition from direct rendering to indirect rendering
2458 if (rsc->direct.rendered) 2522 if (rsc->direct.rendered)
2459 { 2523 {
@@ -2474,16 +2538,15 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2474 use_extension = EINA_TRUE; 2538 use_extension = EINA_TRUE;
2475#endif 2539#endif
2476 2540
2477 // Normal FBO Rendering
2478 // Create FBO if it hasn't been created
2479 if (!ctx->surface_fbo)
2480 _framebuffer_create(&ctx->surface_fbo, use_extension);
2481
2482 // Direct Rendering 2541 // Direct Rendering
2483 if (_evgl_direct_renderable(rsc, sfc)) 2542 if (_evgl_direct_renderable(rsc, sfc))
2484 { 2543 {
2485 if (dbg) DBG("sfc %p is direct renderable.", sfc); 2544 if (dbg) DBG("sfc %p is direct renderable.", sfc);
2486 2545
2546 // Create FBO if it hasn't been created
2547 if (!ctx->surface_fbo)
2548 _framebuffer_create(&ctx->surface_fbo, use_extension);
2549
2487 // This is to transition from FBO rendering to direct rendering 2550 // This is to transition from FBO rendering to direct rendering
2488 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &curr_fbo); 2551 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &curr_fbo);
2489 if (ctx->surface_fbo == (GLuint)curr_fbo) 2552 if (ctx->surface_fbo == (GLuint)curr_fbo)
@@ -2527,10 +2590,6 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2527 ERR("Could not detach current FBO"); 2590 ERR("Could not detach current FBO");
2528 } 2591 }
2529 2592
2530 if (dbg) DBG("Calling make_current(%p, %p)", sfc->pbuffer.native_surface, ctx->context);
2531 evgl_engine->funcs->make_current(eng_data, sfc->pbuffer.native_surface,
2532 ctx->context, EINA_TRUE);
2533
2534 // Bind to the previously bound buffer (may be 0) 2593 // Bind to the previously bound buffer (may be 0)
2535 if (ctx->current_fbo) 2594 if (ctx->current_fbo)
2536 _framebuffer_bind(ctx->current_fbo, use_extension); 2595 _framebuffer_bind(ctx->current_fbo, use_extension);
@@ -2541,6 +2600,10 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2541 { 2600 {
2542 if (dbg) DBG("Surface sfc %p is a normal surface.", sfc); 2601 if (dbg) DBG("Surface sfc %p is a normal surface.", sfc);
2543 2602
2603 // Create FBO if it hasn't been created
2604 if (!ctx->surface_fbo)
2605 _framebuffer_create(&ctx->surface_fbo, use_extension);
2606
2544 // Attach fbo and the buffers 2607 // Attach fbo and the buffers
2545 if ((rsc->current_ctx != ctx) || (ctx->current_sfc != sfc) || (rsc->direct.rendered)) 2608 if ((rsc->current_ctx != ctx) || (ctx->current_sfc != sfc) || (rsc->direct.rendered))
2546 { 2609 {
@@ -2852,8 +2915,28 @@ evgl_get_pixels_post(void)
2852} 2915}
2853 2916
2854Evas_GL_API * 2917Evas_GL_API *
2855evgl_api_get(void *eng_data, Evas_GL_Context_Version version) 2918evgl_api_get(void *eng_data, Evas_GL_Context_Version version, Eina_Bool alloc_only)
2856{ 2919{
2920 Evas_GL_API *api = NULL;
2921
2922 if (version == EVAS_GL_GLES_2_X)
2923 {
2924 if (!gles2_funcs) gles2_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE);
2925 api = gles2_funcs;
2926 }
2927 else if (version == EVAS_GL_GLES_1_X)
2928 {
2929 if (!gles1_funcs) gles1_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE);
2930 api = gles1_funcs;
2931 }
2932 else if (version == EVAS_GL_GLES_3_X)
2933 {
2934 if (!gles3_funcs) gles3_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE);
2935 api = gles3_funcs;
2936 }
2937 else return NULL;
2938 if (alloc_only) return api;
2939
2857#ifdef GL_GLES 2940#ifdef GL_GLES
2858 if (!evgl_api_egl_ext_init(evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data))) 2941 if (!evgl_api_egl_ext_init(evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data)))
2859 { 2942 {
@@ -2862,32 +2945,21 @@ evgl_api_get(void *eng_data, Evas_GL_Context_Version version)
2862#endif 2945#endif
2863 if (version == EVAS_GL_GLES_2_X) 2946 if (version == EVAS_GL_GLES_2_X)
2864 { 2947 {
2865 if (!gles2_funcs) gles2_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE); 2948 _evgl_api_gles2_get(api, evgl_engine->api_debug_mode);
2866 2949 evgl_api_gles2_ext_get(api, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2867 _evgl_api_gles2_get(gles2_funcs, evgl_engine->api_debug_mode);
2868 evgl_api_gles2_ext_get(gles2_funcs, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2869
2870 return gles2_funcs;
2871 } 2950 }
2872 else if (version == EVAS_GL_GLES_1_X) 2951 else if (version == EVAS_GL_GLES_1_X)
2873 { 2952 {
2874 if (!gles1_funcs) gles1_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE); 2953 _evgl_api_gles1_get(api, evgl_engine->api_debug_mode);
2875 2954 evgl_api_gles1_ext_get(api, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2876 _evgl_api_gles1_get(gles1_funcs, evgl_engine->api_debug_mode);
2877 evgl_api_gles1_ext_get(gles1_funcs, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2878
2879 return gles1_funcs;
2880 } 2955 }
2881 else if (version == EVAS_GL_GLES_3_X) 2956 else if (version == EVAS_GL_GLES_3_X)
2882 { 2957 {
2883 if (!gles3_funcs) gles3_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE); 2958 _evgl_api_gles3_get(api, evgl_engine->api_debug_mode);
2884 2959 evgl_api_gles3_ext_get(api, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2885 _evgl_api_gles3_get(gles3_funcs, evgl_engine->api_debug_mode);
2886 evgl_api_gles3_ext_get(gles3_funcs, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2887
2888 return gles3_funcs;
2889 } 2960 }
2890 else return NULL; 2961
2962 return api;
2891} 2963}
2892 2964
2893 2965
diff --git a/src/modules/evas/engines/gl_common/evas_gl_core.h b/src/modules/evas/engines/gl_common/evas_gl_core.h
index 7c321e2d3f..ba8f5beb78 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_core.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_core.h
@@ -64,7 +64,7 @@ int evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *
64 64
65const char *evgl_string_query(int name); 65const char *evgl_string_query(int name);
66int evgl_native_surface_get(EVGL_Surface *sfc, Evas_Native_Surface *ns); 66int evgl_native_surface_get(EVGL_Surface *sfc, Evas_Native_Surface *ns);
67Evas_GL_API *evgl_api_get(void *eng_data, Evas_GL_Context_Version version); 67Evas_GL_API *evgl_api_get(void *eng_data, Evas_GL_Context_Version version, Eina_Bool alloc_only);
68void evgl_safe_extension_add(const char *name, void *funcptr); 68void evgl_safe_extension_add(const char *name, void *funcptr);
69Eina_Bool evgl_safe_extension_get(const char *name, void **pfuncptr); 69Eina_Bool evgl_safe_extension_get(const char *name, void **pfuncptr);
70 70
diff --git a/src/modules/evas/engines/gl_common/evas_gl_core_private.h b/src/modules/evas/engines/gl_common/evas_gl_core_private.h
index 87c74d245a..d7e9932eab 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_core_private.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_core_private.h
@@ -254,7 +254,7 @@ struct _EVGL_Cap
254 254
255struct _EVGL_Resource 255struct _EVGL_Resource
256{ 256{
257 int id; 257 Eina_Thread id;
258 258
259 EVGLNative_Display display; 259 EVGLNative_Display display;
260 EVGLNative_Context context; 260 EVGLNative_Context context;
@@ -317,8 +317,7 @@ struct _EVGL_Engine
317 LK(resource_lock); 317 LK(resource_lock);
318 Eina_TLS resource_key; 318 Eina_TLS resource_key;
319 Eina_List *resource_list; 319 Eina_List *resource_list;
320 int resource_count; 320 Eina_Thread main_tid;
321 int main_tid;
322 321
323 // Add more debug logs (DBG levels 4 and 6) 322 // Add more debug logs (DBG levels 4 and 6)
324 int api_debug_mode; 323 int api_debug_mode;
diff --git a/src/modules/evas/engines/gl_generic/evas_engine.c b/src/modules/evas/engines/gl_generic/evas_engine.c
index 2cf26ab235..4845c7a47c 100644
--- a/src/modules/evas/engines/gl_generic/evas_engine.c
+++ b/src/modules/evas/engines/gl_generic/evas_engine.c
@@ -63,7 +63,8 @@ _context_restore(void)
63 { 63 {
64 if (rsc->id == evgl_engine->main_tid) 64 if (rsc->id == evgl_engine->main_tid)
65 { 65 {
66 evgl_make_current(rsc->stored.data, rsc->stored.surface, rsc->stored.context); 66 if (rsc->stored.data)
67 evgl_make_current(rsc->stored.data, rsc->stored.surface, rsc->stored.context);
67 _need_context_restore = EINA_FALSE; 68 _need_context_restore = EINA_FALSE;
68 } 69 }
69 } 70 }
@@ -1503,14 +1504,13 @@ eng_gl_make_current(void *data, void *surface, void *context)
1503 Render_Engine_GL_Generic *re = data; 1504 Render_Engine_GL_Generic *re = data;
1504 EVGL_Surface *sfc = (EVGL_Surface *)surface; 1505 EVGL_Surface *sfc = (EVGL_Surface *)surface;
1505 EVGL_Context *ctx = (EVGL_Context *)context; 1506 EVGL_Context *ctx = (EVGL_Context *)context;
1507 int ret = 0;
1506 1508
1507 // TODO: Add check for main thread before flush 1509 // TODO: Add check for main thread before flush
1508 1510
1509 EVGLINIT(data, 0); 1511 if ((sfc) && (ctx))
1510 if (ctx)
1511 { 1512 {
1512 Evas_Engine_GL_Context *gl_context; 1513 Evas_Engine_GL_Context *gl_context;
1513 CONTEXT_STORE(data, surface, context);
1514 1514
1515 gl_context = re->window_gl_context_get(re->software.ob); 1515 gl_context = re->window_gl_context_get(re->software.ob);
1516 if ((gl_context->havestuff) || 1516 if ((gl_context->havestuff) ||
@@ -1523,7 +1523,10 @@ eng_gl_make_current(void *data, void *surface, void *context)
1523 } 1523 }
1524 } 1524 }
1525 1525
1526 return evgl_make_current(data, sfc, ctx); 1526 ret = evgl_make_current(data, sfc, ctx);
1527 CONTEXT_STORE(data, surface, context);
1528
1529 return ret;
1527} 1530}
1528 1531
1529static void * 1532static void *
@@ -1606,7 +1609,7 @@ eng_gl_api_get(void *data, int version)
1606 ERR("Version not supported!"); 1609 ERR("Version not supported!");
1607 return NULL; 1610 return NULL;
1608 } 1611 }
1609 ret = evgl_api_get(data, version); 1612 ret = evgl_api_get(data, version, EINA_TRUE);
1610 1613
1611 //Disable GLES3 support if symbols not present 1614 //Disable GLES3 support if symbols not present
1612 if ((!ret) && (version == EVAS_GL_GLES_3_X)) 1615 if ((!ret) && (version == EVAS_GL_GLES_3_X))