From 483c1b2100beac59dfc90b471f1418c364ca2172 Mon Sep 17 00:00:00 2001 From: braveyao Date: Thu, 29 Nov 2018 16:04:45 -0800 Subject: [PATCH] desktop_capture: apply scale to cursor relative positon on Mac only With Retina monitor connected, OSX and Win10 work differently. OSX will use logical pixel to cursor location and physical pixel to cursor image. And Win10 will always use logical coordinate. So the processing in this patchset should only be applied to OSX only. Bug: chromium:909784 Change-Id: I038e7769d101fbc3efe08b4739204d523255b609 Reviewed-on: https://webrtc-review.googlesource.com/c/112523 Reviewed-by: Jamie Walch Commit-Queue: Brave Yao Cr-Commit-Position: refs/heads/master@{#25850} --- modules/desktop_capture/desktop_and_cursor_composer.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/desktop_capture/desktop_and_cursor_composer.cc b/modules/desktop_capture/desktop_and_cursor_composer.cc index b50be5b82f..fae34b453a 100644 --- a/modules/desktop_capture/desktop_and_cursor_composer.cc +++ b/modules/desktop_capture/desktop_and_cursor_composer.cc @@ -171,11 +171,19 @@ void DesktopAndCursorComposer::OnCaptureResult( if (frame && cursor_) { if (frame->rect().Contains(cursor_position_) && !desktop_capturer_->IsOccluded(cursor_position_)) { - const float scale = frame->scale_factor(); DesktopVector relative_position = cursor_position_.subtract(frame->top_left()); +#if defined(WEBRTC_MAC) + // On OSX, the logical(DIP) and physical coordinates are used mixingly. + // For example, the captured cursor has its size in physical pixels(2x) + // and location in logical(DIP) pixels on Retina monitor. This will cause + // problem when the desktop is mixed with Retina and non-Retina monitors. + // So we use DIP pixel for all location info and compensate with the scale + // factor of current frame to the |relative_position|. + const float scale = frame->scale_factor(); relative_position.set(relative_position.x() * scale, relative_position.y() * scale); +#endif frame = absl::make_unique( std::move(frame), *cursor_, relative_position); }