Merge remote-tracking branch 'ajax/xserver-next'

This commit is contained in:
Keith Packard 2011-03-30 10:51:27 -07:00
commit e0a2ad51df
22 changed files with 99 additions and 7322 deletions

View File

@ -562,6 +562,17 @@ RebuildTable(int client)
clientTable[client].resources = resources;
}
static void
doFreeResource(ResourcePtr res, Bool skip)
{
CallResourceStateCallback(ResourceStateFreeing, res);
if (!skip)
resourceTypes[res->type & TypeMask].deleteFunc(res->value, res->id);
free(res);
}
void
FreeResource(XID id, RESTYPE skipDeleteFuncType)
{
@ -590,11 +601,8 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
*prev = res->next;
elements = --*eltptr;
CallResourceStateCallback(ResourceStateFreeing, res);
doFreeResource(res, rtype == skipDeleteFuncType);
if (rtype != skipDeleteFuncType)
(*resourceTypes[rtype & TypeMask].deleteFunc)(res->value, res->id);
free(res);
if (*eltptr != elements)
prev = head; /* prev may no longer be valid */
}
@ -604,7 +612,6 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
}
}
void
FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
{
@ -627,11 +634,8 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
*prev = res->next;
clientTable[cid].elements--;
CallResourceStateCallback(ResourceStateFreeing, res);
doFreeResource(res, skipFree);
if (!skipFree)
(*resourceTypes[type & TypeMask].deleteFunc)(res->value, res->id);
free(res);
break;
}
else
@ -793,12 +797,10 @@ FreeClientNeverRetainResources(ClientPtr client)
#endif
*prev = this->next;
clientTable[client->index].elements--;
CallResourceStateCallback(ResourceStateFreeing, this);
elements = *eltptr;
(*resourceTypes[rtype & TypeMask].deleteFunc)(this->value, this->id);
free(this);
doFreeResource(this, FALSE);
if (*eltptr != elements)
prev = &resources[j]; /* prev may no longer be valid */
}
@ -841,7 +843,6 @@ FreeClientResources(ClientPtr client)
for (this = *head; this; this = *head)
{
RESTYPE rtype = this->type;
#ifdef XSERVER_DTRACE
XSERVER_RESOURCE_FREE(this->id, this->type,
this->value, TypeNameString(this->type));
@ -849,10 +850,7 @@ FreeClientResources(ClientPtr client)
*head = this->next;
clientTable[client->index].elements--;
CallResourceStateCallback(ResourceStateFreeing, this);
(*resourceTypes[rtype & TypeMask].deleteFunc)(this->value, this->id);
free(this);
doFreeResource(this, FALSE);
}
}
free(clientTable[client->index].resources);

View File

@ -11,7 +11,6 @@ AM_CFLAGS = \
@XLIB_CFLAGS@ \
@LIBDRM_CFLAGS@ \
@DRIPROTO_CFLAGS@ \
-DXFree86Server \
@GLX_DEFINES@ \
@GLX_ARCH_DEFINES@
@ -41,7 +40,6 @@ glapi_sources = \
indirect_table.c \
dispatch.h \
glapitable.h \
glapitemp.h \
glapi.c \
glapi.h \
glapioffsets.h \

View File

