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