[gimp/samm/macos-dashboard/gimp-2-10] Add macOS support for the GIMP dashboard
- From: Alex Samorukov <asamorukov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/samm/macos-dashboard/gimp-2-10] Add macOS support for the GIMP dashboard
- Date: Sun, 12 Jan 2020 07:23:24 +0000 (UTC)
commit 215fd5195e0f5399e62ce5462b9dd9f537218dbe
Author: Alex Samorukov <samm os2 kiev ua>
Date: Sun Jan 12 08:22:42 2020 +0100
Add macOS support for the GIMP dashboard
app/widgets/gimpdashboard.c | 147 +++++++++++++++++++++++++++++---------------
1 file changed, 99 insertions(+), 48 deletions(-)
---
diff --git a/app/widgets/gimpdashboard.c b/app/widgets/gimpdashboard.c
index 5afaa5426f..524cbd8185 100644
--- a/app/widgets/gimpdashboard.c
+++ b/app/widgets/gimpdashboard.c
@@ -33,7 +33,12 @@
#include <psapi.h>
#define HAVE_CPU_GROUP
#define HAVE_MEMORY_GROUP
-#else /* ! G_OS_WIN32 */
+#elif defined(PLATFORM_OSX)
+#include <mach/mach.h>
+#include <sys/times.h>
+#define HAVE_CPU_GROUP
+#define HAVE_MEMORY_GROUP
+#else /* ! G_OS_WIN32 && ! PLATFORM_OSX */
#ifdef HAVE_SYS_TIMES_H
#include <sys/times.h>
#define HAVE_CPU_GROUP
@@ -2347,9 +2352,100 @@ gimp_dashboard_sample_cpu_active_time (GimpDashboard *dashboard,
#endif /* HAVE_CPU_GROUP */
#ifdef HAVE_MEMORY_GROUP
+#ifdef PLATFORM_OSX
+static void
+gimp_dashboard_sample_memory_used (GimpDashboard *dashboard,
+ Variable variable)
+{
+ GimpDashboardPrivate *priv = dashboard->priv;
+ VariableData *variable_data = &priv->variables[variable];
+
+ variable_data->available = FALSE;
+#ifndef TASK_VM_INFO_REV0_COUNT /* phys_footprint added in REV1 */
+ struct mach_task_basic_info info;
+ mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
+
+ if( task_info(mach_task_self (), MACH_TASK_BASIC_INFO,
+ (task_info_t)&info, &infoCount ) != KERN_SUCCESS )
+ return; /* Can't access? */
+
+ variable_data->available = TRUE;
+ variable_data->value.size = info.resident_size;
+#else
+ task_vm_info_data_t info;
+ mach_msg_type_number_t infoCount = TASK_VM_INFO_COUNT;
+
+ if( task_info(mach_task_self (), TASK_VM_INFO,
+ (task_info_t)&info, &infoCount ) != KERN_SUCCESS )
+ return; /* Can't access? */
+ variable_data->available = TRUE;
+ variable_data->value.size = info.phys_footprint;
+#endif /* ! TASK_VM_INFO_REV0_COUNT */
+}
+
+static void
+gimp_dashboard_sample_memory_available (GimpDashboard *dashboard,
+ Variable variable)
+{
+ GimpDashboardPrivate *priv = dashboard->priv;
+ VariableData *variable_data = &priv->variables[variable];
+ vm_statistics_data_t info;
+ mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
+
+ variable_data->available = FALSE;
+
+
+ if( host_statistics(mach_host_self (), HOST_VM_INFO,
+ (host_info_t)&info, &infoCount ) != KERN_SUCCESS )
+ return; /* Can't access? */
+
+ variable_data->available = TRUE;
+ variable_data->value.size = info.free_count * PAGE_SIZE;
+}
+
+#elif defined(G_OS_WIN32)
+static void
+gimp_dashboard_sample_memory_used (GimpDashboard *dashboard,
+ Variable variable)
+{
+ GimpDashboardPrivate *priv = dashboard->priv;
+ VariableData *variable_data = &priv->variables[variable];
+ PROCESS_MEMORY_COUNTERS_EX pmc = {};
+
+ variable_data->available = FALSE;
+
+ if (! GetProcessMemoryInfo (GetCurrentProcess (),
+ (PPROCESS_MEMORY_COUNTERS) &pmc,
+ sizeof (pmc)) ||
+ pmc.cb != sizeof (pmc))
+ {
+ return;
+ }
+
+ variable_data->available = TRUE;
+ variable_data->value.size = pmc.PrivateUsage;
+}
+
+static void
+gimp_dashboard_sample_memory_available (GimpDashboard *dashboard,
+ Variable variable)
+{
+ GimpDashboardPrivate *priv = dashboard->priv;
+ VariableData *variable_data = &priv->variables[variable];
+ MEMORYSTATUSEX ms;
-#ifndef G_OS_WIN32
+ variable_data->available = FALSE;
+
+ ms.dwLength = sizeof (ms);
+
+ if (! GlobalMemoryStatusEx (&ms))
+ return;
+
+ variable_data->available = TRUE;
+ variable_data->value.size = ms.ullAvailPhys;
+}
+#else /* ! G_OS_WIN32 && ! PLATFORM_OSX */
static void
gimp_dashboard_sample_memory_used (GimpDashboard *dashboard,
Variable variable)
@@ -2484,52 +2580,7 @@ gimp_dashboard_sample_memory_available (GimpDashboard *dashboard,
variable_data->value.size = available;
}
-#else /* G_OS_WIN32 */
-
-
-static void
-gimp_dashboard_sample_memory_used (GimpDashboard *dashboard,
- Variable variable)
-{
- GimpDashboardPrivate *priv = dashboard->priv;
- VariableData *variable_data = &priv->variables[variable];
- PROCESS_MEMORY_COUNTERS_EX pmc = {};
-
- variable_data->available = FALSE;
-
- if (! GetProcessMemoryInfo (GetCurrentProcess (),
- (PPROCESS_MEMORY_COUNTERS) &pmc,
- sizeof (pmc)) ||
- pmc.cb != sizeof (pmc))
- {
- return;
- }
-
- variable_data->available = TRUE;
- variable_data->value.size = pmc.PrivateUsage;
-}
-
-static void
-gimp_dashboard_sample_memory_available (GimpDashboard *dashboard,
- Variable variable)
-{
- GimpDashboardPrivate *priv = dashboard->priv;
- VariableData *variable_data = &priv->variables[variable];
- MEMORYSTATUSEX ms;
-
- variable_data->available = FALSE;
-
- ms.dwLength = sizeof (ms);
-
- if (! GlobalMemoryStatusEx (&ms))
- return;
-
- variable_data->available = TRUE;
- variable_data->value.size = ms.ullAvailPhys;
-}
-
-
-#endif /* G_OS_WIN32 */
+#endif
static void
gimp_dashboard_sample_memory_size (GimpDashboard *dashboard,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]