@ -22,46 +22,21 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* This file manages the OpenGL API dispatch layer.
* The dispatch table (struct _glapi_table) is basically just a list
* of function pointers.
* There are functions to set/get the current dispatch table for the
* current thread and to manage registration/dispatch of dynamically
* added extension functions.
* This file manages the OpenGL API dispatch layer. There are functions
* to set/get the current dispatch table for the current thread and to
* manage registration/dispatch of dynamically added extension functions.
*
* It's intended that this file and the other glapi*.[ch] files are
* flexible enough to be reused in several places: XFree86, DRI-
* based libGL.so, and perhaps the SGI SI.
*
* NOTE: 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
* 2002/06/28 - added _glapi_set_warning_func(), Mesa 4.1.
* 2002/10/01 - _glapi_get_proc_address() will now generate new entrypoints
* itself (using offset ~0). _glapi_add_entrypoint() can be
* called afterward and it'll fill in the correct dispatch
* offset. This allows DRI libGL to avoid probing for DRI
* drivers! No changes to the public glapi interface.
* This code was originally general enough to be shared with Mesa, but
* they diverged long ago, so this is now just enough support to make
* indirect GLX work.
*/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#include <X11/Xfuncproto.h>
#include <os.h>
#define PUBLIC _X_EXPORT
#else
#include "glheader.h"
#endif
#include <stdlib.h>
#include <string.h>
#ifdef DEBUG
@ -72,91 +47,10 @@
#include "glapioffsets.h"
#include "glapitable.h"
/***** BEGIN NO-OP DISPATCH *****/
static GLboolean WarnFlag = GL_FALSE;
static _glapi_warning_func warning_func;
#if defined(PTHREADS) || defined(GLX_USE_TLS)
static void init_glapi_relocs(void);
#endif
static _glapi_proc generate_entrypoint(GLuint functionOffset);
static void fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset);
/*
* Enable/disable printing of warning messages.
*/
PUBLIC void
_glapi_noop_enable_warnings(GLboolean enable)
{
WarnFlag = enable;
}
/*
* Register a callback function for reporting errors.
*/
PUBLIC void
_glapi_set_warning_func( _glapi_warning_func func )
{
warning_func = func;
}
static GLboolean
warn(void)
{
if ((WarnFlag || getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
&& warning_func) {
return GL_TRUE;
}
else {
return GL_FALSE;
}
}
#if defined(__GNUC__) && (__GNUC__ > 2)
#define possibly_unused __attribute((unused))
#else
#define possibly_unused
#endif
#define KEYWORD1 static
#define KEYWORD1_ALT static
#define KEYWORD2 GLAPIENTRY possibly_unused
#define NAME(func) NoOp##func
#define F NULL
#define DISPATCH(func, args, msg) \
if (warn()) { \
warning_func(NULL, "GL User Error: called without context: %s", #func); \
}
#define RETURN_DISPATCH(func, args, msg) \
if (warn()) { \
warning_func(NULL, "GL User Error: called without context: %s", #func); \
} \
return 0
#define DISPATCH_TABLE_NAME __glapi_noop_table
#define UNUSED_TABLE_NAME __unused_noop_functions
#define TABLE_ENTRY(name) (_glapi_proc) NoOp##name
static GLint NoOpUnused(void)
{
if (warn()) {
warning_func(NULL, "GL User Error: calling extension function without a current context\n");
}
return 0;
}
#include "glapitemp.h"
/***** END NO-OP DISPATCH *****/
/**
* \name Current dispatch and current context control variables
*
@ -185,8 +79,7 @@ static GLint NoOpUnused(void)
#if defined(GLX_USE_TLS)
PUBLIC TLS struct _glapi_table * _glapi_tls_Dispatch
__attribute__((tls_model("initial-exec")))
= (struct _glapi_table *) __glapi_noop_table;
__attribute__((tls_model("initial-exec"))) = NULL;
PUBLIC TLS void * _glapi_tls_Context
__attribute__((tls_model("initial-exec")));
@ -212,30 +105,12 @@ void FreeAllTSD(void)
#endif /* defined(THREADS) */
PUBLIC struct _glapi_table *_glapi_Dispatch =
(struct _glapi_table *) __glapi_noop_table;
PUBLIC struct _glapi_table *_glapi_Dispatch = NULL;
PUBLIC void *_glapi_Context = NULL;
#endif /* defined(GLX_USE_TLS) */
/*@}*/
/**
* strdup() is actually not a standard ANSI C or POSIX routine.
* Irix will not define it if ANSI mode is in effect.
*/
static char *
str_dup(const char *str)
{
char *copy;
copy = (char*) malloc(strlen(str) + 1);
if (!copy)
return NULL;
strcpy(copy, str);
return copy;
}
/*
* xserver's gl is not multithreaded, we promise.
*/
@ -252,7 +127,6 @@ _glapi_check_multithread(void)
PUBLIC void
_glapi_set_context(void *context)
{
(void) __unused_noop_functions; /* silence a warning */
#if defined(GLX_USE_TLS)
_glapi_tls_Context = context;
#elif defined(THREADS)
@ -284,8 +158,6 @@ _glapi_get_context(void)
/**
* Set the global or per-thread dispatch table pointer.
* If the dispatch parameter is NULL we'll plug in the no-op dispatch
* table (__glapi_noop_table).
*/
PUBLIC void
_glapi_set_dispatch(struct _glapi_table *dispatch)
@ -295,11 +167,6 @@ _glapi_set_dispatch(struct _glapi_table *dispatch)
pthread_once( & once_control, init_glapi_relocs );
#endif
if (!dispatch) {
/* use the no-op functions */
dispatch = (struct _glapi_table *) __glapi_noop_table;
}
#if defined(GLX_USE_TLS)
_glapi_tls_Dispatch = dispatch;
#elif defined(THREADS)
@ -344,9 +211,6 @@ _glapi_get_dispatch(void)
# endif
#endif
#if !defined(DISPATCH_FUNCTION_SIZE) && !defined(XFree86Server) && !defined(XGLServer)
# define NEED_FUNCTION_POINTER
#endif
/* The code in this file is auto-generated with Python */
#include "glprocs.h"
@ -385,46 +249,6 @@ get_static_proc_offset(const char *funcName)
}
#if !defined(XFree86Server) && !defined(XGLServer)
#ifdef USE_X86_ASM
#if defined( GLX_USE_TLS )
extern GLubyte gl_dispatch_functions_start[];
extern GLubyte gl_dispatch_functions_end[];
#else
extern const GLubyte gl_dispatch_functions_start[];
#endif
#endif /* USE_X86_ASM */
/**
* Return dispatch function address for the named static (built-in) function.
* Return NULL if function not found.
*/
static _glapi_proc
get_static_proc_address(const char *funcName)
{
const glprocs_table_t * const f = find_entry( funcName );
if (f) {
#if defined(DISPATCH_FUNCTION_SIZE) && defined(GLX_INDIRECT_RENDERING)
return (f->Address == NULL)
? (_glapi_proc) (gl_dispatch_functions_start
+ (DISPATCH_FUNCTION_SIZE * f->Offset))
: f->Address;
#elif defined(DISPATCH_FUNCTION_SIZE)
return (_glapi_proc) (gl_dispatch_functions_start
+ (DISPATCH_FUNCTION_SIZE * f->Offset));
#else
return f->Address;
#endif
}
else {
return NULL;
}
}
#endif /* !defined(XFree86Server) && !defined(XGLServer) */
/**********************************************************************
* Extension function management.
@ -454,7 +278,6 @@ struct _glapi_function {
*/
const char * name;
/**
* Text string that describes the types of the parameters passed to the
* named function. Parameter types are converted to characters using the
@ -466,164 +289,17 @@ struct _glapi_function {
*/
const char * parameter_signature;
/**
* Offset in the dispatch table where the pointer to the real function is
* located. If the driver has not requested that the named function be
* added to the dispatch table, this will have the value ~0.
*/
unsigned dispatch_offset;
/**
* Pointer to the dispatch stub for the named function.
*
* \todo
* The semantic of this field should be changed slightly. Currently, it
* is always expected to be non-\c NULL. However, it would be better to
* only allocate the entry-point stub when the application requests the
* function via \c glXGetProcAddress. This would save memory for all the
* functions that the driver exports but that the application never wants
* to call.
*/
_glapi_proc dispatch_stub;
};
static struct _glapi_function ExtEntryTable[MAX_EXTENSION_FUNCS];
static GLuint NumExtEntryPoints = 0;
#ifdef USE_SPARC_ASM
extern void __glapi_sparc_icache_flush(unsigned int *);
#endif
/**
* Generate a dispatch function (entrypoint) which jumps through
* the given slot number (offset) in the current dispatch table.
* We need assembly language in order to accomplish this.
*/
static _glapi_proc
generate_entrypoint(GLuint functionOffset)
{
#if defined(USE_X86_ASM)
/* 32 is chosen as something of a magic offset. For x86, the dispatch
* at offset 32 is the first one where the offset in the
* "jmp OFFSET*4(%eax)" can't be encoded in a single byte.
*/
const GLubyte * const template_func = gl_dispatch_functions_start
+ (DISPATCH_FUNCTION_SIZE * 32);
GLubyte * const code = (GLubyte *) malloc(DISPATCH_FUNCTION_SIZE);
if ( code != NULL ) {
(void) memcpy(code, template_func, DISPATCH_FUNCTION_SIZE);
fill_in_entrypoint_offset( (_glapi_proc) code, functionOffset );
}
return (_glapi_proc) code;
#elif defined(USE_SPARC_ASM)
#ifdef __arch64__
static const unsigned int insn_template[] = {
0x05000000, /* sethi %uhi(_glapi_Dispatch), %g2 */
0x03000000, /* sethi %hi(_glapi_Dispatch), %g1 */
0x8410a000, /* or %g2, %ulo(_glapi_Dispatch), %g2 */
0x82106000, /* or %g1, %lo(_glapi_Dispatch), %g1 */
0x8528b020, /* sllx %g2, 32, %g2 */
0xc2584002, /* ldx [%g1 + %g2], %g1 */
0x05000000, /* sethi %hi(8 * glapioffset), %g2 */
0x8410a000, /* or %g2, %lo(8 * glapioffset), %g2 */
0xc6584002, /* ldx [%g1 + %g2], %g3 */
0x81c0c000, /* jmpl %g3, %g0 */
0x01000000 /* nop */
};
#else
static const unsigned int insn_template[] = {
0x03000000, /* sethi %hi(_glapi_Dispatch), %g1 */
0xc2006000, /* ld [%g1 + %lo(_glapi_Dispatch)], %g1 */
0xc6006000, /* ld [%g1 + %lo(4*glapioffset)], %g3 */
0x81c0c000, /* jmpl %g3, %g0 */
0x01000000 /* nop */
};
#endif /* __arch64__ */
unsigned int *code = (unsigned int *) malloc(sizeof(insn_template));
unsigned long glapi_addr = (unsigned long) &_glapi_Dispatch;
if (code) {
memcpy(code, insn_template, sizeof(insn_template));
#ifdef __arch64__
code[0] |= (glapi_addr >> (32 + 10));
code[1] |= ((glapi_addr & 0xffffffff) >> 10);
__glapi_sparc_icache_flush(&code[0]);
code[2] |= ((glapi_addr >> 32) & ((1 << 10) - 1));
code[3] |= (glapi_addr & ((1 << 10) - 1));
__glapi_sparc_icache_flush(&code[2]);
code[6] |= ((functionOffset * 8) >> 10);
code[7] |= ((functionOffset * 8) & ((1 << 10) - 1));
__glapi_sparc_icache_flush(&code[6]);
#else
code[0] |= (glapi_addr >> 10);
code[1] |= (glapi_addr & ((1 << 10) - 1));
__glapi_sparc_icache_flush(&code[0]);
code[2] |= (functionOffset * 4);
__glapi_sparc_icache_flush(&code[2]);
#endif /* __arch64__ */
}
return (_glapi_proc) code;
#else
(void) functionOffset;
return NULL;
#endif /* USE_*_ASM */
}
/**
* This function inserts a new dispatch offset into the assembly language
* stub that was generated with the preceeding function.
*/
static void
fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset)
{
#if defined(USE_X86_ASM)
GLubyte * const code = (GLubyte *) entrypoint;
#if DISPATCH_FUNCTION_SIZE == 32
*((unsigned int *)(code + 11)) = 4 * offset;
*((unsigned int *)(code + 22)) = 4 * offset;
#elif DISPATCH_FUNCTION_SIZE == 16 && defined( GLX_USE_TLS )
*((unsigned int *)(code + 8)) = 4 * offset;
#elif DISPATCH_FUNCTION_SIZE == 16
*((unsigned int *)(code + 7)) = 4 * offset;
#else
# error Invalid DISPATCH_FUNCTION_SIZE!
#endif
#elif defined(USE_SPARC_ASM)
/* XXX this hasn't been tested! */
unsigned int *code = (unsigned int *) entrypoint;
#ifdef __arch64__
code[6] = 0x05000000; /* sethi %hi(8 * glapioffset), %g2 */
code[7] = 0x8410a000; /* or %g2, %lo(8 * glapioffset), %g2 */
code[6] |= ((offset * 8) >> 10);
code[7] |= ((offset * 8) & ((1 << 10) - 1));
__glapi_sparc_icache_flush(&code[6]);
#else /* __arch64__ */
code[2] = 0xc6006000; /* ld [%g1 + %lo(4*glapioffset)], %g3 */
code[2] |= (offset * 4);
__glapi_sparc_icache_flush(&code[2]);
#endif /* __arch64__ */
#else
/* an unimplemented architecture */
(void) entrypoint;
(void) offset;
#endif /* USE_*_ASM */
}
/**
* Generate new entrypoint
*
@ -643,16 +319,12 @@ add_function_name( const char * funcName )
struct _glapi_function * entry = NULL;
if (NumExtEntryPoints < MAX_EXTENSION_FUNCS) {
_glapi_proc entrypoint = generate_entrypoint(~0);
if (entrypoint != NULL) {
entry = & ExtEntryTable[NumExtEntryPoints];
entry = &ExtEntryTable[NumExtEntryPoints];
ExtEntryTable[NumExtEntryPoints].name = str_dup(funcName);
ExtEntryTable[NumExtEntryPoints].parameter_signature = NULL;
ExtEntryTable[NumExtEntryPoints].dispatch_offset = ~0;
ExtEntryTable[NumExtEntryPoints].dispatch_stub = entrypoint;
NumExtEntryPoints++;
}
ExtEntryTable[NumExtEntryPoints].name = strdup(funcName);
ExtEntryTable[NumExtEntryPoints].parameter_signature = NULL;
ExtEntryTable[NumExtEntryPoints].dispatch_offset = ~0;
NumExtEntryPoints++;
}
return entry;
@ -721,14 +393,13 @@ _glapi_add_dispatch( const char * const * function_names,
int new_offset;
(void) memset( is_static, 0, sizeof( is_static ) );
(void) memset( entry, 0, sizeof( entry ) );
(void) memset(is_static, 0, sizeof(is_static));
(void) memset(entry, 0, sizeof(entry));
for ( i = 0 ; function_names[i] != NULL ; i++ ) {
/* Do some trivial validation on the name of the function.
*/
for (i = 0 ; function_names[i] != NULL ; i++) {
/* Do some trivial validation on the name of the function. */
if (!function_names[i] || function_names[i][0] != 'g' || function_names[i][1] != 'l')
if (function_names[i][0] != 'g' || function_names[i][1] != 'l')
return GL_FALSE;
/* Determine if the named function already exists. If the function does
@ -742,7 +413,7 @@ _glapi_add_dispatch( const char * const * function_names,
* FIXME: the parameter signature for static functions?
*/
if ( (offset != ~0) && (new_offset != offset) ) {
if ((offset != ~0) && (new_offset != offset)) {
return -1;
}
@ -750,20 +421,17 @@ _glapi_add_dispatch( const char * const * function_names,
offset = new_offset;
}
for ( j = 0 ; j < NumExtEntryPoints ; j++ ) {
for (j = 0; j < NumExtEntryPoints; j++) {
if (strcmp(ExtEntryTable[j].name, function_names[i]) == 0) {
/* The offset may be ~0 if the function name was added by
* glXGetProcAddress but never filled in by the driver.
*/
if (ExtEntryTable[j].dispatch_offset != ~0) {
if (strcmp(real_sig, ExtEntryTable[j].parameter_signature)
!= 0) {
if (strcmp(real_sig, ExtEntryTable[j].parameter_signature) != 0)
return -1;
}
if ( (offset != ~0) && (ExtEntryTable[j].dispatch_offset != offset) ) {
if ((offset != ~0) && (ExtEntryTable[j].dispatch_offset != offset)) {
return -1;
}
@ -781,19 +449,15 @@ _glapi_add_dispatch( const char * const * function_names,
next_dynamic_offset++;
}
for ( i = 0 ; function_names[i] != NULL ; i++ ) {
if (! is_static[i] ) {
for (i = 0 ; function_names[i] != NULL ; i++) {
if (!is_static[i]) {
if (entry[i] == NULL) {
entry[i] = add_function_name( function_names[i] );
if (entry[i] == NULL) {
/* FIXME: Possible memory leak here.
*/
entry[i] = add_function_name(function_names[i]);
if (entry[i] == NULL)
return -1;
}
}
entry[i]->parameter_signature = str_dup(real_sig);
fill_in_entrypoint_offset(entry[i]->dispatch_stub, offset);
entry[i]->parameter_signature = strdup(real_sig);
entry[i]->dispatch_offset = offset;
}
}
@ -801,43 +465,15 @@ _glapi_add_dispatch( const char * const * function_names,
return offset;
}
/**
* Return pointer to the named function. If the function name isn't found
* in the name of static functions, try generating a new API entrypoint on
* the fly with assembly language.
/*
* glXGetProcAddress doesn't exist in the protocol, the drivers never call
* this themselves, and neither does the server. warn if it happens though.
*/
_glapi_proc
PUBLIC _glapi_proc
_glapi_get_proc_address(const char *funcName)
{
struct _glapi_function * entry;
GLuint i;
#ifdef MANGLE
if (funcName[0] != 'm' || funcName[1] != 'g' || funcName[2] != 'l')
return NULL;
#else
if (funcName[0] != 'g' || funcName[1] != 'l')
return NULL;
#endif
/* search extension functions first */
for (i = 0; i < NumExtEntryPoints; i++) {
if (strcmp(ExtEntryTable[i].name, funcName) == 0) {
return ExtEntryTable[i].dispatch_stub;
}
}
#if !defined( XFree86Server ) && !defined( XGLServer )
/* search static functions */
{
const _glapi_proc func = get_static_proc_address(funcName);
if (func)
return func;
}
#endif /* !defined( XFree86Server ) */
entry = add_function_name(funcName);
return (entry == NULL) ? NULL : entry->dispatch_stub;
ErrorF("_glapi_get_proc_address called!\n");
return NULL;
}
/**

View File

@ -106,12 +106,6 @@ extern struct _glapi_table *_glapi_Dispatch;
** GL API public functions
**/
extern void
_glapi_noop_enable_warnings(GLboolean enable);
extern void
_glapi_set_warning_func(_glapi_warning_func func);
extern void
_glapi_check_multithread(void);

File diff suppressed because it is too large Load Diff

View File

@ -136,9 +136,9 @@ validGlxContext(ClientPtr client, XID id, int access_mode,
{
*err = dixLookupResourceByType((pointer *) context, id,
__glXContextRes, client, access_mode);
if (*err != Success) {
if (*err != Success || (*context)->idExists == GL_FALSE) {
client->errorValue = id;
if (*err == BadValue)
if (*err == BadValue || *err == Success)
*err = __glXError(GLXBadContext);
return FALSE;
}
@ -369,6 +369,7 @@ int __glXDisp_CreateContextWithConfigSGIX(__GLXclientState *cl, GLbyte *pc)
return DoCreateContext(cl, req->context, req->shareList,
config, pGlxScreen, req->isDirect);
}
int __glXDisp_DestroyContext(__GLXclientState *cl, GLbyte *pc)
{
ClientPtr client = cl->client;
@ -382,77 +383,31 @@ int __glXDisp_DestroyContext(__GLXclientState *cl, GLbyte *pc)
&glxc, &err))
return err;
FreeResourceByType(req->context, __glXContextRes, FALSE);
glxc->idExists = GL_FALSE;
if (!glxc->isCurrent)
FreeResourceByType(req->context, __glXContextRes, FALSE);
return Success;
}
/*****************************************************************************/
/*
** For each client, the server keeps a table of all the contexts that are
** current for that client (each thread of a client may have its own current
** context). These routines add, change, and lookup contexts in the table.
*/
/*
** Add a current context, and return the tag that will be used to refer to it.
*/
static int AddCurrentContext(__GLXclientState *cl, __GLXcontext *glxc)
{
int i;
int num = cl->numCurrentContexts;
__GLXcontext **table = cl->currentContexts;
if (!glxc) return -1;
/*
** Try to find an empty slot and use it.
*/
for (i=0; i < num; i++) {
if (!table[i]) {
table[i] = glxc;
return i+1;
}
}
/*
** Didn't find a free slot, so we'll have to grow the table.
*/
if (!num) {
table = (__GLXcontext **) malloc(sizeof(__GLXcontext *));
} else {
table = (__GLXcontext **) realloc(table,
(num+1)*sizeof(__GLXcontext *));
}
table[num] = glxc;
cl->currentContexts = table;
cl->numCurrentContexts++;
return num+1;
}
/*
** Given a tag, change the current context for the corresponding entry.
*/
static void ChangeCurrentContext(__GLXclientState *cl, __GLXcontext *glxc,
GLXContextTag tag)
{
__GLXcontext **table = cl->currentContexts;
table[tag-1] = glxc;
}
/*
** For this implementation we have chosen to simply use the index of the
** context's entry in the table as the context tag. A tag must be greater
** than 0.
*/
* This will return "deleted" contexts, ie, where idExists is GL_FALSE.
* Contrast validGlxContext, which will not. We're cheating here and
* using the XID as the context tag, which is fine as long as we defer
* actually destroying the context until it's no longer referenced, and
* block clients from trying to MakeCurrent on contexts that are on the
* way to destruction. Notice that DoMakeCurrent calls validGlxContext
* for new contexts but __glXLookupContextByTag for previous contexts.
*/
__GLXcontext *__glXLookupContextByTag(__GLXclientState *cl, GLXContextTag tag)
{
int num = cl->numCurrentContexts;
__GLXcontext *ret;
if (tag < 1 || tag > num) {
return 0;
} else {
return cl->currentContexts[tag-1];
}
if (dixLookupResourceByType((void **)&ret, tag, __glXContextRes,
cl->client, DixUseAccess) == Success)
return ret;
return NULL;
}
/*****************************************************************************/
@ -466,7 +421,7 @@ static void StopUsingContext(__GLXcontext *glxc)
}
glxc->isCurrent = GL_FALSE;
if (!glxc->idExists) {
__glXFreeContext(glxc);
FreeResourceByType(glxc->id, __glXContextRes, FALSE);
}
}
}
@ -631,10 +586,10 @@ DoMakeCurrent(__GLXclientState *cl,
/*
** Flush the previous context if needed.
*/
if (__GLX_HAS_UNFLUSHED_CMDS(prevglxc)) {
if (prevglxc->hasUnflushedCommands) {
if (__glXForceCurrent(cl, tag, (int *)&error)) {
CALL_Flush( GET_DISPATCH(), () );
__GLX_NOTE_FLUSHED_CMDS(prevglxc);
prevglxc->hasUnflushedCommands = GL_FALSE;
} else {
return error;
}
@ -669,16 +624,11 @@ DoMakeCurrent(__GLXclientState *cl,
glxc->isCurrent = GL_TRUE;
}
if (prevglxc) {
ChangeCurrentContext(cl, glxc, tag);
StopUsingContext(prevglxc);
} else {
tag = AddCurrentContext(cl, glxc);
}
StopUsingContext(prevglxc);
if (glxc) {
StartUsingContext(cl, glxc);
reply.contextTag = tag;
reply.contextTag = glxc->id;
} else {
reply.contextTag = 0;
}
@ -905,7 +855,7 @@ int __glXDisp_CopyContext(__GLXclientState *cl, GLbyte *pc)
** in both streams are completed before the copy is executed.
*/
CALL_Finish( GET_DISPATCH(), () );
__GLX_NOTE_FLUSHED_CMDS(tagcx);
tagcx->hasUnflushedCommands = GL_FALSE;
} else {
return error;
}
@ -1616,7 +1566,7 @@ int __glXDisp_SwapBuffers(__GLXclientState *cl, GLbyte *pc)
** in both streams are completed before the swap is executed.
*/
CALL_Finish( GET_DISPATCH(), () );
__GLX_NOTE_FLUSHED_CMDS(glxc);
glxc->hasUnflushedCommands = GL_FALSE;
} else {
return error;
}
@ -1815,7 +1765,7 @@ int __glXDisp_CopySubBufferMESA(__GLXclientState *cl, GLbyte *pc)
** in both streams are completed before the swap is executed.
*/
CALL_Finish( GET_DISPATCH(), () );
__GLX_NOTE_FLUSHED_CMDS(glxc);
glxc->hasUnflushedCommands = GL_FALSE;
} else {
return error;
}
@ -2002,7 +1952,7 @@ int __glXDisp_Render(__GLXclientState *cl, GLbyte *pc)
left -= cmdlen;
commandsDone++;
}
__GLX_NOTE_UNFLUSHED_CMDS(glxc);
glxc->hasUnflushedCommands = GL_TRUE;
return Success;
}
@ -2199,7 +2149,7 @@ int __glXDisp_RenderLarge(__GLXclientState *cl, GLbyte *pc)
** Skip over the header and execute the command.
*/
(*proc)(cl->largeCmdBuf + __GLX_RENDER_LARGE_HDR_SIZE);
__GLX_NOTE_UNFLUSHED_CMDS(glxc);
glxc->hasUnflushedCommands = GL_TRUE;
/*
** Reset for the next RenderLarge series.

View File

@ -53,8 +53,6 @@ struct __GLXcontext {
int (*copy) (__GLXcontext *dst,
__GLXcontext *src,
unsigned long mask);
int (*forceCurrent) (__GLXcontext *context);
Bool (*wait) (__GLXcontext *context,
__GLXclientState *cl,
int *error);

View File

@ -335,19 +335,6 @@ __glXDRIcontextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc,
src->driContext, mask);
}
static int
__glXDRIcontextForceCurrent(__GLXcontext *baseContext)
{
__GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
__GLXDRIdrawable *draw = (__GLXDRIdrawable *) baseContext->drawPriv;
__GLXDRIdrawable *read = (__GLXDRIdrawable *) baseContext->readPriv;
__GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
return (*screen->core->bindContext)(context->driContext,
draw->driDrawable,
read->driDrawable);
}
static void
glxFillAlphaChannel (CARD32 *pixels, CARD32 rowstride, int width, int height)
{
@ -641,7 +628,6 @@ __glXDRIscreenCreateContext(__GLXscreen *baseScreen,
context->base.makeCurrent = __glXDRIcontextMakeCurrent;
context->base.loseCurrent = __glXDRIcontextLoseCurrent;
context->base.copy = __glXDRIcontextCopy;
context->base.forceCurrent = __glXDRIcontextForceCurrent;
context->base.textureFromPixmap = &__glXDRItextureFromPixmap;
/* Find the requested X visual */

View File

@ -283,19 +283,6 @@ __glXDRIcontextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc,
src->driContext, mask);
}
static int
__glXDRIcontextForceCurrent(__GLXcontext *baseContext)
{
__GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
__GLXDRIdrawable *draw = (__GLXDRIdrawable *) baseContext->drawPriv;
__GLXDRIdrawable *read = (__GLXDRIdrawable *) baseContext->readPriv;
__GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
return (*screen->core->bindContext)(context->driContext,
draw->driDrawable,
read->driDrawable);
}
static Bool
__glXDRIcontextWait(__GLXcontext *baseContext,
__GLXclientState *cl, int *error)
@ -411,7 +398,6 @@ __glXDRIscreenCreateContext(__GLXscreen *baseScreen,
context->base.makeCurrent = __glXDRIcontextMakeCurrent;
context->base.loseCurrent = __glXDRIcontextLoseCurrent;
context->base.copy = __glXDRIcontextCopy;
context->base.forceCurrent = __glXDRIcontextForceCurrent;
context->base.textureFromPixmap = &__glXDRItextureFromPixmap;
context->base.wait = __glXDRIcontextWait;

View File

@ -174,19 +174,6 @@ __glXDRIcontextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc,
src->driContext, mask);
}
static int
__glXDRIcontextForceCurrent(__GLXcontext *baseContext)
{
__GLXDRIcontext *context = (__GLXDRIcontext *) baseContext;
__GLXDRIdrawable *draw = (__GLXDRIdrawable *) baseContext->drawPriv;
__GLXDRIdrawable *read = (__GLXDRIdrawable *) baseContext->readPriv;
__GLXDRIscreen *screen = (__GLXDRIscreen *) context->base.pGlxScreen;
return (*screen->core->bindContext)(context->driContext,
draw->driDrawable,
read->driDrawable);
}
#ifdef __DRI_TEX_BUFFER
static int
@ -289,7 +276,6 @@ __glXDRIscreenCreateContext(__GLXscreen *baseScreen,
context->base.makeCurrent = __glXDRIcontextMakeCurrent;
context->base.loseCurrent = __glXDRIcontextLoseCurrent;
context->base.copy = __glXDRIcontextCopy;
context->base.forceCurrent = __glXDRIcontextForceCurrent;
context->base.textureFromPixmap = &__glXDRItextureFromPixmap;
context->driContext =

View File

@ -50,7 +50,6 @@
** from the server's perspective.
*/
__GLXcontext *__glXLastContext;
__GLXcontext *__glXContextList;
/*
** X resources.
@ -66,11 +65,6 @@ xGLXSingleReply __glXReply;
static DevPrivateKeyRec glxClientPrivateKeyRec;
#define glxClientPrivateKey (&glxClientPrivateKeyRec)
/*
** Client that called into GLX dispatch.
*/
ClientPtr __pGlxClient;
/*
** Forward declarations.
*/
@ -138,34 +132,15 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
for (c = glxAllContexts; c; c = next) {
next = c->next;
if (c->isCurrent && (c->drawPriv == glxPriv || c->readPriv == glxPriv)) {
int i;
(*c->loseCurrent)(c);
c->isCurrent = GL_FALSE;
if (c == __glXLastContext)
__glXFlushContextCache();
for (i = 1; i < currentMaxClients; i++) {
if (clients[i]) {
__GLXclientState *cl = glxGetClient(clients[i]);
if (cl->inUse) {
int j;
for (j = 0; j < cl->numCurrentContexts; j++) {
if (cl->currentContexts[j] == c)
cl->currentContexts[j] = NULL;
}
}
}
}
}
if (c->drawPriv == glxPriv)
c->drawPriv = NULL;
if (c->readPriv == glxPriv)
c->readPriv = NULL;
if (!c->idExists && !c->isCurrent)
__glXFreeContext(c);
}
glxPriv->destroy(glxPriv);
@ -283,8 +258,6 @@ glxClientCallback (CallbackListPtr *list,
NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
ClientPtr pClient = clientinfo->client;
__GLXclientState *cl = glxGetClient(pClient);
__GLXcontext *cx;
int i;
switch (pClient->clientState) {
case ClientStateRunning:
@ -298,18 +271,8 @@ glxClientCallback (CallbackListPtr *list,
break;
case ClientStateGone:
for (i = 0; i < cl->numCurrentContexts; i++) {
cx = cl->currentContexts[i];
if (cx) {
cx->isCurrent = GL_FALSE;
if (!cx->idExists)
__glXFreeContext(cx);
}
}
free(cl->returnBuf);
free(cl->largeCmdBuf);
free(cl->currentContexts);
free(cl->GLClientextensions);
break;
@ -422,7 +385,7 @@ __GLXcontext *__glXForceCurrent(__GLXclientState *cl, GLXContextTag tag,
** See if the context tag is legal; it is managed by the extension,
** so if it's invalid, we have an implementation error.
*/
cx = (__GLXcontext *) __glXLookupContextByTag(cl, tag);
cx = __glXLookupContextByTag(cl, tag);
if (!cx) {
cl->client->errorValue = tag;
*error = __glXError(GLXBadContextTag);
@ -451,7 +414,7 @@ __GLXcontext *__glXForceCurrent(__GLXclientState *cl, GLXContextTag tag,
/* Make this context the current one for the GL. */
if (!cx->isDirect) {
if (!(*cx->forceCurrent)(cx)) {
if (!(*cx->makeCurrent)(cx)) {
/* Bind failed, and set the error code. Bummer */
cl->client->errorValue = cx->id;
*error = __glXError(GLXBadContextState);
@ -571,15 +534,12 @@ static int __glXDispatch(ClientPtr client)
/*
** Use the opcode to index into the procedure table.
*/
proc = (__GLXdispatchSingleProcPtr) __glXGetProtocolDecodeFunction(& Single_dispatch_info,
opcode,
client->swapped);
proc = __glXGetProtocolDecodeFunction(& Single_dispatch_info, opcode,
client->swapped);
if (proc != NULL) {
GLboolean rendering = opcode <= X_GLXRenderLarge;
__glXleaveServer(rendering);
__pGlxClient = client;
retval = (*proc)(cl, (GLbyte *) stuff);
__glXenterServer(rendering);

View File

@ -96,18 +96,8 @@ void __glXScreenInitVisuals(__GLXscreen *screen);
extern __GLXcontext *__glXLastContext;
extern __GLXcontext *__glXForceCurrent(__GLXclientState*, GLXContextTag, int*);
extern ClientPtr __pGlxClient;
int __glXError(int error);
/*
** Macros to set, unset, and retrieve the flag that says whether a context
** has unflushed commands.
*/
#define __GLX_NOTE_UNFLUSHED_CMDS(glxc) glxc->hasUnflushedCommands = GL_TRUE
#define __GLX_NOTE_FLUSHED_CMDS(glxc) glxc->hasUnflushedCommands = GL_FALSE
#define __GLX_HAS_UNFLUSHED_CMDS(glxc) (glxc->hasUnflushedCommands)
/************************************************************************/
typedef struct __GLXprovider __GLXprovider;
@ -158,13 +148,6 @@ struct __GLXclientStateRec {
GLbyte *largeCmdBuf;
GLint largeCmdBufSize;
/*
** Keep a list of all the contexts that are current for this client's
** threads.
*/
__GLXcontext **currentContexts;
GLint numCurrentContexts;
/* Back pointer to X client record */
ClientPtr client;

View File

@ -72,7 +72,7 @@ int __glXDisp_FeedbackBuffer(__GLXclientState *cl, GLbyte *pc)
cx->feedbackBufSize = size;
}
CALL_FeedbackBuffer( GET_DISPATCH(), (size, type, cx->feedbackBuf) );
__GLX_NOTE_UNFLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_TRUE;
return Success;
}
@ -100,7 +100,7 @@ int __glXDisp_SelectBuffer(__GLXclientState *cl, GLbyte *pc)
cx->selectBufSize = size;
}
CALL_SelectBuffer( GET_DISPATCH(), (size, cx->selectBuf) );
__GLX_NOTE_UNFLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_TRUE;
return Success;
}
@ -213,7 +213,7 @@ int __glXDisp_Flush(__GLXclientState *cl, GLbyte *pc)
}
CALL_Flush( GET_DISPATCH(), () );
__GLX_NOTE_FLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_FALSE;
return Success;
}
@ -230,7 +230,7 @@ int __glXDisp_Finish(__GLXclientState *cl, GLbyte *pc)
/* Do a local glFinish */
CALL_Finish( GET_DISPATCH(), () );
__GLX_NOTE_FLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_FALSE;
/* Send empty reply packet to indicate finish is finished */
client = cl->client;

View File

@ -72,7 +72,7 @@ int __glXDispSwap_FeedbackBuffer(__GLXclientState *cl, GLbyte *pc)
cx->feedbackBufSize = size;
}
CALL_FeedbackBuffer( GET_DISPATCH(), (size, type, cx->feedbackBuf) );
__GLX_NOTE_UNFLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_TRUE;
return Success;
}
@ -103,7 +103,7 @@ int __glXDispSwap_SelectBuffer(__GLXclientState *cl, GLbyte *pc)
cx->selectBufSize = size;
}
CALL_SelectBuffer( GET_DISPATCH(), (size, cx->selectBuf) );
__GLX_NOTE_UNFLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_TRUE;
return Success;
}
@ -229,7 +229,7 @@ int __glXDispSwap_Flush(__GLXclientState *cl, GLbyte *pc)
}
CALL_Flush( GET_DISPATCH(), () );
__GLX_NOTE_FLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_FALSE;
return Success;
}
@ -248,7 +248,7 @@ int __glXDispSwap_Finish(__GLXclientState *cl, GLbyte *pc)
/* Do a local glFinish */
CALL_Finish( GET_DISPATCH(), () );
__GLX_NOTE_FLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_FALSE;
/* Send empty reply packet to indicate finish is finished */
client = cl->client;

View File

@ -91,7 +91,7 @@ int __glXDisp_ReadPixels(__GLXclientState *cl, GLbyte *pc)
__GLX_SEND_HEADER();
__GLX_SEND_VOID_ARRAY(compsize);
}
__GLX_NOTE_FLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_FALSE;
return Success;
}

