mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-23 04:40:09 +01:00
glapi: merge all shared-glapi source files into one .c file
Reviewed-by: Adam Jackson <ajax@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34002>
This commit is contained in:
parent
fae087770a
commit
711fc10ea3
9 changed files with 207 additions and 583 deletions
|
|
@ -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 <olv@lunarg.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _ENTRY_H_
|
|
||||||
#define _ENTRY_H_
|
|
||||||
|
|
||||||
void
|
|
||||||
entry_patch_public(void);
|
|
||||||
|
|
||||||
_glapi_proc
|
|
||||||
entry_get_public(int slot);
|
|
||||||
|
|
||||||
#endif /* _ENTRY_H_ */
|
|
||||||
|
|
@ -6,8 +6,47 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "glapi/glapi.h"
|
#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__ */
|
/* REALLY_INITIAL_EXEC implies __GLIBC__ */
|
||||||
#if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC)
|
#if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC)
|
||||||
|
|
@ -24,7 +63,7 @@ extern char x86_entry_end[] HIDDEN;
|
||||||
static inline _glapi_proc
|
static inline _glapi_proc
|
||||||
entry_generate_or_patch(int, char *, size_t);
|
entry_generate_or_patch(int, char *, size_t);
|
||||||
|
|
||||||
void
|
static void
|
||||||
entry_patch_public(void)
|
entry_patch_public(void)
|
||||||
{
|
{
|
||||||
#ifndef GLX_X86_READONLY_TEXT
|
#ifndef GLX_X86_READONLY_TEXT
|
||||||
|
|
@ -36,7 +75,7 @@ entry_patch_public(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
_glapi_proc
|
static _glapi_proc
|
||||||
entry_get_public(int slot)
|
entry_get_public(int slot)
|
||||||
{
|
{
|
||||||
return (_glapi_proc) (x86_entry_start + slot * X86_ENTRY_SIZE);
|
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 <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void
|
static void
|
||||||
entry_patch_public(void)
|
entry_patch_public(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +125,7 @@ entry_patch_public(void)
|
||||||
extern char
|
extern char
|
||||||
x86_64_entry_start[] HIDDEN;
|
x86_64_entry_start[] HIDDEN;
|
||||||
|
|
||||||
_glapi_proc
|
static _glapi_proc
|
||||||
entry_get_public(int slot)
|
entry_get_public(int slot)
|
||||||
{
|
{
|
||||||
return (_glapi_proc) (x86_64_entry_start + slot * 32);
|
return (_glapi_proc) (x86_64_entry_start + slot * 32);
|
||||||
|
|
@ -99,7 +138,7 @@ entry_get_public(int slot)
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void
|
static void
|
||||||
entry_patch_public(void)
|
entry_patch_public(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +146,7 @@ entry_patch_public(void)
|
||||||
extern char
|
extern char
|
||||||
ppc64le_entry_start[] HIDDEN;
|
ppc64le_entry_start[] HIDDEN;
|
||||||
|
|
||||||
_glapi_proc
|
static _glapi_proc
|
||||||
entry_get_public(int slot)
|
entry_get_public(int slot)
|
||||||
{
|
{
|
||||||
return (_glapi_proc) (ppc64le_entry_start + slot * PPC64LE_ENTRY_SIZE);
|
return (_glapi_proc) (ppc64le_entry_start + slot * PPC64LE_ENTRY_SIZE);
|
||||||
|
|
@ -120,15 +159,170 @@ entry_get_public(int slot)
|
||||||
#define MAPI_TMP_PUBLIC_ENTRIES
|
#define MAPI_TMP_PUBLIC_ENTRIES
|
||||||
#include "shared_glapi_mapi_tmp.h"
|
#include "shared_glapi_mapi_tmp.h"
|
||||||
|
|
||||||
_glapi_proc
|
static void
|
||||||
|
entry_patch_public(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static _glapi_proc
|
||||||
entry_get_public(int slot)
|
entry_get_public(int slot)
|
||||||
{
|
{
|
||||||
/* pubic_entries are defined by MAPI_TMP_PUBLIC_ENTRIES */
|
|
||||||
return public_entries[slot];
|
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_)
|
#if defined(_WIN32) && defined(_WINDOWS_)
|
||||||
#error "Should not include <windows.h> here"
|
#error "Should not include <windows.h> here"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* asm */
|
|
||||||
|
|
|
||||||
|
|
@ -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 <olv@lunarg.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +1,6 @@
|
||||||
# Copyright © 2017 Intel Corporation
|
# Copyright © 2017 Intel Corporation
|
||||||
# SPDX-License-Identifier: MIT
|
# 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 = custom_target(
|
||||||
'shared_glapi_mapi_tmp.h',
|
'shared_glapi_mapi_tmp.h',
|
||||||
input : ['../mapi_abi.py', '../glapi/gen/gl_and_es_API.xml'],
|
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(
|
libglapi = static_library(
|
||||||
'glapi',
|
'glapi',
|
||||||
[files_shared_glapi, shared_glapi_mapi_tmp_h],
|
['core.c', shared_glapi_mapi_tmp_h],
|
||||||
c_args : [
|
c_args : [
|
||||||
c_msvc_compat_args,
|
c_msvc_compat_args,
|
||||||
'-DMAPI_MODE_SHARED_GLAPI',
|
'-DMAPI_MODE_SHARED_GLAPI',
|
||||||
|
|
|
||||||
|
|
@ -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 <olv@lunarg.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#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);
|
|
||||||
}
|
|
||||||
|
|
@ -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 <olv@lunarg.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_ */
|
|
||||||
|
|
@ -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 <olv@lunarg.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#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"
|
|
||||||
|
|
@ -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 <olv@lunarg.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#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_ */
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue