aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Borges de Freitas <92enen@gmail.com>2023-09-12 10:26:21 +0100
committerGitHub <noreply@github.com>2023-09-12 10:26:21 +0100
commite1f6fbd900dde2fac35bd785727176c1f07116aa (patch)
tree22f49244c88e96e18767e4c83df00d1d0f5c41a0
parent38128e22de2f59e0397428ea8540c4b1b39c3b23 (diff)
parent4688f74bf79f7e8ddf0960e22ddbfc0579a48d87 (diff)
Merge pull request #23741 from enen92/gpu_info_platform
[info] Platform code for GPUInfo
-rw-r--r--xbmc/guilib/guiinfo/SystemGUIInfo.cpp51
-rw-r--r--xbmc/guilib/guiinfo/SystemGUIInfo.h6
-rw-r--r--xbmc/platform/android/CMakeLists.txt2
-rw-r--r--xbmc/platform/android/GPUInfoAndroid.cpp24
-rw-r--r--xbmc/platform/android/GPUInfoAndroid.h22
-rw-r--r--xbmc/platform/darwin/ios-common/CMakeLists.txt2
-rw-r--r--xbmc/platform/darwin/ios-common/GPUInfoDarwinEmbed.cpp24
-rw-r--r--xbmc/platform/darwin/ios-common/GPUInfoDarwinEmbed.h22
-rw-r--r--xbmc/platform/darwin/osx/CMakeLists.txt2
-rw-r--r--xbmc/platform/darwin/osx/GPUInfoMacOS.cpp32
-rw-r--r--xbmc/platform/darwin/osx/GPUInfoMacOS.h22
-rw-r--r--xbmc/platform/freebsd/CMakeLists.txt2
-rw-r--r--xbmc/platform/freebsd/GPUInfoFreebsd.cpp24
-rw-r--r--xbmc/platform/freebsd/GPUInfoFreebsd.h22
-rw-r--r--xbmc/platform/linux/CMakeLists.txt2
-rw-r--r--xbmc/platform/linux/GPUInfoLinux.cpp24
-rw-r--r--xbmc/platform/linux/GPUInfoLinux.h22
-rw-r--r--xbmc/platform/posix/CMakeLists.txt2
-rw-r--r--xbmc/platform/posix/GPUInfoPosix.cpp52
-rw-r--r--xbmc/platform/posix/GPUInfoPosix.h22
-rw-r--r--xbmc/platform/win10/CMakeLists.txt2
-rw-r--r--xbmc/platform/win10/GPUInfoWin10.cpp35
-rw-r--r--xbmc/platform/win10/GPUInfoWin10.h25
-rw-r--r--xbmc/platform/win32/CMakeLists.txt2
-rw-r--r--xbmc/platform/win32/GPUInfoWin32.cpp35
-rw-r--r--xbmc/platform/win32/GPUInfoWin32.h25
-rw-r--r--xbmc/utils/CMakeLists.txt2
-rw-r--r--xbmc/utils/GpuInfo.cpp35
-rw-r--r--xbmc/utils/GpuInfo.h66
-rw-r--r--xbmc/utils/test/CMakeLists.txt1
-rw-r--r--xbmc/utils/test/TestGPUInfo.cpp37
31 files changed, 600 insertions, 46 deletions
diff --git a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
index 408522ea3e..d6a428fab6 100644
--- a/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
+++ b/xbmc/guilib/guiinfo/SystemGUIInfo.cpp
@@ -20,10 +20,6 @@
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
-#include "network/Network.h"
-#if defined(TARGET_DARWIN_OSX)
-#include "platform/darwin/osx/smc.h"
-#endif
#include "guilib/guiinfo/GUIInfo.h"
#include "guilib/guiinfo/GUIInfoHelper.h"
#include "guilib/guiinfo/GUIInfoLabels.h"
@@ -38,6 +34,7 @@
#include "storage/discs/IDiscDriveHandler.h"
#include "utils/AlarmClock.h"
#include "utils/CPUInfo.h"
+#include "utils/GpuInfo.h"
#include "utils/HDRCapabilities.h"
#include "utils/MemUtils.h"
#include "utils/StringUtils.h"
@@ -50,7 +47,7 @@ using namespace KODI::GUILIB;
using namespace KODI::GUILIB::GUIINFO;
CSystemGUIInfo::CSystemGUIInfo()
-: m_lastSysHeatInfoTime(-SYSTEM_HEAT_UPDATE_INTERVAL)
+ : m_gpuInfo(CGPUInfo::GetGPUInfo()), m_lastSysHeatInfoTime(-SYSTEM_HEAT_UPDATE_INTERVAL)
{
}
@@ -59,10 +56,11 @@ std::string CSystemGUIInfo::GetSystemHeatInfo(int info) const
if (CTimeUtils::GetFrameTime() - m_lastSysHeatInfoTime >= SYSTEM_HEAT_UPDATE_INTERVAL)
{
m_lastSysHeatInfoTime = CTimeUtils::GetFrameTime();
-#if defined(TARGET_POSIX)
CServiceBroker::GetCPUInfo()->GetTemperature(m_cpuTemp);
- m_gpuTemp = GetGPUTemperature();
-#endif
+ if (m_gpuInfo)
+ {
+ m_gpuInfo->GetTemperature(m_gpuTemp);
+ }
}
std::string text;
@@ -89,43 +87,6 @@ std::string CSystemGUIInfo::GetSystemHeatInfo(int info) const
return text;
}
-CTemperature CSystemGUIInfo::GetGPUTemperature() const
-{
- int value = 0;
- char scale = 0;
-
-#if defined(TARGET_DARWIN_OSX)
- value = SMCGetTemperature(SMC_KEY_GPU_TEMP);
- auto temperature = CTemperature::CreateFromCelsius(value);
- if (temperature == CTemperature::CreateFromCelsius(0.0))
- {
- temperature.SetValid(false);
- }
- return temperature;
-#elif defined(TARGET_WINDOWS_STORE)
- return CTemperature::CreateFromCelsius(0);
-#else
- std::string cmd = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_gpuTempCmd;
- int ret = 0;
- FILE* p = NULL;
-
- if (cmd.empty() || !(p = popen(cmd.c_str(), "r")))
- return CTemperature();
-
- ret = fscanf(p, "%d %c", &value, &scale);
- pclose(p);
-
- if (ret != 2)
- return CTemperature();
-#endif
-
- if (scale == 'C' || scale == 'c')
- return CTemperature::CreateFromCelsius(value);
- if (scale == 'F' || scale == 'f')
- return CTemperature::CreateFromFahrenheit(value);
- return CTemperature();
-}
-
void CSystemGUIInfo::UpdateFPS()
{
m_frameCounter++;
diff --git a/xbmc/guilib/guiinfo/SystemGUIInfo.h b/xbmc/guilib/guiinfo/SystemGUIInfo.h
index ed2ea03b2e..43c4f281c4 100644
--- a/xbmc/guilib/guiinfo/SystemGUIInfo.h
+++ b/xbmc/guilib/guiinfo/SystemGUIInfo.h
@@ -9,8 +9,11 @@
#pragma once
#include "guilib/guiinfo/GUIInfoProvider.h"
+#include "utils/GpuInfo.h"
#include "utils/Temperature.h"
+#include <memory>
+
namespace KODI
{
namespace GUILIB
@@ -37,7 +40,8 @@ public:
private:
std::string GetSystemHeatInfo(int info) const;
- CTemperature GetGPUTemperature() const;
+
+ std::unique_ptr<CGPUInfo> m_gpuInfo;
static const int SYSTEM_HEAT_UPDATE_INTERVAL = 60000;
diff --git a/xbmc/platform/android/CMakeLists.txt b/xbmc/platform/android/CMakeLists.txt
index 200729cb9a..d4d65d5ad2 100644
--- a/xbmc/platform/android/CMakeLists.txt
+++ b/xbmc/platform/android/CMakeLists.txt
@@ -1,8 +1,10 @@
set(SOURCES CPUInfoAndroid.cpp
+ GPUInfoAndroid.cpp
MemUtils.cpp
PlatformAndroid.cpp)
set(HEADERS CPUInfoAndroid.h
+ GPUInfoAndroid.h
PlatformAndroid.h)
core_add_library(androidsupport)
diff --git a/xbmc/platform/android/GPUInfoAndroid.cpp b/xbmc/platform/android/GPUInfoAndroid.cpp
new file mode 100644
index 0000000000..9fa41906f8
--- /dev/null
+++ b/xbmc/platform/android/GPUInfoAndroid.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GPUInfoAndroid.h"
+
+std::unique_ptr<CGPUInfo> CGPUInfo::GetGPUInfo()
+{
+ return std::make_unique<CGPUInfoAndroid>();
+}
+
+bool CGPUInfoAndroid::SupportsPlatformTemperature() const
+{
+ return false;
+}
+
+bool CGPUInfoAndroid::GetGPUPlatformTemperature(CTemperature& temperature) const
+{
+ return false;
+}
diff --git a/xbmc/platform/android/GPUInfoAndroid.h b/xbmc/platform/android/GPUInfoAndroid.h
new file mode 100644
index 0000000000..0dbd46890c
--- /dev/null
+++ b/xbmc/platform/android/GPUInfoAndroid.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "platform/posix/GPUInfoPosix.h"
+
+class CGPUInfoAndroid : public CGPUInfoPosix
+{
+public:
+ CGPUInfoAndroid() = default;
+ ~CGPUInfoAndroid() = default;
+
+private:
+ bool SupportsPlatformTemperature() const override;
+ bool GetGPUPlatformTemperature(CTemperature& temperature) const override;
+};
diff --git a/xbmc/platform/darwin/ios-common/CMakeLists.txt b/xbmc/platform/darwin/ios-common/CMakeLists.txt
index 9a95136da4..44476d24f7 100644
--- a/xbmc/platform/darwin/ios-common/CMakeLists.txt
+++ b/xbmc/platform/darwin/ios-common/CMakeLists.txt
@@ -4,6 +4,7 @@ set(SOURCES AnnounceReceiver.mm
DarwinEmbedKeyboardView.mm
DarwinEmbedNowPlayingInfoManager.mm
DarwinEmbedUtils.mm
+ GPUInfoDarwinEmbed.cpp
NSData+GZIP.m
PlatformDarwinEmbedded.cpp)
@@ -13,6 +14,7 @@ set(HEADERS AnnounceReceiver.h
DarwinEmbedKeyboardView.h
DarwinEmbedNowPlayingInfoManager.h
DarwinEmbedUtils.h
+ GPUInfoDarwinEmbed.h
NSData+GZIP.h
PlatformDarwinEmbedded.h)
diff --git a/xbmc/platform/darwin/ios-common/GPUInfoDarwinEmbed.cpp b/xbmc/platform/darwin/ios-common/GPUInfoDarwinEmbed.cpp
new file mode 100644
index 0000000000..a9e3b3ac07
--- /dev/null
+++ b/xbmc/platform/darwin/ios-common/GPUInfoDarwinEmbed.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GPUInfoDarwinEmbed.h"
+
+std::unique_ptr<CGPUInfo> CGPUInfo::GetGPUInfo()
+{
+ return std::make_unique<CGPUInfoDarwinEmbed>();
+}
+
+bool CGPUInfoDarwinEmbed::SupportsPlatformTemperature() const
+{
+ return false;
+}
+
+bool CGPUInfoDarwinEmbed::GetGPUPlatformTemperature(CTemperature& temperature) const
+{
+ return false;
+}
diff --git a/xbmc/platform/darwin/ios-common/GPUInfoDarwinEmbed.h b/xbmc/platform/darwin/ios-common/GPUInfoDarwinEmbed.h
new file mode 100644
index 0000000000..7225e2ff5e
--- /dev/null
+++ b/xbmc/platform/darwin/ios-common/GPUInfoDarwinEmbed.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "platform/posix/GPUInfoPosix.h"
+
+class CGPUInfoDarwinEmbed : public CGPUInfoPosix
+{
+public:
+ CGPUInfoDarwinEmbed() = default;
+ ~CGPUInfoDarwinEmbed() = default;
+
+private:
+ bool SupportsPlatformTemperature() const override;
+ bool GetGPUPlatformTemperature(CTemperature& temperature) const override;
+};
diff --git a/xbmc/platform/darwin/osx/CMakeLists.txt b/xbmc/platform/darwin/osx/CMakeLists.txt
index 4e3a41de98..01db68f8e8 100644
--- a/xbmc/platform/darwin/osx/CMakeLists.txt
+++ b/xbmc/platform/darwin/osx/CMakeLists.txt
@@ -1,11 +1,13 @@
set(SOURCES CocoaInterface.mm
CPUInfoOsx.cpp
+ GPUInfoMacOS.cpp
HotKeyController.m
PlatformDarwinOSX.cpp
smc.c)
set(HEADERS CocoaInterface.h
CPUInfoOsx.h
+ GPUInfoMacOS.h
HotKeyController.h
PlatformDarwinOSX.h
smc.h)
diff --git a/xbmc/platform/darwin/osx/GPUInfoMacOS.cpp b/xbmc/platform/darwin/osx/GPUInfoMacOS.cpp
new file mode 100644
index 0000000000..5594d9bbf2
--- /dev/null
+++ b/xbmc/platform/darwin/osx/GPUInfoMacOS.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GPUInfoMacOS.h"
+
+#include "platform/darwin/osx/smc.h"
+
+std::unique_ptr<CGPUInfo> CGPUInfo::GetGPUInfo()
+{
+ return std::make_unique<CGPUInfoMacOS>();
+}
+
+bool CGPUInfoMacOS::SupportsPlatformTemperature() const
+{
+ return true;
+}
+
+bool CGPUInfoMacOS::GetGPUPlatformTemperature(CTemperature& temperature) const
+{
+ double temperatureValue = SMCGetTemperature(SMC_KEY_GPU_TEMP);
+ if (temperatureValue <= 0.0)
+ {
+ return false;
+ }
+ temperature = CTemperature::CreateFromCelsius(temperatureValue);
+ return true;
+}
diff --git a/xbmc/platform/darwin/osx/GPUInfoMacOS.h b/xbmc/platform/darwin/osx/GPUInfoMacOS.h
new file mode 100644
index 0000000000..8ceb02d578
--- /dev/null
+++ b/xbmc/platform/darwin/osx/GPUInfoMacOS.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "platform/posix/GPUInfoPosix.h"
+
+class CGPUInfoMacOS : public CGPUInfoPosix
+{
+public:
+ CGPUInfoMacOS() = default;
+ ~CGPUInfoMacOS() = default;
+
+private:
+ bool SupportsPlatformTemperature() const override;
+ bool GetGPUPlatformTemperature(CTemperature& temperature) const override;
+};
diff --git a/xbmc/platform/freebsd/CMakeLists.txt b/xbmc/platform/freebsd/CMakeLists.txt
index 3506c2ee70..b8818cefc3 100644
--- a/xbmc/platform/freebsd/CMakeLists.txt
+++ b/xbmc/platform/freebsd/CMakeLists.txt
@@ -1,5 +1,6 @@
set(SOURCES ../linux/AppParamParserLinux.cpp
CPUInfoFreebsd.cpp
+ GPUInfoFreebsd.cpp
OptionalsReg.cpp
../linux/OptionalsReg.cpp
../linux/TimeUtils.cpp
@@ -8,6 +9,7 @@ set(SOURCES ../linux/AppParamParserLinux.cpp
set(HEADERS ../linux/AppParamParserLinux.cpp
CPUInfoFreebsd.h
+ GPUInfoFreebsd.h
OptionalsReg.h
../linux/OptionalsReg.h
../linux/TimeUtils.h
diff --git a/xbmc/platform/freebsd/GPUInfoFreebsd.cpp b/xbmc/platform/freebsd/GPUInfoFreebsd.cpp
new file mode 100644
index 0000000000..030b652d23
--- /dev/null
+++ b/xbmc/platform/freebsd/GPUInfoFreebsd.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GPUInfoFreebsd.h"
+
+std::unique_ptr<CGPUInfo> CGPUInfo::GetGPUInfo()
+{
+ return std::make_unique<CGPUInfoFreebsd>();
+}
+
+bool CGPUInfoFreebsd::SupportsPlatformTemperature() const
+{
+ return false;
+}
+
+bool CGPUInfoFreebsd::GetGPUPlatformTemperature(CTemperature& temperature) const
+{
+ return false;
+}
diff --git a/xbmc/platform/freebsd/GPUInfoFreebsd.h b/xbmc/platform/freebsd/GPUInfoFreebsd.h
new file mode 100644
index 0000000000..62016ecc40
--- /dev/null
+++ b/xbmc/platform/freebsd/GPUInfoFreebsd.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "platform/posix/GPUInfoPosix.h"
+
+class CGPUInfoFreebsd : public CGPUInfoPosix
+{
+public:
+ CGPUInfoFreebsd() = default;
+ ~CGPUInfoFreebsd() = default;
+
+private:
+ bool SupportsPlatformTemperature() const override;
+ bool GetGPUPlatformTemperature(CTemperature& temperature) const override;
+};
diff --git a/xbmc/platform/linux/CMakeLists.txt b/xbmc/platform/linux/CMakeLists.txt
index 0c8bccf8c0..08a696498e 100644
--- a/xbmc/platform/linux/CMakeLists.txt
+++ b/xbmc/platform/linux/CMakeLists.txt
@@ -1,5 +1,6 @@
set(SOURCES AppParamParserLinux.cpp
CPUInfoLinux.cpp
+ GPUInfoLinux.cpp
MemUtils.cpp
OptionalsReg.cpp
PlatformLinux.cpp
@@ -8,6 +9,7 @@ set(SOURCES AppParamParserLinux.cpp
set(HEADERS AppParamParserLinux.h
CPUInfoLinux.h
+ GPUInfoLinux.h
OptionalsReg.h
PlatformLinux.h
SysfsPath.h
diff --git a/xbmc/platform/linux/GPUInfoLinux.cpp b/xbmc/platform/linux/GPUInfoLinux.cpp
new file mode 100644
index 0000000000..dd8585a204
--- /dev/null
+++ b/xbmc/platform/linux/GPUInfoLinux.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GPUInfoLinux.h"
+
+std::unique_ptr<CGPUInfo> CGPUInfo::GetGPUInfo()
+{
+ return std::make_unique<CGPUInfoLinux>();
+}
+
+bool CGPUInfoLinux::SupportsPlatformTemperature() const
+{
+ return false;
+}
+
+bool CGPUInfoLinux::GetGPUPlatformTemperature(CTemperature& temperature) const
+{
+ return false;
+}
diff --git a/xbmc/platform/linux/GPUInfoLinux.h b/xbmc/platform/linux/GPUInfoLinux.h
new file mode 100644
index 0000000000..152068fa0f
--- /dev/null
+++ b/xbmc/platform/linux/GPUInfoLinux.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "platform/posix/GPUInfoPosix.h"
+
+class CGPUInfoLinux : public CGPUInfoPosix
+{
+public:
+ CGPUInfoLinux() = default;
+ ~CGPUInfoLinux() = default;
+
+private:
+ bool SupportsPlatformTemperature() const override;
+ bool GetGPUPlatformTemperature(CTemperature& temperature) const override;
+};
diff --git a/xbmc/platform/posix/CMakeLists.txt b/xbmc/platform/posix/CMakeLists.txt
index 2d8d4dbd63..7907159cf9 100644
--- a/xbmc/platform/posix/CMakeLists.txt
+++ b/xbmc/platform/posix/CMakeLists.txt
@@ -1,6 +1,7 @@
set(SOURCES ConvUtils.cpp
CPUInfoPosix.cpp
Filesystem.cpp
+ GPUInfoPosix.cpp
MessagePrinter.cpp
PlatformPosix.cpp
PosixMountProvider.cpp
@@ -11,6 +12,7 @@ set(SOURCES ConvUtils.cpp
set(HEADERS ConvUtils.h
CPUInfoPosix.h
+ GPUInfoPosix.h
PlatformDefs.h
PlatformPosix.h
PosixMountProvider.h
diff --git a/xbmc/platform/posix/GPUInfoPosix.cpp b/xbmc/platform/posix/GPUInfoPosix.cpp
new file mode 100644
index 0000000000..1f4a957041
--- /dev/null
+++ b/xbmc/platform/posix/GPUInfoPosix.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GPUInfoPosix.h"
+
+#include <stdio.h>
+
+bool CGPUInfoPosix::SupportsCustomTemperatureCommand() const
+{
+ return true;
+}
+
+bool CGPUInfoPosix::GetGPUTemperatureFromCommand(CTemperature& temperature,
+ const std::string& cmd) const
+{
+ int value = 0;
+ char scale = 0;
+ int ret = 0;
+ FILE* p = nullptr;
+
+ if (cmd.empty() || !(p = popen(cmd.c_str(), "r")))
+ {
+ return false;
+ }
+
+ ret = fscanf(p, "%d %c", &value, &scale);
+ pclose(p);
+
+ if (ret != 2)
+ {
+ return false;
+ }
+
+ if (scale == 'C' || scale == 'c')
+ {
+ temperature = CTemperature::CreateFromCelsius(value);
+ }
+ else if (scale == 'F' || scale == 'f')
+ {
+ temperature = CTemperature::CreateFromFahrenheit(value);
+ }
+ else
+ {
+ return false;
+ }
+ return true;
+}
diff --git a/xbmc/platform/posix/GPUInfoPosix.h b/xbmc/platform/posix/GPUInfoPosix.h
new file mode 100644
index 0000000000..b03914e73f
--- /dev/null
+++ b/xbmc/platform/posix/GPUInfoPosix.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "utils/GpuInfo.h"
+
+class CGPUInfoPosix : public CGPUInfo
+{
+protected:
+ CGPUInfoPosix() = default;
+ virtual ~CGPUInfoPosix() = default;
+
+ virtual bool SupportsCustomTemperatureCommand() const override;
+ virtual bool GetGPUTemperatureFromCommand(CTemperature& temperature,
+ const std::string& cmd) const override;
+};
diff --git a/xbmc/platform/win10/CMakeLists.txt b/xbmc/platform/win10/CMakeLists.txt
index 6ddf3c8df7..19bc19f0e5 100644
--- a/xbmc/platform/win10/CMakeLists.txt
+++ b/xbmc/platform/win10/CMakeLists.txt
@@ -1,6 +1,7 @@
set(SOURCES CPUInfoWin10.cpp
input/RemoteControlXbox.cpp
Environment.cpp
+ GPUInfoWin10.cpp
Win10App.cpp
MessagePrinter.cpp
PlatformWin10.cpp
@@ -14,6 +15,7 @@ set(SOURCES CPUInfoWin10.cpp
set(HEADERS AsyncHelpers.h
CPUInfoWin10.h
+ GPUInfoWin10.h
input/RemoteControlXbox.h
Win10App.h
PlatformWin10.h
diff --git a/xbmc/platform/win10/GPUInfoWin10.cpp b/xbmc/platform/win10/GPUInfoWin10.cpp
new file mode 100644
index 0000000000..8c6fb1a661
--- /dev/null
+++ b/xbmc/platform/win10/GPUInfoWin10.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GPUInfoWin10.h"
+
+std::unique_ptr<CGPUInfo> CGPUInfo::GetGPUInfo()
+{
+ return std::make_unique<CGPUInfoWin10>();
+}
+
+bool CGPUInfoWin10::SupportsCustomTemperatureCommand() const
+{
+ return false;
+}
+
+bool CGPUInfoWin10::SupportsPlatformTemperature() const
+{
+ return false;
+}
+
+bool CGPUInfoWin10::GetGPUPlatformTemperature(CTemperature& temperature) const
+{
+ return false;
+}
+
+bool CGPUInfoWin10::GetGPUTemperatureFromCommand(CTemperature& temperature,
+ const std::string& cmd) const
+{
+ return false;
+}
diff --git a/xbmc/platform/win10/GPUInfoWin10.h b/xbmc/platform/win10/GPUInfoWin10.h
new file mode 100644
index 0000000000..6e7d0329af
--- /dev/null
+++ b/xbmc/platform/win10/GPUInfoWin10.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "utils/GpuInfo.h"
+
+class CGPUInfoWin10 : public CGPUInfo
+{
+public:
+ CGPUInfoWin10() = default;
+ ~CGPUInfoWin10() = default;
+
+private:
+ bool SupportsCustomTemperatureCommand() const override;
+ bool SupportsPlatformTemperature() const override;
+ bool GetGPUPlatformTemperature(CTemperature& temperature) const override;
+ bool GetGPUTemperatureFromCommand(CTemperature& temperature,
+ const std::string& cmd) const override;
+};
diff --git a/xbmc/platform/win32/CMakeLists.txt b/xbmc/platform/win32/CMakeLists.txt
index 57afab0e41..28faedb9c0 100644
--- a/xbmc/platform/win32/CMakeLists.txt
+++ b/xbmc/platform/win32/CMakeLists.txt
@@ -1,6 +1,7 @@
set(SOURCES CharsetConverter.cpp
CPUInfoWin32.cpp
Environment.cpp
+ GPUInfoWin32.cpp
MemUtils.cpp
MessagePrinter.cpp
dxerr.cpp
@@ -15,6 +16,7 @@ set(HEADERS CharsetConverter.h
CPUInfoWin32.h
dirent.h
dxerr.h
+ GPUInfoWin32.h
IMMNotificationClient.h
my_ntddcdrm.h
my_ntddscsi.h
diff --git a/xbmc/platform/win32/GPUInfoWin32.cpp b/xbmc/platform/win32/GPUInfoWin32.cpp
new file mode 100644
index 0000000000..bdf0b0f17f
--- /dev/null
+++ b/xbmc/platform/win32/GPUInfoWin32.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GPUInfoWin32.h"
+
+std::unique_ptr<CGPUInfo> CGPUInfo::GetGPUInfo()
+{
+ return std::make_unique<CGPUInfoWin32>();
+}
+
+bool CGPUInfoWin32::SupportsCustomTemperatureCommand() const
+{
+ return false;
+}
+
+bool CGPUInfoWin32::SupportsPlatformTemperature() const
+{
+ return false;
+}
+
+bool CGPUInfoWin32::GetGPUPlatformTemperature(CTemperature& temperature) const
+{
+ return false;
+}
+
+bool CGPUInfoWin32::GetGPUTemperatureFromCommand(CTemperature& temperature,
+ const std::string& cmd) const
+{
+ return false;
+}
diff --git a/xbmc/platform/win32/GPUInfoWin32.h b/xbmc/platform/win32/GPUInfoWin32.h
new file mode 100644
index 0000000000..e23bccb84f
--- /dev/null
+++ b/xbmc/platform/win32/GPUInfoWin32.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "utils/GpuInfo.h"
+
+class CGPUInfoWin32 : public CGPUInfo
+{
+public:
+ CGPUInfoWin32() = default;
+ ~CGPUInfoWin32() = default;
+
+private:
+ bool GetGPUPlatformTemperature(CTemperature& temperature) const override;
+ bool GetGPUTemperatureFromCommand(CTemperature& temperature,
+ const std::string& cmd) const override;
+ bool SupportsCustomTemperatureCommand() const override;
+ bool SupportsPlatformTemperature() const override;
+};
diff --git a/xbmc/utils/CMakeLists.txt b/xbmc/utils/CMakeLists.txt
index c7c053b821..fd9f4ab44f 100644
--- a/xbmc/utils/CMakeLists.txt
+++ b/xbmc/utils/CMakeLists.txt
@@ -27,6 +27,7 @@ set(SOURCES ActorProtocol.cpp
FileOperationJob.cpp
FileUtils.cpp
FontUtils.cpp
+ GpuInfo.cpp
GroupUtils.cpp
HTMLUtil.cpp
HttpHeader.cpp
@@ -111,6 +112,7 @@ set(HEADERS ActorProtocol.h
FontUtils.h
Geometry.h
GlobalsHandling.h
+ GpuInfo.h
GroupUtils.h
HDRCapabilities.h
HTMLUtil.h
diff --git a/xbmc/utils/GpuInfo.cpp b/xbmc/utils/GpuInfo.cpp
new file mode 100644
index 0000000000..9d1db907ba
--- /dev/null
+++ b/xbmc/utils/GpuInfo.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GpuInfo.h"
+
+#include "ServiceBroker.h"
+#include "settings/AdvancedSettings.h"
+#include "settings/SettingsComponent.h"
+
+bool CGPUInfo::GetTemperature(CTemperature& temperature) const
+{
+ // user custom cmd takes precedence over platform implementation
+ if (SupportsCustomTemperatureCommand())
+ {
+ auto cmd = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_gpuTempCmd;
+ if (!cmd.empty() && GetGPUTemperatureFromCommand(temperature, cmd))
+ {
+ return true;
+ }
+ }
+
+ if (SupportsPlatformTemperature() && GetGPUPlatformTemperature(temperature))
+ {
+ return true;
+ }
+
+ temperature = CTemperature();
+ temperature.SetValid(false);
+ return false;
+}
diff --git a/xbmc/utils/GpuInfo.h b/xbmc/utils/GpuInfo.h
new file mode 100644
index 0000000000..26a71a8d28
--- /dev/null
+++ b/xbmc/utils/GpuInfo.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "utils/Temperature.h"
+
+#include <memory>
+#include <string>
+
+/*! \brief Class to concentrate all methods related to GPU information
+* \details This is used by the Info interface to obtain the current GPU temperature
+*/
+class CGPUInfo
+{
+public:
+ CGPUInfo() = default;
+ virtual ~CGPUInfo() = default;
+
+ /*! \brief Getter from the specific platform GPUInfo
+ \return the platform specific implementation of GPUInfo
+ */
+ static std::unique_ptr<CGPUInfo> GetGPUInfo();
+
+ /*! \brief Get the temperature of the GPU
+ \param[in,out] temperature - the temperature to fill with the result
+ \return true if it was possible to obtain the GPU temperature, false otherwise
+ */
+ bool GetTemperature(CTemperature& temperature) const;
+
+protected:
+ /*! \brief Checks if the specific platform implementation supports obtaining the GPU temperature
+ via the execution of a custom command line command
+ \note this is false on the base class but may be overridden by the specific platform implementation.
+ Custom GPU command is defined in advancedsettings.
+ \return true if the implementation supports obtaining the GPU temperature from a custom command, false otherwise
+ */
+ virtual bool SupportsCustomTemperatureCommand() const { return false; }
+
+ /*! \brief Checks if the specific platform implementation supports obtaining the GPU temperature
+ from the platform SDK itself
+ \note this is false on the base class but may be overridden by the specific platform implementation.
+ \return true if the implementation supports obtaining the GPU temperature from the platform SDK, false otherwise
+ */
+ virtual bool SupportsPlatformTemperature() const { return false; }
+
+ /*! \brief Get the GPU temperature from the platform SDK
+ \note platform implementations must override this. For this to take effect SupportsPlatformTemperature must be true.
+ \param[in,out] temperature - the temperature to fill with the result
+ \return true if obtaining the GPU temperature succeeded, false otherwise
+ */
+ virtual bool GetGPUPlatformTemperature(CTemperature& temperature) const = 0;
+
+ /*! \brief Get the GPU temperature from a user provided command (advanced settings)
+ \note platform implementations must override this. For this to take effect SupportsCustomTemperatureCommand must be true.
+ \param[in,out] temperature - the temperature to fill with the result
+ \return true if obtaining the GPU temperature succeeded, false otherwise
+ */
+ virtual bool GetGPUTemperatureFromCommand(CTemperature& temperature,
+ const std::string& cmd) const = 0;
+};
diff --git a/xbmc/utils/test/CMakeLists.txt b/xbmc/utils/test/CMakeLists.txt
index 5cff468669..0ce2a6fafe 100644
--- a/xbmc/utils/test/CMakeLists.txt
+++ b/xbmc/utils/test/CMakeLists.txt
@@ -14,6 +14,7 @@ set(SOURCES TestAlarmClock.cpp
TestFileOperationJob.cpp
TestFileUtils.cpp
TestGlobalsHandling.cpp
+ TestGPUInfo.cpp
TestHTMLUtil.cpp
TestHttpHeader.cpp
TestHttpParser.cpp
diff --git a/xbmc/utils/test/TestGPUInfo.cpp b/xbmc/utils/test/TestGPUInfo.cpp
new file mode 100644
index 0000000000..ce3d4a6d79
--- /dev/null
+++ b/xbmc/utils/test/TestGPUInfo.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2023 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "ServiceBroker.h"
+#include "settings/AdvancedSettings.h"
+#include "settings/SettingsComponent.h"
+#include "utils/GpuInfo.h"
+
+#include <memory>
+
+#include <gtest/gtest.h>
+
+class TestGPUInfo : public ::testing::Test
+{
+protected:
+ TestGPUInfo() = default;
+};
+
+#if defined(TARGET_WINDOWS)
+TEST_F(TestGPUInfo, DISABLED_GetTemperatureFromCmd)
+#else
+TEST_F(TestGPUInfo, GetTemperature)
+#endif
+{
+ CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_gpuTempCmd = "echo '50 c'";
+ std::unique_ptr<CGPUInfo> gpuInfo = CGPUInfo::GetGPUInfo();
+ EXPECT_NE(gpuInfo, nullptr);
+ CTemperature t;
+ bool success = gpuInfo->GetTemperature(t);
+ EXPECT_TRUE(t.IsValid());
+ EXPECT_EQ(t.ToCelsius(), 50);
+}