From 948e3fa27ca9112b903a180d1a18c61cfb2928dc Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 10 Sep 2010 12:59:43 +0800 Subject: [PATCH] st/egl: Use profiles to create OpenGL ES contexts. Replace all uses of ST_API_OPENGL_ES{1,2} by profiles. Having 3 st_api's to provide OpenGL, OpenGL ES 1.1, and OpenGL ES 2.0 is not a sane abstraction, since all of them share glapi for current context/dispatch management. --- .../state_trackers/egl/common/egl_g3d.c | 10 +- .../state_trackers/egl/common/egl_g3d_api.c | 31 ++++--- .../egl/common/egl_g3d_loader.h | 4 +- .../state_trackers/egl/common/egl_g3d_st.h | 29 ------ src/gallium/targets/egl-gdi/egl-static.c | 86 +++++------------ src/gallium/targets/egl/Makefile | 3 +- src/gallium/targets/egl/egl.c | 92 ++++++++----------- src/gallium/targets/egl/st_GL.c | 18 ---- src/gallium/targets/egl/st_GLESv1_CM.c | 4 +- src/gallium/targets/egl/st_GLESv2.c | 4 +- 10 files changed, 92 insertions(+), 189 deletions(-) diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index 4e653bdf3b2..33a838fb798 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -502,13 +502,13 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy, goto fail; } - if (gdpy->loader->api_mask & (1 << ST_API_OPENGL)) + if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_DEFAULT_MASK) dpy->ClientAPIsMask |= EGL_OPENGL_BIT; - if (gdpy->loader->api_mask & (1 << ST_API_OPENGL_ES1)) + if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_OPENGL_ES1_MASK) dpy->ClientAPIsMask |= EGL_OPENGL_ES_BIT; - if (gdpy->loader->api_mask & (1 << ST_API_OPENGL_ES2)) + if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_OPENGL_ES2_MASK) dpy->ClientAPIsMask |= EGL_OPENGL_ES2_BIT; - if (gdpy->loader->api_mask & (1 << ST_API_OPENVG)) + if (gdpy->loader->profile_masks[ST_API_OPENVG] & ST_PROFILE_DEFAULT_MASK) dpy->ClientAPIsMask |= EGL_OPENVG_BIT; gdpy->smapi = egl_g3d_create_st_manager(dpy); @@ -567,7 +567,7 @@ egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname) if (procname && procname[0] == 'v' && procname[1] == 'g') stapi = gdrv->loader->get_st_api(ST_API_OPENVG); else if (procname && procname[0] == 'g' && procname[1] == 'l') - stapi = gdrv->loader->guess_gl_api(); + stapi = gdrv->loader->get_st_api(ST_API_OPENGL); return (_EGLProc) ((stapi) ? stapi->get_proc_address(stapi, procname) : NULL); diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_api.c b/src/gallium/state_trackers/egl/common/egl_g3d_api.c index cda46b8c301..c0164daf9c1 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_api.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d_api.c @@ -47,16 +47,21 @@ egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx, enum st_profile_type *profile) { struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); - EGLint idx = -1; + struct st_api *stapi; + EGLint api = -1; + + *profile = ST_PROFILE_DEFAULT; switch (ctx->ClientAPI) { case EGL_OPENGL_ES_API: switch (ctx->ClientVersion) { case 1: - idx = ST_API_OPENGL_ES1; + api = ST_API_OPENGL; + *profile = ST_PROFILE_OPENGL_ES1; break; case 2: - idx = ST_API_OPENGL_ES2; + api = ST_API_OPENGL; + *profile = ST_PROFILE_OPENGL_ES2; break; default: _eglLog(_EGL_WARNING, "unknown client version %d", @@ -65,29 +70,31 @@ egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx, } break; case EGL_OPENVG_API: - idx = ST_API_OPENVG; + api = ST_API_OPENVG; break; case EGL_OPENGL_API: - idx = ST_API_OPENGL; + api = ST_API_OPENGL; break; default: _eglLog(_EGL_WARNING, "unknown client API 0x%04x", ctx->ClientAPI); break; } - switch (idx) { - case ST_API_OPENGL_ES1: - *profile = ST_PROFILE_OPENGL_ES1; + switch (api) { + case ST_API_OPENGL: + stapi = gdrv->loader->guess_gl_api(*profile); break; - case ST_API_OPENGL_ES2: - *profile = ST_PROFILE_OPENGL_ES2; + case ST_API_OPENVG: + stapi = gdrv->loader->get_st_api(api); break; default: - *profile = ST_PROFILE_DEFAULT; + stapi = NULL; break; } + if (stapi && !(stapi->profile_mask & (1 << *profile))) + stapi = NULL; - return (idx >= 0) ? gdrv->loader->get_st_api(idx) : NULL; + return stapi; } static _EGLContext * diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_loader.h b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h index c9141f8ad4e..78bfe2131ef 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_loader.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d_loader.h @@ -37,9 +37,9 @@ struct pipe_screen; struct sw_winsys; struct egl_g3d_loader { - uint api_mask; + uint profile_masks[ST_API_COUNT]; struct st_api *(*get_st_api)(enum st_api_type api); - struct st_api *(*guess_gl_api)(void); + struct st_api *(*guess_gl_api)(enum st_profile_type profile); struct pipe_screen *(*create_drm_screen)(const char *name, int fd); struct pipe_screen *(*create_sw_screen)(struct sw_winsys *ws); diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.h b/src/gallium/state_trackers/egl/common/egl_g3d_st.h index aa25cc042d7..1f9f07895b4 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d_st.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.h @@ -45,33 +45,4 @@ egl_g3d_create_st_framebuffer(_EGLSurface *surf); void egl_g3d_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); -/** - * Return the EGL__BIT of the st api. - */ -static INLINE int -egl_g3d_st_api_bit(enum st_api_type api) -{ - int bit; - - switch (api) { - case ST_API_OPENGL: - bit = EGL_OPENGL_BIT; - break; - case ST_API_OPENGL_ES1: - bit = EGL_OPENGL_ES_BIT; - break; - case ST_API_OPENGL_ES2: - bit = EGL_OPENGL_ES2_BIT; - break; - case ST_API_OPENVG: - bit = EGL_OPENVG_BIT; - break; - default: - bit = 0; - break; - } - - return bit; -} - #endif /* _EGL_G3D_ST_H_ */ diff --git a/src/gallium/targets/egl-gdi/egl-static.c b/src/gallium/targets/egl-gdi/egl-static.c index 4655d791170..da6e5ce3396 100644 --- a/src/gallium/targets/egl-gdi/egl-static.c +++ b/src/gallium/targets/egl-gdi/egl-static.c @@ -35,27 +35,6 @@ static struct st_api *stapis[ST_API_COUNT]; -static uint -get_api_mask(void) -{ - uint api_mask = 0x0; - -#if FEATURE_GL - api_mask |= 1 << ST_API_OPENGL; -#endif -#if FEATURE_ES1 - api_mask |= 1 << ST_API_OPENGL_ES1; -#endif -#if FEATURE_ES2 - api_mask |= 1 << ST_API_OPENGL_ES2; -#endif -#if FEATURE_VG - api_mask |= 1 << ST_API_OPENVG; -#endif - - return api_mask; -} - static struct st_api * get_st_api(enum st_api_type api) { @@ -66,28 +45,18 @@ get_st_api(enum st_api_type api) return stapi; switch (api) { -#if FEATURE_GL - case ST_API_OPENGL: - stapi = st_gl_api_create(); - break; -#endif -#if FEATURE_ES1 - case ST_API_OPENGL_ES1: - stapi = st_gl_api_create_es1(); - break; -#endif -#if FEATURE_ES2 - case ST_API_OPENGL_ES2: - stapi = st_gl_api_create_es2(); - break; +#if FEATURE_GL || FEATURE_ES1 || FEATURE_ES2 + case ST_API_OPENGL: + stapi = st_gl_api_create(); + break; #endif #if FEATURE_VG - case ST_API_OPENVG: - stapi = (struct st_api *) vg_api_get(); - break; + case ST_API_OPENVG: + stapi = (struct st_api *) vg_api_get(); + break; #endif - default: - break; + default: + break; } stapis[api] = stapi; @@ -96,27 +65,9 @@ get_st_api(enum st_api_type api) } static struct st_api * -guess_gl_api(void) +guess_gl_api(enum st_profile_type profile) { - struct st_api *stapi = NULL; - -#if FEATURE_GL - stapi = get_st_api(ST_API_OPENGL); - if (stapi) - return stapi; -#endif -#if FEATURE_ES1 - stapi = get_st_api(ST_API_OPENGL_ES1); - if (stapi) - return stapi; -#endif -#if FEATURE_ES2 - stapi = get_st_api(ST_API_OPENGL_ES2); - if (stapi) - return stapi; -#endif - - return stapi; + return get_st_api(ST_API_OPENGL); } static struct pipe_screen * @@ -140,10 +91,19 @@ create_sw_screen(struct sw_winsys *ws) static void init_loader(struct egl_g3d_loader *loader) { - if (loader->api_mask) - return; +#if FEATURE_GL + loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_DEFAULT_MASK; +#endif +#if FEATURE_ES1 + loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES1_MASK; +#endif +#if FEATURE_ES2 + loader->profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES2_MASK; +#endif +#if FEATURE_VG + loader->profile_masks[ST_API_OPENVG] |= ST_PROFILE_DEFAULT_MASK; +#endif - loader->api_mask = get_api_mask(); loader->get_st_api = get_st_api; loader->guess_gl_api = guess_gl_api; loader->create_drm_screen = create_drm_screen; diff --git a/src/gallium/targets/egl/Makefile b/src/gallium/targets/egl/Makefile index 2784fd0d100..78f72411996 100644 --- a/src/gallium/targets/egl/Makefile +++ b/src/gallium/targets/egl/Makefile @@ -126,7 +126,8 @@ endif # OpenGL state tracker GL_CPPFLAGS := -I$(TOP)/src/mesa $(API_DEFINES) -GL_SYS := $(DRI_LIB_DEPS) -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) +# do not link to $(GL_LIB) as the it supports GLES too +GL_SYS := $(DRI_LIB_DEPS) GL_LIBS := $(TOP)/src/mesa/libmesagallium.a # OpenGL ES 1.x state tracker diff --git a/src/gallium/targets/egl/egl.c b/src/gallium/targets/egl/egl.c index a573b212179..7c6bb58aecf 100644 --- a/src/gallium/targets/egl/egl.c +++ b/src/gallium/targets/egl/egl.c @@ -98,6 +98,8 @@ load_st_module(struct st_module *stmod, { struct st_api *(*create_api)(void); + _eglLog(_EGL_DEBUG, "searching for st module %s", name); + stmod->name = loader_strdup(name); if (stmod->name) _eglSearchPathForEach(dlopen_st_module_cb, (void *) stmod); @@ -187,7 +189,7 @@ load_pipe_module(struct pipe_module *pmod, const char *name) } static struct st_api * -get_st_api(enum st_api_type api) +get_st_api_full(enum st_api_type api, enum st_profile_type profile) { struct st_module *stmod = &st_modules[api]; const char *names[8], *symbol; @@ -199,17 +201,19 @@ get_st_api(enum st_api_type api) switch (api) { case ST_API_OPENGL: symbol = ST_CREATE_OPENGL_SYMBOL; - names[count++] = "GL"; - break; - case ST_API_OPENGL_ES1: - symbol = ST_CREATE_OPENGL_ES1_SYMBOL; - names[count++] = "GLESv1_CM"; - names[count++] = "GL"; - break; - case ST_API_OPENGL_ES2: - symbol = ST_CREATE_OPENGL_ES2_SYMBOL; - names[count++] = "GLESv2"; - names[count++] = "GL"; + switch (profile) { + case ST_PROFILE_OPENGL_ES1: + names[count++] = "GLESv1_CM"; + names[count++] = "GL"; + break; + case ST_PROFILE_OPENGL_ES2: + names[count++] = "GLESv2"; + names[count++] = "GL"; + break; + default: + names[count++] = "GL"; + break; + } break; case ST_API_OPENVG: symbol = ST_CREATE_OPENVG_SYMBOL; @@ -230,7 +234,7 @@ get_st_api(enum st_api_type api) } if (!stmod->stapi) { - EGLint level = (egl_g3d_loader.api_mask & (1 << api)) ? + EGLint level = (egl_g3d_loader.profile_masks[api]) ? _EGL_WARNING : _EGL_DEBUG; _eglLog(level, "unable to load " ST_PREFIX "%s" UTIL_DL_EXT, names[0]); } @@ -241,50 +245,31 @@ get_st_api(enum st_api_type api) } static struct st_api * -guess_gl_api(void) +get_st_api(enum st_api_type api) { - struct st_api *stapi; - int gl_apis[] = { - ST_API_OPENGL, - ST_API_OPENGL_ES1, - ST_API_OPENGL_ES2, - -1 - }; - int i, api = -1; - - /* determine the api from the loaded libraries */ - for (i = 0; gl_apis[i] != -1; i++) { - if (st_modules[gl_apis[i]].stapi) { - api = gl_apis[i]; - break; - } - } - /* determine the api from the linked libraries */ - if (api == -1) { - struct util_dl_library *self = util_dl_open(NULL); + enum st_profile_type profile = ST_PROFILE_DEFAULT; + /* determine the profile from the linked libraries */ + if (api == ST_API_OPENGL) { + struct util_dl_library *self; + + self = util_dl_open(NULL); if (self) { - if (util_dl_get_proc_address(self, "glColor4d")) - api = ST_API_OPENGL; - else if (util_dl_get_proc_address(self, "glColor4x")) - api = ST_API_OPENGL_ES1; + if (util_dl_get_proc_address(self, "glColor4x")) + profile = ST_PROFILE_OPENGL_ES1; else if (util_dl_get_proc_address(self, "glShaderBinary")) - api = ST_API_OPENGL_ES2; + profile = ST_PROFILE_OPENGL_ES2; util_dl_close(self); } } - stapi = (api != -1) ? get_st_api(api) : NULL; - if (!stapi) { - for (i = 0; gl_apis[i] != -1; i++) { - api = gl_apis[i]; - stapi = get_st_api(api); - if (stapi) - break; - } - } + return get_st_api_full(api, profile); +} - return stapi; +static struct st_api * +guess_gl_api(enum st_profile_type profile) +{ + return get_st_api_full(ST_API_OPENGL, profile); } static struct pipe_module * @@ -333,23 +318,20 @@ create_sw_screen(struct sw_winsys *ws) static const struct egl_g3d_loader * loader_init(void) { - uint api_mask = 0x0; - /* TODO detect at runtime? */ #if FEATURE_GL - api_mask |= 1 << ST_API_OPENGL; + egl_g3d_loader.profile_masks[ST_API_OPENGL] |= ST_PROFILE_DEFAULT_MASK; #endif #if FEATURE_ES1 - api_mask |= 1 << ST_API_OPENGL_ES1; + egl_g3d_loader.profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES1_MASK; #endif #if FEATURE_ES2 - api_mask |= 1 << ST_API_OPENGL_ES2; + egl_g3d_loader.profile_masks[ST_API_OPENGL] |= ST_PROFILE_OPENGL_ES2_MASK; #endif #if FEATURE_VG - api_mask |= 1 << ST_API_OPENVG; + egl_g3d_loader.profile_masks[ST_API_OPENVG] |= ST_PROFILE_DEFAULT_MASK; #endif - egl_g3d_loader.api_mask = api_mask; egl_g3d_loader.get_st_api = get_st_api; egl_g3d_loader.guess_gl_api = guess_gl_api; egl_g3d_loader.create_drm_screen = create_drm_screen; diff --git a/src/gallium/targets/egl/st_GL.c b/src/gallium/targets/egl/st_GL.c index 17b7bf9d481..69c8f7a83cf 100644 --- a/src/gallium/targets/egl/st_GL.c +++ b/src/gallium/targets/egl/st_GL.c @@ -1,26 +1,8 @@ #include "state_tracker/st_gl_api.h" #include "state_tracker/st_api.h" -#if FEATURE_GL PUBLIC struct st_api * st_api_create_OpenGL(void) { return st_gl_api_create(); } -#endif - -#if FEATURE_ES1 -PUBLIC struct st_api * -st_api_create_OpenGL_ES1(void) -{ - return st_gl_api_create_es1(); -} -#endif - -#if FEATURE_ES2 -PUBLIC struct st_api * -st_api_create_OpenGL_ES2(void) -{ - return st_gl_api_create_es2(); -} -#endif diff --git a/src/gallium/targets/egl/st_GLESv1_CM.c b/src/gallium/targets/egl/st_GLESv1_CM.c index c1652d5131a..016bb4e9d08 100644 --- a/src/gallium/targets/egl/st_GLESv1_CM.c +++ b/src/gallium/targets/egl/st_GLESv1_CM.c @@ -2,7 +2,7 @@ #include "state_tracker/st_gl_api.h" PUBLIC struct st_api * -st_api_create_OpenGL_ES1(void) +st_api_create_OpenGL(void) { - return st_gl_api_create_es1(); + return st_gl_api_create(); } diff --git a/src/gallium/targets/egl/st_GLESv2.c b/src/gallium/targets/egl/st_GLESv2.c index 9c269890089..016bb4e9d08 100644 --- a/src/gallium/targets/egl/st_GLESv2.c +++ b/src/gallium/targets/egl/st_GLESv2.c @@ -2,7 +2,7 @@ #include "state_tracker/st_gl_api.h" PUBLIC struct st_api * -st_api_create_OpenGL_ES2(void) +st_api_create_OpenGL(void) { - return st_gl_api_create_es2(); + return st_gl_api_create(); } -- 2.30.2