Index: media/video/capture/screen/mac/desktop_configuration.mm |
diff --git a/media/video/capture/screen/mac/desktop_configuration.mm b/media/video/capture/screen/mac/desktop_configuration.mm |
index 064c4efa77e1871836fbd620f3171f955c14e387..c5a6061724accfd6709515b792e6755726f5364e 100644 |
--- a/media/video/capture/screen/mac/desktop_configuration.mm |
+++ b/media/video/capture/screen/mac/desktop_configuration.mm |
@@ -21,20 +21,24 @@ |
namespace media { |
-MacDisplayConfiguration::MacDisplayConfiguration() |
- : id(0), |
- bounds(SkIRect::MakeEmpty()), |
- pixel_bounds(SkIRect::MakeEmpty()), |
- dip_to_pixel_scale(1.0f) { |
-} |
+namespace { |
-static SkIRect NSRectToSkIRect(const NSRect& ns_rect) { |
+SkIRect NSRectToSkIRect(const NSRect& ns_rect) { |
SkIRect result; |
gfx::CGRectToSkRect(NSRectToCGRect(ns_rect)).roundOut(&result); |
return result; |
} |
-static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { |
+// Inverts the position of |rect| about the horizontal mid-point of |bounds|. |
+// If |bounds| refers to a Cartesian coordinate space then this effectively |
+// converts |rect| from Cartesian (bottom-left origin) to inverse-Cartesian |
+// (top-left origin) coordinates. |
+void InvertRectYOrigin(const SkIRect& bounds, SkIRect* rect) { |
+ rect->setXYWH(rect->x(), bounds.top() + bounds.bottom() - rect->bottom(), |
+ rect->width(), rect->height()); |
+} |
+ |
+MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { |
MacDisplayConfiguration display_config; |
// Fetch the NSScreenNumber, which is also the CGDirectDisplayID. |
@@ -60,17 +64,26 @@ static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { |
return display_config; |
} |
+} // namespace |
+ |
+MacDisplayConfiguration::MacDisplayConfiguration() |
+ : id(0), |
+ bounds(SkIRect::MakeEmpty()), |
+ pixel_bounds(SkIRect::MakeEmpty()), |
+ dip_to_pixel_scale(1.0f) { |
+} |
+ |
MacDesktopConfiguration::MacDesktopConfiguration() |
- : bounds(SkIRect::MakeEmpty()), |
- pixel_bounds(SkIRect::MakeEmpty()), |
- dip_to_pixel_scale(1.0f) { |
+ : bounds(SkIRect::MakeEmpty()), |
+ pixel_bounds(SkIRect::MakeEmpty()), |
+ dip_to_pixel_scale(1.0f) { |
} |
MacDesktopConfiguration::~MacDesktopConfiguration() { |
} |
// static |
-MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() { |
+MacDesktopConfiguration MacDesktopConfiguration::GetCurrent(Origin origin) { |
MacDesktopConfiguration desktop_config; |
NSArray* screens = [NSScreen screens]; |
@@ -92,6 +105,16 @@ MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() { |
continue; |
} |
+ // Mac uses Cartesian (bottom-left origin) coordinates, so if the caller |
+ // wants inverse Cartesian (top-left origin), secondary monitors need |
+ // their coordinates inverting relative to the primary monitor's bounds. |
+ if (i > 0 && origin == TopLeftOrigin) { |
+ InvertRectYOrigin(desktop_config.displays[0].bounds, |
+ &display_config.bounds); |
+ InvertRectYOrigin(desktop_config.displays[0].pixel_bounds, |
+ &display_config.pixel_bounds); |
+ } |
+ |
// Add the display to the configuration. |
desktop_config.displays.push_back(display_config); |