summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/context.c
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2010-10-26 11:31:37 +0800
committerChia-I Wu <[email protected]>2010-11-02 14:43:35 +0800
commit16ee7a55ae269612263468195f2af998cb9ef695 (patch)
tree868970ddf003098218bb905309f6d592e6b271fc /src/mesa/main/context.c
parentfdede1efaae32d23caf3b351cc766df12e3c5f8d (diff)
mesa: Allow contexts of different APIs to coexist.
This effectively redoes 1741ddb747ca0be284315adb4b6fe67ddf292d03 in a way that allows contexts of different APIs to coexist. First, the changes to the remap table are reverted. The remap table (driDispatchRemapTable) is always initialized in the same way regardless of the context API. es_generator.py is updated to use a local remap table, whose sole purpose is to help initialize its dispatch table. The local remap table and the global one are always different, as they use different glapidispatch.h. But the dispatch tables initialized by both remap tables are always compatible with glapi (libGL.so). Finally, the semantics of one_time_init are changed to per-api one-time initialization.
Diffstat (limited to 'src/mesa/main/context.c')
-rw-r--r--src/mesa/main/context.c56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 81e862275d4..4e9bf0f9903 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -131,6 +131,7 @@
#if _HAVE_FULL_GL
#include "math/m_matrix.h"
#endif
+#include "main/dispatch.h" /* for _gloffset_COUNT */
#ifdef USE_SPARC_ASM
#include "sparc/sparc.h"
@@ -379,10 +380,12 @@ _glthread_DECLARE_STATIC_MUTEX(OneTimeLock);
static void
one_time_init( struct gl_context *ctx )
{
- static GLboolean alreadyCalled = GL_FALSE;
- (void) ctx;
+ static GLbitfield api_init_mask = 0x0;
+
_glthread_LOCK_MUTEX(OneTimeLock);
- if (!alreadyCalled) {
+
+ /* truly one-time init */
+ if (!api_init_mask) {
GLuint i;
/* do some implementation tests */
@@ -395,27 +398,9 @@ one_time_init( struct gl_context *ctx )
_mesa_get_cpu_features();
- switch (ctx->API) {
-#if FEATURE_GL
- case API_OPENGL:
- _mesa_init_remap_table();
- break;
-#endif
-#if FEATURE_ES1
- case API_OPENGLES:
- _mesa_init_remap_table_es1();
- break;
-#endif
-#if FEATURE_ES2
- case API_OPENGLES2:
- _mesa_init_remap_table_es2();
- break;
-#endif
- default:
- break;
- }
-
_mesa_init_sqrt_table();
+
+ /* context dependence is never a one-time thing... */
_mesa_init_get_hash(ctx);
for (i = 0; i < 256; i++) {
@@ -426,9 +411,22 @@ one_time_init( struct gl_context *ctx )
_mesa_debug(ctx, "Mesa %s DEBUG build %s %s\n",
MESA_VERSION_STRING, __DATE__, __TIME__);
#endif
+ }
- alreadyCalled = GL_TRUE;
+ /* per-API one-time init */
+ if (!(api_init_mask & (1 << ctx->API))) {
+ /*
+ * This is fine as ES does not use the remap table, but it may not be
+ * future-proof. We cannot always initialize the remap table because
+ * when an app is linked to libGLES*, there are not enough dynamic
+ * entries.
+ */
+ if (ctx->API == API_OPENGL)
+ _mesa_init_remap_table();
}
+
+ api_init_mask |= 1 << ctx->API;
+
_glthread_UNLOCK_MUTEX(OneTimeLock);
/* Hopefully atexit() is widely available. If not, we may need some
@@ -811,9 +809,13 @@ _mesa_alloc_dispatch_table(int size)
* Mesa we do this to accomodate different versions of libGL and various
* DRI drivers.
*/
- GLint numEntries = MAX2(_glapi_get_dispatch_table_size(), size);
- struct _glapi_table *table =
- (struct _glapi_table *) malloc(numEntries * sizeof(_glapi_proc));
+ GLint numEntries = MAX2(_glapi_get_dispatch_table_size(), _gloffset_COUNT);
+ struct _glapi_table *table;
+
+ /* should never happen, but just in case */
+ numEntries = MAX2(numEntries, size);
+
+ table = (struct _glapi_table *) malloc(numEntries * sizeof(_glapi_proc));
if (table) {
_glapi_proc *entry = (_glapi_proc *) table;
GLint i;