1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2015 The Android Open Source Project
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
24 from itertools import imap, chain
26 from enums import enumValue
27 from library import getExtOnlyIface
28 from khr_util.format import indentLines
30 def getMangledName (funcName):
31 assert funcName[:3] == "egl"
32 return "eglw" + funcName[3:]
34 def commandAliasDefinition (command):
35 return "#define\t%s\t%s" % (command.name, getMangledName(command.name))
37 def commandWrapperDeclaration (command):
38 return "%s\t%s\t(%s);" % (
40 getMangledName(command.name),
41 ", ".join([param.declaration for param in command.params]))
44 "EGLNativeWindowType",
45 "EGLNativeDisplayType",
46 "EGLNativePixmapType",
49 def commandWrapperDefinition (command):
51 {returnType} {mangledName} ({paramDecls})
53 const eglw::Library* egl = eglw::getCurrentThreadLibrary();
55 return{defaultReturn};
56 {maybeReturn}egl->{memberName}({arguments});
61 for param in command.params:
62 if param.type in NATIVE_TYPES:
63 arguments.append("(void*)" + param.name)
65 arguments.append(param.name)
67 return template.format(
68 returnType = command.type,
69 mangledName = "eglw" + command.name[3:],
70 paramDecls = commandParams(command),
71 defaultReturn = " " + getDefaultReturn(command) if command.type != 'void' else "",
72 maybeReturn = "return " if command.type != 'void' else "",
73 memberName = getFunctionMemberName(command.name),
74 arguments = ", ".join(arguments))
76 def getDefaultReturn (command):
77 if command.name == "glGetError":
78 return "GL_INVALID_OPERATION"
80 assert command.type != 'void'
81 return "(%s)0" % command.type
83 commandParams = khr_util.format.commandParams
85 def enumDefinitionC (enum):
86 return "#define %s\t%s" % (enum.name, enumValue(enum))
89 noExtIface = getInterface(registry, 'egl', VERSION)
90 extOnlyIface = getExtOnlyIface(registry, 'egl', EXTENSIONS)
91 defaultIface = getDefaultInterface()
92 defines = imap(commandAliasDefinition, defaultIface.commands)
93 prototypes = imap(commandWrapperDeclaration, defaultIface.commands)
94 src = indentLines(chain(defines, prototypes))
96 writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwApi.inl"), src)
97 writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwEnumsC.inl"), indentLines(map(enumDefinitionC, defaultIface.enums)))
98 genCommandList(noExtIface, commandWrapperDefinition, EGL_WRAPPER_DIR, "eglwImpl.inl")
99 genCommandList(extOnlyIface, commandWrapperDefinition, EGL_WRAPPER_DIR, "eglwImplExt.inl")