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 7fdc8eb43fcbde80e735ae1bce3b03fb0fd0dae9..1c41b5f8a7011e41b3176d0cee061310e0e96d80 100644 |
| --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
| +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
| @@ -10,10 +10,9 @@ |
| #include "webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h" |
| -#include <assert.h> |
| - |
| #include <utility> |
| +#include "webrtc/base/checks.h" |
| #include "webrtc/base/timeutils.h" |
| #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
| #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| @@ -34,8 +33,7 @@ static LPCTSTR kMagnifierHostClass = L"ScreenCapturerWinMagnifierHost"; |
| static LPCTSTR kHostWindowName = L"MagnifierHost"; |
| static LPCTSTR kMagnifierWindowClass = L"Magnifier"; |
| static LPCTSTR kMagnifierWindowName = L"MagnifierWindow"; |
| - |
| -Atomic32 ScreenCapturerWinMagnifier::tls_index_(TLS_OUT_OF_INDEXES); |
| +thread_local static ScreenCapturerWinMagnifier* kCurrent; |
|
Sergey Ulanov
2016/09/19 20:53:18
- thread_local is not listed on chromium-cpp.appsp
Hzj_jie
2016/09/19 22:05:23
Emmm, a Google internal mail thread shows thread_l
Sergey Ulanov
2016/09/19 22:21:25
__declspec(thread) seems used in some third-party
|
| ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier( |
| std::unique_ptr<ScreenCapturer> fallback_capturer) |
| @@ -62,7 +60,9 @@ void ScreenCapturerWinMagnifier::Start(Callback* callback) { |
| assert(callback); |
| callback_ = callback; |
| - InitializeMagnifier(); |
| + if (!InitializeMagnifier()) { |
| + StartFallbackCapturer(); |
| + } |
| } |
| void ScreenCapturerWinMagnifier::SetSharedMemoryFactory( |
| @@ -75,14 +75,6 @@ void ScreenCapturerWinMagnifier::Capture(const DesktopRegion& region) { |
| queue_.MoveToNextFrame(); |
| - // Request that the system not power-down the system, or the display hardware. |
| - if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { |
| - if (!set_thread_execution_state_failed_) { |
| - set_thread_execution_state_failed_ = true; |
| - LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " |
| - << GetLastError(); |
| - } |
| - } |
| // Switch to the desktop receiving user input if different from the current |
| // one. |
| std::unique_ptr<Desktop> input_desktop(Desktop::GetInputDesktop()); |
| @@ -101,8 +93,7 @@ void ScreenCapturerWinMagnifier::Capture(const DesktopRegion& region) { |
| // Do not try to use the magnifier if it failed before and in multi-screen |
| // setup (where the API crashes sometimes). |
| - if (magnifier_initialized_ && (GetSystemMetrics(SM_CMONITORS) == 1) && |
| - magnifier_capture_succeeded_) { |
| + if (magnifier_initialized_ && magnifier_capture_succeeded_) { |
| DesktopRect rect = GetScreenRect(current_screen_id_, current_device_key_); |
| CreateCurrentFrameIfNecessary(rect.size()); |
| @@ -120,6 +111,7 @@ void ScreenCapturerWinMagnifier::Capture(const DesktopRegion& region) { |
| const DesktopFrame* current_frame = queue_.current_frame(); |
| const DesktopFrame* last_frame = queue_.previous_frame(); |
| + DesktopRegion updated_region; |
| if (last_frame && last_frame->size().equals(current_frame->size())) { |
| // Make sure the differencer is set up correctly for these previous and |
| // current screens. |
| @@ -133,24 +125,17 @@ void ScreenCapturerWinMagnifier::Capture(const DesktopRegion& region) { |
| } |
| // Calculate difference between the two last captured frames. |
| - DesktopRegion region; |
| differ_->CalcDirtyRegion( |
|
Sergey Ulanov
2016/09/19 20:53:18
Do we need to keep the differ here?
Hzj_jie
2016/09/19 22:05:23
No, but all the differs will be removed in https:/
|
| - last_frame->data(), current_frame->data(), ®ion); |
| - helper_.InvalidateRegion(region); |
| + last_frame->data(), current_frame->data(), &updated_region); |
| } else { |
| - // No previous frame is available, or the screen is resized. Invalidate the |
| - // whole screen. |
| - helper_.InvalidateScreen(current_frame->size()); |
| + updated_region.SetRect(DesktopRect::MakeSize(current_frame->size())); |
| } |
| - helper_.set_size_most_recent(current_frame->size()); |
| - |
| // Emit the current frame. |
| std::unique_ptr<DesktopFrame> frame = queue_.current_frame()->Share(); |
| frame->set_dpi(DesktopVector(GetDeviceCaps(desktop_dc_, LOGPIXELSX), |
| GetDeviceCaps(desktop_dc_, LOGPIXELSY))); |
| - frame->mutable_updated_region()->Clear(); |
| - helper_.TakeInvalidRegion(frame->mutable_updated_region()); |
| + frame->mutable_updated_region()->Swap(&updated_region); |
| frame->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) / |
| rtc::kNumNanosecsPerMillisec); |
| callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); |
| @@ -200,6 +185,7 @@ bool ScreenCapturerWinMagnifier::CaptureImage(const DesktopRect& rect) { |
| RECT native_rect = {rect.left(), rect.top(), rect.right(), rect.bottom()}; |
| + kCurrent = this; |
| // OnCaptured will be called via OnMagImageScalingCallback and fill in the |
| // frame before set_window_source_func_ returns. |
| result = set_window_source_func_(magnifier_window_, native_rect); |
| @@ -223,19 +209,18 @@ BOOL ScreenCapturerWinMagnifier::OnMagImageScalingCallback( |
| RECT unclipped, |
| RECT clipped, |
| HRGN dirty) { |
| - assert(tls_index_.Value() != static_cast<int32_t>(TLS_OUT_OF_INDEXES)); |
| - |
| - ScreenCapturerWinMagnifier* owner = |
| - reinterpret_cast<ScreenCapturerWinMagnifier*>( |
| - TlsGetValue(tls_index_.Value())); |
| - |
| - owner->OnCaptured(srcdata, srcheader); |
| - |
| + RTC_DCHECK(kCurrent != nullptr); |
|
Sergey Ulanov
2016/09/19 20:53:18
Please replace all asserts with RTC_DCHECK
Hzj_jie
2016/09/19 22:05:23
Done.
|
| + kCurrent->OnCaptured(srcdata, srcheader); |
| return TRUE; |
| } |
| bool ScreenCapturerWinMagnifier::InitializeMagnifier() { |
| assert(!magnifier_initialized_); |
| + if (GetSystemMetrics(SM_CMONITORS) != 1) { |
|
Sergey Ulanov
2016/09/19 20:53:18
I think it's better to keep this check in ScreenCa
Hzj_jie
2016/09/19 22:05:23
Good point. Updated.
|
| + // Do not try to use the magnifier if it failed before and in multi-screen |
| + // setup (where the API crashes sometimes). |
| + return false; |
| + } |
| desktop_dc_ = GetDC(nullptr); |
| @@ -345,17 +330,6 @@ bool ScreenCapturerWinMagnifier::InitializeMagnifier() { |
| } |
| } |
| - if (tls_index_.Value() == static_cast<int32_t>(TLS_OUT_OF_INDEXES)) { |
| - // More than one threads may get here at the same time, but only one will |
| - // write to tls_index_ using CompareExchange. |
| - DWORD new_tls_index = TlsAlloc(); |
| - if (!tls_index_.CompareExchange(new_tls_index, TLS_OUT_OF_INDEXES)) |
| - TlsFree(new_tls_index); |
| - } |
| - |
| - assert(tls_index_.Value() != static_cast<int32_t>(TLS_OUT_OF_INDEXES)); |
| - TlsSetValue(tls_index_.Value(), this); |
| - |
| magnifier_initialized_ = true; |
| return true; |
| } |