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

Side by Side Diff: remoting/capturer/mac/desktop_configuration.mm

Issue 12040058: Add support for high-DPI hosts under Mac OS X. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for OS X 10.6. Created 7 years, 11 months 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) 2013 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 "remoting/capturer/mac/desktop_configuration.h"
6
7 #include <Cocoa/Cocoa.h>
8
9 #include "base/logging.h"
10 #include "skia/ext/skia_utils_mac.h"
11
12 #if !defined(MAC_OS_X_VERSION_10_7) || \
13 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
Jamie 2013/01/24 00:20:18 Nit: indent the continuation line.
Wez 2013/01/25 00:32:49 Done.
14
15 @interface NSScreen (LionAPI)
16 - (CGFloat)backingScaleFactor;
17 - (NSRect)convertRectToBacking:(NSRect)aRect;
18 @end
19
20 #endif // 10.7
21
22 namespace {
23 // Standard DPI for Mac OS X displays with 1:1 backing scale.
24 const int kDefaultDPI = 72;
Nico 2013/01/24 00:26:58 nit: no indent in namespaces
Wez 2013/01/25 00:32:49 Done.
25 }
26
27 namespace remoting {
28
29 MacDisplayConfiguration::MacDisplayConfiguration()
30 : id(0),
31 logical_bounds(SkIRect::MakeEmpty()),
32 pixel_bounds(SkIRect::MakeEmpty()),
33 dpi(SkIPoint::Make(0, 0)),
34 logical_to_pixel_scale(1.0f) {
35 }
36
37 static SkIRect NSRectToSkIRect(const NSRect& ns_rect) {
38 SkIRect result;
39 gfx::CGRectToSkRect(NSRectToCGRect(ns_rect)).roundOut(&result);
40 return result;
41 }
42
43 static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
44 MacDisplayConfiguration display_config;
45
46 // Fetch the NSScreenNumber, which is also the CGDirectDisplayID.
47 NSDictionary* device_description = [screen deviceDescription];
48 display_config.id = static_cast<CGDirectDisplayID>(
49 [[device_description objectForKey:@"NSScreenNumber"] intValue]);
50
51 // Determine the display's logical & physical dimensions.
52 NSRect ns_logical_bounds = [screen frame];
53 display_config.logical_bounds = NSRectToSkIRect(ns_logical_bounds);
54
55 // If the host is running Mac OS X 10.7+ or later, query the scaling factor
56 // between logical and physical (aka "backing") pixels, otherwise assume 1:1.
57 if ([screen respondsToSelector:@selector(backingScaleFactor)] &&
58 [screen respondsToSelector:@selector(convertRectToBacking)]) {
Wez 2013/01/24 00:57:30 For some reason I'm getting this returning false..
Nico 2013/01/24 00:58:30 You're missing the trailing ':', it's "convertRect
59 display_config.logical_to_pixel_scale = [screen backingScaleFactor];
60 NSRect ns_pixel_bounds = [screen convertRectToBacking: ns_logical_bounds];
61 display_config.pixel_bounds = NSRectToSkIRect(ns_pixel_bounds);
62 } else {
63 display_config.pixel_bounds = display_config.logical_bounds;
64 }
65
66 // Derive Dots-Per-Inch.
67 display_config.dpi.set(display_config.logical_to_pixel_scale * kDefaultDPI,
68 display_config.logical_to_pixel_scale * kDefaultDPI);
69
70 return display_config;
71 }
72
73 MacDesktopConfiguration::MacDesktopConfiguration()
74 : logical_bounds(SkIRect::MakeEmpty()),
75 pixel_bounds(SkIRect::MakeEmpty()),
76 dpi(SkIPoint::Make(0,0)),
77 logical_to_pixel_scale(1.0f) {
78 }
79
80 MacDesktopConfiguration::~MacDesktopConfiguration() {
81 }
82
83 // static
84 MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() {
85 MacDesktopConfiguration desktop_config;
86
87 NSArray* screens = [NSScreen screens];
88 CHECK(screens != NULL);
89
90 // Iterator over the monitors, adding the primary monitor and monitors whose
91 // DPI match that of the primary monitor.
92 for (NSUInteger i = 0; i < [screens count]; ++i) {
93 MacDisplayConfiguration display_config
94 = GetConfigurationForScreen([screens objectAtIndex: i]);
95
96 // Handling mixed-DPI is hard, so we only return displays that match the
97 // "primary" display's DPI. The primary display is always the first in the
98 // list returned by [NSScreen screens].
99 if (i == 0) {
100 desktop_config.dpi = display_config.dpi;
101 desktop_config.logical_to_pixel_scale =
102 display_config.logical_to_pixel_scale;
103 } else if (display_config.dpi != desktop_config.dpi) {
104 continue;
105 }
106
107 CHECK_EQ(desktop_config.logical_to_pixel_scale,
108 display_config.logical_to_pixel_scale);
109
110 // Add the display to the configuration.
111 desktop_config.displays.push_back(display_config);
112
113 // Update the desktop bounds to account for this display.
114 desktop_config.logical_bounds.join(display_config.logical_bounds);
115 desktop_config.pixel_bounds.join(display_config.pixel_bounds);
116 }
117
118 return desktop_config;
119 }
120
121 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698