Update Vulkan CTS to version 1.0.2.3 am: 633ab6f3c8 am: 399ba4a5ec am: a339444f14
[platform/upstream/VK-GL-CTS.git] / scripts / egl / gtf_wrapper.py
1 # -*- coding: utf-8 -*-
2
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
6 #
7 # Copyright 2015 The Android Open Source Project
8 #
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
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
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.
20 #
21 #-------------------------------------------------------------------------
22
23 import os
24 from itertools import imap, chain
25 from common import *
26 from enums import enumValue
27 from library import getExtOnlyIface
28 from khr_util.format import indentLines
29
30 def getMangledName (funcName):
31         assert funcName[:3] == "egl"
32         return "eglw" + funcName[3:]
33
34 def commandAliasDefinition (command):
35         return "#define\t%s\t%s" % (command.name, getMangledName(command.name))
36
37 def commandWrapperDeclaration (command):
38         return "%s\t%s\t(%s);" % (
39                 command.type,
40                 getMangledName(command.name),
41                 ", ".join([param.declaration for param in command.params]))
42
43 NATIVE_TYPES = [
44         "EGLNativeWindowType",
45         "EGLNativeDisplayType",
46         "EGLNativePixmapType",
47 ]
48
49 def commandWrapperDefinition (command):
50         template = """
51 {returnType} {mangledName} ({paramDecls})
52 {{
53         const eglw::Library* egl = eglw::getCurrentThreadLibrary();
54         if (!egl)
55                 return{defaultReturn};
56         {maybeReturn}egl->{memberName}({arguments});
57 }}"""
58
59         arguments = []
60
61         for param in command.params:
62                 if param.type in NATIVE_TYPES:
63                         arguments.append("(void*)" + param.name)
64                 else:
65                         arguments.append(param.name)
66
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))
75
76 def getDefaultReturn (command):
77         if command.name == "glGetError":
78                 return "GL_INVALID_OPERATION"
79         else:
80                 assert command.type != 'void'
81                 return "(%s)0" % command.type
82
83 commandParams = khr_util.format.commandParams
84
85 def enumDefinitionC (enum):
86         return "#define %s\t%s" % (enum.name, enumValue(enum))
87
88 def gen (registry):
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))
95
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")
100