| 1 | // Copyright (C) 2024 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 QVIDEOFRAMETEXTUREPOOL_P_H | 
| 5 | #define QVIDEOFRAMETEXTUREPOOL_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 "qvideoframe.h" | 
| 19 | #include "qhwvideobuffer_p.h" | 
| 20 |  | 
| 21 | #include <array> | 
| 22 | #include <optional> | 
| 23 |  | 
| 24 | QT_BEGIN_NAMESPACE | 
| 25 |  | 
| 26 | class QRhi; | 
| 27 | class QRhiResourceUpdateBatch; | 
| 28 |  | 
| 29 | /** | 
| 30 |  * @brief The class QVideoFrameTexturePool stores textures in slots to ensure | 
| 31 |  *        they are alive during rhi's rendering rounds. | 
| 32 |  *        Depending on the rhi backend, 1, 2, or 3 rounds are needed | 
| 33 |  *        to complete the texture presentaton. | 
| 34 |  *        The strategy of slots filling is based on QRhi::currentFrameSlot results. | 
| 35 |  */ | 
| 36 | class Q_MULTIMEDIA_EXPORT QVideoFrameTexturePool { | 
| 37 |     static constexpr size_t MaxSlotsCount = 4; | 
| 38 | public: | 
| 39 |     /** | 
| 40 |      * @brief The flag indicates whether the textures need update. | 
| 41 |      *        Whenever a new current frame is set, the flag is turning into true. | 
| 42 |      */ | 
| 43 |     bool texturesDirty() const { return m_texturesDirty; } | 
| 44 |  | 
| 45 |     const QVideoFrame& currentFrame() const { return m_currentFrame; } | 
| 46 |  | 
| 47 |     /** | 
| 48 |      * @brief The method sets the current frame to be converted into textures. | 
| 49 |      *        The flag texturesDirty becomes true after setting a new frame. | 
| 50 |      */ | 
| 51 |     void setCurrentFrame(QVideoFrame frame); | 
| 52 |  | 
| 53 |     /** | 
| 54 |      * @brief The method updates textures basing on the current frame. | 
| 55 |      *        It's recommended to invoke it during rhi's rendering, | 
| 56 |      *        in other words, between QRhi::beginFrame and QRhi::endFrame. | 
| 57 |      *        The method resets texturesDirty to false. | 
| 58 |      * | 
| 59 |      * @return the pointer to the updated texture or null if failed | 
| 60 |      */ | 
| 61 |     QVideoFrameTextures* updateTextures(QRhi &rhi, QRhiResourceUpdateBatch &rub); | 
| 62 |  | 
| 63 |     /** | 
| 64 |      * @brief The method should be invoked after finishing QRhi::endFrame. | 
| 65 |      *        It propagates the call to the current texture in order to | 
| 66 |      *        free resources that are not needed anymore. | 
| 67 |      */ | 
| 68 |     void onFrameEndInvoked(); | 
| 69 |  | 
| 70 |     /** | 
| 71 |      * @brief The method clears all texture slots and sets the dirty flag if | 
| 72 |      *        the current frame is valid. | 
| 73 |      */ | 
| 74 |     void clearTextures(); | 
| 75 |  | 
| 76 | private: | 
| 77 |     QVideoFrame m_currentFrame; | 
| 78 |     bool m_texturesDirty = false; | 
| 79 |     std::array<QVideoFrameTexturesUPtr, MaxSlotsCount> m_textureSlots; | 
| 80 |     std::optional<int> m_currentSlot; | 
| 81 | }; | 
| 82 |  | 
| 83 | QT_END_NAMESPACE | 
| 84 |  | 
| 85 | #endif // QVIDEOFRAMETEXTUREPOOL_P_H | 
| 86 |  |