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.

288 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 ! ONLY_INCLUDE_JUCE_CORE_HEADERS
  128. if (JUCEApplication::getInstance() != 0)
  129. RegisterAppearanceClient();
  130. #endif
  131. TXNInitTextension (0, 0, kTXNWantMoviesMask | kTXNWantGraphicsMask);
  132. String s (SystemStats::getJUCEVersion());
  133. rlimit lim;
  134. getrlimit (RLIMIT_NOFILE, &lim);
  135. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  136. setrlimit (RLIMIT_NOFILE, &lim);
  137. }
  138. }
  139. bool SystemStats::hasMMX() throw()
  140. {
  141. #if JUCE_INTEL
  142. return cpuFlags.hasMMX;
  143. #else
  144. return false;
  145. #endif
  146. }
  147. bool SystemStats::hasSSE() throw()
  148. {
  149. #if JUCE_INTEL
  150. return cpuFlags.hasSSE;
  151. #else
  152. return false;
  153. #endif
  154. }
  155. bool SystemStats::hasSSE2() throw()
  156. {
  157. #if JUCE_INTEL
  158. return cpuFlags.hasSSE2;
  159. #else
  160. return false;
  161. #endif
  162. }
  163. bool SystemStats::has3DNow() throw()
  164. {
  165. #if JUCE_INTEL
  166. return cpuFlags.has3DNow;
  167. #else
  168. return false;
  169. #endif
  170. }
  171. const String SystemStats::getCpuVendor() throw()
  172. {
  173. #if JUCE_INTEL
  174. char v [16];
  175. juce_getCpuVendor (v);
  176. return String (v, 16);
  177. #else
  178. return String::empty;
  179. #endif
  180. }
  181. int SystemStats::getCpuSpeedInMegaherz() throw()
  182. {
  183. return GetCPUSpeed();
  184. }
  185. int SystemStats::getNumCpus() throw()
  186. {
  187. return MPProcessors();
  188. }
  189. //==============================================================================
  190. static int64 juce_getMicroseconds() throw()
  191. {
  192. UnsignedWide t;
  193. Microseconds (&t);
  194. return (((int64) t.hi) << 32) | t.lo;
  195. }
  196. uint32 juce_millisecondsSinceStartup() throw()
  197. {
  198. return (uint32) (juce_getMicroseconds() / 1000);
  199. }
  200. double Time::getMillisecondCounterHiRes() throw()
  201. {
  202. // xxx might be more accurate to use a scaled AudioGetCurrentHostTime?
  203. return juce_getMicroseconds() * 0.001;
  204. }
  205. int64 Time::getHighResolutionTicks() throw()
  206. {
  207. return (int64) AudioGetCurrentHostTime();
  208. }
  209. int64 Time::getHighResolutionTicksPerSecond() throw()
  210. {
  211. return highResTimerFrequency;
  212. }
  213. int64 SystemStats::getClockCycleCounter() throw()
  214. {
  215. jassertfalse
  216. return 0;
  217. }
  218. bool Time::setSystemTimeToThisTime() const throw()
  219. {
  220. jassertfalse
  221. return false;
  222. }
  223. //==============================================================================
  224. int SystemStats::getPageSize() throw()
  225. {
  226. jassertfalse
  227. return 512; //xxx
  228. }
  229. void PlatformUtilities::fpuReset()
  230. {
  231. }
  232. END_JUCE_NAMESPACE