1e5c31af7Sopenharmony_ci# -*- coding: utf-8 -*- 2e5c31af7Sopenharmony_ci 3e5c31af7Sopenharmony_ci#------------------------------------------------------------------------- 4e5c31af7Sopenharmony_ci# drawElements Quality Program utilities 5e5c31af7Sopenharmony_ci# -------------------------------------- 6e5c31af7Sopenharmony_ci# 7e5c31af7Sopenharmony_ci# Copyright 2015 The Android Open Source Project 8e5c31af7Sopenharmony_ci# 9e5c31af7Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 10e5c31af7Sopenharmony_ci# you may not use this file except in compliance with the License. 11e5c31af7Sopenharmony_ci# You may obtain a copy of the License at 12e5c31af7Sopenharmony_ci# 13e5c31af7Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 14e5c31af7Sopenharmony_ci# 15e5c31af7Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 16e5c31af7Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 17e5c31af7Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18e5c31af7Sopenharmony_ci# See the License for the specific language governing permissions and 19e5c31af7Sopenharmony_ci# limitations under the License. 20e5c31af7Sopenharmony_ci# 21e5c31af7Sopenharmony_ci#------------------------------------------------------------------------- 22e5c31af7Sopenharmony_ci 23e5c31af7Sopenharmony_ciimport os 24e5c31af7Sopenharmony_cifrom src_util import * 25e5c31af7Sopenharmony_cifrom itertools import chain 26e5c31af7Sopenharmony_ci 27e5c31af7Sopenharmony_citry: 28e5c31af7Sopenharmony_ci from itertools import imap 29e5c31af7Sopenharmony_ciexcept ImportError: 30e5c31af7Sopenharmony_ci imap=map 31e5c31af7Sopenharmony_ci 32e5c31af7Sopenharmony_cidef getMangledName (funcName): 33e5c31af7Sopenharmony_ci assert funcName[:2] == "gl" 34e5c31af7Sopenharmony_ci return "glw" + funcName[2:] 35e5c31af7Sopenharmony_ci 36e5c31af7Sopenharmony_cidef commandAliasDefinition (command): 37e5c31af7Sopenharmony_ci return "#define\t%s\t%s" % (command.name, getMangledName(command.name)) 38e5c31af7Sopenharmony_ci 39e5c31af7Sopenharmony_cidef commandWrapperDeclaration (command): 40e5c31af7Sopenharmony_ci return "%s\t%s\t(%s);" % ( 41e5c31af7Sopenharmony_ci command.type, 42e5c31af7Sopenharmony_ci getMangledName(command.name), 43e5c31af7Sopenharmony_ci ", ".join([param.declaration for param in command.params])) 44e5c31af7Sopenharmony_ci 45e5c31af7Sopenharmony_cidef genWrapperHeader (iface): 46e5c31af7Sopenharmony_ci defines = imap(commandAliasDefinition, iface.commands) 47e5c31af7Sopenharmony_ci prototypes = imap(commandWrapperDeclaration, iface.commands) 48e5c31af7Sopenharmony_ci src = indentLines(chain(defines, prototypes)) 49e5c31af7Sopenharmony_ci writeInlFile(os.path.join(OPENGL_INC_DIR, "glwApi.inl"), src) 50e5c31af7Sopenharmony_ci 51e5c31af7Sopenharmony_cidef getDefaultReturn (command): 52e5c31af7Sopenharmony_ci if command.name == "glGetError": 53e5c31af7Sopenharmony_ci return "GL_INVALID_OPERATION" 54e5c31af7Sopenharmony_ci else: 55e5c31af7Sopenharmony_ci assert command.type != 'void' 56e5c31af7Sopenharmony_ci return "(%s)0" % command.type 57e5c31af7Sopenharmony_ci 58e5c31af7Sopenharmony_cidef commandWrapperDefinition (command): 59e5c31af7Sopenharmony_ci template = """ 60e5c31af7Sopenharmony_ci{returnType} {mangledName} ({paramDecls}) 61e5c31af7Sopenharmony_ci{{ 62e5c31af7Sopenharmony_ci const glw::Functions* gl = glw::getCurrentThreadFunctions(); 63e5c31af7Sopenharmony_ci if (!gl) 64e5c31af7Sopenharmony_ci return{defaultReturn}; 65e5c31af7Sopenharmony_ci {maybeReturn}gl->{memberName}({arguments}); 66e5c31af7Sopenharmony_ci}}""" 67e5c31af7Sopenharmony_ci return template.format( 68e5c31af7Sopenharmony_ci returnType = command.type, 69e5c31af7Sopenharmony_ci mangledName = getMangledName(command.name), 70e5c31af7Sopenharmony_ci paramDecls = commandParams(command), 71e5c31af7Sopenharmony_ci defaultReturn = " " + getDefaultReturn(command) if command.type != 'void' else "", 72e5c31af7Sopenharmony_ci maybeReturn = "return " if command.type != 'void' else "", 73e5c31af7Sopenharmony_ci memberName = getFunctionMemberName(command.name), 74e5c31af7Sopenharmony_ci arguments = commandArgs(command)) 75e5c31af7Sopenharmony_ci 76e5c31af7Sopenharmony_cidef genWrapperImplementation (iface): 77e5c31af7Sopenharmony_ci genCommandList(iface, commandWrapperDefinition, OPENGL_INC_DIR, "glwImpl.inl") 78e5c31af7Sopenharmony_ci 79e5c31af7Sopenharmony_cidef genWrapper (iface): 80e5c31af7Sopenharmony_ci genWrapperHeader(iface) 81e5c31af7Sopenharmony_ci genWrapperImplementation(iface) 82e5c31af7Sopenharmony_ci 83e5c31af7Sopenharmony_ciif __name__ == "__main__": 84e5c31af7Sopenharmony_ci genWrapper(getHybridInterface()) 85