Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc

Issue 2704943002: Use FallbackDesktopCapturerWrapper in ScreenCapturerWinMagnifier (Closed)
Patch Set: Update comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2a686c4384c65581be035130b21938efb3eb8b1e 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_) {
+ 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_PERMANENT, nullptr);
return;
}
@@ -131,17 +118,12 @@ bool ScreenCapturerWinMagnifier::GetSourceList(SourceList* sources) {
}
bool ScreenCapturerWinMagnifier::SelectSource(SourceId id) {
- bool valid = IsScreenValid(id, &current_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, &current_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 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
« no previous file with comments | « webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698