Enable cropping window capturing for Win7 when Aero is disabled.

BUG=webrtc:496110
R=sergeyu@chromium.org

Review URL: https://codereview.webrtc.org/1199073002 .

Cr-Commit-Position: refs/heads/master@{#9595}
This commit is contained in:
Jiayang Liu
2015-07-16 08:49:38 -07:00
parent bd38428089
commit d848d5e74a
4 changed files with 44 additions and 29 deletions

View File

@ -119,10 +119,12 @@ class CroppingWindowCapturerWin : public CroppingWindowCapturer {
// The region from GetWindowRgn in the desktop coordinate if the region is // The region from GetWindowRgn in the desktop coordinate if the region is
// rectangular, or the rect from GetWindowRect if the region is not set. // rectangular, or the rect from GetWindowRect if the region is not set.
DesktopRect window_region_rect_; DesktopRect window_region_rect_;
AeroChecker aero_checker_;
}; };
bool CroppingWindowCapturerWin::ShouldUseScreenCapturer() { bool CroppingWindowCapturerWin::ShouldUseScreenCapturer() {
if (!rtc::IsWindows8OrLater()) if (!rtc::IsWindows8OrLater() && aero_checker_.IsAeroEnabled())
return false; return false;
// Check if the window is a translucent layered window. // Check if the window is a translucent layered window.

View File

@ -43,4 +43,27 @@ GetCroppedWindowRect(HWND window,
return true; 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 } // namespace webrtc

View File

@ -22,4 +22,19 @@ bool GetCroppedWindowRect(HWND window,
DesktopRect* cropped_rect, DesktopRect* cropped_rect,
DesktopRect* original_rect); DesktopRect* original_rect);
typedef HRESULT (WINAPI *DwmIsCompositionEnabledFunc)(BOOL* enabled);
class AeroChecker {
public:
AeroChecker();
~AeroChecker();
bool IsAeroEnabled();
private:
HMODULE dwmapi_library_;
DwmIsCompositionEnabledFunc func_;
DISALLOW_COPY_AND_ASSIGN(AeroChecker);
};
} // namespace webrtc } // namespace webrtc

View File

@ -22,8 +22,6 @@ namespace webrtc {
namespace { namespace {
typedef HRESULT (WINAPI *DwmIsCompositionEnabledFunc)(BOOL* enabled);
BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) { BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
WindowCapturer::WindowList* list = WindowCapturer::WindowList* list =
reinterpret_cast<WindowCapturer::WindowList*>(param); reinterpret_cast<WindowCapturer::WindowList*>(param);
@ -81,48 +79,25 @@ class WindowCapturerWin : public WindowCapturer {
void Capture(const DesktopRegion& region) override; void Capture(const DesktopRegion& region) override;
private: private:
bool IsAeroEnabled();
Callback* callback_; Callback* callback_;
// HWND and HDC for the currently selected window or NULL if window is not // HWND and HDC for the currently selected window or NULL if window is not
// selected. // selected.
HWND window_; HWND window_;
// dwmapi.dll is used to determine if desktop compositing is enabled.
HMODULE dwmapi_library_;
DwmIsCompositionEnabledFunc is_composition_enabled_func_;
DesktopSize previous_size_; DesktopSize previous_size_;
AeroChecker aero_checker_;
DISALLOW_COPY_AND_ASSIGN(WindowCapturerWin); DISALLOW_COPY_AND_ASSIGN(WindowCapturerWin);
}; };
WindowCapturerWin::WindowCapturerWin() WindowCapturerWin::WindowCapturerWin()
: callback_(NULL), : callback_(NULL),
window_(NULL) { window_(NULL) {
// Try to load dwmapi.dll dynamically since it is not available on XP.
dwmapi_library_ = LoadLibrary(L"dwmapi.dll");
if (dwmapi_library_) {
is_composition_enabled_func_ =
reinterpret_cast<DwmIsCompositionEnabledFunc>(
GetProcAddress(dwmapi_library_, "DwmIsCompositionEnabled"));
assert(is_composition_enabled_func_);
} else {
is_composition_enabled_func_ = NULL;
}
} }
WindowCapturerWin::~WindowCapturerWin() { WindowCapturerWin::~WindowCapturerWin() {
if (dwmapi_library_)
FreeLibrary(dwmapi_library_);
}
bool WindowCapturerWin::IsAeroEnabled() {
BOOL result = FALSE;
if (is_composition_enabled_func_)
is_composition_enabled_func_(&result);
return result != FALSE;
} }
bool WindowCapturerWin::GetWindowList(WindowList* windows) { bool WindowCapturerWin::GetWindowList(WindowList* windows) {
@ -228,7 +203,7 @@ void WindowCapturerWin::Capture(const DesktopRegion& region) {
// capturing - it somehow affects what we get from BitBlt() on the subsequent // capturing - it somehow affects what we get from BitBlt() on the subsequent
// captures. // captures.
if (!IsAeroEnabled() || !previous_size_.equals(frame->size())) { if (!aero_checker_.IsAeroEnabled() || !previous_size_.equals(frame->size())) {
result = PrintWindow(window_, mem_dc, 0); result = PrintWindow(window_, mem_dc, 0);
} }