[email protected] | f48122119 | 2011-04-07 22:15:34 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/sys_info.h" |
| 6 | |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 7 | #include <ApplicationServices/ApplicationServices.h> |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 8 | #include <CoreServices/CoreServices.h> |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 9 | #include <mach/mach_host.h> |
| 10 | #include <mach/mach_init.h> |
| 11 | |
| 12 | #include "base/logging.h" |
[email protected] | 6e001bb | 2011-05-25 20:53:18 | [diff] [blame^] | 13 | #include "base/stringprintf.h" |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 14 | |
| 15 | namespace base { |
| 16 | |
| 17 | // static |
[email protected] | 6e001bb | 2011-05-25 20:53:18 | [diff] [blame^] | 18 | std::string SysInfo::OperatingSystemName() { |
| 19 | return "Mac OS X"; |
| 20 | } |
| 21 | |
| 22 | // static |
| 23 | std::string SysInfo::OperatingSystemVersion() { |
| 24 | int32 major, minor, bugfix; |
| 25 | OperatingSystemVersionNumbers(&major, &minor, &bugfix); |
| 26 | return base::StringPrintf("%d.%d.%d", major, minor, bugfix); |
| 27 | } |
| 28 | |
| 29 | // static |
[email protected] | f48122119 | 2011-04-07 22:15:34 | [diff] [blame] | 30 | void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
| 31 | int32* minor_version, |
| 32 | int32* bugfix_version) { |
[email protected] | 0203ed7 | 2009-07-02 13:59:08 | [diff] [blame] | 33 | Gestalt(gestaltSystemVersionMajor, |
[email protected] | 3a3e5b3 | 2009-08-21 22:30:47 | [diff] [blame] | 34 | reinterpret_cast<SInt32*>(major_version)); |
[email protected] | 0203ed7 | 2009-07-02 13:59:08 | [diff] [blame] | 35 | Gestalt(gestaltSystemVersionMinor, |
[email protected] | 3a3e5b3 | 2009-08-21 22:30:47 | [diff] [blame] | 36 | reinterpret_cast<SInt32*>(minor_version)); |
[email protected] | 0203ed7 | 2009-07-02 13:59:08 | [diff] [blame] | 37 | Gestalt(gestaltSystemVersionBugFix, |
[email protected] | 3a3e5b3 | 2009-08-21 22:30:47 | [diff] [blame] | 38 | reinterpret_cast<SInt32*>(bugfix_version)); |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 39 | } |
| 40 | |
[email protected] | c858763 | 2009-11-12 02:17:19 | [diff] [blame] | 41 | // static |
| 42 | int64 SysInfo::AmountOfPhysicalMemory() { |
| 43 | struct host_basic_info hostinfo; |
| 44 | mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
| 45 | int result = host_info(mach_host_self(), |
| 46 | HOST_BASIC_INFO, |
| 47 | reinterpret_cast<host_info_t>(&hostinfo), |
| 48 | &count); |
| 49 | DCHECK_EQ(HOST_BASIC_INFO_COUNT, count); |
| 50 | if (result != KERN_SUCCESS) { |
| 51 | NOTREACHED(); |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | return static_cast<int64>(hostinfo.max_mem); |
| 56 | } |
| 57 | |
| 58 | // static |
| 59 | void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) { |
| 60 | CGDirectDisplayID main_display = CGMainDisplayID(); |
| 61 | if (width) |
| 62 | *width = CGDisplayPixelsWide(main_display); |
| 63 | if (height) |
| 64 | *height = CGDisplayPixelsHigh(main_display); |
| 65 | } |
| 66 | |
| 67 | // static |
| 68 | int SysInfo::DisplayCount() { |
| 69 | // Don't just return the number of online displays. It includes displays |
| 70 | // that mirror other displays, which are not desired in the count. It's |
| 71 | // tempting to use the count returned by CGGetActiveDisplayList, but active |
| 72 | // displays exclude sleeping displays, and those are desired in the count. |
| 73 | |
| 74 | // It would be ridiculous to have this many displays connected, but |
| 75 | // CGDirectDisplayID is just an integer, so supporting up to this many |
| 76 | // doesn't hurt. |
| 77 | CGDirectDisplayID online_displays[128]; |
| 78 | CGDisplayCount online_display_count = 0; |
| 79 | if (CGGetOnlineDisplayList(arraysize(online_displays), |
| 80 | online_displays, |
| 81 | &online_display_count) != kCGErrorSuccess) { |
| 82 | // 1 is a reasonable assumption. |
| 83 | return 1; |
| 84 | } |
| 85 | |
| 86 | int display_count = 0; |
| 87 | for (CGDisplayCount online_display_index = 0; |
| 88 | online_display_index < online_display_count; |
| 89 | ++online_display_index) { |
| 90 | CGDirectDisplayID online_display = online_displays[online_display_index]; |
| 91 | if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) { |
| 92 | // If this display doesn't mirror any other, include it in the count. |
| 93 | // The primary display in a mirrored set will be counted, but those that |
| 94 | // mirror it will not be. |
| 95 | ++display_count; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return display_count; |
| 100 | } |
| 101 | |
[email protected] | 71aa16c | 2009-02-24 16:37:13 | [diff] [blame] | 102 | } // namespace base |