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