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 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 Callback* callback_; | 96 Callback* callback_; |
97 | 97 |
98 // HWND and HDC for the currently selected window or NULL if window is not | 98 // HWND and HDC for the currently selected window or NULL if window is not |
99 // selected. | 99 // selected. |
100 HWND window_; | 100 HWND window_; |
101 | 101 |
102 DesktopSize previous_size_; | 102 DesktopSize previous_size_; |
103 | 103 |
104 AeroChecker aero_checker_; | 104 AeroChecker aero_checker_; |
105 | 105 |
106 std::map<HWND, DesktopSize> window_size_map_; | |
Sergey Ulanov
2016/02/18 18:50:00
Add a comment to explain why we need to cache the
GeorgeZ
2016/02/19 23:34:48
Done.
| |
107 | |
106 RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerWin); | 108 RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerWin); |
107 }; | 109 }; |
108 | 110 |
109 WindowCapturerWin::WindowCapturerWin() | 111 WindowCapturerWin::WindowCapturerWin() |
110 : callback_(NULL), | 112 : callback_(NULL), |
111 window_(NULL) { | 113 window_(NULL) { |
112 } | 114 } |
113 | 115 |
114 WindowCapturerWin::~WindowCapturerWin() { | 116 WindowCapturerWin::~WindowCapturerWin() { |
115 } | 117 } |
116 | 118 |
117 bool WindowCapturerWin::GetWindowList(WindowList* windows) { | 119 bool WindowCapturerWin::GetWindowList(WindowList* windows) { |
118 WindowList result; | 120 WindowList result; |
119 LPARAM param = reinterpret_cast<LPARAM>(&result); | 121 LPARAM param = reinterpret_cast<LPARAM>(&result); |
120 if (!EnumWindows(&WindowsEnumerationHandler, param)) | 122 if (!EnumWindows(&WindowsEnumerationHandler, param)) |
121 return false; | 123 return false; |
122 windows->swap(result); | 124 windows->swap(result); |
Sergey Ulanov
2016/02/18 18:50:00
Currently windows never get removed from window_si
GeorgeZ
2016/02/19 23:34:48
Done.
| |
123 return true; | 125 return true; |
124 } | 126 } |
125 | 127 |
126 bool WindowCapturerWin::SelectWindow(WindowId id) { | 128 bool WindowCapturerWin::SelectWindow(WindowId id) { |
127 HWND window = reinterpret_cast<HWND>(id); | 129 HWND window = reinterpret_cast<HWND>(id); |
128 if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window)) | 130 if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window)) |
129 return false; | 131 return false; |
130 window_ = window; | 132 window_ = window; |
131 previous_size_.set(0, 0); | 133 if (window_size_map_.count(window)) { |
134 previous_size_ = window_size_map_[window]; | |
135 } else { | |
136 previous_size_.set(0, 0); | |
137 } | |
132 return true; | 138 return true; |
133 } | 139 } |
134 | 140 |
135 bool WindowCapturerWin::BringSelectedWindowToFront() { | 141 bool WindowCapturerWin::BringSelectedWindowToFront() { |
136 if (!window_) | 142 if (!window_) |
137 return false; | 143 return false; |
138 | 144 |
139 if (!IsWindow(window_) || !IsWindowVisible(window_) || IsIconic(window_)) | 145 if (!IsWindow(window_) || !IsWindowVisible(window_) || IsIconic(window_)) |
140 return false; | 146 return false; |
141 | 147 |
(...skipping 21 matching lines...) Expand all Loading... | |
163 } | 169 } |
164 | 170 |
165 // Return a 1x1 black frame if the window is minimized or invisible, to match | 171 // 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 | 172 // behavior on mace. Window can be temporarily invisible during the |
167 // transition of full screen mode on/off. | 173 // transition of full screen mode on/off. |
168 if (IsIconic(window_) || !IsWindowVisible(window_)) { | 174 if (IsIconic(window_) || !IsWindowVisible(window_)) { |
169 BasicDesktopFrame* frame = new BasicDesktopFrame(DesktopSize(1, 1)); | 175 BasicDesktopFrame* frame = new BasicDesktopFrame(DesktopSize(1, 1)); |
170 memset(frame->data(), 0, frame->stride() * frame->size().height()); | 176 memset(frame->data(), 0, frame->stride() * frame->size().height()); |
171 | 177 |
172 previous_size_ = frame->size(); | 178 previous_size_ = frame->size(); |
179 window_size_map_[window_] = previous_size_; | |
173 callback_->OnCaptureCompleted(frame); | 180 callback_->OnCaptureCompleted(frame); |
174 return; | 181 return; |
175 } | 182 } |
176 | 183 |
177 DesktopRect original_rect; | 184 DesktopRect original_rect; |
178 DesktopRect cropped_rect; | 185 DesktopRect cropped_rect; |
179 if (!GetCroppedWindowRect(window_, &cropped_rect, &original_rect)) { | 186 if (!GetCroppedWindowRect(window_, &cropped_rect, &original_rect)) { |
180 LOG(LS_WARNING) << "Failed to get window info: " << GetLastError(); | 187 LOG(LS_WARNING) << "Failed to get window info: " << GetLastError(); |
181 callback_->OnCaptureCompleted(NULL); | 188 callback_->OnCaptureCompleted(NULL); |
182 return; | 189 return; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 cropped_rect.left() - original_rect.left(), | 236 cropped_rect.left() - original_rect.left(), |
230 cropped_rect.top() - original_rect.top(), | 237 cropped_rect.top() - original_rect.top(), |
231 SRCCOPY); | 238 SRCCOPY); |
232 } | 239 } |
233 | 240 |
234 SelectObject(mem_dc, previous_object); | 241 SelectObject(mem_dc, previous_object); |
235 DeleteDC(mem_dc); | 242 DeleteDC(mem_dc); |
236 ReleaseDC(window_, window_dc); | 243 ReleaseDC(window_, window_dc); |
237 | 244 |
238 previous_size_ = frame->size(); | 245 previous_size_ = frame->size(); |
246 window_size_map_[window_] = previous_size_; | |
239 | 247 |
240 frame->mutable_updated_region()->SetRect( | 248 frame->mutable_updated_region()->SetRect( |
241 DesktopRect::MakeSize(frame->size())); | 249 DesktopRect::MakeSize(frame->size())); |
242 | 250 |
243 if (!result) { | 251 if (!result) { |
244 LOG(LS_ERROR) << "Both PrintWindow() and BitBlt() failed."; | 252 LOG(LS_ERROR) << "Both PrintWindow() and BitBlt() failed."; |
245 frame.reset(); | 253 frame.reset(); |
246 } | 254 } |
247 | 255 |
248 callback_->OnCaptureCompleted(frame.release()); | 256 callback_->OnCaptureCompleted(frame.release()); |
249 } | 257 } |
250 | 258 |
251 } // namespace | 259 } // namespace |
252 | 260 |
253 // static | 261 // static |
254 WindowCapturer* WindowCapturer::Create(const DesktopCaptureOptions& options) { | 262 WindowCapturer* WindowCapturer::Create(const DesktopCaptureOptions& options) { |
255 return new WindowCapturerWin(); | 263 return new WindowCapturerWin(); |
256 } | 264 } |
257 | 265 |
258 } // namespace webrtc | 266 } // namespace webrtc |
OLD | NEW |