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
qvideowindow_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 QVIDEOWINDOW_P_H
5#define QVIDEOWINDOW_P_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 <QWindow>
19#include <QOffscreenSurface>
20#include <qtextlayout.h>
21#include <rhi/qrhi.h>
22#include <qvideoframe.h>
23#include <private/qplatformvideosink_p.h>
24#include <private/qvideotexturehelper_p.h>
25#include <private/qvideoframetexturepool_p.h>
26#include <qbackingstore.h>
27
28#include <functional>
29#include <optional>
30
31QT_BEGIN_NAMESPACE
32
33class QVideoWindow;
34
35class Q_MULTIMEDIA_EXPORT QVideoWindowPrivate
36{
37public:
38 static void setGraphicsApiOverride(std::optional<QRhi::Implementation> api);
39
40 QVideoWindowPrivate(QVideoWindow *q);
41 ~QVideoWindowPrivate();
42 bool canRender() const { return m_useRhi; }
43
44 static QVideoWindowPrivate *get(QVideoWindow *q);
45
46 QRhi *rhi() const { return m_rhi.get(); }
47
48 void init();
49 void render();
50
51 void initRhi();
52
53 void resizeSwapChain();
54 void releaseSwapChain();
55
56 void updateTextures(QRhiResourceUpdateBatch *rub);
57 void updateSubtitle(QRhiResourceUpdateBatch *rub, const QSize &frameSize);
58
59 void setupGraphicsPipeline(QRhiGraphicsPipeline *pipeline, QRhiShaderResourceBindings *bindings, const QVideoFrameFormat &fmt);
60
61 void setPostRenderHookForTests(std::function<void(QRhi &, QRhiCommandBuffer &)> hook);
62
63 QVideoWindow *q = nullptr;
64 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio;
65
66 QBackingStore *backingStore = nullptr;
67
68#if QT_CONFIG(opengl)
69 std::unique_ptr<QOffscreenSurface> m_fallbackSurface;
70#endif
71 std::unique_ptr<QRhi> m_rhi;
72 std::unique_ptr<QRhiSwapChain> m_swapChain;
73 std::unique_ptr<QRhiRenderPassDescriptor> m_renderPass;
74
75 std::unique_ptr<QRhiBuffer> m_vertexBuf;
76 bool m_vertexBufReady = false;
77 std::unique_ptr<QRhiBuffer> m_uniformBuf;
78 std::unique_ptr<QRhiSampler> m_textureSampler;
79 std::unique_ptr<QRhiShaderResourceBindings> m_shaderResourceBindings;
80 std::unique_ptr<QRhiGraphicsPipeline> m_graphicsPipeline;
81
82 std::unique_ptr<QRhiTexture> m_subtitleTexture;
83 std::unique_ptr<QRhiShaderResourceBindings> m_subtitleResourceBindings;
84 std::unique_ptr<QRhiGraphicsPipeline> m_subtitlePipeline;
85 std::unique_ptr<QRhiBuffer> m_subtitleUniformBuf;
86
87 std::unique_ptr<QVideoSink> m_sink;
88 std::function<void(QRhi &, QRhiCommandBuffer &)> m_postRenderHookForTests;
89 QRhi::Implementation m_graphicsApi = QRhi::Null;
90 QVideoTextureHelper::SubtitleLayout m_subtitleLayout;
91 QVideoFrameTexturePool m_texturePool;
92
93 bool initialized = false;
94 bool isExposed = false;
95 bool m_useRhi = true;
96 bool m_hasSwapChain = false;
97 bool m_subtitleDirty = false;
98 bool m_hasSubtitle = false;
99 QVideoFrameFormat format;
100};
101
102class Q_MULTIMEDIA_EXPORT QVideoWindow : public QWindow
103{
104 Q_OBJECT
105public:
106 explicit QVideoWindow(QScreen *screen = nullptr);
107 explicit QVideoWindow(QWindow *parent);
108 ~QVideoWindow() override;
109
110 Q_INVOKABLE QVideoSink *videoSink() const;
111
112 Qt::AspectRatioMode aspectRatioMode() const;
113
114public Q_SLOTS:
115 void setAspectRatioMode(Qt::AspectRatioMode mode);
116
117Q_SIGNALS:
118 void aspectRatioModeChanged(Qt::AspectRatioMode mode);
119
120protected:
121 bool event(QEvent *e) override;
122 void resizeEvent(QResizeEvent *) override;
123
124private Q_SLOTS:
125 void setVideoFrame(const QVideoFrame &frame);
126
127private:
128 friend class QVideoWindowPrivate;
129 std::unique_ptr<QVideoWindowPrivate> d;
130};
131
132inline QVideoWindowPrivate *QVideoWindowPrivate::get(QVideoWindow *q)
133{
134 return q->d.get();
135}
136
137QT_END_NAMESPACE
138
139#endif
Combined button and popup list for selecting options.
std::optional< QRhi::Implementation > g_graphicsApiOverride
QSurface::SurfaceType platformSurfaceType()
QSurface::SurfaceType surfaceTypeFor(QRhi::Implementation graphicsApi)
static const float g_vw_quad[]
static QShader vwGetShader(const QString &name)