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 call wrapper for logging.
22 *//*--------------------------------------------------------------------*/
23
24#include "egluCallLogWrapper.hpp"
25#include "egluStrUtil.hpp"
26#include "deStringUtil.hpp"
27#include "deInt32.h"
28
29namespace eglu
30{
31
32using tcu::toHex;
33using tcu::TestLog;
34
35CallLogWrapper::CallLogWrapper (TestLog& log)
36	: m_log			(log)
37	, m_enableLog	(false)
38{
39}
40
41CallLogWrapper::~CallLogWrapper (void)
42{
43}
44
45// Pointer formatter.
46
47template <typename T>
48class PointerFmt
49{
50public:
51	const T*	arr;
52	deUint32	size;
53
54	PointerFmt (const T* arr_, deUint32 size_) : arr(arr_), size(size_) {}
55};
56
57template <typename T>
58std::ostream& operator<< (std::ostream& str, PointerFmt<T> fmt)
59{
60	if (fmt.arr != DE_NULL)
61	{
62		str << "{ ";
63		for (deUint32 ndx = 0; ndx < fmt.size; ndx++)
64		{
65			if (ndx != 0)
66				str << ", ";
67			str << fmt.arr[ndx];
68		}
69		str << " }";
70		return str;
71	}
72	else
73		return str << "(null)";
74}
75
76template <typename T>
77inline PointerFmt<T> getPointerStr (const T* arr, deUint32 size)
78{
79	return PointerFmt<T>(arr, size);
80}
81
82typedef const char* (*GetEnumNameFunc) (int value);
83
84// Enum pointer formatter.
85
86class EnumPointerFmt
87{
88public:
89	const int*		value;
90	GetEnumNameFunc	getName;
91
92	EnumPointerFmt (const int* value_, GetEnumNameFunc getName_) : value(value_), getName(getName_) {}
93};
94
95inline std::ostream& operator<< (std::ostream& str, EnumPointerFmt fmt)
96{
97	if (fmt.value)
98		return str << tcu::Format::Enum(fmt.getName, *fmt.value);
99	else
100		return str << "(null)";
101}
102
103inline EnumPointerFmt getEnumPointerStr (const int* value, GetEnumNameFunc getName)
104{
105	return EnumPointerFmt(value, getName);
106}
107
108// String formatter.
109
110class StringFmt
111{
112public:
113	const char* str;
114	StringFmt (const char* str_) : str(str_) {}
115};
116
117inline std::ostream& operator<< (std::ostream& str, StringFmt fmt)
118{
119	return str << (fmt.str ? fmt.str : "NULL");
120}
121
122inline StringFmt getStringStr (const char* value) { return StringFmt(value); }
123
124// Config attrib pointer formatter
125
126class ConfigAttribValuePointerFmt
127{
128public:
129	deUint32		attrib;
130	const int*		value;
131	ConfigAttribValuePointerFmt (deUint32 attrib_, const int* value_) : attrib(attrib_), value(value_) {}
132};
133
134inline ConfigAttribValuePointerFmt getConfigAttribValuePointerStr (deUint32 attrib, const int* value) { return ConfigAttribValuePointerFmt(attrib, value); }
135
136inline std::ostream& operator<< (std::ostream& str, const ConfigAttribValuePointerFmt& fmt)
137{
138	if (fmt.value)
139		return str << getConfigAttribValueStr(fmt.attrib, *fmt.value);
140	else
141		return str << "NULL";
142}
143
144// Context attrib pointer formatter
145
146class ContextAttribValuePointerFmt
147{
148public:
149	deUint32		attrib;
150	const int*		value;
151	ContextAttribValuePointerFmt (deUint32 attrib_, const int* value_) : attrib(attrib_), value(value_) {}
152};
153
154inline ContextAttribValuePointerFmt getContextAttribValuePointerStr (deUint32 attrib, const int* value) { return ContextAttribValuePointerFmt(attrib, value); }
155
156inline std::ostream& operator<< (std::ostream& str, const ContextAttribValuePointerFmt& fmt)
157{
158	if (fmt.value)
159		return str << getContextAttribValueStr(fmt.attrib, *fmt.value);
160	else
161		return str << "NULL";
162}
163
164// Surface attrib pointer formatter
165
166class SurfaceAttribValuePointerFmt
167{
168public:
169	deUint32		attrib;
170	const int*		value;
171	SurfaceAttribValuePointerFmt (deUint32 attrib_, const int* value_) : attrib(attrib_), value(value_) {}
172};
173
174inline SurfaceAttribValuePointerFmt getSurfaceAttribValuePointerStr (deUint32 attrib, const int* value) { return SurfaceAttribValuePointerFmt(attrib, value); }
175
176inline std::ostream& operator<< (std::ostream& str, const SurfaceAttribValuePointerFmt& fmt)
177{
178	if (fmt.value)
179		return str << getSurfaceAttribValueStr(fmt.attrib, *fmt.value);
180	else
181		return str << "NULL";
182}
183
184// EGLDisplay formatter
185
186class EGLDisplayFmt
187{
188public:
189	EGLDisplay display;
190	EGLDisplayFmt (EGLDisplay display_) : display(display_) {}
191};
192
193inline EGLDisplayFmt getEGLDisplayStr (EGLDisplay display) { return EGLDisplayFmt(display); }
194
195inline std::ostream& operator<< (std::ostream& str, const EGLDisplayFmt& fmt)
196{
197	if (fmt.display == EGL_NO_DISPLAY)
198		return str << "EGL_NO_DISPLAY";
199	else
200		return str << toHex(fmt.display);
201}
202
203// EGLSurface formatter
204
205class EGLSurfaceFmt
206{
207public:
208	EGLSurface display;
209	EGLSurfaceFmt (EGLSurface display_) : display(display_) {}
210};
211
212inline EGLSurfaceFmt getEGLSurfaceStr (EGLSurface display) { return EGLSurfaceFmt(display); }
213
214inline std::ostream& operator<< (std::ostream& str, const EGLSurfaceFmt& fmt)
215{
216	if (fmt.display == EGL_NO_SURFACE)
217		return str << "EGL_NO_SURFACE";
218	else
219		return str << toHex(fmt.display);
220}
221
222// EGLContext formatter
223
224class EGLContextFmt
225{
226public:
227	EGLContext display;
228	EGLContextFmt (EGLContext display_) : display(display_) {}
229};
230
231inline EGLContextFmt getEGLContextStr (EGLContext display) { return EGLContextFmt(display); }
232
233inline std::ostream& operator<< (std::ostream& str, const EGLContextFmt& fmt)
234{
235	if (fmt.display == EGL_NO_CONTEXT)
236		return str << "EGL_NO_CONTEXT";
237	else
238		return str << toHex(fmt.display);
239}
240
241// API entry-point implementations are auto-generated
242#include "egluCallLogWrapper.inl"
243
244} // eglu
245