Commit 1b6fc2c1 authored by wez@chromium.org's avatar wez@chromium.org

Fix ScreenCapturerMac handling of secondary display configurations.

- Fix bugs in translating capture regions into display coordinates.
- Fix MacDeskopConfiguration to support inverse-Cartesian coordinates.

BUG=175261,174090


Review URL: https://chromiumcodereview.appspot.com/12221103

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181885 0039d316-1c4b-4281-b951-d872f2087c98
parent c67d0342
...@@ -20,10 +20,6 @@ namespace media { ...@@ -20,10 +20,6 @@ namespace media {
struct MEDIA_EXPORT MacDisplayConfiguration { struct MEDIA_EXPORT MacDisplayConfiguration {
MacDisplayConfiguration(); MacDisplayConfiguration();
// Returns the current configuration of the specified display.
MEDIA_EXPORT static MacDisplayConfiguration ForDisplay(
CGDirectDisplayID display_id);
// Cocoa identifier for this display. // Cocoa identifier for this display.
CGDirectDisplayID id; CGDirectDisplayID id;
...@@ -41,11 +37,16 @@ typedef std::vector<MacDisplayConfiguration> MacDisplayConfigurations; ...@@ -41,11 +37,16 @@ typedef std::vector<MacDisplayConfiguration> MacDisplayConfigurations;
// Describes the configuration of the whole desktop. // Describes the configuration of the whole desktop.
struct MEDIA_EXPORT MacDesktopConfiguration { struct MEDIA_EXPORT MacDesktopConfiguration {
// Used to request bottom-up or top-down coordinates.
enum Origin { BottomLeftOrigin, TopLeftOrigin };
MacDesktopConfiguration(); MacDesktopConfiguration();
~MacDesktopConfiguration(); ~MacDesktopConfiguration();
// Returns the current configuration of the desktop. // Returns the desktop & display configurations in Cocoa-style "bottom-up"
MEDIA_EXPORT static MacDesktopConfiguration GetCurrent(); // (the origin is the bottom-left of the primary monitor, and coordinates
// increase as you move up the screen) or Carbon-style "top-down" coordinates.
MEDIA_EXPORT static MacDesktopConfiguration GetCurrent(Origin origin);
// Bounds of the desktop in Density-Independent Pixels (DIPs). // Bounds of the desktop in Density-Independent Pixels (DIPs).
SkIRect bounds; SkIRect bounds;
......
...@@ -21,20 +21,23 @@ ...@@ -21,20 +21,23 @@
namespace media { namespace media {
MacDisplayConfiguration::MacDisplayConfiguration() namespace {
: id(0),
bounds(SkIRect::MakeEmpty()),
pixel_bounds(SkIRect::MakeEmpty()),
dip_to_pixel_scale(1.0f) {
}
static SkIRect NSRectToSkIRect(const NSRect& ns_rect) { SkIRect NSRectToSkIRect(const NSRect& ns_rect) {
SkIRect result; SkIRect result;
gfx::CGRectToSkRect(NSRectToCGRect(ns_rect)).roundOut(&result); gfx::CGRectToSkRect(NSRectToCGRect(ns_rect)).roundOut(&result);
return result; return result;
} }
static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { // Inverts the position of |rect| from bottom-up coordinates to top-down,
// relative to |bounds|.
void InvertRectYOrigin(const SkIRect& bounds, SkIRect* rect) {
DCHECK_EQ(0, bounds.top());
rect->setXYWH(rect->x(), bounds.bottom() - rect->bottom(),
rect->width(), rect->height());
}
MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
MacDisplayConfiguration display_config; MacDisplayConfiguration display_config;
// Fetch the NSScreenNumber, which is also the CGDirectDisplayID. // Fetch the NSScreenNumber, which is also the CGDirectDisplayID.
...@@ -60,17 +63,26 @@ static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) { ...@@ -60,17 +63,26 @@ static MacDisplayConfiguration GetConfigurationForScreen(NSScreen* screen) {
return display_config; return display_config;
} }
} // namespace
MacDisplayConfiguration::MacDisplayConfiguration()
: id(0),
bounds(SkIRect::MakeEmpty()),
pixel_bounds(SkIRect::MakeEmpty()),
dip_to_pixel_scale(1.0f) {
}
MacDesktopConfiguration::MacDesktopConfiguration() MacDesktopConfiguration::MacDesktopConfiguration()
: bounds(SkIRect::MakeEmpty()), : bounds(SkIRect::MakeEmpty()),
pixel_bounds(SkIRect::MakeEmpty()), pixel_bounds(SkIRect::MakeEmpty()),
dip_to_pixel_scale(1.0f) { dip_to_pixel_scale(1.0f) {
} }
MacDesktopConfiguration::~MacDesktopConfiguration() { MacDesktopConfiguration::~MacDesktopConfiguration() {
} }
// static // static
MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() { MacDesktopConfiguration MacDesktopConfiguration::GetCurrent(Origin origin) {
MacDesktopConfiguration desktop_config; MacDesktopConfiguration desktop_config;
NSArray* screens = [NSScreen screens]; NSArray* screens = [NSScreen screens];
...@@ -92,6 +104,16 @@ MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() { ...@@ -92,6 +104,16 @@ MacDesktopConfiguration MacDesktopConfiguration::GetCurrent() {
continue; continue;
} }
// Cocoa uses bottom-up coordinates, so if the caller wants top-down then
// we need to invert the positions of secondary monitors relative to the
// primary one (the primary monitor's position is (0,0) in both systems).
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. // Add the display to the configuration.
desktop_config.displays.push_back(display_config); desktop_config.displays.push_back(display_config);
......
...@@ -586,8 +586,7 @@ void ScreenCapturerMac::CgBlitPreLion(const ScreenCaptureFrame& buffer, ...@@ -586,8 +586,7 @@ void ScreenCapturerMac::CgBlitPreLion(const ScreenCaptureFrame& buffer,
continue; continue;
// Translate the region to be copied into display-relative coordinates. // Translate the region to be copied into display-relative coordinates.
copy_region.translate(-desktop_config_.pixel_bounds.left(), copy_region.translate(-display_bounds.left(), -display_bounds.top());
-desktop_config_.pixel_bounds.top());
// Calculate where in the output buffer the display's origin is. // Calculate where in the output buffer the display's origin is.
uint8* out_ptr = buffer.pixels() + uint8* out_ptr = buffer.pixels() +
...@@ -607,7 +606,7 @@ void ScreenCapturerMac::CgBlitPreLion(const ScreenCaptureFrame& buffer, ...@@ -607,7 +606,7 @@ void ScreenCapturerMac::CgBlitPreLion(const ScreenCaptureFrame& buffer,
} }
void ScreenCapturerMac::CgBlitPostLion(const ScreenCaptureFrame& buffer, void ScreenCapturerMac::CgBlitPostLion(const ScreenCaptureFrame& buffer,
const SkRegion& region) { const SkRegion& region) {
const int buffer_height = buffer.dimensions().height(); const int buffer_height = buffer.dimensions().height();
// Copy the entire contents of the previous capture buffer, to capture over. // Copy the entire contents of the previous capture buffer, to capture over.
...@@ -633,8 +632,7 @@ void ScreenCapturerMac::CgBlitPostLion(const ScreenCaptureFrame& buffer, ...@@ -633,8 +632,7 @@ void ScreenCapturerMac::CgBlitPostLion(const ScreenCaptureFrame& buffer,
continue; continue;
// Translate the region to be copied into display-relative coordinates. // Translate the region to be copied into display-relative coordinates.
copy_region.translate(-desktop_config_.pixel_bounds.left(), copy_region.translate(-display_bounds.left(), -display_bounds.top());
-desktop_config_.pixel_bounds.top());
// Create an image containing a snapshot of the display. // Create an image containing a snapshot of the display.
base::mac::ScopedCFTypeRef<CGImageRef> image( base::mac::ScopedCFTypeRef<CGImageRef> image(
...@@ -678,7 +676,8 @@ void ScreenCapturerMac::ScreenConfigurationChanged() { ...@@ -678,7 +676,8 @@ void ScreenCapturerMac::ScreenConfigurationChanged() {
helper_.ClearInvalidRegion(); helper_.ClearInvalidRegion();
// Refresh the cached desktop configuration. // Refresh the cached desktop configuration.
desktop_config_ = MacDesktopConfiguration::GetCurrent(); desktop_config_ = MacDesktopConfiguration::GetCurrent(
MacDesktopConfiguration::TopLeftOrigin);
// Re-mark the entire desktop as dirty. // Re-mark the entire desktop as dirty.
helper_.InvalidateScreen( helper_.InvalidateScreen(
......
...@@ -193,7 +193,8 @@ void EventExecutorMac::Core::InjectMouseEvent(const MouseEvent& event) { ...@@ -193,7 +193,8 @@ void EventExecutorMac::Core::InjectMouseEvent(const MouseEvent& event) {
// could be augmented to include native cursor coordinates for use by // could be augmented to include native cursor coordinates for use by
// MouseClampingFilter, removing the need for translation here. // MouseClampingFilter, removing the need for translation here.
media::MacDesktopConfiguration desktop_config = media::MacDesktopConfiguration desktop_config =
media::MacDesktopConfiguration::GetCurrent(); media::MacDesktopConfiguration::GetCurrent(
media::MacDesktopConfiguration::TopLeftOrigin);
// Translate the mouse position into desktop coordinates. // Translate the mouse position into desktop coordinates.
mouse_pos_ += SkIPoint::Make(desktop_config.pixel_bounds.left(), mouse_pos_ += SkIPoint::Make(desktop_config.pixel_bounds.left(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment