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 fbece4850b505b78d1a7abda19c192d4a65ec375..63b95c813e8bbf41c39493c99f841756afa3e15a 100644 |
--- a/media/video/capture/screen/mac/desktop_configuration.mm |
+++ b/media/video/capture/screen/mac/desktop_configuration.mm |
@@ -4,10 +4,11 @@ |
#include "media/video/capture/screen/mac/desktop_configuration.h" |
+#include <math.h> |
+#include <algorithm> |
#include <Cocoa/Cocoa.h> |
alexeypa (please no reviews)
2013/04/26 21:33:58
nit #1: should <algorithm> go first?
nit #2: shoul
Sergey Ulanov
2013/05/07 22:25:50
C headers go before C++: http://google-styleguide.
|
#include "base/logging.h" |
-#include "skia/ext/skia_utils_mac.h" |
#if !defined(MAC_OS_X_VERSION_10_7) || \ |
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
@@ -23,18 +24,29 @@ namespace media { |
namespace { |
-SkIRect NSRectToSkIRect(const NSRect& ns_rect) { |
- SkIRect result; |
- gfx::CGRectToSkRect(NSRectToCGRect(ns_rect)).roundOut(&result); |
- return result; |
+webrtc::DesktopRect NSRectToDesktopRect(const NSRect& ns_rect) { |
+ return webrtc::DesktopRect::MakeLTRB( |
+ static_cast<int>(ns_rect.origin.x), |
alexeypa (please no reviews)
2013/04/26 21:33:58
nit: Should this function check/sanitize |ns_rect|
Sergey Ulanov
2013/05/07 22:25:50
ns_rect comes from the OS, so sanitizing it here i
|
+ static_cast<int>(ns_rect.origin.y), |
+ static_cast<int>(ceil(ns_rect.origin.x + ns_rect.size.width)), |
+ static_cast<int>(ceil(ns_rect.origin.y + ns_rect.size.height))); |
+} |
+ |
+webrtc::DesktopRect JoinRects(const webrtc::DesktopRect& a, |
alexeypa (please no reviews)
2013/04/26 21:33:58
nit: Consider moving this to DesktopRect.
Sergey Ulanov
2013/05/07 22:25:50
This is the only case where we need it, so don't t
|
+ const webrtc::DesktopRect& b) { |
+ return webrtc::DesktopRect::MakeLTRB( |
+ std::min(a.left(), b.left()), std::min(a.top(), b.top()), |
alexeypa (please no reviews)
2013/04/26 21:33:58
nit: I think it will be more readable if each para
Sergey Ulanov
2013/05/07 22:25:50
Done.
|
+ std::max(a.right(), b.right()), std::max(a.bottom(), b.bottom())); |
} |
// Inverts the position of |rect| from bottom-up coordinates to top-down, |
// relative to |bounds|. |
-void InvertRectYOrigin(const SkIRect& bounds, SkIRect* rect) { |
+void InvertRectYOrigin(const webrtc::DesktopRect& bounds, |
+ webrtc::DesktopRect* rect) { |
DCHECK_EQ(0, bounds.top()); |
- rect->setXYWH(rect->x(), bounds.bottom() - rect->bottom(), |
- rect->width(), rect->height()); |
+ *rect = webrtc::DesktopRect::MakeXYWH( |
+ rect->left(), bounds.bottom() - rect->bottom(), |
+ rect->width(), rect->height()); |
} |
MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { |
@@ -47,7 +59,7 @@ MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { |
// Determine the display's logical & physical dimensions. |
NSRect ns_bounds = [screen frame]; |
- display_config.bounds = NSRectToSkIRect(ns_bounds); |
+ display_config.bounds = NSRectToDesktopRect(ns_bounds); |
// 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. |
@@ -55,7 +67,7 @@ MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { |
[screen respondsToSelector:@selector(convertRectToBacking:)]) { |
display_config.dip_to_pixel_scale = [screen backingScaleFactor]; |
NSRect ns_pixel_bounds = [screen convertRectToBacking: ns_bounds]; |
- display_config.pixel_bounds = NSRectToSkIRect(ns_pixel_bounds); |
+ display_config.pixel_bounds = NSRectToDesktopRect(ns_pixel_bounds); |
} else { |
display_config.pixel_bounds = display_config.bounds; |
} |
@@ -67,15 +79,11 @@ MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { |
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) { |
+ : dip_to_pixel_scale(1.0f) { |
} |
MacDesktopConfiguration::~MacDesktopConfiguration() { |
@@ -91,8 +99,8 @@ MacDesktopConfiguration MacDesktopConfiguration::GetCurrent(Origin origin) { |
// 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]); |
+ 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 |
@@ -118,8 +126,10 @@ MacDesktopConfiguration MacDesktopConfiguration::GetCurrent(Origin origin) { |
desktop_config.displays.push_back(display_config); |
// Update the desktop bounds to account for this display. |
- desktop_config.bounds.join(display_config.bounds); |
- desktop_config.pixel_bounds.join(display_config.pixel_bounds); |
+ desktop_config.bounds = |
+ JoinRects(desktop_config.bounds, display_config.bounds); |
Wez
2013/04/26 18:48:14
nit: Can we have DesktopRect provide a join() or u
Sergey Ulanov
2013/05/07 22:25:50
This is the only place where we need it at the mom
|
+ desktop_config.pixel_bounds = |
+ JoinRects(desktop_config.pixel_bounds, display_config.pixel_bounds); |
} |
return desktop_config; |