jpeg pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=cb5e88d20ff258fb18e7fe1465ca7eddf4e9e2e3

commit cb5e88d20ff258fb18e7fe1465ca7eddf4e9e2e3
Author: Jean-Philippe Andre <[email protected]>
Date:   Mon Sep 1 20:15:33 2014 +0900

    Evas GL: Add APIs to get current surface/context
    
    - evas_gl_current_surface_get
    - evas_gl_current_context_get
    
    @feature
---
 src/lib/evas/Evas_GL.h                             | 30 +++++++++++
 src/lib/evas/canvas/evas_gl.c                      | 62 ++++++++++++++++++++++
 src/lib/evas/include/evas_private.h                |  2 +
 src/modules/evas/engines/gl_generic/evas_engine.c  | 21 ++++++++
 src/modules/evas/engines/gl_x11/evas_engine.c      | 22 ++++++++
 .../evas/engines/software_generic/evas_engine.c    |  2 +
 6 files changed, 139 insertions(+)

diff --git a/src/lib/evas/Evas_GL.h b/src/lib/evas/Evas_GL.h
index 3a46de8..2a51825 100644
--- a/src/lib/evas/Evas_GL.h
+++ b/src/lib/evas/Evas_GL.h
@@ -596,6 +596,36 @@ EAPI Evas_GL_API             *evas_gl_api_get            
(Evas_GL *evas_gl) EINA
  */
 EAPI int                      evas_gl_error_get          (Evas_GL *evas_gl) 
EINA_ARG_NONNULL(1);
 
+/**
+ * @brief Returns the Evas GL context object in use or set by @ref 
evas_gl_make_current.
+ *
+ * @param[in] evas_gl The given Evas_GL object
+ *
+ * @return The current context for the calling thread, or @c NULL in case of
+ *         failure and when there is no current context in this thread.
+ *
+ * @since 1.12
+ */
+EAPI Evas_GL_Context         *evas_gl_current_context_get (Evas_GL *evas_gl) 
EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
+
+/**
+ * @brief Returns the Evas GL surface object in use or set by @ref 
evas_gl_make_current
+ *
+ * @param evas_gl The given Evas_GL object
+ *
+ * @return The current surface for the calling thread, or @c NULL in case of
+ *         failure and when there is no current surface in this thread.
+ *
+ * This can be used to get a handle to the current surface, so as to switch
+ * between contexts back and forth. Note that the OpenGL driver may stall when
+ * doing so.
+ *
+ * @see evas_gl_make_current
+ *
+ * @since 1.12
+ */
+EAPI Evas_GL_Surface         *evas_gl_current_surface_get (Evas_GL *evas_gl) 
EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
+
 #if !defined(__gl_h_) && !defined(__gl2_h_)
 # define __gl_h_
 # define __gl2_h_
diff --git a/src/lib/evas/canvas/evas_gl.c b/src/lib/evas/canvas/evas_gl.c
index 46d4cd4..4a75896 100644
--- a/src/lib/evas/canvas/evas_gl.c
+++ b/src/lib/evas/canvas/evas_gl.c
@@ -365,6 +365,68 @@ evas_gl_make_current(Evas_GL *evas_gl, Evas_GL_Surface 
*surf, Evas_GL_Context *c
    return ret;
 }
 
