Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: gpu/command_buffer/build_gles2_cmd_buffer.py

Issue 2689006: Refactor validation code so it can be modified at runtime.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gpu/command_buffer/service/context_group.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """code generator for GLES2 command buffers.""" 7 """code generator for GLES2 command buffers."""
8 8
9 import os 9 import os
10 import os.path 10 import os.path
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint x, GLint y); 153 GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint x, GLint y);
154 GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint* v); 154 GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint* v);
155 GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat x, GLfl oat y, GLfloat z); 155 GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat x, GLfl oat y, GLfloat z);
156 GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat* v); 156 GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat* v);
157 GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint x, GLint y, GLint z); 157 GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint x, GLint y, GLint z);
158 GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint* v); 158 GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint* v);
159 GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat x, GLfl oat y, GLfloat z, GLfloat w); 159 GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat x, GLfl oat y, GLfloat z, GLfloat w);
160 GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat* v); 160 GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat* v);
161 GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w); 161 GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint x, GLint y, GLint z, GLint w);
162 GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint* v); 162 GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint* v);
163 GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLbooleanFalse transpose, const GLfloat* value); 163 GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLbooleanFalseOnly transpose, const GLfloat* value);
164 GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLbooleanFalse transpose, const GLfloat* value); 164 GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLbooleanFalseOnly transpose, const GLfloat* value);
165 GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLbooleanFalse transpose, const GLfloat* value); 165 GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLbooleanFalseOnly transpose, const GLfloat* value);
166 GL_APICALL void GL_APIENTRY glUseProgram (GLidZeroProgram program); 166 GL_APICALL void GL_APIENTRY glUseProgram (GLidZeroProgram program);
167 GL_APICALL void GL_APIENTRY glValidateProgram (GLidProgram program); 167 GL_APICALL void GL_APIENTRY glValidateProgram (GLidProgram program);
168 GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint indx, GLfloat x); 168 GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint indx, GLfloat x);
169 GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint indx, const GLfloa t* values); 169 GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint indx, const GLfloa t* values);
170 GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint indx, GLfloat x, GL float y); 170 GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint indx, GLfloat x, GL float y);
171 GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint indx, const GLfloa t* values); 171 GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint indx, const GLfloa t* values);
172 GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint indx, GLfloat x, GL float y, GLfloat z); 172 GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint indx, GLfloat x, GL float y, GLfloat z);
173 GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint indx, const GLfloa t* values); 173 GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint indx, const GLfloa t* values);
174 GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GL float y, GLfloat z, GLfloat w); 174 GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GL float y, GLfloat z, GLfloat w);
175 GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloa t* values); 175 GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloa t* values);
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 '1', 940 '1',
941 '2', 941 '2',
942 '3', 942 '3',
943 '4', 943 '4',
944 ], 944 ],
945 'invalid': [ 945 'invalid': [
946 '0', 946 '0',
947 '5', 947 '5',
948 ], 948 ],
949 }, 949 },
950 'False': { 950 'FalseOnly': {
951 'type': 'GLboolean', 951 'type': 'GLboolean',
952 'valid': [ 952 'valid': [
953 'false', 953 'false',
954 ], 954 ],
955 'invalid': [ 955 'invalid': [
956 'true', 956 'true',
957 ], 957 ],
958 }, 958 },
959 } 959 }
960 960
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 'decoder_func': 'DoVertexAttrib4fv', 1445 'decoder_func': 'DoVertexAttrib4fv',
1446 }, 1446 },
1447 'VertexAttribPointer': { 1447 'VertexAttribPointer': {
1448 'type': 'Manual', 1448 'type': 'Manual',
1449 'cmd_args': 'GLuint indx, GLint size, GLenum type, GLboolean normalized, ' 1449 'cmd_args': 'GLuint indx, GLint size, GLenum type, GLboolean normalized, '
1450 'GLsizei stride, GLuint offset', 1450 'GLsizei stride, GLuint offset',
1451 }, 1451 },
1452 } 1452 }
1453 1453
1454 1454
1455 def SplitWords(input_string):
1456 """Transforms a input_string into a list of lower-case components.
1457
1458 Args:
1459 input_string: the input string.
1460
1461 Returns:
1462 a list of lower-case words.
1463 """
1464 if input_string.find('_') > -1:
1465 # 'some_TEXT_' -> 'some text'
1466 return input_string.replace('_', ' ').strip().lower().split()
1467 else:
1468 if re.search('[A-Z]', input_string) and re.search('[a-z]', input_string):
1469 # mixed case.
1470 # look for capitalization to cut input_strings
1471 # 'SomeText' -> 'Some Text'
1472 input_string = re.sub('([A-Z])', r' \1', input_string).strip()
1473 # 'Vector3' -> 'Vector 3'
1474 input_string = re.sub('([^0-9])([0-9])', r'\1 \2', input_string)
1475 return input_string.lower().split()
1476
1477
1478 def Lower(words):
1479 """Makes a lower-case identifier from words.
1480
1481 Args:
1482 words: a list of lower-case words.
1483
1484 Returns:
1485 the lower-case identifier.
1486 """
1487 return '_'.join(words)
1488
1489
1490 def ToUnderscore(input_string):
1491 """converts CamelCase to camel_case."""
1492 words = SplitWords(input_string)
1493 return Lower(words)
1494
1495
1455 class CWriter(object): 1496 class CWriter(object):
1456 """Writes to a file formatting it for Google's style guidelines.""" 1497 """Writes to a file formatting it for Google's style guidelines."""
1457 1498
1458 def __init__(self, filename): 1499 def __init__(self, filename):
1459 self.filename = filename 1500 self.filename = filename
1460 self.file = open(filename, "wb") 1501 self.file = open(filename, "wb")
1461 self.file_num = 0 1502 self.file_num = 0
1462 1503
1463 def SetFileNum(self, num): 1504 def SetFileNum(self, num):
1464 """Used to help write number files and tests.""" 1505 """Used to help write number files and tests."""
(...skipping 2434 matching lines...) Expand 10 before | Expand all | Expand 10 after
3899 3940
3900 class EnumBaseArgument(Argument): 3941 class EnumBaseArgument(Argument):
3901 """Base class for EnumArgument, IntArgument and BoolArgument""" 3942 """Base class for EnumArgument, IntArgument and BoolArgument"""
3902 3943
3903 def __init__(self, name, gl_type, type, gl_error): 3944 def __init__(self, name, gl_type, type, gl_error):
3904 Argument.__init__(self, name, gl_type) 3945 Argument.__init__(self, name, gl_type)
3905 3946
3906 self.local_type = type 3947 self.local_type = type
3907 self.gl_error = gl_error 3948 self.gl_error = gl_error
3908 name = type[len(gl_type):] 3949 name = type[len(gl_type):]
3950 self.type_name = name
3909 self.enum_info = _ENUM_LISTS[name] 3951 self.enum_info = _ENUM_LISTS[name]
3910 3952
3911 def WriteValidationCode(self, file, func): 3953 def WriteValidationCode(self, file, func):
3912 file.Write(" if (!Validate%s(%s)) {\n" % (self.local_type, self.name)) 3954 file.Write(" if (!validators_->%s.IsValid(%s)) {\n" %
3955 (ToUnderscore(self.type_name), self.name))
3913 file.Write(" SetGLError(%s, \"gl%s: %s %s\");\n" % 3956 file.Write(" SetGLError(%s, \"gl%s: %s %s\");\n" %
3914 (self.gl_error, func.original_name, self.name, self.gl_error)) 3957 (self.gl_error, func.original_name, self.name, self.gl_error))
3915 file.Write(" return error::kNoError;\n") 3958 file.Write(" return error::kNoError;\n")
3916 file.Write(" }\n") 3959 file.Write(" }\n")
3917 3960
3918 def GetValidArg(self, offset, index): 3961 def GetValidArg(self, offset, index):
3919 if 'valid' in self.enum_info: 3962 if 'valid' in self.enum_info:
3920 valid = self.enum_info['valid'] 3963 valid = self.enum_info['valid']
3921 num_valid = len(valid) 3964 num_valid = len(valid)
3922 if index >= num_valid: 3965 if index >= num_valid:
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
4895 "// This file is included by gles2_implementation.h to declare the\n" 4938 "// This file is included by gles2_implementation.h to declare the\n"
4896 "// GL api functions.\n") 4939 "// GL api functions.\n")
4897 for func in self.original_functions: 4940 for func in self.original_functions:
4898 func.WriteGLES2ImplementationHeader(file) 4941 func.WriteGLES2ImplementationHeader(file)
4899 file.Close() 4942 file.Close()
4900 4943
4901 def WriteServiceUtilsHeader(self, filename): 4944 def WriteServiceUtilsHeader(self, filename):
4902 """Writes the gles2 auto generated utility header.""" 4945 """Writes the gles2 auto generated utility header."""
4903 file = CHeaderWriter(filename) 4946 file = CHeaderWriter(filename)
4904 for enum in sorted(_ENUM_LISTS.keys()): 4947 for enum in sorted(_ENUM_LISTS.keys()):
4905 file.Write("bool Validate%s%s(GLenum value);\n" % (_ENUM_LISTS[enum]['type '], enum)) 4948 file.Write("ValueValidator<%s> %s;\n" %
4949 (_ENUM_LISTS[enum]['type'], ToUnderscore(enum)))
4906 file.Write("\n") 4950 file.Write("\n")
4907 file.Close() 4951 file.Close()
4908 4952
4909 def WriteServiceUtilsImplementation(self, filename): 4953 def WriteServiceUtilsImplementation(self, filename):
4910 """Writes the gles2 auto generated utility implementation.""" 4954 """Writes the gles2 auto generated utility implementation."""
4911 file = CHeaderWriter(filename) 4955 file = CHeaderWriter(filename)
4912 for enum in sorted(_ENUM_LISTS.keys()): 4956 enums = sorted(_ENUM_LISTS.keys())
4913 file.Write("bool Validate%s%s(GLenum value) {\n" % (_ENUM_LISTS[enum]['typ e'], enum)) 4957 for enum in enums:
4914 file.Write(" switch (value) {\n") 4958 file.Write("static %s valid_%s_table[] = {\n" %
4959 (_ENUM_LISTS[enum]['type'], ToUnderscore(enum)))
4915 for value in _ENUM_LISTS[enum]['valid']: 4960 for value in _ENUM_LISTS[enum]['valid']:
4916 file.Write(" case %s:\n" % value) 4961 file.Write(" %s,\n" % value)
4917 file.Write(" return true;\n") 4962 file.Write("};\n")
4918 file.Write(" default:\n")
4919 file.Write(" return false;\n")
4920 file.Write(" }\n")
4921 file.Write("}\n")
4922 file.Write("\n") 4963 file.Write("\n")
4964 file.Write("Validators::Validators()\n")
4965 pre = ': '
4966 post = ','
4967 count = 0
4968 for enum in enums:
4969 count += 1
4970 if count == len(enums):
4971 post = ' {'
4972 code = """ %(pre)s%(name)s(
4973 valid_%(name)s_table, arraysize(valid_%(name)s_table))%(post)s
4974 """
4975 file.Write(code % {
4976 'name': ToUnderscore(enum),
4977 'pre': pre,
4978 'post': post,
4979 })
4980 pre = ' '
4981 file.Write("}\n");
4923 file.Close() 4982 file.Close()
4924 4983
4925 4984
4926 def main(argv): 4985 def main(argv):
4927 """This is the main function.""" 4986 """This is the main function."""
4928 parser = OptionParser() 4987 parser = OptionParser()
4929 parser.add_option( 4988 parser.add_option(
4930 "-g", "--generate-implementation-templates", action="store_true", 4989 "-g", "--generate-implementation-templates", action="store_true",
4931 help="generates files that are generally hand edited..") 4990 help="generates files that are generally hand edited..")
4932 parser.add_option( 4991 parser.add_option(
(...skipping 27 matching lines...) Expand all
4960 5019
4961 if options.generate_docs: 5020 if options.generate_docs:
4962 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h") 5021 gen.WriteDocs("docs/gles2_cmd_format_docs_autogen.h")
4963 5022
4964 if gen.errors > 0: 5023 if gen.errors > 0:
4965 print "%d errors" % gen.errors 5024 print "%d errors" % gen.errors
4966 sys.exit(1) 5025 sys.exit(1)
4967 5026
4968 if __name__ == '__main__': 5027 if __name__ == '__main__':
4969 main(sys.argv[1:]) 5028 main(sys.argv[1:])
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/service/context_group.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698