Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsd3d11planesplitter.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <QtMultimedia/private/qvideotexturehelper_p.h>
8
9#include <QtCore/qloggingcategory.h>
10#include <QtCore/private/qsystemerror_p.h>
11
13
14namespace QtMultimediaPrivate {
15
16namespace {
17
18Q_LOGGING_CATEGORY(lcD3D11PlaneSplitter, "qt.multimedia.windows.d3d11planesplitter");
19
20DXGI_FORMAT toPlaneViewFormat(QVideoTextureHelper::TextureDescription::TextureFormat format)
21{
22 switch (format) {
23 case QVideoTextureHelper::TextureDescription::Red_8:
24 return DXGI_FORMAT_R8_UNORM;
25 case QVideoTextureHelper::TextureDescription::RG_8:
26 return DXGI_FORMAT_R8G8_UNORM;
27 case QVideoTextureHelper::TextureDescription::Red_16:
28 return DXGI_FORMAT_R16_UNORM;
29 case QVideoTextureHelper::TextureDescription::RG_16:
30 return DXGI_FORMAT_R16G16_UNORM;
31 default:
32 return DXGI_FORMAT_UNKNOWN;
33 }
34}
35
36} // namespace
37
40
42{
43 // Matches the D3D11VA surface formats in FFmpeg's hwcontext_d3d11va supported_formats[].
44 switch (pixelFormat) {
47 return true;
48 default:
49 return false;
50 }
51}
52
61
63{
66
67 if (const HRESULT hr =
69 FAILED(hr)) {
71 << "CreateVertexShader failed:" << QSystemError::windowsComString(hr);
72 return false;
73 }
74
75 if (const HRESULT hr =
77 FAILED(hr)) {
79 << "CreatePixelShader failed:" << QSystemError::windowsComString(hr);
80 m_vs.Reset();
81 return false;
82 }
83
85 return true;
86}
87
91{
95 return { texture, subresourceIndex };
96
105 }
106
107 if (needRecreate) {
117
118 if (const HRESULT hr = device->CreateTexture2D(
120 FAILED(hr)) {
121 qCWarning(lcD3D11PlaneSplitter) << "CreateTexture2D failed for shader-readable copy:"
123 return {};
124 }
125 }
126
128 subresourceIndex, nullptr);
129 return { m_shaderReadableCopy, 0 };
130}
131
135{
140 Q_ASSERT(m_vs && m_ps);
142
144 Q_ASSERT(desc && desc->nplanes == 2);
145
146 const auto [sourceTexture, sourceSlice] =
148 if (!sourceTexture)
149 return std::nullopt;
150
153
154 context->IASetInputLayout(nullptr);
156 context->VSSetShader(m_vs.Get(), nullptr, 0);
157 context->PSSetShader(m_ps.Get(), nullptr, 0);
158
159 for (int plane = 0; plane < desc->nplanes; ++plane) {
162 qCWarning(lcD3D11PlaneSplitter) << "Unsupported plane texture format for pixel format"
163 << pixelFormat << "plane" << plane;
164 return std::nullopt;
165 }
166
169
177
179 if (const HRESULT hr =
181 FAILED(hr)) {
182 qCWarning(lcD3D11PlaneSplitter) << "CreateShaderResourceView failed for plane" << plane
183 << ":" << QSystemError::windowsComString(hr);
184 return std::nullopt;
185 }
186
188 rtDesc.Width = static_cast<UINT>(planeSize.width());
189 rtDesc.Height = static_cast<UINT>(planeSize.height());
190 rtDesc.MipLevels = 1;
191 rtDesc.ArraySize = 1;
196
198 if (const HRESULT hr = device->CreateTexture2D(&rtDesc, nullptr, &planeTex); FAILED(hr)) {
199 qCWarning(lcD3D11PlaneSplitter) << "CreateTexture2D failed for plane" << plane << ":"
201 return std::nullopt;
202 }
203
205 if (const HRESULT hr = device->CreateRenderTargetView(planeTex.Get(), nullptr, &rtv);
206 FAILED(hr)) {
207 qCWarning(lcD3D11PlaneSplitter) << "CreateRenderTargetView failed for plane" << plane
208 << ":" << QSystemError::windowsComString(hr);
209 return std::nullopt;
210 }
211
213 0.0f, 0.0f, float(planeSize.width()), float(planeSize.height()), 0.0f, 1.0f
214 };
217 context->OMSetRenderTargets(1, rtvs, nullptr);
220 context->Draw(3, 0);
221
223 }
224
225 ID3D11ShaderResourceView *nullSrvs[] = { nullptr };
227 ID3D11RenderTargetView *nullRtvs[] = { nullptr };
228 context->OMSetRenderTargets(1, nullRtvs, nullptr);
229
230 return result;
231}
232
233} // namespace QtMultimediaPrivate
234
235QT_END_NAMESPACE
Combined button and popup list for selecting options.