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/base/checks.h" |
18 #include "webrtc/base/timeutils.h" | 18 #include "webrtc/base/timeutils.h" |
19 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 19 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
20 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 20 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
21 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" | 21 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
22 #include "webrtc/modules/desktop_capture/desktop_region.h" | 22 #include "webrtc/modules/desktop_capture/desktop_region.h" |
23 #include "webrtc/modules/desktop_capture/differ.h" | |
24 #include "webrtc/modules/desktop_capture/mouse_cursor.h" | 23 #include "webrtc/modules/desktop_capture/mouse_cursor.h" |
25 #include "webrtc/modules/desktop_capture/win/cursor.h" | 24 #include "webrtc/modules/desktop_capture/win/cursor.h" |
26 #include "webrtc/modules/desktop_capture/win/desktop.h" | 25 #include "webrtc/modules/desktop_capture/win/desktop.h" |
27 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" | 26 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" |
28 #include "webrtc/system_wrappers/include/logging.h" | 27 #include "webrtc/system_wrappers/include/logging.h" |
29 | 28 |
30 namespace webrtc { | 29 namespace webrtc { |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
(...skipping 45 matching lines...) Loading... | |
79 RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); | 78 RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); |
80 | 79 |
81 // Make sure the GDI capture resources are up-to-date. | 80 // Make sure the GDI capture resources are up-to-date. |
82 PrepareCaptureResources(); | 81 PrepareCaptureResources(); |
83 | 82 |
84 if (!CaptureImage()) { | 83 if (!CaptureImage()) { |
85 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); | 84 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
86 return; | 85 return; |
87 } | 86 } |
88 | 87 |
89 const DesktopFrame* current_frame = queue_.current_frame(); | |
90 const DesktopFrame* last_frame = queue_.previous_frame(); | |
91 if (last_frame && last_frame->size().equals(current_frame->size())) { | |
92 // Make sure the differencer is set up correctly for these previous and | |
93 // current screens. | |
94 if (!differ_.get() || | |
95 (differ_->width() != current_frame->size().width()) || | |
96 (differ_->height() != current_frame->size().height()) || | |
97 (differ_->bytes_per_row() != current_frame->stride())) { | |
98 differ_.reset(new Differ(current_frame->size().width(), | |
99 current_frame->size().height(), | |
100 DesktopFrame::kBytesPerPixel, | |
101 current_frame->stride())); | |
102 } | |
103 | |
104 // Calculate difference between the two last captured frames. | |
105 DesktopRegion region; | |
106 differ_->CalcDirtyRegion(last_frame->data(), current_frame->data(), | |
107 ®ion); | |
108 helper_.InvalidateRegion(region); | |
109 } else { | |
110 // No previous frame is available, or the screen is resized. Invalidate the | |
111 // whole screen. | |
112 helper_.InvalidateScreen(current_frame->size()); | |
113 } | |
114 | |
115 helper_.set_size_most_recent(current_frame->size()); | |
116 | |
117 // Emit the current frame. | 88 // Emit the current frame. |
118 std::unique_ptr<DesktopFrame> frame = queue_.current_frame()->Share(); | 89 std::unique_ptr<DesktopFrame> frame = queue_.current_frame()->Share(); |
119 frame->set_dpi(DesktopVector( | 90 frame->set_dpi(DesktopVector( |
120 GetDeviceCaps(desktop_dc_, LOGPIXELSX), | 91 GetDeviceCaps(desktop_dc_, LOGPIXELSX), |
121 GetDeviceCaps(desktop_dc_, LOGPIXELSY))); | 92 GetDeviceCaps(desktop_dc_, LOGPIXELSY))); |
122 frame->mutable_updated_region()->Clear(); | 93 // ScreenCapturerDifferWrapper will help to detect updated region if needed. |
Sergey Ulanov
2016/09/22 18:25:08
I suggest adding a comment in screen_capturer_win_
Hzj_jie
2016/09/22 21:01:34
Done.
| |
123 helper_.TakeInvalidRegion(frame->mutable_updated_region()); | 94 frame->mutable_updated_region()->SetRect( |
95 DesktopRect::MakeSize(frame->size())); | |
124 frame->set_capture_time_ms( | 96 frame->set_capture_time_ms( |
125 (rtc::TimeNanos() - capture_start_time_nanos) / | 97 (rtc::TimeNanos() - capture_start_time_nanos) / |
126 rtc::kNumNanosecsPerMillisec); | 98 rtc::kNumNanosecsPerMillisec); |
127 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); | 99 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); |
128 } | 100 } |
129 | 101 |
130 bool ScreenCapturerWinGdi::GetScreenList(ScreenList* screens) { | 102 bool ScreenCapturerWinGdi::GetScreenList(ScreenList* screens) { |
131 return webrtc::GetScreenList(screens); | 103 return webrtc::GetScreenList(screens); |
132 } | 104 } |
133 | 105 |
(...skipping 71 matching lines...) Loading... | |
205 if (!desktop_dc_) | 177 if (!desktop_dc_) |
206 abort(); | 178 abort(); |
207 memory_dc_ = CreateCompatibleDC(desktop_dc_); | 179 memory_dc_ = CreateCompatibleDC(desktop_dc_); |
208 if (!memory_dc_) | 180 if (!memory_dc_) |
209 abort(); | 181 abort(); |
210 | 182 |
211 desktop_dc_rect_ = screen_rect; | 183 desktop_dc_rect_ = screen_rect; |
212 | 184 |
213 // Make sure the frame buffers will be reallocated. | 185 // Make sure the frame buffers will be reallocated. |
214 queue_.Reset(); | 186 queue_.Reset(); |
215 | |
216 helper_.ClearInvalidRegion(); | |
217 } | 187 } |
218 } | 188 } |
219 | 189 |
220 bool ScreenCapturerWinGdi::CaptureImage() { | 190 bool ScreenCapturerWinGdi::CaptureImage() { |
221 DesktopRect screen_rect = | 191 DesktopRect screen_rect = |
222 GetScreenRect(current_screen_id_, current_device_key_); | 192 GetScreenRect(current_screen_id_, current_device_key_); |
223 if (screen_rect.is_empty()) | 193 if (screen_rect.is_empty()) |
224 return false; | 194 return false; |
225 | 195 |
226 DesktopSize size = screen_rect.size(); | 196 DesktopSize size = screen_rect.size(); |
(...skipping 23 matching lines...) Loading... | |
250 SRCCOPY | CAPTUREBLT); | 220 SRCCOPY | CAPTUREBLT); |
251 | 221 |
252 // Select back the previously selected object to that the device contect | 222 // Select back the previously selected object to that the device contect |
253 // could be destroyed independently of the bitmap if needed. | 223 // could be destroyed independently of the bitmap if needed. |
254 SelectObject(memory_dc_, previous_object); | 224 SelectObject(memory_dc_, previous_object); |
255 } | 225 } |
256 return true; | 226 return true; |
257 } | 227 } |
258 | 228 |
259 } // namespace webrtc | 229 } // namespace webrtc |
OLD | NEW |