1bf215546Sopenharmony_ci 2bf215546Sopenharmony_ci# (C) Copyright IBM Corporation 2005 3bf215546Sopenharmony_ci# All Rights Reserved. 4bf215546Sopenharmony_ci# 5bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci# copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci# to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci# on the rights to use, copy, modify, merge, publish, distribute, sub 9bf215546Sopenharmony_ci# license, and/or sell copies of the Software, and to permit persons to whom 10bf215546Sopenharmony_ci# the Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci# 12bf215546Sopenharmony_ci# The above copyright notice and this permission notice (including the next 13bf215546Sopenharmony_ci# paragraph) shall be included in all copies or substantial portions of the 14bf215546Sopenharmony_ci# Software. 15bf215546Sopenharmony_ci# 16bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci# IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21bf215546Sopenharmony_ci# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22bf215546Sopenharmony_ci# IN THE SOFTWARE. 23bf215546Sopenharmony_ci# 24bf215546Sopenharmony_ci# Authors: 25bf215546Sopenharmony_ci# Ian Romanick <idr@us.ibm.com> 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ciimport argparse 28bf215546Sopenharmony_ciimport string 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ciimport gl_XML, glX_XML, glX_proto_common, license 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ciclass PrintGlxDispatch_h(gl_XML.gl_print_base): 34bf215546Sopenharmony_ci def __init__(self): 35bf215546Sopenharmony_ci gl_XML.gl_print_base.__init__(self) 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci self.name = "glX_proto_recv.py (from Mesa)" 38bf215546Sopenharmony_ci self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci self.header_tag = "_INDIRECT_DISPATCH_H_" 41bf215546Sopenharmony_ci return 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci def printRealHeader(self): 45bf215546Sopenharmony_ci print '# include <X11/Xfuncproto.h>' 46bf215546Sopenharmony_ci print '' 47bf215546Sopenharmony_ci print 'struct __GLXclientStateRec;' 48bf215546Sopenharmony_ci print '' 49bf215546Sopenharmony_ci return 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci def printBody(self, api): 53bf215546Sopenharmony_ci for func in api.functionIterateAll(): 54bf215546Sopenharmony_ci if not func.ignore and not func.vectorequiv: 55bf215546Sopenharmony_ci if func.glx_rop: 56bf215546Sopenharmony_ci print 'extern _X_HIDDEN void __glXDisp_%s(GLbyte * pc);' % (func.name) 57bf215546Sopenharmony_ci print 'extern _X_HIDDEN _X_COLD void __glXDispSwap_%s(GLbyte * pc);' % (func.name) 58bf215546Sopenharmony_ci elif func.glx_sop or func.glx_vendorpriv: 59bf215546Sopenharmony_ci print 'extern _X_HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name) 60bf215546Sopenharmony_ci print 'extern _X_HIDDEN _X_COLD int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (func.name) 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci if func.glx_sop and func.glx_vendorpriv: 63bf215546Sopenharmony_ci n = func.glx_vendorpriv_names[0] 64bf215546Sopenharmony_ci print 'extern _X_HIDDEN int __glXDisp_%s(struct __GLXclientStateRec *, GLbyte *);' % (n) 65bf215546Sopenharmony_ci print 'extern _X_HIDDEN _X_COLD int __glXDispSwap_%s(struct __GLXclientStateRec *, GLbyte *);' % (n) 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci return 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ciclass PrintGlxDispatchFunctions(glX_proto_common.glx_print_proto): 71bf215546Sopenharmony_ci def __init__(self, do_swap): 72bf215546Sopenharmony_ci gl_XML.gl_print_base.__init__(self) 73bf215546Sopenharmony_ci self.name = "glX_proto_recv.py (from Mesa)" 74bf215546Sopenharmony_ci self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2005", "IBM") 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci self.real_types = [ '', '', 'uint16_t', '', 'uint32_t', '', '', '', 'uint64_t' ] 77bf215546Sopenharmony_ci self.do_swap = do_swap 78bf215546Sopenharmony_ci return 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci def printRealHeader(self): 82bf215546Sopenharmony_ci print '#include <inttypes.h>' 83bf215546Sopenharmony_ci print '#include "glxserver.h"' 84bf215546Sopenharmony_ci print '#include "indirect_size.h"' 85bf215546Sopenharmony_ci print '#include "indirect_size_get.h"' 86bf215546Sopenharmony_ci print '#include "indirect_dispatch.h"' 87bf215546Sopenharmony_ci print '#include "glxbyteorder.h"' 88bf215546Sopenharmony_ci print '#include "indirect_util.h"' 89bf215546Sopenharmony_ci print '#include "singlesize.h"' 90bf215546Sopenharmony_ci print '' 91bf215546Sopenharmony_ci print 'typedef struct {' 92bf215546Sopenharmony_ci print ' __GLX_PIXEL_3D_HDR;' 93bf215546Sopenharmony_ci print '} __GLXpixel3DHeader;' 94bf215546Sopenharmony_ci print '' 95bf215546Sopenharmony_ci print 'extern GLboolean __glXErrorOccured( void );' 96bf215546Sopenharmony_ci print 'extern void __glXClearErrorOccured( void );' 97bf215546Sopenharmony_ci print '' 98bf215546Sopenharmony_ci print 'static const unsigned dummy_answer[2] = {0, 0};' 99bf215546Sopenharmony_ci print '' 100bf215546Sopenharmony_ci return 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci def printBody(self, api): 104bf215546Sopenharmony_ci if self.do_swap: 105bf215546Sopenharmony_ci self.emit_swap_wrappers(api) 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci for func in api.functionIterateByOffset(): 109bf215546Sopenharmony_ci if not func.ignore and not func.server_handcode and not func.vectorequiv and (func.glx_rop or func.glx_sop or func.glx_vendorpriv): 110bf215546Sopenharmony_ci self.printFunction(func, func.name) 111bf215546Sopenharmony_ci if func.glx_sop and func.glx_vendorpriv: 112bf215546Sopenharmony_ci self.printFunction(func, func.glx_vendorpriv_names[0]) 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci return 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_ci def fptrType(self, name): 118bf215546Sopenharmony_ci fptr = "pfngl" + name + "proc" 119bf215546Sopenharmony_ci return fptr.upper() 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci def printFunction(self, f, name): 122bf215546Sopenharmony_ci if (f.glx_sop or f.glx_vendorpriv) and (len(f.get_images()) != 0): 123bf215546Sopenharmony_ci return 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci if not self.do_swap: 126bf215546Sopenharmony_ci base = '__glXDisp' 127bf215546Sopenharmony_ci else: 128bf215546Sopenharmony_ci base = '__glXDispSwap' 129bf215546Sopenharmony_ci 130bf215546Sopenharmony_ci if f.glx_rop: 131bf215546Sopenharmony_ci print 'void %s_%s(GLbyte * pc)' % (base, name) 132bf215546Sopenharmony_ci else: 133bf215546Sopenharmony_ci print 'int %s_%s(__GLXclientState *cl, GLbyte *pc)' % (base, name) 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci print '{' 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci if not f.is_abi(): 138bf215546Sopenharmony_ci print ' %s %s = __glGetProcAddress("gl%s");' % (self.fptrType(name), name, name) 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci if f.glx_rop or f.vectorequiv: 141bf215546Sopenharmony_ci self.printRenderFunction(f) 142bf215546Sopenharmony_ci elif f.glx_sop or f.glx_vendorpriv: 143bf215546Sopenharmony_ci if len(f.get_images()) == 0: 144bf215546Sopenharmony_ci self.printSingleFunction(f, name) 145bf215546Sopenharmony_ci else: 146bf215546Sopenharmony_ci print "/* Missing GLX protocol for %s. */" % (name) 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci print '}' 149bf215546Sopenharmony_ci print '' 150bf215546Sopenharmony_ci return 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci def swap_name(self, bytes): 154bf215546Sopenharmony_ci return 'bswap_%u_array' % (8 * bytes) 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci 157bf215546Sopenharmony_ci def emit_swap_wrappers(self, api): 158bf215546Sopenharmony_ci self.type_map = {} 159bf215546Sopenharmony_ci already_done = [ ] 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ci for t in api.typeIterate(): 162bf215546Sopenharmony_ci te = t.get_type_expression() 163bf215546Sopenharmony_ci t_size = te.get_element_size() 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci if t_size > 1 and t.glx_name: 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_ci t_name = "GL" + t.name 168bf215546Sopenharmony_ci self.type_map[ t_name ] = t.glx_name 169bf215546Sopenharmony_ci 170bf215546Sopenharmony_ci if t.glx_name not in already_done: 171bf215546Sopenharmony_ci real_name = self.real_types[t_size] 172bf215546Sopenharmony_ci 173bf215546Sopenharmony_ci print 'static _X_UNUSED %s' % (t_name) 174bf215546Sopenharmony_ci print 'bswap_%s(const void * src)' % (t.glx_name) 175bf215546Sopenharmony_ci print '{' 176bf215546Sopenharmony_ci print ' union { %s dst; %s ret; } x;' % (real_name, t_name) 177bf215546Sopenharmony_ci print ' x.dst = bswap_%u(*(%s *) src);' % (t_size * 8, real_name) 178bf215546Sopenharmony_ci print ' return x.ret;' 179bf215546Sopenharmony_ci print '}' 180bf215546Sopenharmony_ci print '' 181bf215546Sopenharmony_ci already_done.append( t.glx_name ) 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_ci for bits in [16, 32, 64]: 184bf215546Sopenharmony_ci print 'static void *' 185bf215546Sopenharmony_ci print 'bswap_%u_array(uint%u_t * src, unsigned count)' % (bits, bits) 186bf215546Sopenharmony_ci print '{' 187bf215546Sopenharmony_ci print ' unsigned i;' 188bf215546Sopenharmony_ci print '' 189bf215546Sopenharmony_ci print ' for (i = 0 ; i < count ; i++) {' 190bf215546Sopenharmony_ci print ' uint%u_t temp = bswap_%u(src[i]);' % (bits, bits) 191bf215546Sopenharmony_ci print ' src[i] = temp;' 192bf215546Sopenharmony_ci print ' }' 193bf215546Sopenharmony_ci print '' 194bf215546Sopenharmony_ci print ' return src;' 195bf215546Sopenharmony_ci print '}' 196bf215546Sopenharmony_ci print '' 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_ci def fetch_param(self, param): 200bf215546Sopenharmony_ci t = param.type_string() 201bf215546Sopenharmony_ci o = param.offset 202bf215546Sopenharmony_ci element_size = param.size() / param.get_element_count() 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_ci if self.do_swap and (element_size != 1): 205bf215546Sopenharmony_ci if param.is_array(): 206bf215546Sopenharmony_ci real_name = self.real_types[ element_size ] 207bf215546Sopenharmony_ci 208bf215546Sopenharmony_ci swap_func = self.swap_name( element_size ) 209bf215546Sopenharmony_ci return ' (%-8s)%s( (%s *) (pc + %2s), %s )' % (t, swap_func, real_name, o, param.count) 210bf215546Sopenharmony_ci else: 211bf215546Sopenharmony_ci t_name = param.get_base_type_string() 212bf215546Sopenharmony_ci return ' (%-8s)bswap_%-7s( pc + %2s )' % (t, self.type_map[ t_name ], o) 213bf215546Sopenharmony_ci else: 214bf215546Sopenharmony_ci if param.is_array(): 215bf215546Sopenharmony_ci return ' (%-8s)(pc + %2u)' % (t, o) 216bf215546Sopenharmony_ci else: 217bf215546Sopenharmony_ci return '*(%-8s *)(pc + %2u)' % (t, o) 218bf215546Sopenharmony_ci 219bf215546Sopenharmony_ci return None 220bf215546Sopenharmony_ci 221bf215546Sopenharmony_ci 222bf215546Sopenharmony_ci def emit_function_call(self, f, retval_assign, indent): 223bf215546Sopenharmony_ci list = [] 224bf215546Sopenharmony_ci prefix = "gl" if f.is_abi() else "" 225bf215546Sopenharmony_ci 226bf215546Sopenharmony_ci for param in f.parameterIterator(): 227bf215546Sopenharmony_ci if param.is_padding: 228bf215546Sopenharmony_ci continue 229bf215546Sopenharmony_ci 230bf215546Sopenharmony_ci if param.is_counter or param.is_image() or param.is_output or param.name in f.count_parameter_list or len(param.count_parameter_list): 231bf215546Sopenharmony_ci location = param.name 232bf215546Sopenharmony_ci else: 233bf215546Sopenharmony_ci location = self.fetch_param(param) 234bf215546Sopenharmony_ci 235bf215546Sopenharmony_ci list.append( '%s %s' % (indent, location) ) 236bf215546Sopenharmony_ci 237bf215546Sopenharmony_ci print '%s %s%s%s(%s);' % (indent, retval_assign, prefix, f.name, string.join(list, ',\n')) 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_ci 240bf215546Sopenharmony_ci def common_func_print_just_start(self, f, indent): 241bf215546Sopenharmony_ci align64 = 0 242bf215546Sopenharmony_ci need_blank = 0 243bf215546Sopenharmony_ci 244bf215546Sopenharmony_ci 245bf215546Sopenharmony_ci f.calculate_offsets() 246bf215546Sopenharmony_ci for param in f.parameterIterateGlxSend(): 247bf215546Sopenharmony_ci # If any parameter has a 64-bit base type, then we 248bf215546Sopenharmony_ci # have to do alignment magic for the while thing. 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci if param.is_64_bit(): 251bf215546Sopenharmony_ci align64 = 1 252bf215546Sopenharmony_ci 253bf215546Sopenharmony_ci 254bf215546Sopenharmony_ci # FIXME img_null_flag is over-loaded. In addition to 255bf215546Sopenharmony_ci # FIXME being used for images, it is used to signify 256bf215546Sopenharmony_ci # FIXME NULL data pointers for vertex buffer object 257bf215546Sopenharmony_ci # FIXME related functions. Re-name it to null_data 258bf215546Sopenharmony_ci # FIXME or something similar. 259bf215546Sopenharmony_ci 260bf215546Sopenharmony_ci if param.img_null_flag: 261bf215546Sopenharmony_ci print '%s const CARD32 ptr_is_null = *(CARD32 *)(pc + %s);' % (indent, param.offset - 4) 262bf215546Sopenharmony_ci cond = '(ptr_is_null != 0) ? NULL : ' 263bf215546Sopenharmony_ci else: 264bf215546Sopenharmony_ci cond = "" 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_ci 267bf215546Sopenharmony_ci type_string = param.type_string() 268bf215546Sopenharmony_ci 269bf215546Sopenharmony_ci if param.is_image(): 270bf215546Sopenharmony_ci offset = f.offset_of( param.name ) 271bf215546Sopenharmony_ci 272bf215546Sopenharmony_ci print '%s %s const %s = (%s) (%s(pc + %s));' % (indent, type_string, param.name, type_string, cond, offset) 273bf215546Sopenharmony_ci 274bf215546Sopenharmony_ci if param.depth: 275bf215546Sopenharmony_ci print '%s __GLXpixel3DHeader * const hdr = (__GLXpixel3DHeader *)(pc);' % (indent) 276bf215546Sopenharmony_ci else: 277bf215546Sopenharmony_ci print '%s __GLXpixelHeader * const hdr = (__GLXpixelHeader *)(pc);' % (indent) 278bf215546Sopenharmony_ci 279bf215546Sopenharmony_ci need_blank = 1 280bf215546Sopenharmony_ci elif param.is_counter or param.name in f.count_parameter_list: 281bf215546Sopenharmony_ci location = self.fetch_param(param) 282bf215546Sopenharmony_ci print '%s const %s %s = %s;' % (indent, type_string, param.name, location) 283bf215546Sopenharmony_ci need_blank = 1 284bf215546Sopenharmony_ci elif len(param.count_parameter_list): 285bf215546Sopenharmony_ci if param.size() == 1 and not self.do_swap: 286bf215546Sopenharmony_ci location = self.fetch_param(param) 287bf215546Sopenharmony_ci print '%s %s %s = %s%s;' % (indent, type_string, param.name, cond, location) 288bf215546Sopenharmony_ci else: 289bf215546Sopenharmony_ci print '%s %s %s;' % (indent, type_string, param.name) 290bf215546Sopenharmony_ci need_blank = 1 291bf215546Sopenharmony_ci 292bf215546Sopenharmony_ci 293bf215546Sopenharmony_ci 294bf215546Sopenharmony_ci if need_blank: 295bf215546Sopenharmony_ci print '' 296bf215546Sopenharmony_ci 297bf215546Sopenharmony_ci if align64: 298bf215546Sopenharmony_ci print '#ifdef __GLX_ALIGN64' 299bf215546Sopenharmony_ci 300bf215546Sopenharmony_ci if f.has_variable_size_request(): 301bf215546Sopenharmony_ci self.emit_packet_size_calculation(f, 4) 302bf215546Sopenharmony_ci s = "cmdlen" 303bf215546Sopenharmony_ci else: 304bf215546Sopenharmony_ci s = str((f.command_fixed_length() + 3) & ~3) 305bf215546Sopenharmony_ci 306bf215546Sopenharmony_ci print ' if ((unsigned long)(pc) & 7) {' 307bf215546Sopenharmony_ci print ' (void) memmove(pc-4, pc, %s);' % (s) 308bf215546Sopenharmony_ci print ' pc -= 4;' 309bf215546Sopenharmony_ci print ' }' 310bf215546Sopenharmony_ci print '#endif' 311bf215546Sopenharmony_ci print '' 312bf215546Sopenharmony_ci 313bf215546Sopenharmony_ci 314bf215546Sopenharmony_ci need_blank = 0 315bf215546Sopenharmony_ci if self.do_swap: 316bf215546Sopenharmony_ci for param in f.parameterIterateGlxSend(): 317bf215546Sopenharmony_ci if param.count_parameter_list: 318bf215546Sopenharmony_ci o = param.offset 319bf215546Sopenharmony_ci count = param.get_element_count() 320bf215546Sopenharmony_ci type_size = param.size() / count 321bf215546Sopenharmony_ci 322bf215546Sopenharmony_ci if param.counter: 323bf215546Sopenharmony_ci count_name = param.counter 324bf215546Sopenharmony_ci else: 325bf215546Sopenharmony_ci count_name = str(count) 326bf215546Sopenharmony_ci 327bf215546Sopenharmony_ci # This is basically an ugly special- 328bf215546Sopenharmony_ci # case for glCallLists. 329bf215546Sopenharmony_ci 330bf215546Sopenharmony_ci if type_size == 1: 331bf215546Sopenharmony_ci x = [] 332bf215546Sopenharmony_ci x.append( [1, ['BYTE', 'UNSIGNED_BYTE', '2_BYTES', '3_BYTES', '4_BYTES']] ) 333bf215546Sopenharmony_ci x.append( [2, ['SHORT', 'UNSIGNED_SHORT']] ) 334bf215546Sopenharmony_ci x.append( [4, ['INT', 'UNSIGNED_INT', 'FLOAT']] ) 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ci print ' switch(%s) {' % (param.count_parameter_list[0]) 337bf215546Sopenharmony_ci for sub in x: 338bf215546Sopenharmony_ci for t_name in sub[1]: 339bf215546Sopenharmony_ci print ' case GL_%s:' % (t_name) 340bf215546Sopenharmony_ci 341bf215546Sopenharmony_ci if sub[0] == 1: 342bf215546Sopenharmony_ci print ' %s = (%s) (pc + %s); break;' % (param.name, param.type_string(), o) 343bf215546Sopenharmony_ci else: 344bf215546Sopenharmony_ci swap_func = self.swap_name(sub[0]) 345bf215546Sopenharmony_ci print ' %s = (%s) %s( (%s *) (pc + %s), %s ); break;' % (param.name, param.type_string(), swap_func, self.real_types[sub[0]], o, count_name) 346bf215546Sopenharmony_ci print ' default:' 347bf215546Sopenharmony_ci print ' return;' 348bf215546Sopenharmony_ci print ' }' 349bf215546Sopenharmony_ci else: 350bf215546Sopenharmony_ci swap_func = self.swap_name(type_size) 351bf215546Sopenharmony_ci compsize = self.size_call(f, 1) 352bf215546Sopenharmony_ci print ' %s = (%s) %s( (%s *) (pc + %s), %s );' % (param.name, param.type_string(), swap_func, self.real_types[type_size], o, compsize) 353bf215546Sopenharmony_ci 354bf215546Sopenharmony_ci need_blank = 1 355bf215546Sopenharmony_ci 356bf215546Sopenharmony_ci else: 357bf215546Sopenharmony_ci for param in f.parameterIterateGlxSend(): 358bf215546Sopenharmony_ci if param.count_parameter_list: 359bf215546Sopenharmony_ci print '%s %s = (%s) (pc + %s);' % (indent, param.name, param.type_string(), param.offset) 360bf215546Sopenharmony_ci need_blank = 1 361bf215546Sopenharmony_ci 362bf215546Sopenharmony_ci 363bf215546Sopenharmony_ci if need_blank: 364bf215546Sopenharmony_ci print '' 365bf215546Sopenharmony_ci 366bf215546Sopenharmony_ci 367bf215546Sopenharmony_ci return 368bf215546Sopenharmony_ci 369bf215546Sopenharmony_ci 370bf215546Sopenharmony_ci def printSingleFunction(self, f, name): 371bf215546Sopenharmony_ci if name not in f.glx_vendorpriv_names: 372bf215546Sopenharmony_ci print ' xGLXSingleReq * const req = (xGLXSingleReq *) pc;' 373bf215546Sopenharmony_ci else: 374bf215546Sopenharmony_ci print ' xGLXVendorPrivateReq * const req = (xGLXVendorPrivateReq *) pc;' 375bf215546Sopenharmony_ci 376bf215546Sopenharmony_ci print ' int error;' 377bf215546Sopenharmony_ci 378bf215546Sopenharmony_ci if self.do_swap: 379bf215546Sopenharmony_ci print ' __GLXcontext * const cx = __glXForceCurrent(cl, bswap_CARD32( &req->contextTag ), &error);' 380bf215546Sopenharmony_ci else: 381bf215546Sopenharmony_ci print ' __GLXcontext * const cx = __glXForceCurrent(cl, req->contextTag, &error);' 382bf215546Sopenharmony_ci 383bf215546Sopenharmony_ci print '' 384bf215546Sopenharmony_ci if name not in f.glx_vendorpriv_names: 385bf215546Sopenharmony_ci print ' pc += __GLX_SINGLE_HDR_SIZE;' 386bf215546Sopenharmony_ci else: 387bf215546Sopenharmony_ci print ' pc += __GLX_VENDPRIV_HDR_SIZE;' 388bf215546Sopenharmony_ci 389bf215546Sopenharmony_ci print ' if ( cx != NULL ) {' 390bf215546Sopenharmony_ci self.common_func_print_just_start(f, " ") 391bf215546Sopenharmony_ci 392bf215546Sopenharmony_ci 393bf215546Sopenharmony_ci if f.return_type != 'void': 394bf215546Sopenharmony_ci print ' %s retval;' % (f.return_type) 395bf215546Sopenharmony_ci retval_string = "retval" 396bf215546Sopenharmony_ci retval_assign = "retval = " 397bf215546Sopenharmony_ci else: 398bf215546Sopenharmony_ci retval_string = "0" 399bf215546Sopenharmony_ci retval_assign = "" 400bf215546Sopenharmony_ci 401bf215546Sopenharmony_ci 402bf215546Sopenharmony_ci type_size = 0 403bf215546Sopenharmony_ci answer_string = "dummy_answer" 404bf215546Sopenharmony_ci answer_count = "0" 405bf215546Sopenharmony_ci is_array_string = "GL_FALSE" 406bf215546Sopenharmony_ci 407bf215546Sopenharmony_ci for param in f.parameterIterateOutputs(): 408bf215546Sopenharmony_ci answer_type = param.get_base_type_string() 409bf215546Sopenharmony_ci if answer_type == "GLvoid": 410bf215546Sopenharmony_ci answer_type = "GLubyte" 411bf215546Sopenharmony_ci 412bf215546Sopenharmony_ci 413bf215546Sopenharmony_ci c = param.get_element_count() 414bf215546Sopenharmony_ci type_size = (param.size() / c) 415bf215546Sopenharmony_ci if type_size == 1: 416bf215546Sopenharmony_ci size_scale = "" 417bf215546Sopenharmony_ci else: 418bf215546Sopenharmony_ci size_scale = " * %u" % (type_size) 419bf215546Sopenharmony_ci 420bf215546Sopenharmony_ci 421bf215546Sopenharmony_ci if param.count_parameter_list: 422bf215546Sopenharmony_ci print ' const GLuint compsize = %s;' % (self.size_call(f, 1)) 423bf215546Sopenharmony_ci print ' %s answerBuffer[200];' % (answer_type) 424bf215546Sopenharmony_ci print ' %s %s = __glXGetAnswerBuffer(cl, compsize%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, size_scale, type_size ) 425bf215546Sopenharmony_ci answer_string = param.name 426bf215546Sopenharmony_ci answer_count = "compsize" 427bf215546Sopenharmony_ci 428bf215546Sopenharmony_ci print '' 429bf215546Sopenharmony_ci print ' if (%s == NULL) return BadAlloc;' % (param.name) 430bf215546Sopenharmony_ci print ' __glXClearErrorOccured();' 431bf215546Sopenharmony_ci print '' 432bf215546Sopenharmony_ci elif param.counter: 433bf215546Sopenharmony_ci print ' %s answerBuffer[200];' % (answer_type) 434bf215546Sopenharmony_ci print ' %s %s = __glXGetAnswerBuffer(cl, %s%s, answerBuffer, sizeof(answerBuffer), %u);' % (param.type_string(), param.name, param.counter, size_scale, type_size) 435bf215546Sopenharmony_ci answer_string = param.name 436bf215546Sopenharmony_ci answer_count = param.counter 437bf215546Sopenharmony_ci print '' 438bf215546Sopenharmony_ci print ' if (%s == NULL) return BadAlloc;' % (param.name) 439bf215546Sopenharmony_ci print ' __glXClearErrorOccured();' 440bf215546Sopenharmony_ci print '' 441bf215546Sopenharmony_ci elif c >= 1: 442bf215546Sopenharmony_ci print ' %s %s[%u];' % (answer_type, param.name, c) 443bf215546Sopenharmony_ci answer_string = param.name 444bf215546Sopenharmony_ci answer_count = "%u" % (c) 445bf215546Sopenharmony_ci 446bf215546Sopenharmony_ci if f.reply_always_array: 447bf215546Sopenharmony_ci is_array_string = "GL_TRUE" 448bf215546Sopenharmony_ci 449bf215546Sopenharmony_ci 450bf215546Sopenharmony_ci self.emit_function_call(f, retval_assign, " ") 451bf215546Sopenharmony_ci 452bf215546Sopenharmony_ci 453bf215546Sopenharmony_ci if f.needs_reply(): 454bf215546Sopenharmony_ci if self.do_swap: 455bf215546Sopenharmony_ci for param in f.parameterIterateOutputs(): 456bf215546Sopenharmony_ci c = param.get_element_count() 457bf215546Sopenharmony_ci type_size = (param.size() / c) 458bf215546Sopenharmony_ci 459bf215546Sopenharmony_ci if type_size > 1: 460bf215546Sopenharmony_ci swap_name = self.swap_name( type_size ) 461bf215546Sopenharmony_ci print ' (void) %s( (uint%u_t *) %s, %s );' % (swap_name, 8 * type_size, param.name, answer_count) 462bf215546Sopenharmony_ci 463bf215546Sopenharmony_ci 464bf215546Sopenharmony_ci reply_func = '__glXSendReplySwap' 465bf215546Sopenharmony_ci else: 466bf215546Sopenharmony_ci reply_func = '__glXSendReply' 467bf215546Sopenharmony_ci 468bf215546Sopenharmony_ci print ' %s(cl->client, %s, %s, %u, %s, %s);' % (reply_func, answer_string, answer_count, type_size, is_array_string, retval_string) 469bf215546Sopenharmony_ci #elif f.note_unflushed: 470bf215546Sopenharmony_ci # print ' cx->hasUnflushedCommands = GL_TRUE;' 471bf215546Sopenharmony_ci 472bf215546Sopenharmony_ci print ' error = Success;' 473bf215546Sopenharmony_ci print ' }' 474bf215546Sopenharmony_ci print '' 475bf215546Sopenharmony_ci print ' return error;' 476bf215546Sopenharmony_ci return 477bf215546Sopenharmony_ci 478bf215546Sopenharmony_ci 479bf215546Sopenharmony_ci def printRenderFunction(self, f): 480bf215546Sopenharmony_ci # There are 4 distinct phases in a rendering dispatch function. 481bf215546Sopenharmony_ci # In the first phase we compute the sizes and offsets of each 482bf215546Sopenharmony_ci # element in the command. In the second phase we (optionally) 483bf215546Sopenharmony_ci # re-align 64-bit data elements. In the third phase we 484bf215546Sopenharmony_ci # (optionally) byte-swap array data. Finally, in the fourth 485bf215546Sopenharmony_ci # phase we actually dispatch the function. 486bf215546Sopenharmony_ci 487bf215546Sopenharmony_ci self.common_func_print_just_start(f, "") 488bf215546Sopenharmony_ci 489bf215546Sopenharmony_ci images = f.get_images() 490bf215546Sopenharmony_ci if len(images): 491bf215546Sopenharmony_ci if self.do_swap: 492bf215546Sopenharmony_ci pre = "bswap_CARD32( & " 493bf215546Sopenharmony_ci post = " )" 494bf215546Sopenharmony_ci else: 495bf215546Sopenharmony_ci pre = "" 496bf215546Sopenharmony_ci post = "" 497bf215546Sopenharmony_ci 498bf215546Sopenharmony_ci img = images[0] 499bf215546Sopenharmony_ci 500bf215546Sopenharmony_ci # swapBytes and lsbFirst are single byte fields, so 501bf215546Sopenharmony_ci # the must NEVER be byte-swapped. 502bf215546Sopenharmony_ci 503bf215546Sopenharmony_ci if not (img.img_type == "GL_BITMAP" and img.img_format == "GL_COLOR_INDEX"): 504bf215546Sopenharmony_ci print ' glPixelStorei(GL_UNPACK_SWAP_BYTES, hdr->swapBytes);' 505bf215546Sopenharmony_ci 506bf215546Sopenharmony_ci print ' glPixelStorei(GL_UNPACK_LSB_FIRST, hdr->lsbFirst);' 507bf215546Sopenharmony_ci 508bf215546Sopenharmony_ci print ' glPixelStorei(GL_UNPACK_ROW_LENGTH, (GLint) %shdr->rowLength%s);' % (pre, post) 509bf215546Sopenharmony_ci if img.depth: 510bf215546Sopenharmony_ci print ' glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, (GLint) %shdr->imageHeight%s);' % (pre, post) 511bf215546Sopenharmony_ci print ' glPixelStorei(GL_UNPACK_SKIP_ROWS, (GLint) %shdr->skipRows%s);' % (pre, post) 512bf215546Sopenharmony_ci if img.depth: 513bf215546Sopenharmony_ci print ' glPixelStorei(GL_UNPACK_SKIP_IMAGES, (GLint) %shdr->skipImages%s);' % (pre, post) 514bf215546Sopenharmony_ci print ' glPixelStorei(GL_UNPACK_SKIP_PIXELS, (GLint) %shdr->skipPixels%s);' % (pre, post) 515bf215546Sopenharmony_ci print ' glPixelStorei(GL_UNPACK_ALIGNMENT, (GLint) %shdr->alignment%s);' % (pre, post) 516bf215546Sopenharmony_ci print '' 517bf215546Sopenharmony_ci 518bf215546Sopenharmony_ci 519bf215546Sopenharmony_ci self.emit_function_call(f, "", "") 520bf215546Sopenharmony_ci return 521bf215546Sopenharmony_ci 522bf215546Sopenharmony_ci 523bf215546Sopenharmony_cidef _parser(): 524bf215546Sopenharmony_ci """Parse any arguments passed and return a namespace.""" 525bf215546Sopenharmony_ci parser = argparse.ArgumentParser() 526bf215546Sopenharmony_ci parser.add_argument('-f', 527bf215546Sopenharmony_ci dest='filename', 528bf215546Sopenharmony_ci default='gl_API.xml', 529bf215546Sopenharmony_ci help='an xml file describing an OpenGL API') 530bf215546Sopenharmony_ci parser.add_argument('-m', 531bf215546Sopenharmony_ci dest='mode', 532bf215546Sopenharmony_ci default='dispatch_c', 533bf215546Sopenharmony_ci choices=['dispatch_c', 'dispatch_h'], 534bf215546Sopenharmony_ci help='what file to generate') 535bf215546Sopenharmony_ci parser.add_argument('-s', 536bf215546Sopenharmony_ci dest='swap', 537bf215546Sopenharmony_ci action='store_true', 538bf215546Sopenharmony_ci help='emit swap in GlXDispatchFunctions') 539bf215546Sopenharmony_ci return parser.parse_args() 540bf215546Sopenharmony_ci 541bf215546Sopenharmony_ci 542bf215546Sopenharmony_cidef main(): 543bf215546Sopenharmony_ci """Main function.""" 544bf215546Sopenharmony_ci args = _parser() 545bf215546Sopenharmony_ci 546bf215546Sopenharmony_ci if args.mode == "dispatch_c": 547bf215546Sopenharmony_ci printer = PrintGlxDispatchFunctions(args.swap) 548bf215546Sopenharmony_ci elif args.mode == "dispatch_h": 549bf215546Sopenharmony_ci printer = PrintGlxDispatch_h() 550bf215546Sopenharmony_ci 551bf215546Sopenharmony_ci api = gl_XML.parse_GL_API( 552bf215546Sopenharmony_ci args.filename, glX_proto_common.glx_proto_item_factory()) 553bf215546Sopenharmony_ci 554bf215546Sopenharmony_ci printer.Print(api) 555bf215546Sopenharmony_ci 556bf215546Sopenharmony_ci 557bf215546Sopenharmony_ciif __name__ == '__main__': 558bf215546Sopenharmony_ci main() 559