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 23import os 24from src_util import * 25from itertools import chain 26 27try: 28 from itertools import imap 29except ImportError: 30 imap=map 31 32def getMangledName (funcName): 33 assert funcName[:2] == "gl" 34 return "glw" + funcName[2:] 35 36def commandAliasDefinition (command): 37 return "#define\t%s\t%s" % (command.name, getMangledName(command.name)) 38 39def commandWrapperDeclaration (command): 40 return "%s\t%s\t(%s);" % ( 41 command.type, 42 getMangledName(command.name), 43 ", ".join([param.declaration for param in command.params])) 44 45def genWrapperHeader (iface): 46 defines = imap(commandAliasDefinition, iface.commands) 47 prototypes = imap(commandWrapperDeclaration, iface.commands) 48 src = indentLines(chain(defines, prototypes)) 49 writeInlFile(os.path.join(OPENGL_INC_DIR, "glwApi.inl"), src) 50 51def getDefaultReturn (command): 52 if command.name == "glGetError": 53 return "GL_INVALID_OPERATION" 54 else: 55 assert command.type != 'void' 56 return "(%s)0" % command.type 57 58def commandWrapperDefinition (command): 59 template = """ 60{returnType} {mangledName} ({paramDecls}) 61{{ 62 const glw::Functions* gl = glw::getCurrentThreadFunctions(); 63 if (!gl) 64 return{defaultReturn}; 65 {maybeReturn}gl->{memberName}({arguments}); 66}}""" 67 return template.format( 68 returnType = command.type, 69 mangledName = getMangledName(command.name), 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 = commandArgs(command)) 75 76def genWrapperImplementation (iface): 77 genCommandList(iface, commandWrapperDefinition, OPENGL_INC_DIR, "glwImpl.inl") 78 79def genWrapper (iface): 80 genWrapperHeader(iface) 81 genWrapperImplementation(iface) 82 83if __name__ == "__main__": 84 genWrapper(getHybridInterface()) 85