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

Side by Side Diff: chrome/browser/metrics/display_utils_mac.cc

Issue 8382019: Move DisplayUtils methods into gfx::Screen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove DCHECKS Created 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "chrome/browser/metrics/display_utils.h"
6
7 #include <ApplicationServices/ApplicationServices.h>
8
9 // static
10 void DisplayUtils::GetPrimaryDisplayDimensions(int* width, int* height) {
11 CGDirectDisplayID main_display = CGMainDisplayID();
12 if (width)
13 *width = CGDisplayPixelsWide(main_display);
14 if (height)
15 *height = CGDisplayPixelsHigh(main_display);
16 }
17
18 // static
19 int DisplayUtils::GetDisplayCount() {
20 // Don't just return the number of online displays. It includes displays
21 // that mirror other displays, which are not desired in the count. It's
22 // tempting to use the count returned by CGGetActiveDisplayList, but active
23 // displays exclude sleeping displays, and those are desired in the count.
24
25 // It would be ridiculous to have this many displays connected, but
26 // CGDirectDisplayID is just an integer, so supporting up to this many
27 // doesn't hurt.
28 CGDirectDisplayID online_displays[128];
29 CGDisplayCount online_display_count = 0;
30 if (CGGetOnlineDisplayList(arraysize(online_displays),
31 online_displays,
32 &online_display_count) != kCGErrorSuccess) {
33 // 1 is a reasonable assumption.
34 return 1;
35 }
36
37 int display_count = 0;
38 for (CGDisplayCount online_display_index = 0;
39 online_display_index < online_display_count;
40 ++online_display_index) {
41 CGDirectDisplayID online_display = online_displays[online_display_index];
42 if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) {
43 // If this display doesn't mirror any other, include it in the count.
44 // The primary display in a mirrored set will be counted, but those that
45 // mirror it will not be.
46 ++display_count;
47 }
48 }
49
50 return display_count;
51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698