1999-11-11 01:22:25 +00:00
|
|
|
/*
|
|
|
|
* Mesa 3-D graphics library
|
|
|
|
*
|
2008-06-17 20:23:32 +01:00
|
|
|
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
|
1999-11-11 01:22:25 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
2013-04-21 21:46:48 +01:00
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
1999-11-11 01:22:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
1999-11-25 18:17:04 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
2000-01-28 19:03:33 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2002-06-29 20:48:15 +01:00
|
|
|
* NOTE: There are no dependencies on Mesa in this code.
|
2001-01-23 23:35:47 +00:00
|
|
|
*
|
|
|
|
* 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-29 20:48:15 +01:00
|
|
|
* 2002/06/28 - added _glapi_set_warning_func(), Mesa 4.1.
|
2002-10-02 02:51:44 +01:00
|
|
|
* 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.
|
1999-11-25 18:17:04 +00:00
|
|
|
*/
|
|
|
|
|
2015-03-05 02:17:57 +00:00
|
|
|
#include "c11/threads.h"
|
2021-03-05 23:49:17 +00:00
|
|
|
#include "util/u_thread.h"
|
2010-04-23 09:06:26 +01:00
|
|
|
#include "u_current.h"
|
1999-11-25 18:17:04 +00:00
|
|
|
|
2010-12-10 19:27:54 +00:00
|
|
|
#ifndef MAPI_MODE_UTIL
|
2010-04-23 09:06:26 +01:00
|
|
|
|
|
|
|
#include "table.h"
|
|
|
|
#include "stub.h"
|
1999-11-25 18:17:04 +00:00
|
|
|
|
2008-05-21 16:59:23 +01:00
|
|
|
#else
|
|
|
|
|
2010-04-23 09:06:26 +01:00
|
|
|
extern void init_glapi_relocs_once(void);
|
|
|
|
extern void (*__glapi_noop_table[])(void);
|
1999-12-16 17:31:59 +00:00
|
|
|
|
2010-04-23 09:06:26 +01:00
|
|
|
#define table_noop_array __glapi_noop_table
|
|
|
|
#define stub_init_once() init_glapi_relocs_once()
|
2001-03-28 18:19:58 +01:00
|
|
|
|
2010-04-23 09:06:26 +01:00
|
|
|
#endif
|
2001-03-28 18:19:58 +01:00
|
|
|
|
2005-08-11 00:54:15 +01:00
|
|
|
/**
|
|
|
|
* \name Current dispatch and current context control variables
|
|
|
|
*
|
|
|
|
* Depending on whether or not multithreading is support, and the type of
|
|
|
|
* support available, several variables are used to store the current context
|
|
|
|
* pointer and the current dispatch table pointer. In the non-threaded case,
|
|
|
|
* the variables \c _glapi_Dispatch and \c _glapi_Context are used for this
|
|
|
|
* purpose.
|
|
|
|
*
|
2009-08-25 16:37:43 +01:00
|
|
|
* In the "normal" threaded case, the variables \c _glapi_Dispatch and
|
|
|
|
* \c _glapi_Context will be \c NULL if an application is detected as being
|
|
|
|
* multithreaded. Single-threaded applications will use \c _glapi_Dispatch
|
|
|
|
* and \c _glapi_Context just like the case without any threading support.
|
|
|
|
* When \c _glapi_Dispatch and \c _glapi_Context are \c NULL, the thread state
|
|
|
|
* data \c _gl_DispatchTSD and \c ContextTSD are used. Drivers and the
|
|
|
|
* static dispatch functions access these variables via \c _glapi_get_dispatch
|
|
|
|
* and \c _glapi_get_context.
|
2005-08-11 00:54:15 +01:00
|
|
|
*
|
2022-06-21 05:33:30 +01:00
|
|
|
*
|
2005-08-11 00:54:15 +01:00
|
|
|
* In the TLS case, the variables \c _glapi_Dispatch and \c _glapi_Context are
|
|
|
|
* hardcoded to \c NULL. Instead the TLS variables \c _glapi_tls_Dispatch and
|
2009-08-25 16:37:43 +01:00
|
|
|
* \c _glapi_tls_Context are used. Having \c _glapi_Dispatch and
|
|
|
|
* \c _glapi_Context be hardcoded to \c NULL maintains binary compatability
|
|
|
|
* between TLS enabled loaders and non-TLS DRI drivers.
|
2005-08-11 00:54:15 +01:00
|
|
|
*/
|
|
|
|
/*@{*/
|
2005-04-13 21:59:15 +01:00
|
|
|
|
2021-05-21 21:23:07 +01:00
|
|
|
__THREAD_INITIAL_EXEC struct _glapi_table *u_current_table
|
2017-04-13 18:23:50 +01:00
|
|
|
= (struct _glapi_table *) table_noop_array;
|
2005-04-13 21:59:15 +01:00
|
|
|
|
2021-05-21 21:23:07 +01:00
|
|
|
__THREAD_INITIAL_EXEC void *u_current_context;
|
2005-04-13 21:59:15 +01:00
|
|
|
|
2005-08-11 00:54:15 +01:00
|
|
|
/*@}*/
|
2001-01-23 23:35:47 +00:00
|
|
|
|
2004-11-27 03:51:11 +00:00
|
|
|
/**
|
1999-12-17 14:51:28 +00:00
|
|
|
* Set the current context pointer for this thread.
|
|
|
|
* The context pointer is an opaque type which should be cast to
|
|
|
|
* void from the real context pointer type.
|
|
|
|
*/
|
2010-04-23 09:06:26 +01:00
|
|
|
void
|
2014-03-05 14:47:41 +00:00
|
|
|
u_current_set_context(const void *ptr)
|
1999-12-17 14:51:28 +00:00
|
|
|
{
|
2014-03-05 14:47:41 +00:00
|
|
|
u_current_context = (void *) ptr;
|
1999-12-17 14:51:28 +00:00
|
|
|
}
|
|
|
|
|
2004-11-27 03:51:11 +00:00
|
|
|
/**
|
1999-12-17 14:51:28 +00:00
|
|
|
* Get the current context pointer for this thread.
|
|
|
|
* The context pointer is an opaque type which should be cast from
|
|
|
|
* void to the real context pointer type.
|
|
|
|
*/
|
2010-04-23 09:06:26 +01:00
|
|
|
void *
|
2014-03-05 14:47:41 +00:00
|
|
|
u_current_get_context_internal(void)
|
1999-12-17 14:51:28 +00:00
|
|
|
{
|
2014-03-05 14:47:41 +00:00
|
|
|
return u_current_context;
|
1999-12-17 14:51:28 +00:00
|
|
|
}
|
|
|
|
|
2004-11-27 03:51:11 +00:00
|
|
|
/**
|
1999-11-19 22:33:50 +00:00
|
|
|
* Set the global or per-thread dispatch table pointer.
|
2006-03-15 20:56:22 +00:00
|
|
|
* If the dispatch parameter is NULL we'll plug in the no-op dispatch
|
|
|
|
* table (__glapi_noop_table).
|
1999-11-19 22:33:50 +00:00
|
|
|
*/
|
2010-04-23 09:06:26 +01:00
|
|
|
void
|
2017-04-13 18:23:50 +01:00
|
|
|
u_current_set_table(const struct _glapi_table *tbl)
|
1999-11-11 01:22:25 +00:00
|
|
|
{
|
2010-04-23 09:06:26 +01:00
|
|
|
stub_init_once();
|
2005-04-13 21:59:15 +01:00
|
|
|
|
2010-08-21 05:10:02 +01:00
|
|
|
if (!tbl)
|
2017-04-13 18:23:50 +01:00
|
|
|
tbl = (const struct _glapi_table *) table_noop_array;
|
1999-11-11 01:22:25 +00:00
|
|
|
|
2017-04-13 18:23:50 +01:00
|
|
|
u_current_table = (struct _glapi_table *) tbl;
|
1999-11-11 01:22:25 +00:00
|
|
|
}
|
|
|
|
|
2004-11-27 03:51:11 +00:00
|
|
|
/**
|
1999-12-16 17:31:59 +00:00
|
|
|
* Return pointer to current dispatch table for calling thread.
|
1999-11-19 22:33:50 +00:00
|
|
|
*/
|
2017-04-13 18:23:50 +01:00
|
|
|
struct _glapi_table *
|
2014-03-05 14:47:41 +00:00
|
|
|
u_current_get_table_internal(void)
|
1999-11-11 01:22:25 +00:00
|
|
|
{
|
2010-12-10 09:14:04 +00:00
|
|
|
return u_current_table;
|
2000-09-05 21:17:37 +01:00
|
|
|
}
|