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}
76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "webrtc/modules/desktop_capture/win/window_capture_utils.h"
|
|
|
|
#include "webrtc/rtc_base/win32.h"
|
|
|
|
namespace webrtc {
|
|
|
|
bool
|
|
GetCroppedWindowRect(HWND window,
|
|
DesktopRect* cropped_rect,
|
|
DesktopRect* original_rect) {
|
|
RECT rect;
|
|
if (!GetWindowRect(window, &rect)) {
|
|
return false;
|
|
}
|
|
WINDOWPLACEMENT window_placement;
|
|
window_placement.length = sizeof(window_placement);
|
|
if (!GetWindowPlacement(window, &window_placement)) {
|
|
return false;
|
|
}
|
|
|
|
*original_rect = DesktopRect::MakeLTRB(
|
|
rect.left, rect.top, rect.right, rect.bottom);
|
|
|
|
// 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(
|
|
rect.left + border.width(),
|
|
rect.top,
|
|
rect.right - border.width(),
|
|
rect.bottom - border.height());
|
|
} else {
|
|
*cropped_rect = *original_rect;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
AeroChecker::AeroChecker() : dwmapi_library_(nullptr), func_(nullptr) {
|
|
// Try to load dwmapi.dll dynamically since it is not available on XP.
|
|
dwmapi_library_ = LoadLibrary(L"dwmapi.dll");
|
|
if (dwmapi_library_) {
|
|
func_ = reinterpret_cast<DwmIsCompositionEnabledFunc>(
|
|
GetProcAddress(dwmapi_library_, "DwmIsCompositionEnabled"));
|
|
}
|
|
}
|
|
|
|
AeroChecker::~AeroChecker() {
|
|
if (dwmapi_library_) {
|
|
FreeLibrary(dwmapi_library_);
|
|
}
|
|
}
|
|
|
|
bool AeroChecker::IsAeroEnabled() {
|
|
BOOL result = FALSE;
|
|
if (func_) {
|
|
func_(&result);
|
|
}
|
|
return result != FALSE;
|
|
}
|
|
|
|
} // namespace webrtc
|