Hash :
9f088621
Author :
Date :
2018-12-29T20:46:15
Revert "Load entry points dynamically in tests and samples." This reverts commit 03923558a7103827ffec6a4d2a1453ed91f01c6f. Reason for revert: fails compilation on Android, ChromeOS and Fuchsia during roll https://chromium-review.googlesource.com/c/chromium/src/+/1392624 Original change's description: > Load entry points dynamically in tests and samples. > > This CL adds a dynamic loader generator based on XML files. It also > refactors the entry point generation script to move the XML parsing > into a helper class. > > Additionally this includes a new GLES 1.0 base header. The new > header allows for function pointer types and hiding prototypes. > > All tests and samples now load ANGLE dynamically. In the future this > will be extended to load entry points from the driver directly when > possible. This will allow us to perform more accurate A/B testing. > > The new build configuration leads to some tests having more warnings > applied. The CL includes fixes for the new warnings. > > Bug: angleproject:2995 > Change-Id: I6726d4163f7a6e54d2482f094c0a952f59702a05 > Reviewed-on: https://chromium-review.googlesource.com/c/1359516 > Commit-Queue: Jamie Madill <jmadill@chromium.org> > Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> TBR=ynovikov@chromium.org,jmadill@chromium.org,syoussefi@chromium.org Change-Id: I902bec2d733c2b879be29c02ab52a0b7d4eaa077 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: angleproject:2995 Reviewed-on: https://chromium-review.googlesource.com/c/1392381 Reviewed-by: Yuly Novikov <ynovikov@chromium.org> Commit-Queue: Yuly Novikov <ynovikov@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
#!/usr/bin/python2
#
# Copyright 2018 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# generate_loader.py:
# Generates dynamic loaders for various binding interfaces.
import sys, os, pprint, json
from datetime import date
import registry_xml
# Handle inputs/outputs for run_code_generation.py's auto_script
if len(sys.argv) == 2 and sys.argv[1] == 'inputs':
inputs = [
'egl.xml',
'egl_angle_ext.xml',
'registry_xml.py',
]
print(",".join(inputs))
sys.exit(0)
def write_header(data_source_name, all_cmds, api, preamble, path, ns = "", prefix = None):
file_name = "%s_loader_autogen.h" % api
header_path = registry_xml.path_to(path, file_name)
if prefix == None:
prefix = api
def pre(cmd):
return prefix + cmd[len(api):]
with open(header_path, "w") as out:
var_protos = ["extern PFN%sPROC %s%s;" % (cmd.upper(), ns, pre(cmd)) for cmd in all_cmds]
loader_header = template_loader_h.format(
script_name = os.path.basename(sys.argv[0]),
data_source_name = data_source_name,
year = date.today().year,
function_pointers = "\n".join(var_protos),
api_upper = api.upper(),
api_lower = api,
preamble = preamble)
out.write(loader_header)
out.close()
def write_source(data_source_name, all_cmds, api, path, ns = "", prefix = None):
file_name = "%s_loader_autogen.cpp" % api
source_path = registry_xml.path_to(path, file_name)
if prefix == None:
prefix = api
def pre(cmd):
return prefix + cmd[len(api):]
with open(source_path, "w") as out:
var_defs = ["PFN%sPROC %s%s;" % (cmd.upper(), ns, pre(cmd)) for cmd in all_cmds]
setter = " %s%s = reinterpret_cast<PFN%sPROC>(loadProc(\"%s\"));"
setters = [setter % (ns, pre(cmd), cmd.upper(), pre(cmd)) for cmd in all_cmds]
loader_source = template_loader_cpp.format(
script_name = os.path.basename(sys.argv[0]),
data_source_name = data_source_name,
year = date.today().year,
function_pointers = "\n".join(var_defs),
set_pointers = "\n".join(setters),
api_upper = api.upper(),
api_lower = api)
out.write(loader_source)
out.close()
def gen_libegl_loader():
data_source_name = "egl.xml and egl_angle_ext.xml"
xml = registry_xml.RegistryXML("egl.xml", "egl_angle_ext.xml")
for major_version, minor_version in [[1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5]]:
annotation = "{}_{}".format(major_version, minor_version)
name_prefix = "EGL_VERSION_"
feature_name = "{}{}".format(name_prefix, annotation)
xml.AddCommands(feature_name, annotation)
xml.AddExtensionCommands(registry_xml.supported_egl_extensions, ['egl'])
all_cmds = xml.all_cmd_names.get_all_commands()
path = os.path.join("..", "src", "libEGL")
write_header(data_source_name, all_cmds, "egl", egl_preamble, path, "", "EGL_")
write_source(data_source_name, all_cmds, "egl", path, "", "EGL_")
# Generate simple function loader for the tests.
def main():
gen_libegl_loader()
gles_preamble = """#if defined(GL_GLES_PROTOTYPES)
#undef GL_GLES_PROTOTYPES
#endif // defined(GL_GLES_PROTOTYPES)
#if defined(GL_GLEXT_PROTOTYPES)
#undef GL_GLEXT_PROTOTYPES
#endif // defined(GL_GLEXT_PROTOTYPES)
#define GL_GLES_PROTOTYPES 0
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>
#include <GLES3/gl31.h>
#include <GLES3/gl32.h>
"""
egl_preamble = """#include <EGL/egl.h>
#include <EGL/eglext.h>
"""
template_loader_h = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {data_source_name}.
//
// Copyright {year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// {api_lower}_loader_autogen.h:
// Simple {api_upper} function loader.
#ifndef LIBEGL_{api_upper}_LOADER_AUTOGEN_H_
#define LIBEGL_{api_upper}_LOADER_AUTOGEN_H_
{preamble}
{function_pointers}
namespace angle
{{
using GenericProc = void (*)();
using LoadProc = GenericProc (KHRONOS_APIENTRY *)(const char *);
void Load{api_upper}(LoadProc loadProc);
}} // namespace angle
#endif // LIBEGL_{api_upper}_LOADER_AUTOGEN_H_
"""
template_loader_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {data_source_name}.
//
// Copyright {year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// {api_lower}_loader_autogen.cpp:
// Simple {api_upper} function loader.
#include "{api_lower}_loader_autogen.h"
{function_pointers}
namespace angle
{{
void Load{api_upper}(LoadProc loadProc)
{{
{set_pointers}
}}
}} // namespace angle
"""
if __name__ == '__main__':
sys.exit(main())