Merge remote-tracking branch 'goog/mirror-m-wireless-internal-release'
[platform/upstream/VK-GL-CTS.git] / scripts / egl / str_util.py
1 # -*- coding: utf-8 -*-
2
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
6 #
7 # Copyright 2015 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 string
25
26 from common import *
27 from khr_util.format import indentLines
28 from khr_util.gen_str_util import addValuePrefix, genStrUtilProtos, genStrUtilImpls
29
30 # Bitfield mapping
31 BITFIELD_GROUPS = [
32         ("APIBits", [
33                 "OPENGL_BIT",
34                 "OPENGL_ES_BIT",
35                 "OPENGL_ES2_BIT",
36                 "OPENGL_ES3_BIT_KHR",
37                 "OPENVG_BIT"
38                 ]),
39         ("SurfaceBits", [
40                 "PBUFFER_BIT",
41                 "PIXMAP_BIT",
42                 "WINDOW_BIT",
43                 "MULTISAMPLE_RESOLVE_BOX_BIT",
44                 "SWAP_BEHAVIOR_PRESERVED_BIT",
45                 "VG_ALPHA_FORMAT_PRE_BIT",
46                 "VG_COLORSPACE_LINEAR_BIT",
47                 "LOCK_SURFACE_BIT_KHR",
48                 "OPTIMAL_FORMAT_BIT_KHR"
49                 ])
50 ]
51
52 # Enum mapping
53 ENUM_GROUPS = [
54         ("Boolean",                     ["TRUE", "FALSE"]),
55         ("BoolDontCare",        ["TRUE", "FALSE", "DONT_CARE"]),
56         ("API",                         ["OPENGL_API", "OPENGL_ES_API", "OPENVG_API"]),
57         ("Error", [
58                 "SUCCESS",
59                 "NOT_INITIALIZED",
60                 "BAD_ACCESS",
61                 "BAD_ALLOC",
62                 "BAD_ATTRIBUTE",
63                 "BAD_CONFIG",
64                 "BAD_CONTEXT",
65                 "BAD_CURRENT_SURFACE",
66                 "BAD_DISPLAY",
67                 "BAD_MATCH",
68                 "BAD_NATIVE_PIXMAP",
69                 "BAD_NATIVE_WINDOW",
70                 "BAD_PARAMETER",
71                 "BAD_SURFACE",
72                 "CONTEXT_LOST"
73                 ]),
74         ("ContextAttrib", [
75                 "CONFIG_ID",
76                 "CONTEXT_CLIENT_TYPE",
77                 "CONTEXT_CLIENT_VERSION",
78                 "RENDER_BUFFER"
79                 ]),
80         ("ConfigAttrib", [
81                 "BUFFER_SIZE",
82                 "RED_SIZE",
83                 "GREEN_SIZE",
84                 "BLUE_SIZE",
85                 "LUMINANCE_SIZE",
86                 "ALPHA_SIZE",
87                 "ALPHA_MASK_SIZE",
88                 "BIND_TO_TEXTURE_RGB",
89                 "BIND_TO_TEXTURE_RGBA",
90                 "COLOR_BUFFER_TYPE",
91                 "CONFIG_CAVEAT",
92                 "CONFIG_ID",
93                 "CONFORMANT",
94                 "DEPTH_SIZE",
95                 "LEVEL",
96                 "MATCH_NATIVE_PIXMAP",
97                 "MAX_SWAP_INTERVAL",
98                 "MIN_SWAP_INTERVAL",
99                 "NATIVE_RENDERABLE",
100                 "NATIVE_VISUAL_TYPE",
101                 "RENDERABLE_TYPE",
102                 "SAMPLE_BUFFERS",
103                 "SAMPLES",
104                 "STENCIL_SIZE",
105                 "SURFACE_TYPE",
106                 "TRANSPARENT_TYPE",
107                 "TRANSPARENT_RED_VALUE",
108                 "TRANSPARENT_GREEN_VALUE",
109                 "TRANSPARENT_BLUE_VALUE"
110                 ]),
111         ("SurfaceAttrib", [
112                 "CONFIG_ID",
113                 "WIDTH",
114                 "HEIGHT",
115                 "HORIZONTAL_RESOLUTION",
116                 "VERTICAL_RESOLUTION",
117                 "LARGEST_PBUFFER",
118                 "MIPMAP_TEXTURE",
119                 "MIPMAP_LEVEL",
120                 "MULTISAMPLE_RESOLVE",
121                 "PIXEL_ASPECT_RATIO",
122                 "RENDER_BUFFER",
123                 "SWAP_BEHAVIOR",
124                 "TEXTURE_FORMAT",
125                 "TEXTURE_TARGET",
126                 "ALPHA_FORMAT",
127                 "COLORSPACE"
128                 ]),
129         ("SurfaceTarget",               ["READ", "DRAW"]),
130
131         # ConfigAttrib values
132         ("ColorBufferType",             ["RGB_BUFFER", "LUMINANCE_BUFFER"]),
133         ("ConfigCaveat",                ["NONE", "SLOW_CONFIG", "NON_CONFORMANT_CONFIG"]),
134         ("TransparentType",             ["NONE", "TRANSPARENT_RGB"]),
135
136         # SurfaceAttrib values
137         ("MultisampleResolve",  ["MULTISAMPLE_RESOLVE_DEFAULT", "MULTISAMPLE_RESOLVE_BOX"]),
138         ("RenderBuffer",                ["SINGLE_BUFFER", "BACK_BUFFER"]),
139         ("SwapBehavior",                ["BUFFER_DESTROYED", "BUFFER_PRESERVED"]),
140         ("TextureFormat",               ["NO_TEXTURE", "TEXTURE_RGB", "TEXTURE_RGBA"]),
141         ("TextureTarget",               ["NO_TEXTURE", "TEXTURE_2D"]),
142         ("AlphaFormat",                 ["ALPHA_FORMAT_NONPRE", "ALPHA_FORMAT_PRE"]),
143         ("Colorspace",                  ["COLORSPACE_sRGB", "COLORSPACE_LINEAR"])
144 ]
145
146 def gen (iface):
147         enumGroups              = addValuePrefix(ENUM_GROUPS, "EGL_")
148         bitfieldGroups  = addValuePrefix(BITFIELD_GROUPS, "EGL_")
149         prototypeFile   = os.path.join(EGL_DIR, "egluStrUtilPrototypes.inl")
150         implFile                = os.path.join(EGL_DIR, "egluStrUtil.inl")
151
152         writeInlFile(prototypeFile, indentLines(genStrUtilProtos(iface, enumGroups, bitfieldGroups)))
153         writeInlFile(implFile, genStrUtilImpls(iface, enumGroups, bitfieldGroups))