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