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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/capturer/mac/desktop_configuration.mm
diff --git a/remoting/capturer/mac/desktop_configuration.mm b/remoting/capturer/mac/desktop_configuration.mm
new file mode 100644
index 0000000000000000000000000000000000000000..542278ead4281d1f90eef5ffd7292995f6862a94
--- /dev/null
+++ b/remoting/capturer/mac/desktop_configuration.mm
@@ -0,0 +1,121 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/capturer/mac/desktop_configuration.h"
+
+#include <Cocoa/Cocoa.h>
+
+#include "base/logging.h"
+#include "skia/ext/skia_utils_mac.h"
+
+#if !defined(MAC_OS_X_VERSION_10_7) || \
+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.
+
+@interface NSScreen (LionAPI)
+- (CGFloat)backingScaleFactor;
+- (NSRect)convertRectToBacking:(NSRect)aRect;
+@end
+
+#endif // 10.7
+
+namespace {
+ // Standard DPI for Mac OS X displays with 1:1 backing scale.
+ const int kDefaultDPI = 72;
Nico 2013/01/24 00:26:58 nit: no indent in namespaces
Wez 2013/01/25 00:32:49 Done.
+}
+
+namespace remoting {
+
+MacDisplayConfiguration::MacDisplayConfiguration()
+ : id(0),
+ logical_bounds(SkIRect::MakeEmpty()),
+ pixel_bounds(SkIRect::MakeEmpty()),
+ dpi(SkIPoint::Make(0, 0)),
+ logical_to_pixel_scale(1.0f) {
+}
+
+static SkIRect NSRectToSkIRect(const NSRect& ns_rect) {
+ SkIRect result;
+ gfx::CGRectToSkRect(NSRectToCGRect(ns_rect)).roundOut(&result);
+ return result;
+}
+
+static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
+ MacDisplayConfiguration display_config;
+
+ // Fetch the NSScreenNumber, which is also the CGDirectDisplayID.
+ NSDictionary* device_description = [screen deviceDescription];
+ display_config.id = static_cast<CGDirectDisplayID>(
+ [[device_description objectForKey:@"NSScreenNumber"] intValue]);
+
+ // Determine the display's logical & physical dimensions.
+ NSRect ns_logical_bounds = [screen frame];
+ display_config.logical_bounds = NSRectToSkIRect(ns_logical_bounds);
+
+ // If the host is running Mac OS X 10.7+ or later, query the scaling factor
+ // between logical and physical (aka "backing") pixels, otherwise assume 1:1.
+ if ([screen respondsToSelector:@selector(backingScaleFactor)] &&
+ [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
+ display_config.logical_to_pixel_scale = [screen backingScaleFactor];
+ NSRect ns_pixel_bounds = [screen convertRectToBacking: ns_logical_bounds];
+ display_config.pixel_bounds = NSRectToSkIRect(ns_pixel_bounds);
+ } else {
+ display_config.pixel_bounds = display_config.logical_bounds;
+ }
+
+ // Derive Dots-Per-Inch.
+ display_config.dpi.set(display_config.logical_to_pixel_scale * kDefaultDPI,
+ display_config.logical_to_pixel_scale * kDefaultDPI);
+
+ return display_config;
+}
+
+MacDesktopConfiguration::MacDesktopConfiguration()
+ : logical_bounds(SkIRect::MakeEmpty()),
+ pixel_bounds(SkIRect::MakeEmpty()),
+ dpi(SkIPoint::Make(0,0)),
+ logical_to_pixel_scale(1.0f) {
+}
+
+MacDesktopConfiguration::~MacDesktopConfiguration() {
+}
+
+// static
+MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() {
+ MacDesktopConfiguration desktop_config;
+
+ NSArray* screens = [NSScreen screens];
+ CHECK(screens != NULL);
+
+ // Iterator over the monitors, adding the primary monitor and monitors whose
+ // DPI match that of the primary monitor.
+ for (NSUInteger i = 0; i < [screens count]; ++i) {
+ MacDisplayConfiguration display_config
+ = GetConfigurationForScreen([screens objectAtIndex: i]);
+
+ // Handling mixed-DPI is hard, so we only return displays that match the
+ // "primary" display's DPI. The primary display is always the first in the
+ // list returned by [NSScreen screens].
+ if (i == 0) {
+ desktop_config.dpi = display_config.dpi;
+ desktop_config.logical_to_pixel_scale =
+ display_config.logical_to_pixel_scale;
+ } else if (display_config.dpi != desktop_config.dpi) {
+ continue;
+ }
+
+ CHECK_EQ(desktop_config.logical_to_pixel_scale,
+ display_config.logical_to_pixel_scale);
+
+ // Add the display to the configuration.
+ desktop_config.displays.push_back(display_config);
+
+ // Update the desktop bounds to account for this display.
+ desktop_config.logical_bounds.join(display_config.logical_bounds);
+ desktop_config.pixel_bounds.join(display_config.pixel_bounds);
+ }
+
+ return desktop_config;
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698