Always reset the thread desktop before calling DuplicateOutput()

Otherwise capture will fail if the thread desktop is different than the current input desktop (ex: UAC secure desktop is active)
This commit is contained in:
Cameron Gutman 2024-01-17 17:15:21 -06:00
commit f64712f277
2 changed files with 31 additions and 4 deletions

View file

@ -52,6 +52,23 @@ set_gpu_preference(int preference) {
return ERROR_SUCCESS;
}
void
syncThreadDesktop() {
auto hDesk = OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, FALSE, GENERIC_ALL);
if (!hDesk) {
auto err = GetLastError();
std::cout << "Failed to Open Input Desktop [0x"sv << util::hex(err).to_string_view() << ']' << std::endl;
return;
}
if (!SetThreadDesktop(hDesk)) {
auto err = GetLastError();
std::cout << "Failed to sync desktop to thread [0x"sv << util::hex(err).to_string_view() << ']' << std::endl;
}
CloseDesktop(hDesk);
}
HRESULT
test_dxgi_duplication(dxgi::adapter_t &adapter, dxgi::output_t &output) {
D3D_FEATURE_LEVEL featureLevels[] {
@ -87,6 +104,9 @@ test_dxgi_duplication(dxgi::adapter_t &adapter, dxgi::output_t &output) {
return status;
}
// Ensure we can duplicate the current display
syncThreadDesktop();
// Return the result of DuplicateOutput() to Sunshine
dxgi::dup_t dup;
return output1->DuplicateOutput((IUnknown *) device.get(), &dup);