perf: 优化winrt捕获的性能

This commit is contained in:
Xu Liu 2021-09-02 17:50:15 +08:00
commit eebb09b530
3 changed files with 20 additions and 19 deletions

View file

@ -16,7 +16,7 @@ public:
{ UINT(srcClient.right - srcClient.left), UINT(srcClient.bottom - srcClient.top) },
_d3dRenderTargetView,
_linearSampler,
{1.2f,1.2f}
{1.5f,1.5f}
));
}

View file

@ -47,7 +47,6 @@ float3 line_run(float ypos, float3 xpos1, float3 xpos2, float3 linetaps1, float3
float4 PS(VS_OUTPUT input) : SV_Target{
float4 coord = input.TexCoord;
return frameTexture.Sample(linearSampler, coord.xy);
// 用于抗振铃
float3 neighbors[4] = {

View file

@ -107,6 +107,21 @@ public:
// 有些窗口无法用WinRT捕获
Debug::Assert(false, L"WinRT 捕获出错");
}
D3D11_TEXTURE2D_DESC desc{};
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.Width = _clientInFrame.right - _clientInFrame.left;
desc.Height = _clientInFrame.bottom - _clientInFrame.top;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
Debug::ThrowIfComFailed(
Env::$instance->GetD3DDevice()->CreateTexture2D(&desc, nullptr, &_withoutFrame),
L""
);
}
~WinRTCapturer() {
@ -144,28 +159,13 @@ public:
L"从获取 IDirect3DSurface 获取 ID3D11Texture2D 失败"
);
ComPtr<ID3D11Texture2D> withoutFrame;
D3D11_TEXTURE2D_DESC desc{};
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
desc.Width = _clientInFrame.right - _clientInFrame.left;
desc.Height = _clientInFrame.bottom - _clientInFrame.top;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
Debug::ThrowIfComFailed(
Env::$instance->GetD3DDevice()->CreateTexture2D(&desc, nullptr, &withoutFrame),
L""
);
D3D11_BOX box {
_clientInFrame.left, _clientInFrame.top, 0,
_clientInFrame.right, _clientInFrame.bottom, 1
};
Env::$instance->GetD3DDC()->CopySubresourceRegion(withoutFrame.Get(), 0, 0, 0, 0, withFrame.Get(), 0, &box);
Env::$instance->GetD3DDC()->CopySubresourceRegion(_withoutFrame.Get(), 0, 0, 0, 0, withFrame.Get(), 0, &box);
return withoutFrame;
return _withoutFrame;
}
private:
@ -175,4 +175,6 @@ private:
winrt::GraphicsCaptureSession _captureSession{ nullptr };
winrt::GraphicsCaptureItem _captureItem{ nullptr };
winrt::IDirect3DDevice _wrappedD3DDevice{ nullptr };
ComPtr<ID3D11Texture2D> _withoutFrame;
};