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