mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-21 23:13:08 +08:00
Fix: Remote screen black if the window doesn't use dwm to render
This commit is contained in:
@@ -172,12 +172,60 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
// <20><><EFBFBD>³<EFBFBD>ʼ<EFBFBD><CABC> Desktop Duplication
|
||||
BOOL ReinitDuplication()
|
||||
{
|
||||
if (deskDupl) {
|
||||
deskDupl->Release();
|
||||
deskDupl = nullptr;
|
||||
}
|
||||
|
||||
if (!d3dDevice) return FALSE;
|
||||
|
||||
IDXGIDevice* dxgiDevice = nullptr;
|
||||
IDXGIAdapter* dxgiAdapter = nullptr;
|
||||
IDXGIOutput* dxgiOutput = nullptr;
|
||||
IDXGIOutput1* dxgiOutput1 = nullptr;
|
||||
|
||||
HRESULT hr = d3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);
|
||||
if (FAILED(hr)) return FALSE;
|
||||
|
||||
hr = dxgiDevice->GetAdapter(&dxgiAdapter);
|
||||
dxgiDevice->Release();
|
||||
if (FAILED(hr)) return FALSE;
|
||||
|
||||
hr = dxgiAdapter->EnumOutputs(0, &dxgiOutput);
|
||||
dxgiAdapter->Release();
|
||||
if (FAILED(hr)) return FALSE;
|
||||
|
||||
hr = dxgiOutput->QueryInterface(__uuidof(IDXGIOutput1), (void**)&dxgiOutput1);
|
||||
dxgiOutput->Release();
|
||||
if (FAILED(hr)) return FALSE;
|
||||
|
||||
Sleep(100);
|
||||
|
||||
hr = dxgiOutput1->DuplicateOutput(d3dDevice, &deskDupl);
|
||||
dxgiOutput1->Release();
|
||||
|
||||
return SUCCEEDED(hr) && deskDupl;
|
||||
}
|
||||
int CaptureFrame(LPBYTE buffer, ULONG* frameSize, int reservedBytes)
|
||||
{
|
||||
if (!deskDupl) {
|
||||
if (!ReinitDuplication()) return -10;
|
||||
}
|
||||
|
||||
// 1. <20><>ȡ<EFBFBD><C8A1>һ֡
|
||||
IDXGIResource* desktopResource = nullptr;
|
||||
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
||||
HRESULT hr = deskDupl->AcquireNextFrame(100, &frameInfo, &desktopResource);
|
||||
// <20><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD>µķ<C2B5><C4B7>ʶ<EFBFBD>ʧ
|
||||
if (hr == DXGI_ERROR_ACCESS_LOST) {
|
||||
if (ReinitDuplication()) {
|
||||
hr = deskDupl->AcquireNextFrame(100, &frameInfo, &desktopResource);
|
||||
}
|
||||
}
|
||||
|
||||
if (FAILED(hr)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user