Skip to content

Commit

Permalink
perf: 延迟检查显卡的功能级别以加快主窗口显示
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Dec 24, 2024
1 parent f8b1833 commit 66cd3ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Magpie/AdaptersService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ bool AdaptersService::Initialize() noexcept {

_UpdateProfiles();

_monitorThread = std::thread(std::bind_front(&AdaptersService::_MonitorThreadProc, this));
return true;
}

Expand All @@ -66,6 +65,10 @@ void AdaptersService::Uninitialize() noexcept {
_monitorThread.join();
}

void AdaptersService::StartMonitor() noexcept {
_monitorThread = std::thread(std::bind_front(&AdaptersService::_MonitorThreadProc, this));
}

bool AdaptersService::_GatherAdapterInfos(
com_ptr<IDXGIFactory7>& dxgiFactory,
wil::unique_event_nothrow& adaptersChangedEvent,
Expand Down
2 changes: 2 additions & 0 deletions src/Magpie/AdaptersService.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class AdaptersService {

void Uninitialize() noexcept;

void StartMonitor() noexcept;

const std::vector<AdapterInfo>& AdapterInfos() const noexcept {
return _adapterInfos;
}
Expand Down
8 changes: 8 additions & 0 deletions src/Magpie/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ bool App::Initialize(const wchar_t* arguments) {
_Uninitialize();
return false;
}

// 有的设备上后台调用 D3D11CreateDevice 会拖累主窗口显示速度,因此应在主窗口显示后
// 再检查显卡的功能级别,用低优先级回调做到这一点。
App::Get().Dispatcher().RunAsync(CoreDispatcherPriority::Low, []() {
AdaptersService::Get().StartMonitor();
});
} else {
AdaptersService::Get().StartMonitor();
}

return true;
Expand Down

0 comments on commit 66cd3ab

Please sign in to comment.