1#!/usr/bin/python3 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 12import registry_xml 13from registry_xml import apis, script_relative, strip_api_prefix 14 15# Paths 16CL_STUBS_HEADER_PATH = "../src/libGLESv2/cl_stubs_autogen.h" 17EGL_GET_LABELED_OBJECT_DATA_PATH = "../src/libGLESv2/egl_get_labeled_object_data.json" 18EGL_STUBS_HEADER_PATH = "../src/libGLESv2/egl_stubs_autogen.h" 19EGL_EXT_STUBS_HEADER_PATH = "../src/libGLESv2/egl_ext_stubs_autogen.h" 20 21# List of GLES1 extensions for which we don't need to add Context.h decls. 22GLES1_NO_CONTEXT_DECL_EXTENSIONS = [ 23 "GL_OES_framebuffer_object", 24] 25 26# This is a list of exceptions for entry points which don't want to have 27# the EVENT macro. This is required for some debug marker entry points. 28NO_EVENT_MARKER_EXCEPTIONS_LIST = sorted([ 29 "glPushGroupMarkerEXT", 30 "glPopGroupMarkerEXT", 31 "glInsertEventMarkerEXT", 32]) 33 34# glRenderbufferStorageMultisampleEXT aliases glRenderbufferStorageMultisample on desktop GL, and is 35# marked as such in the registry. However, that is not correct for GLES where this entry point 36# comes from GL_EXT_multisampled_render_to_texture which is never promoted to core GLES. 37ALIASING_EXCEPTIONS = [ 38 'glRenderbufferStorageMultisampleEXT', 39 'renderbufferStorageMultisampleEXT', 40] 41 42# These are the entry points which potentially are used first by an application 43# and require that the back ends are initialized before the front end is called. 44INIT_DICT = { 45 "clGetPlatformIDs": "false", 46 "clGetPlatformInfo": "false", 47 "clGetDeviceIDs": "false", 48 "clCreateContext": "false", 49 "clCreateContextFromType": "false", 50 "clIcdGetPlatformIDsKHR": "true", 51} 52 53# Strip these suffixes from Context entry point names. NV is excluded (for now). 54STRIP_SUFFIXES = ["ANDROID", "ANGLE", "EXT", "KHR", "OES", "CHROMIUM", "OVR"] 55 56TEMPLATE_ENTRY_POINT_HEADER = """\ 57// GENERATED FILE - DO NOT EDIT. 58// Generated by {script_name} using data from {data_source_name}. 59// 60// Copyright 2020 The ANGLE Project Authors. All rights reserved. 61// Use of this source code is governed by a BSD-style license that can be 62// found in the LICENSE file. 63// 64// entry_points_{annotation_lower}_autogen.h: 65// Defines the {comment} entry points. 66 67#ifndef {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_ 68#define {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_ 69 70{includes} 71 72{entry_points} 73 74#endif // {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_ 75""" 76 77TEMPLATE_ENTRY_POINT_SOURCE = """\ 78// GENERATED FILE - DO NOT EDIT. 79// Generated by {script_name} using data from {data_source_name}. 80// 81// Copyright 2020 The ANGLE Project Authors. All rights reserved. 82// Use of this source code is governed by a BSD-style license that can be 83// found in the LICENSE file. 84// 85// entry_points_{annotation_lower}_autogen.cpp: 86// Defines the {comment} entry points. 87 88{includes} 89 90{entry_points} 91""" 92 93TEMPLATE_ENTRY_POINTS_ENUM_HEADER = """\ 94// GENERATED FILE - DO NOT EDIT. 95// Generated by {script_name} using data from {data_source_name}. 96// 97// Copyright 2020 The ANGLE Project Authors. All rights reserved. 98// Use of this source code is governed by a BSD-style license that can be 99// found in the LICENSE file. 100// 101// entry_points_enum_autogen.h: 102// Defines the {lib} entry points enumeration. 103 104#ifndef COMMON_ENTRYPOINTSENUM_AUTOGEN_H_ 105#define COMMON_ENTRYPOINTSENUM_AUTOGEN_H_ 106 107namespace angle 108{{ 109enum class EntryPoint 110{{ 111{entry_points_list} 112}}; 113 114const char *GetEntryPointName(EntryPoint ep); 115}} // namespace angle 116#endif // COMMON_ENTRY_POINTS_ENUM_AUTOGEN_H_ 117""" 118 119TEMPLATE_ENTRY_POINTS_NAME_CASE = """\ 120 case EntryPoint::{enum}: 121 return "{cmd}";""" 122 123TEMPLATE_ENTRY_POINTS_ENUM_SOURCE = """\ 124// GENERATED FILE - DO NOT EDIT. 125// Generated by {script_name} using data from {data_source_name}. 126// 127// Copyright 2020 The ANGLE Project Authors. All rights reserved. 128// Use of this source code is governed by a BSD-style license that can be 129// found in the LICENSE file. 130// 131// entry_points_enum_autogen.cpp: 132// Helper methods for the {lib} entry points enumeration. 133 134#include "common/entry_points_enum_autogen.h" 135 136#include "common/debug.h" 137 138namespace angle 139{{ 140const char *GetEntryPointName(EntryPoint ep) 141{{ 142 switch (ep) 143 {{ 144{entry_points_name_cases} 145 default: 146 UNREACHABLE(); 147 return "error"; 148 }} 149}} 150}} // namespace angle 151""" 152 153TEMPLATE_LIB_ENTRY_POINT_SOURCE = """\ 154// GENERATED FILE - DO NOT EDIT. 155// Generated by {script_name} using data from {data_source_name}. 156// 157// Copyright 2020 The ANGLE Project Authors. All rights reserved. 158// Use of this source code is governed by a BSD-style license that can be 159// found in the LICENSE file. 160// 161// {lib_name}_autogen.cpp: Implements the exported {lib_description} functions. 162 163{includes} 164extern "C" {{ 165{entry_points} 166}} // extern "C" 167""" 168 169TEMPLATE_ENTRY_POINT_DECL = """{angle_export}{return_type} {export_def} {name}({params});""" 170 171TEMPLATE_GLES_ENTRY_POINT_NO_RETURN = """\ 172void GL_APIENTRY GL_{name}({params}) 173{{ 174 Context *context = {context_getter}; 175 {event_comment}EVENT(context, GL{name}, "context = %d{comma_if_needed}{format_params}", CID(context){comma_if_needed}{pass_params}); 176 177 if ({valid_context_check}) 178 {{{packed_gl_enum_conversions} 179 std::unique_lock<angle::GlobalMutex> shareContextLock = GetContextLock(context); 180 bool isCallValid = (context->skipValidation() || Validate{name}({validate_params})); 181 if (isCallValid) 182 {{ 183 context->{name_lower_no_suffix}({internal_params}); 184 }} 185 ANGLE_CAPTURE({name}, isCallValid, {capture_params}); 186 }} 187 else 188 {{ 189 {constext_lost_error_generator} 190 }} 191}} 192""" 193 194TEMPLATE_GLES_ENTRY_POINT_WITH_RETURN = """\ 195{return_type} GL_APIENTRY GL_{name}({params}) 196{{ 197 Context *context = {context_getter}; 198 {event_comment}EVENT(context, GL{name}, "context = %d{comma_if_needed}{format_params}", CID(context){comma_if_needed}{pass_params}); 199 200 {return_type} returnValue; 201 if ({valid_context_check}) 202 {{{packed_gl_enum_conversions} 203 std::unique_lock<angle::GlobalMutex> shareContextLock = GetContextLock(context); 204 bool isCallValid = (context->skipValidation() || Validate{name}({validate_params})); 205 if (isCallValid) 206 {{ 207 returnValue = context->{name_lower_no_suffix}({internal_params}); 208 }} 209 else 210 {{ 211 returnValue = GetDefaultReturnValue<angle::EntryPoint::GL{name}, {return_type}>(); 212 }} 213 ANGLE_CAPTURE({name}, isCallValid, {capture_params}, returnValue); 214 }} 215 else 216 {{ 217 {constext_lost_error_generator} 218 returnValue = GetDefaultReturnValue<angle::EntryPoint::GL{name}, {return_type}>(); 219 }} 220 return returnValue; 221}} 222""" 223 224TEMPLATE_EGL_ENTRY_POINT_NO_RETURN = """\ 225void EGLAPIENTRY EGL_{name}({params}) 226{{ 227 ANGLE_SCOPED_GLOBAL_LOCK(); 228 EGL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params}); 229 230 Thread *thread = egl::GetCurrentThread(); 231 232 {packed_gl_enum_conversions} 233 234 ANGLE_EGL_VALIDATE_VOID(thread, {name}, {labeled_object}, {internal_params}); 235 236 {name}(thread{comma_if_needed}{internal_params}); 237}} 238""" 239 240TEMPLATE_EGL_ENTRY_POINT_WITH_RETURN = """\ 241{return_type} EGLAPIENTRY EGL_{name}({params}) 242{{ 243 ANGLE_SCOPED_GLOBAL_LOCK(); 244 EGL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params}); 245 246 Thread *thread = egl::GetCurrentThread(); 247 248 {packed_gl_enum_conversions} 249 250 ANGLE_EGL_VALIDATE(thread, {name}, {labeled_object}, {return_type}{comma_if_needed}{internal_params}); 251 252 return {name}(thread{comma_if_needed}{internal_params}); 253}} 254""" 255 256TEMPLATE_CL_ENTRY_POINT_NO_RETURN = """\ 257void CL_API_CALL cl{name}({params}) 258{{ 259 CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params}); 260 261 {packed_gl_enum_conversions} 262 263 ANGLE_CL_VALIDATE_VOID({name}{comma_if_needed}{internal_params}); 264 265 {name}({internal_params}); 266}} 267""" 268 269TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_ERROR = """\ 270cl_int CL_API_CALL cl{name}({params}) 271{{{initialization} 272 CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params}); 273 274 {packed_gl_enum_conversions} 275 276 ANGLE_CL_VALIDATE_ERROR({name}{comma_if_needed}{internal_params}); 277 278 return {name}({internal_params}); 279}} 280""" 281 282TEMPLATE_CL_ENTRY_POINT_WITH_ERRCODE_RET = """\ 283{return_type} CL_API_CALL cl{name}({params}) 284{{{initialization} 285 CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params}); 286 287 {packed_gl_enum_conversions} 288 289 ANGLE_CL_VALIDATE_ERRCODE_RET({name}{comma_if_needed}{internal_params}); 290 291 cl_int errorCode = CL_SUCCESS; 292 {return_type} object = {name}({internal_params}, errorCode); 293 294 ASSERT((errorCode == CL_SUCCESS) == (object != nullptr)); 295 if (errcode_ret != nullptr) 296 {{ 297 *errcode_ret = errorCode; 298 }} 299 return object; 300}} 301""" 302 303TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_POINTER = """\ 304{return_type} CL_API_CALL cl{name}({params}) 305{{{initialization} 306 CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params}); 307 308 {packed_gl_enum_conversions} 309 310 ANGLE_CL_VALIDATE_POINTER({name}{comma_if_needed}{internal_params}); 311 312 return {name}({internal_params}); 313}} 314""" 315 316TEMPLATE_CL_STUBS_HEADER = """\ 317// GENERATED FILE - DO NOT EDIT. 318// Generated by {script_name} using data from {data_source_name}. 319// 320// Copyright 2021 The ANGLE Project Authors. All rights reserved. 321// Use of this source code is governed by a BSD-style license that can be 322// found in the LICENSE file. 323// 324// {annotation_lower}_stubs_autogen.h: Stubs for {title} entry points. 325 326#ifndef LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_ 327#define LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_ 328 329#include "libANGLE/CLtypes.h" 330 331namespace cl 332{{ 333{stubs} 334}} // namespace cl 335#endif // LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_ 336""" 337 338TEMPLATE_EGL_STUBS_HEADER = """\ 339// GENERATED FILE - DO NOT EDIT. 340// Generated by {script_name} using data from {data_source_name}. 341// 342// Copyright 2020 The ANGLE Project Authors. All rights reserved. 343// Use of this source code is governed by a BSD-style license that can be 344// found in the LICENSE file. 345// 346// {annotation_lower}_stubs_autogen.h: Stubs for {title} entry points. 347 348#ifndef LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_ 349#define LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_ 350 351#include <EGL/egl.h> 352#include <EGL/eglext.h> 353 354#include "common/PackedEGLEnums_autogen.h" 355 356namespace gl 357{{ 358class Context; 359}} // namespace gl 360 361namespace egl 362{{ 363class AttributeMap; 364class Device; 365class Display; 366class Image; 367class Stream; 368class Surface; 369class Sync; 370class Thread; 371struct Config; 372 373{stubs} 374}} // namespace egl 375#endif // LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_ 376""" 377 378CONTEXT_HEADER = """\ 379// GENERATED FILE - DO NOT EDIT. 380// Generated by {script_name} using data from {data_source_name}. 381// 382// Copyright 2020 The ANGLE Project Authors. All rights reserved. 383// Use of this source code is governed by a BSD-style license that can be 384// found in the LICENSE file. 385// 386// Context_{annotation_lower}_autogen.h: Creates a macro for interfaces in Context. 387 388#ifndef ANGLE_CONTEXT_{annotation_upper}_AUTOGEN_H_ 389#define ANGLE_CONTEXT_{annotation_upper}_AUTOGEN_H_ 390 391#define ANGLE_{annotation_upper}_CONTEXT_API \\ 392{interface} 393 394#endif // ANGLE_CONTEXT_API_{version}_AUTOGEN_H_ 395""" 396 397CONTEXT_DECL_FORMAT = """ {return_type} {name_lower_no_suffix}({internal_params}){maybe_const}; \\""" 398 399TEMPLATE_CL_ENTRY_POINT_EXPORT = """\ 400{return_type} CL_API_CALL cl{name}({params}) 401{{ 402 return cl::GetDispatch().cl{name}({internal_params}); 403}} 404""" 405 406TEMPLATE_GL_ENTRY_POINT_EXPORT = """\ 407{return_type} GL_APIENTRY gl{name}({params}) 408{{ 409 return GL_{name}({internal_params}); 410}} 411""" 412 413TEMPLATE_EGL_ENTRY_POINT_EXPORT = """\ 414{return_type} EGLAPIENTRY egl{name}({params}) 415{{ 416 EnsureEGLLoaded(); 417 return EGL_{name}({internal_params}); 418}} 419""" 420 421TEMPLATE_GLEXT_FUNCTION_POINTER = """typedef {return_type}(GL_APIENTRYP PFN{name_upper}PROC)({params});""" 422TEMPLATE_GLEXT_FUNCTION_PROTOTYPE = """{apicall} {return_type}GL_APIENTRY {name}({params});""" 423 424TEMPLATE_GL_VALIDATION_HEADER = """\ 425// GENERATED FILE - DO NOT EDIT. 426// Generated by {script_name} using data from {data_source_name}. 427// 428// Copyright 2020 The ANGLE Project Authors. All rights reserved. 429// Use of this source code is governed by a BSD-style license that can be 430// found in the LICENSE file. 431// 432// validation{annotation}_autogen.h: 433// Validation functions for the OpenGL {comment} entry points. 434 435#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 436#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 437 438#include "common/entry_points_enum_autogen.h" 439#include "common/PackedEnums.h" 440 441namespace gl 442{{ 443class Context; 444 445{prototypes} 446}} // namespace gl 447 448#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 449""" 450 451TEMPLATE_CL_VALIDATION_HEADER = """\ 452// GENERATED FILE - DO NOT EDIT. 453// Generated by {script_name} using data from {data_source_name}. 454// 455// Copyright 2021 The ANGLE Project Authors. All rights reserved. 456// Use of this source code is governed by a BSD-style license that can be 457// found in the LICENSE file. 458// 459// validation{annotation}_autogen.h: 460// Validation functions for the {comment} entry points. 461 462#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 463#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 464 465#include "libANGLE/validationCL.h" 466 467namespace cl 468{{ 469{prototypes} 470}} // namespace cl 471 472#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 473""" 474 475TEMPLATE_EGL_VALIDATION_HEADER = """\ 476// GENERATED FILE - DO NOT EDIT. 477// Generated by {script_name} using data from {data_source_name}. 478// 479// Copyright 2020 The ANGLE Project Authors. All rights reserved. 480// Use of this source code is governed by a BSD-style license that can be 481// found in the LICENSE file. 482// 483// validation{annotation}_autogen.h: 484// Validation functions for the {comment} entry points. 485 486#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 487#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 488 489#include "libANGLE/validationEGL.h" 490 491namespace egl 492{{ 493{prototypes} 494}} // namespace egl 495 496#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_ 497""" 498 499TEMPLATE_CAPTURE_HEADER = """\ 500// GENERATED FILE - DO NOT EDIT. 501// Generated by {script_name} using data from {data_source_name}. 502// 503// Copyright 2020 The ANGLE Project Authors. All rights reserved. 504// Use of this source code is governed by a BSD-style license that can be 505// found in the LICENSE file. 506// 507// capture_gles_{annotation_lower}_autogen.h: 508// Capture functions for the OpenGL ES {comment} entry points. 509 510#ifndef LIBANGLE_CAPTURE_GLES_{annotation_upper}_AUTOGEN_H_ 511#define LIBANGLE_CAPTURE_GLES_{annotation_upper}_AUTOGEN_H_ 512 513#include "common/PackedEnums.h" 514#include "libANGLE/capture/FrameCapture.h" 515 516namespace gl 517{{ 518{prototypes} 519}} // namespace gl 520 521#endif // LIBANGLE_CAPTURE_GLES_{annotation_upper}_AUTOGEN_H_ 522""" 523 524TEMPLATE_CAPTURE_SOURCE = """\ 525// GENERATED FILE - DO NOT EDIT. 526// Generated by {script_name} using data from {data_source_name}. 527// 528// Copyright 2020 The ANGLE Project Authors. All rights reserved. 529// Use of this source code is governed by a BSD-style license that can be 530// found in the LICENSE file. 531// 532// capture_gles_{annotation_with_dash}_autogen.cpp: 533// Capture functions for the OpenGL ES {comment} entry points. 534 535#include "libANGLE/capture/capture_gles_{annotation_with_dash}_autogen.h" 536 537#include "libANGLE/Context.h" 538#include "libANGLE/capture/FrameCapture.h" 539#include "libANGLE/capture/gl_enum_utils.h" 540#include "libANGLE/validation{annotation_no_dash}.h" 541 542using namespace angle; 543 544namespace gl 545{{ 546{capture_methods} 547}} // namespace gl 548""" 549 550TEMPLATE_CAPTURE_METHOD_WITH_RETURN_VALUE = """ 551CallCapture Capture{short_name}({params_with_type}, {return_value_type_original} returnValue) 552{{ 553 ParamBuffer paramBuffer; 554 555 {parameter_captures} 556 557 ParamCapture returnValueCapture("returnValue", ParamType::T{return_value_type_custom}); 558 InitParamValue(ParamType::T{return_value_type_custom}, returnValue, &returnValueCapture.value); 559 paramBuffer.addReturnValue(std::move(returnValueCapture)); 560 561 return CallCapture(angle::EntryPoint::GL{short_name}, std::move(paramBuffer)); 562}} 563""" 564 565TEMPLATE_CAPTURE_METHOD_NO_RETURN_VALUE = """ 566CallCapture Capture{short_name}({params_with_type}) 567{{ 568 ParamBuffer paramBuffer; 569 570 {parameter_captures} 571 572 return CallCapture(angle::EntryPoint::GL{short_name}, std::move(paramBuffer)); 573}} 574""" 575 576TEMPLATE_PARAMETER_CAPTURE_VALUE = """paramBuffer.addValueParam("{name}", ParamType::T{type}, {name});""" 577 578TEMPLATE_PARAMETER_CAPTURE_GL_ENUM = """paramBuffer.addEnumParam("{name}", GLenumGroup::{group}, ParamType::T{type}, {name});""" 579 580TEMPLATE_PARAMETER_CAPTURE_POINTER = """ 581 if (isCallValid) 582 {{ 583 ParamCapture {name}Param("{name}", ParamType::T{type}); 584 InitParamValue(ParamType::T{type}, {name}, &{name}Param.value); 585 {capture_name}({params}, &{name}Param); 586 paramBuffer.addParam(std::move({name}Param)); 587 }} 588 else 589 {{ 590 ParamCapture {name}Param("{name}", ParamType::T{type}); 591 InitParamValue(ParamType::T{type}, static_cast<{cast_type}>(nullptr), &{name}Param.value); 592 paramBuffer.addParam(std::move({name}Param)); 593 }} 594""" 595 596TEMPLATE_PARAMETER_CAPTURE_POINTER_FUNC = """void {name}({params});""" 597 598TEMPLATE_CAPTURE_REPLAY_SOURCE = """\ 599// GENERATED FILE - DO NOT EDIT. 600// Generated by {script_name} using data from {data_source_name}. 601// 602// Copyright 2020 The ANGLE Project Authors. All rights reserved. 603// Use of this source code is governed by a BSD-style license that can be 604// found in the LICENSE file. 605// 606// frame_capture_replay_autogen.cpp: 607// Util function to dispatch captured GL calls through Context and replay them. 608 609#include "angle_gl.h" 610 611#include "common/debug.h" 612#include "common/debug.h" 613#include "libANGLE/Context.h" 614#include "libANGLE/Context.inl.h" 615#include "libANGLE/capture/FrameCapture.h" 616 617using namespace gl; 618 619namespace angle 620{{ 621 622void FrameCaptureShared::ReplayCall(gl::Context *context, 623 ReplayContext *replayContext, 624 const CallCapture &call) 625{{ 626 const ParamBuffer ¶ms = call.params; 627 switch (call.entryPoint) 628 {{ 629 {call_replay_cases} 630 default: 631 UNREACHABLE(); 632 }} 633}} 634 635}} // namespace angle 636 637""" 638 639TEMPLATE_CAPTURE_REPLAY_CALL_CASE = """case angle::EntryPoint::GL{entry_point}: 640 context->{context_call}({param_value_access});break;""" 641 642POINTER_FORMAT = "0x%016\" PRIxPTR \"" 643UNSIGNED_LONG_LONG_FORMAT = "%llu" 644HEX_LONG_LONG_FORMAT = "0x%llX" 645 646FORMAT_DICT = { 647 "GLbitfield": "%s", 648 "GLboolean": "%s", 649 "GLbyte": "%d", 650 "GLclampx": "0x%X", 651 "GLDEBUGPROC": POINTER_FORMAT, 652 "GLDEBUGPROCKHR": POINTER_FORMAT, 653 "GLdouble": "%f", 654 "GLeglClientBufferEXT": POINTER_FORMAT, 655 "GLeglImageOES": POINTER_FORMAT, 656 "GLenum": "%s", 657 "GLfixed": "0x%X", 658 "GLfloat": "%f", 659 "GLint": "%d", 660 "GLintptr": UNSIGNED_LONG_LONG_FORMAT, 661 "GLshort": "%d", 662 "GLsizei": "%d", 663 "GLsizeiptr": UNSIGNED_LONG_LONG_FORMAT, 664 "GLsync": POINTER_FORMAT, 665 "GLubyte": "%d", 666 "GLuint": "%u", 667 "GLuint64": UNSIGNED_LONG_LONG_FORMAT, 668 "GLushort": "%u", 669 "int": "%d", 670 # EGL-specific types 671 "EGLConfig": POINTER_FORMAT, 672 "EGLContext": POINTER_FORMAT, 673 "EGLDisplay": POINTER_FORMAT, 674 "EGLSurface": POINTER_FORMAT, 675 "EGLSync": POINTER_FORMAT, 676 "EGLNativeDisplayType": POINTER_FORMAT, 677 "EGLNativePixmapType": POINTER_FORMAT, 678 "EGLNativeWindowType": POINTER_FORMAT, 679 "EGLClientBuffer": POINTER_FORMAT, 680 "EGLenum": "0x%X", 681 "EGLint": "%d", 682 "EGLImage": POINTER_FORMAT, 683 "EGLTime": UNSIGNED_LONG_LONG_FORMAT, 684 "EGLGetBlobFuncANDROID": POINTER_FORMAT, 685 "EGLSetBlobFuncANDROID": POINTER_FORMAT, 686 "EGLuint64KHR": UNSIGNED_LONG_LONG_FORMAT, 687 "EGLSyncKHR": POINTER_FORMAT, 688 "EGLnsecsANDROID": UNSIGNED_LONG_LONG_FORMAT, 689 "EGLDeviceEXT": POINTER_FORMAT, 690 "EGLDEBUGPROCKHR": POINTER_FORMAT, 691 "EGLObjectKHR": POINTER_FORMAT, 692 "EGLLabelKHR": POINTER_FORMAT, 693 "EGLTimeKHR": UNSIGNED_LONG_LONG_FORMAT, 694 "EGLImageKHR": POINTER_FORMAT, 695 "EGLStreamKHR": POINTER_FORMAT, 696 "EGLFrameTokenANGLE": HEX_LONG_LONG_FORMAT, 697 # WGL-specific types 698 "BOOL": "%u", 699 "DWORD": POINTER_FORMAT, 700 "FLOAT": "%f", 701 "HDC": POINTER_FORMAT, 702 "HENHMETAFILE": POINTER_FORMAT, 703 "HGLRC": POINTER_FORMAT, 704 "LPCSTR": POINTER_FORMAT, 705 "LPGLYPHMETRICSFLOAT": POINTER_FORMAT, 706 "UINT": "%u", 707 # CL-specific types 708 "size_t": "%zu", 709 "cl_char": "%hhd", 710 "cl_uchar": "%hhu", 711 "cl_short": "%hd", 712 "cl_ushort": "%hu", 713 "cl_int": "%d", 714 "cl_uint": "%u", 715 "cl_long": "%lld", 716 "cl_ulong": "%llu", 717 "cl_half": "%hu", 718 "cl_float": "%f", 719 "cl_double": "%f", 720 "cl_platform_id": POINTER_FORMAT, 721 "cl_device_id": POINTER_FORMAT, 722 "cl_context": POINTER_FORMAT, 723 "cl_command_queue": POINTER_FORMAT, 724 "cl_mem": POINTER_FORMAT, 725 "cl_program": POINTER_FORMAT, 726 "cl_kernel": POINTER_FORMAT, 727 "cl_event": POINTER_FORMAT, 728 "cl_sampler": POINTER_FORMAT, 729 "cl_bool": "%u", 730 "cl_bitfield": "%llu", 731 "cl_properties": "%llu", 732 "cl_device_type": "%llu", 733 "cl_platform_info": "%u", 734 "cl_device_info": "%u", 735 "cl_device_fp_config": "%llu", 736 "cl_device_mem_cache_type": "%u", 737 "cl_device_local_mem_type": "%u", 738 "cl_device_exec_capabilities": "%llu", 739 "cl_device_svm_capabilities": "%llu", 740 "cl_command_queue_properties": "%llu", 741 "cl_device_partition_property": "%zu", 742 "cl_device_affinity_domain": "%llu", 743 "cl_context_properties": "%zu", 744 "cl_context_info": "%u", 745 "cl_queue_properties": "%llu", 746 "cl_command_queue_info": "%u", 747 "cl_channel_order": "%u", 748 "cl_channel_type": "%u", 749 "cl_mem_flags": "%llu", 750 "cl_svm_mem_flags": "%llu", 751 "cl_mem_object_type": "%u", 752 "cl_mem_info": "%u", 753 "cl_mem_migration_flags": "%llu", 754 "cl_mem_properties": "%llu", 755 "cl_image_info": "%u", 756 "cl_buffer_create_type": "%u", 757 "cl_addressing_mode": "%u", 758 "cl_filter_mode": "%u", 759 "cl_sampler_info": "%u", 760 "cl_map_flags": "%llu", 761 "cl_pipe_properties": "%zu", 762 "cl_pipe_info": "%u", 763 "cl_program_info": "%u", 764 "cl_program_build_info": "%u", 765 "cl_program_binary_type": "%u", 766 "cl_build_status": "%d", 767 "cl_kernel_info": "%u", 768 "cl_kernel_arg_info": "%u", 769 "cl_kernel_arg_address_qualifier": "%u", 770 "cl_kernel_arg_access_qualifier": "%u", 771 "cl_kernel_arg_type_qualifier": "%llu", 772 "cl_kernel_work_group_info": "%u", 773 "cl_kernel_sub_group_info": "%u", 774 "cl_event_info": "%u", 775 "cl_command_type": "%u", 776 "cl_profiling_info": "%u", 777 "cl_sampler_properties": "%llu", 778 "cl_kernel_exec_info": "%u", 779 "cl_device_atomic_capabilities": "%llu", 780 "cl_khronos_vendor_id": "%u", 781 "cl_version": "%u", 782 "cl_device_device_enqueue_capabilities": "%llu", 783} 784 785TEMPLATE_HEADER_INCLUDES = """\ 786#include <GLES{major}/gl{major}{minor}.h> 787#include <export.h>""" 788 789TEMPLATE_SOURCES_INCLUDES = """\ 790#include "libGLESv2/entry_points_{header_version}_autogen.h" 791 792#include "common/entry_points_enum_autogen.h" 793#include "libANGLE/Context.h" 794#include "libANGLE/Context.inl.h" 795#include "libANGLE/capture/capture_{header_version}_autogen.h" 796#include "libANGLE/capture/gl_enum_utils.h" 797#include "libANGLE/validation{validation_header_version}.h" 798#include "libANGLE/entry_points_utils.h" 799#include "libGLESv2/global_state.h" 800 801using namespace gl; 802""" 803 804GLES_EXT_HEADER_INCLUDES = TEMPLATE_HEADER_INCLUDES.format( 805 major="", minor="") + """ 806#include <GLES/glext.h> 807#include <GLES2/gl2.h> 808#include <GLES2/gl2ext.h> 809#include <GLES3/gl32.h> 810""" 811 812GLES_EXT_SOURCE_INCLUDES = TEMPLATE_SOURCES_INCLUDES.format( 813 header_version="gles_ext", validation_header_version="ESEXT") + """ 814#include "libANGLE/capture/capture_gles_1_0_autogen.h" 815#include "libANGLE/capture/capture_gles_2_0_autogen.h" 816#include "libANGLE/capture/capture_gles_3_0_autogen.h" 817#include "libANGLE/capture/capture_gles_3_1_autogen.h" 818#include "libANGLE/capture/capture_gles_3_2_autogen.h" 819#include "libANGLE/validationES1.h" 820#include "libANGLE/validationES2.h" 821#include "libANGLE/validationES3.h" 822#include "libANGLE/validationES31.h" 823#include "libANGLE/validationES32.h" 824 825using namespace gl; 826""" 827 828DESKTOP_GL_HEADER_INCLUDES = """\ 829#include <export.h> 830#include "angle_gl.h" 831""" 832 833TEMPLATE_DESKTOP_GL_SOURCE_INCLUDES = """\ 834#include "libGL/entry_points_{}_autogen.h" 835 836#include "libANGLE/Context.h" 837#include "libANGLE/Context.inl.h" 838#include "libANGLE/capture/gl_enum_utils.h" 839#include "libANGLE/validationEGL.h" 840#include "libANGLE/validationES.h" 841#include "libANGLE/validationES1.h" 842#include "libANGLE/validationES2.h" 843#include "libANGLE/validationES3.h" 844#include "libANGLE/validationES31.h" 845#include "libANGLE/validationES32.h" 846#include "libANGLE/validationESEXT.h" 847#include "libANGLE/validationGL{}_autogen.h" 848#include "libANGLE/entry_points_utils.h" 849#include "libGLESv2/global_state.h" 850 851using namespace gl; 852""" 853 854EGL_HEADER_INCLUDES = """\ 855#include <EGL/egl.h> 856#include <export.h> 857""" 858 859EGL_SOURCE_INCLUDES = """\ 860#include "libGLESv2/entry_points_egl_autogen.h" 861 862#include "libANGLE/entry_points_utils.h" 863#include "libANGLE/validationEGL_autogen.h" 864#include "libGLESv2/egl_stubs_autogen.h" 865#include "libGLESv2/global_state.h" 866 867using namespace egl; 868""" 869 870EGL_EXT_HEADER_INCLUDES = """\ 871#include <EGL/egl.h> 872#include <EGL/eglext.h> 873#include <export.h> 874""" 875 876EGL_EXT_SOURCE_INCLUDES = """\ 877#include "libGLESv2/entry_points_egl_ext_autogen.h" 878 879#include "libANGLE/entry_points_utils.h" 880#include "libANGLE/validationEGL_autogen.h" 881#include "libGLESv2/egl_ext_stubs_autogen.h" 882#include "libGLESv2/global_state.h" 883 884using namespace egl; 885""" 886 887LIBCL_EXPORT_INCLUDES = """ 888#include "libOpenCL/dispatch.h" 889""" 890 891LIBGLESV2_EXPORT_INCLUDES = """ 892#include "angle_gl.h" 893 894#include "libGLESv2/entry_points_gles_1_0_autogen.h" 895#include "libGLESv2/entry_points_gles_2_0_autogen.h" 896#include "libGLESv2/entry_points_gles_3_0_autogen.h" 897#include "libGLESv2/entry_points_gles_3_1_autogen.h" 898#include "libGLESv2/entry_points_gles_3_2_autogen.h" 899#include "libGLESv2/entry_points_gles_ext_autogen.h" 900 901#include "common/event_tracer.h" 902""" 903 904LIBGL_EXPORT_INCLUDES = """ 905#include "angle_gl.h" 906 907#include "libGL/entry_points_gl_1_autogen.h" 908#include "libGL/entry_points_gl_2_autogen.h" 909#include "libGL/entry_points_gl_3_autogen.h" 910#include "libGL/entry_points_gl_4_autogen.h" 911 912#include "common/event_tracer.h" 913""" 914 915LIBEGL_EXPORT_INCLUDES_AND_PREAMBLE = """ 916#include "anglebase/no_destructor.h" 917#include "common/system_utils.h" 918 919#include <memory> 920 921#if defined(ANGLE_USE_EGL_LOADER) 922# include "libEGL/egl_loader_autogen.h" 923#else 924# include "libGLESv2/entry_points_egl_autogen.h" 925# include "libGLESv2/entry_points_egl_ext_autogen.h" 926#endif // defined(ANGLE_USE_EGL_LOADER) 927 928namespace 929{ 930#if defined(ANGLE_USE_EGL_LOADER) 931bool gLoaded = false; 932 933std::unique_ptr<angle::Library> &EntryPointsLib() 934{ 935 static angle::base::NoDestructor<std::unique_ptr<angle::Library>> sEntryPointsLib; 936 return *sEntryPointsLib; 937} 938 939angle::GenericProc KHRONOS_APIENTRY GlobalLoad(const char *symbol) 940{ 941 return reinterpret_cast<angle::GenericProc>(EntryPointsLib()->getSymbol(symbol)); 942} 943 944void EnsureEGLLoaded() 945{ 946 if (gLoaded) 947 { 948 return; 949 } 950 951 EntryPointsLib().reset( 952 angle::OpenSharedLibrary(ANGLE_GLESV2_LIBRARY_NAME, angle::SearchType::ModuleDir)); 953 angle::LoadEGL_EGL(GlobalLoad); 954 if (!EGL_GetPlatformDisplay) 955 { 956 fprintf(stderr, "Error loading EGL entry points.\\n"); 957 } 958 else 959 { 960 gLoaded = true; 961 } 962} 963#else 964void EnsureEGLLoaded() {} 965#endif // defined(ANGLE_USE_EGL_LOADER) 966} // anonymous namespace 967""" 968 969LIBCL_HEADER_INCLUDES = """\ 970#include "angle_cl.h" 971""" 972 973LIBCL_SOURCE_INCLUDES = """\ 974#include "libGLESv2/entry_points_cl_autogen.h" 975 976#include "libANGLE/validationCL_autogen.h" 977#include "libGLESv2/cl_stubs_autogen.h" 978#include "libGLESv2/entry_points_cl_utils.h" 979""" 980 981TEMPLATE_EVENT_COMMENT = """\ 982 // Don't run the EVENT() macro on the EXT_debug_marker entry points. 983 // It can interfere with the debug events being set by the caller. 984 // """ 985 986TEMPLATE_CAPTURE_PROTO = "angle::CallCapture Capture%s(%s);" 987 988TEMPLATE_VALIDATION_PROTO = "%s Validate%s(%s);" 989 990TEMPLATE_WINDOWS_DEF_FILE = """\ 991; GENERATED FILE - DO NOT EDIT. 992; Generated by {script_name} using data from {data_source_name}. 993; 994; Copyright 2020 The ANGLE Project Authors. All rights reserved. 995; Use of this source code is governed by a BSD-style license that can be 996; found in the LICENSE file. 997LIBRARY {lib} 998EXPORTS 999{exports} 1000""" 1001 1002TEMPLATE_FRAME_CAPTURE_UTILS_HEADER = """\ 1003// GENERATED FILE - DO NOT EDIT. 1004// Generated by {script_name} using data from {data_source_name}. 1005// 1006// Copyright 2020 The ANGLE Project Authors. All rights reserved. 1007// Use of this source code is governed by a BSD-style license that can be 1008// found in the LICENSE file. 1009// 1010// frame_capture_utils_autogen.h: 1011// ANGLE Frame capture types and helper functions. 1012 1013#ifndef LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_ 1014#define LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_ 1015 1016#include "common/PackedEnums.h" 1017 1018namespace angle 1019{{ 1020enum class ParamType 1021{{ 1022 {param_types} 1023}}; 1024 1025constexpr uint32_t kParamTypeCount = {param_type_count}; 1026 1027union ParamValue 1028{{ 1029 {param_union_values} 1030}}; 1031 1032template <ParamType PType, typename T> 1033T GetParamVal(const ParamValue &value); 1034 1035{get_param_val_specializations} 1036 1037template <ParamType PType, typename T> 1038T GetParamVal(const ParamValue &value) 1039{{ 1040 UNREACHABLE(); 1041 return T(); 1042}} 1043 1044template <typename T> 1045T AccessParamValue(ParamType paramType, const ParamValue &value) 1046{{ 1047 switch (paramType) 1048 {{ 1049{access_param_value_cases} 1050 }} 1051 UNREACHABLE(); 1052 return T(); 1053}} 1054 1055template <ParamType PType, typename T> 1056void SetParamVal(T valueIn, ParamValue *valueOut); 1057 1058{set_param_val_specializations} 1059 1060template <ParamType PType, typename T> 1061void SetParamVal(T valueIn, ParamValue *valueOut) 1062{{ 1063 UNREACHABLE(); 1064}} 1065 1066template <typename T> 1067void InitParamValue(ParamType paramType, T valueIn, ParamValue *valueOut) 1068{{ 1069 switch (paramType) 1070 {{ 1071{init_param_value_cases} 1072 }} 1073}} 1074 1075struct CallCapture; 1076struct ParamCapture; 1077 1078void WriteParamCaptureReplay(std::ostream &os, const CallCapture &call, const ParamCapture ¶m); 1079const char *ParamTypeToString(ParamType paramType); 1080 1081enum class ResourceIDType 1082{{ 1083 {resource_id_types} 1084}}; 1085 1086ResourceIDType GetResourceIDTypeFromParamType(ParamType paramType); 1087const char *GetResourceIDTypeName(ResourceIDType resourceIDType); 1088 1089template <typename ResourceType> 1090struct GetResourceIDTypeFromType; 1091 1092{type_to_resource_id_type_structs} 1093}} // namespace angle 1094 1095#endif // LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_ 1096""" 1097 1098TEMPLATE_FRAME_CAPTURE_UTILS_SOURCE = """\ 1099// GENERATED FILE - DO NOT EDIT. 1100// Generated by {script_name} using data from {data_source_name}. 1101// 1102// Copyright 2020 The ANGLE Project Authors. All rights reserved. 1103// Use of this source code is governed by a BSD-style license that can be 1104// found in the LICENSE file. 1105// 1106// frame_capture_utils_autogen.cpp: 1107// ANGLE Frame capture types and helper functions. 1108 1109#include "libANGLE/capture/frame_capture_utils_autogen.h" 1110 1111#include "libANGLE/capture/FrameCapture.h" 1112 1113namespace angle 1114{{ 1115void WriteParamCaptureReplay(std::ostream &os, const CallCapture &call, const ParamCapture ¶m) 1116{{ 1117 switch (param.type) 1118 {{ 1119{write_param_type_to_stream_cases} 1120 default: 1121 os << "unknown"; 1122 break; 1123 }} 1124}} 1125 1126const char *ParamTypeToString(ParamType paramType) 1127{{ 1128 switch (paramType) 1129 {{ 1130{param_type_to_string_cases} 1131 default: 1132 UNREACHABLE(); 1133 return "unknown"; 1134 }} 1135}} 1136 1137ResourceIDType GetResourceIDTypeFromParamType(ParamType paramType) 1138{{ 1139 switch (paramType) 1140 {{ 1141{param_type_resource_id_cases} 1142 default: 1143 return ResourceIDType::InvalidEnum; 1144 }} 1145}} 1146 1147const char *GetResourceIDTypeName(ResourceIDType resourceIDType) 1148{{ 1149 switch (resourceIDType) 1150 {{ 1151{resource_id_type_name_cases} 1152 default: 1153 UNREACHABLE(); 1154 return "GetResourceIDTypeName error"; 1155 }} 1156}} 1157}} // namespace angle 1158""" 1159 1160TEMPLATE_GET_PARAM_VAL_SPECIALIZATION = """\ 1161template <> 1162inline {type} GetParamVal<ParamType::T{enum}, {type}>(const ParamValue &value) 1163{{ 1164 return value.{union_name}; 1165}}""" 1166 1167TEMPLATE_ACCESS_PARAM_VALUE_CASE = """\ 1168 case ParamType::T{enum}: 1169 return GetParamVal<ParamType::T{enum}, T>(value);""" 1170 1171TEMPLATE_SET_PARAM_VAL_SPECIALIZATION = """\ 1172template <> 1173inline void SetParamVal<ParamType::T{enum}>({type} valueIn, ParamValue *valueOut) 1174{{ 1175 valueOut->{union_name} = valueIn; 1176}}""" 1177 1178TEMPLATE_INIT_PARAM_VALUE_CASE = """\ 1179 case ParamType::T{enum}: 1180 SetParamVal<ParamType::T{enum}>(valueIn, valueOut); 1181 break;""" 1182 1183TEMPLATE_WRITE_PARAM_TYPE_TO_STREAM_CASE = """\ 1184 case ParamType::T{enum_in}: 1185 WriteParamValueReplay<ParamType::T{enum_out}>(os, call, param.value.{union_name}); 1186 break;""" 1187 1188TEMPLATE_PARAM_TYPE_TO_STRING_CASE = """\ 1189 case ParamType::T{enum}: 1190 return "{type}";""" 1191 1192TEMPLATE_PARAM_TYPE_TO_RESOURCE_ID_TYPE_CASE = """\ 1193 case ParamType::T{enum}: 1194 return ResourceIDType::{resource_id_type};""" 1195 1196TEMPLATE_RESOURCE_ID_TYPE_NAME_CASE = """\ 1197 case ResourceIDType::{resource_id_type}: 1198 return "{resource_id_type}";""" 1199 1200CL_PACKED_TYPES = { 1201 # Enums 1202 "cl_platform_info": "PlatformInfo", 1203 "cl_device_info": "DeviceInfo", 1204 "cl_context_info": "ContextInfo", 1205 "cl_command_queue_info": "CommandQueueInfo", 1206 "cl_mem_object_type": "MemObjectType", 1207 "cl_mem_info": "MemInfo", 1208 "cl_image_info": "ImageInfo", 1209 "cl_pipe_info": "PipeInfo", 1210 "cl_addressing_mode": "AddressingMode", 1211 "cl_filter_mode": "FilterMode", 1212 "cl_sampler_info": "SamplerInfo", 1213 "cl_program_info": "ProgramInfo", 1214 "cl_program_build_info": "ProgramBuildInfo", 1215 "cl_kernel_info": "KernelInfo", 1216 "cl_kernel_arg_info": "KernelArgInfo", 1217 "cl_kernel_work_group_info": "KernelWorkGroupInfo", 1218 "cl_kernel_sub_group_info": "KernelSubGroupInfo", 1219 "cl_kernel_exec_info": "KernelExecInfo", 1220 "cl_event_info": "EventInfo", 1221 "cl_profiling_info": "ProfilingInfo", 1222 # Bit fields 1223 "cl_device_type": "DeviceType", 1224 "cl_device_fp_config": "DeviceFpConfig", 1225 "cl_device_exec_capabilities": "DeviceExecCapabilities", 1226 "cl_device_svm_capabilities": "DeviceSvmCapabilities", 1227 "cl_command_queue_properties": "CommandQueueProperties", 1228 "cl_device_affinity_domain": "DeviceAffinityDomain", 1229 "cl_mem_flags": "MemFlags", 1230 "cl_svm_mem_flags": "SVM_MemFlags", 1231 "cl_mem_migration_flags": "MemMigrationFlags", 1232 "cl_map_flags": "MapFlags", 1233 "cl_kernel_arg_type_qualifier": "KernelArgTypeQualifier", 1234 "cl_device_atomic_capabilities": "DeviceAtomicCapabilities", 1235 "cl_device_device_enqueue_capabilities": "DeviceEnqueueCapabilities", 1236} 1237 1238EGL_PACKED_TYPES = { 1239 "EGLContext": "gl::Context *", 1240 "EGLConfig": "Config *", 1241 "EGLDeviceEXT": "Device *", 1242 # Needs an explicit namespace to avoid an X11 namespace collision. 1243 "EGLDisplay": "egl::Display *", 1244 "EGLImage": "Image *", 1245 "EGLImageKHR": "Image *", 1246 "EGLStreamKHR": "Stream *", 1247 "EGLSurface": "Surface *", 1248 "EGLSync": "Sync *", 1249 "EGLSyncKHR": "Sync *", 1250} 1251 1252 1253def is_aliasing_excepted(api, cmd_name): 1254 return api == apis.GLES and cmd_name in ALIASING_EXCEPTIONS 1255 1256 1257def entry_point_export(api): 1258 if api == apis.CL: 1259 return "" 1260 return "ANGLE_EXPORT " 1261 1262 1263def entry_point_prefix(api): 1264 if api == apis.CL: 1265 return "cl" 1266 if api == apis.GLES: 1267 return "GL_" 1268 return api + "_" 1269 1270 1271def get_api_entry_def(api): 1272 if api == apis.EGL: 1273 return "EGLAPIENTRY" 1274 elif api == apis.CL: 1275 return "CL_API_CALL" 1276 else: 1277 return "GL_APIENTRY" 1278 1279 1280def get_stubs_header_template(api): 1281 if api == apis.CL: 1282 return TEMPLATE_CL_STUBS_HEADER 1283 elif api == apis.EGL: 1284 return TEMPLATE_EGL_STUBS_HEADER 1285 else: 1286 return "" 1287 1288 1289def format_entry_point_decl(api, cmd_name, proto, params): 1290 comma_if_needed = ", " if len(params) > 0 else "" 1291 stripped = strip_api_prefix(cmd_name) 1292 return TEMPLATE_ENTRY_POINT_DECL.format( 1293 angle_export=entry_point_export(api), 1294 export_def=get_api_entry_def(api), 1295 name="%s%s" % (entry_point_prefix(api), stripped), 1296 return_type=proto[:-len(cmd_name)].strip(), 1297 params=", ".join(params), 1298 comma_if_needed=comma_if_needed) 1299 1300 1301# Returns index range of identifier in function parameter 1302def find_name_range(param): 1303 1304 def is_allowed_in_identifier(char): 1305 return char.isalpha() or char.isdigit() or char == "_" 1306 1307 # If type is a function declaration, only search in first parentheses 1308 left_paren = param.find("(") 1309 if left_paren >= 0: 1310 min = left_paren + 1 1311 end = param.index(")") 1312 else: 1313 min = 0 1314 end = len(param) 1315 1316 # Find last identifier in search range 1317 while end > min and not is_allowed_in_identifier(param[end - 1]): 1318 end -= 1 1319 if end == min: 1320 raise ValueError 1321 start = end - 1 1322 while start > min and is_allowed_in_identifier(param[start - 1]): 1323 start -= 1 1324 return start, end 1325 1326 1327def just_the_type(param): 1328 start, end = find_name_range(param) 1329 return param[:start].strip() + param[end:].strip() 1330 1331 1332def just_the_name(param): 1333 start, end = find_name_range(param) 1334 return param[start:end] 1335 1336 1337def make_param(param_type, param_name): 1338 1339 def insert_name(param_type, param_name, pos): 1340 return param_type[:pos] + " " + param_name + param_type[pos:] 1341 1342 # If type is a function declaration, insert identifier before first closing parentheses 1343 left_paren = param_type.find("(") 1344 if left_paren >= 0: 1345 right_paren = param_type.index(")") 1346 return insert_name(param_type, param_name, right_paren) 1347 1348 # If type is an array declaration, insert identifier before brackets 1349 brackets = param_type.find("[") 1350 if brackets >= 0: 1351 return insert_name(param_type, param_name, brackets) 1352 1353 # Otherwise just append identifier 1354 return param_type + " " + param_name 1355 1356 1357def just_the_type_packed(param, entry): 1358 name = just_the_name(param) 1359 if name in entry: 1360 return entry[name] 1361 else: 1362 return just_the_type(param) 1363 1364 1365def just_the_name_packed(param, reserved_set): 1366 name = just_the_name(param) 1367 if name in reserved_set: 1368 return name + 'Packed' 1369 else: 1370 return name 1371 1372 1373def is_unsigned_long_format(fmt): 1374 return fmt == UNSIGNED_LONG_LONG_FORMAT or fmt == HEX_LONG_LONG_FORMAT 1375 1376 1377def param_print_argument(command_node, param): 1378 name_only = just_the_name(param) 1379 type_only = just_the_type(param) 1380 1381 if "*" not in param and type_only not in FORMAT_DICT: 1382 print(" ".join(param)) 1383 raise Exception("Missing '%s %s' from '%s' entry point" % 1384 (type_only, name_only, registry_xml.get_cmd_name(command_node))) 1385 1386 if "*" in param or FORMAT_DICT[type_only] == POINTER_FORMAT: 1387 return "(uintptr_t)%s" % name_only 1388 1389 if is_unsigned_long_format(FORMAT_DICT[type_only]): 1390 return "static_cast<unsigned long long>(%s)" % name_only 1391 1392 if type_only == "GLboolean": 1393 return "GLbooleanToString(%s)" % name_only 1394 1395 if type_only == "GLbitfield": 1396 group_name = find_gl_enum_group_in_command(command_node, name_only) 1397 return "GLbitfieldToString(GLenumGroup::%s, %s).c_str()" % (group_name, name_only) 1398 1399 if type_only == "GLenum": 1400 group_name = find_gl_enum_group_in_command(command_node, name_only) 1401 return "GLenumToString(GLenumGroup::%s, %s)" % (group_name, name_only) 1402 1403 return name_only 1404 1405 1406def param_format_string(param): 1407 if "*" in param: 1408 return just_the_name(param) + " = 0x%016\" PRIxPTR \"" 1409 else: 1410 type_only = just_the_type(param) 1411 if type_only not in FORMAT_DICT: 1412 raise Exception(type_only + " is not a known type in 'FORMAT_DICT'") 1413 1414 return just_the_name(param) + " = " + FORMAT_DICT[type_only] 1415 1416 1417def is_context_lost_acceptable_cmd(cmd_name): 1418 lost_context_acceptable_cmds = [ 1419 "glGetError", 1420 "glGetSync", 1421 "glGetQueryObjecti", 1422 "glGetProgramiv", 1423 "glGetGraphicsResetStatus", 1424 "glGetShaderiv", 1425 ] 1426 1427 for context_lost_entry_pont in lost_context_acceptable_cmds: 1428 if cmd_name.startswith(context_lost_entry_pont): 1429 return True 1430 return False 1431 1432 1433def get_context_getter_function(cmd_name): 1434 if is_context_lost_acceptable_cmd(cmd_name): 1435 return "GetGlobalContext()" 1436 1437 return "GetValidGlobalContext()" 1438 1439 1440def get_valid_context_check(cmd_name): 1441 return "context" 1442 1443 1444def get_constext_lost_error_generator(cmd_name): 1445 # Don't generate context lost errors on commands that accept lost contexts 1446 if is_context_lost_acceptable_cmd(cmd_name): 1447 return "" 1448 1449 return "GenerateContextLostErrorOnCurrentGlobalContext();" 1450 1451 1452def strip_suffix(api, name): 1453 # For commands where aliasing is excepted, keep the suffix 1454 if is_aliasing_excepted(api, name): 1455 return name 1456 1457 for suffix in STRIP_SUFFIXES: 1458 if name.endswith(suffix): 1459 name = name[0:-len(suffix)] 1460 return name 1461 1462 1463def find_gl_enum_group_in_command(command_node, param_name): 1464 group_name = None 1465 for param_node in command_node.findall('./param'): 1466 if param_node.find('./name').text == param_name: 1467 group_name = param_node.attrib.get('group', None) 1468 break 1469 1470 if group_name is None or group_name in registry_xml.unsupported_enum_group_names: 1471 group_name = registry_xml.default_enum_group_name 1472 1473 return group_name 1474 1475 1476def get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types, params): 1477 # Always strip the suffix when querying packed enums. 1478 result = cmd_packed_gl_enums.get(strip_suffix(api, cmd_name), {}) 1479 for param in params: 1480 param_type = just_the_type(param) 1481 if param_type in packed_param_types: 1482 result[just_the_name(param)] = packed_param_types[param_type] 1483 return result 1484 1485 1486def get_def_template(api, return_type, has_errcode_ret): 1487 if return_type == "void": 1488 if api == apis.EGL: 1489 return TEMPLATE_EGL_ENTRY_POINT_NO_RETURN 1490 elif api == apis.CL: 1491 return TEMPLATE_CL_ENTRY_POINT_NO_RETURN 1492 else: 1493 return TEMPLATE_GLES_ENTRY_POINT_NO_RETURN 1494 elif return_type == "cl_int": 1495 return TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_ERROR 1496 else: 1497 if api == apis.EGL: 1498 return TEMPLATE_EGL_ENTRY_POINT_WITH_RETURN 1499 elif api == apis.CL: 1500 if has_errcode_ret: 1501 return TEMPLATE_CL_ENTRY_POINT_WITH_ERRCODE_RET 1502 else: 1503 return TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_POINTER 1504 else: 1505 return TEMPLATE_GLES_ENTRY_POINT_WITH_RETURN 1506 1507 1508def format_entry_point_def(api, command_node, cmd_name, proto, params, cmd_packed_enums, 1509 packed_param_types, ep_to_object): 1510 packed_enums = get_packed_enums(api, cmd_packed_enums, cmd_name, packed_param_types, params) 1511 internal_params = [just_the_name_packed(param, packed_enums) for param in params] 1512 if internal_params and internal_params[-1] == "errcode_ret": 1513 internal_params.pop() 1514 has_errcode_ret = True 1515 else: 1516 has_errcode_ret = False 1517 packed_gl_enum_conversions = [] 1518 for param in params: 1519 name = just_the_name(param) 1520 if name in packed_enums: 1521 internal_name = name + "Packed" 1522 internal_type = packed_enums[name] 1523 packed_gl_enum_conversions += [ 1524 "\n " + internal_type + " " + internal_name + " = PackParam<" + 1525 internal_type + ">(" + name + ");" 1526 ] 1527 1528 pass_params = [param_print_argument(command_node, param) for param in params] 1529 format_params = [param_format_string(param) for param in params] 1530 return_type = proto[:-len(cmd_name)].strip() 1531 initialization = "InitBackEnds(%s);\n" % INIT_DICT[cmd_name] if cmd_name in INIT_DICT else "" 1532 event_comment = TEMPLATE_EVENT_COMMENT if cmd_name in NO_EVENT_MARKER_EXCEPTIONS_LIST else "" 1533 name_lower_no_suffix = strip_suffix(api, cmd_name[2:3].lower() + cmd_name[3:]) 1534 entry_point_name = "angle::EntryPoint::GL" + strip_api_prefix(cmd_name) 1535 1536 format_params = { 1537 "name": 1538 strip_api_prefix(cmd_name), 1539 "name_lower_no_suffix": 1540 name_lower_no_suffix, 1541 "return_type": 1542 return_type, 1543 "params": 1544 ", ".join(params), 1545 "internal_params": 1546 ", ".join(internal_params), 1547 "initialization": 1548 initialization, 1549 "packed_gl_enum_conversions": 1550 "".join(packed_gl_enum_conversions), 1551 "pass_params": 1552 ", ".join(pass_params), 1553 "comma_if_needed": 1554 ", " if len(params) > 0 else "", 1555 "capture_params": 1556 ", ".join(["context"] + internal_params), 1557 "validate_params": 1558 ", ".join(["context"] + [entry_point_name] + internal_params), 1559 "format_params": 1560 ", ".join(format_params), 1561 "context_getter": 1562 get_context_getter_function(cmd_name), 1563 "valid_context_check": 1564 get_valid_context_check(cmd_name), 1565 "constext_lost_error_generator": 1566 get_constext_lost_error_generator(cmd_name), 1567 "event_comment": 1568 event_comment, 1569 "labeled_object": 1570 get_egl_entry_point_labeled_object(ep_to_object, cmd_name, params, packed_enums) 1571 } 1572 1573 template = get_def_template(api, return_type, has_errcode_ret) 1574 return template.format(**format_params) 1575 1576 1577def get_capture_param_type_name(param_type): 1578 pointer_count = param_type.count("*") 1579 is_const = "const" in param_type.split() 1580 1581 # EGL types are special 1582 for egl_type, angle_type in EGL_PACKED_TYPES.items(): 1583 if angle_type == param_type: 1584 return egl_type 1585 1586 param_type = param_type.replace("*", "") 1587 param_type = param_type.replace("&", "") 1588 param_type = param_type.replace("const", "") 1589 param_type = param_type.replace("struct", "") 1590 param_type = param_type.strip() 1591 1592 if "EGL" not in param_type: 1593 if is_const and param_type != 'AttributeMap': 1594 param_type += "Const" 1595 for x in range(pointer_count): 1596 param_type += "Pointer" 1597 1598 return param_type 1599 1600 1601def format_capture_method(api, command, cmd_name, proto, params, all_param_types, 1602 capture_pointer_funcs, cmd_packed_gl_enums, packed_param_types): 1603 1604 packed_gl_enums = get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types, 1605 params) 1606 1607 params_with_type = get_internal_params(api, cmd_name, 1608 ["const State &glState", "bool isCallValid"] + params, 1609 cmd_packed_gl_enums, packed_param_types) 1610 params_just_name = ", ".join( 1611 ["glState", "isCallValid"] + 1612 [just_the_name_packed(param, packed_gl_enums) for param in params]) 1613 1614 parameter_captures = [] 1615 for param in params: 1616 1617 param_name = just_the_name_packed(param, packed_gl_enums) 1618 param_type = just_the_type_packed(param, packed_gl_enums).strip() 1619 1620 # TODO(http://anglebug.com/4035: Add support for egl::AttributeMap. 1621 if 'AttributeMap' in param_type: 1622 # egl::AttributeMap is too complex for ParamCapture to handle it. 1623 continue 1624 1625 pointer_count = param_type.count("*") 1626 capture_param_type = get_capture_param_type_name(param_type) 1627 1628 if pointer_count > 0: 1629 params = params_just_name 1630 capture_name = "Capture%s_%s" % (strip_api_prefix(cmd_name), param_name) 1631 capture = TEMPLATE_PARAMETER_CAPTURE_POINTER.format( 1632 name=param_name, 1633 type=capture_param_type, 1634 capture_name=capture_name, 1635 params=params, 1636 cast_type=param_type) 1637 1638 capture_pointer_func = TEMPLATE_PARAMETER_CAPTURE_POINTER_FUNC.format( 1639 name=capture_name, params=params_with_type + ", angle::ParamCapture *paramCapture") 1640 capture_pointer_funcs += [capture_pointer_func] 1641 elif capture_param_type in ('GLenum', 'GLbitfield'): 1642 gl_enum_group = find_gl_enum_group_in_command(command, param_name) 1643 capture = TEMPLATE_PARAMETER_CAPTURE_GL_ENUM.format( 1644 name=param_name, type=capture_param_type, group=gl_enum_group) 1645 else: 1646 capture = TEMPLATE_PARAMETER_CAPTURE_VALUE.format( 1647 name=param_name, type=capture_param_type) 1648 1649 all_param_types.add(capture_param_type) 1650 1651 parameter_captures += [capture] 1652 1653 return_type = proto[:-len(cmd_name)].strip() 1654 1655 format_args = { 1656 "full_name": cmd_name, 1657 "short_name": strip_api_prefix(cmd_name), 1658 "params_with_type": params_with_type, 1659 "params_just_name": params_just_name, 1660 "parameter_captures": "\n ".join(parameter_captures), 1661 "return_value_type_original": return_type, 1662 "return_value_type_custom": get_capture_param_type_name(return_type) 1663 } 1664 1665 if return_type == "void": 1666 return TEMPLATE_CAPTURE_METHOD_NO_RETURN_VALUE.format(**format_args) 1667 else: 1668 return TEMPLATE_CAPTURE_METHOD_WITH_RETURN_VALUE.format(**format_args) 1669 1670 1671def const_pointer_type(param, packed_gl_enums): 1672 type = just_the_type_packed(param, packed_gl_enums) 1673 if just_the_name(param) == "errcode_ret" or "(" in type: 1674 return type 1675 elif "**" in type and "const" not in type: 1676 return type.replace("**", "* const *") 1677 elif "*" in type and "const" not in type: 1678 return type.replace("*", "*const ") if "[]" in type else "const " + type 1679 else: 1680 return type 1681 1682 1683def get_internal_params(api, cmd_name, params, cmd_packed_gl_enums, packed_param_types): 1684 packed_gl_enums = get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types, 1685 params) 1686 return ", ".join([ 1687 make_param( 1688 just_the_type_packed(param, packed_gl_enums), 1689 just_the_name_packed(param, packed_gl_enums)) for param in params 1690 ]) 1691 1692 1693def get_validation_params(api, cmd_name, params, cmd_packed_gl_enums, packed_param_types): 1694 packed_gl_enums = get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types, 1695 params) 1696 last = -1 if params and just_the_name(params[-1]) == "errcode_ret" else None 1697 return ", ".join([ 1698 make_param( 1699 const_pointer_type(param, packed_gl_enums), 1700 just_the_name_packed(param, packed_gl_enums)) for param in params[:last] 1701 ]) 1702 1703 1704def format_context_decl(api, cmd_name, proto, params, template, cmd_packed_gl_enums, 1705 packed_param_types): 1706 internal_params = get_internal_params(api, cmd_name, params, cmd_packed_gl_enums, 1707 packed_param_types) 1708 1709 return_type = proto[:-len(cmd_name)].strip() 1710 name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:] 1711 name_lower_no_suffix = strip_suffix(api, name_lower_no_suffix) 1712 maybe_const = " const" if name_lower_no_suffix.startswith( 1713 "is") and name_lower_no_suffix[2].isupper() else "" 1714 1715 return template.format( 1716 return_type=return_type, 1717 name_lower_no_suffix=name_lower_no_suffix, 1718 internal_params=internal_params, 1719 maybe_const=maybe_const) 1720 1721 1722def format_entry_point_export(cmd_name, proto, params, template): 1723 internal_params = [just_the_name(param) for param in params] 1724 return_type = proto[:-len(cmd_name)].strip() 1725 1726 return template.format( 1727 name=strip_api_prefix(cmd_name), 1728 return_type=return_type, 1729 params=", ".join(params), 1730 internal_params=", ".join(internal_params)) 1731 1732 1733def format_validation_proto(api, cmd_name, proto, params, cmd_packed_gl_enums, packed_param_types): 1734 if api == apis.CL: 1735 return_type = "cl_int" 1736 else: 1737 return_type = "bool" 1738 if api in [apis.GL, apis.GLES]: 1739 with_extra_params = ["Context *context"] + ["angle::EntryPoint entryPoint"] + params 1740 elif api == apis.EGL: 1741 with_extra_params = ["ValidationContext *val"] + params 1742 else: 1743 with_extra_params = params 1744 internal_params = get_validation_params(api, cmd_name, with_extra_params, cmd_packed_gl_enums, 1745 packed_param_types) 1746 return TEMPLATE_VALIDATION_PROTO % (return_type, strip_api_prefix(cmd_name), internal_params) 1747 1748 1749def format_capture_proto(api, cmd_name, proto, params, cmd_packed_gl_enums, packed_param_types): 1750 internal_params = get_internal_params(api, cmd_name, 1751 ["const State &glState", "bool isCallValid"] + params, 1752 cmd_packed_gl_enums, packed_param_types) 1753 return_type = proto[:-len(cmd_name)].strip() 1754 if return_type != "void": 1755 internal_params += ", %s returnValue" % return_type 1756 return TEMPLATE_CAPTURE_PROTO % (strip_api_prefix(cmd_name), internal_params) 1757 1758 1759def path_to(folder, file): 1760 return os.path.join(script_relative(".."), "src", folder, file) 1761 1762 1763class ANGLEEntryPoints(registry_xml.EntryPoints): 1764 1765 def __init__(self, 1766 api, 1767 xml, 1768 commands, 1769 all_param_types, 1770 cmd_packed_enums, 1771 export_template=TEMPLATE_GL_ENTRY_POINT_EXPORT, 1772 packed_param_types=[], 1773 ep_to_object={}): 1774 super().__init__(api, xml, commands) 1775 1776 self.decls = [] 1777 self.defs = [] 1778 self.export_defs = [] 1779 self.validation_protos = [] 1780 self.capture_protos = [] 1781 self.capture_methods = [] 1782 self.capture_pointer_funcs = [] 1783 1784 for (cmd_name, command_node, param_text, proto_text) in self.get_infos(): 1785 self.decls.append(format_entry_point_decl(self.api, cmd_name, proto_text, param_text)) 1786 self.defs.append( 1787 format_entry_point_def(self.api, command_node, cmd_name, proto_text, param_text, 1788 cmd_packed_enums, packed_param_types, ep_to_object)) 1789 1790 self.export_defs.append( 1791 format_entry_point_export(cmd_name, proto_text, param_text, export_template)) 1792 1793 self.validation_protos.append( 1794 format_validation_proto(self.api, cmd_name, proto_text, param_text, 1795 cmd_packed_enums, packed_param_types)) 1796 self.capture_protos.append( 1797 format_capture_proto(self.api, cmd_name, proto_text, param_text, cmd_packed_enums, 1798 packed_param_types)) 1799 self.capture_methods.append( 1800 format_capture_method(self.api, command_node, cmd_name, proto_text, param_text, 1801 all_param_types, self.capture_pointer_funcs, 1802 cmd_packed_enums, packed_param_types)) 1803 1804 1805class GLEntryPoints(ANGLEEntryPoints): 1806 1807 all_param_types = set() 1808 1809 def __init__(self, api, xml, commands): 1810 super().__init__(api, xml, commands, GLEntryPoints.all_param_types, 1811 GLEntryPoints.get_packed_enums()) 1812 1813 _packed_enums = None 1814 1815 @classmethod 1816 def get_packed_enums(cls): 1817 if not cls._packed_enums: 1818 with open(script_relative('entry_point_packed_gl_enums.json')) as f: 1819 cls._packed_enums = json.loads(f.read()) 1820 return cls._packed_enums 1821 1822 1823class EGLEntryPoints(ANGLEEntryPoints): 1824 1825 all_param_types = set() 1826 1827 def __init__(self, xml, commands): 1828 super().__init__( 1829 apis.EGL, 1830 xml, 1831 commands, 1832 EGLEntryPoints.all_param_types, 1833 EGLEntryPoints.get_packed_enums(), 1834 export_template=TEMPLATE_EGL_ENTRY_POINT_EXPORT, 1835 packed_param_types=EGL_PACKED_TYPES, 1836 ep_to_object=EGLEntryPoints._get_ep_to_object()) 1837 1838 _ep_to_object = None 1839 1840 @classmethod 1841 def _get_ep_to_object(cls): 1842 1843 if cls._ep_to_object: 1844 return cls._ep_to_object 1845 1846 with open(EGL_GET_LABELED_OBJECT_DATA_PATH) as f: 1847 try: 1848 spec_json = json.loads(f.read()) 1849 except ValueError: 1850 raise Exception("Could not decode JSON from %s" % EGL_GET_LABELED_OBJECT_DATA_PATH) 1851 1852 # Construct a mapping from EP to type. Fill in the gaps with Display/None. 1853 cls._ep_to_object = {} 1854 1855 for category, eps in spec_json.items(): 1856 if category == 'description': 1857 continue 1858 for ep in eps: 1859 cls._ep_to_object[ep] = category 1860 1861 return cls._ep_to_object 1862 1863 _packed_enums = None 1864 1865 @classmethod 1866 def get_packed_enums(cls): 1867 if not cls._packed_enums: 1868 with open(script_relative('entry_point_packed_egl_enums.json')) as f: 1869 cls._packed_enums = json.loads(f.read()) 1870 return cls._packed_enums 1871 1872 1873class CLEntryPoints(ANGLEEntryPoints): 1874 1875 all_param_types = set() 1876 1877 def __init__(self, xml, commands): 1878 super().__init__( 1879 apis.CL, 1880 xml, 1881 commands, 1882 CLEntryPoints.all_param_types, 1883 CLEntryPoints.get_packed_enums(), 1884 export_template=TEMPLATE_CL_ENTRY_POINT_EXPORT, 1885 packed_param_types=CL_PACKED_TYPES) 1886 1887 @classmethod 1888 def get_packed_enums(cls): 1889 return {} 1890 1891 1892def get_decls(api, 1893 formatter, 1894 all_commands, 1895 gles_commands, 1896 already_included, 1897 cmd_packed_gl_enums, 1898 packed_param_types=[]): 1899 decls = [] 1900 for command in all_commands: 1901 proto = command.find('proto') 1902 cmd_name = proto.find('name').text 1903 1904 if cmd_name not in gles_commands: 1905 continue 1906 1907 name_no_suffix = strip_suffix(api, cmd_name) 1908 if name_no_suffix in already_included: 1909 continue 1910 1911 param_text = ["".join(param.itertext()) for param in command.findall('param')] 1912 proto_text = "".join(proto.itertext()) 1913 decls.append( 1914 format_context_decl(api, cmd_name, proto_text, param_text, formatter, 1915 cmd_packed_gl_enums, packed_param_types)) 1916 1917 return decls 1918 1919 1920def get_glext_decls(all_commands, gles_commands, version): 1921 glext_ptrs = [] 1922 glext_protos = [] 1923 is_gles1 = False 1924 1925 if (version == ""): 1926 is_gles1 = True 1927 1928 for command in all_commands: 1929 proto = command.find('proto') 1930 cmd_name = proto.find('name').text 1931 1932 if cmd_name not in gles_commands: 1933 continue 1934 1935 param_text = ["".join(param.itertext()) for param in command.findall('param')] 1936 proto_text = "".join(proto.itertext()) 1937 1938 return_type = proto_text[:-len(cmd_name)] 1939 params = ", ".join(param_text) 1940 1941 format_params = { 1942 "apicall": "GL_API" if is_gles1 else "GL_APICALL", 1943 "name": cmd_name, 1944 "name_upper": cmd_name.upper(), 1945 "return_type": return_type, 1946 "params": params, 1947 } 1948 1949 glext_ptrs.append(TEMPLATE_GLEXT_FUNCTION_POINTER.format(**format_params)) 1950 glext_protos.append(TEMPLATE_GLEXT_FUNCTION_PROTOTYPE.format(**format_params)) 1951 1952 return glext_ptrs, glext_protos 1953 1954 1955def write_file(annotation, comment, template, entry_points, suffix, includes, lib, file): 1956 1957 content = template.format( 1958 script_name=os.path.basename(sys.argv[0]), 1959 data_source_name=file, 1960 annotation_lower=annotation.lower(), 1961 annotation_upper=annotation.upper(), 1962 comment=comment, 1963 lib=lib.upper(), 1964 includes=includes, 1965 entry_points=entry_points) 1966 1967 path = path_to(lib, "entry_points_{}_autogen.{}".format(annotation.lower(), suffix)) 1968 1969 with open(path, "w") as out: 1970 out.write(content) 1971 out.close() 1972 1973 1974def write_export_files(entry_points, includes, source, lib_name, lib_description): 1975 content = TEMPLATE_LIB_ENTRY_POINT_SOURCE.format( 1976 script_name=os.path.basename(sys.argv[0]), 1977 data_source_name=source, 1978 lib_name=lib_name, 1979 lib_description=lib_description, 1980 includes=includes, 1981 entry_points=entry_points) 1982 1983 path = path_to(lib_name, "{}_autogen.cpp".format(lib_name)) 1984 1985 with open(path, "w") as out: 1986 out.write(content) 1987 out.close() 1988 1989 1990def write_context_api_decls(decls, api): 1991 for (major, minor), version_decls in sorted(decls['core'].items()): 1992 if minor == "X": 1993 annotation = '{}_{}'.format(api, major) 1994 version = str(major) 1995 else: 1996 annotation = '{}_{}_{}'.format(api, major, minor) 1997 version = '{}_{}'.format(major, minor) 1998 content = CONTEXT_HEADER.format( 1999 annotation_lower=annotation.lower(), 2000 annotation_upper=annotation.upper(), 2001 script_name=os.path.basename(sys.argv[0]), 2002 data_source_name="gl.xml", 2003 version=version, 2004 interface="\n".join(version_decls)) 2005 2006 path = path_to("libANGLE", "Context_%s_autogen.h" % annotation.lower()) 2007 2008 with open(path, "w") as out: 2009 out.write(content) 2010 out.close() 2011 2012 if 'exts' in decls.keys(): 2013 interface_lines = [] 2014 for annotation in decls['exts'].keys(): 2015 interface_lines.append("\\\n /* " + annotation + " */ \\\n\\") 2016 2017 for extname in sorted(decls['exts'][annotation].keys()): 2018 interface_lines.append(" /* " + extname + " */ \\") 2019 interface_lines.extend(decls['exts'][annotation][extname]) 2020 2021 content = CONTEXT_HEADER.format( 2022 annotation_lower='gles_ext', 2023 annotation_upper='GLES_EXT', 2024 script_name=os.path.basename(sys.argv[0]), 2025 data_source_name="gl.xml", 2026 version='EXT', 2027 interface="\n".join(interface_lines)) 2028 2029 path = path_to("libANGLE", "Context_gles_ext_autogen.h") 2030 2031 with open(path, "w") as out: 2032 out.write(content) 2033 out.close() 2034 2035 2036def write_validation_header(annotation, comment, protos, source, template): 2037 content = template.format( 2038 script_name=os.path.basename(sys.argv[0]), 2039 data_source_name=source, 2040 annotation=annotation, 2041 comment=comment, 2042 prototypes="\n".join(protos)) 2043 2044 path = path_to("libANGLE", "validation%s_autogen.h" % annotation) 2045 2046 with open(path, "w") as out: 2047 out.write(content) 2048 out.close() 2049 2050 2051def write_gl_validation_header(annotation, comment, protos, source): 2052 return write_validation_header(annotation, comment, protos, source, 2053 TEMPLATE_GL_VALIDATION_HEADER) 2054 2055 2056def write_capture_header(annotation, comment, protos, capture_pointer_funcs): 2057 content = TEMPLATE_CAPTURE_HEADER.format( 2058 script_name=os.path.basename(sys.argv[0]), 2059 data_source_name="gl.xml and gl_angle_ext.xml", 2060 annotation_lower=annotation.lower(), 2061 annotation_upper=annotation.upper(), 2062 comment=comment, 2063 prototypes="\n".join(["\n// Method Captures\n"] + protos + ["\n// Parameter Captures\n"] + 2064 capture_pointer_funcs)) 2065 2066 path = path_to(os.path.join("libANGLE", "capture"), "capture_gles_%s_autogen.h" % annotation) 2067 2068 with open(path, "w") as out: 2069 out.write(content) 2070 out.close() 2071 2072 2073def write_capture_source(annotation_with_dash, annotation_no_dash, comment, capture_methods): 2074 content = TEMPLATE_CAPTURE_SOURCE.format( 2075 script_name=os.path.basename(sys.argv[0]), 2076 data_source_name="gl.xml and gl_angle_ext.xml", 2077 annotation_with_dash=annotation_with_dash, 2078 annotation_no_dash=annotation_no_dash, 2079 comment=comment, 2080 capture_methods="\n".join(capture_methods)) 2081 2082 path = path_to( 2083 os.path.join("libANGLE", "capture"), "capture_gles_%s_autogen.cpp" % annotation_with_dash) 2084 2085 with open(path, "w") as out: 2086 out.write(content) 2087 out.close() 2088 2089 2090def is_packed_enum_param_type(param_type): 2091 return param_type[0:2] != "GL" and "void" not in param_type 2092 2093 2094def add_namespace(param_type): 2095 param_type = param_type.strip() 2096 2097 if param_type == 'AHardwareBufferConstPointer' or param_type == 'charConstPointer': 2098 return param_type 2099 2100 if param_type[0:2] == "GL" or param_type[0:3] == "EGL" or "void" in param_type: 2101 return param_type 2102 2103 # ANGLE namespaced EGL types 2104 egl_namespace = [ 2105 'CompositorTiming', 2106 'DevicePointer', 2107 'ObjectType', 2108 'StreamPointer', 2109 'Timestamp', 2110 ] 2111 2112 if param_type in egl_namespace: 2113 return "egl::" + param_type 2114 else: 2115 return "gl::" + param_type 2116 2117 2118def get_gl_pointer_type(param_type): 2119 2120 if "ConstPointerPointer" in param_type: 2121 return "const " + param_type.replace("ConstPointerPointer", "") + " * const *" 2122 2123 if "ConstPointer" in param_type: 2124 return "const " + param_type.replace("ConstPointer", "") + " *" 2125 2126 if "PointerPointer" in param_type: 2127 return param_type.replace("PointerPointer", "") + " **" 2128 2129 if "Pointer" in param_type: 2130 return param_type.replace("Pointer", "") + " *" 2131 2132 return param_type 2133 2134 2135def get_param_type_type(param_type): 2136 param_type = add_namespace(param_type) 2137 return get_gl_pointer_type(param_type) 2138 2139 2140def get_gl_param_type_type(param_type): 2141 if not is_packed_enum_param_type(param_type): 2142 return get_gl_pointer_type(param_type) 2143 else: 2144 base_type = param_type.replace("Pointer", "").replace("Const", "") 2145 if base_type[-2:] == "ID": 2146 replace_type = "GLuint" 2147 else: 2148 replace_type = "GLenum" 2149 param_type = param_type.replace(base_type, replace_type) 2150 return get_gl_pointer_type(param_type) 2151 2152 2153def get_param_type_union_name(param_type): 2154 return param_type + "Val" 2155 2156 2157def format_param_type_union_type(param_type): 2158 return "%s %s;" % (get_param_type_type(param_type), get_param_type_union_name(param_type)) 2159 2160 2161def format_get_param_val_specialization(param_type): 2162 return TEMPLATE_GET_PARAM_VAL_SPECIALIZATION.format( 2163 enum=param_type, 2164 type=get_param_type_type(param_type), 2165 union_name=get_param_type_union_name(param_type)) 2166 2167 2168def format_access_param_value_case(param_type): 2169 return TEMPLATE_ACCESS_PARAM_VALUE_CASE.format(enum=param_type) 2170 2171 2172def format_set_param_val_specialization(param_type): 2173 return TEMPLATE_SET_PARAM_VAL_SPECIALIZATION.format( 2174 enum=param_type, 2175 type=get_param_type_type(param_type), 2176 union_name=get_param_type_union_name(param_type)) 2177 2178 2179def format_init_param_value_case(param_type): 2180 return TEMPLATE_INIT_PARAM_VALUE_CASE.format(enum=param_type) 2181 2182 2183def format_write_param_type_to_stream_case(param_type): 2184 return TEMPLATE_WRITE_PARAM_TYPE_TO_STREAM_CASE.format( 2185 enum_in=param_type, enum_out=param_type, union_name=get_param_type_union_name(param_type)) 2186 2187 2188def get_resource_id_types(all_param_types): 2189 return [ 2190 t[:-2] 2191 for t in filter(lambda t: t.endswith("ID") and not t.endswith("ANDROID"), all_param_types) 2192 ] 2193 2194 2195def format_resource_id_types(all_param_types): 2196 resource_id_types = get_resource_id_types(all_param_types) 2197 resource_id_types += ["EnumCount", "InvalidEnum = EnumCount"] 2198 resource_id_types = ",\n ".join(resource_id_types) 2199 return resource_id_types 2200 2201 2202def format_resource_id_convert_structs(all_param_types): 2203 templ = """\ 2204template <> 2205struct GetResourceIDTypeFromType<gl::%sID> 2206{ 2207 static constexpr ResourceIDType IDType = ResourceIDType::%s; 2208}; 2209""" 2210 resource_id_types = get_resource_id_types(all_param_types) 2211 convert_struct_strings = [templ % (id, id) for id in resource_id_types] 2212 return "\n".join(convert_struct_strings) 2213 2214 2215def write_capture_helper_header(all_param_types): 2216 2217 param_types = "\n ".join(["T%s," % t for t in all_param_types]) 2218 param_union_values = "\n ".join([format_param_type_union_type(t) for t in all_param_types]) 2219 get_param_val_specializations = "\n\n".join( 2220 [format_get_param_val_specialization(t) for t in all_param_types]) 2221 access_param_value_cases = "\n".join( 2222 [format_access_param_value_case(t) for t in all_param_types]) 2223 set_param_val_specializations = "\n\n".join( 2224 [format_set_param_val_specialization(t) for t in all_param_types]) 2225 init_param_value_cases = "\n".join([format_init_param_value_case(t) for t in all_param_types]) 2226 resource_id_types = format_resource_id_types(all_param_types) 2227 convert_structs = format_resource_id_convert_structs(all_param_types) 2228 2229 content = TEMPLATE_FRAME_CAPTURE_UTILS_HEADER.format( 2230 script_name=os.path.basename(sys.argv[0]), 2231 data_source_name="gl.xml and gl_angle_ext.xml", 2232 param_types=param_types, 2233 param_type_count=len(all_param_types), 2234 param_union_values=param_union_values, 2235 get_param_val_specializations=get_param_val_specializations, 2236 access_param_value_cases=access_param_value_cases, 2237 set_param_val_specializations=set_param_val_specializations, 2238 init_param_value_cases=init_param_value_cases, 2239 resource_id_types=resource_id_types, 2240 type_to_resource_id_type_structs=convert_structs) 2241 2242 path = path_to(os.path.join("libANGLE", "capture"), "frame_capture_utils_autogen.h") 2243 2244 with open(path, "w") as out: 2245 out.write(content) 2246 out.close() 2247 2248 2249def format_param_type_to_string_case(param_type): 2250 return TEMPLATE_PARAM_TYPE_TO_STRING_CASE.format( 2251 enum=param_type, type=get_gl_param_type_type(param_type)) 2252 2253 2254def get_resource_id_type_from_param_type(param_type): 2255 if param_type.endswith("ConstPointer"): 2256 return param_type.replace("ConstPointer", "")[:-2] 2257 if param_type.endswith("Pointer"): 2258 return param_type.replace("Pointer", "")[:-2] 2259 return param_type[:-2] 2260 2261 2262def format_param_type_to_resource_id_type_case(param_type): 2263 return TEMPLATE_PARAM_TYPE_TO_RESOURCE_ID_TYPE_CASE.format( 2264 enum=param_type, resource_id_type=get_resource_id_type_from_param_type(param_type)) 2265 2266 2267def format_param_type_resource_id_cases(all_param_types): 2268 id_types = filter( 2269 lambda t: (t.endswith("ID") and not t.endswith("ANDROID")) or t.endswith("IDConstPointer") 2270 or t.endswith("IDPointer"), all_param_types) 2271 return "\n".join([format_param_type_to_resource_id_type_case(t) for t in id_types]) 2272 2273 2274def format_resource_id_type_name_case(resource_id_type): 2275 return TEMPLATE_RESOURCE_ID_TYPE_NAME_CASE.format(resource_id_type=resource_id_type) 2276 2277 2278def write_capture_helper_source(all_param_types): 2279 2280 write_param_type_to_stream_cases = "\n".join( 2281 [format_write_param_type_to_stream_case(t) for t in all_param_types]) 2282 param_type_to_string_cases = "\n".join( 2283 [format_param_type_to_string_case(t) for t in all_param_types]) 2284 2285 param_type_resource_id_cases = format_param_type_resource_id_cases(all_param_types) 2286 2287 resource_id_types = get_resource_id_types(all_param_types) 2288 resource_id_type_name_cases = "\n".join( 2289 [format_resource_id_type_name_case(t) for t in resource_id_types]) 2290 2291 content = TEMPLATE_FRAME_CAPTURE_UTILS_SOURCE.format( 2292 script_name=os.path.basename(sys.argv[0]), 2293 data_source_name="gl.xml and gl_angle_ext.xml", 2294 write_param_type_to_stream_cases=write_param_type_to_stream_cases, 2295 param_type_to_string_cases=param_type_to_string_cases, 2296 param_type_resource_id_cases=param_type_resource_id_cases, 2297 resource_id_type_name_cases=resource_id_type_name_cases) 2298 2299 path = path_to(os.path.join("libANGLE", "capture"), "frame_capture_utils_autogen.cpp") 2300 2301 with open(path, "w") as out: 2302 out.write(content) 2303 out.close() 2304 2305 2306def get_command_params_text(command_node, cmd_name): 2307 param_text_list = list() 2308 for param_node in command_node.findall('param'): 2309 param_text_list.append("".join(param_node.itertext())) 2310 return param_text_list 2311 2312 2313def is_get_pointer_command(command_name): 2314 return command_name.endswith('Pointerv') and command_name.startswith('glGet') 2315 2316 2317def format_capture_replay_param_access(api, command_name, param_text_list, cmd_packed_gl_enums, 2318 packed_param_types): 2319 param_access_strs = list() 2320 cmd_packed_enums = get_packed_enums(api, cmd_packed_gl_enums, command_name, packed_param_types, 2321 param_text_list) 2322 for i, param_text in enumerate(param_text_list): 2323 param_type = just_the_type_packed(param_text, cmd_packed_enums) 2324 param_name = just_the_name_packed(param_text, cmd_packed_enums) 2325 2326 pointer_count = param_type.count('*') 2327 is_const = 'const' in param_type 2328 if pointer_count == 0: 2329 param_template = 'params.getParam("{name}", ParamType::T{enum_type}, {index}).value.{enum_type}Val' 2330 elif pointer_count == 1 and is_const: 2331 param_template = 'replayContext->getAsConstPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))' 2332 elif pointer_count == 2 and is_const: 2333 param_template = 'replayContext->getAsPointerConstPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))' 2334 elif pointer_count == 1 or (pointer_count == 2 and is_get_pointer_command(command_name)): 2335 param_template = 'replayContext->getReadBufferPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))' 2336 else: 2337 assert False, "Not supported param type %s" % param_type 2338 2339 param_access_strs.append( 2340 param_template.format( 2341 index=i, 2342 name=param_name, 2343 type=param_type, 2344 enum_type=get_capture_param_type_name(param_type))) 2345 return ",".join(param_access_strs) 2346 2347 2348def format_capture_replay_call_case(api, command_to_param_types_mapping, cmd_packed_gl_enums, 2349 packed_param_types): 2350 call_str_list = list() 2351 for command_name, cmd_param_texts in sorted(command_to_param_types_mapping.items()): 2352 entry_point_name = strip_api_prefix(command_name) 2353 2354 call_str_list.append( 2355 TEMPLATE_CAPTURE_REPLAY_CALL_CASE.format( 2356 entry_point=entry_point_name, 2357 param_value_access=format_capture_replay_param_access( 2358 api, command_name, cmd_param_texts, cmd_packed_gl_enums, packed_param_types), 2359 context_call=entry_point_name[0].lower() + entry_point_name[1:], 2360 )) 2361 2362 return '\n'.join(call_str_list) 2363 2364 2365def write_capture_replay_source(api, all_commands_nodes, gles_command_names, cmd_packed_gl_enums, 2366 packed_param_types): 2367 all_commands_names = set(gles_command_names) 2368 2369 command_to_param_types_mapping = dict() 2370 for command_node in all_commands_nodes: 2371 command_name = command_node.find('proto').find('name').text 2372 if command_name not in all_commands_names: 2373 continue 2374 2375 command_to_param_types_mapping[command_name] = get_command_params_text( 2376 command_node, command_name) 2377 2378 call_replay_cases = format_capture_replay_call_case(api, command_to_param_types_mapping, 2379 cmd_packed_gl_enums, packed_param_types) 2380 2381 source_content = TEMPLATE_CAPTURE_REPLAY_SOURCE.format( 2382 script_name=os.path.basename(sys.argv[0]), 2383 data_source_name="gl.xml and gl_angle_ext.xml", 2384 call_replay_cases=call_replay_cases, 2385 ) 2386 source_file_path = registry_xml.script_relative( 2387 "../src/libANGLE/capture/frame_capture_replay_autogen.cpp") 2388 with open(source_file_path, 'w') as f: 2389 f.write(source_content) 2390 2391 2392def write_windows_def_file(data_source_name, lib, libexport, folder, exports): 2393 2394 content = TEMPLATE_WINDOWS_DEF_FILE.format( 2395 script_name=os.path.basename(sys.argv[0]), 2396 data_source_name=data_source_name, 2397 exports="\n".join(exports), 2398 lib=libexport) 2399 2400 path = path_to(folder, "%s_autogen.def" % lib) 2401 2402 with open(path, "w") as out: 2403 out.write(content) 2404 out.close() 2405 2406 2407def get_exports(commands, fmt=None): 2408 if fmt: 2409 return [" %s" % fmt(cmd) for cmd in sorted(commands)] 2410 else: 2411 return [" %s" % cmd for cmd in sorted(commands)] 2412 2413 2414# Get EGL exports 2415def get_egl_exports(): 2416 2417 egl = registry_xml.RegistryXML('egl.xml', 'egl_angle_ext.xml') 2418 exports = [] 2419 2420 capser = lambda fn: "EGL_" + fn[3:] 2421 2422 for major, minor in registry_xml.EGL_VERSIONS: 2423 annotation = "{}_{}".format(major, minor) 2424 name_prefix = "EGL_VERSION_" 2425 2426 feature_name = "{}{}".format(name_prefix, annotation) 2427 2428 egl.AddCommands(feature_name, annotation) 2429 2430 commands = egl.commands[annotation] 2431 2432 if len(commands) == 0: 2433 continue 2434 2435 exports.append("\n ; EGL %d.%d" % (major, minor)) 2436 exports += get_exports(commands, capser) 2437 2438 egl.AddExtensionCommands(registry_xml.supported_egl_extensions, ['egl']) 2439 2440 for extension_name, ext_cmd_names in sorted(egl.ext_data.items()): 2441 2442 if len(ext_cmd_names) == 0: 2443 continue 2444 2445 exports.append("\n ; %s" % extension_name) 2446 exports += get_exports(ext_cmd_names, capser) 2447 2448 return exports 2449 2450 2451# Construct a mapping from an EGL EP to object function 2452def get_egl_entry_point_labeled_object(ep_to_object, cmd_stripped, params, packed_enums): 2453 2454 if not ep_to_object: 2455 return "" 2456 2457 # Finds a packed parameter name in a list of params 2458 def find_param(params, type_name, packed_enums): 2459 for param in params: 2460 if just_the_type_packed(param, packed_enums).split(' ')[0] == type_name: 2461 return just_the_name_packed(param, packed_enums) 2462 return None 2463 2464 display_param = find_param(params, "egl::Display", packed_enums) 2465 2466 # For entry points not listed in the JSON file, they default to an EGLDisplay or nothing. 2467 if cmd_stripped not in ep_to_object: 2468 if display_param: 2469 return "GetDisplayIfValid(%s)" % display_param 2470 return "nullptr" 2471 2472 # We first handle a few special cases for certain type categories. 2473 category = ep_to_object[cmd_stripped] 2474 if category == "Thread": 2475 return "GetThreadIfValid(thread)" 2476 found_param = find_param(params, category, packed_enums) 2477 if category == "Context" and not found_param: 2478 return "GetContextIfValid(thread->getDisplay(), thread->getContext())" 2479 assert found_param, "Did not find %s for %s: %s" % (category, cmd_stripped, str(params)) 2480 if category == "Device": 2481 return "GetDeviceIfValid(%s)" % found_param 2482 if category == "LabeledObject": 2483 object_type_param = find_param(params, "ObjectType", packed_enums) 2484 return "GetLabeledObjectIfValid(thread, %s, %s, %s)" % (display_param, object_type_param, 2485 found_param) 2486 2487 # We then handle the general case which handles the rest of the type categories. 2488 return "Get%sIfValid(%s, %s)" % (category, display_param, found_param) 2489 2490 2491def write_stubs_header(api, annotation, title, data_source, out_file, all_commands, commands, 2492 cmd_packed_egl_enums, packed_param_types): 2493 2494 stubs = [] 2495 2496 for command in all_commands: 2497 proto = command.find('proto') 2498 cmd_name = proto.find('name').text 2499 2500 if cmd_name not in commands: 2501 continue 2502 2503 proto_text = "".join(proto.itertext()) 2504 params = [] if api == apis.CL else ["Thread *thread"] 2505 params += ["".join(param.itertext()) for param in command.findall('param')] 2506 if params and just_the_name(params[-1]) == "errcode_ret": 2507 params[-1] = "cl_int &errorCode" 2508 return_type = proto_text[:-len(cmd_name)].strip() 2509 2510 internal_params = get_internal_params(api, cmd_name, params, cmd_packed_egl_enums, 2511 packed_param_types) 2512 2513 stubs.append("%s %s(%s);" % (return_type, strip_api_prefix(cmd_name), internal_params)) 2514 2515 args = { 2516 "annotation_lower": annotation.lower(), 2517 "annotation_upper": annotation.upper(), 2518 "data_source_name": data_source, 2519 "script_name": os.path.basename(sys.argv[0]), 2520 "stubs": "\n".join(stubs), 2521 "title": title, 2522 } 2523 2524 output = get_stubs_header_template(api).format(**args) 2525 2526 with open(out_file, "w") as f: 2527 f.write(output) 2528 2529 2530def main(): 2531 2532 # auto_script parameters. 2533 if len(sys.argv) > 1: 2534 inputs = [ 2535 'entry_point_packed_egl_enums.json', 'entry_point_packed_gl_enums.json', 2536 EGL_GET_LABELED_OBJECT_DATA_PATH 2537 ] + registry_xml.xml_inputs 2538 outputs = [ 2539 CL_STUBS_HEADER_PATH, 2540 EGL_STUBS_HEADER_PATH, 2541 EGL_EXT_STUBS_HEADER_PATH, 2542 '../src/libOpenCL/libOpenCL_autogen.cpp', 2543 '../src/common/entry_points_enum_autogen.cpp', 2544 '../src/common/entry_points_enum_autogen.h', 2545 '../src/libANGLE/Context_gl_1_autogen.h', 2546 '../src/libANGLE/Context_gl_2_autogen.h', 2547 '../src/libANGLE/Context_gl_3_autogen.h', 2548 '../src/libANGLE/Context_gl_4_autogen.h', 2549 '../src/libANGLE/Context_gles_1_0_autogen.h', 2550 '../src/libANGLE/Context_gles_2_0_autogen.h', 2551 '../src/libANGLE/Context_gles_3_0_autogen.h', 2552 '../src/libANGLE/Context_gles_3_1_autogen.h', 2553 '../src/libANGLE/Context_gles_3_2_autogen.h', 2554 '../src/libANGLE/Context_gles_ext_autogen.h', 2555 '../src/libANGLE/capture/capture_gles_1_0_autogen.cpp', 2556 '../src/libANGLE/capture/capture_gles_1_0_autogen.h', 2557 '../src/libANGLE/capture/capture_gles_2_0_autogen.cpp', 2558 '../src/libANGLE/capture/capture_gles_2_0_autogen.h', 2559 '../src/libANGLE/capture/capture_gles_3_0_autogen.cpp', 2560 '../src/libANGLE/capture/capture_gles_3_0_autogen.h', 2561 '../src/libANGLE/capture/capture_gles_3_1_autogen.cpp', 2562 '../src/libANGLE/capture/capture_gles_3_1_autogen.h', 2563 '../src/libANGLE/capture/capture_gles_3_2_autogen.cpp', 2564 '../src/libANGLE/capture/capture_gles_3_2_autogen.h', 2565 '../src/libANGLE/capture/capture_gles_ext_autogen.cpp', 2566 '../src/libANGLE/capture/capture_gles_ext_autogen.h', 2567 '../src/libANGLE/capture/frame_capture_replay_autogen.cpp', 2568 '../src/libANGLE/capture/frame_capture_utils_autogen.cpp', 2569 '../src/libANGLE/capture/frame_capture_utils_autogen.h', 2570 '../src/libANGLE/validationCL_autogen.h', 2571 '../src/libANGLE/validationEGL_autogen.h', 2572 '../src/libANGLE/validationES1_autogen.h', 2573 '../src/libANGLE/validationES2_autogen.h', 2574 '../src/libANGLE/validationES31_autogen.h', 2575 '../src/libANGLE/validationES32_autogen.h', 2576 '../src/libANGLE/validationES3_autogen.h', 2577 '../src/libANGLE/validationESEXT_autogen.h', 2578 '../src/libANGLE/validationGL1_autogen.h', 2579 '../src/libANGLE/validationGL2_autogen.h', 2580 '../src/libANGLE/validationGL3_autogen.h', 2581 '../src/libANGLE/validationGL4_autogen.h', 2582 '../src/libEGL/libEGL_autogen.cpp', 2583 '../src/libEGL/libEGL_autogen.def', 2584 '../src/libGLESv2/entry_points_cl_autogen.cpp', 2585 '../src/libGLESv2/entry_points_cl_autogen.h', 2586 '../src/libGLESv2/entry_points_egl_autogen.cpp', 2587 '../src/libGLESv2/entry_points_egl_autogen.h', 2588 '../src/libGLESv2/entry_points_egl_ext_autogen.cpp', 2589 '../src/libGLESv2/entry_points_egl_ext_autogen.h', 2590 '../src/libGLESv2/entry_points_gles_1_0_autogen.cpp', 2591 '../src/libGLESv2/entry_points_gles_1_0_autogen.h', 2592 '../src/libGLESv2/entry_points_gles_2_0_autogen.cpp', 2593 '../src/libGLESv2/entry_points_gles_2_0_autogen.h', 2594 '../src/libGLESv2/entry_points_gles_3_0_autogen.cpp', 2595 '../src/libGLESv2/entry_points_gles_3_0_autogen.h', 2596 '../src/libGLESv2/entry_points_gles_3_1_autogen.cpp', 2597 '../src/libGLESv2/entry_points_gles_3_1_autogen.h', 2598 '../src/libGLESv2/entry_points_gles_3_2_autogen.cpp', 2599 '../src/libGLESv2/entry_points_gles_3_2_autogen.h', 2600 '../src/libGLESv2/entry_points_gles_ext_autogen.cpp', 2601 '../src/libGLESv2/entry_points_gles_ext_autogen.h', 2602 '../src/libGLESv2/libGLESv2_autogen.cpp', 2603 '../src/libGLESv2/libGLESv2_autogen.def', 2604 '../src/libGLESv2/libGLESv2_no_capture_autogen.def', 2605 '../src/libGLESv2/libGLESv2_with_capture_autogen.def', 2606 '../src/libGL/entry_points_gl_1_autogen.cpp', 2607 '../src/libGL/entry_points_gl_1_autogen.h', 2608 '../src/libGL/entry_points_gl_2_autogen.cpp', 2609 '../src/libGL/entry_points_gl_2_autogen.h', 2610 '../src/libGL/entry_points_gl_3_autogen.cpp', 2611 '../src/libGL/entry_points_gl_3_autogen.h', 2612 '../src/libGL/entry_points_gl_4_autogen.cpp', 2613 '../src/libGL/entry_points_gl_4_autogen.h', 2614 '../src/libGL/libGL_autogen.cpp', 2615 '../src/libGL/libGL_autogen.def', 2616 ] 2617 2618 if sys.argv[1] == 'inputs': 2619 print(','.join(inputs)) 2620 elif sys.argv[1] == 'outputs': 2621 print(','.join(outputs)) 2622 else: 2623 print('Invalid script parameters') 2624 return 1 2625 return 0 2626 2627 glesdecls = {} 2628 glesdecls['core'] = {} 2629 glesdecls['exts'] = {} 2630 for ver in registry_xml.GLES_VERSIONS: 2631 glesdecls['core'][ver] = [] 2632 for ver in ['GLES1 Extensions', 'GLES2+ Extensions', 'ANGLE Extensions']: 2633 glesdecls['exts'][ver] = {} 2634 2635 libgles_ep_defs = [] 2636 libgles_ep_exports = [] 2637 2638 xml = registry_xml.RegistryXML('gl.xml', 'gl_angle_ext.xml') 2639 2640 # Stores core commands to keep track of duplicates 2641 all_commands_no_suffix = [] 2642 all_commands_with_suffix = [] 2643 2644 # First run through the main GLES entry points. Since ES2+ is the primary use 2645 # case, we go through those first and then add ES1-only APIs at the end. 2646 for major_version, minor_version in registry_xml.GLES_VERSIONS: 2647 version = "{}_{}".format(major_version, minor_version) 2648 annotation = "GLES_{}".format(version) 2649 name_prefix = "GL_ES_VERSION_" 2650 2651 if major_version == 1: 2652 name_prefix = "GL_VERSION_ES_CM_" 2653 2654 comment = version.replace("_", ".") 2655 feature_name = "{}{}".format(name_prefix, version) 2656 2657 xml.AddCommands(feature_name, version) 2658 2659 version_commands = xml.commands[version] 2660 all_commands_no_suffix.extend(xml.commands[version]) 2661 all_commands_with_suffix.extend(xml.commands[version]) 2662 2663 eps = GLEntryPoints(apis.GLES, xml, version_commands) 2664 eps.decls.insert(0, "extern \"C\" {") 2665 eps.decls.append("} // extern \"C\"") 2666 eps.defs.insert(0, "extern \"C\" {") 2667 eps.defs.append("} // extern \"C\"") 2668 2669 # Write the version as a comment before the first EP. 2670 libgles_ep_exports.append("\n ; OpenGL ES %s" % comment) 2671 2672 libgles_ep_defs += ["\n// OpenGL ES %s" % comment] + eps.export_defs 2673 libgles_ep_exports += get_exports(version_commands) 2674 2675 major_if_not_one = major_version if major_version != 1 else "" 2676 minor_if_not_zero = minor_version if minor_version != 0 else "" 2677 2678 header_includes = TEMPLATE_HEADER_INCLUDES.format( 2679 major=major_if_not_one, minor=minor_if_not_zero) 2680 2681 # We include the platform.h header since it undefines the conflicting MemoryBarrier macro. 2682 if major_version == 3 and minor_version == 1: 2683 header_includes += "\n#include \"common/platform.h\"\n" 2684 2685 version_annotation = "%s%s" % (major_version, minor_if_not_zero) 2686 source_includes = TEMPLATE_SOURCES_INCLUDES.format( 2687 header_version=annotation.lower(), validation_header_version="ES" + version_annotation) 2688 2689 write_file(annotation, "GLES " + comment, TEMPLATE_ENTRY_POINT_HEADER, 2690 "\n".join(eps.decls), "h", header_includes, "libGLESv2", "gl.xml") 2691 write_file(annotation, "GLES " + comment, TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(eps.defs), 2692 "cpp", source_includes, "libGLESv2", "gl.xml") 2693 2694 glesdecls['core'][(major_version, 2695 minor_version)] = get_decls(apis.GLES, CONTEXT_DECL_FORMAT, 2696 xml.all_commands, version_commands, [], 2697 GLEntryPoints.get_packed_enums()) 2698 2699 validation_annotation = "ES%s%s" % (major_version, minor_if_not_zero) 2700 write_gl_validation_header(validation_annotation, "ES %s" % comment, eps.validation_protos, 2701 "gl.xml and gl_angle_ext.xml") 2702 2703 write_capture_header(version, comment, eps.capture_protos, eps.capture_pointer_funcs) 2704 write_capture_source(version, validation_annotation, comment, eps.capture_methods) 2705 2706 # After we finish with the main entry points, we process the extensions. 2707 extension_decls = ["extern \"C\" {"] 2708 extension_defs = ["extern \"C\" {"] 2709 extension_commands = [] 2710 2711 # Accumulated validation prototypes. 2712 ext_validation_protos = [] 2713 ext_capture_protos = [] 2714 ext_capture_methods = [] 2715 ext_capture_pointer_funcs = [] 2716 2717 for gles1ext in registry_xml.gles1_extensions: 2718 glesdecls['exts']['GLES1 Extensions'][gles1ext] = [] 2719 for glesext in registry_xml.gles_extensions: 2720 glesdecls['exts']['GLES2+ Extensions'][glesext] = [] 2721 for angle_ext in registry_xml.angle_extensions: 2722 glesdecls['exts']['ANGLE Extensions'][angle_ext] = [] 2723 2724 xml.AddExtensionCommands(registry_xml.supported_extensions, ['gles2', 'gles1']) 2725 2726 for extension_name, ext_cmd_names in sorted(xml.ext_data.items()): 2727 extension_commands.extend(xml.ext_data[extension_name]) 2728 2729 # Detect and filter duplicate extensions. 2730 eps = GLEntryPoints(apis.GLES, xml, ext_cmd_names) 2731 2732 # Write the extension name as a comment before the first EP. 2733 comment = "\n// {}".format(extension_name) 2734 libgles_ep_exports.append("\n ; %s" % extension_name) 2735 2736 extension_defs += [comment] + eps.defs 2737 extension_decls += [comment] + eps.decls 2738 2739 # Avoid writing out entry points defined by a prior extension. 2740 for dupe in xml.ext_dupes[extension_name]: 2741 msg = "// {} is already defined.\n".format(strip_api_prefix(dupe)) 2742 extension_defs.append(msg) 2743 2744 ext_validation_protos += [comment] + eps.validation_protos 2745 ext_capture_protos += [comment] + eps.capture_protos 2746 ext_capture_methods += eps.capture_methods 2747 ext_capture_pointer_funcs += eps.capture_pointer_funcs 2748 2749 libgles_ep_defs += [comment] + eps.export_defs 2750 libgles_ep_exports += get_exports(ext_cmd_names) 2751 2752 if (extension_name in registry_xml.gles1_extensions and 2753 extension_name not in GLES1_NO_CONTEXT_DECL_EXTENSIONS): 2754 glesdecls['exts']['GLES1 Extensions'][extension_name] = get_decls( 2755 apis.GLES, CONTEXT_DECL_FORMAT, xml.all_commands, ext_cmd_names, 2756 all_commands_no_suffix, GLEntryPoints.get_packed_enums()) 2757 if extension_name in registry_xml.gles_extensions: 2758 glesdecls['exts']['GLES2+ Extensions'][extension_name] = get_decls( 2759 apis.GLES, CONTEXT_DECL_FORMAT, xml.all_commands, ext_cmd_names, 2760 all_commands_no_suffix, GLEntryPoints.get_packed_enums()) 2761 if extension_name in registry_xml.angle_extensions: 2762 glesdecls['exts']['ANGLE Extensions'][extension_name] = get_decls( 2763 apis.GLES, CONTEXT_DECL_FORMAT, xml.all_commands, ext_cmd_names, 2764 all_commands_no_suffix, GLEntryPoints.get_packed_enums()) 2765 2766 for name in extension_commands: 2767 all_commands_with_suffix.append(name) 2768 all_commands_no_suffix.append(strip_suffix(apis.GLES, name)) 2769 2770 # Now we generate entry points for the desktop implementation 2771 desktop_gl_decls = {} 2772 desktop_gl_decls['core'] = {} 2773 for major, _ in registry_xml.DESKTOP_GL_VERSIONS: 2774 desktop_gl_decls['core'][(major, "X")] = [] 2775 2776 libgl_ep_defs = [] 2777 libgl_ep_exports = [] 2778 2779 glxml = registry_xml.RegistryXML('gl.xml') 2780 2781 for major_version in sorted( 2782 set([major for (major, minor) in registry_xml.DESKTOP_GL_VERSIONS])): 2783 is_major = lambda ver: ver[0] == major_version 2784 2785 ver_decls = ["extern \"C\" {"] 2786 ver_defs = ["extern \"C\" {"] 2787 validation_protos = [] 2788 2789 for _, minor_version in filter(is_major, registry_xml.DESKTOP_GL_VERSIONS): 2790 version = "{}_{}".format(major_version, minor_version) 2791 annotation = "GL_{}".format(version) 2792 name_prefix = "GL_VERSION_" 2793 2794 comment = version.replace("_", ".") 2795 feature_name = "{}{}".format(name_prefix, version) 2796 2797 glxml.AddCommands(feature_name, version) 2798 2799 all_libgl_commands = glxml.commands[version] 2800 2801 just_libgl_commands = [ 2802 cmd for cmd in all_libgl_commands if cmd not in all_commands_no_suffix 2803 ] 2804 just_libgl_commands_suffix = [ 2805 cmd for cmd in all_libgl_commands if cmd not in all_commands_with_suffix 2806 ] 2807 2808 # Validation duplicates handled with suffix 2809 eps_suffix = GLEntryPoints(apis.GL, glxml, just_libgl_commands_suffix) 2810 eps = GLEntryPoints(apis.GL, glxml, all_libgl_commands) 2811 2812 desktop_gl_decls['core'][(major_version, 2813 "X")] += get_decls(apis.GL, CONTEXT_DECL_FORMAT, 2814 glxml.all_commands, just_libgl_commands, 2815 all_commands_no_suffix, 2816 GLEntryPoints.get_packed_enums()) 2817 2818 # Write the version as a comment before the first EP. 2819 cpp_comment = "\n// GL %s" % comment 2820 def_comment = "\n ; GL %s" % comment 2821 2822 libgl_ep_defs += [cpp_comment] + eps.export_defs 2823 libgl_ep_exports += [def_comment] + get_exports(all_libgl_commands) 2824 validation_protos += [cpp_comment] + eps_suffix.validation_protos 2825 ver_decls += [cpp_comment] + eps.decls 2826 ver_defs += [cpp_comment] + eps.defs 2827 2828 ver_decls.append("} // extern \"C\"") 2829 ver_defs.append("} // extern \"C\"") 2830 annotation = "GL_%d" % major_version 2831 name = "Desktop GL %s.x" % major_version 2832 2833 source_includes = TEMPLATE_DESKTOP_GL_SOURCE_INCLUDES.format(annotation.lower(), 2834 major_version) 2835 2836 # Entry point files 2837 write_file(annotation, name, TEMPLATE_ENTRY_POINT_HEADER, "\n".join(ver_decls), "h", 2838 DESKTOP_GL_HEADER_INCLUDES, "libGL", "gl.xml") 2839 write_file(annotation, name, TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(ver_defs), "cpp", 2840 source_includes, "libGL", "gl.xml") 2841 2842 # Validation files 2843 write_gl_validation_header("GL%s" % major_version, name, validation_protos, "gl.xml") 2844 2845 # OpenCL 2846 clxml = registry_xml.RegistryXML('cl.xml') 2847 2848 cl_validation_protos = [] 2849 cl_decls = ["namespace cl\n{"] 2850 cl_defs = ["namespace cl\n{"] 2851 libcl_ep_defs = [] 2852 libcl_windows_def_exports = [] 2853 cl_commands = [] 2854 2855 for major_version, minor_version in registry_xml.CL_VERSIONS: 2856 version = "%d_%d" % (major_version, minor_version) 2857 annotation = "CL_%s" % version 2858 name_prefix = "CL_VERSION_" 2859 2860 comment = version.replace("_", ".") 2861 feature_name = "%s%s" % (name_prefix, version) 2862 2863 clxml.AddCommands(feature_name, version) 2864 2865 cl_version_commands = clxml.commands[version] 2866 cl_commands += cl_version_commands 2867 2868 # Spec revs may have no new commands. 2869 if not cl_version_commands: 2870 continue 2871 2872 eps = CLEntryPoints(clxml, cl_version_commands) 2873 2874 comment = "\n// CL %d.%d" % (major_version, minor_version) 2875 win_def_comment = "\n ; CL %d.%d" % (major_version, minor_version) 2876 2877 cl_decls += [comment] + eps.decls 2878 cl_defs += [comment] + eps.defs 2879 libcl_ep_defs += [comment] + eps.export_defs 2880 cl_validation_protos += [comment] + eps.validation_protos 2881 libcl_windows_def_exports += [win_def_comment] + get_exports(clxml.commands[version]) 2882 2883 clxml.AddExtensionCommands(registry_xml.supported_cl_extensions, ['cl']) 2884 for extension_name, ext_cmd_names in sorted(clxml.ext_data.items()): 2885 2886 # Extensions may have no new commands. 2887 if not ext_cmd_names: 2888 continue 2889 2890 # Detect and filter duplicate extensions. 2891 eps = CLEntryPoints(clxml, ext_cmd_names) 2892 2893 comment = "\n// %s" % extension_name 2894 win_def_comment = "\n ; %s" % (extension_name) 2895 2896 cl_commands += ext_cmd_names 2897 2898 cl_decls += [comment] + eps.decls 2899 cl_defs += [comment] + eps.defs 2900 libcl_ep_defs += [comment] + eps.export_defs 2901 cl_validation_protos += [comment] + eps.validation_protos 2902 libcl_windows_def_exports += [win_def_comment] + get_exports(ext_cmd_names) 2903 2904 # Avoid writing out entry points defined by a prior extension. 2905 for dupe in clxml.ext_dupes[extension_name]: 2906 msg = "// %s is already defined.\n" % strip_api_prefix(dupe) 2907 cl_defs.append(msg) 2908 2909 cl_decls.append("} // namespace cl") 2910 cl_defs.append("} // namespace cl") 2911 2912 write_file("cl", "CL", TEMPLATE_ENTRY_POINT_HEADER, "\n".join(cl_decls), "h", 2913 LIBCL_HEADER_INCLUDES, "libGLESv2", "cl.xml") 2914 write_file("cl", "CL", TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(cl_defs), "cpp", 2915 LIBCL_SOURCE_INCLUDES, "libGLESv2", "cl.xml") 2916 write_validation_header("CL", "CL", cl_validation_protos, "cl.xml", 2917 TEMPLATE_CL_VALIDATION_HEADER) 2918 write_stubs_header("CL", "cl", "CL", "cl.xml", CL_STUBS_HEADER_PATH, clxml.all_commands, 2919 cl_commands, CLEntryPoints.get_packed_enums(), CL_PACKED_TYPES) 2920 2921 # EGL 2922 eglxml = registry_xml.RegistryXML('egl.xml', 'egl_angle_ext.xml') 2923 2924 egl_validation_protos = [] 2925 egl_decls = ["extern \"C\" {"] 2926 egl_defs = ["extern \"C\" {"] 2927 libegl_ep_defs = [] 2928 libegl_windows_def_exports = [] 2929 egl_commands = [] 2930 2931 for major_version, minor_version in registry_xml.EGL_VERSIONS: 2932 version = "%d_%d" % (major_version, minor_version) 2933 annotation = "EGL_%s" % version 2934 name_prefix = "EGL_VERSION_" 2935 2936 comment = version.replace("_", ".") 2937 feature_name = "%s%s" % (name_prefix, version) 2938 2939 eglxml.AddCommands(feature_name, version) 2940 2941 egl_version_commands = eglxml.commands[version] 2942 egl_commands += egl_version_commands 2943 2944 # Spec revs may have no new commands. 2945 if not egl_version_commands: 2946 continue 2947 2948 eps = EGLEntryPoints(eglxml, egl_version_commands) 2949 2950 comment = "\n// EGL %d.%d" % (major_version, minor_version) 2951 win_def_comment = "\n ; EGL %d.%d" % (major_version, minor_version) 2952 2953 egl_decls += [comment] + eps.decls 2954 egl_defs += [comment] + eps.defs 2955 libegl_ep_defs += [comment] + eps.export_defs 2956 egl_validation_protos += [comment] + eps.validation_protos 2957 libegl_windows_def_exports += [win_def_comment] + get_exports(eglxml.commands[version]) 2958 2959 egl_decls.append("} // extern \"C\"") 2960 egl_defs.append("} // extern \"C\"") 2961 2962 write_file("egl", "EGL", TEMPLATE_ENTRY_POINT_HEADER, "\n".join(egl_decls), "h", 2963 EGL_HEADER_INCLUDES, "libGLESv2", "egl.xml") 2964 write_file("egl", "EGL", TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(egl_defs), "cpp", 2965 EGL_SOURCE_INCLUDES, "libGLESv2", "egl.xml") 2966 write_stubs_header("EGL", "egl", "EGL", "egl.xml", EGL_STUBS_HEADER_PATH, eglxml.all_commands, 2967 egl_commands, EGLEntryPoints.get_packed_enums(), EGL_PACKED_TYPES) 2968 2969 eglxml.AddExtensionCommands(registry_xml.supported_egl_extensions, ['egl']) 2970 egl_ext_decls = ["extern \"C\" {"] 2971 egl_ext_defs = ["extern \"C\" {"] 2972 egl_ext_commands = [] 2973 2974 for extension_name, ext_cmd_names in sorted(eglxml.ext_data.items()): 2975 2976 # Extensions may have no new commands. 2977 if not ext_cmd_names: 2978 continue 2979 2980 # Detect and filter duplicate extensions. 2981 eps = EGLEntryPoints(eglxml, ext_cmd_names) 2982 2983 comment = "\n// %s" % extension_name 2984 win_def_comment = "\n ; %s" % (extension_name) 2985 2986 egl_ext_commands += ext_cmd_names 2987 2988 egl_ext_decls += [comment] + eps.decls 2989 egl_ext_defs += [comment] + eps.defs 2990 libegl_ep_defs += [comment] + eps.export_defs 2991 egl_validation_protos += [comment] + eps.validation_protos 2992 libegl_windows_def_exports += [win_def_comment] + get_exports(ext_cmd_names) 2993 2994 # Avoid writing out entry points defined by a prior extension. 2995 for dupe in eglxml.ext_dupes[extension_name]: 2996 msg = "// %s is already defined.\n" % strip_api_prefix(dupe) 2997 egl_ext_defs.append(msg) 2998 2999 egl_ext_decls.append("} // extern \"C\"") 3000 egl_ext_defs.append("} // extern \"C\"") 3001 3002 write_file("egl_ext", "EGL Extension", TEMPLATE_ENTRY_POINT_HEADER, "\n".join(egl_ext_decls), 3003 "h", EGL_EXT_HEADER_INCLUDES, "libGLESv2", "egl.xml and egl_angle_ext.xml") 3004 write_file("egl_ext", "EGL Extension", TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(egl_ext_defs), 3005 "cpp", EGL_EXT_SOURCE_INCLUDES, "libGLESv2", "egl.xml and egl_angle_ext.xml") 3006 write_validation_header("EGL", "EGL", egl_validation_protos, "egl.xml and egl_angle_ext.xml", 3007 TEMPLATE_EGL_VALIDATION_HEADER) 3008 write_stubs_header("EGL", "egl_ext", "EXT extension", "egl.xml and egl_angle_ext.xml", 3009 EGL_EXT_STUBS_HEADER_PATH, eglxml.all_commands, egl_ext_commands, 3010 EGLEntryPoints.get_packed_enums(), EGL_PACKED_TYPES) 3011 3012 # WGL 3013 wglxml = registry_xml.RegistryXML('wgl.xml') 3014 3015 name_prefix = "WGL_VERSION_" 3016 version = "1_0" 3017 comment = version.replace("_", ".") 3018 feature_name = "{}{}".format(name_prefix, version) 3019 wglxml.AddCommands(feature_name, version) 3020 wgl_commands = wglxml.commands[version] 3021 3022 wgl_commands = [cmd if cmd[:3] == 'wgl' else 'wgl' + cmd for cmd in wgl_commands] 3023 3024 # Write the version as a comment before the first EP. 3025 libgl_ep_exports.append("\n ; WGL %s" % comment) 3026 3027 # Other versions of these functions are used 3028 wgl_commands.remove("wglUseFontBitmaps") 3029 wgl_commands.remove("wglUseFontOutlines") 3030 3031 libgl_ep_exports += get_exports(wgl_commands) 3032 extension_decls.append("} // extern \"C\"") 3033 extension_defs.append("} // extern \"C\"") 3034 3035 write_file("gles_ext", "GLES extension", TEMPLATE_ENTRY_POINT_HEADER, 3036 "\n".join([item for item in extension_decls]), "h", GLES_EXT_HEADER_INCLUDES, 3037 "libGLESv2", "gl.xml and gl_angle_ext.xml") 3038 write_file("gles_ext", "GLES extension", TEMPLATE_ENTRY_POINT_SOURCE, 3039 "\n".join([item for item in extension_defs]), "cpp", GLES_EXT_SOURCE_INCLUDES, 3040 "libGLESv2", "gl.xml and gl_angle_ext.xml") 3041 3042 write_gl_validation_header("ESEXT", "ES extension", ext_validation_protos, 3043 "gl.xml and gl_angle_ext.xml") 3044 write_capture_header("ext", "extension", ext_capture_protos, ext_capture_pointer_funcs) 3045 write_capture_source("ext", "ESEXT", "extension", ext_capture_methods) 3046 3047 write_context_api_decls(glesdecls, "gles") 3048 write_context_api_decls(desktop_gl_decls, "gl") 3049 3050 # Entry point enum 3051 cl_cmd_names = [strip_api_prefix(cmd) for cmd in clxml.all_cmd_names.get_all_commands()] 3052 egl_cmd_names = [strip_api_prefix(cmd) for cmd in eglxml.all_cmd_names.get_all_commands()] 3053 gles_cmd_names = ["Invalid" 3054 ] + [strip_api_prefix(cmd) for cmd in xml.all_cmd_names.get_all_commands()] 3055 gl_cmd_names = [strip_api_prefix(cmd) for cmd in glxml.all_cmd_names.get_all_commands()] 3056 wgl_cmd_names = [strip_api_prefix(cmd) for cmd in wglxml.all_cmd_names.get_all_commands()] 3057 unsorted_enums = [("CL%s" % cmd, "cl%s" % cmd) for cmd in cl_cmd_names] + [ 3058 ("EGL%s" % cmd, "egl%s" % cmd) for cmd in egl_cmd_names 3059 ] + [("GL%s" % cmd, "gl%s" % cmd) for cmd in set(gles_cmd_names + gl_cmd_names) 3060 ] + [("WGL%s" % cmd, "wgl%s" % cmd) for cmd in wgl_cmd_names] 3061 all_enums = sorted(unsorted_enums) 3062 3063 entry_points_enum_header = TEMPLATE_ENTRY_POINTS_ENUM_HEADER.format( 3064 script_name=os.path.basename(sys.argv[0]), 3065 data_source_name="gl.xml and gl_angle_ext.xml", 3066 lib="GL/GLES", 3067 entry_points_list=",\n".join([" " + enum for (enum, _) in all_enums])) 3068 3069 entry_points_enum_header_path = path_to("common", "entry_points_enum_autogen.h") 3070 with open(entry_points_enum_header_path, "w") as out: 3071 out.write(entry_points_enum_header) 3072 out.close() 3073 3074 entry_points_cases = [ 3075 TEMPLATE_ENTRY_POINTS_NAME_CASE.format(enum=enum, cmd=cmd) for (enum, cmd) in all_enums 3076 ] 3077 entry_points_enum_source = TEMPLATE_ENTRY_POINTS_ENUM_SOURCE.format( 3078 script_name=os.path.basename(sys.argv[0]), 3079 data_source_name="gl.xml and gl_angle_ext.xml", 3080 lib="GL/GLES", 3081 entry_points_name_cases="\n".join(entry_points_cases)) 3082 3083 entry_points_enum_source_path = path_to("common", "entry_points_enum_autogen.cpp") 3084 with open(entry_points_enum_source_path, "w") as out: 3085 out.write(entry_points_enum_source) 3086 out.close() 3087 3088 write_export_files("\n".join([item for item in libgles_ep_defs]), LIBGLESV2_EXPORT_INCLUDES, 3089 "gl.xml and gl_angle_ext.xml", "libGLESv2", "OpenGL ES") 3090 write_export_files("\n".join([item for item in libgl_ep_defs]), LIBGL_EXPORT_INCLUDES, 3091 "gl.xml and wgl.xml", "libGL", "Windows GL") 3092 write_export_files("\n".join([item for item in libegl_ep_defs]), 3093 LIBEGL_EXPORT_INCLUDES_AND_PREAMBLE, "egl.xml and egl_angle_ext.xml", 3094 "libEGL", "EGL") 3095 write_export_files("\n".join([item for item in libcl_ep_defs]), LIBCL_EXPORT_INCLUDES, 3096 "cl.xml", "libOpenCL", "CL") 3097 3098 libgles_ep_exports += get_egl_exports() 3099 3100 everything = "Khronos and ANGLE XML files" 3101 3102 for lib in ["libGLESv2" + suffix for suffix in ["", "_no_capture", "_with_capture"]]: 3103 write_windows_def_file(everything, lib, lib, "libGLESv2", libgles_ep_exports) 3104 write_windows_def_file(everything, "libGL", "openGL32", "libGL", libgl_ep_exports) 3105 write_windows_def_file("egl.xml and egl_angle_ext.xml", "libEGL", "libEGL", "libEGL", 3106 libegl_windows_def_exports) 3107 3108 all_gles_param_types = sorted(GLEntryPoints.all_param_types) 3109 all_egl_param_types = sorted(EGLEntryPoints.all_param_types) 3110 # Get a sorted list of param types without duplicates 3111 all_param_types = sorted(list(set(all_gles_param_types + all_egl_param_types))) 3112 write_capture_helper_header(all_param_types) 3113 write_capture_helper_source(all_param_types) 3114 write_capture_replay_source(apis.GLES, xml.all_commands, all_commands_no_suffix, 3115 GLEntryPoints.get_packed_enums(), []) 3116 3117 3118if __name__ == '__main__': 3119 sys.exit(main()) 3120