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

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

Issue 2933893003: Add reference counter of DxgiDuplicatorController to unload DXGI components (Closed)
Patch Set: Avoid copy-constructor of std::atomic_int Created 3 years, 6 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
« no previous file with comments | « webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h ('k') | 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
(...skipping 18 matching lines...) Expand all
29 return DxgiDuplicatorController::Instance()->IsSupported(); 29 return DxgiDuplicatorController::Instance()->IsSupported();
30 } 30 }
31 31
32 // static 32 // static
33 bool ScreenCapturerWinDirectx::RetrieveD3dInfo(D3dInfo* info) { 33 bool ScreenCapturerWinDirectx::RetrieveD3dInfo(D3dInfo* info) {
34 // Forwards SupportedFeatureLevels() function call to 34 // Forwards SupportedFeatureLevels() function call to
35 // DxgiDuplicatorController. 35 // DxgiDuplicatorController.
36 return DxgiDuplicatorController::Instance()->RetrieveD3dInfo(info); 36 return DxgiDuplicatorController::Instance()->RetrieveD3dInfo(info);
37 } 37 }
38 38
39 ScreenCapturerWinDirectx::ScreenCapturerWinDirectx( 39 ScreenCapturerWinDirectx::ScreenCapturerWinDirectx()
40 const DesktopCaptureOptions& options) 40 : controller_(DxgiDuplicatorController::Instance()) {}
41 : callback_(nullptr) {}
42 41
43 ScreenCapturerWinDirectx::~ScreenCapturerWinDirectx() {} 42 ScreenCapturerWinDirectx::~ScreenCapturerWinDirectx() = default;
44 43
45 void ScreenCapturerWinDirectx::Start(Callback* callback) { 44 void ScreenCapturerWinDirectx::Start(Callback* callback) {
46 RTC_DCHECK(!callback_); 45 RTC_DCHECK(!callback_);
47 RTC_DCHECK(callback); 46 RTC_DCHECK(callback);
48 47
49 callback_ = callback; 48 callback_ = callback;
50 } 49 }
51 50
52 void ScreenCapturerWinDirectx::SetSharedMemoryFactory( 51 void ScreenCapturerWinDirectx::SetSharedMemoryFactory(
53 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { 52 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {
54 shared_memory_factory_ = std::move(shared_memory_factory); 53 shared_memory_factory_ = std::move(shared_memory_factory);
55 } 54 }
56 55
57 void ScreenCapturerWinDirectx::CaptureFrame() { 56 void ScreenCapturerWinDirectx::CaptureFrame() {
58 RTC_DCHECK(callback_); 57 RTC_DCHECK(callback_);
59 58
60 int64_t capture_start_time_nanos = rtc::TimeNanos(); 59 int64_t capture_start_time_nanos = rtc::TimeNanos();
61 60
62 frames_.MoveToNextFrame(); 61 frames_.MoveToNextFrame();
63 if (!frames_.current_frame()) { 62 if (!frames_.current_frame()) {
64 frames_.ReplaceCurrentFrame( 63 frames_.ReplaceCurrentFrame(
65 rtc::MakeUnique<DxgiFrame>(shared_memory_factory_.get())); 64 rtc::MakeUnique<DxgiFrame>(shared_memory_factory_.get()));
66 } 65 }
67 66
68 DxgiDuplicatorController::Result result; 67 DxgiDuplicatorController::Result result;
69 if (current_screen_id_ == kFullDesktopScreenId) { 68 if (current_screen_id_ == kFullDesktopScreenId) {
70 result = DxgiDuplicatorController::Instance()->Duplicate( 69 result = controller_->Duplicate(frames_.current_frame());
71 frames_.current_frame());
72 } else { 70 } else {
73 result = DxgiDuplicatorController::Instance()->DuplicateMonitor( 71 result = controller_->DuplicateMonitor(
74 frames_.current_frame(), current_screen_id_); 72 frames_.current_frame(), current_screen_id_);
75 } 73 }
76 74
77 using DuplicateResult = DxgiDuplicatorController::Result; 75 using DuplicateResult = DxgiDuplicatorController::Result;
78 switch (result) { 76 switch (result) {
79 case DuplicateResult::FRAME_PREPARE_FAILED: { 77 case DuplicateResult::FRAME_PREPARE_FAILED: {
80 LOG(LS_ERROR) << "Failed to allocate a new DesktopFrame."; 78 LOG(LS_ERROR) << "Failed to allocate a new DesktopFrame.";
81 // This usually means we do not have enough memory or SharedMemoryFactory 79 // This usually means we do not have enough memory or SharedMemoryFactory
82 // cannot work correctly. 80 // cannot work correctly.
83 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); 81 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr);
(...skipping 15 matching lines...) Expand all
99 (rtc::TimeNanos() - capture_start_time_nanos) / 97 (rtc::TimeNanos() - capture_start_time_nanos) /
100 rtc::kNumNanosecsPerMillisec); 98 rtc::kNumNanosecsPerMillisec);
101 frame->set_capturer_id(DesktopCapturerId::kScreenCapturerWinDirectx); 99 frame->set_capturer_id(DesktopCapturerId::kScreenCapturerWinDirectx);
102 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); 100 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame));
103 break; 101 break;
104 } 102 }
105 } 103 }
106 } 104 }
107 105
108 bool ScreenCapturerWinDirectx::GetSourceList(SourceList* sources) { 106 bool ScreenCapturerWinDirectx::GetSourceList(SourceList* sources) {
109 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); 107 int screen_count = controller_->ScreenCount();
110 for (int i = 0; i < screen_count; i++) { 108 for (int i = 0; i < screen_count; i++) {
111 sources->push_back({i}); 109 sources->push_back({i});
112 } 110 }
113 return true; 111 return true;
114 } 112 }
115 113
116 bool ScreenCapturerWinDirectx::SelectSource(SourceId id) { 114 bool ScreenCapturerWinDirectx::SelectSource(SourceId id) {
117 if (id == current_screen_id_) { 115 if (id == current_screen_id_) {
118 return true; 116 return true;
119 } 117 }
120 118
121 if (id == kFullDesktopScreenId) { 119 if (id == kFullDesktopScreenId) {
122 current_screen_id_ = id; 120 current_screen_id_ = id;
123 return true; 121 return true;
124 } 122 }
125 123
126 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); 124 int screen_count = controller_->ScreenCount();
127 if (id >= 0 && id < screen_count) { 125 if (id >= 0 && id < screen_count) {
128 current_screen_id_ = id; 126 current_screen_id_ = id;
129 return true; 127 return true;
130 } 128 }
131 return false; 129 return false;
132 } 130 }
133 131
134 } // namespace webrtc 132 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698