Applied context restoring
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_Debug.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiAnim_Debug.h
20  * @brief       Header file of _VeDebug class
21  *
22  * This file contains declarations _VeDebug class.
23  */
24
25 #ifndef _FUI_ANIM_INTERNAL_DEBUG_H_
26 #define _FUI_ANIM_INTERNAL_DEBUG_H_
27
28 #include <sys/time.h>
29 #include <Evas.h>
30
31 //#define VE_DEBUG // debug config
32 //#define UI_ANIM_DEBUG
33 #define VE_DEBUG_MODULE
34
35 extern "C" _OSP_EXPORT_ void DumpAllEvas(void);
36 extern "C" _OSP_EXPORT_ void DumpVeTree(void);
37 extern "C" _OSP_EXPORT_ void DumpEvasTree(void);
38 extern "C" _OSP_EXPORT_ void DumpVeLayout(void);
39
40 namespace Tizen { namespace Ui { namespace Animations
41 {
42
43 #ifdef VE_DEBUG_MODULE
44
45 #ifdef  _OSP_PERF_
46 class _ElapsedTime
47 {
48 public:
49         _ElapsedTime(const char* tag = null)
50         {
51                 struct timeval tv;
52
53                 tagName = tag;
54
55                 gettimeofday(&tv, null);
56                 start_time = (long long)tv.tv_sec * 1000000LL + (long long)tv.tv_usec / 1LL;
57
58                 depth++;
59                 maxdepth++;
60         }
61
62         ~_ElapsedTime(void)
63         {
64                 long long end_time;
65                 struct timeval tv;
66                 gettimeofday(&tv, null);
67                 end_time = (long long)tv.tv_sec * 1000000LL + (long long)tv.tv_usec / 1LL;
68
69                 depth--;
70                 if (count < 500)
71                         snprintf(logs[count++], 256, "%*s -->[%s]=%lld us\n", depth * 3, " ", tagName, end_time - start_time);
72
73                 if (depth == 0)
74                 {
75                         for (int i = 0; i < count; i++)
76                                 printf("%s", logs[i]);
77
78                         maxdepth = 0;
79                         count = 0;
80                 }
81         }
82
83
84 public:
85         static char logs[500][256];
86         static int depth;
87         static int count;
88         static int maxdepth;
89         long long start_time;
90         const char* tagName;
91 };              // _ElapsedTime
92 #endif
93
94 #define VeLog(UID, ...) \
95         SysLogInternal(UID, 0, 0, __VA_ARGS__);
96 #define VELOG(...) \
97         do \
98         { \
99                 if (_VeDebug::IsDebugEnabled()) \
100                 { \
101                         _VeDebug::DumpVisualElement(this, __func__, __LINE__, __VA_ARGS__); \
102                 } \
103         } while (0)
104
105 #define VELOGEX(_ELEMENT_, ...) \
106         do \
107         { \
108                 if (_VeDebug::IsDebugEnabled()) \
109                 { \
110                         _VeDebug::DumpVisualElement(_ELEMENT_, __func__, __LINE__, __VA_ARGS__); \
111                 } \
112         } while (0)
113
114 #define VELOGEX_NOFUNCTION(_ELEMENT_, ...) \
115         do \
116         { \
117                 if (_VeDebug::IsDebugEnabled()) \
118                 { \
119                         _VeDebug::DumpVisualElement(_ELEMENT_, null, 0, __VA_ARGS__); \
120                 } \
121         } while (0)
122
123 #define VEDUMPTREE(_ELEMENT_, _INDENT_) \
124         do \
125         { \
126                 if (_VeDebug::IsDebugEnabled()) \
127                 { \
128                         _VeDebug::DumpVeTree(_ELEMENT_, _INDENT_); \
129                 } \
130         } while (0)
131
132 #define VELOGRECTTAG    "[%.1f:%.1f ~ %.1f:%.1f]"
133 #define VELOGRECT(r)    (r).x, (r).y, (r).GetBottomRight().x, (r).GetBottomRight().y
134
135 class _VisualElementImpl;
136
137 class _VeDebug
138 {
139 public:
140         static void DumpVisualElement(_VisualElementImpl* pElement, const char* func, int line, const char* fmt, ...);
141         static void PrintVeTree(_VisualElementImpl* pElement = 0, int depth = 0, unsigned int remainedChild = 0);
142         static void DumpVeTree(_VisualElementImpl* pElement = 0, int indent = 0);
143         static void DumpVeImage(_VisualElementImpl* pElement = 0, const char* pathPrefix = 0);
144         static void DumpAllVeImages(_VisualElementImpl* pElement = 0, const char* pathPrefix = 0);
145         static void ReflushAll(_VisualElementImpl* pElement, int depth = 0);
146         static void SetDebugEnabled(bool enable);
147         static bool IsDebugEnabled(void);
148
149         static void DumpEvasTree(_VisualElementImpl* pElement, int indent);
150         static void DumpAllEvas(Evas* pEvas);
151         static void DumpAllEvasImages(Evas* pEvas);
152
153 #ifdef UI_ANIM_DEBUG
154         static void DumpVisualElementLayout(_VisualElementImpl* pElement, FILE* pFile);
155         static void DumpVeLayout(_VisualElementImpl* pElement, int indent, FILE* pFile);
156
157         static void DumpEvasObjectForGraphI(FILE* pFile, Evas_Object* pEvasObject, int depth, int pos);
158         static void DumpEvasTreeGraphI(FILE* pFile, Evas_Object* pObject, int depth, int pos);
159         static void DumpVeObjectForGraphI(FILE* pFile, _VisualElementImpl* pVisualElementImpl, int depth, int pos);
160         static void DumpVeTreeGraphI(FILE* pFile, _VisualElementImpl* pVisualElementImpl, int depth, int pos);
161
162         static void DumpEvasTreeGraph(const char* pFilePath, VisualElement* pVisualElement);
163 #endif
164
165
166 private:
167         _VeDebug(void);
168         _VeDebug(const _VeDebug& rhs);
169         ~_VeDebug(void);
170
171         _VeDebug& operator =(const _VeDebug& rhs);
172
173 private:
174         static void DumpEvasTreeI(Evas_Object* pParent, int indent);
175
176 private:
177         static bool __veDebugEnabled;
178 };              //_VeDebug
179
180 #else
181 #define VELOG(...)
182 #define VELOGEX(_Element_, ...)
183 #define VELOGEX_NOFUNCTION(_ELEMENT_, ...)
184 #define VEDUMPTREE(_ELEMENT_, _INDENT_)
185 #define VELOGRECTTAG
186 #define VELOGRECT(r)
187 #endif
188
189 }}}             // Tizen::Ui::Animations
190
191 #endif //_FUI_ANIM_INTERNAL_DEBUG_H_
192