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.

276 lines
6.8KB

  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. };
  67. static CPUFlags cpuFlags;
  68. #endif
  69. //==============================================================================
  70. void Logger::outputDebugString (const String& text) throw()
  71. {
  72. String withLineFeed (text + T("\n"));
  73. const char* const utf8 = withLineFeed.toUTF8();
  74. fwrite (utf8, strlen (utf8), 1, stdout);
  75. }
  76. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  77. {
  78. String text;
  79. va_list args;
  80. va_start (args, format);
  81. text.vprintf(format, args);
  82. outputDebugString (text);
  83. }
  84. int SystemStats::getMemorySizeInMegabytes() throw()
  85. {
  86. long bytes;
  87. if (Gestalt (gestaltPhysicalRAMSize, &bytes) == noErr)
  88. return (int) (((unsigned long) bytes) / (1024 * 1024));
  89. return 0;
  90. }
  91. //==============================================================================
  92. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  93. {
  94. return MacOSX;
  95. }
  96. const String SystemStats::getOperatingSystemName() throw()
  97. {
  98. return T("Mac OS X");
  99. }
  100. //==============================================================================
  101. void SystemStats::initialiseStats() throw()
  102. {
  103. static bool initialised = false;
  104. if (! initialised)
  105. {
  106. initialised = true;
  107. #if JUCE_INTEL
  108. {
  109. unsigned int familyModel, extFeatures;
  110. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  111. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  112. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  113. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  114. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  115. }
  116. #endif
  117. highResTimerFrequency = (int64) AudioGetHostClockFrequency();
  118. if (JUCEApplication::getInstance() != 0)
  119. RegisterAppearanceClient();
  120. TXNInitTextension (0, 0, kTXNWantMoviesMask | kTXNWantGraphicsMask);
  121. String s (SystemStats::getJUCEVersion());
  122. rlimit lim;
  123. getrlimit (RLIMIT_NOFILE, &lim);
  124. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  125. setrlimit (RLIMIT_NOFILE, &lim);
  126. }
  127. }
  128. bool SystemStats::hasMMX() throw()
  129. {
  130. #if JUCE_INTEL
  131. return cpuFlags.hasMMX;
  132. #else
  133. return false;
  134. #endif
  135. }
  136. bool SystemStats::hasSSE() throw()
  137. {
  138. #if JUCE_INTEL
  139. return cpuFlags.hasSSE;
  140. #else
  141. return false;
  142. #endif
  143. }
  144. bool SystemStats::hasSSE2() throw()
  145. {
  146. #if JUCE_INTEL
  147. return cpuFlags.hasSSE2;
  148. #else
  149. return false;
  150. #endif
  151. }
  152. bool SystemStats::has3DNow() throw()
  153. {
  154. #if JUCE_INTEL
  155. return cpuFlags.has3DNow;
  156. #else
  157. return false;
  158. #endif
  159. }
  160. const String SystemStats::getCpuVendor() throw()
  161. {
  162. #if JUCE_INTEL
  163. char v [16];
  164. juce_getCpuVendor (v);
  165. return String (v, 16);
  166. #else
  167. return String::empty;
  168. #endif
  169. }
  170. int SystemStats::getCpuSpeedInMegaherz() throw()
  171. {
  172. return GetCPUSpeed();
  173. }
  174. int SystemStats::getNumCpus() throw()
  175. {
  176. return MPProcessors();
  177. }
  178. //==============================================================================
  179. static int64 juce_getMicroseconds() throw()
  180. {
  181. UnsignedWide t;
  182. Microseconds (&t);
  183. return (((int64) t.hi) << 32) | t.lo;
  184. }
  185. uint32 juce_millisecondsSinceStartup() throw()
  186. {
  187. return (uint32) (juce_getMicroseconds() / 1000);
  188. }
  189. double Time::getMillisecondCounterHiRes() throw()
  190. {
  191. // xxx might be more accurate to use a scaled AudioGetCurrentHostTime?
  192. return juce_getMicroseconds() * 0.001;
  193. }
  194. int64 Time::getHighResolutionTicks() throw()
  195. {
  196. return (int64) AudioGetCurrentHostTime();
  197. }
  198. int64 Time::getHighResolutionTicksPerSecond() throw()
  199. {
  200. return highResTimerFrequency;
  201. }
  202. int64 SystemStats::getClockCycleCounter() throw()
  203. {
  204. jassertfalse
  205. return 0;
  206. }
  207. bool Time::setSystemTimeToThisTime() const throw()
  208. {
  209. jassertfalse
  210. return false;
  211. }
  212. //==============================================================================
  213. int SystemStats::getPageSize() throw()
  214. {
  215. jassertfalse
  216. return 512; //xxx
  217. }
  218. void PlatformUtilities::fpuReset()
  219. {
  220. }
  221. END_JUCE_NAMESPACE