OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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/win/screen_capturer_win_gdi.h" | 11 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include <utility> | |
16 | |
15 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 17 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
16 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 18 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
17 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" | 19 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
18 #include "webrtc/modules/desktop_capture/desktop_region.h" | 20 #include "webrtc/modules/desktop_capture/desktop_region.h" |
19 #include "webrtc/modules/desktop_capture/differ.h" | 21 #include "webrtc/modules/desktop_capture/differ.h" |
20 #include "webrtc/modules/desktop_capture/mouse_cursor.h" | 22 #include "webrtc/modules/desktop_capture/mouse_cursor.h" |
21 #include "webrtc/modules/desktop_capture/win/cursor.h" | 23 #include "webrtc/modules/desktop_capture/win/cursor.h" |
22 #include "webrtc/modules/desktop_capture/win/desktop.h" | 24 #include "webrtc/modules/desktop_capture/win/desktop.h" |
23 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" | 25 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" |
24 #include "webrtc/system_wrappers/include/logging.h" | 26 #include "webrtc/system_wrappers/include/logging.h" |
25 #include "webrtc/system_wrappers/include/tick_util.h" | 27 #include "webrtc/system_wrappers/include/tick_util.h" |
26 | 28 |
27 namespace webrtc { | 29 namespace webrtc { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 // Constants from dwmapi.h. | 33 // Constants from dwmapi.h. |
32 const UINT DWM_EC_DISABLECOMPOSITION = 0; | 34 const UINT DWM_EC_DISABLECOMPOSITION = 0; |
33 const UINT DWM_EC_ENABLECOMPOSITION = 1; | 35 const UINT DWM_EC_ENABLECOMPOSITION = 1; |
34 | 36 |
35 const wchar_t kDwmapiLibraryName[] = L"dwmapi.dll"; | 37 const wchar_t kDwmapiLibraryName[] = L"dwmapi.dll"; |
36 | 38 |
39 // SharedMemoryFactory that creates SharedMemory using the deprectead | |
joedow
2016/02/09 17:21:15
s/deprectead/deprecated
Sergey Ulanov
2016/02/09 20:07:23
Done.
| |
40 // DesktopCapturer::Callback::CreateSharedMemory(). | |
41 class CallbackSharedMemoryFactory : public SharedMemoryFactory { | |
42 public: | |
43 CallbackSharedMemoryFactory(DesktopCapturer::Callback* callback) | |
44 : callback_(callback) {} | |
45 ~CallbackSharedMemoryFactory() override {} | |
46 | |
47 rtc::scoped_ptr<SharedMemory> CreateSharedMemory(size_t size) override { | |
48 return rtc_make_scoped_ptr(callback_->CreateSharedMemory(size)); | |
49 } | |
50 | |
51 private: | |
52 DesktopCapturer::Callback* callback_; | |
53 }; | |
54 | |
37 } // namespace | 55 } // namespace |
38 | 56 |
39 ScreenCapturerWinGdi::ScreenCapturerWinGdi(const DesktopCaptureOptions& options) | 57 ScreenCapturerWinGdi::ScreenCapturerWinGdi(const DesktopCaptureOptions& options) |
40 : callback_(NULL), | 58 : callback_(NULL), |
41 current_screen_id_(kFullDesktopScreenId), | 59 current_screen_id_(kFullDesktopScreenId), |
42 desktop_dc_(NULL), | 60 desktop_dc_(NULL), |
43 memory_dc_(NULL), | 61 memory_dc_(NULL), |
44 dwmapi_library_(NULL), | 62 dwmapi_library_(NULL), |
45 composition_func_(NULL), | 63 composition_func_(NULL), |
46 set_thread_execution_state_failed_(false) { | 64 set_thread_execution_state_failed_(false) { |
(...skipping 16 matching lines...) Expand all Loading... | |
63 DeleteDC(memory_dc_); | 81 DeleteDC(memory_dc_); |
64 | 82 |
65 // Restore Aero. | 83 // Restore Aero. |
66 if (composition_func_) | 84 if (composition_func_) |
67 (*composition_func_)(DWM_EC_ENABLECOMPOSITION); | 85 (*composition_func_)(DWM_EC_ENABLECOMPOSITION); |
68 | 86 |
69 if (dwmapi_library_) | 87 if (dwmapi_library_) |
70 FreeLibrary(dwmapi_library_); | 88 FreeLibrary(dwmapi_library_); |
71 } | 89 } |
72 | 90 |
91 void ScreenCapturerWinGdi::SetSharedMemoryFactory( | |
92 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) { | |
93 shared_memory_factory_ = std::move(shared_memory_factory); | |
94 } | |
95 | |
73 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { | 96 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { |
74 TickTime capture_start_time = TickTime::Now(); | 97 TickTime capture_start_time = TickTime::Now(); |
75 | 98 |
76 queue_.MoveToNextFrame(); | 99 queue_.MoveToNextFrame(); |
77 | 100 |
78 // Request that the system not power-down the system, or the display hardware. | 101 // Request that the system not power-down the system, or the display hardware. |
79 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { | 102 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { |
80 if (!set_thread_execution_state_failed_) { | 103 if (!set_thread_execution_state_failed_) { |
81 set_thread_execution_state_failed_ = true; | 104 set_thread_execution_state_failed_ = true; |
82 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " | 105 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 if (valid) | 164 if (valid) |
142 current_screen_id_ = id; | 165 current_screen_id_ = id; |
143 return valid; | 166 return valid; |
144 } | 167 } |
145 | 168 |
146 void ScreenCapturerWinGdi::Start(Callback* callback) { | 169 void ScreenCapturerWinGdi::Start(Callback* callback) { |
147 assert(!callback_); | 170 assert(!callback_); |
148 assert(callback); | 171 assert(callback); |
149 | 172 |
150 callback_ = callback; | 173 callback_ = callback; |
174 if (!shared_memory_factory_) | |
175 shared_memory_factory_.reset(new CallbackSharedMemoryFactory(callback)); | |
151 | 176 |
152 // Vote to disable Aero composited desktop effects while capturing. Windows | 177 // Vote to disable Aero composited desktop effects while capturing. Windows |
153 // will restore Aero automatically if the process exits. This has no effect | 178 // will restore Aero automatically if the process exits. This has no effect |
154 // under Windows 8 or higher. See crbug.com/124018. | 179 // under Windows 8 or higher. See crbug.com/124018. |
155 if (composition_func_) | 180 if (composition_func_) |
156 (*composition_func_)(DWM_EC_DISABLECOMPOSITION); | 181 (*composition_func_)(DWM_EC_DISABLECOMPOSITION); |
157 } | 182 } |
158 | 183 |
159 void ScreenCapturerWinGdi::PrepareCaptureResources() { | 184 void ScreenCapturerWinGdi::PrepareCaptureResources() { |
160 // Switch to the desktop receiving user input if different from the current | 185 // Switch to the desktop receiving user input if different from the current |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 | 255 |
231 DesktopSize size = screen_rect.size(); | 256 DesktopSize size = screen_rect.size(); |
232 // If the current buffer is from an older generation then allocate a new one. | 257 // If the current buffer is from an older generation then allocate a new one. |
233 // Note that we can't reallocate other buffers at this point, since the caller | 258 // Note that we can't reallocate other buffers at this point, since the caller |
234 // may still be reading from them. | 259 // may still be reading from them. |
235 if (!queue_.current_frame() || | 260 if (!queue_.current_frame() || |
236 !queue_.current_frame()->size().equals(screen_rect.size())) { | 261 !queue_.current_frame()->size().equals(screen_rect.size())) { |
237 assert(desktop_dc_ != NULL); | 262 assert(desktop_dc_ != NULL); |
238 assert(memory_dc_ != NULL); | 263 assert(memory_dc_ != NULL); |
239 | 264 |
240 size_t buffer_size = size.width() * size.height() * | 265 rtc::scoped_ptr<DesktopFrame> buffer(DesktopFrameWin::Create( |
241 DesktopFrame::kBytesPerPixel; | 266 size, shared_memory_factory_.get(), desktop_dc_)); |
242 SharedMemory* shared_memory = callback_->CreateSharedMemory(buffer_size); | |
243 | |
244 rtc::scoped_ptr<DesktopFrame> buffer( | |
245 DesktopFrameWin::Create(size, shared_memory, desktop_dc_)); | |
246 if (!buffer.get()) | 267 if (!buffer.get()) |
247 return false; | 268 return false; |
248 queue_.ReplaceCurrentFrame(buffer.release()); | 269 queue_.ReplaceCurrentFrame(buffer.release()); |
249 } | 270 } |
250 | 271 |
251 // Select the target bitmap into the memory dc and copy the rect from desktop | 272 // Select the target bitmap into the memory dc and copy the rect from desktop |
252 // to memory. | 273 // to memory. |
253 DesktopFrameWin* current = static_cast<DesktopFrameWin*>( | 274 DesktopFrameWin* current = static_cast<DesktopFrameWin*>( |
254 queue_.current_frame()->GetUnderlyingFrame()); | 275 queue_.current_frame()->GetUnderlyingFrame()); |
255 HGDIOBJ previous_object = SelectObject(memory_dc_, current->bitmap()); | 276 HGDIOBJ previous_object = SelectObject(memory_dc_, current->bitmap()); |
256 if (previous_object != NULL) { | 277 if (previous_object != NULL) { |
257 BitBlt(memory_dc_, | 278 BitBlt(memory_dc_, |
258 0, 0, screen_rect.width(), screen_rect.height(), | 279 0, 0, screen_rect.width(), screen_rect.height(), |
259 desktop_dc_, | 280 desktop_dc_, |
260 screen_rect.left(), screen_rect.top(), | 281 screen_rect.left(), screen_rect.top(), |
261 SRCCOPY | CAPTUREBLT); | 282 SRCCOPY | CAPTUREBLT); |
262 | 283 |
263 // Select back the previously selected object to that the device contect | 284 // Select back the previously selected object to that the device contect |
264 // could be destroyed independently of the bitmap if needed. | 285 // could be destroyed independently of the bitmap if needed. |
265 SelectObject(memory_dc_, previous_object); | 286 SelectObject(memory_dc_, previous_object); |
266 } | 287 } |
267 return true; | 288 return true; |
268 } | 289 } |
269 | 290 |
270 } // namespace webrtc | 291 } // namespace webrtc |
OLD | NEW |