summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2015-10-02 15:15:40 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2015-10-02 16:56:38 +0900
commit90b96b07d9d39bb98f7d362fbfdd386deceefa84 (patch)
tree3367942dc917999b55a7c7e493bcc40f2e0e7795 /src/lib/evas/canvas
parent2317bb83fc830e302d23047dc7ab06e61333a4dc (diff)
Evas GL: Add new API to get current Evas GL
While this seems to go against the rest of the API (because we always pass in the Evas GL object), there is no way right now fully restore a context if there are multiple Evas GL objects. For instance, an app can use Evas GL from an Elm GLView, and also use Cairo with another Evas GL at the same time. In that case Cairo needs to restore the previous Evas GL but the library had no way of getting the current Evas GL. This is the equivalent of eglGetCurrentDisplay(). @feature
Diffstat (limited to 'src/lib/evas/canvas')
-rw-r--r--src/lib/evas/canvas/evas_gl.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/lib/evas/canvas/evas_gl.c b/src/lib/evas/canvas/evas_gl.c
index 5b539e4008..7e9c4e7db9 100644
--- a/src/lib/evas/canvas/evas_gl.c
+++ b/src/lib/evas/canvas/evas_gl.c
@@ -5,6 +5,9 @@
5 5
6typedef struct _Evas_GL_TLS_data Evas_GL_TLS_data; 6typedef struct _Evas_GL_TLS_data Evas_GL_TLS_data;
7 7
8/* since 1.16: store current evas gl - this TLS is never destroyed */
9static Eina_TLS _current_evas_gl_key = 0;
10
8struct _Evas_GL 11struct _Evas_GL
9{ 12{
10 DATA32 magic; 13 DATA32 magic;
@@ -126,6 +129,16 @@ evas_gl_new(Evas *e)
126 return NULL; 129 return NULL;
127 MAGIC_CHECK_END(); 130 MAGIC_CHECK_END();
128 131
132 if (!_current_evas_gl_key)
133 {
134 if (!eina_tls_new(&_current_evas_gl_key))
135 {
136 ERR("Error creating tls key for current Evas GL");
137 return NULL;
138 }
139 eina_tls_set(_current_evas_gl_key, NULL);
140 }
141
129 evas_gl = calloc(1, sizeof(Evas_GL)); 142 evas_gl = calloc(1, sizeof(Evas_GL));
130 if (!evas_gl) return NULL; 143 if (!evas_gl) return NULL;
131 144
@@ -136,6 +149,7 @@ evas_gl_new(Evas *e)
136 if (!evas_gl->evas->engine.func->gl_context_create) 149 if (!evas_gl->evas->engine.func->gl_context_create)
137 { 150 {
138 ERR("Evas GL engine not available."); 151 ERR("Evas GL engine not available.");
152 eo_data_unref(e, evas_gl->evas);
139 free(evas_gl); 153 free(evas_gl);
140 return NULL; 154 return NULL;
141 } 155 }
@@ -144,6 +158,7 @@ evas_gl_new(Evas *e)
144 if (eina_tls_new(&(evas_gl->resource_key)) == EINA_FALSE) 158 if (eina_tls_new(&(evas_gl->resource_key)) == EINA_FALSE)
145 { 159 {
146 ERR("Error creating tls key"); 160 ERR("Error creating tls key");
161 eo_data_unref(e, evas_gl->evas);
147 free(evas_gl); 162 free(evas_gl);
148 return NULL; 163 return NULL;
149 } 164 }
@@ -167,9 +182,13 @@ evas_gl_free(Evas_GL *evas_gl)
167 while (evas_gl->contexts) 182 while (evas_gl->contexts)
168 evas_gl_context_destroy(evas_gl, evas_gl->contexts->data); 183 evas_gl_context_destroy(evas_gl, evas_gl->contexts->data);
169 184
170 // Destroy tls 185 // Destroy private tls
171 _evas_gl_internal_tls_destroy(evas_gl); 186 _evas_gl_internal_tls_destroy(evas_gl);
172 187
188 // Reset current evas gl tls
189 if (_current_evas_gl_key && (evas_gl == eina_tls_get(_current_evas_gl_key)))
190 eina_tls_set(_current_evas_gl_key, NULL);
191
173 eo_data_unref(evas_gl->evas->evas, evas_gl->evas); 192 eo_data_unref(evas_gl->evas->evas, evas_gl->evas);
174 evas_gl->magic = 0; 193 evas_gl->magic = 0;
175 LKD(evas_gl->lck); 194 LKD(evas_gl->lck);
@@ -452,6 +471,9 @@ evas_gl_make_current(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_GL_Context *c
452 return EINA_FALSE; 471 return EINA_FALSE;
453 } 472 }
454 473
474 if (_current_evas_gl_key)
475 eina_tls_set(_current_evas_gl_key, evas_gl);
476
455 return ret; 477 return ret;
456} 478}
457 479
@@ -531,6 +553,26 @@ evas_gl_current_surface_get(Evas_GL *evas_gl)
531 return NULL; 553 return NULL;
532} 554}
533 555
556EAPI Evas_GL *
557evas_gl_current_evas_gl_get(Evas_GL_Context **context, Evas_GL_Surface **surface)
558{
559 Evas_GL *evasgl = NULL;
560
561 if (_current_evas_gl_key)
562 evasgl = eina_tls_get(_current_evas_gl_key);
563
564 if (!evasgl)
565 {
566 if (context) *context = NULL;
567 if (surface) *surface = NULL;
568 return NULL;
569 }
570
571 if (context) *context = evas_gl_current_context_get(evasgl);
572 if (surface) *surface = evas_gl_current_surface_get(evasgl);
573 return evasgl;
574}
575
534EAPI const char * 576EAPI const char *
535evas_gl_string_query(Evas_GL *evas_gl, int name) 577evas_gl_string_query(Evas_GL *evas_gl, int name)
536{ 578{