| Index: webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc
|
| diff --git a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc
|
| index 975d7e47709f42d43284f77e75dd8495486018d3..065a6148c06ba85ded23d9db3943eca650e1a306 100644
|
| --- a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc
|
| +++ b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc
|
| @@ -13,17 +13,24 @@
|
| #include <windows.h>
|
|
|
| #include <algorithm>
|
| +#include <string>
|
|
|
| #include "webrtc/base/checks.h"
|
| +#include "webrtc/modules/desktop_capture/desktop_capture_types.h"
|
| +#include "webrtc/modules/desktop_capture/win/screen_capture_utils.h"
|
|
|
| namespace webrtc {
|
|
|
| -DxgiDuplicatorController::Context::Context() {}
|
| +DxgiDuplicatorController::Context::Context() = default;
|
|
|
| DxgiDuplicatorController::Context::~Context() {
|
| DxgiDuplicatorController::Instance()->Unregister(this);
|
| }
|
|
|
| +void DxgiDuplicatorController::Context::Reset() {
|
| + identity_ = 0;
|
| +}
|
| +
|
| // static
|
| DxgiDuplicatorController* DxgiDuplicatorController::Instance() {
|
| // The static instance won't be deleted to ensure it can be used by other
|
| @@ -44,6 +51,11 @@ bool DxgiDuplicatorController::IsSupported() {
|
| return Initialize();
|
| }
|
|
|
| +void DxgiDuplicatorController::Reset() {
|
| + rtc::CritScope lock(&lock_);
|
| + Deinitialize();
|
| +}
|
| +
|
| bool DxgiDuplicatorController::RetrieveD3dInfo(D3dInfo* info) {
|
| rtc::CritScope lock(&lock_);
|
| if (!Initialize()) {
|
| @@ -182,6 +194,7 @@ bool DxgiDuplicatorController::DoInitialize() {
|
| void DxgiDuplicatorController::Deinitialize() {
|
| desktop_rect_ = DesktopRect();
|
| duplicators_.clear();
|
| + resolution_change_detector_.Reset();
|
| }
|
|
|
| bool DxgiDuplicatorController::ContextExpired(
|
| @@ -219,17 +232,34 @@ bool DxgiDuplicatorController::DoDuplicate(Context* context,
|
| RTC_DCHECK(target);
|
| target->mutable_updated_region()->Clear();
|
| rtc::CritScope lock(&lock_);
|
| + if (DoDuplicateUnlocked(context, monitor_id, target)) {
|
| + return true;
|
| + }
|
| + Deinitialize();
|
| + return false;
|
| +}
|
| +
|
| +bool DxgiDuplicatorController::DoDuplicateUnlocked(Context* context,
|
| + int monitor_id,
|
| + SharedDesktopFrame* target) {
|
| if (!Initialize()) {
|
| // Cannot initialize COM components now, display mode may be changing.
|
| return false;
|
| }
|
|
|
| + if (resolution_change_detector_.IsChanged(
|
| + GetScreenRect(kFullDesktopScreenId, std::wstring()).size())) {
|
| + // Resolution of entire screen has been changed, which usually means a new
|
| + // monitor has been attached or one has been removed. The simplest way is to
|
| + // Deinitialize() and returns false to indicate downstream components.
|
| + return false;
|
| + }
|
| +
|
| Setup(context);
|
| if (monitor_id < 0) {
|
| // Capture entire screen.
|
| for (size_t i = 0; i < duplicators_.size(); i++) {
|
| if (!duplicators_[i].Duplicate(&context->contexts_[i], target)) {
|
| - Deinitialize();
|
| return false;
|
| }
|
| }
|
| @@ -248,7 +278,6 @@ bool DxgiDuplicatorController::DoDuplicate(Context* context,
|
| target->set_dpi(dpi());
|
| return true;
|
| }
|
| - Deinitialize();
|
| return false;
|
| }
|
| }
|
|
|