OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/desktop_capture/window_capturer.h" | 11 #include "webrtc/modules/desktop_capture/window_capturer.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <set> | |
Sergey Ulanov
2016/02/22 17:49:54
don't need this.
GeorgeZ
2016/02/22 18:59:12
Done.
| |
14 | 15 |
15 #include "webrtc/base/scoped_ptr.h" | 16 #include "webrtc/base/scoped_ptr.h" |
16 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/win32.h" | 18 #include "webrtc/base/win32.h" |
18 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" | 19 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
19 #include "webrtc/modules/desktop_capture/win/window_capture_utils.h" | 20 #include "webrtc/modules/desktop_capture/win/window_capture_utils.h" |
20 #include "webrtc/system_wrappers/include/logging.h" | 21 #include "webrtc/system_wrappers/include/logging.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 | 24 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 Callback* callback_; | 97 Callback* callback_; |
97 | 98 |
98 // HWND and HDC for the currently selected window or NULL if window is not | 99 // HWND and HDC for the currently selected window or NULL if window is not |
99 // selected. | 100 // selected. |
100 HWND window_; | 101 HWND window_; |
101 | 102 |
102 DesktopSize previous_size_; | 103 DesktopSize previous_size_; |
103 | 104 |
104 AeroChecker aero_checker_; | 105 AeroChecker aero_checker_; |
105 | 106 |
107 // This map is used to avoid flickering for the case when SelectWindow() calls | |
108 // are interleaved with Capture() calls. | |
109 std::map<HWND, DesktopSize> window_size_map_; | |
110 | |
106 RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerWin); | 111 RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerWin); |
107 }; | 112 }; |
108 | 113 |
109 WindowCapturerWin::WindowCapturerWin() | 114 WindowCapturerWin::WindowCapturerWin() |
110 : callback_(NULL), | 115 : callback_(NULL), |
111 window_(NULL) { | 116 window_(NULL) { |
112 } | 117 } |
113 | 118 |
114 WindowCapturerWin::~WindowCapturerWin() { | 119 WindowCapturerWin::~WindowCapturerWin() { |
115 } | 120 } |
116 | 121 |
117 bool WindowCapturerWin::GetWindowList(WindowList* windows) { | 122 bool WindowCapturerWin::GetWindowList(WindowList* windows) { |
118 WindowList result; | 123 WindowList result; |
119 LPARAM param = reinterpret_cast<LPARAM>(&result); | 124 LPARAM param = reinterpret_cast<LPARAM>(&result); |
120 if (!EnumWindows(&WindowsEnumerationHandler, param)) | 125 if (!EnumWindows(&WindowsEnumerationHandler, param)) |
121 return false; | 126 return false; |
122 windows->swap(result); | 127 windows->swap(result); |
128 | |
129 std::map<HWND, DesktopSize> new_map; | |
130 for (const auto& item : *windows) { | |
131 HWND hwnd = reinterpret_cast<HWND>(item.id); | |
132 new_map[hwnd] = window_size_map_[hwnd]; | |
133 } | |
134 window_size_map_.swap(new_map); | |
135 | |
123 return true; | 136 return true; |
124 } | 137 } |
125 | 138 |
126 bool WindowCapturerWin::SelectWindow(WindowId id) { | 139 bool WindowCapturerWin::SelectWindow(WindowId id) { |
127 HWND window = reinterpret_cast<HWND>(id); | 140 HWND window = reinterpret_cast<HWND>(id); |
128 if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window)) | 141 if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window)) |
129 return false; | 142 return false; |
130 window_ = window; | 143 window_ = window; |
131 previous_size_.set(0, 0); | 144 // When a window is not in the map, window_size_map_[window] will create an |
145 // item with DesktopSize (0, 0). | |
146 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.
| |
132 return true; | 147 return true; |
133 } | 148 } |
134 | 149 |
135 bool WindowCapturerWin::BringSelectedWindowToFront() { | 150 bool WindowCapturerWin::BringSelectedWindowToFront() { |
136 if (!window_) | 151 if (!window_) |
137 return false; | 152 return false; |
138 | 153 |
139 if (!IsWindow(window_) || !IsWindowVisible(window_) || IsIconic(window_)) | 154 if (!IsWindow(window_) || !IsWindowVisible(window_) || IsIconic(window_)) |
140 return false; | 155 return false; |
141 | 156 |
(...skipping 21 matching lines...) Expand all Loading... | |
163 } | 178 } |
164 | 179 |
165 // Return a 1x1 black frame if the window is minimized or invisible, to match | 180 // Return a 1x1 black frame if the window is minimized or invisible, to match |
166 // behavior on mace. Window can be temporarily invisible during the | 181 // behavior on mace. Window can be temporarily invisible during the |
167 // transition of full screen mode on/off. | 182 // transition of full screen mode on/off. |
168 if (IsIconic(window_) || !IsWindowVisible(window_)) { | 183 if (IsIconic(window_) || !IsWindowVisible(window_)) { |
169 BasicDesktopFrame* frame = new BasicDesktopFrame(DesktopSize(1, 1)); | 184 BasicDesktopFrame* frame = new BasicDesktopFrame(DesktopSize(1, 1)); |
170 memset(frame->data(), 0, frame->stride() * frame->size().height()); | 185 memset(frame->data(), 0, frame->stride() * frame->size().height()); |
171 | 186 |
172 previous_size_ = frame->size(); | 187 previous_size_ = frame->size(); |
188 window_size_map_[window_] = previous_size_; | |
173 callback_->OnCaptureCompleted(frame); | 189 callback_->OnCaptureCompleted(frame); |
174 return; | 190 return; |
175 } | 191 } |
176 | 192 |
177 DesktopRect original_rect; | 193 DesktopRect original_rect; |
178 DesktopRect cropped_rect; | 194 DesktopRect cropped_rect; |
179 if (!GetCroppedWindowRect(window_, &cropped_rect, &original_rect)) { | 195 if (!GetCroppedWindowRect(window_, &cropped_rect, &original_rect)) { |
180 LOG(LS_WARNING) << "Failed to get window info: " << GetLastError(); | 196 LOG(LS_WARNING) << "Failed to get window info: " << GetLastError(); |
181 callback_->OnCaptureCompleted(NULL); | 197 callback_->OnCaptureCompleted(NULL); |
182 return; | 198 return; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 cropped_rect.left() - original_rect.left(), | 245 cropped_rect.left() - original_rect.left(), |
230 cropped_rect.top() - original_rect.top(), | 246 cropped_rect.top() - original_rect.top(), |
231 SRCCOPY); | 247 SRCCOPY); |
232 } | 248 } |
233 | 249 |
234 SelectObject(mem_dc, previous_object); | 250 SelectObject(mem_dc, previous_object); |
235 DeleteDC(mem_dc); | 251 DeleteDC(mem_dc); |
236 ReleaseDC(window_, window_dc); | 252 ReleaseDC(window_, window_dc); |
237 | 253 |
238 previous_size_ = frame->size(); | 254 previous_size_ = frame->size(); |
255 window_size_map_[window_] = previous_size_; | |
239 | 256 |
240 frame->mutable_updated_region()->SetRect( | 257 frame->mutable_updated_region()->SetRect( |
241 DesktopRect::MakeSize(frame->size())); | 258 DesktopRect::MakeSize(frame->size())); |
242 | 259 |
243 if (!result) { | 260 if (!result) { |
244 LOG(LS_ERROR) << "Both PrintWindow() and BitBlt() failed."; | 261 LOG(LS_ERROR) << "Both PrintWindow() and BitBlt() failed."; |
245 frame.reset(); | 262 frame.reset(); |
246 } | 263 } |
247 | 264 |
248 callback_->OnCaptureCompleted(frame.release()); | 265 callback_->OnCaptureCompleted(frame.release()); |
249 } | 266 } |
250 | 267 |
251 } // namespace | 268 } // namespace |
252 | 269 |
253 // static | 270 // static |
254 WindowCapturer* WindowCapturer::Create(const DesktopCaptureOptions& options) { | 271 WindowCapturer* WindowCapturer::Create(const DesktopCaptureOptions& options) { |
255 return new WindowCapturerWin(); | 272 return new WindowCapturerWin(); |
256 } | 273 } |
257 | 274 |
258 } // namespace webrtc | 275 } // namespace webrtc |
OLD | NEW |