Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc

Issue 2348803003: Remove differ from ScreenCapturer implementations (Closed)
Patch Set: Comment on the XDamage scenario in screen_capturer_x11.cc Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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...) Expand 10 before | Expand all | Expand 10 after
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 &region);
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 frame->mutable_updated_region()->SetRect(
123 helper_.TakeInvalidRegion(frame->mutable_updated_region()); 94 DesktopRect::MakeSize(frame->size()));
124 frame->set_capture_time_ms( 95 frame->set_capture_time_ms(
125 (rtc::TimeNanos() - capture_start_time_nanos) / 96 (rtc::TimeNanos() - capture_start_time_nanos) /
126 rtc::kNumNanosecsPerMillisec); 97 rtc::kNumNanosecsPerMillisec);
127 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); 98 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame));
128 } 99 }
129 100
130 bool ScreenCapturerWinGdi::GetScreenList(ScreenList* screens) { 101 bool ScreenCapturerWinGdi::GetScreenList(ScreenList* screens) {
131 return webrtc::GetScreenList(screens); 102 return webrtc::GetScreenList(screens);
132 } 103 }
133 104
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (!desktop_dc_) 176 if (!desktop_dc_)
206 abort(); 177 abort();
207 memory_dc_ = CreateCompatibleDC(desktop_dc_); 178 memory_dc_ = CreateCompatibleDC(desktop_dc_);
208 if (!memory_dc_) 179 if (!memory_dc_)
209 abort(); 180 abort();
210 181
211 desktop_dc_rect_ = screen_rect; 182 desktop_dc_rect_ = screen_rect;
212 183
213 // Make sure the frame buffers will be reallocated. 184 // Make sure the frame buffers will be reallocated.
214 queue_.Reset(); 185 queue_.Reset();
215
216 helper_.ClearInvalidRegion();
217 } 186 }
218 } 187 }
219 188
220 bool ScreenCapturerWinGdi::CaptureImage() { 189 bool ScreenCapturerWinGdi::CaptureImage() {
221 DesktopRect screen_rect = 190 DesktopRect screen_rect =
222 GetScreenRect(current_screen_id_, current_device_key_); 191 GetScreenRect(current_screen_id_, current_device_key_);
223 if (screen_rect.is_empty()) 192 if (screen_rect.is_empty())
224 return false; 193 return false;
225 194
226 DesktopSize size = screen_rect.size(); 195 DesktopSize size = screen_rect.size();
(...skipping 23 matching lines...) Expand all
250 SRCCOPY | CAPTUREBLT); 219 SRCCOPY | CAPTUREBLT);
251 220
252 // Select back the previously selected object to that the device contect 221 // Select back the previously selected object to that the device contect
253 // could be destroyed independently of the bitmap if needed. 222 // could be destroyed independently of the bitmap if needed.
254 SelectObject(memory_dc_, previous_object); 223 SelectObject(memory_dc_, previous_object);
255 } 224 }
256 return true; 225 return true;
257 } 226 }
258 227
259 } // namespace webrtc 228 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698