mesa: add support for AlphaToCoverageDitherControlNV
[mesa.git] / src / mapi / glapi / gen / glX_proto_size.py
index 59f65d49ce022ec6ba650388e82de87999606433..2a843c3e24115aae094d2f64283098019e22bcdc 100644 (file)
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 
 # (C) Copyright IBM Corporation 2004, 2005
 # All Rights Reserved.
@@ -25,6 +24,8 @@
 # Authors:
 #    Ian Romanick <idr@us.ibm.com>
 
+from __future__ import print_function
+
 import argparse
 import sys, string
 
@@ -70,7 +71,7 @@ class glx_enum_function(object):
         for enum_name in enum_dict:
             e = enum_dict[ enum_name ]
 
-            if e.functions.has_key( match_name ):
+            if match_name in e.functions:
                 [count, mode] = e.functions[ match_name ]
 
                 if mode_set and mode != self.mode:
@@ -78,11 +79,11 @@ class glx_enum_function(object):
 
                 self.mode = mode
 
-                if self.enums.has_key( e.value ):
+                if e.value in self.enums:
                     if e.name not in self.enums[ e.value ]:
                         self.enums[ e.value ].append( e )
                 else:
-                    if not self.count.has_key( count ):
+                    if count not in self.count:
                         self.count[ count ] = []
 
                     self.enums[ e.value ] = [ e ]
@@ -130,7 +131,7 @@ class glx_enum_function(object):
         for a in self.enums:
             count += 1
 
-        if self.count.has_key(-1):
+        if -1 in self.count:
             return 0
 
         # Determine if there is some mask M, such that M = (2^N) - 1,
@@ -168,19 +169,19 @@ class glx_enum_function(object):
                     masked_count[i] = c
 
 
-            print '    static const GLushort a[%u] = {' % (mask + 1)
+            print('    static const GLushort a[%u] = {' % (mask + 1))
             for e in masked_enums:
-                print '        %s, ' % (masked_enums[e])
-            print '    };'
+                print('        %s, ' % (masked_enums[e]))
+            print('    };')
 
-            print '    static const GLubyte b[%u] = {' % (mask + 1)
+            print('    static const GLubyte b[%u] = {' % (mask + 1))
             for c in masked_count:
-                print '        %u, ' % (masked_count[c])
-            print '    };'
+                print('        %u, ' % (masked_count[c]))
+            print('    };')
 
-            print '    const unsigned idx = (e & 0x%02xU);' % (mask)
-            print ''
-            print '    return (e == a[idx]) ? (GLint) b[idx] : 0;'
+            print('    const unsigned idx = (e & 0x%02xU);' % (mask))
+            print('')
+            print('    return (e == a[idx]) ? (GLint) b[idx] : 0;')
             return 1;
         else:
             return 0;
@@ -190,9 +191,9 @@ class glx_enum_function(object):
         """Emit the body of the __gl*_size function using a 
         switch-statement."""
 
-        print '    switch( e ) {'
+        print('    switch( e ) {')
 
-        for c in self.count:
+        for c in sorted(self.count):
             for e in self.count[c]:
                 first = 1
 
@@ -207,35 +208,34 @@ class glx_enum_function(object):
                 for enum_obj in self.enums[e]:
                     list[ enum_obj.priority() ] = enum_obj.name
 
-                keys = list.keys()
-                keys.sort()
+                keys = sorted(list.keys())
                 for k in keys:
                     j = list[k]
                     if first:
-                        print '        case GL_%s:' % (j)
+                        print('        case GL_%s:' % (j))
                         first = 0
                     else:
-                        print '/*      case GL_%s:*/' % (j)
+                        print('/*      case GL_%s:*/' % (j))
 
             if c == -1:
-                print '            return __gl%s_variable_size( e );' % (name)
+                print('            return __gl%s_variable_size( e );' % (name))
             else:
-                print '            return %u;' % (c)
+                print('            return %u;' % (c))
 
-        print '        default: return 0;'
-        print '    }'
+        print('        default: return 0;')
+        print('    }')
 
 
     def Print(self, name):
-        print '_X_INTERNAL PURE FASTCALL GLint'
-        print '__gl%s_size( GLenum e )' % (name)
-        print '{'
+        print('_X_INTERNAL PURE FASTCALL GLint')
+        print('__gl%s_size( GLenum e )' % (name))
+        print('{')
 
         if not self.PrintUsingTable():
             self.PrintUsingSwitch(name)
 
-        print '}'
-        print ''
+        print('}')
+        print('')
 
 
 class glx_server_enum_function(glx_enum_function):
@@ -274,8 +274,7 @@ class glx_server_enum_function(glx_enum_function):
             o = f.offset_of( param_name )
             foo[o] = param_name
 
