Mesa (master): st/mesa: Add support for multiple APIs.

Chia-I Wu olv at kemper.freedesktop.org
Tue Jun 29 09:17:25 UTC 2010


Module: Mesa
Branch: master
Commit: 57c654324f5577d30c5239cd0c2c3eb7ad474143
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=57c654324f5577d30c5239cd0c2c3eb7ad474143

Author: Chia-I Wu <olv at lunarg.com>
Date:   Wed Jun 23 17:40:49 2010 +0800

st/mesa: Add support for multiple APIs.

Add st_gl_api_create_es1 and st_gl_api_create_es2 to create OpeGL ES 1.1
and OpenGL ES 2.0 contexts respectively.

---

 src/mesa/state_tracker/st_context.c |   13 +----
 src/mesa/state_tracker/st_context.h |    3 +-
 src/mesa/state_tracker/st_gl_api.h  |    4 +-
 src/mesa/state_tracker/st_manager.c |   95 +++++++++++++++++++++++++++-------
 src/mesa/state_tracker/st_manager.h |    3 -
 5 files changed, 82 insertions(+), 36 deletions(-)

diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 4b809b6..7eb5f32 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -153,7 +153,7 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe )
 }
 
 
-struct st_context *st_create_context(struct pipe_context *pipe,
+struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
                                      const __GLcontextModes *visual,
                                      struct st_context *share)
 {
@@ -164,16 +164,7 @@ struct st_context *st_create_context(struct pipe_context *pipe,
    memset(&funcs, 0, sizeof(funcs));
    st_init_driver_functions(&funcs);
 
-#if FEATURE_GL
-   ctx = _mesa_create_context_for_api(API_OPENGL,
-				      visual, shareCtx, &funcs, NULL);
-#elif FEATURE_ES1
-   ctx = _mesa_create_context_for_api(API_OPENGLES,
-				      visual, shareCtx, &funcs, NULL);
-#elif FEATURE_ES2
-   ctx = _mesa_create_context_for_api(API_OPENGLES2,
-				      visual, shareCtx, &funcs, NULL);
-#endif
+   ctx = _mesa_create_context_for_api(api, visual, shareCtx, &funcs, NULL);
 
    /* XXX: need a capability bit in gallium to query if the pipe
     * driver prefers DP4 or MUL/MAD for vertex transformation.
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 7f7088e..a147a02 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -261,7 +261,8 @@ extern int
 st_get_msaa(void);
 
 extern struct st_context *
-st_create_context(struct pipe_context *pipe, const __GLcontextModes *visual,
+st_create_context(gl_api api, struct pipe_context *pipe,
+                  const __GLcontextModes *visual,
                   struct st_context *share);
 
 extern void
diff --git a/src/mesa/state_tracker/st_gl_api.h b/src/mesa/state_tracker/st_gl_api.h
index 52c3fa0..fe1aec2 100644
--- a/src/mesa/state_tracker/st_gl_api.h
+++ b/src/mesa/state_tracker/st_gl_api.h
@@ -4,6 +4,8 @@
 
 #include "state_tracker/st_api.h"
 
-struct st_api * st_gl_api_create(void);
+struct st_api *st_gl_api_create(void);
+struct st_api *st_gl_api_create_es1(void);
+struct st_api *st_gl_api_create_es2(void);
 
 #endif
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index f1d98db..2afc682 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -48,17 +48,9 @@
 #include "st_context.h"
 #include "st_format.h"
 #include "st_cb_fbo.h"
+#include "st_cb_flush.h"
 #include "st_manager.h"
 
-/* these functions are defined in st_context.c */
-struct st_context *
-st_create_context(struct pipe_context *pipe,
-                  const __GLcontextModes *visual,
-                  struct st_context *share);
-void st_destroy_context(struct st_context *st);
-void st_flush(struct st_context *st, uint pipeFlushFlags,
-              struct pipe_fence_handle **fence);
-
 /**
  * Cast wrapper to convert a GLframebuffer to an st_framebuffer.
  * Return NULL if the GLframebuffer is a user-created framebuffer.
@@ -603,9 +595,9 @@ st_context_destroy(struct st_context_iface *stctxi)
 }
 
 static struct st_context_iface *
-st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
-                      const struct st_visual *visual,
-                      struct st_context_iface *shared_stctxi)
+create_context(gl_api api, struct st_manager *smapi,
+               const struct st_visual *visual,
+               struct st_context_iface *shared_stctxi)
 {
    struct st_context *shared_ctx = (struct st_context *) shared_stctxi;
    struct st_context *st;
@@ -617,7 +609,7 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
       return NULL;
 
    st_visual_to_context_mode(visual, &mode);
-   st = st_create_context(pipe, &mode, shared_ctx);
+   st = st_create_context(api, pipe, &mode, shared_ctx);
    if (!st) {
       pipe->destroy(pipe);
       return NULL;
@@ -637,6 +629,30 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
    return &st->iface;
 }
 
+static struct st_context_iface *
+st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
+                      const struct st_visual *visual,
+                      struct st_context_iface *shared_stctxi)
+{
+   return create_context(API_OPENGL, smapi, visual, shared_stctxi);
+}
+
+static struct st_context_iface *
+st_api_create_context_es1(struct st_api *stapi, struct st_manager *smapi,
+                          const struct st_visual *visual,
+                          struct st_context_iface *shared_stctxi)
+{
+   return create_context(API_OPENGLES, smapi, visual, shared_stctxi);
+}
+
+static struct st_context_iface *
+st_api_create_context_es2(struct st_api *stapi, struct st_manager *smapi,
+                          const struct st_visual *visual,
+                          struct st_context_iface *shared_stctxi)
+{
+   return create_context(API_OPENGLES2, smapi, visual, shared_stctxi);
+}
+
 static boolean
 st_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi,
                     struct st_framebuffer_iface *stdrawi,
@@ -812,7 +828,7 @@ st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb,
    return TRUE;
 }
 
-struct st_api st_gl_api = {
+static const struct st_api st_gl_api = {
    st_api_destroy,
    st_api_get_proc_address,
    st_api_create_context,
@@ -820,13 +836,52 @@ struct st_api st_gl_api = {
    st_api_get_current,
 };
 
-/**
- * Return the st_api for this state tracker. This might either be GL, GLES1,
- * GLES2 that mostly depends on the build and link options. But these
- * functions remain the same either way.
- */
+static const struct st_api st_gl_api_es1 = {
+   st_api_destroy,
+   st_api_get_proc_address,
+   st_api_create_context_es1,
+   st_api_make_current,
+   st_api_get_current,
+};
+
+static const struct st_api st_gl_api_es2 = {
+   st_api_destroy,
+   st_api_get_proc_address,
+   st_api_create_context_es2,
+   st_api_make_current,
+   st_api_get_current,
+};
+
 struct st_api *
 st_gl_api_create(void)
 {
-   return &st_gl_api;
+   (void) st_gl_api;
+   (void) st_gl_api_es1;
+   (void) st_gl_api_es2;
+
+#if FEATURE_GL
+   return (struct st_api *) &st_gl_api;
+#else
+   return NULL;
+#endif
+}
+
+struct st_api *
+st_gl_api_create_es1(void)
+{
+#if FEATURE_ES1
+   return (struct st_api *) &st_gl_api_es1;
+#else
+   return NULL;
+#endif
+}
+
+struct st_api *
+st_gl_api_create_es2(void)
+{
+#if FEATURE_ES2
+   return (struct st_api *) &st_gl_api_es2;
+#else
+   return NULL;
+#endif
 }
diff --git a/src/mesa/state_tracker/st_manager.h b/src/mesa/state_tracker/st_manager.h
index dabede4..cd2887b 100644
--- a/src/mesa/state_tracker/st_manager.h
+++ b/src/mesa/state_tracker/st_manager.h
@@ -46,7 +46,4 @@ boolean
 st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb,
                                   gl_buffer_index idx);
 
-struct st_api *
-st_manager_create_api(void);
-
 #endif /* ST_MANAGER_H */




More information about the mesa-commit mailing list