[guilib] fix labelcontrols with auto width always being marked as dirty if they speci...
[vuplus_xbmc] / xbmc / guilib / GUIControlProfiler.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #ifndef GUILIB_GUICONTROLPROFILER_H__
22 #define GUILIB_GUICONTROLPROFILER_H__
23 #pragma once
24
25 #include "GUIControl.h"
26
27 class CGUIControlProfiler;
28 class TiXmlElement;
29
30 class CGUIControlProfilerItem
31 {
32 public:
33   CGUIControlProfiler *m_pProfiler;
34   CGUIControlProfilerItem * m_pParent;
35   CGUIControl *m_pControl;
36   std::vector<CGUIControlProfilerItem *> m_vecChildren;
37   CStdString m_strDescription;
38   int m_controlID;
39   CGUIControl::GUICONTROLTYPES m_ControlType;
40   unsigned int m_visTime;
41   unsigned int m_renderTime;
42   int64_t m_i64VisStart;
43   int64_t m_i64RenderStart;
44
45   CGUIControlProfilerItem(CGUIControlProfiler *pProfiler, CGUIControlProfilerItem *pParent, CGUIControl *pControl);
46   ~CGUIControlProfilerItem(void);
47
48   void Reset(CGUIControlProfiler *pProfiler);
49   void BeginVisibility(void);
50   void EndVisibility(void);
51   void BeginRender(void);
52   void EndRender(void);
53   void SaveToXML(TiXmlElement *parent);
54   unsigned int GetTotalTime(void) const { return m_visTime + m_renderTime; };
55
56   CGUIControlProfilerItem *AddControl(CGUIControl *pControl);
57   CGUIControlProfilerItem *FindOrAddControl(CGUIControl *pControl, bool recurse);
58 };
59
60 class CGUIControlProfiler
61 {
62 public:
63   static CGUIControlProfiler &Instance(void);
64   static bool IsRunning(void);
65
66   void Start(void);
67   void EndFrame(void);
68   void BeginVisibility(CGUIControl *pControl);
69   void EndVisibility(CGUIControl *pControl);
70   void BeginRender(CGUIControl *pControl);
71   void EndRender(CGUIControl *pControl);
72   int GetMaxFrameCount(void) const { return m_iMaxFrameCount; };
73   void SetMaxFrameCount(int iMaxFrameCount) { m_iMaxFrameCount = iMaxFrameCount; };
74   void SetOutputFile(const CStdString &strOutputFile) { m_strOutputFile = strOutputFile; };
75   const CStdString &GetOutputFile(void) const { return m_strOutputFile; };
76   bool SaveResults(void);
77   unsigned int GetTotalTime(void) const { return m_ItemHead.GetTotalTime(); };
78
79   float m_fPerfScale;
80 private:
81   CGUIControlProfiler(void);
82   ~CGUIControlProfiler(void) {};
83   CGUIControlProfiler(const CGUIControlProfiler &that);
84   CGUIControlProfiler &operator=(const CGUIControlProfiler &that);
85
86   CGUIControlProfilerItem m_ItemHead;
87   CGUIControlProfilerItem *m_pLastItem;
88   CGUIControlProfilerItem *FindOrAddControl(CGUIControl *pControl);
89
90   static bool m_bIsRunning;
91   CStdString m_strOutputFile;
92   int m_iMaxFrameCount;
93   int m_iFrameCount;
94 };
95
96 #define GUIPROFILER_VISIBILITY_BEGIN(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().BeginVisibility(x); }
97 #define GUIPROFILER_VISIBILITY_END(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().EndVisibility(x); }
98 #define GUIPROFILER_RENDER_BEGIN(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().BeginRender(x); }
99 #define GUIPROFILER_RENDER_END(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().EndRender(x); }
100
101 #endif