| OLD | NEW |
| 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/screen_capturer_win_directx.h" | 11 #include "webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h" |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/base/ptr_util.h" |
| 18 #include "webrtc/base/timeutils.h" | 19 #include "webrtc/base/timeutils.h" |
| 19 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 20 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
| 20 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" | 21 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h" |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 using Microsoft::WRL::ComPtr; | 25 using Microsoft::WRL::ComPtr; |
| 25 | 26 |
| 26 // static | 27 // static |
| 27 bool ScreenCapturerWinDirectx::IsSupported() { | 28 bool ScreenCapturerWinDirectx::IsSupported() { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } | 100 } |
| 100 if (!new_frame) { | 101 if (!new_frame) { |
| 101 LOG(LS_ERROR) << "Failed to allocate a new DesktopFrame."; | 102 LOG(LS_ERROR) << "Failed to allocate a new DesktopFrame."; |
| 102 // This usually means we do not have enough memory or SharedMemoryFactory | 103 // This usually means we do not have enough memory or SharedMemoryFactory |
| 103 // cannot work correctly. | 104 // cannot work correctly. |
| 104 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); | 105 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
| 105 return; | 106 return; |
| 106 } | 107 } |
| 107 frames_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(std::move(new_frame))); | 108 frames_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(std::move(new_frame))); |
| 108 } | 109 } |
| 110 contexts_.MoveToNextFrame(); |
| 111 if (!contexts_.current_frame()) { |
| 112 contexts_.ReplaceCurrentFrame( |
| 113 rtc::MakeUnique<DxgiDuplicatorController::Context>()); |
| 114 } |
| 109 | 115 |
| 110 if (current_screen_id_ == kFullDesktopScreenId) { | 116 if (current_screen_id_ == kFullDesktopScreenId) { |
| 111 if (!DxgiDuplicatorController::Instance()->Duplicate( | 117 if (!DxgiDuplicatorController::Instance()->Duplicate( |
| 112 &context_, frames_.current_frame())) { | 118 contexts_.current_frame(), frames_.current_frame())) { |
| 113 // Screen size may be changed, so we need to reset the frames. | 119 // Screen size may be changed, so we need to reset the frames. |
| 114 frames_.Reset(); | 120 frames_.Reset(); |
| 115 resolution_change_detector_.Reset(); | 121 resolution_change_detector_.Reset(); |
| 116 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); | 122 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
| 117 return; | 123 return; |
| 118 } | 124 } |
| 119 } else { | 125 } else { |
| 120 if (!DxgiDuplicatorController::Instance()->DuplicateMonitor( | 126 if (!DxgiDuplicatorController::Instance()->DuplicateMonitor( |
| 121 &context_, current_screen_id_, frames_.current_frame())) { | 127 contexts_.current_frame(), current_screen_id_, |
| 128 frames_.current_frame())) { |
| 122 // Screen size may be changed, so we need to reset the frames. | 129 // Screen size may be changed, so we need to reset the frames. |
| 123 frames_.Reset(); | 130 frames_.Reset(); |
| 124 resolution_change_detector_.Reset(); | 131 resolution_change_detector_.Reset(); |
| 125 if (current_screen_id_ >= | 132 if (current_screen_id_ >= |
| 126 DxgiDuplicatorController::Instance()->ScreenCount()) { | 133 DxgiDuplicatorController::Instance()->ScreenCount()) { |
| 127 // Current monitor has been removed from the system. | 134 // Current monitor has been removed from the system. |
| 128 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); | 135 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
| 129 } else { | 136 } else { |
| 130 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); | 137 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
| 131 } | 138 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 151 | 158 |
| 152 bool ScreenCapturerWinDirectx::SelectSource(SourceId id) { | 159 bool ScreenCapturerWinDirectx::SelectSource(SourceId id) { |
| 153 if (id == current_screen_id_) { | 160 if (id == current_screen_id_) { |
| 154 return true; | 161 return true; |
| 155 } | 162 } |
| 156 | 163 |
| 157 // Changing target screen may or may not impact frame size. So resetting | 164 // Changing target screen may or may not impact frame size. So resetting |
| 158 // frames only when a Duplicate() function call returns false. | 165 // frames only when a Duplicate() function call returns false. |
| 159 if (id == kFullDesktopScreenId) { | 166 if (id == kFullDesktopScreenId) { |
| 160 current_screen_id_ = id; | 167 current_screen_id_ = id; |
| 161 context_.Reset(); | 168 contexts_.Reset(); |
| 162 return true; | 169 return true; |
| 163 } | 170 } |
| 164 | 171 |
| 165 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); | 172 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); |
| 166 if (id >= 0 && id < screen_count) { | 173 if (id >= 0 && id < screen_count) { |
| 167 current_screen_id_ = id; | 174 current_screen_id_ = id; |
| 168 context_.Reset(); | 175 contexts_.Reset(); |
| 169 return true; | 176 return true; |
| 170 } | 177 } |
| 171 return false; | 178 return false; |
| 172 } | 179 } |
| 173 | 180 |
| 174 } // namespace webrtc | 181 } // namespace webrtc |
| OLD | NEW |