| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """code generator for GLES2 command buffers.""" | 6 """code generator for GLES2 command buffers.""" |
| 7 | 7 |
| 8 import itertools | 8 import itertools |
| 9 import os | 9 import os |
| 10 import os.path | 10 import os.path |
| (...skipping 4226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4237 Returns: | 4237 Returns: |
| 4238 String that converts the state variable to desired GL type according to GL | 4238 String that converts the state variable to desired GL type according to GL |
| 4239 rules. | 4239 rules. |
| 4240 """ | 4240 """ |
| 4241 | 4241 |
| 4242 if result_type == 'GLint': | 4242 if result_type == 'GLint': |
| 4243 if value_type == 'GLfloat': | 4243 if value_type == 'GLfloat': |
| 4244 return 'static_cast<GLint>(round(%s))' % value | 4244 return 'static_cast<GLint>(round(%s))' % value |
| 4245 return 'static_cast<%s>(%s)' % (result_type, value) | 4245 return 'static_cast<%s>(%s)' % (result_type, value) |
| 4246 | 4246 |
| 4247 |
| 4247 class CWriter(object): | 4248 class CWriter(object): |
| 4248 """Writes to a file formatting it for Google's style guidelines.""" | 4249 """Context manager that creates a C source file. |
| 4249 | 4250 |
| 4251 To be used with the `with` statement. Returns a normal `file` type, open only |
| 4252 for writing - any existing files with that name will be overwritten. It will |
| 4253 automatically write the contents of `_LICENSE` and `_DO_NOT_EDIT_WARNING` |
| 4254 at the beginning. |
| 4255 |
| 4256 Example: |
| 4257 with CWriter("file.cpp") as myfile: |
| 4258 myfile.write("hello") |
| 4259 # type(myfile) == file |
| 4260 """ |
| 4250 def __init__(self, filename): | 4261 def __init__(self, filename): |
| 4251 self.filename = filename | 4262 self.filename = filename |
| 4252 self.content = [] | 4263 self._file = open(filename, 'w') |
| 4264 self._ENTER_MSG = _LICENSE + _DO_NOT_EDIT_WARNING |
| 4265 self._EXIT_MSG = "" |
| 4253 | 4266 |
| 4254 def write(self, string): | 4267 def __enter__(self): |
| 4255 """Writes a string to a file spliting if it's > 80 characters.""" | 4268 self._file.write(self._ENTER_MSG) |
| 4256 lines = string.splitlines() | 4269 return self._file |
| 4257 num_lines = len(lines) | |
| 4258 for ii in range(0, num_lines): | |
| 4259 self.content.append(lines[ii]) | |
| 4260 if ii < (num_lines - 1) or string[-1] == '\n': | |
| 4261 self.content.append('\n') | |
| 4262 | 4270 |
| 4263 def close(self): | 4271 def __exit__(self, exc_type, exc_value, traceback): |
| 4264 """Close the file.""" | 4272 self._file.write(self._EXIT_MSG) |
| 4265 content = "".join(self.content) | 4273 self._file.close() |
| 4266 write_file = True | |
| 4267 if os.path.exists(self.filename): | |
| 4268 old_file = open(self.filename, "rb"); | |
| 4269 old_content = old_file.read() | |
| 4270 old_file.close(); | |
| 4271 if content == old_content: | |
| 4272 write_file = False | |
| 4273 if write_file: | |
| 4274 f = open(self.filename, "wb") | |
| 4275 f.write(content) | |
| 4276 f.close() | |
| 4277 | 4274 |
| 4278 | 4275 |
| 4279 class CHeaderWriter(CWriter): | 4276 class CHeaderWriter(CWriter): |
| 4280 """Writes a C Header file.""" | 4277 """Context manager that creates a C header file. |
| 4281 | 4278 |
| 4282 _non_alnum_re = re.compile(r'[^a-zA-Z0-9]') | 4279 Works the same way as CWriter, except it will also add the #ifdef guard |
| 4280 around it. If `file_comment` is set, it will write that before the #ifdef |
| 4281 guard. |
| 4282 """ |
| 4283 def __init__(self, filename, file_comment=None): |
| 4284 super(CHeaderWriter, self).__init__(filename) |
| 4285 guard = self._get_guard() |
| 4286 if file_comment is None: |
| 4287 file_comment = "" |
| 4288 self._ENTER_MSG = self._ENTER_MSG + file_comment \ |
| 4289 + "#ifndef %s\n#define %s\n\n" % (guard, guard) |
| 4290 self._EXIT_MSG = self._EXIT_MSG + "#endif // %s\n" % guard |
| 4283 | 4291 |
| 4284 def __init__(self, filename, file_comment = None): | 4292 def _get_guard(self): |
| 4285 CWriter.__init__(self, filename) | 4293 non_alnum_re = re.compile(r'[^a-zA-Z0-9]') |
| 4286 | 4294 base = os.path.abspath(self.filename) |
| 4287 base = os.path.abspath(filename) | |
| 4288 while os.path.basename(base) != 'src': | 4295 while os.path.basename(base) != 'src': |
| 4289 new_base = os.path.dirname(base) | 4296 new_base = os.path.dirname(base) |
| 4290 assert new_base != base # Prevent infinite loop. | 4297 assert new_base != base # Prevent infinite loop. |
| 4291 base = new_base | 4298 base = new_base |
| 4299 hpath = os.path.relpath(self.filename, base) |
| 4300 return non_alnum_re.sub('_', hpath).upper() + '_' |
| 4292 | 4301 |
| 4293 hpath = os.path.relpath(filename, base) | |
| 4294 self.guard = self._non_alnum_re.sub('_', hpath).upper() + '_' | |
| 4295 | |
| 4296 self.write(_LICENSE) | |
| 4297 self.write(_DO_NOT_EDIT_WARNING) | |
| 4298 if not file_comment == None: | |
| 4299 self.write(file_comment) | |
| 4300 self.write("#ifndef %s\n" % self.guard) | |
| 4301 self.write("#define %s\n\n" % self.guard) | |
| 4302 | |
| 4303 def close(self): | |
| 4304 self.write("#endif // %s\n\n" % self.guard) | |
| 4305 CWriter.close(self) | |
| 4306 | 4302 |
| 4307 class TypeHandler(object): | 4303 class TypeHandler(object): |
| 4308 """This class emits code for a particular type of function.""" | 4304 """This class emits code for a particular type of function.""" |
| 4309 | 4305 |
| 4310 _remove_expected_call_re = re.compile(r' EXPECT_CALL.*?;\n', re.S) | 4306 _remove_expected_call_re = re.compile(r' EXPECT_CALL.*?;\n', re.S) |
| 4311 | 4307 |
| 4312 def __init__(self): | 4308 def __init__(self): |
| 4313 pass | 4309 pass |
| 4314 | 4310 |
| 4315 def InitFunction(self, func): | 4311 def InitFunction(self, func): |
| (...skipping 5575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9891 f.write("\n") | 9887 f.write("\n") |
| 9892 | 9888 |
| 9893 def WriteNamespaceClose(self, f): | 9889 def WriteNamespaceClose(self, f): |
| 9894 """Writes the code to close the namespace.""" | 9890 """Writes the code to close the namespace.""" |
| 9895 f.write("} // namespace gles2\n") | 9891 f.write("} // namespace gles2\n") |
| 9896 f.write("} // namespace gpu\n") | 9892 f.write("} // namespace gpu\n") |
| 9897 f.write("\n") | 9893 f.write("\n") |
| 9898 | 9894 |
| 9899 def ParseGLH(self, filename): | 9895 def ParseGLH(self, filename): |
| 9900 """Parses the cmd_buffer_functions.txt file and extracts the functions""" | 9896 """Parses the cmd_buffer_functions.txt file and extracts the functions""" |
| 9901 f = open(filename, "r") | 9897 with open(filename, "r") as f: |
| 9902 functions = f.read() | 9898 functions = f.read() |
| 9903 f.close() | |
| 9904 for line in functions.splitlines(): | 9899 for line in functions.splitlines(): |
| 9905 match = self._function_re.match(line) | 9900 match = self._function_re.match(line) |
| 9906 if match: | 9901 if match: |
| 9907 func_name = match.group(2)[2:] | 9902 func_name = match.group(2)[2:] |
| 9908 func_info = self.GetFunctionInfo(func_name) | 9903 func_info = self.GetFunctionInfo(func_name) |
| 9909 if func_info['type'] == 'Noop': | 9904 if func_info['type'] == 'Noop': |
| 9910 continue | 9905 continue |
| 9911 | 9906 |
| 9912 parsed_func_info = { | 9907 parsed_func_info = { |
| 9913 'original_name': func_name, | 9908 'original_name': func_name, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9946 | 9941 |
| 9947 funcs = [f for f in self.functions if not f.can_auto_generate and | 9942 funcs = [f for f in self.functions if not f.can_auto_generate and |
| 9948 (f.IsType('') or f.IsType('Custom') or f.IsType('Todo'))] | 9943 (f.IsType('') or f.IsType('Custom') or f.IsType('Todo'))] |
| 9949 self.Log("Non Auto Generated Functions: %d" % len(funcs)) | 9944 self.Log("Non Auto Generated Functions: %d" % len(funcs)) |
| 9950 | 9945 |
| 9951 for f in funcs: | 9946 for f in funcs: |
| 9952 self.Log(" %-10s %-20s gl%s" % (f.info['type'], f.return_type, f.name)) | 9947 self.Log(" %-10s %-20s gl%s" % (f.info['type'], f.return_type, f.name)) |
| 9953 | 9948 |
| 9954 def WriteCommandIds(self, filename): | 9949 def WriteCommandIds(self, filename): |
| 9955 """Writes the command buffer format""" | 9950 """Writes the command buffer format""" |
| 9956 f = CHeaderWriter(filename) | 9951 with CHeaderWriter(filename) as f: |
| 9957 f.write("#define GLES2_COMMAND_LIST(OP) \\\n") | 9952 f.write("#define GLES2_COMMAND_LIST(OP) \\\n") |
| 9958 id = 256 | 9953 id = 256 |
| 9959 for func in self.functions: | 9954 for func in self.functions: |
| 9960 f.write(" %-60s /* %d */ \\\n" % | 9955 f.write(" %-60s /* %d */ \\\n" % |
| 9961 ("OP(%s)" % func.name, id)) | 9956 ("OP(%s)" % func.name, id)) |
| 9962 id += 1 | 9957 id += 1 |
| 9963 f.write("\n") | 9958 f.write("\n") |
| 9964 | 9959 |
| 9965 f.write("enum CommandId {\n") | 9960 f.write("enum CommandId {\n") |
| 9966 f.write(" kStartPoint = cmd::kLastCommonId, " | 9961 f.write(" kStartPoint = cmd::kLastCommonId, " |
| 9967 "// All GLES2 commands start after this.\n") | 9962 "// All GLES2 commands start after this.\n") |
| 9968 f.write("#define GLES2_CMD_OP(name) k ## name,\n") | 9963 f.write("#define GLES2_CMD_OP(name) k ## name,\n") |
| 9969 f.write(" GLES2_COMMAND_LIST(GLES2_CMD_OP)\n") | 9964 f.write(" GLES2_COMMAND_LIST(GLES2_CMD_OP)\n") |
| 9970 f.write("#undef GLES2_CMD_OP\n") | 9965 f.write("#undef GLES2_CMD_OP\n") |
| 9971 f.write(" kNumCommands\n") | 9966 f.write(" kNumCommands\n") |
| 9972 f.write("};\n") | 9967 f.write("};\n") |
| 9973 f.write("\n") | 9968 f.write("\n") |
| 9974 f.close() | 9969 self.generated_cpp_filenames.append(filename) |
| 9975 self.generated_cpp_filenames.append(f.filename) | |
| 9976 | 9970 |
| 9977 def WriteFormat(self, filename): | 9971 def WriteFormat(self, filename): |
| 9978 """Writes the command buffer format""" | 9972 """Writes the command buffer format""" |
| 9979 f = CHeaderWriter(filename) | 9973 with CHeaderWriter(filename) as f: |
| 9980 # Forward declaration of a few enums used in constant argument | 9974 # Forward declaration of a few enums used in constant argument |
| 9981 # to avoid including GL header files. | 9975 # to avoid including GL header files. |
| 9982 enum_defines = { | 9976 enum_defines = { |
| 9983 'GL_SYNC_GPU_COMMANDS_COMPLETE': '0x9117', | 9977 'GL_SYNC_GPU_COMMANDS_COMPLETE': '0x9117', |
| 9984 'GL_SYNC_FLUSH_COMMANDS_BIT': '0x00000001', | 9978 'GL_SYNC_FLUSH_COMMANDS_BIT': '0x00000001', |
| 9985 } | 9979 } |
| 9986 f.write('\n') | 9980 f.write('\n') |
| 9987 for enum in enum_defines: | 9981 for enum in enum_defines: |
| 9988 f.write("#define %s %s\n" % (enum, enum_defines[enum])) | 9982 f.write("#define %s %s\n" % (enum, enum_defines[enum])) |
| 9989 f.write('\n') | 9983 f.write('\n') |
| 9990 for func in self.functions: | 9984 for func in self.functions: |
| 9991 if True: | 9985 if True: |
| 9992 #gen_cmd = func.GetInfo('gen_cmd') | 9986 #gen_cmd = func.GetInfo('gen_cmd') |
| 9993 #if gen_cmd == True or gen_cmd == None: | 9987 #if gen_cmd == True or gen_cmd == None: |
| 9994 func.WriteStruct(f) | 9988 func.WriteStruct(f) |
| 9995 f.write("\n") | 9989 f.write("\n") |
| 9996 f.close() | 9990 self.generated_cpp_filenames.append(filename) |
| 9997 self.generated_cpp_filenames.append(f.filename) | |
| 9998 | 9991 |
| 9999 def WriteDocs(self, filename): | 9992 def WriteDocs(self, filename): |
| 10000 """Writes the command buffer doc version of the commands""" | 9993 """Writes the command buffer doc version of the commands""" |
| 10001 f = CWriter(filename) | 9994 with CHeaderWriter(filename) as f: |
| 10002 for func in self.functions: | 9995 for func in self.functions: |
| 10003 if True: | 9996 if True: |
| 10004 #gen_cmd = func.GetInfo('gen_cmd') | 9997 #gen_cmd = func.GetInfo('gen_cmd') |
| 10005 #if gen_cmd == True or gen_cmd == None: | 9998 #if gen_cmd == True or gen_cmd == None: |
| 10006 func.WriteDocs(f) | 9999 func.WriteDocs(f) |
| 10007 f.write("\n") | 10000 f.write("\n") |
| 10008 f.close() | 10001 self.generated_cpp_filenames.append(filename) |
| 10009 self.generated_cpp_filenames.append(f.filename) | |
| 10010 | 10002 |
| 10011 def WriteFormatTest(self, filename): | 10003 def WriteFormatTest(self, filename): |
| 10012 """Writes the command buffer format test.""" | 10004 """Writes the command buffer format test.""" |
| 10013 f = CHeaderWriter( | 10005 comment = ("// This file contains unit tests for gles2 commmands\n" |
| 10014 filename, | 10006 "// It is included by gles2_cmd_format_test.cc\n\n") |
| 10015 "// This file contains unit tests for gles2 commmands\n" | 10007 with CHeaderWriter(filename, comment) as f: |
| 10016 "// It is included by gles2_cmd_format_test.cc\n" | 10008 for func in self.functions: |
| 10017 "\n") | 10009 if True: |
| 10018 | 10010 #gen_cmd = func.GetInfo('gen_cmd') |
| 10019 for func in self.functions: | 10011 #if gen_cmd == True or gen_cmd == None: |
| 10020 if True: | 10012 func.WriteFormatTest(f) |
| 10021 #gen_cmd = func.GetInfo('gen_cmd') | 10013 self.generated_cpp_filenames.append(filename) |
| 10022 #if gen_cmd == True or gen_cmd == None: | |
| 10023 func.WriteFormatTest(f) | |
| 10024 | |
| 10025 f.close() | |
| 10026 self.generated_cpp_filenames.append(f.filename) | |
| 10027 | 10014 |
| 10028 def WriteCmdHelperHeader(self, filename): | 10015 def WriteCmdHelperHeader(self, filename): |
| 10029 """Writes the gles2 command helper.""" | 10016 """Writes the gles2 command helper.""" |
| 10030 f = CHeaderWriter(filename) | 10017 with CHeaderWriter(filename) as f: |
| 10031 | 10018 for func in self.functions: |
| 10032 for func in self.functions: | 10019 if True: |
| 10033 if True: | 10020 #gen_cmd = func.GetInfo('gen_cmd') |
| 10034 #gen_cmd = func.GetInfo('gen_cmd') | 10021 #if gen_cmd == True or gen_cmd == None: |
| 10035 #if gen_cmd == True or gen_cmd == None: | 10022 func.WriteCmdHelper(f) |
| 10036 func.WriteCmdHelper(f) | 10023 self.generated_cpp_filenames.append(filename) |
| 10037 | |
| 10038 f.close() | |
| 10039 self.generated_cpp_filenames.append(f.filename) | |
| 10040 | 10024 |
| 10041 def WriteServiceContextStateHeader(self, filename): | 10025 def WriteServiceContextStateHeader(self, filename): |
| 10042 """Writes the service context state header.""" | 10026 """Writes the service context state header.""" |
| 10043 f = CHeaderWriter( | 10027 comment = "// It is included by context_state.h\n" |
| 10044 filename, | 10028 with CHeaderWriter(filename, comment) as f: |
| 10045 "// It is included by context_state.h\n") | 10029 f.write("struct EnableFlags {\n") |
| 10046 f.write("struct EnableFlags {\n") | 10030 f.write(" EnableFlags();\n") |
| 10047 f.write(" EnableFlags();\n") | 10031 for capability in _CAPABILITY_FLAGS: |
| 10048 for capability in _CAPABILITY_FLAGS: | 10032 f.write(" bool %s;\n" % capability['name']) |
| 10049 f.write(" bool %s;\n" % capability['name']) | 10033 f.write(" bool cached_%s;\n" % capability['name']) |
| 10050 f.write(" bool cached_%s;\n" % capability['name']) | 10034 f.write("};\n\n") |
| 10051 f.write("};\n\n") | |
| 10052 | 10035 |
| 10053 for state_name in sorted(_STATES.keys()): | 10036 for state_name in sorted(_STATES.keys()): |
| 10054 state = _STATES[state_name] | 10037 state = _STATES[state_name] |
| 10055 for item in state['states']: | 10038 for item in state['states']: |
| 10056 if isinstance(item['default'], list): | 10039 if isinstance(item['default'], list): |
| 10057 f.write("%s %s[%d];\n" % (item['type'], item['name'], | 10040 f.write("%s %s[%d];\n" % (item['type'], item['name'], |
| 10058 len(item['default']))) | 10041 len(item['default']))) |
| 10059 else: | 10042 else: |
| 10060 f.write("%s %s;\n" % (item['type'], item['name'])) | 10043 f.write("%s %s;\n" % (item['type'], item['name'])) |
| 10061 | 10044 |
| 10062 if item.get('cached', False): | 10045 if item.get('cached', False): |
| 10063 if isinstance(item['default'], list): | 10046 if isinstance(item['default'], list): |
| 10064 f.write("%s cached_%s[%d];\n" % (item['type'], item['name'], | 10047 f.write("%s cached_%s[%d];\n" % (item['type'], item['name'], |
| 10065 len(item['default']))) | 10048 len(item['default']))) |
| 10066 else: | 10049 else: |
| 10067 f.write("%s cached_%s;\n" % (item['type'], item['name'])) | 10050 f.write("%s cached_%s;\n" % (item['type'], item['name'])) |
| 10068 | 10051 |
| 10069 f.write("\n") | 10052 f.write("\n") |
| 10053 f.write(""" |
| 10054 inline void SetDeviceCapabilityState(GLenum cap, bool enable) { |
| 10055 switch (cap) { |
| 10056 """) |
| 10057 for capability in _CAPABILITY_FLAGS: |
| 10058 f.write("""\ |
| 10059 case GL_%s: |
| 10060 """ % capability['name'].upper()) |
| 10061 f.write("""\ |
| 10062 if (enable_flags.cached_%(name)s == enable && |
| 10063 !ignore_cached_state) |
| 10064 return; |
| 10065 enable_flags.cached_%(name)s = enable; |
| 10066 break; |
| 10067 """ % capability) |
| 10070 | 10068 |
| 10071 f.write(""" | |
| 10072 inline void SetDeviceCapabilityState(GLenum cap, bool enable) { | |
| 10073 switch (cap) { | |
| 10074 """) | |
| 10075 for capability in _CAPABILITY_FLAGS: | |
| 10076 f.write("""\ | 10069 f.write("""\ |
| 10077 case GL_%s: | 10070 default: |
| 10078 """ % capability['name'].upper()) | 10071 NOTREACHED(); |
| 10079 f.write("""\ | |
| 10080 if (enable_flags.cached_%(name)s == enable && | |
| 10081 !ignore_cached_state) | |
| 10082 return; | 10072 return; |
| 10083 enable_flags.cached_%(name)s = enable; | 10073 } |
| 10084 break; | 10074 if (enable) |
| 10085 """ % capability) | 10075 glEnable(cap); |
| 10086 | 10076 else |
| 10087 f.write("""\ | 10077 glDisable(cap); |
| 10088 default: | |
| 10089 NOTREACHED(); | |
| 10090 return; | |
| 10091 } | 10078 } |
| 10092 if (enable) | 10079 """) |
| 10093 glEnable(cap); | 10080 self.generated_cpp_filenames.append(filename) |
| 10094 else | |
| 10095 glDisable(cap); | |
| 10096 } | |
| 10097 """) | |
| 10098 | |
| 10099 f.close() | |
| 10100 self.generated_cpp_filenames.append(f.filename) | |
| 10101 | 10081 |
| 10102 def WriteClientContextStateHeader(self, filename): | 10082 def WriteClientContextStateHeader(self, filename): |
| 10103 """Writes the client context state header.""" | 10083 """Writes the client context state header.""" |
| 10104 f = CHeaderWriter( | 10084 comment = "// It is included by client_context_state.h\n" |
| 10105 filename, | 10085 with CHeaderWriter(filename, comment) as f: |
| 10106 "// It is included by client_context_state.h\n") | 10086 f.write("struct EnableFlags {\n") |
| 10107 f.write("struct EnableFlags {\n") | 10087 f.write(" EnableFlags();\n") |
| 10108 f.write(" EnableFlags();\n") | 10088 for capability in _CAPABILITY_FLAGS: |
| 10109 for capability in _CAPABILITY_FLAGS: | 10089 f.write(" bool %s;\n" % capability['name']) |
| 10110 f.write(" bool %s;\n" % capability['name']) | 10090 f.write("};\n\n") |
| 10111 f.write("};\n\n") | 10091 self.generated_cpp_filenames.append(filename) |
| 10112 | |
| 10113 f.close() | |
| 10114 self.generated_cpp_filenames.append(f.filename) | |
| 10115 | 10092 |
| 10116 def WriteContextStateGetters(self, f, class_name): | 10093 def WriteContextStateGetters(self, f, class_name): |
| 10117 """Writes the state getters.""" | 10094 """Writes the state getters.""" |
| 10118 for gl_type in ["GLint", "GLfloat"]: | 10095 for gl_type in ["GLint", "GLfloat"]: |
| 10119 f.write(""" | 10096 f.write(""" |
| 10120 bool %s::GetStateAs%s( | 10097 bool %s::GetStateAs%s( |
| 10121 GLenum pname, %s* params, GLsizei* num_written) const { | 10098 GLenum pname, %s* params, GLsizei* num_written) const { |
| 10122 switch (pname) { | 10099 switch (pname) { |
| 10123 """ % (class_name, gl_type, gl_type)) | 10100 """ % (class_name, gl_type, gl_type)) |
| 10124 for state_name in sorted(_STATES.keys()): | 10101 for state_name in sorted(_STATES.keys()): |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10167 f.write(" }\n") | 10144 f.write(" }\n") |
| 10168 f.write(" return true;\n") | 10145 f.write(" return true;\n") |
| 10169 f.write(""" default: | 10146 f.write(""" default: |
| 10170 return false; | 10147 return false; |
| 10171 } | 10148 } |
| 10172 } | 10149 } |
| 10173 """) | 10150 """) |
| 10174 | 10151 |
| 10175 def WriteServiceContextStateImpl(self, filename): | 10152 def WriteServiceContextStateImpl(self, filename): |
| 10176 """Writes the context state service implementation.""" | 10153 """Writes the context state service implementation.""" |
| 10177 f = CHeaderWriter( | 10154 comment = "// It is included by context_state.cc\n" |
| 10178 filename, | 10155 with CHeaderWriter(filename, comment) as f: |
| 10179 "// It is included by context_state.cc\n") | 10156 code = [] |
| 10180 code = [] | 10157 for capability in _CAPABILITY_FLAGS: |
| 10181 for capability in _CAPABILITY_FLAGS: | 10158 code.append("%s(%s)" % |
| 10182 code.append("%s(%s)" % | 10159 (capability['name'], |
| 10183 (capability['name'], | 10160 ('false', 'true')['default' in capability])) |
| 10184 ('false', 'true')['default' in capability])) | 10161 code.append("cached_%s(%s)" % |
| 10185 code.append("cached_%s(%s)" % | 10162 (capability['name'], |
| 10186 (capability['name'], | 10163 ('false', 'true')['default' in capability])) |
| 10187 ('false', 'true')['default' in capability])) | 10164 f.write("ContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" % |
| 10188 f.write("ContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" % | 10165 ",\n ".join(code)) |
| 10189 ",\n ".join(code)) | 10166 f.write("\n") |
| 10190 f.write("\n") | 10167 |
| 10191 | 10168 f.write("void ContextState::Initialize() {\n") |
| 10192 f.write("void ContextState::Initialize() {\n") | 10169 for state_name in sorted(_STATES.keys()): |
| 10193 for state_name in sorted(_STATES.keys()): | 10170 state = _STATES[state_name] |
| 10194 state = _STATES[state_name] | 10171 for item in state['states']: |
| 10195 for item in state['states']: | |
| 10196 if isinstance(item['default'], list): | |
| 10197 for ndx, value in enumerate(item['default']): | |
| 10198 f.write(" %s[%d] = %s;\n" % (item['name'], ndx, value)) | |
| 10199 else: | |
| 10200 f.write(" %s = %s;\n" % (item['name'], item['default'])) | |
| 10201 if item.get('cached', False): | |
| 10202 if isinstance(item['default'], list): | 10172 if isinstance(item['default'], list): |
| 10203 for ndx, value in enumerate(item['default']): | 10173 for ndx, value in enumerate(item['default']): |
| 10204 f.write(" cached_%s[%d] = %s;\n" % (item['name'], ndx, value)) | 10174 f.write(" %s[%d] = %s;\n" % (item['name'], ndx, value)) |
| 10205 else: | 10175 else: |
| 10206 f.write(" cached_%s = %s;\n" % (item['name'], item['default'])) | 10176 f.write(" %s = %s;\n" % (item['name'], item['default'])) |
| 10207 f.write("}\n") | 10177 if item.get('cached', False): |
| 10208 | 10178 if isinstance(item['default'], list): |
| 10209 f.write(""" | 10179 for ndx, value in enumerate(item['default']): |
| 10180 f.write(" cached_%s[%d] = %s;\n" % (item['name'], ndx, value)) |
| 10181 else: |
| 10182 f.write(" cached_%s = %s;\n" % (item['name'], item['default'])) |
| 10183 f.write("}\n") |
| 10184 |
| 10185 f.write(""" |
| 10210 void ContextState::InitCapabilities(const ContextState* prev_state) const { | 10186 void ContextState::InitCapabilities(const ContextState* prev_state) const { |
| 10211 """) | 10187 """) |
| 10212 def WriteCapabilities(test_prev, es3_caps): | 10188 def WriteCapabilities(test_prev, es3_caps): |
| 10213 for capability in _CAPABILITY_FLAGS: | 10189 for capability in _CAPABILITY_FLAGS: |
| 10214 capability_name = capability['name'] | 10190 capability_name = capability['name'] |
| 10191 capability_es3 = 'es3' in capability and capability['es3'] == True |
| 10192 if capability_es3 and not es3_caps or not capability_es3 and es3_caps: |
| 10193 continue |
| 10194 if test_prev: |
| 10195 f.write(""" if (prev_state->enable_flags.cached_%s != |
| 10196 enable_flags.cached_%s) {\n""" % |
| 10197 (capability_name, capability_name)) |
| 10198 f.write(" EnableDisable(GL_%s, enable_flags.cached_%s);\n" % |
| 10199 (capability_name.upper(), capability_name)) |
| 10200 if test_prev: |
| 10201 f.write(" }") |
| 10202 |
| 10203 f.write(" if (prev_state) {") |
| 10204 WriteCapabilities(True, False) |
| 10205 f.write(" if (feature_info_->IsES3Capable()) {\n") |
| 10206 WriteCapabilities(True, True) |
| 10207 f.write(" }\n") |
| 10208 f.write(" } else {") |
| 10209 WriteCapabilities(False, False) |
| 10210 f.write(" if (feature_info_->IsES3Capable()) {\n") |
| 10211 WriteCapabilities(False, True) |
| 10212 f.write(" }\n") |
| 10213 f.write(" }") |
| 10214 f.write("""} |
| 10215 |
| 10216 void ContextState::InitState(const ContextState *prev_state) const { |
| 10217 """) |
| 10218 |
| 10219 def WriteStates(test_prev): |
| 10220 # We need to sort the keys so the expectations match |
| 10221 for state_name in sorted(_STATES.keys()): |
| 10222 state = _STATES[state_name] |
| 10223 if state['type'] == 'FrontBack': |
| 10224 num_states = len(state['states']) |
| 10225 for ndx, group in enumerate(Grouper(num_states / 2, |
| 10226 state['states'])): |
| 10227 if test_prev: |
| 10228 f.write(" if (") |
| 10229 args = [] |
| 10230 for place, item in enumerate(group): |
| 10231 item_name = CachedStateName(item) |
| 10232 args.append('%s' % item_name) |
| 10233 if test_prev: |
| 10234 if place > 0: |
| 10235 f.write(' ||\n') |
| 10236 f.write("(%s != prev_state->%s)" % (item_name, item_name)) |
| 10237 if test_prev: |
| 10238 f.write(")\n") |
| 10239 f.write( |
| 10240 " gl%s(%s, %s);\n" % |
| 10241 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], |
| 10242 ", ".join(args))) |
| 10243 elif state['type'] == 'NamedParameter': |
| 10244 for item in state['states']: |
| 10245 item_name = CachedStateName(item) |
| 10246 |
| 10247 if 'extension_flag' in item: |
| 10248 f.write(" if (feature_info_->feature_flags().%s) {\n " % |
| 10249 item['extension_flag']) |
| 10250 if test_prev: |
| 10251 if isinstance(item['default'], list): |
| 10252 f.write(" if (memcmp(prev_state->%s, %s, " |
| 10253 "sizeof(%s) * %d)) {\n" % |
| 10254 (item_name, item_name, item['type'], |
| 10255 len(item['default']))) |
| 10256 else: |
| 10257 f.write(" if (prev_state->%s != %s) {\n " % |
| 10258 (item_name, item_name)) |
| 10259 if 'gl_version_flag' in item: |
| 10260 item_name = item['gl_version_flag'] |
| 10261 inverted = '' |
| 10262 if item_name[0] == '!': |
| 10263 inverted = '!' |
| 10264 item_name = item_name[1:] |
| 10265 f.write(" if (%sfeature_info_->gl_version_info().%s) {\n" % |
| 10266 (inverted, item_name)) |
| 10267 f.write(" gl%s(%s, %s);\n" % |
| 10268 (state['func'], |
| 10269 (item['enum_set'] |
| 10270 if 'enum_set' in item else item['enum']), |
| 10271 item['name'])) |
| 10272 if 'gl_version_flag' in item: |
| 10273 f.write(" }\n") |
| 10274 if test_prev: |
| 10275 if 'extension_flag' in item: |
| 10276 f.write(" ") |
| 10277 f.write(" }") |
| 10278 if 'extension_flag' in item: |
| 10279 f.write(" }") |
| 10280 else: |
| 10281 if 'extension_flag' in state: |
| 10282 f.write(" if (feature_info_->feature_flags().%s)\n " % |
| 10283 state['extension_flag']) |
| 10284 if test_prev: |
| 10285 f.write(" if (") |
| 10286 args = [] |
| 10287 for place, item in enumerate(state['states']): |
| 10288 item_name = CachedStateName(item) |
| 10289 args.append('%s' % item_name) |
| 10290 if test_prev: |
| 10291 if place > 0: |
| 10292 f.write(' ||\n') |
| 10293 f.write("(%s != prev_state->%s)" % |
| 10294 (item_name, item_name)) |
| 10295 if test_prev: |
| 10296 f.write(" )\n") |
| 10297 f.write(" gl%s(%s);\n" % (state['func'], ", ".join(args))) |
| 10298 |
| 10299 f.write(" if (prev_state) {") |
| 10300 WriteStates(True) |
| 10301 f.write(" } else {") |
| 10302 WriteStates(False) |
| 10303 f.write(" }") |
| 10304 f.write("}\n") |
| 10305 |
| 10306 f.write("""bool ContextState::GetEnabled(GLenum cap) const { |
| 10307 switch (cap) { |
| 10308 """) |
| 10309 for capability in _CAPABILITY_FLAGS: |
| 10310 f.write(" case GL_%s:\n" % capability['name'].upper()) |
| 10311 f.write(" return enable_flags.%s;\n" % capability['name']) |
| 10312 f.write(""" default: |
| 10313 NOTREACHED(); |
| 10314 return false; |
| 10315 } |
| 10316 } |
| 10317 """) |
| 10318 self.WriteContextStateGetters(f, "ContextState") |
| 10319 self.generated_cpp_filenames.append(filename) |
| 10320 |
| 10321 def WriteClientContextStateImpl(self, filename): |
| 10322 """Writes the context state client side implementation.""" |
| 10323 comment = "// It is included by client_context_state.cc\n" |
| 10324 with CHeaderWriter(filename, comment) as f: |
| 10325 code = [] |
| 10326 for capability in _CAPABILITY_FLAGS: |
| 10327 code.append("%s(%s)" % |
| 10328 (capability['name'], |
| 10329 ('false', 'true')['default' in capability])) |
| 10330 f.write( |
| 10331 "ClientContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" % |
| 10332 ",\n ".join(code)) |
| 10333 f.write("\n") |
| 10334 |
| 10335 f.write(""" |
| 10336 bool ClientContextState::SetCapabilityState( |
| 10337 GLenum cap, bool enabled, bool* changed) { |
| 10338 *changed = false; |
| 10339 switch (cap) { |
| 10340 """) |
| 10341 for capability in _CAPABILITY_FLAGS: |
| 10342 f.write(" case GL_%s:\n" % capability['name'].upper()) |
| 10343 f.write(""" if (enable_flags.%(name)s != enabled) { |
| 10344 *changed = true; |
| 10345 enable_flags.%(name)s = enabled; |
| 10346 } |
| 10347 return true; |
| 10348 """ % capability) |
| 10349 f.write(""" default: |
| 10350 return false; |
| 10351 } |
| 10352 } |
| 10353 """) |
| 10354 f.write("""bool ClientContextState::GetEnabled( |
| 10355 GLenum cap, bool* enabled) const { |
| 10356 switch (cap) { |
| 10357 """) |
| 10358 for capability in _CAPABILITY_FLAGS: |
| 10359 f.write(" case GL_%s:\n" % capability['name'].upper()) |
| 10360 f.write(" *enabled = enable_flags.%s;\n" % capability['name']) |
| 10361 f.write(" return true;\n") |
| 10362 f.write(""" default: |
| 10363 return false; |
| 10364 } |
| 10365 } |
| 10366 """) |
| 10367 self.generated_cpp_filenames.append(filename) |
| 10368 |
| 10369 def WriteServiceImplementation(self, filename): |
| 10370 """Writes the service decorder implementation.""" |
| 10371 comment = "// It is included by gles2_cmd_decoder.cc\n" |
| 10372 with CHeaderWriter(filename, comment) as f: |
| 10373 for func in self.functions: |
| 10374 if True: |
| 10375 #gen_cmd = func.GetInfo('gen_cmd') |
| 10376 #if gen_cmd == True or gen_cmd == None: |
| 10377 func.WriteServiceImplementation(f) |
| 10378 |
| 10379 f.write(""" |
| 10380 bool GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) { |
| 10381 switch (cap) { |
| 10382 """) |
| 10383 for capability in _CAPABILITY_FLAGS: |
| 10384 f.write(" case GL_%s:\n" % capability['name'].upper()) |
| 10385 if 'state_flag' in capability: |
| 10386 |
| 10387 f.write("""\ |
| 10388 state_.enable_flags.%(name)s = enabled; |
| 10389 if (state_.enable_flags.cached_%(name)s != enabled |
| 10390 || state_.ignore_cached_state) { |
| 10391 %(state_flag)s = true; |
| 10392 } |
| 10393 return false; |
| 10394 """ % capability) |
| 10395 else: |
| 10396 f.write("""\ |
| 10397 state_.enable_flags.%(name)s = enabled; |
| 10398 if (state_.enable_flags.cached_%(name)s != enabled |
| 10399 || state_.ignore_cached_state) { |
| 10400 state_.enable_flags.cached_%(name)s = enabled; |
| 10401 return true; |
| 10402 } |
| 10403 return false; |
| 10404 """ % capability) |
| 10405 f.write(""" default: |
| 10406 NOTREACHED(); |
| 10407 return false; |
| 10408 } |
| 10409 } |
| 10410 """) |
| 10411 self.generated_cpp_filenames.append(filename) |
| 10412 |
| 10413 def WriteServiceUnitTests(self, filename_pattern): |
| 10414 """Writes the service decorder unit tests.""" |
| 10415 num_tests = len(self.functions) |
| 10416 FUNCTIONS_PER_FILE = 98 # hard code this so it doesn't change. |
| 10417 count = 0 |
| 10418 for test_num in range(0, num_tests, FUNCTIONS_PER_FILE): |
| 10419 count += 1 |
| 10420 filename = filename_pattern % count |
| 10421 comment = "// It is included by gles2_cmd_decoder_unittest_%d.cc\n" \ |
| 10422 % count |
| 10423 with CHeaderWriter(filename, comment) as f: |
| 10424 test_name = 'GLES2DecoderTest%d' % count |
| 10425 end = test_num + FUNCTIONS_PER_FILE |
| 10426 if end > num_tests: |
| 10427 end = num_tests |
| 10428 for idx in range(test_num, end): |
| 10429 func = self.functions[idx] |
| 10430 |
| 10431 # Do any filtering of the functions here, so that the functions |
| 10432 # will not move between the numbered files if filtering properties |
| 10433 # are changed. |
| 10434 if func.GetInfo('extension_flag'): |
| 10435 continue |
| 10436 |
| 10437 if True: |
| 10438 #gen_cmd = func.GetInfo('gen_cmd') |
| 10439 #if gen_cmd == True or gen_cmd == None: |
| 10440 if func.GetInfo('unit_test') == False: |
| 10441 f.write("// TODO(gman): %s\n" % func.name) |
| 10442 else: |
| 10443 func.WriteServiceUnitTest(f, { |
| 10444 'test_name': test_name |
| 10445 }) |
| 10446 self.generated_cpp_filenames.append(filename) |
| 10447 |
| 10448 comment = "// It is included by gles2_cmd_decoder_unittest_base.cc\n" |
| 10449 filename = filename_pattern % 0 |
| 10450 with CHeaderWriter(filename, comment) as f: |
| 10451 f.write( |
| 10452 """void GLES2DecoderTestBase::SetupInitCapabilitiesExpectations( |
| 10453 bool es3_capable) {""") |
| 10454 for capability in _CAPABILITY_FLAGS: |
| 10215 capability_es3 = 'es3' in capability and capability['es3'] == True | 10455 capability_es3 = 'es3' in capability and capability['es3'] == True |
| 10216 if capability_es3 and not es3_caps or not capability_es3 and es3_caps: | 10456 if not capability_es3: |
| 10217 continue | 10457 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % |
| 10218 if test_prev: | 10458 (capability['name'].upper(), |
| 10219 f.write(""" if (prev_state->enable_flags.cached_%s != | 10459 ('false', 'true')['default' in capability])) |
| 10220 enable_flags.cached_%s) {\n""" % | 10460 |
| 10221 (capability_name, capability_name)) | 10461 f.write(" if (es3_capable) {") |
| 10222 f.write(" EnableDisable(GL_%s, enable_flags.cached_%s);\n" % | 10462 for capability in _CAPABILITY_FLAGS: |
| 10223 (capability_name.upper(), capability_name)) | 10463 capability_es3 = 'es3' in capability and capability['es3'] == True |
| 10224 if test_prev: | 10464 if capability_es3: |
| 10225 f.write(" }") | 10465 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % |
| 10226 | 10466 (capability['name'].upper(), |
| 10227 f.write(" if (prev_state) {") | 10467 ('false', 'true')['default' in capability])) |
| 10228 WriteCapabilities(True, False) | 10468 f.write(""" } |
| 10229 f.write(" if (feature_info_->IsES3Capable()) {\n") | 10469 } |
| 10230 WriteCapabilities(True, True) | 10470 |
| 10231 f.write(" }\n") | 10471 void GLES2DecoderTestBase::SetupInitStateExpectations() { |
| 10232 f.write(" } else {") | 10472 """) |
| 10233 WriteCapabilities(False, False) | |
| 10234 f.write(" if (feature_info_->IsES3Capable()) {\n") | |
| 10235 WriteCapabilities(False, True) | |
| 10236 f.write(" }\n") | |
| 10237 f.write(" }") | |
| 10238 | |
| 10239 f.write("""} | |
| 10240 | |
| 10241 void ContextState::InitState(const ContextState *prev_state) const { | |
| 10242 """) | |
| 10243 | |
| 10244 def WriteStates(test_prev): | |
| 10245 # We need to sort the keys so the expectations match | 10473 # We need to sort the keys so the expectations match |
| 10246 for state_name in sorted(_STATES.keys()): | 10474 for state_name in sorted(_STATES.keys()): |
| 10247 state = _STATES[state_name] | 10475 state = _STATES[state_name] |
| 10248 if state['type'] == 'FrontBack': | 10476 if state['type'] == 'FrontBack': |
| 10249 num_states = len(state['states']) | 10477 num_states = len(state['states']) |
| 10250 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): | 10478 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): |
| 10251 if test_prev: | |
| 10252 f.write(" if (") | |
| 10253 args = [] | 10479 args = [] |
| 10254 for place, item in enumerate(group): | 10480 for item in group: |
| 10255 item_name = CachedStateName(item) | 10481 if 'expected' in item: |
| 10256 args.append('%s' % item_name) | 10482 args.append(item['expected']) |
| 10257 if test_prev: | 10483 else: |
| 10258 if place > 0: | 10484 args.append(item['default']) |
| 10259 f.write(' ||\n') | |
| 10260 f.write("(%s != prev_state->%s)" % (item_name, item_name)) | |
| 10261 if test_prev: | |
| 10262 f.write(")\n") | |
| 10263 f.write( | 10485 f.write( |
| 10264 " gl%s(%s, %s);\n" % | 10486 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % |
| 10265 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) | 10487 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) |
| 10488 f.write(" .Times(1)\n") |
| 10489 f.write(" .RetiresOnSaturation();\n") |
| 10266 elif state['type'] == 'NamedParameter': | 10490 elif state['type'] == 'NamedParameter': |
| 10267 for item in state['states']: | 10491 for item in state['states']: |
| 10268 item_name = CachedStateName(item) | |
| 10269 | |
| 10270 if 'extension_flag' in item: | 10492 if 'extension_flag' in item: |
| 10271 f.write(" if (feature_info_->feature_flags().%s) {\n " % | 10493 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % |
| 10272 item['extension_flag']) | 10494 item['extension_flag']) |
| 10273 if test_prev: | 10495 f.write(" ") |
| 10274 if isinstance(item['default'], list): | 10496 expect_value = item['default'] |
| 10275 f.write(" if (memcmp(prev_state->%s, %s, " | 10497 if isinstance(expect_value, list): |
| 10276 "sizeof(%s) * %d)) {\n" % | 10498 # TODO: Currently we do not check array values. |
| 10277 (item_name, item_name, item['type'], | 10499 expect_value = "_" |
| 10278 len(item['default']))) | 10500 |
| 10279 else: | 10501 f.write( |
| 10280 f.write(" if (prev_state->%s != %s) {\n " % | 10502 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % |
| 10281 (item_name, item_name)) | 10503 (state['func'], |
| 10282 if 'gl_version_flag' in item: | 10504 (item['enum_set'] |
| 10283 item_name = item['gl_version_flag'] | 10505 if 'enum_set' in item else item['enum']), |
| 10284 inverted = '' | 10506 expect_value)) |
| 10285 if item_name[0] == '!': | 10507 f.write(" .Times(1)\n") |
| 10286 inverted = '!' | 10508 f.write(" .RetiresOnSaturation();\n") |
| 10287 item_name = item_name[1:] | 10509 if 'extension_flag' in item: |
| 10288 f.write(" if (%sfeature_info_->gl_version_info().%s) {\n" % | |
| 10289 (inverted, item_name)) | |
| 10290 f.write(" gl%s(%s, %s);\n" % | |
| 10291 (state['func'], | |
| 10292 (item['enum_set'] | |
| 10293 if 'enum_set' in item else item['enum']), | |
| 10294 item['name'])) | |
| 10295 if 'gl_version_flag' in item: | |
| 10296 f.write(" }\n") | 10510 f.write(" }\n") |
| 10297 if test_prev: | |
| 10298 if 'extension_flag' in item: | |
| 10299 f.write(" ") | |
| 10300 f.write(" }") | |
| 10301 if 'extension_flag' in item: | |
| 10302 f.write(" }") | |
| 10303 else: | 10511 else: |
| 10304 if 'extension_flag' in state: | 10512 if 'extension_flag' in state: |
| 10305 f.write(" if (feature_info_->feature_flags().%s)\n " % | 10513 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % |
| 10306 state['extension_flag']) | 10514 state['extension_flag']) |
| 10307 if test_prev: | 10515 f.write(" ") |
| 10308 f.write(" if (") | |
| 10309 args = [] | 10516 args = [] |
| 10310 for place, item in enumerate(state['states']): | 10517 for item in state['states']: |
| 10311 item_name = CachedStateName(item) | |
| 10312 args.append('%s' % item_name) | |
| 10313 if test_prev: | |
| 10314 if place > 0: | |
| 10315 f.write(' ||\n') | |
| 10316 f.write("(%s != prev_state->%s)" % | |
| 10317 (item_name, item_name)) | |
| 10318 if test_prev: | |
| 10319 f.write(" )\n") | |
| 10320 f.write(" gl%s(%s);\n" % (state['func'], ", ".join(args))) | |
| 10321 | |
| 10322 f.write(" if (prev_state) {") | |
| 10323 WriteStates(True) | |
| 10324 f.write(" } else {") | |
| 10325 WriteStates(False) | |
| 10326 f.write(" }") | |
| 10327 f.write("}\n") | |
| 10328 | |
| 10329 f.write("""bool ContextState::GetEnabled(GLenum cap) const { | |
| 10330 switch (cap) { | |
| 10331 """) | |
| 10332 for capability in _CAPABILITY_FLAGS: | |
| 10333 f.write(" case GL_%s:\n" % capability['name'].upper()) | |
| 10334 f.write(" return enable_flags.%s;\n" % capability['name']) | |
| 10335 f.write(""" default: | |
| 10336 NOTREACHED(); | |
| 10337 return false; | |
| 10338 } | |
| 10339 } | |
| 10340 """) | |
| 10341 | |
| 10342 self.WriteContextStateGetters(f, "ContextState") | |
| 10343 f.close() | |
| 10344 self.generated_cpp_filenames.append(f.filename) | |
| 10345 | |
| 10346 def WriteClientContextStateImpl(self, filename): | |
| 10347 """Writes the context state client side implementation.""" | |
| 10348 f = CHeaderWriter( | |
| 10349 filename, | |
| 10350 "// It is included by client_context_state.cc\n") | |
| 10351 code = [] | |
| 10352 for capability in _CAPABILITY_FLAGS: | |
| 10353 code.append("%s(%s)" % | |
| 10354 (capability['name'], | |
| 10355 ('false', 'true')['default' in capability])) | |
| 10356 f.write( | |
| 10357 "ClientContextState::EnableFlags::EnableFlags()\n : %s {\n}\n" % | |
| 10358 ",\n ".join(code)) | |
| 10359 f.write("\n") | |
| 10360 | |
| 10361 f.write(""" | |
| 10362 bool ClientContextState::SetCapabilityState( | |
| 10363 GLenum cap, bool enabled, bool* changed) { | |
| 10364 *changed = false; | |
| 10365 switch (cap) { | |
| 10366 """) | |
| 10367 for capability in _CAPABILITY_FLAGS: | |
| 10368 f.write(" case GL_%s:\n" % capability['name'].upper()) | |
| 10369 f.write(""" if (enable_flags.%(name)s != enabled) { | |
| 10370 *changed = true; | |
| 10371 enable_flags.%(name)s = enabled; | |
| 10372 } | |
| 10373 return true; | |
| 10374 """ % capability) | |
| 10375 f.write(""" default: | |
| 10376 return false; | |
| 10377 } | |
| 10378 } | |
| 10379 """) | |
| 10380 f.write("""bool ClientContextState::GetEnabled( | |
| 10381 GLenum cap, bool* enabled) const { | |
| 10382 switch (cap) { | |
| 10383 """) | |
| 10384 for capability in _CAPABILITY_FLAGS: | |
| 10385 f.write(" case GL_%s:\n" % capability['name'].upper()) | |
| 10386 f.write(" *enabled = enable_flags.%s;\n" % capability['name']) | |
| 10387 f.write(" return true;\n") | |
| 10388 f.write(""" default: | |
| 10389 return false; | |
| 10390 } | |
| 10391 } | |
| 10392 """) | |
| 10393 f.close() | |
| 10394 self.generated_cpp_filenames.append(f.filename) | |
| 10395 | |
| 10396 def WriteServiceImplementation(self, filename): | |
| 10397 """Writes the service decorder implementation.""" | |
| 10398 f = CHeaderWriter( | |
| 10399 filename, | |
| 10400 "// It is included by gles2_cmd_decoder.cc\n") | |
| 10401 | |
| 10402 for func in self.functions: | |
| 10403 if True: | |
| 10404 #gen_cmd = func.GetInfo('gen_cmd') | |
| 10405 #if gen_cmd == True or gen_cmd == None: | |
| 10406 func.WriteServiceImplementation(f) | |
| 10407 | |
| 10408 f.write(""" | |
| 10409 bool GLES2DecoderImpl::SetCapabilityState(GLenum cap, bool enabled) { | |
| 10410 switch (cap) { | |
| 10411 """) | |
| 10412 for capability in _CAPABILITY_FLAGS: | |
| 10413 f.write(" case GL_%s:\n" % capability['name'].upper()) | |
| 10414 if 'state_flag' in capability: | |
| 10415 | |
| 10416 f.write("""\ | |
| 10417 state_.enable_flags.%(name)s = enabled; | |
| 10418 if (state_.enable_flags.cached_%(name)s != enabled | |
| 10419 || state_.ignore_cached_state) { | |
| 10420 %(state_flag)s = true; | |
| 10421 } | |
| 10422 return false; | |
| 10423 """ % capability) | |
| 10424 else: | |
| 10425 f.write("""\ | |
| 10426 state_.enable_flags.%(name)s = enabled; | |
| 10427 if (state_.enable_flags.cached_%(name)s != enabled | |
| 10428 || state_.ignore_cached_state) { | |
| 10429 state_.enable_flags.cached_%(name)s = enabled; | |
| 10430 return true; | |
| 10431 } | |
| 10432 return false; | |
| 10433 """ % capability) | |
| 10434 f.write(""" default: | |
| 10435 NOTREACHED(); | |
| 10436 return false; | |
| 10437 } | |
| 10438 } | |
| 10439 """) | |
| 10440 f.close() | |
| 10441 self.generated_cpp_filenames.append(f.filename) | |
| 10442 | |
| 10443 def WriteServiceUnitTests(self, filename): | |
| 10444 """Writes the service decorder unit tests.""" | |
| 10445 num_tests = len(self.functions) | |
| 10446 FUNCTIONS_PER_FILE = 98 # hard code this so it doesn't change. | |
| 10447 count = 0 | |
| 10448 for test_num in range(0, num_tests, FUNCTIONS_PER_FILE): | |
| 10449 count += 1 | |
| 10450 name = filename % count | |
| 10451 f = CHeaderWriter( | |
| 10452 name, | |
| 10453 "// It is included by gles2_cmd_decoder_unittest_%d.cc\n" % count) | |
| 10454 test_name = 'GLES2DecoderTest%d' % count | |
| 10455 end = test_num + FUNCTIONS_PER_FILE | |
| 10456 if end > num_tests: | |
| 10457 end = num_tests | |
| 10458 for idx in range(test_num, end): | |
| 10459 func = self.functions[idx] | |
| 10460 | |
| 10461 # Do any filtering of the functions here, so that the functions | |
| 10462 # will not move between the numbered files if filtering properties | |
| 10463 # are changed. | |
| 10464 if func.GetInfo('extension_flag'): | |
| 10465 continue | |
| 10466 | |
| 10467 if True: | |
| 10468 #gen_cmd = func.GetInfo('gen_cmd') | |
| 10469 #if gen_cmd == True or gen_cmd == None: | |
| 10470 if func.GetInfo('unit_test') == False: | |
| 10471 f.write("// TODO(gman): %s\n" % func.name) | |
| 10472 else: | |
| 10473 func.WriteServiceUnitTest(f, { | |
| 10474 'test_name': test_name | |
| 10475 }) | |
| 10476 f.close() | |
| 10477 self.generated_cpp_filenames.append(f.filename) | |
| 10478 f = CHeaderWriter( | |
| 10479 filename % 0, | |
| 10480 "// It is included by gles2_cmd_decoder_unittest_base.cc\n") | |
| 10481 f.write( | |
| 10482 """void GLES2DecoderTestBase::SetupInitCapabilitiesExpectations( | |
| 10483 bool es3_capable) {""") | |
| 10484 for capability in _CAPABILITY_FLAGS: | |
| 10485 capability_es3 = 'es3' in capability and capability['es3'] == True | |
| 10486 if not capability_es3: | |
| 10487 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % | |
| 10488 (capability['name'].upper(), | |
| 10489 ('false', 'true')['default' in capability])) | |
| 10490 | |
| 10491 f.write(" if (es3_capable) {") | |
| 10492 for capability in _CAPABILITY_FLAGS: | |
| 10493 capability_es3 = 'es3' in capability and capability['es3'] == True | |
| 10494 if capability_es3: | |
| 10495 f.write(" ExpectEnableDisable(GL_%s, %s);\n" % | |
| 10496 (capability['name'].upper(), | |
| 10497 ('false', 'true')['default' in capability])) | |
| 10498 f.write(""" } | |
| 10499 } | |
| 10500 | |
| 10501 void GLES2DecoderTestBase::SetupInitStateExpectations() { | |
| 10502 """) | |
| 10503 | |
| 10504 # We need to sort the keys so the expectations match | |
| 10505 for state_name in sorted(_STATES.keys()): | |
| 10506 state = _STATES[state_name] | |
| 10507 if state['type'] == 'FrontBack': | |
| 10508 num_states = len(state['states']) | |
| 10509 for ndx, group in enumerate(Grouper(num_states / 2, state['states'])): | |
| 10510 args = [] | |
| 10511 for item in group: | |
| 10512 if 'expected' in item: | 10518 if 'expected' in item: |
| 10513 args.append(item['expected']) | 10519 args.append(item['expected']) |
| 10514 else: | 10520 else: |
| 10515 args.append(item['default']) | 10521 args.append(item['default']) |
| 10516 f.write( | 10522 # TODO: Currently we do not check array values. |
| 10517 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % | 10523 args = ["_" if isinstance(arg, list) else arg for arg in args] |
| 10518 (state['func'], ('GL_FRONT', 'GL_BACK')[ndx], ", ".join(args))) | 10524 f.write(" EXPECT_CALL(*gl_, %s(%s))\n" % |
| 10525 (state['func'], ", ".join(args))) |
| 10519 f.write(" .Times(1)\n") | 10526 f.write(" .Times(1)\n") |
| 10520 f.write(" .RetiresOnSaturation();\n") | 10527 f.write(" .RetiresOnSaturation();\n") |
| 10521 elif state['type'] == 'NamedParameter': | 10528 if 'extension_flag' in state: |
| 10522 for item in state['states']: | |
| 10523 if 'extension_flag' in item: | |
| 10524 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % | |
| 10525 item['extension_flag']) | |
| 10526 f.write(" ") | |
| 10527 expect_value = item['default'] | |
| 10528 if isinstance(expect_value, list): | |
| 10529 # TODO: Currently we do not check array values. | |
| 10530 expect_value = "_" | |
| 10531 | |
| 10532 f.write( | |
| 10533 " EXPECT_CALL(*gl_, %s(%s, %s))\n" % | |
| 10534 (state['func'], | |
| 10535 (item['enum_set'] | |
| 10536 if 'enum_set' in item else item['enum']), | |
| 10537 expect_value)) | |
| 10538 f.write(" .Times(1)\n") | |
| 10539 f.write(" .RetiresOnSaturation();\n") | |
| 10540 if 'extension_flag' in item: | |
| 10541 f.write(" }\n") | 10529 f.write(" }\n") |
| 10542 else: | 10530 f.write("}\n") |
| 10543 if 'extension_flag' in state: | 10531 self.generated_cpp_filenames.append(filename) |
| 10544 f.write(" if (group_->feature_info()->feature_flags().%s) {\n" % | |
| 10545 state['extension_flag']) | |
| 10546 f.write(" ") | |
| 10547 args = [] | |
| 10548 for item in state['states']: | |
| 10549 if 'expected' in item: | |
| 10550 args.append(item['expected']) | |
| 10551 else: | |
| 10552 args.append(item['default']) | |
| 10553 # TODO: Currently we do not check array values. | |
| 10554 args = ["_" if isinstance(arg, list) else arg for arg in args] | |
| 10555 f.write(" EXPECT_CALL(*gl_, %s(%s))\n" % | |
| 10556 (state['func'], ", ".join(args))) | |
| 10557 f.write(" .Times(1)\n") | |
| 10558 f.write(" .RetiresOnSaturation();\n") | |
| 10559 if 'extension_flag' in state: | |
| 10560 f.write(" }\n") | |
| 10561 f.write("""} | |
| 10562 """) | |
| 10563 f.close() | |
| 10564 self.generated_cpp_filenames.append(f.filename) | |
| 10565 | 10532 |
| 10566 def WriteServiceUnitTestsForExtensions(self, filename): | 10533 def WriteServiceUnitTestsForExtensions(self, filename): |
| 10567 """Writes the service decorder unit tests for functions with extension_flag. | 10534 """Writes the service decorder unit tests for functions with extension_flag. |
| 10568 | 10535 |
| 10569 The functions are special in that they need a specific unit test | 10536 The functions are special in that they need a specific unit test |
| 10570 baseclass to turn on the extension. | 10537 baseclass to turn on the extension. |
| 10571 """ | 10538 """ |
| 10572 functions = [f for f in self.functions if f.GetInfo('extension_flag')] | 10539 functions = [f for f in self.functions if f.GetInfo('extension_flag')] |
| 10573 f = CHeaderWriter( | 10540 comment = "// It is included by gles2_cmd_decoder_unittest_extensions.cc\n" |
| 10574 filename, | 10541 with CHeaderWriter(filename, comment) as f: |
| 10575 "// It is included by gles2_cmd_decoder_unittest_extensions.cc\n") | 10542 for func in functions: |
| 10576 for func in functions: | 10543 if True: |
| 10577 if True: | 10544 if func.GetInfo('unit_test') == False: |
| 10578 if func.GetInfo('unit_test') == False: | 10545 f.write("// TODO(gman): %s\n" % func.name) |
| 10579 f.write("// TODO(gman): %s\n" % func.name) | 10546 else: |
| 10580 else: | 10547 extension = ToCamelCase( |
| 10581 extension = ToCamelCase( | 10548 ToGLExtensionString(func.GetInfo('extension_flag'))) |
| 10582 ToGLExtensionString(func.GetInfo('extension_flag'))) | 10549 func.WriteServiceUnitTest(f, { |
| 10583 func.WriteServiceUnitTest(f, { | 10550 'test_name': 'GLES2DecoderTestWith%s' % extension |
| 10584 'test_name': 'GLES2DecoderTestWith%s' % extension | 10551 }) |
| 10585 }) | 10552 self.generated_cpp_filenames.append(filename) |
| 10586 | |
| 10587 f.close() | |
| 10588 self.generated_cpp_filenames.append(f.filename) | |
| 10589 | 10553 |
| 10590 def WriteGLES2Header(self, filename): | 10554 def WriteGLES2Header(self, filename): |
| 10591 """Writes the GLES2 header.""" | 10555 """Writes the GLES2 header.""" |
| 10592 f = CHeaderWriter( | 10556 comment = "// This file contains Chromium-specific GLES2 declarations.\n\n" |
| 10593 filename, | 10557 with CHeaderWriter(filename, comment) as f: |
| 10594 "// This file contains Chromium-specific GLES2 declarations.\n\n") | 10558 for func in self.original_functions: |
| 10595 | 10559 func.WriteGLES2Header(f) |
| 10596 for func in self.original_functions: | 10560 f.write("\n") |
| 10597 func.WriteGLES2Header(f) | 10561 self.generated_cpp_filenames.append(filename) |
| 10598 | |
| 10599 f.write("\n") | |
| 10600 f.close() | |
| 10601 self.generated_cpp_filenames.append(f.filename) | |
| 10602 | 10562 |
| 10603 def WriteGLES2CLibImplementation(self, filename): | 10563 def WriteGLES2CLibImplementation(self, filename): |
| 10604 """Writes the GLES2 c lib implementation.""" | 10564 """Writes the GLES2 c lib implementation.""" |
| 10605 f = CHeaderWriter( | 10565 comment = "// These functions emulate GLES2 over command buffers.\n" |
| 10606 filename, | 10566 with CHeaderWriter(filename, comment) as f: |
| 10607 "// These functions emulate GLES2 over command buffers.\n") | 10567 for func in self.original_functions: |
| 10608 | 10568 func.WriteGLES2CLibImplementation(f) |
| 10609 for func in self.original_functions: | 10569 f.write(""" |
| 10610 func.WriteGLES2CLibImplementation(f) | |
| 10611 | |
| 10612 f.write(""" | |
| 10613 namespace gles2 { | 10570 namespace gles2 { |
| 10614 | 10571 |
| 10615 extern const NameToFunc g_gles2_function_table[] = { | 10572 extern const NameToFunc g_gles2_function_table[] = { |
| 10616 """) | 10573 """) |
| 10617 for func in self.original_functions: | 10574 for func in self.original_functions: |
| 10618 f.write( | 10575 f.write( |
| 10619 ' { "gl%s", reinterpret_cast<GLES2FunctionPointer>(gl%s), },\n' % | 10576 ' { "gl%s", reinterpret_cast<GLES2FunctionPointer>(gl%s), },\n' % |
| 10620 (func.name, func.name)) | 10577 (func.name, func.name)) |
| 10621 f.write(""" { NULL, NULL, }, | 10578 f.write(""" { NULL, NULL, }, |
| 10622 }; | 10579 }; |
| 10623 | 10580 |
| 10624 } // namespace gles2 | 10581 } // namespace gles2 |
| 10625 """) | 10582 """) |
| 10626 f.close() | 10583 self.generated_cpp_filenames.append(filename) |
| 10627 self.generated_cpp_filenames.append(f.filename) | |
| 10628 | 10584 |
| 10629 def WriteGLES2InterfaceHeader(self, filename): | 10585 def WriteGLES2InterfaceHeader(self, filename): |
| 10630 """Writes the GLES2 interface header.""" | 10586 """Writes the GLES2 interface header.""" |
| 10631 f = CHeaderWriter( | 10587 comment = ("// This file is included by gles2_interface.h to declare the\n" |
| 10632 filename, | 10588 "// GL api functions.\n") |
| 10633 "// This file is included by gles2_interface.h to declare the\n" | 10589 with CHeaderWriter(filename, comment) as f: |
| 10634 "// GL api functions.\n") | 10590 for func in self.original_functions: |
| 10635 for func in self.original_functions: | 10591 func.WriteGLES2InterfaceHeader(f) |
| 10636 func.WriteGLES2InterfaceHeader(f) | 10592 self.generated_cpp_filenames.append(filename) |
| 10637 f.close() | |
| 10638 self.generated_cpp_filenames.append(f.filename) | |
| 10639 | 10593 |
| 10640 def WriteMojoGLES2ImplHeader(self, filename): | 10594 def WriteMojoGLES2ImplHeader(self, filename): |
| 10641 """Writes the Mojo GLES2 implementation header.""" | 10595 """Writes the Mojo GLES2 implementation header.""" |
| 10642 f = CHeaderWriter( | 10596 comment = ("// This file is included by gles2_interface.h to declare the\n" |
| 10643 filename, | 10597 "// GL api functions.\n") |
| 10644 "// This file is included by gles2_interface.h to declare the\n" | |
| 10645 "// GL api functions.\n") | |
| 10646 | |
| 10647 code = """ | 10598 code = """ |
| 10648 #include "gpu/command_buffer/client/gles2_interface.h" | 10599 #include "gpu/command_buffer/client/gles2_interface.h" |
| 10649 #include "third_party/mojo/src/mojo/public/c/gles2/gles2.h" | 10600 #include "third_party/mojo/src/mojo/public/c/gles2/gles2.h" |
| 10650 | 10601 |
| 10651 namespace mojo { | 10602 namespace mojo { |
| 10652 | 10603 |
| 10653 class MojoGLES2Impl : public gpu::gles2::GLES2Interface { | 10604 class MojoGLES2Impl : public gpu::gles2::GLES2Interface { |
| 10654 public: | 10605 public: |
| 10655 explicit MojoGLES2Impl(MojoGLES2Context context) { | 10606 explicit MojoGLES2Impl(MojoGLES2Context context) { |
| 10656 context_ = context; | 10607 context_ = context; |
| 10657 } | 10608 } |
| 10658 ~MojoGLES2Impl() override {} | 10609 ~MojoGLES2Impl() override {} |
| 10659 """ | 10610 """ |
| 10660 f.write(code); | 10611 with CHeaderWriter(filename, comment) as f: |
| 10661 for func in self.original_functions: | 10612 f.write(code); |
| 10662 func.WriteMojoGLES2ImplHeader(f) | 10613 for func in self.original_functions: |
| 10663 code = """ | 10614 func.WriteMojoGLES2ImplHeader(f) |
| 10615 code = """ |
| 10664 private: | 10616 private: |
| 10665 MojoGLES2Context context_; | 10617 MojoGLES2Context context_; |
| 10666 }; | 10618 }; |
| 10667 | 10619 |
| 10668 } // namespace mojo | 10620 } // namespace mojo |
| 10669 """ | 10621 """ |
| 10670 f.write(code); | 10622 f.write(code); |
| 10671 f.close() | 10623 self.generated_cpp_filenames.append(filename) |
| 10672 self.generated_cpp_filenames.append(f.filename) | |
| 10673 | 10624 |
| 10674 def WriteMojoGLES2Impl(self, filename): | 10625 def WriteMojoGLES2Impl(self, filename): |
| 10675 """Writes the Mojo GLES2 implementation.""" | 10626 """Writes the Mojo GLES2 implementation.""" |
| 10676 f = CWriter(filename) | |
| 10677 f.write(_LICENSE) | |
| 10678 f.write(_DO_NOT_EDIT_WARNING) | |
| 10679 | |
| 10680 code = """ | 10627 code = """ |
| 10681 #include "mojo/gpu/mojo_gles2_impl_autogen.h" | 10628 #include "mojo/gpu/mojo_gles2_impl_autogen.h" |
| 10682 | 10629 |
| 10683 #include "base/logging.h" | 10630 #include "base/logging.h" |
| 10684 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_copy_texture.h" | 10631 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_copy_texture.h" |
| 10685 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_image.h" | 10632 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_image.h" |
| 10686 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_miscellaneous.h" | 10633 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_miscellaneous.h" |
| 10687 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_pixel_transfer_buffe
r_object.h" | 10634 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_pixel_transfer_buffe
r_object.h" |
| 10688 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_sub_image.h" | 10635 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_sub_image.h" |
| 10689 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_sync_point.h" | 10636 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_sync_point.h" |
| 10690 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_texture_mailbox.h" | 10637 #include "third_party/mojo/src/mojo/public/c/gles2/chromium_texture_mailbox.h" |
| 10691 #include "third_party/mojo/src/mojo/public/c/gles2/gles2.h" | 10638 #include "third_party/mojo/src/mojo/public/c/gles2/gles2.h" |
| 10692 #include "third_party/mojo/src/mojo/public/c/gles2/occlusion_query_ext.h" | 10639 #include "third_party/mojo/src/mojo/public/c/gles2/occlusion_query_ext.h" |
| 10693 | 10640 |
| 10694 namespace mojo { | 10641 namespace mojo { |
| 10695 | 10642 |
| 10696 """ | 10643 """ |
| 10697 f.write(code); | 10644 with CWriter(filename) as f: |
| 10698 for func in self.original_functions: | 10645 f.write(code); |
| 10699 func.WriteMojoGLES2Impl(f) | 10646 for func in self.original_functions: |
| 10700 code = """ | 10647 func.WriteMojoGLES2Impl(f) |
| 10648 code = """ |
| 10701 | 10649 |
| 10702 } // namespace mojo | 10650 } // namespace mojo |
| 10703 """ | 10651 """ |
| 10704 f.write(code); | 10652 f.write(code); |
| 10705 f.close() | 10653 self.generated_cpp_filenames.append(filename) |
| 10706 self.generated_cpp_filenames.append(f.filename) | |
| 10707 | 10654 |
| 10708 def WriteGLES2InterfaceStub(self, filename): | 10655 def WriteGLES2InterfaceStub(self, filename): |
| 10709 """Writes the GLES2 interface stub header.""" | 10656 """Writes the GLES2 interface stub header.""" |
| 10710 f = CHeaderWriter( | 10657 comment = "// This file is included by gles2_interface_stub.h.\n" |
| 10711 filename, | 10658 with CHeaderWriter(filename, comment) as f: |
| 10712 "// This file is included by gles2_interface_stub.h.\n") | 10659 for func in self.original_functions: |
| 10713 for func in self.original_functions: | 10660 func.WriteGLES2InterfaceStub(f) |
| 10714 func.WriteGLES2InterfaceStub(f) | 10661 self.generated_cpp_filenames.append(filename) |
| 10715 f.close() | |
| 10716 self.generated_cpp_filenames.append(f.filename) | |
| 10717 | 10662 |
| 10718 def WriteGLES2InterfaceStubImpl(self, filename): | 10663 def WriteGLES2InterfaceStubImpl(self, filename): |
| 10719 """Writes the GLES2 interface header.""" | 10664 """Writes the GLES2 interface header.""" |
| 10720 f = CHeaderWriter( | 10665 comment = "// This file is included by gles2_interface_stub.cc.\n" |
| 10721 filename, | 10666 with CHeaderWriter(filename, comment) as f: |
| 10722 "// This file is included by gles2_interface_stub.cc.\n") | 10667 for func in self.original_functions: |
| 10723 for func in self.original_functions: | 10668 func.WriteGLES2InterfaceStubImpl(f) |
| 10724 func.WriteGLES2InterfaceStubImpl(f) | 10669 self.generated_cpp_filenames.append(filename) |
| 10725 f.close() | |
| 10726 self.generated_cpp_filenames.append(f.filename) | |
| 10727 | 10670 |
| 10728 def WriteGLES2ImplementationHeader(self, filename): | 10671 def WriteGLES2ImplementationHeader(self, filename): |
| 10729 """Writes the GLES2 Implementation header.""" | 10672 """Writes the GLES2 Implementation header.""" |
| 10730 f = CHeaderWriter( | 10673 comment = \ |
| 10731 filename, | 10674 ("// This file is included by gles2_implementation.h to declare the\n" |
| 10732 "// This file is included by gles2_implementation.h to declare the\n" | 10675 "// GL api functions.\n") |
| 10733 "// GL api functions.\n") | 10676 with CHeaderWriter(filename, comment) as f: |
| 10734 for func in self.original_functions: | 10677 for func in self.original_functions: |
| 10735 func.WriteGLES2ImplementationHeader(f) | 10678 func.WriteGLES2ImplementationHeader(f) |
| 10736 f.close() | 10679 self.generated_cpp_filenames.append(filename) |
| 10737 self.generated_cpp_filenames.append(f.filename) | |
| 10738 | 10680 |
| 10739 def WriteGLES2Implementation(self, filename): | 10681 def WriteGLES2Implementation(self, filename): |
| 10740 """Writes the GLES2 Implementation.""" | 10682 """Writes the GLES2 Implementation.""" |
| 10741 f = CHeaderWriter( | 10683 comment = \ |
| 10742 filename, | 10684 ("// This file is included by gles2_implementation.cc to define the\n" |
| 10743 "// This file is included by gles2_implementation.cc to define the\n" | 10685 "// GL api functions.\n") |
| 10744 "// GL api functions.\n") | 10686 with CHeaderWriter(filename, comment) as f: |
| 10745 for func in self.original_functions: | 10687 for func in self.original_functions: |
| 10746 func.WriteGLES2Implementation(f) | 10688 func.WriteGLES2Implementation(f) |
| 10747 f.close() | 10689 self.generated_cpp_filenames.append(filename) |
| 10748 self.generated_cpp_filenames.append(f.filename) | |
| 10749 | 10690 |
| 10750 def WriteGLES2TraceImplementationHeader(self, filename): | 10691 def WriteGLES2TraceImplementationHeader(self, filename): |
| 10751 """Writes the GLES2 Trace Implementation header.""" | 10692 """Writes the GLES2 Trace Implementation header.""" |
| 10752 f = CHeaderWriter( | 10693 comment = "// This file is included by gles2_trace_implementation.h\n" |
| 10753 filename, | 10694 with CHeaderWriter(filename, comment) as f: |
| 10754 "// This file is included by gles2_trace_implementation.h\n") | 10695 for func in self.original_functions: |
| 10755 for func in self.original_functions: | 10696 func.WriteGLES2TraceImplementationHeader(f) |
| 10756 func.WriteGLES2TraceImplementationHeader(f) | 10697 self.generated_cpp_filenames.append(filename) |
| 10757 f.close() | |
| 10758 self.generated_cpp_filenames.append(f.filename) | |
| 10759 | 10698 |
| 10760 def WriteGLES2TraceImplementation(self, filename): | 10699 def WriteGLES2TraceImplementation(self, filename): |
| 10761 """Writes the GLES2 Trace Implementation.""" | 10700 """Writes the GLES2 Trace Implementation.""" |
| 10762 f = CHeaderWriter( | 10701 comment = "// This file is included by gles2_trace_implementation.cc\n" |
| 10763 filename, | 10702 with CHeaderWriter(filename, comment) as f: |
| 10764 "// This file is included by gles2_trace_implementation.cc\n") | 10703 for func in self.original_functions: |
| 10765 for func in self.original_functions: | 10704 func.WriteGLES2TraceImplementation(f) |
| 10766 func.WriteGLES2TraceImplementation(f) | 10705 self.generated_cpp_filenames.append(filename) |
| 10767 f.close() | |
| 10768 self.generated_cpp_filenames.append(f.filename) | |
| 10769 | 10706 |
| 10770 def WriteGLES2ImplementationUnitTests(self, filename): | 10707 def WriteGLES2ImplementationUnitTests(self, filename): |
| 10771 """Writes the GLES2 helper header.""" | 10708 """Writes the GLES2 helper header.""" |
| 10772 f = CHeaderWriter( | 10709 comment = \ |
| 10773 filename, | 10710 ("// This file is included by gles2_implementation.h to declare the\n" |
| 10774 "// This file is included by gles2_implementation.h to declare the\n" | 10711 "// GL api functions.\n") |
| 10775 "// GL api functions.\n") | 10712 with CHeaderWriter(filename, comment) as f: |
| 10776 for func in self.original_functions: | 10713 for func in self.original_functions: |
| 10777 func.WriteGLES2ImplementationUnitTest(f) | 10714 func.WriteGLES2ImplementationUnitTest(f) |
| 10778 f.close() | 10715 self.generated_cpp_filenames.append(filename) |
| 10779 self.generated_cpp_filenames.append(f.filename) | |
| 10780 | 10716 |
| 10781 def WriteServiceUtilsHeader(self, filename): | 10717 def WriteServiceUtilsHeader(self, filename): |
| 10782 """Writes the gles2 auto generated utility header.""" | 10718 """Writes the gles2 auto generated utility header.""" |
| 10783 f = CHeaderWriter(filename) | 10719 with CHeaderWriter(filename) as f: |
| 10784 for name in sorted(_NAMED_TYPE_INFO.keys()): | 10720 for name in sorted(_NAMED_TYPE_INFO.keys()): |
| 10785 named_type = NamedType(_NAMED_TYPE_INFO[name]) | 10721 named_type = NamedType(_NAMED_TYPE_INFO[name]) |
| 10786 if named_type.IsConstant(): | 10722 if named_type.IsConstant(): |
| 10787 continue | 10723 continue |
| 10788 f.write("ValueValidator<%s> %s;\n" % | 10724 f.write("ValueValidator<%s> %s;\n" % |
| 10789 (named_type.GetType(), ToUnderscore(name))) | 10725 (named_type.GetType(), ToUnderscore(name))) |
| 10790 f.write("\n") | 10726 f.write("\n") |
| 10791 f.close() | 10727 self.generated_cpp_filenames.append(filename) |
| 10792 self.generated_cpp_filenames.append(f.filename) | |
| 10793 | 10728 |
| 10794 def WriteServiceUtilsImplementation(self, filename): | 10729 def WriteServiceUtilsImplementation(self, filename): |
| 10795 """Writes the gles2 auto generated utility implementation.""" | 10730 """Writes the gles2 auto generated utility implementation.""" |
| 10796 f = CHeaderWriter(filename) | 10731 with CHeaderWriter(filename) as f: |
| 10797 names = sorted(_NAMED_TYPE_INFO.keys()) | 10732 names = sorted(_NAMED_TYPE_INFO.keys()) |
| 10798 for name in names: | 10733 for name in names: |
| 10799 named_type = NamedType(_NAMED_TYPE_INFO[name]) | 10734 named_type = NamedType(_NAMED_TYPE_INFO[name]) |
| 10800 if named_type.IsConstant(): | 10735 if named_type.IsConstant(): |
| 10801 continue | 10736 continue |
| 10802 if named_type.GetValidValues(): | 10737 if named_type.GetValidValues(): |
| 10803 f.write("static const %s valid_%s_table[] = {\n" % | 10738 f.write("static const %s valid_%s_table[] = {\n" % |
| 10804 (named_type.GetType(), ToUnderscore(name))) | 10739 (named_type.GetType(), ToUnderscore(name))) |
| 10805 for value in named_type.GetValidValues(): | 10740 for value in named_type.GetValidValues(): |
| 10806 f.write(" %s,\n" % value) | 10741 f.write(" %s,\n" % value) |
| 10807 f.write("};\n") | 10742 f.write("};\n") |
| 10808 f.write("\n") | 10743 f.write("\n") |
| 10809 if named_type.GetValidValuesES3(): | 10744 if named_type.GetValidValuesES3(): |
| 10810 f.write("static const %s valid_%s_table_es3[] = {\n" % | 10745 f.write("static const %s valid_%s_table_es3[] = {\n" % |
| 10811 (named_type.GetType(), ToUnderscore(name))) | 10746 (named_type.GetType(), ToUnderscore(name))) |
| 10812 for value in named_type.GetValidValuesES3(): | 10747 for value in named_type.GetValidValuesES3(): |
| 10813 f.write(" %s,\n" % value) | 10748 f.write(" %s,\n" % value) |
| 10814 f.write("};\n") | 10749 f.write("};\n") |
| 10815 f.write("\n") | 10750 f.write("\n") |
| 10816 if named_type.GetDeprecatedValuesES3(): | 10751 if named_type.GetDeprecatedValuesES3(): |
| 10817 f.write("static const %s deprecated_%s_table_es3[] = {\n" % | 10752 f.write("static const %s deprecated_%s_table_es3[] = {\n" % |
| 10818 (named_type.GetType(), ToUnderscore(name))) | 10753 (named_type.GetType(), ToUnderscore(name))) |
| 10819 for value in named_type.GetDeprecatedValuesES3(): | 10754 for value in named_type.GetDeprecatedValuesES3(): |
| 10820 f.write(" %s,\n" % value) | 10755 f.write(" %s,\n" % value) |
| 10821 f.write("};\n") | 10756 f.write("};\n") |
| 10822 f.write("\n") | 10757 f.write("\n") |
| 10823 f.write("Validators::Validators()") | 10758 f.write("Validators::Validators()") |
| 10824 pre = ' : ' | 10759 pre = ' : ' |
| 10825 for count, name in enumerate(names): | 10760 for count, name in enumerate(names): |
| 10826 named_type = NamedType(_NAMED_TYPE_INFO[name]) | 10761 named_type = NamedType(_NAMED_TYPE_INFO[name]) |
| 10827 if named_type.IsConstant(): | 10762 if named_type.IsConstant(): |
| 10828 continue | 10763 continue |
| 10829 if named_type.GetValidValues(): | 10764 if named_type.GetValidValues(): |
| 10830 code = """%(pre)s%(name)s( | 10765 code = """%(pre)s%(name)s( |
| 10831 valid_%(name)s_table, arraysize(valid_%(name)s_table))""" | 10766 valid_%(name)s_table, arraysize(valid_%(name)s_table))""" |
| 10832 else: | 10767 else: |
| 10833 code = "%(pre)s%(name)s()" | 10768 code = "%(pre)s%(name)s()" |
| 10834 f.write(code % { | 10769 f.write(code % { |
| 10835 'name': ToUnderscore(name), | 10770 'name': ToUnderscore(name), |
| 10836 'pre': pre, | 10771 'pre': pre, |
| 10837 }) | 10772 }) |
| 10838 pre = ',\n ' | 10773 pre = ',\n ' |
| 10839 f.write(" {\n"); | 10774 f.write(" {\n"); |
| 10840 f.write("}\n\n"); | 10775 f.write("}\n\n"); |
| 10841 | 10776 |
| 10842 f.write("void Validators::UpdateValuesES3() {\n") | 10777 f.write("void Validators::UpdateValuesES3() {\n") |
| 10843 for name in names: | 10778 for name in names: |
| 10844 named_type = NamedType(_NAMED_TYPE_INFO[name]) | 10779 named_type = NamedType(_NAMED_TYPE_INFO[name]) |
| 10845 if named_type.GetDeprecatedValuesES3(): | 10780 if named_type.GetDeprecatedValuesES3(): |
| 10846 code = """ %(name)s.RemoveValues( | 10781 code = """ %(name)s.RemoveValues( |
| 10847 deprecated_%(name)s_table_es3, arraysize(deprecated_%(name)s_table_es3)); | 10782 deprecated_%(name)s_table_es3, arraysize(deprecated_%(name)s_table_es3)); |
| 10848 """ | 10783 """ |
| 10849 f.write(code % { | 10784 f.write(code % { |
| 10850 'name': ToUnderscore(name), | 10785 'name': ToUnderscore(name), |
| 10851 }) | 10786 }) |
| 10852 if named_type.GetValidValuesES3(): | 10787 if named_type.GetValidValuesES3(): |
| 10853 code = """ %(name)s.AddValues( | 10788 code = """ %(name)s.AddValues( |
| 10854 valid_%(name)s_table_es3, arraysize(valid_%(name)s_table_es3)); | 10789 valid_%(name)s_table_es3, arraysize(valid_%(name)s_table_es3)); |
| 10855 """ | 10790 """ |
| 10856 f.write(code % { | 10791 f.write(code % { |
| 10857 'name': ToUnderscore(name), | 10792 'name': ToUnderscore(name), |
| 10858 }) | 10793 }) |
| 10859 f.write("}\n\n"); | 10794 f.write("}\n\n"); |
| 10860 f.close() | 10795 self.generated_cpp_filenames.append(filename) |
| 10861 self.generated_cpp_filenames.append(f.filename) | |
| 10862 | 10796 |
| 10863 def WriteCommonUtilsHeader(self, filename): | 10797 def WriteCommonUtilsHeader(self, filename): |
| 10864 """Writes the gles2 common utility header.""" | 10798 """Writes the gles2 common utility header.""" |
| 10865 f = CHeaderWriter(filename) | 10799 with CHeaderWriter(filename) as f: |
| 10866 type_infos = sorted(_NAMED_TYPE_INFO.keys()) | 10800 type_infos = sorted(_NAMED_TYPE_INFO.keys()) |
| 10867 for type_info in type_infos: | 10801 for type_info in type_infos: |
| 10868 if _NAMED_TYPE_INFO[type_info]['type'] == 'GLenum': | 10802 if _NAMED_TYPE_INFO[type_info]['type'] == 'GLenum': |
| 10869 f.write("static std::string GetString%s(uint32_t value);\n" % | 10803 f.write("static std::string GetString%s(uint32_t value);\n" % |
| 10870 type_info) | 10804 type_info) |
| 10871 f.write("\n") | 10805 f.write("\n") |
| 10872 f.close() | 10806 self.generated_cpp_filenames.append(filename) |
| 10873 self.generated_cpp_filenames.append(f.filename) | |
| 10874 | 10807 |
| 10875 def WriteCommonUtilsImpl(self, filename): | 10808 def WriteCommonUtilsImpl(self, filename): |
| 10876 """Writes the gles2 common utility header.""" | 10809 """Writes the gles2 common utility header.""" |
| 10877 enum_re = re.compile(r'\#define\s+(GL_[a-zA-Z0-9_]+)\s+([0-9A-Fa-fx]+)') | 10810 enum_re = re.compile(r'\#define\s+(GL_[a-zA-Z0-9_]+)\s+([0-9A-Fa-fx]+)') |
| 10878 dict = {} | 10811 dict = {} |
| 10879 for fname in ['third_party/khronos/GLES2/gl2.h', | 10812 for fname in ['third_party/khronos/GLES2/gl2.h', |
| 10880 'third_party/khronos/GLES2/gl2ext.h', | 10813 'third_party/khronos/GLES2/gl2ext.h', |
| 10881 'third_party/khronos/GLES3/gl3.h', | 10814 'third_party/khronos/GLES3/gl3.h', |
| 10882 'gpu/GLES2/gl2chromium.h', | 10815 'gpu/GLES2/gl2chromium.h', |
| 10883 'gpu/GLES2/gl2extchromium.h']: | 10816 'gpu/GLES2/gl2extchromium.h']: |
| 10884 lines = open(fname).readlines() | 10817 lines = open(fname).readlines() |
| 10885 for line in lines: | 10818 for line in lines: |
| 10886 m = enum_re.match(line) | 10819 m = enum_re.match(line) |
| 10887 if m: | 10820 if m: |
| 10888 name = m.group(1) | 10821 name = m.group(1) |
| 10889 value = m.group(2) | 10822 value = m.group(2) |
| 10890 if len(value) <= 10: | 10823 if len(value) <= 10: |
| 10891 if not value in dict: | 10824 if not value in dict: |
| 10892 dict[value] = name | 10825 dict[value] = name |
| 10893 # check our own _CHROMIUM macro conflicts with khronos GL headers. | 10826 # check our own _CHROMIUM macro conflicts with khronos GL headers. |
| 10894 elif dict[value] != name and (name.endswith('_CHROMIUM') or | 10827 elif dict[value] != name and (name.endswith('_CHROMIUM') or |
| 10895 dict[value].endswith('_CHROMIUM')): | 10828 dict[value].endswith('_CHROMIUM')): |
| 10896 self.Error("code collision: %s and %s have the same code %s" % | 10829 self.Error("code collision: %s and %s have the same code %s" % |
| 10897 (dict[value], name, value)) | 10830 (dict[value], name, value)) |
| 10898 | 10831 |
| 10899 f = CHeaderWriter(filename) | 10832 with CHeaderWriter(filename) as f: |
| 10900 f.write("static const GLES2Util::EnumToString " | 10833 f.write("static const GLES2Util::EnumToString " |
| 10901 "enum_to_string_table[] = {\n") | 10834 "enum_to_string_table[] = {\n") |
| 10902 for value in dict: | 10835 for value in dict: |
| 10903 f.write(' { %s, "%s", },\n' % (value, dict[value])) | 10836 f.write(' { %s, "%s", },\n' % (value, dict[value])) |
| 10904 f.write("""}; | 10837 f.write("""}; |
| 10905 | 10838 |
| 10906 const GLES2Util::EnumToString* const GLES2Util::enum_to_string_table_ = | 10839 const GLES2Util::EnumToString* const GLES2Util::enum_to_string_table_ = |
| 10907 enum_to_string_table; | 10840 enum_to_string_table; |
| 10908 const size_t GLES2Util::enum_to_string_table_len_ = | 10841 const size_t GLES2Util::enum_to_string_table_len_ = |
| 10909 sizeof(enum_to_string_table) / sizeof(enum_to_string_table[0]); | 10842 sizeof(enum_to_string_table) / sizeof(enum_to_string_table[0]); |
| 10910 | 10843 |
| 10911 """) | 10844 """) |
| 10912 | 10845 |
| 10913 enums = sorted(_NAMED_TYPE_INFO.keys()) | 10846 enums = sorted(_NAMED_TYPE_INFO.keys()) |
| 10914 for enum in enums: | 10847 for enum in enums: |
| 10915 if _NAMED_TYPE_INFO[enum]['type'] == 'GLenum': | 10848 if _NAMED_TYPE_INFO[enum]['type'] == 'GLenum': |
| 10916 f.write("std::string GLES2Util::GetString%s(uint32_t value) {\n" % | 10849 f.write("std::string GLES2Util::GetString%s(uint32_t value) {\n" % |
| 10917 enum) | 10850 enum) |
| 10918 valid_list = _NAMED_TYPE_INFO[enum]['valid'] | 10851 valid_list = _NAMED_TYPE_INFO[enum]['valid'] |
| 10919 if 'valid_es3' in _NAMED_TYPE_INFO[enum]: | 10852 if 'valid_es3' in _NAMED_TYPE_INFO[enum]: |
| 10920 valid_list = valid_list + _NAMED_TYPE_INFO[enum]['valid_es3'] | 10853 valid_list = valid_list + _NAMED_TYPE_INFO[enum]['valid_es3'] |
| 10921 assert len(valid_list) == len(set(valid_list)) | 10854 assert len(valid_list) == len(set(valid_list)) |
| 10922 if len(valid_list) > 0: | 10855 if len(valid_list) > 0: |
| 10923 f.write(" static const EnumToString string_table[] = {\n") | 10856 f.write(" static const EnumToString string_table[] = {\n") |
| 10924 for value in valid_list: | 10857 for value in valid_list: |
| 10925 f.write(' { %s, "%s" },\n' % (value, value)) | 10858 f.write(' { %s, "%s" },\n' % (value, value)) |
| 10926 f.write(""" }; | 10859 f.write(""" }; |
| 10927 return GLES2Util::GetQualifiedEnumString( | 10860 return GLES2Util::GetQualifiedEnumString( |
| 10928 string_table, arraysize(string_table), value); | 10861 string_table, arraysize(string_table), value); |
| 10929 } | 10862 } |
| 10930 | 10863 |
| 10931 """) | 10864 """) |
| 10932 else: | 10865 else: |
| 10933 f.write(""" return GLES2Util::GetQualifiedEnumString( | 10866 f.write(""" return GLES2Util::GetQualifiedEnumString( |
| 10934 NULL, 0, value); | 10867 NULL, 0, value); |
| 10935 } | 10868 } |
| 10936 | 10869 |
| 10937 """) | 10870 """) |
| 10938 f.close() | 10871 self.generated_cpp_filenames.append(filename) |
| 10939 self.generated_cpp_filenames.append(f.filename) | |
| 10940 | 10872 |
| 10941 def WritePepperGLES2Interface(self, filename, dev): | 10873 def WritePepperGLES2Interface(self, filename, dev): |
| 10942 """Writes the Pepper OpenGLES interface definition.""" | 10874 """Writes the Pepper OpenGLES interface definition.""" |
| 10943 f = CWriter(filename) | 10875 with CWriter(filename) as f: |
| 10944 f.write(_LICENSE) | 10876 f.write("label Chrome {\n") |
| 10945 f.write(_DO_NOT_EDIT_WARNING) | 10877 f.write(" M39 = 1.0\n") |
| 10946 | |
| 10947 f.write("label Chrome {\n") | |
| 10948 f.write(" M39 = 1.0\n") | |
| 10949 f.write("};\n\n") | |
| 10950 | |
| 10951 if not dev: | |
| 10952 # Declare GL types. | |
| 10953 f.write("[version=1.0]\n") | |
| 10954 f.write("describe {\n") | |
| 10955 for gltype in ['GLbitfield', 'GLboolean', 'GLbyte', 'GLclampf', | |
| 10956 'GLclampx', 'GLenum', 'GLfixed', 'GLfloat', 'GLint', | |
| 10957 'GLintptr', 'GLshort', 'GLsizei', 'GLsizeiptr', | |
| 10958 'GLubyte', 'GLuint', 'GLushort']: | |
| 10959 f.write(" %s;\n" % gltype) | |
| 10960 f.write(" %s_ptr_t;\n" % gltype) | |
| 10961 f.write("};\n\n") | 10878 f.write("};\n\n") |
| 10962 | 10879 |
| 10963 # C level typedefs. | 10880 if not dev: |
| 10964 f.write("#inline c\n") | 10881 # Declare GL types. |
| 10965 f.write("#include \"ppapi/c/pp_resource.h\"\n") | 10882 f.write("[version=1.0]\n") |
| 10966 if dev: | 10883 f.write("describe {\n") |
| 10967 f.write("#include \"ppapi/c/ppb_opengles2.h\"\n\n") | 10884 for gltype in ['GLbitfield', 'GLboolean', 'GLbyte', 'GLclampf', |
| 10968 else: | 10885 'GLclampx', 'GLenum', 'GLfixed', 'GLfloat', 'GLint', |
| 10969 f.write("\n#ifndef __gl2_h_\n") | 10886 'GLintptr', 'GLshort', 'GLsizei', 'GLsizeiptr', |
| 10970 for (k, v) in _GL_TYPES.iteritems(): | 10887 'GLubyte', 'GLuint', 'GLushort']: |
| 10971 f.write("typedef %s %s;\n" % (v, k)) | 10888 f.write(" %s;\n" % gltype) |
| 10972 f.write("#ifdef _WIN64\n") | 10889 f.write(" %s_ptr_t;\n" % gltype) |
| 10973 for (k, v) in _GL_TYPES_64.iteritems(): | 10890 f.write("};\n\n") |
| 10974 f.write("typedef %s %s;\n" % (v, k)) | 10891 |
| 10975 f.write("#else\n") | 10892 # C level typedefs. |
| 10976 for (k, v) in _GL_TYPES_32.iteritems(): | 10893 f.write("#inline c\n") |
| 10977 f.write("typedef %s %s;\n" % (v, k)) | 10894 f.write("#include \"ppapi/c/pp_resource.h\"\n") |
| 10978 f.write("#endif // _WIN64\n") | 10895 if dev: |
| 10979 f.write("#endif // __gl2_h_\n\n") | 10896 f.write("#include \"ppapi/c/ppb_opengles2.h\"\n\n") |
| 10980 f.write("#endinl\n") | 10897 else: |
| 10981 | 10898 f.write("\n#ifndef __gl2_h_\n") |
| 10982 for interface in self.pepper_interfaces: | 10899 for (k, v) in _GL_TYPES.iteritems(): |
| 10983 if interface.dev != dev: | 10900 f.write("typedef %s %s;\n" % (v, k)) |
| 10984 continue | 10901 f.write("#ifdef _WIN64\n") |
| 10985 # Historically, we provide OpenGLES2 interfaces with struct | 10902 for (k, v) in _GL_TYPES_64.iteritems(): |
| 10986 # namespace. Not to break code which uses the interface as | 10903 f.write("typedef %s %s;\n" % (v, k)) |
| 10987 # "struct OpenGLES2", we put it in struct namespace. | 10904 f.write("#else\n") |
| 10988 f.write('\n[macro="%s", force_struct_namespace]\n' % | 10905 for (k, v) in _GL_TYPES_32.iteritems(): |
| 10989 interface.GetInterfaceName()) | 10906 f.write("typedef %s %s;\n" % (v, k)) |
| 10990 f.write("interface %s {\n" % interface.GetStructName()) | 10907 f.write("#endif // _WIN64\n") |
| 10991 for func in self.original_functions: | 10908 f.write("#endif // __gl2_h_\n\n") |
| 10992 if not func.InPepperInterface(interface): | 10909 f.write("#endinl\n") |
| 10993 continue | 10910 |
| 10994 | 10911 for interface in self.pepper_interfaces: |
| 10995 ret_type = func.MapCTypeToPepperIdlType(func.return_type, | 10912 if interface.dev != dev: |
| 10996 is_for_return_type=True) | 10913 continue |
| 10997 func_prefix = " %s %s(" % (ret_type, func.GetPepperName()) | 10914 # Historically, we provide OpenGLES2 interfaces with struct |
| 10998 f.write(func_prefix) | 10915 # namespace. Not to break code which uses the interface as |
| 10999 f.write("[in] PP_Resource context") | 10916 # "struct OpenGLES2", we put it in struct namespace. |
| 11000 for arg in func.MakeTypedPepperIdlArgStrings(): | 10917 f.write('\n[macro="%s", force_struct_namespace]\n' % |
| 11001 f.write(",\n" + " " * len(func_prefix) + arg) | 10918 interface.GetInterfaceName()) |
| 11002 f.write(");\n") | 10919 f.write("interface %s {\n" % interface.GetStructName()) |
| 11003 f.write("};\n\n") | 10920 for func in self.original_functions: |
| 11004 | 10921 if not func.InPepperInterface(interface): |
| 11005 | 10922 continue |
| 11006 f.close() | 10923 |
| 10924 ret_type = func.MapCTypeToPepperIdlType(func.return_type, |
| 10925 is_for_return_type=True) |
| 10926 func_prefix = " %s %s(" % (ret_type, func.GetPepperName()) |
| 10927 f.write(func_prefix) |
| 10928 f.write("[in] PP_Resource context") |
| 10929 for arg in func.MakeTypedPepperIdlArgStrings(): |
| 10930 f.write(",\n" + " " * len(func_prefix) + arg) |
| 10931 f.write(");\n") |
| 10932 f.write("};\n\n") |
| 11007 | 10933 |
| 11008 def WritePepperGLES2Implementation(self, filename): | 10934 def WritePepperGLES2Implementation(self, filename): |
| 11009 """Writes the Pepper OpenGLES interface implementation.""" | 10935 """Writes the Pepper OpenGLES interface implementation.""" |
| 11010 | 10936 with CWriter(filename) as f: |
| 11011 f = CWriter(filename) | 10937 f.write("#include \"ppapi/shared_impl/ppb_opengles2_shared.h\"\n\n") |
| 11012 f.write(_LICENSE) | 10938 f.write("#include \"base/logging.h\"\n") |
| 11013 f.write(_DO_NOT_EDIT_WARNING) | 10939 f.write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n") |
| 11014 | 10940 f.write("#include \"ppapi/shared_impl/ppb_graphics_3d_shared.h\"\n") |
| 11015 f.write("#include \"ppapi/shared_impl/ppb_opengles2_shared.h\"\n\n") | 10941 f.write("#include \"ppapi/thunk/enter.h\"\n\n") |
| 11016 f.write("#include \"base/logging.h\"\n") | 10942 |
| 11017 f.write("#include \"gpu/command_buffer/client/gles2_implementation.h\"\n") | 10943 f.write("namespace ppapi {\n\n") |
| 11018 f.write("#include \"ppapi/shared_impl/ppb_graphics_3d_shared.h\"\n") | 10944 f.write("namespace {\n\n") |
| 11019 f.write("#include \"ppapi/thunk/enter.h\"\n\n") | 10945 |
| 11020 | 10946 f.write("typedef thunk::EnterResource<thunk::PPB_Graphics3D_API>" |
| 11021 f.write("namespace ppapi {\n\n") | 10947 " Enter3D;\n\n") |
| 11022 f.write("namespace {\n\n") | 10948 |
| 11023 | 10949 f.write("gpu::gles2::GLES2Implementation* ToGles2Impl(Enter3D*" |
| 11024 f.write("typedef thunk::EnterResource<thunk::PPB_Graphics3D_API>" | 10950 " enter) {\n") |
| 11025 " Enter3D;\n\n") | 10951 f.write(" DCHECK(enter);\n") |
| 11026 | 10952 f.write(" DCHECK(enter->succeeded());\n") |
| 11027 f.write("gpu::gles2::GLES2Implementation* ToGles2Impl(Enter3D*" | 10953 f.write(" return static_cast<PPB_Graphics3D_Shared*>(enter->object())->" |
| 11028 " enter) {\n") | 10954 "gles2_impl();\n"); |
| 11029 f.write(" DCHECK(enter);\n") | 10955 f.write("}\n\n"); |
| 11030 f.write(" DCHECK(enter->succeeded());\n") | 10956 |
| 11031 f.write(" return static_cast<PPB_Graphics3D_Shared*>(enter->object())->" | 10957 for func in self.original_functions: |
| 11032 "gles2_impl();\n"); | 10958 if not func.InAnyPepperExtension(): |
| 11033 f.write("}\n\n"); | 10959 continue |
| 11034 | 10960 |
| 11035 for func in self.original_functions: | 10961 original_arg = func.MakeTypedPepperArgString("") |
| 11036 if not func.InAnyPepperExtension(): | 10962 context_arg = "PP_Resource context_id" |
| 11037 continue | 10963 if len(original_arg): |
| 11038 | 10964 arg = context_arg + ", " + original_arg |
| 11039 original_arg = func.MakeTypedPepperArgString("") | 10965 else: |
| 11040 context_arg = "PP_Resource context_id" | 10966 arg = context_arg |
| 11041 if len(original_arg): | 10967 f.write("%s %s(%s) {\n" % |
| 11042 arg = context_arg + ", " + original_arg | 10968 (func.return_type, func.GetPepperName(), arg)) |
| 11043 else: | 10969 f.write(" Enter3D enter(context_id, true);\n") |
| 11044 arg = context_arg | 10970 f.write(" if (enter.succeeded()) {\n") |
| 11045 f.write("%s %s(%s) {\n" % | 10971 |
| 11046 (func.return_type, func.GetPepperName(), arg)) | 10972 return_str = "" if func.return_type == "void" else "return " |
| 11047 f.write(" Enter3D enter(context_id, true);\n") | 10973 f.write(" %sToGles2Impl(&enter)->%s(%s);\n" % |
| 11048 f.write(" if (enter.succeeded()) {\n") | 10974 (return_str, func.original_name, |
| 11049 | 10975 func.MakeOriginalArgString(""))) |
| 11050 return_str = "" if func.return_type == "void" else "return " | 10976 f.write(" }") |
| 11051 f.write(" %sToGles2Impl(&enter)->%s(%s);\n" % | 10977 if func.return_type == "void": |
| 11052 (return_str, func.original_name, | 10978 f.write("\n") |
| 11053 func.MakeOriginalArgString(""))) | 10979 else: |
| 11054 f.write(" }") | 10980 f.write(" else {\n") |
| 11055 if func.return_type == "void": | 10981 f.write(" return %s;\n" % func.GetErrorReturnString()) |
| 10982 f.write(" }\n") |
| 10983 f.write("}\n\n") |
| 10984 |
| 10985 f.write("} // namespace\n") |
| 10986 |
| 10987 for interface in self.pepper_interfaces: |
| 10988 f.write("const %s* PPB_OpenGLES2_Shared::Get%sInterface() {\n" % |
| 10989 (interface.GetStructName(), interface.GetName())) |
| 10990 f.write(" static const struct %s " |
| 10991 "ppb_opengles2 = {\n" % interface.GetStructName()) |
| 10992 f.write(" &") |
| 10993 f.write(",\n &".join( |
| 10994 f.GetPepperName() for f in self.original_functions |
| 10995 if f.InPepperInterface(interface))) |
| 11056 f.write("\n") | 10996 f.write("\n") |
| 11057 else: | 10997 |
| 11058 f.write(" else {\n") | 10998 f.write(" };\n") |
| 11059 f.write(" return %s;\n" % func.GetErrorReturnString()) | 10999 f.write(" return &ppb_opengles2;\n") |
| 11060 f.write(" }\n") | 11000 f.write("}\n") |
| 11061 f.write("}\n\n") | 11001 |
| 11062 | 11002 f.write("} // namespace ppapi\n") |
| 11063 f.write("} // namespace\n") | 11003 self.generated_cpp_filenames.append(filename) |
| 11064 | |
| 11065 for interface in self.pepper_interfaces: | |
| 11066 f.write("const %s* PPB_OpenGLES2_Shared::Get%sInterface() {\n" % | |
| 11067 (interface.GetStructName(), interface.GetName())) | |
| 11068 f.write(" static const struct %s " | |
| 11069 "ppb_opengles2 = {\n" % interface.GetStructName()) | |
| 11070 f.write(" &") | |
| 11071 f.write(",\n &".join( | |
| 11072 f.GetPepperName() for f in self.original_functions | |
| 11073 if f.InPepperInterface(interface))) | |
| 11074 f.write("\n") | |
| 11075 | |
| 11076 f.write(" };\n") | |
| 11077 f.write(" return &ppb_opengles2;\n") | |
| 11078 f.write("}\n") | |
| 11079 | |
| 11080 f.write("} // namespace ppapi\n") | |
| 11081 f.close() | |
| 11082 self.generated_cpp_filenames.append(f.filename) | |
| 11083 | 11004 |
| 11084 def WriteGLES2ToPPAPIBridge(self, filename): | 11005 def WriteGLES2ToPPAPIBridge(self, filename): |
| 11085 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" | 11006 """Connects GLES2 helper library to PPB_OpenGLES2 interface""" |
| 11086 | 11007 with CWriter(filename) as f: |
| 11087 f = CWriter(filename) | 11008 f.write("#ifndef GL_GLEXT_PROTOTYPES\n") |
| 11088 f.write(_LICENSE) | 11009 f.write("#define GL_GLEXT_PROTOTYPES\n") |
| 11089 f.write(_DO_NOT_EDIT_WARNING) | 11010 f.write("#endif\n") |
| 11090 | 11011 f.write("#include <GLES2/gl2.h>\n") |
| 11091 f.write("#ifndef GL_GLEXT_PROTOTYPES\n") | 11012 f.write("#include <GLES2/gl2ext.h>\n") |
| 11092 f.write("#define GL_GLEXT_PROTOTYPES\n") | 11013 f.write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n") |
| 11093 f.write("#endif\n") | 11014 |
| 11094 f.write("#include <GLES2/gl2.h>\n") | 11015 for func in self.original_functions: |
| 11095 f.write("#include <GLES2/gl2ext.h>\n") | 11016 if not func.InAnyPepperExtension(): |
| 11096 f.write("#include \"ppapi/lib/gl/gles2/gl2ext_ppapi.h\"\n\n") | 11017 continue |
| 11097 | 11018 |
| 11098 for func in self.original_functions: | 11019 interface = self.interface_info[func.GetInfo('pepper_interface') or ''] |
| 11099 if not func.InAnyPepperExtension(): | 11020 |
| 11100 continue | 11021 f.write("%s GL_APIENTRY gl%s(%s) {\n" % |
| 11101 | 11022 (func.return_type, func.GetPepperName(), |
| 11102 interface = self.interface_info[func.GetInfo('pepper_interface') or ''] | 11023 func.MakeTypedPepperArgString(""))) |
| 11103 | 11024 return_str = "" if func.return_type == "void" else "return " |
| 11104 f.write("%s GL_APIENTRY gl%s(%s) {\n" % | 11025 interface_str = "glGet%sInterfacePPAPI()" % interface.GetName() |
| 11105 (func.return_type, func.GetPepperName(), | 11026 original_arg = func.MakeOriginalArgString("") |
| 11106 func.MakeTypedPepperArgString(""))) | 11027 context_arg = "glGetCurrentContextPPAPI()" |
| 11107 return_str = "" if func.return_type == "void" else "return " | 11028 if len(original_arg): |
| 11108 interface_str = "glGet%sInterfacePPAPI()" % interface.GetName() | 11029 arg = context_arg + ", " + original_arg |
| 11109 original_arg = func.MakeOriginalArgString("") | 11030 else: |
| 11110 context_arg = "glGetCurrentContextPPAPI()" | 11031 arg = context_arg |
| 11111 if len(original_arg): | 11032 if interface.GetName(): |
| 11112 arg = context_arg + ", " + original_arg | 11033 f.write(" const struct %s* ext = %s;\n" % |
| 11113 else: | 11034 (interface.GetStructName(), interface_str)) |
| 11114 arg = context_arg | 11035 f.write(" if (ext)\n") |
| 11115 if interface.GetName(): | 11036 f.write(" %sext->%s(%s);\n" % |
| 11116 f.write(" const struct %s* ext = %s;\n" % | 11037 (return_str, func.GetPepperName(), arg)) |
| 11117 (interface.GetStructName(), interface_str)) | 11038 if return_str: |
| 11118 f.write(" if (ext)\n") | 11039 f.write(" %s0;\n" % return_str) |
| 11119 f.write(" %sext->%s(%s);\n" % | 11040 else: |
| 11120 (return_str, func.GetPepperName(), arg)) | 11041 f.write(" %s%s->%s(%s);\n" % |
| 11121 if return_str: | 11042 (return_str, interface_str, func.GetPepperName(), arg)) |
| 11122 f.write(" %s0;\n" % return_str) | 11043 f.write("}\n\n") |
| 11123 else: | 11044 self.generated_cpp_filenames.append(filename) |
| 11124 f.write(" %s%s->%s(%s);\n" % | |
| 11125 (return_str, interface_str, func.GetPepperName(), arg)) | |
| 11126 f.write("}\n\n") | |
| 11127 f.close() | |
| 11128 self.generated_cpp_filenames.append(f.filename) | |
| 11129 | 11045 |
| 11130 def WriteMojoGLCallVisitor(self, filename): | 11046 def WriteMojoGLCallVisitor(self, filename): |
| 11131 """Provides the GL implementation for mojo""" | 11047 """Provides the GL implementation for mojo""" |
| 11132 f = CWriter(filename) | 11048 with CWriter(filename) as f: |
| 11133 f.write(_LICENSE) | 11049 for func in self.original_functions: |
| 11134 f.write(_DO_NOT_EDIT_WARNING) | 11050 if not func.IsCoreGLFunction(): |
| 11135 | 11051 continue |
| 11136 for func in self.original_functions: | 11052 f.write("VISIT_GL_CALL(%s, %s, (%s), (%s))\n" % |
| 11137 if not func.IsCoreGLFunction(): | 11053 (func.name, func.return_type, |
| 11138 continue | 11054 func.MakeTypedOriginalArgString(""), |
| 11139 f.write("VISIT_GL_CALL(%s, %s, (%s), (%s))\n" % | 11055 func.MakeOriginalArgString(""))) |
| 11140 (func.name, func.return_type, | 11056 self.generated_cpp_filenames.append(filename) |
| 11141 func.MakeTypedOriginalArgString(""), | |
| 11142 func.MakeOriginalArgString(""))) | |
| 11143 | |
| 11144 f.close() | |
| 11145 self.generated_cpp_filenames.append(f.filename) | |
| 11146 | 11057 |
| 11147 def WriteMojoGLCallVisitorForExtension(self, filename, extension): | 11058 def WriteMojoGLCallVisitorForExtension(self, filename, extension): |
| 11148 """Provides the GL implementation for mojo for a particular extension""" | 11059 """Provides the GL implementation for mojo for a particular extension""" |
| 11149 f = CWriter(filename) | 11060 with CWriter(filename) as f: |
| 11150 f.write(_LICENSE) | 11061 for func in self.original_functions: |
| 11151 f.write(_DO_NOT_EDIT_WARNING) | 11062 if func.GetInfo("extension") != extension: |
| 11152 | 11063 continue |
| 11153 for func in self.original_functions: | 11064 f.write("VISIT_GL_CALL(%s, %s, (%s), (%s))\n" % |
| 11154 if func.GetInfo("extension") != extension: | 11065 (func.name, func.return_type, |
| 11155 continue | 11066 func.MakeTypedOriginalArgString(""), |
| 11156 f.write("VISIT_GL_CALL(%s, %s, (%s), (%s))\n" % | 11067 func.MakeOriginalArgString(""))) |
| 11157 (func.name, func.return_type, | 11068 self.generated_cpp_filenames.append(filename) |
| 11158 func.MakeTypedOriginalArgString(""), | |
| 11159 func.MakeOriginalArgString(""))) | |
| 11160 | |
| 11161 f.close() | |
| 11162 self.generated_cpp_filenames.append(f.filename) | |
| 11163 | 11069 |
| 11164 def Format(generated_files): | 11070 def Format(generated_files): |
| 11165 formatter = "clang-format" | 11071 formatter = "clang-format" |
| 11166 if platform.system() == "Windows": | 11072 if platform.system() == "Windows": |
| 11167 formatter += ".bat" | 11073 formatter += ".bat" |
| 11168 for filename in generated_files: | 11074 for filename in generated_files: |
| 11169 call([formatter, "-i", "-style=chromium", filename]) | 11075 call([formatter, "-i", "-style=chromium", filename]) |
| 11170 | 11076 |
| 11171 def main(argv): | 11077 def main(argv): |
| 11172 """This is the main function.""" | 11078 """This is the main function.""" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11301 Format(gen.generated_cpp_filenames) | 11207 Format(gen.generated_cpp_filenames) |
| 11302 | 11208 |
| 11303 if gen.errors > 0: | 11209 if gen.errors > 0: |
| 11304 print "%d errors" % gen.errors | 11210 print "%d errors" % gen.errors |
| 11305 return 1 | 11211 return 1 |
| 11306 return 0 | 11212 return 0 |
| 11307 | 11213 |
| 11308 | 11214 |
| 11309 if __name__ == '__main__': | 11215 if __name__ == '__main__': |
| 11310 sys.exit(main(sys.argv[1:])) | 11216 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |