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> | 15 #include <utility> |
16 | 16 |
| 17 #include "webrtc/base/checks.h" |
17 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 18 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
18 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 19 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
19 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" | 20 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
20 #include "webrtc/modules/desktop_capture/desktop_region.h" | 21 #include "webrtc/modules/desktop_capture/desktop_region.h" |
21 #include "webrtc/modules/desktop_capture/differ.h" | 22 #include "webrtc/modules/desktop_capture/differ.h" |
22 #include "webrtc/modules/desktop_capture/mouse_cursor.h" | 23 #include "webrtc/modules/desktop_capture/mouse_cursor.h" |
23 #include "webrtc/modules/desktop_capture/win/cursor.h" | 24 #include "webrtc/modules/desktop_capture/win/cursor.h" |
24 #include "webrtc/modules/desktop_capture/win/desktop.h" | 25 #include "webrtc/modules/desktop_capture/win/desktop.h" |
25 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" | 26 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" |
26 #include "webrtc/system_wrappers/include/logging.h" | 27 #include "webrtc/system_wrappers/include/logging.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 void ScreenCapturerWinGdi::SetSharedMemoryFactory( | 76 void ScreenCapturerWinGdi::SetSharedMemoryFactory( |
76 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) { | 77 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) { |
77 shared_memory_factory_ = | 78 shared_memory_factory_ = |
78 rtc::ScopedToUnique(std::move(shared_memory_factory)); | 79 rtc::ScopedToUnique(std::move(shared_memory_factory)); |
79 } | 80 } |
80 | 81 |
81 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { | 82 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { |
82 TickTime capture_start_time = TickTime::Now(); | 83 TickTime capture_start_time = TickTime::Now(); |
83 | 84 |
84 queue_.MoveToNextFrame(); | 85 queue_.MoveToNextFrame(); |
| 86 RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); |
85 | 87 |
86 // Request that the system not power-down the system, or the display hardware. | 88 // Request that the system not power-down the system, or the display hardware. |
87 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { | 89 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { |
88 if (!set_thread_execution_state_failed_) { | 90 if (!set_thread_execution_state_failed_) { |
89 set_thread_execution_state_failed_ = true; | 91 set_thread_execution_state_failed_ = true; |
90 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " | 92 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " |
91 << GetLastError(); | 93 << GetLastError(); |
92 } | 94 } |
93 } | 95 } |
94 | 96 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // If the current buffer is from an older generation then allocate a new one. | 242 // If the current buffer is from an older generation then allocate a new one. |
241 // Note that we can't reallocate other buffers at this point, since the caller | 243 // Note that we can't reallocate other buffers at this point, since the caller |
242 // may still be reading from them. | 244 // may still be reading from them. |
243 if (!queue_.current_frame() || | 245 if (!queue_.current_frame() || |
244 !queue_.current_frame()->size().equals(screen_rect.size())) { | 246 !queue_.current_frame()->size().equals(screen_rect.size())) { |
245 assert(desktop_dc_ != NULL); | 247 assert(desktop_dc_ != NULL); |
246 assert(memory_dc_ != NULL); | 248 assert(memory_dc_ != NULL); |
247 | 249 |
248 std::unique_ptr<DesktopFrame> buffer(DesktopFrameWin::Create( | 250 std::unique_ptr<DesktopFrame> buffer(DesktopFrameWin::Create( |
249 size, shared_memory_factory_.get(), desktop_dc_)); | 251 size, shared_memory_factory_.get(), desktop_dc_)); |
250 if (!buffer.get()) | 252 if (!buffer) |
251 return false; | 253 return false; |
252 queue_.ReplaceCurrentFrame(buffer.release()); | 254 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(buffer.release())); |
253 } | 255 } |
254 | 256 |
255 // Select the target bitmap into the memory dc and copy the rect from desktop | 257 // Select the target bitmap into the memory dc and copy the rect from desktop |
256 // to memory. | 258 // to memory. |
257 DesktopFrameWin* current = static_cast<DesktopFrameWin*>( | 259 DesktopFrameWin* current = static_cast<DesktopFrameWin*>( |
258 queue_.current_frame()->GetUnderlyingFrame()); | 260 queue_.current_frame()->GetUnderlyingFrame()); |
259 HGDIOBJ previous_object = SelectObject(memory_dc_, current->bitmap()); | 261 HGDIOBJ previous_object = SelectObject(memory_dc_, current->bitmap()); |
260 if (previous_object != NULL) { | 262 if (previous_object != NULL) { |
261 BitBlt(memory_dc_, | 263 BitBlt(memory_dc_, |
262 0, 0, screen_rect.width(), screen_rect.height(), | 264 0, 0, screen_rect.width(), screen_rect.height(), |
263 desktop_dc_, | 265 desktop_dc_, |
264 screen_rect.left(), screen_rect.top(), | 266 screen_rect.left(), screen_rect.top(), |
265 SRCCOPY | CAPTUREBLT); | 267 SRCCOPY | CAPTUREBLT); |
266 | 268 |
267 // Select back the previously selected object to that the device contect | 269 // Select back the previously selected object to that the device contect |
268 // could be destroyed independently of the bitmap if needed. | 270 // could be destroyed independently of the bitmap if needed. |
269 SelectObject(memory_dc_, previous_object); | 271 SelectObject(memory_dc_, previous_object); |
270 } | 272 } |
271 return true; | 273 return true; |
272 } | 274 } |
273 | 275 |
274 } // namespace webrtc | 276 } // namespace webrtc |
OLD | NEW |