From be7585b1504cca30963c47889f2b9ae7dd75b5dd Mon Sep 17 00:00:00 2001 From: "sergeyu@chromium.org" Date: Fri, 18 Apr 2014 18:22:41 +0000 Subject: [PATCH] Fix multi-monitor support in the screen capturer for Mac. This feature was broken in r5471. BUG=361919 R=jiayl@webrtc.org Review URL: https://webrtc-codereview.appspot.com/12109004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@5937 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../mac/desktop_configuration.h | 9 +++++---- .../mac/desktop_configuration.mm | 18 +++++++++++------- .../mouse_cursor_monitor_mac.mm | 2 +- .../desktop_capture/screen_capturer_mac.mm | 6 +++--- .../screen_capturer_mac_unittest.cc | 6 +++--- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/webrtc/modules/desktop_capture/mac/desktop_configuration.h b/webrtc/modules/desktop_capture/mac/desktop_configuration.h index 031d92de2a..bac6440a6d 100644 --- a/webrtc/modules/desktop_capture/mac/desktop_configuration.h +++ b/webrtc/modules/desktop_capture/mac/desktop_configuration.h @@ -59,11 +59,12 @@ struct MacDesktopConfiguration { const MacDisplayConfiguration* FindDisplayConfigurationById( CGDirectDisplayID id); - // Bounds of the desktop in Density-Independent Pixels (DIPs). - DesktopRect bounds; + // Bounds of the desktop excluding monitors with DPI settings different from + // the main monitor. In Density-Independent Pixels (DIPs). + DesktopRect primary_bounds; - // Bounds of the desktop in physical pixels. - DesktopRect pixel_bounds; + // Same as primary_bounds, but expressed in physical pixels. + DesktopRect primary_pixel_bounds; // Scale factor from DIPs to physical pixels. float dip_to_pixel_scale; diff --git a/webrtc/modules/desktop_capture/mac/desktop_configuration.mm b/webrtc/modules/desktop_capture/mac/desktop_configuration.mm index 838973e42b..ce33914653 100644 --- a/webrtc/modules/desktop_capture/mac/desktop_configuration.mm +++ b/webrtc/modules/desktop_capture/mac/desktop_configuration.mm @@ -134,11 +134,15 @@ MacDesktopConfiguration MacDesktopConfiguration::GetCurrent(Origin origin) { // Add the display to the configuration. desktop_config.displays.push_back(display_config); - // Update the desktop bounds to account for this display. - desktop_config.bounds = - JoinRects(desktop_config.bounds, display_config.bounds); - desktop_config.pixel_bounds = - JoinRects(desktop_config.pixel_bounds, display_config.pixel_bounds); + // Update the desktop bounds to account for this display, unless the current + // display uses different DPI settings. + if (display_config.dip_to_pixel_scale == + desktop_config.dip_to_pixel_scale) { + desktop_config.primary_bounds = + JoinRects(desktop_config.primary_bounds, display_config.bounds); + desktop_config.primary_pixel_bounds = JoinRects( + desktop_config.primary_pixel_bounds, display_config.pixel_bounds); + } } return desktop_config; @@ -155,8 +159,8 @@ bool operator==(const MacDisplayConfiguration& left, } bool MacDesktopConfiguration::Equals(const MacDesktopConfiguration& other) { - return bounds.equals(other.bounds) && - pixel_bounds.equals(other.pixel_bounds) && + return primary_bounds.equals(other.primary_bounds) && + primary_pixel_bounds.equals(other.primary_pixel_bounds) && dip_to_pixel_scale == other.dip_to_pixel_scale && displays == other.displays; } diff --git a/webrtc/modules/desktop_capture/mouse_cursor_monitor_mac.mm b/webrtc/modules/desktop_capture/mouse_cursor_monitor_mac.mm index e880633819..1b71e0a890 100644 --- a/webrtc/modules/desktop_capture/mouse_cursor_monitor_mac.mm +++ b/webrtc/modules/desktop_capture/mouse_cursor_monitor_mac.mm @@ -200,7 +200,7 @@ void MouseCursorMonitorMac::Capture() { position.set(-1, -1); } } else { - position.subtract(configuration.bounds.top_left()); + position.subtract(configuration.primary_bounds.top_left()); } } if (state == INSIDE) { diff --git a/webrtc/modules/desktop_capture/screen_capturer_mac.mm b/webrtc/modules/desktop_capture/screen_capturer_mac.mm index 2d5733906f..1a2fd7c4d1 100644 --- a/webrtc/modules/desktop_capture/screen_capturer_mac.mm +++ b/webrtc/modules/desktop_capture/screen_capturer_mac.mm @@ -681,8 +681,8 @@ void ScreenCapturerMac::CgBlitPreLion(const DesktopFrame& frame, // Determine the display's position relative to the desktop, in pixels. DesktopRect display_bounds = display_config.pixel_bounds; - display_bounds.Translate(-desktop_config_.pixel_bounds.left(), - -desktop_config_.pixel_bounds.top()); + display_bounds.Translate(-desktop_config_.primary_pixel_bounds.left(), + -desktop_config_.primary_pixel_bounds.top()); // Determine which parts of the blit region, if any, lay within the monitor. DesktopRegion copy_region = region; @@ -854,7 +854,7 @@ void ScreenCapturerMac::ScreenConfigurationChanged() { screen_pixel_bounds_ = config ? config->pixel_bounds : DesktopRect(); dip_to_pixel_scale_ = config ? config->dip_to_pixel_scale : 1.0f; } else { - screen_pixel_bounds_ = desktop_config_.pixel_bounds; + screen_pixel_bounds_ = desktop_config_.primary_pixel_bounds; dip_to_pixel_scale_ = desktop_config_.dip_to_pixel_scale; } diff --git a/webrtc/modules/desktop_capture/screen_capturer_mac_unittest.cc b/webrtc/modules/desktop_capture/screen_capturer_mac_unittest.cc index a51a4792ce..f29eeb8bdf 100644 --- a/webrtc/modules/desktop_capture/screen_capturer_mac_unittest.cc +++ b/webrtc/modules/desktop_capture/screen_capturer_mac_unittest.cc @@ -55,7 +55,7 @@ void ScreenCapturerMacTest::CaptureDoneCallback1( // Verify that the region contains full frame. DesktopRegion::Iterator it(frame->updated_region()); - EXPECT_TRUE(!it.IsAtEnd() && it.rect().equals(config.pixel_bounds)); + EXPECT_TRUE(!it.IsAtEnd() && it.rect().equals(config.primary_pixel_bounds)); } void ScreenCapturerMacTest::CaptureDoneCallback2( @@ -64,8 +64,8 @@ void ScreenCapturerMacTest::CaptureDoneCallback2( MacDesktopConfiguration config = MacDesktopConfiguration::GetCurrent( MacDesktopConfiguration::BottomLeftOrigin); - int width = config.pixel_bounds.width(); - int height = config.pixel_bounds.height(); + int width = config.primary_pixel_bounds.width(); + int height = config.primary_pixel_bounds.height(); EXPECT_EQ(width, frame->size().width()); EXPECT_EQ(height, frame->size().height());