-        keys = foo.keys()
-        keys.sort()
+        keys = sorted(foo.keys())
         for o in keys:
             p = f.parameters_by_name[ foo[o] ]
 
@@ -283,18 +282,18 @@ class glx_server_enum_function(glx_enum_function):
             fixup.append( p.name )
 
 
-        print '    GLsizei compsize;'
-        print ''
+        print('    GLsizei compsize;')
+        print('')
 
         printer.common_emit_fixups(fixup)
 
-        print ''
-        print '    compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ","))
+        print('')
+        print('    compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ",")))
         p = f.variable_length_parameter()
-        print '    return __GLX_PAD(%s);' % (p.size_string())
+        print('    return safe_pad(%s);' % (p.size_string()))
 
-        print '}'
-        print ''
+        print('}')
+        print('')
 
 
 class PrintGlxSizeStubs_common(gl_XML.gl_print_base):
@@ -314,37 +313,34 @@ class PrintGlxSizeStubs_common(gl_XML.gl_print_base):
 
 class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common):
     def printRealHeader(self):
-        print ''
-        print '#include <X11/Xfuncproto.h>'
-        print '#include <GL/gl.h>'
+        print('')
+        print('#include <X11/Xfuncproto.h>')
+        print('#include <GL/gl.h>')
         if self.emit_get:
-            print '#include "indirect_size_get.h"'
-            print '#include "glxserver.h"'
-            print '#include "indirect_util.h"'
+            print('#include "indirect_size_get.h"')
+            print('#include "glxserver.h"')
+            print('#include "indirect_util.h"')
 
-        print '#include "indirect_size.h"'
+        print('#include "indirect_size.h"')
 
-        print ''
+        print('')
         self.printPure()
-        print ''
+        print('')
         self.printFastcall()
-        print ''
-        print ''
-        print '#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(GLX_USE_APPLEGL)'
-        print '#  undef HAVE_ALIAS'
-        print '#endif'
-        print '#ifdef HAVE_ALIAS'
-        print '#  define ALIAS2(from,to) \\'
-        print '    _X_INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\'
-        print '        __attribute__ ((alias( # to )));'
-        print '#  define ALIAS(from,to) ALIAS2( from, __gl ## to ## _size )'
-        print '#else'
-        print '#  define ALIAS(from,to) \\'
-        print '    _X_INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\'
-        print '    { return __gl ## to ## _size( e ); }'
-        print '#endif'
-        print ''
-        print ''
+        print('')
+        print('')
+        print('#ifdef HAVE_FUNC_ATTRIBUTE_ALIAS')
+        print('#  define ALIAS2(from,to) \\')
+        print('    _X_INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\')
+        print('        __attribute__ ((alias( # to )));')
+        print('#  define ALIAS(from,to) ALIAS2( from, __gl ## to ## _size )')
+        print('#else')
+        print('#  define ALIAS(from,to) \\')
+        print('    _X_INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\')
+        print('    { return __gl ## to ## _size( e ); }')
+        print('#endif')
+        print('')
+        print('')
 
 
     def printBody(self, api):
@@ -358,7 +354,7 @@ class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common):
 
             if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get):
                 sig = ef.signature()
-                if enum_sigs.has_key( sig ):
+                if sig in enum_sigs:
                     aliases.append( [func.name, enum_sigs[ sig ]] )
                 else:
                     enum_sigs[ sig ] = func.name
@@ -366,26 +362,26 @@ class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common):
 
 
         for [alias_name, real_name] in aliases:
-            print 'ALIAS( %s, %s )' % (alias_name, real_name)
+            print('ALIAS( %s, %s )' % (alias_name, real_name))
 
 
 
 class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common):
     def printRealHeader(self):
-        print """/**
+        print("""/**
  * \\file
  * Prototypes for functions used to determine the number of data elements in
  * various GLX protocol messages.
  *
  * \\author Ian Romanick <idr@us.ibm.com>
  */
-"""
-        print '#include <X11/Xfuncproto.h>'
-        print ''
+""")
+        print('#include <X11/Xfuncproto.h>')
+        print('')
         self.printPure();
-        print ''
+        print('')
         self.printFastcall();
-        print ''
+        print('')
 
 
     def printBody(self, api):
@@ -395,7 +391,7 @@ class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common):
                 continue
 
             if (ef.is_set() and self.emit_set) or (not ef.is_set() and self.emit_get):
