bccab2dd8d16462ea3309feddb9509e6ef90759e
[profile/ivi/evas.git] / src / lib / canvas / evas_gl.c
1 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/
2 #include "evas_common.h"
3 #include "evas_private.h"
4 #include "Evas_GL.h"
5
6 struct _Evas_GL
7 {
8    DATA32      magic;
9    Evas       *evas;
10
11    Eina_List  *contexts;
12    Eina_List  *surfaces;
13 };
14
15 struct _Evas_GL_Context
16 {
17    void    *data;
18 };
19
20 struct _Evas_GL_Surface
21 {
22    void    *data;
23 };
24
25 EAPI Evas_GL *
26 evas_gl_new(Evas *e)
27 {
28    Evas_GL *evas_gl;
29
30    MAGIC_CHECK(e, Evas, MAGIC_EVAS);
31    return NULL;
32    MAGIC_CHECK_END();
33
34    evas_gl = calloc(1, sizeof(Evas_GL));
35    if (!evas_gl) return NULL;
36
37    evas_gl->magic = MAGIC_EVAS_GL;
38    evas_gl->evas = e;
39
40    if (!evas_gl->evas->engine.func->gl_context_create)
41      {
42         ERR("Evas GL engine not available.");
43         free(evas_gl);
44         return NULL;
45      }
46
47    return evas_gl;
48 }
49
50 EAPI void
51 evas_gl_free(Evas_GL *evas_gl)
52 {
53    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
54    return;
55    MAGIC_CHECK_END();
56
57
58    // Delete undeleted surfaces
59    while (evas_gl->surfaces)
60      evas_gl_surface_destroy(evas_gl, evas_gl->surfaces->data);
61
62    // Delete undeleted contexts
63    while (evas_gl->contexts)
64      evas_gl_context_destroy(evas_gl, evas_gl->contexts->data);
65
66    evas_gl->magic = 0;
67    free(evas_gl);
68 }
69
70 EAPI Evas_GL_Config *
71 evas_gl_config_new()
72 {
73    Evas_GL_Config *cfg;
74
75    cfg = calloc(1, sizeof(Evas_GL_Config));
76
77    if (!cfg) return NULL;
78
79    return cfg;
80 }
81
82 EAPI void
83 evas_gl_config_free(Evas_GL_Config *cfg)
84 {
85    if (cfg) free(cfg);
86 }
87
88 EAPI Evas_GL_Surface *
89 evas_gl_surface_create(Evas_GL *evas_gl, Evas_GL_Config *config, int width, int height)
90 {
91    Evas_GL_Surface *surf;
92
93    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
94    return NULL;
95    MAGIC_CHECK_END();
96
97    if (!config)
98      {
99         ERR("Invalid Config Pointer!");
100         return NULL;
101      }
102
103    surf = calloc(1, sizeof(Evas_GL_Surface));
104
105    if (!surf) return NULL;
106
107    surf->data = evas_gl->evas->engine.func->gl_surface_create(evas_gl->evas->engine.data.output, config, width, height);
108
109    if (!surf->data)
110      {
111         ERR("Failed creating a surface from the engine.");
112         free(surf);
113         return NULL;
114      }
115
116    // Keep track of the surface creations
117    evas_gl->surfaces = eina_list_prepend(evas_gl->surfaces, surf);
118
119    return surf;
120 }
121
122 EAPI void
123 evas_gl_surface_destroy(Evas_GL *evas_gl, Evas_GL_Surface *surf)
124 {
125    // Magic
126    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
127    return;
128    MAGIC_CHECK_END();
129
130    if (!surf)
131      {
132         ERR("Trying to destroy a NULL surface pointer!");
133         return;
134      }
135
136    // Call Engine's Surface Destroy
137    evas_gl->evas->engine.func->gl_surface_destroy(evas_gl->evas->engine.data.output, surf->data);
138
139    // Remove it from the list
140    evas_gl->surfaces = eina_list_remove(evas_gl->surfaces, surf);
141
142    // Delete the object
143    free(surf);
144    surf = NULL;
145 }
146
147 EAPI Evas_GL_Context *
148 evas_gl_context_create(Evas_GL *evas_gl, Evas_GL_Context *share_ctx)
149 {
150    Evas_GL_Context *ctx;
151
152    // Magic
153    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
154    return NULL;
155    MAGIC_CHECK_END();
156
157    // Allocate a context object
158    ctx = calloc(1, sizeof(Evas_GL_Context));
159    if (!ctx)
160      {
161         ERR("Unable to create a Evas_GL_Context object");
162         return NULL;
163      }
164
165    // Call engine->gl_create_context
166    if (share_ctx)
167      {
168         ctx->data = evas_gl->evas->engine.func->gl_context_create(evas_gl->evas->engine.data.output, share_ctx->data);
169      }
170    else
171      {
172         ctx->data = evas_gl->evas->engine.func->gl_context_create(evas_gl->evas->engine.data.output, NULL);
173      }
174
175    // Set a few variables
176    if (!ctx->data)
177      {
178         ERR("Failed creating a context from the engine.");
179         free(ctx);
180         return NULL;
181      }
182
183    // Keep track of the context creations
184    evas_gl->contexts = eina_list_prepend(evas_gl->contexts, ctx);
185
186    return ctx;
187
188 }
189
190 EAPI void
191 evas_gl_context_destroy(Evas_GL *evas_gl, Evas_GL_Context *ctx)
192 {
193
194    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
195    return;
196    MAGIC_CHECK_END();
197
198    if (!ctx)
199      {
200         ERR("Trying to destroy a NULL context pointer!");
201         return;
202      }
203
204    // Call Engine's destroy
205    evas_gl->evas->engine.func->gl_context_destroy(evas_gl->evas->engine.data.output, ctx->data);
206
207    // Remove it from the list
208    evas_gl->contexts = eina_list_remove(evas_gl->contexts, ctx);
209
210    // Delete the object
211    free(ctx);
212    ctx = NULL;
213 }
214
215 EAPI Eina_Bool
216 evas_gl_make_current(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_GL_Context *ctx)
217 {
218    Eina_Bool ret;
219
220    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
221    return EINA_FALSE;
222    MAGIC_CHECK_END();
223
224    if ((!surf) || (!ctx))
225      ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, NULL, NULL);
226    else
227      ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, surf->data, ctx->data);
228
229    return ret;
230 }
231
232 EAPI const char *
233 evas_gl_string_query(Evas_GL *evas_gl, int name)
234 {
235    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
236    return EINA_FALSE;
237    MAGIC_CHECK_END();
238
239    return (const char *)evas_gl->evas->engine.func->gl_string_query(evas_gl->evas->engine.data.output, name);
240 }
241
242 EAPI Evas_GL_Func
243 evas_gl_proc_address_get(Evas_GL *evas_gl, const char *name)
244 {
245    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
246    return EINA_FALSE;
247    MAGIC_CHECK_END();
248
249    return (Evas_GL_Func)evas_gl->evas->engine.func->gl_proc_address_get(evas_gl->evas->engine.data.output, name);
250 }
251
252 EAPI Eina_Bool
253 evas_gl_native_surface_get(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_Native_Surface *ns)
254 {
255    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
256    return EINA_FALSE;
257    MAGIC_CHECK_END();
258
259    if ((!surf) || (!ns))
260      {
261         ERR("Invalid input parameters!");
262         return EINA_FALSE;
263      }
264
265    return (Eina_Bool)evas_gl->evas->engine.func->gl_native_surface_get(evas_gl->evas->engine.data.output, surf->data, ns);
266 }
267
268
269 EAPI Evas_GL_API *
270 evas_gl_api_get(Evas_GL *evas_gl)
271 {
272    MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
273    return NULL;
274    MAGIC_CHECK_END();
275
276    return (Evas_GL_API*)evas_gl->evas->engine.func->gl_api_get(evas_gl->evas->engine.data.output);
277
278 }