From 4a494ffd1255561ee9c17d3d2b3646f8c849e784 Mon Sep 17 00:00:00 2001 From: braveyao Date: Thu, 6 Jul 2017 20:20:27 -0700 Subject: [PATCH] desktop_capture: crop border in window_capture on Win8/10 On Windows8/10, we prefer cropping desired window out from a whole screen capture due to some reasons. The problem is Win10 has an invisible border around the window. If we leave the border, it will expose background a bit. This cl is about to always remove the border of desired window on Win8/10. This will help a lot to capturing still windows during window sharing. This cl still can't handle the background exposure issue when you move the target window around during capturing. More investigation is needed. BUG=chromium:737278 Review-Url: https://codereview.webrtc.org/2973853002 Cr-Commit-Position: refs/heads/master@{#18921} --- .../modules/desktop_capture/win/window_capture_utils.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/webrtc/modules/desktop_capture/win/window_capture_utils.cc b/webrtc/modules/desktop_capture/win/window_capture_utils.cc index 83922ea7f8..41c48224e8 100644 --- a/webrtc/modules/desktop_capture/win/window_capture_utils.cc +++ b/webrtc/modules/desktop_capture/win/window_capture_utils.cc @@ -10,6 +10,8 @@ #include "webrtc/modules/desktop_capture/win/window_capture_utils.h" +#include "webrtc/rtc_base/win32.h" + namespace webrtc { bool @@ -29,7 +31,11 @@ GetCroppedWindowRect(HWND window, *original_rect = DesktopRect::MakeLTRB( rect.left, rect.top, rect.right, rect.bottom); - if (window_placement.showCmd == SW_SHOWMAXIMIZED) { + // After Windows8, transparent borders will be added by OS at + // left/bottom/right sides of a window. If the cropped window + // doesn't remove these borders, the background will be exposed a bit. + if (rtc::IsWindows8OrLater() || + window_placement.showCmd == SW_SHOWMAXIMIZED) { DesktopSize border = DesktopSize(GetSystemMetrics(SM_CXSIZEFRAME), GetSystemMetrics(SM_CYSIZEFRAME)); *cropped_rect = DesktopRect::MakeLTRB(