Home | History | Annotate | Download | only in egl
      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 from common import *
     24 from khr_util.format import indentLines, commandParams, commandArgs
     25 import khr_util.registry
     26 from itertools import imap, chain
     27 
     28 def virtualMemberDecl (command):
     29 	return "virtual %s\t%s\t(%s) const\t= 0;" % (
     30 		command.type,
     31 		getFunctionMemberName(command.name),
     32 		commandParams(command))
     33 
     34 def concreteMemberDecl (command):
     35 	return "%s\t%s\t(%s) const;" % (
     36 		command.type,
     37 		getFunctionMemberName(command.name),
     38 		commandParams(command))
     39 
     40 def memberImpl (command):
     41 	template = """
     42 {returnType} FuncPtrLibrary::{memberName} ({paramDecls}) const
     43 {{
     44 	{maybeReturn}m_egl.{memberName}({arguments});
     45 }}"""
     46 	return template.format(
     47 		returnType		= command.type,
     48 		mangledName		= getFunctionMemberName(command.name),
     49 		paramDecls		= commandParams(command),
     50 		maybeReturn		= "return " if command.type != 'void' else "",
     51 		memberName		= getFunctionMemberName(command.name),
     52 		arguments		= commandArgs(command))
     53 
     54 def initFunctionEntry (command):
     55 	return "dst->%s\t= (%sFunc)\tloader->get(\"%s\");" % (
     56 		getFunctionMemberName(command.name),
     57 		command.name,
     58 		command.name)
     59 
     60 def getExtOnlyIface (registry, api, extensions):
     61 	spec = khr_util.registry.InterfaceSpec()
     62 
     63 	for extension in registry.extensions:
     64 		if not khr_util.registry.getExtensionName(extension) in extensions:
     65 			continue
     66 
     67 		if not khr_util.registry.extensionSupports(extension, api):
     68 			continue
     69 
     70 		spec.addExtension(extension, api)
     71 
     72 	return khr_util.registry.createInterface(registry, spec, api)
     73 
     74 def commandLibraryEntry (command):
     75 	return "\t{ \"%s\",\t(deFunctionPtr)%s }," % (command.name, command.name)
     76 
     77 def genStaticLibrary (registry):
     78 	genCommandLists(registry, commandLibraryEntry,
     79 					check		= lambda api, version: api == 'egl' and version in set(["1.4", "1.5"]),
     80 					directory	= EGL_WRAPPER_DIR,
     81 					filePattern	= "eglwStaticLibrary%s.inl",
     82 					align		= True)
     83 
     84 def gen (registry):
     85 	defaultIface	= getDefaultInterface()
     86 	noExtIface		= getInterface(registry, 'egl', VERSION)
     87 	extOnlyIface	= getExtOnlyIface(registry, 'egl', EXTENSIONS)
     88 
     89 	genCommandList(defaultIface,	virtualMemberDecl,	EGL_WRAPPER_DIR, "eglwLibrary.inl", True)
     90 	genCommandList(defaultIface,	concreteMemberDecl,	EGL_WRAPPER_DIR, "eglwFuncPtrLibraryDecl.inl", True)
     91 	genCommandList(defaultIface,	memberImpl,			EGL_WRAPPER_DIR, "eglwFuncPtrLibraryImpl.inl")
     92 
     93 	genCommandList(noExtIface,		initFunctionEntry,	EGL_WRAPPER_DIR, "eglwInitCore.inl", True)
     94 	genCommandList(extOnlyIface,	initFunctionEntry,	EGL_WRAPPER_DIR, "eglwInitExtensions.inl", True)
     95 
     96 	genStaticLibrary(registry)
     97