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 egl.common import * 25from egl.enums import enumValue 26from egl.library import getExtOnlyIface 27from khr_util.format import indentLines 28from itertools import chain 29 30try: 31 from itertools import imap 32except ImportError: 33 imap=map 34 35def getMangledName (funcName): 36 assert funcName[:3] == "egl" 37 return "eglw" + funcName[3:] 38 39def commandAliasDefinition (command): 40 return "#define\t%s\t%s" % (command.name, getMangledName(command.name)) 41 42def commandWrapperDeclaration (command): 43 return "%s\t%s\t(%s);" % ( 44 command.type, 45 getMangledName(command.name), 46 ", ".join([param.declaration for param in command.params])) 47 48NATIVE_TYPES = [ 49 "EGLNativeWindowType", 50 "EGLNativeDisplayType", 51 "EGLNativePixmapType", 52] 53 54def commandWrapperDefinition (command): 55 template = """ 56{returnType} {mangledName} ({paramDecls}) 57{{ 58 const eglw::Library* egl = eglw::getCurrentThreadLibrary(); 59 if (!egl) 60 return{defaultReturn}; 61 {maybeReturn}egl->{memberName}({arguments}); 62}}""" 63 64 arguments = [] 65 66 for param in command.params: 67 if param.type in NATIVE_TYPES: 68 arguments.append("(void*)" + param.name) 69 else: 70 arguments.append(param.name) 71 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)) 80 81def getDefaultReturn (command): 82 if command.name == "glGetError": 83 return "GL_INVALID_OPERATION" 84 else: 85 assert command.type != 'void' 86 return "(%s)0" % command.type 87 88commandParams = khr_util.format.commandParams 89 90def enumDefinitionC (enum): 91 return "#define %s\t%s" % (enum.name, enumValue(enum)) 92 93def gen (registry): 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)) 100 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") 105 106