1 2# Copyright (C) 2012 Intel Corporation 3# 4# Permission is hereby granted, free of charge, to any person obtaining a 5# copy of this software and associated documentation files (the "Software"), 6# to deal in the Software without restriction, including without limitation 7# the rights to use, copy, modify, merge, publish, distribute, sublicense, 8# and/or sell copies of the Software, and to permit persons to whom the 9# Software is furnished to do so, subject to the following conditions: 10# 11# The above copyright notice and this permission notice (including the next 12# paragraph) shall be included in all copies or substantial portions of the 13# Software. 14# 15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21# IN THE SOFTWARE. 22 23# This script generates the file api_exec_init.c, which contains 24# _mesa_init_dispatch(). It is responsible for populating all 25# entries in the "OutsideBeginEnd" dispatch table. 26 27import argparse 28import collections 29import license 30import gl_XML 31import sys 32import apiexec 33 34 35exec_flavor_map = { 36 'beginend': None, 37 'dlist': '_mesa_', 38 'mesa': '_mesa_', 39 'skip': None, 40 } 41 42 43header = """/** 44 * \\file api_exec_init.c 45 * Initialize dispatch table. 46 */ 47 48 49#include "api_exec_decl.h" 50#include "glapi/glapi.h" 51#include "main/context.h" 52#include "main/dispatch.h" 53 54 55/** 56 * Initialize a context's OutsideBeginEnd table with pointers to Mesa's supported 57 * GL functions. 58 * 59 * This function depends on ctx->Version. 60 * 61 * \param ctx GL context 62 */ 63void 64_mesa_init_dispatch(struct gl_context *ctx) 65{ 66 struct _glapi_table *table = ctx->Dispatch.OutsideBeginEnd; 67 68 assert(table != NULL); 69 assert(ctx->Version > 0); 70""" 71 72 73footer = """ 74} 75""" 76 77 78class PrintCode(gl_XML.gl_print_base): 79 80 def __init__(self): 81 gl_XML.gl_print_base.__init__(self) 82 83 self.name = 'api_exec_init.py' 84 self.license = license.bsd_license_template % ( 85 'Copyright (C) 2012 Intel Corporation', 86 'Intel Corporation') 87 88 def printRealHeader(self): 89 print(header) 90 91 def printRealFooter(self): 92 print(footer) 93 94 def printBody(self, api): 95 # Collect SET_* calls by the condition under which they should 96 # be called. 97 settings_by_condition = collections.defaultdict(lambda: []) 98 for f in api.functionIterateAll(): 99 if f.exec_flavor not in exec_flavor_map: 100 raise Exception( 101 'Unrecognized exec flavor {0!r}'.format(f.exec_flavor)) 102 condition = apiexec.get_api_condition(f) 103 if not condition: 104 continue 105 prefix = exec_flavor_map[f.exec_flavor] 106 if prefix is None: 107 # This function is not implemented, or is dispatched 108 # via beginend. 109 continue 110 if f.has_no_error_variant: 111 no_error_condition = '_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition) 112 error_condition = '!_mesa_is_no_error_enabled(ctx) && ({0})'.format(condition) 113 settings_by_condition[no_error_condition].append( 114 'SET_{0}(table, {1}{0}_no_error);'.format(f.name, prefix, f.name)) 115 settings_by_condition[error_condition].append( 116 'SET_{0}(table, {1}{0});'.format(f.name, prefix, f.name)) 117 else: 118 settings_by_condition[condition].append( 119 'SET_{0}(table, {1}{0});'.format(f.name, prefix, f.name)) 120 # Print out an if statement for each unique condition, with 121 # the SET_* calls nested inside it. 122 for condition in sorted(settings_by_condition.keys()): 123 print(' if ({0}) {{'.format(condition)) 124 for setting in sorted(settings_by_condition[condition]): 125 print(' {0}'.format(setting)) 126 print(' }') 127 128 129if __name__ == '__main__': 130 apiexec.print_glapi_file(PrintCode()) 131