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.

286 lines
7.0KB

  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. bool SystemStats::isOperatingSystem64Bit() throw()
  101. {
  102. #if JUCE_64BIT
  103. return true;
  104. #else
  105. //xxx not sure how to find this out?..
  106. return false;
  107. #endif
  108. }
  109. //==============================================================================
  110. void SystemStats::initialiseStats() throw()
  111. {
  112. static bool initialised = false;
  113. if (! initialised)
  114. {
  115. initialised = true;
  116. #if JUCE_INTEL
  117. {
  118. unsigned int familyModel, extFeatures;
  119. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  120. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  121. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  122. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  123. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  124. }
  125. #endif
  126. highResTimerFrequency = (int64) AudioGetHostClockFrequency();
  127. if (JUCEApplication::getInstance() != 0)
  128. RegisterAppearanceClient();
  129. TXNInitTextension (0, 0, kTXNWantMoviesMask | kTXNWantGraphicsMask);
  130. String s (SystemStats::getJUCEVersion());
  131. rlimit lim;
  132. getrlimit (RLIMIT_NOFILE, &lim);
  133. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  134. setrlimit (RLIMIT_NOFILE, &lim);
  135. }
  136. }
  137. bool SystemStats::hasMMX() throw()
  138. {
  139. #if JUCE_INTEL
  140. return cpuFlags.hasMMX;
  141. #else
  142. return false;
  143. #endif
  144. }
  145. bool SystemStats::hasSSE() throw()
  146. {
  147. #if JUCE_INTEL
  148. return cpuFlags.hasSSE;
  149. #else
  150. return false;
  151. #endif
  152. }
  153. bool SystemStats::hasSSE2() throw()
  154. {
  155. #if JUCE_INTEL
  156. return cpuFlags.hasSSE2;
  157. #else
  158. return false;
  159. #endif
  160. }
  161. bool SystemStats::has3DNow() throw()
  162. {
  163. #if JUCE_INTEL
  164. return cpuFlags.has3DNow;
  165. #else
  166. return false;
  167. #endif
  168. }
  169. const String SystemStats::getCpuVendor() throw()
  170. {
  171. #if JUCE_INTEL
  172. char v [16];
  173. juce_getCpuVendor (v);
  174. return String (v, 16);
  175. #else
  176. return String::empty;
  177. #endif
  178. }
  179. int SystemStats::getCpuSpeedInMegaherz() throw()
  180. {
  181. return GetCPUSpeed();
  182. }
  183. int SystemStats::getNumCpus() throw()
  184. {
  185. return MPProcessors();
  186. }
  187. //==============================================================================
  188. static int64 juce_getMicroseconds() throw()
  189. {
  190. UnsignedWide t;
  191. Microseconds (&t);
  192. return (((int64) t.hi) << 32) | t.lo;
  193. }
  194. uint32 juce_millisecondsSinceStartup() throw()
  195. {
  196. return (uint32) (juce_getMicroseconds() / 1000);
  197. }
  198. double Time::getMillisecondCounterHiRes() throw()
  199. {
  200. // xxx might be more accurate to use a scaled AudioGetCurrentHostTime?
  201. return juce_getMicroseconds() * 0.001;
  202. }
  203. int64 Time::getHighResolutionTicks() throw()
  204. {
  205. return (int64) AudioGetCurrentHostTime();
  206. }
  207. int64 Time::getHighResolutionTicksPerSecond() throw()
  208. {
  209. return highResTimerFrequency;
  210. }
  211. int64 SystemStats::getClockCycleCounter() throw()
  212. {
  213. jassertfalse
  214. return 0;
  215. }
  216. bool Time::setSystemTimeToThisTime() const throw()
  217. {
  218. jassertfalse
  219. return false;
  220. }
  221. //==============================================================================
  222. int SystemStats::getPageSize() throw()
  223. {
  224. jassertfalse
  225. return 512; //xxx
  226. }
  227. void PlatformUtilities::fpuReset()
  228. {
  229. }
  230. END_JUCE_NAMESPACE