summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJøger Hansegård <joger.hansegard@qt.io>2023-05-24 13:34:05 +0200
committerJøger Hansegård <joger.hansegard@qt.io>2023-05-30 13:28:02 +0200
commit9b38bc514c658117a4ee0cb3bfbe6010ff864914 (patch)
tree2238baeeeecb8ec08bbebb68de1c6c838f557d33 /src
parent2d65ac72a38ca8e280758db7430756dc1a468628 (diff)
Make getNextFrame function part of DXGI grabber
Moving the function inside the grabber class will allow us to keep some state around. This will be used for example to improve the grabber performance by avoiding releasing the grabbed frame too frequently. Task-number: QTBUG-113460 Pick-to: 6.5 Change-Id: If883071926b8e7ec9d8a4a156aabcaee8d3370cc Reviewed-by: Artem Dyomin <artem.dyomin@qt.io> Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp b/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp
index 16730ca06..057fa700f 100644
--- a/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp
+++ b/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp
@@ -117,42 +117,6 @@ private:
QVideoFrame::MapMode m_mapMode = QVideoFrame::NotMapped;
};
-static QMaybe<QComPtr<ID3D11Texture2D>> getNextFrame(ID3D11Device *dev, IDXGIOutputDuplication *dup)
-{
- QComPtr<IDXGIResource> frame;
- DXGI_OUTDUPL_FRAME_INFO info;
- HRESULT hr = dup->AcquireNextFrame(0, &info, frame.address());
- if (FAILED(hr))
- return hr == DXGI_ERROR_WAIT_TIMEOUT ? QString{}
- : "Failed to grab the screen content" + errorString(hr);
-
- QComPtr<ID3D11Texture2D> tex;
- hr = frame->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void **>(tex.address()));
- if (FAILED(hr)) {
- dup->ReleaseFrame();
- return "Failed to obtain D3D11 texture" + errorString(hr);
- }
-
- D3D11_TEXTURE2D_DESC texDesc = {};
- tex->GetDesc(&texDesc);
- texDesc.MiscFlags = 0;
- texDesc.BindFlags = 0;
- QComPtr<ID3D11Texture2D> texCopy;
- hr = dev->CreateTexture2D(&texDesc, nullptr, texCopy.address());
- if (FAILED(hr)) {
- dup->ReleaseFrame();
- return "Failed to create texture with CPU access" + errorString(hr);
- }
-
- QComPtr<ID3D11DeviceContext> ctx;
- dev->GetImmediateContext(ctx.address());
- ctx->CopyResource(texCopy.get(), tex.get());
-
- dup->ReleaseFrame();
-
- return texCopy;
-}
-
class QFFmpegScreenCaptureDxgi::Grabber : public QFFmpegScreenCaptureThread
{
public:
@@ -198,7 +162,7 @@ public:
QVideoFrame grabFrame() override {
m_ctxMutex->lock();
- auto maybeTex = getNextFrame(m_device.get(), m_duplication.get());
+ auto maybeTex = getNextFrame();
m_ctxMutex->unlock();
if (maybeTex) {
@@ -213,6 +177,42 @@ public:
};
private:
+ QMaybe<QComPtr<ID3D11Texture2D>> getNextFrame()
+ {
+ QComPtr<IDXGIResource> frame;
+ DXGI_OUTDUPL_FRAME_INFO info;
+ HRESULT hr = m_duplication->AcquireNextFrame(0, &info, frame.address());
+ if (FAILED(hr))
+ return hr == DXGI_ERROR_WAIT_TIMEOUT ? QString{}
+ : "Failed to grab the screen content" + ::errorString(hr);
+
+ QComPtr<ID3D11Texture2D> tex;
+ hr = frame->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void **>(tex.address()));
+ if (FAILED(hr)) {
+ m_duplication->ReleaseFrame();
+ return "Failed to obtain D3D11 texture" + ::errorString(hr);
+ }
+
+ D3D11_TEXTURE2D_DESC texDesc = {};
+ tex->GetDesc(&texDesc);
+ texDesc.MiscFlags = 0;
+ texDesc.BindFlags = 0;
+ QComPtr<ID3D11Texture2D> texCopy;
+ hr = m_device->CreateTexture2D(&texDesc, nullptr, texCopy.address());
+ if (FAILED(hr)) {
+ m_duplication->ReleaseFrame();
+ return "Failed to create texture with CPU access" + ::errorString(hr);
+ }
+
+ QComPtr<ID3D11DeviceContext> ctx;
+ m_device->GetImmediateContext(ctx.address());
+ ctx->CopyResource(texCopy.get(), tex.get());
+
+ m_duplication->ReleaseFrame();
+
+ return texCopy;
+ }
+
QComPtr<IDXGIOutputDuplication> m_duplication;
QComPtr<ID3D11Device> m_device;
QWaitCondition m_waitForFormat;