1# Copyright (c) 2018 The Android Open Source Project 2# Copyright (c) 2018 Google Inc. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16from .common.codegen import CodeGen, VulkanAPIWrapper 17from .common.vulkantypes import \ 18 VulkanAPI, makeVulkanTypeSimple, iterateVulkanType 19 20from .wrapperdefs import VulkanWrapperGenerator 21 22from .wrapperdefs import API_PREFIX_VALIDATE 23from .wrapperdefs import PARAMETERS_VALIDATE 24from .wrapperdefs import VOID_TYPE 25from .wrapperdefs import VALIDATE_RESULT_TYPE 26from .wrapperdefs import VALIDATE_VAR_NAME 27from .wrapperdefs import VALIDATE_GOOD_RESULT 28 29from .wrapperdefs import VULKAN_STREAM_TYPE 30from .wrapperdefs import VULKAN_STREAM_VAR_NAME 31 32from .wrapperdefs import API_PREFIX_MARSHAL 33from .wrapperdefs import API_PREFIX_FRONTEND 34 35# Frontend 36class VulkanFrontend(VulkanWrapperGenerator): 37 38 def __init__(self, module, typeInfo): 39 VulkanWrapperGenerator.__init__(self, module, typeInfo) 40 41 def validateDefFunc(_codegen, _api): 42 # TODO 43 pass 44 45 self.validateWrapper = \ 46 VulkanAPIWrapper( 47 API_PREFIX_VALIDATE, 48 PARAMETERS_VALIDATE, 49 VOID_TYPE, 50 validateDefFunc) 51 52 def frontendDefFunc(codegen, api): 53 retTypeName = api.retType.typeName 54 55 codegen.stmt( 56 "%s %s = %s" % (VALIDATE_RESULT_TYPE, VALIDATE_VAR_NAME, 57 VALIDATE_GOOD_RESULT)) 58 codegen.funcCall(None, API_PREFIX_VALIDATE + api.origName, 59 ["&%s" % VALIDATE_VAR_NAME] + list( 60 map(lambda p: p.paramName, api.parameters))) 61 62 codegen.beginIf( 63 "%s != %s" % (VALIDATE_VAR_NAME, VALIDATE_GOOD_RESULT)) 64 if retTypeName == VALIDATE_RESULT_TYPE: 65 codegen.stmt("return %s" % VALIDATE_VAR_NAME) 66 elif retTypeName != "void": 67 codegen.stmt("return (%s)0" % retTypeName) 68 else: 69 codegen.stmt("return") 70 codegen.endIf() 71 72 codegen.stmt("// VULKAN_STREAM_GET()") 73 codegen.stmt("%s* %s = nullptr" % (VULKAN_STREAM_TYPE, 74 VULKAN_STREAM_VAR_NAME)) 75 76 retLhs = None 77 if retTypeName != "void": 78 retLhs = retTypeName + " res" 79 80 codegen.funcCall(retLhs, API_PREFIX_MARSHAL + api.origName, 81 [VULKAN_STREAM_VAR_NAME] + list( 82 map(lambda p: p.paramName, api.parameters))) 83 84 if retTypeName != "void": 85 codegen.stmt("return res") 86 87 self.frontendWrapper = \ 88 VulkanAPIWrapper( 89 API_PREFIX_FRONTEND, 90 [], 91 None, 92 frontendDefFunc) 93 94 def onGenCmd(self, cmdinfo, name, alias): 95 VulkanWrapperGenerator.onGenCmd(self, cmdinfo, name, alias) 96 self.module.appendHeader( 97 self.frontendWrapper.makeDecl(self.typeInfo, name)) 98 self.module.appendImpl( 99 self.validateWrapper.makeDefinition( 100 self.typeInfo, name, isStatic=True)) 101 self.module.appendImpl( 102 self.frontendWrapper.makeDefinition(self.typeInfo, name)) 103