From 1d27084043855d2609b54d3435f0bd85e39762e2 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 21 Dec 2004 21:26:36 +0000 Subject: [PATCH] Added some comments and fixed typeos. Slightly refactored the way function parameters are iterated. There are no changes in the generated code. --- src/mesa/glapi/glX_XML.py | 72 +++++++++++++++++++++++++++++++- src/mesa/glapi/glX_proto_send.py | 21 +++------- src/mesa/glapi/gl_XML.py | 13 +++--- src/mesa/glapi/gl_apitemp.py | 2 +- src/mesa/glapi/gl_x86_asm.py | 2 +- 5 files changed, 87 insertions(+), 23 deletions(-) diff --git a/src/mesa/glapi/glX_XML.py b/src/mesa/glapi/glX_XML.py index 44f945a9ee4..35341320537 100644 --- a/src/mesa/glapi/glX_XML.py +++ b/src/mesa/glapi/glX_XML.py @@ -263,6 +263,42 @@ class glXParameter(gl_XML.glParameter): gl_XML.glParameter.__init__(self, context, name, attrs); +class glXParameterIterator: + """Class to iterate over a list of glXParameters. + + Objects of this class are returned by the parameterIterator method of + the glXFunction class. They are used to iterate over the list of + parameters to the function.""" + + def __init__(self, data, skip_output, max_order): + self.data = data + self.index = 0 + self.order = 0 + self.skip_output = skip_output + self.max_order = max_order + + def __iter__(self): + return self + + def next(self): + if len( self.data ) == 0: + raise StopIteration + + while 1: + if self.index == len( self.data ): + if self.order == self.max_order: + raise StopIteration + else: + self.order += 1 + self.index = 0 + + i = self.index + self.index += 1 + + if self.data[i].order == self.order and not (self.data[i].is_output and self.skip_output): + return self.data[i] + + class glXFunction(gl_XML.glFunction): glx_rop = 0 glx_sop = 0 @@ -293,6 +329,11 @@ class glXFunction(gl_XML.glFunction): gl_XML.glFunction.__init__(self, context, name, attrs) return + + def parameterIterator(self, skip_output, max_order): + return glXParameterIterator(self.fn_parameters, skip_output, max_order) + + def startElement(self, name, attrs): """Process elements within a function that are specific to GLX.""" @@ -360,7 +401,7 @@ class glXFunction(gl_XML.glFunction): def command_payload_length(self): size = 0 size_string = "" - for p in self: + for p in gl_XML.glFunction.parameterIterator(self): if p.is_output: continue temp = p.size_string() try: @@ -382,6 +423,16 @@ class glXFunction(gl_XML.glFunction): def opcode_real_value(self): + """Get the true numeric value of the GLX opcode + + Behaves similarly to opcode_value, except for + X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands. + In these cases the value for the GLX opcode field (i.e., + 16 for X_GLXVendorPrivate or 17 for + X_GLXVendorPrivateWithReply) is returned. For other 'single' + commands, the opcode for the command (e.g., 101 for + X_GLsop_NewList) is returned.""" + if self.glx_vendorpriv != 0: if self.needs_reply(): return 17 @@ -391,6 +442,8 @@ class glXFunction(gl_XML.glFunction): return self.opcode_value() def opcode_value(self): + """Get the unique protocol opcode for the glXFunction""" + if self.glx_rop != 0: return self.glx_rop elif self.glx_sop != 0: @@ -401,12 +454,20 @@ class glXFunction(gl_XML.glFunction): return -1 def opcode_rop_basename(self): + """Return either the name to be used for GLX protocol enum. + + Returns either the name of the function or the name of the + name of the equivalent vector (e.g., glVertex3fv for + glVertex3f) function.""" + if self.vectorequiv == None: return self.name else: return self.vectorequiv def opcode_name(self): + """Get the unique protocol enum name for the glXFunction""" + if self.glx_rop != 0: return "X_GLrop_%s" % (self.opcode_rop_basename()) elif self.glx_sop != 0: @@ -417,6 +478,15 @@ class glXFunction(gl_XML.glFunction): return "ERROR" def opcode_real_name(self): + """Get the true protocol enum name for the GLX opcode + + Behaves similarly to opcode_name, except for + X_GLXVendorPrivate and X_GLXVendorPrivateWithReply commands. + In these cases the string 'X_GLXVendorPrivate' or + 'X_GLXVendorPrivateWithReply' is returned. For other + single or render commands 'X_GLsop' or 'X_GLrop' plus the + name of the function returned.""" + if self.glx_vendorpriv != 0: if self.needs_reply(): return "X_GLXVendorPrivateWithReply" diff --git a/src/mesa/glapi/glX_proto_send.py b/src/mesa/glapi/glX_proto_send.py index 2b688ace156..418f140df45 100644 --- a/src/mesa/glapi/glX_proto_send.py +++ b/src/mesa/glapi/glX_proto_send.py @@ -153,8 +153,6 @@ generic_%u_byte( GLint rop, const void * ptr ) def common_emit_one_arg(self, p, offset, pc, indent, adjust): - if p.is_output: return - t = p.p_type if p.is_array(): src_ptr = p.name @@ -165,23 +163,16 @@ generic_%u_byte( GLint rop, const void * ptr ) % (indent, pc, offset + adjust, src_ptr, p.size_string() ) def common_emit_args(self, f, pc, indent, adjust, skip_vla): - # First emit all of the fixed-length 8-byte (i.e., GLdouble) - # parameters. - offset = 0 if skip_vla: - r = [0, 1] + r = 1 else: - r = [0, 1, 2] - - for order in r: - for p in f: - if p.is_output or p.order != order: continue - - self.common_emit_one_arg(p, offset, pc, indent, adjust) - offset += p.size() + r = 2 + for p in f.parameterIterator(1, r): + self.common_emit_one_arg(p, offset, pc, indent, adjust) + offset += p.size() return offset @@ -274,7 +265,7 @@ generic_%u_byte( GLint rop, const void * ptr ) # of data, and the protocol for this functions is very # regular. Since they are so regular and there are so many # of them, special case them with generic functions. On - # x86, this save about 26KB in the libGL.so binary. + # x86, this saves about 26KB in the libGL.so binary. if f.variable_length_parameter() == None and len(f.fn_parameters) == 1: p = f.fn_parameters[0] diff --git a/src/mesa/glapi/gl_XML.py b/src/mesa/glapi/gl_XML.py index 79da5abab9b..a58f2851556 100644 --- a/src/mesa/glapi/gl_XML.py +++ b/src/mesa/glapi/gl_XML.py @@ -252,14 +252,17 @@ class glParameter( glItem ): class glParameterIterator: """Class to iterate over a list of glParameters. - Objects of this class are returned by the __iter__ method of the - glFunction class. They are used to iterate over the list of + Objects of this class are returned by the parameterIterator method of + the glFunction class. They are used to iterate over the list of parameters to the function.""" def __init__(self, data): self.data = data self.index = 0 - + + def __iter__(self): + return self + def next(self): if self.index == len( self.data ): raise StopIteration @@ -295,7 +298,7 @@ class glFunction( glItem ): return - def __iter__(self): + def parameterIterator(self): return glParameterIterator(self.fn_parameters) @@ -325,7 +328,7 @@ class glFunction( glItem ): def get_parameter_string(self): arg_string = "" comma = "" - for p in self: + for p in glFunction.parameterIterator(self): arg_string = arg_string + comma + p.p_type_string + " " + p.name comma = ", " diff --git a/src/mesa/glapi/gl_apitemp.py b/src/mesa/glapi/gl_apitemp.py index 1e5c3f4efa5..533cc65becd 100644 --- a/src/mesa/glapi/gl_apitemp.py +++ b/src/mesa/glapi/gl_apitemp.py @@ -48,7 +48,7 @@ class PrintGlOffsets(gl_XML.FilterGLAPISpecBase): t_string = "" comma = "" - for p in f: + for p in f.parameterIterator(): cast = "" if p.is_pointer: diff --git a/src/mesa/glapi/gl_x86_asm.py b/src/mesa/glapi/gl_x86_asm.py index 47cef805473..f87065a5af2 100644 --- a/src/mesa/glapi/gl_x86_asm.py +++ b/src/mesa/glapi/gl_x86_asm.py @@ -45,7 +45,7 @@ class PrintGenericStubs(gl_XML.FilterGLAPISpecBase): def get_stack_size(self, f): size = 0 - for p in f: + for p in f.parameterIterator(): t = p.p_type if p.is_array() or t.size != 8: -- 2.30.2