2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "GUIWindowDebugInfo.h"
11 #include "CompileInfo.h"
12 #include "GUIInfoManager.h"
13 #include "ServiceBroker.h"
14 #include "addons/Skin.h"
15 #include "filesystem/SpecialProtocol.h"
16 #include "guilib/GUIComponent.h"
17 #include "guilib/GUIControlFactory.h"
18 #include "guilib/GUIControlProfiler.h"
19 #include "guilib/GUIFontManager.h"
20 #include "guilib/GUITextLayout.h"
21 #include "guilib/GUIWindowManager.h"
22 #include "input/WindowTranslator.h"
23 #include "settings/AdvancedSettings.h"
24 #include "settings/SettingsComponent.h"
25 #include "utils/CPUInfo.h"
26 #include "utils/MemUtils.h"
27 #include "utils/StringUtils.h"
28 #include "utils/Variant.h"
29 #include "utils/log.h"
33 CGUIWindowDebugInfo::CGUIWindowDebugInfo(void)
34 : CGUIDialog(WINDOW_DEBUG_INFO
, "", DialogModalityType::MODELESS
)
36 m_needsScaling
= false;
38 m_renderOrder
= RENDER_ORDER_WINDOW_DEBUG
;
41 CGUIWindowDebugInfo::~CGUIWindowDebugInfo(void) = default;
43 void CGUIWindowDebugInfo::UpdateVisibility()
45 if (LOG_LEVEL_DEBUG_FREEMEM
<= CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_logLevel
|| g_SkinInfo
->IsDebugging())
51 bool CGUIWindowDebugInfo::OnMessage(CGUIMessage
&message
)
53 if (message
.GetMessage() == GUI_MSG_WINDOW_DEINIT
)
58 else if (message
.GetMessage() == GUI_MSG_REFRESH_TIMER
)
61 return CGUIDialog::OnMessage(message
);
64 void CGUIWindowDebugInfo::Process(unsigned int currentTime
, CDirtyRegionList
&dirtyregions
)
66 CServiceBroker::GetWinSystem()->GetGfxContext().SetRenderingResolution(CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo(), false);
68 CServiceBroker::GetCPUInfo()->GetUsedPercentage(); // must call it to recalculate pct values
70 static int yShift
= 20;
71 static int xShift
= 40;
72 static unsigned int lastShift
= time(nullptr);
73 time_t now
= time(nullptr);
74 if (now
- lastShift
> 10)
85 CGUIFont
*font13
= g_fontManager
.GetDefaultFont();
86 CGUIFont
*font13border
= g_fontManager
.GetDefaultFont(true);
88 m_layout
= new CGUITextLayout(font13
, true, 0, font13border
);
94 if (LOG_LEVEL_DEBUG_FREEMEM
<= CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_logLevel
)
96 KODI::MEMORY::MemoryStatus stat
;
97 KODI::MEMORY::GetMemoryStatus(&stat
);
98 std::string profiling
= CGUIControlProfiler::IsRunning() ? " (profiling)" : "";
100 if (CServiceBroker::GetCPUInfo()->SupportsCPUUsage())
101 strCores
= CServiceBroker::GetCPUInfo()->GetCoresUsageString();
104 std::string lcAppName
= CCompileInfo::GetAppName();
105 StringUtils::ToLower(lcAppName
);
106 #if !defined(TARGET_POSIX)
107 info
= StringUtils::Format("LOG: {}{}.log\nMEM: {}/{} KB - FPS: {:2.1f} fps\nCPU: {}{}",
108 CSpecialProtocol::TranslatePath("special://logpath"), lcAppName
,
109 stat
.availPhys
/ 1024, stat
.totalPhys
/ 1024,
110 CServiceBroker::GetGUI()
113 .GetSystemInfoProvider()
115 strCores
, profiling
);
117 double dCPU
= m_resourceCounter
.GetCPUUsage();
118 std::string ucAppName
= lcAppName
;
119 StringUtils::ToUpper(ucAppName
);
120 info
= StringUtils::Format("LOG: {}{}.log\n"
121 "MEM: {}/{} KB - FPS: {:2.1f} fps\n"
122 "CPU: {} (CPU-{} {:4.2f}%{})",
123 CSpecialProtocol::TranslatePath("special://logpath"), lcAppName
,
124 stat
.availPhys
/ 1024, stat
.totalPhys
/ 1024,
125 CServiceBroker::GetGUI()
128 .GetSystemInfoProvider()
130 strCores
, ucAppName
, dCPU
, profiling
);
134 // render the skin debug info
135 if (g_SkinInfo
->IsDebugging())
139 CGUIWindow
*window
= CServiceBroker::GetGUI()->GetWindowManager().GetWindow(CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindowOrDialog());
140 CGUIWindow
*pointer
= CServiceBroker::GetGUI()->GetWindowManager().GetWindow(WINDOW_DIALOG_POINTER
);
143 point
= CPoint(pointer
->GetXPosition(), pointer
->GetYPosition());
146 std::string windowName
= CWindowTranslator::TranslateWindow(window
->GetID());
147 if (!windowName
.empty())
148 windowName
+= " (" + window
->GetProperty("xmlfile").asString() + ")";
150 windowName
= window
->GetProperty("xmlfile").asString();
151 info
+= "Window: " + windowName
+ "\n";
152 // transform the mouse coordinates to this window's coordinates
153 CServiceBroker::GetWinSystem()->GetGfxContext().SetScalingResolution(window
->GetCoordsRes(), true);
154 point
.x
*= CServiceBroker::GetWinSystem()->GetGfxContext().GetGUIScaleX();
155 point
.y
*= CServiceBroker::GetWinSystem()->GetGfxContext().GetGUIScaleY();
156 CServiceBroker::GetWinSystem()->GetGfxContext().SetRenderingResolution(CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo(), false);
158 info
+= StringUtils::Format("Mouse: ({},{}) ", static_cast<int>(point
.x
),
159 static_cast<int>(point
.y
));
162 CGUIControl
*control
= window
->GetFocusedControl();
164 info
+= StringUtils::Format(
165 "Focused: {} ({})", control
->GetID(),
166 CGUIControlFactory::TranslateControlType(control
->GetControlType()));
171 if (m_layout
->Update(info
))
173 m_layout
->GetTextExtent(w
, h
);
175 float x
= xShift
+ 0.04f
* CServiceBroker::GetWinSystem()->GetGfxContext().GetWidth();
176 float y
= yShift
+ 0.04f
* CServiceBroker::GetWinSystem()->GetGfxContext().GetHeight();
177 m_renderRegion
.SetRect(x
, y
, x
+w
, y
+h
);
180 void CGUIWindowDebugInfo::Render()
182 CServiceBroker::GetWinSystem()->GetGfxContext().SetRenderingResolution(CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo(), false);
184 m_layout
->RenderOutline(m_renderRegion
.x1
, m_renderRegion
.y1
, 0xffffffff, 0xff000000, 0, 0);