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 #-------------------------------------------------------------------------
26 from egl.common import *
27 from khr_util.format import indentLines
30 def __init__ (self, argInPrints, argOutPrints = {}, returnPrint = None):
31 self.argInPrints = argInPrints
32 self.argOutPrints = argOutPrints
33 self.returnPrint = returnPrint
36 return lambda name: "get%sStr(%s)" % (group, name)
39 return lambda name: "getPointerStr(%s, %s)" % (name, size)
41 def enumPointer (group, size):
42 return lambda name: "getEnumPointerStr<%(nameFunc)s>(%(name)s, %(size)s)" % {"name": name, "size": size, "nameFunc": ("get%sName" % group)}
44 def configAttrib (attribNdx):
45 return lambda name: "getConfigAttribValueStr(param%d, %s)" % (attribNdx, name)
47 # Special rules for printing call arguments
49 "eglBindAPI": LogSpec({0: enum("API")}),
50 "eglChooseConfig": LogSpec({1: lambda n: "getConfigAttribListStr(%s)" % n}, argOutPrints = {2: pointer("(num_config && returnValue) ? deMin32(config_size, *num_config) : 0"), 4: lambda n: "(%s ? de::toString(*%s) : \"NULL\")" % (n, n)}),
51 "eglCreateContext": LogSpec({3: lambda n: "getContextAttribListStr(%s)" % n}),
52 "eglCreatePbufferSurface": LogSpec({2: lambda n: "getSurfaceAttribListStr(%s)" % n}),
53 "eglCreatePixmapSurface": LogSpec({3: lambda n: "getSurfaceAttribListStr(%s)" % n}),
54 "eglCreateWindowSurface": LogSpec({3: lambda n: "getSurfaceAttribListStr(%s)" % n}),
55 "eglGetError": LogSpec({}, returnPrint = enum("Error")),
56 "eglGetConfigAttrib": LogSpec({2: enum("ConfigAttrib")}, argOutPrints = {3: lambda n: "getConfigAttribValuePointerStr(attribute, %s)" % n}),
57 "eglGetCurrentSurface": LogSpec({0: enum("SurfaceTarget")}),
58 "eglGetProcAddress": LogSpec({}, returnPrint = lambda n: "tcu::toHex(%s)" % (n)),
59 "eglQueryAPI": LogSpec({}, returnPrint = enum("API")),
60 "eglQueryContext": LogSpec({2: enum("ContextAttrib")}, argOutPrints = {3: lambda n: "getContextAttribValuePointerStr(attribute, %s)" % n}),
61 "eglQuerySurface": LogSpec({2: enum("SurfaceAttrib")}, argOutPrints = {3: lambda n: "getSurfaceAttribValuePointerStr(attribute, %s)" % n}),
62 "eglSurfaceAttrib": LogSpec({2: enum("SurfaceAttrib"), 3: lambda n: "getSurfaceAttribValueStr(attribute, %s)" % n}),
65 def eglwPrefix (string):
66 if string[:5] == "__egl":
67 return "eglw::" + string
69 return re.sub(r'\bEGL', 'eglw::EGL', string)
71 def prefixedParams (command):
72 if len(command.params) > 0:
73 return ", ".join(eglwPrefix(param.declaration) for param in command.params)
77 def commandLogWrapperMemberDecl (command):
78 return "%s\t%s\t(%s);" % (eglwPrefix(command.type), command.name, prefixedParams(command))
80 def getVarDefaultPrint (type, varName):
81 if re.match(r'^const +char *\*$', type):
82 return "getStringStr(%s)" % varName
83 elif re.match(r'(EGLenum|EGLConfig|EGLSurface|EGLClientBuffer|EGLNativeDisplayType|EGLNativeWindowType|EGLNativePixmapType|\*)$', type):
84 return "toHex(%s)" % varName
85 elif type == 'EGLBoolean':
86 return "getBooleanStr(%s)" % varName
90 def commandLogWrapperMemberDef (command):
93 logSpec = CALL_LOG_SPECS[command.name]
98 src += "%s CallLogWrapper::%s (%s)\n{\n" % (eglwPrefix(command.type), command.name, ", ".join(eglwPrefix(p.declaration) for p in command.params))
101 callPrintItems = ["\"%s(\"" % command.name]
102 for paramNdx, param in enumerate(command.params):
104 callPrintItems.append("\", \"")
106 if logSpec and paramNdx in logSpec.argInPrints:
107 callPrintItems.append(logSpec.argInPrints[paramNdx](param.name))
109 callPrintItems.append(getVarDefaultPrint(param.type, param.name))
111 callPrintItems += ["\");\"", "TestLog::EndMessage"]
113 src += "\tif (m_enableLog)\n"
114 src += "\t\tm_log << TestLog::Message << %s;\n" % " << ".join(callPrintItems)
116 callStr = "m_egl.%s(%s)" % (getFunctionMemberName(command.name), ", ".join([p.name for p in command.params]))
118 isVoid = command.type == 'void'
120 src += "\t%s;\n" % callStr
122 src += "\t%s returnValue = %s;\n" % (eglwPrefix(command.type), callStr)
124 if logSpec and len(logSpec.argOutPrints) > 0:
125 # Print values returned in pointers
126 src += "\tif (m_enableLog)\n\t{\n"
128 for paramNdx, param in enumerate(command.params):
129 if paramNdx in logSpec.argOutPrints:
130 src += "\t\tm_log << TestLog::Message << \"// %s = \" << %s << TestLog::EndMessage;\n" % (param.name, logSpec.argOutPrints[paramNdx](param.name))
136 returnPrint = getVarDefaultPrint(command.type, "returnValue")
137 if logSpec and logSpec.returnPrint:
138 returnPrint = logSpec.returnPrint("returnValue")
140 src += "\tif (m_enableLog)\n"
141 src += "\t\tm_log << TestLog::Message << \"// \" << %s << \" returned\" << TestLog::EndMessage;\n" % returnPrint
142 src += "\treturn returnValue;\n"
148 genCommandList(iface, commandLogWrapperMemberDecl, EGL_DIR, "egluCallLogWrapperApi.inl", True)
149 genCommandList(iface, commandLogWrapperMemberDef, EGL_DIR, "egluCallLogWrapper.inl", False)