From 31bbee73a029376ca5a6f74e3d5bf224053a6208 Mon Sep 17 00:00:00 2001 From: erikchen Date: Thu, 9 Mar 2017 13:19:03 -0800 Subject: [PATCH] mac: Fix screen capture for whole-desktop capture. DisplayStream refresh rects are in display coordinates. When the whole screen is being captured, the coordinates passed to the ScreenCapturerHelper need to be in screen coordinates. This CL translates display coordinates to screen coordinates for whole screen capture. BUG=chromium:699672 Review-Url: https://codereview.webrtc.org/2740823002 Cr-Commit-Position: refs/heads/master@{#17153} --- .../desktop_capture/screen_capturer_mac.mm | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/webrtc/modules/desktop_capture/screen_capturer_mac.mm b/webrtc/modules/desktop_capture/screen_capturer_mac.mm index b1d7c9048e..aed7e25e8d 100644 --- a/webrtc/modules/desktop_capture/screen_capturer_mac.mm +++ b/webrtc/modules/desktop_capture/screen_capturer_mac.mm @@ -304,7 +304,9 @@ class ScreenCapturerMac : public DesktopCapturer { bool RegisterRefreshAndMoveHandlers(); void UnregisterRefreshAndMoveHandlers(); - void ScreenRefresh(CGRectCount count, const CGRect *rect_array); + void ScreenRefresh(CGRectCount count, + const CGRect *rect_array, + DesktopVector display_origin); void ReleaseBuffers(); std::unique_ptr CreateFrame(); @@ -938,6 +940,8 @@ bool ScreenCapturerMac::RegisterRefreshAndMoveHandlers() { DisplayStreamManager* manager = display_stream_manager_; int unique_id = manager->GetUniqueId(); CGDirectDisplayID display_id = config.id; + DesktopVector display_origin = config.pixel_bounds.top_left(); + CGDisplayStreamFrameAvailableHandler handler = ^(CGDisplayStreamFrameStatus status, uint64_t display_time, IOSurfaceRef frame_surface, CGDisplayStreamUpdateRef updateRef) { @@ -959,7 +963,7 @@ bool ScreenCapturerMac::RegisterRefreshAndMoveHandlers() { if (count != 0) { // According to CGDisplayStream.h, it's safe to call // CGDisplayStreamStop() from within the callback. - ScreenRefresh(count, rects); + ScreenRefresh(count, rects, display_origin); } }; CGDisplayStreamRef display_stream = CGDisplayStreamCreate( @@ -985,16 +989,28 @@ void ScreenCapturerMac::UnregisterRefreshAndMoveHandlers() { } void ScreenCapturerMac::ScreenRefresh(CGRectCount count, - const CGRect* rect_array) { + const CGRect* rect_array, + DesktopVector display_origin) { if (screen_pixel_bounds_.is_empty()) ScreenConfigurationChanged(); + // The refresh rects are in display coordinates. We want to translate to + // framebuffer coordinates. If a specific display is being captured, then no + // change is necessary. If all displays are being captured, then we want to + // translate by the origin of the display. + DesktopVector translate_vector; + if (!current_display_) + translate_vector = display_origin; + DesktopRegion region; for (CGRectCount i = 0; i < count; ++i) { // All rects are already in physical pixel coordinates. DesktopRect rect = DesktopRect::MakeXYWH( rect_array[i].origin.x, rect_array[i].origin.y, rect_array[i].size.width, rect_array[i].size.height); + + rect.Translate(translate_vector); + region.AddRect(rect); }