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

Unified Diff: media/video/capture/screen/mac/desktop_configuration.mm

Issue 12221103: Fix ScreenCapturerMac handling of secondary configurations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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: 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..8674deb16a32d42784af9702ea6b1c8bf4a19e3c 100644
--- a/media/video/capture/screen/mac/desktop_configuration.mm
+++ b/media/video/capture/screen/mac/desktop_configuration.mm
@@ -21,20 +21,22 @@
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| from top- to bottom-relative with respect to
+// the specified |reference| coordinates.
Jamie 2013/02/11 22:12:44 It's not clear to me from this comment what this f
Wez 2013/02/11 22:56:11 Done.
+void InvertRectYOrigin(const SkIRect& reference, SkIRect* rect) {
+ rect->setXYWH(rect->x(), reference.bottom() - rect->bottom(),
+ rect->width(), rect->height());
+}
+
+MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
MacDisplayConfiguration display_config;
// Fetch the NSScreenNumber, which is also the CGDirectDisplayID.
@@ -49,7 +51,7 @@ static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
// 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:)]) {
+ [screen respondsToSelector:@selector(convertRectToBacking:)]) {
Sergey Ulanov 2013/02/11 22:57:20 nit: this line was indented correctly.
Wez 2013/02/11 23:12:03 Done.
display_config.dip_to_pixel_scale = [screen backingScaleFactor];
NSRect ns_pixel_bounds = [screen convertRectToBacking: ns_bounds];
display_config.pixel_bounds = NSRectToSkIRect(ns_pixel_bounds);
@@ -60,6 +62,15 @@ static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
return display_config;
}
+} // namespace
+
+MacDisplayConfiguration::MacDisplayConfiguration()
+ : id(0),
Sergey Ulanov 2013/02/11 22:57:20 nit: this line should be indented 4 spaces and the
Wez 2013/02/11 23:12:03 Done.
+ bounds(SkIRect::MakeEmpty()),
+ pixel_bounds(SkIRect::MakeEmpty()),
+ dip_to_pixel_scale(1.0f) {
+}
+
MacDesktopConfiguration::MacDesktopConfiguration()
: bounds(SkIRect::MakeEmpty()),
pixel_bounds(SkIRect::MakeEmpty()),
@@ -70,7 +81,7 @@ MacDesktopConfiguration::~MacDesktopConfiguration() {
}
// static
-MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() {
+MacDesktopConfiguration MacDesktopConfiguration::GetCurrent(Origin origin) {
MacDesktopConfiguration desktop_config;
NSArray* screens = [NSScreen screens];
@@ -92,6 +103,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 adjusting.
Jamie 2013/02/11 22:12:44 Why only secondary monitors?
Wez 2013/02/11 22:56:11 The coordinate space is primary-monitor-relative.
+ if (i > 0 && origin == TopLeftOrigin) {
+ InvertRectYOrigin(desktop_config.displays[0].bounds,
Sergey Ulanov 2013/02/11 22:57:20 This doesn't look right to me. why invert bounds r
Wez 2013/02/11 23:12:03 The first parameter is the coordinate scheme about
Sergey Ulanov 2013/02/11 23:16:02 Ah, I see. Thanks for clarifying.
+ &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);

Powered by Google App Engine
This is Rietveld 408576698