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			return str << getBoolDontCareStr(attribFmt.value);
60
61		case EGL_ALPHA_MASK_SIZE:
62		case EGL_ALPHA_SIZE:
63		case EGL_BLUE_SIZE:
64		case EGL_BUFFER_SIZE:
65		case EGL_CONFIG_ID:
66		case EGL_DEPTH_SIZE:
67		case EGL_GREEN_SIZE:
68		case EGL_LEVEL:
69		case EGL_LUMINANCE_SIZE:
70		case EGL_MAX_SWAP_INTERVAL:
71		case EGL_MIN_SWAP_INTERVAL:
72		case EGL_RED_SIZE:
73		case EGL_SAMPLE_BUFFERS:
74		case EGL_SAMPLES:
75		case EGL_STENCIL_SIZE:
76		case EGL_TRANSPARENT_RED_VALUE:
77		case EGL_TRANSPARENT_GREEN_VALUE:
78		case EGL_TRANSPARENT_BLUE_VALUE:
79			return str << (int)attribFmt.value;
80
81		default:
82			return str << tcu::toHex(attribFmt.value);
83	}
84}
85
86std::ostream& operator<< (std::ostream& str, const ContextAttribValueFmt& attribFmt)
87{
88	switch (attribFmt.attribute)
89	{
90		case EGL_CONFIG_ID:
91		case EGL_CONTEXT_CLIENT_VERSION:
92			return str << (int)attribFmt.value;
93
94		case EGL_CONTEXT_CLIENT_TYPE:
95			return str << getAPIStr(attribFmt.value);
96
97		case EGL_RENDER_BUFFER:
98			return str << getRenderBufferStr(attribFmt.value);
99
100		default:
101			return str << tcu::toHex(attribFmt.value);
102	}
103}
104
105std::ostream& operator<< (std::ostream& str, const SurfaceAttribValueFmt& attribFmt)
106{
107	switch (attribFmt.attribute)
108	{
109		case EGL_CONFIG_ID:
110		case EGL_WIDTH:
111		case EGL_HEIGHT:
112		case EGL_HORIZONTAL_RESOLUTION:
113		case EGL_VERTICAL_RESOLUTION:
114		case EGL_PIXEL_ASPECT_RATIO:
115			return str << (int)attribFmt.value;
116
117		case EGL_LARGEST_PBUFFER:
118		case EGL_MIPMAP_TEXTURE:
119			return str << getBoolDontCareStr(attribFmt.value);
120
121		case EGL_MULTISAMPLE_RESOLVE:
122			return str << getMultisampleResolveStr(attribFmt.value);
123
124		case EGL_RENDER_BUFFER:
125			return str << getRenderBufferStr(attribFmt.value);
126
127		case EGL_SWAP_BEHAVIOR:
128			return str << getSwapBehaviorStr(attribFmt.value);
129
130		case EGL_TEXTURE_FORMAT:
131			return str << getTextureFormatStr(attribFmt.value);
132
133		case EGL_TEXTURE_TARGET:
134			return str << getTextureTargetStr(attribFmt.value);
135
136		case EGL_ALPHA_FORMAT:
137			return str << getAlphaFormatStr(attribFmt.value);
138
139		case EGL_COLORSPACE:
140			return str << getColorspaceStr(attribFmt.value);
141
142		default:
143			return str << tcu::toHex(attribFmt.value);
144	}
145}
146
147std::ostream& operator<< (std::ostream& str, const ConfigAttribListFmt& fmt)
148{
149	int pos = 0;
150
151	str << "{ ";
152
153	for (;;)
154	{
155		int attrib = fmt.attribs[pos];
156
157		if (pos != 0)
158			str << ", ";
159
160		if (attrib == EGL_NONE)
161		{
162			// Terminate.
163			str << "EGL_NONE";
164			break;
165		}
166
167		const char*	attribName = getConfigAttribName(attrib);
168
169		if (attribName)
170		{
171			// Valid attribute, print value.
172			str << attribName << ", " << getConfigAttribValueStr(attrib, fmt.attribs[pos+1]);
173			pos += 2;
174		}
175		else
176		{
177			// Invalid attribute. Terminate parsing.
178			str << tcu::toHex(attrib) << ", ???";
179			break;
180		}
181	}
182
183	str << " }";
184	return str;
185}
186
187std::ostream& operator<< (std::ostream& str, const SurfaceAttribListFmt& fmt)
188{
189	int pos = 0;
190
191	str << "{ ";
192
193	for (;;)
194	{
195		int attrib = fmt.attribs[pos];
196
197		if (pos != 0)
198			str << ", ";
199
200		if (attrib == EGL_NONE)
201		{
202			// Terminate.
203			str << "EGL_NONE";
204			break;
205		}
206
207		const char*	attribName = getSurfaceAttribName(attrib);
208
209		if (attribName)
210		{
211			// Valid attribute, print value.
212			str << attribName << ", " << getSurfaceAttribValueStr(attrib, fmt.attribs[pos+1]);
213			pos += 2;
214		}
215		else
216		{
217			// Invalid attribute. Terminate parsing.
218			str << tcu::toHex(attrib) << ", ???";
219			break;
220		}
221	}
222
223	str << " }";
224	return str;
225}
226
227std::ostream& operator<< (std::ostream& str, const ContextAttribListFmt& fmt)
228{
229	int pos = 0;
230
231	str << "{ ";
232
233	for (;;)
234	{
235		int attrib = fmt.attribs[pos];
236
237		if (pos != 0)
238			str << ", ";
239
240		if (attrib == EGL_NONE)
241		{
242			// Terminate.
243			str << "EGL_NONE";
244			break;
245		}
246
247		const char*	attribName = getContextAttribName(attrib);
248
249		if (attribName)
250		{
251			// Valid attribute, print value.
252			str << attribName << ", " << getContextAttribValueStr(attrib, fmt.attribs[pos+1]);
253			pos += 2;
254		}
255		else
256		{
257			// Invalid attribute. Terminate parsing.
258			str << tcu::toHex(attrib) << ", ???";
259			break;
260		}
261	}
262
263	str << " }";
264	return str;
265}
266
267#include "egluStrUtil.inl"
268
269} // eglu
270