Chromium Code Reviews| 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..2b38863fc2a0b1eafc76e5f5668e7cb6cd23288b 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> |
| #include "webrtc/base/scoped_ptr.h" |
| #include "webrtc/base/checks.h" |
| @@ -103,6 +104,13 @@ class WindowCapturerWin : public WindowCapturer { |
| AeroChecker aero_checker_; |
| + // JavaScript fucntion ChooseDesktopMedia() leads SelectWindow() and Capture() |
|
Sergey Ulanov
2016/02/20 18:47:49
nit: no need mention JavaScript here. Just say tha
GeorgeZ
2016/02/22 17:08:45
Done.
|
| + // to be called in interleaved sequence. The size of each window need to be |
| + // tracked so that when there is no size change, capture will use BitBlt() |
| + // instead of PrintWindow() when aero is enabled. keep using PrintWindow() for |
| + // each frame capture will lead to screen flickering. |
| + std::map<HWND, DesktopSize> window_size_map_; |
| + |
| RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerWin); |
| }; |
| @@ -120,6 +128,21 @@ bool WindowCapturerWin::GetWindowList(WindowList* windows) { |
| if (!EnumWindows(&WindowsEnumerationHandler, param)) |
| return false; |
| windows->swap(result); |
| + |
| + // Remove windows not in the list. |
| + std::set<HWND> ids; |
|
Sergey Ulanov
2016/02/20 18:47:49
I think it would be better to just build a new map
GeorgeZ
2016/02/22 17:08:45
Good idea.
|
| + for (const auto& item : *windows) { |
| + ids.insert(reinterpret_cast<HWND>(item.id)); |
| + } |
| + auto itr = window_size_map_.begin(); |
| + while (itr != window_size_map_.end()) { |
| + if (!ids.count(itr->first)) { |
| + itr = window_size_map_.erase(itr); |
| + } else { |
| + ++itr; |
| + } |
| + } |
| + |
| return true; |
| } |
| @@ -128,7 +151,11 @@ bool WindowCapturerWin::SelectWindow(WindowId id) { |
| if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window)) |
| return false; |
| window_ = window; |
| - previous_size_.set(0, 0); |
| + if (window_size_map_.count(window)) { |
| + previous_size_ = window_size_map_[window]; |
| + } else { |
| + previous_size_.set(0, 0); |
| + } |
| return true; |
| } |
| @@ -170,6 +197,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 +264,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())); |