diff options
author | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 17:38:27 +0000 |
---|---|---|
committer | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-23 17:38:27 +0000 |
commit | 50e9dcf831492784c434b95c56808402c6de6295 (patch) | |
tree | b8232101b10a33a50d40ea48cdfecac8bcb40efc /remoting/capturer/mac | |
parent | 45499256db8cd1796deca460a0ebef69368fa841 (diff) | |
download | chromium_src-50e9dcf831492784c434b95c56808402c6de6295.zip chromium_src-50e9dcf831492784c434b95c56808402c6de6295.tar.gz chromium_src-50e9dcf831492784c434b95c56808402c6de6295.tar.bz2 |
Add support for high-DPI hosts under Mac OS X.
- Moves enumeration of display configuration(s) to helper classes, which fetch each display's logical and device-native resolutions.
- Updates VideoFrameCapturerMac and EventExecutorMac to use the helper.
BUG=135081
Review URL: https://chromiumcodereview.appspot.com/11665012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178318 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/capturer/mac')
-rw-r--r-- | remoting/capturer/mac/desktop_configuration.h | 69 | ||||
-rw-r--r-- | remoting/capturer/mac/desktop_configuration.mm | 99 |
2 files changed, 168 insertions, 0 deletions
diff --git a/remoting/capturer/mac/desktop_configuration.h b/remoting/capturer/mac/desktop_configuration.h new file mode 100644 index 0000000..2e76f8d --- /dev/null +++ b/remoting/capturer/mac/desktop_configuration.h @@ -0,0 +1,69 @@ +// 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. + +#ifndef REMOTING_CAPTURER_MAC_DESKTOP_CONFIGURATION_H_ +#define REMOTING_CAPTURER_MAC_DESKTOP_CONFIGURATION_H_ + +#include <ApplicationServices/ApplicationServices.h> +#include <Carbon/Carbon.h> +#include <vector> + +#include "base/basictypes.h" +#include "third_party/skia/include/core/SkPoint.h" +#include "third_party/skia/include/core/SkRect.h" + +namespace remoting { + +// Describes the configuration of a specific display. +struct MacDisplayConfiguration { + MacDisplayConfiguration(); + + // Returns the current configuration of the specified display. + static MacDisplayConfiguration ForDisplay(CGDirectDisplayID display_id); + + // Cocoa identifier for this display. + CGDirectDisplayID id; + + // Bounds of this display in logical (72dpi) coordinates. + SkIRect logical_bounds; + + // Bounds of the desktop in device resolution (i.e. physical) pixels. + SkIRect pixel_bounds; + + // Resolution of the desktop in Dots-Per-Inch. + SkIPoint dpi; + + // Scale factor from logical to pixel units. + float logical_to_pixel_scale; +}; + +typedef std::vector<MacDisplayConfiguration> MacDisplayConfigurations; + +// Describes the configuration of the whole desktop. +struct MacDesktopConfiguration { + MacDesktopConfiguration(); + ~MacDesktopConfiguration(); + + // Returns the current configuration of the desktop. + static MacDesktopConfiguration GetCurrent(); + + // Bounds of the desktop in logical (72dpi) coordinates. + SkIRect logical_bounds; + + // Bounds of the desktop in device resolution (i.e. physical) pixels. + SkIRect pixel_bounds; + + // Resolution of the desktop in Dots-Per-Inch. + SkIPoint dpi; + + // Scale factor from logical to pixel units. + float logical_to_pixel_scale; + + // Configurations of the displays making up the desktop area. + MacDisplayConfigurations displays; +}; + +} // namespace remoting + +#endif // REMOTING_CAPTURER_MAC_DESKTOP_CONFIGURATION_H_ diff --git a/remoting/capturer/mac/desktop_configuration.mm b/remoting/capturer/mac/desktop_configuration.mm new file mode 100644 index 0000000..1bee613 --- /dev/null +++ b/remoting/capturer/mac/desktop_configuration.mm @@ -0,0 +1,99 @@ +// 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" + +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]; + NSRect ns_pixel_bounds = [screen convertRectToBacking: ns_logical_bounds]; + display_config.logical_bounds = NSRectToSkIRect(ns_logical_bounds); + display_config.pixel_bounds = NSRectToSkIRect(ns_pixel_bounds); + + // Determine the display's resolution in Dots-Per-Inch. + NSSize ns_dots_per_inch = + [[device_description objectForKey: NSDeviceResolution] sizeValue]; + display_config.dpi.set(ns_dots_per_inch.width, ns_dots_per_inch.height); + display_config.logical_to_pixel_scale = [screen backingScaleFactor]; + + 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 |