Path: blob/main_old/scripts/generate_entry_points.py
1693 views
#!/usr/bin/python31#2# Copyright 2017 The ANGLE Project Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5#6# generate_entry_points.py:7# Generates the OpenGL bindings and entry point layers for ANGLE.8# NOTE: don't run this script directly. Run scripts/run_code_generation.py.910import sys, os, pprint, json11import registry_xml12from registry_xml import apis, script_relative, strip_api_prefix1314# Paths15CL_STUBS_HEADER_PATH = "../src/libGLESv2/cl_stubs_autogen.h"16EGL_GET_LABELED_OBJECT_DATA_PATH = "../src/libGLESv2/egl_get_labeled_object_data.json"17EGL_STUBS_HEADER_PATH = "../src/libGLESv2/egl_stubs_autogen.h"18EGL_EXT_STUBS_HEADER_PATH = "../src/libGLESv2/egl_ext_stubs_autogen.h"1920# List of GLES1 extensions for which we don't need to add Context.h decls.21GLES1_NO_CONTEXT_DECL_EXTENSIONS = [22"GL_OES_framebuffer_object",23]2425# This is a list of exceptions for entry points which don't want to have26# the EVENT macro. This is required for some debug marker entry points.27NO_EVENT_MARKER_EXCEPTIONS_LIST = sorted([28"glPushGroupMarkerEXT",29"glPopGroupMarkerEXT",30"glInsertEventMarkerEXT",31])3233# glRenderbufferStorageMultisampleEXT aliases glRenderbufferStorageMultisample on desktop GL, and is34# marked as such in the registry. However, that is not correct for GLES where this entry point35# comes from GL_EXT_multisampled_render_to_texture which is never promoted to core GLES.36ALIASING_EXCEPTIONS = [37'glRenderbufferStorageMultisampleEXT',38'renderbufferStorageMultisampleEXT',39]4041# These are the entry points which potentially are used first by an application42# and require that the back ends are initialized before the front end is called.43INIT_DICT = {44"clGetPlatformIDs": "false",45"clGetPlatformInfo": "false",46"clGetDeviceIDs": "false",47"clCreateContext": "false",48"clCreateContextFromType": "false",49"clIcdGetPlatformIDsKHR": "true",50}5152# Strip these suffixes from Context entry point names. NV is excluded (for now).53STRIP_SUFFIXES = ["ANDROID", "ANGLE", "EXT", "KHR", "OES", "CHROMIUM", "OVR"]5455TEMPLATE_ENTRY_POINT_HEADER = """\56// GENERATED FILE - DO NOT EDIT.57// Generated by {script_name} using data from {data_source_name}.58//59// Copyright 2020 The ANGLE Project Authors. All rights reserved.60// Use of this source code is governed by a BSD-style license that can be61// found in the LICENSE file.62//63// entry_points_{annotation_lower}_autogen.h:64// Defines the {comment} entry points.6566#ifndef {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_67#define {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_6869{includes}7071{entry_points}7273#endif // {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_74"""7576TEMPLATE_ENTRY_POINT_SOURCE = """\77// GENERATED FILE - DO NOT EDIT.78// Generated by {script_name} using data from {data_source_name}.79//80// Copyright 2020 The ANGLE Project Authors. All rights reserved.81// Use of this source code is governed by a BSD-style license that can be82// found in the LICENSE file.83//84// entry_points_{annotation_lower}_autogen.cpp:85// Defines the {comment} entry points.8687{includes}8889{entry_points}90"""9192TEMPLATE_ENTRY_POINTS_ENUM_HEADER = """\93// GENERATED FILE - DO NOT EDIT.94// Generated by {script_name} using data from {data_source_name}.95//96// Copyright 2020 The ANGLE Project Authors. All rights reserved.97// Use of this source code is governed by a BSD-style license that can be98// found in the LICENSE file.99//100// entry_points_enum_autogen.h:101// Defines the {lib} entry points enumeration.102103#ifndef COMMON_ENTRYPOINTSENUM_AUTOGEN_H_104#define COMMON_ENTRYPOINTSENUM_AUTOGEN_H_105106namespace angle107{{108enum class EntryPoint109{{110{entry_points_list}111}};112113const char *GetEntryPointName(EntryPoint ep);114}} // namespace angle115#endif // COMMON_ENTRY_POINTS_ENUM_AUTOGEN_H_116"""117118TEMPLATE_ENTRY_POINTS_NAME_CASE = """\119case EntryPoint::{enum}:120return "{cmd}";"""121122TEMPLATE_ENTRY_POINTS_ENUM_SOURCE = """\123// GENERATED FILE - DO NOT EDIT.124// Generated by {script_name} using data from {data_source_name}.125//126// Copyright 2020 The ANGLE Project Authors. All rights reserved.127// Use of this source code is governed by a BSD-style license that can be128// found in the LICENSE file.129//130// entry_points_enum_autogen.cpp:131// Helper methods for the {lib} entry points enumeration.132133#include "common/entry_points_enum_autogen.h"134135#include "common/debug.h"136137namespace angle138{{139const char *GetEntryPointName(EntryPoint ep)140{{141switch (ep)142{{143{entry_points_name_cases}144default:145UNREACHABLE();146return "error";147}}148}}149}} // namespace angle150"""151152TEMPLATE_LIB_ENTRY_POINT_SOURCE = """\153// GENERATED FILE - DO NOT EDIT.154// Generated by {script_name} using data from {data_source_name}.155//156// Copyright 2020 The ANGLE Project Authors. All rights reserved.157// Use of this source code is governed by a BSD-style license that can be158// found in the LICENSE file.159//160// {lib_name}_autogen.cpp: Implements the exported {lib_description} functions.161162{includes}163extern "C" {{164{entry_points}165}} // extern "C"166"""167168TEMPLATE_ENTRY_POINT_DECL = """{angle_export}{return_type} {export_def} {name}({params});"""169170TEMPLATE_GLES_ENTRY_POINT_NO_RETURN = """\171void GL_APIENTRY GL_{name}({params})172{{173Context *context = {context_getter};174{event_comment}EVENT(context, GL{name}, "context = %d{comma_if_needed}{format_params}", CID(context){comma_if_needed}{pass_params});175176if ({valid_context_check})177{{{packed_gl_enum_conversions}178std::unique_lock<angle::GlobalMutex> shareContextLock = GetContextLock(context);179bool isCallValid = (context->skipValidation() || Validate{name}({validate_params}));180if (isCallValid)181{{182context->{name_lower_no_suffix}({internal_params});183}}184ANGLE_CAPTURE({name}, isCallValid, {validate_params});185}}186else187{{188{constext_lost_error_generator}189}}190}}191"""192193TEMPLATE_GLES_ENTRY_POINT_WITH_RETURN = """\194{return_type} GL_APIENTRY GL_{name}({params})195{{196Context *context = {context_getter};197{event_comment}EVENT(context, GL{name}, "context = %d{comma_if_needed}{format_params}", CID(context){comma_if_needed}{pass_params});198199{return_type} returnValue;200if ({valid_context_check})201{{{packed_gl_enum_conversions}202std::unique_lock<angle::GlobalMutex> shareContextLock = GetContextLock(context);203bool isCallValid = (context->skipValidation() || Validate{name}({validate_params}));204if (isCallValid)205{{206returnValue = context->{name_lower_no_suffix}({internal_params});207}}208else209{{210returnValue = GetDefaultReturnValue<angle::EntryPoint::GL{name}, {return_type}>();211}}212ANGLE_CAPTURE({name}, isCallValid, {validate_params}, returnValue);213}}214else215{{216{constext_lost_error_generator}217returnValue = GetDefaultReturnValue<angle::EntryPoint::GL{name}, {return_type}>();218}}219return returnValue;220}}221"""222223TEMPLATE_EGL_ENTRY_POINT_NO_RETURN = """\224void EGLAPIENTRY EGL_{name}({params})225{{226ANGLE_SCOPED_GLOBAL_LOCK();227EGL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});228229Thread *thread = egl::GetCurrentThread();230231{packed_gl_enum_conversions}232233ANGLE_EGL_VALIDATE_VOID(thread, {name}, {labeled_object}, {internal_params});234235{name}(thread{comma_if_needed}{internal_params});236}}237"""238239TEMPLATE_EGL_ENTRY_POINT_WITH_RETURN = """\240{return_type} EGLAPIENTRY EGL_{name}({params})241{{242ANGLE_SCOPED_GLOBAL_LOCK();243EGL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});244245Thread *thread = egl::GetCurrentThread();246247{packed_gl_enum_conversions}248249ANGLE_EGL_VALIDATE(thread, {name}, {labeled_object}, {return_type}{comma_if_needed}{internal_params});250251return {name}(thread{comma_if_needed}{internal_params});252}}253"""254255TEMPLATE_CL_ENTRY_POINT_NO_RETURN = """\256void CL_API_CALL cl{name}({params})257{{258CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});259260{packed_gl_enum_conversions}261262ANGLE_CL_VALIDATE_VOID({name}{comma_if_needed}{internal_params});263264{name}({internal_params});265}}266"""267268TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_ERROR = """\269cl_int CL_API_CALL cl{name}({params})270{{{initialization}271CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});272273{packed_gl_enum_conversions}274275ANGLE_CL_VALIDATE_ERROR({name}{comma_if_needed}{internal_params});276277return {name}({internal_params});278}}279"""280281TEMPLATE_CL_ENTRY_POINT_WITH_ERRCODE_RET = """\282{return_type} CL_API_CALL cl{name}({params})283{{{initialization}284CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});285286{packed_gl_enum_conversions}287288ANGLE_CL_VALIDATE_ERRCODE_RET({name}{comma_if_needed}{internal_params});289290cl_int errorCode = CL_SUCCESS;291{return_type} object = {name}({internal_params}, errorCode);292293ASSERT((errorCode == CL_SUCCESS) == (object != nullptr));294if (errcode_ret != nullptr)295{{296*errcode_ret = errorCode;297}}298return object;299}}300"""301302TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_POINTER = """\303{return_type} CL_API_CALL cl{name}({params})304{{{initialization}305CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});306307{packed_gl_enum_conversions}308309ANGLE_CL_VALIDATE_POINTER({name}{comma_if_needed}{internal_params});310311return {name}({internal_params});312}}313"""314315TEMPLATE_CL_STUBS_HEADER = """\316// GENERATED FILE - DO NOT EDIT.317// Generated by {script_name} using data from {data_source_name}.318//319// Copyright 2021 The ANGLE Project Authors. All rights reserved.320// Use of this source code is governed by a BSD-style license that can be321// found in the LICENSE file.322//323// {annotation_lower}_stubs_autogen.h: Stubs for {title} entry points.324325#ifndef LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_326#define LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_327328#include "libANGLE/CLtypes.h"329330namespace cl331{{332{stubs}333}} // namespace cl334#endif // LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_335"""336337TEMPLATE_EGL_STUBS_HEADER = """\338// GENERATED FILE - DO NOT EDIT.339// Generated by {script_name} using data from {data_source_name}.340//341// Copyright 2020 The ANGLE Project Authors. All rights reserved.342// Use of this source code is governed by a BSD-style license that can be343// found in the LICENSE file.344//345// {annotation_lower}_stubs_autogen.h: Stubs for {title} entry points.346347#ifndef LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_348#define LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_349350#include <EGL/egl.h>351#include <EGL/eglext.h>352353#include "common/PackedEGLEnums_autogen.h"354355namespace gl356{{357class Context;358}} // namespace gl359360namespace egl361{{362class AttributeMap;363class Device;364class Display;365class Image;366class Stream;367class Surface;368class Sync;369class Thread;370struct Config;371372{stubs}373}} // namespace egl374#endif // LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_375"""376377CONTEXT_HEADER = """\378// GENERATED FILE - DO NOT EDIT.379// Generated by {script_name} using data from {data_source_name}.380//381// Copyright 2020 The ANGLE Project Authors. All rights reserved.382// Use of this source code is governed by a BSD-style license that can be383// found in the LICENSE file.384//385// Context_{annotation_lower}_autogen.h: Creates a macro for interfaces in Context.386387#ifndef ANGLE_CONTEXT_{annotation_upper}_AUTOGEN_H_388#define ANGLE_CONTEXT_{annotation_upper}_AUTOGEN_H_389390#define ANGLE_{annotation_upper}_CONTEXT_API \\391{interface}392393#endif // ANGLE_CONTEXT_API_{version}_AUTOGEN_H_394"""395396CONTEXT_DECL_FORMAT = """ {return_type} {name_lower_no_suffix}({internal_params}){maybe_const}; \\"""397398TEMPLATE_CL_ENTRY_POINT_EXPORT = """\399{return_type} CL_API_CALL cl{name}({params})400{{401return cl::GetDispatch().cl{name}({internal_params});402}}403"""404405TEMPLATE_GL_ENTRY_POINT_EXPORT = """\406{return_type} GL_APIENTRY gl{name}({params})407{{408return GL_{name}({internal_params});409}}410"""411412TEMPLATE_EGL_ENTRY_POINT_EXPORT = """\413{return_type} EGLAPIENTRY egl{name}({params})414{{415EnsureEGLLoaded();416return EGL_{name}({internal_params});417}}418"""419420TEMPLATE_GLEXT_FUNCTION_POINTER = """typedef {return_type}(GL_APIENTRYP PFN{name_upper}PROC)({params});"""421TEMPLATE_GLEXT_FUNCTION_PROTOTYPE = """{apicall} {return_type}GL_APIENTRY {name}({params});"""422423TEMPLATE_GL_VALIDATION_HEADER = """\424// GENERATED FILE - DO NOT EDIT.425// Generated by {script_name} using data from {data_source_name}.426//427// Copyright 2020 The ANGLE Project Authors. All rights reserved.428// Use of this source code is governed by a BSD-style license that can be429// found in the LICENSE file.430//431// validation{annotation}_autogen.h:432// Validation functions for the OpenGL {comment} entry points.433434#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_435#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_436437#include "common/PackedEnums.h"438439namespace gl440{{441class Context;442443{prototypes}444}} // namespace gl445446#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_447"""448449TEMPLATE_CL_VALIDATION_HEADER = """\450// GENERATED FILE - DO NOT EDIT.451// Generated by {script_name} using data from {data_source_name}.452//453// Copyright 2021 The ANGLE Project Authors. All rights reserved.454// Use of this source code is governed by a BSD-style license that can be455// found in the LICENSE file.456//457// validation{annotation}_autogen.h:458// Validation functions for the {comment} entry points.459460#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_461#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_462463#include "libANGLE/validationCL.h"464465namespace cl466{{467{prototypes}468}} // namespace cl469470#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_471"""472473TEMPLATE_EGL_VALIDATION_HEADER = """\474// GENERATED FILE - DO NOT EDIT.475// Generated by {script_name} using data from {data_source_name}.476//477// Copyright 2020 The ANGLE Project Authors. All rights reserved.478// Use of this source code is governed by a BSD-style license that can be479// found in the LICENSE file.480//481// validation{annotation}_autogen.h:482// Validation functions for the {comment} entry points.483484#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_485#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_486487#include "libANGLE/validationEGL.h"488489namespace egl490{{491{prototypes}492}} // namespace egl493494#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_495"""496497TEMPLATE_CAPTURE_HEADER = """\498// GENERATED FILE - DO NOT EDIT.499// Generated by {script_name} using data from {data_source_name}.500//501// Copyright 2020 The ANGLE Project Authors. All rights reserved.502// Use of this source code is governed by a BSD-style license that can be503// found in the LICENSE file.504//505// capture_gles_{annotation_lower}_autogen.h:506// Capture functions for the OpenGL ES {comment} entry points.507508#ifndef LIBANGLE_CAPTURE_GLES_{annotation_upper}_AUTOGEN_H_509#define LIBANGLE_CAPTURE_GLES_{annotation_upper}_AUTOGEN_H_510511#include "common/PackedEnums.h"512#include "libANGLE/capture/FrameCapture.h"513514namespace gl515{{516{prototypes}517}} // namespace gl518519#endif // LIBANGLE_CAPTURE_GLES_{annotation_upper}_AUTOGEN_H_520"""521522TEMPLATE_CAPTURE_SOURCE = """\523// GENERATED FILE - DO NOT EDIT.524// Generated by {script_name} using data from {data_source_name}.525//526// Copyright 2020 The ANGLE Project Authors. All rights reserved.527// Use of this source code is governed by a BSD-style license that can be528// found in the LICENSE file.529//530// capture_gles_{annotation_with_dash}_autogen.cpp:531// Capture functions for the OpenGL ES {comment} entry points.532533#include "libANGLE/capture/capture_gles_{annotation_with_dash}_autogen.h"534535#include "libANGLE/Context.h"536#include "libANGLE/capture/FrameCapture.h"537#include "libANGLE/capture/gl_enum_utils.h"538#include "libANGLE/validation{annotation_no_dash}.h"539540using namespace angle;541542namespace gl543{{544{capture_methods}545}} // namespace gl546"""547548TEMPLATE_CAPTURE_METHOD_WITH_RETURN_VALUE = """549CallCapture Capture{short_name}({params_with_type}, {return_value_type_original} returnValue)550{{551ParamBuffer paramBuffer;552553{parameter_captures}554555ParamCapture returnValueCapture("returnValue", ParamType::T{return_value_type_custom});556InitParamValue(ParamType::T{return_value_type_custom}, returnValue, &returnValueCapture.value);557paramBuffer.addReturnValue(std::move(returnValueCapture));558559return CallCapture(angle::EntryPoint::GL{short_name}, std::move(paramBuffer));560}}561"""562563TEMPLATE_CAPTURE_METHOD_NO_RETURN_VALUE = """564CallCapture Capture{short_name}({params_with_type})565{{566ParamBuffer paramBuffer;567568{parameter_captures}569570return CallCapture(angle::EntryPoint::GL{short_name}, std::move(paramBuffer));571}}572"""573574TEMPLATE_PARAMETER_CAPTURE_VALUE = """paramBuffer.addValueParam("{name}", ParamType::T{type}, {name});"""575576TEMPLATE_PARAMETER_CAPTURE_GL_ENUM = """paramBuffer.addEnumParam("{name}", GLenumGroup::{group}, ParamType::T{type}, {name});"""577578TEMPLATE_PARAMETER_CAPTURE_POINTER = """579if (isCallValid)580{{581ParamCapture {name}Param("{name}", ParamType::T{type});582InitParamValue(ParamType::T{type}, {name}, &{name}Param.value);583{capture_name}({params}, &{name}Param);584paramBuffer.addParam(std::move({name}Param));585}}586else587{{588ParamCapture {name}Param("{name}", ParamType::T{type});589InitParamValue(ParamType::T{type}, static_cast<{cast_type}>(nullptr), &{name}Param.value);590paramBuffer.addParam(std::move({name}Param));591}}592"""593594TEMPLATE_PARAMETER_CAPTURE_POINTER_FUNC = """void {name}({params});"""595596TEMPLATE_CAPTURE_REPLAY_SOURCE = """\597// GENERATED FILE - DO NOT EDIT.598// Generated by {script_name} using data from {data_source_name}.599//600// Copyright 2020 The ANGLE Project Authors. All rights reserved.601// Use of this source code is governed by a BSD-style license that can be602// found in the LICENSE file.603//604// frame_capture_replay_autogen.cpp:605// Util function to dispatch captured GL calls through Context and replay them.606607#include "angle_gl.h"608609#include "common/debug.h"610#include "common/debug.h"611#include "libANGLE/Context.h"612#include "libANGLE/Context.inl.h"613#include "libANGLE/capture/FrameCapture.h"614615using namespace gl;616617namespace angle618{{619620void FrameCaptureShared::ReplayCall(gl::Context *context,621ReplayContext *replayContext,622const CallCapture &call)623{{624const ParamBuffer ¶ms = call.params;625switch (call.entryPoint)626{{627{call_replay_cases}628default:629UNREACHABLE();630}}631}}632633}} // namespace angle634635"""636637TEMPLATE_CAPTURE_REPLAY_CALL_CASE = """case angle::EntryPoint::GL{entry_point}:638context->{context_call}({param_value_access});break;"""639640POINTER_FORMAT = "0x%016\" PRIxPTR \""641UNSIGNED_LONG_LONG_FORMAT = "%llu"642HEX_LONG_LONG_FORMAT = "0x%llX"643644FORMAT_DICT = {645"GLbitfield": "%s",646"GLboolean": "%s",647"GLbyte": "%d",648"GLclampx": "0x%X",649"GLDEBUGPROC": POINTER_FORMAT,650"GLDEBUGPROCKHR": POINTER_FORMAT,651"GLdouble": "%f",652"GLeglClientBufferEXT": POINTER_FORMAT,653"GLeglImageOES": POINTER_FORMAT,654"GLenum": "%s",655"GLfixed": "0x%X",656"GLfloat": "%f",657"GLint": "%d",658"GLintptr": UNSIGNED_LONG_LONG_FORMAT,659"GLshort": "%d",660"GLsizei": "%d",661"GLsizeiptr": UNSIGNED_LONG_LONG_FORMAT,662"GLsync": POINTER_FORMAT,663"GLubyte": "%d",664"GLuint": "%u",665"GLuint64": UNSIGNED_LONG_LONG_FORMAT,666"GLushort": "%u",667"int": "%d",668# EGL-specific types669"EGLConfig": POINTER_FORMAT,670"EGLContext": POINTER_FORMAT,671"EGLDisplay": POINTER_FORMAT,672"EGLSurface": POINTER_FORMAT,673"EGLSync": POINTER_FORMAT,674"EGLNativeDisplayType": POINTER_FORMAT,675"EGLNativePixmapType": POINTER_FORMAT,676"EGLNativeWindowType": POINTER_FORMAT,677"EGLClientBuffer": POINTER_FORMAT,678"EGLenum": "0x%X",679"EGLint": "%d",680"EGLImage": POINTER_FORMAT,681"EGLTime": UNSIGNED_LONG_LONG_FORMAT,682"EGLGetBlobFuncANDROID": POINTER_FORMAT,683"EGLSetBlobFuncANDROID": POINTER_FORMAT,684"EGLuint64KHR": UNSIGNED_LONG_LONG_FORMAT,685"EGLSyncKHR": POINTER_FORMAT,686"EGLnsecsANDROID": UNSIGNED_LONG_LONG_FORMAT,687"EGLDeviceEXT": POINTER_FORMAT,688"EGLDEBUGPROCKHR": POINTER_FORMAT,689"EGLObjectKHR": POINTER_FORMAT,690"EGLLabelKHR": POINTER_FORMAT,691"EGLTimeKHR": UNSIGNED_LONG_LONG_FORMAT,692"EGLImageKHR": POINTER_FORMAT,693"EGLStreamKHR": POINTER_FORMAT,694"EGLFrameTokenANGLE": HEX_LONG_LONG_FORMAT,695# WGL-specific types696"BOOL": "%u",697"DWORD": POINTER_FORMAT,698"FLOAT": "%f",699"HDC": POINTER_FORMAT,700"HENHMETAFILE": POINTER_FORMAT,701"HGLRC": POINTER_FORMAT,702"LPCSTR": POINTER_FORMAT,703"LPGLYPHMETRICSFLOAT": POINTER_FORMAT,704"UINT": "%u",705# CL-specific types706"size_t": "%zu",707"cl_char": "%hhd",708"cl_uchar": "%hhu",709"cl_short": "%hd",710"cl_ushort": "%hu",711"cl_int": "%d",712"cl_uint": "%u",713"cl_long": "%lld",714"cl_ulong": "%llu",715"cl_half": "%hu",716"cl_float": "%f",717"cl_double": "%f",718"cl_platform_id": POINTER_FORMAT,719"cl_device_id": POINTER_FORMAT,720"cl_context": POINTER_FORMAT,721"cl_command_queue": POINTER_FORMAT,722"cl_mem": POINTER_FORMAT,723"cl_program": POINTER_FORMAT,724"cl_kernel": POINTER_FORMAT,725"cl_event": POINTER_FORMAT,726"cl_sampler": POINTER_FORMAT,727"cl_bool": "%u",728"cl_bitfield": "%llu",729"cl_properties": "%llu",730"cl_device_type": "%llu",731"cl_platform_info": "%u",732"cl_device_info": "%u",733"cl_device_fp_config": "%llu",734"cl_device_mem_cache_type": "%u",735"cl_device_local_mem_type": "%u",736"cl_device_exec_capabilities": "%llu",737"cl_device_svm_capabilities": "%llu",738"cl_command_queue_properties": "%llu",739"cl_device_partition_property": "%zu",740"cl_device_affinity_domain": "%llu",741"cl_context_properties": "%zu",742"cl_context_info": "%u",743"cl_queue_properties": "%llu",744"cl_command_queue_info": "%u",745"cl_channel_order": "%u",746"cl_channel_type": "%u",747"cl_mem_flags": "%llu",748"cl_svm_mem_flags": "%llu",749"cl_mem_object_type": "%u",750"cl_mem_info": "%u",751"cl_mem_migration_flags": "%llu",752"cl_mem_properties": "%llu",753"cl_image_info": "%u",754"cl_buffer_create_type": "%u",755"cl_addressing_mode": "%u",756"cl_filter_mode": "%u",757"cl_sampler_info": "%u",758"cl_map_flags": "%llu",759"cl_pipe_properties": "%zu",760"cl_pipe_info": "%u",761"cl_program_info": "%u",762"cl_program_build_info": "%u",763"cl_program_binary_type": "%u",764"cl_build_status": "%d",765"cl_kernel_info": "%u",766"cl_kernel_arg_info": "%u",767"cl_kernel_arg_address_qualifier": "%u",768"cl_kernel_arg_access_qualifier": "%u",769"cl_kernel_arg_type_qualifier": "%llu",770"cl_kernel_work_group_info": "%u",771"cl_kernel_sub_group_info": "%u",772"cl_event_info": "%u",773"cl_command_type": "%u",774"cl_profiling_info": "%u",775"cl_sampler_properties": "%llu",776"cl_kernel_exec_info": "%u",777"cl_device_atomic_capabilities": "%llu",778"cl_khronos_vendor_id": "%u",779"cl_version": "%u",780"cl_device_device_enqueue_capabilities": "%llu",781}782783TEMPLATE_HEADER_INCLUDES = """\784#include <GLES{major}/gl{major}{minor}.h>785#include <export.h>"""786787TEMPLATE_SOURCES_INCLUDES = """\788#include "libGLESv2/entry_points_{header_version}_autogen.h"789790#include "common/entry_points_enum_autogen.h"791#include "libANGLE/Context.h"792#include "libANGLE/Context.inl.h"793#include "libANGLE/capture/capture_{header_version}_autogen.h"794#include "libANGLE/capture/gl_enum_utils.h"795#include "libANGLE/validation{validation_header_version}.h"796#include "libANGLE/entry_points_utils.h"797#include "libGLESv2/global_state.h"798799using namespace gl;800"""801802GLES_EXT_HEADER_INCLUDES = TEMPLATE_HEADER_INCLUDES.format(803major="", minor="") + """804#include <GLES/glext.h>805#include <GLES2/gl2.h>806#include <GLES2/gl2ext.h>807#include <GLES3/gl32.h>808"""809810GLES_EXT_SOURCE_INCLUDES = TEMPLATE_SOURCES_INCLUDES.format(811header_version="gles_ext", validation_header_version="ESEXT") + """812#include "libANGLE/capture/capture_gles_1_0_autogen.h"813#include "libANGLE/capture/capture_gles_2_0_autogen.h"814#include "libANGLE/capture/capture_gles_3_0_autogen.h"815#include "libANGLE/capture/capture_gles_3_1_autogen.h"816#include "libANGLE/capture/capture_gles_3_2_autogen.h"817#include "libANGLE/validationES1.h"818#include "libANGLE/validationES2.h"819#include "libANGLE/validationES3.h"820#include "libANGLE/validationES31.h"821#include "libANGLE/validationES32.h"822823using namespace gl;824"""825826DESKTOP_GL_HEADER_INCLUDES = """\827#include <export.h>828#include "angle_gl.h"829"""830831TEMPLATE_DESKTOP_GL_SOURCE_INCLUDES = """\832#include "libGL/entry_points_{}_autogen.h"833834#include "libANGLE/Context.h"835#include "libANGLE/Context.inl.h"836#include "libANGLE/capture/gl_enum_utils.h"837#include "libANGLE/validationEGL.h"838#include "libANGLE/validationES.h"839#include "libANGLE/validationES1.h"840#include "libANGLE/validationES2.h"841#include "libANGLE/validationES3.h"842#include "libANGLE/validationES31.h"843#include "libANGLE/validationES32.h"844#include "libANGLE/validationESEXT.h"845#include "libANGLE/validationGL{}_autogen.h"846#include "libANGLE/entry_points_utils.h"847#include "libGLESv2/global_state.h"848849using namespace gl;850"""851852EGL_HEADER_INCLUDES = """\853#include <EGL/egl.h>854#include <export.h>855"""856857EGL_SOURCE_INCLUDES = """\858#include "libGLESv2/entry_points_egl_autogen.h"859860#include "libANGLE/entry_points_utils.h"861#include "libANGLE/validationEGL_autogen.h"862#include "libGLESv2/egl_stubs_autogen.h"863#include "libGLESv2/global_state.h"864865using namespace egl;866"""867868EGL_EXT_HEADER_INCLUDES = """\869#include <EGL/egl.h>870#include <EGL/eglext.h>871#include <export.h>872"""873874EGL_EXT_SOURCE_INCLUDES = """\875#include "libGLESv2/entry_points_egl_ext_autogen.h"876877#include "libANGLE/entry_points_utils.h"878#include "libANGLE/validationEGL_autogen.h"879#include "libGLESv2/egl_ext_stubs_autogen.h"880#include "libGLESv2/global_state.h"881882using namespace egl;883"""884885LIBCL_EXPORT_INCLUDES = """886#include "libOpenCL/dispatch.h"887"""888889LIBGLESV2_EXPORT_INCLUDES = """890#include "angle_gl.h"891892#include "libGLESv2/entry_points_gles_1_0_autogen.h"893#include "libGLESv2/entry_points_gles_2_0_autogen.h"894#include "libGLESv2/entry_points_gles_3_0_autogen.h"895#include "libGLESv2/entry_points_gles_3_1_autogen.h"896#include "libGLESv2/entry_points_gles_3_2_autogen.h"897#include "libGLESv2/entry_points_gles_ext_autogen.h"898899#include "common/event_tracer.h"900"""901902LIBGL_EXPORT_INCLUDES = """903#include "angle_gl.h"904905#include "libGL/entry_points_gl_1_autogen.h"906#include "libGL/entry_points_gl_2_autogen.h"907#include "libGL/entry_points_gl_3_autogen.h"908#include "libGL/entry_points_gl_4_autogen.h"909910#include "common/event_tracer.h"911"""912913LIBEGL_EXPORT_INCLUDES_AND_PREAMBLE = """914#include "anglebase/no_destructor.h"915#include "common/system_utils.h"916917#include <memory>918919#if defined(ANGLE_USE_EGL_LOADER)920# include "libEGL/egl_loader_autogen.h"921#else922# include "libGLESv2/entry_points_egl_autogen.h"923# include "libGLESv2/entry_points_egl_ext_autogen.h"924#endif // defined(ANGLE_USE_EGL_LOADER)925926namespace927{928#if defined(ANGLE_USE_EGL_LOADER)929bool gLoaded = false;930931std::unique_ptr<angle::Library> &EntryPointsLib()932{933static angle::base::NoDestructor<std::unique_ptr<angle::Library>> sEntryPointsLib;934return *sEntryPointsLib;935}936937angle::GenericProc KHRONOS_APIENTRY GlobalLoad(const char *symbol)938{939return reinterpret_cast<angle::GenericProc>(EntryPointsLib()->getSymbol(symbol));940}941942void EnsureEGLLoaded()943{944if (gLoaded)945{946return;947}948949EntryPointsLib().reset(950angle::OpenSharedLibrary(ANGLE_GLESV2_LIBRARY_NAME, angle::SearchType::ModuleDir));951angle::LoadEGL_EGL(GlobalLoad);952if (!EGL_GetPlatformDisplay)953{954fprintf(stderr, "Error loading EGL entry points.\\n");955}956else957{958gLoaded = true;959}960}961#else962void EnsureEGLLoaded() {}963#endif // defined(ANGLE_USE_EGL_LOADER)964} // anonymous namespace965"""966967LIBCL_HEADER_INCLUDES = """\968#include "angle_cl.h"969"""970971LIBCL_SOURCE_INCLUDES = """\972#include "libGLESv2/entry_points_cl_autogen.h"973974#include "libANGLE/validationCL_autogen.h"975#include "libGLESv2/cl_stubs_autogen.h"976#include "libGLESv2/entry_points_cl_utils.h"977"""978979TEMPLATE_EVENT_COMMENT = """\980// Don't run the EVENT() macro on the EXT_debug_marker entry points.981// It can interfere with the debug events being set by the caller.982// """983984TEMPLATE_CAPTURE_PROTO = "angle::CallCapture Capture%s(%s);"985986TEMPLATE_VALIDATION_PROTO = "%s Validate%s(%s);"987988TEMPLATE_WINDOWS_DEF_FILE = """\989; GENERATED FILE - DO NOT EDIT.990; Generated by {script_name} using data from {data_source_name}.991;992; Copyright 2020 The ANGLE Project Authors. All rights reserved.993; Use of this source code is governed by a BSD-style license that can be994; found in the LICENSE file.995LIBRARY {lib}996EXPORTS997{exports}998"""9991000TEMPLATE_FRAME_CAPTURE_UTILS_HEADER = """\1001// GENERATED FILE - DO NOT EDIT.1002// Generated by {script_name} using data from {data_source_name}.1003//1004// Copyright 2020 The ANGLE Project Authors. All rights reserved.1005// Use of this source code is governed by a BSD-style license that can be1006// found in the LICENSE file.1007//1008// frame_capture_utils_autogen.h:1009// ANGLE Frame capture types and helper functions.10101011#ifndef LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_1012#define LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_10131014#include "common/PackedEnums.h"10151016namespace angle1017{{1018enum class ParamType1019{{1020{param_types}1021}};10221023constexpr uint32_t kParamTypeCount = {param_type_count};10241025union ParamValue1026{{1027{param_union_values}1028}};10291030template <ParamType PType, typename T>1031T GetParamVal(const ParamValue &value);10321033{get_param_val_specializations}10341035template <ParamType PType, typename T>1036T GetParamVal(const ParamValue &value)1037{{1038UNREACHABLE();1039return T();1040}}10411042template <typename T>1043T AccessParamValue(ParamType paramType, const ParamValue &value)1044{{1045switch (paramType)1046{{1047{access_param_value_cases}1048}}1049}}10501051template <ParamType PType, typename T>1052void SetParamVal(T valueIn, ParamValue *valueOut);10531054{set_param_val_specializations}10551056template <ParamType PType, typename T>1057void SetParamVal(T valueIn, ParamValue *valueOut)1058{{1059UNREACHABLE();1060}}10611062template <typename T>1063void InitParamValue(ParamType paramType, T valueIn, ParamValue *valueOut)1064{{1065switch (paramType)1066{{1067{init_param_value_cases}1068}}1069}}10701071struct CallCapture;1072struct ParamCapture;10731074void WriteParamCaptureReplay(std::ostream &os, const CallCapture &call, const ParamCapture ¶m);1075const char *ParamTypeToString(ParamType paramType);10761077enum class ResourceIDType1078{{1079{resource_id_types}1080}};10811082ResourceIDType GetResourceIDTypeFromParamType(ParamType paramType);1083const char *GetResourceIDTypeName(ResourceIDType resourceIDType);10841085template <typename ResourceType>1086struct GetResourceIDTypeFromType;10871088{type_to_resource_id_type_structs}1089}} // namespace angle10901091#endif // LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_1092"""10931094TEMPLATE_FRAME_CAPTURE_UTILS_SOURCE = """\1095// GENERATED FILE - DO NOT EDIT.1096// Generated by {script_name} using data from {data_source_name}.1097//1098// Copyright 2020 The ANGLE Project Authors. All rights reserved.1099// Use of this source code is governed by a BSD-style license that can be1100// found in the LICENSE file.1101//1102// frame_capture_utils_autogen.cpp:1103// ANGLE Frame capture types and helper functions.11041105#include "libANGLE/capture/frame_capture_utils_autogen.h"11061107#include "libANGLE/capture/FrameCapture.h"11081109namespace angle1110{{1111void WriteParamCaptureReplay(std::ostream &os, const CallCapture &call, const ParamCapture ¶m)1112{{1113switch (param.type)1114{{1115{write_param_type_to_stream_cases}1116default:1117os << "unknown";1118break;1119}}1120}}11211122const char *ParamTypeToString(ParamType paramType)1123{{1124switch (paramType)1125{{1126{param_type_to_string_cases}1127default:1128UNREACHABLE();1129return "unknown";1130}}1131}}11321133ResourceIDType GetResourceIDTypeFromParamType(ParamType paramType)1134{{1135switch (paramType)1136{{1137{param_type_resource_id_cases}1138default:1139return ResourceIDType::InvalidEnum;1140}}1141}}11421143const char *GetResourceIDTypeName(ResourceIDType resourceIDType)1144{{1145switch (resourceIDType)1146{{1147{resource_id_type_name_cases}1148default:1149UNREACHABLE();1150return "GetResourceIDTypeName error";1151}}1152}}1153}} // namespace angle1154"""11551156TEMPLATE_GET_PARAM_VAL_SPECIALIZATION = """\1157template <>1158inline {type} GetParamVal<ParamType::T{enum}, {type}>(const ParamValue &value)1159{{1160return value.{union_name};1161}}"""11621163TEMPLATE_ACCESS_PARAM_VALUE_CASE = """\1164case ParamType::T{enum}:1165return GetParamVal<ParamType::T{enum}, T>(value);"""11661167TEMPLATE_SET_PARAM_VAL_SPECIALIZATION = """\1168template <>1169inline void SetParamVal<ParamType::T{enum}>({type} valueIn, ParamValue *valueOut)1170{{1171valueOut->{union_name} = valueIn;1172}}"""11731174TEMPLATE_INIT_PARAM_VALUE_CASE = """\1175case ParamType::T{enum}:1176SetParamVal<ParamType::T{enum}>(valueIn, valueOut);1177break;"""11781179TEMPLATE_WRITE_PARAM_TYPE_TO_STREAM_CASE = """\1180case ParamType::T{enum_in}:1181WriteParamValueReplay<ParamType::T{enum_out}>(os, call, param.value.{union_name});1182break;"""11831184TEMPLATE_PARAM_TYPE_TO_STRING_CASE = """\1185case ParamType::T{enum}:1186return "{type}";"""11871188TEMPLATE_PARAM_TYPE_TO_RESOURCE_ID_TYPE_CASE = """\1189case ParamType::T{enum}:1190return ResourceIDType::{resource_id_type};"""11911192TEMPLATE_RESOURCE_ID_TYPE_NAME_CASE = """\1193case ResourceIDType::{resource_id_type}:1194return "{resource_id_type}";"""11951196CL_PACKED_TYPES = {1197# Enums1198"cl_platform_info": "PlatformInfo",1199"cl_device_info": "DeviceInfo",1200"cl_context_info": "ContextInfo",1201"cl_command_queue_info": "CommandQueueInfo",1202"cl_mem_object_type": "MemObjectType",1203"cl_mem_info": "MemInfo",1204"cl_image_info": "ImageInfo",1205"cl_pipe_info": "PipeInfo",1206"cl_addressing_mode": "AddressingMode",1207"cl_filter_mode": "FilterMode",1208"cl_sampler_info": "SamplerInfo",1209"cl_program_info": "ProgramInfo",1210"cl_program_build_info": "ProgramBuildInfo",1211"cl_kernel_info": "KernelInfo",1212"cl_kernel_arg_info": "KernelArgInfo",1213"cl_kernel_work_group_info": "KernelWorkGroupInfo",1214"cl_kernel_sub_group_info": "KernelSubGroupInfo",1215"cl_kernel_exec_info": "KernelExecInfo",1216"cl_event_info": "EventInfo",1217"cl_profiling_info": "ProfilingInfo",1218# Bit fields1219"cl_device_type": "DeviceType",1220"cl_device_fp_config": "DeviceFpConfig",1221"cl_device_exec_capabilities": "DeviceExecCapabilities",1222"cl_device_svm_capabilities": "DeviceSvmCapabilities",1223"cl_command_queue_properties": "CommandQueueProperties",1224"cl_device_affinity_domain": "DeviceAffinityDomain",1225"cl_mem_flags": "MemFlags",1226"cl_svm_mem_flags": "SVM_MemFlags",1227"cl_mem_migration_flags": "MemMigrationFlags",1228"cl_map_flags": "MapFlags",1229"cl_kernel_arg_type_qualifier": "KernelArgTypeQualifier",1230"cl_device_atomic_capabilities": "DeviceAtomicCapabilities",1231"cl_device_device_enqueue_capabilities": "DeviceEnqueueCapabilities",1232}12331234EGL_PACKED_TYPES = {1235"EGLContext": "gl::Context *",1236"EGLConfig": "Config *",1237"EGLDeviceEXT": "Device *",1238# Needs an explicit namespace to avoid an X11 namespace collision.1239"EGLDisplay": "egl::Display *",1240"EGLImage": "Image *",1241"EGLImageKHR": "Image *",1242"EGLStreamKHR": "Stream *",1243"EGLSurface": "Surface *",1244"EGLSync": "Sync *",1245"EGLSyncKHR": "Sync *",1246}124712481249def is_aliasing_excepted(api, cmd_name):1250return api == apis.GLES and cmd_name in ALIASING_EXCEPTIONS125112521253def entry_point_export(api):1254if api == apis.CL:1255return ""1256return "ANGLE_EXPORT "125712581259def entry_point_prefix(api):1260if api == apis.CL:1261return "cl"1262if api == apis.GLES:1263return "GL_"1264return api + "_"126512661267def get_api_entry_def(api):1268if api == apis.EGL:1269return "EGLAPIENTRY"1270elif api == apis.CL:1271return "CL_API_CALL"1272else:1273return "GL_APIENTRY"127412751276def get_stubs_header_template(api):1277if api == apis.CL:1278return TEMPLATE_CL_STUBS_HEADER1279elif api == apis.EGL:1280return TEMPLATE_EGL_STUBS_HEADER1281else:1282return ""128312841285def format_entry_point_decl(api, cmd_name, proto, params):1286comma_if_needed = ", " if len(params) > 0 else ""1287stripped = strip_api_prefix(cmd_name)1288return TEMPLATE_ENTRY_POINT_DECL.format(1289angle_export=entry_point_export(api),1290export_def=get_api_entry_def(api),1291name="%s%s" % (entry_point_prefix(api), stripped),1292return_type=proto[:-len(cmd_name)].strip(),1293params=", ".join(params),1294comma_if_needed=comma_if_needed)129512961297# Returns index range of identifier in function parameter1298def find_name_range(param):12991300def is_allowed_in_identifier(char):1301return char.isalpha() or char.isdigit() or char == "_"13021303# If type is a function declaration, only search in first parentheses1304left_paren = param.find("(")1305if left_paren >= 0:1306min = left_paren + 11307end = param.index(")")1308else:1309min = 01310end = len(param)13111312# Find last identifier in search range1313while end > min and not is_allowed_in_identifier(param[end - 1]):1314end -= 11315if end == min:1316raise ValueError1317start = end - 11318while start > min and is_allowed_in_identifier(param[start - 1]):1319start -= 11320return start, end132113221323def just_the_type(param):1324start, end = find_name_range(param)1325return param[:start].strip() + param[end:].strip()132613271328def just_the_name(param):1329start, end = find_name_range(param)1330return param[start:end]133113321333def make_param(param_type, param_name):13341335def insert_name(param_type, param_name, pos):1336return param_type[:pos] + " " + param_name + param_type[pos:]13371338# If type is a function declaration, insert identifier before first closing parentheses1339left_paren = param_type.find("(")1340if left_paren >= 0:1341right_paren = param_type.index(")")1342return insert_name(param_type, param_name, right_paren)13431344# If type is an array declaration, insert identifier before brackets1345brackets = param_type.find("[")1346if brackets >= 0:1347return insert_name(param_type, param_name, brackets)13481349# Otherwise just append identifier1350return param_type + " " + param_name135113521353def just_the_type_packed(param, entry):1354name = just_the_name(param)1355if name in entry:1356return entry[name]1357else:1358return just_the_type(param)135913601361def just_the_name_packed(param, reserved_set):1362name = just_the_name(param)1363if name in reserved_set:1364return name + 'Packed'1365else:1366return name136713681369def is_unsigned_long_format(fmt):1370return fmt == UNSIGNED_LONG_LONG_FORMAT or fmt == HEX_LONG_LONG_FORMAT137113721373def param_print_argument(command_node, param):1374name_only = just_the_name(param)1375type_only = just_the_type(param)13761377if "*" not in param and type_only not in FORMAT_DICT:1378print(" ".join(param))1379raise Exception("Missing '%s %s' from '%s' entry point" %1380(type_only, name_only, registry_xml.get_cmd_name(command_node)))13811382if "*" in param or FORMAT_DICT[type_only] == POINTER_FORMAT:1383return "(uintptr_t)%s" % name_only13841385if is_unsigned_long_format(FORMAT_DICT[type_only]):1386return "static_cast<unsigned long long>(%s)" % name_only13871388if type_only == "GLboolean":1389return "GLbooleanToString(%s)" % name_only13901391if type_only == "GLbitfield":1392group_name = find_gl_enum_group_in_command(command_node, name_only)1393return "GLbitfieldToString(GLenumGroup::%s, %s).c_str()" % (group_name, name_only)13941395if type_only == "GLenum":1396group_name = find_gl_enum_group_in_command(command_node, name_only)1397return "GLenumToString(GLenumGroup::%s, %s)" % (group_name, name_only)13981399return name_only140014011402def param_format_string(param):1403if "*" in param:1404return just_the_name(param) + " = 0x%016\" PRIxPTR \""1405else:1406type_only = just_the_type(param)1407if type_only not in FORMAT_DICT:1408raise Exception(type_only + " is not a known type in 'FORMAT_DICT'")14091410return just_the_name(param) + " = " + FORMAT_DICT[type_only]141114121413def is_context_lost_acceptable_cmd(cmd_name):1414lost_context_acceptable_cmds = [1415"glGetError",1416"glGetSync",1417"glGetQueryObjecti",1418"glGetProgramiv",1419"glGetGraphicsResetStatus",1420"glGetShaderiv",1421]14221423for context_lost_entry_pont in lost_context_acceptable_cmds:1424if cmd_name.startswith(context_lost_entry_pont):1425return True1426return False142714281429def get_context_getter_function(cmd_name):1430if is_context_lost_acceptable_cmd(cmd_name):1431return "GetGlobalContext()"14321433return "GetValidGlobalContext()"143414351436def get_valid_context_check(cmd_name):1437return "context"143814391440def get_constext_lost_error_generator(cmd_name):1441# Don't generate context lost errors on commands that accept lost contexts1442if is_context_lost_acceptable_cmd(cmd_name):1443return ""14441445return "GenerateContextLostErrorOnCurrentGlobalContext();"144614471448def strip_suffix(api, name):1449# For commands where aliasing is excepted, keep the suffix1450if is_aliasing_excepted(api, name):1451return name14521453for suffix in STRIP_SUFFIXES:1454if name.endswith(suffix):1455name = name[0:-len(suffix)]1456return name145714581459def find_gl_enum_group_in_command(command_node, param_name):1460group_name = None1461for param_node in command_node.findall('./param'):1462if param_node.find('./name').text == param_name:1463group_name = param_node.attrib.get('group', None)1464break14651466if group_name is None or group_name in registry_xml.unsupported_enum_group_names:1467group_name = registry_xml.default_enum_group_name14681469return group_name147014711472def get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types, params):1473# Always strip the suffix when querying packed enums.1474result = cmd_packed_gl_enums.get(strip_suffix(api, cmd_name), {})1475for param in params:1476param_type = just_the_type(param)1477if param_type in packed_param_types:1478result[just_the_name(param)] = packed_param_types[param_type]1479return result148014811482def get_def_template(api, return_type, has_errcode_ret):1483if return_type == "void":1484if api == apis.EGL:1485return TEMPLATE_EGL_ENTRY_POINT_NO_RETURN1486elif api == apis.CL:1487return TEMPLATE_CL_ENTRY_POINT_NO_RETURN1488else:1489return TEMPLATE_GLES_ENTRY_POINT_NO_RETURN1490elif return_type == "cl_int":1491return TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_ERROR1492else:1493if api == apis.EGL:1494return TEMPLATE_EGL_ENTRY_POINT_WITH_RETURN1495elif api == apis.CL:1496if has_errcode_ret:1497return TEMPLATE_CL_ENTRY_POINT_WITH_ERRCODE_RET1498else:1499return TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_POINTER1500else:1501return TEMPLATE_GLES_ENTRY_POINT_WITH_RETURN150215031504def format_entry_point_def(api, command_node, cmd_name, proto, params, cmd_packed_enums,1505packed_param_types, ep_to_object):1506packed_enums = get_packed_enums(api, cmd_packed_enums, cmd_name, packed_param_types, params)1507internal_params = [just_the_name_packed(param, packed_enums) for param in params]1508if internal_params and internal_params[-1] == "errcode_ret":1509internal_params.pop()1510has_errcode_ret = True1511else:1512has_errcode_ret = False1513packed_gl_enum_conversions = []1514for param in params:1515name = just_the_name(param)1516if name in packed_enums:1517internal_name = name + "Packed"1518internal_type = packed_enums[name]1519packed_gl_enum_conversions += [1520"\n " + internal_type + " " + internal_name + " = PackParam<" +1521internal_type + ">(" + name + ");"1522]15231524pass_params = [param_print_argument(command_node, param) for param in params]1525format_params = [param_format_string(param) for param in params]1526return_type = proto[:-len(cmd_name)].strip()1527initialization = "InitBackEnds(%s);\n" % INIT_DICT[cmd_name] if cmd_name in INIT_DICT else ""1528event_comment = TEMPLATE_EVENT_COMMENT if cmd_name in NO_EVENT_MARKER_EXCEPTIONS_LIST else ""1529name_lower_no_suffix = strip_suffix(api, cmd_name[2:3].lower() + cmd_name[3:])15301531format_params = {1532"name":1533strip_api_prefix(cmd_name),1534"name_lower_no_suffix":1535name_lower_no_suffix,1536"return_type":1537return_type,1538"params":1539", ".join(params),1540"internal_params":1541", ".join(internal_params),1542"initialization":1543initialization,1544"packed_gl_enum_conversions":1545"".join(packed_gl_enum_conversions),1546"pass_params":1547", ".join(pass_params),1548"comma_if_needed":1549", " if len(params) > 0 else "",1550"validate_params":1551", ".join(["context"] + internal_params),1552"format_params":1553", ".join(format_params),1554"context_getter":1555get_context_getter_function(cmd_name),1556"valid_context_check":1557get_valid_context_check(cmd_name),1558"constext_lost_error_generator":1559get_constext_lost_error_generator(cmd_name),1560"event_comment":1561event_comment,1562"labeled_object":1563get_egl_entry_point_labeled_object(ep_to_object, cmd_name, params, packed_enums)1564}15651566template = get_def_template(api, return_type, has_errcode_ret)1567return template.format(**format_params)156815691570def get_capture_param_type_name(param_type):1571pointer_count = param_type.count("*")1572is_const = "const" in param_type.split()15731574# EGL types are special1575for egl_type, angle_type in EGL_PACKED_TYPES.items():1576if angle_type == param_type:1577return egl_type15781579param_type = param_type.replace("*", "")1580param_type = param_type.replace("&", "")1581param_type = param_type.replace("const", "")1582param_type = param_type.replace("struct", "")1583param_type = param_type.strip()15841585if "EGL" not in param_type:1586if is_const and param_type != 'AttributeMap':1587param_type += "Const"1588for x in range(pointer_count):1589param_type += "Pointer"15901591return param_type159215931594def format_capture_method(api, command, cmd_name, proto, params, all_param_types,1595capture_pointer_funcs, cmd_packed_gl_enums, packed_param_types):15961597packed_gl_enums = get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types,1598params)15991600params_with_type = get_internal_params(api, cmd_name,1601["const State &glState", "bool isCallValid"] + params,1602cmd_packed_gl_enums, packed_param_types)1603params_just_name = ", ".join(1604["glState", "isCallValid"] +1605[just_the_name_packed(param, packed_gl_enums) for param in params])16061607parameter_captures = []1608for param in params:16091610param_name = just_the_name_packed(param, packed_gl_enums)1611param_type = just_the_type_packed(param, packed_gl_enums).strip()16121613# TODO(http://anglebug.com/4035: Add support for egl::AttributeMap.1614if 'AttributeMap' in param_type:1615# egl::AttributeMap is too complex for ParamCapture to handle it.1616continue16171618pointer_count = param_type.count("*")1619capture_param_type = get_capture_param_type_name(param_type)16201621if pointer_count > 0:1622params = params_just_name1623capture_name = "Capture%s_%s" % (strip_api_prefix(cmd_name), param_name)1624capture = TEMPLATE_PARAMETER_CAPTURE_POINTER.format(1625name=param_name,1626type=capture_param_type,1627capture_name=capture_name,1628params=params,1629cast_type=param_type)16301631capture_pointer_func = TEMPLATE_PARAMETER_CAPTURE_POINTER_FUNC.format(1632name=capture_name, params=params_with_type + ", angle::ParamCapture *paramCapture")1633capture_pointer_funcs += [capture_pointer_func]1634elif capture_param_type in ('GLenum', 'GLbitfield'):1635gl_enum_group = find_gl_enum_group_in_command(command, param_name)1636capture = TEMPLATE_PARAMETER_CAPTURE_GL_ENUM.format(1637name=param_name, type=capture_param_type, group=gl_enum_group)1638else:1639capture = TEMPLATE_PARAMETER_CAPTURE_VALUE.format(1640name=param_name, type=capture_param_type)16411642all_param_types.add(capture_param_type)16431644parameter_captures += [capture]16451646return_type = proto[:-len(cmd_name)].strip()16471648format_args = {1649"full_name": cmd_name,1650"short_name": strip_api_prefix(cmd_name),1651"params_with_type": params_with_type,1652"params_just_name": params_just_name,1653"parameter_captures": "\n ".join(parameter_captures),1654"return_value_type_original": return_type,1655"return_value_type_custom": get_capture_param_type_name(return_type)1656}16571658if return_type == "void":1659return TEMPLATE_CAPTURE_METHOD_NO_RETURN_VALUE.format(**format_args)1660else:1661return TEMPLATE_CAPTURE_METHOD_WITH_RETURN_VALUE.format(**format_args)166216631664def const_pointer_type(param, packed_gl_enums):1665type = just_the_type_packed(param, packed_gl_enums)1666if just_the_name(param) == "errcode_ret" or "(" in type:1667return type1668elif "**" in type and "const" not in type:1669return type.replace("**", "* const *")1670elif "*" in type and "const" not in type:1671return type.replace("*", "*const ") if "[]" in type else "const " + type1672else:1673return type167416751676def get_internal_params(api, cmd_name, params, cmd_packed_gl_enums, packed_param_types):1677packed_gl_enums = get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types,1678params)1679return ", ".join([1680make_param(1681just_the_type_packed(param, packed_gl_enums),1682just_the_name_packed(param, packed_gl_enums)) for param in params1683])168416851686def get_validation_params(api, cmd_name, params, cmd_packed_gl_enums, packed_param_types):1687packed_gl_enums = get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types,1688params)1689last = -1 if params and just_the_name(params[-1]) == "errcode_ret" else None1690return ", ".join([1691make_param(1692const_pointer_type(param, packed_gl_enums),1693just_the_name_packed(param, packed_gl_enums)) for param in params[:last]1694])169516961697def format_context_decl(api, cmd_name, proto, params, template, cmd_packed_gl_enums,1698packed_param_types):1699internal_params = get_internal_params(api, cmd_name, params, cmd_packed_gl_enums,1700packed_param_types)17011702return_type = proto[:-len(cmd_name)].strip()1703name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:]1704name_lower_no_suffix = strip_suffix(api, name_lower_no_suffix)1705maybe_const = " const" if name_lower_no_suffix.startswith(1706"is") and name_lower_no_suffix[2].isupper() else ""17071708return template.format(1709return_type=return_type,1710name_lower_no_suffix=name_lower_no_suffix,1711internal_params=internal_params,1712maybe_const=maybe_const)171317141715def format_entry_point_export(cmd_name, proto, params, template):1716internal_params = [just_the_name(param) for param in params]1717return_type = proto[:-len(cmd_name)].strip()17181719return template.format(1720name=strip_api_prefix(cmd_name),1721return_type=return_type,1722params=", ".join(params),1723internal_params=", ".join(internal_params))172417251726def format_validation_proto(api, cmd_name, proto, params, cmd_packed_gl_enums, packed_param_types):1727if api == apis.CL:1728return_type = "cl_int"1729else:1730return_type = "bool"1731if api in [apis.GL, apis.GLES]:1732with_extra_params = ["Context *context"] + params1733elif api == apis.EGL:1734with_extra_params = ["ValidationContext *val"] + params1735else:1736with_extra_params = params1737internal_params = get_validation_params(api, cmd_name, with_extra_params, cmd_packed_gl_enums,1738packed_param_types)1739return TEMPLATE_VALIDATION_PROTO % (return_type, strip_api_prefix(cmd_name), internal_params)174017411742def format_capture_proto(api, cmd_name, proto, params, cmd_packed_gl_enums, packed_param_types):1743internal_params = get_internal_params(api, cmd_name,1744["const State &glState", "bool isCallValid"] + params,1745cmd_packed_gl_enums, packed_param_types)1746return_type = proto[:-len(cmd_name)].strip()1747if return_type != "void":1748internal_params += ", %s returnValue" % return_type1749return TEMPLATE_CAPTURE_PROTO % (strip_api_prefix(cmd_name), internal_params)175017511752def path_to(folder, file):1753return os.path.join(script_relative(".."), "src", folder, file)175417551756class ANGLEEntryPoints(registry_xml.EntryPoints):17571758def __init__(self,1759api,1760xml,1761commands,1762all_param_types,1763cmd_packed_enums,1764export_template=TEMPLATE_GL_ENTRY_POINT_EXPORT,1765packed_param_types=[],1766ep_to_object={}):1767super().__init__(api, xml, commands)17681769self.decls = []1770self.defs = []1771self.export_defs = []1772self.validation_protos = []1773self.capture_protos = []1774self.capture_methods = []1775self.capture_pointer_funcs = []17761777for (cmd_name, command_node, param_text, proto_text) in self.get_infos():1778self.decls.append(format_entry_point_decl(self.api, cmd_name, proto_text, param_text))1779self.defs.append(1780format_entry_point_def(self.api, command_node, cmd_name, proto_text, param_text,1781cmd_packed_enums, packed_param_types, ep_to_object))17821783self.export_defs.append(1784format_entry_point_export(cmd_name, proto_text, param_text, export_template))17851786self.validation_protos.append(1787format_validation_proto(self.api, cmd_name, proto_text, param_text,1788cmd_packed_enums, packed_param_types))1789self.capture_protos.append(1790format_capture_proto(self.api, cmd_name, proto_text, param_text, cmd_packed_enums,1791packed_param_types))1792self.capture_methods.append(1793format_capture_method(self.api, command_node, cmd_name, proto_text, param_text,1794all_param_types, self.capture_pointer_funcs,1795cmd_packed_enums, packed_param_types))179617971798class GLEntryPoints(ANGLEEntryPoints):17991800all_param_types = set()18011802def __init__(self, api, xml, commands):1803super().__init__(api, xml, commands, GLEntryPoints.all_param_types,1804GLEntryPoints.get_packed_enums())18051806_packed_enums = None18071808@classmethod1809def get_packed_enums(cls):1810if not cls._packed_enums:1811with open(script_relative('entry_point_packed_gl_enums.json')) as f:1812cls._packed_enums = json.loads(f.read())1813return cls._packed_enums181418151816class EGLEntryPoints(ANGLEEntryPoints):18171818all_param_types = set()18191820def __init__(self, xml, commands):1821super().__init__(1822apis.EGL,1823xml,1824commands,1825EGLEntryPoints.all_param_types,1826EGLEntryPoints.get_packed_enums(),1827export_template=TEMPLATE_EGL_ENTRY_POINT_EXPORT,1828packed_param_types=EGL_PACKED_TYPES,1829ep_to_object=EGLEntryPoints._get_ep_to_object())18301831_ep_to_object = None18321833@classmethod1834def _get_ep_to_object(cls):18351836if cls._ep_to_object:1837return cls._ep_to_object18381839with open(EGL_GET_LABELED_OBJECT_DATA_PATH) as f:1840try:1841spec_json = json.loads(f.read())1842except ValueError:1843raise Exception("Could not decode JSON from %s" % EGL_GET_LABELED_OBJECT_DATA_PATH)18441845# Construct a mapping from EP to type. Fill in the gaps with Display/None.1846cls._ep_to_object = {}18471848for category, eps in spec_json.items():1849if category == 'description':1850continue1851for ep in eps:1852cls._ep_to_object[ep] = category18531854return cls._ep_to_object18551856_packed_enums = None18571858@classmethod1859def get_packed_enums(cls):1860if not cls._packed_enums:1861with open(script_relative('entry_point_packed_egl_enums.json')) as f:1862cls._packed_enums = json.loads(f.read())1863return cls._packed_enums186418651866class CLEntryPoints(ANGLEEntryPoints):18671868all_param_types = set()18691870def __init__(self, xml, commands):1871super().__init__(1872apis.CL,1873xml,1874commands,1875CLEntryPoints.all_param_types,1876CLEntryPoints.get_packed_enums(),1877export_template=TEMPLATE_CL_ENTRY_POINT_EXPORT,1878packed_param_types=CL_PACKED_TYPES)18791880@classmethod1881def get_packed_enums(cls):1882return {}188318841885def get_decls(api,1886formatter,1887all_commands,1888gles_commands,1889already_included,1890cmd_packed_gl_enums,1891packed_param_types=[]):1892decls = []1893for command in all_commands:1894proto = command.find('proto')1895cmd_name = proto.find('name').text18961897if cmd_name not in gles_commands:1898continue18991900name_no_suffix = strip_suffix(api, cmd_name)1901if name_no_suffix in already_included:1902continue19031904param_text = ["".join(param.itertext()) for param in command.findall('param')]1905proto_text = "".join(proto.itertext())1906decls.append(1907format_context_decl(api, cmd_name, proto_text, param_text, formatter,1908cmd_packed_gl_enums, packed_param_types))19091910return decls191119121913def get_glext_decls(all_commands, gles_commands, version):1914glext_ptrs = []1915glext_protos = []1916is_gles1 = False19171918if (version == ""):1919is_gles1 = True19201921for command in all_commands:1922proto = command.find('proto')1923cmd_name = proto.find('name').text19241925if cmd_name not in gles_commands:1926continue19271928param_text = ["".join(param.itertext()) for param in command.findall('param')]1929proto_text = "".join(proto.itertext())19301931return_type = proto_text[:-len(cmd_name)]1932params = ", ".join(param_text)19331934format_params = {1935"apicall": "GL_API" if is_gles1 else "GL_APICALL",1936"name": cmd_name,1937"name_upper": cmd_name.upper(),1938"return_type": return_type,1939"params": params,1940}19411942glext_ptrs.append(TEMPLATE_GLEXT_FUNCTION_POINTER.format(**format_params))1943glext_protos.append(TEMPLATE_GLEXT_FUNCTION_PROTOTYPE.format(**format_params))19441945return glext_ptrs, glext_protos194619471948def write_file(annotation, comment, template, entry_points, suffix, includes, lib, file):19491950content = template.format(1951script_name=os.path.basename(sys.argv[0]),1952data_source_name=file,1953annotation_lower=annotation.lower(),1954annotation_upper=annotation.upper(),1955comment=comment,1956lib=lib.upper(),1957includes=includes,1958entry_points=entry_points)19591960path = path_to(lib, "entry_points_{}_autogen.{}".format(annotation.lower(), suffix))19611962with open(path, "w") as out:1963out.write(content)1964out.close()196519661967def write_export_files(entry_points, includes, source, lib_name, lib_description):1968content = TEMPLATE_LIB_ENTRY_POINT_SOURCE.format(1969script_name=os.path.basename(sys.argv[0]),1970data_source_name=source,1971lib_name=lib_name,1972lib_description=lib_description,1973includes=includes,1974entry_points=entry_points)19751976path = path_to(lib_name, "{}_autogen.cpp".format(lib_name))19771978with open(path, "w") as out:1979out.write(content)1980out.close()198119821983def write_context_api_decls(decls, api):1984for (major, minor), version_decls in sorted(decls['core'].items()):1985if minor == "X":1986annotation = '{}_{}'.format(api, major)1987version = str(major)1988else:1989annotation = '{}_{}_{}'.format(api, major, minor)1990version = '{}_{}'.format(major, minor)1991content = CONTEXT_HEADER.format(1992annotation_lower=annotation.lower(),1993annotation_upper=annotation.upper(),1994script_name=os.path.basename(sys.argv[0]),1995data_source_name="gl.xml",1996version=version,1997interface="\n".join(version_decls))19981999path = path_to("libANGLE", "Context_%s_autogen.h" % annotation.lower())20002001with open(path, "w") as out:2002out.write(content)2003out.close()20042005if 'exts' in decls.keys():2006interface_lines = []2007for annotation in decls['exts'].keys():2008interface_lines.append("\\\n /* " + annotation + " */ \\\n\\")20092010for extname in sorted(decls['exts'][annotation].keys()):2011interface_lines.append(" /* " + extname + " */ \\")2012interface_lines.extend(decls['exts'][annotation][extname])20132014content = CONTEXT_HEADER.format(2015annotation_lower='gles_ext',2016annotation_upper='GLES_EXT',2017script_name=os.path.basename(sys.argv[0]),2018data_source_name="gl.xml",2019version='EXT',2020interface="\n".join(interface_lines))20212022path = path_to("libANGLE", "Context_gles_ext_autogen.h")20232024with open(path, "w") as out:2025out.write(content)2026out.close()202720282029def write_validation_header(annotation, comment, protos, source, template):2030content = template.format(2031script_name=os.path.basename(sys.argv[0]),2032data_source_name=source,2033annotation=annotation,2034comment=comment,2035prototypes="\n".join(protos))20362037path = path_to("libANGLE", "validation%s_autogen.h" % annotation)20382039with open(path, "w") as out:2040out.write(content)2041out.close()204220432044def write_gl_validation_header(annotation, comment, protos, source):2045return write_validation_header(annotation, comment, protos, source,2046TEMPLATE_GL_VALIDATION_HEADER)204720482049def write_capture_header(annotation, comment, protos, capture_pointer_funcs):2050content = TEMPLATE_CAPTURE_HEADER.format(2051script_name=os.path.basename(sys.argv[0]),2052data_source_name="gl.xml and gl_angle_ext.xml",2053annotation_lower=annotation.lower(),2054annotation_upper=annotation.upper(),2055comment=comment,2056prototypes="\n".join(["\n// Method Captures\n"] + protos + ["\n// Parameter Captures\n"] +2057capture_pointer_funcs))20582059path = path_to(os.path.join("libANGLE", "capture"), "capture_gles_%s_autogen.h" % annotation)20602061with open(path, "w") as out:2062out.write(content)2063out.close()206420652066def write_capture_source(annotation_with_dash, annotation_no_dash, comment, capture_methods):2067content = TEMPLATE_CAPTURE_SOURCE.format(2068script_name=os.path.basename(sys.argv[0]),2069data_source_name="gl.xml and gl_angle_ext.xml",2070annotation_with_dash=annotation_with_dash,2071annotation_no_dash=annotation_no_dash,2072comment=comment,2073capture_methods="\n".join(capture_methods))20742075path = path_to(2076os.path.join("libANGLE", "capture"), "capture_gles_%s_autogen.cpp" % annotation_with_dash)20772078with open(path, "w") as out:2079out.write(content)2080out.close()208120822083def is_packed_enum_param_type(param_type):2084return param_type[0:2] != "GL" and "void" not in param_type208520862087def add_namespace(param_type):2088param_type = param_type.strip()20892090if param_type == 'AHardwareBufferConstPointer' or param_type == 'charConstPointer':2091return param_type20922093if param_type[0:2] == "GL" or param_type[0:3] == "EGL" or "void" in param_type:2094return param_type20952096# ANGLE namespaced EGL types2097egl_namespace = [2098'CompositorTiming',2099'DevicePointer',2100'ObjectType',2101'StreamPointer',2102'Timestamp',2103]21042105if param_type in egl_namespace:2106return "egl::" + param_type2107else:2108return "gl::" + param_type210921102111def get_gl_pointer_type(param_type):21122113if "ConstPointerPointer" in param_type:2114return "const " + param_type.replace("ConstPointerPointer", "") + " * const *"21152116if "ConstPointer" in param_type:2117return "const " + param_type.replace("ConstPointer", "") + " *"21182119if "PointerPointer" in param_type:2120return param_type.replace("PointerPointer", "") + " **"21212122if "Pointer" in param_type:2123return param_type.replace("Pointer", "") + " *"21242125return param_type212621272128def get_param_type_type(param_type):2129param_type = add_namespace(param_type)2130return get_gl_pointer_type(param_type)213121322133def get_gl_param_type_type(param_type):2134if not is_packed_enum_param_type(param_type):2135return get_gl_pointer_type(param_type)2136else:2137base_type = param_type.replace("Pointer", "").replace("Const", "")2138if base_type[-2:] == "ID":2139replace_type = "GLuint"2140else:2141replace_type = "GLenum"2142param_type = param_type.replace(base_type, replace_type)2143return get_gl_pointer_type(param_type)214421452146def get_param_type_union_name(param_type):2147return param_type + "Val"214821492150def format_param_type_union_type(param_type):2151return "%s %s;" % (get_param_type_type(param_type), get_param_type_union_name(param_type))215221532154def format_get_param_val_specialization(param_type):2155return TEMPLATE_GET_PARAM_VAL_SPECIALIZATION.format(2156enum=param_type,2157type=get_param_type_type(param_type),2158union_name=get_param_type_union_name(param_type))215921602161def format_access_param_value_case(param_type):2162return TEMPLATE_ACCESS_PARAM_VALUE_CASE.format(enum=param_type)216321642165def format_set_param_val_specialization(param_type):2166return TEMPLATE_SET_PARAM_VAL_SPECIALIZATION.format(2167enum=param_type,2168type=get_param_type_type(param_type),2169union_name=get_param_type_union_name(param_type))217021712172def format_init_param_value_case(param_type):2173return TEMPLATE_INIT_PARAM_VALUE_CASE.format(enum=param_type)217421752176def format_write_param_type_to_stream_case(param_type):2177# Force all enum printing to go through "const void *"2178param_out = "voidConstPointer" if "Pointer" in param_type else param_type2179return TEMPLATE_WRITE_PARAM_TYPE_TO_STREAM_CASE.format(2180enum_in=param_type, enum_out=param_out, union_name=get_param_type_union_name(param_out))218121822183def get_resource_id_types(all_param_types):2184return [2185t[:-2]2186for t in filter(lambda t: t.endswith("ID") and not t.endswith("ANDROID"), all_param_types)2187]218821892190def format_resource_id_types(all_param_types):2191resource_id_types = get_resource_id_types(all_param_types)2192resource_id_types += ["EnumCount", "InvalidEnum = EnumCount"]2193resource_id_types = ",\n ".join(resource_id_types)2194return resource_id_types219521962197def format_resource_id_convert_structs(all_param_types):2198templ = """\2199template <>2200struct GetResourceIDTypeFromType<gl::%sID>2201{2202static constexpr ResourceIDType IDType = ResourceIDType::%s;2203};2204"""2205resource_id_types = get_resource_id_types(all_param_types)2206convert_struct_strings = [templ % (id, id) for id in resource_id_types]2207return "\n".join(convert_struct_strings)220822092210def write_capture_helper_header(all_param_types):22112212param_types = "\n ".join(["T%s," % t for t in all_param_types])2213param_union_values = "\n ".join([format_param_type_union_type(t) for t in all_param_types])2214get_param_val_specializations = "\n\n".join(2215[format_get_param_val_specialization(t) for t in all_param_types])2216access_param_value_cases = "\n".join(2217[format_access_param_value_case(t) for t in all_param_types])2218set_param_val_specializations = "\n\n".join(2219[format_set_param_val_specialization(t) for t in all_param_types])2220init_param_value_cases = "\n".join([format_init_param_value_case(t) for t in all_param_types])2221resource_id_types = format_resource_id_types(all_param_types)2222convert_structs = format_resource_id_convert_structs(all_param_types)22232224content = TEMPLATE_FRAME_CAPTURE_UTILS_HEADER.format(2225script_name=os.path.basename(sys.argv[0]),2226data_source_name="gl.xml and gl_angle_ext.xml",2227param_types=param_types,2228param_type_count=len(all_param_types),2229param_union_values=param_union_values,2230get_param_val_specializations=get_param_val_specializations,2231access_param_value_cases=access_param_value_cases,2232set_param_val_specializations=set_param_val_specializations,2233init_param_value_cases=init_param_value_cases,2234resource_id_types=resource_id_types,2235type_to_resource_id_type_structs=convert_structs)22362237path = path_to(os.path.join("libANGLE", "capture"), "frame_capture_utils_autogen.h")22382239with open(path, "w") as out:2240out.write(content)2241out.close()224222432244def format_param_type_to_string_case(param_type):2245return TEMPLATE_PARAM_TYPE_TO_STRING_CASE.format(2246enum=param_type, type=get_gl_param_type_type(param_type))224722482249def get_resource_id_type_from_param_type(param_type):2250if param_type.endswith("ConstPointer"):2251return param_type.replace("ConstPointer", "")[:-2]2252if param_type.endswith("Pointer"):2253return param_type.replace("Pointer", "")[:-2]2254return param_type[:-2]225522562257def format_param_type_to_resource_id_type_case(param_type):2258return TEMPLATE_PARAM_TYPE_TO_RESOURCE_ID_TYPE_CASE.format(2259enum=param_type, resource_id_type=get_resource_id_type_from_param_type(param_type))226022612262def format_param_type_resource_id_cases(all_param_types):2263id_types = filter(2264lambda t: (t.endswith("ID") and not t.endswith("ANDROID")) or t.endswith("IDConstPointer")2265or t.endswith("IDPointer"), all_param_types)2266return "\n".join([format_param_type_to_resource_id_type_case(t) for t in id_types])226722682269def format_resource_id_type_name_case(resource_id_type):2270return TEMPLATE_RESOURCE_ID_TYPE_NAME_CASE.format(resource_id_type=resource_id_type)227122722273def write_capture_helper_source(all_param_types):22742275write_param_type_to_stream_cases = "\n".join(2276[format_write_param_type_to_stream_case(t) for t in all_param_types])2277param_type_to_string_cases = "\n".join(2278[format_param_type_to_string_case(t) for t in all_param_types])22792280param_type_resource_id_cases = format_param_type_resource_id_cases(all_param_types)22812282resource_id_types = get_resource_id_types(all_param_types)2283resource_id_type_name_cases = "\n".join(2284[format_resource_id_type_name_case(t) for t in resource_id_types])22852286content = TEMPLATE_FRAME_CAPTURE_UTILS_SOURCE.format(2287script_name=os.path.basename(sys.argv[0]),2288data_source_name="gl.xml and gl_angle_ext.xml",2289write_param_type_to_stream_cases=write_param_type_to_stream_cases,2290param_type_to_string_cases=param_type_to_string_cases,2291param_type_resource_id_cases=param_type_resource_id_cases,2292resource_id_type_name_cases=resource_id_type_name_cases)22932294path = path_to(os.path.join("libANGLE", "capture"), "frame_capture_utils_autogen.cpp")22952296with open(path, "w") as out:2297out.write(content)2298out.close()229923002301def get_command_params_text(command_node, cmd_name):2302param_text_list = list()2303for param_node in command_node.findall('param'):2304param_text_list.append("".join(param_node.itertext()))2305return param_text_list230623072308def is_get_pointer_command(command_name):2309return command_name.endswith('Pointerv') and command_name.startswith('glGet')231023112312def format_capture_replay_param_access(api, command_name, param_text_list, cmd_packed_gl_enums,2313packed_param_types):2314param_access_strs = list()2315cmd_packed_enums = get_packed_enums(api, cmd_packed_gl_enums, command_name, packed_param_types,2316param_text_list)2317for i, param_text in enumerate(param_text_list):2318param_type = just_the_type_packed(param_text, cmd_packed_enums)2319param_name = just_the_name_packed(param_text, cmd_packed_enums)23202321pointer_count = param_type.count('*')2322is_const = 'const' in param_type2323if pointer_count == 0:2324param_template = 'params.getParam("{name}", ParamType::T{enum_type}, {index}).value.{enum_type}Val'2325elif pointer_count == 1 and is_const:2326param_template = 'replayContext->getAsConstPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))'2327elif pointer_count == 2 and is_const:2328param_template = 'replayContext->getAsPointerConstPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))'2329elif pointer_count == 1 or (pointer_count == 2 and is_get_pointer_command(command_name)):2330param_template = 'replayContext->getReadBufferPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))'2331else:2332assert False, "Not supported param type %s" % param_type23332334param_access_strs.append(2335param_template.format(2336index=i,2337name=param_name,2338type=param_type,2339enum_type=get_capture_param_type_name(param_type)))2340return ",".join(param_access_strs)234123422343def format_capture_replay_call_case(api, command_to_param_types_mapping, cmd_packed_gl_enums,2344packed_param_types):2345call_str_list = list()2346for command_name, cmd_param_texts in sorted(command_to_param_types_mapping.items()):2347entry_point_name = strip_api_prefix(command_name)23482349call_str_list.append(2350TEMPLATE_CAPTURE_REPLAY_CALL_CASE.format(2351entry_point=entry_point_name,2352param_value_access=format_capture_replay_param_access(2353api, command_name, cmd_param_texts, cmd_packed_gl_enums, packed_param_types),2354context_call=entry_point_name[0].lower() + entry_point_name[1:],2355))23562357return '\n'.join(call_str_list)235823592360def write_capture_replay_source(api, all_commands_nodes, gles_command_names, cmd_packed_gl_enums,2361packed_param_types):2362all_commands_names = set(gles_command_names)23632364command_to_param_types_mapping = dict()2365for command_node in all_commands_nodes:2366command_name = command_node.find('proto').find('name').text2367if command_name not in all_commands_names:2368continue23692370command_to_param_types_mapping[command_name] = get_command_params_text(2371command_node, command_name)23722373call_replay_cases = format_capture_replay_call_case(api, command_to_param_types_mapping,2374cmd_packed_gl_enums, packed_param_types)23752376source_content = TEMPLATE_CAPTURE_REPLAY_SOURCE.format(2377script_name=os.path.basename(sys.argv[0]),2378data_source_name="gl.xml and gl_angle_ext.xml",2379call_replay_cases=call_replay_cases,2380)2381source_file_path = registry_xml.script_relative(2382"../src/libANGLE/capture/frame_capture_replay_autogen.cpp")2383with open(source_file_path, 'w') as f:2384f.write(source_content)238523862387def write_windows_def_file(data_source_name, lib, libexport, folder, exports):23882389content = TEMPLATE_WINDOWS_DEF_FILE.format(2390script_name=os.path.basename(sys.argv[0]),2391data_source_name=data_source_name,2392exports="\n".join(exports),2393lib=libexport)23942395path = path_to(folder, "%s_autogen.def" % lib)23962397with open(path, "w") as out:2398out.write(content)2399out.close()240024012402def get_exports(commands, fmt=None):2403if fmt:2404return [" %s" % fmt(cmd) for cmd in sorted(commands)]2405else:2406return [" %s" % cmd for cmd in sorted(commands)]240724082409# Get EGL exports2410def get_egl_exports():24112412egl = registry_xml.RegistryXML('egl.xml', 'egl_angle_ext.xml')2413exports = []24142415capser = lambda fn: "EGL_" + fn[3:]24162417for major, minor in registry_xml.EGL_VERSIONS:2418annotation = "{}_{}".format(major, minor)2419name_prefix = "EGL_VERSION_"24202421feature_name = "{}{}".format(name_prefix, annotation)24222423egl.AddCommands(feature_name, annotation)24242425commands = egl.commands[annotation]24262427if len(commands) == 0:2428continue24292430exports.append("\n ; EGL %d.%d" % (major, minor))2431exports += get_exports(commands, capser)24322433egl.AddExtensionCommands(registry_xml.supported_egl_extensions, ['egl'])24342435for extension_name, ext_cmd_names in sorted(egl.ext_data.items()):24362437if len(ext_cmd_names) == 0:2438continue24392440exports.append("\n ; %s" % extension_name)2441exports += get_exports(ext_cmd_names, capser)24422443return exports244424452446# Construct a mapping from an EGL EP to object function2447def get_egl_entry_point_labeled_object(ep_to_object, cmd_stripped, params, packed_enums):24482449if not ep_to_object:2450return ""24512452# Finds a packed parameter name in a list of params2453def find_param(params, type_name, packed_enums):2454for param in params:2455if just_the_type_packed(param, packed_enums).split(' ')[0] == type_name:2456return just_the_name_packed(param, packed_enums)2457return None24582459display_param = find_param(params, "egl::Display", packed_enums)24602461# For entry points not listed in the JSON file, they default to an EGLDisplay or nothing.2462if cmd_stripped not in ep_to_object:2463if display_param:2464return "GetDisplayIfValid(%s)" % display_param2465return "nullptr"24662467# We first handle a few special cases for certain type categories.2468category = ep_to_object[cmd_stripped]2469if category == "Thread":2470return "GetThreadIfValid(thread)"2471found_param = find_param(params, category, packed_enums)2472if category == "Context" and not found_param:2473return "GetContextIfValid(thread->getDisplay(), thread->getContext())"2474assert found_param, "Did not find %s for %s: %s" % (category, cmd_stripped, str(params))2475if category == "Device":2476return "GetDeviceIfValid(%s)" % found_param2477if category == "LabeledObject":2478object_type_param = find_param(params, "ObjectType", packed_enums)2479return "GetLabeledObjectIfValid(thread, %s, %s, %s)" % (display_param, object_type_param,2480found_param)24812482# We then handle the general case which handles the rest of the type categories.2483return "Get%sIfValid(%s, %s)" % (category, display_param, found_param)248424852486def write_stubs_header(api, annotation, title, data_source, out_file, all_commands, commands,2487cmd_packed_egl_enums, packed_param_types):24882489stubs = []24902491for command in all_commands:2492proto = command.find('proto')2493cmd_name = proto.find('name').text24942495if cmd_name not in commands:2496continue24972498proto_text = "".join(proto.itertext())2499params = [] if api == apis.CL else ["Thread *thread"]2500params += ["".join(param.itertext()) for param in command.findall('param')]2501if params and just_the_name(params[-1]) == "errcode_ret":2502params[-1] = "cl_int &errorCode"2503return_type = proto_text[:-len(cmd_name)].strip()25042505internal_params = get_internal_params(api, cmd_name, params, cmd_packed_egl_enums,2506packed_param_types)25072508stubs.append("%s %s(%s);" % (return_type, strip_api_prefix(cmd_name), internal_params))25092510args = {2511"annotation_lower": annotation.lower(),2512"annotation_upper": annotation.upper(),2513"data_source_name": data_source,2514"script_name": os.path.basename(sys.argv[0]),2515"stubs": "\n".join(stubs),2516"title": title,2517}25182519output = get_stubs_header_template(api).format(**args)25202521with open(out_file, "w") as f:2522f.write(output)252325242525def main():25262527# auto_script parameters.2528if len(sys.argv) > 1:2529inputs = [2530'entry_point_packed_egl_enums.json', 'entry_point_packed_gl_enums.json',2531EGL_GET_LABELED_OBJECT_DATA_PATH2532] + registry_xml.xml_inputs2533outputs = [2534CL_STUBS_HEADER_PATH,2535EGL_STUBS_HEADER_PATH,2536EGL_EXT_STUBS_HEADER_PATH,2537'../src/libOpenCL/libOpenCL_autogen.cpp',2538'../src/common/entry_points_enum_autogen.cpp',2539'../src/common/entry_points_enum_autogen.h',2540'../src/libANGLE/Context_gl_1_autogen.h',2541'../src/libANGLE/Context_gl_2_autogen.h',2542'../src/libANGLE/Context_gl_3_autogen.h',2543'../src/libANGLE/Context_gl_4_autogen.h',2544'../src/libANGLE/Context_gles_1_0_autogen.h',2545'../src/libANGLE/Context_gles_2_0_autogen.h',2546'../src/libANGLE/Context_gles_3_0_autogen.h',2547'../src/libANGLE/Context_gles_3_1_autogen.h',2548'../src/libANGLE/Context_gles_3_2_autogen.h',2549'../src/libANGLE/Context_gles_ext_autogen.h',2550'../src/libANGLE/capture/capture_gles_1_0_autogen.cpp',2551'../src/libANGLE/capture/capture_gles_1_0_autogen.h',2552'../src/libANGLE/capture/capture_gles_2_0_autogen.cpp',2553'../src/libANGLE/capture/capture_gles_2_0_autogen.h',2554'../src/libANGLE/capture/capture_gles_3_0_autogen.cpp',2555'../src/libANGLE/capture/capture_gles_3_0_autogen.h',2556'../src/libANGLE/capture/capture_gles_3_1_autogen.cpp',2557'../src/libANGLE/capture/capture_gles_3_1_autogen.h',2558'../src/libANGLE/capture/capture_gles_3_2_autogen.cpp',2559'../src/libANGLE/capture/capture_gles_3_2_autogen.h',2560'../src/libANGLE/capture/capture_gles_ext_autogen.cpp',2561'../src/libANGLE/capture/capture_gles_ext_autogen.h',2562'../src/libANGLE/capture/frame_capture_replay_autogen.cpp',2563'../src/libANGLE/capture/frame_capture_utils_autogen.cpp',2564'../src/libANGLE/capture/frame_capture_utils_autogen.h',2565'../src/libANGLE/validationCL_autogen.h',2566'../src/libANGLE/validationEGL_autogen.h',2567'../src/libANGLE/validationES1_autogen.h',2568'../src/libANGLE/validationES2_autogen.h',2569'../src/libANGLE/validationES31_autogen.h',2570'../src/libANGLE/validationES32_autogen.h',2571'../src/libANGLE/validationES3_autogen.h',2572'../src/libANGLE/validationESEXT_autogen.h',2573'../src/libANGLE/validationGL1_autogen.h',2574'../src/libANGLE/validationGL2_autogen.h',2575'../src/libANGLE/validationGL3_autogen.h',2576'../src/libANGLE/validationGL4_autogen.h',2577'../src/libEGL/libEGL_autogen.cpp',2578'../src/libEGL/libEGL_autogen.def',2579'../src/libGLESv2/entry_points_cl_autogen.cpp',2580'../src/libGLESv2/entry_points_cl_autogen.h',2581'../src/libGLESv2/entry_points_egl_autogen.cpp',2582'../src/libGLESv2/entry_points_egl_autogen.h',2583'../src/libGLESv2/entry_points_egl_ext_autogen.cpp',2584'../src/libGLESv2/entry_points_egl_ext_autogen.h',2585'../src/libGLESv2/entry_points_gles_1_0_autogen.cpp',2586'../src/libGLESv2/entry_points_gles_1_0_autogen.h',2587'../src/libGLESv2/entry_points_gles_2_0_autogen.cpp',2588'../src/libGLESv2/entry_points_gles_2_0_autogen.h',2589'../src/libGLESv2/entry_points_gles_3_0_autogen.cpp',2590'../src/libGLESv2/entry_points_gles_3_0_autogen.h',2591'../src/libGLESv2/entry_points_gles_3_1_autogen.cpp',2592'../src/libGLESv2/entry_points_gles_3_1_autogen.h',2593'../src/libGLESv2/entry_points_gles_3_2_autogen.cpp',2594'../src/libGLESv2/entry_points_gles_3_2_autogen.h',2595'../src/libGLESv2/entry_points_gles_ext_autogen.cpp',2596'../src/libGLESv2/entry_points_gles_ext_autogen.h',2597'../src/libGLESv2/libGLESv2_autogen.cpp',2598'../src/libGLESv2/libGLESv2_autogen.def',2599'../src/libGLESv2/libGLESv2_no_capture_autogen.def',2600'../src/libGLESv2/libGLESv2_with_capture_autogen.def',2601'../src/libGL/entry_points_gl_1_autogen.cpp',2602'../src/libGL/entry_points_gl_1_autogen.h',2603'../src/libGL/entry_points_gl_2_autogen.cpp',2604'../src/libGL/entry_points_gl_2_autogen.h',2605'../src/libGL/entry_points_gl_3_autogen.cpp',2606'../src/libGL/entry_points_gl_3_autogen.h',2607'../src/libGL/entry_points_gl_4_autogen.cpp',2608'../src/libGL/entry_points_gl_4_autogen.h',2609'../src/libGL/libGL_autogen.cpp',2610'../src/libGL/libGL_autogen.def',2611]26122613if sys.argv[1] == 'inputs':2614print(','.join(inputs))2615elif sys.argv[1] == 'outputs':2616print(','.join(outputs))2617else:2618print('Invalid script parameters')2619return 12620return 026212622glesdecls = {}2623glesdecls['core'] = {}2624glesdecls['exts'] = {}2625for ver in registry_xml.GLES_VERSIONS:2626glesdecls['core'][ver] = []2627for ver in ['GLES1 Extensions', 'GLES2+ Extensions', 'ANGLE Extensions']:2628glesdecls['exts'][ver] = {}26292630libgles_ep_defs = []2631libgles_ep_exports = []26322633xml = registry_xml.RegistryXML('gl.xml', 'gl_angle_ext.xml')26342635# Stores core commands to keep track of duplicates2636all_commands_no_suffix = []2637all_commands_with_suffix = []26382639# First run through the main GLES entry points. Since ES2+ is the primary use2640# case, we go through those first and then add ES1-only APIs at the end.2641for major_version, minor_version in registry_xml.GLES_VERSIONS:2642version = "{}_{}".format(major_version, minor_version)2643annotation = "GLES_{}".format(version)2644name_prefix = "GL_ES_VERSION_"26452646if major_version == 1:2647name_prefix = "GL_VERSION_ES_CM_"26482649comment = version.replace("_", ".")2650feature_name = "{}{}".format(name_prefix, version)26512652xml.AddCommands(feature_name, version)26532654version_commands = xml.commands[version]2655all_commands_no_suffix.extend(xml.commands[version])2656all_commands_with_suffix.extend(xml.commands[version])26572658eps = GLEntryPoints(apis.GLES, xml, version_commands)2659eps.decls.insert(0, "extern \"C\" {")2660eps.decls.append("} // extern \"C\"")2661eps.defs.insert(0, "extern \"C\" {")2662eps.defs.append("} // extern \"C\"")26632664# Write the version as a comment before the first EP.2665libgles_ep_exports.append("\n ; OpenGL ES %s" % comment)26662667libgles_ep_defs += ["\n// OpenGL ES %s" % comment] + eps.export_defs2668libgles_ep_exports += get_exports(version_commands)26692670major_if_not_one = major_version if major_version != 1 else ""2671minor_if_not_zero = minor_version if minor_version != 0 else ""26722673header_includes = TEMPLATE_HEADER_INCLUDES.format(2674major=major_if_not_one, minor=minor_if_not_zero)26752676# We include the platform.h header since it undefines the conflicting MemoryBarrier macro.2677if major_version == 3 and minor_version == 1:2678header_includes += "\n#include \"common/platform.h\"\n"26792680version_annotation = "%s%s" % (major_version, minor_if_not_zero)2681source_includes = TEMPLATE_SOURCES_INCLUDES.format(2682header_version=annotation.lower(), validation_header_version="ES" + version_annotation)26832684write_file(annotation, "GLES " + comment, TEMPLATE_ENTRY_POINT_HEADER,2685"\n".join(eps.decls), "h", header_includes, "libGLESv2", "gl.xml")2686write_file(annotation, "GLES " + comment, TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(eps.defs),2687"cpp", source_includes, "libGLESv2", "gl.xml")26882689glesdecls['core'][(major_version,2690minor_version)] = get_decls(apis.GLES, CONTEXT_DECL_FORMAT,2691xml.all_commands, version_commands, [],2692GLEntryPoints.get_packed_enums())26932694validation_annotation = "ES%s%s" % (major_version, minor_if_not_zero)2695write_gl_validation_header(validation_annotation, "ES %s" % comment, eps.validation_protos,2696"gl.xml and gl_angle_ext.xml")26972698write_capture_header(version, comment, eps.capture_protos, eps.capture_pointer_funcs)2699write_capture_source(version, validation_annotation, comment, eps.capture_methods)27002701# After we finish with the main entry points, we process the extensions.2702extension_decls = ["extern \"C\" {"]2703extension_defs = ["extern \"C\" {"]2704extension_commands = []27052706# Accumulated validation prototypes.2707ext_validation_protos = []2708ext_capture_protos = []2709ext_capture_methods = []2710ext_capture_pointer_funcs = []27112712for gles1ext in registry_xml.gles1_extensions:2713glesdecls['exts']['GLES1 Extensions'][gles1ext] = []2714for glesext in registry_xml.gles_extensions:2715glesdecls['exts']['GLES2+ Extensions'][glesext] = []2716for angle_ext in registry_xml.angle_extensions:2717glesdecls['exts']['ANGLE Extensions'][angle_ext] = []27182719xml.AddExtensionCommands(registry_xml.supported_extensions, ['gles2', 'gles1'])27202721for extension_name, ext_cmd_names in sorted(xml.ext_data.items()):2722extension_commands.extend(xml.ext_data[extension_name])27232724# Detect and filter duplicate extensions.2725eps = GLEntryPoints(apis.GLES, xml, ext_cmd_names)27262727# Write the extension name as a comment before the first EP.2728comment = "\n// {}".format(extension_name)2729libgles_ep_exports.append("\n ; %s" % extension_name)27302731extension_defs += [comment] + eps.defs2732extension_decls += [comment] + eps.decls27332734# Avoid writing out entry points defined by a prior extension.2735for dupe in xml.ext_dupes[extension_name]:2736msg = "// {} is already defined.\n".format(strip_api_prefix(dupe))2737extension_defs.append(msg)27382739ext_validation_protos += [comment] + eps.validation_protos2740ext_capture_protos += [comment] + eps.capture_protos2741ext_capture_methods += eps.capture_methods2742ext_capture_pointer_funcs += eps.capture_pointer_funcs27432744libgles_ep_defs += [comment] + eps.export_defs2745libgles_ep_exports += get_exports(ext_cmd_names)27462747if (extension_name in registry_xml.gles1_extensions and2748extension_name not in GLES1_NO_CONTEXT_DECL_EXTENSIONS):2749glesdecls['exts']['GLES1 Extensions'][extension_name] = get_decls(2750apis.GLES, CONTEXT_DECL_FORMAT, xml.all_commands, ext_cmd_names,2751all_commands_no_suffix, GLEntryPoints.get_packed_enums())2752if extension_name in registry_xml.gles_extensions:2753glesdecls['exts']['GLES2+ Extensions'][extension_name] = get_decls(2754apis.GLES, CONTEXT_DECL_FORMAT, xml.all_commands, ext_cmd_names,2755all_commands_no_suffix, GLEntryPoints.get_packed_enums())2756if extension_name in registry_xml.angle_extensions:2757glesdecls['exts']['ANGLE Extensions'][extension_name] = get_decls(2758apis.GLES, CONTEXT_DECL_FORMAT, xml.all_commands, ext_cmd_names,2759all_commands_no_suffix, GLEntryPoints.get_packed_enums())27602761for name in extension_commands:2762all_commands_with_suffix.append(name)2763all_commands_no_suffix.append(strip_suffix(apis.GLES, name))27642765# Now we generate entry points for the desktop implementation2766desktop_gl_decls = {}2767desktop_gl_decls['core'] = {}2768for major, _ in registry_xml.DESKTOP_GL_VERSIONS:2769desktop_gl_decls['core'][(major, "X")] = []27702771libgl_ep_defs = []2772libgl_ep_exports = []27732774glxml = registry_xml.RegistryXML('gl.xml')27752776for major_version in sorted(2777set([major for (major, minor) in registry_xml.DESKTOP_GL_VERSIONS])):2778is_major = lambda ver: ver[0] == major_version27792780ver_decls = ["extern \"C\" {"]2781ver_defs = ["extern \"C\" {"]2782validation_protos = []27832784for _, minor_version in filter(is_major, registry_xml.DESKTOP_GL_VERSIONS):2785version = "{}_{}".format(major_version, minor_version)2786annotation = "GL_{}".format(version)2787name_prefix = "GL_VERSION_"27882789comment = version.replace("_", ".")2790feature_name = "{}{}".format(name_prefix, version)27912792glxml.AddCommands(feature_name, version)27932794all_libgl_commands = glxml.commands[version]27952796just_libgl_commands = [2797cmd for cmd in all_libgl_commands if cmd not in all_commands_no_suffix2798]2799just_libgl_commands_suffix = [2800cmd for cmd in all_libgl_commands if cmd not in all_commands_with_suffix2801]28022803# Validation duplicates handled with suffix2804eps_suffix = GLEntryPoints(apis.GL, glxml, just_libgl_commands_suffix)2805eps = GLEntryPoints(apis.GL, glxml, all_libgl_commands)28062807desktop_gl_decls['core'][(major_version,2808"X")] += get_decls(apis.GL, CONTEXT_DECL_FORMAT,2809glxml.all_commands, just_libgl_commands,2810all_commands_no_suffix,2811GLEntryPoints.get_packed_enums())28122813# Write the version as a comment before the first EP.2814cpp_comment = "\n// GL %s" % comment2815def_comment = "\n ; GL %s" % comment28162817libgl_ep_defs += [cpp_comment] + eps.export_defs2818libgl_ep_exports += [def_comment] + get_exports(all_libgl_commands)2819validation_protos += [cpp_comment] + eps_suffix.validation_protos2820ver_decls += [cpp_comment] + eps.decls2821ver_defs += [cpp_comment] + eps.defs28222823ver_decls.append("} // extern \"C\"")2824ver_defs.append("} // extern \"C\"")2825annotation = "GL_%d" % major_version2826name = "Desktop GL %s.x" % major_version28272828source_includes = TEMPLATE_DESKTOP_GL_SOURCE_INCLUDES.format(annotation.lower(),2829major_version)28302831# Entry point files2832write_file(annotation, name, TEMPLATE_ENTRY_POINT_HEADER, "\n".join(ver_decls), "h",2833DESKTOP_GL_HEADER_INCLUDES, "libGL", "gl.xml")2834write_file(annotation, name, TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(ver_defs), "cpp",2835source_includes, "libGL", "gl.xml")28362837# Validation files2838write_gl_validation_header("GL%s" % major_version, name, validation_protos, "gl.xml")28392840# OpenCL2841clxml = registry_xml.RegistryXML('cl.xml')28422843cl_validation_protos = []2844cl_decls = ["namespace cl\n{"]2845cl_defs = ["namespace cl\n{"]2846libcl_ep_defs = []2847libcl_windows_def_exports = []2848cl_commands = []28492850for major_version, minor_version in registry_xml.CL_VERSIONS:2851version = "%d_%d" % (major_version, minor_version)2852annotation = "CL_%s" % version2853name_prefix = "CL_VERSION_"28542855comment = version.replace("_", ".")2856feature_name = "%s%s" % (name_prefix, version)28572858clxml.AddCommands(feature_name, version)28592860cl_version_commands = clxml.commands[version]2861cl_commands += cl_version_commands28622863# Spec revs may have no new commands.2864if not cl_version_commands:2865continue28662867eps = CLEntryPoints(clxml, cl_version_commands)28682869comment = "\n// CL %d.%d" % (major_version, minor_version)2870win_def_comment = "\n ; CL %d.%d" % (major_version, minor_version)28712872cl_decls += [comment] + eps.decls2873cl_defs += [comment] + eps.defs2874libcl_ep_defs += [comment] + eps.export_defs2875cl_validation_protos += [comment] + eps.validation_protos2876libcl_windows_def_exports += [win_def_comment] + get_exports(clxml.commands[version])28772878clxml.AddExtensionCommands(registry_xml.supported_cl_extensions, ['cl'])2879for extension_name, ext_cmd_names in sorted(clxml.ext_data.items()):28802881# Extensions may have no new commands.2882if not ext_cmd_names:2883continue28842885# Detect and filter duplicate extensions.2886eps = CLEntryPoints(clxml, ext_cmd_names)28872888comment = "\n// %s" % extension_name2889win_def_comment = "\n ; %s" % (extension_name)28902891cl_commands += ext_cmd_names28922893cl_decls += [comment] + eps.decls2894cl_defs += [comment] + eps.defs2895libcl_ep_defs += [comment] + eps.export_defs2896cl_validation_protos += [comment] + eps.validation_protos2897libcl_windows_def_exports += [win_def_comment] + get_exports(ext_cmd_names)28982899# Avoid writing out entry points defined by a prior extension.2900for dupe in clxml.ext_dupes[extension_name]:2901msg = "// %s is already defined.\n" % strip_api_prefix(dupe)2902cl_defs.append(msg)29032904cl_decls.append("} // namespace cl")2905cl_defs.append("} // namespace cl")29062907write_file("cl", "CL", TEMPLATE_ENTRY_POINT_HEADER, "\n".join(cl_decls), "h",2908LIBCL_HEADER_INCLUDES, "libGLESv2", "cl.xml")2909write_file("cl", "CL", TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(cl_defs), "cpp",2910LIBCL_SOURCE_INCLUDES, "libGLESv2", "cl.xml")2911write_validation_header("CL", "CL", cl_validation_protos, "cl.xml",2912TEMPLATE_CL_VALIDATION_HEADER)2913write_stubs_header("CL", "cl", "CL", "cl.xml", CL_STUBS_HEADER_PATH, clxml.all_commands,2914cl_commands, CLEntryPoints.get_packed_enums(), CL_PACKED_TYPES)29152916# EGL2917eglxml = registry_xml.RegistryXML('egl.xml', 'egl_angle_ext.xml')29182919egl_validation_protos = []2920egl_decls = ["extern \"C\" {"]2921egl_defs = ["extern \"C\" {"]2922libegl_ep_defs = []2923libegl_windows_def_exports = []2924egl_commands = []29252926for major_version, minor_version in registry_xml.EGL_VERSIONS:2927version = "%d_%d" % (major_version, minor_version)2928annotation = "EGL_%s" % version2929name_prefix = "EGL_VERSION_"29302931comment = version.replace("_", ".")2932feature_name = "%s%s" % (name_prefix, version)29332934eglxml.AddCommands(feature_name, version)29352936egl_version_commands = eglxml.commands[version]2937egl_commands += egl_version_commands29382939# Spec revs may have no new commands.2940if not egl_version_commands:2941continue29422943eps = EGLEntryPoints(eglxml, egl_version_commands)29442945comment = "\n// EGL %d.%d" % (major_version, minor_version)2946win_def_comment = "\n ; EGL %d.%d" % (major_version, minor_version)29472948egl_decls += [comment] + eps.decls2949egl_defs += [comment] + eps.defs2950libegl_ep_defs += [comment] + eps.export_defs2951egl_validation_protos += [comment] + eps.validation_protos2952libegl_windows_def_exports += [win_def_comment] + get_exports(eglxml.commands[version])29532954egl_decls.append("} // extern \"C\"")2955egl_defs.append("} // extern \"C\"")29562957write_file("egl", "EGL", TEMPLATE_ENTRY_POINT_HEADER, "\n".join(egl_decls), "h",2958EGL_HEADER_INCLUDES, "libGLESv2", "egl.xml")2959write_file("egl", "EGL", TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(egl_defs), "cpp",2960EGL_SOURCE_INCLUDES, "libGLESv2", "egl.xml")2961write_stubs_header("EGL", "egl", "EGL", "egl.xml", EGL_STUBS_HEADER_PATH, eglxml.all_commands,2962egl_commands, EGLEntryPoints.get_packed_enums(), EGL_PACKED_TYPES)29632964eglxml.AddExtensionCommands(registry_xml.supported_egl_extensions, ['egl'])2965egl_ext_decls = ["extern \"C\" {"]2966egl_ext_defs = ["extern \"C\" {"]2967egl_ext_commands = []29682969for extension_name, ext_cmd_names in sorted(eglxml.ext_data.items()):29702971# Extensions may have no new commands.2972if not ext_cmd_names:2973continue29742975# Detect and filter duplicate extensions.2976eps = EGLEntryPoints(eglxml, ext_cmd_names)29772978comment = "\n// %s" % extension_name2979win_def_comment = "\n ; %s" % (extension_name)29802981egl_ext_commands += ext_cmd_names29822983egl_ext_decls += [comment] + eps.decls2984egl_ext_defs += [comment] + eps.defs2985libegl_ep_defs += [comment] + eps.export_defs2986egl_validation_protos += [comment] + eps.validation_protos2987libegl_windows_def_exports += [win_def_comment] + get_exports(ext_cmd_names)29882989# Avoid writing out entry points defined by a prior extension.2990for dupe in eglxml.ext_dupes[extension_name]:2991msg = "// %s is already defined.\n" % strip_api_prefix(dupe)2992egl_ext_defs.append(msg)29932994egl_ext_decls.append("} // extern \"C\"")2995egl_ext_defs.append("} // extern \"C\"")29962997write_file("egl_ext", "EGL Extension", TEMPLATE_ENTRY_POINT_HEADER, "\n".join(egl_ext_decls),2998"h", EGL_EXT_HEADER_INCLUDES, "libGLESv2", "egl.xml and egl_angle_ext.xml")2999write_file("egl_ext", "EGL Extension", TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(egl_ext_defs),3000"cpp", EGL_EXT_SOURCE_INCLUDES, "libGLESv2", "egl.xml and egl_angle_ext.xml")3001write_validation_header("EGL", "EGL", egl_validation_protos, "egl.xml and egl_angle_ext.xml",3002TEMPLATE_EGL_VALIDATION_HEADER)3003write_stubs_header("EGL", "egl_ext", "EXT extension", "egl.xml and egl_angle_ext.xml",3004EGL_EXT_STUBS_HEADER_PATH, eglxml.all_commands, egl_ext_commands,3005EGLEntryPoints.get_packed_enums(), EGL_PACKED_TYPES)30063007# WGL3008wglxml = registry_xml.RegistryXML('wgl.xml')30093010name_prefix = "WGL_VERSION_"3011version = "1_0"3012comment = version.replace("_", ".")3013feature_name = "{}{}".format(name_prefix, version)3014wglxml.AddCommands(feature_name, version)3015wgl_commands = wglxml.commands[version]30163017wgl_commands = [cmd if cmd[:3] == 'wgl' else 'wgl' + cmd for cmd in wgl_commands]30183019# Write the version as a comment before the first EP.3020libgl_ep_exports.append("\n ; WGL %s" % comment)30213022# Other versions of these functions are used3023wgl_commands.remove("wglUseFontBitmaps")3024wgl_commands.remove("wglUseFontOutlines")30253026libgl_ep_exports += get_exports(wgl_commands)3027extension_decls.append("} // extern \"C\"")3028extension_defs.append("} // extern \"C\"")30293030write_file("gles_ext", "GLES extension", TEMPLATE_ENTRY_POINT_HEADER,3031"\n".join([item for item in extension_decls]), "h", GLES_EXT_HEADER_INCLUDES,3032"libGLESv2", "gl.xml and gl_angle_ext.xml")3033write_file("gles_ext", "GLES extension", TEMPLATE_ENTRY_POINT_SOURCE,3034"\n".join([item for item in extension_defs]), "cpp", GLES_EXT_SOURCE_INCLUDES,3035"libGLESv2", "gl.xml and gl_angle_ext.xml")30363037write_gl_validation_header("ESEXT", "ES extension", ext_validation_protos,3038"gl.xml and gl_angle_ext.xml")3039write_capture_header("ext", "extension", ext_capture_protos, ext_capture_pointer_funcs)3040write_capture_source("ext", "ESEXT", "extension", ext_capture_methods)30413042write_context_api_decls(glesdecls, "gles")3043write_context_api_decls(desktop_gl_decls, "gl")30443045# Entry point enum3046cl_cmd_names = [strip_api_prefix(cmd) for cmd in clxml.all_cmd_names.get_all_commands()]3047egl_cmd_names = [strip_api_prefix(cmd) for cmd in eglxml.all_cmd_names.get_all_commands()]3048gles_cmd_names = ["Invalid"3049] + [strip_api_prefix(cmd) for cmd in xml.all_cmd_names.get_all_commands()]3050gl_cmd_names = [strip_api_prefix(cmd) for cmd in glxml.all_cmd_names.get_all_commands()]3051wgl_cmd_names = [strip_api_prefix(cmd) for cmd in wglxml.all_cmd_names.get_all_commands()]3052unsorted_enums = [("CL%s" % cmd, "cl%s" % cmd) for cmd in cl_cmd_names] + [3053("EGL%s" % cmd, "egl%s" % cmd) for cmd in egl_cmd_names3054] + [("GL%s" % cmd, "gl%s" % cmd) for cmd in set(gles_cmd_names + gl_cmd_names)3055] + [("WGL%s" % cmd, "wgl%s" % cmd) for cmd in wgl_cmd_names]3056all_enums = sorted(unsorted_enums)30573058entry_points_enum_header = TEMPLATE_ENTRY_POINTS_ENUM_HEADER.format(3059script_name=os.path.basename(sys.argv[0]),3060data_source_name="gl.xml and gl_angle_ext.xml",3061lib="GL/GLES",3062entry_points_list=",\n".join([" " + enum for (enum, _) in all_enums]))30633064entry_points_enum_header_path = path_to("common", "entry_points_enum_autogen.h")3065with open(entry_points_enum_header_path, "w") as out:3066out.write(entry_points_enum_header)3067out.close()30683069entry_points_cases = [3070TEMPLATE_ENTRY_POINTS_NAME_CASE.format(enum=enum, cmd=cmd) for (enum, cmd) in all_enums3071]3072entry_points_enum_source = TEMPLATE_ENTRY_POINTS_ENUM_SOURCE.format(3073script_name=os.path.basename(sys.argv[0]),3074data_source_name="gl.xml and gl_angle_ext.xml",3075lib="GL/GLES",3076entry_points_name_cases="\n".join(entry_points_cases))30773078entry_points_enum_source_path = path_to("common", "entry_points_enum_autogen.cpp")3079with open(entry_points_enum_source_path, "w") as out:3080out.write(entry_points_enum_source)3081out.close()30823083write_export_files("\n".join([item for item in libgles_ep_defs]), LIBGLESV2_EXPORT_INCLUDES,3084"gl.xml and gl_angle_ext.xml", "libGLESv2", "OpenGL ES")3085write_export_files("\n".join([item for item in libgl_ep_defs]), LIBGL_EXPORT_INCLUDES,3086"gl.xml and wgl.xml", "libGL", "Windows GL")3087write_export_files("\n".join([item for item in libegl_ep_defs]),3088LIBEGL_EXPORT_INCLUDES_AND_PREAMBLE, "egl.xml and egl_angle_ext.xml",3089"libEGL", "EGL")3090write_export_files("\n".join([item for item in libcl_ep_defs]), LIBCL_EXPORT_INCLUDES,3091"cl.xml", "libOpenCL", "CL")30923093libgles_ep_exports += get_egl_exports()30943095everything = "Khronos and ANGLE XML files"30963097for lib in ["libGLESv2" + suffix for suffix in ["", "_no_capture", "_with_capture"]]:3098write_windows_def_file(everything, lib, lib, "libGLESv2", libgles_ep_exports)3099write_windows_def_file(everything, "libGL", "openGL32", "libGL", libgl_ep_exports)3100write_windows_def_file("egl.xml and egl_angle_ext.xml", "libEGL", "libEGL", "libEGL",3101libegl_windows_def_exports)31023103all_gles_param_types = sorted(GLEntryPoints.all_param_types)3104all_egl_param_types = sorted(EGLEntryPoints.all_param_types)3105# Get a sorted list of param types without duplicates3106all_param_types = sorted(list(set(all_gles_param_types + all_egl_param_types)))3107write_capture_helper_header(all_param_types)3108write_capture_helper_source(all_param_types)3109write_capture_replay_source(apis.GLES, xml.all_commands, all_commands_no_suffix,3110GLEntryPoints.get_packed_enums(), [])311131123113if __name__ == '__main__':3114sys.exit(main())311531163117