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
qvivantetextureimporter_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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#ifndef QVIVANTETEXTUREIMPORTER_P_H
4#define QVIVANTETEXTUREIMPORTER_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
18
19#include <QtMultimedia/qvideoframeformat.h>
20#include <QtMultimedia/private/qdmabuftextureimporter_p.h>
21#include <QtMultimedia/private/qtmultimediaglobal_p.h>
22
23#include <QtGui/qopenglfunctions.h>
24
25#include <QtCore/qsize.h>
26#include <QtCore/private/qexpected_p.h>
27
28#include <EGL/egl.h>
29
30#include <memory>
31
32static_assert(QT_CONFIG(gpu_vivante));
33
34#ifndef GL_VIV_YV12
35#define GL_VIV_YV12 0x8FC0
36#endif
37#ifndef GL_VIV_NV12
38#define GL_VIV_NV12 0x8FC1
39#endif
40#ifndef GL_VIV_YUY2
41#define GL_VIV_YUY2 0x8FC2
42#endif
43#ifndef GL_VIV_UYVY
44#define GL_VIV_UYVY 0x8FC3
45#endif
46#ifndef GL_VIV_NV21
47#define GL_VIV_NV21 0x8FC4
48#endif
49#ifndef GL_VIV_I420
50#define GL_VIV_I420 0x8FC5
51#endif
52
53static_assert(GL_VIV_YV12 == 0x8FC0);
54static_assert(GL_VIV_NV12 == 0x8FC1);
55static_assert(GL_VIV_YUY2 == 0x8FC2);
56static_assert(GL_VIV_UYVY == 0x8FC3);
57static_assert(GL_VIV_NV21 == 0x8FC4);
58static_assert(GL_VIV_I420 == 0x8FC5);
59
60QT_BEGIN_NAMESPACE
61
62class QRhi;
63class QOpenGLContext;
64
65namespace QtMultimediaPrivate {
66
67class Q_MULTIMEDIA_EXPORT QVivanteGLFunctions
68{
70
71public:
72 static const QVivanteGLFunctions &instance();
73
74 bool isValid() const;
75
76 void glTexDirectVIVMap(GLenum target, GLsizei width, GLsizei height, GLenum format,
77 GLvoid **logical, const GLuint *physical) const;
78 void glTexDirectInvalidateVIV(GLenum target) const;
79
80private:
84 const GLuint *Physical);
85 typedef void(QOPENGLF_APIENTRYP PFNGLTEXDIRECTINVALIDATEVIVPROC)(GLenum Target);
86
87 PFNGLTEXDIRECTVIVMAPPROC m_glTexDirectVIVMap = nullptr;
88 PFNGLTEXDIRECTINVALIDATEVIVPROC m_glTexDirectInvalidateVIV = nullptr;
89};
90
91class Q_MULTIMEDIA_EXPORT VivanteContext
92{
93public:
94 explicit VivanteContext(QRhi *);
95
96 bool isValid() const { return m_valid; }
97
98 QOpenGLContext *glContext() const { return m_glContext; }
99
100private:
101 QOpenGLContext *m_glContext = nullptr;
102 bool m_valid = false;
103};
104
105// Owns exactly one GL texture id. Unlike DMA-BUF import (one EGLImage-backed
106// texture per plane), glTexDirectVIVMap produces a single combined texture
107// per frame: the format token tells the driver how to interpret/convert the
108// (possibly planar) memory, and the result is expected to already be
109// sampleable as plain RGB, with YUV->RGB conversion done by the driver, not
110// a downstream shader. textureHandle() returns that one texture regardless
111// of plane index; downstream code should treat this as single-plane RGB.
112class Q_MULTIMEDIA_EXPORT VivanteTextureHandles final : public QVideoFrameTexturesHandles
113{
114public:
115 VivanteTextureHandles(QRhi &, QOpenGLContext *glContext, GLuint texture,
116 std::shared_ptr<void> parentKeepAlive = {});
117
118 ~VivanteTextureHandles() override;
119
120 quint64 textureHandle(QRhi &, int /*plane*/) override { return m_texture; }
121
122private:
123 void release(QRhi &rhi);
124
125 const std::shared_ptr<void> m_parentKeepAlive; // keep the backend alive
126 QRhi& m_rhi;
127 QOpenGLContext *const m_glContext;
128 const GLuint m_texture;
129 bool m_released = false;
130};
131
132// physicalAddress is the actual 32-bit hardware address of the mapped
133// memory (e.g. from gst_phys_memory_get_phys_addr()), not a host pointer --
134// glTexDirectVIVMap's "Physical" parameter takes an array of such
135// addresses. logicalAddr must be a valid CPU-virtual mapping of the same
136// memory, kept mapped for as long as the texture exists (e.g. via
137// parentKeepAlive).
138Q_MULTIMEDIA_EXPORT q23::expected<QVideoFrameTexturesHandlesUPtr, FailureSeverity>
139importVivanteTexture(QRhi &, const VivanteContext &context, quint32 physicalAddress,
140 void *logicalAddr, QSize, GLenum vivFormatToken,
141 std::shared_ptr<void> parentKeepAlive = {});
142
143} // namespace QtMultimediaPrivate
144
145QT_END_NAMESPACE
146
147#endif // QVIVANTETEXTUREIMPORTER_P_H
void glTexDirectVIVMap(GLenum target, GLsizei width, GLsizei height, GLenum format, GLvoid **logical, const GLuint *physical) const
q23::expected< QVideoFrameTexturesHandlesUPtr, FailureSeverity > importVivanteTexture(QRhi &rhi, const VivanteContext &context, quint32 physicalAddress, void *logicalAddr, QSize size, GLenum vivFormatToken, std::shared_ptr< void > parentKeepAlive)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
#define GL_VIV_I420
#define GL_VIV_YUY2
#define GL_VIV_NV12
#define GL_VIV_UYVY
#define GL_VIV_YV12
#define GL_VIV_NV21