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 | #include "qvideoframetexturepool_p.h" |
5 | #include "qvideotexturehelper_p.h" |
6 | |
7 | #include <rhi/qrhi.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | void QVideoFrameTexturePool::setCurrentFrame(QVideoFrame frame) { |
12 | m_texturesDirty = true; |
13 | m_currentFrame = std::move(frame); |
14 | } |
15 | |
16 | QVideoFrameTextures* QVideoFrameTexturePool::updateTextures(QRhi &rhi, QRhiResourceUpdateBatch &rub) { |
17 | const int currentSlot = rhi.currentFrameSlot(); |
18 | Q_ASSERT(size_t(currentSlot) < MaxSlotsCount); |
19 | |
20 | m_texturesDirty = false; |
21 | QVideoFrameTexturesUPtr &textures = m_textureSlots[currentSlot]; |
22 | textures = QVideoTextureHelper::createTextures(frame: m_currentFrame, rhi, rub, oldTextures: std::move(textures)); |
23 | m_currentSlot = textures ? currentSlot : std::optional<int>{}; |
24 | |
25 | return textures.get(); |
26 | } |
27 | |
28 | void QVideoFrameTexturePool::onFrameEndInvoked() |
29 | { |
30 | if (m_currentSlot && m_textureSlots[*m_currentSlot]) |
31 | m_textureSlots[*m_currentSlot]->onFrameEndInvoked(); |
32 | } |
33 | |
34 | void QVideoFrameTexturePool::clearTextures() |
35 | { |
36 | std::fill(first: std::begin(cont&: m_textureSlots), last: std::end(cont&: m_textureSlots), value: nullptr); |
37 | m_currentSlot.reset(); |
38 | m_texturesDirty = m_currentFrame.isValid(); |
39 | } |
40 | |
41 | QT_END_NAMESPACE |
42 |