eb022609515898a66284553767ed73ca0f0159a7
[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 VE_DEBUG_MODULE
33
34 extern "C" _OSP_EXPORT_ void DumpAllEvas(void);
35 extern "C" _OSP_EXPORT_ void DumpVeTree(void);
36 extern "C" _OSP_EXPORT_ void DumpEvasTree(void);
37 extern "C" _OSP_EXPORT_ void DumpVeLayout(void);
38
39 namespace Tizen { namespace Ui { namespace Animations
40 {
41
42 #ifdef VE_DEBUG_MODULE
43
44 #ifdef  _OSP_PERF_
45 class _ElapsedTime
46 {
47 public:
48         _ElapsedTime(const char* tag = null)
49         {
50                 struct timeval tv;
51
52                 tagName = tag;
53
54                 gettimeofday(&tv, null);
55                 start_time = (long long)tv.tv_sec * 1000000LL + (long long)tv.tv_usec / 1LL;
56
57                 depth++;
58                 maxdepth++;
59         }
60
61         ~_ElapsedTime(void)
62         {
63                 long long end_time;
64                 struct timeval tv;
65                 gettimeofday(&tv, null);
66                 end_time = (long long)tv.tv_sec * 1000000LL + (long long)tv.tv_usec / 1LL;
67
68                 depth--;
69                 if (count < 500)
70                         snprintf(logs[count++], 256, "%*s -->[%s]=%lld us\n", depth * 3, " ", tagName, end_time - start_time);
71
72                 if (depth == 0)
73                 {
74                         for (int i = 0; i < count; i++)
75                                 printf("%s", logs[i]);
76
77                         maxdepth = 0;
78                         count = 0;
79                 }
80         }
81
82
83 public:
84         static char logs[500][256];
85         static int depth;
86         static int count;
87         static int maxdepth;
88         long long start_time;
89         const char* tagName;
90 };              // _ElapsedTime
91 #endif
92
93 #define VeLog(UID, ...) \
94         SysLogInternal(UID, 0, 0, __VA_ARGS__);
95 #define VELOG(...) \
96         do \
97         { \
98                 if (_VeDebug::IsDebugEnabled()) \
99                 { \
100                         _VeDebug::DumpVisualElement(this, __func__, __LINE__, __VA_ARGS__); \
101                 } \
102         } while (0)
103
104 #define VELOGEX(_ELEMENT_, ...) \
105         do \
106         { \
107                 if (_VeDebug::IsDebugEnabled()) \
108                 { \
109                         _VeDebug::DumpVisualElement(_ELEMENT_, __func__, __LINE__, __VA_ARGS__); \
110                 } \
111         } while (0)
112
113 #define VELOGEX_NOFUNCTION(_ELEMENT_, ...) \
114         do \
115         { \
116                 if (_VeDebug::IsDebugEnabled()) \
117                 { \
118                         _VeDebug::DumpVisualElement(_ELEMENT_, null, 0, __VA_ARGS__); \
119                 } \
120         } while (0)
121
122 #define VEDUMPTREE(_ELEMENT_, _INDENT_) \
123         do \
124         { \
125                 if (_VeDebug::IsDebugEnabled()) \
126                 { \
127                         _VeDebug::DumpVeTree(_ELEMENT_, _INDENT_); \
128                 } \
129         } while (0)
130
131 #define VELOGRECTTAG    "[%.1f:%.1f ~ %.1f:%.1f]"
132 #define VELOGRECT(r)    (r).x, (r).y, (r).GetBottomRight().x, (r).GetBottomRight().y
133
134 class _VisualElementImpl;
135
136 class _VeDebug
137 {
138 public:
139         static void DumpVisualElement(_VisualElementImpl* pElement, const char* func, int line, const char* fmt, ...);
140         static void PrintVeTree(_VisualElementImpl* pElement = 0, int depth = 0, unsigned int remainedChild = 0);
141         static void DumpVeTree(_VisualElementImpl* pElement = 0, int indent = 0);
142         static void DumpVeImage(_VisualElementImpl* pElement = 0, const char* pathPrefix = 0);
143         static void DumpAllVeImages(_VisualElementImpl* pElement = 0, const char* pathPrefix = 0);
144         static void ReflushAll(_VisualElementImpl* pElement, int depth = 0);
145         static void SetDebugEnabled(bool enable);
146         static bool IsDebugEnabled(void);
147
148         static void DumpEvasTree(_VisualElementImpl* pElement, int indent);
149         static void DumpAllEvas(Evas* pEvas);
150         static void DumpAllEvasImages(Evas* pEvas);
151
152 #ifdef UI_ANIM_DEBUG
153         static void DumpVisualElementLayout(_VisualElementImpl* pElement, FILE* pFile);
154         static void DumpVeLayout(_VisualElementImpl* pElement, int indent, FILE* pFile);
155
156         static void DumpEvasObjectForGraphI(FILE* pFile, Evas_Object* pEvasObject, int depth, int pos);
157         static void DumpEvasTreeGraphI(FILE* pFile, Evas_Object* pObject, int depth, int pos);
158         static void DumpVeObjectForGraphI(FILE* pFile, _VisualElementImpl* pVisualElementImpl, int depth, int pos);
159         static void DumpVeTreeGraphI(FILE* pFile, _VisualElementImpl* pVisualElementImpl, int depth, int pos);
160
161         static void DumpEvasTreeGraph(const char* pFilePath, VisualElement* pVisualElement);
162 #endif
163
164
165 private:
166         _VeDebug(void);
167         _VeDebug(const _VeDebug& rhs);
168         ~_VeDebug(void);
169
170         _VeDebug& operator =(const _VeDebug& rhs);
171
172 private:
173         static void DumpEvasTreeI(Evas_Object* pParent, int indent);
174
175 private:
176         static bool __veDebugEnabled;
177 };              //_VeDebug
178
179 #else
180 #define VELOG(...)
181 #define VELOGEX(_Element_, ...)
182 #define VELOGEX_NOFUNCTION(_ELEMENT_, ...)
183 #define VEDUMPTREE(_ELEMENT_, _INDENT_)
184 #define VELOGRECTTAG
185 #define VELOGRECT(r)
186 #endif
187
188 }}}             // Tizen::Ui::Animations
189
190 #endif //_FUI_ANIM_INTERNAL_DEBUG_H_
191