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.

267 lines
6.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  19. // compiled on its own).
  20. #ifdef JUCE_INCLUDED_FILE
  21. static int64 highResTimerFrequency;
  22. #if JUCE_INTEL
  23. static void juce_getCpuVendor (char* const v) throw()
  24. {
  25. int vendor[4];
  26. zerostruct (vendor);
  27. int dummy = 0;
  28. asm ("mov %%ebx, %%esi \n\t"
  29. "cpuid \n\t"
  30. "xchg %%esi, %%ebx"
  31. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  32. memcpy (v, vendor, 16);
  33. }
  34. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures) throw()
  35. {
  36. unsigned int cpu = 0;
  37. unsigned int ext = 0;
  38. unsigned int family = 0;
  39. unsigned int dummy = 0;
  40. asm ("mov %%ebx, %%esi \n\t"
  41. "cpuid \n\t"
  42. "xchg %%esi, %%ebx"
  43. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  44. familyModel = family;
  45. extFeatures = ext;
  46. return cpu;
  47. }
  48. struct CPUFlags
  49. {
  50. bool hasMMX : 1;
  51. bool hasSSE : 1;
  52. bool hasSSE2 : 1;
  53. bool has3DNow : 1;
  54. };
  55. static CPUFlags cpuFlags;
  56. #endif
  57. //==============================================================================
  58. void SystemStats::initialiseStats() throw()
  59. {
  60. static bool initialised = false;
  61. if (! initialised)
  62. {
  63. initialised = true;
  64. // extremely annoying: adding this line stops the apple menu items from working. Of
  65. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  66. // any events.
  67. //NSApplicationLoad();
  68. [NSApplication sharedApplication];
  69. #if JUCE_INTEL
  70. {
  71. unsigned int familyModel, extFeatures;
  72. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  73. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  74. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  75. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  76. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  77. }
  78. #endif
  79. highResTimerFrequency = (int64) AudioGetHostClockFrequency();
  80. String s (SystemStats::getJUCEVersion());
  81. rlimit lim;
  82. getrlimit (RLIMIT_NOFILE, &lim);
  83. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  84. setrlimit (RLIMIT_NOFILE, &lim);
  85. }
  86. }
  87. //==============================================================================
  88. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  89. {
  90. return MacOSX;
  91. }
  92. const String SystemStats::getOperatingSystemName() throw()
  93. {
  94. return T("Mac OS X");
  95. }
  96. bool SystemStats::isOperatingSystem64Bit() throw()
  97. {
  98. #if JUCE_64BIT
  99. return true;
  100. #else
  101. //xxx not sure how to find this out?..
  102. return false;
  103. #endif
  104. }
  105. int SystemStats::getMemorySizeInMegabytes() throw()
  106. {
  107. uint64 mem = 0;
  108. size_t memSize = sizeof (mem);
  109. int mib[] = { CTL_HW, HW_MEMSIZE };
  110. sysctl (mib, 2, &mem, &memSize, 0, 0);
  111. return mem / (1024 * 1024);
  112. }
  113. bool SystemStats::hasMMX() throw()
  114. {
  115. #if JUCE_INTEL
  116. return cpuFlags.hasMMX;
  117. #else
  118. return false;
  119. #endif
  120. }
  121. bool SystemStats::hasSSE() throw()
  122. {
  123. #if JUCE_INTEL
  124. return cpuFlags.hasSSE;
  125. #else
  126. return false;
  127. #endif
  128. }
  129. bool SystemStats::hasSSE2() throw()
  130. {
  131. #if JUCE_INTEL
  132. return cpuFlags.hasSSE2;
  133. #else
  134. return false;
  135. #endif
  136. }
  137. bool SystemStats::has3DNow() throw()
  138. {
  139. #if JUCE_INTEL
  140. return cpuFlags.has3DNow;
  141. #else
  142. return false;
  143. #endif
  144. }
  145. const String SystemStats::getCpuVendor() throw()
  146. {
  147. #if JUCE_INTEL
  148. char v [16];
  149. juce_getCpuVendor (v);
  150. return String (v, 16);
  151. #else
  152. return String::empty;
  153. #endif
  154. }
  155. int SystemStats::getCpuSpeedInMegaherz() throw()
  156. {
  157. uint64 speedHz = 0;
  158. size_t speedSize = sizeof (speedHz);
  159. int mib[] = { CTL_HW, HW_CPU_FREQ };
  160. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  161. #if JUCE_BIG_ENDIAN
  162. if (speedSize == 4)
  163. speedHz >>= 32;
  164. #endif
  165. return speedHz / 1000000;
  166. }
  167. int SystemStats::getNumCpus() throw()
  168. {
  169. #if MACOS_10_4_OR_EARLIER
  170. return MPProcessors();
  171. #else
  172. return [[NSProcessInfo processInfo] activeProcessorCount];
  173. #endif
  174. }
  175. //==============================================================================
  176. static int64 juce_getMicroseconds() throw()
  177. {
  178. UnsignedWide t;
  179. Microseconds (&t);
  180. return (((int64) t.hi) << 32) | t.lo;
  181. }
  182. uint32 juce_millisecondsSinceStartup() throw()
  183. {
  184. return (uint32) (juce_getMicroseconds() / 1000);
  185. }
  186. double Time::getMillisecondCounterHiRes() throw()
  187. {
  188. // xxx might be more accurate to use a scaled AudioGetCurrentHostTime?
  189. return juce_getMicroseconds() * 0.001;
  190. }
  191. int64 Time::getHighResolutionTicks() throw()
  192. {
  193. return (int64) AudioGetCurrentHostTime();
  194. }
  195. int64 Time::getHighResolutionTicksPerSecond() throw()
  196. {
  197. return highResTimerFrequency;
  198. }
  199. int64 SystemStats::getClockCycleCounter() throw()
  200. {
  201. return (int64) AudioGetCurrentHostTime();
  202. }
  203. bool Time::setSystemTimeToThisTime() const throw()
  204. {
  205. jassertfalse
  206. return false;
  207. }
  208. //==============================================================================
  209. int SystemStats::getPageSize() throw()
  210. {
  211. return NSPageSize();
  212. }
  213. void PlatformUtilities::fpuReset()
  214. {
  215. }
  216. #endif