| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GUIWindowDebugInfo.h" |
| 10 |
|
| 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" |
| 30 |
|
| 31 |
#include <inttypes.h> |
| 32 |
|
| 33 |
CGUIWindowDebugInfo::CGUIWindowDebugInfo(void) |
| 34 |
: CGUIDialog(WINDOW_DEBUG_INFO, "", DialogModalityType::MODELESS) |
| 35 |
{ |
| 36 |
m_needsScaling = false; |
| 37 |
m_layout = nullptr; |
| 38 |
m_renderOrder = RENDER_ORDER_WINDOW_DEBUG; |
| 39 |
} |
| 40 |
|
| 41 |
CGUIWindowDebugInfo::~CGUIWindowDebugInfo(void) = default; |
| 42 |
|
| 43 |
void CGUIWindowDebugInfo::UpdateVisibility() |
| 44 |
{ |
| 45 |
if (LOG_LEVEL_DEBUG_FREEMEM <= CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_logLevel || g_SkinInfo->IsDebugging()) |
| 46 |
Open(); |
| 47 |
else |
| 48 |
Close(); |
| 49 |
} |
| 50 |
|
| 51 |
bool CGUIWindowDebugInfo::OnMessage(CGUIMessage &message) |
| 52 |
{ |
| 53 |
if (message.GetMessage() == GUI_MSG_WINDOW_DEINIT) |
| 54 |
{ |
| 55 |
delete m_layout; |
| 56 |
m_layout = nullptr; |
| 57 |
} |
| 58 |
else if (message.GetMessage() == GUI_MSG_REFRESH_TIMER) |
| 59 |
MarkDirtyRegion(); |
| 60 |
|
| 61 |
return CGUIDialog::OnMessage(message); |
| 62 |
} |
| 63 |
|
| 64 |
void CGUIWindowDebugInfo::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) |
| 65 |
{ |
| 66 |
CServiceBroker::GetWinSystem()->GetGfxContext().SetRenderingResolution(CServiceBroker::GetWinSystem()->GetGfxContext().GetResInfo(), false); |
| 67 |
|
| 68 |
CServiceBroker::GetCPUInfo()->GetUsedPercentage(); // must call it to recalculate pct values |
| 69 |
|
| 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) |
| 75 |
{ |
| 76 |
yShift *= -1; |
| 77 |
if (now % 5 == 0) |
| 78 |
xShift *= -1; |
| 79 |
lastShift = now; |
| 80 |
MarkDirtyRegion(); |
| 81 |
} |
| 82 |
|
| 83 |
if (!m_layout) |
| 84 |
{ |
| 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); |
| 89 |
} |
| 90 |
if (!m_layout) |
| 91 |
return; |
| 92 |
|
| 93 |
std::string info; |
| 94 |
if (LOG_LEVEL_DEBUG_FREEMEM <= CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_logLevel) |
| 95 |
{ |
| 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 |
| 132 |
} |
| 133 |
|
| 134 |
// render the skin debug info |
| 135 |
if (g_SkinInfo->IsDebugging()) |
| 136 |
{ |
| 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) |
| 145 |
{ |
| 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); |
| 157 |
} |
| 158 |
info += StringUtils::Format("Mouse: ({},{}) ", static_cast<int>(point.x), |
| 159 |
static_cast<int>(point.y)); |
| 160 |
if (window) |
| 161 |
{ |
| 162 |
CGUIControl *control = window->GetFocusedControl(); |
| 163 |
if (control) |
| 164 |
info += StringUtils::Format( |
| 165 |
"Focused: {} ({})", control->GetID(), |
| 166 |
CGUIControlFactory::TranslateControlType(control->GetControlType())); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
float w, h; |
| 171 |
if (m_layout->Update(info)) |
| 172 |
MarkDirtyRegion(); |
| 173 |
m_layout->GetTextExtent(w, h); |
| 174 |
|
| 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); |
| 178 |
} |
| 179 |
|
| 180 |
void CGUIWindowDebugInfo::Render() |
| 181 |
{ |
| 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); |
| 185 |
} |