Merge "Add EXT_primitive_bounding_box tests."
[platform/upstream/VK-GL-CTS.git] / framework / egl / egluCallLogWrapper.cpp
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
29 namespace eglu
30 {
31
32 using tcu::toHex;
33 using tcu::TestLog;
34
35 CallLogWrapper::CallLogWrapper (TestLog& log)
36         : m_log                 (log)
37         , m_enableLog   (false)
38 {
39 }
40
41 CallLogWrapper::~CallLogWrapper (void)
42 {
43 }
44
45 // Pointer formatter.
46
47 template <typename T>
48 class PointerFmt
49 {
50 public:
51         const T*        arr;
52         deUint32        size;
53
54         PointerFmt (const T* arr_, deUint32 size_) : arr(arr_), size(size_) {}
55 };
56
57 template <typename T>
58 std::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
76 template <typename T>
77 inline PointerFmt<T> getPointerStr (const T* arr, deUint32 size)
78 {
79         return PointerFmt<T>(arr, size);
80 }
81
82 typedef const char* (*GetEnumNameFunc) (int value);
83
84 // Enum pointer formatter.
85
86 class EnumPointerFmt
87 {
88 public:
89         const int*              value;
90         GetEnumNameFunc getName;
91
92         EnumPointerFmt (const int* value_, GetEnumNameFunc getName_) : value(value_), getName(getName_) {}
93 };
94
95 inline std::ostream& operator<< (std::ostream& str, EnumPointerFmt fmt)
96 {
97         if (fmt.value)
98                 return str << tcu::Format::Enum<int, 2>(fmt.getName, *fmt.value);
99         else
100                 return str << "(null)";
101 }
102
103 inline EnumPointerFmt getEnumPointerStr (const int* value, GetEnumNameFunc getName)
104 {
105         return EnumPointerFmt(value, getName);
106 }
107
108 // String formatter.
109
110 class StringFmt
111 {
112 public:
113         const char* str;
114         StringFmt (const char* str_) : str(str_) {}
115 };
116
117 inline std::ostream& operator<< (std::ostream& str, StringFmt fmt)
118 {
119         return str << (fmt.str ? fmt.str : "NULL");
120 }
121
122 inline StringFmt getStringStr (const char* value) { return StringFmt(value); }
123
124 // Config attrib pointer formatter
125
126 class ConfigAttribValuePointerFmt
127 {
128 public:
129         deUint32                attrib;
130         const int*              value;
131         ConfigAttribValuePointerFmt (deUint32 attrib_, const int* value_) : attrib(attrib_), value(value_) {}
132 };
133
134 inline ConfigAttribValuePointerFmt getConfigAttribValuePointerStr (deUint32 attrib, const int* value) { return ConfigAttribValuePointerFmt(attrib, value); }
135
136 inline 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
146 class ContextAttribValuePointerFmt
147 {
148 public:
149         deUint32                attrib;
150         const int*              value;
151         ContextAttribValuePointerFmt (deUint32 attrib_, const int* value_) : attrib(attrib_), value(value_) {}
152 };
153
154 inline ContextAttribValuePointerFmt getContextAttribValuePointerStr (deUint32 attrib, const int* value) { return ContextAttribValuePointerFmt(attrib, value); }
155
156 inline 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
166 class SurfaceAttribValuePointerFmt
167 {
168 public:
169         deUint32                attrib;
170         const int*              value;
171         SurfaceAttribValuePointerFmt (deUint32 attrib_, const int* value_) : attrib(attrib_), value(value_) {}
172 };
173
174 inline SurfaceAttribValuePointerFmt getSurfaceAttribValuePointerStr (deUint32 attrib, const int* value) { return SurfaceAttribValuePointerFmt(attrib, value); }
175
176 inline 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
186 class EGLDisplayFmt
187 {
188 public:
189         EGLDisplay display;
190         EGLDisplayFmt (EGLDisplay display_) : display(display_) {}
191 };
192
193 inline EGLDisplayFmt getEGLDisplayStr (EGLDisplay display) { return EGLDisplayFmt(display); }
194
195 inline 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
205 class EGLSurfaceFmt
206 {
207 public:
208         EGLSurface display;
209         EGLSurfaceFmt (EGLSurface display_) : display(display_) {}
210 };
211
212 inline EGLSurfaceFmt getEGLSurfaceStr (EGLSurface display) { return EGLSurfaceFmt(display); }
213
214 inline 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
224 class EGLContextFmt
225 {
226 public:
227         EGLContext display;
228         EGLContextFmt (EGLContext display_) : display(display_) {}
229 };
230
231 inline EGLContextFmt getEGLContextStr (EGLContext display) { return EGLContextFmt(display); }
232
233 inline 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