Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qvideotexturehelper_p.h
Go to the documentation of this file.
1
// Copyright (C) 2021 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
#
ifndef
QVIDEOTEXTUREHELPER_H
5
#
define
QVIDEOTEXTUREHELPER_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QtMultimedia
/
qvideoframeformat
.
h
>
19
#
include
<
QtMultimedia
/
qvideoframe
.
h
>
20
21
#
include
<
QtGui
/
rhi
/
qrhi
.
h
>
22
#
include
<
QtGui
/
qtextlayout
.
h
>
23
24
QT_BEGIN_NAMESPACE
25
26
class
QTextLayout;
27
class
QVideoFrameTextures;
28
using
QVideoFrameTexturesUPtr = std::unique_ptr<QVideoFrameTextures>;
29
class
QVideoFrameTexturesHandles;
30
using
QVideoFrameTexturesHandlesUPtr = std::unique_ptr<QVideoFrameTexturesHandles>;
31
32
namespace
QVideoTextureHelper
33
{
34
35
struct
Q_MULTIMEDIA_EXPORT
TextureDescription
36
{
37
static
constexpr
int
maxPlanes
= 3;
38
struct
SizeScale
{
39
uint8_t
x
;
40
uint8_t
y
;
41
};
42
using
BytesRequired
=
int
(*)(
int
stride
,
int
height
);
43
44
enum
TextureFormat
:
uint8_t
{
45
UnknownFormat
,
46
Red_8
,
47
RG_8
,
48
RGBA_8
,
49
BGRA_8
,
50
Red_16
,
51
RG_16
,
52
};
53
54
enum
class
FallbackPolicy
{
55
Disable
,
56
Enable
57
};
58
59
QRhiTexture
::
Format
rhiTextureFormat
(
int
plane
,
60
QRhi
*
rhi
,
61
FallbackPolicy
policy
=
FallbackPolicy
::
Enable
)
const
;
62
63
inline
int
strideForWidth
(
int
width
)
const
{
return
(
width
*
strideFactor
+ 15) & ~15; }
64
inline
int
bytesForSize
(
QSize
s
)
const
{
return
bytesRequired
(
strideForWidth
(
s
.
width
()),
s
.
height
()); }
65
int
widthForPlane
(
int
width
,
int
plane
)
const
66
{
67
if
(
plane
>
nplanes
)
return
0;
68
return
(
width
+
sizeScale
[
plane
].
x
- 1)/
sizeScale
[
plane
].
x
;
69
}
70
int
heightForPlane
(
int
height
,
int
plane
)
const
71
{
72
if
(
plane
>
nplanes
)
return
0;
73
return
(
height
+
sizeScale
[
plane
].
y
- 1)/
sizeScale
[
plane
].
y
;
74
}
75
76
/**
77
* \returns Plane scaling factors taking into account possible workarounds due to QRhi backend
78
* capabilities.
79
*/
80
SizeScale
rhiSizeScale
(
int
plane
,
QRhi
*
rhi
)
const
81
{
82
if
(!
rhi
)
83
return
sizeScale
[
plane
];
84
85
// NOTE: We need to handle sizing difference when packing two-component textures to RGBA8,
86
// where width gets cut in half.
87
// Another option would be to compare QRhiImplementation::TextureFormatInfo to expected
88
// based on TextureDescription::Format.
89
if
((
textureFormat
[
plane
] ==
TextureDescription
::
RG_8
90
||
textureFormat
[
plane
] ==
TextureDescription
::
Red_16
)
91
&&
rhiTextureFormat
(
plane
,
rhi
) ==
QRhiTexture
::
RGBA8
)
92
return
{
uint8_t
(
sizeScale
[
plane
].
x
* 2),
sizeScale
[
plane
].
y
};
93
94
return
sizeScale
[
plane
];
95
}
96
97
QSize
rhiPlaneSize
(
QSize
frameSize
,
int
plane
,
QRhi
*
rhi
)
const
98
{
99
SizeScale
scale
=
rhiSizeScale
(
plane
,
rhi
);
100
return
QSize
(
frameSize
.
width
() /
scale
.
x
,
frameSize
.
height
() /
scale
.
y
);
101
}
102
103
bool
hasTextureFormat
(
TextureFormat
format
)
const
104
{
105
return
std
::
any_of
(
textureFormat
,
textureFormat
+
nplanes
, [
format
](
TextureFormat
f
) {
106
return
f
==
format
;
107
});
108
}
109
110
const
uint8_t
nplanes
;
111
const
uint8_t
strideFactor
;
112
const
BytesRequired
bytesRequired
;
113
const
TextureFormat
textureFormat
[
maxPlanes
];
114
const
SizeScale
sizeScale
[
maxPlanes
];
115
};
116
117
Q_MULTIMEDIA_EXPORT
const
TextureDescription *
textureDescription
(
QVideoFrameFormat
::
PixelFormat
format
);
118
119
Q_MULTIMEDIA_EXPORT QString
vertexShaderFileName
(
const
QVideoFrameFormat
&
format
);
120
Q_MULTIMEDIA_EXPORT QString
121
fragmentShaderFileName
(
const
QVideoFrameFormat
&
format
,
QRhi
*
rhi
,
122
QRhiSwapChain
::
Format
surfaceFormat
=
QRhiSwapChain
::
SDR
);
123
Q_MULTIMEDIA_EXPORT
void
updateUniformData
(QByteArray *dst, QRhi *rhi,
124
const
QVideoFrameFormat &format,
125
const
QVideoFrame &frame,
const
QMatrix4x4 &transform,
126
float
opacity,
float
maxNits = 100);
127
128
/**
129
* @brief Creates plane textures from texture handles set by the specified rhi.
130
* The result owns the specified handles set; the QRhiTexture(s), exposed by the result
131
* refer to the owned handles set.
132
* If the specified size is empty or pixelFormat is invalid, null is returned.
133
*/
134
Q_MULTIMEDIA_EXPORT QVideoFrameTexturesUPtr
createTexturesFromHandles
(
135
QVideoFrameTexturesHandlesUPtr
handles
,
QRhi
&
rhi
,
136
QVideoFrameFormat
::
PixelFormat
pixelFormat
,
QSize
size
,
QVideoFrame
sourceFrame
= {});
137
138
/**
139
* @brief Creates plane textures from a video frame by the specified rhi.
140
If possible, the function modifies 'oldTextures', which is the texture from the pool,
141
and returns the specified one or a new one with any taken data.
142
*/
143
Q_MULTIMEDIA_EXPORT QVideoFrameTexturesUPtr
createTextures
(
const
QVideoFrame
&
frame
,
QRhi
&
rhi
,
144
QRhiResourceUpdateBatch
&
rub
,
145
QVideoFrameTexturesUPtr
&
oldTextures
);
146
147
/**
148
* @brief Returns a QRhiTexture::Format taking into account rhi capabilities and explicitly excluded
149
* formats using a chain of pre-defined fallback texture formats. If no valid fallback is
150
* determined, will return the format argument.
151
*/
152
Q_MULTIMEDIA_EXPORT
QRhiTexture
::
Format
153
resolvedRhiTextureFormat
(
QRhiTexture
::
Format
format
,
QRhi
*
rhi
);
154
155
Q_MULTIMEDIA_EXPORT
void
156
setExcludedRhiTextureFormats
(QList<QRhiTexture::Format> formats);
// for tests only
157
158
Q_MULTIMEDIA_EXPORT
bool
159
forceGlTextureExternalOesIsSet
();
160
161
// override QT_MULTIMEDIA_FORCE_GL_TEXTURE_EXTERNAL_OES
162
Q_MULTIMEDIA_EXPORT
void
setForceGlTextureExternalOesIsSet
(
bool
);
163
164
struct
UniformData
{
165
float
transformMatrix
[4][4];
166
float
colorMatrix
[4][4];
167
float
opacity
;
168
float
width
;
169
float
masteringWhite
;
170
float
maxLum
;
171
int
redOrAlphaIndex
;
172
int
planeFormats
[
TextureDescription
::
maxPlanes
];
173
};
174
175
struct
Q_MULTIMEDIA_EXPORT
SubtitleLayout
176
{
177
QSize
videoSize
;
178
QRectF
bounds
;
179
QTextLayout
layout
;
180
181
bool
update
(
const
QSize
&
frameSize
,
QString
text
);
182
void
draw
(
QPainter
*
painter
,
const
QPointF
&
translate
)
const
;
183
QImage
toImage
()
const
;
184
};
185
186
}
// namespace QVideoTextureHelper
187
188
QT_END_NAMESPACE
189
190
#
endif
QVideoTextureHelper::QVideoFrameTexturesFromHandlesSet::takeHandles
QVideoFrameTexturesHandlesUPtr takeHandles() override
Definition
qvideoframetexturefromsource.cpp:64
QVideoTextureHelper::QVideoFrameTexturesFromHandlesSet::QVideoFrameTexturesFromHandlesSet
QVideoFrameTexturesFromHandlesSet(RhiTextureArray &&rhiTextures, QVideoFrameTexturesHandlesUPtr handles, QVideoFrame sourceFrame={})
Definition
qvideoframetexturefromsource.cpp:53
QVideoTextureHelper::QVideoFrameTexturesFromHandlesSet::~QVideoFrameTexturesFromHandlesSet
~QVideoFrameTexturesFromHandlesSet() override
QVideoTextureHelper::QVideoFrameTexturesFromMemory::onFrameEndInvoked
void onFrameEndInvoked() override
The virtual method should be invoked after QRhi::endFrame to unmap and free internal resources that a...
Definition
qvideoframetexturefromsource.cpp:45
QVideoTextureHelper::QVideoFrameTexturesFromMemory::QVideoFrameTexturesFromMemory
QVideoFrameTexturesFromMemory(RhiTextureArray &&rhiTextures, QVideoFrame mappedFrame={})
Definition
qvideoframetexturefromsource.cpp:29
QVideoTextureHelper::QVideoFrameTexturesFromMemory::~QVideoFrameTexturesFromMemory
~QVideoFrameTexturesFromMemory() override
Definition
qvideoframetexturefromsource.cpp:40
QVideoTextureHelper::QVideoFrameTexturesFromRhiTextureArray
Definition
qvideoframetexturefromsource_p.h:30
QVideoTextureHelper::QVideoFrameTexturesFromRhiTextureArray::QVideoFrameTexturesFromRhiTextureArray
QVideoFrameTexturesFromRhiTextureArray(RhiTextureArray &&rhiTextures, QVideoFrame sourceFrame={})
Definition
qvideoframetexturefromsource.cpp:10
QVideoTextureHelper::QVideoFrameTexturesFromRhiTextureArray::texture
QRhiTexture * texture(uint plane) const override
Definition
qvideoframetexturefromsource.cpp:19
QVideoTextureHelper::QVideoFrameTexturesFromRhiTextureArray::takeTextureArray
RhiTextureArray takeTextureArray() &&
Definition
qvideoframetexturefromsource.cpp:24
QVideoTextureHelper::QVideoFrameTexturesFromRhiTextureArray::textureArray
const RhiTextureArray & textureArray() const
Definition
qvideoframetexturefromsource_p.h:40
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QVideoTextureHelper
Definition
qvideoframetexturefromsource_p.h:25
QVideoTextureHelper::setExcludedRhiTextureFormats
void setExcludedRhiTextureFormats(QList< QRhiTexture::Format > formats)
Definition
qvideotexturehelper.cpp:340
QVideoTextureHelper::forceGlTextureExternalOesIsSet
bool forceGlTextureExternalOesIsSet()
Definition
qvideotexturehelper.cpp:40
QVideoTextureHelper::updateUniformData
void updateUniformData(QByteArray *dst, QRhi *rhi, const QVideoFrameFormat &format, const QVideoFrame &frame, const QMatrix4x4 &transform, float opacity, float maxNits)
Definition
qvideotexturehelper.cpp:610
QVideoTextureHelper::setForceGlTextureExternalOesIsSet
void setForceGlTextureExternalOesIsSet(bool isSet)
Definition
qvideotexturehelper.cpp:45
QVideoTextureHelper::SubtitleLayout
Definition
qvideotexturehelper_p.h:176
QVideoTextureHelper::TextureDescription
Definition
qvideotexturehelper_p.h:36
QVideoTextureHelper::UniformData
Definition
qvideotexturehelper_p.h:164
QVideoTextureHelper::UniformData::maxLum
float maxLum
Definition
qvideotexturehelper_p.h:170
QVideoTextureHelper::UniformData::width
float width
Definition
qvideotexturehelper_p.h:168
QVideoTextureHelper::UniformData::opacity
float opacity
Definition
qvideotexturehelper_p.h:167
QVideoTextureHelper::UniformData::planeFormats
int planeFormats[TextureDescription::maxPlanes]
Definition
qvideotexturehelper_p.h:172
QVideoTextureHelper::UniformData::masteringWhite
float masteringWhite
Definition
qvideotexturehelper_p.h:169
QVideoTextureHelper::UniformData::redOrAlphaIndex
int redOrAlphaIndex
Definition
qvideotexturehelper_p.h:171
QVideoTextureHelper::UniformData::transformMatrix
float transformMatrix[4][4]
Definition
qvideotexturehelper_p.h:165
QVideoTextureHelper::UniformData::colorMatrix
float colorMatrix[4][4]
Definition
qvideotexturehelper_p.h:166
qtmultimedia
src
multimedia
video
qvideotexturehelper_p.h
Generated on
for Qt by
1.18.0