Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
PlatformDefinesApple.cpp
Go to the documentation of this file.
1
2
3#if defined(__APPLE_CC__)
4
6
7#include <SDL_syswm.h>
8#include <signal.h>
9
10namespace Divide {
11
12 bool DebugBreak(const bool condition) noexcept {
13 if (!condition) {
14 return false;
15 }
16#if defined(SIGTRAP)
17 raise(SIGTRAP);
18#else
19 raise(SIGABRT);
20#endif
21
22 return true;
23 }
24
25 void EnforceDPIScaling() noexcept
26 {
27 NOP();
28 }
29
30 bool GetAvailableMemory(SysInfo& info) {
31 I32 mib[2] = { CTL_HW, HW_MEMSIZE };
32 U32 namelen = sizeof(mib) / sizeof(mib[0]);
33 U64 size;
34 size_t len = sizeof(size);
35 if (sysctl(mib, namelen, &size, &len, NULL, 0) < 0) {
36 perror("sysctl");
37 } else {
38 info._availableRamInBytes = to_size(size);
39 }
40
41 return true;
42 }
43
44 F32 PlatformDefaultDPI() noexcept {
45 return 72.f;
46 }
47
48 void GetWindowHandle(void* window, WindowHandle& handleOut) noexcept {
49 SDL_SysWMinfo wmInfo;
50 SDL_VERSION(&wmInfo.version);
51 SDL_GetWindowWMInfo(static_cast<SDL_Window*>(window), &wmInfo);
52
53 handleOut._handle = wmInfo.info.cocoa.window;
54 }
55
56 void SetThreadPriorityInternal(pthread_t thread, const ThreadPriority priority) {
57 if (priority == ThreadPriority::COUNT) {
58 return;
59 }
60 sched_param sch_params;
61 int policy;
62 pthread_getschedparam(thread, &policy, &sch_params);
63
64 switch (priority) {
66 sch_params.sched_priority = 10;
67 } break;
69 sch_params.sched_priority = 25;
70 } break;
72 sch_params.sched_priority = 50;
73 } break;
75 sch_params.sched_priority = 75;
76 } break;
78 sch_params.sched_priority = 85;
79 } break;
81 sch_params.sched_priority = 99;
82 } break;
83 }
84
85 if (!pthread_setschedparam(thread, SCHED_FIFO, &sch_params)) {
87 }
88 }
89
90 void SetThreadPriority(const ThreadPriority priority) {
91 SetThreadPriorityInternal(pthread_self(), priority);
92 }
93
94 #include <sys/prctl.h>
95 void SetThreadName(const std::string_view threadName) noexcept {
96 pthread_setname_np(pthread_self(), threadName.data());
97 }
98
99 bool CallSystemCmd(const char* cmd, const std::string_view args) {
100 return std::system(Util::StringFormat("{} {}", cmd, args).c_str()) == 0;
101 }
102}; //namespace Divide
103
104#endif //defined(__APPLE_CC__)
SDL_Window SDL_Window
Definition: DisplayWindow.h:42
#define DIVIDE_UNEXPECTED_CALL()
#define NOP()
Str StringFormat(const char *fmt, Args &&...args)
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
void GetWindowHandle(void *window, WindowHandle &handleOut) noexcept
F32 PlatformDefaultDPI() noexcept
void SetThreadName(std::string_view threadName) noexcept
int32_t I32
bool CallSystemCmd(std::string_view cmd, std::string_view args)
void SetThreadPriorityInternal(pthread_t thread, const ThreadPriority priority)
bool DebugBreak(const bool condition) noexcept
void SetThreadPriority(ThreadPriority priority)
void EnforceDPIScaling() noexcept
constexpr size_t to_size(const T value)
bool GetAvailableMemory(SysInfo &info)
uint32_t U32
uint64_t U64