The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
7.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #include "../../../src/juce_core/basics/juce_StandardHeader.h"
  24. #include <Carbon/Carbon.h>
  25. #include <CoreAudio/HostTime.h>
  26. #include <ctime>
  27. #include <sys/resource.h>
  28. BEGIN_JUCE_NAMESPACE
  29. #include "../../../src/juce_appframework/application/juce_Application.h"
  30. #include "../../../src/juce_core/basics/juce_SystemStats.h"
  31. #include "../../../src/juce_core/basics/juce_Time.h"
  32. #include "../../../src/juce_core/misc/juce_PlatformUtilities.h"
  33. static int64 highResTimerFrequency;
  34. #if JUCE_INTEL
  35. static void juce_getCpuVendor (char* const v) throw()
  36. {
  37. int vendor[4];
  38. zerostruct (vendor);
  39. int dummy = 0;
  40. asm ("mov %%ebx, %%esi \n\t"
  41. "cpuid \n\t"
  42. "xchg %%esi, %%ebx"
  43. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  44. memcpy (v, vendor, 16);
  45. }
  46. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures) throw()
  47. {
  48. unsigned int cpu = 0;
  49. unsigned int ext = 0;
  50. unsigned int family = 0;
  51. unsigned int dummy = 0;
  52. asm ("mov %%ebx, %%esi \n\t"
  53. "cpuid \n\t"
  54. "xchg %%esi, %%ebx"
  55. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  56. familyModel = family;
  57. extFeatures = ext;
  58. return cpu;
  59. }
  60. struct CPUFlags
  61. {
  62. bool hasMMX : 1;
  63. bool hasSSE : 1;
  64. bool hasSSE2 : 1;
  65. bool has3DNow : 1;
  66. bool hasHT : 1;
  67. };
  68. static CPUFlags cpuFlags;
  69. #endif
  70. //==============================================================================
  71. void Logger::outputDebugString (const String& text) throw()
  72. {
  73. String withLineFeed (text + T("\n"));
  74. const char* const utf8 = withLineFeed.toUTF8();
  75. fwrite (utf8, strlen (utf8), 1, stdout);
  76. }
  77. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  78. {
  79. String text;
  80. va_list args;
  81. va_start (args, format);
  82. text.vprintf(format, args);
  83. outputDebugString (text);
  84. }
  85. int SystemStats::getMemorySizeInMegabytes() throw()
  86. {
  87. long bytes;
  88. if (Gestalt (gestaltPhysicalRAMSize, &bytes) == noErr)
  89. return (int) (((unsigned long) bytes) / (1024 * 1024));
  90. return 0;
  91. }
  92. //==============================================================================
  93. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  94. {
  95. return MacOSX;
  96. }
  97. const String SystemStats::getOperatingSystemName() throw()
  98. {
  99. return T("Mac OS X");
  100. }
  101. //==============================================================================
  102. void SystemStats::initialiseStats() throw()
  103. {
  104. static bool initialised = false;
  105. if (! initialised)
  106. {
  107. initialised = true;
  108. #if JUCE_INTEL
  109. {
  110. unsigned int familyModel, extFeatures;
  111. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  112. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  113. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  114. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  115. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  116. cpuFlags.hasHT = ((features & (1 << 28)) != 0);
  117. }
  118. #endif
  119. highResTimerFrequency = (int64) AudioGetHostClockFrequency();
  120. if (JUCEApplication::getInstance() != 0)
  121. RegisterAppearanceClient();
  122. TXNInitTextension (0, 0, kTXNWantMoviesMask | kTXNWantGraphicsMask);
  123. String s (SystemStats::getJUCEVersion());
  124. rlimit lim;
  125. getrlimit (RLIMIT_NOFILE, &lim);
  126. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  127. setrlimit (RLIMIT_NOFILE, &lim);
  128. }
  129. }
  130. bool SystemStats::hasMMX() throw()
  131. {
  132. #if JUCE_INTEL
  133. return cpuFlags.hasMMX;
  134. #else
  135. return false;
  136. #endif
  137. }
  138. bool SystemStats::hasSSE() throw()
  139. {
  140. #if JUCE_INTEL
  141. return cpuFlags.hasSSE;
  142. #else
  143. return false;
  144. #endif
  145. }
  146. bool SystemStats::hasSSE2() throw()
  147. {
  148. #if JUCE_INTEL
  149. return cpuFlags.hasSSE2;
  150. #else
  151. return false;
  152. #endif
  153. }
  154. bool SystemStats::has3DNow() throw()
  155. {
  156. #if JUCE_INTEL
  157. return cpuFlags.has3DNow;
  158. #else
  159. return false;
  160. #endif
  161. }
  162. bool SystemStats::hasHyperThreading() throw()
  163. {
  164. #if JUCE_INTEL
  165. return cpuFlags.hasHT;
  166. #else
  167. return false;
  168. #endif
  169. }
  170. const String SystemStats::getCpuVendor() throw()
  171. {
  172. #if JUCE_INTEL
  173. char v [16];
  174. juce_getCpuVendor (v);
  175. return String (v, 16);
  176. #else
  177. return String::empty;
  178. #endif
  179. }
  180. int SystemStats::getCpuSpeedInMegaherz() throw()
  181. {
  182. return GetCPUSpeed();
  183. }
  184. int SystemStats::getNumPhysicalCpus() throw()
  185. {
  186. return MPProcessors();
  187. }
  188. int SystemStats::getNumLogicalCpus() throw()
  189. {
  190. return getNumPhysicalCpus();
  191. }
  192. uint32 SystemStats::getPhysicalAffinityMask() throw()
  193. {
  194. jassertfalse
  195. return 0;
  196. }
  197. //==============================================================================
  198. static int64 juce_getMicroseconds() throw()
  199. {
  200. UnsignedWide t;
  201. Microseconds (&t);
  202. return (((int64) t.hi) << 32) | t.lo;
  203. }
  204. uint32 juce_millisecondsSinceStartup() throw()
  205. {
  206. return (uint32) (juce_getMicroseconds() / 1000);
  207. }
  208. double Time::getMillisecondCounterHiRes() throw()
  209. {
  210. // xxx might be more accurate to use a scaled AudioGetCurrentHostTime?
  211. return juce_getMicroseconds() * 0.001;
  212. }
  213. int64 Time::getHighResolutionTicks() throw()
  214. {
  215. return (int64) AudioGetCurrentHostTime();
  216. }
  217. int64 Time::getHighResolutionTicksPerSecond() throw()
  218. {
  219. return highResTimerFrequency;
  220. }
  221. int64 SystemStats::getClockCycleCounter() throw()
  222. {
  223. jassertfalse
  224. return 0;
  225. }
  226. bool Time::setSystemTimeToThisTime() const throw()
  227. {
  228. jassertfalse
  229. return false;
  230. }
  231. //==============================================================================
  232. int SystemStats::getPageSize() throw()
  233. {
  234. jassertfalse
  235. return 512; //xxx
  236. }
  237. void PlatformUtilities::fpuReset()
  238. {
  239. }
  240. END_JUCE_NAMESPACE