diff options
author | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2020-02-05 12:17:17 +0100 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2020-02-18 12:51:13 +0100 |
commit | 30034a140ca8aefa1986c9964ae1f30dcfef886e (patch) | |
tree | 797fbce757e150d48d00adbc0c1c0b85f7ec5bf1 /src | |
parent | b2606eed8fa46c3f81bb9b03ca10409a00ed134f (diff) |
Remove usage of QGL* APIs
QOpenGL API should be used instead.
Task-number: QTBUG-74409
Fixes: QTBUG-81902
Change-Id: I80d09cba79248451cf211eabd87651301ae18b63
Reviewed-by: Johan Helsing <johan.helsing@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/multimediawidgets/qgraphicsvideoitem.cpp | 4 | ||||
-rw-r--r-- | src/multimediawidgets/qpaintervideosurface.cpp | 90 | ||||
-rw-r--r-- | src/multimediawidgets/qpaintervideosurface_p.h | 13 | ||||
-rw-r--r-- | src/multimediawidgets/qvideowidget.cpp | 3 | ||||
-rw-r--r-- | src/multimediawidgets/qvideowidget_p.h | 2 |
5 files changed, 37 insertions, 75 deletions
diff --git a/src/multimediawidgets/qgraphicsvideoitem.cpp b/src/multimediawidgets/qgraphicsvideoitem.cpp index fae1f9048..7c0521471 100644 --- a/src/multimediawidgets/qgraphicsvideoitem.cpp +++ b/src/multimediawidgets/qgraphicsvideoitem.cpp @@ -49,7 +49,7 @@ #include <QtCore/qpointer.h> #if QT_CONFIG(opengl) -#include <QtOpenGL/qgl.h> +#include <QOpenGLContext> #endif QT_BEGIN_NAMESPACE @@ -395,7 +395,7 @@ void QGraphicsVideoItem::paint( if (painter->paintEngine()->type() == QPaintEngine::OpenGL || painter->paintEngine()->type() == QPaintEngine::OpenGL2) { - d->surface->setGLContext(const_cast<QGLContext *>(QGLContext::currentContext())); + d->surface->updateGLContext(); if (d->surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) { d->surface->setShaderType(QPainterVideoSurface::GlslShader); } else { diff --git a/src/multimediawidgets/qpaintervideosurface.cpp b/src/multimediawidgets/qpaintervideosurface.cpp index 1c8e2dd63..5fe76d869 100644 --- a/src/multimediawidgets/qpaintervideosurface.cpp +++ b/src/multimediawidgets/qpaintervideosurface.cpp @@ -47,9 +47,9 @@ #include <private/qmediaopenglhelper_p.h> #if QT_CONFIG(opengl) -#include <qglshaderprogram.h> -#include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLFunctions> +#include <QOpenGLContext> +#include <QOpenGLFunctions> +#include <QOpenGLShaderProgram> #include <QtGui/QWindow> #ifndef GL_CLAMP_TO_EDGE #define GL_CLAMP_TO_EDGE 0x812F @@ -57,15 +57,6 @@ #ifndef GL_RGB8 #define GL_RGB8 0x8051 #endif - -static void makeCurrent(QGLContext *context) -{ - context->makeCurrent(); - - auto handle = context->contextHandle(); - if (handle && QOpenGLContext::currentContext() != handle) - handle->makeCurrent(handle->surface()); -} #endif #include <QtDebug> @@ -264,7 +255,7 @@ void QVideoSurfaceGenericPainter::updateColors(int, int, int, int) class QVideoSurfaceGLPainter : public QVideoSurfacePainter, protected QOpenGLFunctions { public: - QVideoSurfaceGLPainter(QGLContext *context); + QVideoSurfaceGLPainter(QOpenGLContext *context); ~QVideoSurfaceGLPainter(); QList<QVideoFrame::PixelFormat> supportedPixelFormats( QAbstractVideoBuffer::HandleType handleType) const override; @@ -292,17 +283,12 @@ protected: || format.pixelFormat() == QVideoFrame::Format_ARGB32); } -#if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC) - typedef void (APIENTRY *_glActiveTexture) (GLenum); - _glActiveTexture glActiveTexture; -#endif - QList<QVideoFrame::PixelFormat> m_imagePixelFormats; QList<QVideoFrame::PixelFormat> m_glPixelFormats; QMatrix4x4 m_colorMatrix; QVideoFrame m_frame; - QGLContext *m_context; + QOpenGLContext *m_context; QAbstractVideoBuffer::HandleType m_handleType; QVideoSurfaceFormat::Direction m_scanLineDirection; bool m_mirrored; @@ -320,7 +306,7 @@ protected: bool m_yuv; }; -QVideoSurfaceGLPainter::QVideoSurfaceGLPainter(QGLContext *context) +QVideoSurfaceGLPainter::QVideoSurfaceGLPainter(QOpenGLContext *context) : m_context(context) , m_handleType(QAbstractVideoBuffer::NoHandle) , m_scanLineDirection(QVideoSurfaceFormat::TopToBottom) @@ -332,10 +318,6 @@ QVideoSurfaceGLPainter::QVideoSurfaceGLPainter(QGLContext *context) , m_textureCount(0) , m_yuv(false) { -#if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC) - glActiveTexture = (_glActiveTexture)m_context->getProcAddress(QLatin1String("glActiveTexture")); -#endif - memset(m_textureIds, 0, sizeof(m_textureIds)); memset(m_textureWidths, 0, sizeof(m_textureWidths)); memset(m_textureHeights, 0, sizeof(m_textureHeights)); @@ -404,8 +386,6 @@ QAbstractVideoSurface::Error QVideoSurfaceGLPainter::setCurrentFrame(const QVide glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } else if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) { - makeCurrent(m_context); - for (int i = 0; i < m_textureCount; ++i) { glBindTexture(GL_TEXTURE_2D, m_textureIds[i]); glTexImage2D( @@ -680,7 +660,7 @@ static const char *qt_arbfp_ayuvShaderProgram = class QVideoSurfaceArbFpPainter : public QVideoSurfaceGLPainter { public: - QVideoSurfaceArbFpPainter(QGLContext *context); + QVideoSurfaceArbFpPainter(QOpenGLContext *context); QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) override; void stop() override; @@ -707,20 +687,20 @@ private: QSize m_frameSize; }; -QVideoSurfaceArbFpPainter::QVideoSurfaceArbFpPainter(QGLContext *context) +QVideoSurfaceArbFpPainter::QVideoSurfaceArbFpPainter(QOpenGLContext *context) : QVideoSurfaceGLPainter(context) , m_programId(0) { glProgramStringARB = (_glProgramStringARB) m_context->getProcAddress( - QLatin1String("glProgramStringARB")); + QByteArray("glProgramStringARB")); glBindProgramARB = (_glBindProgramARB) m_context->getProcAddress( - QLatin1String("glBindProgramARB")); + QByteArray("glBindProgramARB")); glDeleteProgramsARB = (_glDeleteProgramsARB) m_context->getProcAddress( - QLatin1String("glDeleteProgramsARB")); + QByteArray("glDeleteProgramsARB")); glGenProgramsARB = (_glGenProgramsARB) m_context->getProcAddress( - QLatin1String("glGenProgramsARB")); + QByteArray("glGenProgramsARB")); glProgramLocalParameter4fARB = (_glProgramLocalParameter4fARB) m_context->getProcAddress( - QLatin1String("glProgramLocalParameter4fARB")); + QByteArray("glProgramLocalParameter4fARB")); m_imagePixelFormats << QVideoFrame::Format_RGB32 @@ -746,8 +726,6 @@ QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::start(const QVideoSurfac QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError; - makeCurrent(m_context); - const char *program = 0; if (format.handleType() == QAbstractVideoBuffer::NoHandle) { @@ -871,8 +849,6 @@ QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::start(const QVideoSurfac void QVideoSurfaceArbFpPainter::stop() { if (m_context) { - makeCurrent(m_context); - if (m_handleType != QAbstractVideoBuffer::GLTextureHandle) glDeleteTextures(m_textureCount, m_textureIds); glDeleteProgramsARB(1, &m_programId); @@ -1079,7 +1055,7 @@ static const char *qt_glsl_ayuvShaderProgram = class QVideoSurfaceGlslPainter : public QVideoSurfaceGLPainter { public: - QVideoSurfaceGlslPainter(QGLContext *context); + QVideoSurfaceGlslPainter(QOpenGLContext *context); QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) override; void stop() override; @@ -1088,11 +1064,11 @@ public: const QRectF &target, QPainter *painter, const QRectF &source) override; private: - QGLShaderProgram m_program; + QOpenGLShaderProgram m_program; QSize m_frameSize; }; -QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QGLContext *context) +QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QOpenGLContext *context) : QVideoSurfaceGLPainter(context) , m_program(context) { @@ -1100,7 +1076,7 @@ QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QGLContext *context) << QVideoFrame::Format_RGB32 << QVideoFrame::Format_BGR32 << QVideoFrame::Format_ARGB32; - if (!context->contextHandle()->isOpenGLES()) { + if (!context->isOpenGLES()) { m_imagePixelFormats << QVideoFrame::Format_RGB24 << QVideoFrame::Format_BGR24; @@ -1124,8 +1100,6 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurface QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError; - makeCurrent(m_context); - const char *fragmentProgram = 0; if (format.handleType() == QAbstractVideoBuffer::NoHandle) { @@ -1143,13 +1117,13 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurface fragmentProgram = qt_glsl_argbShaderProgram; break; case QVideoFrame::Format_RGB24: - if (!m_context->contextHandle()->isOpenGLES()) { + if (!m_context->isOpenGLES()) { initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); fragmentProgram = qt_glsl_rgbShaderProgram; } break; case QVideoFrame::Format_BGR24: - if (!m_context->contextHandle()->isOpenGLES()) { + if (!m_context->isOpenGLES()) { initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize()); fragmentProgram = qt_glsl_argbShaderProgram; } @@ -1202,11 +1176,11 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurface if (!fragmentProgram) { error = QAbstractVideoSurface::UnsupportedFormatError; - } else if (!m_program.addShaderFromSourceCode(QGLShader::Vertex, qt_glsl_vertexShaderProgram)) { + } else if (!m_program.addShaderFromSourceCode(QOpenGLShader::Vertex, qt_glsl_vertexShaderProgram)) { qWarning("QPainterVideoSurface: Vertex shader compile error %s", qPrintable(m_program.log())); error = QAbstractVideoSurface::ResourceError; - } else if (!m_program.addShaderFromSourceCode(QGLShader::Fragment, fragmentProgram)) { + } else if (!m_program.addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentProgram)) { qWarning("QPainterVideoSurface: Shader compile error %s", qPrintable(m_program.log())); error = QAbstractVideoSurface::ResourceError; m_program.removeAllShaders(); @@ -1231,8 +1205,6 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurface void QVideoSurfaceGlslPainter::stop() { if (m_context) { - makeCurrent(m_context); - if (m_handleType != QAbstractVideoBuffer::GLTextureHandle) glDeleteTextures(m_textureCount, m_textureIds); } @@ -1611,35 +1583,33 @@ void QPainterVideoSurface::paint(QPainter *painter, const QRectF &target, const /*! */ -const QGLContext *QPainterVideoSurface::glContext() const +const QOpenGLContext *QPainterVideoSurface::glContext() const { return m_glContext; } /*! */ -void QPainterVideoSurface::setGLContext(QGLContext *context) +void QPainterVideoSurface::updateGLContext() { - if (m_glContext == context) + auto oldContext = m_glContext; + m_glContext = QOpenGLContext::currentContext(); + if (oldContext == m_glContext) return; - m_glContext = context; - m_shaderTypes = NoShaders; if (m_glContext) { //Set a dynamic property to access the OpenGL context - this->setProperty("GLContext", QVariant::fromValue<QObject*>(m_glContext->contextHandle())); - - makeCurrent(m_glContext); + this->setProperty("GLContext", QVariant::fromValue<QObject *>(m_glContext)); const QByteArray extensions(reinterpret_cast<const char *>( - context->contextHandle()->functions()->glGetString(GL_EXTENSIONS))); + m_glContext->functions()->glGetString(GL_EXTENSIONS))); #if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC) if (extensions.contains("ARB_fragment_program")) m_shaderTypes |= FragmentProgramShader; #endif - if (QGLShaderProgram::hasOpenGLShaderPrograms(m_glContext) + if (QOpenGLShaderProgram::hasOpenGLShaderPrograms(m_glContext) #if !defined(QT_OPENGL_ES_2) && !defined(QT_OPENGL_DYNAMIC) && extensions.contains("ARB_shader_objects") #endif @@ -1742,13 +1712,11 @@ void QPainterVideoSurface::createPainter() #if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC) case FragmentProgramShader: Q_ASSERT(m_glContext); - makeCurrent(m_glContext); m_painter = new QVideoSurfaceArbFpPainter(m_glContext); break; #endif // !QT_OPENGL_ES && !QT_OPENGL_DYNAMIC case GlslShader: Q_ASSERT(m_glContext); - makeCurrent(m_glContext); m_painter = new QVideoSurfaceGlslPainter(m_glContext); break; default: diff --git a/src/multimediawidgets/qpaintervideosurface_p.h b/src/multimediawidgets/qpaintervideosurface_p.h index 990d20cbe..582d6944c 100644 --- a/src/multimediawidgets/qpaintervideosurface_p.h +++ b/src/multimediawidgets/qpaintervideosurface_p.h @@ -59,11 +59,6 @@ #include <qabstractvideosurface.h> #include <qvideoframe.h> -QT_BEGIN_NAMESPACE - -class QGLContext; -QT_END_NAMESPACE - QT_USE_NAMESPACE QT_BEGIN_NAMESPACE @@ -90,7 +85,7 @@ public: virtual void viewportDestroyed() {} }; - +class QOpenGLContext; class Q_AUTOTEST_EXPORT QPainterVideoSurface : public QAbstractVideoSurface { Q_OBJECT @@ -126,8 +121,8 @@ public: void paint(QPainter *painter, const QRectF &target, const QRectF &source = QRectF(0, 0, 1, 1)); #if QT_CONFIG(opengl) - const QGLContext *glContext() const; - void setGLContext(QGLContext *context); + const QOpenGLContext *glContext() const; + void updateGLContext(); enum ShaderType { @@ -155,7 +150,7 @@ private: QVideoSurfacePainter *m_painter; #if QT_CONFIG(opengl) - QGLContext *m_glContext; + QOpenGLContext *m_glContext; ShaderTypes m_shaderTypes; ShaderType m_shaderType; #endif diff --git a/src/multimediawidgets/qvideowidget.cpp b/src/multimediawidgets/qvideowidget.cpp index 723a9bbb3..5158b2f35 100644 --- a/src/multimediawidgets/qvideowidget.cpp +++ b/src/multimediawidgets/qvideowidget.cpp @@ -228,7 +228,6 @@ void QRendererVideoWidgetBackend::hideEvent(QHideEvent *) { #if QT_CONFIG(opengl) m_updatePaintDevice = true; - m_surface->setGLContext(0); #endif } @@ -265,7 +264,7 @@ void QRendererVideoWidgetBackend::paintEvent(QPaintEvent *event) || painter.paintEngine()->type() == QPaintEngine::OpenGL2)) { m_updatePaintDevice = false; - m_surface->setGLContext(const_cast<QGLContext *>(QGLContext::currentContext())); + m_surface->updateGLContext(); if (m_surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) { m_surface->setShaderType(QPainterVideoSurface::GlslShader); } else { diff --git a/src/multimediawidgets/qvideowidget_p.h b/src/multimediawidgets/qvideowidget_p.h index 1db91f3f9..a3e687488 100644 --- a/src/multimediawidgets/qvideowidget_p.h +++ b/src/multimediawidgets/qvideowidget_p.h @@ -55,7 +55,7 @@ #include "qvideowidget.h" #ifndef QT_NO_OPENGL -#include <QGLWidget> +#include <QOpenGLWidget> #endif #include "qpaintervideosurface_p.h" |