summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/evas_gl.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2014-09-01 18:11:53 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2014-10-20 12:16:06 +0900
commit8d6f873354ef67753777b671341438289a4e8876 (patch)
tree3efcd0e0d4c867816a1435a4bc5492c1dcb22be6 /src/lib/evas/canvas/evas_gl.c
parent08889de92b616ca8a8d198a1adb5b040e30abf53 (diff)
Evas GL: Add API evas_gl_error_get()
Similar in meaning to eglGetError() @feature
Diffstat (limited to 'src/lib/evas/canvas/evas_gl.c')
-rw-r--r--src/lib/evas/canvas/evas_gl.c142
1 files changed, 140 insertions, 2 deletions
diff --git a/src/lib/evas/canvas/evas_gl.c b/src/lib/evas/canvas/evas_gl.c
index 38a8468..46d4cd4 100644
--- a/src/lib/evas/canvas/evas_gl.c
+++ b/src/lib/evas/canvas/evas_gl.c
@@ -3,6 +3,8 @@
3#include "evas_private.h" 3#include "evas_private.h"
4#include "Evas_GL.h" 4#include "Evas_GL.h"
5 5
6typedef struct _Evas_GL_TLS_data Evas_GL_TLS_data;
7
6struct _Evas_GL 8struct _Evas_GL
7{ 9{
8 DATA32 magic; 10 DATA32 magic;
@@ -11,6 +13,8 @@ struct _Evas_GL
11 Eina_List *contexts; 13 Eina_List *contexts;
12 Eina_List *surfaces; 14 Eina_List *surfaces;
13 Eina_Lock lck; 15 Eina_Lock lck;
16 Eina_TLS resource_key;
17 Eina_List *resource_list;
14}; 18};
15 19
16struct _Evas_GL_Context 20struct _Evas_GL_Context
@@ -23,6 +27,95 @@ struct _Evas_GL_Surface
23 void *data; 27 void *data;
24}; 28};
25 29
30struct _Evas_GL_TLS_data
31{
32 int error_state;
33};
34
35Evas_GL_TLS_data *
36_evas_gl_internal_tls_get(Evas_GL *evas_gl)
37{
38 Evas_GL_TLS_data *tls_data;
39
40 if (!evas_gl) return NULL;
41
42 if (!(tls_data = eina_tls_get(evas_gl->resource_key)))
43 {
44 tls_data = (Evas_GL_TLS_data*) calloc(1, sizeof(Evas_GL_TLS_data));
45 if (!tls_data)
46 {
47 ERR("Evas_GL: Could not set error!");
48 return NULL;
49 }
50 tls_data->error_state = EVAS_GL_SUCCESS;
51
52 if (eina_tls_set(evas_gl->resource_key, (void*)tls_data) == EINA_TRUE)
53 {
54 LKL(evas_gl->lck);
55 evas_gl->resource_list = eina_list_prepend(evas_gl->resource_list, tls_data);
56 LKU(evas_gl->lck);
57 return tls_data;
58 }
59 else
60 {
61 ERR("Evas_GL: Failed setting TLS data!");
62 free(tls_data);
63 return NULL;
64 }
65 }
66
67 return tls_data;
68}
69
70void
71_evas_gl_internal_tls_destroy(Evas_GL *evas_gl)
72{
73 Evas_GL_TLS_data *tls_data;
74
75 if (!evas_gl) return;
76
77 if (!(tls_data = eina_tls_get(evas_gl->resource_key)))
78 {
79 WRN("Destructor: TLS data was never set!");
80 return;
81 }
82
83 LKL(evas_gl->lck);
84 EINA_LIST_FREE(evas_gl->resource_list, tls_data)
85 free(tls_data);
86
87 if (evas_gl->resource_key)
88 eina_tls_free(evas_gl->resource_key);
89 evas_gl->resource_key = 0;
90 LKU(evas_gl->lck);
91}
92
93void
94_evas_gl_internal_error_set(Evas_GL *evas_gl, int error_enum)
95{
96 Evas_GL_TLS_data *tls_data;
97
98 if (!evas_gl) return;
99
100 tls_data = _evas_gl_internal_tls_get(evas_gl);
101 if (!tls_data) return;
102
103 tls_data->error_state = error_enum;
104}
105
106int
107_evas_gl_internal_error_get(Evas_GL *evas_gl)
108{
109 Evas_GL_TLS_data *tls_data;
110
111 if (!evas_gl) return EVAS_GL_NOT_INITIALIZED;
112
113 tls_data = _evas_gl_internal_tls_get(evas_gl);
114 if (!tls_data) return EVAS_GL_NOT_INITIALIZED;
115
116 return tls_data->error_state;
117}
118
26EAPI Evas_GL * 119EAPI Evas_GL *
27evas_gl_new(Evas *e) 120evas_gl_new(Evas *e)
28{ 121{
@@ -46,6 +139,15 @@ evas_gl_new(Evas *e)
46 return NULL; 139 return NULL;
47 } 140 }
48 141
142 // Initialize tls resource key
143 if (eina_tls_new(&(evas_gl->resource_key)) == EINA_FALSE)
144 {
145 ERR("Error creating tls key");
146 free(evas_gl);
147 return NULL;
148 }
149
150 _evas_gl_internal_error_set(evas_gl, EVAS_GL_SUCCESS);
49 return evas_gl; 151 return evas_gl;
50} 152}
51 153
@@ -64,6 +166,9 @@ evas_gl_free(Evas_GL *evas_gl)
64 while (evas_gl->contexts) 166 while (evas_gl->contexts)
65 evas_gl_context_destroy(evas_gl, evas_gl->contexts->data); 167 evas_gl_context_destroy(evas_gl, evas_gl->contexts->data);
66 168
169 // Destroy tls
170 _evas_gl_internal_tls_destroy(evas_gl);
171
67 eo_data_unref(evas_gl->evas->evas, evas_gl->evas); 172 eo_data_unref(evas_gl->evas->evas, evas_gl->evas);
68 evas_gl->magic = 0; 173 evas_gl->magic = 0;
69 LKD(evas_gl->lck); 174 LKD(evas_gl->lck);
@@ -100,18 +205,24 @@ evas_gl_surface_create(Evas_GL *evas_gl, Evas_GL_Config *config, int width, int
100 if (!config) 205 if (!config)
101 { 206 {
102 ERR("Invalid Config Pointer!"); 207 ERR("Invalid Config Pointer!");
208 _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_CONFIG);
103 return NULL; 209 return NULL;
104 } 210 }
105 211
106 if ((width <= 0) || (height <= 0)) 212 if ((width <= 0) || (height <= 0))
107 { 213 {
108 ERR("Invalid surface dimensions: %d, %d", width, height); 214 ERR("Invalid surface dimensions: %d, %d", width, height);
215 _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_PARAMETER);
109 return NULL; 216 return NULL;
110 } 217 }
111 218
112 surf = calloc(1, sizeof(Evas_GL_Surface)); 219 surf = calloc(1, sizeof(Evas_GL_Surface));
113 220
114 if (!surf) return NULL; 221 if (!surf)
222 {
223 _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_ALLOC);
224 return NULL;
225 }
115 226
116 surf->data = evas_gl->evas->engine.func->gl_surface_create(evas_gl->evas->engine.data.output, config, width, height); 227 surf->data = evas_gl->evas->engine.func->gl_surface_create(evas_gl->evas->engine.data.output, config, width, height);
117 228
@@ -141,6 +252,7 @@ evas_gl_surface_destroy(Evas_GL *evas_gl, Evas_GL_Surface *surf)
141 if (!surf) 252 if (!surf)
142 { 253 {
143 ERR("Trying to destroy a NULL surface pointer!"); 254 ERR("Trying to destroy a NULL surface pointer!");
255 _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_SURFACE);
144 return; 256 return;
145 } 257 }
146 258
@@ -172,6 +284,7 @@ evas_gl_context_create(Evas_GL *evas_gl, Evas_GL_Context *share_ctx)
172 if (!ctx) 284 if (!ctx)
173 { 285 {
174 ERR("Unable to create a Evas_GL_Context object"); 286 ERR("Unable to create a Evas_GL_Context object");
287 _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_ALLOC);
175 return NULL; 288 return NULL;
176 } 289 }
177 290
@@ -199,7 +312,6 @@ evas_gl_context_create(Evas_GL *evas_gl, Evas_GL_Context *share_ctx)
199 LKU(evas_gl->lck); 312 LKU(evas_gl->lck);
200 313
201 return ctx; 314 return ctx;
202
203} 315}
204 316
205EAPI void 317EAPI void
@@ -213,6 +325,7 @@ evas_gl_context_destroy(Evas_GL *evas_gl, Evas_GL_Context *ctx)
213 if (!ctx) 325 if (!ctx)
214 { 326 {
215 ERR("Trying to destroy a NULL context pointer!"); 327 ERR("Trying to destroy a NULL context pointer!");
328 _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_CONTEXT);
216 return; 329 return;
217 } 330 }
218 331
@@ -245,6 +358,7 @@ evas_gl_make_current(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_GL_Context *c
245 else 358 else
246 { 359 {
247 ERR("Bad match between surface: %p and context: %p", surf, ctx); 360 ERR("Bad match between surface: %p and context: %p", surf, ctx);
361 _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_MATCH);
248 return EINA_FALSE; 362 return EINA_FALSE;
249 } 363 }
250 364
@@ -281,12 +395,14 @@ evas_gl_native_surface_get(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_Native_
281 if (!surf) 395 if (!surf)
282 { 396 {
283 ERR("Invalid surface!"); 397 ERR("Invalid surface!");
398 _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_SURFACE);
284 return EINA_FALSE; 399 return EINA_FALSE;
285 } 400 }
286 401
287 if (!ns) 402 if (!ns)
288 { 403 {
289 ERR("Invalid input parameters!"); 404 ERR("Invalid input parameters!");
405 _evas_gl_internal_error_set(evas_gl, EVAS_GL_BAD_PARAMETER);
290 return EINA_FALSE; 406 return EINA_FALSE;
291 } 407 }
292 408
@@ -303,3 +419,25 @@ evas_gl_api_get(Evas_GL *evas_gl)
303 419
304 return (Evas_GL_API*)evas_gl->evas->engine.func->gl_api_get(evas_gl->evas->engine.data.output); 420 return (Evas_GL_API*)evas_gl->evas->engine.func->gl_api_get(evas_gl->evas->engine.data.output);
305} 421}
422
423EAPI int
424evas_gl_error_get(Evas_GL *evas_gl)
425{
426 int err;
427
428 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
429 return EVAS_GL_NOT_INITIALIZED;
430 MAGIC_CHECK_END();
431
432 if ((err = _evas_gl_internal_error_get(evas_gl)) != EVAS_GL_SUCCESS) goto end;
433
434 if (!evas_gl->evas->engine.func->gl_error_get)
435 err = EVAS_GL_NOT_INITIALIZED;
436 else
437 err = evas_gl->evas->engine.func->gl_error_get(evas_gl->evas->engine.data.output);
438
439end:
440 /* Call to evas_gl_error_get() should set error to EVAS_GL_SUCCESS */
441 _evas_gl_internal_error_set(evas_gl, EVAS_GL_SUCCESS);
442 return err;
443}