View File

@ -102,7 +102,7 @@ int __glXDispSwap_ReadPixels(__GLXclientState *cl, GLbyte *pc)
__GLX_SEND_HEADER();
__GLX_SEND_VOID_ARRAY(compsize);
}
__GLX_NOTE_FLUSHED_CMDS(cx);
cx->hasUnflushedCommands = GL_FALSE;
return Success;
}

View File

@ -92,14 +92,6 @@ extern GLint __glXNumActiveScreens;
extern __GLXcontext *__glXLastContext;
extern __GLXcontext *__glXForceCurrent(__GLXclientState*, GLXContextTag, int*);
/*
** Macros to set, unset, and retrieve the flag that says whether a context
** has unflushed commands.
*/
#define __GLX_NOTE_UNFLUSHED_CMDS(glxc) glxc->hasUnflushedCommands = GL_TRUE
#define __GLX_NOTE_FLUSHED_CMDS(glxc) glxc->hasUnflushedCommands = GL_FALSE
#define __GLX_HAS_UNFLUSHED_CMDS(glxc) (glxc->hasUnflushedCommands)
/************************************************************************/
typedef struct {

View File

@ -1755,6 +1755,7 @@ xf86RandR12EnterVT (int screen_index, int flags)
XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
rrScrPrivPtr rp = rrGetScrPriv(pScreen);
Bool ret;
int i;
if (randrp->orig_EnterVT) {
pScrn->EnterVT = randrp->orig_EnterVT;
@ -1766,7 +1767,6 @@ xf86RandR12EnterVT (int screen_index, int flags)
}
/* reload gamma */
int i;
for (i = 0; i < rp->numCrtcs; i++)
xf86RandR12CrtcSetGamma(pScreen, rp->crtcs[i]);

View File

@ -189,7 +189,7 @@ xf86parsePointerSection (void)
if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) {
Error (ZAXISMAPPING_MSG, NULL);
}
if (asprintf(&s, "%ul %ul", val1, val.num) == -1)
if (asprintf(&s, "%lu %u", val1, val.num) == -1)
s = NULL;
break;
case XAXIS:

