[Mesa-dev] [RFC PATCH 1/6] st_api: Remove st_module
Kristian Høgsberg
krh at bitplanet.net
Sat Apr 24 17:30:38 PDT 2010
On Sat, Apr 24, 2010 at 10:25 AM, Jakob Bornecrantz
<wallbraker at gmail.com> wrote:
> The struct st_module isn't needed as it is the same thing as the st_api
> struct. That is they both represent the API. Instead just use a single
> function entry point to the the API.
> ---
> src/gallium/include/state_tracker/st_api.h | 35 +++++++-------------
> src/gallium/state_trackers/dri/common/dri_st_api.c | 4 +-
> src/gallium/state_trackers/egl/common/egl_g3d_st.c | 29 ++++++++--------
> src/gallium/state_trackers/es/st_es1.c | 13 +++----
> src/gallium/state_trackers/es/st_es2.c | 14 ++++----
> src/gallium/state_trackers/vega/vg_manager.c | 33 +++++++------------
> src/gallium/targets/libgl-xlib/xlib.c | 16 ++++----
> src/mesa/state_tracker/st_gl_api.h | 9 +++++
> src/mesa/state_tracker/st_manager.c | 33 ++++++++----------
> 9 files changed, 86 insertions(+), 100 deletions(-)
> create mode 100644 src/mesa/state_tracker/st_gl_api.h
>
> diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h
> index 8897ff7..002d1c6 100644
> --- a/src/gallium/include/state_tracker/st_api.h
> +++ b/src/gallium/include/state_tracker/st_api.h
> @@ -43,14 +43,6 @@
> */
>
> /**
> - * The entry points of the state trackers.
> - */
> -#define ST_MODULE_OPENGL_SYMBOL "st_module_OpenGL"
> -#define ST_MODULE_OPENGL_ES1_SYMBOL "st_module_OpenGL_ES1"
> -#define ST_MODULE_OPENGL_ES2_SYMBOL "st_module_OpenGL_ES2"
> -#define ST_MODULE_OPENVG_SYMBOL "st_module_OpenVG"
> -
> -/**
> * The supported rendering API of a state tracker.
> */
> enum st_api_type {
> @@ -379,17 +371,6 @@ struct st_api
> };
>
> /**
> - * Represent a state tracker.
> - *
> - * This is the entry point of a state tracker.
> - */
> -struct st_module
> -{
> - enum st_api_type api;
> - struct st_api *(*create_api)(void);
> -};
> -
> -/**
> * Return true if the visual has the specified buffers.
> */
> static INLINE boolean
> @@ -399,9 +380,17 @@ st_visual_have_buffers(const struct st_visual *visual, unsigned mask)
> }
>
> /* these symbols may need to be dynamically lookup up */
> -extern PUBLIC const struct st_module st_module_OpenGL;
> -extern PUBLIC const struct st_module st_module_OpenGL_ES1;
> -extern PUBLIC const struct st_module st_module_OpenGL_ES2;
> -extern PUBLIC const struct st_module st_module_OpenVG;
> +extern PUBLIC struct st_api * st_api_create_OpenGL(void);
> +extern PUBLIC struct st_api * st_api_create_OpenGL_ES1(void);
> +extern PUBLIC struct st_api * st_api_create_OpenGL_ES2(void);
> +extern PUBLIC struct st_api * st_api_create_OpenVG(void);
> +
> +/**
> + * The entry points of the state trackers.
> + */
> +#define ST_CREATE_OPENGL_SYMBOL "st_api_create_OpenGL"
> +#define ST_CREATE_OPENGL_ES1_SYMBOL "st_api_create_OpenGL_ES1"
> +#define ST_CREATE_OPENGL_ES2_SYMBOL "st_api_create_OpenGL_ES2"
> +#define ST_CREATE_OPENVG_SYMBOL "st_api_create_OpenVG"
>
> #endif /* _ST_API_H_ */
> diff --git a/src/gallium/state_trackers/dri/common/dri_st_api.c b/src/gallium/state_trackers/dri/common/dri_st_api.c
> index 261bae7..f9295cb 100644
> --- a/src/gallium/state_trackers/dri/common/dri_st_api.c
> +++ b/src/gallium/state_trackers/dri/common/dri_st_api.c
> @@ -30,7 +30,7 @@
> #include "util/u_inlines.h"
> #include "util/u_format.h"
> #include "util/u_debug.h"
> -#include "state_tracker/st_manager.h" /* for st_manager_create_api */
> +#include "state_tracker/st_gl_api.h" /* for st_gl_api_create */
>
> #include "dri_screen.h"
> #include "dri_context.h"
> @@ -208,7 +208,7 @@ _dri_get_st_api(void)
> {
> p_atomic_inc(&dri_st_api.refcnt);
> if (p_atomic_read(&dri_st_api.refcnt) == 1)
> - dri_st_api.stapi = st_manager_create_api();
> + dri_st_api.stapi = st_gl_api_create();
> }
>
> /**
> diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.c b/src/gallium/state_trackers/egl/common/egl_g3d_st.c
> index 57a479f..47ecc50 100644
> --- a/src/gallium/state_trackers/egl/common/egl_g3d_st.c
> +++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.c
> @@ -49,41 +49,42 @@ egl_g3d_st_manager(struct st_manager *smapi)
> struct st_api *
> egl_g3d_create_st_api(enum st_api_type api)
> {
> - const char *stmod_name;
> struct util_dl_library *lib;
> - const struct st_module *mod;
> + const char *proc_name;
> + struct st_api * (*proc)(void) = NULL;
>
> switch (api) {
> case ST_API_OPENGL:
> - stmod_name = ST_MODULE_OPENGL_SYMBOL;
> + proc_name = ST_CREATE_OPENGL_SYMBOL;
> break;
> case ST_API_OPENGL_ES1:
> - stmod_name = ST_MODULE_OPENGL_ES1_SYMBOL;
> + proc_name = ST_CREATE_OPENGL_ES1_SYMBOL;
> break;
> case ST_API_OPENGL_ES2:
> - stmod_name = ST_MODULE_OPENGL_ES2_SYMBOL;
> + proc_name = ST_CREATE_OPENGL_ES2_SYMBOL;
> break;
> case ST_API_OPENVG:
> - stmod_name = ST_MODULE_OPENVG_SYMBOL;
> + proc_name = ST_CREATE_OPENVG_SYMBOL;
> break;
> default:
> - stmod_name = NULL;
> - break;
> + assert(!"Unknown API Type\n");
> + return NULL;
> }
> - if (!stmod_name)
> +
> + if (!proc_name)
> return NULL;
>
> - mod = NULL;
> lib = util_dl_open(NULL);
> if (lib) {
> - mod = (const struct st_module *)
> - util_dl_get_proc_address(lib, stmod_name);
> + proc = util_dl_get_proc_address(lib, proc_name);
> + debug_printf("%s: %s %p\n", __func__, proc_name, proc);
> util_dl_close(lib);
> }
> - if (!mod || mod->api != api)
> +
> + if (!proc)
> return NULL;
>
> - return mod->create_api();
> + return proc();
> }
>
> static boolean
> diff --git a/src/gallium/state_trackers/es/st_es1.c b/src/gallium/state_trackers/es/st_es1.c
> index 4e89e06..825fdac 100644
> --- a/src/gallium/state_trackers/es/st_es1.c
> +++ b/src/gallium/state_trackers/es/st_es1.c
> @@ -1,8 +1,7 @@
> -#include "state_tracker/st_manager.h"
> +#include "state_tracker/st_gl_api.h"
>
> -PUBLIC const int st_api_OpenGL_ES1 = 1;
> -
> -PUBLIC const struct st_module st_module_OpenGL_ES1 = {
> - .api = ST_API_OPENGL_ES1,
> - .create_api = st_manager_create_api
> -};
> +PUBLIC struct st_api *
> +st_api_create_OpenGL_ES1()
> +{
> + return st_gl_api_create();
Can we make st_gl_api_create() take an enum (like ST_API_OPENGL_ES1)
to indicate which GL API we want to create? I have a patch series on
the way to make core mesa multi-API aware and mesa_create_context()
will take a similar enum from mtypes.h. If we add that argument to
st_gl_api_create(), one gallium GL state tracker will be able to
implement the three API in one driver.
Kristian
More information about the mesa-dev
mailing list