+EAPI Evas_GL_Context *
+evas_gl_current_context_get(Evas_GL *evas_gl)
+{
+   Evas_GL_Context *comp;
+   void *internal_ctx;
+   Eina_List *li;
+
+   // Magic
+   MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
+   return NULL;
+   MAGIC_CHECK_END();
+
+   internal_ctx = 
evas_gl->evas->engine.func->gl_current_context_get(evas_gl->evas->engine.data.output);
+   if (!internal_ctx)
+     return NULL;
+
+   LKL(evas_gl->lck);
+   EINA_LIST_FOREACH(evas_gl->contexts, li, comp)
+     {
+        if (comp->data == internal_ctx)
+          {
+             LKU(evas_gl->lck);
+             return comp;
+          }
+     }
+
+   ERR("The currently bound context could not be found.");
+   LKU(evas_gl->lck);
+   return NULL;
+}
+
+EAPI Evas_GL_Surface *
+evas_gl_current_surface_get(Evas_GL *evas_gl)
+{
+   Evas_GL_Surface *comp;
+   void *internal_sfc;
+   Eina_List *li;
+
+   // Magic
+   MAGIC_CHECK(evas_gl, Evas_GL, MAGIC_EVAS_GL);
+   return NULL;
+   MAGIC_CHECK_END();
+
+   internal_sfc = 
evas_gl->evas->engine.func->gl_current_surface_get(evas_gl->evas->engine.data.output);
+   if (!internal_sfc)
+     return NULL;
+
+   LKL(evas_gl->lck);
+   EINA_LIST_FOREACH(evas_gl->surfaces, li, comp)
+     {
+        if (comp->data == internal_sfc)
+          {
+             LKU(evas_gl->lck);
+             return comp;
+          }
+     }
+
+   ERR("The currently bound surface could not be found.");
+   LKU(evas_gl->lck);
+   return NULL;
+}
+
 EAPI const char *
 evas_gl_string_query(Evas_GL *evas_gl, int name)
 {
diff --git a/src/lib/evas/include/evas_private.h 
b/src/lib/evas/include/evas_private.h
index 3e66c73..c23b1d4 100644
--- a/src/lib/evas/include/evas_private.h
+++ b/src/lib/evas/include/evas_private.h
@@ -1245,6 +1245,8 @@ struct _Evas_Func
    Eina_Bool (*gl_surface_read_pixels)   (void *data, void *surface, int x, 
int y, int w, int h, Evas_Colorspace cspace, void *pixels);
    Eina_Bool (*gl_surface_unlock)        (void *data, void *surface);
    int  (*gl_error_get)                  (void *data);
+   void *(*gl_current_context_get)       (void *data);
+   void *(*gl_current_surface_get)       (void *data);
 
    int  (*image_load_error_get)          (void *data, void *image);
    int  (*font_run_end_get)              (void *data, Evas_Font_Set *font, 
Evas_Font_Instance **script_fi, Evas_Font_Instance **cur_fi, Evas_Script_Type 
script, const Eina_Unicode *text, int run_len);
diff --git a/src/modules/evas/engines/gl_generic/evas_engine.c 
b/src/modules/evas/engines/gl_generic/evas_engine.c
index d1c2577..c31dee3 100644
--- a/src/modules/evas/engines/gl_generic/evas_engine.c
+++ b/src/modules/evas/engines/gl_generic/evas_engine.c
@@ -1147,6 +1147,8 @@ eng_gl_make_current(void *data, void *surface, void 
*context)
    EVGL_Surface  *sfc = (EVGL_Surface *)surface;
    EVGL_Context  *ctx = (EVGL_Context *)context;
 
+   // TODO: Add check for main thread before flush
+
    EVGLINIT(data, 0);
    if ((sfc) && (ctx))
      {
@@ -1167,6 +1169,20 @@ eng_gl_make_current(void *data, void *surface, void 
*context)
 }
 
 static void *
+eng_gl_current_surface_get(void *data EINA_UNUSED)
+{
+   EVGL_Context *ctx;
+
+   ctx = _evgl_current_context_get();
+   if (!ctx)
+     return NULL;
+
+   // Note: We could verify with a call to eglGetCurrentSurface
+
+   return ctx->current_sfc;
+}
+
+static void *
 eng_gl_string_query(void *data, int name)
 {
    EVGLINIT(data, NULL);
@@ -1782,6 +1798,11 @@ module_open(Evas_Module *em)
    ORD(gl_surface_lock);
    ORD(gl_surface_read_pixels);
    ORD(gl_surface_unlock);
+   //ORD(gl_error_get);
+   //ORD(gl_surface_query);
+   // gl_current_context_get is in engine
+   ORD(gl_current_surface_get);
+   //ORD(gl_rotation_angle_get);
 
    ORD(image_load_error_get);
 
diff --git a/src/modules/evas/engines/gl_x11/evas_engine.c 
b/src/modules/evas/engines/gl_x11/evas_engine.c
index 3475532..fa731f7 100644
--- a/src/modules/evas/engines/gl_x11/evas_engine.c
+++ b/src/modules/evas/engines/gl_x11/evas_engine.c
@@ -1264,6 +1264,28 @@ eng_output_dump(void *data)
    _re_winfree(re);
 }
 
+static void *
+eng_gl_current_context_get(void *data EINA_UNUSED)
+{
+   EVGL_Context *ctx;
+
+   ctx = _evgl_current_context_get();
+   if (!ctx)
+     return NULL;
+
+#ifdef GL_GLES
+   if (eglGetCurrentContext() == (ctx->context))
+     return ctx;
+   else
+     return NULL;
+#else
+   if (glXGetCurrentContext() == (ctx->context))
+     return ctx;
+   else
+     return NULL;
+#endif
+}
+
 static int
 eng_gl_error_get(void *data EINA_UNUSED)
 {
diff --git a/src/modules/evas/engines/software_generic/evas_engine.c 
b/src/modules/evas/engines/software_generic/evas_engine.c
index d65aae3..9319306 100644
--- a/src/modules/evas/engines/software_generic/evas_engine.c
+++ b/src/modules/evas/engines/software_generic/evas_engine.c
@@ -3003,6 +3003,8 @@ static Evas_Func func =
      NULL, // need software mesa for gl rendering <- gl_surface_read_pixels
      NULL, // need software mesa for gl rendering <- gl_surface_unlock
      NULL, // need software mesa for gl rendering <- gl_error_get
+     NULL, // need software mesa for gl rendering <- gl_current_context_get
+     NULL, // need software mesa for gl rendering <- gl_current_surface_get
      eng_image_load_error_get,
      eng_font_run_font_end_get,
      eng_image_animated_get,

-- 


Reply via email to