Merge "Fix error double accounting in fuzzyCompare()" am: 0cf17c4bf8
[platform/upstream/VK-GL-CTS.git] / scripts / egl / common.py
1 # -*- coding: utf-8 -*-
2
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
6 #
7 # Copyright 2015-2017 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 import os
24 import re
25 import sys
26
27 def registerPaths():
28         sys.path.append(os.path.dirname(os.path.dirname(__file__)))
29
30 registerPaths()
31
32 import khr_util.format
33 import khr_util.registry
34 import khr_util.registry_cache
35
36 SCRIPTS_DIR                     = os.path.dirname(__file__)
37 EGL_DIR                         = os.path.normpath(os.path.join(SCRIPTS_DIR, "..", "..", "framework", "egl"))
38 EGL_WRAPPER_DIR         = os.path.normpath(os.path.join(EGL_DIR, "wrapper"))
39
40 EGL_SOURCE                      = khr_util.registry_cache.RegistrySource(
41                                                 "https://raw.githubusercontent.com/KhronosGroup/EGL-Registry",
42                                                 "api/egl.xml",
43                                                 "13a26984991216cbf9a44fbf390f95dc05b5493a",
44                                                 "1c59e6b6b89d2b9047a8f5c680a6bb240b8048700ce91cefa0e870798da4f3db")
45
46 VERSION                         = '1.5'
47
48 EXTENSIONS                      = [
49         # \todo [2014-12-05 pyry] Use 1.5 core functions/enums instead
50         "EGL_KHR_create_context",
51         "EGL_KHR_create_context_no_error",
52         "EGL_KHR_lock_surface",
53         "EGL_KHR_image_base",
54         "EGL_KHR_fence_sync",
55         "EGL_KHR_reusable_sync",
56         "EGL_KHR_wait_sync",
57         "EGL_KHR_gl_texture_2D_image",
58         "EGL_KHR_gl_texture_cubemap_image",
59         "EGL_KHR_gl_renderbuffer_image",
60         "EGL_KHR_gl_texture_3D_image",
61         "EGL_EXT_create_context_robustness",
62         "EGL_EXT_platform_base",
63         "EGL_EXT_platform_x11",
64         "EGL_KHR_platform_wayland",
65         "EGL_ANDROID_image_native_buffer",
66         "EGL_EXT_yuv_surface",
67         "EGL_EXT_buffer_age",
68         "EGL_KHR_partial_update",
69         "EGL_KHR_swap_buffers_with_damage",
70         "EGL_KHR_mutable_render_buffer",
71         "EGL_EXT_pixel_format_float",
72         "EGL_KHR_gl_colorspace",
73         "EGL_EXT_gl_colorspace_bt2020_linear",
74         "EGL_EXT_gl_colorspace_bt2020_pq",
75         "EGL_EXT_gl_colorspace_display_p3",
76         "EGL_EXT_gl_colorspace_display_p3_linear",
77         "EGL_EXT_gl_colorspace_scrgb",
78         "EGL_EXT_gl_colorspace_scrgb_linear"
79 ]
80 PROTECTS                        = [
81         "KHRONOS_SUPPORT_INT64"
82 ]
83
84 def getEGLRegistry ():
85         return khr_util.registry_cache.getRegistry(EGL_SOURCE)
86
87 def getInterface (registry, api, version=None, profile=None, **kwargs):
88         spec = khr_util.registry.spec(registry, api, version, profile, **kwargs)
89         return khr_util.registry.createInterface(registry, spec, api)
90
91 def getDefaultInterface ():
92         return getInterface(getEGLRegistry(), 'egl', VERSION, extensionNames = EXTENSIONS, protects = PROTECTS)
93
94 def getFunctionTypeName (funcName):
95         return "%sFunc" % funcName
96
97 def getFunctionMemberName (funcName):
98         assert funcName[:3] == "egl"
99         return "%c%s" % (funcName[3].lower(), funcName[4:])
100
101 def genCommandList (iface, renderCommand, directory, filename, align=False):
102         lines = map(renderCommand, iface.commands)
103         if align:
104                 lines = khr_util.format.indentLines(lines)
105         writeInlFile(os.path.join(directory, filename), lines)
106
107 def getVersionToken (version):
108         return version.replace(".", "")
109
110 def genCommandLists (registry, renderCommand, check, directory, filePattern, align=False):
111         for eFeature in registry.features:
112                 api                     = eFeature.get('api')
113                 version         = eFeature.get('number')
114                 profile         = check(api, version)
115                 if profile is True:
116                         profile = None
117                 elif profile is False:
118                         continue
119                 iface           = getInterface(registry, api, version=version, profile=profile)
120                 filename        = filePattern % getVersionToken(version)
121                 genCommandList(iface, renderCommand, directory, filename, align)
122
123 INL_HEADER = khr_util.format.genInlHeader("Khronos EGL API description (egl.xml)", EGL_SOURCE.getRevision())
124
125 def writeInlFile (filename, source):
126         khr_util.format.writeInlFile(filename, INL_HEADER, source)