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
qwindowsd3d11texturereadback.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
4
#
include
"qwindowsd3d11texturereadback_p.h"
5
6
#
include
<
QtCore
/
qloggingcategory
.
h
>
7
#
include
<
QtCore
/
private
/
qsystemerror_p
.
h
>
8
9
QT_BEGIN_NAMESPACE
10
11
namespace
QtMultimediaPrivate
{
12
13
namespace
{
14
Q_LOGGING_CATEGORY(lcD3D11TextureReadback,
"qt.multimedia.windows.d3d11texturereadback"
);
15
}
16
17
QAbstractVideoBuffer
::
MapData
18
QWindowsD3D11TextureReadback
::
map
(
const
ComPtr
<
ID3D11Device
> &
device
,
19
const
ComPtr
<
ID3D11Texture2D
> &
texture
,
const
QSize
&
frameSize
)
20
{
21
Q_ASSERT
(
device
);
22
Q_ASSERT
(
texture
);
23
24
if
(
m_mapped
)
25
return
{};
26
27
device
->
GetImmediateContext
(&
m_stagingCtx
);
28
29
CD3D11_TEXTURE2D_DESC
desc
;
30
texture
->
GetDesc
(&
desc
);
31
desc
.
Usage
=
D3D11_USAGE_STAGING
;
32
desc
.
BindFlags
= 0;
33
desc
.
CPUAccessFlags
=
D3D11_CPU_ACCESS_READ
;
34
desc
.
MiscFlags
= 0;
35
36
if
(
const
HRESULT
hr
=
device
->
CreateTexture2D
(&
desc
,
nullptr
, &
m_stagingTex
);
FAILED
(
hr
)) {
37
qCWarning
(
lcD3D11TextureReadback
)
38
<<
"CreateTexture2D failed:"
<<
QSystemError
::
windowsComString
(
hr
);
39
return
{};
40
}
41
42
m_stagingCtx
->
CopyResource
(
m_stagingTex
.
Get
(),
texture
.
Get
());
43
44
D3D11_MAPPED_SUBRESOURCE
mapped
= {};
45
if
(
const
HRESULT
hr
=
m_stagingCtx
->
Map
(
m_stagingTex
.
Get
(), 0,
D3D11_MAP_READ
, 0, &
mapped
);
46
FAILED
(
hr
)) {
47
qCWarning
(
lcD3D11TextureReadback
) <<
"Map failed:"
<<
QSystemError
::
windowsComString
(
hr
);
48
m_stagingTex
.
Reset
();
49
m_stagingCtx
.
Reset
();
50
return
{};
51
}
52
53
m_mapped
=
true
;
54
55
QAbstractVideoBuffer
::
MapData
data
;
56
data
.
planeCount
= 1;
57
data
.
bytesPerLine
[0] =
static_cast
<
int
>(
mapped
.
RowPitch
);
58
data
.
data
[0] =
static_cast
<
uchar
*>(
mapped
.
pData
);
59
data
.
dataSize
[0] =
static_cast
<
int
>(
mapped
.
RowPitch
) *
frameSize
.
height
();
60
return
data
;
61
}
62
63
void
QWindowsD3D11TextureReadback
::
unmap
()
64
{
65
if
(!
m_mapped
)
66
return
;
67
68
m_stagingCtx
->
Unmap
(
m_stagingTex
.
Get
(), 0);
69
m_stagingTex
.
Reset
();
70
m_stagingCtx
.
Reset
();
71
m_mapped
=
false
;
72
}
73
74
}
// namespace QtMultimediaPrivate
75
76
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtMultimediaPrivate::impl
Definition
qaudiosystem_p.h:257
qtmultimedia
src
multimedia
windows
qwindowsd3d11texturereadback.cpp
Generated on
for Qt by
1.16.1