diff options
author | Chia-I Wu <olv@lunarg.com> | 2010-12-17 00:24:27 +0800 |
---|---|---|
committer | Chia-I Wu <olv@lunarg.com> | 2011-01-20 17:15:50 +0800 |
commit | 97185bf2654f7e72d8bfcc216f905492655d4c77 (patch) | |
tree | 92a3f7e0ef7faa683270dd91df34390c0cc0b838 /src/mapi/mapi/mapi_abi.py | |
parent | 96c52d16c1716b8974b5421342f53f36cb80c10f (diff) |
mapi: Add support for bridge mode.
In bridge mode, mapi no longer implements glapi.h. It becomes a user of
glapi.h. Imagine an app that uses both libGL.so and libGLESv2.so.
There will be two copies of glapi in the app's memory. It is possible
that _glapi_get_dispatch does not return what _glapi_set_dispatch set,
if they access different copies of the global variables. The solution
to this situation to build either one of the libraries as a bridge to
the other. Or build both libraries as bridges to another shared
glapi library.
Diffstat (limited to 'src/mapi/mapi/mapi_abi.py')
-rw-r--r-- | src/mapi/mapi/mapi_abi.py | 93 |
1 files changed, 76 insertions, 17 deletions
diff --git a/src/mapi/mapi/mapi_abi.py b/src/mapi/mapi/mapi_abi.py index 47be8c5b4a..cb9fc0ef84 100644 --- a/src/mapi/mapi/mapi_abi.py +++ b/src/mapi/mapi/mapi_abi.py @@ -295,6 +295,7 @@ class ABIPrinter(object): self.indent = ' ' * 3 self.noop_warn = 'noop_warn' self.noop_generic = 'noop_generic' + self.current_get = 'entry_current_get' self.api_defines = [] self.api_headers = ['"KHR/khrplatform.h"'] @@ -307,7 +308,8 @@ class ABIPrinter(object): self.lib_need_table_size = True self.lib_need_noop_array = True self.lib_need_stubs = True - self.lib_need_entries = True + self.lib_need_all_entries = True + self.lib_need_non_hidden_entries = False def c_notice(self): return '/* This file is automatically generated by mapi_abi.py. Do not modify. */' @@ -337,11 +339,7 @@ class ABIPrinter(object): def c_mapi_table(self): """Return defines of the dispatch table size.""" - num_static_entries = 0 - for ent in self.entries: - if not ent.alias: - num_static_entries += 1 - + num_static_entries = self.entries[-1].slot + 1 return ('#define MAPI_TABLE_NUM_STATIC %d\n' + \ '#define MAPI_TABLE_NUM_DYNAMIC %d') % ( num_static_entries, ABI_NUM_DYNAMIC_ENTRIES) @@ -418,10 +416,13 @@ class ABIPrinter(object): return "\n".join(decls) - def c_public_dispatches(self, prefix): + def c_public_dispatches(self, prefix, no_hidden): """Return the public dispatch functions.""" dispatches = [] for ent in self.entries: + if ent.hidden and no_hidden: + continue + if not self.need_entry_point(ent): continue @@ -434,7 +435,8 @@ class ABIPrinter(object): if ent.ret: ret = 'return ' stmt1 = self.indent - stmt1 += 'const struct mapi_table *_tbl = u_current_get();' + stmt1 += 'const struct mapi_table *_tbl = %s();' % ( + self.current_get) stmt2 = self.indent stmt2 += 'mapi_func _func = ((const mapi_func *) _tbl)[%d];' % ( ent.slot) @@ -524,11 +526,13 @@ class ABIPrinter(object): pre = self.indent + '(mapi_func) ' return pre + (',\n' + pre).join(entries) - def c_asm_gcc(self, prefix): + def c_asm_gcc(self, prefix, no_hidden): asm = [] - asm.append('__asm__(') for ent in self.entries: + if ent.hidden and no_hidden: + continue + if not self.need_entry_point(ent): continue @@ -540,7 +544,7 @@ class ABIPrinter(object): if ent.hidden: asm.append('".hidden "%s"\\n"' % (name)) - if ent.alias: + if ent.alias and not (ent.alias.hidden and no_hidden): asm.append('".globl "%s"\\n"' % (name)) asm.append('".set "%s", "%s"\\n"' % (name, self._c_function(ent.alias, prefix, True, True))) @@ -551,7 +555,6 @@ class ABIPrinter(object): if ent.handcode: asm.append('#endif') asm.append('') - asm.append(');') return "\n".join(asm) @@ -611,10 +614,10 @@ class ABIPrinter(object): print '#undef MAPI_TMP_PUBLIC_STUBS' print '#endif /* MAPI_TMP_PUBLIC_STUBS */' - if self.lib_need_entries: + if self.lib_need_all_entries: print print '#ifdef MAPI_TMP_PUBLIC_ENTRIES' - print self.c_public_dispatches(self.prefix_lib) + print self.c_public_dispatches(self.prefix_lib, False) print print 'static const mapi_func public_entries[] = {' print self.c_public_initializer(self.prefix_lib) @@ -624,10 +627,35 @@ class ABIPrinter(object): print print '#ifdef MAPI_TMP_STUB_ASM_GCC' - print self.c_asm_gcc(self.prefix_lib) + print '__asm__(' + print self.c_asm_gcc(self.prefix_lib, False) + print ');' print '#undef MAPI_TMP_STUB_ASM_GCC' print '#endif /* MAPI_TMP_STUB_ASM_GCC */' + if self.lib_need_non_hidden_entries: + all_hidden = True + for ent in self.entries: + if not ent.hidden: + all_hidden = False + break + if not all_hidden: + print + print '#ifdef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN' + print self.c_public_dispatches(self.prefix_lib, True) + print + print '/* does not need public_entries */' + print '#undef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN' + print '#endif /* MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN */' + + print + print '#ifdef MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN' + print '__asm__(' + print self.c_asm_gcc(self.prefix_lib, True) + print ');' + print '#undef MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN' + print '#endif /* MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN */' + def output_for_app(self): print self.c_notice() print @@ -657,6 +685,12 @@ class GLAPIPrinter(ABIPrinter): self.api_entry = 'APIENTRY' self.api_attrs = '' + self.lib_need_table_size = False + self.lib_need_noop_array = False + self.lib_need_stubs = False + self.lib_need_all_entries = False + self.lib_need_non_hidden_entries = True + self.prefix_lib = 'GLAPI_PREFIX' self.prefix_app = '_mesa_' self.prefix_noop = 'noop' @@ -1161,6 +1195,30 @@ typedef int GLclampx; return header +class SharedGLAPIPrinter(GLAPIPrinter): + """Shared GLAPI API Printer""" + + def __init__(self, entries): + super(SharedGLAPIPrinter, self).__init__(entries, []) + + self.lib_need_table_size = True + self.lib_need_noop_array = True + self.lib_need_stubs = True + self.lib_need_all_entries = True + self.lib_need_non_hidden_entries = False + + self.prefix_lib = 'shared' + self.prefix_warn = 'gl' + + def _get_c_header(self): + header = """#ifndef _GLAPI_TMP_H_ +#define _GLAPI_TMP_H_ +typedef int GLfixed; +typedef int GLclampx; +#endif /* _GLAPI_TMP_H_ */""" + + return header + class VGAPIPrinter(ABIPrinter): """OpenVG API Printer""" @@ -1179,7 +1237,7 @@ class VGAPIPrinter(ABIPrinter): self.prefix_warn = 'vg' def parse_args(): - printers = ['glapi', 'es1api', 'es2api', 'vgapi'] + printers = ['vgapi', 'glapi', 'es1api', 'es2api', 'shared-glapi'] modes = ['lib', 'app'] parser = OptionParser(usage='usage: %prog [options] <filename>') @@ -1201,7 +1259,8 @@ def main(): 'vgapi': VGAPIPrinter, 'glapi': GLAPIPrinter, 'es1api': ES1APIPrinter, - 'es2api': ES2APIPrinter + 'es2api': ES2APIPrinter, + 'shared-glapi': SharedGLAPIPrinter, } filename, options = parse_args() |