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