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" | |
18 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 17 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
19 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 18 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
20 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" | 19 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
21 #include "webrtc/modules/desktop_capture/desktop_region.h" | 20 #include "webrtc/modules/desktop_capture/desktop_region.h" |
22 #include "webrtc/modules/desktop_capture/differ.h" | 21 #include "webrtc/modules/desktop_capture/differ.h" |
23 #include "webrtc/modules/desktop_capture/mouse_cursor.h" | 22 #include "webrtc/modules/desktop_capture/mouse_cursor.h" |
24 #include "webrtc/modules/desktop_capture/win/cursor.h" | 23 #include "webrtc/modules/desktop_capture/win/cursor.h" |
25 #include "webrtc/modules/desktop_capture/win/desktop.h" | 24 #include "webrtc/modules/desktop_capture/win/desktop.h" |
26 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" | 25 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" |
27 #include "webrtc/system_wrappers/include/logging.h" | 26 #include "webrtc/system_wrappers/include/logging.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 void ScreenCapturerWinGdi::SetSharedMemoryFactory( | 91 void ScreenCapturerWinGdi::SetSharedMemoryFactory( |
93 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) { | 92 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) { |
94 shared_memory_factory_ = | 93 shared_memory_factory_ = |
95 rtc::ScopedToUnique(std::move(shared_memory_factory)); | 94 rtc::ScopedToUnique(std::move(shared_memory_factory)); |
96 } | 95 } |
97 | 96 |
98 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { | 97 void ScreenCapturerWinGdi::Capture(const DesktopRegion& region) { |
99 TickTime capture_start_time = TickTime::Now(); | 98 TickTime capture_start_time = TickTime::Now(); |
100 | 99 |
101 queue_.MoveToNextFrame(); | 100 queue_.MoveToNextFrame(); |
102 RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); | |
103 | 101 |
104 // Request that the system not power-down the system, or the display hardware. | 102 // Request that the system not power-down the system, or the display hardware. |
105 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { | 103 if (!SetThreadExecutionState(ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED)) { |
106 if (!set_thread_execution_state_failed_) { | 104 if (!set_thread_execution_state_failed_) { |
107 set_thread_execution_state_failed_ = true; | 105 set_thread_execution_state_failed_ = true; |
108 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " | 106 LOG_F(LS_WARNING) << "Failed to make system & display power assertion: " |
109 << GetLastError(); | 107 << GetLastError(); |
110 } | 108 } |
111 } | 109 } |
112 | 110 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 // If the current buffer is from an older generation then allocate a new one. | 258 // If the current buffer is from an older generation then allocate a new one. |
261 // Note that we can't reallocate other buffers at this point, since the caller | 259 // Note that we can't reallocate other buffers at this point, since the caller |
262 // may still be reading from them. | 260 // may still be reading from them. |
263 if (!queue_.current_frame() || | 261 if (!queue_.current_frame() || |
264 !queue_.current_frame()->size().equals(screen_rect.size())) { | 262 !queue_.current_frame()->size().equals(screen_rect.size())) { |
265 assert(desktop_dc_ != NULL); | 263 assert(desktop_dc_ != NULL); |
266 assert(memory_dc_ != NULL); | 264 assert(memory_dc_ != NULL); |
267 | 265 |
268 std::unique_ptr<DesktopFrame> buffer(DesktopFrameWin::Create( | 266 std::unique_ptr<DesktopFrame> buffer(DesktopFrameWin::Create( |
269 size, shared_memory_factory_.get(), desktop_dc_)); | 267 size, shared_memory_factory_.get(), desktop_dc_)); |
270 if (!buffer) | 268 if (!buffer.get()) |
271 return false; | 269 return false; |
272 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(buffer.release())); | 270 queue_.ReplaceCurrentFrame(buffer.release()); |
273 } | 271 } |
274 | 272 |
275 // Select the target bitmap into the memory dc and copy the rect from desktop | 273 // Select the target bitmap into the memory dc and copy the rect from desktop |
276 // to memory. | 274 // to memory. |
277 DesktopFrameWin* current = static_cast<DesktopFrameWin*>( | 275 DesktopFrameWin* current = static_cast<DesktopFrameWin*>( |
278 queue_.current_frame()->GetUnderlyingFrame()); | 276 queue_.current_frame()->GetUnderlyingFrame()); |
279 HGDIOBJ previous_object = SelectObject(memory_dc_, current->bitmap()); | 277 HGDIOBJ previous_object = SelectObject(memory_dc_, current->bitmap()); |
280 if (previous_object != NULL) { | 278 if (previous_object != NULL) { |
281 BitBlt(memory_dc_, | 279 BitBlt(memory_dc_, |
282 0, 0, screen_rect.width(), screen_rect.height(), | 280 0, 0, screen_rect.width(), screen_rect.height(), |
283 desktop_dc_, | 281 desktop_dc_, |
284 screen_rect.left(), screen_rect.top(), | 282 screen_rect.left(), screen_rect.top(), |
285 SRCCOPY | CAPTUREBLT); | 283 SRCCOPY | CAPTUREBLT); |
286 | 284 |
287 // Select back the previously selected object to that the device contect | 285 // Select back the previously selected object to that the device contect |
288 // could be destroyed independently of the bitmap if needed. | 286 // could be destroyed independently of the bitmap if needed. |
289 SelectObject(memory_dc_, previous_object); | 287 SelectObject(memory_dc_, previous_object); |
290 } | 288 } |
291 return true; | 289 return true; |
292 } | 290 } |
293 | 291 |
294 } // namespace webrtc | 292 } // namespace webrtc |
OLD | NEW |