Bug 1932347 - Adjust positioning of tab preview for vertical tabs r=tabbrowser-review...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / py / tex_image_test_generator.py
blob37b4022738d244a7836c924d599e2325289a5d4f
1 #!/usr/bin/env python2
3 # Copyright (c) 2019 The Khronos Group Inc.
4 # Use of this source code is governed by an MIT-style license that can be
5 # found in the LICENSE.txt file.
7 """
8 Generator for tex-2d* and tex-3d* tests.
9 This file needs to be run in its folder.
10 """
12 import os
13 import os.path
14 import sys
16 _LICENSE = """<!--
17 Copyright (c) 2019 The Khronos Group Inc.
18 Use of this source code is governed by an MIT-style license that can be
19 found in the LICENSE.txt file.
20 -->
22 """
24 _DO_NOT_EDIT_WARNING = """<!--
26 This file is auto-generated from py/tex_image_test_generator.py
27 DO NOT EDIT!
29 -->
31 """
33 _ELEMENT_TYPES = [
34 'canvas',
35 'canvas-sub-rectangle',
36 'image',
37 'image-data',
38 'svg-image',
39 'video',
40 'webgl-canvas',
41 'image-bitmap-from-image-data',
42 'image-bitmap-from-image',
43 'image-bitmap-from-video',
44 'image-bitmap-from-canvas',
45 'image-bitmap-from-blob',
46 'image-bitmap-from-image-bitmap'
49 _FORMATS_TYPES_WEBGL1 = [
50 {'internal_format': 'RGB', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' },
51 {'internal_format': 'RGB', 'format': 'RGB', 'type': 'UNSIGNED_SHORT_5_6_5' },
52 {'internal_format': 'RGBA', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
53 {'internal_format': 'RGBA', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_4_4_4_4' },
54 {'internal_format': 'RGBA', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_5_5_5_1' },
55 {'internal_format': 'LUMINANCE', 'format': 'LUMINANCE', 'type': 'UNSIGNED_BYTE' },
56 {'internal_format': 'ALPHA', 'format': 'ALPHA', 'type': 'UNSIGNED_BYTE' },
57 {'internal_format': 'LUMINANCE_ALPHA', 'format': 'LUMINANCE_ALPHA', 'type': 'UNSIGNED_BYTE' },
60 _FORMATS_TYPES_WEBGL2 = [
61 {'internal_format': 'R8', 'format': 'RED', 'type': 'UNSIGNED_BYTE' },
62 {'internal_format': 'R16F', 'format': 'RED', 'type': 'HALF_FLOAT' },
63 {'internal_format': 'R16F', 'format': 'RED', 'type': 'FLOAT' },
64 {'internal_format': 'R32F', 'format': 'RED', 'type': 'FLOAT' },
65 {'internal_format': 'R8UI', 'format': 'RED_INTEGER', 'type': 'UNSIGNED_BYTE' },
66 {'internal_format': 'RG8', 'format': 'RG', 'type': 'UNSIGNED_BYTE' },
67 {'internal_format': 'RG16F', 'format': 'RG', 'type': 'HALF_FLOAT' },
68 {'internal_format': 'RG16F', 'format': 'RG', 'type': 'FLOAT' },
69 {'internal_format': 'RG32F', 'format': 'RG', 'type': 'FLOAT' },
70 {'internal_format': 'RG8UI', 'format': 'RG_INTEGER', 'type': 'UNSIGNED_BYTE' },
71 {'internal_format': 'RGB8', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' },
72 {'internal_format': 'SRGB8', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' },
73 {'internal_format': 'RGB565', 'format': 'RGB', 'type': 'UNSIGNED_BYTE' },
74 {'internal_format': 'RGB565', 'format': 'RGB', 'type': 'UNSIGNED_SHORT_5_6_5' },
75 {'internal_format': 'R11F_G11F_B10F', 'format': 'RGB', 'type': 'UNSIGNED_INT_10F_11F_11F_REV' },
76 {'internal_format': 'R11F_G11F_B10F', 'format': 'RGB', 'type': 'HALF_FLOAT' },
77 {'internal_format': 'R11F_G11F_B10F', 'format': 'RGB', 'type': 'FLOAT' },
78 {'internal_format': 'RGB9_E5', 'format': 'RGB', 'type': 'HALF_FLOAT' },
79 {'internal_format': 'RGB9_E5', 'format': 'RGB', 'type': 'FLOAT' },
80 {'internal_format': 'RGB16F', 'format': 'RGB', 'type': 'HALF_FLOAT' },
81 {'internal_format': 'RGB16F', 'format': 'RGB', 'type': 'FLOAT' },
82 {'internal_format': 'RGB32F', 'format': 'RGB', 'type': 'FLOAT' },
83 {'internal_format': 'RGB8UI', 'format': 'RGB_INTEGER', 'type': 'UNSIGNED_BYTE' },
84 {'internal_format': 'RGBA8', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
85 {'internal_format': 'SRGB8_ALPHA8', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
86 {'internal_format': 'RGB5_A1', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
87 {'internal_format': 'RGB5_A1', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_5_5_5_1' },
88 {'internal_format': 'RGB10_A2', 'format': 'RGBA', 'type': 'UNSIGNED_INT_2_10_10_10_REV' },
89 {'internal_format': 'RGBA4', 'format': 'RGBA', 'type': 'UNSIGNED_BYTE' },
90 {'internal_format': 'RGBA4', 'format': 'RGBA', 'type': 'UNSIGNED_SHORT_4_4_4_4' },
91 {'internal_format': 'RGBA16F', 'format': 'RGBA', 'type': 'HALF_FLOAT' },
92 {'internal_format': 'RGBA16F', 'format': 'RGBA', 'type': 'FLOAT' },
93 {'internal_format': 'RGBA32F', 'format': 'RGBA', 'type': 'FLOAT' },
94 {'internal_format': 'RGBA8UI', 'format': 'RGBA_INTEGER', 'type': 'UNSIGNED_BYTE' },
97 def GenerateFilename(dimension, element_type, internal_format, format, type):
98 """Generate test filename."""
99 filename = ("tex-" + dimension + "d-" +
100 internal_format + "-" + format + "-" + type + ".html")
101 return filename.lower()
103 def WriteTest(filename, dimension, element_type, internal_format, format, type, default_context_version):
104 """Write one test."""
105 file = open(filename, "wb")
106 file.write(_LICENSE)
107 file.write(_DO_NOT_EDIT_WARNING)
108 code = """
109 <!DOCTYPE html>
110 <html>
111 <head>
112 <meta charset="utf-8">
113 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
114 <script src="../../../js/js-test-pre.js"></script>
115 <script src="../../../js/webgl-test-utils.js"></script>
116 <script src="../../../js/tests/tex-image-and-sub-image-utils.js"></script>"""
117 if element_type == 'image-bitmap-from-image-data' or element_type == 'image-bitmap-from-image' or \
118 element_type == 'image-bitmap-from-video' or element_type == 'image-bitmap-from-canvas' or \
119 element_type == 'image-bitmap-from-blob' or element_type == 'image-bitmap-from-image-bitmap':
120 code += """
121 <script src="../../../js/tests/tex-image-and-sub-image-with-image-bitmap-utils.js"></script>"""
122 code += """
123 <script src="../../../js/tests/tex-image-and-sub-image-%(dimension)sd-with-%(element_type)s.js"></script>
124 </head>
125 <body>"""
126 if element_type == 'image-data':
127 code += """
128 <canvas id="texcanvas" width="2" height="2"></canvas>"""
129 code += """
130 <canvas id="example" width="32" height="32"></canvas>"""
131 code += """
132 <div id="description"></div>
133 <div id="console"></div>
134 <script>
135 "use strict";
136 function testPrologue(gl) {
137 return true;
140 generateTest("%(internal_format)s", "%(format)s", "%(type)s", testPrologue, "../../../resources/", %(default_context_version)s)();
141 </script>
142 </body>
143 </html>
145 file.write(code % {
146 'dimension': dimension,
147 'element_type': element_type,
148 'internal_format': internal_format,
149 'format': format,
150 'type': type,
151 'default_context_version': default_context_version,
153 file.close()
155 def GenerateTests(test_dir, test_cases, dimension, default_context_version):
156 test_dir_template = test_dir + '/%s'
157 for element_type in _ELEMENT_TYPES:
158 os.chdir(test_dir_template % element_type.replace('-', '_'))
159 if dimension == '3':
160 # Assume we write 2D tests first.
161 index_file = open("00_test_list.txt", "ab")
162 else:
163 index_file = open("00_test_list.txt", "wb")
164 for tex_info in test_cases:
165 internal_format = tex_info['internal_format']
166 format = tex_info['format']
167 type = tex_info['type']
168 filename = GenerateFilename(dimension, element_type, internal_format, format, type)
169 index_file.write(filename)
170 index_file.write('\n')
171 WriteTest(filename, dimension, element_type, internal_format, format, type, default_context_version)
172 index_file.close();
174 def main(argv):
175 """This is the main function."""
176 py_dir = os.path.dirname(os.path.realpath(__file__))
177 GenerateTests(os.path.realpath(py_dir + '/../conformance/textures'), _FORMATS_TYPES_WEBGL1, '2', '1')
178 GenerateTests(os.path.realpath(py_dir + '/../conformance2/textures'), _FORMATS_TYPES_WEBGL2, '2', '2')
179 GenerateTests(os.path.realpath(py_dir + '/../conformance2/textures'), _FORMATS_TYPES_WEBGL2, '3', '2')
181 if __name__ == '__main__':
182 sys.exit(main(sys.argv[1:]))