From 711fc10ea3d5aa369b47999d737793157a791929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 8 Mar 2025 00:28:35 -0500 Subject: [PATCH] glapi: merge all shared-glapi source files into one .c file Reviewed-by: Adam Jackson Part-of: --- src/mapi/entry.h | 37 ----- src/mapi/shared-glapi/core.c | 218 ++++++++++++++++++++++++++++-- src/mapi/shared-glapi/glapi.c | 112 --------------- src/mapi/shared-glapi/meson.build | 12 +- src/mapi/shared-glapi/stub.c | 125 ----------------- src/mapi/shared-glapi/stub.h | 51 ------- src/mapi/shared-glapi/table.c | 81 ----------- src/mapi/shared-glapi/table.h | 42 ------ src/mapi/u_current.c | 112 --------------- 9 files changed, 207 insertions(+), 583 deletions(-) delete mode 100644 src/mapi/entry.h delete mode 100644 src/mapi/shared-glapi/glapi.c delete mode 100644 src/mapi/shared-glapi/stub.c delete mode 100644 src/mapi/shared-glapi/stub.h delete mode 100644 src/mapi/shared-glapi/table.c delete mode 100644 src/mapi/shared-glapi/table.h delete mode 100644 src/mapi/u_current.c diff --git a/src/mapi/entry.h b/src/mapi/entry.h deleted file mode 100644 index 24725e383b7..00000000000 --- a/src/mapi/entry.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 2010 LunarG Inc. - * - * 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 - * 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. - * - * Authors: - * Chia-I Wu - */ - -#ifndef _ENTRY_H_ -#define _ENTRY_H_ - -void -entry_patch_public(void); - -_glapi_proc -entry_get_public(int slot); - -#endif /* _ENTRY_H_ */ diff --git a/src/mapi/shared-glapi/core.c b/src/mapi/shared-glapi/core.c index 54f33cea5ea..a1040de53fe 100644 --- a/src/mapi/shared-glapi/core.c +++ b/src/mapi/shared-glapi/core.c @@ -6,8 +6,47 @@ */ #include "glapi/glapi.h" -#include "stub.h" -#include "entry.h" + +struct mapi_stub { + size_t name_offset; + int slot; +}; + +static bool log_noop; +static _glapi_nop_handler_proc nop_handler = NULL; + +static void check_debug_env(void) +{ + const char *debug = getenv("MESA_DEBUG"); + if (!debug) + debug = getenv("LIBGL_DEBUG"); + if (debug && strcmp(debug, "silent") != 0) + log_noop = true; +} + +static void +noop_warn(const char *name) +{ + if (nop_handler) { + nop_handler(name); + } else { + static once_flag flag = ONCE_FLAG_INIT; + call_once(&flag, check_debug_env); + + if (log_noop) + fprintf(stderr, "%s is no-op\n", name); + } +} + +static int +noop_generic(void) +{ + noop_warn("function"); + return 0; +} + +#define MAPI_TMP_NOOP_ARRAY +#define MAPI_TMP_PUBLIC_STUBS /* REALLY_INITIAL_EXEC implies __GLIBC__ */ #if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC) @@ -24,7 +63,7 @@ extern char x86_entry_end[] HIDDEN; static inline _glapi_proc entry_generate_or_patch(int, char *, size_t); -void +static void entry_patch_public(void) { #ifndef GLX_X86_READONLY_TEXT @@ -36,7 +75,7 @@ entry_patch_public(void) #endif } -_glapi_proc +static _glapi_proc entry_get_public(int slot) { return (_glapi_proc) (x86_entry_start + slot * X86_ENTRY_SIZE); @@ -78,7 +117,7 @@ entry_generate_or_patch(int slot, char *code, size_t size) #include -void +static void entry_patch_public(void) { } @@ -86,7 +125,7 @@ entry_patch_public(void) extern char x86_64_entry_start[] HIDDEN; -_glapi_proc +static _glapi_proc entry_get_public(int slot) { return (_glapi_proc) (x86_64_entry_start + slot * 32); @@ -99,7 +138,7 @@ entry_get_public(int slot) #include -void +static void entry_patch_public(void) { } @@ -107,7 +146,7 @@ entry_patch_public(void) extern char ppc64le_entry_start[] HIDDEN; -_glapi_proc +static _glapi_proc entry_get_public(int slot) { return (_glapi_proc) (ppc64le_entry_start + slot * PPC64LE_ENTRY_SIZE); @@ -120,15 +159,170 @@ entry_get_public(int slot) #define MAPI_TMP_PUBLIC_ENTRIES #include "shared_glapi_mapi_tmp.h" -_glapi_proc +static void +entry_patch_public(void) +{ +} + +static _glapi_proc entry_get_public(int slot) { - /* pubic_entries are defined by MAPI_TMP_PUBLIC_ENTRIES */ return public_entries[slot]; } +#endif /* asm */ + +/** + * \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 _mesa_glapi_Dispatch and \c _glapi_Context are used for this + * purpose. + * + * In multi threaded case, The TLS variables \c _mesa_glapi_tls_Dispatch and + * \c _mesa_glapi_tls_Context are used. Having \c _mesa_glapi_Dispatch + * be hardcoded to \c NULL maintains binary compatability between TLS enabled + * loaders and non-TLS DRI drivers. When \c _mesa_glapi_Dispatch + * are \c NULL, the thread state data \c ContextTSD are used. + */ + +__THREAD_INITIAL_EXEC struct _glapi_table *_mesa_glapi_tls_Dispatch + = (struct _glapi_table *)table_noop_array; +__THREAD_INITIAL_EXEC void *_mesa_glapi_tls_Context; +const struct _glapi_table *_mesa_glapi_Dispatch; + +static int +stub_compare(const void *key, const void *elem) +{ + const char *name = (const char *)key; + const struct mapi_stub *stub = (const struct mapi_stub *)elem; + + return strcmp(name, &public_string_pool[stub->name_offset]); +} + +/** + * Return size of dispatch table struct as number of functions (or + * slots). + */ +unsigned +_mesa_glapi_get_dispatch_table_size(void) +{ + return _gloffset_COUNT; +} + +static const struct mapi_stub * +_glapi_get_stub(const char *name) +{ + if (!name || name[0] != 'g' || name[1] != 'l') + return NULL; + + return (const struct mapi_stub *) + bsearch(name + 2, public_stubs, ARRAY_SIZE(public_stubs), + sizeof(public_stubs[0]), stub_compare); +} + +/** + * Return offset of entrypoint for named function within dispatch table. + */ +int +_mesa_glapi_get_proc_offset(const char *funcName) +{ + const struct mapi_stub *stub = _glapi_get_stub(funcName); + return stub ? stub->slot : -1; +} + +/** + * 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. + */ +_glapi_proc +_mesa_glapi_get_proc_address(const char *funcName) +{ + const struct mapi_stub *stub = _glapi_get_stub(funcName); + return stub ? entry_get_public(stub->slot) : NULL; +} + +/** + * Return the name of the function at the given dispatch offset. + * This is only intended for debugging. + */ +const char * +_glapi_get_proc_name(unsigned offset) +{ + for (unsigned i = 0; i < ARRAY_SIZE(public_stubs); ++i) { + if (public_stubs[i].slot == offset) + return &public_string_pool[public_stubs[i].name_offset]; + } + + return NULL; +} + +/** Return pointer to new dispatch table filled with no-op functions */ +struct _glapi_table * +_glapi_new_nop_table(void) +{ + struct _glapi_table *table = malloc(_gloffset_COUNT * sizeof(_glapi_proc)); + + if (table) + memcpy(table, table_noop_array, _gloffset_COUNT * sizeof(_glapi_proc)); + return table; +} + +void +_glapi_set_nop_handler(_glapi_nop_handler_proc func) +{ + nop_handler = func; +} + +/** + * 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. + */ +void +_mesa_glapi_set_context(void *ptr) +{ + _mesa_glapi_tls_Context = ptr; +} + +/** + * 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. + */ +void * +_mesa_glapi_get_context(void) +{ + return _mesa_glapi_tls_Context; +} + +/** + * 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). + */ +void +_mesa_glapi_set_dispatch(struct _glapi_table *tbl) +{ + static once_flag flag = ONCE_FLAG_INIT; + call_once(&flag, entry_patch_public); + + _mesa_glapi_tls_Dispatch = + tbl ? tbl : (struct _glapi_table *)table_noop_array; +} + +/** + * Return pointer to current dispatch table for calling thread. + */ +struct _glapi_table * +_mesa_glapi_get_dispatch(void) +{ + return _mesa_glapi_tls_Dispatch; +} + #if defined(_WIN32) && defined(_WINDOWS_) #error "Should not include here" #endif - -#endif /* asm */ diff --git a/src/mapi/shared-glapi/glapi.c b/src/mapi/shared-glapi/glapi.c deleted file mode 100644 index 0d7d69b0579..00000000000 --- a/src/mapi/shared-glapi/glapi.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. - * Copyright (C) 2010 LunarG Inc. - * - * 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 - * 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. - * - * Authors: - * Chia-I Wu - */ - -#include -#include -#include "glapi/glapi.h" -#include "table.h" -#include "stub.h" - -/* - * _mesa_glapi_Dispatch, - * _mesa_glapi_tls_Dispatch, _mesa_glapi_tls_Context, - * _mesa_glapi_set_dispatch, and _mesa_glapi_get_dispatch - * are defined in u_current.c. - */ - -/** - * Return size of dispatch table struct as number of functions (or - * slots). - */ -unsigned int -_mesa_glapi_get_dispatch_table_size(void) -{ - return _gloffset_COUNT; -} - -static const struct mapi_stub * -_glapi_get_stub(const char *name) -{ - if (!name || name[0] != 'g' || name[1] != 'l') - return NULL; - name += 2; - - return stub_find_public(name); -} - -/** - * Return offset of entrypoint for named function within dispatch table. - */ -int -_mesa_glapi_get_proc_offset(const char *funcName) -{ - const struct mapi_stub *stub = _glapi_get_stub(funcName); - return (stub) ? stub_get_slot(stub) : -1; -} - -/** - * 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. - */ -_glapi_proc -_mesa_glapi_get_proc_address(const char *funcName) -{ - const struct mapi_stub *stub = _glapi_get_stub(funcName); - return (stub) ? (_glapi_proc) stub_get_addr(stub) : NULL; -} - -/** - * Return the name of the function at the given dispatch offset. - * This is only intended for debugging. - */ -const char * -_glapi_get_proc_name(unsigned int offset) -{ - const struct mapi_stub *stub = stub_find_by_slot(offset); - return stub ? stub_get_name(stub) : NULL; -} - -/** Return pointer to new dispatch table filled with no-op functions */ -struct _glapi_table * -_glapi_new_nop_table(void) -{ - struct _glapi_table *table; - - table = malloc(_gloffset_COUNT * sizeof(_glapi_proc)); - if (table) { - memcpy(table, table_noop_array, _gloffset_COUNT * sizeof(_glapi_proc)); - } - return table; -} - -void -_glapi_set_nop_handler(_glapi_nop_handler_proc func) -{ - table_set_noop_handler(func); -} diff --git a/src/mapi/shared-glapi/meson.build b/src/mapi/shared-glapi/meson.build index 857a8563f2f..3af5f304e6f 100644 --- a/src/mapi/shared-glapi/meson.build +++ b/src/mapi/shared-glapi/meson.build @@ -1,16 +1,6 @@ # Copyright © 2017 Intel Corporation # SPDX-License-Identifier: MIT -files_shared_glapi = files( - 'core.c', - '../u_current.c', - 'glapi.c', - 'stub.c', - 'stub.h', - 'table.c', - 'table.h', -) - shared_glapi_mapi_tmp_h = custom_target( 'shared_glapi_mapi_tmp.h', input : ['../mapi_abi.py', '../glapi/gen/gl_and_es_API.xml'], @@ -22,7 +12,7 @@ shared_glapi_mapi_tmp_h = custom_target( libglapi = static_library( 'glapi', - [files_shared_glapi, shared_glapi_mapi_tmp_h], + ['core.c', shared_glapi_mapi_tmp_h], c_args : [ c_msvc_compat_args, '-DMAPI_MODE_SHARED_GLAPI', diff --git a/src/mapi/shared-glapi/stub.c b/src/mapi/shared-glapi/stub.c deleted file mode 100644 index c5b27d8508e..00000000000 --- a/src/mapi/shared-glapi/stub.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 2010 LunarG Inc. - * - * 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 - * 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. - * - * Authors: - * Chia-I Wu - */ - -#include -#include -#include -#include "c11/threads.h" - -#include "util/macros.h" -#include "util/simple_mtx.h" -#include "glapi/glapi.h" -#include "stub.h" -#include "table.h" -#include "entry.h" - - -struct mapi_stub { - size_t name_offset; - int slot; -}; - -/* define public_string_pool and public_stubs */ -#define MAPI_TMP_PUBLIC_STUBS -#include "shared_glapi_mapi_tmp.h" - -void -stub_init_once(void) -{ - static once_flag flag = ONCE_FLAG_INIT; - call_once(&flag, entry_patch_public); -} - -static int -stub_compare(const void *key, const void *elem) -{ - const char *name = (const char *) key; - const struct mapi_stub *stub = (const struct mapi_stub *) elem; - const char *stub_name; - - stub_name = &public_string_pool[stub->name_offset]; - - return strcmp(name, stub_name); -} - -/** - * Return the public stub with the given name. - */ -const struct mapi_stub * -stub_find_public(const char *name) -{ - return (const struct mapi_stub *) bsearch(name, public_stubs, - ARRAY_SIZE(public_stubs), sizeof(public_stubs[0]), stub_compare); -} - - -static const struct mapi_stub * -search_table_by_slot(const struct mapi_stub *table, size_t num_entries, - int slot) -{ - size_t i; - for (i = 0; i < num_entries; ++i) { - if (table[i].slot == slot) - return &table[i]; - } - return NULL; -} - -const struct mapi_stub * -stub_find_by_slot(int slot) -{ - const struct mapi_stub *stub = - search_table_by_slot(public_stubs, ARRAY_SIZE(public_stubs), slot); - return stub; -} - -/** - * Return the name of a stub. - */ -const char * -stub_get_name(const struct mapi_stub *stub) -{ - return &public_string_pool[stub->name_offset]; -} - -/** - * Return the slot of a stub. - */ -int -stub_get_slot(const struct mapi_stub *stub) -{ - return stub->slot; -} - -/** - * Return the address of a stub. - */ -_glapi_proc -stub_get_addr(const struct mapi_stub *stub) -{ - return entry_get_public(stub->slot); -} diff --git a/src/mapi/shared-glapi/stub.h b/src/mapi/shared-glapi/stub.h deleted file mode 100644 index 081abac797c..00000000000 --- a/src/mapi/shared-glapi/stub.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 2010 LunarG Inc. - * - * 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 - * 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. - * - * Authors: - * Chia-I Wu - */ - -#ifndef _STUB_H_ -#define _STUB_H_ - -struct mapi_stub; - -void -stub_init_once(void); - -const struct mapi_stub * -stub_find_public(const char *name); - -const struct mapi_stub * -stub_find_by_slot(int slot); - -const char * -stub_get_name(const struct mapi_stub *stub); - -int -stub_get_slot(const struct mapi_stub *stub); - -_glapi_proc -stub_get_addr(const struct mapi_stub *stub); - -#endif /* _STUB_H_ */ diff --git a/src/mapi/shared-glapi/table.c b/src/mapi/shared-glapi/table.c deleted file mode 100644 index 2c773c1ab2a..00000000000 --- a/src/mapi/shared-glapi/table.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 2010 LunarG Inc. - * - * 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 - * 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. - * - * Authors: - * Chia-I Wu - */ - -#include -#include -#include -#include - -#include "c11/threads.h" -#include "glapi/glapi.h" -#include "table.h" - -static nop_handler_proc nop_handler = NULL; - -void -table_set_noop_handler(nop_handler_proc func) -{ - nop_handler = func; -} - -static bool log_noop; - -static void check_debug_env(void) -{ - const char *debug = getenv("MESA_DEBUG"); - if (!debug) - debug = getenv("LIBGL_DEBUG"); - if (debug && strcmp(debug, "silent") != 0) - log_noop = true; -} - -static void -noop_warn(const char *name) -{ - if (nop_handler) { - nop_handler(name); - } - else { - static once_flag flag = ONCE_FLAG_INIT; - call_once(&flag, check_debug_env); - - if (log_noop) - fprintf(stderr, "%s is no-op\n", name); - } -} - -static int -noop_generic(void) -{ - noop_warn("function"); - return 0; -} - -/* define noop_array */ -#define MAPI_TMP_DEFINES -#define MAPI_TMP_NOOP_ARRAY -#include "shared_glapi_mapi_tmp.h" diff --git a/src/mapi/shared-glapi/table.h b/src/mapi/shared-glapi/table.h deleted file mode 100644 index d5185565f00..00000000000 --- a/src/mapi/shared-glapi/table.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 2010 LunarG Inc. - * - * 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 - * 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. - * - * Authors: - * Chia-I Wu - */ - -#ifndef _TABLE_H_ -#define _TABLE_H_ - -#include "shared_glapi_mapi_tmp.h" - -struct _glapi_table; - -extern const _glapi_proc table_noop_array[]; - -typedef void (*nop_handler_proc)(const char *name); - -void -table_set_noop_handler(nop_handler_proc func); - -#endif /* _TABLE_H_ */ diff --git a/src/mapi/u_current.c b/src/mapi/u_current.c deleted file mode 100644 index 65e9e1b46ee..00000000000 --- a/src/mapi/u_current.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. - * - * 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 - * 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. - */ - - -/* - * 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. - */ - -#include "c11/threads.h" -#include "util/u_thread.h" -#include "glapi/glapi.h" - -#include "table.h" -#include "stub.h" - -/** - * \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 _mesa_glapi_Dispatch and \c _glapi_Context are used for this - * purpose. - * - * In multi threaded case, The TLS variables \c _mesa_glapi_tls_Dispatch and - * \c _mesa_glapi_tls_Context are used. Having \c _mesa_glapi_Dispatch - * be hardcoded to \c NULL maintains binary compatability between TLS enabled - * loaders and non-TLS DRI drivers. When \c _mesa_glapi_Dispatch - * are \c NULL, the thread state data \c ContextTSD are used. - */ -/*@{*/ - -__THREAD_INITIAL_EXEC struct _glapi_table *_mesa_glapi_tls_Dispatch - = (struct _glapi_table *) table_noop_array; - -__THREAD_INITIAL_EXEC void *_mesa_glapi_tls_Context; - -const struct _glapi_table *_mesa_glapi_Dispatch; - -/*@}*/ - -/** - * 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. - */ -void -_mesa_glapi_set_context(void *ptr) -{ - _mesa_glapi_tls_Context = ptr; -} - -/** - * 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. - */ -void * -_mesa_glapi_get_context(void) -{ - return _mesa_glapi_tls_Context; -} - -/** - * 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). - */ -void -_mesa_glapi_set_dispatch(struct _glapi_table *tbl) -{ - stub_init_once(); - - if (!tbl) - tbl = (struct _glapi_table *) table_noop_array; - - _mesa_glapi_tls_Dispatch = tbl; -} - -/** - * Return pointer to current dispatch table for calling thread. - */ -struct _glapi_table * -_mesa_glapi_get_dispatch(void) -{ - return _mesa_glapi_tls_Dispatch; -}