Index: webrtc/modules/desktop_capture/window_capturer_win.cc |
diff --git a/webrtc/modules/desktop_capture/window_capturer_win.cc b/webrtc/modules/desktop_capture/window_capturer_win.cc |
index 54b2768aa803fe265d90a6b1f40884aafc795f88..d7b54562a91c866019439f46a1b4a6ead031f1d5 100644 |
--- a/webrtc/modules/desktop_capture/window_capturer_win.cc |
+++ b/webrtc/modules/desktop_capture/window_capturer_win.cc |
@@ -11,6 +11,7 @@ |
#include "webrtc/modules/desktop_capture/window_capturer.h" |
#include <assert.h> |
+#include <set> |
Sergey Ulanov
2016/02/22 17:49:54
don't need this.
GeorgeZ
2016/02/22 18:59:12
Done.
|
#include "webrtc/base/scoped_ptr.h" |
#include "webrtc/base/checks.h" |
@@ -103,6 +104,10 @@ class WindowCapturerWin : public WindowCapturer { |
AeroChecker aero_checker_; |
+ // This map is used to avoid flickering for the case when SelectWindow() calls |
+ // are interleaved with Capture() calls. |
+ std::map<HWND, DesktopSize> window_size_map_; |
+ |
RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerWin); |
}; |
@@ -120,6 +125,14 @@ bool WindowCapturerWin::GetWindowList(WindowList* windows) { |
if (!EnumWindows(&WindowsEnumerationHandler, param)) |
return false; |
windows->swap(result); |
+ |
+ std::map<HWND, DesktopSize> new_map; |
+ for (const auto& item : *windows) { |
+ HWND hwnd = reinterpret_cast<HWND>(item.id); |
+ new_map[hwnd] = window_size_map_[hwnd]; |
+ } |
+ window_size_map_.swap(new_map); |
+ |
return true; |
} |
@@ -128,7 +141,9 @@ bool WindowCapturerWin::SelectWindow(WindowId id) { |
if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window)) |
return false; |
window_ = window; |
- previous_size_.set(0, 0); |
+ // When a window is not in the map, window_size_map_[window] will create an |
+ // item with DesktopSize (0, 0). |
+ previous_size_ = window_size_map_[window]; |
Sergey Ulanov
2016/02/22 17:49:54
Note that this also has side-effect of inserting a
GeorgeZ
2016/02/22 18:59:12
Acknowledged.
|
return true; |
} |
@@ -170,6 +185,7 @@ void WindowCapturerWin::Capture(const DesktopRegion& region) { |
memset(frame->data(), 0, frame->stride() * frame->size().height()); |
previous_size_ = frame->size(); |
+ window_size_map_[window_] = previous_size_; |
callback_->OnCaptureCompleted(frame); |
return; |
} |
@@ -236,6 +252,7 @@ void WindowCapturerWin::Capture(const DesktopRegion& region) { |
ReleaseDC(window_, window_dc); |
previous_size_ = frame->size(); |
+ window_size_map_[window_] = previous_size_; |
frame->mutable_updated_region()->SetRect( |
DesktopRect::MakeSize(frame->size())); |