Chromium Code Reviews| Index: webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
| diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
| index 96348ca49455bc5f1b0d1ab4b7bf75488f0bffce..2d134c6669908bcbf2653165d70b11069a1716a1 100644 |
| --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
| +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
| @@ -35,10 +35,7 @@ static LPCTSTR kMagnifierWindowName = L"MagnifierWindow"; |
| Atomic32 ScreenCapturerWinMagnifier::tls_index_(TLS_OUT_OF_INDEXES); |
| -ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier( |
| - std::unique_ptr<DesktopCapturer> fallback_capturer) |
| - : fallback_capturer_(std::move(fallback_capturer)) {} |
| - |
| +ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier() = default; |
| ScreenCapturerWinMagnifier::~ScreenCapturerWinMagnifier() { |
| // DestroyWindow must be called before MagUninitialize. magnifier_window_ is |
| // destroyed automatically when host_window_ is destroyed. |
| @@ -61,9 +58,7 @@ void ScreenCapturerWinMagnifier::Start(Callback* callback) { |
| callback_ = callback; |
| if (!InitializeMagnifier()) { |
| - LOG_F(LS_WARNING) << "Switching to fallback screen capturer becuase " |
| - "magnifier initialization failed."; |
| - StartFallbackCapturer(); |
| + LOG_F(LS_WARNING) << "Magnifier initialization failed."; |
| } |
| } |
| @@ -73,16 +68,10 @@ void ScreenCapturerWinMagnifier::SetSharedMemoryFactory( |
| } |
| void ScreenCapturerWinMagnifier::CaptureFrame() { |
| - if (!magnifier_initialized_ || |
| - !magnifier_capture_succeeded_ || |
| - GetSystemMetrics(SM_CMONITORS) != 1) { |
| - // Do not try to use the magnifier if it failed before and in multi-screen |
| - // setup (where the API crashes sometimes). |
| - LOG_F(LS_WARNING) << "Switching to the fallback screen capturer because " |
| - "initialization or last capture attempt failed, or " |
| - "execute on multi-screen system."; |
| - StartFallbackCapturer(); |
| - fallback_capturer_->CaptureFrame(); |
| + RTC_DCHECK(callback_); |
| + if (!magnifier_initialized_) { |
|
Sergey Ulanov
2017/02/21 20:49:31
Previously the capturer was always falling back to
Hzj_jie
2017/02/21 23:27:33
Done.
|
| + LOG_F(LS_WARNING) << "Magnifier initialization failed."; |
| + callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
| return; |
| } |
| @@ -108,10 +97,8 @@ void ScreenCapturerWinMagnifier::CaptureFrame() { |
| // CaptureImage may fail in some situations, e.g. windows8 metro mode. So |
| // defer to the fallback capturer if magnifier capturer did not work. |
| if (!CaptureImage(rect)) { |
| - LOG_F(LS_WARNING) << "Switching to the fallback screen capturer because " |
| - "last capture attempt failed."; |
| - StartFallbackCapturer(); |
| - fallback_capturer_->CaptureFrame(); |
| + LOG_F(LS_WARNING) << "Magnifier capturer failed to capture a frame."; |
| + callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
| return; |
| } |
| @@ -131,17 +118,12 @@ bool ScreenCapturerWinMagnifier::GetSourceList(SourceList* sources) { |
| } |
| bool ScreenCapturerWinMagnifier::SelectSource(SourceId id) { |
| - bool valid = IsScreenValid(id, ¤t_device_key_); |
| - |
| - // Set current_screen_id_ even if the fallback capturer is being used, so we |
| - // can switch back to the magnifier when possible. |
| - if (valid) |
| + if (IsScreenValid(id, ¤t_device_key_)) { |
| current_screen_id_ = id; |
| + return true; |
| + } |
| - if (fallback_capturer_started_) |
| - fallback_capturer_->SelectSource(id); |
| - |
| - return valid; |
| + return false; |
| } |
| void ScreenCapturerWinMagnifier::SetExcludedWindow(WindowId excluded_window) { |
| @@ -210,6 +192,15 @@ BOOL ScreenCapturerWinMagnifier::OnMagImageScalingCallback( |
| // include and function calls instead of a dynamical loaded library. |
| bool ScreenCapturerWinMagnifier::InitializeMagnifier() { |
| RTC_DCHECK(!magnifier_initialized_); |
| + |
| + if (GetSystemMetrics(SM_CMONITORS) != 1) { |
| + // Do not try to use the magnifier if it failed before and in multi-screen |
| + // setup (where the API crashes sometimes). |
| + LOG_F(LS_WARNING) << "Magnifier capturer cannot work on multi-screen " |
| + "system."; |
| + return false; |
| + } |
| + |
| desktop_dc_ = GetDC(nullptr); |
| mag_lib_handle_ = LoadLibrary(L"Magnification.dll"); |
| @@ -376,14 +367,4 @@ void ScreenCapturerWinMagnifier::CreateCurrentFrameIfNecessary( |
| } |
| } |
| -void ScreenCapturerWinMagnifier::StartFallbackCapturer() { |
| - RTC_DCHECK(fallback_capturer_); |
| - if (!fallback_capturer_started_) { |
| - fallback_capturer_started_ = true; |
| - |
| - fallback_capturer_->Start(callback_); |
| - fallback_capturer_->SelectSource(current_screen_id_); |
| - } |
| -} |
| - |
| } // namespace webrtc |