added dispatch override mechanism, used by trace extension
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
/* $Id: glapi.c,v 1.48 2000/11/22 07:32:17 joukj Exp $ */
|
/* $Id: glapi.c,v 1.49 2001/01/23 23:35:47 brianp Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mesa 3-D graphics library
|
* Mesa 3-D graphics library
|
||||||
* Version: 3.5
|
* Version: 3.5
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
|
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -38,6 +38,10 @@
|
|||||||
* based libGL.so, and perhaps the SGI SI.
|
* based libGL.so, and perhaps the SGI SI.
|
||||||
*
|
*
|
||||||
* There are no dependencies on Mesa in this code.
|
* There are no dependencies on Mesa in this code.
|
||||||
|
*
|
||||||
|
* Versions (API changes):
|
||||||
|
* 2000/02/23 - original version for Mesa 3.3 and XFree86 4.0
|
||||||
|
* 2001/01/16 - added dispatch override feature for Mesa 3.5
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -49,12 +53,9 @@
|
|||||||
#include "glapitable.h"
|
#include "glapitable.h"
|
||||||
#include "glthread.h"
|
#include "glthread.h"
|
||||||
|
|
||||||
#if defined(MESA_TRACE)
|
|
||||||
#include "mtypes.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This is used when thread safety is disabled */
|
/* This is used when thread safety is disabled */
|
||||||
struct _glapi_table *_glapi_Dispatch = (struct _glapi_table *) __glapi_noop_table;
|
struct _glapi_table *_glapi_Dispatch = (struct _glapi_table *) __glapi_noop_table;
|
||||||
|
struct _glapi_table *_glapi_RealDispatch = (struct _glapi_table *) __glapi_noop_table;
|
||||||
|
|
||||||
/* Used when thread safety disabled */
|
/* Used when thread safety disabled */
|
||||||
void *_glapi_Context = NULL;
|
void *_glapi_Context = NULL;
|
||||||
@@ -66,6 +67,7 @@ void *_glapi_Context = NULL;
|
|||||||
static GLboolean ThreadSafe = GL_FALSE;
|
static GLboolean ThreadSafe = GL_FALSE;
|
||||||
|
|
||||||
static _glthread_TSD DispatchTSD;
|
static _glthread_TSD DispatchTSD;
|
||||||
|
static _glthread_TSD RealDispatchTSD; /* only when using override */
|
||||||
|
|
||||||
static _glthread_TSD ContextTSD;
|
static _glthread_TSD ContextTSD;
|
||||||
|
|
||||||
@@ -76,6 +78,10 @@ static _glthread_TSD ContextTSD;
|
|||||||
static GLuint MaxDispatchOffset = sizeof(struct _glapi_table) / sizeof(void *) - 1;
|
static GLuint MaxDispatchOffset = sizeof(struct _glapi_table) / sizeof(void *) - 1;
|
||||||
static GLboolean GetSizeCalled = GL_FALSE;
|
static GLboolean GetSizeCalled = GL_FALSE;
|
||||||
|
|
||||||
|
static GLboolean DispatchOverride = GL_FALSE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* strdup is actually not a standard ANSI C or POSIX routine
|
/* strdup is actually not a standard ANSI C or POSIX routine
|
||||||
Irix will not define it if ANSI mode is in effect. */
|
Irix will not define it if ANSI mode is in effect. */
|
||||||
static char *str_dup(const char *str)
|
static char *str_dup(const char *str)
|
||||||
@@ -170,10 +176,6 @@ _glapi_get_context(void)
|
|||||||
void
|
void
|
||||||
_glapi_set_dispatch(struct _glapi_table *dispatch)
|
_glapi_set_dispatch(struct _glapi_table *dispatch)
|
||||||
{
|
{
|
||||||
#if defined(MESA_TRACE)
|
|
||||||
GLcontext * ctx;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!dispatch) {
|
if (!dispatch) {
|
||||||
/* use the no-op functions */
|
/* use the no-op functions */
|
||||||
dispatch = (struct _glapi_table *) __glapi_noop_table;
|
dispatch = (struct _glapi_table *) __glapi_noop_table;
|
||||||
@@ -185,36 +187,28 @@ _glapi_set_dispatch(struct _glapi_table *dispatch)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(THREADS)
|
#if defined(THREADS)
|
||||||
#if defined(MESA_TRACE)
|
if (DispatchOverride) {
|
||||||
ctx = (GLcontext *)_glthread_GetTSD(&ContextTSD);
|
_glthread_SetTSD(&RealDispatchTSD, (void *) dispatch);
|
||||||
if (ctx->TraceCtx->traceEnabled == GL_TRUE) {
|
|
||||||
_glthread_SetTSD(&DispatchTSD, (void *) ctx->TraceDispatch);
|
|
||||||
if (ThreadSafe)
|
if (ThreadSafe)
|
||||||
_glapi_Dispatch = NULL;
|
_glapi_RealDispatch = NULL;
|
||||||
else
|
else
|
||||||
_glapi_Dispatch = ctx->TraceDispatch;
|
_glapi_RealDispatch = dispatch;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* normal operation */
|
||||||
_glthread_SetTSD(&DispatchTSD, (void *) dispatch);
|
_glthread_SetTSD(&DispatchTSD, (void *) dispatch);
|
||||||
if (ThreadSafe)
|
if (ThreadSafe)
|
||||||
_glapi_Dispatch = NULL;
|
_glapi_Dispatch = NULL;
|
||||||
else
|
else
|
||||||
_glapi_Dispatch = dispatch;
|
_glapi_Dispatch = dispatch;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
_glthread_SetTSD(&DispatchTSD, (void *) dispatch);
|
|
||||||
if (ThreadSafe)
|
|
||||||
_glapi_Dispatch = NULL;
|
|
||||||
else
|
|
||||||
_glapi_Dispatch = dispatch;
|
|
||||||
#endif /*MESA_TRACE*/
|
|
||||||
#else /*THREADS*/
|
#else /*THREADS*/
|
||||||
#if defined(MESA_TRACE)
|
if (DispatchOverride) {
|
||||||
ctx = (GLcontext *)_glthread_GetTSD(&ContextTSD);
|
_glapi_RealDispatch = dispatch;
|
||||||
_glapi_Dispatch = ctx->TraceDispatch;
|
}
|
||||||
#else
|
else {
|
||||||
_glapi_Dispatch = dispatch;
|
_glapi_Dispatch = dispatch;
|
||||||
#endif /*MESA_TRACE*/
|
}
|
||||||
#endif /*THREADS*/
|
#endif /*THREADS*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,43 +222,109 @@ _glapi_get_dispatch(void)
|
|||||||
{
|
{
|
||||||
#if defined(THREADS)
|
#if defined(THREADS)
|
||||||
if (ThreadSafe) {
|
if (ThreadSafe) {
|
||||||
|
if (DispatchOverride) {
|
||||||
|
return (struct _glapi_table *) _glthread_GetTSD(&RealDispatchTSD);
|
||||||
|
}
|
||||||
|
else {
|
||||||
return (struct _glapi_table *) _glthread_GetTSD(&DispatchTSD);
|
return (struct _glapi_table *) _glthread_GetTSD(&DispatchTSD);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (DispatchOverride) {
|
||||||
|
assert(_glapi_RealDispatch);
|
||||||
|
return _glapi_RealDispatch;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
assert(_glapi_Dispatch);
|
assert(_glapi_Dispatch);
|
||||||
return _glapi_Dispatch;
|
return _glapi_Dispatch;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
return _glapi_Dispatch;
|
return _glapi_Dispatch;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(MESA_TRACE)
|
/*
|
||||||
struct _glapi_table *
|
* Notes on dispatch overrride:
|
||||||
_glapi_get_true_dispatch(void)
|
*
|
||||||
|
* Dispatch override allows an external agent to hook into the GL dispatch
|
||||||
|
* mechanism before execution goes into the core rendering library. For
|
||||||
|
* example, a trace mechanism would insert itself as an overrider, print
|
||||||
|
* logging info for each GL function, then dispatch to the real GL function.
|
||||||
|
*
|
||||||
|
* libGLS (GL Stream library) is another agent that might use override.
|
||||||
|
*
|
||||||
|
* We don't allow more than one layer of overriding at this time.
|
||||||
|
* In the future we may allow nested/layered override. In that case
|
||||||
|
* _glapi_begin_dispatch_override() will return an override layer,
|
||||||
|
* _glapi_end_dispatch_override(layer) will remove an override layer
|
||||||
|
* and _glapi_get_override_dispatch(layer) will return the dispatch
|
||||||
|
* table for a given override layer. layer = 0 will be the "real"
|
||||||
|
* dispatch table.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return: dispatch override layer number.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
_glapi_begin_dispatch_override(struct _glapi_table *override)
|
||||||
{
|
{
|
||||||
GLcontext* ctx;
|
struct _glapi_table *real = _glapi_get_dispatch();
|
||||||
|
|
||||||
|
assert(!DispatchOverride); /* can't nest at this time */
|
||||||
|
DispatchOverride = GL_TRUE;
|
||||||
|
|
||||||
|
_glapi_set_dispatch(real);
|
||||||
|
|
||||||
#if defined(THREADS)
|
#if defined(THREADS)
|
||||||
if (ThreadSafe) {
|
_glthread_SetTSD(&DispatchTSD, (void *) override);
|
||||||
ctx = (GLcontext *) _glthread_GetTSD(&ContextTSD);
|
if (ThreadSafe)
|
||||||
assert(ctx);
|
_glapi_Dispatch = NULL;
|
||||||
assert(ctx->CurrentDispatch);
|
else
|
||||||
return ctx->CurrentDispatch;
|
_glapi_Dispatch = override;
|
||||||
|
#else
|
||||||
|
_glapi_Dispatch = override;
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
_glapi_end_dispatch_override(int layer)
|
||||||
|
{
|
||||||
|
struct _glapi_table *real = _glapi_get_dispatch();
|
||||||
|
(void) layer;
|
||||||
|
DispatchOverride = GL_FALSE;
|
||||||
|
_glapi_set_dispatch(real);
|
||||||
|
/* the rest of this isn't needed, just play it safe */
|
||||||
|
#if defined(THREADS)
|
||||||
|
_glthread_SetTSD(&RealDispatchTSD, NULL);
|
||||||
|
#endif
|
||||||
|
_glapi_RealDispatch = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct _glapi_table *
|
||||||
|
_glapi_get_override_dispatch(int layer)
|
||||||
|
{
|
||||||
|
if (layer == 0) {
|
||||||
|
return _glapi_get_dispatch();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(_glapi_Context);
|
if (DispatchOverride) {
|
||||||
assert(((GLcontext *)_glapi_Context)->CurrentDispatch);
|
#if defined(THREADS)
|
||||||
return ((GLcontext *)_glapi_Context)->CurrentDispatch;
|
return (struct _glapi_table *) _glthread_GetTSD(&DispatchTSD);
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
assert(_glapi_Context);
|
return _glapi_Dispatch;
|
||||||
assert(((GLcontext *)_glapi_Context)->CurrentDispatch);
|
|
||||||
return ((GLcontext *)_glapi_Context)->CurrentDispatch;
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* MESA_TRACE */
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -287,7 +347,7 @@ _glapi_get_dispatch_table_size(void)
|
|||||||
const char *
|
const char *
|
||||||
_glapi_get_version(void)
|
_glapi_get_version(void)
|
||||||
{
|
{
|
||||||
return "20001026"; /* YYYYMMDD */
|
return "20010116"; /* YYYYMMDD */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
/* $Id: glapi.h,v 1.17 2000/09/26 15:27:23 brianp Exp $ */
|
/* $Id: glapi.h,v 1.18 2001/01/23 23:35:47 brianp Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mesa 3-D graphics library
|
* Mesa 3-D graphics library
|
||||||
* Version: 3.5
|
* Version: 3.5
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
|
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -59,10 +59,16 @@ extern struct _glapi_table *
|
|||||||
_glapi_get_dispatch(void);
|
_glapi_get_dispatch(void);
|
||||||
|
|
||||||
|
|
||||||
#if defined(MESA_TRACE)
|
extern int
|
||||||
extern struct _glapi_table *
|
_glapi_begin_dispatch_override(struct _glapi_table *override);
|
||||||
_glapi_get_true_dispatch(void);
|
|
||||||
#endif
|
|
||||||
|
extern void
|
||||||
|
_glapi_end_dispatch_override(int layer);
|
||||||
|
|
||||||
|
|
||||||
|
struct _glapi_table *
|
||||||
|
_glapi_get_override_dispatch(int layer);
|
||||||
|
|
||||||
|
|
||||||
extern GLuint
|
extern GLuint
|
||||||
|
Reference in New Issue
Block a user