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-11-11 15:59:52 +0900
commit65b2a436397d8cad4155968f214d1f68ce3d951f (patch)
tree82fe0ba0e98f4244946bb24b3a169e1f50d4f0f8
parent80ebf5b4531384bebac4f4b851d3489b98f3eb99 (diff)
Evas GL: Minimize internal resource creation
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.c444
-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, 279 insertions, 194 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 44a87cc..2c96a6c 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_api.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_api.c
@@ -1571,6 +1571,11 @@ _evgl_glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
1571 glViewport(nc[0], nc[1], nc[2], nc[3]); 1571 glViewport(nc[0], nc[1], nc[2], nc[3]);
1572 } 1572 }
1573 1573
1574 ctx->viewport_direct[0] = nc[0];
1575 ctx->viewport_direct[1] = nc[1];
1576 ctx->viewport_direct[2] = nc[2];
1577 ctx->viewport_direct[3] = nc[3];
1578
1574 // Keep a copy of the original coordinates 1579 // Keep a copy of the original coordinates
1575 ctx->viewport_coord[0] = x; 1580 ctx->viewport_coord[0] = x;
1576 ctx->viewport_coord[1] = y; 1581 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 7c41575..b826df7 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
@@ -567,7 +567,7 @@ evgl_api_egl_ext_init(void *getproc, const char *glueexts)
567 Eina_Strbuf *sb = NULL; 567 Eina_Strbuf *sb = NULL;
568 568
569 if (_evgl_api_ext_status & EVASGL_API_EGL_EXT_INITIALIZED) 569 if (_evgl_api_ext_status & EVASGL_API_EGL_EXT_INITIALIZED)
570 return EINA_TRUE; 570 return EINA_TRUE;
571 571
572 sb = eina_strbuf_new(); 572 sb = eina_strbuf_new();
573 573
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 2a0787d..75b1b98 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)
@@ -815,13 +865,14 @@ error:
815static int 865static int
816_surface_cap_init(void *eng_data) 866_surface_cap_init(void *eng_data)
817{ 867{
868 int ret = 0;
818 int max_size = 0; 869 int max_size = 0;
819 870
820 // Do internal make current 871 // Do internal make current
821 if (!_internal_resource_make_current(eng_data, NULL)) 872 if (!_internal_resource_make_current(eng_data, NULL, NULL))
822 { 873 {
823 ERR("Error doing an internal resource make current"); 874 ERR("Error doing an internal resource make current");
824 return 0; 875 return ret;
825 } 876 }
826 877
827 // Query the max width and height of the surface 878 // Query the max width and height of the surface
@@ -870,13 +921,17 @@ _surface_cap_init(void *eng_data)
870 { 921 {
871 _surface_cap_print(0); 922 _surface_cap_print(0);
872 DBG("Number of supported surface formats: %d", evgl_engine->caps.num_fbo_fmts); 923 DBG("Number of supported surface formats: %d", evgl_engine->caps.num_fbo_fmts);
873 return 1; 924 ret = 1;
874 } 925 }
875 else 926 else
876 { 927 {
877 ERR("There are no available surface formats. Error!"); 928 ERR("There are no available surface formats. Error!");
878 return 0;
879 } 929 }
930
931 // Destroy internal resources
932 _evgl_tls_resource_destroy(eng_data);
933
934 return ret;
880} 935}
881 936
882static int 937static int
@@ -1190,16 +1245,8 @@ _surface_buffers_create(EVGL_Surface *sfc)
1190 1245
1191 1246
1192static int 1247static int
1193_surface_buffers_allocate(void *eng_data, EVGL_Surface *sfc, int w, int h, int mc, Evas_GL_Context_Version version) 1248_surface_buffers_allocate(void *eng_data EINA_UNUSED, EVGL_Surface *sfc, int w, int h, Evas_GL_Context_Version version)
1194{ 1249{
1195 // Set the context current with resource context/surface
1196 if (mc)
1197 if (!_internal_resource_make_current(eng_data, NULL))
1198 {
1199 ERR("Error doing an internal resource make current");
1200 return 0;
1201 }
1202
1203 // Create buffers 1250 // Create buffers
1204 if (sfc->color_fmt) 1251 if (sfc->color_fmt)
1205 { 1252 {
@@ -1464,12 +1511,22 @@ _evgl_tls_resource_get(void)
1464 return NULL; 1511 return NULL;
1465 } 1512 }
1466 1513
1467 rsc = eina_tls_get(evgl_engine->resource_key); 1514 if (evgl_engine->resource_key)
1515 rsc = eina_tls_get(evgl_engine->resource_key);
1468 1516
1469 if (!rsc) 1517 return rsc;
1470 return NULL; 1518}
1471 else 1519
1472 return rsc; 1520static void
1521_evgl_tls_resource_destroy_cb(void *data)
1522{
1523 EVGL_Resource *rsc = data;
1524
1525 LKL(evgl_engine->resource_lock);
1526 evgl_engine->resource_list = eina_list_remove(evgl_engine->resource_list, rsc);
1527 LKU(evgl_engine->resource_lock);
1528
1529 _internal_resources_destroy(rsc->current_eng, rsc);
1473} 1530}
1474 1531
1475EVGL_Resource * 1532EVGL_Resource *
@@ -1484,6 +1541,14 @@ _evgl_tls_resource_create(void *eng_data)
1484 return NULL; 1541 return NULL;
1485 } 1542 }
1486 1543
1544 // Initialize Resource TLS
1545 if (!evgl_engine->resource_key && eina_tls_cb_new(&evgl_engine->resource_key, _evgl_tls_resource_destroy_cb) == EINA_FALSE)
1546 {
1547 ERR("Error creating tls key");
1548 return NULL;
1549 }
1550 DBG("TLS KEY created: %d", evgl_engine->resource_key);
1551
1487 // Create internal resources if it hasn't been created already 1552 // Create internal resources if it hasn't been created already
1488 if (!(rsc = _internal_resources_create(eng_data))) 1553 if (!(rsc = _internal_resources_create(eng_data)))
1489 { 1554 {
@@ -1496,7 +1561,6 @@ _evgl_tls_resource_create(void *eng_data)
1496 { 1561 {
1497 // Add to the resource resource list for cleanup 1562 // Add to the resource resource list for cleanup
1498 LKL(evgl_engine->resource_lock); 1563 LKL(evgl_engine->resource_lock);
1499 rsc->id = evgl_engine->resource_count++;
1500 evgl_engine->resource_list = eina_list_prepend(evgl_engine->resource_list, rsc); 1564 evgl_engine->resource_list = eina_list_prepend(evgl_engine->resource_list, rsc);
1501 LKU(evgl_engine->resource_lock); 1565 LKU(evgl_engine->resource_lock);
1502 return rsc; 1566 return rsc;
@@ -1514,6 +1578,8 @@ _evgl_tls_resource_destroy(void *eng_data)
1514{ 1578{
1515 Eina_List *l; 1579 Eina_List *l;
1516 EVGL_Resource *rsc; 1580 EVGL_Resource *rsc;
1581 EVGL_Surface *sfc;
1582 EVGL_Context *ctx;
1517 1583
1518 // Check if engine is valid 1584 // Check if engine is valid
1519 if (!evgl_engine) 1585 if (!evgl_engine)
@@ -1522,18 +1588,30 @@ _evgl_tls_resource_destroy(void *eng_data)
1522 return; 1588 return;
1523 } 1589 }
1524 1590
1525 if (!_evgl_tls_resource_get()) 1591 EINA_LIST_FOREACH(evgl_engine->surfaces, l, sfc)
1526 { 1592 {
1527 ERR("Error retrieving resource from TLS"); 1593 evgl_surface_destroy(eng_data, sfc);
1528 return; 1594 }
1595 EINA_LIST_FOREACH(evgl_engine->contexts, l, ctx)
1596 {
1597 evgl_context_destroy(eng_data, ctx);
1529 } 1598 }
1530 1599
1531 LKL(evgl_engine->resource_lock); 1600 LKL(evgl_engine->resource_lock);
1601
1602 eina_list_free(evgl_engine->surfaces);
1603 evgl_engine->surfaces = NULL;
1604
1605 eina_list_free(evgl_engine->contexts);
1606 evgl_engine->contexts = NULL;
1607
1532 EINA_LIST_FOREACH(evgl_engine->resource_list, l, rsc) 1608 EINA_LIST_FOREACH(evgl_engine->resource_list, l, rsc)
1533 { 1609 {
1534 _internal_resources_destroy(eng_data, rsc); 1610 _internal_resources_destroy(eng_data, rsc);
1535 } 1611 }
1536 eina_list_free(evgl_engine->resource_list); 1612 eina_list_free(evgl_engine->resource_list);
1613 evgl_engine->resource_list = NULL;
1614
1537 LKU(evgl_engine->resource_lock); 1615 LKU(evgl_engine->resource_lock);
1538 1616
1539 // Destroy TLS 1617 // Destroy TLS
@@ -1717,17 +1795,11 @@ evgl_engine_init(void *eng_data, const EVGL_Interface *efunc)
1717 1795
1718 // Assign functions 1796 // Assign functions
1719 evgl_engine->funcs = efunc; 1797 evgl_engine->funcs = efunc;
1720
1721 // Initialize Resource TLS
1722 if (eina_tls_new(&evgl_engine->resource_key) == EINA_FALSE)
1723 {
1724 ERR("Error creating tls key");
1725 goto error;
1726 }
1727 DBG("TLS KEY created: %d", evgl_engine->resource_key);
1728
1729 evgl_engine->safe_extensions = eina_hash_string_small_new(NULL); 1798 evgl_engine->safe_extensions = eina_hash_string_small_new(NULL);
1730 1799
1800 // Main Thread ID
1801 evgl_engine->main_tid = eina_thread_self();
1802
1731 // Surface Caps 1803 // Surface Caps
1732 if (!_surface_cap_init(eng_data)) 1804 if (!_surface_cap_init(eng_data))
1733 { 1805 {
@@ -1773,9 +1845,6 @@ evgl_engine_init(void *eng_data, const EVGL_Interface *efunc)
1773 if (debug_mode == 1) 1845 if (debug_mode == 1)
1774 evgl_engine->api_debug_mode = 1; 1846 evgl_engine->api_debug_mode = 1;
1775 1847
1776 // Maint Thread ID (get tid not available in eina thread yet)
1777 evgl_engine->main_tid = 0;
1778
1779 return evgl_engine; 1848 return evgl_engine;
1780 1849
1781error: 1850error:
@@ -1809,15 +1878,19 @@ evgl_engine_shutdown(void *eng_data)
1809 eina_hash_free(evgl_engine->safe_extensions); 1878 eina_hash_free(evgl_engine->safe_extensions);
1810 evgl_engine->safe_extensions = NULL; 1879 evgl_engine->safe_extensions = NULL;
1811 1880
1812 // Log 1881 if (gles1_funcs) free(gles1_funcs);
1813 eina_log_domain_unregister(_evas_gl_log_dom); 1882 if (gles2_funcs) free(gles2_funcs);
1814 _evas_gl_log_dom = -1; 1883 if (gles3_funcs) free(gles3_funcs);
1815 1884
1816 // Destroy internal resources 1885 // Destroy internal resources
1817 _evgl_tls_resource_destroy(eng_data); 1886 _evgl_tls_resource_destroy(eng_data);
1818 1887
1819 LKD(evgl_engine->resource_lock); 1888 LKD(evgl_engine->resource_lock);
1820 1889
1890 // Log
1891 eina_log_domain_unregister(_evas_gl_log_dom);
1892 _evas_gl_log_dom = -1;
1893
1821 // Free engine 1894 // Free engine
1822 free(evgl_engine); 1895 free(evgl_engine);
1823 evgl_engine = NULL; 1896 evgl_engine = NULL;
@@ -2008,43 +2081,41 @@ evgl_surface_destroy(void *eng_data, EVGL_Surface *sfc)
2008 return 0; 2081 return 0;
2009 } 2082 }
2010 2083
2011 // Retrieve the resource object
2012 if (!(rsc = _evgl_tls_resource_get()))
2013 {
2014 ERR("Error retrieving resource from TLS");
2015 return 0;
2016 }
2017
2018 if ((dbg = evgl_engine->api_debug_mode)) 2084 if ((dbg = evgl_engine->api_debug_mode))
2019 DBG("Destroying surface sfc %p (eng %p)", sfc, eng_data); 2085 DBG("Destroying surface sfc %p (eng %p)", sfc, eng_data);
2020 2086
2021 if ((rsc->current_ctx) && (rsc->current_ctx->current_sfc == sfc) ) 2087 // Retrieve the resource object
2088 rsc = _evgl_tls_resource_get();
2089 if (rsc && rsc->current_ctx)
2022 { 2090 {
2023 if (evgl_engine->api_debug_mode) 2091 // Make current to current context to destroy surface buffers
2092 if (!_internal_resource_make_current(eng_data, sfc, rsc->current_ctx))
2024 { 2093 {
2025 ERR("The context is still current before it's being destroyed. " 2094 ERR("Error doing an internal resource make current");
2026 "Calling make_current(NULL, NULL)"); 2095 return 0;
2027 } 2096 }
2028 else 2097
2098 // Destroy created buffers
2099 if (!_surface_buffers_destroy(sfc))
2029 { 2100 {
2030 WRN("The context is still current before it's being destroyed. " 2101 ERR("Error deleting surface resources.");
2031 "Calling make_current(NULL, NULL)"); 2102 return 0;
2032 } 2103 }
2033 evgl_make_current(eng_data, NULL, NULL);
2034 }
2035 2104
2036 // Make current to current context to destroy surface buffers 2105 if (rsc->current_ctx->current_sfc == sfc)
2037 if (!_internal_resource_make_current(eng_data, rsc->current_ctx)) 2106 {
2038 { 2107 if (evgl_engine->api_debug_mode)
2039 ERR("Error doing an internal resource make current"); 2108 {
2040 return 0; 2109 ERR("The surface is still current before it's being destroyed.");
2041 } 2110 ERR("Doing make_current(NULL, NULL)");
2042 2111 }
2043 // Destroy created buffers 2112 else
2044 if (!_surface_buffers_destroy(sfc)) 2113 {
2045 { 2114 WRN("The surface is still current before it's being destroyed.");
2046 ERR("Error deleting surface resources."); 2115 WRN("Doing make_current(NULL, NULL)");
2047 return 0; 2116 }
2117 evgl_make_current(eng_data, NULL, NULL);
2118 }
2048 } 2119 }
2049 2120
2050 // Destroy indirect surface 2121 // Destroy indirect surface
@@ -2091,8 +2162,12 @@ evgl_surface_destroy(void *eng_data, EVGL_Surface *sfc)
2091 } 2162 }
2092 } 2163 }
2093 2164
2094 if (sfc->current_ctx && sfc->current_ctx->current_sfc == sfc) 2165 if (dbg) DBG("Calling make_current(NULL, NULL)");
2095 sfc->current_ctx->current_sfc = NULL; 2166 if (!evgl_engine->funcs->make_current(eng_data, NULL, NULL, 0))
2167 {
2168 ERR("Error doing make_current(NULL, NULL).");
2169 return 0;
2170 }
2096 2171
2097 // Remove it from the list 2172 // Remove it from the list
2098 LKL(evgl_engine->resource_lock); 2173 LKL(evgl_engine->resource_lock);
@@ -2114,7 +2189,6 @@ evgl_context_create(void *eng_data, EVGL_Context *share_ctx,
2114 void *(*engine_data_get)(void *)) 2189 void *(*engine_data_get)(void *))
2115{ 2190{
2116 EVGL_Context *ctx = NULL; 2191 EVGL_Context *ctx = NULL;
2117 EVGL_Resource *rsc = NULL;
2118 2192
2119 // A little bit ugly. But it works even when dlsym(DEFAULT) doesn't work. 2193 // A little bit ugly. But it works even when dlsym(DEFAULT) doesn't work.
2120 glsym_evas_gl_native_context_get = native_context_get; 2194 glsym_evas_gl_native_context_get = native_context_get;
@@ -2138,12 +2212,6 @@ evgl_context_create(void *eng_data, EVGL_Context *share_ctx,
2138 if (evgl_engine->api_debug_mode) 2212 if (evgl_engine->api_debug_mode)
2139 DBG("Creating context GLESv%d (eng = %p, shctx = %p)", version, eng_data, share_ctx); 2213 DBG("Creating context GLESv%d (eng = %p, shctx = %p)", version, eng_data, share_ctx);
2140 2214
2141 if (!(rsc = _evgl_tls_resource_get()))
2142 {
2143 ERR("Error creating resources in tls.");
2144 return NULL;
2145 }
2146
2147 // Allocate context object 2215 // Allocate context object
2148 ctx = calloc(1, sizeof(EVGL_Context)); 2216 ctx = calloc(1, sizeof(EVGL_Context));
2149 if (!ctx) 2217 if (!ctx)
@@ -2227,16 +2295,31 @@ evgl_context_destroy(void *eng_data, EVGL_Context *ctx)
2227 if (ctx->current_sfc && (ctx->current_sfc->current_ctx == ctx)) 2295 if (ctx->current_sfc && (ctx->current_sfc->current_ctx == ctx))
2228 ctx->current_sfc->current_ctx = NULL; 2296 ctx->current_sfc->current_ctx = NULL;
2229 2297
2230 // Set the context current with resource context/surface 2298 // Delete the FBO
2231 if (!_internal_resource_make_current(eng_data, rsc->current_ctx)) 2299 if (ctx->surface_fbo)
2232 { 2300 {
2233 ERR("Error doing an internal resource make current"); 2301 // Set the context current with resource context/surface
2234 return 0; 2302 if (!_internal_resource_make_current(eng_data, ctx->current_sfc, ctx))
2303 {
2304 ERR("Error doing an internal resource make current");
2305 return 0;
2306 }
2307 glDeleteFramebuffers(1, &ctx->surface_fbo);
2235 } 2308 }
2236 2309
2237 // Delete the FBO 2310 // Retrieve the resource object
2238 if (ctx->surface_fbo) 2311 rsc = _evgl_tls_resource_get();
2239 glDeleteFramebuffers(1, &ctx->surface_fbo); 2312 if (rsc && rsc->current_ctx == ctx)
2313 {
2314 // Unset the currrent context
2315 if (dbg) DBG("Calling make_current(NULL, NULL)");
2316 if (!evgl_engine->funcs->make_current(eng_data, NULL, NULL, 0))
2317 {
2318 ERR("Error doing make_current(NULL, NULL).");
2319 return 0;
2320 }
2321 rsc->current_ctx = NULL;
2322 }
2240 2323
2241 // Destroy indirect rendering context 2324 // Destroy indirect rendering context
2242 if (ctx->indirect_context && 2325 if (ctx->indirect_context &&
@@ -2271,23 +2354,18 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2271 EVGL_Resource *rsc; 2354 EVGL_Resource *rsc;
2272 int curr_fbo = 0, curr_draw_fbo = 0, curr_read_fbo = 0; 2355 int curr_fbo = 0, curr_draw_fbo = 0, curr_read_fbo = 0;
2273 2356
2274 // Check the input validity. If either sfc or ctx is NULL, it's also error. 2357 // Check the input validity. If either sfc is valid but ctx is NULL, it's also error.
2275 if ( (!evgl_engine) || 2358 // sfc can be NULL as evas gl supports surfaceless make current
2276 (sfc && (!ctx)) ) 2359 if ( (!evgl_engine) || ((sfc) && (!ctx)) )
2277 { 2360 {
2278 ERR("Invalid Inputs. Engine: %p Surface: %p Context: %p!", evgl_engine, sfc, ctx); 2361 ERR("Invalid Input: Engine: %p, Surface: %p, Context: %p", evgl_engine, sfc, ctx);
2279 if(!sfc) evas_gl_common_error_set(eng_data, EVAS_GL_BAD_SURFACE); 2362 if (!evgl_engine) evas_gl_common_error_set(eng_data, EVAS_GL_NOT_INITIALIZED);
2280 if(!ctx) evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONTEXT); 2363 if (!ctx) evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONTEXT);
2281 return 0; 2364 return 0;
2282 } 2365 }
2283 2366
2284 // Get TLS Resources 2367 // Get TLS Resources
2285 rsc = _evgl_tls_resource_get(); 2368 rsc = _evgl_tls_resource_get();
2286
2287 // Abuse debug mode - extra tracing for make_current and friends
2288 dbg = evgl_engine->api_debug_mode;
2289 if (dbg) DBG("(eng = %p, sfc = %p, ctx = %p), rsc = %p", eng_data, sfc, ctx, rsc);
2290
2291 if (!rsc) 2369 if (!rsc)
2292 { 2370 {
2293 DBG("Creating new TLS for this thread: %lu", (unsigned long)eina_thread_self()); 2371 DBG("Creating new TLS for this thread: %lu", (unsigned long)eina_thread_self());
@@ -2295,13 +2373,17 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2295 if (!rsc) return 0; 2373 if (!rsc) return 0;
2296 } 2374 }
2297 2375
2376 // Abuse debug mode - extra tracing for make_current and friends
2377 dbg = evgl_engine->api_debug_mode;
2378 if (dbg) DBG("(eng = %p, sfc = %p, ctx = %p), rsc = %p", eng_data, sfc, ctx, rsc);
2379
2298 // Unset 2380 // Unset
2299 if ((!sfc) && (!ctx)) 2381 if ((!sfc) && (!ctx))
2300 { 2382 {
2301 if (rsc->current_ctx) 2383 if (rsc->current_ctx)
2302 { 2384 {
2303 if (rsc->direct.partial.enabled) 2385 if (rsc->direct.partial.enabled)
2304 evgl_direct_partial_render_end(); 2386 evgl_direct_partial_render_end();
2305 2387
2306 if (rsc->current_ctx->version == EVAS_GL_GLES_3_X) 2388 if (rsc->current_ctx->version == EVAS_GL_GLES_3_X)
2307 { 2389 {
@@ -2355,7 +2437,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2355 } 2437 }
2356 2438
2357 // Do a make current 2439 // Do a make current
2358 if (!_internal_resource_make_current(eng_data, ctx)) 2440 if (!_internal_resource_make_current(eng_data, sfc, ctx))
2359 { 2441 {
2360 ERR("Error doing a make current with internal surface. Context: %p", ctx); 2442 ERR("Error doing a make current with internal surface. Context: %p", ctx);
2361 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONTEXT); 2443 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_CONTEXT);
@@ -2368,7 +2450,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2368 // to use fbo & egl image passing to evas 2450 // to use fbo & egl image passing to evas
2369 if (!ctx->extension_checked) 2451 if (!ctx->extension_checked)
2370 { 2452 {
2371 if (!evgl_api_get(eng_data, ctx->version)) 2453 if (!evgl_api_get(eng_data, ctx->version, EINA_FALSE))
2372 { 2454 {
2373 ERR("Unable to get the list of GL APIs for version %d", ctx->version); 2455 ERR("Unable to get the list of GL APIs for version %d", ctx->version);
2374 evas_gl_common_error_set(eng_data, EVAS_GL_NOT_INITIALIZED); 2456 evas_gl_common_error_set(eng_data, EVAS_GL_NOT_INITIALIZED);
@@ -2413,7 +2495,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2413 // Destroy created resources 2495 // Destroy created resources
2414 if (sfc->buffers_allocated) 2496 if (sfc->buffers_allocated)
2415 { 2497 {
2416 if (!_surface_buffers_allocate(eng_data, sfc, 0, 0, 0, ctx->version)) 2498 if (!_surface_buffers_allocate(eng_data, sfc, 0, 0, ctx->version))
2417 { 2499 {
2418 ERR("Unable to destroy surface buffers!"); 2500 ERR("Unable to destroy surface buffers!");
2419 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC); 2501 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC);
@@ -2434,7 +2516,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2434 if (!sfc->buffers_allocated) 2516 if (!sfc->buffers_allocated)
2435 { 2517 {
2436 if (dbg) DBG("Allocating buffers for sfc %p", sfc); 2518 if (dbg) DBG("Allocating buffers for sfc %p", sfc);
2437 if (!_surface_buffers_allocate(eng_data, sfc, sfc->w, sfc->h, 1, ctx->version)) 2519 if (!_surface_buffers_allocate(eng_data, sfc, sfc->w, sfc->h, ctx->version))
2438 { 2520 {
2439 ERR("Unable Create Specificed Surfaces. Unsupported format!"); 2521 ERR("Unable Create Specificed Surfaces. Unsupported format!");
2440 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC); 2522 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC);
@@ -2449,7 +2531,7 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2449 { 2531 {
2450 if (!sfc->buffers_allocated) 2532 if (!sfc->buffers_allocated)
2451 { 2533 {
2452 if (!_surface_buffers_allocate(eng_data, sfc, sfc->w, sfc->h, 0, ctx->version)) 2534 if (!_surface_buffers_allocate(eng_data, sfc, sfc->w, sfc->h, ctx->version))
2453 { 2535 {
2454 ERR("Unable Create Allocate Memory for Surface."); 2536 ERR("Unable Create Allocate Memory for Surface.");
2455 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC); 2537 evas_gl_common_error_set(eng_data, EVAS_GL_BAD_ALLOC);
@@ -2478,24 +2560,6 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2478 } 2560 }
2479 else 2561 else
2480 { 2562 {
2481 if (!sfc->indirect_sfc)
2482 {
2483 evgl_engine->funcs->indirect_surface_create(evgl_engine, eng_data, sfc, sfc->cfg, sfc->w, sfc->h);
2484 sfc->egl_image = _egl_image_create(NULL, EVAS_GL_NATIVE_PIXMAP, sfc->indirect_sfc_native);
2485 }
2486 if (!ctx->indirect_context)
2487 {
2488 ctx->indirect_context =
2489 evgl_engine->funcs->gles_context_create(eng_data, ctx, sfc);
2490 }
2491 if (dbg) DBG("Calling make_current(%p, %p)", sfc->indirect_sfc, ctx->indirect_context);
2492 if (!evgl_engine->funcs->make_current(eng_data, sfc->indirect_sfc,
2493 ctx->indirect_context, EINA_TRUE))
2494 {
2495 ERR("Failed to make current with indirect surface.");
2496 return 0;
2497 }
2498
2499 // Transition from direct rendering to indirect rendering 2563 // Transition from direct rendering to indirect rendering
2500 if (rsc->direct.rendered) 2564 if (rsc->direct.rendered)
2501 { 2565 {
@@ -2519,16 +2583,21 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2519 } 2583 }
2520 else 2584 else
2521 { 2585 {
2522 // Normal FBO Rendering 2586 Eina_Bool use_extension = EINA_FALSE;
2523 // Create FBO if it hasn't been created 2587#ifdef GL_GLES
2524 if (!ctx->surface_fbo) 2588 if ((ctx->version == EVAS_GL_GLES_1_X) && (gles1_funcs))
2525 _framebuffer_create(&ctx->surface_fbo, ctx->version); 2589 use_extension = EINA_TRUE;
2590#endif
2526 2591
2527 // Direct Rendering 2592 // Direct Rendering
2528 if (_evgl_direct_renderable(rsc, sfc)) 2593 if (_evgl_direct_renderable(rsc, sfc))
2529 { 2594 {
2530 if (dbg) DBG("sfc %p is direct renderable.", sfc); 2595 if (dbg) DBG("sfc %p is direct renderable.", sfc);
2531 2596
2597 // Create FBO if it hasn't been created
2598 if (!ctx->surface_fbo)
2599 _framebuffer_create(&ctx->surface_fbo, use_extension);
2600
2532 if (ctx->version == EVAS_GL_GLES_3_X) 2601 if (ctx->version == EVAS_GL_GLES_3_X)
2533 { 2602 {
2534 // This is to transition from FBO rendering to direct rendering 2603 // This is to transition from FBO rendering to direct rendering
@@ -2616,10 +2685,6 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2616 ERR("Could not detach current FBO"); 2685 ERR("Could not detach current FBO");
2617 } 2686 }
2618 2687
2619 if (dbg) DBG("Calling make_current(%p, %p)", sfc->pbuffer.native_surface, ctx->context);
2620 evgl_engine->funcs->make_current(eng_data, sfc->pbuffer.native_surface,
2621 ctx->context, EINA_TRUE);
2622
2623 // Bind to the previously bound buffer (may be 0) 2688 // Bind to the previously bound buffer (may be 0)
2624 if (ctx->version == EVAS_GL_GLES_3_X) 2689 if (ctx->version == EVAS_GL_GLES_3_X)
2625 { 2690 {
@@ -2642,6 +2707,10 @@ evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *ctx)
2642 { 2707 {
2643 if (dbg) DBG("Surface sfc %p is a normal surface.", sfc); 2708 if (dbg) DBG("Surface sfc %p is a normal surface.", sfc);
2644 2709
2710 // Create FBO if it hasn't been created
2711 if (!ctx->surface_fbo)
2712 _framebuffer_create(&ctx->surface_fbo, use_extension);
2713
2645 // Attach fbo and the buffers 2714 // Attach fbo and the buffers
2646 if ((rsc->current_ctx != ctx) || (ctx->current_sfc != sfc) || (rsc->direct.rendered)) 2715 if ((rsc->current_ctx != ctx) || (ctx->current_sfc != sfc) || (rsc->direct.rendered))
2647 { 2716 {
@@ -2964,8 +3033,28 @@ evgl_get_pixels_post(void)
2964} 3033}
2965 3034
2966Evas_GL_API * 3035Evas_GL_API *
2967evgl_api_get(void *eng_data, Evas_GL_Context_Version version) 3036evgl_api_get(void *eng_data, Evas_GL_Context_Version version, Eina_Bool alloc_only)
2968{ 3037{
3038 Evas_GL_API *api = NULL;
3039
3040 if (version == EVAS_GL_GLES_2_X)
3041 {
3042 if (!gles2_funcs) gles2_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE);
3043 api = gles2_funcs;
3044 }
3045 else if (version == EVAS_GL_GLES_1_X)
3046 {
3047 if (!gles1_funcs) gles1_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE);
3048 api = gles1_funcs;
3049 }
3050 else if (version == EVAS_GL_GLES_3_X)
3051 {
3052 if (!gles3_funcs) gles3_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE);
3053 api = gles3_funcs;
3054 }
3055 else return NULL;
3056 if (alloc_only) return api;
3057
2969#ifdef GL_GLES 3058#ifdef GL_GLES
2970 if (!evgl_api_egl_ext_init(evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data))) 3059 if (!evgl_api_egl_ext_init(evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data)))
2971 { 3060 {
@@ -2974,32 +3063,21 @@ evgl_api_get(void *eng_data, Evas_GL_Context_Version version)
2974#endif 3063#endif
2975 if (version == EVAS_GL_GLES_2_X) 3064 if (version == EVAS_GL_GLES_2_X)
2976 { 3065 {
2977 if (!gles2_funcs) gles2_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE); 3066 _evgl_api_gles2_get(api, evgl_engine->api_debug_mode);
2978 3067 evgl_api_gles2_ext_get(api, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2979 _evgl_api_gles2_get(gles2_funcs, evgl_engine->api_debug_mode);
2980 evgl_api_gles2_ext_get(gles2_funcs, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2981
2982 return gles2_funcs;
2983 } 3068 }
2984 else if (version == EVAS_GL_GLES_1_X) 3069 else if (version == EVAS_GL_GLES_1_X)
2985 { 3070 {
2986 if (!gles1_funcs) gles1_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE); 3071 _evgl_api_gles1_get(api, evgl_engine->api_debug_mode);
2987 3072 evgl_api_gles1_ext_get(api, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2988 _evgl_api_gles1_get(gles1_funcs, evgl_engine->api_debug_mode);
2989 evgl_api_gles1_ext_get(gles1_funcs, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2990
2991 return gles1_funcs;
2992 } 3073 }
2993 else if (version == EVAS_GL_GLES_3_X) 3074 else if (version == EVAS_GL_GLES_3_X)
2994 { 3075 {
2995 if (!gles3_funcs) gles3_funcs = calloc(1, EVAS_GL_API_STRUCT_SIZE); 3076 _evgl_api_gles3_get(api, evgl_engine->api_debug_mode);
2996 3077 evgl_api_gles3_ext_get(api, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2997 _evgl_api_gles3_get(gles3_funcs, evgl_engine->api_debug_mode);
2998 evgl_api_gles3_ext_get(gles3_funcs, evgl_engine->funcs->proc_address_get, evgl_engine->funcs->ext_string_get(eng_data));
2999
3000 return gles3_funcs;
3001 } 3078 }
3002 else return NULL; 3079
3080 return api;
3003} 3081}
3004 3082
3005 3083
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 8939cdb..e1e6764 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_core.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_core.h
@@ -65,7 +65,7 @@ int evgl_make_current(void *eng_data, EVGL_Surface *sfc, EVGL_Context *
65 65
66const char *evgl_string_query(int name); 66const char *evgl_string_query(int name);
67int evgl_native_surface_get(EVGL_Surface *sfc, Evas_Native_Surface *ns); 67int evgl_native_surface_get(EVGL_Surface *sfc, Evas_Native_Surface *ns);
68Evas_GL_API *evgl_api_get(void *eng_data, Evas_GL_Context_Version version); 68Evas_GL_API *evgl_api_get(void *eng_data, Evas_GL_Context_Version version, Eina_Bool alloc_only);
69void evgl_safe_extension_add(const char *name, void *funcptr); 69void evgl_safe_extension_add(const char *name, void *funcptr);
70Eina_Bool evgl_safe_extension_get(const char *name, void **pfuncptr); 70Eina_Bool evgl_safe_extension_get(const char *name, void **pfuncptr);
71 71
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 41151d5..71deebe 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
@@ -259,7 +259,7 @@ struct _EVGL_Cap
259 259
260struct _EVGL_Resource 260struct _EVGL_Resource
261{ 261{
262 int id; 262 Eina_Thread id;
263 263
264 EVGLNative_Display display; 264 EVGLNative_Display display;
265 EVGLNative_Context context; 265 EVGLNative_Context context;
@@ -322,8 +322,7 @@ struct _EVGL_Engine
322 LK(resource_lock); 322 LK(resource_lock);
323 Eina_TLS resource_key; 323 Eina_TLS resource_key;
324 Eina_List *resource_list; 324 Eina_List *resource_list;
325 int resource_count; 325 Eina_Thread main_tid;
326 int main_tid;
327 326
328 // Add more debug logs (DBG levels 4 and 6) 327 // Add more debug logs (DBG levels 4 and 6)
329 int api_debug_mode; 328 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 eaca5e4..8895f9b 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 }
@@ -1538,14 +1539,13 @@ eng_gl_make_current(void *data, void *surface, void *context)
1538 Render_Engine_GL_Generic *re = data; 1539 Render_Engine_GL_Generic *re = data;
1539 EVGL_Surface *sfc = (EVGL_Surface *)surface; 1540 EVGL_Surface *sfc = (EVGL_Surface *)surface;
1540 EVGL_Context *ctx = (EVGL_Context *)context; 1541 EVGL_Context *ctx = (EVGL_Context *)context;
1542 int ret = 0;
1541 1543
1542 // TODO: Add check for main thread before flush 1544 // TODO: Add check for main thread before flush
1543 1545
1544 EVGLINIT(data, 0); 1546 if ((sfc) && (ctx))
1545 if (ctx)
1546 { 1547 {
1547 Evas_Engine_GL_Context *gl_context; 1548 Evas_Engine_GL_Context *gl_context;
1548 CONTEXT_STORE(data, surface, context);
1549 1549
1550 gl_context = re->window_gl_context_get(re->software.ob); 1550 gl_context = re->window_gl_context_get(re->software.ob);
1551 if ((gl_context->havestuff) || 1551 if ((gl_context->havestuff) ||
@@ -1558,7 +1558,10 @@ eng_gl_make_current(void *data, void *surface, void *context)
1558 } 1558 }
1559 } 1559 }
1560 1560
1561 return evgl_make_current(data, sfc, ctx); 1561 ret = evgl_make_current(data, sfc, ctx);
1562 CONTEXT_STORE(data, surface, context);
1563
1564 return ret;
1562} 1565}
1563 1566
1564static void * 1567static void *
@@ -1641,7 +1644,7 @@ eng_gl_api_get(void *data, int version)
1641 ERR("Version not supported!"); 1644 ERR("Version not supported!");
1642 return NULL; 1645 return NULL;
1643 } 1646 }
1644 ret = evgl_api_get(data, version); 1647 ret = evgl_api_get(data, version, EINA_TRUE);
1645 1648
1646 //Disable GLES3 support if symbols not present 1649 //Disable GLES3 support if symbols not present
1647 if ((!ret) && (version == EVAS_GL_GLES_3_X)) 1650 if ((!ret) && (version == EVAS_GL_GLES_3_X))