Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: base/sys_info_mac.cc

Issue 384069: posix: move mac-specific code into mac-specific file (Closed)
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/sys_info_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <ApplicationServices/ApplicationServices.h>
7 #include <CoreServices/CoreServices.h> 8 #include <CoreServices/CoreServices.h>
9 #include <mach/mach_host.h>
10 #include <mach/mach_init.h>
8 11
9 namespace base { 12 namespace base {
10 13
11 // static 14 // static
12 void SysInfo::OperatingSystemVersionNumbers(int32 *major_version, 15 void SysInfo::OperatingSystemVersionNumbers(int32 *major_version,
13 int32 *minor_version, 16 int32 *minor_version,
14 int32 *bugfix_version) { 17 int32 *bugfix_version) {
15 Gestalt(gestaltSystemVersionMajor, 18 Gestalt(gestaltSystemVersionMajor,
16 reinterpret_cast<SInt32*>(major_version)); 19 reinterpret_cast<SInt32*>(major_version));
17 Gestalt(gestaltSystemVersionMinor, 20 Gestalt(gestaltSystemVersionMinor,
18 reinterpret_cast<SInt32*>(minor_version)); 21 reinterpret_cast<SInt32*>(minor_version));
19 Gestalt(gestaltSystemVersionBugFix, 22 Gestalt(gestaltSystemVersionBugFix,
20 reinterpret_cast<SInt32*>(bugfix_version)); 23 reinterpret_cast<SInt32*>(bugfix_version));
21 } 24 }
22 25
26 // static
27 int64 SysInfo::AmountOfPhysicalMemory() {
28 struct host_basic_info hostinfo;
29 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
30 int result = host_info(mach_host_self(),
31 HOST_BASIC_INFO,
32 reinterpret_cast<host_info_t>(&hostinfo),
33 &count);
34 DCHECK_EQ(HOST_BASIC_INFO_COUNT, count);
35 if (result != KERN_SUCCESS) {
36 NOTREACHED();
37 return 0;
38 }
39
40 return static_cast<int64>(hostinfo.max_mem);
41 }
42
43 // static
44 void SysInfo::GetPrimaryDisplayDimensions(int* width, int* height) {
45 CGDirectDisplayID main_display = CGMainDisplayID();
46 if (width)
47 *width = CGDisplayPixelsWide(main_display);
48 if (height)
49 *height = CGDisplayPixelsHigh(main_display);
50 }
51
52 // static
53 int SysInfo::DisplayCount() {
54 // Don't just return the number of online displays. It includes displays
55 // that mirror other displays, which are not desired in the count. It's
56 // tempting to use the count returned by CGGetActiveDisplayList, but active
57 // displays exclude sleeping displays, and those are desired in the count.
58
59 // It would be ridiculous to have this many displays connected, but
60 // CGDirectDisplayID is just an integer, so supporting up to this many
61 // doesn't hurt.
62 CGDirectDisplayID online_displays[128];
63 CGDisplayCount online_display_count = 0;
64 if (CGGetOnlineDisplayList(arraysize(online_displays),
65 online_displays,
66 &online_display_count) != kCGErrorSuccess) {
67 // 1 is a reasonable assumption.
68 return 1;
69 }
70
71 int display_count = 0;
72 for (CGDisplayCount online_display_index = 0;
73 online_display_index < online_display_count;
74 ++online_display_index) {
75 CGDirectDisplayID online_display = online_displays[online_display_index];
76 if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) {
77 // If this display doesn't mirror any other, include it in the count.
78 // The primary display in a mirrored set will be counted, but those that
79 // mirror it will not be.
80 ++display_count;
81 }
82 }
83
84 return display_count;
85 }
86
23 } // namespace base 87 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/sys_info_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698