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
This commit is contained in:
sergeyu@chromium.org 2014-04-18 18:22:41 +00:00
parent a596a389ea
commit be7585b150
5 changed files with 23 additions and 18 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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());