-                print 'extern _X_INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (func.name)
+                print('extern _X_INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (func.name))
 
 
 class PrintGlxReqSize_common(gl_XML.gl_print_base):
@@ -419,16 +415,16 @@ class PrintGlxReqSize_h(PrintGlxReqSize_common):
 
 
     def printRealHeader(self):
-        print '#include <X11/Xfuncproto.h>'
-        print ''
+        print('#include <X11/Xfuncproto.h>')
+        print('')
         self.printPure()
-        print ''
+        print('')
 
 
     def printBody(self, api):
         for func in api.functionIterateGlx():
             if not func.ignore and func.has_variable_size_request():
-                print 'extern PURE _X_HIDDEN int __glX%sReqSize(const GLbyte *pc, Bool swap);' % (func.name)
+                print('extern PURE _X_HIDDEN int __glX%sReqSize(const GLbyte *pc, Bool swap, int reqlen);' % (func.name))
 
 
 class PrintGlxReqSize_c(PrintGlxReqSize_common):
@@ -445,30 +441,25 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
 
 
     def printRealHeader(self):
-        print ''
-        print '#include <GL/gl.h>'
-        print '#include "glxserver.h"'
-        print '#include "glxbyteorder.h"'
-        print '#include "indirect_size.h"'
-        print '#include "indirect_reqsize.h"'
-        print ''
-        print '#define __GLX_PAD(x)  (((x) + 3) & ~3)'
-        print ''
-        print '#if defined(__CYGWIN__) || defined(__MINGW32__)'
-        print '#  undef HAVE_ALIAS'
-        print '#endif'
-        print '#ifdef HAVE_ALIAS'
-        print '#  define ALIAS2(from,to) \\'
-        print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\'
-        print '        __attribute__ ((alias( # to )));'
-        print '#  define ALIAS(from,to) ALIAS2( from, __glX ## to ## ReqSize )'
-        print '#else'
-        print '#  define ALIAS(from,to) \\'
-        print '    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap ) \\'
-        print '    { return __glX ## to ## ReqSize( pc, swap ); }'
-        print '#endif'
-        print ''
-        print ''
+        print('')
+        print('#include <GL/gl.h>')
+        print('#include "glxserver.h"')
+        print('#include "glxbyteorder.h"')
+        print('#include "indirect_size.h"')
+        print('#include "indirect_reqsize.h"')
+        print('')
+        print('#ifdef HAVE_FUNC_ATTRIBUTE_ALIAS')
+        print('#  define ALIAS2(from,to) \\')
+        print('    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap, int reqlen ) \\')
+        print('        __attribute__ ((alias( # to )));')
+        print('#  define ALIAS(from,to) ALIAS2( from, __glX ## to ## ReqSize )')
+        print('#else')
+        print('#  define ALIAS(from,to) \\')
+        print('    GLint __glX ## from ## ReqSize( const GLbyte * pc, Bool swap, int reqlen ) \\')
+        print('    { return __glX ## to ## ReqSize( pc, swap, reqlen ); }')
+        print('#endif')
+        print('')
+        print('')
 
 
     def printBody(self, api):
@@ -484,10 +475,10 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
 
             sig = ef.signature()
 
-            if not enum_functions.has_key(func.name):
+            if func.name not in enum_functions:
                 enum_functions[ func.name ] = sig
 
-            if not enum_sigs.has_key( sig ):
+            if sig not in enum_sigs:
                 enum_sigs[ sig ] = ef
 
 
@@ -503,7 +494,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
             if func.server_handcode: continue
             if not func.has_variable_size_request(): continue
 
-            if enum_functions.has_key(func.name):
+            if func.name in enum_functions:
                 sig = enum_functions[func.name]
                 ef = enum_sigs[ sig ]
 
@@ -520,7 +511,7 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
 
 
         for [alias_name, real_name] in aliases:
-            print 'ALIAS( %s, %s )' % (alias_name, real_name)
+            print('ALIAS( %s, %s )' % (alias_name, real_name))
 
         return
 
@@ -529,10 +520,10 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
         """Utility function to emit conditional byte-swaps."""
 
         if fixup:
-            print '    if (swap) {'
+            print('    if (swap) {')
             for name in fixup:
-                print '        %s = bswap_32(%s);' % (name, name)
-            print '    }'
+                print('        %s = bswap_32(%s);' % (name, name))
+            print('    }')
 
         return
 
@@ -541,14 +532,14 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
         offset = p.offset
         dst = p.string()
         src = '(%s *)' % (p.type_string())
-        print '%-18s = *%11s(%s + %u);' % (dst, src, pc, offset + adjust);
+        print('%-18s = *%11s(%s + %u);' % (dst, src, pc, offset + adjust));
         return
 
 
     def common_func_print_just_header(self, f):
-        print 'int'
-        print '__glX%sReqSize( const GLbyte * pc, Bool swap )' % (f.name)
-        print '{'
+        print('int')
+        print('__glX%sReqSize( const GLbyte * pc, Bool swap, int reqlen )' % (f.name))
+        print('{')
 
 
     def printPixelFunction(self, f):
@@ -557,20 +548,20 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
         f.offset_of( f.parameters[0].name )
         [dim, w, h, d, junk] = f.get_images()[0].get_dimensions()
 
-        print '    GLint row_length   = *  (GLint *)(pc +  4);'
+        print('    GLint row_length   = *  (GLint *)(pc +  4);')
 
         if dim < 3:
             fixup = ['row_length', 'skip_rows', 'alignment']
-            print '    GLint image_height = 0;'
-            print '    GLint skip_images  = 0;'
-            print '    GLint skip_rows    = *  (GLint *)(pc +  8);'
-            print '    GLint alignment    = *  (GLint *)(pc + 16);'
+            print('    GLint image_height = 0;')
+            print('    GLint skip_images  = 0;')
+            print('    GLint skip_rows    = *  (GLint *)(pc +  8);')
+            print('    GLint alignment    = *  (GLint *)(pc + 16);')
         else:
             fixup = ['row_length', 'image_height', 'skip_rows', 'skip_images', 'alignment']
-            print '    GLint image_height = *  (GLint *)(pc +  8);'
-            print '    GLint skip_rows    = *  (GLint *)(pc + 16);'
-            print '    GLint skip_images  = *  (GLint *)(pc + 20);'
-            print '    GLint alignment    = *  (GLint *)(pc + 32);'
+            print('    GLint image_height = *  (GLint *)(pc +  8);')
+            print('    GLint skip_rows    = *  (GLint *)(pc + 16);')
+            print('    GLint skip_images  = *  (GLint *)(pc + 20);')
+            print('    GLint alignment    = *  (GLint *)(pc + 32);')
 
         img = f.images[0]
         for p in f.parameterIterateGlxSend():
@@ -578,21 +569,21 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
                 self.common_emit_one_arg(p, "pc", 0)
                 fixup.append( p.name )
 
-        print ''
+        print('')
 
         self.common_emit_fixups(fixup)
 
         if img.img_null_flag:
-            print ''
-            print '       if (*(CARD32 *) (pc + %s))' % (img.offset - 4)
-            print '           return 0;'
-
-        print ''
-        print '    return __glXImageSize(%s, %s, %s, %s, %s, %s,' % (img.img_format, img.img_type, img.img_target, w, h, d )
-        print '                          image_height, row_length, skip_images,'
-        print '                          skip_rows, alignment);'
-        print '}'
-        print ''
+            print('')
+            print('       if (*(CARD32 *) (pc + %s))' % (img.offset - 4))
+            print('           return 0;')
+
+        print('')
+        print('    return __glXImageSize(%s, %s, %s, %s, %s, %s,' % (img.img_format, img.img_type, img.img_target, w, h, d ))
+        print('                          image_height, row_length, skip_images,')
+        print('                          skip_rows, alignment);')
+        print('}')
+        print('')
         return
 
 
@@ -602,7 +593,6 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
         offset = 0
         fixup = []
         params = []
-        plus = ''
         size = ''
         param_offsets = {}
 
@@ -620,15 +610,16 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
                 if s == 0: s = 1
 
                 sig += "(%u,%u)" % (f.offset_of(p.counter), s)
-                size += '%s%s' % (plus, p.size_string())
-                plus = ' + '
-
+                if size == '':
+                    size = p.size_string()
+                else:
+                    size = "safe_add(%s, %s)" % (size, p.size_string())
 
         # If the calculated signature matches a function that has
         # already be emitted, don't emit this function.  Instead, add
         # it to the list of function aliases.
 
-        if self.counter_sigs.has_key(sig):
+        if sig in self.counter_sigs:
             n = self.counter_sigs[sig];
             alias = [f.name, n]
         else:
@@ -641,13 +632,13 @@ class PrintGlxReqSize_c(PrintGlxReqSize_common):
                 self.common_emit_one_arg(p, "pc", 0)
 
 
-            print ''
+            print('')
             self.common_emit_fixups(fixup)
-            print ''
+            print('')
 
-            print '    return __GLX_PAD(%s);' % (size)
-            print '}'
-            print ''
+            print('    return safe_pad(%s);' % (size))
+            print('}')
+            print('')
 
         return alias
 
@@ -684,7 +675,8 @@ def _parser():
     return parser.parse_args()
 
 
-if __name__ == '__main__':
+def main():
+    """Main function."""
     args = _parser()
 
     if args.mode == "size_c":
@@ -701,3 +693,7 @@ if __name__ == '__main__':
     api = gl_XML.parse_GL_API(args.filename, glX_XML.glx_item_factory())
 
     printer.Print(api)
+
+
+if __name__ == '__main__':
+    main()