1#!/usr/bin/python2 2# 3# Copyright 2017 The ANGLE Project Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6# 7# generate_entry_points.py: 8# Generates the OpenGL bindings and entry point layers for ANGLE. 9# NOTE: don't run this script directly. Run scripts/run_code_generation.py. 10 11import sys, os, pprint, json 12from datetime import date 13import registry_xml 14 15# List of GLES1 extensions for which we don't need to add Context.h decls. 16gles1_no_context_decl_extensions = [ 17 "GL_OES_framebuffer_object", 18] 19 20# This is a list of exceptions for entry points which don't want to have 21# the EVENT macro. This is required for some debug marker entry points. 22no_event_marker_exceptions_list = sorted([ 23 "glPushGroupMarkerEXT", 24 "glPopGroupMarkerEXT", 25 "glInsertEventMarkerEXT", 26]) 27 28# Strip these suffixes from Context entry point names. NV is excluded (for now). 29strip_suffixes = ["ANGLE", "EXT", "KHR", "OES", "CHROMIUM", "OVR"] 30 31template_entry_point_header = """// GENERATED FILE - DO NOT EDIT. 32// Generated by {script_name} using data from {data_source_name}. 33// 34// Copyright {year} The ANGLE Project Authors. All rights reserved. 35// Use of this source code is governed by a BSD-style license that can be 36// found in the LICENSE file. 37// 38// entry_points_{annotation_lower}_autogen.h: 39// Defines the {comment} entry points. 40 41#ifndef {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_ 42#define {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_ 43 44{includes} 45 46namespace gl 47{{ 48{entry_points} 49}} // namespace gl 50 51#endif // {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_ 52""" 53 54template_entry_point_source = """// GENERATED FILE - DO NOT EDIT. 55// Generated by {script_name} using data from {data_source_name}. 56// 57// Copyright {year} The ANGLE Project Authors. All rights reserved. 58// Use of this source code is governed by a BSD-style license that can be 59// found in the LICENSE file. 60// 61// entry_points_{annotation_lower}_autogen.cpp: 62// Defines the {comment} entry points. 63 64{includes} 65 66namespace gl 67{{ 68{entry_points}}} // namespace gl 69""" 70 71template_entry_points_enum_header = """// GENERATED FILE - DO NOT EDIT. 72// Generated by {script_name} using data from {data_source_name}. 73// 74// Copyright {year} The ANGLE Project Authors. All rights reserved. 75// Use of this source code is governed by a BSD-style license that can be 76// found in the LICENSE file. 77// 78// entry_points_enum_autogen.h: 79// Defines the {lib} entry points enumeration. 80 81#ifndef LIBANGLE_ENTRYPOINTSENUM_AUTOGEN_H_ 82#define LIBANGLE_ENTRYPOINTSENUM_AUTOGEN_H_ 83 84namespace gl 85{{ 86enum class EntryPoint 87{{ 88{entry_points_list} 89}}; 90 91const char *GetEntryPointName(EntryPoint ep); 92}} // namespace gl 93#endif // LIBANGLE_ENTRY_POINTS_ENUM_AUTOGEN_H_ 94""" 95 96template_entry_points_name_case = """ case EntryPoint::{enum}: 97 return "gl{enum}";""" 98 99template_entry_points_enum_source = """// GENERATED FILE - DO NOT EDIT. 100// Generated by {script_name} using data from {data_source_name}. 101// 102// Copyright {year} The ANGLE Project Authors. All rights reserved. 103// Use of this source code is governed by a BSD-style license that can be 104// found in the LICENSE file. 105// 106// entry_points_enum_autogen.cpp: 107// Helper methods for the {lib} entry points enumeration. 108 109#include "libANGLE/entry_points_enum_autogen.h" 110 111#include "common/debug.h" 112 113namespace gl 114{{ 115const char *GetEntryPointName(EntryPoint ep) 116{{ 117 switch (ep) 118 {{ 119{entry_points_name_cases} 120 default: 121 UNREACHABLE(); 122 return "error"; 123 }} 124}} 125}} // namespace gl 126""" 127 128template_lib_entry_point_source = """// GENERATED FILE - DO NOT EDIT. 129// Generated by {script_name} using data from {data_source_name}. 130// 131// Copyright {year} The ANGLE Project Authors. All rights reserved. 132// Use of this source code is governed by a BSD-style license that can be 133// found in the LICENSE file. 134// 135// {lib_name}.cpp: Implements the exported {lib_description} functions. 136 137{includes} 138extern "C" {{ 139{entry_points} 140}} // extern "C" 141""" 142 143template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params});""" 144 145template_entry_point_no_return = """void GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params}) 146{{ 147 Context *context = {context_getter}; 148 {event_comment}EVENT("gl{name}", "context = %d{comma_if_needed}{format_params}", CID(context){comma_if_needed}{pass_params}); 149 150 if (context) 151 {{{assert_explicit_context}{packed_gl_enum_conversions} 152 std::unique_lock<angle::GlobalMutex> shareContextLock = GetShareGroupLock(context); 153 bool isCallValid = (context->skipValidation() || Validate{name}({validate_params})); 154 if (isCallValid) 155 {{ 156 context->{name_lower_no_suffix}({internal_params}); 157 }} 158 ANGLE_CAPTURE({name}, isCallValid, {validate_params}); 159 }} 160}} 161""" 162 163template_entry_point_with_return = """{return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params}) 164{{ 165 Context *context = {context_getter}; 166 {event_comment}EVENT("gl{name}", "context = %d{comma_if_needed}{format_params}", CID(context){comma_if_needed}{pass_params}); 167 168 {return_type} returnValue; 169 if (context) 170 {{{assert_explicit_context}{packed_gl_enum_conversions} 171 std::unique_lock<angle::GlobalMutex> shareContextLock = GetShareGroupLock(context); 172 bool isCallValid = (context->skipValidation() || Validate{name}({validate_params})); 173 if (isCallValid) 174 {{ 175 returnValue = context->{name_lower_no_suffix}({internal_params}); 176 }} 177 else 178 {{ 179 returnValue = GetDefaultReturnValue<EntryPoint::{name}, {return_type}>(); 180 }} 181 ANGLE_CAPTURE({name}, isCallValid, {validate_params}, returnValue); 182 }} 183 else 184 {{ 185 returnValue = GetDefaultReturnValue<EntryPoint::{name}, {return_type}>(); 186 }} 187 return returnValue; 188}} 189""" 190 191context_header = """// GENERATED FILE - DO NOT EDIT. 192// Generated by {script_name} using data from {data_source_name}. 193// 194// Copyright {year} The ANGLE Project Authors. All rights reserved. 195// Use of this source code is governed by a BSD-style license that can be 196// found in the LICENSE file. 197// 198// Context_{annotation_lower}_autogen.h: Creates a macro for interfaces in Context. 199 200#ifndef ANGLE_CONTEXT_{annotation_upper}_AUTOGEN_H_ 201#define ANGLE_CONTEXT_{annotation_upper}_AUTOGEN_H_ 202 203#define ANGLE_{annotation_upper}_CONTEXT_API \\ 204{interface} 205 206#endif // ANGLE_CONTEXT_API_{version}_AUTOGEN_H_ 207""" 208 209context_decl_format = """ {return_type} {name_lower_no_suffix}({internal_params}){maybe_const}; \\""" 210 211libgles_entry_point_def = """{return_type}GL_APIENTRY gl{name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params}) 212{{ 213 return gl::{name}{explicit_context_suffix}({explicit_context_internal_param}{explicit_context_comma}{internal_params}); 214}} 215""" 216 217template_glext_explicit_context_inc = """// GENERATED FILE - DO NOT EDIT. 218// Generated by {script_name} using data from {data_source_name}. 219// 220// Copyright {year} The ANGLE Project Authors. All rights reserved. 221// Use of this source code is governed by a BSD-style license that can be 222// found in the LICENSE file. 223// 224// gl{version}ext_explicit_context_autogen.inc: 225// Function declarations for the EGL_ANGLE_explicit_context extension 226 227{function_pointers} 228#ifdef GL_GLEXT_PROTOTYPES 229{function_prototypes} 230#endif 231""" 232 233template_glext_function_pointer = """typedef {return_type}(GL_APIENTRYP PFN{name_upper}{explicit_context_suffix_upper}PROC)({explicit_context_param}{explicit_context_comma}{params});""" 234template_glext_function_prototype = """{apicall} {return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params});""" 235 236template_validation_header = """// GENERATED FILE - DO NOT EDIT. 237// Generated by {script_name} using data from {data_source_name}. 238// 239// Copyright {year} The ANGLE Project Authors. All rights reserved. 240// Use of this source code is governed by a BSD-style license that can be 241// found in the LICENSE file. 242// 243// validation{annotation}_autogen.h: 244// Validation functions for the OpenGL {comment} entry points. 245 246#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 247#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 248 249#include "common/PackedEnums.h" 250 251namespace gl 252{{ 253class Context; 254 255{prototypes} 256}} // namespace gl 257 258#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 259""" 260 261template_capture_header = """// GENERATED FILE - DO NOT EDIT. 262// Generated by {script_name} using data from {data_source_name}. 263// 264// Copyright {year} The ANGLE Project Authors. All rights reserved. 265// Use of this source code is governed by a BSD-style license that can be 266// found in the LICENSE file. 267// 268// capture_gles_{annotation}_autogen.h: 269// Capture functions for the OpenGL ES {comment} entry points. 270 271#ifndef LIBANGLE_CAPTURE_GLES_{annotation}_AUTOGEN_H_ 272#define LIBANGLE_CAPTURE_GLES_{annotation}_AUTOGEN_H_ 273 274#include "common/PackedEnums.h" 275#include "libANGLE/FrameCapture.h" 276 277namespace gl 278{{ 279{prototypes} 280}} // namespace gl 281 282#endif // LIBANGLE_CAPTURE_GLES_{annotation}_AUTOGEN_H_ 283""" 284 285template_capture_source = """// GENERATED FILE - DO NOT EDIT. 286// Generated by {script_name} using data from {data_source_name}. 287// 288// Copyright {year} The ANGLE Project Authors. All rights reserved. 289// Use of this source code is governed by a BSD-style license that can be 290// found in the LICENSE file. 291// 292// capture_gles_{annotation_with_dash}_autogen.cpp: 293// Capture functions for the OpenGL ES {comment} entry points. 294 295#include "libANGLE/capture_gles_{annotation_with_dash}_autogen.h" 296 297#include "libANGLE/Context.h" 298#include "libANGLE/FrameCapture.h" 299#include "libANGLE/gl_enum_utils.h" 300#include "libANGLE/validation{annotation_no_dash}.h" 301 302using namespace angle; 303 304namespace gl 305{{ 306{capture_methods} 307}} // namespace gl 308""" 309 310template_capture_method_with_return_value = """ 311CallCapture Capture{short_name}({params_with_type}, {return_value_type_original} returnValue) 312{{ 313 ParamBuffer paramBuffer; 314 315 {parameter_captures} 316 317 ParamCapture returnValueCapture("returnValue", ParamType::T{return_value_type_custom}); 318 InitParamValue(ParamType::T{return_value_type_custom}, returnValue, &returnValueCapture.value); 319 paramBuffer.addReturnValue(std::move(returnValueCapture)); 320 321 return CallCapture(gl::EntryPoint::{short_name}, std::move(paramBuffer)); 322}} 323""" 324 325template_capture_method_no_return_value = """ 326CallCapture Capture{short_name}({params_with_type}) 327{{ 328 ParamBuffer paramBuffer; 329 330 {parameter_captures} 331 332 return CallCapture(gl::EntryPoint::{short_name}, std::move(paramBuffer)); 333}} 334""" 335 336template_parameter_capture_value = """paramBuffer.addValueParam("{name}", ParamType::T{type}, {name});""" 337 338template_parameter_capture_gl_enum = """paramBuffer.addEnumParam("{name}", GLenumGroup::{group}, ParamType::T{type}, {name});""" 339 340template_parameter_capture_pointer = """ 341 ParamCapture {name}Param("{name}", ParamType::T{type}); 342 InitParamValue(ParamType::T{type}, {name}, &{name}Param.value); 343 {capture_name}({params}, &{name}Param); 344 paramBuffer.addParam(std::move({name}Param)); 345""" 346 347template_parameter_capture_pointer_func = """void {name}({params});""" 348 349template_capture_replay_source = """// GENERATED FILE - DO NOT EDIT. 350// Generated by {script_name} using data from {data_source_name}. 351// 352// Copyright {year} The ANGLE Project Authors. All rights reserved. 353// Use of this source code is governed by a BSD-style license that can be 354// found in the LICENSE file. 355// 356// frame_capture_replay_autogen.cpp: 357// Util function to dispatch captured GL calls through Context and replay them. 358 359#include "angle_gl.h" 360 361#include "common/debug.h" 362#include "common/debug.h" 363#include "libANGLE/Context.h" 364#include "libANGLE/Context.inl.h" 365#include "libANGLE/FrameCapture.h" 366 367using namespace gl; 368 369namespace angle 370{{ 371 372void FrameCapture::ReplayCall(gl::Context *context, 373 ReplayContext *replayContext, 374 const CallCapture &call) 375{{ 376 const ParamBuffer ¶ms = call.params; 377 switch (call.entryPoint) 378 {{ 379 {call_replay_cases} 380 default: 381 UNREACHABLE(); 382 }} 383}} 384 385}} // namespace angle 386 387""" 388 389template_capture_replay_call_case = """case gl::EntryPoint::{entry_point}: 390 context->{context_call}({param_value_access});break;""" 391 392static_cast_to_dict = { 393 "GLintptr": "unsigned long long", 394 "GLsizeiptr": "unsigned long long", 395 "GLuint64": "unsigned long long", 396} 397 398reinterpret_cast_to_dict = { 399 "GLsync": "uintptr_t", 400 "GLDEBUGPROC": "uintptr_t", 401 "GLDEBUGPROCKHR": "uintptr_t", 402 "GLeglImageOES": "uintptr_t", 403} 404 405format_dict = { 406 "GLbitfield": "%s", 407 "GLboolean": "%s", 408 "GLbyte": "%d", 409 "GLclampx": "0x%X", 410 "GLDEBUGPROC": "0x%016\" PRIxPTR \"", 411 "GLDEBUGPROCKHR": "0x%016\" PRIxPTR \"", 412 "GLdouble": "%f", 413 "GLeglImageOES": "0x%016\" PRIxPTR \"", 414 "GLenum": "%s", 415 "GLfixed": "0x%X", 416 "GLfloat": "%f", 417 "GLint": "%d", 418 "GLintptr": "%llu", 419 "GLshort": "%d", 420 "GLsizei": "%d", 421 "GLsizeiptr": "%llu", 422 "GLsync": "0x%016\" PRIxPTR \"", 423 "GLubyte": "%d", 424 "GLuint": "%u", 425 "GLuint64": "%llu", 426 "GLushort": "%u", 427 "int": "%d", 428 # WGL specific types 429 "BOOL": "%u", 430 "DWORD": "0x%016\" PRIxPTR \"", 431 "FLOAT": "%f", 432 "HDC": "0x%016\" PRIxPTR \"", 433 "HENHMETAFILE": "0x%016\" PRIxPTR \"", 434 "HGLRC": "0x%016\" PRIxPTR \"", 435 "LPCSTR": "0x%016\" PRIxPTR \"", 436 "LPGLYPHMETRICSFLOAT": "0x%016\" PRIxPTR \"", 437 "UINT": "%u", 438} 439 440template_header_includes = """#include <GLES{major}/gl{major}{minor}.h> 441#include <export.h>""" 442 443template_sources_includes = """#include "libGLESv2/entry_points_{header_version}_autogen.h" 444 445#include "libANGLE/Context.h" 446#include "libANGLE/Context.inl.h" 447#include "libANGLE/capture_{header_version}_autogen.h" 448#include "libANGLE/gl_enum_utils.h" 449#include "libANGLE/validation{validation_header_version}.h" 450#include "libANGLE/entry_points_utils.h" 451#include "libGLESv2/global_state.h" 452""" 453 454template_header_includes_gl32 = """#include <export.h> 455#include "angle_gl.h" 456 457""" 458 459template_sources_includes_gl32 = """#include "libGL/entry_points_{}_autogen.h" 460 461#include "libANGLE/Context.h" 462#include "libANGLE/Context.inl.h" 463#include "libANGLE/gl_enum_utils.h" 464#include "libANGLE/validationEGL.h" 465#include "libANGLE/validationES.h" 466#include "libANGLE/validationES1.h" 467#include "libANGLE/validationES2.h" 468#include "libANGLE/validationES3.h" 469#include "libANGLE/validationES31.h" 470#include "libANGLE/validationES32.h" 471#include "libANGLE/validationESEXT.h" 472#include "libANGLE/validationGL{}{}_autogen.h" 473#include "libANGLE/entry_points_utils.h" 474#include "libGLESv2/global_state.h" 475""" 476 477template_event_comment = """// Don't run the EVENT() macro on the EXT_debug_marker entry points. 478 // It can interfere with the debug events being set by the caller. 479 // """ 480 481template_capture_proto = "angle::CallCapture Capture%s(%s);" 482 483template_validation_proto = "bool Validate%s(%s);" 484 485template_windows_def_file = """; GENERATED FILE - DO NOT EDIT. 486; Generated by {script_name} using data from {data_source_name}. 487; 488; Copyright {year} The ANGLE Project Authors. All rights reserved. 489; Use of this source code is governed by a BSD-style license that can be 490; found in the LICENSE file. 491LIBRARY {lib} 492EXPORTS 493{exports} 494""" 495 496template_frame_capture_utils_header = """// GENERATED FILE - DO NOT EDIT. 497// Generated by {script_name} using data from {data_source_name}. 498// 499// Copyright {year} The ANGLE Project Authors. All rights reserved. 500// Use of this source code is governed by a BSD-style license that can be 501// found in the LICENSE file. 502// 503// frame_capture_utils_autogen.h: 504// ANGLE Frame capture types and helper functions. 505 506#ifndef LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_ 507#define LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_ 508 509#include "common/PackedEnums.h" 510 511namespace angle 512{{ 513enum class ParamType 514{{ 515 {param_types} 516}}; 517 518constexpr uint32_t kParamTypeCount = {param_type_count}; 519 520union ParamValue 521{{ 522 {param_union_values} 523}}; 524 525template <ParamType PType, typename T> 526T GetParamVal(const ParamValue &value); 527 528{get_param_val_specializations} 529 530template <ParamType PType, typename T> 531T GetParamVal(const ParamValue &value) 532{{ 533 UNREACHABLE(); 534 return T(); 535}} 536 537template <typename T> 538T AccessParamValue(ParamType paramType, const ParamValue &value) 539{{ 540 switch (paramType) 541 {{ 542{access_param_value_cases} 543 }} 544}} 545 546template <ParamType PType, typename T> 547void SetParamVal(T valueIn, ParamValue *valueOut); 548 549{set_param_val_specializations} 550 551template <ParamType PType, typename T> 552void SetParamVal(T valueIn, ParamValue *valueOut) 553{{ 554 UNREACHABLE(); 555}} 556 557template <typename T> 558void InitParamValue(ParamType paramType, T valueIn, ParamValue *valueOut) 559{{ 560 switch (paramType) 561 {{ 562{init_param_value_cases} 563 }} 564}} 565 566struct CallCapture; 567struct ParamCapture; 568 569void WriteParamCaptureReplay(std::ostream &os, const CallCapture &call, const ParamCapture ¶m); 570const char *ParamTypeToString(ParamType paramType); 571 572enum class ResourceIDType 573{{ 574 {resource_id_types} 575}}; 576 577ResourceIDType GetResourceIDTypeFromParamType(ParamType paramType); 578const char *GetResourceIDTypeName(ResourceIDType resourceIDType); 579}} // namespace angle 580 581#endif // LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_ 582""" 583 584template_frame_capture_utils_source = """// GENERATED FILE - DO NOT EDIT. 585// Generated by {script_name} using data from {data_source_name}. 586// 587// Copyright {year} The ANGLE Project Authors. All rights reserved. 588// Use of this source code is governed by a BSD-style license that can be 589// found in the LICENSE file. 590// 591// frame_capture_utils_autogen.cpp: 592// ANGLE Frame capture types and helper functions. 593 594#include "libANGLE/frame_capture_utils_autogen.h" 595 596#include "libANGLE/FrameCapture.h" 597 598namespace angle 599{{ 600void WriteParamCaptureReplay(std::ostream &os, const CallCapture &call, const ParamCapture ¶m) 601{{ 602 switch (param.type) 603 {{ 604{write_param_type_to_stream_cases} 605 default: 606 os << "unknown"; 607 break; 608 }} 609}} 610 611const char *ParamTypeToString(ParamType paramType) 612{{ 613 switch (paramType) 614 {{ 615{param_type_to_string_cases} 616 default: 617 UNREACHABLE(); 618 return "unknown"; 619 }} 620}} 621 622ResourceIDType GetResourceIDTypeFromParamType(ParamType paramType) 623{{ 624 switch (paramType) 625 {{ 626{param_type_resource_id_cases} 627 default: 628 return ResourceIDType::InvalidEnum; 629 }} 630}} 631 632const char *GetResourceIDTypeName(ResourceIDType resourceIDType) 633{{ 634 switch (resourceIDType) 635 {{ 636{resource_id_type_name_cases} 637 default: 638 UNREACHABLE(); 639 return "GetResourceIDTypeName error"; 640 }} 641}} 642}} // namespace angle 643""" 644 645template_get_param_val_specialization = """template <> 646inline {type} GetParamVal<ParamType::T{enum}, {type}>(const ParamValue &value) 647{{ 648 return value.{union_name}; 649}}""" 650 651template_access_param_value_case = """ case ParamType::T{enum}: 652 return GetParamVal<ParamType::T{enum}, T>(value);""" 653 654template_set_param_val_specialization = """template <> 655inline void SetParamVal<ParamType::T{enum}>({type} valueIn, ParamValue *valueOut) 656{{ 657 valueOut->{union_name} = valueIn; 658}}""" 659 660template_init_param_value_case = """ case ParamType::T{enum}: 661 SetParamVal<ParamType::T{enum}>(valueIn, valueOut); 662 break;""" 663 664template_write_param_type_to_stream_case = """ case ParamType::T{enum}: 665 WriteParamValueReplay<ParamType::T{enum}>(os, call, param.value.{union_name}); 666 break;""" 667 668template_param_type_to_string_case = """ case ParamType::T{enum}: 669 return "{type}";""" 670 671template_param_type_to_resource_id_type_case = """ case ParamType::T{enum}: 672 return ResourceIDType::{resource_id_type};""" 673 674template_resource_id_type_name_case = """ case ResourceIDType::{resource_id_type}: 675 return "{resource_id_type}";""" 676 677 678def script_relative(path): 679 return os.path.join(os.path.dirname(sys.argv[0]), path) 680 681 682def format_entry_point_decl(cmd_name, proto, params, is_explicit_context): 683 comma_if_needed = ", " if len(params) > 0 else "" 684 return template_entry_point_decl.format( 685 name=cmd_name[2:], 686 return_type=proto[:-len(cmd_name)], 687 params=", ".join(params), 688 comma_if_needed=comma_if_needed, 689 explicit_context_suffix="ContextANGLE" if is_explicit_context else "", 690 explicit_context_param="GLeglContext ctx" if is_explicit_context else "", 691 explicit_context_comma=", " if is_explicit_context and len(params) > 0 else "") 692 693 694def type_name_sep_index(param): 695 space = param.rfind(" ") 696 pointer = param.rfind("*") 697 return max(space, pointer) 698 699 700def just_the_type(param): 701 if "*" in param: 702 return param[:type_name_sep_index(param) + 1] 703 return param[:type_name_sep_index(param)] 704 705 706def just_the_name(param): 707 return param[type_name_sep_index(param) + 1:] 708 709 710def make_param(param_type, param_name): 711 return param_type + " " + param_name 712 713 714def just_the_type_packed(param, entry): 715 name = just_the_name(param) 716 if entry.has_key(name): 717 return entry[name] 718 else: 719 return just_the_type(param) 720 721 722def just_the_name_packed(param, reserved_set): 723 name = just_the_name(param) 724 if name in reserved_set: 725 return name + 'Packed' 726 else: 727 return name 728 729 730def param_print_argument(command_node, param): 731 name_only = just_the_name(param) 732 type_only = just_the_type(param) 733 734 if "*" in param: 735 return "(uintptr_t)" + name_only 736 737 if type_only in reinterpret_cast_to_dict: 738 return "(" + reinterpret_cast_to_dict[type_only] + ")" + name_only 739 740 if type_only in static_cast_to_dict: 741 return "static_cast<" + static_cast_to_dict[type_only] + ">(" + name_only + ")" 742 743 if type_only == "GLboolean": 744 return "GLbooleanToString(%s)" % (name_only,) 745 746 if type_only == "GLbitfield": 747 group_name = find_gl_enum_group_in_command(command_node, name_only) 748 return "GLbitfieldToString(GLenumGroup::%s, %s).c_str()" % (group_name, name_only) 749 750 if type_only == "GLenum": 751 group_name = find_gl_enum_group_in_command(command_node, name_only) 752 return "GLenumToString(GLenumGroup::%s, %s)" % (group_name, name_only) 753 754 return name_only 755 756 757def param_format_string(param): 758 if "*" in param: 759 return param + " = 0x%016\" PRIxPTR \"" 760 else: 761 type_only = just_the_type(param) 762 if type_only not in format_dict: 763 raise Exception(type_only + " is not a known type in 'format_dict'") 764 765 return param + " = " + format_dict[type_only] 766 767 768def default_return_value(cmd_name, return_type): 769 if return_type == "void": 770 return "" 771 return "GetDefaultReturnValue<EntryPoint::" + cmd_name[2:] + ", " + return_type + ">()" 772 773 774def get_context_getter_function(cmd_name, is_explicit_context): 775 if is_explicit_context: 776 return "static_cast<gl::Context *>(ctx)" 777 778 lost_context_acceptable_cmds = [ 779 "glGetError", 780 "glGetSync", 781 "glGetQueryObjecti", 782 "glGetProgramiv", 783 "glGetGraphicsResetStatus", 784 "glGetShaderiv", 785 ] 786 for context_lost_entry_pont in lost_context_acceptable_cmds: 787 if cmd_name.startswith(context_lost_entry_pont): 788 return "GetGlobalContext()" 789 return "GetValidGlobalContext()" 790 791 792def strip_suffix(name): 793 for suffix in strip_suffixes: 794 if name.endswith(suffix): 795 name = name[0:-len(suffix)] 796 return name 797 798 799def find_gl_enum_group_in_command(command_node, param_name): 800 group_name = None 801 for param_node in command_node.findall('./param'): 802 if param_node.find('./name').text == param_name: 803 group_name = param_node.attrib.get('group', None) 804 break 805 806 if group_name is None or group_name in registry_xml.unsupported_enum_group_names: 807 group_name = registry_xml.default_enum_group_name 808 809 return group_name 810 811 812def get_packed_enums(cmd_packed_gl_enums, cmd_name): 813 # Always strip the suffix when querying packed enums. 814 return cmd_packed_gl_enums.get(strip_suffix(cmd_name), {}) 815 816 817def format_entry_point_def(command_node, cmd_name, proto, params, is_explicit_context, 818 cmd_packed_gl_enums): 819 packed_gl_enums = get_packed_enums(cmd_packed_gl_enums, cmd_name) 820 internal_params = [just_the_name_packed(param, packed_gl_enums) for param in params] 821 packed_gl_enum_conversions = [] 822 for param in params: 823 name = just_the_name(param) 824 if name in packed_gl_enums: 825 internal_name = name + "Packed" 826 internal_type = packed_gl_enums[name] 827 packed_gl_enum_conversions += [ 828 "\n " + internal_type + " " + internal_name + " = FromGL<" + internal_type + 829 ">(" + name + ");" 830 ] 831 832 pass_params = [param_print_argument(command_node, param) for param in params] 833 format_params = [param_format_string(param) for param in params] 834 return_type = proto[:-len(cmd_name)] 835 default_return = default_return_value(cmd_name, return_type.strip()) 836 event_comment = template_event_comment if cmd_name in no_event_marker_exceptions_list else "" 837 name_lower_no_suffix = strip_suffix(cmd_name[2:3].lower() + cmd_name[3:]) 838 839 format_params = { 840 "name": 841 cmd_name[2:], 842 "name_lower_no_suffix": 843 name_lower_no_suffix, 844 "return_type": 845 return_type, 846 "params": 847 ", ".join(params), 848 "internal_params": 849 ", ".join(internal_params), 850 "packed_gl_enum_conversions": 851 "".join(packed_gl_enum_conversions), 852 "pass_params": 853 ", ".join(pass_params), 854 "comma_if_needed": 855 ", " if len(params) > 0 else "", 856 "validate_params": 857 ", ".join(["context"] + internal_params), 858 "format_params": 859 ", ".join(format_params), 860 "context_getter": 861 get_context_getter_function(cmd_name, is_explicit_context), 862 "event_comment": 863 event_comment, 864 "explicit_context_suffix": 865 "ContextANGLE" if is_explicit_context else "", 866 "explicit_context_param": 867 "GLeglContext ctx" if is_explicit_context else "", 868 "explicit_context_comma": 869 ", " if is_explicit_context and len(params) > 0 else "", 870 "assert_explicit_context": 871 "\nASSERT(context == GetValidGlobalContext());" if is_explicit_context else "" 872 } 873 874 if return_type.strip() == "void": 875 return template_entry_point_no_return.format(**format_params) 876 else: 877 return template_entry_point_with_return.format(**format_params) 878 879 880def get_capture_param_type_name(param_type): 881 882 pointer_count = param_type.count("*") 883 is_const = "const" in param_type.split() 884 885 param_type = param_type.replace("*", "").strip() 886 param_type = " ".join([param for param in param_type.split() if param != "const"]) 887 888 if is_const: 889 param_type += "Const" 890 for x in range(pointer_count): 891 param_type += "Pointer" 892 893 return param_type 894 895 896def format_capture_method(command, cmd_name, proto, params, all_param_types, capture_pointer_funcs, 897 cmd_packed_gl_enums): 898 899 packed_gl_enums = get_packed_enums(cmd_packed_gl_enums, cmd_name) 900 901 params_with_type = get_internal_params( 902 cmd_name, ["const State &glState", "bool isCallValid"] + params, cmd_packed_gl_enums) 903 params_just_name = ", ".join( 904 ["glState", "isCallValid"] + 905 [just_the_name_packed(param, packed_gl_enums) for param in params]) 906 907 parameter_captures = [] 908 for param in params: 909 910 param_name = just_the_name_packed(param, packed_gl_enums) 911 param_type = just_the_type_packed(param, packed_gl_enums).strip() 912 913 pointer_count = param_type.count("*") 914 param_type = get_capture_param_type_name(param_type) 915 916 if pointer_count > 0: 917 params = params_just_name 918 capture_name = "Capture%s_%s" % (cmd_name[2:], param_name) 919 capture = template_parameter_capture_pointer.format( 920 name=param_name, type=param_type, capture_name=capture_name, params=params) 921 922 capture_pointer_func = template_parameter_capture_pointer_func.format( 923 name=capture_name, params=params_with_type + ", angle::ParamCapture *paramCapture") 924 capture_pointer_funcs += [capture_pointer_func] 925 elif param_type in ('GLenum', 'GLbitfield'): 926 gl_enum_group = find_gl_enum_group_in_command(command, param_name) 927 capture = template_parameter_capture_gl_enum.format( 928 name=param_name, type=param_type, group=gl_enum_group) 929 else: 930 capture = template_parameter_capture_value.format(name=param_name, type=param_type) 931 932 all_param_types.add(param_type) 933 934 parameter_captures += [capture] 935 936 return_type = proto[:-len(cmd_name)].strip() 937 938 format_args = { 939 "full_name": cmd_name, 940 "short_name": cmd_name[2:], 941 "params_with_type": params_with_type, 942 "params_just_name": params_just_name, 943 "parameter_captures": "\n ".join(parameter_captures), 944 "return_value_type_original": return_type, 945 "return_value_type_custom": get_capture_param_type_name(return_type) 946 } 947 948 if return_type == "void": 949 return template_capture_method_no_return_value.format(**format_args) 950 else: 951 return template_capture_method_with_return_value.format(**format_args) 952 953 954def const_pointer_type(param, packed_gl_enums): 955 type = just_the_type_packed(param, packed_gl_enums) 956 if "**" in type and "const" not in type: 957 return type.replace("**", "* const *") 958 elif "*" in type and "const" not in type: 959 return "const " + type 960 else: 961 return type 962 963 964def get_internal_params(cmd_name, params, cmd_packed_gl_enums): 965 packed_gl_enums = get_packed_enums(cmd_packed_gl_enums, cmd_name) 966 return ", ".join([ 967 make_param( 968 just_the_type_packed(param, packed_gl_enums), 969 just_the_name_packed(param, packed_gl_enums)) for param in params 970 ]) 971 972 973def get_validation_params(cmd_name, params, cmd_packed_gl_enums): 974 packed_gl_enums = get_packed_enums(cmd_packed_gl_enums, cmd_name) 975 return ", ".join([ 976 make_param( 977 const_pointer_type(param, packed_gl_enums), just_the_name_packed( 978 param, packed_gl_enums)) for param in params 979 ]) 980 981 982def format_context_decl(cmd_name, proto, params, template, cmd_packed_gl_enums): 983 internal_params = get_internal_params(cmd_name, params, cmd_packed_gl_enums) 984 985 return_type = proto[:-len(cmd_name)] 986 name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:] 987 name_lower_no_suffix = strip_suffix(name_lower_no_suffix) 988 maybe_const = " const" if name_lower_no_suffix.startswith( 989 "is") and name_lower_no_suffix[2].isupper() else "" 990 991 return template.format( 992 return_type=return_type, 993 name_lower_no_suffix=name_lower_no_suffix, 994 internal_params=internal_params, 995 maybe_const=maybe_const) 996 997 998def format_libgles_entry_point_def(cmd_name, proto, params, is_explicit_context): 999 internal_params = [just_the_name(param) for param in params] 1000 return_type = proto[:-len(cmd_name)] 1001 1002 return libgles_entry_point_def.format( 1003 name=cmd_name[2:], 1004 return_type=return_type, 1005 params=", ".join(params), 1006 internal_params=", ".join(internal_params), 1007 explicit_context_suffix="ContextANGLE" if is_explicit_context else "", 1008 explicit_context_param="GLeglContext ctx" if is_explicit_context else "", 1009 explicit_context_comma=", " if is_explicit_context and len(params) > 0 else "", 1010 explicit_context_internal_param="ctx" if is_explicit_context else "") 1011 1012 1013def format_validation_proto(cmd_name, params, cmd_packed_gl_enums): 1014 internal_params = get_validation_params(cmd_name, ["Context *context"] + params, 1015 cmd_packed_gl_enums) 1016 return template_validation_proto % (cmd_name[2:], internal_params) 1017 1018 1019def format_capture_proto(cmd_name, proto, params, cmd_packed_gl_enums): 1020 internal_params = get_internal_params( 1021 cmd_name, ["const State &glState", "bool isCallValid"] + params, cmd_packed_gl_enums) 1022 return_type = proto[:-len(cmd_name)].strip() 1023 if return_type != "void": 1024 internal_params += ", %s returnValue" % return_type 1025 return template_capture_proto % (cmd_name[2:], internal_params) 1026 1027 1028def path_to(folder, file): 1029 return os.path.join(script_relative(".."), "src", folder, file) 1030 1031 1032def get_entry_points(all_commands, commands, is_explicit_context, is_wgl, all_param_types, 1033 cmd_packed_gl_enums): 1034 decls = [] 1035 defs = [] 1036 export_defs = [] 1037 validation_protos = [] 1038 capture_protos = [] 1039 capture_methods = [] 1040 capture_pointer_funcs = [] 1041 1042 for command in all_commands: 1043 proto = command.find('proto') 1044 cmd_name = proto.find('name').text 1045 1046 if is_wgl: 1047 cmd_name = cmd_name if cmd_name[:3] == 'wgl' else 'wgl' + cmd_name 1048 1049 if cmd_name not in commands: 1050 continue 1051 1052 param_text = ["".join(param.itertext()) for param in command.findall('param')] 1053 proto_text = "".join(proto.itertext()) 1054 decls.append( 1055 format_entry_point_decl(cmd_name, proto_text, param_text, is_explicit_context)) 1056 defs.append( 1057 format_entry_point_def(command, cmd_name, proto_text, param_text, is_explicit_context, 1058 cmd_packed_gl_enums)) 1059 1060 export_defs.append( 1061 format_libgles_entry_point_def(cmd_name, proto_text, param_text, is_explicit_context)) 1062 1063 validation_protos.append( 1064 format_validation_proto(cmd_name, param_text, cmd_packed_gl_enums)) 1065 capture_protos.append( 1066 format_capture_proto(cmd_name, proto_text, param_text, cmd_packed_gl_enums)) 1067 capture_methods.append( 1068 format_capture_method(command, cmd_name, proto_text, param_text, all_param_types, 1069 capture_pointer_funcs, cmd_packed_gl_enums)) 1070 1071 return decls, defs, export_defs, validation_protos, capture_protos, capture_methods, capture_pointer_funcs 1072 1073 1074def get_decls(formatter, all_commands, gles_commands, already_included, cmd_packed_gl_enums): 1075 decls = [] 1076 for command in all_commands: 1077 proto = command.find('proto') 1078 cmd_name = proto.find('name').text 1079 1080 if cmd_name not in gles_commands: 1081 continue 1082 1083 name_no_suffix = strip_suffix(cmd_name) 1084 if name_no_suffix in already_included: 1085 continue 1086 1087 param_text = ["".join(param.itertext()) for param in command.findall('param')] 1088 proto_text = "".join(proto.itertext()) 1089 decls.append( 1090 format_context_decl(cmd_name, proto_text, param_text, formatter, cmd_packed_gl_enums)) 1091 1092 return decls 1093 1094 1095def get_glext_decls(all_commands, gles_commands, version, is_explicit_context): 1096 glext_ptrs = [] 1097 glext_protos = [] 1098 is_gles1 = False 1099 1100 if (version == ""): 1101 is_gles1 = True 1102 1103 for command in all_commands: 1104 proto = command.find('proto') 1105 cmd_name = proto.find('name').text 1106 1107 if cmd_name not in gles_commands: 1108 continue 1109 1110 param_text = ["".join(param.itertext()) for param in command.findall('param')] 1111 proto_text = "".join(proto.itertext()) 1112 1113 return_type = proto_text[:-len(cmd_name)] 1114 params = ", ".join(param_text) 1115 1116 format_params = { 1117 "apicall": "GL_API" if is_gles1 else "GL_APICALL", 1118 "name": cmd_name, 1119 "name_upper": cmd_name.upper(), 1120 "return_type": return_type, 1121 "params": params, 1122 "explicit_context_comma": ", " if is_explicit_context and len(params) > 0 else "", 1123 "explicit_context_suffix": "ContextANGLE" if is_explicit_context else "", 1124 "explicit_context_suffix_upper": "CONTEXTANGLE" if is_explicit_context else "", 1125 "explicit_context_param": "GLeglContext ctx" if is_explicit_context else "" 1126 } 1127 1128 glext_ptrs.append(template_glext_function_pointer.format(**format_params)) 1129 glext_protos.append(template_glext_function_prototype.format(**format_params)) 1130 1131 return glext_ptrs, glext_protos 1132 1133 1134def write_file(annotation, comment, template, entry_points, suffix, includes, lib, file): 1135 content = template.format( 1136 script_name=os.path.basename(sys.argv[0]), 1137 data_source_name=file, 1138 year=date.today().year, 1139 annotation_lower=annotation.lower(), 1140 annotation_upper=annotation.upper(), 1141 comment=comment, 1142 lib=lib.upper(), 1143 includes=includes, 1144 entry_points=entry_points) 1145 1146 path = path_to(lib, "entry_points_{}_autogen.{}".format(annotation.lower(), suffix)) 1147 1148 with open(path, "w") as out: 1149 out.write(content) 1150 out.close() 1151 1152 1153def write_export_files(entry_points, includes, source, lib_name, lib_description): 1154 content = template_lib_entry_point_source.format( 1155 script_name=os.path.basename(sys.argv[0]), 1156 data_source_name=source, 1157 year=date.today().year, 1158 lib_name=lib_name, 1159 lib_description=lib_description, 1160 includes=includes, 1161 entry_points=entry_points) 1162 1163 path = path_to(lib_name, "{}_autogen.cpp".format(lib_name)) 1164 1165 with open(path, "w") as out: 1166 out.write(content) 1167 out.close() 1168 1169 1170def write_context_api_decls(template, decls, api): 1171 for ver in decls['core'].keys(): 1172 interface_lines = [] 1173 1174 for i in decls['core'][ver]: 1175 interface_lines.append(i) 1176 1177 annotation = '{}_{}_{}'.format(api, ver[0], ver[1]) 1178 version = '{}_{}'.format(ver[0], ver[1]) 1179 1180 content = template.format( 1181 annotation_lower=annotation.lower(), 1182 annotation_upper=annotation.upper(), 1183 script_name=os.path.basename(sys.argv[0]), 1184 data_source_name="gl.xml", 1185 year=date.today().year, 1186 version=version, 1187 interface="\n".join(interface_lines)) 1188 1189 path = path_to("libANGLE", "Context_%s_autogen.h" % annotation.lower()) 1190 1191 with open(path, "w") as out: 1192 out.write(content) 1193 out.close() 1194 1195 if 'exts' in decls.keys(): 1196 interface_lines = [] 1197 for annotation in decls['exts'].keys(): 1198 interface_lines.append("\\\n /* " + annotation + " */ \\\n\\") 1199 1200 for extname in sorted(decls['exts'][annotation].keys()): 1201 interface_lines.append(" /* " + extname + " */ \\") 1202 interface_lines.extend(decls['exts'][annotation][extname]) 1203 1204 content = template.format( 1205 annotation_lower='gles_ext', 1206 annotation_upper='GLES_EXT', 1207 script_name=os.path.basename(sys.argv[0]), 1208 data_source_name="gl.xml", 1209 year=date.today().year, 1210 version='EXT', 1211 interface="\n".join(interface_lines)) 1212 1213 path = path_to("libANGLE", "Context_gles_ext_autogen.h") 1214 1215 with open(path, "w") as out: 1216 out.write(content) 1217 out.close() 1218 1219 1220def write_glext_explicit_context_inc(version, ptrs, protos): 1221 possible_versions = ["31", "32"] 1222 folder_version = version if version not in possible_versions else "3" 1223 1224 content = template_glext_explicit_context_inc.format( 1225 script_name=os.path.basename(sys.argv[0]), 1226 data_source_name="gl.xml and gl_angle_ext.xml", 1227 year=date.today().year, 1228 version=version, 1229 function_pointers=ptrs, 1230 function_prototypes=protos) 1231 1232 path = os.path.join( 1233 script_relative(".."), "include", "GLES{}".format(folder_version), 1234 "gl{}ext_explicit_context_autogen.inc".format(version)) 1235 1236 with open(path, "w") as out: 1237 out.write(content) 1238 out.close() 1239 1240 1241def write_validation_header(annotation, comment, protos, source): 1242 content = template_validation_header.format( 1243 script_name=os.path.basename(sys.argv[0]), 1244 data_source_name=source, 1245 year=date.today().year, 1246 annotation=annotation, 1247 comment=comment, 1248 prototypes="\n".join(protos)) 1249 1250 path = path_to("libANGLE", "validation%s_autogen.h" % annotation) 1251 1252 with open(path, "w") as out: 1253 out.write(content) 1254 out.close() 1255 1256 1257def write_capture_header(annotation, comment, protos, capture_pointer_funcs): 1258 content = template_capture_header.format( 1259 script_name=os.path.basename(sys.argv[0]), 1260 data_source_name="gl.xml and gl_angle_ext.xml", 1261 year=date.today().year, 1262 annotation=annotation, 1263 comment=comment, 1264 prototypes="\n".join(["\n// Method Captures\n"] + protos + ["\n// Parameter Captures\n"] + 1265 capture_pointer_funcs)) 1266 1267 path = path_to("libANGLE", "capture_gles_%s_autogen.h" % annotation) 1268 1269 with open(path, "w") as out: 1270 out.write(content) 1271 out.close() 1272 1273 1274def write_capture_source(annotation_with_dash, annotation_no_dash, comment, capture_methods): 1275 content = template_capture_source.format( 1276 script_name=os.path.basename(sys.argv[0]), 1277 data_source_name="gl.xml and gl_angle_ext.xml", 1278 year=date.today().year, 1279 annotation_with_dash=annotation_with_dash, 1280 annotation_no_dash=annotation_no_dash, 1281 comment=comment, 1282 capture_methods="\n".join(capture_methods)) 1283 1284 path = path_to("libANGLE", "capture_gles_%s_autogen.cpp" % annotation_with_dash) 1285 1286 with open(path, "w") as out: 1287 out.write(content) 1288 out.close() 1289 1290 1291def is_packed_enum_param_type(param_type): 1292 return param_type[0:2] != "GL" and "void" not in param_type 1293 1294 1295def get_gl_pointer_type(param_type): 1296 1297 if "ConstPointerPointer" in param_type: 1298 return "const " + param_type.replace("ConstPointerPointer", "") + " * const *" 1299 1300 if "ConstPointer" in param_type: 1301 return "const " + param_type.replace("ConstPointer", "") + " *" 1302 1303 if "PointerPointer" in param_type: 1304 return param_type.replace("PointerPointer", "") + " **" 1305 1306 if "Pointer" in param_type: 1307 return param_type.replace("Pointer", "") + " *" 1308 1309 return param_type 1310 1311 1312def get_param_type_type(param_type): 1313 1314 if is_packed_enum_param_type(param_type): 1315 param_type = "gl::" + param_type 1316 1317 return get_gl_pointer_type(param_type) 1318 1319 1320def get_gl_param_type_type(param_type): 1321 if not is_packed_enum_param_type(param_type): 1322 return get_gl_pointer_type(param_type) 1323 else: 1324 base_type = param_type.replace("Pointer", "").replace("Const", "") 1325 if base_type[-2:] == "ID": 1326 replace_type = "GLuint" 1327 else: 1328 replace_type = "GLenum" 1329 param_type = param_type.replace(base_type, replace_type) 1330 return get_gl_pointer_type(param_type) 1331 1332 1333def get_param_type_union_name(param_type): 1334 return param_type + "Val" 1335 1336 1337def format_param_type_union_type(param_type): 1338 return "%s %s;" % (get_param_type_type(param_type), get_param_type_union_name(param_type)) 1339 1340 1341def format_get_param_val_specialization(param_type): 1342 return template_get_param_val_specialization.format( 1343 enum=param_type, 1344 type=get_param_type_type(param_type), 1345 union_name=get_param_type_union_name(param_type)) 1346 1347 1348def format_access_param_value_case(param_type): 1349 return template_access_param_value_case.format(enum=param_type) 1350 1351 1352def format_set_param_val_specialization(param_type): 1353 return template_set_param_val_specialization.format( 1354 enum=param_type, 1355 type=get_param_type_type(param_type), 1356 union_name=get_param_type_union_name(param_type)) 1357 1358 1359def format_init_param_value_case(param_type): 1360 return template_init_param_value_case.format(enum=param_type) 1361 1362 1363def format_write_param_type_to_stream_case(param_type): 1364 return template_write_param_type_to_stream_case.format( 1365 enum=param_type, union_name=get_param_type_union_name(param_type)) 1366 1367 1368def get_resource_id_types(all_param_types): 1369 return [t[:-2] for t in filter(lambda t: t.endswith("ID"), all_param_types)] 1370 1371 1372def format_resource_id_types(all_param_types): 1373 resource_id_types = get_resource_id_types(all_param_types) 1374 resource_id_types += ["EnumCount", "InvalidEnum = EnumCount"] 1375 resource_id_types = ",\n ".join(resource_id_types) 1376 return resource_id_types 1377 1378 1379def write_capture_helper_header(all_param_types): 1380 1381 param_types = "\n ".join(["T%s," % t for t in all_param_types]) 1382 param_union_values = "\n ".join([format_param_type_union_type(t) for t in all_param_types]) 1383 get_param_val_specializations = "\n\n".join( 1384 [format_get_param_val_specialization(t) for t in all_param_types]) 1385 access_param_value_cases = "\n".join( 1386 [format_access_param_value_case(t) for t in all_param_types]) 1387 set_param_val_specializations = "\n\n".join( 1388 [format_set_param_val_specialization(t) for t in all_param_types]) 1389 init_param_value_cases = "\n".join([format_init_param_value_case(t) for t in all_param_types]) 1390 resource_id_types = format_resource_id_types(all_param_types) 1391 1392 content = template_frame_capture_utils_header.format( 1393 script_name=os.path.basename(sys.argv[0]), 1394 data_source_name="gl.xml and gl_angle_ext.xml", 1395 year=date.today().year, 1396 param_types=param_types, 1397 param_type_count=len(all_param_types), 1398 param_union_values=param_union_values, 1399 get_param_val_specializations=get_param_val_specializations, 1400 access_param_value_cases=access_param_value_cases, 1401 set_param_val_specializations=set_param_val_specializations, 1402 init_param_value_cases=init_param_value_cases, 1403 resource_id_types=resource_id_types) 1404 1405 path = path_to("libANGLE", "frame_capture_utils_autogen.h") 1406 1407 with open(path, "w") as out: 1408 out.write(content) 1409 out.close() 1410 1411 1412def format_param_type_to_string_case(param_type): 1413 return template_param_type_to_string_case.format( 1414 enum=param_type, type=get_gl_param_type_type(param_type)) 1415 1416 1417def get_resource_id_type_from_param_type(param_type): 1418 if param_type.endswith("ConstPointer"): 1419 return param_type.replace("ConstPointer", "")[:-2] 1420 if param_type.endswith("Pointer"): 1421 return param_type.replace("Pointer", "")[:-2] 1422 return param_type[:-2] 1423 1424 1425def format_param_type_to_resource_id_type_case(param_type): 1426 return template_param_type_to_resource_id_type_case.format( 1427 enum=param_type, resource_id_type=get_resource_id_type_from_param_type(param_type)) 1428 1429 1430def format_param_type_resource_id_cases(all_param_types): 1431 id_types = filter( 1432 lambda t: t.endswith("ID") or t.endswith("IDConstPointer") or t.endswith("IDPointer"), 1433 all_param_types) 1434 return "\n".join([format_param_type_to_resource_id_type_case(t) for t in id_types]) 1435 1436 1437def format_resource_id_type_name_case(resource_id_type): 1438 return template_resource_id_type_name_case.format(resource_id_type=resource_id_type) 1439 1440 1441def write_capture_helper_source(all_param_types): 1442 1443 write_param_type_to_stream_cases = "\n".join( 1444 [format_write_param_type_to_stream_case(t) for t in all_param_types]) 1445 param_type_to_string_cases = "\n".join( 1446 [format_param_type_to_string_case(t) for t in all_param_types]) 1447 1448 param_type_resource_id_cases = format_param_type_resource_id_cases(all_param_types) 1449 1450 resource_id_types = get_resource_id_types(all_param_types) 1451 resource_id_type_name_cases = "\n".join( 1452 [format_resource_id_type_name_case(t) for t in resource_id_types]) 1453 1454 content = template_frame_capture_utils_source.format( 1455 script_name=os.path.basename(sys.argv[0]), 1456 data_source_name="gl.xml and gl_angle_ext.xml", 1457 year=date.today().year, 1458 write_param_type_to_stream_cases=write_param_type_to_stream_cases, 1459 param_type_to_string_cases=param_type_to_string_cases, 1460 param_type_resource_id_cases=param_type_resource_id_cases, 1461 resource_id_type_name_cases=resource_id_type_name_cases) 1462 1463 path = path_to("libANGLE", "frame_capture_utils_autogen.cpp") 1464 1465 with open(path, "w") as out: 1466 out.write(content) 1467 out.close() 1468 1469 1470def get_command_params_text(command_node, cmd_name): 1471 param_text_list = list() 1472 for param_node in command_node.findall('param'): 1473 param_text_list.append("".join(param_node.itertext())) 1474 return param_text_list 1475 1476 1477def is_get_pointer_command(command_name): 1478 return command_name.endswith('Pointerv') and command_name.startswith('glGet') 1479 1480 1481def format_capture_replay_param_access(command_name, param_text_list, cmd_packed_gl_enums): 1482 param_access_strs = list() 1483 cmd_packed_enums = get_packed_enums(cmd_packed_gl_enums, command_name) 1484 for i, param_text in enumerate(param_text_list): 1485 param_type = just_the_type_packed(param_text, cmd_packed_enums) 1486 param_name = just_the_name_packed(param_text, cmd_packed_enums) 1487 1488 pointer_count = param_type.count('*') 1489 is_const = 'const' in param_type 1490 if pointer_count == 0: 1491 param_template = 'params.getParam("{name}", ParamType::T{enum_type}, {index}).value.{enum_type}Val' 1492 elif pointer_count == 1 and is_const: 1493 param_template = 'replayContext->getAsConstPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))' 1494 elif pointer_count == 2 and is_const: 1495 param_template = 'replayContext->getAsPointerConstPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))' 1496 elif pointer_count == 1 or (pointer_count == 2 and is_get_pointer_command(command_name)): 1497 param_template = 'replayContext->getReadBufferPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))' 1498 else: 1499 assert False, "Not supported param type %s" % param_type 1500 1501 param_access_strs.append( 1502 param_template.format( 1503 index=i, 1504 name=param_name, 1505 type=param_type, 1506 enum_type=get_capture_param_type_name(param_type))) 1507 return ",".join(param_access_strs) 1508 1509 1510def format_capture_replay_call_case(command_to_param_types_mapping, cmd_packed_gl_enums): 1511 call_str_list = list() 1512 for command_name, cmd_param_texts in sorted(command_to_param_types_mapping.items()): 1513 entry_point_name = command_name[2:] # strip the 'gl' prefix 1514 1515 call_str_list.append( 1516 template_capture_replay_call_case.format( 1517 entry_point=entry_point_name, 1518 param_value_access=format_capture_replay_param_access( 1519 command_name, cmd_param_texts, cmd_packed_gl_enums), 1520 context_call=entry_point_name[0].lower() + entry_point_name[1:], 1521 )) 1522 1523 return '\n'.join(call_str_list) 1524 1525 1526def write_capture_replay_source(all_commands_nodes, gles_command_names, cmd_packed_gl_enums): 1527 all_commands_names = set(gles_command_names) 1528 1529 command_to_param_types_mapping = dict() 1530 for command_node in all_commands_nodes: 1531 command_name = command_node.find('proto').find('name').text 1532 if command_name not in all_commands_names: 1533 continue 1534 1535 command_to_param_types_mapping[command_name] = get_command_params_text( 1536 command_node, command_name) 1537 1538 call_replay_cases = format_capture_replay_call_case(command_to_param_types_mapping, 1539 cmd_packed_gl_enums) 1540 1541 source_content = template_capture_replay_source.format( 1542 script_name=os.path.basename(sys.argv[0]), 1543 data_source_name="gl.xml and gl_angle_ext.xml", 1544 year=date.today().year, 1545 call_replay_cases=call_replay_cases, 1546 ) 1547 source_file_path = registry_xml.script_relative( 1548 "../src/libANGLE/frame_capture_replay_autogen.cpp") 1549 with open(source_file_path, 'w') as f: 1550 f.write(source_content) 1551 1552 1553def write_windows_def_file(data_source_name, lib, libexport, folder, exports): 1554 1555 content = template_windows_def_file.format( 1556 script_name=os.path.basename(sys.argv[0]), 1557 data_source_name=data_source_name, 1558 exports="\n".join(exports), 1559 year=date.today().year, 1560 lib=libexport) 1561 1562 path = path_to(folder, "%s_autogen.def" % lib) 1563 1564 with open(path, "w") as out: 1565 out.write(content) 1566 out.close() 1567 1568 1569def get_exports(commands, fmt=None): 1570 if fmt: 1571 return [" %s" % fmt(cmd) for cmd in sorted(commands)] 1572 else: 1573 return [" %s" % cmd for cmd in sorted(commands)] 1574 1575 1576# Get EGL exports 1577def get_egl_exports(): 1578 1579 egl = registry_xml.RegistryXML('egl.xml', 'egl_angle_ext.xml') 1580 exports = [] 1581 1582 capser = lambda fn: "EGL_" + fn[3:] 1583 1584 for major, minor in [[1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5]]: 1585 annotation = "{}_{}".format(major, minor) 1586 name_prefix = "EGL_VERSION_" 1587 1588 feature_name = "{}{}".format(name_prefix, annotation) 1589 1590 egl.AddCommands(feature_name, annotation) 1591 1592 commands = egl.commands[annotation] 1593 1594 if len(commands) == 0: 1595 continue 1596 1597 exports.append("\n ; EGL %d.%d" % (major, minor)) 1598 exports += get_exports(commands, capser) 1599 1600 egl.AddExtensionCommands(registry_xml.supported_egl_extensions, ['egl']) 1601 1602 for extension_name, ext_cmd_names in sorted(egl.ext_data.iteritems()): 1603 1604 if len(ext_cmd_names) == 0: 1605 continue 1606 1607 exports.append("\n ; %s" % extension_name) 1608 exports += get_exports(ext_cmd_names, capser) 1609 1610 return exports 1611 1612 1613def main(): 1614 1615 # auto_script parameters. 1616 if len(sys.argv) > 1: 1617 inputs = ['entry_point_packed_gl_enums.json'] + registry_xml.xml_inputs 1618 outputs = [ 1619 '../src/libANGLE/Context_gl_1_0_autogen.h', 1620 '../src/libANGLE/Context_gl_1_1_autogen.h', 1621 '../src/libANGLE/Context_gl_1_2_autogen.h', 1622 '../src/libANGLE/Context_gl_1_3_autogen.h', 1623 '../src/libANGLE/Context_gl_1_4_autogen.h', 1624 '../src/libANGLE/Context_gl_1_5_autogen.h', 1625 '../src/libANGLE/Context_gl_2_0_autogen.h', 1626 '../src/libANGLE/Context_gl_2_1_autogen.h', 1627 '../src/libANGLE/Context_gl_3_0_autogen.h', 1628 '../src/libANGLE/Context_gl_3_1_autogen.h', 1629 '../src/libANGLE/Context_gl_3_2_autogen.h', 1630 '../src/libANGLE/Context_gl_3_3_autogen.h', 1631 '../src/libANGLE/Context_gl_4_0_autogen.h', 1632 '../src/libANGLE/Context_gl_4_1_autogen.h', 1633 '../src/libANGLE/Context_gl_4_2_autogen.h', 1634 '../src/libANGLE/Context_gl_4_3_autogen.h', 1635 '../src/libANGLE/Context_gl_4_4_autogen.h', 1636 '../src/libANGLE/Context_gl_4_5_autogen.h', 1637 '../src/libANGLE/Context_gl_4_6_autogen.h', 1638 '../src/libANGLE/Context_gles_1_0_autogen.h', 1639 '../src/libANGLE/Context_gles_2_0_autogen.h', 1640 '../src/libANGLE/Context_gles_3_0_autogen.h', 1641 '../src/libANGLE/Context_gles_3_1_autogen.h', 1642 '../src/libANGLE/Context_gles_3_2_autogen.h', 1643 '../src/libANGLE/Context_gles_ext_autogen.h', 1644 '../src/libANGLE/capture_gles_1_0_autogen.cpp', 1645 '../src/libANGLE/capture_gles_1_0_autogen.h', 1646 '../src/libANGLE/capture_gles_2_0_autogen.cpp', 1647 '../src/libANGLE/capture_gles_2_0_autogen.h', 1648 '../src/libANGLE/capture_gles_3_0_autogen.cpp', 1649 '../src/libANGLE/capture_gles_3_0_autogen.h', 1650 '../src/libANGLE/capture_gles_3_1_autogen.cpp', 1651 '../src/libANGLE/capture_gles_3_1_autogen.h', 1652 '../src/libANGLE/capture_gles_3_2_autogen.cpp', 1653 '../src/libANGLE/capture_gles_3_2_autogen.h', 1654 '../src/libANGLE/capture_gles_ext_autogen.cpp', 1655 '../src/libANGLE/capture_gles_ext_autogen.h', 1656 '../src/libANGLE/frame_capture_replay_autogen.cpp', 1657 '../src/libANGLE/frame_capture_utils_autogen.cpp', 1658 '../src/libANGLE/frame_capture_utils_autogen.h', 1659 '../src/libANGLE/entry_points_enum_autogen.cpp', 1660 '../src/libANGLE/entry_points_enum_autogen.h', 1661 '../src/libANGLE/validationES1_autogen.h', 1662 '../src/libANGLE/validationES2_autogen.h', 1663 '../src/libANGLE/validationES31_autogen.h', 1664 '../src/libANGLE/validationES32_autogen.h', 1665 '../src/libANGLE/validationES3_autogen.h', 1666 '../src/libANGLE/validationESEXT_autogen.h', 1667 '../src/libANGLE/validationGL1_autogen.h', 1668 '../src/libANGLE/validationGL2_autogen.h', 1669 '../src/libANGLE/validationGL3_autogen.h', 1670 '../src/libANGLE/validationGL4_autogen.h', 1671 '../src/libANGLE/validationGL11_autogen.h', 1672 '../src/libANGLE/validationGL12_autogen.h', 1673 '../src/libANGLE/validationGL13_autogen.h', 1674 '../src/libANGLE/validationGL14_autogen.h', 1675 '../src/libANGLE/validationGL15_autogen.h', 1676 '../src/libANGLE/validationGL21_autogen.h', 1677 '../src/libANGLE/validationGL31_autogen.h', 1678 '../src/libANGLE/validationGL32_autogen.h', 1679 '../src/libANGLE/validationGL33_autogen.h', 1680 '../src/libANGLE/validationGL41_autogen.h', 1681 '../src/libANGLE/validationGL42_autogen.h', 1682 '../src/libANGLE/validationGL43_autogen.h', 1683 '../src/libANGLE/validationGL44_autogen.h', 1684 '../src/libANGLE/validationGL45_autogen.h', 1685 '../src/libANGLE/validationGL46_autogen.h', 1686 '../src/libGLESv2/entry_points_gles_1_0_autogen.cpp', 1687 '../src/libGLESv2/entry_points_gles_1_0_autogen.h', 1688 '../src/libGLESv2/entry_points_gles_2_0_autogen.cpp', 1689 '../src/libGLESv2/entry_points_gles_2_0_autogen.h', 1690 '../src/libGLESv2/entry_points_gles_3_0_autogen.cpp', 1691 '../src/libGLESv2/entry_points_gles_3_0_autogen.h', 1692 '../src/libGLESv2/entry_points_gles_3_1_autogen.cpp', 1693 '../src/libGLESv2/entry_points_gles_3_1_autogen.h', 1694 '../src/libGLESv2/entry_points_gles_3_2_autogen.cpp', 1695 '../src/libGLESv2/entry_points_gles_3_2_autogen.h', 1696 '../src/libGLESv2/entry_points_gles_ext_autogen.cpp', 1697 '../src/libGLESv2/entry_points_gles_ext_autogen.h', 1698 '../src/libGLESv2/libGLESv2_autogen.cpp', 1699 '../src/libGLESv2/libGLESv2_autogen.def', 1700 '../src/libGLESv2/libGLESv2_no_capture_autogen.def', 1701 '../src/libGLESv2/libGLESv2_with_capture_autogen.def', 1702 '../src/libGL/entry_points_gl_1_0_autogen.cpp', 1703 '../src/libGL/entry_points_gl_1_0_autogen.h', 1704 '../src/libGL/entry_points_gl_1_1_autogen.cpp', 1705 '../src/libGL/entry_points_gl_1_1_autogen.h', 1706 '../src/libGL/entry_points_gl_1_2_autogen.cpp', 1707 '../src/libGL/entry_points_gl_1_2_autogen.h', 1708 '../src/libGL/entry_points_gl_1_3_autogen.cpp', 1709 '../src/libGL/entry_points_gl_1_3_autogen.h', 1710 '../src/libGL/entry_points_gl_1_4_autogen.cpp', 1711 '../src/libGL/entry_points_gl_1_4_autogen.h', 1712 '../src/libGL/entry_points_gl_1_5_autogen.cpp', 1713 '../src/libGL/entry_points_gl_1_5_autogen.h', 1714 '../src/libGL/entry_points_gl_2_0_autogen.cpp', 1715 '../src/libGL/entry_points_gl_2_0_autogen.h', 1716 '../src/libGL/entry_points_gl_2_1_autogen.cpp', 1717 '../src/libGL/entry_points_gl_2_1_autogen.h', 1718 '../src/libGL/entry_points_gl_3_0_autogen.cpp', 1719 '../src/libGL/entry_points_gl_3_0_autogen.h', 1720 '../src/libGL/entry_points_gl_3_1_autogen.cpp', 1721 '../src/libGL/entry_points_gl_3_1_autogen.h', 1722 '../src/libGL/entry_points_gl_3_2_autogen.cpp', 1723 '../src/libGL/entry_points_gl_3_2_autogen.h', 1724 '../src/libGL/entry_points_gl_3_3_autogen.cpp', 1725 '../src/libGL/entry_points_gl_3_3_autogen.h', 1726 '../src/libGL/entry_points_gl_4_0_autogen.cpp', 1727 '../src/libGL/entry_points_gl_4_0_autogen.h', 1728 '../src/libGL/entry_points_gl_4_1_autogen.cpp', 1729 '../src/libGL/entry_points_gl_4_1_autogen.h', 1730 '../src/libGL/entry_points_gl_4_2_autogen.cpp', 1731 '../src/libGL/entry_points_gl_4_2_autogen.h', 1732 '../src/libGL/entry_points_gl_4_3_autogen.cpp', 1733 '../src/libGL/entry_points_gl_4_3_autogen.h', 1734 '../src/libGL/entry_points_gl_4_4_autogen.cpp', 1735 '../src/libGL/entry_points_gl_4_4_autogen.h', 1736 '../src/libGL/entry_points_gl_4_5_autogen.cpp', 1737 '../src/libGL/entry_points_gl_4_5_autogen.h', 1738 '../src/libGL/entry_points_gl_4_6_autogen.cpp', 1739 '../src/libGL/entry_points_gl_4_6_autogen.h', 1740 '../src/libGL/libGL_autogen.cpp', 1741 '../src/libGL/libGL_autogen.def', 1742 ] 1743 1744 if sys.argv[1] == 'inputs': 1745 print ','.join(inputs) 1746 elif sys.argv[1] == 'outputs': 1747 print ','.join(outputs) 1748 else: 1749 print('Invalid script parameters') 1750 return 1 1751 return 0 1752 1753 with open(script_relative('entry_point_packed_gl_enums.json')) as f: 1754 cmd_packed_gl_enums = json.loads(f.read()) 1755 1756 glesdecls = {} 1757 glesdecls['core'] = {} 1758 glesdecls['exts'] = {} 1759 for ver in [(1, 0), (2, 0), (3, 0), (3, 1), (3, 2)]: 1760 glesdecls['core'][ver] = [] 1761 for ver in ['GLES1 Extensions', 'GLES2+ Extensions', 'ANGLE Extensions']: 1762 glesdecls['exts'][ver] = {} 1763 1764 libgles_ep_defs = [] 1765 libgles_ep_exports = [] 1766 1767 xml = registry_xml.RegistryXML('gl.xml', 'gl_angle_ext.xml') 1768 1769 # Stores core commands to keep track of duplicates 1770 all_commands_no_suffix = [] 1771 all_commands_with_suffix = [] 1772 all_gles_param_types = set() 1773 1774 # First run through the main GLES entry points. Since ES2+ is the primary use 1775 # case, we go through those first and then add ES1-only APIs at the end. 1776 versions = [[2, 0], [3, 0], [3, 1], [3, 2], [1, 0]] 1777 for major_version, minor_version in versions: 1778 version = "{}_{}".format(major_version, minor_version) 1779 annotation = "GLES_{}".format(version) 1780 name_prefix = "GL_ES_VERSION_" 1781 1782 if major_version == 1: 1783 name_prefix = "GL_VERSION_ES_CM_" 1784 1785 comment = version.replace("_", ".") 1786 feature_name = "{}{}".format(name_prefix, version) 1787 1788 xml.AddCommands(feature_name, version) 1789 1790 gles_commands = xml.commands[version] 1791 all_commands = xml.all_commands 1792 all_commands_no_suffix.extend(xml.commands[version]) 1793 all_commands_with_suffix.extend(xml.commands[version]) 1794 1795 decls, defs, libgles_defs, validation_protos, capture_protos, capture_methods, capture_pointer_funcs = get_entry_points( 1796 all_commands, gles_commands, False, False, all_gles_param_types, cmd_packed_gl_enums) 1797 1798 # Write the version as a comment before the first EP. 1799 libgles_defs.insert(0, "\n// OpenGL ES %s" % comment) 1800 libgles_ep_exports.append("\n ; OpenGL ES %s" % comment) 1801 1802 libgles_ep_defs += libgles_defs 1803 libgles_ep_exports += get_exports(gles_commands) 1804 1805 major_if_not_one = major_version if major_version != 1 else "" 1806 minor_if_not_zero = minor_version if minor_version != 0 else "" 1807 1808 header_includes = template_header_includes.format( 1809 major=major_if_not_one, minor=minor_if_not_zero) 1810 1811 # We include the platform.h header since it undefines the conflicting MemoryBarrier macro. 1812 if major_version == 3 and minor_version == 1: 1813 header_includes += "\n#include \"common/platform.h\"\n" 1814 1815 version_annotation = "%s%s" % (major_version, minor_if_not_zero) 1816 source_includes = template_sources_includes.format( 1817 header_version=annotation.lower(), validation_header_version="ES" + version_annotation) 1818 1819 write_file(annotation, "GLES " + comment, template_entry_point_header, "\n".join(decls), 1820 "h", header_includes, "libGLESv2", "gl.xml") 1821 write_file(annotation, "GLES " + comment, template_entry_point_source, "\n".join(defs), 1822 "cpp", source_includes, "libGLESv2", "gl.xml") 1823 1824 glesdecls['core'][(major_version, minor_version)] = get_decls( 1825 context_decl_format, all_commands, gles_commands, [], cmd_packed_gl_enums) 1826 1827 validation_annotation = "ES%s%s" % (major_version, minor_if_not_zero) 1828 write_validation_header(validation_annotation, "ES %s" % comment, validation_protos, 1829 "gl.xml and gl_angle_ext.xml") 1830 1831 write_capture_header(version, comment, capture_protos, capture_pointer_funcs) 1832 write_capture_source(version, validation_annotation, comment, capture_methods) 1833 1834 # After we finish with the main entry points, we process the extensions. 1835 extension_defs = [] 1836 extension_decls = [] 1837 extension_commands = [] 1838 1839 # Accumulated validation prototypes. 1840 ext_validation_protos = [] 1841 ext_capture_protos = [] 1842 ext_capture_methods = [] 1843 ext_capture_param_funcs = [] 1844 1845 for gles1ext in registry_xml.gles1_extensions: 1846 glesdecls['exts']['GLES1 Extensions'][gles1ext] = [] 1847 for glesext in registry_xml.gles_extensions: 1848 glesdecls['exts']['GLES2+ Extensions'][glesext] = [] 1849 for angle_ext in registry_xml.angle_extensions: 1850 glesdecls['exts']['ANGLE Extensions'][angle_ext] = [] 1851 1852 xml.AddExtensionCommands(registry_xml.supported_extensions, ['gles2', 'gles1']) 1853 1854 for extension_name, ext_cmd_names in sorted(xml.ext_data.iteritems()): 1855 extension_commands.extend(xml.ext_data[extension_name]) 1856 1857 # Detect and filter duplicate extensions. 1858 decls, defs, libgles_defs, validation_protos, capture_protos, capture_methods, capture_param_funcs = get_entry_points( 1859 xml.all_commands, ext_cmd_names, False, False, all_gles_param_types, 1860 cmd_packed_gl_enums) 1861 1862 # Avoid writing out entry points defined by a prior extension. 1863 for dupe in xml.ext_dupes[extension_name]: 1864 msg = "// {} is already defined.\n".format(dupe[2:]) 1865 defs.append(msg) 1866 1867 # Write the extension name as a comment before the first EP. 1868 comment = "\n// {}".format(extension_name) 1869 defs.insert(0, comment) 1870 decls.insert(0, comment) 1871 libgles_defs.insert(0, comment) 1872 libgles_ep_exports.append("\n ; %s" % extension_name) 1873 1874 extension_defs += defs 1875 extension_decls += decls 1876 1877 ext_validation_protos += [comment] + validation_protos 1878 ext_capture_protos += [comment] + capture_protos 1879 ext_capture_methods += capture_methods 1880 ext_capture_param_funcs += capture_param_funcs 1881 1882 libgles_ep_defs += libgles_defs 1883 libgles_ep_exports += get_exports(ext_cmd_names) 1884 1885 if (extension_name in registry_xml.gles1_extensions and 1886 extension_name not in gles1_no_context_decl_extensions): 1887 glesdecls['exts']['GLES1 Extensions'][extension_name] = get_decls( 1888 context_decl_format, all_commands, ext_cmd_names, all_commands_no_suffix, 1889 cmd_packed_gl_enums) 1890 if extension_name in registry_xml.gles_extensions: 1891 glesdecls['exts']['GLES2+ Extensions'][extension_name] = get_decls( 1892 context_decl_format, all_commands, ext_cmd_names, all_commands_no_suffix, 1893 cmd_packed_gl_enums) 1894 if extension_name in registry_xml.angle_extensions: 1895 glesdecls['exts']['ANGLE Extensions'][extension_name] = get_decls( 1896 context_decl_format, all_commands, ext_cmd_names, all_commands_no_suffix, 1897 cmd_packed_gl_enums) 1898 1899 for name in extension_commands: 1900 all_commands_with_suffix.append(name) 1901 all_commands_no_suffix.append(strip_suffix(name)) 1902 1903 # Special handling for EGL_ANGLE_explicit_context extension 1904 if registry_xml.support_EGL_ANGLE_explicit_context: 1905 comment = "\n// EGL_ANGLE_explicit_context" 1906 extension_defs.append(comment) 1907 extension_decls.append(comment) 1908 libgles_ep_defs.append(comment) 1909 1910 cmds = xml.all_cmd_names.get_all_commands() 1911 1912 # Get the explicit context entry points 1913 decls, defs, libgles_defs, validation_protos, capture_protos, capture_methods, capture_param_funcs = get_entry_points( 1914 xml.all_commands, cmds, True, False, all_gles_param_types, cmd_packed_gl_enums) 1915 1916 # Append the explicit context entry points 1917 extension_decls += decls 1918 extension_defs += defs 1919 libgles_ep_defs += libgles_defs 1920 1921 libgles_ep_exports.append("\n ; EGL_ANGLE_explicit_context") 1922 libgles_ep_exports += get_exports(cmds, lambda x: "%sContextANGLE" % x) 1923 1924 # Generate .inc files for extension function pointers and declarations 1925 for major, minor in versions: 1926 annotation = "{}_{}".format(major, minor) 1927 1928 major_if_not_one = major if major != 1 else "" 1929 minor_if_not_zero = minor if minor != 0 else "" 1930 version = "{}{}".format(major_if_not_one, minor_if_not_zero) 1931 1932 glext_ptrs, glext_protos = get_glext_decls(all_commands, 1933 xml.all_cmd_names.get_commands(annotation), 1934 version, True) 1935 1936 glext_ext_ptrs = [] 1937 glext_ext_protos = [] 1938 1939 # Append extensions for 1.0 and 2.0 1940 if (annotation == "1_0"): 1941 glext_ext_ptrs, glext_ext_protos = get_glext_decls( 1942 all_commands, xml.all_cmd_names.get_commands("glext"), version, True) 1943 elif (annotation == "2_0"): 1944 glext_ext_ptrs, glext_ext_protos = get_glext_decls( 1945 all_commands, xml.all_cmd_names.get_commands("gl2ext"), version, True) 1946 1947 glext_ptrs += glext_ext_ptrs 1948 glext_protos += glext_ext_protos 1949 1950 write_glext_explicit_context_inc(version, "\n".join(glext_ptrs), 1951 "\n".join(glext_protos)) 1952 1953 # Now we generate entry points for the desktop implementation 1954 gldecls = {} 1955 gldecls['core'] = {} 1956 for ver in [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 0), (2, 1), (3, 0), (3, 1), 1957 (3, 2), (3, 3), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6)]: 1958 gldecls['core'][ver] = [] 1959 1960 libgl_ep_defs = [] 1961 libgl_ep_exports = [] 1962 1963 glxml = registry_xml.RegistryXML('gl.xml') 1964 1965 for major_version, minor_version in [[1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [2, 0], 1966 [2, 1], [3, 0], [3, 1], [3, 2], [3, 3], [4, 0], [4, 1], 1967 [4, 2], [4, 3], [4, 4], [4, 5], [4, 6]]: 1968 version = "{}_{}".format(major_version, minor_version) 1969 annotation = "GL_{}".format(version) 1970 name_prefix = "GL_VERSION_" 1971 1972 comment = version.replace("_", ".") 1973 feature_name = "{}{}".format(name_prefix, version) 1974 1975 glxml.AddCommands(feature_name, version) 1976 1977 all_libgl_commands = glxml.commands[version] 1978 1979 just_libgl_commands = [ 1980 cmd for cmd in all_libgl_commands if cmd not in all_commands_no_suffix 1981 ] 1982 just_libgl_commands_suffix = [ 1983 cmd for cmd in all_libgl_commands if cmd not in all_commands_with_suffix 1984 ] 1985 1986 all_commands32 = glxml.all_commands 1987 1988 # Validation duplicates handled with suffix 1989 _, _, _, validation_protos32, _, _, _ = get_entry_points( 1990 all_commands32, just_libgl_commands_suffix, False, False, all_gles_param_types, 1991 cmd_packed_gl_enums) 1992 decls_gl, defs_gl, libgl_defs, _, _, _, _ = get_entry_points( 1993 all_commands32, all_libgl_commands, False, False, all_gles_param_types, 1994 cmd_packed_gl_enums) 1995 1996 # Write the version as a comment before the first EP. 1997 libgl_defs.insert(0, "\n// GL %s" % comment) 1998 libgl_ep_exports.append("\n ; GL %s" % comment) 1999 2000 libgl_ep_defs += libgl_defs 2001 libgl_ep_exports += get_exports(all_libgl_commands) 2002 2003 minor_if_not_zero = minor_version if minor_version != 0 else "" 2004 2005 header_includes = template_header_includes_gl32 2006 source_includes = template_sources_includes_gl32.format(annotation.lower(), major_version, 2007 minor_if_not_zero) 2008 2009 # Entry point files 2010 write_file(annotation, "GL " + comment, template_entry_point_header, "\n".join(decls_gl), 2011 "h", header_includes, "libGL", "gl.xml") 2012 write_file(annotation, "GL " + comment, template_entry_point_source, "\n".join(defs_gl), 2013 "cpp", source_includes, "libGL", "gl.xml") 2014 2015 gldecls['core'][(major_version, minor_version)] = get_decls( 2016 context_decl_format, all_commands32, just_libgl_commands, all_commands_no_suffix, 2017 cmd_packed_gl_enums) 2018 2019 # Validation files 2020 validation_annotation = "GL%s%s" % (major_version, minor_if_not_zero) 2021 write_validation_header(validation_annotation, "%s" % comment, validation_protos32, 2022 "gl.xml and wgl.xml") 2023 2024 # WGL 2025 wglxml = registry_xml.RegistryXML('wgl.xml') 2026 2027 name_prefix = "WGL_VERSION_" 2028 version = "1_0" 2029 comment = version.replace("_", ".") 2030 feature_name = "{}{}".format(name_prefix, version) 2031 wglxml.AddCommands(feature_name, version) 2032 wgl_commands = wglxml.commands[version] 2033 all_commands32.extend(wglxml.all_commands) 2034 2035 wgl_commands = [cmd if cmd[:3] == 'wgl' else 'wgl' + cmd for cmd in wgl_commands] 2036 2037 wgl_param_types = set() 2038 decls_wgl, defs_wgl, wgl_defs, validation_protos_wgl, _, _, _ = get_entry_points( 2039 all_commands32, wgl_commands, False, True, wgl_param_types, {}) 2040 2041 # Write the version as a comment before the first EP. 2042 libgl_ep_exports.append("\n ; WGL %s" % comment) 2043 2044 # Other versions of these functions are used 2045 wgl_commands.remove("wglUseFontBitmaps") 2046 wgl_commands.remove("wglUseFontOutlines") 2047 2048 libgl_ep_exports += get_exports(wgl_commands) 2049 2050 header_includes = template_header_includes.format(major="", minor="") 2051 header_includes += """ 2052 #include <GLES/glext.h> 2053 #include <GLES2/gl2.h> 2054 #include <GLES2/gl2ext.h> 2055 #include <GLES3/gl32.h> 2056 """ 2057 2058 source_includes = template_sources_includes.format( 2059 header_version="gles_ext", validation_header_version="ESEXT") 2060 source_includes += """ 2061 #include "libANGLE/capture_gles_1_0_autogen.h" 2062 #include "libANGLE/capture_gles_2_0_autogen.h" 2063 #include "libANGLE/capture_gles_3_0_autogen.h" 2064 #include "libANGLE/capture_gles_3_1_autogen.h" 2065 #include "libANGLE/capture_gles_3_2_autogen.h" 2066 #include "libANGLE/validationES1.h" 2067 #include "libANGLE/validationES2.h" 2068 #include "libANGLE/validationES3.h" 2069 #include "libANGLE/validationES31.h" 2070 #include "libANGLE/validationES32.h" 2071 """ 2072 2073 write_file("gles_ext", "GLES extension", template_entry_point_header, 2074 "\n".join([item for item in extension_decls]), "h", header_includes, "libGLESv2", 2075 "gl.xml and gl_angle_ext.xml") 2076 write_file("gles_ext", "GLES extension", template_entry_point_source, 2077 "\n".join([item for item in extension_defs]), "cpp", source_includes, "libGLESv2", 2078 "gl.xml and gl_angle_ext.xml") 2079 2080 write_validation_header("ESEXT", "ES extension", ext_validation_protos, 2081 "gl.xml and gl_angle_ext.xml") 2082 write_capture_header("ext", "extension", ext_capture_protos, ext_capture_param_funcs) 2083 write_capture_source("ext", "ESEXT", "extension", ext_capture_methods) 2084 2085 write_context_api_decls(context_header, glesdecls, "gles") 2086 write_context_api_decls(context_header, gldecls, "gl") 2087 2088 # Entry point enum 2089 cmd_names = ["Invalid"] + [cmd[2:] for cmd in xml.all_cmd_names.get_all_commands()] 2090 gl_cmd_names = [cmd[2:] for cmd in glxml.all_cmd_names.get_all_commands()] 2091 cmd_names.extend([cmd for cmd in gl_cmd_names if cmd not in cmd_names]) 2092 sorted_cmd_names = sorted(cmd_names) 2093 2094 entry_points_enum_header = template_entry_points_enum_header.format( 2095 script_name=os.path.basename(sys.argv[0]), 2096 data_source_name="gl.xml and gl_angle_ext.xml", 2097 year=date.today().year, 2098 lib="GL/GLES", 2099 entry_points_list=",\n".join([" " + cmd for cmd in sorted_cmd_names])) 2100 2101 entry_points_enum_header_path = path_to("libANGLE", "entry_points_enum_autogen.h") 2102 with open(entry_points_enum_header_path, "w") as out: 2103 out.write(entry_points_enum_header) 2104 out.close() 2105 2106 entry_points_cases = [ 2107 template_entry_points_name_case.format(enum=cmd) for cmd in sorted_cmd_names 2108 ] 2109 entry_points_enum_source = template_entry_points_enum_source.format( 2110 script_name=os.path.basename(sys.argv[0]), 2111 data_source_name="gl.xml and gl_angle_ext.xml", 2112 year=date.today().year, 2113 lib="GL/GLES", 2114 entry_points_name_cases="\n".join(entry_points_cases)) 2115 2116 entry_points_enum_source_path = path_to("libANGLE", "entry_points_enum_autogen.cpp") 2117 with open(entry_points_enum_source_path, "w") as out: 2118 out.write(entry_points_enum_source) 2119 out.close() 2120 2121 source_includes = """ 2122 #include "angle_gl.h" 2123 2124 #include "libGLESv2/entry_points_gles_1_0_autogen.h" 2125 #include "libGLESv2/entry_points_gles_2_0_autogen.h" 2126 #include "libGLESv2/entry_points_gles_3_0_autogen.h" 2127 #include "libGLESv2/entry_points_gles_3_1_autogen.h" 2128 #include "libGLESv2/entry_points_gles_3_2_autogen.h" 2129 #include "libGLESv2/entry_points_gles_ext_autogen.h" 2130 2131 #include "common/event_tracer.h" 2132 """ 2133 2134 write_export_files("\n".join([item for item in libgles_ep_defs]), source_includes, 2135 "gl.xml and gl_angle_ext.xml", "libGLESv2", "OpenGL ES") 2136 2137 source_includes = """ 2138 #include "angle_gl.h" 2139 2140 #include "libGL/entry_points_gl_1_0_autogen.h" 2141 #include "libGL/entry_points_gl_1_1_autogen.h" 2142 #include "libGL/entry_points_gl_1_2_autogen.h" 2143 #include "libGL/entry_points_gl_1_3_autogen.h" 2144 #include "libGL/entry_points_gl_1_4_autogen.h" 2145 #include "libGL/entry_points_gl_1_5_autogen.h" 2146 #include "libGL/entry_points_gl_2_0_autogen.h" 2147 #include "libGL/entry_points_gl_2_1_autogen.h" 2148 #include "libGL/entry_points_gl_3_0_autogen.h" 2149 #include "libGL/entry_points_gl_3_1_autogen.h" 2150 #include "libGL/entry_points_gl_3_2_autogen.h" 2151 #include "libGL/entry_points_gl_3_3_autogen.h" 2152 #include "libGL/entry_points_gl_4_0_autogen.h" 2153 #include "libGL/entry_points_gl_4_1_autogen.h" 2154 #include "libGL/entry_points_gl_4_2_autogen.h" 2155 #include "libGL/entry_points_gl_4_3_autogen.h" 2156 #include "libGL/entry_points_gl_4_4_autogen.h" 2157 #include "libGL/entry_points_gl_4_5_autogen.h" 2158 #include "libGL/entry_points_gl_4_6_autogen.h" 2159 2160 #include "common/event_tracer.h" 2161 """ 2162 2163 write_export_files("\n".join([item for item in libgl_ep_defs]), source_includes, 2164 "gl.xml and wgl.xml", "libGL", "Windows GL") 2165 2166 libgles_ep_exports += get_egl_exports() 2167 2168 everything = "Khronos and ANGLE XML files" 2169 2170 for lib in ["libGLESv2" + suffix for suffix in ["", "_no_capture", "_with_capture"]]: 2171 write_windows_def_file(everything, lib, lib, "libGLESv2", libgles_ep_exports) 2172 write_windows_def_file(everything, "libGL", "openGL32", "libGL", libgl_ep_exports) 2173 2174 all_gles_param_types = sorted(all_gles_param_types) 2175 write_capture_helper_header(all_gles_param_types) 2176 write_capture_helper_source(all_gles_param_types) 2177 write_capture_replay_source(xml.all_commands, all_commands_no_suffix, cmd_packed_gl_enums) 2178 2179 2180if __name__ == '__main__': 2181 sys.exit(main()) 2182