1/*-------------------------------------------------------------------------
2 * drawElements Quality Program EGL Utilities
3 * ------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief EGL String Utilities.
22 *//*--------------------------------------------------------------------*/
23
24#include "egluStrUtil.hpp"
25#include "eglwEnums.hpp"
26
27namespace eglu
28{
29
30std::ostream& operator<< (std::ostream& str, const ConfigAttribValueFmt& attribFmt)
31{
32	switch (attribFmt.attribute)
33	{
34		case EGL_COLOR_BUFFER_TYPE:
35			return str << getColorBufferTypeStr(attribFmt.value);
36
37		case EGL_CONFIG_CAVEAT:
38			return str << getConfigCaveatStr(attribFmt.value);
39
40		case EGL_CONFORMANT:
41		case EGL_RENDERABLE_TYPE:
42			return str << getAPIBitsStr(attribFmt.value);
43
44		case EGL_SURFACE_TYPE:
45			return str << getSurfaceBitsStr(attribFmt.value);
46
47		case EGL_MATCH_NATIVE_PIXMAP:
48			if (attribFmt.value == EGL_NONE)
49				return str << "EGL_NONE";
50			else
51				return str << tcu::toHex(attribFmt.value);
52
53		case EGL_TRANSPARENT_TYPE:
54			return str << getTransparentTypeStr(attribFmt.value);
55
56		case EGL_BIND_TO_TEXTURE_RGB:
57		case EGL_BIND_TO_TEXTURE_RGBA:
58		case EGL_NATIVE_RENDERABLE:
59		case EGL_RECORDABLE_ANDROID:
60			return str << getBoolDontCareStr(attribFmt.value);
61
62		case EGL_ALPHA_MASK_SIZE:
63		case EGL_ALPHA_SIZE:
64		case EGL_BLUE_SIZE:
65		case EGL_BUFFER_SIZE:
66		case EGL_CONFIG_ID:
67		case EGL_DEPTH_SIZE:
68		case EGL_GREEN_SIZE:
69		case EGL_LEVEL:
70		case EGL_LUMINANCE_SIZE:
71		case EGL_MAX_SWAP_INTERVAL:
72		case EGL_MIN_SWAP_INTERVAL:
73		case EGL_RED_SIZE:
74		case EGL_SAMPLE_BUFFERS:
75		case EGL_SAMPLES:
76		case EGL_STENCIL_SIZE:
77		case EGL_TRANSPARENT_RED_VALUE:
78		case EGL_TRANSPARENT_GREEN_VALUE:
79		case EGL_TRANSPARENT_BLUE_VALUE:
80			return str << (int)attribFmt.value;
81
82		default:
83			return str << tcu::toHex(attribFmt.value);
84	}
85}
86
87std::ostream& operator<< (std::ostream& str, const ContextAttribValueFmt& attribFmt)
88{
89	switch (attribFmt.attribute)
90	{
91		case EGL_CONFIG_ID:
92		case EGL_CONTEXT_CLIENT_VERSION:
93			return str << (int)attribFmt.value;
94
95		case EGL_CONTEXT_CLIENT_TYPE:
96			return str << getAPIStr(attribFmt.value);
97
98		case EGL_RENDER_BUFFER:
99			return str << getRenderBufferStr(attribFmt.value);
100
101		default:
102			return str << tcu::toHex(attribFmt.value);
103	}
104}
105
106std::ostream& operator<< (std::ostream& str, const SurfaceAttribValueFmt& attribFmt)
107{
108	switch (attribFmt.attribute)
109	{
110		case EGL_CONFIG_ID:
111		case EGL_WIDTH:
112		case EGL_HEIGHT:
113		case EGL_HORIZONTAL_RESOLUTION:
114		case EGL_VERTICAL_RESOLUTION:
115		case EGL_PIXEL_ASPECT_RATIO:
116			return str << (int)attribFmt.value;
117
118		case EGL_LARGEST_PBUFFER:
119		case EGL_MIPMAP_TEXTURE:
120			return str << getBoolDontCareStr(attribFmt.value);
121
122		case EGL_MULTISAMPLE_RESOLVE:
123			return str << getMultisampleResolveStr(attribFmt.value);
124
125		case EGL_RENDER_BUFFER:
126			return str << getRenderBufferStr(attribFmt.value);
127
128		case EGL_SWAP_BEHAVIOR:
129			return str << getSwapBehaviorStr(attribFmt.value);
130
131		case EGL_TEXTURE_FORMAT:
132			return str << getTextureFormatStr(attribFmt.value);
133
134		case EGL_TEXTURE_TARGET:
135			return str << getTextureTargetStr(attribFmt.value);
136
137		case EGL_ALPHA_FORMAT:
138			return str << getAlphaFormatStr(attribFmt.value);
139
140		case EGL_COLORSPACE:
141			return str << getColorspaceStr(attribFmt.value);
142
143		default:
144			return str << tcu::toHex(attribFmt.value);
145	}
146}
147
148std::ostream& operator<< (std::ostream& str, const ConfigAttribListFmt& fmt)
149{
150	int pos = 0;
151
152	str << "{ ";
153
154	for (;;)
155	{
156		int attrib = fmt.attribs[pos];
157
158		if (pos != 0)
159			str << ", ";
160
161		if (attrib == EGL_NONE)
162		{
163			// Terminate.
164			str << "EGL_NONE";
165			break;
166		}
167
168		const char*	attribName = getConfigAttribName(attrib);
169
170		if (attribName)
171		{
172			// Valid attribute, print value.
173			str << attribName << ", " << getConfigAttribValueStr(attrib, fmt.attribs[pos+1]);
174			pos += 2;
175		}
176		else
177		{
178			// Invalid attribute. Terminate parsing.
179			str << tcu::toHex(attrib) << ", ???";
180			break;
181		}
182	}
183
184	str << " }";
185	return str;
186}
187
188std::ostream& operator<< (std::ostream& str, const SurfaceAttribListFmt& fmt)
189{
190	int pos = 0;
191
192	str << "{ ";
193
194	for (;;)
195	{
196		int attrib = fmt.attribs[pos];
197
198		if (pos != 0)
199			str << ", ";
200
201		if (attrib == EGL_NONE)
202		{
203			// Terminate.
204			str << "EGL_NONE";
205			break;
206		}
207
208		const char*	attribName = getSurfaceAttribName(attrib);
209
210		if (attribName)
211		{
212			// Valid attribute, print value.
213			str << attribName << ", " << getSurfaceAttribValueStr(attrib, fmt.attribs[pos+1]);
214			pos += 2;
215		}
216		else
217		{
218			// Invalid attribute. Terminate parsing.
219			str << tcu::toHex(attrib) << ", ???";
220			break;
221		}
222	}
223
224	str << " }";
225	return str;
226}
227
228std::ostream& operator<< (std::ostream& str, const ContextAttribListFmt& fmt)
229{
230	int pos = 0;
231
232	str << "{ ";
233
234	for (;;)
235	{
236		int attrib = fmt.attribs[pos];
237
238		if (pos != 0)
239			str << ", ";
240
241		if (attrib == EGL_NONE)
242		{
243			// Terminate.
244			str << "EGL_NONE";
245			break;
246		}
247
248		const char*	attribName = getContextAttribName(attrib);
249
250		if (attribName)
251		{
252			// Valid attribute, print value.
253			str << attribName << ", " << getContextAttribValueStr(attrib, fmt.attribs[pos+1]);
254			pos += 2;
255		}
256		else
257		{
258			// Invalid attribute. Terminate parsing.
259			str << tcu::toHex(attrib) << ", ???";
260			break;
261		}
262	}
263
264	str << " }";
265	return str;
266}
267
268#include "egluStrUtil.inl"
269
270} // eglu
271