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.

291 lines
7.1KB

  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 <AppKit/AppKit.h>
  25. #include <Carbon/Carbon.h>
  26. #include <CoreAudio/HostTime.h>
  27. #include <ctime>
  28. #include <sys/resource.h>
  29. BEGIN_JUCE_NAMESPACE
  30. #include "../../../src/juce_appframework/application/juce_Application.h"
  31. #include "../../../src/juce_core/basics/juce_SystemStats.h"
  32. #include "../../../src/juce_core/basics/juce_Time.h"
  33. #include "../../../src/juce_core/misc/juce_PlatformUtilities.h"
  34. static int64 highResTimerFrequency;
  35. #if JUCE_INTEL
  36. static void juce_getCpuVendor (char* const v) throw()
  37. {
  38. int vendor[4];
  39. zerostruct (vendor);
  40. int dummy = 0;
  41. asm ("mov %%ebx, %%esi \n\t"
  42. "cpuid \n\t"
  43. "xchg %%esi, %%ebx"
  44. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  45. memcpy (v, vendor, 16);
  46. }
  47. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures) throw()
  48. {
  49. unsigned int cpu = 0;
  50. unsigned int ext = 0;
  51. unsigned int family = 0;
  52. unsigned int dummy = 0;
  53. asm ("mov %%ebx, %%esi \n\t"
  54. "cpuid \n\t"
  55. "xchg %%esi, %%ebx"
  56. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  57. familyModel = family;
  58. extFeatures = ext;
  59. return cpu;
  60. }
  61. struct CPUFlags
  62. {
  63. bool hasMMX : 1;
  64. bool hasSSE : 1;
  65. bool hasSSE2 : 1;
  66. bool has3DNow : 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. bool SystemStats::isOperatingSystem64Bit() throw()
  102. {
  103. #if JUCE_64BIT
  104. return true;
  105. #else
  106. //xxx not sure how to find this out?..
  107. return false;
  108. #endif
  109. }
  110. //==============================================================================
  111. void SystemStats::initialiseStats() throw()
  112. {
  113. static bool initialised = false;
  114. if (! initialised)
  115. {
  116. initialised = true;
  117. NSApplicationLoad();
  118. #if JUCE_INTEL
  119. {
  120. unsigned int familyModel, extFeatures;
  121. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  122. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  123. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  124. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  125. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  126. }
  127. #endif
  128. highResTimerFrequency = (int64) AudioGetHostClockFrequency();
  129. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  130. if (JUCEApplication::getInstance() != 0)
  131. RegisterAppearanceClient();
  132. #endif
  133. TXNInitTextension (0, 0, kTXNWantMoviesMask | kTXNWantGraphicsMask);
  134. String s (SystemStats::getJUCEVersion());
  135. rlimit lim;
  136. getrlimit (RLIMIT_NOFILE, &lim);
  137. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  138. setrlimit (RLIMIT_NOFILE, &lim);
  139. }
  140. }
  141. bool SystemStats::hasMMX() throw()
  142. {
  143. #if JUCE_INTEL
  144. return cpuFlags.hasMMX;
  145. #else
  146. return false;
  147. #endif
  148. }
  149. bool SystemStats::hasSSE() throw()
  150. {
  151. #if JUCE_INTEL
  152. return cpuFlags.hasSSE;
  153. #else
  154. return false;
  155. #endif
  156. }
  157. bool SystemStats::hasSSE2() throw()
  158. {
  159. #if JUCE_INTEL
  160. return cpuFlags.hasSSE2;
  161. #else
  162. return false;
  163. #endif
  164. }
  165. bool SystemStats::has3DNow() throw()
  166. {
  167. #if JUCE_INTEL
  168. return cpuFlags.has3DNow;
  169. #else
  170. return false;
  171. #endif
  172. }
  173. const String SystemStats::getCpuVendor() throw()
  174. {
  175. #if JUCE_INTEL
  176. char v [16];
  177. juce_getCpuVendor (v);
  178. return String (v, 16);
  179. #else
  180. return String::empty;
  181. #endif
  182. }
  183. int SystemStats::getCpuSpeedInMegaherz() throw()
  184. {
  185. return GetCPUSpeed();
  186. }
  187. int SystemStats::getNumCpus() throw()
  188. {
  189. return MPProcessors();
  190. }
  191. //==============================================================================
  192. static int64 juce_getMicroseconds() throw()
  193. {
  194. UnsignedWide t;
  195. Microseconds (&t);
  196. return (((int64) t.hi) << 32) | t.lo;
  197. }
  198. uint32 juce_millisecondsSinceStartup() throw()
  199. {
  200. return (uint32) (juce_getMicroseconds() / 1000);
  201. }
  202. double Time::getMillisecondCounterHiRes() throw()
  203. {
  204. // xxx might be more accurate to use a scaled AudioGetCurrentHostTime?
  205. return juce_getMicroseconds() * 0.001;
  206. }
  207. int64 Time::getHighResolutionTicks() throw()
  208. {
  209. return (int64) AudioGetCurrentHostTime();
  210. }
  211. int64 Time::getHighResolutionTicksPerSecond() throw()
  212. {
  213. return highResTimerFrequency;
  214. }
  215. int64 SystemStats::getClockCycleCounter() throw()
  216. {
  217. jassertfalse
  218. return 0;
  219. }
  220. bool Time::setSystemTimeToThisTime() const throw()
  221. {
  222. jassertfalse
  223. return false;
  224. }
  225. //==============================================================================
  226. int SystemStats::getPageSize() throw()
  227. {
  228. jassertfalse
  229. return 512; //xxx
  230. }
  231. void PlatformUtilities::fpuReset()
  232. {
  233. }
  234. END_JUCE_NAMESPACE