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
qwasmgltexturevideobuffer_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
4#ifndef QWASMGLTEXTUREVIDEOBUFFER_H
5#define QWASMGLTEXTUREVIDEOBUFFER_H
6
7#include <QtGui/rhi/qrhi.h>
8#include <QSize>
9#include <QThread>
10
11#include <QtMultimedia/private/qhwvideobuffer_p.h>
12#include "qvideoframe.h"
13
14#include <QtCore/private/quniquehandle_p.h>
15
16#include <emscripten/val.h>
17#include <emscripten/html5.h>
18#include <GLES2/gl2.h>
19
20//
21// W A R N I N G
22// -------------
23//
24// This file is not part of the Qt API. It exists purely as an
25// implementation detail. This header file may change from version to
26// version without notice, or even be removed.
27//
28// We mean it.
29//
30
31QT_BEGIN_NAMESPACE
32
33struct QGlTextureHandleTraits
34{
35 using Type = GLuint;
36 static Type invalidValue() { return 0; }
37 static bool close(Type handle)
38 {
39 glDeleteTextures(1, &handle);
40 return true;
41 }
42};
43using QGlTextureHandle = QUniqueHandle<QGlTextureHandleTraits>;
44
46{
47public:
48 explicit QWasmGLTextureVideoBuffer(QGlTextureHandle textureHandle, const QSize &size,
49 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE glContext, QRhi *rhi);
50
52 void unmap() override;
53
54 QVideoFrameFormat format() const override { return m_videoFrameFormat; }
55 quint64 textureHandle(QRhi &, int plane) override;
56
57 // Must return the RHI that owns the WebGL context the texture lives in.
58 // Without this, qImageFromVideoFrame() calls qEnsureThreadLocalRhi()
59 // which creates a second WebGL context, corrupting the GL state for the
60 // QQuick render loop that resumes after toImage() returns.
62 {
63 return (QThread::currentThread() == m_rhiThread) ? m_rhi : nullptr;
64 }
65
66private:
67 QGlTextureHandle m_glTextureHandle;
68 QSize m_size;
69 QVideoFrameFormat m_videoFrameFormat;
70 // WebGL context the texture was created in
71 EMSCRIPTEN_WEBGL_CONTEXT_HANDLE m_glContext;
72 QRhi *m_rhi;
73 QThread *m_rhiThread;
74};
75
76QT_END_NAMESPACE
77
78#endif // QWASMGLTEXTUREVIDEOBUFFER_H
QVideoFrameFormat format() const override
Gets \l QVideoFrameFormat of the underlying video buffer.
quint64 textureHandle(QRhi &, int plane) override
void unmap() override
Releases the memory mapped by the map() function.
QWasmGLTextureVideoBuffer(QGlTextureHandle textureHandle, const QSize &size, EMSCRIPTEN_WEBGL_CONTEXT_HANDLE glContext, QRhi *rhi)
QWasmGLTextureVideoBuffer::MapData map(QVideoFrame::MapMode) override
Maps the planes of a video buffer to memory.
QRhi * associatedCurrentThreadRhi() const override
Combined button and popup list for selecting options.