1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/sys_info.h"
7 #include <ApplicationServices/ApplicationServices.h>
8 #include <CoreServices/CoreServices.h>
9 #include <mach/mach_host.h>
10 #include <mach/mach_init.h>
12 #include "base/logging.h"
17 void SysInfo::OperatingSystemVersionNumbers(int32
*major_version
,
19 int32
*bugfix_version
) {
20 Gestalt(gestaltSystemVersionMajor
,
21 reinterpret_cast<SInt32
*>(major_version
));
22 Gestalt(gestaltSystemVersionMinor
,
23 reinterpret_cast<SInt32
*>(minor_version
));
24 Gestalt(gestaltSystemVersionBugFix
,
25 reinterpret_cast<SInt32
*>(bugfix_version
));
29 int64
SysInfo::AmountOfPhysicalMemory() {
30 struct host_basic_info hostinfo
;
31 mach_msg_type_number_t count
= HOST_BASIC_INFO_COUNT
;
32 int result
= host_info(mach_host_self(),
34 reinterpret_cast<host_info_t
>(&hostinfo
),
36 DCHECK_EQ(HOST_BASIC_INFO_COUNT
, count
);
37 if (result
!= KERN_SUCCESS
) {
42 return static_cast<int64
>(hostinfo
.max_mem
);
46 void SysInfo::GetPrimaryDisplayDimensions(int* width
, int* height
) {
47 CGDirectDisplayID main_display
= CGMainDisplayID();
49 *width
= CGDisplayPixelsWide(main_display
);
51 *height
= CGDisplayPixelsHigh(main_display
);
55 int SysInfo::DisplayCount() {
56 // Don't just return the number of online displays. It includes displays
57 // that mirror other displays, which are not desired in the count. It's
58 // tempting to use the count returned by CGGetActiveDisplayList, but active
59 // displays exclude sleeping displays, and those are desired in the count.
61 // It would be ridiculous to have this many displays connected, but
62 // CGDirectDisplayID is just an integer, so supporting up to this many
64 CGDirectDisplayID online_displays
[128];
65 CGDisplayCount online_display_count
= 0;
66 if (CGGetOnlineDisplayList(arraysize(online_displays
),
68 &online_display_count
) != kCGErrorSuccess
) {
69 // 1 is a reasonable assumption.
73 int display_count
= 0;
74 for (CGDisplayCount online_display_index
= 0;
75 online_display_index
< online_display_count
;
76 ++online_display_index
) {
77 CGDirectDisplayID online_display
= online_displays
[online_display_index
];
78 if (CGDisplayMirrorsDisplay(online_display
) == kCGNullDirectDisplay
) {
79 // If this display doesn't mirror any other, include it in the count.
80 // The primary display in a mirrored set will be counted, but those that
81 // mirror it will not be.