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"
15 struct _Evas_GL_Context
20 struct _Evas_GL_Surface
30 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
34 evas_gl = calloc(1, sizeof(Evas_GL));
35 if (!evas_gl) return NULL;
37 evas_gl->magic = MAGIC_EVAS_GL;
40 if (!evas_gl->evas->engine.func->gl_context_create)
42 ERR("Evas GL engine not available.");
51 evas_gl_free(Evas_GL *evas_gl)
53 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
58 // Delete undeleted surfaces
59 while (evas_gl->surfaces)
60 evas_gl_surface_destroy(evas_gl, evas_gl->surfaces->data);
62 // Delete undeleted contexts
63 while (evas_gl->contexts)
64 evas_gl_context_destroy(evas_gl, evas_gl->contexts->data);
75 cfg = calloc(1, sizeof(Evas_GL_Config));
77 if (!cfg) return NULL;
83 evas_gl_config_free(Evas_GL_Config *cfg)
88 EAPI Evas_GL_Surface *
89 evas_gl_surface_create(Evas_GL *evas_gl, Evas_GL_Config *config, int width, int height)
91 Evas_GL_Surface *surf;
93 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
99 ERR("Invalid Config Pointer!");
103 if ( (width <= 0) || (height <= 0))
105 ERR("Invalid surface dimensions: %d, %d", width, height);
109 surf = calloc(1, sizeof(Evas_GL_Surface));
111 if (!surf) return NULL;
113 surf->data = evas_gl->evas->engine.func->gl_surface_create(evas_gl->evas->engine.data.output, config, width, height);
117 ERR("Failed creating a surface from the engine.");
122 // Keep track of the surface creations
123 evas_gl->surfaces = eina_list_prepend(evas_gl->surfaces, surf);
129 evas_gl_surface_destroy(Evas_GL *evas_gl, Evas_GL_Surface *surf)
132 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
138 ERR("Trying to destroy a NULL surface pointer!");
142 // Call Engine's Surface Destroy
143 evas_gl->evas->engine.func->gl_surface_destroy(evas_gl->evas->engine.data.output, surf->data);
145 // Remove it from the list
146 evas_gl->surfaces = eina_list_remove(evas_gl->surfaces, surf);
153 EAPI Evas_GL_Context *
154 evas_gl_context_create(Evas_GL *evas_gl, Evas_GL_Context *share_ctx)
156 Evas_GL_Context *ctx;
159 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
163 // Allocate a context object
164 ctx = calloc(1, sizeof(Evas_GL_Context));
167 ERR("Unable to create a Evas_GL_Context object");
171 // Call engine->gl_create_context
174 ctx->data = evas_gl->evas->engine.func->gl_context_create(evas_gl->evas->engine.data.output, share_ctx->data);
178 ctx->data = evas_gl->evas->engine.func->gl_context_create(evas_gl->evas->engine.data.output, NULL);
181 // Set a few variables
184 ERR("Failed creating a context from the engine.");
189 // Keep track of the context creations
190 evas_gl->contexts = eina_list_prepend(evas_gl->contexts, ctx);
197 evas_gl_context_destroy(Evas_GL *evas_gl, Evas_GL_Context *ctx)
200 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
206 ERR("Trying to destroy a NULL context pointer!");
210 // Call Engine's destroy
211 evas_gl->evas->engine.func->gl_context_destroy(evas_gl->evas->engine.data.output, ctx->data);
213 // Remove it from the list
214 evas_gl->contexts = eina_list_remove(evas_gl->contexts, ctx);
222 evas_gl_make_current(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_GL_Context *ctx)
226 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
231 ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, surf->data, ctx->data);
232 else if ((!surf) && (!ctx))
233 ret = (Eina_Bool)evas_gl->evas->engine.func->gl_make_current(evas_gl->evas->engine.data.output, NULL, NULL);
236 ERR("Bad match between surface: %p and context: %p", surf, ctx);
244 evas_gl_string_query(Evas_GL *evas_gl, int name)
246 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
250 return (const char *)evas_gl->evas->engine.func->gl_string_query(evas_gl->evas->engine.data.output, name);
254 evas_gl_proc_address_get(Evas_GL *evas_gl, const char *name)
256 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
260 return (Evas_GL_Func)evas_gl->evas->engine.func->gl_proc_address_get(evas_gl->evas->engine.data.output, name);
264 evas_gl_native_surface_get(Evas_GL *evas_gl, Evas_GL_Surface *surf, Evas_Native_Surface *ns)
266 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
270 if ((!surf) || (!ns))
272 ERR("Invalid input parameters!");
276 return (Eina_Bool)evas_gl->evas->engine.func->gl_native_surface_get(evas_gl->evas->engine.data.output, surf->data, ns);
281 evas_gl_api_get(Evas_GL *evas_gl)
283 MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
287 return (Evas_GL_API*)evas_gl->evas->engine.func->gl_api_get(evas_gl->evas->engine.data.output);