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