mesa: Add core support for EXT_multisampled_render_to_texture{,2}
[mesa.git] / src / mapi / mapi_abi.py
1
2 # Mesa 3-D graphics library
3 #
4 # Copyright (C) 2010 LunarG Inc.
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 # DEALINGS IN THE SOFTWARE.
23 #
24 # Authors:
25 # Chia-I Wu <olv@lunarg.com>
26
27 from __future__ import print_function
28
29 import sys
30 # make it possible to import glapi
31 import os
32 GLAPI = os.path.join(".", os.path.dirname(sys.argv[0]), "glapi/gen")
33 sys.path.append(GLAPI)
34
35 from operator import attrgetter
36 import re
37 from optparse import OptionParser
38 import gl_XML
39 import glX_XML
40
41
42 # number of dynamic entries
43 ABI_NUM_DYNAMIC_ENTRIES = 256
44
45 class ABIEntry(object):
46 """Represent an ABI entry."""
47
48 _match_c_param = re.compile(
49 '^(?P<type>[\w\s*]+?)(?P<name>\w+)(\[(?P<array>\d+)\])?$')
50
51 def __init__(self, cols, attrs, xml_data = None):
52 self._parse(cols)
53
54 self.slot = attrs['slot']
55 self.hidden = attrs['hidden']
56 self.alias = attrs['alias']
57 self.handcode = attrs['handcode']
58 self.xml_data = xml_data
59
60 def c_prototype(self):
61 return '%s %s(%s)' % (self.c_return(), self.name, self.c_params())
62
63 def c_return(self):
64 ret = self.ret
65 if not ret:
66 ret = 'void'
67
68 return ret
69
70 def c_params(self):
71 """Return the parameter list used in the entry prototype."""
72 c_params = []
73 for t, n, a in self.params:
74 sep = '' if t.endswith('*') else ' '
75 arr = '[%d]' % a if a else ''
76 c_params.append(t + sep + n + arr)
77 if not c_params:
78 c_params.append('void')
79
80 return ", ".join(c_params)
81
82 def c_args(self):
83 """Return the argument list used in the entry invocation."""
84 c_args = []
85 for t, n, a in self.params:
86 c_args.append(n)
87
88 return ", ".join(c_args)
89
90 def _parse(self, cols):
91 ret = cols.pop(0)
92 if ret == 'void':
93 ret = None
94
95 name = cols.pop(0)
96
97 params = []
98 if not cols:
99 raise Exception(cols)
100 elif len(cols) == 1 and cols[0] == 'void':
101 pass
102 else:
103 for val in cols:
104 params.append(self._parse_param(val))
105
106 self.ret = ret
107 self.name = name
108 self.params = params
109
110 def _parse_param(self, c_param):
111 m = self._match_c_param.match(c_param)
112 if not m:
113 raise Exception('unrecognized param ' + c_param)
114
115 c_type = m.group('type').strip()
116 c_name = m.group('name')
117 c_array = m.group('array')
118 c_array = int(c_array) if c_array else 0
119
120 return (c_type, c_name, c_array)
121
122 def __str__(self):
123 return self.c_prototype()
124
125 def __lt__(self, other):
126 # compare slot, alias, and then name
127 if self.slot == other.slot:
128 if not self.alias:
129 return True
130 elif not other.alias:
131 return False
132
133 return self.name < other.name
134
135 return self.slot < other.slot
136
137
138 def abi_parse_xml(xml):
139 """Parse a GLAPI XML file for ABI entries."""
140 api = gl_XML.parse_GL_API(xml, glX_XML.glx_item_factory())
141
142 entry_dict = {}
143 for func in api.functionIterateByOffset():
144 # make sure func.name appear first
145 entry_points = func.entry_points[:]
146 entry_points.remove(func.name)
147 entry_points.insert(0, func.name)
148
149 for name in entry_points:
150 attrs = {
151 'slot': func.offset,
152 'hidden': not func.is_static_entry_point(name),
153 'alias': None if name == func.name else func.name,
154 'handcode': bool(func.has_different_protocol(name)),
155 }
156
157 # post-process attrs
158 if attrs['alias']:
159 try:
160 alias = entry_dict[attrs['alias']]
161 except KeyError:
162 raise Exception('failed to alias %s' % attrs['alias'])
163 if alias.alias:
164 raise Exception('recursive alias %s' % ent.name)
165 attrs['alias'] = alias
166 if attrs['handcode']:
167 attrs['handcode'] = func.static_glx_name(name)
168 else:
169 attrs['handcode'] = None
170
171 if name in entry_dict:
172 raise Exception('%s is duplicated' % (name))
173
174 cols = []
175 cols.append(func.return_type)
176 cols.append(name)
177 params = func.get_parameter_string(name)
178 cols.extend([p.strip() for p in params.split(',')])
179
180 ent = ABIEntry(cols, attrs, func)
181 entry_dict[ent.name] = ent
182
183 entries = sorted(entry_dict.values())
184
185 return entries
186
187 def abi_parse_line(line):
188 cols = [col.strip() for col in line.split(',')]
189
190 attrs = {
191 'slot': -1,
192 'hidden': False,
193 'alias': None,
194 'handcode': None,
195 }
196
197 # extract attributes from the first column
198 vals = cols[0].split(':')
199 while len(vals) > 1:
200 val = vals.pop(0)
201 if val.startswith('slot='):
202 attrs['slot'] = int(val[5:])
203 elif val == 'hidden':
204 attrs['hidden'] = True
205 elif val.startswith('alias='):
206 attrs['alias'] = val[6:]
207 elif val.startswith('handcode='):
208 attrs['handcode'] = val[9:]
209 elif not val:
210 pass
211 else:
212 raise Exception('unknown attribute %s' % val)
213 cols[0] = vals[0]
214
215 return (attrs, cols)
216
217 def abi_parse(filename):
218 """Parse a CSV file for ABI entries."""
219 fp = open(filename) if filename != '-' else sys.stdin
220 lines = [line.strip() for line in fp.readlines()
221 if not line.startswith('#') and line.strip()]
222
223 entry_dict = {}
224 next_slot = 0
225 for line in lines:
226 attrs, cols = abi_parse_line(line)
227
228 # post-process attributes
229 if attrs['alias']:
230 try:
231 alias = entry_dict[attrs['alias']]
232 except KeyError:
233 raise Exception('failed to alias %s' % attrs['alias'])
234 if alias.alias:
235 raise Exception('recursive alias %s' % ent.name)
236 slot = alias.slot
237 attrs['alias'] = alias
238 else:
239 slot = next_slot
240 next_slot += 1
241
242 if attrs['slot'] < 0:
243 attrs['slot'] = slot
244 elif attrs['slot'] != slot:
245 raise Exception('invalid slot in %s' % (line))
246
247 ent = ABIEntry(cols, attrs)
248 if ent.name in entry_dict:
249 raise Exception('%s is duplicated' % (ent.name))
250 entry_dict[ent.name] = ent
251
252 entries = sorted(entry_dict.values())
253
254 return entries
255
256 def abi_sanity_check(entries):
257 if not entries:
258 return
259
260 all_names = []
261 last_slot = entries[-1].slot
262 i = 0
263 for slot in range(last_slot + 1):
264 if entries[i].slot != slot:
265 raise Exception('entries are not ordered by slots')
266 if entries[i].alias:
267 raise Exception('first entry of slot %d aliases %s'
268 % (slot, entries[i].alias.name))
269 handcode = None
270 while i < len(entries) and entries[i].slot == slot:
271 ent = entries[i]
272 if not handcode and ent.handcode:
273 handcode = ent.handcode
274 elif ent.handcode != handcode:
275 raise Exception('two aliases with handcode %s != %s',
276 ent.handcode, handcode)
277
278 if ent.name in all_names:
279 raise Exception('%s is duplicated' % (ent.name))
280 if ent.alias and ent.alias.name not in all_names:
281 raise Exception('failed to alias %s' % (ent.alias.name))
282 all_names.append(ent.name)
283 i += 1
284 if i < len(entries):
285 raise Exception('there are %d invalid entries' % (len(entries) - 1))
286
287 class ABIPrinter(object):
288 """MAPI Printer"""
289
290 def __init__(self, entries):
291 self.entries = entries
292
293 # sort entries by their names
294 self.entries_sorted_by_names = sorted(self.entries, key=attrgetter('name'))
295
296 self.indent = ' ' * 3
297 self.noop_warn = 'noop_warn'
298 self.noop_generic = 'noop_generic'
299 self.current_get = 'entry_current_get'
300
301 self.api_defines = []
302 self.api_headers = ['"KHR/khrplatform.h"']
303 self.api_call = 'KHRONOS_APICALL'
304 self.api_entry = 'KHRONOS_APIENTRY'
305 self.api_attrs = 'KHRONOS_APIATTRIBUTES'
306
307 self.c_header = ''
308
309 self.lib_need_table_size = True
310 self.lib_need_noop_array = True
311 self.lib_need_stubs = True
312 self.lib_need_all_entries = True
313 self.lib_need_non_hidden_entries = False
314
315 def c_notice(self):
316 return '/* This file is automatically generated by mapi_abi.py. Do not modify. */'
317
318 def c_public_includes(self):
319 """Return includes of the client API headers."""
320 defines = ['#define ' + d for d in self.api_defines]
321 includes = ['#include ' + h for h in self.api_headers]
322 return "\n".join(defines + includes)
323
324 def need_entry_point(self, ent):
325 """Return True if an entry point is needed for the entry."""
326 # non-handcode hidden aliases may share the entry they alias
327 use_alias = (ent.hidden and ent.alias and not ent.handcode)
328 return not use_alias
329
330 def c_public_declarations(self, prefix):
331 """Return the declarations of public entry points."""
332 decls = []
333 for ent in self.entries:
334 if not self.need_entry_point(ent):
335 continue
336 export = self.api_call if not ent.hidden else ''
337 decls.append(self._c_decl(ent, prefix, True, export) + ';')
338
339 return "\n".join(decls)
340
341 def c_mapi_table(self):
342 """Return defines of the dispatch table size."""
343 num_static_entries = self.entries[-1].slot + 1
344 return ('#define MAPI_TABLE_NUM_STATIC %d\n' + \
345 '#define MAPI_TABLE_NUM_DYNAMIC %d') % (
346 num_static_entries, ABI_NUM_DYNAMIC_ENTRIES)
347
348 def _c_function(self, ent, prefix, mangle=False, stringify=False):
349 """Return the function name of an entry."""
350 formats = {
351 True: { True: '%s_STR(%s)', False: '%s(%s)' },
352 False: { True: '"%s%s"', False: '%s%s' },
353 }
354 fmt = formats[prefix.isupper()][stringify]
355 name = ent.name
356 if mangle and ent.hidden:
357 name = '_dispatch_stub_' + str(ent.slot)
358 return fmt % (prefix, name)
359
360 def _c_function_call(self, ent, prefix):
361 """Return the function name used for calling."""
362 if ent.handcode:
363 # _c_function does not handle this case
364 formats = { True: '%s(%s)', False: '%s%s' }
365 fmt = formats[prefix.isupper()]
366 name = fmt % (prefix, ent.handcode)
367 elif self.need_entry_point(ent):
368 name = self._c_function(ent, prefix, True)
369 else:
370 name = self._c_function(ent.alias, prefix, True)
371 return name
372
373 def _c_decl(self, ent, prefix, mangle=False, export=''):
374 """Return the C declaration for the entry."""
375 decl = '%s %s %s(%s)' % (ent.c_return(), self.api_entry,
376 self._c_function(ent, prefix, mangle), ent.c_params())
377 if export:
378 decl = export + ' ' + decl
379 if self.api_attrs:
380 decl += ' ' + self.api_attrs
381
382 return decl
383
384 def _c_cast(self, ent):
385 """Return the C cast for the entry."""
386 cast = '%s (%s *)(%s)' % (
387 ent.c_return(), self.api_entry, ent.c_params())
388
389 return cast
390
391 def c_public_dispatches(self, prefix, no_hidden):
392 """Return the public dispatch functions."""
393 dispatches = []
394 for ent in self.entries:
395 if ent.hidden and no_hidden:
396 continue
397
398 if not self.need_entry_point(ent):
399 continue
400
401 export = self.api_call if not ent.hidden else ''
402
403 proto = self._c_decl(ent, prefix, True, export)
404 cast = self._c_cast(ent)
405
406 ret = ''
407 if ent.ret:
408 ret = 'return '
409 stmt1 = self.indent
410 stmt1 += 'const struct _glapi_table *_tbl = %s();' % (
411 self.current_get)
412 stmt2 = self.indent
413 stmt2 += 'mapi_func _func = ((const mapi_func *) _tbl)[%d];' % (
414 ent.slot)
415 stmt3 = self.indent
416 stmt3 += '%s((%s) _func)(%s);' % (ret, cast, ent.c_args())
417
418 disp = '%s\n{\n%s\n%s\n%s\n}' % (proto, stmt1, stmt2, stmt3)
419
420 if ent.handcode:
421 disp = '#if 0\n' + disp + '\n#endif'
422
423 dispatches.append(disp)
424
425 return '\n\n'.join(dispatches)
426
427 def c_public_initializer(self, prefix):
428 """Return the initializer for public dispatch functions."""
429 names = []
430 for ent in self.entries:
431 if ent.alias:
432 continue
433
434 name = '%s(mapi_func) %s' % (self.indent,
435 self._c_function_call(ent, prefix))
436 names.append(name)
437
438 return ',\n'.join(names)
439
440 def c_stub_string_pool(self):
441 """Return the string pool for use by stubs."""
442 # sort entries by their names
443 sorted_entries = sorted(self.entries, key=attrgetter('name'))
444
445 pool = []
446 offsets = {}
447 count = 0
448 for ent in sorted_entries:
449 offsets[ent] = count
450 pool.append('%s' % (ent.name))
451 count += len(ent.name) + 1
452
453 pool_str = self.indent + '"' + \
454 ('\\0"\n' + self.indent + '"').join(pool) + '";'
455 return (pool_str, offsets)
456
457 def c_stub_initializer(self, prefix, pool_offsets):
458 """Return the initializer for struct mapi_stub array."""
459 stubs = []
460 for ent in self.entries_sorted_by_names:
461 stubs.append('%s{ (void *) %d, %d, NULL }' % (
462 self.indent, pool_offsets[ent], ent.slot))
463
464 return ',\n'.join(stubs)
465
466 def c_noop_functions(self, prefix, warn_prefix):
467 """Return the noop functions."""
468 noops = []
469 for ent in self.entries:
470 if ent.alias:
471 continue
472
473 proto = self._c_decl(ent, prefix, False, 'static')
474
475 stmt1 = self.indent;
476 space = ''
477 for t, n, a in ent.params:
478 stmt1 += "%s(void) %s;" % (space, n)
479 space = ' '
480
481 if ent.params:
482 stmt1 += '\n';
483
484 stmt1 += self.indent + '%s(%s);' % (self.noop_warn,
485 self._c_function(ent, warn_prefix, False, True))
486
487 if ent.ret:
488 stmt2 = self.indent + 'return (%s) 0;' % (ent.ret)
489 noop = '%s\n{\n%s\n%s\n}' % (proto, stmt1, stmt2)
490 else:
491 noop = '%s\n{\n%s\n}' % (proto, stmt1)
492
493 noops.append(noop)
494
495 return '\n\n'.join(noops)
496
497 def c_noop_initializer(self, prefix, use_generic):
498 """Return an initializer for the noop dispatch table."""
499 entries = [self._c_function(ent, prefix)
500 for ent in self.entries if not ent.alias]
501 if use_generic:
502 entries = [self.noop_generic] * len(entries)
503
504 entries.extend([self.noop_generic] * ABI_NUM_DYNAMIC_ENTRIES)
505
506 pre = self.indent + '(mapi_func) '
507 return pre + (',\n' + pre).join(entries)
508
509 def c_asm_gcc(self, prefix, no_hidden):
510 asm = []
511
512 for ent in self.entries:
513 if ent.hidden and no_hidden:
514 continue
515
516 if not self.need_entry_point(ent):
517 continue
518
519 name = self._c_function(ent, prefix, True, True)
520
521 if ent.handcode:
522 asm.append('#if 0')
523
524 if ent.hidden:
525 asm.append('".hidden "%s"\\n"' % (name))
526
527 if ent.alias and not (ent.alias.hidden and no_hidden):
528 asm.append('".globl "%s"\\n"' % (name))
529 asm.append('".set "%s", "%s"\\n"' % (name,
530 self._c_function(ent.alias, prefix, True, True)))
531 else:
532 asm.append('STUB_ASM_ENTRY(%s)"\\n"' % (name))
533 asm.append('"\\t"STUB_ASM_CODE("%d")"\\n"' % (ent.slot))
534
535 if ent.handcode:
536 asm.append('#endif')
537 asm.append('')
538
539 return "\n".join(asm)
540
541 def output_for_lib(self):
542 print(self.c_notice())
543
544 if self.c_header:
545 print()
546 print(self.c_header)
547
548 print()
549 print('#ifdef MAPI_TMP_DEFINES')
550 print(self.c_public_includes())
551 print()
552 print(self.c_public_declarations(self.prefix_lib))
553 print('#undef MAPI_TMP_DEFINES')
554 print('#endif /* MAPI_TMP_DEFINES */')
555
556 if self.lib_need_table_size:
557 print()
558 print('#ifdef MAPI_TMP_TABLE')
559 print(self.c_mapi_table())
560 print('#undef MAPI_TMP_TABLE')
561 print('#endif /* MAPI_TMP_TABLE */')
562
563 if self.lib_need_noop_array:
564 print()
565 print('#ifdef MAPI_TMP_NOOP_ARRAY')
566 print('#ifdef DEBUG')
567 print()
568 print(self.c_noop_functions(self.prefix_noop, self.prefix_warn))
569 print()
570 print('const mapi_func table_%s_array[] = {' % (self.prefix_noop))
571 print(self.c_noop_initializer(self.prefix_noop, False))
572 print('};')
573 print()
574 print('#else /* DEBUG */')
575 print()
576 print('const mapi_func table_%s_array[] = {' % (self.prefix_noop))
577 print(self.c_noop_initializer(self.prefix_noop, True))
578 print('};')
579 print()
580 print('#endif /* DEBUG */')
581 print('#undef MAPI_TMP_NOOP_ARRAY')
582 print('#endif /* MAPI_TMP_NOOP_ARRAY */')
583
584 if self.lib_need_stubs:
585 pool, pool_offsets = self.c_stub_string_pool()
586 print()
587 print('#ifdef MAPI_TMP_PUBLIC_STUBS')
588 print('static const char public_string_pool[] =')
589 print(pool)
590 print()
591 print('static const struct mapi_stub public_stubs[] = {')
592 print(self.c_stub_initializer(self.prefix_lib, pool_offsets))
593 print('};')
594 print('#undef MAPI_TMP_PUBLIC_STUBS')
595 print('#endif /* MAPI_TMP_PUBLIC_STUBS */')
596
597 if self.lib_need_all_entries:
598 print()
599 print('#ifdef MAPI_TMP_PUBLIC_ENTRIES')
600 print(self.c_public_dispatches(self.prefix_lib, False))
601 print()
602 print('static const mapi_func public_entries[] = {')
603 print(self.c_public_initializer(self.prefix_lib))
604 print('};')
605 print('#undef MAPI_TMP_PUBLIC_ENTRIES')
606 print('#endif /* MAPI_TMP_PUBLIC_ENTRIES */')
607
608 print()
609 print('#ifdef MAPI_TMP_STUB_ASM_GCC')
610 print('__asm__(')
611 print(self.c_asm_gcc(self.prefix_lib, False))
612 print(');')
613 print('#undef MAPI_TMP_STUB_ASM_GCC')
614 print('#endif /* MAPI_TMP_STUB_ASM_GCC */')
615
616 if self.lib_need_non_hidden_entries:
617 all_hidden = True
618 for ent in self.entries:
619 if not ent.hidden:
620 all_hidden = False
621 break
622 if not all_hidden:
623 print()
624 print('#ifdef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN')
625 print(self.c_public_dispatches(self.prefix_lib, True))
626 print()
627 print('/* does not need public_entries */')
628 print('#undef MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN')
629 print('#endif /* MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN */')
630
631 print()
632 print('#ifdef MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN')
633 print('__asm__(')
634 print(self.c_asm_gcc(self.prefix_lib, True))
635 print(');')
636 print('#undef MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN')
637 print('#endif /* MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN */')
638
639 class GLAPIPrinter(ABIPrinter):
640 """OpenGL API Printer"""
641
642 def __init__(self, entries):
643 for ent in entries:
644 self._override_for_api(ent)
645 super(GLAPIPrinter, self).__init__(entries)
646
647 self.api_defines = ['GL_GLEXT_PROTOTYPES']
648 self.api_headers = ['"GL/gl.h"', '"GL/glext.h"']
649 self.api_call = 'GLAPI'
650 self.api_entry = 'APIENTRY'
651 self.api_attrs = ''
652
653 self.lib_need_table_size = False
654 self.lib_need_noop_array = False
655 self.lib_need_stubs = False
656 self.lib_need_all_entries = False
657 self.lib_need_non_hidden_entries = True
658
659 self.prefix_lib = 'GLAPI_PREFIX'
660 self.prefix_noop = 'noop'
661 self.prefix_warn = self.prefix_lib
662
663 self.c_header = self._get_c_header()
664
665 def _override_for_api(self, ent):
666 """Override attributes of an entry if necessary for this
667 printer."""
668 # By default, no override is necessary.
669 pass
670
671 def _get_c_header(self):
672 header = """#ifndef _GLAPI_TMP_H_
673 #define _GLAPI_TMP_H_
674 #ifdef USE_MGL_NAMESPACE
675 #define GLAPI_PREFIX(func) mgl##func
676 #define GLAPI_PREFIX_STR(func) "mgl"#func
677 #else
678 #define GLAPI_PREFIX(func) gl##func
679 #define GLAPI_PREFIX_STR(func) "gl"#func
680 #endif /* USE_MGL_NAMESPACE */
681
682 typedef int GLclampx;
683 #endif /* _GLAPI_TMP_H_ */"""
684
685 return header
686
687 class ES1APIPrinter(GLAPIPrinter):
688 """OpenGL ES 1.x API Printer"""
689
690 def __init__(self, entries):
691 super(ES1APIPrinter, self).__init__(entries)
692 self.prefix_lib = 'gl'
693 self.prefix_warn = 'gl'
694
695 def _override_for_api(self, ent):
696 if ent.xml_data is None:
697 raise Exception('ES2 API printer requires XML input')
698 ent.hidden = (ent.name not in \
699 ent.xml_data.entry_points_for_api_version('es1')) \
700 or ent.hidden
701 ent.handcode = False
702
703 def _get_c_header(self):
704 header = """#ifndef _GLAPI_TMP_H_
705 #define _GLAPI_TMP_H_
706 typedef int GLclampx;
707 #endif /* _GLAPI_TMP_H_ */"""
708
709 return header
710
711 class ES2APIPrinter(GLAPIPrinter):
712 """OpenGL ES 2.x API Printer"""
713
714 def __init__(self, entries):
715 super(ES2APIPrinter, self).__init__(entries)
716 self.prefix_lib = 'gl'
717 self.prefix_warn = 'gl'
718
719 def _override_for_api(self, ent):
720 if ent.xml_data is None:
721 raise Exception('ES2 API printer requires XML input')
722 ent.hidden = (ent.name not in \
723 ent.xml_data.entry_points_for_api_version('es2')) \
724 or ent.hidden
725
726 # This is hella ugly. The same-named function in desktop OpenGL is
727 # hidden, but it needs to be exposed by libGLESv2 for OpenGL ES 3.0.
728 # There's no way to express in the XML that a function should be be
729 # hidden in one API but exposed in another.
730 if ent.name == 'GetInternalformativ':
731 ent.hidden = False
732
733 ent.handcode = False
734
735 def _get_c_header(self):
736 header = """#ifndef _GLAPI_TMP_H_
737 #define _GLAPI_TMP_H_
738 typedef int GLclampx;
739 #endif /* _GLAPI_TMP_H_ */"""
740
741 return header
742
743 class SharedGLAPIPrinter(GLAPIPrinter):
744 """Shared GLAPI API Printer"""
745
746 def __init__(self, entries):
747 super(SharedGLAPIPrinter, self).__init__(entries)
748
749 self.lib_need_table_size = True
750 self.lib_need_noop_array = True
751 self.lib_need_stubs = True
752 self.lib_need_all_entries = True
753 self.lib_need_non_hidden_entries = False
754
755 self.prefix_lib = 'shared'
756 self.prefix_warn = 'gl'
757
758 def _override_for_api(self, ent):
759 ent.hidden = True
760 ent.handcode = False
761
762 def _get_c_header(self):
763 header = """#ifndef _GLAPI_TMP_H_
764 #define _GLAPI_TMP_H_
765 typedef int GLclampx;
766 #endif /* _GLAPI_TMP_H_ */"""
767
768 return header
769
770 def parse_args():
771 printers = ['glapi', 'es1api', 'es2api', 'shared-glapi']
772
773 parser = OptionParser(usage='usage: %prog [options] <filename>')
774 parser.add_option('-p', '--printer', dest='printer',
775 help='printer to use: %s' % (", ".join(printers)))
776
777 options, args = parser.parse_args()
778 if not args or options.printer not in printers:
779 parser.print_help()
780 sys.exit(1)
781
782 return (args[0], options)
783
784 def main():
785 printers = {
786 'glapi': GLAPIPrinter,
787 'es1api': ES1APIPrinter,
788 'es2api': ES2APIPrinter,
789 'shared-glapi': SharedGLAPIPrinter,
790 }
791
792 filename, options = parse_args()
793
794 if filename.endswith('.xml'):
795 entries = abi_parse_xml(filename)
796 else:
797 entries = abi_parse(filename)
798 abi_sanity_check(entries)
799
800 printer = printers[options.printer](entries)
801 printer.output_for_lib()
802
803 if __name__ == '__main__':
804 main()