View File

@ -174,7 +174,6 @@ static __GLXdrawable * __glXAquaScreenCreateDrawable(ClientPtr client, __GLXscre
static void __glXAquaContextDestroy(__GLXcontext *baseContext);
static int __glXAquaContextMakeCurrent(__GLXcontext *baseContext);
static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext);
static int __glXAquaContextForceCurrent(__GLXcontext *baseContext);
static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask);
static CGLPixelFormatObj makeFormat(__GLXconfig *conf);
@ -235,7 +234,6 @@ __glXAquaScreenCreateContext(__GLXscreen *screen,
context->base.makeCurrent = __glXAquaContextMakeCurrent;
context->base.loseCurrent = __glXAquaContextLoseCurrent;
context->base.copy = __glXAquaContextCopy;
context->base.forceCurrent = __glXAquaContextForceCurrent;
/*FIXME verify that the context->base is fully initialized. */
context->pixelFormat = makeFormat(conf);
@ -458,19 +456,6 @@ static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, un
return gl_err == 0;
}
static int __glXAquaContextForceCurrent(__GLXcontext *baseContext)
{
CGLError gl_err;
__GLXAquaContext *context = (__GLXAquaContext *) baseContext;
GLAQUA_DEBUG_MSG("glAquaForceCurrent (ctx %p)\n", context->ctx);
gl_err = CGLSetCurrentContext(context->ctx);
if (gl_err != 0)
ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
return gl_err == 0;
}
/* Drawing surface notification callbacks */
static GLboolean __glXAquaDrawableSwapBuffers(ClientPtr client, __GLXdrawable *base) {
CGLError err;
@ -681,17 +666,8 @@ GLuint __glFloorLog2(GLuint val)
return c;
}
void warn_func(void * p1, char *format, ...) {
va_list v;
va_start(v, format);
vfprintf(stderr, format, v);
va_end(v);
}
static void setup_dispatch_table(void) {
struct _glapi_table *disp=_glapi_get_dispatch();
_glapi_set_warning_func((_glapi_warning_func)warn_func);
_glapi_noop_enable_warnings(TRUE);
/* to update:
* for f in $(grep 'define SET_' ../../../glx/dispatch.h | cut -f2 -d' ' | cut -f1 -d\( | sort -u); do grep -q $f indirect.c || echo $f ; done | grep -v by_offset | sed 's:SET_\(.*\)$:SET_\1(disp, gl\1)\;:' | pbcopy

View File

@ -859,7 +859,7 @@ glxWinDrawableDestroy(__GLXdrawable *base)
// on the next context change)
// (GLX core considers it an error when we try to select a new current context if the old one
// has unflushed commands, but the window has disappeared..)
__GLX_NOTE_FLUSHED_CMDS(__glXLastContext);
__glXLastContext->hasUnflushedCommands = FALSE;
__glXLastContext = NULL;
}
@ -1480,13 +1480,6 @@ glxWinContextCopy(__GLXcontext *dst_base, __GLXcontext *src_base, unsigned long
return ret;
}
static int
glxWinContextForceCurrent(__GLXcontext *base)
{
/* wglMakeCurrent always flushes the previous context, so this is equivalent to glxWinContextMakeCurrent */
return glxWinContextMakeCurrent(base);
}
static void
glxWinContextDestroy(__GLXcontext *base)
{
@ -1541,7 +1534,6 @@ glxWinCreateContext(__GLXscreen *screen,
context->base.makeCurrent = glxWinContextMakeCurrent;
context->base.loseCurrent = glxWinContextLoseCurrent;
context->base.copy = glxWinContextCopy;
context->base.forceCurrent = glxWinContextForceCurrent;
context->base.textureFromPixmap = &glxWinTextureFromPixmap;
context->base.config = modes;
context->base.pGlxScreen = screen;

View File

@ -1773,8 +1773,6 @@ CompositeTriStrip (CARD8 op,
int npoints,
xPointFixed *points)
{
ScreenPtr pScreen = pDst->pDrawable->pScreen;
PictureScreenPtr ps = GetPictureScreen(pScreen);
xTriangle *tris, *tri;
int ntri;
@ -1804,7 +1802,6 @@ CompositeTriFan (CARD8 op,
int npoints,
xPointFixed *points)
{
ScreenPtr pScreen = pDst->pDrawable->pScreen;
xTriangle *tris, *tri;
xPointFixed *first;
int ntri;