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 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 }, | 2306 }, |
2307 'LoseContextCHROMIUM': { | 2307 'LoseContextCHROMIUM': { |
2308 'type': 'Manual', | 2308 'type': 'Manual', |
2309 'impl_func': True, | 2309 'impl_func': True, |
2310 'extension': True, | 2310 'extension': True, |
2311 'chromium': True, | 2311 'chromium': True, |
2312 }, | 2312 }, |
2313 } | 2313 } |
2314 | 2314 |
2315 | 2315 |
| 2316 _CHROMIUM_SPECIFIC_CONSTANTS = { |
| 2317 'GL_CONTEXT_LOST': '0x300E', # TODO(gman): What value? |
| 2318 } |
| 2319 |
| 2320 |
| 2321 _CHROMIUM_SPECIFIC_EXTENSIONS = { |
| 2322 'GL_EXT_framebuffer_multisample': { |
| 2323 'constants': { |
| 2324 'GL_DRAW_FRAMEBUFFER_BINDING': '0x8CA6', |
| 2325 'GL_DRAW_FRAMEBUFFER_BINDING_EXT': 'GL_DRAW_FRAMEBUFFER_BINDING', |
| 2326 'GL_FRAMEBUFFER_BINDING': '0x8CA6', |
| 2327 'GL_FRAMEBUFFER_BINDING_EXT': 'GL_FRAMEBUFFER_BINDING', |
| 2328 'GL_RENDERBUFFER_BINDING': '0x8CA7', |
| 2329 'GL_RENDERBUFFER_BINDING_EXT': 'GL_RENDERBUFFER_BINDING', |
| 2330 'GL_READ_FRAMEBUFFER': '0x8CA8', |
| 2331 'GL_READ_FRAMEBUFFER_EXT': 'GL_READ_FRAMEBUFFER', |
| 2332 'GL_DRAW_FRAMEBUFFER': '0x8CA9', |
| 2333 'GL_DRAW_FRAMEBUFFER_EXT': 'GL_DRAW_FRAMEBUFFER', |
| 2334 'GL_READ_FRAMEBUFFER_BINDING': '0x8CAA', |
| 2335 'GL_READ_FRAMEBUFFER_BINDING_EXT': 'GL_READ_FRAMEBUFFER_BINDING', |
| 2336 'GL_RENDERBUFFER_SAMPLES': '0x8CAB', |
| 2337 'GL_RENDERBUFFER_SAMPLES_EXT': 'GL_RENDERBUFFER_SAMPLES', |
| 2338 'GL_MAX_SAMPLES': '0x8D57', |
| 2339 'GL_MAX_SAMPLES_EXT': 'GL_MAX_SAMPLES', |
| 2340 'GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE': '0x8D56', |
| 2341 'GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT': |
| 2342 'GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE', |
| 2343 }, |
| 2344 }, |
| 2345 'GL_EXT_framebuffer_blit': { |
| 2346 'functions': [ |
| 2347 'BlitFramebufferEXT', |
| 2348 ], |
| 2349 }, |
| 2350 'GL_CHROMIUM_map_sub': { |
| 2351 'constants': { |
| 2352 'GL_READ_ONLY': '0x88B8', |
| 2353 'GL_WRITE_ONLY': '0x88B9', |
| 2354 }, |
| 2355 'functions': [ |
| 2356 'MapBufferSubDataCHROMIUM', |
| 2357 'UnmapBufferSubDataCHROMIUM', |
| 2358 'MapTexSubImage2DCHROMIUM', |
| 2359 'UnmapTexSubImage2DCHROMIUM', |
| 2360 ], |
| 2361 }, |
| 2362 'GL_CHROMIUM_resize': { |
| 2363 'functions': [ |
| 2364 'ResizeCHROMIUM', |
| 2365 ], |
| 2366 }, |
| 2367 'GL_CHROMIUM_request_extension': { |
| 2368 'functions': [ |
| 2369 'GetRequestableExtensionsCHROMIUM', |
| 2370 'RequestExtensionCHROMIUM', |
| 2371 ], |
| 2372 }, |
| 2373 'GL_CHROMIUM_rate_limit_offscreen_context': { |
| 2374 'functions': [ |
| 2375 'RateLimitOffscreenContextCHROMIUM', |
| 2376 ], |
| 2377 }, |
| 2378 'GL_CHROMIUM_get_multiple': { |
| 2379 'functions': [ |
| 2380 'GetMultipleIntegervCHROMIUM', |
| 2381 'GetProgramInfoCHROMIUM', |
| 2382 ], |
| 2383 }, |
| 2384 'GL_CHROMIUM_flipy': { |
| 2385 'constants': { |
| 2386 'GL_UNPACK_FLIP_Y_CHROMIUM': '0x9240', |
| 2387 }, |
| 2388 }, |
| 2389 'GL_CHROMIUM_texture_compression_dxt3': { |
| 2390 'constants': { |
| 2391 'GL_COMPRESSED_RGBA_S3TC_DXT3_EXT': '0x83F2', |
| 2392 }, |
| 2393 }, |
| 2394 'GL_CHROMIUM_texture_compression_dxt5': { |
| 2395 'constants': { |
| 2396 'GL_COMPRESSED_RGBA_S3TC_DXT5_EXT': '0x83F3', |
| 2397 }, |
| 2398 }, |
| 2399 'GL_CHROMIUM_enable_feature': { |
| 2400 'functions': [ |
| 2401 'EnableFeatureCHROMIUM', |
| 2402 ], |
| 2403 }, |
| 2404 'GL_CHROMIUM_post_sub_buffer': { |
| 2405 'functions': [ |
| 2406 'PostSubBufferCHROMIUM', |
| 2407 ], |
| 2408 }, |
| 2409 'GL_CHROMIUM_front_buffer_cached': { |
| 2410 }, |
| 2411 'GL_CHROMIUM_gpu_memory_manager': { |
| 2412 'constants': { |
| 2413 'GL_TEXTURE_POOL_CHROMIUM': '0x6000', |
| 2414 'GL_TEXTURE_POOL_MANAGED_CHROMIUM': '0x6001', |
| 2415 'GL_TEXTURE_POOL_UNMANAGED_CHROMIUM': '0x6002', |
| 2416 }, |
| 2417 }, |
| 2418 'GL_ARB_robustness': { |
| 2419 'constants': { |
| 2420 'GL_GUILTY_CONTEXT_RESET_ARB': '0x8253', |
| 2421 'GL_INNOCENT_CONTEXT_RESET_ARB': '0x8254', |
| 2422 'GL_UNKNOWN_CONTEXT_RESET_ARB': '0x8255', |
| 2423 }, |
| 2424 }, |
| 2425 'GL_ARB_texture_rectangle': { |
| 2426 'constants': { |
| 2427 'GL_TEXTURE_RECTANGLE_ARB': '0x84F5', |
| 2428 'GL_TEXTURE_BINDING_RECTANGLE_ARB': '0x84F6', |
| 2429 'GL_SAMPLER_2D_RECT_ARB': '0x8B63', |
| 2430 }, |
| 2431 }, |
| 2432 'GL_CHROMIUM_iosurface': { |
| 2433 'functions': [ |
| 2434 'TexImageIOSurface2DCHROMIUM', |
| 2435 ], |
| 2436 }, |
| 2437 'GL_CHROMIUM_copy_texture': { |
| 2438 'constants': { |
| 2439 'GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM': '0x9241', |
| 2440 'GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM': '0x9242', |
| 2441 'GL_UNPACK_COLORSPACE_CONVERSION_CHROMIUM': '0x9243', |
| 2442 }, |
| 2443 'functions': [ |
| 2444 'CopyTextureCHROMIUM', |
| 2445 ], |
| 2446 }, |
| 2447 'GL_CHROMIUM_command_buffer_query': { |
| 2448 'constants': { |
| 2449 # TODO(gman): Get official numbers for these constants. |
| 2450 'GL_COMMANDS_ISSUED_CHROMIUM': '0x84F2', |
| 2451 }, |
| 2452 }, |
| 2453 'GL_CHROMIUM_get_error_query': { |
| 2454 'constants': { |
| 2455 # TODO(gman): Get official numbers for these constants. |
| 2456 'GL_GET_ERROR_QUERY_CHROMIUM': '0x84F3', |
| 2457 }, |
| 2458 }, |
| 2459 'GL_CHROMIUM_command_buffer_latency_query': { |
| 2460 'constants': { |
| 2461 # TODO(gman): Get official numbers for these constants. |
| 2462 'GL_LATENCY_QUERY_CHROMIUM': '0x84F4', |
| 2463 }, |
| 2464 }, |
| 2465 'GL_CHROMIUM_texture_mailbox': { |
| 2466 'constants': { |
| 2467 'GL_MAILBOX_SIZE_CHROMIUM': '64', |
| 2468 }, |
| 2469 'functions': [ |
| 2470 'GenMailboxCHROMIUM', |
| 2471 'ProduceTextureCHROMIUM', |
| 2472 'ConsumeTextureCHROMIUM', |
| 2473 ], |
| 2474 }, |
| 2475 'GL_CHROMIUM_bind_uniform_location': { |
| 2476 'functions': [ |
| 2477 'BindUniformLocationCHROMIUM', |
| 2478 ], |
| 2479 }, |
| 2480 'GL_CHROMIUM_texture_from_image': { |
| 2481 'functions': [ |
| 2482 'BindTexImage2DCHROMIUM', |
| 2483 'ReleaseTexImage2DCHROMIUM', |
| 2484 ], |
| 2485 }, |
| 2486 'GL_CHROMIUM_pixel_transfer_buffer_object': { |
| 2487 'constants': { |
| 2488 # TODO(reveman): Get official numbers for these constants. |
| 2489 'GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM': '0x88EC', |
| 2490 'GL_PIXEL_UNPACK_TRANSFER_BUFFER_BINDING_CHROMIUM': '0x88EF', |
| 2491 }, |
| 2492 }, |
| 2493 'GL_CHROMIUM_async_pixel_transfers': { |
| 2494 'constants': { |
| 2495 # TODO(reveman): Get official numbers for these constants. |
| 2496 'GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM': '0x84F5', |
| 2497 }, |
| 2498 }, |
| 2499 'GL_CHROMIUM_lose_context': { |
| 2500 'functions': [ |
| 2501 'LoseContextCHROMIUM', |
| 2502 ], |
| 2503 }, |
| 2504 } |
| 2505 |
| 2506 |
2316 def Grouper(n, iterable, fillvalue=None): | 2507 def Grouper(n, iterable, fillvalue=None): |
2317 """Collect data into fixed-length chunks or blocks""" | 2508 """Collect data into fixed-length chunks or blocks""" |
2318 args = [iter(iterable)] * n | 2509 args = [iter(iterable)] * n |
2319 return itertools.izip_longest(fillvalue=fillvalue, *args) | 2510 return itertools.izip_longest(fillvalue=fillvalue, *args) |
2320 | 2511 |
2321 | 2512 |
2322 def SplitWords(input_string): | 2513 def SplitWords(input_string): |
2323 """Transforms a input_string into a list of lower-case components. | 2514 """Transforms a input_string into a list of lower-case components. |
2324 | 2515 |
2325 Args: | 2516 Args: |
(...skipping 4748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7074 file.Write(" .Times(1)\n") | 7265 file.Write(" .Times(1)\n") |
7075 file.Write(" .RetiresOnSaturation();\n") | 7266 file.Write(" .RetiresOnSaturation();\n") |
7076 file.Write("""} | 7267 file.Write("""} |
7077 """) | 7268 """) |
7078 file.Close() | 7269 file.Close() |
7079 | 7270 |
7080 def WriteGLES2Header(self, filename): | 7271 def WriteGLES2Header(self, filename): |
7081 """Writes the GLES2 header.""" | 7272 """Writes the GLES2 header.""" |
7082 file = CHeaderWriter( | 7273 file = CHeaderWriter( |
7083 filename, | 7274 filename, |
7084 "// Because we are using both the real system GL and our own.\n" | 7275 "// This file contains Chromium-specific GLES2 declarations.\n\n") |
7085 "// emulated GL we need to use different names to avoid conflicts.\n" | |
7086 "\n") | |
7087 | 7276 |
7088 file.Write("""#if defined(GLES2_USE_CPP_BINDINGS) | 7277 file.Write("#include <GLES2/gl2platform.h>\n") |
| 7278 |
| 7279 for name, value in _CHROMIUM_SPECIFIC_CONSTANTS.iteritems(): |
| 7280 file.Write("#define %s %s\n" % (name, value)) |
| 7281 |
| 7282 file.Write(""" |
| 7283 // Because we are using both the real system GL and our own |
| 7284 // emulated GL we need to use different names to avoid conflicts. |
| 7285 #if defined(GLES2_USE_CPP_BINDINGS) |
7089 #define GLES2_GET_FUN(name) gles2::GetGLContext()->name | 7286 #define GLES2_GET_FUN(name) gles2::GetGLContext()->name |
7090 #else | 7287 #else |
7091 #define GLES2_GET_FUN(name) GLES2 ## name | 7288 #define GLES2_GET_FUN(name) GLES2 ## name |
7092 #endif | 7289 #endif |
7093 | 7290 |
7094 """) | 7291 """) |
7095 | 7292 |
7096 for func in self.original_functions: | 7293 for func in self.original_functions: |
7097 func.WriteGLES2Header(file) | 7294 func.WriteGLES2Header(file) |
7098 | 7295 |
7099 file.Write("\n") | 7296 file.Write("\n") |
7100 file.Close() | 7297 file.Close() |
7101 | 7298 |
| 7299 def WriteGLES2ExtHeader(self, filename): |
| 7300 """Writes the GLES2 extensions header.""" |
| 7301 file = CHeaderWriter( |
| 7302 filename, |
| 7303 "// This file contains Chromium-specific " |
| 7304 "GLES2 extensions declarations.\n\n") |
| 7305 |
| 7306 file.Write("#include <GLES2/gl2chromium.h>\n") |
| 7307 file.Write("""#ifdef __cplusplus |
| 7308 extern "C" { |
| 7309 #endif |
| 7310 """) |
| 7311 |
| 7312 for ext_name, ext_dict in _CHROMIUM_SPECIFIC_EXTENSIONS.iteritems(): |
| 7313 file.Write(""" |
| 7314 /* %(name)s */ |
| 7315 #ifndef %(name)s |
| 7316 #define %(name)s 1 |
| 7317 """ % {'name' : ext_name}) |
| 7318 for name, value in ext_dict.get('constants', {}).iteritems(): |
| 7319 file.Write(""" |
| 7320 #ifndef %(name)s |
| 7321 #define %(name)s %(value)s |
| 7322 #endif |
| 7323 """ % {'name': name, 'value': value}) |
| 7324 |
| 7325 for name in ext_dict.get('functions', []): |
| 7326 found = False |
| 7327 for function in self.original_functions: |
| 7328 if function.name != name: |
| 7329 continue |
| 7330 file.Write("#ifdef GL_GLEXT_PROTOTYPES\n") |
| 7331 file.Write("GL_APICALL %s GL_APIENTRY gl%s(%s);\n" % ( |
| 7332 function.return_type, |
| 7333 function.name, |
| 7334 function.MakeTypedOriginalArgString(prefix=''))) |
| 7335 file.Write("#endif\n") |
| 7336 file.Write("typedef %s (GL_APIENTRYP %s) (%s);\n" % ( |
| 7337 function.return_type, |
| 7338 'PFNGL%sPROC' % function.name.upper(), |
| 7339 function.MakeTypedOriginalArgString(prefix=''))) |
| 7340 found = True |
| 7341 break |
| 7342 if not found: |
| 7343 self.Error("Function '%s' not found." % name) |
| 7344 |
| 7345 file.Write("#endif /* %s */\n" % ext_name) |
| 7346 |
| 7347 file.Write("""#ifdef __cplusplus |
| 7348 } |
| 7349 #endif |
| 7350 """) |
| 7351 |
| 7352 file.Write("\n") |
| 7353 file.Close() |
| 7354 |
7102 def WriteGLES2CLibImplementation(self, filename): | 7355 def WriteGLES2CLibImplementation(self, filename): |
7103 """Writes the GLES2 c lib implementation.""" | 7356 """Writes the GLES2 c lib implementation.""" |
7104 file = CHeaderWriter( | 7357 file = CHeaderWriter( |
7105 filename, | 7358 filename, |
7106 "// These functions emulate GLES2 over command buffers.\n") | 7359 "// These functions emulate GLES2 over command buffers.\n") |
7107 | 7360 |
7108 for func in self.original_functions: | 7361 for func in self.original_functions: |
7109 func.WriteGLES2CLibImplementation(file) | 7362 func.WriteGLES2CLibImplementation(file) |
7110 | 7363 |
7111 file.Write(""" | 7364 file.Write(""" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7233 if _ENUM_LISTS[enum]['type'] == 'GLenum': | 7486 if _ENUM_LISTS[enum]['type'] == 'GLenum': |
7234 file.Write("static std::string GetString%s(uint32 value);\n" % enum) | 7487 file.Write("static std::string GetString%s(uint32 value);\n" % enum) |
7235 file.Write("\n") | 7488 file.Write("\n") |
7236 file.Close() | 7489 file.Close() |
7237 | 7490 |
7238 def WriteCommonUtilsImpl(self, filename): | 7491 def WriteCommonUtilsImpl(self, filename): |
7239 """Writes the gles2 common utility header.""" | 7492 """Writes the gles2 common utility header.""" |
7240 enum_re = re.compile(r'\#define\s+(GL_[a-zA-Z0-9_]+)\s+([0-9A-Fa-fx]+)') | 7493 enum_re = re.compile(r'\#define\s+(GL_[a-zA-Z0-9_]+)\s+([0-9A-Fa-fx]+)') |
7241 dict = {} | 7494 dict = {} |
7242 for fname in ['../../third_party/khronos/GLES2/gl2.h', | 7495 for fname in ['../../third_party/khronos/GLES2/gl2.h', |
7243 '../../third_party/khronos/GLES2/gl2ext.h']: | 7496 '../../third_party/khronos/GLES2/gl2ext.h', |
| 7497 '../../gpu/GLES2/gl2chromium.h', |
| 7498 '../../gpu/GLES2/gl2extchromium.h']: |
7244 lines = open(fname).readlines() | 7499 lines = open(fname).readlines() |
7245 for line in lines: | 7500 for line in lines: |
7246 m = enum_re.match(line) | 7501 m = enum_re.match(line) |
7247 if m: | 7502 if m: |
7248 name = m.group(1) | 7503 name = m.group(1) |
7249 value = m.group(2) | 7504 value = m.group(2) |
7250 if len(value) <= 10 and not value in dict: | 7505 if len(value) <= 10 and not value in dict: |
7251 dict[value] = name | 7506 dict[value] = name |
7252 | 7507 |
7253 file = CHeaderWriter(filename) | 7508 file = CHeaderWriter(filename) |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7571 gen.WriteClientContextStateHeader("client/client_context_state_autogen.h") | 7826 gen.WriteClientContextStateHeader("client/client_context_state_autogen.h") |
7572 gen.WriteClientContextStateImpl( | 7827 gen.WriteClientContextStateImpl( |
7573 "client/client_context_state_impl_autogen.h") | 7828 "client/client_context_state_impl_autogen.h") |
7574 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") | 7829 gen.WriteServiceUnitTests("service/gles2_cmd_decoder_unittest_%d_autogen.h") |
7575 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") | 7830 gen.WriteServiceUtilsHeader("service/gles2_cmd_validation_autogen.h") |
7576 gen.WriteServiceUtilsImplementation( | 7831 gen.WriteServiceUtilsImplementation( |
7577 "service/gles2_cmd_validation_implementation_autogen.h") | 7832 "service/gles2_cmd_validation_implementation_autogen.h") |
7578 gen.WriteCommonUtilsHeader("common/gles2_cmd_utils_autogen.h") | 7833 gen.WriteCommonUtilsHeader("common/gles2_cmd_utils_autogen.h") |
7579 gen.WriteCommonUtilsImpl("common/gles2_cmd_utils_implementation_autogen.h") | 7834 gen.WriteCommonUtilsImpl("common/gles2_cmd_utils_implementation_autogen.h") |
7580 gen.WriteGLES2Header("../GLES2/gl2chromium.h") | 7835 gen.WriteGLES2Header("../GLES2/gl2chromium.h") |
| 7836 gen.WriteGLES2ExtHeader("../GLES2/gl2extchromium.h") |
7581 | 7837 |
7582 if gen.errors > 0: | 7838 if gen.errors > 0: |
7583 print "%d errors" % gen.errors | 7839 print "%d errors" % gen.errors |
7584 return 1 | 7840 return 1 |
7585 return 0 | 7841 return 0 |
7586 | 7842 |
7587 | 7843 |
7588 if __name__ == '__main__': | 7844 if __name__ == '__main__': |
7589 sys.exit(main(sys.argv[1:])) | 7845 sys.exit(main(sys.argv[1:])) |
OLD | NEW |