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 egl.common import *
25 from egl.enums import enumValue
26 from egl.library import getExtOnlyIface
27 from khr_util.format import indentLines
28 from itertools import chain
31 from itertools import imap
35 def getMangledName (funcName):
36 assert funcName[:3] == "egl"
37 return "eglw" + funcName[3:]
39 def commandAliasDefinition (command):
40 return "#define\t%s\t%s" % (command.name, getMangledName(command.name))
42 def commandWrapperDeclaration (command):
43 return "%s\t%s\t(%s);" % (
45 getMangledName(command.name),
46 ", ".join([param.declaration for param in command.params]))
49 "EGLNativeWindowType",
50 "EGLNativeDisplayType",
51 "EGLNativePixmapType",
54 def commandWrapperDefinition (command):
56 {returnType} {mangledName} ({paramDecls})
58 const eglw::Library* egl = eglw::getCurrentThreadLibrary();
60 return{defaultReturn};
61 {maybeReturn}egl->{memberName}({arguments});
66 for param in command.params:
67 if param.type in NATIVE_TYPES:
68 arguments.append("(void*)" + param.name)
70 arguments.append(param.name)
72 return template.format(
73 returnType = command.type,
74 mangledName = "eglw" + command.name[3:],
75 paramDecls = commandParams(command),
76 defaultReturn = " " + getDefaultReturn(command) if command.type != 'void' else "",
77 maybeReturn = "return " if command.type != 'void' else "",
78 memberName = getFunctionMemberName(command.name),
79 arguments = ", ".join(arguments))
81 def getDefaultReturn (command):
82 if command.name == "glGetError":
83 return "GL_INVALID_OPERATION"
85 assert command.type != 'void'
86 return "(%s)0" % command.type
88 commandParams = khr_util.format.commandParams
90 def enumDefinitionC (enum):
91 return "#define %s\t%s" % (enum.name, enumValue(enum))
94 noExtIface = getInterface(registry, 'egl', VERSION)
95 extOnlyIface = getExtOnlyIface(registry, 'egl', EXTENSIONS)
96 defaultIface = getDefaultInterface()
97 defines = imap(commandAliasDefinition, defaultIface.commands)
98 prototypes = imap(commandWrapperDeclaration, defaultIface.commands)
99 src = indentLines(chain(defines, prototypes))
101 writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwApi.inl"), src)
102 writeInlFile(os.path.join(EGL_WRAPPER_DIR, "eglwEnumsC.inl"), indentLines(map(enumDefinitionC, defaultIface.enums)))
103 genCommandList(noExtIface, commandWrapperDefinition, EGL_WRAPPER_DIR, "eglwImpl.inl")
104 genCommandList(extOnlyIface, commandWrapperDefinition, EGL_WRAPPER_DIR, "eglwImplExt.inl")