[video] fix selection after changing video or extra art
[xbmc.git] / xbmc / windows / GUIWindowDebugInfo.cpp
blob764e6b0b714f71c09f754eaeb53241dc025a83ea
1 /*
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.
7 */
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"
31 #include <inttypes.h>
33 CGUIWindowDebugInfo::CGUIWindowDebugInfo(void)
34 : CGUIDialog(WINDOW_DEBUG_INFO, "", DialogModalityType::MODELESS)
36 m_needsScaling = false;
37 m_layout = nullptr;
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())
46 Open();
47 else
48 Close();
51 bool CGUIWindowDebugInfo::OnMessage(CGUIMessage &message)
53 if (message.GetMessage() == GUI_MSG_WINDOW_DEINIT)
55 delete m_layout;
56 m_layout = nullptr;
58 else if (message.GetMessage() == GUI_MSG_REFRESH_TIMER)
59 MarkDirtyRegion();
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)
76 yShift *= -1;
77 if (now % 5 == 0)
78 xShift *= -1;
79 lastShift = now;
80 MarkDirtyRegion();
83 if (!m_layout)
85 CGUIFont *font13 = g_fontManager.GetDefaultFont();
86 CGUIFont *font13border = g_fontManager.GetDefaultFont(true);
87 if (font13)
88 m_layout = new CGUITextLayout(font13, true, 0, font13border);
90 if (!m_layout)
91 return;
93 std::string info;
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)" : "";
99 std::string strCores;
100 if (CServiceBroker::GetCPUInfo()->SupportsCPUUsage())
101 strCores = CServiceBroker::GetCPUInfo()->GetCoresUsageString();
102 else
103 strCores = "N/A";
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()
111 ->GetInfoManager()
112 .GetInfoProviders()
113 .GetSystemInfoProvider()
114 .GetFPS(),
115 strCores, profiling);
116 #else
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()
126 ->GetInfoManager()
127 .GetInfoProviders()
128 .GetSystemInfoProvider()
129 .GetFPS(),
130 strCores, ucAppName, dCPU, profiling);
131 #endif
134 // render the skin debug info
135 if (g_SkinInfo->IsDebugging())
137 if (!info.empty())
138 info += "\n";
139 CGUIWindow *window = CServiceBroker::GetGUI()->GetWindowManager().GetWindow(CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindowOrDialog());
140 CGUIWindow *pointer = CServiceBroker::GetGUI()->GetWindowManager().GetWindow(WINDOW_DIALOG_POINTER);
141 CPoint point;
142 if (pointer)
143 point = CPoint(pointer->GetXPosition(), pointer->GetYPosition());
144 if (window)
146 std::string windowName = CWindowTranslator::TranslateWindow(window->GetID());
147 if (!windowName.empty())
148 windowName += " (" + window->GetProperty("xmlfile").asString() + ")";
149 else
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));
160 if (window)
162 CGUIControl *control = window->GetFocusedControl();
163 if (control)
164 info += StringUtils::Format(
165 "Focused: {} ({})", control->GetID(),
166 CGUIControlFactory::TranslateControlType(control->GetControlType()));
170 float w, h;
171 if (m_layout->Update(info))
172 MarkDirtyRegion();
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);
183 if (m_layout)
184 m_layout->RenderOutline(m_renderRegion.x1, m_renderRegion.y1, 0xffffffff, 0xff000000, 0, 0);