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 <qbackingstore.h> |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QVideoWindow; |
30 | |
31 | class QVideoWindowPrivate { |
32 | public: |
33 | QVideoWindowPrivate(QVideoWindow *q); |
34 | ~QVideoWindowPrivate(); |
35 | bool canRender() const { return m_useRhi; } |
36 | |
37 | QRhi *rhi() const { return m_rhi.get(); } |
38 | |
39 | void init(); |
40 | void render(); |
41 | |
42 | void initRhi(); |
43 | |
44 | void resizeSwapChain(); |
45 | void releaseSwapChain(); |
46 | |
47 | void updateTextures(QRhiResourceUpdateBatch *rub); |
48 | void updateSubtitle(QRhiResourceUpdateBatch *rub, const QSize &frameSize); |
49 | |
50 | void setupGraphicsPipeline(QRhiGraphicsPipeline *pipeline, QRhiShaderResourceBindings *bindings, const QVideoFrameFormat &fmt); |
51 | |
52 | QVideoWindow *q = nullptr; |
53 | Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio; |
54 | |
55 | QBackingStore *backingStore = nullptr; |
56 | |
57 | #if QT_CONFIG(opengl) |
58 | std::unique_ptr<QOffscreenSurface> m_fallbackSurface; |
59 | #endif |
60 | std::unique_ptr<QRhi> m_rhi; |
61 | std::unique_ptr<QRhiSwapChain> m_swapChain; |
62 | std::unique_ptr<QRhiRenderPassDescriptor> m_renderPass; |
63 | |
64 | std::unique_ptr<QRhiBuffer> m_vertexBuf; |
65 | bool m_vertexBufReady = false; |
66 | std::unique_ptr<QRhiBuffer> m_uniformBuf; |
67 | std::unique_ptr<QVideoFrameTextures> m_frameTextures; |
68 | std::unique_ptr<QRhiSampler> m_textureSampler; |
69 | std::unique_ptr<QRhiShaderResourceBindings> m_shaderResourceBindings; |
70 | std::unique_ptr<QRhiGraphicsPipeline> m_graphicsPipeline; |
71 | |
72 | std::unique_ptr<QRhiTexture> m_subtitleTexture; |
73 | std::unique_ptr<QRhiShaderResourceBindings> m_subtitleResourceBindings; |
74 | std::unique_ptr<QRhiGraphicsPipeline> m_subtitlePipeline; |
75 | std::unique_ptr<QRhiBuffer> m_subtitleUniformBuf; |
76 | |
77 | std::unique_ptr<QVideoSink> m_sink; |
78 | QRhi::Implementation m_graphicsApi = QRhi::Null; |
79 | QVideoFrame m_currentFrame; |
80 | QVideoTextureHelper::SubtitleLayout m_subtitleLayout; |
81 | |
82 | enum { NVideoFrameSlots = 4 }; |
83 | QVideoFrame m_videoFrameSlots[NVideoFrameSlots]; |
84 | |
85 | bool initialized = false; |
86 | bool isExposed = false; |
87 | bool m_useRhi = true; |
88 | bool m_hasSwapChain = false; |
89 | bool m_texturesDirty = true; |
90 | bool m_subtitleDirty = false; |
91 | bool m_hasSubtitle = false; |
92 | QVideoFrameFormat format; |
93 | }; |
94 | |
95 | class Q_MULTIMEDIA_EXPORT QVideoWindow : public QWindow |
96 | { |
97 | Q_OBJECT |
98 | public: |
99 | explicit QVideoWindow(QScreen *screen = nullptr); |
100 | explicit QVideoWindow(QWindow *parent); |
101 | ~QVideoWindow(); |
102 | |
103 | Q_INVOKABLE QVideoSink *videoSink() const; |
104 | |
105 | Qt::AspectRatioMode aspectRatioMode() const; |
106 | |
107 | public Q_SLOTS: |
108 | void setAspectRatioMode(Qt::AspectRatioMode mode); |
109 | |
110 | Q_SIGNALS: |
111 | void aspectRatioModeChanged(Qt::AspectRatioMode mode); |
112 | |
113 | protected: |
114 | bool event(QEvent *e) override; |
115 | void resizeEvent(QResizeEvent *) override; |
116 | |
117 | private Q_SLOTS: |
118 | void setVideoFrame(const QVideoFrame &frame); |
119 | |
120 | private: |
121 | friend class QVideoWindowPrivate; |
122 | std::unique_ptr<QVideoWindowPrivate> d; |
123 | }; |
124 | |
125 | QT_END_NAMESPACE |
126 | |
127 | #endif |
128 |