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

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

Issue 2494893002: Crash in DirectX capturer (Closed)
Patch Set: Resolve review comments Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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/dxgi_output_duplicator.h" 11 #include "webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h"
12 12
13 #include <string.h> 13 #include <string.h>
14 14
15 #include <unknwn.h> 15 #include <unknwn.h>
16 #include <DXGIFormat.h> 16 #include <DXGIFormat.h>
17 #include <Windows.h> 17 #include <Windows.h>
18 18
19 #include <algorithm>
20
19 #include "webrtc/base/checks.h" 21 #include "webrtc/base/checks.h"
20 #include "webrtc/base/logging.h" 22 #include "webrtc/base/logging.h"
21 #include "webrtc/modules/desktop_capture/win/dxgi_texture_mapping.h" 23 #include "webrtc/modules/desktop_capture/win/dxgi_texture_mapping.h"
22 #include "webrtc/modules/desktop_capture/win/dxgi_texture_staging.h" 24 #include "webrtc/modules/desktop_capture/win/dxgi_texture_staging.h"
23 25
24 namespace webrtc { 26 namespace webrtc {
25 27
26 using Microsoft::WRL::ComPtr; 28 using Microsoft::WRL::ComPtr;
27 29
28 namespace { 30 namespace {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 dirty_rects_count--; 269 dirty_rects_count--;
268 } 270 }
269 271
270 return true; 272 return true;
271 } 273 }
272 274
273 void DxgiOutputDuplicator::Setup(Context* context) { 275 void DxgiOutputDuplicator::Setup(Context* context) {
274 RTC_DCHECK(context->updated_region.is_empty()); 276 RTC_DCHECK(context->updated_region.is_empty());
275 // Always copy entire monitor during the first Duplicate() function call. 277 // Always copy entire monitor during the first Duplicate() function call.
276 context->updated_region.AddRect(desktop_rect_); 278 context->updated_region.AddRect(desktop_rect_);
277 for (size_t i = 0; i < contexts_.size(); i++) { 279 RTC_DCHECK(std::find(contexts_.begin(), contexts_.end(), context) ==
278 if (contexts_[i] == nullptr) { 280 contexts_.end());
279 contexts_[i] = context;
280 return;
281 }
282 }
283
284 contexts_.push_back(context); 281 contexts_.push_back(context);
285 } 282 }
286 283
287 void DxgiOutputDuplicator::Unregister(const Context* const context) { 284 void DxgiOutputDuplicator::Unregister(const Context* const context) {
288 for (size_t i = 0; i < contexts_.size(); i++) { 285 auto it = std::find(contexts_.begin(), contexts_.end(), context);
289 if (contexts_[i] == context) { 286 RTC_DCHECK(it != contexts_.end());
290 contexts_[i] = nullptr; 287 contexts_.erase(it);
291 return;
292 }
293 }
294
295 RTC_NOTREACHED();
296 } 288 }
297 289
298 void DxgiOutputDuplicator::SpreadContextChange(const Context* const source) { 290 void DxgiOutputDuplicator::SpreadContextChange(const Context* const source) {
299 for (Context* dest : contexts_) { 291 for (Context* dest : contexts_) {
292 RTC_DCHECK(dest);
300 if (dest != source) { 293 if (dest != source) {
301 dest->updated_region.AddRegion(source->updated_region); 294 dest->updated_region.AddRegion(source->updated_region);
302 } 295 }
303 } 296 }
304 } 297 }
305 298
306 DesktopRect DxgiOutputDuplicator::SourceRect(DesktopRect rect) { 299 DesktopRect DxgiOutputDuplicator::SourceRect(DesktopRect rect) {
307 // |texture_|->AsDesktopFrame() starts from (0, 0). 300 // |texture_|->AsDesktopFrame() starts from (0, 0).
308 rect.Translate(-desktop_rect_.left(), -desktop_rect_.top()); 301 rect.Translate(-desktop_rect_.left(), -desktop_rect_.top());
309 return rect; 302 return rect;
310 } 303 }
311 304
312 DesktopRect DxgiOutputDuplicator::TargetRect(DesktopRect rect, 305 DesktopRect DxgiOutputDuplicator::TargetRect(DesktopRect rect,
313 DesktopVector offset) { 306 DesktopVector offset) {
314 rect = SourceRect(rect); 307 rect = SourceRect(rect);
315 rect.Translate(offset); 308 rect.Translate(offset);
316 return rect; 309 return rect;
317 } 310 }
318 311
319 } // namespace webrtc 312 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698