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
qhwvideobuffer_p.h
Go to the documentation of this file.
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 QHWVIDEOBUFFER_P_H
5#define QHWVIDEOBUFFER_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
19#include "qvideoframe.h"
20
21#include <QtGui/qmatrix4x4.h>
22
23#include <optional>
24
25QT_BEGIN_NAMESPACE
26
27class QRhi;
28class QRhiTexture;
29class QVideoFrame;
30
31/**
32 * @brief QVideoFrameTexturesHandles is the base class, providing texture handles for frame planes.
33 * Instances of the class may own textures, share ownership, or refer to inner hw textures
34 * of QVideoFrame. Referencing to inner frame's textures without shared ownership is
35 * not recommended, we strive to get around it; if texture are referencing,
36 * the source frame is kept in the QVideoFrameTextures instance via its
37 * constructor-provided source frame.
38 */
39class Q_MULTIMEDIA_EXPORT QVideoFrameTexturesHandles
40{
41public:
42 virtual ~QVideoFrameTexturesHandles();
43
44 virtual quint64 textureHandle(QRhi &, int /*plane*/) { return 0; }
45
46 // Set when the textures don't have the layout of the frame's pixel format, e.g. a
47 // single-image import, which exposes one texture for a multi-plane frame.
48 virtual std::optional<QVideoFrameFormat::PixelFormat> texturePixelFormat() const { return {}; }
49};
50using QVideoFrameTexturesHandlesUPtr = std::unique_ptr<QVideoFrameTexturesHandles>;
51
52/**
53 * @brief QVideoFrameTextures is the base class representing an abstraction layer
54 * between QVideoFrame's texture(s) and rhi's plane textures.
55 * QVideoFrameTextures must own the inner rhi textures or
56 * share ownership. QVideoFrameTextures instances are propagated to
57 * QVideoFrameTexturesPool, where their lifetime is managed
58 * according to results of QRhi::currentFrameSlot upon rendering.
59 *
60 */
61class Q_MULTIMEDIA_EXPORT QVideoFrameTextures
62{
63public:
64 explicit QVideoFrameTextures(QVideoFrame sourceFrame = {});
65 virtual ~QVideoFrameTextures();
66 virtual QRhiTexture *texture(uint plane) const = 0;
67
68 /**
69 * @brief The virtual method should be invoked after QRhi::endFrame to unmap and free
70 * internal resources that are not needed anymore.
71 */
72 virtual void onFrameEndInvoked() { }
73
74 virtual QVideoFrameTexturesHandlesUPtr takeHandles() { return nullptr; }
75
76private:
77 QVideoFrame m_sourceFrame;
78};
79using QVideoFrameTexturesUPtr = std::unique_ptr<QVideoFrameTextures>;
80
81class Q_MULTIMEDIA_EXPORT QHwVideoBuffer : public QAbstractVideoBuffer,
82 public QVideoFrameTexturesHandles
83{
84public:
85 QHwVideoBuffer();
86
87 ~QHwVideoBuffer() override;
88
89 // returns rhi in the current thread that has been associated with the frame
90 // during texture mapping or texture converter initialization.
91 virtual QRhi *associatedCurrentThreadRhi() const { return nullptr; }
92
93 QVideoFrameFormat format() const final
94 {
95 // invalid by design: we have to go through QVideoFramePrivate::createFrame
96 return {};
97 }
98
99 virtual QMatrix4x4 externalTextureMatrix() const { return {}; }
100
101 virtual QVideoFrameTexturesUPtr mapTextures(QRhi &rhi,
102 QVideoFrameTexturesUPtr & /*oldTextures*/)
103 {
104 return mapTextures(rhi);
105 }
106 virtual QVideoFrameTexturesUPtr mapTextures(QRhi &) { return nullptr; }
107
108 virtual void initTextureConverter(QRhi &) { }
109
110 virtual bool isDmaBuf() const { return false; }
111};
112
113QT_END_NAMESPACE
114
115#endif // QHWVIDEOBUFFER_P_H
QVideoFrameTexturesHandles is the base class, providing texture handles for frame planes....
QVideoFrameTextures is the base class representing an abstraction layer between QVideoFrame's texture...
static bool dmaModifierIsNotSupportedByDisplay(const DmaBufPlane &plane, EGLDisplay eglDisplay)
static bool isExternalOesOnly(const QEglImageFunctions &eglFunctions, EGLDisplay eglDisplay, const DmaBufPlane &plane)
q23::expected< QVideoFrameTexturesHandlesUPtr, FailureSeverity > importDmaBufTextures(QRhi &rhi, const DmaBufEglContext &eglContext, QSpan< const DmaBufPlane > planes, QVideoFrameFormat::PixelFormat qtFormat, QSize frameSize, std::shared_ptr< void > parentKeepAlive, DmaBufImportMode importMode)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)