Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复D3D设备丢失时重新创建的设备不齐全的问题 #1656

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions TrafficMonitor/TaskBarDlgDrawCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,22 @@ bool CTaskBarDlgDrawCommonSupport::IsAllDevicesRecreatedByThisFunction()
auto hr = p_d3d10_device1->GetDeviceRemovedReason();
if (hr != S_OK)
{
CCommon::WriteLog(
"D3D10.1 device is invalid. All devices will be recreated.",
theApp.m_log_path.c_str());
CCommon::WriteLog("Notice: D3D10.1 device is invalid. All devices will be recreated. This message is sent by "
"the function on the next line:",
theApp.m_log_path.c_str());
CCommon::WriteLog(__FUNCSIG__, theApp.m_log_path.c_str());
RecreateAll();
return true;
}
return false;
}

void CTaskBarDlgDrawCommonSupport::InternalRecreateD3D10Device1()
{
auto &&default_adapter1 = CD3D10Support1::GetDeviceList(true).front();
m_d3d10_device1.Recreate(default_adapter1);
}

CTaskBarDlgDrawCommonSupport::CTaskBarDlgDrawCommonSupport()
{
D2D1_STROKE_STYLE_PROPERTIES d2d1_stroke_style_properties{
Expand Down Expand Up @@ -259,7 +266,10 @@ auto CTaskBarDlgDrawCommonSupport::GetPsDotLikeStyle() noexcept

void CTaskBarDlgDrawCommonSupport::RecreateAll()
{
RecreateD3D10Device1();
CCommon::WriteLog("Notice: All devices will be recreated. This message is sent by the function on the next line:",
theApp.m_log_path.c_str());
CCommon::WriteLog(__FUNCSIG__, theApp.m_log_path.c_str());
InternalRecreateD3D10Device1();
RecreateD2D1Device();
RecreateDCompositionDevice();
}
Expand All @@ -269,19 +279,23 @@ void CTaskBarDlgDrawCommonSupport::RecreateD3D10Device1(const HRESULT recreate_r
if (recreate_reason != S_OK)
{
DrawCommonHelper::LogDeviceRecreateReason(recreate_reason);
CCommon::WriteLog("Notice: The D3D10.1 device will be recreated.", theApp.m_log_path.c_str());
CCommon::WriteLog("Notice: D3D10.1 device is invalid. All devices will be recreated. This message is sent by "
"the function on the next line:",
theApp.m_log_path.c_str());
CCommon::WriteLog(__FUNCSIG__, theApp.m_log_path.c_str());
}
auto&& default_adapter1 =
CD3D10Support1::GetDeviceList(true).front();
m_d3d10_device1.Recreate(default_adapter1);
RecreateAll();
}

void CTaskBarDlgDrawCommonSupport::RecreateD2D1Device(const HRESULT recreate_reason)
{
if (recreate_reason != S_OK)
{
DrawCommonHelper::LogDeviceRecreateReason(recreate_reason);
CCommon::WriteLog("Notice: The D2D1 device will be recreated.", theApp.m_log_path.c_str());
CCommon::WriteLog(
"Notice: The D2D1 device will be recreated. This message is sent by the function on the next line:",
theApp.m_log_path.c_str());
CCommon::WriteLog(__FUNCSIG__, theApp.m_log_path.c_str());
}
if (IsAllDevicesRecreatedByThisFunction())
{
Expand All @@ -299,7 +313,9 @@ void CTaskBarDlgDrawCommonSupport::RecreateDCompositionDevice(const HRESULT recr
if (recreate_reason != S_OK)
{
DrawCommonHelper::LogDeviceRecreateReason(recreate_reason);
CCommon::WriteLog("Notice: The DirectComposition device will be recreated.", theApp.m_log_path.c_str());
CCommon::WriteLog("Notice: The DirectComposition device will be recreated. This message is sent by the function on the next line:",
theApp.m_log_path.c_str());
CCommon::WriteLog(__FUNCSIG__, theApp.m_log_path.c_str());
}
if (IsAllDevicesRecreatedByThisFunction())
{
Expand Down
1 change: 1 addition & 0 deletions TrafficMonitor/TaskBarDlgDrawCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class CTaskBarDlgDrawCommonSupport
Microsoft::WRL::ComPtr<ID2D1StrokeStyle> m_p_ps_dot_like_style{};

bool IsAllDevicesRecreatedByThisFunction();
void InternalRecreateD3D10Device1();

public:
CTaskBarDlgDrawCommonSupport();
Expand Down